from options import * from match import Match class FunctionListHtmlPage: """ The main part here is to create a TOC (table of contents) at the start of the page - linking down to the descriptions of the functions. Sure we need to generate anchors on the fly. Additionally, all the non-html (docbook-like) markup needs to be converted for ouput. - each element to be added should implement get_name(), get_head() and get_body() with the latter two having a xml_text() method.""" _null_table100 = '' _ul_start = '
' _ul_end = '
' _li_start = '' _li_end = '' http_opengroup = "http://www.opengroup.org/onlinepubs/000095399/functions/" http_zlib = "http://www.zlib.net/manual.html" def __init__(self, o = None): self.toc = "" self.text = "" self.head = "" self.body = "" self.anchors = [] self.o = o if self.o is None: self.o = Options() self.not_found_in_anchors = [] def cut(self): self.text += ("
"+self._ul_start+self.head+self._ul_end+"
"+ "
"+self._ul_start+self.body+self._ul_end+"
") self.head = "" self.body = "" def add(self, entry): name = entry.get_name() head_text = entry.head_xml_text() body_text = entry.body_xml_text(name) if not head_text: print "no head_text for", name return try: prespec = entry.head_get_prespec() namespec = entry.head_get_namespec() callspec = entry.head_get_callspec() head_text = (""+namespec+"" +callspec+" : "+prespec+"") except Exception, e: pass try: extraline = "" title = entry.get_title() filename = entry.get_filename().replace("../","") if title: subtitle = ' '+title+'' extraline = (self._null_table100+' '+subtitle+' '+ ' '+ ''+filename+''+ '') body_text = extraline + body_text except Exception, e: pass def link(text): return (text & Match("(\w*)") >> "\\1") def here(text): has_function = Match("(\w*)") if text & has_function: func = has_function[1] self.anchors += [ func ] return (text & has_function >> ''+"\\1"+'') else: return text self.toc += self._li_start+self.sane(link(head_text))+self._li_end self.head += self._li_start+self.sane(here(head_text))+self._li_end self.body += self._li_start+self.sane(body_text)+self._li_end def get_title(self): return self.o.package+" Library Functions" def xml_text(self): self.cut() return ("

"+self.get_title()+"

"+ self.version_line()+ self.mainheader_line()+ self._ul_start+ self.resolve_links(self.toc)+ self._ul_end+ "

Documentation

"+ "
"+ self.resolve_links(self.text)+ "
") def version_line(self): if self.o.version: return "

Version "+self.o.version+"

" return "" def mainheader_line(self): if self.o.onlymainheader: include = "#include <"+self.o.onlymainheader+">" return "

"+include+"

" return "" def resolve_links(self, text): text &= (Match("(?s)([^<>]*)(\(\d\))") >> (lambda x: self.resolve_external(x.group(1), x.group(2)))) text &= (Match("(?s)(\w+)") >> (lambda x: self.resolve_internal(x.group(1)))) if len(self.not_found_in_anchors): print "not found in anchors: ", self.not_found_in_anchors return (text & Match("(?s)([^<>]*)") >> "\\1") def resolve_external(self, func, sect): x = Match() if func & x("^zlib(.*)"): return (''+ ""+func+sect+""+'') if sect & x("[23]"): return (''+ ""+func+sect+""+'') return ""+func+""+sect+"" def resolve_internal(self, func): if func in self.anchors: return ''+func+"" if func not in self.not_found_in_anchors: self.not_found_in_anchors += [ func ] return ""+func+"" def sane(self, text): return (text .replace("", "") .replace("", ""))