111
|
1 #! /usr/bin/python2
|
|
2 import os.path
|
|
3 import sys
|
|
4 import shlex
|
|
5 import re
|
|
6
|
|
7 from headerutils import *
|
|
8
|
|
9
|
|
10
|
|
11 usage = False
|
|
12 src = list()
|
|
13 flist = { }
|
|
14 process_h = False
|
|
15 process_c = False
|
|
16 verbose = False
|
|
17 level = 0
|
|
18 match_all = False
|
|
19 num_match = 1
|
|
20
|
|
21 file_list = list()
|
|
22 current = True
|
|
23 deeper = True
|
|
24 scanfiles = True
|
|
25 for x in sys.argv[1:]:
|
|
26 if x[0:2] == "-h":
|
|
27 usage = True
|
|
28 elif x[0:2] == "-i":
|
|
29 process_h = True
|
|
30 elif x[0:2] == "-s" or x[0:2] == "-c":
|
|
31 process_c = True
|
|
32 elif x[0:2] == "-v":
|
|
33 verbose = True
|
|
34 elif x[0:2] == "-a":
|
|
35 match_all = True
|
|
36 elif x[0:2] == "-n":
|
|
37 num_match = int(x[2:])
|
|
38 elif x[0:2] == "-1":
|
|
39 deeper = False
|
|
40 elif x[0:2] == "-2":
|
|
41 current = False
|
|
42 elif x[0:2] == "-f":
|
|
43 file_list = open (x[2:]).read().splitlines()
|
|
44 scanfiles = False
|
|
45 elif x[0] == "-":
|
|
46 print "Error: Unknown option " + x
|
|
47 usage = True
|
|
48 else:
|
|
49 src.append (x)
|
|
50
|
|
51 if match_all:
|
|
52 num_match = len (src)
|
|
53
|
|
54 if not process_h and not process_c:
|
|
55 process_h = True
|
|
56 process_c = True
|
|
57
|
|
58 if len(src) == 0:
|
|
59 usage = True
|
|
60
|
|
61 if not usage:
|
|
62 if scanfiles:
|
|
63 if process_h:
|
|
64 file_list = find_gcc_files ("\*.h", current, deeper)
|
|
65 if process_c:
|
|
66 file_list = file_list + find_gcc_files ("\*.c", current, deeper)
|
|
67 file_list = file_list + find_gcc_files ("\*.cc", current, deeper)
|
|
68 else:
|
|
69 newlist = list()
|
|
70 for x in file_list:
|
|
71 if process_h and x[-2:] == ".h":
|
|
72 newlist.append (x)
|
|
73 elif process_c and (x[-2:] == ".c" or x[-3:] == ".cc"):
|
|
74 newlist.append (x)
|
|
75 file_list = newlist;
|
|
76
|
|
77 file_list.sort()
|
|
78 for fn in file_list:
|
|
79 found = find_unique_include_list (fn)
|
|
80 careabout = list()
|
|
81 output = ""
|
|
82 for inc in found:
|
|
83 if inc in src:
|
|
84 careabout.append (inc)
|
|
85 if output == "":
|
|
86 output = fn
|
|
87 if verbose:
|
|
88 output = output + " [" + inc +"]"
|
|
89 if len (careabout) < num_match:
|
|
90 output = ""
|
|
91 if output != "":
|
|
92 print output
|
|
93 else:
|
|
94 print "included-by [-h] [-i] [-c] [-v] [-a] [-nx] file1 [file2] ... [filen]"
|
|
95 print "find the list of all files in subdirectories that include any of "
|
|
96 print "the listed files. processed to a depth of 3 subdirs"
|
|
97 print " -h : Show this message"
|
|
98 print " -i : process only header files (*.h) for #include"
|
|
99 print " -c : process only source files (*.c *.cc) for #include"
|
|
100 print " If nothing is specified, defaults to -i -c"
|
|
101 print " -s : Same as -c."
|
|
102 print " -v : Show which include(s) were found"
|
|
103 print " -nx : Only list files which have at least x different matches. Default = 1"
|
|
104 print " -a : Show only files which all listed files are included"
|
|
105 print " This is equivilent to -nT where T == # of items in list"
|
|
106 print " -flistfile : Show only files contained in the list of files"
|
|
107
|
|
108
|
|
109
|
|
110
|
|
111
|
|
112
|