tests: fix gobject warnings
[gtk-doc.git] / gtkdoc-mkdb.in
blobba2282689738295868f7546b3d7a90efc3298a53
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     } else {
167         $doctype_header =
168 "<?xml version=\"1.0\"?>\n" .
169 "<!DOCTYPE book PUBLIC \"-//OASIS//DTD DocBook XML V4.3//EN\"\n" .
170 "               \"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd\"\n" .
171 "[\n" .
172 "  <!ENTITY % local.common.attrib \"xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'\">\n" .
173 "]>\n";
174     }
175     $doctype_header =~ s/<!DOCTYPE \w+/<!DOCTYPE refentry/;
176 } else {
177     if (!$MAIN_SGML_FILE) {
178         $MAIN_SGML_FILE = "${MODULE}-docs.sgml";
179     }
180     $empty_element_end = ">";
181     $doctype_header = "";
184 my $ROOT_DIR = ".";
186 # All the files are written in subdirectories beneath here.
187 $TMPL_DIR = $TMPL_DIR ? $TMPL_DIR : "$ROOT_DIR/tmpl";
189 # This is where we put all the DocBook output.
190 $SGML_OUTPUT_DIR = $SGML_OUTPUT_DIR ? $SGML_OUTPUT_DIR : "$ROOT_DIR/$OUTPUT_FORMAT";
192 # This file contains the object hierarchy.
193 my $OBJECT_TREE_FILE = "$ROOT_DIR/$MODULE.hierarchy";
195 # This file contains the interfaces.
196 my $INTERFACES_FILE = "$ROOT_DIR/$MODULE.interfaces";
198 # This file contains the prerequisites.
199 my $PREREQUISITES_FILE = "$ROOT_DIR/$MODULE.prerequisites";
201 # This file contains signal arguments and names.
202 my $SIGNALS_FILE = "$ROOT_DIR/$MODULE.signals";
204 # The file containing Arg information.
205 my $ARGS_FILE = "$ROOT_DIR/$MODULE.args";
207 # These global arrays store information on signals. Each signal has an entry
208 # in each of these arrays at the same index, like a multi-dimensional array.
209 my @SignalObjects;      # The GtkObject which emits the signal.
210 my @SignalNames;        # The signal name.
211 my @SignalReturns;      # The return type.
212 my @SignalFlags;        # Flags for the signal
213 my @SignalPrototypes;   # The rest of the prototype of the signal handler.
215 # These global arrays store information on Args. Each Arg has an entry
216 # in each of these arrays at the same index, like a multi-dimensional array.
217 my @ArgObjects;         # The GtkObject which has the Arg.
218 my @ArgNames;           # The Arg name.
219 my @ArgTypes;           # The Arg type - gint, GtkArrowType etc.
220 my @ArgFlags;           # How the Arg can be used - readable/writable etc.
221 my @ArgNicks;           # The nickname of the Arg.
222 my @ArgBlurbs;          # Docstring of the Arg.
223 my @ArgDefaults;        # Default value of the Arg.
224 my @ArgRanges;          # The range of the Arg type
225 # These global hashes store declaration info keyed on a symbol name.
226 my %Declarations;
227 my %DeclarationTypes;
228 my %DeclarationConditional;
229 my %DeclarationOutput;
230 my %Deprecated;
231 my %Since;
232 my %StabilityLevel;
233 my %StructHasTypedef;
235 # These global hashes store the existing documentation.
236 my %SymbolDocs;
237 my %SymbolTypes;
238 my %SymbolParams;
239 my %SymbolSourceFile;
240 my %SymbolSourceLine;
242 # These global hashes store documentation scanned from the source files.
243 my %SourceSymbolDocs;
244 my %SourceSymbolParams;
245 my %SourceSymbolSourceFile;
246 my %SourceSymbolSourceLine;
248 # all documentation goes in here, so we can do coverage analysis
249 my %AllSymbols;
250 my %AllIncompleteSymbols;
251 my %AllUnusedSymbols;
252 my %AllDocumentedSymbols;
254 # Undeclared yet documented symbols
255 my %UndeclaredSymbols;
257 # These global arrays store GObject, subclasses and the hierarchy.
258 my @Objects;
259 my @ObjectLevels;
261 my %Interfaces;
262 my %Prerequisites;
264 # holds the symbols which are mentioned in $MODULE-sections.txt and in which
265 # section they are defined
266 my %KnownSymbols;
267 my %SymbolSection;
268 my %SymbolSectionId;
270 # collects index entries
271 my %IndexEntriesFull;
272 my %IndexEntriesSince;
273 my %IndexEntriesDeprecated;
275 # Standard C preprocessor directives, which we ignore for '#' abbreviations.
276 my %PreProcessorDirectives;
277 $PreProcessorDirectives{"assert"} = 1;
278 $PreProcessorDirectives{"define"} = 1;
279 $PreProcessorDirectives{"elif"} = 1;
280 $PreProcessorDirectives{"else"} = 1;
281 $PreProcessorDirectives{"endif"} = 1;
282 $PreProcessorDirectives{"error"} = 1;
283 $PreProcessorDirectives{"if"} = 1;
284 $PreProcessorDirectives{"ifdef"} = 1;
285 $PreProcessorDirectives{"ifndef"} = 1;
286 $PreProcessorDirectives{"include"} = 1;
287 $PreProcessorDirectives{"line"} = 1;
288 $PreProcessorDirectives{"pragma"} = 1;
289 $PreProcessorDirectives{"unassert"} = 1;
290 $PreProcessorDirectives{"undef"} = 1;
291 $PreProcessorDirectives{"warning"} = 1;
293 # remember used annotation (to write minimal glossary)
294 my %AnnotationsUsed;
296 my %AnnotationDefinition = (
297     'allow-none' => "NULL is ok, both for passing and for returning.",
298     'array' => "Parameter points to an array of items.",
299     'default' => "Default parameter value (for in case the <acronym>shadows</acronym>-to function has less parameters).",
300     'element-type' => "Generics and defining elements of containers and arrays.",
301     'error-domains' => "Typed errors. Similar to throws in Java.",
302     'in' => "Parameter for input. Default is <acronym>transfer none</acronym>.",
303     'inout' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
304     'in-out' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
305     'not-error' => "A GError parameter is not to be handled like a normal GError.",
306     'out' => "Parameter for returning results. Default is <acronym>transfer full</acronym>.",
307     'transfer container' => "Free data container after the code is done.",
308     'transfer full' => "Free data after the code is done.",
309     'transfer none' => "Don't free data after the code is done.",
310     'scope call' => "The callback is valid only during the call to the method.",
311     'scope async' => "The callback is valid until first called.",
312     'scope notfied' => "The callback is valid until the GDestroyNotify argument is called."
315 # Create the root DocBook output directory if it doens't exist.
316 if (! -e $SGML_OUTPUT_DIR) {
317     mkdir ("$SGML_OUTPUT_DIR", 0777)
318         || die "Can't create directory: $SGML_OUTPUT_DIR";
321 # Function and other declaration output settings.
322 my $RETURN_TYPE_FIELD_WIDTH = 20;
323 my $SYMBOL_FIELD_WIDTH = 36;
324 my $SIGNAL_FIELD_WIDTH = 16;
325 my $PARAM_FIELD_COUNT = 2;
327 &ReadKnownSymbols ("$ROOT_DIR/$MODULE-sections.txt");
328 &ReadSignalsFile ($SIGNALS_FILE);
329 &ReadArgsFile ($ARGS_FILE);
330 &ReadObjectHierarchy;
331 &ReadInterfaces;
332 &ReadPrerequisites;
334 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-decl.txt", 0);
335 if (-f "$ROOT_DIR/$MODULE-overrides.txt") {
336     &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-overrides.txt", 1);
339 for my $dir (@SOURCE_DIRS) {
340     &ReadSourceDocumentation ($dir);
343 my $changed = &OutputSGML ("$ROOT_DIR/$MODULE-sections.txt");
345 # If any of the DocBook SGML files have changed, update the timestamp file (so
346 # it can be used for Makefile dependencies).
347 if ($changed || ! -e "$ROOT_DIR/sgml.stamp") {
349     # try to detect the common prefix
350     # GtkWidget, GTK_WIDGET, gtk_widget -> gtk
351     if ($NAME_SPACE eq "") {
352         $NAME_SPACE="";
353         my $pos=0;
354         my $ratio=0.0;
355         do {
356             my %prefix;
357             my $letter="";
358             foreach my $symbol (keys(%IndexEntriesFull)) {
359                 if(($NAME_SPACE eq "") || $symbol =~ /^$NAME_SPACE/i) {
360                     if (length($symbol)>$pos) {
361                         $letter=substr($symbol,$pos,1);
362                         # stop prefix scanning
363                         if ($letter eq "_") {
364                             # stop on "_"
365                             last;
366                         }
367                         # Should we also stop on a uppercase char, if last was lowercase
368                         #   GtkWidget, if we have the 'W' and had the 't' before
369                         # or should we count upper and lowercase, and stop one 2nd uppercase, if we already had a lowercase
370                         #   GtkWidget, the 'W' would be the 2nd uppercase and with 't','k' we had lowercase chars before
371                         # need to recound each time as this is per symbol
372                         $prefix{uc($letter)}++;
373                     }
374                 }
375             }
376             if ($letter ne "" && $letter ne "_") {
377                 my $maxletter="";
378                 my $maxsymbols=0;
379                 foreach $letter (keys(%prefix)) {
380                     #print "$letter: $prefix{$letter}.\n";
381                     if ($prefix{$letter}>$maxsymbols) {
382                         $maxletter=$letter;
383                         $maxsymbols=$prefix{$letter};
384                     }
385                 }
386                 $ratio = scalar(keys(%IndexEntriesFull)) / $prefix{$maxletter};
387                 #print "most symbols start with $maxletter, that is ". (100 * $ratio) ." %\n";
388                 if ($ratio > 0.9) {
389                     # do another round
390                     $NAME_SPACE .= $maxletter;
391                 }
392                 $pos++;
393             }
394             else {
395                 $ratio=0.0;
396             }
397         } while ($ratio > 0.9);
398         #print "most symbols start with $NAME_SPACE\n";
399     }
401     &OutputIndexFull;
402     &OutputDeprecatedIndex;
403     &OutputSinceIndexes;
404     &OutputAnnotationGlossary;
406     open (TIMESTAMP, ">$ROOT_DIR/sgml.stamp")
407         || die "Can't create $ROOT_DIR/sgml.stamp: $!";
408     print (TIMESTAMP "timestamp");
409     close (TIMESTAMP);
412 #############################################################################
413 # Function    : OutputObjectList
414 # Description : This outputs the alphabetical list of objects, in a columned
415 #               table.
416 #               FIXME: Currently this also outputs ancestor objects
417 #               which may not actually be in this module.
418 # Arguments   : none
419 #############################################################################
421 sub OutputObjectList {
422     my $cols = 3;
423     
424     # FIXME: use $OUTPUT_FORMAT
425     # my $old_object_index = "$SGML_OUTPUT_DIR/object_index.$OUTPUT_FORMAT";
426     my $old_object_index = "$SGML_OUTPUT_DIR/object_index.sgml";
427     my $new_object_index = "$SGML_OUTPUT_DIR/object_index.new";
429     open (OUTPUT, ">$new_object_index")
430         || die "Can't create $new_object_index: $!";
432     if ($OUTPUT_FORMAT eq "xml") {
433         my $header = $doctype_header;
435         $header =~ s/<!DOCTYPE \w+/<!DOCTYPE informaltable/;
436         print (OUTPUT "$header");
437     }
439     print (OUTPUT <<EOF);
440 <informaltable pgwide="1" frame="none">
441 <tgroup cols="$cols">
442 <colspec colwidth="1*"${empty_element_end}
443 <colspec colwidth="1*"${empty_element_end}
444 <colspec colwidth="1*"${empty_element_end}
445 <tbody>
448     my $count = 0;
449     my $object;
450     foreach $object (sort (@Objects)) {
451         my $xref = &MakeXRef ($object);
452         if ($count % $cols == 0) { print (OUTPUT "<row>\n"); }
453         print (OUTPUT "<entry>$xref</entry>\n");
454         if ($count % $cols == ($cols - 1)) { print (OUTPUT "</row>\n"); }
455         $count++;
456     }
457     if ($count == 0) {
458         # emit an empty row, since empty tables are invalid
459         print (OUTPUT "<row><entry> </entry></row>\n");
460     }
461     else {
462         if ($count % $cols > 0) {
463             print (OUTPUT "</row>\n");
464         }
465     }
467     print (OUTPUT <<EOF);
468 </tbody></tgroup></informaltable>
470     close (OUTPUT);
472     &UpdateFileIfChanged ($old_object_index, $new_object_index, 0);
476 #############################################################################
477 # Function    : OutputSGML
478 # Description : This collects the output for each section of the docs, and
479 #               outputs each file when the end of the section is found.
480 # Arguments   : $file - the $MODULE-sections.txt file which contains all of
481 #               the functions/macros/structs etc. being documented, organised
482 #               into sections and subsections.
483 #############################################################################
485 sub OutputSGML {
486     my ($file) = @_;
488     #print "Reading: $file\n";
489     open (INPUT, $file)
490         || die "Can't open $file: $!";
491     my $filename = "";
492     my $book_top = "";
493     my $book_bottom = "";
494     my $includes = (defined $DEFAULT_INCLUDES) ? $DEFAULT_INCLUDES : "";
495     my $section_includes = "";
496     my $in_section = 0;
497     my $title = "";
498     my $section_id = "";
499     my $subsection = "";
500     my $synopsis;
501     my $details;
502     my $num_symbols;
503     my $changed = 0;
504     my $signals_synop = "";
505     my $signals_desc = "";
506     my $args_synop = "";
507     my $child_args_synop = "";
508     my $style_args_synop = "";
509     my $args_desc = "";
510     my $child_args_desc = "";
511     my $style_args_desc = "";
512     my $hierarchy = "";
513     my $interfaces = "";
514     my $implementations = "";
515     my $prerequisites = "";
516     my $derived = "";
517     my @file_objects = ();
518     my %templates = ();
519     my %symbol_def_line = ();
521     # merge the source docs, in case there are no templates
522     &MergeSourceDocumentation;
524     while (<INPUT>) {
525         if (m/^#/) {
526             next;
528         } elsif (m/^<SECTION>/) {
529             $synopsis = "";
530             $details = "";
531             $num_symbols = 0;
532             $in_section = 1;
533             @file_objects = ();
534             %symbol_def_line = ();
536         } elsif (m/^<SUBSECTION\s*(.*)>/i) {
537             $synopsis .= "\n";
538             $subsection = $1;
540         } elsif (m/^<SUBSECTION>/) {
542         } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
543             $title = $1;
544             #print "Section: $title\n";
546             # We don't want warnings if object & class structs aren't used.
547             $DeclarationOutput{$title} = 1;
548             $DeclarationOutput{"${title}Class"} = 1;
549             $DeclarationOutput{"${title}Iface"} = 1;
550             $DeclarationOutput{"${title}Interface"} = 1;
552         } elsif (m/^<FILE>(.*)<\/FILE>/) {
553             $filename = $1;
554             if (! defined $templates{$filename}) {
555                if (&ReadTemplateFile ("$TMPL_DIR/$filename", 1)) {
556                    &MergeSourceDocumentation;
557                    $templates{$filename}=$.;
558                }
559             } else {
560                 &LogWarning ($file, $., "Double <FILE>$filename</FILE> entry. ".
561                     "Previous occurrence on line ".$templates{$filename}.".");
562             }
563             if (($title eq "") and (defined $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"})) {
564                 $title = $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"};
565                 # Remove trailing blanks
566                 $title =~ s/\s+$//;
567            }
569         } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
570             if ($in_section) {
571                 $section_includes = $1;
572             } else {
573                 if (defined $DEFAULT_INCLUDES) {
574                     &LogWarning ($file, $., "Default <INCLUDE> being overridden by command line option.");
575                 }
576                 else {
577                     $includes = $1;
578                 }
579             }
581         } elsif (m/^<\/SECTION>/) {
582             #print "End of section: $title\n";
583             if ($num_symbols > 0) {
584                 # collect documents
585                 if ($OUTPUT_FORMAT eq "xml") {
586                     $book_bottom .= "    <xi:include href=\"xml/$filename.xml\"/>\n";
587                 } else {
588                     $book_top.="<!ENTITY $section_id SYSTEM \"sgml/$filename.sgml\">\n";
589                     $book_bottom .= "    &$section_id;\n";
590                 }
592                 if (defined ($SourceSymbolDocs{"$TMPL_DIR/$filename:Include"})) {
593                     if ($section_includes) {
594                         &LogWarning ($file, $., "Section <INCLUDE> being overridden by inline comments.");
595                     }
596                     $section_includes = $SourceSymbolDocs{"$TMPL_DIR/$filename:Include"};
597                 }
598                 if ($section_includes eq "") {
599                     $section_includes = $includes;
600                 }
602                  $signals_synop =~ s/^\n*//g;
603                  $signals_synop =~ s/\n+$/\n/g;
604                 if ($signals_synop ne '') {
605                     $signals_synop = <<EOF;
606 <refsect1 id="$section_id.signals" role="signal_proto">
607 <title role="signal_proto.title">Signals</title>
608 <synopsis>
609 ${signals_synop}</synopsis>
610 </refsect1>
612                      $signals_desc =~ s/^\n*//g;
613                      $signals_desc =~ s/\n+$/\n/g;
614                      $signals_desc =~ s/(\s|\n)+$//ms;
615                     $signals_desc  = <<EOF;
616 <refsect1 id="$section_id.signal-details" role="signals">
617 <title role="signals.title">Signal Details</title>
618 $signals_desc
619 </refsect1>
621                 }
623                  $args_synop =~ s/^\n*//g;
624                  $args_synop =~ s/\n+$/\n/g;
625                 if ($args_synop ne '') {
626                     $args_synop = <<EOF;
627 <refsect1 id="$section_id.properties" role="properties">
628 <title role="properties.title">Properties</title>
629 <synopsis>
630 ${args_synop}</synopsis>
631 </refsect1>
633                      $args_desc =~ s/^\n*//g;
634                      $args_desc =~ s/\n+$/\n/g;
635                      $args_desc =~ s/(\s|\n)+$//ms;
636                     $args_desc  = <<EOF;
637 <refsect1 id="$section_id.property-details" role="property_details">
638 <title role="property_details.title">Property Details</title>
639 $args_desc
640 </refsect1>
642                 }
644                  $child_args_synop =~ s/^\n*//g;
645                  $child_args_synop =~ s/\n+$/\n/g;
646                 if ($child_args_synop ne '') {
647                     $args_synop .= <<EOF;
648 <refsect1 id="$section_id.child-properties" role="child_properties">
649 <title role="child_properties.title">Child Properties</title>
650 <synopsis>
651 ${child_args_synop}</synopsis>
652 </refsect1>
654                      $child_args_desc =~ s/^\n*//g;
655                      $child_args_desc =~ s/\n+$/\n/g;
656                      $child_args_desc =~ s/(\s|\n)+$//ms;
657                     $args_desc .= <<EOF;
658 <refsect1 id="$section_id.child-property-details" role="child_property_details">
659 <title role="child_property_details.title">Child Property Details</title>
660 $child_args_desc
661 </refsect1>
663                 }
665                  $style_args_synop =~ s/^\n*//g;
666                  $style_args_synop =~ s/\n+$/\n/g;
667                 if ($style_args_synop ne '') {
668                     $args_synop .= <<EOF;
669 <refsect1 id="$section_id.style-properties" role="style_properties">
670 <title role="style_properties.title">Style Properties</title>
671 <synopsis>
672 ${style_args_synop}</synopsis>
673 </refsect1>
675                      $style_args_desc =~ s/^\n*//g;
676                      $style_args_desc =~ s/\n+$/\n/g;
677                      $style_args_desc =~ s/(\s|\n)+$//ms;
678                     $args_desc .= <<EOF;
679 <refsect1 id="$section_id.style-property-details" role="style_properties_details">
680 <title role="style_properties_details.title">Style Property Details</title>
681 $style_args_desc
682 </refsect1>
684                 }
686                  $hierarchy =~ s/^\n*//g;
687                  $hierarchy =~ s/\n+$/\n/g;
688                  $hierarchy =~ s/(\s|\n)+$//ms;
689                 if ($hierarchy ne "") {
690                     $hierarchy = <<EOF;
691 <refsect1 id="$section_id.object-hierarchy" role="object_hierarchy">
692 <title role="object_hierarchy.title">Object Hierarchy</title>
693 $hierarchy
694 </refsect1>
696                 }
698                  $interfaces =~ s/^\n*//g;
699                  $interfaces =~ s/\n+$/\n/g;
700                  $interfaces =~ s/(\s|\n)+$//ms;
701                 if ($interfaces ne "") {
702                     $interfaces = <<EOF;
703 <refsect1 id="$section_id.implemented-interfaces" role="impl_interfaces">
704 <title role="impl_interfaces.title">Implemented Interfaces</title>
705 $interfaces
706 </refsect1>
708                 }
710                  $implementations =~ s/^\n*//g;
711                  $implementations =~ s/\n+$/\n/g;
712                  $implementations =~ s/(\s|\n)+$//ms;
713                 if ($implementations ne "") {
714                     $implementations = <<EOF;
715 <refsect1 id="$section_id.implementations" role="implementations">
716 <title role="implementations.title">Known Implementations</title>
717 $implementations
718 </refsect1>
720                 }
722                  $prerequisites =~ s/^\n*//g;
723                  $prerequisites =~ s/\n+$/\n/g;
724                  $prerequisites =~ s/(\s|\n)+$//ms;
725                 if ($prerequisites ne "") {
726                     $prerequisites = <<EOF;
727 <refsect1 id="$section_id.prerequisites" role="prerequisites">
728 <title role="prerequisites.title">Prerequisites</title>
729 $prerequisites
730 </refsect1>
732                 }
734                  $derived =~ s/^\n*//g;
735                  $derived =~ s/\n+$/\n/g;
736                  $derived =~ s/(\s|\n)+$//ms;
737                 if ($derived ne "") {
738                     $derived = <<EOF;
739 <refsect1 id="$section_id.derived-interfaces" role="derived_interfaces">
740 <title role="derived_interfaces.title">Known Derived Interfaces</title>
741 $derived
742 </refsect1>
744                 }
746                 $synopsis =~ s/^\n*//g;
747                 $synopsis =~ s/\n+$/\n/g;
748                 my $file_changed = &OutputSGMLFile ($filename, $title, $section_id,
749                                                     $section_includes,
750                                                     \$synopsis, \$details,
751                                                     \$signals_synop, \$signals_desc,
752                                                     \$args_synop, \$args_desc,
753                                                     \$hierarchy, \$interfaces,
754                                                     \$implementations,
755                                                     \$prerequisites, \$derived,
756                                                     \@file_objects);
757                 if ($file_changed) {
758                     $changed = 1;
759                 }
760             }
761             $title = "";
762             $section_id = "";
763             $subsection = "";
764             $in_section = 0;
765             $section_includes = "";
766             $signals_synop = "";
767             $signals_desc = "";
768             $args_synop = "";
769             $child_args_synop = "";
770             $style_args_synop = "";
771             $args_desc = "";
772             $child_args_desc = "";
773             $style_args_desc = "";
774             $hierarchy = "";
775             $interfaces = "";
776             $implementations = "";
777             $prerequisites = "";
778             $derived = "";
780         } elsif (m/^(\S+)/) {
781             my $symbol = $1;
782             #print "  Symbol: $symbol\n";
784             # check for duplicate entries
785             if (! defined $symbol_def_line{$symbol}) {
786                 my $declaration = $Declarations{$symbol};
787                 if (defined ($declaration)) {
788                     # We don't want standard macros/functions of GObjects,
789                     # or private declarations.
790                     if ($subsection ne "Standard" && $subsection ne "Private") {
791                         if (&CheckIsObject ($symbol)) {
792                             push @file_objects, $symbol;
793                         }
794                         my ($synop, $desc) = &OutputDeclaration ($symbol,
795                                                                  $declaration);
796                         my ($sig_synop, $sig_desc) = &GetSignals ($symbol);
797                         my ($arg_synop, $child_arg_synop, $style_arg_synop,
798                             $arg_desc, $child_arg_desc, $style_arg_desc) = &GetArgs ($symbol);
799                         my $hier = &GetHierarchy ($symbol);
800                         my $ifaces = &GetInterfaces ($symbol);
801                         my $impls = &GetImplementations ($symbol);
802                         my $prereqs = &GetPrerequisites ($symbol);
803                         my $der = &GetDerived ($symbol);
804                         $synopsis .= $synop;
805                         $details .= $desc;
806                         $signals_synop .= $sig_synop;
807                         $signals_desc .= $sig_desc;
808                         $args_synop .= $arg_synop;
809                         $child_args_synop .= $child_arg_synop;
810                         $style_args_synop .= $style_arg_synop;
811                         $args_desc .= $arg_desc;
812                         $child_args_desc .= $child_arg_desc;
813                         $style_args_desc .= $style_arg_desc;
814                         $hierarchy .= $hier;
815                         $interfaces .= $ifaces;
816                         $implementations .= $impls;
817                         $prerequisites .= $prereqs;
818                         $derived .= $der;
819                     }
820     
821                     # Note that the declaration has been output.
822                     $DeclarationOutput{$symbol} = 1;
823                 } elsif ($subsection ne "Standard" && $subsection ne "Private") {
824                     $UndeclaredSymbols{$symbol} = 1;
825                     &LogWarning ($file, $., "No declaration found for $symbol.");
826                 }
827                 $num_symbols++;
828                 $symbol_def_line{$symbol}=$.;
830                 if ($section_id eq "") {
831                     if($title eq "" && $filename eq "") {
832                         &LogWarning ($file, $., "Section has no title and no file.");
833                     }
834                     # FIXME: one of those would be enough
835                     # filename should be an internal detail for gtk-doc
836                     if ($title eq "") {
837                         $title = $filename;
838                     } elsif ($filename eq "") {
839                         $filename = $title;
840                     }
841                     $filename =~ s/\s/_/g;
842         
843                     $section_id = $SourceSymbolDocs{"$TMPL_DIR/$filename:Section_Id"};
844                     if (defined ($section_id) && $section_id !~ m/^\s*$/) {
845                         # Remove trailing blanks and use as is
846                         $section_id =~ s/\s+$//;
847                     } elsif (&CheckIsObject ($title)) {
848                         # GObjects use their class name as the ID.
849                         $section_id = &CreateValidSGMLID ($title);
850                     } else {
851                         $section_id = &CreateValidSGMLID ("$MODULE-$title");
852                     }
853                 }
854                 $SymbolSection{$symbol}=$title;
855                 $SymbolSectionId{$symbol}=$section_id;
856             }
857             else {
858                 &LogWarning ($file, $., "Double symbol entry for $symbol. ".
859                     "Previous occurrence on line ".$symbol_def_line{$symbol}.".");
860             }
861         }
862     }
863     close (INPUT);
865     &OutputMissingDocumentation;
866     &OutputUndeclaredSymbols;
867     &OutputUnusedSymbols;
869     if ($OUTPUT_ALL_SYMBOLS) {
870         &OutputAllSymbols;
871     }
872     if ($OUTPUT_SYMBOLS_WITHOUT_SINCE) {
873         &OutputSymbolsWithoutSince;
874     }
876     for $filename (split (' ', $EXPAND_CONTENT_FILES)) {
877         my $file_changed = &OutputExtraFile ($filename);
878         if ($file_changed) {
879             $changed = 1;
880         }
881     }
883     &OutputBook ($book_top, $book_bottom);
885     return $changed;
888 #############################################################################
889 # Function    : OutputIndex
890 # Description : This writes an indexlist that can be included into the main-
891 #               document into an <index> tag.
892 #############################################################################
894 sub OutputIndex {
895     my ($basename, $apiindexref ) = @_;
896     my %apiindex = %{$apiindexref};
897     my $old_index = "$SGML_OUTPUT_DIR/$basename.xml";
898     my $new_index = "$SGML_OUTPUT_DIR/$basename.new";
899     my $lastletter = " ";
900     my $divopen = 0;
901     my $symbol;
902     my $short_symbol;
904     open (OUTPUT, ">$new_index")
905         || die "Can't create $new_index";
907     my $header = $doctype_header;
908     $header =~ s/<!DOCTYPE \w+/<!DOCTYPE indexdiv/;
910     print (OUTPUT "$header<indexdiv>\n");
912     #print "generate $basename index (".%apiindex." entries)\n";
913     
914     # do a case insensitive sort while chopping off the prefix
915     foreach my $hash (
916         sort { $$a{criteria} cmp $$b{criteria} }
917         map { my $x = uc($_); $x =~ s/^$NAME_SPACE\_?(.*)/$1/i; { criteria => $x, original => $_, short => $1 } } 
918         keys %apiindex) {
920         $symbol = $$hash{original};
921         if (defined($$hash{short})) {
922             $short_symbol = $$hash{short};
923         } else {
924             $short_symbol = $symbol;
925         }
927         # generate a short symbol description
928         my $symbol_desc = "";
929         my $symbol_section = "";
930         my $symbol_section_id = "";
931         my $symbol_type = lc($DeclarationTypes{$symbol});
932         if ($symbol_type eq "") {
933             #print "trying symbol $symbol\n";
934             if ($symbol =~ m/(.*)::(.*)/) {
935                 my $oname = $1;
936                 my $osym = $2;
937                 my $i;
938                 #print "  trying object signal ${oname}:$osym in ".$#SignalNames." signals\n";
939                 for ($i = 0; $i <= $#SignalNames; $i++) {
940                     if ($SignalNames[$i] eq $osym) {
941                         $symbol_type = "object signal";
942                         if (defined($SymbolSection{$oname})) {
943                            $symbol_section = $SymbolSection{$oname};
944                            $symbol_section_id = $SymbolSectionId{$oname};
945                         }
946                         last;
947                     }
948                 }
949             } elsif ($symbol =~ m/(.*):(.*)/) {
950                 my $oname = $1;
951                 my $osym = $2;
952                 my $i;
953                 #print "  trying object property ${oname}::$osym in ".$#ArgNames." properties\n";
954                 for ($i = 0; $i <= $#ArgNames; $i++) {
955                     #print "    ".$ArgNames[$i]."\n";
956                     if ($ArgNames[$i] eq $osym) {
957                         $symbol_type = "object property";
958                         if (defined($SymbolSection{$oname})) {
959                            $symbol_section = $SymbolSection{$oname};
960                            $symbol_section_id = $SymbolSectionId{$oname};
961                         }
962                         last;
963                     }
964                 }
965             }
966         } else {
967            if (defined($SymbolSection{$symbol})) {
968                $symbol_section = $SymbolSection{$symbol};
969                $symbol_section_id = $SymbolSectionId{$symbol};
970            }
971         }
972         if ($symbol_type ne "") {
973            $symbol_desc=", $symbol_type";
974            if ($symbol_section ne "") {
975                $symbol_desc.=" in <link linkend=\"$symbol_section_id\">$symbol_section</link>";
976                #$symbol_desc.=" in ". &ExpandAbbreviations($symbol, "#$symbol_section");
977            }
978         }
980         my $curletter = uc(substr($short_symbol,0,1));
981         my $id = $apiindex{$symbol};
983         #print "  add symbol $symbol with $id to index in section $curletter\n";
985         if ($curletter ne $lastletter) {
986             $lastletter = $curletter;
988             if ($divopen == 1) {
989                 print (OUTPUT "</indexdiv>\n");
990             }
991             print (OUTPUT "<indexdiv><title>$curletter</title>\n");
992             $divopen = 1;
993         }
995         print (OUTPUT <<EOF);
996 <indexentry><primaryie linkends="$id"><link linkend="$id">$symbol</link>$symbol_desc</primaryie></indexentry>
998     }
1000     if ($divopen == 1) {
1001         print (OUTPUT "</indexdiv>\n");
1002     }
1003     print (OUTPUT "</indexdiv>\n");
1004     close (OUTPUT);
1006     &UpdateFileIfChanged ($old_index, $new_index, 0);
1010 #############################################################################
1011 # Function    : OutputIndexFull
1012 # Description : This writes the full api indexlist that can be included into the
1013 #               main document into an <index> tag.
1014 #############################################################################
1016 sub OutputIndexFull {
1017     &OutputIndex ("api-index-full", \%IndexEntriesFull);
1021 #############################################################################
1022 # Function    : OutputDeprecatedIndex
1023 # Description : This writes the deprecated api indexlist that can be included
1024 #               into the main document into an <index> tag.
1025 #############################################################################
1027 sub OutputDeprecatedIndex {
1028     &OutputIndex ("api-index-deprecated", \%IndexEntriesDeprecated);
1032 #############################################################################
1033 # Function    : OutputSinceIndexes
1034 # Description : This writes the 'since' api indexlists that can be included into
1035 #               the main document into an <index> tag.
1036 #############################################################################
1038 sub OutputSinceIndexes {
1039     my @sinces = keys %{{ map { $_ => 1 } values %Since }};
1041     foreach my $version (@sinces) {
1042         #print "Since : [$version]\n";
1043         # TODO make filtered hash
1044         #my %index = grep { $Since{$_} eq $version } %IndexEntriesSince;
1045         my %index = map { $_ => $IndexEntriesSince{$_} } grep { $Since{$_} eq $version } keys %IndexEntriesSince;
1047         &OutputIndex ("api-index-$version", \%index);
1048     }
1051 #############################################################################
1052 # Function    : OutputAnnotationGlossary
1053 # Description : This writes a glossary of the used annotation terms into a
1054 #               separate glossary file that can be included into the main
1055 #               document.
1056 #############################################################################
1058 sub OutputAnnotationGlossary {
1059     my $old_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.xml";
1060     my $new_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.new";
1061     my $lastletter = " ";
1062     my $divopen = 0;
1064     # if there are no annotations used return
1065     return if (! keys(%AnnotationsUsed));
1067     # add acronyms that are referenced from acronym text
1068 rerun:
1069     foreach my $annotation (keys(%AnnotationsUsed)) {
1070         if($AnnotationDefinition{$annotation} =~ m/<acronym>([\w ]+)<\/acronym>/) {
1071             if (!exists($AnnotationsUsed{$1})) {
1072                 $AnnotationsUsed{$1} = 1;
1073                 goto rerun;
1074             }
1075         }
1076     }
1078     open (OUTPUT, ">$new_glossary")
1079         || die "Can't create $new_glossary";
1081     my $header = $doctype_header;
1082     $header =~ s/<!DOCTYPE \w+/<!DOCTYPE glossary/;
1084     print (OUTPUT  <<EOF);
1085 $header
1086 <glossary id="annotation-glossary">
1087   <title>Annotation Glossary</title>
1090     foreach my $annotation (keys(%AnnotationsUsed)) {
1091         my $def = $AnnotationDefinition{$annotation};
1092         my $curletter = uc(substr($annotation,0,1));
1094         if ($curletter ne $lastletter) {
1095             $lastletter = $curletter;
1096       
1097             if ($divopen == 1) {
1098                 print (OUTPUT "</glossdiv>\n");
1099             }
1100             print (OUTPUT "<glossdiv><title>$curletter</title>\n");
1101             $divopen = 1;
1102         }
1103         print (OUTPUT <<EOF);
1104     <glossentry>
1105       <glossterm><anchor id="annotation-glossterm-$annotation"/>$annotation</glossterm>
1106       <glossdef>
1107         <para>$def</para>
1108       </glossdef>
1109     </glossentry>
1111     }
1113     if ($divopen == 1) {
1114         print (OUTPUT "</glossdiv>\n");
1115     }
1116     print (OUTPUT "</glossary>\n");
1117     close (OUTPUT);
1119     &UpdateFileIfChanged ($old_glossary, $new_glossary, 0);
1122 #############################################################################
1123 # Function    : ReadKnownSymbols
1124 # Description : This collects the names of non-private symbols from the
1125 #               $MODULE-sections.txt file.
1126 # Arguments   : $file - the $MODULE-sections.txt file which contains all of
1127 #               the functions/macros/structs etc. being documented, organised
1128 #               into sections and subsections.
1129 #############################################################################
1131 sub ReadKnownSymbols {
1132     my ($file) = @_;
1134     my $subsection = "";
1136     #print "Reading: $file\n";
1137     open (INPUT, $file)
1138         || die "Can't open $file: $!";
1140     while (<INPUT>) {
1141         if (m/^#/) {
1142             next;
1144         } elsif (m/^<SECTION>/) {
1145             $subsection = "";
1147         } elsif (m/^<SUBSECTION\s*(.*)>/i) {
1148             $subsection = $1;
1150         } elsif (m/^<SUBSECTION>/) {
1151             next;
1153         } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
1154             next;
1156         } elsif (m/^<FILE>(.*)<\/FILE>/) {
1157             $KnownSymbols{"$TMPL_DIR/$1:Long_Description"} = 1;
1158             $KnownSymbols{"$TMPL_DIR/$1:Short_Description"} = 1;
1159             next;
1161         } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
1162             next;
1164         } elsif (m/^<\/SECTION>/) {
1165             next;
1167         } elsif (m/^(\S+)/) {
1168             my $symbol = $1;
1170             if ($subsection ne "Standard" && $subsection ne "Private") {
1171                 $KnownSymbols{$symbol} = 1;
1172             }
1173             else {
1174                 $KnownSymbols{$symbol} = 0;
1175             }
1176         }
1177     }
1178     close (INPUT);
1182 #############################################################################
1183 # Function    : OutputDeclaration
1184 # Description : Returns the synopsis and detailed description DocBook
1185 #               describing one function/macro etc.
1186 # Arguments   : $symbol - the name of the function/macro begin described.
1187 #               $declaration - the declaration of the function/macro.
1188 #############################################################################
1190 sub OutputDeclaration {
1191     my ($symbol, $declaration) = @_;
1193     my $type = $DeclarationTypes {$symbol};
1194     if ($type eq 'MACRO') {
1195         return &OutputMacro ($symbol, $declaration);
1196     } elsif ($type eq 'TYPEDEF') {
1197         return &OutputTypedef ($symbol, $declaration);
1198     } elsif ($type eq 'STRUCT') {
1199         return &OutputStruct ($symbol, $declaration);
1200     } elsif ($type eq 'ENUM') {
1201         return &OutputEnum ($symbol, $declaration);
1202     } elsif ($type eq 'UNION') {
1203         return &OutputUnion ($symbol, $declaration);
1204     } elsif ($type eq 'VARIABLE') {
1205         return &OutputVariable ($symbol, $declaration);
1206     } elsif ($type eq 'FUNCTION') {
1207         return &OutputFunction ($symbol, $declaration, $type);
1208     } elsif ($type eq 'USER_FUNCTION') {
1209         return &OutputFunction ($symbol, $declaration, $type);
1210     } else {
1211         die "Unknown symbol type";
1212     }
1216 #############################################################################
1217 # Function    : OutputSymbolTraits
1218 # Description : Returns the Since and StabilityLevel paragraphs for a symbol.
1219 # Arguments   : $symbol - the name of the function/macro begin described.
1220 #############################################################################
1222 sub OutputSymbolTraits {
1223     my ($symbol) = @_;
1224     my $desc = "";
1226     if (exists $Since{$symbol}) {
1227         $desc .= "<para role=\"since\">Since $Since{$symbol}</para>";
1228     }
1229     if (exists $StabilityLevel{$symbol}) {
1230         $desc .= "<para role=\"stability\">Stability Level: $StabilityLevel{$symbol}</para>";
1231     }
1232     return $desc;
1235 #############################################################################
1236 # Function    : Outpu{Symbol,Section}ExtraLinks
1237 # Description : Returns extralinks for the symbol (if enabled).
1238 # Arguments   : $symbol - the name of the function/macro begin described.
1239 #############################################################################
1241 sub uri_escape {
1242     my $text = $_[0];
1243     return undef unless defined $text;
1245     # Build a char to hex map
1246     my %escapes = ();
1247     for (0..255) {
1248             $escapes{chr($_)} = sprintf("%%%02X", $_);
1249     }
1251     # Default unsafe characters.  RFC 2732 ^(uric - reserved)
1252     $text =~ s/([^A-Za-z0-9\-_.!~*'()])/$escapes{$1}/g;
1254     return $text;
1257 sub OutputSymbolExtraLinks {
1258     my ($symbol) = @_;
1259     my $desc = "";
1261     if (0) { # NEW FEATURE: needs configurability
1262     my $sstr = &uri_escape($symbol);
1263     my $mstr = &uri_escape($MODULE);
1264     $desc .= <<EOF;
1265 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1266 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&amp;symbol=$sstr">edit documentation</ulink>
1268     }
1269     return $desc;
1272 sub OutputSectionExtraLinks {
1273     my ($symbol,$docsymbol) = @_;
1274     my $desc = "";
1276     if (0) { # NEW FEATURE: needs configurability
1277     my $sstr = &uri_escape($symbol);
1278     my $mstr = &uri_escape($MODULE);
1279     my $dsstr = &uri_escape($docsymbol);
1280     $desc .= <<EOF;
1281 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1282 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&amp;symbol=$dsstr">edit documentation</ulink>
1284     }
1285     return $desc;
1289 #############################################################################
1290 # Function    : OutputMacro
1291 # Description : Returns the synopsis and detailed description of a macro.
1292 # Arguments   : $symbol - the macro.
1293 #               $declaration - the declaration of the macro.
1294 #############################################################################
1296 sub OutputMacro {
1297     my ($symbol, $declaration) = @_;
1298     my $id = &CreateValidSGMLID ($symbol);
1299     my $condition = &MakeConditionDescription ($symbol);
1300     my $synop = &MakeReturnField("#define") . "<link linkend=\"$id\">$symbol</link>";
1301     my $desc;
1303     my @fields = ParseMacroDeclaration($declaration, \&CreateValidSGML);
1304     my $title = $symbol . (@fields ? "()" : "");
1306     $desc = "<refsect2 id=\"$id\" role=\"macro\"$condition>\n<title>$title</title>\n";
1307     $desc .= MakeIndexterms($symbol, $id);
1308     $desc .= "\n";
1309     $desc .= OutputSymbolExtraLinks($symbol);
1311     if (@fields) {
1312         if (length ($symbol) < $SYMBOL_FIELD_WIDTH) {
1313             $synop .= (' ' x ($SYMBOL_FIELD_WIDTH - length ($symbol)));
1314         }
1315     
1316         $synop .= "(";
1317         for (my $i = 1; $i <= $#fields; $i += 2) {
1318             my $field_name = $fields[$i];
1320             if ($i == 1) {
1321                 $synop .= "$field_name";
1322             } else {
1323                 $synop .= ",\n"
1324                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1325                     . " $field_name";
1326             }
1327         }
1328         $synop .= ")";
1329     }
1330     $synop .= "\n";
1332     # Don't output the macro definition if is is a conditional macro or it
1333     # looks like a function, i.e. starts with "g_" or "_?gnome_", or it is
1334     # longer than 2 lines, otherwise we get lots of complicated macros like
1335     # g_assert.
1336     if (!defined ($DeclarationConditional{$symbol}) && ($symbol !~ m/^g_/)
1337         && ($symbol !~ m/^_?gnome_/) && (($declaration =~ tr/\n//) < 2)) {
1338         my $decl_out = &CreateValidSGML ($declaration);
1339         $desc .= "<programlisting>$decl_out</programlisting>\n";
1340     } else {
1341         $desc .= "<programlisting>" . &MakeReturnField("#define") . "$symbol";
1342         if ($declaration =~ m/^\s*#\s*define\s+\w+(\([^\)]*\))/) {
1343             my $args = $1;
1344             my $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH - length ("#define "));
1345             # Align each line so that if should all line up OK.
1346             $args =~ s/\n/\n$pad/gm;
1347             $desc .= &CreateValidSGML ($args);
1348         }
1349         $desc .= "</programlisting>\n";
1350     }
1352     $desc .= &MakeDeprecationNote($symbol);
1354     my $parameters = &OutputParamDescriptions ("MACRO", $symbol, @fields);
1355     my $parameters_output = 0;
1357     if (defined ($SymbolDocs{$symbol})) {
1358         my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1360         # Try to insert the parameter table at the author's desired position.
1361         # Otherwise we need to tag it onto the end.
1362         if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1363           $parameters_output = 1;
1364         }
1365         $desc .= $symbol_docs;
1366     }
1368     if ($parameters_output == 0) {
1369         $desc .= $parameters;
1370     }
1372     $desc .= OutputSymbolTraits ($symbol);
1373     $desc .= "</refsect2>\n";
1374     return ($synop, $desc);
1378 #############################################################################
1379 # Function    : OutputTypedef
1380 # Description : Returns the synopsis and detailed description of a typedef.
1381 # Arguments   : $symbol - the typedef.
1382 #               $declaration - the declaration of the typedef,
1383 #                 e.g. 'typedef unsigned int guint;'
1384 #############################################################################
1386 sub OutputTypedef {
1387     my ($symbol, $declaration) = @_;
1388     my $id = &CreateValidSGMLID ($symbol);
1389     my $condition = &MakeConditionDescription ($symbol);
1390     my $synop = &MakeReturnField("typedef") . "<link linkend=\"$id\">$symbol</link>;\n";
1391     my $desc = "<refsect2 id=\"$id\" role=\"typedef\"$condition>\n<title>$symbol</title>\n";
1393     $desc .= MakeIndexterms($symbol, $id);
1394     $desc .= "\n";
1395     $desc .= OutputSymbolExtraLinks($symbol);
1397     if (!defined ($DeclarationConditional{$symbol})) {
1398         my $decl_out = &CreateValidSGML ($declaration);
1399         $desc .= "<programlisting>$decl_out</programlisting>\n";
1400     }
1402     $desc .= &MakeDeprecationNote($symbol);
1404     if (defined ($SymbolDocs{$symbol})) {
1405         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1406     }
1407     $desc .= OutputSymbolTraits ($symbol);
1408     $desc .= "</refsect2>\n";
1409     return ($synop, $desc);
1413 #############################################################################
1414 # Function    : OutputStruct
1415 # Description : Returns the synopsis and detailed description of a struct.
1416 #               We check if it is a object struct, and if so we only output
1417 #               parts of it that are noted as public fields.
1418 #               We also use a different SGML ID for object structs, since the
1419 #               original ID is used for the entire RefEntry.
1420 # Arguments   : $symbol - the struct.
1421 #               $declaration - the declaration of the struct.
1422 #############################################################################
1424 sub OutputStruct {
1425     my ($symbol, $declaration) = @_;
1427     my $is_object_struct = 0;
1428     my $default_to_public = 1;
1429     if (&CheckIsObject ($symbol)) {
1430         #print "Found object struct: $symbol\n";
1431         $is_object_struct = 1;
1432         $default_to_public = 0;
1433     }
1435     my $id;
1436     my $condition;
1437     if ($is_object_struct) {
1438         $id = &CreateValidSGMLID ($symbol . "_struct");
1439         $condition = &MakeConditionDescription ($symbol . "_struct");
1440     } else {
1441         $id = &CreateValidSGMLID ($symbol);
1442         $condition = &MakeConditionDescription ($symbol);
1443     }
1445     # Determine if it is a simple struct or it also has a typedef.
1446     my $has_typedef = 0;
1447     if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1448       $has_typedef = 1;
1449     }
1451     my $synop;
1452     my $desc;
1453     if ($has_typedef) {
1454         # For structs with typedefs we just output the struct name.
1455         $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1456         $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>$symbol</title>\n";
1457     } else {
1458         $synop = &MakeReturnField("struct") . "<link linkend=\"$id\">$symbol</link>;\n";
1459         $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>struct $symbol</title>\n";
1460     }
1462     $desc .= MakeIndexterms($symbol, $id);
1463     $desc .= "\n";
1464     $desc .= OutputSymbolExtraLinks($symbol);
1466     # Form a pretty-printed, private-data-removed form of the declaration
1468     my $decl_out = "";
1469     if ($declaration =~ m/^\s*$/) {
1470         #print "Found opaque struct: $symbol\n";
1471         $decl_out = "typedef struct _$symbol $symbol;";
1472     } elsif ($declaration =~ m/^\s*struct\s+\w+\s*;\s*$/) {
1473         #print "Found opaque struct: $symbol\n";
1474         $decl_out = "struct $symbol;";
1475     } else {
1476         my $public = $default_to_public;
1477         my $new_declaration = "";
1478         my $decl_line;
1479         my $decl = $declaration;
1481         if ($decl =~ m/^\s*(typedef\s+)?struct\s*\w*\s*(?:\/\*.*\*\/)?\s*{(.*)}\s*\w*\s*;\s*$/s) {
1482             my $struct_contents = $2;
1484             foreach $decl_line (split (/\n/, $struct_contents)) {
1485                 #print "Struct line: $decl_line\n";
1486                 if ($decl_line =~ m%/\*\s*<\s*public\s*>\s*\*/%) {
1487                     $public = 1;
1488                 } elsif ($decl_line =~ m%/\*\s*<\s*(private|protected)\s*>\s*\*/%) {
1489                     $public = 0;
1490                 } elsif ($public) {
1491                     $new_declaration .= $decl_line . "\n";
1492                 }
1493             }
1495             if ($new_declaration) {
1496                 # Strip any blank lines off the ends.
1497                 $new_declaration =~ s/^\s*\n//;
1498                 $new_declaration =~ s/\n\s*$/\n/;
1500                 if ($has_typedef) {
1501                     $decl_out = "typedef struct {\n" . $new_declaration
1502                       . "} $symbol;\n";
1503                 } else {
1504                     $decl_out = "struct $symbol {\n" . $new_declaration
1505                       . "};\n";
1506                 }
1507             }
1508         } else {
1509             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1510                 "Couldn't parse struct:\n$declaration");
1511         }
1513         # If we couldn't parse the struct or it was all private, output an
1514         # empty struct declaration.
1515         if ($decl_out eq "") {
1516             if ($has_typedef) {
1517                 $decl_out = "typedef struct _$symbol $symbol;";
1518             } else {
1519                 $decl_out = "struct $symbol;";
1520             }
1521         }
1522     }
1524     $decl_out = &CreateValidSGML ($decl_out);
1525     $desc .= "<programlisting>$decl_out</programlisting>\n";
1527     $desc .= &MakeDeprecationNote($symbol);
1529     if (defined ($SymbolDocs{$symbol})) {
1530         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1531     }
1533     # Create a table of fields and descriptions
1535     # FIXME: Inserting &#160's into the produced type declarations here would
1536     #        improve the output in most situations ... except for function
1537     #        members of structs!
1538     my @fields = ParseStructDeclaration($declaration, !$default_to_public,
1539                                         0, \&MakeXRef,
1540                                         sub {
1541                                             "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1542                                         });
1543     my $params = $SymbolParams{$symbol};
1545     # If no parameters are filled in, we don't generate the description
1546     # table, for backwards compatibility
1548     my $found = 0;
1549     if (defined $params) {
1550         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1551             if ($params->[$i] =~ /\S/) {
1552                 $found = 1;
1553                 last;
1554             }
1555         }
1556     }
1558     if ($found) {
1559         my %field_descrs = @$params;
1560         my $missing_parameters = "";
1561         my $unused_parameters = "";
1563         $desc .= "<variablelist role=\"struct\">\n";
1564         while (@fields) {
1565             my $field_name = shift @fields;
1566             my $text = shift @fields;
1567             my $field_descr = $field_descrs{$field_name};
1568             my $param_annotations = "";
1570             $desc .= "<varlistentry><term>$text</term>\n";
1571             if (defined $field_descr) {
1572                 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1573                 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1574                 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1575                 delete $field_descrs{$field_name};
1576             } else {
1577                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1578                     "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1579                 if ($missing_parameters ne "") {
1580                   $missing_parameters .= ", ".$field_name;
1581                 } else {
1582                     $missing_parameters = $field_name;
1583                 }
1584                 $desc .= "<listitem />\n";
1585             }
1586             $desc .= "</varlistentry>\n";
1587         }
1588         $desc .= "</variablelist>";
1589         foreach my $field_name (keys %field_descrs) {
1590             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1591                 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1592             if ($unused_parameters ne "") {
1593               $unused_parameters .= ", ".$field_name;
1594             } else {
1595                $unused_parameters = $field_name;
1596             }
1597         }
1599         # remember missing/unused parameters (needed in tmpl-free build)
1600         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1601             $AllIncompleteSymbols{$symbol}=$missing_parameters;
1602         }
1603         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1604             $AllUnusedSymbols{$symbol}=$unused_parameters;
1605         }
1606     }
1607     else {
1608         if (scalar(@fields) > 0) {
1609             if (! exists ($AllIncompleteSymbols{$symbol})) {
1610                 $AllIncompleteSymbols{$symbol}="<items>";
1611                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1612                     "Field descriptions for $symbol are missing in source code comment block.");
1613             }
1614         }
1615     }
1617     $desc .= OutputSymbolTraits ($symbol);
1618     $desc .= "</refsect2>\n";
1619     return ($synop, $desc);
1623 #############################################################################
1624 # Function    : OutputUnion
1625 # Description : Returns the synopsis and detailed description of a union.
1626 # Arguments   : $symbol - the union.
1627 #               $declaration - the declaration of the union.
1628 #############################################################################
1630 sub OutputUnion {
1631     my ($symbol, $declaration) = @_;
1632     my $id = &CreateValidSGMLID ($symbol);
1633     my $condition = &MakeConditionDescription ($symbol);
1635     # Determine if it is a simple struct or it also has a typedef.
1636     my $has_typedef = 0;
1637     if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1638       $has_typedef = 1;
1639     }
1641     my $synop;
1642     my $desc;
1643     if ($has_typedef) {
1644         # For unions with typedefs we just output the union name.
1645         $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1646         $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>$symbol</title>\n";
1647     } else {
1648         $synop = &MakeReturnField("union") . "<link linkend=\"$id\">$symbol</link>;\n";
1649         $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>union $symbol</title>\n";
1650     }
1652     $desc .= MakeIndexterms($symbol, $id);
1653     $desc .= "\n";
1654     $desc .= OutputSymbolExtraLinks($symbol);
1656     # FIXME: we do more for structs
1657     my $decl_out = &CreateValidSGML ($declaration);
1658     $desc .= "<programlisting>$decl_out</programlisting>\n";
1660     $desc .= &MakeDeprecationNote($symbol);
1662     if (defined ($SymbolDocs{$symbol})) {
1663         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1664     }
1666     # Create a table of fields and descriptions
1668     # FIXME: Inserting &#160's into the produced type declarations here would
1669     #        improve the output in most situations ... except for function
1670     #        members of structs!
1671     my @fields = ParseStructDeclaration($declaration, 0,
1672                                         0, \&MakeXRef,
1673                                         sub {
1674                                             "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1675                                         });
1676     my $params = $SymbolParams{$symbol};
1678     # If no parameters are filled in, we don't generate the description
1679     # table, for backwards compatibility
1681     my $found = 0;
1682     if (defined $params) {
1683         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1684             if ($params->[$i] =~ /\S/) {
1685                 $found = 1;
1686                 last;
1687             }
1688         }
1689     }
1691     if ($found) {
1692         my %field_descrs = @$params;
1693         my $missing_parameters = "";
1694         my $unused_parameters = "";
1696         $desc .= "<variablelist role=\"union\">\n";
1697         while (@fields) {
1698             my $field_name = shift @fields;
1699             my $text = shift @fields;
1700             my $field_descr = $field_descrs{$field_name};
1701             my $param_annotations = "";
1703             $desc .= "<varlistentry><term>$text</term>\n";
1704             if (defined $field_descr) {
1705                 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1706                 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1707                 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1708                 delete $field_descrs{$field_name};
1709             } else {
1710                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1711                     "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1712                 if ($missing_parameters ne "") {
1713                     $missing_parameters .= ", ".$field_name;
1714                 } else {
1715                     $missing_parameters = $field_name;
1716                 }
1717                 $desc .= "<listitem />\n";
1718             }
1719             $desc .= "</varlistentry>\n";
1720         }
1721         $desc .= "</variablelist>";
1722         foreach my $field_name (keys %field_descrs) {
1723             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1724                 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1725             if ($unused_parameters ne "") {
1726               $unused_parameters .= ", ".$field_name;
1727             } else {
1728                $unused_parameters = $field_name;
1729             }
1730         }
1732         # remember missing/unused parameters (needed in tmpl-free build)
1733         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1734             $AllIncompleteSymbols{$symbol}=$missing_parameters;
1735         }
1736         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1737             $AllUnusedSymbols{$symbol}=$unused_parameters;
1738         }
1739     }
1740     else {
1741         if (scalar(@fields) > 0) {
1742             if (! exists ($AllIncompleteSymbols{$symbol})) {
1743                 $AllIncompleteSymbols{$symbol}="<items>";
1744                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1745                     "Field descriptions for $symbol are missing in source code comment block.");
1746             }
1747         }
1748     }
1750     $desc .= OutputSymbolTraits ($symbol);
1751     $desc .= "</refsect2>\n";
1752     return ($synop, $desc);
1756 #############################################################################
1757 # Function    : OutputEnum
1758 # Description : Returns the synopsis and detailed description of a enum.
1759 # Arguments   : $symbol - the enum.
1760 #               $declaration - the declaration of the enum.
1761 #############################################################################
1763 sub OutputEnum {
1764     my ($symbol, $declaration) = @_;
1765     my $id = &CreateValidSGMLID ($symbol);
1766     my $condition = &MakeConditionDescription ($symbol);
1767     my $synop = &MakeReturnField("enum") . "<link linkend=\"$id\">$symbol</link>;\n";
1768     my $desc = "<refsect2 id=\"$id\" role=\"enum\"$condition>\n<title>enum $symbol</title>\n";
1770     $desc .= MakeIndexterms($symbol, $id);
1771     $desc .= "\n";
1772     $desc .= OutputSymbolExtraLinks($symbol);
1774     my $decl_out = &CreateValidSGML ($declaration);
1775     $desc .= "<programlisting>$decl_out</programlisting>\n";
1777     $desc .= &MakeDeprecationNote($symbol);
1779     if (defined ($SymbolDocs{$symbol})) {
1780         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1781     }
1783     # Create a table of fields and descriptions
1785     my @fields = ParseEnumDeclaration($declaration);
1786     my $params = $SymbolParams{$symbol};
1788     # If no parameters are filled in, we don't generate the description
1789     # table, for backwards compatibility
1791     my $found = 0;
1792     if (defined $params) {
1793         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1794             if ($params->[$i] =~ /\S/) {
1795                 $found = 1;
1796                 last;
1797             }
1798         }
1799     }
1801     if ($found) {
1802         my %field_descrs = @$params;
1803         my $missing_parameters = "";
1804         my $unused_parameters = "";
1806         $desc .= "<variablelist role=\"enum\">\n";
1807         for my $field_name (@fields) {
1808             my $field_descr = $field_descrs{$field_name};
1809             my $param_annotations = "";
1811             $id = &CreateValidSGMLID ($field_name);
1812             $condition = &MakeConditionDescription ($field_name);
1813             $desc .= "<varlistentry id=\"$id\" role=\"constant\"$condition>\n<term><literal>$field_name</literal></term>\n";
1814             if (defined $field_descr) {
1815                 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1816                 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1817                 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1818                 delete $field_descrs{$field_name};
1819             } else {
1820                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1821                     "Value description for $symbol"."::"."$field_name is missing in source code comment block.");
1822                 if ($missing_parameters ne "") {
1823                   $missing_parameters .= ", ".$field_name;
1824                 } else {
1825                     $missing_parameters = $field_name;
1826                 }
1827                 $desc .= "<listitem />\n";
1828             }
1829             $desc .= "</varlistentry>\n";
1830         }
1831         $desc .= "</variablelist>";
1832         foreach my $field_name (keys %field_descrs) {
1833             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1834                 "Value description for $symbol"."::"."$field_name is not used from source code comment block.");
1835             if ($unused_parameters ne "") {
1836               $unused_parameters .= ", ".$field_name;
1837             } else {
1838                $unused_parameters = $field_name;
1839             }
1840         }
1842         # remember missing/unused parameters (needed in tmpl-free build)
1843         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1844             $AllIncompleteSymbols{$symbol}=$missing_parameters;
1845         }
1846         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1847             $AllUnusedSymbols{$symbol}=$unused_parameters;
1848         }
1849     }
1850     else {
1851         if (scalar(@fields) > 0) {
1852             if (! exists ($AllIncompleteSymbols{$symbol})) {
1853                 $AllIncompleteSymbols{$symbol}="<items>";
1854                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1855                     "Value descriptions for $symbol are missing in source code comment block.");
1856             }
1857         }
1858     }
1860     $desc .= OutputSymbolTraits ($symbol);
1861     $desc .= "</refsect2>\n";
1862     return ($synop, $desc);
1866 #############################################################################
1867 # Function    : OutputVariable
1868 # Description : Returns the synopsis and detailed description of a variable.
1869 # Arguments   : $symbol - the extern'ed variable.
1870 #               $declaration - the declaration of the variable.
1871 #############################################################################
1873 sub OutputVariable {
1874     my ($symbol, $declaration) = @_;
1875     my $id = &CreateValidSGMLID ($symbol);
1876     my $condition = &MakeConditionDescription ($symbol);
1878     my $synop;
1879     if ($declaration =~ m/^\s*extern\s+((const\s+|signed\s+|unsigned\s+)*\w+)(\s+\*+|\*+|\s)(\s*)([A-Za-z]\w*)\s*;/) {
1880         my $mod = defined ($1) ? $1 : "";
1881         my $ptr = defined ($3) ? $3 : "";
1882         my $space = defined ($4) ? $4 : "";
1883         $synop = &MakeReturnField("extern") . "$mod$ptr$space<link linkend=\"$id\">$symbol</link>;\n";
1885     } else {
1886         $synop = &MakeReturnField("extern") . "<link linkend=\"$id\">$symbol</link>;\n";
1887     }
1889     my $desc = "<refsect2 id=\"$id\" role=\"variable\"$condition>\n<title>$symbol</title>\n";
1891     $desc .= MakeIndexterms($symbol, $id);
1892     $desc .= "\n";
1893     $desc .= OutputSymbolExtraLinks($symbol);
1895     my $decl_out = &CreateValidSGML ($declaration);
1896     $desc .= "<programlisting>$decl_out</programlisting>\n";
1898     $desc .= &MakeDeprecationNote($symbol);
1900     if (defined ($SymbolDocs{$symbol})) {
1901         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1902     }
1903     $desc .= OutputSymbolTraits ($symbol);
1904     $desc .= "</refsect2>\n";
1905     return ($synop, $desc);
1909 #############################################################################
1910 # Function    : OutputFunction
1911 # Description : Returns the synopsis and detailed description of a function.
1912 # Arguments   : $symbol - the function.
1913 #               $declaration - the declaration of the function.
1914 #############################################################################
1916 sub OutputFunction {
1917     my ($symbol, $declaration, $symbol_type) = @_;
1918     my $id = &CreateValidSGMLID ($symbol);
1919     my $condition = &MakeConditionDescription ($symbol);
1921     # Take out the return type     $1                                                                                     $3   $4
1922     $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//;
1923     my $type_modifier = defined($1) ? $1 : "";
1924     my $type = $3;
1925     my $pointer = $4;
1926     #print "$symbol pointer is $pointer\n";
1927     my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1928     my $start = "";
1929     #if ($symbol_type eq 'USER_FUNCTION') {
1930     #    $start = "typedef ";
1931     #}
1933     # We output const rather than G_CONST_RETURN.
1934     $type_modifier =~ s/G_CONST_RETURN/const/g;
1935     $pointer =~ s/G_CONST_RETURN/const/g;
1936     $pointer =~ s/^\s+/ /g;
1938     my $ret_type_len = length ($start) + length ($type_modifier)
1939         + length ($pointer) + length ($type);
1940     my $ret_type_output;
1941     my $symbol_len;
1942     if ($ret_type_len < $RETURN_TYPE_FIELD_WIDTH) {
1943         $ret_type_output = "$start$type_modifier$xref$pointer"
1944             . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
1945         $symbol_len = 0;
1946     } else {
1947         #$ret_type_output = "$start$type_modifier$xref$pointer\n" . (' ' x $RETURN_TYPE_FIELD_WIDTH);
1949         $ret_type_output = "$start$type_modifier$xref$pointer ";
1950         $symbol_len = $ret_type_len + 1 - $RETURN_TYPE_FIELD_WIDTH;
1951     }
1953     $symbol_len += length ($symbol);
1954     my $char1 = my $char2 = my $char3 = "";
1955     if ($symbol_type eq 'USER_FUNCTION') {
1956         $symbol_len += 3;
1957         $char1 = "(";
1958         $char2 = "*";
1959         $char3 = ")";
1960     }
1962     my ($symbol_output, $symbol_desc_output);
1963     if ($symbol_len < $SYMBOL_FIELD_WIDTH) {
1964         $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3"
1965             . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1966         $symbol_desc_output = "$char1$char2$symbol$char3"
1967             . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1968     } else {
1969         $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3\n"
1970             . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1971         $symbol_desc_output = "$char1$char2$symbol$char3\n"
1972             . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1973     }
1975     my $synop = $ret_type_output . $symbol_output . '(';
1976     my $desc = "<refsect2 id=\"$id\" role=\"function\"$condition>\n<title>${symbol} ()</title>\n";
1978     $desc .= MakeIndexterms($symbol, $id);
1979     $desc .= "\n";
1980     $desc .= OutputSymbolExtraLinks($symbol);
1982     $desc  .= "<programlisting>${ret_type_output}$symbol_desc_output(";
1983     
1984     my @fields = ParseFunctionDeclaration($declaration, \&MakeXRef,
1985                                         sub {
1986                                             &tagify($_[0],"parameter");
1987                                         });
1988     
1989     for (my $i = 1; $i <= $#fields; $i += 2) {
1990         my $field_name = $fields[$i];
1991         
1992         if ($field_name eq "Varargs") {
1993             $field_name = "...";
1994         }
1996         if ($i == 1) {
1997             $synop .= "$field_name";
1998             $desc  .= "$field_name";
1999         } else {
2000             $synop .= ",\n"
2001                 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2002                 . " $field_name";
2003             $desc  .= ",\n"
2004                 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2005                 . " $field_name";
2006         }
2007         
2008     }
2010     $synop .= ");\n";
2011     $desc  .= ");</programlisting>\n";
2013     $desc .= &MakeDeprecationNote($symbol);
2015     my $parameters = &OutputParamDescriptions ("FUNCTION", $symbol, @fields);
2016     my $parameters_output = 0;
2018     if (defined ($SymbolDocs{$symbol})) {
2019         my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
2021         # Try to insert the parameter table at the author's desired position.
2022         # Otherwise we need to tag it onto the end.
2023         # FIXME: document that in the user manual and make it useable for other
2024         # types too
2025         if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
2026           $parameters_output = 1;
2027         }
2028         $desc .= $symbol_docs;
2029     }
2031     if ($parameters_output == 0) {
2032         $desc .= $parameters;
2033     }
2035     $desc .= OutputSymbolTraits ($symbol);
2036     $desc .= "</refsect2>\n";
2037     return ($synop, $desc);
2041 #############################################################################
2042 # Function    : OutputParamDescriptions
2043 # Description : Returns the DocBook output describing the parameters of a
2044 #               function, macro or signal handler.
2045 # Arguments   : $symbol_type - 'FUNCTION', 'MACRO' or 'SIGNAL'. Signal
2046 #                 handlers have an implicit user_data parameter last.
2047 #               $symbol - the name of the function/macro being described.
2048 #               @fields - parsed fields from the declaration, used to determine
2049 #                  undocumented/unused entries
2050 #############################################################################
2052 sub OutputParamDescriptions {
2053     my ($symbol_type, $symbol, @fields) = @_;
2054     my $output = "";
2055     my $params = $SymbolParams{$symbol};
2056     my $num_params = 0;
2057     my %field_descrs = ();
2059     if (@fields) {
2060         %field_descrs = @fields;
2061         delete $field_descrs{"void"};
2062         delete $field_descrs{"Returns"};
2063     }
2065     if (defined $params) {
2066         my $returns = "";
2067         my $params_desc = "";
2068         my $missing_parameters = "";
2069         my $unused_parameters = "";
2070         my $j;
2072         for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
2073             my $param_name = $$params[$j];
2074             my $param_desc = $$params[$j + 1];
2075             my $param_annotations = "";
2076             
2077             ($param_desc,$param_annotations) = & ExpandAnnotation($symbol, $param_desc);
2078             $param_desc = &ExpandAbbreviations($symbol, $param_desc);
2079             $param_desc .= $param_annotations;
2080             if ($param_name eq "Returns") {
2081                 $returns = "$param_desc";
2082             } elsif ($param_name eq "void") {
2083                 #print "!!!! void in params for $symbol?\n";
2084             } else {
2085                 if (@fields) {
2086                     if (!defined $field_descrs{$param_name}) {
2087                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2088                             "Parameter description for $symbol"."::"."$param_name is not used from source code comment block.");
2089                         if ($unused_parameters ne "") {
2090                           $unused_parameters .= ", ".$param_name;
2091                         } else {
2092                            $unused_parameters = $param_name;
2093                         }
2094                     } else {
2095                         delete $field_descrs{$param_name};
2096                     }
2097                 }
2098                 if ($param_name eq "Varargs") {
2099                     $param_name = "...";
2100                 }
2101                 if($param_desc ne "") {
2102                     $params_desc .= "<varlistentry><term><parameter>$param_name</parameter>&#160;:</term>\n<listitem><simpara>$param_desc</simpara></listitem></varlistentry>\n";
2103                     $num_params++;
2104                 }
2105             }
2106         }
2107         foreach my $param_name (keys %field_descrs) {
2108             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2109                 "Parameter description for $symbol"."::"."$param_name is missing in source code comment block.");
2110             if ($missing_parameters ne "") {
2111               $missing_parameters .= ", ".$param_name;
2112             } else {
2113                $missing_parameters = $param_name;
2114             }
2115         }
2117         # Signals have an implicit user_data parameter which we describe.
2118         if ($symbol_type eq "SIGNAL") {
2119             $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";
2120         }
2122         # Start a table if we need one.
2123         if ($params_desc || $returns) {
2124             $output .= "<variablelist role=\"params\">\n";
2125             if ($params_desc ne "") {
2126                 #$output .= "<varlistentry><term>Parameters:</term><listitem></listitem></varlistentry>\n";
2127                 $output .= $params_desc;
2128             }
2130             # Output the returns info last.
2131             if ($returns) {
2132                 $output .= "<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara>$returns</simpara></listitem></varlistentry>\n";
2133             }
2135             # Finish the table.
2136             $output .= "</variablelist>";
2137         }
2139         # remember missing/unused parameters (needed in tmpl-free build)
2140         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
2141             $AllIncompleteSymbols{$symbol}=$missing_parameters;
2142         }
2143         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
2144             $AllUnusedSymbols{$symbol}=$unused_parameters;
2145         }
2146     }
2147     if (($num_params == 0) && @fields && (scalar(keys(%field_descrs)) > 0)) {
2148         if (! exists ($AllIncompleteSymbols{$symbol})) {
2149             $AllIncompleteSymbols{$symbol}="<parameters>";
2150         }
2151     }
2152     
2153     return $output;
2157 #############################################################################
2158 # Function    : ParseStabilityLevel
2159 # Description : Parses a stability level and outputs a warning if it isn't
2160 #               valid.
2161 # Arguments   : $stability - the stability text.
2162 #               $file, $line - context for error message
2163 #               $message - description of where the level is from, to use in
2164 #               any error message.
2165 # Returns     : The parsed stability level string.
2166 #############################################################################
2168 sub ParseStabilityLevel {
2169     my ($stability, $file, $line, $message) = @_;
2171     $stability =~ s/^\s*//;
2172     $stability =~ s/\s*$//;
2173     if ($stability =~ m/^stable$/i) {
2174         $stability = "Stable";
2175     } elsif ($stability =~ m/^unstable$/i) {
2176         $stability = "Unstable";
2177     } elsif ($stability =~ m/^private$/i) {
2178         $stability = "Private";
2179     } else {
2180         &LogWarning ($file, $line, "$message is $stability.".
2181             "It should be one of these: Stable, Unstable, or Private.");
2182     }
2183     return $stability;
2187 #############################################################################
2188 # Function    : OutputSGMLFile
2189 # Description : Outputs the final DocBook file for one section.
2190 # Arguments   : $file - the name of the file.
2191 #               $title - the title from the $MODULE-sections.txt file, which
2192 #                 will be overridden by the title in the template file.
2193 #               $section_id - the SGML id to use for the toplevel tag.
2194 #               $includes - comma-separates list of include files added at top
2195 #                 of synopsis, with '<' '>' around them (if not already enclosed in "").
2196 #               $synopsis - reference to the DocBook for the Synopsis part.
2197 #               $details - reference to the DocBook for the Details part.
2198 #               $signal_synop - reference to the DocBook for the Signal Synopsis part
2199 #               $signal_desc - reference to the DocBook for the Signal Description part
2200 #               $args_synop - reference to the DocBook for the Arg Synopsis part
2201 #               $args_desc - reference to the DocBook for the Arg Description part
2202 #               $hierarchy - reference to the DocBook for the Object Hierarchy part
2203 #               $interfaces - reference to the DocBook for the Interfaces part
2204 #               $implementations - reference to the DocBook for the Known Implementations part
2205 #               $prerequisites - reference to the DocBook for the Prerequisites part
2206 #               $derived - reference to the DocBook for the Derived Interfaces part
2207 #               $file_objects - reference to an array of objects in this file
2208 #############################################################################
2210 sub OutputSGMLFile {
2211     my ($file, $title, $section_id, $includes, $synopsis, $details, $signals_synop, $signals_desc, $args_synop, $args_desc, $hierarchy, $interfaces, $implementations, $prerequisites, $derived, $file_objects) = @_;
2213     #print "Output sgml for file $file with title '$title'\n";
2214     
2215     # The edited title overrides the one from the sections file.
2216     my $new_title = $SymbolDocs{"$TMPL_DIR/$file:Title"};
2217     if (defined ($new_title) && $new_title !~ m/^\s*$/) {
2218         $title = $new_title;
2219         #print "Found title: $title\n";
2220     }
2221     my $short_desc = $SymbolDocs{"$TMPL_DIR/$file:Short_Description"};
2222     if (!defined ($short_desc) || $short_desc =~ m/^\s*$/) {
2223         $short_desc = "";
2224     } else {
2225         $short_desc = &ExpandAbbreviations("$title:Short_description",
2226                                            $short_desc);
2227         #print "Found short_desc: $short_desc";
2228     }
2229     my $long_desc = $SymbolDocs{"$TMPL_DIR/$file:Long_Description"};
2230     if (!defined ($long_desc) || $long_desc =~ m/^\s*$/) {
2231         $long_desc = "";
2232     } else {
2233         $long_desc = &ExpandAbbreviations("$title:Long_description",
2234                                           $long_desc);
2235         #print "Found long_desc: $long_desc";
2236     }
2237     my $see_also = $SymbolDocs{"$TMPL_DIR/$file:See_Also"};
2238     if (!defined ($see_also) || $see_also =~ m%^\s*(<para>)?\s*(</para>)?\s*$%) {
2239         $see_also = "";
2240     } else {
2241         $see_also = &ExpandAbbreviations("$title:See_Also", $see_also);
2242         #print "Found see_also: $see_also";
2243     }
2244     if ($see_also) {
2245         $see_also = "<refsect1 id=\"$section_id.see-also\">\n<title>See Also</title>\n$see_also\n</refsect1>\n";
2246     }
2247     my $stability = $SymbolDocs{"$TMPL_DIR/$file:Stability_Level"};
2248     if (!defined ($stability) || $stability =~ m/^\s*$/) {
2249         $stability = "";
2250     } else {
2251         $stability = &ParseStabilityLevel($stability, $file, $., "Section stability level");
2252         #print "Found stability: $stability";
2253     }
2254     if ($stability) {
2255         $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$stability, unless otherwise indicated\n</refsect1>\n";
2256     } elsif ($DEFAULT_STABILITY) {
2257         $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$DEFAULT_STABILITY, unless otherwise indicated\n</refsect1>\n";
2258     }
2260     my $image = $SymbolDocs{"$TMPL_DIR/$file:Image"};
2261     if (!defined ($image) || $image =~ m/^\s*$/) {
2262       $image = "";
2263     } else {
2264       $image =~ s/^\s*//;
2265       $image =~ s/\s*$//;
2267       my $format;
2269       if ($image =~ /jpe?g$/i) {
2270         $format = "format='JPEG'";
2271       } elsif ($image =~ /png$/i) {
2272         $format = "format='PNG'";
2273       } elsif ($image =~ /svg$/i) {
2274         $format = "format='SVG'";
2275       } else {
2276         $format = "";
2277       }
2279       $image = "  <inlinegraphic fileref='$image' $format/>\n"
2280     }
2282     my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
2283         gmtime (time);
2284     my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
2285     $year += 1900;
2287     my $include_output = "";
2288     my $include;
2289     foreach $include (split (/,/, $includes)) {
2290         if ($include =~ m/^\".+\"$/) {
2291             $include_output .= "#include ${include}\n";
2292         }
2293         else {
2294             $include =~ s/^\s+|\s+$//gs;
2295             $include_output .= "#include &lt;${include}&gt;\n";
2296         }
2297     }
2298     if ($include_output ne '') {
2299         $include_output = "\n$include_output\n";
2300     }
2301     
2302     my $extralinks = OutputSectionExtraLinks($title,"Section:$file");
2304     my $old_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT";
2305     my $new_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT.new";
2307     open (OUTPUT, ">$new_sgml_file")
2308         || die "Can't create $new_sgml_file: $!";
2310     my $object_anchors = "";
2311     foreach my $object (@$file_objects) {
2312         next if ($object eq $section_id);
2313         my $id = CreateValidSGMLID($object);
2314         #print "Debug: Adding anchor for $object\n";
2315         $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
2316     }
2318     # We used to output this, but is messes up our UpdateFileIfChanged code
2319     # since it changes every day (and it is only used in the man pages):
2320     # "<refentry id="$section_id" revision="$mday $month $year">"
2322     if ($OUTPUT_FORMAT eq "xml") {
2323         print OUTPUT $doctype_header;
2324     }
2326     print OUTPUT <<EOF;
2327 <refentry id="$section_id">
2328 <refmeta>
2329 <refentrytitle role="top_of_page" id="$section_id.top_of_page">$title</refentrytitle>
2330 <manvolnum>3</manvolnum>
2331 <refmiscinfo>
2332   \U$MODULE\E Library
2333 $image</refmiscinfo>
2334 </refmeta>
2335 <refnamediv>
2336 <refname>$title</refname>
2337 <refpurpose>$short_desc</refpurpose>
2338 </refnamediv>
2339 $stability
2340 <refsynopsisdiv id="$section_id.synopsis" role="synopsis">
2341 <title role="synopsis.title">Synopsis</title>
2342 $object_anchors
2343 <synopsis>$include_output$${synopsis}</synopsis>
2344 </refsynopsisdiv>
2345 $$hierarchy$$prerequisites$$derived$$interfaces$$implementations$$args_synop$$signals_synop
2346 <refsect1 id="$section_id.description" role="desc">
2347 <title role="desc.title">Description</title>
2348 $extralinks$long_desc
2349 </refsect1>
2350 <refsect1 id="$section_id.details" role="details">
2351 <title role="details.title">Details</title>
2352 $$details
2353 </refsect1>
2354 $$args_desc$$signals_desc$see_also
2355 </refentry>
2357     close (OUTPUT);
2359     return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2363 #############################################################################
2364 # Function    : OutputExtraFile
2365 # Description : Copies an "extra" DocBook file into the output directory,
2366 #               expanding abbreviations
2367 # Arguments   : $file - the source file.
2368 #############################################################################
2369 sub OutputExtraFile {
2370     my ($file) = @_;
2372     my $basename;
2374     ($basename = $file) =~ s!^.*/!!;
2376     my $old_sgml_file = "$SGML_OUTPUT_DIR/$basename";
2377     my $new_sgml_file = "$SGML_OUTPUT_DIR/$basename.new";
2379     my $contents;
2381     open(EXTRA_FILE, "<$file") || die "Can't open $file";
2383     {
2384         local $/;
2385         $contents = <EXTRA_FILE>;
2386     }
2388     open (OUTPUT, ">$new_sgml_file")
2389         || die "Can't create $new_sgml_file: $!";
2391     print OUTPUT &ExpandAbbreviations ("$basename file", $contents);
2392     close (OUTPUT);
2394     return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2396 #############################################################################
2397 # Function    : OutputBook
2398 # Description : Outputs the SGML entities that need to be included into the
2399 #               main SGML file for the module.
2400 # Arguments   : $book_top - the declarations of the entities, which are added
2401 #                 at the top of the main SGML file.
2402 #               $book_bottom - the references to the entities, which are
2403 #                 added in the main SGML file at the desired position.
2404 #############################################################################
2406 sub OutputBook {
2407     my ($book_top, $book_bottom) = @_;
2409     my $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top";
2410     my $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top.new";
2412     open (OUTPUT, ">$new_file")
2413         || die "Can't create $new_file: $!";
2414     print OUTPUT $book_top;
2415     close (OUTPUT);
2417     &UpdateFileIfChanged ($old_file, $new_file, 0);
2420     $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom";
2421     $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom.new";
2423     open (OUTPUT, ">$new_file")
2424         || die "Can't create $new_file: $!";
2425     print OUTPUT $book_bottom;
2426     close (OUTPUT);
2428     &UpdateFileIfChanged ($old_file, $new_file, 0);
2431     # If the main SGML/XML file hasn't been created yet, we create it here.
2432     # The user can tweak it later.
2433     if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
2434       open (OUTPUT, ">$MAIN_SGML_FILE")
2435         || die "Can't create $MAIN_SGML_FILE: $!";
2437       if ($OUTPUT_FORMAT eq "xml") {
2438           print OUTPUT <<EOF;
2439 <?xml version="1.0"?>
2440 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
2441                "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
2443   <!ENTITY % local.common.attrib "xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'">
2445 <book id="index">
2447       } else {
2448         print OUTPUT <<EOF;
2449 <!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
2450 $book_top
2452 <book id="index">
2454       }
2456 print OUTPUT <<EOF;
2457   <bookinfo>
2458     <title>$MODULE Reference Manual</title>
2459     <releaseinfo>
2460       for $MODULE [VERSION].
2461       The latest version of this documentation can be found on-line at
2462       <ulink role="online-location" url="http://[SERVER]/$MODULE/index.html">http://[SERVER]/$MODULE/</ulink>.
2463     </releaseinfo>
2464   </bookinfo>
2466   <chapter>
2467     <title>[Insert title here]</title>
2468     $book_bottom
2469   </chapter>
2471   if (-e $OBJECT_TREE_FILE) {
2472     print OUTPUT <<EOF;
2473   <chapter id="object-tree">
2474     <title>Object Hierarchy</title>
2475      <xi:include href="xml/tree_index.sgml"/>
2476   </chapter>
2478   }
2480 print OUTPUT <<EOF;
2481   <index id="api-index-full">
2482     <title>API Index</title>
2483     <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
2484   </index>
2486   <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
2487 </book>
2490       close (OUTPUT);
2491     }
2495 #############################################################################
2496 # Function    : CreateValidSGML
2497 # Description : This turns any chars which are used in SGML into entities,
2498 #               e.g. '<' into '&lt;'
2499 # Arguments   : $text - the text to turn into proper SGML.
2500 #############################################################################
2502 sub CreateValidSGML {
2503     my ($text) = @_;
2504     $text =~ s/&/&amp;/g;       # Do this first, or the others get messed up.
2505     $text =~ s/</&lt;/g;
2506     $text =~ s/>/&gt;/g;
2507     # browers render single tabs inconsistently
2508     $text =~ s/([^\s])\t([^\s])/$1&#160;$2/g;
2509     return $text;
2512 #############################################################################
2513 # Function    : ConvertSGMLChars
2514 # Description : This is used for text in source code comment blocks, to turn
2515 #               chars which are used in SGML into entities, e.g. '<' into
2516 #               '&lt;'. Depending on $SGML_MODE, this is done
2517 #               unconditionally or only if the character doesn't seem to be
2518 #               part of an SGML construct (tag or entity reference).
2519 # Arguments   : $text - the text to turn into proper SGML.
2520 #############################################################################
2522 sub ConvertSGMLChars {
2523     my ($symbol, $text) = @_;
2525     if ($SGML_MODE) {
2526         # For the SGML mode only convert to entities outside CDATA sections.
2527         return &ModifyXMLElements ($text, $symbol,
2528                                    "<!\\[CDATA\\[|<programlisting[^>]*>",
2529                                    \&ConvertSGMLCharsEndTag,
2530                                    \&ConvertSGMLCharsCallback);
2531     } else {
2532         # For the simple non-sgml mode, convert to entities everywhere.
2533         $text =~ s/&/&amp;/g;   # Do this first, or the others get messed up.
2534         $text =~ s/</&lt;/g;
2535         $text =~ s/>/&gt;/g;
2536         return $text;
2537     }
2541 sub ConvertSGMLCharsEndTag {
2542   if ($_[0] eq "<!\[CDATA\[") {
2543     return "]]>";
2544   } else {
2545     return "</programlisting>";
2546   }
2549 sub ConvertSGMLCharsCallback {
2550   my ($text, $symbol, $tag) = @_;
2552   if ($tag =~ m/^<programlisting/) {
2553     # We can handle <programlisting> specially here.
2554     return &ModifyXMLElements ($text, $symbol,
2555                                "<!\\[CDATA\\[",
2556                                \&ConvertSGMLCharsEndTag,
2557                                \&ConvertSGMLCharsCallback2);
2558   } elsif ($tag eq "") {
2559     # If we're not in CDATA convert to entities.
2560     $text =~ s/&(?![a-zA-Z#]+;)/&amp;/g;        # Do this first, or the others get messed up.
2561     $text =~ s/<(?![a-zA-Z\/!])/&lt;/g;
2562     $text =~ s/(?<![a-zA-Z0-9"'\/-])>/&gt;/g;
2564     # Handle "#include <xxxxx>"
2565     $text =~ s/#include(\s+)<([^>]+)>/#include$1&lt;$2&gt;/g;
2566   }
2568   return $text;
2571 sub ConvertSGMLCharsCallback2 {
2572   my ($text, $symbol, $tag) = @_;
2574   # If we're not in CDATA convert to entities.
2575   # We could handle <programlisting> differently, though I'm not sure it helps.
2576   if ($tag eq "") {
2577     # replace only if its not a tag
2578     $text =~ s/&(?![a-zA-Z#]+;)/&amp;/g;        # Do this first, or the others get messed up.
2579     $text =~ s/<(?![a-zA-Z\/!])/&lt;/g;
2580     $text =~ s/(?<![a-zA-Z0-9"'\/-])>/&gt;/g;
2582     # Handle "#include <xxxxx>"
2583     $text =~ s/#include(\s+)<([^>]+)>/#include$1&lt;$2&gt;/g;
2584   }
2586   return $text;
2589 #############################################################################
2590 # Function    : ExpandAnnotation
2591 # Description : This turns annotations into acrony tags.
2592 # Arguments   : $symbol - the symbol being documented, for error messages.
2593 #               $text - the text to expand.
2594 #############################################################################
2595 sub ExpandAnnotation {
2596     my ($symbol, $param_desc) = @_;
2597     my $param_annotations = "";
2598     
2599     if ($param_desc =~ m%\s*\((.*)\):%) {
2600         my @annotations;
2601         my $annotation;
2602         my $annotation_extra = "";
2603         $param_desc = $';
2604     
2605         @annotations = split(/\)\s*\(/,$1);
2606         foreach $annotation (@annotations) {
2607             # need to search for the longest key-match in %AnnotationDefinition
2608             my $match_length=0;
2609             my $match_annotation="";
2610             my $annotationdef;
2611             foreach $annotationdef (keys %AnnotationDefinition) {
2612                 if ($annotation =~ m/^$annotationdef/) {
2613                     if (length($annotationdef)>$match_length) {
2614                         $match_length=length($annotationdef);
2615                         $match_annotation=$annotationdef;
2616                     }
2617                 }
2618             }
2619             if ($match_annotation ne "") {
2620                 if ($annotation =~ m%$match_annotation\s+(.*)%) {
2621                     $annotation_extra = " $1";
2622                 }
2623                 $AnnotationsUsed{$match_annotation} = 1;
2624                 $param_annotations .= "[<acronym>$match_annotation</acronym>$annotation_extra]";
2625             }
2626             else {
2627                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2628                     "unknown annotation \"$annotation\" in documentation for $symbol.");
2629                 $param_annotations .= "[$annotation]";
2630             }
2631         }
2632         chomp($param_desc);
2633         $param_desc =~ m/^(.*?)\.*\s*$/s;
2634         $param_desc = "$1. ";
2635     }
2636     if ($param_annotations ne "") {
2637         $param_annotations = "<emphasis role=\"annotation\">$param_annotations</emphasis>";
2638     }
2639     return ($param_desc, $param_annotations);
2642 #############################################################################
2643 # Function    : ExpandAbbreviations
2644 # Description : This turns the abbreviations function(), macro(), @param,
2645 #               %constant, and #symbol into appropriate DocBook markup.
2646 #               CDATA sections and <programlisting> parts are skipped.
2647 # Arguments   : $symbol - the symbol being documented, for error messages.
2648 #               $text - the text to expand.
2649 #############################################################################
2651 sub ExpandAbbreviations {
2652   my ($symbol, $text) = @_;
2654   # Convert "|[" and "]|" into the start and end of program listing examples.
2655   $text =~ s%\|\[%<informalexample><programlisting>%g;
2656   $text =~ s%\]\|%</programlisting></informalexample>%g;
2657   # TODO: check for a xml comment after |[ and pick the language attribute from
2658   # that
2660   # keep CDATA unmodified, preserve ulink tags (ideally we preseve all tags
2661   # as such)
2662   return &ModifyXMLElements ($text, $symbol,
2663                              "<!\\[CDATA\\[|<ulink[^>]*>|<programlisting[^>]*>|<!DOCTYPE",
2664                              \&ExpandAbbreviationsEndTag,
2665                              \&ExpandAbbreviationsCallback);
2669 # Returns the end tag corresponding to the given start tag.
2670 sub ExpandAbbreviationsEndTag {
2671   my ($start_tag) = @_;
2673   if ($start_tag eq "<!\[CDATA\[") {
2674     return "]]>";
2675   } elsif ($start_tag eq "<!DOCTYPE") {
2676     return "]>";
2677   } elsif ($start_tag =~ m/<(\w+)/) {
2678     return "</$1>";
2679   }
2682 # Called inside or outside each CDATA or <programlisting> section.
2683 sub ExpandAbbreviationsCallback {
2684   my ($text, $symbol, $tag) = @_;
2686   if ($tag =~ m/^<programlisting/) {
2687     # Handle any embedded CDATA sections.
2688     return &ModifyXMLElements ($text, $symbol,
2689                                "<!\\[CDATA\\[",
2690                                \&ExpandAbbreviationsEndTag,
2691                                \&ExpandAbbreviationsCallback2);
2692   } elsif ($tag eq "") {
2693     # We are outside any CDATA or <programlisting> sections, so we expand
2694     # any gtk-doc abbreviations.
2696     # Convert 'function()' or 'macro()'.
2697     # if there is abc_*_def() we don't want to make a link to _def()
2698     # FIXME: also handle abc(....) : but that would need to be done recursively :/
2699     $text =~ s/([^\*.\w])(\w+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2700     # handle #Object.func()
2701     $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2703     # Convert '@param', but not '\@param'.
2704     $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)/$1<parameter>$2<\/parameter>/g;
2705     $text =~ s/\\\@/\@/g;
2707     # Convert '%constant', but not '\%constant'.
2708     # Also allow negative numbers, e.g. %-1.
2709     $text =~ s/(\A|[^\\])\%(-?\w+)/$1.&MakeXRef($2, &tagify($2, "literal"));/eg;
2710     $text =~ s/\\\%/\%/g;
2712     # Convert '#symbol', but not '\#symbol'.
2713     $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)/$1.&MakeHashXRef($2, "type");/eg;
2714     $text =~ s/\\#/#/g;
2715     
2716     # Expand urls
2717     # FIXME: should we skip urls that are already tagged? (e.g. <literal>http://...</literal>)
2718     # this is apparently also called for markup and not just for plain text
2719     # disable for now.
2720     #$text =~ s%(http|https|ftp)://(.*?)((?:\s|,|\)|\]|\<|\.\s))%<ulink url="$1://$2">$2</ulink>$3%g;
2722     # TODO: optionally check all words from $text against internal symbols and
2723     # warn if those could be xreffed, but miss a %,# or ()
2724   }
2726   return $text;
2729 # This is called inside a <programlisting>
2730 sub ExpandAbbreviationsCallback2 {
2731   my ($text, $symbol, $tag) = @_;
2733   if ($tag eq "") {
2734     # We are inside a <programlisting> but outside any CDATA sections,
2735     # so we expand any gtk-doc abbreviations.
2736     # FIXME: why is this different from &ExpandAbbreviationsCallback(),
2737     #        why not just call it
2738     $text =~ s/#(\w+)/&MakeHashXRef($1, "");/eg;
2739   }
2741   return $text;
2744 sub MakeHashXRef {
2745     my ($symbol, $tag) = @_;;
2746     my $text = $symbol;
2748     # Check for things like '#include', '#define', and skip them.
2749     if ($PreProcessorDirectives{$symbol}) {
2750       return "#$symbol";
2751     }
2753     # Get rid of any special '-struct' suffix.
2754     $text =~ s/-struct$//;
2756     # If the symbol is in the form "Object::signal", then change the symbol to
2757     # "Object-signal" and use "signal" as the text.
2758     if ($symbol =~ s/::/-/) {
2759       $text = "\"$'\"";
2760     }
2762     # If the symbol is in the form "Object:property", then change the symbol to
2763     # "Object--property" and use "property" as the text.
2764     if ($symbol =~ s/:/--/) {
2765       $text = "\"$'\"";
2766     }
2768     if ($tag ne "") {
2769       $text = tagify ($text, $tag);
2770     }
2771     
2772     return &MakeXRef($symbol, $text);
2776 #############################################################################
2777 # Function    : ModifyXMLElements
2778 # Description : Looks for given XML element tags within the text, and calls
2779 #               the callback on pieces of text inside & outside those elements.
2780 #               Used for special handling of text inside things like CDATA
2781 #               and <programlisting>.
2782 # Arguments   : $text - the text.
2783 #               $symbol - the symbol currently being documented (only used for
2784 #                      error messages).
2785 #               $start_tag_regexp - the regular expression to match start tags.
2786 #                      e.g. "<!\\[CDATA\\[|<programlisting[^>]*>" to match
2787 #                      CDATA sections or programlisting elements.
2788 #               $end_tag_func - function which is passed the matched start tag
2789 #                      and should return the appropriate end tag string.
2790 #               $callback - callback called with each part of the text. It is
2791 #                      called with a piece of text, the symbol being
2792 #                      documented, and the matched start tag or "" if the text
2793 #                      is outside the XML elements being matched.
2794 #############################################################################
2795 sub ModifyXMLElements {
2796     my ($text, $symbol, $start_tag_regexp, $end_tag_func, $callback) = @_;
2797     my ($before_tag, $start_tag, $end_tag_regexp, $end_tag);
2798     my $result = "";
2800     while ($text =~ m/$start_tag_regexp/s) {
2801       $before_tag = $`; # Prematch for last successful match string
2802       $start_tag = $&;  # Last successful match
2803       $text = $';       # Postmatch for last successful match string
2805       $result .= &$callback ($before_tag, $symbol, "");
2806       $result .= $start_tag;
2808       # get the mathing end-tag for current tag
2809       $end_tag_regexp = &$end_tag_func ($start_tag);
2811       if ($text =~ m/$end_tag_regexp/s) {
2812         $before_tag = $`;
2813         $end_tag = $&;
2814         $text = $';
2816         $result .= &$callback ($before_tag, $symbol, $start_tag);
2817         $result .= $end_tag;
2818       } else {
2819         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2820             "Can't find tag end: $end_tag_regexp in docs for: $symbol.");
2821         # Just assume it is all inside the tag.
2822         $result .= &$callback ($text, $symbol, $start_tag);
2823         $text = "";
2824       }
2825     }
2827     # Handle any remaining text outside the tags.
2828     $result .= &$callback ($text, $symbol, "");
2830     return $result;
2833 sub noop {
2834   return $_[0];
2837 # Adds a tag around some text.
2838 # e.g tagify("Text", "literal") => "<literal>Text</literal>".
2839 sub tagify {
2840    my ($text, $elem) = @_;
2841    return "<" . $elem . ">" . $text . "</" . $elem . ">";
2845 #############################################################################
2846 # Function    : MakeXRef
2847 # Description : This returns a cross-reference link to the given symbol.
2848 #               Though it doesn't try to do this for a few standard C types
2849 #               that it knows won't be in the documentation.
2850 # Arguments   : $symbol - the symbol to try to create a XRef to.
2851 #               $text - text text to put inside the XRef, defaults to $symbol
2852 #############################################################################
2854 sub MakeXRef {
2855     my ($symbol, $text) = ($_[0], $_[1]);
2857     $symbol =~ s/^\s+//;
2858     $symbol =~ s/\s+$//;
2860     if (!defined($text)) {
2861         $text = $symbol;
2863         # Get rid of special '-struct' suffix.
2864         $text =~ s/-struct$//;
2865     }
2867     if ($symbol =~ m/ /) {
2868         return "$text";
2869     }
2871     #print "Getting type link for $symbol -> $text\n";
2873     my $symbol_id = &CreateValidSGMLID ($symbol);
2874     return "<link linkend=\"$symbol_id\">$text</link>";
2878 #############################################################################
2879 # Function    : MakeIndexterms
2880 # Description : This returns a indexterm elements for the given symbol
2881 # Arguments   : $symbol - the symbol to create indexterms for
2882 #############################################################################
2884 sub MakeIndexterms {
2885   my ($symbol, $id) = @_;
2886   my $terms =  "";
2887   my $sortas = "";
2888   
2889   # make the index useful, by ommiting the namespace when sorting
2890   if ($NAME_SPACE ne "") {
2891     if ($symbol =~ m/^$NAME_SPACE\_?(.*)/i) {
2892        $sortas=" sortas=\"$1\"";
2893     }
2894   }
2896   if (exists $Deprecated{$symbol}) {
2897       $terms .= "<indexterm zone=\"$id\" role=\"deprecated\"><primary$sortas>$symbol</primary></indexterm>";
2898       $IndexEntriesDeprecated{$symbol}=$id;
2899       $IndexEntriesFull{$symbol}=$id;
2900   }
2901   if (exists $Since{$symbol}) {
2902      my $since = $Since{$symbol};
2903      $since =~ s/^\s+//;
2904      $since =~ s/\s+$//;
2905      if ($since ne "") {
2906          $terms .= "<indexterm zone=\"$id\" role=\"$since\"><primary$sortas>$symbol</primary></indexterm>";
2907      }
2908      $IndexEntriesSince{$symbol}=$id;
2909      $IndexEntriesFull{$symbol}=$id;
2910   }
2911   if ($terms eq "") {
2912      $terms .= "<indexterm zone=\"$id\"><primary$sortas>$symbol</primary></indexterm>";
2913      $IndexEntriesFull{$symbol}=$id;
2914   }
2916   return $terms;
2919 #############################################################################
2920 # Function    : MakeDeprecationNote
2921 # Description : This returns a deprecation warning for the given symbol.
2922 # Arguments   : $symbol - the symbol to try to create a warning for.
2923 #############################################################################
2925 sub MakeDeprecationNote {
2926     my ($symbol) = $_[0];
2927     my $desc = "";
2928     my $note = "";
2929     if (exists $Deprecated{$symbol}) {
2930         $desc .= "<warning>";
2932         if ($Deprecated{$symbol} =~ /^\s*([0-9\.]+)\s*:/) {
2933                 $desc .= "<para><literal>$symbol</literal> has been deprecated since version $1 and should not be used in newly-written code.";
2934         } else {
2935                 $desc .= "<para><literal>$symbol</literal> is deprecated and should not be used in newly-written code.";
2936         }
2937         if ($Deprecated{$symbol} ne "") {
2938             $note = &ExpandAbbreviations($symbol, $Deprecated{$symbol});
2939             $note =~ s/^\s*([0-9\.]+)\s*:\s*//;
2940             $note =~ s/^\s+//;
2941             $note =~ s/\s+$//;
2942             $note =~ s%\n{2,}%\n</para>\n<para>\n%g;
2943             $desc .= " " . $note;
2944         }
2945         $desc .= "</para></warning>\n";
2946     }
2947     return $desc;
2950 #############################################################################
2951 # Function    : MakeConditionDescription
2952 # Description : This returns a sumary of conditions for the given symbol.
2953 # Arguments   : $symbol - the symbol to try to create the sumary.
2954 #############################################################################
2956 sub MakeConditionDescription {
2957     my ($symbol) = $_[0];
2958     my $desc = "";
2960     if (exists $Deprecated{$symbol}) {
2961         if ($desc ne "") {
2962             $desc .= "|";
2963         }
2965         if ($Deprecated{$symbol} =~ /^\s*(.*?)\s*$/) {
2966                 $desc .= "deprecated:$1";
2967         } else {
2968                 $desc .= "deprecated";
2969         }
2970     }
2972     if (exists $Since{$symbol}) {
2973         if ($desc ne "") {
2974             $desc .= "|";
2975         }
2977         if ($Since{$symbol} =~ /^\s*(.*?)\s*$/) {
2978                 $desc .= "since:$1";
2979         } else {
2980                 $desc .= "since";
2981         }
2982     }
2984     if (exists $StabilityLevel{$symbol}) {
2985         if ($desc ne "") {
2986             $desc .= "|";
2987         }
2988         $desc .= "stability:".$StabilityLevel{$symbol};
2989     }
2991     if ($desc ne "") {
2992         $desc=" condition=\"".$desc."\"";
2993         #print "condition for '$symbol' = '$desc'\n";
2994     }
2995     return $desc;
2998 #############################################################################
2999 # Function    : GetHierarchy
3000 # Description : Returns the DocBook output describing the ancestors and
3001 #               immediate children of a GObject subclass. It uses the
3002 #               global @Objects and @ObjectLevels arrays to walk the tree.
3003 # Arguments   : $object - the GtkObject subclass.
3004 #############################################################################
3006 sub GetHierarchy {
3007     my ($object) = @_;
3009     # Find object in the objects array.
3010     my $found = 0;
3011     my @children = ();
3012     my $i;
3013     my $level;
3014     my $j;
3015     for ($i = 0; $i < @Objects; $i++) {
3016         if ($found) {
3017             if ($ObjectLevels[$i] <= $level) {
3018             last;
3019         }
3020             elsif ($ObjectLevels[$i] == $level + 1) {
3021                 push (@children, $Objects[$i]);
3022             }
3023         }
3024         elsif ($Objects[$i] eq $object) {
3025             $found = 1;
3026             $j = $i;
3027             $level = $ObjectLevels[$i];
3028         }
3029     }
3030     if (!$found) {
3031         return "";
3032     }
3034     # Walk up the hierarchy, pushing ancestors onto the ancestors array.
3035     my @ancestors = ();
3036     push (@ancestors, $object);
3037     #print "Level: $level\n";
3038     while ($level > 1) {
3039         $j--;
3040         if ($ObjectLevels[$j] < $level) {
3041             push (@ancestors, $Objects[$j]);
3042             $level = $ObjectLevels[$j];
3043             #print "Level: $level\n";
3044         }
3045     }
3047     # Output the ancestors list, indented and with links.
3048     my $hierarchy = "<synopsis>\n";
3049     $level = 0;
3050     for ($i = $#ancestors; $i >= 0; $i--) {
3051         my $link_text;
3052         # Don't add a link to the current object, i.e. when i == 0.
3053         if ($i > 0) {
3054             my $ancestor_id = &CreateValidSGMLID ($ancestors[$i]);
3055             $link_text = "<link linkend=\"$ancestor_id\">$ancestors[$i]</link>";
3056         } else {
3057             $link_text = "$ancestors[$i]";
3058         }
3059         if ($level == 0) {
3060             $hierarchy .= "  $link_text\n";
3061         } else {
3062 #           $hierarchy .= ' ' x ($level * 6 - 3) . "|\n";
3063             $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3064         }
3065         $level++;
3066     }
3067     for ($i = 0; $i <= $#children; $i++) {
3068       my $id = &CreateValidSGMLID ($children[$i]);
3069       my $link_text = "<link linkend=\"$id\">$children[$i]</link>";
3070       $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3071     }
3072     $hierarchy .= "</synopsis>\n";
3074     return $hierarchy;
3078 #############################################################################
3079 # Function    : GetInterfaces
3080 # Description : Returns the DocBook output describing the interfaces
3081 #               implemented by a class. It uses the global %Interfaces hash.
3082 # Arguments   : $object - the GtkObject subclass.
3083 #############################################################################
3085 sub GetInterfaces {
3086     my ($object) = @_;
3087     my $text = "";
3088     my $i;
3090     # Find object in the objects array.
3091     if (exists($Interfaces{$object})) {
3092         my @ifaces = split(' ', $Interfaces{$object});
3093         $text = <<EOF;
3094 <para>
3095 $object implements
3097         for ($i = 0; $i <= $#ifaces; $i++) {
3098             my $id = &CreateValidSGMLID ($ifaces[$i]);
3099             $text .= " <link linkend=\"$id\">$ifaces[$i]</link>";
3100             if ($i < $#ifaces - 1) {
3101                 $text .= ', ';
3102             }
3103             elsif ($i < $#ifaces) {
3104                 $text .= ' and ';
3105             }
3106             else {
3107                 $text .= '.';
3108             }
3109         }
3110         $text .= <<EOF;
3111 </para>
3113     }
3115     return $text;
3118 #############################################################################
3119 # Function    : GetImplementations
3120 # Description : Returns the DocBook output describing the implementations
3121 #               of an interface. It uses the global %Interfaces hash.
3122 # Arguments   : $object - the GtkObject subclass.
3123 #############################################################################
3125 sub GetImplementations {
3126     my ($object) = @_;
3127     my @impls = ();
3128     my $text = "";
3129     my $i;
3130     foreach my $key (keys %Interfaces) {
3131         if ($Interfaces{$key} =~ /\b$object\b/) {
3132             push (@impls, $key);
3133         }
3134     }
3135     if ($#impls >= 0) {
3136         @impls = sort @impls;
3137         $text = <<EOF;
3138 <para>
3139 $object is implemented by
3141         for ($i = 0; $i <= $#impls; $i++) {
3142             my $id = &CreateValidSGMLID ($impls[$i]);
3143             $text .= " <link linkend=\"$id\">$impls[$i]</link>";
3144             if ($i < $#impls - 1) {
3145                 $text .= ', ';
3146             }
3147             elsif ($i < $#impls) {
3148                 $text .= ' and ';
3149             }
3150             else {
3151                 $text .= '.';
3152             }
3153         }
3154         $text .= <<EOF;
3155 </para>
3157     }
3158     return $text;
3162 #############################################################################
3163 # Function    : GetPrerequisites
3164 # Description : Returns the DocBook output describing the prerequisites
3165 #               of an interface. It uses the global %Prerequisites hash.
3166 # Arguments   : $iface - the interface.
3167 #############################################################################
3169 sub GetPrerequisites {
3170     my ($iface) = @_;
3171     my $text = "";
3172     my $i;
3174     if (exists($Prerequisites{$iface})) {
3175         $text = <<EOF;
3176 <para>
3177 $iface requires
3179         my @prereqs = split(' ', $Prerequisites{$iface});
3180         for ($i = 0; $i <= $#prereqs; $i++) {
3181             my $id = &CreateValidSGMLID ($prereqs[$i]);
3182             $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
3183             if ($i < $#prereqs - 1) {
3184                 $text .= ', ';
3185             }
3186             elsif ($i < $#prereqs) {
3187                 $text .= ' and ';
3188             }
3189             else {
3190                 $text .= '.';
3191             }
3192         }
3193         $text .= <<EOF;
3194 </para>
3196     }
3197     return $text;
3200 #############################################################################
3201 # Function    : GetDerived
3202 # Description : Returns the DocBook output describing the derived interfaces
3203 #               of an interface. It uses the global %Prerequisites hash.
3204 # Arguments   : $iface - the interface.
3205 #############################################################################
3207 sub GetDerived {
3208     my ($iface) = @_;
3209     my $text = "";
3210     my $i;
3212     my @derived = ();
3213     foreach my $key (keys %Prerequisites) {
3214         if ($Prerequisites{$key} =~ /\b$iface\b/) {
3215             push (@derived, $key);
3216         }
3217     }
3218     if ($#derived >= 0) {
3219         @derived = sort @derived;
3220         $text = <<EOF;
3221 <para>
3222 $iface is required by
3224         for ($i = 0; $i <= $#derived; $i++) {
3225             my $id = &CreateValidSGMLID ($derived[$i]);
3226             $text .= " <link linkend=\"$id\">$derived[$i]</link>";
3227             if ($i < $#derived - 1) {
3228                 $text .= ', ';
3229             }
3230             elsif ($i < $#derived) {
3231                 $text .= ' and ';
3232             }
3233             else {
3234                 $text .= '.';
3235             }
3236         }
3237         $text .= <<EOF;
3238 </para>
3240     }
3241     return $text;
3245 #############################################################################
3246 # Function    : GetSignals
3247 # Description : Returns the synopsis and detailed description DocBook output
3248 #               for the signal handlers of a given GtkObject subclass.
3249 # Arguments   : $object - the GtkObject subclass, e.g. 'GtkButton'.
3250 #############################################################################
3252 sub GetSignals {
3253     my ($object) = @_;
3254     my $synop = "";
3255     my $desc = "";
3257     my $i;
3258     for ($i = 0; $i <= $#SignalObjects; $i++) {
3259         if ($SignalObjects[$i] eq $object) {
3260             #print "Found signal: $SignalNames[$i]\n";
3261             my $name = $SignalNames[$i];
3262             my $symbol = "${object}::${name}";
3263             my $id = &CreateValidSGMLID ("$object-$name");
3265             my $pad = ' ' x (46 - length($name));
3266             $synop .= "  &quot;<link linkend=\"$id\">$name</link>&quot;$pad ";
3268             $desc .= "<refsect2 id=\"$id\" role=\"signal\"><title>The <literal>&quot;$name&quot;</literal> signal</title>\n";
3269             $desc .= MakeIndexterms($symbol, $id);
3270             $desc .= "\n";
3271             $desc .= OutputSymbolExtraLinks($symbol);
3273             $desc .= "<programlisting>";
3275             $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
3276             my $type_modifier = defined($1) ? $1 : "";
3277             my $type = $2;
3278             my $pointer = $3;
3279             my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
3281             my $ret_type_len = length ($type_modifier) + length ($pointer)
3282                 + length ($type);
3283             my $ret_type_output = "$type_modifier$xref$pointer"
3284                 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
3286             $desc  .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
3288             my $sourceparams = $SourceSymbolParams{$symbol};
3289             my @params = split ("\n", $SignalPrototypes[$i]);
3290             my $j;
3291             my $l;
3292             my $type_len = length("gpointer");
3293             my $name_len = length("user_data");
3294             # do two passes, the first one is to calculate padding
3295             for ($l = 0; $l < 2; $l++) {
3296                 for ($j = 0; $j <= $#params; $j++) {
3297                     # allow alphanumerics, '_', '[' & ']' in param names
3298                     if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
3299                         $type = $1;
3300                         $pointer = $2;
3301                         if (defined($sourceparams)) {
3302                             $name = $$sourceparams[$PARAM_FIELD_COUNT * $j];
3303                         }
3304                         else {
3305                             $name = $3;
3306                         }
3307                         if (!defined($name)) {
3308                             $name = "arg$j";
3309                         }
3310                         if ($l == 0) {
3311                             if (length($type) + length($pointer) > $type_len) {
3312                                 $type_len = length($type) + length($pointer);
3313                             }
3314                             if (length($name) > $name_len) {
3315                                 $name_len = length($name);
3316                             }
3317                         }
3318                         else {
3319                             $xref = &MakeXRef ($type, &tagify($type, "type"));
3320                             $pad = ' ' x ($type_len - length($type) - length($pointer));
3321                             $desc .= "$xref$pad $pointer$name,\n";
3322                             $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
3323                         }
3324                     } else {
3325                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3326                              "Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]");
3327                     }
3328                 }
3329             }
3330             $xref = &MakeXRef ("gpointer", &tagify("gpointer", "type"));
3331             $pad = ' ' x ($type_len - length("gpointer"));
3332             $desc  .= "$xref$pad user_data)";
3334             my $flags = $SignalFlags[$i];
3335             my $flags_string = "";
3337             if (defined ($flags)) {
3338               if ($flags =~ m/f/) {
3339                 $flags_string = "Run First";
3340               }
3341               elsif ($flags =~ m/l/) {
3342                 $flags_string = "Run Last";
3343               }
3344               elsif ($flags =~ m/c/) {
3345                 $flags_string = "Cleanup";
3346               }
3347               if ($flags =~ m/r/) {
3348                 if ($flags_string) { $flags_string .= " / "; }
3349                 $flags_string .= "No Recursion";
3350               }
3351               if ($flags =~ m/d/) {
3352                 if ($flags_string) { $flags_string .= " / "; }
3353                 $flags_string .= "Has Details";
3354               }
3355               if ($flags =~ m/a/) {
3356                 if ($flags_string) { $flags_string .= " / "; }
3357                 $flags_string .= "Action";
3358               }
3359               if ($flags =~ m/h/) {
3360                 if ($flags_string) { $flags_string .= " / "; }
3361                 $flags_string .= "No Hooks";
3362               }
3363             }
3365             if ($flags_string)
3366               {
3367                 $synop .= ": $flags_string\n";
3369                 $pad = ' ' x (5 + $name_len - length("user_data"));
3370                 $desc  .= "$pad : $flags_string</programlisting>\n";
3371               }
3372             else
3373               {
3374                 $synop .= "\n";
3375                 $desc  .= "</programlisting>\n";
3376               }
3378             $desc .= &MakeDeprecationNote($symbol);
3380             my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
3381             my $parameters_output = 0;
3383             $AllSymbols{$symbol} = 1;
3384             if (defined ($SymbolDocs{$symbol})) {
3385                 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3387                 # Try to insert the parameter table at the author's desired
3388                 # position. Otherwise we need to tag it onto the end.
3389                 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
3390                   $parameters_output = 1;
3391                 }
3392                 $desc .= $symbol_docs;
3394                 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
3395                     $AllDocumentedSymbols{$symbol} = 1;
3396                 }
3397             }
3399             if ($parameters_output == 0) {
3400                 $desc .= $parameters;
3401               }
3402             $desc .= OutputSymbolTraits ($symbol);
3403             $desc .= "</refsect2>";
3404         }
3405     }
3406     return ($synop, $desc);
3410 #############################################################################
3411 # Function    : GetArgs
3412 # Description : Returns the synopsis and detailed description DocBook output
3413 #               for the Args of a given GtkObject subclass.
3414 # Arguments   : $object - the GtkObject subclass, e.g. 'GtkButton'.
3415 #############################################################################
3417 sub GetArgs {
3418     my ($object) = @_;
3419     my $synop = "";
3420     my $desc = "";
3421     my $child_synop = "";
3422     my $child_desc = "";
3423     my $style_synop = "";
3424     my $style_desc = "";
3426     my $i;
3427     for ($i = 0; $i <= $#ArgObjects; $i++) {
3428         if ($ArgObjects[$i] eq $object) {
3429             #print "Found arg: $ArgNames[$i]\n";
3430             my $name = $ArgNames[$i];
3431             my $flags = $ArgFlags[$i];
3432             my $flags_string = "";
3433             my $kind = "";
3434             my $id_sep = "";
3436             if ($flags =~ m/c/) {
3437                 $kind = "child property";
3438                 $id_sep = "c-";
3439             }
3440             elsif ($flags =~ m/s/) {
3441                 $kind = "style property";
3442                 $id_sep = "s-";
3443             }
3444             else {
3445                 $kind = "property";
3446             }
3448             # Remember only one colon so we don't clash with signals.
3449             my $symbol = "${object}:${name}";
3450             # use two dashes and ev. an extra separator here for the same reason.
3451             my $id = &CreateValidSGMLID ("$object--$id_sep$name");
3453             my $type = $ArgTypes[$i];
3454             my $type_output;
3455             my $range = $ArgRanges[$i];
3456             my $range_output = CreateValidSGML ($range);
3457             my $default = $ArgDefaults[$i];
3458             my $default_output = CreateValidSGML ($default);
3460             if ($type eq "GtkString") {
3461                 $type = "char*";
3462             }
3463             if ($type eq "GtkSignal") {
3464                 $type = "GtkSignalFunc, gpointer";
3465                 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
3466                     . &MakeXRef ("gpointer");
3467             } elsif ($type =~ m/^(\w+)\*$/) {
3468                 $type_output = &MakeXRef ($1, &tagify($1, "type")) . "*";
3469             } else {
3470                 $type_output = &MakeXRef ($type, &tagify($type, "type"));
3471             }
3473             if ($flags =~ m/r/) {
3474                 $flags_string = "Read";
3475             }
3476             if ($flags =~ m/w/) {
3477                 if ($flags_string) { $flags_string .= " / "; }
3478                 $flags_string .= "Write";
3479             }
3480             if ($flags =~ m/x/) {
3481                 if ($flags_string) { $flags_string .= " / "; }
3482                 $flags_string .= "Construct";
3483             }
3484             if ($flags =~ m/X/) {
3485                 if ($flags_string) { $flags_string .= " / "; }
3486                 $flags_string .= "Construct Only";
3487             }
3489             $AllSymbols{$symbol} = 1;
3490             my $blurb;
3491             if (defined($SymbolDocs{$symbol}) &&
3492                 !IsEmptyDoc($SymbolDocs{$symbol})) {
3493                 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3494                 #print ".. [$SymbolDocs{$symbol}][$blurb]\n";
3495                 $AllDocumentedSymbols{$symbol} = 1;
3496             }
3497             else {
3498                 if (!($ArgBlurbs[$i] eq "")) {
3499                     $AllDocumentedSymbols{$symbol} = 1;
3500                 } else {
3501                     # FIXME: print a warning?
3502                     #print ".. no description\n";
3503                 }
3504                 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
3505             }
3507             my $pad1 = " " x (24 - length ($name));
3508             my $pad2 = " " x (20 - length ($type));
3510             my $arg_synop = "  &quot;<link linkend=\"$id\">$name</link>&quot;$pad1 $type_output $pad2 : $flags_string\n";
3511             my $arg_desc = "<refsect2 id=\"$id\" role=\"property\"><title>The <literal>&quot;$name&quot;</literal> $kind</title>\n";
3512             $arg_desc .= MakeIndexterms($symbol, $id);
3513             $arg_desc .= "\n";
3514             $arg_desc .= OutputSymbolExtraLinks($symbol);
3516             $arg_desc .= "<programlisting>  &quot;$name&quot;$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
3517             $arg_desc .= &MakeDeprecationNote($symbol);
3518             $arg_desc .= $blurb;
3519             if ($range ne "") {
3520                 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
3521             }
3522             if ($default ne "") {
3523                 $arg_desc .= "<para>Default value: $default_output</para>\n";
3524             }
3525             $arg_desc .= OutputSymbolTraits ($symbol);
3526             $arg_desc .= "</refsect2>\n";
3528             if ($flags =~ m/c/) {
3529                 $child_synop .= $arg_synop;
3530                 $child_desc .= $arg_desc;
3531             }
3532             elsif ($flags =~ m/s/) {
3533                 $style_synop .= $arg_synop;
3534                 $style_desc .= $arg_desc;
3535             }
3536             else {
3537                 $synop .= $arg_synop;
3538                 $desc .= $arg_desc;
3539             }
3540         }
3541     }
3542     return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
3546 #############################################################################
3547 # Function    : ReadSourceDocumentation
3548 # Description : This reads in the documentation embedded in comment blocks
3549 #               in the source code (for Gnome).
3551 #               Parameter descriptions override any in the template files.
3552 #               Function descriptions are placed before any description from
3553 #               the template files.
3555 #               It recursively descends the source directory looking for .c
3556 #               files and scans them looking for specially-formatted comment
3557 #               blocks.
3559 # Arguments   : $source_dir - the directory to scan.
3560 #############m###############################################################
3562 sub ReadSourceDocumentation {
3563     my ($source_dir) = @_;
3564     my ($file, $dir, @suffix_list, $suffix);
3565     #print "Scanning source directory: $source_dir\n";
3567     # This array holds any subdirectories found.
3568     my (@subdirs) = ();
3570     @suffix_list = split (/,/, $SOURCE_SUFFIXES);
3572     opendir (SRCDIR, $source_dir)
3573         || die "Can't open source directory $source_dir: $!";
3575     foreach $file (readdir (SRCDIR)) {
3576       if ($file =~ /^\./) {
3577         next;
3578       } elsif (-d "$source_dir/$file") {
3579         push (@subdirs, $file);
3580       } elsif (@suffix_list) {
3581         foreach $suffix (@suffix_list) {
3582           if ($file =~ m/\.\Q${suffix}\E$/) {
3583             &ScanSourceFile ("$source_dir/$file");
3584           }
3585         }
3586       } elsif ($file =~ m/\.[ch]$/) {
3587         &ScanSourceFile ("$source_dir/$file");
3588       }
3589     }
3590     closedir (SRCDIR);
3592     # Now recursively scan the subdirectories.
3593     foreach $dir (@subdirs) {
3594         next if ($IGNORE_FILES =~ m/(\s|^)\Q${dir}\E(\s|$)/);
3595         &ReadSourceDocumentation ("$source_dir/$dir");
3596     }
3600 #############################################################################
3601 # Function    : ScanSourceFile
3602 # Description : Scans one source file looking for specially-formatted comment
3603 #               blocks. Later &MergeSourceDocumentation is used to merge any
3604 #               documentation found with the documentation already read in
3605 #               from the template files.
3607 # Arguments   : $file - the file to scan.
3608 #############################################################################
3610 sub ScanSourceFile {
3611     my ($file) = @_;
3612     my $basename;
3614     if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
3615         $basename = $1;
3616     } else {
3617         &LogWarning ($file, 1, "Can't find basename for this filename.");
3618         $basename = $file;
3619     }
3621     # Check if the basename is in the list of files to ignore.
3622     if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
3623         return;
3624     }
3626     #print "DEBUG: Scanning $file\n";
3628     open (SRCFILE, $file)
3629         || die "Can't open $file: $!";
3630     my $in_comment_block = 0;
3631     my $symbol;
3632     my ($in_description, $in_return, $in_since, $in_stability, $in_deprecated);
3633     my ($description, $return_desc, $return_start, $return_style);
3634     my ($since_desc, $stability_desc, $deprecated_desc);
3635     my $current_param;
3636     my $ignore_broken_returns;
3637     my @params;
3638     while (<SRCFILE>) {
3639         # Look for the start of a comment block.
3640         if (!$in_comment_block) {
3641             if (m%^\s*/\*.*\*/%) {
3642                 #one-line comment - not gtkdoc
3643             } elsif (m%^\s*/\*\*\s%) {
3644                 #print "Found comment block start\n";
3646                 $in_comment_block = 1;
3648                 # Reset all the symbol data.
3649                 $symbol = "";
3650                 $in_description = 0;
3651                 $in_return = 0;
3652                 $in_since = 0;
3653                 $in_deprecated = 0;
3654                 $in_stability = 0;
3655                 $description = "";
3656                 $return_desc = "";
3657                 $return_style = "";
3658                 $since_desc = "";
3659                 $deprecated_desc = "";
3660                 $stability_desc = "";
3661                 $current_param = -1;
3662                 $ignore_broken_returns = 0;
3663                 @params = ();
3664             }
3665             next;
3666         }
3668         # We're in a comment block. Check if we've found the end of it.
3669         if (m%^\s*\*+/%) {
3670             if (!$symbol) {
3671                 # maybe its not even meant to be a gtk-doc comment?
3672                 &LogWarning ($file, $., "Symbol name not found at the start of the comment block.");
3673             } else {
3674                 # Add the return value description onto the end of the params.
3675                 if ($return_desc) {
3676                     push (@params, "Returns");
3677                     push (@params, $return_desc);
3678                     if ($return_style eq 'broken') {
3679                         &LogWarning ($file, $., "Free-form return value description in $symbol. Use `Returns:' to avoid ambiguities.");
3680                     }
3681                 }
3682                 # Convert special SGML characters
3683                 $description = &ConvertSGMLChars ($symbol, $description);
3684                 my $k;
3685                 for ($k = 1; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3686                     $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
3687                 }
3689                 # Handle Section docs
3690                 if ($symbol =~ m/SECTION:\s*(.*)/) {
3691                     my $real_symbol=$1;
3692                     my $key;
3694                     if (scalar %KnownSymbols) {
3695                         if ((! defined($KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"})) || $KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"} != 1) {
3696                             &LogWarning ($file, $., "Section $real_symbol is not defined in the $MODULE-section.txt file.");
3697                         }
3698                     }
3700                     #print "SECTION DOCS found in source for : '$real_symbol'\n";
3701                     $ignore_broken_returns = 1;
3702                     for ($k = 0; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3703                         #print "   '".$params[$k]."'\n";
3704                         $params[$k] = "\L$params[$k]";
3705                         undef $key;
3706                         if ($params[$k] eq "short_description") {
3707                             $key = "$TMPL_DIR/$real_symbol:Short_Description";
3708                         } elsif ($params[$k] eq "see_also") {
3709                             $key = "$TMPL_DIR/$real_symbol:See_Also";
3710                         } elsif ($params[$k] eq "title") {
3711                             $key = "$TMPL_DIR/$real_symbol:Title";
3712                         } elsif ($params[$k] eq "stability") {
3713                             $key = "$TMPL_DIR/$real_symbol:Stability_Level";
3714                         } elsif ($params[$k] eq "section_id") {
3715                             $key = "$TMPL_DIR/$real_symbol:Section_Id";
3716                         } elsif ($params[$k] eq "include") {
3717                             $key = "$TMPL_DIR/$real_symbol:Include";
3718                         } elsif ($params[$k] eq "image") {
3719                             $key = "$TMPL_DIR/$real_symbol:Image";
3720                         }
3721                         if (defined($key)) {
3722                             $SourceSymbolDocs{$key}=$params[$k+1];
3723                             $SourceSymbolSourceFile{$key} = $file;
3724                             $SourceSymbolSourceLine{$key} = $.;
3725                         }
3726                     }
3727                     $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
3728                     $SourceSymbolSourceFile{"$TMPL_DIR/$real_symbol:Long_Description"} = $file;
3729                     $SourceSymbolSourceLine{"$TMPL_DIR/$real_symbol:Long_Description"} = $.;
3730                     #$SourceSymbolTypes{$symbol} = "SECTION";
3731                 } else {
3732                     #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
3733                     $SourceSymbolDocs{$symbol} = $description;
3734                     $SourceSymbolParams{$symbol} = [ @params ];
3735                     # FIXME $SourceSymbolTypes{$symbol} = "STRUCT,SIGNAL,ARG,FUNCTION,MACRO";
3736                     #if (defined $DeclarationTypes{$symbol}) {
3737                     #    $SourceSymbolTypes{$symbol} = $DeclarationTypes{$symbol}
3738                     #}
3739                     $SourceSymbolSourceFile{$symbol} = $file;
3740                     $SourceSymbolSourceLine{$symbol} = $.;
3741                 }
3743                 if ($since_desc) {
3744                      ($since_desc, my @extra_lines) = split ("\n", $since_desc);
3745                      $since_desc =~ s/^\s+//;
3746                      $since_desc =~ s/\s+$//;
3747                      #print "Since($symbol) : [$since_desc]\n";
3748                      $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
3749                      if(scalar @extra_lines) {
3750                          &LogWarning ($file, $., "multi-line since docs found");
3751                      }
3752                 }
3754                 if ($stability_desc) {
3755                     $stability_desc = &ParseStabilityLevel($stability_desc, $file, $., "Stability level for $symbol");
3756                     $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
3757                 }
3759                 if ($deprecated_desc) {
3760                     if (exists $Deprecated{$symbol}) {
3761                     }
3762                     else {
3763                          # don't warn for signals and properties
3764                          #if ($symbol !~ m/::?(.*)/) {
3765                          if (defined $DeclarationTypes{$symbol}) {
3766                              &LogWarning ($file, $., 
3767                                  "$symbol is deprecated in the inline comments, but no deprecation guards were found around the declaration.".
3768                                  " (See the --deprecated-guards option for gtkdoc-scan.)");
3769                          }
3770                     }
3771                     $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
3772                 }
3773             }
3775             $in_comment_block = 0;
3776             next;
3777         }
3779         # Get rid of ' * ' at start of every line in the comment block.
3780         s%^\s*\*\s?%%;
3781         # But make sure we don't get rid of the newline at the end.
3782         if (!$_) {
3783             $_ = "\n";
3784         }
3785         #print "DEBUG: scanning :$_";
3787         # If we haven't found the symbol name yet, look for it.
3788         if (!$symbol) {
3789             if (m%^\s*(SECTION:\s*\S+)%) {
3790                 $symbol = $1;
3791                 #print "SECTION DOCS found in source for : '$symbol'\n";
3792                 $ignore_broken_returns = 1;
3793             } elsif (m%^\s*([\w:-]*\w)\s*:?\s*(\([a-z ]+\)\s*)*$%) {
3794                 $symbol = $1;
3795                 #print "SYMBOL DOCS found in source for : '$symbol'\n";
3796             }
3797             next;
3798         }
3800         # If we're in the return value description, add it to the end.
3801         if ($in_return) {
3802             # If we find another valid returns line, we assume that the first
3803             # one was really part of the description.
3804             if (m/^\s*(returns:|return\s+value:)/i) {
3805                 if ($return_style eq 'broken') {
3806                     $description .= $return_start . $return_desc;
3807                 }
3808                 $return_start = $1;
3809                 if ($return_style eq 'sane') {
3810                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3811                 }
3812                 $return_style = 'sane';
3813                 $ignore_broken_returns = 1;
3814                 $return_desc = $';
3815             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3816                 $description .= $return_start . $return_desc;
3817                 $return_start = $1;
3818                 $return_style = 'broken';
3819                 $return_desc = $';
3820             } elsif (m%^\s*since:%i) {
3821                 $since_desc = $';
3822                 $in_since = 1;
3823                 $in_return = 0;
3824             } elsif (m%^\s*stability:%i) {
3825                 $stability_desc = $';
3826                 $in_stability = 1;
3827                 $in_return = 0;
3828             } elsif (m%^\s*deprecated:%i) {
3829                 $deprecated_desc = $';
3830                 $in_deprecated = 1;
3831                 $in_return = 0;
3832             } else {
3833                 $return_desc .= $_;
3834             }
3835             next;
3836         }
3838         if ($in_since) {
3839             if (m/^\s*(returns:|return\s+value:)/i) {
3840                 if ($return_style eq 'broken') {
3841                     $description .= $return_start . $return_desc;
3842                 }
3843                 $return_start = $1;
3844                 if ($return_style eq 'sane') {
3845                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3846                 }
3847                 $return_style = 'sane';
3848                 $ignore_broken_returns = 1;
3849                 $return_desc = $';
3850                 $in_return = 1;
3851                 $in_since = 0;
3852             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3853                 $return_start = $1;
3854                 $return_style = 'broken';
3855                 $return_desc = $';
3856                 $in_return = 1;
3857                 $in_since = 0;
3858             } elsif (m%^\s*deprecated:%i) {
3859                 $deprecated_desc = $';
3860                 $in_deprecated = 1;
3861                 $in_since = 0;
3862             } elsif (m%^\s*stability:%i) {
3863                 $stability_desc = $';
3864                 $in_stability = 1;
3865                 $in_since = 0;
3866             } else {
3867                 $since_desc .= $_;
3868             }
3869             next;
3870         }
3872         if ($in_stability) {
3873             if (m/^\s*(returns:|return\s+value:)/i) {
3874                 if ($return_style eq 'broken') {
3875                     $description .= $return_start . $return_desc;
3876                 }
3877                 $return_start = $1;
3878                 if ($return_style eq 'sane') {
3879                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3880                 }
3881                 $return_style = 'sane';
3882                 $ignore_broken_returns = 1;
3883                 $return_desc = $';
3884                 $in_return = 1;
3885                 $in_stability = 0;
3886             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3887                 $return_start = $1;
3888                 $return_style = 'broken';
3889                 $return_desc = $';
3890                 $in_return = 1;
3891                 $in_stability = 0;
3892             } elsif (m%^\s*deprecated:%i) {
3893                 $deprecated_desc = $';
3894                 $in_deprecated = 1;
3895                 $in_stability = 0;
3896             } elsif (m%^\s*since:%i) {
3897                 $since_desc = $';
3898                 $in_since = 1;
3899                 $in_stability = 0;
3900             } else {
3901                 $stability_desc .= $_;
3902             }
3903             next;
3904         }
3906         if ($in_deprecated) {
3907             if (m/^\s*(returns:|return\s+value:)/i) {
3908                 if ($return_style eq 'broken') {
3909                     $description .= $return_start . $return_desc;
3910                 }
3911                 $return_start = $1;
3912                 if ($return_style eq 'sane') {
3913                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3914                 }
3915                 $return_style = 'sane';
3916                 $ignore_broken_returns = 1;
3917                 $return_desc = $';
3918                 $in_return = 1;
3919                 $in_deprecated = 0;
3920             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3921                 $return_start = $1;
3922                 $return_style = 'broken';
3923                 $return_desc = $';
3924                 $in_return = 1;
3925                 $in_deprecated = 0;
3926             } elsif (m%^\s*since:%i) {
3927                 $since_desc = $';
3928                 $in_since = 1;
3929                 $in_deprecated = 0;
3930             } elsif (m%^\s*stability:%i) {
3931                 $stability_desc = $';
3932                 $in_stability = 1;
3933                 $in_deprecated = 0;
3934             } else {
3935                 $deprecated_desc .= $_;
3936             }
3937             next;
3938         }
3940         # If we're in the description part, check for the 'Returns:' line.
3941         # If that isn't found, add the text to the end.
3942         if ($in_description) {
3943             # Get rid of 'Description:'
3944             s%^\s*Description:%%;
3946             if (m/^\s*(returns:|return\s+value:)/i) {
3947                 if ($return_style eq 'broken') {
3948                     $description .= $return_start . $return_desc;
3949                 }
3950                 $return_start = $1;
3951                 if ($return_style eq 'sane') {
3952                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3953                 }
3954                 $return_style = 'sane';
3955                 $ignore_broken_returns = 1;
3956                 $return_desc = $';
3957                 $in_return = 1;
3958                 next;
3959             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3960                 $return_start = $1;
3961                 $return_style = 'broken';
3962                 $return_desc = $';
3963                 $in_return = 1;
3964                 next;
3965             } elsif (m%^\s*since:%i) {
3966                 $since_desc = $';
3967                 $in_since = 1;
3968                 next;
3969             } elsif (m%^\s*deprecated:%i) {
3970                 $deprecated_desc = $';
3971                 $in_deprecated = 1;
3972                 next;
3973             } elsif (m%^\s*stability:%i) {
3974                 $stability_desc = $';
3975                 $in_stability = 1;
3976                 next;
3977             }
3979             $description .= $_;
3980             next;
3981         }
3983         # We must be in the parameters. Check for the empty line below them.
3984         if (m%^\s*$%) {
3985             $in_description = 1;
3986             next;
3987         }
3989         # Look for a parameter name.
3990         if (m%^\s*@(\S+)\s*:\s*%) {
3991             my $param_name = $1;
3992             my $param_desc = $';
3994             #print "Found parameter: $param_name\n";
3995             # Allow '...' as the Varargs parameter.
3996             if ($param_name eq "...") {
3997                 $param_name = "Varargs";
3998             }
3999             if ("\L$param_name" eq "returns") {
4000                 $return_style = 'sane';
4001                 $ignore_broken_returns = 1;
4002             }
4003             push (@params, $param_name);
4004             push (@params, $param_desc);
4005             $current_param += $PARAM_FIELD_COUNT;
4006             next;
4007         }
4009         # We must be in the middle of a parameter description, so add it on
4010         # to the last element in @params.
4011         if ($current_param == -1) {
4012             &LogWarning ($file, $., "Parsing comment block file : parameter expected.");
4013         } else {
4014             $params[$#params] .= $_;
4015         }
4016     }
4017     close (SRCFILE);
4020 #############################################################################
4021 # Function    : OutputMissingDocumentation
4022 # Description : Outputs report of documentation coverage to a file
4024 # Arguments   : none
4025 #############################################################################
4027 sub OutputMissingDocumentation {
4028     my $old_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.txt";
4029     my $new_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.new";
4031     my $n_documented = 0;
4032     my $n_incomplete = 0;
4033     my $total = 0;
4034     my $symbol;
4035     my $percent;
4036     my $msg;
4037     my $buffer = "";
4038     my $buffer_deprecated = "";
4039     my $buffer_descriptions = "";
4040     
4041     open(UNDOCUMENTED, ">$new_undocumented_file")
4042       || die "Can't create $new_undocumented_file";
4043     
4044     foreach $symbol (sort (keys (%AllSymbols))) {
4045         # FIXME: should we print LogWarnings for undocumented stuff?
4046         # DEBUG
4047         #my $ssfile = &GetSymbolSourceFile($symbol);
4048         #my $ssline = &GetSymbolSourceLine($symbol);
4049         #my $location = "defined at " . (defined($ssfile)?$ssfile:"?") . ":" . (defined($ssline)?$ssline:"0") . "\n";
4050         # DEBUG
4051         if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include|Section_Id|Image)/) {
4052             $total++;
4053             if (exists ($AllDocumentedSymbols{$symbol})) {
4054                 $n_documented++;
4055                 if (exists ($AllIncompleteSymbols{$symbol})) {
4056                     $n_incomplete++;
4057                     $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4058                     #$buffer .= "\t0: ".$location;
4059                 }
4060             } elsif (exists $Deprecated{$symbol}) {
4061                 if (exists ($AllIncompleteSymbols{$symbol})) {
4062                     $n_incomplete++;
4063                     $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4064                     #$buffer .= "\t1a: ".$location;
4065                 } else {
4066                     $buffer_deprecated .= $symbol . "\n";
4067                     #$buffer .= "\t1b: ".$location;
4068                 }
4069             } else {
4070                 if (exists ($AllIncompleteSymbols{$symbol})) {
4071                     $n_incomplete++;
4072                     $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4073                     #$buffer .= "\t2a: ".$location;
4074                 } else {
4075                     $buffer .= $symbol . "\n";
4076                     #$buffer .= "\t2b: ".$location;
4077                 }
4078             }
4079         } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
4080             $total++;
4081             #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
4082             #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
4083             #print "%%%% $symbol : $len1,$len2\n";
4084             if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
4085             || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
4086               $n_documented++;
4087             } else {
4088               # cut off the leading namespace ($TMPL_DIR)
4089               $symbol =~ m/^.*\/(.*)$/;
4090               $buffer_descriptions .= $1 . "\n";
4091             }
4092         }
4093     }
4094     
4095     $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
4096     
4097     if ($total == 0) {
4098       $percent = 100;
4099     } else {
4100       $percent = ($n_documented / $total) * 100.0;
4101     }
4102     
4103     printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
4104     print UNDOCUMENTED "$n_documented symbols documented.\n";
4105     print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
4106     print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
4107     
4108     print UNDOCUMENTED $buffer;
4109     close (UNDOCUMENTED);
4110     
4111     return &UpdateFileIfChanged ($old_undocumented_file, $new_undocumented_file, 0);
4112     
4113     printf "%.0f%% symbol docs coverage", $percent;
4114     print "($n_documented symbols documented, $n_incomplete symbols incomplete, " . ($total - $n_documented) . " not documented)\n";
4115     print "See $MODULE-undocumented.txt for a list of missing docs.\nThe doc coverage percentage doesn't include intro sections.\n";
4119 #############################################################################
4120 # Function    : OutputUndeclaredSymbols
4121 # Description : Outputs symbols that are listed in the section file, but not
4122 #               declaration is found in the sources
4124 # Arguments   : none
4125 #############################################################################
4127 sub OutputUndeclaredSymbols {
4128     my $old_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.txt";
4129     my $new_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.new";
4131     open(UNDECLARED, ">$new_undeclared_file")
4132         || die "Can't create $new_undeclared_file";
4134     if (%UndeclaredSymbols) {
4135         print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
4136         print UNDECLARED "\n";
4137         print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
4138     }
4139     close(UNDECLARED);
4141     return &UpdateFileIfChanged ($old_undeclared_file, $new_undeclared_file, 0);
4144 #############################################################################
4145 # Function    : OutputUnusedSymbols
4146 # Description : Outputs symbols that are documented in comments, but not
4147 #               declared in the sources
4149 # Arguments   : none
4150 #############################################################################
4152 sub OutputUnusedSymbols {
4153     my $num_unused = 0;
4154     my $old_unused_file = "$ROOT_DIR/$MODULE-unused.txt";
4155     my $new_unused_file = "$ROOT_DIR/$MODULE-unused.new";
4157     open (UNUSED, ">$new_unused_file")
4158         || die "Can't open $new_unused_file";
4159     my ($symbol);
4160     foreach $symbol (sort keys (%Declarations)) {
4161         if (!defined ($DeclarationOutput{$symbol})) {
4162             print (UNUSED "$symbol\n");
4163             $num_unused++;
4164         }
4165     }
4166     foreach $symbol (sort (keys (%AllUnusedSymbols))) {
4167         print (UNUSED "$symbol(" . $AllUnusedSymbols{$symbol} . ")\n");
4168         $num_unused++;
4169     }
4170     close (UNUSED);
4171     if ($num_unused != 0) {
4172         &LogWarning ($old_unused_file, 1, "$num_unused unused declarations.".
4173             "They should be added to $MODULE-sections.txt in the appropriate place.");
4174     }
4175     
4176     return &UpdateFileIfChanged ($old_unused_file, $new_unused_file, 0); 
4180 #############################################################################
4181 # Function    : OutputAllSymbols
4182 # Description : Outputs list of all symbols to a file
4184 # Arguments   : none
4185 #############################################################################
4187 sub OutputAllSymbols {
4188      my $n_documented = 0;
4189      my $total = 0;
4190      my $symbol;
4191      my $percent;
4192      my $msg;
4194      open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
4195           || die "Can't create $ROOT_DIR/$MODULE-symbols.txt: $!";
4197      foreach $symbol (sort (keys (%AllSymbols))) {
4198           print SYMBOLS $symbol . "\n";
4199      }
4201      close (SYMBOLS);
4204 #############################################################################
4205 # Function    : OutputSymbolsWithoutSince
4206 # Description : Outputs list of all symbols without a since tag to a file
4208 # Arguments   : none
4209 #############################################################################
4211 sub OutputSymbolsWithoutSince {
4212      my $n_documented = 0;
4213      my $total = 0;
4214      my $symbol;
4215      my $percent;
4216      my $msg;
4218      open (SYMBOLS, ">$ROOT_DIR/$MODULE-nosince.txt")
4219           || die "Can't create $ROOT_DIR/$MODULE-nosince.txt: $!";
4221      foreach $symbol (sort (keys (%SourceSymbolDocs))) {
4222          if (!defined $Since{$symbol}) {
4223              print SYMBOLS $symbol . "\n";
4224          }
4225      }
4227      close (SYMBOLS);
4231 #############################################################################
4232 # Function    : MergeSourceDocumentation
4233 # Description : This merges documentation read from a source file into the
4234 #               documentation read in from a template file.
4236 #               Parameter descriptions override any in the template files.
4237 #               Function descriptions are placed before any description from
4238 #               the template files.
4240 # Arguments   : none
4241 #############################################################################
4243 sub MergeSourceDocumentation {
4244     my $symbol;
4245     my @Symbols;
4247     if (scalar %SymbolDocs) {
4248         @Symbols=keys (%SymbolDocs);
4249         #print "num existing entries: ".(scalar @Symbols)."\n";
4250         #print "  ",$Symbols[0], " ",$Symbols[1],"\n";
4251     }
4252     else {
4253         # filter scanned declarations, with what we suppress from -sections.txt
4254         my %tmp = ();
4255         foreach $symbol (keys (%Declarations)) {
4256             if (defined($KnownSymbols{$symbol}) && $KnownSymbols{$symbol} == 1) {
4257                 $tmp{$symbol}=1;
4258             }
4259         }
4260         # , add the rest from -sections.txt
4261         foreach $symbol (keys (%KnownSymbols)) {
4262             if ($KnownSymbols{$symbol} == 1) {
4263                 $tmp{$symbol}=1;
4264             }
4265         }
4266         # and add whats found in the source
4267         foreach $symbol (keys (%SourceSymbolDocs)) {
4268             $tmp{$symbol}=1;
4269         }
4270         @Symbols = keys (%tmp);
4271         #print "num source entries: ".(scalar @Symbols)."\n";
4272     }
4273     foreach $symbol (@Symbols) {
4274         $AllSymbols{$symbol} = 1;
4276         my $have_tmpl_docs = 0;
4278         ## See if the symbol is documented in template
4279         my $tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4280         my $check_tmpl_doc =$tmpl_doc;
4281         # remove all xml-tags and whitespaces
4282         #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
4283         $check_tmpl_doc =~ s/<.*?>//g;
4284         $check_tmpl_doc =~ s/\s//g;
4285         # anything left ?
4286         if ($check_tmpl_doc ne "") {
4287             $have_tmpl_docs = 1;
4288             #print "## [$check_tmpl_doc]\n";
4289         } else {
4290             $tmpl_doc = "";
4291         }
4293         if (exists ($SourceSymbolDocs{$symbol})) {
4294             my $type = $DeclarationTypes {$symbol};
4296             #print "merging [$symbol] from source\n";
4298             my $item = "Parameter";
4299             if (defined ($type)) {
4300                 if ($type eq 'STRUCT') {
4301                     $item = "Field";
4302                 } elsif ($type eq 'ENUM') {
4303                     $item = "Value";
4304                 } elsif ($type eq 'UNION') {
4305                     $item = "Field";
4306                 }
4307             } else {
4308                 $type="SIGNAL";
4309             }
4311             my $src_doc = $SourceSymbolDocs{$symbol};
4312             # remove leading and training whitespaces
4313             $src_doc =~ s/^\s+//;
4314             $src_doc =~ s/\s+$//;
4316             # Don't output warnings for overridden titles as titles are
4317             # automatically generated in the -sections.txt file, and thus they
4318             # are often overridden.
4319             if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
4320                 # check if content is different
4321                 if ($tmpl_doc ne $src_doc) {
4322                     #print "[$tmpl_doc] [$src_doc]\n";
4323                     &LogWarning ($SourceSymbolSourceFile{$symbol}, $SourceSymbolSourceLine{$symbol},
4324                         "Documentation in template ".$SymbolSourceFile{$symbol}.":".$SymbolSourceLine{$symbol}." for $symbol being overridden by inline comments.");
4325                 }
4326             }
4328             if ($src_doc ne "") {
4329                  $AllDocumentedSymbols{$symbol} = 1;
4330             }
4332             # Convert <!--PARAMETERS--> with any blank lines around it to
4333             # a </para> followed by <!--PARAMETERS--> followed by <para>.
4334             $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
4336             # Do not add <para> to nothing, it breaks missing docs checks.
4337             my $src_doc_para = "";
4338             if ($src_doc ne "") {
4339                 # If there is a blank line, finish the paragraph and start another.
4340                 $src_doc = &ConvertBlankLines ($src_doc, $symbol);
4341                 $src_doc_para = "<para>\n$src_doc\n</para>";
4342                 # fixup xml markup
4343                 $src_doc_para =~ s%<para>\n<refsect2%<refsect2%gms;
4344                 $src_doc_para =~ s%</refsect2>\n</para>%</refsect2>%gms;
4345                 #print "$symbol : [$src_doc][$src_doc_para]\n";
4346             }
4348             if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
4349                 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4350             } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
4351                 # For the title/summary/see also section docs we don't want to
4352                 # add any <para> tags.
4353                 $SymbolDocs{$symbol} = "$src_doc"
4354             } else {
4355                 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4356             }
4358             # merge parameters
4359             if ($symbol =~ m/.*::.*/) {
4360                 # For signals we prefer the param names from the source docs,
4361                 # since the ones from the templates are likely to contain the
4362                 # artificial argn names which are generated by gtkdoc-scangobj.
4363                 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4364                 # FIXME: we need to check for empty docs here as well!
4365             } else {
4366                 # The templates contain the definitive parameter names and order,
4367                 # so we will not change that. We only override the actual text.
4368                 my $tmpl_params = $SymbolParams{$symbol};
4369                 if (!defined ($tmpl_params)) {
4370                     #print "No merge needed for $symbol\n";
4371                     $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4372                     #  FIXME: we still like to get the number of params and merge
4373                     #  1) we would noticed that params have been removed/renamed
4374                     #  2) we would catch undocumented params
4375                     #  params are not (yet) exported in -decl.txt so that we
4376                     #  could easily grab them :/
4377                 } else {
4378                     my $params = $SourceSymbolParams{$symbol};
4379                     my $j;
4380                     #print "Merge needed for $symbol, tmpl_params: ",$#$tmpl_params,", source_params: ",$#$params," \n";
4381                     for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4382                         my $tmpl_param_name = $$tmpl_params[$j];
4384                         # Allow '...' as the Varargs parameter.
4385                         if ($tmpl_param_name eq "...") {
4386                             $tmpl_param_name = "Varargs";
4387                         }
4389                         # Try to find the param in the source comment documentation.
4390                         my $found = 0;
4391                         my $k;
4392                         #print "  try merge param $tmpl_param_name\n";
4393                         for ($k = 0; $k <= $#$params; $k += $PARAM_FIELD_COUNT) {
4394                             my $param_name = $$params[$k];
4395                             my $param_desc = $$params[$k + 1];
4397                             #print "    test param  $param_name\n";
4398                             # We accept changes in case, since the Gnome source
4399                             # docs contain a lot of these.
4400                             if ("\L$param_name" eq "\L$tmpl_param_name") {
4401                                 $found = 1;
4403                                 # Override the description.
4404                                 $$tmpl_params[$j + 1] = $param_desc;
4406                                 # Set the name to "" to mark it as used.
4407                                 $$params[$k] = "";
4408                                 last;
4409                             }
4410                         }
4412                         # If it looks like the parameters are there, but not
4413                         # in the right place, try to explain a bit better.
4414                         if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
4415                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4416                                 "Parameters for $symbol must start on the line immediately after the function or macro name.");
4417                         }
4418                     }
4420                     # Now we output a warning if parameters have been described which
4421                     # do not exist.
4422                     for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
4423                         my $param_name = $$params[$j];
4424                         if ($param_name) {
4425                             # the template builder cannot detect if a macro returns
4426                             # a result or not
4427                             if(($type eq "MACRO") && ($param_name eq "Returns")) {
4428                                 # FIXME: do we need to add it then to tmpl_params[] ?
4429                                 my $num=$#$tmpl_params;
4430                                 #print "  adding Returns: to macro docs for $symbol.\n";
4431                                 $$tmpl_params[$num+1]="Returns";
4432                                 $$tmpl_params[$num+2]=$$params[$j+1];
4433                                 next;
4434                             }
4435                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4436                                 "$item described in source code comment block but does not exist. $type: $symbol $item: $param_name.");
4437                         }
4438                     }
4439                 }
4440             }
4441         } else {
4442             if ($have_tmpl_docs) {
4443                 $AllDocumentedSymbols{$symbol} = 1;
4444                 #print "merging [$symbol] from template\n";
4445             }
4446             else {
4447                 #print "[$symbol] undocumented\n";
4448             }
4449         }
4451         # if this symbol is documented, check if docs are complete
4452         $check_tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4453         # remove all xml-tags and whitespaces
4454         #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
4455         $check_tmpl_doc =~ s/<.*?>//g;
4456         $check_tmpl_doc =~ s/\s//g;
4457         if ($check_tmpl_doc ne "") {
4458             my $tmpl_params = $SymbolParams{$symbol};
4459             if (defined ($tmpl_params)) {
4460                 my $type = $DeclarationTypes {$symbol};
4462                 my $item = "Parameter";
4463                 if (defined ($type)) {
4464                     if ($type eq 'STRUCT') {
4465                         $item = "Field";
4466                     } elsif ($type eq 'ENUM') {
4467                         $item = "Value";
4468                     } elsif ($type eq 'UNION') {
4469                         $item = "Field";
4470                     }
4471                 } else {
4472                     $type="SIGNAL";
4473                 }
4475                 #print "Check param docs for $symbol, tmpl_params: ",$#$tmpl_params," entries, type=$type\n";
4477                 if ($#$tmpl_params > 0) {
4478                     my $j;
4479                     for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4480                         # Output a warning if the parameter is empty and
4481                         # remember for stats.
4482                         my $tmpl_param_name = $$tmpl_params[$j];
4483                         my $tmpl_param_desc = $$tmpl_params[$j + 1];
4484                         if ($tmpl_param_name ne "void" && $tmpl_param_desc !~ m/\S/) {
4485                             if (exists ($AllIncompleteSymbols{$symbol})) {
4486                                 $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
4487                             } else {
4488                                 $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
4489                             }
4490                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4491                                 "$item description for $symbol"."::"."$tmpl_param_name is missing in source code comment block.");
4492                         }
4493                     }
4494                 }
4495                 else {
4496                     if ($#$tmpl_params == 0) {
4497                         $AllIncompleteSymbols{$symbol}="<items>";
4498                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4499                             "$item descriptions for $symbol are missing in source code comment block.");
4500                     }
4501                     # $#$tmpl_params==-1 means we don't know about parameters
4502                     # this unfortunately does not tell if there should be some
4503                 }
4504             }
4505         }
4506    }
4507    #print "num doc entries: ".(scalar %SymbolDocs)."\n";
4510 #############################################################################
4511 # Function    : IsEmptyDoc
4512 # Description : Check if a doc-string is empty. Its also regarded as empty if
4513 #               it only consist of whitespace or e.g. FIXME.
4514 # Arguments   : the doc-string
4515 #############################################################################
4516 sub IsEmptyDoc {
4517     my ($doc) = @_;
4518     
4519     if ($doc =~ /^\s*$/) {
4520         return 1;
4521     }
4523     if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
4524         return 1;
4525     }
4527     return 0;
4531 # This converts blank lines to "</para><para>", but only outside CDATA and
4532 # <programlisting> tags.
4533 sub ConvertBlankLines {
4534     return &ModifyXMLElements ($_[0], $_[1],
4535                                "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
4536                                \&ConvertBlankLinesEndTag,
4537                                \&ConvertBlankLinesCallback);
4541 sub ConvertBlankLinesEndTag {
4542   if ($_[0] eq "<!\[CDATA\[") {
4543     return "]]>";
4544   } elsif ($_[0] eq "|[") {
4545     return "]\\|";
4546   } else {
4547     return "</programlisting>";
4548   }
4551 sub ConvertBlankLinesCallback {
4552   my ($text, $symbol, $tag) = @_;
4554   # If we're not in CDATA or a <programlisting> we convert blank lines so
4555   # they start a new <para>.
4556   if ($tag eq "") {
4557     $text =~ s%\n{2,}%\n</para>\n<para>\n%g;
4558   }
4560   return $text;
4564 #############################################################################
4565 # LIBRARY FUNCTIONS -   These functions are used in both gtkdoc-mkdb and
4566 #                       gtkdoc-mktmpl and should eventually be moved to a
4567 #                       separate library.
4568 #############################################################################
4570 #############################################################################
4571 # Function    : ReadDeclarationsFile
4572 # Description : This reads in a file containing the function/macro/enum etc.
4573 #               declarations.
4575 #               Note that in some cases there are several declarations with
4576 #               the same name, e.g. for conditional macros. In this case we
4577 #               set a flag in the %DeclarationConditional hash so the
4578 #               declaration is not shown in the docs.
4580 #               If a macro and a function have the same name, e.g. for
4581 #               gtk_object_ref, the function declaration takes precedence.
4583 #               Some opaque structs are just declared with 'typedef struct
4584 #               _name name;' in which case the declaration may be empty.
4585 #               The structure may have been found later in the header, so
4586 #               that overrides the empty declaration.
4588 # Arguments   : $file - the declarations file to read
4589 #               $override - if declarations in this file should override
4590 #                       any current declaration.
4591 #############################################################################
4593 sub ReadDeclarationsFile {
4594     my ($file, $override) = @_;
4596     if ($override == 0) {
4597         %Declarations = ();
4598         %DeclarationTypes = ();
4599         %DeclarationConditional = ();
4600         %DeclarationOutput = ();
4601     }
4603     open (INPUT, $file)
4604         || die "Can't open $file: $!";
4605     my $declaration_type = "";
4606     my $declaration_name;
4607     my $declaration;
4608     my $is_deprecated = 0;
4609     while (<INPUT>) {
4610         if (!$declaration_type) {
4611             if (m/^<([^>]+)>/) {
4612                 $declaration_type = $1;
4613                 $declaration_name = "";
4614                 #print "Found declaration: $declaration_type\n";
4615                 $declaration = "";
4616             }
4617         } else {
4618             if (m%^<NAME>(.*)</NAME>%) {
4619                 $declaration_name = $1;
4620             } elsif (m%^<DEPRECATED/>%) {
4621                 $is_deprecated = 1;
4622             } elsif (m%^</$declaration_type>%) {
4623                 #print "Found end of declaration: $declaration_name\n";
4624                 # Check that the declaration has a name
4625                 if ($declaration_name eq "") {
4626                     print "ERROR: $declaration_type has no name $file:$.\n";
4627                 }
4629                 # If the declaration is an empty typedef struct _XXX XXX
4630                 # set the flag to indicate the struct has a typedef.
4631                 if ($declaration_type eq 'STRUCT'
4632                     && $declaration =~ m/^\s*$/) {
4633                     #print "Struct has typedef: $declaration_name\n";
4634                     $StructHasTypedef{$declaration_name} = 1;
4635                 }
4637                 # Check if the symbol is already defined.
4638                 if (defined ($Declarations{$declaration_name})
4639                     && $override == 0) {
4640                     # Function declarations take precedence.
4641                     if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
4642                         # Ignore it.
4643                     } elsif ($declaration_type eq 'FUNCTION') {
4644                         if ($is_deprecated) {
4645                             $Deprecated{$declaration_name} = "";
4646                         }
4647                         $Declarations{$declaration_name} = $declaration;
4648                         $DeclarationTypes{$declaration_name} = $declaration_type;
4649                     } elsif ($DeclarationTypes{$declaration_name}
4650                               eq $declaration_type) {
4651                         # If the existing declaration is empty, or is just a
4652                         # forward declaration of a struct, override it.
4653                         if ($declaration_type eq 'STRUCT') {
4654                             if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4655                                 if ($is_deprecated) {
4656                                     $Deprecated{$declaration_name} = "";
4657                                 }
4658                                 $Declarations{$declaration_name} = $declaration;
4659                             } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4660                                 # Ignore an empty or forward declaration.
4661                             } else {
4662                                 &LogWarning ($file, $., "Structure $declaration_name has multiple definitions.");
4663                             }
4664                         } else {
4665                             # set flag in %DeclarationConditional hash for
4666                             # multiply defined macros/typedefs.
4667                             $DeclarationConditional{$declaration_name} = 1;
4668                         }
4669                     } else {
4670                         &LogWarning ($file, $., "$declaration_name has multiple definitions.");
4671                     }
4672                 } else {
4673                     if ($is_deprecated) {
4674                         $Deprecated{$declaration_name} = "";
4675                     }
4676                     $Declarations{$declaration_name} = $declaration;
4677                     $DeclarationTypes{$declaration_name} = $declaration_type;
4678                 }
4680                 $declaration_type = "";
4681                 $is_deprecated = 0;
4682             } else {
4683                 $declaration .= $_;
4684             }
4685         }
4686     }
4687     close (INPUT);
4691 #############################################################################
4692 # Function    : ReadSignalsFile
4693 # Description : This reads in an existing file which contains information on
4694 #               all GTK signals. It creates the arrays @SignalNames and
4695 #               @SignalPrototypes containing info on the signals. The first
4696 #               line of the SignalPrototype is the return type of the signal
4697 #               handler. The remaining lines are the parameters passed to it.
4698 #               The last parameter, "gpointer user_data" is always the same
4699 #               so is not included.
4700 # Arguments   : $file - the file containing the signal handler prototype
4701 #                       information.
4702 #############################################################################
4704 sub ReadSignalsFile {
4705     my ($file) = @_;
4707     my $in_signal = 0;
4708     my $signal_object;
4709     my $signal_name;
4710     my $signal_returns;
4711     my $signal_flags;
4712     my $signal_prototype;
4714     # Reset the signal info.
4715     @SignalObjects = ();
4716     @SignalNames = ();
4717     @SignalReturns = ();
4718     @SignalFlags = ();
4719     @SignalPrototypes = ();
4721     if (! -f $file) {
4722         return;
4723     }
4724     if (!open (INPUT, $file)) {
4725         warn "Can't open $file - skipping signals\n";
4726         return;
4727     }
4728     while (<INPUT>) {
4729         if (!$in_signal) {
4730             if (m/^<SIGNAL>/) {
4731                 $in_signal = 1;
4732                 $signal_object = "";
4733                 $signal_name = "";
4734                 $signal_returns = "";
4735                 $signal_prototype = "";
4736             }
4737         } else {
4738             if (m/^<NAME>(.*)<\/NAME>/) {
4739                 $signal_name = $1;
4740                 if ($signal_name =~ m/^(.*)::(.*)$/) {
4741                     $signal_object = $1;
4742                     ($signal_name = $2) =~ s/_/-/g;
4743                     #print "Found signal: $signal_name\n";
4744                 } else {
4745                     &LogWarning ($file, $., "Invalid signal name: $signal_name.");
4746                 }
4747             } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
4748                 $signal_returns = $1;
4749             } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4750                 $signal_flags = $1;
4751             } elsif (m%^</SIGNAL>%) {
4752                 #print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
4753                 push (@SignalObjects, $signal_object);
4754                 push (@SignalNames, $signal_name);
4755                 push (@SignalReturns, $signal_returns);
4756                 push (@SignalFlags, $signal_flags);
4757                 push (@SignalPrototypes, $signal_prototype);
4758                 $in_signal = 0;
4759             } else {
4760                 $signal_prototype .= $_;
4761             }
4762         }
4763     }
4764     close (INPUT);
4768 #############################################################################
4769 # Function    : ReadTemplateFile
4770 # Description : This reads in the manually-edited documentation file
4771 #               corresponding to the file currently being created, so we can
4772 #               insert the documentation at the appropriate places.
4773 #               It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
4774 #               is a hash of arrays.
4775 #               NOTE: This function is duplicated in gtkdoc-mktmpl (but
4776 #               slightly different).
4777 # Arguments   : $docsfile - the template file to read in.
4778 #               $skip_unused_params - 1 if the unused parameters should be
4779 #                       skipped.
4780 #############################################################################
4782 sub ReadTemplateFile {
4783     my ($docsfile, $skip_unused_params) = @_;
4785     my $template = "$docsfile.sgml";
4786     if (! -f $template) {
4787         #print "File doesn't exist: $template\n";
4788         return 0;
4789     }
4790     #print "Reading $template\n";
4792     # start with empty hashes, we merge the source comment for each file
4793     # afterwards
4794     %SymbolDocs = ();
4795     %SymbolTypes = ();
4796     %SymbolParams = ();
4798     my $current_type = "";      # Type of symbol being read.
4799     my $current_symbol = "";    # Name of symbol being read.
4800     my $symbol_doc = "";                # Description of symbol being read.
4801     my @params;                 # Parameter names and descriptions of current
4802                                 #   function/macro/function typedef.
4803     my $current_param = -1;     # Index of parameter currently being read.
4804                                 #   Note that the param array contains pairs
4805                                 #   of param name & description.
4806     my $in_unused_params = 0;   # True if we are reading in the unused params.
4807     my $in_deprecated = 0;
4808     my $in_since = 0;
4809     my $in_stability = 0;
4811     open (DOCS, "$template")
4812         || die "Can't open $template: $!";
4813     while (<DOCS>) {
4814         if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
4815             my $type = $1;
4816             my $symbol = $2;
4817             if ($symbol eq "Title"
4818                 || $symbol eq "Short_Description"
4819                 || $symbol eq "Long_Description"
4820                 || $symbol eq "See_Also"
4821                 || $symbol eq "Stability_Level"
4822                 || $symbol eq "Include"
4823                 || $symbol eq "Image") {
4825                 $symbol = $docsfile . ":" . $symbol;
4826             }
4828             #print "Found symbol: $symbol\n";
4829             # Remember file and line for the symbol
4830             $SymbolSourceFile{$symbol} = $template;
4831             $SymbolSourceLine{$symbol} = $.;
4833             # Store previous symbol, but remove any trailing blank lines.
4834             if ($current_symbol ne "") {
4835                 $symbol_doc =~ s/\s+$//;
4836                 $SymbolTypes{$current_symbol} = $current_type;
4837                 $SymbolDocs{$current_symbol} = $symbol_doc;
4839                 # Check that the stability level is valid.
4840                 if ($StabilityLevel{$current_symbol}) {
4841                     $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4842                 }
4844                 if ($current_param >= 0) {
4845                     $SymbolParams{$current_symbol} = [ @params ];
4846                 } else {
4847                     # Delete any existing params in case we are overriding a
4848                     # previously read template.
4849                     delete $SymbolParams{$current_symbol};
4850                 }
4851             }
4852             $current_type = $type;
4853             $current_symbol = $symbol;
4854             $current_param = -1;
4855             $in_unused_params = 0;
4856             $in_deprecated = 0;
4857             $in_since = 0;
4858             $in_stability = 0;
4859             $symbol_doc = "";
4860             @params = ();
4862         } elsif (m/^<!-- # Unused Parameters # -->/) {
4863             #print "DEBUG: Found unused parameters\n";
4864             $in_unused_params = 1;
4865             next;
4867         } elsif ($in_unused_params && $skip_unused_params) {
4868             # When outputting the DocBook we skip unused parameters.
4869             #print "DEBUG: Skipping unused param: $_";
4870             next;
4872         } else {
4873             # Check if param found. Need to handle "..." and "format...".
4874             if (s/^\@([\w\.]+):\040?//) {
4875                 my $param_name = $1;
4876                 my $param_desc = $_;
4877                 # Allow variations of 'Returns'
4878                 if ($param_name =~ m/^[Rr]eturns?$/) {
4879                     $param_name = "Returns";
4880                 }
4882                 # strip trailing whitespaces and blank lines
4883                 s/\s+\n$/\n/m;
4884                 s/\n+$/\n/sm;
4885                 #print "Found param for symbol $current_symbol : '$param_name'= '$_'";
4887                 if ($param_name eq "Deprecated") {
4888                     $in_deprecated = 1;
4889                     $Deprecated{$current_symbol} = $_;
4890                 } elsif ($param_name eq "Since") {
4891                     $in_since = 1;
4892                     chomp;
4893                     $Since{$current_symbol} = $_;
4894                 } elsif ($param_name eq "Stability") {
4895                     $in_stability = 1;
4896                     $StabilityLevel{$current_symbol} = $_;
4897                 } else {
4898                     push (@params, $param_name);
4899                     push (@params, $param_desc);
4900                     $current_param += $PARAM_FIELD_COUNT;
4901                 }
4902             } else {
4903                 # strip trailing whitespaces and blank lines
4904                 s/\s+\n$/\n/m;
4905                 s/\n+$/\n/sm;
4906                 
4907                 if (!m/^\s+$/) {
4908                     if ($in_deprecated) {
4909                         $Deprecated{$current_symbol} .= $_;
4910                     } elsif ($in_since) {
4911                         &LogWarning ($template, $., "multi-line since docs found");
4912                         #$Since{$current_symbol} .= $_;
4913                     } elsif ($in_stability) {
4914                         $StabilityLevel{$current_symbol} .= $_;
4915                     } elsif ($current_param >= 0) {
4916                         $params[$current_param] .= $_;
4917                     } else {
4918                         $symbol_doc .= $_;
4919                     }
4920                 }
4921             }
4922         }
4923     }
4925     # Remember to finish the current symbol doccs.
4926     if ($current_symbol ne "") {
4928         $symbol_doc =~ s/\s+$//;
4929         $SymbolTypes{$current_symbol} = $current_type;
4930         $SymbolDocs{$current_symbol} = $symbol_doc;
4932         # Check that the stability level is valid.
4933         if ($StabilityLevel{$current_symbol}) {
4934             $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4935         }
4937         if ($current_param >= 0) {
4938             $SymbolParams{$current_symbol} = [ @params ];
4939         } else {
4940             # Delete any existing params in case we are overriding a
4941             # previously read template.
4942             delete $SymbolParams{$current_symbol};
4943         }
4944     }
4946     close (DOCS);
4947     return 1;
4951 #############################################################################
4952 # Function    : ReadObjectHierarchy
4953 # Description : This reads in the $MODULE-hierarchy.txt file containing all
4954 #               the GtkObject subclasses described in this module (and their
4955 #               ancestors).
4956 #               It places them in the @Objects array, and places their level
4957 #               in the object hierarchy in the @ObjectLevels array, at the
4958 #               same index. GtkObject, the root object, has a level of 1.
4960 #               FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
4961 #               as it goes along, this should be split out into a separate
4962 #               function.
4964 # Arguments   : none
4965 #############################################################################
4967 sub ReadObjectHierarchy {
4968     @Objects = ();
4969     @ObjectLevels = ();
4971     if (! -f $OBJECT_TREE_FILE) {
4972         return;
4973     }
4974     if (!open (INPUT, $OBJECT_TREE_FILE)) {
4975         warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
4976         return;
4977     }
4979     # FIXME: use $OUTPUT_FORMAT
4980     # my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.$OUTPUT_FORMAT";
4981     my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
4982     my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
4984     open (OUTPUT, ">$new_tree_index")
4985         || die "Can't create $new_tree_index: $!";
4987     if ($OUTPUT_FORMAT eq "xml") {
4988         my $tree_header = $doctype_header;
4990         $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
4991         print (OUTPUT "$tree_header");
4992     }
4993     print (OUTPUT "<screen>\n");
4995     # Only emit objects if they are supposed to be documented, or if
4996     # they have documented children. To implement this, we maintain a
4997     # stack of pending objects which will be emitted if a documented
4998     # child turns up.
4999     my @pending_objects = ();
5000     my @pending_levels = ();
5001     while (<INPUT>) {
5002         if (m/\S+/) {
5003             my $object = $&;
5004             my $level = (length($`)) / 2 + 1;
5005             my $xref = "";
5007             while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
5008                 my $pobject = pop(@pending_objects);
5009                 my $plevel = pop(@pending_levels);
5010             }
5012             push (@pending_objects, $object);
5013             push (@pending_levels, $level);
5015             if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5016                 while ($#pending_levels >= 0) {
5017                     $object = shift @pending_objects;
5018                     $level = shift @pending_levels;
5019                     $xref = &MakeXRef ($object);
5021                     print (OUTPUT ' ' x ($level * 4), "$xref\n");
5022                     push (@Objects, $object);
5023                     push (@ObjectLevels, $level);
5024                 }
5025             }
5026             #else {
5027             #    LogWarning ($OBJECT_TREE_FILE, $., "unknown type $object");
5028             #}
5029         }
5030     }
5031     print (OUTPUT "</screen>\n");
5033     close (INPUT);
5034     close (OUTPUT);
5036     &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
5038     &OutputObjectList;
5041 #############################################################################
5042 # Function    : ReadInterfaces
5043 # Description : This reads in the $MODULE.interfaces file.
5045 # Arguments   : none
5046 #############################################################################
5048 sub ReadInterfaces {
5049     %Interfaces = ();
5051     if (! -f $INTERFACES_FILE) {
5052         return;
5053     }
5054     if (!open (INPUT, $INTERFACES_FILE)) {
5055         warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
5056         return;
5057     }
5059     while (<INPUT>) {
5060        chomp;
5061        my ($object, @ifaces) = split;
5062        if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5063            my @knownIfaces = ();
5065            # filter out private interfaces, but leave foreign interfaces
5066            foreach my $iface (@ifaces) {
5067                if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
5068                    push (@knownIfaces, $iface);
5069                }
5070              }
5072            $Interfaces{$object} = join(' ', @knownIfaces);
5073        }
5074     }
5075     close (INPUT);
5078 #############################################################################
5079 # Function    : ReadPrerequisites
5080 # Description : This reads in the $MODULE.prerequisites file.
5082 # Arguments   : none
5083 #############################################################################
5085 sub ReadPrerequisites {
5086     %Prerequisites = ();
5088     if (! -f $PREREQUISITES_FILE) {
5089         return;
5090     }
5091     if (!open (INPUT, $PREREQUISITES_FILE)) {
5092         warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
5093         return;
5094     }
5096     while (<INPUT>) {
5097        chomp;
5098        my ($iface, @prereqs) = split;
5099        if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
5100            my @knownPrereqs = ();
5102            # filter out private prerequisites, but leave foreign prerequisites
5103            foreach my $prereq (@prereqs) {
5104                if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
5105                   push (@knownPrereqs, $prereq);
5106                }
5107            }
5109            $Prerequisites{$iface} = join(' ', @knownPrereqs);
5110        }
5111     }
5112     close (INPUT);
5115 #############################################################################
5116 # Function    : ReadArgsFile
5117 # Description : This reads in an existing file which contains information on
5118 #               all GTK args. It creates the arrays @ArgObjects, @ArgNames,
5119 #               @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
5120 #               on the args.
5121 # Arguments   : $file - the file containing the arg information.
5122 #############################################################################
5124 sub ReadArgsFile {
5125     my ($file) = @_;
5127     my $in_arg = 0;
5128     my $arg_object;
5129     my $arg_name;
5130     my $arg_type;
5131     my $arg_flags;
5132     my $arg_nick;
5133     my $arg_blurb;
5134     my $arg_default;
5135     my $arg_range;
5137     # Reset the args info.
5138     @ArgObjects = ();
5139     @ArgNames = ();
5140     @ArgTypes = ();
5141     @ArgFlags = ();
5142     @ArgNicks = ();
5143     @ArgBlurbs = ();
5144     @ArgDefaults = ();
5145     @ArgRanges = ();
5147     if (! -f $file) {
5148         return;
5149     }
5150     if (!open (INPUT, $file)) {
5151         warn "Can't open $file - skipping args\n";
5152         return;
5153     }
5154     while (<INPUT>) {
5155         if (!$in_arg) {
5156             if (m/^<ARG>/) {
5157                 $in_arg = 1;
5158                 $arg_object = "";
5159                 $arg_name = "";
5160                 $arg_type = "";
5161                 $arg_flags = "";
5162                 $arg_nick = "";
5163                 $arg_blurb = "";
5164                 $arg_default = "";
5165                 $arg_range = "";
5166             }
5167         } else {
5168             if (m/^<NAME>(.*)<\/NAME>/) {
5169                 $arg_name = $1;
5170                 if ($arg_name =~ m/^(.*)::(.*)$/) {
5171                     $arg_object = $1;
5172                     ($arg_name = $2) =~ s/_/-/g;
5173                     #print "Found arg: $arg_name\n";
5174                 } else {
5175                     &LogWarning ($file, $., "Invalid argument name: $arg_name");
5176                 }
5177             } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
5178                 $arg_type = $1;
5179             } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
5180                 $arg_range = $1;
5181             } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
5182                 $arg_flags = $1;
5183             } elsif (m/^<NICK>(.*)<\/NICK>/) {
5184                 $arg_nick = $1;
5185             } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
5186                 $arg_blurb = $1;
5187                 if ($arg_blurb eq "(null)") {
5188                   $arg_blurb = "";
5189                   &LogWarning ($file, $., "Property ${arg_object}:${arg_name} has no documentation.");
5190                 }
5191             } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
5192                 $arg_default = $1;
5193             } elsif (m%^</ARG>%) {
5194                 #print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
5195                 push (@ArgObjects, $arg_object);
5196                 push (@ArgNames, $arg_name);
5197                 push (@ArgTypes, $arg_type);
5198                 push (@ArgRanges, $arg_range);
5199                 push (@ArgFlags, $arg_flags);
5200                 push (@ArgNicks, $arg_nick);
5201                 push (@ArgBlurbs, $arg_blurb);
5202                 push (@ArgDefaults, $arg_default);
5203                 $in_arg = 0;
5204             }
5205         }
5206     }
5207     close (INPUT);
5211 #############################################################################
5212 # Function    : CheckIsObject
5213 # Description : Returns 1 if the given name is a GObject or a subclass.
5214 #               It uses the global @Objects array.
5215 #               Note that the @Objects array only contains classes in the
5216 #               current module and their ancestors - not all GObject classes.
5217 # Arguments   : $name - the name to check.
5218 #############################################################################
5220 sub CheckIsObject {
5221     my ($name) = @_;
5223     my $object;
5224     foreach $object (@Objects) {
5225         if ($object eq $name) {
5226             return 1;
5227         }
5228     }
5229     return 0;
5233 #############################################################################
5234 # Function    : MakeReturnField
5235 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
5236 # Arguments   : $str - the string to pad.
5237 #############################################################################
5239 sub MakeReturnField {
5240     my ($str) = @_;
5242     return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));
5245 #############################################################################
5246 # Function    : GetSymbolSourceFile
5247 # Description : Get the filename where the symbol docs where taken from.
5248 # Arguments   : $symbol - the symbol name
5249 #############################################################################
5251 sub GetSymbolSourceFile {
5252     my ($symbol) = @_;
5254     if (defined($SourceSymbolSourceFile{$symbol})) {
5255         return $SourceSymbolSourceFile{$symbol};
5256     } elsif (defined($SymbolSourceFile{$symbol})) {
5257         return $SymbolSourceFile{$symbol};
5258     } else {
5259         return "";
5260     }
5263 #############################################################################
5264 # Function    : GetSymbolSourceLine
5265 # Description : Get the file line where the symbol docs where taken from.
5266 # Arguments   : $symbol - the symbol name
5267 #############################################################################
5269 sub GetSymbolSourceLine {
5270     my ($symbol) = @_;
5272     if (defined($SourceSymbolSourceLine{$symbol})) {
5273         return $SourceSymbolSourceLine{$symbol};
5274     } elsif (defined($SymbolSourceLine{$symbol})) {
5275         return $SymbolSourceLine{$symbol};
5276     } else {
5277         return 0;
5278     }