blob: f9c1f1fa901eb9deba59c9de84f1d1ca15c8e3c9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
#!/usr/bin/env python3
import re
import sys
# group 0: The whole shebang
# group 1 or group 2: The page name (sans fonts, if any)
# group 3: The section
REFERENCE = re.compile(r'(?:\\fB([a-zA-Z0-9_.-]+)\\fR|([a-zA-Z0-9_.-]+))\(([0-9][A-Za-z]*)\)')
def match_section(match):
return match.group(3).upper()
def match_page(match):
return match.group(1) or match.group(2)
def sort_key(line):
match = REFERENCE.match(line) # If this fails we're hosed
assert(match)
return [match_section(match), match_page(match)]
lines = [f.rstrip(',\n') for f in sys.stdin]
lines.sort(key=sort_key)
print(',\n'.join(lines))
|