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