release: update news and date in manual
[gtk-doc.git] / gtkdoc-mkdb.in
blobf9e4b9dc3563bf614c86a9c51e87c2b0fbe0503b
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 $INLINE_MARKUP_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' => \$INLINE_MARKUP_MODE,
66               'xml-mode' => \$INLINE_MARKUP_MODE,
67               'default-stability' => \$DEFAULT_STABILITY,
68               'default-includes' => \$DEFAULT_INCLUDES,
69               'output-format' => \$OUTPUT_FORMAT,
70               'name-space' => \$NAME_SPACE,
71               'outputallsymbols' => \$OUTPUT_ALL_SYMBOLS,
72               'outputsymbolswithoutsince' => \$OUTPUT_SYMBOLS_WITHOUT_SINCE
73               );
74 GetOptions(\%optctl, "module=s", "source-dir:s", "source-suffixes:s", 
75     "ignore-files:s", "output-dir:s", "tmpl-dir:s", "version", "outputallsymbols",
76     "outputsymbolswithoutsince",
77     "expand-content-files:s", "main-sgml-file:s", "extra-db-files:s", "help",
78     "sgml-mode", "xml-mode", "default-stability:s", "default-includes:s", 
79     "output-format:s", "name-space:s");
81 if ($PRINT_VERSION) {
82     print "@VERSION@\n";
83     exit 0;
86 if (!$MODULE) {
87     $PRINT_HELP = 1;
90 if ($DEFAULT_STABILITY && $DEFAULT_STABILITY ne "Stable"
91     && $DEFAULT_STABILITY ne "Private" && $DEFAULT_STABILITY ne "Unstable") {
92     $PRINT_HELP = 1;
95 if ($PRINT_HELP) {
96     print <<EOF;
97 gtkdoc-mkdb version @VERSION@ - generate docbook files
99 --module=MODULE_NAME       Name of the doc module being parsed
100 --source-dir=DIRNAME       Directories which contain inline reference material
101 --source-suffixes=SUFFIXES Suffixes of source files to scan, comma-separated
102 --ignore-files=FILES       Files or directories which should not be scanned
103                            May be used more than once for multiple directories
104 --output-dir=DIRNAME       Directory to put the generated DocBook files in
105 --tmpl-dir=DIRNAME         Directory in which template files may be found
106 --main-sgml-file=FILE      File containing the toplevel DocBook file.
107 --expand-content-files=FILES Extra DocBook files to expand abbreviations in.
108 --output-format=FORMAT     Format to use for the generated docbook, XML or SGML.
109 --{xml,sgml}-mode          Allow DocBook markup in inline documentation.
110 --default-stability=LEVEL  Specify default stability Level. Valid values are
111                            Stable, Unstable, or Private.
112 --default-includes=FILENAMES Specify default includes for section Synopsis
113 --name-space=NS            Omit namespace in index.
114 --version                  Print the version of this program
115 --help                     Print this help
117     exit 0;
120 my ($empty_element_end, $doctype_header);
122 # autodetect output format
123 if (! defined($OUTPUT_FORMAT) || ($OUTPUT_FORMAT eq "")) {
124     if (!$MAIN_SGML_FILE) {
125         if (-e "${MODULE}-docs.xml") {
126             $OUTPUT_FORMAT = "xml";
127         } else {
128             $OUTPUT_FORMAT = "sgml";
129         }
130     } else {
131         if ($MAIN_SGML_FILE =~ m/.*\.(.*ml)$/i) {
132             $OUTPUT_FORMAT = lc($1);
133         }
134     }
135     
136 } else {
137     $OUTPUT_FORMAT = lc($OUTPUT_FORMAT);
140 #print "DEBUG: output-format: [$OUTPUT_FORMAT]\n";
142 if ($OUTPUT_FORMAT eq "xml") {
143     if (!$MAIN_SGML_FILE) {
144         # backwards compatibility
145         if (-e "${MODULE}-docs.sgml") {
146             $MAIN_SGML_FILE = "${MODULE}-docs.sgml";
147         } else {
148             $MAIN_SGML_FILE = "${MODULE}-docs.xml";
149         }
150     }
151     $empty_element_end = "/>";
153     if (-e $MAIN_SGML_FILE) {
154         open(INPUT, "<$MAIN_SGML_FILE") || die "Can't open $MAIN_SGML_FILE";
155         $doctype_header = "";
156         while (<INPUT>) {
157             if (/^\s*<(book|chapter|article)/) {
158                 # check that the top-level tag or the doctype decl contain the xinclude namespace decl
159                 if (($_ !~ m/http:\/\/www.w3.org\/200[13]\/XInclude/) && ($doctype_header !~ m/http:\/\/www.w3.org\/200[13]\/XInclude/m)) {
160                     $doctype_header = "";
161                 }
162                 last;
163             }
164             $doctype_header .= $_;
165         }
166         close(INPUT);
167         $doctype_header =~ s/<!DOCTYPE \w+/<!DOCTYPE refentry/;
168         # if there are SYSTEM ENTITIES here, we should prepend "../" to the path
169         # FIXME: not sure if we can do this now, as people already work-around the problem
170         # $doctype_header =~ s#<!ENTITY % ([a-zA-Z-]+) SYSTEM \"([^/][a-zA-Z./]+)\">#<!ENTITY % $1 SYSTEM \"../$2\">#g;
171     } else {
172         $doctype_header =
173 "<?xml version=\"1.0\"?>\n" .
174 "<!DOCTYPE refentry PUBLIC \"-//OASIS//DTD DocBook XML V4.3//EN\"\n" .
175 "               \"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd\"\n" .
176 "[\n" .
177 "  <!ENTITY % local.common.attrib \"xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'\">\n" .
178 "]>\n";
179     }
180 } else {
181     if (!$MAIN_SGML_FILE) {
182         $MAIN_SGML_FILE = "${MODULE}-docs.sgml";
183     }
184     $empty_element_end = ">";
185     $doctype_header = "";
188 my $ROOT_DIR = ".";
190 # All the files are written in subdirectories beneath here.
191 $TMPL_DIR = $TMPL_DIR ? $TMPL_DIR : "$ROOT_DIR/tmpl";
193 # This is where we put all the DocBook output.
194 $SGML_OUTPUT_DIR = $SGML_OUTPUT_DIR ? $SGML_OUTPUT_DIR : "$ROOT_DIR/$OUTPUT_FORMAT";
196 # This file contains the object hierarchy.
197 my $OBJECT_TREE_FILE = "$ROOT_DIR/$MODULE.hierarchy";
199 # This file contains the interfaces.
200 my $INTERFACES_FILE = "$ROOT_DIR/$MODULE.interfaces";
202 # This file contains the prerequisites.
203 my $PREREQUISITES_FILE = "$ROOT_DIR/$MODULE.prerequisites";
205 # This file contains signal arguments and names.
206 my $SIGNALS_FILE = "$ROOT_DIR/$MODULE.signals";
208 # The file containing Arg information.
209 my $ARGS_FILE = "$ROOT_DIR/$MODULE.args";
211 # These global arrays store information on signals. Each signal has an entry
212 # in each of these arrays at the same index, like a multi-dimensional array.
213 my @SignalObjects;      # The GtkObject which emits the signal.
214 my @SignalNames;        # The signal name.
215 my @SignalReturns;      # The return type.
216 my @SignalFlags;        # Flags for the signal
217 my @SignalPrototypes;   # The rest of the prototype of the signal handler.
219 # These global arrays store information on Args. Each Arg has an entry
220 # in each of these arrays at the same index, like a multi-dimensional array.
221 my @ArgObjects;         # The GtkObject which has the Arg.
222 my @ArgNames;           # The Arg name.
223 my @ArgTypes;           # The Arg type - gint, GtkArrowType etc.
224 my @ArgFlags;           # How the Arg can be used - readable/writable etc.
225 my @ArgNicks;           # The nickname of the Arg.
226 my @ArgBlurbs;          # Docstring of the Arg.
227 my @ArgDefaults;        # Default value of the Arg.
228 my @ArgRanges;          # The range of the Arg type
229 # These global hashes store declaration info keyed on a symbol name.
230 my %Declarations;
231 my %DeclarationTypes;
232 my %DeclarationConditional;
233 my %DeclarationOutput;
234 my %Deprecated;
235 my %Since;
236 my %StabilityLevel;
237 my %StructHasTypedef;
239 # These global hashes store the existing documentation.
240 my %SymbolDocs;
241 my %SymbolTypes;
242 my %SymbolParams;
243 my %SymbolSourceFile;
244 my %SymbolSourceLine;
246 # These global hashes store documentation scanned from the source files.
247 my %SourceSymbolDocs;
248 my %SourceSymbolParams;
249 my %SourceSymbolSourceFile;
250 my %SourceSymbolSourceLine;
252 # all documentation goes in here, so we can do coverage analysis
253 my %AllSymbols;
254 my %AllIncompleteSymbols;
255 my %AllUnusedSymbols;
256 my %AllDocumentedSymbols;
258 # Undeclared yet documented symbols
259 my %UndeclaredSymbols;
261 # These global arrays store GObject, subclasses and the hierarchy.
262 my @Objects;
263 my @ObjectLevels;
265 my %Interfaces;
266 my %Prerequisites;
268 # holds the symbols which are mentioned in $MODULE-sections.txt and in which
269 # section they are defined
270 my %KnownSymbols;
271 my %SymbolSection;
272 my %SymbolSectionId;
274 # collects index entries
275 my %IndexEntriesFull;
276 my %IndexEntriesSince;
277 my %IndexEntriesDeprecated;
279 # Standard C preprocessor directives, which we ignore for '#' abbreviations.
280 my %PreProcessorDirectives;
281 $PreProcessorDirectives{"assert"} = 1;
282 $PreProcessorDirectives{"define"} = 1;
283 $PreProcessorDirectives{"elif"} = 1;
284 $PreProcessorDirectives{"else"} = 1;
285 $PreProcessorDirectives{"endif"} = 1;
286 $PreProcessorDirectives{"error"} = 1;
287 $PreProcessorDirectives{"if"} = 1;
288 $PreProcessorDirectives{"ifdef"} = 1;
289 $PreProcessorDirectives{"ifndef"} = 1;
290 $PreProcessorDirectives{"include"} = 1;
291 $PreProcessorDirectives{"line"} = 1;
292 $PreProcessorDirectives{"pragma"} = 1;
293 $PreProcessorDirectives{"unassert"} = 1;
294 $PreProcessorDirectives{"undef"} = 1;
295 $PreProcessorDirectives{"warning"} = 1;
297 # remember used annotation (to write minimal glossary)
298 my %AnnotationsUsed;
300 # the annotations are defined at:
301 # http://live.gnome.org/GObjectIntrospection/Annotations
302 my %AnnotationDefinition = (
303     'allow-none' => "NULL is ok, both for passing and for returning.",
304     'array' => "Parameter points to an array of items.",
305     'closure' => "This parameter is a 'user_data', for callbacks; many bindings can pass NULL here.",
306     'default' => "Default parameter value (for in case the <acronym>shadows</acronym>-to function has less parameters).",
307     'element-type' => "Generics and defining elements of containers and arrays.",
308     'error-domains' => "Typed errors. Similar to throws in Java.",
309     'in' => "Parameter for input. Default is <acronym>transfer none</acronym>.",
310     'inout' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
311     'in-out' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
312     'not-error' => "A GError parameter is not to be handled like a normal GError.",
313     'out' => "Parameter for returning results. Default is <acronym>transfer full</acronym>.",
314     'transfer container' => "Free data container after the code is done.",
315     'transfer full' => "Free data after the code is done.",
316     'transfer none' => "Don't free data after the code is done.",
317     'scope call' => "The callback is valid only during the call to the method.",
318     'scope async' => "The callback is valid until first called.",
319     'scope notified' => "The callback is valid until the GDestroyNotify argument is called.",
320     'type' => "Override the parsed C type with given type"
323 # Create the root DocBook output directory if it doens't exist.
324 if (! -e $SGML_OUTPUT_DIR) {
325     mkdir ("$SGML_OUTPUT_DIR", 0777)
326         || die "Can't create directory: $SGML_OUTPUT_DIR";
329 # Function and other declaration output settings.
330 my $RETURN_TYPE_FIELD_WIDTH = 20;
331 my $SYMBOL_FIELD_WIDTH = 36;
332 my $SIGNAL_FIELD_WIDTH = 16;
333 my $PARAM_FIELD_COUNT = 2;
335 &ReadKnownSymbols ("$ROOT_DIR/$MODULE-sections.txt");
336 &ReadSignalsFile ($SIGNALS_FILE);
337 &ReadArgsFile ($ARGS_FILE);
338 &ReadObjectHierarchy;
339 &ReadInterfaces;
340 &ReadPrerequisites;
342 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-decl.txt", 0);
343 if (-f "$ROOT_DIR/$MODULE-overrides.txt") {
344     &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-overrides.txt", 1);
347 for my $dir (@SOURCE_DIRS) {
348     &ReadSourceDocumentation ($dir);
351 my $changed = &OutputSGML ("$ROOT_DIR/$MODULE-sections.txt");
353 # If any of the DocBook SGML files have changed, update the timestamp file (so
354 # it can be used for Makefile dependencies).
355 if ($changed || ! -e "$ROOT_DIR/sgml.stamp") {
357     # try to detect the common prefix
358     # GtkWidget, GTK_WIDGET, gtk_widget -> gtk
359     if ($NAME_SPACE eq "") {
360         $NAME_SPACE="";
361         my $pos=0;
362         my $ratio=0.0;
363         do {
364             my %prefix;
365             my $letter="";
366             foreach my $symbol (keys(%IndexEntriesFull)) {
367                 if(($NAME_SPACE eq "") || $symbol =~ /^$NAME_SPACE/i) {
368                     if (length($symbol)>$pos) {
369                         $letter=substr($symbol,$pos,1);
370                         # stop prefix scanning
371                         if ($letter eq "_") {
372                             # stop on "_"
373                             last;
374                         }
375                         # Should we also stop on a uppercase char, if last was lowercase
376                         #   GtkWidget, if we have the 'W' and had the 't' before
377                         # or should we count upper and lowercase, and stop one 2nd uppercase, if we already had a lowercase
378                         #   GtkWidget, the 'W' would be the 2nd uppercase and with 't','k' we had lowercase chars before
379                         # need to recound each time as this is per symbol
380                         $prefix{uc($letter)}++;
381                     }
382                 }
383             }
384             if ($letter ne "" && $letter ne "_") {
385                 my $maxletter="";
386                 my $maxsymbols=0;
387                 foreach $letter (keys(%prefix)) {
388                     #print "$letter: $prefix{$letter}.\n";
389                     if ($prefix{$letter}>$maxsymbols) {
390                         $maxletter=$letter;
391                         $maxsymbols=$prefix{$letter};
392                     }
393                 }
394                 $ratio = scalar(keys(%IndexEntriesFull)) / $prefix{$maxletter};
395                 #print "most symbols start with $maxletter, that is ". (100 * $ratio) ." %\n";
396                 if ($ratio > 0.9) {
397                     # do another round
398                     $NAME_SPACE .= $maxletter;
399                 }
400                 $pos++;
401             }
402             else {
403                 $ratio=0.0;
404             }
405         } while ($ratio > 0.9);
406         #print "most symbols start with $NAME_SPACE\n";
407     }
409     &OutputIndexFull;
410     &OutputDeprecatedIndex;
411     &OutputSinceIndexes;
412     &OutputAnnotationGlossary;
414     open (TIMESTAMP, ">$ROOT_DIR/sgml.stamp")
415         || die "Can't create $ROOT_DIR/sgml.stamp: $!";
416     print (TIMESTAMP "timestamp");
417     close (TIMESTAMP);
420 #############################################################################
421 # Function    : OutputObjectList
422 # Description : This outputs the alphabetical list of objects, in a columned
423 #               table.
424 #               FIXME: Currently this also outputs ancestor objects
425 #               which may not actually be in this module.
426 # Arguments   : none
427 #############################################################################
429 sub OutputObjectList {
430     my $cols = 3;
431     
432     # FIXME: use $OUTPUT_FORMAT
433     # my $old_object_index = "$SGML_OUTPUT_DIR/object_index.$OUTPUT_FORMAT";
434     my $old_object_index = "$SGML_OUTPUT_DIR/object_index.sgml";
435     my $new_object_index = "$SGML_OUTPUT_DIR/object_index.new";
437     open (OUTPUT, ">$new_object_index")
438         || die "Can't create $new_object_index: $!";
440     if ($OUTPUT_FORMAT eq "xml") {
441         my $header = $doctype_header;
443         $header =~ s/<!DOCTYPE \w+/<!DOCTYPE informaltable/;
444         print (OUTPUT "$header");
445     }
447     print (OUTPUT <<EOF);
448 <informaltable pgwide="1" frame="none">
449 <tgroup cols="$cols">
450 <colspec colwidth="1*"${empty_element_end}
451 <colspec colwidth="1*"${empty_element_end}
452 <colspec colwidth="1*"${empty_element_end}
453 <tbody>
456     my $count = 0;
457     my $object;
458     foreach $object (sort (@Objects)) {
459         my $xref = &MakeXRef ($object);
460         if ($count % $cols == 0) { print (OUTPUT "<row>\n"); }
461         print (OUTPUT "<entry>$xref</entry>\n");
462         if ($count % $cols == ($cols - 1)) { print (OUTPUT "</row>\n"); }
463         $count++;
464     }
465     if ($count == 0) {
466         # emit an empty row, since empty tables are invalid
467         print (OUTPUT "<row><entry> </entry></row>\n");
468     }
469     else {
470         if ($count % $cols > 0) {
471             print (OUTPUT "</row>\n");
472         }
473     }
475     print (OUTPUT <<EOF);
476 </tbody></tgroup></informaltable>
478     close (OUTPUT);
480     &UpdateFileIfChanged ($old_object_index, $new_object_index, 0);
484 #############################################################################
485 # Function    : OutputSGML
486 # Description : This collects the output for each section of the docs, and
487 #               outputs each file when the end of the section is found.
488 # Arguments   : $file - the $MODULE-sections.txt file which contains all of
489 #               the functions/macros/structs etc. being documented, organised
490 #               into sections and subsections.
491 #############################################################################
493 sub OutputSGML {
494     my ($file) = @_;
496     #print "Reading: $file\n";
497     open (INPUT, $file)
498         || die "Can't open $file: $!";
499     my $filename = "";
500     my $book_top = "";
501     my $book_bottom = "";
502     my $includes = (defined $DEFAULT_INCLUDES) ? $DEFAULT_INCLUDES : "";
503     my $section_includes = "";
504     my $in_section = 0;
505     my $title = "";
506     my $section_id = "";
507     my $subsection = "";
508     my $synopsis;
509     my $details;
510     my $num_symbols;
511     my $changed = 0;
512     my $signals_synop = "";
513     my $signals_desc = "";
514     my $args_synop = "";
515     my $child_args_synop = "";
516     my $style_args_synop = "";
517     my $args_desc = "";
518     my $child_args_desc = "";
519     my $style_args_desc = "";
520     my $hierarchy = "";
521     my $interfaces = "";
522     my $implementations = "";
523     my $prerequisites = "";
524     my $derived = "";
525     my @file_objects = ();
526     my %templates = ();
527     my %symbol_def_line = ();
529     # merge the source docs, in case there are no templates
530     &MergeSourceDocumentation;
532     while (<INPUT>) {
533         if (m/^#/) {
534             next;
536         } elsif (m/^<SECTION>/) {
537             $synopsis = "";
538             $details = "";
539             $num_symbols = 0;
540             $in_section = 1;
541             @file_objects = ();
542             %symbol_def_line = ();
544         } elsif (m/^<SUBSECTION\s*(.*)>/i) {
545             $synopsis .= "\n";
546             $subsection = $1;
548         } elsif (m/^<SUBSECTION>/) {
550         } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
551             $title = $1;
552             #print "Section: $title\n";
554             # We don't want warnings if object & class structs aren't used.
555             $DeclarationOutput{$title} = 1;
556             $DeclarationOutput{"${title}Class"} = 1;
557             $DeclarationOutput{"${title}Iface"} = 1;
558             $DeclarationOutput{"${title}Interface"} = 1;
560         } elsif (m/^<FILE>(.*)<\/FILE>/) {
561             $filename = $1;
562             if (! defined $templates{$filename}) {
563                if (&ReadTemplateFile ("$TMPL_DIR/$filename", 1)) {
564                    &MergeSourceDocumentation;
565                    $templates{$filename}=$.;
566                }
567             } else {
568                 &LogWarning ($file, $., "Double <FILE>$filename</FILE> entry. ".
569                     "Previous occurrence on line ".$templates{$filename}.".");
570             }
571             if (($title eq "") and (defined $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"})) {
572                 $title = $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"};
573                 # Remove trailing blanks
574                 $title =~ s/\s+$//;
575            }
577         } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
578             if ($in_section) {
579                 $section_includes = $1;
580             } else {
581                 if (defined $DEFAULT_INCLUDES) {
582                     &LogWarning ($file, $., "Default <INCLUDE> being overridden by command line option.");
583                 }
584                 else {
585                     $includes = $1;
586                 }
587             }
589         } elsif (m/^<\/SECTION>/) {
590             #print "End of section: $title\n";
591             if ($num_symbols > 0) {
592                 # collect documents
593                 if ($OUTPUT_FORMAT eq "xml") {
594                     $book_bottom .= "    <xi:include href=\"xml/$filename.xml\"/>\n";
595                 } else {
596                     $book_top.="<!ENTITY $section_id SYSTEM \"sgml/$filename.sgml\">\n";
597                     $book_bottom .= "    &$section_id;\n";
598                 }
600                 if (defined ($SourceSymbolDocs{"$TMPL_DIR/$filename:Include"})) {
601                     if ($section_includes) {
602                         &LogWarning ($file, $., "Section <INCLUDE> being overridden by inline comments.");
603                     }
604                     $section_includes = $SourceSymbolDocs{"$TMPL_DIR/$filename:Include"};
605                 }
606                 if ($section_includes eq "") {
607                     $section_includes = $includes;
608                 }
610                  $signals_synop =~ s/^\n*//g;
611                  $signals_synop =~ s/\n+$/\n/g;
612                 if ($signals_synop ne '') {
613                     $signals_synop = <<EOF;
614 <refsect1 id="$section_id.signals" role="signal_proto">
615 <title role="signal_proto.title">Signals</title>
616 <synopsis>
617 ${signals_synop}</synopsis>
618 </refsect1>
620                      $signals_desc =~ s/^\n*//g;
621                      $signals_desc =~ s/\n+$/\n/g;
622                      $signals_desc =~ s/(\s|\n)+$//ms;
623                     $signals_desc  = <<EOF;
624 <refsect1 id="$section_id.signal-details" role="signals">
625 <title role="signals.title">Signal Details</title>
626 $signals_desc
627 </refsect1>
629                 }
631                  $args_synop =~ s/^\n*//g;
632                  $args_synop =~ s/\n+$/\n/g;
633                 if ($args_synop ne '') {
634                     $args_synop = <<EOF;
635 <refsect1 id="$section_id.properties" role="properties">
636 <title role="properties.title">Properties</title>
637 <synopsis>
638 ${args_synop}</synopsis>
639 </refsect1>
641                      $args_desc =~ s/^\n*//g;
642                      $args_desc =~ s/\n+$/\n/g;
643                      $args_desc =~ s/(\s|\n)+$//ms;
644                     $args_desc  = <<EOF;
645 <refsect1 id="$section_id.property-details" role="property_details">
646 <title role="property_details.title">Property Details</title>
647 $args_desc
648 </refsect1>
650                 }
652                  $child_args_synop =~ s/^\n*//g;
653                  $child_args_synop =~ s/\n+$/\n/g;
654                 if ($child_args_synop ne '') {
655                     $args_synop .= <<EOF;
656 <refsect1 id="$section_id.child-properties" role="child_properties">
657 <title role="child_properties.title">Child Properties</title>
658 <synopsis>
659 ${child_args_synop}</synopsis>
660 </refsect1>
662                      $child_args_desc =~ s/^\n*//g;
663                      $child_args_desc =~ s/\n+$/\n/g;
664                      $child_args_desc =~ s/(\s|\n)+$//ms;
665                     $args_desc .= <<EOF;
666 <refsect1 id="$section_id.child-property-details" role="child_property_details">
667 <title role="child_property_details.title">Child Property Details</title>
668 $child_args_desc
669 </refsect1>
671                 }
673                  $style_args_synop =~ s/^\n*//g;
674                  $style_args_synop =~ s/\n+$/\n/g;
675                 if ($style_args_synop ne '') {
676                     $args_synop .= <<EOF;
677 <refsect1 id="$section_id.style-properties" role="style_properties">
678 <title role="style_properties.title">Style Properties</title>
679 <synopsis>
680 ${style_args_synop}</synopsis>
681 </refsect1>
683                      $style_args_desc =~ s/^\n*//g;
684                      $style_args_desc =~ s/\n+$/\n/g;
685                      $style_args_desc =~ s/(\s|\n)+$//ms;
686                     $args_desc .= <<EOF;
687 <refsect1 id="$section_id.style-property-details" role="style_properties_details">
688 <title role="style_properties_details.title">Style Property Details</title>
689 $style_args_desc
690 </refsect1>
692                 }
694                  $hierarchy =~ s/^\n*//g;
695                  $hierarchy =~ s/\n+$/\n/g;
696                  $hierarchy =~ s/(\s|\n)+$//ms;
697                 if ($hierarchy ne "") {
698                     $hierarchy = <<EOF;
699 <refsect1 id="$section_id.object-hierarchy" role="object_hierarchy">
700 <title role="object_hierarchy.title">Object Hierarchy</title>
701 $hierarchy
702 </refsect1>
704                 }
706                  $interfaces =~ s/^\n*//g;
707                  $interfaces =~ s/\n+$/\n/g;
708                  $interfaces =~ s/(\s|\n)+$//ms;
709                 if ($interfaces ne "") {
710                     $interfaces = <<EOF;
711 <refsect1 id="$section_id.implemented-interfaces" role="impl_interfaces">
712 <title role="impl_interfaces.title">Implemented Interfaces</title>
713 $interfaces
714 </refsect1>
716                 }
718                  $implementations =~ s/^\n*//g;
719                  $implementations =~ s/\n+$/\n/g;
720                  $implementations =~ s/(\s|\n)+$//ms;
721                 if ($implementations ne "") {
722                     $implementations = <<EOF;
723 <refsect1 id="$section_id.implementations" role="implementations">
724 <title role="implementations.title">Known Implementations</title>
725 $implementations
726 </refsect1>
728                 }
730                  $prerequisites =~ s/^\n*//g;
731                  $prerequisites =~ s/\n+$/\n/g;
732                  $prerequisites =~ s/(\s|\n)+$//ms;
733                 if ($prerequisites ne "") {
734                     $prerequisites = <<EOF;
735 <refsect1 id="$section_id.prerequisites" role="prerequisites">
736 <title role="prerequisites.title">Prerequisites</title>
737 $prerequisites
738 </refsect1>
740                 }
742                  $derived =~ s/^\n*//g;
743                  $derived =~ s/\n+$/\n/g;
744                  $derived =~ s/(\s|\n)+$//ms;
745                 if ($derived ne "") {
746                     $derived = <<EOF;
747 <refsect1 id="$section_id.derived-interfaces" role="derived_interfaces">
748 <title role="derived_interfaces.title">Known Derived Interfaces</title>
749 $derived
750 </refsect1>
752                 }
754                 $synopsis =~ s/^\n*//g;
755                 $synopsis =~ s/\n+$/\n/g;
756                 my $file_changed = &OutputSGMLFile ($filename, $title, $section_id,
757                                                     $section_includes,
758                                                     \$synopsis, \$details,
759                                                     \$signals_synop, \$signals_desc,
760                                                     \$args_synop, \$args_desc,
761                                                     \$hierarchy, \$interfaces,
762                                                     \$implementations,
763                                                     \$prerequisites, \$derived,
764                                                     \@file_objects);
765                 if ($file_changed) {
766                     $changed = 1;
767                 }
768             }
769             $title = "";
770             $section_id = "";
771             $subsection = "";
772             $in_section = 0;
773             $section_includes = "";
774             $signals_synop = "";
775             $signals_desc = "";
776             $args_synop = "";
777             $child_args_synop = "";
778             $style_args_synop = "";
779             $args_desc = "";
780             $child_args_desc = "";
781             $style_args_desc = "";
782             $hierarchy = "";
783             $interfaces = "";
784             $implementations = "";
785             $prerequisites = "";
786             $derived = "";
788         } elsif (m/^(\S+)/) {
789             my $symbol = $1;
790             #print "  Symbol: $symbol\n";
792             # check for duplicate entries
793             if (! defined $symbol_def_line{$symbol}) {
794                 my $declaration = $Declarations{$symbol};
795                 if (defined ($declaration)) {
796                     # We don't want standard macros/functions of GObjects,
797                     # or private declarations.
798                     if ($subsection ne "Standard" && $subsection ne "Private") {
799                         if (&CheckIsObject ($symbol)) {
800                             push @file_objects, $symbol;
801                         }
802                         my ($synop, $desc) = &OutputDeclaration ($symbol,
803                                                                  $declaration);
804                         my ($sig_synop, $sig_desc) = &GetSignals ($symbol);
805                         my ($arg_synop, $child_arg_synop, $style_arg_synop,
806                             $arg_desc, $child_arg_desc, $style_arg_desc) = &GetArgs ($symbol);
807                         my $hier = &GetHierarchy ($symbol);
808                         my $ifaces = &GetInterfaces ($symbol);
809                         my $impls = &GetImplementations ($symbol);
810                         my $prereqs = &GetPrerequisites ($symbol);
811                         my $der = &GetDerived ($symbol);
812                         $synopsis .= $synop;
813                         $details .= $desc;
814                         $signals_synop .= $sig_synop;
815                         $signals_desc .= $sig_desc;
816                         $args_synop .= $arg_synop;
817                         $child_args_synop .= $child_arg_synop;
818                         $style_args_synop .= $style_arg_synop;
819                         $args_desc .= $arg_desc;
820                         $child_args_desc .= $child_arg_desc;
821                         $style_args_desc .= $style_arg_desc;
822                         $hierarchy .= $hier;
823                         $interfaces .= $ifaces;
824                         $implementations .= $impls;
825                         $prerequisites .= $prereqs;
826                         $derived .= $der;
827                     }
828     
829                     # Note that the declaration has been output.
830                     $DeclarationOutput{$symbol} = 1;
831                 } elsif ($subsection ne "Standard" && $subsection ne "Private") {
832                     $UndeclaredSymbols{$symbol} = 1;
833                     &LogWarning ($file, $., "No declaration found for $symbol.");
834                 }
835                 $num_symbols++;
836                 $symbol_def_line{$symbol}=$.;
838                 if ($section_id eq "") {
839                     if($title eq "" && $filename eq "") {
840                         &LogWarning ($file, $., "Section has no title and no file.");
841                     }
842                     # FIXME: one of those would be enough
843                     # filename should be an internal detail for gtk-doc
844                     if ($title eq "") {
845                         $title = $filename;
846                     } elsif ($filename eq "") {
847                         $filename = $title;
848                     }
849                     $filename =~ s/\s/_/g;
850         
851                     $section_id = $SourceSymbolDocs{"$TMPL_DIR/$filename:Section_Id"};
852                     if (defined ($section_id) && $section_id !~ m/^\s*$/) {
853                         # Remove trailing blanks and use as is
854                         $section_id =~ s/\s+$//;
855                     } elsif (&CheckIsObject ($title)) {
856                         # GObjects use their class name as the ID.
857                         $section_id = &CreateValidSGMLID ($title);
858                     } else {
859                         $section_id = &CreateValidSGMLID ("$MODULE-$title");
860                     }
861                 }
862                 $SymbolSection{$symbol}=$title;
863                 $SymbolSectionId{$symbol}=$section_id;
864             }
865             else {
866                 &LogWarning ($file, $., "Double symbol entry for $symbol. ".
867                     "Previous occurrence on line ".$symbol_def_line{$symbol}.".");
868             }
869         }
870     }
871     close (INPUT);
873     &OutputMissingDocumentation;
874     &OutputUndeclaredSymbols;
875     &OutputUnusedSymbols;
877     if ($OUTPUT_ALL_SYMBOLS) {
878         &OutputAllSymbols;
879     }
880     if ($OUTPUT_SYMBOLS_WITHOUT_SINCE) {
881         &OutputSymbolsWithoutSince;
882     }
884     for $filename (split (' ', $EXPAND_CONTENT_FILES)) {
885         my $file_changed = &OutputExtraFile ($filename);
886         if ($file_changed) {
887             $changed = 1;
888         }
889     }
891     &OutputBook ($book_top, $book_bottom);
893     return $changed;
896 #############################################################################
897 # Function    : OutputIndex
898 # Description : This writes an indexlist that can be included into the main-
899 #               document into an <index> tag.
900 #############################################################################
902 sub OutputIndex {
903     my ($basename, $apiindexref ) = @_;
904     my %apiindex = %{$apiindexref};
905     my $old_index = "$SGML_OUTPUT_DIR/$basename.xml";
906     my $new_index = "$SGML_OUTPUT_DIR/$basename.new";
907     my $lastletter = " ";
908     my $divopen = 0;
909     my $symbol;
910     my $short_symbol;
912     open (OUTPUT, ">$new_index")
913         || die "Can't create $new_index";
915     my $header = $doctype_header;
916     $header =~ s/<!DOCTYPE \w+/<!DOCTYPE indexdiv/;
918     print (OUTPUT "$header<indexdiv>\n");
920     #print "generate $basename index (".%apiindex." entries)\n";
921     
922     # do a case insensitive sort while chopping off the prefix
923     foreach my $hash (
924         sort { $$a{criteria} cmp $$b{criteria} }
925         map { my $x = uc($_); $x =~ s/^$NAME_SPACE\_?(.*)/$1/i; { criteria => $x, original => $_, short => $1 } } 
926         keys %apiindex) {
928         $symbol = $$hash{original};
929         if (defined($$hash{short})) {
930             $short_symbol = $$hash{short};
931         } else {
932             $short_symbol = $symbol;
933         }
935         # generate a short symbol description
936         my $symbol_desc = "";
937         my $symbol_section = "";
938         my $symbol_section_id = "";
939         my $symbol_type = "";
940         if (defined($DeclarationTypes{$symbol})) {
941           $symbol_type = lc($DeclarationTypes{$symbol});
942         }
943         if ($symbol_type eq "") {
944             #print "trying symbol $symbol\n";
945             if ($symbol =~ m/(.*)::(.*)/) {
946                 my $oname = $1;
947                 my $osym = $2;
948                 my $i;
949                 #print "  trying object signal ${oname}:$osym in ".$#SignalNames." signals\n";
950                 for ($i = 0; $i <= $#SignalNames; $i++) {
951                     if ($SignalNames[$i] eq $osym) {
952                         $symbol_type = "object signal";
953                         if (defined($SymbolSection{$oname})) {
954                            $symbol_section = $SymbolSection{$oname};
955                            $symbol_section_id = $SymbolSectionId{$oname};
956                         }
957                         last;
958                     }
959                 }
960             } elsif ($symbol =~ m/(.*):(.*)/) {
961                 my $oname = $1;
962                 my $osym = $2;
963                 my $i;
964                 #print "  trying object property ${oname}::$osym in ".$#ArgNames." properties\n";
965                 for ($i = 0; $i <= $#ArgNames; $i++) {
966                     #print "    ".$ArgNames[$i]."\n";
967                     if ($ArgNames[$i] eq $osym) {
968                         $symbol_type = "object property";
969                         if (defined($SymbolSection{$oname})) {
970                            $symbol_section = $SymbolSection{$oname};
971                            $symbol_section_id = $SymbolSectionId{$oname};
972                         }
973                         last;
974                     }
975                 }
976             }
977         } else {
978            if (defined($SymbolSection{$symbol})) {
979                $symbol_section = $SymbolSection{$symbol};
980                $symbol_section_id = $SymbolSectionId{$symbol};
981            }
982         }
983         if ($symbol_type ne "") {
984            $symbol_desc=", $symbol_type";
985            if ($symbol_section ne "") {
986                $symbol_desc.=" in <link linkend=\"$symbol_section_id\">$symbol_section</link>";
987                #$symbol_desc.=" in ". &ExpandAbbreviations($symbol, "#$symbol_section");
988            }
989         }
991         my $curletter = uc(substr($short_symbol,0,1));
992         my $id = $apiindex{$symbol};
994         #print "  add symbol $symbol with $id to index in section $curletter\n";
996         if ($curletter ne $lastletter) {
997             $lastletter = $curletter;
999             if ($divopen == 1) {
1000                 print (OUTPUT "</indexdiv>\n");
1001             }
1002             print (OUTPUT "<indexdiv><title>$curletter</title>\n");
1003             $divopen = 1;
1004         }
1006         print (OUTPUT <<EOF);
1007 <indexentry><primaryie linkends="$id"><link linkend="$id">$symbol</link>$symbol_desc</primaryie></indexentry>
1009     }
1011     if ($divopen == 1) {
1012         print (OUTPUT "</indexdiv>\n");
1013     }
1014     print (OUTPUT "</indexdiv>\n");
1015     close (OUTPUT);
1017     &UpdateFileIfChanged ($old_index, $new_index, 0);
1021 #############################################################################
1022 # Function    : OutputIndexFull
1023 # Description : This writes the full api indexlist that can be included into the
1024 #               main document into an <index> tag.
1025 #############################################################################
1027 sub OutputIndexFull {
1028     &OutputIndex ("api-index-full", \%IndexEntriesFull);
1032 #############################################################################
1033 # Function    : OutputDeprecatedIndex
1034 # Description : This writes the deprecated api indexlist that can be included
1035 #               into the main document into an <index> tag.
1036 #############################################################################
1038 sub OutputDeprecatedIndex {
1039     &OutputIndex ("api-index-deprecated", \%IndexEntriesDeprecated);
1043 #############################################################################
1044 # Function    : OutputSinceIndexes
1045 # Description : This writes the 'since' api indexlists that can be included into
1046 #               the main document into an <index> tag.
1047 #############################################################################
1049 sub OutputSinceIndexes {
1050     my @sinces = keys %{{ map { $_ => 1 } values %Since }};
1052     foreach my $version (@sinces) {
1053         #print "Since : [$version]\n";
1054         # TODO make filtered hash
1055         #my %index = grep { $Since{$_} eq $version } %IndexEntriesSince;
1056         my %index = map { $_ => $IndexEntriesSince{$_} } grep { $Since{$_} eq $version } keys %IndexEntriesSince;
1058         &OutputIndex ("api-index-$version", \%index);
1059     }
1062 #############################################################################
1063 # Function    : OutputAnnotationGlossary
1064 # Description : This writes a glossary of the used annotation terms into a
1065 #               separate glossary file that can be included into the main
1066 #               document.
1067 #############################################################################
1069 sub OutputAnnotationGlossary {
1070     my $old_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.xml";
1071     my $new_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.new";
1072     my $lastletter = " ";
1073     my $divopen = 0;
1075     # if there are no annotations used return
1076     return if (! keys(%AnnotationsUsed));
1078     # add acronyms that are referenced from acronym text
1079 rerun:
1080     foreach my $annotation (keys(%AnnotationsUsed)) {
1081         if(defined($AnnotationDefinition{$annotation})) {
1082             if($AnnotationDefinition{$annotation} =~ m/<acronym>([\w ]+)<\/acronym>/) {
1083                 if (!exists($AnnotationsUsed{$1})) {
1084                     $AnnotationsUsed{$1} = 1;
1085                     goto rerun;
1086                 }
1087             }
1088         }
1089     }
1091     open (OUTPUT, ">$new_glossary")
1092         || die "Can't create $new_glossary";
1094     my $header = $doctype_header;
1095     $header =~ s/<!DOCTYPE \w+/<!DOCTYPE glossary/;
1097     print (OUTPUT  <<EOF);
1098 $header
1099 <glossary id="annotation-glossary">
1100   <title>Annotation Glossary</title>
1103     foreach my $annotation (keys(%AnnotationsUsed)) {
1104         if(defined($AnnotationDefinition{$annotation})) {
1105             my $def = $AnnotationDefinition{$annotation};
1106             my $curletter = uc(substr($annotation,0,1));
1107     
1108             if ($curletter ne $lastletter) {
1109                 $lastletter = $curletter;
1110           
1111                 if ($divopen == 1) {
1112                     print (OUTPUT "</glossdiv>\n");
1113                 }
1114                 print (OUTPUT "<glossdiv><title>$curletter</title>\n");
1115                 $divopen = 1;
1116             }
1117             print (OUTPUT <<EOF);
1118     <glossentry>
1119       <glossterm><anchor id="annotation-glossterm-$annotation"/>$annotation</glossterm>
1120       <glossdef>
1121         <para>$def</para>
1122       </glossdef>
1123     </glossentry>
1125         }
1126     }
1128     if ($divopen == 1) {
1129         print (OUTPUT "</glossdiv>\n");
1130     }
1131     print (OUTPUT "</glossary>\n");
1132     close (OUTPUT);
1134     &UpdateFileIfChanged ($old_glossary, $new_glossary, 0);
1137 #############################################################################
1138 # Function    : ReadKnownSymbols
1139 # Description : This collects the names of non-private symbols from the
1140 #               $MODULE-sections.txt file.
1141 # Arguments   : $file - the $MODULE-sections.txt file which contains all of
1142 #               the functions/macros/structs etc. being documented, organised
1143 #               into sections and subsections.
1144 #############################################################################
1146 sub ReadKnownSymbols {
1147     my ($file) = @_;
1149     my $subsection = "";
1151     #print "Reading: $file\n";
1152     open (INPUT, $file)
1153         || die "Can't open $file: $!";
1155     while (<INPUT>) {
1156         if (m/^#/) {
1157             next;
1159         } elsif (m/^<SECTION>/) {
1160             $subsection = "";
1162         } elsif (m/^<SUBSECTION\s*(.*)>/i) {
1163             $subsection = $1;
1165         } elsif (m/^<SUBSECTION>/) {
1166             next;
1168         } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
1169             next;
1171         } elsif (m/^<FILE>(.*)<\/FILE>/) {
1172             $KnownSymbols{"$TMPL_DIR/$1:Long_Description"} = 1;
1173             $KnownSymbols{"$TMPL_DIR/$1:Short_Description"} = 1;
1174             next;
1176         } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
1177             next;
1179         } elsif (m/^<\/SECTION>/) {
1180             next;
1182         } elsif (m/^(\S+)/) {
1183             my $symbol = $1;
1185             if ($subsection ne "Standard" && $subsection ne "Private") {
1186                 $KnownSymbols{$symbol} = 1;
1187             }
1188             else {
1189                 $KnownSymbols{$symbol} = 0;
1190             }
1191         }
1192     }
1193     close (INPUT);
1197 #############################################################################
1198 # Function    : OutputDeclaration
1199 # Description : Returns the synopsis and detailed description DocBook
1200 #               describing one function/macro etc.
1201 # Arguments   : $symbol - the name of the function/macro begin described.
1202 #               $declaration - the declaration of the function/macro.
1203 #############################################################################
1205 sub OutputDeclaration {
1206     my ($symbol, $declaration) = @_;
1208     my $type = $DeclarationTypes {$symbol};
1209     if ($type eq 'MACRO') {
1210         return &OutputMacro ($symbol, $declaration);
1211     } elsif ($type eq 'TYPEDEF') {
1212         return &OutputTypedef ($symbol, $declaration);
1213     } elsif ($type eq 'STRUCT') {
1214         return &OutputStruct ($symbol, $declaration);
1215     } elsif ($type eq 'ENUM') {
1216         return &OutputEnum ($symbol, $declaration);
1217     } elsif ($type eq 'UNION') {
1218         return &OutputUnion ($symbol, $declaration);
1219     } elsif ($type eq 'VARIABLE') {
1220         return &OutputVariable ($symbol, $declaration);
1221     } elsif ($type eq 'FUNCTION') {
1222         return &OutputFunction ($symbol, $declaration, $type);
1223     } elsif ($type eq 'USER_FUNCTION') {
1224         return &OutputFunction ($symbol, $declaration, $type);
1225     } else {
1226         die "Unknown symbol type";
1227     }
1231 #############################################################################
1232 # Function    : OutputSymbolTraits
1233 # Description : Returns the Since and StabilityLevel paragraphs for a symbol.
1234 # Arguments   : $symbol - the name of the function/macro begin described.
1235 #############################################################################
1237 sub OutputSymbolTraits {
1238     my ($symbol) = @_;
1239     my $desc = "";
1241     if (exists $Since{$symbol}) {
1242         $desc .= "<para role=\"since\">Since $Since{$symbol}</para>";
1243     }
1244     if (exists $StabilityLevel{$symbol}) {
1245         $desc .= "<para role=\"stability\">Stability Level: $StabilityLevel{$symbol}</para>";
1246     }
1247     return $desc;
1250 #############################################################################
1251 # Function    : Outpu{Symbol,Section}ExtraLinks
1252 # Description : Returns extralinks for the symbol (if enabled).
1253 # Arguments   : $symbol - the name of the function/macro begin described.
1254 #############################################################################
1256 sub uri_escape {
1257     my $text = $_[0];
1258     return undef unless defined $text;
1260     # Build a char to hex map
1261     my %escapes = ();
1262     for (0..255) {
1263             $escapes{chr($_)} = sprintf("%%%02X", $_);
1264     }
1266     # Default unsafe characters.  RFC 2732 ^(uric - reserved)
1267     $text =~ s/([^A-Za-z0-9\-_.!~*'()])/$escapes{$1}/g;
1269     return $text;
1272 sub OutputSymbolExtraLinks {
1273     my ($symbol) = @_;
1274     my $desc = "";
1276     if (0) { # NEW FEATURE: needs configurability
1277     my $sstr = &uri_escape($symbol);
1278     my $mstr = &uri_escape($MODULE);
1279     $desc .= <<EOF;
1280 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1281 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&amp;symbol=$sstr">edit documentation</ulink>
1283     }
1284     return $desc;
1287 sub OutputSectionExtraLinks {
1288     my ($symbol,$docsymbol) = @_;
1289     my $desc = "";
1291     if (0) { # NEW FEATURE: needs configurability
1292     my $sstr = &uri_escape($symbol);
1293     my $mstr = &uri_escape($MODULE);
1294     my $dsstr = &uri_escape($docsymbol);
1295     $desc .= <<EOF;
1296 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1297 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&amp;symbol=$dsstr">edit documentation</ulink>
1299     }
1300     return $desc;
1304 #############################################################################
1305 # Function    : OutputMacro
1306 # Description : Returns the synopsis and detailed description of a macro.
1307 # Arguments   : $symbol - the macro.
1308 #               $declaration - the declaration of the macro.
1309 #############################################################################
1311 sub OutputMacro {
1312     my ($symbol, $declaration) = @_;
1313     my $id = &CreateValidSGMLID ($symbol);
1314     my $condition = &MakeConditionDescription ($symbol);
1315     my $synop = &MakeReturnField("#define") . "<link linkend=\"$id\">$symbol</link>";
1316     my $desc;
1318     my @fields = ParseMacroDeclaration($declaration, \&CreateValidSGML);
1319     my $title = $symbol . (@fields ? "()" : "");
1321     $desc = "<refsect2 id=\"$id\" role=\"macro\"$condition>\n<title>$title</title>\n";
1322     $desc .= MakeIndexterms($symbol, $id);
1323     $desc .= "\n";
1324     $desc .= OutputSymbolExtraLinks($symbol);
1326     if (@fields) {
1327         if (length ($symbol) < $SYMBOL_FIELD_WIDTH) {
1328             $synop .= (' ' x ($SYMBOL_FIELD_WIDTH - length ($symbol)));
1329         }
1330     
1331         $synop .= "(";
1332         for (my $i = 1; $i <= $#fields; $i += 2) {
1333             my $field_name = $fields[$i];
1335             if ($i == 1) {
1336                 $synop .= "$field_name";
1337             } else {
1338                 $synop .= ",\n"
1339                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1340                     . " $field_name";
1341             }
1342         }
1343         $synop .= ")";
1344     }
1345     $synop .= "\n";
1347     # Don't output the macro definition if is is a conditional macro or it
1348     # looks like a function, i.e. starts with "g_" or "_?gnome_", or it is
1349     # longer than 2 lines, otherwise we get lots of complicated macros like
1350     # g_assert.
1351     if (!defined ($DeclarationConditional{$symbol}) && ($symbol !~ m/^g_/)
1352         && ($symbol !~ m/^_?gnome_/) && (($declaration =~ tr/\n//) < 2)) {
1353         my $decl_out = &CreateValidSGML ($declaration);
1354         $desc .= "<programlisting>$decl_out</programlisting>\n";
1355     } else {
1356         $desc .= "<programlisting>" . &MakeReturnField("#define") . "$symbol";
1357         if ($declaration =~ m/^\s*#\s*define\s+\w+(\([^\)]*\))/) {
1358             my $args = $1;
1359             my $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH - length ("#define "));
1360             # Align each line so that if should all line up OK.
1361             $args =~ s/\n/\n$pad/gm;
1362             $desc .= &CreateValidSGML ($args);
1363         }
1364         $desc .= "</programlisting>\n";
1365     }
1367     $desc .= &MakeDeprecationNote($symbol);
1369     my $parameters = &OutputParamDescriptions ("MACRO", $symbol, @fields);
1370     my $parameters_output = 0;
1372     if (defined ($SymbolDocs{$symbol})) {
1373         my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1375         # Try to insert the parameter table at the author's desired position.
1376         # Otherwise we need to tag it onto the end.
1377         if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1378           $parameters_output = 1;
1379         }
1380         $desc .= $symbol_docs;
1381     }
1383     if ($parameters_output == 0) {
1384         $desc .= $parameters;
1385     }
1387     $desc .= OutputSymbolTraits ($symbol);
1388     $desc .= "</refsect2>\n";
1389     return ($synop, $desc);
1393 #############################################################################
1394 # Function    : OutputTypedef
1395 # Description : Returns the synopsis and detailed description of a typedef.
1396 # Arguments   : $symbol - the typedef.
1397 #               $declaration - the declaration of the typedef,
1398 #                 e.g. 'typedef unsigned int guint;'
1399 #############################################################################
1401 sub OutputTypedef {
1402     my ($symbol, $declaration) = @_;
1403     my $id = &CreateValidSGMLID ($symbol);
1404     my $condition = &MakeConditionDescription ($symbol);
1405     my $synop = &MakeReturnField("typedef") . "<link linkend=\"$id\">$symbol</link>;\n";
1406     my $desc = "<refsect2 id=\"$id\" role=\"typedef\"$condition>\n<title>$symbol</title>\n";
1408     $desc .= MakeIndexterms($symbol, $id);
1409     $desc .= "\n";
1410     $desc .= OutputSymbolExtraLinks($symbol);
1412     if (!defined ($DeclarationConditional{$symbol})) {
1413         my $decl_out = &CreateValidSGML ($declaration);
1414         $desc .= "<programlisting>$decl_out</programlisting>\n";
1415     }
1417     $desc .= &MakeDeprecationNote($symbol);
1419     if (defined ($SymbolDocs{$symbol})) {
1420         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1421     }
1422     $desc .= OutputSymbolTraits ($symbol);
1423     $desc .= "</refsect2>\n";
1424     return ($synop, $desc);
1428 #############################################################################
1429 # Function    : OutputStruct
1430 # Description : Returns the synopsis and detailed description of a struct.
1431 #               We check if it is a object struct, and if so we only output
1432 #               parts of it that are noted as public fields.
1433 #               We also use a different SGML ID for object structs, since the
1434 #               original ID is used for the entire RefEntry.
1435 # Arguments   : $symbol - the struct.
1436 #               $declaration - the declaration of the struct.
1437 #############################################################################
1439 sub OutputStruct {
1440     my ($symbol, $declaration) = @_;
1442     my $is_object_struct = 0;
1443     my $default_to_public = 1;
1444     if (&CheckIsObject ($symbol)) {
1445         #print "Found object struct: $symbol\n";
1446         $is_object_struct = 1;
1447         $default_to_public = 0;
1448     }
1450     my $id;
1451     my $condition;
1452     if ($is_object_struct) {
1453         $id = &CreateValidSGMLID ($symbol . "_struct");
1454         $condition = &MakeConditionDescription ($symbol . "_struct");
1455     } else {
1456         $id = &CreateValidSGMLID ($symbol);
1457         $condition = &MakeConditionDescription ($symbol);
1458     }
1460     # Determine if it is a simple struct or it also has a typedef.
1461     my $has_typedef = 0;
1462     if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1463       $has_typedef = 1;
1464     }
1466     my $synop;
1467     my $desc;
1468     if ($has_typedef) {
1469         # For structs with typedefs we just output the struct name.
1470         $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1471         $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>$symbol</title>\n";
1472     } else {
1473         $synop = &MakeReturnField("struct") . "<link linkend=\"$id\">$symbol</link>;\n";
1474         $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>struct $symbol</title>\n";
1475     }
1477     $desc .= MakeIndexterms($symbol, $id);
1478     $desc .= "\n";
1479     $desc .= OutputSymbolExtraLinks($symbol);
1481     # Form a pretty-printed, private-data-removed form of the declaration
1483     my $decl_out = "";
1484     if ($declaration =~ m/^\s*$/) {
1485         #print "Found opaque struct: $symbol\n";
1486         $decl_out = "typedef struct _$symbol $symbol;";
1487     } elsif ($declaration =~ m/^\s*struct\s+\w+\s*;\s*$/) {
1488         #print "Found opaque struct: $symbol\n";
1489         $decl_out = "struct $symbol;";
1490     } else {
1491         my $public = $default_to_public;
1492         my $new_declaration = "";
1493         my $decl_line;
1494         my $decl = $declaration;
1496         if ($decl =~ m/^\s*(typedef\s+)?struct\s*\w*\s*(?:\/\*.*\*\/)?\s*{(.*)}\s*\w*\s*;\s*$/s) {
1497             my $struct_contents = $2;
1499             foreach $decl_line (split (/\n/, $struct_contents)) {
1500                 #print "Struct line: $decl_line\n";
1501                 if ($decl_line =~ m%/\*\s*<\s*public\s*>\s*\*/%) {
1502                     $public = 1;
1503                 } elsif ($decl_line =~ m%/\*\s*<\s*(private|protected)\s*>\s*\*/%) {
1504                     $public = 0;
1505                 } elsif ($public) {
1506                     $new_declaration .= $decl_line . "\n";
1507                 }
1508             }
1510             if ($new_declaration) {
1511                 # Strip any blank lines off the ends.
1512                 $new_declaration =~ s/^\s*\n//;
1513                 $new_declaration =~ s/\n\s*$/\n/;
1515                 if ($has_typedef) {
1516                     $decl_out = "typedef struct {\n" . $new_declaration
1517                       . "} $symbol;\n";
1518                 } else {
1519                     $decl_out = "struct $symbol {\n" . $new_declaration
1520                       . "};\n";
1521                 }
1522             }
1523         } else {
1524             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1525                 "Couldn't parse struct:\n$declaration");
1526         }
1528         # If we couldn't parse the struct or it was all private, output an
1529         # empty struct declaration.
1530         if ($decl_out eq "") {
1531             if ($has_typedef) {
1532                 $decl_out = "typedef struct _$symbol $symbol;";
1533             } else {
1534                 $decl_out = "struct $symbol;";
1535             }
1536         }
1537     }
1539     $decl_out = &CreateValidSGML ($decl_out);
1540     $desc .= "<programlisting>$decl_out</programlisting>\n";
1542     $desc .= &MakeDeprecationNote($symbol);
1544     if (defined ($SymbolDocs{$symbol})) {
1545         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1546     }
1548     # Create a table of fields and descriptions
1550     # FIXME: Inserting &#160's into the produced type declarations here would
1551     #        improve the output in most situations ... except for function
1552     #        members of structs!
1553     my @fields = ParseStructDeclaration($declaration, !$default_to_public,
1554                                         0, \&MakeXRef,
1555                                         sub {
1556                                             "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1557                                         });
1558     my $params = $SymbolParams{$symbol};
1560     # If no parameters are filled in, we don't generate the description
1561     # table, for backwards compatibility
1563     my $found = 0;
1564     if (defined $params) {
1565         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1566             if ($params->[$i] =~ /\S/) {
1567                 $found = 1;
1568                 last;
1569             }
1570         }
1571     }
1573     if ($found) {
1574         my %field_descrs = @$params;
1575         my $missing_parameters = "";
1576         my $unused_parameters = "";
1578         $desc .= "<variablelist role=\"struct\">\n";
1579         while (@fields) {
1580             my $field_name = shift @fields;
1581             my $text = shift @fields;
1582             my $field_descr = $field_descrs{$field_name};
1583             my $param_annotations = "";
1585             $desc .= "<varlistentry><term>$text</term>\n";
1586             if (defined $field_descr) {
1587                 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1588                 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1589                 $field_descr .= $param_annotations;
1590                 # trim
1591                 $field_descr =~ s/^(\s|\n)+//msg;
1592                 $field_descr =~ s/(\s|\n)+$//msg;
1593                 $desc .= "<listitem><simpara>$field_descr</simpara></listitem>\n";
1594                 delete $field_descrs{$field_name};
1595             } else {
1596                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1597                     "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1598                 if ($missing_parameters ne "") {
1599                   $missing_parameters .= ", ".$field_name;
1600                 } else {
1601                     $missing_parameters = $field_name;
1602                 }
1603                 $desc .= "<listitem />\n";
1604             }
1605             $desc .= "</varlistentry>\n";
1606         }
1607         $desc .= "</variablelist>";
1608         foreach my $field_name (keys %field_descrs) {
1609             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1610                 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1611             if ($unused_parameters ne "") {
1612               $unused_parameters .= ", ".$field_name;
1613             } else {
1614                $unused_parameters = $field_name;
1615             }
1616         }
1618         # remember missing/unused parameters (needed in tmpl-free build)
1619         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1620             $AllIncompleteSymbols{$symbol}=$missing_parameters;
1621         }
1622         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1623             $AllUnusedSymbols{$symbol}=$unused_parameters;
1624         }
1625     }
1626     else {
1627         if (scalar(@fields) > 0) {
1628             if (! exists ($AllIncompleteSymbols{$symbol})) {
1629                 $AllIncompleteSymbols{$symbol}="<items>";
1630                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1631                     "Field descriptions for $symbol are missing in source code comment block.");
1632             }
1633         }
1634     }
1636     $desc .= OutputSymbolTraits ($symbol);
1637     $desc .= "</refsect2>\n";
1638     return ($synop, $desc);
1642 #############################################################################
1643 # Function    : OutputUnion
1644 # Description : Returns the synopsis and detailed description of a union.
1645 # Arguments   : $symbol - the union.
1646 #               $declaration - the declaration of the union.
1647 #############################################################################
1649 sub OutputUnion {
1650     my ($symbol, $declaration) = @_;
1651     my $id = &CreateValidSGMLID ($symbol);
1652     my $condition = &MakeConditionDescription ($symbol);
1654     # Determine if it is a simple struct or it also has a typedef.
1655     my $has_typedef = 0;
1656     if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1657       $has_typedef = 1;
1658     }
1660     my $synop;
1661     my $desc;
1662     if ($has_typedef) {
1663         # For unions with typedefs we just output the union name.
1664         $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1665         $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>$symbol</title>\n";
1666     } else {
1667         $synop = &MakeReturnField("union") . "<link linkend=\"$id\">$symbol</link>;\n";
1668         $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>union $symbol</title>\n";
1669     }
1671     $desc .= MakeIndexterms($symbol, $id);
1672     $desc .= "\n";
1673     $desc .= OutputSymbolExtraLinks($symbol);
1675     # FIXME: we do more for structs
1676     my $decl_out = &CreateValidSGML ($declaration);
1677     $desc .= "<programlisting>$decl_out</programlisting>\n";
1679     $desc .= &MakeDeprecationNote($symbol);
1681     if (defined ($SymbolDocs{$symbol})) {
1682         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1683     }
1685     # Create a table of fields and descriptions
1687     # FIXME: Inserting &#160's into the produced type declarations here would
1688     #        improve the output in most situations ... except for function
1689     #        members of structs!
1690     my @fields = ParseStructDeclaration($declaration, 0,
1691                                         0, \&MakeXRef,
1692                                         sub {
1693                                             "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1694                                         });
1695     my $params = $SymbolParams{$symbol};
1697     # If no parameters are filled in, we don't generate the description
1698     # table, for backwards compatibility
1700     my $found = 0;
1701     if (defined $params) {
1702         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1703             if ($params->[$i] =~ /\S/) {
1704                 $found = 1;
1705                 last;
1706             }
1707         }
1708     }
1710     if ($found) {
1711         my %field_descrs = @$params;
1712         my $missing_parameters = "";
1713         my $unused_parameters = "";
1715         $desc .= "<variablelist role=\"union\">\n";
1716         while (@fields) {
1717             my $field_name = shift @fields;
1718             my $text = shift @fields;
1719             my $field_descr = $field_descrs{$field_name};
1720             my $param_annotations = "";
1722             $desc .= "<varlistentry><term>$text</term>\n";
1723             if (defined $field_descr) {
1724                 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1725                 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1726                 $field_descr .= $param_annotations;
1727                 # trim
1728                 $field_descr =~ s/^(\s|\n)+//msg;
1729                 $field_descr =~ s/(\s|\n)+$//msg;
1730                 $desc .= "<listitem><simpara>$field_descr</simpara></listitem>\n";
1731                 delete $field_descrs{$field_name};
1732             } else {
1733                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1734                     "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1735                 if ($missing_parameters ne "") {
1736                     $missing_parameters .= ", ".$field_name;
1737                 } else {
1738                     $missing_parameters = $field_name;
1739                 }
1740                 $desc .= "<listitem />\n";
1741             }
1742             $desc .= "</varlistentry>\n";
1743         }
1744         $desc .= "</variablelist>";
1745         foreach my $field_name (keys %field_descrs) {
1746             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1747                 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1748             if ($unused_parameters ne "") {
1749               $unused_parameters .= ", ".$field_name;
1750             } else {
1751                $unused_parameters = $field_name;
1752             }
1753         }
1755         # remember missing/unused parameters (needed in tmpl-free build)
1756         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1757             $AllIncompleteSymbols{$symbol}=$missing_parameters;
1758         }
1759         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1760             $AllUnusedSymbols{$symbol}=$unused_parameters;
1761         }
1762     }
1763     else {
1764         if (scalar(@fields) > 0) {
1765             if (! exists ($AllIncompleteSymbols{$symbol})) {
1766                 $AllIncompleteSymbols{$symbol}="<items>";
1767                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1768                     "Field descriptions for $symbol are missing in source code comment block.");
1769             }
1770         }
1771     }
1773     $desc .= OutputSymbolTraits ($symbol);
1774     $desc .= "</refsect2>\n";
1775     return ($synop, $desc);
1779 #############################################################################
1780 # Function    : OutputEnum
1781 # Description : Returns the synopsis and detailed description of a enum.
1782 # Arguments   : $symbol - the enum.
1783 #               $declaration - the declaration of the enum.
1784 #############################################################################
1786 sub OutputEnum {
1787     my ($symbol, $declaration) = @_;
1788     my $id = &CreateValidSGMLID ($symbol);
1789     my $condition = &MakeConditionDescription ($symbol);
1790     my $synop = &MakeReturnField("enum") . "<link linkend=\"$id\">$symbol</link>;\n";
1791     my $desc = "<refsect2 id=\"$id\" role=\"enum\"$condition>\n<title>enum $symbol</title>\n";
1793     $desc .= MakeIndexterms($symbol, $id);
1794     $desc .= "\n";
1795     $desc .= OutputSymbolExtraLinks($symbol);
1797     my $decl_out = &CreateValidSGML ($declaration);
1798     $desc .= "<programlisting>$decl_out</programlisting>\n";
1800     $desc .= &MakeDeprecationNote($symbol);
1802     if (defined ($SymbolDocs{$symbol})) {
1803         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1804     }
1806     # Create a table of fields and descriptions
1808     my @fields = ParseEnumDeclaration($declaration);
1809     my $params = $SymbolParams{$symbol};
1811     # If no parameters are filled in, we don't generate the description
1812     # table, for backwards compatibility
1814     my $found = 0;
1815     if (defined $params) {
1816         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1817             if ($params->[$i] =~ /\S/) {
1818                 $found = 1;
1819                 last;
1820             }
1821         }
1822     }
1824     if ($found) {
1825         my %field_descrs = @$params;
1826         my $missing_parameters = "";
1827         my $unused_parameters = "";
1829         $desc .= "<variablelist role=\"enum\">\n";
1830         for my $field_name (@fields) {
1831             my $field_descr = $field_descrs{$field_name};
1832             my $param_annotations = "";
1834             $id = &CreateValidSGMLID ($field_name);
1835             $condition = &MakeConditionDescription ($field_name);
1836             $desc .= "<varlistentry id=\"$id\" role=\"constant\"$condition>\n<term><literal>$field_name</literal></term>\n";
1837             if (defined $field_descr) {
1838                 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1839                 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1840                 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1841                 delete $field_descrs{$field_name};
1842             } else {
1843                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1844                     "Value description for $symbol"."::"."$field_name is missing in source code comment block.");
1845                 if ($missing_parameters ne "") {
1846                   $missing_parameters .= ", ".$field_name;
1847                 } else {
1848                     $missing_parameters = $field_name;
1849                 }
1850                 $desc .= "<listitem />\n";
1851             }
1852             $desc .= "</varlistentry>\n";
1853         }
1854         $desc .= "</variablelist>";
1855         foreach my $field_name (keys %field_descrs) {
1856             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1857                 "Value description for $symbol"."::"."$field_name is not used from source code comment block.");
1858             if ($unused_parameters ne "") {
1859               $unused_parameters .= ", ".$field_name;
1860             } else {
1861                $unused_parameters = $field_name;
1862             }
1863         }
1865         # remember missing/unused parameters (needed in tmpl-free build)
1866         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1867             $AllIncompleteSymbols{$symbol}=$missing_parameters;
1868         }
1869         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1870             $AllUnusedSymbols{$symbol}=$unused_parameters;
1871         }
1872     }
1873     else {
1874         if (scalar(@fields) > 0) {
1875             if (! exists ($AllIncompleteSymbols{$symbol})) {
1876                 $AllIncompleteSymbols{$symbol}="<items>";
1877                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1878                     "Value descriptions for $symbol are missing in source code comment block.");
1879             }
1880         }
1881     }
1883     $desc .= OutputSymbolTraits ($symbol);
1884     $desc .= "</refsect2>\n";
1885     return ($synop, $desc);
1889 #############################################################################
1890 # Function    : OutputVariable
1891 # Description : Returns the synopsis and detailed description of a variable.
1892 # Arguments   : $symbol - the extern'ed variable.
1893 #               $declaration - the declaration of the variable.
1894 #############################################################################
1896 sub OutputVariable {
1897     my ($symbol, $declaration) = @_;
1898     my $id = &CreateValidSGMLID ($symbol);
1899     my $condition = &MakeConditionDescription ($symbol);
1901     my $synop;
1902     if ($declaration =~ m/^\s*extern\s+((const\s+|signed\s+|unsigned\s+)*\w+)(\s+\*+|\*+|\s)(\s*)([A-Za-z]\w*)\s*;/) {
1903         my $mod = defined ($1) ? $1 : "";
1904         my $ptr = defined ($3) ? $3 : "";
1905         my $space = defined ($4) ? $4 : "";
1906         $synop = &MakeReturnField("extern") . "$mod$ptr$space<link linkend=\"$id\">$symbol</link>;\n";
1908     } else {
1909         $synop = &MakeReturnField("extern") . "<link linkend=\"$id\">$symbol</link>;\n";
1910     }
1912     my $desc = "<refsect2 id=\"$id\" role=\"variable\"$condition>\n<title>$symbol</title>\n";
1914     $desc .= MakeIndexterms($symbol, $id);
1915     $desc .= "\n";
1916     $desc .= OutputSymbolExtraLinks($symbol);
1918     my $decl_out = &CreateValidSGML ($declaration);
1919     $desc .= "<programlisting>$decl_out</programlisting>\n";
1921     $desc .= &MakeDeprecationNote($symbol);
1923     if (defined ($SymbolDocs{$symbol})) {
1924         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1925     }
1926     $desc .= OutputSymbolTraits ($symbol);
1927     $desc .= "</refsect2>\n";
1928     return ($synop, $desc);
1932 #############################################################################
1933 # Function    : OutputFunction
1934 # Description : Returns the synopsis and detailed description of a function.
1935 # Arguments   : $symbol - the function.
1936 #               $declaration - the declaration of the function.
1937 #############################################################################
1939 sub OutputFunction {
1940     my ($symbol, $declaration, $symbol_type) = @_;
1941     my $id = &CreateValidSGMLID ($symbol);
1942     my $condition = &MakeConditionDescription ($symbol);
1944     # Take out the return type     $1                                                                                     $3   $4
1945     $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//;
1946     my $type_modifier = defined($1) ? $1 : "";
1947     my $type = $3;
1948     my $pointer = $4;
1949     #print "$symbol pointer is $pointer\n";
1950     my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1951     my $start = "";
1952     #if ($symbol_type eq 'USER_FUNCTION') {
1953     #    $start = "typedef ";
1954     #}
1956     # We output const rather than G_CONST_RETURN.
1957     $type_modifier =~ s/G_CONST_RETURN/const/g;
1958     $pointer =~ s/G_CONST_RETURN/const/g;
1959     $pointer =~ s/^\s+/ /g;
1961     my $ret_type_len = length ($start) + length ($type_modifier)
1962         + length ($pointer) + length ($type);
1963     my $ret_type_output;
1964     my $symbol_len;
1965     if ($ret_type_len < $RETURN_TYPE_FIELD_WIDTH) {
1966         $ret_type_output = "$start$type_modifier$xref$pointer"
1967             . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
1968         $symbol_len = 0;
1969     } else {
1970         #$ret_type_output = "$start$type_modifier$xref$pointer\n" . (' ' x $RETURN_TYPE_FIELD_WIDTH);
1972         $ret_type_output = "$start$type_modifier$xref$pointer ";
1973         $symbol_len = $ret_type_len + 1 - $RETURN_TYPE_FIELD_WIDTH;
1974     }
1976     $symbol_len += length ($symbol);
1977     my $char1 = my $char2 = my $char3 = "";
1978     if ($symbol_type eq 'USER_FUNCTION') {
1979         $symbol_len += 3;
1980         $char1 = "(";
1981         $char2 = "*";
1982         $char3 = ")";
1983     }
1985     my ($symbol_output, $symbol_desc_output);
1986     if ($symbol_len < $SYMBOL_FIELD_WIDTH) {
1987         $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3"
1988             . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1989         $symbol_desc_output = "$char1$char2$symbol$char3"
1990             . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1991     } else {
1992         $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3\n"
1993             . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1994         $symbol_desc_output = "$char1$char2$symbol$char3\n"
1995             . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1996     }
1998     my $synop = $ret_type_output . $symbol_output . '(';
1999     my $desc = "<refsect2 id=\"$id\" role=\"function\"$condition>\n<title>${symbol} ()</title>\n";
2001     $desc .= MakeIndexterms($symbol, $id);
2002     $desc .= "\n";
2003     $desc .= OutputSymbolExtraLinks($symbol);
2005     $desc  .= "<programlisting>${ret_type_output}$symbol_desc_output(";
2006     
2007     my @fields = ParseFunctionDeclaration($declaration, \&MakeXRef,
2008                                         sub {
2009                                             &tagify($_[0],"parameter");
2010                                         });
2011     
2012     for (my $i = 1; $i <= $#fields; $i += 2) {
2013         my $field_name = $fields[$i];
2014         
2015         if ($field_name eq "Varargs") {
2016             $field_name = "...";
2017         }
2019         if ($i == 1) {
2020             $synop .= "$field_name";
2021             $desc  .= "$field_name";
2022         } else {
2023             $synop .= ",\n"
2024                 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2025                 . " $field_name";
2026             $desc  .= ",\n"
2027                 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2028                 . " $field_name";
2029         }
2030         
2031     }
2033     $synop .= ");\n";
2034     $desc  .= ");</programlisting>\n";
2036     $desc .= &MakeDeprecationNote($symbol);
2038     my $parameters = &OutputParamDescriptions ("FUNCTION", $symbol, @fields);
2039     my $parameters_output = 0;
2041     if (defined ($SymbolDocs{$symbol})) {
2042         my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
2044         # Try to insert the parameter table at the author's desired position.
2045         # Otherwise we need to tag it onto the end.
2046         # FIXME: document that in the user manual and make it useable for other
2047         # types too
2048         if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
2049           $parameters_output = 1;
2050         }
2051         $desc .= $symbol_docs;
2052     }
2054     if ($parameters_output == 0) {
2055         $desc .= $parameters;
2056     }
2058     $desc .= OutputSymbolTraits ($symbol);
2059     $desc .= "</refsect2>\n";
2060     return ($synop, $desc);
2064 #############################################################################
2065 # Function    : OutputParamDescriptions
2066 # Description : Returns the DocBook output describing the parameters of a
2067 #               function, macro or signal handler.
2068 # Arguments   : $symbol_type - 'FUNCTION', 'MACRO' or 'SIGNAL'. Signal
2069 #                 handlers have an implicit user_data parameter last.
2070 #               $symbol - the name of the function/macro being described.
2071 #               @fields - parsed fields from the declaration, used to determine
2072 #                  undocumented/unused entries
2073 #############################################################################
2075 sub OutputParamDescriptions {
2076     my ($symbol_type, $symbol, @fields) = @_;
2077     my $output = "";
2078     my $params = $SymbolParams{$symbol};
2079     my $num_params = 0;
2080     my %field_descrs = ();
2082     if (@fields) {
2083         %field_descrs = @fields;
2084         delete $field_descrs{"void"};
2085         delete $field_descrs{"Returns"};
2086     }
2088     if (defined $params) {
2089         my $returns = "";
2090         my $params_desc = "";
2091         my $missing_parameters = "";
2092         my $unused_parameters = "";
2093         my $j;
2095         for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
2096             my $param_name = $$params[$j];
2097             my $param_desc = $$params[$j + 1];
2098             my $param_annotations = "";
2099             
2100             ($param_desc,$param_annotations) = & ExpandAnnotation($symbol, $param_desc);
2101             $param_desc = &ExpandAbbreviations($symbol, $param_desc);
2102             $param_desc .= $param_annotations;
2103             # trim
2104             $param_desc =~ s/^(\s|\n)+//msg;
2105             $param_desc =~ s/(\s|\n)+$//msg;
2106             if ($param_name eq "Returns") {
2107                 $returns = "$param_desc";
2108             } elsif ($param_name eq "void") {
2109                 #print "!!!! void in params for $symbol?\n";
2110             } else {
2111                 if (@fields) {
2112                     if (!defined $field_descrs{$param_name}) {
2113                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2114                             "Parameter description for $symbol"."::"."$param_name is not used from source code comment block.");
2115                         if ($unused_parameters ne "") {
2116                           $unused_parameters .= ", ".$param_name;
2117                         } else {
2118                            $unused_parameters = $param_name;
2119                         }
2120                     } else {
2121                         delete $field_descrs{$param_name};
2122                     }
2123                 }
2124                 if ($param_name eq "Varargs") {
2125                     $param_name = "...";
2126                 }
2127                 if($param_desc ne "") {
2128                     $params_desc .= "<varlistentry><term><parameter>$param_name</parameter>&#160;:</term>\n<listitem><simpara>$param_desc</simpara></listitem></varlistentry>\n";
2129                     $num_params++;
2130                 }
2131             }
2132         }
2133         foreach my $param_name (keys %field_descrs) {
2134             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2135                 "Parameter description for $symbol"."::"."$param_name is missing in source code comment block.");
2136             if ($missing_parameters ne "") {
2137               $missing_parameters .= ", ".$param_name;
2138             } else {
2139                $missing_parameters = $param_name;
2140             }
2141         }
2143         # Signals have an implicit user_data parameter which we describe.
2144         if ($symbol_type eq "SIGNAL") {
2145             $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";
2146         }
2148         # Start a table if we need one.
2149         if ($params_desc || $returns) {
2150             $output .= "<variablelist role=\"params\">\n";
2151             if ($params_desc ne "") {
2152                 #$output .= "<varlistentry><term>Parameters:</term><listitem></listitem></varlistentry>\n";
2153                 $output .= $params_desc;
2154             }
2156             # Output the returns info last
2157             if ($returns) {
2158                 $output .= "<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara>$returns</simpara></listitem></varlistentry>\n";
2159             }
2161             # Finish the table.
2162             $output .= "</variablelist>";
2163         }
2165         # remember missing/unused parameters (needed in tmpl-free build)
2166         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
2167             $AllIncompleteSymbols{$symbol}=$missing_parameters;
2168         }
2169         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
2170             $AllUnusedSymbols{$symbol}=$unused_parameters;
2171         }
2172     }
2173     if (($num_params == 0) && @fields && (scalar(keys(%field_descrs)) > 0)) {
2174         if (! exists ($AllIncompleteSymbols{$symbol})) {
2175             $AllIncompleteSymbols{$symbol}="<parameters>";
2176         }
2177     }
2178     
2179     return $output;
2183 #############################################################################
2184 # Function    : ParseStabilityLevel
2185 # Description : Parses a stability level and outputs a warning if it isn't
2186 #               valid.
2187 # Arguments   : $stability - the stability text.
2188 #               $file, $line - context for error message
2189 #               $message - description of where the level is from, to use in
2190 #               any error message.
2191 # Returns     : The parsed stability level string.
2192 #############################################################################
2194 sub ParseStabilityLevel {
2195     my ($stability, $file, $line, $message) = @_;
2197     $stability =~ s/^\s*//;
2198     $stability =~ s/\s*$//;
2199     if ($stability =~ m/^stable$/i) {
2200         $stability = "Stable";
2201     } elsif ($stability =~ m/^unstable$/i) {
2202         $stability = "Unstable";
2203     } elsif ($stability =~ m/^private$/i) {
2204         $stability = "Private";
2205     } else {
2206         &LogWarning ($file, $line, "$message is $stability.".
2207             "It should be one of these: Stable, Unstable, or Private.");
2208     }
2209     return $stability;
2213 #############################################################################
2214 # Function    : OutputSGMLFile
2215 # Description : Outputs the final DocBook file for one section.
2216 # Arguments   : $file - the name of the file.
2217 #               $title - the title from the $MODULE-sections.txt file, which
2218 #                 will be overridden by the title in the template file.
2219 #               $section_id - the SGML id to use for the toplevel tag.
2220 #               $includes - comma-separates list of include files added at top
2221 #                 of synopsis, with '<' '>' around them (if not already enclosed in "").
2222 #               $synopsis - reference to the DocBook for the Synopsis part.
2223 #               $details - reference to the DocBook for the Details part.
2224 #               $signal_synop - reference to the DocBook for the Signal Synopsis part
2225 #               $signal_desc - reference to the DocBook for the Signal Description part
2226 #               $args_synop - reference to the DocBook for the Arg Synopsis part
2227 #               $args_desc - reference to the DocBook for the Arg Description part
2228 #               $hierarchy - reference to the DocBook for the Object Hierarchy part
2229 #               $interfaces - reference to the DocBook for the Interfaces part
2230 #               $implementations - reference to the DocBook for the Known Implementations part
2231 #               $prerequisites - reference to the DocBook for the Prerequisites part
2232 #               $derived - reference to the DocBook for the Derived Interfaces part
2233 #               $file_objects - reference to an array of objects in this file
2234 #############################################################################
2236 sub OutputSGMLFile {
2237     my ($file, $title, $section_id, $includes, $synopsis, $details, $signals_synop, $signals_desc, $args_synop, $args_desc, $hierarchy, $interfaces, $implementations, $prerequisites, $derived, $file_objects) = @_;
2239     #print "Output sgml for file $file with title '$title'\n";
2240     
2241     # The edited title overrides the one from the sections file.
2242     my $new_title = $SymbolDocs{"$TMPL_DIR/$file:Title"};
2243     if (defined ($new_title) && $new_title !~ m/^\s*$/) {
2244         $title = $new_title;
2245         #print "Found title: $title\n";
2246     }
2247     my $short_desc = $SymbolDocs{"$TMPL_DIR/$file:Short_Description"};
2248     if (!defined ($short_desc) || $short_desc =~ m/^\s*$/) {
2249         $short_desc = "";
2250     } else {
2251         $short_desc = &ExpandAbbreviations("$title:Short_description",
2252                                            $short_desc);
2253         #print "Found short_desc: $short_desc";
2254     }
2255     my $long_desc = $SymbolDocs{"$TMPL_DIR/$file:Long_Description"};
2256     if (!defined ($long_desc) || $long_desc =~ m/^\s*$/) {
2257         $long_desc = "";
2258     } else {
2259         $long_desc = &ExpandAbbreviations("$title:Long_description",
2260                                           $long_desc);
2261         #print "Found long_desc: $long_desc";
2262     }
2263     my $see_also = $SymbolDocs{"$TMPL_DIR/$file:See_Also"};
2264     if (!defined ($see_also) || $see_also =~ m%^\s*(<para>)?\s*(</para>)?\s*$%) {
2265         $see_also = "";
2266     } else {
2267         $see_also = &ExpandAbbreviations("$title:See_Also", $see_also);
2268         #print "Found see_also: $see_also";
2269     }
2270     if ($see_also) {
2271         $see_also = "<refsect1 id=\"$section_id.see-also\">\n<title>See Also</title>\n$see_also\n</refsect1>\n";
2272     }
2273     my $stability = $SymbolDocs{"$TMPL_DIR/$file:Stability_Level"};
2274     if (!defined ($stability) || $stability =~ m/^\s*$/) {
2275         $stability = "";
2276     } else {
2277         $stability = &ParseStabilityLevel($stability, $file, $., "Section stability level");
2278         #print "Found stability: $stability";
2279     }
2280     if ($stability) {
2281         $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$stability, unless otherwise indicated\n</refsect1>\n";
2282     } elsif ($DEFAULT_STABILITY) {
2283         $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$DEFAULT_STABILITY, unless otherwise indicated\n</refsect1>\n";
2284     }
2286     my $image = $SymbolDocs{"$TMPL_DIR/$file:Image"};
2287     if (!defined ($image) || $image =~ m/^\s*$/) {
2288       $image = "";
2289     } else {
2290       $image =~ s/^\s*//;
2291       $image =~ s/\s*$//;
2293       my $format;
2295       if ($image =~ /jpe?g$/i) {
2296         $format = "format='JPEG'";
2297       } elsif ($image =~ /png$/i) {
2298         $format = "format='PNG'";
2299       } elsif ($image =~ /svg$/i) {
2300         $format = "format='SVG'";
2301       } else {
2302         $format = "";
2303       }
2305       $image = "  <inlinegraphic fileref='$image' $format/>\n"
2306     }
2308     my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
2309         gmtime (time);
2310     my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
2311     $year += 1900;
2313     my $include_output = "";
2314     my $include;
2315     foreach $include (split (/,/, $includes)) {
2316         if ($include =~ m/^\".+\"$/) {
2317             $include_output .= "#include ${include}\n";
2318         }
2319         else {
2320             $include =~ s/^\s+|\s+$//gs;
2321             $include_output .= "#include &lt;${include}&gt;\n";
2322         }
2323     }
2324     if ($include_output ne '') {
2325         $include_output = "\n$include_output\n";
2326     }
2327     
2328     my $extralinks = OutputSectionExtraLinks($title,"Section:$file");
2330     my $old_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT";
2331     my $new_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT.new";
2333     open (OUTPUT, ">$new_sgml_file")
2334         || die "Can't create $new_sgml_file: $!";
2336     my $object_anchors = "";
2337     foreach my $object (@$file_objects) {
2338         next if ($object eq $section_id);
2339         my $id = CreateValidSGMLID($object);
2340         #print "Debug: Adding anchor for $object\n";
2341         $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
2342     }
2344     # We used to output this, but is messes up our UpdateFileIfChanged code
2345     # since it changes every day (and it is only used in the man pages):
2346     # "<refentry id="$section_id" revision="$mday $month $year">"
2348     if ($OUTPUT_FORMAT eq "xml") {
2349         print OUTPUT $doctype_header;
2350     }
2352     print OUTPUT <<EOF;
2353 <refentry id="$section_id">
2354 <refmeta>
2355 <refentrytitle role="top_of_page" id="$section_id.top_of_page">$title</refentrytitle>
2356 <manvolnum>3</manvolnum>
2357 <refmiscinfo>
2358   \U$MODULE\E Library
2359 $image</refmiscinfo>
2360 </refmeta>
2361 <refnamediv>
2362 <refname>$title</refname>
2363 <refpurpose>$short_desc</refpurpose>
2364 </refnamediv>
2365 $stability
2366 <refsynopsisdiv id="$section_id.synopsis" role="synopsis">
2367 <title role="synopsis.title">Synopsis</title>
2368 $object_anchors
2369 <synopsis>$include_output$${synopsis}</synopsis>
2370 </refsynopsisdiv>
2371 $$hierarchy$$prerequisites$$derived$$interfaces$$implementations$$args_synop$$signals_synop
2372 <refsect1 id="$section_id.description" role="desc">
2373 <title role="desc.title">Description</title>
2374 $extralinks$long_desc
2375 </refsect1>
2376 <refsect1 id="$section_id.details" role="details">
2377 <title role="details.title">Details</title>
2378 $$details
2379 </refsect1>
2380 $$args_desc$$signals_desc$see_also
2381 </refentry>
2383     close (OUTPUT);
2385     return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2389 #############################################################################
2390 # Function    : OutputExtraFile
2391 # Description : Copies an "extra" DocBook file into the output directory,
2392 #               expanding abbreviations
2393 # Arguments   : $file - the source file.
2394 #############################################################################
2395 sub OutputExtraFile {
2396     my ($file) = @_;
2398     my $basename;
2400     ($basename = $file) =~ s!^.*/!!;
2402     my $old_sgml_file = "$SGML_OUTPUT_DIR/$basename";
2403     my $new_sgml_file = "$SGML_OUTPUT_DIR/$basename.new";
2405     my $contents;
2407     open(EXTRA_FILE, "<$file") || die "Can't open $file";
2409     {
2410         local $/;
2411         $contents = <EXTRA_FILE>;
2412     }
2414     open (OUTPUT, ">$new_sgml_file")
2415         || die "Can't create $new_sgml_file: $!";
2417     print OUTPUT &ExpandAbbreviations ("$basename file", $contents);
2418     close (OUTPUT);
2420     return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2422 #############################################################################
2423 # Function    : OutputBook
2424 # Description : Outputs the SGML entities that need to be included into the
2425 #               main SGML file for the module.
2426 # Arguments   : $book_top - the declarations of the entities, which are added
2427 #                 at the top of the main SGML file.
2428 #               $book_bottom - the references to the entities, which are
2429 #                 added in the main SGML file at the desired position.
2430 #############################################################################
2432 sub OutputBook {
2433     my ($book_top, $book_bottom) = @_;
2435     my $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top";
2436     my $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top.new";
2438     open (OUTPUT, ">$new_file")
2439         || die "Can't create $new_file: $!";
2440     print OUTPUT $book_top;
2441     close (OUTPUT);
2443     &UpdateFileIfChanged ($old_file, $new_file, 0);
2446     $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom";
2447     $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom.new";
2449     open (OUTPUT, ">$new_file")
2450         || die "Can't create $new_file: $!";
2451     print OUTPUT $book_bottom;
2452     close (OUTPUT);
2454     &UpdateFileIfChanged ($old_file, $new_file, 0);
2457     # If the main SGML/XML file hasn't been created yet, we create it here.
2458     # The user can tweak it later.
2459     if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
2460       open (OUTPUT, ">$MAIN_SGML_FILE")
2461         || die "Can't create $MAIN_SGML_FILE: $!";
2463       if ($OUTPUT_FORMAT eq "xml") {
2464           print OUTPUT <<EOF;
2465 <?xml version="1.0"?>
2466 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
2467                "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
2469   <!ENTITY % local.common.attrib "xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'">
2471 <book id="index">
2473       } else {
2474         print OUTPUT <<EOF;
2475 <!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
2476 $book_top
2478 <book id="index">
2480       }
2482 print OUTPUT <<EOF;
2483   <bookinfo>
2484     <title>$MODULE Reference Manual</title>
2485     <releaseinfo>
2486       for $MODULE [VERSION].
2487       The latest version of this documentation can be found on-line at
2488       <ulink role="online-location" url="http://[SERVER]/$MODULE/index.html">http://[SERVER]/$MODULE/</ulink>.
2489     </releaseinfo>
2490   </bookinfo>
2492   <chapter>
2493     <title>[Insert title here]</title>
2494     $book_bottom
2495   </chapter>
2497   if (-e $OBJECT_TREE_FILE) {
2498     print OUTPUT <<EOF;
2499   <chapter id="object-tree">
2500     <title>Object Hierarchy</title>
2501      <xi:include href="xml/tree_index.sgml"/>
2502   </chapter>
2504   }
2506 print OUTPUT <<EOF;
2507   <index id="api-index-full">
2508     <title>API Index</title>
2509     <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
2510   </index>
2511   <index id="deprecated-api-index" role="deprecated">
2512     <title>Index of deprecated API</title>
2513     <xi:include href="xml/api-index-deprecated.xml"><xi:fallback /></xi:include>
2514   </index>
2516   <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
2517 </book>
2520       close (OUTPUT);
2521     }
2525 #############################################################################
2526 # Function    : CreateValidSGML
2527 # Description : This turns any chars which are used in SGML into entities,
2528 #               e.g. '<' into '&lt;'
2529 # Arguments   : $text - the text to turn into proper SGML.
2530 #############################################################################
2532 sub CreateValidSGML {
2533     my ($text) = @_;
2534     $text =~ s/&/&amp;/g;       # Do this first, or the others get messed up.
2535     $text =~ s/</&lt;/g;
2536     $text =~ s/>/&gt;/g;
2537     # browers render single tabs inconsistently
2538     $text =~ s/([^\s])\t([^\s])/$1&#160;$2/g;
2539     return $text;
2542 #############################################################################
2543 # Function    : ConvertSGMLChars
2544 # Description : This is used for text in source code comment blocks, to turn
2545 #               chars which are used in SGML into entities, e.g. '<' into
2546 #               '&lt;'. Depending on $INLINE_MARKUP_MODE, this is done
2547 #               unconditionally or only if the character doesn't seem to be
2548 #               part of an SGML construct (tag or entity reference).
2549 # Arguments   : $text - the text to turn into proper SGML.
2550 #############################################################################
2552 sub ConvertSGMLChars {
2553     my ($symbol, $text) = @_;
2555     if ($INLINE_MARKUP_MODE) {
2556         # For the XML/SGML mode only convert to entities outside CDATA sections.
2557         return &ModifyXMLElements ($text, $symbol,
2558                                    "<!\\[CDATA\\[|<programlisting[^>]*>",
2559                                    \&ConvertSGMLCharsEndTag,
2560                                    \&ConvertSGMLCharsCallback);
2561     } else {
2562         # For the simple non-sgml mode, convert to entities everywhere.
2563         $text =~ s/&/&amp;/g;   # Do this first, or the others get messed up.
2564         $text =~ s/</&lt;/g;
2565         $text =~ s/>/&gt;/g;
2566         return $text;
2567     }
2571 sub ConvertSGMLCharsEndTag {
2572   if ($_[0] eq "<!\[CDATA\[") {
2573     return "]]>";
2574   } else {
2575     return "</programlisting>";
2576   }
2579 sub ConvertSGMLCharsCallback {
2580   my ($text, $symbol, $tag) = @_;
2582   if ($tag =~ m/^<programlisting/) {
2583     # We can handle <programlisting> specially here.
2584     return &ModifyXMLElements ($text, $symbol,
2585                                "<!\\[CDATA\\[",
2586                                \&ConvertSGMLCharsEndTag,
2587                                \&ConvertSGMLCharsCallback2);
2588   } elsif ($tag eq "") {
2589     # If we're not in CDATA convert to entities.
2590     $text =~ s/&(?![a-zA-Z#]+;)/&amp;/g;        # Do this first, or the others get messed up.
2591     $text =~ s/<(?![a-zA-Z\/!])/&lt;/g;
2592     $text =~ s/(?<![a-zA-Z0-9"'\/-])>/&gt;/g;
2594     # Handle "#include <xxxxx>"
2595     $text =~ s/#include(\s+)<([^>]+)>/#include$1&lt;$2&gt;/g;
2596   }
2598   return $text;
2601 sub ConvertSGMLCharsCallback2 {
2602   my ($text, $symbol, $tag) = @_;
2604   # If we're not in CDATA convert to entities.
2605   # We could handle <programlisting> differently, though I'm not sure it helps.
2606   if ($tag eq "") {
2607     # replace only if its not a tag
2608     $text =~ s/&(?![a-zA-Z#]+;)/&amp;/g;        # Do this first, or the others get messed up.
2609     $text =~ s/<(?![a-zA-Z\/!])/&lt;/g;
2610     $text =~ s/(?<![a-zA-Z0-9"'\/-])>/&gt;/g;
2612     # Handle "#include <xxxxx>"
2613     $text =~ s/#include(\s+)<([^>]+)>/#include$1&lt;$2&gt;/g;
2614   }
2616   return $text;
2619 #############################################################################
2620 # Function    : ExpandAnnotation
2621 # Description : This turns annotations into acronym tags.
2622 # Arguments   : $symbol - the symbol being documented, for error messages.
2623 #               $text - the text to expand.
2624 #############################################################################
2625 sub ExpandAnnotation {
2626     my ($symbol, $param_desc) = @_;
2627     my $param_annotations = "";
2629     # look for annotations at the start of the comment part
2630     if ($param_desc =~ m%^\s*\((.*?)\):%) {
2631         my @annotations;
2632         my $annotation;
2633         $param_desc = $';
2634         
2635         @annotations = split(/\)\s*\(/,$1);
2636         foreach $annotation (@annotations) {
2637             # need to search for the longest key-match in %AnnotationDefinition
2638             my $match_length=0;
2639             my $match_annotation="";
2640             my $annotationdef;
2641             foreach $annotationdef (keys %AnnotationDefinition) {
2642                 if ($annotation =~ m/^$annotationdef/) {
2643                     if (length($annotationdef)>$match_length) {
2644                         $match_length=length($annotationdef);
2645                         $match_annotation=$annotationdef;
2646                     }
2647                 }
2648             }
2649             my $annotation_extra = "";
2650             if ($match_annotation ne "") {
2651                 if ($annotation =~ m%$match_annotation\s+(.*)%) {
2652                     $annotation_extra = " $1";
2653                 }
2654                 $AnnotationsUsed{$match_annotation} = 1;
2655                 $param_annotations .= "[<acronym>$match_annotation</acronym>$annotation_extra]";
2656             }
2657             else {
2658                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2659                     "unknown annotation \"$annotation\" in documentation for $symbol.");
2660                 $param_annotations .= "[$annotation]";
2661             }
2662         }
2663         chomp($param_desc);
2664         $param_desc =~ m/^(.*?)\.*\s*$/s;
2665         $param_desc = "$1. ";
2666     }
2667     if ($param_annotations ne "") {
2668         $param_annotations = "<emphasis role=\"annotation\">$param_annotations</emphasis>";
2669     }
2670     return ($param_desc, $param_annotations);
2673 #############################################################################
2674 # Function    : ExpandAbbreviations
2675 # Description : This turns the abbreviations function(), macro(), @param,
2676 #               %constant, and #symbol into appropriate DocBook markup.
2677 #               CDATA sections and <programlisting> parts are skipped.
2678 # Arguments   : $symbol - the symbol being documented, for error messages.
2679 #               $text - the text to expand.
2680 #############################################################################
2682 sub ExpandAbbreviations {
2683   my ($symbol, $text) = @_;
2685   # Convert "|[" and "]|" into the start and end of program listing examples.
2686   # FIXME: we like to have a way to specify parameters e.g. language="c"
2687   $text =~ s%\|\[%<informalexample><programlisting>%g;
2688   $text =~ s%\]\|%</programlisting></informalexample>%g;
2689   # TODO: check for a xml comment after |[ and pick the language attribute from
2690   # that
2692   # keep CDATA unmodified, preserve ulink tags (ideally we preseve all tags
2693   # as such)
2694   return &ModifyXMLElements ($text, $symbol,
2695                              "<!\\[CDATA\\[|<ulink[^>]*>|<programlisting[^>]*>|<!DOCTYPE",
2696                              \&ExpandAbbreviationsEndTag,
2697                              \&ExpandAbbreviationsCallback);
2701 # Returns the end tag corresponding to the given start tag.
2702 sub ExpandAbbreviationsEndTag {
2703   my ($start_tag) = @_;
2705   if ($start_tag eq "<!\[CDATA\[") {
2706     return "]]>";
2707   } elsif ($start_tag eq "<!DOCTYPE") {
2708     return "]>";
2709   } elsif ($start_tag =~ m/<(\w+)/) {
2710     return "</$1>";
2711   }
2714 # Called inside or outside each CDATA or <programlisting> section.
2715 sub ExpandAbbreviationsCallback {
2716   my ($text, $symbol, $tag) = @_;
2718   if ($tag =~ m/^<programlisting/) {
2719     # Handle any embedded CDATA sections.
2720     return &ModifyXMLElements ($text, $symbol,
2721                                "<!\\[CDATA\\[",
2722                                \&ExpandAbbreviationsEndTag,
2723                                \&ExpandAbbreviationsCallback2);
2724   } elsif ($tag eq "") {
2725     # We are outside any CDATA or <programlisting> sections, so we expand
2726     # any gtk-doc abbreviations.
2728     # Convert 'function()' or 'macro()'.
2729     # if there is abc_*_def() we don't want to make a link to _def()
2730     # FIXME: also handle abc(....) : but that would need to be done recursively :/
2731     $text =~ s/([^\*.\w])(\w+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2732     # handle #Object.func()
2733     $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2735     # Convert '@param', but not '\@param'.
2736     $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)/$1<parameter>$2<\/parameter>/g;
2737     $text =~ s/\\\@/\@/g;
2739     # Convert '%constant', but not '\%constant'.
2740     # Also allow negative numbers, e.g. %-1.
2741     $text =~ s/(\A|[^\\])\%(-?\w+)/$1.&MakeXRef($2, &tagify($2, "literal"));/eg;
2742     $text =~ s/\\\%/\%/g;
2744     # Convert '#symbol', but not '\#symbol'.
2745     $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)/$1.&MakeHashXRef($2, "type");/eg;
2746     $text =~ s/\\#/#/g;
2747     
2748     # Expand urls
2749     # FIXME: should we skip urls that are already tagged? (e.g. <literal>http://...</literal>)
2750     # this is apparently also called for markup and not just for plain text
2751     # disable for now.
2752     #$text =~ s%(http|https|ftp)://(.*?)((?:\s|,|\)|\]|\<|\.\s))%<ulink url="$1://$2">$2</ulink>$3%g;
2754     # TODO: optionally check all words from $text against internal symbols and
2755     # warn if those could be xreffed, but miss a %,# or ()
2756   }
2758   return $text;
2761 # This is called inside a <programlisting>
2762 sub ExpandAbbreviationsCallback2 {
2763   my ($text, $symbol, $tag) = @_;
2765   if ($tag eq "") {
2766     # We are inside a <programlisting> but outside any CDATA sections,
2767     # so we expand any gtk-doc abbreviations.
2768     # FIXME: why is this different from &ExpandAbbreviationsCallback(),
2769     #        why not just call it
2770     $text =~ s/#(\w+)/&MakeHashXRef($1, "");/eg;
2771   }
2773   return $text;
2776 sub MakeHashXRef {
2777     my ($symbol, $tag) = @_;;
2778     my $text = $symbol;
2780     # Check for things like '#include', '#define', and skip them.
2781     if ($PreProcessorDirectives{$symbol}) {
2782       return "#$symbol";
2783     }
2785     # Get rid of any special '-struct' suffix.
2786     $text =~ s/-struct$//;
2788     # If the symbol is in the form "Object::signal", then change the symbol to
2789     # "Object-signal" and use "signal" as the text.
2790     if ($symbol =~ s/::/-/) {
2791       $text = "\"$'\"";
2792     }
2794     # If the symbol is in the form "Object:property", then change the symbol to
2795     # "Object--property" and use "property" as the text.
2796     if ($symbol =~ s/:/--/) {
2797       $text = "\"$'\"";
2798     }
2800     if ($tag ne "") {
2801       $text = tagify ($text, $tag);
2802     }
2803     
2804     return &MakeXRef($symbol, $text);
2808 #############################################################################
2809 # Function    : ModifyXMLElements
2810 # Description : Looks for given XML element tags within the text, and calls
2811 #               the callback on pieces of text inside & outside those elements.
2812 #               Used for special handling of text inside things like CDATA
2813 #               and <programlisting>.
2814 # Arguments   : $text - the text.
2815 #               $symbol - the symbol currently being documented (only used for
2816 #                      error messages).
2817 #               $start_tag_regexp - the regular expression to match start tags.
2818 #                      e.g. "<!\\[CDATA\\[|<programlisting[^>]*>" to match
2819 #                      CDATA sections or programlisting elements.
2820 #               $end_tag_func - function which is passed the matched start tag
2821 #                      and should return the appropriate end tag string.
2822 #               $callback - callback called with each part of the text. It is
2823 #                      called with a piece of text, the symbol being
2824 #                      documented, and the matched start tag or "" if the text
2825 #                      is outside the XML elements being matched.
2826 #############################################################################
2827 sub ModifyXMLElements {
2828     my ($text, $symbol, $start_tag_regexp, $end_tag_func, $callback) = @_;
2829     my ($before_tag, $start_tag, $end_tag_regexp, $end_tag);
2830     my $result = "";
2832     while ($text =~ m/$start_tag_regexp/s) {
2833       $before_tag = $`; # Prematch for last successful match string
2834       $start_tag = $&;  # Last successful match
2835       $text = $';       # Postmatch for last successful match string
2837       $result .= &$callback ($before_tag, $symbol, "");
2838       $result .= $start_tag;
2840       # get the mathing end-tag for current tag
2841       $end_tag_regexp = &$end_tag_func ($start_tag);
2843       if ($text =~ m/$end_tag_regexp/s) {
2844         $before_tag = $`;
2845         $end_tag = $&;
2846         $text = $';
2848         $result .= &$callback ($before_tag, $symbol, $start_tag);
2849         $result .= $end_tag;
2850       } else {
2851         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2852             "Can't find tag end: $end_tag_regexp in docs for: $symbol.");
2853         # Just assume it is all inside the tag.
2854         $result .= &$callback ($text, $symbol, $start_tag);
2855         $text = "";
2856       }
2857     }
2859     # Handle any remaining text outside the tags.
2860     $result .= &$callback ($text, $symbol, "");
2862     return $result;
2865 sub noop {
2866   return $_[0];
2869 # Adds a tag around some text.
2870 # e.g tagify("Text", "literal") => "<literal>Text</literal>".
2871 sub tagify {
2872    my ($text, $elem) = @_;
2873    return "<" . $elem . ">" . $text . "</" . $elem . ">";
2877 #############################################################################
2878 # Function    : MakeXRef
2879 # Description : This returns a cross-reference link to the given symbol.
2880 #               Though it doesn't try to do this for a few standard C types
2881 #               that it knows won't be in the documentation.
2882 # Arguments   : $symbol - the symbol to try to create a XRef to.
2883 #               $text - text text to put inside the XRef, defaults to $symbol
2884 #############################################################################
2886 sub MakeXRef {
2887     my ($symbol, $text) = ($_[0], $_[1]);
2889     $symbol =~ s/^\s+//;
2890     $symbol =~ s/\s+$//;
2892     if (!defined($text)) {
2893         $text = $symbol;
2895         # Get rid of special '-struct' suffix.
2896         $text =~ s/-struct$//;
2897     }
2899     if ($symbol =~ m/ /) {
2900         return "$text";
2901     }
2903     #print "Getting type link for $symbol -> $text\n";
2905     my $symbol_id = &CreateValidSGMLID ($symbol);
2906     return "<link linkend=\"$symbol_id\">$text</link>";
2910 #############################################################################
2911 # Function    : MakeIndexterms
2912 # Description : This returns a indexterm elements for the given symbol
2913 # Arguments   : $symbol - the symbol to create indexterms for
2914 #############################################################################
2916 sub MakeIndexterms {
2917   my ($symbol, $id) = @_;
2918   my $terms =  "";
2919   my $sortas = "";
2920   
2921   # make the index useful, by ommiting the namespace when sorting
2922   if ($NAME_SPACE ne "") {
2923     if ($symbol =~ m/^$NAME_SPACE\_?(.*)/i) {
2924        $sortas=" sortas=\"$1\"";
2925     }
2926   }
2928   if (exists $Deprecated{$symbol}) {
2929       $terms .= "<indexterm zone=\"$id\" role=\"deprecated\"><primary$sortas>$symbol</primary></indexterm>";
2930       $IndexEntriesDeprecated{$symbol}=$id;
2931       $IndexEntriesFull{$symbol}=$id;
2932   }
2933   if (exists $Since{$symbol}) {
2934      my $since = $Since{$symbol};
2935      $since =~ s/^\s+//;
2936      $since =~ s/\s+$//;
2937      if ($since ne "") {
2938          $terms .= "<indexterm zone=\"$id\" role=\"$since\"><primary$sortas>$symbol</primary></indexterm>";
2939      }
2940      $IndexEntriesSince{$symbol}=$id;
2941      $IndexEntriesFull{$symbol}=$id;
2942   }
2943   if ($terms eq "") {
2944      $terms .= "<indexterm zone=\"$id\"><primary$sortas>$symbol</primary></indexterm>";
2945      $IndexEntriesFull{$symbol}=$id;
2946   }
2948   return $terms;
2951 #############################################################################
2952 # Function    : MakeDeprecationNote
2953 # Description : This returns a deprecation warning for the given symbol.
2954 # Arguments   : $symbol - the symbol to try to create a warning for.
2955 #############################################################################
2957 sub MakeDeprecationNote {
2958     my ($symbol) = $_[0];
2959     my $desc = "";
2960     my $note = "";
2961     if (exists $Deprecated{$symbol}) {
2962         $desc .= "<warning>";
2964         if ($Deprecated{$symbol} =~ /^\s*([0-9\.]+)\s*:/) {
2965                 $desc .= "<para><literal>$symbol</literal> has been deprecated since version $1 and should not be used in newly-written code.";
2966         } else {
2967                 $desc .= "<para><literal>$symbol</literal> is deprecated and should not be used in newly-written code.";
2968         }
2969         if ($Deprecated{$symbol} ne "") {
2970             $note = &ExpandAbbreviations($symbol, $Deprecated{$symbol});
2971             $note =~ s/^\s*([0-9\.]+)\s*:\s*//;
2972             $note =~ s/^\s+//;
2973             $note =~ s/\s+$//;
2974             $note =~ s%\n{2,}%\n</para>\n<para>\n%g;
2975             $desc .= " " . $note;
2976         }
2977         $desc .= "</para></warning>\n";
2978     }
2979     return $desc;
2982 #############################################################################
2983 # Function    : MakeConditionDescription
2984 # Description : This returns a sumary of conditions for the given symbol.
2985 # Arguments   : $symbol - the symbol to try to create the sumary.
2986 #############################################################################
2988 sub MakeConditionDescription {
2989     my ($symbol) = $_[0];
2990     my $desc = "";
2992     if (exists $Deprecated{$symbol}) {
2993         if ($desc ne "") {
2994             $desc .= "|";
2995         }
2997         if ($Deprecated{$symbol} =~ /^\s*(.*?)\s*$/) {
2998                 $desc .= "deprecated:$1";
2999         } else {
3000                 $desc .= "deprecated";
3001         }
3002     }
3004     if (exists $Since{$symbol}) {
3005         if ($desc ne "") {
3006             $desc .= "|";
3007         }
3009         if ($Since{$symbol} =~ /^\s*(.*?)\s*$/) {
3010                 $desc .= "since:$1";
3011         } else {
3012                 $desc .= "since";
3013         }
3014     }
3016     if (exists $StabilityLevel{$symbol}) {
3017         if ($desc ne "") {
3018             $desc .= "|";
3019         }
3020         $desc .= "stability:".$StabilityLevel{$symbol};
3021     }
3023     if ($desc ne "") {
3024         $desc=" condition=\"".$desc."\"";
3025         #print "condition for '$symbol' = '$desc'\n";
3026     }
3027     return $desc;
3030 #############################################################################
3031 # Function    : GetHierarchy
3032 # Description : Returns the DocBook output describing the ancestors and
3033 #               immediate children of a GObject subclass. It uses the
3034 #               global @Objects and @ObjectLevels arrays to walk the tree.
3035 # Arguments   : $object - the GtkObject subclass.
3036 #############################################################################
3038 sub GetHierarchy {
3039     my ($object) = @_;
3041     # Find object in the objects array.
3042     my $found = 0;
3043     my @children = ();
3044     my $i;
3045     my $level;
3046     my $j;
3047     for ($i = 0; $i < @Objects; $i++) {
3048         if ($found) {
3049             if ($ObjectLevels[$i] <= $level) {
3050             last;
3051         }
3052             elsif ($ObjectLevels[$i] == $level + 1) {
3053                 push (@children, $Objects[$i]);
3054             }
3055         }
3056         elsif ($Objects[$i] eq $object) {
3057             $found = 1;
3058             $j = $i;
3059             $level = $ObjectLevels[$i];
3060         }
3061     }
3062     if (!$found) {
3063         return "";
3064     }
3066     # Walk up the hierarchy, pushing ancestors onto the ancestors array.
3067     my @ancestors = ();
3068     push (@ancestors, $object);
3069     #print "Level: $level\n";
3070     while ($level > 1) {
3071         $j--;
3072         if ($ObjectLevels[$j] < $level) {
3073             push (@ancestors, $Objects[$j]);
3074             $level = $ObjectLevels[$j];
3075             #print "Level: $level\n";
3076         }
3077     }
3079     # Output the ancestors list, indented and with links.
3080     my $hierarchy = "<synopsis>\n";
3081     $level = 0;
3082     for ($i = $#ancestors; $i >= 0; $i--) {
3083         my $link_text;
3084         # Don't add a link to the current object, i.e. when i == 0.
3085         if ($i > 0) {
3086             my $ancestor_id = &CreateValidSGMLID ($ancestors[$i]);
3087             $link_text = "<link linkend=\"$ancestor_id\">$ancestors[$i]</link>";
3088         } else {
3089             $link_text = "$ancestors[$i]";
3090         }
3091         if ($level == 0) {
3092             $hierarchy .= "  $link_text\n";
3093         } else {
3094 #           $hierarchy .= ' ' x ($level * 6 - 3) . "|\n";
3095             $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3096         }
3097         $level++;
3098     }
3099     for ($i = 0; $i <= $#children; $i++) {
3100       my $id = &CreateValidSGMLID ($children[$i]);
3101       my $link_text = "<link linkend=\"$id\">$children[$i]</link>";
3102       $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3103     }
3104     $hierarchy .= "</synopsis>\n";
3106     return $hierarchy;
3110 #############################################################################
3111 # Function    : GetInterfaces
3112 # Description : Returns the DocBook output describing the interfaces
3113 #               implemented by a class. It uses the global %Interfaces hash.
3114 # Arguments   : $object - the GtkObject subclass.
3115 #############################################################################
3117 sub GetInterfaces {
3118     my ($object) = @_;
3119     my $text = "";
3120     my $i;
3122     # Find object in the objects array.
3123     if (exists($Interfaces{$object})) {
3124         my @ifaces = split(' ', $Interfaces{$object});
3125         $text = <<EOF;
3126 <para>
3127 $object implements
3129         for ($i = 0; $i <= $#ifaces; $i++) {
3130             my $id = &CreateValidSGMLID ($ifaces[$i]);
3131             $text .= " <link linkend=\"$id\">$ifaces[$i]</link>";
3132             if ($i < $#ifaces - 1) {
3133                 $text .= ', ';
3134             }
3135             elsif ($i < $#ifaces) {
3136                 $text .= ' and ';
3137             }
3138             else {
3139                 $text .= '.';
3140             }
3141         }
3142         $text .= <<EOF;
3143 </para>
3145     }
3147     return $text;
3150 #############################################################################
3151 # Function    : GetImplementations
3152 # Description : Returns the DocBook output describing the implementations
3153 #               of an interface. It uses the global %Interfaces hash.
3154 # Arguments   : $object - the GtkObject subclass.
3155 #############################################################################
3157 sub GetImplementations {
3158     my ($object) = @_;
3159     my @impls = ();
3160     my $text = "";
3161     my $i;
3162     foreach my $key (keys %Interfaces) {
3163         if ($Interfaces{$key} =~ /\b$object\b/) {
3164             push (@impls, $key);
3165         }
3166     }
3167     if ($#impls >= 0) {
3168         @impls = sort @impls;
3169         $text = <<EOF;
3170 <para>
3171 $object is implemented by
3173         for ($i = 0; $i <= $#impls; $i++) {
3174             my $id = &CreateValidSGMLID ($impls[$i]);
3175             $text .= " <link linkend=\"$id\">$impls[$i]</link>";
3176             if ($i < $#impls - 1) {
3177                 $text .= ', ';
3178             }
3179             elsif ($i < $#impls) {
3180                 $text .= ' and ';
3181             }
3182             else {
3183                 $text .= '.';
3184             }
3185         }
3186         $text .= <<EOF;
3187 </para>
3189     }
3190     return $text;
3194 #############################################################################
3195 # Function    : GetPrerequisites
3196 # Description : Returns the DocBook output describing the prerequisites
3197 #               of an interface. It uses the global %Prerequisites hash.
3198 # Arguments   : $iface - the interface.
3199 #############################################################################
3201 sub GetPrerequisites {
3202     my ($iface) = @_;
3203     my $text = "";
3204     my $i;
3206     if (exists($Prerequisites{$iface})) {
3207         $text = <<EOF;
3208 <para>
3209 $iface requires
3211         my @prereqs = split(' ', $Prerequisites{$iface});
3212         for ($i = 0; $i <= $#prereqs; $i++) {
3213             my $id = &CreateValidSGMLID ($prereqs[$i]);
3214             $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
3215             if ($i < $#prereqs - 1) {
3216                 $text .= ', ';
3217             }
3218             elsif ($i < $#prereqs) {
3219                 $text .= ' and ';
3220             }
3221             else {
3222                 $text .= '.';
3223             }
3224         }
3225         $text .= <<EOF;
3226 </para>
3228     }
3229     return $text;
3232 #############################################################################
3233 # Function    : GetDerived
3234 # Description : Returns the DocBook output describing the derived interfaces
3235 #               of an interface. It uses the global %Prerequisites hash.
3236 # Arguments   : $iface - the interface.
3237 #############################################################################
3239 sub GetDerived {
3240     my ($iface) = @_;
3241     my $text = "";
3242     my $i;
3244     my @derived = ();
3245     foreach my $key (keys %Prerequisites) {
3246         if ($Prerequisites{$key} =~ /\b$iface\b/) {
3247             push (@derived, $key);
3248         }
3249     }
3250     if ($#derived >= 0) {
3251         @derived = sort @derived;
3252         $text = <<EOF;
3253 <para>
3254 $iface is required by
3256         for ($i = 0; $i <= $#derived; $i++) {
3257             my $id = &CreateValidSGMLID ($derived[$i]);
3258             $text .= " <link linkend=\"$id\">$derived[$i]</link>";
3259             if ($i < $#derived - 1) {
3260                 $text .= ', ';
3261             }
3262             elsif ($i < $#derived) {
3263                 $text .= ' and ';
3264             }
3265             else {
3266                 $text .= '.';
3267             }
3268         }
3269         $text .= <<EOF;
3270 </para>
3272     }
3273     return $text;
3277 #############################################################################
3278 # Function    : GetSignals
3279 # Description : Returns the synopsis and detailed description DocBook output
3280 #               for the signal handlers of a given GtkObject subclass.
3281 # Arguments   : $object - the GtkObject subclass, e.g. 'GtkButton'.
3282 #############################################################################
3284 sub GetSignals {
3285     my ($object) = @_;
3286     my $synop = "";
3287     my $desc = "";
3289     my $i;
3290     for ($i = 0; $i <= $#SignalObjects; $i++) {
3291         if ($SignalObjects[$i] eq $object) {
3292             #print "Found signal: $SignalNames[$i]\n";
3293             my $name = $SignalNames[$i];
3294             my $symbol = "${object}::${name}";
3295             my $id = &CreateValidSGMLID ("$object-$name");
3297             my $pad = ' ' x (46 - length($name));
3298             $synop .= "  &quot;<link linkend=\"$id\">$name</link>&quot;$pad ";
3300             $desc .= "<refsect2 id=\"$id\" role=\"signal\"><title>The <literal>&quot;$name&quot;</literal> signal</title>\n";
3301             $desc .= MakeIndexterms($symbol, $id);
3302             $desc .= "\n";
3303             $desc .= OutputSymbolExtraLinks($symbol);
3305             $desc .= "<programlisting>";
3307             $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
3308             my $type_modifier = defined($1) ? $1 : "";
3309             my $type = $2;
3310             my $pointer = $3;
3311             my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
3313             my $ret_type_len = length ($type_modifier) + length ($pointer)
3314                 + length ($type);
3315             my $ret_type_output = "$type_modifier$xref$pointer"
3316                 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
3318             $desc  .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
3320             my $sourceparams = $SourceSymbolParams{$symbol};
3321             my @params = split ("\n", $SignalPrototypes[$i]);
3322             my $j;
3323             my $l;
3324             my $type_len = length("gpointer");
3325             my $name_len = length("user_data");
3326             # do two passes, the first one is to calculate padding
3327             for ($l = 0; $l < 2; $l++) {
3328                 for ($j = 0; $j <= $#params; $j++) {
3329                     # allow alphanumerics, '_', '[' & ']' in param names
3330                     if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
3331                         $type = $1;
3332                         $pointer = $2;
3333                         if (defined($sourceparams)) {
3334                             $name = $$sourceparams[$PARAM_FIELD_COUNT * $j];
3335                         }
3336                         else {
3337                             $name = $3;
3338                         }
3339                         if (!defined($name)) {
3340                             $name = "arg$j";
3341                         }
3342                         if ($l == 0) {
3343                             if (length($type) + length($pointer) > $type_len) {
3344                                 $type_len = length($type) + length($pointer);
3345                             }
3346                             if (length($name) > $name_len) {
3347                                 $name_len = length($name);
3348                             }
3349                         }
3350                         else {
3351                             $xref = &MakeXRef ($type, &tagify($type, "type"));
3352                             $pad = ' ' x ($type_len - length($type) - length($pointer));
3353                             $desc .= "$xref$pad $pointer$name,\n";
3354                             $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
3355                         }
3356                     } else {
3357                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3358                              "Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]");
3359                     }
3360                 }
3361             }
3362             $xref = &MakeXRef ("gpointer", &tagify("gpointer", "type"));
3363             $pad = ' ' x ($type_len - length("gpointer"));
3364             $desc  .= "$xref$pad user_data)";
3366             my $flags = $SignalFlags[$i];
3367             my $flags_string = "";
3369             if (defined ($flags)) {
3370               if ($flags =~ m/f/) {
3371                 $flags_string = "<link linkend=\"G-SIGNAL-RUN-FIRST:CAPS\"><literal>Run First</literal></link>";
3372               }
3373               elsif ($flags =~ m/l/) {
3374                 $flags_string = "<link linkend=\"G-SIGNAL-RUN-LAST:CAPS\"><literal>Run Last</literal></link>";
3375               }
3376               elsif ($flags =~ m/c/) {
3377                 $flags_string = "<link linkend=\"G-SIGNAL-RUN-CLEANUP:CAPS\"><literal>Cleanup</literal></link>";
3378                 $flags_string = "Cleanup";
3379               }
3380               if ($flags =~ m/r/) {
3381                 if ($flags_string) { $flags_string .= " / "; }
3382                 $flags_string = "<link linkend=\"G-SIGNAL-NO-RECURSE:CAPS\"><literal>No Recursion</literal></link>";
3383               }
3384               if ($flags =~ m/d/) {
3385                 if ($flags_string) { $flags_string .= " / "; }
3386                 $flags_string = "<link linkend=\"G-SIGNAL-DETAILED:CAPS\"><literal>Has Details</literal></link>";
3387               }
3388               if ($flags =~ m/a/) {
3389                 if ($flags_string) { $flags_string .= " / "; }
3390                 $flags_string = "<link linkend=\"G-SIGNAL-ACTION:CAPS\"><literal>Action</literal></link>";
3391               }
3392               if ($flags =~ m/h/) {
3393                 if ($flags_string) { $flags_string .= " / "; }
3394                 $flags_string = "<link linkend=\"G-SIGNAL-NO-HOOKS:CAPS\"><literal>No Hooks</literal></link>";
3395               }
3396             }
3398             if ($flags_string)
3399               {
3400                 $synop .= ": $flags_string\n";
3401                 
3402                 $pad = ' ' x (5 + $name_len - length("user_data"));
3403                 $desc  .= "$pad : $flags_string</programlisting>\n";
3404               }
3405             else
3406               {
3407                 $synop .= "\n";
3408                 $desc  .= "</programlisting>\n";
3409               }
3411             $desc .= &MakeDeprecationNote($symbol);
3413             my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
3414             my $parameters_output = 0;
3416             $AllSymbols{$symbol} = 1;
3417             if (defined ($SymbolDocs{$symbol})) {
3418                 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3420                 # Try to insert the parameter table at the author's desired
3421                 # position. Otherwise we need to tag it onto the end.
3422                 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
3423                   $parameters_output = 1;
3424                 }
3425                 $desc .= $symbol_docs;
3427                 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
3428                     $AllDocumentedSymbols{$symbol} = 1;
3429                 }
3430             }
3432             if ($parameters_output == 0) {
3433                 $desc .= $parameters;
3434               }
3435             $desc .= OutputSymbolTraits ($symbol);
3436             $desc .= "</refsect2>";
3437         }
3438     }
3439     return ($synop, $desc);
3443 #############################################################################
3444 # Function    : GetArgs
3445 # Description : Returns the synopsis and detailed description DocBook output
3446 #               for the Args of a given GtkObject subclass.
3447 # Arguments   : $object - the GtkObject subclass, e.g. 'GtkButton'.
3448 #############################################################################
3450 sub GetArgs {
3451     my ($object) = @_;
3452     my $synop = "";
3453     my $desc = "";
3454     my $child_synop = "";
3455     my $child_desc = "";
3456     my $style_synop = "";
3457     my $style_desc = "";
3459     my $i;
3460     for ($i = 0; $i <= $#ArgObjects; $i++) {
3461         if ($ArgObjects[$i] eq $object) {
3462             #print "Found arg: $ArgNames[$i]\n";
3463             my $name = $ArgNames[$i];
3464             my $flags = $ArgFlags[$i];
3465             my $flags_string = "";
3466             my $kind = "";
3467             my $id_sep = "";
3469             if ($flags =~ m/c/) {
3470                 $kind = "child property";
3471                 $id_sep = "c-";
3472             }
3473             elsif ($flags =~ m/s/) {
3474                 $kind = "style property";
3475                 $id_sep = "s-";
3476             }
3477             else {
3478                 $kind = "property";
3479             }
3481             # Remember only one colon so we don't clash with signals.
3482             my $symbol = "${object}:${name}";
3483             # use two dashes and ev. an extra separator here for the same reason.
3484             my $id = &CreateValidSGMLID ("$object--$id_sep$name");
3486             my $type = $ArgTypes[$i];
3487             my $type_output;
3488             my $range = $ArgRanges[$i];
3489             my $range_output = CreateValidSGML ($range);
3490             my $default = $ArgDefaults[$i];
3491             my $default_output = CreateValidSGML ($default);
3493             if ($type eq "GtkString") {
3494                 $type = "char*";
3495             }
3496             if ($type eq "GtkSignal") {
3497                 $type = "GtkSignalFunc, gpointer";
3498                 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
3499                     . &MakeXRef ("gpointer");
3500             } elsif ($type =~ m/^(\w+)\*$/) {
3501                 $type_output = &MakeXRef ($1, &tagify($1, "type")) . "*";
3502             } else {
3503                 $type_output = &MakeXRef ($type, &tagify($type, "type"));
3504             }
3506             if ($flags =~ m/r/) {
3507                 $flags_string = "Read";
3508             }
3509             if ($flags =~ m/w/) {
3510                 if ($flags_string) { $flags_string .= " / "; }
3511                 $flags_string .= "Write";
3512             }
3513             if ($flags =~ m/x/) {
3514                 if ($flags_string) { $flags_string .= " / "; }
3515                 $flags_string .= "Construct";
3516             }
3517             if ($flags =~ m/X/) {
3518                 if ($flags_string) { $flags_string .= " / "; }
3519                 $flags_string .= "Construct Only";
3520             }
3522             $AllSymbols{$symbol} = 1;
3523             my $blurb;
3524             if (defined($SymbolDocs{$symbol}) &&
3525                 !IsEmptyDoc($SymbolDocs{$symbol})) {
3526                 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3527                 #print ".. [$SymbolDocs{$symbol}][$blurb]\n";
3528                 $AllDocumentedSymbols{$symbol} = 1;
3529             }
3530             else {
3531                 if (!($ArgBlurbs[$i] eq "")) {
3532                     $AllDocumentedSymbols{$symbol} = 1;
3533                 } else {
3534                     # FIXME: print a warning?
3535                     #print ".. no description\n";
3536                 }
3537                 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
3538             }
3540             my $pad1 = " " x (24 - length ($name));
3541             my $pad2 = " " x (20 - length ($type));
3543             my $arg_synop = "  &quot;<link linkend=\"$id\">$name</link>&quot;$pad1 $type_output $pad2 : $flags_string\n";
3544             my $arg_desc = "<refsect2 id=\"$id\" role=\"property\"><title>The <literal>&quot;$name&quot;</literal> $kind</title>\n";
3545             $arg_desc .= MakeIndexterms($symbol, $id);
3546             $arg_desc .= "\n";
3547             $arg_desc .= OutputSymbolExtraLinks($symbol);
3549             $arg_desc .= "<programlisting>  &quot;$name&quot;$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
3550             $arg_desc .= &MakeDeprecationNote($symbol);
3551             $arg_desc .= $blurb;
3552             if ($range ne "") {
3553                 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
3554             }
3555             if ($default ne "") {
3556                 $arg_desc .= "<para>Default value: $default_output</para>\n";
3557             }
3558             $arg_desc .= OutputSymbolTraits ($symbol);
3559             $arg_desc .= "</refsect2>\n";
3561             if ($flags =~ m/c/) {
3562                 $child_synop .= $arg_synop;
3563                 $child_desc .= $arg_desc;
3564             }
3565             elsif ($flags =~ m/s/) {
3566                 $style_synop .= $arg_synop;
3567                 $style_desc .= $arg_desc;
3568             }
3569             else {
3570                 $synop .= $arg_synop;
3571                 $desc .= $arg_desc;
3572             }
3573         }
3574     }
3575     return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
3579 #############################################################################
3580 # Function    : ReadSourceDocumentation
3581 # Description : This reads in the documentation embedded in comment blocks
3582 #               in the source code (for Gnome).
3584 #               Parameter descriptions override any in the template files.
3585 #               Function descriptions are placed before any description from
3586 #               the template files.
3588 #               It recursively descends the source directory looking for .c
3589 #               files and scans them looking for specially-formatted comment
3590 #               blocks.
3592 # Arguments   : $source_dir - the directory to scan.
3593 #############m###############################################################
3595 sub ReadSourceDocumentation {
3596     my ($source_dir) = @_;
3597     my ($file, $dir, @suffix_list, $suffix);
3598     #print "Scanning source directory: $source_dir\n";
3600     # This array holds any subdirectories found.
3601     my (@subdirs) = ();
3603     @suffix_list = split (/,/, $SOURCE_SUFFIXES);
3605     opendir (SRCDIR, $source_dir)
3606         || die "Can't open source directory $source_dir: $!";
3608     foreach $file (readdir (SRCDIR)) {
3609       if ($file =~ /^\./) {
3610         next;
3611       } elsif (-d "$source_dir/$file") {
3612         push (@subdirs, $file);
3613       } elsif (@suffix_list) {
3614         foreach $suffix (@suffix_list) {
3615           if ($file =~ m/\.\Q${suffix}\E$/) {
3616             &ScanSourceFile ("$source_dir/$file");
3617           }
3618         }
3619       } elsif ($file =~ m/\.[ch]$/) {
3620         &ScanSourceFile ("$source_dir/$file");
3621       }
3622     }
3623     closedir (SRCDIR);
3625     # Now recursively scan the subdirectories.
3626     foreach $dir (@subdirs) {
3627         next if ($IGNORE_FILES =~ m/(\s|^)\Q${dir}\E(\s|$)/);
3628         &ReadSourceDocumentation ("$source_dir/$dir");
3629     }
3633 #############################################################################
3634 # Function    : ScanSourceFile
3635 # Description : Scans one source file looking for specially-formatted comment
3636 #               blocks. Later &MergeSourceDocumentation is used to merge any
3637 #               documentation found with the documentation already read in
3638 #               from the template files.
3640 # Arguments   : $file - the file to scan.
3641 #############################################################################
3643 sub ScanSourceFile {
3644     my ($file) = @_;
3645     my $basename;
3647     if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
3648         $basename = $1;
3649     } else {
3650         &LogWarning ($file, 1, "Can't find basename for this filename.");
3651         $basename = $file;
3652     }
3654     # Check if the basename is in the list of files to ignore.
3655     if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
3656         return;
3657     }
3659     #print "DEBUG: Scanning $file\n";
3661     open (SRCFILE, $file)
3662         || die "Can't open $file: $!";
3663     my $in_comment_block = 0;
3664     my $symbol;
3665     my ($in_description, $in_return, $in_since, $in_stability, $in_deprecated);
3666     my ($description, $return_desc, $return_start, $return_style);
3667     my ($since_desc, $stability_desc, $deprecated_desc);
3668     my $current_param;
3669     my $ignore_broken_returns;
3670     my @params;
3671     while (<SRCFILE>) {
3672         # Look for the start of a comment block.
3673         if (!$in_comment_block) {
3674             if (m%^\s*/\*.*\*/%) {
3675                 #one-line comment - not gtkdoc
3676             } elsif (m%^\s*/\*\*\s%) {
3677                 #print "Found comment block start\n";
3679                 $in_comment_block = 1;
3681                 # Reset all the symbol data.
3682                 $symbol = "";
3683                 $in_description = 0;
3684                 $in_return = 0;
3685                 $in_since = 0;
3686                 $in_deprecated = 0;
3687                 $in_stability = 0;
3688                 $description = "";
3689                 $return_desc = "";
3690                 $return_style = "";
3691                 $since_desc = "";
3692                 $deprecated_desc = "";
3693                 $stability_desc = "";
3694                 $current_param = -1;
3695                 $ignore_broken_returns = 0;
3696                 @params = ();
3697             }
3698             next;
3699         }
3701         # We're in a comment block. Check if we've found the end of it.
3702         if (m%^\s*\*+/%) {
3703             if (!$symbol) {
3704                 # maybe its not even meant to be a gtk-doc comment?
3705                 &LogWarning ($file, $., "Symbol name not found at the start of the comment block.");
3706             } else {
3707                 # Add the return value description onto the end of the params.
3708                 if ($return_desc) {
3709                     push (@params, "Returns");
3710                     push (@params, $return_desc);
3711                     if ($return_style eq 'broken') {
3712                         &LogWarning ($file, $., "Free-form return value description in $symbol. Use `Returns:' to avoid ambiguities.");
3713                     }
3714                 }
3715                 # Convert special SGML characters
3716                 $description = &ConvertSGMLChars ($symbol, $description);
3717                 my $k;
3718                 for ($k = 1; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3719                     $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
3720                 }
3722                 # Handle Section docs
3723                 if ($symbol =~ m/SECTION:\s*(.*)/) {
3724                     my $real_symbol=$1;
3725                     my $key;
3727                     if (scalar %KnownSymbols) {
3728                         if ((! defined($KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"})) || $KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"} != 1) {
3729                             &LogWarning ($file, $., "Section $real_symbol is not defined in the $MODULE-section.txt file.");
3730                         }
3731                     }
3733                     #print "SECTION DOCS found in source for : '$real_symbol'\n";
3734                     $ignore_broken_returns = 1;
3735                     for ($k = 0; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3736                         #print "   '".$params[$k]."'\n";
3737                         $params[$k] = "\L$params[$k]";
3738                         undef $key;
3739                         if ($params[$k] eq "short_description") {
3740                             $key = "$TMPL_DIR/$real_symbol:Short_Description";
3741                         } elsif ($params[$k] eq "see_also") {
3742                             $key = "$TMPL_DIR/$real_symbol:See_Also";
3743                         } elsif ($params[$k] eq "title") {
3744                             $key = "$TMPL_DIR/$real_symbol:Title";
3745                         } elsif ($params[$k] eq "stability") {
3746                             $key = "$TMPL_DIR/$real_symbol:Stability_Level";
3747                         } elsif ($params[$k] eq "section_id") {
3748                             $key = "$TMPL_DIR/$real_symbol:Section_Id";
3749                         } elsif ($params[$k] eq "include") {
3750                             $key = "$TMPL_DIR/$real_symbol:Include";
3751                         } elsif ($params[$k] eq "image") {
3752                             $key = "$TMPL_DIR/$real_symbol:Image";
3753                         }
3754                         if (defined($key)) {
3755                             $SourceSymbolDocs{$key}=$params[$k+1];
3756                             $SourceSymbolSourceFile{$key} = $file;
3757                             $SourceSymbolSourceLine{$key} = $.;
3758                         }
3759                     }
3760                     $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
3761                     $SourceSymbolSourceFile{"$TMPL_DIR/$real_symbol:Long_Description"} = $file;
3762                     $SourceSymbolSourceLine{"$TMPL_DIR/$real_symbol:Long_Description"} = $.;
3763                     #$SourceSymbolTypes{$symbol} = "SECTION";
3764                 } else {
3765                     #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
3766                     $SourceSymbolDocs{$symbol} = $description;
3767                     $SourceSymbolParams{$symbol} = [ @params ];
3768                     # FIXME $SourceSymbolTypes{$symbol} = "STRUCT,SIGNAL,ARG,FUNCTION,MACRO";
3769                     #if (defined $DeclarationTypes{$symbol}) {
3770                     #    $SourceSymbolTypes{$symbol} = $DeclarationTypes{$symbol}
3771                     #}
3772                     $SourceSymbolSourceFile{$symbol} = $file;
3773                     $SourceSymbolSourceLine{$symbol} = $.;
3774                 }
3776                 if ($since_desc) {
3777                      ($since_desc, my @extra_lines) = split ("\n", $since_desc);
3778                      $since_desc =~ s/^\s+//;
3779                      $since_desc =~ s/\s+$//;
3780                      #print "Since($symbol) : [$since_desc]\n";
3781                      $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
3782                      if(scalar @extra_lines) {
3783                          &LogWarning ($file, $., "multi-line since docs found");
3784                      }
3785                 }
3787                 if ($stability_desc) {
3788                     $stability_desc = &ParseStabilityLevel($stability_desc, $file, $., "Stability level for $symbol");
3789                     $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
3790                 }
3792                 if ($deprecated_desc) {
3793                     if (exists $Deprecated{$symbol}) {
3794                     }
3795                     else {
3796                          # don't warn for signals and properties
3797                          #if ($symbol !~ m/::?(.*)/) {
3798                          if (defined $DeclarationTypes{$symbol}) {
3799                              &LogWarning ($file, $., 
3800                                  "$symbol is deprecated in the inline comments, but no deprecation guards were found around the declaration.".
3801                                  " (See the --deprecated-guards option for gtkdoc-scan.)");
3802                          }
3803                     }
3804                     $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
3805                 }
3806             }
3808             $in_comment_block = 0;
3809             next;
3810         }
3812         # Get rid of ' * ' at start of every line in the comment block.
3813         s%^\s*\*\s?%%;
3814         # But make sure we don't get rid of the newline at the end.
3815         if (!$_) {
3816             $_ = "\n";
3817         }
3818         #print "DEBUG: scanning :$_";
3820         # If we haven't found the symbol name yet, look for it.
3821         if (!$symbol) {
3822             if (m%^\s*(SECTION:\s*\S+)%) {
3823                 $symbol = $1;
3824                 #print "SECTION DOCS found in source for : '$symbol'\n";
3825                 $ignore_broken_returns = 1;
3826             } elsif (m%^\s*([\w:-]*\w)\s*:?\s*(\([a-z ]+\)\s*)*$%) {
3827                 $symbol = $1;
3828                 #print "SYMBOL DOCS found in source for : '$symbol'\n";
3829             }
3830             next;
3831         }
3833         # If we're in the return value description, add it to the end.
3834         if ($in_return) {
3835             # If we find another valid returns line, we assume that the first
3836             # one was really part of the description.
3837             if (m/^\s*(returns:|return\s+value:)/i) {
3838                 if ($return_style eq 'broken') {
3839                     $description .= $return_start . $return_desc;
3840                 }
3841                 $return_start = $1;
3842                 if ($return_style eq 'sane') {
3843                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3844                 }
3845                 $return_style = 'sane';
3846                 $ignore_broken_returns = 1;
3847                 $return_desc = $';
3848             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3849                 $description .= $return_start . $return_desc;
3850                 $return_start = $1;
3851                 $return_style = 'broken';
3852                 $return_desc = $';
3853             } elsif (m%^\s*since:%i) {
3854                 $since_desc = $';
3855                 $in_since = 1;
3856                 $in_return = 0;
3857             } elsif (m%^\s*stability:%i) {
3858                 $stability_desc = $';
3859                 $in_stability = 1;
3860                 $in_return = 0;
3861             } elsif (m%^\s*deprecated:%i) {
3862                 $deprecated_desc = $';
3863                 $in_deprecated = 1;
3864                 $in_return = 0;
3865             } else {
3866                 $return_desc .= $_;
3867             }
3868             next;
3869         }
3871         if ($in_since) {
3872             if (m/^\s*(returns:|return\s+value:)/i) {
3873                 if ($return_style eq 'broken') {
3874                     $description .= $return_start . $return_desc;
3875                 }
3876                 $return_start = $1;
3877                 if ($return_style eq 'sane') {
3878                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3879                 }
3880                 $return_style = 'sane';
3881                 $ignore_broken_returns = 1;
3882                 $return_desc = $';
3883                 $in_return = 1;
3884                 $in_since = 0;
3885             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3886                 $return_start = $1;
3887                 $return_style = 'broken';
3888                 $return_desc = $';
3889                 $in_return = 1;
3890                 $in_since = 0;
3891             } elsif (m%^\s*deprecated:%i) {
3892                 $deprecated_desc = $';
3893                 $in_deprecated = 1;
3894                 $in_since = 0;
3895             } elsif (m%^\s*stability:%i) {
3896                 $stability_desc = $';
3897                 $in_stability = 1;
3898                 $in_since = 0;
3899             } else {
3900                 $since_desc .= $_;
3901             }
3902             next;
3903         }
3905         if ($in_stability) {
3906             if (m/^\s*(returns:|return\s+value:)/i) {
3907                 if ($return_style eq 'broken') {
3908                     $description .= $return_start . $return_desc;
3909                 }
3910                 $return_start = $1;
3911                 if ($return_style eq 'sane') {
3912                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3913                 }
3914                 $return_style = 'sane';
3915                 $ignore_broken_returns = 1;
3916                 $return_desc = $';
3917                 $in_return = 1;
3918                 $in_stability = 0;
3919             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3920                 $return_start = $1;
3921                 $return_style = 'broken';
3922                 $return_desc = $';
3923                 $in_return = 1;
3924                 $in_stability = 0;
3925             } elsif (m%^\s*deprecated:%i) {
3926                 $deprecated_desc = $';
3927                 $in_deprecated = 1;
3928                 $in_stability = 0;
3929             } elsif (m%^\s*since:%i) {
3930                 $since_desc = $';
3931                 $in_since = 1;
3932                 $in_stability = 0;
3933             } else {
3934                 $stability_desc .= $_;
3935             }
3936             next;
3937         }
3939         if ($in_deprecated) {
3940             if (m/^\s*(returns:|return\s+value:)/i) {
3941                 if ($return_style eq 'broken') {
3942                     $description .= $return_start . $return_desc;
3943                 }
3944                 $return_start = $1;
3945                 if ($return_style eq 'sane') {
3946                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3947                 }
3948                 $return_style = 'sane';
3949                 $ignore_broken_returns = 1;
3950                 $return_desc = $';
3951                 $in_return = 1;
3952                 $in_deprecated = 0;
3953             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3954                 $return_start = $1;
3955                 $return_style = 'broken';
3956                 $return_desc = $';
3957                 $in_return = 1;
3958                 $in_deprecated = 0;
3959             } elsif (m%^\s*since:%i) {
3960                 $since_desc = $';
3961                 $in_since = 1;
3962                 $in_deprecated = 0;
3963             } elsif (m%^\s*stability:%i) {
3964                 $stability_desc = $';
3965                 $in_stability = 1;
3966                 $in_deprecated = 0;
3967             } else {
3968                 $deprecated_desc .= $_;
3969             }
3970             next;
3971         }
3973         # If we're in the description part, check for the 'Returns:' line.
3974         # If that isn't found, add the text to the end.
3975         if ($in_description) {
3976             # Get rid of 'Description:'
3977             s%^\s*Description:%%;
3979             if (m/^\s*(returns:|return\s+value:)/i) {
3980                 if ($return_style eq 'broken') {
3981                     $description .= $return_start . $return_desc;
3982                 }
3983                 $return_start = $1;
3984                 if ($return_style eq 'sane') {
3985                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3986                 }
3987                 $return_style = 'sane';
3988                 $ignore_broken_returns = 1;
3989                 $return_desc = $';
3990                 $in_return = 1;
3991                 next;
3992             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3993                 $return_start = $1;
3994                 $return_style = 'broken';
3995                 $return_desc = $';
3996                 $in_return = 1;
3997                 next;
3998             } elsif (m%^\s*since:%i) {
3999                 $since_desc = $';
4000                 $in_since = 1;
4001                 next;
4002             } elsif (m%^\s*deprecated:%i) {
4003                 $deprecated_desc = $';
4004                 $in_deprecated = 1;
4005                 next;
4006             } elsif (m%^\s*stability:%i) {
4007                 $stability_desc = $';
4008                 $in_stability = 1;
4009                 next;
4010             }
4012             $description .= $_;
4013             next;
4014         }
4016         # We must be in the parameters. Check for the empty line below them.
4017         if (m%^\s*$%) {
4018             $in_description = 1;
4019             next;
4020         }
4022         # Look for a parameter name.
4023         if (m%^\s*@(\S+)\s*:\s*%) {
4024             my $param_name = $1;
4025             my $param_desc = $';
4027             #print "Found parameter: $param_name\n";
4028             # Allow '...' as the Varargs parameter.
4029             if ($param_name eq "...") {
4030                 $param_name = "Varargs";
4031             }
4032             if ("\L$param_name" eq "returns") {
4033                 $return_style = 'sane';
4034                 $ignore_broken_returns = 1;
4035             }
4036             push (@params, $param_name);
4037             push (@params, $param_desc);
4038             $current_param += $PARAM_FIELD_COUNT;
4039             next;
4040         }
4042         # We must be in the middle of a parameter description, so add it on
4043         # to the last element in @params.
4044         if ($current_param == -1) {
4045             &LogWarning ($file, $., "Parsing comment block file : parameter expected.");
4046         } else {
4047             $params[$#params] .= $_;
4048         }
4049     }
4050     close (SRCFILE);
4053 #############################################################################
4054 # Function    : OutputMissingDocumentation
4055 # Description : Outputs report of documentation coverage to a file
4057 # Arguments   : none
4058 #############################################################################
4060 sub OutputMissingDocumentation {
4061     my $old_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.txt";
4062     my $new_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.new";
4064     my $n_documented = 0;
4065     my $n_incomplete = 0;
4066     my $total = 0;
4067     my $symbol;
4068     my $percent;
4069     my $msg;
4070     my $buffer = "";
4071     my $buffer_deprecated = "";
4072     my $buffer_descriptions = "";
4073     
4074     open(UNDOCUMENTED, ">$new_undocumented_file")
4075       || die "Can't create $new_undocumented_file";
4076     
4077     foreach $symbol (sort (keys (%AllSymbols))) {
4078         # FIXME: should we print LogWarnings for undocumented stuff?
4079         # DEBUG
4080         #my $ssfile = &GetSymbolSourceFile($symbol);
4081         #my $ssline = &GetSymbolSourceLine($symbol);
4082         #my $location = "defined at " . (defined($ssfile)?$ssfile:"?") . ":" . (defined($ssline)?$ssline:"0") . "\n";
4083         # DEBUG
4084         if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include|Section_Id|Image)/) {
4085             $total++;
4086             if (exists ($AllDocumentedSymbols{$symbol})) {
4087                 $n_documented++;
4088                 if (exists ($AllIncompleteSymbols{$symbol})) {
4089                     $n_incomplete++;
4090                     $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4091                     #$buffer .= "\t0: ".$location;
4092                 }
4093             } elsif (exists $Deprecated{$symbol}) {
4094                 if (exists ($AllIncompleteSymbols{$symbol})) {
4095                     $n_incomplete++;
4096                     $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4097                     #$buffer .= "\t1a: ".$location;
4098                 } else {
4099                     $buffer_deprecated .= $symbol . "\n";
4100                     #$buffer .= "\t1b: ".$location;
4101                 }
4102             } else {
4103                 if (exists ($AllIncompleteSymbols{$symbol})) {
4104                     $n_incomplete++;
4105                     $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4106                     #$buffer .= "\t2a: ".$location;
4107                 } else {
4108                     $buffer .= $symbol . "\n";
4109                     #$buffer .= "\t2b: ".$location;
4110                 }
4111             }
4112         } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
4113             $total++;
4114             #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
4115             #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
4116             #print "%%%% $symbol : $len1,$len2\n";
4117             if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
4118             || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
4119               $n_documented++;
4120             } else {
4121               # cut off the leading namespace ($TMPL_DIR)
4122               $symbol =~ m/^.*\/(.*)$/;
4123               $buffer_descriptions .= $1 . "\n";
4124             }
4125         }
4126     }
4127     
4128     $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
4129     
4130     if ($total == 0) {
4131       $percent = 100;
4132     } else {
4133       $percent = ($n_documented / $total) * 100.0;
4134     }
4135     
4136     printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
4137     print UNDOCUMENTED "$n_documented symbols documented.\n";
4138     print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
4139     print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
4140     
4141     print UNDOCUMENTED $buffer;
4142     close (UNDOCUMENTED);
4143     
4144     return &UpdateFileIfChanged ($old_undocumented_file, $new_undocumented_file, 0);
4145     
4146     printf "%.0f%% symbol docs coverage", $percent;
4147     print "($n_documented symbols documented, $n_incomplete symbols incomplete, " . ($total - $n_documented) . " not documented)\n";
4148     print "See $MODULE-undocumented.txt for a list of missing docs.\nThe doc coverage percentage doesn't include intro sections.\n";
4152 #############################################################################
4153 # Function    : OutputUndeclaredSymbols
4154 # Description : Outputs symbols that are listed in the section file, but not
4155 #               declaration is found in the sources
4157 # Arguments   : none
4158 #############################################################################
4160 sub OutputUndeclaredSymbols {
4161     my $old_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.txt";
4162     my $new_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.new";
4164     open(UNDECLARED, ">$new_undeclared_file")
4165         || die "Can't create $new_undeclared_file";
4167     if (%UndeclaredSymbols) {
4168         print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
4169         print UNDECLARED "\n";
4170         print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
4171     }
4172     close(UNDECLARED);
4174     return &UpdateFileIfChanged ($old_undeclared_file, $new_undeclared_file, 0);
4177 #############################################################################
4178 # Function    : OutputUnusedSymbols
4179 # Description : Outputs symbols that are documented in comments, but not
4180 #               declared in the sources
4182 # Arguments   : none
4183 #############################################################################
4185 sub OutputUnusedSymbols {
4186     my $num_unused = 0;
4187     my $old_unused_file = "$ROOT_DIR/$MODULE-unused.txt";
4188     my $new_unused_file = "$ROOT_DIR/$MODULE-unused.new";
4190     open (UNUSED, ">$new_unused_file")
4191         || die "Can't open $new_unused_file";
4192     my ($symbol);
4193     foreach $symbol (sort keys (%Declarations)) {
4194         if (!defined ($DeclarationOutput{$symbol})) {
4195             print (UNUSED "$symbol\n");
4196             $num_unused++;
4197         }
4198     }
4199     foreach $symbol (sort (keys (%AllUnusedSymbols))) {
4200         print (UNUSED "$symbol(" . $AllUnusedSymbols{$symbol} . ")\n");
4201         $num_unused++;
4202     }
4203     close (UNUSED);
4204     if ($num_unused != 0) {
4205         &LogWarning ($old_unused_file, 1, "$num_unused unused declarations.".
4206             "They should be added to $MODULE-sections.txt in the appropriate place.");
4207     }
4208     
4209     return &UpdateFileIfChanged ($old_unused_file, $new_unused_file, 0); 
4213 #############################################################################
4214 # Function    : OutputAllSymbols
4215 # Description : Outputs list of all symbols to a file
4217 # Arguments   : none
4218 #############################################################################
4220 sub OutputAllSymbols {
4221      my $n_documented = 0;
4222      my $total = 0;
4223      my $symbol;
4224      my $percent;
4225      my $msg;
4227      open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
4228           || die "Can't create $ROOT_DIR/$MODULE-symbols.txt: $!";
4230      foreach $symbol (sort (keys (%AllSymbols))) {
4231           print SYMBOLS $symbol . "\n";
4232      }
4234      close (SYMBOLS);
4237 #############################################################################
4238 # Function    : OutputSymbolsWithoutSince
4239 # Description : Outputs list of all symbols without a since tag to a file
4241 # Arguments   : none
4242 #############################################################################
4244 sub OutputSymbolsWithoutSince {
4245      my $n_documented = 0;
4246      my $total = 0;
4247      my $symbol;
4248      my $percent;
4249      my $msg;
4251      open (SYMBOLS, ">$ROOT_DIR/$MODULE-nosince.txt")
4252           || die "Can't create $ROOT_DIR/$MODULE-nosince.txt: $!";
4254      foreach $symbol (sort (keys (%SourceSymbolDocs))) {
4255          if (!defined $Since{$symbol}) {
4256              print SYMBOLS $symbol . "\n";
4257          }
4258      }
4260      close (SYMBOLS);
4264 #############################################################################
4265 # Function    : MergeSourceDocumentation
4266 # Description : This merges documentation read from a source file into the
4267 #               documentation read in from a template file.
4269 #               Parameter descriptions override any in the template files.
4270 #               Function descriptions are placed before any description from
4271 #               the template files.
4273 # Arguments   : none
4274 #############################################################################
4276 sub MergeSourceDocumentation {
4277     my $symbol;
4278     my @Symbols;
4280     if (scalar %SymbolDocs) {
4281         @Symbols=keys (%SymbolDocs);
4282         #print "num existing entries: ".(scalar @Symbols)."\n";
4283         #print "  ",$Symbols[0], " ",$Symbols[1],"\n";
4284     }
4285     else {
4286         # filter scanned declarations, with what we suppress from -sections.txt
4287         my %tmp = ();
4288         foreach $symbol (keys (%Declarations)) {
4289             if (defined($KnownSymbols{$symbol}) && $KnownSymbols{$symbol} == 1) {
4290                 $tmp{$symbol}=1;
4291             }
4292         }
4293         # , add the rest from -sections.txt
4294         foreach $symbol (keys (%KnownSymbols)) {
4295             if ($KnownSymbols{$symbol} == 1) {
4296                 $tmp{$symbol}=1;
4297             }
4298         }
4299         # and add whats found in the source
4300         foreach $symbol (keys (%SourceSymbolDocs)) {
4301             $tmp{$symbol}=1;
4302         }
4303         @Symbols = keys (%tmp);
4304         #print "num source entries: ".(scalar @Symbols)."\n";
4305     }
4306     foreach $symbol (@Symbols) {
4307         $AllSymbols{$symbol} = 1;
4309         my $have_tmpl_docs = 0;
4311         ## see if the symbol is documented in template
4312         my $tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4313         my $check_tmpl_doc =$tmpl_doc;
4314         # remove all xml-tags and whitespaces 
4315         $check_tmpl_doc =~ s/<.*?>//g;
4316         $check_tmpl_doc =~ s/\s//g;
4317         # anything left ?
4318         if ($check_tmpl_doc ne "") {
4319             $have_tmpl_docs = 1;
4320             #print "## [$check_tmpl_doc]\n";
4321         } else {
4322             # if the docs have just an empty para, don't merge that.
4323             $check_tmpl_doc = $tmpl_doc;
4324             $check_tmpl_doc =~ s/(\s|\n)//msg;
4325             if ($check_tmpl_doc eq "<para></para>") {
4326                $tmpl_doc = ""; 
4327             }
4328         }
4330         if (exists ($SourceSymbolDocs{$symbol})) {
4331             my $type = $DeclarationTypes {$symbol};
4333             #print "merging [$symbol] from source\n";
4335             my $item = "Parameter";
4336             if (defined ($type)) {
4337                 if ($type eq 'STRUCT') {
4338                     $item = "Field";
4339                 } elsif ($type eq 'ENUM') {
4340                     $item = "Value";
4341                 } elsif ($type eq 'UNION') {
4342                     $item = "Field";
4343                 }
4344             } else {
4345                 $type="SIGNAL";
4346             }
4348             my $src_doc = $SourceSymbolDocs{$symbol};
4349             # remove leading and training whitespaces
4350             $src_doc =~ s/^\s+//;
4351             $src_doc =~ s/\s+$//;
4352             
4353             # Don't output warnings for overridden titles as titles are
4354             # automatically generated in the -sections.txt file, and thus they
4355             # are often overridden.
4356             if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
4357                 # check if content is different
4358                 if ($tmpl_doc ne $src_doc) {
4359                     #print "[$tmpl_doc] [$src_doc]\n";
4360                     &LogWarning ($SourceSymbolSourceFile{$symbol}, $SourceSymbolSourceLine{$symbol},
4361                         "Documentation in template ".$SymbolSourceFile{$symbol}.":".$SymbolSourceLine{$symbol}." for $symbol being overridden by inline comments.");
4362                 }
4363             }
4365             if ($src_doc ne "") {
4366                  $AllDocumentedSymbols{$symbol} = 1;
4367             }
4369             # Convert <!--PARAMETERS--> with any blank lines around it to
4370             # a </para> followed by <!--PARAMETERS--> followed by <para>.
4371             $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
4373             # Do not add <para> to nothing, it breaks missing docs checks.
4374             my $src_doc_para = "";
4375             if ($src_doc ne "") {
4376                 # If there is a blank line, finish the paragraph and start another.
4377                 $src_doc = &ConvertBlankLines ($src_doc, $symbol);
4378                 $src_doc_para = "<para>\n$src_doc\n</para>";
4379                 ## fixup xml markup
4380                 # FIXME: this is questionable, as we can't make assumtions on the content really
4381                 #$src_doc_para =~ s%^<para>\n(<refsect[1-9])%$1%gms;
4382                 #$src_doc_para =~ s%^<para>\n<para>%<para>%gms;
4383                 #$src_doc_para =~ s%(</refsect[1-9]>)\n</para>$%$1%gms;
4384                 #print "$symbol : [$src_doc][$src_doc_para]\n";
4385             }
4387             if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
4388                 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4389             } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
4390                 # For the title/summary/see also section docs we don't want to
4391                 # add any <para> tags.
4392                 $SymbolDocs{$symbol} = "$src_doc"
4393             } else {
4394                 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4395             }
4397             # merge parameters
4398             if ($symbol =~ m/.*::.*/) {
4399                 # For signals we prefer the param names from the source docs,
4400                 # since the ones from the templates are likely to contain the
4401                 # artificial argn names which are generated by gtkdoc-scangobj.
4402                 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4403                 # FIXME: we need to check for empty docs here as well!
4404             } else {
4405                 # The templates contain the definitive parameter names and order,
4406                 # so we will not change that. We only override the actual text.
4407                 my $tmpl_params = $SymbolParams{$symbol};
4408                 if (!defined ($tmpl_params)) {
4409                     #print "No merge needed for $symbol\n";
4410                     $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4411                     #  FIXME: we still like to get the number of params and merge
4412                     #  1) we would noticed that params have been removed/renamed
4413                     #  2) we would catch undocumented params
4414                     #  params are not (yet) exported in -decl.txt so that we
4415                     #  could easily grab them :/
4416                 } else {
4417                     my $params = $SourceSymbolParams{$symbol};
4418                     my $j;
4419                     #print "Merge needed for $symbol, tmpl_params: ",$#$tmpl_params,", source_params: ",$#$params," \n";
4420                     for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4421                         my $tmpl_param_name = $$tmpl_params[$j];
4423                         # Allow '...' as the Varargs parameter.
4424                         if ($tmpl_param_name eq "...") {
4425                             $tmpl_param_name = "Varargs";
4426                         }
4428                         # Try to find the param in the source comment documentation.
4429                         my $found = 0;
4430                         my $k;
4431                         #print "  try merge param $tmpl_param_name\n";
4432                         for ($k = 0; $k <= $#$params; $k += $PARAM_FIELD_COUNT) {
4433                             my $param_name = $$params[$k];
4434                             my $param_desc = $$params[$k + 1];
4436                             #print "    test param  $param_name\n";
4437                             # We accept changes in case, since the Gnome source
4438                             # docs contain a lot of these.
4439                             if ("\L$param_name" eq "\L$tmpl_param_name") {
4440                                 $found = 1;
4442                                 # Override the description.
4443                                 $$tmpl_params[$j + 1] = $param_desc;
4445                                 # Set the name to "" to mark it as used.
4446                                 $$params[$k] = "";
4447                                 last;
4448                             }
4449                         }
4451                         # If it looks like the parameters are there, but not
4452                         # in the right place, try to explain a bit better.
4453                         if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
4454                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4455                                 "Parameters for $symbol must start on the line immediately after the function or macro name.");
4456                         }
4457                     }
4459                     # Now we output a warning if parameters have been described which
4460                     # do not exist.
4461                     for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
4462                         my $param_name = $$params[$j];
4463                         if ($param_name) {
4464                             # the template builder cannot detect if a macro returns
4465                             # a result or not
4466                             if(($type eq "MACRO") && ($param_name eq "Returns")) {
4467                                 # FIXME: do we need to add it then to tmpl_params[] ?
4468                                 my $num=$#$tmpl_params;
4469                                 #print "  adding Returns: to macro docs for $symbol.\n";
4470                                 $$tmpl_params[$num+1]="Returns";
4471                                 $$tmpl_params[$num+2]=$$params[$j+1];
4472                                 next;
4473                             }
4474                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4475                                 "$item described in source code comment block but does not exist. $type: $symbol $item: $param_name.");
4476                         }
4477                     }
4478                 }
4479             }
4480         } else {
4481             if ($have_tmpl_docs) {
4482                 $AllDocumentedSymbols{$symbol} = 1;
4483                 #print "merging [$symbol] from template\n";
4484             }
4485             else {
4486                 #print "[$symbol] undocumented\n";
4487             }
4488         }
4490         # if this symbol is documented, check if docs are complete
4491         $check_tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4492         # remove all xml-tags and whitespaces
4493         $check_tmpl_doc =~ s/<.*?>//g;
4494         $check_tmpl_doc =~ s/\s//g;
4495         if ($check_tmpl_doc ne "") {
4496             my $tmpl_params = $SymbolParams{$symbol};
4497             if (defined ($tmpl_params)) {
4498                 my $type = $DeclarationTypes {$symbol};
4500                 my $item = "Parameter";
4501                 if (defined ($type)) {
4502                     if ($type eq 'STRUCT') {
4503                         $item = "Field";
4504                     } elsif ($type eq 'ENUM') {
4505                         $item = "Value";
4506                     } elsif ($type eq 'UNION') {
4507                         $item = "Field";
4508                     }
4509                 } else {
4510                     $type="SIGNAL";
4511                 }
4513                 #print "Check param docs for $symbol, tmpl_params: ",$#$tmpl_params," entries, type=$type\n";
4515                 if ($#$tmpl_params > 0) {
4516                     my $j;
4517                     for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4518                         # Output a warning if the parameter is empty and
4519                         # remember for stats.
4520                         my $tmpl_param_name = $$tmpl_params[$j];
4521                         my $tmpl_param_desc = $$tmpl_params[$j + 1];
4522                         if ($tmpl_param_name ne "void" && $tmpl_param_desc !~ m/\S/) {
4523                             if (exists ($AllIncompleteSymbols{$symbol})) {
4524                                 $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
4525                             } else {
4526                                 $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
4527                             }
4528                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4529                                 "$item description for $symbol"."::"."$tmpl_param_name is missing in source code comment block.");
4530                         }
4531                     }
4532                 }
4533                 else {
4534                     if ($#$tmpl_params == 0) {
4535                         $AllIncompleteSymbols{$symbol}="<items>";
4536                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4537                             "$item descriptions for $symbol are missing in source code comment block.");
4538                     }
4539                     # $#$tmpl_params==-1 means we don't know about parameters
4540                     # this unfortunately does not tell if there should be some
4541                 }
4542             }
4543         }
4544    }
4545    #print "num doc entries: ".(scalar %SymbolDocs)."\n";
4548 #############################################################################
4549 # Function    : IsEmptyDoc
4550 # Description : Check if a doc-string is empty. Its also regarded as empty if
4551 #               it only consist of whitespace or e.g. FIXME.
4552 # Arguments   : the doc-string
4553 #############################################################################
4554 sub IsEmptyDoc {
4555     my ($doc) = @_;
4556     
4557     if ($doc =~ /^\s*$/) {
4558         return 1;
4559     }
4561     if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
4562         return 1;
4563     }
4565     return 0;
4569 # This converts blank lines to "</para><para>", but only outside CDATA and
4570 # <programlisting> tags.
4571 sub ConvertBlankLines {
4572     return &ModifyXMLElements ($_[0], $_[1],
4573                                "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
4574                                \&ConvertBlankLinesEndTag,
4575                                \&ConvertBlankLinesCallback);
4579 sub ConvertBlankLinesEndTag {
4580   if ($_[0] eq "<!\[CDATA\[") {
4581     return "]]>";
4582   } elsif ($_[0] eq "|[") {
4583     return "]\\|";
4584   } else {
4585     return "</programlisting>";
4586   }
4589 sub ConvertBlankLinesCallback {
4590   my ($text, $symbol, $tag) = @_;
4592   # If we're not in CDATA or a <programlisting> we convert blank lines so
4593   # they start a new <para>.
4594   if ($tag eq "") {
4595     $text =~ s%\n{2,}%\n</para>\n<para>\n%g;
4596   }
4598   return $text;
4602 #############################################################################
4603 # LIBRARY FUNCTIONS -   These functions are used in both gtkdoc-mkdb and
4604 #                       gtkdoc-mktmpl and should eventually be moved to a
4605 #                       separate library.
4606 #############################################################################
4608 #############################################################################
4609 # Function    : ReadDeclarationsFile
4610 # Description : This reads in a file containing the function/macro/enum etc.
4611 #               declarations.
4613 #               Note that in some cases there are several declarations with
4614 #               the same name, e.g. for conditional macros. In this case we
4615 #               set a flag in the %DeclarationConditional hash so the
4616 #               declaration is not shown in the docs.
4618 #               If a macro and a function have the same name, e.g. for
4619 #               gtk_object_ref, the function declaration takes precedence.
4621 #               Some opaque structs are just declared with 'typedef struct
4622 #               _name name;' in which case the declaration may be empty.
4623 #               The structure may have been found later in the header, so
4624 #               that overrides the empty declaration.
4626 # Arguments   : $file - the declarations file to read
4627 #               $override - if declarations in this file should override
4628 #                       any current declaration.
4629 #############################################################################
4631 sub ReadDeclarationsFile {
4632     my ($file, $override) = @_;
4634     if ($override == 0) {
4635         %Declarations = ();
4636         %DeclarationTypes = ();
4637         %DeclarationConditional = ();
4638         %DeclarationOutput = ();
4639     }
4641     open (INPUT, $file)
4642         || die "Can't open $file: $!";
4643     my $declaration_type = "";
4644     my $declaration_name;
4645     my $declaration;
4646     my $is_deprecated = 0;
4647     while (<INPUT>) {
4648         if (!$declaration_type) {
4649             if (m/^<([^>]+)>/) {
4650                 $declaration_type = $1;
4651                 $declaration_name = "";
4652                 #print "Found declaration: $declaration_type\n";
4653                 $declaration = "";
4654             }
4655         } else {
4656             if (m%^<NAME>(.*)</NAME>%) {
4657                 $declaration_name = $1;
4658             } elsif (m%^<DEPRECATED/>%) {
4659                 $is_deprecated = 1;
4660             } elsif (m%^</$declaration_type>%) {
4661                 #print "Found end of declaration: $declaration_name\n";
4662                 # Check that the declaration has a name
4663                 if ($declaration_name eq "") {
4664                     print "ERROR: $declaration_type has no name $file:$.\n";
4665                 }
4667                 # If the declaration is an empty typedef struct _XXX XXX
4668                 # set the flag to indicate the struct has a typedef.
4669                 if ($declaration_type eq 'STRUCT'
4670                     && $declaration =~ m/^\s*$/) {
4671                     #print "Struct has typedef: $declaration_name\n";
4672                     $StructHasTypedef{$declaration_name} = 1;
4673                 }
4675                 # Check if the symbol is already defined.
4676                 if (defined ($Declarations{$declaration_name})
4677                     && $override == 0) {
4678                     # Function declarations take precedence.
4679                     if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
4680                         # Ignore it.
4681                     } elsif ($declaration_type eq 'FUNCTION') {
4682                         if ($is_deprecated) {
4683                             $Deprecated{$declaration_name} = "";
4684                         }
4685                         $Declarations{$declaration_name} = $declaration;
4686                         $DeclarationTypes{$declaration_name} = $declaration_type;
4687                     } elsif ($DeclarationTypes{$declaration_name}
4688                               eq $declaration_type) {
4689                         # If the existing declaration is empty, or is just a
4690                         # forward declaration of a struct, override it.
4691                         if ($declaration_type eq 'STRUCT') {
4692                             if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4693                                 if ($is_deprecated) {
4694                                     $Deprecated{$declaration_name} = "";
4695                                 }
4696                                 $Declarations{$declaration_name} = $declaration;
4697                             } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4698                                 # Ignore an empty or forward declaration.
4699                             } else {
4700                                 &LogWarning ($file, $., "Structure $declaration_name has multiple definitions.");
4701                             }
4702                         } else {
4703                             # set flag in %DeclarationConditional hash for
4704                             # multiply defined macros/typedefs.
4705                             $DeclarationConditional{$declaration_name} = 1;
4706                         }
4707                     } else {
4708                         &LogWarning ($file, $., "$declaration_name has multiple definitions.");
4709                     }
4710                 } else {
4711                     if ($is_deprecated) {
4712                         $Deprecated{$declaration_name} = "";
4713                     }
4714                     $Declarations{$declaration_name} = $declaration;
4715                     $DeclarationTypes{$declaration_name} = $declaration_type;
4716                 }
4718                 $declaration_type = "";
4719                 $is_deprecated = 0;
4720             } else {
4721                 $declaration .= $_;
4722             }
4723         }
4724     }
4725     close (INPUT);
4729 #############################################################################
4730 # Function    : ReadSignalsFile
4731 # Description : This reads in an existing file which contains information on
4732 #               all GTK signals. It creates the arrays @SignalNames and
4733 #               @SignalPrototypes containing info on the signals. The first
4734 #               line of the SignalPrototype is the return type of the signal
4735 #               handler. The remaining lines are the parameters passed to it.
4736 #               The last parameter, "gpointer user_data" is always the same
4737 #               so is not included.
4738 # Arguments   : $file - the file containing the signal handler prototype
4739 #                       information.
4740 #############################################################################
4742 sub ReadSignalsFile {
4743     my ($file) = @_;
4745     my $in_signal = 0;
4746     my $signal_object;
4747     my $signal_name;
4748     my $signal_returns;
4749     my $signal_flags;
4750     my $signal_prototype;
4752     # Reset the signal info.
4753     @SignalObjects = ();
4754     @SignalNames = ();
4755     @SignalReturns = ();
4756     @SignalFlags = ();
4757     @SignalPrototypes = ();
4759     if (! -f $file) {
4760         return;
4761     }
4762     if (!open (INPUT, $file)) {
4763         warn "Can't open $file - skipping signals\n";
4764         return;
4765     }
4766     while (<INPUT>) {
4767         if (!$in_signal) {
4768             if (m/^<SIGNAL>/) {
4769                 $in_signal = 1;
4770                 $signal_object = "";
4771                 $signal_name = "";
4772                 $signal_returns = "";
4773                 $signal_prototype = "";
4774             }
4775         } else {
4776             if (m/^<NAME>(.*)<\/NAME>/) {
4777                 $signal_name = $1;
4778                 if ($signal_name =~ m/^(.*)::(.*)$/) {
4779                     $signal_object = $1;
4780                     ($signal_name = $2) =~ s/_/-/g;
4781                     #print "Found signal: $signal_name\n";
4782                 } else {
4783                     &LogWarning ($file, $., "Invalid signal name: $signal_name.");
4784                 }
4785             } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
4786                 $signal_returns = $1;
4787             } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4788                 $signal_flags = $1;
4789             } elsif (m%^</SIGNAL>%) {
4790                 #print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
4791                 push (@SignalObjects, $signal_object);
4792                 push (@SignalNames, $signal_name);
4793                 push (@SignalReturns, $signal_returns);
4794                 push (@SignalFlags, $signal_flags);
4795                 push (@SignalPrototypes, $signal_prototype);
4796                 $in_signal = 0;
4797             } else {
4798                 $signal_prototype .= $_;
4799             }
4800         }
4801     }
4802     close (INPUT);
4806 #############################################################################
4807 # Function    : ReadTemplateFile
4808 # Description : This reads in the manually-edited documentation file
4809 #               corresponding to the file currently being created, so we can
4810 #               insert the documentation at the appropriate places.
4811 #               It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
4812 #               is a hash of arrays.
4813 #               NOTE: This function is duplicated in gtkdoc-mktmpl (but
4814 #               slightly different).
4815 # Arguments   : $docsfile - the template file to read in.
4816 #               $skip_unused_params - 1 if the unused parameters should be
4817 #                       skipped.
4818 #############################################################################
4820 sub ReadTemplateFile {
4821     my ($docsfile, $skip_unused_params) = @_;
4823     my $template = "$docsfile.sgml";
4824     if (! -f $template) {
4825         #print "File doesn't exist: $template\n";
4826         return 0;
4827     }
4828     #print "Reading $template\n";
4830     # start with empty hashes, we merge the source comment for each file
4831     # afterwards
4832     %SymbolDocs = ();
4833     %SymbolTypes = ();
4834     %SymbolParams = ();
4836     my $current_type = "";      # Type of symbol being read.
4837     my $current_symbol = "";    # Name of symbol being read.
4838     my $symbol_doc = "";                # Description of symbol being read.
4839     my @params;                 # Parameter names and descriptions of current
4840                                 #   function/macro/function typedef.
4841     my $current_param = -1;     # Index of parameter currently being read.
4842                                 #   Note that the param array contains pairs
4843                                 #   of param name & description.
4844     my $in_unused_params = 0;   # True if we are reading in the unused params.
4845     my $in_deprecated = 0;
4846     my $in_since = 0;
4847     my $in_stability = 0;
4849     open (DOCS, "$template")
4850         || die "Can't open $template: $!";
4851     while (<DOCS>) {
4852         if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
4853             my $type = $1;
4854             my $symbol = $2;
4855             if ($symbol eq "Title"
4856                 || $symbol eq "Short_Description"
4857                 || $symbol eq "Long_Description"
4858                 || $symbol eq "See_Also"
4859                 || $symbol eq "Stability_Level"
4860                 || $symbol eq "Include"
4861                 || $symbol eq "Image") {
4863                 $symbol = $docsfile . ":" . $symbol;
4864             }
4866             #print "Found symbol: $symbol\n";
4867             # Remember file and line for the symbol
4868             $SymbolSourceFile{$symbol} = $template;
4869             $SymbolSourceLine{$symbol} = $.;
4871             # Store previous symbol, but remove any trailing blank lines.
4872             if ($current_symbol ne "") {
4873                 $symbol_doc =~ s/\s+$//;
4874                 $SymbolTypes{$current_symbol} = $current_type;
4875                 $SymbolDocs{$current_symbol} = $symbol_doc;
4877                 # Check that the stability level is valid.
4878                 if ($StabilityLevel{$current_symbol}) {
4879                     $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4880                 }
4882                 if ($current_param >= 0) {
4883                     $SymbolParams{$current_symbol} = [ @params ];
4884                 } else {
4885                     # Delete any existing params in case we are overriding a
4886                     # previously read template.
4887                     delete $SymbolParams{$current_symbol};
4888                 }
4889             }
4890             $current_type = $type;
4891             $current_symbol = $symbol;
4892             $current_param = -1;
4893             $in_unused_params = 0;
4894             $in_deprecated = 0;
4895             $in_since = 0;
4896             $in_stability = 0;
4897             $symbol_doc = "";
4898             @params = ();
4900         } elsif (m/^<!-- # Unused Parameters # -->/) {
4901             #print "DEBUG: Found unused parameters\n";
4902             $in_unused_params = 1;
4903             next;
4905         } elsif ($in_unused_params && $skip_unused_params) {
4906             # When outputting the DocBook we skip unused parameters.
4907             #print "DEBUG: Skipping unused param: $_";
4908             next;
4910         } else {
4911             # Check if param found. Need to handle "..." and "format...".
4912             if (s/^\@([\w\.]+):\040?//) {
4913                 my $param_name = $1;
4914                 my $param_desc = $_;
4915                 # Allow variations of 'Returns'
4916                 if ($param_name =~ m/^[Rr]eturns?$/) {
4917                     $param_name = "Returns";
4918                 }
4920                 # strip trailing whitespaces and blank lines
4921                 s/\s+\n$/\n/m;
4922                 s/\n+$/\n/sm;
4923                 #print "Found param for symbol $current_symbol : '$param_name'= '$_'";
4925                 if ($param_name eq "Deprecated") {
4926                     $in_deprecated = 1;
4927                     $Deprecated{$current_symbol} = $_;
4928                 } elsif ($param_name eq "Since") {
4929                     $in_since = 1;
4930                     chomp;
4931                     $Since{$current_symbol} = $_;
4932                 } elsif ($param_name eq "Stability") {
4933                     $in_stability = 1;
4934                     $StabilityLevel{$current_symbol} = $_;
4935                 } else {
4936                     push (@params, $param_name);
4937                     push (@params, $param_desc);
4938                     $current_param += $PARAM_FIELD_COUNT;
4939                 }
4940             } else {
4941                 # strip trailing whitespaces and blank lines
4942                 s/\s+\n$/\n/m;
4943                 s/\n+$/\n/sm;
4944                 
4945                 if (!m/^\s+$/) {
4946                     if ($in_deprecated) {
4947                         $Deprecated{$current_symbol} .= $_;
4948                     } elsif ($in_since) {
4949                         &LogWarning ($template, $., "multi-line since docs found");
4950                         #$Since{$current_symbol} .= $_;
4951                     } elsif ($in_stability) {
4952                         $StabilityLevel{$current_symbol} .= $_;
4953                     } elsif ($current_param >= 0) {
4954                         $params[$current_param] .= $_;
4955                     } else {
4956                         $symbol_doc .= $_;
4957                     }
4958                 }
4959             }
4960         }
4961     }
4963     # Remember to finish the current symbol doccs.
4964     if ($current_symbol ne "") {
4966         $symbol_doc =~ s/\s+$//;
4967         $SymbolTypes{$current_symbol} = $current_type;
4968         $SymbolDocs{$current_symbol} = $symbol_doc;
4970         # Check that the stability level is valid.
4971         if ($StabilityLevel{$current_symbol}) {
4972             $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4973         }
4975         if ($current_param >= 0) {
4976             $SymbolParams{$current_symbol} = [ @params ];
4977         } else {
4978             # Delete any existing params in case we are overriding a
4979             # previously read template.
4980             delete $SymbolParams{$current_symbol};
4981         }
4982     }
4984     close (DOCS);
4985     return 1;
4989 #############################################################################
4990 # Function    : ReadObjectHierarchy
4991 # Description : This reads in the $MODULE-hierarchy.txt file containing all
4992 #               the GtkObject subclasses described in this module (and their
4993 #               ancestors).
4994 #               It places them in the @Objects array, and places their level
4995 #               in the object hierarchy in the @ObjectLevels array, at the
4996 #               same index. GtkObject, the root object, has a level of 1.
4998 #               FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
4999 #               as it goes along, this should be split out into a separate
5000 #               function.
5002 # Arguments   : none
5003 #############################################################################
5005 sub ReadObjectHierarchy {
5006     @Objects = ();
5007     @ObjectLevels = ();
5009     if (! -f $OBJECT_TREE_FILE) {
5010         return;
5011     }
5012     if (!open (INPUT, $OBJECT_TREE_FILE)) {
5013         warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
5014         return;
5015     }
5017     # FIXME: use $OUTPUT_FORMAT
5018     # my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.$OUTPUT_FORMAT";
5019     my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
5020     my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
5022     open (OUTPUT, ">$new_tree_index")
5023         || die "Can't create $new_tree_index: $!";
5025     if ($OUTPUT_FORMAT eq "xml") {
5026         my $tree_header = $doctype_header;
5028         $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
5029         print (OUTPUT "$tree_header");
5030     }
5031     print (OUTPUT "<screen>\n");
5033     # Only emit objects if they are supposed to be documented, or if
5034     # they have documented children. To implement this, we maintain a
5035     # stack of pending objects which will be emitted if a documented
5036     # child turns up.
5037     my @pending_objects = ();
5038     my @pending_levels = ();
5039     while (<INPUT>) {
5040         if (m/\S+/) {
5041             my $object = $&;
5042             my $level = (length($`)) / 2 + 1;
5043             my $xref = "";
5045             while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
5046                 my $pobject = pop(@pending_objects);
5047                 my $plevel = pop(@pending_levels);
5048             }
5050             push (@pending_objects, $object);
5051             push (@pending_levels, $level);
5053             if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5054                 while ($#pending_levels >= 0) {
5055                     $object = shift @pending_objects;
5056                     $level = shift @pending_levels;
5057                     $xref = &MakeXRef ($object);
5059                     print (OUTPUT ' ' x ($level * 4), "$xref\n");
5060                     push (@Objects, $object);
5061                     push (@ObjectLevels, $level);
5062                 }
5063             }
5064             #else {
5065             #    LogWarning ($OBJECT_TREE_FILE, $., "unknown type $object");
5066             #}
5067         }
5068     }
5069     print (OUTPUT "</screen>\n");
5071     close (INPUT);
5072     close (OUTPUT);
5074     &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
5076     &OutputObjectList;
5079 #############################################################################
5080 # Function    : ReadInterfaces
5081 # Description : This reads in the $MODULE.interfaces file.
5083 # Arguments   : none
5084 #############################################################################
5086 sub ReadInterfaces {
5087     %Interfaces = ();
5089     if (! -f $INTERFACES_FILE) {
5090         return;
5091     }
5092     if (!open (INPUT, $INTERFACES_FILE)) {
5093         warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
5094         return;
5095     }
5097     while (<INPUT>) {
5098        chomp;
5099        my ($object, @ifaces) = split;
5100        if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5101            my @knownIfaces = ();
5103            # filter out private interfaces, but leave foreign interfaces
5104            foreach my $iface (@ifaces) {
5105                if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
5106                    push (@knownIfaces, $iface);
5107                }
5108              }
5110            $Interfaces{$object} = join(' ', @knownIfaces);
5111        }
5112     }
5113     close (INPUT);
5116 #############################################################################
5117 # Function    : ReadPrerequisites
5118 # Description : This reads in the $MODULE.prerequisites file.
5120 # Arguments   : none
5121 #############################################################################
5123 sub ReadPrerequisites {
5124     %Prerequisites = ();
5126     if (! -f $PREREQUISITES_FILE) {
5127         return;
5128     }
5129     if (!open (INPUT, $PREREQUISITES_FILE)) {
5130         warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
5131         return;
5132     }
5134     while (<INPUT>) {
5135        chomp;
5136        my ($iface, @prereqs) = split;
5137        if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
5138            my @knownPrereqs = ();
5140            # filter out private prerequisites, but leave foreign prerequisites
5141            foreach my $prereq (@prereqs) {
5142                if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
5143                   push (@knownPrereqs, $prereq);
5144                }
5145            }
5147            $Prerequisites{$iface} = join(' ', @knownPrereqs);
5148        }
5149     }
5150     close (INPUT);
5153 #############################################################################
5154 # Function    : ReadArgsFile
5155 # Description : This reads in an existing file which contains information on
5156 #               all GTK args. It creates the arrays @ArgObjects, @ArgNames,
5157 #               @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
5158 #               on the args.
5159 # Arguments   : $file - the file containing the arg information.
5160 #############################################################################
5162 sub ReadArgsFile {
5163     my ($file) = @_;
5165     my $in_arg = 0;
5166     my $arg_object;
5167     my $arg_name;
5168     my $arg_type;
5169     my $arg_flags;
5170     my $arg_nick;
5171     my $arg_blurb;
5172     my $arg_default;
5173     my $arg_range;
5175     # Reset the args info.
5176     @ArgObjects = ();
5177     @ArgNames = ();
5178     @ArgTypes = ();
5179     @ArgFlags = ();
5180     @ArgNicks = ();
5181     @ArgBlurbs = ();
5182     @ArgDefaults = ();
5183     @ArgRanges = ();
5185     if (! -f $file) {
5186         return;
5187     }
5188     if (!open (INPUT, $file)) {
5189         warn "Can't open $file - skipping args\n";
5190         return;
5191     }
5192     while (<INPUT>) {
5193         if (!$in_arg) {
5194             if (m/^<ARG>/) {
5195                 $in_arg = 1;
5196                 $arg_object = "";
5197                 $arg_name = "";
5198                 $arg_type = "";
5199                 $arg_flags = "";
5200                 $arg_nick = "";
5201                 $arg_blurb = "";
5202                 $arg_default = "";
5203                 $arg_range = "";
5204             }
5205         } else {
5206             if (m/^<NAME>(.*)<\/NAME>/) {
5207                 $arg_name = $1;
5208                 if ($arg_name =~ m/^(.*)::(.*)$/) {
5209                     $arg_object = $1;
5210                     ($arg_name = $2) =~ s/_/-/g;
5211                     #print "Found arg: $arg_name\n";
5212                 } else {
5213                     &LogWarning ($file, $., "Invalid argument name: $arg_name");
5214                 }
5215             } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
5216                 $arg_type = $1;
5217             } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
5218                 $arg_range = $1;
5219             } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
5220                 $arg_flags = $1;
5221             } elsif (m/^<NICK>(.*)<\/NICK>/) {
5222                 $arg_nick = $1;
5223             } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
5224                 $arg_blurb = $1;
5225                 if ($arg_blurb eq "(null)") {
5226                   $arg_blurb = "";
5227                   &LogWarning ($file, $., "Property ${arg_object}:${arg_name} has no documentation.");
5228                 }
5229             } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
5230                 $arg_default = $1;
5231             } elsif (m%^</ARG>%) {
5232                 #print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
5233                 push (@ArgObjects, $arg_object);
5234                 push (@ArgNames, $arg_name);
5235                 push (@ArgTypes, $arg_type);
5236                 push (@ArgRanges, $arg_range);
5237                 push (@ArgFlags, $arg_flags);
5238                 push (@ArgNicks, $arg_nick);
5239                 push (@ArgBlurbs, $arg_blurb);
5240                 push (@ArgDefaults, $arg_default);
5241                 $in_arg = 0;
5242             }
5243         }
5244     }
5245     close (INPUT);
5249 #############################################################################
5250 # Function    : CheckIsObject
5251 # Description : Returns 1 if the given name is a GObject or a subclass.
5252 #               It uses the global @Objects array.
5253 #               Note that the @Objects array only contains classes in the
5254 #               current module and their ancestors - not all GObject classes.
5255 # Arguments   : $name - the name to check.
5256 #############################################################################
5258 sub CheckIsObject {
5259     my ($name) = @_;
5261     my $object;
5262     foreach $object (@Objects) {
5263         if ($object eq $name) {
5264             return 1;
5265         }
5266     }
5267     return 0;
5271 #############################################################################
5272 # Function    : MakeReturnField
5273 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
5274 # Arguments   : $str - the string to pad.
5275 #############################################################################
5277 sub MakeReturnField {
5278     my ($str) = @_;
5280     return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));
5283 #############################################################################
5284 # Function    : GetSymbolSourceFile
5285 # Description : Get the filename where the symbol docs where taken from.
5286 # Arguments   : $symbol - the symbol name
5287 #############################################################################
5289 sub GetSymbolSourceFile {
5290     my ($symbol) = @_;
5292     if (defined($SourceSymbolSourceFile{$symbol})) {
5293         return $SourceSymbolSourceFile{$symbol};
5294     } elsif (defined($SymbolSourceFile{$symbol})) {
5295         return $SymbolSourceFile{$symbol};
5296     } else {
5297         return "";
5298     }
5301 #############################################################################
5302 # Function    : GetSymbolSourceLine
5303 # Description : Get the file line where the symbol docs where taken from.
5304 # Arguments   : $symbol - the symbol name
5305 #############################################################################
5307 sub GetSymbolSourceLine {
5308     my ($symbol) = @_;
5310     if (defined($SourceSymbolSourceLine{$symbol})) {
5311         return $SourceSymbolSourceLine{$symbol};
5312     } elsif (defined($SymbolSourceLine{$symbol})) {
5313         return $SymbolSourceLine{$symbol};
5314     } else {
5315         return 0;
5316     }