summaryrefslogtreecommitdiffstats
blob: 95e5c875cd7df327e84db5e93e28fb7f11c507a5 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
Import("env")

env.Tool("DocBook", toolpath = ["#/BuildTools/DocBook/SCons"])

################################################################################
# Code generation helper
################################################################################

import sys, re, os.path

def generateDocBookCode(env, target, source) :
    # Parse program
    filename = source[0].abspath
    filenameBase = os.path.basename(filename).replace(".cpp", "")
    inputfile = open(filename)
    program = ""
    programs = {}
    programName = ""
    inEllipsis = False
    for line in inputfile.readlines() :
        if inEllipsis :
            if "//..." in line :
                inEllipsis = False
        else :
            if line.startswith("/*") or line.startswith(" *") :
                continue
            if "//..." in line :
                inEllipsis = True
                line = line.replace("//...", "]]>&#x2026;<![CDATA[")
            else :
                m = re.match("^/// (.*)", line)
                if m :
                    if programName :
                        programs[programName] = program
                    program = ""
                    programName = m.group(1).strip().replace(" ", "")
                    continue
            line = re.sub("\t", "  ", line)
            program += line
    programs[programName] = program
    inputfile.close()

    for programName, program in programs.items() :
        document = "<foo><programlisting><![CDATA[" + program.strip() + "]]></programlisting></foo>"

        # Generate code
        output = open(target[0].abspath, 'w')
        output.write(document)
        output.close()

################################################################################

if "doc" in ARGUMENTS :
    env.DocBook("Swiften Developers Guide.xml")

sources = []
for i in range(1, 7) :
    sources.append("Examples/EchoBot/EchoBot" + str(i) + ".cpp")
sources.append("Examples/EchoBot/EchoBot0x.cpp")
sources += ["Examples/EchoBot/" + i for i in ["EchoPayloadParserFactory.h", "EchoPayloadSerializer.h", "EchoPayload.h", "EchoComponent.cpp"]]
for source in sources :
    env.Command(source + ".xml", source, Action(generateDocBookCode, cmdstr = "$GENCOMSTR"))

SConscript(dirs = ["Examples"])