Fred Drake | 34a05f7 | 2002-04-16 21:27:17 +0000 | [diff] [blame^] | 1 | #! /usr/bin/env python |
| 2 | |
| 3 | import errno |
| 4 | import os |
| 5 | import sys |
| 6 | |
| 7 | if __name__ == "__main__": |
| 8 | _base = sys.argv[0] |
| 9 | else: |
| 10 | _base = __file__ |
| 11 | |
| 12 | _script_home = os.path.abspath(os.path.dirname(_base)) |
| 13 | |
| 14 | srcdir = os.path.dirname(os.path.dirname(_script_home)) |
| 15 | |
| 16 | EXCLUDES = ["bitset.h", "cStringIO.h", "graminit.h", "grammar.h", |
| 17 | "longintrepr.h", "metagrammar.h", |
| 18 | "node.h", "opcode.h", "osdefs.h", "pgenheaders.h", |
| 19 | "py_curses.h", "parsetok.h", "symtable.h", "token.h"] |
| 20 | |
| 21 | |
| 22 | def list_headers(): |
| 23 | """Return a list of headers.""" |
| 24 | incdir = os.path.join(srcdir, "Include") |
| 25 | return [fn for fn in os.listdir(incdir) |
| 26 | if fn.endswith(".h") and fn not in EXCLUDES] |
| 27 | |
| 28 | def list_documented_items(): |
| 29 | """Return a list of everything that's already documented.""" |
| 30 | docdir = os.path.join(srcdir, "Doc") |
| 31 | return [] |
| 32 | |
| 33 | def split_documented(all, documented): |
| 34 | """Split the list of all symbols into documented and undocumented |
| 35 | categories.""" |
| 36 | doc = [] |
| 37 | undoc = [] |
| 38 | for t in all: |
| 39 | if t[0] in documented: |
| 40 | doc.append(t) |
| 41 | else: |
| 42 | undoc.append(t) |
| 43 | return doc, undoc |
| 44 | |
| 45 | def print_list(L, title=None): |
| 46 | """Dump a list to stdout.""" |
| 47 | if title: |
| 48 | print title + ":" |
| 49 | print "-" * (len(title) + 1) |
| 50 | w = 0 |
| 51 | for sym, filename in L: |
| 52 | w = max(w, len(sym)) |
| 53 | if w % 4 == 0: |
| 54 | w += 4 |
| 55 | else: |
| 56 | w += (4 - (w % 4)) |
| 57 | for sym, filename in L: |
| 58 | print "%-*s%s" % (w, sym, filename) |
| 59 | |
| 60 | |
| 61 | _spcjoin = ' '.join |
| 62 | |
| 63 | def main(): |
| 64 | args = sys.argv[1:] |
| 65 | if args: |
| 66 | headers = args |
| 67 | documented = [] |
| 68 | else: |
| 69 | os.chdir(os.path.join(srcdir, "Include")) |
| 70 | headers = list_headers() |
| 71 | documented = list_documented_items() |
| 72 | |
| 73 | cmd = ("ctags -f - --file-scope=no --c-types=-mv " |
| 74 | "-Istaticforward -Istatichere " |
| 75 | + _spcjoin(headers)) |
| 76 | fp = os.popen(cmd) |
| 77 | L = [] |
| 78 | prevsym = None |
| 79 | while 1: |
| 80 | line = fp.readline() |
| 81 | if not line: |
| 82 | break |
| 83 | sym, filename = line.split()[:2] |
| 84 | if sym == prevsym: |
| 85 | continue |
| 86 | if not sym.endswith("_H"): |
| 87 | L.append((sym, filename)) |
| 88 | prevsym = sym |
| 89 | L.sort() |
| 90 | fp.close() |
| 91 | |
| 92 | try: |
| 93 | if documented: |
| 94 | documented, undocumented = split_documented(L, documented) |
| 95 | print_list(documented, "Documented symbols") |
| 96 | if undocumented: |
| 97 | print |
| 98 | print_list(undocumented, "Undocumented symbols") |
| 99 | else: |
| 100 | print_list(L) |
| 101 | except IOError, e: |
| 102 | if e.errno != errno.EPIPE: |
| 103 | raise |
| 104 | |
| 105 | |
| 106 | if __name__ == "__main__": |
| 107 | main() |