beta-0.89.2
[luatex.git] / source / libs / zziplib / zziplib-0.13.62 / docs / zzipdoc / functionlisthtmlpage.py
blob4ec9178ca10ee2ad593246692fd144945684250b
1 from options import *
2 from match import Match
4 class FunctionListHtmlPage:
5 """ The main part here is to create a TOC (table of contents) at the
6 start of the page - linking down to the descriptions of the functions.
7 Sure we need to generate anchors on the fly. Additionally, all the
8 non-html (docbook-like) markup needs to be converted for ouput. -
9 each element to be added should implement get_name(), get_head() and
10 get_body() with the latter two having a xml_text() method."""
11 _null_table100 = '<table border="0" width="100%"' \
12 ' cellpadding="0" cellspacing="0">'
13 _ul_start = '<table width="100%">'
14 _ul_end = '</table>'
15 _li_start = '<tr><td valign="top">'
16 _li_end = '</td></tr>'
17 http_opengroup = "http://www.opengroup.org/onlinepubs/000095399/functions/"
18 http_zlib = "http://www.zlib.net/manual.html"
19 def __init__(self, o = None):
20 self.toc = ""
21 self.text = ""
22 self.head = ""
23 self.body = ""
24 self.anchors = []
25 self.o = o
26 if self.o is None: self.o = Options()
27 self.not_found_in_anchors = []
28 def cut(self):
29 self.text += ("<dt>"+self._ul_start+self.head+self._ul_end+"</dt>"+
30 "<dd>"+self._ul_start+self.body+self._ul_end+"</dd>")
31 self.head = ""
32 self.body = ""
33 def add(self, entry):
34 name = entry.get_name()
35 head_text = entry.head_xml_text()
36 body_text = entry.body_xml_text(name)
37 if not head_text:
38 print "no head_text for", name
39 return
40 try:
41 prespec = entry.head_get_prespec()
42 namespec = entry.head_get_namespec()
43 callspec = entry.head_get_callspec()
44 head_text = ("<code><b><function>"+namespec+"</function></b>"
45 +callspec+" : "+prespec+"</code>")
46 except Exception, e:
47 pass
48 try:
49 extraline = ""
50 title = entry.get_title()
51 filename = entry.get_filename().replace("../","")
52 if title:
53 subtitle = '&nbsp;<em>'+title+'</em>'
54 extraline = (self._null_table100+'<td> '+subtitle+' </td>'+
55 '<td align="right"> '+
56 '<em><small>'+filename+'</small></em>'+
57 '</td></table>')
58 body_text = extraline + body_text
59 except Exception, e:
60 pass
61 def link(text):
62 return (text & Match("<function>(\w*)</function>")
63 >> "<link>\\1</link>")
64 def here(text):
65 has_function = Match("<function>(\w*)</function>")
66 if text & has_function:
67 func = has_function[1]
68 self.anchors += [ func ]
69 return (text & has_function
70 >> '<a name="'+"\\1"+'">'+"\\1"+'</a>')
71 else:
72 return text
73 self.toc += self._li_start+self.sane(link(head_text))+self._li_end
74 self.head += self._li_start+self.sane(here(head_text))+self._li_end
75 self.body += self._li_start+self.sane(body_text)+self._li_end
76 def get_title(self):
77 return self.o.package+" Library Functions"
78 def xml_text(self):
79 self.cut()
80 return ("<h2>"+self.get_title()+"</h2>"+
81 self.version_line()+
82 self.mainheader_line()+
83 self._ul_start+
84 self.resolve_links(self.toc)+
85 self._ul_end+
86 "<h3>Documentation</h3>"+
87 "<dl>"+
88 self.resolve_links(self.text)+
89 "</dl>")
90 def version_line(self):
91 if self.o.version:
92 return "<p>Version "+self.o.version+"</p>"
93 return ""
94 def mainheader_line(self):
95 if self.o.onlymainheader:
96 include = "#include &lt;"+self.o.onlymainheader+"&gt;"
97 return "<p><big><b><code>"+include+"</code></b></big></p>"
98 return ""
99 def resolve_links(self, text):
100 text &= (Match("(?s)<link>([^<>]*)(\(\d\))</link>")
101 >> (lambda x: self.resolve_external(x.group(1), x.group(2))))
102 text &= (Match("(?s)<link>(\w+)</link>")
103 >> (lambda x: self.resolve_internal(x.group(1))))
104 if len(self.not_found_in_anchors):
105 print "not found in anchors: ", self.not_found_in_anchors
106 return (text & Match("(?s)<link>([^<>]*)</link>")
107 >> "<code>\\1</code>")
108 def resolve_external(self, func, sect):
109 x = Match()
110 if func & x("^zlib(.*)"):
111 return ('<a href="'+self.http_zlib+x[1]+'">'+
112 "<code>"+func+sect+"</code>"+'</a>')
113 if sect & x("[23]"):
114 return ('<a href="'+self.http_opengroup+func+'.html">'+
115 "<code>"+func+sect+"</code>"+'</a>')
116 return "<code>"+func+"<em>"+sect+"</em></sect>"
117 def resolve_internal(self, func):
118 if func in self.anchors:
119 return '<code><a href="#'+func+'">'+func+"</a></code>"
120 if func not in self.not_found_in_anchors:
121 self.not_found_in_anchors += [ func ]
122 return "<code><u>"+func+"</u></code>"
123 def sane(self, text):
124 return (text
125 .replace("<function>", "<code>")
126 .replace("</function>", "</code>"))