design: plans for less report files
[gtk-doc.git] / gtkdoc-mkdb.in
blob625b752749b3d8578d1f29c8da211744437d4d49
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 if (lc($OUTPUT_FORMAT) eq "xml") {
122     if (!$MAIN_SGML_FILE) {
123         # backwards compatibility
124         if (-e "${MODULE}-docs.sgml") {
125             $MAIN_SGML_FILE="${MODULE}-docs.sgml";
126         } else {
127             $MAIN_SGML_FILE="${MODULE}-docs.xml";
128         }
129     }
130     $OUTPUT_FORMAT = "xml";
131     $empty_element_end = "/>";
133     if (-e $MAIN_SGML_FILE) {
134         open(INPUT, "<$MAIN_SGML_FILE") || die "Can't open $MAIN_SGML_FILE";
135         $doctype_header = "";
136         while (<INPUT>) {
137             if (/^\s*<(book|chapter|article)/) {
138                 if ($_ !~ m/http:\/\/www.w3.org\/200[13]\/XInclude/) {
139                     $doctype_header = "";
140                 }
141                 last;
142             }
143             $doctype_header .= $_;
144         }
145         close(INPUT);
146     } else {
147         $doctype_header =
148 "<?xml version=\"1.0\"?>\n" .
149 "<!DOCTYPE book PUBLIC \"-//OASIS//DTD DocBook XML V4.3//EN\"\n" .
150 "               \"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd\">\n";
151     }
152     $doctype_header =~ s/<!DOCTYPE \w+/<!DOCTYPE refentry/;
153 } else {
154     if (!$MAIN_SGML_FILE) {
155         $MAIN_SGML_FILE="${MODULE}-docs.sgml";
156     }
157     $OUTPUT_FORMAT = "sgml";
158     $doctype_header = "";
159     $empty_element_end = ">";
162 my $ROOT_DIR = ".";
164 # All the files are written in subdirectories beneath here.
165 $TMPL_DIR = $TMPL_DIR ? $TMPL_DIR : "$ROOT_DIR/tmpl";
167 # This is where we put all the DocBook output.
168 $SGML_OUTPUT_DIR = $SGML_OUTPUT_DIR ? $SGML_OUTPUT_DIR : "$ROOT_DIR/$OUTPUT_FORMAT";
170 # This file contains the object hierarchy.
171 my $OBJECT_TREE_FILE = "$ROOT_DIR/$MODULE.hierarchy";
173 # This file contains the interfaces.
174 my $INTERFACES_FILE = "$ROOT_DIR/$MODULE.interfaces";
176 # This file contains the prerequisites.
177 my $PREREQUISITES_FILE = "$ROOT_DIR/$MODULE.prerequisites";
179 # This file contains signal arguments and names.
180 my $SIGNALS_FILE = "$ROOT_DIR/$MODULE.signals";
182 # The file containing Arg information.
183 my $ARGS_FILE = "$ROOT_DIR/$MODULE.args";
185 # These global arrays store information on signals. Each signal has an entry
186 # in each of these arrays at the same index, like a multi-dimensional array.
187 my @SignalObjects;      # The GtkObject which emits the signal.
188 my @SignalNames;        # The signal name.
189 my @SignalReturns;      # The return type.
190 my @SignalFlags;        # Flags for the signal
191 my @SignalPrototypes;   # The rest of the prototype of the signal handler.
193 # These global arrays store information on Args. Each Arg has an entry
194 # in each of these arrays at the same index, like a multi-dimensional array.
195 my @ArgObjects;         # The GtkObject which has the Arg.
196 my @ArgNames;           # The Arg name.
197 my @ArgTypes;           # The Arg type - gint, GtkArrowType etc.
198 my @ArgFlags;           # How the Arg can be used - readable/writable etc.
199 my @ArgNicks;           # The nickname of the Arg.
200 my @ArgBlurbs;          # Docstring of the Arg.
201 my @ArgDefaults;        # Default value of the Arg.
202 my @ArgRanges;          # The range of the Arg type
203 # These global hashes store declaration info keyed on a symbol name.
204 my %Declarations;
205 my %DeclarationTypes;
206 my %DeclarationConditional;
207 my %DeclarationOutput;
208 my %Deprecated;
209 my %Since;
210 my %StabilityLevel;
211 my %StructHasTypedef;
213 # These global hashes store the existing documentation.
214 my %SymbolDocs;
215 my %SymbolTypes;
216 my %SymbolParams;
217 my %SymbolSourceFile;
218 my %SymbolSourceLine;
220 # These global hashes store documentation scanned from the source files.
221 my %SourceSymbolDocs;
222 my %SourceSymbolParams;
223 my %SourceSymbolSourceFile;
224 my %SourceSymbolSourceLine;
226 # all documentation goes in here, so we can do coverage analysis
227 my %AllSymbols;
228 my %AllIncompleteSymbols;
229 my %AllDocumentedSymbols;
231 # Undeclared yet documented symbols
232 my %UndeclaredSymbols;
234 # These global arrays store GObject, subclasses and the hierarchy.
235 my @Objects;
236 my @ObjectLevels;
238 my %Interfaces;
239 my %Prerequisites;
241 # holds the symbols which are mentioned in $MODULE-sections.txt and in which
242 # section they are defined
243 my %KnownSymbols;
244 my %SymbolSection;
245 my %SymbolSectionId;
247 # collects index entries
248 my %IndexEntriesFull;
249 my %IndexEntriesSince;
250 my %IndexEntriesDeprecated;
252 # Standard C preprocessor directives, which we ignore for '#' abbreviations.
253 my %PreProcessorDirectives;
254 $PreProcessorDirectives{"assert"} = 1;
255 $PreProcessorDirectives{"define"} = 1;
256 $PreProcessorDirectives{"elif"} = 1;
257 $PreProcessorDirectives{"else"} = 1;
258 $PreProcessorDirectives{"endif"} = 1;
259 $PreProcessorDirectives{"error"} = 1;
260 $PreProcessorDirectives{"if"} = 1;
261 $PreProcessorDirectives{"ifdef"} = 1;
262 $PreProcessorDirectives{"ifndef"} = 1;
263 $PreProcessorDirectives{"include"} = 1;
264 $PreProcessorDirectives{"line"} = 1;
265 $PreProcessorDirectives{"pragma"} = 1;
266 $PreProcessorDirectives{"unassert"} = 1;
267 $PreProcessorDirectives{"undef"} = 1;
268 $PreProcessorDirectives{"warning"} = 1;
270 # remember used annotation (to write minimal glossary)
271 my %AnnotationsUsed;
273 my %AnnotationDefinition = (
274     'allow-none' => "NULL is ok, both for passing and for returning.",
275     'array' => "Parameter points to an array of items.",
276     'default' => "Default parameter value (for in case the <acronym>shadows</acronym>-to function has less parameters).",
277     'element-type' => "Generics and defining elements of containers and arrays.",
278     'error-domains' => "Typed errors. Similar to throws in Java.",
279     'in' => "Parameter for input. Default is <acronym>transfer none</acronym>.",
280     'inout' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
281     'in-out' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
282     'not-error' => "A GError parameter is not to be handled like a normal GError.",
283     'out' => "Parameter for returning results. Default is <acronym>transfer full</acronym>.",
284     'transfer container' => "Free data container after the code is done.",
285     'transfer full' => "Free data after the code is done.",
286     'transfer none' => "Don't free data after the code is done."
289 # Create the root DocBook output directory if it doens't exist.
290 if (! -e $SGML_OUTPUT_DIR) {
291     mkdir ("$SGML_OUTPUT_DIR", 0777)
292         || die "Can't create directory: $SGML_OUTPUT_DIR";
295 # Function and other declaration output settings.
296 my $RETURN_TYPE_FIELD_WIDTH = 20;
297 my $SYMBOL_FIELD_WIDTH = 36;
298 my $SIGNAL_FIELD_WIDTH = 16;
299 my $PARAM_FIELD_COUNT = 2;
301 &ReadKnownSymbols ("$ROOT_DIR/$MODULE-sections.txt");
302 &ReadSignalsFile ($SIGNALS_FILE);
303 &ReadArgsFile ($ARGS_FILE);
304 &ReadObjectHierarchy;
305 &ReadInterfaces;
306 &ReadPrerequisites;
308 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-decl.txt", 0);
309 if (-f "$ROOT_DIR/$MODULE-overrides.txt") {
310     &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-overrides.txt", 1);
313 for my $dir (@SOURCE_DIRS) {
314     &ReadSourceDocumentation ($dir);
317 my $changed = &OutputSGML ("$ROOT_DIR/$MODULE-sections.txt");
319 # If any of the DocBook SGML files have changed, update the timestamp file (so
320 # it can be used for Makefile dependencies).
321 if ($changed || ! -e "$ROOT_DIR/sgml.stamp") {
323     # try to detect the common prefix
324     # GtkWidget, GTK_WIDGET, gtk_widget -> gtk
325     if ($NAME_SPACE eq "") {
326         $NAME_SPACE="";
327         my $pos=0;
328         my $ratio=0.0;
329         do {
330             my %prefix;
331             my $letter="";
332             foreach my $symbol (keys(%IndexEntriesFull)) {
333                 if(($NAME_SPACE eq "") || $symbol =~ /^$NAME_SPACE/i) {
334                     if (length($symbol)>$pos) {
335                         $letter=substr($symbol,$pos,1);
336                         # stop prefix scanning
337                         if ($letter eq "_") {
338                             # stop on "_"
339                             last;
340                         }
341                         # Should we also stop on a uppercase char, if last was lowercase
342                         #   GtkWidget, if we have the 'W' and had the 't' before
343                         # or should we count upper and lowercase, and stop one 2nd uppercase, if we already had a lowercase
344                         #   GtkWidget, the 'W' would be the 2nd uppercase and with 't','k' we had lowercase chars before
345                         # need to recound each time as this is per symbol
346                         $prefix{uc($letter)}++;
347                     }
348                 }
349             }
350             if ($letter ne "" && $letter ne "_") {
351                 my $maxletter="";
352                 my $maxsymbols=0;
353                 foreach $letter (keys(%prefix)) {
354                     #print "$letter: $prefix{$letter}.\n";
355                     if ($prefix{$letter}>$maxsymbols) {
356                         $maxletter=$letter;
357                         $maxsymbols=$prefix{$letter};
358                     }
359                 }
360                 $ratio = scalar(keys(%IndexEntriesFull)) / $prefix{$maxletter};
361                 #print "most symbols start with $maxletter, that is ". (100 * $ratio) ." %\n";
362                 if ($ratio > 0.9) {
363                     # do another round
364                     $NAME_SPACE .= $maxletter;
365                 }
366                 $pos++;
367             }
368             else {
369                 $ratio=0.0;
370             }
371         } while ($ratio > 0.9);
372         #print "most symbols start with $NAME_SPACE\n";
373     }
375     &OutputIndexFull;
376     &OutputDeprecatedIndex;
377     &OutputSinceIndexes;
378     &OutputAnnotationGlossary;
380     open (TIMESTAMP, ">$ROOT_DIR/sgml.stamp")
381         || die "Can't create $ROOT_DIR/sgml.stamp: $!";
382     print (TIMESTAMP "timestamp");
383     close (TIMESTAMP);
386 #############################################################################
387 # Function    : OutputObjectList
388 # Description : This outputs the alphabetical list of objects, in a columned
389 #               table.
390 #               FIXME: Currently this also outputs ancestor objects
391 #               which may not actually be in this module.
392 # Arguments   : none
393 #############################################################################
395 sub OutputObjectList {
396     my $cols = 3;
397     
398     # FIXME: use $OUTPUT_FORMAT
399     # my $old_object_index = "$SGML_OUTPUT_DIR/object_index.$OUTPUT_FORMAT";
400     my $old_object_index = "$SGML_OUTPUT_DIR/object_index.sgml";
401     my $new_object_index = "$SGML_OUTPUT_DIR/object_index.new";
403     open (OUTPUT, ">$new_object_index")
404         || die "Can't create $new_object_index: $!";
406     if (lc($OUTPUT_FORMAT) eq "xml") {
407         my $header = $doctype_header;
409         $header =~ s/<!DOCTYPE \w+/<!DOCTYPE informaltable/;
410         print (OUTPUT "$header");
411     }
413     print (OUTPUT <<EOF);
414 <informaltable pgwide="1" frame="none">
415 <tgroup cols="$cols">
416 <colspec colwidth="1*"${empty_element_end}
417 <colspec colwidth="1*"${empty_element_end}
418 <colspec colwidth="1*"${empty_element_end}
419 <tbody>
422     my $count = 0;
423     my $object;
424     foreach $object (sort (@Objects)) {
425         my $xref = &MakeXRef ($object);
426         if ($count % $cols == 0) { print (OUTPUT "<row>\n"); }
427         print (OUTPUT "<entry>$xref</entry>\n");
428         if ($count % $cols == ($cols - 1)) { print (OUTPUT "</row>\n"); }
429         $count++;
430     }
431     if ($count == 0) {
432         # emit an empty row, since empty tables are invalid
433         print (OUTPUT "<row><entry> </entry></row>\n");
434     }
435     else {
436         print (OUTPUT "</row>\n");
437     }
439     print (OUTPUT <<EOF);
440 </tbody></tgroup></informaltable>
442     close (OUTPUT);
444     &UpdateFileIfChanged ($old_object_index, $new_object_index, 0);
448 #############################################################################
449 # Function    : OutputSGML
450 # Description : This collects the output for each section of the docs, and
451 #               outputs each file when the end of the section is found.
452 # Arguments   : $file - the $MODULE-sections.txt file which contains all of
453 #               the functions/macros/structs etc. being documented, organised
454 #               into sections and subsections.
455 #############################################################################
457 sub OutputSGML {
458     my ($file) = @_;
460     #print "Reading: $file\n";
461     open (INPUT, $file)
462         || die "Can't open $file: $!";
463     my $filename = "";
464     my $book_top = "";
465     my $book_bottom = "";
466     my $includes = (defined $DEFAULT_INCLUDES) ? $DEFAULT_INCLUDES : "";
467     my $section_includes = "";
468     my $in_section = 0;
469     my $title = "";
470     my $section_id = "";
471     my $subsection = "";
472     my $synopsis;
473     my $details;
474     my $num_symbols;
475     my $changed = 0;
476     my $signals_synop = "";
477     my $signals_desc = "";
478     my $args_synop = "";
479     my $child_args_synop = "";
480     my $style_args_synop = "";
481     my $args_desc = "";
482     my $child_args_desc = "";
483     my $style_args_desc = "";
484     my $hierarchy = "";
485     my $interfaces = "";
486     my $implementations = "";
487     my $prerequisites = "";
488     my $derived = "";
489     my @file_objects = ();
490     my %templates = ();
491     my %symbol_def_line = ();
493     # merge the source docs, in case there are no templates
494     &MergeSourceDocumentation;
496     while (<INPUT>) {
497         if (m/^#/) {
498             next;
500         } elsif (m/^<SECTION>/) {
501             $synopsis = "";
502             $details = "";
503             $num_symbols = 0;
504             $in_section = 1;
505             @file_objects = ();
506             %symbol_def_line = ();
508         } elsif (m/^<SUBSECTION\s*(.*)>/i) {
509             $synopsis .= "\n";
510             $subsection = $1;
512         } elsif (m/^<SUBSECTION>/) {
514         } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
515             $title = $1;
516             #print "Section: $title\n";
518             # We don't want warnings if object & class structs aren't used.
519             $DeclarationOutput{$title} = 1;
520             $DeclarationOutput{"${title}Class"} = 1;
521             $DeclarationOutput{"${title}Iface"} = 1;
522             $DeclarationOutput{"${title}Interface"} = 1;
524         } elsif (m/^<FILE>(.*)<\/FILE>/) {
525             $filename = $1;
526             if (! defined $templates{$filename}) {
527                if (&ReadTemplateFile ("$TMPL_DIR/$filename", 1)) {
528                    &MergeSourceDocumentation;
529                    $templates{$filename}=$.;
530                }
531             } else {
532                 &LogWarning ($file, $., "Double <FILE>$filename</FILE> entry. ".
533                     "Previous occurrence on line ".$templates{$filename}.".");
534             }
535             if (($title eq "") and (defined $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"})) {
536                 $title = $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"};
537                 # Remove trailing blanks
538                 $title =~ s/\s+$//;
539            }
541         } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
542             if ($in_section) {
543                 $section_includes = $1;
544             } else {
545                 if (defined $DEFAULT_INCLUDES) {
546                     &LogWarning ($file, $., "Default <INCLUDE> being overridden by command line option.");
547                 }
548                 else {
549                     $includes = $1;
550                 }
551             }
553         } elsif (m/^<\/SECTION>/) {
554             #print "End of section: $title\n";
555             if ($num_symbols > 0) {
556                 # collect documents
557                 if (lc($OUTPUT_FORMAT) eq "xml") {
558                     $book_bottom .= "    <xi:include href=\"xml/$filename.xml\"/>\n";
559                 } else {
560                     $book_top.="<!ENTITY $section_id SYSTEM \"sgml/$filename.sgml\">\n";
561                     $book_bottom .= "    &$section_id;\n";
562                 }
564                 if (defined ($SourceSymbolDocs{"$TMPL_DIR/$filename:Include"})) {
565                     if ($section_includes) {
566                         &LogWarning ($file, $., "Section <INCLUDE> being overridden by inline comments.");
567                     }
568                     $section_includes = $SourceSymbolDocs{"$TMPL_DIR/$filename:Include"};
569                 }
570                 if ($section_includes eq "") {
571                     $section_includes = $includes;
572                 }
574                  $signals_synop =~ s/^\n*//g;
575                  $signals_synop =~ s/\n+$/\n/g;
576                 if ($signals_synop ne '') {
577                     $signals_synop = <<EOF;
578 <refsect1 id="$section_id.signals" role="signal_proto">
579 <title role="signal_proto.title">Signals</title>
580 <synopsis>
581 ${signals_synop}</synopsis>
582 </refsect1>
584                      $signals_desc =~ s/^\n*//g;
585                      $signals_desc =~ s/\n+$/\n/g;
586                      $signals_desc =~ s/(\s|\n)+$//ms;
587                     $signals_desc  = <<EOF;
588 <refsect1 id="$section_id.signal-details" role="signals">
589 <title role="signals.title">Signal Details</title>
590 $signals_desc
591 </refsect1>
593                 }
595                  $args_synop =~ s/^\n*//g;
596                  $args_synop =~ s/\n+$/\n/g;
597                 if ($args_synop ne '') {
598                     $args_synop = <<EOF;
599 <refsect1 id="$section_id.properties" role="properties">
600 <title role="properties.title">Properties</title>
601 <synopsis>
602 ${args_synop}</synopsis>
603 </refsect1>
605                      $args_desc =~ s/^\n*//g;
606                      $args_desc =~ s/\n+$/\n/g;
607                      $args_desc =~ s/(\s|\n)+$//ms;
608                     $args_desc  = <<EOF;
609 <refsect1 id="$section_id.property-details" role="property_details">
610 <title role="property_details.title">Property Details</title>
611 $args_desc
612 </refsect1>
614                 }
616                  $child_args_synop =~ s/^\n*//g;
617                  $child_args_synop =~ s/\n+$/\n/g;
618                 if ($child_args_synop ne '') {
619                     $args_synop .= <<EOF;
620 <refsect1 id="$section_id.child-properties" role="child_properties">
621 <title role="child_properties.title">Child Properties</title>
622 <synopsis>
623 ${child_args_synop}</synopsis>
624 </refsect1>
626                      $child_args_desc =~ s/^\n*//g;
627                      $child_args_desc =~ s/\n+$/\n/g;
628                      $child_args_desc =~ s/(\s|\n)+$//ms;
629                     $args_desc .= <<EOF;
630 <refsect1 id="$section_id.child-property-details" role="child_property_details">
631 <title role="child_property_details.title">Child Property Details</title>
632 $child_args_desc
633 </refsect1>
635                 }
637                  $style_args_synop =~ s/^\n*//g;
638                  $style_args_synop =~ s/\n+$/\n/g;
639                 if ($style_args_synop ne '') {
640                     $args_synop .= <<EOF;
641 <refsect1 id="$section_id.style-properties" role="style_properties">
642 <title role="style_properties.title">Style Properties</title>
643 <synopsis>
644 ${style_args_synop}</synopsis>
645 </refsect1>
647                      $style_args_desc =~ s/^\n*//g;
648                      $style_args_desc =~ s/\n+$/\n/g;
649                      $style_args_desc =~ s/(\s|\n)+$//ms;
650                     $args_desc .= <<EOF;
651 <refsect1 id="$section_id.style-property-details" role="style_properties_details">
652 <title role="style_properties_details.title">Style Property Details</title>
653 $style_args_desc
654 </refsect1>
656                 }
658                  $hierarchy =~ s/^\n*//g;
659                  $hierarchy =~ s/\n+$/\n/g;
660                  $hierarchy =~ s/(\s|\n)+$//ms;
661                 if ($hierarchy ne "") {
662                     $hierarchy = <<EOF;
663 <refsect1 id="$section_id.object-hierarchy" role="object_hierarchy">
664 <title role="object_hierarchy.title">Object Hierarchy</title>
665 $hierarchy
666 </refsect1>
668                 }
670                  $interfaces =~ s/^\n*//g;
671                  $interfaces =~ s/\n+$/\n/g;
672                  $interfaces =~ s/(\s|\n)+$//ms;
673                 if ($interfaces ne "") {
674                     $interfaces = <<EOF;
675 <refsect1 id="$section_id.implemented-interfaces" role="impl_interfaces">
676 <title role="impl_interfaces.title">Implemented Interfaces</title>
677 $interfaces
678 </refsect1>
680                 }
682                  $implementations =~ s/^\n*//g;
683                  $implementations =~ s/\n+$/\n/g;
684                  $implementations =~ s/(\s|\n)+$//ms;
685                 if ($implementations ne "") {
686                     $implementations = <<EOF;
687 <refsect1 id="$section_id.implementations" role="implementations">
688 <title role="implementations.title">Known Implementations</title>
689 $implementations
690 </refsect1>
692                 }
694                  $prerequisites =~ s/^\n*//g;
695                  $prerequisites =~ s/\n+$/\n/g;
696                  $prerequisites =~ s/(\s|\n)+$//ms;
697                 if ($prerequisites ne "") {
698                     $prerequisites = <<EOF;
699 <refsect1 id="$section_id.prerequisites" role="prerequisites">
700 <title role="prerequisites.title">Prerequisites</title>
701 $prerequisites
702 </refsect1>
704                 }
706                  $derived =~ s/^\n*//g;
707                  $derived =~ s/\n+$/\n/g;
708                  $derived =~ s/(\s|\n)+$//ms;
709                 if ($derived ne "") {
710                     $derived = <<EOF;
711 <refsect1 id="$section_id.derived-interfaces" role="derived_interfaces">
712 <title role="derived_interfaces.title">Known Derived Interfaces</title>
713 $derived
714 </refsect1>
716                 }
718                 $synopsis =~ s/^\n*//g;
719                 $synopsis =~ s/\n+$/\n/g;
720                 my $file_changed = &OutputSGMLFile ($filename, $title, $section_id,
721                                                     $section_includes,
722                                                     \$synopsis, \$details,
723                                                     \$signals_synop, \$signals_desc,
724                                                     \$args_synop, \$args_desc,
725                                                     \$hierarchy, \$interfaces,
726                                                     \$implementations,
727                                                     \$prerequisites, \$derived,
728                                                     \@file_objects);
729                 if ($file_changed) {
730                     $changed = 1;
731                 }
732             }
733             $title = "";
734             $section_id = "";
735             $subsection = "";
736             $in_section = 0;
737             $section_includes = "";
738             $signals_synop = "";
739             $signals_desc = "";
740             $args_synop = "";
741             $child_args_synop = "";
742             $style_args_synop = "";
743             $args_desc = "";
744             $child_args_desc = "";
745             $style_args_desc = "";
746             $hierarchy = "";
747             $interfaces = "";
748             $implementations = "";
749             $prerequisites = "";
750             $derived = "";
752         } elsif (m/^(\S+)/) {
753             my $symbol = $1;
754             #print "  Symbol: $symbol\n";
756             # check for duplicate entries
757             if (! defined $symbol_def_line{$symbol}) {
758                 my $declaration = $Declarations{$symbol};
759                 if (defined ($declaration)) {
760                     # We don't want standard macros/functions of GObjects,
761                     # or private declarations.
762                     if ($subsection ne "Standard" && $subsection ne "Private") {
763                         if (&CheckIsObject ($symbol)) {
764                             push @file_objects, $symbol;
765                         }
766                         my ($synop, $desc) = &OutputDeclaration ($symbol,
767                                                                  $declaration);
768                         my ($sig_synop, $sig_desc) = &GetSignals ($symbol);
769                         my ($arg_synop, $child_arg_synop, $style_arg_synop,
770                             $arg_desc, $child_arg_desc, $style_arg_desc) = &GetArgs ($symbol);
771                         my $hier = &GetHierarchy ($symbol);
772                         my $ifaces = &GetInterfaces ($symbol);
773                         my $impls = &GetImplementations ($symbol);
774                         my $prereqs = &GetPrerequisites ($symbol);
775                         my $der = &GetDerived ($symbol);
776                         $synopsis .= $synop;
777                         $details .= $desc;
778                         $signals_synop .= $sig_synop;
779                         $signals_desc .= $sig_desc;
780                         $args_synop .= $arg_synop;
781                         $child_args_synop .= $child_arg_synop;
782                         $style_args_synop .= $style_arg_synop;
783                         $args_desc .= $arg_desc;
784                         $child_args_desc .= $child_arg_desc;
785                         $style_args_desc .= $style_arg_desc;
786                         $hierarchy .= $hier;
787                         $interfaces .= $ifaces;
788                         $implementations .= $impls;
789                         $prerequisites .= $prereqs;
790                         $derived .= $der;
791                     }
792     
793                     # Note that the declaration has been output.
794                     $DeclarationOutput{$symbol} = 1;
795                 } elsif ($subsection ne "Standard" && $subsection ne "Private") {
796                     $UndeclaredSymbols{$symbol} = 1;
797                     &LogWarning ($file, $., "No declaration found for $symbol.");
798                 }
799                 $num_symbols++;
800                 $symbol_def_line{$symbol}=$.;
802                 if ($section_id eq "") {
803                     if($title eq "" && $filename eq "") {
804                         &LogWarning ($file, $., "Section has no title and no file.");
805                     }
806                     # FIXME: one of those would be enough
807                     # filename should be an internal detail for gtk-doc
808                     if ($title eq "") {
809                         $title = $filename;
810                     } elsif ($filename eq "") {
811                         $filename = $title;
812                     }
813                     $filename =~ s/\s/_/g;
814         
815                     $section_id = $SourceSymbolDocs{"$TMPL_DIR/$filename:Section_Id"};
816                     if (defined ($section_id) && $section_id !~ m/^\s*$/) {
817                         # Remove trailing blanks and use as is
818                         $section_id =~ s/\s+$//;
819                     } elsif (&CheckIsObject ($title)) {
820                         # GObjects use their class name as the ID.
821                         $section_id = &CreateValidSGMLID ($title);
822                     } else {
823                         $section_id = &CreateValidSGMLID ("$MODULE-$title");
824                     }
825                 }
826                 $SymbolSection{$symbol}=$title;
827                 $SymbolSectionId{$symbol}=$section_id;
828             }
829             else {
830                 &LogWarning ($file, $., "Double symbol entry for $symbol. ".
831                     "Previous occurrence on line ".$symbol_def_line{$symbol}.".");
832             }
833         }
834     }
835     close (INPUT);
837     &OutputMissingDocumentation;
838     &OutputUndeclaredSymbols;
840     if ($OUTPUT_ALL_SYMBOLS) {
841         &OutputAllSymbols;
842     }
843     if ($OUTPUT_SYMBOLS_WITHOUT_SINCE) {
844         &OutputSymbolsWithoutSince;
845     }
847     for $filename (split (' ', $EXPAND_CONTENT_FILES)) {
848         my $file_changed = &OutputExtraFile ($filename);
849         if ($file_changed) {
850             $changed = 1;
851         }
852     }
854     &OutputBook ($book_top, $book_bottom);
856     return $changed;
859 #############################################################################
860 # Function    : OutputIndex
861 # Description : This writes an indexlist that can be included into the main-
862 #               document into an <index> tag.
863 #############################################################################
865 sub OutputIndex {
866     my ($basename, $apiindexref ) = @_;
867     my %apiindex = %{$apiindexref};
868     my $old_index = "$SGML_OUTPUT_DIR/$basename.xml";
869     my $new_index = "$SGML_OUTPUT_DIR/$basename.new";
870     my $lastletter = " ";
871     my $divopen = 0;
872     my $symbol;
873     my $short_symbol;
875     open (OUTPUT, ">$new_index")
876         || die "Can't create $new_index";
878     my $header = $doctype_header;
879     $header =~ s/<!DOCTYPE \w+/<!DOCTYPE indexdiv/;
881     print (OUTPUT "$header<indexdiv>\n");
883     #print "generate $basename index (".%apiindex." entries)\n";
884     
885     # do a case insensitive sort while chopping off the prefix
886     foreach my $hash (
887         sort { $$a{criteria} cmp $$b{criteria} }
888         map { my $x = uc($_); $x =~ s/^$NAME_SPACE\_?(.*)/$1/i; { criteria => $x, original => $_, short => $1 } } 
889         keys %apiindex) {
891         $symbol = $$hash{original};
892         if (defined($$hash{short})) {
893             $short_symbol = $$hash{short};
894         } else {
895             $short_symbol = $symbol;
896         }
898         # generate a short symbol description
899         my $symbol_desc = "";
900         my $symbol_section = "";
901         my $symbol_section_id = "";
902         my $symbol_type = lc($DeclarationTypes{$symbol});
903         if ($symbol_type eq "") {
904             #print "trying symbol $symbol\n";
905             if ($symbol =~ m/(.*)::(.*)/) {
906                 my $oname = $1;
907                 my $osym = $2;
908                 my $i;
909                 #print "  trying object signal ${oname}:$osym in ".$#SignalNames." signals\n";
910                 for ($i = 0; $i <= $#SignalNames; $i++) {
911                     if ($SignalNames[$i] eq $osym) {
912                         $symbol_type = "object signal";
913                         if (defined($SymbolSection{$oname})) {
914                            $symbol_section = $SymbolSection{$oname};
915                            $symbol_section_id = $SymbolSectionId{$oname};
916                         }
917                         last;
918                     }
919                 }
920             } elsif ($symbol =~ m/(.*):(.*)/) {
921                 my $oname = $1;
922                 my $osym = $2;
923                 my $i;
924                 #print "  trying object property ${oname}::$osym in ".$#ArgNames." properties\n";
925                 for ($i = 0; $i <= $#ArgNames; $i++) {
926                     #print "    ".$ArgNames[$i]."\n";
927                     if ($ArgNames[$i] eq $osym) {
928                         $symbol_type = "object property";
929                         if (defined($SymbolSection{$oname})) {
930                            $symbol_section = $SymbolSection{$oname};
931                            $symbol_section_id = $SymbolSectionId{$oname};
932                         }
933                         last;
934                     }
935                 }
936             }
937         } else {
938            if (defined($SymbolSection{$symbol})) {
939                $symbol_section = $SymbolSection{$symbol};
940                $symbol_section_id = $SymbolSectionId{$symbol};
941            }
942         }
943         if ($symbol_type ne "") {
944            $symbol_desc=", $symbol_type";
945            if ($symbol_section ne "") {
946                $symbol_desc.=" in <link linkend=\"$symbol_section_id\">$symbol_section</link>";
947                #$symbol_desc.=" in ". &ExpandAbbreviations($symbol, "#$symbol_section");
948            }
949         }
951         my $curletter = uc(substr($short_symbol,0,1));
952         my $id = $apiindex{$symbol};
954         #print "  add symbol $symbol with $id to index in section $curletter\n";
956         if ($curletter ne $lastletter) {
957             $lastletter = $curletter;
959             if ($divopen == 1) {
960                 print (OUTPUT "</indexdiv>\n");
961             }
962             print (OUTPUT "<indexdiv><title>$curletter</title>\n");
963             $divopen = 1;
964         }
966         print (OUTPUT <<EOF);
967 <indexentry><primaryie linkends="$id"><link linkend="$id">$symbol</link>$symbol_desc</primaryie></indexentry>
969     }
971     if ($divopen == 1) {
972         print (OUTPUT "</indexdiv>\n");
973     }
974     print (OUTPUT "</indexdiv>\n");
975     close (OUTPUT);
977     &UpdateFileIfChanged ($old_index, $new_index, 0);
981 #############################################################################
982 # Function    : OutputIndexFull
983 # Description : This writes the full api indexlist that can be included into the
984 #               main document into an <index> tag.
985 #############################################################################
987 sub OutputIndexFull {
988     &OutputIndex ("api-index-full", \%IndexEntriesFull);
992 #############################################################################
993 # Function    : OutputDeprecatedIndex
994 # Description : This writes the deprecated api indexlist that can be included
995 #               into the main document into an <index> tag.
996 #############################################################################
998 sub OutputDeprecatedIndex {
999     &OutputIndex ("api-index-deprecated", \%IndexEntriesDeprecated);
1003 #############################################################################
1004 # Function    : OutputSinceIndexes
1005 # Description : This writes the 'since' api indexlists that can be included into
1006 #               the main document into an <index> tag.
1007 #############################################################################
1009 sub OutputSinceIndexes {
1010     my @sinces = keys %{{ map { $_ => 1 } values %Since }};
1012     foreach my $version (@sinces) {
1013         #print "Since : [$version]\n";
1014         # TODO make filtered hash
1015         #my %index = grep { $Since{$_} eq $version } %IndexEntriesSince;
1016         my %index = map { $_ => $IndexEntriesSince{$_} } grep { $Since{$_} eq $version } keys %IndexEntriesSince;
1018         &OutputIndex ("api-index-$version", \%index);
1019     }
1022 #############################################################################
1023 # Function    : OutputAnnotationGlossary
1024 # Description : This writes a glossary of the used annotation terms into a
1025 #               separate glossary file that can be included into the main
1026 #               document.
1027 #############################################################################
1029 sub OutputAnnotationGlossary {
1030     my $old_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.xml";
1031     my $new_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.new";
1032     my $lastletter = " ";
1033     my $divopen = 0;
1035     # if there are no annotations used return
1036     return if (! keys(%AnnotationsUsed));
1038     # add acronyms that are referenced from acronym text
1039 rerun:
1040     foreach my $annotation (keys(%AnnotationsUsed)) {
1041         if($AnnotationDefinition{$annotation} =~ m/<acronym>([\w ]+)<\/acronym>/) {
1042             if (!exists($AnnotationsUsed{$1})) {
1043                 $AnnotationsUsed{$1} = 1;
1044                 goto rerun;
1045             }
1046         }
1047     }
1049     open (OUTPUT, ">$new_glossary")
1050         || die "Can't create $new_glossary";
1052     my $header = $doctype_header;
1053     $header =~ s/<!DOCTYPE \w+/<!DOCTYPE glossary/;
1055     print (OUTPUT  <<EOF);
1056 $header
1057 <glossary id="annotation-glossary">
1058   <title>Annotation Glossary</title>
1061     foreach my $annotation (keys(%AnnotationsUsed)) {
1062         my $def = $AnnotationDefinition{$annotation};
1063         my $curletter = uc(substr($annotation,0,1));
1065         if ($curletter ne $lastletter) {
1066             $lastletter = $curletter;
1067       
1068             if ($divopen == 1) {
1069                 print (OUTPUT "</glossdiv>\n");
1070             }
1071             print (OUTPUT "<glossdiv><title>$curletter</title>\n");
1072             $divopen = 1;
1073         }
1074         print (OUTPUT <<EOF);
1075     <glossentry>
1076       <glossterm><anchor id="annotation-glossterm-$annotation"/>$annotation</glossterm>
1077       <glossdef>
1078         <para>$def</para>
1079       </glossdef>
1080     </glossentry>
1082     }
1084     if ($divopen == 1) {
1085         print (OUTPUT "</glossdiv>\n");
1086     }
1087     print (OUTPUT "</glossary>\n");
1088     close (OUTPUT);
1090     &UpdateFileIfChanged ($old_glossary, $new_glossary, 0);
1093 #############################################################################
1094 # Function    : ReadKnownSymbols
1095 # Description : This collects the names of non-private symbols from the
1096 #               $MODULE-sections.txt file.
1097 # Arguments   : $file - the $MODULE-sections.txt file which contains all of
1098 #               the functions/macros/structs etc. being documented, organised
1099 #               into sections and subsections.
1100 #############################################################################
1102 sub ReadKnownSymbols {
1103     my ($file) = @_;
1105     my $subsection = "";
1107     #print "Reading: $file\n";
1108     open (INPUT, $file)
1109         || die "Can't open $file: $!";
1111     while (<INPUT>) {
1112         if (m/^#/) {
1113             next;
1115         } elsif (m/^<SECTION>/) {
1116             $subsection = "";
1118         } elsif (m/^<SUBSECTION\s*(.*)>/i) {
1119             $subsection = $1;
1121         } elsif (m/^<SUBSECTION>/) {
1122             next;
1124         } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
1125             next;
1127         } elsif (m/^<FILE>(.*)<\/FILE>/) {
1128             $KnownSymbols{"$TMPL_DIR/$1:Long_Description"} = 1;
1129             $KnownSymbols{"$TMPL_DIR/$1:Short_Description"} = 1;
1130             next;
1132         } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
1133             next;
1135         } elsif (m/^<\/SECTION>/) {
1136             next;
1138         } elsif (m/^(\S+)/) {
1139             my $symbol = $1;
1141             if ($subsection ne "Standard" && $subsection ne "Private") {
1142                 $KnownSymbols{$symbol} = 1;
1143             }
1144             else {
1145                 $KnownSymbols{$symbol} = 0;
1146             }
1147         }
1148     }
1149     close (INPUT);
1153 #############################################################################
1154 # Function    : OutputDeclaration
1155 # Description : Returns the synopsis and detailed description DocBook
1156 #               describing one function/macro etc.
1157 # Arguments   : $symbol - the name of the function/macro begin described.
1158 #               $declaration - the declaration of the function/macro.
1159 #############################################################################
1161 sub OutputDeclaration {
1162     my ($symbol, $declaration) = @_;
1164     my $type = $DeclarationTypes {$symbol};
1165     if ($type eq 'MACRO') {
1166         return &OutputMacro ($symbol, $declaration);
1167     } elsif ($type eq 'TYPEDEF') {
1168         return &OutputTypedef ($symbol, $declaration);
1169     } elsif ($type eq 'STRUCT') {
1170         return &OutputStruct ($symbol, $declaration);
1171     } elsif ($type eq 'ENUM') {
1172         return &OutputEnum ($symbol, $declaration);
1173     } elsif ($type eq 'UNION') {
1174         return &OutputUnion ($symbol, $declaration);
1175     } elsif ($type eq 'VARIABLE') {
1176         return &OutputVariable ($symbol, $declaration);
1177     } elsif ($type eq 'FUNCTION') {
1178         return &OutputFunction ($symbol, $declaration, $type);
1179     } elsif ($type eq 'USER_FUNCTION') {
1180         return &OutputFunction ($symbol, $declaration, $type);
1181     } else {
1182         die "Unknown symbol type";
1183     }
1187 #############################################################################
1188 # Function    : OutputSymbolTraits
1189 # Description : Returns the Since and StabilityLevel paragraphs for a symbol.
1190 # Arguments   : $symbol - the name of the function/macro begin described.
1191 #############################################################################
1193 sub OutputSymbolTraits {
1194     my ($symbol) = @_;
1195     my $desc = "";
1197     if (exists $Since{$symbol}) {
1198         $desc .= "<para role=\"since\">Since $Since{$symbol}</para>";
1199     }
1200     if (exists $StabilityLevel{$symbol}) {
1201         $desc .= "<para role=\"stability\">Stability Level: $StabilityLevel{$symbol}</para>";
1202     }
1203     return $desc;
1206 #############################################################################
1207 # Function    : Outpu{Symbol,Section}ExtraLinks
1208 # Description : Returns extralinks for the symbol (if enabled).
1209 # Arguments   : $symbol - the name of the function/macro begin described.
1210 #############################################################################
1212 sub uri_escape {
1213     my $text = $_[0];
1214     return undef unless defined $text;
1216     # Build a char to hex map
1217     my %escapes = ();
1218     for (0..255) {
1219             $escapes{chr($_)} = sprintf("%%%02X", $_);
1220     }
1222     # Default unsafe characters.  RFC 2732 ^(uric - reserved)
1223     $text =~ s/([^A-Za-z0-9\-_.!~*'()])/$escapes{$1}/g;
1225     return $text;
1228 sub OutputSymbolExtraLinks {
1229     my ($symbol) = @_;
1230     my $desc = "";
1232     if (0) { # NEW FEATURE: needs configurability
1233     my $sstr = &uri_escape($symbol);
1234     my $mstr = &uri_escape($MODULE);
1235     $desc .= <<EOF;
1236 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1237 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&amp;symbol=$sstr">edit documentation</ulink>
1239     }
1240     return $desc;
1243 sub OutputSectionExtraLinks {
1244     my ($symbol,$docsymbol) = @_;
1245     my $desc = "";
1247     if (0) { # NEW FEATURE: needs configurability
1248     my $sstr = &uri_escape($symbol);
1249     my $mstr = &uri_escape($MODULE);
1250     my $dsstr = &uri_escape($docsymbol);
1251     $desc .= <<EOF;
1252 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1253 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&amp;symbol=$dsstr">edit documentation</ulink>
1255     }
1256     return $desc;
1260 #############################################################################
1261 # Function    : OutputMacro
1262 # Description : Returns the synopsis and detailed description of a macro.
1263 # Arguments   : $symbol - the macro.
1264 #               $declaration - the declaration of the macro.
1265 #############################################################################
1267 sub OutputMacro {
1268     my ($symbol, $declaration) = @_;
1269     my $id = &CreateValidSGMLID ($symbol);
1270     my $condition = &MakeConditionDescription ($symbol);
1271     my $synop = &MakeReturnField("#define") . "<link linkend=\"$id\">$symbol</link>";
1272     my $desc;
1273     my $padding = "";
1274     my $args = "";
1275     my $pad;
1277     if ($declaration =~ m/^\s*#\s*define(\s+)\w+(\([^\)]*\))/) {
1278         $padding = $1;
1279         $args = $2;
1281         if (length ($symbol) < $SYMBOL_FIELD_WIDTH) {
1282             $synop .= (' ' x ($SYMBOL_FIELD_WIDTH - length ($symbol)));
1283         }
1285         # Try to align all the lines of args correctly.
1286         $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH + $SYMBOL_FIELD_WIDTH + 1);
1287         my $args_padded = $args;
1288         $args_padded =~ s/ *\\\n */\n$pad/gm;
1289         $synop .= &CreateValidSGML ($args_padded);
1290     }
1291     $synop .= "\n";
1293     my $title = $symbol . ($args ? "()" : "");
1294     $desc = "<refsect2 id=\"$id\" role=\"macro\"$condition>\n<title>$title</title>\n";
1295     $desc .= MakeIndexterms($symbol, $id);
1296     $desc .= "\n";
1297     $desc .= OutputSymbolExtraLinks($symbol);
1299     # Don't output the macro definition if is is a conditional macro or it
1300     # looks like a function, i.e. starts with "g_" or "_?gnome_", or it is
1301     # longer than 2 lines, otherwise we get lots of complicated macros like
1302     # g_assert.
1303     if (!defined ($DeclarationConditional{$symbol}) && ($symbol !~ m/^g_/)
1304         && ($symbol !~ m/^_?gnome_/) && (($declaration =~ tr/\n//) < 2)) {
1305         my $decl_out = &CreateValidSGML ($declaration);
1306         $desc .= "<programlisting>$decl_out</programlisting>\n";
1307     } else {
1308         $desc .= "<programlisting>" . &MakeReturnField("#define") . "$symbol";
1309         # Align each line so that if should all line up OK.
1310         $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH - length ("#define "));
1311         $args =~ s/\n/\n$pad/gm;
1312         $desc .= &CreateValidSGML ($args);
1313         $desc .= "</programlisting>\n";
1314     }
1316     $desc .= &MakeDeprecationNote($symbol);
1318     my $parameters = &OutputParamDescriptions ("MACRO", $symbol);
1319     my $parameters_output = 0;
1321     if (defined ($SymbolDocs{$symbol})) {
1322         my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1324         # Try to insert the parameter table at the author's desired position.
1325         # Otherwise we need to tag it onto the end.
1326         if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1327           $parameters_output = 1;
1328         }
1329         $desc .= $symbol_docs;
1330     }
1332     if ($parameters_output == 0) {
1333         $desc .= $parameters;
1334     }
1336     $desc .= OutputSymbolTraits ($symbol);
1337     $desc .= "</refsect2>\n";
1338     return ($synop, $desc);
1342 #############################################################################
1343 # Function    : OutputTypedef
1344 # Description : Returns the synopsis and detailed description of a typedef.
1345 # Arguments   : $symbol - the typedef.
1346 #               $declaration - the declaration of the typedef,
1347 #                 e.g. 'typedef unsigned int guint;'
1348 #############################################################################
1350 sub OutputTypedef {
1351     my ($symbol, $declaration) = @_;
1352     my $id = &CreateValidSGMLID ($symbol);
1353     my $condition = &MakeConditionDescription ($symbol);
1354     my $synop = &MakeReturnField("typedef") . "<link linkend=\"$id\">$symbol</link>;\n";
1355     my $desc = "<refsect2 id=\"$id\" role=\"typedef\"$condition>\n<title>$symbol</title>\n";
1357     $desc .= MakeIndexterms($symbol, $id);
1358     $desc .= "\n";
1359     $desc .= OutputSymbolExtraLinks($symbol);
1361     if (!defined ($DeclarationConditional{$symbol})) {
1362         my $decl_out = &CreateValidSGML ($declaration);
1363         $desc .= "<programlisting>$decl_out</programlisting>\n";
1364     }
1366     $desc .= &MakeDeprecationNote($symbol);
1368     if (defined ($SymbolDocs{$symbol})) {
1369         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1370     }
1371     $desc .= OutputSymbolTraits ($symbol);
1372     $desc .= "</refsect2>\n";
1373     return ($synop, $desc);
1377 #############################################################################
1378 # Function    : OutputStruct
1379 # Description : Returns the synopsis and detailed description of a struct.
1380 #               We check if it is a object struct, and if so we only output
1381 #               parts of it that are noted as public fields.
1382 #               We also use a different SGML ID for object structs, since the
1383 #               original ID is used for the entire RefEntry.
1384 # Arguments   : $symbol - the struct.
1385 #               $declaration - the declaration of the struct.
1386 #############################################################################
1388 sub OutputStruct {
1389     my ($symbol, $declaration) = @_;
1391     my $is_object_struct = 0;
1392     my $default_to_public = 1;
1393     if (&CheckIsObject ($symbol)) {
1394         #print "Found object struct: $symbol\n";
1395         $is_object_struct = 1;
1396         $default_to_public = 0;
1397     }
1399     my $id;
1400     my $condition;
1401     if ($is_object_struct) {
1402         $id = &CreateValidSGMLID ($symbol . "_struct");
1403         $condition = &MakeConditionDescription ($symbol . "_struct");
1404     } else {
1405         $id = &CreateValidSGMLID ($symbol);
1406         $condition = &MakeConditionDescription ($symbol);
1407     }
1409     # Determine if it is a simple struct or it also has a typedef.
1410     my $has_typedef = 0;
1411     if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1412       $has_typedef = 1;
1413     }
1415     my $synop;
1416     my $desc;
1417     if ($has_typedef) {
1418         # For structs with typedefs we just output the struct name.
1419         $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1420         $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>$symbol</title>\n";
1421     } else {
1422         $synop = &MakeReturnField("struct") . "<link linkend=\"$id\">$symbol</link>;\n";
1423         $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>struct $symbol</title>\n";
1424     }
1426     $desc .= MakeIndexterms($symbol, $id);
1427     $desc .= "\n";
1428     $desc .= OutputSymbolExtraLinks($symbol);
1430     # Form a pretty-printed, private-data-removed form of the declaration
1432     my $decl_out = "";
1433     if ($declaration =~ m/^\s*$/) {
1434         #print "Found opaque struct: $symbol\n";
1435         $decl_out = "typedef struct _$symbol $symbol;";
1436     } elsif ($declaration =~ m/^\s*struct\s+\w+\s*;\s*$/) {
1437         #print "Found opaque struct: $symbol\n";
1438         $decl_out = "struct $symbol;";
1439     } else {
1440         my $public = $default_to_public;
1441         my $new_declaration = "";
1442         my $decl_line;
1443         my $decl = $declaration;
1445         if ($decl =~ m/^\s*(typedef\s+)?struct\s*\w*\s*(?:\/\*.*\*\/)?\s*{(.*)}\s*\w*\s*;\s*$/s) {
1446             my $struct_contents = $2;
1448             foreach $decl_line (split (/\n/, $struct_contents)) {
1449                 #print "Struct line: $decl_line\n";
1450                 if ($decl_line =~ m%/\*\s*<\s*public\s*>\s*\*/%) {
1451                     $public = 1;
1452                 } elsif ($decl_line =~ m%/\*\s*<\s*(private|protected)\s*>\s*\*/%) {
1453                     $public = 0;
1454                 } elsif ($public) {
1455                     $new_declaration .= $decl_line . "\n";
1456                 }
1457             }
1459             if ($new_declaration) {
1460                 # Strip any blank lines off the ends.
1461                 $new_declaration =~ s/^\s*\n//;
1462                 $new_declaration =~ s/\n\s*$/\n/;
1464                 if ($has_typedef) {
1465                     $decl_out = "typedef struct {\n" . $new_declaration
1466                       . "} $symbol;\n";
1467                 } else {
1468                     $decl_out = "struct $symbol {\n" . $new_declaration
1469                       . "};\n";
1470                 }
1471             }
1472         } else {
1473             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1474                 "Couldn't parse struct:\n$declaration");
1475         }
1477         # If we couldn't parse the struct or it was all private, output an
1478         # empty struct declaration.
1479         if ($decl_out eq "") {
1480             if ($has_typedef) {
1481                 $decl_out = "typedef struct _$symbol $symbol;";
1482             } else {
1483                 $decl_out = "struct $symbol;";
1484             }
1485         }
1486     }
1488     $decl_out = &CreateValidSGML ($decl_out);
1489     $desc .= "<programlisting>$decl_out</programlisting>\n";
1491     $desc .= &MakeDeprecationNote($symbol);
1493     if (defined ($SymbolDocs{$symbol})) {
1494         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1495     }
1497     # Create a table of fields and descriptions
1499     # FIXME: Inserting &#160's into the produced type declarations here would
1500     #        improve the output in most situations ... except for function
1501     #        members of structs!
1502     my @fields = ParseStructDeclaration($declaration, !$default_to_public,
1503                                         0, \&MakeXRef,
1504                                         sub {
1505                                             "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1506                                         });
1507     my $params = $SymbolParams{$symbol};
1509     # If no parameters are filled in, we don't generate the description
1510     # table, for backwards compatibility
1512     my $found = 0;
1513     if (defined $params) {
1514         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1515             if ($params->[$i] =~ /\S/) {
1516                 $found = 1;
1517                 last;
1518             }
1519         }
1520     }
1522     if ($found) {
1523         my %field_descrs = @$params;
1524         my $missing_parameters = "";
1526         $desc .= "<variablelist role=\"struct\">\n";
1527         while (@fields) {
1528             my $field_name = shift @fields;
1529             my $text = shift @fields;
1530             my $field_descr = $field_descrs{$field_name};
1531             my $param_annotations = "";
1533             $desc .= "<varlistentry><term>$text</term>\n";
1534             if (defined $field_descr) {
1535                 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1536                 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1537                 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1538             } else {
1539                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1540                     "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1541                 if ($missing_parameters ne "") {
1542                   $missing_parameters .= ", ".$field_name;
1543                 } else {
1544                     $missing_parameters = $field_name;
1545                 }
1546                 $desc .= "<listitem />\n";
1547             }
1548             $desc .= "</varlistentry>\n";
1549         }
1550         $desc .= "</variablelist>";
1552         # remember missing parameters (needed in tmpl-free build)
1553         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1554             $AllIncompleteSymbols{$symbol}=$missing_parameters;
1555         }
1556     }
1557     else {
1558         if (scalar(@fields) > 0) {
1559             if (! exists ($AllIncompleteSymbols{$symbol})) {
1560                 $AllIncompleteSymbols{$symbol}="<items>";
1561                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1562                     "Field descriptions for $symbol are missing in source code comment block.");
1563             }
1564         }
1565     }
1567     $desc .= OutputSymbolTraits ($symbol);
1568     $desc .= "</refsect2>\n";
1569     return ($synop, $desc);
1573 #############################################################################
1574 # Function    : OutputUnion
1575 # Description : Returns the synopsis and detailed description of a union.
1576 # Arguments   : $symbol - the union.
1577 #               $declaration - the declaration of the union.
1578 #############################################################################
1580 sub OutputUnion {
1581     my ($symbol, $declaration) = @_;
1582     my $id = &CreateValidSGMLID ($symbol);
1583     my $condition = &MakeConditionDescription ($symbol);
1585     # Determine if it is a simple struct or it also has a typedef.
1586     my $has_typedef = 0;
1587     if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1588       $has_typedef = 1;
1589     }
1591     my $synop;
1592     my $desc;
1593     if ($has_typedef) {
1594         # For unions with typedefs we just output the union name.
1595         $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1596         $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>$symbol</title>\n";
1597     } else {
1598         $synop = &MakeReturnField("union") . "<link linkend=\"$id\">$symbol</link>;\n";
1599         $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>union $symbol</title>\n";
1600     }
1602     $desc .= MakeIndexterms($symbol, $id);
1603     $desc .= "\n";
1604     $desc .= OutputSymbolExtraLinks($symbol);
1606     # FIXME: we do more for structs
1607     my $decl_out = &CreateValidSGML ($declaration);
1608     $desc .= "<programlisting>$decl_out</programlisting>\n";
1610     $desc .= &MakeDeprecationNote($symbol);
1612     if (defined ($SymbolDocs{$symbol})) {
1613         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1614     }
1616     # Create a table of fields and descriptions
1618     # FIXME: Inserting &#160's into the produced type declarations here would
1619     #        improve the output in most situations ... except for function
1620     #        members of structs!
1621     my @fields = ParseStructDeclaration($declaration, 0,
1622                                         0, \&MakeXRef,
1623                                         sub {
1624                                             "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1625                                         });
1626     my $params = $SymbolParams{$symbol};
1628     # If no parameters are filled in, we don't generate the description
1629     # table, for backwards compatibility
1631     my $found = 0;
1632     if (defined $params) {
1633         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1634             if ($params->[$i] =~ /\S/) {
1635                 $found = 1;
1636                 last;
1637             }
1638         }
1639     }
1641     if ($found) {
1642         my %field_descrs = @$params;
1643         my $missing_parameters = "";
1645         $desc .= "<variablelist role=\"union\">\n";
1646         while (@fields) {
1647             my $field_name = shift @fields;
1648             my $text = shift @fields;
1649             my $field_descr = $field_descrs{$field_name};
1650             my $param_annotations = "";
1652             $desc .= "<varlistentry><term>$text</term>\n";
1653             if (defined $field_descr) {
1654                 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1655                 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1656                 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1657             } else {
1658                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1659                     "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1660                 if ($missing_parameters ne "") {
1661                     $missing_parameters .= ", ".$field_name;
1662                 } else {
1663                     $missing_parameters = $field_name;
1664                 }
1665                 $desc .= "<listitem />\n";
1666             }
1667             $desc .= "</varlistentry>\n";
1668         }
1669         $desc .= "</variablelist>";
1671         # remember missing parameters (needed in tmpl-free build)
1672         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1673             $AllIncompleteSymbols{$symbol}=$missing_parameters;
1674         }
1675     }
1676     else {
1677         if (scalar(@fields) > 0) {
1678             if (! exists ($AllIncompleteSymbols{$symbol})) {
1679                 $AllIncompleteSymbols{$symbol}="<items>";
1680                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1681                     "Field descriptions for $symbol are missing in source code comment block.");
1682             }
1683         }
1684     }
1686     $desc .= OutputSymbolTraits ($symbol);
1687     $desc .= "</refsect2>\n";
1688     return ($synop, $desc);
1692 #############################################################################
1693 # Function    : OutputEnum
1694 # Description : Returns the synopsis and detailed description of a enum.
1695 # Arguments   : $symbol - the enum.
1696 #               $declaration - the declaration of the enum.
1697 #############################################################################
1699 sub OutputEnum {
1700     my ($symbol, $declaration) = @_;
1701     my $id = &CreateValidSGMLID ($symbol);
1702     my $condition = &MakeConditionDescription ($symbol);
1703     my $synop = &MakeReturnField("enum") . "<link linkend=\"$id\">$symbol</link>;\n";
1704     my $desc = "<refsect2 id=\"$id\" role=\"enum\"$condition>\n<title>enum $symbol</title>\n";
1706     $desc .= MakeIndexterms($symbol, $id);
1707     $desc .= "\n";
1708     $desc .= OutputSymbolExtraLinks($symbol);
1710     my $decl_out = &CreateValidSGML ($declaration);
1711     $desc .= "<programlisting>$decl_out</programlisting>\n";
1713     $desc .= &MakeDeprecationNote($symbol);
1715     if (defined ($SymbolDocs{$symbol})) {
1716         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1717     }
1719     # Create a table of fields and descriptions
1721     my @fields = ParseEnumDeclaration($declaration);
1722     my $params = $SymbolParams{$symbol};
1724     # If no parameters are filled in, we don't generate the description
1725     # table, for backwards compatibility
1727     my $found = 0;
1728     if (defined $params) {
1729         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1730             if ($params->[$i] =~ /\S/) {
1731                 $found = 1;
1732                 last;
1733             }
1734         }
1735     }
1737     if ($found) {
1738         my %field_descrs = @$params;
1739         my $missing_parameters = "";
1741         $desc .= "<variablelist role=\"enum\">\n";
1742         for my $field_name (@fields) {
1743             my $field_descr = $field_descrs{$field_name};
1744             my $param_annotations = "";
1746             $id = &CreateValidSGMLID ($field_name);
1747             $condition = &MakeConditionDescription ($field_name);
1748             $desc .= "<varlistentry id=\"$id\" role=\"constant\"$condition>\n<term><literal>$field_name</literal></term>\n";
1749             if (defined $field_descr) {
1750                 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1751                 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1752                 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1753             } else {
1754                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1755                     "Value description for $symbol"."::"."$field_name is missing in source code comment block.");
1756                 if ($missing_parameters ne "") {
1757                   $missing_parameters .= ", ".$field_name;
1758                 } else {
1759                     $missing_parameters = $field_name;
1760                 }
1761                 $desc .= "<listitem />\n";
1762             }
1763             $desc .= "</varlistentry>\n";
1764         }
1765         $desc .= "</variablelist>";
1767         # remember missing parameters (needed in tmpl-free build)
1768         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1769             $AllIncompleteSymbols{$symbol}=$missing_parameters;
1770         }
1771     }
1772     else {
1773         if (scalar(@fields) > 0) {
1774             if (! exists ($AllIncompleteSymbols{$symbol})) {
1775                 $AllIncompleteSymbols{$symbol}="<items>";
1776                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1777                     "Value descriptions for $symbol are missing in source code comment block.");
1778             }
1779         }
1780     }
1782     $desc .= OutputSymbolTraits ($symbol);
1783     $desc .= "</refsect2>\n";
1784     return ($synop, $desc);
1788 #############################################################################
1789 # Function    : OutputVariable
1790 # Description : Returns the synopsis and detailed description of a variable.
1791 # Arguments   : $symbol - the extern'ed variable.
1792 #               $declaration - the declaration of the variable.
1793 #############################################################################
1795 sub OutputVariable {
1796     my ($symbol, $declaration) = @_;
1797     my $id = &CreateValidSGMLID ($symbol);
1798     my $condition = &MakeConditionDescription ($symbol);
1800     my $synop;
1801     if ($declaration =~ m/^\s*extern\s+((const\s+|unsigned\s+)*\w+)(\s+\*+|\*+|\s)(\s*)([A-Za-z]\w*)\s*;/) {
1802         my $mod = defined ($1) ? $1 : "";
1803         my $ptr = defined ($3) ? $3 : "";
1804         my $space = defined ($4) ? $4 : "";
1805         $synop = &MakeReturnField("extern") . "$mod$ptr$space<link linkend=\"$id\">$symbol</link>;\n";
1807     } else {
1808         $synop = &MakeReturnField("extern") . "<link linkend=\"$id\">$symbol</link>;\n";
1809     }
1811     my $desc = "<refsect2 id=\"$id\" role=\"variable\"$condition>\n<title>$symbol</title>\n";
1813     $desc .= MakeIndexterms($symbol, $id);
1814     $desc .= "\n";
1815     $desc .= OutputSymbolExtraLinks($symbol);
1817     my $decl_out = &CreateValidSGML ($declaration);
1818     $desc .= "<programlisting>$decl_out</programlisting>\n";
1820     $desc .= &MakeDeprecationNote($symbol);
1822     if (defined ($SymbolDocs{$symbol})) {
1823         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1824     }
1825     $desc .= OutputSymbolTraits ($symbol);
1826     $desc .= "</refsect2>\n";
1827     return ($synop, $desc);
1831 #############################################################################
1832 # Function    : OutputFunction
1833 # Description : Returns the synopsis and detailed description of a function.
1834 # Arguments   : $symbol - the function.
1835 #               $declaration - the declaration of the function.
1836 #############################################################################
1838 sub OutputFunction {
1839     my ($symbol, $declaration, $symbol_type) = @_;
1840     my $id = &CreateValidSGMLID ($symbol);
1841     my $condition = &MakeConditionDescription ($symbol);
1843     # Take out the return type     $1                                                                           $3   $4
1844     $declaration =~ s/<RETURNS>\s*((const\s+|G_CONST_RETURN\s+|unsigned\s+|long\s+|short\s+|struct\s+|enum\s+)*)(\w+)(\s*\**\s*(const|G_CONST_RETURN)?\s*\**\s*(restrict)?\s*)<\/RETURNS>\n//;
1845     my $type_modifier = defined($1) ? $1 : "";
1846     my $type = $3;
1847     my $pointer = $4;
1848     #print "$symbol pointer is $pointer\n";
1849     my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1850     my $start = "";
1851     #if ($symbol_type eq 'USER_FUNCTION') {
1852     #    $start = "typedef ";
1853     #}
1855     # We output const rather than G_CONST_RETURN.
1856     $type_modifier =~ s/G_CONST_RETURN/const/g;
1857     $pointer =~ s/G_CONST_RETURN/const/g;
1858     $pointer =~ s/^\s+/ /g;
1860     my $ret_type_len = length ($start) + length ($type_modifier)
1861         + length ($pointer) + length ($type);
1862     my $ret_type_output;
1863     my $symbol_len;
1864     if ($ret_type_len < $RETURN_TYPE_FIELD_WIDTH) {
1865         $ret_type_output = "$start$type_modifier$xref$pointer"
1866             . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
1867         $symbol_len = 0;
1868     } else {
1869         #$ret_type_output = "$start$type_modifier$xref$pointer\n" . (' ' x $RETURN_TYPE_FIELD_WIDTH);
1871         $ret_type_output = "$start$type_modifier$xref$pointer ";
1872         $symbol_len = $ret_type_len + 1 - $RETURN_TYPE_FIELD_WIDTH;
1873     }
1875     $symbol_len += length ($symbol);
1876     my $char1 = my $char2 = my $char3 = "";
1877     if ($symbol_type eq 'USER_FUNCTION') {
1878         $symbol_len += 3;
1879         $char1 = "(";
1880         $char2 = "*";
1881         $char3 = ")";
1882     }
1884     my ($symbol_output, $symbol_desc_output);
1885     if ($symbol_len < $SYMBOL_FIELD_WIDTH) {
1886         $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3"
1887             . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1888         $symbol_desc_output = "$char1$char2$symbol$char3"
1889             . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1890     } else {
1891         $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3\n"
1892             . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1893         $symbol_desc_output = "$char1$char2$symbol$char3\n"
1894             . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1895     }
1897     my $synop = $ret_type_output . $symbol_output . '(';
1898     my $desc = "<refsect2 id=\"$id\" role=\"function\"$condition>\n<title>${symbol} ()</title>\n";
1900     $desc .= MakeIndexterms($symbol, $id);
1901     $desc .= "\n";
1902     $desc .= OutputSymbolExtraLinks($symbol);
1904     $desc  .= "<programlisting>${ret_type_output}$symbol_desc_output(";
1906     my $param_num = 0;
1907     while ($declaration ne "") {
1908         #print "$declaration";
1910         if ($declaration =~ s/^[\s,]+//) {
1911             # skip whitespace and commas
1912             next;
1914         } elsif ($declaration =~ s/^void\s*[,\n]//) {
1915             $synop .= "void";
1916             $desc  .= "void";
1918         } elsif ($declaration =~ s/^...\s*[,\n]//) {
1919             if ($param_num == 0) {
1920                 $synop .= "...";
1921                 $desc  .= "...";
1922             } else {
1923                 $synop .= ",\n"
1924                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1925                     . " ...";
1926                 $desc  .= ",\n"
1927                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1928                     . " ...";
1929             }
1931         # allow alphanumerics, '_', '[' & ']' in param names
1932         # Try to match a standard parameter (keep in sync with gtkdoc-mktmpl)
1933         #                                $1                                                                                                                                    $2                             $3                                                           $4       $5
1934         } elsif ($declaration =~ s/^\s*((?:G_CONST_RETURN|G_GNUC_UNUSED|unsigned long|unsigned short|signed long|signed short|unsigned|signed|long|short|volatile|const)\s+)*((?:struct\b|enum\b)?\s*\w+)\s*((?:(?:const\b|restrict\b)?\s*\*?\s*(?:const\b|restrict\b)?\s*)*)(\w+)?\s*((?:\[\S*\])*)\s*[,\n]//) {
1935             my $pre     = defined($1) ? $1 : "";
1936             my $type    = $2;
1937             my $ptr     = defined($3) ? $3 : "";
1938             my $name    = defined($4) ? $4 : "";
1939             my $array   = defined($5) ? $5 : "";
1941             $pre  =~ s/\s+/ /g;
1942             $type =~ s/\s+/ /g;
1943             $ptr  =~ s/\s+/ /g;
1944             $ptr  =~ s/\s+$//;
1945             if ($ptr && $ptr !~ m/\*$/) { $ptr .= " "; }
1947             #print "$symbol: '$pre' '$type' '$ptr' '$name' '$array'\n";
1949             if (($name eq "") && $pre =~ m/^((un)?signed .*)\s?/ ) {
1950                 $name = $type;
1951                 $type = "$1";
1952                 $pre = "";
1953             }
1955             my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1956             my $label   = "$pre$xref $ptr$name$array";
1958             #print "$symbol: '$pre' '$type' '$ptr' '$name' '$array'\n";
1960             if ($param_num == 0) {
1961                 $synop .= "$label";
1962                 $desc  .= "$label";
1963             } else {
1964                 $synop .= ",\n"
1965                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1966                     . " $label";
1967                 $desc  .= ",\n"
1968                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1969                     . " $label";
1970             }
1972         # Try to match parameters which are functions (keep in sync with gtkdoc-mktmpl)
1973         #                              $1                                       $2          $3      $4                        $5                    $7             $8
1974         } elsif ($declaration =~ s/^(const\s+|G_CONST_RETURN\s+|unsigned\s+)*(struct\s+)?(\w+)\s*(\**)\s*(?:restrict\b)?\s*(const\s+)?\(\s*\*+\s*(\w+)\s*\)\s*\(([^)]*)\)\s*[,\n]//) {
1975             my $mod1 = defined($1) ? $1 : "";
1976             if (defined($2)) { $mod1 .= $2; }
1977             my $type = $3;
1978             my $ptr1 = $4;
1979             my $mod2 = defined($5) ? $5 : "";
1980             my $func_ptr = $6;
1981             my $name = $7;
1982             my $func_params = defined($8) ? $8 : "";
1983             
1984             #if (!defined($type)) { print "## no type\n"; };
1985             #if (!defined($ptr1)) { print "## no ptr1\n"; };
1986             #if (!defined($func_ptr)) { print "## no func_ptr\n"; };
1987             #if (!defined($name)) { print "## no name\n"; };
1989             if ($ptr1 && $ptr1 !~ m/\*$/) { $ptr1 .= " "; }
1990             $func_ptr  =~ s/\s+//g;
1991             my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1992             my $label = "$mod1$xref$ptr1$mod2 ($func_ptr$name) ($func_params)";
1994             #print "Type: [$mod1][$xref][$ptr1][$mod2] ([$func_ptr][$name]) ($func_params)\n";
1995             if ($param_num == 0) {
1996                 $synop .= "$label";
1997                 $desc  .= "$label";
1998             } else {
1999                 $synop .= ",\n"
2000                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2001                     . " $label";
2002                 $desc  .= ",\n"
2003                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2004                     . " $label";
2005             }
2007         } else {
2008             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2009                 "Can't parse args for function $symbol: $declaration");
2010             last;
2011         }
2012         $param_num++;
2013     }
2014     $synop .= ");\n";
2015     $desc  .= ");</programlisting>\n";
2017     $desc .= &MakeDeprecationNote($symbol);
2019     my $parameters = &OutputParamDescriptions ("FUNCTION", $symbol);
2020     my $parameters_output = 0;
2022     if (defined ($SymbolDocs{$symbol})) {
2023         my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
2025         # Try to insert the parameter table at the author's desired position.
2026         # Otherwise we need to tag it onto the end.
2027         if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
2028           $parameters_output = 1;
2029         }
2030         $desc .= $symbol_docs;
2031     }
2033     if ($parameters_output == 0) {
2034         $desc .= $parameters;
2035     }
2037     $desc .= OutputSymbolTraits ($symbol);
2038     $desc .= "</refsect2>\n";
2039     return ($synop, $desc);
2043 #############################################################################
2044 # Function    : OutputParamDescriptions
2045 # Description : Returns the DocBook output describing the parameters of a
2046 #               function, macro or signal handler.
2047 # Arguments   : $symbol_type - 'FUNCTION', 'MACRO' or 'SIGNAL'. Signal
2048 #                 handlers have an implicit user_data parameter last.
2049 #               $symbol - the name of the function/macro being described.
2050 #############################################################################
2052 sub OutputParamDescriptions {
2053     my ($symbol_type, $symbol) = @_;
2054     my $output = "";
2055     if (defined ($SymbolParams{$symbol})) {
2056         my $returns = "";
2057         my $params = $SymbolParams{$symbol};
2058         my $params_desc = "";
2059         my $j;
2060         for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
2061             my $param_name = $$params[$j];
2062             my $param_desc = $$params[$j + 1];
2063             my $param_annotations = "";
2065             ($param_desc,$param_annotations) = & ExpandAnnotation($symbol, $param_desc);
2066             $param_desc = &ExpandAbbreviations($symbol, $param_desc);
2067             if ($param_name eq "Returns") {
2068                 $returns = "$param_desc$param_annotations";
2069             } else {
2070                 if ($param_name eq "Varargs") {
2071                     $param_name = "...";
2072                 }
2073                 $params_desc .= "<varlistentry><term><parameter>$param_name</parameter>&#160;:</term>\n<listitem><simpara>$param_desc$param_annotations</simpara></listitem></varlistentry>\n";
2074             }
2075         }
2077         # Signals have an implicit user_data parameter which we describe.
2078         if ($symbol_type eq "SIGNAL") {
2079             $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";
2080         }
2082         # Start a table if we need one.
2083         if ($params_desc || $returns) {
2084             $output .= "<variablelist role=\"params\">\n";
2085             if ($params_desc ne "") {
2086                 #$output .= "<varlistentry><term>Parameters:</term><listitem></listitem></varlistentry>\n";
2087                 $output .= $params_desc;
2088             }
2090             # Output the returns info last.
2091             if ($returns) {
2092                 $output .= "<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara>$returns</simpara></listitem></varlistentry>\n";
2093             }
2095             # Finish the table.
2096             $output .= "</variablelist>";
2097         }
2098     }
2099     return $output;
2103 #############################################################################
2104 # Function    : ParseStabilityLevel
2105 # Description : Parses a stability level and outputs a warning if it isn't
2106 #               valid.
2107 # Arguments   : $stability - the stability text.
2108 #               $file, $line - context for error message
2109 #               $message - description of where the level is from, to use in
2110 #               any error message.
2111 # Returns     : The parsed stability level string.
2112 #############################################################################
2114 sub ParseStabilityLevel {
2115     my ($stability, $file, $line, $message) = @_;
2117     $stability =~ s/^\s*//;
2118     $stability =~ s/\s*$//;
2119     if ($stability =~ m/^stable$/i) {
2120         $stability = "Stable";
2121     } elsif ($stability =~ m/^unstable$/i) {
2122         $stability = "Unstable";
2123     } elsif ($stability =~ m/^private$/i) {
2124         $stability = "Private";
2125     } else {
2126         &LogWarning ($file, $line, "$message is $stability.".
2127             "It should be one of these: Stable, Unstable, or Private.");
2128     }
2129     return $stability;
2133 #############################################################################
2134 # Function    : OutputSGMLFile
2135 # Description : Outputs the final DocBook file for one section.
2136 # Arguments   : $file - the name of the file.
2137 #               $title - the title from the $MODULE-sections.txt file, which
2138 #                 will be overridden by the title in the template file.
2139 #               $section_id - the SGML id to use for the toplevel tag.
2140 #               $includes - comma-separates list of include files added at top
2141 #                 of synopsis, with '<' '>' around them (if not already enclosed in "").
2142 #               $synopsis - reference to the DocBook for the Synopsis part.
2143 #               $details - reference to the DocBook for the Details part.
2144 #               $signal_synop - reference to the DocBook for the Signal Synopsis part
2145 #               $signal_desc - reference to the DocBook for the Signal Description part
2146 #               $args_synop - reference to the DocBook for the Arg Synopsis part
2147 #               $args_desc - reference to the DocBook for the Arg Description part
2148 #               $hierarchy - reference to the DocBook for the Object Hierarchy part
2149 #               $interfaces - reference to the DocBook for the Interfaces part
2150 #               $implementations - reference to the DocBook for the Known Implementations part
2151 #               $prerequisites - reference to the DocBook for the Prerequisites part
2152 #               $derived - reference to the DocBook for the Derived Interfaces part
2153 #               $file_objects - reference to an array of objects in this file
2154 #############################################################################
2156 sub OutputSGMLFile {
2157     my ($file, $title, $section_id, $includes, $synopsis, $details, $signals_synop, $signals_desc, $args_synop, $args_desc, $hierarchy, $interfaces, $implementations, $prerequisites, $derived, $file_objects) = @_;
2159     #print "Output sgml for file $file with title '$title'\n";
2160     
2161     # The edited title overrides the one from the sections file.
2162     my $new_title = $SymbolDocs{"$TMPL_DIR/$file:Title"};
2163     if (defined ($new_title) && $new_title !~ m/^\s*$/) {
2164         $title = $new_title;
2165         #print "Found title: $title\n";
2166     }
2167     my $short_desc = $SymbolDocs{"$TMPL_DIR/$file:Short_Description"};
2168     if (!defined ($short_desc) || $short_desc =~ m/^\s*$/) {
2169         $short_desc = "";
2170     } else {
2171         $short_desc = &ExpandAbbreviations("$title:Short_description",
2172                                            $short_desc);
2173         #print "Found short_desc: $short_desc";
2174     }
2175     my $long_desc = $SymbolDocs{"$TMPL_DIR/$file:Long_Description"};
2176     if (!defined ($long_desc) || $long_desc =~ m/^\s*$/) {
2177         $long_desc = "";
2178     } else {
2179         $long_desc = &ExpandAbbreviations("$title:Long_description",
2180                                           $long_desc);
2181         #print "Found long_desc: $long_desc";
2182     }
2183     my $see_also = $SymbolDocs{"$TMPL_DIR/$file:See_Also"};
2184     if (!defined ($see_also) || $see_also =~ m%^\s*(<para>)?\s*(</para>)?\s*$%) {
2185         $see_also = "";
2186     } else {
2187         $see_also = &ExpandAbbreviations("$title:See_Also", $see_also);
2188         #print "Found see_also: $see_also";
2189     }
2190     if ($see_also) {
2191         $see_also = "<refsect1 id=\"$section_id.see-also\">\n<title>See Also</title>\n$see_also\n</refsect1>\n";
2192     }
2193     my $stability = $SymbolDocs{"$TMPL_DIR/$file:Stability_Level"};
2194     if (!defined ($stability) || $stability =~ m/^\s*$/) {
2195         $stability = "";
2196     } else {
2197         $stability = &ParseStabilityLevel($stability, $file, $., "Section stability level");
2198         #print "Found stability: $stability";
2199     }
2200     if ($stability) {
2201         $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$stability, unless otherwise indicated\n</refsect1>\n";
2202     } elsif ($DEFAULT_STABILITY) {
2203         $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$DEFAULT_STABILITY, unless otherwise indicated\n</refsect1>\n";
2204     }
2206     my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
2207         gmtime (time);
2208     my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
2209     $year += 1900;
2211     my $include_output = "";
2212     my $include;
2213     foreach $include (split (/,/, $includes)) {
2214         if ($include =~ m/^\".+\"$/) {
2215             $include_output .= "#include ${include}\n";
2216         }
2217         else {
2218             $include =~ s/^\s+|\s+$//gs;
2219             $include_output .= "#include &lt;${include}&gt;\n";
2220         }
2221     }
2222     if ($include_output ne '') {
2223         $include_output = "\n$include_output\n";
2224     }
2225     
2226     my $extralinks = OutputSectionExtraLinks($title,"Section:$file");
2228     my $old_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT";
2229     my $new_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT.new";
2231     open (OUTPUT, ">$new_sgml_file")
2232         || die "Can't create $new_sgml_file: $!";
2234     my $object_anchors = "";
2235     foreach my $object (@$file_objects) {
2236         next if ($object eq $section_id);
2237         my $id = CreateValidSGMLID($object);
2238         #print "Debug: Adding anchor for $object\n";
2239         $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
2240     }
2242     # We used to output this, but is messes up our UpdateFileIfChanged code
2243     # since it changes every day (and it is only used in the man pages):
2244     # "<refentry id="$section_id" revision="$mday $month $year">"
2246     if (lc($OUTPUT_FORMAT) eq "xml") {
2247         print OUTPUT $doctype_header;
2248     }
2250     print OUTPUT <<EOF;
2251 <refentry id="$section_id">
2252 <refmeta>
2253 <refentrytitle role="top_of_page" id="$section_id.top_of_page">$title</refentrytitle>
2254 <manvolnum>3</manvolnum>
2255 <refmiscinfo>\U$MODULE\E Library</refmiscinfo>
2256 </refmeta>
2257 <refnamediv>
2258 <refname>$title</refname>
2259 <refpurpose>$short_desc</refpurpose>
2260 </refnamediv>
2261 $stability
2262 <refsynopsisdiv id="$section_id.synopsis" role="synopsis">
2263 <title role="synopsis.title">Synopsis</title>
2264 $object_anchors
2265 <synopsis>$include_output$${synopsis}</synopsis>
2266 </refsynopsisdiv>
2267 $$hierarchy$$prerequisites$$derived$$interfaces$$implementations$$args_synop$$signals_synop
2268 <refsect1 id="$section_id.description" role="desc">
2269 <title role="desc.title">Description</title>
2270 $extralinks$long_desc
2271 </refsect1>
2272 <refsect1 id="$section_id.details" role="details">
2273 <title role="details.title">Details</title>
2274 $$details
2275 </refsect1>
2276 $$args_desc$$signals_desc$see_also
2277 </refentry>
2279     close (OUTPUT);
2281     return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2285 #############################################################################
2286 # Function    : OutputExtraFile
2287 # Description : Copies an "extra" DocBook file into the output directory,
2288 #               expanding abbreviations
2289 # Arguments   : $file - the source file.
2290 #############################################################################
2291 sub OutputExtraFile {
2292     my ($file) = @_;
2294     my $basename;
2296     ($basename = $file) =~ s!^.*/!!;
2298     my $old_sgml_file = "$SGML_OUTPUT_DIR/$basename";
2299     my $new_sgml_file = "$SGML_OUTPUT_DIR/$basename.new";
2301     my $contents;
2303     open(EXTRA_FILE, "<$file") || die "Can't open $file";
2305     {
2306         local $/;
2307         $contents = <EXTRA_FILE>;
2308     }
2310     open (OUTPUT, ">$new_sgml_file")
2311         || die "Can't create $new_sgml_file: $!";
2313     print OUTPUT &ExpandAbbreviations ("$basename file", $contents);
2314     close (OUTPUT);
2316     return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2318 #############################################################################
2319 # Function    : OutputBook
2320 # Description : Outputs the SGML entities that need to be included into the
2321 #               main SGML file for the module.
2322 # Arguments   : $book_top - the declarations of the entities, which are added
2323 #                 at the top of the main SGML file.
2324 #               $book_bottom - the references to the entities, which are
2325 #                 added in the main SGML file at the desired position.
2326 #############################################################################
2328 sub OutputBook {
2329     my ($book_top, $book_bottom) = @_;
2331     my $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top";
2332     my $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top.new";
2334     open (OUTPUT, ">$new_file")
2335         || die "Can't create $new_file: $!";
2336     print OUTPUT $book_top;
2337     close (OUTPUT);
2339     &UpdateFileIfChanged ($old_file, $new_file, 0);
2342     $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom";
2343     $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom.new";
2345     open (OUTPUT, ">$new_file")
2346         || die "Can't create $new_file: $!";
2347     print OUTPUT $book_bottom;
2348     close (OUTPUT);
2350     &UpdateFileIfChanged ($old_file, $new_file, 0);
2353     # If the main SGML file hasn't been created yet, we create it here.
2354     # The user can tweak it later.
2355     if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
2356       open (OUTPUT, ">$MAIN_SGML_FILE")
2357         || die "Can't create $MAIN_SGML_FILE: $!";
2359       if (lc($OUTPUT_FORMAT) eq "xml") {
2360           print OUTPUT <<EOF;
2361 <?xml version="1.0"?>
2362 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
2363                "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
2365   <!ENTITY % local.common.attrib "xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'">
2367 <book id="index">
2369       } else {
2370         print OUTPUT <<EOF;
2371 <!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
2372 $book_top
2374 <book id="index">
2376       }
2378 print OUTPUT <<EOF;
2379   <bookinfo>
2380     <title>$MODULE Reference Manual</title>
2381     <releaseinfo>
2382       for $MODULE [VERSION].
2383       The latest version of this documentation can be found on-line at
2384       <ulink role="online-location" url="http://[SERVER]/$MODULE/index.html">http://[SERVER]/$MODULE/</ulink>.
2385     </releaseinfo>
2386   </bookinfo>
2388   <chapter>
2389     <title>[Insert title here]</title>
2390     $book_bottom
2391   </chapter>
2393   if (-e $OBJECT_TREE_FILE) {
2394     print OUTPUT <<EOF;
2395   <chapter id="object-tree">
2396     <title>Object Hierarchy</title>
2397      <xi:include href="xml/tree_index.sgml"/>
2398   </chapter>
2400   }
2402 print OUTPUT <<EOF;
2403   <index id="api-index-full">
2404     <title>API Index</title>
2405     <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
2406   </index>
2408   <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
2409 </book>
2412       close (OUTPUT);
2413     }
2417 #############################################################################
2418 # Function    : CreateValidSGML
2419 # Description : This turns any chars which are used in SGML into entities,
2420 #               e.g. '<' into '&lt;'
2421 # Arguments   : $text - the text to turn into proper SGML.
2422 #############################################################################
2424 sub CreateValidSGML {
2425     my ($text) = @_;
2426     $text =~ s/&/&amp;/g;       # Do this first, or the others get messed up.
2427     $text =~ s/</&lt;/g;
2428     $text =~ s/>/&gt;/g;
2429     # browers render single tabs inconsistently
2430     $text =~ s/([^\s])\t([^\s])/$1&#160;$2/g;
2431     return $text;
2434 #############################################################################
2435 # Function    : ConvertSGMLChars
2436 # Description : This is used for text in source code comment blocks, to turn
2437 #               chars which are used in SGML into entities, e.g. '<' into
2438 #               '&lt;'. Depending on $SGML_MODE, this is done
2439 #               unconditionally or only if the character doesn't seem to be
2440 #               part of an SGML construct (tag or entity reference).
2441 # Arguments   : $text - the text to turn into proper SGML.
2442 #############################################################################
2444 sub ConvertSGMLChars {
2445     my ($symbol, $text) = @_;
2447     if ($SGML_MODE) {
2448         # For the SGML mode only convert to entities outside CDATA sections.
2449         return &ModifyXMLElements ($text, $symbol,
2450                                    "<!\\[CDATA\\[|<programlisting[^>]*>",
2451                                    \&ConvertSGMLCharsEndTag,
2452                                    \&ConvertSGMLCharsCallback);
2453     } else {
2454         # For the simple non-sgml mode, convert to entities everywhere.
2455         $text =~ s/&/&amp;/g;   # Do this first, or the others get messed up.
2456         $text =~ s/</&lt;/g;
2457         $text =~ s/>/&gt;/g;
2458         return $text;
2459     }
2463 sub ConvertSGMLCharsEndTag {
2464   if ($_[0] eq "<!\[CDATA\[") {
2465     return "]]>";
2466   } else {
2467     return "</programlisting>";
2468   }
2471 sub ConvertSGMLCharsCallback {
2472   my ($text, $symbol, $tag) = @_;
2474   if ($tag =~ m/^<programlisting/) {
2475     # We can handle <programlisting> specially here.
2476     return &ModifyXMLElements ($text, $symbol,
2477                                "<!\\[CDATA\\[",
2478                                \&ConvertSGMLCharsEndTag,
2479                                \&ConvertSGMLCharsCallback2);
2480   } elsif ($tag eq "") {
2481     # If we're not in CDATA convert to entities.
2482     $text =~ s/&(?![a-zA-Z#]+;)/&amp;/g;        # Do this first, or the others get messed up.
2483     $text =~ s/<(?![a-zA-Z\/!])/&lt;/g;
2484     $text =~ s/(?<![a-zA-Z0-9"'\/-])>/&gt;/g;
2486     # Handle "#include <xxxxx>"
2487     $text =~ s/#include(\s+)<([^>]+)>/#include$1&lt;$2&gt;/g;
2488   }
2490   return $text;
2493 sub ConvertSGMLCharsCallback2 {
2494   my ($text, $symbol, $tag) = @_;
2496   # If we're not in CDATA convert to entities.
2497   # We could handle <programlisting> differently, though I'm not sure it helps.
2498   if ($tag eq "") {
2499     # replace only if its not a tag
2500     $text =~ s/&(?![a-zA-Z#]+;)/&amp;/g;        # Do this first, or the others get messed up.
2501     $text =~ s/<(?![a-zA-Z\/!])/&lt;/g;
2502     $text =~ s/(?<![a-zA-Z0-9"'\/-])>/&gt;/g;
2504     # Handle "#include <xxxxx>"
2505     $text =~ s/#include(\s+)<([^>]+)>/#include$1&lt;$2&gt;/g;
2506   }
2508   return $text;
2511 #############################################################################
2512 # Function    : ExpandAnnotation
2513 # Description : This turns annotations into acrony tags.
2514 # Arguments   : $symbol - the symbol being documented, for error messages.
2515 #               $text - the text to expand.
2516 #############################################################################
2517 sub ExpandAnnotation {
2518     my ($symbol, $param_desc) = @_;
2519     my $param_annotations = "";
2520     
2521     if ($param_desc =~ m%\s*\((.*)\):%) {
2522         my @annotations;
2523         my $annotation;
2524         my $annotation_extra = "";
2525         $param_desc = $';
2526     
2527         @annotations = split(/\)\s*\(/,$1);
2528         foreach $annotation (@annotations) {
2529             # need to search for the longest key-match in %AnnotationDefinition
2530             my $match_length=0;
2531             my $match_annotation="";
2532             my $annotationdef;
2533             foreach $annotationdef (keys %AnnotationDefinition) {
2534                 if ($annotation =~ m/^$annotationdef/) {
2535                     if (length($annotationdef)>$match_length) {
2536                         $match_length=length($annotationdef);
2537                         $match_annotation=$annotationdef;
2538                     }
2539                 }
2540             }
2541             if ($match_annotation ne "") {
2542                 if ($annotation =~ m%$match_annotation\s+(.*)%) {
2543                     $annotation_extra = " $1";
2544                 }
2545                 $AnnotationsUsed{$match_annotation} = 1;
2546                 $param_annotations .= "<acronym>$match_annotation</acronym>$annotation_extra. ";
2547             }
2548             else {
2549                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2550                     "unknown annotation \"$annotation\" in documentation for $symbol.");
2551                 $param_annotations=$annotation;
2552             }
2553         }
2554         chomp($param_desc);
2555         $param_desc =~ m/^(.*)\.*\s*$/;
2556         $param_desc = "$1. ";
2557     }    
2558     return ($param_desc, $param_annotations);
2561 #############################################################################
2562 # Function    : ExpandAbbreviations
2563 # Description : This turns the abbreviations function(), macro(), @param,
2564 #               %constant, and #symbol into appropriate DocBook markup.
2565 #               CDATA sections and <programlisting> parts are skipped.
2566 # Arguments   : $symbol - the symbol being documented, for error messages.
2567 #               $text - the text to expand.
2568 #############################################################################
2570 sub ExpandAbbreviations {
2571   my ($symbol, $text) = @_;
2573   # Convert "|[" and "]|" into the start and end of program listing examples.
2574   $text =~ s%\|\[%<informalexample><programlisting>%g;
2575   $text =~ s%\]\|%</programlisting></informalexample>%g;
2576   # TODO: check for a xml comment after |[ and pick the language attribute from
2577   # that
2579   # keep CDATA unmodified, preserve ulink tags (ideally we preseve all tags
2580   # as such)
2581   return &ModifyXMLElements ($text, $symbol,
2582                              "<!\\[CDATA\\[|<ulink[^>]*>|<programlisting[^>]*>|<!DOCTYPE",
2583                              \&ExpandAbbreviationsEndTag,
2584                              \&ExpandAbbreviationsCallback);
2588 # Returns the end tag corresponding to the given start tag.
2589 sub ExpandAbbreviationsEndTag {
2590   my ($start_tag) = @_;
2592   if ($start_tag eq "<!\[CDATA\[") {
2593     return "]]>";
2594   } elsif ($start_tag eq "<!DOCTYPE") {
2595     return "]>";
2596   } elsif ($start_tag =~ m/<(\w+)/) {
2597     return "</$1>";
2598   }
2601 # Called inside or outside each CDATA or <programlisting> section.
2602 sub ExpandAbbreviationsCallback {
2603   my ($text, $symbol, $tag) = @_;
2605   if ($tag =~ m/^<programlisting/) {
2606     # Handle any embedded CDATA sections.
2607     return &ModifyXMLElements ($text, $symbol,
2608                                "<!\\[CDATA\\[",
2609                                \&ExpandAbbreviationsEndTag,
2610                                \&ExpandAbbreviationsCallback2);
2611   } elsif ($tag eq "") {
2612     # We are outside any CDATA or <programlisting> sections, so we expand
2613     # any gtk-doc abbreviations.
2615     # Convert 'function()' or 'macro()'.
2616     # if there is abc_*_def() we don't want to make a link to _def()
2617     # FIXME: also handle abc(....) : but that would need to be done recursively :/
2618     $text =~ s/([^\*.\w])(\w+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2619     # handle #Object.func()
2620     $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2622     # Convert '@param', but not '\@param'.
2623     $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)/$1<parameter>$2<\/parameter>/g;
2624     $text =~ s/\\\@/\@/g;
2626     # Convert '%constant', but not '\%constant'.
2627     # Also allow negative numbers, e.g. %-1.
2628     $text =~ s/(\A|[^\\])\%(-?\w+)/$1.&MakeXRef($2, &tagify($2, "literal"));/eg;
2629     $text =~ s/\\\%/\%/g;
2631     # Convert '#symbol', but not '\#symbol'.
2632     $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)/$1.&MakeHashXRef($2, "type");/eg;
2633     $text =~ s/\\#/#/g;
2634     
2635     # Expand urls
2636     # FIXME: should we skip urls that are already tagged? (e.g. <literal>http://...</literal>)
2637     # this is apparently also called for markup and not just for plain text
2638     # disable for now.
2639     #$text =~ s%(http|https|ftp)://(.*?)((?:\s|,|\)|\]|\<|\.\s))%<ulink url="$1://$2">$2</ulink>$3%g;
2641     # TODO: optionally check all words from $text against internal symbols and
2642     # warn if those could be xreffed, but miss a %,# or ()
2643   }
2645   return $text;
2648 # This is called inside a <programlisting>
2649 sub ExpandAbbreviationsCallback2 {
2650   my ($text, $symbol, $tag) = @_;
2652   if ($tag eq "") {
2653     # We are inside a <programlisting> but outside any CDATA sections,
2654     # so we expand any gtk-doc abbreviations.
2655     # FIXME: why is this different from &ExpandAbbreviationsCallback(),
2656     #        why not just call it
2657     $text =~ s/#(\w+)/&MakeHashXRef($1, "");/eg;
2658   }
2660   return $text;
2663 sub MakeHashXRef {
2664     my ($symbol, $tag) = @_;;
2665     my $text = $symbol;
2667     # Check for things like '#include', '#define', and skip them.
2668     if ($PreProcessorDirectives{$symbol}) {
2669       return "#$symbol";
2670     }
2672     # Get rid of any special '-struct' suffix.
2673     $text =~ s/-struct$//;
2675     # If the symbol is in the form "Object::signal", then change the symbol to
2676     # "Object-signal" and use "signal" as the text.
2677     if ($symbol =~ s/::/-/) {
2678       $text = "\"$'\"";
2679     }
2681     # If the symbol is in the form "Object:property", then change the symbol to
2682     # "Object--property" and use "property" as the text.
2683     if ($symbol =~ s/:/--/) {
2684       $text = "\"$'\"";
2685     }
2687     if ($tag ne "") {
2688       $text = tagify ($text, $tag);
2689     }
2690     
2691     return &MakeXRef($symbol, $text);
2695 #############################################################################
2696 # Function    : ModifyXMLElements
2697 # Description : Looks for given XML element tags within the text, and calls
2698 #               the callback on pieces of text inside & outside those elements.
2699 #               Used for special handling of text inside things like CDATA
2700 #               and <programlisting>.
2701 # Arguments   : $text - the text.
2702 #               $symbol - the symbol currently being documented (only used for
2703 #                      error messages).
2704 #               $start_tag_regexp - the regular expression to match start tags.
2705 #                      e.g. "<!\\[CDATA\\[|<programlisting[^>]*>" to match
2706 #                      CDATA sections or programlisting elements.
2707 #               $end_tag_func - function which is passed the matched start tag
2708 #                      and should return the appropriate end tag string.
2709 #               $callback - callback called with each part of the text. It is
2710 #                      called with a piece of text, the symbol being
2711 #                      documented, and the matched start tag or "" if the text
2712 #                      is outside the XML elements being matched.
2713 #############################################################################
2714 sub ModifyXMLElements {
2715     my ($text, $symbol, $start_tag_regexp, $end_tag_func, $callback) = @_;
2716     my ($before_tag, $start_tag, $end_tag_regexp, $end_tag);
2717     my $result = "";
2719     while ($text =~ m/$start_tag_regexp/s) {
2720       $before_tag = $`; # Prematch for last successful match string
2721       $start_tag = $&;  # Last successful match
2722       $text = $';       # Postmatch for last successful match string
2724       $result .= &$callback ($before_tag, $symbol, "");
2725       $result .= $start_tag;
2727       # get the mathing end-tag for current tag
2728       $end_tag_regexp = &$end_tag_func ($start_tag);
2730       if ($text =~ m/$end_tag_regexp/s) {
2731         $before_tag = $`;
2732         $end_tag = $&;
2733         $text = $';
2735         $result .= &$callback ($before_tag, $symbol, $start_tag);
2736         $result .= $end_tag;
2737       } else {
2738         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2739             "Can't find tag end: $end_tag_regexp in docs for: $symbol.");
2740         # Just assume it is all inside the tag.
2741         $result .= &$callback ($text, $symbol, $start_tag);
2742         $text = "";
2743       }
2744     }
2746     # Handle any remaining text outside the tags.
2747     $result .= &$callback ($text, $symbol, "");
2749     return $result;
2752 sub noop {
2753   return $_[0];
2756 # Adds a tag around some text.
2757 # e.g tagify("Text", "literal") => "<literal>Text</literal>".
2758 sub tagify {
2759    my ($text, $elem) = @_;
2760    return "<" . $elem . ">" . $text . "</" . $elem . ">";
2764 #############################################################################
2765 # Function    : MakeXRef
2766 # Description : This returns a cross-reference link to the given symbol.
2767 #               Though it doesn't try to do this for a few standard C types
2768 #               that it knows won't be in the documentation.
2769 # Arguments   : $symbol - the symbol to try to create a XRef to.
2770 #               $text - text text to put inside the XRef, defaults to $symbol
2771 #############################################################################
2773 sub MakeXRef {
2774     my ($symbol, $text) = ($_[0], $_[1]);
2776     $symbol =~ s/^\s+//;
2777     $symbol =~ s/\s+$//;
2779     if (!defined($text)) {
2780         $text = $symbol;
2782         # Get rid of special '-struct' suffix.
2783         $text =~ s/-struct$//;
2784     }
2786     if ($symbol =~ m/ /) {
2787         return "$text";
2788     }
2790     #print "Getting type link for $symbol -> $text\n";
2792     my $symbol_id = &CreateValidSGMLID ($symbol);
2793     return "<link linkend=\"$symbol_id\">$text</link>";
2797 #############################################################################
2798 # Function    : MakeIndexterms
2799 # Description : This returns a indexterm elements for the given symbol
2800 # Arguments   : $symbol - the symbol to create indexterms for
2801 #############################################################################
2803 sub MakeIndexterms {
2804   my ($symbol, $id) = @_;
2805   my $terms =  "";
2806   my $sortas = "";
2807   
2808   # make the index useful, by ommiting the namespace when sorting
2809   if ($NAME_SPACE ne "") {
2810     if ($symbol =~ m/^$NAME_SPACE\_?(.*)/i) {
2811        $sortas=" sortas=\"$1\"";
2812     }
2813   }
2815   if (exists $Deprecated{$symbol}) {
2816       $terms .= "<indexterm zone=\"$id\" role=\"deprecated\"><primary$sortas>$symbol</primary></indexterm>";
2817       $IndexEntriesDeprecated{$symbol}=$id;
2818       $IndexEntriesFull{$symbol}=$id;
2819   }
2820   if (exists $Since{$symbol}) {
2821      my $since = $Since{$symbol};
2822      $since =~ s/^\s+//;
2823      $since =~ s/\s+$//;
2824      if ($since ne "") {
2825          $terms .= "<indexterm zone=\"$id\" role=\"$since\"><primary$sortas>$symbol</primary></indexterm>";
2826      }
2827      $IndexEntriesSince{$symbol}=$id;
2828      $IndexEntriesFull{$symbol}=$id;
2829   }
2830   if ($terms eq "") {
2831      $terms .= "<indexterm zone=\"$id\"><primary$sortas>$symbol</primary></indexterm>";
2832      $IndexEntriesFull{$symbol}=$id;
2833   }
2835   return $terms;
2838 #############################################################################
2839 # Function    : MakeDeprecationNote
2840 # Description : This returns a deprecation warning for the given symbol.
2841 # Arguments   : $symbol - the symbol to try to create a warning for.
2842 #############################################################################
2844 sub MakeDeprecationNote {
2845     my ($symbol) = $_[0];
2846     my $desc = "";
2847     my $note = "";
2848     if (exists $Deprecated{$symbol}) {
2849         $desc .= "<warning>";
2851         if ($Deprecated{$symbol} =~ /^\s*([0-9\.]+)\s*:/) {
2852                 $desc .= "<para><literal>$symbol</literal> has been deprecated since version $1 and should not be used in newly-written code.";
2853         } else {
2854                 $desc .= "<para><literal>$symbol</literal> is deprecated and should not be used in newly-written code.";
2855         }
2856         if ($Deprecated{$symbol} ne "") {
2857             $note = &ExpandAbbreviations($symbol, $Deprecated{$symbol});
2858             $note =~ s/^\s*([0-9\.]+)\s*:\s*//;
2859             $note =~ s/^\s+//;
2860             $note =~ s/\s+$//;
2861             $note =~ s%\n{2,}%\n</para>\n<para>\n%g;
2862             $desc .= " " . $note;
2863         }
2864         $desc .= "</para></warning>\n";
2865     }
2866     return $desc;
2869 #############################################################################
2870 # Function    : MakeConditionDescription
2871 # Description : This returns a sumary of conditions for the given symbol.
2872 # Arguments   : $symbol - the symbol to try to create the sumary.
2873 #############################################################################
2875 sub MakeConditionDescription {
2876     my ($symbol) = $_[0];
2877     my $desc = "";
2879     if (exists $Deprecated{$symbol}) {
2880         if ($desc ne "") {
2881             $desc .= "|";
2882         }
2884         if ($Deprecated{$symbol} =~ /^\s*(.*?)\s*$/) {
2885                 $desc .= "deprecated:$1";
2886         } else {
2887                 $desc .= "deprecated";
2888         }
2889     }
2891     if (exists $Since{$symbol}) {
2892         if ($desc ne "") {
2893             $desc .= "|";
2894         }
2896         if ($Since{$symbol} =~ /^\s*(.*?)\s*$/) {
2897                 $desc .= "since:$1";
2898         } else {
2899                 $desc .= "since";
2900         }
2901     }
2903     if (exists $StabilityLevel{$symbol}) {
2904         if ($desc ne "") {
2905             $desc .= "|";
2906         }
2907         $desc .= "stability:".$StabilityLevel{$symbol};
2908     }
2910     if ($desc ne "") {
2911         $desc=" condition=\"".$desc."\"";
2912         #print "condition for '$symbol' = '$desc'\n";
2913     }
2914     return $desc;
2917 #############################################################################
2918 # Function    : GetHierarchy
2919 # Description : Returns the DocBook output describing the ancestors and
2920 #               immediate children of a GObject subclass. It uses the
2921 #               global @Objects and @ObjectLevels arrays to walk the tree.
2922 # Arguments   : $object - the GtkObject subclass.
2923 #############################################################################
2925 sub GetHierarchy {
2926     my ($object) = @_;
2928     # Find object in the objects array.
2929     my $found = 0;
2930     my @children = ();
2931     my $i;
2932     my $level;
2933     my $j;
2934     for ($i = 0; $i < @Objects; $i++) {
2935         if ($found) {
2936             if ($ObjectLevels[$i] <= $level) {
2937             last;
2938         }
2939             elsif ($ObjectLevels[$i] == $level + 1) {
2940                 push (@children, $Objects[$i]);
2941             }
2942         }
2943         elsif ($Objects[$i] eq $object) {
2944             $found = 1;
2945             $j = $i;
2946             $level = $ObjectLevels[$i];
2947         }
2948     }
2949     if (!$found) {
2950         return "";
2951     }
2953     # Walk up the hierarchy, pushing ancestors onto the ancestors array.
2954     my @ancestors = ();
2955     push (@ancestors, $object);
2956     #print "Level: $level\n";
2957     while ($level > 1) {
2958         $j--;
2959         if ($ObjectLevels[$j] < $level) {
2960             push (@ancestors, $Objects[$j]);
2961             $level = $ObjectLevels[$j];
2962             #print "Level: $level\n";
2963         }
2964     }
2966     # Output the ancestors list, indented and with links.
2967     my $hierarchy = "<synopsis>\n";
2968     $level = 0;
2969     for ($i = $#ancestors; $i >= 0; $i--) {
2970         my $link_text;
2971         # Don't add a link to the current object, i.e. when i == 0.
2972         if ($i > 0) {
2973             my $ancestor_id = &CreateValidSGMLID ($ancestors[$i]);
2974             $link_text = "<link linkend=\"$ancestor_id\">$ancestors[$i]</link>";
2975         } else {
2976             $link_text = "$ancestors[$i]";
2977         }
2978         if ($level == 0) {
2979             $hierarchy .= "  $link_text\n";
2980         } else {
2981 #           $hierarchy .= ' ' x ($level * 6 - 3) . "|\n";
2982             $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
2983         }
2984         $level++;
2985     }
2986     for ($i = 0; $i <= $#children; $i++) {
2987       my $id = &CreateValidSGMLID ($children[$i]);
2988       my $link_text = "<link linkend=\"$id\">$children[$i]</link>";
2989       $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
2990     }
2991     $hierarchy .= "</synopsis>\n";
2993     return $hierarchy;
2997 #############################################################################
2998 # Function    : GetInterfaces
2999 # Description : Returns the DocBook output describing the interfaces
3000 #               implemented by a class. It uses the global %Interfaces hash.
3001 # Arguments   : $object - the GtkObject subclass.
3002 #############################################################################
3004 sub GetInterfaces {
3005     my ($object) = @_;
3006     my $text = "";
3007     my $i;
3009     # Find object in the objects array.
3010     if (exists($Interfaces{$object})) {
3011         my @ifaces = split(' ', $Interfaces{$object});
3012         $text = <<EOF;
3013 <para>
3014 $object implements
3016         for ($i = 0; $i <= $#ifaces; $i++) {
3017             my $id = &CreateValidSGMLID ($ifaces[$i]);
3018             $text .= " <link linkend=\"$id\">$ifaces[$i]</link>";
3019             if ($i < $#ifaces - 1) {
3020                 $text .= ', ';
3021             }
3022             elsif ($i < $#ifaces) {
3023                 $text .= ' and ';
3024             }
3025             else {
3026                 $text .= '.';
3027             }
3028         }
3029         $text .= <<EOF;
3030 </para>
3032     }
3034     return $text;
3037 #############################################################################
3038 # Function    : GetImplementations
3039 # Description : Returns the DocBook output describing the implementations
3040 #               of an interface. It uses the global %Interfaces hash.
3041 # Arguments   : $object - the GtkObject subclass.
3042 #############################################################################
3044 sub GetImplementations {
3045     my ($object) = @_;
3046     my @impls = ();
3047     my $text = "";
3048     my $i;
3049     foreach my $key (keys %Interfaces) {
3050         if ($Interfaces{$key} =~ /\b$object\b/) {
3051             push (@impls, $key);
3052         }
3053     }
3054     if ($#impls >= 0) {
3055         $text = <<EOF;
3056 <para>
3057 $object is implemented by
3059         for ($i = 0; $i <= $#impls; $i++) {
3060             my $id = &CreateValidSGMLID ($impls[$i]);
3061             $text .= " <link linkend=\"$id\">$impls[$i]</link>";
3062             if ($i < $#impls - 1) {
3063                 $text .= ', ';
3064             }
3065             elsif ($i < $#impls) {
3066                 $text .= ' and ';
3067             }
3068             else {
3069                 $text .= '.';
3070             }
3071         }
3072         $text .= <<EOF;
3073 </para>
3075     }
3076     return $text;
3080 #############################################################################
3081 # Function    : GetPrerequisites
3082 # Description : Returns the DocBook output describing the prerequisites
3083 #               of an interface. It uses the global %Prerequisites hash.
3084 # Arguments   : $iface - the interface.
3085 #############################################################################
3087 sub GetPrerequisites {
3088     my ($iface) = @_;
3089     my $text = "";
3090     my $i;
3092     if (exists($Prerequisites{$iface})) {
3093         $text = <<EOF;
3094 <para>
3095 $iface requires
3097         my @prereqs = split(' ', $Prerequisites{$iface});
3098         for ($i = 0; $i <= $#prereqs; $i++) {
3099             my $id = &CreateValidSGMLID ($prereqs[$i]);
3100             $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
3101             if ($i < $#prereqs - 1) {
3102                 $text .= ', ';
3103             }
3104             elsif ($i < $#prereqs) {
3105                 $text .= ' and ';
3106             }
3107             else {
3108                 $text .= '.';
3109             }
3110         }
3111         $text .= <<EOF;
3112 </para>
3114     }
3115     return $text;
3118 #############################################################################
3119 # Function    : GetDerived
3120 # Description : Returns the DocBook output describing the derived interfaces
3121 #               of an interface. It uses the global %Prerequisites hash.
3122 # Arguments   : $iface - the interface.
3123 #############################################################################
3125 sub GetDerived {
3126     my ($iface) = @_;
3127     my $text = "";
3128     my $i;
3130     my @derived = ();
3131     foreach my $key (keys %Prerequisites) {
3132         if ($Prerequisites{$key} =~ /\b$iface\b/) {
3133             push (@derived, $key);
3134         }
3135     }
3136     if ($#derived >= 0) {
3137         $text = <<EOF;
3138 <para>
3139 $iface is required by
3141         for ($i = 0; $i <= $#derived; $i++) {
3142             my $id = &CreateValidSGMLID ($derived[$i]);
3143             $text .= " <link linkend=\"$id\">$derived[$i]</link>";
3144             if ($i < $#derived - 1) {
3145                 $text .= ', ';
3146             }
3147             elsif ($i < $#derived) {
3148                 $text .= ' and ';
3149             }
3150             else {
3151                 $text .= '.';
3152             }
3153         }
3154         $text .= <<EOF;
3155 </para>
3157     }
3158     return $text;
3162 #############################################################################
3163 # Function    : GetSignals
3164 # Description : Returns the synopsis and detailed description DocBook output
3165 #               for the signal handlers of a given GtkObject subclass.
3166 # Arguments   : $object - the GtkObject subclass, e.g. 'GtkButton'.
3167 #############################################################################
3169 sub GetSignals {
3170     my ($object) = @_;
3171     my $synop = "";
3172     my $desc = "";
3174     my $i;
3175     for ($i = 0; $i <= $#SignalObjects; $i++) {
3176         if ($SignalObjects[$i] eq $object) {
3177             #print "Found signal: $SignalNames[$i]\n";
3178             my $name = $SignalNames[$i];
3179             my $symbol = "${object}::${name}";
3180             my $id = &CreateValidSGMLID ("$object-$name");
3182             my $pad = ' ' x (46 - length($name));
3183             $synop .= "  &quot;<link linkend=\"$id\">$name</link>&quot;$pad ";
3185             $desc .= "<refsect2 id=\"$id\" role=\"signal\"><title>The <literal>&quot;$name&quot;</literal> signal</title>\n";
3186             $desc .= MakeIndexterms($symbol, $id);
3187             $desc .= "\n";
3188             $desc .= OutputSymbolExtraLinks($symbol);
3190             $desc .= "<programlisting>";
3192             $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
3193             my $type_modifier = defined($1) ? $1 : "";
3194             my $type = $2;
3195             my $pointer = $3;
3196             my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
3198             my $ret_type_len = length ($type_modifier) + length ($pointer)
3199                 + length ($type);
3200             my $ret_type_output = "$type_modifier$xref$pointer"
3201                 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
3203             $desc  .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
3205             my $sourceparams = $SourceSymbolParams{$symbol};
3206             my @params = split ("\n", $SignalPrototypes[$i]);
3207             my $j;
3208             my $l;
3209             my $type_len = length("gpointer");
3210             my $name_len = length("user_data");
3211             # do two passes, the first one is to calculate padding
3212             for ($l = 0; $l < 2; $l++) {
3213                 for ($j = 0; $j <= $#params; $j++) {
3214                     # allow alphanumerics, '_', '[' & ']' in param names
3215                     if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
3216                         $type = $1;
3217                         $pointer = $2;
3218                         if (defined($sourceparams)) {
3219                             $name = $$sourceparams[$PARAM_FIELD_COUNT * $j];
3220                         }
3221                         else {
3222                             $name = $3;
3223                         }
3224                         if (!defined($name)) {
3225                             $name = "arg$j";
3226                         }
3227                         if ($l == 0) {
3228                             if (length($type) + length($pointer) > $type_len) {
3229                                 $type_len = length($type) + length($pointer);
3230                             }
3231                             if (length($name) > $name_len) {
3232                                 $name_len = length($name);
3233                             }
3234                         }
3235                         else {
3236                             $xref = &MakeXRef ($type, &tagify($type, "type"));
3237                             $pad = ' ' x ($type_len - length($type) - length($pointer));
3238                             $desc .= "$xref$pad $pointer$name,\n";
3239                             $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
3240                         }
3241                     } else {
3242                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3243                              "Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]");
3244                     }
3245                 }
3246             }
3247             $xref = &MakeXRef ("gpointer", &tagify("gpointer", "type"));
3248             $pad = ' ' x ($type_len - length("gpointer"));
3249             $desc  .= "$xref$pad user_data)";
3251             my $flags = $SignalFlags[$i];
3252             my $flags_string = "";
3254             if (defined ($flags)) {
3255               if ($flags =~ m/f/) {
3256                 $flags_string = "Run First";
3257               }
3258               elsif ($flags =~ m/l/) {
3259                 $flags_string = "Run Last";
3260               }
3261               elsif ($flags =~ m/c/) {
3262                 $flags_string = "Cleanup";
3263               }
3264               if ($flags =~ m/r/) {
3265                 if ($flags_string) { $flags_string .= " / "; }
3266                 $flags_string .= "No Recursion";
3267               }
3268               if ($flags =~ m/d/) {
3269                 if ($flags_string) { $flags_string .= " / "; }
3270                 $flags_string .= "Has Details";
3271               }
3272               if ($flags =~ m/a/) {
3273                 if ($flags_string) { $flags_string .= " / "; }
3274                 $flags_string .= "Action";
3275               }
3276               if ($flags =~ m/h/) {
3277                 if ($flags_string) { $flags_string .= " / "; }
3278                 $flags_string .= "No Hooks";
3279               }
3280             }
3282             if ($flags_string)
3283               {
3284                 $synop .= ": $flags_string\n";
3286                 $pad = ' ' x (5 + $name_len - length("user_data"));
3287                 $desc  .= "$pad : $flags_string</programlisting>\n";
3288               }
3289             else
3290               {
3291                 $synop .= "\n";
3292                 $desc  .= "</programlisting>\n";
3293               }
3295             $desc .= &MakeDeprecationNote($symbol);
3297             my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
3298             my $parameters_output = 0;
3300             $AllSymbols{$symbol} = 1;
3301             if (defined ($SymbolDocs{$symbol})) {
3302                 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3304                 # Try to insert the parameter table at the author's desired
3305                 # position. Otherwise we need to tag it onto the end.
3306                 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
3307                   $parameters_output = 1;
3308                 }
3309                 $desc .= $symbol_docs;
3311                 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
3312                     $AllDocumentedSymbols{$symbol} = 1;
3313                 }
3314             }
3316             if ($parameters_output == 0) {
3317                 $desc .= $parameters;
3318               }
3319             $desc .= OutputSymbolTraits ($symbol);
3320             $desc .= "</refsect2>";
3321         }
3322     }
3323     return ($synop, $desc);
3327 #############################################################################
3328 # Function    : GetArgs
3329 # Description : Returns the synopsis and detailed description DocBook output
3330 #               for the Args of a given GtkObject subclass.
3331 # Arguments   : $object - the GtkObject subclass, e.g. 'GtkButton'.
3332 #############################################################################
3334 sub GetArgs {
3335     my ($object) = @_;
3336     my $synop = "";
3337     my $desc = "";
3338     my $child_synop = "";
3339     my $child_desc = "";
3340     my $style_synop = "";
3341     my $style_desc = "";
3343     my $i;
3344     for ($i = 0; $i <= $#ArgObjects; $i++) {
3345         if ($ArgObjects[$i] eq $object) {
3346             #print "Found arg: $ArgNames[$i]\n";
3347             my $name = $ArgNames[$i];
3348             my $flags = $ArgFlags[$i];
3349             my $flags_string = "";
3350             my $kind = "";
3351             my $id_sep = "";
3353             if ($flags =~ m/c/) {
3354                 $kind = "child property";
3355                 $id_sep = "c-";
3356             }
3357             elsif ($flags =~ m/s/) {
3358                 $kind = "style property";
3359                 $id_sep = "s-";
3360             }
3361             else {
3362                 $kind = "property";
3363             }
3365             # Remember only one colon so we don't clash with signals.
3366             my $symbol = "${object}:${name}";
3367             # use two dashes and ev. an extra separator here for the same reason.
3368             my $id = &CreateValidSGMLID ("$object--$id_sep$name");
3370             my $type = $ArgTypes[$i];
3371             my $type_output;
3372             my $range = $ArgRanges[$i];
3373             my $range_output = CreateValidSGML ($range);
3374             my $default = $ArgDefaults[$i];
3375             my $default_output = CreateValidSGML ($default);
3377             if ($type eq "GtkString") {
3378                 $type = "char*";
3379             }
3380             if ($type eq "GtkSignal") {
3381                 $type = "GtkSignalFunc, gpointer";
3382                 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
3383                     . &MakeXRef ("gpointer");
3384             } elsif ($type =~ m/^(\w+)\*$/) {
3385                 $type_output = &MakeXRef ($1, &tagify($1, "type")) . "*";
3386             } else {
3387                 $type_output = &MakeXRef ($type, &tagify($type, "type"));
3388             }
3390             if ($flags =~ m/r/) {
3391                 $flags_string = "Read";
3392             }
3393             if ($flags =~ m/w/) {
3394                 if ($flags_string) { $flags_string .= " / "; }
3395                 $flags_string .= "Write";
3396             }
3397             if ($flags =~ m/x/) {
3398                 if ($flags_string) { $flags_string .= " / "; }
3399                 $flags_string .= "Construct";
3400             }
3401             if ($flags =~ m/X/) {
3402                 if ($flags_string) { $flags_string .= " / "; }
3403                 $flags_string .= "Construct Only";
3404             }
3406             $AllSymbols{$symbol} = 1;
3407             my $blurb;
3408             if (defined($SymbolDocs{$symbol}) &&
3409                 !IsEmptyDoc($SymbolDocs{$symbol})) {
3410                 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3411                 #print ".. [$SymbolDocs{$symbol}][$blurb]\n";
3412                 $AllDocumentedSymbols{$symbol} = 1;
3413             }
3414             else {
3415                 if (!($ArgBlurbs[$i] eq "")) {
3416                     $AllDocumentedSymbols{$symbol} = 1;
3417                 } else {
3418                     # FIXME: print a warning?
3419                     #print ".. no description\n";
3420                 }
3421                 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
3422             }
3424             my $pad1 = " " x (24 - length ($name));
3425             my $pad2 = " " x (20 - length ($type));
3427             my $arg_synop = "  &quot;<link linkend=\"$id\">$name</link>&quot;$pad1 $type_output $pad2 : $flags_string\n";
3428             my $arg_desc = "<refsect2 id=\"$id\" role=\"property\"><title>The <literal>&quot;$name&quot;</literal> $kind</title>\n";
3429             $arg_desc .= MakeIndexterms($symbol, $id);
3430             $arg_desc .= "\n";
3431             $arg_desc .= OutputSymbolExtraLinks($symbol);
3433             $arg_desc .= "<programlisting>  &quot;$name&quot;$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
3434             $arg_desc .= &MakeDeprecationNote($symbol);
3435             $arg_desc .= $blurb;
3436             if ($range ne "") {
3437                 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
3438             }
3439             if ($default ne "") {
3440                 $arg_desc .= "<para>Default value: $default_output</para>\n";
3441             }
3442             $arg_desc .= OutputSymbolTraits ($symbol);
3443             $arg_desc .= "</refsect2>\n";
3445             if ($flags =~ m/c/) {
3446                 $child_synop .= $arg_synop;
3447                 $child_desc .= $arg_desc;
3448             }
3449             elsif ($flags =~ m/s/) {
3450                 $style_synop .= $arg_synop;
3451                 $style_desc .= $arg_desc;
3452             }
3453             else {
3454                 $synop .= $arg_synop;
3455                 $desc .= $arg_desc;
3456             }
3457         }
3458     }
3459     return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
3463 #############################################################################
3464 # Function    : ReadSourceDocumentation
3465 # Description : This reads in the documentation embedded in comment blocks
3466 #               in the source code (for Gnome).
3468 #               Parameter descriptions override any in the template files.
3469 #               Function descriptions are placed before any description from
3470 #               the template files.
3472 #               It recursively descends the source directory looking for .c
3473 #               files and scans them looking for specially-formatted comment
3474 #               blocks.
3476 # Arguments   : $source_dir - the directory to scan.
3477 #############m###############################################################
3479 sub ReadSourceDocumentation {
3480     my ($source_dir) = @_;
3481     my ($file, $dir, @suffix_list, $suffix);
3482     #print "Scanning source directory: $source_dir\n";
3484     # This array holds any subdirectories found.
3485     my (@subdirs) = ();
3487     @suffix_list = split (/,/, $SOURCE_SUFFIXES);
3489     opendir (SRCDIR, $source_dir)
3490         || die "Can't open source directory $source_dir: $!";
3492     foreach $file (readdir (SRCDIR)) {
3493       if ($file =~ /^\./) {
3494         next;
3495       } elsif (-d "$source_dir/$file") {
3496         push (@subdirs, $file);
3497       } elsif (@suffix_list) {
3498         foreach $suffix (@suffix_list) {
3499           if ($file =~ m/\.\Q${suffix}\E$/) {
3500             &ScanSourceFile ("$source_dir/$file");
3501           }
3502         }
3503       } elsif ($file =~ m/\.[ch]$/) {
3504         &ScanSourceFile ("$source_dir/$file");
3505       }
3506     }
3507     closedir (SRCDIR);
3509     # Now recursively scan the subdirectories.
3510     foreach $dir (@subdirs) {
3511         next if ($IGNORE_FILES =~ m/(\s|^)\Q${dir}\E(\s|$)/);
3512         &ReadSourceDocumentation ("$source_dir/$dir");
3513     }
3517 #############################################################################
3518 # Function    : ScanSourceFile
3519 # Description : Scans one source file looking for specially-formatted comment
3520 #               blocks. Later &MergeSourceDocumentation is used to merge any
3521 #               documentation found with the documentation already read in
3522 #               from the template files.
3524 # Arguments   : $file - the file to scan.
3525 #############################################################################
3527 sub ScanSourceFile {
3528     my ($file) = @_;
3529     my $basename;
3531     if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
3532         $basename = $1;
3533     } else {
3534         &LogWarning ($file, 1, "Can't find basename for this filename.");
3535         $basename = $file;
3536     }
3538     # Check if the basename is in the list of files to ignore.
3539     if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
3540         return;
3541     }
3543     #print "DEBUG: Scanning $file\n";
3545     open (SRCFILE, $file)
3546         || die "Can't open $file: $!";
3547     my $in_comment_block = 0;
3548     my $symbol;
3549     my ($in_description, $in_return, $in_since, $in_stability, $in_deprecated);
3550     my ($description, $return_desc, $return_start, $return_style);
3551     my ($since_desc, $stability_desc, $deprecated_desc);
3552     my $current_param;
3553     my $ignore_broken_returns;
3554     my @params;
3555     while (<SRCFILE>) {
3556         # Look for the start of a comment block.
3557         if (!$in_comment_block) {
3558             if (m%^\s*/\*.*\*/%) {
3559                 #one-line comment - not gtkdoc
3560             } elsif (m%^\s*/\*\*\s%) {
3561                 #print "Found comment block start\n";
3563                 $in_comment_block = 1;
3565                 # Reset all the symbol data.
3566                 $symbol = "";
3567                 $in_description = 0;
3568                 $in_return = 0;
3569                 $in_since = 0;
3570                 $in_deprecated = 0;
3571                 $in_stability = 0;
3572                 $description = "";
3573                 $return_desc = "";
3574                 $return_style = "";
3575                 $since_desc = "";
3576                 $deprecated_desc = "";
3577                 $stability_desc = "";
3578                 $current_param = -1;
3579                 $ignore_broken_returns = 0;
3580                 @params = ();
3581             }
3582             next;
3583         }
3585         # We're in a comment block. Check if we've found the end of it.
3586         if (m%^\s*\*+/%) {
3587             if (!$symbol) {
3588                 # maybe its not even meant to be a gtk-doc comment?
3589                 &LogWarning ($file, $., "Symbol name not found at the start of the comment block.");
3590             } else {
3591                 # Add the return value description onto the end of the params.
3592                 if ($return_desc) {
3593                     push (@params, "Returns");
3594                     push (@params, $return_desc);
3595                     if ($return_style eq 'broken') {
3596                         &LogWarning ($file, $., "Free-form return value description in $symbol. Use `Returns:' to avoid ambiguities.");
3597                     }
3598                 }
3599                 # Convert special SGML characters
3600                 $description = &ConvertSGMLChars ($symbol, $description);
3601                 my $k;
3602                 for ($k = 1; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3603                     $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
3604                 }
3606                 # Handle Section docs
3607                 if ($symbol =~ m/SECTION:\s*(.*)/) {
3608                     my $real_symbol=$1;
3609                     my $key;
3611                     if (scalar %KnownSymbols) {
3612                         if ((! defined($KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"})) || $KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"} != 1) {
3613                             &LogWarning ($file, $., "Section $real_symbol is not defined in the $MODULE-section.txt file.");
3614                         }
3615                     }
3617                     #print "SECTION DOCS found in source for : '$real_symbol'\n";
3618                     $ignore_broken_returns = 1;
3619                     for ($k = 0; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3620                         #print "   '".$params[$k]."'\n";
3621                         $params[$k] = "\L$params[$k]";
3622                         undef $key;
3623                         if ($params[$k] eq "short_description") {
3624                             $key = "$TMPL_DIR/$real_symbol:Short_Description";
3625                         } elsif ($params[$k] eq "see_also") {
3626                             $key = "$TMPL_DIR/$real_symbol:See_Also";
3627                         } elsif ($params[$k] eq "title") {
3628                             $key = "$TMPL_DIR/$real_symbol:Title";
3629                         } elsif ($params[$k] eq "stability") {
3630                             $key = "$TMPL_DIR/$real_symbol:Stability_Level";
3631                         } elsif ($params[$k] eq "section_id") {
3632                             $key = "$TMPL_DIR/$real_symbol:Section_Id";
3633                         } elsif ($params[$k] eq "include") {
3634                             $key = "$TMPL_DIR/$real_symbol:Include";
3635                         }
3636                         if (defined($key)) {
3637                             $SourceSymbolDocs{$key}=$params[$k+1];
3638                             $SourceSymbolSourceFile{$key} = $file;
3639                             $SourceSymbolSourceLine{$key} = $.;
3640                         }
3641                     }
3642                     $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
3643                     $SourceSymbolSourceFile{"$TMPL_DIR/$real_symbol:Long_Description"} = $file;
3644                     $SourceSymbolSourceLine{"$TMPL_DIR/$real_symbol:Long_Description"} = $.;
3645                     #$SourceSymbolTypes{$symbol} = "SECTION";
3646                 } else {
3647                     #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
3648                     $SourceSymbolDocs{$symbol} = $description;
3649                     $SourceSymbolParams{$symbol} = [ @params ];
3650                     # FIXME $SourceSymbolTypes{$symbol} = "STRUCT,SIGNAL,ARG,FUNCTION,MACRO";
3651                     #if (defined $DeclarationTypes{$symbol}) {
3652                     #    $SourceSymbolTypes{$symbol} = $DeclarationTypes{$symbol}
3653                     #}
3654                     $SourceSymbolSourceFile{$symbol} = $file;
3655                     $SourceSymbolSourceLine{$symbol} = $.;
3656                 }
3658                 if ($since_desc) {
3659                      ($since_desc, my @extra_lines) = split ("\n", $since_desc);
3660                      $since_desc =~ s/^\s+//;
3661                      $since_desc =~ s/\s+$//;
3662                      #print "Since($symbol) : [$since_desc]\n";
3663                      $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
3664                      if(scalar @extra_lines) {
3665                          &LogWarning ($file, $., "multi-line since docs found");
3666                      }
3667                 }
3669                 if ($stability_desc) {
3670                     $stability_desc = &ParseStabilityLevel($stability_desc, $file, $., "Stability level for $symbol");
3671                     $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
3672                 }
3674                 if ($deprecated_desc) {
3675                     if (exists $Deprecated{$symbol}) {
3676                     }
3677                     else {
3678                          # don't warn for signals and properties
3679                          #if ($symbol !~ m/::?(.*)/) {
3680                          if (defined $DeclarationTypes{$symbol}) {
3681                              &LogWarning ($file, $., 
3682                                  "$symbol is deprecated in the inline comments, but no deprecation guards were found around the declaration.".
3683                                  " (See the --deprecated-guards option for gtkdoc-scan.)");
3684                          }
3685                     }
3686                     $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
3687                 }
3688             }
3690             $in_comment_block = 0;
3691             next;
3692         }
3694         # Get rid of ' * ' at start of every line in the comment block.
3695         s%^\s*\*\s?%%;
3696         # But make sure we don't get rid of the newline at the end.
3697         if (!$_) {
3698             $_ = "\n";
3699         }
3700         #print "DEBUG: scanning :$_";
3702         # If we haven't found the symbol name yet, look for it.
3703         if (!$symbol) {
3704             if (m%^\s*(SECTION:\s*\S+)%) {
3705                 $symbol = $1;
3706                 #print "SECTION DOCS found in source for : '$symbol'\n";
3707                 $ignore_broken_returns = 1;
3708             } elsif (m%^\s*([\w:-]*\w)\s*:?\s*$%) {
3709                 $symbol = $1;
3710                 #print "SYMBOL DOCS found in source for : '$symbol'\n";
3711             }
3712             next;
3713         }
3715         # If we're in the return value description, add it to the end.
3716         if ($in_return) {
3717             # If we find another valid returns line, we assume that the first
3718             # one was really part of the description.
3719             if (m/^\s*(returns:|return\s+value:)/i) {
3720                 if ($return_style eq 'broken') {
3721                     $description .= $return_start . $return_desc;
3722                 }
3723                 $return_start = $1;
3724                 if ($return_style eq 'sane') {
3725                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3726                 }
3727                 $return_style = 'sane';
3728                 $ignore_broken_returns = 1;
3729                 $return_desc = $';
3730             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3731                 $description .= $return_start . $return_desc;
3732                 $return_start = $1;
3733                 $return_style = 'broken';
3734                 $return_desc = $';
3735             } elsif (m%^\s*since:%i) {
3736                 $since_desc = $';
3737                 $in_since = 1;
3738                 $in_return = 0;
3739             } elsif (m%^\s*stability:%i) {
3740                 $stability_desc = $';
3741                 $in_stability = 1;
3742                 $in_return = 0;
3743             } elsif (m%^\s*deprecated:%i) {
3744                 $deprecated_desc = $';
3745                 $in_deprecated = 1;
3746                 $in_return = 0;
3747             } else {
3748                 $return_desc .= $_;
3749             }
3750             next;
3751         }
3753         if ($in_since) {
3754             if (m/^\s*(returns:|return\s+value:)/i) {
3755                 if ($return_style eq 'broken') {
3756                     $description .= $return_start . $return_desc;
3757                 }
3758                 $return_start = $1;
3759                 if ($return_style eq 'sane') {
3760                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3761                 }
3762                 $return_style = 'sane';
3763                 $ignore_broken_returns = 1;
3764                 $return_desc = $';
3765                 $in_return = 1;
3766                 $in_since = 0;
3767             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3768                 $return_start = $1;
3769                 $return_style = 'broken';
3770                 $return_desc = $';
3771                 $in_return = 1;
3772                 $in_since = 0;
3773             } elsif (m%^\s*deprecated:%i) {
3774                 $deprecated_desc = $';
3775                 $in_deprecated = 1;
3776                 $in_since = 0;
3777             } elsif (m%^\s*stability:%i) {
3778                 $stability_desc = $';
3779                 $in_stability = 1;
3780                 $in_since = 0;
3781             } else {
3782                 $since_desc .= $_;
3783             }
3784             next;
3785         }
3787         if ($in_stability) {
3788             if (m/^\s*(returns:|return\s+value:)/i) {
3789                 if ($return_style eq 'broken') {
3790                     $description .= $return_start . $return_desc;
3791                 }
3792                 $return_start = $1;
3793                 if ($return_style eq 'sane') {
3794                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3795                 }
3796                 $return_style = 'sane';
3797                 $ignore_broken_returns = 1;
3798                 $return_desc = $';
3799                 $in_return = 1;
3800                 $in_stability = 0;
3801             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3802                 $return_start = $1;
3803                 $return_style = 'broken';
3804                 $return_desc = $';
3805                 $in_return = 1;
3806                 $in_stability = 0;
3807             } elsif (m%^\s*deprecated:%i) {
3808                 $deprecated_desc = $';
3809                 $in_deprecated = 1;
3810                 $in_stability = 0;
3811             } elsif (m%^\s*since:%i) {
3812                 $since_desc = $';
3813                 $in_since = 1;
3814                 $in_stability = 0;
3815             } else {
3816                 $stability_desc .= $_;
3817             }
3818             next;
3819         }
3821         if ($in_deprecated) {
3822             if (m/^\s*(returns:|return\s+value:)/i) {
3823                 if ($return_style eq 'broken') {
3824                     $description .= $return_start . $return_desc;
3825                 }
3826                 $return_start = $1;
3827                 if ($return_style eq 'sane') {
3828                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3829                 }
3830                 $return_style = 'sane';
3831                 $ignore_broken_returns = 1;
3832                 $return_desc = $';
3833                 $in_return = 1;
3834                 $in_deprecated = 0;
3835             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3836                 $return_start = $1;
3837                 $return_style = 'broken';
3838                 $return_desc = $';
3839                 $in_return = 1;
3840                 $in_deprecated = 0;
3841             } elsif (m%^\s*since:%i) {
3842                 $since_desc = $';
3843                 $in_since = 1;
3844                 $in_deprecated = 0;
3845             } elsif (m%^\s*stability:%i) {
3846                 $stability_desc = $';
3847                 $in_stability = 1;
3848                 $in_deprecated = 0;
3849             } else {
3850                 $deprecated_desc .= $_;
3851             }
3852             next;
3853         }
3855         # If we're in the description part, check for the 'Returns:' line.
3856         # If that isn't found, add the text to the end.
3857         if ($in_description) {
3858             # Get rid of 'Description:'
3859             s%^\s*Description:%%;
3861             if (m/^\s*(returns:|return\s+value:)/i) {
3862                 if ($return_style eq 'broken') {
3863                     $description .= $return_start . $return_desc;
3864                 }
3865                 $return_start = $1;
3866                 if ($return_style eq 'sane') {
3867                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3868                 }
3869                 $return_style = 'sane';
3870                 $ignore_broken_returns = 1;
3871                 $return_desc = $';
3872                 $in_return = 1;
3873                 next;
3874             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3875                 $return_start = $1;
3876                 $return_style = 'broken';
3877                 $return_desc = $';
3878                 $in_return = 1;
3879                 next;
3880             } elsif (m%^\s*since:%i) {
3881                 $since_desc = $';
3882                 $in_since = 1;
3883                 next;
3884             } elsif (m%^\s*deprecated:%i) {
3885                 $deprecated_desc = $';
3886                 $in_deprecated = 1;
3887                 next;
3888             } elsif (m%^\s*stability:%i) {
3889                 $stability_desc = $';
3890                 $in_stability = 1;
3891                 next;
3892             }
3894             $description .= $_;
3895             next;
3896         }
3898         # We must be in the parameters. Check for the empty line below them.
3899         if (m%^\s*$%) {
3900             $in_description = 1;
3901             next;
3902         }
3904         # Look for a parameter name.
3905         if (m%^\s*@(\S+)\s*:\s*%) {
3906             my $param_name = $1;
3907             my $param_desc = $';
3909             #print "Found parameter: $param_name\n";
3910             # Allow '...' as the Varargs parameter.
3911             if ($param_name eq "...") {
3912                 $param_name = "Varargs";
3913             }
3914             if ("\L$param_name" eq "returns") {
3915                 $return_style = 'sane';
3916                 $ignore_broken_returns = 1;
3917             }
3918             push (@params, $param_name);
3919             push (@params, $param_desc);
3920             $current_param += $PARAM_FIELD_COUNT;
3921             next;
3922         }
3924         # We must be in the middle of a parameter description, so add it on
3925         # to the last element in @params.
3926         if ($current_param == -1) {
3927             &LogWarning ($file, $., "Parsing comment block file : parameter expected.");
3928         } else {
3929             $params[$#params] .= $_;
3930         }
3931     }
3932     close (SRCFILE);
3935 #############################################################################
3936 # Function    : OutputMissingDocumentation
3937 # Description : Outputs report of documentation coverage to a file
3939 # Arguments   : none
3940 #############################################################################
3942 sub OutputMissingDocumentation {
3943     my $n_documented = 0;
3944     my $n_incomplete = 0;
3945     my $total = 0;
3946     my $symbol;
3947     my $percent;
3948     my $msg;
3949     my $buffer = "";
3950     my $buffer_deprecated = "";
3951     my $buffer_descriptions = "";
3952     
3953     open (UNDOCUMENTED, ">$ROOT_DIR/$MODULE-undocumented.txt")
3954       || die "Can't create $ROOT_DIR/$MODULE-undocumented.txt: $!";
3955     
3956     foreach $symbol (sort (keys (%AllSymbols))) {
3957         # FIXME: should we print LogWarnings for undocumented stuff?
3958         # DEBUG
3959         #my $ssfile = &GetSymbolSourceFile($symbol);
3960         #my $ssline = &GetSymbolSourceLine($symbol);
3961         #my $location = "defined at " . (defined($ssfile)?$ssfile:"?") . ":" . (defined($ssline)?$ssline:"0") . "\n";
3962         # DEBUG
3963         if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include|Section_Id)/) {
3964             $total++;
3965             if (exists ($AllDocumentedSymbols{$symbol})) {
3966                 $n_documented++;
3967                 if (exists ($AllIncompleteSymbols{$symbol})) {
3968                     $n_incomplete++;
3969                     $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3970                     #$buffer .= "\t0: ".$location;
3971                 }
3972             } elsif (exists $Deprecated{$symbol}) {
3973                 if (exists ($AllIncompleteSymbols{$symbol})) {
3974                     $n_incomplete++;
3975                     $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3976                     #$buffer .= "\t1a: ".$location;
3977                 } else {
3978                     $buffer_deprecated .= $symbol . "\n";
3979                     #$buffer .= "\t1b: ".$location;
3980                 }
3981             } else {
3982                 if (exists ($AllIncompleteSymbols{$symbol})) {
3983                     $n_incomplete++;
3984                     $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3985                     #$buffer .= "\t2a: ".$location;
3986                 } else {
3987                     $buffer .= $symbol . "\n";
3988                     #$buffer .= "\t2b: ".$location;
3989                 }
3990             }
3991         } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
3992             $total++;
3993             #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
3994             #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
3995             #print "%%%% $symbol : $len1,$len2\n";
3996             if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
3997             || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
3998               $n_documented++;
3999             } else {
4000               # cut off the leading namespace ($TMPL_DIR)
4001               $symbol =~ m/^.*\/(.*)$/;
4002               $buffer_descriptions .= $1 . "\n";
4003             }
4004         }
4005     }
4006     
4007     $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
4008     
4009     if ($total == 0) {
4010       $percent = 100;
4011     } else {
4012       $percent = ($n_documented / $total) * 100.0;
4013     }
4014     
4015     printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
4016     print UNDOCUMENTED "$n_documented symbols documented.\n";
4017     print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
4018     print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
4019     
4020     print UNDOCUMENTED $buffer;
4021     
4022     close (UNDOCUMENTED);
4023     
4024     printf (("%.0f%% symbol docs coverage ($n_documented symbols documented, $n_incomplete symbols incomplete, " . ($total - $n_documented) . " not documented)\nSee $MODULE-undocumented.txt for a list of missing docs.\nThe doc coverage percentage doesn't include intro sections.\n"), $percent);
4028 #############################################################################
4029 # Function    : OutputUndeclaredSymbols
4030 # Description : Outputs symbols that are undeclared yet documented to a file
4032 # Arguments   : none
4033 #############################################################################
4035 sub OutputUndeclaredSymbols {
4036     open(UNDECLARED, ">$ROOT_DIR/$MODULE-undeclared.txt")
4037         || die "Can't create $ROOT_DIR/$MODULE-undeclared.txt";
4039     if (%UndeclaredSymbols) {
4040         print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
4041         print UNDECLARED "\n";
4042         print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
4043     }
4044     close(UNDECLARED);
4048 #############################################################################
4049 # Function    : OutputAllSymbols
4050 # Description : Outputs list of all symbols to a file
4052 # Arguments   : none
4053 #############################################################################
4055 sub OutputAllSymbols {
4056      my $n_documented = 0;
4057      my $total = 0;
4058      my $symbol;
4059      my $percent;
4060      my $msg;
4062      open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
4063           || die "Can't create $ROOT_DIR/$MODULE-symbols.txt: $!";
4065      foreach $symbol (sort (keys (%AllSymbols))) {
4066           print SYMBOLS $symbol . "\n";
4067      }
4069      close (SYMBOLS);
4072 #############################################################################
4073 # Function    : OutputSymbolsWithoutSince
4074 # Description : Outputs list of all symbols without a since tag to a file
4076 # Arguments   : none
4077 #############################################################################
4079 sub OutputSymbolsWithoutSince {
4080      my $n_documented = 0;
4081      my $total = 0;
4082      my $symbol;
4083      my $percent;
4084      my $msg;
4086      open (SYMBOLS, ">$ROOT_DIR/$MODULE-nosince.txt")
4087           || die "Can't create $ROOT_DIR/$MODULE-nosince.txt: $!";
4089      foreach $symbol (sort (keys (%SourceSymbolDocs))) {
4090          if (!defined $Since{$symbol}) {
4091              print SYMBOLS $symbol . "\n";
4092          }
4093      }
4095      close (SYMBOLS);
4099 #############################################################################
4100 # Function    : MergeSourceDocumentation
4101 # Description : This merges documentation read from a source file into the
4102 #               documentation read in from a template file.
4104 #               Parameter descriptions override any in the template files.
4105 #               Function descriptions are placed before any description from
4106 #               the template files.
4108 # Arguments   : none
4109 #############################################################################
4111 sub MergeSourceDocumentation {
4112     my $symbol;
4113     my @Symbols;
4115     if (scalar %SymbolDocs) {
4116         @Symbols=keys (%SymbolDocs);
4117         #print "num existing entries: ".(scalar @Symbols)."\n";
4118         #print "  ",$Symbols[0], " ",$Symbols[1],"\n";
4119     }
4120     else {
4121         # filter scanned declarations, with what we suppress from -sections.txt
4122         my %tmp = ();
4123         foreach $symbol (keys (%Declarations)) {
4124             if (defined($KnownSymbols{$symbol}) && $KnownSymbols{$symbol} == 1) {
4125                 $tmp{$symbol}=1;
4126             }
4127         }
4128         # , add the rest from -sections.txt
4129         foreach $symbol (keys (%KnownSymbols)) {
4130             if ($KnownSymbols{$symbol} == 1) {
4131                 $tmp{$symbol}=1;
4132             }
4133         }
4134         # and add whats found in the source
4135         foreach $symbol (keys (%SourceSymbolDocs)) {
4136             $tmp{$symbol}=1;
4137         }
4138         @Symbols = keys (%tmp);
4139         #print "num source entries: ".(scalar @Symbols)."\n";
4140     }
4141     foreach $symbol (@Symbols) {
4142         $AllSymbols{$symbol} = 1;
4144         my $have_tmpl_docs = 0;
4146         ## See if the symbol is documented in template
4147         my $tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4148         my $check_tmpl_doc =$tmpl_doc;
4149         # remove all xml-tags and whitespaces
4150         #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
4151         $check_tmpl_doc =~ s/<.*?>//g;
4152         $check_tmpl_doc =~ s/\s//g;
4153         # anything left ?
4154         if ($check_tmpl_doc ne "") {
4155             $have_tmpl_docs = 1;
4156             #print "## [$check_tmpl_doc]\n";
4157         } else {
4158             $tmpl_doc = "";
4159         }
4161         if (exists ($SourceSymbolDocs{$symbol})) {
4162             my $type = $DeclarationTypes {$symbol};
4164             #print "merging [$symbol] from source\n";
4166             my $item = "Parameter";
4167             if (defined ($type)) {
4168                 if ($type eq 'STRUCT') {
4169                     $item = "Field";
4170                 } elsif ($type eq 'ENUM') {
4171                     $item = "Value";
4172                 } elsif ($type eq 'UNION') {
4173                     $item = "Field";
4174                 }
4175             } else {
4176                 $type="SIGNAL";
4177             }
4179             my $src_doc = $SourceSymbolDocs{$symbol};
4180             # remove leading and training whitespaces
4181             $src_doc =~ s/^\s+//;
4182             $src_doc =~ s/\s+$//;
4184             # Don't output warnings for overridden titles as titles are
4185             # automatically generated in the -sections.txt file, and thus they
4186             # are often overridden.
4187             if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
4188                 # check if content is different
4189                 if ($tmpl_doc ne $src_doc) {
4190                     #print "[$tmpl_doc] [$src_doc]\n";
4191                     &LogWarning ($SourceSymbolSourceFile{$symbol}, $SourceSymbolSourceLine{$symbol},
4192                         "Documentation in template ".$SymbolSourceFile{$symbol}.":".$SymbolSourceLine{$symbol}." for $symbol being overridden by inline comments.");
4193                 }
4194             }
4196             if ($src_doc ne "") {
4197                  $AllDocumentedSymbols{$symbol} = 1;
4198             }
4200             # Convert <!--PARAMETERS--> with any blank lines around it to
4201             # a </para> followed by <!--PARAMETERS--> followed by <para>.
4202             $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
4204             # If there is a blank line, finish the paragraph and start another.
4205             $src_doc = &ConvertBlankLines ($src_doc, $symbol);
4206             # Do not add <para> to nothing, it breaks missing docs checks.
4207             my $src_doc_para = "";
4208             if ($src_doc) {
4209                 $src_doc_para = "<para>\n$src_doc</para>\n";
4210                 #print "$symbol : [$src_doc][$src_doc_para]\n";
4211             }
4213             if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
4214                 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4215             } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
4216                 # For the title/summary/see also section docs we don't want to
4217                 # add any <para> tags.
4218                 $SymbolDocs{$symbol} = "$src_doc"
4219             } else {
4220                 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4221             }
4223             # merge parameters
4224             if ($symbol =~ m/.*::.*/) {
4225                 # For signals we prefer the param names from the source docs,
4226                 # since the ones from the templates are likely to contain the
4227                 # artificial argn names which are generated by gtkdoc-scangobj.
4228                 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4229                 # FIXME: we need to check for empty docs here as well!
4230             } else {
4231                 # The templates contain the definitive parameter names and order,
4232                 # so we will not change that. We only override the actual text.
4233                 my $tmpl_params = $SymbolParams{$symbol};
4234                 if (!defined ($tmpl_params)) {
4235                     #print "No merge needed for $symbol\n";
4236                     $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4237                     #  FIXME: we still like to get the number of params and merge
4238                     #  1) we would noticed that params have been removed/renamed
4239                     #  2) we would catch undocumented params
4240                     #  params are not (yet) exported in -decl.txt so that we
4241                     #  could easily grab them :/
4242                 } else {
4243                     my $params = $SourceSymbolParams{$symbol};
4244                     my $j;
4245                     #print "Merge needed for $symbol, tmpl_params: ",$#$tmpl_params,", source_params: ",$#$params," \n";
4246                     for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4247                         my $tmpl_param_name = $$tmpl_params[$j];
4249                         # Allow '...' as the Varargs parameter.
4250                         if ($tmpl_param_name eq "...") {
4251                             $tmpl_param_name = "Varargs";
4252                         }
4254                         # Try to find the param in the source comment documentation.
4255                         my $found = 0;
4256                         my $k;
4257                         #print "  try merge param $tmpl_param_name\n";
4258                         for ($k = 0; $k <= $#$params; $k += $PARAM_FIELD_COUNT) {
4259                             my $param_name = $$params[$k];
4260                             my $param_desc = $$params[$k + 1];
4262                             #print "    test param  $param_name\n";
4263                             # We accept changes in case, since the Gnome source
4264                             # docs contain a lot of these.
4265                             if ("\L$param_name" eq "\L$tmpl_param_name") {
4266                                 $found = 1;
4268                                 # Override the description.
4269                                 $$tmpl_params[$j + 1] = $param_desc;
4271                                 # Set the name to "" to mark it as used.
4272                                 $$params[$k] = "";
4273                                 last;
4274                             }
4275                         }
4277                         # If it looks like the parameters are there, but not
4278                         # in the right place, try to explain a bit better.
4279                         if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
4280                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4281                                 "Parameters for $symbol must start on the line immediately after the function or macro name.");
4282                         }
4283                     }
4285                     # Now we output a warning if parameters have been described which
4286                     # do not exist.
4287                     for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
4288                         my $param_name = $$params[$j];
4289                         if ($param_name) {
4290                             # the template builder cannot detect if a macro returns
4291                             # a result or not
4292                             if(($type eq "MACRO") && ($param_name eq "Returns")) {
4293                                 # FIXME: do we need to add it then to tmpl_params[] ?
4294                                 my $num=$#$tmpl_params;
4295                                 #print "  adding Returns: to macro docs for $symbol.\n";
4296                                 $$tmpl_params[$num+1]="Returns";
4297                                 $$tmpl_params[$num+2]=$$params[$j+1];
4298                                 next;
4299                             }
4300                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4301                                 "$item described in source code comment block but does not exist. $type: $symbol $item: $param_name.");
4302                         }
4303                     }
4304                 }
4305             }
4306         } else {
4307             if ($have_tmpl_docs) {
4308                 $AllDocumentedSymbols{$symbol} = 1;
4309                 #print "merging [$symbol] from template\n";
4310             }
4311             else {
4312                 #print "[$symbol] undocumented\n";
4313             }
4314         }
4316         # if this symbol is documented, check if docs are complete
4317         $check_tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4318         # remove all xml-tags and whitespaces
4319         #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
4320         $check_tmpl_doc =~ s/<.*?>//g;
4321         $check_tmpl_doc =~ s/\s//g;
4322         if ($check_tmpl_doc ne "") {
4323             my $tmpl_params = $SymbolParams{$symbol};
4324             if (defined ($tmpl_params)) {
4325                 my $type = $DeclarationTypes {$symbol};
4327                 my $item = "Parameter";
4328                 if (defined ($type)) {
4329                     if ($type eq 'STRUCT') {
4330                         $item = "Field";
4331                     } elsif ($type eq 'ENUM') {
4332                         $item = "Value";
4333                     } elsif ($type eq 'UNION') {
4334                         $item = "Field";
4335                     }
4336                 } else {
4337                     $type="SIGNAL";
4338                 }
4340                 #print "Check param docs for $symbol, tmpl_params: ",$#$tmpl_params," entries, type=$type\n";
4342                 if ($#$tmpl_params > 0) {
4343                     my $j;
4344                     for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4345                         # Output a warning if the parameter is empty and
4346                         # remember for stats.
4347                         my $tmpl_param_name = $$tmpl_params[$j];
4348                         my $tmpl_param_desc = $$tmpl_params[$j + 1];
4349                         if ($tmpl_param_desc !~ m/\S/) {
4350                             if (exists ($AllIncompleteSymbols{$symbol})) {
4351                                 $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
4352                             } else {
4353                                 $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
4354                             }
4355                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4356                                 "$item description for $symbol"."::"."$tmpl_param_name is missing in source code comment block.");
4357                         }
4358                     }
4359                 }
4360                 else {
4361                     if ($#$tmpl_params == 0) {
4362                         $AllIncompleteSymbols{$symbol}="<items>";
4363                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4364                             "$item descriptions for $symbol are missing in source code comment block.");
4365                     }
4366                     # $#$tmpl_params==-1 means we don't know about parameters
4367                     # this unfortunately does not tell if there should be some
4368                 }
4369             }
4370         }
4371    }
4372    #print "num doc entries: ".(scalar %SymbolDocs)."\n";
4375 #############################################################################
4376 # Function    : IsEmptyDoc
4377 # Description : Check if a doc-string is empty. Its also regarded as empty if
4378 #               it only consist of whitespace or e.g. FIXME.
4379 # Arguments   : the doc-string
4380 #############################################################################
4381 sub IsEmptyDoc {
4382     my ($doc) = @_;
4383     
4384     if ($doc =~ /^\s*$/) {
4385         return 1;
4386     }
4388     if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
4389         return 1;
4390     }
4392     return 0;
4396 # This converts blank lines to "</para><para>", but only outside CDATA and
4397 # <programlisting> tags.
4398 sub ConvertBlankLines {
4399     return &ModifyXMLElements ($_[0], $_[1],
4400                                "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
4401                                \&ConvertBlankLinesEndTag,
4402                                \&ConvertBlankLinesCallback);
4406 sub ConvertBlankLinesEndTag {
4407   if ($_[0] eq "<!\[CDATA\[") {
4408     return "]]>";
4409   } elsif ($_[0] eq "|[") {
4410     return "]\\|";
4411   } else {
4412     return "</programlisting>";
4413   }
4416 sub ConvertBlankLinesCallback {
4417   my ($text, $symbol, $tag) = @_;
4419   # If we're not in CDATA or a <programlisting> we convert blank lines so
4420   # they start a new <para>.
4421   if ($tag eq "") {
4422     $text =~ s%\n{2,}%\n</para>\n<para>\n%g;
4423   }
4425   return $text;
4429 #############################################################################
4430 # LIBRARY FUNCTIONS -   These functions are used in both gtkdoc-mkdb and
4431 #                       gtkdoc-mktmpl and should eventually be moved to a
4432 #                       separate library.
4433 #############################################################################
4435 #############################################################################
4436 # Function    : ReadDeclarationsFile
4437 # Description : This reads in a file containing the function/macro/enum etc.
4438 #               declarations.
4440 #               Note that in some cases there are several declarations with
4441 #               the same name, e.g. for conditional macros. In this case we
4442 #               set a flag in the %DeclarationConditional hash so the
4443 #               declaration is not shown in the docs.
4445 #               If a macro and a function have the same name, e.g. for
4446 #               gtk_object_ref, the function declaration takes precedence.
4448 #               Some opaque structs are just declared with 'typedef struct
4449 #               _name name;' in which case the declaration may be empty.
4450 #               The structure may have been found later in the header, so
4451 #               that overrides the empty declaration.
4453 # Arguments   : $file - the declarations file to read
4454 #               $override - if declarations in this file should override
4455 #                       any current declaration.
4456 #############################################################################
4458 sub ReadDeclarationsFile {
4459     my ($file, $override) = @_;
4461     if ($override == 0) {
4462         %Declarations = ();
4463         %DeclarationTypes = ();
4464         %DeclarationConditional = ();
4465         %DeclarationOutput = ();
4466     }
4468     open (INPUT, $file)
4469         || die "Can't open $file: $!";
4470     my $declaration_type = "";
4471     my $declaration_name;
4472     my $declaration;
4473     my $is_deprecated = 0;
4474     while (<INPUT>) {
4475         if (!$declaration_type) {
4476             if (m/^<([^>]+)>/) {
4477                 $declaration_type = $1;
4478                 $declaration_name = "";
4479                 #print "Found declaration: $declaration_type\n";
4480                 $declaration = "";
4481             }
4482         } else {
4483             if (m%^<NAME>(.*)</NAME>%) {
4484                 $declaration_name = $1;
4485             } elsif (m%^<DEPRECATED/>%) {
4486                 $is_deprecated = 1;
4487             } elsif (m%^</$declaration_type>%) {
4488                 #print "Found end of declaration: $declaration_name\n";
4489                 # Check that the declaration has a name
4490                 if ($declaration_name eq "") {
4491                     print "ERROR: $declaration_type has no name $file:$.\n";
4492                 }
4494                 # If the declaration is an empty typedef struct _XXX XXX
4495                 # set the flag to indicate the struct has a typedef.
4496                 if ($declaration_type eq 'STRUCT'
4497                     && $declaration =~ m/^\s*$/) {
4498                     #print "Struct has typedef: $declaration_name\n";
4499                     $StructHasTypedef{$declaration_name} = 1;
4500                 }
4502                 # Check if the symbol is already defined.
4503                 if (defined ($Declarations{$declaration_name})
4504                     && $override == 0) {
4505                     # Function declarations take precedence.
4506                     if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
4507                         # Ignore it.
4508                     } elsif ($declaration_type eq 'FUNCTION') {
4509                         if ($is_deprecated) {
4510                             $Deprecated{$declaration_name} = "";
4511                         }
4512                         $Declarations{$declaration_name} = $declaration;
4513                         $DeclarationTypes{$declaration_name} = $declaration_type;
4514                     } elsif ($DeclarationTypes{$declaration_name}
4515                               eq $declaration_type) {
4516                         # If the existing declaration is empty, or is just a
4517                         # forward declaration of a struct, override it.
4518                         if ($declaration_type eq 'STRUCT') {
4519                             if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4520                                 if ($is_deprecated) {
4521                                     $Deprecated{$declaration_name} = "";
4522                                 }
4523                                 $Declarations{$declaration_name} = $declaration;
4524                             } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4525                                 # Ignore an empty or forward declaration.
4526                             } else {
4527                                 &LogWarning ($file, $., "Structure $declaration_name has multiple definitions.");
4528                             }
4529                         } else {
4530                             # set flag in %DeclarationConditional hash for
4531                             # multiply defined macros/typedefs.
4532                             $DeclarationConditional{$declaration_name} = 1;
4533                         }
4534                     } else {
4535                         &LogWarning ($file, $., "$declaration_name has multiple definitions.");
4536                     }
4537                 } else {
4538                     if ($is_deprecated) {
4539                         $Deprecated{$declaration_name} = "";
4540                     }
4541                     $Declarations{$declaration_name} = $declaration;
4542                     $DeclarationTypes{$declaration_name} = $declaration_type;
4543                 }
4545                 $declaration_type = "";
4546                 $is_deprecated = 0;
4547             } else {
4548                 $declaration .= $_;
4549             }
4550         }
4551     }
4552     close (INPUT);
4556 #############################################################################
4557 # Function    : ReadSignalsFile
4558 # Description : This reads in an existing file which contains information on
4559 #               all GTK signals. It creates the arrays @SignalNames and
4560 #               @SignalPrototypes containing info on the signals. The first
4561 #               line of the SignalPrototype is the return type of the signal
4562 #               handler. The remaining lines are the parameters passed to it.
4563 #               The last parameter, "gpointer user_data" is always the same
4564 #               so is not included.
4565 # Arguments   : $file - the file containing the signal handler prototype
4566 #                       information.
4567 #############################################################################
4569 sub ReadSignalsFile {
4570     my ($file) = @_;
4572     my $in_signal = 0;
4573     my $signal_object;
4574     my $signal_name;
4575     my $signal_returns;
4576     my $signal_flags;
4577     my $signal_prototype;
4579     # Reset the signal info.
4580     @SignalObjects = ();
4581     @SignalNames = ();
4582     @SignalReturns = ();
4583     @SignalFlags = ();
4584     @SignalPrototypes = ();
4586     if (! -f $file) {
4587         return;
4588     }
4589     if (!open (INPUT, $file)) {
4590         warn "Can't open $file - skipping signals\n";
4591         return;
4592     }
4593     while (<INPUT>) {
4594         if (!$in_signal) {
4595             if (m/^<SIGNAL>/) {
4596                 $in_signal = 1;
4597                 $signal_object = "";
4598                 $signal_name = "";
4599                 $signal_returns = "";
4600                 $signal_prototype = "";
4601             }
4602         } else {
4603             if (m/^<NAME>(.*)<\/NAME>/) {
4604                 $signal_name = $1;
4605                 if ($signal_name =~ m/^(.*)::(.*)$/) {
4606                     $signal_object = $1;
4607                     ($signal_name = $2) =~ s/_/-/g;
4608                     #print "Found signal: $signal_name\n";
4609                 } else {
4610                     &LogWarning ($file, $., "Invalid signal name: $signal_name.");
4611                 }
4612             } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
4613                 $signal_returns = $1;
4614             } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4615                 $signal_flags = $1;
4616             } elsif (m%^</SIGNAL>%) {
4617                 #print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
4618                 push (@SignalObjects, $signal_object);
4619                 push (@SignalNames, $signal_name);
4620                 push (@SignalReturns, $signal_returns);
4621                 push (@SignalFlags, $signal_flags);
4622                 push (@SignalPrototypes, $signal_prototype);
4623                 $in_signal = 0;
4624             } else {
4625                 $signal_prototype .= $_;
4626             }
4627         }
4628     }
4629     close (INPUT);
4633 #############################################################################
4634 # Function    : ReadTemplateFile
4635 # Description : This reads in the manually-edited documentation file
4636 #               corresponding to the file currently being created, so we can
4637 #               insert the documentation at the appropriate places.
4638 #               It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
4639 #               is a hash of arrays.
4640 #               NOTE: This function is duplicated in gtkdoc-mktmpl (but
4641 #               slightly different).
4642 # Arguments   : $docsfile - the template file to read in.
4643 #               $skip_unused_params - 1 if the unused parameters should be
4644 #                       skipped.
4645 #############################################################################
4647 sub ReadTemplateFile {
4648     my ($docsfile, $skip_unused_params) = @_;
4650     my $template = "$docsfile.sgml";
4651     if (! -f $template) {
4652         #print "File doesn't exist: $template\n";
4653         return 0;
4654     }
4655     #print "Reading $template\n";
4657     # start with empty hashes, we merge the source comment for each file
4658     # afterwards
4659     %SymbolDocs = ();
4660     %SymbolTypes = ();
4661     %SymbolParams = ();
4663     my $current_type = "";      # Type of symbol being read.
4664     my $current_symbol = "";    # Name of symbol being read.
4665     my $symbol_doc = "";                # Description of symbol being read.
4666     my @params;                 # Parameter names and descriptions of current
4667                                 #   function/macro/function typedef.
4668     my $current_param = -1;     # Index of parameter currently being read.
4669                                 #   Note that the param array contains pairs
4670                                 #   of param name & description.
4671     my $in_unused_params = 0;   # True if we are reading in the unused params.
4672     my $in_deprecated = 0;
4673     my $in_since = 0;
4674     my $in_stability = 0;
4676     open (DOCS, "$template")
4677         || die "Can't open $template: $!";
4678     while (<DOCS>) {
4679         if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
4680             my $type = $1;
4681             my $symbol = $2;
4682             if ($symbol eq "Title"
4683                 || $symbol eq "Short_Description"
4684                 || $symbol eq "Long_Description"
4685                 || $symbol eq "See_Also"
4686                 || $symbol eq "Stability_Level"
4687                 || $symbol eq "Include") {
4689                 $symbol = $docsfile . ":" . $symbol;
4690             }
4692             #print "Found symbol: $symbol\n";
4693             # Remember file and line for the symbol
4694             $SymbolSourceFile{$symbol} = $template;
4695             $SymbolSourceLine{$symbol} = $.;
4697             # Store previous symbol, but remove any trailing blank lines.
4698             if ($current_symbol ne "") {
4699                 $symbol_doc =~ s/\s+$//;
4700                 $SymbolTypes{$current_symbol} = $current_type;
4701                 $SymbolDocs{$current_symbol} = $symbol_doc;
4703                 # Check that the stability level is valid.
4704                 if ($StabilityLevel{$current_symbol}) {
4705                     $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4706                 }
4708                 if ($current_param >= 0) {
4709                     $SymbolParams{$current_symbol} = [ @params ];
4710                 } else {
4711                     # Delete any existing params in case we are overriding a
4712                     # previously read template.
4713                     delete $SymbolParams{$current_symbol};
4714                 }
4715             }
4716             $current_type = $type;
4717             $current_symbol = $symbol;
4718             $current_param = -1;
4719             $in_unused_params = 0;
4720             $in_deprecated = 0;
4721             $in_since = 0;
4722             $in_stability = 0;
4723             $symbol_doc = "";
4724             @params = ();
4726         } elsif (m/^<!-- # Unused Parameters # -->/) {
4727             #print "DEBUG: Found unused parameters\n";
4728             $in_unused_params = 1;
4729             next;
4731         } elsif ($in_unused_params && $skip_unused_params) {
4732             # When outputting the DocBook we skip unused parameters.
4733             #print "DEBUG: Skipping unused param: $_";
4734             next;
4736         } else {
4737             # Check if param found. Need to handle "..." and "format...".
4738             if (s/^\@([\w\.]+):\040?//) {
4739                 my $param_name = $1;
4740                 my $param_desc = $_;
4741                 # Allow variations of 'Returns'
4742                 if ($param_name =~ m/^[Rr]eturns?$/) {
4743                     $param_name = "Returns";
4744                 }
4746                 # strip trailing whitespaces and blank lines
4747                 s/\s+\n$/\n/m;
4748                 s/\n+$/\n/sm;
4749                 #print "Found param for symbol $current_symbol : '$param_name'= '$_'";
4751                 if ($param_name eq "Deprecated") {
4752                     $in_deprecated = 1;
4753                     $Deprecated{$current_symbol} = $_;
4754                 } elsif ($param_name eq "Since") {
4755                     $in_since = 1;
4756                     chomp;
4757                     $Since{$current_symbol} = $_;
4758                 } elsif ($param_name eq "Stability") {
4759                     $in_stability = 1;
4760                     $StabilityLevel{$current_symbol} = $_;
4761                 } else {
4762                     push (@params, $param_name);
4763                     push (@params, $param_desc);
4764                     $current_param += $PARAM_FIELD_COUNT;
4765                 }
4766             } else {
4767                 # strip trailing whitespaces and blank lines
4768                 s/\s+\n$/\n/m;
4769                 s/\n+$/\n/sm;
4770                 
4771                 if (!m/^\s+$/) {
4772                     if ($in_deprecated) {
4773                         $Deprecated{$current_symbol} .= $_;
4774                     } elsif ($in_since) {
4775                         &LogWarning ($template, $., "multi-line since docs found");
4776                         #$Since{$current_symbol} .= $_;
4777                     } elsif ($in_stability) {
4778                         $StabilityLevel{$current_symbol} .= $_;
4779                     } elsif ($current_param >= 0) {
4780                         $params[$current_param] .= $_;
4781                     } else {
4782                         $symbol_doc .= $_;
4783                     }
4784                 }
4785             }
4786         }
4787     }
4789     # Remember to finish the current symbol doccs.
4790     if ($current_symbol ne "") {
4792         $symbol_doc =~ s/\s+$//;
4793         $SymbolTypes{$current_symbol} = $current_type;
4794         $SymbolDocs{$current_symbol} = $symbol_doc;
4796         # Check that the stability level is valid.
4797         if ($StabilityLevel{$current_symbol}) {
4798             $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4799         }
4801         if ($current_param >= 0) {
4802             $SymbolParams{$current_symbol} = [ @params ];
4803         } else {
4804             # Delete any existing params in case we are overriding a
4805             # previously read template.
4806             delete $SymbolParams{$current_symbol};
4807         }
4808     }
4810     close (DOCS);
4811     return 1;
4815 #############################################################################
4816 # Function    : ReadObjectHierarchy
4817 # Description : This reads in the $MODULE-hierarchy.txt file containing all
4818 #               the GtkObject subclasses described in this module (and their
4819 #               ancestors).
4820 #               It places them in the @Objects array, and places their level
4821 #               in the object hierarchy in the @ObjectLevels array, at the
4822 #               same index. GtkObject, the root object, has a level of 1.
4824 #               FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
4825 #               as it goes along, this should be split out into a separate
4826 #               function.
4828 # Arguments   : none
4829 #############################################################################
4831 sub ReadObjectHierarchy {
4832     @Objects = ();
4833     @ObjectLevels = ();
4835     if (! -f $OBJECT_TREE_FILE) {
4836         return;
4837     }
4838     if (!open (INPUT, $OBJECT_TREE_FILE)) {
4839         warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
4840         return;
4841     }
4843     # FIXME: use $OUTPUT_FORMAT
4844     # my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.$OUTPUT_FORMAT";
4845     my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
4846     my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
4848     open (OUTPUT, ">$new_tree_index")
4849         || die "Can't create $new_tree_index: $!";
4851     if (lc($OUTPUT_FORMAT) eq "xml") {
4852         my $tree_header = $doctype_header;
4854         $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
4855         print (OUTPUT "$tree_header");
4856     }
4857     print (OUTPUT "<screen>\n");
4859     # Only emit objects if they are supposed to be documented, or if
4860     # they have documented children. To implement this, we maintain a
4861     # stack of pending objects which will be emitted if a documented
4862     # child turns up.
4863     my @pending_objects = ();
4864     my @pending_levels = ();
4865     while (<INPUT>) {
4866         if (m/\S+/) {
4867             my $object = $&;
4868             my $level = (length($`)) / 2 + 1;
4869             my $xref = "";
4871             while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
4872                 my $pobject = pop(@pending_objects);
4873                 my $plevel = pop(@pending_levels);
4874             }
4876             push (@pending_objects, $object);
4877             push (@pending_levels, $level);
4879             if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
4880                 while ($#pending_levels >= 0) {
4881                     $object = shift @pending_objects;
4882                     $level = shift @pending_levels;
4883                     $xref = &MakeXRef ($object);
4885                     print (OUTPUT ' ' x ($level * 4), "$xref\n");
4886                     push (@Objects, $object);
4887                     push (@ObjectLevels, $level);
4888                 }
4889             }
4890             #else {
4891             #    LogWarning ($OBJECT_TREE_FILE, $., "unknown type $object");
4892             #}
4893         }
4894     }
4895     print (OUTPUT "</screen>\n");
4897     close (INPUT);
4898     close (OUTPUT);
4900     &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
4902     &OutputObjectList;
4905 #############################################################################
4906 # Function    : ReadInterfaces
4907 # Description : This reads in the $MODULE.interfaces file.
4909 # Arguments   : none
4910 #############################################################################
4912 sub ReadInterfaces {
4913     %Interfaces = ();
4915     if (! -f $INTERFACES_FILE) {
4916         return;
4917     }
4918     if (!open (INPUT, $INTERFACES_FILE)) {
4919         warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
4920         return;
4921     }
4923     while (<INPUT>) {
4924        chomp;
4925        my ($object, @ifaces) = split;
4926        if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
4927            my @knownIfaces = ();
4929            # filter out private interfaces, but leave foreign interfaces
4930            foreach my $iface (@ifaces) {
4931                if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
4932                    push (@knownIfaces, $iface);
4933                }
4934              }
4936            $Interfaces{$object} = join(' ', @knownIfaces);
4937        }
4938     }
4939     close (INPUT);
4942 #############################################################################
4943 # Function    : ReadPrerequisites
4944 # Description : This reads in the $MODULE.prerequisites file.
4946 # Arguments   : none
4947 #############################################################################
4949 sub ReadPrerequisites {
4950     %Prerequisites = ();
4952     if (! -f $PREREQUISITES_FILE) {
4953         return;
4954     }
4955     if (!open (INPUT, $PREREQUISITES_FILE)) {
4956         warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
4957         return;
4958     }
4960     while (<INPUT>) {
4961        chomp;
4962        my ($iface, @prereqs) = split;
4963        if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
4964            my @knownPrereqs = ();
4966            # filter out private prerequisites, but leave foreign prerequisites
4967            foreach my $prereq (@prereqs) {
4968                if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
4969                   push (@knownPrereqs, $prereq);
4970                }
4971            }
4973            $Prerequisites{$iface} = join(' ', @knownPrereqs);
4974        }
4975     }
4976     close (INPUT);
4979 #############################################################################
4980 # Function    : ReadArgsFile
4981 # Description : This reads in an existing file which contains information on
4982 #               all GTK args. It creates the arrays @ArgObjects, @ArgNames,
4983 #               @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
4984 #               on the args.
4985 # Arguments   : $file - the file containing the arg information.
4986 #############################################################################
4988 sub ReadArgsFile {
4989     my ($file) = @_;
4991     my $in_arg = 0;
4992     my $arg_object;
4993     my $arg_name;
4994     my $arg_type;
4995     my $arg_flags;
4996     my $arg_nick;
4997     my $arg_blurb;
4998     my $arg_default;
4999     my $arg_range;
5001     # Reset the args info.
5002     @ArgObjects = ();
5003     @ArgNames = ();
5004     @ArgTypes = ();
5005     @ArgFlags = ();
5006     @ArgNicks = ();
5007     @ArgBlurbs = ();
5008     @ArgDefaults = ();
5009     @ArgRanges = ();
5011     if (! -f $file) {
5012         return;
5013     }
5014     if (!open (INPUT, $file)) {
5015         warn "Can't open $file - skipping args\n";
5016         return;
5017     }
5018     while (<INPUT>) {
5019         if (!$in_arg) {
5020             if (m/^<ARG>/) {
5021                 $in_arg = 1;
5022                 $arg_object = "";
5023                 $arg_name = "";
5024                 $arg_type = "";
5025                 $arg_flags = "";
5026                 $arg_nick = "";
5027                 $arg_blurb = "";
5028                 $arg_default = "";
5029                 $arg_range = "";
5030             }
5031         } else {
5032             if (m/^<NAME>(.*)<\/NAME>/) {
5033                 $arg_name = $1;
5034                 if ($arg_name =~ m/^(.*)::(.*)$/) {
5035                     $arg_object = $1;
5036                     ($arg_name = $2) =~ s/_/-/g;
5037                     #print "Found arg: $arg_name\n";
5038                 } else {
5039                     &LogWarning ($file, $., "Invalid argument name: $arg_name");
5040                 }
5041             } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
5042                 $arg_type = $1;
5043             } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
5044                 $arg_range = $1;
5045             } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
5046                 $arg_flags = $1;
5047             } elsif (m/^<NICK>(.*)<\/NICK>/) {
5048                 $arg_nick = $1;
5049             } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
5050                 $arg_blurb = $1;
5051                 if ($arg_blurb eq "(null)") {
5052                   $arg_blurb = "";
5053                   &LogWarning ($file, $., "Property ${arg_object}:${arg_name} has no documentation.");
5054                 }
5055             } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
5056                 $arg_default = $1;
5057             } elsif (m%^</ARG>%) {
5058                 #print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
5059                 push (@ArgObjects, $arg_object);
5060                 push (@ArgNames, $arg_name);
5061                 push (@ArgTypes, $arg_type);
5062                 push (@ArgRanges, $arg_range);
5063                 push (@ArgFlags, $arg_flags);
5064                 push (@ArgNicks, $arg_nick);
5065                 push (@ArgBlurbs, $arg_blurb);
5066                 push (@ArgDefaults, $arg_default);
5067                 $in_arg = 0;
5068             }
5069         }
5070     }
5071     close (INPUT);
5075 #############################################################################
5076 # Function    : CheckIsObject
5077 # Description : Returns 1 if the given name is a GObject or a subclass.
5078 #               It uses the global @Objects array.
5079 #               Note that the @Objects array only contains classes in the
5080 #               current module and their ancestors - not all GObject classes.
5081 # Arguments   : $name - the name to check.
5082 #############################################################################
5084 sub CheckIsObject {
5085     my ($name) = @_;
5087     my $object;
5088     foreach $object (@Objects) {
5089         if ($object eq $name) {
5090             return 1;
5091         }
5092     }
5093     return 0;
5097 #############################################################################
5098 # Function    : MakeReturnField
5099 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
5100 # Arguments   : $str - the string to pad.
5101 #############################################################################
5103 sub MakeReturnField {
5104     my ($str) = @_;
5106     return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));
5109 #############################################################################
5110 # Function    : GetSymbolSourceFile
5111 # Description : Get the filename where the symbol docs where taken from.
5112 # Arguments   : $symbol - the symbol name
5113 #############################################################################
5115 sub GetSymbolSourceFile {
5116     my ($symbol) = @_;
5118     if (defined($SourceSymbolSourceFile{$symbol})) {
5119         return $SourceSymbolSourceFile{$symbol};
5120     } elsif (defined($SymbolSourceFile{$symbol})) {
5121         return $SymbolSourceFile{$symbol};
5122     } else {
5123         return "";
5124     }
5127 #############################################################################
5128 # Function    : GetSymbolSourceLine
5129 # Description : Get the file line where the symbol docs where taken from.
5130 # Arguments   : $symbol - the symbol name
5131 #############################################################################
5133 sub GetSymbolSourceLine {
5134     my ($symbol) = @_;
5136     if (defined($SourceSymbolSourceLine{$symbol})) {
5137         return $SourceSymbolSourceLine{$symbol};
5138     } elsif (defined($SymbolSourceLine{$symbol})) {
5139         return $SymbolSourceLine{$symbol};
5140     } else {
5141         return 0;
5142     }