tiger-lib 1.9.1

Library used by the tools ck3-tiger, vic3-tiger, and imperator-tiger. This library holds the bulk of the code for them. It can be built either for ck3-tiger with the feature ck3, or for vic3-tiger with the feature vic3, or for imperator-tiger with the feature imperator, but not both at the same time.
Documentation
#!/usr/bin/python3

import os.path
import sys

fname = sys.argv[1]

print(fname, file=sys.stderr)
try:
    text = open(fname, encoding="utf-8").read()
except:
    try:
        text = open(fname, encoding="windows-1252").read()
    except:
        # triggers.log has a stray 0x90 in it
        text = open(fname, encoding="utf-8", errors="replace").read()

SEPARATOR = "\n--------------------\n\n"

items = text.split(SEPARATOR)

if fname.endswith("event_targets.log"):
    header = items[0]
    footer = items[-1]
    del items[0]
    del items[-1]
    items.sort()
    items.insert(0, header)
    items.append(footer)
    print(SEPARATOR.join(items))

elif fname.endswith("triggers.log"):
    header = items[0:2]
    del items[0:1]

    items.sort()

    items.insert(0, header[1])
    items.insert(0, header[0])

    print(SEPARATOR.join(items))

elif fname.endswith("effects.log"):
    header = items[0]
    del items[0]

    items.sort()

    items.insert(0, header)
    print(SEPARATOR.join(items))

elif fname.endswith("modifiers.log"):
    items = text.split("\n\n")
    sortable = []
    for item in items:
        lines = item.splitlines()
        if len(lines) == 3:
            if lines[0].startswith("Printing "):
                del lines[0]
            elif lines[1].startswith("Extra "):
                del lines[1]
        if not lines:
            continue
        lines = [ lines[1], lines[0] ]
        sortable.append(lines)
    sortable.sort()
    for lines in sortable:
        print(lines[1])
        print(lines[0])
        print()