| Message |
Here is one way of tackling the issue. As David said, a few regexps might find a bit of orphan code. I modified some code I had written for another SMAUG fixup project, namely at:
http://www.gammon.com.au/forum/?id=7139&page=2
The code below, which I ran in the MUSHclient immediate window, scans the Smaugfuss source .c files twice. The first time it attempts to find function bodies (and hence the names of the functions). The second time it sees if there are more than one reference to them by a simple find. Of course there will be one mention, which is the function declaration itself.
Here is the code, you probably need to change the path to the source:
-- pattern to detect a function declaration
pat = "[%a_]+%s+%*?%s*([%a%d_]+)%s*%b().-(%b{})"
olddir = "C:\\cygwin\\home\\Owner\\smaugfuss\\src\\"
funcs = {}
function process_function (name, body)
-- Note (" +++ function: " .. name)
funcs [name] = 0
end -- process_function
function build_functions (name)
local f, s
print ("Looking for functions in: " .. name)
f = assert (io.open (olddir .. name, "rb")) -- open input
s = f:read ("*a") -- read all of it
f:close () -- close it
-- fix up imc strange function defs
s = string.gsub (s, "PFUN%( ([%a%d_]+) %)",
"void %1( IMC_PACKET *q, char *packet )")
s = string.gsub (s, "IMC_CMD%( ([%a%d_]+) %)",
"void %1( CHAR_DATA *ch, char *argument )")
s = string.gsub (s, "'}'", "") -- confuses function finding
s = string.gsub (s, "/%*.-%*/", " ") -- remove comments
s = string.gsub (s, "//.-\r?\n", "\n") -- remove comments
string.gsub (s, pat, process_function)
end -- build_functions
local t = assert (utils.readdir (olddir .. "*.c"))
for k in pairs (t) do
build_functions (k)
end -- for
function count_it (name)
if funcs [name] then
funcs [name] = funcs [name] + 1
end -- if
end -- count_it
function check_xrefs (name)
local f, s
print ("Cross reference check in: " .. name)
f = assert (io.open (olddir .. name, "rb")) -- open input
s = f:read ("*a") -- read all of it
f:close () -- close it
string.gsub (s, "[%a%d_]+", count_it)
end -- build_functions
for k in pairs (t) do
check_xrefs (k)
end -- for
require "pairsbykeys"
for k, v in pairsByKeys (funcs) do
if v <= 1 then
if not string.match (k, "^do_") and
not string.match (k, "^spell_") then
print (k)
end -- not likely to be spell or command
end -- not referenced
end -- for
Running that gave me these results:
CONTENTS_NUM_ITEM
VAMP_AC
can_learn_lang
can_oedit
ch_slookup
chance_attrib
clean_resets
color_align
count_lines
economize_mobgold
ext_clear_bits
ext_has_bits
ext_is_empty
ext_remove_bits
ext_same_bits
ext_set_bits
ext_toggle_bits
find_skill
find_tongue
find_weapon
fwrite_bitvector
genrand_int31
genrand_real1
genrand_real3
get_exit_number
get_pcflag
get_wearloc
getcolor
imc_save_pfile
imc_savecolor
in_hash_table
in_soft_range
is_hunting
is_name_prefix
level_exp
make_fire
oprog_script_trigger
paint
personal_lookup
read_char_mobile
refresh_page
rprog_script_trigger
send_obj_page_to_char
smush_tilde
toggle_bexit_flag
web_imc_list
write_char_mobile
I'm not sure which are genuinely orphan functions, but that gives you a starting point for investigating. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|