summaryrefslogtreecommitdiffstats
path: root/misc/xml-tokens/gen-tokens.py
blob: f344e2e932802831d9b4a366128418ce7e9235b8 (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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python3
########################################################################
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
########################################################################

import token_util
import argparse
import sys
from pathlib import Path


desc = """Generate C++ source files from a list of tokens.

To generate tokens files for Excel 2003 XML (xls-xml), run

  %(prog)s xls-xml-tokens.txt \\
    ../../src/liborcus/xls_xml_token_constants.inl \\
    ../../src/liborcus/xls_xml_tokens.inl \\
"""

def main ():
    parser = argparse.ArgumentParser(
        description=desc,
        formatter_class=argparse.RawTextHelpFormatter
    )
    parser.add_argument("tokenlist", type=Path, help="plain-text file that contains a list of tokens.")
    parser.add_argument("output1", type=Path, help="output file that will contain XML token values.")
    parser.add_argument("output2", type=Path, help="output file that will contain XML token names.")
    args = parser.parse_args()

    tokens = {}
    with open(args.tokenlist, "r") as f:
        for line in f.readlines():
            token = line.strip()
            tokens[token] = True

    tokens = sorted(tokens.keys())
    token_util.gen_token_constants(args.output1, tokens)
    token_util.gen_token_names(args.output2, tokens)


if __name__ == "__main__":
    main()