7 from headerutils import *
9 def pretty_name (name):
10 return name.replace(".","_").replace("-","_").replace("/","_").replace("+","_");
13 include_files = list()
19 def build_inclist (output, filen):
24 inc = build_include_list (filen)
25 if one_c and filen[-2:] == ".c":
28 pn = pretty_name(filen)
32 if len(build_include_list(nm)) != 0 or not noterm:
33 output.write (pretty_name(nm) + " -> " + pn + ";\n")
35 if nm not in include_files:
36 include_files.append(nm)
39 output.write (pretty_name(nm) + " -> " + pn + ";\n")
41 if nm not in include_files:
42 include_files.append(nm)
46 graphname = "graph.png"
48 def build_dot_file (file_list):
50 output = open(dotname, "w")
51 output.write ("digraph incweb {\n");
53 output.write ("all_c [shape=box];\n");
56 include_files.append (x)
57 elif os.path.exists (x):
58 build_inclist (output, x)
60 output.write (pretty_name (x) + "[shape=box];\n")
62 for x in include_files:
63 term = build_inclist (output, x)
65 output.write (pretty_name(x) + " [style=filled];\n")
73 for arg in sys.argv[1:]:
75 dotname = arg[2:]+".dot"
76 graphname = arg[2:]+".png"
77 elif arg[0:2] == "-h":
79 elif arg[0:2] == "-a":
83 elif arg[0:2] == "-f":
84 if not os.path.exists (arg[2:]):
85 print "Option " + arg +" doesn't specify a proper file"
88 sfile = open (arg[2:], "r")
89 srcdata = sfile.readlines()
92 files.append(x.rstrip())
93 elif arg[0:2] == "-n":
94 edge_thresh = int (arg[2:])
96 print "Unrecognized option " + arg
101 if len(sys.argv) == 1:
105 print "Generates a graph of the include web for specified files."
106 print "Usage: [-finput_file] [-h] [-ooutput] [file1 ... [filen]]"
107 print " -finput_file : Input file containing a list of files to process."
108 print " -ooutput : Specifies output to output.dot and output.png."
109 print " defaults to graph.dot and graph.png."
110 print " -nnum : Specifies the # of edges beyond which sfdp is invoked. def=0."
111 print " -a : Aggregate all .c files to 1 file. Shows only include web."
112 print " -at : Aggregate, but don't include terminal.h to .c links."
113 print " -h : Print this help."
116 build_dot_file (files)
117 if edges > edge_thresh:
118 os.system ("sfdp -Tpng " + dotname + " -o" + graphname)
120 os.system ("dot -Tpng " + dotname + " -o" + graphname)