included-by 2.7 KB

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