aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorq66 <daniel@octaforge.org>2018-08-01 15:10:11 +0200
committerq66 <daniel@octaforge.org>2018-08-01 15:10:11 +0200
commit61960aadafdebb017cba57c2f9107b99a93d2dc7 (patch)
tree88740224271edd79a1020c314eee9b20a278073e
parentsplit off name retrieval into a module (diff)
downloadeolian_tools-61960aadafdebb017cba57c2f9107b99a93d2dc7.tar.gz
add a script to list used beta names in a project
-rw-r--r--list_used_beta_api.lua109
1 files changed, 109 insertions, 0 deletions
diff --git a/list_used_beta_api.lua b/list_used_beta_api.lua
new file mode 100644
index 0000000..0c86474
--- /dev/null
+++ b/list_used_beta_api.lua
@@ -0,0 +1,109 @@
+local eolian = require("eolian")
+local getopt = require("getopt")
+
+local eou = require("utils.eolian_extras")
+
+local exit = false
+local pargs
+
+getopt.parse {
+ usage = "Usage: %prog [OPTIONS] path_to_project [path_to_eo_files]",
+ args = arg,
+ header = [[
+Print all beta C names used in the given project. You can specify a custom
+path to .eo files as the second argument. If you don't, system-wide eo files
+will be used instead.]],
+ descs = {
+ { "h", "help", false, help = "Show this message.",
+ callback = getopt.help_cb(io.stdout)
+ }
+ },
+ error_cb = function(parser, msg)
+ io.stderr:write(msg, "\n")
+ getopt.help(parser, io.stderr)
+ exit = true
+ end,
+ done_cb = function(parser, opts, args)
+ if opts["h"] then
+ exit = true
+ end
+ if #args == 0 then
+ parser:error_cb("project path not specified")
+ return
+ end
+ pargs = args
+ end
+}
+
+if exit then
+ return true
+end
+
+local eos = eolian.new()
+
+if #pargs > 1 then
+ eos:directory_add(pargs[2])
+else
+ eos:system_directory_add()
+end
+
+-- find all source, header and inline files first, we don't have a reasonable
+-- filesystem api available here so this hack is necessary, maybe replace later
+local f = io.popen(("find '%s' -name '*.[chx]'"):format(
+ pargs[1]:gsub("'", "\\'")))
+if not f then
+ error("could not find source files")
+end
+
+local srcs, syms = {}, {}
+
+-- collect source files
+for fn in f:lines() do
+ srcs[#srcs + 1] = fn
+end
+f:close()
+
+-- collect names as a lookup table
+eos:all_eot_files_parse()
+eos:all_eo_files_parse()
+
+local add_syms = function(fun)
+ for i, n in ipairs(fun(eos)) do
+ syms[n] = n
+ end
+end
+
+add_syms(eou.get_c_functions)
+add_syms(eou.get_c_events)
+add_syms(eou.get_c_function_pointers)
+add_syms(eou.get_c_aliases)
+add_syms(eou.get_c_structs)
+add_syms(eou.get_c_enums)
+add_syms(eou.get_c_globals)
+add_syms(eou.get_c_constants)
+
+-- match words in sources against names
+
+local match_names = function(fn)
+ local fs = io.open(fn)
+ if not fs then
+ return
+ end
+ local lnum = 1
+ for l in fs:lines() do
+ -- C names on thel ine
+ for w in l:gmatch("[%a_][%w_]*") do
+ if syms[w] then
+ print(("%s:%d: used beta name '%s'"):format(fn, lnum, w))
+ end
+ end
+ lnum = lnum + 1
+ end
+ fs:close()
+end
+
+for i, fn in ipairs(srcs) do
+ match_names(fn)
+end
+
+return true