scan: add one more trace statement
[gtk-doc.git] / gtkdoc-mkdb.in
blob86326307cd8c246cf29db8dc624e5b680edca754
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_object_struct = 0;
1443     my $default_to_public = 1;
1444     if (&CheckIsObject ($symbol)) {
1445         #print "Found object struct: $symbol\n";
1446         $is_object_struct = 1;
1447         $default_to_public = 0;
1448     }
1450     my $id;
1451     my $condition;
1452     if ($is_object_struct) {
1453         $id = &CreateValidSGMLID ($symbol . "_struct");
1454         $condition = &MakeConditionDescription ($symbol . "_struct");
1455     } else {
1456         $id = &CreateValidSGMLID ($symbol);
1457         $condition = &MakeConditionDescription ($symbol);
1458     }
1460     # Determine if it is a simple struct or it also has a typedef.
1461     my $has_typedef = 0;
1462     if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1463       $has_typedef = 1;
1464     }
1466     my $synop;
1467     my $desc;
1468     if ($has_typedef) {
1469         # For structs with typedefs we just output the struct name.
1470         $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1471         $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>$symbol</title>\n";
1472     } else {
1473         $synop = &MakeReturnField("struct") . "<link linkend=\"$id\">$symbol</link>;\n";
1474         $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>struct $symbol</title>\n";
1475     }
1477     $desc .= MakeIndexterms($symbol, $id);
1478     $desc .= "\n";
1479     $desc .= OutputSymbolExtraLinks($symbol);
1481     # Form a pretty-printed, private-data-removed form of the declaration
1483     my $decl_out = "";
1484     if ($declaration =~ m/^\s*$/) {
1485         #print "Found opaque struct: $symbol\n";
1486         $decl_out = "typedef struct _$symbol $symbol;";
1487     } elsif ($declaration =~ m/^\s*struct\s+\w+\s*;\s*$/) {
1488         #print "Found opaque struct: $symbol\n";
1489         $decl_out = "struct $symbol;";
1490     } else {
1491         my $public = $default_to_public;
1492         my $new_declaration = "";
1493         my $decl_line;
1494         my $decl = $declaration;
1496         if ($decl =~ m/^\s*(typedef\s+)?struct\s*\w*\s*(?:\/\*.*\*\/)?\s*{(.*)}\s*\w*\s*;\s*$/s) {
1497             my $struct_contents = $2;
1499             foreach $decl_line (split (/\n/, $struct_contents)) {
1500                 #print "Struct line: $decl_line\n";
1501                 if ($decl_line =~ m%/\*\s*<\s*public\s*>\s*\*/%) {
1502                     $public = 1;
1503                 } elsif ($decl_line =~ m%/\*\s*<\s*(private|protected)\s*>\s*\*/%) {
1504                     $public = 0;
1505                 } elsif ($public) {
1506                     $new_declaration .= $decl_line . "\n";
1507                 }
1508             }
1510             if ($new_declaration) {
1511                 # Strip any blank lines off the ends.
1512                 $new_declaration =~ s/^\s*\n//;
1513                 $new_declaration =~ s/\n\s*$/\n/;
1515                 if ($has_typedef) {
1516                     $decl_out = "typedef struct {\n" . $new_declaration
1517                       . "} $symbol;\n";
1518                 } else {
1519                     $decl_out = "struct $symbol {\n" . $new_declaration
1520                       . "};\n";
1521                 }
1522             }
1523         } else {
1524             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1525                 "Couldn't parse struct:\n$declaration");
1526         }
1528         # If we couldn't parse the struct or it was all private, output an
1529         # empty struct declaration.
1530         if ($decl_out eq "") {
1531             if ($has_typedef) {
1532                 $decl_out = "typedef struct _$symbol $symbol;";
1533             } else {
1534                 $decl_out = "struct $symbol;";
1535             }
1536         }
1537     }
1539     $decl_out = &CreateValidSGML ($decl_out);
1540     $desc .= "<programlisting>$decl_out</programlisting>\n";
1542     $desc .= &MakeDeprecationNote($symbol);
1544     if (defined ($SymbolDocs{$symbol})) {
1545         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1546     }
1548     # Create a table of fields and descriptions
1550     # FIXME: Inserting &#160's into the produced type declarations here would
1551     #        improve the output in most situations ... except for function
1552     #        members of structs!
1553     my @fields = ParseStructDeclaration($declaration, !$default_to_public,
1554                                         0, \&MakeXRef,
1555                                         sub {
1556                                             "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1557                                         });
1558     my $params = $SymbolParams{$symbol};
1560     # If no parameters are filled in, we don't generate the description
1561     # table, for backwards compatibility
1563     my $found = 0;
1564     if (defined $params) {
1565         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1566             if ($params->[$i] =~ /\S/) {
1567                 $found = 1;
1568                 last;
1569             }
1570         }
1571     }
1573     if ($found) {
1574         my %field_descrs = @$params;
1575         my $missing_parameters = "";
1576         my $unused_parameters = "";
1578         $desc .= "<variablelist role=\"struct\">\n";
1579         while (@fields) {
1580             my $field_name = shift @fields;
1581             my $text = shift @fields;
1582             my $field_descr = $field_descrs{$field_name};
1583             my $param_annotations = "";
1585             $desc .= "<varlistentry><term>$text</term>\n";
1586             if (defined $field_descr) {
1587                 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1588                 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1589                 $field_descr .= $param_annotations;
1590                 # trim
1591                 $field_descr =~ s/^(\s|\n)+//msg;
1592                 $field_descr =~ s/(\s|\n)+$//msg;
1593                 $desc .= "<listitem><simpara>$field_descr</simpara></listitem>\n";
1594                 delete $field_descrs{$field_name};
1595             } else {
1596                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1597                     "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1598                 if ($missing_parameters ne "") {
1599                   $missing_parameters .= ", ".$field_name;
1600                 } else {
1601                     $missing_parameters = $field_name;
1602                 }
1603                 $desc .= "<listitem />\n";
1604             }
1605             $desc .= "</varlistentry>\n";
1606         }
1607         $desc .= "</variablelist>";
1608         foreach my $field_name (keys %field_descrs) {
1609             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1610                 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1611             if ($unused_parameters ne "") {
1612               $unused_parameters .= ", ".$field_name;
1613             } else {
1614                $unused_parameters = $field_name;
1615             }
1616         }
1618         # remember missing/unused parameters (needed in tmpl-free build)
1619         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1620             $AllIncompleteSymbols{$symbol}=$missing_parameters;
1621         }
1622         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1623             $AllUnusedSymbols{$symbol}=$unused_parameters;
1624         }
1625     }
1626     else {
1627         if (scalar(@fields) > 0) {
1628             if (! exists ($AllIncompleteSymbols{$symbol})) {
1629                 $AllIncompleteSymbols{$symbol}="<items>";
1630                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1631                     "Field descriptions for $symbol are missing in source code comment block.");
1632             }
1633         }
1634     }
1636     $desc .= OutputSymbolTraits ($symbol);
1637     $desc .= "</refsect2>\n";
1638     return ($synop, $desc);
1642 #############################################################################
1643 # Function    : OutputUnion
1644 # Description : Returns the synopsis and detailed description of a union.
1645 # Arguments   : $symbol - the union.
1646 #               $declaration - the declaration of the union.
1647 #############################################################################
1649 sub OutputUnion {
1650     my ($symbol, $declaration) = @_;
1651     my $id = &CreateValidSGMLID ($symbol);
1652     my $condition = &MakeConditionDescription ($symbol);
1654     # Determine if it is a simple struct or it also has a typedef.
1655     my $has_typedef = 0;
1656     if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1657       $has_typedef = 1;
1658     }
1660     my $synop;
1661     my $desc;
1662     if ($has_typedef) {
1663         # For unions with typedefs we just output the union name.
1664         $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1665         $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>$symbol</title>\n";
1666     } else {
1667         $synop = &MakeReturnField("union") . "<link linkend=\"$id\">$symbol</link>;\n";
1668         $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>union $symbol</title>\n";
1669     }
1671     $desc .= MakeIndexterms($symbol, $id);
1672     $desc .= "\n";
1673     $desc .= OutputSymbolExtraLinks($symbol);
1675     # FIXME: we do more for structs
1676     my $decl_out = &CreateValidSGML ($declaration);
1677     $desc .= "<programlisting>$decl_out</programlisting>\n";
1679     $desc .= &MakeDeprecationNote($symbol);
1681     if (defined ($SymbolDocs{$symbol})) {
1682         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1683     }
1685     # Create a table of fields and descriptions
1687     # FIXME: Inserting &#160's into the produced type declarations here would
1688     #        improve the output in most situations ... except for function
1689     #        members of structs!
1690     my @fields = ParseStructDeclaration($declaration, 0,
1691                                         0, \&MakeXRef,
1692                                         sub {
1693                                             "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1694                                         });
1695     my $params = $SymbolParams{$symbol};
1697     # If no parameters are filled in, we don't generate the description
1698     # table, for backwards compatibility
1700     my $found = 0;
1701     if (defined $params) {
1702         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1703             if ($params->[$i] =~ /\S/) {
1704                 $found = 1;
1705                 last;
1706             }
1707         }
1708     }
1710     if ($found) {
1711         my %field_descrs = @$params;
1712         my $missing_parameters = "";
1713         my $unused_parameters = "";
1715         $desc .= "<variablelist role=\"union\">\n";
1716         while (@fields) {
1717             my $field_name = shift @fields;
1718             my $text = shift @fields;
1719             my $field_descr = $field_descrs{$field_name};
1720             my $param_annotations = "";
1722             $desc .= "<varlistentry><term>$text</term>\n";
1723             if (defined $field_descr) {
1724                 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1725                 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1726                 $field_descr .= $param_annotations;
1727                 # trim
1728                 $field_descr =~ s/^(\s|\n)+//msg;
1729                 $field_descr =~ s/(\s|\n)+$//msg;
1730                 $desc .= "<listitem><simpara>$field_descr</simpara></listitem>\n";
1731                 delete $field_descrs{$field_name};
1732             } else {
1733                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1734                     "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1735                 if ($missing_parameters ne "") {
1736                     $missing_parameters .= ", ".$field_name;
1737                 } else {
1738                     $missing_parameters = $field_name;
1739                 }
1740                 $desc .= "<listitem />\n";
1741             }
1742             $desc .= "</varlistentry>\n";
1743         }
1744         $desc .= "</variablelist>";
1745         foreach my $field_name (keys %field_descrs) {
1746             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1747                 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1748             if ($unused_parameters ne "") {
1749               $unused_parameters .= ", ".$field_name;
1750             } else {
1751                $unused_parameters = $field_name;
1752             }
1753         }
1755         # remember missing/unused parameters (needed in tmpl-free build)
1756         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1757             $AllIncompleteSymbols{$symbol}=$missing_parameters;
1758         }
1759         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1760             $AllUnusedSymbols{$symbol}=$unused_parameters;
1761         }
1762     }
1763     else {
1764         if (scalar(@fields) > 0) {
1765             if (! exists ($AllIncompleteSymbols{$symbol})) {
1766                 $AllIncompleteSymbols{$symbol}="<items>";
1767                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1768                     "Field descriptions for $symbol are missing in source code comment block.");
1769             }
1770         }
1771     }
1773     $desc .= OutputSymbolTraits ($symbol);
1774     $desc .= "</refsect2>\n";
1775     return ($synop, $desc);
1779 #############################################################################
1780 # Function    : OutputEnum
1781 # Description : Returns the synopsis and detailed description of a enum.
1782 # Arguments   : $symbol - the enum.
1783 #               $declaration - the declaration of the enum.
1784 #############################################################################
1786 sub OutputEnum {
1787     my ($symbol, $declaration) = @_;
1788     my $id = &CreateValidSGMLID ($symbol);
1789     my $condition = &MakeConditionDescription ($symbol);
1790     my $synop = &MakeReturnField("enum") . "<link linkend=\"$id\">$symbol</link>;\n";
1791     my $desc = "<refsect2 id=\"$id\" role=\"enum\"$condition>\n<title>enum $symbol</title>\n";
1793     $desc .= MakeIndexterms($symbol, $id);
1794     $desc .= "\n";
1795     $desc .= OutputSymbolExtraLinks($symbol);
1797     my $decl_out = &CreateValidSGML ($declaration);
1798     $desc .= "<programlisting>$decl_out</programlisting>\n";
1800     $desc .= &MakeDeprecationNote($symbol);
1802     if (defined ($SymbolDocs{$symbol})) {
1803         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1804     }
1806     # Create a table of fields and descriptions
1808     my @fields = ParseEnumDeclaration($declaration);
1809     my $params = $SymbolParams{$symbol};
1811     # If no parameters are filled in, we don't generate the description
1812     # table, for backwards compatibility
1814     my $found = 0;
1815     if (defined $params) {
1816         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1817             if ($params->[$i] =~ /\S/) {
1818                 $found = 1;
1819                 last;
1820             }
1821         }
1822     }
1824     if ($found) {
1825         my %field_descrs = @$params;
1826         my $missing_parameters = "";
1827         my $unused_parameters = "";
1829         $desc .= "<variablelist role=\"enum\">\n";
1830         for my $field_name (@fields) {
1831             my $field_descr = $field_descrs{$field_name};
1832             my $param_annotations = "";
1834             $id = &CreateValidSGMLID ($field_name);
1835             $condition = &MakeConditionDescription ($field_name);
1836             $desc .= "<varlistentry id=\"$id\" role=\"constant\"$condition>\n<term><literal>$field_name</literal></term>\n";
1837             if (defined $field_descr) {
1838                 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1839                 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1840                 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1841                 delete $field_descrs{$field_name};
1842             } else {
1843                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1844                     "Value description for $symbol"."::"."$field_name is missing in source code comment block.");
1845                 if ($missing_parameters ne "") {
1846                   $missing_parameters .= ", ".$field_name;
1847                 } else {
1848                     $missing_parameters = $field_name;
1849                 }
1850                 $desc .= "<listitem />\n";
1851             }
1852             $desc .= "</varlistentry>\n";
1853         }
1854         $desc .= "</variablelist>";
1855         foreach my $field_name (keys %field_descrs) {
1856             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1857                 "Value description for $symbol"."::"."$field_name is not used from source code comment block.");
1858             if ($unused_parameters ne "") {
1859               $unused_parameters .= ", ".$field_name;
1860             } else {
1861                $unused_parameters = $field_name;
1862             }
1863         }
1865         # remember missing/unused parameters (needed in tmpl-free build)
1866         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1867             $AllIncompleteSymbols{$symbol}=$missing_parameters;
1868         }
1869         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1870             $AllUnusedSymbols{$symbol}=$unused_parameters;
1871         }
1872     }
1873     else {
1874         if (scalar(@fields) > 0) {
1875             if (! exists ($AllIncompleteSymbols{$symbol})) {
1876                 $AllIncompleteSymbols{$symbol}="<items>";
1877                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1878                     "Value descriptions for $symbol are missing in source code comment block.");
1879             }
1880         }
1881     }
1883     $desc .= OutputSymbolTraits ($symbol);
1884     $desc .= "</refsect2>\n";
1885     return ($synop, $desc);
1889 #############################################################################
1890 # Function    : OutputVariable
1891 # Description : Returns the synopsis and detailed description of a variable.
1892 # Arguments   : $symbol - the extern'ed variable.
1893 #               $declaration - the declaration of the variable.
1894 #############################################################################
1896 sub OutputVariable {
1897     my ($symbol, $declaration) = @_;
1898     my $id = &CreateValidSGMLID ($symbol);
1899     my $condition = &MakeConditionDescription ($symbol);
1901     my $synop;
1902     if ($declaration =~ m/^\s*extern\s+((const\s+|signed\s+|unsigned\s+)*\w+)(\s+\*+|\*+|\s)(\s*)([A-Za-z]\w*)\s*;/) {
1903         my $mod = defined ($1) ? $1 : "";
1904         my $ptr = defined ($3) ? $3 : "";
1905         my $space = defined ($4) ? $4 : "";
1906         $synop = &MakeReturnField("extern") . "$mod$ptr$space<link linkend=\"$id\">$symbol</link>;\n";
1908     } else {
1909         $synop = &MakeReturnField("extern") . "<link linkend=\"$id\">$symbol</link>;\n";
1910     }
1912     my $desc = "<refsect2 id=\"$id\" role=\"variable\"$condition>\n<title>$symbol</title>\n";
1914     $desc .= MakeIndexterms($symbol, $id);
1915     $desc .= "\n";
1916     $desc .= OutputSymbolExtraLinks($symbol);
1918     my $decl_out = &CreateValidSGML ($declaration);
1919     $desc .= "<programlisting>$decl_out</programlisting>\n";
1921     $desc .= &MakeDeprecationNote($symbol);
1923     if (defined ($SymbolDocs{$symbol})) {
1924         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1925     }
1926     $desc .= OutputSymbolTraits ($symbol);
1927     $desc .= "</refsect2>\n";
1928     return ($synop, $desc);
1932 #############################################################################
1933 # Function    : OutputFunction
1934 # Description : Returns the synopsis and detailed description of a function.
1935 # Arguments   : $symbol - the function.
1936 #               $declaration - the declaration of the function.
1937 #############################################################################
1939 sub OutputFunction {
1940     my ($symbol, $declaration, $symbol_type) = @_;
1941     my $id = &CreateValidSGMLID ($symbol);
1942     my $condition = &MakeConditionDescription ($symbol);
1944     # Take out the return type     $1                                                                                     $3   $4
1945     $declaration =~ s/<RETURNS>\s*((const\s+|G_CONST_RETURN\s+|signed\s+|unsigned\s+|long\s+|short\s+|struct\s+|enum\s+)*)(\w+)(\s*\**\s*(const|G_CONST_RETURN)?\s*\**\s*(restrict)?\s*)<\/RETURNS>\n//;
1946     my $type_modifier = defined($1) ? $1 : "";
1947     my $type = $3;
1948     my $pointer = $4;
1949     #print "$symbol pointer is $pointer\n";
1950     my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1951     my $start = "";
1952     #if ($symbol_type eq 'USER_FUNCTION') {
1953     #    $start = "typedef ";
1954     #}
1956     # We output const rather than G_CONST_RETURN.
1957     $type_modifier =~ s/G_CONST_RETURN/const/g;
1958     $pointer =~ s/G_CONST_RETURN/const/g;
1959     $pointer =~ s/^\s+/ /g;
1961     my $ret_type_len = length ($start) + length ($type_modifier)
1962         + length ($pointer) + length ($type);
1963     my $ret_type_output;
1964     my $symbol_len;
1965     if ($ret_type_len < $RETURN_TYPE_FIELD_WIDTH) {
1966         $ret_type_output = "$start$type_modifier$xref$pointer"
1967             . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
1968         $symbol_len = 0;
1969     } else {
1970         #$ret_type_output = "$start$type_modifier$xref$pointer\n" . (' ' x $RETURN_TYPE_FIELD_WIDTH);
1972         $ret_type_output = "$start$type_modifier$xref$pointer ";
1973         $symbol_len = $ret_type_len + 1 - $RETURN_TYPE_FIELD_WIDTH;
1974     }
1976     $symbol_len += length ($symbol);
1977     my $char1 = my $char2 = my $char3 = "";
1978     if ($symbol_type eq 'USER_FUNCTION') {
1979         $symbol_len += 3;
1980         $char1 = "(";
1981         $char2 = "*";
1982         $char3 = ")";
1983     }
1985     my ($symbol_output, $symbol_desc_output);
1986     if ($symbol_len < $SYMBOL_FIELD_WIDTH) {
1987         $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3"
1988             . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1989         $symbol_desc_output = "$char1$char2$symbol$char3"
1990             . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1991     } else {
1992         $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3\n"
1993             . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1994         $symbol_desc_output = "$char1$char2$symbol$char3\n"
1995             . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1996     }
1998     my $synop = $ret_type_output . $symbol_output . '(';
1999     my $desc = "<refsect2 id=\"$id\" role=\"function\"$condition>\n<title>${symbol} ()</title>\n";
2001     $desc .= MakeIndexterms($symbol, $id);
2002     $desc .= "\n";
2003     $desc .= OutputSymbolExtraLinks($symbol);
2005     $desc  .= "<programlisting>${ret_type_output}$symbol_desc_output(";
2007     my @fields = ParseFunctionDeclaration($declaration, \&MakeXRef,
2008                                         sub {
2009                                             &tagify($_[0],"parameter");
2010                                         });
2012     for (my $i = 1; $i <= $#fields; $i += 2) {
2013         my $field_name = $fields[$i];
2015         if ($field_name eq "Varargs") {
2016             $field_name = "...";
2017         }
2019         if ($i == 1) {
2020             $synop .= "$field_name";
2021             $desc  .= "$field_name";
2022         } else {
2023             $synop .= ",\n"
2024                 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2025                 . " $field_name";
2026             $desc  .= ",\n"
2027                 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2028                 . " $field_name";
2029         }
2031     }
2033     $synop .= ");\n";
2034     $desc  .= ");</programlisting>\n";
2036     $desc .= &MakeDeprecationNote($symbol);
2038     my $parameters = &OutputParamDescriptions ("FUNCTION", $symbol, @fields);
2039     my $parameters_output = 0;
2041     if (defined ($SymbolDocs{$symbol})) {
2042         my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
2044         # Try to insert the parameter table at the author's desired position.
2045         # Otherwise we need to tag it onto the end.
2046         # FIXME: document that in the user manual and make it useable for other
2047         # types too
2048         if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
2049           $parameters_output = 1;
2050         }
2051         $desc .= $symbol_docs;
2052     }
2054     if ($parameters_output == 0) {
2055         $desc .= $parameters;
2056     }
2058     $desc .= OutputSymbolTraits ($symbol);
2059     $desc .= "</refsect2>\n";
2060     return ($synop, $desc);
2064 #############################################################################
2065 # Function    : OutputParamDescriptions
2066 # Description : Returns the DocBook output describing the parameters of a
2067 #               function, macro or signal handler.
2068 # Arguments   : $symbol_type - 'FUNCTION', 'MACRO' or 'SIGNAL'. Signal
2069 #                 handlers have an implicit user_data parameter last.
2070 #               $symbol - the name of the function/macro being described.
2071 #               @fields - parsed fields from the declaration, used to determine
2072 #                  undocumented/unused entries
2073 #############################################################################
2075 sub OutputParamDescriptions {
2076     my ($symbol_type, $symbol, @fields) = @_;
2077     my $output = "";
2078     my $params = $SymbolParams{$symbol};
2079     my $num_params = 0;
2080     my %field_descrs = ();
2082     if (@fields) {
2083         %field_descrs = @fields;
2084         delete $field_descrs{"void"};
2085         delete $field_descrs{"Returns"};
2086     }
2088     if (defined $params) {
2089         my $returns = "";
2090         my $params_desc = "";
2091         my $missing_parameters = "";
2092         my $unused_parameters = "";
2093         my $j;
2095         for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
2096             my $param_name = $$params[$j];
2097             my $param_desc = $$params[$j + 1];
2098             my $param_annotations = "";
2100             ($param_desc,$param_annotations) = & ExpandAnnotation($symbol, $param_desc);
2101             $param_desc = &ExpandAbbreviations($symbol, $param_desc);
2102             $param_desc .= $param_annotations;
2103             # trim
2104             $param_desc =~ s/^(\s|\n)+//msg;
2105             $param_desc =~ s/(\s|\n)+$//msg;
2106             if ($param_name eq "Returns") {
2107                 $returns = "$param_desc";
2108             } elsif ($param_name eq "void") {
2109                 #print "!!!! void in params for $symbol?\n";
2110             } else {
2111                 if (@fields) {
2112                     if (!defined $field_descrs{$param_name}) {
2113                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2114                             "Parameter description for $symbol"."::"."$param_name is not used from source code comment block.");
2115                         if ($unused_parameters ne "") {
2116                           $unused_parameters .= ", ".$param_name;
2117                         } else {
2118                            $unused_parameters = $param_name;
2119                         }
2120                     } else {
2121                         delete $field_descrs{$param_name};
2122                     }
2123                 }
2124                 if ($param_name eq "Varargs") {
2125                     $param_name = "...";
2126                 }
2127                 if($param_desc ne "") {
2128                     $params_desc .= "<varlistentry><term><parameter>$param_name</parameter>&#160;:</term>\n<listitem><simpara>$param_desc</simpara></listitem></varlistentry>\n";
2129                     $num_params++;
2130                 }
2131             }
2132         }
2133         foreach my $param_name (keys %field_descrs) {
2134             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2135                 "Parameter description for $symbol"."::"."$param_name is missing in source code comment block.");
2136             if ($missing_parameters ne "") {
2137               $missing_parameters .= ", ".$param_name;
2138             } else {
2139                $missing_parameters = $param_name;
2140             }
2141         }
2143         # Signals have an implicit user_data parameter which we describe.
2144         if ($symbol_type eq "SIGNAL") {
2145             $params_desc .= "<varlistentry><term><parameter>user_data</parameter>&#160;:</term>\n<listitem><simpara>user data set when the signal handler was connected.</simpara></listitem></varlistentry>\n";
2146         }
2148         # Start a table if we need one.
2149         if ($params_desc || $returns) {
2150             $output .= "<variablelist role=\"params\">\n";
2151             if ($params_desc ne "") {
2152                 #$output .= "<varlistentry><term>Parameters:</term><listitem></listitem></varlistentry>\n";
2153                 $output .= $params_desc;
2154             }
2156             # Output the returns info last
2157             if ($returns) {
2158                 $output .= "<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara>$returns</simpara></listitem></varlistentry>\n";
2159             }
2161             # Finish the table.
2162             $output .= "</variablelist>";
2163         }
2165         # remember missing/unused parameters (needed in tmpl-free build)
2166         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
2167             $AllIncompleteSymbols{$symbol}=$missing_parameters;
2168         }
2169         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
2170             $AllUnusedSymbols{$symbol}=$unused_parameters;
2171         }
2172     }
2173     if (($num_params == 0) && @fields && (scalar(keys(%field_descrs)) > 0)) {
2174         if (! exists ($AllIncompleteSymbols{$symbol})) {
2175             $AllIncompleteSymbols{$symbol}="<parameters>";
2176         }
2177     }
2179     return $output;
2183 #############################################################################
2184 # Function    : ParseStabilityLevel
2185 # Description : Parses a stability level and outputs a warning if it isn't
2186 #               valid.
2187 # Arguments   : $stability - the stability text.
2188 #               $file, $line - context for error message
2189 #               $message - description of where the level is from, to use in
2190 #               any error message.
2191 # Returns     : The parsed stability level string.
2192 #############################################################################
2194 sub ParseStabilityLevel {
2195     my ($stability, $file, $line, $message) = @_;
2197     $stability =~ s/^\s*//;
2198     $stability =~ s/\s*$//;
2199     if ($stability =~ m/^stable$/i) {
2200         $stability = "Stable";
2201     } elsif ($stability =~ m/^unstable$/i) {
2202         $stability = "Unstable";
2203     } elsif ($stability =~ m/^private$/i) {
2204         $stability = "Private";
2205     } else {
2206         &LogWarning ($file, $line, "$message is $stability.".
2207             "It should be one of these: Stable, Unstable, or Private.");
2208     }
2209     return $stability;
2213 #############################################################################
2214 # Function    : OutputSGMLFile
2215 # Description : Outputs the final DocBook file for one section.
2216 # Arguments   : $file - the name of the file.
2217 #               $title - the title from the $MODULE-sections.txt file, which
2218 #                 will be overridden by the title in the template file.
2219 #               $section_id - the SGML id to use for the toplevel tag.
2220 #               $includes - comma-separates list of include files added at top
2221 #                 of synopsis, with '<' '>' around them (if not already enclosed in "").
2222 #               $synopsis - reference to the DocBook for the Synopsis part.
2223 #               $details - reference to the DocBook for the Details part.
2224 #               $signal_synop - reference to the DocBook for the Signal Synopsis part
2225 #               $signal_desc - reference to the DocBook for the Signal Description part
2226 #               $args_synop - reference to the DocBook for the Arg Synopsis part
2227 #               $args_desc - reference to the DocBook for the Arg Description part
2228 #               $hierarchy - reference to the DocBook for the Object Hierarchy part
2229 #               $interfaces - reference to the DocBook for the Interfaces part
2230 #               $implementations - reference to the DocBook for the Known Implementations part
2231 #               $prerequisites - reference to the DocBook for the Prerequisites part
2232 #               $derived - reference to the DocBook for the Derived Interfaces part
2233 #               $file_objects - reference to an array of objects in this file
2234 #############################################################################
2236 sub OutputSGMLFile {
2237     my ($file, $title, $section_id, $includes, $synopsis, $details, $signals_synop, $signals_desc, $args_synop, $args_desc, $hierarchy, $interfaces, $implementations, $prerequisites, $derived, $file_objects) = @_;
2239     #print "Output sgml for file $file with title '$title'\n";
2241     # The edited title overrides the one from the sections file.
2242     my $new_title = $SymbolDocs{"$TMPL_DIR/$file:Title"};
2243     if (defined ($new_title) && $new_title !~ m/^\s*$/) {
2244         $title = $new_title;
2245         #print "Found title: $title\n";
2246     }
2247     my $short_desc = $SymbolDocs{"$TMPL_DIR/$file:Short_Description"};
2248     if (!defined ($short_desc) || $short_desc =~ m/^\s*$/) {
2249         $short_desc = "";
2250     } else {
2251         $short_desc = &ExpandAbbreviations("$title:Short_description",
2252                                            $short_desc);
2253         #print "Found short_desc: $short_desc";
2254     }
2255     my $long_desc = $SymbolDocs{"$TMPL_DIR/$file:Long_Description"};
2256     if (!defined ($long_desc) || $long_desc =~ m/^\s*$/) {
2257         $long_desc = "";
2258     } else {
2259         $long_desc = &ExpandAbbreviations("$title:Long_description",
2260                                           $long_desc);
2261         #print "Found long_desc: $long_desc";
2262     }
2263     my $see_also = $SymbolDocs{"$TMPL_DIR/$file:See_Also"};
2264     if (!defined ($see_also) || $see_also =~ m%^\s*(<para>)?\s*(</para>)?\s*$%) {
2265         $see_also = "";
2266     } else {
2267         $see_also = &ExpandAbbreviations("$title:See_Also", $see_also);
2268         #print "Found see_also: $see_also";
2269     }
2270     if ($see_also) {
2271         $see_also = "<refsect1 id=\"$section_id.see-also\">\n<title>See Also</title>\n$see_also\n</refsect1>\n";
2272     }
2273     my $stability = $SymbolDocs{"$TMPL_DIR/$file:Stability_Level"};
2274     if (!defined ($stability) || $stability =~ m/^\s*$/) {
2275         $stability = "";
2276     } else {
2277         $stability = &ParseStabilityLevel($stability, $file, $., "Section stability level");
2278         #print "Found stability: $stability";
2279     }
2280     if ($stability) {
2281         $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$stability, unless otherwise indicated\n</refsect1>\n";
2282     } elsif ($DEFAULT_STABILITY) {
2283         $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$DEFAULT_STABILITY, unless otherwise indicated\n</refsect1>\n";
2284     }
2286     my $image = $SymbolDocs{"$TMPL_DIR/$file:Image"};
2287     if (!defined ($image) || $image =~ m/^\s*$/) {
2288       $image = "";
2289     } else {
2290       $image =~ s/^\s*//;
2291       $image =~ s/\s*$//;
2293       my $format;
2295       if ($image =~ /jpe?g$/i) {
2296         $format = "format='JPEG'";
2297       } elsif ($image =~ /png$/i) {
2298         $format = "format='PNG'";
2299       } elsif ($image =~ /svg$/i) {
2300         $format = "format='SVG'";
2301       } else {
2302         $format = "";
2303       }
2305       $image = "  <inlinegraphic fileref='$image' $format/>\n"
2306     }
2308     my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
2309         gmtime (time);
2310     my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
2311     $year += 1900;
2313     my $include_output = "";
2314     my $include;
2315     foreach $include (split (/,/, $includes)) {
2316         if ($include =~ m/^\".+\"$/) {
2317             $include_output .= "#include ${include}\n";
2318         }
2319         else {
2320             $include =~ s/^\s+|\s+$//gs;
2321             $include_output .= "#include &lt;${include}&gt;\n";
2322         }
2323     }
2324     if ($include_output ne '') {
2325         $include_output = "\n$include_output\n";
2326     }
2328     my $extralinks = OutputSectionExtraLinks($title,"Section:$file");
2330     my $old_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT";
2331     my $new_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT.new";
2333     open (OUTPUT, ">$new_sgml_file")
2334         || die "Can't create $new_sgml_file: $!";
2336     my $object_anchors = "";
2337     foreach my $object (@$file_objects) {
2338         next if ($object eq $section_id);
2339         my $id = CreateValidSGMLID($object);
2340         #print "Debug: Adding anchor for $object\n";
2341         $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
2342     }
2344     # We used to output this, but is messes up our UpdateFileIfChanged code
2345     # since it changes every day (and it is only used in the man pages):
2346     # "<refentry id="$section_id" revision="$mday $month $year">"
2348     if ($OUTPUT_FORMAT eq "xml") {
2349         print OUTPUT $doctype_header;
2350     }
2352     print OUTPUT <<EOF;
2353 <refentry id="$section_id">
2354 <refmeta>
2355 <refentrytitle role="top_of_page" id="$section_id.top_of_page">$title</refentrytitle>
2356 <manvolnum>3</manvolnum>
2357 <refmiscinfo>
2358   \U$MODULE\E Library
2359 $image</refmiscinfo>
2360 </refmeta>
2361 <refnamediv>
2362 <refname>$title</refname>
2363 <refpurpose>$short_desc</refpurpose>
2364 </refnamediv>
2365 $stability
2366 <refsynopsisdiv id="$section_id.synopsis" role="synopsis">
2367 <title role="synopsis.title">Synopsis</title>
2368 $object_anchors
2369 <synopsis>$include_output$${synopsis}</synopsis>
2370 </refsynopsisdiv>
2371 $$hierarchy$$prerequisites$$derived$$interfaces$$implementations$$args_synop$$signals_synop
2372 <refsect1 id="$section_id.description" role="desc">
2373 <title role="desc.title">Description</title>
2374 $extralinks$long_desc
2375 </refsect1>
2376 <refsect1 id="$section_id.details" role="details">
2377 <title role="details.title">Details</title>
2378 $$details
2379 </refsect1>
2380 $$args_desc$$signals_desc$see_also
2381 </refentry>
2383     close (OUTPUT);
2385     return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2389 #############################################################################
2390 # Function    : OutputExtraFile
2391 # Description : Copies an "extra" DocBook file into the output directory,
2392 #               expanding abbreviations
2393 # Arguments   : $file - the source file.
2394 #############################################################################
2395 sub OutputExtraFile {
2396     my ($file) = @_;
2398     my $basename;
2400     ($basename = $file) =~ s!^.*/!!;
2402     my $old_sgml_file = "$SGML_OUTPUT_DIR/$basename";
2403     my $new_sgml_file = "$SGML_OUTPUT_DIR/$basename.new";
2405     my $contents;
2407     open(EXTRA_FILE, "<$file") || die "Can't open $file";
2409     {
2410         local $/;
2411         $contents = <EXTRA_FILE>;
2412     }
2414     open (OUTPUT, ">$new_sgml_file")
2415         || die "Can't create $new_sgml_file: $!";
2417     print OUTPUT &ExpandAbbreviations ("$basename file", $contents);
2418     close (OUTPUT);
2420     return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2422 #############################################################################
2423 # Function    : OutputBook
2424 # Description : Outputs the SGML entities that need to be included into the
2425 #               main SGML file for the module.
2426 # Arguments   : $book_top - the declarations of the entities, which are added
2427 #                 at the top of the main SGML file.
2428 #               $book_bottom - the references to the entities, which are
2429 #                 added in the main SGML file at the desired position.
2430 #############################################################################
2432 sub OutputBook {
2433     my ($book_top, $book_bottom) = @_;
2435     my $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top";
2436     my $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top.new";
2438     open (OUTPUT, ">$new_file")
2439         || die "Can't create $new_file: $!";
2440     print OUTPUT $book_top;
2441     close (OUTPUT);
2443     &UpdateFileIfChanged ($old_file, $new_file, 0);
2446     $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom";
2447     $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom.new";
2449     open (OUTPUT, ">$new_file")
2450         || die "Can't create $new_file: $!";
2451     print OUTPUT $book_bottom;
2452     close (OUTPUT);
2454     &UpdateFileIfChanged ($old_file, $new_file, 0);
2457     # If the main SGML/XML file hasn't been created yet, we create it here.
2458     # The user can tweak it later.
2459     if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
2460       open (OUTPUT, ">$MAIN_SGML_FILE")
2461         || die "Can't create $MAIN_SGML_FILE: $!";
2463       if ($OUTPUT_FORMAT eq "xml") {
2464           print OUTPUT <<EOF;
2465 <?xml version="1.0"?>
2466 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
2467                "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
2469   <!ENTITY % local.common.attrib "xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'">
2471 <book id="index">
2473       } else {
2474         print OUTPUT <<EOF;
2475 <!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
2476 $book_top
2478 <book id="index">
2480       }
2482 print OUTPUT <<EOF;
2483   <bookinfo>
2484     <title>$MODULE Reference Manual</title>
2485     <releaseinfo>
2486       for $MODULE [VERSION].
2487       The latest version of this documentation can be found on-line at
2488       <ulink role="online-location" url="http://[SERVER]/$MODULE/index.html">http://[SERVER]/$MODULE/</ulink>.
2489     </releaseinfo>
2490   </bookinfo>
2492   <chapter>
2493     <title>[Insert title here]</title>
2494     $book_bottom
2495   </chapter>
2497   if (-e $OBJECT_TREE_FILE) {
2498     print OUTPUT <<EOF;
2499   <chapter id="object-tree">
2500     <title>Object Hierarchy</title>
2501      <xi:include href="xml/tree_index.sgml"/>
2502   </chapter>
2504   }
2506 print OUTPUT <<EOF;
2507   <index id="api-index-full">
2508     <title>API Index</title>
2509     <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
2510   </index>
2511   <index id="deprecated-api-index" role="deprecated">
2512     <title>Index of deprecated API</title>
2513     <xi:include href="xml/api-index-deprecated.xml"><xi:fallback /></xi:include>
2514   </index>
2516   <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
2517 </book>
2520       close (OUTPUT);
2521     }
2525 #############################################################################
2526 # Function    : CreateValidSGML
2527 # Description : This turns any chars which are used in SGML into entities,
2528 #               e.g. '<' into '&lt;'
2529 # Arguments   : $text - the text to turn into proper SGML.
2530 #############################################################################
2532 sub CreateValidSGML {
2533     my ($text) = @_;
2534     $text =~ s/&/&amp;/g;       # Do this first, or the others get messed up.
2535     $text =~ s/</&lt;/g;
2536     $text =~ s/>/&gt;/g;
2537     # browers render single tabs inconsistently
2538     $text =~ s/([^\s])\t([^\s])/$1&#160;$2/g;
2539     return $text;
2542 #############################################################################
2543 # Function    : ConvertSGMLChars
2544 # Description : This is used for text in source code comment blocks, to turn
2545 #               chars which are used in SGML into entities, e.g. '<' into
2546 #               '&lt;'. Depending on $INLINE_MARKUP_MODE, this is done
2547 #               unconditionally or only if the character doesn't seem to be
2548 #               part of an SGML construct (tag or entity reference).
2549 # Arguments   : $text - the text to turn into proper SGML.
2550 #############################################################################
2552 sub ConvertSGMLChars {
2553     my ($symbol, $text) = @_;
2555     if ($INLINE_MARKUP_MODE) {
2556         # For the XML/SGML mode only convert to entities outside CDATA sections.
2557         return &ModifyXMLElements ($text, $symbol,
2558                                    "<!\\[CDATA\\[|<programlisting[^>]*>",
2559                                    \&ConvertSGMLCharsEndTag,
2560                                    \&ConvertSGMLCharsCallback);
2561     } else {
2562         # For the simple non-sgml mode, convert to entities everywhere.
2563         $text =~ s/&/&amp;/g;   # Do this first, or the others get messed up.
2564         $text =~ s/</&lt;/g;
2565         $text =~ s/>/&gt;/g;
2566         return $text;
2567     }
2571 sub ConvertSGMLCharsEndTag {
2572   if ($_[0] eq "<!\[CDATA\[") {
2573     return "]]>";
2574   } else {
2575     return "</programlisting>";
2576   }
2579 sub ConvertSGMLCharsCallback {
2580   my ($text, $symbol, $tag) = @_;
2582   if ($tag =~ m/^<programlisting/) {
2583     # We can handle <programlisting> specially here.
2584     return &ModifyXMLElements ($text, $symbol,
2585                                "<!\\[CDATA\\[",
2586                                \&ConvertSGMLCharsEndTag,
2587                                \&ConvertSGMLCharsCallback2);
2588   } elsif ($tag eq "") {
2589     # If we're not in CDATA convert to entities.
2590     $text =~ s/&(?![a-zA-Z#]+;)/&amp;/g;        # Do this first, or the others get messed up.
2591     $text =~ s/<(?![a-zA-Z\/!])/&lt;/g;
2592     $text =~ s/(?<![a-zA-Z0-9"'\/-])>/&gt;/g;
2594     # Handle "#include <xxxxx>"
2595     $text =~ s/#include(\s+)<([^>]+)>/#include$1&lt;$2&gt;/g;
2596   }
2598   return $text;
2601 sub ConvertSGMLCharsCallback2 {
2602   my ($text, $symbol, $tag) = @_;
2604   # If we're not in CDATA convert to entities.
2605   # We could handle <programlisting> differently, though I'm not sure it helps.
2606   if ($tag eq "") {
2607     # replace only if its not a tag
2608     $text =~ s/&(?![a-zA-Z#]+;)/&amp;/g;        # Do this first, or the others get messed up.
2609     $text =~ s/<(?![a-zA-Z\/!])/&lt;/g;
2610     $text =~ s/(?<![a-zA-Z0-9"'\/-])>/&gt;/g;
2612     # Handle "#include <xxxxx>"
2613     $text =~ s/#include(\s+)<([^>]+)>/#include$1&lt;$2&gt;/g;
2614   }
2616   return $text;
2619 #############################################################################
2620 # Function    : ExpandAnnotation
2621 # Description : This turns annotations into acronym tags.
2622 # Arguments   : $symbol - the symbol being documented, for error messages.
2623 #               $text - the text to expand.
2624 #############################################################################
2625 sub ExpandAnnotation {
2626     my ($symbol, $param_desc) = @_;
2627     my $param_annotations = "";
2629     # look for annotations at the start of the comment part
2630     if ($param_desc =~ m%^\s*\((.*?)\):%) {
2631         my @annotations;
2632         my $annotation;
2633         $param_desc = $';
2635         @annotations = split(/\)\s*\(/,$1);
2636         foreach $annotation (@annotations) {
2637             # need to search for the longest key-match in %AnnotationDefinition
2638             my $match_length=0;
2639             my $match_annotation="";
2640             my $annotationdef;
2641             foreach $annotationdef (keys %AnnotationDefinition) {
2642                 if ($annotation =~ m/^$annotationdef/) {
2643                     if (length($annotationdef)>$match_length) {
2644                         $match_length=length($annotationdef);
2645                         $match_annotation=$annotationdef;
2646                     }
2647                 }
2648             }
2649             my $annotation_extra = "";
2650             if ($match_annotation ne "") {
2651                 if ($annotation =~ m%$match_annotation\s+(.*)%) {
2652                     $annotation_extra = " $1";
2653                 }
2654                 $AnnotationsUsed{$match_annotation} = 1;
2655                 $param_annotations .= "[<acronym>$match_annotation</acronym>$annotation_extra]";
2656             }
2657             else {
2658                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2659                     "unknown annotation \"$annotation\" in documentation for $symbol.");
2660                 $param_annotations .= "[$annotation]";
2661             }
2662         }
2663         chomp($param_desc);
2664         $param_desc =~ m/^(.*?)\.*\s*$/s;
2665         $param_desc = "$1. ";
2666     }
2667     if ($param_annotations ne "") {
2668         $param_annotations = "<emphasis role=\"annotation\">$param_annotations</emphasis>";
2669     }
2670     return ($param_desc, $param_annotations);
2673 #############################################################################
2674 # Function    : ExpandAbbreviations
2675 # Description : This turns the abbreviations function(), macro(), @param,
2676 #               %constant, and #symbol into appropriate DocBook markup.
2677 #               CDATA sections and <programlisting> parts are skipped.
2678 # Arguments   : $symbol - the symbol being documented, for error messages.
2679 #               $text - the text to expand.
2680 #############################################################################
2682 sub ExpandAbbreviations {
2683   my ($symbol, $text) = @_;
2685   # Convert "|[" and "]|" into the start and end of program listing examples.
2686   # FIXME: we like to have a way to specify parameters e.g. language="c"
2687   $text =~ s%\|\[%<informalexample><programlisting>%g;
2688   $text =~ s%\]\|%</programlisting></informalexample>%g;
2689   # TODO: check for a xml comment after |[ and pick the language attribute from
2690   # that
2692   # keep CDATA unmodified, preserve ulink tags (ideally we preseve all tags
2693   # as such)
2694   return &ModifyXMLElements ($text, $symbol,
2695                              "<!\\[CDATA\\[|<ulink[^>]*>|<programlisting[^>]*>|<!DOCTYPE",
2696                              \&ExpandAbbreviationsEndTag,
2697                              \&ExpandAbbreviationsCallback);
2701 # Returns the end tag corresponding to the given start tag.
2702 sub ExpandAbbreviationsEndTag {
2703   my ($start_tag) = @_;
2705   if ($start_tag eq "<!\[CDATA\[") {
2706     return "]]>";
2707   } elsif ($start_tag eq "<!DOCTYPE") {
2708     return "]>";
2709   } elsif ($start_tag =~ m/<(\w+)/) {
2710     return "</$1>";
2711   }
2714 # Called inside or outside each CDATA or <programlisting> section.
2715 sub ExpandAbbreviationsCallback {
2716   my ($text, $symbol, $tag) = @_;
2718   if ($tag =~ m/^<programlisting/) {
2719     # Handle any embedded CDATA sections.
2720     return &ModifyXMLElements ($text, $symbol,
2721                                "<!\\[CDATA\\[",
2722                                \&ExpandAbbreviationsEndTag,
2723                                \&ExpandAbbreviationsCallback2);
2724   } elsif ($tag eq "") {
2725     # We are outside any CDATA or <programlisting> sections, so we expand
2726     # any gtk-doc abbreviations.
2728     # Convert '@param()'
2729     # FIXME: we could make those also links ($symbol.$2), but that would be less
2730     # useful as the link target is a few lines up or down
2731     $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)\s*\(\)/$1<parameter>$2()<\/parameter>/g;
2733     # Convert 'function()' or 'macro()'.
2734     # if there is abc_*_def() we don't want to make a link to _def()
2735     # FIXME: also handle abc(def(....)) : but that would need to be done recursively :/
2736     $text =~ s/([^\*.\w])(\w+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2737     # handle #Object.func()
2738     $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2740     # Convert '@param', but not '\@param'.
2741     $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)/$1<parameter>$2<\/parameter>/g;
2742     $text =~ s/\\\@/\@/g;
2744     # Convert '%constant', but not '\%constant'.
2745     # Also allow negative numbers, e.g. %-1.
2746     $text =~ s/(\A|[^\\])\%(-?\w+)/$1.&MakeXRef($2, &tagify($2, "literal"));/eg;
2747     $text =~ s/\\\%/\%/g;
2749     # Convert '#symbol', but not '\#symbol'.
2750     $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)/$1.&MakeHashXRef($2, "type");/eg;
2751     $text =~ s/\\#/#/g;
2753     # Expand urls
2754     # FIXME: should we skip urls that are already tagged? (e.g. <literal>http://...</literal>)
2755     # this is apparently also called for markup and not just for plain text
2756     # disable for now.
2757     #$text =~ s%(http|https|ftp)://(.*?)((?:\s|,|\)|\]|\<|\.\s))%<ulink url="$1://$2">$2</ulink>$3%g;
2759     # TODO: optionally check all words from $text against internal symbols and
2760     # warn if those could be xreffed, but miss a %,# or ()
2761   }
2763   return $text;
2766 # This is called inside a <programlisting>
2767 sub ExpandAbbreviationsCallback2 {
2768   my ($text, $symbol, $tag) = @_;
2770   if ($tag eq "") {
2771     # We are inside a <programlisting> but outside any CDATA sections,
2772     # so we expand any gtk-doc abbreviations.
2773     # FIXME: why is this different from &ExpandAbbreviationsCallback(),
2774     #        why not just call it
2775     $text =~ s/#(\w+)/&MakeHashXRef($1, "");/eg;
2776   }
2778   return $text;
2781 sub MakeHashXRef {
2782     my ($symbol, $tag) = @_;;
2783     my $text = $symbol;
2785     # Check for things like '#include', '#define', and skip them.
2786     if ($PreProcessorDirectives{$symbol}) {
2787       return "#$symbol";
2788     }
2790     # Get rid of any special '-struct' suffix.
2791     $text =~ s/-struct$//;
2793     # If the symbol is in the form "Object::signal", then change the symbol to
2794     # "Object-signal" and use "signal" as the text.
2795     if ($symbol =~ s/::/-/) {
2796       $text = "\"$'\"";
2797     }
2799     # If the symbol is in the form "Object:property", then change the symbol to
2800     # "Object--property" and use "property" as the text.
2801     if ($symbol =~ s/:/--/) {
2802       $text = "\"$'\"";
2803     }
2805     if ($tag ne "") {
2806       $text = tagify ($text, $tag);
2807     }
2809     return &MakeXRef($symbol, $text);
2813 #############################################################################
2814 # Function    : ModifyXMLElements
2815 # Description : Looks for given XML element tags within the text, and calls
2816 #               the callback on pieces of text inside & outside those elements.
2817 #               Used for special handling of text inside things like CDATA
2818 #               and <programlisting>.
2819 # Arguments   : $text - the text.
2820 #               $symbol - the symbol currently being documented (only used for
2821 #                      error messages).
2822 #               $start_tag_regexp - the regular expression to match start tags.
2823 #                      e.g. "<!\\[CDATA\\[|<programlisting[^>]*>" to match
2824 #                      CDATA sections or programlisting elements.
2825 #               $end_tag_func - function which is passed the matched start tag
2826 #                      and should return the appropriate end tag string.
2827 #               $callback - callback called with each part of the text. It is
2828 #                      called with a piece of text, the symbol being
2829 #                      documented, and the matched start tag or "" if the text
2830 #                      is outside the XML elements being matched.
2831 #############################################################################
2832 sub ModifyXMLElements {
2833     my ($text, $symbol, $start_tag_regexp, $end_tag_func, $callback) = @_;
2834     my ($before_tag, $start_tag, $end_tag_regexp, $end_tag);
2835     my $result = "";
2837     while ($text =~ m/$start_tag_regexp/s) {
2838       $before_tag = $`; # Prematch for last successful match string
2839       $start_tag = $&;  # Last successful match
2840       $text = $';       # Postmatch for last successful match string
2842       $result .= &$callback ($before_tag, $symbol, "");
2843       $result .= $start_tag;
2845       # get the mathing end-tag for current tag
2846       $end_tag_regexp = &$end_tag_func ($start_tag);
2848       if ($text =~ m/$end_tag_regexp/s) {
2849         $before_tag = $`;
2850         $end_tag = $&;
2851         $text = $';
2853         $result .= &$callback ($before_tag, $symbol, $start_tag);
2854         $result .= $end_tag;
2855       } else {
2856         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2857             "Can't find tag end: $end_tag_regexp in docs for: $symbol.");
2858         # Just assume it is all inside the tag.
2859         $result .= &$callback ($text, $symbol, $start_tag);
2860         $text = "";
2861       }
2862     }
2864     # Handle any remaining text outside the tags.
2865     $result .= &$callback ($text, $symbol, "");
2867     return $result;
2870 sub noop {
2871   return $_[0];
2874 # Adds a tag around some text.
2875 # e.g tagify("Text", "literal") => "<literal>Text</literal>".
2876 sub tagify {
2877    my ($text, $elem) = @_;
2878    return "<" . $elem . ">" . $text . "</" . $elem . ">";
2882 #############################################################################
2883 # Function    : MakeXRef
2884 # Description : This returns a cross-reference link to the given symbol.
2885 #               Though it doesn't try to do this for a few standard C types
2886 #               that it knows won't be in the documentation.
2887 # Arguments   : $symbol - the symbol to try to create a XRef to.
2888 #               $text - text text to put inside the XRef, defaults to $symbol
2889 #############################################################################
2891 sub MakeXRef {
2892     my ($symbol, $text) = ($_[0], $_[1]);
2894     $symbol =~ s/^\s+//;
2895     $symbol =~ s/\s+$//;
2897     if (!defined($text)) {
2898         $text = $symbol;
2900         # Get rid of special '-struct' suffix.
2901         $text =~ s/-struct$//;
2902     }
2904     if ($symbol =~ m/ /) {
2905         return "$text";
2906     }
2908     #print "Getting type link for $symbol -> $text\n";
2910     my $symbol_id = &CreateValidSGMLID ($symbol);
2911     return "<link linkend=\"$symbol_id\">$text</link>";
2915 #############################################################################
2916 # Function    : MakeIndexterms
2917 # Description : This returns a indexterm elements for the given symbol
2918 # Arguments   : $symbol - the symbol to create indexterms for
2919 #############################################################################
2921 sub MakeIndexterms {
2922   my ($symbol, $id) = @_;
2923   my $terms =  "";
2924   my $sortas = "";
2926   # make the index useful, by ommiting the namespace when sorting
2927   if ($NAME_SPACE ne "") {
2928     if ($symbol =~ m/^$NAME_SPACE\_?(.*)/i) {
2929        $sortas=" sortas=\"$1\"";
2930     }
2931   }
2933   if (exists $Deprecated{$symbol}) {
2934       $terms .= "<indexterm zone=\"$id\" role=\"deprecated\"><primary$sortas>$symbol</primary></indexterm>";
2935       $IndexEntriesDeprecated{$symbol}=$id;
2936       $IndexEntriesFull{$symbol}=$id;
2937   }
2938   if (exists $Since{$symbol}) {
2939      my $since = $Since{$symbol};
2940      $since =~ s/^\s+//;
2941      $since =~ s/\s+$//;
2942      if ($since ne "") {
2943          $terms .= "<indexterm zone=\"$id\" role=\"$since\"><primary$sortas>$symbol</primary></indexterm>";
2944      }
2945      $IndexEntriesSince{$symbol}=$id;
2946      $IndexEntriesFull{$symbol}=$id;
2947   }
2948   if ($terms eq "") {
2949      $terms .= "<indexterm zone=\"$id\"><primary$sortas>$symbol</primary></indexterm>";
2950      $IndexEntriesFull{$symbol}=$id;
2951   }
2953   return $terms;
2956 #############################################################################
2957 # Function    : MakeDeprecationNote
2958 # Description : This returns a deprecation warning for the given symbol.
2959 # Arguments   : $symbol - the symbol to try to create a warning for.
2960 #############################################################################
2962 sub MakeDeprecationNote {
2963     my ($symbol) = $_[0];
2964     my $desc = "";
2965     my $note = "";
2966     if (exists $Deprecated{$symbol}) {
2967         $desc .= "<warning>";
2969         if ($Deprecated{$symbol} =~ /^\s*([0-9\.]+)\s*:/) {
2970                 $desc .= "<para><literal>$symbol</literal> has been deprecated since version $1 and should not be used in newly-written code.";
2971         } else {
2972                 $desc .= "<para><literal>$symbol</literal> is deprecated and should not be used in newly-written code.";
2973         }
2974         if ($Deprecated{$symbol} ne "") {
2975             $note = &ExpandAbbreviations($symbol, $Deprecated{$symbol});
2976             $note =~ s/^\s*([0-9\.]+)\s*:\s*//;
2977             $note =~ s/^\s+//;
2978             $note =~ s/\s+$//;
2979             $note =~ s%\n{2,}%\n</para>\n<para>\n%g;
2980             $desc .= " " . $note;
2981         }
2982         $desc .= "</para></warning>\n";
2983     }
2984     return $desc;
2987 #############################################################################
2988 # Function    : MakeConditionDescription
2989 # Description : This returns a sumary of conditions for the given symbol.
2990 # Arguments   : $symbol - the symbol to try to create the sumary.
2991 #############################################################################
2993 sub MakeConditionDescription {
2994     my ($symbol) = $_[0];
2995     my $desc = "";
2997     if (exists $Deprecated{$symbol}) {
2998         if ($desc ne "") {
2999             $desc .= "|";
3000         }
3002         if ($Deprecated{$symbol} =~ /^\s*(.*?)\s*$/) {
3003                 $desc .= "deprecated:$1";
3004         } else {
3005                 $desc .= "deprecated";
3006         }
3007     }
3009     if (exists $Since{$symbol}) {
3010         if ($desc ne "") {
3011             $desc .= "|";
3012         }
3014         if ($Since{$symbol} =~ /^\s*(.*?)\s*$/) {
3015                 $desc .= "since:$1";
3016         } else {
3017                 $desc .= "since";
3018         }
3019     }
3021     if (exists $StabilityLevel{$symbol}) {
3022         if ($desc ne "") {
3023             $desc .= "|";
3024         }
3025         $desc .= "stability:".$StabilityLevel{$symbol};
3026     }
3028     if ($desc ne "") {
3029         $desc=" condition=\"".$desc."\"";
3030         #print "condition for '$symbol' = '$desc'\n";
3031     }
3032     return $desc;
3035 #############################################################################
3036 # Function    : GetHierarchy
3037 # Description : Returns the DocBook output describing the ancestors and
3038 #               immediate children of a GObject subclass. It uses the
3039 #               global @Objects and @ObjectLevels arrays to walk the tree.
3040 # Arguments   : $object - the GtkObject subclass.
3041 #############################################################################
3043 sub GetHierarchy {
3044     my ($object) = @_;
3046     # Find object in the objects array.
3047     my $found = 0;
3048     my @children = ();
3049     my $i;
3050     my $level;
3051     my $j;
3052     for ($i = 0; $i < @Objects; $i++) {
3053         if ($found) {
3054             if ($ObjectLevels[$i] <= $level) {
3055             last;
3056         }
3057             elsif ($ObjectLevels[$i] == $level + 1) {
3058                 push (@children, $Objects[$i]);
3059             }
3060         }
3061         elsif ($Objects[$i] eq $object) {
3062             $found = 1;
3063             $j = $i;
3064             $level = $ObjectLevels[$i];
3065         }
3066     }
3067     if (!$found) {
3068         return "";
3069     }
3071     # Walk up the hierarchy, pushing ancestors onto the ancestors array.
3072     my @ancestors = ();
3073     push (@ancestors, $object);
3074     #print "Level: $level\n";
3075     while ($level > 1) {
3076         $j--;
3077         if ($ObjectLevels[$j] < $level) {
3078             push (@ancestors, $Objects[$j]);
3079             $level = $ObjectLevels[$j];
3080             #print "Level: $level\n";
3081         }
3082     }
3084     # Output the ancestors list, indented and with links.
3085     my $hierarchy = "<synopsis>\n";
3086     $level = 0;
3087     for ($i = $#ancestors; $i >= 0; $i--) {
3088         my $link_text;
3089         # Don't add a link to the current object, i.e. when i == 0.
3090         if ($i > 0) {
3091             my $ancestor_id = &CreateValidSGMLID ($ancestors[$i]);
3092             $link_text = "<link linkend=\"$ancestor_id\">$ancestors[$i]</link>";
3093         } else {
3094             $link_text = "$ancestors[$i]";
3095         }
3096         if ($level == 0) {
3097             $hierarchy .= "  $link_text\n";
3098         } else {
3099 #           $hierarchy .= ' ' x ($level * 6 - 3) . "|\n";
3100             $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3101         }
3102         $level++;
3103     }
3104     for ($i = 0; $i <= $#children; $i++) {
3105       my $id = &CreateValidSGMLID ($children[$i]);
3106       my $link_text = "<link linkend=\"$id\">$children[$i]</link>";
3107       $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3108     }
3109     $hierarchy .= "</synopsis>\n";
3111     return $hierarchy;
3115 #############################################################################
3116 # Function    : GetInterfaces
3117 # Description : Returns the DocBook output describing the interfaces
3118 #               implemented by a class. It uses the global %Interfaces hash.
3119 # Arguments   : $object - the GtkObject subclass.
3120 #############################################################################
3122 sub GetInterfaces {
3123     my ($object) = @_;
3124     my $text = "";
3125     my $i;
3127     # Find object in the objects array.
3128     if (exists($Interfaces{$object})) {
3129         my @ifaces = split(' ', $Interfaces{$object});
3130         $text = <<EOF;
3131 <para>
3132 $object implements
3134         for ($i = 0; $i <= $#ifaces; $i++) {
3135             my $id = &CreateValidSGMLID ($ifaces[$i]);
3136             $text .= " <link linkend=\"$id\">$ifaces[$i]</link>";
3137             if ($i < $#ifaces - 1) {
3138                 $text .= ', ';
3139             }
3140             elsif ($i < $#ifaces) {
3141                 $text .= ' and ';
3142             }
3143             else {
3144                 $text .= '.';
3145             }
3146         }
3147         $text .= <<EOF;
3148 </para>
3150     }
3152     return $text;
3155 #############################################################################
3156 # Function    : GetImplementations
3157 # Description : Returns the DocBook output describing the implementations
3158 #               of an interface. It uses the global %Interfaces hash.
3159 # Arguments   : $object - the GtkObject subclass.
3160 #############################################################################
3162 sub GetImplementations {
3163     my ($object) = @_;
3164     my @impls = ();
3165     my $text = "";
3166     my $i;
3167     foreach my $key (keys %Interfaces) {
3168         if ($Interfaces{$key} =~ /\b$object\b/) {
3169             push (@impls, $key);
3170         }
3171     }
3172     if ($#impls >= 0) {
3173         @impls = sort @impls;
3174         $text = <<EOF;
3175 <para>
3176 $object is implemented by
3178         for ($i = 0; $i <= $#impls; $i++) {
3179             my $id = &CreateValidSGMLID ($impls[$i]);
3180             $text .= " <link linkend=\"$id\">$impls[$i]</link>";
3181             if ($i < $#impls - 1) {
3182                 $text .= ', ';
3183             }
3184             elsif ($i < $#impls) {
3185                 $text .= ' and ';
3186             }
3187             else {
3188                 $text .= '.';
3189             }
3190         }
3191         $text .= <<EOF;
3192 </para>
3194     }
3195     return $text;
3199 #############################################################################
3200 # Function    : GetPrerequisites
3201 # Description : Returns the DocBook output describing the prerequisites
3202 #               of an interface. It uses the global %Prerequisites hash.
3203 # Arguments   : $iface - the interface.
3204 #############################################################################
3206 sub GetPrerequisites {
3207     my ($iface) = @_;
3208     my $text = "";
3209     my $i;
3211     if (exists($Prerequisites{$iface})) {
3212         $text = <<EOF;
3213 <para>
3214 $iface requires
3216         my @prereqs = split(' ', $Prerequisites{$iface});
3217         for ($i = 0; $i <= $#prereqs; $i++) {
3218             my $id = &CreateValidSGMLID ($prereqs[$i]);
3219             $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
3220             if ($i < $#prereqs - 1) {
3221                 $text .= ', ';
3222             }
3223             elsif ($i < $#prereqs) {
3224                 $text .= ' and ';
3225             }
3226             else {
3227                 $text .= '.';
3228             }
3229         }
3230         $text .= <<EOF;
3231 </para>
3233     }
3234     return $text;
3237 #############################################################################
3238 # Function    : GetDerived
3239 # Description : Returns the DocBook output describing the derived interfaces
3240 #               of an interface. It uses the global %Prerequisites hash.
3241 # Arguments   : $iface - the interface.
3242 #############################################################################
3244 sub GetDerived {
3245     my ($iface) = @_;
3246     my $text = "";
3247     my $i;
3249     my @derived = ();
3250     foreach my $key (keys %Prerequisites) {
3251         if ($Prerequisites{$key} =~ /\b$iface\b/) {
3252             push (@derived, $key);
3253         }
3254     }
3255     if ($#derived >= 0) {
3256         @derived = sort @derived;
3257         $text = <<EOF;
3258 <para>
3259 $iface is required by
3261         for ($i = 0; $i <= $#derived; $i++) {
3262             my $id = &CreateValidSGMLID ($derived[$i]);
3263             $text .= " <link linkend=\"$id\">$derived[$i]</link>";
3264             if ($i < $#derived - 1) {
3265                 $text .= ', ';
3266             }
3267             elsif ($i < $#derived) {
3268                 $text .= ' and ';
3269             }
3270             else {
3271                 $text .= '.';
3272             }
3273         }
3274         $text .= <<EOF;
3275 </para>
3277     }
3278     return $text;
3282 #############################################################################
3283 # Function    : GetSignals
3284 # Description : Returns the synopsis and detailed description DocBook output
3285 #               for the signal handlers of a given GtkObject subclass.
3286 # Arguments   : $object - the GtkObject subclass, e.g. 'GtkButton'.
3287 #############################################################################
3289 sub GetSignals {
3290     my ($object) = @_;
3291     my $synop = "";
3292     my $desc = "";
3294     my $i;
3295     for ($i = 0; $i <= $#SignalObjects; $i++) {
3296         if ($SignalObjects[$i] eq $object) {
3297             #print "Found signal: $SignalNames[$i]\n";
3298             my $name = $SignalNames[$i];
3299             my $symbol = "${object}::${name}";
3300             my $id = &CreateValidSGMLID ("$object-$name");
3302             my $pad = ' ' x (46 - length($name));
3303             $synop .= "  &quot;<link linkend=\"$id\">$name</link>&quot;$pad ";
3305             $desc .= "<refsect2 id=\"$id\" role=\"signal\"><title>The <literal>&quot;$name&quot;</literal> signal</title>\n";
3306             $desc .= MakeIndexterms($symbol, $id);
3307             $desc .= "\n";
3308             $desc .= OutputSymbolExtraLinks($symbol);
3310             $desc .= "<programlisting>";
3312             $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
3313             my $type_modifier = defined($1) ? $1 : "";
3314             my $type = $2;
3315             my $pointer = $3;
3316             my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
3318             my $ret_type_len = length ($type_modifier) + length ($pointer)
3319                 + length ($type);
3320             my $ret_type_output = "$type_modifier$xref$pointer"
3321                 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
3323             $desc  .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
3325             my $sourceparams = $SourceSymbolParams{$symbol};
3326             my @params = split ("\n", $SignalPrototypes[$i]);
3327             my $j;
3328             my $l;
3329             my $type_len = length("gpointer");
3330             my $name_len = length("user_data");
3331             # do two passes, the first one is to calculate padding
3332             for ($l = 0; $l < 2; $l++) {
3333                 for ($j = 0; $j <= $#params; $j++) {
3334                     # allow alphanumerics, '_', '[' & ']' in param names
3335                     if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
3336                         $type = $1;
3337                         $pointer = $2;
3338                         if (defined($sourceparams)) {
3339                             $name = $$sourceparams[$PARAM_FIELD_COUNT * $j];
3340                         }
3341                         else {
3342                             $name = $3;
3343                         }
3344                         if (!defined($name)) {
3345                             $name = "arg$j";
3346                         }
3347                         if ($l == 0) {
3348                             if (length($type) + length($pointer) > $type_len) {
3349                                 $type_len = length($type) + length($pointer);
3350                             }
3351                             if (length($name) > $name_len) {
3352                                 $name_len = length($name);
3353                             }
3354                         }
3355                         else {
3356                             $xref = &MakeXRef ($type, &tagify($type, "type"));
3357                             $pad = ' ' x ($type_len - length($type) - length($pointer));
3358                             $desc .= "$xref$pad $pointer$name,\n";
3359                             $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
3360                         }
3361                     } else {
3362                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3363                              "Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]");
3364                     }
3365                 }
3366             }
3367             $xref = &MakeXRef ("gpointer", &tagify("gpointer", "type"));
3368             $pad = ' ' x ($type_len - length("gpointer"));
3369             $desc  .= "$xref$pad user_data)";
3371             my $flags = $SignalFlags[$i];
3372             my $flags_string = "";
3374             if (defined ($flags)) {
3375               if ($flags =~ m/f/) {
3376                 $flags_string = "<link linkend=\"G-SIGNAL-RUN-FIRST:CAPS\"><literal>Run First</literal></link>";
3377               }
3378               elsif ($flags =~ m/l/) {
3379                 $flags_string = "<link linkend=\"G-SIGNAL-RUN-LAST:CAPS\"><literal>Run Last</literal></link>";
3380               }
3381               elsif ($flags =~ m/c/) {
3382                 $flags_string = "<link linkend=\"G-SIGNAL-RUN-CLEANUP:CAPS\"><literal>Cleanup</literal></link>";
3383                 $flags_string = "Cleanup";
3384               }
3385               if ($flags =~ m/r/) {
3386                 if ($flags_string) { $flags_string .= " / "; }
3387                 $flags_string = "<link linkend=\"G-SIGNAL-NO-RECURSE:CAPS\"><literal>No Recursion</literal></link>";
3388               }
3389               if ($flags =~ m/d/) {
3390                 if ($flags_string) { $flags_string .= " / "; }
3391                 $flags_string = "<link linkend=\"G-SIGNAL-DETAILED:CAPS\"><literal>Has Details</literal></link>";
3392               }
3393               if ($flags =~ m/a/) {
3394                 if ($flags_string) { $flags_string .= " / "; }
3395                 $flags_string = "<link linkend=\"G-SIGNAL-ACTION:CAPS\"><literal>Action</literal></link>";
3396               }
3397               if ($flags =~ m/h/) {
3398                 if ($flags_string) { $flags_string .= " / "; }
3399                 $flags_string = "<link linkend=\"G-SIGNAL-NO-HOOKS:CAPS\"><literal>No Hooks</literal></link>";
3400               }
3401             }
3403             if ($flags_string)
3404               {
3405                 $synop .= ": $flags_string\n";
3407                 $pad = ' ' x (5 + $name_len - length("user_data"));
3408                 $desc  .= "$pad : $flags_string</programlisting>\n";
3409               }
3410             else
3411               {
3412                 $synop .= "\n";
3413                 $desc  .= "</programlisting>\n";
3414               }
3416             $desc .= &MakeDeprecationNote($symbol);
3418             my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
3419             my $parameters_output = 0;
3421             $AllSymbols{$symbol} = 1;
3422             if (defined ($SymbolDocs{$symbol})) {
3423                 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3425                 # Try to insert the parameter table at the author's desired
3426                 # position. Otherwise we need to tag it onto the end.
3427                 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
3428                   $parameters_output = 1;
3429                 }
3430                 $desc .= $symbol_docs;
3432                 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
3433                     $AllDocumentedSymbols{$symbol} = 1;
3434                 }
3435             }
3437             if ($parameters_output == 0) {
3438                 $desc .= $parameters;
3439               }
3440             $desc .= OutputSymbolTraits ($symbol);
3441             $desc .= "</refsect2>";
3442         }
3443     }
3444     return ($synop, $desc);
3448 #############################################################################
3449 # Function    : GetArgs
3450 # Description : Returns the synopsis and detailed description DocBook output
3451 #               for the Args of a given GtkObject subclass.
3452 # Arguments   : $object - the GtkObject subclass, e.g. 'GtkButton'.
3453 #############################################################################
3455 sub GetArgs {
3456     my ($object) = @_;
3457     my $synop = "";
3458     my $desc = "";
3459     my $child_synop = "";
3460     my $child_desc = "";
3461     my $style_synop = "";
3462     my $style_desc = "";
3464     my $i;
3465     for ($i = 0; $i <= $#ArgObjects; $i++) {
3466         if ($ArgObjects[$i] eq $object) {
3467             #print "Found arg: $ArgNames[$i]\n";
3468             my $name = $ArgNames[$i];
3469             my $flags = $ArgFlags[$i];
3470             my $flags_string = "";
3471             my $kind = "";
3472             my $id_sep = "";
3474             if ($flags =~ m/c/) {
3475                 $kind = "child property";
3476                 $id_sep = "c-";
3477             }
3478             elsif ($flags =~ m/s/) {
3479                 $kind = "style property";
3480                 $id_sep = "s-";
3481             }
3482             else {
3483                 $kind = "property";
3484             }
3486             # Remember only one colon so we don't clash with signals.
3487             my $symbol = "${object}:${name}";
3488             # use two dashes and ev. an extra separator here for the same reason.
3489             my $id = &CreateValidSGMLID ("$object--$id_sep$name");
3491             my $type = $ArgTypes[$i];
3492             my $type_output;
3493             my $range = $ArgRanges[$i];
3494             my $range_output = CreateValidSGML ($range);
3495             my $default = $ArgDefaults[$i];
3496             my $default_output = CreateValidSGML ($default);
3498             if ($type eq "GtkString") {
3499                 $type = "char*";
3500             }
3501             if ($type eq "GtkSignal") {
3502                 $type = "GtkSignalFunc, gpointer";
3503                 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
3504                     . &MakeXRef ("gpointer");
3505             } elsif ($type =~ m/^(\w+)\*$/) {
3506                 $type_output = &MakeXRef ($1, &tagify($1, "type")) . "*";
3507             } else {
3508                 $type_output = &MakeXRef ($type, &tagify($type, "type"));
3509             }
3511             if ($flags =~ m/r/) {
3512                 $flags_string = "Read";
3513             }
3514             if ($flags =~ m/w/) {
3515                 if ($flags_string) { $flags_string .= " / "; }
3516                 $flags_string .= "Write";
3517             }
3518             if ($flags =~ m/x/) {
3519                 if ($flags_string) { $flags_string .= " / "; }
3520                 $flags_string .= "Construct";
3521             }
3522             if ($flags =~ m/X/) {
3523                 if ($flags_string) { $flags_string .= " / "; }
3524                 $flags_string .= "Construct Only";
3525             }
3527             $AllSymbols{$symbol} = 1;
3528             my $blurb;
3529             if (defined($SymbolDocs{$symbol}) &&
3530                 !IsEmptyDoc($SymbolDocs{$symbol})) {
3531                 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3532                 #print ".. [$SymbolDocs{$symbol}][$blurb]\n";
3533                 $AllDocumentedSymbols{$symbol} = 1;
3534             }
3535             else {
3536                 if (!($ArgBlurbs[$i] eq "")) {
3537                     $AllDocumentedSymbols{$symbol} = 1;
3538                 } else {
3539                     # FIXME: print a warning?
3540                     #print ".. no description\n";
3541                 }
3542                 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
3543             }
3545             my $pad1 = " " x (24 - length ($name));
3546             my $pad2 = " " x (20 - length ($type));
3548             my $arg_synop = "  &quot;<link linkend=\"$id\">$name</link>&quot;$pad1 $type_output $pad2 : $flags_string\n";
3549             my $arg_desc = "<refsect2 id=\"$id\" role=\"property\"><title>The <literal>&quot;$name&quot;</literal> $kind</title>\n";
3550             $arg_desc .= MakeIndexterms($symbol, $id);
3551             $arg_desc .= "\n";
3552             $arg_desc .= OutputSymbolExtraLinks($symbol);
3554             $arg_desc .= "<programlisting>  &quot;$name&quot;$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
3555             $arg_desc .= &MakeDeprecationNote($symbol);
3556             $arg_desc .= $blurb;
3557             if ($range ne "") {
3558                 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
3559             }
3560             if ($default ne "") {
3561                 $arg_desc .= "<para>Default value: $default_output</para>\n";
3562             }
3563             $arg_desc .= OutputSymbolTraits ($symbol);
3564             $arg_desc .= "</refsect2>\n";
3566             if ($flags =~ m/c/) {
3567                 $child_synop .= $arg_synop;
3568                 $child_desc .= $arg_desc;
3569             }
3570             elsif ($flags =~ m/s/) {
3571                 $style_synop .= $arg_synop;
3572                 $style_desc .= $arg_desc;
3573             }
3574             else {
3575                 $synop .= $arg_synop;
3576                 $desc .= $arg_desc;
3577             }
3578         }
3579     }
3580     return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
3584 #############################################################################
3585 # Function    : ReadSourceDocumentation
3586 # Description : This reads in the documentation embedded in comment blocks
3587 #               in the source code (for Gnome).
3589 #               Parameter descriptions override any in the template files.
3590 #               Function descriptions are placed before any description from
3591 #               the template files.
3593 #               It recursively descends the source directory looking for .c
3594 #               files and scans them looking for specially-formatted comment
3595 #               blocks.
3597 # Arguments   : $source_dir - the directory to scan.
3598 #############m###############################################################
3600 sub ReadSourceDocumentation {
3601     my ($source_dir) = @_;
3602     my ($file, $dir, @suffix_list, $suffix);
3603     #print "Scanning source directory: $source_dir\n";
3605     # This array holds any subdirectories found.
3606     my (@subdirs) = ();
3608     @suffix_list = split (/,/, $SOURCE_SUFFIXES);
3610     opendir (SRCDIR, $source_dir)
3611         || die "Can't open source directory $source_dir: $!";
3613     foreach $file (readdir (SRCDIR)) {
3614       if ($file =~ /^\./) {
3615         next;
3616       } elsif (-d "$source_dir/$file") {
3617         push (@subdirs, $file);
3618       } elsif (@suffix_list) {
3619         foreach $suffix (@suffix_list) {
3620           if ($file =~ m/\.\Q${suffix}\E$/) {
3621             &ScanSourceFile ("$source_dir/$file");
3622           }
3623         }
3624       } elsif ($file =~ m/\.[ch]$/) {
3625         &ScanSourceFile ("$source_dir/$file");
3626       }
3627     }
3628     closedir (SRCDIR);
3630     # Now recursively scan the subdirectories.
3631     foreach $dir (@subdirs) {
3632         next if ($IGNORE_FILES =~ m/(\s|^)\Q${dir}\E(\s|$)/);
3633         &ReadSourceDocumentation ("$source_dir/$dir");
3634     }
3638 #############################################################################
3639 # Function    : ScanSourceFile
3640 # Description : Scans one source file looking for specially-formatted comment
3641 #               blocks. Later &MergeSourceDocumentation is used to merge any
3642 #               documentation found with the documentation already read in
3643 #               from the template files.
3645 # Arguments   : $file - the file to scan.
3646 #############################################################################
3648 sub ScanSourceFile {
3649     my ($file) = @_;
3650     my $basename;
3652     if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
3653         $basename = $1;
3654     } else {
3655         &LogWarning ($file, 1, "Can't find basename for this filename.");
3656         $basename = $file;
3657     }
3659     # Check if the basename is in the list of files to ignore.
3660     if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
3661         return;
3662     }
3664     #print "DEBUG: Scanning $file\n";
3666     open (SRCFILE, $file)
3667         || die "Can't open $file: $!";
3668     my $in_comment_block = 0;
3669     my $symbol;
3670     my ($in_description, $in_return, $in_since, $in_stability, $in_deprecated);
3671     my ($description, $return_desc, $return_start, $return_style);
3672     my ($since_desc, $stability_desc, $deprecated_desc);
3673     my $current_param;
3674     my $ignore_broken_returns;
3675     my @params;
3676     while (<SRCFILE>) {
3677         # Look for the start of a comment block.
3678         if (!$in_comment_block) {
3679             if (m%^\s*/\*.*\*/%) {
3680                 #one-line comment - not gtkdoc
3681             } elsif (m%^\s*/\*\*\s%) {
3682                 #print "Found comment block start\n";
3684                 $in_comment_block = 1;
3686                 # Reset all the symbol data.
3687                 $symbol = "";
3688                 $in_description = 0;
3689                 $in_return = 0;
3690                 $in_since = 0;
3691                 $in_deprecated = 0;
3692                 $in_stability = 0;
3693                 $description = "";
3694                 $return_desc = "";
3695                 $return_style = "";
3696                 $since_desc = "";
3697                 $deprecated_desc = "";
3698                 $stability_desc = "";
3699                 $current_param = -1;
3700                 $ignore_broken_returns = 0;
3701                 @params = ();
3702             }
3703             next;
3704         }
3706         # We're in a comment block. Check if we've found the end of it.
3707         if (m%^\s*\*+/%) {
3708             if (!$symbol) {
3709                 # maybe its not even meant to be a gtk-doc comment?
3710                 &LogWarning ($file, $., "Symbol name not found at the start of the comment block.");
3711             } else {
3712                 # Add the return value description onto the end of the params.
3713                 if ($return_desc) {
3714                     push (@params, "Returns");
3715                     push (@params, $return_desc);
3716                     if ($return_style eq 'broken') {
3717                         &LogWarning ($file, $., "Free-form return value description in $symbol. Use `Returns:' to avoid ambiguities.");
3718                     }
3719                 }
3720                 # Convert special SGML characters
3721                 $description = &ConvertSGMLChars ($symbol, $description);
3722                 my $k;
3723                 for ($k = 1; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3724                     $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
3725                 }
3727                 # Handle Section docs
3728                 if ($symbol =~ m/SECTION:\s*(.*)/) {
3729                     my $real_symbol=$1;
3730                     my $key;
3732                     if (scalar %KnownSymbols) {
3733                         if ((! defined($KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"})) || $KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"} != 1) {
3734                             &LogWarning ($file, $., "Section $real_symbol is not defined in the $MODULE-section.txt file.");
3735                         }
3736                     }
3738                     #print "SECTION DOCS found in source for : '$real_symbol'\n";
3739                     $ignore_broken_returns = 1;
3740                     for ($k = 0; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3741                         #print "   '".$params[$k]."'\n";
3742                         $params[$k] = "\L$params[$k]";
3743                         undef $key;
3744                         if ($params[$k] eq "short_description") {
3745                             $key = "$TMPL_DIR/$real_symbol:Short_Description";
3746                         } elsif ($params[$k] eq "see_also") {
3747                             $key = "$TMPL_DIR/$real_symbol:See_Also";
3748                         } elsif ($params[$k] eq "title") {
3749                             $key = "$TMPL_DIR/$real_symbol:Title";
3750                         } elsif ($params[$k] eq "stability") {
3751                             $key = "$TMPL_DIR/$real_symbol:Stability_Level";
3752                         } elsif ($params[$k] eq "section_id") {
3753                             $key = "$TMPL_DIR/$real_symbol:Section_Id";
3754                         } elsif ($params[$k] eq "include") {
3755                             $key = "$TMPL_DIR/$real_symbol:Include";
3756                         } elsif ($params[$k] eq "image") {
3757                             $key = "$TMPL_DIR/$real_symbol:Image";
3758                         }
3759                         if (defined($key)) {
3760                             $SourceSymbolDocs{$key}=$params[$k+1];
3761                             $SourceSymbolSourceFile{$key} = $file;
3762                             $SourceSymbolSourceLine{$key} = $.;
3763                         }
3764                     }
3765                     $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
3766                     $SourceSymbolSourceFile{"$TMPL_DIR/$real_symbol:Long_Description"} = $file;
3767                     $SourceSymbolSourceLine{"$TMPL_DIR/$real_symbol:Long_Description"} = $.;
3768                     #$SourceSymbolTypes{$symbol} = "SECTION";
3769                 } else {
3770                     #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
3771                     $SourceSymbolDocs{$symbol} = $description;
3772                     $SourceSymbolParams{$symbol} = [ @params ];
3773                     # FIXME $SourceSymbolTypes{$symbol} = "STRUCT,SIGNAL,ARG,FUNCTION,MACRO";
3774                     #if (defined $DeclarationTypes{$symbol}) {
3775                     #    $SourceSymbolTypes{$symbol} = $DeclarationTypes{$symbol}
3776                     #}
3777                     $SourceSymbolSourceFile{$symbol} = $file;
3778                     $SourceSymbolSourceLine{$symbol} = $.;
3779                 }
3781                 if ($since_desc) {
3782                      ($since_desc, my @extra_lines) = split ("\n", $since_desc);
3783                      $since_desc =~ s/^\s+//;
3784                      $since_desc =~ s/\s+$//;
3785                      #print "Since($symbol) : [$since_desc]\n";
3786                      $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
3787                      if(scalar @extra_lines) {
3788                          &LogWarning ($file, $., "multi-line since docs found");
3789                      }
3790                 }
3792                 if ($stability_desc) {
3793                     $stability_desc = &ParseStabilityLevel($stability_desc, $file, $., "Stability level for $symbol");
3794                     $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
3795                 }
3797                 if ($deprecated_desc) {
3798                     if (exists $Deprecated{$symbol}) {
3799                     }
3800                     else {
3801                          # don't warn for signals and properties
3802                          #if ($symbol !~ m/::?(.*)/) {
3803                          if (defined $DeclarationTypes{$symbol}) {
3804                              &LogWarning ($file, $.,
3805                                  "$symbol is deprecated in the inline comments, but no deprecation guards were found around the declaration.".
3806                                  " (See the --deprecated-guards option for gtkdoc-scan.)");
3807                          }
3808                     }
3809                     $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
3810                 }
3811             }
3813             $in_comment_block = 0;
3814             next;
3815         }
3817         # Get rid of ' * ' at start of every line in the comment block.
3818         s%^\s*\*\s?%%;
3819         # But make sure we don't get rid of the newline at the end.
3820         if (!$_) {
3821             $_ = "\n";
3822         }
3823         #print "DEBUG: scanning :$_";
3825         # If we haven't found the symbol name yet, look for it.
3826         if (!$symbol) {
3827             if (m%^\s*(SECTION:\s*\S+)%) {
3828                 $symbol = $1;
3829                 #print "SECTION DOCS found in source for : '$symbol'\n";
3830                 $ignore_broken_returns = 1;
3831             } elsif (m%^\s*([\w:-]*\w)\s*:?\s*(\([a-z ]+\)\s*)*$%) {
3832                 $symbol = $1;
3833                 #print "SYMBOL DOCS found in source for : '$symbol'\n";
3834             }
3835             next;
3836         }
3838         # If we're in the return value description, add it to the end.
3839         if ($in_return) {
3840             # If we find another valid returns line, we assume that the first
3841             # one was really part of the description.
3842             if (m/^\s*(returns:|return\s+value:)/i) {
3843                 if ($return_style eq 'broken') {
3844                     $description .= $return_start . $return_desc;
3845                 }
3846                 $return_start = $1;
3847                 if ($return_style eq 'sane') {
3848                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3849                 }
3850                 $return_style = 'sane';
3851                 $ignore_broken_returns = 1;
3852                 $return_desc = $';
3853             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3854                 $description .= $return_start . $return_desc;
3855                 $return_start = $1;
3856                 $return_style = 'broken';
3857                 $return_desc = $';
3858             } elsif (m%^\s*since:%i) {
3859                 $since_desc = $';
3860                 $in_since = 1;
3861                 $in_return = 0;
3862             } elsif (m%^\s*stability:%i) {
3863                 $stability_desc = $';
3864                 $in_stability = 1;
3865                 $in_return = 0;
3866             } elsif (m%^\s*deprecated:%i) {
3867                 $deprecated_desc = $';
3868                 $in_deprecated = 1;
3869                 $in_return = 0;
3870             } else {
3871                 $return_desc .= $_;
3872             }
3873             next;
3874         }
3876         if ($in_since) {
3877             if (m/^\s*(returns:|return\s+value:)/i) {
3878                 if ($return_style eq 'broken') {
3879                     $description .= $return_start . $return_desc;
3880                 }
3881                 $return_start = $1;
3882                 if ($return_style eq 'sane') {
3883                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3884                 }
3885                 $return_style = 'sane';
3886                 $ignore_broken_returns = 1;
3887                 $return_desc = $';
3888                 $in_return = 1;
3889                 $in_since = 0;
3890             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3891                 $return_start = $1;
3892                 $return_style = 'broken';
3893                 $return_desc = $';
3894                 $in_return = 1;
3895                 $in_since = 0;
3896             } elsif (m%^\s*deprecated:%i) {
3897                 $deprecated_desc = $';
3898                 $in_deprecated = 1;
3899                 $in_since = 0;
3900             } elsif (m%^\s*stability:%i) {
3901                 $stability_desc = $';
3902                 $in_stability = 1;
3903                 $in_since = 0;
3904             } else {
3905                 $since_desc .= $_;
3906             }
3907             next;
3908         }
3910         if ($in_stability) {
3911             if (m/^\s*(returns:|return\s+value:)/i) {
3912                 if ($return_style eq 'broken') {
3913                     $description .= $return_start . $return_desc;
3914                 }
3915                 $return_start = $1;
3916                 if ($return_style eq 'sane') {
3917                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3918                 }
3919                 $return_style = 'sane';
3920                 $ignore_broken_returns = 1;
3921                 $return_desc = $';
3922                 $in_return = 1;
3923                 $in_stability = 0;
3924             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3925                 $return_start = $1;
3926                 $return_style = 'broken';
3927                 $return_desc = $';
3928                 $in_return = 1;
3929                 $in_stability = 0;
3930             } elsif (m%^\s*deprecated:%i) {
3931                 $deprecated_desc = $';
3932                 $in_deprecated = 1;
3933                 $in_stability = 0;
3934             } elsif (m%^\s*since:%i) {
3935                 $since_desc = $';
3936                 $in_since = 1;
3937                 $in_stability = 0;
3938             } else {
3939                 $stability_desc .= $_;
3940             }
3941             next;
3942         }
3944         if ($in_deprecated) {
3945             if (m/^\s*(returns:|return\s+value:)/i) {
3946                 if ($return_style eq 'broken') {
3947                     $description .= $return_start . $return_desc;
3948                 }
3949                 $return_start = $1;
3950                 if ($return_style eq 'sane') {
3951                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3952                 }
3953                 $return_style = 'sane';
3954                 $ignore_broken_returns = 1;
3955                 $return_desc = $';
3956                 $in_return = 1;
3957                 $in_deprecated = 0;
3958             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3959                 $return_start = $1;
3960                 $return_style = 'broken';
3961                 $return_desc = $';
3962                 $in_return = 1;
3963                 $in_deprecated = 0;
3964             } elsif (m%^\s*since:%i) {
3965                 $since_desc = $';
3966                 $in_since = 1;
3967                 $in_deprecated = 0;
3968             } elsif (m%^\s*stability:%i) {
3969                 $stability_desc = $';
3970                 $in_stability = 1;
3971                 $in_deprecated = 0;
3972             } else {
3973                 $deprecated_desc .= $_;
3974             }
3975             next;
3976         }
3978         # If we're in the description part, check for the 'Returns:' line.
3979         # If that isn't found, add the text to the end.
3980         if ($in_description) {
3981             # Get rid of 'Description:'
3982             s%^\s*Description:%%;
3984             if (m/^\s*(returns:|return\s+value:)/i) {
3985                 if ($return_style eq 'broken') {
3986                     $description .= $return_start . $return_desc;
3987                 }
3988                 $return_start = $1;
3989                 if ($return_style eq 'sane') {
3990                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3991                 }
3992                 $return_style = 'sane';
3993                 $ignore_broken_returns = 1;
3994                 $return_desc = $';
3995                 $in_return = 1;
3996                 next;
3997             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3998                 $return_start = $1;
3999                 $return_style = 'broken';
4000                 $return_desc = $';
4001                 $in_return = 1;
4002                 next;
4003             } elsif (m%^\s*since:%i) {
4004                 $since_desc = $';
4005                 $in_since = 1;
4006                 next;
4007             } elsif (m%^\s*deprecated:%i) {
4008                 $deprecated_desc = $';
4009                 $in_deprecated = 1;
4010                 next;
4011             } elsif (m%^\s*stability:%i) {
4012                 $stability_desc = $';
4013                 $in_stability = 1;
4014                 next;
4015             }
4017             $description .= $_;
4018             next;
4019         }
4021         # We must be in the parameters. Check for the empty line below them.
4022         if (m%^\s*$%) {
4023             $in_description = 1;
4024             next;
4025         }
4027         # Look for a parameter name.
4028         if (m%^\s*@(\S+)\s*:\s*%) {
4029             my $param_name = $1;
4030             my $param_desc = $';
4032             #print "Found parameter: $param_name\n";
4033             # Allow '...' as the Varargs parameter.
4034             if ($param_name eq "...") {
4035                 $param_name = "Varargs";
4036             }
4037             if ("\L$param_name" eq "returns") {
4038                 $return_style = 'sane';
4039                 $ignore_broken_returns = 1;
4040             }
4041             push (@params, $param_name);
4042             push (@params, $param_desc);
4043             $current_param += $PARAM_FIELD_COUNT;
4044             next;
4045         }
4047         # We must be in the middle of a parameter description, so add it on
4048         # to the last element in @params.
4049         if ($current_param == -1) {
4050             &LogWarning ($file, $., "Parsing comment block file : parameter expected.");
4051         } else {
4052             $params[$#params] .= $_;
4053         }
4054     }
4055     close (SRCFILE);
4058 #############################################################################
4059 # Function    : OutputMissingDocumentation
4060 # Description : Outputs report of documentation coverage to a file
4062 # Arguments   : none
4063 #############################################################################
4065 sub OutputMissingDocumentation {
4066     my $old_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.txt";
4067     my $new_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.new";
4069     my $n_documented = 0;
4070     my $n_incomplete = 0;
4071     my $total = 0;
4072     my $symbol;
4073     my $percent;
4074     my $msg;
4075     my $buffer = "";
4076     my $buffer_deprecated = "";
4077     my $buffer_descriptions = "";
4079     open(UNDOCUMENTED, ">$new_undocumented_file")
4080       || die "Can't create $new_undocumented_file";
4082     foreach $symbol (sort (keys (%AllSymbols))) {
4083         # FIXME: should we print LogWarnings for undocumented stuff?
4084         # DEBUG
4085         #my $ssfile = &GetSymbolSourceFile($symbol);
4086         #my $ssline = &GetSymbolSourceLine($symbol);
4087         #my $location = "defined at " . (defined($ssfile)?$ssfile:"?") . ":" . (defined($ssline)?$ssline:"0") . "\n";
4088         # DEBUG
4089         if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include|Section_Id|Image)/) {
4090             $total++;
4091             if (exists ($AllDocumentedSymbols{$symbol})) {
4092                 $n_documented++;
4093                 if (exists ($AllIncompleteSymbols{$symbol})) {
4094                     $n_incomplete++;
4095                     $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4096                     #$buffer .= "\t0: ".$location;
4097                 }
4098             } elsif (exists $Deprecated{$symbol}) {
4099                 if (exists ($AllIncompleteSymbols{$symbol})) {
4100                     $n_incomplete++;
4101                     $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4102                     #$buffer .= "\t1a: ".$location;
4103                 } else {
4104                     $buffer_deprecated .= $symbol . "\n";
4105                     #$buffer .= "\t1b: ".$location;
4106                 }
4107             } else {
4108                 if (exists ($AllIncompleteSymbols{$symbol})) {
4109                     $n_incomplete++;
4110                     $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4111                     #$buffer .= "\t2a: ".$location;
4112                 } else {
4113                     $buffer .= $symbol . "\n";
4114                     #$buffer .= "\t2b: ".$location;
4115                 }
4116             }
4117         } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
4118             $total++;
4119             #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
4120             #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
4121             #print "%%%% $symbol : $len1,$len2\n";
4122             if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
4123             || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
4124               $n_documented++;
4125             } else {
4126               # cut off the leading namespace ($TMPL_DIR)
4127               $symbol =~ m/^.*\/(.*)$/;
4128               $buffer_descriptions .= $1 . "\n";
4129             }
4130         }
4131     }
4133     $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
4135     if ($total == 0) {
4136       $percent = 100;
4137     } else {
4138       $percent = ($n_documented / $total) * 100.0;
4139     }
4141     printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
4142     print UNDOCUMENTED "$n_documented symbols documented.\n";
4143     print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
4144     print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
4146     print UNDOCUMENTED $buffer;
4147     close (UNDOCUMENTED);
4149     return &UpdateFileIfChanged ($old_undocumented_file, $new_undocumented_file, 0);
4151     printf "%.0f%% symbol docs coverage", $percent;
4152     print "($n_documented symbols documented, $n_incomplete symbols incomplete, " . ($total - $n_documented) . " not documented)\n";
4153     print "See $MODULE-undocumented.txt for a list of missing docs.\nThe doc coverage percentage doesn't include intro sections.\n";
4157 #############################################################################
4158 # Function    : OutputUndeclaredSymbols
4159 # Description : Outputs symbols that are listed in the section file, but not
4160 #               declaration is found in the sources
4162 # Arguments   : none
4163 #############################################################################
4165 sub OutputUndeclaredSymbols {
4166     my $old_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.txt";
4167     my $new_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.new";
4169     open(UNDECLARED, ">$new_undeclared_file")
4170         || die "Can't create $new_undeclared_file";
4172     if (%UndeclaredSymbols) {
4173         print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
4174         print UNDECLARED "\n";
4175         print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
4176     }
4177     close(UNDECLARED);
4179     return &UpdateFileIfChanged ($old_undeclared_file, $new_undeclared_file, 0);
4182 #############################################################################
4183 # Function    : OutputUnusedSymbols
4184 # Description : Outputs symbols that are documented in comments, but not
4185 #               declared in the sources
4187 # Arguments   : none
4188 #############################################################################
4190 sub OutputUnusedSymbols {
4191     my $num_unused = 0;
4192     my $old_unused_file = "$ROOT_DIR/$MODULE-unused.txt";
4193     my $new_unused_file = "$ROOT_DIR/$MODULE-unused.new";
4195     open (UNUSED, ">$new_unused_file")
4196         || die "Can't open $new_unused_file";
4197     my ($symbol);
4198     foreach $symbol (sort keys (%Declarations)) {
4199         if (!defined ($DeclarationOutput{$symbol})) {
4200             print (UNUSED "$symbol\n");
4201             $num_unused++;
4202         }
4203     }
4204     foreach $symbol (sort (keys (%AllUnusedSymbols))) {
4205         print (UNUSED "$symbol(" . $AllUnusedSymbols{$symbol} . ")\n");
4206         $num_unused++;
4207     }
4208     close (UNUSED);
4209     if ($num_unused != 0) {
4210         &LogWarning ($old_unused_file, 1, "$num_unused unused declarations.".
4211             "They should be added to $MODULE-sections.txt in the appropriate place.");
4212     }
4214     return &UpdateFileIfChanged ($old_unused_file, $new_unused_file, 0);
4218 #############################################################################
4219 # Function    : OutputAllSymbols
4220 # Description : Outputs list of all symbols to a file
4222 # Arguments   : none
4223 #############################################################################
4225 sub OutputAllSymbols {
4226      my $n_documented = 0;
4227      my $total = 0;
4228      my $symbol;
4229      my $percent;
4230      my $msg;
4232      open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
4233           || die "Can't create $ROOT_DIR/$MODULE-symbols.txt: $!";
4235      foreach $symbol (sort (keys (%AllSymbols))) {
4236           print SYMBOLS $symbol . "\n";
4237      }
4239      close (SYMBOLS);
4242 #############################################################################
4243 # Function    : OutputSymbolsWithoutSince
4244 # Description : Outputs list of all symbols without a since tag to a file
4246 # Arguments   : none
4247 #############################################################################
4249 sub OutputSymbolsWithoutSince {
4250      my $n_documented = 0;
4251      my $total = 0;
4252      my $symbol;
4253      my $percent;
4254      my $msg;
4256      open (SYMBOLS, ">$ROOT_DIR/$MODULE-nosince.txt")
4257           || die "Can't create $ROOT_DIR/$MODULE-nosince.txt: $!";
4259      foreach $symbol (sort (keys (%SourceSymbolDocs))) {
4260          if (!defined $Since{$symbol}) {
4261              print SYMBOLS $symbol . "\n";
4262          }
4263      }
4265      close (SYMBOLS);
4269 #############################################################################
4270 # Function    : MergeSourceDocumentation
4271 # Description : This merges documentation read from a source file into the
4272 #               documentation read in from a template file.
4274 #               Parameter descriptions override any in the template files.
4275 #               Function descriptions are placed before any description from
4276 #               the template files.
4278 # Arguments   : none
4279 #############################################################################
4281 sub MergeSourceDocumentation {
4282     my $symbol;
4283     my @Symbols;
4285     if (scalar %SymbolDocs) {
4286         @Symbols=keys (%SymbolDocs);
4287         #print "num existing entries: ".(scalar @Symbols)."\n";
4288         #print "  ",$Symbols[0], " ",$Symbols[1],"\n";
4289     }
4290     else {
4291         # filter scanned declarations, with what we suppress from -sections.txt
4292         my %tmp = ();
4293         foreach $symbol (keys (%Declarations)) {
4294             if (defined($KnownSymbols{$symbol}) && $KnownSymbols{$symbol} == 1) {
4295                 $tmp{$symbol}=1;
4296             }
4297         }
4298         # , add the rest from -sections.txt
4299         foreach $symbol (keys (%KnownSymbols)) {
4300             if ($KnownSymbols{$symbol} == 1) {
4301                 $tmp{$symbol}=1;
4302             }
4303         }
4304         # and add whats found in the source
4305         foreach $symbol (keys (%SourceSymbolDocs)) {
4306             $tmp{$symbol}=1;
4307         }
4308         @Symbols = keys (%tmp);
4309         #print "num source entries: ".(scalar @Symbols)."\n";
4310     }
4311     foreach $symbol (@Symbols) {
4312         $AllSymbols{$symbol} = 1;
4314         my $have_tmpl_docs = 0;
4316         ## see if the symbol is documented in template
4317         my $tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4318         my $check_tmpl_doc =$tmpl_doc;
4319         # remove all xml-tags and whitespaces
4320         $check_tmpl_doc =~ s/<.*?>//g;
4321         $check_tmpl_doc =~ s/\s//g;
4322         # anything left ?
4323         if ($check_tmpl_doc ne "") {
4324             $have_tmpl_docs = 1;
4325             #print "## [$check_tmpl_doc]\n";
4326         } else {
4327             # if the docs have just an empty para, don't merge that.
4328             $check_tmpl_doc = $tmpl_doc;
4329             $check_tmpl_doc =~ s/(\s|\n)//msg;
4330             if ($check_tmpl_doc eq "<para></para>") {
4331                $tmpl_doc = "";
4332             }
4333         }
4335         if (exists ($SourceSymbolDocs{$symbol})) {
4336             my $type = $DeclarationTypes {$symbol};
4338             #print "merging [$symbol] from source\n";
4340             my $item = "Parameter";
4341             if (defined ($type)) {
4342                 if ($type eq 'STRUCT') {
4343                     $item = "Field";
4344                 } elsif ($type eq 'ENUM') {
4345                     $item = "Value";
4346                 } elsif ($type eq 'UNION') {
4347                     $item = "Field";
4348                 }
4349             } else {
4350                 $type="SIGNAL";
4351             }
4353             my $src_doc = $SourceSymbolDocs{$symbol};
4354             # remove leading and training whitespaces
4355             $src_doc =~ s/^\s+//;
4356             $src_doc =~ s/\s+$//;
4358             # Don't output warnings for overridden titles as titles are
4359             # automatically generated in the -sections.txt file, and thus they
4360             # are often overridden.
4361             if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
4362                 # check if content is different
4363                 if ($tmpl_doc ne $src_doc) {
4364                     #print "[$tmpl_doc] [$src_doc]\n";
4365                     &LogWarning ($SourceSymbolSourceFile{$symbol}, $SourceSymbolSourceLine{$symbol},
4366                         "Documentation in template ".$SymbolSourceFile{$symbol}.":".$SymbolSourceLine{$symbol}." for $symbol being overridden by inline comments.");
4367                 }
4368             }
4370             if ($src_doc ne "") {
4371                  $AllDocumentedSymbols{$symbol} = 1;
4372             }
4374             # Convert <!--PARAMETERS--> with any blank lines around it to
4375             # a </para> followed by <!--PARAMETERS--> followed by <para>.
4376             $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
4378             # Do not add <para> to nothing, it breaks missing docs checks.
4379             my $src_doc_para = "";
4380             if ($src_doc ne "") {
4381                 # Expand markdown (and do paragraphs)
4382                 $src_doc_para = &ConvertMarkDown ($src_doc, $symbol);
4383                 ## fixup xml markup
4384                 # FIXME: this is questionable, as we can't make assumtions on the content really
4385                 #$src_doc_para =~ s%^<para>\n(<refsect[1-9])%$1%gms;
4386                 #$src_doc_para =~ s%^<para>\n<para>%<para>%gms;
4387                 #$src_doc_para =~ s%(</refsect[1-9]>)\n</para>$%$1%gms;
4388                 #print "$symbol : [$src_doc][$src_doc_para]\n";
4389             }
4391             if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
4392                 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4393             } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
4394                 # For the title/summary/see also section docs we don't want to
4395                 # add any <para> tags.
4396                 $SymbolDocs{$symbol} = "$src_doc"
4397             } else {
4398                 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4399             }
4401             # merge parameters
4402             if ($symbol =~ m/.*::.*/) {
4403                 # For signals we prefer the param names from the source docs,
4404                 # since the ones from the templates are likely to contain the
4405                 # artificial argn names which are generated by gtkdoc-scangobj.
4406                 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4407                 # FIXME: we need to check for empty docs here as well!
4408             } else {
4409                 # The templates contain the definitive parameter names and order,
4410                 # so we will not change that. We only override the actual text.
4411                 my $tmpl_params = $SymbolParams{$symbol};
4412                 if (!defined ($tmpl_params)) {
4413                     #print "No merge needed for $symbol\n";
4414                     $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4415                     #  FIXME: we still like to get the number of params and merge
4416                     #  1) we would noticed that params have been removed/renamed
4417                     #  2) we would catch undocumented params
4418                     #  params are not (yet) exported in -decl.txt so that we
4419                     #  could easily grab them :/
4420                 } else {
4421                     my $params = $SourceSymbolParams{$symbol};
4422                     my $j;
4423                     #print "Merge needed for $symbol, tmpl_params: ",$#$tmpl_params,", source_params: ",$#$params," \n";
4424                     for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4425                         my $tmpl_param_name = $$tmpl_params[$j];
4427                         # Allow '...' as the Varargs parameter.
4428                         if ($tmpl_param_name eq "...") {
4429                             $tmpl_param_name = "Varargs";
4430                         }
4432                         # Try to find the param in the source comment documentation.
4433                         my $found = 0;
4434                         my $k;
4435                         #print "  try merge param $tmpl_param_name\n";
4436                         for ($k = 0; $k <= $#$params; $k += $PARAM_FIELD_COUNT) {
4437                             my $param_name = $$params[$k];
4438                             my $param_desc = $$params[$k + 1];
4440                             #print "    test param  $param_name\n";
4441                             # We accept changes in case, since the Gnome source
4442                             # docs contain a lot of these.
4443                             if ("\L$param_name" eq "\L$tmpl_param_name") {
4444                                 $found = 1;
4446                                 # Override the description.
4447                                 $$tmpl_params[$j + 1] = $param_desc;
4449                                 # Set the name to "" to mark it as used.
4450                                 $$params[$k] = "";
4451                                 last;
4452                             }
4453                         }
4455                         # If it looks like the parameters are there, but not
4456                         # in the right place, try to explain a bit better.
4457                         if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
4458                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4459                                 "Parameters for $symbol must start on the line immediately after the function or macro name.");
4460                         }
4461                     }
4463                     # Now we output a warning if parameters have been described which
4464                     # do not exist.
4465                     for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
4466                         my $param_name = $$params[$j];
4467                         if ($param_name) {
4468                             # the template builder cannot detect if a macro returns
4469                             # a result or not
4470                             if(($type eq "MACRO") && ($param_name eq "Returns")) {
4471                                 # FIXME: do we need to add it then to tmpl_params[] ?
4472                                 my $num=$#$tmpl_params;
4473                                 #print "  adding Returns: to macro docs for $symbol.\n";
4474                                 $$tmpl_params[$num+1]="Returns";
4475                                 $$tmpl_params[$num+2]=$$params[$j+1];
4476                                 next;
4477                             }
4478                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4479                                 "$item described in source code comment block but does not exist. $type: $symbol $item: $param_name.");
4480                         }
4481                     }
4482                 }
4483             }
4484         } else {
4485             if ($have_tmpl_docs) {
4486                 $AllDocumentedSymbols{$symbol} = 1;
4487                 #print "merging [$symbol] from template\n";
4488             }
4489             else {
4490                 #print "[$symbol] undocumented\n";
4491             }
4492         }
4494         # if this symbol is documented, check if docs are complete
4495         $check_tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4496         # remove all xml-tags and whitespaces
4497         $check_tmpl_doc =~ s/<.*?>//g;
4498         $check_tmpl_doc =~ s/\s//g;
4499         if ($check_tmpl_doc ne "") {
4500             my $tmpl_params = $SymbolParams{$symbol};
4501             if (defined ($tmpl_params)) {
4502                 my $type = $DeclarationTypes {$symbol};
4504                 my $item = "Parameter";
4505                 if (defined ($type)) {
4506                     if ($type eq 'STRUCT') {
4507                         $item = "Field";
4508                     } elsif ($type eq 'ENUM') {
4509                         $item = "Value";
4510                     } elsif ($type eq 'UNION') {
4511                         $item = "Field";
4512                     }
4513                 } else {
4514                     $type="SIGNAL";
4515                 }
4517                 #print "Check param docs for $symbol, tmpl_params: ",$#$tmpl_params," entries, type=$type\n";
4519                 if ($#$tmpl_params > 0) {
4520                     my $j;
4521                     for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4522                         # Output a warning if the parameter is empty and
4523                         # remember for stats.
4524                         my $tmpl_param_name = $$tmpl_params[$j];
4525                         my $tmpl_param_desc = $$tmpl_params[$j + 1];
4526                         if ($tmpl_param_name ne "void" && $tmpl_param_desc !~ m/\S/) {
4527                             if (exists ($AllIncompleteSymbols{$symbol})) {
4528                                 $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
4529                             } else {
4530                                 $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
4531                             }
4532                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4533                                 "$item description for $symbol"."::"."$tmpl_param_name is missing in source code comment block.");
4534                         }
4535                     }
4536                 }
4537                 else {
4538                     if ($#$tmpl_params == 0) {
4539                         $AllIncompleteSymbols{$symbol}="<items>";
4540                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4541                             "$item descriptions for $symbol are missing in source code comment block.");
4542                     }
4543                     # $#$tmpl_params==-1 means we don't know about parameters
4544                     # this unfortunately does not tell if there should be some
4545                 }
4546             }
4547         }
4548    }
4549    #print "num doc entries: ".(scalar %SymbolDocs)."\n";
4552 #############################################################################
4553 # Function    : IsEmptyDoc
4554 # Description : Check if a doc-string is empty. Its also regarded as empty if
4555 #               it only consist of whitespace or e.g. FIXME.
4556 # Arguments   : the doc-string
4557 #############################################################################
4558 sub IsEmptyDoc {
4559     my ($doc) = @_;
4561     if ($doc =~ /^\s*$/) {
4562         return 1;
4563     }
4565     if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
4566         return 1;
4567     }
4569     return 0;
4573 #############################################################################
4574 # Function    : ConvertMarkDown
4575 # Description : Converts mark down syntax to the respective docbook, but only
4576 #               outside CDATA and <programlisting> tags.
4577 #               http://de.wikipedia.org/wiki/Markdown
4578 #               Code snippets have been takesn from
4579 #               http://daringfireball.net/projects/markdown/
4580 #                 Copyright (c) 2004 John Gruber
4581 # Arguments   : the doc-string, the symbol name
4582 #############################################################################
4583 my $md_in_refsect2;
4584 sub ConvertMarkDown {
4585     my ($text, $symbol) = @_;
4587     # reset state
4588     $md_in_refsect2=0;
4590     # convert
4591     $text = &ModifyXMLElements ($text, $symbol,
4592                                "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
4593                                \&ConvertMarkDownEndTag,
4594                                \&ConvertMarkDownCallback);
4595     # encapsulate and terminate
4596     $text = "<para>\n$text\n</para>";
4597     if ($md_in_refsect2==1) {
4598         $text = "$text</refsect2>"
4599     }
4600     return $text
4603 sub ConvertMarkDownEndTag {
4604   if ($_[0] eq "<!\[CDATA\[") {
4605     return "]]>";
4606   } elsif ($_[0] eq "|[") {
4607     return "]\\|";
4608   } else {
4609     return "</programlisting>";
4610   }
4613 sub ConvertMarkDownCallback {
4614   my ($text, $symbol, $tag) = @_;
4616   # If we're not in CDATA or a <programlisting> we convert blank lines so
4617   # they start a new <para>.
4618   if ($tag eq "") {
4619     my $end_of_para="";
4620     my $end_of_section="";
4621     my $have_list=0;
4623     $end_of_para = "$end_of_para</para>";
4624     $end_of_section = "$end_of_section</para>";
4625     if ($md_in_refsect2==1) {
4626         $end_of_section= "$end_of_section</refsect2>";
4627     }
4629     # Setext-style headers:
4630     #     Header 1
4631     #     ========
4632     #
4633     #     Header 2
4634     #     --------
4635     #
4636     if($text =~ s%^\n(.+)[ \t]*\n=+[ \t]*\n\n%$end_of_section<refsect2><title>$1</title><para>\n%gm) {
4637         $md_in_refsect2=1;
4638     }
4640     # atx-style headers:
4641     #   # Header 1
4642     #   ## Header 2
4643     #   ## Header 2 with closing hashes ##
4644     #   ...
4645     #   ###### Header 6
4646     #
4647     if($text =~ s%^\n\#[ \t]*(.+?)[ \t]*\#\n+%$end_of_section<refsect2><title>$1</title><para>\n%gm) {
4648         $md_in_refsect2=1;
4649     }
4651     # Simple (unnested) lists:
4652     #   Please select:
4653     #   - item 1
4654     #   - item 2 with loooong
4655     #     description
4656     #   - item 3
4657     #
4658     #   New paragraph.
4659     $text.="\n"; # we need a new line to avoid too complicated matching rules below
4660     if ($text =~ s%(?<=\n)-\s+(.+?)(?=(?:\n-\s+)|(?:\n\n)|(?:\n$))%<listitem><para>$1</para></listitem>%gs) {
4661         $text =~ s%(?<!</listitem>)(\n<listitem>)%\n<itemizedlist>$1%g;
4662         $text =~ s%(</listitem>\n)(?!<listitem>)%$1</itemizedlist>\n%g;
4663     }
4664     chomp $text;
4666     # Make Paragraphs on blank lines
4667     $text =~ s%\n{2,}%\n$end_of_para\n<para>\n%g;
4668   }
4670   return $text;
4674 #############################################################################
4675 # LIBRARY FUNCTIONS -   These functions are used in both gtkdoc-mkdb and
4676 #                       gtkdoc-mktmpl and should eventually be moved to a
4677 #                       separate library.
4678 #############################################################################
4680 #############################################################################
4681 # Function    : ReadDeclarationsFile
4682 # Description : This reads in a file containing the function/macro/enum etc.
4683 #               declarations.
4685 #               Note that in some cases there are several declarations with
4686 #               the same name, e.g. for conditional macros. In this case we
4687 #               set a flag in the %DeclarationConditional hash so the
4688 #               declaration is not shown in the docs.
4690 #               If a macro and a function have the same name, e.g. for
4691 #               gtk_object_ref, the function declaration takes precedence.
4693 #               Some opaque structs are just declared with 'typedef struct
4694 #               _name name;' in which case the declaration may be empty.
4695 #               The structure may have been found later in the header, so
4696 #               that overrides the empty declaration.
4698 # Arguments   : $file - the declarations file to read
4699 #               $override - if declarations in this file should override
4700 #                       any current declaration.
4701 #############################################################################
4703 sub ReadDeclarationsFile {
4704     my ($file, $override) = @_;
4706     if ($override == 0) {
4707         %Declarations = ();
4708         %DeclarationTypes = ();
4709         %DeclarationConditional = ();
4710         %DeclarationOutput = ();
4711     }
4713     open (INPUT, $file)
4714         || die "Can't open $file: $!";
4715     my $declaration_type = "";
4716     my $declaration_name;
4717     my $declaration;
4718     my $is_deprecated = 0;
4719     while (<INPUT>) {
4720         if (!$declaration_type) {
4721             if (m/^<([^>]+)>/) {
4722                 $declaration_type = $1;
4723                 $declaration_name = "";
4724                 #print "Found declaration: $declaration_type\n";
4725                 $declaration = "";
4726             }
4727         } else {
4728             if (m%^<NAME>(.*)</NAME>%) {
4729                 $declaration_name = $1;
4730             } elsif (m%^<DEPRECATED/>%) {
4731                 $is_deprecated = 1;
4732             } elsif (m%^</$declaration_type>%) {
4733                 #print "Found end of declaration: $declaration_name\n";
4734                 # Check that the declaration has a name
4735                 if ($declaration_name eq "") {
4736                     print "ERROR: $declaration_type has no name $file:$.\n";
4737                 }
4739                 # If the declaration is an empty typedef struct _XXX XXX
4740                 # set the flag to indicate the struct has a typedef.
4741                 if ($declaration_type eq 'STRUCT'
4742                     && $declaration =~ m/^\s*$/) {
4743                     #print "Struct has typedef: $declaration_name\n";
4744                     $StructHasTypedef{$declaration_name} = 1;
4745                 }
4747                 # Check if the symbol is already defined.
4748                 if (defined ($Declarations{$declaration_name})
4749                     && $override == 0) {
4750                     # Function declarations take precedence.
4751                     if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
4752                         # Ignore it.
4753                     } elsif ($declaration_type eq 'FUNCTION') {
4754                         if ($is_deprecated) {
4755                             $Deprecated{$declaration_name} = "";
4756                         }
4757                         $Declarations{$declaration_name} = $declaration;
4758                         $DeclarationTypes{$declaration_name} = $declaration_type;
4759                     } elsif ($DeclarationTypes{$declaration_name}
4760                               eq $declaration_type) {
4761                         # If the existing declaration is empty, or is just a
4762                         # forward declaration of a struct, override it.
4763                         if ($declaration_type eq 'STRUCT') {
4764                             if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4765                                 if ($is_deprecated) {
4766                                     $Deprecated{$declaration_name} = "";
4767                                 }
4768                                 $Declarations{$declaration_name} = $declaration;
4769                             } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4770                                 # Ignore an empty or forward declaration.
4771                             } else {
4772                                 &LogWarning ($file, $., "Structure $declaration_name has multiple definitions.");
4773                             }
4774                         } else {
4775                             # set flag in %DeclarationConditional hash for
4776                             # multiply defined macros/typedefs.
4777                             $DeclarationConditional{$declaration_name} = 1;
4778                         }
4779                     } else {
4780                         &LogWarning ($file, $., "$declaration_name has multiple definitions.");
4781                     }
4782                 } else {
4783                     if ($is_deprecated) {
4784                         $Deprecated{$declaration_name} = "";
4785                     }
4786                     $Declarations{$declaration_name} = $declaration;
4787                     $DeclarationTypes{$declaration_name} = $declaration_type;
4788                 }
4790                 $declaration_type = "";
4791                 $is_deprecated = 0;
4792             } else {
4793                 $declaration .= $_;
4794             }
4795         }
4796     }
4797     close (INPUT);
4801 #############################################################################
4802 # Function    : ReadSignalsFile
4803 # Description : This reads in an existing file which contains information on
4804 #               all GTK signals. It creates the arrays @SignalNames and
4805 #               @SignalPrototypes containing info on the signals. The first
4806 #               line of the SignalPrototype is the return type of the signal
4807 #               handler. The remaining lines are the parameters passed to it.
4808 #               The last parameter, "gpointer user_data" is always the same
4809 #               so is not included.
4810 # Arguments   : $file - the file containing the signal handler prototype
4811 #                       information.
4812 #############################################################################
4814 sub ReadSignalsFile {
4815     my ($file) = @_;
4817     my $in_signal = 0;
4818     my $signal_object;
4819     my $signal_name;
4820     my $signal_returns;
4821     my $signal_flags;
4822     my $signal_prototype;
4824     # Reset the signal info.
4825     @SignalObjects = ();
4826     @SignalNames = ();
4827     @SignalReturns = ();
4828     @SignalFlags = ();
4829     @SignalPrototypes = ();
4831     if (! -f $file) {
4832         return;
4833     }
4834     if (!open (INPUT, $file)) {
4835         warn "Can't open $file - skipping signals\n";
4836         return;
4837     }
4838     while (<INPUT>) {
4839         if (!$in_signal) {
4840             if (m/^<SIGNAL>/) {
4841                 $in_signal = 1;
4842                 $signal_object = "";
4843                 $signal_name = "";
4844                 $signal_returns = "";
4845                 $signal_prototype = "";
4846             }
4847         } else {
4848             if (m/^<NAME>(.*)<\/NAME>/) {
4849                 $signal_name = $1;
4850                 if ($signal_name =~ m/^(.*)::(.*)$/) {
4851                     $signal_object = $1;
4852                     ($signal_name = $2) =~ s/_/-/g;
4853                     #print "Found signal: $signal_name\n";
4854                 } else {
4855                     &LogWarning ($file, $., "Invalid signal name: $signal_name.");
4856                 }
4857             } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
4858                 $signal_returns = $1;
4859             } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4860                 $signal_flags = $1;
4861             } elsif (m%^</SIGNAL>%) {
4862                 #print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
4863                 push (@SignalObjects, $signal_object);
4864                 push (@SignalNames, $signal_name);
4865                 push (@SignalReturns, $signal_returns);
4866                 push (@SignalFlags, $signal_flags);
4867                 push (@SignalPrototypes, $signal_prototype);
4868                 $in_signal = 0;
4869             } else {
4870                 $signal_prototype .= $_;
4871             }
4872         }
4873     }
4874     close (INPUT);
4878 #############################################################################
4879 # Function    : ReadTemplateFile
4880 # Description : This reads in the manually-edited documentation file
4881 #               corresponding to the file currently being created, so we can
4882 #               insert the documentation at the appropriate places.
4883 #               It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
4884 #               is a hash of arrays.
4885 #               NOTE: This function is duplicated in gtkdoc-mktmpl (but
4886 #               slightly different).
4887 # Arguments   : $docsfile - the template file to read in.
4888 #               $skip_unused_params - 1 if the unused parameters should be
4889 #                       skipped.
4890 #############################################################################
4892 sub ReadTemplateFile {
4893     my ($docsfile, $skip_unused_params) = @_;
4895     my $template = "$docsfile.sgml";
4896     if (! -f $template) {
4897         #print "File doesn't exist: $template\n";
4898         return 0;
4899     }
4900     #print "Reading $template\n";
4902     # start with empty hashes, we merge the source comment for each file
4903     # afterwards
4904     %SymbolDocs = ();
4905     %SymbolTypes = ();
4906     %SymbolParams = ();
4908     my $current_type = "";      # Type of symbol being read.
4909     my $current_symbol = "";    # Name of symbol being read.
4910     my $symbol_doc = "";                # Description of symbol being read.
4911     my @params;                 # Parameter names and descriptions of current
4912                                 #   function/macro/function typedef.
4913     my $current_param = -1;     # Index of parameter currently being read.
4914                                 #   Note that the param array contains pairs
4915                                 #   of param name & description.
4916     my $in_unused_params = 0;   # True if we are reading in the unused params.
4917     my $in_deprecated = 0;
4918     my $in_since = 0;
4919     my $in_stability = 0;
4921     open (DOCS, "$template")
4922         || die "Can't open $template: $!";
4923     while (<DOCS>) {
4924         if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
4925             my $type = $1;
4926             my $symbol = $2;
4927             if ($symbol eq "Title"
4928                 || $symbol eq "Short_Description"
4929                 || $symbol eq "Long_Description"
4930                 || $symbol eq "See_Also"
4931                 || $symbol eq "Stability_Level"
4932                 || $symbol eq "Include"
4933                 || $symbol eq "Image") {
4935                 $symbol = $docsfile . ":" . $symbol;
4936             }
4938             #print "Found symbol: $symbol\n";
4939             # Remember file and line for the symbol
4940             $SymbolSourceFile{$symbol} = $template;
4941             $SymbolSourceLine{$symbol} = $.;
4943             # Store previous symbol, but remove any trailing blank lines.
4944             if ($current_symbol ne "") {
4945                 $symbol_doc =~ s/\s+$//;
4946                 $SymbolTypes{$current_symbol} = $current_type;
4947                 $SymbolDocs{$current_symbol} = $symbol_doc;
4949                 # Check that the stability level is valid.
4950                 if ($StabilityLevel{$current_symbol}) {
4951                     $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4952                 }
4954                 if ($current_param >= 0) {
4955                     $SymbolParams{$current_symbol} = [ @params ];
4956                 } else {
4957                     # Delete any existing params in case we are overriding a
4958                     # previously read template.
4959                     delete $SymbolParams{$current_symbol};
4960                 }
4961             }
4962             $current_type = $type;
4963             $current_symbol = $symbol;
4964             $current_param = -1;
4965             $in_unused_params = 0;
4966             $in_deprecated = 0;
4967             $in_since = 0;
4968             $in_stability = 0;
4969             $symbol_doc = "";
4970             @params = ();
4972         } elsif (m/^<!-- # Unused Parameters # -->/) {
4973             #print "DEBUG: Found unused parameters\n";
4974             $in_unused_params = 1;
4975             next;
4977         } elsif ($in_unused_params && $skip_unused_params) {
4978             # When outputting the DocBook we skip unused parameters.
4979             #print "DEBUG: Skipping unused param: $_";
4980             next;
4982         } else {
4983             # Check if param found. Need to handle "..." and "format...".
4984             if (s/^\@([\w\.]+):\040?//) {
4985                 my $param_name = $1;
4986                 my $param_desc = $_;
4987                 # Allow variations of 'Returns'
4988                 if ($param_name =~ m/^[Rr]eturns?$/) {
4989                     $param_name = "Returns";
4990                 }
4992                 # strip trailing whitespaces and blank lines
4993                 s/\s+\n$/\n/m;
4994                 s/\n+$/\n/sm;
4995                 #print "Found param for symbol $current_symbol : '$param_name'= '$_'";
4997                 if ($param_name eq "Deprecated") {
4998                     $in_deprecated = 1;
4999                     $Deprecated{$current_symbol} = $_;
5000                 } elsif ($param_name eq "Since") {
5001                     $in_since = 1;
5002                     chomp;
5003                     $Since{$current_symbol} = $_;
5004                 } elsif ($param_name eq "Stability") {
5005                     $in_stability = 1;
5006                     $StabilityLevel{$current_symbol} = $_;
5007                 } else {
5008                     push (@params, $param_name);
5009                     push (@params, $param_desc);
5010                     $current_param += $PARAM_FIELD_COUNT;
5011                 }
5012             } else {
5013                 # strip trailing whitespaces and blank lines
5014                 s/\s+\n$/\n/m;
5015                 s/\n+$/\n/sm;
5017                 if (!m/^\s+$/) {
5018                     if ($in_deprecated) {
5019                         $Deprecated{$current_symbol} .= $_;
5020                     } elsif ($in_since) {
5021                         &LogWarning ($template, $., "multi-line since docs found");
5022                         #$Since{$current_symbol} .= $_;
5023                     } elsif ($in_stability) {
5024                         $StabilityLevel{$current_symbol} .= $_;
5025                     } elsif ($current_param >= 0) {
5026                         $params[$current_param] .= $_;
5027                     } else {
5028                         $symbol_doc .= $_;
5029                     }
5030                 }
5031             }
5032         }
5033     }
5035     # Remember to finish the current symbol doccs.
5036     if ($current_symbol ne "") {
5038         $symbol_doc =~ s/\s+$//;
5039         $SymbolTypes{$current_symbol} = $current_type;
5040         $SymbolDocs{$current_symbol} = $symbol_doc;
5042         # Check that the stability level is valid.
5043         if ($StabilityLevel{$current_symbol}) {
5044             $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
5045         }
5047         if ($current_param >= 0) {
5048             $SymbolParams{$current_symbol} = [ @params ];
5049         } else {
5050             # Delete any existing params in case we are overriding a
5051             # previously read template.
5052             delete $SymbolParams{$current_symbol};
5053         }
5054     }
5056     close (DOCS);
5057     return 1;
5061 #############################################################################
5062 # Function    : ReadObjectHierarchy
5063 # Description : This reads in the $MODULE-hierarchy.txt file containing all
5064 #               the GtkObject subclasses described in this module (and their
5065 #               ancestors).
5066 #               It places them in the @Objects array, and places their level
5067 #               in the object hierarchy in the @ObjectLevels array, at the
5068 #               same index. GtkObject, the root object, has a level of 1.
5070 #               FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
5071 #               as it goes along, this should be split out into a separate
5072 #               function.
5074 # Arguments   : none
5075 #############################################################################
5077 sub ReadObjectHierarchy {
5078     @Objects = ();
5079     @ObjectLevels = ();
5081     if (! -f $OBJECT_TREE_FILE) {
5082         return;
5083     }
5084     if (!open (INPUT, $OBJECT_TREE_FILE)) {
5085         warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
5086         return;
5087     }
5089     # FIXME: use $OUTPUT_FORMAT
5090     # my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.$OUTPUT_FORMAT";
5091     my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
5092     my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
5094     open (OUTPUT, ">$new_tree_index")
5095         || die "Can't create $new_tree_index: $!";
5097     if ($OUTPUT_FORMAT eq "xml") {
5098         my $tree_header = $doctype_header;
5100         $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
5101         print (OUTPUT "$tree_header");
5102     }
5103     print (OUTPUT "<screen>\n");
5105     # Only emit objects if they are supposed to be documented, or if
5106     # they have documented children. To implement this, we maintain a
5107     # stack of pending objects which will be emitted if a documented
5108     # child turns up.
5109     my @pending_objects = ();
5110     my @pending_levels = ();
5111     while (<INPUT>) {
5112         if (m/\S+/) {
5113             my $object = $&;
5114             my $level = (length($`)) / 2 + 1;
5115             my $xref = "";
5117             while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
5118                 my $pobject = pop(@pending_objects);
5119                 my $plevel = pop(@pending_levels);
5120             }
5122             push (@pending_objects, $object);
5123             push (@pending_levels, $level);
5125             if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5126                 while ($#pending_levels >= 0) {
5127                     $object = shift @pending_objects;
5128                     $level = shift @pending_levels;
5129                     $xref = &MakeXRef ($object);
5131                     print (OUTPUT ' ' x ($level * 4), "$xref\n");
5132                     push (@Objects, $object);
5133                     push (@ObjectLevels, $level);
5134                 }
5135             }
5136             #else {
5137             #    LogWarning ($OBJECT_TREE_FILE, $., "unknown type $object");
5138             #}
5139         }
5140     }
5141     print (OUTPUT "</screen>\n");
5143     close (INPUT);
5144     close (OUTPUT);
5146     &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
5148     &OutputObjectList;
5151 #############################################################################
5152 # Function    : ReadInterfaces
5153 # Description : This reads in the $MODULE.interfaces file.
5155 # Arguments   : none
5156 #############################################################################
5158 sub ReadInterfaces {
5159     %Interfaces = ();
5161     if (! -f $INTERFACES_FILE) {
5162         return;
5163     }
5164     if (!open (INPUT, $INTERFACES_FILE)) {
5165         warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
5166         return;
5167     }
5169     while (<INPUT>) {
5170        chomp;
5171        my ($object, @ifaces) = split;
5172        if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5173            my @knownIfaces = ();
5175            # filter out private interfaces, but leave foreign interfaces
5176            foreach my $iface (@ifaces) {
5177                if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
5178                    push (@knownIfaces, $iface);
5179                }
5180              }
5182            $Interfaces{$object} = join(' ', @knownIfaces);
5183        }
5184     }
5185     close (INPUT);
5188 #############################################################################
5189 # Function    : ReadPrerequisites
5190 # Description : This reads in the $MODULE.prerequisites file.
5192 # Arguments   : none
5193 #############################################################################
5195 sub ReadPrerequisites {
5196     %Prerequisites = ();
5198     if (! -f $PREREQUISITES_FILE) {
5199         return;
5200     }
5201     if (!open (INPUT, $PREREQUISITES_FILE)) {
5202         warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
5203         return;
5204     }
5206     while (<INPUT>) {
5207        chomp;
5208        my ($iface, @prereqs) = split;
5209        if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
5210            my @knownPrereqs = ();
5212            # filter out private prerequisites, but leave foreign prerequisites
5213            foreach my $prereq (@prereqs) {
5214                if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
5215                   push (@knownPrereqs, $prereq);
5216                }
5217            }
5219            $Prerequisites{$iface} = join(' ', @knownPrereqs);
5220        }
5221     }
5222     close (INPUT);
5225 #############################################################################
5226 # Function    : ReadArgsFile
5227 # Description : This reads in an existing file which contains information on
5228 #               all GTK args. It creates the arrays @ArgObjects, @ArgNames,
5229 #               @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
5230 #               on the args.
5231 # Arguments   : $file - the file containing the arg information.
5232 #############################################################################
5234 sub ReadArgsFile {
5235     my ($file) = @_;
5237     my $in_arg = 0;
5238     my $arg_object;
5239     my $arg_name;
5240     my $arg_type;
5241     my $arg_flags;
5242     my $arg_nick;
5243     my $arg_blurb;
5244     my $arg_default;
5245     my $arg_range;
5247     # Reset the args info.
5248     @ArgObjects = ();
5249     @ArgNames = ();
5250     @ArgTypes = ();
5251     @ArgFlags = ();
5252     @ArgNicks = ();
5253     @ArgBlurbs = ();
5254     @ArgDefaults = ();
5255     @ArgRanges = ();
5257     if (! -f $file) {
5258         return;
5259     }
5260     if (!open (INPUT, $file)) {
5261         warn "Can't open $file - skipping args\n";
5262         return;
5263     }
5264     while (<INPUT>) {
5265         if (!$in_arg) {
5266             if (m/^<ARG>/) {
5267                 $in_arg = 1;
5268                 $arg_object = "";
5269                 $arg_name = "";
5270                 $arg_type = "";
5271                 $arg_flags = "";
5272                 $arg_nick = "";
5273                 $arg_blurb = "";
5274                 $arg_default = "";
5275                 $arg_range = "";
5276             }
5277         } else {
5278             if (m/^<NAME>(.*)<\/NAME>/) {
5279                 $arg_name = $1;
5280                 if ($arg_name =~ m/^(.*)::(.*)$/) {
5281                     $arg_object = $1;
5282                     ($arg_name = $2) =~ s/_/-/g;
5283                     #print "Found arg: $arg_name\n";
5284                 } else {
5285                     &LogWarning ($file, $., "Invalid argument name: $arg_name");
5286                 }
5287             } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
5288                 $arg_type = $1;
5289             } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
5290                 $arg_range = $1;
5291             } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
5292                 $arg_flags = $1;
5293             } elsif (m/^<NICK>(.*)<\/NICK>/) {
5294                 $arg_nick = $1;
5295             } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
5296                 $arg_blurb = $1;
5297                 if ($arg_blurb eq "(null)") {
5298                   $arg_blurb = "";
5299                   &LogWarning ($file, $., "Property ${arg_object}:${arg_name} has no documentation.");
5300                 }
5301             } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
5302                 $arg_default = $1;
5303             } elsif (m%^</ARG>%) {
5304                 #print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
5305                 push (@ArgObjects, $arg_object);
5306                 push (@ArgNames, $arg_name);
5307                 push (@ArgTypes, $arg_type);
5308                 push (@ArgRanges, $arg_range);
5309                 push (@ArgFlags, $arg_flags);
5310                 push (@ArgNicks, $arg_nick);
5311                 push (@ArgBlurbs, $arg_blurb);
5312                 push (@ArgDefaults, $arg_default);
5313                 $in_arg = 0;
5314             }
5315         }
5316     }
5317     close (INPUT);
5321 #############################################################################
5322 # Function    : CheckIsObject
5323 # Description : Returns 1 if the given name is a GObject or a subclass.
5324 #               It uses the global @Objects array.
5325 #               Note that the @Objects array only contains classes in the
5326 #               current module and their ancestors - not all GObject classes.
5327 # Arguments   : $name - the name to check.
5328 #############################################################################
5330 sub CheckIsObject {
5331     my ($name) = @_;
5333     my $object;
5334     foreach $object (@Objects) {
5335         if ($object eq $name) {
5336             return 1;
5337         }
5338     }
5339     return 0;
5343 #############################################################################
5344 # Function    : MakeReturnField
5345 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
5346 # Arguments   : $str - the string to pad.
5347 #############################################################################
5349 sub MakeReturnField {
5350     my ($str) = @_;
5352     return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));
5355 #############################################################################
5356 # Function    : GetSymbolSourceFile
5357 # Description : Get the filename where the symbol docs where taken from.
5358 # Arguments   : $symbol - the symbol name
5359 #############################################################################
5361 sub GetSymbolSourceFile {
5362     my ($symbol) = @_;
5364     if (defined($SourceSymbolSourceFile{$symbol})) {
5365         return $SourceSymbolSourceFile{$symbol};
5366     } elsif (defined($SymbolSourceFile{$symbol})) {
5367         return $SymbolSourceFile{$symbol};
5368     } else {
5369         return "";
5370     }
5373 #############################################################################
5374 # Function    : GetSymbolSourceLine
5375 # Description : Get the file line where the symbol docs where taken from.
5376 # Arguments   : $symbol - the symbol name
5377 #############################################################################
5379 sub GetSymbolSourceLine {
5380     my ($symbol) = @_;
5382     if (defined($SourceSymbolSourceLine{$symbol})) {
5383         return $SourceSymbolSourceLine{$symbol};
5384     } elsif (defined($SymbolSourceLine{$symbol})) {
5385         return $SymbolSourceLine{$symbol};
5386     } else {
5387         return 0;
5388     }