Add commented out TESTS. Check for location of gtkdoc-check.
[gtk-doc.git] / gtkdoc-mkdb.in
blob3bba6884d8fea564bec604372316b2c3eb73ed64
1 #!@PERL@ -w
2 # -*- cperl -*-
4 # gtk-doc - GTK DocBook documentation generator.
5 # Copyright (C) 1998  Damon Chaplin
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #############################################################################
23 # Script      : gtkdoc-mkdb
24 # Description : This creates the DocBook files from the edited templates.
26 #               NOTE: When creating SGML IDS, we append ":CAPS" to all
27 #               all-caps identifiers to prevent name clashes. (It basically
28 #               never is the case that mixed-case identifiers would collide.)
29 #               See the CreateValidSGMLID function.
30 #############################################################################
32 use strict;
33 use Getopt::Long;
35 unshift @INC, '@PACKAGE_DATA_DIR@';
36 require "gtkdoc-common.pl";
38 # Options
40 # name of documentation module
41 my $MODULE;
42 my $TMPL_DIR;
43 my $SGML_OUTPUT_DIR;
44 my @SOURCE_DIRS;
45 my $SOURCE_SUFFIXES = "";
46 my $IGNORE_FILES = "";
47 my $PRINT_VERSION;
48 my $PRINT_HELP;
49 my $OUTPUT_ALL_SYMBOLS;
50 my $MAIN_SGML_FILE;
51 my $EXPAND_CONTENT_FILES = "";
52 my $SGML_MODE;
53 my $DEFAULT_STABILITY;
54 my $DEFAULT_INCLUDES;
55 my $OUTPUT_FORMAT;
57 my %optctl = (module => \$MODULE,
58               'source-dir' => \@SOURCE_DIRS,
59               'source-suffixes' => \$SOURCE_SUFFIXES,
60               'ignore-files' => \$IGNORE_FILES,
61               'output-dir' => \$SGML_OUTPUT_DIR,
62               'tmpl-dir' => \$TMPL_DIR,
63               'version' => \$PRINT_VERSION,
64               'help' => \$PRINT_HELP,
65               'main-sgml-file' => \$MAIN_SGML_FILE,
66               'expand-content-files' => \$EXPAND_CONTENT_FILES,
67               'outputallsymbols' => \$OUTPUT_ALL_SYMBOLS,
68               'sgml-mode' => \$SGML_MODE,
69               'default-stability' => \$DEFAULT_STABILITY,
70               'default-includes' => \$DEFAULT_INCLUDES,
71               'output-format' => \$OUTPUT_FORMAT);
72 GetOptions(\%optctl, "module=s", "source-dir:s", "source-suffixes:s", "ignore-files:s", "output-dir:s", "tmpl-dir:s", "version", "outputallsymbols", "expand-content-files:s", "main-sgml-file:s", "extra-db-files:s", "help", "sgml-mode", "default-stability:s", "default-includes:s", "output-format:s");
74 if ($PRINT_VERSION) {
75     print "@VERSION@\n";
76     exit 0;
79 if (!$MODULE) {
80     $PRINT_HELP = 1;
83 if ($DEFAULT_STABILITY && $DEFAULT_STABILITY ne "Stable"
84     && $DEFAULT_STABILITY ne "Private" && $DEFAULT_STABILITY ne "Unstable") {
85     $PRINT_HELP = 1;
88 if ($PRINT_HELP) {
89     print "gtkdoc-mkdb version @VERSION@\n";
90     print "\n--module=MODULE_NAME   Name of the doc module being parsed";
91     print "\n--source-dir=DIRNAME   Directories which contain inline reference material";
92     print "\n--source-suffixes=SUFFIXES Suffixes of source files to scan, comma-separated";
93     print "\n--ignore-files=FILES   Files or directories which should not be scanned";
94     print "\n                       May be used more than once for multiple directories";
95     print "\n--output-dir=DIRNAME   Directory to put the generated DocBook files in";
96     print "\n--tmpl-dir=DIRNAME     Directory in which template files may be found";
97     print "\n--main-sgml-file=FILE  File containing the toplevel DocBook file.";
98     print "\n--expand-content-files=FILES Extra DocBook files to expand abbreviations in.";
99     print "\n--output-format=FORMAT The format to use for the generated docbook, XML or SGML.";
100     print "\n--sgml-mode            Allow DocBook markup in inline documentation.";
101     print "\n--default-stability=LEVEL Specify default stability Level. Valid values are";
102     print "\n                       Stable, Unstable, or Private.";
103     print "\n--default-includes=FILENAMES Specify default includes for section Synopsis";
104     print "\n--version              Print the version of this program";
105     print "\n--help                 Print this help\n";
106     exit 0;
109 if (!$MAIN_SGML_FILE) {
110     $MAIN_SGML_FILE="${MODULE}-docs.sgml";
113 my ($empty_element_end, $doctype_header);
115 if (lc($OUTPUT_FORMAT) eq "xml") {
116     $OUTPUT_FORMAT = "xml";
117     $empty_element_end = "/>";
119     if ($MAIN_SGML_FILE && -e $MAIN_SGML_FILE) {
120         open(INPUT, "<$MAIN_SGML_FILE") || die "Can't open $MAIN_SGML_FILE";
121         $doctype_header = "";
122         while (<INPUT>) {
123             if (/^\s*<(book|chapter|article)/) {
124                 if ($_ !~ m/http:\/\/www.w3.org\/200[13]\/XInclude/) {
125                     $doctype_header = "";
126                 }
127                 last;
128             }
129             $doctype_header .= $_;
130         }
131         close(INPUT);
132     } else {
133         $doctype_header =
134 "<?xml version=\"1.0\"?>\n" .
135 "<!DOCTYPE book PUBLIC \"-//OASIS//DTD DocBook XML V4.1.2//EN\"\n" .
136 "               \"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd\">\n";
137     }
138     $doctype_header =~ s/<!DOCTYPE \w+/<!DOCTYPE refentry/;
139   } else {
140     $OUTPUT_FORMAT = "sgml";
141     $doctype_header = "";
142     $empty_element_end = ">";
145 my $ROOT_DIR = ".";
147 # All the files are written in subdirectories beneath here.
148 $TMPL_DIR = $TMPL_DIR ? $TMPL_DIR : "$ROOT_DIR/tmpl";
150 # This is where we put all the DocBook output.
151 $SGML_OUTPUT_DIR = $SGML_OUTPUT_DIR ? $SGML_OUTPUT_DIR : "$ROOT_DIR/$OUTPUT_FORMAT";
153 # This file contains the object hierarchy.
154 my $OBJECT_TREE_FILE = "$ROOT_DIR/$MODULE.hierarchy";
156 # This file contains the interfaces.
157 my $INTERFACES_FILE = "$ROOT_DIR/$MODULE.interfaces";
159 # This file contains the prerequisites.
160 my $PREREQUISITES_FILE = "$ROOT_DIR/$MODULE.prerequisites";
162 # This file contains signal arguments and names.
163 my $SIGNALS_FILE = "$ROOT_DIR/$MODULE.signals";
165 # The file containing Arg information.
166 my $ARGS_FILE = "$ROOT_DIR/$MODULE.args";
168 # These global arrays store information on signals. Each signal has an entry
169 # in each of these arrays at the same index, like a multi-dimensional array.
170 my @SignalObjects;      # The GtkObject which emits the signal.
171 my @SignalNames;        # The signal name.
172 my @SignalReturns;      # The return type.
173 my @SignalFlags;        # Flags for the signal
174 my @SignalPrototypes;   # The rest of the prototype of the signal handler.
176 # These global arrays store information on Args. Each Arg has an entry
177 # in each of these arrays at the same index, like a multi-dimensional array.
178 my @ArgObjects;         # The GtkObject which has the Arg.
179 my @ArgNames;           # The Arg name.
180 my @ArgTypes;           # The Arg type - gint, GtkArrowType etc.
181 my @ArgFlags;           # How the Arg can be used - readable/writable etc.
182 my @ArgNicks;           # The nickname of the Arg.
183 my @ArgBlurbs;          # Docstring of the Arg.
184 my @ArgDefaults;        # Default value of the Arg.
185 my @ArgRanges;          # The range of the Arg type
186 # These global hashes store declaration info keyed on a symbol name.
187 my %Declarations;
188 my %DeclarationTypes;
189 my %DeclarationConditional;
190 my %DeclarationOutput;
191 my %Deprecated;
192 my %Since;
193 my %StabilityLevel;
194 my %StructHasTypedef;
196 # These global hashes store the existing documentation.
197 my %SymbolDocs;
198 my %SymbolTypes;
199 my %SymbolParams;
201 # These global hashes store documentation scanned from the source files.
202 my %SourceSymbolDocs;
203 my %SourceSymbolParams;
205 # all documentation goes in here, so we can do coverage analysis
206 my %AllSymbols;
207 my %AllIncompleteSymbols;
208 my %AllDocumentedSymbols;
210 # Undeclared yet documented symbols
211 my %UndeclaredSymbols;
213 # These global arrays store GtkObject and subclasses and the hierarchy.
214 my @Objects;
215 my @ObjectLevels;
217 my %Interfaces;
218 my %Prerequisites;
220 # holds the symbols which are mentioned in $MODULE-sections.txt
221 my %KnownSymbols;
223 # Standard C preprocessor directives, which we ignore for '#' abbreviations.
224 my %PreProcessorDirectives;
225 $PreProcessorDirectives{"assert"} = 1;
226 $PreProcessorDirectives{"define"} = 1;
227 $PreProcessorDirectives{"elif"} = 1;
228 $PreProcessorDirectives{"else"} = 1;
229 $PreProcessorDirectives{"endif"} = 1;
230 $PreProcessorDirectives{"error"} = 1;
231 $PreProcessorDirectives{"if"} = 1;
232 $PreProcessorDirectives{"ifdef"} = 1;
233 $PreProcessorDirectives{"ifndef"} = 1;
234 $PreProcessorDirectives{"include"} = 1;
235 $PreProcessorDirectives{"line"} = 1;
236 $PreProcessorDirectives{"pragma"} = 1;
237 $PreProcessorDirectives{"unassert"} = 1;
238 $PreProcessorDirectives{"undef"} = 1;
239 $PreProcessorDirectives{"warning"} = 1;
241 # Create the root DocBook output directory if it doens't exist.
242 if (! -e $SGML_OUTPUT_DIR) {
243     mkdir ("$SGML_OUTPUT_DIR", 0777)
244         || die "Can't create directory: $SGML_OUTPUT_DIR";
247 # Function and other declaration output settings.
248 my $RETURN_TYPE_FIELD_WIDTH = 20;
249 my $SYMBOL_FIELD_WIDTH = 36;
250 my $SIGNAL_FIELD_WIDTH = 16;
252 &ReadKnownSymbols ("$ROOT_DIR/$MODULE-sections.txt");
253 &ReadSignalsFile ($SIGNALS_FILE);
254 &ReadArgsFile ($ARGS_FILE);
255 &ReadObjectHierarchy;
256 &ReadInterfaces;
257 &ReadPrerequisites;
259 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-decl.txt", 0);
260 if (-f "$ROOT_DIR/$MODULE-overrides.txt") {
261     &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-overrides.txt", 1);
264 for my $dir (@SOURCE_DIRS) {
265     &ReadSourceDocumentation ($dir);
268 my $changed = &OutputSGML ("$ROOT_DIR/$MODULE-sections.txt");
270 # If any of the DocBook SGML files have changed, update the timestamp file (so
271 # it can be used for Makefile dependencies).
272 if ($changed || ! -e "$ROOT_DIR/sgml.stamp") {
273     open (TIMESTAMP, ">$ROOT_DIR/sgml.stamp")
274         || die "Can't create $ROOT_DIR/sgml.stamp";
275     print (TIMESTAMP "timestamp");
276     close (TIMESTAMP);
279 #############################################################################
280 # Function    : OutputObjectList
281 # Description : This outputs the alphabetical list of objects, in a columned
282 #               table. FIXME: Currently this also outputs ancestor objects
283 #               which may not actually be in this module.
284 # Arguments   : none
285 #############################################################################
287 sub OutputObjectList {
288     my $cols = 3;
289     my $old_object_index = "$SGML_OUTPUT_DIR/object_index.sgml";
290     my $new_object_index = "$SGML_OUTPUT_DIR/object_index.new";
292     open (OUTPUT, ">$new_object_index")
293         || die "Can't create $new_object_index";
294     print (OUTPUT <<EOF);
295 <informaltable pgwide="1" frame="none">
296 <tgroup cols="$cols">
297 <colspec colwidth="1*"${empty_element_end}
298 <colspec colwidth="1*"${empty_element_end}
299 <colspec colwidth="1*"${empty_element_end}
300 <tbody>
303     my $count = 0;
304     my $object;
305     foreach $object (sort(@Objects)) {
306         my $xref = &MakeXRef ($object);
307         if ($count % $cols == 0) { print (OUTPUT "<row>\n"); }
308         print (OUTPUT "<entry>$xref</entry>\n");
309         if ($count % $cols == ($cols - 1)) { print (OUTPUT "</row>\n"); }
310         $count++;
311     }
312     if ($count == 0) {
313         # emit an empty row, since empty tables are invalid
314         print (OUTPUT "<row><entry> </entry></row>\n");
315     }
317     print (OUTPUT <<EOF);
318 </tbody></tgroup></informaltable>
320     close (OUTPUT);
322     &UpdateFileIfChanged ($old_object_index, $new_object_index, 0);
326 #############################################################################
327 # Function    : OutputSGML
328 # Description : This collects the output for each section of the docs, and
329 #               outputs each file when the end of the section is found.
330 # Arguments   : $file - the $MODULE-sections.txt file which contains all of
331 #               the functions/macros/structs etc. being documented, organised
332 #               into sections and subsections.
333 #############################################################################
335 sub OutputSGML {
336     my ($file) = @_;
338 #    print "Reading: $file\n";
339     open (INPUT, $file)
340         || die "Can't open $file";
341     my $book_top = "";
342     my $book_bottom = "";
343     my $includes = (defined $DEFAULT_INCLUDES) ? $DEFAULT_INCLUDES : "";
344     my $section_includes = "";
345     my $in_section = 0;
346     my $title = "";
347     my $subsection = "";
348     my $synopsis;
349     my $details;
350     my $num_symbols;
351     my $changed = 0;
352     my $signals_synop = "";
353     my $signals_desc = "";
354     my $args_synop = "";
355     my $child_args_synop = "";
356     my $style_args_synop = "";
357     my $args_desc = "";
358     my $child_args_desc = "";
359     my $style_args_desc = "";
360     my $hierarchy = "";
361     my $interfaces = "";
362     my $implementations = "";
363     my $prerequisites = "";
364     my $derived = "";
365     my @file_objects = ();
367     while (<INPUT>) {
368         if (m/^#/) {
369             next;
371         } elsif (m/^<SECTION>/) {
372             $synopsis = "";
373             $details = "";
374             $num_symbols = 0;
375             $in_section = 1;
376             @file_objects = ();
378         } elsif (m/^<SUBSECTION\s*(.*)>/i) {
379             $synopsis .= "\n";
380             $subsection = $1;
382         } elsif (m/^<SUBSECTION>/) {
384         } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
385             $title = $1;
386 #           print "Section: $title\n";
388             # We don't want warnings if object & class structs aren't used.
389             $DeclarationOutput{$title} = 1;
390             $DeclarationOutput{"${title}Class"} = 1;
392         } elsif (m/^<FILE>(.*)<\/FILE>/) {
393             my $sym;
395             $file = $1;
396             %SymbolDocs = ();
397             %SymbolTypes = ();
398             %SymbolParams = ();
399             &ReadTemplateFile ("$TMPL_DIR/$file", 1);
400             &MergeSourceDocumentation;
402         } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
403             if ($in_section) {
404                 $section_includes = $1;
405             } else {
406                 if (defined $DEFAULT_INCLUDES) {
407                     print <<EOF;
408 WARNING: Default <INCLUDE> being overridden by command line option
410                 }
411                 else {
412                     $includes = $1;
413                 }
414             }
416         } elsif (m/^<\/SECTION>/) {
417             if ($title eq "") {
418                 $title = $file;
419             }
420 #           print "End of section: $title\n";
422             $file =~ s/\s/_/g;
424             my $section_id = $SourceSymbolDocs{"$TMPL_DIR/$file:Section_Id"};
425             if (defined ($section_id) && $section_id !~ m/^\s*$/) {
426                 # Do nothing. Use section_id as it is.
427             } elsif (&CheckIsObject ($title)) {
428                 # GtkObjects use their class name as the ID.
429                 $section_id = &CreateValidSGMLID ($title);
430             } else {
431                 $section_id = &CreateValidSGMLID ("$MODULE-$title");
432             }
434             if ($num_symbols > 0) {
435                 if (lc($OUTPUT_FORMAT) eq "xml") {
436                     $book_bottom .= "    <xi:include href=\"xml/$file.xml\"/>\n";
437                 } else {
438                     $book_top.="<!ENTITY $section_id SYSTEM \"sgml/$file.sgml\">\n";
439                     $book_bottom .= "    &$section_id;\n";
440                 }
442                 if (defined ($SourceSymbolDocs{"$TMPL_DIR/$file:Include"})) {
443                     if ($section_includes) {
444                         print <<EOF;
445 WARNING: Section <INCLUDE> for file $file being overridden by inline comments
447                     }
448                     $section_includes = $SourceSymbolDocs{"$TMPL_DIR/$file:Include"};
449                 }
450                 if ($section_includes eq "") {
451                     $section_includes = $includes;
452                 }
454                 if ($signals_synop ne '') {
455                     $signals_synop = <<EOF;
456 <refsect1 role="signal_proto">
457 <title role="signal_proto.title">Signals</title>
458 <synopsis>
460 ${signals_synop}</synopsis>
461 </refsect1>
463                     $signals_desc  = <<EOF;
464 <refsect1 role="signals">
465 <title role="signals.title">Signal Details</title>
466 $signals_desc
467 </refsect1>
469                 }
471                 if ($args_synop ne '') {
472                     $args_synop = <<EOF;
473 <refsect1 role="properties">
474 <title role="properties.title">Properties</title>
475 <synopsis>
477 ${args_synop}</synopsis>
478 </refsect1>
480                     $args_desc  = <<EOF;
481 <refsect1 role="property_details">
482 <title role="property_details.title">Property Details</title>
483 $args_desc
484 </refsect1>
486                 }
488                 if ($child_args_synop ne '') {
489                     $args_synop .= <<EOF;
490 <refsect1 role="child_properties">
491 <title role="child_properties.title">Child Properties</title>
492 <synopsis>
494 ${child_args_synop}</synopsis>
495 </refsect1>
497                     $args_desc .= <<EOF;
498 <refsect1 role="child_property_details">
499 <title role="child_property_details.title">Child Property Details</title>
500 $child_args_desc
501 </refsect1>
503                 }
505                 if ($style_args_synop ne '') {
506                     $args_synop .= <<EOF;
507 <refsect1 role="style_properties">
508 <title role="style_properties.title">Style Properties</title>
509 <synopsis>
511 ${style_args_synop}</synopsis>
512 </refsect1>
514                     $args_desc .= <<EOF;
515 <refsect1 role="style_properties_details">
516 <title role="style_properties_details.title">Style Property Details</title>
517 $style_args_desc
518 </refsect1>
520                 }
522                 if ($hierarchy ne "") {
523                     $hierarchy = <<EOF;
524 <refsect1 role="object_hierarchy">
525 <title role="object_hierarchy.title">Object Hierarchy</title>
526 $hierarchy
527 </refsect1>
529                 }
531                 if ($interfaces ne "") {
532                     $interfaces = <<EOF;
533 <refsect1 role="impl_interfaces">
534 <title role="impl_interfaces.title">Implemented Interfaces</title>
535 $interfaces
536 </refsect1>
538                 }
540                 if ($implementations ne "") {
541                     $implementations = <<EOF;
542 <refsect1 role="implementations">
543 <title role="implementations.title">Known Implementations</title>
544 $implementations
545 </refsect1>
547                 }
549                 if ($prerequisites ne "") {
550                     $prerequisites = <<EOF;
551 <refsect1 role="prerequisites">
552 <title role="prerequisites.title">Prerequisites</title>
553 $prerequisites
554 </refsect1>
556                 }
558                 if ($derived ne "") {
559                     $derived = <<EOF;
560 <refsect1 role="derived_interfaces">
561 <title role="derived_interfaces.title">Known Derived Interfaces</title>
562 $derived
563 </refsect1>
565                 }
567                 my $file_changed = &OutputSGMLFile ($file, $title, $section_id,
568                                                     $section_includes,
569                                                     \$synopsis, \$details,
570                                                     \$signals_synop, \$signals_desc,
571                                                     \$args_synop, \$args_desc,
572                                                     \$hierarchy, \$interfaces,
573                                                     \$implementations,
574                                                     \$prerequisites, \$derived,
575                                                     \@file_objects);
576                 if ($file_changed) {
577                     $changed = 1;
578                 }
579             }
580             $title = "";
581             $subsection = "";
582             $in_section = 0;
583             $section_includes = "";
584             $signals_synop = "";
585             $signals_desc = "";
586             $args_synop = "";
587             $child_args_synop = "";
588             $style_args_synop = "";
589             $args_desc = "";
590             $child_args_desc = "";
591             $style_args_desc = "";
592             $hierarchy = "";
593             $interfaces = "";
594             $implementations = "";
595             $prerequisites = "";
596             $derived = "";
598         } elsif (m/^(\S+)/) {
599             my $symbol = $1;
600 #           print "  Symbol: $symbol\n";
602             my $declaration = $Declarations{$symbol};
603             if (defined ($declaration)) {
604                 # We don't want standard macros/functions of GtkObjects,
605                 # or private declarations.
606                 if ($subsection ne "Standard" && $subsection ne "Private") {
607                     if (&CheckIsObject ($symbol)) {
608                         push @file_objects, $symbol;
609                     }
610                     my ($synop, $desc) = &OutputDeclaration ($symbol,
611                                                              $declaration);
612                     my ($sig_synop, $sig_desc) = &GetSignals ($symbol);
613                     my ($arg_synop, $child_arg_synop, $style_arg_synop,
614                         $arg_desc, $child_arg_desc, $style_arg_desc) = &GetArgs ($symbol);
615                     my $hier = &GetHierarchy ($symbol);
616                     my $ifaces = &GetInterfaces ($symbol);
617                     my $impls = &GetImplementations ($symbol);
618                     my $prereqs = &GetPrerequisites ($symbol);
619                     my $der = &GetDerived ($symbol);
620                     $synopsis .= $synop;
621                     $details .= $desc;
622                     $signals_synop .= $sig_synop;
623                     $signals_desc .= $sig_desc;
624                     $args_synop .= $arg_synop;
625                     $child_args_synop .= $child_arg_synop;
626                     $style_args_synop .= $style_arg_synop;
627                     $args_desc .= $arg_desc;
628                     $child_args_desc .= $child_arg_desc;
629                     $style_args_desc .= $style_arg_desc;
630                     $hierarchy .= $hier;
631                     $interfaces .= $ifaces;
632                     $implementations .= $impls;
633                     $prerequisites .= $prereqs;
634                     $derived .= $der;
635                 }
637                 # Note that the declaration has been output.
638                 $DeclarationOutput{$symbol} = 1;
639             } elsif ($subsection ne "Standard" && $subsection ne "Private") {
640                 $UndeclaredSymbols{$1} = 1;
641                 print "WARNING: No declaration found for: $1\n";
642             }
643             $num_symbols++;
644         }
645     }
646     close (INPUT);
648     &OutputMissingDocumentation;
649     &OutputUndeclaredSymbols;
651     if ($OUTPUT_ALL_SYMBOLS) {
652         &OutputAllSymbols;
653     }
655     for $file (split (' ', $EXPAND_CONTENT_FILES)) {
656         my $file_changed = &OutputExtraFile ($file);
657         if ($file_changed) {
658             $changed = 1;
659         }
660     }
662     &OutputBook ($book_top, $book_bottom);
664     return $changed;
668 #############################################################################
669 # Function    : ReadKnownSymbols
670 # Description : This collects the names of non-private symbols from the
671 #               $MODULE-sections.txt file.
672 # Arguments   : $file - the $MODULE-sections.txt file which contains all of
673 #               the functions/macros/structs etc. being documented, organised
674 #               into sections and subsections.
675 #############################################################################
677 sub ReadKnownSymbols {
678     my ($file) = @_;
680     my $subsection = "";
682 #    print "Reading: $file\n";
683     open (INPUT, $file)
684         || die "Can't open $file";
686     while (<INPUT>) {
687         if (m/^#/) {
688             next;
690         } elsif (m/^<SECTION>/) {
691             $subsection = "";
693         } elsif (m/^<SUBSECTION\s*(.*)>/i) {
694             $subsection = $1;
696         } elsif (m/^<SUBSECTION>/) {
697             next;
699         } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
700             next;
702         } elsif (m/^<FILE>(.*)<\/FILE>/) {
703             next;
705         } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
706             next;
708         } elsif (m/^<\/SECTION>/) {
709             next;
711         } elsif (m/^(\S+)/) {
712             my $symbol = $1;
714             if ($subsection ne "Standard" && $subsection ne "Private") {
715                 $KnownSymbols{$symbol} = 1;
716             }
717             else {
718                 $KnownSymbols{$symbol} = 0;
719             }
720         }
721     }
722     close (INPUT);
726 #############################################################################
727 # Function    : OutputDeclaration
728 # Description : Returns the synopsis and detailed description DocBook
729 #               describing one function/macro etc.
730 # Arguments   : $symbol - the name of the function/macro begin described.
731 #               $declaration - the declaration of the function/macro.
732 #############################################################################
734 sub OutputDeclaration {
735     my ($symbol, $declaration) = @_;
737     my $type = $DeclarationTypes {$symbol};
738     if ($type eq 'MACRO') {
739         return &OutputMacro ($symbol, $declaration);
740     } elsif ($type eq 'TYPEDEF') {
741         return &OutputTypedef ($symbol, $declaration);
742     } elsif ($type eq 'STRUCT') {
743         return &OutputStruct ($symbol, $declaration);
744     } elsif ($type eq 'ENUM') {
745         return &OutputEnum ($symbol, $declaration);
746     } elsif ($type eq 'UNION') {
747         return &OutputUnion ($symbol, $declaration);
748     } elsif ($type eq 'VARIABLE') {
749         return &OutputVariable ($symbol, $declaration);
751     } elsif ($type eq 'FUNCTION') {
752         return &OutputFunction ($symbol, $declaration, $type);
753     } elsif ($type eq 'USER_FUNCTION') {
754         return &OutputFunction ($symbol, $declaration, $type);
755     } else {
756         die "Unknown symbol type";
757     }
761 #############################################################################
762 # Function    : OutputSymbolTraits
763 # Description : Returns the Since and StabilityLevel paragraphs for a symbol.
764 # Arguments   : $symbol - the name of the function/macro begin described.
765 #############################################################################
767 sub OutputSymbolTraits {
768     my ($symbol) = @_;
769     my $desc = "";
771     if (exists $Since{$symbol}) {
772         $desc .= "<para role=\"since\">Since $Since{$symbol}</para>";
773     }
774     if (exists $StabilityLevel{$symbol}) {
775         $desc .= "<para role=\"stability\">Stability Level: $StabilityLevel{$symbol}</para>";
776     }
777     return $desc;
781 #############################################################################
782 # Function    : OutputMacro
783 # Description : Returns the synopsis and detailed description of a macro.
784 # Arguments   : $symbol - the macro.
785 #               $declaration - the declaration of the macro.
786 #############################################################################
788 sub OutputMacro {
789     my ($symbol, $declaration) = @_;
790     my $id = &CreateValidSGMLID ($symbol);
791     my $condition = &MakeConditionDescription ($symbol);
792     my $synop = &MakeReturnField("#define") . "<link linkend=\"$id\">$symbol</link>";
793     my $desc;
794     my $padding = "";
795     my $args = "";
796     my $pad;
798     if ($declaration =~ m/^\s*#\s*define(\s+)\w+(\([^\)]*\))/) {
799         $padding = $1;
800         $args = $2;
802         if (length ($symbol) < $SYMBOL_FIELD_WIDTH) {
803             $synop .= (' ' x ($SYMBOL_FIELD_WIDTH - length ($symbol)));
804         }
806         # Try to align all the lines of args correctly.
807         $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH + $SYMBOL_FIELD_WIDTH + 1);
808         my $args_padded = $args;
809         $args_padded =~ s/ *\\\n */\n$pad/gm;
810         $synop .= &CreateValidSGML ($args_padded);
811     }
812     $synop .= "\n";
814     if ($args ne "") {
815         $desc = "<refsect2>\n<title><anchor id=\"$id\" role=\"macro\"${condition}${empty_element_end}${symbol}()</title>\n";
816     } else {
817         $desc = "<refsect2>\n<title><anchor id=\"$id\" role=\"macro\"${condition}${empty_element_end}$symbol</title>\n";
818     }
819     $desc .= MakeIndexterms($symbol);
821     # Don't output the macro definition if is is a conditional macro or it
822     # looks like a function, i.e. starts with "g_" or "_?gnome_", or it is
823     # longer than 2 lines, otherwise we get lots of complicated macros like
824     # g_assert.
825     if (!defined ($DeclarationConditional{$symbol}) && ($symbol !~ m/^g_/)
826         && ($symbol !~ m/^_?gnome_/) && (($declaration =~ tr/\n//) < 2)) {
827         $declaration = &CreateValidSGML ($declaration);
828         $desc .= "<programlisting>$declaration</programlisting>\n";
829     } else {
830         $desc .= "<programlisting>" . &MakeReturnField("#define") . "$symbol";
831         # Align each line so that if should all line up OK.
832         $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH - length ("#define "));
833         $args =~ s/\n/\n$pad/gm;
834         $desc .= &CreateValidSGML ($args);
835         $desc .= "</programlisting>\n";
836     }
838     $desc .= &MakeDeprecationNote($symbol);
840     my $parameters = &OutputParamDescriptions ("MACRO", $symbol);
841     my $parameters_output = 0;
843     if (defined ($SymbolDocs{$symbol})) {
844         my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
846         # Try to insert the parameter table at the author's desired position.
847         # Otherwise we need to tag it onto the end.
848         if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
849           $parameters_output = 1;
850         }
851         $desc .= $symbol_docs;
852     }
854     if ($parameters_output == 0) {
855         $desc .= $parameters;
856     }
858     $desc .= OutputSymbolTraits ($symbol);
859     $desc .= "</refsect2>\n";
860     return ($synop, $desc);
864 #############################################################################
865 # Function    : OutputTypedef
866 # Description : Returns the synopsis and detailed description of a typedef.
867 # Arguments   : $symbol - the typedef.
868 #               $declaration - the declaration of the typedef,
869 #                 e.g. 'typedef unsigned int guint;'
870 #############################################################################
872 sub OutputTypedef {
873     my ($symbol, $declaration) = @_;
874     my $id = &CreateValidSGMLID ($symbol);
875     my $condition = &MakeConditionDescription ($symbol);
876     my $synop = &MakeReturnField("typedef") . "<link linkend=\"$id\">$symbol</link>;\n";
877     my $desc = "<refsect2>\n<title><anchor id=\"$id\" role=\"typedef\"${condition}${empty_element_end}$symbol</title>\n";
879     $desc .= MakeIndexterms($symbol);
881     if (!defined ($DeclarationConditional{$symbol})) {
882         $declaration = &CreateValidSGML ($declaration);
883         $desc .= "<programlisting>$declaration</programlisting>\n";
884     }
886     $desc .= &MakeDeprecationNote($symbol);
888     if (defined ($SymbolDocs{$symbol})) {
889         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
890     }
891     $desc .= OutputSymbolTraits ($symbol);
892     $desc .= "</refsect2>\n";
893     return ($synop, $desc);
897 #############################################################################
898 # Function    : OutputStruct
899 # Description : Returns the synopsis and detailed description of a struct.
900 #               We check if it is a widget struct, and if so we only output
901 #               parts of it that are noted as public fields.
902 #               We also use a different SGML ID for widget structs, since the
903 #               original ID is used for the entire RefEntry.
904 # Arguments   : $symbol - the struct.
905 #               $declaration - the declaration of the struct.
906 #############################################################################
908 sub OutputStruct {
909     my ($symbol, $declaration) = @_;
911     my $is_widget_struct = 0;
912     my $default_to_public = 1;
913     if (&CheckIsObject ($symbol)) {
914 #       print "Found widget struct: $symbol\n";
915         $is_widget_struct = 1;
916         $default_to_public = 0;
917     }
919     my $id;
920     my $condition;
921     if ($is_widget_struct) {
922         $id = &CreateValidSGMLID ($symbol . "_struct");
923         $condition = &MakeConditionDescription ($symbol . "_struct");
924     } else {
925         $id = &CreateValidSGMLID ($symbol);
926         $condition = &MakeConditionDescription ($symbol);
927     }
929     # Determine if it is a simple struct or it also has a typedef.
930     my $has_typedef = 0;
931     if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
932       $has_typedef = 1;
933     }
935     my $synop;
936     my $desc;
937     if ($has_typedef) {
938         # For structs with typedefs we just output the struct name.
939         $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
940         $desc = "<refsect2>\n<title><anchor id=\"$id\" role=\"struct\"${condition}${empty_element_end}$symbol</title>\n";
941     } else {
942         $synop = &MakeReturnField("struct") . "<link linkend=\"$id\">$symbol</link>;\n";
943         $desc = "<refsect2>\n<title><anchor id=\"$id\" role=\"struct\"${condition}${empty_element_end}struct $symbol</title>\n";
944     }
946     $desc .= MakeIndexterms($symbol);
948     # Form a pretty-printed, private-data-removed form of the declaration
950     my $decl_out = "";
951     if ($declaration =~ m/^\s*$/) {
952 #       print "Found opaque struct: $symbol\n";
953         $decl_out = "typedef struct _$symbol $symbol;";
954     } elsif ($declaration =~ m/^\s*struct\s+\w+\s*;\s*$/) {
955 #       print "Found opaque struct: $symbol\n";
956         $decl_out = "struct $symbol;";
957     } else {
958         my $public = $default_to_public;
959         my $new_declaration = "";
960         my $decl_line;
961         my $decl = $declaration;
963         if ($decl =~ m/^\s*(typedef\s+)?struct\s*\w*\s*(?:\/\*.*\*\/)?\s*{(.*)}\s*\w*\s*;\s*$/s) {
964             my $struct_contents = $2;
966             foreach $decl_line (split (/\n/, $struct_contents)) {
967 #               print "Struct line: $decl_line\n";
968                 if ($decl_line =~ m%/\*\s*<\s*public\s*>\s*\*/%) {
969                     $public = 1;
970                 } elsif ($decl_line =~ m%/\*\s*<\s*(private|protected)\s*>\s*\*/%) {
971                     $public = 0;
972                 } elsif ($public) {
973                     $new_declaration .= $decl_line . "\n";
974                 }
975             }
977             if ($new_declaration) {
978                 # Strip any blank lines off the ends.
979                 $new_declaration =~ s/^\s*\n//;
980                 $new_declaration =~ s/\n\s*$/\n/;
982                 if ($has_typedef) {
983                     $decl_out = "typedef struct {\n" . $new_declaration
984                       . "} $symbol;\n";
985                 } else {
986                     $decl_out = "struct $symbol {\n" . $new_declaration
987                       . "};\n";
988                 }
989             }
990         } else {
991             print "WARNING: Couldn't parse struct:\n$declaration\n";
992         }
994         # If we couldn't parse the struct or it was all private, output an
995         # empty struct declaration.
996         if ($decl_out eq "") {
997             if ($has_typedef) {
998                 $decl_out = "typedef struct _$symbol $symbol;";
999             } else {
1000                 $decl_out = "struct $symbol;";
1001             }
1002         }
1003     }
1005     $decl_out = &CreateValidSGML ($decl_out);
1006     $desc .= "<programlisting>$decl_out</programlisting>\n";
1008     $desc .= &MakeDeprecationNote($symbol);
1010     if (defined ($SymbolDocs{$symbol})) {
1011         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1012     }
1014     # Create a table of fields and descriptions
1016     # FIXME: Inserting &nbsp's into the produced type declarations here would
1017     #        improve the output in most situations ... except for function
1018     #        members of structs!
1019     my @fields = ParseStructDeclaration($declaration, !$default_to_public,
1020                                         0, \&MakeXRef,
1021                                         sub {
1022                                             "<structfield>$_[0]</structfield>";
1023                                         });
1024     my $params = $SymbolParams{$symbol};
1026     # If no parameters are filled in, we don't generate the description
1027     # table, for backwards compatibility
1029     my $found = 0;
1030     if (defined $params) {
1031         for (my $i = 1; $i <= $#$params; $i += 2) {
1032             if ($params->[$i] =~ /\S/) {
1033                 $found = 1;
1034                 last;
1035             }
1036         }
1037     }
1039     if ($found) {
1040         my %field_descrs = @$params;
1042             $desc .= <<EOF;
1043 <variablelist role="struct">
1045         while (@fields) {
1046             my $field_name = shift @fields;
1047             my $text = shift @fields;
1048             my $field_descr = $field_descrs{$field_name};
1050             $desc .= "<varlistentry>\n<term>$text</term>\n";
1051             if (defined $field_descr) {
1052                 $desc .= "<listitem><simpara>".&ExpandAbbreviations($symbol, $field_descr)."</simpara></listitem>\n";
1053             } else {
1054                 $desc .= "<listitem></listitem>\n";
1055             }
1056             $desc .= "</varlistentry>\n";
1057         }
1059         $desc .= "</variablelist>";
1060     }
1061     $desc .= OutputSymbolTraits ($symbol);
1062     $desc .= "</refsect2>\n";
1063     return ($synop, $desc);
1067 #############################################################################
1068 # Function    : OutputEnum
1069 # Description : Returns the synopsis and detailed description of a enum.
1070 # Arguments   : $symbol - the enum.
1071 #               $declaration - the declaration of the enum.
1072 #############################################################################
1074 sub OutputEnum {
1075     my ($symbol, $declaration) = @_;
1076     my $id = &CreateValidSGMLID ($symbol);
1077     my $condition = &MakeConditionDescription ($symbol);
1078     my $synop = &MakeReturnField("enum") . "<link linkend=\"$id\">$symbol</link>;\n";
1079     my $desc = "<refsect2>\n<title><anchor id=\"$id\" role=\"enum\"${condition}${empty_element_end}enum $symbol</title>\n";
1081     $desc .= MakeIndexterms($symbol);
1083     $declaration = &CreateValidSGML ($declaration);
1084     $desc .= "<programlisting>$declaration</programlisting>\n";
1086     $desc .= &MakeDeprecationNote($symbol);
1088     if (defined ($SymbolDocs{$symbol})) {
1089         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1090     }
1092     # Create a table of fields and descriptions
1094     my @members = ParseEnumDeclaration($declaration);
1095     my $params = $SymbolParams{$symbol};
1097     # If no parameters are filled in, we don't generate the description
1098     # table, for backwards compatibility
1100     my $found = 0;
1101     if (defined $params) {
1102         for (my $i = 1; $i <= $#$params; $i += 2) {
1103             if ($params->[$i] =~ /\S/) {
1104                 $found = 1;
1105                 last;
1106             }
1107         }
1108     }
1110     if ($found) {
1111         my %member_descrs = @$params;
1113             $desc .= <<EOF;
1114 <variablelist role="enum">
1116         for my $member_name (@members) {
1117             my $member_descr = $member_descrs{$member_name};
1119             $id = &CreateValidSGMLID ($member_name);
1120             $condition = &MakeConditionDescription ($member_name);
1121             $desc .= "<varlistentry>\n<term><anchor id=\"$id\" role=\"constant\"${condition}${empty_element_end}<literal>$member_name</literal></term>\n";
1122             if (defined $member_descr) {
1123                 $desc .= "<listitem><simpara>".&ExpandAbbreviations($symbol, $member_descr)."</simpara></listitem>\n";
1124             } else {
1125                 $desc .= "<listitem></listitem>\n";
1126             }
1127             $desc .= "</varlistentry>\n";
1128         }
1130         $desc .= "</variablelist>";
1131     }
1133     $desc .= OutputSymbolTraits ($symbol);
1134     $desc .= "</refsect2>\n";
1135     return ($synop, $desc);
1139 #############################################################################
1140 # Function    : OutputUnion
1141 # Description : Returns the synopsis and detailed description of a union.
1142 # Arguments   : $symbol - the union.
1143 #               $declaration - the declaration of the union.
1144 #############################################################################
1146 sub OutputUnion {
1147     my ($symbol, $declaration) = @_;
1148     my $id = &CreateValidSGMLID ($symbol);
1149     my $condition = &MakeConditionDescription ($symbol);
1150     my $synop = &MakeReturnField("union") . "<link linkend=\"$id\">$symbol</link>;\n";
1151     my $desc = "<refsect2>\n<title><anchor id=\"$id\" role=\"union\"${condition}${empty_element_end}union $symbol</title>\n";
1153     $desc .= MakeIndexterms($symbol);
1155     $declaration = &CreateValidSGML ($declaration);
1156     $desc .= "<programlisting>$declaration</programlisting>\n";
1158     $desc .= &MakeDeprecationNote($symbol);
1160     if (defined ($SymbolDocs{$symbol})) {
1161         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1162     }
1163     $desc .= OutputSymbolTraits ($symbol);
1164     $desc .= "</refsect2>\n";
1165     return ($synop, $desc);
1169 #############################################################################
1170 # Function    : OutputVariable
1171 # Description : Returns the synopsis and detailed description of a variable.
1172 # Arguments   : $symbol - the extern'ed variable.
1173 #               $declaration - the declaration of the variable.
1174 #############################################################################
1176 sub OutputVariable {
1177     my ($symbol, $declaration) = @_;
1178     my $id = &CreateValidSGMLID ($symbol);
1179     my $condition = &MakeConditionDescription ($symbol);
1181     my $synop;
1182     if ($declaration =~ m/^\s*extern\s+((const\s+|unsigned\s+)*\w+)(\s+\*+|\*+|\s)(\s*)([A-Za-z]\w*)\s*;/) {
1183         my $mod = defined ($1) ? $1 : "";
1184         my $ptr = defined ($3) ? $3 : "";
1185         my $space = defined ($4) ? $4 : "";
1186         $synop = &MakeReturnField("extern") . "$mod$ptr$space<link linkend=\"$id\">$symbol</link>;\n";
1188     } else {
1189         $synop = &MakeReturnField("extern") . "<link linkend=\"$id\">$symbol</link>;\n";
1190     }
1192     my $desc = "<refsect2>\n<title><anchor id=\"$id\" role=\"variable\"${condition}${empty_element_end}$symbol</title>\n";
1194     $desc .= MakeIndexterms($symbol);
1196     $declaration = &CreateValidSGML ($declaration);
1197     $desc .= "<programlisting>$declaration</programlisting>\n";
1199     $desc .= &MakeDeprecationNote($symbol);
1201     if (defined ($SymbolDocs{$symbol})) {
1202         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1203     }
1204     $desc .= OutputSymbolTraits ($symbol);
1205     $desc .= "</refsect2>\n";
1206     return ($synop, $desc);
1210 #############################################################################
1211 # Function    : OutputFunction
1212 # Description : Returns the synopsis and detailed description of a function.
1213 # Arguments   : $symbol - the function.
1214 #               $declaration - the declaration of the function.
1215 #############################################################################
1217 sub OutputFunction {
1218     my ($symbol, $declaration, $symbol_type) = @_;
1219     my $id = &CreateValidSGMLID ($symbol);
1220     my $condition = &MakeConditionDescription ($symbol);
1222     # Take out the return type
1223     $declaration =~ s/<RETURNS>\s*((const\s+|G_CONST_RETURN\s+|unsigned\s+|struct\s+|enum\s+)*)(\w+)\s*(\**\s*(const|G_CONST_RETURN)?\s*\**\s*(restrict)?\s*)<\/RETURNS>\n//;
1224     my $type_modifier = defined($1) ? $1 : "";
1225     my $type = $3;
1226     my $pointer = $4;
1227 #   print "$symbol pointer is $pointer\n";
1228     my $xref = &MakeXRef ($type);
1229     my $start = "";
1230     if ($symbol_type eq 'USER_FUNCTION') {
1231 #       $start = "typedef ";
1232     }
1234     # We output const rather than G_CONST_RETURN.
1235     $type_modifier =~ s/G_CONST_RETURN/const/g;
1236     $pointer =~ s/G_CONST_RETURN/const/g;
1238     my $ret_type_len = length ($start) + length ($type_modifier)
1239         + length ($pointer) + length ($type);
1240     my $ret_type_output;
1241     my $symbol_len;
1242     if ($ret_type_len < $RETURN_TYPE_FIELD_WIDTH) {
1243         $ret_type_output = "$start$type_modifier$xref$pointer"
1244             . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
1245         $symbol_len = 0;
1246     } else {
1247 #       $ret_type_output = "$start$type_modifier$xref$pointer\n"
1248 #           . (' ' x $RETURN_TYPE_FIELD_WIDTH);
1250         $ret_type_output = "$start$type_modifier$xref$pointer ";
1251         $symbol_len = $ret_type_len + 1 - $RETURN_TYPE_FIELD_WIDTH;
1252     }
1254     $symbol_len += length ($symbol);
1255     my $char1 = my $char2 = my $char3 = "";
1256     if ($symbol_type eq 'USER_FUNCTION') {
1257         $symbol_len += 3;
1258         $char1 = "(";
1259         $char2 = "*";
1260         $char3 = ")";
1261     }
1263     my ($symbol_output, $symbol_desc_output);
1264     if ($symbol_len < $SYMBOL_FIELD_WIDTH) {
1265         $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3"
1266             . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1267         $symbol_desc_output = "$char1$char2$symbol$char3"
1268             . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1269     } else {
1270         $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3\n"
1271             . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1272         $symbol_desc_output = "$char1$char2$symbol$char3\n"
1273             . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1274     }
1276     my $synop = $ret_type_output . $symbol_output . '(';
1277     my $desc = "<refsect2>\n<title><anchor id=\"$id\" role=\"function\"${condition}${empty_element_end}${symbol} ()</title>\n";
1279     $desc .= MakeIndexterms($symbol);
1281     $desc  .= "<programlisting>${ret_type_output}$symbol_desc_output(";
1283     my $param_num = 0;
1284     while ($declaration ne "") {
1285         if ($declaration =~ s/^[\s,]+//) {
1286             # skip whitespace and commas
1287             next;
1289         } elsif ($declaration =~ s/^void\s*[,\n]//) {
1290             $synop .= "void";
1291             $desc  .= "void";
1293         } elsif ($declaration =~ s/^...\s*[,\n]//) {
1294             if ($param_num == 0) {
1295                 $synop .= "...";
1296                 $desc  .= "...";
1297             } else {
1298                 $synop .= ",\n"
1299                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1300                     . " ...";
1301                 $desc  .= ",\n"
1302                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1303                     . " ...";
1304             }
1306         # allow alphanumerics, '_', '[' & ']' in param names
1307         # Try to match a standard parameter (keep in sync with gtkdoc-mktmpl)
1308         #                                $1                                                                              $2                             $3                                                           $4       $5
1309         } elsif ($declaration =~ s/^\s*((?:G_CONST_RETURN|G_GNUC_UNUSED|unsigned|signed|long|short|volatile|const)\s+)*((?:struct\b|enum\b)?\s*\w+)\s*((?:(?:const|restrict)?\s*\*?\s*(?:const\b|restrict\b)?\s*)*)(\w+)?\s*((?:\[\S*\])*)\s*[,\n]//) {
1310             my $pre     = defined($1) ? $1 : "";
1311             my $type    = $2;
1312             my $ptr     = defined($3) ? $3 : "";
1313             my $name    = defined($4) ? $4 : "";
1314             my $array   = defined($5) ? $5 : "";
1316             $pre  =~ s/\s+/ /g;
1317             $type =~ s/\s+/ /g;
1318             $ptr  =~ s/\s+/ /g;
1319             $ptr  =~ s/\s+$//;
1320             if ($ptr && $ptr !~ m/\*$/) { $ptr .= " "; }
1322             if (($name eq "") && $pre =~ m/^((un)?signed)\s?/ ) {
1323                 $name = $type;
1324                 $type = "$1";
1325                 $pre = "";
1326             }
1328             my $xref = &MakeXRef ($type);
1329             my $label   = "$pre$xref $ptr$name$array";
1331             #print "$symbol: '$pre' '$type' '$ptr' '$name' '$array'\n";
1333             if ($param_num == 0) {
1334                 $synop .= "$label";
1335                 $desc  .= "$label";
1336             } else {
1337                 $synop .= ",\n"
1338                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1339                     . " $label";
1340                 $desc  .= ",\n"
1341                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1342                     . " $label";
1343             }
1345         # Try to match parameters which are functions (keep in sync with gtkdoc-mktmpl)
1346         #                              $1                                       $2          $3      $4                        $5                    $7             $8
1347         } elsif ($declaration =~ s/^(const\s+|G_CONST_RETURN\s+|unsigned\s+)*(struct\s+)?(\w+)\s*(\**)\s*(?:restrict\b)?\s*(const\s+)?\(\s*\*+\s*(\w+)\s*\)\s*\(([^)]*)\)\s*[,\n]//) {
1348             my $mod1 = defined($1) ? $1 : "";
1349             if (defined($2)) { $mod1 .= $2; }
1350             my $type = $3;
1351             my $ptr1 = $4;
1352             my $mod2 = defined($5) ? $5 : "";
1353             my $func_ptr = $6;
1354             my $name = $7;
1355             my $func_params = $8;
1357             if ($ptr1 && $ptr1 !~ m/\*$/) { $ptr1 .= " "; }
1358             $func_ptr  =~ s/\s+//g;
1359             my $xref = &MakeXRef ($type);
1360             my $label = "$mod1$xref$ptr1$mod2 ($func_ptr$name) ($func_params)";
1362             #print "Type: $mod1$type$ptr1$mod2($func_ptr$name)($func_params)\n";
1363             if ($param_num == 0) {
1364                 $synop .= "$label";
1365                 $desc  .= "$label";
1366             } else {
1367                 $synop .= ",\n"
1368                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1369                     . " $label";
1370                 $desc  .= ",\n"
1371                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1372                     . " $label";
1373             }
1375         } else {
1376             print "###Can't parse args for function $symbol: $declaration\n";
1377             last;
1378         }
1379         $param_num++;
1380     }
1381     $synop .= ");\n";
1382     $desc  .= ");</programlisting>\n";
1384     $desc .= &MakeDeprecationNote($symbol);
1386     my $parameters = &OutputParamDescriptions ("FUNCTION", $symbol);
1387     my $parameters_output = 0;
1389     if (defined ($SymbolDocs{$symbol})) {
1390         my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1392         # Try to insert the parameter table at the author's desired position.
1393         # Otherwise we need to tag it onto the end.
1394         if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1395           $parameters_output = 1;
1396         }
1397         $desc .= $symbol_docs;
1398     }
1400     if ($parameters_output == 0) {
1401         $desc .= $parameters;
1402     }
1404     $desc .= OutputSymbolTraits ($symbol);
1405     $desc .= "</refsect2>\n";
1406     return ($synop, $desc);
1410 #############################################################################
1411 # Function    : OutputParamDescriptions
1412 # Description : Returns the DocBook output describing the parameters of a
1413 #               function, macro or signal handler.
1414 # Arguments   : $symbol_type - 'FUNCTION', 'MACRO' or 'SIGNAL'. Signal
1415 #                 handlers have an implicit user_data parameter last.
1416 #               $symbol - the name of the function/macro being described.
1417 #############################################################################
1419 sub OutputParamDescriptions {
1420     my ($symbol_type, $symbol) = @_;
1421     my $output = "";
1422     if (defined ($SymbolParams{$symbol})) {
1423         my $returns = "";
1424         my $params = $SymbolParams{$symbol};
1425         my $params_desc = "";
1426         my $j;
1427         for ($j = 0; $j <= $#$params; $j += 2) {
1428             my $param_name = $$params[$j];
1429             my $param = $$params[$j + 1];
1430             if ($param_name eq "Returns") {
1431                 $returns = &ExpandAbbreviations($symbol, $param);
1432             } else {
1433                 if ($param_name eq "Varargs") {
1434                     $param_name = "...";
1435                 }
1436                 $param = &ExpandAbbreviations($symbol, $param);
1437                 $params_desc .= "<varlistentry><term><parameter>$param_name</parameter>&nbsp;:</term>\n<listitem><simpara>$param</simpara></listitem></varlistentry>\n";
1438             }
1439         }
1441         # Signals have an implicit user_data parameter which we describe.
1442         if ($symbol_type eq "SIGNAL") {
1443             $params_desc .= "<varlistentry><term><parameter>user_data</parameter>&nbsp;:</term>\n<listitem><simpara>user data set when the signal handler was connected.</simpara></listitem></varlistentry>\n";
1444         }
1446         # Start a table if we need one.
1447         if ($params_desc || $returns) {
1448             $output .= <<EOF;
1449 <variablelist role="params">
1452             if ($params_desc ne "") {
1453 #               $output .= "<varlistentry><term>Parameters:</term><listitem></listitem></varlistentry>\n";
1454                 $output .= $params_desc;
1455             }
1457             # Output the returns info last.
1458             if ($returns) {
1459                 $output .= "<varlistentry><term><emphasis>Returns</emphasis>&nbsp;:</term><listitem><simpara>$returns</simpara></listitem></varlistentry>\n";
1460             }
1462             # Finish the table.
1463             $output .= "</variablelist>";
1464         }
1465     }
1466     return $output;
1470 #############################################################################
1471 # Function    : ParseStabilityLevel
1472 # Description : Parses a stability level and outputs a warning if it isn't
1473 #               valid.
1474 # Arguments   : $stability - the stability text.
1475 #               $message - description of where the level is from, to use in
1476 #               any error message.
1477 # Returns     : The parsed stability level string.
1478 #############################################################################
1480 sub ParseStabilityLevel {
1481     my ($stability, $message) = @_;
1483     $stability =~ s/^\s*//;
1484     $stability =~ s/\s*$//;
1485     if ($stability =~ m/^stable$/i) {
1486         $stability = "Stable";
1487     } elsif ($stability =~ m/^unstable$/i) {
1488         $stability = "Unstable";
1489     } elsif ($stability =~ m/^private$/i) {
1490         $stability = "Private";
1491     } else {
1492         print <<EOF;
1493 WARNING: $message is $stability.
1494 It should be one of these: Stable, Unstable, or Private.
1496     }
1497     return $stability;
1501 #############################################################################
1502 # Function    : OutputSGMLFile
1503 # Description : Outputs the final DocBook file for one section.
1504 # Arguments   : $file - the name of the file.
1505 #               $title - the title from the $MODULE-sections.txt file, which
1506 #                 will be overridden by the title in the template file.
1507 #               $section_id - the SGML id to use for the toplevel tag.
1508 #               $includes - comma-separates list of include files added at top
1509 #                 of synopsis, with '<' '>' around them (if not already enclosed in "").
1510 #               $synopsis - reference to the DocBook for the Synopsis part.
1511 #               $details - reference to the DocBook for the Details part.
1512 #               $signal_synop - reference to the DocBook for the Signal Synopsis part
1513 #               $signal_desc - reference to the DocBook for the Signal Description part
1514 #               $args_synop - reference to the DocBook for the Arg Synopsis part
1515 #               $args_desc - reference to the DocBook for the Arg Description part
1516 #               $hierarchy - reference to the DocBook for the Object Hierarchy part
1517 #               $interfaces - reference to the DocBook for the Interfaces part
1518 #               $implementations - reference to the DocBook for the Known Implementations part
1519 #               $prerequisites - reference to the DocBook for the Prerequisites part
1520 #               $derived - reference to the DocBook for the Derived Interfaces part
1521 #               $file_objects - reference to an array of objects in this file
1522 #############################################################################
1524 sub OutputSGMLFile {
1525     my ($file, $title, $section_id, $includes, $synopsis, $details, $signals_synop, $signals_desc, $args_synop, $args_desc, $hierarchy, $interfaces, $implementations, $prerequisites, $derived, $file_objects) = @_;
1527     # The edited title overrides the one from the sections file.
1528     my $new_title = $SymbolDocs{"$TMPL_DIR/$file:Title"};
1529     if (defined ($new_title) && $new_title !~ m/^\s*$/) {
1530         $title = $new_title;
1531 #       print "Found title: $title\n";
1532     }
1533     my $short_desc = $SymbolDocs{"$TMPL_DIR/$file:Short_Description"};
1534     if (!defined ($short_desc) || $short_desc =~ m/^\s*$/) {
1535 #       $short_desc = "one line description goes here.";
1536         $short_desc = "";
1537     } else {
1538         $short_desc = &ExpandAbbreviations("$title:Short_description",
1539                                            $short_desc);
1540 #       print "Found short_desc: $short_desc";
1541     }
1542     my $long_desc = $SymbolDocs{"$TMPL_DIR/$file:Long_Description"};
1543     if (!defined ($long_desc) || $long_desc =~ m/^\s*$/) {
1544         $long_desc = "<para>\nA longer description goes here.\n</para>\n";
1545     } else {
1546         $long_desc = &ExpandAbbreviations("$title:Long_description",
1547                                           $long_desc);
1548 #       print "Found long_desc: $long_desc";
1549     }
1550     my $see_also = $SymbolDocs{"$TMPL_DIR/$file:See_Also"};
1551     if (!defined ($see_also) || $see_also =~ m%^\s*(<para>)?\s*(</para>)?\s*$%) {
1552         $see_also = "";
1553     } else {
1554         $see_also = &ExpandAbbreviations("$title:See_Also", $see_also);
1555 #       print "Found see_also: $see_also";
1556     }
1557     if ($see_also) {
1558         $see_also = "<refsect1>\n<title>See Also</title>\n$see_also\n</refsect1>\n";
1559     }
1560     my $stability = $SymbolDocs{"$TMPL_DIR/$file:Stability_Level"};
1561     if (!defined ($stability) || $stability =~ m/^\s*$/) {
1562         $stability = "";
1563     } else {
1564         $stability = &ParseStabilityLevel($stability, "Section stability level for $file");
1565 #       print "Found stability: $stability";
1566     }
1567     if ($stability) {
1568         $stability = "<refsect1>\n<title>Stability Level</title>\n$stability, unless otherwise indicated\n</refsect1>\n";
1569     } elsif ($DEFAULT_STABILITY) {
1570         $stability = "<refsect1>\n<title>Stability Level</title>\n$DEFAULT_STABILITY, unless otherwise indicated\n</refsect1>\n";
1571     }
1573     my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
1574         gmtime (time);
1575     my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
1576     $year += 1900;
1578     my $include_output = "";
1579     my $include;
1580     foreach $include (split (/,/, $includes)) {
1581         if ($include =~ m/^\".+\"$/) {
1582             $include_output .= "#include ${include}\n";
1583         }
1584         else {
1585             $include =~ s/^\s+|\s+$//gs;
1586             $include_output .= "#include &lt;${include}&gt;\n";
1587         }
1588     }
1590     my $old_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT";
1591     my $new_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT.new";
1593     open (OUTPUT, ">$new_sgml_file")
1594         || die "Can't create $new_sgml_file";
1596     my $object_anchors = "";
1597     foreach my $object (@$file_objects) {
1598         next if ($object eq $section_id);
1599         my $id = CreateValidSGMLID($object);
1600 #       print "Debug: Adding anchor for $object\n";
1601         $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
1602     }
1604     # We used to output this, but is messes up our UpdateFileIfChanged code
1605     # since it changes every day (and it is only used in the man pages):
1606     # "<refentry id="$section_id" revision="$mday $month $year">"
1608     if (lc($OUTPUT_FORMAT) eq "xml") {
1609         print OUTPUT $doctype_header;
1610     }
1612     print OUTPUT <<EOF;
1613 <refentry id="$section_id">
1614 <refmeta>
1615 <refentrytitle role="top_of_page">$title</refentrytitle>
1616 <manvolnum>3</manvolnum>
1617 <refmiscinfo>\U$MODULE\E Library</refmiscinfo>
1618 </refmeta>
1620 <refnamediv>
1621 <refname>$title</refname>
1622 <refpurpose>$short_desc</refpurpose>
1623 <!--[<xref linkend="desc" endterm="desc.title"/>]-->
1624 </refnamediv>
1625 $stability
1626 <refsynopsisdiv role="synopsis">
1627 <title role="synopsis.title">Synopsis</title>
1628 $object_anchors
1629 <synopsis>
1631 $include_output
1633 $${synopsis}</synopsis>
1634 </refsynopsisdiv>
1636 $$hierarchy
1637 $$prerequisites
1638 $$derived
1639 $$interfaces
1640 $$implementations
1641 $$args_synop
1642 $$signals_synop
1644 <refsect1 role="desc">
1645 <title role="desc.title">Description</title>
1646 $long_desc
1647 </refsect1>
1649 <refsect1 role="details">
1650 <title role="details.title">Details</title>
1651 $$details
1652 </refsect1>
1653 $$args_desc
1654 $$signals_desc
1656 $see_also
1657 </refentry>
1659     close (OUTPUT);
1661     return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
1665 #############################################################################
1666 # Function    : OutputExtraFile
1667 # Description : Copies an "extra" DocBook file into the output directory,
1668 #               expanding abbreviations
1669 # Arguments   : $file - the source file.
1670 #############################################################################
1671 sub OutputExtraFile {
1672     my ($file) = @_;
1674     my $basename;
1676     ($basename = $file) =~ s!^.*/!!;
1678     my $old_sgml_file = "$SGML_OUTPUT_DIR/$basename";
1679     my $new_sgml_file = "$SGML_OUTPUT_DIR/$basename.new";
1681     my $contents;
1683     open(EXTRA_FILE, "<$file") || die "Can't open $file";
1685     {
1686         local $/;
1687         $contents = <EXTRA_FILE>;
1688     }
1690     open (OUTPUT, ">$new_sgml_file")
1691         || die "Can't create $new_sgml_file";
1693     print OUTPUT &ExpandAbbreviations ("$basename file", $contents);
1694     close (OUTPUT);
1696     return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
1699 #############################################################################
1700 # Function    : OutputBook
1701 # Description : Outputs the SGML entities that need to be included into the
1702 #               main SGML file for the module.
1703 # Arguments   : $book_top - the declarations of the entities, which are added
1704 #                 at the top of the main SGML file.
1705 #               $book_bottom - the references to the entities, which are
1706 #                 added in the main SGML file at the desired position.
1707 #############################################################################
1709 sub OutputBook {
1710     my ($book_top, $book_bottom) = @_;
1712     my $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top";
1713     my $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top.new";
1715     open (OUTPUT, ">$new_file")
1716         || die "Can't create $new_file";
1717     print OUTPUT $book_top;
1718     close (OUTPUT);
1720     &UpdateFileIfChanged ($old_file, $new_file, 0);
1723     $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom";
1724     $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom.new";
1726     open (OUTPUT, ">$new_file")
1727         || die "Can't create $new_file";
1728     print OUTPUT $book_bottom;
1729     close (OUTPUT);
1731     &UpdateFileIfChanged ($old_file, $new_file, 0);
1734     # If the main SGML file hasn't been created yet, we create it here.
1735     # The user can tweak it later.
1736     if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
1737       open (OUTPUT, ">$MAIN_SGML_FILE")
1738         || die "Can't create $MAIN_SGML_FILE";
1740       if (lc($OUTPUT_FORMAT) eq "xml") {
1741           print OUTPUT <<EOF;
1742 <?xml version="1.0"?>
1743 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
1744                "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
1745 <book id="index" xmlns:xi="http://www.w3.org/2003/XInclude">
1747       } else {
1748         print OUTPUT <<EOF;
1749 <!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
1751         print OUTPUT $book_top;
1752         print OUTPUT <<EOF;
1754 <book id="index">
1756       }
1758 print OUTPUT <<EOF;
1759   <bookinfo>
1760     <title>$MODULE Reference Manual</title>
1761     <releaseinfo>
1762       for $MODULE [VERSION]
1763       The latest version of this documentation can be found on-line at
1764       <ulink role="online-location" url="http://[SERVER]/$MODULE/index.html">http://[SERVER]/$MODULE/</ulink>.
1765     </releaseinfo>
1766   </bookinfo>
1768   <chapter>
1769     <title>[Insert title here]</title>
1771       print OUTPUT $book_bottom;
1773       print OUTPUT <<EOF;
1774   </chapter>
1775 </book>
1778       close (OUTPUT);
1779     }
1783 #############################################################################
1784 # Function    : CreateValidSGMLID
1785 # Description : Creates a valid SGML 'id' from the given string.
1786 #               NOTE: SGML ids are case-insensitive, so we have a few special
1787 #                     cases to avoid clashes of ids.
1788 # Arguments   : $id - the string to be converted into a valid SGML id.
1789 #############################################################################
1791 sub CreateValidSGMLID {
1792     my ($id) = $_[0];
1794     # Append ":CAPS" to all all-caps identifiers
1796     # Special case, '_' would end up as '' so we use 'gettext-macro' instead.
1797     if ($id eq "_") { return "gettext-macro"; }
1799     if ($id !~ /[a-z]/) { $id .= ":CAPS" };
1801     $id =~ s/[_ ]/-/g;
1802     $id =~ s/[,\.]//g;
1803     $id =~ s/^-*//;
1804     $id =~ s/::/-/g;
1806     return $id;
1810 #############################################################################
1811 # Function    : CreateValidSGML
1812 # Description : This turns any chars which are used in SGML into entities,
1813 #               e.g. '<' into '&lt;'
1814 # Arguments   : $text - the text to turn into proper SGML.
1815 #############################################################################
1817 sub CreateValidSGML {
1818     my ($text) = @_;
1819     $text =~ s/&/&amp;/g;       # Do this first, or the others get messed up.
1820     $text =~ s/</&lt;/g;
1821     $text =~ s/>/&gt;/g;
1822     return $text;
1825 #############################################################################
1826 # Function    : ConvertSGMLChars
1827 # Description : This is used for text in source code comment blocks, to turn
1828 #               chars which are used in SGML into entities, e.g. '<' into
1829 #               '&lt;'. Depending on $SGML_MODE, this is done
1830 #               unconditionally or only if the character doesn't seem to be
1831 #               part of an SGML construct (tag or entity reference).
1832 # Arguments   : $text - the text to turn into proper SGML.
1833 #############################################################################
1835 sub ConvertSGMLChars {
1836     my ($symbol, $text) = @_;
1838     if ($SGML_MODE) {
1839         # For the SGML mode only convert to entities outside CDATA sections.
1840         return &ModifyXMLElements ($text, $symbol,
1841                                    "<!\\[CDATA\\[|<programlisting[^>]*>",
1842                                    \&ConvertSGMLCharsEndTag,
1843                                    \&ConvertSGMLCharsCallback);
1844     } else {
1845         # For the simple non-sgml mode, convert to entities everywhere.
1846         $text =~ s/&/&amp;/g;   # Do this first, or the others get messed up.
1847         $text =~ s/</&lt;/g;
1848         $text =~ s/>/&gt;/g;
1849         return $text;
1850     }
1854 sub ConvertSGMLCharsEndTag {
1855   if ($_[0] eq "<!\[CDATA\[") {
1856     return "]]>";
1857   } else {
1858     return "</programlisting>";
1859   }
1862 sub ConvertSGMLCharsCallback {
1863   my ($text, $symbol, $tag) = @_;
1865   if ($tag =~ m/^<programlisting/) {
1866     # We can handle <programlisting> specially here.
1867     return &ModifyXMLElements ($text, $symbol,
1868                                "<!\\[CDATA\\[",
1869                                \&ConvertSGMLCharsEndTag,
1870                                \&ConvertSGMLCharsCallback2);
1871   } elsif ($tag eq "") {
1872     # If we're not in CDATA convert to entities.
1873     $text =~ s/&(?![a-zA-Z#]+;)/&amp;/g;        # Do this first, or the others get messed up.
1874     $text =~ s/<(?![a-zA-Z\/!])/&lt;/g;
1875     $text =~ s/(?<![a-zA-Z0-9"'\/-])>/&gt;/g;
1877     # Handle "#include <xxxxx>"
1878     $text =~ s/#include(\s+)<([^>]+)>/#include$1&lt;$2&gt;/g;
1879   }
1881   return $text;
1884 sub ConvertSGMLCharsCallback2 {
1885   my ($text, $symbol, $tag) = @_;
1887   # If we're not in CDATA convert to entities.
1888   # We could handle <programlisting> differently, though I'm not sure it helps.
1889   if ($tag eq "") {
1890     $text =~ s/&(?![a-zA-Z#]+;)/&amp;/g;        # Do this first, or the others get messed up.
1891 #    $text =~ s/&/&amp;/g;      # Do this first, or the others get messed up.
1892     $text =~ s/<(?![a-zA-Z\/!])/&lt;/g;
1893     $text =~ s/(?<![a-zA-Z0-9"'\/-])>/&gt;/g;
1895     # Handle "#include <xxxxx>"
1896     $text =~ s/#include(\s+)<([^>]+)>/#include$1&lt;$2&gt;/g;
1897   }
1899   return $text;
1903 #############################################################################
1904 # Function    : ExpandAbbreviations
1905 # Description : This turns the abbreviations function(), macro(), @param,
1906 #               %constant, and #symbol into appropriate DocBook markup.
1907 #               CDATA sections and <programlisting> parts are skipped.
1908 # Arguments   : $symbol - the symbol being documented, for error messages.
1909 #               $text - the text to expand.
1910 #############################################################################
1912 sub ExpandAbbreviations {
1913   my ($symbol, $text) = @_;
1915   # Convert "|[" and "]|" into the start and end of program listing examples.
1916   $text =~ s%\|\[%<informalexample><programlisting>%g;
1917   $text =~ s%\]\|%</programlisting></informalexample>%g;
1919   return &ModifyXMLElements ($text, $symbol,
1920                              "<!\\[CDATA\\[|<programlisting[^>]*>",
1921                              \&ExpandAbbreviationsEndTag,
1922                              \&ExpandAbbreviationsCallback);
1926 # Returns the end tag corresponding to the given start tag.
1927 sub ExpandAbbreviationsEndTag {
1928   if ($_[0] eq "<!\[CDATA\[") {
1929     return "]]>";
1930   } else {
1931     return "</programlisting>";
1932   }
1935 # Called inside or outside each CDATA or <programlisting> section.
1936 sub ExpandAbbreviationsCallback {
1937   my ($text, $symbol, $tag) = @_;
1939   if ($tag =~ m/^<programlisting/) {
1940     # Handle any embedded CDATA sections.
1941     return &ModifyXMLElements ($text, $symbol,
1942                                "<!\\[CDATA\\[",
1943                                \&ExpandAbbreviationsEndTag,
1944                                \&ExpandAbbreviationsCallback2);
1945   } elsif ($tag eq "") {
1946     # We are outside any CDATA or <programlisting> sections, so we expand
1947     # any gtk-doc abbreviations.
1949     # Convert 'function()' or 'macro()'
1950     $text =~ s/(\w+)\s*\(\)/&MakeXRef($1, &tagify($1 . "()", "function"));/eg;
1952     # Convert '@param'
1953     $text =~ s/\@(\w+((\.|->)\w+)*)/<parameter>$1<\/parameter>/g;
1955     # Convert '%constant'. Also allow negative numbers, e.g. %-1.
1956     $text =~ s/\%(-?\w+)/&MakeXRef($1, &tagify($1, "literal"));/eg;
1958     # Convert '#symbol'
1959     $text =~ s/#([\w\-:]+)/&MakeHashXRef($1, "type");/eg;
1960   }
1962   return $text;
1965 # This is called inside a <programlisting>
1966 sub ExpandAbbreviationsCallback2 {
1967   my ($text, $symbol, $tag) = @_;
1969   if ($tag eq "") {
1970     # We are inside a <programlisting> but outside any CDATA sections,
1971     # so we expand any gtk-doc abbreviations.
1972     $text =~ s/#(\w+)/&MakeHashXRef($1, "");/eg;
1973   }
1975   return $text;
1978 sub MakeHashXRef {
1979     my ($symbol, $tag) = @_;;
1980     my $text = $symbol;
1982     # Check for things like '#include', '#define', and skip them.
1983     if ($PreProcessorDirectives{$symbol}) {
1984       return "#$symbol";
1985     }
1987     # Get rid of any special '-struct' suffix.
1988     $text =~ s/-struct$//;
1990     # If the symbol is in the form "Object::signal", then change the symbol to
1991     # "Object-signal" and use "signal" as the text.
1992     if ($symbol =~ s/::/-/) {
1993       $text = "\"$'\"";
1994     }
1996     # If the symbol is in the form "Object:property", then change the symbol to
1997     # "Object--property" and use "property" as the text.
1998     if ($symbol =~ s/:/--/) {
1999       $text = "\"$'\"";
2000     }
2002     if ($tag ne "") {
2003       $text = tagify ($text, $tag);
2004     }
2006     return &MakeXRef($symbol, $text);
2010 #############################################################################
2011 # Function    : ModifyXMLElements
2012 # Description : Looks for given XML element tags within the text, and calls
2013 #               the callback on pieces of text inside & outside those elements.
2014 #               Used for special handling of text inside things like CDATA
2015 #               and <programlisting>.
2016 # Arguments   : $text - the text.
2017 #               $symbol - the symbol currently being documented (only used for
2018 #                      error messages).
2019 #               $start_tag_regexp - the regular expression to match start tags.
2020 #                      e.g. "<!\\[CDATA\\[|<programlisting[^>]*>" to match
2021 #                      CDATA sections or programlisting elements.
2022 #               $end_tag_func - function which is passed the matched start tag
2023 #                      and should return the appropriate end tag string.
2024 #               $callback - callback called with each part of the text. It is
2025 #                      called with a piece of text, the symbol being
2026 #                      documented, and the matched start tag or "" if the text
2027 #                      is outside the XML elements being matched.
2028 #############################################################################
2029 sub ModifyXMLElements {
2030     my ($text, $symbol, $start_tag_regexp, $end_tag_func, $callback) = @_;
2031     my ($before_tag, $start_tag, $end_tag_regexp, $end_tag);
2032     my $result = "";
2034     while ($text =~ m/$start_tag_regexp/s) {
2035       $before_tag = $`;
2036       $start_tag = $&;
2037       $text = $';
2039       $result .= &$callback ($before_tag, $symbol, "");
2040       $result .= $start_tag;
2042       $end_tag_regexp = &$end_tag_func ($start_tag);
2044       if ($text =~ m/$end_tag_regexp/s) {
2045         $before_tag = $`;
2046         $end_tag = $&;
2047         $text = $';
2049         $result .= &$callback ($before_tag, $symbol, $start_tag);
2050         $result .= $end_tag;
2051       } else {
2052         print "WARNING: Can't find tag end: $end_tag_regexp in docs for: $symbol\n";
2053         # Just assume it is all inside the tag.
2054         $result .= &$callback ($text, $symbol, $start_tag);
2055         $text = "";
2056       }
2057     }
2059     # Handle any remaining text outside the tags.
2060     $result .= &$callback ($text, $symbol, "");
2062     return $result;
2065 sub noop {
2066   return $_[0];
2069 # Adds a tag around some text.
2070 # e.g tagify("Text", "literal") => "<literal>Text</literal>".
2071 sub tagify {
2072    my ($text, $elem) = @_;
2073    return "<" . $elem . ">" . $text . "</" . $elem . ">";
2077 #############################################################################
2078 # Function    : MakeXRef
2079 # Description : This returns a cross-reference link to the given symbol.
2080 #               Though it doesn't try to do this for a few standard C types
2081 #               that it knows won't be in the documentation.
2082 # Arguments   : $symbol - the symbol to try to create a XRef to.
2083 #               $text - text text to put inside the XRef, defaults to $symbol
2084 #############################################################################
2086 sub MakeXRef {
2087     my ($symbol, $text) = ($_[0], $_[1]);
2088     if (!defined($text)) {
2089         $text = $symbol;
2091         # Get rid of special '-struct' suffix.
2092         $text =~ s/-struct$//;
2093     }
2095     #print "Getting type link for $symbol -> $text\n";
2097     my $symbol_id = &CreateValidSGMLID ($symbol);
2098     return "<link linkend=\"$symbol_id\">$text</link>";
2102 #############################################################################
2103 # Function    : MakeIndexterms
2104 # Description : This returns a indexterm elements for the given symbol
2105 # Arguments   : $symbol - the symbol to create indexterms for
2106 #############################################################################
2108 sub MakeIndexterms {
2109   my ($symbol) = $_[0];
2110   my $terms =  "";
2112   if (exists $Deprecated{$symbol}) {
2113       $terms .= "<indexterm role=\"deprecated\"><primary>$symbol</primary></indexterm>"
2114   }
2115   if (exists $Since{$symbol}) {
2116      my $since = $Since{$symbol};
2117      $since =~ s/^\s+//;
2118      $since =~ s/\s+$//;
2119      if ($since ne "") {
2120          $terms .= "<indexterm role=\"$since\"><primary>$symbol</primary></indexterm>";
2121      }
2122   }
2123   if ($terms eq "") {
2124      $terms .= "<indexterm><primary>$symbol</primary></indexterm>";
2125   }
2127   return $terms;
2130 #############################################################################
2131 # Function    : MakeDeprecationNote
2132 # Description : This returns a deprecation warning for the given symbol.
2133 # Arguments   : $symbol - the symbol to try to create a warning for.
2134 #############################################################################
2136 sub MakeDeprecationNote {
2137     my ($symbol) = $_[0];
2138     my $desc = "";
2139     my $note = "";
2140     if (exists $Deprecated{$symbol}) {
2141         $desc .= "<warning>";
2143         if ($Deprecated{$symbol} =~ /^\s*([0-9\.]+)\s*:/) {
2144                 $desc .= "<para><literal>$symbol</literal> has been deprecated since version $1 and should not be used in newly-written code.";
2145         } else {
2146                 $desc .= "<para><literal>$symbol</literal> is deprecated and should not be used in newly-written code.";
2147         }
2148         if ($Deprecated{$symbol} ne "") {
2149             $note = &ExpandAbbreviations($symbol, $Deprecated{$symbol});
2150             $note =~ s/^\s*([0-9\.]+)\s*:\s*//;
2151             $note =~ s/^\s+//;
2152             $note =~ s/\s+$//;
2153             $note =~ s%\n{2,}%\n</para>\n<para>\n%g;
2154             $desc .= " " . $note;
2155         }
2156         $desc .= "</para></warning>\n";
2157     }
2158     return $desc;
2161 #############################################################################
2162 # Function    : MakeConditionDescription
2163 # Description : This returns a sumary of conditions for the given symbol.
2164 # Arguments   : $symbol - the symbol to try to create the sumary.
2165 #############################################################################
2167 sub MakeConditionDescription {
2168     my ($symbol) = $_[0];
2169     my $desc = "";
2171     if (exists $Deprecated{$symbol}) {
2172         if ($desc ne "") {
2173             $desc .= "|";
2174         }
2176         if ($Deprecated{$symbol} =~ /^\s*(.*?)\s*$/) {
2177                 $desc .= "deprecated:$1";
2178         } else {
2179                 $desc .= "deprecated";
2180         }
2181     }
2183     if (exists $Since{$symbol}) {
2184         if ($desc ne "") {
2185             $desc .= "|";
2186         }
2188         if ($Since{$symbol} =~ /^\s*(.*?)\s*$/) {
2189                 $desc .= "since:$1";
2190         } else {
2191                 $desc .= "since";
2192         }
2193     }
2195     if (exists $StabilityLevel{$symbol}) {
2196         if ($desc ne "") {
2197             $desc .= "|";
2198         }
2199         $desc .= "stability:".$StabilityLevel{$symbol};
2200     }
2202     if ($desc ne "") {
2203         $desc=" condition=\"".$desc."\"";
2204         #print "condition for '$symbol' = '$desc'\n";
2205     }
2206     return $desc;
2209 #############################################################################
2210 # Function    : GetHierarchy
2211 # Description : Returns the DocBook output describing the ancestors and
2212 #               immediate children of a GObject subclass. It uses the
2213 #               global @Objects and @ObjectLevels arrays to walk the tree.
2214 # Arguments   : $object - the GtkObject subclass.
2215 #############################################################################
2217 sub GetHierarchy {
2218     my ($object) = @_;
2220     # Find object in the objects array.
2221     my $found = 0;
2222     my @children = ();
2223     my $i;
2224     my $level;
2225     my $j;
2226     for ($i = 0; $i < @Objects; $i++) {
2227         if ($found) {
2228             if ($ObjectLevels[$i] <= $level) {
2229             last;
2230         }
2231             elsif ($ObjectLevels[$i] == $level + 1) {
2232                 push (@children, $Objects[$i]);
2233             }
2234         }
2235         elsif ($Objects[$i] eq $object) {
2236             $found = 1;
2237             $j = $i;
2238             $level = $ObjectLevels[$i];
2239         }
2240     }
2241     if (!$found) {
2242         return "";
2243     }
2245     # Walk up the hierarchy, pushing ancestors onto the ancestors array.
2246     my @ancestors = ();
2247     push (@ancestors, $object);
2248 #    print "Level: $level\n";
2249     while ($level > 1) {
2250         $j--;
2251         if ($ObjectLevels[$j] < $level) {
2252             push (@ancestors, $Objects[$j]);
2253             $level = $ObjectLevels[$j];
2254 #           print "Level: $level\n";
2255         }
2256     }
2258     # Output the ancestors list, indented and with links.
2259     my $hierarchy = "<synopsis>\n\n";
2260     $level = 0;
2261     for ($i = $#ancestors; $i >= 0; $i--) {
2262         my $link_text;
2263         # Don't add a link to the current widget, i.e. when i == 0.
2264         if ($i > 0) {
2265             my $ancestor_id = &CreateValidSGMLID ($ancestors[$i]);
2266             $link_text = "<link linkend=\"$ancestor_id\">$ancestors[$i]</link>";
2267         } else {
2268             $link_text = "$ancestors[$i]";
2269         }
2270         if ($level == 0) {
2271             $hierarchy .= "  $link_text\n";
2272         } else {
2273 #           $hierarchy .= ' ' x ($level * 6 - 3) . "|\n";
2274             $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
2275         }
2276         $level++;
2277     }
2278     for ($i = 0; $i <= $#children; $i++) {
2279       my $id = &CreateValidSGMLID ($children[$i]);
2280       my $link_text = "<link linkend=\"$id\">$children[$i]</link>";
2281       $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
2282     }
2283     $hierarchy .= "</synopsis>\n";
2285     return $hierarchy;
2289 #############################################################################
2290 # Function    : GetInterfaces
2291 # Description : Returns the DocBook output describing the interfaces
2292 #               implemented by a class. It uses the global %Interfaces hash.
2293 # Arguments   : $object - the GtkObject subclass.
2294 #############################################################################
2296 sub GetInterfaces {
2297     my ($object) = @_;
2298     my $text = "";
2299     my $i;
2301     # Find object in the objects array.
2302     if (exists($Interfaces{$object})) {
2303         my @ifaces = split(' ', $Interfaces{$object});
2304         $text = <<EOF;
2305 <para>
2306 $object implements
2308         for ($i = 0; $i <= $#ifaces; $i++) {
2309             my $id = &CreateValidSGMLID ($ifaces[$i]);
2310             $text .= " <link linkend=\"$id\">$ifaces[$i]</link>";
2311             if ($i < $#ifaces - 1) {
2312                 $text .= ', ';
2313             }
2314             elsif ($i < $#ifaces) {
2315                 $text .= ' and ';
2316             }
2317             else {
2318                 $text .= '.';
2319             }
2320         }
2321         $text .= <<EOF;
2322 </para>
2324     }
2326     return $text;
2329 #############################################################################
2330 # Function    : GetImplementations
2331 # Description : Returns the DocBook output describing the implementations
2332 #               of an interface. It uses the global %Interfaces hash.
2333 # Arguments   : $object - the GtkObject subclass.
2334 #############################################################################
2336 sub GetImplementations {
2337     my ($object) = @_;
2338     my @impls = ();
2339     my $text = "";
2340     my $i;
2341     foreach my $key (keys %Interfaces) {
2342         if ($Interfaces{$key} =~ /\b$object\b/) {
2343             push (@impls, $key);
2344         }
2345     }
2346     if ($#impls >= 0) {
2347         $text = <<EOF;
2348 <para>
2349 $object is implemented by
2351         for ($i = 0; $i <= $#impls; $i++) {
2352             my $id = &CreateValidSGMLID ($impls[$i]);
2353             $text .= " <link linkend=\"$id\">$impls[$i]</link>";
2354             if ($i < $#impls - 1) {
2355                 $text .= ', ';
2356             }
2357             elsif ($i < $#impls) {
2358                 $text .= ' and ';
2359             }
2360             else {
2361                 $text .= '.';
2362             }
2363         }
2364         $text .= <<EOF;
2365 </para>
2367     }
2368     return $text;
2372 #############################################################################
2373 # Function    : GetPrerequisites
2374 # Description : Returns the DocBook output describing the prerequisites
2375 #               of an interface. It uses the global %Prerequisites hash.
2376 # Arguments   : $iface - the interface.
2377 #############################################################################
2379 sub GetPrerequisites {
2380     my ($iface) = @_;
2381     my $text = "";
2382     my $i;
2384     if (exists($Prerequisites{$iface})) {
2385         $text = <<EOF;
2386 <para>
2387 $iface requires
2389         my @prereqs = split(' ', $Prerequisites{$iface});
2390         for ($i = 0; $i <= $#prereqs; $i++) {
2391             my $id = &CreateValidSGMLID ($prereqs[$i]);
2392             $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
2393             if ($i < $#prereqs - 1) {
2394                 $text .= ', ';
2395             }
2396             elsif ($i < $#prereqs) {
2397                 $text .= ' and ';
2398             }
2399             else {
2400                 $text .= '.';
2401             }
2402         }
2403         $text .= <<EOF;
2404 </para>
2406     }
2407     return $text;
2410 #############################################################################
2411 # Function    : GetDerived
2412 # Description : Returns the DocBook output describing the derived interfaces
2413 #               of an interface. It uses the global %Prerequisites hash.
2414 # Arguments   : $iface - the interface.
2415 #############################################################################
2417 sub GetDerived {
2418     my ($iface) = @_;
2419     my $text = "";
2420     my $i;
2422     my @derived = ();
2423     foreach my $key (keys %Prerequisites) {
2424         if ($Prerequisites{$key} =~ /\b$iface\b/) {
2425             push (@derived, $key);
2426         }
2427     }
2428     if ($#derived >= 0) {
2429         $text = <<EOF;
2430 <para>
2431 $iface is required by
2433         for ($i = 0; $i <= $#derived; $i++) {
2434             my $id = &CreateValidSGMLID ($derived[$i]);
2435             $text .= " <link linkend=\"$id\">$derived[$i]</link>";
2436             if ($i < $#derived - 1) {
2437                 $text .= ', ';
2438             }
2439             elsif ($i < $#derived) {
2440                 $text .= ' and ';
2441             }
2442             else {
2443                 $text .= '.';
2444             }
2445         }
2446         $text .= <<EOF;
2447 </para>
2449     }
2450     return $text;
2454 #############################################################################
2455 # Function    : GetSignals
2456 # Description : Returns the synopsis and detailed description DocBook output
2457 #               for the signal handlers of a given GtkObject subclass.
2458 # Arguments   : $object - the GtkObject subclass, e.g. 'GtkButton'.
2459 #############################################################################
2461 sub GetSignals {
2462     my ($object) = @_;
2463     my $synop = "";
2464     my $desc = "";
2466     my $i;
2467     for ($i = 0; $i <= $#SignalObjects; $i++) {
2468         if ($SignalObjects[$i] eq $object) {
2469 #           print "Found signal: $SignalNames[$i]\n";
2470             my $name = $SignalNames[$i];
2471             my $symbol = "${object}::${name}";
2472             my $id = &CreateValidSGMLID ("$object-$name");
2474             my $pad = ' ' x (46 - length($name));
2475             $synop .= "  &quot;<link linkend=\"$id\">$name</link>&quot;$pad ";
2477             $desc .= "<refsect2><title><anchor id=\"$id\"${empty_element_end}The <literal>&quot;$name&quot;</literal> signal</title>\n";
2478             $desc .= MakeIndexterms($symbol);
2479             $desc .= "<programlisting>";
2481             $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
2482             my $type_modifier = defined($1) ? $1 : "";
2483             my $type = $2;
2484             my $pointer = $3;
2485             my $xref = &MakeXRef ($type);
2487             my $ret_type_len = length ($type_modifier) + length ($pointer)
2488                 + length ($type);
2489             my $ret_type_output = "$type_modifier$xref$pointer"
2490                 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
2492             $desc  .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
2494             my $sourceparams = $SourceSymbolParams{$symbol};
2495             my @params = split ("\n", $SignalPrototypes[$i]);
2496             my $j;
2497             my $l;
2498             my $type_len = length("gpointer");
2499             my $name_len = length("user_data");
2500             # do two passes, the first one is to calculate padding
2501             for ($l = 0; $l < 2; $l++) {
2502                 for ($j = 0; $j <= $#params; $j++) {
2503                     # allow alphanumerics, '_', '[' & ']' in param names
2504                     if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
2505                         $type = $1;
2506                         $pointer = $2;
2507                         if (defined($sourceparams)) {
2508                             $name = $$sourceparams[2 * $j];
2509                         }
2510                         else {
2511                             $name = $3;
2512                         }
2513                         if (!defined($name)) {
2514                             $name = "arg$j";
2515                         }
2516                         if ($l == 0) {
2517                             if (length($type) + length($pointer) > $type_len) {
2518                                 $type_len = length($type) + length($pointer);
2519                             }
2520                             if (length($name) > $name_len) {
2521                                 $name_len = length($name);
2522                             }
2523                         }
2524                         else {
2525                             $xref = &MakeXRef ($type);
2526                             $pad = ' ' x ($type_len - length($type) - length($pointer));
2527                             $desc .= "$xref$pad $pointer$name,\n";
2528                             $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
2529                         }
2530                      } else {
2531                          print "###Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]\n";
2532                      }
2533                 }
2534             }
2535             $xref = &MakeXRef ("gpointer");
2536             $pad = ' ' x ($type_len - length("gpointer"));
2537             $desc  .= "$xref$pad user_data)";
2539             my $flags = $SignalFlags[$i];
2540             my $flags_string = "";
2542             if (defined ($flags)) {
2543               if ($flags =~ m/f/) {
2544                 $flags_string = "Run First";
2545               }
2546               elsif ($flags =~ m/l/) {
2547                 $flags_string = "Run Last";
2548               }
2549               elsif ($flags =~ m/c/) {
2550                 $flags_string = "Cleanup";
2551               }
2552               if ($flags =~ m/r/) {
2553                 if ($flags_string) { $flags_string .= " / "; }
2554                 $flags_string .= "No Recursion";
2555               }
2556               if ($flags =~ m/d/) {
2557                 if ($flags_string) { $flags_string .= " / "; }
2558                 $flags_string .= "Has Details";
2559               }
2560               if ($flags =~ m/a/) {
2561                 if ($flags_string) { $flags_string .= " / "; }
2562                 $flags_string .= "Action";
2563               }
2564               if ($flags =~ m/h/) {
2565                 if ($flags_string) { $flags_string .= " / "; }
2566                 $flags_string .= "No Hooks";
2567               }
2568             }
2570             if ($flags_string)
2571               {
2572                 $synop .= ": $flags_string\n";
2574                 $pad = ' ' x (5 + $name_len - length("user_data"));
2575                 $desc  .= "$pad : $flags_string</programlisting>\n";
2576               }
2577             else
2578               {
2579                 $synop .= "\n";
2580                 $desc  .= "</programlisting>\n";
2581               }
2583             my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
2584             my $parameters_output = 0;
2586             $AllSymbols{$symbol} = 1;
2587             if (defined ($SymbolDocs{$symbol})) {
2588                 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
2590                 # Try to insert the parameter table at the author's desired
2591                 # position. Otherwise we need to tag it onto the end.
2592                 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
2593                   $parameters_output = 1;
2594                 }
2595                 $desc .= $symbol_docs;
2597                 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
2598                     $AllDocumentedSymbols{$symbol} = 1;
2599                 }
2600             }
2602             if ($parameters_output == 0) {
2603                 $desc .= $parameters;
2604               }
2606             if (exists $Since{$symbol}) {
2607               $desc .= "<para>Since $Since{$symbol}</para>";
2608             }
2609             if (exists $StabilityLevel{$symbol}) {
2610               $desc .= "<para>Stability Level: $StabilityLevel{$symbol}</para>";
2611             }
2612             $desc .= "</refsect2>";
2613         }
2614     }
2615     return ($synop, $desc);
2619 #############################################################################
2620 # Function    : GetArgs
2621 # Description : Returns the synopsis and detailed description DocBook output
2622 #               for the Args of a given GtkObject subclass.
2623 # Arguments   : $object - the GtkObject subclass, e.g. 'GtkButton'.
2624 #############################################################################
2626 sub GetArgs {
2627     my ($object) = @_;
2628     my $synop = "";
2629     my $desc = "";
2630     my $child_synop = "";
2631     my $child_desc = "";
2632     my $style_synop = "";
2633     my $style_desc = "";
2635     my $i;
2636     for ($i = 0; $i <= $#ArgObjects; $i++) {
2637         if ($ArgObjects[$i] eq $object) {
2638 #           print "Found arg: $ArgNames[$i]\n";
2639             my $name = $ArgNames[$i];
2640             # Remember only one colon so we don't clash with signals.
2641             my $symbol = "${object}:${name}";
2642             # I've used two dashes here for the same reason.
2643             my $id = &CreateValidSGMLID ("$object--$name");
2645             my $type = $ArgTypes[$i];
2646             my $type_output;
2647             my $range = $ArgRanges[$i];
2648             my $range_output = CreateValidSGML($range);
2649             my $default = $ArgDefaults[$i];
2650             my $default_output = CreateValidSGML($default);
2652             if ($type eq "GtkSignal") {
2653                 $type = "GtkSignalFunc, gpointer";
2654                 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
2655                     . &MakeXRef ("gpointer");
2656             } elsif ($type eq "GtkString") {
2657                 $type = "gchar*";
2658                 $type_output = &MakeXRef ("gchar") . "*";
2659             } else {
2660                 $type_output = &MakeXRef ($type);
2661             }
2663             my $flags = $ArgFlags[$i];
2664             my $flags_string = "";
2666             if ($flags =~ m/r/) {
2667                 $flags_string = "Read";
2668             }
2669             if ($flags =~ m/w/) {
2670                 if ($flags_string) { $flags_string .= " / "; }
2671                 $flags_string .= "Write";
2672             }
2673             if ($flags =~ m/x/) {
2674                 if ($flags_string) { $flags_string .= " / "; }
2675                 $flags_string .= "Construct";
2676             }
2677             if ($flags =~ m/X/) {
2678                 if ($flags_string) { $flags_string .= " / "; }
2679                 $flags_string .= "Construct Only";
2680             }
2682             $AllSymbols{$symbol} = 1;
2683             my $blurb;
2684             if (defined($SymbolDocs{$symbol}) &&
2685                 !IsEmptyDoc($SymbolDocs{$symbol})) {
2686                 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
2687                 $AllDocumentedSymbols{$symbol} = 1;
2688             }
2689             else {
2690                 if (!($ArgBlurbs[$i] eq "")) {
2691                     $AllDocumentedSymbols{$symbol} = 1;
2692                 }
2693                 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
2694             }
2696             my $pad1 = " " x (24 - length ($name));
2697             my $pad2 = " " x (20 - length ($type));
2698             my $kind = "";
2700             if ($flags =~ m/c/) {
2701                 $kind = "child property";
2702             }
2703             elsif ($flags =~ m/s/) {
2704                 $kind = "style property";
2705             }
2706             else {
2707                 $kind = "property";
2708             }
2710             my $arg_synop = "  &quot;<link linkend=\"$id\">$name</link>&quot;$pad1 $type_output $pad2 : $flags_string\n";
2711             my $arg_desc = "<refsect2><title><anchor id=\"$id\"${empty_element_end}The <literal>&quot;$name&quot;</literal> $kind</title>\n";
2712             $arg_desc .= MakeIndexterms($symbol);
2713             $arg_desc .= "<programlisting>  &quot;$name&quot;$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
2714             $arg_desc .= $blurb;
2715             if ($range ne "") {
2716                 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
2717             }
2718             if ($default ne "") {
2719                 $arg_desc .= "<para>Default value: $default_output</para>\n";
2720             }
2721             if (exists $Since{$symbol}) {
2722               $arg_desc .= "<para>Since $Since{$symbol}</para>\n";
2723             }
2724             if (exists $StabilityLevel{$symbol}) {
2725               $arg_desc .= "<para>Stability Level $StabilityLevel{$symbol}</para>\n";
2726             }
2727             $arg_desc .= "</refsect2>\n";
2729             if ($flags =~ m/c/) {
2730                 $child_synop .= $arg_synop;
2731                 $child_desc .= $arg_desc;
2732             }
2733             elsif ($flags =~ m/s/) {
2734                 $style_synop .= $arg_synop;
2735                 $style_desc .= $arg_desc;
2736             }
2737             else {
2738                 $synop .= $arg_synop;
2739                 $desc .= $arg_desc;
2740             }
2741         }
2742     }
2743     return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
2747 #############################################################################
2748 # Function    : ReadSourceDocumentation
2749 # Description : This reads in the documentation embedded in comment blocks
2750 #               in the source code (for Gnome).
2752 #               Parameter descriptions override any in the template files.
2753 #               Function descriptions are placed before any description from
2754 #               the template files.
2756 #               It recursively descends the source directory looking for .c
2757 #               files and scans them looking for specially-formatted comment
2758 #               blocks.
2760 # Arguments   : $source_dir - the directory to scan.
2761 #############m###############################################################
2763 sub ReadSourceDocumentation {
2764     my ($source_dir) = @_;
2765     my ($file, $dir, @suffix_list, $suffix);
2766 #    print "Scanning source directory: $source_dir\n";
2768     # This array holds any subdirectories found.
2769     my (@subdirs) = ();
2771     @suffix_list = split (/,/, $SOURCE_SUFFIXES);
2773     opendir (SRCDIR, $source_dir)
2774         || die "Can't open source directory $source_dir: $!";
2776     foreach $file (readdir (SRCDIR)) {
2777       if ($file =~ /^\./) {
2778         next;
2779       } elsif (-d "$source_dir/$file") {
2780         push (@subdirs, $file);
2781       } elsif (@suffix_list) {
2782         foreach $suffix (@suffix_list) {
2783           if ($file =~ m/\.\Q${suffix}\E$/) {
2784             &ScanSourceFile ("$source_dir/$file");
2785           }
2786         }
2787       } elsif ($file =~ m/\.[ch]$/) {
2788         &ScanSourceFile ("$source_dir/$file");
2789       }
2790     }
2791     closedir (SRCDIR);
2793     # Now recursively scan the subdirectories.
2794     foreach $dir (@subdirs) {
2795         next if ($IGNORE_FILES =~ m/(\s|^)\Q${dir}\E(\s|$)/);
2796         &ReadSourceDocumentation ("$source_dir/$dir");
2797     }
2801 #############################################################################
2802 # Function    : ScanSourceFile
2803 # Description : Scans one source file looking for specially-formatted comment
2804 #               blocks. Later &MergeSourceDocumentation is used to merge any
2805 #               documentation found with the documentation already read in
2806 #               from the template files.
2808 # Arguments   : $file - the file to scan.
2809 #############################################################################
2811 sub ScanSourceFile {
2812     my ($file) = @_;
2813     my $basename;
2815     if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
2816         $basename = $1;
2817     } else {
2818         print "WARNING: Can't find basename of file $file\n";
2819         $basename = $file;
2820     }
2822     # Check if the basename is in the list of files to ignore.
2823     if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
2824         return;
2825     }
2827 #    print "DEBUG: Scanning $file\n";
2829     open (SRCFILE, $file)
2830         || die "Can't open $file: $!";
2831     my $in_comment_block = 0;
2832     my $symbol;
2833     my ($in_description, $in_return, $in_since, $in_stability, $in_deprecated);
2834     my ($description, $return_desc, $return_start, $return_style);
2835     my ($since_desc, $stability_desc, $deprecated_desc);
2836     my $current_param;
2837     my $ignore_broken_returns;
2838     my @params;
2839     while (<SRCFILE>) {
2840         # Look for the start of a comment block.
2841         if (!$in_comment_block) {
2842             if (m%^\s*/\*.*\*/%) {
2843                 #one-line comment - not gtkdoc
2844             } elsif (m%^\s*/\*\*\s%) {
2845 #             print "Found comment block start\n";
2847                 $in_comment_block = 1;
2849                 # Reset all the symbol data.
2850                 $symbol = "";
2851                 $in_description = 0;
2852                 $in_return = 0;
2853                 $in_since = 0;
2854                 $in_deprecated = 0;
2855                 $in_stability = 0;
2856                 $description = "";
2857                 $return_desc = "";
2858                 $return_style = "";
2859                 $since_desc = "";
2860                 $deprecated_desc = "";
2861                 $stability_desc = "";
2862                 $current_param = -1;
2863                 $ignore_broken_returns = 0;
2864                 @params = ();
2865             }
2866             next;
2867         }
2869         # We're in a comment block. Check if we've found the end of it.
2870         if (m%^\s*\*+/%) {
2871             if (!$symbol) {
2872                 print <<EOF;
2873 WARNING: Symbol name not found at the start of the comment block.
2874  $file line $.
2876             } else {
2877                 # Add the return value description onto the end of the params.
2878                 if ($return_desc) {
2879                     push (@params, "Returns");
2880                     push (@params, $return_desc);
2881                     if ($return_style eq 'broken') {
2882                         print <<EOF;
2883 WARNING: Free-form return value description in $symbol.
2884          Use `Returns:' to avoid ambiguities.
2886                     }
2887                 }
2888                 # Convert special SGML characters
2889                 $description = &ConvertSGMLChars ($symbol, $description);
2890                 my $k;
2891                 for ($k = 1; $k <= $#params; $k += 2) {
2892                     $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
2893                 }
2895                 # Handle Section docs
2896                 if ($symbol =~ m/SECTION:\s*(.*)/) {
2897                     my $real_symbol=$1;
2898                     my $k;
2900                     #print "SECTION DOCS found in source for : '$real_symbol'\n";
2901                     $ignore_broken_returns = 1;
2902                     for ($k = 0; $k <= $#params; $k += 2) {
2903                         #print "   '".$params[$k]."'\n";
2904                         $params[$k] = "\L$params[$k]";
2905                         if ($params[$k] eq "short_description") {
2906                             $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Short_Description"}=$params[$k+1];
2907                         } elsif ($params[$k] eq "see_also") {
2908                             $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:See_Also"}=$params[$k+1];
2909                         } elsif ($params[$k] eq "title") {
2910                             $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Title"}=$params[$k+1];
2911                         } elsif ($params[$k] eq "stability") {
2912                             $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Stability_Level"}=$params[$k+1];
2913                         } elsif ($params[$k] eq "section_id") {
2914                             $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Section_Id"}=$params[$k+1];
2915                         } elsif ($params[$k] eq "include") {
2916                             $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Include"}=$params[$k+1];
2917                         }
2918                     }
2919                     $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
2920                 } else {
2921                     #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
2922                     $SourceSymbolDocs{$symbol} = $description;
2923                     $SourceSymbolParams{$symbol} = [ @params ];
2924                 }
2926                 if ($since_desc) {
2927                     $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
2928                 }
2930                 if ($stability_desc) {
2931                     $stability_desc = &ParseStabilityLevel($stability_desc, "Stability level for $symbol");
2932                     $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
2933                 }
2935                 if ($deprecated_desc) {
2936                     if (exists $Deprecated{$symbol}) {
2937                     }
2938                     else {
2939                         print <<EOF;
2940 WARNING: $symbol is deprecated in the inline comments
2941          but no deprecation guards were found around the declaration.
2942          (See the --deprecated-guards option for gtkdoc-scan.)
2944                     }
2945                     $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
2946                 }
2947             }
2949             $in_comment_block = 0;
2950             next;
2951         }
2953         # Get rid of ' * ' at start of every line in the comment block.
2954         s%^\s*\*\s?%%;
2955         # But make sure we don't get rid of the newline at the end.
2956         if (!$_) {
2957             $_ = "\n";
2958         }
2959 #       print "DEBUG: scanning :$_";
2961         # If we haven't found the symbol name yet, look for it.
2962         if (!$symbol) {
2963             if (m%^\s*(SECTION:\s*\S+)%) {
2964                 $symbol = $1;
2965                 #print "SECTION DOCS found in source for : '$symbol'\n";
2966                 $ignore_broken_returns = 1;
2967             } elsif (m%^\s*([\w:-]*\w)\s*:?%) {
2968                 $symbol = $1;
2969                 #print "SYMBOL DOCS found in source for : '$symbol'\n";
2970             }
2971             next;
2972         }
2974         # If we're in the return value description, add it to the end.
2975         if ($in_return) {
2976             # If we find another valid returns line, we assume that the first
2977             # one was really part of the description.
2978             if (m/^\s*(returns:|return\s+value:)/i) {
2979                 $description .= $return_start . $return_desc;
2980                 $return_start = $1;
2981                 if ($return_style eq 'sane') {
2982                     print <<EOF
2983 WARNING: Multiple Returns for $symbol
2985                 }
2986                 $return_style = 'sane';
2987                 $ignore_broken_returns = 1;
2988                 $return_desc = $';
2989             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
2990                 $description .= $return_start . $return_desc;
2991                 $return_start = $1;
2992                 $return_style = 'broken';
2993                 $return_desc = $';
2994             } elsif (m%^\s*since:%i) {
2995                 $since_desc = $';
2996                 $in_since = 1;
2997                 $in_return = 0;
2998             } elsif (m%^\s*stability:%i) {
2999                 $stability_desc = $';
3000                 $in_stability = 1;
3001                 $in_return = 0;
3002             } elsif (m%^\s*deprecated:%i) {
3003                 $deprecated_desc = $';
3004                 $in_deprecated = 1;
3005                 $in_return = 0;
3006             } else {
3007                 $return_desc .= $_;
3008             }
3009             next;
3010         }
3012         if ($in_since) {
3013             if (m/^\s*(returns:|return\s+value:)/i) {
3014                 $return_start = $1;
3015                 if ($return_style eq 'sane') {
3016                     print <<EOF
3017 WARNING: Multiple Returns for $symbol
3019                 }
3020                 $return_style = 'sane';
3021                 $ignore_broken_returns = 1;
3022                 $return_desc = $';
3023                 $in_return = 1;
3024                 $in_since = 0;
3025             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3026                 $return_start = $1;
3027                 $return_style = 'broken';
3028                 $return_desc = $';
3029                 $in_return = 1;
3030                 $in_since = 0;
3031             } elsif (m%^\s*deprecated:%i) {
3032                 $deprecated_desc = $';
3033                 $in_deprecated = 1;
3034                 $in_since = 0;
3035             } elsif (m%^\s*stability:%i) {
3036                 $stability_desc = $';
3037                 $in_stability = 1;
3038                 $in_since = 0;
3039             } else {
3040                 $since_desc .= $_;
3041             }
3042             next;
3043         }
3045         if ($in_stability) {
3046             if (m/^\s*(returns:|return\s+value:)/i) {
3047                 $return_start = $1;
3048                 if ($return_style eq 'sane') {
3049                     print <<EOF
3050 WARNING: Multiple Returns for $symbol
3052                 }
3053                 $return_style = 'sane';
3054                 $ignore_broken_returns = 1;
3055                 $return_desc = $';
3056                 $in_return = 1;
3057                 $in_stability = 0;
3058             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3059                 $return_start = $1;
3060                 $return_style = 'broken';
3061                 $return_desc = $';
3062                 $in_return = 1;
3063                 $in_stability = 0;
3064             } elsif (m%^\s*deprecated:%i) {
3065                 $deprecated_desc = $';
3066                 $in_deprecated = 1;
3067                 $in_stability = 0;
3068             } elsif (m%^\s*since:%i) {
3069                 $since_desc = $';
3070                 $in_since = 1;
3071                 $in_stability = 0;
3072             } else {
3073                 $stability_desc .= $_;
3074             }
3075             next;
3076         }
3078         if ($in_deprecated) {
3079             if (m/^\s*(returns:|return\s+value:)/i) {
3080                 $return_start = $1;
3081                 if ($return_style eq 'sane') {
3082                     print <<EOF
3083 WARNING: Multiple Returns for $symbol
3085                 }
3086                 $return_style = 'sane';
3087                 $ignore_broken_returns = 1;
3088                 $return_desc = $';
3089                 $in_return = 1;
3090                 $in_deprecated = 0;
3091             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3092                 $return_start = $1;
3093                 $return_style = 'broken';
3094                 $return_desc = $';
3095                 $in_return = 1;
3096                 $in_deprecated = 0;
3097             } elsif (m%^\s*since:%i) {
3098                 $since_desc = $';
3099                 $in_since = 1;
3100                 $in_deprecated = 0;
3101             } elsif (m%^\s*stability:%i) {
3102                 $stability_desc = $';
3103                 $in_stability = 1;
3104                 $in_deprecated = 0;
3105             } else {
3106                 $deprecated_desc .= $_;
3107             }
3108             next;
3109         }
3111         # If we're in the description part, check for the 'Returns:' line.
3112         # If that isn't found, add the text to the end.
3113         if ($in_description) {
3114             # Get rid of 'Description:'
3115             s%^\s*Description:%%;
3117             if (m/^\s*(returns:|return\s+value:)/i) {
3118                 $return_start = $1;
3119                 if ($return_style eq 'sane') {
3120                     print <<EOF
3121 WARNING: Multiple Returns for $symbol
3123                 }
3124                 $return_style = 'sane';
3125                 $ignore_broken_returns = 1;
3126                 $return_desc = $';
3127                 $in_return = 1;
3128                 next;
3129             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3130                 $return_start = $1;
3131                 $return_style = 'broken';
3132                 $return_desc = $';
3133                 $in_return = 1;
3134                 next;
3135             } elsif (m%^\s*since:%i) {
3136                 $since_desc = $';
3137                 $in_since = 1;
3138                 next;
3139             } elsif (m%^\s*deprecated:%i) {
3140                 $deprecated_desc = $';
3141                 $in_deprecated = 1;
3142                 next;
3143             } elsif (m%^\s*stability:%i) {
3144                 $stability_desc = $';
3145                 $in_stability = 1;
3146                 next;
3147             }
3149             $description .= $_;
3150             next;
3151         }
3153         # We must be in the parameters. Check for the empty line below them.
3154         if (m%^\s*$%) {
3155             $in_description = 1;
3156             next;
3157         }
3159         # Look for a parameter name.
3160         if (m%^\s*@(\S+)\s*:%) {
3161             my $param_name = $1;
3162 #           print "Found parameter: $param_name\n";
3163             # Allow '...' as the Varargs parameter.
3164             if ($param_name eq "...") {
3165                 $param_name = "Varargs";
3166             }
3167             if ("\L$param_name" eq "returns") {
3168                 $return_style = 'sane';
3169                 $ignore_broken_returns = 1;
3170             }
3171             push (@params, $param_name);
3172             push (@params, $');
3173             $current_param += 2;
3174             next;
3175         }
3177         # We must be in the middle of a parameter description, so add it on
3178         # to the last element in @params.
3179         if ($current_param == -1) {
3180             print <<EOF
3181 ERROR parsing comment block file : parameter expected -
3182  $file:$.
3184         } else {
3185             $params[$#params] .= $_;
3186         }
3187     }
3188     close (SRCFILE);
3191 #############################################################################
3192 # Function    : OutputMissingDocumentation
3193 # Description : Outputs report of documentation coverage to a file
3195 # Arguments   : none
3196 #############################################################################
3198 sub OutputMissingDocumentation {
3199      my $n_documented = 0;
3200      my $n_incomplete = 0;
3201      my $total = 0;
3202      my $symbol;
3203      my $percent;
3204      my $msg;
3205      my $buffer = "";
3206      my $buffer_deprecated = "";
3207      my $buffer_descriptions = "";
3209      open (UNDOCUMENTED, ">$ROOT_DIR/$MODULE-undocumented.txt")
3210           || die "Can't create $ROOT_DIR/$MODULE-undocumented.txt";
3212      foreach $symbol (sort (keys (%AllSymbols))) {
3213           if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include)/) {
3214               $total++;
3215               if (exists ($AllDocumentedSymbols{$symbol})) {
3216                   $n_documented++;
3217                   if (exists ($AllIncompleteSymbols{$symbol})) {
3218                       $n_incomplete++;
3219                       $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3220                   }
3221               } elsif (exists $Deprecated{$symbol}) {
3222                   if (exists ($AllIncompleteSymbols{$symbol})) {
3223                       $n_incomplete++;
3224                       $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3225                   } else {
3226                       $buffer_deprecated .= $symbol . "\n";
3227                   }
3228               } else {
3229                   if (exists ($AllIncompleteSymbols{$symbol})) {
3230                       $n_incomplete++;
3231                       $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3232                   } else {
3233                       $buffer .= $symbol . "\n";
3234                   }
3235               }
3236           } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
3237               $total++;
3238               #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
3239               #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
3240               #print "%%%% $symbol : $len1,$len2\n";
3241               if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
3242               || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
3243                   $n_documented++;
3244               } else {
3245                   $symbol =~ m/^.*\/(.*)$/;
3246                   $buffer_descriptions .= $1 . "\n";
3247               }
3248           }
3249      }
3251      $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
3253      if ($total == 0) {
3254           $percent = 100;
3255      } else {
3256           $percent = ($n_documented / $total) * 100.0;
3257      }
3259      printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
3260      print UNDOCUMENTED "$n_documented symbols documented.\n";
3261      print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
3262      print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
3264      print UNDOCUMENTED $buffer;
3266      close (UNDOCUMENTED);
3268      printf (("%.0f%% symbol docs coverage ($n_documented symbols documented, $n_incomplete symbols incomplete, " . ($total - $n_documented) . " not documented)\nSee $MODULE-undocumented.txt for a list of missing docs.\nThe doc coverage percentage doesn't include intro sections.\n"), $percent);
3272 #############################################################################
3273 # Function    : OutputUndeclaredSymbols
3274 # Description : Outputs symbols that are undeclared yet documented to a file
3276 # Arguments   : none
3277 #############################################################################
3279 sub OutputUndeclaredSymbols {
3280     open(UNDECLARED, ">$ROOT_DIR/$MODULE-undeclared.txt")
3281         || die "Can't create $ROOT_DIR/$MODULE-undeclared.txt";
3283     if (%UndeclaredSymbols) {
3284         print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
3285         print UNDECLARED "\n";
3286         print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
3287     }
3288     close(UNDECLARED);
3292 #############################################################################
3293 # Function    : OutputAllSymbols
3294 # Description : Outputs list of all symbols to a file
3296 # Arguments   : none
3297 #############################################################################
3299 sub OutputAllSymbols {
3300      my $n_documented = 0;
3301      my $total = 0;
3302      my $symbol;
3303      my $percent;
3304      my $msg;
3306      open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
3307           || die "Can't create $ROOT_DIR/$MODULE-symbols.txt";
3309      foreach $symbol (sort (keys (%AllSymbols))) {
3310           print SYMBOLS $symbol . "\n"
3311      }
3313      close (SYMBOLS);
3317 #############################################################################
3318 # Function    : MergeSourceDocumentation
3319 # Description : This merges documentation read from a source file into the
3320 #               documentation read in from a template file.
3322 #               Parameter descriptions override any in the template files.
3323 #               Function descriptions are placed before any description from
3324 #               the template files.
3326 # Arguments   : none
3327 #############################################################################
3329 sub MergeSourceDocumentation {
3330     my $symbol;
3331     foreach $symbol (keys (%SymbolDocs)) {
3332         $AllSymbols{$symbol} = 1;
3334         my $have_tmpl_docs = 0;
3336         ## See if the symbol is documented out-of-line
3337         my $tmpl_doc = $SymbolDocs{$symbol};
3338         $tmpl_doc = defined ($tmpl_doc) ? $tmpl_doc : "";
3339         $tmpl_doc =~ s/<\/?[a-z]+>//g;
3340         $tmpl_doc =~ s/\s//g;
3341         if ($tmpl_doc ne "") {
3342             $have_tmpl_docs = 1;
3343         }
3345         if (exists ($SourceSymbolDocs{$symbol})) {
3346             my $src_doc = $SourceSymbolDocs{$symbol};
3347             my $tmpl_doc = $SymbolDocs{$symbol};
3348             my $type = $DeclarationTypes {$symbol};
3350             my $item = "Parameter";
3351             if (defined ($type)) {
3352                 if ($type eq 'STRUCT') {
3353                     $item = "Field";
3354                 } elsif ($type eq 'ENUM') {
3355                     $item = "Value";
3356                 } elsif ($type eq 'UNION') {
3357                     $item = "Field";
3358                 }
3359             } else {
3360                 $type="SIGNAL";
3361             }
3363             $tmpl_doc = defined ($tmpl_doc) ? $tmpl_doc : "";
3364             $src_doc =~ s/^\s+//;
3365             $src_doc =~ s/\s+$//;
3367             # Don't output warnings for overridden titles as titles are
3368             # automatically generated in the -sections.txt file so are often
3369             # overridden.
3370             if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
3371                     print <<EOF;
3372 WARNING: Documentation in template file for $symbol being overridden by inline comments
3374             }
3376             if ($src_doc ne "") {
3377                  $AllDocumentedSymbols{$symbol} = 1;
3378             }
3380             # Convert <!--PARAMETERS--> with any blank lines around it to
3381             # a </para> followed by <!--PARAMETERS--> followed by <para>.
3382             $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
3384             # If there is a blank line, finish the paragraph and start another.
3385             $src_doc = &ConvertBlankLines ($src_doc, $symbol);
3387             if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
3388                 # FIXME: should we check for empty $tmpl_doc ?
3389                 $SymbolDocs{$symbol} = "<para>\n$src_doc</para>\n$tmpl_doc"
3390             } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
3391                 # For the title/summary/see also section docs we don't want to
3392                 # add any <para> tags.
3393                 $SymbolDocs{$symbol} = "$src_doc"
3394             } else {
3395                 $SymbolDocs{$symbol} = "<para>\n$src_doc</para>\n$tmpl_doc";
3396             }
3398             if ($symbol =~ m/.*::.*/) {
3399                 # For signals we prefer the param names from the source docs,
3400                 # since the ones from the templates are likely to contain the
3401                 # artificial argn names which are generated by gtkdoc-scangobj.
3402                 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol}
3403                 # FIXME: we need to check for empty docs here as well!
3404             } else {
3405                 # The templates contain the definitive parameter names and order,
3406                 # so we will not change that. We only override the actual text.
3407                 my $tmpl_params = $SymbolParams{$symbol};
3408                 if (!defined ($tmpl_params)) {
3409                     #print "No merge for $symbol\n";
3410                     next;
3411                 }
3413                 my $params = $SourceSymbolParams{$symbol};
3414                 my $j;
3415                 for ($j = 0; $j <= $#$tmpl_params; $j += 2) {
3416                     my $tmpl_param_name = $$tmpl_params[$j];
3418                     # Allow '...' as the Varargs parameter.
3419                     if ($tmpl_param_name eq "...") {
3420                       $tmpl_param_name = "Varargs";
3421                     }
3423                     # Try to find the param in the source comment documentation.
3424                     my $found = 0;
3425                     my $k;
3426                     for ($k = 0; $k <= $#$params; $k += 2) {
3427                         my $param_name = $$params[$k];
3428                         my $param_desc = $$params[$k + 1];
3430                         # We accept changes in case, since the Gnome source docs
3431                         # contain a lot of these.
3432                         if ("\L$param_name" eq "\L$tmpl_param_name") {
3433                             $found = 1;
3435                             # Override the description.
3436                             $$tmpl_params[$j + 1] = $param_desc ;
3438                             # Set the name to "" to mark it as used.
3439                             $$params[$k] = "";
3440                             last;
3441                         }
3442                     }
3444                     # If it looks like the parameters are there, but not
3445                     # in the right place, try to explain a bit better.
3446                     if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
3447                         print <<EOF;
3448          Parameters must start on the line immediately after the function
3449          or macro name.
3451                     }
3452                 }
3454                 # Now we output a warning if parameters have been described which
3455                 # do not exist.
3456                 for ($j = 0; $j <= $#$params; $j += 2) {
3457                     my $param_name = $$params[$j];
3458                     if ($param_name) {
3459                         # the template builder cannot detect if a macro returns
3460                         # a result or not
3461                         if(($type eq "MACRO") && ($param_name eq "Returns")) {
3462                             next;
3463                         }
3464                         print <<EOF;
3465 WARNING: $item described in source code comment block but does not exist -
3466          $type: $symbol $item: $param_name.
3468                     }
3469                 }
3470             }
3471         } else {
3472             if ($have_tmpl_docs) {
3473                 $AllDocumentedSymbols{$symbol} = 1;
3474             }
3475         }
3476         # if this symbol is documented, check if docs are complete
3477         $tmpl_doc = $SymbolDocs{$symbol};
3478         $tmpl_doc = defined ($tmpl_doc) ? $tmpl_doc : "";
3479         $tmpl_doc =~ s/<\/?[a-z]+>//g;
3480         $tmpl_doc =~ s/\s//g;
3481         if ($tmpl_doc ne "") {
3482             my $tmpl_params = $SymbolParams{$symbol};
3483             if (defined ($tmpl_params)) {
3484                 my $type = $DeclarationTypes {$symbol};
3486                 my $item = "Parameter";
3487                 if (defined ($type)) {
3488                     if ($type eq 'STRUCT') {
3489                         $item = "Field";
3490                     } elsif ($type eq 'ENUM') {
3491                         $item = "Value";
3492                     } elsif ($type eq 'UNION') {
3493                         $item = "Field";
3494                     }
3495                 } else {
3496                     $type="SIGNAL";
3497                 }
3499                 my $j;
3500                 for ($j = 0; $j <= $#$tmpl_params; $j += 2) {
3501                     # Output a warning if the parameter is empty and
3502                     # remember for stats.
3503                     my $tmpl_param_name = $$tmpl_params[$j];
3504                     my $tmpl_param_desc = $$tmpl_params[$j + 1];
3505                     if ($tmpl_param_desc !~ m/\S/) {
3506                         if (exists ($AllIncompleteSymbols{$symbol})) {
3507                             $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
3508                         } else {
3509                             $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
3510                         }
3511 #                        print <<EOF;
3512 #WARNING: $item description missing in source code comment block -
3513 # $type: $symbol $item: $tmpl_param_name.
3514 #EOF
3515                     }
3516                 }
3517             }
3518         }
3519    }
3522 sub IsEmptyDoc {
3523     my ($doc) = @_;
3525     if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
3526         return 1;
3527     } else {
3528         return 0;
3529     }
3533 # This converts blank lines to "</para><para>", but only outside CDATA and
3534 # <programlisting> tags.
3535 sub ConvertBlankLines {
3536     return &ModifyXMLElements ($_[0], $_[1],
3537                                "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
3538                                \&ConvertBlankLinesEndTag,
3539                                \&ConvertBlankLinesCallback);
3543 sub ConvertBlankLinesEndTag {
3544   if ($_[0] eq "<!\[CDATA\[") {
3545     return "]]>";
3546   } elsif ($_[0] eq "|[") {
3547     return "]\\|";
3548   } else {
3549     return "</programlisting>";
3550   }
3553 sub ConvertBlankLinesCallback {
3554   my ($text, $symbol, $tag) = @_;
3556   # If we're not in CDATA or a <programlisting> we convert blank lines so
3557   # they start a new <para>.
3558   if ($tag eq "") {
3559     $text =~ s%\n{2,}%\n</para>\n<para>\n%g;
3560   }
3562   return $text;
3566 #############################################################################
3567 # LIBRARY FUNCTIONS -   These functions are used in both gtkdoc-mkdb and
3568 #                       gtkdoc-mktmpl and should eventually be moved to a
3569 #                       separate library.
3570 #############################################################################
3572 #############################################################################
3573 # Function    : ReadDeclarationsFile
3574 # Description : This reads in a file containing the function/macro/enum etc.
3575 #               declarations.
3577 #               Note that in some cases there are several declarations with
3578 #               the same name, e.g. for conditional macros. In this case we
3579 #               set a flag in the %DeclarationConditional hash so the
3580 #               declaration is not shown in the docs.
3582 #               If a macro and a function have the same name, e.g. for
3583 #               gtk_object_ref, the function declaration takes precedence.
3585 #               Some opaque structs are just declared with 'typedef struct
3586 #               _name name;' in which case the declaration may be empty.
3587 #               The structure may have been found later in the header, so
3588 #               that overrides the empty declaration.
3590 # Arguments   : $file - the declarations file to read
3591 #               $override - if declarations in this file should override
3592 #                       any current declaration.
3593 #############################################################################
3595 sub ReadDeclarationsFile {
3596     my ($file, $override) = @_;
3598     if ($override == 0) {
3599         %Declarations = ();
3600         %DeclarationTypes = ();
3601         %DeclarationConditional = ();
3602         %DeclarationOutput = ();
3603     }
3605     open (INPUT, $file)
3606         || die "Can't open $file";
3607     my $declaration_type = "";
3608     my $declaration_name;
3609     my $declaration;
3610     my $is_deprecated = 0;
3611     while (<INPUT>) {
3612         if (!$declaration_type) {
3613             if (m/^<([^>]+)>/) {
3614                 $declaration_type = $1;
3615                 $declaration_name = "";
3616 #               print "Found declaration: $declaration_type\n";
3617                 $declaration = "";
3618             }
3619         } else {
3620             if (m%^<NAME>(.*)</NAME>%) {
3621                 $declaration_name = $1;
3622             } elsif (m%^<DEPRECATED/>%) {
3623                 $is_deprecated = 1;
3624             } elsif (m%^</$declaration_type>%) {
3625 #               print "Found end of declaration: $declaration_name\n";
3626                 # Check that the declaration has a name
3627                 if ($declaration_name eq "") {
3628                     print "ERROR: $declaration_type has no name $file:$.\n";
3629                 }
3631                 # If the declaration is an empty typedef struct _XXX XXX
3632                 # set the flag to indicate the struct has a typedef.
3633                 if ($declaration_type eq 'STRUCT'
3634                     && $declaration =~ m/^\s*$/) {
3635 #                   print "Struct has typedef: $declaration_name\n";
3636                     $StructHasTypedef{$declaration_name} = 1;
3637                 }
3639                 # Check if the symbol is already defined.
3640                 if (defined ($Declarations{$declaration_name})
3641                     && $override == 0) {
3642                     # Function declarations take precedence.
3643                     if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
3644                         # Ignore it.
3645                     } elsif ($declaration_type eq 'FUNCTION') {
3646                         if ($is_deprecated) {
3647                             $Deprecated{$declaration_name} = "";
3648                         }
3649                         $Declarations{$declaration_name} = $declaration;
3650                         $DeclarationTypes{$declaration_name} = $declaration_type;
3651                     } elsif ($DeclarationTypes{$declaration_name}
3652                               eq $declaration_type) {
3653                         # If the existing declaration is empty, or is just a
3654                         # forward declaration of a struct, override it.
3655                         if ($declaration_type eq 'STRUCT') {
3656                             if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
3657                                 if ($is_deprecated) {
3658                                     $Deprecated{$declaration_name} = "";
3659                                 }
3660                                 $Declarations{$declaration_name} = $declaration;
3661                             } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
3662                                 # Ignore an empty or forward declaration.
3663                             } else {
3664                                 print "WARNING: Structure has multiple definitions: $declaration_name\n";
3665                             }
3667                         } else {
3668                             # set flag in %DeclarationConditional hash for
3669                             # multiply defined macros/typedefs.
3670                             $DeclarationConditional{$declaration_name} = 1;
3671                         }
3672                     } else {
3673                         print "ERROR: $declaration_name has multiple definitions\n";
3674                     }
3675                 } else {
3676                     if ($is_deprecated) {
3677                         $Deprecated{$declaration_name} = "";
3678                     }
3679                     $Declarations{$declaration_name} = $declaration;
3680                     $DeclarationTypes{$declaration_name} = $declaration_type;
3681                 }
3683                 $declaration_type = "";
3684                 $is_deprecated = 0;
3685             } else {
3686                 $declaration .= $_;
3687             }
3688         }
3689     }
3690     close (INPUT);
3694 #############################################################################
3695 # Function    : ReadSignalsFile
3696 # Description : This reads in an existing file which contains information on
3697 #               all GTK signals. It creates the arrays @SignalNames and
3698 #               @SignalPrototypes containing info on the signals. The first
3699 #               line of the SignalPrototype is the return type of the signal
3700 #               handler. The remaining lines are the parameters passed to it.
3701 #               The last parameter, "gpointer user_data" is always the same
3702 #               so is not included.
3703 # Arguments   : $file - the file containing the signal handler prototype
3704 #                       information.
3705 #############################################################################
3707 sub ReadSignalsFile {
3708     my ($file) = @_;
3710     my $in_signal = 0;
3711     my $signal_object;
3712     my $signal_name;
3713     my $signal_returns;
3714     my $signal_flags;
3715     my $signal_prototype;
3717     # Reset the signal info.
3718     @SignalObjects = ();
3719     @SignalNames = ();
3720     @SignalReturns = ();
3721     @SignalFlags = ();
3722     @SignalPrototypes = ();
3724     if (! -f $file) {
3725         return;
3726     }
3727     if (!open (INPUT, $file)) {
3728         warn "Can't open $file - skipping signals\n";
3729         return;
3730     }
3731     while (<INPUT>) {
3732         if (!$in_signal) {
3733             if (m/^<SIGNAL>/) {
3734                 $in_signal = 1;
3735                 $signal_object = "";
3736                 $signal_name = "";
3737                 $signal_returns = "";
3738                 $signal_prototype = "";
3739             }
3740         } else {
3741             if (m/^<NAME>(.*)<\/NAME>/) {
3742                 $signal_name = $1;
3743                 if ($signal_name =~ m/^(.*)::(.*)$/) {
3744                     $signal_object = $1;
3745                     ($signal_name = $2) =~ s/_/-/g;
3746 #                   print "Found signal: $signal_name\n";
3747                 } else {
3748                     print "Invalid signal name: $signal_name\n";
3749                 }
3750             } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
3751                 $signal_returns = $1;
3752             } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
3753                 $signal_flags = $1;
3754             } elsif (m%^</SIGNAL>%) {
3755 #               print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
3756                 push (@SignalObjects, $signal_object);
3757                 push (@SignalNames, $signal_name);
3758                 push (@SignalReturns, $signal_returns);
3759                 push (@SignalFlags, $signal_flags);
3760                 push (@SignalPrototypes, $signal_prototype);
3761                 $in_signal = 0;
3762             } else {
3763                 $signal_prototype .= $_;
3764             }
3765         }
3766     }
3767     close (INPUT);
3771 #############################################################################
3772 # Function    : ReadTemplateFile
3773 # Description : This reads in the manually-edited documentation file
3774 #               corresponding to the file currently being created, so we can
3775 #               insert the documentation at the appropriate places.
3776 #               It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
3777 #               is a hash of arrays.
3778 #               NOTE: This function is duplicated in gtkdoc-mkdb (but
3779 #               slightly different).
3780 # Arguments   : $docsfile - the template file to read in.
3781 #               $skip_unused_params - 1 if the unused parameters should be
3782 #                       skipped.
3783 #############################################################################
3785 sub ReadTemplateFile {
3786     my ($docsfile, $skip_unused_params) = @_;
3788     my $template = "$docsfile.sgml";
3789 #    print "Reading $template\n";
3790     if (! -f $template) {
3791         print "File doesn't exist: $template\n";
3792         return;
3793     }
3795     my $current_type = "";      # Type of symbol being read.
3796     my $current_symbol = "";    # Name of symbol being read.
3797     my $symbol_doc = "";                # Description of symbol being read.
3798     my @params;                 # Parameter names and descriptions of current
3799                                 #   function/macro/function typedef.
3800     my $current_param = -1;     # Index of parameter currently being read.
3801                                 #   Note that the param array contains pairs
3802                                 #   of param name & description.
3803     my $in_unused_params = 0;   # True if we are reading in the unused params.
3804     my $in_deprecated = 0;
3805     my $in_since = 0;
3806     my $in_stability = 0;
3808     open (DOCS, "$template")
3809         || die "Can't open file $template: $!";
3810     while (<DOCS>) {
3811         if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
3812             my $type = $1;
3813             my $symbol = $2;
3814             if ($symbol eq "Title"
3815                 || $symbol eq "Short_Description"
3816                 || $symbol eq "Long_Description"
3817                 || $symbol eq "See_Also"
3818                 || $symbol eq "Stability_Level"
3819                 || $symbol eq "Include") {
3821                 $symbol = $docsfile . ":" . $symbol;
3822             }
3824 #           print "Found symbol: $symbol\n";
3826             # Store previous symbol, but remove any trailing blank lines.
3827             if ($current_symbol ne "") {
3828                 $symbol_doc =~ s/\s+$//;
3829                 $SymbolTypes{$current_symbol} = $current_type;
3830                 $SymbolDocs{$current_symbol} = $symbol_doc;
3832                 # Check that the stability level is valid.
3833                 if ($StabilityLevel{$current_symbol}) {
3834                     $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, "Stability level for $current_symbol");
3835                 }
3837                 if ($current_param >= 0) {
3838                     $SymbolParams{$current_symbol} = [ @params ];
3839                 } else {
3840                     # Delete any existing params in case we are overriding a
3841                     # previously read template.
3842                     delete $SymbolParams{$current_symbol};
3843                 }
3844             }
3845             $current_type = $type;
3846             $current_symbol = $symbol;
3847             $current_param = -1;
3848             $in_unused_params = 0;
3849             $in_deprecated = 0;
3850             $in_since = 0;
3851             $in_stability = 0;
3852             $symbol_doc = "";
3853             @params = ();
3855         } elsif (m/^<!-- # Unused Parameters # -->/) {
3856 #           print "DEBUG: Found unused parameters\n";
3857             $in_unused_params = 1;
3858             next;
3860         } elsif ($in_unused_params && $skip_unused_params) {
3861             # When outputting the DocBook we skip unused parameters.
3862 #           print "DEBUG: Skipping unused param: $_";
3863             next;
3865         } else {
3866             # Check if param found. Need to handle "..." and "format...".
3867             if (s/^\@([\w\.]+):\040?//) {
3868                 my $param_name = $1;
3869                 # Allow variations of 'Returns'
3870                 if ($param_name =~ m/^[Rr]eturns?$/) {
3871                     $param_name = "Returns";
3872                 }
3873 #               print "Found param for symbol $current_symbol : '$param_name'= '$_'\n";
3875                 if ($param_name eq "Deprecated") {
3876                     $in_deprecated = 1;
3877                     $Deprecated{$current_symbol} = $_;
3878                 } elsif ($param_name eq "Since") {
3879                     $in_since = 1;
3880                     $Since{$current_symbol} = $_;
3881                 } elsif ($param_name eq "Stability") {
3882                     $in_stability = 1;
3883                     $StabilityLevel{$current_symbol} = $_;
3884                 } else {
3885                     push (@params, $param_name);
3886                     push (@params, $_);
3887                     $current_param += 2;
3888                 }
3889             } else {
3890                 if ($in_deprecated) {
3891                     $Deprecated{$current_symbol} .= $_;
3892                 } elsif ($in_since) {
3893                     $Since{$current_symbol} .= $_;
3894                 } elsif ($in_stability) {
3895                     $StabilityLevel{$current_symbol} .= $_;
3896                 } elsif ($current_param >= 0) {
3897                     $params[$current_param] .= $_;
3898                 } else {
3899                     $symbol_doc .= $_;
3900                 }
3901             }
3902         }
3903     }
3905     # Remember to finish the current symbol doccs.
3906     if ($current_symbol ne "") {
3908         $symbol_doc =~ s/\s+$//;
3909         $SymbolTypes{$current_symbol} = $current_type;
3910         $SymbolDocs{$current_symbol} = $symbol_doc;
3912         # Check that the stability level is valid.
3913         if ($StabilityLevel{$current_symbol}) {
3914             $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, "Stability level for $current_symbol");
3915         }
3917         if ($current_param >= 0) {
3918             $SymbolParams{$current_symbol} = [ @params ];
3919         } else {
3920             # Delete any existing params in case we are overriding a
3921             # previously read template.
3922             delete $SymbolParams{$current_symbol};
3923         }
3924     }
3926     close (DOCS);
3930 #############################################################################
3931 # Function    : ReadObjectHierarchy
3932 # Description : This reads in the $MODULE-hierarchy.txt file containing all
3933 #               the GtkObject subclasses described in this module (and their
3934 #               ancestors).
3935 #               It places them in the @Objects array, and places their level
3936 #               in the widget hierarchy in the @ObjectLevels array, at the
3937 #               same index. GtkObject, the root object, has a level of 1.
3939 #               FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
3940 #               as it goes along, this should be split out into a separate
3941 #               function.
3943 # Arguments   : none
3944 #############################################################################
3946 sub ReadObjectHierarchy {
3947     @Objects = ();
3948     @ObjectLevels = ();
3950     if (! -f $OBJECT_TREE_FILE) {
3951         return;
3952     }
3953     if (!open (INPUT, $OBJECT_TREE_FILE)) {
3954         warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
3955         return;
3956     }
3958     my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
3959     my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
3960     my $tree_header = $doctype_header;
3961     $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
3963     open (OUTPUT, ">$new_tree_index")
3964         || die "Can't create $new_tree_index";
3965     print (OUTPUT "$tree_header<screen>\n");
3967     # Only emit objects if they are supposed to be documented, or if
3968     # they have documented children. To implement this, we maintain a
3969     # stack of pending objects which will be emitted if a documented
3970     # child turns up.
3971     my @pending_objects = ();
3972     my @pending_levels = ();
3973     while (<INPUT>) {
3974         if (m/\S+/) {
3975             my $object = $&;
3976             my $level = (length($`)) / 2 + 1;
3977             my $xref = "";
3979             while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
3980                 my $pobject = pop(@pending_objects);
3981                 my $plevel = pop(@pending_levels);
3982             }
3984             push (@pending_objects, $object);
3985             push (@pending_levels, $level);
3987             if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
3988                 while ($#pending_levels >= 0) {
3989                     $object = shift @pending_objects;
3990                     $level = shift @pending_levels;
3991                     $xref = &MakeXRef ($object);
3993                     print (OUTPUT ' ' x ($level * 4), "$xref\n");
3994                     push (@Objects, $object);
3995                     push (@ObjectLevels, $level);
3996                 }
3997             }
3998         }
3999     }
4000     print (OUTPUT "</screen>\n");
4002     close (INPUT);
4003     close (OUTPUT);
4005     &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
4007     &OutputObjectList;
4010 #############################################################################
4011 # Function    : ReadInterfaces
4012 # Description : This reads in the $MODULE.interfaces file.
4014 # Arguments   : none
4015 #############################################################################
4017 sub ReadInterfaces {
4018     %Interfaces = ();
4020     if (! -f $INTERFACES_FILE) {
4021         return;
4022     }
4023     if (!open (INPUT, $INTERFACES_FILE)) {
4024         warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
4025         return;
4026     }
4028     while (<INPUT>) {
4029        chomp;
4030        my ($object, @ifaces) = split;
4031        if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
4032            my @knownIfaces = ();
4034            # filter out private interfaces, but leave foreign interfaces
4035            foreach my $iface (@ifaces) {
4036                if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
4037                    push (@knownIfaces, $iface);
4038                }
4039              }
4041            $Interfaces{$object} = join(' ', @knownIfaces);
4042        }
4043     }
4044     close (INPUT);
4047 #############################################################################
4048 # Function    : ReadPrerequisites
4049 # Description : This reads in the $MODULE.prerequisites file.
4051 # Arguments   : none
4052 #############################################################################
4054 sub ReadPrerequisites {
4055     %Prerequisites = ();
4057     if (! -f $PREREQUISITES_FILE) {
4058         return;
4059     }
4060     if (!open (INPUT, $PREREQUISITES_FILE)) {
4061         warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
4062         return;
4063     }
4065     while (<INPUT>) {
4066        chomp;
4067        my ($iface, @prereqs) = split;
4068        if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
4069            my @knownPrereqs = ();
4071            # filter out private prerequisites, but leave foreign prerequisites
4072            foreach my $prereq (@prereqs) {
4073                if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
4074                   push (@knownPrereqs, $prereq);
4075                }
4076            }
4078            $Prerequisites{$iface} = join(' ', @knownPrereqs);
4079        }
4080     }
4081     close (INPUT);
4084 #############################################################################
4085 # Function    : ReadArgsFile
4086 # Description : This reads in an existing file which contains information on
4087 #               all GTK args. It creates the arrays @ArgObjects, @ArgNames,
4088 #               @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
4089 #               on the args.
4090 # Arguments   : $file - the file containing the arg information.
4091 #############################################################################
4093 sub ReadArgsFile {
4094     my ($file) = @_;
4096     my $in_arg = 0;
4097     my $arg_object;
4098     my $arg_name;
4099     my $arg_type;
4100     my $arg_flags;
4101     my $arg_nick;
4102     my $arg_blurb;
4103     my $arg_default;
4104     my $arg_range;
4106     # Reset the args info.
4107     @ArgObjects = ();
4108     @ArgNames = ();
4109     @ArgTypes = ();
4110     @ArgFlags = ();
4111     @ArgNicks = ();
4112     @ArgBlurbs = ();
4113     @ArgDefaults = ();
4114     @ArgRanges = ();
4116     if (! -f $file) {
4117         return;
4118     }
4119     if (!open (INPUT, $file)) {
4120         warn "Can't open $file - skipping args\n";
4121         return;
4122     }
4123     while (<INPUT>) {
4124         if (!$in_arg) {
4125             if (m/^<ARG>/) {
4126                 $in_arg = 1;
4127                 $arg_object = "";
4128                 $arg_name = "";
4129                 $arg_type = "";
4130                 $arg_flags = "";
4131                 $arg_nick = "";
4132                 $arg_blurb = "";
4133                 $arg_default = "";
4134                 $arg_range = "";
4135             }
4136         } else {
4137             if (m/^<NAME>(.*)<\/NAME>/) {
4138                 $arg_name = $1;
4139                 if ($arg_name =~ m/^(.*)::(.*)$/) {
4140                     $arg_object = $1;
4141                     ($arg_name = $2) =~ s/_/-/g;
4142 #                   print "Found arg: $arg_name\n";
4143                 } else {
4144                     print "Invalid arg name: $arg_name\n";
4145                 }
4146             } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
4147                 $arg_type = $1;
4148             } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
4149                 $arg_range = $1;
4150             } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4151                 $arg_flags = $1;
4152             } elsif (m/^<NICK>(.*)<\/NICK>/) {
4153                 $arg_nick = $1;
4154             } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
4155                 $arg_blurb = $1;
4156                 if ($arg_blurb eq "(null)") {
4157                   $arg_blurb = "";
4158                   print <<EOF;
4159 WARNING: Property ${arg_object}:${arg_name} has no documentation.
4161                 }
4162             } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
4163                 $arg_default = $1;
4164             } elsif (m%^</ARG>%) {
4165 #               print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
4166                 push (@ArgObjects, $arg_object);
4167                 push (@ArgNames, $arg_name);
4168                 push (@ArgTypes, $arg_type);
4169                 push (@ArgRanges, $arg_range);
4170                 push (@ArgFlags, $arg_flags);
4171                 push (@ArgNicks, $arg_nick);
4172                 push (@ArgBlurbs, $arg_blurb);
4173                 push (@ArgDefaults, $arg_default);
4174                 $in_arg = 0;
4175             }
4176         }
4177     }
4178     close (INPUT);
4182 #############################################################################
4183 # Function    : CheckIsObject
4184 # Description : Returns 1 if the given name is a GtkObject or a subclass.
4185 #               It uses the global @Objects array.
4186 #               Note that the @Objects array only contains classes in the
4187 #               current module and their ancestors - not all GTK classes.
4188 # Arguments   : $name - the name to check.
4189 #############################################################################
4191 sub CheckIsObject {
4192     my ($name) = @_;
4194     my $object;
4195     foreach $object (@Objects) {
4196         if ($object eq $name) {
4197             return 1;
4198         }
4199     }
4200     return 0;
4204 #############################################################################
4205 # Function    : MakeReturnField
4206 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
4207 # Arguments   : $str - the string to pad.
4208 #############################################################################
4210 sub MakeReturnField {
4211     my ($str) = @_;
4213     return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));