summaryrefslogtreecommitdiff
path: root/sw/source/writerfilter/ooxml/factoryinc.py
blob: ec07f7fda1ce2cf67677948e13e696d71cb4c358 (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
48
49
#!/usr/bin/env python
#
# This file is part of the LibreOffice project.
#
# 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/.
#

from xml.dom import minidom
import sys


def createInclude(model):
    print("""
#ifndef INCLUDED_OOXML_FACTORY_GENERATED_HXX
#define INCLUDED_OOXML_FACTORY_GENERATED_HXX

namespace writerfilter {
namespace ooxml {

/// @cond GENERATED
    """)

    # Create namespaces.
    counter = 1
    for namespace in sorted([ns.getAttribute("name") for ns in model.getElementsByTagName("namespace")]):
        print("const Id NN_%s = %s << 16;" % (namespace.replace('-', '_'), counter))
        counter += 1

    # Create defines.
    counter = 1
    defines = []
    for define in sorted([ns.getAttribute("name") for ns in model.getElementsByTagName("define")]):
        if define not in defines:
            print("const Id DEFINE_%s = %s;" % (define, counter))
            defines.append(define)
        counter += 1
    print("""/// @endcond
}}

#endif // INCLUDED_OOXML_FACTORY_GENERATED_HXX""")


modelPath = sys.argv[1]
model = minidom.parse(modelPath)
createInclude(model)

# vim:set shiftwidth=4 softtabstop=4 expandtab: