mkdb: fix issues from wrong rebase conflic handling
[gtk-doc.git] / gtkdoc-mkdb.in
blob31f51d63df9fa16efd124dda4d2315b6f74d3f89
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 ($field_name eq "Varargs") {
2033             $field_name = "...";
2034         }
2036         if ($i == 1) {
2037             $synop .= "$field_name";
2038             $desc  .= "$field_name";
2039         } else {
2040             $synop .= ",\n"
2041                 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2042                 . " $field_name";
2043             $desc  .= ",\n"
2044                 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2045                 . " $field_name";
2046         }
2048     }
2050     $synop .= ");\n";
2051     $desc  .= ");</programlisting>\n";
2053     $desc .= &MakeDeprecationNote($symbol);
2055     my $parameters = &OutputParamDescriptions ("FUNCTION", $symbol, @fields);
2056     my $parameters_output = 0;
2058     if (defined ($SymbolDocs{$symbol})) {
2059         my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
2061         # Try to insert the parameter table at the author's desired position.
2062         # Otherwise we need to tag it onto the end.
2063         # FIXME: document that in the user manual and make it useable for other
2064         # types too
2065         if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
2066           $parameters_output = 1;
2067         }
2068         $desc .= $symbol_docs;
2069     }
2071     if ($parameters_output == 0) {
2072         $desc .= $parameters;
2073     }
2075     $desc .= OutputSymbolTraits ($symbol);
2076     $desc .= "</refsect2>\n";
2077     return ($synop, $desc);
2081 #############################################################################
2082 # Function    : OutputParamDescriptions
2083 # Description : Returns the DocBook output describing the parameters of a
2084 #                function, macro or signal handler.
2085 # Arguments   : $symbol_type - 'FUNCTION', 'MACRO' or 'SIGNAL'. Signal
2086 #                  handlers have an implicit user_data parameter last.
2087 #                $symbol - the name of the function/macro being described.
2088 #               @fields - parsed fields from the declaration, used to determine
2089 #                  undocumented/unused entries
2090 #############################################################################
2092 sub OutputParamDescriptions {
2093     my ($symbol_type, $symbol, @fields) = @_;
2094     my $output = "";
2095     my $params = $SymbolParams{$symbol};
2096     my $num_params = 0;
2097     my %field_descrs = ();
2099     if (@fields) {
2100         %field_descrs = @fields;
2101         delete $field_descrs{"void"};
2102         delete $field_descrs{"Returns"};
2103     }
2105     if (defined $params) {
2106         my $returns = "";
2107         my $params_desc = "";
2108         my $missing_parameters = "";
2109         my $unused_parameters = "";
2110         my $j;
2112         for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
2113             my $param_name = $$params[$j];
2114             my $param_desc = $$params[$j + 1];
2115             my $param_annotations = "";
2117             ($param_desc,$param_annotations) = & ExpandAnnotation($symbol, $param_desc);
2118             $param_desc = &ExpandAbbreviations($symbol, $param_desc);
2119             $param_desc .= $param_annotations;
2120             # trim
2121             $param_desc =~ s/^(\s|\n)+//msg;
2122             $param_desc =~ s/(\s|\n)+$//msg;
2123             if ($param_name eq "Returns") {
2124                 $returns = "$param_desc";
2125             } elsif ($param_name eq "void") {
2126                 #print "!!!! void in params for $symbol?\n";
2127             } else {
2128                 if ($param_name eq "Varargs") {
2129                     $param_name = "...";
2130                 }
2131                 if (@fields) {
2132                     if (!defined $field_descrs{$param_name}) {
2133                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2134                             "Parameter description for $symbol"."::"."$param_name is not used from source code comment block.");
2135                         if ($unused_parameters ne "") {
2136                           $unused_parameters .= ", ".$param_name;
2137                         } else {
2138                            $unused_parameters = $param_name;
2139                         }
2140                     } else {
2141                         delete $field_descrs{$param_name};
2142                     }
2143                 }
2144                 if($param_desc ne "") {
2145                     $params_desc .= "<varlistentry><term><parameter>$param_name</parameter>&#160;:</term>\n<listitem><simpara>$param_desc</simpara></listitem></varlistentry>\n";
2146                     $num_params++;
2147                 }
2148             }
2149         }
2150         foreach my $param_name (keys %field_descrs) {
2151             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2152                 "Parameter description for $symbol"."::"."$param_name is missing in source code comment block.");
2153             if ($missing_parameters ne "") {
2154               $missing_parameters .= ", ".$param_name;
2155             } else {
2156                $missing_parameters = $param_name;
2157             }
2158         }
2160         # Signals have an implicit user_data parameter which we describe.
2161         if ($symbol_type eq "SIGNAL") {
2162             $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";
2163         }
2165         # Start a table if we need one.
2166         if ($params_desc || $returns) {
2167             $output .= "<variablelist role=\"params\">\n";
2168             if ($params_desc ne "") {
2169                 #$output .= "<varlistentry><term>Parameters:</term><listitem></listitem></varlistentry>\n";
2170                 $output .= $params_desc;
2171             }
2173             # Output the returns info last
2174             if ($returns) {
2175                 $output .= "<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara>$returns</simpara></listitem></varlistentry>\n";
2176             }
2178             # Finish the table.
2179             $output .= "</variablelist>";
2180         }
2182         # remember missing/unused parameters (needed in tmpl-free build)
2183         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
2184             $AllIncompleteSymbols{$symbol}=$missing_parameters;
2185         }
2186         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
2187             $AllUnusedSymbols{$symbol}=$unused_parameters;
2188         }
2189     }
2190     if (($num_params == 0) && @fields && (scalar(keys(%field_descrs)) > 0)) {
2191         if (! exists ($AllIncompleteSymbols{$symbol})) {
2192             $AllIncompleteSymbols{$symbol}="<parameters>";
2193         }
2194     }
2196     return $output;
2200 #############################################################################
2201 # Function    : ParseStabilityLevel
2202 # Description : Parses a stability level and outputs a warning if it isn't
2203 #               valid.
2204 # Arguments   : $stability - the stability text.
2205 #                $file, $line - context for error message
2206 #                $message - description of where the level is from, to use in
2207 #               any error message.
2208 # Returns     : The parsed stability level string.
2209 #############################################################################
2211 sub ParseStabilityLevel {
2212     my ($stability, $file, $line, $message) = @_;
2214     $stability =~ s/^\s*//;
2215     $stability =~ s/\s*$//;
2216     if ($stability =~ m/^stable$/i) {
2217         $stability = "Stable";
2218     } elsif ($stability =~ m/^unstable$/i) {
2219         $stability = "Unstable";
2220     } elsif ($stability =~ m/^private$/i) {
2221         $stability = "Private";
2222     } else {
2223         &LogWarning ($file, $line, "$message is $stability.".
2224             "It should be one of these: Stable, Unstable, or Private.");
2225     }
2226     return $stability;
2230 #############################################################################
2231 # Function    : OutputSGMLFile
2232 # Description : Outputs the final DocBook file for one section.
2233 # Arguments   : $file - the name of the file.
2234 #               $title - the title from the $MODULE-sections.txt file, which
2235 #                 will be overridden by the title in the template file.
2236 #               $section_id - the SGML id to use for the toplevel tag.
2237 #               $includes - comma-separates list of include files added at top of
2238 #                 synopsis, with '<' '>' around them (if not already enclosed in "").
2239 #               $synopsis - reference to the DocBook for the Synopsis part.
2240 #               $details - reference to the DocBook for the Details part.
2241 #               $signal_synop - reference to the DocBook for the Signal Synopsis part
2242 #               $signal_desc - reference to the DocBook for the Signal Description part
2243 #               $args_synop - reference to the DocBook for the Arg Synopsis part
2244 #               $args_desc - reference to the DocBook for the Arg Description part
2245 #               $hierarchy - reference to the DocBook for the Object Hierarchy part
2246 #               $interfaces - reference to the DocBook for the Interfaces part
2247 #               $implementations - reference to the DocBook for the Known Implementations part
2248 #               $prerequisites - reference to the DocBook for the Prerequisites part
2249 #               $derived - reference to the DocBook for the Derived Interfaces part
2250 #               $file_objects - reference to an array of objects in this file
2251 #############################################################################
2253 sub OutputSGMLFile {
2254     my ($file, $title, $section_id, $includes, $synopsis, $details, $signals_synop, $signals_desc, $args_synop, $args_desc, $hierarchy, $interfaces, $implementations, $prerequisites, $derived, $file_objects) = @_;
2256     #print "Output sgml for file $file with title '$title'\n";
2258     # The edited title overrides the one from the sections file.
2259     my $new_title = $SymbolDocs{"$TMPL_DIR/$file:Title"};
2260     if (defined ($new_title) && $new_title !~ m/^\s*$/) {
2261         $title = $new_title;
2262         #print "Found title: $title\n";
2263     }
2264     my $short_desc = $SymbolDocs{"$TMPL_DIR/$file:Short_Description"};
2265     if (!defined ($short_desc) || $short_desc =~ m/^\s*$/) {
2266         $short_desc = "";
2267     } else {
2268         $short_desc = &ExpandAbbreviations("$title:Short_description",
2269                                            $short_desc);
2270         #print "Found short_desc: $short_desc";
2271     }
2272     my $long_desc = $SymbolDocs{"$TMPL_DIR/$file:Long_Description"};
2273     if (!defined ($long_desc) || $long_desc =~ m/^\s*$/) {
2274         $long_desc = "";
2275     } else {
2276         $long_desc = &ExpandAbbreviations("$title:Long_description",
2277                                           $long_desc);
2278         #print "Found long_desc: $long_desc";
2279     }
2280     my $see_also = $SymbolDocs{"$TMPL_DIR/$file:See_Also"};
2281     if (!defined ($see_also) || $see_also =~ m%^\s*(<para>)?\s*(</para>)?\s*$%) {
2282         $see_also = "";
2283     } else {
2284         $see_also = &ExpandAbbreviations("$title:See_Also", $see_also);
2285         #print "Found see_also: $see_also";
2286     }
2287     if ($see_also) {
2288         $see_also = "<refsect1 id=\"$section_id.see-also\">\n<title>See Also</title>\n$see_also\n</refsect1>\n";
2289     }
2290     my $stability = $SymbolDocs{"$TMPL_DIR/$file:Stability_Level"};
2291     if (!defined ($stability) || $stability =~ m/^\s*$/) {
2292         $stability = "";
2293     } else {
2294         $stability = &ParseStabilityLevel($stability, $file, $., "Section stability level");
2295         #print "Found stability: $stability";
2296     }
2297     if ($stability) {
2298         $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$stability, unless otherwise indicated\n</refsect1>\n";
2299     } elsif ($DEFAULT_STABILITY) {
2300         $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$DEFAULT_STABILITY, unless otherwise indicated\n</refsect1>\n";
2301     }
2303     my $image = $SymbolDocs{"$TMPL_DIR/$file:Image"};
2304     if (!defined ($image) || $image =~ m/^\s*$/) {
2305       $image = "";
2306     } else {
2307       $image =~ s/^\s*//;
2308       $image =~ s/\s*$//;
2310       my $format;
2312       if ($image =~ /jpe?g$/i) {
2313         $format = "format='JPEG'";
2314       } elsif ($image =~ /png$/i) {
2315         $format = "format='PNG'";
2316       } elsif ($image =~ /svg$/i) {
2317         $format = "format='SVG'";
2318       } else {
2319         $format = "";
2320       }
2322       $image = "  <inlinegraphic fileref='$image' $format/>\n"
2323     }
2325     my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
2326         gmtime (time);
2327     my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
2328     $year += 1900;
2330     my $include_output = "";
2331     my $include;
2332     foreach $include (split (/,/, $includes)) {
2333         if ($include =~ m/^\".+\"$/) {
2334             $include_output .= "#include ${include}\n";
2335         }
2336         else {
2337             $include =~ s/^\s+|\s+$//gs;
2338             $include_output .= "#include &lt;${include}&gt;\n";
2339         }
2340     }
2341     if ($include_output ne '') {
2342         $include_output = "\n$include_output\n";
2343     }
2345     my $extralinks = OutputSectionExtraLinks($title,"Section:$file");
2347     my $old_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT";
2348     my $new_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT.new";
2350     open (OUTPUT, ">$new_sgml_file")
2351         || die "Can't create $new_sgml_file: $!";
2353     my $object_anchors = "";
2354     foreach my $object (@$file_objects) {
2355         next if ($object eq $section_id);
2356         my $id = CreateValidSGMLID($object);
2357         #print "Debug: Adding anchor for $object\n";
2358         $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
2359     }
2361     # We used to output this, but is messes up our UpdateFileIfChanged code
2362     # since it changes every day (and it is only used in the man pages):
2363     # "<refentry id="$section_id" revision="$mday $month $year">"
2365     if ($OUTPUT_FORMAT eq "xml") {
2366         print OUTPUT $doctype_header;
2367     }
2369     print OUTPUT <<EOF;
2370 <refentry id="$section_id">
2371 <refmeta>
2372 <refentrytitle role="top_of_page" id="$section_id.top_of_page">$title</refentrytitle>
2373 <manvolnum>3</manvolnum>
2374 <refmiscinfo>
2375   \U$MODULE\E Library
2376 $image</refmiscinfo>
2377 </refmeta>
2378 <refnamediv>
2379 <refname>$title</refname>
2380 <refpurpose>$short_desc</refpurpose>
2381 </refnamediv>
2382 $stability
2383 <refsynopsisdiv id="$section_id.synopsis" role="synopsis">
2384 <title role="synopsis.title">Synopsis</title>
2385 $object_anchors
2386 <synopsis>$include_output$${synopsis}</synopsis>
2387 </refsynopsisdiv>
2388 $$hierarchy$$prerequisites$$derived$$interfaces$$implementations$$args_synop$$signals_synop
2389 <refsect1 id="$section_id.description" role="desc">
2390 <title role="desc.title">Description</title>
2391 $extralinks$long_desc
2392 </refsect1>
2393 <refsect1 id="$section_id.details" role="details">
2394 <title role="details.title">Details</title>
2395 $$details
2396 </refsect1>
2397 $$args_desc$$signals_desc$see_also
2398 </refentry>
2400     close (OUTPUT);
2402     return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2406 #############################################################################
2407 # Function    : OutputExtraFile
2408 # Description : Copies an "extra" DocBook file into the output directory,
2409 #               expanding abbreviations
2410 # Arguments   : $file - the source file.
2411 #############################################################################
2412 sub OutputExtraFile {
2413     my ($file) = @_;
2415     my $basename;
2417     ($basename = $file) =~ s!^.*/!!;
2419     my $old_sgml_file = "$SGML_OUTPUT_DIR/$basename";
2420     my $new_sgml_file = "$SGML_OUTPUT_DIR/$basename.new";
2422     my $contents;
2424     open(EXTRA_FILE, "<$file") || die "Can't open $file";
2426     {
2427         local $/;
2428         $contents = <EXTRA_FILE>;
2429     }
2431     open (OUTPUT, ">$new_sgml_file")
2432         || die "Can't create $new_sgml_file: $!";
2434     print OUTPUT &ExpandAbbreviations ("$basename file", $contents);
2435     close (OUTPUT);
2437     return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2439 #############################################################################
2440 # Function    : OutputBook
2441 # Description : Outputs the SGML entities that need to be included into the
2442 #                main SGML file for the module.
2443 # Arguments   : $book_top - the declarations of the entities, which are added
2444 #                  at the top of the main SGML file.
2445 #                $book_bottom - the references to the entities, which are
2446 #                  added in the main SGML file at the desired position.
2447 #############################################################################
2449 sub OutputBook {
2450     my ($book_top, $book_bottom) = @_;
2452     my $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top";
2453     my $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top.new";
2455     open (OUTPUT, ">$new_file")
2456         || die "Can't create $new_file: $!";
2457     print OUTPUT $book_top;
2458     close (OUTPUT);
2460     &UpdateFileIfChanged ($old_file, $new_file, 0);
2463     $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom";
2464     $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom.new";
2466     open (OUTPUT, ">$new_file")
2467         || die "Can't create $new_file: $!";
2468     print OUTPUT $book_bottom;
2469     close (OUTPUT);
2471     &UpdateFileIfChanged ($old_file, $new_file, 0);
2474     # If the main SGML/XML file hasn't been created yet, we create it here.
2475     # The user can tweak it later.
2476     if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
2477       open (OUTPUT, ">$MAIN_SGML_FILE")
2478         || die "Can't create $MAIN_SGML_FILE: $!";
2480       if ($OUTPUT_FORMAT eq "xml") {
2481           print OUTPUT <<EOF;
2482 <?xml version="1.0"?>
2483 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
2484                "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
2486   <!ENTITY % local.common.attrib "xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'">
2488 <book id="index">
2490       } else {
2491         print OUTPUT <<EOF;
2492 <!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
2493 $book_top
2495 <book id="index">
2497       }
2499 print OUTPUT <<EOF;
2500   <bookinfo>
2501     <title>$MODULE Reference Manual</title>
2502     <releaseinfo>
2503       for $MODULE [VERSION].
2504       The latest version of this documentation can be found on-line at
2505       <ulink role="online-location" url="http://[SERVER]/$MODULE/index.html">http://[SERVER]/$MODULE/</ulink>.
2506     </releaseinfo>
2507   </bookinfo>
2509   <chapter>
2510     <title>[Insert title here]</title>
2511     $book_bottom
2512   </chapter>
2514   if (-e $OBJECT_TREE_FILE) {
2515     print OUTPUT <<EOF;
2516   <chapter id="object-tree">
2517     <title>Object Hierarchy</title>
2518      <xi:include href="xml/tree_index.sgml"/>
2519   </chapter>
2521   }
2523 print OUTPUT <<EOF;
2524   <index id="api-index-full">
2525     <title>API Index</title>
2526     <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
2527   </index>
2528   <index id="deprecated-api-index" role="deprecated">
2529     <title>Index of deprecated API</title>
2530     <xi:include href="xml/api-index-deprecated.xml"><xi:fallback /></xi:include>
2531   </index>
2533   <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
2534 </book>
2537       close (OUTPUT);
2538     }
2542 #############################################################################
2543 # Function    : CreateValidSGML
2544 # Description : This turns any chars which are used in SGML into entities,
2545 #                e.g. '<' into '&lt;'
2546 # Arguments   : $text - the text to turn into proper SGML.
2547 #############################################################################
2549 sub CreateValidSGML {
2550     my ($text) = @_;
2551     $text =~ s/&/&amp;/g;        # Do this first, or the others get messed up.
2552     $text =~ s/</&lt;/g;
2553     $text =~ s/>/&gt;/g;
2554     # browers render single tabs inconsistently
2555     $text =~ s/([^\s])\t([^\s])/$1&#160;$2/g;
2556     return $text;
2559 #############################################################################
2560 # Function    : ConvertSGMLChars
2561 # Description : This is used for text in source code comment blocks, to turn
2562 #               chars which are used in SGML into entities, e.g. '<' into
2563 #               '&lt;'. Depending on $INLINE_MARKUP_MODE, this is done
2564 #               unconditionally or only if the character doesn't seem to be
2565 #               part of an SGML construct (tag or entity reference).
2566 # Arguments   : $text - the text to turn into proper SGML.
2567 #############################################################################
2569 sub ConvertSGMLChars {
2570     my ($symbol, $text) = @_;
2572     if ($INLINE_MARKUP_MODE) {
2573         # For the XML/SGML mode only convert to entities outside CDATA sections.
2574         return &ModifyXMLElements ($text, $symbol,
2575                                    "<!\\[CDATA\\[|<programlisting[^>]*>",
2576                                    \&ConvertSGMLCharsEndTag,
2577                                    \&ConvertSGMLCharsCallback);
2578     } else {
2579         # For the simple non-sgml mode, convert to entities everywhere.
2580         $text =~ s/&/&amp;/g;        # Do this first, or the others get messed up.
2581         $text =~ s/</&lt;/g;
2582         $text =~ s/>/&gt;/g;
2583         return $text;
2584     }
2588 sub ConvertSGMLCharsEndTag {
2589   if ($_[0] eq "<!\[CDATA\[") {
2590     return "]]>";
2591   } else {
2592     return "</programlisting>";
2593   }
2596 sub ConvertSGMLCharsCallback {
2597   my ($text, $symbol, $tag) = @_;
2599   if ($tag =~ m/^<programlisting/) {
2600     # We can handle <programlisting> specially here.
2601     return &ModifyXMLElements ($text, $symbol,
2602                                "<!\\[CDATA\\[",
2603                                \&ConvertSGMLCharsEndTag,
2604                                \&ConvertSGMLCharsCallback2);
2605   } elsif ($tag eq "") {
2606     # If we're not in CDATA convert to entities.
2607     $text =~ s/&(?![a-zA-Z#]+;)/&amp;/g;        # Do this first, or the others get messed up.
2608     $text =~ s/<(?![a-zA-Z\/!])/&lt;/g;
2609     $text =~ s/(?<![a-zA-Z0-9"'\/-])>/&gt;/g;
2611     # Handle "#include <xxxxx>"
2612     $text =~ s/#include(\s+)<([^>]+)>/#include$1&lt;$2&gt;/g;
2613   }
2615   return $text;
2618 sub ConvertSGMLCharsCallback2 {
2619   my ($text, $symbol, $tag) = @_;
2621   # If we're not in CDATA convert to entities.
2622   # We could handle <programlisting> differently, though I'm not sure it helps.
2623   if ($tag eq "") {
2624     # replace only if its not a tag
2625     $text =~ s/&(?![a-zA-Z#]+;)/&amp;/g;        # Do this first, or the others get messed up.
2626     $text =~ s/<(?![a-zA-Z\/!])/&lt;/g;
2627     $text =~ s/(?<![a-zA-Z0-9"'\/-])>/&gt;/g;
2629     # Handle "#include <xxxxx>"
2630     $text =~ s/#include(\s+)<([^>]+)>/#include$1&lt;$2&gt;/g;
2631   }
2633   return $text;
2636 #############################################################################
2637 # Function    : ExpandAnnotation
2638 # Description : This turns annotations into acronym tags.
2639 # Arguments   : $symbol - the symbol being documented, for error messages.
2640 #                $text - the text to expand.
2641 #############################################################################
2642 sub ExpandAnnotation {
2643     my ($symbol, $param_desc) = @_;
2644     my $param_annotations = "";
2646     # look for annotations at the start of the comment part
2647     if ($param_desc =~ m%^\s*\((.*?)\):%) {
2648         my @annotations;
2649         my $annotation;
2650         $param_desc = $';
2652         @annotations = split(/\)\s*\(/,$1);
2653         foreach $annotation (@annotations) {
2654             # need to search for the longest key-match in %AnnotationDefinition
2655             my $match_length=0;
2656             my $match_annotation="";
2657             my $annotationdef;
2658             foreach $annotationdef (keys %AnnotationDefinition) {
2659                 if ($annotation =~ m/^$annotationdef/) {
2660                     if (length($annotationdef)>$match_length) {
2661                         $match_length=length($annotationdef);
2662                         $match_annotation=$annotationdef;
2663                     }
2664                 }
2665             }
2666             my $annotation_extra = "";
2667             if ($match_annotation ne "") {
2668                 if ($annotation =~ m%$match_annotation\s+(.*)%) {
2669                     $annotation_extra = " $1";
2670                 }
2671                 $AnnotationsUsed{$match_annotation} = 1;
2672                 $param_annotations .= "[<acronym>$match_annotation</acronym>$annotation_extra]";
2673             }
2674             else {
2675                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2676                     "unknown annotation \"$annotation\" in documentation for $symbol.");
2677                 $param_annotations .= "[$annotation]";
2678             }
2679         }
2680         chomp($param_desc);
2681         $param_desc =~ m/^(.*?)\.*\s*$/s;
2682         $param_desc = "$1. ";
2683     }
2684     if ($param_annotations ne "") {
2685         $param_annotations = "<emphasis role=\"annotation\">$param_annotations</emphasis>";
2686     }
2687     return ($param_desc, $param_annotations);
2690 #############################################################################
2691 # Function    : ExpandAbbreviations
2692 # Description : This turns the abbreviations function(), macro(), @param,
2693 #                %constant, and #symbol into appropriate DocBook markup.
2694 #               CDATA sections and <programlisting> parts are skipped.
2695 # Arguments   : $symbol - the symbol being documented, for error messages.
2696 #                $text - the text to expand.
2697 #############################################################################
2699 sub ExpandAbbreviations {
2700   my ($symbol, $text) = @_;
2702   # Convert "|[" and "]|" into the start and end of program listing examples.
2703   # FIXME: we like to have a way to specify parameters e.g. language="c"
2704   $text =~ s%\|\[%<informalexample><programlisting>%g;
2705   $text =~ s%\]\|%</programlisting></informalexample>%g;
2706   # TODO: check for a xml comment after |[ and pick the language attribute from
2707   # that
2709   # keep CDATA unmodified, preserve ulink tags (ideally we preseve all tags
2710   # as such)
2711   return &ModifyXMLElements ($text, $symbol,
2712                              "<!\\[CDATA\\[|<ulink[^>]*>|<programlisting[^>]*>|<!DOCTYPE",
2713                              \&ExpandAbbreviationsEndTag,
2714                              \&ExpandAbbreviationsCallback);
2718 # Returns the end tag corresponding to the given start tag.
2719 sub ExpandAbbreviationsEndTag {
2720   my ($start_tag) = @_;
2722   if ($start_tag eq "<!\[CDATA\[") {
2723     return "]]>";
2724   } elsif ($start_tag eq "<!DOCTYPE") {
2725     return "]>";
2726   } elsif ($start_tag =~ m/<(\w+)/) {
2727     return "</$1>";
2728   }
2731 # Called inside or outside each CDATA or <programlisting> section.
2732 sub ExpandAbbreviationsCallback {
2733   my ($text, $symbol, $tag) = @_;
2735   if ($tag =~ m/^<programlisting/) {
2736     # Handle any embedded CDATA sections.
2737     return &ModifyXMLElements ($text, $symbol,
2738                                "<!\\[CDATA\\[",
2739                                \&ExpandAbbreviationsEndTag,
2740                                \&ExpandAbbreviationsCallback2);
2741   } elsif ($tag eq "") {
2742     # We are outside any CDATA or <programlisting> sections, so we expand
2743     # any gtk-doc abbreviations.
2745     # Convert '@param()'
2746     # FIXME: we could make those also links ($symbol.$2), but that would be less
2747     # useful as the link target is a few lines up or down
2748     $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)\s*\(\)/$1<parameter>$2()<\/parameter>/g;
2750     # Convert 'function()' or 'macro()'.
2751     # if there is abc_*_def() we don't want to make a link to _def()
2752     # FIXME: also handle abc(def(....)) : but that would need to be done recursively :/
2753     $text =~ s/([^\*.\w])(\w+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2754     # handle #Object.func()
2755     $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2757     # Convert '@param', but not '\@param'.
2758     $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)/$1<parameter>$2<\/parameter>/g;
2759     $text =~ s/\\\@/\@/g;
2761     # Convert '%constant', but not '\%constant'.
2762     # Also allow negative numbers, e.g. %-1.
2763     $text =~ s/(\A|[^\\])\%(-?\w+)/$1.&MakeXRef($2, &tagify($2, "literal"));/eg;
2764     $text =~ s/\\\%/\%/g;
2766     # Convert '#symbol', but not '\#symbol'.
2767     $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)/$1.&MakeHashXRef($2, "type");/eg;
2768     $text =~ s/\\#/#/g;
2770     # Expand urls
2771     # FIXME: should we skip urls that are already tagged? (e.g. <literal>http://...</literal>)
2772     # this is apparently also called for markup and not just for plain text
2773     # disable for now.
2774     #$text =~ s%(http|https|ftp)://(.*?)((?:\s|,|\)|\]|\<|\.\s))%<ulink url="$1://$2">$2</ulink>$3%g;
2776     # TODO: optionally check all words from $text against internal symbols and
2777     # warn if those could be xreffed, but miss a %,# or ()
2778   }
2780   return $text;
2783 # This is called inside a <programlisting>
2784 sub ExpandAbbreviationsCallback2 {
2785   my ($text, $symbol, $tag) = @_;
2787   if ($tag eq "") {
2788     # We are inside a <programlisting> but outside any CDATA sections,
2789     # so we expand any gtk-doc abbreviations.
2790     # FIXME: why is this different from &ExpandAbbreviationsCallback(),
2791     #        why not just call it
2792     $text =~ s/#(\w+)/&MakeHashXRef($1, "");/eg;
2793   }
2795   return $text;
2798 sub MakeHashXRef {
2799     my ($symbol, $tag) = @_;;
2800     my $text = $symbol;
2802     # Check for things like '#include', '#define', and skip them.
2803     if ($PreProcessorDirectives{$symbol}) {
2804       return "#$symbol";
2805     }
2807     # Get rid of any special '-struct' suffix.
2808     $text =~ s/-struct$//;
2810     # If the symbol is in the form "Object::signal", then change the symbol to
2811     # "Object-signal" and use "signal" as the text.
2812     if ($symbol =~ s/::/-/) {
2813       $text = "\"$'\"";
2814     }
2816     # If the symbol is in the form "Object:property", then change the symbol to
2817     # "Object--property" and use "property" as the text.
2818     if ($symbol =~ s/:/--/) {
2819       $text = "\"$'\"";
2820     }
2822     if ($tag ne "") {
2823       $text = tagify ($text, $tag);
2824     }
2826     return &MakeXRef($symbol, $text);
2830 #############################################################################
2831 # Function    : ModifyXMLElements
2832 # Description : Looks for given XML element tags within the text, and calls
2833 #               the callback on pieces of text inside & outside those elements.
2834 #               Used for special handling of text inside things like CDATA
2835 #               and <programlisting>.
2836 # Arguments   : $text - the text.
2837 #               $symbol - the symbol currently being documented (only used for
2838 #                      error messages).
2839 #               $start_tag_regexp - the regular expression to match start tags.
2840 #                      e.g. "<!\\[CDATA\\[|<programlisting[^>]*>" to match
2841 #                      CDATA sections or programlisting elements.
2842 #               $end_tag_func - function which is passed the matched start tag
2843 #                      and should return the appropriate end tag string.
2844 #               $callback - callback called with each part of the text. It is
2845 #                      called with a piece of text, the symbol being
2846 #                      documented, and the matched start tag or "" if the text
2847 #                      is outside the XML elements being matched.
2848 #############################################################################
2849 sub ModifyXMLElements {
2850     my ($text, $symbol, $start_tag_regexp, $end_tag_func, $callback) = @_;
2851     my ($before_tag, $start_tag, $end_tag_regexp, $end_tag);
2852     my $result = "";
2854     while ($text =~ m/$start_tag_regexp/s) {
2855       $before_tag = $`; # Prematch for last successful match string
2856       $start_tag = $&;  # Last successful match
2857       $text = $';       # Postmatch for last successful match string
2859       $result .= &$callback ($before_tag, $symbol, "");
2860       $result .= $start_tag;
2862       # get the mathing end-tag for current tag
2863       $end_tag_regexp = &$end_tag_func ($start_tag);
2865       if ($text =~ m/$end_tag_regexp/s) {
2866         $before_tag = $`;
2867         $end_tag = $&;
2868         $text = $';
2870         $result .= &$callback ($before_tag, $symbol, $start_tag);
2871         $result .= $end_tag;
2872       } else {
2873         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2874             "Can't find tag end: $end_tag_regexp in docs for: $symbol.");
2875         # Just assume it is all inside the tag.
2876         $result .= &$callback ($text, $symbol, $start_tag);
2877         $text = "";
2878       }
2879     }
2881     # Handle any remaining text outside the tags.
2882     $result .= &$callback ($text, $symbol, "");
2884     return $result;
2887 sub noop {
2888   return $_[0];
2891 # Adds a tag around some text.
2892 # e.g tagify("Text", "literal") => "<literal>Text</literal>".
2893 sub tagify {
2894    my ($text, $elem) = @_;
2895    return "<" . $elem . ">" . $text . "</" . $elem . ">";
2899 #############################################################################
2900 # Function    : MakeXRef
2901 # Description : This returns a cross-reference link to the given symbol.
2902 #                Though it doesn't try to do this for a few standard C types
2903 #                that it        knows won't be in the documentation.
2904 # Arguments   : $symbol - the symbol to try to create a XRef to.
2905 #               $text - text text to put inside the XRef, defaults to $symbol
2906 #############################################################################
2908 sub MakeXRef {
2909     my ($symbol, $text) = ($_[0], $_[1]);
2911     $symbol =~ s/^\s+//;
2912     $symbol =~ s/\s+$//;
2914     if (!defined($text)) {
2915         $text = $symbol;
2917         # Get rid of special '-struct' suffix.
2918         $text =~ s/-struct$//;
2919     }
2921     if ($symbol =~ m/ /) {
2922         return "$text";
2923     }
2925     #print "Getting type link for $symbol -> $text\n";
2927     my $symbol_id = &CreateValidSGMLID ($symbol);
2928     return "<link linkend=\"$symbol_id\">$text</link>";
2932 #############################################################################
2933 # Function    : MakeIndexterms
2934 # Description : This returns a indexterm elements for the given symbol
2935 # Arguments   : $symbol - the symbol to create indexterms for
2936 #############################################################################
2938 sub MakeIndexterms {
2939   my ($symbol, $id) = @_;
2940   my $terms =  "";
2941   my $sortas = "";
2943   # make the index useful, by ommiting the namespace when sorting
2944   if ($NAME_SPACE ne "") {
2945     if ($symbol =~ m/^$NAME_SPACE\_?(.*)/i) {
2946        $sortas=" sortas=\"$1\"";
2947     }
2948   }
2950   if (exists $Deprecated{$symbol}) {
2951       $terms .= "<indexterm zone=\"$id\" role=\"deprecated\"><primary$sortas>$symbol</primary></indexterm>";
2952       $IndexEntriesDeprecated{$symbol}=$id;
2953       $IndexEntriesFull{$symbol}=$id;
2954   }
2955   if (exists $Since{$symbol}) {
2956      my $since = $Since{$symbol};
2957      $since =~ s/^\s+//;
2958      $since =~ s/\s+$//;
2959      if ($since ne "") {
2960          $terms .= "<indexterm zone=\"$id\" role=\"$since\"><primary$sortas>$symbol</primary></indexterm>";
2961      }
2962      $IndexEntriesSince{$symbol}=$id;
2963      $IndexEntriesFull{$symbol}=$id;
2964   }
2965   if ($terms eq "") {
2966      $terms .= "<indexterm zone=\"$id\"><primary$sortas>$symbol</primary></indexterm>";
2967      $IndexEntriesFull{$symbol}=$id;
2968   }
2970   return $terms;
2973 #############################################################################
2974 # Function    : MakeDeprecationNote
2975 # Description : This returns a deprecation warning for the given symbol.
2976 # Arguments   : $symbol - the symbol to try to create a warning for.
2977 #############################################################################
2979 sub MakeDeprecationNote {
2980     my ($symbol) = $_[0];
2981     my $desc = "";
2982     my $note = "";
2983     if (exists $Deprecated{$symbol}) {
2984         $desc .= "<warning>";
2986         if ($Deprecated{$symbol} =~ /^\s*([0-9\.]+)\s*:/) {
2987                 $desc .= "<para><literal>$symbol</literal> has been deprecated since version $1 and should not be used in newly-written code.";
2988         } else {
2989                 $desc .= "<para><literal>$symbol</literal> is deprecated and should not be used in newly-written code.";
2990         }
2991         if ($Deprecated{$symbol} ne "") {
2992             $note = &ExpandAbbreviations($symbol, $Deprecated{$symbol});
2993             $note =~ s/^\s*([0-9\.]+)\s*:\s*//;
2994             $note =~ s/^\s+//;
2995             $note =~ s/\s+$//;
2996             $note =~ s%\n{2,}%\n</para>\n<para>\n%g;
2997             $desc .= " " . $note;
2998         }
2999         $desc .= "</para></warning>\n";
3000     }
3001     return $desc;
3004 #############################################################################
3005 # Function    : MakeConditionDescription
3006 # Description : This returns a sumary of conditions for the given symbol.
3007 # Arguments   : $symbol - the symbol to try to create the sumary.
3008 #############################################################################
3010 sub MakeConditionDescription {
3011     my ($symbol) = $_[0];
3012     my $desc = "";
3014     if (exists $Deprecated{$symbol}) {
3015         if ($desc ne "") {
3016             $desc .= "|";
3017         }
3019         if ($Deprecated{$symbol} =~ /^\s*(.*?)\s*$/) {
3020                 $desc .= "deprecated:$1";
3021         } else {
3022                 $desc .= "deprecated";
3023         }
3024     }
3026     if (exists $Since{$symbol}) {
3027         if ($desc ne "") {
3028             $desc .= "|";
3029         }
3031         if ($Since{$symbol} =~ /^\s*(.*?)\s*$/) {
3032                 $desc .= "since:$1";
3033         } else {
3034                 $desc .= "since";
3035         }
3036     }
3038     if (exists $StabilityLevel{$symbol}) {
3039         if ($desc ne "") {
3040             $desc .= "|";
3041         }
3042         $desc .= "stability:".$StabilityLevel{$symbol};
3043     }
3045     if ($desc ne "") {
3046         $desc=" condition=\"".$desc."\"";
3047         #print "condition for '$symbol' = '$desc'\n";
3048     }
3049     return $desc;
3052 #############################################################################
3053 # Function    : GetHierarchy
3054 # Description : Returns the DocBook output describing the ancestors and
3055 #               immediate children of a GObject subclass. It uses the
3056 #               global @Objects and @ObjectLevels arrays to walk the tree.
3057 # Arguments   : $object - the GtkObject subclass.
3058 #############################################################################
3060 sub GetHierarchy {
3061     my ($object) = @_;
3063     # Find object in the objects array.
3064     my $found = 0;
3065     my @children = ();
3066     my $i;
3067     my $level;
3068     my $j;
3069     for ($i = 0; $i < @Objects; $i++) {
3070         if ($found) {
3071             if ($ObjectLevels[$i] <= $level) {
3072             last;
3073         }
3074             elsif ($ObjectLevels[$i] == $level + 1) {
3075                 push (@children, $Objects[$i]);
3076             }
3077         }
3078         elsif ($Objects[$i] eq $object) {
3079             $found = 1;
3080             $j = $i;
3081             $level = $ObjectLevels[$i];
3082         }
3083     }
3084     if (!$found) {
3085         return "";
3086     }
3088     # Walk up the hierarchy, pushing ancestors onto the ancestors array.
3089     my @ancestors = ();
3090     push (@ancestors, $object);
3091     #print "Level: $level\n";
3092     while ($level > 1) {
3093         $j--;
3094         if ($ObjectLevels[$j] < $level) {
3095             push (@ancestors, $Objects[$j]);
3096             $level = $ObjectLevels[$j];
3097             #print "Level: $level\n";
3098         }
3099     }
3101     # Output the ancestors list, indented and with links.
3102     my $hierarchy = "<synopsis>\n";
3103     $level = 0;
3104     for ($i = $#ancestors; $i >= 0; $i--) {
3105         my $link_text;
3106         # Don't add a link to the current object, i.e. when i == 0.
3107         if ($i > 0) {
3108             my $ancestor_id = &CreateValidSGMLID ($ancestors[$i]);
3109             $link_text = "<link linkend=\"$ancestor_id\">$ancestors[$i]</link>";
3110         } else {
3111             $link_text = "$ancestors[$i]";
3112         }
3113         if ($level == 0) {
3114             $hierarchy .= "  $link_text\n";
3115         } else {
3116 #            $hierarchy .= ' ' x ($level * 6 - 3) . "|\n";
3117             $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3118         }
3119         $level++;
3120     }
3121     for ($i = 0; $i <= $#children; $i++) {
3122       my $id = &CreateValidSGMLID ($children[$i]);
3123       my $link_text = "<link linkend=\"$id\">$children[$i]</link>";
3124       $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3125     }
3126     $hierarchy .= "</synopsis>\n";
3128     return $hierarchy;
3132 #############################################################################
3133 # Function    : GetInterfaces
3134 # Description : Returns the DocBook output describing the interfaces
3135 #               implemented by a class. It uses the global %Interfaces hash.
3136 # Arguments   : $object - the GtkObject subclass.
3137 #############################################################################
3139 sub GetInterfaces {
3140     my ($object) = @_;
3141     my $text = "";
3142     my $i;
3144     # Find object in the objects array.
3145     if (exists($Interfaces{$object})) {
3146         my @ifaces = split(' ', $Interfaces{$object});
3147         $text = <<EOF;
3148 <para>
3149 $object implements
3151         for ($i = 0; $i <= $#ifaces; $i++) {
3152             my $id = &CreateValidSGMLID ($ifaces[$i]);
3153             $text .= " <link linkend=\"$id\">$ifaces[$i]</link>";
3154             if ($i < $#ifaces - 1) {
3155                 $text .= ', ';
3156             }
3157             elsif ($i < $#ifaces) {
3158                 $text .= ' and ';
3159             }
3160             else {
3161                 $text .= '.';
3162             }
3163         }
3164         $text .= <<EOF;
3165 </para>
3167     }
3169     return $text;
3172 #############################################################################
3173 # Function    : GetImplementations
3174 # Description : Returns the DocBook output describing the implementations
3175 #               of an interface. It uses the global %Interfaces hash.
3176 # Arguments   : $object - the GtkObject subclass.
3177 #############################################################################
3179 sub GetImplementations {
3180     my ($object) = @_;
3181     my @impls = ();
3182     my $text = "";
3183     my $i;
3184     foreach my $key (keys %Interfaces) {
3185         if ($Interfaces{$key} =~ /\b$object\b/) {
3186             push (@impls, $key);
3187         }
3188     }
3189     if ($#impls >= 0) {
3190         @impls = sort @impls;
3191         $text = <<EOF;
3192 <para>
3193 $object is implemented by
3195         for ($i = 0; $i <= $#impls; $i++) {
3196             my $id = &CreateValidSGMLID ($impls[$i]);
3197             $text .= " <link linkend=\"$id\">$impls[$i]</link>";
3198             if ($i < $#impls - 1) {
3199                 $text .= ', ';
3200             }
3201             elsif ($i < $#impls) {
3202                 $text .= ' and ';
3203             }
3204             else {
3205                 $text .= '.';
3206             }
3207         }
3208         $text .= <<EOF;
3209 </para>
3211     }
3212     return $text;
3216 #############################################################################
3217 # Function    : GetPrerequisites
3218 # Description : Returns the DocBook output describing the prerequisites
3219 #               of an interface. It uses the global %Prerequisites hash.
3220 # Arguments   : $iface - the interface.
3221 #############################################################################
3223 sub GetPrerequisites {
3224     my ($iface) = @_;
3225     my $text = "";
3226     my $i;
3228     if (exists($Prerequisites{$iface})) {
3229         $text = <<EOF;
3230 <para>
3231 $iface requires
3233         my @prereqs = split(' ', $Prerequisites{$iface});
3234         for ($i = 0; $i <= $#prereqs; $i++) {
3235             my $id = &CreateValidSGMLID ($prereqs[$i]);
3236             $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
3237             if ($i < $#prereqs - 1) {
3238                 $text .= ', ';
3239             }
3240             elsif ($i < $#prereqs) {
3241                 $text .= ' and ';
3242             }
3243             else {
3244                 $text .= '.';
3245             }
3246         }
3247         $text .= <<EOF;
3248 </para>
3250     }
3251     return $text;
3254 #############################################################################
3255 # Function    : GetDerived
3256 # Description : Returns the DocBook output describing the derived interfaces
3257 #               of an interface. It uses the global %Prerequisites hash.
3258 # Arguments   : $iface - the interface.
3259 #############################################################################
3261 sub GetDerived {
3262     my ($iface) = @_;
3263     my $text = "";
3264     my $i;
3266     my @derived = ();
3267     foreach my $key (keys %Prerequisites) {
3268         if ($Prerequisites{$key} =~ /\b$iface\b/) {
3269             push (@derived, $key);
3270         }
3271     }
3272     if ($#derived >= 0) {
3273         @derived = sort @derived;
3274         $text = <<EOF;
3275 <para>
3276 $iface is required by
3278         for ($i = 0; $i <= $#derived; $i++) {
3279             my $id = &CreateValidSGMLID ($derived[$i]);
3280             $text .= " <link linkend=\"$id\">$derived[$i]</link>";
3281             if ($i < $#derived - 1) {
3282                 $text .= ', ';
3283             }
3284             elsif ($i < $#derived) {
3285                 $text .= ' and ';
3286             }
3287             else {
3288                 $text .= '.';
3289             }
3290         }
3291         $text .= <<EOF;
3292 </para>
3294     }
3295     return $text;
3299 #############################################################################
3300 # Function    : GetSignals
3301 # Description : Returns the synopsis and detailed description DocBook output
3302 #                for the signal handlers of a given GtkObject subclass.
3303 # Arguments   : $object - the GtkObject subclass, e.g. 'GtkButton'.
3304 #############################################################################
3306 sub GetSignals {
3307     my ($object) = @_;
3308     my $synop = "";
3309     my $desc = "";
3311     my $i;
3312     for ($i = 0; $i <= $#SignalObjects; $i++) {
3313         if ($SignalObjects[$i] eq $object) {
3314             #print "Found signal: $SignalNames[$i]\n";
3315             my $name = $SignalNames[$i];
3316             my $symbol = "${object}::${name}";
3317             my $id = &CreateValidSGMLID ("$object-$name");
3319             my $pad = ' ' x (46 - length($name));
3320             $synop .= "  &quot;<link linkend=\"$id\">$name</link>&quot;$pad ";
3322             $desc .= "<refsect2 id=\"$id\" role=\"signal\"><title>The <literal>&quot;$name&quot;</literal> signal</title>\n";
3323             $desc .= MakeIndexterms($symbol, $id);
3324             $desc .= "\n";
3325             $desc .= OutputSymbolExtraLinks($symbol);
3327             $desc .= "<programlisting>";
3329             $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
3330             my $type_modifier = defined($1) ? $1 : "";
3331             my $type = $2;
3332             my $pointer = $3;
3333             my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
3335             my $ret_type_len = length ($type_modifier) + length ($pointer)
3336                 + length ($type);
3337             my $ret_type_output = "$type_modifier$xref$pointer"
3338                 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
3340             $desc  .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
3342             my $sourceparams = $SourceSymbolParams{$symbol};
3343             my @params = split ("\n", $SignalPrototypes[$i]);
3344             my $j;
3345             my $l;
3346             my $type_len = length("gpointer");
3347             my $name_len = length("user_data");
3348             # do two passes, the first one is to calculate padding
3349             for ($l = 0; $l < 2; $l++) {
3350                 for ($j = 0; $j <= $#params; $j++) {
3351                     # allow alphanumerics, '_', '[' & ']' in param names
3352                     if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
3353                         $type = $1;
3354                         $pointer = $2;
3355                         if (defined($sourceparams)) {
3356                             $name = $$sourceparams[$PARAM_FIELD_COUNT * $j];
3357                         }
3358                         else {
3359                             $name = $3;
3360                         }
3361                         if (!defined($name)) {
3362                             $name = "arg$j";
3363                         }
3364                         if ($l == 0) {
3365                             if (length($type) + length($pointer) > $type_len) {
3366                                 $type_len = length($type) + length($pointer);
3367                             }
3368                             if (length($name) > $name_len) {
3369                                 $name_len = length($name);
3370                             }
3371                         }
3372                         else {
3373                             $xref = &MakeXRef ($type, &tagify($type, "type"));
3374                             $pad = ' ' x ($type_len - length($type) - length($pointer));
3375                             $desc .= "$xref$pad $pointer$name,\n";
3376                             $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
3377                         }
3378                     } else {
3379                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3380                              "Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]");
3381                     }
3382                 }
3383             }
3384             $xref = &MakeXRef ("gpointer", &tagify("gpointer", "type"));
3385             $pad = ' ' x ($type_len - length("gpointer"));
3386             $desc  .= "$xref$pad user_data)";
3388             my $flags = $SignalFlags[$i];
3389             my $flags_string = "";
3391             if (defined ($flags)) {
3392               if ($flags =~ m/f/) {
3393                 $flags_string = "<link linkend=\"G-SIGNAL-RUN-FIRST:CAPS\"><literal>Run First</literal></link>";
3394               }
3395               elsif ($flags =~ m/l/) {
3396                 $flags_string = "<link linkend=\"G-SIGNAL-RUN-LAST:CAPS\"><literal>Run Last</literal></link>";
3397               }
3398               elsif ($flags =~ m/c/) {
3399                 $flags_string = "<link linkend=\"G-SIGNAL-RUN-CLEANUP:CAPS\"><literal>Cleanup</literal></link>";
3400                 $flags_string = "Cleanup";
3401               }
3402               if ($flags =~ m/r/) {
3403                 if ($flags_string) { $flags_string .= " / "; }
3404                 $flags_string = "<link linkend=\"G-SIGNAL-NO-RECURSE:CAPS\"><literal>No Recursion</literal></link>";
3405               }
3406               if ($flags =~ m/d/) {
3407                 if ($flags_string) { $flags_string .= " / "; }
3408                 $flags_string = "<link linkend=\"G-SIGNAL-DETAILED:CAPS\"><literal>Has Details</literal></link>";
3409               }
3410               if ($flags =~ m/a/) {
3411                 if ($flags_string) { $flags_string .= " / "; }
3412                 $flags_string = "<link linkend=\"G-SIGNAL-ACTION:CAPS\"><literal>Action</literal></link>";
3413               }
3414               if ($flags =~ m/h/) {
3415                 if ($flags_string) { $flags_string .= " / "; }
3416                 $flags_string = "<link linkend=\"G-SIGNAL-NO-HOOKS:CAPS\"><literal>No Hooks</literal></link>";
3417               }
3418             }
3420             if ($flags_string)
3421               {
3422                 $synop .= ": $flags_string\n";
3424                 $pad = ' ' x (5 + $name_len - length("user_data"));
3425                 $desc  .= "$pad : $flags_string</programlisting>\n";
3426               }
3427             else
3428               {
3429                 $synop .= "\n";
3430                 $desc  .= "</programlisting>\n";
3431               }
3433             $desc .= &MakeDeprecationNote($symbol);
3435             my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
3436             my $parameters_output = 0;
3438             $AllSymbols{$symbol} = 1;
3439             if (defined ($SymbolDocs{$symbol})) {
3440                 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3442                 # Try to insert the parameter table at the author's desired
3443                 # position. Otherwise we need to tag it onto the end.
3444                 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
3445                   $parameters_output = 1;
3446                 }
3447                 $desc .= $symbol_docs;
3449                 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
3450                     $AllDocumentedSymbols{$symbol} = 1;
3451                 }
3452             }
3454             if ($parameters_output == 0) {
3455                 $desc .= $parameters;
3456               }
3457             $desc .= OutputSymbolTraits ($symbol);
3458             $desc .= "</refsect2>";
3459         }
3460     }
3461     return ($synop, $desc);
3465 #############################################################################
3466 # Function    : GetArgs
3467 # Description : Returns the synopsis and detailed description DocBook output
3468 #                for the Args of a given GtkObject subclass.
3469 # Arguments   : $object - the GtkObject subclass, e.g. 'GtkButton'.
3470 #############################################################################
3472 sub GetArgs {
3473     my ($object) = @_;
3474     my $synop = "";
3475     my $desc = "";
3476     my $child_synop = "";
3477     my $child_desc = "";
3478     my $style_synop = "";
3479     my $style_desc = "";
3481     my $i;
3482     for ($i = 0; $i <= $#ArgObjects; $i++) {
3483         if ($ArgObjects[$i] eq $object) {
3484             #print "Found arg: $ArgNames[$i]\n";
3485             my $name = $ArgNames[$i];
3486             my $flags = $ArgFlags[$i];
3487             my $flags_string = "";
3488             my $kind = "";
3489             my $id_sep = "";
3491             if ($flags =~ m/c/) {
3492                 $kind = "child property";
3493                 $id_sep = "c-";
3494             }
3495             elsif ($flags =~ m/s/) {
3496                 $kind = "style property";
3497                 $id_sep = "s-";
3498             }
3499             else {
3500                 $kind = "property";
3501             }
3503             # Remember only one colon so we don't clash with signals.
3504             my $symbol = "${object}:${name}";
3505             # use two dashes and ev. an extra separator here for the same reason.
3506             my $id = &CreateValidSGMLID ("$object--$id_sep$name");
3508             my $type = $ArgTypes[$i];
3509             my $type_output;
3510             my $range = $ArgRanges[$i];
3511             my $range_output = CreateValidSGML ($range);
3512             my $default = $ArgDefaults[$i];
3513             my $default_output = CreateValidSGML ($default);
3515             if ($type eq "GtkString") {
3516                 $type = "char*";
3517             }
3518             if ($type eq "GtkSignal") {
3519                 $type = "GtkSignalFunc, gpointer";
3520                 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
3521                     . &MakeXRef ("gpointer");
3522             } elsif ($type =~ m/^(\w+)\*$/) {
3523                 $type_output = &MakeXRef ($1, &tagify($1, "type")) . "*";
3524             } else {
3525                 $type_output = &MakeXRef ($type, &tagify($type, "type"));
3526             }
3528             if ($flags =~ m/r/) {
3529                 $flags_string = "Read";
3530             }
3531             if ($flags =~ m/w/) {
3532                 if ($flags_string) { $flags_string .= " / "; }
3533                 $flags_string .= "Write";
3534             }
3535             if ($flags =~ m/x/) {
3536                 if ($flags_string) { $flags_string .= " / "; }
3537                 $flags_string .= "Construct";
3538             }
3539             if ($flags =~ m/X/) {
3540                 if ($flags_string) { $flags_string .= " / "; }
3541                 $flags_string .= "Construct Only";
3542             }
3544             $AllSymbols{$symbol} = 1;
3545             my $blurb;
3546             if (defined($SymbolDocs{$symbol}) &&
3547                 !IsEmptyDoc($SymbolDocs{$symbol})) {
3548                 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3549                 #print ".. [$SymbolDocs{$symbol}][$blurb]\n";
3550                 $AllDocumentedSymbols{$symbol} = 1;
3551             }
3552             else {
3553                 if (!($ArgBlurbs[$i] eq "")) {
3554                     $AllDocumentedSymbols{$symbol} = 1;
3555                 } else {
3556                     # FIXME: print a warning?
3557                     #print ".. no description\n";
3558                 }
3559                 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
3560             }
3562             my $pad1 = " " x (24 - length ($name));
3563             my $pad2 = " " x (20 - length ($type));
3565              my $arg_synop = "  &quot;<link linkend=\"$id\">$name</link>&quot;$pad1 $type_output $pad2 : $flags_string\n";
3566             my $arg_desc = "<refsect2 id=\"$id\" role=\"property\"><title>The <literal>&quot;$name&quot;</literal> $kind</title>\n";
3567             $arg_desc .= MakeIndexterms($symbol, $id);
3568             $arg_desc .= "\n";
3569             $arg_desc .= OutputSymbolExtraLinks($symbol);
3571             $arg_desc .= "<programlisting>  &quot;$name&quot;$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
3572             $arg_desc .= &MakeDeprecationNote($symbol);
3573             $arg_desc .= $blurb;
3574             if ($range ne "") {
3575                 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
3576             }
3577             if ($default ne "") {
3578                 $arg_desc .= "<para>Default value: $default_output</para>\n";
3579             }
3580             $arg_desc .= OutputSymbolTraits ($symbol);
3581             $arg_desc .= "</refsect2>\n";
3583             if ($flags =~ m/c/) {
3584                 $child_synop .= $arg_synop;
3585                 $child_desc .= $arg_desc;
3586             }
3587             elsif ($flags =~ m/s/) {
3588                 $style_synop .= $arg_synop;
3589                 $style_desc .= $arg_desc;
3590             }
3591             else {
3592                 $synop .= $arg_synop;
3593                 $desc .= $arg_desc;
3594             }
3595         }
3596     }
3597     return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
3601 #############################################################################
3602 # Function    : ReadSourceDocumentation
3603 # Description : This reads in the documentation embedded in comment blocks
3604 #                in the source code (for Gnome).
3606 #                Parameter descriptions override any in the template files.
3607 #                Function descriptions are placed before any description from
3608 #                the template files.
3610 #                It recursively descends the source directory looking for .c
3611 #                files and scans them looking for specially-formatted comment
3612 #                blocks.
3614 # Arguments   : $source_dir - the directory to scan.
3615 #############m###############################################################
3617 sub ReadSourceDocumentation {
3618     my ($source_dir) = @_;
3619     my ($file, $dir, @suffix_list, $suffix);
3621     # prepend entries from @SOURCE_DIR
3622     for my $dir (@SOURCE_DIRS) {
3623         # Check if the filename is in the ignore list.
3624         if ($source_dir =~ m%^\Q$dir\E/(.*)$% and $IGNORE_FILES =~ m/(\s|^)\Q$1\E(\s|$)/) {
3625             @TRACE@("Skipping source directory: $source_dir");
3626             return;
3627         }
3628     }
3630     @TRACE@("Scanning source directory: $source_dir");
3632     # This array holds any subdirectories found.
3633     my (@subdirs) = ();
3635     @suffix_list = split (/,/, $SOURCE_SUFFIXES);
3637     opendir (SRCDIR, $source_dir)
3638         || die "Can't open source directory $source_dir: $!";
3640     foreach $file (readdir (SRCDIR)) {
3641       if ($file =~ /^\./) {
3642         next;
3643       } elsif (-d "$source_dir/$file") {
3644         push (@subdirs, $file);
3645       } elsif (@suffix_list) {
3646         foreach $suffix (@suffix_list) {
3647           if ($file =~ m/\.\Q${suffix}\E$/) {
3648             &ScanSourceFile ("$source_dir/$file");
3649           }
3650         }
3651       } elsif ($file =~ m/\.[ch]$/) {
3652         &ScanSourceFile ("$source_dir/$file");
3653       }
3654     }
3655     closedir (SRCDIR);
3657     # Now recursively scan the subdirectories.
3658     foreach $dir (@subdirs) {
3659         &ReadSourceDocumentation ("$source_dir/$dir");
3660     }
3664 #############################################################################
3665 # Function    : ScanSourceFile
3666 # Description : Scans one source file looking for specially-formatted comment
3667 #                blocks. Later &MergeSourceDocumentation is used to merge any
3668 #                documentation found with the documentation already read in
3669 #                from the template files.
3671 # Arguments   : $file - the file to scan.
3672 #############################################################################
3674 sub ScanSourceFile {
3675     my ($file) = @_;
3676     my $basename;
3678     # prepend entries from @SOURCE_DIR
3679     for my $dir (@SOURCE_DIRS) {
3680         # Check if the filename is in the ignore list.
3681         if ($file =~ m%^\Q$dir\E/(.*)$% and $IGNORE_FILES =~ m/(\s|^)\Q$1\E(\s|$)/) {
3682             @TRACE@("Skipping source file: $file");
3683             return;
3684         }
3685     }
3687     if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
3688         $basename = $1;
3689     } else {
3690         &LogWarning ($file, 1, "Can't find basename for this filename.");
3691         $basename = $file;
3692     }
3694     # Check if the basename is in the list of files to ignore.
3695     if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
3696         @TRACE@("Skipping source file: $file");
3697         return;
3698     }
3700     @TRACE@("Scanning source file: $file");
3702     open (SRCFILE, $file)
3703         || die "Can't open $file: $!";
3704     my $in_comment_block = 0;
3705     my $symbol;
3706     my ($in_description, $in_return, $in_since, $in_stability, $in_deprecated);
3707     my ($description, $return_desc, $return_start, $return_style);
3708     my ($since_desc, $stability_desc, $deprecated_desc);
3709     my $current_param;
3710     my $ignore_broken_returns;
3711     my @params;
3712     while (<SRCFILE>) {
3713         # Look for the start of a comment block.
3714         if (!$in_comment_block) {
3715             if (m%^\s*/\*.*\*/%) {
3716                 #one-line comment - not gtkdoc
3717             } elsif (m%^\s*/\*\*\s%) {
3718                 #print "Found comment block start\n";
3720                 $in_comment_block = 1;
3722                 # Reset all the symbol data.
3723                 $symbol = "";
3724                 $in_description = 0;
3725                 $in_return = 0;
3726                 $in_since = 0;
3727                 $in_deprecated = 0;
3728                 $in_stability = 0;
3729                 $description = "";
3730                 $return_desc = "";
3731                 $return_style = "";
3732                 $since_desc = "";
3733                 $deprecated_desc = "";
3734                 $stability_desc = "";
3735                 $current_param = -1;
3736                 $ignore_broken_returns = 0;
3737                 @params = ();
3738             }
3739             next;
3740         }
3742         # We're in a comment block. Check if we've found the end of it.
3743         if (m%^\s*\*+/%) {
3744             if (!$symbol) {
3745                 # maybe its not even meant to be a gtk-doc comment?
3746                 &LogWarning ($file, $., "Symbol name not found at the start of the comment block.");
3747             } else {
3748                 # Add the return value description onto the end of the params.
3749                 if ($return_desc) {
3750                     push (@params, "Returns");
3751                     push (@params, $return_desc);
3752                     if ($return_style eq 'broken') {
3753                         &LogWarning ($file, $., "Free-form return value description in $symbol. Use `Returns:' to avoid ambiguities.");
3754                     }
3755                 }
3756                 # Convert special SGML characters
3757                 $description = &ConvertSGMLChars ($symbol, $description);
3758                 my $k;
3759                 for ($k = 1; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3760                     $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
3761                 }
3763                 # Handle Section docs
3764                 if ($symbol =~ m/SECTION:\s*(.*)/) {
3765                     my $real_symbol=$1;
3766                     my $key;
3768                     if (scalar %KnownSymbols) {
3769                         if ((! defined($KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"})) || $KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"} != 1) {
3770                             &LogWarning ($file, $., "Section $real_symbol is not defined in the $MODULE-section.txt file.");
3771                         }
3772                     }
3774                     #print "SECTION DOCS found in source for : '$real_symbol'\n";
3775                     $ignore_broken_returns = 1;
3776                     for ($k = 0; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3777                         #print "   '".$params[$k]."'\n";
3778                         $params[$k] = "\L$params[$k]";
3779                         undef $key;
3780                         if ($params[$k] eq "short_description") {
3781                             $key = "$TMPL_DIR/$real_symbol:Short_Description";
3782                         } elsif ($params[$k] eq "see_also") {
3783                             $key = "$TMPL_DIR/$real_symbol:See_Also";
3784                         } elsif ($params[$k] eq "title") {
3785                             $key = "$TMPL_DIR/$real_symbol:Title";
3786                         } elsif ($params[$k] eq "stability") {
3787                             $key = "$TMPL_DIR/$real_symbol:Stability_Level";
3788                         } elsif ($params[$k] eq "section_id") {
3789                             $key = "$TMPL_DIR/$real_symbol:Section_Id";
3790                         } elsif ($params[$k] eq "include") {
3791                             $key = "$TMPL_DIR/$real_symbol:Include";
3792                         } elsif ($params[$k] eq "image") {
3793                             $key = "$TMPL_DIR/$real_symbol:Image";
3794                         }
3795                         if (defined($key)) {
3796                             $SourceSymbolDocs{$key}=$params[$k+1];
3797                             $SourceSymbolSourceFile{$key} = $file;
3798                             $SourceSymbolSourceLine{$key} = $.;
3799                         }
3800                     }
3801                     $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
3802                     $SourceSymbolSourceFile{"$TMPL_DIR/$real_symbol:Long_Description"} = $file;
3803                     $SourceSymbolSourceLine{"$TMPL_DIR/$real_symbol:Long_Description"} = $.;
3804                     #$SourceSymbolTypes{$symbol} = "SECTION";
3805                 } else {
3806                     #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
3807                     $SourceSymbolDocs{$symbol} = $description;
3808                     $SourceSymbolParams{$symbol} = [ @params ];
3809                     # FIXME $SourceSymbolTypes{$symbol} = "STRUCT,SIGNAL,ARG,FUNCTION,MACRO";
3810                     #if (defined $DeclarationTypes{$symbol}) {
3811                     #    $SourceSymbolTypes{$symbol} = $DeclarationTypes{$symbol}
3812                     #}
3813                     $SourceSymbolSourceFile{$symbol} = $file;
3814                     $SourceSymbolSourceLine{$symbol} = $.;
3815                 }
3817                 if ($since_desc) {
3818                      ($since_desc, my @extra_lines) = split ("\n", $since_desc);
3819                      $since_desc =~ s/^\s+//;
3820                      $since_desc =~ s/\s+$//;
3821                      #print "Since($symbol) : [$since_desc]\n";
3822                      $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
3823                      if(scalar @extra_lines) {
3824                          &LogWarning ($file, $., "multi-line since docs found");
3825                      }
3826                 }
3828                 if ($stability_desc) {
3829                     $stability_desc = &ParseStabilityLevel($stability_desc, $file, $., "Stability level for $symbol");
3830                     $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
3831                 }
3833                 if ($deprecated_desc) {
3834                     if (exists $Deprecated{$symbol}) {
3835                     }
3836                     else {
3837                          # don't warn for signals and properties
3838                          #if ($symbol !~ m/::?(.*)/) {
3839                          if (defined $DeclarationTypes{$symbol}) {
3840                              &LogWarning ($file, $.,
3841                                  "$symbol is deprecated in the inline comments, but no deprecation guards were found around the declaration.".
3842                                  " (See the --deprecated-guards option for gtkdoc-scan.)");
3843                          }
3844                     }
3845                     $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
3846                 }
3847             }
3849             $in_comment_block = 0;
3850             next;
3851         }
3853         # Get rid of ' * ' at start of every line in the comment block.
3854         s%^\s*\*\s?%%;
3855         # But make sure we don't get rid of the newline at the end.
3856         if (!$_) {
3857             $_ = "\n";
3858         }
3859         #print "DEBUG: scanning :$_";
3861         # If we haven't found the symbol name yet, look for it.
3862         if (!$symbol) {
3863             if (m%^\s*(SECTION:\s*\S+)%) {
3864                 $symbol = $1;
3865                 #print "SECTION DOCS found in source for : '$symbol'\n";
3866                 $ignore_broken_returns = 1;
3867             } elsif (m%^\s*([\w:-]*\w)\s*:?\s*(\([a-z ]+\)\s*)*$%) {
3868                 $symbol = $1;
3869                 #print "SYMBOL DOCS found in source for : '$symbol'\n";
3870             }
3871             next;
3872         }
3874         # FIXME: flip this around
3875         # instead of repeating the other parts, just have them once and
3876         # do if(!$in_return) { ... }
3877         # also maybe have in_part="description,return,since,deprecated,stability,..."
3879         # If we're in the return value description, add it to the end.
3880         if ($in_return) {
3881             # If we find another valid returns line, we assume that the first
3882             # one was really part of the description.
3883             if (m/^\s*(returns:|return\s+value:)/i) {
3884                 if ($return_style eq 'broken') {
3885                     $description .= $return_start . $return_desc;
3886                 }
3887                 $return_start = $1;
3888                 if ($return_style eq 'sane') {
3889                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3890                 }
3891                 $return_style = 'sane';
3892                 $ignore_broken_returns = 1;
3893                 $return_desc = $';
3894             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3895                 $description .= $return_start . $return_desc;
3896                 $return_start = $1;
3897                 $return_style = 'broken';
3898                 $return_desc = $';
3899             } elsif (m%^\s*since:%i) {
3900                 $since_desc = $';
3901                 $in_since = 1;
3902                 $in_return = 0;
3903             } elsif (m%^\s*stability:%i) {
3904                 $stability_desc = $';
3905                 $in_stability = 1;
3906                 $in_return = 0;
3907             } elsif (m%^\s*deprecated:%i) {
3908                 $deprecated_desc = $';
3909                 $in_deprecated = 1;
3910                 $in_return = 0;
3911             } else {
3912                 $return_desc .= $_;
3913             }
3914             next;
3915         }
3917         if ($in_since) {
3918             if (m/^\s*(returns:|return\s+value:)/i) {
3919                 if ($return_style eq 'broken') {
3920                     $description .= $return_start . $return_desc;
3921                 }
3922                 $return_start = $1;
3923                 if ($return_style eq 'sane') {
3924                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3925                 }
3926                 $return_style = 'sane';
3927                 $ignore_broken_returns = 1;
3928                 $return_desc = $';
3929                 $in_return = 1;
3930                 $in_since = 0;
3931             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3932                 $return_start = $1;
3933                 $return_style = 'broken';
3934                 $return_desc = $';
3935                 $in_return = 1;
3936                 $in_since = 0;
3937             } elsif (m%^\s*deprecated:%i) {
3938                 $deprecated_desc = $';
3939                 $in_deprecated = 1;
3940                 $in_since = 0;
3941             } elsif (m%^\s*stability:%i) {
3942                 $stability_desc = $';
3943                 $in_stability = 1;
3944                 $in_since = 0;
3945             } else {
3946                 $since_desc .= $_;
3947             }
3948             next;
3949         }
3951         if ($in_stability) {
3952             if (m/^\s*(returns:|return\s+value:)/i) {
3953                 if ($return_style eq 'broken') {
3954                     $description .= $return_start . $return_desc;
3955                 }
3956                 $return_start = $1;
3957                 if ($return_style eq 'sane') {
3958                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3959                 }
3960                 $return_style = 'sane';
3961                 $ignore_broken_returns = 1;
3962                 $return_desc = $';
3963                 $in_return = 1;
3964                 $in_stability = 0;
3965             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3966                 $return_start = $1;
3967                 $return_style = 'broken';
3968                 $return_desc = $';
3969                 $in_return = 1;
3970                 $in_stability = 0;
3971             } elsif (m%^\s*deprecated:%i) {
3972                 $deprecated_desc = $';
3973                 $in_deprecated = 1;
3974                 $in_stability = 0;
3975             } elsif (m%^\s*since:%i) {
3976                 $since_desc = $';
3977                 $in_since = 1;
3978                 $in_stability = 0;
3979             } else {
3980                 $stability_desc .= $_;
3981             }
3982             next;
3983         }
3985         if ($in_deprecated) {
3986             if (m/^\s*(returns:|return\s+value:)/i) {
3987                 if ($return_style eq 'broken') {
3988                     $description .= $return_start . $return_desc;
3989                 }
3990                 $return_start = $1;
3991                 if ($return_style eq 'sane') {
3992                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3993                 }
3994                 $return_style = 'sane';
3995                 $ignore_broken_returns = 1;
3996                 $return_desc = $';
3997                 $in_return = 1;
3998                 $in_deprecated = 0;
3999             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
4000                 $return_start = $1;
4001                 $return_style = 'broken';
4002                 $return_desc = $';
4003                 $in_return = 1;
4004                 $in_deprecated = 0;
4005             } elsif (m%^\s*since:%i) {
4006                 $since_desc = $';
4007                 $in_since = 1;
4008                 $in_deprecated = 0;
4009             } elsif (m%^\s*stability:%i) {
4010                 $stability_desc = $';
4011                 $in_stability = 1;
4012                 $in_deprecated = 0;
4013             } else {
4014                 $deprecated_desc .= $_;
4015             }
4016             next;
4017         }
4019         # If we're in the description part, check for the 'Returns:' line.
4020         # If that isn't found, add the text to the end.
4021         if ($in_description) {
4022             # Get rid of 'Description:'
4023             s%^\s*Description:%%;
4025             if (m/^\s*(returns:|return\s+value:)/i) {
4026                 if ($return_style eq 'broken') {
4027                     $description .= $return_start . $return_desc;
4028                 }
4029                 $return_start = $1;
4030                 if ($return_style eq 'sane') {
4031                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
4032                 }
4033                 $return_style = 'sane';
4034                 $ignore_broken_returns = 1;
4035                 $return_desc = $';
4036                 $in_return = 1;
4037                 next;
4038             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
4039                 $return_start = $1;
4040                 $return_style = 'broken';
4041                 $return_desc = $';
4042                 $in_return = 1;
4043                 next;
4044             } elsif (m%^\s*since:%i) {
4045                 $since_desc = $';
4046                 $in_since = 1;
4047                 next;
4048             } elsif (m%^\s*deprecated:%i) {
4049                 $deprecated_desc = $';
4050                 $in_deprecated = 1;
4051                 next;
4052             } elsif (m%^\s*stability:%i) {
4053                 $stability_desc = $';
4054                 $in_stability = 1;
4055                 next;
4056             }
4058             $description .= $_;
4059             next;
4060         }
4062         # We must be in the parameters. Check for the empty line below them.
4063         if (m%^\s*$%) {
4064             $in_description = 1;
4065             next;
4066         }
4068         # Look for a parameter name.
4069         if (m%^\s*@(\S+)\s*:\s*%) {
4070             my $param_name = $1;
4071             my $param_desc = $';
4073             #print "Found parameter: $param_name\n";
4074             # Allow '...' as the Varargs parameter.
4075             if ($param_name eq "...") {
4076                 $param_name = "Varargs";
4077             }
4078             if ("\L$param_name" eq "returns") {
4079                 $return_style = 'sane';
4080                 $ignore_broken_returns = 1;
4081             }
4082             push (@params, $param_name);
4083             push (@params, $param_desc);
4084             $current_param += $PARAM_FIELD_COUNT;
4085             next;
4086         }
4088         # We must be in the middle of a parameter description, so add it on
4089         # to the last element in @params.
4090         if ($current_param == -1) {
4091             &LogWarning ($file, $., "Parsing comment block file : parameter expected.");
4092         } else {
4093             $params[$#params] .= $_;
4094         }
4095     }
4096     close (SRCFILE);
4099 #############################################################################
4100 # Function    : OutputMissingDocumentation
4101 # Description : Outputs report of documentation coverage to a file
4103 # Arguments   : none
4104 #############################################################################
4106 sub OutputMissingDocumentation {
4107     my $old_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.txt";
4108     my $new_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.new";
4110     my $n_documented = 0;
4111     my $n_incomplete = 0;
4112     my $total = 0;
4113     my $symbol;
4114     my $percent;
4115     my $msg;
4116     my $buffer = "";
4117     my $buffer_deprecated = "";
4118     my $buffer_descriptions = "";
4120     open(UNDOCUMENTED, ">$new_undocumented_file")
4121       || die "Can't create $new_undocumented_file";
4123     foreach $symbol (sort (keys (%AllSymbols))) {
4124         # FIXME: should we print LogWarnings for undocumented stuff?
4125         # DEBUG
4126         #my $ssfile = &GetSymbolSourceFile($symbol);
4127         #my $ssline = &GetSymbolSourceLine($symbol);
4128         #my $location = "defined at " . (defined($ssfile)?$ssfile:"?") . ":" . (defined($ssline)?$ssline:"0") . "\n";
4129         # DEBUG
4130         if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include|Section_Id|Image)/) {
4131             $total++;
4132             if (exists ($AllDocumentedSymbols{$symbol})) {
4133                 $n_documented++;
4134                 if (exists ($AllIncompleteSymbols{$symbol})) {
4135                     $n_incomplete++;
4136                     $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4137                     #$buffer .= "\t0: ".$location;
4138                 }
4139             } elsif (exists $Deprecated{$symbol}) {
4140                 if (exists ($AllIncompleteSymbols{$symbol})) {
4141                     $n_incomplete++;
4142                     $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4143                     #$buffer .= "\t1a: ".$location;
4144                 } else {
4145                     $buffer_deprecated .= $symbol . "\n";
4146                     #$buffer .= "\t1b: ".$location;
4147                 }
4148             } else {
4149                 if (exists ($AllIncompleteSymbols{$symbol})) {
4150                     $n_incomplete++;
4151                     $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4152                     #$buffer .= "\t2a: ".$location;
4153                 } else {
4154                     $buffer .= $symbol . "\n";
4155                     #$buffer .= "\t2b: ".$location;
4156                 }
4157             }
4158         } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
4159             $total++;
4160             #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
4161             #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
4162             #print "%%%% $symbol : $len1,$len2\n";
4163             if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
4164             || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
4165               $n_documented++;
4166             } else {
4167               # cut off the leading namespace ($TMPL_DIR)
4168               $symbol =~ m/^.*\/(.*)$/;
4169               $buffer_descriptions .= $1 . "\n";
4170             }
4171         }
4172     }
4174     $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
4176     if ($total == 0) {
4177       $percent = 100;
4178     } else {
4179       $percent = ($n_documented / $total) * 100.0;
4180     }
4182     printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
4183     print UNDOCUMENTED "$n_documented symbols documented.\n";
4184     print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
4185     print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
4187     print UNDOCUMENTED $buffer;
4188     close (UNDOCUMENTED);
4190     return &UpdateFileIfChanged ($old_undocumented_file, $new_undocumented_file, 0);
4192     printf "%.0f%% symbol docs coverage", $percent;
4193     print "($n_documented symbols documented, $n_incomplete symbols incomplete, " . ($total - $n_documented) . " not documented)\n";
4194     print "See $MODULE-undocumented.txt for a list of missing docs.\nThe doc coverage percentage doesn't include intro sections.\n";
4198 #############################################################################
4199 # Function    : OutputUndeclaredSymbols
4200 # Description : Outputs symbols that are listed in the section file, but not
4201 #               declaration is found in the sources
4203 # Arguments   : none
4204 #############################################################################
4206 sub OutputUndeclaredSymbols {
4207     my $old_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.txt";
4208     my $new_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.new";
4210     open(UNDECLARED, ">$new_undeclared_file")
4211         || die "Can't create $new_undeclared_file";
4213     if (%UndeclaredSymbols) {
4214         print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
4215         print UNDECLARED "\n";
4216         print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
4217     }
4218     close(UNDECLARED);
4220     return &UpdateFileIfChanged ($old_undeclared_file, $new_undeclared_file, 0);
4223 #############################################################################
4224 # Function    : OutputUnusedSymbols
4225 # Description : Outputs symbols that are documented in comments, but not
4226 #               declared in the sources
4228 # Arguments   : none
4229 #############################################################################
4231 sub OutputUnusedSymbols {
4232     my $num_unused = 0;
4233     my $old_unused_file = "$ROOT_DIR/$MODULE-unused.txt";
4234     my $new_unused_file = "$ROOT_DIR/$MODULE-unused.new";
4236     open (UNUSED, ">$new_unused_file")
4237         || die "Can't open $new_unused_file";
4238     my ($symbol);
4239     foreach $symbol (sort keys (%Declarations)) {
4240         if (!defined ($DeclarationOutput{$symbol})) {
4241             print (UNUSED "$symbol\n");
4242             $num_unused++;
4243         }
4244     }
4245     foreach $symbol (sort (keys (%AllUnusedSymbols))) {
4246         print (UNUSED "$symbol(" . $AllUnusedSymbols{$symbol} . ")\n");
4247         $num_unused++;
4248     }
4249     close (UNUSED);
4250     if ($num_unused != 0) {
4251         &LogWarning ($old_unused_file, 1, "$num_unused unused declarations.".
4252             "They should be added to $MODULE-sections.txt in the appropriate place.");
4253     }
4255     return &UpdateFileIfChanged ($old_unused_file, $new_unused_file, 0);
4259 #############################################################################
4260 # Function    : OutputAllSymbols
4261 # Description : Outputs list of all symbols to a file
4263 # Arguments   : none
4264 #############################################################################
4266 sub OutputAllSymbols {
4267      my $n_documented = 0;
4268      my $total = 0;
4269      my $symbol;
4270      my $percent;
4271      my $msg;
4273      open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
4274           || die "Can't create $ROOT_DIR/$MODULE-symbols.txt: $!";
4276      foreach $symbol (sort (keys (%AllSymbols))) {
4277           print SYMBOLS $symbol . "\n";
4278      }
4280      close (SYMBOLS);
4283 #############################################################################
4284 # Function    : OutputSymbolsWithoutSince
4285 # Description : Outputs list of all symbols without a since tag to a file
4287 # Arguments   : none
4288 #############################################################################
4290 sub OutputSymbolsWithoutSince {
4291      my $n_documented = 0;
4292      my $total = 0;
4293      my $symbol;
4294      my $percent;
4295      my $msg;
4297      open (SYMBOLS, ">$ROOT_DIR/$MODULE-nosince.txt")
4298           || die "Can't create $ROOT_DIR/$MODULE-nosince.txt: $!";
4300      foreach $symbol (sort (keys (%SourceSymbolDocs))) {
4301          if (!defined $Since{$symbol}) {
4302              print SYMBOLS $symbol . "\n";
4303          }
4304      }
4306      close (SYMBOLS);
4310 #############################################################################
4311 # Function    : MergeSourceDocumentation
4312 # Description : This merges documentation read from a source file into the
4313 #                documentation read in from a template file.
4315 #                Parameter descriptions override any in the template files.
4316 #                Function descriptions are placed before any description from
4317 #                the template files.
4319 # Arguments   : none
4320 #############################################################################
4322 sub MergeSourceDocumentation {
4323     my $symbol;
4324     my @Symbols;
4326     if (scalar %SymbolDocs) {
4327         @Symbols=keys (%SymbolDocs);
4328         #print "num existing entries: ".(scalar @Symbols)."\n";
4329         #print "  ",$Symbols[0], " ",$Symbols[1],"\n";
4330     }
4331     else {
4332         # filter scanned declarations, with what we suppress from -sections.txt
4333         my %tmp = ();
4334         foreach $symbol (keys (%Declarations)) {
4335             if (defined($KnownSymbols{$symbol}) && $KnownSymbols{$symbol} == 1) {
4336                 $tmp{$symbol}=1;
4337             }
4338         }
4339         # , add the rest from -sections.txt
4340         foreach $symbol (keys (%KnownSymbols)) {
4341             if ($KnownSymbols{$symbol} == 1) {
4342                 $tmp{$symbol}=1;
4343             }
4344         }
4345         # and add whats found in the source
4346         foreach $symbol (keys (%SourceSymbolDocs)) {
4347             $tmp{$symbol}=1;
4348         }
4349         @Symbols = keys (%tmp);
4350         #print "num source entries: ".(scalar @Symbols)."\n";
4351     }
4352     foreach $symbol (@Symbols) {
4353         $AllSymbols{$symbol} = 1;
4355         my $have_tmpl_docs = 0;
4357         ## see if the symbol is documented in template
4358         my $tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4359         my $check_tmpl_doc =$tmpl_doc;
4360         # remove all xml-tags and whitespaces
4361         $check_tmpl_doc =~ s/<.*?>//g;
4362         $check_tmpl_doc =~ s/\s//g;
4363         # anything left ?
4364         if ($check_tmpl_doc ne "") {
4365             $have_tmpl_docs = 1;
4366             #print "## [$check_tmpl_doc]\n";
4367         } else {
4368             # if the docs have just an empty para, don't merge that.
4369             $check_tmpl_doc = $tmpl_doc;
4370             $check_tmpl_doc =~ s/(\s|\n)//msg;
4371             if ($check_tmpl_doc eq "<para></para>") {
4372                $tmpl_doc = "";
4373             }
4374         }
4376         if (exists ($SourceSymbolDocs{$symbol})) {
4377             my $type = $DeclarationTypes {$symbol};
4379             #print "merging [$symbol] from source\n";
4381             my $item = "Parameter";
4382             if (defined ($type)) {
4383                 if ($type eq 'STRUCT') {
4384                     $item = "Field";
4385                 } elsif ($type eq 'ENUM') {
4386                     $item = "Value";
4387                 } elsif ($type eq 'UNION') {
4388                     $item = "Field";
4389                 }
4390             } else {
4391                 $type="SIGNAL";
4392             }
4394             my $src_doc = $SourceSymbolDocs{$symbol};
4395             # remove leading and training whitespaces
4396             $src_doc =~ s/^\s+//;
4397             $src_doc =~ s/\s+$//;
4399             # Don't output warnings for overridden titles as titles are
4400             # automatically generated in the -sections.txt file, and thus they
4401             # are often overridden.
4402             if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
4403                 # check if content is different
4404                 if ($tmpl_doc ne $src_doc) {
4405                     #print "[$tmpl_doc] [$src_doc]\n";
4406                     &LogWarning ($SourceSymbolSourceFile{$symbol}, $SourceSymbolSourceLine{$symbol},
4407                         "Documentation in template ".$SymbolSourceFile{$symbol}.":".$SymbolSourceLine{$symbol}." for $symbol being overridden by inline comments.");
4408                 }
4409             }
4411             if ($src_doc ne "") {
4412                  $AllDocumentedSymbols{$symbol} = 1;
4413             }
4415             # Convert <!--PARAMETERS--> with any blank lines around it to
4416             # a </para> followed by <!--PARAMETERS--> followed by <para>.
4417             $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
4419             # Do not add <para> to nothing, it breaks missing docs checks.
4420             my $src_doc_para = "";
4421             if ($src_doc ne "") {
4422                 # Expand markdown (and do paragraphs)
4423                 $src_doc_para = &ConvertMarkDown ($src_doc, $symbol);
4424                 ## fixup xml markup
4425                 # FIXME: this is questionable, as we can't make assumtions on the content really
4426                 #$src_doc_para =~ s%^<para>\n(<refsect[1-9])%$1%gms;
4427                 #$src_doc_para =~ s%^<para>\n<para>%<para>%gms;
4428                 #$src_doc_para =~ s%(</refsect[1-9]>)\n</para>$%$1%gms;
4429                 #print "$symbol : [$src_doc][$src_doc_para]\n";
4430             }
4432             if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
4433                 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4434             } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
4435                 # For the title/summary/see also section docs we don't want to
4436                 # add any <para> tags.
4437                 $SymbolDocs{$symbol} = "$src_doc"
4438             } else {
4439                 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4440             }
4442             # merge parameters
4443             if ($symbol =~ m/.*::.*/) {
4444                 # For signals we prefer the param names from the source docs,
4445                 # since the ones from the templates are likely to contain the
4446                 # artificial argn names which are generated by gtkdoc-scangobj.
4447                 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4448                 # FIXME: we need to check for empty docs here as well!
4449             } else {
4450                 # The templates contain the definitive parameter names and order,
4451                 # so we will not change that. We only override the actual text.
4452                 my $tmpl_params = $SymbolParams{$symbol};
4453                 if (!defined ($tmpl_params)) {
4454                     #print "No merge needed for $symbol\n";
4455                     $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4456                     #  FIXME: we still like to get the number of params and merge
4457                     #  1) we would noticed that params have been removed/renamed
4458                     #  2) we would catch undocumented params
4459                     #  params are not (yet) exported in -decl.txt so that we
4460                     #  could easily grab them :/
4461                 } else {
4462                     my $params = $SourceSymbolParams{$symbol};
4463                     my $j;
4464                     #print "Merge needed for $symbol, tmpl_params: ",$#$tmpl_params,", source_params: ",$#$params," \n";
4465                     for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4466                         my $tmpl_param_name = $$tmpl_params[$j];
4468                         # Allow '...' as the Varargs parameter.
4469                         if ($tmpl_param_name eq "...") {
4470                             $tmpl_param_name = "Varargs";
4471                         }
4473                         # Try to find the param in the source comment documentation.
4474                         my $found = 0;
4475                         my $k;
4476                         #print "  try merge param $tmpl_param_name\n";
4477                         for ($k = 0; $k <= $#$params; $k += $PARAM_FIELD_COUNT) {
4478                             my $param_name = $$params[$k];
4479                             my $param_desc = $$params[$k + 1];
4481                             #print "    test param  $param_name\n";
4482                             # We accept changes in case, since the Gnome source
4483                             # docs contain a lot of these.
4484                             if ("\L$param_name" eq "\L$tmpl_param_name") {
4485                                 $found = 1;
4487                                 # Override the description.
4488                                 $$tmpl_params[$j + 1] = $param_desc;
4490                                 # Set the name to "" to mark it as used.
4491                                 $$params[$k] = "";
4492                                 last;
4493                             }
4494                         }
4496                         # If it looks like the parameters are there, but not
4497                         # in the right place, try to explain a bit better.
4498                         if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
4499                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4500                                 "Parameters for $symbol must start on the line immediately after the function or macro name.");
4501                         }
4502                     }
4504                     # Now we output a warning if parameters have been described which
4505                     # do not exist.
4506                     for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
4507                         my $param_name = $$params[$j];
4508                         if ($param_name) {
4509                             # the template builder cannot detect if a macro returns
4510                             # a result or not
4511                             if(($type eq "MACRO") && ($param_name eq "Returns")) {
4512                                 # FIXME: do we need to add it then to tmpl_params[] ?
4513                                 my $num=$#$tmpl_params;
4514                                 #print "  adding Returns: to macro docs for $symbol.\n";
4515                                 $$tmpl_params[$num+1]="Returns";
4516                                 $$tmpl_params[$num+2]=$$params[$j+1];
4517                                 next;
4518                             }
4519                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4520                                 "$item described in source code comment block but does not exist. $type: $symbol $item: $param_name.");
4521                         }
4522                     }
4523                 }
4524             }
4525         } else {
4526             if ($have_tmpl_docs) {
4527                 $AllDocumentedSymbols{$symbol} = 1;
4528                 #print "merging [$symbol] from template\n";
4529             }
4530             else {
4531                 #print "[$symbol] undocumented\n";
4532             }
4533         }
4535         # if this symbol is documented, check if docs are complete
4536         $check_tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4537         # remove all xml-tags and whitespaces
4538         $check_tmpl_doc =~ s/<.*?>//g;
4539         $check_tmpl_doc =~ s/\s//g;
4540         if ($check_tmpl_doc ne "") {
4541             my $tmpl_params = $SymbolParams{$symbol};
4542             if (defined ($tmpl_params)) {
4543                 my $type = $DeclarationTypes {$symbol};
4545                 my $item = "Parameter";
4546                 if (defined ($type)) {
4547                     if ($type eq 'STRUCT') {
4548                         $item = "Field";
4549                     } elsif ($type eq 'ENUM') {
4550                         $item = "Value";
4551                     } elsif ($type eq 'UNION') {
4552                         $item = "Field";
4553                     }
4554                 } else {
4555                     $type="SIGNAL";
4556                 }
4558                 #print "Check param docs for $symbol, tmpl_params: ",$#$tmpl_params," entries, type=$type\n";
4560                 if ($#$tmpl_params > 0) {
4561                     my $j;
4562                     for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4563                         # Output a warning if the parameter is empty and
4564                         # remember for stats.
4565                         my $tmpl_param_name = $$tmpl_params[$j];
4566                         my $tmpl_param_desc = $$tmpl_params[$j + 1];
4567                         if ($tmpl_param_name ne "void" && $tmpl_param_desc !~ m/\S/) {
4568                             if (exists ($AllIncompleteSymbols{$symbol})) {
4569                                 $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
4570                             } else {
4571                                 $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
4572                             }
4573                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4574                                 "$item description for $symbol"."::"."$tmpl_param_name is missing in source code comment block.");
4575                         }
4576                     }
4577                 }
4578                 else {
4579                     if ($#$tmpl_params == 0) {
4580                         $AllIncompleteSymbols{$symbol}="<items>";
4581                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4582                             "$item descriptions for $symbol are missing in source code comment block.");
4583                     }
4584                     # $#$tmpl_params==-1 means we don't know about parameters
4585                     # this unfortunately does not tell if there should be some
4586                 }
4587             }
4588         }
4589    }
4590    #print "num doc entries: ".(scalar %SymbolDocs)."\n";
4593 #############################################################################
4594 # Function    : IsEmptyDoc
4595 # Description : Check if a doc-string is empty. Its also regarded as empty if
4596 #               it only consist of whitespace or e.g. FIXME.
4597 # Arguments   : the doc-string
4598 #############################################################################
4599 sub IsEmptyDoc {
4600     my ($doc) = @_;
4602     if ($doc =~ /^\s*$/) {
4603         return 1;
4604     }
4606     if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
4607         return 1;
4608     }
4610     return 0;
4614 #############################################################################
4615 # Function    : ConvertMarkDown
4616 # Description : Converts mark down syntax to the respective docbook, but only
4617 #               outside CDATA and <programlisting> tags.
4618 #               http://de.wikipedia.org/wiki/Markdown
4619 #               Code snippets have been takesn from
4620 #               http://daringfireball.net/projects/markdown/
4621 #                 Copyright (c) 2004 John Gruber
4622 # Arguments   : the doc-string, the symbol name
4623 #############################################################################
4624 my $md_in_refsect2;
4625 sub ConvertMarkDown {
4626     my ($text, $symbol) = @_;
4628     # reset state
4629     $md_in_refsect2=0;
4631     # convert
4632     $text = &ModifyXMLElements ($text, $symbol,
4633                                "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
4634                                \&ConvertMarkDownEndTag,
4635                                \&ConvertMarkDownCallback);
4636     # encapsulate and terminate
4637     $text = "<para>\n$text\n</para>";
4638     if ($md_in_refsect2==1) {
4639         $text = "$text</refsect2>"
4640     }
4641     return $text
4644 sub ConvertMarkDownEndTag {
4645   if ($_[0] eq "<!\[CDATA\[") {
4646     return "]]>";
4647   } elsif ($_[0] eq "|[") {
4648     return "]\\|";
4649   } else {
4650     return "</programlisting>";
4651   }
4654 sub ConvertMarkDownCallback {
4655   my ($text, $symbol, $tag) = @_;
4657   # If we're not in CDATA or a <programlisting> we convert blank lines so
4658   # they start a new <para>.
4659   if ($tag eq "") {
4660     my $end_of_para="";
4661     my $end_of_section="";
4662     my $have_list=0;
4664     $end_of_para = "$end_of_para</para>";
4665     $end_of_section = "$end_of_section</para>";
4666     if ($md_in_refsect2==1) {
4667         $end_of_section= "$end_of_section</refsect2>";
4668     }
4670     # Setext-style headers:
4671     #          Header 1
4672     #          ========
4673     #
4674     #          Header 2
4675     #          --------
4676     #
4677     if($text =~ s%^\n(.+)[ \t]*\n=+[ \t]*\n\n%$end_of_section<refsect2><title>$1</title><para>\n%gm) {
4678         $md_in_refsect2=1;
4679     }
4681     # atx-style headers:
4682     #        # Header 1
4683     #        ## Header 2
4684     #        ## Header 2 with closing hashes ##
4685     #        ...
4686     #        ###### Header 6
4687     #
4688     if($text =~ s%^\n\#[ \t]*(.+?)[ \t]*\#\n+%$end_of_section<refsect2><title>$1</title><para>\n%gm) {
4689         $md_in_refsect2=1;
4690     }
4692     # Simple (unnested) lists:
4693     #   Please select:
4694     #   - item 1
4695     #   - item 2 with loooong
4696     #     description
4697     #   - item 3
4698     #
4699     #   New paragraph.
4700     $text.="\n"; # we need a new line to avoid too complicated matching rules below
4701     if ($text =~ s%(?<=\n)-\s+(.+?)(?=(?:\n-\s+)|(?:\n\n)|(?:\n$))%<listitem><para>$1</para></listitem>%gs) {
4702         $text =~ s%(?<!</listitem>)(\n<listitem>)%\n<itemizedlist>$1%g;
4703         $text =~ s%(</listitem>\n)(?!<listitem>)%$1</itemizedlist>\n%g;
4704     }
4705     chomp $text;
4707     # Make Paragraphs on blank lines
4708     $text =~ s%\n{2,}%\n$end_of_para\n<para>\n%g;
4709   }
4711   return $text;
4715 #############################################################################
4716 # LIBRARY FUNCTIONS -        These functions are used in both gtkdoc-mkdb and
4717 #                        gtkdoc-mktmpl and should eventually be moved to a
4718 #                        separate library.
4719 #############################################################################
4721 #############################################################################
4722 # Function    : ReadDeclarationsFile
4723 # Description : This reads in a file containing the function/macro/enum etc.
4724 #                declarations.
4726 #                Note that in some cases there are several declarations with
4727 #                the same name, e.g. for conditional macros. In this case we
4728 #                set a flag in the %DeclarationConditional hash so the
4729 #                declaration is not shown in the docs.
4731 #                If a macro and a function have the same name, e.g. for
4732 #                gtk_object_ref, the function declaration takes precedence.
4734 #                Some opaque structs are just declared with 'typedef struct
4735 #                _name name;' in which case the declaration may be empty.
4736 #                The structure may have been found later in the header, so
4737 #                that overrides the empty declaration.
4739 # Arguments   : $file - the declarations file to read
4740 #                $override - if declarations in this file should override
4741 #                        any current declaration.
4742 #############################################################################
4744 sub ReadDeclarationsFile {
4745     my ($file, $override) = @_;
4747     if ($override == 0) {
4748         %Declarations = ();
4749         %DeclarationTypes = ();
4750         %DeclarationConditional = ();
4751         %DeclarationOutput = ();
4752     }
4754     open (INPUT, $file)
4755         || die "Can't open $file: $!";
4756     my $declaration_type = "";
4757     my $declaration_name;
4758     my $declaration;
4759     my $is_deprecated = 0;
4760     while (<INPUT>) {
4761         if (!$declaration_type) {
4762             if (m/^<([^>]+)>/) {
4763                 $declaration_type = $1;
4764                 $declaration_name = "";
4765                 #print "Found declaration: $declaration_type\n";
4766                 $declaration = "";
4767             }
4768         } else {
4769             if (m%^<NAME>(.*)</NAME>%) {
4770                 $declaration_name = $1;
4771             } elsif (m%^<DEPRECATED/>%) {
4772                 $is_deprecated = 1;
4773             } elsif (m%^</$declaration_type>%) {
4774                 #print "Found end of declaration: $declaration_name\n";
4775                 # Check that the declaration has a name
4776                 if ($declaration_name eq "") {
4777                     print "ERROR: $declaration_type has no name $file:$.\n";
4778                 }
4780                 # If the declaration is an empty typedef struct _XXX XXX
4781                 # set the flag to indicate the struct has a typedef.
4782                 if ($declaration_type eq 'STRUCT'
4783                     && $declaration =~ m/^\s*$/) {
4784                     #print "Struct has typedef: $declaration_name\n";
4785                     $StructHasTypedef{$declaration_name} = 1;
4786                 }
4788                 # Check if the symbol is already defined.
4789                 if (defined ($Declarations{$declaration_name})
4790                     && $override == 0) {
4791                     # Function declarations take precedence.
4792                     if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
4793                         # Ignore it.
4794                     } elsif ($declaration_type eq 'FUNCTION') {
4795                         if ($is_deprecated) {
4796                             $Deprecated{$declaration_name} = "";
4797                         }
4798                         $Declarations{$declaration_name} = $declaration;
4799                         $DeclarationTypes{$declaration_name} = $declaration_type;
4800                     } elsif ($DeclarationTypes{$declaration_name}
4801                               eq $declaration_type) {
4802                         # If the existing declaration is empty, or is just a
4803                         # forward declaration of a struct, override it.
4804                         if ($declaration_type eq 'STRUCT') {
4805                             if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4806                                 if ($is_deprecated) {
4807                                     $Deprecated{$declaration_name} = "";
4808                                 }
4809                                 $Declarations{$declaration_name} = $declaration;
4810                             } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4811                                 # Ignore an empty or forward declaration.
4812                             } else {
4813                                 &LogWarning ($file, $., "Structure $declaration_name has multiple definitions.");
4814                             }
4815                         } else {
4816                             # set flag in %DeclarationConditional hash for
4817                             # multiply defined macros/typedefs.
4818                             $DeclarationConditional{$declaration_name} = 1;
4819                         }
4820                     } else {
4821                         &LogWarning ($file, $., "$declaration_name has multiple definitions.");
4822                     }
4823                 } else {
4824                     if ($is_deprecated) {
4825                         $Deprecated{$declaration_name} = "";
4826                     }
4827                     $Declarations{$declaration_name} = $declaration;
4828                     $DeclarationTypes{$declaration_name} = $declaration_type;
4829                 }
4831                 $declaration_type = "";
4832                 $is_deprecated = 0;
4833             } else {
4834                 $declaration .= $_;
4835             }
4836         }
4837     }
4838     close (INPUT);
4842 #############################################################################
4843 # Function    : ReadSignalsFile
4844 # Description : This reads in an existing file which contains information on
4845 #                all GTK signals. It creates the arrays @SignalNames and
4846 #                @SignalPrototypes containing info on the signals. The first
4847 #                line of the SignalPrototype is the return type of the signal
4848 #                handler. The remaining lines are the parameters passed to it.
4849 #                The last parameter, "gpointer user_data" is always the same
4850 #                so is not included.
4851 # Arguments   : $file - the file containing the signal handler prototype
4852 #                        information.
4853 #############################################################################
4855 sub ReadSignalsFile {
4856     my ($file) = @_;
4858     my $in_signal = 0;
4859     my $signal_object;
4860     my $signal_name;
4861     my $signal_returns;
4862     my $signal_flags;
4863     my $signal_prototype;
4865     # Reset the signal info.
4866     @SignalObjects = ();
4867     @SignalNames = ();
4868     @SignalReturns = ();
4869     @SignalFlags = ();
4870     @SignalPrototypes = ();
4872     if (! -f $file) {
4873         return;
4874     }
4875     if (!open (INPUT, $file)) {
4876         warn "Can't open $file - skipping signals\n";
4877         return;
4878     }
4879     while (<INPUT>) {
4880         if (!$in_signal) {
4881             if (m/^<SIGNAL>/) {
4882                 $in_signal = 1;
4883                 $signal_object = "";
4884                 $signal_name = "";
4885                 $signal_returns = "";
4886                 $signal_prototype = "";
4887             }
4888         } else {
4889             if (m/^<NAME>(.*)<\/NAME>/) {
4890                 $signal_name = $1;
4891                 if ($signal_name =~ m/^(.*)::(.*)$/) {
4892                     $signal_object = $1;
4893                     ($signal_name = $2) =~ s/_/-/g;
4894                     #print "Found signal: $signal_name\n";
4895                 } else {
4896                     &LogWarning ($file, $., "Invalid signal name: $signal_name.");
4897                 }
4898             } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
4899                 $signal_returns = $1;
4900             } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4901                 $signal_flags = $1;
4902             } elsif (m%^</SIGNAL>%) {
4903                 #print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
4904                 push (@SignalObjects, $signal_object);
4905                 push (@SignalNames, $signal_name);
4906                 push (@SignalReturns, $signal_returns);
4907                 push (@SignalFlags, $signal_flags);
4908                 push (@SignalPrototypes, $signal_prototype);
4909                 $in_signal = 0;
4910             } else {
4911                 $signal_prototype .= $_;
4912             }
4913         }
4914     }
4915     close (INPUT);
4919 #############################################################################
4920 # Function    : ReadTemplateFile
4921 # Description : This reads in the manually-edited documentation file
4922 #                corresponding to the file currently being created, so we can
4923 #                insert the documentation at the appropriate places.
4924 #                It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
4925 #                is a hash of arrays.
4926 #                NOTE: This function is duplicated in gtkdoc-mktmpl (but
4927 #                slightly different).
4928 # Arguments   : $docsfile - the template file to read in.
4929 #                $skip_unused_params - 1 if the unused parameters should be
4930 #                        skipped.
4931 #############################################################################
4933 sub ReadTemplateFile {
4934     my ($docsfile, $skip_unused_params) = @_;
4936     my $template = "$docsfile.sgml";
4937     if (! -f $template) {
4938         #print "File doesn't exist: $template\n";
4939         return 0;
4940     }
4941     #print "Reading $template\n";
4943     # start with empty hashes, we merge the source comment for each file
4944     # afterwards
4945     %SymbolDocs = ();
4946     %SymbolTypes = ();
4947     %SymbolParams = ();
4949     my $current_type = "";        # Type of symbol being read.
4950     my $current_symbol = "";        # Name of symbol being read.
4951     my $symbol_doc = "";                # Description of symbol being read.
4952     my @params;                        # Parameter names and descriptions of current
4953                                 #   function/macro/function typedef.
4954     my $current_param = -1;        # Index of parameter currently being read.
4955                                 #   Note that the param array contains pairs
4956                                 #   of param name & description.
4957     my $in_unused_params = 0;        # True if we are reading in the unused params.
4958     my $in_deprecated = 0;
4959     my $in_since = 0;
4960     my $in_stability = 0;
4962     open (DOCS, "$template")
4963         || die "Can't open $template: $!";
4964     while (<DOCS>) {
4965         if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
4966             my $type = $1;
4967             my $symbol = $2;
4968             if ($symbol eq "Title"
4969                 || $symbol eq "Short_Description"
4970                 || $symbol eq "Long_Description"
4971                 || $symbol eq "See_Also"
4972                 || $symbol eq "Stability_Level"
4973                 || $symbol eq "Include"
4974                 || $symbol eq "Image") {
4976                 $symbol = $docsfile . ":" . $symbol;
4977             }
4979             #print "Found symbol: $symbol\n";
4980             # Remember file and line for the symbol
4981             $SymbolSourceFile{$symbol} = $template;
4982             $SymbolSourceLine{$symbol} = $.;
4984             # Store previous symbol, but remove any trailing blank lines.
4985             if ($current_symbol ne "") {
4986                 $symbol_doc =~ s/\s+$//;
4987                 $SymbolTypes{$current_symbol} = $current_type;
4988                 $SymbolDocs{$current_symbol} = $symbol_doc;
4990                 # Check that the stability level is valid.
4991                 if ($StabilityLevel{$current_symbol}) {
4992                     $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4993                 }
4995                 if ($current_param >= 0) {
4996                     $SymbolParams{$current_symbol} = [ @params ];
4997                 } else {
4998                     # Delete any existing params in case we are overriding a
4999                     # previously read template.
5000                     delete $SymbolParams{$current_symbol};
5001                 }
5002             }
5003             $current_type = $type;
5004             $current_symbol = $symbol;
5005             $current_param = -1;
5006             $in_unused_params = 0;
5007             $in_deprecated = 0;
5008             $in_since = 0;
5009             $in_stability = 0;
5010             $symbol_doc = "";
5011             @params = ();
5013         } elsif (m/^<!-- # Unused Parameters # -->/) {
5014             #print "DEBUG: Found unused parameters\n";
5015             $in_unused_params = 1;
5016             next;
5018         } elsif ($in_unused_params && $skip_unused_params) {
5019             # When outputting the DocBook we skip unused parameters.
5020             #print "DEBUG: Skipping unused param: $_";
5021             next;
5023         } else {
5024             # Check if param found. Need to handle "..." and "format...".
5025             if (s/^\@([\w\.]+):\040?//) {
5026                 my $param_name = $1;
5027                 my $param_desc = $_;
5028                 # Allow variations of 'Returns'
5029                 if ($param_name =~ m/^[Rr]eturns?$/) {
5030                     $param_name = "Returns";
5031                 }
5033                 # strip trailing whitespaces and blank lines
5034                 s/\s+\n$/\n/m;
5035                 s/\n+$/\n/sm;
5036                 #print "Found param for symbol $current_symbol : '$param_name'= '$_'";
5038                 if ($param_name eq "Deprecated") {
5039                     $in_deprecated = 1;
5040                     $Deprecated{$current_symbol} = $_;
5041                 } elsif ($param_name eq "Since") {
5042                     $in_since = 1;
5043                     chomp;
5044                     $Since{$current_symbol} = $_;
5045                 } elsif ($param_name eq "Stability") {
5046                     $in_stability = 1;
5047                     $StabilityLevel{$current_symbol} = $_;
5048                 } else {
5049                     push (@params, $param_name);
5050                     push (@params, $param_desc);
5051                     $current_param += $PARAM_FIELD_COUNT;
5052                 }
5053             } else {
5054                 # strip trailing whitespaces and blank lines
5055                 s/\s+\n$/\n/m;
5056                 s/\n+$/\n/sm;
5058                 if (!m/^\s+$/) {
5059                     if ($in_deprecated) {
5060                         $Deprecated{$current_symbol} .= $_;
5061                     } elsif ($in_since) {
5062                         &LogWarning ($template, $., "multi-line since docs found");
5063                         #$Since{$current_symbol} .= $_;
5064                     } elsif ($in_stability) {
5065                         $StabilityLevel{$current_symbol} .= $_;
5066                     } elsif ($current_param >= 0) {
5067                         $params[$current_param] .= $_;
5068                     } else {
5069                         $symbol_doc .= $_;
5070                     }
5071                 }
5072             }
5073         }
5074     }
5076     # Remember to finish the current symbol doccs.
5077     if ($current_symbol ne "") {
5079         $symbol_doc =~ s/\s+$//;
5080         $SymbolTypes{$current_symbol} = $current_type;
5081         $SymbolDocs{$current_symbol} = $symbol_doc;
5083         # Check that the stability level is valid.
5084         if ($StabilityLevel{$current_symbol}) {
5085             $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
5086         }
5088         if ($current_param >= 0) {
5089             $SymbolParams{$current_symbol} = [ @params ];
5090         } else {
5091             # Delete any existing params in case we are overriding a
5092             # previously read template.
5093             delete $SymbolParams{$current_symbol};
5094         }
5095     }
5097     close (DOCS);
5098     return 1;
5102 #############################################################################
5103 # Function    : ReadObjectHierarchy
5104 # Description : This reads in the $MODULE-hierarchy.txt file containing all
5105 #                the GtkObject subclasses described in this module (and their
5106 #                ancestors).
5107 #                It places them in the @Objects array, and places their level
5108 #                in the object hierarchy in the @ObjectLevels array, at the
5109 #                same index. GtkObject, the root object, has a level of 1.
5111 #               FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
5112 #               as it goes along, this should be split out into a separate
5113 #               function.
5115 # Arguments   : none
5116 #############################################################################
5118 sub ReadObjectHierarchy {
5119     @Objects = ();
5120     @ObjectLevels = ();
5122     if (! -f $OBJECT_TREE_FILE) {
5123         return;
5124     }
5125     if (!open (INPUT, $OBJECT_TREE_FILE)) {
5126         warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
5127         return;
5128     }
5130     # FIXME: use $OUTPUT_FORMAT
5131     # my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.$OUTPUT_FORMAT";
5132     my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
5133     my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
5135     open (OUTPUT, ">$new_tree_index")
5136         || die "Can't create $new_tree_index: $!";
5138     if ($OUTPUT_FORMAT eq "xml") {
5139         my $tree_header = $doctype_header;
5141         $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
5142         print (OUTPUT "$tree_header");
5143     }
5144     print (OUTPUT "<screen>\n");
5146     # Only emit objects if they are supposed to be documented, or if
5147     # they have documented children. To implement this, we maintain a
5148     # stack of pending objects which will be emitted if a documented
5149     # child turns up.
5150     my @pending_objects = ();
5151     my @pending_levels = ();
5152     while (<INPUT>) {
5153         if (m/\S+/) {
5154             my $object = $&;
5155             my $level = (length($`)) / 2 + 1;
5156             my $xref = "";
5158             while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
5159                 my $pobject = pop(@pending_objects);
5160                 my $plevel = pop(@pending_levels);
5161             }
5163                push (@pending_objects, $object);
5164             push (@pending_levels, $level);
5166             if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5167                    while ($#pending_levels >= 0) {
5168                     $object = shift @pending_objects;
5169                     $level = shift @pending_levels;
5170                        $xref = &MakeXRef ($object);
5172                      print (OUTPUT ' ' x ($level * 4), "$xref\n");
5173                     push (@Objects, $object);
5174                     push (@ObjectLevels, $level);
5175                 }
5176             }
5177             #else {
5178             #    LogWarning ($OBJECT_TREE_FILE, $., "unknown type $object");
5179             #}
5180         }
5181     }
5182     print (OUTPUT "</screen>\n");
5184     close (INPUT);
5185     close (OUTPUT);
5187     &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
5189     &OutputObjectList;
5192 #############################################################################
5193 # Function    : ReadInterfaces
5194 # Description : This reads in the $MODULE.interfaces file.
5196 # Arguments   : none
5197 #############################################################################
5199 sub ReadInterfaces {
5200     %Interfaces = ();
5202     if (! -f $INTERFACES_FILE) {
5203         return;
5204     }
5205     if (!open (INPUT, $INTERFACES_FILE)) {
5206         warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
5207         return;
5208     }
5210     while (<INPUT>) {
5211        chomp;
5212        my ($object, @ifaces) = split;
5213        if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5214            my @knownIfaces = ();
5216            # filter out private interfaces, but leave foreign interfaces
5217            foreach my $iface (@ifaces) {
5218                if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
5219                    push (@knownIfaces, $iface);
5220                }
5221              }
5223            $Interfaces{$object} = join(' ', @knownIfaces);
5224        }
5225     }
5226     close (INPUT);
5229 #############################################################################
5230 # Function    : ReadPrerequisites
5231 # Description : This reads in the $MODULE.prerequisites file.
5233 # Arguments   : none
5234 #############################################################################
5236 sub ReadPrerequisites {
5237     %Prerequisites = ();
5239     if (! -f $PREREQUISITES_FILE) {
5240         return;
5241     }
5242     if (!open (INPUT, $PREREQUISITES_FILE)) {
5243         warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
5244         return;
5245     }
5247     while (<INPUT>) {
5248        chomp;
5249        my ($iface, @prereqs) = split;
5250        if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
5251            my @knownPrereqs = ();
5253            # filter out private prerequisites, but leave foreign prerequisites
5254            foreach my $prereq (@prereqs) {
5255                if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
5256                   push (@knownPrereqs, $prereq);
5257                }
5258            }
5260            $Prerequisites{$iface} = join(' ', @knownPrereqs);
5261        }
5262     }
5263     close (INPUT);
5266 #############################################################################
5267 # Function    : ReadArgsFile
5268 # Description : This reads in an existing file which contains information on
5269 #                all GTK args. It creates the arrays @ArgObjects, @ArgNames,
5270 #                @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
5271 #               on the args.
5272 # Arguments   : $file - the file containing the arg information.
5273 #############################################################################
5275 sub ReadArgsFile {
5276     my ($file) = @_;
5278     my $in_arg = 0;
5279     my $arg_object;
5280     my $arg_name;
5281     my $arg_type;
5282     my $arg_flags;
5283     my $arg_nick;
5284     my $arg_blurb;
5285     my $arg_default;
5286     my $arg_range;
5288     # Reset the args info.
5289     @ArgObjects = ();
5290     @ArgNames = ();
5291     @ArgTypes = ();
5292     @ArgFlags = ();
5293     @ArgNicks = ();
5294     @ArgBlurbs = ();
5295     @ArgDefaults = ();
5296     @ArgRanges = ();
5298     if (! -f $file) {
5299         return;
5300     }
5301     if (!open (INPUT, $file)) {
5302         warn "Can't open $file - skipping args\n";
5303         return;
5304     }
5305     while (<INPUT>) {
5306         if (!$in_arg) {
5307             if (m/^<ARG>/) {
5308                 $in_arg = 1;
5309                 $arg_object = "";
5310                 $arg_name = "";
5311                 $arg_type = "";
5312                 $arg_flags = "";
5313                 $arg_nick = "";
5314                 $arg_blurb = "";
5315                 $arg_default = "";
5316                 $arg_range = "";
5317             }
5318         } else {
5319             if (m/^<NAME>(.*)<\/NAME>/) {
5320                 $arg_name = $1;
5321                 if ($arg_name =~ m/^(.*)::(.*)$/) {
5322                     $arg_object = $1;
5323                     ($arg_name = $2) =~ s/_/-/g;
5324                     #print "Found arg: $arg_name\n";
5325                 } else {
5326                     &LogWarning ($file, $., "Invalid argument name: $arg_name");
5327                 }
5328             } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
5329                 $arg_type = $1;
5330             } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
5331                 $arg_range = $1;
5332             } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
5333                 $arg_flags = $1;
5334             } elsif (m/^<NICK>(.*)<\/NICK>/) {
5335                 $arg_nick = $1;
5336             } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
5337                 $arg_blurb = $1;
5338                 if ($arg_blurb eq "(null)") {
5339                   $arg_blurb = "";
5340                   &LogWarning ($file, $., "Property ${arg_object}:${arg_name} has no documentation.");
5341                 }
5342             } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
5343                 $arg_default = $1;
5344             } elsif (m%^</ARG>%) {
5345                 #print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
5346                 push (@ArgObjects, $arg_object);
5347                 push (@ArgNames, $arg_name);
5348                 push (@ArgTypes, $arg_type);
5349                 push (@ArgRanges, $arg_range);
5350                 push (@ArgFlags, $arg_flags);
5351                 push (@ArgNicks, $arg_nick);
5352                 push (@ArgBlurbs, $arg_blurb);
5353                 push (@ArgDefaults, $arg_default);
5354                 $in_arg = 0;
5355             }
5356         }
5357     }
5358     close (INPUT);
5362 #############################################################################
5363 # Function    : CheckIsObject
5364 # Description : Returns 1 if the given name is a GObject or a subclass.
5365 #                It uses the global @Objects array.
5366 #                Note that the @Objects array only contains classes in the
5367 #                current module and their ancestors - not all GObject classes.
5368 # Arguments   : $name - the name to check.
5369 #############################################################################
5371 sub CheckIsObject {
5372     my ($name) = @_;
5374     my $object;
5375     foreach $object (@Objects) {
5376         if ($object eq $name) {
5377             return 1;
5378         }
5379     }
5380     return 0;
5384 #############################################################################
5385 # Function    : MakeReturnField
5386 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
5387 # Arguments   : $str - the string to pad.
5388 #############################################################################
5390 sub MakeReturnField {
5391     my ($str) = @_;
5393     return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));
5396 #############################################################################
5397 # Function    : GetSymbolSourceFile
5398 # Description : Get the filename where the symbol docs where taken from.
5399 # Arguments   : $symbol - the symbol name
5400 #############################################################################
5402 sub GetSymbolSourceFile {
5403     my ($symbol) = @_;
5405     if (defined($SourceSymbolSourceFile{$symbol})) {
5406         return $SourceSymbolSourceFile{$symbol};
5407     } elsif (defined($SymbolSourceFile{$symbol})) {
5408         return $SymbolSourceFile{$symbol};
5409     } else {
5410         return "";
5411     }
5414 #############################################################################
5415 # Function    : GetSymbolSourceLine
5416 # Description : Get the file line where the symbol docs where taken from.
5417 # Arguments   : $symbol - the symbol name
5418 #############################################################################
5420 sub GetSymbolSourceLine {
5421     my ($symbol) = @_;
5423     if (defined($SourceSymbolSourceLine{$symbol})) {
5424         return $SourceSymbolSourceLine{$symbol};
5425     } elsif (defined($SymbolSourceLine{$symbol})) {
5426         return $SymbolSourceLine{$symbol};
5427     } else {
5428         return 0;
5429     }