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