From 83decd22b44019b0fe369224fb19e1ef21263ab6 Mon Sep 17 00:00:00 2001 From: Dan McDonald Date: Tue, 15 Mar 2022 12:07:15 -0400 Subject: OS-8361 IPD 4 (man page renumbering) tracking issue Reviewed by: Brian Bennett Approved by: Brian Bennett --- sort-xrefs.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 sort-xrefs.py (limited to 'sort-xrefs.py') diff --git a/sort-xrefs.py b/sort-xrefs.py new file mode 100755 index 0000000000..f9c1f1fa90 --- /dev/null +++ b/sort-xrefs.py @@ -0,0 +1,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)) -- cgit v1.2.3