mkdb: do strip all tags when checking for empty docs, but don't reset tmpl docs
[gtk-doc.git] / gtkdoc-mkdb.in
blobd29bc6bca2a455458b7eac49fbf89996e67fd427
1 #!@PERL@ -w
2 # -*- cperl -*-
4 # gtk-doc - GTK DocBook documentation generator.
5 # Copyright (C) 1998  Damon Chaplin
6 #               2007,2008,2009  Stefan Kost
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #############################################################################
24 # Script      : gtkdoc-mkdb
25 # Description : This creates the DocBook files from the edited templates.
26 #############################################################################
28 use strict;
29 use Getopt::Long;
31 push @INC, '@PACKAGE_DATA_DIR@';
32 require "gtkdoc-common.pl";
34 # Options
36 # name of documentation module
37 my $MODULE;
38 my $TMPL_DIR;
39 my $SGML_OUTPUT_DIR;
40 my @SOURCE_DIRS;
41 my $SOURCE_SUFFIXES = "";
42 my $IGNORE_FILES = "";
43 my $PRINT_VERSION;
44 my $PRINT_HELP;
45 my $MAIN_SGML_FILE;
46 my $EXPAND_CONTENT_FILES = "";
47 my $INLINE_MARKUP_MODE;
48 my $DEFAULT_STABILITY;
49 my $DEFAULT_INCLUDES;
50 my $OUTPUT_FORMAT;
51 my $NAME_SPACE = "";
52 my $OUTPUT_ALL_SYMBOLS;
53 my $OUTPUT_SYMBOLS_WITHOUT_SINCE;
55 my %optctl = ('module' => \$MODULE,
56               'source-dir' => \@SOURCE_DIRS,
57               'source-suffixes' => \$SOURCE_SUFFIXES,
58               'ignore-files' => \$IGNORE_FILES,
59               'output-dir' => \$SGML_OUTPUT_DIR,
60               'tmpl-dir' => \$TMPL_DIR,
61               'version' => \$PRINT_VERSION,
62               'help' => \$PRINT_HELP,
63               'main-sgml-file' => \$MAIN_SGML_FILE,
64               'expand-content-files' => \$EXPAND_CONTENT_FILES,
65               'sgml-mode' => \$INLINE_MARKUP_MODE,
66               'xml-mode' => \$INLINE_MARKUP_MODE,
67               'default-stability' => \$DEFAULT_STABILITY,
68               'default-includes' => \$DEFAULT_INCLUDES,
69               'output-format' => \$OUTPUT_FORMAT,
70               'name-space' => \$NAME_SPACE,
71               'outputallsymbols' => \$OUTPUT_ALL_SYMBOLS,
72               'outputsymbolswithoutsince' => \$OUTPUT_SYMBOLS_WITHOUT_SINCE
73               );
74 GetOptions(\%optctl, "module=s", "source-dir:s", "source-suffixes:s", 
75     "ignore-files:s", "output-dir:s", "tmpl-dir:s", "version", "outputallsymbols",
76     "outputsymbolswithoutsince",
77     "expand-content-files:s", "main-sgml-file:s", "extra-db-files:s", "help",
78     "sgml-mode", "xml-mode", "default-stability:s", "default-includes:s", 
79     "output-format:s", "name-space:s");
81 if ($PRINT_VERSION) {
82     print "@VERSION@\n";
83     exit 0;
86 if (!$MODULE) {
87     $PRINT_HELP = 1;
90 if ($DEFAULT_STABILITY && $DEFAULT_STABILITY ne "Stable"
91     && $DEFAULT_STABILITY ne "Private" && $DEFAULT_STABILITY ne "Unstable") {
92     $PRINT_HELP = 1;
95 if ($PRINT_HELP) {
96     print <<EOF;
97 gtkdoc-mkdb version @VERSION@ - generate docbook files
99 --module=MODULE_NAME       Name of the doc module being parsed
100 --source-dir=DIRNAME       Directories which contain inline reference material
101 --source-suffixes=SUFFIXES Suffixes of source files to scan, comma-separated
102 --ignore-files=FILES       Files or directories which should not be scanned
103                            May be used more than once for multiple directories
104 --output-dir=DIRNAME       Directory to put the generated DocBook files in
105 --tmpl-dir=DIRNAME         Directory in which template files may be found
106 --main-sgml-file=FILE      File containing the toplevel DocBook file.
107 --expand-content-files=FILES Extra DocBook files to expand abbreviations in.
108 --output-format=FORMAT     Format to use for the generated docbook, XML or SGML.
109 --{xml,sgml}-mode          Allow DocBook markup in inline documentation.
110 --default-stability=LEVEL  Specify default stability Level. Valid values are
111                            Stable, Unstable, or Private.
112 --default-includes=FILENAMES Specify default includes for section Synopsis
113 --name-space=NS            Omit namespace in index.
114 --version                  Print the version of this program
115 --help                     Print this help
117     exit 0;
120 my ($empty_element_end, $doctype_header);
122 # autodetect output format
123 if (! defined($OUTPUT_FORMAT) || ($OUTPUT_FORMAT eq "")) {
124     if (!$MAIN_SGML_FILE) {
125         if (-e "${MODULE}-docs.xml") {
126             $OUTPUT_FORMAT = "xml";
127         } else {
128             $OUTPUT_FORMAT = "sgml";
129         }
130     } else {
131         if ($MAIN_SGML_FILE =~ m/.*\.(.*ml)$/i) {
132             $OUTPUT_FORMAT = lc($1);
133         }
134     }
135     
136 } else {
137     $OUTPUT_FORMAT = lc($OUTPUT_FORMAT);
140 #print "DEBUG: output-format: [$OUTPUT_FORMAT]\n";
142 if ($OUTPUT_FORMAT eq "xml") {
143     if (!$MAIN_SGML_FILE) {
144         # backwards compatibility
145         if (-e "${MODULE}-docs.sgml") {
146             $MAIN_SGML_FILE = "${MODULE}-docs.sgml";
147         } else {
148             $MAIN_SGML_FILE = "${MODULE}-docs.xml";
149         }
150     }
151     $empty_element_end = "/>";
153     if (-e $MAIN_SGML_FILE) {
154         open(INPUT, "<$MAIN_SGML_FILE") || die "Can't open $MAIN_SGML_FILE";
155         $doctype_header = "";
156         while (<INPUT>) {
157             if (/^\s*<(book|chapter|article)/) {
158                 # check that the top-level tag or the doctype decl contain the xinclude namespace decl
159                 if (($_ !~ m/http:\/\/www.w3.org\/200[13]\/XInclude/) && ($doctype_header !~ m/http:\/\/www.w3.org\/200[13]\/XInclude/m)) {
160                     $doctype_header = "";
161                 }
162                 last;
163             }
164             $doctype_header .= $_;
165         }
166         close(INPUT);
167         $doctype_header =~ s/<!DOCTYPE \w+/<!DOCTYPE refentry/;
168         # if there are SYSTEM ENTITIES here, we should prepend "../" to the path
169         # FIXME: not sure if we can do this now, as people already work-around the problem
170         # $doctype_header =~ s#<!ENTITY % ([a-zA-Z-]+) SYSTEM \"([^/][a-zA-Z./]+)\">#<!ENTITY % $1 SYSTEM \"../$2\">#g;
171     } else {
172         $doctype_header =
173 "<?xml version=\"1.0\"?>\n" .
174 "<!DOCTYPE refentry PUBLIC \"-//OASIS//DTD DocBook XML V4.3//EN\"\n" .
175 "               \"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd\"\n" .
176 "[\n" .
177 "  <!ENTITY % local.common.attrib \"xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'\">\n" .
178 "]>\n";
179     }
180 } else {
181     if (!$MAIN_SGML_FILE) {
182         $MAIN_SGML_FILE = "${MODULE}-docs.sgml";
183     }
184     $empty_element_end = ">";
185     $doctype_header = "";
188 my $ROOT_DIR = ".";
190 # All the files are written in subdirectories beneath here.
191 $TMPL_DIR = $TMPL_DIR ? $TMPL_DIR : "$ROOT_DIR/tmpl";
193 # This is where we put all the DocBook output.
194 $SGML_OUTPUT_DIR = $SGML_OUTPUT_DIR ? $SGML_OUTPUT_DIR : "$ROOT_DIR/$OUTPUT_FORMAT";
196 # This file contains the object hierarchy.
197 my $OBJECT_TREE_FILE = "$ROOT_DIR/$MODULE.hierarchy";
199 # This file contains the interfaces.
200 my $INTERFACES_FILE = "$ROOT_DIR/$MODULE.interfaces";
202 # This file contains the prerequisites.
203 my $PREREQUISITES_FILE = "$ROOT_DIR/$MODULE.prerequisites";
205 # This file contains signal arguments and names.
206 my $SIGNALS_FILE = "$ROOT_DIR/$MODULE.signals";
208 # The file containing Arg information.
209 my $ARGS_FILE = "$ROOT_DIR/$MODULE.args";
211 # These global arrays store information on signals. Each signal has an entry
212 # in each of these arrays at the same index, like a multi-dimensional array.
213 my @SignalObjects;      # The GtkObject which emits the signal.
214 my @SignalNames;        # The signal name.
215 my @SignalReturns;      # The return type.
216 my @SignalFlags;        # Flags for the signal
217 my @SignalPrototypes;   # The rest of the prototype of the signal handler.
219 # These global arrays store information on Args. Each Arg has an entry
220 # in each of these arrays at the same index, like a multi-dimensional array.
221 my @ArgObjects;         # The GtkObject which has the Arg.
222 my @ArgNames;           # The Arg name.
223 my @ArgTypes;           # The Arg type - gint, GtkArrowType etc.
224 my @ArgFlags;           # How the Arg can be used - readable/writable etc.
225 my @ArgNicks;           # The nickname of the Arg.
226 my @ArgBlurbs;          # Docstring of the Arg.
227 my @ArgDefaults;        # Default value of the Arg.
228 my @ArgRanges;          # The range of the Arg type
229 # These global hashes store declaration info keyed on a symbol name.
230 my %Declarations;
231 my %DeclarationTypes;
232 my %DeclarationConditional;
233 my %DeclarationOutput;
234 my %Deprecated;
235 my %Since;
236 my %StabilityLevel;
237 my %StructHasTypedef;
239 # These global hashes store the existing documentation.
240 my %SymbolDocs;
241 my %SymbolTypes;
242 my %SymbolParams;
243 my %SymbolSourceFile;
244 my %SymbolSourceLine;
246 # These global hashes store documentation scanned from the source files.
247 my %SourceSymbolDocs;
248 my %SourceSymbolParams;
249 my %SourceSymbolSourceFile;
250 my %SourceSymbolSourceLine;
252 # all documentation goes in here, so we can do coverage analysis
253 my %AllSymbols;
254 my %AllIncompleteSymbols;
255 my %AllUnusedSymbols;
256 my %AllDocumentedSymbols;
258 # Undeclared yet documented symbols
259 my %UndeclaredSymbols;
261 # These global arrays store GObject, subclasses and the hierarchy.
262 my @Objects;
263 my @ObjectLevels;
265 my %Interfaces;
266 my %Prerequisites;
268 # holds the symbols which are mentioned in $MODULE-sections.txt and in which
269 # section they are defined
270 my %KnownSymbols;
271 my %SymbolSection;
272 my %SymbolSectionId;
274 # collects index entries
275 my %IndexEntriesFull;
276 my %IndexEntriesSince;
277 my %IndexEntriesDeprecated;
279 # Standard C preprocessor directives, which we ignore for '#' abbreviations.
280 my %PreProcessorDirectives;
281 $PreProcessorDirectives{"assert"} = 1;
282 $PreProcessorDirectives{"define"} = 1;
283 $PreProcessorDirectives{"elif"} = 1;
284 $PreProcessorDirectives{"else"} = 1;
285 $PreProcessorDirectives{"endif"} = 1;
286 $PreProcessorDirectives{"error"} = 1;
287 $PreProcessorDirectives{"if"} = 1;
288 $PreProcessorDirectives{"ifdef"} = 1;
289 $PreProcessorDirectives{"ifndef"} = 1;
290 $PreProcessorDirectives{"include"} = 1;
291 $PreProcessorDirectives{"line"} = 1;
292 $PreProcessorDirectives{"pragma"} = 1;
293 $PreProcessorDirectives{"unassert"} = 1;
294 $PreProcessorDirectives{"undef"} = 1;
295 $PreProcessorDirectives{"warning"} = 1;
297 # remember used annotation (to write minimal glossary)
298 my %AnnotationsUsed;
300 # the annotations are defined at:
301 # http://live.gnome.org/GObjectIntrospection/Annotations
302 my %AnnotationDefinition = (
303     'allow-none' => "NULL is ok, both for passing and for returning.",
304     'array' => "Parameter points to an array of items.",
305     'default' => "Default parameter value (for in case the <acronym>shadows</acronym>-to function has less parameters).",
306     'element-type' => "Generics and defining elements of containers and arrays.",
307     'error-domains' => "Typed errors. Similar to throws in Java.",
308     'in' => "Parameter for input. Default is <acronym>transfer none</acronym>.",
309     'inout' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
310     'in-out' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
311     'not-error' => "A GError parameter is not to be handled like a normal GError.",
312     'out' => "Parameter for returning results. Default is <acronym>transfer full</acronym>.",
313     'transfer container' => "Free data container after the code is done.",
314     'transfer full' => "Free data after the code is done.",
315     'transfer none' => "Don't free data after the code is done.",
316     'scope call' => "The callback is valid only during the call to the method.",
317     'scope async' => "The callback is valid until first called.",
318     'scope notified' => "The callback is valid until the GDestroyNotify argument is called.",
319     'type' => "Override the parsed C type with given type"
322 # Create the root DocBook output directory if it doens't exist.
323 if (! -e $SGML_OUTPUT_DIR) {
324     mkdir ("$SGML_OUTPUT_DIR", 0777)
325         || die "Can't create directory: $SGML_OUTPUT_DIR";
328 # Function and other declaration output settings.
329 my $RETURN_TYPE_FIELD_WIDTH = 20;
330 my $SYMBOL_FIELD_WIDTH = 36;
331 my $SIGNAL_FIELD_WIDTH = 16;
332 my $PARAM_FIELD_COUNT = 2;
334 &ReadKnownSymbols ("$ROOT_DIR/$MODULE-sections.txt");
335 &ReadSignalsFile ($SIGNALS_FILE);
336 &ReadArgsFile ($ARGS_FILE);
337 &ReadObjectHierarchy;
338 &ReadInterfaces;
339 &ReadPrerequisites;
341 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-decl.txt", 0);
342 if (-f "$ROOT_DIR/$MODULE-overrides.txt") {
343     &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-overrides.txt", 1);
346 for my $dir (@SOURCE_DIRS) {
347     &ReadSourceDocumentation ($dir);
350 my $changed = &OutputSGML ("$ROOT_DIR/$MODULE-sections.txt");
352 # If any of the DocBook SGML files have changed, update the timestamp file (so
353 # it can be used for Makefile dependencies).
354 if ($changed || ! -e "$ROOT_DIR/sgml.stamp") {
356     # try to detect the common prefix
357     # GtkWidget, GTK_WIDGET, gtk_widget -> gtk
358     if ($NAME_SPACE eq "") {
359         $NAME_SPACE="";
360         my $pos=0;
361         my $ratio=0.0;
362         do {
363             my %prefix;
364             my $letter="";
365             foreach my $symbol (keys(%IndexEntriesFull)) {
366                 if(($NAME_SPACE eq "") || $symbol =~ /^$NAME_SPACE/i) {
367                     if (length($symbol)>$pos) {
368                         $letter=substr($symbol,$pos,1);
369                         # stop prefix scanning
370                         if ($letter eq "_") {
371                             # stop on "_"
372                             last;
373                         }
374                         # Should we also stop on a uppercase char, if last was lowercase
375                         #   GtkWidget, if we have the 'W' and had the 't' before
376                         # or should we count upper and lowercase, and stop one 2nd uppercase, if we already had a lowercase
377                         #   GtkWidget, the 'W' would be the 2nd uppercase and with 't','k' we had lowercase chars before
378                         # need to recound each time as this is per symbol
379                         $prefix{uc($letter)}++;
380                     }
381                 }
382             }
383             if ($letter ne "" && $letter ne "_") {
384                 my $maxletter="";
385                 my $maxsymbols=0;
386                 foreach $letter (keys(%prefix)) {
387                     #print "$letter: $prefix{$letter}.\n";
388                     if ($prefix{$letter}>$maxsymbols) {
389                         $maxletter=$letter;
390                         $maxsymbols=$prefix{$letter};
391                     }
392                 }
393                 $ratio = scalar(keys(%IndexEntriesFull)) / $prefix{$maxletter};
394                 #print "most symbols start with $maxletter, that is ". (100 * $ratio) ." %\n";
395                 if ($ratio > 0.9) {
396                     # do another round
397                     $NAME_SPACE .= $maxletter;
398                 }
399                 $pos++;
400             }
401             else {
402                 $ratio=0.0;
403             }
404         } while ($ratio > 0.9);
405         #print "most symbols start with $NAME_SPACE\n";
406     }
408     &OutputIndexFull;
409     &OutputDeprecatedIndex;
410     &OutputSinceIndexes;
411     &OutputAnnotationGlossary;
413     open (TIMESTAMP, ">$ROOT_DIR/sgml.stamp")
414         || die "Can't create $ROOT_DIR/sgml.stamp: $!";
415     print (TIMESTAMP "timestamp");
416     close (TIMESTAMP);
419 #############################################################################
420 # Function    : OutputObjectList
421 # Description : This outputs the alphabetical list of objects, in a columned
422 #               table.
423 #               FIXME: Currently this also outputs ancestor objects
424 #               which may not actually be in this module.
425 # Arguments   : none
426 #############################################################################
428 sub OutputObjectList {
429     my $cols = 3;
430     
431     # FIXME: use $OUTPUT_FORMAT
432     # my $old_object_index = "$SGML_OUTPUT_DIR/object_index.$OUTPUT_FORMAT";
433     my $old_object_index = "$SGML_OUTPUT_DIR/object_index.sgml";
434     my $new_object_index = "$SGML_OUTPUT_DIR/object_index.new";
436     open (OUTPUT, ">$new_object_index")
437         || die "Can't create $new_object_index: $!";
439     if ($OUTPUT_FORMAT eq "xml") {
440         my $header = $doctype_header;
442         $header =~ s/<!DOCTYPE \w+/<!DOCTYPE informaltable/;
443         print (OUTPUT "$header");
444     }
446     print (OUTPUT <<EOF);
447 <informaltable pgwide="1" frame="none">
448 <tgroup cols="$cols">
449 <colspec colwidth="1*"${empty_element_end}
450 <colspec colwidth="1*"${empty_element_end}
451 <colspec colwidth="1*"${empty_element_end}
452 <tbody>
455     my $count = 0;
456     my $object;
457     foreach $object (sort (@Objects)) {
458         my $xref = &MakeXRef ($object);
459         if ($count % $cols == 0) { print (OUTPUT "<row>\n"); }
460         print (OUTPUT "<entry>$xref</entry>\n");
461         if ($count % $cols == ($cols - 1)) { print (OUTPUT "</row>\n"); }
462         $count++;
463     }
464     if ($count == 0) {
465         # emit an empty row, since empty tables are invalid
466         print (OUTPUT "<row><entry> </entry></row>\n");
467     }
468     else {
469         if ($count % $cols > 0) {
470             print (OUTPUT "</row>\n");
471         }
472     }
474     print (OUTPUT <<EOF);
475 </tbody></tgroup></informaltable>
477     close (OUTPUT);
479     &UpdateFileIfChanged ($old_object_index, $new_object_index, 0);
483 #############################################################################
484 # Function    : OutputSGML
485 # Description : This collects the output for each section of the docs, and
486 #               outputs each file when the end of the section is found.
487 # Arguments   : $file - the $MODULE-sections.txt file which contains all of
488 #               the functions/macros/structs etc. being documented, organised
489 #               into sections and subsections.
490 #############################################################################
492 sub OutputSGML {
493     my ($file) = @_;
495     #print "Reading: $file\n";
496     open (INPUT, $file)
497         || die "Can't open $file: $!";
498     my $filename = "";
499     my $book_top = "";
500     my $book_bottom = "";
501     my $includes = (defined $DEFAULT_INCLUDES) ? $DEFAULT_INCLUDES : "";
502     my $section_includes = "";
503     my $in_section = 0;
504     my $title = "";
505     my $section_id = "";
506     my $subsection = "";
507     my $synopsis;
508     my $details;
509     my $num_symbols;
510     my $changed = 0;
511     my $signals_synop = "";
512     my $signals_desc = "";
513     my $args_synop = "";
514     my $child_args_synop = "";
515     my $style_args_synop = "";
516     my $args_desc = "";
517     my $child_args_desc = "";
518     my $style_args_desc = "";
519     my $hierarchy = "";
520     my $interfaces = "";
521     my $implementations = "";
522     my $prerequisites = "";
523     my $derived = "";
524     my @file_objects = ();
525     my %templates = ();
526     my %symbol_def_line = ();
528     # merge the source docs, in case there are no templates
529     &MergeSourceDocumentation;
531     while (<INPUT>) {
532         if (m/^#/) {
533             next;
535         } elsif (m/^<SECTION>/) {
536             $synopsis = "";
537             $details = "";
538             $num_symbols = 0;
539             $in_section = 1;
540             @file_objects = ();
541             %symbol_def_line = ();
543         } elsif (m/^<SUBSECTION\s*(.*)>/i) {
544             $synopsis .= "\n";
545             $subsection = $1;
547         } elsif (m/^<SUBSECTION>/) {
549         } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
550             $title = $1;
551             #print "Section: $title\n";
553             # We don't want warnings if object & class structs aren't used.
554             $DeclarationOutput{$title} = 1;
555             $DeclarationOutput{"${title}Class"} = 1;
556             $DeclarationOutput{"${title}Iface"} = 1;
557             $DeclarationOutput{"${title}Interface"} = 1;
559         } elsif (m/^<FILE>(.*)<\/FILE>/) {
560             $filename = $1;
561             if (! defined $templates{$filename}) {
562                if (&ReadTemplateFile ("$TMPL_DIR/$filename", 1)) {
563                    &MergeSourceDocumentation;
564                    $templates{$filename}=$.;
565                }
566             } else {
567                 &LogWarning ($file, $., "Double <FILE>$filename</FILE> entry. ".
568                     "Previous occurrence on line ".$templates{$filename}.".");
569             }
570             if (($title eq "") and (defined $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"})) {
571                 $title = $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"};
572                 # Remove trailing blanks
573                 $title =~ s/\s+$//;
574            }
576         } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
577             if ($in_section) {
578                 $section_includes = $1;
579             } else {
580                 if (defined $DEFAULT_INCLUDES) {
581                     &LogWarning ($file, $., "Default <INCLUDE> being overridden by command line option.");
582                 }
583                 else {
584                     $includes = $1;
585                 }
586             }
588         } elsif (m/^<\/SECTION>/) {
589             #print "End of section: $title\n";
590             if ($num_symbols > 0) {
591                 # collect documents
592                 if ($OUTPUT_FORMAT eq "xml") {
593                     $book_bottom .= "    <xi:include href=\"xml/$filename.xml\"/>\n";
594                 } else {
595                     $book_top.="<!ENTITY $section_id SYSTEM \"sgml/$filename.sgml\">\n";
596                     $book_bottom .= "    &$section_id;\n";
597                 }
599                 if (defined ($SourceSymbolDocs{"$TMPL_DIR/$filename:Include"})) {
600                     if ($section_includes) {
601                         &LogWarning ($file, $., "Section <INCLUDE> being overridden by inline comments.");
602                     }
603                     $section_includes = $SourceSymbolDocs{"$TMPL_DIR/$filename:Include"};
604                 }
605                 if ($section_includes eq "") {
606                     $section_includes = $includes;
607                 }
609                  $signals_synop =~ s/^\n*//g;
610                  $signals_synop =~ s/\n+$/\n/g;
611                 if ($signals_synop ne '') {
612                     $signals_synop = <<EOF;
613 <refsect1 id="$section_id.signals" role="signal_proto">
614 <title role="signal_proto.title">Signals</title>
615 <synopsis>
616 ${signals_synop}</synopsis>
617 </refsect1>
619                      $signals_desc =~ s/^\n*//g;
620                      $signals_desc =~ s/\n+$/\n/g;
621                      $signals_desc =~ s/(\s|\n)+$//ms;
622                     $signals_desc  = <<EOF;
623 <refsect1 id="$section_id.signal-details" role="signals">
624 <title role="signals.title">Signal Details</title>
625 $signals_desc
626 </refsect1>
628                 }
630                  $args_synop =~ s/^\n*//g;
631                  $args_synop =~ s/\n+$/\n/g;
632                 if ($args_synop ne '') {
633                     $args_synop = <<EOF;
634 <refsect1 id="$section_id.properties" role="properties">
635 <title role="properties.title">Properties</title>
636 <synopsis>
637 ${args_synop}</synopsis>
638 </refsect1>
640                      $args_desc =~ s/^\n*//g;
641                      $args_desc =~ s/\n+$/\n/g;
642                      $args_desc =~ s/(\s|\n)+$//ms;
643                     $args_desc  = <<EOF;
644 <refsect1 id="$section_id.property-details" role="property_details">
645 <title role="property_details.title">Property Details</title>
646 $args_desc
647 </refsect1>
649                 }
651                  $child_args_synop =~ s/^\n*//g;
652                  $child_args_synop =~ s/\n+$/\n/g;
653                 if ($child_args_synop ne '') {
654                     $args_synop .= <<EOF;
655 <refsect1 id="$section_id.child-properties" role="child_properties">
656 <title role="child_properties.title">Child Properties</title>
657 <synopsis>
658 ${child_args_synop}</synopsis>
659 </refsect1>
661                      $child_args_desc =~ s/^\n*//g;
662                      $child_args_desc =~ s/\n+$/\n/g;
663                      $child_args_desc =~ s/(\s|\n)+$//ms;
664                     $args_desc .= <<EOF;
665 <refsect1 id="$section_id.child-property-details" role="child_property_details">
666 <title role="child_property_details.title">Child Property Details</title>
667 $child_args_desc
668 </refsect1>
670                 }
672                  $style_args_synop =~ s/^\n*//g;
673                  $style_args_synop =~ s/\n+$/\n/g;
674                 if ($style_args_synop ne '') {
675                     $args_synop .= <<EOF;
676 <refsect1 id="$section_id.style-properties" role="style_properties">
677 <title role="style_properties.title">Style Properties</title>
678 <synopsis>
679 ${style_args_synop}</synopsis>
680 </refsect1>
682                      $style_args_desc =~ s/^\n*//g;
683                      $style_args_desc =~ s/\n+$/\n/g;
684                      $style_args_desc =~ s/(\s|\n)+$//ms;
685                     $args_desc .= <<EOF;
686 <refsect1 id="$section_id.style-property-details" role="style_properties_details">
687 <title role="style_properties_details.title">Style Property Details</title>
688 $style_args_desc
689 </refsect1>
691                 }
693                  $hierarchy =~ s/^\n*//g;
694                  $hierarchy =~ s/\n+$/\n/g;
695                  $hierarchy =~ s/(\s|\n)+$//ms;
696                 if ($hierarchy ne "") {
697                     $hierarchy = <<EOF;
698 <refsect1 id="$section_id.object-hierarchy" role="object_hierarchy">
699 <title role="object_hierarchy.title">Object Hierarchy</title>
700 $hierarchy
701 </refsect1>
703                 }
705                  $interfaces =~ s/^\n*//g;
706                  $interfaces =~ s/\n+$/\n/g;
707                  $interfaces =~ s/(\s|\n)+$//ms;
708                 if ($interfaces ne "") {
709                     $interfaces = <<EOF;
710 <refsect1 id="$section_id.implemented-interfaces" role="impl_interfaces">
711 <title role="impl_interfaces.title">Implemented Interfaces</title>
712 $interfaces
713 </refsect1>
715                 }
717                  $implementations =~ s/^\n*//g;
718                  $implementations =~ s/\n+$/\n/g;
719                  $implementations =~ s/(\s|\n)+$//ms;
720                 if ($implementations ne "") {
721                     $implementations = <<EOF;
722 <refsect1 id="$section_id.implementations" role="implementations">
723 <title role="implementations.title">Known Implementations</title>
724 $implementations
725 </refsect1>
727                 }
729                  $prerequisites =~ s/^\n*//g;
730                  $prerequisites =~ s/\n+$/\n/g;
731                  $prerequisites =~ s/(\s|\n)+$//ms;
732                 if ($prerequisites ne "") {
733                     $prerequisites = <<EOF;
734 <refsect1 id="$section_id.prerequisites" role="prerequisites">
735 <title role="prerequisites.title">Prerequisites</title>
736 $prerequisites
737 </refsect1>
739                 }
741                  $derived =~ s/^\n*//g;
742                  $derived =~ s/\n+$/\n/g;
743                  $derived =~ s/(\s|\n)+$//ms;
744                 if ($derived ne "") {
745                     $derived = <<EOF;
746 <refsect1 id="$section_id.derived-interfaces" role="derived_interfaces">
747 <title role="derived_interfaces.title">Known Derived Interfaces</title>
748 $derived
749 </refsect1>
751                 }
753                 $synopsis =~ s/^\n*//g;
754                 $synopsis =~ s/\n+$/\n/g;
755                 my $file_changed = &OutputSGMLFile ($filename, $title, $section_id,
756                                                     $section_includes,
757                                                     \$synopsis, \$details,
758                                                     \$signals_synop, \$signals_desc,
759                                                     \$args_synop, \$args_desc,
760                                                     \$hierarchy, \$interfaces,
761                                                     \$implementations,
762                                                     \$prerequisites, \$derived,
763                                                     \@file_objects);
764                 if ($file_changed) {
765                     $changed = 1;
766                 }
767             }
768             $title = "";
769             $section_id = "";
770             $subsection = "";
771             $in_section = 0;
772             $section_includes = "";
773             $signals_synop = "";
774             $signals_desc = "";
775             $args_synop = "";
776             $child_args_synop = "";
777             $style_args_synop = "";
778             $args_desc = "";
779             $child_args_desc = "";
780             $style_args_desc = "";
781             $hierarchy = "";
782             $interfaces = "";
783             $implementations = "";
784             $prerequisites = "";
785             $derived = "";
787         } elsif (m/^(\S+)/) {
788             my $symbol = $1;
789             #print "  Symbol: $symbol\n";
791             # check for duplicate entries
792             if (! defined $symbol_def_line{$symbol}) {
793                 my $declaration = $Declarations{$symbol};
794                 if (defined ($declaration)) {
795                     # We don't want standard macros/functions of GObjects,
796                     # or private declarations.
797                     if ($subsection ne "Standard" && $subsection ne "Private") {
798                         if (&CheckIsObject ($symbol)) {
799                             push @file_objects, $symbol;
800                         }
801                         my ($synop, $desc) = &OutputDeclaration ($symbol,
802                                                                  $declaration);
803                         my ($sig_synop, $sig_desc) = &GetSignals ($symbol);
804                         my ($arg_synop, $child_arg_synop, $style_arg_synop,
805                             $arg_desc, $child_arg_desc, $style_arg_desc) = &GetArgs ($symbol);
806                         my $hier = &GetHierarchy ($symbol);
807                         my $ifaces = &GetInterfaces ($symbol);
808                         my $impls = &GetImplementations ($symbol);
809                         my $prereqs = &GetPrerequisites ($symbol);
810                         my $der = &GetDerived ($symbol);
811                         $synopsis .= $synop;
812                         $details .= $desc;
813                         $signals_synop .= $sig_synop;
814                         $signals_desc .= $sig_desc;
815                         $args_synop .= $arg_synop;
816                         $child_args_synop .= $child_arg_synop;
817                         $style_args_synop .= $style_arg_synop;
818                         $args_desc .= $arg_desc;
819                         $child_args_desc .= $child_arg_desc;
820                         $style_args_desc .= $style_arg_desc;
821                         $hierarchy .= $hier;
822                         $interfaces .= $ifaces;
823                         $implementations .= $impls;
824                         $prerequisites .= $prereqs;
825                         $derived .= $der;
826                     }
827     
828                     # Note that the declaration has been output.
829                     $DeclarationOutput{$symbol} = 1;
830                 } elsif ($subsection ne "Standard" && $subsection ne "Private") {
831                     $UndeclaredSymbols{$symbol} = 1;
832                     &LogWarning ($file, $., "No declaration found for $symbol.");
833                 }
834                 $num_symbols++;
835                 $symbol_def_line{$symbol}=$.;
837                 if ($section_id eq "") {
838                     if($title eq "" && $filename eq "") {
839                         &LogWarning ($file, $., "Section has no title and no file.");
840                     }
841                     # FIXME: one of those would be enough
842                     # filename should be an internal detail for gtk-doc
843                     if ($title eq "") {
844                         $title = $filename;
845                     } elsif ($filename eq "") {
846                         $filename = $title;
847                     }
848                     $filename =~ s/\s/_/g;
849         
850                     $section_id = $SourceSymbolDocs{"$TMPL_DIR/$filename:Section_Id"};
851                     if (defined ($section_id) && $section_id !~ m/^\s*$/) {
852                         # Remove trailing blanks and use as is
853                         $section_id =~ s/\s+$//;
854                     } elsif (&CheckIsObject ($title)) {
855                         # GObjects use their class name as the ID.
856                         $section_id = &CreateValidSGMLID ($title);
857                     } else {
858                         $section_id = &CreateValidSGMLID ("$MODULE-$title");
859                     }
860                 }
861                 $SymbolSection{$symbol}=$title;
862                 $SymbolSectionId{$symbol}=$section_id;
863             }
864             else {
865                 &LogWarning ($file, $., "Double symbol entry for $symbol. ".
866                     "Previous occurrence on line ".$symbol_def_line{$symbol}.".");
867             }
868         }
869     }
870     close (INPUT);
872     &OutputMissingDocumentation;
873     &OutputUndeclaredSymbols;
874     &OutputUnusedSymbols;
876     if ($OUTPUT_ALL_SYMBOLS) {
877         &OutputAllSymbols;
878     }
879     if ($OUTPUT_SYMBOLS_WITHOUT_SINCE) {
880         &OutputSymbolsWithoutSince;
881     }
883     for $filename (split (' ', $EXPAND_CONTENT_FILES)) {
884         my $file_changed = &OutputExtraFile ($filename);
885         if ($file_changed) {
886             $changed = 1;
887         }
888     }
890     &OutputBook ($book_top, $book_bottom);
892     return $changed;
895 #############################################################################
896 # Function    : OutputIndex
897 # Description : This writes an indexlist that can be included into the main-
898 #               document into an <index> tag.
899 #############################################################################
901 sub OutputIndex {
902     my ($basename, $apiindexref ) = @_;
903     my %apiindex = %{$apiindexref};
904     my $old_index = "$SGML_OUTPUT_DIR/$basename.xml";
905     my $new_index = "$SGML_OUTPUT_DIR/$basename.new";
906     my $lastletter = " ";
907     my $divopen = 0;
908     my $symbol;
909     my $short_symbol;
911     open (OUTPUT, ">$new_index")
912         || die "Can't create $new_index";
914     my $header = $doctype_header;
915     $header =~ s/<!DOCTYPE \w+/<!DOCTYPE indexdiv/;
917     print (OUTPUT "$header<indexdiv>\n");
919     #print "generate $basename index (".%apiindex." entries)\n";
920     
921     # do a case insensitive sort while chopping off the prefix
922     foreach my $hash (
923         sort { $$a{criteria} cmp $$b{criteria} }
924         map { my $x = uc($_); $x =~ s/^$NAME_SPACE\_?(.*)/$1/i; { criteria => $x, original => $_, short => $1 } } 
925         keys %apiindex) {
927         $symbol = $$hash{original};
928         if (defined($$hash{short})) {
929             $short_symbol = $$hash{short};
930         } else {
931             $short_symbol = $symbol;
932         }
934         # generate a short symbol description
935         my $symbol_desc = "";
936         my $symbol_section = "";
937         my $symbol_section_id = "";
938         my $symbol_type = "";
939         if (defined($DeclarationTypes{$symbol})) {
940           $symbol_type = lc($DeclarationTypes{$symbol});
941         }
942         if ($symbol_type eq "") {
943             #print "trying symbol $symbol\n";
944             if ($symbol =~ m/(.*)::(.*)/) {
945                 my $oname = $1;
946                 my $osym = $2;
947                 my $i;
948                 #print "  trying object signal ${oname}:$osym in ".$#SignalNames." signals\n";
949                 for ($i = 0; $i <= $#SignalNames; $i++) {
950                     if ($SignalNames[$i] eq $osym) {
951                         $symbol_type = "object signal";
952                         if (defined($SymbolSection{$oname})) {
953                            $symbol_section = $SymbolSection{$oname};
954                            $symbol_section_id = $SymbolSectionId{$oname};
955                         }
956                         last;
957                     }
958                 }
959             } elsif ($symbol =~ m/(.*):(.*)/) {
960                 my $oname = $1;
961                 my $osym = $2;
962                 my $i;
963                 #print "  trying object property ${oname}::$osym in ".$#ArgNames." properties\n";
964                 for ($i = 0; $i <= $#ArgNames; $i++) {
965                     #print "    ".$ArgNames[$i]."\n";
966                     if ($ArgNames[$i] eq $osym) {
967                         $symbol_type = "object property";
968                         if (defined($SymbolSection{$oname})) {
969                            $symbol_section = $SymbolSection{$oname};
970                            $symbol_section_id = $SymbolSectionId{$oname};
971                         }
972                         last;
973                     }
974                 }
975             }
976         } else {
977            if (defined($SymbolSection{$symbol})) {
978                $symbol_section = $SymbolSection{$symbol};
979                $symbol_section_id = $SymbolSectionId{$symbol};
980            }
981         }
982         if ($symbol_type ne "") {
983            $symbol_desc=", $symbol_type";
984            if ($symbol_section ne "") {
985                $symbol_desc.=" in <link linkend=\"$symbol_section_id\">$symbol_section</link>";
986                #$symbol_desc.=" in ". &ExpandAbbreviations($symbol, "#$symbol_section");
987            }
988         }
990         my $curletter = uc(substr($short_symbol,0,1));
991         my $id = $apiindex{$symbol};
993         #print "  add symbol $symbol with $id to index in section $curletter\n";
995         if ($curletter ne $lastletter) {
996             $lastletter = $curletter;
998             if ($divopen == 1) {
999                 print (OUTPUT "</indexdiv>\n");
1000             }
1001             print (OUTPUT "<indexdiv><title>$curletter</title>\n");
1002             $divopen = 1;
1003         }
1005         print (OUTPUT <<EOF);
1006 <indexentry><primaryie linkends="$id"><link linkend="$id">$symbol</link>$symbol_desc</primaryie></indexentry>
1008     }
1010     if ($divopen == 1) {
1011         print (OUTPUT "</indexdiv>\n");
1012     }
1013     print (OUTPUT "</indexdiv>\n");
1014     close (OUTPUT);
1016     &UpdateFileIfChanged ($old_index, $new_index, 0);
1020 #############################################################################
1021 # Function    : OutputIndexFull
1022 # Description : This writes the full api indexlist that can be included into the
1023 #               main document into an <index> tag.
1024 #############################################################################
1026 sub OutputIndexFull {
1027     &OutputIndex ("api-index-full", \%IndexEntriesFull);
1031 #############################################################################
1032 # Function    : OutputDeprecatedIndex
1033 # Description : This writes the deprecated api indexlist that can be included
1034 #               into the main document into an <index> tag.
1035 #############################################################################
1037 sub OutputDeprecatedIndex {
1038     &OutputIndex ("api-index-deprecated", \%IndexEntriesDeprecated);
1042 #############################################################################
1043 # Function    : OutputSinceIndexes
1044 # Description : This writes the 'since' api indexlists that can be included into
1045 #               the main document into an <index> tag.
1046 #############################################################################
1048 sub OutputSinceIndexes {
1049     my @sinces = keys %{{ map { $_ => 1 } values %Since }};
1051     foreach my $version (@sinces) {
1052         #print "Since : [$version]\n";
1053         # TODO make filtered hash
1054         #my %index = grep { $Since{$_} eq $version } %IndexEntriesSince;
1055         my %index = map { $_ => $IndexEntriesSince{$_} } grep { $Since{$_} eq $version } keys %IndexEntriesSince;
1057         &OutputIndex ("api-index-$version", \%index);
1058     }
1061 #############################################################################
1062 # Function    : OutputAnnotationGlossary
1063 # Description : This writes a glossary of the used annotation terms into a
1064 #               separate glossary file that can be included into the main
1065 #               document.
1066 #############################################################################
1068 sub OutputAnnotationGlossary {
1069     my $old_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.xml";
1070     my $new_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.new";
1071     my $lastletter = " ";
1072     my $divopen = 0;
1074     # if there are no annotations used return
1075     return if (! keys(%AnnotationsUsed));
1077     # add acronyms that are referenced from acronym text
1078 rerun:
1079     foreach my $annotation (keys(%AnnotationsUsed)) {
1080         if(defined($AnnotationDefinition{$annotation})) {
1081             if($AnnotationDefinition{$annotation} =~ m/<acronym>([\w ]+)<\/acronym>/) {
1082                 if (!exists($AnnotationsUsed{$1})) {
1083                     $AnnotationsUsed{$1} = 1;
1084                     goto rerun;
1085                 }
1086             }
1087         }
1088     }
1090     open (OUTPUT, ">$new_glossary")
1091         || die "Can't create $new_glossary";
1093     my $header = $doctype_header;
1094     $header =~ s/<!DOCTYPE \w+/<!DOCTYPE glossary/;
1096     print (OUTPUT  <<EOF);
1097 $header
1098 <glossary id="annotation-glossary">
1099   <title>Annotation Glossary</title>
1102     foreach my $annotation (keys(%AnnotationsUsed)) {
1103         if(defined($AnnotationDefinition{$annotation})) {
1104             my $def = $AnnotationDefinition{$annotation};
1105             my $curletter = uc(substr($annotation,0,1));
1106     
1107             if ($curletter ne $lastletter) {
1108                 $lastletter = $curletter;
1109           
1110                 if ($divopen == 1) {
1111                     print (OUTPUT "</glossdiv>\n");
1112                 }
1113                 print (OUTPUT "<glossdiv><title>$curletter</title>\n");
1114                 $divopen = 1;
1115             }
1116             print (OUTPUT <<EOF);
1117     <glossentry>
1118       <glossterm><anchor id="annotation-glossterm-$annotation"/>$annotation</glossterm>
1119       <glossdef>
1120         <para>$def</para>
1121       </glossdef>
1122     </glossentry>
1124         }
1125     }
1127     if ($divopen == 1) {
1128         print (OUTPUT "</glossdiv>\n");
1129     }
1130     print (OUTPUT "</glossary>\n");
1131     close (OUTPUT);
1133     &UpdateFileIfChanged ($old_glossary, $new_glossary, 0);
1136 #############################################################################
1137 # Function    : ReadKnownSymbols
1138 # Description : This collects the names of non-private symbols from the
1139 #               $MODULE-sections.txt file.
1140 # Arguments   : $file - the $MODULE-sections.txt file which contains all of
1141 #               the functions/macros/structs etc. being documented, organised
1142 #               into sections and subsections.
1143 #############################################################################
1145 sub ReadKnownSymbols {
1146     my ($file) = @_;
1148     my $subsection = "";
1150     #print "Reading: $file\n";
1151     open (INPUT, $file)
1152         || die "Can't open $file: $!";
1154     while (<INPUT>) {
1155         if (m/^#/) {
1156             next;
1158         } elsif (m/^<SECTION>/) {
1159             $subsection = "";
1161         } elsif (m/^<SUBSECTION\s*(.*)>/i) {
1162             $subsection = $1;
1164         } elsif (m/^<SUBSECTION>/) {
1165             next;
1167         } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
1168             next;
1170         } elsif (m/^<FILE>(.*)<\/FILE>/) {
1171             $KnownSymbols{"$TMPL_DIR/$1:Long_Description"} = 1;
1172             $KnownSymbols{"$TMPL_DIR/$1:Short_Description"} = 1;
1173             next;
1175         } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
1176             next;
1178         } elsif (m/^<\/SECTION>/) {
1179             next;
1181         } elsif (m/^(\S+)/) {
1182             my $symbol = $1;
1184             if ($subsection ne "Standard" && $subsection ne "Private") {
1185                 $KnownSymbols{$symbol} = 1;
1186             }
1187             else {
1188                 $KnownSymbols{$symbol} = 0;
1189             }
1190         }
1191     }
1192     close (INPUT);
1196 #############################################################################
1197 # Function    : OutputDeclaration
1198 # Description : Returns the synopsis and detailed description DocBook
1199 #               describing one function/macro etc.
1200 # Arguments   : $symbol - the name of the function/macro begin described.
1201 #               $declaration - the declaration of the function/macro.
1202 #############################################################################
1204 sub OutputDeclaration {
1205     my ($symbol, $declaration) = @_;
1207     my $type = $DeclarationTypes {$symbol};
1208     if ($type eq 'MACRO') {
1209         return &OutputMacro ($symbol, $declaration);
1210     } elsif ($type eq 'TYPEDEF') {
1211         return &OutputTypedef ($symbol, $declaration);
1212     } elsif ($type eq 'STRUCT') {
1213         return &OutputStruct ($symbol, $declaration);
1214     } elsif ($type eq 'ENUM') {
1215         return &OutputEnum ($symbol, $declaration);
1216     } elsif ($type eq 'UNION') {
1217         return &OutputUnion ($symbol, $declaration);
1218     } elsif ($type eq 'VARIABLE') {
1219         return &OutputVariable ($symbol, $declaration);
1220     } elsif ($type eq 'FUNCTION') {
1221         return &OutputFunction ($symbol, $declaration, $type);
1222     } elsif ($type eq 'USER_FUNCTION') {
1223         return &OutputFunction ($symbol, $declaration, $type);
1224     } else {
1225         die "Unknown symbol type";
1226     }
1230 #############################################################################
1231 # Function    : OutputSymbolTraits
1232 # Description : Returns the Since and StabilityLevel paragraphs for a symbol.
1233 # Arguments   : $symbol - the name of the function/macro begin described.
1234 #############################################################################
1236 sub OutputSymbolTraits {
1237     my ($symbol) = @_;
1238     my $desc = "";
1240     if (exists $Since{$symbol}) {
1241         $desc .= "<para role=\"since\">Since $Since{$symbol}</para>";
1242     }
1243     if (exists $StabilityLevel{$symbol}) {
1244         $desc .= "<para role=\"stability\">Stability Level: $StabilityLevel{$symbol}</para>";
1245     }
1246     return $desc;
1249 #############################################################################
1250 # Function    : Outpu{Symbol,Section}ExtraLinks
1251 # Description : Returns extralinks for the symbol (if enabled).
1252 # Arguments   : $symbol - the name of the function/macro begin described.
1253 #############################################################################
1255 sub uri_escape {
1256     my $text = $_[0];
1257     return undef unless defined $text;
1259     # Build a char to hex map
1260     my %escapes = ();
1261     for (0..255) {
1262             $escapes{chr($_)} = sprintf("%%%02X", $_);
1263     }
1265     # Default unsafe characters.  RFC 2732 ^(uric - reserved)
1266     $text =~ s/([^A-Za-z0-9\-_.!~*'()])/$escapes{$1}/g;
1268     return $text;
1271 sub OutputSymbolExtraLinks {
1272     my ($symbol) = @_;
1273     my $desc = "";
1275     if (0) { # NEW FEATURE: needs configurability
1276     my $sstr = &uri_escape($symbol);
1277     my $mstr = &uri_escape($MODULE);
1278     $desc .= <<EOF;
1279 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1280 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&amp;symbol=$sstr">edit documentation</ulink>
1282     }
1283     return $desc;
1286 sub OutputSectionExtraLinks {
1287     my ($symbol,$docsymbol) = @_;
1288     my $desc = "";
1290     if (0) { # NEW FEATURE: needs configurability
1291     my $sstr = &uri_escape($symbol);
1292     my $mstr = &uri_escape($MODULE);
1293     my $dsstr = &uri_escape($docsymbol);
1294     $desc .= <<EOF;
1295 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1296 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&amp;symbol=$dsstr">edit documentation</ulink>
1298     }
1299     return $desc;
1303 #############################################################################
1304 # Function    : OutputMacro
1305 # Description : Returns the synopsis and detailed description of a macro.
1306 # Arguments   : $symbol - the macro.
1307 #               $declaration - the declaration of the macro.
1308 #############################################################################
1310 sub OutputMacro {
1311     my ($symbol, $declaration) = @_;
1312     my $id = &CreateValidSGMLID ($symbol);
1313     my $condition = &MakeConditionDescription ($symbol);
1314     my $synop = &MakeReturnField("#define") . "<link linkend=\"$id\">$symbol</link>";
1315     my $desc;
1317     my @fields = ParseMacroDeclaration($declaration, \&CreateValidSGML);
1318     my $title = $symbol . (@fields ? "()" : "");
1320     $desc = "<refsect2 id=\"$id\" role=\"macro\"$condition>\n<title>$title</title>\n";
1321     $desc .= MakeIndexterms($symbol, $id);
1322     $desc .= "\n";
1323     $desc .= OutputSymbolExtraLinks($symbol);
1325     if (@fields) {
1326         if (length ($symbol) < $SYMBOL_FIELD_WIDTH) {
1327             $synop .= (' ' x ($SYMBOL_FIELD_WIDTH - length ($symbol)));
1328         }
1329     
1330         $synop .= "(";
1331         for (my $i = 1; $i <= $#fields; $i += 2) {
1332             my $field_name = $fields[$i];
1334             if ($i == 1) {
1335                 $synop .= "$field_name";
1336             } else {
1337                 $synop .= ",\n"
1338                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1339                     . " $field_name";
1340             }
1341         }
1342         $synop .= ")";
1343     }
1344     $synop .= "\n";
1346     # Don't output the macro definition if is is a conditional macro or it
1347     # looks like a function, i.e. starts with "g_" or "_?gnome_", or it is
1348     # longer than 2 lines, otherwise we get lots of complicated macros like
1349     # g_assert.
1350     if (!defined ($DeclarationConditional{$symbol}) && ($symbol !~ m/^g_/)
1351         && ($symbol !~ m/^_?gnome_/) && (($declaration =~ tr/\n//) < 2)) {
1352         my $decl_out = &CreateValidSGML ($declaration);
1353         $desc .= "<programlisting>$decl_out</programlisting>\n";
1354     } else {
1355         $desc .= "<programlisting>" . &MakeReturnField("#define") . "$symbol";
1356         if ($declaration =~ m/^\s*#\s*define\s+\w+(\([^\)]*\))/) {
1357             my $args = $1;
1358             my $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH - length ("#define "));
1359             # Align each line so that if should all line up OK.
1360             $args =~ s/\n/\n$pad/gm;
1361             $desc .= &CreateValidSGML ($args);
1362         }
1363         $desc .= "</programlisting>\n";
1364     }
1366     $desc .= &MakeDeprecationNote($symbol);
1368     my $parameters = &OutputParamDescriptions ("MACRO", $symbol, @fields);
1369     my $parameters_output = 0;
1371     if (defined ($SymbolDocs{$symbol})) {
1372         my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1374         # Try to insert the parameter table at the author's desired position.
1375         # Otherwise we need to tag it onto the end.
1376         if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1377           $parameters_output = 1;
1378         }
1379         $desc .= $symbol_docs;
1380     }
1382     if ($parameters_output == 0) {
1383         $desc .= $parameters;
1384     }
1386     $desc .= OutputSymbolTraits ($symbol);
1387     $desc .= "</refsect2>\n";
1388     return ($synop, $desc);
1392 #############################################################################
1393 # Function    : OutputTypedef
1394 # Description : Returns the synopsis and detailed description of a typedef.
1395 # Arguments   : $symbol - the typedef.
1396 #               $declaration - the declaration of the typedef,
1397 #                 e.g. 'typedef unsigned int guint;'
1398 #############################################################################
1400 sub OutputTypedef {
1401     my ($symbol, $declaration) = @_;
1402     my $id = &CreateValidSGMLID ($symbol);
1403     my $condition = &MakeConditionDescription ($symbol);
1404     my $synop = &MakeReturnField("typedef") . "<link linkend=\"$id\">$symbol</link>;\n";
1405     my $desc = "<refsect2 id=\"$id\" role=\"typedef\"$condition>\n<title>$symbol</title>\n";
1407     $desc .= MakeIndexterms($symbol, $id);
1408     $desc .= "\n";
1409     $desc .= OutputSymbolExtraLinks($symbol);
1411     if (!defined ($DeclarationConditional{$symbol})) {
1412         my $decl_out = &CreateValidSGML ($declaration);
1413         $desc .= "<programlisting>$decl_out</programlisting>\n";
1414     }
1416     $desc .= &MakeDeprecationNote($symbol);
1418     if (defined ($SymbolDocs{$symbol})) {
1419         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1420     }
1421     $desc .= OutputSymbolTraits ($symbol);
1422     $desc .= "</refsect2>\n";
1423     return ($synop, $desc);
1427 #############################################################################
1428 # Function    : OutputStruct
1429 # Description : Returns the synopsis and detailed description of a struct.
1430 #               We check if it is a object struct, and if so we only output
1431 #               parts of it that are noted as public fields.
1432 #               We also use a different SGML ID for object structs, since the
1433 #               original ID is used for the entire RefEntry.
1434 # Arguments   : $symbol - the struct.
1435 #               $declaration - the declaration of the struct.
1436 #############################################################################
1438 sub OutputStruct {
1439     my ($symbol, $declaration) = @_;
1441     my $is_object_struct = 0;
1442     my $default_to_public = 1;
1443     if (&CheckIsObject ($symbol)) {
1444         #print "Found object struct: $symbol\n";
1445         $is_object_struct = 1;
1446         $default_to_public = 0;
1447     }
1449     my $id;
1450     my $condition;
1451     if ($is_object_struct) {
1452         $id = &CreateValidSGMLID ($symbol . "_struct");
1453         $condition = &MakeConditionDescription ($symbol . "_struct");
1454     } else {
1455         $id = &CreateValidSGMLID ($symbol);
1456         $condition = &MakeConditionDescription ($symbol);
1457     }
1459     # Determine if it is a simple struct or it also has a typedef.
1460     my $has_typedef = 0;
1461     if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1462       $has_typedef = 1;
1463     }
1465     my $synop;
1466     my $desc;
1467     if ($has_typedef) {
1468         # For structs with typedefs we just output the struct name.
1469         $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1470         $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>$symbol</title>\n";
1471     } else {
1472         $synop = &MakeReturnField("struct") . "<link linkend=\"$id\">$symbol</link>;\n";
1473         $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>struct $symbol</title>\n";
1474     }
1476     $desc .= MakeIndexterms($symbol, $id);
1477     $desc .= "\n";
1478     $desc .= OutputSymbolExtraLinks($symbol);
1480     # Form a pretty-printed, private-data-removed form of the declaration
1482     my $decl_out = "";
1483     if ($declaration =~ m/^\s*$/) {
1484         #print "Found opaque struct: $symbol\n";
1485         $decl_out = "typedef struct _$symbol $symbol;";
1486     } elsif ($declaration =~ m/^\s*struct\s+\w+\s*;\s*$/) {
1487         #print "Found opaque struct: $symbol\n";
1488         $decl_out = "struct $symbol;";
1489     } else {
1490         my $public = $default_to_public;
1491         my $new_declaration = "";
1492         my $decl_line;
1493         my $decl = $declaration;
1495         if ($decl =~ m/^\s*(typedef\s+)?struct\s*\w*\s*(?:\/\*.*\*\/)?\s*{(.*)}\s*\w*\s*;\s*$/s) {
1496             my $struct_contents = $2;
1498             foreach $decl_line (split (/\n/, $struct_contents)) {
1499                 #print "Struct line: $decl_line\n";
1500                 if ($decl_line =~ m%/\*\s*<\s*public\s*>\s*\*/%) {
1501                     $public = 1;
1502                 } elsif ($decl_line =~ m%/\*\s*<\s*(private|protected)\s*>\s*\*/%) {
1503                     $public = 0;
1504                 } elsif ($public) {
1505                     $new_declaration .= $decl_line . "\n";
1506                 }
1507             }
1509             if ($new_declaration) {
1510                 # Strip any blank lines off the ends.
1511                 $new_declaration =~ s/^\s*\n//;
1512                 $new_declaration =~ s/\n\s*$/\n/;
1514                 if ($has_typedef) {
1515                     $decl_out = "typedef struct {\n" . $new_declaration
1516                       . "} $symbol;\n";
1517                 } else {
1518                     $decl_out = "struct $symbol {\n" . $new_declaration
1519                       . "};\n";
1520                 }
1521             }
1522         } else {
1523             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1524                 "Couldn't parse struct:\n$declaration");
1525         }
1527         # If we couldn't parse the struct or it was all private, output an
1528         # empty struct declaration.
1529         if ($decl_out eq "") {
1530             if ($has_typedef) {
1531                 $decl_out = "typedef struct _$symbol $symbol;";
1532             } else {
1533                 $decl_out = "struct $symbol;";
1534             }
1535         }
1536     }
1538     $decl_out = &CreateValidSGML ($decl_out);
1539     $desc .= "<programlisting>$decl_out</programlisting>\n";
1541     $desc .= &MakeDeprecationNote($symbol);
1543     if (defined ($SymbolDocs{$symbol})) {
1544         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1545     }
1547     # Create a table of fields and descriptions
1549     # FIXME: Inserting &#160's into the produced type declarations here would
1550     #        improve the output in most situations ... except for function
1551     #        members of structs!
1552     my @fields = ParseStructDeclaration($declaration, !$default_to_public,
1553                                         0, \&MakeXRef,
1554                                         sub {
1555                                             "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1556                                         });
1557     my $params = $SymbolParams{$symbol};
1559     # If no parameters are filled in, we don't generate the description
1560     # table, for backwards compatibility
1562     my $found = 0;
1563     if (defined $params) {
1564         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1565             if ($params->[$i] =~ /\S/) {
1566                 $found = 1;
1567                 last;
1568             }
1569         }
1570     }
1572     if ($found) {
1573         my %field_descrs = @$params;
1574         my $missing_parameters = "";
1575         my $unused_parameters = "";
1577         $desc .= "<variablelist role=\"struct\">\n";
1578         while (@fields) {
1579             my $field_name = shift @fields;
1580             my $text = shift @fields;
1581             my $field_descr = $field_descrs{$field_name};
1582             my $param_annotations = "";
1584             $desc .= "<varlistentry><term>$text</term>\n";
1585             if (defined $field_descr) {
1586                 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1587                 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1588                 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1589                 delete $field_descrs{$field_name};
1590             } else {
1591                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1592                     "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1593                 if ($missing_parameters ne "") {
1594                   $missing_parameters .= ", ".$field_name;
1595                 } else {
1596                     $missing_parameters = $field_name;
1597                 }
1598                 $desc .= "<listitem />\n";
1599             }
1600             $desc .= "</varlistentry>\n";
1601         }
1602         $desc .= "</variablelist>";
1603         foreach my $field_name (keys %field_descrs) {
1604             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1605                 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1606             if ($unused_parameters ne "") {
1607               $unused_parameters .= ", ".$field_name;
1608             } else {
1609                $unused_parameters = $field_name;
1610             }
1611         }
1613         # remember missing/unused parameters (needed in tmpl-free build)
1614         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1615             $AllIncompleteSymbols{$symbol}=$missing_parameters;
1616         }
1617         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1618             $AllUnusedSymbols{$symbol}=$unused_parameters;
1619         }
1620     }
1621     else {
1622         if (scalar(@fields) > 0) {
1623             if (! exists ($AllIncompleteSymbols{$symbol})) {
1624                 $AllIncompleteSymbols{$symbol}="<items>";
1625                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1626                     "Field descriptions for $symbol are missing in source code comment block.");
1627             }
1628         }
1629     }
1631     $desc .= OutputSymbolTraits ($symbol);
1632     $desc .= "</refsect2>\n";
1633     return ($synop, $desc);
1637 #############################################################################
1638 # Function    : OutputUnion
1639 # Description : Returns the synopsis and detailed description of a union.
1640 # Arguments   : $symbol - the union.
1641 #               $declaration - the declaration of the union.
1642 #############################################################################
1644 sub OutputUnion {
1645     my ($symbol, $declaration) = @_;
1646     my $id = &CreateValidSGMLID ($symbol);
1647     my $condition = &MakeConditionDescription ($symbol);
1649     # Determine if it is a simple struct or it also has a typedef.
1650     my $has_typedef = 0;
1651     if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1652       $has_typedef = 1;
1653     }
1655     my $synop;
1656     my $desc;
1657     if ($has_typedef) {
1658         # For unions with typedefs we just output the union name.
1659         $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1660         $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>$symbol</title>\n";
1661     } else {
1662         $synop = &MakeReturnField("union") . "<link linkend=\"$id\">$symbol</link>;\n";
1663         $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>union $symbol</title>\n";
1664     }
1666     $desc .= MakeIndexterms($symbol, $id);
1667     $desc .= "\n";
1668     $desc .= OutputSymbolExtraLinks($symbol);
1670     # FIXME: we do more for structs
1671     my $decl_out = &CreateValidSGML ($declaration);
1672     $desc .= "<programlisting>$decl_out</programlisting>\n";
1674     $desc .= &MakeDeprecationNote($symbol);
1676     if (defined ($SymbolDocs{$symbol})) {
1677         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1678     }
1680     # Create a table of fields and descriptions
1682     # FIXME: Inserting &#160's into the produced type declarations here would
1683     #        improve the output in most situations ... except for function
1684     #        members of structs!
1685     my @fields = ParseStructDeclaration($declaration, 0,
1686                                         0, \&MakeXRef,
1687                                         sub {
1688                                             "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1689                                         });
1690     my $params = $SymbolParams{$symbol};
1692     # If no parameters are filled in, we don't generate the description
1693     # table, for backwards compatibility
1695     my $found = 0;
1696     if (defined $params) {
1697         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1698             if ($params->[$i] =~ /\S/) {
1699                 $found = 1;
1700                 last;
1701             }
1702         }
1703     }
1705     if ($found) {
1706         my %field_descrs = @$params;
1707         my $missing_parameters = "";
1708         my $unused_parameters = "";
1710         $desc .= "<variablelist role=\"union\">\n";
1711         while (@fields) {
1712             my $field_name = shift @fields;
1713             my $text = shift @fields;
1714             my $field_descr = $field_descrs{$field_name};
1715             my $param_annotations = "";
1717             $desc .= "<varlistentry><term>$text</term>\n";
1718             if (defined $field_descr) {
1719                 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1720                 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1721                 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1722                 delete $field_descrs{$field_name};
1723             } else {
1724                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1725                     "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1726                 if ($missing_parameters ne "") {
1727                     $missing_parameters .= ", ".$field_name;
1728                 } else {
1729                     $missing_parameters = $field_name;
1730                 }
1731                 $desc .= "<listitem />\n";
1732             }
1733             $desc .= "</varlistentry>\n";
1734         }
1735         $desc .= "</variablelist>";
1736         foreach my $field_name (keys %field_descrs) {
1737             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1738                 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1739             if ($unused_parameters ne "") {
1740               $unused_parameters .= ", ".$field_name;
1741             } else {
1742                $unused_parameters = $field_name;
1743             }
1744         }
1746         # remember missing/unused parameters (needed in tmpl-free build)
1747         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1748             $AllIncompleteSymbols{$symbol}=$missing_parameters;
1749         }
1750         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1751             $AllUnusedSymbols{$symbol}=$unused_parameters;
1752         }
1753     }
1754     else {
1755         if (scalar(@fields) > 0) {
1756             if (! exists ($AllIncompleteSymbols{$symbol})) {
1757                 $AllIncompleteSymbols{$symbol}="<items>";
1758                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1759                     "Field descriptions for $symbol are missing in source code comment block.");
1760             }
1761         }
1762     }
1764     $desc .= OutputSymbolTraits ($symbol);
1765     $desc .= "</refsect2>\n";
1766     return ($synop, $desc);
1770 #############################################################################
1771 # Function    : OutputEnum
1772 # Description : Returns the synopsis and detailed description of a enum.
1773 # Arguments   : $symbol - the enum.
1774 #               $declaration - the declaration of the enum.
1775 #############################################################################
1777 sub OutputEnum {
1778     my ($symbol, $declaration) = @_;
1779     my $id = &CreateValidSGMLID ($symbol);
1780     my $condition = &MakeConditionDescription ($symbol);
1781     my $synop = &MakeReturnField("enum") . "<link linkend=\"$id\">$symbol</link>;\n";
1782     my $desc = "<refsect2 id=\"$id\" role=\"enum\"$condition>\n<title>enum $symbol</title>\n";
1784     $desc .= MakeIndexterms($symbol, $id);
1785     $desc .= "\n";
1786     $desc .= OutputSymbolExtraLinks($symbol);
1788     my $decl_out = &CreateValidSGML ($declaration);
1789     $desc .= "<programlisting>$decl_out</programlisting>\n";
1791     $desc .= &MakeDeprecationNote($symbol);
1793     if (defined ($SymbolDocs{$symbol})) {
1794         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1795     }
1797     # Create a table of fields and descriptions
1799     my @fields = ParseEnumDeclaration($declaration);
1800     my $params = $SymbolParams{$symbol};
1802     # If no parameters are filled in, we don't generate the description
1803     # table, for backwards compatibility
1805     my $found = 0;
1806     if (defined $params) {
1807         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1808             if ($params->[$i] =~ /\S/) {
1809                 $found = 1;
1810                 last;
1811             }
1812         }
1813     }
1815     if ($found) {
1816         my %field_descrs = @$params;
1817         my $missing_parameters = "";
1818         my $unused_parameters = "";
1820         $desc .= "<variablelist role=\"enum\">\n";
1821         for my $field_name (@fields) {
1822             my $field_descr = $field_descrs{$field_name};
1823             my $param_annotations = "";
1825             $id = &CreateValidSGMLID ($field_name);
1826             $condition = &MakeConditionDescription ($field_name);
1827             $desc .= "<varlistentry id=\"$id\" role=\"constant\"$condition>\n<term><literal>$field_name</literal></term>\n";
1828             if (defined $field_descr) {
1829                 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1830                 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1831                 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1832                 delete $field_descrs{$field_name};
1833             } else {
1834                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1835                     "Value description for $symbol"."::"."$field_name is missing in source code comment block.");
1836                 if ($missing_parameters ne "") {
1837                   $missing_parameters .= ", ".$field_name;
1838                 } else {
1839                     $missing_parameters = $field_name;
1840                 }
1841                 $desc .= "<listitem />\n";
1842             }
1843             $desc .= "</varlistentry>\n";
1844         }
1845         $desc .= "</variablelist>";
1846         foreach my $field_name (keys %field_descrs) {
1847             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1848                 "Value description for $symbol"."::"."$field_name is not used from source code comment block.");
1849             if ($unused_parameters ne "") {
1850               $unused_parameters .= ", ".$field_name;
1851             } else {
1852                $unused_parameters = $field_name;
1853             }
1854         }
1856         # remember missing/unused parameters (needed in tmpl-free build)
1857         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1858             $AllIncompleteSymbols{$symbol}=$missing_parameters;
1859         }
1860         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1861             $AllUnusedSymbols{$symbol}=$unused_parameters;
1862         }
1863     }
1864     else {
1865         if (scalar(@fields) > 0) {
1866             if (! exists ($AllIncompleteSymbols{$symbol})) {
1867                 $AllIncompleteSymbols{$symbol}="<items>";
1868                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1869                     "Value descriptions for $symbol are missing in source code comment block.");
1870             }
1871         }
1872     }
1874     $desc .= OutputSymbolTraits ($symbol);
1875     $desc .= "</refsect2>\n";
1876     return ($synop, $desc);
1880 #############################################################################
1881 # Function    : OutputVariable
1882 # Description : Returns the synopsis and detailed description of a variable.
1883 # Arguments   : $symbol - the extern'ed variable.
1884 #               $declaration - the declaration of the variable.
1885 #############################################################################
1887 sub OutputVariable {
1888     my ($symbol, $declaration) = @_;
1889     my $id = &CreateValidSGMLID ($symbol);
1890     my $condition = &MakeConditionDescription ($symbol);
1892     my $synop;
1893     if ($declaration =~ m/^\s*extern\s+((const\s+|signed\s+|unsigned\s+)*\w+)(\s+\*+|\*+|\s)(\s*)([A-Za-z]\w*)\s*;/) {
1894         my $mod = defined ($1) ? $1 : "";
1895         my $ptr = defined ($3) ? $3 : "";
1896         my $space = defined ($4) ? $4 : "";
1897         $synop = &MakeReturnField("extern") . "$mod$ptr$space<link linkend=\"$id\">$symbol</link>;\n";
1899     } else {
1900         $synop = &MakeReturnField("extern") . "<link linkend=\"$id\">$symbol</link>;\n";
1901     }
1903     my $desc = "<refsect2 id=\"$id\" role=\"variable\"$condition>\n<title>$symbol</title>\n";
1905     $desc .= MakeIndexterms($symbol, $id);
1906     $desc .= "\n";
1907     $desc .= OutputSymbolExtraLinks($symbol);
1909     my $decl_out = &CreateValidSGML ($declaration);
1910     $desc .= "<programlisting>$decl_out</programlisting>\n";
1912     $desc .= &MakeDeprecationNote($symbol);
1914     if (defined ($SymbolDocs{$symbol})) {
1915         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1916     }
1917     $desc .= OutputSymbolTraits ($symbol);
1918     $desc .= "</refsect2>\n";
1919     return ($synop, $desc);
1923 #############################################################################
1924 # Function    : OutputFunction
1925 # Description : Returns the synopsis and detailed description of a function.
1926 # Arguments   : $symbol - the function.
1927 #               $declaration - the declaration of the function.
1928 #############################################################################
1930 sub OutputFunction {
1931     my ($symbol, $declaration, $symbol_type) = @_;
1932     my $id = &CreateValidSGMLID ($symbol);
1933     my $condition = &MakeConditionDescription ($symbol);
1935     # Take out the return type     $1                                                                                     $3   $4
1936     $declaration =~ s/<RETURNS>\s*((const\s+|G_CONST_RETURN\s+|signed\s+|unsigned\s+|long\s+|short\s+|struct\s+|enum\s+)*)(\w+)(\s*\**\s*(const|G_CONST_RETURN)?\s*\**\s*(restrict)?\s*)<\/RETURNS>\n//;
1937     my $type_modifier = defined($1) ? $1 : "";
1938     my $type = $3;
1939     my $pointer = $4;
1940     #print "$symbol pointer is $pointer\n";
1941     my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1942     my $start = "";
1943     #if ($symbol_type eq 'USER_FUNCTION') {
1944     #    $start = "typedef ";
1945     #}
1947     # We output const rather than G_CONST_RETURN.
1948     $type_modifier =~ s/G_CONST_RETURN/const/g;
1949     $pointer =~ s/G_CONST_RETURN/const/g;
1950     $pointer =~ s/^\s+/ /g;
1952     my $ret_type_len = length ($start) + length ($type_modifier)
1953         + length ($pointer) + length ($type);
1954     my $ret_type_output;
1955     my $symbol_len;
1956     if ($ret_type_len < $RETURN_TYPE_FIELD_WIDTH) {
1957         $ret_type_output = "$start$type_modifier$xref$pointer"
1958             . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
1959         $symbol_len = 0;
1960     } else {
1961         #$ret_type_output = "$start$type_modifier$xref$pointer\n" . (' ' x $RETURN_TYPE_FIELD_WIDTH);
1963         $ret_type_output = "$start$type_modifier$xref$pointer ";
1964         $symbol_len = $ret_type_len + 1 - $RETURN_TYPE_FIELD_WIDTH;
1965     }
1967     $symbol_len += length ($symbol);
1968     my $char1 = my $char2 = my $char3 = "";
1969     if ($symbol_type eq 'USER_FUNCTION') {
1970         $symbol_len += 3;
1971         $char1 = "(";
1972         $char2 = "*";
1973         $char3 = ")";
1974     }
1976     my ($symbol_output, $symbol_desc_output);
1977     if ($symbol_len < $SYMBOL_FIELD_WIDTH) {
1978         $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3"
1979             . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1980         $symbol_desc_output = "$char1$char2$symbol$char3"
1981             . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1982     } else {
1983         $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3\n"
1984             . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1985         $symbol_desc_output = "$char1$char2$symbol$char3\n"
1986             . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1987     }
1989     my $synop = $ret_type_output . $symbol_output . '(';
1990     my $desc = "<refsect2 id=\"$id\" role=\"function\"$condition>\n<title>${symbol} ()</title>\n";
1992     $desc .= MakeIndexterms($symbol, $id);
1993     $desc .= "\n";
1994     $desc .= OutputSymbolExtraLinks($symbol);
1996     $desc  .= "<programlisting>${ret_type_output}$symbol_desc_output(";
1997     
1998     my @fields = ParseFunctionDeclaration($declaration, \&MakeXRef,
1999                                         sub {
2000                                             &tagify($_[0],"parameter");
2001                                         });
2002     
2003     for (my $i = 1; $i <= $#fields; $i += 2) {
2004         my $field_name = $fields[$i];
2005         
2006         if ($field_name eq "Varargs") {
2007             $field_name = "...";
2008         }
2010         if ($i == 1) {
2011             $synop .= "$field_name";
2012             $desc  .= "$field_name";
2013         } else {
2014             $synop .= ",\n"
2015                 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2016                 . " $field_name";
2017             $desc  .= ",\n"
2018                 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2019                 . " $field_name";
2020         }
2021         
2022     }
2024     $synop .= ");\n";
2025     $desc  .= ");</programlisting>\n";
2027     $desc .= &MakeDeprecationNote($symbol);
2029     my $parameters = &OutputParamDescriptions ("FUNCTION", $symbol, @fields);
2030     my $parameters_output = 0;
2032     if (defined ($SymbolDocs{$symbol})) {
2033         my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
2035         # Try to insert the parameter table at the author's desired position.
2036         # Otherwise we need to tag it onto the end.
2037         # FIXME: document that in the user manual and make it useable for other
2038         # types too
2039         if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
2040           $parameters_output = 1;
2041         }
2042         $desc .= $symbol_docs;
2043     }
2045     if ($parameters_output == 0) {
2046         $desc .= $parameters;
2047     }
2049     $desc .= OutputSymbolTraits ($symbol);
2050     $desc .= "</refsect2>\n";
2051     return ($synop, $desc);
2055 #############################################################################
2056 # Function    : OutputParamDescriptions
2057 # Description : Returns the DocBook output describing the parameters of a
2058 #               function, macro or signal handler.
2059 # Arguments   : $symbol_type - 'FUNCTION', 'MACRO' or 'SIGNAL'. Signal
2060 #                 handlers have an implicit user_data parameter last.
2061 #               $symbol - the name of the function/macro being described.
2062 #               @fields - parsed fields from the declaration, used to determine
2063 #                  undocumented/unused entries
2064 #############################################################################
2066 sub OutputParamDescriptions {
2067     my ($symbol_type, $symbol, @fields) = @_;
2068     my $output = "";
2069     my $params = $SymbolParams{$symbol};
2070     my $num_params = 0;
2071     my %field_descrs = ();
2073     if (@fields) {
2074         %field_descrs = @fields;
2075         delete $field_descrs{"void"};
2076         delete $field_descrs{"Returns"};
2077     }
2079     if (defined $params) {
2080         my $returns = "";
2081         my $params_desc = "";
2082         my $missing_parameters = "";
2083         my $unused_parameters = "";
2084         my $j;
2086         for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
2087             my $param_name = $$params[$j];
2088             my $param_desc = $$params[$j + 1];
2089             my $param_annotations = "";
2090             
2091             ($param_desc,$param_annotations) = & ExpandAnnotation($symbol, $param_desc);
2092             $param_desc = &ExpandAbbreviations($symbol, $param_desc);
2093             $param_desc .= $param_annotations;
2094             if ($param_name eq "Returns") {
2095                 $returns = "$param_desc";
2096             } elsif ($param_name eq "void") {
2097                 #print "!!!! void in params for $symbol?\n";
2098             } else {
2099                 if (@fields) {
2100                     if (!defined $field_descrs{$param_name}) {
2101                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2102                             "Parameter description for $symbol"."::"."$param_name is not used from source code comment block.");
2103                         if ($unused_parameters ne "") {
2104                           $unused_parameters .= ", ".$param_name;
2105                         } else {
2106                            $unused_parameters = $param_name;
2107                         }
2108                     } else {
2109                         delete $field_descrs{$param_name};
2110                     }
2111                 }
2112                 if ($param_name eq "Varargs") {
2113                     $param_name = "...";
2114                 }
2115                 if($param_desc ne "") {
2116                     $params_desc .= "<varlistentry><term><parameter>$param_name</parameter>&#160;:</term>\n<listitem><simpara>$param_desc</simpara></listitem></varlistentry>\n";
2117                     $num_params++;
2118                 }
2119             }
2120         }
2121         foreach my $param_name (keys %field_descrs) {
2122             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2123                 "Parameter description for $symbol"."::"."$param_name is missing in source code comment block.");
2124             if ($missing_parameters ne "") {
2125               $missing_parameters .= ", ".$param_name;
2126             } else {
2127                $missing_parameters = $param_name;
2128             }
2129         }
2131         # Signals have an implicit user_data parameter which we describe.
2132         if ($symbol_type eq "SIGNAL") {
2133             $params_desc .= "<varlistentry><term><parameter>user_data</parameter>&#160;:</term>\n<listitem><simpara>user data set when the signal handler was connected.</simpara></listitem></varlistentry>\n";
2134         }
2136         # Start a table if we need one.
2137         if ($params_desc || $returns) {
2138             $output .= "<variablelist role=\"params\">\n";
2139             if ($params_desc ne "") {
2140                 #$output .= "<varlistentry><term>Parameters:</term><listitem></listitem></varlistentry>\n";
2141                 $output .= $params_desc;
2142             }
2144             # Output the returns info last.
2145             if ($returns) {
2146                 $output .= "<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara>$returns</simpara></listitem></varlistentry>\n";
2147             }
2149             # Finish the table.
2150             $output .= "</variablelist>";
2151         }
2153         # remember missing/unused parameters (needed in tmpl-free build)
2154         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
2155             $AllIncompleteSymbols{$symbol}=$missing_parameters;
2156         }
2157         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
2158             $AllUnusedSymbols{$symbol}=$unused_parameters;
2159         }
2160     }
2161     if (($num_params == 0) && @fields && (scalar(keys(%field_descrs)) > 0)) {
2162         if (! exists ($AllIncompleteSymbols{$symbol})) {
2163             $AllIncompleteSymbols{$symbol}="<parameters>";
2164         }
2165     }
2166     
2167     return $output;
2171 #############################################################################
2172 # Function    : ParseStabilityLevel
2173 # Description : Parses a stability level and outputs a warning if it isn't
2174 #               valid.
2175 # Arguments   : $stability - the stability text.
2176 #               $file, $line - context for error message
2177 #               $message - description of where the level is from, to use in
2178 #               any error message.
2179 # Returns     : The parsed stability level string.
2180 #############################################################################
2182 sub ParseStabilityLevel {
2183     my ($stability, $file, $line, $message) = @_;
2185     $stability =~ s/^\s*//;
2186     $stability =~ s/\s*$//;
2187     if ($stability =~ m/^stable$/i) {
2188         $stability = "Stable";
2189     } elsif ($stability =~ m/^unstable$/i) {
2190         $stability = "Unstable";
2191     } elsif ($stability =~ m/^private$/i) {
2192         $stability = "Private";
2193     } else {
2194         &LogWarning ($file, $line, "$message is $stability.".
2195             "It should be one of these: Stable, Unstable, or Private.");
2196     }
2197     return $stability;
2201 #############################################################################
2202 # Function    : OutputSGMLFile
2203 # Description : Outputs the final DocBook file for one section.
2204 # Arguments   : $file - the name of the file.
2205 #               $title - the title from the $MODULE-sections.txt file, which
2206 #                 will be overridden by the title in the template file.
2207 #               $section_id - the SGML id to use for the toplevel tag.
2208 #               $includes - comma-separates list of include files added at top
2209 #                 of synopsis, with '<' '>' around them (if not already enclosed in "").
2210 #               $synopsis - reference to the DocBook for the Synopsis part.
2211 #               $details - reference to the DocBook for the Details part.
2212 #               $signal_synop - reference to the DocBook for the Signal Synopsis part
2213 #               $signal_desc - reference to the DocBook for the Signal Description part
2214 #               $args_synop - reference to the DocBook for the Arg Synopsis part
2215 #               $args_desc - reference to the DocBook for the Arg Description part
2216 #               $hierarchy - reference to the DocBook for the Object Hierarchy part
2217 #               $interfaces - reference to the DocBook for the Interfaces part
2218 #               $implementations - reference to the DocBook for the Known Implementations part
2219 #               $prerequisites - reference to the DocBook for the Prerequisites part
2220 #               $derived - reference to the DocBook for the Derived Interfaces part
2221 #               $file_objects - reference to an array of objects in this file
2222 #############################################################################
2224 sub OutputSGMLFile {
2225     my ($file, $title, $section_id, $includes, $synopsis, $details, $signals_synop, $signals_desc, $args_synop, $args_desc, $hierarchy, $interfaces, $implementations, $prerequisites, $derived, $file_objects) = @_;
2227     #print "Output sgml for file $file with title '$title'\n";
2228     
2229     # The edited title overrides the one from the sections file.
2230     my $new_title = $SymbolDocs{"$TMPL_DIR/$file:Title"};
2231     if (defined ($new_title) && $new_title !~ m/^\s*$/) {
2232         $title = $new_title;
2233         #print "Found title: $title\n";
2234     }
2235     my $short_desc = $SymbolDocs{"$TMPL_DIR/$file:Short_Description"};
2236     if (!defined ($short_desc) || $short_desc =~ m/^\s*$/) {
2237         $short_desc = "";
2238     } else {
2239         $short_desc = &ExpandAbbreviations("$title:Short_description",
2240                                            $short_desc);
2241         #print "Found short_desc: $short_desc";
2242     }
2243     my $long_desc = $SymbolDocs{"$TMPL_DIR/$file:Long_Description"};
2244     if (!defined ($long_desc) || $long_desc =~ m/^\s*$/) {
2245         $long_desc = "";
2246     } else {
2247         $long_desc = &ExpandAbbreviations("$title:Long_description",
2248                                           $long_desc);
2249         #print "Found long_desc: $long_desc";
2250     }
2251     my $see_also = $SymbolDocs{"$TMPL_DIR/$file:See_Also"};
2252     if (!defined ($see_also) || $see_also =~ m%^\s*(<para>)?\s*(</para>)?\s*$%) {
2253         $see_also = "";
2254     } else {
2255         $see_also = &ExpandAbbreviations("$title:See_Also", $see_also);
2256         #print "Found see_also: $see_also";
2257     }
2258     if ($see_also) {
2259         $see_also = "<refsect1 id=\"$section_id.see-also\">\n<title>See Also</title>\n$see_also\n</refsect1>\n";
2260     }
2261     my $stability = $SymbolDocs{"$TMPL_DIR/$file:Stability_Level"};
2262     if (!defined ($stability) || $stability =~ m/^\s*$/) {
2263         $stability = "";
2264     } else {
2265         $stability = &ParseStabilityLevel($stability, $file, $., "Section stability level");
2266         #print "Found stability: $stability";
2267     }
2268     if ($stability) {
2269         $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$stability, unless otherwise indicated\n</refsect1>\n";
2270     } elsif ($DEFAULT_STABILITY) {
2271         $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$DEFAULT_STABILITY, unless otherwise indicated\n</refsect1>\n";
2272     }
2274     my $image = $SymbolDocs{"$TMPL_DIR/$file:Image"};
2275     if (!defined ($image) || $image =~ m/^\s*$/) {
2276       $image = "";
2277     } else {
2278       $image =~ s/^\s*//;
2279       $image =~ s/\s*$//;
2281       my $format;
2283       if ($image =~ /jpe?g$/i) {
2284         $format = "format='JPEG'";
2285       } elsif ($image =~ /png$/i) {
2286         $format = "format='PNG'";
2287       } elsif ($image =~ /svg$/i) {
2288         $format = "format='SVG'";
2289       } else {
2290         $format = "";
2291       }
2293       $image = "  <inlinegraphic fileref='$image' $format/>\n"
2294     }
2296     my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
2297         gmtime (time);
2298     my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
2299     $year += 1900;
2301     my $include_output = "";
2302     my $include;
2303     foreach $include (split (/,/, $includes)) {
2304         if ($include =~ m/^\".+\"$/) {
2305             $include_output .= "#include ${include}\n";
2306         }
2307         else {
2308             $include =~ s/^\s+|\s+$//gs;
2309             $include_output .= "#include &lt;${include}&gt;\n";
2310         }
2311     }
2312     if ($include_output ne '') {
2313         $include_output = "\n$include_output\n";
2314     }
2315     
2316     my $extralinks = OutputSectionExtraLinks($title,"Section:$file");
2318     my $old_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT";
2319     my $new_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT.new";
2321     open (OUTPUT, ">$new_sgml_file")
2322         || die "Can't create $new_sgml_file: $!";
2324     my $object_anchors = "";
2325     foreach my $object (@$file_objects) {
2326         next if ($object eq $section_id);
2327         my $id = CreateValidSGMLID($object);
2328         #print "Debug: Adding anchor for $object\n";
2329         $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
2330     }
2332     # We used to output this, but is messes up our UpdateFileIfChanged code
2333     # since it changes every day (and it is only used in the man pages):
2334     # "<refentry id="$section_id" revision="$mday $month $year">"
2336     if ($OUTPUT_FORMAT eq "xml") {
2337         print OUTPUT $doctype_header;
2338     }
2340     print OUTPUT <<EOF;
2341 <refentry id="$section_id">
2342 <refmeta>
2343 <refentrytitle role="top_of_page" id="$section_id.top_of_page">$title</refentrytitle>
2344 <manvolnum>3</manvolnum>
2345 <refmiscinfo>
2346   \U$MODULE\E Library
2347 $image</refmiscinfo>
2348 </refmeta>
2349 <refnamediv>
2350 <refname>$title</refname>
2351 <refpurpose>$short_desc</refpurpose>
2352 </refnamediv>
2353 $stability
2354 <refsynopsisdiv id="$section_id.synopsis" role="synopsis">
2355 <title role="synopsis.title">Synopsis</title>
2356 $object_anchors
2357 <synopsis>$include_output$${synopsis}</synopsis>
2358 </refsynopsisdiv>
2359 $$hierarchy$$prerequisites$$derived$$interfaces$$implementations$$args_synop$$signals_synop
2360 <refsect1 id="$section_id.description" role="desc">
2361 <title role="desc.title">Description</title>
2362 $extralinks$long_desc
2363 </refsect1>
2364 <refsect1 id="$section_id.details" role="details">
2365 <title role="details.title">Details</title>
2366 $$details
2367 </refsect1>
2368 $$args_desc$$signals_desc$see_also
2369 </refentry>
2371     close (OUTPUT);
2373     return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2377 #############################################################################
2378 # Function    : OutputExtraFile
2379 # Description : Copies an "extra" DocBook file into the output directory,
2380 #               expanding abbreviations
2381 # Arguments   : $file - the source file.
2382 #############################################################################
2383 sub OutputExtraFile {
2384     my ($file) = @_;
2386     my $basename;
2388     ($basename = $file) =~ s!^.*/!!;
2390     my $old_sgml_file = "$SGML_OUTPUT_DIR/$basename";
2391     my $new_sgml_file = "$SGML_OUTPUT_DIR/$basename.new";
2393     my $contents;
2395     open(EXTRA_FILE, "<$file") || die "Can't open $file";
2397     {
2398         local $/;
2399         $contents = <EXTRA_FILE>;
2400     }
2402     open (OUTPUT, ">$new_sgml_file")
2403         || die "Can't create $new_sgml_file: $!";
2405     print OUTPUT &ExpandAbbreviations ("$basename file", $contents);
2406     close (OUTPUT);
2408     return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2410 #############################################################################
2411 # Function    : OutputBook
2412 # Description : Outputs the SGML entities that need to be included into the
2413 #               main SGML file for the module.
2414 # Arguments   : $book_top - the declarations of the entities, which are added
2415 #                 at the top of the main SGML file.
2416 #               $book_bottom - the references to the entities, which are
2417 #                 added in the main SGML file at the desired position.
2418 #############################################################################
2420 sub OutputBook {
2421     my ($book_top, $book_bottom) = @_;
2423     my $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top";
2424     my $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top.new";
2426     open (OUTPUT, ">$new_file")
2427         || die "Can't create $new_file: $!";
2428     print OUTPUT $book_top;
2429     close (OUTPUT);
2431     &UpdateFileIfChanged ($old_file, $new_file, 0);
2434     $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom";
2435     $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom.new";
2437     open (OUTPUT, ">$new_file")
2438         || die "Can't create $new_file: $!";
2439     print OUTPUT $book_bottom;
2440     close (OUTPUT);
2442     &UpdateFileIfChanged ($old_file, $new_file, 0);
2445     # If the main SGML/XML file hasn't been created yet, we create it here.
2446     # The user can tweak it later.
2447     if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
2448       open (OUTPUT, ">$MAIN_SGML_FILE")
2449         || die "Can't create $MAIN_SGML_FILE: $!";
2451       if ($OUTPUT_FORMAT eq "xml") {
2452           print OUTPUT <<EOF;
2453 <?xml version="1.0"?>
2454 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
2455                "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
2457   <!ENTITY % local.common.attrib "xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'">
2459 <book id="index">
2461       } else {
2462         print OUTPUT <<EOF;
2463 <!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
2464 $book_top
2466 <book id="index">
2468       }
2470 print OUTPUT <<EOF;
2471   <bookinfo>
2472     <title>$MODULE Reference Manual</title>
2473     <releaseinfo>
2474       for $MODULE [VERSION].
2475       The latest version of this documentation can be found on-line at
2476       <ulink role="online-location" url="http://[SERVER]/$MODULE/index.html">http://[SERVER]/$MODULE/</ulink>.
2477     </releaseinfo>
2478   </bookinfo>
2480   <chapter>
2481     <title>[Insert title here]</title>
2482     $book_bottom
2483   </chapter>
2485   if (-e $OBJECT_TREE_FILE) {
2486     print OUTPUT <<EOF;
2487   <chapter id="object-tree">
2488     <title>Object Hierarchy</title>
2489      <xi:include href="xml/tree_index.sgml"/>
2490   </chapter>
2492   }
2494 print OUTPUT <<EOF;
2495   <index id="api-index-full">
2496     <title>API Index</title>
2497     <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
2498   </index>
2499   <index id="deprecated-api-index" role="deprecated">
2500     <title>Index of deprecated API</title>
2501     <xi:include href="xml/api-index-deprecated.xml"><xi:fallback /></xi:include>
2502   </index>
2504   <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
2505 </book>
2508       close (OUTPUT);
2509     }
2513 #############################################################################
2514 # Function    : CreateValidSGML
2515 # Description : This turns any chars which are used in SGML into entities,
2516 #               e.g. '<' into '&lt;'
2517 # Arguments   : $text - the text to turn into proper SGML.
2518 #############################################################################
2520 sub CreateValidSGML {
2521     my ($text) = @_;
2522     $text =~ s/&/&amp;/g;       # Do this first, or the others get messed up.
2523     $text =~ s/</&lt;/g;
2524     $text =~ s/>/&gt;/g;
2525     # browers render single tabs inconsistently
2526     $text =~ s/([^\s])\t([^\s])/$1&#160;$2/g;
2527     return $text;
2530 #############################################################################
2531 # Function    : ConvertSGMLChars
2532 # Description : This is used for text in source code comment blocks, to turn
2533 #               chars which are used in SGML into entities, e.g. '<' into
2534 #               '&lt;'. Depending on $INLINE_MARKUP_MODE, this is done
2535 #               unconditionally or only if the character doesn't seem to be
2536 #               part of an SGML construct (tag or entity reference).
2537 # Arguments   : $text - the text to turn into proper SGML.
2538 #############################################################################
2540 sub ConvertSGMLChars {
2541     my ($symbol, $text) = @_;
2543     if ($INLINE_MARKUP_MODE) {
2544         # For the XML/SGML mode only convert to entities outside CDATA sections.
2545         return &ModifyXMLElements ($text, $symbol,
2546                                    "<!\\[CDATA\\[|<programlisting[^>]*>",
2547                                    \&ConvertSGMLCharsEndTag,
2548                                    \&ConvertSGMLCharsCallback);
2549     } else {
2550         # For the simple non-sgml mode, convert to entities everywhere.
2551         $text =~ s/&/&amp;/g;   # Do this first, or the others get messed up.
2552         $text =~ s/</&lt;/g;
2553         $text =~ s/>/&gt;/g;
2554         return $text;
2555     }
2559 sub ConvertSGMLCharsEndTag {
2560   if ($_[0] eq "<!\[CDATA\[") {
2561     return "]]>";
2562   } else {
2563     return "</programlisting>";
2564   }
2567 sub ConvertSGMLCharsCallback {
2568   my ($text, $symbol, $tag) = @_;
2570   if ($tag =~ m/^<programlisting/) {
2571     # We can handle <programlisting> specially here.
2572     return &ModifyXMLElements ($text, $symbol,
2573                                "<!\\[CDATA\\[",
2574                                \&ConvertSGMLCharsEndTag,
2575                                \&ConvertSGMLCharsCallback2);
2576   } elsif ($tag eq "") {
2577     # If we're not in CDATA convert to entities.
2578     $text =~ s/&(?![a-zA-Z#]+;)/&amp;/g;        # Do this first, or the others get messed up.
2579     $text =~ s/<(?![a-zA-Z\/!])/&lt;/g;
2580     $text =~ s/(?<![a-zA-Z0-9"'\/-])>/&gt;/g;
2582     # Handle "#include <xxxxx>"
2583     $text =~ s/#include(\s+)<([^>]+)>/#include$1&lt;$2&gt;/g;
2584   }
2586   return $text;
2589 sub ConvertSGMLCharsCallback2 {
2590   my ($text, $symbol, $tag) = @_;
2592   # If we're not in CDATA convert to entities.
2593   # We could handle <programlisting> differently, though I'm not sure it helps.
2594   if ($tag eq "") {
2595     # replace only if its not a tag
2596     $text =~ s/&(?![a-zA-Z#]+;)/&amp;/g;        # Do this first, or the others get messed up.
2597     $text =~ s/<(?![a-zA-Z\/!])/&lt;/g;
2598     $text =~ s/(?<![a-zA-Z0-9"'\/-])>/&gt;/g;
2600     # Handle "#include <xxxxx>"
2601     $text =~ s/#include(\s+)<([^>]+)>/#include$1&lt;$2&gt;/g;
2602   }
2604   return $text;
2607 #############################################################################
2608 # Function    : ExpandAnnotation
2609 # Description : This turns annotations into acronym tags.
2610 # Arguments   : $symbol - the symbol being documented, for error messages.
2611 #               $text - the text to expand.
2612 #############################################################################
2613 sub ExpandAnnotation {
2614     my ($symbol, $param_desc) = @_;
2615     my $param_annotations = "";
2617     # look for annotations at the start of the comment part
2618     if ($param_desc =~ m%^\s*\((.*?)\):%) {
2619         my @annotations;
2620         my $annotation;
2621         $param_desc = $';
2622         
2623         @annotations = split(/\)\s*\(/,$1);
2624         foreach $annotation (@annotations) {
2625             # need to search for the longest key-match in %AnnotationDefinition
2626             my $match_length=0;
2627             my $match_annotation="";
2628             my $annotationdef;
2629             foreach $annotationdef (keys %AnnotationDefinition) {
2630                 if ($annotation =~ m/^$annotationdef/) {
2631                     if (length($annotationdef)>$match_length) {
2632                         $match_length=length($annotationdef);
2633                         $match_annotation=$annotationdef;
2634                     }
2635                 }
2636             }
2637             my $annotation_extra = "";
2638             if ($match_annotation ne "") {
2639                 if ($annotation =~ m%$match_annotation\s+(.*)%) {
2640                     $annotation_extra = " $1";
2641                 }
2642                 $AnnotationsUsed{$match_annotation} = 1;
2643                 $param_annotations .= "[<acronym>$match_annotation</acronym>$annotation_extra]";
2644             }
2645             else {
2646                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2647                     "unknown annotation \"$annotation\" in documentation for $symbol.");
2648                 $param_annotations .= "[$annotation]";
2649             }
2650         }
2651         chomp($param_desc);
2652         $param_desc =~ m/^(.*?)\.*\s*$/s;
2653         $param_desc = "$1. ";
2654     }
2655     if ($param_annotations ne "") {
2656         $param_annotations = "<emphasis role=\"annotation\">$param_annotations</emphasis>";
2657     }
2658     return ($param_desc, $param_annotations);
2661 #############################################################################
2662 # Function    : ExpandAbbreviations
2663 # Description : This turns the abbreviations function(), macro(), @param,
2664 #               %constant, and #symbol into appropriate DocBook markup.
2665 #               CDATA sections and <programlisting> parts are skipped.
2666 # Arguments   : $symbol - the symbol being documented, for error messages.
2667 #               $text - the text to expand.
2668 #############################################################################
2670 sub ExpandAbbreviations {
2671   my ($symbol, $text) = @_;
2673   # Convert "|[" and "]|" into the start and end of program listing examples.
2674   # FIXME: we like to have a way to specify parameters e.g. language="c"
2675   $text =~ s%\|\[%<informalexample><programlisting>%g;
2676   $text =~ s%\]\|%</programlisting></informalexample>%g;
2677   # TODO: check for a xml comment after |[ and pick the language attribute from
2678   # that
2680   # keep CDATA unmodified, preserve ulink tags (ideally we preseve all tags
2681   # as such)
2682   return &ModifyXMLElements ($text, $symbol,
2683                              "<!\\[CDATA\\[|<ulink[^>]*>|<programlisting[^>]*>|<!DOCTYPE",
2684                              \&ExpandAbbreviationsEndTag,
2685                              \&ExpandAbbreviationsCallback);
2689 # Returns the end tag corresponding to the given start tag.
2690 sub ExpandAbbreviationsEndTag {
2691   my ($start_tag) = @_;
2693   if ($start_tag eq "<!\[CDATA\[") {
2694     return "]]>";
2695   } elsif ($start_tag eq "<!DOCTYPE") {
2696     return "]>";
2697   } elsif ($start_tag =~ m/<(\w+)/) {
2698     return "</$1>";
2699   }
2702 # Called inside or outside each CDATA or <programlisting> section.
2703 sub ExpandAbbreviationsCallback {
2704   my ($text, $symbol, $tag) = @_;
2706   if ($tag =~ m/^<programlisting/) {
2707     # Handle any embedded CDATA sections.
2708     return &ModifyXMLElements ($text, $symbol,
2709                                "<!\\[CDATA\\[",
2710                                \&ExpandAbbreviationsEndTag,
2711                                \&ExpandAbbreviationsCallback2);
2712   } elsif ($tag eq "") {
2713     # We are outside any CDATA or <programlisting> sections, so we expand
2714     # any gtk-doc abbreviations.
2716     # Convert 'function()' or 'macro()'.
2717     # if there is abc_*_def() we don't want to make a link to _def()
2718     # FIXME: also handle abc(....) : but that would need to be done recursively :/
2719     $text =~ s/([^\*.\w])(\w+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2720     # handle #Object.func()
2721     $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2723     # Convert '@param', but not '\@param'.
2724     $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)/$1<parameter>$2<\/parameter>/g;
2725     $text =~ s/\\\@/\@/g;
2727     # Convert '%constant', but not '\%constant'.
2728     # Also allow negative numbers, e.g. %-1.
2729     $text =~ s/(\A|[^\\])\%(-?\w+)/$1.&MakeXRef($2, &tagify($2, "literal"));/eg;
2730     $text =~ s/\\\%/\%/g;
2732     # Convert '#symbol', but not '\#symbol'.
2733     $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)/$1.&MakeHashXRef($2, "type");/eg;
2734     $text =~ s/\\#/#/g;
2735     
2736     # Expand urls
2737     # FIXME: should we skip urls that are already tagged? (e.g. <literal>http://...</literal>)
2738     # this is apparently also called for markup and not just for plain text
2739     # disable for now.
2740     #$text =~ s%(http|https|ftp)://(.*?)((?:\s|,|\)|\]|\<|\.\s))%<ulink url="$1://$2">$2</ulink>$3%g;
2742     # TODO: optionally check all words from $text against internal symbols and
2743     # warn if those could be xreffed, but miss a %,# or ()
2744   }
2746   return $text;
2749 # This is called inside a <programlisting>
2750 sub ExpandAbbreviationsCallback2 {
2751   my ($text, $symbol, $tag) = @_;
2753   if ($tag eq "") {
2754     # We are inside a <programlisting> but outside any CDATA sections,
2755     # so we expand any gtk-doc abbreviations.
2756     # FIXME: why is this different from &ExpandAbbreviationsCallback(),
2757     #        why not just call it
2758     $text =~ s/#(\w+)/&MakeHashXRef($1, "");/eg;
2759   }
2761   return $text;
2764 sub MakeHashXRef {
2765     my ($symbol, $tag) = @_;;
2766     my $text = $symbol;
2768     # Check for things like '#include', '#define', and skip them.
2769     if ($PreProcessorDirectives{$symbol}) {
2770       return "#$symbol";
2771     }
2773     # Get rid of any special '-struct' suffix.
2774     $text =~ s/-struct$//;
2776     # If the symbol is in the form "Object::signal", then change the symbol to
2777     # "Object-signal" and use "signal" as the text.
2778     if ($symbol =~ s/::/-/) {
2779       $text = "\"$'\"";
2780     }
2782     # If the symbol is in the form "Object:property", then change the symbol to
2783     # "Object--property" and use "property" as the text.
2784     if ($symbol =~ s/:/--/) {
2785       $text = "\"$'\"";
2786     }
2788     if ($tag ne "") {
2789       $text = tagify ($text, $tag);
2790     }
2791     
2792     return &MakeXRef($symbol, $text);
2796 #############################################################################
2797 # Function    : ModifyXMLElements
2798 # Description : Looks for given XML element tags within the text, and calls
2799 #               the callback on pieces of text inside & outside those elements.
2800 #               Used for special handling of text inside things like CDATA
2801 #               and <programlisting>.
2802 # Arguments   : $text - the text.
2803 #               $symbol - the symbol currently being documented (only used for
2804 #                      error messages).
2805 #               $start_tag_regexp - the regular expression to match start tags.
2806 #                      e.g. "<!\\[CDATA\\[|<programlisting[^>]*>" to match
2807 #                      CDATA sections or programlisting elements.
2808 #               $end_tag_func - function which is passed the matched start tag
2809 #                      and should return the appropriate end tag string.
2810 #               $callback - callback called with each part of the text. It is
2811 #                      called with a piece of text, the symbol being
2812 #                      documented, and the matched start tag or "" if the text
2813 #                      is outside the XML elements being matched.
2814 #############################################################################
2815 sub ModifyXMLElements {
2816     my ($text, $symbol, $start_tag_regexp, $end_tag_func, $callback) = @_;
2817     my ($before_tag, $start_tag, $end_tag_regexp, $end_tag);
2818     my $result = "";
2820     while ($text =~ m/$start_tag_regexp/s) {
2821       $before_tag = $`; # Prematch for last successful match string
2822       $start_tag = $&;  # Last successful match
2823       $text = $';       # Postmatch for last successful match string
2825       $result .= &$callback ($before_tag, $symbol, "");
2826       $result .= $start_tag;
2828       # get the mathing end-tag for current tag
2829       $end_tag_regexp = &$end_tag_func ($start_tag);
2831       if ($text =~ m/$end_tag_regexp/s) {
2832         $before_tag = $`;
2833         $end_tag = $&;
2834         $text = $';
2836         $result .= &$callback ($before_tag, $symbol, $start_tag);
2837         $result .= $end_tag;
2838       } else {
2839         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2840             "Can't find tag end: $end_tag_regexp in docs for: $symbol.");
2841         # Just assume it is all inside the tag.
2842         $result .= &$callback ($text, $symbol, $start_tag);
2843         $text = "";
2844       }
2845     }
2847     # Handle any remaining text outside the tags.
2848     $result .= &$callback ($text, $symbol, "");
2850     return $result;
2853 sub noop {
2854   return $_[0];
2857 # Adds a tag around some text.
2858 # e.g tagify("Text", "literal") => "<literal>Text</literal>".
2859 sub tagify {
2860    my ($text, $elem) = @_;
2861    return "<" . $elem . ">" . $text . "</" . $elem . ">";
2865 #############################################################################
2866 # Function    : MakeXRef
2867 # Description : This returns a cross-reference link to the given symbol.
2868 #               Though it doesn't try to do this for a few standard C types
2869 #               that it knows won't be in the documentation.
2870 # Arguments   : $symbol - the symbol to try to create a XRef to.
2871 #               $text - text text to put inside the XRef, defaults to $symbol
2872 #############################################################################
2874 sub MakeXRef {
2875     my ($symbol, $text) = ($_[0], $_[1]);
2877     $symbol =~ s/^\s+//;
2878     $symbol =~ s/\s+$//;
2880     if (!defined($text)) {
2881         $text = $symbol;
2883         # Get rid of special '-struct' suffix.
2884         $text =~ s/-struct$//;
2885     }
2887     if ($symbol =~ m/ /) {
2888         return "$text";
2889     }
2891     #print "Getting type link for $symbol -> $text\n";
2893     my $symbol_id = &CreateValidSGMLID ($symbol);
2894     return "<link linkend=\"$symbol_id\">$text</link>";
2898 #############################################################################
2899 # Function    : MakeIndexterms
2900 # Description : This returns a indexterm elements for the given symbol
2901 # Arguments   : $symbol - the symbol to create indexterms for
2902 #############################################################################
2904 sub MakeIndexterms {
2905   my ($symbol, $id) = @_;
2906   my $terms =  "";
2907   my $sortas = "";
2908   
2909   # make the index useful, by ommiting the namespace when sorting
2910   if ($NAME_SPACE ne "") {
2911     if ($symbol =~ m/^$NAME_SPACE\_?(.*)/i) {
2912        $sortas=" sortas=\"$1\"";
2913     }
2914   }
2916   if (exists $Deprecated{$symbol}) {
2917       $terms .= "<indexterm zone=\"$id\" role=\"deprecated\"><primary$sortas>$symbol</primary></indexterm>";
2918       $IndexEntriesDeprecated{$symbol}=$id;
2919       $IndexEntriesFull{$symbol}=$id;
2920   }
2921   if (exists $Since{$symbol}) {
2922      my $since = $Since{$symbol};
2923      $since =~ s/^\s+//;
2924      $since =~ s/\s+$//;
2925      if ($since ne "") {
2926          $terms .= "<indexterm zone=\"$id\" role=\"$since\"><primary$sortas>$symbol</primary></indexterm>";
2927      }
2928      $IndexEntriesSince{$symbol}=$id;
2929      $IndexEntriesFull{$symbol}=$id;
2930   }
2931   if ($terms eq "") {
2932      $terms .= "<indexterm zone=\"$id\"><primary$sortas>$symbol</primary></indexterm>";
2933      $IndexEntriesFull{$symbol}=$id;
2934   }
2936   return $terms;
2939 #############################################################################
2940 # Function    : MakeDeprecationNote
2941 # Description : This returns a deprecation warning for the given symbol.
2942 # Arguments   : $symbol - the symbol to try to create a warning for.
2943 #############################################################################
2945 sub MakeDeprecationNote {
2946     my ($symbol) = $_[0];
2947     my $desc = "";
2948     my $note = "";
2949     if (exists $Deprecated{$symbol}) {
2950         $desc .= "<warning>";
2952         if ($Deprecated{$symbol} =~ /^\s*([0-9\.]+)\s*:/) {
2953                 $desc .= "<para><literal>$symbol</literal> has been deprecated since version $1 and should not be used in newly-written code.";
2954         } else {
2955                 $desc .= "<para><literal>$symbol</literal> is deprecated and should not be used in newly-written code.";
2956         }
2957         if ($Deprecated{$symbol} ne "") {
2958             $note = &ExpandAbbreviations($symbol, $Deprecated{$symbol});
2959             $note =~ s/^\s*([0-9\.]+)\s*:\s*//;
2960             $note =~ s/^\s+//;
2961             $note =~ s/\s+$//;
2962             $note =~ s%\n{2,}%\n</para>\n<para>\n%g;
2963             $desc .= " " . $note;
2964         }
2965         $desc .= "</para></warning>\n";
2966     }
2967     return $desc;
2970 #############################################################################
2971 # Function    : MakeConditionDescription
2972 # Description : This returns a sumary of conditions for the given symbol.
2973 # Arguments   : $symbol - the symbol to try to create the sumary.
2974 #############################################################################
2976 sub MakeConditionDescription {
2977     my ($symbol) = $_[0];
2978     my $desc = "";
2980     if (exists $Deprecated{$symbol}) {
2981         if ($desc ne "") {
2982             $desc .= "|";
2983         }
2985         if ($Deprecated{$symbol} =~ /^\s*(.*?)\s*$/) {
2986                 $desc .= "deprecated:$1";
2987         } else {
2988                 $desc .= "deprecated";
2989         }
2990     }
2992     if (exists $Since{$symbol}) {
2993         if ($desc ne "") {
2994             $desc .= "|";
2995         }
2997         if ($Since{$symbol} =~ /^\s*(.*?)\s*$/) {
2998                 $desc .= "since:$1";
2999         } else {
3000                 $desc .= "since";
3001         }
3002     }
3004     if (exists $StabilityLevel{$symbol}) {
3005         if ($desc ne "") {
3006             $desc .= "|";
3007         }
3008         $desc .= "stability:".$StabilityLevel{$symbol};
3009     }
3011     if ($desc ne "") {
3012         $desc=" condition=\"".$desc."\"";
3013         #print "condition for '$symbol' = '$desc'\n";
3014     }
3015     return $desc;
3018 #############################################################################
3019 # Function    : GetHierarchy
3020 # Description : Returns the DocBook output describing the ancestors and
3021 #               immediate children of a GObject subclass. It uses the
3022 #               global @Objects and @ObjectLevels arrays to walk the tree.
3023 # Arguments   : $object - the GtkObject subclass.
3024 #############################################################################
3026 sub GetHierarchy {
3027     my ($object) = @_;
3029     # Find object in the objects array.
3030     my $found = 0;
3031     my @children = ();
3032     my $i;
3033     my $level;
3034     my $j;
3035     for ($i = 0; $i < @Objects; $i++) {
3036         if ($found) {
3037             if ($ObjectLevels[$i] <= $level) {
3038             last;
3039         }
3040             elsif ($ObjectLevels[$i] == $level + 1) {
3041                 push (@children, $Objects[$i]);
3042             }
3043         }
3044         elsif ($Objects[$i] eq $object) {
3045             $found = 1;
3046             $j = $i;
3047             $level = $ObjectLevels[$i];
3048         }
3049     }
3050     if (!$found) {
3051         return "";
3052     }
3054     # Walk up the hierarchy, pushing ancestors onto the ancestors array.
3055     my @ancestors = ();
3056     push (@ancestors, $object);
3057     #print "Level: $level\n";
3058     while ($level > 1) {
3059         $j--;
3060         if ($ObjectLevels[$j] < $level) {
3061             push (@ancestors, $Objects[$j]);
3062             $level = $ObjectLevels[$j];
3063             #print "Level: $level\n";
3064         }
3065     }
3067     # Output the ancestors list, indented and with links.
3068     my $hierarchy = "<synopsis>\n";
3069     $level = 0;
3070     for ($i = $#ancestors; $i >= 0; $i--) {
3071         my $link_text;
3072         # Don't add a link to the current object, i.e. when i == 0.
3073         if ($i > 0) {
3074             my $ancestor_id = &CreateValidSGMLID ($ancestors[$i]);
3075             $link_text = "<link linkend=\"$ancestor_id\">$ancestors[$i]</link>";
3076         } else {
3077             $link_text = "$ancestors[$i]";
3078         }
3079         if ($level == 0) {
3080             $hierarchy .= "  $link_text\n";
3081         } else {
3082 #           $hierarchy .= ' ' x ($level * 6 - 3) . "|\n";
3083             $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3084         }
3085         $level++;
3086     }
3087     for ($i = 0; $i <= $#children; $i++) {
3088       my $id = &CreateValidSGMLID ($children[$i]);
3089       my $link_text = "<link linkend=\"$id\">$children[$i]</link>";
3090       $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3091     }
3092     $hierarchy .= "</synopsis>\n";
3094     return $hierarchy;
3098 #############################################################################
3099 # Function    : GetInterfaces
3100 # Description : Returns the DocBook output describing the interfaces
3101 #               implemented by a class. It uses the global %Interfaces hash.
3102 # Arguments   : $object - the GtkObject subclass.
3103 #############################################################################
3105 sub GetInterfaces {
3106     my ($object) = @_;
3107     my $text = "";
3108     my $i;
3110     # Find object in the objects array.
3111     if (exists($Interfaces{$object})) {
3112         my @ifaces = split(' ', $Interfaces{$object});
3113         $text = <<EOF;
3114 <para>
3115 $object implements
3117         for ($i = 0; $i <= $#ifaces; $i++) {
3118             my $id = &CreateValidSGMLID ($ifaces[$i]);
3119             $text .= " <link linkend=\"$id\">$ifaces[$i]</link>";
3120             if ($i < $#ifaces - 1) {
3121                 $text .= ', ';
3122             }
3123             elsif ($i < $#ifaces) {
3124                 $text .= ' and ';
3125             }
3126             else {
3127                 $text .= '.';
3128             }
3129         }
3130         $text .= <<EOF;
3131 </para>
3133     }
3135     return $text;
3138 #############################################################################
3139 # Function    : GetImplementations
3140 # Description : Returns the DocBook output describing the implementations
3141 #               of an interface. It uses the global %Interfaces hash.
3142 # Arguments   : $object - the GtkObject subclass.
3143 #############################################################################
3145 sub GetImplementations {
3146     my ($object) = @_;
3147     my @impls = ();
3148     my $text = "";
3149     my $i;
3150     foreach my $key (keys %Interfaces) {
3151         if ($Interfaces{$key} =~ /\b$object\b/) {
3152             push (@impls, $key);
3153         }
3154     }
3155     if ($#impls >= 0) {
3156         @impls = sort @impls;
3157         $text = <<EOF;
3158 <para>
3159 $object is implemented by
3161         for ($i = 0; $i <= $#impls; $i++) {
3162             my $id = &CreateValidSGMLID ($impls[$i]);
3163             $text .= " <link linkend=\"$id\">$impls[$i]</link>";
3164             if ($i < $#impls - 1) {
3165                 $text .= ', ';
3166             }
3167             elsif ($i < $#impls) {
3168                 $text .= ' and ';
3169             }
3170             else {
3171                 $text .= '.';
3172             }
3173         }
3174         $text .= <<EOF;
3175 </para>
3177     }
3178     return $text;
3182 #############################################################################
3183 # Function    : GetPrerequisites
3184 # Description : Returns the DocBook output describing the prerequisites
3185 #               of an interface. It uses the global %Prerequisites hash.
3186 # Arguments   : $iface - the interface.
3187 #############################################################################
3189 sub GetPrerequisites {
3190     my ($iface) = @_;
3191     my $text = "";
3192     my $i;
3194     if (exists($Prerequisites{$iface})) {
3195         $text = <<EOF;
3196 <para>
3197 $iface requires
3199         my @prereqs = split(' ', $Prerequisites{$iface});
3200         for ($i = 0; $i <= $#prereqs; $i++) {
3201             my $id = &CreateValidSGMLID ($prereqs[$i]);
3202             $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
3203             if ($i < $#prereqs - 1) {
3204                 $text .= ', ';
3205             }
3206             elsif ($i < $#prereqs) {
3207                 $text .= ' and ';
3208             }
3209             else {
3210                 $text .= '.';
3211             }
3212         }
3213         $text .= <<EOF;
3214 </para>
3216     }
3217     return $text;
3220 #############################################################################
3221 # Function    : GetDerived
3222 # Description : Returns the DocBook output describing the derived interfaces
3223 #               of an interface. It uses the global %Prerequisites hash.
3224 # Arguments   : $iface - the interface.
3225 #############################################################################
3227 sub GetDerived {
3228     my ($iface) = @_;
3229     my $text = "";
3230     my $i;
3232     my @derived = ();
3233     foreach my $key (keys %Prerequisites) {
3234         if ($Prerequisites{$key} =~ /\b$iface\b/) {
3235             push (@derived, $key);
3236         }
3237     }
3238     if ($#derived >= 0) {
3239         @derived = sort @derived;
3240         $text = <<EOF;
3241 <para>
3242 $iface is required by
3244         for ($i = 0; $i <= $#derived; $i++) {
3245             my $id = &CreateValidSGMLID ($derived[$i]);
3246             $text .= " <link linkend=\"$id\">$derived[$i]</link>";
3247             if ($i < $#derived - 1) {
3248                 $text .= ', ';
3249             }
3250             elsif ($i < $#derived) {
3251                 $text .= ' and ';
3252             }
3253             else {
3254                 $text .= '.';
3255             }
3256         }
3257         $text .= <<EOF;
3258 </para>
3260     }
3261     return $text;
3265 #############################################################################
3266 # Function    : GetSignals
3267 # Description : Returns the synopsis and detailed description DocBook output
3268 #               for the signal handlers of a given GtkObject subclass.
3269 # Arguments   : $object - the GtkObject subclass, e.g. 'GtkButton'.
3270 #############################################################################
3272 sub GetSignals {
3273     my ($object) = @_;
3274     my $synop = "";
3275     my $desc = "";
3277     my $i;
3278     for ($i = 0; $i <= $#SignalObjects; $i++) {
3279         if ($SignalObjects[$i] eq $object) {
3280             #print "Found signal: $SignalNames[$i]\n";
3281             my $name = $SignalNames[$i];
3282             my $symbol = "${object}::${name}";
3283             my $id = &CreateValidSGMLID ("$object-$name");
3285             my $pad = ' ' x (46 - length($name));
3286             $synop .= "  &quot;<link linkend=\"$id\">$name</link>&quot;$pad ";
3288             $desc .= "<refsect2 id=\"$id\" role=\"signal\"><title>The <literal>&quot;$name&quot;</literal> signal</title>\n";
3289             $desc .= MakeIndexterms($symbol, $id);
3290             $desc .= "\n";
3291             $desc .= OutputSymbolExtraLinks($symbol);
3293             $desc .= "<programlisting>";
3295             $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
3296             my $type_modifier = defined($1) ? $1 : "";
3297             my $type = $2;
3298             my $pointer = $3;
3299             my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
3301             my $ret_type_len = length ($type_modifier) + length ($pointer)
3302                 + length ($type);
3303             my $ret_type_output = "$type_modifier$xref$pointer"
3304                 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
3306             $desc  .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
3308             my $sourceparams = $SourceSymbolParams{$symbol};
3309             my @params = split ("\n", $SignalPrototypes[$i]);
3310             my $j;
3311             my $l;
3312             my $type_len = length("gpointer");
3313             my $name_len = length("user_data");
3314             # do two passes, the first one is to calculate padding
3315             for ($l = 0; $l < 2; $l++) {
3316                 for ($j = 0; $j <= $#params; $j++) {
3317                     # allow alphanumerics, '_', '[' & ']' in param names
3318                     if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
3319                         $type = $1;
3320                         $pointer = $2;
3321                         if (defined($sourceparams)) {
3322                             $name = $$sourceparams[$PARAM_FIELD_COUNT * $j];
3323                         }
3324                         else {
3325                             $name = $3;
3326                         }
3327                         if (!defined($name)) {
3328                             $name = "arg$j";
3329                         }
3330                         if ($l == 0) {
3331                             if (length($type) + length($pointer) > $type_len) {
3332                                 $type_len = length($type) + length($pointer);
3333                             }
3334                             if (length($name) > $name_len) {
3335                                 $name_len = length($name);
3336                             }
3337                         }
3338                         else {
3339                             $xref = &MakeXRef ($type, &tagify($type, "type"));
3340                             $pad = ' ' x ($type_len - length($type) - length($pointer));
3341                             $desc .= "$xref$pad $pointer$name,\n";
3342                             $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
3343                         }
3344                     } else {
3345                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3346                              "Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]");
3347                     }
3348                 }
3349             }
3350             $xref = &MakeXRef ("gpointer", &tagify("gpointer", "type"));
3351             $pad = ' ' x ($type_len - length("gpointer"));
3352             $desc  .= "$xref$pad user_data)";
3354             my $flags = $SignalFlags[$i];
3355             my $flags_string = "";
3357             if (defined ($flags)) {
3358               if ($flags =~ m/f/) {
3359                 $flags_string = "<link linkend=\"G-SIGNAL-RUN-FIRST:CAPS\"><literal>Run First</literal></link>";
3360               }
3361               elsif ($flags =~ m/l/) {
3362                 $flags_string = "<link linkend=\"G-SIGNAL-RUN-LAST:CAPS\"><literal>Run Last</literal></link>";
3363               }
3364               elsif ($flags =~ m/c/) {
3365                 $flags_string = "<link linkend=\"G-SIGNAL-RUN-CLEANUP:CAPS\"><literal>Cleanup</literal></link>";
3366                 $flags_string = "Cleanup";
3367               }
3368               if ($flags =~ m/r/) {
3369                 if ($flags_string) { $flags_string .= " / "; }
3370                 $flags_string = "<link linkend=\"G-SIGNAL-NO-RECURSE:CAPS\"><literal>No Recursion</literal></link>";
3371               }
3372               if ($flags =~ m/d/) {
3373                 if ($flags_string) { $flags_string .= " / "; }
3374                 $flags_string = "<link linkend=\"G-SIGNAL-DETAILED:CAPS\"><literal>Has Details</literal></link>";
3375               }
3376               if ($flags =~ m/a/) {
3377                 if ($flags_string) { $flags_string .= " / "; }
3378                 $flags_string = "<link linkend=\"G-SIGNAL-ACTION:CAPS\"><literal>Action</literal></link>";
3379               }
3380               if ($flags =~ m/h/) {
3381                 if ($flags_string) { $flags_string .= " / "; }
3382                 $flags_string = "<link linkend=\"G-SIGNAL-NO-HOOKS:CAPS\"><literal>No Hooks</literal></link>";
3383               }
3384             }
3386             if ($flags_string)
3387               {
3388                 $synop .= ": $flags_string\n";
3389                 
3390                 $pad = ' ' x (5 + $name_len - length("user_data"));
3391                 $desc  .= "$pad : $flags_string</programlisting>\n";
3392               }
3393             else
3394               {
3395                 $synop .= "\n";
3396                 $desc  .= "</programlisting>\n";
3397               }
3399             $desc .= &MakeDeprecationNote($symbol);
3401             my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
3402             my $parameters_output = 0;
3404             $AllSymbols{$symbol} = 1;
3405             if (defined ($SymbolDocs{$symbol})) {
3406                 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3408                 # Try to insert the parameter table at the author's desired
3409                 # position. Otherwise we need to tag it onto the end.
3410                 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
3411                   $parameters_output = 1;
3412                 }
3413                 $desc .= $symbol_docs;
3415                 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
3416                     $AllDocumentedSymbols{$symbol} = 1;
3417                 }
3418             }
3420             if ($parameters_output == 0) {
3421                 $desc .= $parameters;
3422               }
3423             $desc .= OutputSymbolTraits ($symbol);
3424             $desc .= "</refsect2>";
3425         }
3426     }
3427     return ($synop, $desc);
3431 #############################################################################
3432 # Function    : GetArgs
3433 # Description : Returns the synopsis and detailed description DocBook output
3434 #               for the Args of a given GtkObject subclass.
3435 # Arguments   : $object - the GtkObject subclass, e.g. 'GtkButton'.
3436 #############################################################################
3438 sub GetArgs {
3439     my ($object) = @_;
3440     my $synop = "";
3441     my $desc = "";
3442     my $child_synop = "";
3443     my $child_desc = "";
3444     my $style_synop = "";
3445     my $style_desc = "";
3447     my $i;
3448     for ($i = 0; $i <= $#ArgObjects; $i++) {
3449         if ($ArgObjects[$i] eq $object) {
3450             #print "Found arg: $ArgNames[$i]\n";
3451             my $name = $ArgNames[$i];
3452             my $flags = $ArgFlags[$i];
3453             my $flags_string = "";
3454             my $kind = "";
3455             my $id_sep = "";
3457             if ($flags =~ m/c/) {
3458                 $kind = "child property";
3459                 $id_sep = "c-";
3460             }
3461             elsif ($flags =~ m/s/) {
3462                 $kind = "style property";
3463                 $id_sep = "s-";
3464             }
3465             else {
3466                 $kind = "property";
3467             }
3469             # Remember only one colon so we don't clash with signals.
3470             my $symbol = "${object}:${name}";
3471             # use two dashes and ev. an extra separator here for the same reason.
3472             my $id = &CreateValidSGMLID ("$object--$id_sep$name");
3474             my $type = $ArgTypes[$i];
3475             my $type_output;
3476             my $range = $ArgRanges[$i];
3477             my $range_output = CreateValidSGML ($range);
3478             my $default = $ArgDefaults[$i];
3479             my $default_output = CreateValidSGML ($default);
3481             if ($type eq "GtkString") {
3482                 $type = "char*";
3483             }
3484             if ($type eq "GtkSignal") {
3485                 $type = "GtkSignalFunc, gpointer";
3486                 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
3487                     . &MakeXRef ("gpointer");
3488             } elsif ($type =~ m/^(\w+)\*$/) {
3489                 $type_output = &MakeXRef ($1, &tagify($1, "type")) . "*";
3490             } else {
3491                 $type_output = &MakeXRef ($type, &tagify($type, "type"));
3492             }
3494             if ($flags =~ m/r/) {
3495                 $flags_string = "Read";
3496             }
3497             if ($flags =~ m/w/) {
3498                 if ($flags_string) { $flags_string .= " / "; }
3499                 $flags_string .= "Write";
3500             }
3501             if ($flags =~ m/x/) {
3502                 if ($flags_string) { $flags_string .= " / "; }
3503                 $flags_string .= "Construct";
3504             }
3505             if ($flags =~ m/X/) {
3506                 if ($flags_string) { $flags_string .= " / "; }
3507                 $flags_string .= "Construct Only";
3508             }
3510             $AllSymbols{$symbol} = 1;
3511             my $blurb;
3512             if (defined($SymbolDocs{$symbol}) &&
3513                 !IsEmptyDoc($SymbolDocs{$symbol})) {
3514                 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3515                 #print ".. [$SymbolDocs{$symbol}][$blurb]\n";
3516                 $AllDocumentedSymbols{$symbol} = 1;
3517             }
3518             else {
3519                 if (!($ArgBlurbs[$i] eq "")) {
3520                     $AllDocumentedSymbols{$symbol} = 1;
3521                 } else {
3522                     # FIXME: print a warning?
3523                     #print ".. no description\n";
3524                 }
3525                 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
3526             }
3528             my $pad1 = " " x (24 - length ($name));
3529             my $pad2 = " " x (20 - length ($type));
3531             my $arg_synop = "  &quot;<link linkend=\"$id\">$name</link>&quot;$pad1 $type_output $pad2 : $flags_string\n";
3532             my $arg_desc = "<refsect2 id=\"$id\" role=\"property\"><title>The <literal>&quot;$name&quot;</literal> $kind</title>\n";
3533             $arg_desc .= MakeIndexterms($symbol, $id);
3534             $arg_desc .= "\n";
3535             $arg_desc .= OutputSymbolExtraLinks($symbol);
3537             $arg_desc .= "<programlisting>  &quot;$name&quot;$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
3538             $arg_desc .= &MakeDeprecationNote($symbol);
3539             $arg_desc .= $blurb;
3540             if ($range ne "") {
3541                 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
3542             }
3543             if ($default ne "") {
3544                 $arg_desc .= "<para>Default value: $default_output</para>\n";
3545             }
3546             $arg_desc .= OutputSymbolTraits ($symbol);
3547             $arg_desc .= "</refsect2>\n";
3549             if ($flags =~ m/c/) {
3550                 $child_synop .= $arg_synop;
3551                 $child_desc .= $arg_desc;
3552             }
3553             elsif ($flags =~ m/s/) {
3554                 $style_synop .= $arg_synop;
3555                 $style_desc .= $arg_desc;
3556             }
3557             else {
3558                 $synop .= $arg_synop;
3559                 $desc .= $arg_desc;
3560             }
3561         }
3562     }
3563     return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
3567 #############################################################################
3568 # Function    : ReadSourceDocumentation
3569 # Description : This reads in the documentation embedded in comment blocks
3570 #               in the source code (for Gnome).
3572 #               Parameter descriptions override any in the template files.
3573 #               Function descriptions are placed before any description from
3574 #               the template files.
3576 #               It recursively descends the source directory looking for .c
3577 #               files and scans them looking for specially-formatted comment
3578 #               blocks.
3580 # Arguments   : $source_dir - the directory to scan.
3581 #############m###############################################################
3583 sub ReadSourceDocumentation {
3584     my ($source_dir) = @_;
3585     my ($file, $dir, @suffix_list, $suffix);
3586     #print "Scanning source directory: $source_dir\n";
3588     # This array holds any subdirectories found.
3589     my (@subdirs) = ();
3591     @suffix_list = split (/,/, $SOURCE_SUFFIXES);
3593     opendir (SRCDIR, $source_dir)
3594         || die "Can't open source directory $source_dir: $!";
3596     foreach $file (readdir (SRCDIR)) {
3597       if ($file =~ /^\./) {
3598         next;
3599       } elsif (-d "$source_dir/$file") {
3600         push (@subdirs, $file);
3601       } elsif (@suffix_list) {
3602         foreach $suffix (@suffix_list) {
3603           if ($file =~ m/\.\Q${suffix}\E$/) {
3604             &ScanSourceFile ("$source_dir/$file");
3605           }
3606         }
3607       } elsif ($file =~ m/\.[ch]$/) {
3608         &ScanSourceFile ("$source_dir/$file");
3609       }
3610     }
3611     closedir (SRCDIR);
3613     # Now recursively scan the subdirectories.
3614     foreach $dir (@subdirs) {
3615         next if ($IGNORE_FILES =~ m/(\s|^)\Q${dir}\E(\s|$)/);
3616         &ReadSourceDocumentation ("$source_dir/$dir");
3617     }
3621 #############################################################################
3622 # Function    : ScanSourceFile
3623 # Description : Scans one source file looking for specially-formatted comment
3624 #               blocks. Later &MergeSourceDocumentation is used to merge any
3625 #               documentation found with the documentation already read in
3626 #               from the template files.
3628 # Arguments   : $file - the file to scan.
3629 #############################################################################
3631 sub ScanSourceFile {
3632     my ($file) = @_;
3633     my $basename;
3635     if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
3636         $basename = $1;
3637     } else {
3638         &LogWarning ($file, 1, "Can't find basename for this filename.");
3639         $basename = $file;
3640     }
3642     # Check if the basename is in the list of files to ignore.
3643     if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
3644         return;
3645     }
3647     #print "DEBUG: Scanning $file\n";
3649     open (SRCFILE, $file)
3650         || die "Can't open $file: $!";
3651     my $in_comment_block = 0;
3652     my $symbol;
3653     my ($in_description, $in_return, $in_since, $in_stability, $in_deprecated);
3654     my ($description, $return_desc, $return_start, $return_style);
3655     my ($since_desc, $stability_desc, $deprecated_desc);
3656     my $current_param;
3657     my $ignore_broken_returns;
3658     my @params;
3659     while (<SRCFILE>) {
3660         # Look for the start of a comment block.
3661         if (!$in_comment_block) {
3662             if (m%^\s*/\*.*\*/%) {
3663                 #one-line comment - not gtkdoc
3664             } elsif (m%^\s*/\*\*\s%) {
3665                 #print "Found comment block start\n";
3667                 $in_comment_block = 1;
3669                 # Reset all the symbol data.
3670                 $symbol = "";
3671                 $in_description = 0;
3672                 $in_return = 0;
3673                 $in_since = 0;
3674                 $in_deprecated = 0;
3675                 $in_stability = 0;
3676                 $description = "";
3677                 $return_desc = "";
3678                 $return_style = "";
3679                 $since_desc = "";
3680                 $deprecated_desc = "";
3681                 $stability_desc = "";
3682                 $current_param = -1;
3683                 $ignore_broken_returns = 0;
3684                 @params = ();
3685             }
3686             next;
3687         }
3689         # We're in a comment block. Check if we've found the end of it.
3690         if (m%^\s*\*+/%) {
3691             if (!$symbol) {
3692                 # maybe its not even meant to be a gtk-doc comment?
3693                 &LogWarning ($file, $., "Symbol name not found at the start of the comment block.");
3694             } else {
3695                 # Add the return value description onto the end of the params.
3696                 if ($return_desc) {
3697                     push (@params, "Returns");
3698                     push (@params, $return_desc);
3699                     if ($return_style eq 'broken') {
3700                         &LogWarning ($file, $., "Free-form return value description in $symbol. Use `Returns:' to avoid ambiguities.");
3701                     }
3702                 }
3703                 # Convert special SGML characters
3704                 $description = &ConvertSGMLChars ($symbol, $description);
3705                 my $k;
3706                 for ($k = 1; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3707                     $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
3708                 }
3710                 # Handle Section docs
3711                 if ($symbol =~ m/SECTION:\s*(.*)/) {
3712                     my $real_symbol=$1;
3713                     my $key;
3715                     if (scalar %KnownSymbols) {
3716                         if ((! defined($KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"})) || $KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"} != 1) {
3717                             &LogWarning ($file, $., "Section $real_symbol is not defined in the $MODULE-section.txt file.");
3718                         }
3719                     }
3721                     #print "SECTION DOCS found in source for : '$real_symbol'\n";
3722                     $ignore_broken_returns = 1;
3723                     for ($k = 0; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3724                         #print "   '".$params[$k]."'\n";
3725                         $params[$k] = "\L$params[$k]";
3726                         undef $key;
3727                         if ($params[$k] eq "short_description") {
3728                             $key = "$TMPL_DIR/$real_symbol:Short_Description";
3729                         } elsif ($params[$k] eq "see_also") {
3730                             $key = "$TMPL_DIR/$real_symbol:See_Also";
3731                         } elsif ($params[$k] eq "title") {
3732                             $key = "$TMPL_DIR/$real_symbol:Title";
3733                         } elsif ($params[$k] eq "stability") {
3734                             $key = "$TMPL_DIR/$real_symbol:Stability_Level";
3735                         } elsif ($params[$k] eq "section_id") {
3736                             $key = "$TMPL_DIR/$real_symbol:Section_Id";
3737                         } elsif ($params[$k] eq "include") {
3738                             $key = "$TMPL_DIR/$real_symbol:Include";
3739                         } elsif ($params[$k] eq "image") {
3740                             $key = "$TMPL_DIR/$real_symbol:Image";
3741                         }
3742                         if (defined($key)) {
3743                             $SourceSymbolDocs{$key}=$params[$k+1];
3744                             $SourceSymbolSourceFile{$key} = $file;
3745                             $SourceSymbolSourceLine{$key} = $.;
3746                         }
3747                     }
3748                     $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
3749                     $SourceSymbolSourceFile{"$TMPL_DIR/$real_symbol:Long_Description"} = $file;
3750                     $SourceSymbolSourceLine{"$TMPL_DIR/$real_symbol:Long_Description"} = $.;
3751                     #$SourceSymbolTypes{$symbol} = "SECTION";
3752                 } else {
3753                     #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
3754                     $SourceSymbolDocs{$symbol} = $description;
3755                     $SourceSymbolParams{$symbol} = [ @params ];
3756                     # FIXME $SourceSymbolTypes{$symbol} = "STRUCT,SIGNAL,ARG,FUNCTION,MACRO";
3757                     #if (defined $DeclarationTypes{$symbol}) {
3758                     #    $SourceSymbolTypes{$symbol} = $DeclarationTypes{$symbol}
3759                     #}
3760                     $SourceSymbolSourceFile{$symbol} = $file;
3761                     $SourceSymbolSourceLine{$symbol} = $.;
3762                 }
3764                 if ($since_desc) {
3765                      ($since_desc, my @extra_lines) = split ("\n", $since_desc);
3766                      $since_desc =~ s/^\s+//;
3767                      $since_desc =~ s/\s+$//;
3768                      #print "Since($symbol) : [$since_desc]\n";
3769                      $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
3770                      if(scalar @extra_lines) {
3771                          &LogWarning ($file, $., "multi-line since docs found");
3772                      }
3773                 }
3775                 if ($stability_desc) {
3776                     $stability_desc = &ParseStabilityLevel($stability_desc, $file, $., "Stability level for $symbol");
3777                     $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
3778                 }
3780                 if ($deprecated_desc) {
3781                     if (exists $Deprecated{$symbol}) {
3782                     }
3783                     else {
3784                          # don't warn for signals and properties
3785                          #if ($symbol !~ m/::?(.*)/) {
3786                          if (defined $DeclarationTypes{$symbol}) {
3787                              &LogWarning ($file, $., 
3788                                  "$symbol is deprecated in the inline comments, but no deprecation guards were found around the declaration.".
3789                                  " (See the --deprecated-guards option for gtkdoc-scan.)");
3790                          }
3791                     }
3792                     $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
3793                 }
3794             }
3796             $in_comment_block = 0;
3797             next;
3798         }
3800         # Get rid of ' * ' at start of every line in the comment block.
3801         s%^\s*\*\s?%%;
3802         # But make sure we don't get rid of the newline at the end.
3803         if (!$_) {
3804             $_ = "\n";
3805         }
3806         #print "DEBUG: scanning :$_";
3808         # If we haven't found the symbol name yet, look for it.
3809         if (!$symbol) {
3810             if (m%^\s*(SECTION:\s*\S+)%) {
3811                 $symbol = $1;
3812                 #print "SECTION DOCS found in source for : '$symbol'\n";
3813                 $ignore_broken_returns = 1;
3814             } elsif (m%^\s*([\w:-]*\w)\s*:?\s*(\([a-z ]+\)\s*)*$%) {
3815                 $symbol = $1;
3816                 #print "SYMBOL DOCS found in source for : '$symbol'\n";
3817             }
3818             next;
3819         }
3821         # If we're in the return value description, add it to the end.
3822         if ($in_return) {
3823             # If we find another valid returns line, we assume that the first
3824             # one was really part of the description.
3825             if (m/^\s*(returns:|return\s+value:)/i) {
3826                 if ($return_style eq 'broken') {
3827                     $description .= $return_start . $return_desc;
3828                 }
3829                 $return_start = $1;
3830                 if ($return_style eq 'sane') {
3831                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3832                 }
3833                 $return_style = 'sane';
3834                 $ignore_broken_returns = 1;
3835                 $return_desc = $';
3836             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3837                 $description .= $return_start . $return_desc;
3838                 $return_start = $1;
3839                 $return_style = 'broken';
3840                 $return_desc = $';
3841             } elsif (m%^\s*since:%i) {
3842                 $since_desc = $';
3843                 $in_since = 1;
3844                 $in_return = 0;
3845             } elsif (m%^\s*stability:%i) {
3846                 $stability_desc = $';
3847                 $in_stability = 1;
3848                 $in_return = 0;
3849             } elsif (m%^\s*deprecated:%i) {
3850                 $deprecated_desc = $';
3851                 $in_deprecated = 1;
3852                 $in_return = 0;
3853             } else {
3854                 $return_desc .= $_;
3855             }
3856             next;
3857         }
3859         if ($in_since) {
3860             if (m/^\s*(returns:|return\s+value:)/i) {
3861                 if ($return_style eq 'broken') {
3862                     $description .= $return_start . $return_desc;
3863                 }
3864                 $return_start = $1;
3865                 if ($return_style eq 'sane') {
3866                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3867                 }
3868                 $return_style = 'sane';
3869                 $ignore_broken_returns = 1;
3870                 $return_desc = $';
3871                 $in_return = 1;
3872                 $in_since = 0;
3873             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3874                 $return_start = $1;
3875                 $return_style = 'broken';
3876                 $return_desc = $';
3877                 $in_return = 1;
3878                 $in_since = 0;
3879             } elsif (m%^\s*deprecated:%i) {
3880                 $deprecated_desc = $';
3881                 $in_deprecated = 1;
3882                 $in_since = 0;
3883             } elsif (m%^\s*stability:%i) {
3884                 $stability_desc = $';
3885                 $in_stability = 1;
3886                 $in_since = 0;
3887             } else {
3888                 $since_desc .= $_;
3889             }
3890             next;
3891         }
3893         if ($in_stability) {
3894             if (m/^\s*(returns:|return\s+value:)/i) {
3895                 if ($return_style eq 'broken') {
3896                     $description .= $return_start . $return_desc;
3897                 }
3898                 $return_start = $1;
3899                 if ($return_style eq 'sane') {
3900                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3901                 }
3902                 $return_style = 'sane';
3903                 $ignore_broken_returns = 1;
3904                 $return_desc = $';
3905                 $in_return = 1;
3906                 $in_stability = 0;
3907             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3908                 $return_start = $1;
3909                 $return_style = 'broken';
3910                 $return_desc = $';
3911                 $in_return = 1;
3912                 $in_stability = 0;
3913             } elsif (m%^\s*deprecated:%i) {
3914                 $deprecated_desc = $';
3915                 $in_deprecated = 1;
3916                 $in_stability = 0;
3917             } elsif (m%^\s*since:%i) {
3918                 $since_desc = $';
3919                 $in_since = 1;
3920                 $in_stability = 0;
3921             } else {
3922                 $stability_desc .= $_;
3923             }
3924             next;
3925         }
3927         if ($in_deprecated) {
3928             if (m/^\s*(returns:|return\s+value:)/i) {
3929                 if ($return_style eq 'broken') {
3930                     $description .= $return_start . $return_desc;
3931                 }
3932                 $return_start = $1;
3933                 if ($return_style eq 'sane') {
3934                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3935                 }
3936                 $return_style = 'sane';
3937                 $ignore_broken_returns = 1;
3938                 $return_desc = $';
3939                 $in_return = 1;
3940                 $in_deprecated = 0;
3941             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3942                 $return_start = $1;
3943                 $return_style = 'broken';
3944                 $return_desc = $';
3945                 $in_return = 1;
3946                 $in_deprecated = 0;
3947             } elsif (m%^\s*since:%i) {
3948                 $since_desc = $';
3949                 $in_since = 1;
3950                 $in_deprecated = 0;
3951             } elsif (m%^\s*stability:%i) {
3952                 $stability_desc = $';
3953                 $in_stability = 1;
3954                 $in_deprecated = 0;
3955             } else {
3956                 $deprecated_desc .= $_;
3957             }
3958             next;
3959         }
3961         # If we're in the description part, check for the 'Returns:' line.
3962         # If that isn't found, add the text to the end.
3963         if ($in_description) {
3964             # Get rid of 'Description:'
3965             s%^\s*Description:%%;
3967             if (m/^\s*(returns:|return\s+value:)/i) {
3968                 if ($return_style eq 'broken') {
3969                     $description .= $return_start . $return_desc;
3970                 }
3971                 $return_start = $1;
3972                 if ($return_style eq 'sane') {
3973                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3974                 }
3975                 $return_style = 'sane';
3976                 $ignore_broken_returns = 1;
3977                 $return_desc = $';
3978                 $in_return = 1;
3979                 next;
3980             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3981                 $return_start = $1;
3982                 $return_style = 'broken';
3983                 $return_desc = $';
3984                 $in_return = 1;
3985                 next;
3986             } elsif (m%^\s*since:%i) {
3987                 $since_desc = $';
3988                 $in_since = 1;
3989                 next;
3990             } elsif (m%^\s*deprecated:%i) {
3991                 $deprecated_desc = $';
3992                 $in_deprecated = 1;
3993                 next;
3994             } elsif (m%^\s*stability:%i) {
3995                 $stability_desc = $';
3996                 $in_stability = 1;
3997                 next;
3998             }
4000             $description .= $_;
4001             next;
4002         }
4004         # We must be in the parameters. Check for the empty line below them.
4005         if (m%^\s*$%) {
4006             $in_description = 1;
4007             next;
4008         }
4010         # Look for a parameter name.
4011         if (m%^\s*@(\S+)\s*:\s*%) {
4012             my $param_name = $1;
4013             my $param_desc = $';
4015             #print "Found parameter: $param_name\n";
4016             # Allow '...' as the Varargs parameter.
4017             if ($param_name eq "...") {
4018                 $param_name = "Varargs";
4019             }
4020             if ("\L$param_name" eq "returns") {
4021                 $return_style = 'sane';
4022                 $ignore_broken_returns = 1;
4023             }
4024             push (@params, $param_name);
4025             push (@params, $param_desc);
4026             $current_param += $PARAM_FIELD_COUNT;
4027             next;
4028         }
4030         # We must be in the middle of a parameter description, so add it on
4031         # to the last element in @params.
4032         if ($current_param == -1) {
4033             &LogWarning ($file, $., "Parsing comment block file : parameter expected.");
4034         } else {
4035             $params[$#params] .= $_;
4036         }
4037     }
4038     close (SRCFILE);
4041 #############################################################################
4042 # Function    : OutputMissingDocumentation
4043 # Description : Outputs report of documentation coverage to a file
4045 # Arguments   : none
4046 #############################################################################
4048 sub OutputMissingDocumentation {
4049     my $old_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.txt";
4050     my $new_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.new";
4052     my $n_documented = 0;
4053     my $n_incomplete = 0;
4054     my $total = 0;
4055     my $symbol;
4056     my $percent;
4057     my $msg;
4058     my $buffer = "";
4059     my $buffer_deprecated = "";
4060     my $buffer_descriptions = "";
4061     
4062     open(UNDOCUMENTED, ">$new_undocumented_file")
4063       || die "Can't create $new_undocumented_file";
4064     
4065     foreach $symbol (sort (keys (%AllSymbols))) {
4066         # FIXME: should we print LogWarnings for undocumented stuff?
4067         # DEBUG
4068         #my $ssfile = &GetSymbolSourceFile($symbol);
4069         #my $ssline = &GetSymbolSourceLine($symbol);
4070         #my $location = "defined at " . (defined($ssfile)?$ssfile:"?") . ":" . (defined($ssline)?$ssline:"0") . "\n";
4071         # DEBUG
4072         if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include|Section_Id|Image)/) {
4073             $total++;
4074             if (exists ($AllDocumentedSymbols{$symbol})) {
4075                 $n_documented++;
4076                 if (exists ($AllIncompleteSymbols{$symbol})) {
4077                     $n_incomplete++;
4078                     $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4079                     #$buffer .= "\t0: ".$location;
4080                 }
4081             } elsif (exists $Deprecated{$symbol}) {
4082                 if (exists ($AllIncompleteSymbols{$symbol})) {
4083                     $n_incomplete++;
4084                     $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4085                     #$buffer .= "\t1a: ".$location;
4086                 } else {
4087                     $buffer_deprecated .= $symbol . "\n";
4088                     #$buffer .= "\t1b: ".$location;
4089                 }
4090             } else {
4091                 if (exists ($AllIncompleteSymbols{$symbol})) {
4092                     $n_incomplete++;
4093                     $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4094                     #$buffer .= "\t2a: ".$location;
4095                 } else {
4096                     $buffer .= $symbol . "\n";
4097                     #$buffer .= "\t2b: ".$location;
4098                 }
4099             }
4100         } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
4101             $total++;
4102             #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
4103             #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
4104             #print "%%%% $symbol : $len1,$len2\n";
4105             if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
4106             || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
4107               $n_documented++;
4108             } else {
4109               # cut off the leading namespace ($TMPL_DIR)
4110               $symbol =~ m/^.*\/(.*)$/;
4111               $buffer_descriptions .= $1 . "\n";
4112             }
4113         }
4114     }
4115     
4116     $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
4117     
4118     if ($total == 0) {
4119       $percent = 100;
4120     } else {
4121       $percent = ($n_documented / $total) * 100.0;
4122     }
4123     
4124     printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
4125     print UNDOCUMENTED "$n_documented symbols documented.\n";
4126     print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
4127     print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
4128     
4129     print UNDOCUMENTED $buffer;
4130     close (UNDOCUMENTED);
4131     
4132     return &UpdateFileIfChanged ($old_undocumented_file, $new_undocumented_file, 0);
4133     
4134     printf "%.0f%% symbol docs coverage", $percent;
4135     print "($n_documented symbols documented, $n_incomplete symbols incomplete, " . ($total - $n_documented) . " not documented)\n";
4136     print "See $MODULE-undocumented.txt for a list of missing docs.\nThe doc coverage percentage doesn't include intro sections.\n";
4140 #############################################################################
4141 # Function    : OutputUndeclaredSymbols
4142 # Description : Outputs symbols that are listed in the section file, but not
4143 #               declaration is found in the sources
4145 # Arguments   : none
4146 #############################################################################
4148 sub OutputUndeclaredSymbols {
4149     my $old_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.txt";
4150     my $new_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.new";
4152     open(UNDECLARED, ">$new_undeclared_file")
4153         || die "Can't create $new_undeclared_file";
4155     if (%UndeclaredSymbols) {
4156         print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
4157         print UNDECLARED "\n";
4158         print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
4159     }
4160     close(UNDECLARED);
4162     return &UpdateFileIfChanged ($old_undeclared_file, $new_undeclared_file, 0);
4165 #############################################################################
4166 # Function    : OutputUnusedSymbols
4167 # Description : Outputs symbols that are documented in comments, but not
4168 #               declared in the sources
4170 # Arguments   : none
4171 #############################################################################
4173 sub OutputUnusedSymbols {
4174     my $num_unused = 0;
4175     my $old_unused_file = "$ROOT_DIR/$MODULE-unused.txt";
4176     my $new_unused_file = "$ROOT_DIR/$MODULE-unused.new";
4178     open (UNUSED, ">$new_unused_file")
4179         || die "Can't open $new_unused_file";
4180     my ($symbol);
4181     foreach $symbol (sort keys (%Declarations)) {
4182         if (!defined ($DeclarationOutput{$symbol})) {
4183             print (UNUSED "$symbol\n");
4184             $num_unused++;
4185         }
4186     }
4187     foreach $symbol (sort (keys (%AllUnusedSymbols))) {
4188         print (UNUSED "$symbol(" . $AllUnusedSymbols{$symbol} . ")\n");
4189         $num_unused++;
4190     }
4191     close (UNUSED);
4192     if ($num_unused != 0) {
4193         &LogWarning ($old_unused_file, 1, "$num_unused unused declarations.".
4194             "They should be added to $MODULE-sections.txt in the appropriate place.");
4195     }
4196     
4197     return &UpdateFileIfChanged ($old_unused_file, $new_unused_file, 0); 
4201 #############################################################################
4202 # Function    : OutputAllSymbols
4203 # Description : Outputs list of all symbols to a file
4205 # Arguments   : none
4206 #############################################################################
4208 sub OutputAllSymbols {
4209      my $n_documented = 0;
4210      my $total = 0;
4211      my $symbol;
4212      my $percent;
4213      my $msg;
4215      open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
4216           || die "Can't create $ROOT_DIR/$MODULE-symbols.txt: $!";
4218      foreach $symbol (sort (keys (%AllSymbols))) {
4219           print SYMBOLS $symbol . "\n";
4220      }
4222      close (SYMBOLS);
4225 #############################################################################
4226 # Function    : OutputSymbolsWithoutSince
4227 # Description : Outputs list of all symbols without a since tag to a file
4229 # Arguments   : none
4230 #############################################################################
4232 sub OutputSymbolsWithoutSince {
4233      my $n_documented = 0;
4234      my $total = 0;
4235      my $symbol;
4236      my $percent;
4237      my $msg;
4239      open (SYMBOLS, ">$ROOT_DIR/$MODULE-nosince.txt")
4240           || die "Can't create $ROOT_DIR/$MODULE-nosince.txt: $!";
4242      foreach $symbol (sort (keys (%SourceSymbolDocs))) {
4243          if (!defined $Since{$symbol}) {
4244              print SYMBOLS $symbol . "\n";
4245          }
4246      }
4248      close (SYMBOLS);
4252 #############################################################################
4253 # Function    : MergeSourceDocumentation
4254 # Description : This merges documentation read from a source file into the
4255 #               documentation read in from a template file.
4257 #               Parameter descriptions override any in the template files.
4258 #               Function descriptions are placed before any description from
4259 #               the template files.
4261 # Arguments   : none
4262 #############################################################################
4264 sub MergeSourceDocumentation {
4265     my $symbol;
4266     my @Symbols;
4268     if (scalar %SymbolDocs) {
4269         @Symbols=keys (%SymbolDocs);
4270         #print "num existing entries: ".(scalar @Symbols)."\n";
4271         #print "  ",$Symbols[0], " ",$Symbols[1],"\n";
4272     }
4273     else {
4274         # filter scanned declarations, with what we suppress from -sections.txt
4275         my %tmp = ();
4276         foreach $symbol (keys (%Declarations)) {
4277             if (defined($KnownSymbols{$symbol}) && $KnownSymbols{$symbol} == 1) {
4278                 $tmp{$symbol}=1;
4279             }
4280         }
4281         # , add the rest from -sections.txt
4282         foreach $symbol (keys (%KnownSymbols)) {
4283             if ($KnownSymbols{$symbol} == 1) {
4284                 $tmp{$symbol}=1;
4285             }
4286         }
4287         # and add whats found in the source
4288         foreach $symbol (keys (%SourceSymbolDocs)) {
4289             $tmp{$symbol}=1;
4290         }
4291         @Symbols = keys (%tmp);
4292         #print "num source entries: ".(scalar @Symbols)."\n";
4293     }
4294     foreach $symbol (@Symbols) {
4295         $AllSymbols{$symbol} = 1;
4297         my $have_tmpl_docs = 0;
4299         ## see if the symbol is documented in template
4300         my $tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4301         my $check_tmpl_doc =$tmpl_doc;
4302         # remove all xml-tags and whitespaces 
4303         $check_tmpl_doc =~ s/<.*?>//g;
4304         $check_tmpl_doc =~ s/\s//g;
4305         # anything left ?
4306         if ($check_tmpl_doc ne "") {
4307             $have_tmpl_docs = 1;
4308             #print "## [$check_tmpl_doc]\n";
4309         }
4311         if (exists ($SourceSymbolDocs{$symbol})) {
4312             my $type = $DeclarationTypes {$symbol};
4314             #print "merging [$symbol] from source\n";
4316             my $item = "Parameter";
4317             if (defined ($type)) {
4318                 if ($type eq 'STRUCT') {
4319                     $item = "Field";
4320                 } elsif ($type eq 'ENUM') {
4321                     $item = "Value";
4322                 } elsif ($type eq 'UNION') {
4323                     $item = "Field";
4324                 }
4325             } else {
4326                 $type="SIGNAL";
4327             }
4329             my $src_doc = $SourceSymbolDocs{$symbol};
4330             # remove leading and training whitespaces
4331             $src_doc =~ s/^\s+//;
4332             $src_doc =~ s/\s+$//;
4333             
4334             # Don't output warnings for overridden titles as titles are
4335             # automatically generated in the -sections.txt file, and thus they
4336             # are often overridden.
4337             if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
4338                 # check if content is different
4339                 if ($tmpl_doc ne $src_doc) {
4340                     #print "[$tmpl_doc] [$src_doc]\n";
4341                     &LogWarning ($SourceSymbolSourceFile{$symbol}, $SourceSymbolSourceLine{$symbol},
4342                         "Documentation in template ".$SymbolSourceFile{$symbol}.":".$SymbolSourceLine{$symbol}." for $symbol being overridden by inline comments.");
4343                 }
4344             }
4346             if ($src_doc ne "") {
4347                  $AllDocumentedSymbols{$symbol} = 1;
4348             }
4350             # Convert <!--PARAMETERS--> with any blank lines around it to
4351             # a </para> followed by <!--PARAMETERS--> followed by <para>.
4352             $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
4354             # Do not add <para> to nothing, it breaks missing docs checks.
4355             my $src_doc_para = "";
4356             if ($src_doc ne "") {
4357                 # If there is a blank line, finish the paragraph and start another.
4358                 $src_doc = &ConvertBlankLines ($src_doc, $symbol);
4359                 $src_doc_para = "<para>\n$src_doc\n</para>";
4360                 ## fixup xml markup
4361                 # FIXME: this is questionable, as we can't make assumtions on the content really
4362                 #$src_doc_para =~ s%^<para>\n(<refsect[1-9])%$1%gms;
4363                 #$src_doc_para =~ s%^<para>\n<para>%<para>%gms;
4364                 #$src_doc_para =~ s%(</refsect[1-9]>)\n</para>$%$1%gms;
4365                 #print "$symbol : [$src_doc][$src_doc_para]\n";
4366             }
4368             if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
4369                 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4370             } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
4371                 # For the title/summary/see also section docs we don't want to
4372                 # add any <para> tags.
4373                 $SymbolDocs{$symbol} = "$src_doc"
4374             } else {
4375                 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4376             }
4378             # merge parameters
4379             if ($symbol =~ m/.*::.*/) {
4380                 # For signals we prefer the param names from the source docs,
4381                 # since the ones from the templates are likely to contain the
4382                 # artificial argn names which are generated by gtkdoc-scangobj.
4383                 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4384                 # FIXME: we need to check for empty docs here as well!
4385             } else {
4386                 # The templates contain the definitive parameter names and order,
4387                 # so we will not change that. We only override the actual text.
4388                 my $tmpl_params = $SymbolParams{$symbol};
4389                 if (!defined ($tmpl_params)) {
4390                     #print "No merge needed for $symbol\n";
4391                     $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4392                     #  FIXME: we still like to get the number of params and merge
4393                     #  1) we would noticed that params have been removed/renamed
4394                     #  2) we would catch undocumented params
4395                     #  params are not (yet) exported in -decl.txt so that we
4396                     #  could easily grab them :/
4397                 } else {
4398                     my $params = $SourceSymbolParams{$symbol};
4399                     my $j;
4400                     #print "Merge needed for $symbol, tmpl_params: ",$#$tmpl_params,", source_params: ",$#$params," \n";
4401                     for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4402                         my $tmpl_param_name = $$tmpl_params[$j];
4404                         # Allow '...' as the Varargs parameter.
4405                         if ($tmpl_param_name eq "...") {
4406                             $tmpl_param_name = "Varargs";
4407                         }
4409                         # Try to find the param in the source comment documentation.
4410                         my $found = 0;
4411                         my $k;
4412                         #print "  try merge param $tmpl_param_name\n";
4413                         for ($k = 0; $k <= $#$params; $k += $PARAM_FIELD_COUNT) {
4414                             my $param_name = $$params[$k];
4415                             my $param_desc = $$params[$k + 1];
4417                             #print "    test param  $param_name\n";
4418                             # We accept changes in case, since the Gnome source
4419                             # docs contain a lot of these.
4420                             if ("\L$param_name" eq "\L$tmpl_param_name") {
4421                                 $found = 1;
4423                                 # Override the description.
4424                                 $$tmpl_params[$j + 1] = $param_desc;
4426                                 # Set the name to "" to mark it as used.
4427                                 $$params[$k] = "";
4428                                 last;
4429                             }
4430                         }
4432                         # If it looks like the parameters are there, but not
4433                         # in the right place, try to explain a bit better.
4434                         if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
4435                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4436                                 "Parameters for $symbol must start on the line immediately after the function or macro name.");
4437                         }
4438                     }
4440                     # Now we output a warning if parameters have been described which
4441                     # do not exist.
4442                     for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
4443                         my $param_name = $$params[$j];
4444                         if ($param_name) {
4445                             # the template builder cannot detect if a macro returns
4446                             # a result or not
4447                             if(($type eq "MACRO") && ($param_name eq "Returns")) {
4448                                 # FIXME: do we need to add it then to tmpl_params[] ?
4449                                 my $num=$#$tmpl_params;
4450                                 #print "  adding Returns: to macro docs for $symbol.\n";
4451                                 $$tmpl_params[$num+1]="Returns";
4452                                 $$tmpl_params[$num+2]=$$params[$j+1];
4453                                 next;
4454                             }
4455                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4456                                 "$item described in source code comment block but does not exist. $type: $symbol $item: $param_name.");
4457                         }
4458                     }
4459                 }
4460             }
4461         } else {
4462             if ($have_tmpl_docs) {
4463                 $AllDocumentedSymbols{$symbol} = 1;
4464                 #print "merging [$symbol] from template\n";
4465             }
4466             else {
4467                 #print "[$symbol] undocumented\n";
4468             }
4469         }
4471         # if this symbol is documented, check if docs are complete
4472         $check_tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4473         # remove all xml-tags and whitespaces
4474         $check_tmpl_doc =~ s/<.*?>//g;
4475         $check_tmpl_doc =~ s/\s//g;
4476         if ($check_tmpl_doc ne "") {
4477             my $tmpl_params = $SymbolParams{$symbol};
4478             if (defined ($tmpl_params)) {
4479                 my $type = $DeclarationTypes {$symbol};
4481                 my $item = "Parameter";
4482                 if (defined ($type)) {
4483                     if ($type eq 'STRUCT') {
4484                         $item = "Field";
4485                     } elsif ($type eq 'ENUM') {
4486                         $item = "Value";
4487                     } elsif ($type eq 'UNION') {
4488                         $item = "Field";
4489                     }
4490                 } else {
4491                     $type="SIGNAL";
4492                 }
4494                 #print "Check param docs for $symbol, tmpl_params: ",$#$tmpl_params," entries, type=$type\n";
4496                 if ($#$tmpl_params > 0) {
4497                     my $j;
4498                     for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4499                         # Output a warning if the parameter is empty and
4500                         # remember for stats.
4501                         my $tmpl_param_name = $$tmpl_params[$j];
4502                         my $tmpl_param_desc = $$tmpl_params[$j + 1];
4503                         if ($tmpl_param_name ne "void" && $tmpl_param_desc !~ m/\S/) {
4504                             if (exists ($AllIncompleteSymbols{$symbol})) {
4505                                 $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
4506                             } else {
4507                                 $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
4508                             }
4509                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4510                                 "$item description for $symbol"."::"."$tmpl_param_name is missing in source code comment block.");
4511                         }
4512                     }
4513                 }
4514                 else {
4515                     if ($#$tmpl_params == 0) {
4516                         $AllIncompleteSymbols{$symbol}="<items>";
4517                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4518                             "$item descriptions for $symbol are missing in source code comment block.");
4519                     }
4520                     # $#$tmpl_params==-1 means we don't know about parameters
4521                     # this unfortunately does not tell if there should be some
4522                 }
4523             }
4524         }
4525    }
4526    #print "num doc entries: ".(scalar %SymbolDocs)."\n";
4529 #############################################################################
4530 # Function    : IsEmptyDoc
4531 # Description : Check if a doc-string is empty. Its also regarded as empty if
4532 #               it only consist of whitespace or e.g. FIXME.
4533 # Arguments   : the doc-string
4534 #############################################################################
4535 sub IsEmptyDoc {
4536     my ($doc) = @_;
4537     
4538     if ($doc =~ /^\s*$/) {
4539         return 1;
4540     }
4542     if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
4543         return 1;
4544     }
4546     return 0;
4550 # This converts blank lines to "</para><para>", but only outside CDATA and
4551 # <programlisting> tags.
4552 sub ConvertBlankLines {
4553     return &ModifyXMLElements ($_[0], $_[1],
4554                                "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
4555                                \&ConvertBlankLinesEndTag,
4556                                \&ConvertBlankLinesCallback);
4560 sub ConvertBlankLinesEndTag {
4561   if ($_[0] eq "<!\[CDATA\[") {
4562     return "]]>";
4563   } elsif ($_[0] eq "|[") {
4564     return "]\\|";
4565   } else {
4566     return "</programlisting>";
4567   }
4570 sub ConvertBlankLinesCallback {
4571   my ($text, $symbol, $tag) = @_;
4573   # If we're not in CDATA or a <programlisting> we convert blank lines so
4574   # they start a new <para>.
4575   if ($tag eq "") {
4576     $text =~ s%\n{2,}%\n</para>\n<para>\n%g;
4577   }
4579   return $text;
4583 #############################################################################
4584 # LIBRARY FUNCTIONS -   These functions are used in both gtkdoc-mkdb and
4585 #                       gtkdoc-mktmpl and should eventually be moved to a
4586 #                       separate library.
4587 #############################################################################
4589 #############################################################################
4590 # Function    : ReadDeclarationsFile
4591 # Description : This reads in a file containing the function/macro/enum etc.
4592 #               declarations.
4594 #               Note that in some cases there are several declarations with
4595 #               the same name, e.g. for conditional macros. In this case we
4596 #               set a flag in the %DeclarationConditional hash so the
4597 #               declaration is not shown in the docs.
4599 #               If a macro and a function have the same name, e.g. for
4600 #               gtk_object_ref, the function declaration takes precedence.
4602 #               Some opaque structs are just declared with 'typedef struct
4603 #               _name name;' in which case the declaration may be empty.
4604 #               The structure may have been found later in the header, so
4605 #               that overrides the empty declaration.
4607 # Arguments   : $file - the declarations file to read
4608 #               $override - if declarations in this file should override
4609 #                       any current declaration.
4610 #############################################################################
4612 sub ReadDeclarationsFile {
4613     my ($file, $override) = @_;
4615     if ($override == 0) {
4616         %Declarations = ();
4617         %DeclarationTypes = ();
4618         %DeclarationConditional = ();
4619         %DeclarationOutput = ();
4620     }
4622     open (INPUT, $file)
4623         || die "Can't open $file: $!";
4624     my $declaration_type = "";
4625     my $declaration_name;
4626     my $declaration;
4627     my $is_deprecated = 0;
4628     while (<INPUT>) {
4629         if (!$declaration_type) {
4630             if (m/^<([^>]+)>/) {
4631                 $declaration_type = $1;
4632                 $declaration_name = "";
4633                 #print "Found declaration: $declaration_type\n";
4634                 $declaration = "";
4635             }
4636         } else {
4637             if (m%^<NAME>(.*)</NAME>%) {
4638                 $declaration_name = $1;
4639             } elsif (m%^<DEPRECATED/>%) {
4640                 $is_deprecated = 1;
4641             } elsif (m%^</$declaration_type>%) {
4642                 #print "Found end of declaration: $declaration_name\n";
4643                 # Check that the declaration has a name
4644                 if ($declaration_name eq "") {
4645                     print "ERROR: $declaration_type has no name $file:$.\n";
4646                 }
4648                 # If the declaration is an empty typedef struct _XXX XXX
4649                 # set the flag to indicate the struct has a typedef.
4650                 if ($declaration_type eq 'STRUCT'
4651                     && $declaration =~ m/^\s*$/) {
4652                     #print "Struct has typedef: $declaration_name\n";
4653                     $StructHasTypedef{$declaration_name} = 1;
4654                 }
4656                 # Check if the symbol is already defined.
4657                 if (defined ($Declarations{$declaration_name})
4658                     && $override == 0) {
4659                     # Function declarations take precedence.
4660                     if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
4661                         # Ignore it.
4662                     } elsif ($declaration_type eq 'FUNCTION') {
4663                         if ($is_deprecated) {
4664                             $Deprecated{$declaration_name} = "";
4665                         }
4666                         $Declarations{$declaration_name} = $declaration;
4667                         $DeclarationTypes{$declaration_name} = $declaration_type;
4668                     } elsif ($DeclarationTypes{$declaration_name}
4669                               eq $declaration_type) {
4670                         # If the existing declaration is empty, or is just a
4671                         # forward declaration of a struct, override it.
4672                         if ($declaration_type eq 'STRUCT') {
4673                             if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4674                                 if ($is_deprecated) {
4675                                     $Deprecated{$declaration_name} = "";
4676                                 }
4677                                 $Declarations{$declaration_name} = $declaration;
4678                             } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4679                                 # Ignore an empty or forward declaration.
4680                             } else {
4681                                 &LogWarning ($file, $., "Structure $declaration_name has multiple definitions.");
4682                             }
4683                         } else {
4684                             # set flag in %DeclarationConditional hash for
4685                             # multiply defined macros/typedefs.
4686                             $DeclarationConditional{$declaration_name} = 1;
4687                         }
4688                     } else {
4689                         &LogWarning ($file, $., "$declaration_name has multiple definitions.");
4690                     }
4691                 } else {
4692                     if ($is_deprecated) {
4693                         $Deprecated{$declaration_name} = "";
4694                     }
4695                     $Declarations{$declaration_name} = $declaration;
4696                     $DeclarationTypes{$declaration_name} = $declaration_type;
4697                 }
4699                 $declaration_type = "";
4700                 $is_deprecated = 0;
4701             } else {
4702                 $declaration .= $_;
4703             }
4704         }
4705     }
4706     close (INPUT);
4710 #############################################################################
4711 # Function    : ReadSignalsFile
4712 # Description : This reads in an existing file which contains information on
4713 #               all GTK signals. It creates the arrays @SignalNames and
4714 #               @SignalPrototypes containing info on the signals. The first
4715 #               line of the SignalPrototype is the return type of the signal
4716 #               handler. The remaining lines are the parameters passed to it.
4717 #               The last parameter, "gpointer user_data" is always the same
4718 #               so is not included.
4719 # Arguments   : $file - the file containing the signal handler prototype
4720 #                       information.
4721 #############################################################################
4723 sub ReadSignalsFile {
4724     my ($file) = @_;
4726     my $in_signal = 0;
4727     my $signal_object;
4728     my $signal_name;
4729     my $signal_returns;
4730     my $signal_flags;
4731     my $signal_prototype;
4733     # Reset the signal info.
4734     @SignalObjects = ();
4735     @SignalNames = ();
4736     @SignalReturns = ();
4737     @SignalFlags = ();
4738     @SignalPrototypes = ();
4740     if (! -f $file) {
4741         return;
4742     }
4743     if (!open (INPUT, $file)) {
4744         warn "Can't open $file - skipping signals\n";
4745         return;
4746     }
4747     while (<INPUT>) {
4748         if (!$in_signal) {
4749             if (m/^<SIGNAL>/) {
4750                 $in_signal = 1;
4751                 $signal_object = "";
4752                 $signal_name = "";
4753                 $signal_returns = "";
4754                 $signal_prototype = "";
4755             }
4756         } else {
4757             if (m/^<NAME>(.*)<\/NAME>/) {
4758                 $signal_name = $1;
4759                 if ($signal_name =~ m/^(.*)::(.*)$/) {
4760                     $signal_object = $1;
4761                     ($signal_name = $2) =~ s/_/-/g;
4762                     #print "Found signal: $signal_name\n";
4763                 } else {
4764                     &LogWarning ($file, $., "Invalid signal name: $signal_name.");
4765                 }
4766             } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
4767                 $signal_returns = $1;
4768             } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4769                 $signal_flags = $1;
4770             } elsif (m%^</SIGNAL>%) {
4771                 #print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
4772                 push (@SignalObjects, $signal_object);
4773                 push (@SignalNames, $signal_name);
4774                 push (@SignalReturns, $signal_returns);
4775                 push (@SignalFlags, $signal_flags);
4776                 push (@SignalPrototypes, $signal_prototype);
4777                 $in_signal = 0;
4778             } else {
4779                 $signal_prototype .= $_;
4780             }
4781         }
4782     }
4783     close (INPUT);
4787 #############################################################################
4788 # Function    : ReadTemplateFile
4789 # Description : This reads in the manually-edited documentation file
4790 #               corresponding to the file currently being created, so we can
4791 #               insert the documentation at the appropriate places.
4792 #               It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
4793 #               is a hash of arrays.
4794 #               NOTE: This function is duplicated in gtkdoc-mktmpl (but
4795 #               slightly different).
4796 # Arguments   : $docsfile - the template file to read in.
4797 #               $skip_unused_params - 1 if the unused parameters should be
4798 #                       skipped.
4799 #############################################################################
4801 sub ReadTemplateFile {
4802     my ($docsfile, $skip_unused_params) = @_;
4804     my $template = "$docsfile.sgml";
4805     if (! -f $template) {
4806         #print "File doesn't exist: $template\n";
4807         return 0;
4808     }
4809     #print "Reading $template\n";
4811     # start with empty hashes, we merge the source comment for each file
4812     # afterwards
4813     %SymbolDocs = ();
4814     %SymbolTypes = ();
4815     %SymbolParams = ();
4817     my $current_type = "";      # Type of symbol being read.
4818     my $current_symbol = "";    # Name of symbol being read.
4819     my $symbol_doc = "";                # Description of symbol being read.
4820     my @params;                 # Parameter names and descriptions of current
4821                                 #   function/macro/function typedef.
4822     my $current_param = -1;     # Index of parameter currently being read.
4823                                 #   Note that the param array contains pairs
4824                                 #   of param name & description.
4825     my $in_unused_params = 0;   # True if we are reading in the unused params.
4826     my $in_deprecated = 0;
4827     my $in_since = 0;
4828     my $in_stability = 0;
4830     open (DOCS, "$template")
4831         || die "Can't open $template: $!";
4832     while (<DOCS>) {
4833         if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
4834             my $type = $1;
4835             my $symbol = $2;
4836             if ($symbol eq "Title"
4837                 || $symbol eq "Short_Description"
4838                 || $symbol eq "Long_Description"
4839                 || $symbol eq "See_Also"
4840                 || $symbol eq "Stability_Level"
4841                 || $symbol eq "Include"
4842                 || $symbol eq "Image") {
4844                 $symbol = $docsfile . ":" . $symbol;
4845             }
4847             #print "Found symbol: $symbol\n";
4848             # Remember file and line for the symbol
4849             $SymbolSourceFile{$symbol} = $template;
4850             $SymbolSourceLine{$symbol} = $.;
4852             # Store previous symbol, but remove any trailing blank lines.
4853             if ($current_symbol ne "") {
4854                 $symbol_doc =~ s/\s+$//;
4855                 $SymbolTypes{$current_symbol} = $current_type;
4856                 $SymbolDocs{$current_symbol} = $symbol_doc;
4858                 # Check that the stability level is valid.
4859                 if ($StabilityLevel{$current_symbol}) {
4860                     $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4861                 }
4863                 if ($current_param >= 0) {
4864                     $SymbolParams{$current_symbol} = [ @params ];
4865                 } else {
4866                     # Delete any existing params in case we are overriding a
4867                     # previously read template.
4868                     delete $SymbolParams{$current_symbol};
4869                 }
4870             }
4871             $current_type = $type;
4872             $current_symbol = $symbol;
4873             $current_param = -1;
4874             $in_unused_params = 0;
4875             $in_deprecated = 0;
4876             $in_since = 0;
4877             $in_stability = 0;
4878             $symbol_doc = "";
4879             @params = ();
4881         } elsif (m/^<!-- # Unused Parameters # -->/) {
4882             #print "DEBUG: Found unused parameters\n";
4883             $in_unused_params = 1;
4884             next;
4886         } elsif ($in_unused_params && $skip_unused_params) {
4887             # When outputting the DocBook we skip unused parameters.
4888             #print "DEBUG: Skipping unused param: $_";
4889             next;
4891         } else {
4892             # Check if param found. Need to handle "..." and "format...".
4893             if (s/^\@([\w\.]+):\040?//) {
4894                 my $param_name = $1;
4895                 my $param_desc = $_;
4896                 # Allow variations of 'Returns'
4897                 if ($param_name =~ m/^[Rr]eturns?$/) {
4898                     $param_name = "Returns";
4899                 }
4901                 # strip trailing whitespaces and blank lines
4902                 s/\s+\n$/\n/m;
4903                 s/\n+$/\n/sm;
4904                 #print "Found param for symbol $current_symbol : '$param_name'= '$_'";
4906                 if ($param_name eq "Deprecated") {
4907                     $in_deprecated = 1;
4908                     $Deprecated{$current_symbol} = $_;
4909                 } elsif ($param_name eq "Since") {
4910                     $in_since = 1;
4911                     chomp;
4912                     $Since{$current_symbol} = $_;
4913                 } elsif ($param_name eq "Stability") {
4914                     $in_stability = 1;
4915                     $StabilityLevel{$current_symbol} = $_;
4916                 } else {
4917                     push (@params, $param_name);
4918                     push (@params, $param_desc);
4919                     $current_param += $PARAM_FIELD_COUNT;
4920                 }
4921             } else {
4922                 # strip trailing whitespaces and blank lines
4923                 s/\s+\n$/\n/m;
4924                 s/\n+$/\n/sm;
4925                 
4926                 if (!m/^\s+$/) {
4927                     if ($in_deprecated) {
4928                         $Deprecated{$current_symbol} .= $_;
4929                     } elsif ($in_since) {
4930                         &LogWarning ($template, $., "multi-line since docs found");
4931                         #$Since{$current_symbol} .= $_;
4932                     } elsif ($in_stability) {
4933                         $StabilityLevel{$current_symbol} .= $_;
4934                     } elsif ($current_param >= 0) {
4935                         $params[$current_param] .= $_;
4936                     } else {
4937                         $symbol_doc .= $_;
4938                     }
4939                 }
4940             }
4941         }
4942     }
4944     # Remember to finish the current symbol doccs.
4945     if ($current_symbol ne "") {
4947         $symbol_doc =~ s/\s+$//;
4948         $SymbolTypes{$current_symbol} = $current_type;
4949         $SymbolDocs{$current_symbol} = $symbol_doc;
4951         # Check that the stability level is valid.
4952         if ($StabilityLevel{$current_symbol}) {
4953             $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4954         }
4956         if ($current_param >= 0) {
4957             $SymbolParams{$current_symbol} = [ @params ];
4958         } else {
4959             # Delete any existing params in case we are overriding a
4960             # previously read template.
4961             delete $SymbolParams{$current_symbol};
4962         }
4963     }
4965     close (DOCS);
4966     return 1;
4970 #############################################################################
4971 # Function    : ReadObjectHierarchy
4972 # Description : This reads in the $MODULE-hierarchy.txt file containing all
4973 #               the GtkObject subclasses described in this module (and their
4974 #               ancestors).
4975 #               It places them in the @Objects array, and places their level
4976 #               in the object hierarchy in the @ObjectLevels array, at the
4977 #               same index. GtkObject, the root object, has a level of 1.
4979 #               FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
4980 #               as it goes along, this should be split out into a separate
4981 #               function.
4983 # Arguments   : none
4984 #############################################################################
4986 sub ReadObjectHierarchy {
4987     @Objects = ();
4988     @ObjectLevels = ();
4990     if (! -f $OBJECT_TREE_FILE) {
4991         return;
4992     }
4993     if (!open (INPUT, $OBJECT_TREE_FILE)) {
4994         warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
4995         return;
4996     }
4998     # FIXME: use $OUTPUT_FORMAT
4999     # my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.$OUTPUT_FORMAT";
5000     my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
5001     my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
5003     open (OUTPUT, ">$new_tree_index")
5004         || die "Can't create $new_tree_index: $!";
5006     if ($OUTPUT_FORMAT eq "xml") {
5007         my $tree_header = $doctype_header;
5009         $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
5010         print (OUTPUT "$tree_header");
5011     }
5012     print (OUTPUT "<screen>\n");
5014     # Only emit objects if they are supposed to be documented, or if
5015     # they have documented children. To implement this, we maintain a
5016     # stack of pending objects which will be emitted if a documented
5017     # child turns up.
5018     my @pending_objects = ();
5019     my @pending_levels = ();
5020     while (<INPUT>) {
5021         if (m/\S+/) {
5022             my $object = $&;
5023             my $level = (length($`)) / 2 + 1;
5024             my $xref = "";
5026             while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
5027                 my $pobject = pop(@pending_objects);
5028                 my $plevel = pop(@pending_levels);
5029             }
5031             push (@pending_objects, $object);
5032             push (@pending_levels, $level);
5034             if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5035                 while ($#pending_levels >= 0) {
5036                     $object = shift @pending_objects;
5037                     $level = shift @pending_levels;
5038                     $xref = &MakeXRef ($object);
5040                     print (OUTPUT ' ' x ($level * 4), "$xref\n");
5041                     push (@Objects, $object);
5042                     push (@ObjectLevels, $level);
5043                 }
5044             }
5045             #else {
5046             #    LogWarning ($OBJECT_TREE_FILE, $., "unknown type $object");
5047             #}
5048         }
5049     }
5050     print (OUTPUT "</screen>\n");
5052     close (INPUT);
5053     close (OUTPUT);
5055     &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
5057     &OutputObjectList;
5060 #############################################################################
5061 # Function    : ReadInterfaces
5062 # Description : This reads in the $MODULE.interfaces file.
5064 # Arguments   : none
5065 #############################################################################
5067 sub ReadInterfaces {
5068     %Interfaces = ();
5070     if (! -f $INTERFACES_FILE) {
5071         return;
5072     }
5073     if (!open (INPUT, $INTERFACES_FILE)) {
5074         warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
5075         return;
5076     }
5078     while (<INPUT>) {
5079        chomp;
5080        my ($object, @ifaces) = split;
5081        if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5082            my @knownIfaces = ();
5084            # filter out private interfaces, but leave foreign interfaces
5085            foreach my $iface (@ifaces) {
5086                if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
5087                    push (@knownIfaces, $iface);
5088                }
5089              }
5091            $Interfaces{$object} = join(' ', @knownIfaces);
5092        }
5093     }
5094     close (INPUT);
5097 #############################################################################
5098 # Function    : ReadPrerequisites
5099 # Description : This reads in the $MODULE.prerequisites file.
5101 # Arguments   : none
5102 #############################################################################
5104 sub ReadPrerequisites {
5105     %Prerequisites = ();
5107     if (! -f $PREREQUISITES_FILE) {
5108         return;
5109     }
5110     if (!open (INPUT, $PREREQUISITES_FILE)) {
5111         warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
5112         return;
5113     }
5115     while (<INPUT>) {
5116        chomp;
5117        my ($iface, @prereqs) = split;
5118        if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
5119            my @knownPrereqs = ();
5121            # filter out private prerequisites, but leave foreign prerequisites
5122            foreach my $prereq (@prereqs) {
5123                if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
5124                   push (@knownPrereqs, $prereq);
5125                }
5126            }
5128            $Prerequisites{$iface} = join(' ', @knownPrereqs);
5129        }
5130     }
5131     close (INPUT);
5134 #############################################################################
5135 # Function    : ReadArgsFile
5136 # Description : This reads in an existing file which contains information on
5137 #               all GTK args. It creates the arrays @ArgObjects, @ArgNames,
5138 #               @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
5139 #               on the args.
5140 # Arguments   : $file - the file containing the arg information.
5141 #############################################################################
5143 sub ReadArgsFile {
5144     my ($file) = @_;
5146     my $in_arg = 0;
5147     my $arg_object;
5148     my $arg_name;
5149     my $arg_type;
5150     my $arg_flags;
5151     my $arg_nick;
5152     my $arg_blurb;
5153     my $arg_default;
5154     my $arg_range;
5156     # Reset the args info.
5157     @ArgObjects = ();
5158     @ArgNames = ();
5159     @ArgTypes = ();
5160     @ArgFlags = ();
5161     @ArgNicks = ();
5162     @ArgBlurbs = ();
5163     @ArgDefaults = ();
5164     @ArgRanges = ();
5166     if (! -f $file) {
5167         return;
5168     }
5169     if (!open (INPUT, $file)) {
5170         warn "Can't open $file - skipping args\n";
5171         return;
5172     }
5173     while (<INPUT>) {
5174         if (!$in_arg) {
5175             if (m/^<ARG>/) {
5176                 $in_arg = 1;
5177                 $arg_object = "";
5178                 $arg_name = "";
5179                 $arg_type = "";
5180                 $arg_flags = "";
5181                 $arg_nick = "";
5182                 $arg_blurb = "";
5183                 $arg_default = "";
5184                 $arg_range = "";
5185             }
5186         } else {
5187             if (m/^<NAME>(.*)<\/NAME>/) {
5188                 $arg_name = $1;
5189                 if ($arg_name =~ m/^(.*)::(.*)$/) {
5190                     $arg_object = $1;
5191                     ($arg_name = $2) =~ s/_/-/g;
5192                     #print "Found arg: $arg_name\n";
5193                 } else {
5194                     &LogWarning ($file, $., "Invalid argument name: $arg_name");
5195                 }
5196             } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
5197                 $arg_type = $1;
5198             } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
5199                 $arg_range = $1;
5200             } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
5201                 $arg_flags = $1;
5202             } elsif (m/^<NICK>(.*)<\/NICK>/) {
5203                 $arg_nick = $1;
5204             } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
5205                 $arg_blurb = $1;
5206                 if ($arg_blurb eq "(null)") {
5207                   $arg_blurb = "";
5208                   &LogWarning ($file, $., "Property ${arg_object}:${arg_name} has no documentation.");
5209                 }
5210             } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
5211                 $arg_default = $1;
5212             } elsif (m%^</ARG>%) {
5213                 #print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
5214                 push (@ArgObjects, $arg_object);
5215                 push (@ArgNames, $arg_name);
5216                 push (@ArgTypes, $arg_type);
5217                 push (@ArgRanges, $arg_range);
5218                 push (@ArgFlags, $arg_flags);
5219                 push (@ArgNicks, $arg_nick);
5220                 push (@ArgBlurbs, $arg_blurb);
5221                 push (@ArgDefaults, $arg_default);
5222                 $in_arg = 0;
5223             }
5224         }
5225     }
5226     close (INPUT);
5230 #############################################################################
5231 # Function    : CheckIsObject
5232 # Description : Returns 1 if the given name is a GObject or a subclass.
5233 #               It uses the global @Objects array.
5234 #               Note that the @Objects array only contains classes in the
5235 #               current module and their ancestors - not all GObject classes.
5236 # Arguments   : $name - the name to check.
5237 #############################################################################
5239 sub CheckIsObject {
5240     my ($name) = @_;
5242     my $object;
5243     foreach $object (@Objects) {
5244         if ($object eq $name) {
5245             return 1;
5246         }
5247     }
5248     return 0;
5252 #############################################################################
5253 # Function    : MakeReturnField
5254 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
5255 # Arguments   : $str - the string to pad.
5256 #############################################################################
5258 sub MakeReturnField {
5259     my ($str) = @_;
5261     return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));
5264 #############################################################################
5265 # Function    : GetSymbolSourceFile
5266 # Description : Get the filename where the symbol docs where taken from.
5267 # Arguments   : $symbol - the symbol name
5268 #############################################################################
5270 sub GetSymbolSourceFile {
5271     my ($symbol) = @_;
5273     if (defined($SourceSymbolSourceFile{$symbol})) {
5274         return $SourceSymbolSourceFile{$symbol};
5275     } elsif (defined($SymbolSourceFile{$symbol})) {
5276         return $SymbolSourceFile{$symbol};
5277     } else {
5278         return "";
5279     }
5282 #############################################################################
5283 # Function    : GetSymbolSourceLine
5284 # Description : Get the file line where the symbol docs where taken from.
5285 # Arguments   : $symbol - the symbol name
5286 #############################################################################
5288 sub GetSymbolSourceLine {
5289     my ($symbol) = @_;
5291     if (defined($SourceSymbolSourceLine{$symbol})) {
5292         return $SourceSymbolSourceLine{$symbol};
5293     } elsif (defined($SymbolSourceLine{$symbol})) {
5294         return $SymbolSourceLine{$symbol};
5295     } else {
5296         return 0;
5297     }