summaryrefslogtreecommitdiff
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
parent8c8f1fc182ad72d4810fd9cb09bad952883787a9 (diff)
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 @@
1local eolian = require("eolian")
2local getopt = require("getopt")
3
4local eou = require("utils.eolian_extras")
5
6local exit = false
7local pargs
8
9getopt.parse {
10 usage = "Usage: %prog [OPTIONS] path_to_project [path_to_eo_files]",
11 args = arg,
12 header = [[
13Print all beta C names used in the given project. You can specify a custom
14path to .eo files as the second argument. If you don't, system-wide eo files
15will be used instead.]],
16 descs = {
17 { "h", "help", false, help = "Show this message.",
18 callback = getopt.help_cb(io.stdout)
19 }
20 },
21 error_cb = function(parser, msg)
22 io.stderr:write(msg, "\n")
23 getopt.help(parser, io.stderr)
24 exit = true
25 end,
26 done_cb = function(parser, opts, args)
27 if opts["h"] then
28 exit = true
29 end
30 if #args == 0 then
31 parser:error_cb("project path not specified")
32 return
33 end
34 pargs = args
35 end
36}
37
38if exit then
39 return true
40end
41
42local eos = eolian.new()
43
44if #pargs > 1 then
45 eos:directory_add(pargs[2])
46else
47 eos:system_directory_add()
48end
49
50-- find all source, header and inline files first, we don't have a reasonable
51-- filesystem api available here so this hack is necessary, maybe replace later
52local f = io.popen(("find '%s' -name '*.[chx]'"):format(
53 pargs[1]:gsub("'", "\\'")))
54if not f then
55 error("could not find source files")
56end
57
58local srcs, syms = {}, {}
59
60-- collect source files
61for fn in f:lines() do
62 srcs[#srcs + 1] = fn
63end
64f:close()
65
66-- collect names as a lookup table
67eos:all_eot_files_parse()
68eos:all_eo_files_parse()
69
70local add_syms = function(fun)
71 for i, n in ipairs(fun(eos)) do
72 syms[n] = n
73 end
74end
75
76add_syms(eou.get_c_functions)
77add_syms(eou.get_c_events)
78add_syms(eou.get_c_function_pointers)
79add_syms(eou.get_c_aliases)
80add_syms(eou.get_c_structs)
81add_syms(eou.get_c_enums)
82add_syms(eou.get_c_globals)
83add_syms(eou.get_c_constants)
84
85-- match words in sources against names
86
87local match_names = function(fn)
88 local fs = io.open(fn)
89 if not fs then
90 return
91 end
92 local lnum = 1
93 for l in fs:lines() do
94 -- C names on thel ine
95 for w in l:gmatch("[%a_][%w_]*") do
96 if syms[w] then
97 print(("%s:%d: used beta name '%s'"):format(fn, lnum, w))
98 end
99 end
100 lnum = lnum + 1
101 end
102 fs:close()
103end
104
105for i, fn in ipairs(srcs) do
106 match_names(fn)
107end
108
109return true