NullLogic

...

#!/usr/bin/nsp // Create a map of all functions in libnsp, and all functions that call those functions. function get_functions(topdir) { local function get_name(line) { if ((string.atoi(line, 0)<97) || (string.atoi(line, 0)>122) || (string.str(line, "(")==null)) return null; s=string.sub(line, 0, string.len(line)-string.len(string.str(line, "("))); s=string.split(s, " "); s=s[sizeof(s)-1]; if (string.sub(s, 0, 1)=="*") s=string.sub(s, 1); return s; } local flist={}; foreach (n,f in dirlist(topdir)) { if (string.sub(n, -2)!=".c") continue; x=file.readall(topdir+"/"+n); flist[n]={ src=x; functions={}; }; foreach (line in string.split(x, "\n")) { if ((z=get_name(line))==null) continue; if (z=='') continue; flist[n]['functions'][z]={ callers={}; }; } } foreach (n,v in flist) { foreach (n2,v2 in v['functions']) { if (string.len(n2)<1) continue; foreach (n3,v3 in flist) { foreach (line in string.split(v3['src'], "\n")) { if (string.sub(line, 0, 1)=="#") continue; if ((z=get_name(line))!=null) { fname=z; continue; } else if (line=="}") { fname=0; continue; } if (fname==0) continue; if (fname=='') continue; if (string.str(line, n2+"(")==null) continue; v['functions'][n2]['callers'][fname]=tonumber(v['functions'][n2]['callers'][fname])+1; } } } } foreach (n,v in flist) v['src']=""; return flist; } function print_list(flist) { foreach (n,v in flist) { print(n, "\n"); foreach (n2,v2 in v['functions']) { print("\t", n2, "\n"); foreach (n3,v3 in v2['callers']) { print("\t\t", n3, " (", v3, ")\n"); } } } } function fwrite_list(flist) { fname="srcmap.txt"; file.writeall(fname, ""); foreach (n,v in flist) { file.append(fname, n+"\n"); foreach (n2,v2 in v['functions']) { file.append(fname, "\t"+n2+"\n"); foreach (n3,v3 in v2['callers']) { file.append(fname, "\t\tcalled by "+n3+" ("+v3+")\n"); } } } } flist=get_functions("../../src/libnsp"); //print_list(flist); fwrite_list(flist); io.flush(); //print(serialize(flist),"\n");