Line | |
---|
1 | #! /usr/bin/env python
|
---|
2 | # -*- Python -*-
|
---|
3 |
|
---|
4 | import fileinput
|
---|
5 | import getopt
|
---|
6 | import glob
|
---|
7 | import os
|
---|
8 | import re
|
---|
9 | import sys
|
---|
10 |
|
---|
11 |
|
---|
12 | declare_rx = re.compile(
|
---|
13 | r"\\declaremodule(?:\[[a-zA-Z0-9]*\]*)?{[a-zA-Z_0-9]+}{([a-zA-Z_0-9]+)}")
|
---|
14 |
|
---|
15 | module_rx = re.compile(r"\\module{([a-zA-Z_0-9]+)}")
|
---|
16 |
|
---|
17 | def main():
|
---|
18 | try:
|
---|
19 | 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
|
---|
28 | 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:
|
---|
48 | 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])
|
---|
58 | except KeyboardInterrupt:
|
---|
59 | sys.exit(1)
|
---|
60 |
|
---|
61 |
|
---|
62 | if __name__ == "__main__":
|
---|
63 | main()
|
---|
Note:
See
TracBrowser
for help on using the repository browser.