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%">'
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):
26 if self
.o
is None: self
.o
= Options()
27 self
.not_found_in_anchors
= []
29 self
.text
+= ("<dt>"+self
._ul_start
+self
.head
+self
._ul_end
+"</dt>"+
30 "<dd>"+self
._ul_start
+self
.body
+self
._ul_end
+"</dd>")
34 name
= entry
.get_name()
35 head_text
= entry
.head_xml_text()
36 body_text
= entry
.body_xml_text(name
)
38 print "no head_text for", name
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>")
50 title
= entry
.get_title()
51 filename
= entry
.get_filename().replace("../","")
53 subtitle
= ' <em>'+title
+'</em>'
54 extraline
= (self
._null
_table
100+'<td> '+subtitle
+' </td>'+
55 '<td align="right"> '+
56 '<em><small>'+filename
+'</small></em>'+
58 body_text
= extraline
+ body_text
62 return (text
& Match("<function>(\w*)</function>")
63 >> "<link>\\1</link>")
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>')
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
77 return self
.o
.package
+" Library Functions"
80 return ("<h2>"+self
.get_title()+"</h2>"+
82 self
.mainheader_line()+
84 self
.resolve_links(self
.toc
)+
86 "<h3>Documentation</h3>"+
88 self
.resolve_links(self
.text
)+
90 def version_line(self
):
92 return "<p>Version "+self
.o
.version
+"</p>"
94 def mainheader_line(self
):
95 if self
.o
.onlymainheader
:
96 include
= "#include <"+self
.o
.onlymainheader
+">"
97 return "<p><big><b><code>"+include
+"</code></b></big></p>"
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
):
110 if func
& x("^zlib(.*)"):
111 return ('<a href="'+self
.http_zlib
+x
[1]+'">'+
112 "<code>"+func
+sect
+"</code>"+'</a>')
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
):
125 .replace("<function>", "<code>")
126 .replace("</function>", "</code>"))