add a script to list used beta names in a project
This commit is contained in:
parent
8c8f1fc182
commit
61960aadaf
|
@ -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
|
Loading…
Reference in New Issue