summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2012-05-08 12:03:21 +0200
committerTor Andersson <tor@ghostscript.com>2012-05-08 10:22:41 +0000
commitfb1663c8181639f49387234f8f4abd5df3d7cc5a (patch)
tree6df99dc2084a7845ca16f9e284cd913b136d44fb /scripts
parent79d3afa22e79363dc687d48af56c627c7879d8c8 (diff)
downloadmupdf-fb1663c8181639f49387234f8f4abd5df3d7cc5a.tar.xz
Add scripts to generate hyperlinked source in HTML.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/runtohtml.sh18
-rw-r--r--scripts/tohtml.py66
2 files changed, 84 insertions, 0 deletions
diff --git a/scripts/runtohtml.sh b/scripts/runtohtml.sh
new file mode 100644
index 00000000..9b94e22b
--- /dev/null
+++ b/scripts/runtohtml.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+mkdir -p doc/source
+rm doc/source/*.html
+
+FILES="fitz/*.[ch] draw/*.[ch] pdf/*.[ch] xps/*.[ch] cbz/*.[ch] apps/*.[ch]"
+
+echo running ctags to make xref
+ctags -x $FILES > tags-xref
+
+for input in $FILES
+do
+ output=doc/source/$(basename $input).html
+ echo $input $output
+ python scripts/tohtml.py < $input > $output
+done
+
+rm tags-xref
diff --git a/scripts/tohtml.py b/scripts/tohtml.py
new file mode 100644
index 00000000..6ad22ecd
--- /dev/null
+++ b/scripts/tohtml.py
@@ -0,0 +1,66 @@
+import sys, os, re
+
+HEADER="""<head>
+<style>
+body { background-color:#fffff0; color:black; margin:16pt; }
+a { text-decoration:none; color:darkblue; }
+a.line { position:relative; padding-top:300px; }
+.comment { color:green; font-style:italic; }
+.comment a { color:darkgreen; }
+</style>
+</head>
+<body><pre><pre>"""
+
+FOOTER="""</pre></body>"""
+
+prefixes = [ 'fz_', 'pdf_', 'xps_', 'cbz_', 'pdfapp_' ]
+
+def is_public(s):
+ for prefix in prefixes:
+ if s.startswith(prefix):
+ return True
+ return False
+
+def load_tags():
+ tags = {}
+ for line in open("tags-xref").readlines():
+ ident, type, line, file, text = line.split(None, 4)
+ if not is_public(ident):
+ continue
+ if type == 'function':
+ tags[ident] = '<a class="function" href="%s#%s">%s</a>' % (os.path.basename(file), line, ident)
+ if type == 'typedef' or type == 'struct':
+ tags[ident] = '<a class="typedef" href="%s#%s">%s</a>' % (os.path.basename(file), line, ident)
+ return tags
+
+tags = load_tags()
+
+def quote(s):
+ return s.replace('&','&amp;').replace('<','&lt;').replace('>','&gt;')
+
+print HEADER
+
+N = 1
+for line in sys.stdin.readlines():
+ # expand tabs, html-quote special characters and colorize comments
+ line = line.replace('\t', ' ').rstrip()
+ line = quote(line)
+ line = line.replace("/*", '<span class="comment">/*')
+ line = line.replace("*/", '*/</span>')
+
+ line = re.sub('^#include "([a-z-]*\.h)"', '#include "<a href="\\1">\\1</a>"', line)
+
+ # find identifiers and hyperlink to their definitions
+ words = re.split("(\W+)", line)
+ line = ""
+ for word in words:
+ if word in tags:
+ word = tags[word]
+ line += word
+
+ #print('<a class="line" name="%d">%4d</a> %s' % (N, N, line))
+ print('<a class="line" name="%d"></a>%s' % (N, line))
+
+ N = N + 1
+
+print FOOTER