tracing: add traceline for reading tmpl files
[gtk-doc.git] / gtkdoc-mkdb.in
blob9ccc4cb32ea3773905e9f82d16507da78a6ffdc7
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     }
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;
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                     }
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;
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";
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));
1108             if ($curletter ne $lastletter) {
1109                 $lastletter = $curletter;
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         }
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_gtype = 0;
1443     my $default_to_public = 1;
1444     if (&CheckIsObject ($symbol)) {
1445         #print "Found struct gtype: $symbol\n";
1446         $is_gtype = 1;
1447         $default_to_public = 0;
1448     }
1450     my $id;
1451     my $condition;
1452     if ($is_gtype) {
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) = @_;
1789     my $is_gtype = 0;
1790     if (&CheckIsObject ($symbol)) {
1791         #print "Found enum gtype: $symbol\n";
1792         $is_gtype = 1;
1793     }
1795     my $id;
1796     my $condition;
1797     if ($is_gtype) {
1798         $id = &CreateValidSGMLID ($symbol . "_enum");
1799         $condition = &MakeConditionDescription ($symbol . "_enum");
1800     } else {
1801         $id = &CreateValidSGMLID ($symbol);
1802         $condition = &MakeConditionDescription ($symbol);
1803     }
1805     my $synop = &MakeReturnField("enum") . "<link linkend=\"$id\">$symbol</link>;\n";
1806     my $desc = "<refsect2 id=\"$id\" role=\"enum\"$condition>\n<title>enum $symbol</title>\n";
1808     $desc .= MakeIndexterms($symbol, $id);
1809     $desc .= "\n";
1810     $desc .= OutputSymbolExtraLinks($symbol);
1812     my $decl_out = &CreateValidSGML ($declaration);
1813     $desc .= "<programlisting>$decl_out</programlisting>\n";
1815     $desc .= &MakeDeprecationNote($symbol);
1817     if (defined ($SymbolDocs{$symbol})) {
1818         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1819     }
1821     # Create a table of fields and descriptions
1823     my @fields = ParseEnumDeclaration($declaration);
1824     my $params = $SymbolParams{$symbol};
1826     # If no parameters are filled in, we don't generate the description
1827     # table, for backwards compatibility
1829     my $found = 0;
1830     if (defined $params) {
1831         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1832             if ($params->[$i] =~ /\S/) {
1833                 $found = 1;
1834                 last;
1835             }
1836         }
1837     }
1839     if ($found) {
1840         my %field_descrs = @$params;
1841         my $missing_parameters = "";
1842         my $unused_parameters = "";
1844         $desc .= "<variablelist role=\"enum\">\n";
1845         for my $field_name (@fields) {
1846             my $field_descr = $field_descrs{$field_name};
1847             my $param_annotations = "";
1849             $id = &CreateValidSGMLID ($field_name);
1850             $condition = &MakeConditionDescription ($field_name);
1851             $desc .= "<varlistentry id=\"$id\" role=\"constant\"$condition>\n<term><literal>$field_name</literal></term>\n";
1852             if (defined $field_descr) {
1853                 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1854                 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1855                 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1856                 delete $field_descrs{$field_name};
1857             } else {
1858                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1859                     "Value description for $symbol"."::"."$field_name is missing in source code comment block.");
1860                 if ($missing_parameters ne "") {
1861                   $missing_parameters .= ", ".$field_name;
1862                 } else {
1863                     $missing_parameters = $field_name;
1864                 }
1865                 $desc .= "<listitem />\n";
1866             }
1867             $desc .= "</varlistentry>\n";
1868         }
1869         $desc .= "</variablelist>";
1870         foreach my $field_name (keys %field_descrs) {
1871             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1872                 "Value description for $symbol"."::"."$field_name is not used from source code comment block.");
1873             if ($unused_parameters ne "") {
1874               $unused_parameters .= ", ".$field_name;
1875             } else {
1876                $unused_parameters = $field_name;
1877             }
1878         }
1880         # remember missing/unused parameters (needed in tmpl-free build)
1881         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1882             $AllIncompleteSymbols{$symbol}=$missing_parameters;
1883         }
1884         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1885             $AllUnusedSymbols{$symbol}=$unused_parameters;
1886         }
1887     }
1888     else {
1889         if (scalar(@fields) > 0) {
1890             if (! exists ($AllIncompleteSymbols{$symbol})) {
1891                 $AllIncompleteSymbols{$symbol}="<items>";
1892                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1893                     "Value descriptions for $symbol are missing in source code comment block.");
1894             }
1895         }
1896     }
1898     $desc .= OutputSymbolTraits ($symbol);
1899     $desc .= "</refsect2>\n";
1900     return ($synop, $desc);
1904 #############################################################################
1905 # Function    : OutputVariable
1906 # Description : Returns the synopsis and detailed description of a variable.
1907 # Arguments   : $symbol - the extern'ed variable.
1908 #                $declaration - the declaration of the variable.
1909 #############################################################################
1911 sub OutputVariable {
1912     my ($symbol, $declaration) = @_;
1913     my $id = &CreateValidSGMLID ($symbol);
1914     my $condition = &MakeConditionDescription ($symbol);
1916     my $synop;
1917     if ($declaration =~ m/^\s*extern\s+((const\s+|signed\s+|unsigned\s+)*\w+)(\s+\*+|\*+|\s)(\s*)([A-Za-z]\w*)\s*;/) {
1918         my $mod = defined ($1) ? $1 : "";
1919         my $ptr = defined ($3) ? $3 : "";
1920         my $space = defined ($4) ? $4 : "";
1921         $synop = &MakeReturnField("extern") . "$mod$ptr$space<link linkend=\"$id\">$symbol</link>;\n";
1923     } else {
1924         $synop = &MakeReturnField("extern") . "<link linkend=\"$id\">$symbol</link>;\n";
1925     }
1927     my $desc = "<refsect2 id=\"$id\" role=\"variable\"$condition>\n<title>$symbol</title>\n";
1929     $desc .= MakeIndexterms($symbol, $id);
1930     $desc .= "\n";
1931     $desc .= OutputSymbolExtraLinks($symbol);
1933     my $decl_out = &CreateValidSGML ($declaration);
1934     $desc .= "<programlisting>$decl_out</programlisting>\n";
1936     $desc .= &MakeDeprecationNote($symbol);
1938     if (defined ($SymbolDocs{$symbol})) {
1939         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1940     }
1941     $desc .= OutputSymbolTraits ($symbol);
1942     $desc .= "</refsect2>\n";
1943     return ($synop, $desc);
1947 #############################################################################
1948 # Function    : OutputFunction
1949 # Description : Returns the synopsis and detailed description of a function.
1950 # Arguments   : $symbol - the function.
1951 #                $declaration - the declaration of the function.
1952 #############################################################################
1954 sub OutputFunction {
1955     my ($symbol, $declaration, $symbol_type) = @_;
1956     my $id = &CreateValidSGMLID ($symbol);
1957     my $condition = &MakeConditionDescription ($symbol);
1959     # Take out the return type     $1                                                                                       $2   $3
1960     $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//;
1961     my $type_modifier = defined($1) ? $1 : "";
1962     my $type = $2;
1963     my $pointer = $3;
1964     # Trim trailing spaces as we are going to pad to $RETURN_TYPE_FIELD_WIDTH below anyway
1965     $pointer =~ s/\s+$//;
1966     my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1967     my $start = "";
1968     #if ($symbol_type eq 'USER_FUNCTION') {
1969     #    $start = "typedef ";
1970     #}
1972     # We output const rather than G_CONST_RETURN.
1973     $type_modifier =~ s/G_CONST_RETURN/const/g;
1974     $pointer =~ s/G_CONST_RETURN/const/g;
1975     $pointer =~ s/^\s+/ /g;
1977     my $ret_type_len = length ($start) + length ($type_modifier)+ length ($type)
1978         + length ($pointer);
1979     my $ret_type_output;
1980     my $symbol_len;
1981     if ($ret_type_len < $RETURN_TYPE_FIELD_WIDTH) {
1982         $ret_type_output = "$start$type_modifier$xref$pointer"
1983             . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
1984         $symbol_len = 0;
1985     } else {
1986         #$ret_type_output = "$start$type_modifier$xref$pointer\n" . (' ' x $RETURN_TYPE_FIELD_WIDTH);
1988         $ret_type_output = "$start$type_modifier$xref$pointer ";
1989         $symbol_len = $ret_type_len + 1 - $RETURN_TYPE_FIELD_WIDTH;
1990     }
1991     #@TRACE@("$symbol ret type output: [$ret_type_output], $ret_type_len");
1993     $symbol_len += length ($symbol);
1994     my $char1 = my $char2 = my $char3 = "";
1995     if ($symbol_type eq 'USER_FUNCTION') {
1996         $symbol_len += 3;
1997         $char1 = "(";
1998         $char2 = "*";
1999         $char3 = ")";
2000     }
2002     my ($symbol_output, $symbol_desc_output);
2003     if ($symbol_len < $SYMBOL_FIELD_WIDTH) {
2004         $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3"
2005             . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
2006         $symbol_desc_output = "$char1$char2$symbol$char3"
2007             . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
2008     } else {
2009         $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3\n"
2010             . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
2011         $symbol_desc_output = "$char1$char2$symbol$char3\n"
2012             . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
2013     }
2015     my $synop = $ret_type_output . $symbol_output . '(';
2016     my $desc = "<refsect2 id=\"$id\" role=\"function\"$condition>\n<title>${symbol} ()</title>\n";
2018     $desc .= MakeIndexterms($symbol, $id);
2019     $desc .= "\n";
2020     $desc .= OutputSymbolExtraLinks($symbol);
2022     $desc  .= "<programlisting>${ret_type_output}$symbol_desc_output(";
2024     my @fields = ParseFunctionDeclaration($declaration, \&MakeXRef,
2025                                         sub {
2026                                             &tagify($_[0],"parameter");
2027                                         });
2029     for (my $i = 1; $i <= $#fields; $i += 2) {
2030         my $field_name = $fields[$i];
2032         if ($i == 1) {
2033             $synop .= "$field_name";
2034             $desc  .= "$field_name";
2035         } else {
2036             $synop .= ",\n"
2037                 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2038                 . " $field_name";
2039             $desc  .= ",\n"
2040                 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2041                 . " $field_name";
2042         }
2044     }
2046     $synop .= ");\n";
2047     $desc  .= ");</programlisting>\n";
2049     $desc .= &MakeDeprecationNote($symbol);
2051     my $parameters = &OutputParamDescriptions ("FUNCTION", $symbol, @fields);
2052     my $parameters_output = 0;
2054     if (defined ($SymbolDocs{$symbol})) {
2055         my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
2057         # Try to insert the parameter table at the author's desired position.
2058         # Otherwise we need to tag it onto the end.
2059         # FIXME: document that in the user manual and make it useable for other
2060         # types too
2061         if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
2062           $parameters_output = 1;
2063         }
2064         $desc .= $symbol_docs;
2065     }
2067     if ($parameters_output == 0) {
2068         $desc .= $parameters;
2069     }
2071     $desc .= OutputSymbolTraits ($symbol);
2072     $desc .= "</refsect2>\n";
2073     return ($synop, $desc);
2077 #############################################################################
2078 # Function    : OutputParamDescriptions
2079 # Description : Returns the DocBook output describing the parameters of a
2080 #                function, macro or signal handler.
2081 # Arguments   : $symbol_type - 'FUNCTION', 'MACRO' or 'SIGNAL'. Signal
2082 #                  handlers have an implicit user_data parameter last.
2083 #                $symbol - the name of the function/macro being described.
2084 #               @fields - parsed fields from the declaration, used to determine
2085 #                  undocumented/unused entries
2086 #############################################################################
2088 sub OutputParamDescriptions {
2089     my ($symbol_type, $symbol, @fields) = @_;
2090     my $output = "";
2091     my $params = $SymbolParams{$symbol};
2092     my $num_params = 0;
2093     my %field_descrs = ();
2095     if (@fields) {
2096         %field_descrs = @fields;
2097         delete $field_descrs{"void"};
2098         delete $field_descrs{"Returns"};
2099     }
2101     if (defined $params) {
2102         my $returns = "";
2103         my $params_desc = "";
2104         my $missing_parameters = "";
2105         my $unused_parameters = "";
2106         my $j;
2108         for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
2109             my $param_name = $$params[$j];
2110             my $param_desc = $$params[$j + 1];
2111             my $param_annotations = "";
2113             ($param_desc,$param_annotations) = & ExpandAnnotation($symbol, $param_desc);
2114             $param_desc = &ExpandAbbreviations($symbol, $param_desc);
2115             $param_desc .= $param_annotations;
2116             # trim
2117             $param_desc =~ s/^(\s|\n)+//msg;
2118             $param_desc =~ s/(\s|\n)+$//msg;
2119             if ($param_name eq "Returns") {
2120                 $returns = "$param_desc";
2121             } elsif ($param_name eq "void") {
2122                 #print "!!!! void in params for $symbol?\n";
2123             } else {
2124                 if (@fields) {
2125                     if (!defined $field_descrs{$param_name}) {
2126                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2127                             "Parameter description for $symbol"."::"."$param_name is not used from source code comment block.");
2128                         if ($unused_parameters ne "") {
2129                           $unused_parameters .= ", ".$param_name;
2130                         } else {
2131                            $unused_parameters = $param_name;
2132                         }
2133                     } else {
2134                         delete $field_descrs{$param_name};
2135                     }
2136                 }
2137                 if($param_desc ne "") {
2138                     $params_desc .= "<varlistentry><term><parameter>$param_name</parameter>&#160;:</term>\n<listitem><simpara>$param_desc</simpara></listitem></varlistentry>\n";
2139                     $num_params++;
2140                 }
2141             }
2142         }
2143         foreach my $param_name (keys %field_descrs) {
2144             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2145                 "Parameter description for $symbol"."::"."$param_name is missing in source code comment block.");
2146             if ($missing_parameters ne "") {
2147               $missing_parameters .= ", ".$param_name;
2148             } else {
2149                $missing_parameters = $param_name;
2150             }
2151         }
2153         # Signals have an implicit user_data parameter which we describe.
2154         if ($symbol_type eq "SIGNAL") {
2155             $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";
2156         }
2158         # Start a table if we need one.
2159         if ($params_desc || $returns) {
2160             $output .= "<variablelist role=\"params\">\n";
2161             if ($params_desc ne "") {
2162                 #$output .= "<varlistentry><term>Parameters:</term><listitem></listitem></varlistentry>\n";
2163                 $output .= $params_desc;
2164             }
2166             # Output the returns info last
2167             if ($returns) {
2168                 $output .= "<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara>$returns</simpara></listitem></varlistentry>\n";
2169             }
2171             # Finish the table.
2172             $output .= "</variablelist>";
2173         }
2175         # remember missing/unused parameters (needed in tmpl-free build)
2176         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
2177             $AllIncompleteSymbols{$symbol}=$missing_parameters;
2178         }
2179         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
2180             $AllUnusedSymbols{$symbol}=$unused_parameters;
2181         }
2182     }
2183     if (($num_params == 0) && @fields && (scalar(keys(%field_descrs)) > 0)) {
2184         if (! exists ($AllIncompleteSymbols{$symbol})) {
2185             $AllIncompleteSymbols{$symbol}="<parameters>";
2186         }
2187     }
2189     return $output;
2193 #############################################################################
2194 # Function    : ParseStabilityLevel
2195 # Description : Parses a stability level and outputs a warning if it isn't
2196 #               valid.
2197 # Arguments   : $stability - the stability text.
2198 #                $file, $line - context for error message
2199 #                $message - description of where the level is from, to use in
2200 #               any error message.
2201 # Returns     : The parsed stability level string.
2202 #############################################################################
2204 sub ParseStabilityLevel {
2205     my ($stability, $file, $line, $message) = @_;
2207     $stability =~ s/^\s*//;
2208     $stability =~ s/\s*$//;
2209     if ($stability =~ m/^stable$/i) {
2210         $stability = "Stable";
2211     } elsif ($stability =~ m/^unstable$/i) {
2212         $stability = "Unstable";
2213     } elsif ($stability =~ m/^private$/i) {
2214         $stability = "Private";
2215     } else {
2216         &LogWarning ($file, $line, "$message is $stability.".
2217             "It should be one of these: Stable, Unstable, or Private.");
2218     }
2219     return $stability;
2223 #############################################################################
2224 # Function    : OutputSGMLFile
2225 # Description : Outputs the final DocBook file for one section.
2226 # Arguments   : $file - the name of the file.
2227 #               $title - the title from the $MODULE-sections.txt file, which
2228 #                 will be overridden by the title in the template file.
2229 #               $section_id - the SGML id to use for the toplevel tag.
2230 #               $includes - comma-separates list of include files added at top of
2231 #                 synopsis, with '<' '>' around them (if not already enclosed in "").
2232 #               $synopsis - reference to the DocBook for the Synopsis part.
2233 #               $details - reference to the DocBook for the Details part.
2234 #               $signal_synop - reference to the DocBook for the Signal Synopsis part
2235 #               $signal_desc - reference to the DocBook for the Signal Description part
2236 #               $args_synop - reference to the DocBook for the Arg Synopsis part
2237 #               $args_desc - reference to the DocBook for the Arg Description part
2238 #               $hierarchy - reference to the DocBook for the Object Hierarchy part
2239 #               $interfaces - reference to the DocBook for the Interfaces part
2240 #               $implementations - reference to the DocBook for the Known Implementations part
2241 #               $prerequisites - reference to the DocBook for the Prerequisites part
2242 #               $derived - reference to the DocBook for the Derived Interfaces part
2243 #               $file_objects - reference to an array of objects in this file
2244 #############################################################################
2246 sub OutputSGMLFile {
2247     my ($file, $title, $section_id, $includes, $synopsis, $details, $signals_synop, $signals_desc, $args_synop, $args_desc, $hierarchy, $interfaces, $implementations, $prerequisites, $derived, $file_objects) = @_;
2249     #print "Output sgml for file $file with title '$title'\n";
2251     # The edited title overrides the one from the sections file.
2252     my $new_title = $SymbolDocs{"$TMPL_DIR/$file:Title"};
2253     if (defined ($new_title) && $new_title !~ m/^\s*$/) {
2254         $title = $new_title;
2255         #print "Found title: $title\n";
2256     }
2257     my $short_desc = $SymbolDocs{"$TMPL_DIR/$file:Short_Description"};
2258     if (!defined ($short_desc) || $short_desc =~ m/^\s*$/) {
2259         $short_desc = "";
2260     } else {
2261         $short_desc = &ExpandAbbreviations("$title:Short_description",
2262                                            $short_desc);
2263         #print "Found short_desc: $short_desc";
2264     }
2265     my $long_desc = $SymbolDocs{"$TMPL_DIR/$file:Long_Description"};
2266     if (!defined ($long_desc) || $long_desc =~ m/^\s*$/) {
2267         $long_desc = "";
2268     } else {
2269         $long_desc = &ExpandAbbreviations("$title:Long_description",
2270                                           $long_desc);
2271         #print "Found long_desc: $long_desc";
2272     }
2273     my $see_also = $SymbolDocs{"$TMPL_DIR/$file:See_Also"};
2274     if (!defined ($see_also) || $see_also =~ m%^\s*(<para>)?\s*(</para>)?\s*$%) {
2275         $see_also = "";
2276     } else {
2277         $see_also = &ExpandAbbreviations("$title:See_Also", $see_also);
2278         #print "Found see_also: $see_also";
2279     }
2280     if ($see_also) {
2281         $see_also = "<refsect1 id=\"$section_id.see-also\">\n<title>See Also</title>\n$see_also\n</refsect1>\n";
2282     }
2283     my $stability = $SymbolDocs{"$TMPL_DIR/$file:Stability_Level"};
2284     if (!defined ($stability) || $stability =~ m/^\s*$/) {
2285         $stability = "";
2286     } else {
2287         $stability = &ParseStabilityLevel($stability, $file, $., "Section stability level");
2288         #print "Found stability: $stability";
2289     }
2290     if ($stability) {
2291         $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$stability, unless otherwise indicated\n</refsect1>\n";
2292     } elsif ($DEFAULT_STABILITY) {
2293         $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$DEFAULT_STABILITY, unless otherwise indicated\n</refsect1>\n";
2294     }
2296     my $image = $SymbolDocs{"$TMPL_DIR/$file:Image"};
2297     if (!defined ($image) || $image =~ m/^\s*$/) {
2298       $image = "";
2299     } else {
2300       $image =~ s/^\s*//;
2301       $image =~ s/\s*$//;
2303       my $format;
2305       if ($image =~ /jpe?g$/i) {
2306         $format = "format='JPEG'";
2307       } elsif ($image =~ /png$/i) {
2308         $format = "format='PNG'";
2309       } elsif ($image =~ /svg$/i) {
2310         $format = "format='SVG'";
2311       } else {
2312         $format = "";
2313       }
2315       $image = "  <inlinegraphic fileref='$image' $format/>\n"
2316     }
2318     my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
2319         gmtime (time);
2320     my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
2321     $year += 1900;
2323     my $include_output = "";
2324     my $include;
2325     foreach $include (split (/,/, $includes)) {
2326         if ($include =~ m/^\".+\"$/) {
2327             $include_output .= "#include ${include}\n";
2328         }
2329         else {
2330             $include =~ s/^\s+|\s+$//gs;
2331             $include_output .= "#include &lt;${include}&gt;\n";
2332         }
2333     }
2334     if ($include_output ne '') {
2335         $include_output = "\n$include_output\n";
2336     }
2338     my $extralinks = OutputSectionExtraLinks($title,"Section:$file");
2340     my $old_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT";
2341     my $new_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT.new";
2343     open (OUTPUT, ">$new_sgml_file")
2344         || die "Can't create $new_sgml_file: $!";
2346     my $object_anchors = "";
2347     foreach my $object (@$file_objects) {
2348         next if ($object eq $section_id);
2349         my $id = CreateValidSGMLID($object);
2350         #print "Debug: Adding anchor for $object\n";
2351         $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
2352     }
2354     # We used to output this, but is messes up our UpdateFileIfChanged code
2355     # since it changes every day (and it is only used in the man pages):
2356     # "<refentry id="$section_id" revision="$mday $month $year">"
2358     if ($OUTPUT_FORMAT eq "xml") {
2359         print OUTPUT $doctype_header;
2360     }
2362     print OUTPUT <<EOF;
2363 <refentry id="$section_id">
2364 <refmeta>
2365 <refentrytitle role="top_of_page" id="$section_id.top_of_page">$title</refentrytitle>
2366 <manvolnum>3</manvolnum>
2367 <refmiscinfo>
2368   \U$MODULE\E Library
2369 $image</refmiscinfo>
2370 </refmeta>
2371 <refnamediv>
2372 <refname>$title</refname>
2373 <refpurpose>$short_desc</refpurpose>
2374 </refnamediv>
2375 $stability
2376 <refsynopsisdiv id="$section_id.synopsis" role="synopsis">
2377 <title role="synopsis.title">Synopsis</title>
2378 $object_anchors
2379 <synopsis>$include_output$${synopsis}</synopsis>
2380 </refsynopsisdiv>
2381 $$hierarchy$$prerequisites$$derived$$interfaces$$implementations$$args_synop$$signals_synop
2382 <refsect1 id="$section_id.description" role="desc">
2383 <title role="desc.title">Description</title>
2384 $extralinks$long_desc
2385 </refsect1>
2386 <refsect1 id="$section_id.details" role="details">
2387 <title role="details.title">Details</title>
2388 $$details
2389 </refsect1>
2390 $$args_desc$$signals_desc$see_also
2391 </refentry>
2393     close (OUTPUT);
2395     return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2399 #############################################################################
2400 # Function    : OutputExtraFile
2401 # Description : Copies an "extra" DocBook file into the output directory,
2402 #               expanding abbreviations
2403 # Arguments   : $file - the source file.
2404 #############################################################################
2405 sub OutputExtraFile {
2406     my ($file) = @_;
2408     my $basename;
2410     ($basename = $file) =~ s!^.*/!!;
2412     my $old_sgml_file = "$SGML_OUTPUT_DIR/$basename";
2413     my $new_sgml_file = "$SGML_OUTPUT_DIR/$basename.new";
2415     my $contents;
2417     open(EXTRA_FILE, "<$file") || die "Can't open $file";
2419     {
2420         local $/;
2421         $contents = <EXTRA_FILE>;
2422     }
2424     open (OUTPUT, ">$new_sgml_file")
2425         || die "Can't create $new_sgml_file: $!";
2427     print OUTPUT &ExpandAbbreviations ("$basename file", $contents);
2428     close (OUTPUT);
2430     return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2432 #############################################################################
2433 # Function    : OutputBook
2434 # Description : Outputs the SGML entities that need to be included into the
2435 #                main SGML file for the module.
2436 # Arguments   : $book_top - the declarations of the entities, which are added
2437 #                  at the top of the main SGML file.
2438 #                $book_bottom - the references to the entities, which are
2439 #                  added in the main SGML file at the desired position.
2440 #############################################################################
2442 sub OutputBook {
2443     my ($book_top, $book_bottom) = @_;
2445     my $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top";
2446     my $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top.new";
2448     open (OUTPUT, ">$new_file")
2449         || die "Can't create $new_file: $!";
2450     print OUTPUT $book_top;
2451     close (OUTPUT);
2453     &UpdateFileIfChanged ($old_file, $new_file, 0);
2456     $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom";
2457     $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom.new";
2459     open (OUTPUT, ">$new_file")
2460         || die "Can't create $new_file: $!";
2461     print OUTPUT $book_bottom;
2462     close (OUTPUT);
2464     &UpdateFileIfChanged ($old_file, $new_file, 0);
2467     # If the main SGML/XML file hasn't been created yet, we create it here.
2468     # The user can tweak it later.
2469     if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
2470       open (OUTPUT, ">$MAIN_SGML_FILE")
2471         || die "Can't create $MAIN_SGML_FILE: $!";
2473       if ($OUTPUT_FORMAT eq "xml") {
2474           print OUTPUT <<EOF;
2475 <?xml version="1.0"?>
2476 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
2477                "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
2479   <!ENTITY % local.common.attrib "xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'">
2481 <book id="index">
2483       } else {
2484         print OUTPUT <<EOF;
2485 <!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
2486 $book_top
2488 <book id="index">
2490       }
2492 print OUTPUT <<EOF;
2493   <bookinfo>
2494     <title>$MODULE Reference Manual</title>
2495     <releaseinfo>
2496       for $MODULE [VERSION].
2497       The latest version of this documentation can be found on-line at
2498       <ulink role="online-location" url="http://[SERVER]/$MODULE/index.html">http://[SERVER]/$MODULE/</ulink>.
2499     </releaseinfo>
2500   </bookinfo>
2502   <chapter>
2503     <title>[Insert title here]</title>
2504     $book_bottom
2505   </chapter>
2507   if (-e $OBJECT_TREE_FILE) {
2508     print OUTPUT <<EOF;
2509   <chapter id="object-tree">
2510     <title>Object Hierarchy</title>
2511      <xi:include href="xml/tree_index.sgml"/>
2512   </chapter>
2514   }
2516 print OUTPUT <<EOF;
2517   <index id="api-index-full">
2518     <title>API Index</title>
2519     <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
2520   </index>
2521   <index id="deprecated-api-index" role="deprecated">
2522     <title>Index of deprecated API</title>
2523     <xi:include href="xml/api-index-deprecated.xml"><xi:fallback /></xi:include>
2524   </index>
2526   <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
2527 </book>
2530       close (OUTPUT);
2531     }
2535 #############################################################################
2536 # Function    : CreateValidSGML
2537 # Description : This turns any chars which are used in SGML into entities,
2538 #                e.g. '<' into '&lt;'
2539 # Arguments   : $text - the text to turn into proper SGML.
2540 #############################################################################
2542 sub CreateValidSGML {
2543     my ($text) = @_;
2544     $text =~ s/&/&amp;/g;        # Do this first, or the others get messed up.
2545     $text =~ s/</&lt;/g;
2546     $text =~ s/>/&gt;/g;
2547     # browers render single tabs inconsistently
2548     $text =~ s/([^\s])\t([^\s])/$1&#160;$2/g;
2549     return $text;
2552 #############################################################################
2553 # Function    : ConvertSGMLChars
2554 # Description : This is used for text in source code comment blocks, to turn
2555 #               chars which are used in SGML into entities, e.g. '<' into
2556 #               '&lt;'. Depending on $INLINE_MARKUP_MODE, this is done
2557 #               unconditionally or only if the character doesn't seem to be
2558 #               part of an SGML construct (tag or entity reference).
2559 # Arguments   : $text - the text to turn into proper SGML.
2560 #############################################################################
2562 sub ConvertSGMLChars {
2563     my ($symbol, $text) = @_;
2565     if ($INLINE_MARKUP_MODE) {
2566         # For the XML/SGML mode only convert to entities outside CDATA sections.
2567         return &ModifyXMLElements ($text, $symbol,
2568                                    "<!\\[CDATA\\[|<programlisting[^>]*>",
2569                                    \&ConvertSGMLCharsEndTag,
2570                                    \&ConvertSGMLCharsCallback);
2571     } else {
2572         # For the simple non-sgml mode, convert to entities everywhere.
2573         $text =~ s/&/&amp;/g;        # Do this first, or the others get messed up.
2574         $text =~ s/</&lt;/g;
2575         $text =~ s/>/&gt;/g;
2576         return $text;
2577     }
2581 sub ConvertSGMLCharsEndTag {
2582   if ($_[0] eq "<!\[CDATA\[") {
2583     return "]]>";
2584   } else {
2585     return "</programlisting>";
2586   }
2589 sub ConvertSGMLCharsCallback {
2590   my ($text, $symbol, $tag) = @_;
2592   if ($tag =~ m/^<programlisting/) {
2593     # We can handle <programlisting> specially here.
2594     return &ModifyXMLElements ($text, $symbol,
2595                                "<!\\[CDATA\\[",
2596                                \&ConvertSGMLCharsEndTag,
2597                                \&ConvertSGMLCharsCallback2);
2598   } elsif ($tag eq "") {
2599     # If we're not in CDATA convert to entities.
2600     $text =~ s/&(?![a-zA-Z#]+;)/&amp;/g;        # Do this first, or the others get messed up.
2601     $text =~ s/<(?![a-zA-Z\/!])/&lt;/g;
2602     $text =~ s/(?<![a-zA-Z0-9"'\/-])>/&gt;/g;
2604     # Handle "#include <xxxxx>"
2605     $text =~ s/#include(\s+)<([^>]+)>/#include$1&lt;$2&gt;/g;
2606   }
2608   return $text;
2611 sub ConvertSGMLCharsCallback2 {
2612   my ($text, $symbol, $tag) = @_;
2614   # If we're not in CDATA convert to entities.
2615   # We could handle <programlisting> differently, though I'm not sure it helps.
2616   if ($tag eq "") {
2617     # replace only if its not a tag
2618     $text =~ s/&(?![a-zA-Z#]+;)/&amp;/g;        # Do this first, or the others get messed up.
2619     $text =~ s/<(?![a-zA-Z\/!])/&lt;/g;
2620     $text =~ s/(?<![a-zA-Z0-9"'\/-])>/&gt;/g;
2622     # Handle "#include <xxxxx>"
2623     $text =~ s/#include(\s+)<([^>]+)>/#include$1&lt;$2&gt;/g;
2624   }
2626   return $text;
2629 #############################################################################
2630 # Function    : ExpandAnnotation
2631 # Description : This turns annotations into acronym tags.
2632 # Arguments   : $symbol - the symbol being documented, for error messages.
2633 #                $text - the text to expand.
2634 #############################################################################
2635 sub ExpandAnnotation {
2636     my ($symbol, $param_desc) = @_;
2637     my $param_annotations = "";
2639     # look for annotations at the start of the comment part
2640     if ($param_desc =~ m%^\s*\((.*?)\):%) {
2641         my @annotations;
2642         my $annotation;
2643         $param_desc = $';
2645         @annotations = split(/\)\s*\(/,$1);
2646         foreach $annotation (@annotations) {
2647             # need to search for the longest key-match in %AnnotationDefinition
2648             my $match_length=0;
2649             my $match_annotation="";
2650             my $annotationdef;
2651             foreach $annotationdef (keys %AnnotationDefinition) {
2652                 if ($annotation =~ m/^$annotationdef/) {
2653                     if (length($annotationdef)>$match_length) {
2654                         $match_length=length($annotationdef);
2655                         $match_annotation=$annotationdef;
2656                     }
2657                 }
2658             }
2659             my $annotation_extra = "";
2660             if ($match_annotation ne "") {
2661                 if ($annotation =~ m%$match_annotation\s+(.*)%) {
2662                     $annotation_extra = " $1";
2663                 }
2664                 $AnnotationsUsed{$match_annotation} = 1;
2665                 $param_annotations .= "[<acronym>$match_annotation</acronym>$annotation_extra]";
2666             }
2667             else {
2668                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2669                     "unknown annotation \"$annotation\" in documentation for $symbol.");
2670                 $param_annotations .= "[$annotation]";
2671             }
2672         }
2673         chomp($param_desc);
2674         $param_desc =~ m/^(.*?)\.*\s*$/s;
2675         $param_desc = "$1. ";
2676     }
2677     if ($param_annotations ne "") {
2678         $param_annotations = "<emphasis role=\"annotation\">$param_annotations</emphasis>";
2679     }
2680     return ($param_desc, $param_annotations);
2683 #############################################################################
2684 # Function    : ExpandAbbreviations
2685 # Description : This turns the abbreviations function(), macro(), @param,
2686 #                %constant, and #symbol into appropriate DocBook markup.
2687 #               CDATA sections and <programlisting> parts are skipped.
2688 # Arguments   : $symbol - the symbol being documented, for error messages.
2689 #                $text - the text to expand.
2690 #############################################################################
2692 sub ExpandAbbreviations {
2693   my ($symbol, $text) = @_;
2695   # Convert "|[" and "]|" into the start and end of program listing examples.
2696   # FIXME: we like to have a way to specify parameters e.g. language="c"
2697   $text =~ s%\|\[%<informalexample><programlisting>%g;
2698   $text =~ s%\]\|%</programlisting></informalexample>%g;
2699   # TODO: check for a xml comment after |[ and pick the language attribute from
2700   # that
2702   # keep CDATA unmodified, preserve ulink tags (ideally we preseve all tags
2703   # as such)
2704   return &ModifyXMLElements ($text, $symbol,
2705                              "<!\\[CDATA\\[|<ulink[^>]*>|<programlisting[^>]*>|<!DOCTYPE",
2706                              \&ExpandAbbreviationsEndTag,
2707                              \&ExpandAbbreviationsCallback);
2711 # Returns the end tag corresponding to the given start tag.
2712 sub ExpandAbbreviationsEndTag {
2713   my ($start_tag) = @_;
2715   if ($start_tag eq "<!\[CDATA\[") {
2716     return "]]>";
2717   } elsif ($start_tag eq "<!DOCTYPE") {
2718     return "]>";
2719   } elsif ($start_tag =~ m/<(\w+)/) {
2720     return "</$1>";
2721   }
2724 # Called inside or outside each CDATA or <programlisting> section.
2725 sub ExpandAbbreviationsCallback {
2726   my ($text, $symbol, $tag) = @_;
2728   if ($tag =~ m/^<programlisting/) {
2729     # Handle any embedded CDATA sections.
2730     return &ModifyXMLElements ($text, $symbol,
2731                                "<!\\[CDATA\\[",
2732                                \&ExpandAbbreviationsEndTag,
2733                                \&ExpandAbbreviationsCallback2);
2734   } elsif ($tag eq "") {
2735     # We are outside any CDATA or <programlisting> sections, so we expand
2736     # any gtk-doc abbreviations.
2738     # Convert '@param()'
2739     # FIXME: we could make those also links ($symbol.$2), but that would be less
2740     # useful as the link target is a few lines up or down
2741     $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)\s*\(\)/$1<parameter>$2()<\/parameter>/g;
2743     # Convert 'function()' or 'macro()'.
2744     # if there is abc_*_def() we don't want to make a link to _def()
2745     # FIXME: also handle abc(def(....)) : but that would need to be done recursively :/
2746     $text =~ s/([^\*.\w])(\w+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2747     # handle #Object.func()
2748     $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2750     # Convert '@param', but not '\@param'.
2751     $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)/$1<parameter>$2<\/parameter>/g;
2752     $text =~ s/\\\@/\@/g;
2754     # Convert '%constant', but not '\%constant'.
2755     # Also allow negative numbers, e.g. %-1.
2756     $text =~ s/(\A|[^\\])\%(-?\w+)/$1.&MakeXRef($2, &tagify($2, "literal"));/eg;
2757     $text =~ s/\\\%/\%/g;
2759     # Convert '#symbol', but not '\#symbol'.
2760     $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)/$1.&MakeHashXRef($2, "type");/eg;
2761     $text =~ s/\\#/#/g;
2763     # Expand urls
2764     # FIXME: should we skip urls that are already tagged? (e.g. <literal>http://...</literal>)
2765     # this is apparently also called for markup and not just for plain text
2766     # disable for now.
2767     #$text =~ s%(http|https|ftp)://(.*?)((?:\s|,|\)|\]|\<|\.\s))%<ulink url="$1://$2">$2</ulink>$3%g;
2769     # TODO: optionally check all words from $text against internal symbols and
2770     # warn if those could be xreffed, but miss a %,# or ()
2771   }
2773   return $text;
2776 # This is called inside a <programlisting>
2777 sub ExpandAbbreviationsCallback2 {
2778   my ($text, $symbol, $tag) = @_;
2780   if ($tag eq "") {
2781     # We are inside a <programlisting> but outside any CDATA sections,
2782     # so we expand any gtk-doc abbreviations.
2783     # FIXME: why is this different from &ExpandAbbreviationsCallback(),
2784     #        why not just call it
2785     $text =~ s/#(\w+)/&MakeHashXRef($1, "");/eg;
2786   }
2788   return $text;
2791 sub MakeHashXRef {
2792     my ($symbol, $tag) = @_;;
2793     my $text = $symbol;
2795     # Check for things like '#include', '#define', and skip them.
2796     if ($PreProcessorDirectives{$symbol}) {
2797       return "#$symbol";
2798     }
2800     # Get rid of any special '-struct' suffix.
2801     $text =~ s/-struct$//;
2803     # If the symbol is in the form "Object::signal", then change the symbol to
2804     # "Object-signal" and use "signal" as the text.
2805     if ($symbol =~ s/::/-/) {
2806       $text = "\"$'\"";
2807     }
2809     # If the symbol is in the form "Object:property", then change the symbol to
2810     # "Object--property" and use "property" as the text.
2811     if ($symbol =~ s/:/--/) {
2812       $text = "\"$'\"";
2813     }
2815     if ($tag ne "") {
2816       $text = tagify ($text, $tag);
2817     }
2819     return &MakeXRef($symbol, $text);
2823 #############################################################################
2824 # Function    : ModifyXMLElements
2825 # Description : Looks for given XML element tags within the text, and calls
2826 #               the callback on pieces of text inside & outside those elements.
2827 #               Used for special handling of text inside things like CDATA
2828 #               and <programlisting>.
2829 # Arguments   : $text - the text.
2830 #               $symbol - the symbol currently being documented (only used for
2831 #                      error messages).
2832 #               $start_tag_regexp - the regular expression to match start tags.
2833 #                      e.g. "<!\\[CDATA\\[|<programlisting[^>]*>" to match
2834 #                      CDATA sections or programlisting elements.
2835 #               $end_tag_func - function which is passed the matched start tag
2836 #                      and should return the appropriate end tag string.
2837 #               $callback - callback called with each part of the text. It is
2838 #                      called with a piece of text, the symbol being
2839 #                      documented, and the matched start tag or "" if the text
2840 #                      is outside the XML elements being matched.
2841 #############################################################################
2842 sub ModifyXMLElements {
2843     my ($text, $symbol, $start_tag_regexp, $end_tag_func, $callback) = @_;
2844     my ($before_tag, $start_tag, $end_tag_regexp, $end_tag);
2845     my $result = "";
2847     while ($text =~ m/$start_tag_regexp/s) {
2848       $before_tag = $`; # Prematch for last successful match string
2849       $start_tag = $&;  # Last successful match
2850       $text = $';       # Postmatch for last successful match string
2852       $result .= &$callback ($before_tag, $symbol, "");
2853       $result .= $start_tag;
2855       # get the mathing end-tag for current tag
2856       $end_tag_regexp = &$end_tag_func ($start_tag);
2858       if ($text =~ m/$end_tag_regexp/s) {
2859         $before_tag = $`;
2860         $end_tag = $&;
2861         $text = $';
2863         $result .= &$callback ($before_tag, $symbol, $start_tag);
2864         $result .= $end_tag;
2865       } else {
2866         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2867             "Can't find tag end: $end_tag_regexp in docs for: $symbol.");
2868         # Just assume it is all inside the tag.
2869         $result .= &$callback ($text, $symbol, $start_tag);
2870         $text = "";
2871       }
2872     }
2874     # Handle any remaining text outside the tags.
2875     $result .= &$callback ($text, $symbol, "");
2877     return $result;
2880 sub noop {
2881   return $_[0];
2884 # Adds a tag around some text.
2885 # e.g tagify("Text", "literal") => "<literal>Text</literal>".
2886 sub tagify {
2887    my ($text, $elem) = @_;
2888    return "<" . $elem . ">" . $text . "</" . $elem . ">";
2892 #############################################################################
2893 # Function    : MakeXRef
2894 # Description : This returns a cross-reference link to the given symbol.
2895 #                Though it doesn't try to do this for a few standard C types
2896 #                that it        knows won't be in the documentation.
2897 # Arguments   : $symbol - the symbol to try to create a XRef to.
2898 #               $text - text text to put inside the XRef, defaults to $symbol
2899 #############################################################################
2901 sub MakeXRef {
2902     my ($symbol, $text) = ($_[0], $_[1]);
2904     $symbol =~ s/^\s+//;
2905     $symbol =~ s/\s+$//;
2907     if (!defined($text)) {
2908         $text = $symbol;
2910         # Get rid of special '-struct' suffix.
2911         $text =~ s/-struct$//;
2912     }
2914     if ($symbol =~ m/ /) {
2915         return "$text";
2916     }
2918     #print "Getting type link for $symbol -> $text\n";
2920     my $symbol_id = &CreateValidSGMLID ($symbol);
2921     return "<link linkend=\"$symbol_id\">$text</link>";
2925 #############################################################################
2926 # Function    : MakeIndexterms
2927 # Description : This returns a indexterm elements for the given symbol
2928 # Arguments   : $symbol - the symbol to create indexterms for
2929 #############################################################################
2931 sub MakeIndexterms {
2932   my ($symbol, $id) = @_;
2933   my $terms =  "";
2934   my $sortas = "";
2936   # make the index useful, by ommiting the namespace when sorting
2937   if ($NAME_SPACE ne "") {
2938     if ($symbol =~ m/^$NAME_SPACE\_?(.*)/i) {
2939        $sortas=" sortas=\"$1\"";
2940     }
2941   }
2943   if (exists $Deprecated{$symbol}) {
2944       $terms .= "<indexterm zone=\"$id\" role=\"deprecated\"><primary$sortas>$symbol</primary></indexterm>";
2945       $IndexEntriesDeprecated{$symbol}=$id;
2946       $IndexEntriesFull{$symbol}=$id;
2947   }
2948   if (exists $Since{$symbol}) {
2949      my $since = $Since{$symbol};
2950      $since =~ s/^\s+//;
2951      $since =~ s/\s+$//;
2952      if ($since ne "") {
2953          $terms .= "<indexterm zone=\"$id\" role=\"$since\"><primary$sortas>$symbol</primary></indexterm>";
2954      }
2955      $IndexEntriesSince{$symbol}=$id;
2956      $IndexEntriesFull{$symbol}=$id;
2957   }
2958   if ($terms eq "") {
2959      $terms .= "<indexterm zone=\"$id\"><primary$sortas>$symbol</primary></indexterm>";
2960      $IndexEntriesFull{$symbol}=$id;
2961   }
2963   return $terms;
2966 #############################################################################
2967 # Function    : MakeDeprecationNote
2968 # Description : This returns a deprecation warning for the given symbol.
2969 # Arguments   : $symbol - the symbol to try to create a warning for.
2970 #############################################################################
2972 sub MakeDeprecationNote {
2973     my ($symbol) = $_[0];
2974     my $desc = "";
2975     my $note = "";
2976     if (exists $Deprecated{$symbol}) {
2977         $desc .= "<warning>";
2979         if ($Deprecated{$symbol} =~ /^\s*([0-9\.]+)\s*:/) {
2980                 $desc .= "<para><literal>$symbol</literal> has been deprecated since version $1 and should not be used in newly-written code.";
2981         } else {
2982                 $desc .= "<para><literal>$symbol</literal> is deprecated and should not be used in newly-written code.";
2983         }
2984         if ($Deprecated{$symbol} ne "") {
2985             $note = &ExpandAbbreviations($symbol, $Deprecated{$symbol});
2986             $note =~ s/^\s*([0-9\.]+)\s*:\s*//;
2987             $note =~ s/^\s+//;
2988             $note =~ s/\s+$//;
2989             $note =~ s%\n{2,}%\n</para>\n<para>\n%g;
2990             $desc .= " " . $note;
2991         }
2992         $desc .= "</para></warning>\n";
2993     }
2994     return $desc;
2997 #############################################################################
2998 # Function    : MakeConditionDescription
2999 # Description : This returns a sumary of conditions for the given symbol.
3000 # Arguments   : $symbol - the symbol to try to create the sumary.
3001 #############################################################################
3003 sub MakeConditionDescription {
3004     my ($symbol) = $_[0];
3005     my $desc = "";
3007     if (exists $Deprecated{$symbol}) {
3008         if ($desc ne "") {
3009             $desc .= "|";
3010         }
3012         if ($Deprecated{$symbol} =~ /^\s*(.*?)\s*$/) {
3013                 $desc .= "deprecated:$1";
3014         } else {
3015                 $desc .= "deprecated";
3016         }
3017     }
3019     if (exists $Since{$symbol}) {
3020         if ($desc ne "") {
3021             $desc .= "|";
3022         }
3024         if ($Since{$symbol} =~ /^\s*(.*?)\s*$/) {
3025                 $desc .= "since:$1";
3026         } else {
3027                 $desc .= "since";
3028         }
3029     }
3031     if (exists $StabilityLevel{$symbol}) {
3032         if ($desc ne "") {
3033             $desc .= "|";
3034         }
3035         $desc .= "stability:".$StabilityLevel{$symbol};
3036     }
3038     if ($desc ne "") {
3039         $desc=" condition=\"".$desc."\"";
3040         #print "condition for '$symbol' = '$desc'\n";
3041     }
3042     return $desc;
3045 #############################################################################
3046 # Function    : GetHierarchy
3047 # Description : Returns the DocBook output describing the ancestors and
3048 #               immediate children of a GObject subclass. It uses the
3049 #               global @Objects and @ObjectLevels arrays to walk the tree.
3050 # Arguments   : $object - the GtkObject subclass.
3051 #############################################################################
3053 sub GetHierarchy {
3054     my ($object) = @_;
3056     # Find object in the objects array.
3057     my $found = 0;
3058     my @children = ();
3059     my $i;
3060     my $level;
3061     my $j;
3062     for ($i = 0; $i < @Objects; $i++) {
3063         if ($found) {
3064             if ($ObjectLevels[$i] <= $level) {
3065             last;
3066         }
3067             elsif ($ObjectLevels[$i] == $level + 1) {
3068                 push (@children, $Objects[$i]);
3069             }
3070         }
3071         elsif ($Objects[$i] eq $object) {
3072             $found = 1;
3073             $j = $i;
3074             $level = $ObjectLevels[$i];
3075         }
3076     }
3077     if (!$found) {
3078         return "";
3079     }
3081     # Walk up the hierarchy, pushing ancestors onto the ancestors array.
3082     my @ancestors = ();
3083     push (@ancestors, $object);
3084     #print "Level: $level\n";
3085     while ($level > 1) {
3086         $j--;
3087         if ($ObjectLevels[$j] < $level) {
3088             push (@ancestors, $Objects[$j]);
3089             $level = $ObjectLevels[$j];
3090             #print "Level: $level\n";
3091         }
3092     }
3094     # Output the ancestors list, indented and with links.
3095     my $hierarchy = "<synopsis>\n";
3096     $level = 0;
3097     for ($i = $#ancestors; $i >= 0; $i--) {
3098         my $link_text;
3099         # Don't add a link to the current object, i.e. when i == 0.
3100         if ($i > 0) {
3101             my $ancestor_id = &CreateValidSGMLID ($ancestors[$i]);
3102             $link_text = "<link linkend=\"$ancestor_id\">$ancestors[$i]</link>";
3103         } else {
3104             $link_text = "$ancestors[$i]";
3105         }
3106         if ($level == 0) {
3107             $hierarchy .= "  $link_text\n";
3108         } else {
3109 #            $hierarchy .= ' ' x ($level * 6 - 3) . "|\n";
3110             $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3111         }
3112         $level++;
3113     }
3114     for ($i = 0; $i <= $#children; $i++) {
3115       my $id = &CreateValidSGMLID ($children[$i]);
3116       my $link_text = "<link linkend=\"$id\">$children[$i]</link>";
3117       $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3118     }
3119     $hierarchy .= "</synopsis>\n";
3121     return $hierarchy;
3125 #############################################################################
3126 # Function    : GetInterfaces
3127 # Description : Returns the DocBook output describing the interfaces
3128 #               implemented by a class. It uses the global %Interfaces hash.
3129 # Arguments   : $object - the GtkObject subclass.
3130 #############################################################################
3132 sub GetInterfaces {
3133     my ($object) = @_;
3134     my $text = "";
3135     my $i;
3137     # Find object in the objects array.
3138     if (exists($Interfaces{$object})) {
3139         my @ifaces = split(' ', $Interfaces{$object});
3140         $text = <<EOF;
3141 <para>
3142 $object implements
3144         for ($i = 0; $i <= $#ifaces; $i++) {
3145             my $id = &CreateValidSGMLID ($ifaces[$i]);
3146             $text .= " <link linkend=\"$id\">$ifaces[$i]</link>";
3147             if ($i < $#ifaces - 1) {
3148                 $text .= ', ';
3149             }
3150             elsif ($i < $#ifaces) {
3151                 $text .= ' and ';
3152             }
3153             else {
3154                 $text .= '.';
3155             }
3156         }
3157         $text .= <<EOF;
3158 </para>
3160     }
3162     return $text;
3165 #############################################################################
3166 # Function    : GetImplementations
3167 # Description : Returns the DocBook output describing the implementations
3168 #               of an interface. It uses the global %Interfaces hash.
3169 # Arguments   : $object - the GtkObject subclass.
3170 #############################################################################
3172 sub GetImplementations {
3173     my ($object) = @_;
3174     my @impls = ();
3175     my $text = "";
3176     my $i;
3177     foreach my $key (keys %Interfaces) {
3178         if ($Interfaces{$key} =~ /\b$object\b/) {
3179             push (@impls, $key);
3180         }
3181     }
3182     if ($#impls >= 0) {
3183         @impls = sort @impls;
3184         $text = <<EOF;
3185 <para>
3186 $object is implemented by
3188         for ($i = 0; $i <= $#impls; $i++) {
3189             my $id = &CreateValidSGMLID ($impls[$i]);
3190             $text .= " <link linkend=\"$id\">$impls[$i]</link>";
3191             if ($i < $#impls - 1) {
3192                 $text .= ', ';
3193             }
3194             elsif ($i < $#impls) {
3195                 $text .= ' and ';
3196             }
3197             else {
3198                 $text .= '.';
3199             }
3200         }
3201         $text .= <<EOF;
3202 </para>
3204     }
3205     return $text;
3209 #############################################################################
3210 # Function    : GetPrerequisites
3211 # Description : Returns the DocBook output describing the prerequisites
3212 #               of an interface. It uses the global %Prerequisites hash.
3213 # Arguments   : $iface - the interface.
3214 #############################################################################
3216 sub GetPrerequisites {
3217     my ($iface) = @_;
3218     my $text = "";
3219     my $i;
3221     if (exists($Prerequisites{$iface})) {
3222         $text = <<EOF;
3223 <para>
3224 $iface requires
3226         my @prereqs = split(' ', $Prerequisites{$iface});
3227         for ($i = 0; $i <= $#prereqs; $i++) {
3228             my $id = &CreateValidSGMLID ($prereqs[$i]);
3229             $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
3230             if ($i < $#prereqs - 1) {
3231                 $text .= ', ';
3232             }
3233             elsif ($i < $#prereqs) {
3234                 $text .= ' and ';
3235             }
3236             else {
3237                 $text .= '.';
3238             }
3239         }
3240         $text .= <<EOF;
3241 </para>
3243     }
3244     return $text;
3247 #############################################################################
3248 # Function    : GetDerived
3249 # Description : Returns the DocBook output describing the derived interfaces
3250 #               of an interface. It uses the global %Prerequisites hash.
3251 # Arguments   : $iface - the interface.
3252 #############################################################################
3254 sub GetDerived {
3255     my ($iface) = @_;
3256     my $text = "";
3257     my $i;
3259     my @derived = ();
3260     foreach my $key (keys %Prerequisites) {
3261         if ($Prerequisites{$key} =~ /\b$iface\b/) {
3262             push (@derived, $key);
3263         }
3264     }
3265     if ($#derived >= 0) {
3266         @derived = sort @derived;
3267         $text = <<EOF;
3268 <para>
3269 $iface is required by
3271         for ($i = 0; $i <= $#derived; $i++) {
3272             my $id = &CreateValidSGMLID ($derived[$i]);
3273             $text .= " <link linkend=\"$id\">$derived[$i]</link>";
3274             if ($i < $#derived - 1) {
3275                 $text .= ', ';
3276             }
3277             elsif ($i < $#derived) {
3278                 $text .= ' and ';
3279             }
3280             else {
3281                 $text .= '.';
3282             }
3283         }
3284         $text .= <<EOF;
3285 </para>
3287     }
3288     return $text;
3292 #############################################################################
3293 # Function    : GetSignals
3294 # Description : Returns the synopsis and detailed description DocBook output
3295 #                for the signal handlers of a given GtkObject subclass.
3296 # Arguments   : $object - the GtkObject subclass, e.g. 'GtkButton'.
3297 #############################################################################
3299 sub GetSignals {
3300     my ($object) = @_;
3301     my $synop = "";
3302     my $desc = "";
3304     my $i;
3305     for ($i = 0; $i <= $#SignalObjects; $i++) {
3306         if ($SignalObjects[$i] eq $object) {
3307             #print "Found signal: $SignalNames[$i]\n";
3308             my $name = $SignalNames[$i];
3309             my $symbol = "${object}::${name}";
3310             my $id = &CreateValidSGMLID ("$object-$name");
3312             my $pad = ' ' x (46 - length($name));
3313             $synop .= "  &quot;<link linkend=\"$id\">$name</link>&quot;$pad ";
3315             $desc .= "<refsect2 id=\"$id\" role=\"signal\"><title>The <literal>&quot;$name&quot;</literal> signal</title>\n";
3316             $desc .= MakeIndexterms($symbol, $id);
3317             $desc .= "\n";
3318             $desc .= OutputSymbolExtraLinks($symbol);
3320             $desc .= "<programlisting>";
3322             $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
3323             my $type_modifier = defined($1) ? $1 : "";
3324             my $type = $2;
3325             my $pointer = $3;
3326             my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
3328             my $ret_type_len = length ($type_modifier) + length ($pointer)
3329                 + length ($type);
3330             my $ret_type_output = "$type_modifier$xref$pointer"
3331                 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
3333             $desc  .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
3335             my $sourceparams = $SourceSymbolParams{$symbol};
3336             my @params = split ("\n", $SignalPrototypes[$i]);
3337             my $j;
3338             my $l;
3339             my $type_len = length("gpointer");
3340             my $name_len = length("user_data");
3341             # do two passes, the first one is to calculate padding
3342             for ($l = 0; $l < 2; $l++) {
3343                 for ($j = 0; $j <= $#params; $j++) {
3344                     # allow alphanumerics, '_', '[' & ']' in param names
3345                     if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
3346                         $type = $1;
3347                         $pointer = $2;
3348                         if (defined($sourceparams)) {
3349                             $name = $$sourceparams[$PARAM_FIELD_COUNT * $j];
3350                         }
3351                         else {
3352                             $name = $3;
3353                         }
3354                         if (!defined($name)) {
3355                             $name = "arg$j";
3356                         }
3357                         if ($l == 0) {
3358                             if (length($type) + length($pointer) > $type_len) {
3359                                 $type_len = length($type) + length($pointer);
3360                             }
3361                             if (length($name) > $name_len) {
3362                                 $name_len = length($name);
3363                             }
3364                         }
3365                         else {
3366                             $xref = &MakeXRef ($type, &tagify($type, "type"));
3367                             $pad = ' ' x ($type_len - length($type) - length($pointer));
3368                             $desc .= "$xref$pad $pointer$name,\n";
3369                             $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
3370                         }
3371                     } else {
3372                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3373                              "Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]");
3374                     }
3375                 }
3376             }
3377             $xref = &MakeXRef ("gpointer", &tagify("gpointer", "type"));
3378             $pad = ' ' x ($type_len - length("gpointer"));
3379             $desc  .= "$xref$pad user_data)";
3381             my $flags = $SignalFlags[$i];
3382             my $flags_string = "";
3384             if (defined ($flags)) {
3385               if ($flags =~ m/f/) {
3386                 $flags_string = "<link linkend=\"G-SIGNAL-RUN-FIRST:CAPS\"><literal>Run First</literal></link>";
3387               }
3388               elsif ($flags =~ m/l/) {
3389                 $flags_string = "<link linkend=\"G-SIGNAL-RUN-LAST:CAPS\"><literal>Run Last</literal></link>";
3390               }
3391               elsif ($flags =~ m/c/) {
3392                 $flags_string = "<link linkend=\"G-SIGNAL-RUN-CLEANUP:CAPS\"><literal>Cleanup</literal></link>";
3393                 $flags_string = "Cleanup";
3394               }
3395               if ($flags =~ m/r/) {
3396                 if ($flags_string) { $flags_string .= " / "; }
3397                 $flags_string = "<link linkend=\"G-SIGNAL-NO-RECURSE:CAPS\"><literal>No Recursion</literal></link>";
3398               }
3399               if ($flags =~ m/d/) {
3400                 if ($flags_string) { $flags_string .= " / "; }
3401                 $flags_string = "<link linkend=\"G-SIGNAL-DETAILED:CAPS\"><literal>Has Details</literal></link>";
3402               }
3403               if ($flags =~ m/a/) {
3404                 if ($flags_string) { $flags_string .= " / "; }
3405                 $flags_string = "<link linkend=\"G-SIGNAL-ACTION:CAPS\"><literal>Action</literal></link>";
3406               }
3407               if ($flags =~ m/h/) {
3408                 if ($flags_string) { $flags_string .= " / "; }
3409                 $flags_string = "<link linkend=\"G-SIGNAL-NO-HOOKS:CAPS\"><literal>No Hooks</literal></link>";
3410               }
3411             }
3413             if ($flags_string)
3414               {
3415                 $synop .= ": $flags_string\n";
3417                 $pad = ' ' x (5 + $name_len - length("user_data"));
3418                 $desc  .= "$pad : $flags_string</programlisting>\n";
3419               }
3420             else
3421               {
3422                 $synop .= "\n";
3423                 $desc  .= "</programlisting>\n";
3424               }
3426             $desc .= &MakeDeprecationNote($symbol);
3428             my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
3429             my $parameters_output = 0;
3431             $AllSymbols{$symbol} = 1;
3432             if (defined ($SymbolDocs{$symbol})) {
3433                 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3435                 # Try to insert the parameter table at the author's desired
3436                 # position. Otherwise we need to tag it onto the end.
3437                 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
3438                   $parameters_output = 1;
3439                 }
3440                 $desc .= $symbol_docs;
3442                 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
3443                     $AllDocumentedSymbols{$symbol} = 1;
3444                 }
3445             }
3447             if ($parameters_output == 0) {
3448                 $desc .= $parameters;
3449               }
3450             $desc .= OutputSymbolTraits ($symbol);
3451             $desc .= "</refsect2>";
3452         }
3453     }
3454     return ($synop, $desc);
3458 #############################################################################
3459 # Function    : GetArgs
3460 # Description : Returns the synopsis and detailed description DocBook output
3461 #                for the Args of a given GtkObject subclass.
3462 # Arguments   : $object - the GtkObject subclass, e.g. 'GtkButton'.
3463 #############################################################################
3465 sub GetArgs {
3466     my ($object) = @_;
3467     my $synop = "";
3468     my $desc = "";
3469     my $child_synop = "";
3470     my $child_desc = "";
3471     my $style_synop = "";
3472     my $style_desc = "";
3474     my $i;
3475     for ($i = 0; $i <= $#ArgObjects; $i++) {
3476         if ($ArgObjects[$i] eq $object) {
3477             #print "Found arg: $ArgNames[$i]\n";
3478             my $name = $ArgNames[$i];
3479             my $flags = $ArgFlags[$i];
3480             my $flags_string = "";
3481             my $kind = "";
3482             my $id_sep = "";
3484             if ($flags =~ m/c/) {
3485                 $kind = "child property";
3486                 $id_sep = "c-";
3487             }
3488             elsif ($flags =~ m/s/) {
3489                 $kind = "style property";
3490                 $id_sep = "s-";
3491             }
3492             else {
3493                 $kind = "property";
3494             }
3496             # Remember only one colon so we don't clash with signals.
3497             my $symbol = "${object}:${name}";
3498             # use two dashes and ev. an extra separator here for the same reason.
3499             my $id = &CreateValidSGMLID ("$object--$id_sep$name");
3501             my $type = $ArgTypes[$i];
3502             my $type_output;
3503             my $range = $ArgRanges[$i];
3504             my $range_output = CreateValidSGML ($range);
3505             my $default = $ArgDefaults[$i];
3506             my $default_output = CreateValidSGML ($default);
3508             if ($type eq "GtkString") {
3509                 $type = "char*";
3510             }
3511             if ($type eq "GtkSignal") {
3512                 $type = "GtkSignalFunc, gpointer";
3513                 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
3514                     . &MakeXRef ("gpointer");
3515             } elsif ($type =~ m/^(\w+)\*$/) {
3516                 $type_output = &MakeXRef ($1, &tagify($1, "type")) . "*";
3517             } else {
3518                 $type_output = &MakeXRef ($type, &tagify($type, "type"));
3519             }
3521             if ($flags =~ m/r/) {
3522                 $flags_string = "Read";
3523             }
3524             if ($flags =~ m/w/) {
3525                 if ($flags_string) { $flags_string .= " / "; }
3526                 $flags_string .= "Write";
3527             }
3528             if ($flags =~ m/x/) {
3529                 if ($flags_string) { $flags_string .= " / "; }
3530                 $flags_string .= "Construct";
3531             }
3532             if ($flags =~ m/X/) {
3533                 if ($flags_string) { $flags_string .= " / "; }
3534                 $flags_string .= "Construct Only";
3535             }
3537             $AllSymbols{$symbol} = 1;
3538             my $blurb;
3539             if (defined($SymbolDocs{$symbol}) &&
3540                 !IsEmptyDoc($SymbolDocs{$symbol})) {
3541                 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3542                 #print ".. [$SymbolDocs{$symbol}][$blurb]\n";
3543                 $AllDocumentedSymbols{$symbol} = 1;
3544             }
3545             else {
3546                 if (!($ArgBlurbs[$i] eq "")) {
3547                     $AllDocumentedSymbols{$symbol} = 1;
3548                 } else {
3549                     # FIXME: print a warning?
3550                     #print ".. no description\n";
3551                 }
3552                 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
3553             }
3555             my $pad1 = " " x (24 - length ($name));
3556             my $pad2 = " " x (20 - length ($type));
3558              my $arg_synop = "  &quot;<link linkend=\"$id\">$name</link>&quot;$pad1 $type_output $pad2 : $flags_string\n";
3559             my $arg_desc = "<refsect2 id=\"$id\" role=\"property\"><title>The <literal>&quot;$name&quot;</literal> $kind</title>\n";
3560             $arg_desc .= MakeIndexterms($symbol, $id);
3561             $arg_desc .= "\n";
3562             $arg_desc .= OutputSymbolExtraLinks($symbol);
3564             $arg_desc .= "<programlisting>  &quot;$name&quot;$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
3565             $arg_desc .= &MakeDeprecationNote($symbol);
3566             $arg_desc .= $blurb;
3567             if ($range ne "") {
3568                 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
3569             }
3570             if ($default ne "") {
3571                 $arg_desc .= "<para>Default value: $default_output</para>\n";
3572             }
3573             $arg_desc .= OutputSymbolTraits ($symbol);
3574             $arg_desc .= "</refsect2>\n";
3576             if ($flags =~ m/c/) {
3577                 $child_synop .= $arg_synop;
3578                 $child_desc .= $arg_desc;
3579             }
3580             elsif ($flags =~ m/s/) {
3581                 $style_synop .= $arg_synop;
3582                 $style_desc .= $arg_desc;
3583             }
3584             else {
3585                 $synop .= $arg_synop;
3586                 $desc .= $arg_desc;
3587             }
3588         }
3589     }
3590     return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
3594 #############################################################################
3595 # Function    : ReadSourceDocumentation
3596 # Description : This reads in the documentation embedded in comment blocks
3597 #                in the source code (for Gnome).
3599 #                Parameter descriptions override any in the template files.
3600 #                Function descriptions are placed before any description from
3601 #                the template files.
3603 #                It recursively descends the source directory looking for .c
3604 #                files and scans them looking for specially-formatted comment
3605 #                blocks.
3607 # Arguments   : $source_dir - the directory to scan.
3608 #############m###############################################################
3610 sub ReadSourceDocumentation {
3611     my ($source_dir) = @_;
3612     my ($file, $dir, @suffix_list, $suffix);
3614     # prepend entries from @SOURCE_DIR
3615     for my $dir (@SOURCE_DIRS) {
3616         # Check if the filename is in the ignore list.
3617         if ($source_dir =~ m%^\Q$dir\E/(.*)$% and $IGNORE_FILES =~ m/(\s|^)\Q$1\E(\s|$)/) {
3618             @TRACE@("Skipping source directory: $source_dir");
3619             return;
3620         }
3621     }
3623     @TRACE@("Scanning source directory: $source_dir");
3625     # This array holds any subdirectories found.
3626     my (@subdirs) = ();
3628     @suffix_list = split (/,/, $SOURCE_SUFFIXES);
3630     opendir (SRCDIR, $source_dir)
3631         || die "Can't open source directory $source_dir: $!";
3633     foreach $file (readdir (SRCDIR)) {
3634       if ($file =~ /^\./) {
3635         next;
3636       } elsif (-d "$source_dir/$file") {
3637         push (@subdirs, $file);
3638       } elsif (@suffix_list) {
3639         foreach $suffix (@suffix_list) {
3640           if ($file =~ m/\.\Q${suffix}\E$/) {
3641             &ScanSourceFile ("$source_dir/$file");
3642           }
3643         }
3644       } elsif ($file =~ m/\.[ch]$/) {
3645         &ScanSourceFile ("$source_dir/$file");
3646       }
3647     }
3648     closedir (SRCDIR);
3650     # Now recursively scan the subdirectories.
3651     foreach $dir (@subdirs) {
3652         &ReadSourceDocumentation ("$source_dir/$dir");
3653     }
3657 #############################################################################
3658 # Function    : ScanSourceFile
3659 # Description : Scans one source file looking for specially-formatted comment
3660 #                blocks. Later &MergeSourceDocumentation is used to merge any
3661 #                documentation found with the documentation already read in
3662 #                from the template files.
3664 # Arguments   : $file - the file to scan.
3665 #############################################################################
3667 sub ScanSourceFile {
3668     my ($file) = @_;
3669     my $basename;
3671     # prepend entries from @SOURCE_DIR
3672     for my $dir (@SOURCE_DIRS) {
3673         # Check if the filename is in the ignore list.
3674         if ($file =~ m%^\Q$dir\E/(.*)$% and $IGNORE_FILES =~ m/(\s|^)\Q$1\E(\s|$)/) {
3675             @TRACE@("Skipping source file: $file");
3676             return;
3677         }
3678     }
3680     if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
3681         $basename = $1;
3682     } else {
3683         &LogWarning ($file, 1, "Can't find basename for this filename.");
3684         $basename = $file;
3685     }
3687     # Check if the basename is in the list of files to ignore.
3688     if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
3689         @TRACE@("Skipping source file: $file");
3690         return;
3691     }
3693     @TRACE@("Scanning source file: $file");
3695     open (SRCFILE, $file)
3696         || die "Can't open $file: $!";
3697     my $in_comment_block = 0;
3698     my $symbol;
3699     my ($in_description, $in_return, $in_since, $in_stability, $in_deprecated);
3700     my ($description, $return_desc, $return_start, $return_style);
3701     my ($since_desc, $stability_desc, $deprecated_desc);
3702     my $current_param;
3703     my $ignore_broken_returns;
3704     my @params;
3705     while (<SRCFILE>) {
3706         # Look for the start of a comment block.
3707         if (!$in_comment_block) {
3708             if (m%^\s*/\*.*\*/%) {
3709                 #one-line comment - not gtkdoc
3710             } elsif (m%^\s*/\*\*\s%) {
3711                 #print "Found comment block start\n";
3713                 $in_comment_block = 1;
3715                 # Reset all the symbol data.
3716                 $symbol = "";
3717                 $in_description = 0;
3718                 $in_return = 0;
3719                 $in_since = 0;
3720                 $in_deprecated = 0;
3721                 $in_stability = 0;
3722                 $description = "";
3723                 $return_desc = "";
3724                 $return_style = "";
3725                 $since_desc = "";
3726                 $deprecated_desc = "";
3727                 $stability_desc = "";
3728                 $current_param = -1;
3729                 $ignore_broken_returns = 0;
3730                 @params = ();
3731             }
3732             next;
3733         }
3735         # We're in a comment block. Check if we've found the end of it.
3736         if (m%^\s*\*+/%) {
3737             if (!$symbol) {
3738                 # maybe its not even meant to be a gtk-doc comment?
3739                 &LogWarning ($file, $., "Symbol name not found at the start of the comment block.");
3740             } else {
3741                 # Add the return value description onto the end of the params.
3742                 if ($return_desc) {
3743                     push (@params, "Returns");
3744                     push (@params, $return_desc);
3745                     if ($return_style eq 'broken') {
3746                         &LogWarning ($file, $., "Free-form return value description in $symbol. Use `Returns:' to avoid ambiguities.");
3747                     }
3748                 }
3749                 # Convert special SGML characters
3750                 $description = &ConvertSGMLChars ($symbol, $description);
3751                 my $k;
3752                 for ($k = 1; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3753                     $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
3754                 }
3756                 # Handle Section docs
3757                 if ($symbol =~ m/SECTION:\s*(.*)/) {
3758                     my $real_symbol=$1;
3759                     my $key;
3761                     if (scalar %KnownSymbols) {
3762                         if ((! defined($KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"})) || $KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"} != 1) {
3763                             &LogWarning ($file, $., "Section $real_symbol is not defined in the $MODULE-section.txt file.");
3764                         }
3765                     }
3767                     #print "SECTION DOCS found in source for : '$real_symbol'\n";
3768                     $ignore_broken_returns = 1;
3769                     for ($k = 0; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3770                         #print "   '".$params[$k]."'\n";
3771                         $params[$k] = "\L$params[$k]";
3772                         undef $key;
3773                         if ($params[$k] eq "short_description") {
3774                             $key = "$TMPL_DIR/$real_symbol:Short_Description";
3775                         } elsif ($params[$k] eq "see_also") {
3776                             $key = "$TMPL_DIR/$real_symbol:See_Also";
3777                         } elsif ($params[$k] eq "title") {
3778                             $key = "$TMPL_DIR/$real_symbol:Title";
3779                         } elsif ($params[$k] eq "stability") {
3780                             $key = "$TMPL_DIR/$real_symbol:Stability_Level";
3781                         } elsif ($params[$k] eq "section_id") {
3782                             $key = "$TMPL_DIR/$real_symbol:Section_Id";
3783                         } elsif ($params[$k] eq "include") {
3784                             $key = "$TMPL_DIR/$real_symbol:Include";
3785                         } elsif ($params[$k] eq "image") {
3786                             $key = "$TMPL_DIR/$real_symbol:Image";
3787                         }
3788                         if (defined($key)) {
3789                             $SourceSymbolDocs{$key}=$params[$k+1];
3790                             $SourceSymbolSourceFile{$key} = $file;
3791                             $SourceSymbolSourceLine{$key} = $.;
3792                         }
3793                     }
3794                     $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
3795                     $SourceSymbolSourceFile{"$TMPL_DIR/$real_symbol:Long_Description"} = $file;
3796                     $SourceSymbolSourceLine{"$TMPL_DIR/$real_symbol:Long_Description"} = $.;
3797                     #$SourceSymbolTypes{$symbol} = "SECTION";
3798                 } else {
3799                     #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
3800                     $SourceSymbolDocs{$symbol} = $description;
3801                     $SourceSymbolParams{$symbol} = [ @params ];
3802                     # FIXME $SourceSymbolTypes{$symbol} = "STRUCT,SIGNAL,ARG,FUNCTION,MACRO";
3803                     #if (defined $DeclarationTypes{$symbol}) {
3804                     #    $SourceSymbolTypes{$symbol} = $DeclarationTypes{$symbol}
3805                     #}
3806                     $SourceSymbolSourceFile{$symbol} = $file;
3807                     $SourceSymbolSourceLine{$symbol} = $.;
3808                 }
3810                 if ($since_desc) {
3811                      ($since_desc, my @extra_lines) = split ("\n", $since_desc);
3812                      $since_desc =~ s/^\s+//;
3813                      $since_desc =~ s/\s+$//;
3814                      #print "Since($symbol) : [$since_desc]\n";
3815                      $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
3816                      if(scalar @extra_lines) {
3817                          &LogWarning ($file, $., "multi-line since docs found");
3818                      }
3819                 }
3821                 if ($stability_desc) {
3822                     $stability_desc = &ParseStabilityLevel($stability_desc, $file, $., "Stability level for $symbol");
3823                     $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
3824                 }
3826                 if ($deprecated_desc) {
3827                     if (exists $Deprecated{$symbol}) {
3828                     }
3829                     else {
3830                          # don't warn for signals and properties
3831                          #if ($symbol !~ m/::?(.*)/) {
3832                          if (defined $DeclarationTypes{$symbol}) {
3833                              &LogWarning ($file, $.,
3834                                  "$symbol is deprecated in the inline comments, but no deprecation guards were found around the declaration.".
3835                                  " (See the --deprecated-guards option for gtkdoc-scan.)");
3836                          }
3837                     }
3838                     $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
3839                 }
3840             }
3842             $in_comment_block = 0;
3843             next;
3844         }
3846         # Get rid of ' * ' at start of every line in the comment block.
3847         s%^\s*\*\s?%%;
3848         # But make sure we don't get rid of the newline at the end.
3849         if (!$_) {
3850             $_ = "\n";
3851         }
3852         #print "DEBUG: scanning :$_";
3854         # If we haven't found the symbol name yet, look for it.
3855         if (!$symbol) {
3856             if (m%^\s*(SECTION:\s*\S+)%) {
3857                 $symbol = $1;
3858                 #print "SECTION DOCS found in source for : '$symbol'\n";
3859                 $ignore_broken_returns = 1;
3860             } elsif (m%^\s*([\w:-]*\w)\s*:?\s*(\([a-z ]+\)\s*)*$%) {
3861                 $symbol = $1;
3862                 #print "SYMBOL DOCS found in source for : '$symbol'\n";
3863             }
3864             next;
3865         }
3867         # FIXME: flip this around
3868         # instead of repeating the other parts, just have them once and
3869         # do if(!$in_return) { ... }
3870         # also maybe have in_part="description,return,since,deprecated,stability,..."
3872         # If we're in the return value description, add it to the end.
3873         if ($in_return) {
3874             # If we find another valid returns line, we assume that the first
3875             # one was really part of the description.
3876             if (m/^\s*(returns:|return\s+value:)/i) {
3877                 if ($return_style eq 'broken') {
3878                     $description .= $return_start . $return_desc;
3879                 }
3880                 $return_start = $1;
3881                 if ($return_style eq 'sane') {
3882                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3883                 }
3884                 $return_style = 'sane';
3885                 $ignore_broken_returns = 1;
3886                 $return_desc = $';
3887             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3888                 $description .= $return_start . $return_desc;
3889                 $return_start = $1;
3890                 $return_style = 'broken';
3891                 $return_desc = $';
3892             } elsif (m%^\s*since:%i) {
3893                 $since_desc = $';
3894                 $in_since = 1;
3895                 $in_return = 0;
3896             } elsif (m%^\s*stability:%i) {
3897                 $stability_desc = $';
3898                 $in_stability = 1;
3899                 $in_return = 0;
3900             } elsif (m%^\s*deprecated:%i) {
3901                 $deprecated_desc = $';
3902                 $in_deprecated = 1;
3903                 $in_return = 0;
3904             } else {
3905                 $return_desc .= $_;
3906             }
3907             next;
3908         }
3910         if ($in_since) {
3911             if (m/^\s*(returns:|return\s+value:)/i) {
3912                 if ($return_style eq 'broken') {
3913                     $description .= $return_start . $return_desc;
3914                 }
3915                 $return_start = $1;
3916                 if ($return_style eq 'sane') {
3917                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3918                 }
3919                 $return_style = 'sane';
3920                 $ignore_broken_returns = 1;
3921                 $return_desc = $';
3922                 $in_return = 1;
3923                 $in_since = 0;
3924             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3925                 $return_start = $1;
3926                 $return_style = 'broken';
3927                 $return_desc = $';
3928                 $in_return = 1;
3929                 $in_since = 0;
3930             } elsif (m%^\s*deprecated:%i) {
3931                 $deprecated_desc = $';
3932                 $in_deprecated = 1;
3933                 $in_since = 0;
3934             } elsif (m%^\s*stability:%i) {
3935                 $stability_desc = $';
3936                 $in_stability = 1;
3937                 $in_since = 0;
3938             } else {
3939                 $since_desc .= $_;
3940             }
3941             next;
3942         }
3944         if ($in_stability) {
3945             if (m/^\s*(returns:|return\s+value:)/i) {
3946                 if ($return_style eq 'broken') {
3947                     $description .= $return_start . $return_desc;
3948                 }
3949                 $return_start = $1;
3950                 if ($return_style eq 'sane') {
3951                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3952                 }
3953                 $return_style = 'sane';
3954                 $ignore_broken_returns = 1;
3955                 $return_desc = $';
3956                 $in_return = 1;
3957                 $in_stability = 0;
3958             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3959                 $return_start = $1;
3960                 $return_style = 'broken';
3961                 $return_desc = $';
3962                 $in_return = 1;
3963                 $in_stability = 0;
3964             } elsif (m%^\s*deprecated:%i) {
3965                 $deprecated_desc = $';
3966                 $in_deprecated = 1;
3967                 $in_stability = 0;
3968             } elsif (m%^\s*since:%i) {
3969                 $since_desc = $';
3970                 $in_since = 1;
3971                 $in_stability = 0;
3972             } else {
3973                 $stability_desc .= $_;
3974             }
3975             next;
3976         }
3978         if ($in_deprecated) {
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                 $in_deprecated = 0;
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                 $in_deprecated = 0;
3998             } elsif (m%^\s*since:%i) {
3999                 $since_desc = $';
4000                 $in_since = 1;
4001                 $in_deprecated = 0;
4002             } elsif (m%^\s*stability:%i) {
4003                 $stability_desc = $';
4004                 $in_stability = 1;
4005                 $in_deprecated = 0;
4006             } else {
4007                 $deprecated_desc .= $_;
4008             }
4009             next;
4010         }
4012         # If we're in the description part, check for the 'Returns:' line.
4013         # If that isn't found, add the text to the end.
4014         if ($in_description) {
4015             # Get rid of 'Description:'
4016             s%^\s*Description:%%;
4018             if (m/^\s*(returns:|return\s+value:)/i) {
4019                 if ($return_style eq 'broken') {
4020                     $description .= $return_start . $return_desc;
4021                 }
4022                 $return_start = $1;
4023                 if ($return_style eq 'sane') {
4024                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
4025                 }
4026                 $return_style = 'sane';
4027                 $ignore_broken_returns = 1;
4028                 $return_desc = $';
4029                 $in_return = 1;
4030                 next;
4031             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
4032                 $return_start = $1;
4033                 $return_style = 'broken';
4034                 $return_desc = $';
4035                 $in_return = 1;
4036                 next;
4037             } elsif (m%^\s*since:%i) {
4038                 $since_desc = $';
4039                 $in_since = 1;
4040                 next;
4041             } elsif (m%^\s*deprecated:%i) {
4042                 $deprecated_desc = $';
4043                 $in_deprecated = 1;
4044                 next;
4045             } elsif (m%^\s*stability:%i) {
4046                 $stability_desc = $';
4047                 $in_stability = 1;
4048                 next;
4049             }
4051             $description .= $_;
4052             next;
4053         }
4055         # We must be in the parameters. Check for the empty line below them.
4056         if (m%^\s*$%) {
4057             $in_description = 1;
4058             next;
4059         }
4061         # Look for a parameter name.
4062         if (m%^\s*@(\S+)\s*:\s*%) {
4063             my $param_name = $1;
4064             my $param_desc = $';
4066             #print "Found parameter: $param_name\n";
4067             # Allow varargs variations
4068             if ($param_name =~ m/^.*\.\.\.$/) {
4069                 $param_name = "...";
4070             }
4071             if ("\L$param_name" eq "returns") {
4072                 $return_style = 'sane';
4073                 $ignore_broken_returns = 1;
4074             }
4075             @TRACE@("Found param for symbol $symbol : '$param_name'= '$_'");
4077             push (@params, $param_name);
4078             push (@params, $param_desc);
4079             $current_param += $PARAM_FIELD_COUNT;
4080             next;
4081         }
4083         # We must be in the middle of a parameter description, so add it on
4084         # to the last element in @params.
4085         if ($current_param == -1) {
4086             &LogWarning ($file, $., "Parsing comment block file : parameter expected.");
4087         } else {
4088             $params[$#params] .= $_;
4089         }
4090     }
4091     close (SRCFILE);
4094 #############################################################################
4095 # Function    : OutputMissingDocumentation
4096 # Description : Outputs report of documentation coverage to a file
4098 # Arguments   : none
4099 #############################################################################
4101 sub OutputMissingDocumentation {
4102     my $old_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.txt";
4103     my $new_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.new";
4105     my $n_documented = 0;
4106     my $n_incomplete = 0;
4107     my $total = 0;
4108     my $symbol;
4109     my $percent;
4110     my $msg;
4111     my $buffer = "";
4112     my $buffer_deprecated = "";
4113     my $buffer_descriptions = "";
4115     open(UNDOCUMENTED, ">$new_undocumented_file")
4116       || die "Can't create $new_undocumented_file";
4118     foreach $symbol (sort (keys (%AllSymbols))) {
4119         # FIXME: should we print LogWarnings for undocumented stuff?
4120         # DEBUG
4121         #my $ssfile = &GetSymbolSourceFile($symbol);
4122         #my $ssline = &GetSymbolSourceLine($symbol);
4123         #my $location = "defined at " . (defined($ssfile)?$ssfile:"?") . ":" . (defined($ssline)?$ssline:"0") . "\n";
4124         # DEBUG
4125         if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include|Section_Id|Image)/) {
4126             $total++;
4127             if (exists ($AllDocumentedSymbols{$symbol})) {
4128                 $n_documented++;
4129                 if (exists ($AllIncompleteSymbols{$symbol})) {
4130                     $n_incomplete++;
4131                     $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4132                     #$buffer .= "\t0: ".$location;
4133                 }
4134             } elsif (exists $Deprecated{$symbol}) {
4135                 if (exists ($AllIncompleteSymbols{$symbol})) {
4136                     $n_incomplete++;
4137                     $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4138                     #$buffer .= "\t1a: ".$location;
4139                 } else {
4140                     $buffer_deprecated .= $symbol . "\n";
4141                     #$buffer .= "\t1b: ".$location;
4142                 }
4143             } else {
4144                 if (exists ($AllIncompleteSymbols{$symbol})) {
4145                     $n_incomplete++;
4146                     $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4147                     #$buffer .= "\t2a: ".$location;
4148                 } else {
4149                     $buffer .= $symbol . "\n";
4150                     #$buffer .= "\t2b: ".$location;
4151                 }
4152             }
4153         } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
4154             $total++;
4155             #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
4156             #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
4157             #print "%%%% $symbol : $len1,$len2\n";
4158             if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
4159             || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
4160               $n_documented++;
4161             } else {
4162               # cut off the leading namespace ($TMPL_DIR)
4163               $symbol =~ m/^.*\/(.*)$/;
4164               $buffer_descriptions .= $1 . "\n";
4165             }
4166         }
4167     }
4169     $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
4171     if ($total == 0) {
4172       $percent = 100;
4173     } else {
4174       $percent = ($n_documented / $total) * 100.0;
4175     }
4177     printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
4178     print UNDOCUMENTED "$n_documented symbols documented.\n";
4179     print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
4180     print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
4182     print UNDOCUMENTED $buffer;
4183     close (UNDOCUMENTED);
4185     return &UpdateFileIfChanged ($old_undocumented_file, $new_undocumented_file, 0);
4187     printf "%.0f%% symbol docs coverage", $percent;
4188     print "($n_documented symbols documented, $n_incomplete symbols incomplete, " . ($total - $n_documented) . " not documented)\n";
4189     print "See $MODULE-undocumented.txt for a list of missing docs.\nThe doc coverage percentage doesn't include intro sections.\n";
4193 #############################################################################
4194 # Function    : OutputUndeclaredSymbols
4195 # Description : Outputs symbols that are listed in the section file, but not
4196 #               declaration is found in the sources
4198 # Arguments   : none
4199 #############################################################################
4201 sub OutputUndeclaredSymbols {
4202     my $old_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.txt";
4203     my $new_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.new";
4205     open(UNDECLARED, ">$new_undeclared_file")
4206         || die "Can't create $new_undeclared_file";
4208     if (%UndeclaredSymbols) {
4209         print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
4210         print UNDECLARED "\n";
4211         print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
4212     }
4213     close(UNDECLARED);
4215     return &UpdateFileIfChanged ($old_undeclared_file, $new_undeclared_file, 0);
4218 #############################################################################
4219 # Function    : OutputUnusedSymbols
4220 # Description : Outputs symbols that are documented in comments, but not
4221 #               declared in the sources
4223 # Arguments   : none
4224 #############################################################################
4226 sub OutputUnusedSymbols {
4227     my $num_unused = 0;
4228     my $old_unused_file = "$ROOT_DIR/$MODULE-unused.txt";
4229     my $new_unused_file = "$ROOT_DIR/$MODULE-unused.new";
4231     open (UNUSED, ">$new_unused_file")
4232         || die "Can't open $new_unused_file";
4233     my ($symbol);
4234     foreach $symbol (sort keys (%Declarations)) {
4235         if (!defined ($DeclarationOutput{$symbol})) {
4236             print (UNUSED "$symbol\n");
4237             $num_unused++;
4238         }
4239     }
4240     foreach $symbol (sort (keys (%AllUnusedSymbols))) {
4241         print (UNUSED "$symbol(" . $AllUnusedSymbols{$symbol} . ")\n");
4242         $num_unused++;
4243     }
4244     close (UNUSED);
4245     if ($num_unused != 0) {
4246         &LogWarning ($old_unused_file, 1, "$num_unused unused declarations.".
4247             "They should be added to $MODULE-sections.txt in the appropriate place.");
4248     }
4250     return &UpdateFileIfChanged ($old_unused_file, $new_unused_file, 0);
4254 #############################################################################
4255 # Function    : OutputAllSymbols
4256 # Description : Outputs list of all symbols to a file
4258 # Arguments   : none
4259 #############################################################################
4261 sub OutputAllSymbols {
4262      my $n_documented = 0;
4263      my $total = 0;
4264      my $symbol;
4265      my $percent;
4266      my $msg;
4268      open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
4269           || die "Can't create $ROOT_DIR/$MODULE-symbols.txt: $!";
4271      foreach $symbol (sort (keys (%AllSymbols))) {
4272           print SYMBOLS $symbol . "\n";
4273      }
4275      close (SYMBOLS);
4278 #############################################################################
4279 # Function    : OutputSymbolsWithoutSince
4280 # Description : Outputs list of all symbols without a since tag to a file
4282 # Arguments   : none
4283 #############################################################################
4285 sub OutputSymbolsWithoutSince {
4286      my $n_documented = 0;
4287      my $total = 0;
4288      my $symbol;
4289      my $percent;
4290      my $msg;
4292      open (SYMBOLS, ">$ROOT_DIR/$MODULE-nosince.txt")
4293           || die "Can't create $ROOT_DIR/$MODULE-nosince.txt: $!";
4295      foreach $symbol (sort (keys (%SourceSymbolDocs))) {
4296          if (!defined $Since{$symbol}) {
4297              print SYMBOLS $symbol . "\n";
4298          }
4299      }
4301      close (SYMBOLS);
4305 #############################################################################
4306 # Function    : MergeSourceDocumentation
4307 # Description : This merges documentation read from a source file into the
4308 #                documentation read in from a template file.
4310 #                Parameter descriptions override any in the template files.
4311 #                Function descriptions are placed before any description from
4312 #                the template files.
4314 # Arguments   : none
4315 #############################################################################
4317 sub MergeSourceDocumentation {
4318     my $symbol;
4319     my @Symbols;
4321     if (scalar %SymbolDocs) {
4322         @Symbols=keys (%SymbolDocs);
4323         #print "num existing entries: ".(scalar @Symbols)."\n";
4324         #print "  ",$Symbols[0], " ",$Symbols[1],"\n";
4325     }
4326     else {
4327         # filter scanned declarations, with what we suppress from -sections.txt
4328         my %tmp = ();
4329         foreach $symbol (keys (%Declarations)) {
4330             if (defined($KnownSymbols{$symbol}) && $KnownSymbols{$symbol} == 1) {
4331                 $tmp{$symbol}=1;
4332             }
4333         }
4334         # , add the rest from -sections.txt
4335         foreach $symbol (keys (%KnownSymbols)) {
4336             if ($KnownSymbols{$symbol} == 1) {
4337                 $tmp{$symbol}=1;
4338             }
4339         }
4340         # and add whats found in the source
4341         foreach $symbol (keys (%SourceSymbolDocs)) {
4342             $tmp{$symbol}=1;
4343         }
4344         @Symbols = keys (%tmp);
4345         #print "num source entries: ".(scalar @Symbols)."\n";
4346     }
4347     foreach $symbol (@Symbols) {
4348         $AllSymbols{$symbol} = 1;
4350         my $have_tmpl_docs = 0;
4352         ## see if the symbol is documented in template
4353         my $tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4354         my $check_tmpl_doc =$tmpl_doc;
4355         # remove all xml-tags and whitespaces
4356         $check_tmpl_doc =~ s/<.*?>//g;
4357         $check_tmpl_doc =~ s/\s//g;
4358         # anything left ?
4359         if ($check_tmpl_doc ne "") {
4360             $have_tmpl_docs = 1;
4361             #print "## [$check_tmpl_doc]\n";
4362         } else {
4363             # if the docs have just an empty para, don't merge that.
4364             $check_tmpl_doc = $tmpl_doc;
4365             $check_tmpl_doc =~ s/(\s|\n)//msg;
4366             if ($check_tmpl_doc eq "<para></para>") {
4367                $tmpl_doc = "";
4368             }
4369         }
4371         if (exists ($SourceSymbolDocs{$symbol})) {
4372             my $type = $DeclarationTypes {$symbol};
4374             #print "merging [$symbol] from source\n";
4376             my $item = "Parameter";
4377             if (defined ($type)) {
4378                 if ($type eq 'STRUCT') {
4379                     $item = "Field";
4380                 } elsif ($type eq 'ENUM') {
4381                     $item = "Value";
4382                 } elsif ($type eq 'UNION') {
4383                     $item = "Field";
4384                 }
4385             } else {
4386                 $type="SIGNAL";
4387             }
4389             my $src_doc = $SourceSymbolDocs{$symbol};
4390             # remove leading and training whitespaces
4391             $src_doc =~ s/^\s+//;
4392             $src_doc =~ s/\s+$//;
4394             # Don't output warnings for overridden titles as titles are
4395             # automatically generated in the -sections.txt file, and thus they
4396             # are often overridden.
4397             if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
4398                 # check if content is different
4399                 if ($tmpl_doc ne $src_doc) {
4400                     #print "[$tmpl_doc] [$src_doc]\n";
4401                     &LogWarning ($SourceSymbolSourceFile{$symbol}, $SourceSymbolSourceLine{$symbol},
4402                         "Documentation in template ".$SymbolSourceFile{$symbol}.":".$SymbolSourceLine{$symbol}." for $symbol being overridden by inline comments.");
4403                 }
4404             }
4406             if ($src_doc ne "") {
4407                  $AllDocumentedSymbols{$symbol} = 1;
4408             }
4410             # Convert <!--PARAMETERS--> with any blank lines around it to
4411             # a </para> followed by <!--PARAMETERS--> followed by <para>.
4412             $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
4414             # Do not add <para> to nothing, it breaks missing docs checks.
4415             my $src_doc_para = "";
4416             if ($src_doc ne "") {
4417                 # Expand markdown (and do paragraphs)
4418                 $src_doc_para = &ConvertMarkDown ($src_doc, $symbol);
4419                 ## fixup xml markup
4420                 # FIXME: this is questionable, as we can't make assumtions on the content really
4421                 #$src_doc_para =~ s%^<para>\n(<refsect[1-9])%$1%gms;
4422                 #$src_doc_para =~ s%^<para>\n<para>%<para>%gms;
4423                 #$src_doc_para =~ s%(</refsect[1-9]>)\n</para>$%$1%gms;
4424                 #print "$symbol : [$src_doc][$src_doc_para]\n";
4425             }
4427             if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
4428                 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4429             } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
4430                 # For the title/summary/see also section docs we don't want to
4431                 # add any <para> tags.
4432                 $SymbolDocs{$symbol} = "$src_doc"
4433             } else {
4434                 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4435             }
4437             # merge parameters
4438             if ($symbol =~ m/.*::.*/) {
4439                 # For signals we prefer the param names from the source docs,
4440                 # since the ones from the templates are likely to contain the
4441                 # artificial argn names which are generated by gtkdoc-scangobj.
4442                 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4443                 # FIXME: we need to check for empty docs here as well!
4444             } else {
4445                 # The templates contain the definitive parameter names and order,
4446                 # so we will not change that. We only override the actual text.
4447                 my $tmpl_params = $SymbolParams{$symbol};
4448                 if (!defined ($tmpl_params)) {
4449                     #print "No merge needed for $symbol\n";
4450                     $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4451                     #  FIXME: we still like to get the number of params and merge
4452                     #  1) we would noticed that params have been removed/renamed
4453                     #  2) we would catch undocumented params
4454                     #  params are not (yet) exported in -decl.txt so that we
4455                     #  could easily grab them :/
4456                 } else {
4457                     my $params = $SourceSymbolParams{$symbol};
4458                     my $j;
4459                     #print "Merge needed for $symbol, tmpl_params: ",$#$tmpl_params,", source_params: ",$#$params," \n";
4460                     for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4461                         my $tmpl_param_name = $$tmpl_params[$j];
4463                         # Try to find the param in the source comment documentation.
4464                         my $found = 0;
4465                         my $k;
4466                         #print "  try merge param $tmpl_param_name\n";
4467                         for ($k = 0; $k <= $#$params; $k += $PARAM_FIELD_COUNT) {
4468                             my $param_name = $$params[$k];
4469                             my $param_desc = $$params[$k + 1];
4471                             #print "    test param  $param_name\n";
4472                             # We accept changes in case, since the Gnome source
4473                             # docs contain a lot of these.
4474                             if ("\L$param_name" eq "\L$tmpl_param_name") {
4475                                 $found = 1;
4477                                 # Override the description.
4478                                 $$tmpl_params[$j + 1] = $param_desc;
4480                                 # Set the name to "" to mark it as used.
4481                                 $$params[$k] = "";
4482                                 last;
4483                             }
4484                         }
4486                         # If it looks like the parameters are there, but not
4487                         # in the right place, try to explain a bit better.
4488                         if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
4489                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4490                                 "Parameters for $symbol must start on the line immediately after the function or macro name.");
4491                         }
4492                     }
4494                     # Now we output a warning if parameters have been described which
4495                     # do not exist.
4496                     for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
4497                         my $param_name = $$params[$j];
4498                         if ($param_name) {
4499                             # the template builder cannot detect if a macro returns
4500                             # a result or not
4501                             if(($type eq "MACRO") && ($param_name eq "Returns")) {
4502                                 # FIXME: do we need to add it then to tmpl_params[] ?
4503                                 my $num=$#$tmpl_params;
4504                                 #print "  adding Returns: to macro docs for $symbol.\n";
4505                                 $$tmpl_params[$num+1]="Returns";
4506                                 $$tmpl_params[$num+2]=$$params[$j+1];
4507                                 next;
4508                             }
4509                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4510                                 "$item described in source code comment block but does not exist. $type: $symbol $item: $param_name.");
4511                         }
4512                     }
4513                 }
4514             }
4515         } else {
4516             if ($have_tmpl_docs) {
4517                 $AllDocumentedSymbols{$symbol} = 1;
4518                 #print "merging [$symbol] from template\n";
4519             }
4520             else {
4521                 #print "[$symbol] undocumented\n";
4522             }
4523         }
4525         # if this symbol is documented, check if docs are complete
4526         $check_tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4527         # remove all xml-tags and whitespaces
4528         $check_tmpl_doc =~ s/<.*?>//g;
4529         $check_tmpl_doc =~ s/\s//g;
4530         if ($check_tmpl_doc ne "") {
4531             my $tmpl_params = $SymbolParams{$symbol};
4532             if (defined ($tmpl_params)) {
4533                 my $type = $DeclarationTypes {$symbol};
4535                 my $item = "Parameter";
4536                 if (defined ($type)) {
4537                     if ($type eq 'STRUCT') {
4538                         $item = "Field";
4539                     } elsif ($type eq 'ENUM') {
4540                         $item = "Value";
4541                     } elsif ($type eq 'UNION') {
4542                         $item = "Field";
4543                     }
4544                 } else {
4545                     $type="SIGNAL";
4546                 }
4548                 #print "Check param docs for $symbol, tmpl_params: ",$#$tmpl_params," entries, type=$type\n";
4550                 if ($#$tmpl_params > 0) {
4551                     my $j;
4552                     for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4553                         # Output a warning if the parameter is empty and
4554                         # remember for stats.
4555                         my $tmpl_param_name = $$tmpl_params[$j];
4556                         my $tmpl_param_desc = $$tmpl_params[$j + 1];
4557                         if ($tmpl_param_name ne "void" && $tmpl_param_desc !~ m/\S/) {
4558                             if (exists ($AllIncompleteSymbols{$symbol})) {
4559                                 $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
4560                             } else {
4561                                 $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
4562                             }
4563                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4564                                 "$item description for $symbol"."::"."$tmpl_param_name is missing in source code comment block.");
4565                         }
4566                     }
4567                 }
4568                 else {
4569                     if ($#$tmpl_params == 0) {
4570                         $AllIncompleteSymbols{$symbol}="<items>";
4571                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4572                             "$item descriptions for $symbol are missing in source code comment block.");
4573                     }
4574                     # $#$tmpl_params==-1 means we don't know about parameters
4575                     # this unfortunately does not tell if there should be some
4576                 }
4577             }
4578         }
4579    }
4580    #print "num doc entries: ".(scalar %SymbolDocs)."\n";
4583 #############################################################################
4584 # Function    : IsEmptyDoc
4585 # Description : Check if a doc-string is empty. Its also regarded as empty if
4586 #               it only consist of whitespace or e.g. FIXME.
4587 # Arguments   : the doc-string
4588 #############################################################################
4589 sub IsEmptyDoc {
4590     my ($doc) = @_;
4592     if ($doc =~ /^\s*$/) {
4593         return 1;
4594     }
4596     if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
4597         return 1;
4598     }
4600     return 0;
4604 #############################################################################
4605 # Function    : ConvertMarkDown
4606 # Description : Converts mark down syntax to the respective docbook, but only
4607 #               outside CDATA and <programlisting> tags.
4608 #               http://de.wikipedia.org/wiki/Markdown
4609 #               Code snippets have been takesn from
4610 #               http://daringfireball.net/projects/markdown/
4611 #                 Copyright (c) 2004 John Gruber
4612 # Arguments   : the doc-string, the symbol name
4613 #############################################################################
4614 my $md_in_refsect2;
4615 sub ConvertMarkDown {
4616     my ($text, $symbol) = @_;
4618     # reset state
4619     $md_in_refsect2=0;
4621     # convert
4622     $text = &ModifyXMLElements ($text, $symbol,
4623                                "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
4624                                \&ConvertMarkDownEndTag,
4625                                \&ConvertMarkDownCallback);
4626     # encapsulate and terminate
4627     $text = "<para>\n$text\n</para>";
4628     if ($md_in_refsect2==1) {
4629         $text = "$text</refsect2>"
4630     }
4631     return $text
4634 sub ConvertMarkDownEndTag {
4635   if ($_[0] eq "<!\[CDATA\[") {
4636     return "]]>";
4637   } elsif ($_[0] eq "|[") {
4638     return "]\\|";
4639   } else {
4640     return "</programlisting>";
4641   }
4644 sub ConvertMarkDownCallback {
4645   my ($text, $symbol, $tag) = @_;
4647   # If we're not in CDATA or a <programlisting> we convert blank lines so
4648   # they start a new <para>.
4649   if ($tag eq "") {
4650     my $end_of_para="";
4651     my $end_of_section="";
4652     my $have_list=0;
4654     $end_of_para = "$end_of_para</para>";
4655     $end_of_section = "$end_of_section</para>";
4656     if ($md_in_refsect2==1) {
4657         $end_of_section= "$end_of_section</refsect2>";
4658     }
4660     # Setext-style headers:
4661     #          Header 1
4662     #          ========
4663     #
4664     #          Header 2
4665     #          --------
4666     #
4667     if($text =~ s%^\n(.+)[ \t]*\n=+[ \t]*\n\n%$end_of_section<refsect2><title>$1</title><para>\n%gm) {
4668         $md_in_refsect2=1;
4669     }
4671     # atx-style headers:
4672     #        # Header 1
4673     #        ## Header 2
4674     #        ## Header 2 with closing hashes ##
4675     #        ...
4676     #        ###### Header 6
4677     #
4678     if($text =~ s%^\n\#[ \t]*(.+?)[ \t]*\#\n+%$end_of_section<refsect2><title>$1</title><para>\n%gm) {
4679         $md_in_refsect2=1;
4680     }
4682     # Simple (unnested) lists:
4683     #   Please select:
4684     #   - item 1
4685     #   - item 2 with loooong
4686     #     description
4687     #   - item 3
4688     #
4689     #   New paragraph.
4690     $text.="\n"; # we need a new line to avoid too complicated matching rules below
4691     if ($text =~ s%(?<=\n)-\s+(.+?)(?=(?:\n-\s+)|(?:\n\n)|(?:\n$))%<listitem><para>$1</para></listitem>%gs) {
4692         $text =~ s%(?<!</listitem>)(\n<listitem>)%\n<itemizedlist>$1%g;
4693         $text =~ s%(</listitem>\n)(?!<listitem>)%$1</itemizedlist>\n%g;
4694     }
4695     chomp $text;
4697     # Make Paragraphs on blank lines
4698     $text =~ s%\n{2,}%\n$end_of_para\n<para>\n%g;
4699   }
4701   return $text;
4705 #############################################################################
4706 # LIBRARY FUNCTIONS -        These functions are used in both gtkdoc-mkdb and
4707 #                        gtkdoc-mktmpl and should eventually be moved to a
4708 #                        separate library.
4709 #############################################################################
4711 #############################################################################
4712 # Function    : ReadDeclarationsFile
4713 # Description : This reads in a file containing the function/macro/enum etc.
4714 #                declarations.
4716 #                Note that in some cases there are several declarations with
4717 #                the same name, e.g. for conditional macros. In this case we
4718 #                set a flag in the %DeclarationConditional hash so the
4719 #                declaration is not shown in the docs.
4721 #                If a macro and a function have the same name, e.g. for
4722 #                gtk_object_ref, the function declaration takes precedence.
4724 #                Some opaque structs are just declared with 'typedef struct
4725 #                _name name;' in which case the declaration may be empty.
4726 #                The structure may have been found later in the header, so
4727 #                that overrides the empty declaration.
4729 # Arguments   : $file - the declarations file to read
4730 #                $override - if declarations in this file should override
4731 #                        any current declaration.
4732 #############################################################################
4734 sub ReadDeclarationsFile {
4735     my ($file, $override) = @_;
4737     if ($override == 0) {
4738         %Declarations = ();
4739         %DeclarationTypes = ();
4740         %DeclarationConditional = ();
4741         %DeclarationOutput = ();
4742     }
4744     open (INPUT, $file)
4745         || die "Can't open $file: $!";
4746     my $declaration_type = "";
4747     my $declaration_name;
4748     my $declaration;
4749     my $is_deprecated = 0;
4750     while (<INPUT>) {
4751         if (!$declaration_type) {
4752             if (m/^<([^>]+)>/) {
4753                 $declaration_type = $1;
4754                 $declaration_name = "";
4755                 #print "Found declaration: $declaration_type\n";
4756                 $declaration = "";
4757             }
4758         } else {
4759             if (m%^<NAME>(.*)</NAME>%) {
4760                 $declaration_name = $1;
4761             } elsif (m%^<DEPRECATED/>%) {
4762                 $is_deprecated = 1;
4763             } elsif (m%^</$declaration_type>%) {
4764                 #print "Found end of declaration: $declaration_name\n";
4765                 # Check that the declaration has a name
4766                 if ($declaration_name eq "") {
4767                     print "ERROR: $declaration_type has no name $file:$.\n";
4768                 }
4770                 # If the declaration is an empty typedef struct _XXX XXX
4771                 # set the flag to indicate the struct has a typedef.
4772                 if ($declaration_type eq 'STRUCT'
4773                     && $declaration =~ m/^\s*$/) {
4774                     #print "Struct has typedef: $declaration_name\n";
4775                     $StructHasTypedef{$declaration_name} = 1;
4776                 }
4778                 # Check if the symbol is already defined.
4779                 if (defined ($Declarations{$declaration_name})
4780                     && $override == 0) {
4781                     # Function declarations take precedence.
4782                     if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
4783                         # Ignore it.
4784                     } elsif ($declaration_type eq 'FUNCTION') {
4785                         if ($is_deprecated) {
4786                             $Deprecated{$declaration_name} = "";
4787                         }
4788                         $Declarations{$declaration_name} = $declaration;
4789                         $DeclarationTypes{$declaration_name} = $declaration_type;
4790                     } elsif ($DeclarationTypes{$declaration_name}
4791                               eq $declaration_type) {
4792                         # If the existing declaration is empty, or is just a
4793                         # forward declaration of a struct, override it.
4794                         if ($declaration_type eq 'STRUCT') {
4795                             if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4796                                 if ($is_deprecated) {
4797                                     $Deprecated{$declaration_name} = "";
4798                                 }
4799                                 $Declarations{$declaration_name} = $declaration;
4800                             } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4801                                 # Ignore an empty or forward declaration.
4802                             } else {
4803                                 &LogWarning ($file, $., "Structure $declaration_name has multiple definitions.");
4804                             }
4805                         } else {
4806                             # set flag in %DeclarationConditional hash for
4807                             # multiply defined macros/typedefs.
4808                             $DeclarationConditional{$declaration_name} = 1;
4809                         }
4810                     } else {
4811                         &LogWarning ($file, $., "$declaration_name has multiple definitions.");
4812                     }
4813                 } else {
4814                     if ($is_deprecated) {
4815                         $Deprecated{$declaration_name} = "";
4816                     }
4817                     $Declarations{$declaration_name} = $declaration;
4818                     $DeclarationTypes{$declaration_name} = $declaration_type;
4819                 }
4821                 $declaration_type = "";
4822                 $is_deprecated = 0;
4823             } else {
4824                 $declaration .= $_;
4825             }
4826         }
4827     }
4828     close (INPUT);
4832 #############################################################################
4833 # Function    : ReadSignalsFile
4834 # Description : This reads in an existing file which contains information on
4835 #                all GTK signals. It creates the arrays @SignalNames and
4836 #                @SignalPrototypes containing info on the signals. The first
4837 #                line of the SignalPrototype is the return type of the signal
4838 #                handler. The remaining lines are the parameters passed to it.
4839 #                The last parameter, "gpointer user_data" is always the same
4840 #                so is not included.
4841 # Arguments   : $file - the file containing the signal handler prototype
4842 #                        information.
4843 #############################################################################
4845 sub ReadSignalsFile {
4846     my ($file) = @_;
4848     my $in_signal = 0;
4849     my $signal_object;
4850     my $signal_name;
4851     my $signal_returns;
4852     my $signal_flags;
4853     my $signal_prototype;
4855     # Reset the signal info.
4856     @SignalObjects = ();
4857     @SignalNames = ();
4858     @SignalReturns = ();
4859     @SignalFlags = ();
4860     @SignalPrototypes = ();
4862     if (! -f $file) {
4863         return;
4864     }
4865     if (!open (INPUT, $file)) {
4866         warn "Can't open $file - skipping signals\n";
4867         return;
4868     }
4869     while (<INPUT>) {
4870         if (!$in_signal) {
4871             if (m/^<SIGNAL>/) {
4872                 $in_signal = 1;
4873                 $signal_object = "";
4874                 $signal_name = "";
4875                 $signal_returns = "";
4876                 $signal_prototype = "";
4877             }
4878         } else {
4879             if (m/^<NAME>(.*)<\/NAME>/) {
4880                 $signal_name = $1;
4881                 if ($signal_name =~ m/^(.*)::(.*)$/) {
4882                     $signal_object = $1;
4883                     ($signal_name = $2) =~ s/_/-/g;
4884                     #print "Found signal: $signal_name\n";
4885                 } else {
4886                     &LogWarning ($file, $., "Invalid signal name: $signal_name.");
4887                 }
4888             } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
4889                 $signal_returns = $1;
4890             } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4891                 $signal_flags = $1;
4892             } elsif (m%^</SIGNAL>%) {
4893                 #print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
4894                 push (@SignalObjects, $signal_object);
4895                 push (@SignalNames, $signal_name);
4896                 push (@SignalReturns, $signal_returns);
4897                 push (@SignalFlags, $signal_flags);
4898                 push (@SignalPrototypes, $signal_prototype);
4899                 $in_signal = 0;
4900             } else {
4901                 $signal_prototype .= $_;
4902             }
4903         }
4904     }
4905     close (INPUT);
4909 #############################################################################
4910 # Function    : ReadTemplateFile
4911 # Description : This reads in the manually-edited documentation file
4912 #                corresponding to the file currently being created, so we can
4913 #                insert the documentation at the appropriate places.
4914 #                It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
4915 #                is a hash of arrays.
4916 #                NOTE: This function is duplicated in gtkdoc-mktmpl (but
4917 #                slightly different).
4918 # Arguments   : $docsfile - the template file to read in.
4919 #                $skip_unused_params - 1 if the unused parameters should be
4920 #                        skipped.
4921 #############################################################################
4923 sub ReadTemplateFile {
4924     my ($docsfile, $skip_unused_params) = @_;
4926     my $template = "$docsfile.sgml";
4927     if (! -f $template) {
4928         #print "File doesn't exist: $template\n";
4929         return 0;
4930     }
4932     # start with empty hashes, we merge the source comment for each file
4933     # afterwards
4934     %SymbolDocs = ();
4935     %SymbolTypes = ();
4936     %SymbolParams = ();
4938     my $current_type = "";        # Type of symbol being read.
4939     my $current_symbol = "";        # Name of symbol being read.
4940     my $symbol_doc = "";                # Description of symbol being read.
4941     my @params;                        # Parameter names and descriptions of current
4942                                 #   function/macro/function typedef.
4943     my $current_param = -1;        # Index of parameter currently being read.
4944                                 #   Note that the param array contains pairs
4945                                 #   of param name & description.
4946     my $in_unused_params = 0;        # True if we are reading in the unused params.
4947     my $in_deprecated = 0;
4948     my $in_since = 0;
4949     my $in_stability = 0;
4951     open (DOCS, "$template")
4952         || die "Can't open $template: $!";
4954     @TRACE@("reading template $template");
4956     while (<DOCS>) {
4957         if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
4958             my $type = $1;
4959             my $symbol = $2;
4960             if ($symbol eq "Title"
4961                 || $symbol eq "Short_Description"
4962                 || $symbol eq "Long_Description"
4963                 || $symbol eq "See_Also"
4964                 || $symbol eq "Stability_Level"
4965                 || $symbol eq "Include"
4966                 || $symbol eq "Image") {
4968                 $symbol = $docsfile . ":" . $symbol;
4969             }
4971             #print "Found symbol: $symbol\n";
4972             # Remember file and line for the symbol
4973             $SymbolSourceFile{$symbol} = $template;
4974             $SymbolSourceLine{$symbol} = $.;
4976             # Store previous symbol, but remove any trailing blank lines.
4977             if ($current_symbol ne "") {
4978                 $symbol_doc =~ s/\s+$//;
4979                 $SymbolTypes{$current_symbol} = $current_type;
4980                 $SymbolDocs{$current_symbol} = $symbol_doc;
4982                 # Check that the stability level is valid.
4983                 if ($StabilityLevel{$current_symbol}) {
4984                     $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4985                 }
4987                 if ($current_param >= 0) {
4988                     $SymbolParams{$current_symbol} = [ @params ];
4989                 } else {
4990                     # Delete any existing params in case we are overriding a
4991                     # previously read template.
4992                     delete $SymbolParams{$current_symbol};
4993                 }
4994             }
4995             $current_type = $type;
4996             $current_symbol = $symbol;
4997             $current_param = -1;
4998             $in_unused_params = 0;
4999             $in_deprecated = 0;
5000             $in_since = 0;
5001             $in_stability = 0;
5002             $symbol_doc = "";
5003             @params = ();
5005         } elsif (m/^<!-- # Unused Parameters # -->/) {
5006             #print "DEBUG: Found unused parameters\n";
5007             $in_unused_params = 1;
5008             next;
5010         } elsif ($in_unused_params && $skip_unused_params) {
5011             # When outputting the DocBook we skip unused parameters.
5012             #print "DEBUG: Skipping unused param: $_";
5013             next;
5015         } else {
5016             # Check if param found. Need to handle "..." and "format...".
5017             if (s/^\@([\w\.]+):\040?//) {
5018                 my $param_name = $1;
5019                 my $param_desc = $_;
5020                 # Allow variations of 'Returns'
5021                 if ($param_name =~ m/^[Rr]eturns?$/) {
5022                     $param_name = "Returns";
5023                 }
5024                 # Allow varargs variations
5025                 if ($param_name =~ m/^.*\.\.\.$/) {
5026                     $param_name = "...";
5027                 }
5029                 # strip trailing whitespaces and blank lines
5030                 s/\s+\n$/\n/m;
5031                 s/\n+$/\n/sm;
5032                 @TRACE@("Found param for symbol $current_symbol : '$param_name'= '$_'");
5034                 if ($param_name eq "Deprecated") {
5035                     $in_deprecated = 1;
5036                     $Deprecated{$current_symbol} = $_;
5037                 } elsif ($param_name eq "Since") {
5038                     $in_since = 1;
5039                     chomp;
5040                     $Since{$current_symbol} = $_;
5041                 } elsif ($param_name eq "Stability") {
5042                     $in_stability = 1;
5043                     $StabilityLevel{$current_symbol} = $_;
5044                 } else {
5045                     push (@params, $param_name);
5046                     push (@params, $param_desc);
5047                     $current_param += $PARAM_FIELD_COUNT;
5048                 }
5049             } else {
5050                 # strip trailing whitespaces and blank lines
5051                 s/\s+\n$/\n/m;
5052                 s/\n+$/\n/sm;
5054                 if (!m/^\s+$/) {
5055                     if ($in_deprecated) {
5056                         $Deprecated{$current_symbol} .= $_;
5057                     } elsif ($in_since) {
5058                         &LogWarning ($template, $., "multi-line since docs found");
5059                         #$Since{$current_symbol} .= $_;
5060                     } elsif ($in_stability) {
5061                         $StabilityLevel{$current_symbol} .= $_;
5062                     } elsif ($current_param >= 0) {
5063                         $params[$current_param] .= $_;
5064                     } else {
5065                         $symbol_doc .= $_;
5066                     }
5067                 }
5068             }
5069         }
5070     }
5072     # Remember to finish the current symbol doccs.
5073     if ($current_symbol ne "") {
5075         $symbol_doc =~ s/\s+$//;
5076         $SymbolTypes{$current_symbol} = $current_type;
5077         $SymbolDocs{$current_symbol} = $symbol_doc;
5079         # Check that the stability level is valid.
5080         if ($StabilityLevel{$current_symbol}) {
5081             $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
5082         }
5084         if ($current_param >= 0) {
5085             $SymbolParams{$current_symbol} = [ @params ];
5086         } else {
5087             # Delete any existing params in case we are overriding a
5088             # previously read template.
5089             delete $SymbolParams{$current_symbol};
5090         }
5091     }
5093     close (DOCS);
5094     return 1;
5098 #############################################################################
5099 # Function    : ReadObjectHierarchy
5100 # Description : This reads in the $MODULE-hierarchy.txt file containing all
5101 #                the GtkObject subclasses described in this module (and their
5102 #                ancestors).
5103 #                It places them in the @Objects array, and places their level
5104 #                in the object hierarchy in the @ObjectLevels array, at the
5105 #                same index. GtkObject, the root object, has a level of 1.
5107 #               FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
5108 #               as it goes along, this should be split out into a separate
5109 #               function.
5111 # Arguments   : none
5112 #############################################################################
5114 sub ReadObjectHierarchy {
5115     @Objects = ();
5116     @ObjectLevels = ();
5118     if (! -f $OBJECT_TREE_FILE) {
5119         return;
5120     }
5121     if (!open (INPUT, $OBJECT_TREE_FILE)) {
5122         warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
5123         return;
5124     }
5126     # FIXME: use $OUTPUT_FORMAT
5127     # my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.$OUTPUT_FORMAT";
5128     my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
5129     my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
5131     open (OUTPUT, ">$new_tree_index")
5132         || die "Can't create $new_tree_index: $!";
5134     if ($OUTPUT_FORMAT eq "xml") {
5135         my $tree_header = $doctype_header;
5137         $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
5138         print (OUTPUT "$tree_header");
5139     }
5140     print (OUTPUT "<screen>\n");
5142     # Only emit objects if they are supposed to be documented, or if
5143     # they have documented children. To implement this, we maintain a
5144     # stack of pending objects which will be emitted if a documented
5145     # child turns up.
5146     my @pending_objects = ();
5147     my @pending_levels = ();
5148     while (<INPUT>) {
5149         if (m/\S+/) {
5150             my $object = $&;
5151             my $level = (length($`)) / 2 + 1;
5152             my $xref = "";
5154             while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
5155                 my $pobject = pop(@pending_objects);
5156                 my $plevel = pop(@pending_levels);
5157             }
5159                push (@pending_objects, $object);
5160             push (@pending_levels, $level);
5162             if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5163                    while ($#pending_levels >= 0) {
5164                     $object = shift @pending_objects;
5165                     $level = shift @pending_levels;
5166                        $xref = &MakeXRef ($object);
5168                      print (OUTPUT ' ' x ($level * 4), "$xref\n");
5169                     push (@Objects, $object);
5170                     push (@ObjectLevels, $level);
5171                 }
5172             }
5173             #else {
5174             #    LogWarning ($OBJECT_TREE_FILE, $., "unknown type $object");
5175             #}
5176         }
5177     }
5178     print (OUTPUT "</screen>\n");
5180     close (INPUT);
5181     close (OUTPUT);
5183     &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
5185     &OutputObjectList;
5188 #############################################################################
5189 # Function    : ReadInterfaces
5190 # Description : This reads in the $MODULE.interfaces file.
5192 # Arguments   : none
5193 #############################################################################
5195 sub ReadInterfaces {
5196     %Interfaces = ();
5198     if (! -f $INTERFACES_FILE) {
5199         return;
5200     }
5201     if (!open (INPUT, $INTERFACES_FILE)) {
5202         warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
5203         return;
5204     }
5206     while (<INPUT>) {
5207        chomp;
5208        my ($object, @ifaces) = split;
5209        if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5210            my @knownIfaces = ();
5212            # filter out private interfaces, but leave foreign interfaces
5213            foreach my $iface (@ifaces) {
5214                if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
5215                    push (@knownIfaces, $iface);
5216                }
5217              }
5219            $Interfaces{$object} = join(' ', @knownIfaces);
5220        }
5221     }
5222     close (INPUT);
5225 #############################################################################
5226 # Function    : ReadPrerequisites
5227 # Description : This reads in the $MODULE.prerequisites file.
5229 # Arguments   : none
5230 #############################################################################
5232 sub ReadPrerequisites {
5233     %Prerequisites = ();
5235     if (! -f $PREREQUISITES_FILE) {
5236         return;
5237     }
5238     if (!open (INPUT, $PREREQUISITES_FILE)) {
5239         warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
5240         return;
5241     }
5243     while (<INPUT>) {
5244        chomp;
5245        my ($iface, @prereqs) = split;
5246        if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
5247            my @knownPrereqs = ();
5249            # filter out private prerequisites, but leave foreign prerequisites
5250            foreach my $prereq (@prereqs) {
5251                if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
5252                   push (@knownPrereqs, $prereq);
5253                }
5254            }
5256            $Prerequisites{$iface} = join(' ', @knownPrereqs);
5257        }
5258     }
5259     close (INPUT);
5262 #############################################################################
5263 # Function    : ReadArgsFile
5264 # Description : This reads in an existing file which contains information on
5265 #                all GTK args. It creates the arrays @ArgObjects, @ArgNames,
5266 #                @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
5267 #               on the args.
5268 # Arguments   : $file - the file containing the arg information.
5269 #############################################################################
5271 sub ReadArgsFile {
5272     my ($file) = @_;
5274     my $in_arg = 0;
5275     my $arg_object;
5276     my $arg_name;
5277     my $arg_type;
5278     my $arg_flags;
5279     my $arg_nick;
5280     my $arg_blurb;
5281     my $arg_default;
5282     my $arg_range;
5284     # Reset the args info.
5285     @ArgObjects = ();
5286     @ArgNames = ();
5287     @ArgTypes = ();
5288     @ArgFlags = ();
5289     @ArgNicks = ();
5290     @ArgBlurbs = ();
5291     @ArgDefaults = ();
5292     @ArgRanges = ();
5294     if (! -f $file) {
5295         return;
5296     }
5297     if (!open (INPUT, $file)) {
5298         warn "Can't open $file - skipping args\n";
5299         return;
5300     }
5301     while (<INPUT>) {
5302         if (!$in_arg) {
5303             if (m/^<ARG>/) {
5304                 $in_arg = 1;
5305                 $arg_object = "";
5306                 $arg_name = "";
5307                 $arg_type = "";
5308                 $arg_flags = "";
5309                 $arg_nick = "";
5310                 $arg_blurb = "";
5311                 $arg_default = "";
5312                 $arg_range = "";
5313             }
5314         } else {
5315             if (m/^<NAME>(.*)<\/NAME>/) {
5316                 $arg_name = $1;
5317                 if ($arg_name =~ m/^(.*)::(.*)$/) {
5318                     $arg_object = $1;
5319                     ($arg_name = $2) =~ s/_/-/g;
5320                     #print "Found arg: $arg_name\n";
5321                 } else {
5322                     &LogWarning ($file, $., "Invalid argument name: $arg_name");
5323                 }
5324             } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
5325                 $arg_type = $1;
5326             } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
5327                 $arg_range = $1;
5328             } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
5329                 $arg_flags = $1;
5330             } elsif (m/^<NICK>(.*)<\/NICK>/) {
5331                 $arg_nick = $1;
5332             } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
5333                 $arg_blurb = $1;
5334                 if ($arg_blurb eq "(null)") {
5335                   $arg_blurb = "";
5336                   &LogWarning ($file, $., "Property ${arg_object}:${arg_name} has no documentation.");
5337                 }
5338             } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
5339                 $arg_default = $1;
5340             } elsif (m%^</ARG>%) {
5341                 #print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
5342                 push (@ArgObjects, $arg_object);
5343                 push (@ArgNames, $arg_name);
5344                 push (@ArgTypes, $arg_type);
5345                 push (@ArgRanges, $arg_range);
5346                 push (@ArgFlags, $arg_flags);
5347                 push (@ArgNicks, $arg_nick);
5348                 push (@ArgBlurbs, $arg_blurb);
5349                 push (@ArgDefaults, $arg_default);
5350                 $in_arg = 0;
5351             }
5352         }
5353     }
5354     close (INPUT);
5358 #############################################################################
5359 # Function    : CheckIsObject
5360 # Description : Returns 1 if the given name is a GObject or a subclass.
5361 #                It uses the global @Objects array.
5362 #                Note that the @Objects array only contains classes in the
5363 #                current module and their ancestors - not all GObject classes.
5364 # Arguments   : $name - the name to check.
5365 #############################################################################
5367 sub CheckIsObject {
5368     my ($name) = @_;
5370     my $object;
5371     foreach $object (@Objects) {
5372         if ($object eq $name) {
5373             return 1;
5374         }
5375     }
5376     return 0;
5380 #############################################################################
5381 # Function    : MakeReturnField
5382 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
5383 # Arguments   : $str - the string to pad.
5384 #############################################################################
5386 sub MakeReturnField {
5387     my ($str) = @_;
5389     return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));
5392 #############################################################################
5393 # Function    : GetSymbolSourceFile
5394 # Description : Get the filename where the symbol docs where taken from.
5395 # Arguments   : $symbol - the symbol name
5396 #############################################################################
5398 sub GetSymbolSourceFile {
5399     my ($symbol) = @_;
5401     if (defined($SourceSymbolSourceFile{$symbol})) {
5402         return $SourceSymbolSourceFile{$symbol};
5403     } elsif (defined($SymbolSourceFile{$symbol})) {
5404         return $SymbolSourceFile{$symbol};
5405     } else {
5406         return "";
5407     }
5410 #############################################################################
5411 # Function    : GetSymbolSourceLine
5412 # Description : Get the file line where the symbol docs where taken from.
5413 # Arguments   : $symbol - the symbol name
5414 #############################################################################
5416 sub GetSymbolSourceLine {
5417     my ($symbol) = @_;
5419     if (defined($SourceSymbolSourceLine{$symbol})) {
5420         return $SourceSymbolSourceLine{$symbol};
5421     } elsif (defined($SymbolSourceLine{$symbol})) {
5422         return $SymbolSourceLine{$symbol};
5423     } else {
5424         return 0;
5425     }