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+\}))+)")
49 opts
, args
= getopt
.getopt(sys
.argv
[1:], "o:")
51 if opt
in ("-o", "--output"):
54 outfile
= outfile
or filename
59 ofp
= StringIO
.StringIO()
61 match
= breakable_re
.match
69 entry
= m
.group(1, 2, 3)
70 if entries
and entries
[-1][0] != entry
[0]:
71 dump_entries(write
, entries
)
75 dump_entries(write
, entries
)
86 fp
= open(outfile
, "w")
87 fp
.write(ofp
.getvalue())
91 if __name__
== "__main__":