annotate contrib/header-tools/included-by @ 158:494b0b89df80 default tip

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