mkdb: GtkObject -> GObject in comments
[gtk-doc.git] / gtkdoc-mkdb.in
blobde33d184dd754bf72662523f0bfd93fe692e8dc8
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 widget 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 widget 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_widget_struct = 0;
1392     my $default_to_public = 1;
1393     if (&CheckIsObject ($symbol)) {
1394     #print "Found widget struct: $symbol\n";
1395     $is_widget_struct = 1;
1396         $default_to_public = 0;
1397     }
1399     my $id;
1400     my $condition;
1401     if ($is_widget_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;
1525             $desc .= <<EOF;
1526 <variablelist role="struct">
1528         while (@fields) {
1529             my $field_name = shift @fields;
1530             my $text = shift @fields;
1531             my $field_descr = $field_descrs{$field_name};
1532             my $param_annotations = "";
1534             $desc .= "<varlistentry><term>$text</term>\n";
1535             if (defined $field_descr) {
1536                 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1537                 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1538                 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1539             } else {
1540                 $desc .= "<listitem><simpara /></listitem>\n";
1541             }
1542             $desc .= "</varlistentry>\n";
1543         }
1545         $desc .= "</variablelist>";
1546     }
1547     $desc .= OutputSymbolTraits ($symbol);
1548     $desc .= "</refsect2>\n";
1549     return ($synop, $desc);
1553 #############################################################################
1554 # Function    : OutputEnum
1555 # Description : Returns the synopsis and detailed description of a enum.
1556 # Arguments   : $symbol - the enum.
1557 #               $declaration - the declaration of the enum.
1558 #############################################################################
1560 sub OutputEnum {
1561     my ($symbol, $declaration) = @_;
1562     my $id = &CreateValidSGMLID ($symbol);
1563     my $condition = &MakeConditionDescription ($symbol);
1564     my $synop = &MakeReturnField("enum") . "<link linkend=\"$id\">$symbol</link>;\n";
1565     my $desc = "<refsect2 id=\"$id\" role=\"enum\"$condition>\n<title>enum $symbol</title>\n";
1567     $desc .= MakeIndexterms($symbol, $id);
1568     $desc .= "\n";
1569     $desc .= OutputSymbolExtraLinks($symbol);
1571     my $decl_out = &CreateValidSGML ($declaration);
1572     $desc .= "<programlisting>$decl_out</programlisting>\n";
1574     $desc .= &MakeDeprecationNote($symbol);
1576     if (defined ($SymbolDocs{$symbol})) {
1577         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1578     }
1580     # Create a table of fields and descriptions
1582     my @members = ParseEnumDeclaration($declaration);
1583     my $params = $SymbolParams{$symbol};
1585     # If no parameters are filled in, we don't generate the description
1586     # table, for backwards compatibility
1588     my $found = 0;
1589     if (defined $params) {
1590         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1591             if ($params->[$i] =~ /\S/) {
1592                 $found = 1;
1593                 last;
1594             }
1595         }
1596     }
1598     if ($found) {
1599         my %member_descrs = @$params;
1601             $desc .= <<EOF;
1602 <variablelist role="enum">
1604         for my $member_name (@members) {
1605             my $member_descr = $member_descrs{$member_name};
1606             my $param_annotations = "";
1608             $id = &CreateValidSGMLID ($member_name);
1609             $condition = &MakeConditionDescription ($member_name);
1610             $desc .= "<varlistentry id=\"$id\" role=\"constant\"$condition>\n<term><literal>$member_name</literal></term>\n";
1611             if (defined $member_descr) {
1612                 ($member_descr,$param_annotations) = &ExpandAnnotation($symbol, $member_descr);
1613                 $member_descr = &ExpandAbbreviations($symbol, $member_descr);
1614                 $desc .= "<listitem><simpara>$member_descr$param_annotations</simpara></listitem>\n";
1615             } else {
1616                 $desc .= "<listitem></listitem>\n";
1617             }
1618             $desc .= "</varlistentry>\n";
1619         }
1621         $desc .= "</variablelist>";
1622     }
1624     $desc .= OutputSymbolTraits ($symbol);
1625     $desc .= "</refsect2>\n";
1626     return ($synop, $desc);
1630 #############################################################################
1631 # Function    : OutputUnion
1632 # Description : Returns the synopsis and detailed description of a union.
1633 # Arguments   : $symbol - the union.
1634 #               $declaration - the declaration of the union.
1635 #############################################################################
1637 sub OutputUnion {
1638     my ($symbol, $declaration) = @_;
1639     my $id = &CreateValidSGMLID ($symbol);
1640     my $condition = &MakeConditionDescription ($symbol);
1642     # Determine if it is a simple struct or it also has a typedef.
1643     my $has_typedef = 0;
1644     if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1645       $has_typedef = 1;
1646     }
1648     my $synop;
1649     my $desc;
1650     if ($has_typedef) {
1651         # For unions with typedefs we just output the union name.
1652         $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1653         $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>$symbol</title>\n";
1654     } else {
1655         $synop = &MakeReturnField("union") . "<link linkend=\"$id\">$symbol</link>;\n";
1656         $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>union $symbol</title>\n";
1657     }
1659     $desc .= MakeIndexterms($symbol, $id);
1660     $desc .= "\n";
1661     $desc .= OutputSymbolExtraLinks($symbol);
1663     # FIXME: we do more for structs
1664     my $decl_out = &CreateValidSGML ($declaration);
1665     $desc .= "<programlisting>$decl_out</programlisting>\n";
1667     $desc .= &MakeDeprecationNote($symbol);
1669     if (defined ($SymbolDocs{$symbol})) {
1670         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1671     }
1673     # Create a table of fields and descriptions
1675     # FIXME: Inserting &#160's into the produced type declarations here would
1676     #        improve the output in most situations ... except for function
1677     #        members of structs!
1678     my @fields = ParseStructDeclaration($declaration, 0,
1679                                         0, \&MakeXRef,
1680                                         sub {
1681                                             "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1682                                         });
1683     my $params = $SymbolParams{$symbol};
1685     # If no parameters are filled in, we don't generate the description
1686     # table, for backwards compatibility
1688     my $found = 0;
1689     if (defined $params) {
1690         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1691             if ($params->[$i] =~ /\S/) {
1692                 $found = 1;
1693                 last;
1694             }
1695         }
1696     }
1698     if ($found) {
1699         my %field_descrs = @$params;
1701             $desc .= <<EOF;
1702 <variablelist role="struct">
1704         while (@fields) {
1705             my $field_name = shift @fields;
1706             my $text = shift @fields;
1707             my $field_descr = $field_descrs{$field_name};
1708             my $param_annotations = "";
1710             $desc .= "<varlistentry><term>$text</term>\n";
1711             if (defined $field_descr) {
1712                 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1713                 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1714                 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1715             } else {
1716                 $desc .= "<listitem><simpara /></listitem>\n";
1717             }
1718             $desc .= "</varlistentry>\n";
1719         }
1721         $desc .= "</variablelist>";
1722     }
1723     $desc .= OutputSymbolTraits ($symbol);
1724     $desc .= "</refsect2>\n";
1725     return ($synop, $desc);
1729 #############################################################################
1730 # Function    : OutputVariable
1731 # Description : Returns the synopsis and detailed description of a variable.
1732 # Arguments   : $symbol - the extern'ed variable.
1733 #               $declaration - the declaration of the variable.
1734 #############################################################################
1736 sub OutputVariable {
1737     my ($symbol, $declaration) = @_;
1738     my $id = &CreateValidSGMLID ($symbol);
1739     my $condition = &MakeConditionDescription ($symbol);
1741     my $synop;
1742     if ($declaration =~ m/^\s*extern\s+((const\s+|unsigned\s+)*\w+)(\s+\*+|\*+|\s)(\s*)([A-Za-z]\w*)\s*;/) {
1743         my $mod = defined ($1) ? $1 : "";
1744         my $ptr = defined ($3) ? $3 : "";
1745         my $space = defined ($4) ? $4 : "";
1746         $synop = &MakeReturnField("extern") . "$mod$ptr$space<link linkend=\"$id\">$symbol</link>;\n";
1748     } else {
1749         $synop = &MakeReturnField("extern") . "<link linkend=\"$id\">$symbol</link>;\n";
1750     }
1752     my $desc = "<refsect2 id=\"$id\" role=\"variable\"$condition>\n<title>$symbol</title>\n";
1754     $desc .= MakeIndexterms($symbol, $id);
1755     $desc .= "\n";
1756     $desc .= OutputSymbolExtraLinks($symbol);
1758     my $decl_out = &CreateValidSGML ($declaration);
1759     $desc .= "<programlisting>$decl_out</programlisting>\n";
1761     $desc .= &MakeDeprecationNote($symbol);
1763     if (defined ($SymbolDocs{$symbol})) {
1764         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1765     }
1766     $desc .= OutputSymbolTraits ($symbol);
1767     $desc .= "</refsect2>\n";
1768     return ($synop, $desc);
1772 #############################################################################
1773 # Function    : OutputFunction
1774 # Description : Returns the synopsis and detailed description of a function.
1775 # Arguments   : $symbol - the function.
1776 #               $declaration - the declaration of the function.
1777 #############################################################################
1779 sub OutputFunction {
1780     my ($symbol, $declaration, $symbol_type) = @_;
1781     my $id = &CreateValidSGMLID ($symbol);
1782     my $condition = &MakeConditionDescription ($symbol);
1784     # Take out the return type     $1                                                                           $3   $4
1785     $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//;
1786     my $type_modifier = defined($1) ? $1 : "";
1787     my $type = $3;
1788     my $pointer = $4;
1789     #print "$symbol pointer is $pointer\n";
1790     my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1791     my $start = "";
1792     #if ($symbol_type eq 'USER_FUNCTION') {
1793     #    $start = "typedef ";
1794     #}
1796     # We output const rather than G_CONST_RETURN.
1797     $type_modifier =~ s/G_CONST_RETURN/const/g;
1798     $pointer =~ s/G_CONST_RETURN/const/g;
1799     $pointer =~ s/^\s+/ /g;
1801     my $ret_type_len = length ($start) + length ($type_modifier)
1802         + length ($pointer) + length ($type);
1803     my $ret_type_output;
1804     my $symbol_len;
1805     if ($ret_type_len < $RETURN_TYPE_FIELD_WIDTH) {
1806         $ret_type_output = "$start$type_modifier$xref$pointer"
1807             . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
1808         $symbol_len = 0;
1809     } else {
1810 #       $ret_type_output = "$start$type_modifier$xref$pointer\n"
1811 #           . (' ' x $RETURN_TYPE_FIELD_WIDTH);
1813         $ret_type_output = "$start$type_modifier$xref$pointer ";
1814         $symbol_len = $ret_type_len + 1 - $RETURN_TYPE_FIELD_WIDTH;
1815     }
1817     $symbol_len += length ($symbol);
1818     my $char1 = my $char2 = my $char3 = "";
1819     if ($symbol_type eq 'USER_FUNCTION') {
1820         $symbol_len += 3;
1821         $char1 = "(";
1822         $char2 = "*";
1823         $char3 = ")";
1824     }
1826     my ($symbol_output, $symbol_desc_output);
1827     if ($symbol_len < $SYMBOL_FIELD_WIDTH) {
1828         $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3"
1829             . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1830         $symbol_desc_output = "$char1$char2$symbol$char3"
1831             . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1832     } else {
1833         $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3\n"
1834             . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1835         $symbol_desc_output = "$char1$char2$symbol$char3\n"
1836             . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1837     }
1839     my $synop = $ret_type_output . $symbol_output . '(';
1840     my $desc = "<refsect2 id=\"$id\" role=\"function\"$condition>\n<title>${symbol} ()</title>\n";
1842     $desc .= MakeIndexterms($symbol, $id);
1843     $desc .= "\n";
1844     $desc .= OutputSymbolExtraLinks($symbol);
1846     $desc  .= "<programlisting>${ret_type_output}$symbol_desc_output(";
1848     my $param_num = 0;
1849     while ($declaration ne "") {
1850         #print "$declaration";
1852         if ($declaration =~ s/^[\s,]+//) {
1853             # skip whitespace and commas
1854             next;
1856         } elsif ($declaration =~ s/^void\s*[,\n]//) {
1857             $synop .= "void";
1858             $desc  .= "void";
1860         } elsif ($declaration =~ s/^...\s*[,\n]//) {
1861             if ($param_num == 0) {
1862                 $synop .= "...";
1863                 $desc  .= "...";
1864             } else {
1865                 $synop .= ",\n"
1866                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1867                     . " ...";
1868                 $desc  .= ",\n"
1869                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1870                     . " ...";
1871             }
1873         # allow alphanumerics, '_', '[' & ']' in param names
1874         # Try to match a standard parameter (keep in sync with gtkdoc-mktmpl)
1875         #                                $1                                                                                                                                    $2                             $3                                                           $4       $5
1876         } 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]//) {
1877             my $pre     = defined($1) ? $1 : "";
1878             my $type    = $2;
1879             my $ptr     = defined($3) ? $3 : "";
1880             my $name    = defined($4) ? $4 : "";
1881             my $array   = defined($5) ? $5 : "";
1883             $pre  =~ s/\s+/ /g;
1884             $type =~ s/\s+/ /g;
1885             $ptr  =~ s/\s+/ /g;
1886             $ptr  =~ s/\s+$//;
1887             if ($ptr && $ptr !~ m/\*$/) { $ptr .= " "; }
1889             #print "$symbol: '$pre' '$type' '$ptr' '$name' '$array'\n";
1891             if (($name eq "") && $pre =~ m/^((un)?signed .*)\s?/ ) {
1892                 $name = $type;
1893                 $type = "$1";
1894                 $pre = "";
1895             }
1897             my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1898             my $label   = "$pre$xref $ptr$name$array";
1900             #print "$symbol: '$pre' '$type' '$ptr' '$name' '$array'\n";
1902             if ($param_num == 0) {
1903                 $synop .= "$label";
1904                 $desc  .= "$label";
1905             } else {
1906                 $synop .= ",\n"
1907                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1908                     . " $label";
1909                 $desc  .= ",\n"
1910                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1911                     . " $label";
1912             }
1914         # Try to match parameters which are functions (keep in sync with gtkdoc-mktmpl)
1915         #                              $1                                       $2          $3      $4                        $5                    $7             $8
1916         } 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]//) {
1917             my $mod1 = defined($1) ? $1 : "";
1918             if (defined($2)) { $mod1 .= $2; }
1919             my $type = $3;
1920             my $ptr1 = $4;
1921             my $mod2 = defined($5) ? $5 : "";
1922             my $func_ptr = $6;
1923             my $name = $7;
1924             my $func_params = defined($8) ? $8 : "";
1925             
1926             #if (!defined($type)) { print "## no type\n"; };
1927             #if (!defined($ptr1)) { print "## no ptr1\n"; };
1928             #if (!defined($func_ptr)) { print "## no func_ptr\n"; };
1929             #if (!defined($name)) { print "## no name\n"; };
1931             if ($ptr1 && $ptr1 !~ m/\*$/) { $ptr1 .= " "; }
1932             $func_ptr  =~ s/\s+//g;
1933             my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1934             my $label = "$mod1$xref$ptr1$mod2 ($func_ptr$name) ($func_params)";
1936             #print "Type: [$mod1][$xref][$ptr1][$mod2] ([$func_ptr][$name]) ($func_params)\n";
1937             if ($param_num == 0) {
1938                 $synop .= "$label";
1939                 $desc  .= "$label";
1940             } else {
1941                 $synop .= ",\n"
1942                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1943                     . " $label";
1944                 $desc  .= ",\n"
1945                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1946                     . " $label";
1947             }
1949         } else {
1950             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1951                 "Can't parse args for function $symbol: $declaration");
1952             last;
1953         }
1954         $param_num++;
1955     }
1956     $synop .= ");\n";
1957     $desc  .= ");</programlisting>\n";
1959     $desc .= &MakeDeprecationNote($symbol);
1961     my $parameters = &OutputParamDescriptions ("FUNCTION", $symbol);
1962     my $parameters_output = 0;
1964     if (defined ($SymbolDocs{$symbol})) {
1965         my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1967         # Try to insert the parameter table at the author's desired position.
1968         # Otherwise we need to tag it onto the end.
1969         if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1970           $parameters_output = 1;
1971         }
1972         $desc .= $symbol_docs;
1973     }
1975     if ($parameters_output == 0) {
1976         $desc .= $parameters;
1977     }
1979     $desc .= OutputSymbolTraits ($symbol);
1980     $desc .= "</refsect2>\n";
1981     return ($synop, $desc);
1985 #############################################################################
1986 # Function    : OutputParamDescriptions
1987 # Description : Returns the DocBook output describing the parameters of a
1988 #               function, macro or signal handler.
1989 # Arguments   : $symbol_type - 'FUNCTION', 'MACRO' or 'SIGNAL'. Signal
1990 #                 handlers have an implicit user_data parameter last.
1991 #               $symbol - the name of the function/macro being described.
1992 #############################################################################
1994 sub OutputParamDescriptions {
1995     my ($symbol_type, $symbol) = @_;
1996     my $output = "";
1997     if (defined ($SymbolParams{$symbol})) {
1998         my $returns = "";
1999         my $params = $SymbolParams{$symbol};
2000         my $params_desc = "";
2001         my $j;
2002         for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
2003             my $param_name = $$params[$j];
2004             my $param_desc = $$params[$j + 1];
2005             my $param_annotations = "";
2007             ($param_desc,$param_annotations) = & ExpandAnnotation($symbol, $param_desc);
2008             $param_desc = &ExpandAbbreviations($symbol, $param_desc);
2009             if ($param_name eq "Returns") {
2010                 $returns = "$param_desc$param_annotations";
2011             } else {
2012                 if ($param_name eq "Varargs") {
2013                     $param_name = "...";
2014                 }
2015                 $params_desc .= "<varlistentry><term><parameter>$param_name</parameter>&#160;:</term>\n<listitem><simpara>$param_desc$param_annotations</simpara></listitem></varlistentry>\n";
2016             }
2017         }
2019         # Signals have an implicit user_data parameter which we describe.
2020         if ($symbol_type eq "SIGNAL") {
2021             $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";
2022         }
2024         # Start a table if we need one.
2025         if ($params_desc || $returns) {
2026             $output .= "<variablelist role=\"params\">\n";
2027             if ($params_desc ne "") {
2028                 #$output .= "<varlistentry><term>Parameters:</term><listitem></listitem></varlistentry>\n";
2029                 $output .= $params_desc;
2030             }
2032             # Output the returns info last.
2033             if ($returns) {
2034                 $output .= "<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara>$returns</simpara></listitem></varlistentry>\n";
2035             }
2037             # Finish the table.
2038             $output .= "</variablelist>";
2039         }
2040     }
2041     return $output;
2045 #############################################################################
2046 # Function    : ParseStabilityLevel
2047 # Description : Parses a stability level and outputs a warning if it isn't
2048 #               valid.
2049 # Arguments   : $stability - the stability text.
2050 #               $file, $line - context for error message
2051 #               $message - description of where the level is from, to use in
2052 #               any error message.
2053 # Returns     : The parsed stability level string.
2054 #############################################################################
2056 sub ParseStabilityLevel {
2057     my ($stability, $file, $line, $message) = @_;
2059     $stability =~ s/^\s*//;
2060     $stability =~ s/\s*$//;
2061     if ($stability =~ m/^stable$/i) {
2062         $stability = "Stable";
2063     } elsif ($stability =~ m/^unstable$/i) {
2064         $stability = "Unstable";
2065     } elsif ($stability =~ m/^private$/i) {
2066         $stability = "Private";
2067     } else {
2068         &LogWarning ($file, $line, "$message is $stability.".
2069             "It should be one of these: Stable, Unstable, or Private.");
2070     }
2071     return $stability;
2075 #############################################################################
2076 # Function    : OutputSGMLFile
2077 # Description : Outputs the final DocBook file for one section.
2078 # Arguments   : $file - the name of the file.
2079 #               $title - the title from the $MODULE-sections.txt file, which
2080 #                 will be overridden by the title in the template file.
2081 #               $section_id - the SGML id to use for the toplevel tag.
2082 #               $includes - comma-separates list of include files added at top
2083 #                 of synopsis, with '<' '>' around them (if not already enclosed in "").
2084 #               $synopsis - reference to the DocBook for the Synopsis part.
2085 #               $details - reference to the DocBook for the Details part.
2086 #               $signal_synop - reference to the DocBook for the Signal Synopsis part
2087 #               $signal_desc - reference to the DocBook for the Signal Description part
2088 #               $args_synop - reference to the DocBook for the Arg Synopsis part
2089 #               $args_desc - reference to the DocBook for the Arg Description part
2090 #               $hierarchy - reference to the DocBook for the Object Hierarchy part
2091 #               $interfaces - reference to the DocBook for the Interfaces part
2092 #               $implementations - reference to the DocBook for the Known Implementations part
2093 #               $prerequisites - reference to the DocBook for the Prerequisites part
2094 #               $derived - reference to the DocBook for the Derived Interfaces part
2095 #               $file_objects - reference to an array of objects in this file
2096 #############################################################################
2098 sub OutputSGMLFile {
2099     my ($file, $title, $section_id, $includes, $synopsis, $details, $signals_synop, $signals_desc, $args_synop, $args_desc, $hierarchy, $interfaces, $implementations, $prerequisites, $derived, $file_objects) = @_;
2101     #print "Output sgml for file $file with title '$title'\n";
2102     
2103     # The edited title overrides the one from the sections file.
2104     my $new_title = $SymbolDocs{"$TMPL_DIR/$file:Title"};
2105     if (defined ($new_title) && $new_title !~ m/^\s*$/) {
2106         $title = $new_title;
2107         #print "Found title: $title\n";
2108     }
2109     my $short_desc = $SymbolDocs{"$TMPL_DIR/$file:Short_Description"};
2110     if (!defined ($short_desc) || $short_desc =~ m/^\s*$/) {
2111         $short_desc = "";
2112     } else {
2113         $short_desc = &ExpandAbbreviations("$title:Short_description",
2114                                            $short_desc);
2115         #print "Found short_desc: $short_desc";
2116     }
2117     my $long_desc = $SymbolDocs{"$TMPL_DIR/$file:Long_Description"};
2118     if (!defined ($long_desc) || $long_desc =~ m/^\s*$/) {
2119         $long_desc = "";
2120     } else {
2121         $long_desc = &ExpandAbbreviations("$title:Long_description",
2122                                           $long_desc);
2123         #print "Found long_desc: $long_desc";
2124     }
2125     my $see_also = $SymbolDocs{"$TMPL_DIR/$file:See_Also"};
2126     if (!defined ($see_also) || $see_also =~ m%^\s*(<para>)?\s*(</para>)?\s*$%) {
2127         $see_also = "";
2128     } else {
2129         $see_also = &ExpandAbbreviations("$title:See_Also", $see_also);
2130         #print "Found see_also: $see_also";
2131     }
2132     if ($see_also) {
2133         $see_also = "<refsect1 id=\"$section_id.see-also\">\n<title>See Also</title>\n$see_also\n</refsect1>\n";
2134     }
2135     my $stability = $SymbolDocs{"$TMPL_DIR/$file:Stability_Level"};
2136     if (!defined ($stability) || $stability =~ m/^\s*$/) {
2137         $stability = "";
2138     } else {
2139         $stability = &ParseStabilityLevel($stability, $file, $., "Section stability level");
2140         #print "Found stability: $stability";
2141     }
2142     if ($stability) {
2143         $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$stability, unless otherwise indicated\n</refsect1>\n";
2144     } elsif ($DEFAULT_STABILITY) {
2145         $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$DEFAULT_STABILITY, unless otherwise indicated\n</refsect1>\n";
2146     }
2148     my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
2149         gmtime (time);
2150     my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
2151     $year += 1900;
2153     my $include_output = "";
2154     my $include;
2155     foreach $include (split (/,/, $includes)) {
2156         if ($include =~ m/^\".+\"$/) {
2157             $include_output .= "#include ${include}\n";
2158         }
2159         else {
2160             $include =~ s/^\s+|\s+$//gs;
2161             $include_output .= "#include &lt;${include}&gt;\n";
2162         }
2163     }
2164     if ($include_output ne '') {
2165         $include_output = "\n$include_output\n";
2166     }
2167     
2168     my $extralinks = OutputSectionExtraLinks($title,"Section:$file");
2170     my $old_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT";
2171     my $new_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT.new";
2173     open (OUTPUT, ">$new_sgml_file")
2174         || die "Can't create $new_sgml_file: $!";
2176     my $object_anchors = "";
2177     foreach my $object (@$file_objects) {
2178         next if ($object eq $section_id);
2179         my $id = CreateValidSGMLID($object);
2180         #print "Debug: Adding anchor for $object\n";
2181         $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
2182     }
2184     # We used to output this, but is messes up our UpdateFileIfChanged code
2185     # since it changes every day (and it is only used in the man pages):
2186     # "<refentry id="$section_id" revision="$mday $month $year">"
2188     if (lc($OUTPUT_FORMAT) eq "xml") {
2189         print OUTPUT $doctype_header;
2190     }
2192     print OUTPUT <<EOF;
2193 <refentry id="$section_id">
2194 <refmeta>
2195 <refentrytitle role="top_of_page" id="$section_id.top_of_page">$title</refentrytitle>
2196 <manvolnum>3</manvolnum>
2197 <refmiscinfo>\U$MODULE\E Library</refmiscinfo>
2198 </refmeta>
2199 <refnamediv>
2200 <refname>$title</refname>
2201 <refpurpose>$short_desc</refpurpose>
2202 </refnamediv>
2203 $stability
2204 <refsynopsisdiv id="$section_id.synopsis" role="synopsis">
2205 <title role="synopsis.title">Synopsis</title>
2206 $object_anchors
2207 <synopsis>$include_output$${synopsis}</synopsis>
2208 </refsynopsisdiv>
2209 $$hierarchy$$prerequisites$$derived$$interfaces$$implementations$$args_synop$$signals_synop
2210 <refsect1 id="$section_id.description" role="desc">
2211 <title role="desc.title">Description</title>
2212 $extralinks$long_desc
2213 </refsect1>
2214 <refsect1 id="$section_id.details" role="details">
2215 <title role="details.title">Details</title>
2216 $$details
2217 </refsect1>
2218 $$args_desc$$signals_desc$see_also
2219 </refentry>
2221     close (OUTPUT);
2223     return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2227 #############################################################################
2228 # Function    : OutputExtraFile
2229 # Description : Copies an "extra" DocBook file into the output directory,
2230 #               expanding abbreviations
2231 # Arguments   : $file - the source file.
2232 #############################################################################
2233 sub OutputExtraFile {
2234     my ($file) = @_;
2236     my $basename;
2238     ($basename = $file) =~ s!^.*/!!;
2240     my $old_sgml_file = "$SGML_OUTPUT_DIR/$basename";
2241     my $new_sgml_file = "$SGML_OUTPUT_DIR/$basename.new";
2243     my $contents;
2245     open(EXTRA_FILE, "<$file") || die "Can't open $file";
2247     {
2248         local $/;
2249         $contents = <EXTRA_FILE>;
2250     }
2252     open (OUTPUT, ">$new_sgml_file")
2253         || die "Can't create $new_sgml_file: $!";
2255     print OUTPUT &ExpandAbbreviations ("$basename file", $contents);
2256     close (OUTPUT);
2258     return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2260 #############################################################################
2261 # Function    : OutputBook
2262 # Description : Outputs the SGML entities that need to be included into the
2263 #               main SGML file for the module.
2264 # Arguments   : $book_top - the declarations of the entities, which are added
2265 #                 at the top of the main SGML file.
2266 #               $book_bottom - the references to the entities, which are
2267 #                 added in the main SGML file at the desired position.
2268 #############################################################################
2270 sub OutputBook {
2271     my ($book_top, $book_bottom) = @_;
2273     my $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top";
2274     my $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top.new";
2276     open (OUTPUT, ">$new_file")
2277         || die "Can't create $new_file: $!";
2278     print OUTPUT $book_top;
2279     close (OUTPUT);
2281     &UpdateFileIfChanged ($old_file, $new_file, 0);
2284     $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom";
2285     $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom.new";
2287     open (OUTPUT, ">$new_file")
2288         || die "Can't create $new_file: $!";
2289     print OUTPUT $book_bottom;
2290     close (OUTPUT);
2292     &UpdateFileIfChanged ($old_file, $new_file, 0);
2295     # If the main SGML file hasn't been created yet, we create it here.
2296     # The user can tweak it later.
2297     if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
2298       open (OUTPUT, ">$MAIN_SGML_FILE")
2299         || die "Can't create $MAIN_SGML_FILE: $!";
2301       if (lc($OUTPUT_FORMAT) eq "xml") {
2302           print OUTPUT <<EOF;
2303 <?xml version="1.0"?>
2304 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
2305                "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
2307   <!ENTITY % local.common.attrib "xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'">
2309 <book id="index">
2311       } else {
2312         print OUTPUT <<EOF;
2313 <!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
2314 $book_top
2316 <book id="index">
2318       }
2320 print OUTPUT <<EOF;
2321   <bookinfo>
2322     <title>$MODULE Reference Manual</title>
2323     <releaseinfo>
2324       for $MODULE [VERSION].
2325       The latest version of this documentation can be found on-line at
2326       <ulink role="online-location" url="http://[SERVER]/$MODULE/index.html">http://[SERVER]/$MODULE/</ulink>.
2327     </releaseinfo>
2328   </bookinfo>
2330   <chapter>
2331     <title>[Insert title here]</title>
2332     $book_bottom
2333   </chapter>
2335   if (-e $OBJECT_TREE_FILE) {
2336     print OUTPUT <<EOF;
2337   <chapter id="object-tree">
2338     <title>Object Hierarchy</title>
2339      <xi:include href="xml/tree_index.sgml"/>
2340   </chapter>
2342   }
2344 print OUTPUT <<EOF;
2345   <index id="api-index-full">
2346     <title>API Index</title>
2347     <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
2348   </index>
2350   <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
2351 </book>
2354       close (OUTPUT);
2355     }
2359 #############################################################################
2360 # Function    : CreateValidSGML
2361 # Description : This turns any chars which are used in SGML into entities,
2362 #               e.g. '<' into '&lt;'
2363 # Arguments   : $text - the text to turn into proper SGML.
2364 #############################################################################
2366 sub CreateValidSGML {
2367     my ($text) = @_;
2368     $text =~ s/&/&amp;/g;       # Do this first, or the others get messed up.
2369     $text =~ s/</&lt;/g;
2370     $text =~ s/>/&gt;/g;
2371     # browers render single tabs inconsistently
2372     $text =~ s/([^\s])\t([^\s])/$1&#160;$2/g;
2373     return $text;
2376 #############################################################################
2377 # Function    : ConvertSGMLChars
2378 # Description : This is used for text in source code comment blocks, to turn
2379 #               chars which are used in SGML into entities, e.g. '<' into
2380 #               '&lt;'. Depending on $SGML_MODE, this is done
2381 #               unconditionally or only if the character doesn't seem to be
2382 #               part of an SGML construct (tag or entity reference).
2383 # Arguments   : $text - the text to turn into proper SGML.
2384 #############################################################################
2386 sub ConvertSGMLChars {
2387     my ($symbol, $text) = @_;
2389     if ($SGML_MODE) {
2390         # For the SGML mode only convert to entities outside CDATA sections.
2391         return &ModifyXMLElements ($text, $symbol,
2392                                    "<!\\[CDATA\\[|<programlisting[^>]*>",
2393                                    \&ConvertSGMLCharsEndTag,
2394                                    \&ConvertSGMLCharsCallback);
2395     } else {
2396         # For the simple non-sgml mode, convert to entities everywhere.
2397         $text =~ s/&/&amp;/g;   # Do this first, or the others get messed up.
2398         $text =~ s/</&lt;/g;
2399         $text =~ s/>/&gt;/g;
2400         return $text;
2401     }
2405 sub ConvertSGMLCharsEndTag {
2406   if ($_[0] eq "<!\[CDATA\[") {
2407     return "]]>";
2408   } else {
2409     return "</programlisting>";
2410   }
2413 sub ConvertSGMLCharsCallback {
2414   my ($text, $symbol, $tag) = @_;
2416   if ($tag =~ m/^<programlisting/) {
2417     # We can handle <programlisting> specially here.
2418     return &ModifyXMLElements ($text, $symbol,
2419                                "<!\\[CDATA\\[",
2420                                \&ConvertSGMLCharsEndTag,
2421                                \&ConvertSGMLCharsCallback2);
2422   } elsif ($tag eq "") {
2423     # If we're not in CDATA convert to entities.
2424     $text =~ s/&(?![a-zA-Z#]+;)/&amp;/g;        # Do this first, or the others get messed up.
2425     $text =~ s/<(?![a-zA-Z\/!])/&lt;/g;
2426     $text =~ s/(?<![a-zA-Z0-9"'\/-])>/&gt;/g;
2428     # Handle "#include <xxxxx>"
2429     $text =~ s/#include(\s+)<([^>]+)>/#include$1&lt;$2&gt;/g;
2430   }
2432   return $text;
2435 sub ConvertSGMLCharsCallback2 {
2436   my ($text, $symbol, $tag) = @_;
2438   # If we're not in CDATA convert to entities.
2439   # We could handle <programlisting> differently, though I'm not sure it helps.
2440   if ($tag eq "") {
2441     # replace only if its not a tag
2442     $text =~ s/&(?![a-zA-Z#]+;)/&amp;/g;        # Do this first, or the others get messed up.
2443     $text =~ s/<(?![a-zA-Z\/!])/&lt;/g;
2444     $text =~ s/(?<![a-zA-Z0-9"'\/-])>/&gt;/g;
2446     # Handle "#include <xxxxx>"
2447     $text =~ s/#include(\s+)<([^>]+)>/#include$1&lt;$2&gt;/g;
2448   }
2450   return $text;
2453 #############################################################################
2454 # Function    : ExpandAnnotation
2455 # Description : This turns annotations into acrony tags.
2456 # Arguments   : $symbol - the symbol being documented, for error messages.
2457 #               $text - the text to expand.
2458 #############################################################################
2459 sub ExpandAnnotation {
2460     my ($symbol, $param_desc) = @_;
2461     my $param_annotations = "";
2462     
2463     if ($param_desc =~ m%\s*\((.*)\):%) {
2464         my @annotations;
2465         my $annotation;
2466         my $annotation_extra = "";
2467         $param_desc = $';
2468     
2469         @annotations = split(/\)\s*\(/,$1);
2470         foreach $annotation (@annotations) {
2471             # need to search for the longest key-match in %AnnotationDefinition
2472             my $match_length=0;
2473             my $match_annotation="";
2474             my $annotationdef;
2475             foreach $annotationdef (keys %AnnotationDefinition) {
2476                 if ($annotation =~ m/^$annotationdef/) {
2477                     if (length($annotationdef)>$match_length) {
2478                         $match_length=length($annotationdef);
2479                         $match_annotation=$annotationdef;
2480                     }
2481                 }
2482             }
2483             if ($match_annotation ne "") {
2484                 if ($annotation =~ m%$match_annotation\s+(.*)%) {
2485                     $annotation_extra = " $1";
2486                 }
2487                 $AnnotationsUsed{$match_annotation} = 1;
2488                 $param_annotations .= "<acronym>$match_annotation</acronym>$annotation_extra. ";
2489             }
2490             else {
2491                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2492                     "unknown annotation \"$annotation\" in documentation for $symbol.");
2493                 $param_annotations=$annotation;
2494             }
2495         }
2496         chomp($param_desc);
2497         $param_desc =~ m/^(.*)\.*\s*$/;
2498         $param_desc = "$1. ";
2499     }    
2500     return ($param_desc, $param_annotations);
2503 #############################################################################
2504 # Function    : ExpandAbbreviations
2505 # Description : This turns the abbreviations function(), macro(), @param,
2506 #               %constant, and #symbol into appropriate DocBook markup.
2507 #               CDATA sections and <programlisting> parts are skipped.
2508 # Arguments   : $symbol - the symbol being documented, for error messages.
2509 #               $text - the text to expand.
2510 #############################################################################
2512 sub ExpandAbbreviations {
2513   my ($symbol, $text) = @_;
2515   # Convert "|[" and "]|" into the start and end of program listing examples.
2516   $text =~ s%\|\[%<informalexample><programlisting>%g;
2517   $text =~ s%\]\|%</programlisting></informalexample>%g;
2518   # TODO: check for a xml comment after |[ and pick the language attribute from
2519   # that
2521   # TODO: optionally check all words from $text against internal symbols and
2522   # warn if those could be xreffed, but miss a %,# or ()
2524   # keep CDATA unmodified, preserve ulink tags (ideally we preseve all tags
2525   # as such)
2526   return &ModifyXMLElements ($text, $symbol,
2527                              "<!\\[CDATA\\[|<ulink[^>]*>|<programlisting[^>]*>|<!DOCTYPE",
2528                              \&ExpandAbbreviationsEndTag,
2529                              \&ExpandAbbreviationsCallback);
2533 # Returns the end tag corresponding to the given start tag.
2534 sub ExpandAbbreviationsEndTag {
2535   my ($start_tag) = @_;
2537   if ($start_tag eq "<!\[CDATA\[") {
2538     return "]]>";
2539   } elsif ($start_tag eq "<!DOCTYPE") {
2540     return "]>";
2541   } elsif ($start_tag =~ m/<(\w+)/) {
2542     return "</$1>";
2543   }
2546 # Called inside or outside each CDATA or <programlisting> section.
2547 sub ExpandAbbreviationsCallback {
2548   my ($text, $symbol, $tag) = @_;
2550   if ($tag =~ m/^<programlisting/) {
2551     # Handle any embedded CDATA sections.
2552     return &ModifyXMLElements ($text, $symbol,
2553                                "<!\\[CDATA\\[",
2554                                \&ExpandAbbreviationsEndTag,
2555                                \&ExpandAbbreviationsCallback2);
2556   } elsif ($tag eq "") {
2557     # We are outside any CDATA or <programlisting> sections, so we expand
2558     # any gtk-doc abbreviations.
2560     # Convert 'function()' or 'macro()'.
2561     # if there is abc_*_def() we don't want to make a link to _def()
2562     # FIXME: also handle abc(....) : but that would need to be done recursively :/
2563     $text =~ s/([^\*.\w])(\w+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2564     # handle #Object.func()
2565     $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2567     # Convert '@param', but not '\@param'.
2568     $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)/$1<parameter>$2<\/parameter>/g;
2569     $text =~ s/\\\@/\@/g;
2571     # Convert '%constant', but not '\%constant'.
2572     # Also allow negative numbers, e.g. %-1.
2573     $text =~ s/(\A|[^\\])\%(-?\w+)/$1.&MakeXRef($2, &tagify($2, "literal"));/eg;
2574     $text =~ s/\\\%/\%/g;
2576     # Convert '#symbol', but not '\#symbol'.
2577     $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)/$1.&MakeHashXRef($2, "type");/eg;
2578     $text =~ s/\\#/#/g;
2579     
2580     # Expand urls
2581     # FIXME: should we skip urls that are already tagged? (e.g. <literal>http://...</literal>)
2582     # this is apparently also called for markup and not just for plain text
2583     # disable for now.
2584     #$text =~ s%(http|https|ftp)://(.*?)((?:\s|,|\)|\]|\<|\.\s))%<ulink url="$1://$2">$2</ulink>$3%g;
2585   }
2587   return $text;
2590 # This is called inside a <programlisting>
2591 sub ExpandAbbreviationsCallback2 {
2592   my ($text, $symbol, $tag) = @_;
2594   if ($tag eq "") {
2595     # We are inside a <programlisting> but outside any CDATA sections,
2596     # so we expand any gtk-doc abbreviations.
2597     # FIXME: why is this different from &ExpandAbbreviationsCallback(),
2598     #        why not just call it
2599     $text =~ s/#(\w+)/&MakeHashXRef($1, "");/eg;
2600   }
2602   return $text;
2605 sub MakeHashXRef {
2606     my ($symbol, $tag) = @_;;
2607     my $text = $symbol;
2609     # Check for things like '#include', '#define', and skip them.
2610     if ($PreProcessorDirectives{$symbol}) {
2611       return "#$symbol";
2612     }
2614     # Get rid of any special '-struct' suffix.
2615     $text =~ s/-struct$//;
2617     # If the symbol is in the form "Object::signal", then change the symbol to
2618     # "Object-signal" and use "signal" as the text.
2619     if ($symbol =~ s/::/-/) {
2620       $text = "\"$'\"";
2621     }
2623     # If the symbol is in the form "Object:property", then change the symbol to
2624     # "Object--property" and use "property" as the text.
2625     if ($symbol =~ s/:/--/) {
2626       $text = "\"$'\"";
2627     }
2629     if ($tag ne "") {
2630       $text = tagify ($text, $tag);
2631     }
2632     
2633     return &MakeXRef($symbol, $text);
2637 #############################################################################
2638 # Function    : ModifyXMLElements
2639 # Description : Looks for given XML element tags within the text, and calls
2640 #               the callback on pieces of text inside & outside those elements.
2641 #               Used for special handling of text inside things like CDATA
2642 #               and <programlisting>.
2643 # Arguments   : $text - the text.
2644 #               $symbol - the symbol currently being documented (only used for
2645 #                      error messages).
2646 #               $start_tag_regexp - the regular expression to match start tags.
2647 #                      e.g. "<!\\[CDATA\\[|<programlisting[^>]*>" to match
2648 #                      CDATA sections or programlisting elements.
2649 #               $end_tag_func - function which is passed the matched start tag
2650 #                      and should return the appropriate end tag string.
2651 #               $callback - callback called with each part of the text. It is
2652 #                      called with a piece of text, the symbol being
2653 #                      documented, and the matched start tag or "" if the text
2654 #                      is outside the XML elements being matched.
2655 #############################################################################
2656 sub ModifyXMLElements {
2657     my ($text, $symbol, $start_tag_regexp, $end_tag_func, $callback) = @_;
2658     my ($before_tag, $start_tag, $end_tag_regexp, $end_tag);
2659     my $result = "";
2661     while ($text =~ m/$start_tag_regexp/s) {
2662       $before_tag = $`; # Prematch for last successful match string
2663       $start_tag = $&;  # Last successful match
2664       $text = $';       # Postmatch for last successful match string
2666       $result .= &$callback ($before_tag, $symbol, "");
2667       $result .= $start_tag;
2669       # get the mathing end-tag for current tag
2670       $end_tag_regexp = &$end_tag_func ($start_tag);
2672       if ($text =~ m/$end_tag_regexp/s) {
2673         $before_tag = $`;
2674         $end_tag = $&;
2675         $text = $';
2677         $result .= &$callback ($before_tag, $symbol, $start_tag);
2678         $result .= $end_tag;
2679       } else {
2680         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2681             "Can't find tag end: $end_tag_regexp in docs for: $symbol.");
2682         # Just assume it is all inside the tag.
2683         $result .= &$callback ($text, $symbol, $start_tag);
2684         $text = "";
2685       }
2686     }
2688     # Handle any remaining text outside the tags.
2689     $result .= &$callback ($text, $symbol, "");
2691     return $result;
2694 sub noop {
2695   return $_[0];
2698 # Adds a tag around some text.
2699 # e.g tagify("Text", "literal") => "<literal>Text</literal>".
2700 sub tagify {
2701    my ($text, $elem) = @_;
2702    return "<" . $elem . ">" . $text . "</" . $elem . ">";
2706 #############################################################################
2707 # Function    : MakeXRef
2708 # Description : This returns a cross-reference link to the given symbol.
2709 #               Though it doesn't try to do this for a few standard C types
2710 #               that it knows won't be in the documentation.
2711 # Arguments   : $symbol - the symbol to try to create a XRef to.
2712 #               $text - text text to put inside the XRef, defaults to $symbol
2713 #############################################################################
2715 sub MakeXRef {
2716     my ($symbol, $text) = ($_[0], $_[1]);
2718     $symbol =~ s/^\s+//;
2719     $symbol =~ s/\s+$//;
2721     if (!defined($text)) {
2722         $text = $symbol;
2724         # Get rid of special '-struct' suffix.
2725         $text =~ s/-struct$//;
2726     }
2728     if ($symbol =~ m/ /) {
2729         return "$text";
2730     }
2732     #print "Getting type link for $symbol -> $text\n";
2734     my $symbol_id = &CreateValidSGMLID ($symbol);
2735     return "<link linkend=\"$symbol_id\">$text</link>";
2739 #############################################################################
2740 # Function    : MakeIndexterms
2741 # Description : This returns a indexterm elements for the given symbol
2742 # Arguments   : $symbol - the symbol to create indexterms for
2743 #############################################################################
2745 sub MakeIndexterms {
2746   my ($symbol, $id) = @_;
2747   my $terms =  "";
2748   my $sortas = "";
2749   
2750   # make the index useful, by ommiting the namespace when sorting
2751   if ($NAME_SPACE ne "") {
2752     if ($symbol =~ m/^$NAME_SPACE\_?(.*)/i) {
2753        $sortas=" sortas=\"$1\"";
2754     }
2755   }
2757   if (exists $Deprecated{$symbol}) {
2758       $terms .= "<indexterm zone=\"$id\" role=\"deprecated\"><primary$sortas>$symbol</primary></indexterm>";
2759       $IndexEntriesDeprecated{$symbol}=$id;
2760       $IndexEntriesFull{$symbol}=$id;
2761   }
2762   if (exists $Since{$symbol}) {
2763      my $since = $Since{$symbol};
2764      $since =~ s/^\s+//;
2765      $since =~ s/\s+$//;
2766      if ($since ne "") {
2767          $terms .= "<indexterm zone=\"$id\" role=\"$since\"><primary$sortas>$symbol</primary></indexterm>";
2768      }
2769      $IndexEntriesSince{$symbol}=$id;
2770      $IndexEntriesFull{$symbol}=$id;
2771   }
2772   if ($terms eq "") {
2773      $terms .= "<indexterm zone=\"$id\"><primary$sortas>$symbol</primary></indexterm>";
2774      $IndexEntriesFull{$symbol}=$id;
2775   }
2777   return $terms;
2780 #############################################################################
2781 # Function    : MakeDeprecationNote
2782 # Description : This returns a deprecation warning for the given symbol.
2783 # Arguments   : $symbol - the symbol to try to create a warning for.
2784 #############################################################################
2786 sub MakeDeprecationNote {
2787     my ($symbol) = $_[0];
2788     my $desc = "";
2789     my $note = "";
2790     if (exists $Deprecated{$symbol}) {
2791         $desc .= "<warning>";
2793         if ($Deprecated{$symbol} =~ /^\s*([0-9\.]+)\s*:/) {
2794                 $desc .= "<para><literal>$symbol</literal> has been deprecated since version $1 and should not be used in newly-written code.";
2795         } else {
2796                 $desc .= "<para><literal>$symbol</literal> is deprecated and should not be used in newly-written code.";
2797         }
2798         if ($Deprecated{$symbol} ne "") {
2799             $note = &ExpandAbbreviations($symbol, $Deprecated{$symbol});
2800             $note =~ s/^\s*([0-9\.]+)\s*:\s*//;
2801             $note =~ s/^\s+//;
2802             $note =~ s/\s+$//;
2803             $note =~ s%\n{2,}%\n</para>\n<para>\n%g;
2804             $desc .= " " . $note;
2805         }
2806         $desc .= "</para></warning>\n";
2807     }
2808     return $desc;
2811 #############################################################################
2812 # Function    : MakeConditionDescription
2813 # Description : This returns a sumary of conditions for the given symbol.
2814 # Arguments   : $symbol - the symbol to try to create the sumary.
2815 #############################################################################
2817 sub MakeConditionDescription {
2818     my ($symbol) = $_[0];
2819     my $desc = "";
2821     if (exists $Deprecated{$symbol}) {
2822         if ($desc ne "") {
2823             $desc .= "|";
2824         }
2826         if ($Deprecated{$symbol} =~ /^\s*(.*?)\s*$/) {
2827                 $desc .= "deprecated:$1";
2828         } else {
2829                 $desc .= "deprecated";
2830         }
2831     }
2833     if (exists $Since{$symbol}) {
2834         if ($desc ne "") {
2835             $desc .= "|";
2836         }
2838         if ($Since{$symbol} =~ /^\s*(.*?)\s*$/) {
2839                 $desc .= "since:$1";
2840         } else {
2841                 $desc .= "since";
2842         }
2843     }
2845     if (exists $StabilityLevel{$symbol}) {
2846         if ($desc ne "") {
2847             $desc .= "|";
2848         }
2849         $desc .= "stability:".$StabilityLevel{$symbol};
2850     }
2852     if ($desc ne "") {
2853         $desc=" condition=\"".$desc."\"";
2854         #print "condition for '$symbol' = '$desc'\n";
2855     }
2856     return $desc;
2859 #############################################################################
2860 # Function    : GetHierarchy
2861 # Description : Returns the DocBook output describing the ancestors and
2862 #               immediate children of a GObject subclass. It uses the
2863 #               global @Objects and @ObjectLevels arrays to walk the tree.
2864 # Arguments   : $object - the GtkObject subclass.
2865 #############################################################################
2867 sub GetHierarchy {
2868     my ($object) = @_;
2870     # Find object in the objects array.
2871     my $found = 0;
2872     my @children = ();
2873     my $i;
2874     my $level;
2875     my $j;
2876     for ($i = 0; $i < @Objects; $i++) {
2877         if ($found) {
2878             if ($ObjectLevels[$i] <= $level) {
2879             last;
2880         }
2881             elsif ($ObjectLevels[$i] == $level + 1) {
2882                 push (@children, $Objects[$i]);
2883             }
2884         }
2885         elsif ($Objects[$i] eq $object) {
2886             $found = 1;
2887             $j = $i;
2888             $level = $ObjectLevels[$i];
2889         }
2890     }
2891     if (!$found) {
2892         return "";
2893     }
2895     # Walk up the hierarchy, pushing ancestors onto the ancestors array.
2896     my @ancestors = ();
2897     push (@ancestors, $object);
2898     #print "Level: $level\n";
2899     while ($level > 1) {
2900         $j--;
2901         if ($ObjectLevels[$j] < $level) {
2902             push (@ancestors, $Objects[$j]);
2903             $level = $ObjectLevels[$j];
2904             #print "Level: $level\n";
2905         }
2906     }
2908     # Output the ancestors list, indented and with links.
2909     my $hierarchy = "<synopsis>\n";
2910     $level = 0;
2911     for ($i = $#ancestors; $i >= 0; $i--) {
2912         my $link_text;
2913         # Don't add a link to the current widget, i.e. when i == 0.
2914         if ($i > 0) {
2915             my $ancestor_id = &CreateValidSGMLID ($ancestors[$i]);
2916             $link_text = "<link linkend=\"$ancestor_id\">$ancestors[$i]</link>";
2917         } else {
2918             $link_text = "$ancestors[$i]";
2919         }
2920         if ($level == 0) {
2921             $hierarchy .= "  $link_text\n";
2922         } else {
2923 #           $hierarchy .= ' ' x ($level * 6 - 3) . "|\n";
2924             $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
2925         }
2926         $level++;
2927     }
2928     for ($i = 0; $i <= $#children; $i++) {
2929       my $id = &CreateValidSGMLID ($children[$i]);
2930       my $link_text = "<link linkend=\"$id\">$children[$i]</link>";
2931       $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
2932     }
2933     $hierarchy .= "</synopsis>\n";
2935     return $hierarchy;
2939 #############################################################################
2940 # Function    : GetInterfaces
2941 # Description : Returns the DocBook output describing the interfaces
2942 #               implemented by a class. It uses the global %Interfaces hash.
2943 # Arguments   : $object - the GtkObject subclass.
2944 #############################################################################
2946 sub GetInterfaces {
2947     my ($object) = @_;
2948     my $text = "";
2949     my $i;
2951     # Find object in the objects array.
2952     if (exists($Interfaces{$object})) {
2953         my @ifaces = split(' ', $Interfaces{$object});
2954         $text = <<EOF;
2955 <para>
2956 $object implements
2958         for ($i = 0; $i <= $#ifaces; $i++) {
2959             my $id = &CreateValidSGMLID ($ifaces[$i]);
2960             $text .= " <link linkend=\"$id\">$ifaces[$i]</link>";
2961             if ($i < $#ifaces - 1) {
2962                 $text .= ', ';
2963             }
2964             elsif ($i < $#ifaces) {
2965                 $text .= ' and ';
2966             }
2967             else {
2968                 $text .= '.';
2969             }
2970         }
2971         $text .= <<EOF;
2972 </para>
2974     }
2976     return $text;
2979 #############################################################################
2980 # Function    : GetImplementations
2981 # Description : Returns the DocBook output describing the implementations
2982 #               of an interface. It uses the global %Interfaces hash.
2983 # Arguments   : $object - the GtkObject subclass.
2984 #############################################################################
2986 sub GetImplementations {
2987     my ($object) = @_;
2988     my @impls = ();
2989     my $text = "";
2990     my $i;
2991     foreach my $key (keys %Interfaces) {
2992         if ($Interfaces{$key} =~ /\b$object\b/) {
2993             push (@impls, $key);
2994         }
2995     }
2996     if ($#impls >= 0) {
2997         $text = <<EOF;
2998 <para>
2999 $object is implemented by
3001         for ($i = 0; $i <= $#impls; $i++) {
3002             my $id = &CreateValidSGMLID ($impls[$i]);
3003             $text .= " <link linkend=\"$id\">$impls[$i]</link>";
3004             if ($i < $#impls - 1) {
3005                 $text .= ', ';
3006             }
3007             elsif ($i < $#impls) {
3008                 $text .= ' and ';
3009             }
3010             else {
3011                 $text .= '.';
3012             }
3013         }
3014         $text .= <<EOF;
3015 </para>
3017     }
3018     return $text;
3022 #############################################################################
3023 # Function    : GetPrerequisites
3024 # Description : Returns the DocBook output describing the prerequisites
3025 #               of an interface. It uses the global %Prerequisites hash.
3026 # Arguments   : $iface - the interface.
3027 #############################################################################
3029 sub GetPrerequisites {
3030     my ($iface) = @_;
3031     my $text = "";
3032     my $i;
3034     if (exists($Prerequisites{$iface})) {
3035         $text = <<EOF;
3036 <para>
3037 $iface requires
3039         my @prereqs = split(' ', $Prerequisites{$iface});
3040         for ($i = 0; $i <= $#prereqs; $i++) {
3041             my $id = &CreateValidSGMLID ($prereqs[$i]);
3042             $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
3043             if ($i < $#prereqs - 1) {
3044                 $text .= ', ';
3045             }
3046             elsif ($i < $#prereqs) {
3047                 $text .= ' and ';
3048             }
3049             else {
3050                 $text .= '.';
3051             }
3052         }
3053         $text .= <<EOF;
3054 </para>
3056     }
3057     return $text;
3060 #############################################################################
3061 # Function    : GetDerived
3062 # Description : Returns the DocBook output describing the derived interfaces
3063 #               of an interface. It uses the global %Prerequisites hash.
3064 # Arguments   : $iface - the interface.
3065 #############################################################################
3067 sub GetDerived {
3068     my ($iface) = @_;
3069     my $text = "";
3070     my $i;
3072     my @derived = ();
3073     foreach my $key (keys %Prerequisites) {
3074         if ($Prerequisites{$key} =~ /\b$iface\b/) {
3075             push (@derived, $key);
3076         }
3077     }
3078     if ($#derived >= 0) {
3079         $text = <<EOF;
3080 <para>
3081 $iface is required by
3083         for ($i = 0; $i <= $#derived; $i++) {
3084             my $id = &CreateValidSGMLID ($derived[$i]);
3085             $text .= " <link linkend=\"$id\">$derived[$i]</link>";
3086             if ($i < $#derived - 1) {
3087                 $text .= ', ';
3088             }
3089             elsif ($i < $#derived) {
3090                 $text .= ' and ';
3091             }
3092             else {
3093                 $text .= '.';
3094             }
3095         }
3096         $text .= <<EOF;
3097 </para>
3099     }
3100     return $text;
3104 #############################################################################
3105 # Function    : GetSignals
3106 # Description : Returns the synopsis and detailed description DocBook output
3107 #               for the signal handlers of a given GtkObject subclass.
3108 # Arguments   : $object - the GtkObject subclass, e.g. 'GtkButton'.
3109 #############################################################################
3111 sub GetSignals {
3112     my ($object) = @_;
3113     my $synop = "";
3114     my $desc = "";
3116     my $i;
3117     for ($i = 0; $i <= $#SignalObjects; $i++) {
3118         if ($SignalObjects[$i] eq $object) {
3119             #print "Found signal: $SignalNames[$i]\n";
3120             my $name = $SignalNames[$i];
3121             my $symbol = "${object}::${name}";
3122             my $id = &CreateValidSGMLID ("$object-$name");
3124             my $pad = ' ' x (46 - length($name));
3125             $synop .= "  &quot;<link linkend=\"$id\">$name</link>&quot;$pad ";
3127             $desc .= "<refsect2 id=\"$id\" role=\"signal\"><title>The <literal>&quot;$name&quot;</literal> signal</title>\n";
3128             $desc .= MakeIndexterms($symbol, $id);
3129             $desc .= "\n";
3130             $desc .= OutputSymbolExtraLinks($symbol);
3132             $desc .= "<programlisting>";
3134             $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
3135             my $type_modifier = defined($1) ? $1 : "";
3136             my $type = $2;
3137             my $pointer = $3;
3138             my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
3140             my $ret_type_len = length ($type_modifier) + length ($pointer)
3141                 + length ($type);
3142             my $ret_type_output = "$type_modifier$xref$pointer"
3143                 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
3145             $desc  .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
3147             my $sourceparams = $SourceSymbolParams{$symbol};
3148             my @params = split ("\n", $SignalPrototypes[$i]);
3149             my $j;
3150             my $l;
3151             my $type_len = length("gpointer");
3152             my $name_len = length("user_data");
3153             # do two passes, the first one is to calculate padding
3154             for ($l = 0; $l < 2; $l++) {
3155                 for ($j = 0; $j <= $#params; $j++) {
3156                     # allow alphanumerics, '_', '[' & ']' in param names
3157                     if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
3158                         $type = $1;
3159                         $pointer = $2;
3160                         if (defined($sourceparams)) {
3161                             $name = $$sourceparams[$PARAM_FIELD_COUNT * $j];
3162                         }
3163                         else {
3164                             $name = $3;
3165                         }
3166                         if (!defined($name)) {
3167                             $name = "arg$j";
3168                         }
3169                         if ($l == 0) {
3170                             if (length($type) + length($pointer) > $type_len) {
3171                                 $type_len = length($type) + length($pointer);
3172                             }
3173                             if (length($name) > $name_len) {
3174                                 $name_len = length($name);
3175                             }
3176                         }
3177                         else {
3178                             $xref = &MakeXRef ($type, &tagify($type, "type"));
3179                             $pad = ' ' x ($type_len - length($type) - length($pointer));
3180                             $desc .= "$xref$pad $pointer$name,\n";
3181                             $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
3182                         }
3183                     } else {
3184                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3185                              "Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]");
3186                     }
3187                 }
3188             }
3189             $xref = &MakeXRef ("gpointer", &tagify("gpointer", "type"));
3190             $pad = ' ' x ($type_len - length("gpointer"));
3191             $desc  .= "$xref$pad user_data)";
3193             my $flags = $SignalFlags[$i];
3194             my $flags_string = "";
3196             if (defined ($flags)) {
3197               if ($flags =~ m/f/) {
3198                 $flags_string = "Run First";
3199               }
3200               elsif ($flags =~ m/l/) {
3201                 $flags_string = "Run Last";
3202               }
3203               elsif ($flags =~ m/c/) {
3204                 $flags_string = "Cleanup";
3205               }
3206               if ($flags =~ m/r/) {
3207                 if ($flags_string) { $flags_string .= " / "; }
3208                 $flags_string .= "No Recursion";
3209               }
3210               if ($flags =~ m/d/) {
3211                 if ($flags_string) { $flags_string .= " / "; }
3212                 $flags_string .= "Has Details";
3213               }
3214               if ($flags =~ m/a/) {
3215                 if ($flags_string) { $flags_string .= " / "; }
3216                 $flags_string .= "Action";
3217               }
3218               if ($flags =~ m/h/) {
3219                 if ($flags_string) { $flags_string .= " / "; }
3220                 $flags_string .= "No Hooks";
3221               }
3222             }
3224             if ($flags_string)
3225               {
3226                 $synop .= ": $flags_string\n";
3228                 $pad = ' ' x (5 + $name_len - length("user_data"));
3229                 $desc  .= "$pad : $flags_string</programlisting>\n";
3230               }
3231             else
3232               {
3233                 $synop .= "\n";
3234                 $desc  .= "</programlisting>\n";
3235               }
3237             $desc .= &MakeDeprecationNote($symbol);
3239             my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
3240             my $parameters_output = 0;
3242             $AllSymbols{$symbol} = 1;
3243             if (defined ($SymbolDocs{$symbol})) {
3244                 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3246                 # Try to insert the parameter table at the author's desired
3247                 # position. Otherwise we need to tag it onto the end.
3248                 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
3249                   $parameters_output = 1;
3250                 }
3251                 $desc .= $symbol_docs;
3253                 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
3254                     $AllDocumentedSymbols{$symbol} = 1;
3255                 }
3256             }
3258             if ($parameters_output == 0) {
3259                 $desc .= $parameters;
3260               }
3261             $desc .= OutputSymbolTraits ($symbol);
3262             $desc .= "</refsect2>";
3263         }
3264     }
3265     return ($synop, $desc);
3269 #############################################################################
3270 # Function    : GetArgs
3271 # Description : Returns the synopsis and detailed description DocBook output
3272 #               for the Args of a given GtkObject subclass.
3273 # Arguments   : $object - the GtkObject subclass, e.g. 'GtkButton'.
3274 #############################################################################
3276 sub GetArgs {
3277     my ($object) = @_;
3278     my $synop = "";
3279     my $desc = "";
3280     my $child_synop = "";
3281     my $child_desc = "";
3282     my $style_synop = "";
3283     my $style_desc = "";
3285     my $i;
3286     for ($i = 0; $i <= $#ArgObjects; $i++) {
3287         if ($ArgObjects[$i] eq $object) {
3288             #print "Found arg: $ArgNames[$i]\n";
3289             my $name = $ArgNames[$i];
3290             my $flags = $ArgFlags[$i];
3291             my $flags_string = "";
3292             my $kind = "";
3293             my $id_sep = "";
3295             if ($flags =~ m/c/) {
3296                 $kind = "child property";
3297                 $id_sep = "c-";
3298             }
3299             elsif ($flags =~ m/s/) {
3300                 $kind = "style property";
3301                 $id_sep = "s-";
3302             }
3303             else {
3304                 $kind = "property";
3305             }
3307             # Remember only one colon so we don't clash with signals.
3308             my $symbol = "${object}:${name}";
3309             # use two dashes and ev. an extra separator here for the same reason.
3310             my $id = &CreateValidSGMLID ("$object--$id_sep$name");
3312             my $type = $ArgTypes[$i];
3313             my $type_output;
3314             my $range = $ArgRanges[$i];
3315             my $range_output = CreateValidSGML ($range);
3316             my $default = $ArgDefaults[$i];
3317             my $default_output = CreateValidSGML ($default);
3319             if ($type eq "GtkString") {
3320                 $type = "char*";
3321             }
3322             if ($type eq "GtkSignal") {
3323                 $type = "GtkSignalFunc, gpointer";
3324                 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
3325                     . &MakeXRef ("gpointer");
3326             } elsif ($type =~ m/^(\w+)\*$/) {
3327                 $type_output = &MakeXRef ($1, &tagify($1, "type")) . "*";
3328             } else {
3329                 $type_output = &MakeXRef ($type, &tagify($type, "type"));
3330             }
3332             if ($flags =~ m/r/) {
3333                 $flags_string = "Read";
3334             }
3335             if ($flags =~ m/w/) {
3336                 if ($flags_string) { $flags_string .= " / "; }
3337                 $flags_string .= "Write";
3338             }
3339             if ($flags =~ m/x/) {
3340                 if ($flags_string) { $flags_string .= " / "; }
3341                 $flags_string .= "Construct";
3342             }
3343             if ($flags =~ m/X/) {
3344                 if ($flags_string) { $flags_string .= " / "; }
3345                 $flags_string .= "Construct Only";
3346             }
3348             $AllSymbols{$symbol} = 1;
3349             my $blurb;
3350             if (defined($SymbolDocs{$symbol}) &&
3351                 !IsEmptyDoc($SymbolDocs{$symbol})) {
3352                 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3353                 #print ".. [$SymbolDocs{$symbol}][$blurb]\n";
3354                 $AllDocumentedSymbols{$symbol} = 1;
3355             }
3356             else {
3357                 if (!($ArgBlurbs[$i] eq "")) {
3358                     $AllDocumentedSymbols{$symbol} = 1;
3359                 } else {
3360                     # FIXME: print a warning?
3361                     #print ".. no description\n";
3362                 }
3363                 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
3364             }
3366             my $pad1 = " " x (24 - length ($name));
3367             my $pad2 = " " x (20 - length ($type));
3369             my $arg_synop = "  &quot;<link linkend=\"$id\">$name</link>&quot;$pad1 $type_output $pad2 : $flags_string\n";
3370             my $arg_desc = "<refsect2 id=\"$id\" role=\"property\"><title>The <literal>&quot;$name&quot;</literal> $kind</title>\n";
3371             $arg_desc .= MakeIndexterms($symbol, $id);
3372             $arg_desc .= "\n";
3373             $arg_desc .= OutputSymbolExtraLinks($symbol);
3375             $arg_desc .= "<programlisting>  &quot;$name&quot;$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
3376             $arg_desc .= &MakeDeprecationNote($symbol);
3377             $arg_desc .= $blurb;
3378             if ($range ne "") {
3379                 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
3380             }
3381             if ($default ne "") {
3382                 $arg_desc .= "<para>Default value: $default_output</para>\n";
3383             }
3384             $arg_desc .= OutputSymbolTraits ($symbol);
3385             $arg_desc .= "</refsect2>\n";
3387             if ($flags =~ m/c/) {
3388                 $child_synop .= $arg_synop;
3389                 $child_desc .= $arg_desc;
3390             }
3391             elsif ($flags =~ m/s/) {
3392                 $style_synop .= $arg_synop;
3393                 $style_desc .= $arg_desc;
3394             }
3395             else {
3396                 $synop .= $arg_synop;
3397                 $desc .= $arg_desc;
3398             }
3399         }
3400     }
3401     return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
3405 #############################################################################
3406 # Function    : ReadSourceDocumentation
3407 # Description : This reads in the documentation embedded in comment blocks
3408 #               in the source code (for Gnome).
3410 #               Parameter descriptions override any in the template files.
3411 #               Function descriptions are placed before any description from
3412 #               the template files.
3414 #               It recursively descends the source directory looking for .c
3415 #               files and scans them looking for specially-formatted comment
3416 #               blocks.
3418 # Arguments   : $source_dir - the directory to scan.
3419 #############m###############################################################
3421 sub ReadSourceDocumentation {
3422     my ($source_dir) = @_;
3423     my ($file, $dir, @suffix_list, $suffix);
3424     #print "Scanning source directory: $source_dir\n";
3426     # This array holds any subdirectories found.
3427     my (@subdirs) = ();
3429     @suffix_list = split (/,/, $SOURCE_SUFFIXES);
3431     opendir (SRCDIR, $source_dir)
3432         || die "Can't open source directory $source_dir: $!";
3434     foreach $file (readdir (SRCDIR)) {
3435       if ($file =~ /^\./) {
3436         next;
3437       } elsif (-d "$source_dir/$file") {
3438         push (@subdirs, $file);
3439       } elsif (@suffix_list) {
3440         foreach $suffix (@suffix_list) {
3441           if ($file =~ m/\.\Q${suffix}\E$/) {
3442             &ScanSourceFile ("$source_dir/$file");
3443           }
3444         }
3445       } elsif ($file =~ m/\.[ch]$/) {
3446         &ScanSourceFile ("$source_dir/$file");
3447       }
3448     }
3449     closedir (SRCDIR);
3451     # Now recursively scan the subdirectories.
3452     foreach $dir (@subdirs) {
3453         next if ($IGNORE_FILES =~ m/(\s|^)\Q${dir}\E(\s|$)/);
3454         &ReadSourceDocumentation ("$source_dir/$dir");
3455     }
3459 #############################################################################
3460 # Function    : ScanSourceFile
3461 # Description : Scans one source file looking for specially-formatted comment
3462 #               blocks. Later &MergeSourceDocumentation is used to merge any
3463 #               documentation found with the documentation already read in
3464 #               from the template files.
3466 # Arguments   : $file - the file to scan.
3467 #############################################################################
3469 sub ScanSourceFile {
3470     my ($file) = @_;
3471     my $basename;
3473     if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
3474         $basename = $1;
3475     } else {
3476         &LogWarning ($file, 1, "Can't find basename for this filename.");
3477         $basename = $file;
3478     }
3480     # Check if the basename is in the list of files to ignore.
3481     if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
3482         return;
3483     }
3485     #print "DEBUG: Scanning $file\n";
3487     open (SRCFILE, $file)
3488         || die "Can't open $file: $!";
3489     my $in_comment_block = 0;
3490     my $symbol;
3491     my ($in_description, $in_return, $in_since, $in_stability, $in_deprecated);
3492     my ($description, $return_desc, $return_start, $return_style);
3493     my ($since_desc, $stability_desc, $deprecated_desc);
3494     my $current_param;
3495     my $ignore_broken_returns;
3496     my @params;
3497     while (<SRCFILE>) {
3498         # Look for the start of a comment block.
3499         if (!$in_comment_block) {
3500             if (m%^\s*/\*.*\*/%) {
3501                 #one-line comment - not gtkdoc
3502             } elsif (m%^\s*/\*\*\s%) {
3503                 #print "Found comment block start\n";
3505                 $in_comment_block = 1;
3507                 # Reset all the symbol data.
3508                 $symbol = "";
3509                 $in_description = 0;
3510                 $in_return = 0;
3511                 $in_since = 0;
3512                 $in_deprecated = 0;
3513                 $in_stability = 0;
3514                 $description = "";
3515                 $return_desc = "";
3516                 $return_style = "";
3517                 $since_desc = "";
3518                 $deprecated_desc = "";
3519                 $stability_desc = "";
3520                 $current_param = -1;
3521                 $ignore_broken_returns = 0;
3522                 @params = ();
3523             }
3524             next;
3525         }
3527         # We're in a comment block. Check if we've found the end of it.
3528         if (m%^\s*\*+/%) {
3529             if (!$symbol) {
3530                 # maybe its not even meant to be a gtk-doc comment?
3531                 &LogWarning ($file, $., "Symbol name not found at the start of the comment block.");
3532             } else {
3533                 # Add the return value description onto the end of the params.
3534                 if ($return_desc) {
3535                     push (@params, "Returns");
3536                     push (@params, $return_desc);
3537                     if ($return_style eq 'broken') {
3538                         &LogWarning ($file, $., "Free-form return value description in $symbol. Use `Returns:' to avoid ambiguities.");
3539                     }
3540                 }
3541                 # Convert special SGML characters
3542                 $description = &ConvertSGMLChars ($symbol, $description);
3543                 my $k;
3544                 for ($k = 1; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3545                     $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
3546                 }
3548                 # Handle Section docs
3549                 if ($symbol =~ m/SECTION:\s*(.*)/) {
3550                     my $real_symbol=$1;
3551                     my $key;
3553                     if (scalar %KnownSymbols) {
3554                         if ((! defined($KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"})) || $KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"} != 1) {
3555                             &LogWarning ($file, $., "Section $real_symbol is not defined in the $MODULE-section.txt file.");
3556                         }
3557                     }
3559                     #print "SECTION DOCS found in source for : '$real_symbol'\n";
3560                     $ignore_broken_returns = 1;
3561                     for ($k = 0; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3562                         #print "   '".$params[$k]."'\n";
3563                         $params[$k] = "\L$params[$k]";
3564                         undef $key;
3565                         if ($params[$k] eq "short_description") {
3566                             $key = "$TMPL_DIR/$real_symbol:Short_Description";
3567                         } elsif ($params[$k] eq "see_also") {
3568                             $key = "$TMPL_DIR/$real_symbol:See_Also";
3569                         } elsif ($params[$k] eq "title") {
3570                             $key = "$TMPL_DIR/$real_symbol:Title";
3571                         } elsif ($params[$k] eq "stability") {
3572                             $key = "$TMPL_DIR/$real_symbol:Stability_Level";
3573                         } elsif ($params[$k] eq "section_id") {
3574                             $key = "$TMPL_DIR/$real_symbol:Section_Id";
3575                         } elsif ($params[$k] eq "include") {
3576                             $key = "$TMPL_DIR/$real_symbol:Include";
3577                         }
3578                         if (defined($key)) {
3579                             $SourceSymbolDocs{$key}=$params[$k+1];
3580                             $SourceSymbolSourceFile{$key} = $file;
3581                             $SourceSymbolSourceLine{$key} = $.;
3582                         }
3583                     }
3584                     $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
3585                     $SourceSymbolSourceFile{"$TMPL_DIR/$real_symbol:Long_Description"} = $file;
3586                     $SourceSymbolSourceLine{"$TMPL_DIR/$real_symbol:Long_Description"} = $.;
3587                     #$SourceSymbolTypes{$symbol} = "SECTION";
3588                 } else {
3589                     #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
3590                     $SourceSymbolDocs{$symbol} = $description;
3591                     $SourceSymbolParams{$symbol} = [ @params ];
3592                     # FIXME $SourceSymbolTypes{$symbol} = "STRUCT,SIGNAL,ARG,FUNCTION,MACRO";
3593                     #if (defined $DeclarationTypes{$symbol}) {
3594                     #    $SourceSymbolTypes{$symbol} = $DeclarationTypes{$symbol}
3595                     #}
3596                     $SourceSymbolSourceFile{$symbol} = $file;
3597                     $SourceSymbolSourceLine{$symbol} = $.;
3598                 }
3600                 if ($since_desc) {
3601                      ($since_desc, my @extra_lines) = split ("\n", $since_desc);
3602                      $since_desc =~ s/^\s+//;
3603                      $since_desc =~ s/\s+$//;
3604                      #print "Since($symbol) : [$since_desc]\n";
3605                      $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
3606                      if(scalar @extra_lines) {
3607                          &LogWarning ($file, $., "multi-line since docs found");
3608                      }
3609                 }
3611                 if ($stability_desc) {
3612                     $stability_desc = &ParseStabilityLevel($stability_desc, $file, $., "Stability level for $symbol");
3613                     $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
3614                 }
3616                 if ($deprecated_desc) {
3617                     if (exists $Deprecated{$symbol}) {
3618                     }
3619                     else {
3620                          # don't warn for signals and properties
3621                          #if ($symbol !~ m/::?(.*)/) {
3622                          if (defined $DeclarationTypes{$symbol}) {
3623                              &LogWarning ($file, $., 
3624                                  "$symbol is deprecated in the inline comments, but no deprecation guards were found around the declaration.".
3625                                  " (See the --deprecated-guards option for gtkdoc-scan.)");
3626                          }
3627                     }
3628                     $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
3629                 }
3630             }
3632             $in_comment_block = 0;
3633             next;
3634         }
3636         # Get rid of ' * ' at start of every line in the comment block.
3637         s%^\s*\*\s?%%;
3638         # But make sure we don't get rid of the newline at the end.
3639         if (!$_) {
3640             $_ = "\n";
3641         }
3642         #print "DEBUG: scanning :$_";
3644         # If we haven't found the symbol name yet, look for it.
3645         if (!$symbol) {
3646             if (m%^\s*(SECTION:\s*\S+)%) {
3647                 $symbol = $1;
3648                 #print "SECTION DOCS found in source for : '$symbol'\n";
3649                 $ignore_broken_returns = 1;
3650             } elsif (m%^\s*([\w:-]*\w)\s*:?\s*$%) {
3651                 $symbol = $1;
3652                 #print "SYMBOL DOCS found in source for : '$symbol'\n";
3653             }
3654             next;
3655         }
3657         # If we're in the return value description, add it to the end.
3658         if ($in_return) {
3659             # If we find another valid returns line, we assume that the first
3660             # one was really part of the description.
3661             if (m/^\s*(returns:|return\s+value:)/i) {
3662                 if ($return_style eq 'broken') {
3663                     $description .= $return_start . $return_desc;
3664                 }
3665                 $return_start = $1;
3666                 if ($return_style eq 'sane') {
3667                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3668                 }
3669                 $return_style = 'sane';
3670                 $ignore_broken_returns = 1;
3671                 $return_desc = $';
3672             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3673                 $description .= $return_start . $return_desc;
3674                 $return_start = $1;
3675                 $return_style = 'broken';
3676                 $return_desc = $';
3677             } elsif (m%^\s*since:%i) {
3678                 $since_desc = $';
3679                 $in_since = 1;
3680                 $in_return = 0;
3681             } elsif (m%^\s*stability:%i) {
3682                 $stability_desc = $';
3683                 $in_stability = 1;
3684                 $in_return = 0;
3685             } elsif (m%^\s*deprecated:%i) {
3686                 $deprecated_desc = $';
3687                 $in_deprecated = 1;
3688                 $in_return = 0;
3689             } else {
3690                 $return_desc .= $_;
3691             }
3692             next;
3693         }
3695         if ($in_since) {
3696             if (m/^\s*(returns:|return\s+value:)/i) {
3697                 if ($return_style eq 'broken') {
3698                     $description .= $return_start . $return_desc;
3699                 }
3700                 $return_start = $1;
3701                 if ($return_style eq 'sane') {
3702                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3703                 }
3704                 $return_style = 'sane';
3705                 $ignore_broken_returns = 1;
3706                 $return_desc = $';
3707                 $in_return = 1;
3708                 $in_since = 0;
3709             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3710                 $return_start = $1;
3711                 $return_style = 'broken';
3712                 $return_desc = $';
3713                 $in_return = 1;
3714                 $in_since = 0;
3715             } elsif (m%^\s*deprecated:%i) {
3716                 $deprecated_desc = $';
3717                 $in_deprecated = 1;
3718                 $in_since = 0;
3719             } elsif (m%^\s*stability:%i) {
3720                 $stability_desc = $';
3721                 $in_stability = 1;
3722                 $in_since = 0;
3723             } else {
3724                 $since_desc .= $_;
3725             }
3726             next;
3727         }
3729         if ($in_stability) {
3730             if (m/^\s*(returns:|return\s+value:)/i) {
3731                 if ($return_style eq 'broken') {
3732                     $description .= $return_start . $return_desc;
3733                 }
3734                 $return_start = $1;
3735                 if ($return_style eq 'sane') {
3736                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3737                 }
3738                 $return_style = 'sane';
3739                 $ignore_broken_returns = 1;
3740                 $return_desc = $';
3741                 $in_return = 1;
3742                 $in_stability = 0;
3743             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3744                 $return_start = $1;
3745                 $return_style = 'broken';
3746                 $return_desc = $';
3747                 $in_return = 1;
3748                 $in_stability = 0;
3749             } elsif (m%^\s*deprecated:%i) {
3750                 $deprecated_desc = $';
3751                 $in_deprecated = 1;
3752                 $in_stability = 0;
3753             } elsif (m%^\s*since:%i) {
3754                 $since_desc = $';
3755                 $in_since = 1;
3756                 $in_stability = 0;
3757             } else {
3758                 $stability_desc .= $_;
3759             }
3760             next;
3761         }
3763         if ($in_deprecated) {
3764             if (m/^\s*(returns:|return\s+value:)/i) {
3765                 if ($return_style eq 'broken') {
3766                     $description .= $return_start . $return_desc;
3767                 }
3768                 $return_start = $1;
3769                 if ($return_style eq 'sane') {
3770                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3771                 }
3772                 $return_style = 'sane';
3773                 $ignore_broken_returns = 1;
3774                 $return_desc = $';
3775                 $in_return = 1;
3776                 $in_deprecated = 0;
3777             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3778                 $return_start = $1;
3779                 $return_style = 'broken';
3780                 $return_desc = $';
3781                 $in_return = 1;
3782                 $in_deprecated = 0;
3783             } elsif (m%^\s*since:%i) {
3784                 $since_desc = $';
3785                 $in_since = 1;
3786                 $in_deprecated = 0;
3787             } elsif (m%^\s*stability:%i) {
3788                 $stability_desc = $';
3789                 $in_stability = 1;
3790                 $in_deprecated = 0;
3791             } else {
3792                 $deprecated_desc .= $_;
3793             }
3794             next;
3795         }
3797         # If we're in the description part, check for the 'Returns:' line.
3798         # If that isn't found, add the text to the end.
3799         if ($in_description) {
3800             # Get rid of 'Description:'
3801             s%^\s*Description:%%;
3803             if (m/^\s*(returns:|return\s+value:)/i) {
3804                 if ($return_style eq 'broken') {
3805                     $description .= $return_start . $return_desc;
3806                 }
3807                 $return_start = $1;
3808                 if ($return_style eq 'sane') {
3809                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3810                 }
3811                 $return_style = 'sane';
3812                 $ignore_broken_returns = 1;
3813                 $return_desc = $';
3814                 $in_return = 1;
3815                 next;
3816             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3817                 $return_start = $1;
3818                 $return_style = 'broken';
3819                 $return_desc = $';
3820                 $in_return = 1;
3821                 next;
3822             } elsif (m%^\s*since:%i) {
3823                 $since_desc = $';
3824                 $in_since = 1;
3825                 next;
3826             } elsif (m%^\s*deprecated:%i) {
3827                 $deprecated_desc = $';
3828                 $in_deprecated = 1;
3829                 next;
3830             } elsif (m%^\s*stability:%i) {
3831                 $stability_desc = $';
3832                 $in_stability = 1;
3833                 next;
3834             }
3836             $description .= $_;
3837             next;
3838         }
3840         # We must be in the parameters. Check for the empty line below them.
3841         if (m%^\s*$%) {
3842             $in_description = 1;
3843             next;
3844         }
3846         # Look for a parameter name.
3847         if (m%^\s*@(\S+)\s*:\s*%) {
3848             my $param_name = $1;
3849             my $param_desc = $';
3851             #print "Found parameter: $param_name\n";
3852             # Allow '...' as the Varargs parameter.
3853             if ($param_name eq "...") {
3854                 $param_name = "Varargs";
3855             }
3856             if ("\L$param_name" eq "returns") {
3857                 $return_style = 'sane';
3858                 $ignore_broken_returns = 1;
3859             }
3860             push (@params, $param_name);
3861             push (@params, $param_desc);
3862             $current_param += $PARAM_FIELD_COUNT;
3863             next;
3864         }
3866         # We must be in the middle of a parameter description, so add it on
3867         # to the last element in @params.
3868         if ($current_param == -1) {
3869             &LogWarning ($file, $., "Parsing comment block file : parameter expected.");
3870         } else {
3871             $params[$#params] .= $_;
3872         }
3873     }
3874     close (SRCFILE);
3877 #############################################################################
3878 # Function    : OutputMissingDocumentation
3879 # Description : Outputs report of documentation coverage to a file
3881 # Arguments   : none
3882 #############################################################################
3884 sub OutputMissingDocumentation {
3885     my $n_documented = 0;
3886     my $n_incomplete = 0;
3887     my $total = 0;
3888     my $symbol;
3889     my $percent;
3890     my $msg;
3891     my $buffer = "";
3892     my $buffer_deprecated = "";
3893     my $buffer_descriptions = "";
3894     
3895     open (UNDOCUMENTED, ">$ROOT_DIR/$MODULE-undocumented.txt")
3896       || die "Can't create $ROOT_DIR/$MODULE-undocumented.txt: $!";
3897     
3898     foreach $symbol (sort (keys (%AllSymbols))) {
3899         # FIXME: should we print LogWarnings for undocumented stuff?
3900         # DEBUG
3901         #my $ssfile = &GetSymbolSourceFile($symbol);
3902         #my $ssline = &GetSymbolSourceLine($symbol);
3903         #my $location = "defined at " . (defined($ssfile)?$ssfile:"?") . ":" . (defined($ssline)?$ssline:"0") . "\n";
3904         # DEBUG
3905         if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include|Section_Id)/) {
3906             $total++;
3907             if (exists ($AllDocumentedSymbols{$symbol})) {
3908                 $n_documented++;
3909                 if (exists ($AllIncompleteSymbols{$symbol})) {
3910                     $n_incomplete++;
3911                     $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3912                     #$buffer .= "\t0: ".$location;
3913                 }
3914             } elsif (exists $Deprecated{$symbol}) {
3915                 if (exists ($AllIncompleteSymbols{$symbol})) {
3916                     $n_incomplete++;
3917                     $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3918                     #$buffer .= "\t1a: ".$location;
3919                 } else {
3920                     $buffer_deprecated .= $symbol . "\n";
3921                     #$buffer .= "\t1b: ".$location;
3922                 }
3923             } else {
3924                 if (exists ($AllIncompleteSymbols{$symbol})) {
3925                     $n_incomplete++;
3926                     $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3927                     #$buffer .= "\t2a: ".$location;
3928                 } else {
3929                     $buffer .= $symbol . "\n";
3930                     #$buffer .= "\t2b: ".$location;
3931                 }
3932             }
3933         } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
3934             $total++;
3935             #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
3936             #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
3937             #print "%%%% $symbol : $len1,$len2\n";
3938             if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
3939             || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
3940               $n_documented++;
3941             } else {
3942               # cut off the leading namespace ($TMPL_DIR)
3943               $symbol =~ m/^.*\/(.*)$/;
3944               $buffer_descriptions .= $1 . "\n";
3945             }
3946         }
3947     }
3948     
3949     $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
3950     
3951     if ($total == 0) {
3952       $percent = 100;
3953     } else {
3954       $percent = ($n_documented / $total) * 100.0;
3955     }
3956     
3957     printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
3958     print UNDOCUMENTED "$n_documented symbols documented.\n";
3959     print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
3960     print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
3961     
3962     print UNDOCUMENTED $buffer;
3963     
3964     close (UNDOCUMENTED);
3965     
3966     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);
3970 #############################################################################
3971 # Function    : OutputUndeclaredSymbols
3972 # Description : Outputs symbols that are undeclared yet documented to a file
3974 # Arguments   : none
3975 #############################################################################
3977 sub OutputUndeclaredSymbols {
3978     open(UNDECLARED, ">$ROOT_DIR/$MODULE-undeclared.txt")
3979         || die "Can't create $ROOT_DIR/$MODULE-undeclared.txt";
3981     if (%UndeclaredSymbols) {
3982         print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
3983         print UNDECLARED "\n";
3984         print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
3985     }
3986     close(UNDECLARED);
3990 #############################################################################
3991 # Function    : OutputAllSymbols
3992 # Description : Outputs list of all symbols to a file
3994 # Arguments   : none
3995 #############################################################################
3997 sub OutputAllSymbols {
3998      my $n_documented = 0;
3999      my $total = 0;
4000      my $symbol;
4001      my $percent;
4002      my $msg;
4004      open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
4005           || die "Can't create $ROOT_DIR/$MODULE-symbols.txt: $!";
4007      foreach $symbol (sort (keys (%AllSymbols))) {
4008           print SYMBOLS $symbol . "\n";
4009      }
4011      close (SYMBOLS);
4014 #############################################################################
4015 # Function    : OutputSymbolsWithoutSince
4016 # Description : Outputs list of all symbols without a since tag to a file
4018 # Arguments   : none
4019 #############################################################################
4021 sub OutputSymbolsWithoutSince {
4022      my $n_documented = 0;
4023      my $total = 0;
4024      my $symbol;
4025      my $percent;
4026      my $msg;
4028      open (SYMBOLS, ">$ROOT_DIR/$MODULE-nosince.txt")
4029           || die "Can't create $ROOT_DIR/$MODULE-nosince.txt: $!";
4031      foreach $symbol (sort (keys (%SourceSymbolDocs))) {
4032          if (!defined $Since{$symbol}) {
4033              print SYMBOLS $symbol . "\n";
4034          }
4035      }
4037      close (SYMBOLS);
4041 #############################################################################
4042 # Function    : MergeSourceDocumentation
4043 # Description : This merges documentation read from a source file into the
4044 #               documentation read in from a template file.
4046 #               Parameter descriptions override any in the template files.
4047 #               Function descriptions are placed before any description from
4048 #               the template files.
4050 # Arguments   : none
4051 #############################################################################
4053 sub MergeSourceDocumentation {
4054     my $symbol;
4055     my @Symbols;
4057     if (scalar %SymbolDocs) {
4058         @Symbols=keys (%SymbolDocs);
4059         #print "num existing entries: ".(scalar @Symbols)."\n";
4060         #print "  ",$Symbols[0], " ",$Symbols[1],"\n";
4061     }
4062     else {
4063         # filter scanned declarations, with what we suppress from -sections.txt
4064         my %tmp = ();
4065         foreach $symbol (keys (%Declarations)) {
4066             if (defined($KnownSymbols{$symbol}) && $KnownSymbols{$symbol} == 1) {
4067                 $tmp{$symbol}=1;
4068             }
4069         }
4070         # , add the rest from -sections.txt
4071         foreach $symbol (keys (%KnownSymbols)) {
4072             if ($KnownSymbols{$symbol} == 1) {
4073                 $tmp{$symbol}=1;
4074             }
4075         }
4076         # and add whats found in the source
4077         foreach $symbol (keys (%SourceSymbolDocs)) {
4078             $tmp{$symbol}=1;
4079         }
4080         @Symbols = keys (%tmp);
4081         #print "num source entries: ".(scalar @Symbols)."\n";
4082     }
4083     foreach $symbol (@Symbols) {
4084         $AllSymbols{$symbol} = 1;
4086         my $have_tmpl_docs = 0;
4088         ## See if the symbol is documented in template
4089         my $tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4090         my $check_tmpl_doc =$tmpl_doc;
4091         # remove all xml-tags and whitespaces
4092         #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
4093         $check_tmpl_doc =~ s/<.*?>//g;
4094         $check_tmpl_doc =~ s/\s//g;
4095         # anything left ?
4096         if ($check_tmpl_doc ne "") {
4097             $have_tmpl_docs = 1;
4098             #print "## [$check_tmpl_doc]\n";
4099         } else {
4100             $tmpl_doc = "";
4101         }
4103         if (exists ($SourceSymbolDocs{$symbol})) {
4104             my $type = $DeclarationTypes {$symbol};
4106             #print "merging [$symbol] from source\n";
4108             my $item = "Parameter";
4109             if (defined ($type)) {
4110                 if ($type eq 'STRUCT') {
4111                     $item = "Field";
4112                 } elsif ($type eq 'ENUM') {
4113                     $item = "Value";
4114                 } elsif ($type eq 'UNION') {
4115                     $item = "Field";
4116                 }
4117             } else {
4118                 $type="SIGNAL";
4119             }
4121             my $src_doc = $SourceSymbolDocs{$symbol};
4122             # remove leading and training whitespaces
4123             $src_doc =~ s/^\s+//;
4124             $src_doc =~ s/\s+$//;
4126             # Don't output warnings for overridden titles as titles are
4127             # automatically generated in the -sections.txt file, and thus they
4128             # are often overridden.
4129             if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
4130                 # check if content is different
4131                 if ($tmpl_doc ne $src_doc) {
4132                     #print "[$tmpl_doc] [$src_doc]\n";
4133                     &LogWarning ($SourceSymbolSourceFile{$symbol}, $SourceSymbolSourceLine{$symbol},
4134                         "Documentation in template ".$SymbolSourceFile{$symbol}.":".$SymbolSourceLine{$symbol}." for $symbol being overridden by inline comments.");
4135                 }
4136             }
4138             if ($src_doc ne "") {
4139                  $AllDocumentedSymbols{$symbol} = 1;
4140             }
4142             # Convert <!--PARAMETERS--> with any blank lines around it to
4143             # a </para> followed by <!--PARAMETERS--> followed by <para>.
4144             $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
4146             # If there is a blank line, finish the paragraph and start another.
4147             $src_doc = &ConvertBlankLines ($src_doc, $symbol);
4148             # Do not add <para> to nothing, it breaks missing docs checks.
4149             my $src_doc_para = "";
4150             if ($src_doc) {
4151                 $src_doc_para = "<para>\n$src_doc</para>\n";
4152                 #print "$symbol : [$src_doc][$src_doc_para]\n";
4153             }
4155             if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
4156                 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4157             } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
4158                 # For the title/summary/see also section docs we don't want to
4159                 # add any <para> tags.
4160                 $SymbolDocs{$symbol} = "$src_doc"
4161             } else {
4162                 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4163             }
4165             # merge parameters
4166             if ($symbol =~ m/.*::.*/) {
4167                 # For signals we prefer the param names from the source docs,
4168                 # since the ones from the templates are likely to contain the
4169                 # artificial argn names which are generated by gtkdoc-scangobj.
4170                 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4171                 # FIXME: we need to check for empty docs here as well!
4172             } else {
4173                 # The templates contain the definitive parameter names and order,
4174                 # so we will not change that. We only override the actual text.
4175                 my $tmpl_params = $SymbolParams{$symbol};
4176                 if (!defined ($tmpl_params)) {
4177                     #print "No merge needed for $symbol\n";
4178                     $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4179                     #  FIXME: we still like to get the number of params and merge
4180                     #  1) we would noticed that params have been removed/renamed
4181                     #  2) we would catch undocumented params
4182                     #  params are not (yet) exported in -decl.txt so that we
4183                     #  could easily grab them :/
4184                 } else {
4185                     my $params = $SourceSymbolParams{$symbol};
4186                     my $j;
4187                     #print "Merge needed for $symbol, tmpl_params: ",$#$tmpl_params,", source_params: ",$#$params," \n";
4188                     for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4189                         my $tmpl_param_name = $$tmpl_params[$j];
4191                         # Allow '...' as the Varargs parameter.
4192                         if ($tmpl_param_name eq "...") {
4193                             $tmpl_param_name = "Varargs";
4194                         }
4196                         # Try to find the param in the source comment documentation.
4197                         my $found = 0;
4198                         my $k;
4199                         #print "  try merge param $tmpl_param_name\n";
4200                         for ($k = 0; $k <= $#$params; $k += $PARAM_FIELD_COUNT) {
4201                             my $param_name = $$params[$k];
4202                             my $param_desc = $$params[$k + 1];
4204                             #print "    test param  $param_name\n";
4205                             # We accept changes in case, since the Gnome source
4206                             # docs contain a lot of these.
4207                             if ("\L$param_name" eq "\L$tmpl_param_name") {
4208                                 $found = 1;
4210                                 # Override the description.
4211                                 $$tmpl_params[$j + 1] = $param_desc;
4213                                 # Set the name to "" to mark it as used.
4214                                 $$params[$k] = "";
4215                                 last;
4216                             }
4217                         }
4219                         # If it looks like the parameters are there, but not
4220                         # in the right place, try to explain a bit better.
4221                         if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
4222                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4223                                 "Parameters for $symbol must start on the line immediately after the function or macro name.");
4224                         }
4225                     }
4227                     # Now we output a warning if parameters have been described which
4228                     # do not exist.
4229                     for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
4230                         my $param_name = $$params[$j];
4231                         if ($param_name) {
4232                             # the template builder cannot detect if a macro returns
4233                             # a result or not
4234                             if(($type eq "MACRO") && ($param_name eq "Returns")) {
4235                                 # FIXME: do we need to add it then to tmpl_params[] ?
4236                                 my $num=$#$tmpl_params;
4237                                 #print "  adding Returns: to macro docs for $symbol.\n";
4238                                 $$tmpl_params[$num+1]="Returns";
4239                                 $$tmpl_params[$num+2]=$$params[$j+1];
4240                                 next;
4241                             }
4242                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4243                                 "$item described in source code comment block but does not exist. $type: $symbol $item: $param_name.");
4244                         }
4245                     }
4246                 }
4247             }
4248         } else {
4249             if ($have_tmpl_docs) {
4250                 $AllDocumentedSymbols{$symbol} = 1;
4251                 #print "merging [$symbol] from template\n";
4252             }
4253             else {
4254                 #print "[$symbol] undocumented\n";
4255             }
4256         }
4258         # if this symbol is documented, check if docs are complete
4259         $check_tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4260         # remove all xml-tags and whitespaces
4261         #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
4262         $check_tmpl_doc =~ s/<.*?>//g;
4263         $check_tmpl_doc =~ s/\s//g;
4264         if ($check_tmpl_doc ne "") {
4265             my $tmpl_params = $SymbolParams{$symbol};
4266             if (defined ($tmpl_params)) {
4267                 my $type = $DeclarationTypes {$symbol};
4269                 my $item = "Parameter";
4270                 if (defined ($type)) {
4271                     if ($type eq 'STRUCT') {
4272                         $item = "Field";
4273                     } elsif ($type eq 'ENUM') {
4274                         $item = "Value";
4275                     } elsif ($type eq 'UNION') {
4276                         $item = "Field";
4277                     }
4278                 } else {
4279                     $type="SIGNAL";
4280                 }
4282                 #print "Check param docs for $symbol, tmpl_params: ",$#$tmpl_params," entries, type=$type\n";
4284                 if ($#$tmpl_params > 0) {
4285                     my $j;
4286                     for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4287                         # Output a warning if the parameter is empty and
4288                         # remember for stats.
4289                         my $tmpl_param_name = $$tmpl_params[$j];
4290                         my $tmpl_param_desc = $$tmpl_params[$j + 1];
4291                         if ($tmpl_param_desc !~ m/\S/) {
4292                             if (exists ($AllIncompleteSymbols{$symbol})) {
4293                                 $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
4294                             } else {
4295                                 $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
4296                             }
4297                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4298                                 "$item description for $symbol"."::"."$tmpl_param_name is missing in source code comment block.");
4299                         }
4300                     }
4301                 }
4302                 else {
4303                     if ($#$tmpl_params == 0) {
4304                         $AllIncompleteSymbols{$symbol}="<items>";
4305                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4306                             "$item descriptions for $symbol are missing in source code comment block.");
4307                     }
4308                     # $#$tmpl_params==-1 means we don't know about parameters
4309                     # this unfortunately does not tell if there should be some
4310                 }
4311             }
4312         }
4313    }
4314    #print "num doc entries: ".(scalar %SymbolDocs)."\n";
4317 #############################################################################
4318 # Function    : IsEmptyDoc
4319 # Description : Check if a doc-string is empty. Its also regarded as empty if
4320 #               it only consist of whitespace or e.g. FIXME.
4321 # Arguments   : the doc-string
4322 #############################################################################
4323 sub IsEmptyDoc {
4324     my ($doc) = @_;
4325     
4326     if ($doc =~ /^\s*$/) {
4327         return 1;
4328     }
4330     if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
4331         return 1;
4332     }
4334     return 0;
4338 # This converts blank lines to "</para><para>", but only outside CDATA and
4339 # <programlisting> tags.
4340 sub ConvertBlankLines {
4341     return &ModifyXMLElements ($_[0], $_[1],
4342                                "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
4343                                \&ConvertBlankLinesEndTag,
4344                                \&ConvertBlankLinesCallback);
4348 sub ConvertBlankLinesEndTag {
4349   if ($_[0] eq "<!\[CDATA\[") {
4350     return "]]>";
4351   } elsif ($_[0] eq "|[") {
4352     return "]\\|";
4353   } else {
4354     return "</programlisting>";
4355   }
4358 sub ConvertBlankLinesCallback {
4359   my ($text, $symbol, $tag) = @_;
4361   # If we're not in CDATA or a <programlisting> we convert blank lines so
4362   # they start a new <para>.
4363   if ($tag eq "") {
4364     $text =~ s%\n{2,}%\n</para>\n<para>\n%g;
4365   }
4367   return $text;
4371 #############################################################################
4372 # LIBRARY FUNCTIONS -   These functions are used in both gtkdoc-mkdb and
4373 #                       gtkdoc-mktmpl and should eventually be moved to a
4374 #                       separate library.
4375 #############################################################################
4377 #############################################################################
4378 # Function    : ReadDeclarationsFile
4379 # Description : This reads in a file containing the function/macro/enum etc.
4380 #               declarations.
4382 #               Note that in some cases there are several declarations with
4383 #               the same name, e.g. for conditional macros. In this case we
4384 #               set a flag in the %DeclarationConditional hash so the
4385 #               declaration is not shown in the docs.
4387 #               If a macro and a function have the same name, e.g. for
4388 #               gtk_object_ref, the function declaration takes precedence.
4390 #               Some opaque structs are just declared with 'typedef struct
4391 #               _name name;' in which case the declaration may be empty.
4392 #               The structure may have been found later in the header, so
4393 #               that overrides the empty declaration.
4395 # Arguments   : $file - the declarations file to read
4396 #               $override - if declarations in this file should override
4397 #                       any current declaration.
4398 #############################################################################
4400 sub ReadDeclarationsFile {
4401     my ($file, $override) = @_;
4403     if ($override == 0) {
4404         %Declarations = ();
4405         %DeclarationTypes = ();
4406         %DeclarationConditional = ();
4407         %DeclarationOutput = ();
4408     }
4410     open (INPUT, $file)
4411         || die "Can't open $file: $!";
4412     my $declaration_type = "";
4413     my $declaration_name;
4414     my $declaration;
4415     my $is_deprecated = 0;
4416     while (<INPUT>) {
4417         if (!$declaration_type) {
4418             if (m/^<([^>]+)>/) {
4419                 $declaration_type = $1;
4420                 $declaration_name = "";
4421                 #print "Found declaration: $declaration_type\n";
4422                 $declaration = "";
4423             }
4424         } else {
4425             if (m%^<NAME>(.*)</NAME>%) {
4426                 $declaration_name = $1;
4427             } elsif (m%^<DEPRECATED/>%) {
4428                 $is_deprecated = 1;
4429             } elsif (m%^</$declaration_type>%) {
4430                 #print "Found end of declaration: $declaration_name\n";
4431                 # Check that the declaration has a name
4432                 if ($declaration_name eq "") {
4433                     print "ERROR: $declaration_type has no name $file:$.\n";
4434                 }
4436                 # If the declaration is an empty typedef struct _XXX XXX
4437                 # set the flag to indicate the struct has a typedef.
4438                 if ($declaration_type eq 'STRUCT'
4439                     && $declaration =~ m/^\s*$/) {
4440                     #print "Struct has typedef: $declaration_name\n";
4441                     $StructHasTypedef{$declaration_name} = 1;
4442                 }
4444                 # Check if the symbol is already defined.
4445                 if (defined ($Declarations{$declaration_name})
4446                     && $override == 0) {
4447                     # Function declarations take precedence.
4448                     if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
4449                         # Ignore it.
4450                     } elsif ($declaration_type eq 'FUNCTION') {
4451                         if ($is_deprecated) {
4452                             $Deprecated{$declaration_name} = "";
4453                         }
4454                         $Declarations{$declaration_name} = $declaration;
4455                         $DeclarationTypes{$declaration_name} = $declaration_type;
4456                     } elsif ($DeclarationTypes{$declaration_name}
4457                               eq $declaration_type) {
4458                         # If the existing declaration is empty, or is just a
4459                         # forward declaration of a struct, override it.
4460                         if ($declaration_type eq 'STRUCT') {
4461                             if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4462                                 if ($is_deprecated) {
4463                                     $Deprecated{$declaration_name} = "";
4464                                 }
4465                                 $Declarations{$declaration_name} = $declaration;
4466                             } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4467                                 # Ignore an empty or forward declaration.
4468                             } else {
4469                                 &LogWarning ($file, $., "Structure $declaration_name has multiple definitions.");
4470                             }
4471                         } else {
4472                             # set flag in %DeclarationConditional hash for
4473                             # multiply defined macros/typedefs.
4474                             $DeclarationConditional{$declaration_name} = 1;
4475                         }
4476                     } else {
4477                         &LogWarning ($file, $., "$declaration_name has multiple definitions.");
4478                     }
4479                 } else {
4480                     if ($is_deprecated) {
4481                         $Deprecated{$declaration_name} = "";
4482                     }
4483                     $Declarations{$declaration_name} = $declaration;
4484                     $DeclarationTypes{$declaration_name} = $declaration_type;
4485                 }
4487                 $declaration_type = "";
4488                 $is_deprecated = 0;
4489             } else {
4490                 $declaration .= $_;
4491             }
4492         }
4493     }
4494     close (INPUT);
4498 #############################################################################
4499 # Function    : ReadSignalsFile
4500 # Description : This reads in an existing file which contains information on
4501 #               all GTK signals. It creates the arrays @SignalNames and
4502 #               @SignalPrototypes containing info on the signals. The first
4503 #               line of the SignalPrototype is the return type of the signal
4504 #               handler. The remaining lines are the parameters passed to it.
4505 #               The last parameter, "gpointer user_data" is always the same
4506 #               so is not included.
4507 # Arguments   : $file - the file containing the signal handler prototype
4508 #                       information.
4509 #############################################################################
4511 sub ReadSignalsFile {
4512     my ($file) = @_;
4514     my $in_signal = 0;
4515     my $signal_object;
4516     my $signal_name;
4517     my $signal_returns;
4518     my $signal_flags;
4519     my $signal_prototype;
4521     # Reset the signal info.
4522     @SignalObjects = ();
4523     @SignalNames = ();
4524     @SignalReturns = ();
4525     @SignalFlags = ();
4526     @SignalPrototypes = ();
4528     if (! -f $file) {
4529         return;
4530     }
4531     if (!open (INPUT, $file)) {
4532         warn "Can't open $file - skipping signals\n";
4533         return;
4534     }
4535     while (<INPUT>) {
4536         if (!$in_signal) {
4537             if (m/^<SIGNAL>/) {
4538                 $in_signal = 1;
4539                 $signal_object = "";
4540                 $signal_name = "";
4541                 $signal_returns = "";
4542                 $signal_prototype = "";
4543             }
4544         } else {
4545             if (m/^<NAME>(.*)<\/NAME>/) {
4546                 $signal_name = $1;
4547                 if ($signal_name =~ m/^(.*)::(.*)$/) {
4548                     $signal_object = $1;
4549                     ($signal_name = $2) =~ s/_/-/g;
4550                     #print "Found signal: $signal_name\n";
4551                 } else {
4552                     &LogWarning ($file, $., "Invalid signal name: $signal_name.");
4553                 }
4554             } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
4555                 $signal_returns = $1;
4556             } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4557                 $signal_flags = $1;
4558             } elsif (m%^</SIGNAL>%) {
4559                 #print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
4560                 push (@SignalObjects, $signal_object);
4561                 push (@SignalNames, $signal_name);
4562                 push (@SignalReturns, $signal_returns);
4563                 push (@SignalFlags, $signal_flags);
4564                 push (@SignalPrototypes, $signal_prototype);
4565                 $in_signal = 0;
4566             } else {
4567                 $signal_prototype .= $_;
4568             }
4569         }
4570     }
4571     close (INPUT);
4575 #############################################################################
4576 # Function    : ReadTemplateFile
4577 # Description : This reads in the manually-edited documentation file
4578 #               corresponding to the file currently being created, so we can
4579 #               insert the documentation at the appropriate places.
4580 #               It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
4581 #               is a hash of arrays.
4582 #               NOTE: This function is duplicated in gtkdoc-mktmpl (but
4583 #               slightly different).
4584 # Arguments   : $docsfile - the template file to read in.
4585 #               $skip_unused_params - 1 if the unused parameters should be
4586 #                       skipped.
4587 #############################################################################
4589 sub ReadTemplateFile {
4590     my ($docsfile, $skip_unused_params) = @_;
4592     my $template = "$docsfile.sgml";
4593     if (! -f $template) {
4594         #print "File doesn't exist: $template\n";
4595         return 0;
4596     }
4597     #print "Reading $template\n";
4599     # start with empty hashes, we merge the source comment for each file
4600     # afterwards
4601     %SymbolDocs = ();
4602     %SymbolTypes = ();
4603     %SymbolParams = ();
4605     my $current_type = "";      # Type of symbol being read.
4606     my $current_symbol = "";    # Name of symbol being read.
4607     my $symbol_doc = "";                # Description of symbol being read.
4608     my @params;                 # Parameter names and descriptions of current
4609                                 #   function/macro/function typedef.
4610     my $current_param = -1;     # Index of parameter currently being read.
4611                                 #   Note that the param array contains pairs
4612                                 #   of param name & description.
4613     my $in_unused_params = 0;   # True if we are reading in the unused params.
4614     my $in_deprecated = 0;
4615     my $in_since = 0;
4616     my $in_stability = 0;
4618     open (DOCS, "$template")
4619         || die "Can't open $template: $!";
4620     while (<DOCS>) {
4621         if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
4622             my $type = $1;
4623             my $symbol = $2;
4624             if ($symbol eq "Title"
4625                 || $symbol eq "Short_Description"
4626                 || $symbol eq "Long_Description"
4627                 || $symbol eq "See_Also"
4628                 || $symbol eq "Stability_Level"
4629                 || $symbol eq "Include") {
4631                 $symbol = $docsfile . ":" . $symbol;
4632             }
4634             #print "Found symbol: $symbol\n";
4635             # Remember file and line for the symbol
4636             $SymbolSourceFile{$symbol} = $template;
4637             $SymbolSourceLine{$symbol} = $.;
4639             # Store previous symbol, but remove any trailing blank lines.
4640             if ($current_symbol ne "") {
4641                 $symbol_doc =~ s/\s+$//;
4642                 $SymbolTypes{$current_symbol} = $current_type;
4643                 $SymbolDocs{$current_symbol} = $symbol_doc;
4645                 # Check that the stability level is valid.
4646                 if ($StabilityLevel{$current_symbol}) {
4647                     $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4648                 }
4650                 if ($current_param >= 0) {
4651                     $SymbolParams{$current_symbol} = [ @params ];
4652                 } else {
4653                     # Delete any existing params in case we are overriding a
4654                     # previously read template.
4655                     delete $SymbolParams{$current_symbol};
4656                 }
4657             }
4658             $current_type = $type;
4659             $current_symbol = $symbol;
4660             $current_param = -1;
4661             $in_unused_params = 0;
4662             $in_deprecated = 0;
4663             $in_since = 0;
4664             $in_stability = 0;
4665             $symbol_doc = "";
4666             @params = ();
4668         } elsif (m/^<!-- # Unused Parameters # -->/) {
4669             #print "DEBUG: Found unused parameters\n";
4670             $in_unused_params = 1;
4671             next;
4673         } elsif ($in_unused_params && $skip_unused_params) {
4674             # When outputting the DocBook we skip unused parameters.
4675             #print "DEBUG: Skipping unused param: $_";
4676             next;
4678         } else {
4679             # Check if param found. Need to handle "..." and "format...".
4680             if (s/^\@([\w\.]+):\040?//) {
4681                 my $param_name = $1;
4682                 my $param_desc = $_;
4683                 # Allow variations of 'Returns'
4684                 if ($param_name =~ m/^[Rr]eturns?$/) {
4685                     $param_name = "Returns";
4686                 }
4688                 # strip trailing whitespaces and blank lines
4689                 s/\s+\n$/\n/m;
4690                 s/\n+$/\n/sm;
4691                 #print "Found param for symbol $current_symbol : '$param_name'= '$_'";
4693                 if ($param_name eq "Deprecated") {
4694                     $in_deprecated = 1;
4695                     $Deprecated{$current_symbol} = $_;
4696                 } elsif ($param_name eq "Since") {
4697                     $in_since = 1;
4698                     chomp;
4699                     $Since{$current_symbol} = $_;
4700                 } elsif ($param_name eq "Stability") {
4701                     $in_stability = 1;
4702                     $StabilityLevel{$current_symbol} = $_;
4703                 } else {
4704                     push (@params, $param_name);
4705                     push (@params, $param_desc);
4706                     $current_param += $PARAM_FIELD_COUNT;
4707                 }
4708             } else {
4709                 # strip trailing whitespaces and blank lines
4710                 s/\s+\n$/\n/m;
4711                 s/\n+$/\n/sm;
4712                 
4713                 if (!m/^\s+$/) {
4714                     if ($in_deprecated) {
4715                         $Deprecated{$current_symbol} .= $_;
4716                     } elsif ($in_since) {
4717                         &LogWarning ($template, $., "multi-line since docs found");
4718                         #$Since{$current_symbol} .= $_;
4719                     } elsif ($in_stability) {
4720                         $StabilityLevel{$current_symbol} .= $_;
4721                     } elsif ($current_param >= 0) {
4722                         $params[$current_param] .= $_;
4723                     } else {
4724                         $symbol_doc .= $_;
4725                     }
4726                 }
4727             }
4728         }
4729     }
4731     # Remember to finish the current symbol doccs.
4732     if ($current_symbol ne "") {
4734         $symbol_doc =~ s/\s+$//;
4735         $SymbolTypes{$current_symbol} = $current_type;
4736         $SymbolDocs{$current_symbol} = $symbol_doc;
4738         # Check that the stability level is valid.
4739         if ($StabilityLevel{$current_symbol}) {
4740             $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4741         }
4743         if ($current_param >= 0) {
4744             $SymbolParams{$current_symbol} = [ @params ];
4745         } else {
4746             # Delete any existing params in case we are overriding a
4747             # previously read template.
4748             delete $SymbolParams{$current_symbol};
4749         }
4750     }
4752     close (DOCS);
4753     return 1;
4757 #############################################################################
4758 # Function    : ReadObjectHierarchy
4759 # Description : This reads in the $MODULE-hierarchy.txt file containing all
4760 #               the GtkObject subclasses described in this module (and their
4761 #               ancestors).
4762 #               It places them in the @Objects array, and places their level
4763 #               in the widget hierarchy in the @ObjectLevels array, at the
4764 #               same index. GtkObject, the root object, has a level of 1.
4766 #               FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
4767 #               as it goes along, this should be split out into a separate
4768 #               function.
4770 # Arguments   : none
4771 #############################################################################
4773 sub ReadObjectHierarchy {
4774     @Objects = ();
4775     @ObjectLevels = ();
4777     if (! -f $OBJECT_TREE_FILE) {
4778         return;
4779     }
4780     if (!open (INPUT, $OBJECT_TREE_FILE)) {
4781         warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
4782         return;
4783     }
4785     # FIXME: use $OUTPUT_FORMAT
4786     # my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.$OUTPUT_FORMAT";
4787     my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
4788     my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
4790     open (OUTPUT, ">$new_tree_index")
4791         || die "Can't create $new_tree_index: $!";
4793     if (lc($OUTPUT_FORMAT) eq "xml") {
4794         my $tree_header = $doctype_header;
4796         $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
4797         print (OUTPUT "$tree_header");
4798     }
4799     print (OUTPUT "<screen>\n");
4801     # Only emit objects if they are supposed to be documented, or if
4802     # they have documented children. To implement this, we maintain a
4803     # stack of pending objects which will be emitted if a documented
4804     # child turns up.
4805     my @pending_objects = ();
4806     my @pending_levels = ();
4807     while (<INPUT>) {
4808         if (m/\S+/) {
4809             my $object = $&;
4810             my $level = (length($`)) / 2 + 1;
4811             my $xref = "";
4813             while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
4814                 my $pobject = pop(@pending_objects);
4815                 my $plevel = pop(@pending_levels);
4816             }
4818             push (@pending_objects, $object);
4819             push (@pending_levels, $level);
4821             if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
4822                 while ($#pending_levels >= 0) {
4823                     $object = shift @pending_objects;
4824                     $level = shift @pending_levels;
4825                     $xref = &MakeXRef ($object);
4827                     print (OUTPUT ' ' x ($level * 4), "$xref\n");
4828                     push (@Objects, $object);
4829                     push (@ObjectLevels, $level);
4830                 }
4831             }
4832             #else {
4833             #    LogWarning ($OBJECT_TREE_FILE, $., "unknown type $object");
4834             #}
4835         }
4836     }
4837     print (OUTPUT "</screen>\n");
4839     close (INPUT);
4840     close (OUTPUT);
4842     &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
4844     &OutputObjectList;
4847 #############################################################################
4848 # Function    : ReadInterfaces
4849 # Description : This reads in the $MODULE.interfaces file.
4851 # Arguments   : none
4852 #############################################################################
4854 sub ReadInterfaces {
4855     %Interfaces = ();
4857     if (! -f $INTERFACES_FILE) {
4858         return;
4859     }
4860     if (!open (INPUT, $INTERFACES_FILE)) {
4861         warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
4862         return;
4863     }
4865     while (<INPUT>) {
4866        chomp;
4867        my ($object, @ifaces) = split;
4868        if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
4869            my @knownIfaces = ();
4871            # filter out private interfaces, but leave foreign interfaces
4872            foreach my $iface (@ifaces) {
4873                if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
4874                    push (@knownIfaces, $iface);
4875                }
4876              }
4878            $Interfaces{$object} = join(' ', @knownIfaces);
4879        }
4880     }
4881     close (INPUT);
4884 #############################################################################
4885 # Function    : ReadPrerequisites
4886 # Description : This reads in the $MODULE.prerequisites file.
4888 # Arguments   : none
4889 #############################################################################
4891 sub ReadPrerequisites {
4892     %Prerequisites = ();
4894     if (! -f $PREREQUISITES_FILE) {
4895         return;
4896     }
4897     if (!open (INPUT, $PREREQUISITES_FILE)) {
4898         warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
4899         return;
4900     }
4902     while (<INPUT>) {
4903        chomp;
4904        my ($iface, @prereqs) = split;
4905        if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
4906            my @knownPrereqs = ();
4908            # filter out private prerequisites, but leave foreign prerequisites
4909            foreach my $prereq (@prereqs) {
4910                if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
4911                   push (@knownPrereqs, $prereq);
4912                }
4913            }
4915            $Prerequisites{$iface} = join(' ', @knownPrereqs);
4916        }
4917     }
4918     close (INPUT);
4921 #############################################################################
4922 # Function    : ReadArgsFile
4923 # Description : This reads in an existing file which contains information on
4924 #               all GTK args. It creates the arrays @ArgObjects, @ArgNames,
4925 #               @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
4926 #               on the args.
4927 # Arguments   : $file - the file containing the arg information.
4928 #############################################################################
4930 sub ReadArgsFile {
4931     my ($file) = @_;
4933     my $in_arg = 0;
4934     my $arg_object;
4935     my $arg_name;
4936     my $arg_type;
4937     my $arg_flags;
4938     my $arg_nick;
4939     my $arg_blurb;
4940     my $arg_default;
4941     my $arg_range;
4943     # Reset the args info.
4944     @ArgObjects = ();
4945     @ArgNames = ();
4946     @ArgTypes = ();
4947     @ArgFlags = ();
4948     @ArgNicks = ();
4949     @ArgBlurbs = ();
4950     @ArgDefaults = ();
4951     @ArgRanges = ();
4953     if (! -f $file) {
4954         return;
4955     }
4956     if (!open (INPUT, $file)) {
4957         warn "Can't open $file - skipping args\n";
4958         return;
4959     }
4960     while (<INPUT>) {
4961         if (!$in_arg) {
4962             if (m/^<ARG>/) {
4963                 $in_arg = 1;
4964                 $arg_object = "";
4965                 $arg_name = "";
4966                 $arg_type = "";
4967                 $arg_flags = "";
4968                 $arg_nick = "";
4969                 $arg_blurb = "";
4970                 $arg_default = "";
4971                 $arg_range = "";
4972             }
4973         } else {
4974             if (m/^<NAME>(.*)<\/NAME>/) {
4975                 $arg_name = $1;
4976                 if ($arg_name =~ m/^(.*)::(.*)$/) {
4977                     $arg_object = $1;
4978                     ($arg_name = $2) =~ s/_/-/g;
4979                     #print "Found arg: $arg_name\n";
4980                 } else {
4981                     &LogWarning ($file, $., "Invalid argument name: $arg_name");
4982                 }
4983             } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
4984                 $arg_type = $1;
4985             } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
4986                 $arg_range = $1;
4987             } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4988                 $arg_flags = $1;
4989             } elsif (m/^<NICK>(.*)<\/NICK>/) {
4990                 $arg_nick = $1;
4991             } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
4992                 $arg_blurb = $1;
4993                 if ($arg_blurb eq "(null)") {
4994                   $arg_blurb = "";
4995                   &LogWarning ($file, $., "Property ${arg_object}:${arg_name} has no documentation.");
4996                 }
4997             } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
4998                 $arg_default = $1;
4999             } elsif (m%^</ARG>%) {
5000                 #print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
5001                 push (@ArgObjects, $arg_object);
5002                 push (@ArgNames, $arg_name);
5003                 push (@ArgTypes, $arg_type);
5004                 push (@ArgRanges, $arg_range);
5005                 push (@ArgFlags, $arg_flags);
5006                 push (@ArgNicks, $arg_nick);
5007                 push (@ArgBlurbs, $arg_blurb);
5008                 push (@ArgDefaults, $arg_default);
5009                 $in_arg = 0;
5010             }
5011         }
5012     }
5013     close (INPUT);
5017 #############################################################################
5018 # Function    : CheckIsObject
5019 # Description : Returns 1 if the given name is a GObject or a subclass.
5020 #               It uses the global @Objects array.
5021 #               Note that the @Objects array only contains classes in the
5022 #               current module and their ancestors - not all GObject classes.
5023 # Arguments   : $name - the name to check.
5024 #############################################################################
5026 sub CheckIsObject {
5027     my ($name) = @_;
5029     my $object;
5030     foreach $object (@Objects) {
5031         if ($object eq $name) {
5032             return 1;
5033         }
5034     }
5035     return 0;
5039 #############################################################################
5040 # Function    : MakeReturnField
5041 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
5042 # Arguments   : $str - the string to pad.
5043 #############################################################################
5045 sub MakeReturnField {
5046     my ($str) = @_;
5048     return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));
5051 #############################################################################
5052 # Function    : GetSymbolSourceFile
5053 # Description : Get the filename where the symbol docs where taken from.
5054 # Arguments   : $symbol - the symbol name
5055 #############################################################################
5057 sub GetSymbolSourceFile {
5058     my ($symbol) = @_;
5060     if (defined($SourceSymbolSourceFile{$symbol})) {
5061         return $SourceSymbolSourceFile{$symbol};
5062     } elsif (defined($SymbolSourceFile{$symbol})) {
5063         return $SymbolSourceFile{$symbol};
5064     } else {
5065         return "";
5066     }
5069 #############################################################################
5070 # Function    : GetSymbolSourceLine
5071 # Description : Get the file line where the symbol docs where taken from.
5072 # Arguments   : $symbol - the symbol name
5073 #############################################################################
5075 sub GetSymbolSourceLine {
5076     my ($symbol) = @_;
5078     if (defined($SourceSymbolSourceLine{$symbol})) {
5079         return $SourceSymbolSourceLine{$symbol};
5080     } elsif (defined($SymbolSourceLine{$symbol})) {
5081         return $SymbolSourceLine{$symbol};
5082     } else {
5083         return 0;
5084     }