tests: add a multi-annotation test
[gtk-doc.git] / gtkdoc-mkdb.in
bloba26f716796b27d8f1a2f493d09aaaca0340a399b
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 $SGML_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' => \$SGML_MODE,
66               'default-stability' => \$DEFAULT_STABILITY,
67               'default-includes' => \$DEFAULT_INCLUDES,
68               'output-format' => \$OUTPUT_FORMAT,
69               'name-space' => \$NAME_SPACE,
70               'outputallsymbols' => \$OUTPUT_ALL_SYMBOLS,
71               'outputsymbolswithoutsince' => \$OUTPUT_SYMBOLS_WITHOUT_SINCE
72               );
73 GetOptions(\%optctl, "module=s", "source-dir:s", "source-suffixes:s", 
74     "ignore-files:s", "output-dir:s", "tmpl-dir:s", "version", "outputallsymbols",
75     "outputsymbolswithoutsince",
76     "expand-content-files:s", "main-sgml-file:s", "extra-db-files:s", "help",
77     "sgml-mode", "default-stability:s", "default-includes:s", "output-format:s",
78     "name-space:s");
80 if ($PRINT_VERSION) {
81     print "@VERSION@\n";
82     exit 0;
85 if (!$MODULE) {
86     $PRINT_HELP = 1;
89 if ($DEFAULT_STABILITY && $DEFAULT_STABILITY ne "Stable"
90     && $DEFAULT_STABILITY ne "Private" && $DEFAULT_STABILITY ne "Unstable") {
91     $PRINT_HELP = 1;
94 if ($PRINT_HELP) {
95     print <<EOF;
96 gtkdoc-mkdb version @VERSION@ - generate docbook files
98 --module=MODULE_NAME       Name of the doc module being parsed
99 --source-dir=DIRNAME       Directories which contain inline reference material
100 --source-suffixes=SUFFIXES Suffixes of source files to scan, comma-separated
101 --ignore-files=FILES       Files or directories which should not be scanned
102                            May be used more than once for multiple directories
103 --output-dir=DIRNAME       Directory to put the generated DocBook files in
104 --tmpl-dir=DIRNAME         Directory in which template files may be found
105 --main-sgml-file=FILE      File containing the toplevel DocBook file.
106 --expand-content-files=FILES Extra DocBook files to expand abbreviations in.
107 --output-format=FORMAT     Format to use for the generated docbook, XML or SGML.
108 --sgml-mode                Allow DocBook markup in inline documentation.
109 --default-stability=LEVEL  Specify default stability Level. Valid values are
110                            Stable, Unstable, or Private.
111 --default-includes=FILENAMES Specify default includes for section Synopsis
112 --name-space=NS            Omit namespace in index.
113 --version                  Print the version of this program
114 --help                     Print this help
116     exit 0;
119 my ($empty_element_end, $doctype_header);
121 # autodetect output format
122 if (! defined($OUTPUT_FORMAT) || ($OUTPUT_FORMAT eq "")) {
123     if (!$MAIN_SGML_FILE) {
124         if (-e "${MODULE}-docs.xml") {
125             $OUTPUT_FORMAT = "xml";
126         } else {
127             $OUTPUT_FORMAT = "sgml";
128         }
129     } else {
130         if ($MAIN_SGML_FILE =~ m/.*\.(.*ml)$/i) {
131             $OUTPUT_FORMAT = lc($1);
132         }
133     }
134     
135 } else {
136     $OUTPUT_FORMAT = lc($OUTPUT_FORMAT);
139 #print "DEBUG: output-format: [$OUTPUT_FORMAT]\n";
141 if ($OUTPUT_FORMAT eq "xml") {
142     if (!$MAIN_SGML_FILE) {
143         # backwards compatibility
144         if (-e "${MODULE}-docs.sgml") {
145             $MAIN_SGML_FILE = "${MODULE}-docs.sgml";
146         } else {
147             $MAIN_SGML_FILE = "${MODULE}-docs.xml";
148         }
149     }
150     $empty_element_end = "/>";
152     if (-e $MAIN_SGML_FILE) {
153         open(INPUT, "<$MAIN_SGML_FILE") || die "Can't open $MAIN_SGML_FILE";
154         $doctype_header = "";
155         while (<INPUT>) {
156             if (/^\s*<(book|chapter|article)/) {
157                 # check that the top-level tag or the doctype decl contain the xinclude namespace decl
158                 if (($_ !~ m/http:\/\/www.w3.org\/200[13]\/XInclude/) && ($doctype_header !~ m/http:\/\/www.w3.org\/200[13]\/XInclude/m)) {
159                     $doctype_header = "";
160                 }
161                 last;
162             }
163             $doctype_header .= $_;
164         }
165         close(INPUT);
166         $doctype_header =~ s/<!DOCTYPE \w+/<!DOCTYPE refentry/;
167         # if there are SYSTEM ENTITIES here, we should prepend "../" to the path
168         # FIXME: not sure if we can do this now, as people already work-around the problem
169         # $doctype_header =~ s#<!ENTITY % ([a-zA-Z-]+) SYSTEM \"([^/][a-zA-Z./]+)\">#<!ENTITY % $1 SYSTEM \"../$2\">#g;
170     } else {
171         $doctype_header =
172 "<?xml version=\"1.0\"?>\n" .
173 "<!DOCTYPE refentry PUBLIC \"-//OASIS//DTD DocBook XML V4.3//EN\"\n" .
174 "               \"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd\"\n" .
175 "[\n" .
176 "  <!ENTITY % local.common.attrib \"xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'\">\n" .
177 "]>\n";
178     }
179 } else {
180     if (!$MAIN_SGML_FILE) {
181         $MAIN_SGML_FILE = "${MODULE}-docs.sgml";
182     }
183     $empty_element_end = ">";
184     $doctype_header = "";
187 my $ROOT_DIR = ".";
189 # All the files are written in subdirectories beneath here.
190 $TMPL_DIR = $TMPL_DIR ? $TMPL_DIR : "$ROOT_DIR/tmpl";
192 # This is where we put all the DocBook output.
193 $SGML_OUTPUT_DIR = $SGML_OUTPUT_DIR ? $SGML_OUTPUT_DIR : "$ROOT_DIR/$OUTPUT_FORMAT";
195 # This file contains the object hierarchy.
196 my $OBJECT_TREE_FILE = "$ROOT_DIR/$MODULE.hierarchy";
198 # This file contains the interfaces.
199 my $INTERFACES_FILE = "$ROOT_DIR/$MODULE.interfaces";
201 # This file contains the prerequisites.
202 my $PREREQUISITES_FILE = "$ROOT_DIR/$MODULE.prerequisites";
204 # This file contains signal arguments and names.
205 my $SIGNALS_FILE = "$ROOT_DIR/$MODULE.signals";
207 # The file containing Arg information.
208 my $ARGS_FILE = "$ROOT_DIR/$MODULE.args";
210 # These global arrays store information on signals. Each signal has an entry
211 # in each of these arrays at the same index, like a multi-dimensional array.
212 my @SignalObjects;      # The GtkObject which emits the signal.
213 my @SignalNames;        # The signal name.
214 my @SignalReturns;      # The return type.
215 my @SignalFlags;        # Flags for the signal
216 my @SignalPrototypes;   # The rest of the prototype of the signal handler.
218 # These global arrays store information on Args. Each Arg has an entry
219 # in each of these arrays at the same index, like a multi-dimensional array.
220 my @ArgObjects;         # The GtkObject which has the Arg.
221 my @ArgNames;           # The Arg name.
222 my @ArgTypes;           # The Arg type - gint, GtkArrowType etc.
223 my @ArgFlags;           # How the Arg can be used - readable/writable etc.
224 my @ArgNicks;           # The nickname of the Arg.
225 my @ArgBlurbs;          # Docstring of the Arg.
226 my @ArgDefaults;        # Default value of the Arg.
227 my @ArgRanges;          # The range of the Arg type
228 # These global hashes store declaration info keyed on a symbol name.
229 my %Declarations;
230 my %DeclarationTypes;
231 my %DeclarationConditional;
232 my %DeclarationOutput;
233 my %Deprecated;
234 my %Since;
235 my %StabilityLevel;
236 my %StructHasTypedef;
238 # These global hashes store the existing documentation.
239 my %SymbolDocs;
240 my %SymbolTypes;
241 my %SymbolParams;
242 my %SymbolSourceFile;
243 my %SymbolSourceLine;
245 # These global hashes store documentation scanned from the source files.
246 my %SourceSymbolDocs;
247 my %SourceSymbolParams;
248 my %SourceSymbolSourceFile;
249 my %SourceSymbolSourceLine;
251 # all documentation goes in here, so we can do coverage analysis
252 my %AllSymbols;
253 my %AllIncompleteSymbols;
254 my %AllUnusedSymbols;
255 my %AllDocumentedSymbols;
257 # Undeclared yet documented symbols
258 my %UndeclaredSymbols;
260 # These global arrays store GObject, subclasses and the hierarchy.
261 my @Objects;
262 my @ObjectLevels;
264 my %Interfaces;
265 my %Prerequisites;
267 # holds the symbols which are mentioned in $MODULE-sections.txt and in which
268 # section they are defined
269 my %KnownSymbols;
270 my %SymbolSection;
271 my %SymbolSectionId;
273 # collects index entries
274 my %IndexEntriesFull;
275 my %IndexEntriesSince;
276 my %IndexEntriesDeprecated;
278 # Standard C preprocessor directives, which we ignore for '#' abbreviations.
279 my %PreProcessorDirectives;
280 $PreProcessorDirectives{"assert"} = 1;
281 $PreProcessorDirectives{"define"} = 1;
282 $PreProcessorDirectives{"elif"} = 1;
283 $PreProcessorDirectives{"else"} = 1;
284 $PreProcessorDirectives{"endif"} = 1;
285 $PreProcessorDirectives{"error"} = 1;
286 $PreProcessorDirectives{"if"} = 1;
287 $PreProcessorDirectives{"ifdef"} = 1;
288 $PreProcessorDirectives{"ifndef"} = 1;
289 $PreProcessorDirectives{"include"} = 1;
290 $PreProcessorDirectives{"line"} = 1;
291 $PreProcessorDirectives{"pragma"} = 1;
292 $PreProcessorDirectives{"unassert"} = 1;
293 $PreProcessorDirectives{"undef"} = 1;
294 $PreProcessorDirectives{"warning"} = 1;
296 # remember used annotation (to write minimal glossary)
297 my %AnnotationsUsed;
299 # the annotations are defined at:
300 # http://live.gnome.org/GObjectIntrospection/Annotations
301 my %AnnotationDefinition = (
302     'allow-none' => "NULL is ok, both for passing and for returning.",
303     'array' => "Parameter points to an array of items.",
304     'default' => "Default parameter value (for in case the <acronym>shadows</acronym>-to function has less parameters).",
305     'element-type' => "Generics and defining elements of containers and arrays.",
306     'error-domains' => "Typed errors. Similar to throws in Java.",
307     'in' => "Parameter for input. Default is <acronym>transfer none</acronym>.",
308     'inout' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
309     'in-out' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
310     'not-error' => "A GError parameter is not to be handled like a normal GError.",
311     'out' => "Parameter for returning results. Default is <acronym>transfer full</acronym>.",
312     'transfer container' => "Free data container after the code is done.",
313     'transfer full' => "Free data after the code is done.",
314     'transfer none' => "Don't free data after the code is done.",
315     'scope call' => "The callback is valid only during the call to the method.",
316     'scope async' => "The callback is valid until first called.",
317     'scope notfied' => "The callback is valid until the GDestroyNotify argument is called.",
318     'type' => "Override the parsed C type with given type"
321 # Create the root DocBook output directory if it doens't exist.
322 if (! -e $SGML_OUTPUT_DIR) {
323     mkdir ("$SGML_OUTPUT_DIR", 0777)
324         || die "Can't create directory: $SGML_OUTPUT_DIR";
327 # Function and other declaration output settings.
328 my $RETURN_TYPE_FIELD_WIDTH = 20;
329 my $SYMBOL_FIELD_WIDTH = 36;
330 my $SIGNAL_FIELD_WIDTH = 16;
331 my $PARAM_FIELD_COUNT = 2;
333 &ReadKnownSymbols ("$ROOT_DIR/$MODULE-sections.txt");
334 &ReadSignalsFile ($SIGNALS_FILE);
335 &ReadArgsFile ($ARGS_FILE);
336 &ReadObjectHierarchy;
337 &ReadInterfaces;
338 &ReadPrerequisites;
340 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-decl.txt", 0);
341 if (-f "$ROOT_DIR/$MODULE-overrides.txt") {
342     &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-overrides.txt", 1);
345 for my $dir (@SOURCE_DIRS) {
346     &ReadSourceDocumentation ($dir);
349 my $changed = &OutputSGML ("$ROOT_DIR/$MODULE-sections.txt");
351 # If any of the DocBook SGML files have changed, update the timestamp file (so
352 # it can be used for Makefile dependencies).
353 if ($changed || ! -e "$ROOT_DIR/sgml.stamp") {
355     # try to detect the common prefix
356     # GtkWidget, GTK_WIDGET, gtk_widget -> gtk
357     if ($NAME_SPACE eq "") {
358         $NAME_SPACE="";
359         my $pos=0;
360         my $ratio=0.0;
361         do {
362             my %prefix;
363             my $letter="";
364             foreach my $symbol (keys(%IndexEntriesFull)) {
365                 if(($NAME_SPACE eq "") || $symbol =~ /^$NAME_SPACE/i) {
366                     if (length($symbol)>$pos) {
367                         $letter=substr($symbol,$pos,1);
368                         # stop prefix scanning
369                         if ($letter eq "_") {
370                             # stop on "_"
371                             last;
372                         }
373                         # Should we also stop on a uppercase char, if last was lowercase
374                         #   GtkWidget, if we have the 'W' and had the 't' before
375                         # or should we count upper and lowercase, and stop one 2nd uppercase, if we already had a lowercase
376                         #   GtkWidget, the 'W' would be the 2nd uppercase and with 't','k' we had lowercase chars before
377                         # need to recound each time as this is per symbol
378                         $prefix{uc($letter)}++;
379                     }
380                 }
381             }
382             if ($letter ne "" && $letter ne "_") {
383                 my $maxletter="";
384                 my $maxsymbols=0;
385                 foreach $letter (keys(%prefix)) {
386                     #print "$letter: $prefix{$letter}.\n";
387                     if ($prefix{$letter}>$maxsymbols) {
388                         $maxletter=$letter;
389                         $maxsymbols=$prefix{$letter};
390                     }
391                 }
392                 $ratio = scalar(keys(%IndexEntriesFull)) / $prefix{$maxletter};
393                 #print "most symbols start with $maxletter, that is ". (100 * $ratio) ." %\n";
394                 if ($ratio > 0.9) {
395                     # do another round
396                     $NAME_SPACE .= $maxletter;
397                 }
398                 $pos++;
399             }
400             else {
401                 $ratio=0.0;
402             }
403         } while ($ratio > 0.9);
404         #print "most symbols start with $NAME_SPACE\n";
405     }
407     &OutputIndexFull;
408     &OutputDeprecatedIndex;
409     &OutputSinceIndexes;
410     &OutputAnnotationGlossary;
412     open (TIMESTAMP, ">$ROOT_DIR/sgml.stamp")
413         || die "Can't create $ROOT_DIR/sgml.stamp: $!";
414     print (TIMESTAMP "timestamp");
415     close (TIMESTAMP);
418 #############################################################################
419 # Function    : OutputObjectList
420 # Description : This outputs the alphabetical list of objects, in a columned
421 #               table.
422 #               FIXME: Currently this also outputs ancestor objects
423 #               which may not actually be in this module.
424 # Arguments   : none
425 #############################################################################
427 sub OutputObjectList {
428     my $cols = 3;
429     
430     # FIXME: use $OUTPUT_FORMAT
431     # my $old_object_index = "$SGML_OUTPUT_DIR/object_index.$OUTPUT_FORMAT";
432     my $old_object_index = "$SGML_OUTPUT_DIR/object_index.sgml";
433     my $new_object_index = "$SGML_OUTPUT_DIR/object_index.new";
435     open (OUTPUT, ">$new_object_index")
436         || die "Can't create $new_object_index: $!";
438     if ($OUTPUT_FORMAT eq "xml") {
439         my $header = $doctype_header;
441         $header =~ s/<!DOCTYPE \w+/<!DOCTYPE informaltable/;
442         print (OUTPUT "$header");
443     }
445     print (OUTPUT <<EOF);
446 <informaltable pgwide="1" frame="none">
447 <tgroup cols="$cols">
448 <colspec colwidth="1*"${empty_element_end}
449 <colspec colwidth="1*"${empty_element_end}
450 <colspec colwidth="1*"${empty_element_end}
451 <tbody>
454     my $count = 0;
455     my $object;
456     foreach $object (sort (@Objects)) {
457         my $xref = &MakeXRef ($object);
458         if ($count % $cols == 0) { print (OUTPUT "<row>\n"); }
459         print (OUTPUT "<entry>$xref</entry>\n");
460         if ($count % $cols == ($cols - 1)) { print (OUTPUT "</row>\n"); }
461         $count++;
462     }
463     if ($count == 0) {
464         # emit an empty row, since empty tables are invalid
465         print (OUTPUT "<row><entry> </entry></row>\n");
466     }
467     else {
468         if ($count % $cols > 0) {
469             print (OUTPUT "</row>\n");
470         }
471     }
473     print (OUTPUT <<EOF);
474 </tbody></tgroup></informaltable>
476     close (OUTPUT);
478     &UpdateFileIfChanged ($old_object_index, $new_object_index, 0);
482 #############################################################################
483 # Function    : OutputSGML
484 # Description : This collects the output for each section of the docs, and
485 #               outputs each file when the end of the section is found.
486 # Arguments   : $file - the $MODULE-sections.txt file which contains all of
487 #               the functions/macros/structs etc. being documented, organised
488 #               into sections and subsections.
489 #############################################################################
491 sub OutputSGML {
492     my ($file) = @_;
494     #print "Reading: $file\n";
495     open (INPUT, $file)
496         || die "Can't open $file: $!";
497     my $filename = "";
498     my $book_top = "";
499     my $book_bottom = "";
500     my $includes = (defined $DEFAULT_INCLUDES) ? $DEFAULT_INCLUDES : "";
501     my $section_includes = "";
502     my $in_section = 0;
503     my $title = "";
504     my $section_id = "";
505     my $subsection = "";
506     my $synopsis;
507     my $details;
508     my $num_symbols;
509     my $changed = 0;
510     my $signals_synop = "";
511     my $signals_desc = "";
512     my $args_synop = "";
513     my $child_args_synop = "";
514     my $style_args_synop = "";
515     my $args_desc = "";
516     my $child_args_desc = "";
517     my $style_args_desc = "";
518     my $hierarchy = "";
519     my $interfaces = "";
520     my $implementations = "";
521     my $prerequisites = "";
522     my $derived = "";
523     my @file_objects = ();
524     my %templates = ();
525     my %symbol_def_line = ();
527     # merge the source docs, in case there are no templates
528     &MergeSourceDocumentation;
530     while (<INPUT>) {
531         if (m/^#/) {
532             next;
534         } elsif (m/^<SECTION>/) {
535             $synopsis = "";
536             $details = "";
537             $num_symbols = 0;
538             $in_section = 1;
539             @file_objects = ();
540             %symbol_def_line = ();
542         } elsif (m/^<SUBSECTION\s*(.*)>/i) {
543             $synopsis .= "\n";
544             $subsection = $1;
546         } elsif (m/^<SUBSECTION>/) {
548         } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
549             $title = $1;
550             #print "Section: $title\n";
552             # We don't want warnings if object & class structs aren't used.
553             $DeclarationOutput{$title} = 1;
554             $DeclarationOutput{"${title}Class"} = 1;
555             $DeclarationOutput{"${title}Iface"} = 1;
556             $DeclarationOutput{"${title}Interface"} = 1;
558         } elsif (m/^<FILE>(.*)<\/FILE>/) {
559             $filename = $1;
560             if (! defined $templates{$filename}) {
561                if (&ReadTemplateFile ("$TMPL_DIR/$filename", 1)) {
562                    &MergeSourceDocumentation;
563                    $templates{$filename}=$.;
564                }
565             } else {
566                 &LogWarning ($file, $., "Double <FILE>$filename</FILE> entry. ".
567                     "Previous occurrence on line ".$templates{$filename}.".");
568             }
569             if (($title eq "") and (defined $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"})) {
570                 $title = $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"};
571                 # Remove trailing blanks
572                 $title =~ s/\s+$//;
573            }
575         } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
576             if ($in_section) {
577                 $section_includes = $1;
578             } else {
579                 if (defined $DEFAULT_INCLUDES) {
580                     &LogWarning ($file, $., "Default <INCLUDE> being overridden by command line option.");
581                 }
582                 else {
583                     $includes = $1;
584                 }
585             }
587         } elsif (m/^<\/SECTION>/) {
588             #print "End of section: $title\n";
589             if ($num_symbols > 0) {
590                 # collect documents
591                 if ($OUTPUT_FORMAT eq "xml") {
592                     $book_bottom .= "    <xi:include href=\"xml/$filename.xml\"/>\n";
593                 } else {
594                     $book_top.="<!ENTITY $section_id SYSTEM \"sgml/$filename.sgml\">\n";
595                     $book_bottom .= "    &$section_id;\n";
596                 }
598                 if (defined ($SourceSymbolDocs{"$TMPL_DIR/$filename:Include"})) {
599                     if ($section_includes) {
600                         &LogWarning ($file, $., "Section <INCLUDE> being overridden by inline comments.");
601                     }
602                     $section_includes = $SourceSymbolDocs{"$TMPL_DIR/$filename:Include"};
603                 }
604                 if ($section_includes eq "") {
605                     $section_includes = $includes;
606                 }
608                  $signals_synop =~ s/^\n*//g;
609                  $signals_synop =~ s/\n+$/\n/g;
610                 if ($signals_synop ne '') {
611                     $signals_synop = <<EOF;
612 <refsect1 id="$section_id.signals" role="signal_proto">
613 <title role="signal_proto.title">Signals</title>
614 <synopsis>
615 ${signals_synop}</synopsis>
616 </refsect1>
618                      $signals_desc =~ s/^\n*//g;
619                      $signals_desc =~ s/\n+$/\n/g;
620                      $signals_desc =~ s/(\s|\n)+$//ms;
621                     $signals_desc  = <<EOF;
622 <refsect1 id="$section_id.signal-details" role="signals">
623 <title role="signals.title">Signal Details</title>
624 $signals_desc
625 </refsect1>
627                 }
629                  $args_synop =~ s/^\n*//g;
630                  $args_synop =~ s/\n+$/\n/g;
631                 if ($args_synop ne '') {
632                     $args_synop = <<EOF;
633 <refsect1 id="$section_id.properties" role="properties">
634 <title role="properties.title">Properties</title>
635 <synopsis>
636 ${args_synop}</synopsis>
637 </refsect1>
639                      $args_desc =~ s/^\n*//g;
640                      $args_desc =~ s/\n+$/\n/g;
641                      $args_desc =~ s/(\s|\n)+$//ms;
642                     $args_desc  = <<EOF;
643 <refsect1 id="$section_id.property-details" role="property_details">
644 <title role="property_details.title">Property Details</title>
645 $args_desc
646 </refsect1>
648                 }
650                  $child_args_synop =~ s/^\n*//g;
651                  $child_args_synop =~ s/\n+$/\n/g;
652                 if ($child_args_synop ne '') {
653                     $args_synop .= <<EOF;
654 <refsect1 id="$section_id.child-properties" role="child_properties">
655 <title role="child_properties.title">Child Properties</title>
656 <synopsis>
657 ${child_args_synop}</synopsis>
658 </refsect1>
660                      $child_args_desc =~ s/^\n*//g;
661                      $child_args_desc =~ s/\n+$/\n/g;
662                      $child_args_desc =~ s/(\s|\n)+$//ms;
663                     $args_desc .= <<EOF;
664 <refsect1 id="$section_id.child-property-details" role="child_property_details">
665 <title role="child_property_details.title">Child Property Details</title>
666 $child_args_desc
667 </refsect1>
669                 }
671                  $style_args_synop =~ s/^\n*//g;
672                  $style_args_synop =~ s/\n+$/\n/g;
673                 if ($style_args_synop ne '') {
674                     $args_synop .= <<EOF;
675 <refsect1 id="$section_id.style-properties" role="style_properties">
676 <title role="style_properties.title">Style Properties</title>
677 <synopsis>
678 ${style_args_synop}</synopsis>
679 </refsect1>
681                      $style_args_desc =~ s/^\n*//g;
682                      $style_args_desc =~ s/\n+$/\n/g;
683                      $style_args_desc =~ s/(\s|\n)+$//ms;
684                     $args_desc .= <<EOF;
685 <refsect1 id="$section_id.style-property-details" role="style_properties_details">
686 <title role="style_properties_details.title">Style Property Details</title>
687 $style_args_desc
688 </refsect1>
690                 }
692                  $hierarchy =~ s/^\n*//g;
693                  $hierarchy =~ s/\n+$/\n/g;
694                  $hierarchy =~ s/(\s|\n)+$//ms;
695                 if ($hierarchy ne "") {
696                     $hierarchy = <<EOF;
697 <refsect1 id="$section_id.object-hierarchy" role="object_hierarchy">
698 <title role="object_hierarchy.title">Object Hierarchy</title>
699 $hierarchy
700 </refsect1>
702                 }
704                  $interfaces =~ s/^\n*//g;
705                  $interfaces =~ s/\n+$/\n/g;
706                  $interfaces =~ s/(\s|\n)+$//ms;
707                 if ($interfaces ne "") {
708                     $interfaces = <<EOF;
709 <refsect1 id="$section_id.implemented-interfaces" role="impl_interfaces">
710 <title role="impl_interfaces.title">Implemented Interfaces</title>
711 $interfaces
712 </refsect1>
714                 }
716                  $implementations =~ s/^\n*//g;
717                  $implementations =~ s/\n+$/\n/g;
718                  $implementations =~ s/(\s|\n)+$//ms;
719                 if ($implementations ne "") {
720                     $implementations = <<EOF;
721 <refsect1 id="$section_id.implementations" role="implementations">
722 <title role="implementations.title">Known Implementations</title>
723 $implementations
724 </refsect1>
726                 }
728                  $prerequisites =~ s/^\n*//g;
729                  $prerequisites =~ s/\n+$/\n/g;
730                  $prerequisites =~ s/(\s|\n)+$//ms;
731                 if ($prerequisites ne "") {
732                     $prerequisites = <<EOF;
733 <refsect1 id="$section_id.prerequisites" role="prerequisites">
734 <title role="prerequisites.title">Prerequisites</title>
735 $prerequisites
736 </refsect1>
738                 }
740                  $derived =~ s/^\n*//g;
741                  $derived =~ s/\n+$/\n/g;
742                  $derived =~ s/(\s|\n)+$//ms;
743                 if ($derived ne "") {
744                     $derived = <<EOF;
745 <refsect1 id="$section_id.derived-interfaces" role="derived_interfaces">
746 <title role="derived_interfaces.title">Known Derived Interfaces</title>
747 $derived
748 </refsect1>
750                 }
752                 $synopsis =~ s/^\n*//g;
753                 $synopsis =~ s/\n+$/\n/g;
754                 my $file_changed = &OutputSGMLFile ($filename, $title, $section_id,
755                                                     $section_includes,
756                                                     \$synopsis, \$details,
757                                                     \$signals_synop, \$signals_desc,
758                                                     \$args_synop, \$args_desc,
759                                                     \$hierarchy, \$interfaces,
760                                                     \$implementations,
761                                                     \$prerequisites, \$derived,
762                                                     \@file_objects);
763                 if ($file_changed) {
764                     $changed = 1;
765                 }
766             }
767             $title = "";
768             $section_id = "";
769             $subsection = "";
770             $in_section = 0;
771             $section_includes = "";
772             $signals_synop = "";
773             $signals_desc = "";
774             $args_synop = "";
775             $child_args_synop = "";
776             $style_args_synop = "";
777             $args_desc = "";
778             $child_args_desc = "";
779             $style_args_desc = "";
780             $hierarchy = "";
781             $interfaces = "";
782             $implementations = "";
783             $prerequisites = "";
784             $derived = "";
786         } elsif (m/^(\S+)/) {
787             my $symbol = $1;
788             #print "  Symbol: $symbol\n";
790             # check for duplicate entries
791             if (! defined $symbol_def_line{$symbol}) {
792                 my $declaration = $Declarations{$symbol};
793                 if (defined ($declaration)) {
794                     # We don't want standard macros/functions of GObjects,
795                     # or private declarations.
796                     if ($subsection ne "Standard" && $subsection ne "Private") {
797                         if (&CheckIsObject ($symbol)) {
798                             push @file_objects, $symbol;
799                         }
800                         my ($synop, $desc) = &OutputDeclaration ($symbol,
801                                                                  $declaration);
802                         my ($sig_synop, $sig_desc) = &GetSignals ($symbol);
803                         my ($arg_synop, $child_arg_synop, $style_arg_synop,
804                             $arg_desc, $child_arg_desc, $style_arg_desc) = &GetArgs ($symbol);
805                         my $hier = &GetHierarchy ($symbol);
806                         my $ifaces = &GetInterfaces ($symbol);
807                         my $impls = &GetImplementations ($symbol);
808                         my $prereqs = &GetPrerequisites ($symbol);
809                         my $der = &GetDerived ($symbol);
810                         $synopsis .= $synop;
811                         $details .= $desc;
812                         $signals_synop .= $sig_synop;
813                         $signals_desc .= $sig_desc;
814                         $args_synop .= $arg_synop;
815                         $child_args_synop .= $child_arg_synop;
816                         $style_args_synop .= $style_arg_synop;
817                         $args_desc .= $arg_desc;
818                         $child_args_desc .= $child_arg_desc;
819                         $style_args_desc .= $style_arg_desc;
820                         $hierarchy .= $hier;
821                         $interfaces .= $ifaces;
822                         $implementations .= $impls;
823                         $prerequisites .= $prereqs;
824                         $derived .= $der;
825                     }
826     
827                     # Note that the declaration has been output.
828                     $DeclarationOutput{$symbol} = 1;
829                 } elsif ($subsection ne "Standard" && $subsection ne "Private") {
830                     $UndeclaredSymbols{$symbol} = 1;
831                     &LogWarning ($file, $., "No declaration found for $symbol.");
832                 }
833                 $num_symbols++;
834                 $symbol_def_line{$symbol}=$.;
836                 if ($section_id eq "") {
837                     if($title eq "" && $filename eq "") {
838                         &LogWarning ($file, $., "Section has no title and no file.");
839                     }
840                     # FIXME: one of those would be enough
841                     # filename should be an internal detail for gtk-doc
842                     if ($title eq "") {
843                         $title = $filename;
844                     } elsif ($filename eq "") {
845                         $filename = $title;
846                     }
847                     $filename =~ s/\s/_/g;
848         
849                     $section_id = $SourceSymbolDocs{"$TMPL_DIR/$filename:Section_Id"};
850                     if (defined ($section_id) && $section_id !~ m/^\s*$/) {
851                         # Remove trailing blanks and use as is
852                         $section_id =~ s/\s+$//;
853                     } elsif (&CheckIsObject ($title)) {
854                         # GObjects use their class name as the ID.
855                         $section_id = &CreateValidSGMLID ($title);
856                     } else {
857                         $section_id = &CreateValidSGMLID ("$MODULE-$title");
858                     }
859                 }
860                 $SymbolSection{$symbol}=$title;
861                 $SymbolSectionId{$symbol}=$section_id;
862             }
863             else {
864                 &LogWarning ($file, $., "Double symbol entry for $symbol. ".
865                     "Previous occurrence on line ".$symbol_def_line{$symbol}.".");
866             }
867         }
868     }
869     close (INPUT);
871     &OutputMissingDocumentation;
872     &OutputUndeclaredSymbols;
873     &OutputUnusedSymbols;
875     if ($OUTPUT_ALL_SYMBOLS) {
876         &OutputAllSymbols;
877     }
878     if ($OUTPUT_SYMBOLS_WITHOUT_SINCE) {
879         &OutputSymbolsWithoutSince;
880     }
882     for $filename (split (' ', $EXPAND_CONTENT_FILES)) {
883         my $file_changed = &OutputExtraFile ($filename);
884         if ($file_changed) {
885             $changed = 1;
886         }
887     }
889     &OutputBook ($book_top, $book_bottom);
891     return $changed;
894 #############################################################################
895 # Function    : OutputIndex
896 # Description : This writes an indexlist that can be included into the main-
897 #               document into an <index> tag.
898 #############################################################################
900 sub OutputIndex {
901     my ($basename, $apiindexref ) = @_;
902     my %apiindex = %{$apiindexref};
903     my $old_index = "$SGML_OUTPUT_DIR/$basename.xml";
904     my $new_index = "$SGML_OUTPUT_DIR/$basename.new";
905     my $lastletter = " ";
906     my $divopen = 0;
907     my $symbol;
908     my $short_symbol;
910     open (OUTPUT, ">$new_index")
911         || die "Can't create $new_index";
913     my $header = $doctype_header;
914     $header =~ s/<!DOCTYPE \w+/<!DOCTYPE indexdiv/;
916     print (OUTPUT "$header<indexdiv>\n");
918     #print "generate $basename index (".%apiindex." entries)\n";
919     
920     # do a case insensitive sort while chopping off the prefix
921     foreach my $hash (
922         sort { $$a{criteria} cmp $$b{criteria} }
923         map { my $x = uc($_); $x =~ s/^$NAME_SPACE\_?(.*)/$1/i; { criteria => $x, original => $_, short => $1 } } 
924         keys %apiindex) {
926         $symbol = $$hash{original};
927         if (defined($$hash{short})) {
928             $short_symbol = $$hash{short};
929         } else {
930             $short_symbol = $symbol;
931         }
933         # generate a short symbol description
934         my $symbol_desc = "";
935         my $symbol_section = "";
936         my $symbol_section_id = "";
937         my $symbol_type = "";
938         if (defined($DeclarationTypes{$symbol})) {
939           $symbol_type = lc($DeclarationTypes{$symbol});
940         }
941         if ($symbol_type eq "") {
942             #print "trying symbol $symbol\n";
943             if ($symbol =~ m/(.*)::(.*)/) {
944                 my $oname = $1;
945                 my $osym = $2;
946                 my $i;
947                 #print "  trying object signal ${oname}:$osym in ".$#SignalNames." signals\n";
948                 for ($i = 0; $i <= $#SignalNames; $i++) {
949                     if ($SignalNames[$i] eq $osym) {
950                         $symbol_type = "object signal";
951                         if (defined($SymbolSection{$oname})) {
952                            $symbol_section = $SymbolSection{$oname};
953                            $symbol_section_id = $SymbolSectionId{$oname};
954                         }
955                         last;
956                     }
957                 }
958             } elsif ($symbol =~ m/(.*):(.*)/) {
959                 my $oname = $1;
960                 my $osym = $2;
961                 my $i;
962                 #print "  trying object property ${oname}::$osym in ".$#ArgNames." properties\n";
963                 for ($i = 0; $i <= $#ArgNames; $i++) {
964                     #print "    ".$ArgNames[$i]."\n";
965                     if ($ArgNames[$i] eq $osym) {
966                         $symbol_type = "object property";
967                         if (defined($SymbolSection{$oname})) {
968                            $symbol_section = $SymbolSection{$oname};
969                            $symbol_section_id = $SymbolSectionId{$oname};
970                         }
971                         last;
972                     }
973                 }
974             }
975         } else {
976            if (defined($SymbolSection{$symbol})) {
977                $symbol_section = $SymbolSection{$symbol};
978                $symbol_section_id = $SymbolSectionId{$symbol};
979            }
980         }
981         if ($symbol_type ne "") {
982            $symbol_desc=", $symbol_type";
983            if ($symbol_section ne "") {
984                $symbol_desc.=" in <link linkend=\"$symbol_section_id\">$symbol_section</link>";
985                #$symbol_desc.=" in ". &ExpandAbbreviations($symbol, "#$symbol_section");
986            }
987         }
989         my $curletter = uc(substr($short_symbol,0,1));
990         my $id = $apiindex{$symbol};
992         #print "  add symbol $symbol with $id to index in section $curletter\n";
994         if ($curletter ne $lastletter) {
995             $lastletter = $curletter;
997             if ($divopen == 1) {
998                 print (OUTPUT "</indexdiv>\n");
999             }
1000             print (OUTPUT "<indexdiv><title>$curletter</title>\n");
1001             $divopen = 1;
1002         }
1004         print (OUTPUT <<EOF);
1005 <indexentry><primaryie linkends="$id"><link linkend="$id">$symbol</link>$symbol_desc</primaryie></indexentry>
1007     }
1009     if ($divopen == 1) {
1010         print (OUTPUT "</indexdiv>\n");
1011     }
1012     print (OUTPUT "</indexdiv>\n");
1013     close (OUTPUT);
1015     &UpdateFileIfChanged ($old_index, $new_index, 0);
1019 #############################################################################
1020 # Function    : OutputIndexFull
1021 # Description : This writes the full api indexlist that can be included into the
1022 #               main document into an <index> tag.
1023 #############################################################################
1025 sub OutputIndexFull {
1026     &OutputIndex ("api-index-full", \%IndexEntriesFull);
1030 #############################################################################
1031 # Function    : OutputDeprecatedIndex
1032 # Description : This writes the deprecated api indexlist that can be included
1033 #               into the main document into an <index> tag.
1034 #############################################################################
1036 sub OutputDeprecatedIndex {
1037     &OutputIndex ("api-index-deprecated", \%IndexEntriesDeprecated);
1041 #############################################################################
1042 # Function    : OutputSinceIndexes
1043 # Description : This writes the 'since' api indexlists that can be included into
1044 #               the main document into an <index> tag.
1045 #############################################################################
1047 sub OutputSinceIndexes {
1048     my @sinces = keys %{{ map { $_ => 1 } values %Since }};
1050     foreach my $version (@sinces) {
1051         #print "Since : [$version]\n";
1052         # TODO make filtered hash
1053         #my %index = grep { $Since{$_} eq $version } %IndexEntriesSince;
1054         my %index = map { $_ => $IndexEntriesSince{$_} } grep { $Since{$_} eq $version } keys %IndexEntriesSince;
1056         &OutputIndex ("api-index-$version", \%index);
1057     }
1060 #############################################################################
1061 # Function    : OutputAnnotationGlossary
1062 # Description : This writes a glossary of the used annotation terms into a
1063 #               separate glossary file that can be included into the main
1064 #               document.
1065 #############################################################################
1067 sub OutputAnnotationGlossary {
1068     my $old_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.xml";
1069     my $new_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.new";
1070     my $lastletter = " ";
1071     my $divopen = 0;
1073     # if there are no annotations used return
1074     return if (! keys(%AnnotationsUsed));
1076     # add acronyms that are referenced from acronym text
1077 rerun:
1078     foreach my $annotation (keys(%AnnotationsUsed)) {
1079         if(defined($AnnotationDefinition{$annotation})) {
1080             if($AnnotationDefinition{$annotation} =~ m/<acronym>([\w ]+)<\/acronym>/) {
1081                 if (!exists($AnnotationsUsed{$1})) {
1082                     $AnnotationsUsed{$1} = 1;
1083                     goto rerun;
1084                 }
1085             }
1086         }
1087     }
1089     open (OUTPUT, ">$new_glossary")
1090         || die "Can't create $new_glossary";
1092     my $header = $doctype_header;
1093     $header =~ s/<!DOCTYPE \w+/<!DOCTYPE glossary/;
1095     print (OUTPUT  <<EOF);
1096 $header
1097 <glossary id="annotation-glossary">
1098   <title>Annotation Glossary</title>
1101     foreach my $annotation (keys(%AnnotationsUsed)) {
1102         if(defined($AnnotationDefinition{$annotation})) {
1103             my $def = $AnnotationDefinition{$annotation};
1104             my $curletter = uc(substr($annotation,0,1));
1105     
1106             if ($curletter ne $lastletter) {
1107                 $lastletter = $curletter;
1108           
1109                 if ($divopen == 1) {
1110                     print (OUTPUT "</glossdiv>\n");
1111                 }
1112                 print (OUTPUT "<glossdiv><title>$curletter</title>\n");
1113                 $divopen = 1;
1114             }
1115             print (OUTPUT <<EOF);
1116     <glossentry>
1117       <glossterm><anchor id="annotation-glossterm-$annotation"/>$annotation</glossterm>
1118       <glossdef>
1119         <para>$def</para>
1120       </glossdef>
1121     </glossentry>
1123         }
1124     }
1126     if ($divopen == 1) {
1127         print (OUTPUT "</glossdiv>\n");
1128     }
1129     print (OUTPUT "</glossary>\n");
1130     close (OUTPUT);
1132     &UpdateFileIfChanged ($old_glossary, $new_glossary, 0);
1135 #############################################################################
1136 # Function    : ReadKnownSymbols
1137 # Description : This collects the names of non-private symbols from the
1138 #               $MODULE-sections.txt file.
1139 # Arguments   : $file - the $MODULE-sections.txt file which contains all of
1140 #               the functions/macros/structs etc. being documented, organised
1141 #               into sections and subsections.
1142 #############################################################################
1144 sub ReadKnownSymbols {
1145     my ($file) = @_;
1147     my $subsection = "";
1149     #print "Reading: $file\n";
1150     open (INPUT, $file)
1151         || die "Can't open $file: $!";
1153     while (<INPUT>) {
1154         if (m/^#/) {
1155             next;
1157         } elsif (m/^<SECTION>/) {
1158             $subsection = "";
1160         } elsif (m/^<SUBSECTION\s*(.*)>/i) {
1161             $subsection = $1;
1163         } elsif (m/^<SUBSECTION>/) {
1164             next;
1166         } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
1167             next;
1169         } elsif (m/^<FILE>(.*)<\/FILE>/) {
1170             $KnownSymbols{"$TMPL_DIR/$1:Long_Description"} = 1;
1171             $KnownSymbols{"$TMPL_DIR/$1:Short_Description"} = 1;
1172             next;
1174         } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
1175             next;
1177         } elsif (m/^<\/SECTION>/) {
1178             next;
1180         } elsif (m/^(\S+)/) {
1181             my $symbol = $1;
1183             if ($subsection ne "Standard" && $subsection ne "Private") {
1184                 $KnownSymbols{$symbol} = 1;
1185             }
1186             else {
1187                 $KnownSymbols{$symbol} = 0;
1188             }
1189         }
1190     }
1191     close (INPUT);
1195 #############################################################################
1196 # Function    : OutputDeclaration
1197 # Description : Returns the synopsis and detailed description DocBook
1198 #               describing one function/macro etc.
1199 # Arguments   : $symbol - the name of the function/macro begin described.
1200 #               $declaration - the declaration of the function/macro.
1201 #############################################################################
1203 sub OutputDeclaration {
1204     my ($symbol, $declaration) = @_;
1206     my $type = $DeclarationTypes {$symbol};
1207     if ($type eq 'MACRO') {
1208         return &OutputMacro ($symbol, $declaration);
1209     } elsif ($type eq 'TYPEDEF') {
1210         return &OutputTypedef ($symbol, $declaration);
1211     } elsif ($type eq 'STRUCT') {
1212         return &OutputStruct ($symbol, $declaration);
1213     } elsif ($type eq 'ENUM') {
1214         return &OutputEnum ($symbol, $declaration);
1215     } elsif ($type eq 'UNION') {
1216         return &OutputUnion ($symbol, $declaration);
1217     } elsif ($type eq 'VARIABLE') {
1218         return &OutputVariable ($symbol, $declaration);
1219     } elsif ($type eq 'FUNCTION') {
1220         return &OutputFunction ($symbol, $declaration, $type);
1221     } elsif ($type eq 'USER_FUNCTION') {
1222         return &OutputFunction ($symbol, $declaration, $type);
1223     } else {
1224         die "Unknown symbol type";
1225     }
1229 #############################################################################
1230 # Function    : OutputSymbolTraits
1231 # Description : Returns the Since and StabilityLevel paragraphs for a symbol.
1232 # Arguments   : $symbol - the name of the function/macro begin described.
1233 #############################################################################
1235 sub OutputSymbolTraits {
1236     my ($symbol) = @_;
1237     my $desc = "";
1239     if (exists $Since{$symbol}) {
1240         $desc .= "<para role=\"since\">Since $Since{$symbol}</para>";
1241     }
1242     if (exists $StabilityLevel{$symbol}) {
1243         $desc .= "<para role=\"stability\">Stability Level: $StabilityLevel{$symbol}</para>";
1244     }
1245     return $desc;
1248 #############################################################################
1249 # Function    : Outpu{Symbol,Section}ExtraLinks
1250 # Description : Returns extralinks for the symbol (if enabled).
1251 # Arguments   : $symbol - the name of the function/macro begin described.
1252 #############################################################################
1254 sub uri_escape {
1255     my $text = $_[0];
1256     return undef unless defined $text;
1258     # Build a char to hex map
1259     my %escapes = ();
1260     for (0..255) {
1261             $escapes{chr($_)} = sprintf("%%%02X", $_);
1262     }
1264     # Default unsafe characters.  RFC 2732 ^(uric - reserved)
1265     $text =~ s/([^A-Za-z0-9\-_.!~*'()])/$escapes{$1}/g;
1267     return $text;
1270 sub OutputSymbolExtraLinks {
1271     my ($symbol) = @_;
1272     my $desc = "";
1274     if (0) { # NEW FEATURE: needs configurability
1275     my $sstr = &uri_escape($symbol);
1276     my $mstr = &uri_escape($MODULE);
1277     $desc .= <<EOF;
1278 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1279 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&amp;symbol=$sstr">edit documentation</ulink>
1281     }
1282     return $desc;
1285 sub OutputSectionExtraLinks {
1286     my ($symbol,$docsymbol) = @_;
1287     my $desc = "";
1289     if (0) { # NEW FEATURE: needs configurability
1290     my $sstr = &uri_escape($symbol);
1291     my $mstr = &uri_escape($MODULE);
1292     my $dsstr = &uri_escape($docsymbol);
1293     $desc .= <<EOF;
1294 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1295 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&amp;symbol=$dsstr">edit documentation</ulink>
1297     }
1298     return $desc;
1302 #############################################################################
1303 # Function    : OutputMacro
1304 # Description : Returns the synopsis and detailed description of a macro.
1305 # Arguments   : $symbol - the macro.
1306 #               $declaration - the declaration of the macro.
1307 #############################################################################
1309 sub OutputMacro {
1310     my ($symbol, $declaration) = @_;
1311     my $id = &CreateValidSGMLID ($symbol);
1312     my $condition = &MakeConditionDescription ($symbol);
1313     my $synop = &MakeReturnField("#define") . "<link linkend=\"$id\">$symbol</link>";
1314     my $desc;
1316     my @fields = ParseMacroDeclaration($declaration, \&CreateValidSGML);
1317     my $title = $symbol . (@fields ? "()" : "");
1319     $desc = "<refsect2 id=\"$id\" role=\"macro\"$condition>\n<title>$title</title>\n";
1320     $desc .= MakeIndexterms($symbol, $id);
1321     $desc .= "\n";
1322     $desc .= OutputSymbolExtraLinks($symbol);
1324     if (@fields) {
1325         if (length ($symbol) < $SYMBOL_FIELD_WIDTH) {
1326             $synop .= (' ' x ($SYMBOL_FIELD_WIDTH - length ($symbol)));
1327         }
1328     
1329         $synop .= "(";
1330         for (my $i = 1; $i <= $#fields; $i += 2) {
1331             my $field_name = $fields[$i];
1333             if ($i == 1) {
1334                 $synop .= "$field_name";
1335             } else {
1336                 $synop .= ",\n"
1337                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1338                     . " $field_name";
1339             }
1340         }
1341         $synop .= ")";
1342     }
1343     $synop .= "\n";
1345     # Don't output the macro definition if is is a conditional macro or it
1346     # looks like a function, i.e. starts with "g_" or "_?gnome_", or it is
1347     # longer than 2 lines, otherwise we get lots of complicated macros like
1348     # g_assert.
1349     if (!defined ($DeclarationConditional{$symbol}) && ($symbol !~ m/^g_/)
1350         && ($symbol !~ m/^_?gnome_/) && (($declaration =~ tr/\n//) < 2)) {
1351         my $decl_out = &CreateValidSGML ($declaration);
1352         $desc .= "<programlisting>$decl_out</programlisting>\n";
1353     } else {
1354         $desc .= "<programlisting>" . &MakeReturnField("#define") . "$symbol";
1355         if ($declaration =~ m/^\s*#\s*define\s+\w+(\([^\)]*\))/) {
1356             my $args = $1;
1357             my $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH - length ("#define "));
1358             # Align each line so that if should all line up OK.
1359             $args =~ s/\n/\n$pad/gm;
1360             $desc .= &CreateValidSGML ($args);
1361         }
1362         $desc .= "</programlisting>\n";
1363     }
1365     $desc .= &MakeDeprecationNote($symbol);
1367     my $parameters = &OutputParamDescriptions ("MACRO", $symbol, @fields);
1368     my $parameters_output = 0;
1370     if (defined ($SymbolDocs{$symbol})) {
1371         my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1373         # Try to insert the parameter table at the author's desired position.
1374         # Otherwise we need to tag it onto the end.
1375         if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1376           $parameters_output = 1;
1377         }
1378         $desc .= $symbol_docs;
1379     }
1381     if ($parameters_output == 0) {
1382         $desc .= $parameters;
1383     }
1385     $desc .= OutputSymbolTraits ($symbol);
1386     $desc .= "</refsect2>\n";
1387     return ($synop, $desc);
1391 #############################################################################
1392 # Function    : OutputTypedef
1393 # Description : Returns the synopsis and detailed description of a typedef.
1394 # Arguments   : $symbol - the typedef.
1395 #               $declaration - the declaration of the typedef,
1396 #                 e.g. 'typedef unsigned int guint;'
1397 #############################################################################
1399 sub OutputTypedef {
1400     my ($symbol, $declaration) = @_;
1401     my $id = &CreateValidSGMLID ($symbol);
1402     my $condition = &MakeConditionDescription ($symbol);
1403     my $synop = &MakeReturnField("typedef") . "<link linkend=\"$id\">$symbol</link>;\n";
1404     my $desc = "<refsect2 id=\"$id\" role=\"typedef\"$condition>\n<title>$symbol</title>\n";
1406     $desc .= MakeIndexterms($symbol, $id);
1407     $desc .= "\n";
1408     $desc .= OutputSymbolExtraLinks($symbol);
1410     if (!defined ($DeclarationConditional{$symbol})) {
1411         my $decl_out = &CreateValidSGML ($declaration);
1412         $desc .= "<programlisting>$decl_out</programlisting>\n";
1413     }
1415     $desc .= &MakeDeprecationNote($symbol);
1417     if (defined ($SymbolDocs{$symbol})) {
1418         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1419     }
1420     $desc .= OutputSymbolTraits ($symbol);
1421     $desc .= "</refsect2>\n";
1422     return ($synop, $desc);
1426 #############################################################################
1427 # Function    : OutputStruct
1428 # Description : Returns the synopsis and detailed description of a struct.
1429 #               We check if it is a object struct, and if so we only output
1430 #               parts of it that are noted as public fields.
1431 #               We also use a different SGML ID for object structs, since the
1432 #               original ID is used for the entire RefEntry.
1433 # Arguments   : $symbol - the struct.
1434 #               $declaration - the declaration of the struct.
1435 #############################################################################
1437 sub OutputStruct {
1438     my ($symbol, $declaration) = @_;
1440     my $is_object_struct = 0;
1441     my $default_to_public = 1;
1442     if (&CheckIsObject ($symbol)) {
1443         #print "Found object struct: $symbol\n";
1444         $is_object_struct = 1;
1445         $default_to_public = 0;
1446     }
1448     my $id;
1449     my $condition;
1450     if ($is_object_struct) {
1451         $id = &CreateValidSGMLID ($symbol . "_struct");
1452         $condition = &MakeConditionDescription ($symbol . "_struct");
1453     } else {
1454         $id = &CreateValidSGMLID ($symbol);
1455         $condition = &MakeConditionDescription ($symbol);
1456     }
1458     # Determine if it is a simple struct or it also has a typedef.
1459     my $has_typedef = 0;
1460     if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1461       $has_typedef = 1;
1462     }
1464     my $synop;
1465     my $desc;
1466     if ($has_typedef) {
1467         # For structs with typedefs we just output the struct name.
1468         $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1469         $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>$symbol</title>\n";
1470     } else {
1471         $synop = &MakeReturnField("struct") . "<link linkend=\"$id\">$symbol</link>;\n";
1472         $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>struct $symbol</title>\n";
1473     }
1475     $desc .= MakeIndexterms($symbol, $id);
1476     $desc .= "\n";
1477     $desc .= OutputSymbolExtraLinks($symbol);
1479     # Form a pretty-printed, private-data-removed form of the declaration
1481     my $decl_out = "";
1482     if ($declaration =~ m/^\s*$/) {
1483         #print "Found opaque struct: $symbol\n";
1484         $decl_out = "typedef struct _$symbol $symbol;";
1485     } elsif ($declaration =~ m/^\s*struct\s+\w+\s*;\s*$/) {
1486         #print "Found opaque struct: $symbol\n";
1487         $decl_out = "struct $symbol;";
1488     } else {
1489         my $public = $default_to_public;
1490         my $new_declaration = "";
1491         my $decl_line;
1492         my $decl = $declaration;
1494         if ($decl =~ m/^\s*(typedef\s+)?struct\s*\w*\s*(?:\/\*.*\*\/)?\s*{(.*)}\s*\w*\s*;\s*$/s) {
1495             my $struct_contents = $2;
1497             foreach $decl_line (split (/\n/, $struct_contents)) {
1498                 #print "Struct line: $decl_line\n";
1499                 if ($decl_line =~ m%/\*\s*<\s*public\s*>\s*\*/%) {
1500                     $public = 1;
1501                 } elsif ($decl_line =~ m%/\*\s*<\s*(private|protected)\s*>\s*\*/%) {
1502                     $public = 0;
1503                 } elsif ($public) {
1504                     $new_declaration .= $decl_line . "\n";
1505                 }
1506             }
1508             if ($new_declaration) {
1509                 # Strip any blank lines off the ends.
1510                 $new_declaration =~ s/^\s*\n//;
1511                 $new_declaration =~ s/\n\s*$/\n/;
1513                 if ($has_typedef) {
1514                     $decl_out = "typedef struct {\n" . $new_declaration
1515                       . "} $symbol;\n";
1516                 } else {
1517                     $decl_out = "struct $symbol {\n" . $new_declaration
1518                       . "};\n";
1519                 }
1520             }
1521         } else {
1522             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1523                 "Couldn't parse struct:\n$declaration");
1524         }
1526         # If we couldn't parse the struct or it was all private, output an
1527         # empty struct declaration.
1528         if ($decl_out eq "") {
1529             if ($has_typedef) {
1530                 $decl_out = "typedef struct _$symbol $symbol;";
1531             } else {
1532                 $decl_out = "struct $symbol;";
1533             }
1534         }
1535     }
1537     $decl_out = &CreateValidSGML ($decl_out);
1538     $desc .= "<programlisting>$decl_out</programlisting>\n";
1540     $desc .= &MakeDeprecationNote($symbol);
1542     if (defined ($SymbolDocs{$symbol})) {
1543         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1544     }
1546     # Create a table of fields and descriptions
1548     # FIXME: Inserting &#160's into the produced type declarations here would
1549     #        improve the output in most situations ... except for function
1550     #        members of structs!
1551     my @fields = ParseStructDeclaration($declaration, !$default_to_public,
1552                                         0, \&MakeXRef,
1553                                         sub {
1554                                             "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1555                                         });
1556     my $params = $SymbolParams{$symbol};
1558     # If no parameters are filled in, we don't generate the description
1559     # table, for backwards compatibility
1561     my $found = 0;
1562     if (defined $params) {
1563         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1564             if ($params->[$i] =~ /\S/) {
1565                 $found = 1;
1566                 last;
1567             }
1568         }
1569     }
1571     if ($found) {
1572         my %field_descrs = @$params;
1573         my $missing_parameters = "";
1574         my $unused_parameters = "";
1576         $desc .= "<variablelist role=\"struct\">\n";
1577         while (@fields) {
1578             my $field_name = shift @fields;
1579             my $text = shift @fields;
1580             my $field_descr = $field_descrs{$field_name};
1581             my $param_annotations = "";
1583             $desc .= "<varlistentry><term>$text</term>\n";
1584             if (defined $field_descr) {
1585                 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1586                 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1587                 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1588                 delete $field_descrs{$field_name};
1589             } else {
1590                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1591                     "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1592                 if ($missing_parameters ne "") {
1593                   $missing_parameters .= ", ".$field_name;
1594                 } else {
1595                     $missing_parameters = $field_name;
1596                 }
1597                 $desc .= "<listitem />\n";
1598             }
1599             $desc .= "</varlistentry>\n";
1600         }
1601         $desc .= "</variablelist>";
1602         foreach my $field_name (keys %field_descrs) {
1603             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1604                 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1605             if ($unused_parameters ne "") {
1606               $unused_parameters .= ", ".$field_name;
1607             } else {
1608                $unused_parameters = $field_name;
1609             }
1610         }
1612         # remember missing/unused parameters (needed in tmpl-free build)
1613         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1614             $AllIncompleteSymbols{$symbol}=$missing_parameters;
1615         }
1616         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1617             $AllUnusedSymbols{$symbol}=$unused_parameters;
1618         }
1619     }
1620     else {
1621         if (scalar(@fields) > 0) {
1622             if (! exists ($AllIncompleteSymbols{$symbol})) {
1623                 $AllIncompleteSymbols{$symbol}="<items>";
1624                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1625                     "Field descriptions for $symbol are missing in source code comment block.");
1626             }
1627         }
1628     }
1630     $desc .= OutputSymbolTraits ($symbol);
1631     $desc .= "</refsect2>\n";
1632     return ($synop, $desc);
1636 #############################################################################
1637 # Function    : OutputUnion
1638 # Description : Returns the synopsis and detailed description of a union.
1639 # Arguments   : $symbol - the union.
1640 #               $declaration - the declaration of the union.
1641 #############################################################################
1643 sub OutputUnion {
1644     my ($symbol, $declaration) = @_;
1645     my $id = &CreateValidSGMLID ($symbol);
1646     my $condition = &MakeConditionDescription ($symbol);
1648     # Determine if it is a simple struct or it also has a typedef.
1649     my $has_typedef = 0;
1650     if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1651       $has_typedef = 1;
1652     }
1654     my $synop;
1655     my $desc;
1656     if ($has_typedef) {
1657         # For unions with typedefs we just output the union name.
1658         $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1659         $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>$symbol</title>\n";
1660     } else {
1661         $synop = &MakeReturnField("union") . "<link linkend=\"$id\">$symbol</link>;\n";
1662         $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>union $symbol</title>\n";
1663     }
1665     $desc .= MakeIndexterms($symbol, $id);
1666     $desc .= "\n";
1667     $desc .= OutputSymbolExtraLinks($symbol);
1669     # FIXME: we do more for structs
1670     my $decl_out = &CreateValidSGML ($declaration);
1671     $desc .= "<programlisting>$decl_out</programlisting>\n";
1673     $desc .= &MakeDeprecationNote($symbol);
1675     if (defined ($SymbolDocs{$symbol})) {
1676         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1677     }
1679     # Create a table of fields and descriptions
1681     # FIXME: Inserting &#160's into the produced type declarations here would
1682     #        improve the output in most situations ... except for function
1683     #        members of structs!
1684     my @fields = ParseStructDeclaration($declaration, 0,
1685                                         0, \&MakeXRef,
1686                                         sub {
1687                                             "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1688                                         });
1689     my $params = $SymbolParams{$symbol};
1691     # If no parameters are filled in, we don't generate the description
1692     # table, for backwards compatibility
1694     my $found = 0;
1695     if (defined $params) {
1696         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1697             if ($params->[$i] =~ /\S/) {
1698                 $found = 1;
1699                 last;
1700             }
1701         }
1702     }
1704     if ($found) {
1705         my %field_descrs = @$params;
1706         my $missing_parameters = "";
1707         my $unused_parameters = "";
1709         $desc .= "<variablelist role=\"union\">\n";
1710         while (@fields) {
1711             my $field_name = shift @fields;
1712             my $text = shift @fields;
1713             my $field_descr = $field_descrs{$field_name};
1714             my $param_annotations = "";
1716             $desc .= "<varlistentry><term>$text</term>\n";
1717             if (defined $field_descr) {
1718                 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1719                 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1720                 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1721                 delete $field_descrs{$field_name};
1722             } else {
1723                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1724                     "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1725                 if ($missing_parameters ne "") {
1726                     $missing_parameters .= ", ".$field_name;
1727                 } else {
1728                     $missing_parameters = $field_name;
1729                 }
1730                 $desc .= "<listitem />\n";
1731             }
1732             $desc .= "</varlistentry>\n";
1733         }
1734         $desc .= "</variablelist>";
1735         foreach my $field_name (keys %field_descrs) {
1736             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1737                 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1738             if ($unused_parameters ne "") {
1739               $unused_parameters .= ", ".$field_name;
1740             } else {
1741                $unused_parameters = $field_name;
1742             }
1743         }
1745         # remember missing/unused parameters (needed in tmpl-free build)
1746         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1747             $AllIncompleteSymbols{$symbol}=$missing_parameters;
1748         }
1749         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1750             $AllUnusedSymbols{$symbol}=$unused_parameters;
1751         }
1752     }
1753     else {
1754         if (scalar(@fields) > 0) {
1755             if (! exists ($AllIncompleteSymbols{$symbol})) {
1756                 $AllIncompleteSymbols{$symbol}="<items>";
1757                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1758                     "Field descriptions for $symbol are missing in source code comment block.");
1759             }
1760         }
1761     }
1763     $desc .= OutputSymbolTraits ($symbol);
1764     $desc .= "</refsect2>\n";
1765     return ($synop, $desc);
1769 #############################################################################
1770 # Function    : OutputEnum
1771 # Description : Returns the synopsis and detailed description of a enum.
1772 # Arguments   : $symbol - the enum.
1773 #               $declaration - the declaration of the enum.
1774 #############################################################################
1776 sub OutputEnum {
1777     my ($symbol, $declaration) = @_;
1778     my $id = &CreateValidSGMLID ($symbol);
1779     my $condition = &MakeConditionDescription ($symbol);
1780     my $synop = &MakeReturnField("enum") . "<link linkend=\"$id\">$symbol</link>;\n";
1781     my $desc = "<refsect2 id=\"$id\" role=\"enum\"$condition>\n<title>enum $symbol</title>\n";
1783     $desc .= MakeIndexterms($symbol, $id);
1784     $desc .= "\n";
1785     $desc .= OutputSymbolExtraLinks($symbol);
1787     my $decl_out = &CreateValidSGML ($declaration);
1788     $desc .= "<programlisting>$decl_out</programlisting>\n";
1790     $desc .= &MakeDeprecationNote($symbol);
1792     if (defined ($SymbolDocs{$symbol})) {
1793         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1794     }
1796     # Create a table of fields and descriptions
1798     my @fields = ParseEnumDeclaration($declaration);
1799     my $params = $SymbolParams{$symbol};
1801     # If no parameters are filled in, we don't generate the description
1802     # table, for backwards compatibility
1804     my $found = 0;
1805     if (defined $params) {
1806         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1807             if ($params->[$i] =~ /\S/) {
1808                 $found = 1;
1809                 last;
1810             }
1811         }
1812     }
1814     if ($found) {
1815         my %field_descrs = @$params;
1816         my $missing_parameters = "";
1817         my $unused_parameters = "";
1819         $desc .= "<variablelist role=\"enum\">\n";
1820         for my $field_name (@fields) {
1821             my $field_descr = $field_descrs{$field_name};
1822             my $param_annotations = "";
1824             $id = &CreateValidSGMLID ($field_name);
1825             $condition = &MakeConditionDescription ($field_name);
1826             $desc .= "<varlistentry id=\"$id\" role=\"constant\"$condition>\n<term><literal>$field_name</literal></term>\n";
1827             if (defined $field_descr) {
1828                 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1829                 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1830                 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1831                 delete $field_descrs{$field_name};
1832             } else {
1833                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1834                     "Value description for $symbol"."::"."$field_name is missing in source code comment block.");
1835                 if ($missing_parameters ne "") {
1836                   $missing_parameters .= ", ".$field_name;
1837                 } else {
1838                     $missing_parameters = $field_name;
1839                 }
1840                 $desc .= "<listitem />\n";
1841             }
1842             $desc .= "</varlistentry>\n";
1843         }
1844         $desc .= "</variablelist>";
1845         foreach my $field_name (keys %field_descrs) {
1846             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1847                 "Value description for $symbol"."::"."$field_name is not used from source code comment block.");
1848             if ($unused_parameters ne "") {
1849               $unused_parameters .= ", ".$field_name;
1850             } else {
1851                $unused_parameters = $field_name;
1852             }
1853         }
1855         # remember missing/unused parameters (needed in tmpl-free build)
1856         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1857             $AllIncompleteSymbols{$symbol}=$missing_parameters;
1858         }
1859         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1860             $AllUnusedSymbols{$symbol}=$unused_parameters;
1861         }
1862     }
1863     else {
1864         if (scalar(@fields) > 0) {
1865             if (! exists ($AllIncompleteSymbols{$symbol})) {
1866                 $AllIncompleteSymbols{$symbol}="<items>";
1867                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1868                     "Value descriptions for $symbol are missing in source code comment block.");
1869             }
1870         }
1871     }
1873     $desc .= OutputSymbolTraits ($symbol);
1874     $desc .= "</refsect2>\n";
1875     return ($synop, $desc);
1879 #############################################################################
1880 # Function    : OutputVariable
1881 # Description : Returns the synopsis and detailed description of a variable.
1882 # Arguments   : $symbol - the extern'ed variable.
1883 #               $declaration - the declaration of the variable.
1884 #############################################################################
1886 sub OutputVariable {
1887     my ($symbol, $declaration) = @_;
1888     my $id = &CreateValidSGMLID ($symbol);
1889     my $condition = &MakeConditionDescription ($symbol);
1891     my $synop;
1892     if ($declaration =~ m/^\s*extern\s+((const\s+|signed\s+|unsigned\s+)*\w+)(\s+\*+|\*+|\s)(\s*)([A-Za-z]\w*)\s*;/) {
1893         my $mod = defined ($1) ? $1 : "";
1894         my $ptr = defined ($3) ? $3 : "";
1895         my $space = defined ($4) ? $4 : "";
1896         $synop = &MakeReturnField("extern") . "$mod$ptr$space<link linkend=\"$id\">$symbol</link>;\n";
1898     } else {
1899         $synop = &MakeReturnField("extern") . "<link linkend=\"$id\">$symbol</link>;\n";
1900     }
1902     my $desc = "<refsect2 id=\"$id\" role=\"variable\"$condition>\n<title>$symbol</title>\n";
1904     $desc .= MakeIndexterms($symbol, $id);
1905     $desc .= "\n";
1906     $desc .= OutputSymbolExtraLinks($symbol);
1908     my $decl_out = &CreateValidSGML ($declaration);
1909     $desc .= "<programlisting>$decl_out</programlisting>\n";
1911     $desc .= &MakeDeprecationNote($symbol);
1913     if (defined ($SymbolDocs{$symbol})) {
1914         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1915     }
1916     $desc .= OutputSymbolTraits ($symbol);
1917     $desc .= "</refsect2>\n";
1918     return ($synop, $desc);
1922 #############################################################################
1923 # Function    : OutputFunction
1924 # Description : Returns the synopsis and detailed description of a function.
1925 # Arguments   : $symbol - the function.
1926 #               $declaration - the declaration of the function.
1927 #############################################################################
1929 sub OutputFunction {
1930     my ($symbol, $declaration, $symbol_type) = @_;
1931     my $id = &CreateValidSGMLID ($symbol);
1932     my $condition = &MakeConditionDescription ($symbol);
1934     # Take out the return type     $1                                                                                     $3   $4
1935     $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//;
1936     my $type_modifier = defined($1) ? $1 : "";
1937     my $type = $3;
1938     my $pointer = $4;
1939     #print "$symbol pointer is $pointer\n";
1940     my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1941     my $start = "";
1942     #if ($symbol_type eq 'USER_FUNCTION') {
1943     #    $start = "typedef ";
1944     #}
1946     # We output const rather than G_CONST_RETURN.
1947     $type_modifier =~ s/G_CONST_RETURN/const/g;
1948     $pointer =~ s/G_CONST_RETURN/const/g;
1949     $pointer =~ s/^\s+/ /g;
1951     my $ret_type_len = length ($start) + length ($type_modifier)
1952         + length ($pointer) + length ($type);
1953     my $ret_type_output;
1954     my $symbol_len;
1955     if ($ret_type_len < $RETURN_TYPE_FIELD_WIDTH) {
1956         $ret_type_output = "$start$type_modifier$xref$pointer"
1957             . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
1958         $symbol_len = 0;
1959     } else {
1960         #$ret_type_output = "$start$type_modifier$xref$pointer\n" . (' ' x $RETURN_TYPE_FIELD_WIDTH);
1962         $ret_type_output = "$start$type_modifier$xref$pointer ";
1963         $symbol_len = $ret_type_len + 1 - $RETURN_TYPE_FIELD_WIDTH;
1964     }
1966     $symbol_len += length ($symbol);
1967     my $char1 = my $char2 = my $char3 = "";
1968     if ($symbol_type eq 'USER_FUNCTION') {
1969         $symbol_len += 3;
1970         $char1 = "(";
1971         $char2 = "*";
1972         $char3 = ")";
1973     }
1975     my ($symbol_output, $symbol_desc_output);
1976     if ($symbol_len < $SYMBOL_FIELD_WIDTH) {
1977         $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3"
1978             . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1979         $symbol_desc_output = "$char1$char2$symbol$char3"
1980             . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1981     } else {
1982         $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3\n"
1983             . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1984         $symbol_desc_output = "$char1$char2$symbol$char3\n"
1985             . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1986     }
1988     my $synop = $ret_type_output . $symbol_output . '(';
1989     my $desc = "<refsect2 id=\"$id\" role=\"function\"$condition>\n<title>${symbol} ()</title>\n";
1991     $desc .= MakeIndexterms($symbol, $id);
1992     $desc .= "\n";
1993     $desc .= OutputSymbolExtraLinks($symbol);
1995     $desc  .= "<programlisting>${ret_type_output}$symbol_desc_output(";
1996     
1997     my @fields = ParseFunctionDeclaration($declaration, \&MakeXRef,
1998                                         sub {
1999                                             &tagify($_[0],"parameter");
2000                                         });
2001     
2002     for (my $i = 1; $i <= $#fields; $i += 2) {
2003         my $field_name = $fields[$i];
2004         
2005         if ($field_name eq "Varargs") {
2006             $field_name = "...";
2007         }
2009         if ($i == 1) {
2010             $synop .= "$field_name";
2011             $desc  .= "$field_name";
2012         } else {
2013             $synop .= ",\n"
2014                 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2015                 . " $field_name";
2016             $desc  .= ",\n"
2017                 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2018                 . " $field_name";
2019         }
2020         
2021     }
2023     $synop .= ");\n";
2024     $desc  .= ");</programlisting>\n";
2026     $desc .= &MakeDeprecationNote($symbol);
2028     my $parameters = &OutputParamDescriptions ("FUNCTION", $symbol, @fields);
2029     my $parameters_output = 0;
2031     if (defined ($SymbolDocs{$symbol})) {
2032         my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
2034         # Try to insert the parameter table at the author's desired position.
2035         # Otherwise we need to tag it onto the end.
2036         # FIXME: document that in the user manual and make it useable for other
2037         # types too
2038         if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
2039           $parameters_output = 1;
2040         }
2041         $desc .= $symbol_docs;
2042     }
2044     if ($parameters_output == 0) {
2045         $desc .= $parameters;
2046     }
2048     $desc .= OutputSymbolTraits ($symbol);
2049     $desc .= "</refsect2>\n";
2050     return ($synop, $desc);
2054 #############################################################################
2055 # Function    : OutputParamDescriptions
2056 # Description : Returns the DocBook output describing the parameters of a
2057 #               function, macro or signal handler.
2058 # Arguments   : $symbol_type - 'FUNCTION', 'MACRO' or 'SIGNAL'. Signal
2059 #                 handlers have an implicit user_data parameter last.
2060 #               $symbol - the name of the function/macro being described.
2061 #               @fields - parsed fields from the declaration, used to determine
2062 #                  undocumented/unused entries
2063 #############################################################################
2065 sub OutputParamDescriptions {
2066     my ($symbol_type, $symbol, @fields) = @_;
2067     my $output = "";
2068     my $params = $SymbolParams{$symbol};
2069     my $num_params = 0;
2070     my %field_descrs = ();
2072     if (@fields) {
2073         %field_descrs = @fields;
2074         delete $field_descrs{"void"};
2075         delete $field_descrs{"Returns"};
2076     }
2078     if (defined $params) {
2079         my $returns = "";
2080         my $params_desc = "";
2081         my $missing_parameters = "";
2082         my $unused_parameters = "";
2083         my $j;
2085         for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
2086             my $param_name = $$params[$j];
2087             my $param_desc = $$params[$j + 1];
2088             my $param_annotations = "";
2089             
2090             ($param_desc,$param_annotations) = & ExpandAnnotation($symbol, $param_desc);
2091             $param_desc = &ExpandAbbreviations($symbol, $param_desc);
2092             $param_desc .= $param_annotations;
2093             if ($param_name eq "Returns") {
2094                 $returns = "$param_desc";
2095             } elsif ($param_name eq "void") {
2096                 #print "!!!! void in params for $symbol?\n";
2097             } else {
2098                 if (@fields) {
2099                     if (!defined $field_descrs{$param_name}) {
2100                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2101                             "Parameter description for $symbol"."::"."$param_name is not used from source code comment block.");
2102                         if ($unused_parameters ne "") {
2103                           $unused_parameters .= ", ".$param_name;
2104                         } else {
2105                            $unused_parameters = $param_name;
2106                         }
2107                     } else {
2108                         delete $field_descrs{$param_name};
2109                     }
2110                 }
2111                 if ($param_name eq "Varargs") {
2112                     $param_name = "...";
2113                 }
2114                 if($param_desc ne "") {
2115                     $params_desc .= "<varlistentry><term><parameter>$param_name</parameter>&#160;:</term>\n<listitem><simpara>$param_desc</simpara></listitem></varlistentry>\n";
2116                     $num_params++;
2117                 }
2118             }
2119         }
2120         foreach my $param_name (keys %field_descrs) {
2121             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2122                 "Parameter description for $symbol"."::"."$param_name is missing in source code comment block.");
2123             if ($missing_parameters ne "") {
2124               $missing_parameters .= ", ".$param_name;
2125             } else {
2126                $missing_parameters = $param_name;
2127             }
2128         }
2130         # Signals have an implicit user_data parameter which we describe.
2131         if ($symbol_type eq "SIGNAL") {
2132             $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";
2133         }
2135         # Start a table if we need one.
2136         if ($params_desc || $returns) {
2137             $output .= "<variablelist role=\"params\">\n";
2138             if ($params_desc ne "") {
2139                 #$output .= "<varlistentry><term>Parameters:</term><listitem></listitem></varlistentry>\n";
2140                 $output .= $params_desc;
2141             }
2143             # Output the returns info last.
2144             if ($returns) {
2145                 $output .= "<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara>$returns</simpara></listitem></varlistentry>\n";
2146             }
2148             # Finish the table.
2149             $output .= "</variablelist>";
2150         }
2152         # remember missing/unused parameters (needed in tmpl-free build)
2153         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
2154             $AllIncompleteSymbols{$symbol}=$missing_parameters;
2155         }
2156         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
2157             $AllUnusedSymbols{$symbol}=$unused_parameters;
2158         }
2159     }
2160     if (($num_params == 0) && @fields && (scalar(keys(%field_descrs)) > 0)) {
2161         if (! exists ($AllIncompleteSymbols{$symbol})) {
2162             $AllIncompleteSymbols{$symbol}="<parameters>";
2163         }
2164     }
2165     
2166     return $output;
2170 #############################################################################
2171 # Function    : ParseStabilityLevel
2172 # Description : Parses a stability level and outputs a warning if it isn't
2173 #               valid.
2174 # Arguments   : $stability - the stability text.
2175 #               $file, $line - context for error message
2176 #               $message - description of where the level is from, to use in
2177 #               any error message.
2178 # Returns     : The parsed stability level string.
2179 #############################################################################
2181 sub ParseStabilityLevel {
2182     my ($stability, $file, $line, $message) = @_;
2184     $stability =~ s/^\s*//;
2185     $stability =~ s/\s*$//;
2186     if ($stability =~ m/^stable$/i) {
2187         $stability = "Stable";
2188     } elsif ($stability =~ m/^unstable$/i) {
2189         $stability = "Unstable";
2190     } elsif ($stability =~ m/^private$/i) {
2191         $stability = "Private";
2192     } else {
2193         &LogWarning ($file, $line, "$message is $stability.".
2194             "It should be one of these: Stable, Unstable, or Private.");
2195     }
2196     return $stability;
2200 #############################################################################
2201 # Function    : OutputSGMLFile
2202 # Description : Outputs the final DocBook file for one section.
2203 # Arguments   : $file - the name of the file.
2204 #               $title - the title from the $MODULE-sections.txt file, which
2205 #                 will be overridden by the title in the template file.
2206 #               $section_id - the SGML id to use for the toplevel tag.
2207 #               $includes - comma-separates list of include files added at top
2208 #                 of synopsis, with '<' '>' around them (if not already enclosed in "").
2209 #               $synopsis - reference to the DocBook for the Synopsis part.
2210 #               $details - reference to the DocBook for the Details part.
2211 #               $signal_synop - reference to the DocBook for the Signal Synopsis part
2212 #               $signal_desc - reference to the DocBook for the Signal Description part
2213 #               $args_synop - reference to the DocBook for the Arg Synopsis part
2214 #               $args_desc - reference to the DocBook for the Arg Description part
2215 #               $hierarchy - reference to the DocBook for the Object Hierarchy part
2216 #               $interfaces - reference to the DocBook for the Interfaces part
2217 #               $implementations - reference to the DocBook for the Known Implementations part
2218 #               $prerequisites - reference to the DocBook for the Prerequisites part
2219 #               $derived - reference to the DocBook for the Derived Interfaces part
2220 #               $file_objects - reference to an array of objects in this file
2221 #############################################################################
2223 sub OutputSGMLFile {
2224     my ($file, $title, $section_id, $includes, $synopsis, $details, $signals_synop, $signals_desc, $args_synop, $args_desc, $hierarchy, $interfaces, $implementations, $prerequisites, $derived, $file_objects) = @_;
2226     #print "Output sgml for file $file with title '$title'\n";
2227     
2228     # The edited title overrides the one from the sections file.
2229     my $new_title = $SymbolDocs{"$TMPL_DIR/$file:Title"};
2230     if (defined ($new_title) && $new_title !~ m/^\s*$/) {
2231         $title = $new_title;
2232         #print "Found title: $title\n";
2233     }
2234     my $short_desc = $SymbolDocs{"$TMPL_DIR/$file:Short_Description"};
2235     if (!defined ($short_desc) || $short_desc =~ m/^\s*$/) {
2236         $short_desc = "";
2237     } else {
2238         $short_desc = &ExpandAbbreviations("$title:Short_description",
2239                                            $short_desc);
2240         #print "Found short_desc: $short_desc";
2241     }
2242     my $long_desc = $SymbolDocs{"$TMPL_DIR/$file:Long_Description"};
2243     if (!defined ($long_desc) || $long_desc =~ m/^\s*$/) {
2244         $long_desc = "";
2245     } else {
2246         $long_desc = &ExpandAbbreviations("$title:Long_description",
2247                                           $long_desc);
2248         #print "Found long_desc: $long_desc";
2249     }
2250     my $see_also = $SymbolDocs{"$TMPL_DIR/$file:See_Also"};
2251     if (!defined ($see_also) || $see_also =~ m%^\s*(<para>)?\s*(</para>)?\s*$%) {
2252         $see_also = "";
2253     } else {
2254         $see_also = &ExpandAbbreviations("$title:See_Also", $see_also);
2255         #print "Found see_also: $see_also";
2256     }
2257     if ($see_also) {
2258         $see_also = "<refsect1 id=\"$section_id.see-also\">\n<title>See Also</title>\n$see_also\n</refsect1>\n";
2259     }
2260     my $stability = $SymbolDocs{"$TMPL_DIR/$file:Stability_Level"};
2261     if (!defined ($stability) || $stability =~ m/^\s*$/) {
2262         $stability = "";
2263     } else {
2264         $stability = &ParseStabilityLevel($stability, $file, $., "Section stability level");
2265         #print "Found stability: $stability";
2266     }
2267     if ($stability) {
2268         $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$stability, unless otherwise indicated\n</refsect1>\n";
2269     } elsif ($DEFAULT_STABILITY) {
2270         $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$DEFAULT_STABILITY, unless otherwise indicated\n</refsect1>\n";
2271     }
2273     my $image = $SymbolDocs{"$TMPL_DIR/$file:Image"};
2274     if (!defined ($image) || $image =~ m/^\s*$/) {
2275       $image = "";
2276     } else {
2277       $image =~ s/^\s*//;
2278       $image =~ s/\s*$//;
2280       my $format;
2282       if ($image =~ /jpe?g$/i) {
2283         $format = "format='JPEG'";
2284       } elsif ($image =~ /png$/i) {
2285         $format = "format='PNG'";
2286       } elsif ($image =~ /svg$/i) {
2287         $format = "format='SVG'";
2288       } else {
2289         $format = "";
2290       }
2292       $image = "  <inlinegraphic fileref='$image' $format/>\n"
2293     }
2295     my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
2296         gmtime (time);
2297     my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
2298     $year += 1900;
2300     my $include_output = "";
2301     my $include;
2302     foreach $include (split (/,/, $includes)) {
2303         if ($include =~ m/^\".+\"$/) {
2304             $include_output .= "#include ${include}\n";
2305         }
2306         else {
2307             $include =~ s/^\s+|\s+$//gs;
2308             $include_output .= "#include &lt;${include}&gt;\n";
2309         }
2310     }
2311     if ($include_output ne '') {
2312         $include_output = "\n$include_output\n";
2313     }
2314     
2315     my $extralinks = OutputSectionExtraLinks($title,"Section:$file");
2317     my $old_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT";
2318     my $new_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT.new";
2320     open (OUTPUT, ">$new_sgml_file")
2321         || die "Can't create $new_sgml_file: $!";
2323     my $object_anchors = "";
2324     foreach my $object (@$file_objects) {
2325         next if ($object eq $section_id);
2326         my $id = CreateValidSGMLID($object);
2327         #print "Debug: Adding anchor for $object\n";
2328         $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
2329     }
2331     # We used to output this, but is messes up our UpdateFileIfChanged code
2332     # since it changes every day (and it is only used in the man pages):
2333     # "<refentry id="$section_id" revision="$mday $month $year">"
2335     if ($OUTPUT_FORMAT eq "xml") {
2336         print OUTPUT $doctype_header;
2337     }
2339     print OUTPUT <<EOF;
2340 <refentry id="$section_id">
2341 <refmeta>
2342 <refentrytitle role="top_of_page" id="$section_id.top_of_page">$title</refentrytitle>
2343 <manvolnum>3</manvolnum>
2344 <refmiscinfo>
2345   \U$MODULE\E Library
2346 $image</refmiscinfo>
2347 </refmeta>
2348 <refnamediv>
2349 <refname>$title</refname>
2350 <refpurpose>$short_desc</refpurpose>
2351 </refnamediv>
2352 $stability
2353 <refsynopsisdiv id="$section_id.synopsis" role="synopsis">
2354 <title role="synopsis.title">Synopsis</title>
2355 $object_anchors
2356 <synopsis>$include_output$${synopsis}</synopsis>
2357 </refsynopsisdiv>
2358 $$hierarchy$$prerequisites$$derived$$interfaces$$implementations$$args_synop$$signals_synop
2359 <refsect1 id="$section_id.description" role="desc">
2360 <title role="desc.title">Description</title>
2361 $extralinks$long_desc
2362 </refsect1>
2363 <refsect1 id="$section_id.details" role="details">
2364 <title role="details.title">Details</title>
2365 $$details
2366 </refsect1>
2367 $$args_desc$$signals_desc$see_also
2368 </refentry>
2370     close (OUTPUT);
2372     return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2376 #############################################################################
2377 # Function    : OutputExtraFile
2378 # Description : Copies an "extra" DocBook file into the output directory,
2379 #               expanding abbreviations
2380 # Arguments   : $file - the source file.
2381 #############################################################################
2382 sub OutputExtraFile {
2383     my ($file) = @_;
2385     my $basename;
2387     ($basename = $file) =~ s!^.*/!!;
2389     my $old_sgml_file = "$SGML_OUTPUT_DIR/$basename";
2390     my $new_sgml_file = "$SGML_OUTPUT_DIR/$basename.new";
2392     my $contents;
2394     open(EXTRA_FILE, "<$file") || die "Can't open $file";
2396     {
2397         local $/;
2398         $contents = <EXTRA_FILE>;
2399     }
2401     open (OUTPUT, ">$new_sgml_file")
2402         || die "Can't create $new_sgml_file: $!";
2404     print OUTPUT &ExpandAbbreviations ("$basename file", $contents);
2405     close (OUTPUT);
2407     return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2409 #############################################################################
2410 # Function    : OutputBook
2411 # Description : Outputs the SGML entities that need to be included into the
2412 #               main SGML file for the module.
2413 # Arguments   : $book_top - the declarations of the entities, which are added
2414 #                 at the top of the main SGML file.
2415 #               $book_bottom - the references to the entities, which are
2416 #                 added in the main SGML file at the desired position.
2417 #############################################################################
2419 sub OutputBook {
2420     my ($book_top, $book_bottom) = @_;
2422     my $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top";
2423     my $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top.new";
2425     open (OUTPUT, ">$new_file")
2426         || die "Can't create $new_file: $!";
2427     print OUTPUT $book_top;
2428     close (OUTPUT);
2430     &UpdateFileIfChanged ($old_file, $new_file, 0);
2433     $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom";
2434     $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom.new";
2436     open (OUTPUT, ">$new_file")
2437         || die "Can't create $new_file: $!";
2438     print OUTPUT $book_bottom;
2439     close (OUTPUT);
2441     &UpdateFileIfChanged ($old_file, $new_file, 0);
2444     # If the main SGML/XML file hasn't been created yet, we create it here.
2445     # The user can tweak it later.
2446     if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
2447       open (OUTPUT, ">$MAIN_SGML_FILE")
2448         || die "Can't create $MAIN_SGML_FILE: $!";
2450       if ($OUTPUT_FORMAT eq "xml") {
2451           print OUTPUT <<EOF;
2452 <?xml version="1.0"?>
2453 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
2454                "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
2456   <!ENTITY % local.common.attrib "xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'">
2458 <book id="index">
2460       } else {
2461         print OUTPUT <<EOF;
2462 <!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
2463 $book_top
2465 <book id="index">
2467       }
2469 print OUTPUT <<EOF;
2470   <bookinfo>
2471     <title>$MODULE Reference Manual</title>
2472     <releaseinfo>
2473       for $MODULE [VERSION].
2474       The latest version of this documentation can be found on-line at
2475       <ulink role="online-location" url="http://[SERVER]/$MODULE/index.html">http://[SERVER]/$MODULE/</ulink>.
2476     </releaseinfo>
2477   </bookinfo>
2479   <chapter>
2480     <title>[Insert title here]</title>
2481     $book_bottom
2482   </chapter>
2484   if (-e $OBJECT_TREE_FILE) {
2485     print OUTPUT <<EOF;
2486   <chapter id="object-tree">
2487     <title>Object Hierarchy</title>
2488      <xi:include href="xml/tree_index.sgml"/>
2489   </chapter>
2491   }
2493 print OUTPUT <<EOF;
2494   <index id="api-index-full">
2495     <title>API Index</title>
2496     <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
2497   </index>
2499   <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
2500 </book>
2503       close (OUTPUT);
2504     }
2508 #############################################################################
2509 # Function    : CreateValidSGML
2510 # Description : This turns any chars which are used in SGML into entities,
2511 #               e.g. '<' into '&lt;'
2512 # Arguments   : $text - the text to turn into proper SGML.
2513 #############################################################################
2515 sub CreateValidSGML {
2516     my ($text) = @_;
2517     $text =~ s/&/&amp;/g;       # Do this first, or the others get messed up.
2518     $text =~ s/</&lt;/g;
2519     $text =~ s/>/&gt;/g;
2520     # browers render single tabs inconsistently
2521     $text =~ s/([^\s])\t([^\s])/$1&#160;$2/g;
2522     return $text;
2525 #############################################################################
2526 # Function    : ConvertSGMLChars
2527 # Description : This is used for text in source code comment blocks, to turn
2528 #               chars which are used in SGML into entities, e.g. '<' into
2529 #               '&lt;'. Depending on $SGML_MODE, this is done
2530 #               unconditionally or only if the character doesn't seem to be
2531 #               part of an SGML construct (tag or entity reference).
2532 # Arguments   : $text - the text to turn into proper SGML.
2533 #############################################################################
2535 sub ConvertSGMLChars {
2536     my ($symbol, $text) = @_;
2538     if ($SGML_MODE) {
2539         # For the SGML mode only convert to entities outside CDATA sections.
2540         return &ModifyXMLElements ($text, $symbol,
2541                                    "<!\\[CDATA\\[|<programlisting[^>]*>",
2542                                    \&ConvertSGMLCharsEndTag,
2543                                    \&ConvertSGMLCharsCallback);
2544     } else {
2545         # For the simple non-sgml mode, convert to entities everywhere.
2546         $text =~ s/&/&amp;/g;   # Do this first, or the others get messed up.
2547         $text =~ s/</&lt;/g;
2548         $text =~ s/>/&gt;/g;
2549         return $text;
2550     }
2554 sub ConvertSGMLCharsEndTag {
2555   if ($_[0] eq "<!\[CDATA\[") {
2556     return "]]>";
2557   } else {
2558     return "</programlisting>";
2559   }
2562 sub ConvertSGMLCharsCallback {
2563   my ($text, $symbol, $tag) = @_;
2565   if ($tag =~ m/^<programlisting/) {
2566     # We can handle <programlisting> specially here.
2567     return &ModifyXMLElements ($text, $symbol,
2568                                "<!\\[CDATA\\[",
2569                                \&ConvertSGMLCharsEndTag,
2570                                \&ConvertSGMLCharsCallback2);
2571   } elsif ($tag eq "") {
2572     # If we're not in CDATA convert to entities.
2573     $text =~ s/&(?![a-zA-Z#]+;)/&amp;/g;        # Do this first, or the others get messed up.
2574     $text =~ s/<(?![a-zA-Z\/!])/&lt;/g;
2575     $text =~ s/(?<![a-zA-Z0-9"'\/-])>/&gt;/g;
2577     # Handle "#include <xxxxx>"
2578     $text =~ s/#include(\s+)<([^>]+)>/#include$1&lt;$2&gt;/g;
2579   }
2581   return $text;
2584 sub ConvertSGMLCharsCallback2 {
2585   my ($text, $symbol, $tag) = @_;
2587   # If we're not in CDATA convert to entities.
2588   # We could handle <programlisting> differently, though I'm not sure it helps.
2589   if ($tag eq "") {
2590     # replace only if its not a tag
2591     $text =~ s/&(?![a-zA-Z#]+;)/&amp;/g;        # Do this first, or the others get messed up.
2592     $text =~ s/<(?![a-zA-Z\/!])/&lt;/g;
2593     $text =~ s/(?<![a-zA-Z0-9"'\/-])>/&gt;/g;
2595     # Handle "#include <xxxxx>"
2596     $text =~ s/#include(\s+)<([^>]+)>/#include$1&lt;$2&gt;/g;
2597   }
2599   return $text;
2602 #############################################################################
2603 # Function    : ExpandAnnotation
2604 # Description : This turns annotations into acronym tags.
2605 # Arguments   : $symbol - the symbol being documented, for error messages.
2606 #               $text - the text to expand.
2607 #############################################################################
2608 sub ExpandAnnotation {
2609     my ($symbol, $param_desc) = @_;
2610     my $param_annotations = "";
2612     # look for annotations at the start of the comment
2613     if ($param_desc =~ m%^\s*\(([^)]*)\):%) {
2614         my @annotations;
2615         my $annotation;
2616         my $annotation_extra = "";
2617         $param_desc = $';
2618     
2619         @annotations = split(/\)\s*\(/,$1);
2620         foreach $annotation (@annotations) {
2621             # need to search for the longest key-match in %AnnotationDefinition
2622             my $match_length=0;
2623             my $match_annotation="";
2624             my $annotationdef;
2625             foreach $annotationdef (keys %AnnotationDefinition) {
2626                 if ($annotation =~ m/^$annotationdef/) {
2627                     if (length($annotationdef)>$match_length) {
2628                         $match_length=length($annotationdef);
2629                         $match_annotation=$annotationdef;
2630                     }
2631                 }
2632             }
2633             if ($match_annotation ne "") {
2634                 if ($annotation =~ m%$match_annotation\s+(.*)%) {
2635                     $annotation_extra = " $1";
2636                 }
2637                 $AnnotationsUsed{$match_annotation} = 1;
2638                 $param_annotations .= "[<acronym>$match_annotation</acronym>$annotation_extra]";
2639             }
2640             else {
2641                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2642                     "unknown annotation \"$annotation\" in documentation for $symbol.");
2643                 $param_annotations .= "[$annotation]";
2644             }
2645         }
2646         chomp($param_desc);
2647         $param_desc =~ m/^(.*?)\.*\s*$/s;
2648         $param_desc = "$1. ";
2649     }
2650     if ($param_annotations ne "") {
2651         $param_annotations = "<emphasis role=\"annotation\">$param_annotations</emphasis>";
2652     }
2653     return ($param_desc, $param_annotations);
2656 #############################################################################
2657 # Function    : ExpandAbbreviations
2658 # Description : This turns the abbreviations function(), macro(), @param,
2659 #               %constant, and #symbol into appropriate DocBook markup.
2660 #               CDATA sections and <programlisting> parts are skipped.
2661 # Arguments   : $symbol - the symbol being documented, for error messages.
2662 #               $text - the text to expand.
2663 #############################################################################
2665 sub ExpandAbbreviations {
2666   my ($symbol, $text) = @_;
2668   # Convert "|[" and "]|" into the start and end of program listing examples.
2669   # FIXME: we like to have a way to specify parameters e.g. language="c"
2670   $text =~ s%\|\[%<informalexample><programlisting>%g;
2671   $text =~ s%\]\|%</programlisting></informalexample>%g;
2672   # TODO: check for a xml comment after |[ and pick the language attribute from
2673   # that
2675   # keep CDATA unmodified, preserve ulink tags (ideally we preseve all tags
2676   # as such)
2677   return &ModifyXMLElements ($text, $symbol,
2678                              "<!\\[CDATA\\[|<ulink[^>]*>|<programlisting[^>]*>|<!DOCTYPE",
2679                              \&ExpandAbbreviationsEndTag,
2680                              \&ExpandAbbreviationsCallback);
2684 # Returns the end tag corresponding to the given start tag.
2685 sub ExpandAbbreviationsEndTag {
2686   my ($start_tag) = @_;
2688   if ($start_tag eq "<!\[CDATA\[") {
2689     return "]]>";
2690   } elsif ($start_tag eq "<!DOCTYPE") {
2691     return "]>";
2692   } elsif ($start_tag =~ m/<(\w+)/) {
2693     return "</$1>";
2694   }
2697 # Called inside or outside each CDATA or <programlisting> section.
2698 sub ExpandAbbreviationsCallback {
2699   my ($text, $symbol, $tag) = @_;
2701   if ($tag =~ m/^<programlisting/) {
2702     # Handle any embedded CDATA sections.
2703     return &ModifyXMLElements ($text, $symbol,
2704                                "<!\\[CDATA\\[",
2705                                \&ExpandAbbreviationsEndTag,
2706                                \&ExpandAbbreviationsCallback2);
2707   } elsif ($tag eq "") {
2708     # We are outside any CDATA or <programlisting> sections, so we expand
2709     # any gtk-doc abbreviations.
2711     # Convert 'function()' or 'macro()'.
2712     # if there is abc_*_def() we don't want to make a link to _def()
2713     # FIXME: also handle abc(....) : but that would need to be done recursively :/
2714     $text =~ s/([^\*.\w])(\w+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2715     # handle #Object.func()
2716     $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2718     # Convert '@param', but not '\@param'.
2719     $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)/$1<parameter>$2<\/parameter>/g;
2720     $text =~ s/\\\@/\@/g;
2722     # Convert '%constant', but not '\%constant'.
2723     # Also allow negative numbers, e.g. %-1.
2724     $text =~ s/(\A|[^\\])\%(-?\w+)/$1.&MakeXRef($2, &tagify($2, "literal"));/eg;
2725     $text =~ s/\\\%/\%/g;
2727     # Convert '#symbol', but not '\#symbol'.
2728     $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)/$1.&MakeHashXRef($2, "type");/eg;
2729     $text =~ s/\\#/#/g;
2730     
2731     # Expand urls
2732     # FIXME: should we skip urls that are already tagged? (e.g. <literal>http://...</literal>)
2733     # this is apparently also called for markup and not just for plain text
2734     # disable for now.
2735     #$text =~ s%(http|https|ftp)://(.*?)((?:\s|,|\)|\]|\<|\.\s))%<ulink url="$1://$2">$2</ulink>$3%g;
2737     # TODO: optionally check all words from $text against internal symbols and
2738     # warn if those could be xreffed, but miss a %,# or ()
2739   }
2741   return $text;
2744 # This is called inside a <programlisting>
2745 sub ExpandAbbreviationsCallback2 {
2746   my ($text, $symbol, $tag) = @_;
2748   if ($tag eq "") {
2749     # We are inside a <programlisting> but outside any CDATA sections,
2750     # so we expand any gtk-doc abbreviations.
2751     # FIXME: why is this different from &ExpandAbbreviationsCallback(),
2752     #        why not just call it
2753     $text =~ s/#(\w+)/&MakeHashXRef($1, "");/eg;
2754   }
2756   return $text;
2759 sub MakeHashXRef {
2760     my ($symbol, $tag) = @_;;
2761     my $text = $symbol;
2763     # Check for things like '#include', '#define', and skip them.
2764     if ($PreProcessorDirectives{$symbol}) {
2765       return "#$symbol";
2766     }
2768     # Get rid of any special '-struct' suffix.
2769     $text =~ s/-struct$//;
2771     # If the symbol is in the form "Object::signal", then change the symbol to
2772     # "Object-signal" and use "signal" as the text.
2773     if ($symbol =~ s/::/-/) {
2774       $text = "\"$'\"";
2775     }
2777     # If the symbol is in the form "Object:property", then change the symbol to
2778     # "Object--property" and use "property" as the text.
2779     if ($symbol =~ s/:/--/) {
2780       $text = "\"$'\"";
2781     }
2783     if ($tag ne "") {
2784       $text = tagify ($text, $tag);
2785     }
2786     
2787     return &MakeXRef($symbol, $text);
2791 #############################################################################
2792 # Function    : ModifyXMLElements
2793 # Description : Looks for given XML element tags within the text, and calls
2794 #               the callback on pieces of text inside & outside those elements.
2795 #               Used for special handling of text inside things like CDATA
2796 #               and <programlisting>.
2797 # Arguments   : $text - the text.
2798 #               $symbol - the symbol currently being documented (only used for
2799 #                      error messages).
2800 #               $start_tag_regexp - the regular expression to match start tags.
2801 #                      e.g. "<!\\[CDATA\\[|<programlisting[^>]*>" to match
2802 #                      CDATA sections or programlisting elements.
2803 #               $end_tag_func - function which is passed the matched start tag
2804 #                      and should return the appropriate end tag string.
2805 #               $callback - callback called with each part of the text. It is
2806 #                      called with a piece of text, the symbol being
2807 #                      documented, and the matched start tag or "" if the text
2808 #                      is outside the XML elements being matched.
2809 #############################################################################
2810 sub ModifyXMLElements {
2811     my ($text, $symbol, $start_tag_regexp, $end_tag_func, $callback) = @_;
2812     my ($before_tag, $start_tag, $end_tag_regexp, $end_tag);
2813     my $result = "";
2815     while ($text =~ m/$start_tag_regexp/s) {
2816       $before_tag = $`; # Prematch for last successful match string
2817       $start_tag = $&;  # Last successful match
2818       $text = $';       # Postmatch for last successful match string
2820       $result .= &$callback ($before_tag, $symbol, "");
2821       $result .= $start_tag;
2823       # get the mathing end-tag for current tag
2824       $end_tag_regexp = &$end_tag_func ($start_tag);
2826       if ($text =~ m/$end_tag_regexp/s) {
2827         $before_tag = $`;
2828         $end_tag = $&;
2829         $text = $';
2831         $result .= &$callback ($before_tag, $symbol, $start_tag);
2832         $result .= $end_tag;
2833       } else {
2834         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2835             "Can't find tag end: $end_tag_regexp in docs for: $symbol.");
2836         # Just assume it is all inside the tag.
2837         $result .= &$callback ($text, $symbol, $start_tag);
2838         $text = "";
2839       }
2840     }
2842     # Handle any remaining text outside the tags.
2843     $result .= &$callback ($text, $symbol, "");
2845     return $result;
2848 sub noop {
2849   return $_[0];
2852 # Adds a tag around some text.
2853 # e.g tagify("Text", "literal") => "<literal>Text</literal>".
2854 sub tagify {
2855    my ($text, $elem) = @_;
2856    return "<" . $elem . ">" . $text . "</" . $elem . ">";
2860 #############################################################################
2861 # Function    : MakeXRef
2862 # Description : This returns a cross-reference link to the given symbol.
2863 #               Though it doesn't try to do this for a few standard C types
2864 #               that it knows won't be in the documentation.
2865 # Arguments   : $symbol - the symbol to try to create a XRef to.
2866 #               $text - text text to put inside the XRef, defaults to $symbol
2867 #############################################################################
2869 sub MakeXRef {
2870     my ($symbol, $text) = ($_[0], $_[1]);
2872     $symbol =~ s/^\s+//;
2873     $symbol =~ s/\s+$//;
2875     if (!defined($text)) {
2876         $text = $symbol;
2878         # Get rid of special '-struct' suffix.
2879         $text =~ s/-struct$//;
2880     }
2882     if ($symbol =~ m/ /) {
2883         return "$text";
2884     }
2886     #print "Getting type link for $symbol -> $text\n";
2888     my $symbol_id = &CreateValidSGMLID ($symbol);
2889     return "<link linkend=\"$symbol_id\">$text</link>";
2893 #############################################################################
2894 # Function    : MakeIndexterms
2895 # Description : This returns a indexterm elements for the given symbol
2896 # Arguments   : $symbol - the symbol to create indexterms for
2897 #############################################################################
2899 sub MakeIndexterms {
2900   my ($symbol, $id) = @_;
2901   my $terms =  "";
2902   my $sortas = "";
2903   
2904   # make the index useful, by ommiting the namespace when sorting
2905   if ($NAME_SPACE ne "") {
2906     if ($symbol =~ m/^$NAME_SPACE\_?(.*)/i) {
2907        $sortas=" sortas=\"$1\"";
2908     }
2909   }
2911   if (exists $Deprecated{$symbol}) {
2912       $terms .= "<indexterm zone=\"$id\" role=\"deprecated\"><primary$sortas>$symbol</primary></indexterm>";
2913       $IndexEntriesDeprecated{$symbol}=$id;
2914       $IndexEntriesFull{$symbol}=$id;
2915   }
2916   if (exists $Since{$symbol}) {
2917      my $since = $Since{$symbol};
2918      $since =~ s/^\s+//;
2919      $since =~ s/\s+$//;
2920      if ($since ne "") {
2921          $terms .= "<indexterm zone=\"$id\" role=\"$since\"><primary$sortas>$symbol</primary></indexterm>";
2922      }
2923      $IndexEntriesSince{$symbol}=$id;
2924      $IndexEntriesFull{$symbol}=$id;
2925   }
2926   if ($terms eq "") {
2927      $terms .= "<indexterm zone=\"$id\"><primary$sortas>$symbol</primary></indexterm>";
2928      $IndexEntriesFull{$symbol}=$id;
2929   }
2931   return $terms;
2934 #############################################################################
2935 # Function    : MakeDeprecationNote
2936 # Description : This returns a deprecation warning for the given symbol.
2937 # Arguments   : $symbol - the symbol to try to create a warning for.
2938 #############################################################################
2940 sub MakeDeprecationNote {
2941     my ($symbol) = $_[0];
2942     my $desc = "";
2943     my $note = "";
2944     if (exists $Deprecated{$symbol}) {
2945         $desc .= "<warning>";
2947         if ($Deprecated{$symbol} =~ /^\s*([0-9\.]+)\s*:/) {
2948                 $desc .= "<para><literal>$symbol</literal> has been deprecated since version $1 and should not be used in newly-written code.";
2949         } else {
2950                 $desc .= "<para><literal>$symbol</literal> is deprecated and should not be used in newly-written code.";
2951         }
2952         if ($Deprecated{$symbol} ne "") {
2953             $note = &ExpandAbbreviations($symbol, $Deprecated{$symbol});
2954             $note =~ s/^\s*([0-9\.]+)\s*:\s*//;
2955             $note =~ s/^\s+//;
2956             $note =~ s/\s+$//;
2957             $note =~ s%\n{2,}%\n</para>\n<para>\n%g;
2958             $desc .= " " . $note;
2959         }
2960         $desc .= "</para></warning>\n";
2961     }
2962     return $desc;
2965 #############################################################################
2966 # Function    : MakeConditionDescription
2967 # Description : This returns a sumary of conditions for the given symbol.
2968 # Arguments   : $symbol - the symbol to try to create the sumary.
2969 #############################################################################
2971 sub MakeConditionDescription {
2972     my ($symbol) = $_[0];
2973     my $desc = "";
2975     if (exists $Deprecated{$symbol}) {
2976         if ($desc ne "") {
2977             $desc .= "|";
2978         }
2980         if ($Deprecated{$symbol} =~ /^\s*(.*?)\s*$/) {
2981                 $desc .= "deprecated:$1";
2982         } else {
2983                 $desc .= "deprecated";
2984         }
2985     }
2987     if (exists $Since{$symbol}) {
2988         if ($desc ne "") {
2989             $desc .= "|";
2990         }
2992         if ($Since{$symbol} =~ /^\s*(.*?)\s*$/) {
2993                 $desc .= "since:$1";
2994         } else {
2995                 $desc .= "since";
2996         }
2997     }
2999     if (exists $StabilityLevel{$symbol}) {
3000         if ($desc ne "") {
3001             $desc .= "|";
3002         }
3003         $desc .= "stability:".$StabilityLevel{$symbol};
3004     }
3006     if ($desc ne "") {
3007         $desc=" condition=\"".$desc."\"";
3008         #print "condition for '$symbol' = '$desc'\n";
3009     }
3010     return $desc;
3013 #############################################################################
3014 # Function    : GetHierarchy
3015 # Description : Returns the DocBook output describing the ancestors and
3016 #               immediate children of a GObject subclass. It uses the
3017 #               global @Objects and @ObjectLevels arrays to walk the tree.
3018 # Arguments   : $object - the GtkObject subclass.
3019 #############################################################################
3021 sub GetHierarchy {
3022     my ($object) = @_;
3024     # Find object in the objects array.
3025     my $found = 0;
3026     my @children = ();
3027     my $i;
3028     my $level;
3029     my $j;
3030     for ($i = 0; $i < @Objects; $i++) {
3031         if ($found) {
3032             if ($ObjectLevels[$i] <= $level) {
3033             last;
3034         }
3035             elsif ($ObjectLevels[$i] == $level + 1) {
3036                 push (@children, $Objects[$i]);
3037             }
3038         }
3039         elsif ($Objects[$i] eq $object) {
3040             $found = 1;
3041             $j = $i;
3042             $level = $ObjectLevels[$i];
3043         }
3044     }
3045     if (!$found) {
3046         return "";
3047     }
3049     # Walk up the hierarchy, pushing ancestors onto the ancestors array.
3050     my @ancestors = ();
3051     push (@ancestors, $object);
3052     #print "Level: $level\n";
3053     while ($level > 1) {
3054         $j--;
3055         if ($ObjectLevels[$j] < $level) {
3056             push (@ancestors, $Objects[$j]);
3057             $level = $ObjectLevels[$j];
3058             #print "Level: $level\n";
3059         }
3060     }
3062     # Output the ancestors list, indented and with links.
3063     my $hierarchy = "<synopsis>\n";
3064     $level = 0;
3065     for ($i = $#ancestors; $i >= 0; $i--) {
3066         my $link_text;
3067         # Don't add a link to the current object, i.e. when i == 0.
3068         if ($i > 0) {
3069             my $ancestor_id = &CreateValidSGMLID ($ancestors[$i]);
3070             $link_text = "<link linkend=\"$ancestor_id\">$ancestors[$i]</link>";
3071         } else {
3072             $link_text = "$ancestors[$i]";
3073         }
3074         if ($level == 0) {
3075             $hierarchy .= "  $link_text\n";
3076         } else {
3077 #           $hierarchy .= ' ' x ($level * 6 - 3) . "|\n";
3078             $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3079         }
3080         $level++;
3081     }
3082     for ($i = 0; $i <= $#children; $i++) {
3083       my $id = &CreateValidSGMLID ($children[$i]);
3084       my $link_text = "<link linkend=\"$id\">$children[$i]</link>";
3085       $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3086     }
3087     $hierarchy .= "</synopsis>\n";
3089     return $hierarchy;
3093 #############################################################################
3094 # Function    : GetInterfaces
3095 # Description : Returns the DocBook output describing the interfaces
3096 #               implemented by a class. It uses the global %Interfaces hash.
3097 # Arguments   : $object - the GtkObject subclass.
3098 #############################################################################
3100 sub GetInterfaces {
3101     my ($object) = @_;
3102     my $text = "";
3103     my $i;
3105     # Find object in the objects array.
3106     if (exists($Interfaces{$object})) {
3107         my @ifaces = split(' ', $Interfaces{$object});
3108         $text = <<EOF;
3109 <para>
3110 $object implements
3112         for ($i = 0; $i <= $#ifaces; $i++) {
3113             my $id = &CreateValidSGMLID ($ifaces[$i]);
3114             $text .= " <link linkend=\"$id\">$ifaces[$i]</link>";
3115             if ($i < $#ifaces - 1) {
3116                 $text .= ', ';
3117             }
3118             elsif ($i < $#ifaces) {
3119                 $text .= ' and ';
3120             }
3121             else {
3122                 $text .= '.';
3123             }
3124         }
3125         $text .= <<EOF;
3126 </para>
3128     }
3130     return $text;
3133 #############################################################################
3134 # Function    : GetImplementations
3135 # Description : Returns the DocBook output describing the implementations
3136 #               of an interface. It uses the global %Interfaces hash.
3137 # Arguments   : $object - the GtkObject subclass.
3138 #############################################################################
3140 sub GetImplementations {
3141     my ($object) = @_;
3142     my @impls = ();
3143     my $text = "";
3144     my $i;
3145     foreach my $key (keys %Interfaces) {
3146         if ($Interfaces{$key} =~ /\b$object\b/) {
3147             push (@impls, $key);
3148         }
3149     }
3150     if ($#impls >= 0) {
3151         @impls = sort @impls;
3152         $text = <<EOF;
3153 <para>
3154 $object is implemented by
3156         for ($i = 0; $i <= $#impls; $i++) {
3157             my $id = &CreateValidSGMLID ($impls[$i]);
3158             $text .= " <link linkend=\"$id\">$impls[$i]</link>";
3159             if ($i < $#impls - 1) {
3160                 $text .= ', ';
3161             }
3162             elsif ($i < $#impls) {
3163                 $text .= ' and ';
3164             }
3165             else {
3166                 $text .= '.';
3167             }
3168         }
3169         $text .= <<EOF;
3170 </para>
3172     }
3173     return $text;
3177 #############################################################################
3178 # Function    : GetPrerequisites
3179 # Description : Returns the DocBook output describing the prerequisites
3180 #               of an interface. It uses the global %Prerequisites hash.
3181 # Arguments   : $iface - the interface.
3182 #############################################################################
3184 sub GetPrerequisites {
3185     my ($iface) = @_;
3186     my $text = "";
3187     my $i;
3189     if (exists($Prerequisites{$iface})) {
3190         $text = <<EOF;
3191 <para>
3192 $iface requires
3194         my @prereqs = split(' ', $Prerequisites{$iface});
3195         for ($i = 0; $i <= $#prereqs; $i++) {
3196             my $id = &CreateValidSGMLID ($prereqs[$i]);
3197             $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
3198             if ($i < $#prereqs - 1) {
3199                 $text .= ', ';
3200             }
3201             elsif ($i < $#prereqs) {
3202                 $text .= ' and ';
3203             }
3204             else {
3205                 $text .= '.';
3206             }
3207         }
3208         $text .= <<EOF;
3209 </para>
3211     }
3212     return $text;
3215 #############################################################################
3216 # Function    : GetDerived
3217 # Description : Returns the DocBook output describing the derived interfaces
3218 #               of an interface. It uses the global %Prerequisites hash.
3219 # Arguments   : $iface - the interface.
3220 #############################################################################
3222 sub GetDerived {
3223     my ($iface) = @_;
3224     my $text = "";
3225     my $i;
3227     my @derived = ();
3228     foreach my $key (keys %Prerequisites) {
3229         if ($Prerequisites{$key} =~ /\b$iface\b/) {
3230             push (@derived, $key);
3231         }
3232     }
3233     if ($#derived >= 0) {
3234         @derived = sort @derived;
3235         $text = <<EOF;
3236 <para>
3237 $iface is required by
3239         for ($i = 0; $i <= $#derived; $i++) {
3240             my $id = &CreateValidSGMLID ($derived[$i]);
3241             $text .= " <link linkend=\"$id\">$derived[$i]</link>";
3242             if ($i < $#derived - 1) {
3243                 $text .= ', ';
3244             }
3245             elsif ($i < $#derived) {
3246                 $text .= ' and ';
3247             }
3248             else {
3249                 $text .= '.';
3250             }
3251         }
3252         $text .= <<EOF;
3253 </para>
3255     }
3256     return $text;
3260 #############################################################################
3261 # Function    : GetSignals
3262 # Description : Returns the synopsis and detailed description DocBook output
3263 #               for the signal handlers of a given GtkObject subclass.
3264 # Arguments   : $object - the GtkObject subclass, e.g. 'GtkButton'.
3265 #############################################################################
3267 sub GetSignals {
3268     my ($object) = @_;
3269     my $synop = "";
3270     my $desc = "";
3272     my $i;
3273     for ($i = 0; $i <= $#SignalObjects; $i++) {
3274         if ($SignalObjects[$i] eq $object) {
3275             #print "Found signal: $SignalNames[$i]\n";
3276             my $name = $SignalNames[$i];
3277             my $symbol = "${object}::${name}";
3278             my $id = &CreateValidSGMLID ("$object-$name");
3280             my $pad = ' ' x (46 - length($name));
3281             $synop .= "  &quot;<link linkend=\"$id\">$name</link>&quot;$pad ";
3283             $desc .= "<refsect2 id=\"$id\" role=\"signal\"><title>The <literal>&quot;$name&quot;</literal> signal</title>\n";
3284             $desc .= MakeIndexterms($symbol, $id);
3285             $desc .= "\n";
3286             $desc .= OutputSymbolExtraLinks($symbol);
3288             $desc .= "<programlisting>";
3290             $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
3291             my $type_modifier = defined($1) ? $1 : "";
3292             my $type = $2;
3293             my $pointer = $3;
3294             my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
3296             my $ret_type_len = length ($type_modifier) + length ($pointer)
3297                 + length ($type);
3298             my $ret_type_output = "$type_modifier$xref$pointer"
3299                 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
3301             $desc  .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
3303             my $sourceparams = $SourceSymbolParams{$symbol};
3304             my @params = split ("\n", $SignalPrototypes[$i]);
3305             my $j;
3306             my $l;
3307             my $type_len = length("gpointer");
3308             my $name_len = length("user_data");
3309             # do two passes, the first one is to calculate padding
3310             for ($l = 0; $l < 2; $l++) {
3311                 for ($j = 0; $j <= $#params; $j++) {
3312                     # allow alphanumerics, '_', '[' & ']' in param names
3313                     if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
3314                         $type = $1;
3315                         $pointer = $2;
3316                         if (defined($sourceparams)) {
3317                             $name = $$sourceparams[$PARAM_FIELD_COUNT * $j];
3318                         }
3319                         else {
3320                             $name = $3;
3321                         }
3322                         if (!defined($name)) {
3323                             $name = "arg$j";
3324                         }
3325                         if ($l == 0) {
3326                             if (length($type) + length($pointer) > $type_len) {
3327                                 $type_len = length($type) + length($pointer);
3328                             }
3329                             if (length($name) > $name_len) {
3330                                 $name_len = length($name);
3331                             }
3332                         }
3333                         else {
3334                             $xref = &MakeXRef ($type, &tagify($type, "type"));
3335                             $pad = ' ' x ($type_len - length($type) - length($pointer));
3336                             $desc .= "$xref$pad $pointer$name,\n";
3337                             $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
3338                         }
3339                     } else {
3340                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3341                              "Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]");
3342                     }
3343                 }
3344             }
3345             $xref = &MakeXRef ("gpointer", &tagify("gpointer", "type"));
3346             $pad = ' ' x ($type_len - length("gpointer"));
3347             $desc  .= "$xref$pad user_data)";
3349             my $flags = $SignalFlags[$i];
3350             my $flags_string = "";
3352             if (defined ($flags)) {
3353               if ($flags =~ m/f/) {
3354                 $flags_string = "Run First";
3355               }
3356               elsif ($flags =~ m/l/) {
3357                 $flags_string = "Run Last";
3358               }
3359               elsif ($flags =~ m/c/) {
3360                 $flags_string = "Cleanup";
3361               }
3362               if ($flags =~ m/r/) {
3363                 if ($flags_string) { $flags_string .= " / "; }
3364                 $flags_string .= "No Recursion";
3365               }
3366               if ($flags =~ m/d/) {
3367                 if ($flags_string) { $flags_string .= " / "; }
3368                 $flags_string .= "Has Details";
3369               }
3370               if ($flags =~ m/a/) {
3371                 if ($flags_string) { $flags_string .= " / "; }
3372                 $flags_string .= "Action";
3373               }
3374               if ($flags =~ m/h/) {
3375                 if ($flags_string) { $flags_string .= " / "; }
3376                 $flags_string .= "No Hooks";
3377               }
3378             }
3380             if ($flags_string)
3381               {
3382                 $synop .= ": $flags_string\n";
3384                 $pad = ' ' x (5 + $name_len - length("user_data"));
3385                 $desc  .= "$pad : $flags_string</programlisting>\n";
3386               }
3387             else
3388               {
3389                 $synop .= "\n";
3390                 $desc  .= "</programlisting>\n";
3391               }
3393             $desc .= &MakeDeprecationNote($symbol);
3395             my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
3396             my $parameters_output = 0;
3398             $AllSymbols{$symbol} = 1;
3399             if (defined ($SymbolDocs{$symbol})) {
3400                 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3402                 # Try to insert the parameter table at the author's desired
3403                 # position. Otherwise we need to tag it onto the end.
3404                 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
3405                   $parameters_output = 1;
3406                 }
3407                 $desc .= $symbol_docs;
3409                 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
3410                     $AllDocumentedSymbols{$symbol} = 1;
3411                 }
3412             }
3414             if ($parameters_output == 0) {
3415                 $desc .= $parameters;
3416               }
3417             $desc .= OutputSymbolTraits ($symbol);
3418             $desc .= "</refsect2>";
3419         }
3420     }
3421     return ($synop, $desc);
3425 #############################################################################
3426 # Function    : GetArgs
3427 # Description : Returns the synopsis and detailed description DocBook output
3428 #               for the Args of a given GtkObject subclass.
3429 # Arguments   : $object - the GtkObject subclass, e.g. 'GtkButton'.
3430 #############################################################################
3432 sub GetArgs {
3433     my ($object) = @_;
3434     my $synop = "";
3435     my $desc = "";
3436     my $child_synop = "";
3437     my $child_desc = "";
3438     my $style_synop = "";
3439     my $style_desc = "";
3441     my $i;
3442     for ($i = 0; $i <= $#ArgObjects; $i++) {
3443         if ($ArgObjects[$i] eq $object) {
3444             #print "Found arg: $ArgNames[$i]\n";
3445             my $name = $ArgNames[$i];
3446             my $flags = $ArgFlags[$i];
3447             my $flags_string = "";
3448             my $kind = "";
3449             my $id_sep = "";
3451             if ($flags =~ m/c/) {
3452                 $kind = "child property";
3453                 $id_sep = "c-";
3454             }
3455             elsif ($flags =~ m/s/) {
3456                 $kind = "style property";
3457                 $id_sep = "s-";
3458             }
3459             else {
3460                 $kind = "property";
3461             }
3463             # Remember only one colon so we don't clash with signals.
3464             my $symbol = "${object}:${name}";
3465             # use two dashes and ev. an extra separator here for the same reason.
3466             my $id = &CreateValidSGMLID ("$object--$id_sep$name");
3468             my $type = $ArgTypes[$i];
3469             my $type_output;
3470             my $range = $ArgRanges[$i];
3471             my $range_output = CreateValidSGML ($range);
3472             my $default = $ArgDefaults[$i];
3473             my $default_output = CreateValidSGML ($default);
3475             if ($type eq "GtkString") {
3476                 $type = "char*";
3477             }
3478             if ($type eq "GtkSignal") {
3479                 $type = "GtkSignalFunc, gpointer";
3480                 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
3481                     . &MakeXRef ("gpointer");
3482             } elsif ($type =~ m/^(\w+)\*$/) {
3483                 $type_output = &MakeXRef ($1, &tagify($1, "type")) . "*";
3484             } else {
3485                 $type_output = &MakeXRef ($type, &tagify($type, "type"));
3486             }
3488             if ($flags =~ m/r/) {
3489                 $flags_string = "Read";
3490             }
3491             if ($flags =~ m/w/) {
3492                 if ($flags_string) { $flags_string .= " / "; }
3493                 $flags_string .= "Write";
3494             }
3495             if ($flags =~ m/x/) {
3496                 if ($flags_string) { $flags_string .= " / "; }
3497                 $flags_string .= "Construct";
3498             }
3499             if ($flags =~ m/X/) {
3500                 if ($flags_string) { $flags_string .= " / "; }
3501                 $flags_string .= "Construct Only";
3502             }
3504             $AllSymbols{$symbol} = 1;
3505             my $blurb;
3506             if (defined($SymbolDocs{$symbol}) &&
3507                 !IsEmptyDoc($SymbolDocs{$symbol})) {
3508                 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3509                 #print ".. [$SymbolDocs{$symbol}][$blurb]\n";
3510                 $AllDocumentedSymbols{$symbol} = 1;
3511             }
3512             else {
3513                 if (!($ArgBlurbs[$i] eq "")) {
3514                     $AllDocumentedSymbols{$symbol} = 1;
3515                 } else {
3516                     # FIXME: print a warning?
3517                     #print ".. no description\n";
3518                 }
3519                 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
3520             }
3522             my $pad1 = " " x (24 - length ($name));
3523             my $pad2 = " " x (20 - length ($type));
3525             my $arg_synop = "  &quot;<link linkend=\"$id\">$name</link>&quot;$pad1 $type_output $pad2 : $flags_string\n";
3526             my $arg_desc = "<refsect2 id=\"$id\" role=\"property\"><title>The <literal>&quot;$name&quot;</literal> $kind</title>\n";
3527             $arg_desc .= MakeIndexterms($symbol, $id);
3528             $arg_desc .= "\n";
3529             $arg_desc .= OutputSymbolExtraLinks($symbol);
3531             $arg_desc .= "<programlisting>  &quot;$name&quot;$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
3532             $arg_desc .= &MakeDeprecationNote($symbol);
3533             $arg_desc .= $blurb;
3534             if ($range ne "") {
3535                 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
3536             }
3537             if ($default ne "") {
3538                 $arg_desc .= "<para>Default value: $default_output</para>\n";
3539             }
3540             $arg_desc .= OutputSymbolTraits ($symbol);
3541             $arg_desc .= "</refsect2>\n";
3543             if ($flags =~ m/c/) {
3544                 $child_synop .= $arg_synop;
3545                 $child_desc .= $arg_desc;
3546             }
3547             elsif ($flags =~ m/s/) {
3548                 $style_synop .= $arg_synop;
3549                 $style_desc .= $arg_desc;
3550             }
3551             else {
3552                 $synop .= $arg_synop;
3553                 $desc .= $arg_desc;
3554             }
3555         }
3556     }
3557     return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
3561 #############################################################################
3562 # Function    : ReadSourceDocumentation
3563 # Description : This reads in the documentation embedded in comment blocks
3564 #               in the source code (for Gnome).
3566 #               Parameter descriptions override any in the template files.
3567 #               Function descriptions are placed before any description from
3568 #               the template files.
3570 #               It recursively descends the source directory looking for .c
3571 #               files and scans them looking for specially-formatted comment
3572 #               blocks.
3574 # Arguments   : $source_dir - the directory to scan.
3575 #############m###############################################################
3577 sub ReadSourceDocumentation {
3578     my ($source_dir) = @_;
3579     my ($file, $dir, @suffix_list, $suffix);
3580     #print "Scanning source directory: $source_dir\n";
3582     # This array holds any subdirectories found.
3583     my (@subdirs) = ();
3585     @suffix_list = split (/,/, $SOURCE_SUFFIXES);
3587     opendir (SRCDIR, $source_dir)
3588         || die "Can't open source directory $source_dir: $!";
3590     foreach $file (readdir (SRCDIR)) {
3591       if ($file =~ /^\./) {
3592         next;
3593       } elsif (-d "$source_dir/$file") {
3594         push (@subdirs, $file);
3595       } elsif (@suffix_list) {
3596         foreach $suffix (@suffix_list) {
3597           if ($file =~ m/\.\Q${suffix}\E$/) {
3598             &ScanSourceFile ("$source_dir/$file");
3599           }
3600         }
3601       } elsif ($file =~ m/\.[ch]$/) {
3602         &ScanSourceFile ("$source_dir/$file");
3603       }
3604     }
3605     closedir (SRCDIR);
3607     # Now recursively scan the subdirectories.
3608     foreach $dir (@subdirs) {
3609         next if ($IGNORE_FILES =~ m/(\s|^)\Q${dir}\E(\s|$)/);
3610         &ReadSourceDocumentation ("$source_dir/$dir");
3611     }
3615 #############################################################################
3616 # Function    : ScanSourceFile
3617 # Description : Scans one source file looking for specially-formatted comment
3618 #               blocks. Later &MergeSourceDocumentation is used to merge any
3619 #               documentation found with the documentation already read in
3620 #               from the template files.
3622 # Arguments   : $file - the file to scan.
3623 #############################################################################
3625 sub ScanSourceFile {
3626     my ($file) = @_;
3627     my $basename;
3629     if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
3630         $basename = $1;
3631     } else {
3632         &LogWarning ($file, 1, "Can't find basename for this filename.");
3633         $basename = $file;
3634     }
3636     # Check if the basename is in the list of files to ignore.
3637     if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
3638         return;
3639     }
3641     #print "DEBUG: Scanning $file\n";
3643     open (SRCFILE, $file)
3644         || die "Can't open $file: $!";
3645     my $in_comment_block = 0;
3646     my $symbol;
3647     my ($in_description, $in_return, $in_since, $in_stability, $in_deprecated);
3648     my ($description, $return_desc, $return_start, $return_style);
3649     my ($since_desc, $stability_desc, $deprecated_desc);
3650     my $current_param;
3651     my $ignore_broken_returns;
3652     my @params;
3653     while (<SRCFILE>) {
3654         # Look for the start of a comment block.
3655         if (!$in_comment_block) {
3656             if (m%^\s*/\*.*\*/%) {
3657                 #one-line comment - not gtkdoc
3658             } elsif (m%^\s*/\*\*\s%) {
3659                 #print "Found comment block start\n";
3661                 $in_comment_block = 1;
3663                 # Reset all the symbol data.
3664                 $symbol = "";
3665                 $in_description = 0;
3666                 $in_return = 0;
3667                 $in_since = 0;
3668                 $in_deprecated = 0;
3669                 $in_stability = 0;
3670                 $description = "";
3671                 $return_desc = "";
3672                 $return_style = "";
3673                 $since_desc = "";
3674                 $deprecated_desc = "";
3675                 $stability_desc = "";
3676                 $current_param = -1;
3677                 $ignore_broken_returns = 0;
3678                 @params = ();
3679             }
3680             next;
3681         }
3683         # We're in a comment block. Check if we've found the end of it.
3684         if (m%^\s*\*+/%) {
3685             if (!$symbol) {
3686                 # maybe its not even meant to be a gtk-doc comment?
3687                 &LogWarning ($file, $., "Symbol name not found at the start of the comment block.");
3688             } else {
3689                 # Add the return value description onto the end of the params.
3690                 if ($return_desc) {
3691                     push (@params, "Returns");
3692                     push (@params, $return_desc);
3693                     if ($return_style eq 'broken') {
3694                         &LogWarning ($file, $., "Free-form return value description in $symbol. Use `Returns:' to avoid ambiguities.");
3695                     }
3696                 }
3697                 # Convert special SGML characters
3698                 $description = &ConvertSGMLChars ($symbol, $description);
3699                 my $k;
3700                 for ($k = 1; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3701                     $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
3702                 }
3704                 # Handle Section docs
3705                 if ($symbol =~ m/SECTION:\s*(.*)/) {
3706                     my $real_symbol=$1;
3707                     my $key;
3709                     if (scalar %KnownSymbols) {
3710                         if ((! defined($KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"})) || $KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"} != 1) {
3711                             &LogWarning ($file, $., "Section $real_symbol is not defined in the $MODULE-section.txt file.");
3712                         }
3713                     }
3715                     #print "SECTION DOCS found in source for : '$real_symbol'\n";
3716                     $ignore_broken_returns = 1;
3717                     for ($k = 0; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3718                         #print "   '".$params[$k]."'\n";
3719                         $params[$k] = "\L$params[$k]";
3720                         undef $key;
3721                         if ($params[$k] eq "short_description") {
3722                             $key = "$TMPL_DIR/$real_symbol:Short_Description";
3723                         } elsif ($params[$k] eq "see_also") {
3724                             $key = "$TMPL_DIR/$real_symbol:See_Also";
3725                         } elsif ($params[$k] eq "title") {
3726                             $key = "$TMPL_DIR/$real_symbol:Title";
3727                         } elsif ($params[$k] eq "stability") {
3728                             $key = "$TMPL_DIR/$real_symbol:Stability_Level";
3729                         } elsif ($params[$k] eq "section_id") {
3730                             $key = "$TMPL_DIR/$real_symbol:Section_Id";
3731                         } elsif ($params[$k] eq "include") {
3732                             $key = "$TMPL_DIR/$real_symbol:Include";
3733                         } elsif ($params[$k] eq "image") {
3734                             $key = "$TMPL_DIR/$real_symbol:Image";
3735                         }
3736                         if (defined($key)) {
3737                             $SourceSymbolDocs{$key}=$params[$k+1];
3738                             $SourceSymbolSourceFile{$key} = $file;
3739                             $SourceSymbolSourceLine{$key} = $.;
3740                         }
3741                     }
3742                     $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
3743                     $SourceSymbolSourceFile{"$TMPL_DIR/$real_symbol:Long_Description"} = $file;
3744                     $SourceSymbolSourceLine{"$TMPL_DIR/$real_symbol:Long_Description"} = $.;
3745                     #$SourceSymbolTypes{$symbol} = "SECTION";
3746                 } else {
3747                     #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
3748                     $SourceSymbolDocs{$symbol} = $description;
3749                     $SourceSymbolParams{$symbol} = [ @params ];
3750                     # FIXME $SourceSymbolTypes{$symbol} = "STRUCT,SIGNAL,ARG,FUNCTION,MACRO";
3751                     #if (defined $DeclarationTypes{$symbol}) {
3752                     #    $SourceSymbolTypes{$symbol} = $DeclarationTypes{$symbol}
3753                     #}
3754                     $SourceSymbolSourceFile{$symbol} = $file;
3755                     $SourceSymbolSourceLine{$symbol} = $.;
3756                 }
3758                 if ($since_desc) {
3759                      ($since_desc, my @extra_lines) = split ("\n", $since_desc);
3760                      $since_desc =~ s/^\s+//;
3761                      $since_desc =~ s/\s+$//;
3762                      #print "Since($symbol) : [$since_desc]\n";
3763                      $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
3764                      if(scalar @extra_lines) {
3765                          &LogWarning ($file, $., "multi-line since docs found");
3766                      }
3767                 }
3769                 if ($stability_desc) {
3770                     $stability_desc = &ParseStabilityLevel($stability_desc, $file, $., "Stability level for $symbol");
3771                     $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
3772                 }
3774                 if ($deprecated_desc) {
3775                     if (exists $Deprecated{$symbol}) {
3776                     }
3777                     else {
3778                          # don't warn for signals and properties
3779                          #if ($symbol !~ m/::?(.*)/) {
3780                          if (defined $DeclarationTypes{$symbol}) {
3781                              &LogWarning ($file, $., 
3782                                  "$symbol is deprecated in the inline comments, but no deprecation guards were found around the declaration.".
3783                                  " (See the --deprecated-guards option for gtkdoc-scan.)");
3784                          }
3785                     }
3786                     $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
3787                 }
3788             }
3790             $in_comment_block = 0;
3791             next;
3792         }
3794         # Get rid of ' * ' at start of every line in the comment block.
3795         s%^\s*\*\s?%%;
3796         # But make sure we don't get rid of the newline at the end.
3797         if (!$_) {
3798             $_ = "\n";
3799         }
3800         #print "DEBUG: scanning :$_";
3802         # If we haven't found the symbol name yet, look for it.
3803         if (!$symbol) {
3804             if (m%^\s*(SECTION:\s*\S+)%) {
3805                 $symbol = $1;
3806                 #print "SECTION DOCS found in source for : '$symbol'\n";
3807                 $ignore_broken_returns = 1;
3808             } elsif (m%^\s*([\w:-]*\w)\s*:?\s*(\([a-z ]+\)\s*)*$%) {
3809                 $symbol = $1;
3810                 #print "SYMBOL DOCS found in source for : '$symbol'\n";
3811             }
3812             next;
3813         }
3815         # If we're in the return value description, add it to the end.
3816         if ($in_return) {
3817             # If we find another valid returns line, we assume that the first
3818             # one was really part of the description.
3819             if (m/^\s*(returns:|return\s+value:)/i) {
3820                 if ($return_style eq 'broken') {
3821                     $description .= $return_start . $return_desc;
3822                 }
3823                 $return_start = $1;
3824                 if ($return_style eq 'sane') {
3825                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3826                 }
3827                 $return_style = 'sane';
3828                 $ignore_broken_returns = 1;
3829                 $return_desc = $';
3830             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3831                 $description .= $return_start . $return_desc;
3832                 $return_start = $1;
3833                 $return_style = 'broken';
3834                 $return_desc = $';
3835             } elsif (m%^\s*since:%i) {
3836                 $since_desc = $';
3837                 $in_since = 1;
3838                 $in_return = 0;
3839             } elsif (m%^\s*stability:%i) {
3840                 $stability_desc = $';
3841                 $in_stability = 1;
3842                 $in_return = 0;
3843             } elsif (m%^\s*deprecated:%i) {
3844                 $deprecated_desc = $';
3845                 $in_deprecated = 1;
3846                 $in_return = 0;
3847             } else {
3848                 $return_desc .= $_;
3849             }
3850             next;
3851         }
3853         if ($in_since) {
3854             if (m/^\s*(returns:|return\s+value:)/i) {
3855                 if ($return_style eq 'broken') {
3856                     $description .= $return_start . $return_desc;
3857                 }
3858                 $return_start = $1;
3859                 if ($return_style eq 'sane') {
3860                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3861                 }
3862                 $return_style = 'sane';
3863                 $ignore_broken_returns = 1;
3864                 $return_desc = $';
3865                 $in_return = 1;
3866                 $in_since = 0;
3867             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3868                 $return_start = $1;
3869                 $return_style = 'broken';
3870                 $return_desc = $';
3871                 $in_return = 1;
3872                 $in_since = 0;
3873             } elsif (m%^\s*deprecated:%i) {
3874                 $deprecated_desc = $';
3875                 $in_deprecated = 1;
3876                 $in_since = 0;
3877             } elsif (m%^\s*stability:%i) {
3878                 $stability_desc = $';
3879                 $in_stability = 1;
3880                 $in_since = 0;
3881             } else {
3882                 $since_desc .= $_;
3883             }
3884             next;
3885         }
3887         if ($in_stability) {
3888             if (m/^\s*(returns:|return\s+value:)/i) {
3889                 if ($return_style eq 'broken') {
3890                     $description .= $return_start . $return_desc;
3891                 }
3892                 $return_start = $1;
3893                 if ($return_style eq 'sane') {
3894                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3895                 }
3896                 $return_style = 'sane';
3897                 $ignore_broken_returns = 1;
3898                 $return_desc = $';
3899                 $in_return = 1;
3900                 $in_stability = 0;
3901             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3902                 $return_start = $1;
3903                 $return_style = 'broken';
3904                 $return_desc = $';
3905                 $in_return = 1;
3906                 $in_stability = 0;
3907             } elsif (m%^\s*deprecated:%i) {
3908                 $deprecated_desc = $';
3909                 $in_deprecated = 1;
3910                 $in_stability = 0;
3911             } elsif (m%^\s*since:%i) {
3912                 $since_desc = $';
3913                 $in_since = 1;
3914                 $in_stability = 0;
3915             } else {
3916                 $stability_desc .= $_;
3917             }
3918             next;
3919         }
3921         if ($in_deprecated) {
3922             if (m/^\s*(returns:|return\s+value:)/i) {
3923                 if ($return_style eq 'broken') {
3924                     $description .= $return_start . $return_desc;
3925                 }
3926                 $return_start = $1;
3927                 if ($return_style eq 'sane') {
3928                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3929                 }
3930                 $return_style = 'sane';
3931                 $ignore_broken_returns = 1;
3932                 $return_desc = $';
3933                 $in_return = 1;
3934                 $in_deprecated = 0;
3935             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3936                 $return_start = $1;
3937                 $return_style = 'broken';
3938                 $return_desc = $';
3939                 $in_return = 1;
3940                 $in_deprecated = 0;
3941             } elsif (m%^\s*since:%i) {
3942                 $since_desc = $';
3943                 $in_since = 1;
3944                 $in_deprecated = 0;
3945             } elsif (m%^\s*stability:%i) {
3946                 $stability_desc = $';
3947                 $in_stability = 1;
3948                 $in_deprecated = 0;
3949             } else {
3950                 $deprecated_desc .= $_;
3951             }
3952             next;
3953         }
3955         # If we're in the description part, check for the 'Returns:' line.
3956         # If that isn't found, add the text to the end.
3957         if ($in_description) {
3958             # Get rid of 'Description:'
3959             s%^\s*Description:%%;
3961             if (m/^\s*(returns:|return\s+value:)/i) {
3962                 if ($return_style eq 'broken') {
3963                     $description .= $return_start . $return_desc;
3964                 }
3965                 $return_start = $1;
3966                 if ($return_style eq 'sane') {
3967                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3968                 }
3969                 $return_style = 'sane';
3970                 $ignore_broken_returns = 1;
3971                 $return_desc = $';
3972                 $in_return = 1;
3973                 next;
3974             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3975                 $return_start = $1;
3976                 $return_style = 'broken';
3977                 $return_desc = $';
3978                 $in_return = 1;
3979                 next;
3980             } elsif (m%^\s*since:%i) {
3981                 $since_desc = $';
3982                 $in_since = 1;
3983                 next;
3984             } elsif (m%^\s*deprecated:%i) {
3985                 $deprecated_desc = $';
3986                 $in_deprecated = 1;
3987                 next;
3988             } elsif (m%^\s*stability:%i) {
3989                 $stability_desc = $';
3990                 $in_stability = 1;
3991                 next;
3992             }
3994             $description .= $_;
3995             next;
3996         }
3998         # We must be in the parameters. Check for the empty line below them.
3999         if (m%^\s*$%) {
4000             $in_description = 1;
4001             next;
4002         }
4004         # Look for a parameter name.
4005         if (m%^\s*@(\S+)\s*:\s*%) {
4006             my $param_name = $1;
4007             my $param_desc = $';
4009             #print "Found parameter: $param_name\n";
4010             # Allow '...' as the Varargs parameter.
4011             if ($param_name eq "...") {
4012                 $param_name = "Varargs";
4013             }
4014             if ("\L$param_name" eq "returns") {
4015                 $return_style = 'sane';
4016                 $ignore_broken_returns = 1;
4017             }
4018             push (@params, $param_name);
4019             push (@params, $param_desc);
4020             $current_param += $PARAM_FIELD_COUNT;
4021             next;
4022         }
4024         # We must be in the middle of a parameter description, so add it on
4025         # to the last element in @params.
4026         if ($current_param == -1) {
4027             &LogWarning ($file, $., "Parsing comment block file : parameter expected.");
4028         } else {
4029             $params[$#params] .= $_;
4030         }
4031     }
4032     close (SRCFILE);
4035 #############################################################################
4036 # Function    : OutputMissingDocumentation
4037 # Description : Outputs report of documentation coverage to a file
4039 # Arguments   : none
4040 #############################################################################
4042 sub OutputMissingDocumentation {
4043     my $old_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.txt";
4044     my $new_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.new";
4046     my $n_documented = 0;
4047     my $n_incomplete = 0;
4048     my $total = 0;
4049     my $symbol;
4050     my $percent;
4051     my $msg;
4052     my $buffer = "";
4053     my $buffer_deprecated = "";
4054     my $buffer_descriptions = "";
4055     
4056     open(UNDOCUMENTED, ">$new_undocumented_file")
4057       || die "Can't create $new_undocumented_file";
4058     
4059     foreach $symbol (sort (keys (%AllSymbols))) {
4060         # FIXME: should we print LogWarnings for undocumented stuff?
4061         # DEBUG
4062         #my $ssfile = &GetSymbolSourceFile($symbol);
4063         #my $ssline = &GetSymbolSourceLine($symbol);
4064         #my $location = "defined at " . (defined($ssfile)?$ssfile:"?") . ":" . (defined($ssline)?$ssline:"0") . "\n";
4065         # DEBUG
4066         if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include|Section_Id|Image)/) {
4067             $total++;
4068             if (exists ($AllDocumentedSymbols{$symbol})) {
4069                 $n_documented++;
4070                 if (exists ($AllIncompleteSymbols{$symbol})) {
4071                     $n_incomplete++;
4072                     $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4073                     #$buffer .= "\t0: ".$location;
4074                 }
4075             } elsif (exists $Deprecated{$symbol}) {
4076                 if (exists ($AllIncompleteSymbols{$symbol})) {
4077                     $n_incomplete++;
4078                     $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4079                     #$buffer .= "\t1a: ".$location;
4080                 } else {
4081                     $buffer_deprecated .= $symbol . "\n";
4082                     #$buffer .= "\t1b: ".$location;
4083                 }
4084             } else {
4085                 if (exists ($AllIncompleteSymbols{$symbol})) {
4086                     $n_incomplete++;
4087                     $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4088                     #$buffer .= "\t2a: ".$location;
4089                 } else {
4090                     $buffer .= $symbol . "\n";
4091                     #$buffer .= "\t2b: ".$location;
4092                 }
4093             }
4094         } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
4095             $total++;
4096             #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
4097             #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
4098             #print "%%%% $symbol : $len1,$len2\n";
4099             if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
4100             || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
4101               $n_documented++;
4102             } else {
4103               # cut off the leading namespace ($TMPL_DIR)
4104               $symbol =~ m/^.*\/(.*)$/;
4105               $buffer_descriptions .= $1 . "\n";
4106             }
4107         }
4108     }
4109     
4110     $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
4111     
4112     if ($total == 0) {
4113       $percent = 100;
4114     } else {
4115       $percent = ($n_documented / $total) * 100.0;
4116     }
4117     
4118     printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
4119     print UNDOCUMENTED "$n_documented symbols documented.\n";
4120     print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
4121     print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
4122     
4123     print UNDOCUMENTED $buffer;
4124     close (UNDOCUMENTED);
4125     
4126     return &UpdateFileIfChanged ($old_undocumented_file, $new_undocumented_file, 0);
4127     
4128     printf "%.0f%% symbol docs coverage", $percent;
4129     print "($n_documented symbols documented, $n_incomplete symbols incomplete, " . ($total - $n_documented) . " not documented)\n";
4130     print "See $MODULE-undocumented.txt for a list of missing docs.\nThe doc coverage percentage doesn't include intro sections.\n";
4134 #############################################################################
4135 # Function    : OutputUndeclaredSymbols
4136 # Description : Outputs symbols that are listed in the section file, but not
4137 #               declaration is found in the sources
4139 # Arguments   : none
4140 #############################################################################
4142 sub OutputUndeclaredSymbols {
4143     my $old_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.txt";
4144     my $new_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.new";
4146     open(UNDECLARED, ">$new_undeclared_file")
4147         || die "Can't create $new_undeclared_file";
4149     if (%UndeclaredSymbols) {
4150         print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
4151         print UNDECLARED "\n";
4152         print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
4153     }
4154     close(UNDECLARED);
4156     return &UpdateFileIfChanged ($old_undeclared_file, $new_undeclared_file, 0);
4159 #############################################################################
4160 # Function    : OutputUnusedSymbols
4161 # Description : Outputs symbols that are documented in comments, but not
4162 #               declared in the sources
4164 # Arguments   : none
4165 #############################################################################
4167 sub OutputUnusedSymbols {
4168     my $num_unused = 0;
4169     my $old_unused_file = "$ROOT_DIR/$MODULE-unused.txt";
4170     my $new_unused_file = "$ROOT_DIR/$MODULE-unused.new";
4172     open (UNUSED, ">$new_unused_file")
4173         || die "Can't open $new_unused_file";
4174     my ($symbol);
4175     foreach $symbol (sort keys (%Declarations)) {
4176         if (!defined ($DeclarationOutput{$symbol})) {
4177             print (UNUSED "$symbol\n");
4178             $num_unused++;
4179         }
4180     }
4181     foreach $symbol (sort (keys (%AllUnusedSymbols))) {
4182         print (UNUSED "$symbol(" . $AllUnusedSymbols{$symbol} . ")\n");
4183         $num_unused++;
4184     }
4185     close (UNUSED);
4186     if ($num_unused != 0) {
4187         &LogWarning ($old_unused_file, 1, "$num_unused unused declarations.".
4188             "They should be added to $MODULE-sections.txt in the appropriate place.");
4189     }
4190     
4191     return &UpdateFileIfChanged ($old_unused_file, $new_unused_file, 0); 
4195 #############################################################################
4196 # Function    : OutputAllSymbols
4197 # Description : Outputs list of all symbols to a file
4199 # Arguments   : none
4200 #############################################################################
4202 sub OutputAllSymbols {
4203      my $n_documented = 0;
4204      my $total = 0;
4205      my $symbol;
4206      my $percent;
4207      my $msg;
4209      open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
4210           || die "Can't create $ROOT_DIR/$MODULE-symbols.txt: $!";
4212      foreach $symbol (sort (keys (%AllSymbols))) {
4213           print SYMBOLS $symbol . "\n";
4214      }
4216      close (SYMBOLS);
4219 #############################################################################
4220 # Function    : OutputSymbolsWithoutSince
4221 # Description : Outputs list of all symbols without a since tag to a file
4223 # Arguments   : none
4224 #############################################################################
4226 sub OutputSymbolsWithoutSince {
4227      my $n_documented = 0;
4228      my $total = 0;
4229      my $symbol;
4230      my $percent;
4231      my $msg;
4233      open (SYMBOLS, ">$ROOT_DIR/$MODULE-nosince.txt")
4234           || die "Can't create $ROOT_DIR/$MODULE-nosince.txt: $!";
4236      foreach $symbol (sort (keys (%SourceSymbolDocs))) {
4237          if (!defined $Since{$symbol}) {
4238              print SYMBOLS $symbol . "\n";
4239          }
4240      }
4242      close (SYMBOLS);
4246 #############################################################################
4247 # Function    : MergeSourceDocumentation
4248 # Description : This merges documentation read from a source file into the
4249 #               documentation read in from a template file.
4251 #               Parameter descriptions override any in the template files.
4252 #               Function descriptions are placed before any description from
4253 #               the template files.
4255 # Arguments   : none
4256 #############################################################################
4258 sub MergeSourceDocumentation {
4259     my $symbol;
4260     my @Symbols;
4262     if (scalar %SymbolDocs) {
4263         @Symbols=keys (%SymbolDocs);
4264         #print "num existing entries: ".(scalar @Symbols)."\n";
4265         #print "  ",$Symbols[0], " ",$Symbols[1],"\n";
4266     }
4267     else {
4268         # filter scanned declarations, with what we suppress from -sections.txt
4269         my %tmp = ();
4270         foreach $symbol (keys (%Declarations)) {
4271             if (defined($KnownSymbols{$symbol}) && $KnownSymbols{$symbol} == 1) {
4272                 $tmp{$symbol}=1;
4273             }
4274         }
4275         # , add the rest from -sections.txt
4276         foreach $symbol (keys (%KnownSymbols)) {
4277             if ($KnownSymbols{$symbol} == 1) {
4278                 $tmp{$symbol}=1;
4279             }
4280         }
4281         # and add whats found in the source
4282         foreach $symbol (keys (%SourceSymbolDocs)) {
4283             $tmp{$symbol}=1;
4284         }
4285         @Symbols = keys (%tmp);
4286         #print "num source entries: ".(scalar @Symbols)."\n";
4287     }
4288     foreach $symbol (@Symbols) {
4289         $AllSymbols{$symbol} = 1;
4291         my $have_tmpl_docs = 0;
4293         ## See if the symbol is documented in template
4294         my $tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4295         my $check_tmpl_doc =$tmpl_doc;
4296         # remove all xml-tags and whitespaces (don't kill <include href="..."> tags) 
4297         $check_tmpl_doc =~ s/<\/?[a-z]+>//gi;
4298         $check_tmpl_doc =~ s/\s//g;
4299         # anything left ?
4300         if ($check_tmpl_doc ne "") {
4301             $have_tmpl_docs = 1;
4302             #print "## [$check_tmpl_doc]\n";
4303         } else {
4304             $tmpl_doc = "";
4305         }
4307         if (exists ($SourceSymbolDocs{$symbol})) {
4308             my $type = $DeclarationTypes {$symbol};
4310             #print "merging [$symbol] from source\n";
4312             my $item = "Parameter";
4313             if (defined ($type)) {
4314                 if ($type eq 'STRUCT') {
4315                     $item = "Field";
4316                 } elsif ($type eq 'ENUM') {
4317                     $item = "Value";
4318                 } elsif ($type eq 'UNION') {
4319                     $item = "Field";
4320                 }
4321             } else {
4322                 $type="SIGNAL";
4323             }
4325             my $src_doc = $SourceSymbolDocs{$symbol};
4326             # remove leading and training whitespaces
4327             $src_doc =~ s/^\s+//;
4328             $src_doc =~ s/\s+$//;
4330             # Don't output warnings for overridden titles as titles are
4331             # automatically generated in the -sections.txt file, and thus they
4332             # are often overridden.
4333             if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
4334                 # check if content is different
4335                 if ($tmpl_doc ne $src_doc) {
4336                     #print "[$tmpl_doc] [$src_doc]\n";
4337                     &LogWarning ($SourceSymbolSourceFile{$symbol}, $SourceSymbolSourceLine{$symbol},
4338                         "Documentation in template ".$SymbolSourceFile{$symbol}.":".$SymbolSourceLine{$symbol}." for $symbol being overridden by inline comments.");
4339                 }
4340             }
4342             if ($src_doc ne "") {
4343                  $AllDocumentedSymbols{$symbol} = 1;
4344             }
4346             # Convert <!--PARAMETERS--> with any blank lines around it to
4347             # a </para> followed by <!--PARAMETERS--> followed by <para>.
4348             $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
4350             # Do not add <para> to nothing, it breaks missing docs checks.
4351             my $src_doc_para = "";
4352             if ($src_doc ne "") {
4353                 # If there is a blank line, finish the paragraph and start another.
4354                 $src_doc = &ConvertBlankLines ($src_doc, $symbol);
4355                 $src_doc_para = "<para>\n$src_doc\n</para>";
4356                 ## fixup xml markup
4357                 # FIXME: this is questionable, as we can't make assumtions on the content really
4358                 #$src_doc_para =~ s%^<para>\n(<refsect[1-9])%$1%gms;
4359                 #$src_doc_para =~ s%^<para>\n<para>%<para>%gms;
4360                 #$src_doc_para =~ s%(</refsect[1-9]>)\n</para>$%$1%gms;
4361                 #print "$symbol : [$src_doc][$src_doc_para]\n";
4362             }
4364             if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
4365                 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4366             } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
4367                 # For the title/summary/see also section docs we don't want to
4368                 # add any <para> tags.
4369                 $SymbolDocs{$symbol} = "$src_doc"
4370             } else {
4371                 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4372             }
4374             # merge parameters
4375             if ($symbol =~ m/.*::.*/) {
4376                 # For signals we prefer the param names from the source docs,
4377                 # since the ones from the templates are likely to contain the
4378                 # artificial argn names which are generated by gtkdoc-scangobj.
4379                 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4380                 # FIXME: we need to check for empty docs here as well!
4381             } else {
4382                 # The templates contain the definitive parameter names and order,
4383                 # so we will not change that. We only override the actual text.
4384                 my $tmpl_params = $SymbolParams{$symbol};
4385                 if (!defined ($tmpl_params)) {
4386                     #print "No merge needed for $symbol\n";
4387                     $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4388                     #  FIXME: we still like to get the number of params and merge
4389                     #  1) we would noticed that params have been removed/renamed
4390                     #  2) we would catch undocumented params
4391                     #  params are not (yet) exported in -decl.txt so that we
4392                     #  could easily grab them :/
4393                 } else {
4394                     my $params = $SourceSymbolParams{$symbol};
4395                     my $j;
4396                     #print "Merge needed for $symbol, tmpl_params: ",$#$tmpl_params,", source_params: ",$#$params," \n";
4397                     for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4398                         my $tmpl_param_name = $$tmpl_params[$j];
4400                         # Allow '...' as the Varargs parameter.
4401                         if ($tmpl_param_name eq "...") {
4402                             $tmpl_param_name = "Varargs";
4403                         }
4405                         # Try to find the param in the source comment documentation.
4406                         my $found = 0;
4407                         my $k;
4408                         #print "  try merge param $tmpl_param_name\n";
4409                         for ($k = 0; $k <= $#$params; $k += $PARAM_FIELD_COUNT) {
4410                             my $param_name = $$params[$k];
4411                             my $param_desc = $$params[$k + 1];
4413                             #print "    test param  $param_name\n";
4414                             # We accept changes in case, since the Gnome source
4415                             # docs contain a lot of these.
4416                             if ("\L$param_name" eq "\L$tmpl_param_name") {
4417                                 $found = 1;
4419                                 # Override the description.
4420                                 $$tmpl_params[$j + 1] = $param_desc;
4422                                 # Set the name to "" to mark it as used.
4423                                 $$params[$k] = "";
4424                                 last;
4425                             }
4426                         }
4428                         # If it looks like the parameters are there, but not
4429                         # in the right place, try to explain a bit better.
4430                         if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
4431                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4432                                 "Parameters for $symbol must start on the line immediately after the function or macro name.");
4433                         }
4434                     }
4436                     # Now we output a warning if parameters have been described which
4437                     # do not exist.
4438                     for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
4439                         my $param_name = $$params[$j];
4440                         if ($param_name) {
4441                             # the template builder cannot detect if a macro returns
4442                             # a result or not
4443                             if(($type eq "MACRO") && ($param_name eq "Returns")) {
4444                                 # FIXME: do we need to add it then to tmpl_params[] ?
4445                                 my $num=$#$tmpl_params;
4446                                 #print "  adding Returns: to macro docs for $symbol.\n";
4447                                 $$tmpl_params[$num+1]="Returns";
4448                                 $$tmpl_params[$num+2]=$$params[$j+1];
4449                                 next;
4450                             }
4451                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4452                                 "$item described in source code comment block but does not exist. $type: $symbol $item: $param_name.");
4453                         }
4454                     }
4455                 }
4456             }
4457         } else {
4458             if ($have_tmpl_docs) {
4459                 $AllDocumentedSymbols{$symbol} = 1;
4460                 #print "merging [$symbol] from template\n";
4461             }
4462             else {
4463                 #print "[$symbol] undocumented\n";
4464             }
4465         }
4467         # if this symbol is documented, check if docs are complete
4468         $check_tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4469         # remove all xml-tags and whitespaces
4470         #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
4471         $check_tmpl_doc =~ s/<.*?>//g;
4472         $check_tmpl_doc =~ s/\s//g;
4473         if ($check_tmpl_doc ne "") {
4474             my $tmpl_params = $SymbolParams{$symbol};
4475             if (defined ($tmpl_params)) {
4476                 my $type = $DeclarationTypes {$symbol};
4478                 my $item = "Parameter";
4479                 if (defined ($type)) {
4480                     if ($type eq 'STRUCT') {
4481                         $item = "Field";
4482                     } elsif ($type eq 'ENUM') {
4483                         $item = "Value";
4484                     } elsif ($type eq 'UNION') {
4485                         $item = "Field";
4486                     }
4487                 } else {
4488                     $type="SIGNAL";
4489                 }
4491                 #print "Check param docs for $symbol, tmpl_params: ",$#$tmpl_params," entries, type=$type\n";
4493                 if ($#$tmpl_params > 0) {
4494                     my $j;
4495                     for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4496                         # Output a warning if the parameter is empty and
4497                         # remember for stats.
4498                         my $tmpl_param_name = $$tmpl_params[$j];
4499                         my $tmpl_param_desc = $$tmpl_params[$j + 1];
4500                         if ($tmpl_param_name ne "void" && $tmpl_param_desc !~ m/\S/) {
4501                             if (exists ($AllIncompleteSymbols{$symbol})) {
4502                                 $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
4503                             } else {
4504                                 $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
4505                             }
4506                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4507                                 "$item description for $symbol"."::"."$tmpl_param_name is missing in source code comment block.");
4508                         }
4509                     }
4510                 }
4511                 else {
4512                     if ($#$tmpl_params == 0) {
4513                         $AllIncompleteSymbols{$symbol}="<items>";
4514                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4515                             "$item descriptions for $symbol are missing in source code comment block.");
4516                     }
4517                     # $#$tmpl_params==-1 means we don't know about parameters
4518                     # this unfortunately does not tell if there should be some
4519                 }
4520             }
4521         }
4522    }
4523    #print "num doc entries: ".(scalar %SymbolDocs)."\n";
4526 #############################################################################
4527 # Function    : IsEmptyDoc
4528 # Description : Check if a doc-string is empty. Its also regarded as empty if
4529 #               it only consist of whitespace or e.g. FIXME.
4530 # Arguments   : the doc-string
4531 #############################################################################
4532 sub IsEmptyDoc {
4533     my ($doc) = @_;
4534     
4535     if ($doc =~ /^\s*$/) {
4536         return 1;
4537     }
4539     if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
4540         return 1;
4541     }
4543     return 0;
4547 # This converts blank lines to "</para><para>", but only outside CDATA and
4548 # <programlisting> tags.
4549 sub ConvertBlankLines {
4550     return &ModifyXMLElements ($_[0], $_[1],
4551                                "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
4552                                \&ConvertBlankLinesEndTag,
4553                                \&ConvertBlankLinesCallback);
4557 sub ConvertBlankLinesEndTag {
4558   if ($_[0] eq "<!\[CDATA\[") {
4559     return "]]>";
4560   } elsif ($_[0] eq "|[") {
4561     return "]\\|";
4562   } else {
4563     return "</programlisting>";
4564   }
4567 sub ConvertBlankLinesCallback {
4568   my ($text, $symbol, $tag) = @_;
4570   # If we're not in CDATA or a <programlisting> we convert blank lines so
4571   # they start a new <para>.
4572   if ($tag eq "") {
4573     $text =~ s%\n{2,}%\n</para>\n<para>\n%g;
4574   }
4576   return $text;
4580 #############################################################################
4581 # LIBRARY FUNCTIONS -   These functions are used in both gtkdoc-mkdb and
4582 #                       gtkdoc-mktmpl and should eventually be moved to a
4583 #                       separate library.
4584 #############################################################################
4586 #############################################################################
4587 # Function    : ReadDeclarationsFile
4588 # Description : This reads in a file containing the function/macro/enum etc.
4589 #               declarations.
4591 #               Note that in some cases there are several declarations with
4592 #               the same name, e.g. for conditional macros. In this case we
4593 #               set a flag in the %DeclarationConditional hash so the
4594 #               declaration is not shown in the docs.
4596 #               If a macro and a function have the same name, e.g. for
4597 #               gtk_object_ref, the function declaration takes precedence.
4599 #               Some opaque structs are just declared with 'typedef struct
4600 #               _name name;' in which case the declaration may be empty.
4601 #               The structure may have been found later in the header, so
4602 #               that overrides the empty declaration.
4604 # Arguments   : $file - the declarations file to read
4605 #               $override - if declarations in this file should override
4606 #                       any current declaration.
4607 #############################################################################
4609 sub ReadDeclarationsFile {
4610     my ($file, $override) = @_;
4612     if ($override == 0) {
4613         %Declarations = ();
4614         %DeclarationTypes = ();
4615         %DeclarationConditional = ();
4616         %DeclarationOutput = ();
4617     }
4619     open (INPUT, $file)
4620         || die "Can't open $file: $!";
4621     my $declaration_type = "";
4622     my $declaration_name;
4623     my $declaration;
4624     my $is_deprecated = 0;
4625     while (<INPUT>) {
4626         if (!$declaration_type) {
4627             if (m/^<([^>]+)>/) {
4628                 $declaration_type = $1;
4629                 $declaration_name = "";
4630                 #print "Found declaration: $declaration_type\n";
4631                 $declaration = "";
4632             }
4633         } else {
4634             if (m%^<NAME>(.*)</NAME>%) {
4635                 $declaration_name = $1;
4636             } elsif (m%^<DEPRECATED/>%) {
4637                 $is_deprecated = 1;
4638             } elsif (m%^</$declaration_type>%) {
4639                 #print "Found end of declaration: $declaration_name\n";
4640                 # Check that the declaration has a name
4641                 if ($declaration_name eq "") {
4642                     print "ERROR: $declaration_type has no name $file:$.\n";
4643                 }
4645                 # If the declaration is an empty typedef struct _XXX XXX
4646                 # set the flag to indicate the struct has a typedef.
4647                 if ($declaration_type eq 'STRUCT'
4648                     && $declaration =~ m/^\s*$/) {
4649                     #print "Struct has typedef: $declaration_name\n";
4650                     $StructHasTypedef{$declaration_name} = 1;
4651                 }
4653                 # Check if the symbol is already defined.
4654                 if (defined ($Declarations{$declaration_name})
4655                     && $override == 0) {
4656                     # Function declarations take precedence.
4657                     if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
4658                         # Ignore it.
4659                     } elsif ($declaration_type eq 'FUNCTION') {
4660                         if ($is_deprecated) {
4661                             $Deprecated{$declaration_name} = "";
4662                         }
4663                         $Declarations{$declaration_name} = $declaration;
4664                         $DeclarationTypes{$declaration_name} = $declaration_type;
4665                     } elsif ($DeclarationTypes{$declaration_name}
4666                               eq $declaration_type) {
4667                         # If the existing declaration is empty, or is just a
4668                         # forward declaration of a struct, override it.
4669                         if ($declaration_type eq 'STRUCT') {
4670                             if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4671                                 if ($is_deprecated) {
4672                                     $Deprecated{$declaration_name} = "";
4673                                 }
4674                                 $Declarations{$declaration_name} = $declaration;
4675                             } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4676                                 # Ignore an empty or forward declaration.
4677                             } else {
4678                                 &LogWarning ($file, $., "Structure $declaration_name has multiple definitions.");
4679                             }
4680                         } else {
4681                             # set flag in %DeclarationConditional hash for
4682                             # multiply defined macros/typedefs.
4683                             $DeclarationConditional{$declaration_name} = 1;
4684                         }
4685                     } else {
4686                         &LogWarning ($file, $., "$declaration_name has multiple definitions.");
4687                     }
4688                 } else {
4689                     if ($is_deprecated) {
4690                         $Deprecated{$declaration_name} = "";
4691                     }
4692                     $Declarations{$declaration_name} = $declaration;
4693                     $DeclarationTypes{$declaration_name} = $declaration_type;
4694                 }
4696                 $declaration_type = "";
4697                 $is_deprecated = 0;
4698             } else {
4699                 $declaration .= $_;
4700             }
4701         }
4702     }
4703     close (INPUT);
4707 #############################################################################
4708 # Function    : ReadSignalsFile
4709 # Description : This reads in an existing file which contains information on
4710 #               all GTK signals. It creates the arrays @SignalNames and
4711 #               @SignalPrototypes containing info on the signals. The first
4712 #               line of the SignalPrototype is the return type of the signal
4713 #               handler. The remaining lines are the parameters passed to it.
4714 #               The last parameter, "gpointer user_data" is always the same
4715 #               so is not included.
4716 # Arguments   : $file - the file containing the signal handler prototype
4717 #                       information.
4718 #############################################################################
4720 sub ReadSignalsFile {
4721     my ($file) = @_;
4723     my $in_signal = 0;
4724     my $signal_object;
4725     my $signal_name;
4726     my $signal_returns;
4727     my $signal_flags;
4728     my $signal_prototype;
4730     # Reset the signal info.
4731     @SignalObjects = ();
4732     @SignalNames = ();
4733     @SignalReturns = ();
4734     @SignalFlags = ();
4735     @SignalPrototypes = ();
4737     if (! -f $file) {
4738         return;
4739     }
4740     if (!open (INPUT, $file)) {
4741         warn "Can't open $file - skipping signals\n";
4742         return;
4743     }
4744     while (<INPUT>) {
4745         if (!$in_signal) {
4746             if (m/^<SIGNAL>/) {
4747                 $in_signal = 1;
4748                 $signal_object = "";
4749                 $signal_name = "";
4750                 $signal_returns = "";
4751                 $signal_prototype = "";
4752             }
4753         } else {
4754             if (m/^<NAME>(.*)<\/NAME>/) {
4755                 $signal_name = $1;
4756                 if ($signal_name =~ m/^(.*)::(.*)$/) {
4757                     $signal_object = $1;
4758                     ($signal_name = $2) =~ s/_/-/g;
4759                     #print "Found signal: $signal_name\n";
4760                 } else {
4761                     &LogWarning ($file, $., "Invalid signal name: $signal_name.");
4762                 }
4763             } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
4764                 $signal_returns = $1;
4765             } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4766                 $signal_flags = $1;
4767             } elsif (m%^</SIGNAL>%) {
4768                 #print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
4769                 push (@SignalObjects, $signal_object);
4770                 push (@SignalNames, $signal_name);
4771                 push (@SignalReturns, $signal_returns);
4772                 push (@SignalFlags, $signal_flags);
4773                 push (@SignalPrototypes, $signal_prototype);
4774                 $in_signal = 0;
4775             } else {
4776                 $signal_prototype .= $_;
4777             }
4778         }
4779     }
4780     close (INPUT);
4784 #############################################################################
4785 # Function    : ReadTemplateFile
4786 # Description : This reads in the manually-edited documentation file
4787 #               corresponding to the file currently being created, so we can
4788 #               insert the documentation at the appropriate places.
4789 #               It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
4790 #               is a hash of arrays.
4791 #               NOTE: This function is duplicated in gtkdoc-mktmpl (but
4792 #               slightly different).
4793 # Arguments   : $docsfile - the template file to read in.
4794 #               $skip_unused_params - 1 if the unused parameters should be
4795 #                       skipped.
4796 #############################################################################
4798 sub ReadTemplateFile {
4799     my ($docsfile, $skip_unused_params) = @_;
4801     my $template = "$docsfile.sgml";
4802     if (! -f $template) {
4803         #print "File doesn't exist: $template\n";
4804         return 0;
4805     }
4806     #print "Reading $template\n";
4808     # start with empty hashes, we merge the source comment for each file
4809     # afterwards
4810     %SymbolDocs = ();
4811     %SymbolTypes = ();
4812     %SymbolParams = ();
4814     my $current_type = "";      # Type of symbol being read.
4815     my $current_symbol = "";    # Name of symbol being read.
4816     my $symbol_doc = "";                # Description of symbol being read.
4817     my @params;                 # Parameter names and descriptions of current
4818                                 #   function/macro/function typedef.
4819     my $current_param = -1;     # Index of parameter currently being read.
4820                                 #   Note that the param array contains pairs
4821                                 #   of param name & description.
4822     my $in_unused_params = 0;   # True if we are reading in the unused params.
4823     my $in_deprecated = 0;
4824     my $in_since = 0;
4825     my $in_stability = 0;
4827     open (DOCS, "$template")
4828         || die "Can't open $template: $!";
4829     while (<DOCS>) {
4830         if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
4831             my $type = $1;
4832             my $symbol = $2;
4833             if ($symbol eq "Title"
4834                 || $symbol eq "Short_Description"
4835                 || $symbol eq "Long_Description"
4836                 || $symbol eq "See_Also"
4837                 || $symbol eq "Stability_Level"
4838                 || $symbol eq "Include"
4839                 || $symbol eq "Image") {
4841                 $symbol = $docsfile . ":" . $symbol;
4842             }
4844             #print "Found symbol: $symbol\n";
4845             # Remember file and line for the symbol
4846             $SymbolSourceFile{$symbol} = $template;
4847             $SymbolSourceLine{$symbol} = $.;
4849             # Store previous symbol, but remove any trailing blank lines.
4850             if ($current_symbol ne "") {
4851                 $symbol_doc =~ s/\s+$//;
4852                 $SymbolTypes{$current_symbol} = $current_type;
4853                 $SymbolDocs{$current_symbol} = $symbol_doc;
4855                 # Check that the stability level is valid.
4856                 if ($StabilityLevel{$current_symbol}) {
4857                     $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4858                 }
4860                 if ($current_param >= 0) {
4861                     $SymbolParams{$current_symbol} = [ @params ];
4862                 } else {
4863                     # Delete any existing params in case we are overriding a
4864                     # previously read template.
4865                     delete $SymbolParams{$current_symbol};
4866                 }
4867             }
4868             $current_type = $type;
4869             $current_symbol = $symbol;
4870             $current_param = -1;
4871             $in_unused_params = 0;
4872             $in_deprecated = 0;
4873             $in_since = 0;
4874             $in_stability = 0;
4875             $symbol_doc = "";
4876             @params = ();
4878         } elsif (m/^<!-- # Unused Parameters # -->/) {
4879             #print "DEBUG: Found unused parameters\n";
4880             $in_unused_params = 1;
4881             next;
4883         } elsif ($in_unused_params && $skip_unused_params) {
4884             # When outputting the DocBook we skip unused parameters.
4885             #print "DEBUG: Skipping unused param: $_";
4886             next;
4888         } else {
4889             # Check if param found. Need to handle "..." and "format...".
4890             if (s/^\@([\w\.]+):\040?//) {
4891                 my $param_name = $1;
4892                 my $param_desc = $_;
4893                 # Allow variations of 'Returns'
4894                 if ($param_name =~ m/^[Rr]eturns?$/) {
4895                     $param_name = "Returns";
4896                 }
4898                 # strip trailing whitespaces and blank lines
4899                 s/\s+\n$/\n/m;
4900                 s/\n+$/\n/sm;
4901                 #print "Found param for symbol $current_symbol : '$param_name'= '$_'";
4903                 if ($param_name eq "Deprecated") {
4904                     $in_deprecated = 1;
4905                     $Deprecated{$current_symbol} = $_;
4906                 } elsif ($param_name eq "Since") {
4907                     $in_since = 1;
4908                     chomp;
4909                     $Since{$current_symbol} = $_;
4910                 } elsif ($param_name eq "Stability") {
4911                     $in_stability = 1;
4912                     $StabilityLevel{$current_symbol} = $_;
4913                 } else {
4914                     push (@params, $param_name);
4915                     push (@params, $param_desc);
4916                     $current_param += $PARAM_FIELD_COUNT;
4917                 }
4918             } else {
4919                 # strip trailing whitespaces and blank lines
4920                 s/\s+\n$/\n/m;
4921                 s/\n+$/\n/sm;
4922                 
4923                 if (!m/^\s+$/) {
4924                     if ($in_deprecated) {
4925                         $Deprecated{$current_symbol} .= $_;
4926                     } elsif ($in_since) {
4927                         &LogWarning ($template, $., "multi-line since docs found");
4928                         #$Since{$current_symbol} .= $_;
4929                     } elsif ($in_stability) {
4930                         $StabilityLevel{$current_symbol} .= $_;
4931                     } elsif ($current_param >= 0) {
4932                         $params[$current_param] .= $_;
4933                     } else {
4934                         $symbol_doc .= $_;
4935                     }
4936                 }
4937             }
4938         }
4939     }
4941     # Remember to finish the current symbol doccs.
4942     if ($current_symbol ne "") {
4944         $symbol_doc =~ s/\s+$//;
4945         $SymbolTypes{$current_symbol} = $current_type;
4946         $SymbolDocs{$current_symbol} = $symbol_doc;
4948         # Check that the stability level is valid.
4949         if ($StabilityLevel{$current_symbol}) {
4950             $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4951         }
4953         if ($current_param >= 0) {
4954             $SymbolParams{$current_symbol} = [ @params ];
4955         } else {
4956             # Delete any existing params in case we are overriding a
4957             # previously read template.
4958             delete $SymbolParams{$current_symbol};
4959         }
4960     }
4962     close (DOCS);
4963     return 1;
4967 #############################################################################
4968 # Function    : ReadObjectHierarchy
4969 # Description : This reads in the $MODULE-hierarchy.txt file containing all
4970 #               the GtkObject subclasses described in this module (and their
4971 #               ancestors).
4972 #               It places them in the @Objects array, and places their level
4973 #               in the object hierarchy in the @ObjectLevels array, at the
4974 #               same index. GtkObject, the root object, has a level of 1.
4976 #               FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
4977 #               as it goes along, this should be split out into a separate
4978 #               function.
4980 # Arguments   : none
4981 #############################################################################
4983 sub ReadObjectHierarchy {
4984     @Objects = ();
4985     @ObjectLevels = ();
4987     if (! -f $OBJECT_TREE_FILE) {
4988         return;
4989     }
4990     if (!open (INPUT, $OBJECT_TREE_FILE)) {
4991         warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
4992         return;
4993     }
4995     # FIXME: use $OUTPUT_FORMAT
4996     # my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.$OUTPUT_FORMAT";
4997     my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
4998     my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
5000     open (OUTPUT, ">$new_tree_index")
5001         || die "Can't create $new_tree_index: $!";
5003     if ($OUTPUT_FORMAT eq "xml") {
5004         my $tree_header = $doctype_header;
5006         $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
5007         print (OUTPUT "$tree_header");
5008     }
5009     print (OUTPUT "<screen>\n");
5011     # Only emit objects if they are supposed to be documented, or if
5012     # they have documented children. To implement this, we maintain a
5013     # stack of pending objects which will be emitted if a documented
5014     # child turns up.
5015     my @pending_objects = ();
5016     my @pending_levels = ();
5017     while (<INPUT>) {
5018         if (m/\S+/) {
5019             my $object = $&;
5020             my $level = (length($`)) / 2 + 1;
5021             my $xref = "";
5023             while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
5024                 my $pobject = pop(@pending_objects);
5025                 my $plevel = pop(@pending_levels);
5026             }
5028             push (@pending_objects, $object);
5029             push (@pending_levels, $level);
5031             if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5032                 while ($#pending_levels >= 0) {
5033                     $object = shift @pending_objects;
5034                     $level = shift @pending_levels;
5035                     $xref = &MakeXRef ($object);
5037                     print (OUTPUT ' ' x ($level * 4), "$xref\n");
5038                     push (@Objects, $object);
5039                     push (@ObjectLevels, $level);
5040                 }
5041             }
5042             #else {
5043             #    LogWarning ($OBJECT_TREE_FILE, $., "unknown type $object");
5044             #}
5045         }
5046     }
5047     print (OUTPUT "</screen>\n");
5049     close (INPUT);
5050     close (OUTPUT);
5052     &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
5054     &OutputObjectList;
5057 #############################################################################
5058 # Function    : ReadInterfaces
5059 # Description : This reads in the $MODULE.interfaces file.
5061 # Arguments   : none
5062 #############################################################################
5064 sub ReadInterfaces {
5065     %Interfaces = ();
5067     if (! -f $INTERFACES_FILE) {
5068         return;
5069     }
5070     if (!open (INPUT, $INTERFACES_FILE)) {
5071         warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
5072         return;
5073     }
5075     while (<INPUT>) {
5076        chomp;
5077        my ($object, @ifaces) = split;
5078        if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5079            my @knownIfaces = ();
5081            # filter out private interfaces, but leave foreign interfaces
5082            foreach my $iface (@ifaces) {
5083                if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
5084                    push (@knownIfaces, $iface);
5085                }
5086              }
5088            $Interfaces{$object} = join(' ', @knownIfaces);
5089        }
5090     }
5091     close (INPUT);
5094 #############################################################################
5095 # Function    : ReadPrerequisites
5096 # Description : This reads in the $MODULE.prerequisites file.
5098 # Arguments   : none
5099 #############################################################################
5101 sub ReadPrerequisites {
5102     %Prerequisites = ();
5104     if (! -f $PREREQUISITES_FILE) {
5105         return;
5106     }
5107     if (!open (INPUT, $PREREQUISITES_FILE)) {
5108         warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
5109         return;
5110     }
5112     while (<INPUT>) {
5113        chomp;
5114        my ($iface, @prereqs) = split;
5115        if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
5116            my @knownPrereqs = ();
5118            # filter out private prerequisites, but leave foreign prerequisites
5119            foreach my $prereq (@prereqs) {
5120                if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
5121                   push (@knownPrereqs, $prereq);
5122                }
5123            }
5125            $Prerequisites{$iface} = join(' ', @knownPrereqs);
5126        }
5127     }
5128     close (INPUT);
5131 #############################################################################
5132 # Function    : ReadArgsFile
5133 # Description : This reads in an existing file which contains information on
5134 #               all GTK args. It creates the arrays @ArgObjects, @ArgNames,
5135 #               @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
5136 #               on the args.
5137 # Arguments   : $file - the file containing the arg information.
5138 #############################################################################
5140 sub ReadArgsFile {
5141     my ($file) = @_;
5143     my $in_arg = 0;
5144     my $arg_object;
5145     my $arg_name;
5146     my $arg_type;
5147     my $arg_flags;
5148     my $arg_nick;
5149     my $arg_blurb;
5150     my $arg_default;
5151     my $arg_range;
5153     # Reset the args info.
5154     @ArgObjects = ();
5155     @ArgNames = ();
5156     @ArgTypes = ();
5157     @ArgFlags = ();
5158     @ArgNicks = ();
5159     @ArgBlurbs = ();
5160     @ArgDefaults = ();
5161     @ArgRanges = ();
5163     if (! -f $file) {
5164         return;
5165     }
5166     if (!open (INPUT, $file)) {
5167         warn "Can't open $file - skipping args\n";
5168         return;
5169     }
5170     while (<INPUT>) {
5171         if (!$in_arg) {
5172             if (m/^<ARG>/) {
5173                 $in_arg = 1;
5174                 $arg_object = "";
5175                 $arg_name = "";
5176                 $arg_type = "";
5177                 $arg_flags = "";
5178                 $arg_nick = "";
5179                 $arg_blurb = "";
5180                 $arg_default = "";
5181                 $arg_range = "";
5182             }
5183         } else {
5184             if (m/^<NAME>(.*)<\/NAME>/) {
5185                 $arg_name = $1;
5186                 if ($arg_name =~ m/^(.*)::(.*)$/) {
5187                     $arg_object = $1;
5188                     ($arg_name = $2) =~ s/_/-/g;
5189                     #print "Found arg: $arg_name\n";
5190                 } else {
5191                     &LogWarning ($file, $., "Invalid argument name: $arg_name");
5192                 }
5193             } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
5194                 $arg_type = $1;
5195             } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
5196                 $arg_range = $1;
5197             } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
5198                 $arg_flags = $1;
5199             } elsif (m/^<NICK>(.*)<\/NICK>/) {
5200                 $arg_nick = $1;
5201             } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
5202                 $arg_blurb = $1;
5203                 if ($arg_blurb eq "(null)") {
5204                   $arg_blurb = "";
5205                   &LogWarning ($file, $., "Property ${arg_object}:${arg_name} has no documentation.");
5206                 }
5207             } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
5208                 $arg_default = $1;
5209             } elsif (m%^</ARG>%) {
5210                 #print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
5211                 push (@ArgObjects, $arg_object);
5212                 push (@ArgNames, $arg_name);
5213                 push (@ArgTypes, $arg_type);
5214                 push (@ArgRanges, $arg_range);
5215                 push (@ArgFlags, $arg_flags);
5216                 push (@ArgNicks, $arg_nick);
5217                 push (@ArgBlurbs, $arg_blurb);
5218                 push (@ArgDefaults, $arg_default);
5219                 $in_arg = 0;
5220             }
5221         }
5222     }
5223     close (INPUT);
5227 #############################################################################
5228 # Function    : CheckIsObject
5229 # Description : Returns 1 if the given name is a GObject or a subclass.
5230 #               It uses the global @Objects array.
5231 #               Note that the @Objects array only contains classes in the
5232 #               current module and their ancestors - not all GObject classes.
5233 # Arguments   : $name - the name to check.
5234 #############################################################################
5236 sub CheckIsObject {
5237     my ($name) = @_;
5239     my $object;
5240     foreach $object (@Objects) {
5241         if ($object eq $name) {
5242             return 1;
5243         }
5244     }
5245     return 0;
5249 #############################################################################
5250 # Function    : MakeReturnField
5251 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
5252 # Arguments   : $str - the string to pad.
5253 #############################################################################
5255 sub MakeReturnField {
5256     my ($str) = @_;
5258     return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));
5261 #############################################################################
5262 # Function    : GetSymbolSourceFile
5263 # Description : Get the filename where the symbol docs where taken from.
5264 # Arguments   : $symbol - the symbol name
5265 #############################################################################
5267 sub GetSymbolSourceFile {
5268     my ($symbol) = @_;
5270     if (defined($SourceSymbolSourceFile{$symbol})) {
5271         return $SourceSymbolSourceFile{$symbol};
5272     } elsif (defined($SymbolSourceFile{$symbol})) {
5273         return $SymbolSourceFile{$symbol};
5274     } else {
5275         return "";
5276     }
5279 #############################################################################
5280 # Function    : GetSymbolSourceLine
5281 # Description : Get the file line where the symbol docs where taken from.
5282 # Arguments   : $symbol - the symbol name
5283 #############################################################################
5285 sub GetSymbolSourceLine {
5286     my ($symbol) = @_;
5288     if (defined($SourceSymbolSourceLine{$symbol})) {
5289         return $SourceSymbolSourceLine{$symbol};
5290     } elsif (defined($SymbolSourceLine{$symbol})) {
5291         return $SymbolSourceLine{$symbol};
5292     } else {
5293         return 0;
5294     }