summaryrefslogtreecommitdiff
path: root/scripts/tohtml.py
blob: b6cb548e20b58db99d492284cea7fba917a9cda8 (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
65
66
67
68
69
import sys, os, re

HEADER="""<!DOCTYPE html>
<html>
<head>
<style>
body { background-color:white; 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>"""

FOOTER="""</pre></body>"""

prefixes = [ 'fz_', 'pdf_', 'xps_', 'cbz_', 'html_', 'epub_', 'svg_', 'ui_', 'pdfapp_' ]

def is_public(s):
	for prefix in prefixes:
		if s.startswith(prefix):
			return True
	return False

def load_tags(curfile):
	tags = {}
	for line in open("tags-xref").readlines():
		ident, type, line, file, text = line.split(None, 4)
		if not is_public(ident) and file != curfile:
			continue
		if type == 'function' or type == 'macro':
			tags[ident] = '<a class="function" href="%s#%s">%s</a>' % ("/docs/browse/" + file, line, ident)
		if type == 'typedef':
			tags[ident] = '<a class="typedef" href="%s#%s">%s</a>' % ("/docs/browse/" + file, line, ident)
	return tags

tags = load_tags(sys.argv[1])

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="/docs/browse/include/\\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