From b98dbcdddff0d758bfeddace5535bdcd4bce174a Mon Sep 17 00:00:00 2001 From: Lars Luthman Date: Fri, 11 Mar 2011 22:26:38 +0000 Subject: lv2specgen.py creates links for every mention of a header file, preprocessor define, data structure etc --- gendoc.py | 10 ++++++++-- lv2specgen/lv2specgen.py | 31 +++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/gendoc.py b/gendoc.py index 3ce14b3..94b6814 100755 --- a/gendoc.py +++ b/gendoc.py @@ -21,6 +21,7 @@ URIPREFIX = 'http://lv2plug.in/ns/' DOXPREFIX = 'http://lv2plug.in/ns/doc/html/' SPECGENDIR = './specgen' STYLEURI = os.path.join('aux', 'style.css') +TAGFILE = './doclinks' release_dir = os.path.join('build', 'spec') try: @@ -51,14 +52,17 @@ def getChildText(elt, tagname): tagdoc = xml.dom.minidom.parse('c_tags') root = tagdoc.documentElement -bettertags = open('c_bettertags', 'w') +bettertags = open(TAGFILE, 'w') for cn in root.childNodes: if cn.nodeType == xml.dom.Node.ELEMENT_NODE and cn.tagName == 'compound': if cn.getAttribute('kind') == 'page': continue name = getChildText(cn, 'name') filename = getChildText(cn, 'filename') - bettertags.write('%s %s%s.html\n' % (name, DOXPREFIX, filename)) + # Sometimes the .html is there, sometimes it isn't... + if filename[-5:] != '.html': + filename += '.html' + bettertags.write('%s %s%s\n' % (name, DOXPREFIX, filename)) if cn.getAttribute('kind') == 'file': prefix = '' else: @@ -88,6 +92,7 @@ def gendoc(specgen_dir, bundle_dir, ttl_filename, html_filename): STYLEURI, os.path.join(out_base, html_filename), os.path.join('..', '..'), + TAGFILE, '-i']) gendoc('./lv2specgen', 'core.lv2', 'lv2.ttl', 'lv2core/lv2core.html') @@ -163,6 +168,7 @@ SELECT ?rev FROM <%s.lv2/%s.ttl> WHERE { <%s> doap:release [ doap:revision ?rev STYLEURI, '%s.lv2/%s.html' % (b, b), os.path.join('..', '..', '..'), + os.path.join('..', '..', '..', TAGFILE), '-i'], cwd=outdir); li = '
  • ' diff --git a/lv2specgen/lv2specgen.py b/lv2specgen/lv2specgen.py index 9b9ce1a..e69cb2e 100755 --- a/lv2specgen/lv2specgen.py +++ b/lv2specgen/lv2specgen.py @@ -60,6 +60,7 @@ except ImportError: #global vars classranges = {} classdomains = {} +linkmap = {} spec_url = None spec_ns_str = None spec_ns = None @@ -128,9 +129,14 @@ def getComment(m, urinode): 'struct' + match.replace('_', '__') + '.html') markup = markup.replace('href="urn:struct:' + match + '"', 'href="' + struct_uri + '"') - - return markup - + + rgx = re.compile('([^a-zA-Z0-9_:])(' + \ + '|'.join(map(re.escape, linkmap)) + \ + ')([^a-aA-Z0-9_:])') + def translate(match): + return match.group(1) + linkmap[match.group(2)] + match.group(3) + return rgx.sub(translate, markup) + c = m.find_statements(RDF.Statement(urinode, rdfs.comment, None)) if c.current(): text = c.current().object.literal_value['string'] @@ -662,7 +668,7 @@ def getInstances(model, classes, properties): return instances -def specgen(specloc, docdir, template, instances=False, mode="spec"): +def specgen(specloc, docdir, template, doclinks, instances=False, mode="spec"): """The meat and potatoes: Everything starts here.""" global spec_url @@ -670,7 +676,13 @@ def specgen(specloc, docdir, template, instances=False, mode="spec"): global spec_ns global spec_pre global ns_list - + + # Build a symbol -> link mapping for external links + dlfile = open(doclinks, 'r') + for line in dlfile: + sym, _, url = line.rstrip().partition(' ') + linkmap[sym] = '%s' % (url, sym) + m = RDF.Model() try: base = specloc[0:specloc.rfind('/')] @@ -913,6 +925,9 @@ if __name__ == "__main__": # Doxygen documentation directory doc_base = args[4] + + # C symbol -> doxygen link mapping + doc_links = args[5] template = template.replace('@STYLE_URI@', os.path.join(doc_base, style_uri)) @@ -920,8 +935,8 @@ if __name__ == "__main__": # Flags instances = False - if len(args) > 4: - flags = args[4:] + if len(args) > 5: + flags = args[5:] i = 0 while i < len(flags): if flags[i] == '-i': @@ -931,5 +946,5 @@ if __name__ == "__main__": i += 1 i += 1 - save(dest, specgen(specloc, docdir, template, instances=instances)) + save(dest, specgen(specloc, docdir, template, doc_links, instances=instances)) -- cgit v1.2.1