1999-04-22 10:08:09 -03:00
|
|
|
#! /usr/bin/env python
|
|
|
|
# -*- Python -*-
|
|
|
|
|
|
|
|
import fileinput
|
1999-04-22 17:32:21 -03:00
|
|
|
import getopt
|
1999-04-22 10:08:09 -03:00
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
declare_rx = re.compile(
|
|
|
|
r"\\declaremodule(?:\[[a-zA-Z0-9]*\]*)?{[a-zA-Z_0-9]+}{([a-zA-Z_0-9]+)}")
|
|
|
|
|
|
|
|
module_rx = re.compile(r"\\module{([a-zA-Z_0-9]+)}")
|
|
|
|
|
|
|
|
def main():
|
|
|
|
try:
|
1999-04-22 17:32:21 -03:00
|
|
|
just_list = 0
|
|
|
|
print_lineno = 0
|
|
|
|
opts, args = getopt.getopt(sys.argv[1:], "ln", ["list", "number"])
|
|
|
|
for opt, arg in opts:
|
|
|
|
if opt in ("-l", "--list"):
|
|
|
|
just_list = 1
|
|
|
|
elif opt in ("-n", "--number"):
|
|
|
|
print_lineno = 1
|
|
|
|
files = args
|
1999-04-22 10:08:09 -03:00
|
|
|
if not files:
|
|
|
|
files = glob.glob("*.tex")
|
|
|
|
files.sort()
|
|
|
|
modulename = None
|
|
|
|
for line in fileinput.input(files):
|
|
|
|
if line[:9] == r"\section{":
|
|
|
|
modulename = None
|
|
|
|
continue
|
|
|
|
if line[:16] == r"\modulesynopsys{":
|
|
|
|
continue
|
|
|
|
m = declare_rx.match(line)
|
|
|
|
if m:
|
|
|
|
modulename = m.group(1)
|
|
|
|
continue
|
|
|
|
if not modulename:
|
|
|
|
continue
|
|
|
|
m = module_rx.search(line)
|
|
|
|
if m:
|
|
|
|
name = m.group(1)
|
|
|
|
if name != modulename:
|
1999-04-22 17:32:21 -03:00
|
|
|
filename = fileinput.filename()
|
|
|
|
if just_list:
|
|
|
|
print filename
|
|
|
|
fileinput.nextfile()
|
|
|
|
modulename = None
|
|
|
|
elif print_lineno:
|
|
|
|
print "%s(%d):%s" \
|
|
|
|
% (filename, fileinput.filelineno(), line[:-1])
|
|
|
|
else:
|
|
|
|
print "%s:%s" % (filename, line[:-1])
|
1999-04-22 10:08:09 -03:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|