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