blob: 8c5f93fb6e2d21110eca0d4c10b80182d30fda6e [file] [log] [blame]
Fred Drake693a2c61999-04-22 13:08:09 +00001#! /usr/bin/env python
2# -*- Python -*-
3
4import fileinput
Fred Drakec4a623e1999-04-22 20:32:21 +00005import getopt
Fred Drake693a2c61999-04-22 13:08:09 +00006import glob
7import os
8import re
9import sys
10
11
12declare_rx = re.compile(
13 r"\\declaremodule(?:\[[a-zA-Z0-9]*\]*)?{[a-zA-Z_0-9]+}{([a-zA-Z_0-9]+)}")
14
15module_rx = re.compile(r"\\module{([a-zA-Z_0-9]+)}")
16
17def main():
18 try:
Fred Drakec4a623e1999-04-22 20:32:21 +000019 just_list = 0
20 print_lineno = 0
21 opts, args = getopt.getopt(sys.argv[1:], "ln", ["list", "number"])
22 for opt, arg in opts:
23 if opt in ("-l", "--list"):
24 just_list = 1
25 elif opt in ("-n", "--number"):
26 print_lineno = 1
27 files = args
Fred Drake693a2c61999-04-22 13:08:09 +000028 if not files:
29 files = glob.glob("*.tex")
30 files.sort()
31 modulename = None
32 for line in fileinput.input(files):
33 if line[:9] == r"\section{":
34 modulename = None
35 continue
36 if line[:16] == r"\modulesynopsys{":
37 continue
38 m = declare_rx.match(line)
39 if m:
40 modulename = m.group(1)
41 continue
42 if not modulename:
43 continue
44 m = module_rx.search(line)
45 if m:
46 name = m.group(1)
47 if name != modulename:
Fred Drakec4a623e1999-04-22 20:32:21 +000048 filename = fileinput.filename()
49 if just_list:
50 print filename
51 fileinput.nextfile()
52 modulename = None
53 elif print_lineno:
54 print "%s(%d):%s" \
55 % (filename, fileinput.filelineno(), line[:-1])
56 else:
57 print "%s:%s" % (filename, line[:-1])
Fred Drake693a2c61999-04-22 13:08:09 +000058 except KeyboardInterrupt:
59 sys.exit(1)
60
61
62if __name__ == "__main__":
63 main()