2000-01-10 16:49:01 +01:00
|
|
|
|
#!/usr/bin/env python
|
|
|
|
|
#
|
|
|
|
|
# DocMaker is a very simple program used to generate HTML documentation
|
|
|
|
|
# from the source files of the FreeType packages.
|
|
|
|
|
#
|
2000-10-26 02:06:35 +02:00
|
|
|
|
# I should really be using regular expressions to do this, but hey,
|
|
|
|
|
# i'm too lazy right now, and the damn thing seems to work :-)
|
|
|
|
|
# - David
|
|
|
|
|
#
|
2000-01-10 16:49:01 +01:00
|
|
|
|
|
2001-01-10 12:15:48 +01:00
|
|
|
|
import fileinput, sys, string, glob
|
2000-01-10 16:49:01 +01:00
|
|
|
|
|
2001-01-11 10:27:49 +01:00
|
|
|
|
html_header = """\
|
2000-08-22 01:01:32 +02:00
|
|
|
|
<html>
|
|
|
|
|
<header>
|
|
|
|
|
<title>FreeType 2 API Reference</title>
|
|
|
|
|
<basefont face="Georgia, Arial, Helvetica, Geneva">
|
|
|
|
|
<style content="text/css">
|
|
|
|
|
P { text-align=justify }
|
|
|
|
|
H1 { text-align=center }
|
|
|
|
|
LI { text-align=justify }
|
|
|
|
|
</style>
|
|
|
|
|
</header>
|
2001-01-11 10:27:49 +01:00
|
|
|
|
<body text=#000000
|
|
|
|
|
bgcolor=#FFFFFF
|
|
|
|
|
link=#0000EF
|
|
|
|
|
vlink=#51188E
|
|
|
|
|
alink=#FF0000>
|
2000-08-22 01:01:32 +02:00
|
|
|
|
<center><h1>FreeType 2 API Reference</h1></center>
|
|
|
|
|
"""
|
|
|
|
|
|
2001-01-11 10:27:49 +01:00
|
|
|
|
html_footer = """\
|
2000-08-22 01:01:32 +02:00
|
|
|
|
</body>
|
2001-01-11 10:27:49 +01:00
|
|
|
|
</html>"""
|
2000-12-05 15:49:39 +01:00
|
|
|
|
|
2001-01-11 10:27:49 +01:00
|
|
|
|
section_title_header = "<center><h1>"
|
|
|
|
|
section_title_footer = "</h1></center>"
|
2000-08-22 01:01:32 +02:00
|
|
|
|
|
2001-01-11 10:27:49 +01:00
|
|
|
|
code_header = "<font color=blue><pre>"
|
|
|
|
|
code_footer = "</pre></font>"
|
2000-08-22 01:01:32 +02:00
|
|
|
|
|
|
|
|
|
para_header = "<p>"
|
|
|
|
|
para_footer = "</p>"
|
|
|
|
|
|
2001-02-02 06:24:11 +01:00
|
|
|
|
block_header = "<center><table width=75%><tr><td>"
|
|
|
|
|
block_footer = "</td></tr></table><hr width=75%></center>"
|
2000-08-22 01:01:32 +02:00
|
|
|
|
|
2001-01-12 01:33:30 +01:00
|
|
|
|
description_header = "<center><table width=87%><tr><td>"
|
2001-01-11 10:27:49 +01:00
|
|
|
|
description_footer = "</td></tr></table></center><br>"
|
2001-01-10 07:53:49 +01:00
|
|
|
|
|
2001-01-12 01:33:30 +01:00
|
|
|
|
marker_header = "<center><table width=87% cellpadding=5><tr bgcolor=#EEEEFF><td><em><b>"
|
2001-01-10 07:53:49 +01:00
|
|
|
|
marker_inter = "</b></em></td></tr><tr><td>"
|
|
|
|
|
marker_footer = "</td></tr></table></center>"
|
|
|
|
|
|
2001-01-12 01:33:30 +01:00
|
|
|
|
source_header = "<center><table width=87%><tr bgcolor=#D6E8FF width=100%><td><pre>"
|
2001-01-11 10:27:49 +01:00
|
|
|
|
source_footer = "</pre></table></center><br>"
|
2000-08-22 01:01:32 +02:00
|
|
|
|
|
2001-02-13 18:42:49 +01:00
|
|
|
|
chapter_header = "<center><table width=75%><tr><td><h2>"
|
|
|
|
|
chapter_inter = "</h2><ul>"
|
|
|
|
|
chapter_footer = "</ul></td></tr></table></center>"
|
2000-12-05 15:49:39 +01:00
|
|
|
|
|
|
|
|
|
current_section = None
|
|
|
|
|
|
|
|
|
|
|
2001-02-03 04:00:06 +01:00
|
|
|
|
# This function is used to sort the index. It's a simple lexicographical
|
|
|
|
|
# sort, except that it places capital letters before small ones.
|
2001-02-02 06:24:11 +01:00
|
|
|
|
#
|
|
|
|
|
def index_sort( s1, s2 ):
|
|
|
|
|
if not s1:
|
|
|
|
|
return -1
|
|
|
|
|
|
|
|
|
|
if not s2:
|
|
|
|
|
return 1
|
|
|
|
|
|
2001-02-03 04:00:06 +01:00
|
|
|
|
l1 = len( s1 )
|
|
|
|
|
l2 = len( s2 )
|
|
|
|
|
m1 = string.lower( s1 )
|
|
|
|
|
m2 = string.lower( s2 )
|
2001-02-02 06:24:11 +01:00
|
|
|
|
|
2001-02-03 04:00:06 +01:00
|
|
|
|
for i in range( l1 ):
|
2001-02-02 06:24:11 +01:00
|
|
|
|
if i >= l2 or m1[i] > m2[i]:
|
|
|
|
|
return 1
|
2001-02-14 05:59:57 +01:00
|
|
|
|
|
2001-02-02 06:24:11 +01:00
|
|
|
|
if m1[i] < m2[i]:
|
|
|
|
|
return -1
|
|
|
|
|
|
|
|
|
|
if s1[i] < s2[i]:
|
|
|
|
|
return -1
|
|
|
|
|
|
|
|
|
|
if s1[i] > s2[i]:
|
|
|
|
|
return 1
|
2001-02-14 05:59:57 +01:00
|
|
|
|
|
2001-02-02 06:24:11 +01:00
|
|
|
|
if l2 > l1:
|
|
|
|
|
return -1
|
2001-02-14 05:59:57 +01:00
|
|
|
|
|
|
|
|
|
return 0
|
2001-02-02 06:24:11 +01:00
|
|
|
|
|
|
|
|
|
|
2001-02-13 18:42:49 +01:00
|
|
|
|
# sort input_list, placing the elements of order_list in front
|
|
|
|
|
#
|
|
|
|
|
def sort_order_list( input_list, order_list ):
|
|
|
|
|
new_list = order_list[:]
|
|
|
|
|
for id in input_list:
|
|
|
|
|
if not id in order_list:
|
2001-02-14 05:59:57 +01:00
|
|
|
|
new_list.append( id )
|
2001-02-13 18:42:49 +01:00
|
|
|
|
return new_list
|
|
|
|
|
|
|
|
|
|
|
2000-08-22 01:01:32 +02:00
|
|
|
|
# The FreeType 2 reference is extracted from the source files. These contain
|
|
|
|
|
# various comment blocks that follow one of the following formats:
|
2000-01-10 16:49:01 +01:00
|
|
|
|
#
|
|
|
|
|
# /**************************
|
|
|
|
|
# *
|
|
|
|
|
# * FORMAT1
|
|
|
|
|
# *
|
|
|
|
|
# *
|
|
|
|
|
# *
|
|
|
|
|
# *
|
|
|
|
|
# *************************/
|
|
|
|
|
#
|
|
|
|
|
# /**************************/
|
|
|
|
|
# /* */
|
|
|
|
|
# /* FORMAT2 */
|
|
|
|
|
# /* */
|
|
|
|
|
# /* */
|
|
|
|
|
# /* */
|
|
|
|
|
# /* */
|
|
|
|
|
#
|
|
|
|
|
# /**************************/
|
|
|
|
|
# /* */
|
|
|
|
|
# /* FORMAT3 */
|
|
|
|
|
# /* */
|
|
|
|
|
# /* */
|
|
|
|
|
# /* */
|
|
|
|
|
# /* */
|
|
|
|
|
# /**************************/
|
|
|
|
|
#
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# Each block contains a list of markers; each one can be followed by
|
2000-08-22 01:01:32 +02:00
|
|
|
|
# some arbitrary text or a list of fields. Here's an example:
|
|
|
|
|
#
|
|
|
|
|
# <Struct>
|
|
|
|
|
# MyStruct
|
|
|
|
|
#
|
|
|
|
|
# <Description>
|
|
|
|
|
# this structure holds some data
|
|
|
|
|
#
|
|
|
|
|
# <Fields>
|
|
|
|
|
# x :: horizontal coordinate
|
|
|
|
|
# y :: vertical coordinate
|
|
|
|
|
#
|
|
|
|
|
#
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# This example defines three markers: 'Struct', 'Description' & 'Fields'.
|
2000-08-22 01:01:32 +02:00
|
|
|
|
# The first two markers contain arbitrary text, while the last one contains
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# a list of fields.
|
2000-08-22 01:01:32 +02:00
|
|
|
|
#
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# Each field is simple of the format: WORD :: TEXT...
|
2000-08-22 01:01:32 +02:00
|
|
|
|
#
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# Note that typically each comment block is followed by some source
|
|
|
|
|
# code declaration that may need to be kept in the reference.
|
2000-01-10 16:49:01 +01:00
|
|
|
|
#
|
2000-10-23 20:32:55 +02:00
|
|
|
|
# Note that markers can alternatively be written as "@MARKER:"
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# instead of "<MARKER>". All marker identifiers are converted to
|
|
|
|
|
# lower case during parsing in order to simply sorting.
|
2000-10-23 20:32:55 +02:00
|
|
|
|
#
|
2000-10-26 02:06:35 +02:00
|
|
|
|
# We associate with each block the following source lines that do not
|
|
|
|
|
# begin with a comment. For example, the following:
|
|
|
|
|
#
|
|
|
|
|
# /**********************************
|
|
|
|
|
# *
|
|
|
|
|
# * <mytag> blabla
|
|
|
|
|
# *
|
|
|
|
|
# */
|
|
|
|
|
#
|
|
|
|
|
# bla_bla_bla
|
|
|
|
|
# bilip_bilip
|
|
|
|
|
#
|
|
|
|
|
# /* - this comment acts as a separator - */
|
|
|
|
|
#
|
|
|
|
|
# blo_blo_blo
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
# will only keep the first two lines of sources with
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# the "blabla" block.
|
2000-10-26 02:06:35 +02:00
|
|
|
|
#
|
|
|
|
|
# However, the comment will be kept, with following source lines
|
|
|
|
|
# if it contains a starting '#' or '@' as in:
|
|
|
|
|
#
|
|
|
|
|
# /*@.....*/
|
|
|
|
|
# /*#.....*/
|
|
|
|
|
# /* @.....*/
|
|
|
|
|
# /* #.....*/
|
|
|
|
|
#
|
2000-01-10 16:49:01 +01:00
|
|
|
|
|
2000-08-22 01:01:32 +02:00
|
|
|
|
|
2000-01-10 16:49:01 +01:00
|
|
|
|
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#############################################################################
|
2000-01-10 16:49:01 +01:00
|
|
|
|
#
|
2000-08-22 01:01:32 +02:00
|
|
|
|
# The DocCode class is used to store source code lines
|
2000-01-10 16:49:01 +01:00
|
|
|
|
#
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# 'self.lines' contains a set of source code lines that will
|
2000-10-26 09:52:40 +02:00
|
|
|
|
# be dumped as HTML in a <PRE> tag.
|
|
|
|
|
#
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# The object is filled line by line by the parser; it strips the
|
2000-10-26 09:52:40 +02:00
|
|
|
|
# leading "margin" space from each input line before storing it
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# in 'self.lines'.
|
2000-10-26 09:52:40 +02:00
|
|
|
|
#
|
2000-08-22 01:01:32 +02:00
|
|
|
|
class DocCode:
|
2000-01-10 16:49:01 +01:00
|
|
|
|
|
2000-08-27 09:12:40 +02:00
|
|
|
|
def __init__( self, margin = 0 ):
|
|
|
|
|
self.lines = []
|
2000-10-31 21:42:18 +01:00
|
|
|
|
self.margin = margin
|
|
|
|
|
|
2000-12-06 17:31:30 +01:00
|
|
|
|
|
2000-08-27 09:12:40 +02:00
|
|
|
|
def add( self, line ):
|
2000-08-22 01:01:32 +02:00
|
|
|
|
# remove margin whitespace
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
2000-08-27 09:12:40 +02:00
|
|
|
|
if string.strip( line[: self.margin] ) == "":
|
|
|
|
|
line = line[self.margin :]
|
|
|
|
|
self.lines.append( line )
|
2000-01-10 16:49:01 +01:00
|
|
|
|
|
|
|
|
|
|
2000-10-26 09:52:40 +02:00
|
|
|
|
def dump( self ):
|
2000-08-22 01:01:32 +02:00
|
|
|
|
for line in self.lines:
|
|
|
|
|
print "--" + line
|
2000-08-27 09:12:40 +02:00
|
|
|
|
print ""
|
2000-01-10 16:49:01 +01:00
|
|
|
|
|
2000-12-06 17:31:30 +01:00
|
|
|
|
|
2000-10-26 09:52:40 +02:00
|
|
|
|
def get_identifier( self ):
|
|
|
|
|
# this function should never be called
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
|
|
|
|
return "UNKNOWN_CODE_IDENTIFIER!"
|
2000-01-10 16:49:01 +01:00
|
|
|
|
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2001-01-12 01:33:30 +01:00
|
|
|
|
def dump_html( self, identifiers = None ):
|
2000-08-22 01:01:32 +02:00
|
|
|
|
# clean the last empty lines
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
2000-08-27 09:12:40 +02:00
|
|
|
|
l = len( self.lines ) - 1
|
2000-10-26 09:52:40 +02:00
|
|
|
|
while l > 0 and string.strip( self.lines[l - 1] ) == "":
|
|
|
|
|
l = l - 1
|
2000-01-10 16:49:01 +01:00
|
|
|
|
|
2001-01-11 10:27:49 +01:00
|
|
|
|
# the code footer should be directly appended to the last code
|
|
|
|
|
# line to avoid an additional blank line
|
|
|
|
|
#
|
|
|
|
|
sys.stdout.write( code_header )
|
2001-02-13 18:42:49 +01:00
|
|
|
|
for line in self.lines[0 : l+1]:
|
2001-01-11 10:27:49 +01:00
|
|
|
|
sys.stdout.write( '\n' + line )
|
|
|
|
|
sys.stdout.write( code_footer )
|
|
|
|
|
|
2000-01-10 16:49:01 +01:00
|
|
|
|
|
2000-08-22 01:01:32 +02:00
|
|
|
|
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#############################################################################
|
2000-01-10 16:49:01 +01:00
|
|
|
|
#
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# The DocParagraph is used to store text paragraphs.
|
|
|
|
|
# 'self.words' is simply a list of words for the paragraph.
|
2000-01-10 16:49:01 +01:00
|
|
|
|
#
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# The paragraph is filled line by line by the parser.
|
2000-10-26 09:52:40 +02:00
|
|
|
|
#
|
2000-08-22 01:01:32 +02:00
|
|
|
|
class DocParagraph:
|
|
|
|
|
|
2000-08-27 09:12:40 +02:00
|
|
|
|
def __init__( self ):
|
|
|
|
|
self.words = []
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-12-06 17:31:30 +01:00
|
|
|
|
|
2000-08-27 09:12:40 +02:00
|
|
|
|
def add( self, line ):
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# Get rid of unwanted spaces in the paragraph.
|
2000-08-27 09:12:40 +02:00
|
|
|
|
#
|
2001-01-11 10:27:49 +01:00
|
|
|
|
# The following two lines are the same as
|
2000-08-27 09:12:40 +02:00
|
|
|
|
#
|
|
|
|
|
# self.words.extend( string.split( line ) )
|
|
|
|
|
#
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# but older Python versions don't have the `extend' attribute.
|
2000-08-27 09:12:40 +02:00
|
|
|
|
#
|
2001-01-11 10:27:49 +01:00
|
|
|
|
last = len( self.words )
|
2001-02-14 05:59:57 +01:00
|
|
|
|
self.words[last : last] = string.split( line )
|
2000-10-26 09:52:40 +02:00
|
|
|
|
|
2000-12-06 17:31:30 +01:00
|
|
|
|
|
|
|
|
|
# This function is used to retrieve the first word of a given
|
|
|
|
|
# paragraph.
|
|
|
|
|
#
|
2000-10-26 09:52:40 +02:00
|
|
|
|
def get_identifier( self ):
|
|
|
|
|
if self.words:
|
|
|
|
|
return self.words[0]
|
|
|
|
|
|
|
|
|
|
# should never happen
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
|
|
|
|
return "UNKNOWN_PARA_IDENTIFIER!"
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
|
|
|
|
|
2001-02-02 06:24:11 +01:00
|
|
|
|
def get_words( self ):
|
|
|
|
|
return self.words[:]
|
|
|
|
|
|
|
|
|
|
|
2001-01-12 01:33:30 +01:00
|
|
|
|
def dump( self, identifiers = None ):
|
2000-08-27 09:12:40 +02:00
|
|
|
|
max_width = 50
|
2000-08-22 01:01:32 +02:00
|
|
|
|
cursor = 0
|
|
|
|
|
line = ""
|
2001-01-12 01:33:30 +01:00
|
|
|
|
extra = None
|
|
|
|
|
alphanum = string.lowercase + string.uppercase + string.digits + '_'
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-08-22 01:01:32 +02:00
|
|
|
|
for word in self.words:
|
2001-01-16 00:11:55 +01:00
|
|
|
|
# process cross references if needed
|
|
|
|
|
#
|
2001-01-12 01:33:30 +01:00
|
|
|
|
if identifiers and word and word[0] == '@':
|
2001-02-14 05:59:57 +01:00
|
|
|
|
word = word[1 :]
|
2001-01-12 01:33:30 +01:00
|
|
|
|
|
2001-01-16 00:11:55 +01:00
|
|
|
|
# we need to find non-alphanumeric characters
|
|
|
|
|
#
|
|
|
|
|
i = len( word )
|
|
|
|
|
while i > 0 and not word[i - 1] in alphanum:
|
|
|
|
|
i = i - 1
|
2001-02-14 05:59:57 +01:00
|
|
|
|
|
2001-01-12 01:33:30 +01:00
|
|
|
|
if i > 0:
|
2001-02-14 05:59:57 +01:00
|
|
|
|
extra = word[i :]
|
|
|
|
|
word = word[0 : i]
|
2001-01-12 01:33:30 +01:00
|
|
|
|
|
|
|
|
|
block = identifiers.get( word )
|
|
|
|
|
if block:
|
2001-01-16 00:11:55 +01:00
|
|
|
|
word = '<a href="' + block.html_address() + '">' + word + '</a>'
|
2001-01-12 01:33:30 +01:00
|
|
|
|
else:
|
2001-01-16 00:11:55 +01:00
|
|
|
|
word = '?' + word
|
2001-01-12 01:33:30 +01:00
|
|
|
|
|
2000-08-27 09:12:40 +02:00
|
|
|
|
if cursor + len( word ) + 1 > max_width:
|
|
|
|
|
print line
|
|
|
|
|
cursor = 0
|
|
|
|
|
line = ""
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2001-01-16 00:11:55 +01:00
|
|
|
|
line = line + word
|
2001-01-12 01:33:30 +01:00
|
|
|
|
if not extra:
|
|
|
|
|
line = line + " "
|
2001-01-16 00:11:55 +01:00
|
|
|
|
|
2000-08-27 09:12:40 +02:00
|
|
|
|
cursor = cursor + len( word ) + 1
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2001-01-16 00:11:55 +01:00
|
|
|
|
# handle trailing periods, commas, etc. at the end of
|
|
|
|
|
# cross references.
|
|
|
|
|
#
|
2001-01-12 01:33:30 +01:00
|
|
|
|
if extra:
|
|
|
|
|
if cursor + len( extra ) + 1 > max_width:
|
|
|
|
|
print line
|
|
|
|
|
cursor = 0
|
2001-01-16 00:11:55 +01:00
|
|
|
|
line = ""
|
2001-01-12 01:33:30 +01:00
|
|
|
|
|
|
|
|
|
line = line + extra + " "
|
|
|
|
|
cursor = cursor + len( extra ) + 1
|
|
|
|
|
extra = None
|
|
|
|
|
|
2000-08-22 01:01:32 +02:00
|
|
|
|
if cursor > 0:
|
2000-08-27 09:12:40 +02:00
|
|
|
|
print line
|
2000-08-22 01:01:32 +02:00
|
|
|
|
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# print "<22>" # for debugging only
|
2000-08-22 01:01:32 +02:00
|
|
|
|
|
|
|
|
|
|
2000-12-05 15:49:39 +01:00
|
|
|
|
def dump_string( self ):
|
|
|
|
|
s = ""
|
|
|
|
|
space = ""
|
|
|
|
|
for word in self.words:
|
|
|
|
|
s = s + space + word
|
|
|
|
|
space = " "
|
|
|
|
|
|
|
|
|
|
return s
|
|
|
|
|
|
|
|
|
|
|
2001-01-12 01:33:30 +01:00
|
|
|
|
def dump_html( self, identifiers = None ):
|
2000-08-22 01:01:32 +02:00
|
|
|
|
print para_header
|
2001-01-12 01:33:30 +01:00
|
|
|
|
self.dump( identifiers )
|
2000-08-22 01:01:32 +02:00
|
|
|
|
print para_footer
|
|
|
|
|
|
|
|
|
|
|
2001-01-11 10:27:49 +01:00
|
|
|
|
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#############################################################################
|
2000-01-10 16:49:01 +01:00
|
|
|
|
#
|
2000-08-22 01:01:32 +02:00
|
|
|
|
# DocContent is used to store the content of a given marker.
|
2000-01-10 16:49:01 +01:00
|
|
|
|
#
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# The "self.items" list contains (field,elements) records, where
|
2000-10-23 20:32:55 +02:00
|
|
|
|
# "field" corresponds to a given structure fields or function
|
|
|
|
|
# parameter (indicated by a "::"), or NULL for a normal section
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# of text/code.
|
2000-10-23 20:32:55 +02:00
|
|
|
|
#
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# Hence, the following example:
|
2000-10-23 20:32:55 +02:00
|
|
|
|
#
|
|
|
|
|
# <MyMarker>
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# This is an example of what can be put in a content section,
|
2000-10-23 20:32:55 +02:00
|
|
|
|
#
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# A second line of example text.
|
2000-10-23 20:32:55 +02:00
|
|
|
|
#
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# x :: A simple test field, with some contents.
|
|
|
|
|
# y :: Even before, this field has some code contents.
|
2000-10-23 20:32:55 +02:00
|
|
|
|
# {
|
|
|
|
|
# y = x+2;
|
|
|
|
|
# }
|
|
|
|
|
#
|
|
|
|
|
# should be stored as
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
2000-10-23 20:32:55 +02:00
|
|
|
|
# [ ( None, [ DocParagraph, DocParagraph] ),
|
|
|
|
|
# ( "x", [ DocParagraph ] ),
|
|
|
|
|
# ( "y", [ DocParagraph, DocCode ] ) ]
|
2000-10-31 21:42:18 +01:00
|
|
|
|
#
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# in 'self.items'.
|
2000-10-26 09:52:40 +02:00
|
|
|
|
#
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# The DocContent object is entirely built at creation time; you must
|
|
|
|
|
# pass a list of input text lines in the "lines_list" parameter.
|
2000-10-26 09:52:40 +02:00
|
|
|
|
#
|
2000-01-10 16:49:01 +01:00
|
|
|
|
class DocContent:
|
|
|
|
|
|
2000-08-27 09:12:40 +02:00
|
|
|
|
def __init__( self, lines_list ):
|
|
|
|
|
self.items = []
|
|
|
|
|
code_mode = 0
|
|
|
|
|
code_margin = 0
|
|
|
|
|
text = []
|
2000-10-26 09:52:40 +02:00
|
|
|
|
paragraph = None # represents the current DocParagraph
|
|
|
|
|
code = None # represents the current DocCode
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-10-26 09:52:40 +02:00
|
|
|
|
elements = [] # the list of elements for the current field,
|
|
|
|
|
# contains DocParagraph or DocCode objects
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-10-26 09:52:40 +02:00
|
|
|
|
field = None # the current field
|
2000-08-27 09:12:40 +02:00
|
|
|
|
|
|
|
|
|
for aline in lines_list:
|
|
|
|
|
if code_mode == 0:
|
|
|
|
|
line = string.lstrip( aline )
|
|
|
|
|
l = len( line )
|
|
|
|
|
margin = len( aline ) - l
|
|
|
|
|
|
|
|
|
|
# if the line is empty, this is the end of the current
|
|
|
|
|
# paragraph
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
2000-08-27 09:12:40 +02:00
|
|
|
|
if l == 0 or line == '{':
|
|
|
|
|
if paragraph:
|
|
|
|
|
elements.append( paragraph )
|
2000-08-22 01:01:32 +02:00
|
|
|
|
paragraph = None
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-08-22 01:01:32 +02:00
|
|
|
|
if line == "":
|
|
|
|
|
continue
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-08-22 01:01:32 +02:00
|
|
|
|
code_mode = 1
|
|
|
|
|
code_margin = margin
|
|
|
|
|
code = None
|
|
|
|
|
continue
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-08-27 09:12:40 +02:00
|
|
|
|
words = string.split( line )
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-08-27 09:12:40 +02:00
|
|
|
|
# test for a field delimiter on the start of the line, i.e.
|
|
|
|
|
# the token `::'
|
|
|
|
|
#
|
|
|
|
|
if len( words ) >= 2 and words[1] == "::":
|
2000-10-26 09:52:40 +02:00
|
|
|
|
# start a new field - complete current paragraph if any
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
2000-08-27 09:12:40 +02:00
|
|
|
|
if paragraph:
|
|
|
|
|
elements.append( paragraph )
|
2000-08-22 01:01:32 +02:00
|
|
|
|
paragraph = None
|
|
|
|
|
|
2000-10-26 09:52:40 +02:00
|
|
|
|
# append previous "field" to self.items
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
2000-08-27 09:12:40 +02:00
|
|
|
|
self.items.append( ( field, elements ) )
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-10-26 09:52:40 +02:00
|
|
|
|
# start new field and elements list
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
2000-08-27 09:12:40 +02:00
|
|
|
|
field = words[0]
|
|
|
|
|
elements = []
|
|
|
|
|
words = words[2 :]
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-10-26 09:52:40 +02:00
|
|
|
|
# append remaining words to current paragraph
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
2000-08-27 09:12:40 +02:00
|
|
|
|
if len( words ) > 0:
|
|
|
|
|
line = string.join( words )
|
|
|
|
|
if not paragraph:
|
|
|
|
|
paragraph = DocParagraph()
|
|
|
|
|
paragraph.add( line )
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-08-27 09:12:40 +02:00
|
|
|
|
else:
|
2001-01-11 10:27:49 +01:00
|
|
|
|
# we are in code mode...
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
2000-08-27 09:12:40 +02:00
|
|
|
|
line = aline
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# the code block ends with a line that has a single '}' on
|
|
|
|
|
# it that is located at the same column that the opening
|
|
|
|
|
# accolade...
|
|
|
|
|
#
|
2000-08-27 09:12:40 +02:00
|
|
|
|
if line == " " * code_margin + '}':
|
2000-08-22 01:01:32 +02:00
|
|
|
|
if code:
|
2000-08-27 09:12:40 +02:00
|
|
|
|
elements.append( code )
|
2000-08-22 01:01:32 +02:00
|
|
|
|
code = None
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-08-27 09:12:40 +02:00
|
|
|
|
code_mode = 0
|
|
|
|
|
code_margin = 0
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-08-27 09:12:40 +02:00
|
|
|
|
# otherwise, add the line to the current paragraph
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
2000-08-27 09:12:40 +02:00
|
|
|
|
else:
|
2000-08-22 01:01:32 +02:00
|
|
|
|
if not code:
|
|
|
|
|
code = DocCode()
|
2000-08-27 09:12:40 +02:00
|
|
|
|
code.add( line )
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-08-27 09:12:40 +02:00
|
|
|
|
if paragraph:
|
|
|
|
|
elements.append( paragraph )
|
2000-08-22 01:01:32 +02:00
|
|
|
|
|
|
|
|
|
if code:
|
2000-08-27 09:12:40 +02:00
|
|
|
|
elements.append( code )
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-08-27 09:12:40 +02:00
|
|
|
|
self.items.append( ( field, elements ) )
|
2000-08-22 01:01:32 +02:00
|
|
|
|
|
2000-01-10 16:49:01 +01:00
|
|
|
|
|
2000-10-26 09:52:40 +02:00
|
|
|
|
def get_identifier( self ):
|
|
|
|
|
if self.items:
|
|
|
|
|
item = self.items[0]
|
|
|
|
|
for element in item[1]:
|
|
|
|
|
return element.get_identifier()
|
|
|
|
|
|
|
|
|
|
# should never happen
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
|
|
|
|
return "UNKNOWN_CONTENT_IDENTIFIER!"
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-01-10 16:49:01 +01:00
|
|
|
|
|
2000-12-05 15:49:39 +01:00
|
|
|
|
def get_title( self ):
|
|
|
|
|
if self.items:
|
|
|
|
|
item = self.items[0]
|
|
|
|
|
for element in item[1]:
|
|
|
|
|
return element.dump_string()
|
|
|
|
|
|
|
|
|
|
# should never happen
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
|
|
|
|
return "UNKNOWN_CONTENT_TITLE!"
|
2000-12-05 15:49:39 +01:00
|
|
|
|
|
|
|
|
|
|
2000-08-27 09:12:40 +02:00
|
|
|
|
def dump( self ):
|
|
|
|
|
for item in self.items:
|
2000-08-22 01:01:32 +02:00
|
|
|
|
field = item[0]
|
2000-08-27 09:12:40 +02:00
|
|
|
|
if field:
|
|
|
|
|
print "<field " + field + ">"
|
2000-01-10 16:49:01 +01:00
|
|
|
|
|
2000-08-27 09:12:40 +02:00
|
|
|
|
for element in item[1]:
|
2000-08-22 01:01:32 +02:00
|
|
|
|
element.dump()
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-08-27 09:12:40 +02:00
|
|
|
|
if field:
|
2001-01-11 10:27:49 +01:00
|
|
|
|
print "</field>"
|
2000-01-10 16:49:01 +01:00
|
|
|
|
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2001-01-12 01:33:30 +01:00
|
|
|
|
def dump_html( self, identifiers = None ):
|
2000-08-27 09:12:40 +02:00
|
|
|
|
n = len( self.items )
|
2000-08-22 01:01:32 +02:00
|
|
|
|
in_table = 0
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-08-27 09:12:40 +02:00
|
|
|
|
for i in range( n ):
|
2000-08-22 01:01:32 +02:00
|
|
|
|
item = self.items[i]
|
|
|
|
|
field = item[0]
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-08-22 01:01:32 +02:00
|
|
|
|
if not field:
|
|
|
|
|
if in_table:
|
2000-08-27 09:12:40 +02:00
|
|
|
|
print "</td></tr></table>"
|
|
|
|
|
in_table = 0
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-08-22 01:01:32 +02:00
|
|
|
|
for element in item[1]:
|
2001-01-12 01:33:30 +01:00
|
|
|
|
element.dump_html( identifiers )
|
2000-12-06 17:31:30 +01:00
|
|
|
|
|
2000-05-31 09:54:45 +02:00
|
|
|
|
else:
|
2000-08-22 01:01:32 +02:00
|
|
|
|
if not in_table:
|
2001-01-11 10:27:49 +01:00
|
|
|
|
print "<table cellpadding=4><tr valign=top><td>"
|
2000-08-22 01:01:32 +02:00
|
|
|
|
in_table = 1
|
2000-05-31 09:54:45 +02:00
|
|
|
|
else:
|
|
|
|
|
print "</td></tr><tr valign=top><td>"
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-08-27 09:12:40 +02:00
|
|
|
|
print "<b>" + field + "</b></td><td>"
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-08-22 01:01:32 +02:00
|
|
|
|
for element in item[1]:
|
2001-01-12 01:33:30 +01:00
|
|
|
|
element.dump_html( identifiers )
|
2000-08-22 01:01:32 +02:00
|
|
|
|
|
|
|
|
|
if in_table:
|
|
|
|
|
print "</td></tr></table>"
|
2000-01-10 16:49:01 +01:00
|
|
|
|
|
2000-08-27 09:12:40 +02:00
|
|
|
|
|
2001-01-12 01:33:30 +01:00
|
|
|
|
def dump_html_in_table( self, identifiers = None ):
|
2001-01-10 07:53:49 +01:00
|
|
|
|
n = len( self.items )
|
|
|
|
|
in_table = 0
|
|
|
|
|
|
|
|
|
|
for i in range( n ):
|
|
|
|
|
item = self.items[i]
|
|
|
|
|
field = item[0]
|
|
|
|
|
|
|
|
|
|
if not field:
|
|
|
|
|
if item[1]:
|
|
|
|
|
print "<tr><td colspan=2>"
|
|
|
|
|
for element in item[1]:
|
2001-01-12 01:33:30 +01:00
|
|
|
|
element.dump_html( identifiers )
|
2001-01-10 07:53:49 +01:00
|
|
|
|
print "</td></tr>"
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
print "<tr><td><b>" + field + "</b></td><td>"
|
|
|
|
|
|
|
|
|
|
for element in item[1]:
|
2001-01-12 01:33:30 +01:00
|
|
|
|
element.dump_html( identifiers )
|
2001-01-10 07:53:49 +01:00
|
|
|
|
|
|
|
|
|
print "</td></tr>"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-01-11 10:27:49 +01:00
|
|
|
|
#############################################################################
|
2000-01-10 16:49:01 +01:00
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
# The DocBlock class is used to store a given comment block. It contains
|
|
|
|
|
# a list of markers, as well as a list of contents for each marker.
|
|
|
|
|
#
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# "self.items" is a list of (marker, contents) elements, where
|
2000-10-26 09:52:40 +02:00
|
|
|
|
# 'marker' is a lowercase marker string, and 'contents' is a DocContent
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# object.
|
2000-10-26 09:52:40 +02:00
|
|
|
|
#
|
|
|
|
|
# "self.source" is simply a list of text lines taken from the
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# uncommented source itself.
|
2000-10-26 09:52:40 +02:00
|
|
|
|
#
|
2001-01-11 10:27:49 +01:00
|
|
|
|
# Finally, "self.name" is a simple identifier used to uniquely identify
|
|
|
|
|
# the block. It is taken from the first word of the first
|
|
|
|
|
# paragraph of the first marker of a given block, i.e:
|
2001-01-10 07:53:49 +01:00
|
|
|
|
#
|
|
|
|
|
# <Type> Goo
|
|
|
|
|
# <Description> Bla bla bla
|
|
|
|
|
#
|
|
|
|
|
# will have a name of "Goo"
|
2000-01-10 16:49:01 +01:00
|
|
|
|
#
|
|
|
|
|
class DocBlock:
|
|
|
|
|
|
2000-08-27 09:12:40 +02:00
|
|
|
|
def __init__( self, block_line_list = [], source_line_list = [] ):
|
2001-01-16 00:11:55 +01:00
|
|
|
|
self.items = [] # current ( marker, contents ) list
|
|
|
|
|
self.section = None # section this block belongs to
|
|
|
|
|
self.filename = "unknown" # filename defining this block
|
|
|
|
|
self.lineno = 0 # line number in filename
|
2001-01-11 10:27:49 +01:00
|
|
|
|
|
2001-01-16 00:11:55 +01:00
|
|
|
|
marker = None # current marker
|
|
|
|
|
content = [] # current content lines list
|
|
|
|
|
alphanum = string.letters + string.digits + "_"
|
|
|
|
|
self.name = None
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-01-10 16:49:01 +01:00
|
|
|
|
for line in block_line_list:
|
2000-08-27 09:12:40 +02:00
|
|
|
|
line2 = string.lstrip( line )
|
|
|
|
|
l = len( line2 )
|
|
|
|
|
margin = len( line ) - l
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-10-26 09:52:40 +02:00
|
|
|
|
if l > 3:
|
|
|
|
|
ender = None
|
|
|
|
|
if line2[0] == '<':
|
|
|
|
|
ender = '>'
|
|
|
|
|
elif line2[0] == '@':
|
|
|
|
|
ender = ':'
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-10-26 09:52:40 +02:00
|
|
|
|
if ender:
|
|
|
|
|
i = 1
|
|
|
|
|
while i < l and line2[i] in alphanum:
|
|
|
|
|
i = i + 1
|
|
|
|
|
if i < l and line2[i] == ender:
|
|
|
|
|
if marker and content:
|
|
|
|
|
self.add( marker, content )
|
|
|
|
|
marker = line2[1 : i]
|
|
|
|
|
content = []
|
2001-02-14 05:59:57 +01:00
|
|
|
|
line2 = string.lstrip( line2[i+1 :] )
|
2000-10-26 09:52:40 +02:00
|
|
|
|
l = len( line2 )
|
|
|
|
|
line = " " * margin + line2
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-08-27 09:12:40 +02:00
|
|
|
|
content.append( line )
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-10-26 09:52:40 +02:00
|
|
|
|
if marker and content:
|
2000-08-27 09:12:40 +02:00
|
|
|
|
self.add( marker, content )
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-10-26 09:52:40 +02:00
|
|
|
|
self.source = []
|
|
|
|
|
if self.items:
|
|
|
|
|
self.source = source_line_list
|
|
|
|
|
|
2000-12-05 15:49:39 +01:00
|
|
|
|
# now retrieve block name when possible
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
2000-12-05 15:49:39 +01:00
|
|
|
|
if self.items:
|
|
|
|
|
first = self.items[0]
|
|
|
|
|
self.name = first[1].get_identifier()
|
|
|
|
|
|
2000-10-26 09:52:40 +02:00
|
|
|
|
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# This function adds a new element to 'self.items'.
|
|
|
|
|
# 'marker' is a marker string, or None.
|
|
|
|
|
# 'lines' is a list of text lines used to compute a list of
|
|
|
|
|
# DocContent objects.
|
2000-10-26 09:52:40 +02:00
|
|
|
|
#
|
2000-01-10 16:49:01 +01:00
|
|
|
|
def add( self, marker, lines ):
|
2000-08-27 09:12:40 +02:00
|
|
|
|
# remove the first and last empty lines from the content list
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
2000-08-27 09:12:40 +02:00
|
|
|
|
l = len( lines )
|
|
|
|
|
if l > 0:
|
|
|
|
|
i = 0
|
|
|
|
|
while l > 0 and string.strip( lines[l - 1] ) == "":
|
|
|
|
|
l = l - 1
|
|
|
|
|
while i < l and string.strip( lines[i] ) == "":
|
|
|
|
|
i = i + 1
|
|
|
|
|
lines = lines[i : l]
|
|
|
|
|
l = len( lines )
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# add a new marker only if its marker and its content list
|
|
|
|
|
# aren't empty
|
|
|
|
|
#
|
2000-08-27 09:12:40 +02:00
|
|
|
|
if l > 0 and marker:
|
2000-12-06 17:31:30 +01:00
|
|
|
|
content = DocContent( lines )
|
|
|
|
|
self.items.append( ( string.lower( marker ), content ) )
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2001-01-11 10:27:49 +01:00
|
|
|
|
|
2000-12-05 15:49:39 +01:00
|
|
|
|
def find_content( self, marker ):
|
|
|
|
|
for item in self.items:
|
|
|
|
|
if ( item[0] == marker ):
|
|
|
|
|
return item[1]
|
|
|
|
|
return None
|
|
|
|
|
|
2001-01-16 00:11:55 +01:00
|
|
|
|
|
2001-01-12 01:33:30 +01:00
|
|
|
|
def html_address( self ):
|
|
|
|
|
section = self.section
|
|
|
|
|
if section and section.filename:
|
2001-01-16 00:11:55 +01:00
|
|
|
|
return section.filename + '#' + self.name
|
2001-01-12 01:33:30 +01:00
|
|
|
|
|
2001-01-16 00:11:55 +01:00
|
|
|
|
return "" # this block is not in a section?
|
2001-01-12 01:33:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def location( self ):
|
2001-01-16 00:11:55 +01:00
|
|
|
|
return self.filename + ':' + str( self.lineno )
|
2001-01-12 01:33:30 +01:00
|
|
|
|
|
2001-02-14 05:59:57 +01:00
|
|
|
|
|
2001-02-13 18:42:49 +01:00
|
|
|
|
def print_warning( self, message ):
|
2001-02-14 05:59:57 +01:00
|
|
|
|
sys.stderr.write( "WARNING:" +
|
|
|
|
|
self.location() + ": " + message + '\n' )
|
|
|
|
|
|
2001-02-13 18:42:49 +01:00
|
|
|
|
|
|
|
|
|
def print_error( self, message ):
|
2001-02-14 05:59:57 +01:00
|
|
|
|
sys.stderr.write( "ERROR:" +
|
|
|
|
|
self.location() + ": " + message + '\n' )
|
2001-02-13 18:42:49 +01:00
|
|
|
|
sys.exit()
|
|
|
|
|
|
2000-10-26 09:52:40 +02:00
|
|
|
|
|
2000-01-10 16:49:01 +01:00
|
|
|
|
def dump( self ):
|
2000-10-26 09:52:40 +02:00
|
|
|
|
for i in range( len( self.items ) ):
|
|
|
|
|
print "[" + self.items[i][0] + "]"
|
|
|
|
|
content = self.items[i][1]
|
|
|
|
|
content.dump()
|
2000-01-10 16:49:01 +01:00
|
|
|
|
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2001-01-12 01:33:30 +01:00
|
|
|
|
def dump_html( self, identifiers = None ):
|
2001-02-14 05:59:57 +01:00
|
|
|
|
types = ['type', 'struct', 'functype', 'function',
|
|
|
|
|
'constant', 'enum', 'macro', 'structure', 'also']
|
2000-01-10 16:49:01 +01:00
|
|
|
|
|
2001-02-14 05:59:57 +01:00
|
|
|
|
parameters = ['input', 'inout', 'output', 'return']
|
2001-01-10 07:53:49 +01:00
|
|
|
|
|
2000-10-26 09:52:40 +02:00
|
|
|
|
if not self.items:
|
2000-12-06 17:31:30 +01:00
|
|
|
|
return
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-10-26 09:52:40 +02:00
|
|
|
|
# start of a block
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
2000-10-26 09:52:40 +02:00
|
|
|
|
print block_header
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2001-01-11 10:27:49 +01:00
|
|
|
|
# place html anchor if needed
|
|
|
|
|
#
|
|
|
|
|
if self.name:
|
|
|
|
|
print '<a name="' + self.name + '">'
|
|
|
|
|
print "<h4>" + self.name + "</h4>"
|
|
|
|
|
print "</a>"
|
2000-01-10 16:49:01 +01:00
|
|
|
|
|
2000-10-26 09:52:40 +02:00
|
|
|
|
# print source code
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
2000-10-26 09:52:40 +02:00
|
|
|
|
if not self.source:
|
2001-01-12 01:33:30 +01:00
|
|
|
|
print block_footer
|
2000-10-26 09:52:40 +02:00
|
|
|
|
return
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-10-26 09:52:40 +02:00
|
|
|
|
lines = self.source
|
|
|
|
|
l = len( lines ) - 1
|
|
|
|
|
while l >= 0 and string.strip( lines[l] ) == "":
|
|
|
|
|
l = l - 1
|
|
|
|
|
print source_header
|
2001-01-11 10:27:49 +01:00
|
|
|
|
print ""
|
2001-02-14 05:59:57 +01:00
|
|
|
|
for line in lines[0 : l+1]:
|
2001-01-11 10:27:49 +01:00
|
|
|
|
print line
|
2000-10-26 09:52:40 +02:00
|
|
|
|
print source_footer
|
2000-01-10 16:49:01 +01:00
|
|
|
|
|
2001-01-10 07:53:49 +01:00
|
|
|
|
in_table = 0
|
2001-01-11 10:27:49 +01:00
|
|
|
|
|
2000-10-26 09:52:40 +02:00
|
|
|
|
# dump each (marker,content) element
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
2000-10-26 09:52:40 +02:00
|
|
|
|
for element in self.items:
|
|
|
|
|
marker = element[0]
|
|
|
|
|
content = element[1]
|
2000-01-10 16:49:01 +01:00
|
|
|
|
|
2000-10-26 09:52:40 +02:00
|
|
|
|
if marker == "description":
|
2001-01-10 07:53:49 +01:00
|
|
|
|
print description_header
|
2001-01-12 01:33:30 +01:00
|
|
|
|
content.dump_html( identifiers )
|
2001-01-10 07:53:49 +01:00
|
|
|
|
print description_footer
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-12-06 17:31:30 +01:00
|
|
|
|
elif not ( marker in types ):
|
2001-01-11 10:27:49 +01:00
|
|
|
|
sys.stdout.write( marker_header )
|
|
|
|
|
sys.stdout.write( marker )
|
|
|
|
|
sys.stdout.write( marker_inter + '\n' )
|
2001-01-12 01:33:30 +01:00
|
|
|
|
content.dump_html( identifiers )
|
2001-01-10 07:53:49 +01:00
|
|
|
|
print marker_footer
|
2001-01-11 10:27:49 +01:00
|
|
|
|
|
2001-01-10 07:53:49 +01:00
|
|
|
|
print ""
|
2000-10-26 09:52:40 +02:00
|
|
|
|
|
|
|
|
|
print block_footer
|
|
|
|
|
|
|
|
|
|
|
2001-01-11 10:27:49 +01:00
|
|
|
|
|
|
|
|
|
#############################################################################
|
2000-12-05 15:49:39 +01:00
|
|
|
|
#
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# The DocSection class is used to store a given documentation section.
|
2000-12-05 15:49:39 +01:00
|
|
|
|
#
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# Each section is made of an identifier, an abstract and a description.
|
2000-12-05 15:49:39 +01:00
|
|
|
|
#
|
|
|
|
|
# For example, look at:
|
|
|
|
|
#
|
|
|
|
|
# <Section> Basic_Data_Types
|
|
|
|
|
#
|
2001-01-10 07:53:49 +01:00
|
|
|
|
# <Title> FreeType 2 Basic Data Types
|
|
|
|
|
#
|
2000-12-05 15:49:39 +01:00
|
|
|
|
# <Abstract>
|
|
|
|
|
# Definitions of basic FreeType data types
|
|
|
|
|
#
|
|
|
|
|
# <Description>
|
|
|
|
|
# FreeType defines several basic data types for all its
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# operations...
|
2000-12-05 15:49:39 +01:00
|
|
|
|
#
|
|
|
|
|
class DocSection:
|
|
|
|
|
|
|
|
|
|
def __init__( self, block ):
|
|
|
|
|
self.block = block
|
2000-12-06 17:31:30 +01:00
|
|
|
|
self.name = string.lower( block.name )
|
|
|
|
|
self.abstract = block.find_content( "abstract" )
|
|
|
|
|
self.description = block.find_content( "description" )
|
2000-12-05 15:49:39 +01:00
|
|
|
|
self.elements = {}
|
|
|
|
|
self.list = []
|
|
|
|
|
self.filename = self.name + ".html"
|
2001-02-13 18:42:49 +01:00
|
|
|
|
self.chapter = None
|
2000-12-05 15:49:39 +01:00
|
|
|
|
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# sys.stderr.write( "new section '" + self.name + "'" )
|
|
|
|
|
|
2000-12-05 15:49:39 +01:00
|
|
|
|
|
|
|
|
|
def add_element( self, block ):
|
|
|
|
|
# check that we don't have a duplicate element in this
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# section
|
|
|
|
|
#
|
2000-12-05 15:49:39 +01:00
|
|
|
|
if self.elements.has_key( block.name ):
|
2001-02-14 05:59:57 +01:00
|
|
|
|
self.print_error( "duplicate element definition for " +
|
|
|
|
|
"'" + block.name + "' " +
|
|
|
|
|
"in section " +
|
|
|
|
|
"'" + self.name + "'\n" +
|
|
|
|
|
"previous definition in " +
|
|
|
|
|
"'" + self.elements[block.name].location() + "'" )
|
|
|
|
|
|
|
|
|
|
self.elements[block.name] = block
|
2000-12-05 15:49:39 +01:00
|
|
|
|
self.list.append( block )
|
|
|
|
|
|
|
|
|
|
|
2001-02-13 18:42:49 +01:00
|
|
|
|
def print_warning( self, message ):
|
|
|
|
|
self.block.print_warning( message )
|
|
|
|
|
|
2001-02-14 05:59:57 +01:00
|
|
|
|
|
2001-02-13 18:42:49 +01:00
|
|
|
|
def print_error( self, message ):
|
|
|
|
|
self.block.print_error( message )
|
|
|
|
|
|
2001-02-14 05:59:57 +01:00
|
|
|
|
|
2001-01-12 01:33:30 +01:00
|
|
|
|
def dump_html( self, identifiers = None ):
|
2000-12-05 15:49:39 +01:00
|
|
|
|
"""make an HTML page from a given DocSection"""
|
|
|
|
|
|
|
|
|
|
# print HTML header
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
2000-12-05 15:49:39 +01:00
|
|
|
|
print html_header
|
|
|
|
|
|
|
|
|
|
# print title
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
2000-12-05 15:49:39 +01:00
|
|
|
|
print section_title_header
|
|
|
|
|
print self.title
|
|
|
|
|
print section_title_footer
|
|
|
|
|
|
|
|
|
|
# print description
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
2000-12-05 15:49:39 +01:00
|
|
|
|
print block_header
|
2001-01-12 01:33:30 +01:00
|
|
|
|
self.description.dump_html( identifiers )
|
2000-12-05 15:49:39 +01:00
|
|
|
|
print block_footer
|
|
|
|
|
|
|
|
|
|
# print elements
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
2000-12-05 15:49:39 +01:00
|
|
|
|
for element in self.list:
|
2001-01-12 01:33:30 +01:00
|
|
|
|
element.dump_html( identifiers )
|
2000-12-05 15:49:39 +01:00
|
|
|
|
|
|
|
|
|
print html_footer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DocSectionList:
|
|
|
|
|
|
2000-12-06 17:31:30 +01:00
|
|
|
|
def __init__( self ):
|
2001-01-12 01:33:30 +01:00
|
|
|
|
self.sections = {} # map section names to section objects
|
|
|
|
|
self.list = [] # list of sections (in creation order)
|
|
|
|
|
self.current_section = None # current section
|
|
|
|
|
self.identifiers = {} # map identifiers to blocks
|
2001-02-14 05:59:57 +01:00
|
|
|
|
|
|
|
|
|
|
2000-12-06 17:31:30 +01:00
|
|
|
|
def append_section( self, block ):
|
2001-01-10 12:15:48 +01:00
|
|
|
|
name = string.lower( block.name )
|
2000-12-06 17:31:30 +01:00
|
|
|
|
abstract = block.find_content( "abstract" )
|
2000-12-05 15:49:39 +01:00
|
|
|
|
|
2000-12-06 17:31:30 +01:00
|
|
|
|
if self.sections.has_key( name ):
|
|
|
|
|
# There is already a section with this name in our
|
2001-01-11 10:27:49 +01:00
|
|
|
|
# list. We will try to complete it.
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
2000-12-05 15:49:39 +01:00
|
|
|
|
section = self.sections[name]
|
|
|
|
|
if section.abstract:
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# This section already has an abstract defined;
|
2000-12-05 15:49:39 +01:00
|
|
|
|
# simply check that the new section doesn't
|
|
|
|
|
# provide a new one.
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
2000-12-05 15:49:39 +01:00
|
|
|
|
if abstract:
|
2001-02-14 05:59:57 +01:00
|
|
|
|
print_error( "duplicate section definition for " +
|
|
|
|
|
"'" + name + "'\n" +
|
|
|
|
|
"previous definition in " +
|
|
|
|
|
"'" + section.block.location() + "'\n" +
|
|
|
|
|
"second definition in " +
|
|
|
|
|
"'" + block.location() + "'" )
|
2000-12-05 15:49:39 +01:00
|
|
|
|
else:
|
2001-01-11 10:27:49 +01:00
|
|
|
|
# The old section didn't contain an abstract; we are
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# now going to replace it.
|
|
|
|
|
#
|
2000-12-05 15:49:39 +01:00
|
|
|
|
section.abstract = abstract
|
|
|
|
|
section.description = block.find_content( "description" )
|
2001-01-10 07:53:49 +01:00
|
|
|
|
section.block = block
|
2000-12-06 17:31:30 +01:00
|
|
|
|
|
2000-12-05 15:49:39 +01:00
|
|
|
|
else:
|
|
|
|
|
# a new section
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
2000-12-05 15:49:39 +01:00
|
|
|
|
section = DocSection( block )
|
|
|
|
|
self.sections[name] = section
|
|
|
|
|
self.list.append( section )
|
2001-01-11 10:27:49 +01:00
|
|
|
|
|
2000-12-05 15:49:39 +01:00
|
|
|
|
self.current_section = section
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def append_block( self, block ):
|
|
|
|
|
if block.name:
|
|
|
|
|
section = block.find_content( "section" )
|
|
|
|
|
if section:
|
|
|
|
|
self.append_section( block )
|
|
|
|
|
|
|
|
|
|
elif self.current_section:
|
|
|
|
|
self.current_section.add_element( block )
|
2001-02-14 05:59:57 +01:00
|
|
|
|
block.section = self.current_section
|
2001-01-12 01:33:30 +01:00
|
|
|
|
self.identifiers[block.name] = block
|
2001-01-10 07:53:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def prepare_files( self, file_prefix = None ):
|
|
|
|
|
# prepare the section list, by computing section filenames
|
|
|
|
|
# and the index
|
2001-01-11 10:27:49 +01:00
|
|
|
|
#
|
2001-01-10 07:53:49 +01:00
|
|
|
|
if file_prefix:
|
|
|
|
|
prefix = file_prefix + "-"
|
|
|
|
|
else:
|
|
|
|
|
prefix = ""
|
|
|
|
|
|
|
|
|
|
# compute section names
|
2001-01-11 10:27:49 +01:00
|
|
|
|
#
|
2001-01-10 07:53:49 +01:00
|
|
|
|
for section in self.sections.values():
|
|
|
|
|
title_content = section.block.find_content( "title" )
|
|
|
|
|
if title_content:
|
|
|
|
|
section.title = title_content.get_title()
|
|
|
|
|
else:
|
|
|
|
|
section.title = "UNKNOWN_SECTION_TITLE!"
|
|
|
|
|
|
2001-02-03 04:00:06 +01:00
|
|
|
|
# sort section elements according to the <order> marker if
|
2001-02-02 06:24:11 +01:00
|
|
|
|
# available
|
2001-02-03 04:00:06 +01:00
|
|
|
|
#
|
2001-02-02 06:24:11 +01:00
|
|
|
|
for section in self.sections.values():
|
|
|
|
|
order = section.block.find_content( "order" )
|
|
|
|
|
if order:
|
2001-02-03 04:00:06 +01:00
|
|
|
|
# sys.stderr.write( "<order> found at "
|
|
|
|
|
# + section.block.location() + '\n' )
|
2001-02-02 06:24:11 +01:00
|
|
|
|
order_list = []
|
|
|
|
|
for item in order.items:
|
|
|
|
|
for element in item[1]:
|
|
|
|
|
words = None
|
|
|
|
|
try:
|
|
|
|
|
words = element.get_words()
|
|
|
|
|
except:
|
2001-02-14 05:59:57 +01:00
|
|
|
|
section.block.print_warning(
|
|
|
|
|
"invalid content in <order> marker\n" )
|
2001-02-02 06:24:11 +01:00
|
|
|
|
if words:
|
|
|
|
|
for word in words:
|
|
|
|
|
block = self.identifiers.get( word )
|
|
|
|
|
if block:
|
|
|
|
|
if block.section == section:
|
2001-02-13 18:42:49 +01:00
|
|
|
|
order_list.append( block )
|
2001-02-02 06:24:11 +01:00
|
|
|
|
else:
|
2001-02-14 05:59:57 +01:00
|
|
|
|
section.block.print_warning(
|
|
|
|
|
"invalid reference to " +
|
|
|
|
|
"'" + word + "' " +
|
|
|
|
|
"defined in other section" )
|
2001-02-02 06:24:11 +01:00
|
|
|
|
else:
|
2001-02-14 05:59:57 +01:00
|
|
|
|
section.block.print_warning(
|
|
|
|
|
"invalid reference to " +
|
|
|
|
|
"'" + word + "'" )
|
|
|
|
|
|
2001-02-02 06:24:11 +01:00
|
|
|
|
# now sort the list of blocks according to the order list
|
|
|
|
|
#
|
2001-02-13 18:42:49 +01:00
|
|
|
|
new_list = order_list[:]
|
|
|
|
|
for block in section.list:
|
|
|
|
|
if not block in order_list:
|
2001-02-14 05:59:57 +01:00
|
|
|
|
new_list.append( block )
|
|
|
|
|
|
|
|
|
|
section.list = new_list
|
2001-02-02 06:24:11 +01:00
|
|
|
|
|
2001-01-11 10:27:49 +01:00
|
|
|
|
# compute section filenames
|
|
|
|
|
#
|
2001-01-10 07:53:49 +01:00
|
|
|
|
for section in self.sections.values():
|
|
|
|
|
section.filename = prefix + section.name + ".html"
|
2000-12-05 15:49:39 +01:00
|
|
|
|
|
2001-01-10 07:53:49 +01:00
|
|
|
|
self.toc_filename = prefix + "toc.html"
|
|
|
|
|
self.index_filename = prefix + "index.html"
|
|
|
|
|
|
2001-01-12 01:33:30 +01:00
|
|
|
|
# compute the sorted list of identifiers for the index
|
2001-01-11 10:27:49 +01:00
|
|
|
|
#
|
2001-01-12 01:33:30 +01:00
|
|
|
|
self.index = self.identifiers.keys()
|
2001-02-02 06:24:11 +01:00
|
|
|
|
self.index.sort( index_sort )
|
2001-01-11 10:27:49 +01:00
|
|
|
|
|
2000-12-05 15:49:39 +01:00
|
|
|
|
|
|
|
|
|
def dump_html_sections( self ):
|
|
|
|
|
old_stdout = sys.stdout
|
2001-01-10 07:53:49 +01:00
|
|
|
|
|
2000-12-05 15:49:39 +01:00
|
|
|
|
for section in self.sections.values():
|
2001-01-10 07:53:49 +01:00
|
|
|
|
if section.filename:
|
|
|
|
|
new_file = open( section.filename, "w" )
|
|
|
|
|
sys.stdout = new_file
|
2001-01-12 01:33:30 +01:00
|
|
|
|
section.dump_html( self.identifiers )
|
2001-01-10 07:53:49 +01:00
|
|
|
|
new_file.close()
|
2000-12-05 15:49:39 +01:00
|
|
|
|
|
|
|
|
|
sys.stdout = old_stdout
|
|
|
|
|
|
|
|
|
|
|
2001-01-10 07:53:49 +01:00
|
|
|
|
def dump_html_index( self ):
|
|
|
|
|
old_stdout = sys.stdout
|
|
|
|
|
new_file = open( self.index_filename, "w" )
|
|
|
|
|
sys.stdout = new_file
|
|
|
|
|
|
|
|
|
|
num_columns = 3
|
|
|
|
|
total = len( self.index )
|
|
|
|
|
line = 0
|
|
|
|
|
|
|
|
|
|
print html_header
|
|
|
|
|
print "<center><h1>General Index</h1></center>"
|
|
|
|
|
print "<center><table cellpadding=5><tr valign=top><td>"
|
|
|
|
|
|
2001-01-12 01:33:30 +01:00
|
|
|
|
for ident in self.index:
|
|
|
|
|
block = self.identifiers[ident]
|
|
|
|
|
if block:
|
|
|
|
|
sys.stdout.write( '<a href="' + block.html_address() + '">' )
|
|
|
|
|
sys.stdout.write( block.name )
|
|
|
|
|
sys.stdout.write( '</a><br>' + '\n' )
|
2001-01-10 07:53:49 +01:00
|
|
|
|
|
2001-01-12 01:33:30 +01:00
|
|
|
|
if line * num_columns >= total:
|
|
|
|
|
print "</td><td>"
|
|
|
|
|
line = 0
|
|
|
|
|
else:
|
|
|
|
|
line = line + 1
|
2001-01-10 07:53:49 +01:00
|
|
|
|
else:
|
2001-02-14 05:59:57 +01:00
|
|
|
|
sys.stderr.write( "identifier '" + ident +
|
2001-01-16 00:11:55 +01:00
|
|
|
|
"' has no definition" + '\n' )
|
2001-01-10 07:53:49 +01:00
|
|
|
|
|
|
|
|
|
print "</tr></table></center>"
|
|
|
|
|
print html_footer
|
2001-01-11 10:27:49 +01:00
|
|
|
|
|
2001-01-10 07:53:49 +01:00
|
|
|
|
sys.stdout = old_stdout
|
2001-01-11 10:27:49 +01:00
|
|
|
|
|
2000-12-05 15:49:39 +01:00
|
|
|
|
|
2001-02-02 06:24:11 +01:00
|
|
|
|
|
2001-02-14 05:59:57 +01:00
|
|
|
|
# Filter a given list of DocBlocks. Returns a new list of DocBlock objects
|
|
|
|
|
# that only contains element whose "type" (i.e. first marker) is in the
|
|
|
|
|
# "types" parameter.
|
|
|
|
|
#
|
2001-02-13 18:42:49 +01:00
|
|
|
|
class DocChapter:
|
2001-02-14 05:59:57 +01:00
|
|
|
|
|
|
|
|
|
def __init__( self, block ):
|
2001-02-13 18:42:49 +01:00
|
|
|
|
self.sections_names = [] # ordered list of section names
|
2001-02-14 05:59:57 +01:00
|
|
|
|
self.sections = [] # ordered list of DocSection objects
|
|
|
|
|
# for this chapter
|
2001-02-13 18:42:49 +01:00
|
|
|
|
self.block = block
|
|
|
|
|
|
|
|
|
|
# look for chapter title
|
|
|
|
|
content = block.find_content( "title" )
|
|
|
|
|
if content:
|
|
|
|
|
self.title = content.get_title()
|
|
|
|
|
else:
|
|
|
|
|
self.title = "UNKNOWN CHAPTER TITLE"
|
|
|
|
|
|
|
|
|
|
# look for section list
|
|
|
|
|
content = block.find_content( "sections" )
|
|
|
|
|
if not content:
|
|
|
|
|
block.print_error( "chapter has no <sections> content" )
|
|
|
|
|
|
2001-02-14 05:59:57 +01:00
|
|
|
|
# compute list of section names
|
2001-02-13 18:42:49 +01:00
|
|
|
|
slist = []
|
|
|
|
|
for item in content.items:
|
|
|
|
|
for element in item[1]:
|
|
|
|
|
try:
|
2001-02-14 05:59:57 +01:00
|
|
|
|
words = element.get_words()
|
|
|
|
|
l = len( slist )
|
|
|
|
|
slist[l : l] = words
|
2001-02-13 18:42:49 +01:00
|
|
|
|
except:
|
2001-02-14 05:59:57 +01:00
|
|
|
|
block.print_warning(
|
|
|
|
|
"invalid content in <sections> marker" )
|
|
|
|
|
|
2001-02-13 18:42:49 +01:00
|
|
|
|
self.section_names = slist
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DocDocument:
|
|
|
|
|
|
|
|
|
|
def __init__( self ):
|
|
|
|
|
self.section_list = DocSectionList() # section list object
|
|
|
|
|
self.chapters = [] # list of chapters
|
2001-02-14 05:59:57 +01:00
|
|
|
|
self.lost_sections = [] # list of sections with
|
|
|
|
|
# no chapter
|
2001-02-13 18:42:49 +01:00
|
|
|
|
|
|
|
|
|
def append_block( self, block ):
|
|
|
|
|
if block.name:
|
|
|
|
|
content = block.find_content( "chapter" )
|
|
|
|
|
if content:
|
2001-02-14 05:59:57 +01:00
|
|
|
|
# it's a chapter definition -- add it to our list
|
2001-02-13 18:42:49 +01:00
|
|
|
|
chapter = DocChapter( block )
|
|
|
|
|
self.chapters.append( chapter )
|
|
|
|
|
else:
|
|
|
|
|
self.section_list.append_block( block )
|
2001-02-14 05:59:57 +01:00
|
|
|
|
|
|
|
|
|
|
2001-02-13 18:42:49 +01:00
|
|
|
|
def prepare_chapters( self ):
|
|
|
|
|
# check section names
|
|
|
|
|
#
|
|
|
|
|
for chapter in self.chapters:
|
|
|
|
|
slist = []
|
|
|
|
|
for name in chapter.section_names:
|
2001-02-14 05:59:57 +01:00
|
|
|
|
section = self.section_list.sections.get( name )
|
2001-02-13 18:42:49 +01:00
|
|
|
|
if not section:
|
2001-02-14 05:59:57 +01:00
|
|
|
|
chapter.block.print_warning(
|
|
|
|
|
"invalid reference to unknown section '" + name + "'" )
|
2001-02-13 18:42:49 +01:00
|
|
|
|
else:
|
|
|
|
|
section.chapter = chapter
|
|
|
|
|
slist.append( section )
|
2001-02-14 05:59:57 +01:00
|
|
|
|
|
2001-02-13 18:42:49 +01:00
|
|
|
|
chapter.sections = slist
|
|
|
|
|
|
|
|
|
|
for section in self.section_list.list:
|
|
|
|
|
if not section.chapter:
|
2001-02-14 05:59:57 +01:00
|
|
|
|
section.block.print_warning(
|
|
|
|
|
"section '" + section.name + "' is not in any chapter" )
|
2001-02-13 18:42:49 +01:00
|
|
|
|
self.lost_sections.append( section )
|
|
|
|
|
|
2001-02-14 05:59:57 +01:00
|
|
|
|
|
2001-02-13 18:42:49 +01:00
|
|
|
|
def prepare_files( self, file_prefix = None ):
|
|
|
|
|
self.section_list.prepare_files( file_prefix )
|
|
|
|
|
self.prepare_chapters()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def dump_toc_html( self ):
|
|
|
|
|
# dump an html table of contents
|
|
|
|
|
#
|
|
|
|
|
old_stdout = sys.stdout
|
|
|
|
|
new_file = open( self.section_list.toc_filename, "w" )
|
|
|
|
|
sys.stdout = new_file
|
|
|
|
|
|
|
|
|
|
print html_header
|
|
|
|
|
|
|
|
|
|
print "<center><h1>Table of Contents</h1></center>"
|
|
|
|
|
|
|
|
|
|
for chapter in self.chapters:
|
|
|
|
|
print chapter_header + chapter.title + chapter_inter
|
|
|
|
|
|
|
|
|
|
print "<table cellpadding=5>"
|
|
|
|
|
for section in chapter.sections:
|
|
|
|
|
if section.abstract:
|
|
|
|
|
print "<tr valign=top><td>"
|
|
|
|
|
sys.stdout.write( '<a href="' + section.filename + '">' )
|
|
|
|
|
sys.stdout.write( section.title )
|
|
|
|
|
sys.stdout.write( "</a></td><td>" + '\n' )
|
|
|
|
|
section.abstract.dump_html( self.section_list.identifiers )
|
|
|
|
|
print "</td></tr>"
|
|
|
|
|
|
|
|
|
|
print "</table>"
|
|
|
|
|
|
|
|
|
|
print chapter_footer
|
|
|
|
|
|
|
|
|
|
# list lost sections
|
|
|
|
|
if self.lost_sections:
|
|
|
|
|
print chapter_header + "OTHER SECTIONS:" + chapter_inter
|
2001-02-14 05:59:57 +01:00
|
|
|
|
|
2001-02-13 18:42:49 +01:00
|
|
|
|
print "<table cellpadding=5>"
|
|
|
|
|
for section in self.lost_sections:
|
|
|
|
|
if section.abstract:
|
|
|
|
|
print "<tr valign=top><td>"
|
|
|
|
|
sys.stdout.write( '<a href="' + section.filename + '">' )
|
|
|
|
|
sys.stdout.write( section.title )
|
|
|
|
|
sys.stdout.write( "</a></td><td>" + '\n' )
|
|
|
|
|
section.abstract.dump_html( self.section_list.identifiers )
|
|
|
|
|
print "</td></tr>"
|
|
|
|
|
|
|
|
|
|
print "</table>"
|
|
|
|
|
|
|
|
|
|
print chapter_footer
|
2001-02-14 05:59:57 +01:00
|
|
|
|
|
2001-02-13 18:42:49 +01:00
|
|
|
|
print html_footer
|
|
|
|
|
|
|
|
|
|
sys.stdout = old_stdout
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def dump_index_html( self ):
|
|
|
|
|
self.section_list.dump_html_index()
|
|
|
|
|
|
2001-02-14 05:59:57 +01:00
|
|
|
|
|
2001-02-13 18:42:49 +01:00
|
|
|
|
def dump_sections_html( self ):
|
|
|
|
|
self.section_list.dump_html_sections()
|
|
|
|
|
|
|
|
|
|
|
2001-01-10 07:53:49 +01:00
|
|
|
|
def filter_blocks_by_type( block_list, types ):
|
2000-10-26 09:52:40 +02:00
|
|
|
|
new_list = []
|
|
|
|
|
for block in block_list:
|
|
|
|
|
if block.items:
|
|
|
|
|
element = block.items[0]
|
|
|
|
|
marker = element[0]
|
|
|
|
|
if marker in types:
|
|
|
|
|
new_list.append( block )
|
2000-01-10 16:49:01 +01:00
|
|
|
|
|
2000-10-26 09:52:40 +02:00
|
|
|
|
return new_list
|
2000-01-10 16:49:01 +01:00
|
|
|
|
|
2000-08-27 09:12:40 +02:00
|
|
|
|
|
2001-01-10 07:53:49 +01:00
|
|
|
|
def filter_section_blocks( block ):
|
|
|
|
|
return block.section != None
|
|
|
|
|
|
|
|
|
|
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# Perform a lexicographical comparison of two DocBlock
|
|
|
|
|
# objects. Returns -1, 0 or 1.
|
2000-10-26 09:52:40 +02:00
|
|
|
|
#
|
|
|
|
|
def block_lexicographical_compare( b1, b2 ):
|
2001-01-10 07:53:49 +01:00
|
|
|
|
if not b1.name:
|
2000-10-26 09:52:40 +02:00
|
|
|
|
return -1
|
2001-01-10 07:53:49 +01:00
|
|
|
|
if not b2.name:
|
2000-10-26 09:52:40 +02:00
|
|
|
|
return 1
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2001-01-10 07:53:49 +01:00
|
|
|
|
id1 = string.lower( b1.name )
|
|
|
|
|
id2 = string.lower( b2.name )
|
2000-12-06 17:31:30 +01:00
|
|
|
|
|
2000-10-26 09:52:40 +02:00
|
|
|
|
if id1 < id2:
|
|
|
|
|
return -1
|
|
|
|
|
elif id1 == id2:
|
|
|
|
|
return 0
|
|
|
|
|
else:
|
|
|
|
|
return 1
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-01-10 16:49:01 +01:00
|
|
|
|
|
2000-10-26 09:52:40 +02:00
|
|
|
|
# dump a list block as a single HTML page
|
|
|
|
|
#
|
2000-05-31 09:54:45 +02:00
|
|
|
|
def dump_html_1( block_list ):
|
2000-08-22 01:01:32 +02:00
|
|
|
|
print html_header
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-05-31 09:54:45 +02:00
|
|
|
|
for block in block_list:
|
2000-10-26 09:52:40 +02:00
|
|
|
|
block.dump_html()
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-10-26 09:52:40 +02:00
|
|
|
|
print html_footer
|
2000-08-22 01:01:32 +02:00
|
|
|
|
|
|
|
|
|
|
2001-01-12 01:33:30 +01:00
|
|
|
|
def file_exists( pathname ):
|
|
|
|
|
result = 1
|
|
|
|
|
try:
|
|
|
|
|
file = open( pathname, "r" )
|
|
|
|
|
file.close()
|
|
|
|
|
except:
|
|
|
|
|
result = None
|
|
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def add_new_block( list, filename, lineno, block_lines, source_lines ):
|
|
|
|
|
"""add a new block to the list"""
|
2001-01-16 00:11:55 +01:00
|
|
|
|
block = DocBlock( block_lines, source_lines )
|
2001-01-12 01:33:30 +01:00
|
|
|
|
block.filename = filename
|
|
|
|
|
block.lineno = lineno
|
|
|
|
|
list.append( block )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def make_block_list():
|
2000-10-26 09:52:40 +02:00
|
|
|
|
"""parse a file and extract comments blocks from it"""
|
|
|
|
|
|
2001-01-10 12:15:48 +01:00
|
|
|
|
file_list = []
|
2001-02-14 05:59:57 +01:00
|
|
|
|
# sys.stderr.write( repr( sys.argv[1 :] ) + '\n' )
|
2001-01-11 10:27:49 +01:00
|
|
|
|
|
2001-02-14 05:59:57 +01:00
|
|
|
|
for pathname in sys.argv[1 :]:
|
2001-01-12 01:33:30 +01:00
|
|
|
|
if string.find( pathname, '*' ) >= 0:
|
|
|
|
|
newpath = glob.glob( pathname )
|
2001-01-16 00:11:55 +01:00
|
|
|
|
newpath.sort() # sort files -- this is important because
|
|
|
|
|
# of the order of files
|
2001-01-12 01:33:30 +01:00
|
|
|
|
else:
|
2001-01-16 00:11:55 +01:00
|
|
|
|
newpath = [pathname]
|
2001-01-12 01:33:30 +01:00
|
|
|
|
|
2001-01-11 10:27:49 +01:00
|
|
|
|
last = len( file_list )
|
2001-02-14 05:59:57 +01:00
|
|
|
|
file_list[last : last] = newpath
|
2001-01-10 12:15:48 +01:00
|
|
|
|
|
|
|
|
|
if len( file_list ) == 0:
|
|
|
|
|
file_list = None
|
2001-01-12 01:33:30 +01:00
|
|
|
|
else:
|
|
|
|
|
# now filter the file list to remove non-existing ones
|
|
|
|
|
file_list = filter( file_exists, file_list )
|
2001-01-10 12:15:48 +01:00
|
|
|
|
|
2000-10-26 09:52:40 +02:00
|
|
|
|
list = []
|
|
|
|
|
block = []
|
|
|
|
|
format = 0
|
2001-01-12 01:33:30 +01:00
|
|
|
|
lineno = 0
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# We use "format" to store the state of our parser:
|
2000-10-26 09:52:40 +02:00
|
|
|
|
#
|
|
|
|
|
# 0 - wait for beginning of comment
|
|
|
|
|
# 1 - parse comment format 1
|
|
|
|
|
# 2 - parse comment format 2
|
|
|
|
|
#
|
|
|
|
|
# 4 - wait for beginning of source (or comment ??)
|
|
|
|
|
# 5 - process source
|
|
|
|
|
#
|
2001-01-11 10:27:49 +01:00
|
|
|
|
comment = []
|
|
|
|
|
source = []
|
|
|
|
|
state = 0
|
2000-10-26 09:52:40 +02:00
|
|
|
|
|
2001-01-10 12:15:48 +01:00
|
|
|
|
for line in fileinput.input( file_list ):
|
2000-10-26 09:52:40 +02:00
|
|
|
|
l = len( line )
|
|
|
|
|
if l > 0 and line[l - 1] == '\012':
|
2001-02-14 05:59:57 +01:00
|
|
|
|
line = line[0 : l-1]
|
2000-10-26 09:52:40 +02:00
|
|
|
|
|
|
|
|
|
# stripped version of the line
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
2000-10-26 09:52:40 +02:00
|
|
|
|
line2 = string.strip( line )
|
|
|
|
|
l = len( line2 )
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-10-26 09:52:40 +02:00
|
|
|
|
# if this line begins with a comment and we are processing some
|
|
|
|
|
# source, exit to state 0
|
|
|
|
|
#
|
|
|
|
|
# unless we encounter something like:
|
|
|
|
|
#
|
|
|
|
|
# /*@.....
|
|
|
|
|
# /*#.....
|
|
|
|
|
#
|
|
|
|
|
# /* @.....
|
|
|
|
|
# /* #.....
|
|
|
|
|
#
|
|
|
|
|
if format >= 4 and l > 2 and line2[0 : 2] == '/*':
|
2001-02-14 05:59:57 +01:00
|
|
|
|
if l < 4 or ( line2[2] != '@' and line2[2 : 4] != ' @' and
|
|
|
|
|
line2[2] != '#' and line2[2 : 4] != ' #'):
|
2001-01-16 00:11:55 +01:00
|
|
|
|
add_new_block( list, fileinput.filename(),
|
|
|
|
|
lineno, block, source )
|
2000-10-26 09:52:40 +02:00
|
|
|
|
format = 0
|
|
|
|
|
|
|
|
|
|
if format == 0: #### wait for beginning of comment ####
|
|
|
|
|
if l > 3 and line2[0 : 3] == '/**':
|
|
|
|
|
i = 3
|
|
|
|
|
while i < l and line2[i] == '*':
|
|
|
|
|
i = i + 1
|
|
|
|
|
|
|
|
|
|
if i == l:
|
|
|
|
|
# this is '/**' followed by any number of '*', the
|
|
|
|
|
# beginning of a Format 1 block
|
|
|
|
|
#
|
|
|
|
|
block = []
|
|
|
|
|
source = []
|
|
|
|
|
format = 1
|
2001-01-12 01:33:30 +01:00
|
|
|
|
lineno = fileinput.lineno()
|
2000-10-26 09:52:40 +02:00
|
|
|
|
|
|
|
|
|
elif i == l - 1 and line2[i] == '/':
|
|
|
|
|
# this is '/**' followed by any number of '*', followed
|
|
|
|
|
# by a '/', i.e. the beginning of a Format 2 or 3 block
|
|
|
|
|
#
|
|
|
|
|
block = []
|
|
|
|
|
source = []
|
|
|
|
|
format = 2
|
2001-01-12 01:33:30 +01:00
|
|
|
|
lineno = fileinput.lineno()
|
2000-10-26 09:52:40 +02:00
|
|
|
|
|
|
|
|
|
##############################################################
|
|
|
|
|
#
|
|
|
|
|
# FORMAT 1
|
|
|
|
|
#
|
|
|
|
|
elif format == 1:
|
|
|
|
|
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# If the line doesn't begin with a "*", something went
|
|
|
|
|
# wrong, and we must exit, and forget the current block.
|
|
|
|
|
#
|
2000-10-26 09:52:40 +02:00
|
|
|
|
if l == 0 or line2[0] != '*':
|
|
|
|
|
block = []
|
|
|
|
|
format = 0
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# Otherwise, we test for an end of block, which is an
|
|
|
|
|
# arbitrary number of '*', followed by '/'.
|
|
|
|
|
#
|
2000-10-26 09:52:40 +02:00
|
|
|
|
else:
|
|
|
|
|
i = 1
|
|
|
|
|
while i < l and line2[i] == '*':
|
|
|
|
|
i = i + 1
|
|
|
|
|
|
|
|
|
|
# test for the end of the block
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
2000-10-26 09:52:40 +02:00
|
|
|
|
if i < l and line2[i] == '/':
|
|
|
|
|
if block != []:
|
|
|
|
|
format = 4
|
|
|
|
|
else:
|
|
|
|
|
format = 0
|
|
|
|
|
else:
|
|
|
|
|
# otherwise simply append line to current block
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
2001-02-14 05:59:57 +01:00
|
|
|
|
block.append( line2[i :] )
|
2000-10-26 09:52:40 +02:00
|
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
##############################################################
|
|
|
|
|
#
|
|
|
|
|
# FORMAT 2
|
|
|
|
|
#
|
|
|
|
|
elif format == 2:
|
|
|
|
|
|
2000-12-06 17:31:30 +01:00
|
|
|
|
# If the line doesn't begin with '/*' and end with '*/',
|
|
|
|
|
# this is the end of the format 2 format.
|
|
|
|
|
#
|
2000-10-26 09:52:40 +02:00
|
|
|
|
if l < 4 or line2[: 2] != '/*' or line2[-2 :] != '*/':
|
|
|
|
|
if block != []:
|
|
|
|
|
format = 4
|
|
|
|
|
else:
|
|
|
|
|
format = 0
|
|
|
|
|
else:
|
|
|
|
|
# remove the start and end comment delimiters, then
|
|
|
|
|
# right-strip the line
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
2000-10-26 09:52:40 +02:00
|
|
|
|
line2 = string.rstrip( line2[2 : -2] )
|
|
|
|
|
|
|
|
|
|
# check for end of a format2 block, i.e. a run of '*'
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
2000-10-26 09:52:40 +02:00
|
|
|
|
if string.count( line2, '*' ) == l - 4:
|
|
|
|
|
if block != []:
|
|
|
|
|
format = 4
|
|
|
|
|
else:
|
|
|
|
|
format = 0
|
|
|
|
|
else:
|
|
|
|
|
# otherwise, add the line to the current block
|
2000-12-06 17:31:30 +01:00
|
|
|
|
#
|
2000-10-26 09:52:40 +02:00
|
|
|
|
block.append( line2 )
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-10-26 09:52:40 +02:00
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
if format >= 4: #### source processing ####
|
|
|
|
|
if l > 0:
|
|
|
|
|
format = 5
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-10-26 09:52:40 +02:00
|
|
|
|
if format == 5:
|
|
|
|
|
source.append( line )
|
|
|
|
|
|
|
|
|
|
if format >= 4:
|
2001-01-12 01:33:30 +01:00
|
|
|
|
add_new_block( list, fileinput.filename(), lineno, block, source )
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2000-10-26 09:52:40 +02:00
|
|
|
|
return list
|
|
|
|
|
|
|
|
|
|
|
2001-01-10 07:53:49 +01:00
|
|
|
|
|
2000-10-26 09:52:40 +02:00
|
|
|
|
# This function is only used for debugging
|
|
|
|
|
#
|
|
|
|
|
def dump_block_list( list ):
|
|
|
|
|
"""dump a comment block list"""
|
|
|
|
|
for block in list:
|
|
|
|
|
print "----------------------------------------"
|
|
|
|
|
for line in block[0]:
|
|
|
|
|
print line
|
|
|
|
|
for line in block[1]:
|
|
|
|
|
print line
|
|
|
|
|
|
|
|
|
|
print "---------the end-----------------------"
|
2000-08-22 01:01:32 +02:00
|
|
|
|
|
|
|
|
|
|
2000-08-27 09:12:40 +02:00
|
|
|
|
def main( argv ):
|
2000-01-10 16:49:01 +01:00
|
|
|
|
"""main program loop"""
|
2001-01-10 07:53:49 +01:00
|
|
|
|
|
|
|
|
|
# we begin by simply building a list of DocBlock elements
|
|
|
|
|
#
|
2000-08-27 09:12:40 +02:00
|
|
|
|
sys.stderr.write( "extracting comment blocks from sources...\n" )
|
2000-01-10 16:49:01 +01:00
|
|
|
|
list = make_block_list()
|
2000-10-31 21:42:18 +01:00
|
|
|
|
|
2001-01-10 07:53:49 +01:00
|
|
|
|
# now, sort the blocks into sections
|
|
|
|
|
#
|
2001-02-13 18:42:49 +01:00
|
|
|
|
document = DocDocument()
|
2000-12-05 15:49:39 +01:00
|
|
|
|
for block in list:
|
2001-02-13 18:42:49 +01:00
|
|
|
|
document.append_block( block )
|
2000-12-05 15:49:39 +01:00
|
|
|
|
|
2001-02-13 18:42:49 +01:00
|
|
|
|
document.prepare_files( "ft2" )
|
2001-01-10 07:53:49 +01:00
|
|
|
|
|
2001-02-13 18:42:49 +01:00
|
|
|
|
document.dump_toc_html()
|
|
|
|
|
document.dump_sections_html()
|
|
|
|
|
document.dump_index_html()
|
2001-02-14 05:59:57 +01:00
|
|
|
|
|
2001-02-13 18:42:49 +01:00
|
|
|
|
## section_list = DocSectionList()
|
|
|
|
|
## for block in list:
|
|
|
|
|
## section_list.append_block( block )
|
|
|
|
|
##
|
|
|
|
|
## section_list.prepare_files( "ft2" )
|
|
|
|
|
|
|
|
|
|
## # dump the section list TOC and sections
|
|
|
|
|
## #
|
|
|
|
|
## section_list.dump_html_toc()
|
|
|
|
|
## section_list.dump_html_sections()
|
|
|
|
|
## section_list.dump_html_index()
|
2000-01-10 16:49:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# If called from the command line
|
2001-01-11 10:27:49 +01:00
|
|
|
|
#
|
2000-08-27 09:12:40 +02:00
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
main( sys.argv )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# eof
|