Commit f52165cc068e5abc27bd64d793358c258e1acd18

David Turner 2002-07-30T18:49:52

* src/tools/docmaker/*: adding new (more advanced) version of the DocMaker tool. Python with regular expressions rocks..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
diff --git a/ChangeLog b/ChangeLog
index c4654f9..3ab8883 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,9 @@
         to demonstrate a "cleaner" API to support incremental font loading.
         comments appreciated...
 
+        * src/tools/docmaker/*: adding new (more advanced) version of
+        the DocMaker tool. Python with regular expressions rocks..
+
 2002-07-28  Werner Lemberg  <wl@gnu.org>
 
 	s/ft_memset/FT_MEM_SET/.
diff --git a/src/tools/docmaker/content.py b/src/tools/docmaker/content.py
new file mode 100644
index 0000000..52f7c11
--- /dev/null
+++ b/src/tools/docmaker/content.py
@@ -0,0 +1,547 @@
+#
+#  this file contains routines used to parse the content of documentation
+#  comment block and build a more structured objects out of them
+#
+
+from sources import *
+from utils import *
+import string, re
+
+
+# this regular expresion is used to detect code sequences. these
+# are simply code fragments embedded in '{' and '}' like in:
+#
+#  {
+#    x = y + z;
+#    if ( zookoo == 2 )
+#    {
+#      foobar();
+#    }
+#  }
+#
+# note that identation of the starting and ending accolades must be
+# exactly the same. the code sequence can contain accolades at greater
+# indentation
+#
+re_code_start = re.compile( r"(\s*){\s*$" )
+re_code_end   = re.compile( r"(\s*)}\s*$" )
+
+
+# this regular expression is used to isolate identifiers from
+# other text
+#
+re_identifier = re.compile( r'(\w*)' )
+
+
+#############################################################################
+#
+# The DocCode class is used to store source code lines.
+#
+#   'self.lines' contains a set of source code lines that will be dumped as
+#   HTML in a <PRE> tag.
+#
+#   The object is filled line by line by the parser; it strips the leading
+#   "margin" space from each input line before storing it in 'self.lines'.
+#
+class DocCode:
+
+    def __init__( self, margin, lines ):
+        self.lines  = []
+        self.words  = None
+
+        # remove margin spaces
+        for l in lines:
+            if string.strip( l[:margin] ) == "":
+                l = l[margin:]
+            self.lines.append( l )
+
+    def dump( self, prefix = "", width=60 ):
+        for l in self.lines:
+            print prefix + l
+
+
+#############################################################################
+#
+# The DocPara class is used to store "normal" text paragraph.
+#
+#   'self.words' contains the list of words that make up the paragraph
+#
+class DocPara:
+
+    def __init__( self, lines ):
+        self.lines = None
+        self.words = []
+        for l in lines:
+            l = string.strip(l)
+            self.words.extend( string.split( l ) )
+
+    def dump( self, prefix = "", width = 60 ):
+        cur  = ""  # current line
+        col  = 0   # current width
+
+        for word in self.words:
+            ln = len(word)
+            if col > 0:
+                ln = ln+1
+
+            if col + ln > width:
+                print prefix + cur
+                cur = word
+                col = len(word)
+            else:
+                if col > 0:
+                    cur = cur + " "
+                cur = cur + word
+                col = col + ln
+
+        if col > 0:
+            print prefix + cur
+
+
+
+#############################################################################
+#
+#  The DocField class is used to store a list containing either DocPara or
+#  DocCode objects. Each DocField also has an optional "name" which is used
+#  when the object corresponds to a field of value definition
+#
+class DocField:
+
+    def __init__( self, name, lines ):
+
+        self.name  = name  # can be None for normal paragraphs/sources
+        self.items = []     # list of items
+
+        mode_none  = 0   # start parsing mode
+        mode_code  = 1   # parsing code sequences
+        mode_para  = 3   # parsing normal paragraph
+
+        margin     = -1  # current code sequence indentation
+        cur_lines  = []
+
+        # now analyze the markup lines to see if they contain paragraphs,
+        # code sequences or fields definitions
+        #
+        start = 0
+        mode  = mode_none
+        for l in lines:
+
+            # are we parsing a code sequence ?
+            if mode == mode_code:
+
+                m = re_code_end.match( l )
+                if m and len(m.group(1)) <= margin:
+                    # that's it, we finised the code sequence
+                    code = DocCode( margin, cur_lines )
+                    self.items.append( code )
+                    margin    = -1
+                    cur_lines = []
+                    mode      = mode_none
+                else:
+                    # nope, continue the code sequence
+                    cur_lines.append( l[margin:] )
+            else:
+                # start of code sequence ?
+                m = re_code_start.match( l )
+                if m:
+                    # save current lines
+                    if cur_lines:
+                        para = DocPara( cur_lines )
+                        self.items.append( para )
+                        cur_lines = []
+
+                    # switch to code extraction mode
+                    margin = len(m.group(1))
+                    mode   = mode_code
+
+                else:
+                    if not string.split( l ) and cur_lines:
+                        # if the line is empty, we end the current paragraph,
+                        # if any
+                        para = DocPara( cur_lines )
+                        self.items.append( para )
+                        cur_lines = []
+                    else:
+                        # otherwise, simply add the line to the current
+                        # paragraph
+                        cur_lines.append( l )
+
+        if mode == mode_code:
+            # unexpected end of code sequence
+            code = DocCode( margin, cur_lines )
+            self.items.append( code )
+
+        elif cur_lines:
+            para = DocPara( cur_lines )
+            self.items.append( para )
+
+    def dump( self, prefix = "" ):
+        if self.field:
+            print prefix + self.field + " ::"
+            prefix = prefix + "----"
+
+        first = 1
+        for p in self.items:
+            if not first:
+                print ""
+            p.dump( prefix )
+            first = 0
+
+
+# this regular expression is used to detect field definitions
+#
+re_field  = re.compile( r"\s*(\w*)\s*::" )
+
+
+
+class DocMarkup:
+
+    def __init__( self, tag, lines ):
+        self.tag       = string.lower(tag)
+        self.fields    = []
+
+        cur_lines = []
+        field     = None
+        mode      = 0
+
+        for l in lines:
+            m = re_field.match( l )
+            if m:
+                # we detected the start of a new field definition
+
+                # first, save the current one
+                if cur_lines:
+                    f = DocField( field, cur_lines )
+                    self.fields.append( f )
+                    cur_lines = []
+                    field     = None
+
+                field     = m.group(1)   # record field name
+                ln        = len(m.group(0))
+                l         = " "*ln + l[ln:]
+                cur_lines = [ l ]
+            else:
+                cur_lines.append( l )
+
+        if field or cur_lines:
+            f = DocField( field, cur_lines )
+            self.fields.append( f )
+
+    def get_name( self ):
+        try:
+            return self.fields[0].items[0].words[0]
+
+        except:
+            return None
+
+    def dump( self, margin ):
+        print " "*margin + "<" + self.tag + ">"
+        for f in self.fields:
+            f.dump( "  " )
+        print " "*margin + "</" + self.tag + ">"
+
+
+
+
+class DocChapter:
+
+    def __init__( self, block ):
+        self.block    = block
+        self.sections = []
+        if block:
+            self.name     = block.name
+            self.title    = block.get_markup_words( "title" )
+            self.order    = block.get_markup_words( "sections" )
+        else:
+            self.name     = "Other"
+            self.title    = string.split( "Miscellaneous" )
+            self.order    = []
+
+
+
+class DocSection:
+
+    def __init__( self, name = "Other" ):
+        self.name        = name
+        self.blocks      = {}
+        self.block_names = []  # ordered block names in section
+        self.defs        = []
+        self.abstract    = ""
+        self.description = ""
+        self.order       = []
+        self.title       = "ERROR"
+        self.chapter     = None
+
+    def add_def( self, block ):
+        self.defs.append( block )
+
+    def add_block( self, block ):
+        self.block_names.append( block.name )
+        self.blocks[ block.name ] = block
+
+    def process( self ):
+        # lookup one block that contains a valid section description
+        for block in self.defs:
+            title = block.get_markup_text( "Title" )
+            if title:
+                self.title       = title
+                self.abstract    = block.get_markup_words( "abstract" )
+                self.description = block.get_markup_items( "description" )
+                self.order       = block.get_markup_words( "order" )
+                return
+                
+    def reorder( self ):
+        
+        self.block_names = sort_order_list( self.block_names, self.order )
+
+
+class ContentProcessor:
+
+    def __init__( self ):
+        """initialize a block content processor"""
+        self.reset()
+        
+        self.sections = {}    # dictionary of documentation sections
+        self.section  = None  # current documentation section
+
+        self.chapters = []        # list of chapters
+
+    def set_section( self, section_name ):
+        """set current section during parsing"""
+        if not self.sections.has_key( section_name ):
+            section = DocSection( section_name )
+            self.sections[ section_name ] = section
+            self.section                  = section
+        else:
+            self.section = self.sections[ section_name ]
+
+    def add_chapter( self, block ):
+        chapter = DocChapter( block )
+        self.chapters.append( chapter )
+
+
+    def reset( self ):
+        """reset the content processor for a new block"""
+        self.markups      = []
+        self.markup       = None
+        self.markup_lines = []
+
+    def add_markup( self ):
+        """add a new markup section"""
+        if self.markup and self.markup_lines:
+
+            # get rid of last line of markup if it's empty
+            marks = self.markup_lines
+            if len(marks) > 0 and not string.strip(marks[-1]):
+                self.markup_lines = marks[:-1]
+
+            m = DocMarkup( self.markup, self.markup_lines )
+
+            self.markups.append( m )
+
+            self.markup       = None
+            self.markup_lines = []
+
+
+    def process_content( self, content ):
+        """process a block content and return a list of DocMarkup objects
+           corresponding to it"""
+        markup       = None
+        markup_lines = []
+        first        = 1
+
+        for line in content:
+            found = None
+            for t in re_markup_tags:
+                m = t.match( line )
+                if m:
+                    found  = string.lower(m.group(1))
+                    prefix = len(m.group(0))
+                    line   = " "*prefix + line[prefix:]   # remove markup from line
+                    break
+
+            # is it the start of a new markup section ?
+            if found:
+                first = 0
+                self.add_markup()  # add current markup content
+                self.markup = found
+                if len(string.strip( line )) > 0:
+                    self.markup_lines.append( line )
+            elif first == 0:
+                self.markup_lines.append( line )
+
+        self.add_markup()
+
+        return self.markups
+
+
+    def  parse_sources( self, source_processor ):
+        blocks = source_processor.blocks
+        count  = len(blocks)
+        for n in range(count):
+            
+            source = blocks[n]
+            if source.content:
+                # this is a documentation comment, we need to catch
+                # all following normal blocks in the "follow" list
+                #
+                follow = []
+                m = n+1
+                while m < count and not blocks[m].content:
+                    follow.append( blocks[m] )
+                    m = m+1
+
+                doc_block = DocBlock( source, follow, self )
+    
+    
+    def  finish( self ):
+
+        # process all sections to extract their abstract, description
+        # and ordered list of items
+        #
+        for sec in self.sections.values():
+            sec.process()
+
+        # process chapters to check that all sections are correctly
+        # listed there
+        for chap in self.chapters:
+            for sec in chap.order:
+                if self.sections.has_key(sec):
+                    section = self.sections[ sec ]
+                    section.chapter = chap
+                    section.reorder()
+                    chap.sections.append( section )
+                else:
+                    sys.stderr.write( "WARNING: chapter '" +
+                        chap.name + "' in " + chap.block.location() + \
+                        " lists unknown section '" + sec + "'\n" )
+
+        # check that all sections are in a chapter
+        #
+        others = []
+        for sec in self.sections.values():
+            if not sec.chapter:
+                others.append(sec)
+
+        # create a new special chapter for all remaining sections
+        # when necessary
+        #
+        if others:
+            chap = DocChapter( None )
+            chap.sections = others
+            self.chapters.append( chap )
+            
+
+
+class DocBlock:
+
+    def __init__( self, source, follow, processor ):
+        
+        processor.reset()
+
+        self.source    = source
+        self.code      = []
+        self.type      = "ERRTYPE"
+        self.name      = "ERRNAME"
+        self.section   = processor.section
+        self.markups   = processor.process_content( source.content )
+
+        # compute block type from first markup tag
+        try:
+            self.type = self.markups[0].tag
+        except:
+            pass
+        
+            
+        # compute block name from first markup paragraph
+        try:
+            markup = self.markups[0]
+            para   = markup.fields[0].items[0]
+            name   = para.words[0]
+            m = re_identifier.match( name )
+            if m:
+                name = m.group(1)
+            self.name = name
+        except:
+            pass
+
+        # detect new section starts
+        if self.type == "section":
+            processor.set_section( self.name )
+            processor.section.add_def( self )
+
+        # detect new chapter
+        elif self.type == "chapter":
+            processor.add_chapter( self )
+
+        else:
+            processor.section.add_block( self )
+
+        # now, compute the source lines relevant to this documentation
+        # block. We keep normal comments in for obvious reasons (??)
+        source = []
+        for b in follow:
+            if b.format:
+                break
+            for l in b.lines:
+                # we use "/* */" as a separator
+                if re_source_sep.match( l ):
+                    break
+                source.append( l )
+
+        # now strip the leading and trailing empty lines from the sources
+        start = 0
+        end   = len( source )-1
+        
+        while start < end and not string.strip( source[start] ):
+            start = start + 1
+
+        while start < end and not string.strip( source[end] ):
+            end = end - 1
+
+        source = source[start:end+1]
+
+        self.code = source
+
+
+    def location( self ):
+        return self.source.location()
+
+
+
+    def get_markup( self, tag_name ):
+        """return the DocMarkup corresponding to a given tag in a block"""
+        for m in self.markups:
+            if m.tag == string.lower(tag_name):
+                return m
+        return None
+
+
+    def get_markup_name( self, tag_name ):
+        """return the name of a given primary markup in a block"""
+        try:
+            m = self.get_markup( tag_name )
+            return m.get_name()
+        except:
+            return None
+
+
+    def get_markup_words( self, tag_name ):
+        try:
+            m = self.get_markup( tag_name )
+            return m.fields[0].items[0].words
+        except:
+            return []
+
+
+    def get_markup_text( self, tag_name ):
+        result = self.get_markup_words( tag_name )
+        return string.join( result )
+
+
+    def get_markup_items( self, tag_name ):
+        try:
+            m = self.get_markup( tag_name )
+            return m.fields[0].items
+        except:
+            return None
\ No newline at end of file
diff --git a/src/tools/docmaker/docmaker.py b/src/tools/docmaker/docmaker.py
new file mode 100644
index 0000000..a502c9c
--- /dev/null
+++ b/src/tools/docmaker/docmaker.py
@@ -0,0 +1,120 @@
+#!/usr/bin/env python
+#
+#  DocMaker 0.2 (c) 2002 David Turner <david@freetype.org>
+#
+# This program is a re-write of the original DocMaker took used
+# to generate the API Reference of the FreeType font engine
+# by converting in-source comments into structured HTML
+#
+# This new version is capable of outputting XML data, as well
+# as accepts more liberal formatting options
+#
+# It also uses regular expression matching and substitution
+# to speed things significantly
+#
+
+from sources import *
+from content import *
+from tohtml  import *
+
+import sys, os, time, string, glob, getopt
+
+
+def file_exists( pathname ):
+    """checks that a given file exists"""
+    result = 1
+    try:
+        file = open( pathname, "r" )
+        file.close()
+    except:
+        result = None
+        sys.err.write( pathname + " couldn't be accessed\n" )
+
+    return result
+
+
+def make_file_list( args = None ):
+    """builds a list of input files from command-line arguments"""
+
+    file_list = []
+    # sys.stderr.write( repr( sys.argv[1 :] ) + '\n' )
+
+    if not args:
+        args = sys.argv[1 :]
+
+    for pathname in args:
+        if string.find( pathname, '*' ) >= 0:
+            newpath = glob.glob( pathname )
+            newpath.sort()  # sort files -- this is important because
+                            # of the order of files
+        else:
+            newpath = [pathname]
+            
+        last = len( file_list )
+        file_list[last : last] = newpath
+
+    if len( file_list ) == 0:
+        file_list = None
+    else:
+        # now filter the file list to remove non-existing ones
+        file_list = filter( file_exists, file_list )
+    
+    return file_list
+
+
+
+def usage():
+    print "\nDocMaker 0.2 Usage information\n"
+    print "  docmaker [options] file1 [ file2 ... ]\n"
+    print "using the following options:\n"
+    print "  -h : print this page"
+    
+
+def main( argv ):
+    """main program loop"""
+
+    try:
+        opts, args = getopt.getopt( argv[1:],"h", [ "help" ] )
+
+    except getopt.GetoptError:
+        usage()
+        sys.exit( 2 )
+
+    if args == []:
+        usage()
+        sys.exit( 1 )
+
+    # process options
+    #
+    for opt in opts:
+        if opt[0] in ( "-h", "--help" ):
+            usage()
+            sys.exit( 0 )
+
+    # create context and processor
+    source_processor  = SourceProcessor()
+    content_processor = ContentProcessor()
+
+    # retrieve the list of files to process
+    file_list = make_file_list()
+    for filename in file_list:
+        source_processor.parse_file( filename )
+        content_processor.parse_sources( source_processor )
+        
+    # process sections
+    content_processor.finish()
+
+    formatter = HtmlFormatter( content_processor, "Example", "zz" )
+
+    formatter.toc_dump()
+    formatter.index_dump()
+    formatter.section_dump_all()
+
+
+# if called from the command line
+#
+if __name__ == '__main__':
+    main( sys.argv )
+
+
+# eof
diff --git a/src/tools/docmaker/formatter.py b/src/tools/docmaker/formatter.py
new file mode 100644
index 0000000..36d72ae
--- /dev/null
+++ b/src/tools/docmaker/formatter.py
@@ -0,0 +1,194 @@
+from sources import *
+from content import *
+from utils   import *
+
+class Formatter:
+
+    def __init__( self, processor ):
+
+        self.processor   = processor
+        self.identifiers = {}
+        self.chapters    = processor.chapters
+        self.sections    = processor.sections.values()
+        self.block_index = []
+
+        # store all blocks in a dictionary
+        self.blocks      = []
+        for section in self.sections:
+            for block in section.blocks.values():
+                self.add_identifier( block.name, block )
+                    
+                # add enumeration values to the index, since this is useful
+                for markup in block.markups:
+                    if markup.tag == 'values':
+                        for field in markup.fields:
+                            self.add_identifier( field.name, block )
+
+
+        self.block_index = self.identifiers.keys()
+        self.block_index.sort( index_sort )
+
+
+    def add_identifier( self, name, block ):
+        if self.identifiers.has_key( name ):
+            # duplicate name !!
+            sys.stderr.write( \
+               "WARNING: duplicate definition for '" + name + "' in " + \
+               block.location() + ", previous definition in " +         \
+               self.identifiers[ name ].location() + "\n" )
+        else:
+            self.identifiers[name] = block
+              
+
+    #
+    #  Formatting the table of contents
+    #
+
+    def  toc_enter( self ):
+        pass
+    
+    def  toc_chapter_enter( self, chapter ):
+        pass
+    
+    def  toc_section_enter( self, section ):
+        pass
+        
+    def  toc_section_exit( self, section ):
+        pass
+        
+    def  toc_chapter_exit( self, chapter ):
+        pass
+
+    def  toc_index( self, index_filename ):
+        pass
+    
+    def  toc_exit( self ):
+        pass
+
+    def  toc_dump( self, toc_filename = None, index_filename = None ):
+        
+        output = None
+        if toc_filename:
+            output = open_output( toc_filename )
+        
+        self.toc_enter()
+    
+        for chap in self.processor.chapters:
+    
+            self.toc_chapter_enter( chap )
+    
+            for section in chap.sections:
+                self.toc_section_enter( section )
+                self.toc_section_exit( section )
+    
+            self.toc_chapter_exit ( chap )
+    
+        self.toc_index( index_filename )
+    
+        self.toc_exit()
+
+        if output:
+            close_output( output )
+    
+    #
+    #  Formatting the index
+    #
+
+    def  index_enter( self ):
+        pass
+
+    def  index_name_enter( self, name ):
+        pass
+
+    def  index_name_exit( self, name ):
+        pass
+
+    def  index_exit( self ):
+        pass
+
+    def  index_dump( self, index_filename = None ):
+        
+        output = None
+        if index_filename:
+            output = open_output( index_filename )
+
+        self.index_enter()
+
+        for name in self.block_index:
+            self.index_name_enter( name )
+            self.index_name_exit ( name )
+
+        self.index_exit()
+     
+        if output:
+            close_output( output )
+     
+    #
+    #  Formatting a section
+    #
+    def  section_enter( self, section ):
+        pass
+    
+    def  block_enter( self, block ):
+        pass
+    
+    def  markup_enter( self, markup, block = None ):
+        pass
+    
+    def  field_enter( self, field, markup = None, block = None ):
+        pass
+        
+    def  field_exit( self, field, markup = None, block = None ):
+        pass
+    
+    def  markup_exit( self, markup, block = None ):
+        pass
+        
+    def  block_exit( self, block ):
+        pass
+
+    def  section_exit( self, section ):
+        pass
+
+
+    def  section_dump( self, section, section_filename = None ):
+        
+        output = None
+        if section_filename:
+            output = open_output( section_filename )
+        
+        self.section_enter( section )
+
+        for name in section.block_names:
+            block = self.identifiers[ name ]
+            self.block_enter( block )
+
+            for markup in block.markups[1:]:   # always ignore first markup !!
+                self.markup_enter( markup, block )
+
+                for field in markup.fields:
+                    self.field_enter( field, markup, block )
+
+                    self.field_exit ( field, markup, block )
+
+                self.markup_exit( markup, block )
+
+            self.block_exit( block )
+
+        self.section_exit ( section )
+
+        if output:
+            close_output( output )
+
+
+    def section_dump_all( self ):
+        for section in self.sections:
+            self.section_dump( section )
+
+    #
+    #  Formatting a block
+    #
+
+
+
+
diff --git a/src/tools/docmaker/sources.py b/src/tools/docmaker/sources.py
new file mode 100644
index 0000000..6961cd9
--- /dev/null
+++ b/src/tools/docmaker/sources.py
@@ -0,0 +1,355 @@
+#
+# this file contains definitions of classes needed to decompose
+# C sources files into a series of multi-line "blocks". There are
+# two kinds of blocks:
+#
+#   - normal blocks, which contain source code or ordinary comments
+#
+#   - documentation blocks, which have restricted formatting, and
+#     whose text always start with a documentation markup tag like
+#     "<Function>", "<Type>", etc..
+#
+# the routines used to process the content of documentation blocks
+# are not contained here, but in "doccontent.py"
+#
+# the classes and methods found here only deal with text parsing
+# and basic documentation block extraction
+#
+import fileinput, re, sys, os, string
+
+
+
+
+
+
+################################################################
+##
+##  BLOCK FORMAT PATTERN
+##
+##   A simple class containing compiled regular expressions used
+##   to detect potential documentation format block comments within
+##   C source code
+##
+##   note that the 'column' pattern must contain a group that will
+##   be used to "unbox" the content of documentation comment blocks
+##
+class SourceBlockFormat:
+
+    def __init__( self, id, start, column, end ):
+        """create a block pattern, used to recognize special documentation blocks"""
+
+        self.id     = id
+        self.start  = re.compile( start, re.VERBOSE )
+        self.column = re.compile( column, re.VERBOSE )
+        self.end    = re.compile( end, re.VERBOSE )
+
+
+
+#
+# format 1 documentation comment blocks look like the following:
+#
+#    /************************************/
+#    /*                                  */
+#    /*                                  */
+#    /*                                  */
+#    /************************************/
+#
+# we define a few regular expressions here to detect them
+#
+
+start = r'''
+  \s*       # any number of whitespace
+  /\*{2,}/  # followed by '/' and at least two asterisks then '/'
+  \s*$      # eventually followed by whitespace
+'''
+
+column = r'''
+  \s*      # any number of whitespace
+  /\*{1}   # followed by '/' and precisely one asterisk
+  ([^*].*) # followed by anything (group 1)
+  \*{1}/   # followed by one asterisk and a '/'
+  \s*$     # enventually followed by whitespace
+'''
+
+re_source_block_format1 = SourceBlockFormat( 1, start, column, start )
+
+#
+# format 2 documentation comment blocks look like the following:
+#
+#    /************************************
+#     *
+#     *                                                                    
+#     *                                                                    
+#     *                                                                    
+#     **/       (1 or more asterisks at the end)
+#
+# we define a few regular expressions here to detect them
+#
+start = r'''
+  \s*     # any number of whitespace
+  /\*{2,} # followed by '/' and at least two asterisks
+  \s*$    # eventually followed by whitespace
+'''
+
+column = r'''
+  \s*         # any number of whitespace
+  \*{1}       # followed by precisely one asterisk
+  (.*)        # followed by anything (group1)
+'''
+
+end = r'''
+  \s*     # any number of whitespace
+  \*+/    # followed by at least on asterisk, then '/'
+'''
+
+re_source_block_format2 = SourceBlockFormat( 2, start, column, end )
+
+#
+# the list of supported documentation block formats, we could add new ones
+# relatively easily
+#
+re_source_block_formats = [ re_source_block_format1, re_source_block_format2 ]
+
+
+#
+# the following regular expressions corresponds to markup tags
+# within the documentation comment blocks. they're equivalent
+# despite their different syntax
+#
+# notice how each markup tag _must_ begin a new line
+#
+re_markup_tag1 = re.compile( r'''\s*<(\w*)>''' )  # <xxxx> format
+re_markup_tag2 = re.compile( r'''\s*@(\w*):''' )  # @xxxx: format
+
+#
+# the list of supported markup tags, we could add new ones relatively
+# easily
+#
+re_markup_tags = [ re_markup_tag1, re_markup_tag2 ]
+
+#
+# used to detect a cross-reference, after markup tags have been stripped
+#
+re_crossref = re.compile( r'@(\w*)' )
+
+#
+# used to detect italic and bold styles in paragraph text
+#
+re_italic = re.compile( r'_(\w+)_' )
+re_bold   = re.compile( r'\*(\w+)\*' )
+
+#
+# used to detect the end of commented source lines
+#
+re_source_sep = re.compile( r'\s*/\*\s*\*/' )
+
+#
+# used to perform cross-reference within source output
+#
+re_source_crossref = re.compile( r'(\W*)(\w*)' )
+
+#
+# a list of reserved source keywords
+#
+re_source_keywords = re.compile( '''( typedef | 
+                                       struct |
+                                       enum   |
+                                       union  |
+                                       const  |
+                                       char   |
+                                       int    |
+                                       short  |
+                                       long   |
+                                       void   |
+                                       signed |
+                                       unsigned |
+                                       \#include |
+                                       \#define  |
+                                       \#undef   |
+                                       \#if      |
+                                       \#ifdef   |
+                                       \#ifndef  |
+                                       \#else    |
+                                       \#endif   )''', re.VERBOSE )
+
+################################################################
+##
+##  SOURCE BLOCK CLASS
+##
+##   A SourceProcessor is in charge or reading a C source file
+##   and decomposing it into a series of different "SourceBlocks".
+##   each one of these blocks can be made of the following data:
+##
+##   - A documentation comment block that starts with "/**" and
+##     whose exact format will be discussed later
+##
+##   - normal sources lines, include comments
+##
+##   the important fields in a text block are the following ones:
+##
+##     self.lines   : a list of text lines for the corresponding block
+##
+##     self.content : for documentation comment blocks only, this is the
+##                    block content that has been "unboxed" from its
+##                    decoration. This is None for all other blocks
+##                    (i.e. sources or ordinary comments with no starting
+##                     markup tag)
+##
+class SourceBlock:
+    def __init__( self, processor, filename, lineno, lines ):
+        self.processor = processor
+        self.filename  = filename
+        self.lineno    = lineno
+        self.lines     = lines
+        self.format    = processor.format
+        self.content   = []
+
+        if self.format == None:
+            return
+
+        words = []
+
+        # extract comment lines
+        lines = []
+
+        for line0 in self.lines[1:]:
+            m = self.format.column.match( line0 )
+            if m:
+                lines.append( m.group(1) )
+
+        # now, look for a markup tag
+        for l in lines:
+            l = string.strip(l)
+            if len(l) > 0:
+                for tag in re_markup_tags:
+                    if tag.match( l ):
+                        self.content = lines
+                return
+
+    def location( self ):
+        return "(" + self.filename + ":" + repr(self.lineno) + ")"
+
+
+    # debugging only - not used in normal operations
+    def dump( self ):
+        
+        if self.content:
+            print "{{{content start---"
+            for l in self.content:
+                print l
+            print "---content end}}}"
+            return
+            
+        fmt = ""
+        if self.format:
+            fmt = repr(self.format.id) + " "
+        
+        for line in self.lines:
+            print line
+
+
+################################################################
+##
+##  SOURCE PROCESSOR CLASS
+##
+##   The SourceProcessor is in charge or reading a C source file
+##   and decomposing it into a series of different "SourceBlock"
+##   objects.
+##
+##   each one of these blocks can be made of the following data:
+##
+##   - A documentation comment block that starts with "/**" and
+##     whose exact format will be discussed later
+##
+##   - normal sources lines, include comments
+##
+##
+class SourceProcessor:
+
+    def  __init__( self ):
+        """initialize a source processor"""
+        self.blocks   = []
+        self.filename = None
+        self.format   = None
+        self.lines    = []
+
+    def  reset( self ):
+        """reset a block processor, clean all its blocks"""
+        self.blocks = []
+        self.format = None
+
+
+    def  parse_file( self, filename ):
+        """parse a C source file, and adds its blocks to the processor's list"""
+        
+        self.reset()
+        
+        self.filename = filename
+        
+        fileinput.close()
+        self.format    = None
+        self.lineno    = 0
+        self.lines     = []
+
+        for line in fileinput.input( filename ):
+            
+            # strip trailing newlines, important on Windows machines !!
+            if  line[-1] == '\012':
+                line = line[0:-1]
+    
+            if self.format == None:
+                self.process_normal_line( line )
+
+            else:
+                if self.format.end.match( line ):
+                    # that's a normal block end, add it to lines and
+                    # create a new block
+                    self.lines.append( line )
+                    self.add_block_lines()
+                    
+                elif self.format.column.match( line ):
+                    # that's a normal column line, add it to 'lines'
+                    self.lines.append( line )
+                        
+                else:
+                    # humm.. this is an unexcepted block end,
+                    # create a new block, but don't process the line
+                    self.add_block_lines()
+                    
+                    # we need to process the line again
+                    self.process_normal_line( line )
+                                
+        # record the last lines
+        self.add_block_lines()
+
+        
+
+    def process_normal_line( self, line ):
+        """process a normal line and check if it's the start of a new block"""
+        for f in re_source_block_formats:
+          if f.start.match( line ):
+            self.add_block_lines()
+            self.format = f
+            self.lineno = fileinput.filelineno()
+
+        self.lines.append( line )
+
+    
+
+    def add_block_lines( self ):
+        """add the current accumulated lines, and create a new block"""
+        if self.lines != []:
+            block = SourceBlock( self, self.filename, self.lineno, self.lines )
+            
+            self.blocks.append( block )
+            self.format = None
+            self.lines  = []
+
+    
+    # debugging only, not used in normal operations
+    def dump( self ):
+        """print all blocks in a processor"""
+        for b in self.blocks:
+            b.dump()
+
+# eof
diff --git a/src/tools/docmaker/tohtml.py b/src/tools/docmaker/tohtml.py
new file mode 100644
index 0000000..1067d34
--- /dev/null
+++ b/src/tools/docmaker/tohtml.py
@@ -0,0 +1,475 @@
+from sources import *
+from content import *
+from formatter import *
+import time
+
+# The following defines the HTML header used by all generated pages.
+#
+html_header_1 = """\
+<html>
+<header>
+<title>"""
+
+html_header_2= """ API Reference</title>
+<basefont face="Verdana,Geneva,Arial,Helvetica">
+<style content="text/css">
+  P { text-align=justify }
+  H1 { text-align=center }
+  LI { text-align=justify }
+</style>
+</header>
+<body text=#000000
+      bgcolor=#FFFFFF
+      link=#0000EF
+      vlink=#51188E
+      alink=#FF0000>
+<center><h1>"""
+
+html_header_3=""" API Reference</h1></center>
+"""
+
+
+
+# The HTML footer used by all generated pages.
+#
+html_footer = """\
+</body>
+</html>"""
+
+# The header and footer used for each section.
+#
+section_title_header = "<center><h1>"
+section_title_footer = "</h1></center>"
+
+# The header and footer used for code segments.
+#
+code_header = "<font color=blue><pre>"
+code_footer = "</pre></font>"
+
+# Paragraph header and footer.
+#
+para_header = "<p>"
+para_footer = "</p>"
+
+# Block header and footer.
+#
+block_header = "<center><table width=75%><tr><td>"
+block_footer = "</td></tr></table><hr width=75%></center>"
+
+# Description header/footer.
+#
+description_header = "<center><table width=87%><tr><td>"
+description_footer = "</td></tr></table></center><br>"
+
+# Marker header/inter/footer combination.
+#
+marker_header = "<center><table width=87% cellpadding=5><tr bgcolor=#EEEEFF><td><em><b>"
+marker_inter  = "</b></em></td></tr><tr><td>"
+marker_footer = "</td></tr></table></center>"
+
+# Source code extracts header/footer.
+#
+source_header = "<center><table width=87%><tr bgcolor=#D6E8FF width=100%><td><pre>\n"
+source_footer = "\n</pre></table></center><br>"
+
+# Chapter header/inter/footer.
+#
+chapter_header = "<br><center><table width=75%><tr><td><h2>"
+chapter_inter  = "</h2><ul>"
+chapter_footer = "</ul></td></tr></table></center>"
+
+
+# source language keyword coloration/styling
+#
+keyword_prefix = '<font color="darkblue">'
+keyword_suffix = '</font>'
+
+section_synopsis_header = '<h2>Synopsys</h2><font color="cyan">'
+section_synopsis_footer = '</font>'
+
+# Translate a single line of source to HTML.  This will convert
+# a "<" into "&lt.", ">" into "&gt.", etc.
+#
+def html_quote( line ):
+    result = string.replace( line,   "&", "&amp;" )
+    result = string.replace( result, "<", "&lt;" )
+    result = string.replace( result, ">", "&gt;" )
+    return result
+
+
+# same as 'html_quote', but ignores left and right brackets
+#
+def html_quote0( line ):
+    return string.replace( line, "&", "&amp;" )
+
+
+def dump_html_code( lines, prefix = "" ):
+    # clean the last empty lines
+    #
+    l = len( self.lines )
+    while l > 0 and string.strip( self.lines[l - 1] ) == "":
+        l = l - 1
+
+    # The code footer should be directly appended to the last code
+    # line to avoid an additional blank line.
+    #
+    print prefix + code_header,
+    for line in self.lines[0 : l+1]:
+        print '\n' + prefix + html_quote(line),
+    print prefix + code_footer,
+
+
+
+class HtmlFormatter(Formatter):
+    
+    def __init__( self, processor, project_title, file_prefix ):
+        
+        Formatter.__init__( self, processor )
+        
+        global html_header_1, html_header_2, html_header_3, html_footer
+        
+        if file_prefix:
+            file_prefix = file_prefix + "-"
+        else:
+            file_prefix = ""
+
+        self.project_title = project_title
+        self.file_prefix   = file_prefix
+        self.html_header   = html_header_1 + project_title + html_header_2 + \
+                             project_title + html_header_3
+    
+        self.html_footer = "<p><center><font size=""-2"">generated on " +   \
+                            time.asctime( time.localtime( time.time() ) ) + \
+                           "</font></p></center>" + html_footer
+        
+        self.columns = 3
+    
+    def  make_section_url( self, section ):
+        return self.file_prefix + section.name + ".html"
+
+
+    def  make_block_url( self, block ):
+        return self.make_section_url( block.section ) + "#" + block.name
+
+
+    def  make_html_words( self, words ):
+        """ convert a series of simple words into some HTML text """
+        line = ""
+        if words:
+            line = html_quote( words[0] )
+            for w in words[1:]:
+                line = line + " " + html_quote( w )
+
+        return line
+
+
+    def  make_html_word( self, word ):
+        """analyze a simple word to detect cross-references and styling"""
+        # look for cross-references
+        #
+        m = re_crossref.match( word )
+        if m:
+            try:
+                name = m.group(1)
+                block = self.identifiers[ name ]
+                url   = self.make_block_url( block )
+                return '<a href="' + url + '">' + name + '</a>'
+            except:
+                return '?' + name + '?'
+
+        # look for italics and bolds
+        m = re_italic.match( word )
+        if m:
+            name = m.group(1)
+            return '<i>'+name+'</i>'
+    
+        m = re_bold.match( word )
+        if m:
+            name = m.group(1)
+            return '<b>'+name+'</b>'
+
+        return html_quote(word)
+
+
+    def  make_html_para( self, words ):
+        """ convert a paragraph's words into tagged HTML text, handle xrefs """
+        line = ""
+        if words:
+            line = self.make_html_word( words[0] )
+            for word in words[1:]:
+                line = line + " " + self.make_html_word( word )
+        
+        return "<p>" + line + "</p>"
+
+
+    def  make_html_code( self, lines ):
+        """ convert a code sequence to HTML """
+        line = code_header + '\n'
+        for l in lines:
+            line = line + html_quote( l ) + '\n'
+
+        return line + code_footer
+
+
+    def  make_html_items( self, items ):
+        """ convert a field's content into some valid HTML """
+        lines = []
+        for item in items:
+            if item.lines:
+                lines.append( self.make_html_code( item.lines ) )
+            else:
+                lines.append( self.make_html_para( item.words ) )
+
+        return string.join( lines, '\n' )
+
+
+    def  print_html_items( self, items ):
+        print self.make_html_items( items )
+
+
+    def print_html_field( self, field ):
+        if field.name:
+            print "<table valign=top><tr><td><b>"+field.name+"</b></td><td>"
+
+        print self.make_html_items( field.items )
+        
+        if field.name:
+            print "</td></tr></table>"
+
+
+    def html_source_quote( self, line, block_name = None ):
+        result = ""
+        while line:
+            m = re_source_crossref.match( line )
+            if m:
+                name   = m.group(2)
+                prefix = html_quote( m.group(1) )
+                length = len( m.group(0) )
+                
+                if name == block_name:
+                    # this is the current block name, if any
+                    result = result + prefix + '<b>' + name + '</b>'
+                
+                elif re_source_keywords.match(name):
+                    # this is a C keyword
+                    result = result + prefix + keyword_prefix + name + keyword_suffix
+                    
+                elif self.identifiers.has_key(name):
+                    # this is a known identifier
+                    block = self.identifiers[name]
+                    result = result + prefix + '<a href="' + \
+                             self.make_block_url(block) + '">' + name + '</a>'
+                else:
+                    result = result + html_quote(line[ : length ])
+
+                line = line[ length : ]
+            else:
+                result = result + html_quote(line)
+                line   = []
+        
+        return result
+
+
+    def print_html_field_list( self, fields ):
+        print "<table valign=top cellpadding=3>"
+        for field in fields:
+            print "<tr><td><b>" + field.name + "</b></td><td>"
+            self.print_html_items( field.items )
+            print "</td></tr>"
+        print "</table>"
+    
+    
+    def print_html_markup( self, markup ):
+        table_fields = []
+        for field in markup.fields:
+            if field.name:
+                # we begin a new series of field or value definitions, we
+                # will record them in the 'table_fields' list before outputting
+                # all of them as a single table
+                #
+                table_fields.append( field )
+                
+            else:
+                if table_fields:
+                    self.print_html_field_list( table_fields )
+                    table_fields = []
+    
+                self.print_html_items( field.items )
+        
+        if table_fields:
+            self.print_html_field_list( table_fields )
+
+    #
+    #  Formatting the index
+    #
+    
+    def  index_enter( self ):
+        print self.html_header
+        self.index_items = {}
+
+    def  index_name_enter( self, name ):
+        block = self.identifiers[ name ]
+        url   = self.make_block_url( block )
+        self.index_items[ name ] = url
+
+    def  index_exit( self ):
+        
+        # block_index already contains the sorted list of index names
+        count = len( self.block_index )
+        rows  = (count + self.columns - 1)/self.columns
+        
+        print "<center><table border=0 cellpadding=0 cellspacing=0>"
+        for r in range(rows):
+            line = "<tr>"
+            for c in range(self.columns):
+                i = r + c*rows
+                if i < count:
+                    bname = self.block_index[ r + c*rows ]
+                    url   = self.index_items[ bname ]
+                    line = line + '<td><a href="' + url + '">' + bname + '</a></td>'
+                else:
+                    line = line + '<td></td>'
+            line = line + "</tr>"
+            print line
+
+        print "</table></center>"
+        print self.html_footer
+        self.index_items = {}
+
+    def  index_dump( self, index_filename = None ):
+        
+        if index_filename == None:
+            index_filename = self.file_prefix + "index.html"
+
+        Formatter.index_dump( self, index_filename )
+
+    #
+    #  Formatting the table of content
+    #    
+    def  toc_enter( self ):
+        print self.html_header
+        print "<center><h1>Table of Contents</h1></center>"
+
+    def  toc_chapter_enter( self, chapter ):
+        print  chapter_header + string.join(chapter.title) + chapter_inter
+        print "<table cellpadding=5>"
+
+    def  toc_section_enter( self, section ):
+        print "<tr valign=top><td>"
+        print '<a href="' + self.make_section_url( section ) + '">' + \
+               section.title + '</a></td><td>'
+        
+        print self.make_html_para( section.abstract )
+
+    def  toc_section_exit( self, section ):
+        print "</td></tr>"
+
+    def  toc_chapter_exit( self, chapter ):
+        print "</table>"
+        print  chapter_footer
+
+    def  toc_index( self, index_filename ):
+        print chapter_header + '<a href="' + index_filename + '">Global Index</a>' + chapter_inter + chapter_footer
+
+    def  toc_exit( self ):
+        print "</table></center>"
+        print self.html_footer
+
+    def  toc_dump( self, toc_filename = None, index_filename = None ):
+        if toc_filename == None:
+            toc_filename = self.file_prefix + "toc.html"
+        
+        if index_filename == None:
+            index_filename = self.file_prefix + "index.html"
+
+        Formatter.toc_dump( self, toc_filename, index_filename )
+
+    #
+    #  Formatting sections
+    #
+    def  section_enter( self, section ):
+        print self.html_header
+
+        print section_title_header
+        print section.title
+        print section_title_footer
+
+        # print section synopsys
+        print section_synopsis_header
+        print "<center><table cellspacing=5 cellpadding=0 border=0>"
+        
+        maxwidth = 0
+        for b in section.blocks.values():
+            if len(b.name) > maxwidth:
+                maxwidth = len(b.name)
+
+        width  = 130  # XXX magic number
+        columns = width / maxwidth
+        if columns < 1:
+            columns = 1
+
+        count   = len(section.block_names)
+        rows    = (count + columns-1)/columns
+        for r in range(rows):
+            line = "<tr>"
+            for c in range(columns):
+                i = r + c*rows
+                line = line + '<td></td><td>'
+                if i < count:
+                    name = section.block_names[i]
+                    line = line + '<a href="#' + name + '">' + name + '</a>'
+
+                line = line + '</td>'
+            line = line + "</tr>"
+            print line
+            
+        print "</table></center><br><br>"
+        print section_synopsis_footer
+
+        print description_header
+        print self.make_html_items( section.description )
+        print description_footer
+
+    def  block_enter( self, block ):
+        print block_header
+
+        # place html anchor if needed
+        if block.name:
+            print '<a name="' + block.name + '">'
+            print "<h4>" + block.name + "</h4>"
+            print "</a>"
+        
+        # dump the block C source lines now
+        if block.code:
+            print source_header
+            for l in block.code:
+                print self.html_source_quote( l, block.name )
+            print source_footer
+
+
+    def  markup_enter( self, markup, block ):
+        if markup.tag == "description":
+            print description_header
+        else:
+            print marker_header + markup.tag + marker_inter
+        
+        self.print_html_markup( markup )
+    
+    def  markup_exit( self, markup, block ):
+        if markup.tag == "description":
+            print description_footer
+        else:
+            print marker_footer
+
+    def  block_exit( self, block ):
+        print block_footer
+
+        
+    def  section_exit( self, section ):
+        print html_footer
+
+
+    def section_dump_all( self ):
+        for section in self.sections:
+            self.section_dump( section, self.file_prefix + section.name + '.html' )
+        
\ No newline at end of file
diff --git a/src/tools/docmaker/utils.py b/src/tools/docmaker/utils.py
new file mode 100644
index 0000000..f27353e
--- /dev/null
+++ b/src/tools/docmaker/utils.py
@@ -0,0 +1,86 @@
+import string, sys
+
+# This function is used to sort the index.  It is a simple lexicographical
+# sort, except that it places capital letters before lowercase ones.
+#
+def index_sort( s1, s2 ):
+    if not s1:
+        return -1
+
+    if not s2:
+        return 1
+
+    l1 = len( s1 )
+    l2 = len( s2 )
+    m1 = string.lower( s1 )
+    m2 = string.lower( s2 )
+
+    for i in range( l1 ):
+        if i >= l2 or m1[i] > m2[i]:
+            return 1
+
+        if m1[i] < m2[i]:
+            return -1
+
+        if s1[i] < s2[i]:
+            return -1
+
+        if s1[i] > s2[i]:
+            return 1
+
+    if l2 > l1:
+        return -1
+
+    return 0
+
+# 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:
+            new_list.append( id )
+    return new_list
+
+
+# current output directory
+#
+output_dir = None
+
+
+# Open the standard output to a given project documentation file.  Use
+# "output_dir" to determine the filename location if necessary and save the
+# old stdout in a tuple that is returned by this function.
+#
+def open_output( filename ):
+    global output_dir
+
+    if output_dir and output_dir != "":
+        filename = output_dir + os.sep + filename
+
+    old_stdout = sys.stdout
+    new_file   = open( filename, "w" )
+    sys.stdout = new_file
+
+    return ( new_file, old_stdout )
+
+
+# Close the output that was returned by "close_output".
+#
+def close_output( output ):
+    output[0].close()
+    sys.stdout = output[1]
+
+
+# Check output directory.
+#
+def check_output( ):
+    global output_dir
+    if output_dir:
+        if output_dir != "":
+            if not os.path.isdir( output_dir ):
+                sys.stderr.write( "argument" + " '" + output_dir + "' " +
+                                  "is not a valid directory" )
+                sys.exit( 2 )
+        else:
+            output_dir = None