3 """Combine similar index entries into an entry and subentries.
7 \item {foobar} (in module flotz), 23
8 \item {foobar} (in module whackit), 4323
13 \subitem in module flotz, 23
14 \subitem in module whackit, 4323
16 Note that an item which matches the format of a collapsable item but which
17 isn't part of a group of similar items is not modified.
19 __version__
= '$Revision$'
27 def cmp_entries(e1
, e2
, lower
=string
.lower
):
28 return cmp(lower(e1
[1]), lower(e2
[1])) or cmp(e1
, e2
)
31 def dump_entries(write
, entries
):
33 write(" \\item %s (%s)%s\n" % entries
[0])
35 write(" \item %s\n" % entries
[0][0])
36 # now sort these in a case insensitive manner:
38 entries
.sort(cmp_entries
)
39 for xxx
, subitem
, pages
in entries
:
40 write(" \subitem %s%s\n" % (subitem
, pages
))
43 breakable_re
= re
.compile(
44 r
" \\item (.*) [(](.*)[)]((?:(?:, \d+)|(?:, \\[a-z]*\{\d+\}))+)")
47 def process(ifn
, ofn
=None):
54 ofp
= StringIO
.StringIO()
56 match
= breakable_re
.match
64 entry
= m
.group(1, 2, 3)
65 if entries
and entries
[-1][0] != entry
[0]:
66 dump_entries(write
, entries
)
70 dump_entries(write
, entries
)
91 opts
, args
= getopt
.getopt(sys
.argv
[1:], "o:")
93 if opt
in ("-o", "--output"):
96 outfile
= outfile
or filename
97 process(filename
, outfile
)
100 if __name__
== "__main__":