source: trunk/essentials/dev-lang/python/Doc/tools/cmpcsyms@ 3398

Last change on this file since 3398 was 3225, checked in by bird, 19 years ago

Python 2.5

File size: 4.5 KB
Line 
1#! /usr/bin/env python
2from __future__ import with_statement
3import errno
4import os
5import re
6import sys
7import string
8
9if __name__ == "__main__":
10 _base = sys.argv[0]
11else:
12 _base = __file__
13
14_script_home = os.path.abspath(os.path.dirname(_base))
15
16srcdir = os.path.dirname(os.path.dirname(_script_home))
17
18EXCLUDES = ["bitset.h", "cStringIO.h", "graminit.h", "grammar.h",
19 "longintrepr.h", "metagrammar.h",
20 "node.h", "opcode.h", "osdefs.h", "pgenheaders.h",
21 "py_curses.h", "parsetok.h", "symtable.h", "token.h"]
22
23
24def list_headers():
25 """Return a list of headers."""
26 incdir = os.path.join(srcdir, "Include")
27 return [os.path.join(incdir, fn) for fn in os.listdir(incdir)
28 if fn.endswith(".h") and fn not in EXCLUDES]
29
30
31def matcher(pattern):
32 return re.compile(pattern).search
33
34MATCHERS = [
35 # XXX this should also deal with ctypedesc, cvardesc and cmemberdesc
36 matcher(r"\\begin\{cfuncdesc\}\{(?P<result>[^}]*)\}\{(?P<sym>[^}]*)\}{(?P<params>[^}]*)\}"),
37 matcher(r"\\cfuncline\{(?P<result>[^})]*)\}\{(?P<sym>[^}]*)\}{(?P<params>[^}]*)\}"),
38 ]
39
40def list_documented_items():
41 """Return a list of everything that's already documented."""
42 apidir = os.path.join(srcdir, "Doc", "api")
43 files = [fn for fn in os.listdir(apidir) if fn.endswith(".tex")]
44 L = []
45 for fn in files:
46 fullname = os.path.join(apidir, fn)
47 data = open(fullname).read()
48 for matcher in MATCHERS:
49 pos = 0
50 while 1:
51 m = matcher(data, pos)
52 if not m: break
53 pos = m.end()
54 sym = m.group("sym")
55 result = m.group("result")