diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-10-09 09:52:51 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-10-09 14:20:47 (GMT) |
commit | c5bb67eab6f97ae0f5f7e673ff0ba9b1111191f4 (patch) | |
tree | ad17bd2ee34263af472340a839a4757859ddaea1 /Documentation/SwiftenDevelopersGuide/SConscript | |
parent | 0a84186a22fd48485deed77bc067877ac332d0b4 (diff) | |
download | swift-c5bb67eab6f97ae0f5f7e673ff0ba9b1111191f4.zip swift-c5bb67eab6f97ae0f5f7e673ff0ba9b1111191f4.tar.bz2 |
Added EchoBot walkthrough example.
Diffstat (limited to 'Documentation/SwiftenDevelopersGuide/SConscript')
-rw-r--r-- | Documentation/SwiftenDevelopersGuide/SConscript | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/Documentation/SwiftenDevelopersGuide/SConscript b/Documentation/SwiftenDevelopersGuide/SConscript index 145663f..fb08a8f 100644 --- a/Documentation/SwiftenDevelopersGuide/SConscript +++ b/Documentation/SwiftenDevelopersGuide/SConscript @@ -2,4 +2,89 @@ Import("env") env.Tool("DocBook", toolpath = ["#/BuildTools/DocBook/SCons"]) +################################################################################ +# Code generation helper +################################################################################ + +import sys, re, os.path + +def generateDocBookCode(env, target, source) : + # Strips empty lines from the beginning & end of a program + def stripEmptyLines(program) : + programLines = program.split('\n') + newProgramLines = [] + inProgram = False + for line in programLines : + if not re.match("^\s*$", line) or inProgram : + inProgram = True + newProgramLines.append(line) + return '\n'.join(newProgramLines).rstrip() + + def createCallouts(program, calloutPrefix) : + newProgramLines = [] + calloutLines = [] + nextID = 0 + for line in program.split("\n") : + # FIXME: Takes the largest match + m = re.match(".*\/* \(\*\) (.*) \*/.*", line) + if m : + cobID = "cob-" + calloutPrefix + "-" + str(nextID) + coID = "co-" + calloutPrefix + "-" + str(nextID) + nextID += 1 + line = re.sub("/\*.*\*/", "]]><co id=\"%(cobID)s\" linkends=\"%(coID)s\"/><![CDATA[" % {"cobID" : cobID, "coID" : coID}, line) + calloutLines.append("<callout arearefs=\"%(cobID)s\" id=\"%(coID)s\"><para>%(text)s</para></callout>" % {"cobID": cobID, "coID": coID, "text": m.group(1)}) + newProgramLines.append(line) + callouts = "<calloutlist>" + "\n".join(calloutLines) + "</calloutlist>" if len(calloutLines) > 0 else "" + return ("\n".join(newProgramLines), callouts) + + # 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("//...", "]]>…<![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() : + program = stripEmptyLines(program) + (program, callouts) = createCallouts(program, filenameBase + "-" + programName) + + document = "<foo><programlisting><![CDATA[" + program + "]]></programlisting>" + callouts + "</foo>" + + # Generate code + output = open(target[0].abspath, 'w') + output.write(document) + output.close() + +################################################################################ + env.DocBook("Swiften Developers Guide.xml") + +for i in range(1, 6) : + source = "Examples/EchoBot/EchoBot" + str(i) + ".cpp" + env.Command(source + ".xml", source, Action(generateDocBookCode, cmdstr = "$GENCOMSTR")) + +SConscript(dirs = ["Examples"]) |