Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
7638 views
1
import sys, os, re
2
3
HEADER="""<head>
4
<style>
5
body { background-color:#fffff0; color:black; margin:16pt; }
6
a { text-decoration:none; color:darkblue; }
7
a.line { position:relative; padding-top:300px; }
8
.comment { color:green; font-style:italic; }
9
.comment a { color:darkgreen; }
10
</style>
11
</head>
12
<body><pre><pre>"""
13
14
FOOTER="""</pre></body>"""
15
16
prefixes = [ 'fz_', 'pdf_', 'xps_', 'cbz_', 'pdfapp_' ]
17
18
def is_public(s):
19
for prefix in prefixes:
20
if s.startswith(prefix):
21
return True
22
return False
23
24
def load_tags():
25
tags = {}
26
for line in open("tags-xref").readlines():
27
ident, type, line, file, text = line.split(None, 4)
28
if not is_public(ident):
29
continue
30
if type == 'function':
31
tags[ident] = '<a class="function" href="%s#%s">%s</a>' % ("/docs/browse/" + file, line, ident)
32
if type == 'typedef' or type == 'struct':
33
tags[ident] = '<a class="typedef" href="%s#%s">%s</a>' % ("/docs/browse/" + file, line, ident)
34
return tags
35
36
tags = load_tags()
37
38
def quote(s):
39
return s.replace('&','&amp;').replace('<','&lt;').replace('>','&gt;')
40
41
print HEADER
42
43
N = 1
44
for line in sys.stdin.readlines():
45
# expand tabs, html-quote special characters and colorize comments
46
line = line.replace('\t', ' ').rstrip()
47
line = quote(line)
48
line = line.replace("/*", '<span class="comment">/*')
49
line = line.replace("*/", '*/</span>')
50
51
line = re.sub('^#include "([a-z-/]*\.h)"', '#include "<a href="/docs/browse/include/\\1">\\1</a>"', line)
52
53
# find identifiers and hyperlink to their definitions
54
words = re.split("(\W+)", line)
55
line = ""
56
for word in words:
57
if word in tags:
58
word = tags[word]
59
line += word
60
61
#print('<a class="line" name="%d">%4d</a> %s' % (N, N, line))
62
print('<a class="line" name="%d"></a>%s' % (N, line))
63
64
N = N + 1
65
66
print FOOTER
67
68