Formatting.

docmaker.py will now run with older Python versions also.  Small fix.
This commit is contained in:
Werner Lemberg 2000-08-27 07:12:40 +00:00
parent ec54ffde03
commit 312b59b7c0
2 changed files with 311 additions and 295 deletions

View File

@ -126,140 +126,139 @@ def make_block_list():
# 5 - process source # 5 - process source
# #
comment = [] comment = []
source = [] source = []
state = 0 state = 0
for line in fileinput.input(): for line in fileinput.input():
# remove trailing CR l = len( line )
l = len(line) if l > 0 and line[l - 1] == '\012':
if l > 0 and line[l-1] == '\012': line = line[0 : l - 1]
line = line[0:l-1]
# stripped version of the line # stripped version of the line
line2 = string.strip(line) line2 = string.strip( line )
l = len(line2) l = len( line2 )
# if this line begins with a comment and we're processing some source, exit # if this line begins with a comment and we are processing some
# to state 0 # source, exit to state 0
# #
if format >= 4 and l > 2 and line2[0:2] == '/*': if format >= 4 and l > 2 and line2[0 : 2] == '/*':
list.append( (block,source) ) list.append( ( block, source ) )
format = 0 format = 0
if format == 0: ##################### wait beginning of comment ###########
if l > 3 and line2[0:3] == '/**':
i = 3
while (i < l) and (line2[i] == '*'):
i = i+1
if i == l: if format == 0: #### wait for beginning of comment ####
# this is '/**' followed by any number of '*', the
# beginning of a Format 1 block
#
block = []
source = []
format = 1
elif (i == l-1) and (line2[i] == '/'): if l > 3 and line2[0 : 3] == '/**':
# this is '/**' followed by any number of '*', followed i = 3
# by a '/', i.e. the beginning of a Format 2 or 3 block while i < l and line2[i] == '*':
# i = i + 1
block = []
source = []
format = 2
############################################################## if i == l:
# # this is '/**' followed by any number of '*', the
# FORMAT 1 # beginning of a Format 1 block
# #
elif format == 1: block = []
source = []
format = 1
# if the line doesn't begin with a "*", something went elif i == l - 1 and line2[i] == '/':
# wrong, and we must exit, and forget the current block.. # this is '/**' followed by any number of '*', followed
if (l == 0) or (line2[0] != '*'): # by a '/', i.e. the beginning of a Format 2 or 3 block
block = [] #
format = 0 block = []
source = []
# otherwise, we test for an end of block, which is an format = 2
# arbitrary number of '*', followed by '/'
else: ##############################################################
i = 1 #
while (i < l) and (line2[i] == '*'): # FORMAT 1
i = i+1 #
elif format == 1:
# if the line doesn't begin with a "*", something went
# wrong, and we must exit, and forget the current block..
if l == 0 or line2[0] != '*':
block = []
format = 0
# otherwise, we test for an end of block, which is an
# arbitrary number of '*', followed by '/'
else:
i = 1
while i < l and line2[i] == '*':
i = i + 1
# test for the end of the block
if i < l and line2[i] == '/':
if block != []:
format = 4
else:
format = 0
else:
# otherwise simply append line to current block
block.append( line2 )
# test for the end of the block
if (i < l) and (line2[i] == '/'):
if block != []:
format = 4
else:
format = 0
else:
# otherwise simply append line to current block
block.append(line2)
continue continue
############################################################## ##############################################################
# #
# FORMAT 2 # FORMAT 2
# #
elif format == 2: elif format == 2:
# if the line doesn't begin with '/*' and end with '*/', # if the line doesn't begin with '/*' and end with '*/',
# this is the end of the format 2 format.. # this is the end of the format 2 format
if (l < 4 ) or (line2[:2] != '/*') or (line2[-2:] != '*/'): if l < 4 or line2[: 2] != '/*' or line2[-2 :] != '*/':
if block != []: if block != []:
format = 4 format = 4
else: else:
format = 0 format = 0
else: else:
# remove the start and end comment delimiters, then right-strip # remove the start and end comment delimiters, then
# the line # right-strip the line
line2 = string.rstrip(line2[2:-2]) line2 = string.rstrip( line2[2 : -2] )
# check for end of a format2 block, i.e. a run of '*' # check for end of a format2 block, i.e. a run of '*'
if string.count(line2,'*') == l-4: if string.count( line2, '*' ) == l - 4:
if block != []: if block != []:
format = 4 format = 4
else: else:
format = 0 format = 0
else: else:
# otherwise, add the line to the current block # otherwise, add the line to the current block
block.append(line2) block.append( line2 )
continue continue
if format >= 4: ########################## source processing ################ if format >= 4: #### source processing ####
if l > 0: if l > 0:
format = 5 format = 5
if format == 5: if format == 5:
source.append(line) source.append( line )
if format >= 4: if format >= 4:
list.append([block,source]) list.append( [block, source] )
return list return list
# This function is only used for debugging # This function is only used for debugging
# #
def dump_block_list( list ): def dump_block_list( list ):
"""dump a comment block list""" """dump a comment block list"""
for block in list: for block in list:
print "----------------------------------------" print "----------------------------------------"
for line in block[0]: for line in block[0]:
print line print line
for line in block[1]: for line in block[1]:
print line print line
print "---------the end-----------------------" print "---------the end-----------------------"
@ -271,77 +270,86 @@ def dump_block_list( list ):
# #
class DocCode: class DocCode:
def __init__(self,margin=0): def __init__( self, margin = 0 ):
self.lines = [] self.lines = []
self.margin = margin self.margin = margin
def add(self,line): def add( self, line ):
# remove margin whitespace # remove margin whitespace
if string.strip( line[:self.margin] ) == "": line = line[self.margin:] if string.strip( line[: self.margin] ) == "":
self.lines.append(line) line = line[self.margin :]
self.lines.append( line )
def dump(self): def dump( self ):
max_width = 50 max_width = 50
for line in self.lines: for line in self.lines:
print "--" + line print "--" + line
print "" print ""
def dump_html(self): def dump_html( self ):
# clean the last empty lines # clean the last empty lines
l = len(self.lines)-1 l = len( self.lines ) - 1
while (len > 0) and string.strip(lines[len-1])=="": while len > 0 and string.strip( lines[len - 1] ) == "":
len = len-1 len = len - 1
print code_header print code_header
for line in self.lines[0:len]: for line in self.lines[0 : len]:
print lines print lines
print code_footer print code_footer
############################################################################## ##############################################################################
# #
# The DocParagraph is used to store either simple text paragraphs # The DocParagraph is used to store text paragraphs
# self.words is simply a list of words for the paragraph # self.words is simply a list of words for the paragraph
# #
class DocParagraph: class DocParagraph:
def __init__(self): def __init__( self ):
self.words = [] self.words = []
def add(self,line): def add( self, line ):
# get rid of unwanted spaces in the paragraph # get rid of unwanted spaces in the paragraph
self.words.extend( string.split(line) ) #
# the following line is the same as
#
# self.words.extend( string.split( line ) )
#
# but older Python versions don't have the `extend' attribute
#
self.words[len( self.words ) : len( self.words )] = \
string.split( line )
def dump(self): def dump( self ):
max_width = 50 max_width = 50
cursor = 0 cursor = 0
line = "" line = ""
for word in self.words: for word in self.words:
if cursor+len(word)+1 > max_width: if cursor + len( word ) + 1 > max_width:
print line print line
cursor = 0 cursor = 0
line = "" line = ""
line = line + word + " " line = line + word + " "
cursor = cursor + len(word) + 1 cursor = cursor + len( word ) + 1
if cursor > 0: if cursor > 0:
print line print line
print "" print ""
def dump_html(self): def dump_html( self ):
print para_header print para_header
self.dump() self.dump()
@ -352,33 +360,31 @@ class DocParagraph:
# #
# DocContent is used to store the content of a given marker. # DocContent is used to store the content of a given marker.
# #
#
#
class DocContent: class DocContent:
def __init__(self,lines_list): def __init__( self, lines_list ):
self.items = [] self.items = []
code_mode = 0 code_mode = 0
code_margin = 0 code_margin = 0
text = [] text = []
paragraph = None paragraph = None
code = None code = None
elements = [] elements = []
field = None field = None
for aline in lines_list: for aline in lines_list:
if code_mode == 0: if code_mode == 0:
line = string.lstrip(aline) line = string.lstrip( aline )
l = len(line) l = len( line )
margin = len(aline) - l margin = len( aline ) - l
# if the line is empty, this is the end of the current # if the line is empty, this is the end of the current
# paragraph # paragraph
if l == 0 or line == '{': if l == 0 or line == '{':
if paragraph: if paragraph:
elements.append(paragraph) elements.append( paragraph )
paragraph = None paragraph = None
if line == "": if line == "":
@ -388,87 +394,87 @@ class DocContent:
code_margin = margin code_margin = margin
code = None code = None
continue continue
words = string.split(line) words = string.split( line )
# test for a field delimiter on the start of the line, i.e. # test for a field delimiter on the start of the line, i.e.
# the token `::' # the token `::'
# #
if len(words) >= 2 and words[1] == "::": if len( words ) >= 2 and words[1] == "::":
if paragraph: if paragraph:
elements.append(paragraph) elements.append( paragraph )
paragraph = None paragraph = None
self.items.append( (field,elements) ) self.items.append( ( field, elements ) )
field = words[0] field = words[0]
elements = [] elements = []
words = words[2:] words = words[2 :]
if len(words) > 0: if len( words ) > 0:
line = string.join(words) line = string.join( words )
if not paragraph: if not paragraph:
paragraph = DocParagraph() paragraph = DocParagraph()
paragraph.add( line ) paragraph.add( line )
else: else:
line = aline line = aline
# the code block ends with a line that has a single '}' on it # the code block ends with a line that has a single '}' on it
if line == " "*code_margin+'}': if line == " " * code_margin + '}':
if code: if code:
elements.append(code) elements.append( code )
code = None code = None
code_mode = 0 code_mode = 0
code_margin = 0 code_margin = 0
# otherwise, add the line to the current paragraph # otherwise, add the line to the current paragraph
else: else:
if not code: if not code:
code = DocCode() code = DocCode()
code.add(line) code.add( line )
if paragraph: if paragraph:
elements.append(paragraph) elements.append( paragraph )
if code: if code:
elements.append(code) elements.append( code )
self.items.append( (field,elements) ) self.items.append( ( field, elements ) )
def dump(self): def dump( self ):
for item in self.items: for item in self.items:
field = item[0] field = item[0]
if field: if field:
print "<field "+field+">" print "<field " + field + ">"
for element in item[1]: for element in item[1]:
element.dump() element.dump()
if field: if field:
print "</field> " print "</field> "
def dump_html(self): def dump_html( self ):
n = len(self.items) n = len( self.items )
in_table = 0 in_table = 0
for i in range(n): for i in range( n ):
item = self.items[i] item = self.items[i]
field = item[0] field = item[0]
if not field: if not field:
if in_table: if in_table:
print "</td></tr></table>" print "</td></tr></table>"
in_table = 0 in_table = 0
for element in item[1]: for element in item[1]:
element.dump_html() element.dump_html()
else: else:
if not in_table: if not in_table:
print "<table cellpadding=4><tr valign=top><td>" print "<table cellpadding=4><tr valign=top><td>"
@ -476,7 +482,7 @@ class DocContent:
else: else:
print "</td></tr><tr valign=top><td>" print "</td></tr><tr valign=top><td>"
print "<b>"+field+"</b></td><td>" print "<b>" + field + "</b></td><td>"
for element in item[1]: for element in item[1]:
element.dump_html() element.dump_html()
@ -484,6 +490,7 @@ class DocContent:
if in_table: if in_table:
print "</td></tr></table>" print "</td></tr></table>"
###################################################################################### ######################################################################################
# #
# #
@ -493,9 +500,9 @@ class DocContent:
# #
class DocBlock: class DocBlock:
def __init__(self, block_line_list=[], source_line_list=[]): def __init__( self, block_line_list = [], source_line_list = [] ):
self.markers = [] self.markers = []
self.contents = [] self.contents = []
self.source = source_line_list self.source = source_line_list
marker = "" marker = ""
@ -503,62 +510,65 @@ class DocBlock:
alphanum = string.letters + string.digits + "_" alphanum = string.letters + string.digits + "_"
for line in block_line_list: for line in block_line_list:
line2 = string.lstrip(line) line2 = string.lstrip( line )
l = len(line2) l = len( line2 )
margin = len(line) - l margin = len( line ) - l
if l > 3 and line2[0] == '<': if l > 3 and line2[0] == '<':
i = 1 i = 1
while i < l and line2[i] in alphanum: i = i+1 while i < l and line2[i] in alphanum:
if i < l and line2[i] == '>': i = i + 1
if marker or content: if i < l and line2[i] == '>':
self.add( marker, content ) if marker or content:
marker = line2[1:i] self.add( marker, content )
content = [] marker = line2[1 : i]
line2 = string.lstrip(line2[i+1:]) content = []
l = len(line2) line2 = string.lstrip( line2[i + 1 :] )
line = " "*margin + line2 l = len( line2 )
line = " " * margin + line2
content.append(line)
content.append( line )
if marker or content:
self.add( marker, content ) if marker or content:
self.add( marker, content )
def add( self, marker, lines ): def add( self, marker, lines ):
# remove the first and last empty lines from the content list # remove the first and last empty lines from the content list
l = len(lines) l = len( lines )
if l > 0: if l > 0:
i = 0 i = 0
while l > 0 and string.strip(lines[l-1]) == "": l = l-1 while l > 0 and string.strip( lines[l - 1] ) == "":
while i < l and string.strip(lines[i]) == "": i = i+1 l = l - 1
lines = lines[i:l] while i < l and string.strip( lines[i] ) == "":
l = len(lines) i = i + 1
lines = lines[i : l]
# add a new marker only if its marker and its content list aren't empty l = len( lines )
if l > 0 and marker:
self.markers.append(marker) # add a new marker only if its marker and its content list aren't empty
self.contents.append(lines) if l > 0 and marker:
self.markers.append( marker )
self.contents.append( lines )
def dump( self ): def dump( self ):
for i in range( len(self.markers) ): for i in range( len( self.markers ) ):
print "["+self.markers[i]+"]" print "[" + self.markers[i] + "]"
for line in self.contents[i]: for line in self.contents[i]:
print "-- "+line print "-- " + line
def doc_contents(self): def doc_contents( self ):
contents = [] contents = []
for item in self.contents: for item in self.contents:
contents.append( DocContent(item) ) contents.append( DocContent( item ) )
return contents return contents
def dump_doc_blocks( block_list ): def dump_doc_blocks( block_list ):
for block in block_list: for block in block_list:
docblock = DocBlock(block) docblock = DocBlock( block )
docblock.dump() docblock.dump()
print "<<------------------->>" print "<<------------------->>"
# #
@ -566,64 +576,68 @@ def dump_doc_blocks( block_list ):
# #
def dump_single_content( block_list ): def dump_single_content( block_list ):
block = block_list[0] block = block_list[0]
docblock = DocBlock(block) docblock = DocBlock( block )
print "<block>" print "<block>"
for i in range(len(docblock.markers)): for i in range( len( docblock.markers ) ):
marker = docblock.markers[i] marker = docblock.markers[i]
contents = docblock.contents[i] contents = docblock.contents[i]
print "<marker "+marker+">" print "<marker " + marker + ">"
doccontent = DocContent( contents ) doccontent = DocContent( contents )
doccontent.dump() doccontent.dump()
print "</marker>" print "</marker>"
print "</block>" print "</block>"
def dump_doc_contents( block_list ): def dump_doc_contents( block_list ):
for block in block_list: for block in block_list:
docblock = DocBlock(block) docblock = DocBlock( block )
print "<block>" print "<block>"
for i in range(len(docblock.markers)): for i in range( len( docblock.markers ) ):
print "<marker "+docblock.markers[i]+">" print "<marker " + docblock.markers[i] + ">"
content = DocContent( docblock.contents[i] ) content = DocContent( docblock.contents[i] )
content.dump() content.dump()
print "</marker>" print "</marker>"
print "</block>" print "</block>"
def dump_html_1( block_list ): def dump_html_1( block_list ):
print html_header print html_header
types = [ 'Type', 'Struct', 'FuncType', 'Function', 'Constant', 'Enumeration' ] types = [ 'Type', 'Struct', 'FuncType', 'Function', 'Constant',
'Enumeration' ]
for block in block_list: for block in block_list:
docblock = DocBlock(block[0],block[1]) docblock = DocBlock( block[0], block[1] )
if len(docblock.markers) == 0: if len( docblock.markers ) == 0:
continue continue
print block_header print block_header
for i in range(len(docblock.markers)): for i in range( len( docblock.markers ) ):
marker = docblock.markers[i] marker = docblock.markers[i]
content = docblock.contents[i] content = docblock.contents[i]
dcontent = DocContent( content ) dcontent = DocContent( content )
if marker=="Description": if marker == "Description":
print "<ul><p>" print "<ul><p>"
dcontent.dump() dcontent.dump()
print "</p></ul>" print "</p></ul>"
elif marker in types: elif marker in types:
print "<h3><font color=blue>"+content[0]+"</font></h3>" print "<h3><font color=blue>" + content[0] + "</font></h3>"
else: else:
print "<h4>"+marker+"</h4>" print "<h4>" + marker + "</h4>"
print "<ul><p>" print "<ul><p>"
dcontent.dump_html() dcontent.dump_html()
print "</p></ul>" print "</p></ul>"
@ -634,27 +648,29 @@ def dump_html_1( block_list ):
# print source code # print source code
lines = block[1] lines = block[1]
l = len(lines)-1 l = len( lines ) - 1
while (l >= 0) and string.strip(lines[l])=="": while l >= 0 and string.strip( lines[l] ) == "":
l = l-1 l = l - 1
print source_header print source_header
for line in lines[0:l+1]: for line in lines[0 : l + 1]:
print line print line
print source_footer print source_footer
print html_footer print html_footer
def main(argv): def main( argv ):
"""main program loop""" """main program loop"""
print "extracting comment blocks from sources .." sys.stderr.write( "extracting comment blocks from sources...\n" )
list = make_block_list() list = make_block_list()
dump_html_1( list ) dump_html_1( list )
# If called from the command line # If called from the command line
if __name__=='__main__': main(sys.argv) if __name__ == '__main__':
main( sys.argv )
# eof

View File

@ -325,6 +325,8 @@
/* Because of 32-bit charcodes defined in Unicode (i.e., surrogates), */ /* Because of 32-bit charcodes defined in Unicode (i.e., surrogates), */
/* all character codes must be expressed as FT_Longs. */ /* all character codes must be expressed as FT_Longs. */
/* */ /* */
/* Other encodings might be defined in the future. */
/* */
typedef enum FT_Encoding_ typedef enum FT_Encoding_
{ {
ft_encoding_none = 0, ft_encoding_none = 0,
@ -343,8 +345,6 @@
ft_encoding_apple_roman = FT_MAKE_TAG( 'a', 'r', 'm', 'n' ) ft_encoding_apple_roman = FT_MAKE_TAG( 'a', 'r', 'm', 'n' )
/* other encodings might be defined in the future */
} FT_Encoding; } FT_Encoding;