]> granicus.if.org Git - python/commitdiff
Script to convert module index data to module index.
authorFred Drake <fdrake@acm.org>
Fri, 2 Jan 1998 03:00:27 +0000 (03:00 +0000)
committerFred Drake <fdrake@acm.org>
Fri, 2 Jan 1998 03:00:27 +0000 (03:00 +0000)
Doc/modindex.py [new file with mode: 0755]
Doc/tools/modindex.py [new file with mode: 0755]

diff --git a/Doc/modindex.py b/Doc/modindex.py
new file mode 100755 (executable)
index 0000000..f85b909
--- /dev/null
@@ -0,0 +1,62 @@
+#! /usr/bin/env python
+
+"""Script to convert raw module index data to module index."""
+
+import os
+import string
+import sys
+
+
+def parse_line(input):
+    lineno = string.split(input)[-1]
+    module = input[:len(input)-(len(lineno)+1)]
+    return module, lineno
+    return 
+
+
+def cmp_items((s1, line1), (s2, line2)):
+    rc = cmp(string.lower(s1), string.lower(s2))
+    if rc == 0:
+       # Make the lower-case version come first since the upper-case
+       # version is usually a helper module for constants and such.
+       rc = cmp(s2, s1)
+    return rc
+
+
+def main():
+    if sys.argv[1:]:
+       infile = sys.argv[1]
+    else:
+       infile = "-"
+    if infile == "-":
+       ifp = sys.stdin
+       ofp = sys.stdout
+       sys.stdout = sys.stderr
+    else:
+       ifp = open(infile)
+       base, ext = os.path.splitext(infile)
+       outfile = base + ".ind"
+       ofp = open(outfile, "w")
+    ofp.write("\\begin{theindex}\n\n")
+    lines = ifp.readlines()
+    for i in range(len(lines)):
+       if lines[i][0] == '\\':
+           lines[i] = '\1' + lines[i]
+    lines = map(parse_line, lines)
+    lines.sort(cmp_items)
+    prev_letter = lines[0][0][0]
+    if prev_letter == '\1':
+       prev_letter = lines[0][0][1]
+    prev_letter = string.lower(prev_letter)
+    for module, lineno in lines:
+       if module[0] == '\1':
+           module = module[1:]
+       if string.lower(module[0]) != prev_letter:
+           ofp.write("\n  \\indexspace\n\n")
+           prev_letter = string.lower(module[0])
+       ofp.write("  \\item {\\tt %s} %s\n" % (module, lineno))
+    ofp.write("\n\\end{theindex}\n")
+
+
+if __name__ == "__main__":
+    main()
diff --git a/Doc/tools/modindex.py b/Doc/tools/modindex.py
new file mode 100755 (executable)
index 0000000..f85b909
--- /dev/null
@@ -0,0 +1,62 @@
+#! /usr/bin/env python
+
+"""Script to convert raw module index data to module index."""
+
+import os
+import string
+import sys
+
+
+def parse_line(input):
+    lineno = string.split(input)[-1]
+    module = input[:len(input)-(len(lineno)+1)]
+    return module, lineno
+    return 
+
+
+def cmp_items((s1, line1), (s2, line2)):
+    rc = cmp(string.lower(s1), string.lower(s2))
+    if rc == 0:
+       # Make the lower-case version come first since the upper-case
+       # version is usually a helper module for constants and such.
+       rc = cmp(s2, s1)
+    return rc
+
+
+def main():
+    if sys.argv[1:]:
+       infile = sys.argv[1]
+    else:
+       infile = "-"
+    if infile == "-":
+       ifp = sys.stdin
+       ofp = sys.stdout
+       sys.stdout = sys.stderr
+    else:
+       ifp = open(infile)
+       base, ext = os.path.splitext(infile)
+       outfile = base + ".ind"
+       ofp = open(outfile, "w")
+    ofp.write("\\begin{theindex}\n\n")
+    lines = ifp.readlines()
+    for i in range(len(lines)):
+       if lines[i][0] == '\\':
+           lines[i] = '\1' + lines[i]
+    lines = map(parse_line, lines)
+    lines.sort(cmp_items)
+    prev_letter = lines[0][0][0]
+    if prev_letter == '\1':
+       prev_letter = lines[0][0][1]
+    prev_letter = string.lower(prev_letter)
+    for module, lineno in lines:
+       if module[0] == '\1':
+           module = module[1:]
+       if string.lower(module[0]) != prev_letter:
+           ofp.write("\n  \\indexspace\n\n")
+           prev_letter = string.lower(module[0])
+       ofp.write("  \\item {\\tt %s} %s\n" % (module, lineno))
+    ofp.write("\n\\end{theindex}\n")
+
+
+if __name__ == "__main__":
+    main()