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