hacking: more filename updates
[gtk-doc.git] / gtkdoc-mkdb.in
blobb08c0b765eafd0f5e7dca1c0733483880b0d9f6a
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 (also of
262 # non-object derived types).
263 my @Objects;
264 my @ObjectLevels;
265 my %ObjectRoots;
267 my %Interfaces;
268 my %Prerequisites;
270 # holds the symbols which are mentioned in $MODULE-sections.txt and in which
271 # section they are defined
272 my %KnownSymbols;
273 my %SymbolSection;
274 my %SymbolSectionId;
276 # collects index entries
277 my %IndexEntriesFull;
278 my %IndexEntriesSince;
279 my %IndexEntriesDeprecated;
281 # Standard C preprocessor directives, which we ignore for '#' abbreviations.
282 my %PreProcessorDirectives;
283 $PreProcessorDirectives{"assert"} = 1;
284 $PreProcessorDirectives{"define"} = 1;
285 $PreProcessorDirectives{"elif"} = 1;
286 $PreProcessorDirectives{"else"} = 1;
287 $PreProcessorDirectives{"endif"} = 1;
288 $PreProcessorDirectives{"error"} = 1;
289 $PreProcessorDirectives{"if"} = 1;
290 $PreProcessorDirectives{"ifdef"} = 1;
291 $PreProcessorDirectives{"ifndef"} = 1;
292 $PreProcessorDirectives{"include"} = 1;
293 $PreProcessorDirectives{"line"} = 1;
294 $PreProcessorDirectives{"pragma"} = 1;
295 $PreProcessorDirectives{"unassert"} = 1;
296 $PreProcessorDirectives{"undef"} = 1;
297 $PreProcessorDirectives{"warning"} = 1;
299 # remember used annotation (to write minimal glossary)
300 my %AnnotationsUsed;
302 # the annotations are defined at:
303 # https://live.gnome.org/GObjectIntrospection/Annotations
304 my %AnnotationDefinition = (
305     'allow-none' => "NULL is ok, both for passing and for returning.",
306     'array' => "Parameter points to an array of items.",
307     'attribute' => "Free-form custom annotation.",
308     'closure' => "This parameter is a 'user_data', for callbacks; many bindings can pass NULL here.",
309     'default' => "Default parameter value (for in case the <acronym>shadows</acronym>-to function has less parameters).",
310     'element-type' => "Generics and defining elements of containers and arrays.",
311     'error-domains' => "Typed errors. Similar to throws in Java.",
312     'in' => "Parameter for input. Default is <acronym>transfer none</acronym>.",
313     'inout' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
314     'in-out' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
315     'not-error' => "A GError parameter is not to be handled like a normal GError.",
316     'out' => "Parameter for returning results. Default is <acronym>transfer full</acronym>.",
317     'out caller-allocates' => "Out parameter, where caller must allocate storage.",
318     'out callee-allocates' => "Out parameter, where caller must allocate storage.",
319     'transfer container' => "Free data container after the code is done.",
320     'transfer floating' => "Alias for <acronym>transfer none</acronym>, used for objects with floating refs.",
321     'transfer full' => "Free data after the code is done.",
322     'transfer none' => "Don't free data after the code is done.",
323     'scope call' => "The callback is valid only during the call to the method.",
324     'scope async' => "The callback is valid until first called.",
325     'scope notified' => "The callback is valid until the GDestroyNotify argument is called.",
326     'skip' => "Exposed in C code, not necessarily available in other languages.",
327     'type' => "Override the parsed C type with given type."
330 # Create the root DocBook output directory if it doens't exist.
331 if (! -e $SGML_OUTPUT_DIR) {
332     mkdir ("$SGML_OUTPUT_DIR", 0777)
333         || die "Can't create directory: $SGML_OUTPUT_DIR";
336 # Function and other declaration output settings.
337 my $RETURN_TYPE_FIELD_WIDTH = 20;
338 my $SYMBOL_FIELD_WIDTH = 36;
339 my $SIGNAL_FIELD_WIDTH = 16;
340 my $PARAM_FIELD_COUNT = 2;
342 &ReadKnownSymbols ("$ROOT_DIR/$MODULE-sections.txt");
343 &ReadSignalsFile ($SIGNALS_FILE);
344 &ReadArgsFile ($ARGS_FILE);
345 &ReadObjectHierarchy;
346 &ReadInterfaces;
347 &ReadPrerequisites;
349 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-decl.txt", 0);
350 if (-f "$ROOT_DIR/$MODULE-overrides.txt") {
351     &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-overrides.txt", 1);
354 for my $dir (@SOURCE_DIRS) {
355     &ReadSourceDocumentation ($dir);
358 my $changed = &OutputSGML ("$ROOT_DIR/$MODULE-sections.txt");
360 # If any of the DocBook SGML files have changed, update the timestamp file (so
361 # it can be used for Makefile dependencies).
362 if ($changed || ! -e "$ROOT_DIR/sgml.stamp") {
364     # try to detect the common prefix
365     # GtkWidget, GTK_WIDGET, gtk_widget -> gtk
366     if ($NAME_SPACE eq "") {
367         $NAME_SPACE="";
368         my $pos=0;
369         my $ratio=0.0;
370         do {
371             my %prefix;
372             my $letter="";
373             foreach my $symbol (keys(%IndexEntriesFull)) {
374                 if(($NAME_SPACE eq "") || $symbol =~ /^$NAME_SPACE/i) {
375                     if (length($symbol)>$pos) {
376                         $letter=substr($symbol,$pos,1);
377                         # stop prefix scanning
378                         if ($letter eq "_") {
379                             # stop on "_"
380                             last;
381                         }
382                         # Should we also stop on a uppercase char, if last was lowercase
383                         #   GtkWidget, if we have the 'W' and had the 't' before
384                         # or should we count upper and lowercase, and stop one 2nd uppercase, if we already had a lowercase
385                         #   GtkWidget, the 'W' would be the 2nd uppercase and with 't','k' we had lowercase chars before
386                         # need to recound each time as this is per symbol
387                         $prefix{uc($letter)}++;
388                     }
389                 }
390             }
391             if ($letter ne "" && $letter ne "_") {
392                 my $maxletter="";
393                 my $maxsymbols=0;
394                 foreach $letter (keys(%prefix)) {
395                     #print "$letter: $prefix{$letter}.\n";
396                     if ($prefix{$letter}>$maxsymbols) {
397                         $maxletter=$letter;
398                         $maxsymbols=$prefix{$letter};
399                     }
400                 }
401                 $ratio = scalar(keys(%IndexEntriesFull)) / $prefix{$maxletter};
402                 #print "most symbols start with $maxletter, that is ". (100 * $ratio) ." %\n";
403                 if ($ratio > 0.9) {
404                     # do another round
405                     $NAME_SPACE .= $maxletter;
406                 }
407                 $pos++;
408             }
409             else {
410                 $ratio=0.0;
411             }
412         } while ($ratio > 0.9);
413         #print "most symbols start with $NAME_SPACE\n";
414     }
416     &OutputIndexFull;
417     &OutputDeprecatedIndex;
418     &OutputSinceIndexes;
419     &OutputAnnotationGlossary;
421     open (TIMESTAMP, ">$ROOT_DIR/sgml.stamp")
422         || die "Can't create $ROOT_DIR/sgml.stamp: $!";
423     print (TIMESTAMP "timestamp");
424     close (TIMESTAMP);
427 #############################################################################
428 # Function    : OutputObjectList
429 # Description : This outputs the alphabetical list of objects, in a columned
430 #                table.
431 #               FIXME: Currently this also outputs ancestor objects
432 #                which may not actually be in this module.
433 # Arguments   : none
434 #############################################################################
436 sub OutputObjectList {
437     my $cols = 3;
439     # FIXME: use $OUTPUT_FORMAT
440     # my $old_object_index = "$SGML_OUTPUT_DIR/object_index.$OUTPUT_FORMAT";
441     my $old_object_index = "$SGML_OUTPUT_DIR/object_index.sgml";
442     my $new_object_index = "$SGML_OUTPUT_DIR/object_index.new";
444     open (OUTPUT, ">$new_object_index")
445         || die "Can't create $new_object_index: $!";
447     if ($OUTPUT_FORMAT eq "xml") {
448         my $header = $doctype_header;
450         $header =~ s/<!DOCTYPE \w+/<!DOCTYPE informaltable/;
451         print (OUTPUT "$header");
452     }
454     print (OUTPUT <<EOF);
455 <informaltable pgwide="1" frame="none">
456 <tgroup cols="$cols">
457 <colspec colwidth="1*"${empty_element_end}
458 <colspec colwidth="1*"${empty_element_end}
459 <colspec colwidth="1*"${empty_element_end}
460 <tbody>
463     my $count = 0;
464     my $object;
465     foreach $object (sort (@Objects)) {
466         my $xref = &MakeXRef ($object);
467         if ($count % $cols == 0) { print (OUTPUT "<row>\n"); }
468         print (OUTPUT "<entry>$xref</entry>\n");
469         if ($count % $cols == ($cols - 1)) { print (OUTPUT "</row>\n"); }
470         $count++;
471     }
472     if ($count == 0) {
473         # emit an empty row, since empty tables are invalid
474         print (OUTPUT "<row><entry> </entry></row>\n");
475     }
476     else {
477         if ($count % $cols > 0) {
478             print (OUTPUT "</row>\n");
479         }
480     }
482     print (OUTPUT <<EOF);
483 </tbody></tgroup></informaltable>
485     close (OUTPUT);
487     &UpdateFileIfChanged ($old_object_index, $new_object_index, 0);
490 #############################################################################
491 # Function    : TrimTextBlock
492 # Description : Trims extra whitespace. Empty lines inside a block are
493 #                preserved.
494 # Arguments   : $desc - the text block to trim. May contain newlines.
495 #############################################################################
497 sub TrimTextBlock {
498   my ($desc) = @_;
499   
500   # strip leading spaces on the block
501   $desc =~ s/^\s+//s;
502   # strip trailing spaces on every line
503   $desc =~ s/\s+$/\n/mg;
504   
505   return $desc;
509 #############################################################################
510 # Function    : OutputSGML
511 # Description : This collects the output for each section of the docs, and
512 #                outputs each file when the end of the section is found.
513 # Arguments   : $file - the $MODULE-sections.txt file which contains all of
514 #                the functions/macros/structs etc. being documented, organised
515 #                into sections and subsections.
516 #############################################################################
518 sub OutputSGML {
519     my ($file) = @_;
521     #print "Reading: $file\n";
522     open (INPUT, $file)
523         || die "Can't open $file: $!";
524     my $filename = "";
525     my $book_top = "";
526     my $book_bottom = "";
527     my $includes = (defined $DEFAULT_INCLUDES) ? $DEFAULT_INCLUDES : "";
528     my $section_includes = "";
529     my $in_section = 0;
530     my $title = "";
531     my $section_id = "";
532     my $subsection = "";
533     my $synopsis;
534     my $details;
535     my $num_symbols;
536     my $changed = 0;
537     my $signals_synop = "";
538     my $signals_desc = "";
539     my $args_synop = "";
540     my $child_args_synop = "";
541     my $style_args_synop = "";
542     my $args_desc = "";
543     my $child_args_desc = "";
544     my $style_args_desc = "";
545     my $hierarchy = "";
546     my $interfaces = "";
547     my $implementations = "";
548     my $prerequisites = "";
549     my $derived = "";
550     my @file_objects = ();
551     my %templates = ();
552     my %symbol_def_line = ();
554     # merge the source docs, in case there are no templates
555     &MergeSourceDocumentation;
557     while (<INPUT>) {
558         if (m/^#/) {
559             next;
561         } elsif (m/^<SECTION>/) {
562             $synopsis = "";
563             $details = "";
564             $num_symbols = 0;
565             $in_section = 1;
566             @file_objects = ();
567             %symbol_def_line = ();
569         } elsif (m/^<SUBSECTION\s*(.*)>/i) {
570             $synopsis .= "\n";
571             $subsection = $1;
573         } elsif (m/^<SUBSECTION>/) {
575         } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
576             $title = $1;
577             #print "Section: $title\n";
579             # We don't want warnings if object & class structs aren't used.
580             $DeclarationOutput{$title} = 1;
581             $DeclarationOutput{"${title}Class"} = 1;
582             $DeclarationOutput{"${title}Iface"} = 1;
583             $DeclarationOutput{"${title}Interface"} = 1;
585         } elsif (m/^<FILE>(.*)<\/FILE>/) {
586             $filename = $1;
587             if (! defined $templates{$filename}) {
588                if (&ReadTemplateFile ("$TMPL_DIR/$filename", 1)) {
589                    &MergeSourceDocumentation;
590                    $templates{$filename}=$.;
591                }
592             } else {
593                 &LogWarning ($file, $., "Double <FILE>$filename</FILE> entry. ".
594                     "Previous occurrence on line ".$templates{$filename}.".");
595             }
596             if (($title eq "") and (defined $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"})) {
597                 $title = $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"};
598                  # Remove trailing blanks
599                 $title =~ s/\s+$//;
600            }
602         } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
603             if ($in_section) {
604                 $section_includes = $1;
605             } else {
606                 if (defined $DEFAULT_INCLUDES) {
607                     &LogWarning ($file, $., "Default <INCLUDE> being overridden by command line option.");
608                 }
609                 else {
610                     $includes = $1;
611                 }
612             }
614         } elsif (m/^<\/SECTION>/) {
615             #print "End of section: $title\n";
616             if ($num_symbols > 0) {
617                 # collect documents
618                 if ($OUTPUT_FORMAT eq "xml") {
619                     $book_bottom .= "    <xi:include href=\"xml/$filename.xml\"/>\n";
620                 } else {
621                     $book_top.="<!ENTITY $section_id SYSTEM \"sgml/$filename.sgml\">\n";
622                     $book_bottom .= "    &$section_id;\n";
623                 }
625                 if (defined ($SourceSymbolDocs{"$TMPL_DIR/$filename:Include"})) {
626                     if ($section_includes) {
627                         &LogWarning ($file, $., "Section <INCLUDE> being overridden by inline comments.");
628                     }
629                     $section_includes = $SourceSymbolDocs{"$TMPL_DIR/$filename:Include"};
630                 }
631                 if ($section_includes eq "") {
632                     $section_includes = $includes;
633                 }
635                  $signals_synop =~ s/^\n*//g;
636                  $signals_synop =~ s/\n+$/\n/g;
637                 if ($signals_synop ne '') {
638                     $signals_synop = <<EOF;
639 <refsect1 id="$section_id.signals" role="signal_proto">
640 <title role="signal_proto.title">Signals</title>
641 <synopsis>
642 ${signals_synop}</synopsis>
643 </refsect1>
645                      $signals_desc = TrimTextBlock($signals_desc);
646                     $signals_desc  = <<EOF;
647 <refsect1 id="$section_id.signal-details" role="signals">
648 <title role="signals.title">Signal Details</title>
649 $signals_desc
650 </refsect1>
652                 }
654                  $args_synop =~ s/^\n*//g;
655                  $args_synop =~ s/\n+$/\n/g;
656                 if ($args_synop ne '') {
657                     $args_synop = <<EOF;
658 <refsect1 id="$section_id.properties" role="properties">
659 <title role="properties.title">Properties</title>
660 <synopsis>
661 ${args_synop}</synopsis>
662 </refsect1>
664                      $args_desc = TrimTextBlock($args_desc);
665                     $args_desc  = <<EOF;
666 <refsect1 id="$section_id.property-details" role="property_details">
667 <title role="property_details.title">Property Details</title>
668 $args_desc
669 </refsect1>
671                 }
673                  $child_args_synop =~ s/^\n*//g;
674                  $child_args_synop =~ s/\n+$/\n/g;
675                 if ($child_args_synop ne '') {
676                     $args_synop .= <<EOF;
677 <refsect1 id="$section_id.child-properties" role="child_properties">
678 <title role="child_properties.title">Child Properties</title>
679 <synopsis>
680 ${child_args_synop}</synopsis>
681 </refsect1>
683                      $child_args_desc = TrimTextBlock($child_args_desc);
684                      $args_desc .= <<EOF;
685 <refsect1 id="$section_id.child-property-details" role="child_property_details">
686 <title role="child_property_details.title">Child Property Details</title>
687 $child_args_desc
688 </refsect1>
690                 }
692                  $style_args_synop =~ s/^\n*//g;
693                  $style_args_synop =~ s/\n+$/\n/g;
694                 if ($style_args_synop ne '') {
695                     $args_synop .= <<EOF;
696 <refsect1 id="$section_id.style-properties" role="style_properties">
697 <title role="style_properties.title">Style Properties</title>
698 <synopsis>
699 ${style_args_synop}</synopsis>
700 </refsect1>
702                      $style_args_desc = TrimTextBlock($style_args_desc);
703                     $args_desc .= <<EOF;
704 <refsect1 id="$section_id.style-property-details" role="style_properties_details">
705 <title role="style_properties_details.title">Style Property Details</title>
706 $style_args_desc
707 </refsect1>
709                 }
711                  $hierarchy = TrimTextBlock($hierarchy);
712                 if ($hierarchy ne "") {
713                     $hierarchy = <<EOF;
714 <refsect1 id="$section_id.object-hierarchy" role="object_hierarchy">
715 <title role="object_hierarchy.title">Object Hierarchy</title>
716 $hierarchy
717 </refsect1>
719                 }
721                  $interfaces =~ TrimTextBlock($interfaces);
722                 if ($interfaces ne "") {
723                     $interfaces = <<EOF;
724 <refsect1 id="$section_id.implemented-interfaces" role="impl_interfaces">
725 <title role="impl_interfaces.title">Implemented Interfaces</title>
726 $interfaces
727 </refsect1>
729                 }
731                  $implementations = TrimTextBlock($implementations);
732                 if ($implementations ne "") {
733                     $implementations = <<EOF;
734 <refsect1 id="$section_id.implementations" role="implementations">
735 <title role="implementations.title">Known Implementations</title>
736 $implementations
737 </refsect1>
739                 }
741                  $prerequisites = TrimTextBlock($prerequisites);
742                 if ($prerequisites ne "") {
743                     $prerequisites = <<EOF;
744 <refsect1 id="$section_id.prerequisites" role="prerequisites">
745 <title role="prerequisites.title">Prerequisites</title>
746 $prerequisites
747 </refsect1>
749                 }
751                  $derived = TrimTextBlock($derived);
752                 if ($derived ne "") {
753                     $derived = <<EOF;
754 <refsect1 id="$section_id.derived-interfaces" role="derived_interfaces">
755 <title role="derived_interfaces.title">Known Derived Interfaces</title>
756 $derived
757 </refsect1>
759                 }
761                 $synopsis =~ s/^\n*//g;
762                 $synopsis =~ s/\n+$/\n/g;
763                 my $file_changed = &OutputSGMLFile ($filename, $title, $section_id,
764                                                     $section_includes,
765                                                     \$synopsis, \$details,
766                                                     \$signals_synop, \$signals_desc,
767                                                     \$args_synop, \$args_desc,
768                                                     \$hierarchy, \$interfaces,
769                                                     \$implementations,
770                                                     \$prerequisites, \$derived,
771                                                     \@file_objects);
772                 if ($file_changed) {
773                     $changed = 1;
774                 }
775             }
776             $title = "";
777             $section_id = "";
778             $subsection = "";
779             $in_section = 0;
780             $section_includes = "";
781             $signals_synop = "";
782             $signals_desc = "";
783             $args_synop = "";
784             $child_args_synop = "";
785             $style_args_synop = "";
786             $args_desc = "";
787             $child_args_desc = "";
788             $style_args_desc = "";
789             $hierarchy = "";
790              $interfaces = "";
791              $implementations = "";
792             $prerequisites = "";
793             $derived = "";
795         } elsif (m/^(\S+)/) {
796             my $symbol = $1;
797             #print "  Symbol: $symbol\n";
799             # check for duplicate entries
800             if (! defined $symbol_def_line{$symbol}) {
801                 my $declaration = $Declarations{$symbol};
802                 if (defined ($declaration)) {
803                     # We don't want standard macros/functions of GObjects,
804                     # or private declarations.
805                     if ($subsection ne "Standard" && $subsection ne "Private") {
806                         if (&CheckIsObject ($symbol)) {
807                             push @file_objects, $symbol;
808                         }
809                         my ($synop, $desc) = &OutputDeclaration ($symbol,
810                                                                  $declaration);
811                         my ($sig_synop, $sig_desc) = &GetSignals ($symbol);
812                         my ($arg_synop, $child_arg_synop, $style_arg_synop,
813                             $arg_desc, $child_arg_desc, $style_arg_desc) = &GetArgs ($symbol);
814                         my $hier = &GetHierarchy ($symbol);
815                         my $ifaces = &GetInterfaces ($symbol);
816                         my $impls = &GetImplementations ($symbol);
817                         my $prereqs = &GetPrerequisites ($symbol);
818                         my $der = &GetDerived ($symbol);
819                         $synopsis .= $synop;
820                         $details .= $desc;
821                         $signals_synop .= $sig_synop;
822                         $signals_desc .= $sig_desc;
823                         $args_synop .= $arg_synop;
824                         $child_args_synop .= $child_arg_synop;
825                         $style_args_synop .= $style_arg_synop;
826                         $args_desc .= $arg_desc;
827                         $child_args_desc .= $child_arg_desc;
828                         $style_args_desc .= $style_arg_desc;
829                         $hierarchy .= $hier;
830                         $interfaces .= $ifaces;
831                         $implementations .= $impls;
832                         $prerequisites .= $prereqs;
833                         $derived .= $der;
834                     }
836                     # Note that the declaration has been output.
837                     $DeclarationOutput{$symbol} = 1;
838                 } elsif ($subsection ne "Standard" && $subsection ne "Private") {
839                     $UndeclaredSymbols{$symbol} = 1;
840                     &LogWarning ($file, $., "No declaration found for $symbol.");
841                 }
842                 $num_symbols++;
843                 $symbol_def_line{$symbol}=$.;
845                 if ($section_id eq "") {
846                     if($title eq "" && $filename eq "") {
847                         &LogWarning ($file, $., "Section has no title and no file.");
848                     }
849                     # FIXME: one of those would be enough
850                     # filename should be an internal detail for gtk-doc
851                     if ($title eq "") {
852                         $title = $filename;
853                     } elsif ($filename eq "") {
854                         $filename = $title;
855                     }
856                     $filename =~ s/\s/_/g;
858                     $section_id = $SourceSymbolDocs{"$TMPL_DIR/$filename:Section_Id"};
859                     if (defined ($section_id) && $section_id !~ m/^\s*$/) {
860                         # Remove trailing blanks and use as is
861                         $section_id =~ s/\s+$//;
862                     } elsif (&CheckIsObject ($title)) {
863                         # GObjects use their class name as the ID.
864                         $section_id = &CreateValidSGMLID ($title);
865                     } else {
866                         $section_id = &CreateValidSGMLID ("$MODULE-$title");
867                     }
868                 }
869                 $SymbolSection{$symbol}=$title;
870                 $SymbolSectionId{$symbol}=$section_id;
871             }
872             else {
873                 &LogWarning ($file, $., "Double symbol entry for $symbol. ".
874                     "Previous occurrence on line ".$symbol_def_line{$symbol}.".");
875             }
876         }
877     }
878     close (INPUT);
880     &OutputMissingDocumentation;
881     &OutputUndeclaredSymbols;
882     &OutputUnusedSymbols;
884     if ($OUTPUT_ALL_SYMBOLS) {
885         &OutputAllSymbols;
886     }
887     if ($OUTPUT_SYMBOLS_WITHOUT_SINCE) {
888         &OutputSymbolsWithoutSince;
889     }
891     for $filename (split (' ', $EXPAND_CONTENT_FILES)) {
892         my $file_changed = &OutputExtraFile ($filename);
893         if ($file_changed) {
894             $changed = 1;
895         }
896     }
898     &OutputBook ($book_top, $book_bottom);
900     return $changed;
903 #############################################################################
904 # Function    : OutputIndex
905 # Description : This writes an indexlist that can be included into the main-
906 #               document into an <index> tag.
907 #############################################################################
909 sub OutputIndex {
910     my ($basename, $apiindexref ) = @_;
911     my %apiindex = %{$apiindexref};
912     my $old_index = "$SGML_OUTPUT_DIR/$basename.xml";
913     my $new_index = "$SGML_OUTPUT_DIR/$basename.new";
914     my $lastletter = " ";
915     my $divopen = 0;
916     my $symbol;
917     my $short_symbol;
919     open (OUTPUT, ">$new_index")
920         || die "Can't create $new_index";
922     my $header = $doctype_header;
923     $header =~ s/<!DOCTYPE \w+/<!DOCTYPE indexdiv/;
925     print (OUTPUT "$header<indexdiv>\n");
927     #print "generate $basename index (".%apiindex." entries)\n";
929     # do a case insensitive sort while chopping off the prefix
930     foreach my $hash (
931         sort { $$a{criteria} cmp $$b{criteria} }
932         map { my $x = uc($_); $x =~ s/^$NAME_SPACE\_?(.*)/$1/i; { criteria => $x, original => $_, short => $1 } }
933         keys %apiindex) {
935         $symbol = $$hash{original};
936         if (defined($$hash{short})) {
937             $short_symbol = $$hash{short};
938         } else {
939             $short_symbol = $symbol;
940         }
942         # generate a short symbol description
943         my $symbol_desc = "";
944         my $symbol_section = "";
945         my $symbol_section_id = "";
946         my $symbol_type = "";
947         if (defined($DeclarationTypes{$symbol})) {
948           $symbol_type = lc($DeclarationTypes{$symbol});
949         }
950         if ($symbol_type eq "") {
951             #print "trying symbol $symbol\n";
952             if ($symbol =~ m/(.*)::(.*)/) {
953                 my $oname = $1;
954                 my $osym = $2;
955                 my $i;
956                 #print "  trying object signal ${oname}:$osym in ".$#SignalNames." signals\n";
957                 for ($i = 0; $i <= $#SignalNames; $i++) {
958                     if ($SignalNames[$i] eq $osym) {
959                         $symbol_type = "object signal";
960                         if (defined($SymbolSection{$oname})) {
961                            $symbol_section = $SymbolSection{$oname};
962                            $symbol_section_id = $SymbolSectionId{$oname};
963                         }
964                         last;
965                     }
966                 }
967             } elsif ($symbol =~ m/(.*):(.*)/) {
968                 my $oname = $1;
969                 my $osym = $2;
970                 my $i;
971                 #print "  trying object property ${oname}::$osym in ".$#ArgNames." properties\n";
972                 for ($i = 0; $i <= $#ArgNames; $i++) {
973                     #print "    ".$ArgNames[$i]."\n";
974                     if ($ArgNames[$i] eq $osym) {
975                         $symbol_type = "object property";
976                         if (defined($SymbolSection{$oname})) {
977                            $symbol_section = $SymbolSection{$oname};
978                            $symbol_section_id = $SymbolSectionId{$oname};
979                         }
980                         last;
981                     }
982                 }
983             }
984         } else {
985            if (defined($SymbolSection{$symbol})) {
986                $symbol_section = $SymbolSection{$symbol};
987                $symbol_section_id = $SymbolSectionId{$symbol};
988            }
989         }
990         if ($symbol_type ne "") {
991            $symbol_desc=", $symbol_type";
992            if ($symbol_section ne "") {
993                $symbol_desc.=" in <link linkend=\"$symbol_section_id\">$symbol_section</link>";
994                #$symbol_desc.=" in ". &ExpandAbbreviations($symbol, "#$symbol_section");
995            }
996         }
998         my $curletter = uc(substr($short_symbol,0,1));
999         my $id = $apiindex{$symbol};
1001         #print "  add symbol $symbol with $id to index in section $curletter\n";
1003         if ($curletter ne $lastletter) {
1004             $lastletter = $curletter;
1006             if ($divopen == 1) {
1007                 print (OUTPUT "</indexdiv>\n");
1008             }
1009             print (OUTPUT "<indexdiv><title>$curletter</title>\n");
1010             $divopen = 1;
1011         }
1013         print (OUTPUT <<EOF);
1014 <indexentry><primaryie linkends="$id"><link linkend="$id">$symbol</link>$symbol_desc</primaryie></indexentry>
1016     }
1018     if ($divopen == 1) {
1019         print (OUTPUT "</indexdiv>\n");
1020     }
1021     print (OUTPUT "</indexdiv>\n");
1022     close (OUTPUT);
1024     &UpdateFileIfChanged ($old_index, $new_index, 0);
1028 #############################################################################
1029 # Function    : OutputIndexFull
1030 # Description : This writes the full api indexlist that can be included into the
1031 #               main document into an <index> tag.
1032 #############################################################################
1034 sub OutputIndexFull {
1035     &OutputIndex ("api-index-full", \%IndexEntriesFull);
1039 #############################################################################
1040 # Function    : OutputDeprecatedIndex
1041 # Description : This writes the deprecated api indexlist that can be included
1042 #               into the main document into an <index> tag.
1043 #############################################################################
1045 sub OutputDeprecatedIndex {
1046     &OutputIndex ("api-index-deprecated", \%IndexEntriesDeprecated);
1050 #############################################################################
1051 # Function    : OutputSinceIndexes
1052 # Description : This writes the 'since' api indexlists that can be included into
1053 #               the main document into an <index> tag.
1054 #############################################################################
1056 sub OutputSinceIndexes {
1057     my @sinces = keys %{{ map { $_ => 1 } values %Since }};
1059     foreach my $version (@sinces) {
1060         #print "Since : [$version]\n";
1061         # TODO make filtered hash
1062         #my %index = grep { $Since{$_} eq $version } %IndexEntriesSince;
1063         my %index = map { $_ => $IndexEntriesSince{$_} } grep { $Since{$_} eq $version } keys %IndexEntriesSince;
1065         &OutputIndex ("api-index-$version", \%index);
1066     }
1069 #############################################################################
1070 # Function    : OutputAnnotationGlossary
1071 # Description : This writes a glossary of the used annotation terms into a
1072 #               separate glossary file that can be included into the main
1073 #               document.
1074 #############################################################################
1076 sub OutputAnnotationGlossary {
1077     my $old_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.xml";
1078     my $new_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.new";
1079     my $lastletter = " ";
1080     my $divopen = 0;
1082     # if there are no annotations used return
1083     return if (! keys(%AnnotationsUsed));
1085     # add acronyms that are referenced from acronym text
1086 rerun:
1087     foreach my $annotation (keys(%AnnotationsUsed)) {
1088         if(defined($AnnotationDefinition{$annotation})) {
1089             if($AnnotationDefinition{$annotation} =~ m/<acronym>([\w ]+)<\/acronym>/) {
1090                 if (!exists($AnnotationsUsed{$1})) {
1091                     $AnnotationsUsed{$1} = 1;
1092                     goto rerun;
1093                 }
1094             }
1095         }
1096     }
1098     open (OUTPUT, ">$new_glossary")
1099         || die "Can't create $new_glossary";
1101     my $header = $doctype_header;
1102     $header =~ s/<!DOCTYPE \w+/<!DOCTYPE glossary/;
1104     print (OUTPUT  <<EOF);
1105 $header
1106 <glossary id="annotation-glossary">
1107   <title>Annotation Glossary</title>
1110     foreach my $annotation (keys(%AnnotationsUsed)) {
1111         if(defined($AnnotationDefinition{$annotation})) {
1112             my $def = $AnnotationDefinition{$annotation};
1113             my $curletter = uc(substr($annotation,0,1));
1115             if ($curletter ne $lastletter) {
1116                 $lastletter = $curletter;
1118                 if ($divopen == 1) {
1119                     print (OUTPUT "</glossdiv>\n");
1120                 }
1121                 print (OUTPUT "<glossdiv><title>$curletter</title>\n");
1122                 $divopen = 1;
1123             }
1124             print (OUTPUT <<EOF);
1125     <glossentry>
1126       <glossterm><anchor id="annotation-glossterm-$annotation"/>$annotation</glossterm>
1127       <glossdef>
1128         <para>$def</para>
1129       </glossdef>
1130     </glossentry>
1132         }
1133     }
1135     if ($divopen == 1) {
1136         print (OUTPUT "</glossdiv>\n");
1137     }
1138     print (OUTPUT "</glossary>\n");
1139     close (OUTPUT);
1141     &UpdateFileIfChanged ($old_glossary, $new_glossary, 0);
1144 #############################################################################
1145 # Function    : ReadKnownSymbols
1146 # Description : This collects the names of non-private symbols from the
1147 #               $MODULE-sections.txt file.
1148 # Arguments   : $file - the $MODULE-sections.txt file which contains all of
1149 #                the functions/macros/structs etc. being documented, organised
1150 #                into sections and subsections.
1151 #############################################################################
1153 sub ReadKnownSymbols {
1154     my ($file) = @_;
1156     my $subsection = "";
1158     #print "Reading: $file\n";
1159     open (INPUT, $file)
1160         || die "Can't open $file: $!";
1162     while (<INPUT>) {
1163         if (m/^#/) {
1164             next;
1166         } elsif (m/^<SECTION>/) {
1167             $subsection = "";
1169         } elsif (m/^<SUBSECTION\s*(.*)>/i) {
1170             $subsection = $1;
1172         } elsif (m/^<SUBSECTION>/) {
1173             next;
1175         } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
1176             next;
1178         } elsif (m/^<FILE>(.*)<\/FILE>/) {
1179             $KnownSymbols{"$TMPL_DIR/$1:Long_Description"} = 1;
1180             $KnownSymbols{"$TMPL_DIR/$1:Short_Description"} = 1;
1181             next;
1183         } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
1184             next;
1186         } elsif (m/^<\/SECTION>/) {
1187             next;
1189         } elsif (m/^(\S+)/) {
1190             my $symbol = $1;
1192             if ($subsection ne "Standard" && $subsection ne "Private") {
1193                 $KnownSymbols{$symbol} = 1;
1194             }
1195             else {
1196                 $KnownSymbols{$symbol} = 0;
1197             }
1198         }
1199     }
1200     close (INPUT);
1204 #############################################################################
1205 # Function    : OutputDeclaration
1206 # Description : Returns the synopsis and detailed description DocBook
1207 #                describing one function/macro etc.
1208 # Arguments   : $symbol - the name of the function/macro begin described.
1209 #                $declaration - the declaration of the function/macro.
1210 #############################################################################
1212 sub OutputDeclaration {
1213     my ($symbol, $declaration) = @_;
1215     my $type = $DeclarationTypes {$symbol};
1216     if ($type eq 'MACRO') {
1217         return &OutputMacro ($symbol, $declaration);
1218     } elsif ($type eq 'TYPEDEF') {
1219         return &OutputTypedef ($symbol, $declaration);
1220     } elsif ($type eq 'STRUCT') {
1221         return &OutputStruct ($symbol, $declaration);
1222     } elsif ($type eq 'ENUM') {
1223         return &OutputEnum ($symbol, $declaration);
1224     } elsif ($type eq 'UNION') {
1225         return &OutputUnion ($symbol, $declaration);
1226     } elsif ($type eq 'VARIABLE') {
1227         return &OutputVariable ($symbol, $declaration);
1228     } elsif ($type eq 'FUNCTION') {
1229         return &OutputFunction ($symbol, $declaration, $type);
1230     } elsif ($type eq 'USER_FUNCTION') {
1231         return &OutputFunction ($symbol, $declaration, $type);
1232     } else {
1233         die "Unknown symbol type";
1234     }
1238 #############################################################################
1239 # Function    : OutputSymbolTraits
1240 # Description : Returns the Since and StabilityLevel paragraphs for a symbol.
1241 # Arguments   : $symbol - the name of the function/macro begin described.
1242 #############################################################################
1244 sub OutputSymbolTraits {
1245     my ($symbol) = @_;
1246     my $desc = "";
1248     if (exists $Since{$symbol}) {
1249         $desc .= "<para role=\"since\">Since $Since{$symbol}</para>";
1250     }
1251     if (exists $StabilityLevel{$symbol}) {
1252         $desc .= "<para role=\"stability\">Stability Level: $StabilityLevel{$symbol}</para>";
1253     }
1254     return $desc;
1257 #############################################################################
1258 # Function    : Outpu{Symbol,Section}ExtraLinks
1259 # Description : Returns extralinks for the symbol (if enabled).
1260 # Arguments   : $symbol - the name of the function/macro begin described.
1261 #############################################################################
1263 sub uri_escape {
1264     my $text = $_[0];
1265     return undef unless defined $text;
1267     # Build a char to hex map
1268     my %escapes = ();
1269     for (0..255) {
1270             $escapes{chr($_)} = sprintf("%%%02X", $_);
1271     }
1273     # Default unsafe characters.  RFC 2732 ^(uric - reserved)
1274     $text =~ s/([^A-Za-z0-9\-_.!~*'()])/$escapes{$1}/g;
1276     return $text;
1279 sub OutputSymbolExtraLinks {
1280     my ($symbol) = @_;
1281     my $desc = "";
1283     if (0) { # NEW FEATURE: needs configurability
1284     my $sstr = &uri_escape($symbol);
1285     my $mstr = &uri_escape($MODULE);
1286     $desc .= <<EOF;
1287 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1288 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&amp;symbol=$sstr">edit documentation</ulink>
1290     }
1291     return $desc;
1294 sub OutputSectionExtraLinks {
1295     my ($symbol,$docsymbol) = @_;
1296     my $desc = "";
1298     if (0) { # NEW FEATURE: needs configurability
1299     my $sstr = &uri_escape($symbol);
1300     my $mstr = &uri_escape($MODULE);
1301     my $dsstr = &uri_escape($docsymbol);
1302     $desc .= <<EOF;
1303 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1304 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&amp;symbol=$dsstr">edit documentation</ulink>
1306     }
1307     return $desc;
1311 #############################################################################
1312 # Function    : OutputMacro
1313 # Description : Returns the synopsis and detailed description of a macro.
1314 # Arguments   : $symbol - the macro.
1315 #                $declaration - the declaration of the macro.
1316 #############################################################################
1318 sub OutputMacro {
1319     my ($symbol, $declaration) = @_;
1320     my $id = &CreateValidSGMLID ($symbol);
1321     my $condition = &MakeConditionDescription ($symbol);
1322     my $synop = &MakeReturnField("#define") . "<link linkend=\"$id\">$symbol</link>";
1323     my $desc;
1325     my @fields = ParseMacroDeclaration($declaration, \&CreateValidSGML);
1326     my $title = $symbol . (@fields ? "()" : "");
1328     $desc = "<refsect2 id=\"$id\" role=\"macro\"$condition>\n<title>$title</title>\n";
1329     $desc .= MakeIndexterms($symbol, $id);
1330     $desc .= "\n";
1331     $desc .= OutputSymbolExtraLinks($symbol);
1333     if (@fields) {
1334         if (length ($symbol) < $SYMBOL_FIELD_WIDTH) {
1335             $synop .= (' ' x ($SYMBOL_FIELD_WIDTH - length ($symbol)));
1336         }
1338         $synop .= "(";
1339         for (my $i = 1; $i <= $#fields; $i += 2) {
1340             my $field_name = $fields[$i];
1342             if ($i == 1) {
1343                 $synop .= "$field_name";
1344             } else {
1345                 $synop .= ",\n"
1346                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1347                     . " $field_name";
1348             }
1349         }
1350         $synop .= ")";
1351     }
1352     $synop .= "\n";
1354     # Don't output the macro definition if is is a conditional macro or it
1355     # looks like a function, i.e. starts with "g_" or "_?gnome_", or it is
1356     # longer than 2 lines, otherwise we get lots of complicated macros like
1357     # g_assert.
1358     if (!defined ($DeclarationConditional{$symbol}) && ($symbol !~ m/^g_/)
1359         && ($symbol !~ m/^_?gnome_/) && (($declaration =~ tr/\n//) < 2)) {
1360         my $decl_out = &CreateValidSGML ($declaration);
1361         $desc .= "<programlisting>$decl_out</programlisting>\n";
1362     } else {
1363         $desc .= "<programlisting>" . &MakeReturnField("#define") . "$symbol";
1364         if ($declaration =~ m/^\s*#\s*define\s+\w+(\([^\)]*\))/) {
1365             my $args = $1;
1366             my $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH - length ("#define "));
1367             # Align each line so that if should all line up OK.
1368             $args =~ s/\n/\n$pad/gm;
1369             $desc .= &CreateValidSGML ($args);
1370         }
1371         $desc .= "</programlisting>\n";
1372     }
1374     $desc .= &MakeDeprecationNote($symbol);
1376     my $parameters = &OutputParamDescriptions ("MACRO", $symbol, @fields);
1377     my $parameters_output = 0;
1379     if (defined ($SymbolDocs{$symbol})) {
1380         my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1382         # Try to insert the parameter table at the author's desired position.
1383         # Otherwise we need to tag it onto the end.
1384         if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1385           $parameters_output = 1;
1386         }
1387         $desc .= $symbol_docs;
1388     }
1390     if ($parameters_output == 0) {
1391         $desc .= $parameters;
1392     }
1394     $desc .= OutputSymbolTraits ($symbol);
1395     $desc .= "</refsect2>\n";
1396     return ($synop, $desc);
1400 #############################################################################
1401 # Function    : OutputTypedef
1402 # Description : Returns the synopsis and detailed description of a typedef.
1403 # Arguments   : $symbol - the typedef.
1404 #                $declaration - the declaration of the typedef,
1405 #                  e.g. 'typedef unsigned int guint;'
1406 #############################################################################
1408 sub OutputTypedef {
1409     my ($symbol, $declaration) = @_;
1410     my $id = &CreateValidSGMLID ($symbol);
1411     my $condition = &MakeConditionDescription ($symbol);
1412     my $synop = &MakeReturnField("typedef") . "<link linkend=\"$id\">$symbol</link>;\n";
1413     my $desc = "<refsect2 id=\"$id\" role=\"typedef\"$condition>\n<title>$symbol</title>\n";
1415     $desc .= MakeIndexterms($symbol, $id);
1416     $desc .= "\n";
1417     $desc .= OutputSymbolExtraLinks($symbol);
1419     if (!defined ($DeclarationConditional{$symbol})) {
1420         my $decl_out = &CreateValidSGML ($declaration);
1421         $desc .= "<programlisting>$decl_out</programlisting>\n";
1422     }
1424     $desc .= &MakeDeprecationNote($symbol);
1426     if (defined ($SymbolDocs{$symbol})) {
1427         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1428     }
1429     $desc .= OutputSymbolTraits ($symbol);
1430     $desc .= "</refsect2>\n";
1431     return ($synop, $desc);
1435 #############################################################################
1436 # Function    : OutputStruct
1437 # Description : Returns the synopsis and detailed description of a struct.
1438 #                We check if it is a object struct, and if so we only output
1439 #                parts of it that are noted as public fields.
1440 #                We also use a different SGML ID for object structs, since the
1441 #                original ID is used for the entire RefEntry.
1442 # Arguments   : $symbol - the struct.
1443 #                $declaration - the declaration of the struct.
1444 #############################################################################
1446 sub OutputStruct {
1447     my ($symbol, $declaration) = @_;
1449     my $is_gtype = 0;
1450     my $default_to_public = 1;
1451     if (&CheckIsObject ($symbol)) {
1452         #print "Found struct gtype: $symbol\n";
1453         $is_gtype = 1;
1454         $default_to_public = $ObjectRoots{$symbol} eq 'GBoxed';
1455     }
1457     my $id;
1458     my $condition;
1459     if ($is_gtype) {
1460         $id = &CreateValidSGMLID ($symbol . "_struct");
1461         $condition = &MakeConditionDescription ($symbol . "_struct");
1462     } else {
1463         $id = &CreateValidSGMLID ($symbol);
1464         $condition = &MakeConditionDescription ($symbol);
1465     }
1467     # Determine if it is a simple struct or it also has a typedef.
1468     my $has_typedef = 0;
1469     if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1470       $has_typedef = 1;
1471     }
1473     my $synop;
1474     my $desc;
1475     if ($has_typedef) {
1476         # For structs with typedefs we just output the struct name.
1477         $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1478         $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>$symbol</title>\n";
1479     } else {
1480         $synop = &MakeReturnField("struct") . "<link linkend=\"$id\">$symbol</link>;\n";
1481         $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>struct $symbol</title>\n";
1482     }
1484     $desc .= MakeIndexterms($symbol, $id);
1485     $desc .= "\n";
1486     $desc .= OutputSymbolExtraLinks($symbol);
1488     # Form a pretty-printed, private-data-removed form of the declaration
1490     my $decl_out = "";
1491     if ($declaration =~ m/^\s*$/) {
1492         #print "Found opaque struct: $symbol\n";
1493         $decl_out = "typedef struct _$symbol $symbol;";
1494     } elsif ($declaration =~ m/^\s*struct\s+\w+\s*;\s*$/) {
1495         #print "Found opaque struct: $symbol\n";
1496         $decl_out = "struct $symbol;";
1497     } else {
1498         my $public = $default_to_public;
1499         my $new_declaration = "";
1500         my $decl_line;
1501         my $decl = $declaration;
1503         if ($decl =~ m/^\s*(typedef\s+)?struct\s*\w*\s*(?:\/\*.*\*\/)?\s*{(.*)}\s*\w*\s*;\s*$/s) {
1504             my $struct_contents = $2;
1506             foreach $decl_line (split (/\n/, $struct_contents)) {
1507                 #print "Struct line: $decl_line\n";
1508                 if ($decl_line =~ m%/\*\s*<\s*public\s*>\s*\*/%) {
1509                     $public = 1;
1510                 } elsif ($decl_line =~ m%/\*\s*<\s*(private|protected)\s*>\s*\*/%) {
1511                     $public = 0;
1512                 } elsif ($public) {
1513                     $new_declaration .= $decl_line . "\n";
1514                 }
1515             }
1517             if ($new_declaration) {
1518                 # Strip any blank lines off the ends.
1519                 $new_declaration =~ s/^\s*\n//;
1520                 $new_declaration =~ s/\n\s*$/\n/;
1522                 if ($has_typedef) {
1523                     $decl_out = "typedef struct {\n" . $new_declaration
1524                       . "} $symbol;\n";
1525                 } else {
1526                     $decl_out = "struct $symbol {\n" . $new_declaration
1527                       . "};\n";
1528                 }
1529             }
1530         } else {
1531             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1532                 "Couldn't parse struct:\n$declaration");
1533         }
1535         # If we couldn't parse the struct or it was all private, output an
1536         # empty struct declaration.
1537         if ($decl_out eq "") {
1538             if ($has_typedef) {
1539                 $decl_out = "typedef struct _$symbol $symbol;";
1540             } else {
1541                 $decl_out = "struct $symbol;";
1542             }
1543         }
1544     }
1546     $decl_out = &CreateValidSGML ($decl_out);
1547     $desc .= "<programlisting>$decl_out</programlisting>\n";
1549     $desc .= &MakeDeprecationNote($symbol);
1551     if (defined ($SymbolDocs{$symbol})) {
1552         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1553     }
1555     # Create a table of fields and descriptions
1557     # FIXME: Inserting &#160's into the produced type declarations here would
1558     #        improve the output in most situations ... except for function
1559     #        members of structs!
1560     my @fields = ParseStructDeclaration($declaration, !$default_to_public,
1561                                         0, \&MakeXRef,
1562                                         sub {
1563                                             "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1564                                         });
1565     my $params = $SymbolParams{$symbol};
1567     # If no parameters are filled in, we don't generate the description
1568     # table, for backwards compatibility.
1570     my $found = 0;
1571     if (defined $params) {
1572         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1573             if ($params->[$i] =~ /\S/) {
1574                 $found = 1;
1575                 last;
1576             }
1577         }
1578     }
1580     if ($found) {
1581         my %field_descrs = @$params;
1582         my $missing_parameters = "";
1583         my $unused_parameters = "";
1585         $desc .= "<variablelist role=\"struct\">\n";
1586         while (@fields) {
1587             my $field_name = shift @fields;
1588             my $text = shift @fields;
1589             my $field_descr = $field_descrs{$field_name};
1590             my $param_annotations = "";
1592             $desc .= "<varlistentry><term>$text</term>\n";
1593             if (defined $field_descr) {
1594                 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1595                 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1596                 $field_descr .= $param_annotations;
1597                 # trim
1598                 $field_descr =~ s/^(\s|\n)+//msg;
1599                 $field_descr =~ s/(\s|\n)+$//msg;
1600                 $desc .= "<listitem><simpara>$field_descr</simpara></listitem>\n";
1601                 delete $field_descrs{$field_name};
1602             } else {
1603                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1604                     "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1605                 if ($missing_parameters ne "") {
1606                   $missing_parameters .= ", ".$field_name;
1607                 } else {
1608                     $missing_parameters = $field_name;
1609                 }
1610                 $desc .= "<listitem />\n";
1611             }
1612             $desc .= "</varlistentry>\n";
1613         }
1614         $desc .= "</variablelist>";
1615         foreach my $field_name (keys %field_descrs) {
1616             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1617                 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1618             if ($unused_parameters ne "") {
1619               $unused_parameters .= ", ".$field_name;
1620             } else {
1621                $unused_parameters = $field_name;
1622             }
1623         }
1625         # remember missing/unused parameters (needed in tmpl-free build)
1626         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1627             $AllIncompleteSymbols{$symbol}=$missing_parameters;
1628         }
1629         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1630             $AllUnusedSymbols{$symbol}=$unused_parameters;
1631         }
1632     }
1633     else {
1634         if (scalar(@fields) > 0) {
1635             if (! exists ($AllIncompleteSymbols{$symbol})) {
1636                 $AllIncompleteSymbols{$symbol}="<items>";
1637                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1638                     "Field descriptions for struct $symbol are missing in source code comment block.");
1639                 @TRACE@("Remaining structs fields: ".@fields.":".join(',',@fields)."\n");
1640             }
1641         }
1642     }
1644     $desc .= OutputSymbolTraits ($symbol);
1645     $desc .= "</refsect2>\n";
1646     return ($synop, $desc);
1650 #############################################################################
1651 # Function    : OutputUnion
1652 # Description : Returns the synopsis and detailed description of a union.
1653 # Arguments   : $symbol - the union.
1654 #                $declaration - the declaration of the union.
1655 #############################################################################
1657 sub OutputUnion {
1658     my ($symbol, $declaration) = @_;
1659     my $id = &CreateValidSGMLID ($symbol);
1660     my $condition = &MakeConditionDescription ($symbol);
1662     # Determine if it is a simple struct or it also has a typedef.
1663     my $has_typedef = 0;
1664     if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1665       $has_typedef = 1;
1666     }
1668     my $synop;
1669     my $desc;
1670     if ($has_typedef) {
1671         # For unions with typedefs we just output the union name.
1672         $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1673         $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>$symbol</title>\n";
1674     } else {
1675         $synop = &MakeReturnField("union") . "<link linkend=\"$id\">$symbol</link>;\n";
1676         $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>union $symbol</title>\n";
1677     }
1679     $desc .= MakeIndexterms($symbol, $id);
1680     $desc .= "\n";
1681     $desc .= OutputSymbolExtraLinks($symbol);
1683     # FIXME: we do more for structs
1684     my $decl_out = &CreateValidSGML ($declaration);
1685     $desc .= "<programlisting>$decl_out</programlisting>\n";
1687     $desc .= &MakeDeprecationNote($symbol);
1689     if (defined ($SymbolDocs{$symbol})) {
1690         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1691     }
1693     # Create a table of fields and descriptions
1695     # FIXME: Inserting &#160's into the produced type declarations here would
1696     #        improve the output in most situations ... except for function
1697     #        members of structs!
1698     my @fields = ParseStructDeclaration($declaration, 0,
1699                                         0, \&MakeXRef,
1700                                         sub {
1701                                             "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1702                                         });
1703     my $params = $SymbolParams{$symbol};
1705     # If no parameters are filled in, we don't generate the description
1706     # table, for backwards compatibility
1708     my $found = 0;
1709     if (defined $params) {
1710         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1711             if ($params->[$i] =~ /\S/) {
1712                 $found = 1;
1713                 last;
1714             }
1715         }
1716     }
1718     if ($found) {
1719         my %field_descrs = @$params;
1720         my $missing_parameters = "";
1721         my $unused_parameters = "";
1723         $desc .= "<variablelist role=\"union\">\n";
1724         while (@fields) {
1725             my $field_name = shift @fields;
1726             my $text = shift @fields;
1727             my $field_descr = $field_descrs{$field_name};
1728             my $param_annotations = "";
1730             $desc .= "<varlistentry><term>$text</term>\n";
1731             if (defined $field_descr) {
1732                 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1733                 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1734                 $field_descr .= $param_annotations;
1735                 # trim
1736                 $field_descr =~ s/^(\s|\n)+//msg;
1737                 $field_descr =~ s/(\s|\n)+$//msg;
1738                 $desc .= "<listitem><simpara>$field_descr</simpara></listitem>\n";
1739                 delete $field_descrs{$field_name};
1740             } else {
1741                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1742                     "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1743                 if ($missing_parameters ne "") {
1744                     $missing_parameters .= ", ".$field_name;
1745                 } else {
1746                     $missing_parameters = $field_name;
1747                 }
1748                 $desc .= "<listitem />\n";
1749             }
1750             $desc .= "</varlistentry>\n";
1751         }
1752         $desc .= "</variablelist>";
1753         foreach my $field_name (keys %field_descrs) {
1754             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1755                 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1756             if ($unused_parameters ne "") {
1757               $unused_parameters .= ", ".$field_name;
1758             } else {
1759                $unused_parameters = $field_name;
1760             }
1761         }
1763         # remember missing/unused parameters (needed in tmpl-free build)
1764         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1765             $AllIncompleteSymbols{$symbol}=$missing_parameters;
1766         }
1767         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1768             $AllUnusedSymbols{$symbol}=$unused_parameters;
1769         }
1770     }
1771     else {
1772         if (scalar(@fields) > 0) {
1773             if (! exists ($AllIncompleteSymbols{$symbol})) {
1774                 $AllIncompleteSymbols{$symbol}="<items>";
1775                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1776                     "Field descriptions for union $symbol are missing in source code comment block.");
1777                 @TRACE@("Remaining union fields: ".@fields.":".join(',',@fields)."\n");
1778             }
1779         }
1780     }
1782     $desc .= OutputSymbolTraits ($symbol);
1783     $desc .= "</refsect2>\n";
1784     return ($synop, $desc);
1788 #############################################################################
1789 # Function    : OutputEnum
1790 # Description : Returns the synopsis and detailed description of a enum.
1791 # Arguments   : $symbol - the enum.
1792 #                $declaration - the declaration of the enum.
1793 #############################################################################
1795 sub OutputEnum {
1796     my ($symbol, $declaration) = @_;
1798     my $is_gtype = 0;
1799     if (&CheckIsObject ($symbol)) {
1800         #print "Found enum gtype: $symbol\n";
1801         $is_gtype = 1;
1802     }
1804     my $id;
1805     my $condition;
1806     if ($is_gtype) {
1807         $id = &CreateValidSGMLID ($symbol . "_enum");
1808         $condition = &MakeConditionDescription ($symbol . "_enum");
1809     } else {
1810         $id = &CreateValidSGMLID ($symbol);
1811         $condition = &MakeConditionDescription ($symbol);
1812     }
1814     my $synop = &MakeReturnField("enum") . "<link linkend=\"$id\">$symbol</link>;\n";
1815     my $desc = "<refsect2 id=\"$id\" role=\"enum\"$condition>\n<title>enum $symbol</title>\n";
1817     $desc .= MakeIndexterms($symbol, $id);
1818     $desc .= "\n";
1819     $desc .= OutputSymbolExtraLinks($symbol);
1821     my $decl_out = "";
1822     my $public = 1;
1823     my $new_declaration = "";
1824     my $decl_line;
1825     my $decl = $declaration;
1827     if ($decl =~ m/^\s*(typedef\s+)?enum\s*\w*\s*(?:\/\*.*\*\/)?\s*{(.*)}\s*\w*\s*;\s*$/s) {
1828         my $has_typedef = defined($1) ? 1 : 0;
1829         my $enum_contents = $2;
1831         foreach $decl_line (split (/\n/, $enum_contents)) {
1832             #print "Enum line: $decl_line\n";
1833             if ($decl_line =~ m%/\*\s*<\s*public\s*>\s*\*/%) {
1834                 $public = 1;
1835             } elsif ($decl_line =~ m%/\*\s*<\s*(private|protected)\s*>\s*\*/%) {
1836                 $public = 0;
1837             } elsif ($public) {
1838                 $new_declaration .= $decl_line . "\n";
1839             }
1840         }
1842         if ($new_declaration) {
1843             # Strip any blank lines off the ends.
1844             $new_declaration =~ s/^\s*\n//;
1845             $new_declaration =~ s/\n\s*$/\n/;
1847             if ($has_typedef) {
1848                 $decl_out = "typedef enum {\n" . $new_declaration
1849                   . "} $symbol;\n";
1850             } else {
1851                 $decl_out = "enum $symbol {\n" . $new_declaration
1852                   . "};\n";
1853             }
1854         }
1855     }
1857     $decl_out = &CreateValidSGML ($decl_out);
1858     $desc .= "<programlisting>$decl_out</programlisting>\n";
1860     $desc .= &MakeDeprecationNote($symbol);
1862     if (defined ($SymbolDocs{$symbol})) {
1863         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1864     }
1866     # Create a table of fields and descriptions
1868     my @fields = ParseEnumDeclaration($declaration);
1869     my $params = $SymbolParams{$symbol};
1871     # If nothing at all is documented log a single summary warning at the end.
1872     # Otherwise, warn about each undocumented item.
1874     my $found = 0;
1875     if (defined $params) {
1876         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1877             if ($params->[$i] =~ /\S/) {
1878                 $found = 1;
1879                 last;
1880             }
1881         }
1882     }
1884     my %field_descrs = (defined $params ? @$params : ());
1885     my $missing_parameters = "";
1886     my $unused_parameters = "";
1888     $desc .= "<variablelist role=\"enum\">\n";
1889     for my $field_name (@fields) {
1890         my $field_descr = $field_descrs{$field_name};
1891         my $param_annotations = "";
1893         $id = &CreateValidSGMLID ($field_name);
1894         $condition = &MakeConditionDescription ($field_name);
1895         $desc .= "<varlistentry id=\"$id\" role=\"constant\"$condition>\n<term><literal>$field_name</literal></term>\n";
1896         if (defined $field_descr) {
1897             ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1898             $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1899             $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1900             delete $field_descrs{$field_name};
1901         } else {
1902             if ($found) {
1903                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1904                     "Value description for $symbol"."::"."$field_name is missing in source code comment block.");
1905                 if ($missing_parameters ne "") {
1906                     $missing_parameters .= ", ".$field_name;
1907                 } else {
1908                     $missing_parameters = $field_name;
1909                 }
1910             }
1911             $desc .= "<listitem />\n";
1912         }
1913         $desc .= "</varlistentry>\n";
1914     }
1915     $desc .= "</variablelist>";
1916     foreach my $field_name (keys %field_descrs) {
1917         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1918             "Value description for $symbol"."::"."$field_name is not used from source code comment block.");
1919         if ($unused_parameters ne "") {
1920             $unused_parameters .= ", ".$field_name;
1921         } else {
1922             $unused_parameters = $field_name;
1923         }
1924     }
1926     # remember missing/unused parameters (needed in tmpl-free build)
1927     if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1928         $AllIncompleteSymbols{$symbol}=$missing_parameters;
1929     }
1930     if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1931         $AllUnusedSymbols{$symbol}=$unused_parameters;
1932     }
1934     if (!$found) {
1935         if (scalar(@fields) > 0) {
1936             if (! exists ($AllIncompleteSymbols{$symbol})) {
1937                 $AllIncompleteSymbols{$symbol}="<items>";
1938                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1939                     "Value descriptions for $symbol are missing in source code comment block.");
1940             }
1941         }
1942     }
1944     $desc .= OutputSymbolTraits ($symbol);
1945     $desc .= "</refsect2>\n";
1946     return ($synop, $desc);
1950 #############################################################################
1951 # Function    : OutputVariable
1952 # Description : Returns the synopsis and detailed description of a variable.
1953 # Arguments   : $symbol - the extern'ed variable.
1954 #                $declaration - the declaration of the variable.
1955 #############################################################################
1957 sub OutputVariable {
1958     my ($symbol, $declaration) = @_;
1959     my $id = &CreateValidSGMLID ($symbol);
1960     my $condition = &MakeConditionDescription ($symbol);
1961     
1962     @TRACE@("ouputing variable: '$symbol' '$declaration'");
1964     my $synop;
1965     if ($declaration =~ m/^\s*extern\s+((const\s+|signed\s+|unsigned\s+|long\s+|short\s+)*\w+)(\s+\*+|\*+|\s)(\s*)(const\s+)*([A-Za-z]\w*)\s*;/) {
1966         my $mod1 = defined ($1) ? $1 : "";
1967         my $ptr = defined ($3) ? $3 : "";
1968         my $space = defined ($4) ? $4 : "";
1969         my $mod2 = defined ($5) ? $5 : "";
1970         $synop = &MakeReturnField("extern $mod1$ptr$space$mod2") . "<link linkend=\"$id\">$symbol</link>;\n";
1971     } elsif ($declaration =~ m/^\s*((const\s+|signed\s+|unsigned\s+|long\s+|short\s+)*\w+)(\s+\*+|\*+|\s)(\s*)(const\s+)*([A-Za-z]\w*)\s*=/) {
1972         my $mod1 = defined ($1) ? $1 : "";
1973         my $ptr = defined ($3) ? $3 : "";
1974         my $space = defined ($4) ? $4 : "";
1975         my $mod2 = defined ($5) ? $5 : "";
1976         $synop = &MakeReturnField("$mod1$ptr$space$mod2") . "<link linkend=\"$id\">$symbol</link>;\n";
1978     } else {
1979         $synop = &MakeReturnField("extern") . "<link linkend=\"$id\">$symbol</link>;\n";
1980     }
1982     my $desc = "<refsect2 id=\"$id\" role=\"variable\"$condition>\n<title>$symbol</title>\n";
1984     $desc .= MakeIndexterms($symbol, $id);
1985     $desc .= "\n";
1986     $desc .= OutputSymbolExtraLinks($symbol);
1988     my $decl_out = &CreateValidSGML ($declaration);
1989     $desc .= "<programlisting>$decl_out</programlisting>\n";
1991     $desc .= &MakeDeprecationNote($symbol);
1993     if (defined ($SymbolDocs{$symbol})) {
1994         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1995     }
1996     $desc .= OutputSymbolTraits ($symbol);
1997     $desc .= "</refsect2>\n";
1998     return ($synop, $desc);
2002 #############################################################################
2003 # Function    : OutputFunction
2004 # Description : Returns the synopsis and detailed description of a function.
2005 # Arguments   : $symbol - the function.
2006 #                $declaration - the declaration of the function.
2007 #############################################################################
2009 sub OutputFunction {
2010     my ($symbol, $declaration, $symbol_type) = @_;
2011     my $id = &CreateValidSGMLID ($symbol);
2012     my $condition = &MakeConditionDescription ($symbol);
2014     # Take out the return type     $1                                                                                       $2   $3
2015     $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//;
2016     my $type_modifier = defined($1) ? $1 : "";
2017     my $type = $2;
2018     my $pointer = $3;
2019     # Trim trailing spaces as we are going to pad to $RETURN_TYPE_FIELD_WIDTH below anyway
2020     $pointer =~ s/\s+$//;
2021     my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
2022     my $start = "";
2023     #if ($symbol_type eq 'USER_FUNCTION') {
2024     #    $start = "typedef ";
2025     #}
2027     # We output const rather than G_CONST_RETURN.
2028     $type_modifier =~ s/G_CONST_RETURN/const/g;
2029     $pointer =~ s/G_CONST_RETURN/const/g;
2030     $pointer =~ s/^\s+/ /g;
2032     my $ret_type_len = length ($start) + length ($type_modifier)+ length ($type)
2033         + length ($pointer);
2034     my $ret_type_output;
2035     my $symbol_len;
2036     if ($ret_type_len < $RETURN_TYPE_FIELD_WIDTH) {
2037         $ret_type_output = "$start$type_modifier$xref$pointer"
2038             . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
2039         $symbol_len = 0;
2040     } else {
2041         #$ret_type_output = "$start$type_modifier$xref$pointer\n" . (' ' x $RETURN_TYPE_FIELD_WIDTH);
2043         $ret_type_output = "$start$type_modifier$xref$pointer ";
2044         $symbol_len = $ret_type_len + 1 - $RETURN_TYPE_FIELD_WIDTH;
2045     }
2046     #@TRACE@("$symbol ret type output: [$ret_type_output], $ret_type_len");
2048     $symbol_len += length ($symbol);
2049     my $char1 = my $char2 = my $char3 = "";
2050     if ($symbol_type eq 'USER_FUNCTION') {
2051         $symbol_len += 3;
2052         $char1 = "(";
2053         $char2 = "*";
2054         $char3 = ")";
2055     }
2057     my ($symbol_output, $symbol_desc_output);
2058     if ($symbol_len < $SYMBOL_FIELD_WIDTH) {
2059         $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3"
2060             . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
2061         $symbol_desc_output = "$char1$char2$symbol$char3"
2062             . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
2063     } else {
2064         $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3\n"
2065             . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
2066         $symbol_desc_output = "$char1$char2$symbol$char3\n"
2067             . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
2068     }
2070     my $synop = $ret_type_output . $symbol_output . '(';
2071     my $desc = "<refsect2 id=\"$id\" role=\"function\"$condition>\n<title>${symbol} ()</title>\n";
2073     $desc .= MakeIndexterms($symbol, $id);
2074     $desc .= "\n";
2075     $desc .= OutputSymbolExtraLinks($symbol);
2077     $desc  .= "<programlisting>${ret_type_output}$symbol_desc_output(";
2079     my @fields = ParseFunctionDeclaration($declaration, \&MakeXRef,
2080                                         sub {
2081                                             &tagify($_[0],"parameter");
2082                                         });
2084     for (my $i = 1; $i <= $#fields; $i += 2) {
2085         my $field_name = $fields[$i];
2087         if ($i == 1) {
2088             $synop .= "$field_name";
2089             $desc  .= "$field_name";
2090         } else {
2091             $synop .= ",\n"
2092                 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2093                 . " $field_name";
2094             $desc  .= ",\n"
2095                 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2096                 . " $field_name";
2097         }
2099     }
2101     $synop .= ");\n";
2102     $desc  .= ");</programlisting>\n";
2104     $desc .= &MakeDeprecationNote($symbol);
2106     my $parameters = &OutputParamDescriptions ("FUNCTION", $symbol, @fields);
2107     my $parameters_output = 0;
2109     if (defined ($SymbolDocs{$symbol})) {
2110         my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
2112         # Try to insert the parameter table at the author's desired position.
2113         # Otherwise we need to tag it onto the end.
2114         # FIXME: document that in the user manual and make it useable for other
2115         # types too
2116         if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
2117           $parameters_output = 1;
2118         }
2119         $desc .= $symbol_docs;
2120     }
2122     if ($parameters_output == 0) {
2123         $desc .= $parameters;
2124     }
2126     $desc .= OutputSymbolTraits ($symbol);
2127     $desc .= "</refsect2>\n";
2128     return ($synop, $desc);
2132 #############################################################################
2133 # Function    : OutputParamDescriptions
2134 # Description : Returns the DocBook output describing the parameters of a
2135 #                function, macro or signal handler.
2136 # Arguments   : $symbol_type - 'FUNCTION', 'MACRO' or 'SIGNAL'. Signal
2137 #                  handlers have an implicit user_data parameter last.
2138 #                $symbol - the name of the function/macro being described.
2139 #               @fields - parsed fields from the declaration, used to determine
2140 #                  undocumented/unused entries
2141 #############################################################################
2143 sub OutputParamDescriptions {
2144     my ($symbol_type, $symbol, @fields) = @_;
2145     my $output = "";
2146     my $params = $SymbolParams{$symbol};
2147     my $num_params = 0;
2148     my %field_descrs = ();
2150     if (@fields) {
2151         %field_descrs = @fields;
2152         delete $field_descrs{"void"};
2153         delete $field_descrs{"Returns"};
2154     }
2156     if (defined $params) {
2157         my $returns = "";
2158         my $params_desc = "";
2159         my $missing_parameters = "";
2160         my $unused_parameters = "";
2161         my $j;
2163         for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
2164             my $param_name = $$params[$j];
2165             my $param_desc = $$params[$j + 1];
2166             my $param_annotations = "";
2168             ($param_desc,$param_annotations) = & ExpandAnnotation($symbol, $param_desc);
2169             $param_desc = &ExpandAbbreviations($symbol, $param_desc);
2170             $param_desc .= $param_annotations;
2171             # trim
2172             $param_desc =~ s/^(\s|\n)+//msg;
2173             $param_desc =~ s/(\s|\n)+$//msg;
2174             if ($param_name eq "Returns") {
2175                 $returns = "$param_desc";
2176             } elsif ($param_name eq "void") {
2177                 #print "!!!! void in params for $symbol?\n";
2178             } else {
2179                 if (@fields) {
2180                     if (!defined $field_descrs{$param_name}) {
2181                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2182                             "Parameter description for $symbol"."::"."$param_name is not used from source code comment block.");
2183                         if ($unused_parameters ne "") {
2184                           $unused_parameters .= ", ".$param_name;
2185                         } else {
2186                            $unused_parameters = $param_name;
2187                         }
2188                     } else {
2189                         delete $field_descrs{$param_name};
2190                     }
2191                 }
2192                 if($param_desc ne "") {
2193                     $params_desc .= "<varlistentry><term><parameter>$param_name</parameter>&#160;:</term>\n<listitem><simpara>$param_desc</simpara></listitem></varlistentry>\n";
2194                     $num_params++;
2195                 }
2196             }
2197         }
2198         foreach my $param_name (keys %field_descrs) {
2199             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2200                 "Parameter description for $symbol"."::"."$param_name is missing in source code comment block.");
2201             if ($missing_parameters ne "") {
2202               $missing_parameters .= ", ".$param_name;
2203             } else {
2204                $missing_parameters = $param_name;
2205             }
2206         }
2208         # Signals have an implicit user_data parameter which we describe.
2209         if ($symbol_type eq "SIGNAL") {
2210             $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";
2211         }
2213         # Start a table if we need one.
2214         if ($params_desc || $returns) {
2215             $output .= "<variablelist role=\"params\">\n";
2216             if ($params_desc ne "") {
2217                 #$output .= "<varlistentry><term>Parameters:</term><listitem></listitem></varlistentry>\n";
2218                 $output .= $params_desc;
2219             }
2221             # Output the returns info last
2222             if ($returns) {
2223                 $output .= "<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara>$returns</simpara></listitem></varlistentry>\n";
2224             }
2226             # Finish the table.
2227             $output .= "</variablelist>";
2228         }
2230         # remember missing/unused parameters (needed in tmpl-free build)
2231         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
2232             $AllIncompleteSymbols{$symbol}=$missing_parameters;
2233         }
2234         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
2235             $AllUnusedSymbols{$symbol}=$unused_parameters;
2236         }
2237     }
2238     if (($num_params == 0) && @fields && (scalar(keys(%field_descrs)) > 0)) {
2239         if (! exists ($AllIncompleteSymbols{$symbol})) {
2240             $AllIncompleteSymbols{$symbol}="<parameters>";
2241         }
2242     }
2244     return $output;
2248 #############################################################################
2249 # Function    : ParseStabilityLevel
2250 # Description : Parses a stability level and outputs a warning if it isn't
2251 #               valid.
2252 # Arguments   : $stability - the stability text.
2253 #                $file, $line - context for error message
2254 #                $message - description of where the level is from, to use in
2255 #               any error message.
2256 # Returns     : The parsed stability level string.
2257 #############################################################################
2259 sub ParseStabilityLevel {
2260     my ($stability, $file, $line, $message) = @_;
2262     $stability =~ s/^\s*//;
2263     $stability =~ s/\s*$//;
2264     if ($stability =~ m/^stable$/i) {
2265         $stability = "Stable";
2266     } elsif ($stability =~ m/^unstable$/i) {
2267         $stability = "Unstable";
2268     } elsif ($stability =~ m/^private$/i) {
2269         $stability = "Private";
2270     } else {
2271         &LogWarning ($file, $line, "$message is $stability.".
2272             "It should be one of these: Stable, Unstable, or Private.");
2273     }
2274     return $stability;
2278 #############################################################################
2279 # Function    : OutputSGMLFile
2280 # Description : Outputs the final DocBook file for one section.
2281 # Arguments   : $file - the name of the file.
2282 #               $title - the title from the $MODULE-sections.txt file, which
2283 #                 will be overridden by the title in the template file.
2284 #               $section_id - the SGML id to use for the toplevel tag.
2285 #               $includes - comma-separates list of include files added at top of
2286 #                 synopsis, with '<' '>' around them (if not already enclosed in "").
2287 #               $synopsis - reference to the DocBook for the Synopsis part.
2288 #               $details - reference to the DocBook for the Details part.
2289 #               $signal_synop - reference to the DocBook for the Signal Synopsis part
2290 #               $signal_desc - reference to the DocBook for the Signal Description part
2291 #               $args_synop - reference to the DocBook for the Arg Synopsis part
2292 #               $args_desc - reference to the DocBook for the Arg Description part
2293 #               $hierarchy - reference to the DocBook for the Object Hierarchy part
2294 #               $interfaces - reference to the DocBook for the Interfaces part
2295 #               $implementations - reference to the DocBook for the Known Implementations part
2296 #               $prerequisites - reference to the DocBook for the Prerequisites part
2297 #               $derived - reference to the DocBook for the Derived Interfaces part
2298 #               $file_objects - reference to an array of objects in this file
2299 #############################################################################
2301 sub OutputSGMLFile {
2302     my ($file, $title, $section_id, $includes, $synopsis, $details, $signals_synop, $signals_desc, $args_synop, $args_desc, $hierarchy, $interfaces, $implementations, $prerequisites, $derived, $file_objects) = @_;
2304     #print "Output sgml for file $file with title '$title'\n";
2306     # The edited title overrides the one from the sections file.
2307     my $new_title = $SymbolDocs{"$TMPL_DIR/$file:Title"};
2308     if (defined ($new_title) && $new_title !~ m/^\s*$/) {
2309         $title = $new_title;
2310         #print "Found title: $title\n";
2311     }
2312     my $short_desc = $SymbolDocs{"$TMPL_DIR/$file:Short_Description"};
2313     if (!defined ($short_desc) || $short_desc =~ m/^\s*$/) {
2314         $short_desc = "";
2315     } else {
2316         $short_desc = &ExpandAbbreviations("$title:Short_description",
2317                                            $short_desc);
2318         #print "Found short_desc: $short_desc";
2319     }
2320     my $long_desc = $SymbolDocs{"$TMPL_DIR/$file:Long_Description"};
2321     if (!defined ($long_desc) || $long_desc =~ m/^\s*$/) {
2322         $long_desc = "";
2323     } else {
2324         $long_desc = &ExpandAbbreviations("$title:Long_description",
2325                                           $long_desc);
2326         #print "Found long_desc: $long_desc";
2327     }
2328     my $see_also = $SymbolDocs{"$TMPL_DIR/$file:See_Also"};
2329     if (!defined ($see_also) || $see_also =~ m%^\s*(<para>)?\s*(</para>)?\s*$%) {
2330         $see_also = "";
2331     } else {
2332         $see_also = &ExpandAbbreviations("$title:See_Also", $see_also);
2333         #print "Found see_also: $see_also";
2334     }
2335     if ($see_also) {
2336         $see_also = "<refsect1 id=\"$section_id.see-also\">\n<title>See Also</title>\n$see_also\n</refsect1>\n";
2337     }
2338     my $stability = $SymbolDocs{"$TMPL_DIR/$file:Stability_Level"};
2339     if (!defined ($stability) || $stability =~ m/^\s*$/) {
2340         $stability = "";
2341     } else {
2342         $stability = &ParseStabilityLevel($stability, $file, $., "Section stability level");
2343         #print "Found stability: $stability";
2344     }
2345     if ($stability) {
2346         $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$stability, unless otherwise indicated\n</refsect1>\n";
2347     } elsif ($DEFAULT_STABILITY) {
2348         $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$DEFAULT_STABILITY, unless otherwise indicated\n</refsect1>\n";
2349     }
2351     my $image = $SymbolDocs{"$TMPL_DIR/$file:Image"};
2352     if (!defined ($image) || $image =~ m/^\s*$/) {
2353       $image = "";
2354     } else {
2355       $image =~ s/^\s*//;
2356       $image =~ s/\s*$//;
2358       my $format;
2360       if ($image =~ /jpe?g$/i) {
2361         $format = "format='JPEG'";
2362       } elsif ($image =~ /png$/i) {
2363         $format = "format='PNG'";
2364       } elsif ($image =~ /svg$/i) {
2365         $format = "format='SVG'";
2366       } else {
2367         $format = "";
2368       }
2370       $image = "  <inlinegraphic fileref='$image' $format/>\n"
2371     }
2373     my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
2374         gmtime (time);
2375     my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
2376     $year += 1900;
2378     my $include_output = "";
2379     my $include;
2380     foreach $include (split (/,/, $includes)) {
2381         if ($include =~ m/^\".+\"$/) {
2382             $include_output .= "#include ${include}\n";
2383         }
2384         else {
2385             $include =~ s/^\s+|\s+$//gs;
2386             $include_output .= "#include &lt;${include}&gt;\n";
2387         }
2388     }
2389     if ($include_output ne '') {
2390         $include_output = "\n$include_output\n";
2391     }
2393     my $extralinks = OutputSectionExtraLinks($title,"Section:$file");
2395     my $old_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT";
2396     my $new_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT.new";
2398     open (OUTPUT, ">$new_sgml_file")
2399         || die "Can't create $new_sgml_file: $!";
2401     my $object_anchors = "";
2402     foreach my $object (@$file_objects) {
2403         next if ($object eq $section_id);
2404         my $id = CreateValidSGMLID($object);
2405         #print "Debug: Adding anchor for $object\n";
2406         $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
2407     }
2409     # We used to output this, but is messes up our UpdateFileIfChanged code
2410     # since it changes every day (and it is only used in the man pages):
2411     # "<refentry id="$section_id" revision="$mday $month $year">"
2413     if ($OUTPUT_FORMAT eq "xml") {
2414         print OUTPUT $doctype_header;
2415     }
2417     print OUTPUT <<EOF;
2418 <refentry id="$section_id">
2419 <refmeta>
2420 <refentrytitle role="top_of_page" id="$section_id.top_of_page">$title</refentrytitle>
2421 <manvolnum>3</manvolnum>
2422 <refmiscinfo>
2423   \U$MODULE\E Library
2424 $image</refmiscinfo>
2425 </refmeta>
2426 <refnamediv>
2427 <refname>$title</refname>
2428 <refpurpose>$short_desc</refpurpose>
2429 </refnamediv>
2430 $stability
2431 <refsynopsisdiv id="$section_id.synopsis" role="synopsis">
2432 <title role="synopsis.title">Synopsis</title>
2433 $object_anchors
2434 <synopsis>$include_output$${synopsis}</synopsis>
2435 </refsynopsisdiv>
2436 $$hierarchy$$prerequisites$$derived$$interfaces$$implementations$$args_synop$$signals_synop
2437 <refsect1 id="$section_id.description" role="desc">
2438 <title role="desc.title">Description</title>
2439 $extralinks$long_desc
2440 </refsect1>
2441 <refsect1 id="$section_id.details" role="details">
2442 <title role="details.title">Details</title>
2443 $$details
2444 </refsect1>
2445 $$args_desc$$signals_desc$see_also
2446 </refentry>
2448     close (OUTPUT);
2450     return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2454 #############################################################################
2455 # Function    : OutputExtraFile
2456 # Description : Copies an "extra" DocBook file into the output directory,
2457 #               expanding abbreviations
2458 # Arguments   : $file - the source file.
2459 #############################################################################
2460 sub OutputExtraFile {
2461     my ($file) = @_;
2463     my $basename;
2465     ($basename = $file) =~ s!^.*/!!;
2467     my $old_sgml_file = "$SGML_OUTPUT_DIR/$basename";
2468     my $new_sgml_file = "$SGML_OUTPUT_DIR/$basename.new";
2470     my $contents;
2472     open(EXTRA_FILE, "<$file") || die "Can't open $file";
2474     {
2475         local $/;
2476         $contents = <EXTRA_FILE>;
2477     }
2479     open (OUTPUT, ">$new_sgml_file")
2480         || die "Can't create $new_sgml_file: $!";
2482     print OUTPUT &ExpandAbbreviations ("$basename file", $contents);
2483     close (OUTPUT);
2485     return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2487 #############################################################################
2488 # Function    : OutputBook
2489 # Description : Outputs the SGML entities that need to be included into the
2490 #                main SGML file for the module.
2491 # Arguments   : $book_top - the declarations of the entities, which are added
2492 #                  at the top of the main SGML file.
2493 #                $book_bottom - the references to the entities, which are
2494 #                  added in the main SGML file at the desired position.
2495 #############################################################################
2497 sub OutputBook {
2498     my ($book_top, $book_bottom) = @_;
2500     my $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top";
2501     my $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top.new";
2503     open (OUTPUT, ">$new_file")
2504         || die "Can't create $new_file: $!";
2505     print OUTPUT $book_top;
2506     close (OUTPUT);
2508     &UpdateFileIfChanged ($old_file, $new_file, 0);
2511     $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom";
2512     $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom.new";
2514     open (OUTPUT, ">$new_file")
2515         || die "Can't create $new_file: $!";
2516     print OUTPUT $book_bottom;
2517     close (OUTPUT);
2519     &UpdateFileIfChanged ($old_file, $new_file, 0);
2522     # If the main SGML/XML file hasn't been created yet, we create it here.
2523     # The user can tweak it later.
2524     if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
2525       open (OUTPUT, ">$MAIN_SGML_FILE")
2526         || die "Can't create $MAIN_SGML_FILE: $!";
2528       if ($OUTPUT_FORMAT eq "xml") {
2529           print OUTPUT <<EOF;
2530 <?xml version="1.0"?>
2531 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
2532                "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
2534   <!ENTITY % local.common.attrib "xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'">
2536 <book id="index">
2538       } else {
2539         print OUTPUT <<EOF;
2540 <!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
2541 $book_top
2543 <book id="index">
2545       }
2547 print OUTPUT <<EOF;
2548   <bookinfo>
2549     <title>$MODULE Reference Manual</title>
2550     <releaseinfo>
2551       for $MODULE [VERSION].
2552       The latest version of this documentation can be found on-line at
2553       <ulink role="online-location" url="http://[SERVER]/$MODULE/index.html">http://[SERVER]/$MODULE/</ulink>.
2554     </releaseinfo>
2555   </bookinfo>
2557   <chapter>
2558     <title>[Insert title here]</title>
2559     $book_bottom
2560   </chapter>
2562   if (-e $OBJECT_TREE_FILE) {
2563     print OUTPUT <<EOF;
2564   <chapter id="object-tree">
2565     <title>Object Hierarchy</title>
2566      <xi:include href="xml/tree_index.sgml"/>
2567   </chapter>
2569   }
2571 print OUTPUT <<EOF;
2572   <index id="api-index-full">
2573     <title>API Index</title>
2574     <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
2575   </index>
2576   <index id="deprecated-api-index" role="deprecated">
2577     <title>Index of deprecated API</title>
2578     <xi:include href="xml/api-index-deprecated.xml"><xi:fallback /></xi:include>
2579   </index>
2581   <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
2582 </book>
2585       close (OUTPUT);
2586     }
2590 #############################################################################
2591 # Function    : CreateValidSGML
2592 # Description : This turns any chars which are used in SGML into entities,
2593 #                e.g. '<' into '&lt;'
2594 # Arguments   : $text - the text to turn into proper SGML.
2595 #############################################################################
2597 sub CreateValidSGML {
2598     my ($text) = @_;
2599     $text =~ s/&/&amp;/g;        # Do this first, or the others get messed up.
2600     $text =~ s/</&lt;/g;
2601     $text =~ s/>/&gt;/g;
2602     # browers render single tabs inconsistently
2603     $text =~ s/([^\s])\t([^\s])/$1&#160;$2/g;
2604     return $text;
2607 #############################################################################
2608 # Function    : ConvertSGMLChars
2609 # Description : This is used for text in source code comment blocks, to turn
2610 #               chars which are used in SGML into entities, e.g. '<' into
2611 #               '&lt;'. Depending on $INLINE_MARKUP_MODE, this is done
2612 #               unconditionally or only if the character doesn't seem to be
2613 #               part of an SGML construct (tag or entity reference).
2614 # Arguments   : $text - the text to turn into proper SGML.
2615 #############################################################################
2617 sub ConvertSGMLChars {
2618     my ($symbol, $text) = @_;
2620     if ($INLINE_MARKUP_MODE) {
2621         # For the XML/SGML mode only convert to entities outside CDATA sections.
2622         return &ModifyXMLElements ($text, $symbol,
2623                                    "<!\\[CDATA\\[|<programlisting[^>]*>",
2624                                    \&ConvertSGMLCharsEndTag,
2625                                    \&ConvertSGMLCharsCallback);
2626     } else {
2627         # For the simple non-sgml mode, convert to entities everywhere.
2628         $text =~ s/&/&amp;/g;        # Do this first, or the others get messed up.
2629         $text =~ s/</&lt;/g;
2630         $text =~ s/>/&gt;/g;
2631         return $text;
2632     }
2636 sub ConvertSGMLCharsEndTag {
2637   if ($_[0] eq "<!\[CDATA\[") {
2638     return "]]>";
2639   } else {
2640     return "</programlisting>";
2641   }
2644 sub ConvertSGMLCharsCallback {
2645   my ($text, $symbol, $tag) = @_;
2647   if ($tag =~ m/^<programlisting/) {
2648     # We can handle <programlisting> specially here.
2649     return &ModifyXMLElements ($text, $symbol,
2650                                "<!\\[CDATA\\[",
2651                                \&ConvertSGMLCharsEndTag,
2652                                \&ConvertSGMLCharsCallback2);
2653   } elsif ($tag eq "") {
2654     # If we're not in CDATA convert to entities.
2655     $text =~ s/&(?![a-zA-Z#]+;)/&amp;/g;        # Do this first, or the others get messed up.
2656     $text =~ s/<(?![a-zA-Z\/!])/&lt;/g;
2657     $text =~ s/(?<![a-zA-Z0-9"'\/-])>/&gt;/g;
2659     # Handle "#include <xxxxx>"
2660     $text =~ s/#include(\s+)<([^>]+)>/#include$1&lt;$2&gt;/g;
2661   }
2663   return $text;
2666 sub ConvertSGMLCharsCallback2 {
2667   my ($text, $symbol, $tag) = @_;
2669   # If we're not in CDATA convert to entities.
2670   # We could handle <programlisting> differently, though I'm not sure it helps.
2671   if ($tag eq "") {
2672     # replace only if its not a tag
2673     $text =~ s/&(?![a-zA-Z#]+;)/&amp;/g;        # Do this first, or the others get messed up.
2674     $text =~ s/<(?![a-zA-Z\/!])/&lt;/g;
2675     $text =~ s/(?<![a-zA-Z0-9"'\/-])>/&gt;/g;
2677     # Handle "#include <xxxxx>"
2678     $text =~ s/#include(\s+)<([^>]+)>/#include$1&lt;$2&gt;/g;
2679   }
2681   return $text;
2684 #############################################################################
2685 # Function    : ExpandAnnotation
2686 # Description : This turns annotations into acronym tags.
2687 # Arguments   : $symbol - the symbol being documented, for error messages.
2688 #                $text - the text to expand.
2689 #############################################################################
2690 sub ExpandAnnotation {
2691     my ($symbol, $param_desc) = @_;
2692     my $param_annotations = "";
2694     # look for annotations at the start of the comment part
2695     if ($param_desc =~ m%^\s*\((.*?)\):%) {
2696         my @annotations;
2697         my $annotation;
2698         $param_desc = $';
2700         @annotations = split(/\)\s*\(/,$1);
2701         foreach $annotation (@annotations) {
2702             # need to search for the longest key-match in %AnnotationDefinition
2703             my $match_length=0;
2704             my $match_annotation="";
2705             my $annotationdef;
2706             foreach $annotationdef (keys %AnnotationDefinition) {
2707                 if ($annotation =~ m/^$annotationdef/) {
2708                     if (length($annotationdef)>$match_length) {
2709                         $match_length=length($annotationdef);
2710                         $match_annotation=$annotationdef;
2711                     }
2712                 }
2713             }
2714             my $annotation_extra = "";
2715             if ($match_annotation ne "") {
2716                 if ($annotation =~ m%$match_annotation\s+(.*)%) {
2717                     $annotation_extra = " $1";
2718                 }
2719                 $AnnotationsUsed{$match_annotation} = 1;
2720                 $param_annotations .= "[<acronym>$match_annotation</acronym>$annotation_extra]";
2721             }
2722             else {
2723                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2724                     "unknown annotation \"$annotation\" in documentation for $symbol.");
2725                 $param_annotations .= "[$annotation]";
2726             }
2727         }
2728         chomp($param_desc);
2729         $param_desc =~ m/^(.*?)\.*\s*$/s;
2730         $param_desc = "$1. ";
2731     }
2732     if ($param_annotations ne "") {
2733         $param_annotations = "<emphasis role=\"annotation\">$param_annotations</emphasis>";
2734     }
2735     return ($param_desc, $param_annotations);
2738 #############################################################################
2739 # Function    : ExpandAbbreviations
2740 # Description : This turns the abbreviations function(), macro(), @param,
2741 #                %constant, and #symbol into appropriate DocBook markup.
2742 #               CDATA sections and <programlisting> parts are skipped.
2743 # Arguments   : $symbol - the symbol being documented, for error messages.
2744 #                $text - the text to expand.
2745 #############################################################################
2747 sub ExpandAbbreviations {
2748   my ($symbol, $text) = @_;
2750   # Convert "|[" and "]|" into the start and end of program listing examples.
2751   # FIXME: we like to have a way to specify parameters e.g. language="c"
2752   $text =~ s%\|\[%<informalexample><programlisting>%g;
2753   $text =~ s%\]\|%</programlisting></informalexample>%g;
2754   # TODO: check for a xml comment after |[ and pick the language attribute from
2755   # that
2757   # keep CDATA unmodified, preserve ulink tags (ideally we preseve all tags
2758   # as such)
2759   return &ModifyXMLElements ($text, $symbol,
2760                              "<!\\[CDATA\\[|<ulink[^>]*>|<programlisting[^>]*>|<!DOCTYPE",
2761                              \&ExpandAbbreviationsEndTag,
2762                              \&ExpandAbbreviationsCallback);
2766 # Returns the end tag (as a regexp) corresponding to the given start tag.
2767 sub ExpandAbbreviationsEndTag {
2768   my ($start_tag) = @_;
2770   if ($start_tag eq "<!\[CDATA\[") {
2771     return "]]>";
2772   } elsif ($start_tag eq "<!DOCTYPE") {
2773     return ">";
2774   } elsif ($start_tag =~ m/<(\w+)/) {
2775     return "</$1>";
2776   }
2779 # Called inside or outside each CDATA or <programlisting> section.
2780 sub ExpandAbbreviationsCallback {
2781   my ($text, $symbol, $tag) = @_;
2783   if ($tag =~ m/^<programlisting/) {
2784     # Handle any embedded CDATA sections.
2785     return &ModifyXMLElements ($text, $symbol,
2786                                "<!\\[CDATA\\[",
2787                                \&ExpandAbbreviationsEndTag,
2788                                \&ExpandAbbreviationsCallback2);
2789   } elsif ($tag eq "") {
2790     # We are outside any CDATA or <programlisting> sections, so we expand
2791     # any gtk-doc abbreviations.
2793     # Convert '@param()'
2794     # FIXME: we could make those also links ($symbol.$2), but that would be less
2795     # useful as the link target is a few lines up or down
2796     $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)\s*\(\)/$1<parameter>$2()<\/parameter>/g;
2798     # Convert 'function()' or 'macro()'.
2799     # if there is abc_*_def() we don't want to make a link to _def()
2800     # FIXME: also handle abc(def(....)) : but that would need to be done recursively :/
2801     $text =~ s/([^\*.\w])(\w+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2802     # handle #Object.func()
2803     $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2805     # Convert '@param', but not '\@param'.
2806     $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)/$1<parameter>$2<\/parameter>/g;
2807     $text =~ s/\\\@/\@/g;
2809     # Convert '%constant', but not '\%constant'.
2810     # Also allow negative numbers, e.g. %-1.
2811     $text =~ s/(\A|[^\\])\%(-?\w+)/$1.&MakeXRef($2, &tagify($2, "literal"));/eg;
2812     $text =~ s/\\\%/\%/g;
2814     # Convert '#symbol', but not '\#symbol'.
2815     $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)/$1.&MakeHashXRef($2, "type");/eg;
2816     $text =~ s/\\#/#/g;
2818     # Expand urls
2819     # FIXME: should we skip urls that are already tagged? (e.g. <literal>http://...</literal>)
2820     # this is apparently also called for markup and not just for plain text
2821     # disable for now.
2822     #$text =~ s%(http|https|ftp)://(.*?)((?:\s|,|\)|\]|\<|\.\s))%<ulink url="$1://$2">$2</ulink>$3%g;
2824     # TODO: optionally check all words from $text against internal symbols and
2825     # warn if those could be xreffed, but miss a %,# or ()
2826   }
2828   return $text;
2831 # This is called inside a <programlisting>
2832 sub ExpandAbbreviationsCallback2 {
2833   my ($text, $symbol, $tag) = @_;
2835   if ($tag eq "") {
2836     # We are inside a <programlisting> but outside any CDATA sections,
2837     # so we expand any gtk-doc abbreviations.
2838     # FIXME: why is this different from &ExpandAbbreviationsCallback(),
2839     #        why not just call it
2840     $text =~ s/#(\w+)/&MakeHashXRef($1, "");/eg;
2841   }
2843   return $text;
2846 sub MakeHashXRef {
2847     my ($symbol, $tag) = @_;;
2848     my $text = $symbol;
2850     # Check for things like '#include', '#define', and skip them.
2851     if ($PreProcessorDirectives{$symbol}) {
2852       return "#$symbol";
2853     }
2855     # Get rid of special suffixes ('-struct','-enum').
2856     $text =~ s/-struct$//;
2857     $text =~ s/-enum$//;
2859     # If the symbol is in the form "Object::signal", then change the symbol to
2860     # "Object-signal" and use "signal" as the text.
2861     if ($symbol =~ s/::/-/) {
2862       $text = "\"$'\"";
2863     }
2865     # If the symbol is in the form "Object:property", then change the symbol to
2866     # "Object--property" and use "property" as the text.
2867     if ($symbol =~ s/:/--/) {
2868       $text = "\"$'\"";
2869     }
2871     if ($tag ne "") {
2872       $text = tagify ($text, $tag);
2873     }
2875     return &MakeXRef($symbol, $text);
2879 #############################################################################
2880 # Function    : ModifyXMLElements
2881 # Description : Looks for given XML element tags within the text, and calls
2882 #               the callback on pieces of text inside & outside those elements.
2883 #               Used for special handling of text inside things like CDATA
2884 #               and <programlisting>.
2885 # Arguments   : $text - the text.
2886 #               $symbol - the symbol currently being documented (only used for
2887 #                      error messages).
2888 #               $start_tag_regexp - the regular expression to match start tags.
2889 #                      e.g. "<!\\[CDATA\\[|<programlisting[^>]*>" to match
2890 #                      CDATA sections or programlisting elements.
2891 #               $end_tag_func - function which is passed the matched start tag
2892 #                      and should return the appropriate end tag string regexp.
2893 #               $callback - callback called with each part of the text. It is
2894 #                      called with a piece of text, the symbol being
2895 #                      documented, and the matched start tag or "" if the text
2896 #                      is outside the XML elements being matched.
2897 #############################################################################
2898 sub ModifyXMLElements {
2899     my ($text, $symbol, $start_tag_regexp, $end_tag_func, $callback) = @_;
2900     my ($before_tag, $start_tag, $end_tag_regexp, $end_tag);
2901     my $result = "";
2903     while ($text =~ m/$start_tag_regexp/s) {
2904       $before_tag = $`; # Prematch for last successful match string
2905       $start_tag = $&;  # Last successful match
2906       $text = $';       # Postmatch for last successful match string
2908       $result .= &$callback ($before_tag, $symbol, "");
2909       $result .= $start_tag;
2911       # get the matching end-tag for current tag
2912       $end_tag_regexp = &$end_tag_func ($start_tag);
2914       if ($text =~ m/$end_tag_regexp/s) {
2915         $before_tag = $`;
2916         $end_tag = $&;
2917         $text = $';
2919         $result .= &$callback ($before_tag, $symbol, $start_tag);
2920         $result .= $end_tag;
2921       } else {
2922         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2923             "Can't find tag end: $end_tag_regexp in docs for: $symbol.");
2924         # Just assume it is all inside the tag.
2925         $result .= &$callback ($text, $symbol, $start_tag);
2926         $text = "";
2927       }
2928     }
2930     # Handle any remaining text outside the tags.
2931     $result .= &$callback ($text, $symbol, "");
2933     return $result;
2936 sub noop {
2937   return $_[0];
2940 # Adds a tag around some text.
2941 # e.g tagify("Text", "literal") => "<literal>Text</literal>".
2942 sub tagify {
2943    my ($text, $elem) = @_;
2944    return "<" . $elem . ">" . $text . "</" . $elem . ">";
2948 #############################################################################
2949 # Function    : MakeXRef
2950 # Description : This returns a cross-reference link to the given symbol.
2951 #                Though it doesn't try to do this for a few standard C types
2952 #                that it        knows won't be in the documentation.
2953 # Arguments   : $symbol - the symbol to try to create a XRef to.
2954 #               $text - text text to put inside the XRef, defaults to $symbol
2955 #############################################################################
2957 sub MakeXRef {
2958     my ($symbol, $text) = ($_[0], $_[1]);
2960     $symbol =~ s/^\s+//;
2961     $symbol =~ s/\s+$//;
2963     if (!defined($text)) {
2964         $text = $symbol;
2966         # Get rid of special suffixes ('-struct','-enum').
2967         $text =~ s/-struct$//;
2968         $text =~ s/-enum$//;
2969     }
2971     if ($symbol =~ m/ /) {
2972         return "$text";
2973     }
2975     #print "Getting type link for $symbol -> $text\n";
2977     my $symbol_id = &CreateValidSGMLID ($symbol);
2978     return "<link linkend=\"$symbol_id\">$text</link>";
2982 #############################################################################
2983 # Function    : MakeIndexterms
2984 # Description : This returns a indexterm elements for the given symbol
2985 # Arguments   : $symbol - the symbol to create indexterms for
2986 #############################################################################
2988 sub MakeIndexterms {
2989   my ($symbol, $id) = @_;
2990   my $terms =  "";
2991   my $sortas = "";
2993   # make the index useful, by ommiting the namespace when sorting
2994   if ($NAME_SPACE ne "") {
2995     if ($symbol =~ m/^$NAME_SPACE\_?(.*)/i) {
2996        $sortas=" sortas=\"$1\"";
2997     }
2998   }
3000   if (exists $Deprecated{$symbol}) {
3001       $terms .= "<indexterm zone=\"$id\" role=\"deprecated\"><primary$sortas>$symbol</primary></indexterm>";
3002       $IndexEntriesDeprecated{$symbol}=$id;
3003       $IndexEntriesFull{$symbol}=$id;
3004   }
3005   if (exists $Since{$symbol}) {
3006      my $since = $Since{$symbol};
3007      $since =~ s/^\s+//;
3008      $since =~ s/\s+$//;
3009      if ($since ne "") {
3010          $terms .= "<indexterm zone=\"$id\" role=\"$since\"><primary$sortas>$symbol</primary></indexterm>";
3011      }
3012      $IndexEntriesSince{$symbol}=$id;
3013      $IndexEntriesFull{$symbol}=$id;
3014   }
3015   if ($terms eq "") {
3016      $terms .= "<indexterm zone=\"$id\"><primary$sortas>$symbol</primary></indexterm>";
3017      $IndexEntriesFull{$symbol}=$id;
3018   }
3020   return $terms;
3023 #############################################################################
3024 # Function    : MakeDeprecationNote
3025 # Description : This returns a deprecation warning for the given symbol.
3026 # Arguments   : $symbol - the symbol to try to create a warning for.
3027 #############################################################################
3029 sub MakeDeprecationNote {
3030     my ($symbol) = $_[0];
3031     my $desc = "";
3032     my $note = "";
3033     if (exists $Deprecated{$symbol}) {
3034         $desc .= "<warning>";
3036         if ($Deprecated{$symbol} =~ /^\s*([0-9\.]+)\s*:/) {
3037                 $desc .= "<para><literal>$symbol</literal> has been deprecated since version $1 and should not be used in newly-written code.";
3038         } else {
3039                 $desc .= "<para><literal>$symbol</literal> is deprecated and should not be used in newly-written code.";
3040         }
3041         if ($Deprecated{$symbol} ne "") {
3042             $note = &ExpandAbbreviations($symbol, $Deprecated{$symbol});
3043             $note =~ s/^\s*([0-9\.]+)\s*:\s*//;
3044             $note =~ s/^\s+//;
3045             $note =~ s/\s+$//;
3046             $note =~ s%\n{2,}%\n</para>\n<para>\n%g;
3047             $desc .= " " . $note;
3048         }
3049         $desc .= "</para></warning>\n";
3050     }
3051     return $desc;
3054 #############################################################################
3055 # Function    : MakeConditionDescription
3056 # Description : This returns a sumary of conditions for the given symbol.
3057 # Arguments   : $symbol - the symbol to try to create the sumary.
3058 #############################################################################
3060 sub MakeConditionDescription {
3061     my ($symbol) = $_[0];
3062     my $desc = "";
3064     if (exists $Deprecated{$symbol}) {
3065         if ($desc ne "") {
3066             $desc .= "|";
3067         }
3069         if ($Deprecated{$symbol} =~ /^\s*(.*?)\s*$/) {
3070                 $desc .= "deprecated:$1";
3071         } else {
3072                 $desc .= "deprecated";
3073         }
3074     }
3076     if (exists $Since{$symbol}) {
3077         if ($desc ne "") {
3078             $desc .= "|";
3079         }
3081         if ($Since{$symbol} =~ /^\s*(.*?)\s*$/) {
3082                 $desc .= "since:$1";
3083         } else {
3084                 $desc .= "since";
3085         }
3086     }
3088     if (exists $StabilityLevel{$symbol}) {
3089         if ($desc ne "") {
3090             $desc .= "|";
3091         }
3092         $desc .= "stability:".$StabilityLevel{$symbol};
3093     }
3095     if ($desc ne "") {
3096         $desc=" condition=\"".$desc."\"";
3097         #print "condition for '$symbol' = '$desc'\n";
3098     }
3099     return $desc;
3102 #############################################################################
3103 # Function    : GetHierarchy
3104 # Description : Returns the DocBook output describing the ancestors and
3105 #               immediate children of a GObject subclass. It uses the
3106 #               global @Objects and @ObjectLevels arrays to walk the tree.
3107 # Arguments   : $object - the GtkObject subclass.
3108 #############################################################################
3110 sub GetHierarchy {
3111     my ($object) = @_;
3113     # Find object in the objects array.
3114     my $found = 0;
3115     my @children = ();
3116     my $i;
3117     my $level;
3118     my $j;
3119     for ($i = 0; $i < @Objects; $i++) {
3120         if ($found) {
3121             if ($ObjectLevels[$i] <= $level) {
3122             last;
3123         }
3124             elsif ($ObjectLevels[$i] == $level + 1) {
3125                 push (@children, $Objects[$i]);
3126             }
3127         }
3128         elsif ($Objects[$i] eq $object) {
3129             $found = 1;
3130             $j = $i;
3131             $level = $ObjectLevels[$i];
3132         }
3133     }
3134     if (!$found) {
3135         return "";
3136     }
3138     # Walk up the hierarchy, pushing ancestors onto the ancestors array.
3139     my @ancestors = ();
3140     push (@ancestors, $object);
3141     #print "Level: $level\n";
3142     while ($level > 1) {
3143         $j--;
3144         if ($ObjectLevels[$j] < $level) {
3145             push (@ancestors, $Objects[$j]);
3146             $level = $ObjectLevels[$j];
3147             #print "Level: $level\n";
3148         }
3149     }
3151     # Output the ancestors list, indented and with links.
3152     my $hierarchy = "<synopsis>\n";
3153     $level = 0;
3154     for ($i = $#ancestors; $i >= 0; $i--) {
3155         my $link_text;
3156         # Don't add a link to the current object, i.e. when i == 0.
3157         if ($i > 0) {
3158             my $ancestor_id = &CreateValidSGMLID ($ancestors[$i]);
3159             $link_text = "<link linkend=\"$ancestor_id\">$ancestors[$i]</link>";
3160         } else {
3161             $link_text = "$ancestors[$i]";
3162         }
3163         if ($level == 0) {
3164             $hierarchy .= "  $link_text\n";
3165         } else {
3166 #            $hierarchy .= ' ' x ($level * 6 - 3) . "|\n";
3167             $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3168         }
3169         $level++;
3170     }
3171     for ($i = 0; $i <= $#children; $i++) {
3172       my $id = &CreateValidSGMLID ($children[$i]);
3173       my $link_text = "<link linkend=\"$id\">$children[$i]</link>";
3174       $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3175     }
3176     $hierarchy .= "</synopsis>\n";
3178     return $hierarchy;
3182 #############################################################################
3183 # Function    : GetInterfaces
3184 # Description : Returns the DocBook output describing the interfaces
3185 #               implemented by a class. It uses the global %Interfaces hash.
3186 # Arguments   : $object - the GtkObject subclass.
3187 #############################################################################
3189 sub GetInterfaces {
3190     my ($object) = @_;
3191     my $text = "";
3192     my $i;
3194     # Find object in the objects array.
3195     if (exists($Interfaces{$object})) {
3196         my @ifaces = split(' ', $Interfaces{$object});
3197         $text = <<EOF;
3198 <para>
3199 $object implements
3201         for ($i = 0; $i <= $#ifaces; $i++) {
3202             my $id = &CreateValidSGMLID ($ifaces[$i]);
3203             $text .= " <link linkend=\"$id\">$ifaces[$i]</link>";
3204             if ($i < $#ifaces - 1) {
3205                 $text .= ', ';
3206             }
3207             elsif ($i < $#ifaces) {
3208                 $text .= ' and ';
3209             }
3210             else {
3211                 $text .= '.';
3212             }
3213         }
3214         $text .= <<EOF;
3215 </para>
3217     }
3219     return $text;
3222 #############################################################################
3223 # Function    : GetImplementations
3224 # Description : Returns the DocBook output describing the implementations
3225 #               of an interface. It uses the global %Interfaces hash.
3226 # Arguments   : $object - the GtkObject subclass.
3227 #############################################################################
3229 sub GetImplementations {
3230     my ($object) = @_;
3231     my @impls = ();
3232     my $text = "";
3233     my $i;
3234     foreach my $key (keys %Interfaces) {
3235         if ($Interfaces{$key} =~ /\b$object\b/) {
3236             push (@impls, $key);
3237         }
3238     }
3239     if ($#impls >= 0) {
3240         @impls = sort @impls;
3241         $text = <<EOF;
3242 <para>
3243 $object is implemented by
3245         for ($i = 0; $i <= $#impls; $i++) {
3246             my $id = &CreateValidSGMLID ($impls[$i]);
3247             $text .= " <link linkend=\"$id\">$impls[$i]</link>";
3248             if ($i < $#impls - 1) {
3249                 $text .= ', ';
3250             }
3251             elsif ($i < $#impls) {
3252                 $text .= ' and ';
3253             }
3254             else {
3255                 $text .= '.';
3256             }
3257         }
3258         $text .= <<EOF;
3259 </para>
3261     }
3262     return $text;
3266 #############################################################################
3267 # Function    : GetPrerequisites
3268 # Description : Returns the DocBook output describing the prerequisites
3269 #               of an interface. It uses the global %Prerequisites hash.
3270 # Arguments   : $iface - the interface.
3271 #############################################################################
3273 sub GetPrerequisites {
3274     my ($iface) = @_;
3275     my $text = "";
3276     my $i;
3278     if (exists($Prerequisites{$iface})) {
3279         $text = <<EOF;
3280 <para>
3281 $iface requires
3283         my @prereqs = split(' ', $Prerequisites{$iface});
3284         for ($i = 0; $i <= $#prereqs; $i++) {
3285             my $id = &CreateValidSGMLID ($prereqs[$i]);
3286             $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
3287             if ($i < $#prereqs - 1) {
3288                 $text .= ', ';
3289             }
3290             elsif ($i < $#prereqs) {
3291                 $text .= ' and ';
3292             }
3293             else {
3294                 $text .= '.';
3295             }
3296         }
3297         $text .= <<EOF;
3298 </para>
3300     }
3301     return $text;
3304 #############################################################################
3305 # Function    : GetDerived
3306 # Description : Returns the DocBook output describing the derived interfaces
3307 #               of an interface. It uses the global %Prerequisites hash.
3308 # Arguments   : $iface - the interface.
3309 #############################################################################
3311 sub GetDerived {
3312     my ($iface) = @_;
3313     my $text = "";
3314     my $i;
3316     my @derived = ();
3317     foreach my $key (keys %Prerequisites) {
3318         if ($Prerequisites{$key} =~ /\b$iface\b/) {
3319             push (@derived, $key);
3320         }
3321     }
3322     if ($#derived >= 0) {
3323         @derived = sort @derived;
3324         $text = <<EOF;
3325 <para>
3326 $iface is required by
3328         for ($i = 0; $i <= $#derived; $i++) {
3329             my $id = &CreateValidSGMLID ($derived[$i]);
3330             $text .= " <link linkend=\"$id\">$derived[$i]</link>";
3331             if ($i < $#derived - 1) {
3332                 $text .= ', ';
3333             }
3334             elsif ($i < $#derived) {
3335                 $text .= ' and ';
3336             }
3337             else {
3338                 $text .= '.';
3339             }
3340         }
3341         $text .= <<EOF;
3342 </para>
3344     }
3345     return $text;
3349 #############################################################################
3350 # Function    : GetSignals
3351 # Description : Returns the synopsis and detailed description DocBook output
3352 #                for the signal handlers of a given GtkObject subclass.
3353 # Arguments   : $object - the GtkObject subclass, e.g. 'GtkButton'.
3354 #############################################################################
3356 sub GetSignals {
3357     my ($object) = @_;
3358     my $synop = "";
3359     my $desc = "";
3361     my $i;
3362     for ($i = 0; $i <= $#SignalObjects; $i++) {
3363         if ($SignalObjects[$i] eq $object) {
3364             #print "Found signal: $SignalNames[$i]\n";
3365             my $name = $SignalNames[$i];
3366             my $symbol = "${object}::${name}";
3367             my $id = &CreateValidSGMLID ("$object-$name");
3369             my $pad = ' ' x (46 - length($name));
3370             $synop .= "  &quot;<link linkend=\"$id\">$name</link>&quot;$pad ";
3372             $desc .= "<refsect2 id=\"$id\" role=\"signal\"><title>The <literal>&quot;$name&quot;</literal> signal</title>\n";
3373             $desc .= MakeIndexterms($symbol, $id);
3374             $desc .= "\n";
3375             $desc .= OutputSymbolExtraLinks($symbol);
3377             $desc .= "<programlisting>";
3379             $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
3380             my $type_modifier = defined($1) ? $1 : "";
3381             my $type = $2;
3382             my $pointer = $3;
3383             my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
3385             my $ret_type_len = length ($type_modifier) + length ($pointer)
3386                 + length ($type);
3387             my $ret_type_output = "$type_modifier$xref$pointer"
3388                 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
3390             $desc  .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
3392             my $sourceparams = $SourceSymbolParams{$symbol};
3393             my @params = split ("\n", $SignalPrototypes[$i]);
3394             my $j;
3395             my $l;
3396             my $type_len = length("gpointer");
3397             my $name_len = length("user_data");
3398             # do two passes, the first one is to calculate padding
3399             for ($l = 0; $l < 2; $l++) {
3400                 for ($j = 0; $j <= $#params; $j++) {
3401                     # allow alphanumerics, '_', '[' & ']' in param names
3402                     if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
3403                         $type = $1;
3404                         $pointer = $2;
3405                         if (defined($sourceparams)) {
3406                             $name = $$sourceparams[$PARAM_FIELD_COUNT * $j];
3407                         }
3408                         else {
3409                             $name = $3;
3410                         }
3411                         if (!defined($name)) {
3412                             $name = "arg$j";
3413                         }
3414                         if ($l == 0) {
3415                             if (length($type) + length($pointer) > $type_len) {
3416                                 $type_len = length($type) + length($pointer);
3417                             }
3418                             if (length($name) > $name_len) {
3419                                 $name_len = length($name);
3420                             }
3421                         }
3422                         else {
3423                             $xref = &MakeXRef ($type, &tagify($type, "type"));
3424                             $pad = ' ' x ($type_len - length($type) - length($pointer));
3425                             $desc .= "$xref$pad $pointer$name,\n";
3426                             $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
3427                         }
3428                     } else {
3429                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3430                              "Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]");
3431                     }
3432                 }
3433             }
3434             $xref = &MakeXRef ("gpointer", &tagify("gpointer", "type"));
3435             $pad = ' ' x ($type_len - length("gpointer"));
3436             $desc  .= "$xref$pad user_data)";
3438             my $flags = $SignalFlags[$i];
3439             my $flags_string = "";
3441             if (defined ($flags)) {
3442               if ($flags =~ m/f/) {
3443                 $flags_string = "<link linkend=\"G-SIGNAL-RUN-FIRST:CAPS\"><literal>Run First</literal></link>";
3444               }
3445               elsif ($flags =~ m/l/) {
3446                 $flags_string = "<link linkend=\"G-SIGNAL-RUN-LAST:CAPS\"><literal>Run Last</literal></link>";
3447               }
3448               elsif ($flags =~ m/c/) {
3449                 $flags_string = "<link linkend=\"G-SIGNAL-RUN-CLEANUP:CAPS\"><literal>Cleanup</literal></link>";
3450                 $flags_string = "Cleanup";
3451               }
3452               if ($flags =~ m/r/) {
3453                 if ($flags_string) { $flags_string .= " / "; }
3454                 $flags_string = "<link linkend=\"G-SIGNAL-NO-RECURSE:CAPS\"><literal>No Recursion</literal></link>";
3455               }
3456               if ($flags =~ m/d/) {
3457                 if ($flags_string) { $flags_string .= " / "; }
3458                 $flags_string = "<link linkend=\"G-SIGNAL-DETAILED:CAPS\"><literal>Has Details</literal></link>";
3459               }
3460               if ($flags =~ m/a/) {
3461                 if ($flags_string) { $flags_string .= " / "; }
3462                 $flags_string = "<link linkend=\"G-SIGNAL-ACTION:CAPS\"><literal>Action</literal></link>";
3463               }
3464               if ($flags =~ m/h/) {
3465                 if ($flags_string) { $flags_string .= " / "; }
3466                 $flags_string = "<link linkend=\"G-SIGNAL-NO-HOOKS:CAPS\"><literal>No Hooks</literal></link>";
3467               }
3468             }
3470             if ($flags_string)
3471               {
3472                 $synop .= ": $flags_string\n";
3474                 $pad = ' ' x (5 + $name_len - length("user_data"));
3475                 $desc  .= "$pad : $flags_string</programlisting>\n";
3476               }
3477             else
3478               {
3479                 $synop .= "\n";
3480                 $desc  .= "</programlisting>\n";
3481               }
3483             $desc .= &MakeDeprecationNote($symbol);
3485             my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
3486             my $parameters_output = 0;
3488             $AllSymbols{$symbol} = 1;
3489             if (defined ($SymbolDocs{$symbol})) {
3490                 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3492                 # Try to insert the parameter table at the author's desired
3493                 # position. Otherwise we need to tag it onto the end.
3494                 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
3495                   $parameters_output = 1;
3496                 }
3497                 $desc .= $symbol_docs;
3499                 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
3500                     $AllDocumentedSymbols{$symbol} = 1;
3501                 }
3502             }
3504             if ($parameters_output == 0) {
3505                 $desc .= $parameters;
3506               }
3507             $desc .= OutputSymbolTraits ($symbol);
3508             $desc .= "</refsect2>";
3509         }
3510     }
3511     return ($synop, $desc);
3515 #############################################################################
3516 # Function    : GetArgs
3517 # Description : Returns the synopsis and detailed description DocBook output
3518 #                for the Args of a given GtkObject subclass.
3519 # Arguments   : $object - the GtkObject subclass, e.g. 'GtkButton'.
3520 #############################################################################
3522 sub GetArgs {
3523     my ($object) = @_;
3524     my $synop = "";
3525     my $desc = "";
3526     my $child_synop = "";
3527     my $child_desc = "";
3528     my $style_synop = "";
3529     my $style_desc = "";
3531     my $i;
3532     for ($i = 0; $i <= $#ArgObjects; $i++) {
3533         if ($ArgObjects[$i] eq $object) {
3534             #print "Found arg: $ArgNames[$i]\n";
3535             my $name = $ArgNames[$i];
3536             my $flags = $ArgFlags[$i];
3537             my $flags_string = "";
3538             my $kind = "";
3539             my $id_sep = "";
3541             if ($flags =~ m/c/) {
3542                 $kind = "child property";
3543                 $id_sep = "c-";
3544             }
3545             elsif ($flags =~ m/s/) {
3546                 $kind = "style property";
3547                 $id_sep = "s-";
3548             }
3549             else {
3550                 $kind = "property";
3551             }
3553             # Remember only one colon so we don't clash with signals.
3554             my $symbol = "${object}:${name}";
3555             # use two dashes and ev. an extra separator here for the same reason.
3556             my $id = &CreateValidSGMLID ("$object--$id_sep$name");
3558             my $type = $ArgTypes[$i];
3559             my $type_output;
3560             my $range = $ArgRanges[$i];
3561             my $range_output = CreateValidSGML ($range);
3562             my $default = $ArgDefaults[$i];
3563             my $default_output = CreateValidSGML ($default);
3565             if ($type eq "GtkString") {
3566                 $type = "char*";
3567             }
3568             if ($type eq "GtkSignal") {
3569                 $type = "GtkSignalFunc, gpointer";
3570                 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
3571                     . &MakeXRef ("gpointer");
3572             } elsif ($type =~ m/^(\w+)\*$/) {
3573                 $type_output = &MakeXRef ($1, &tagify($1, "type")) . "*";
3574             } else {
3575                 $type_output = &MakeXRef ($type, &tagify($type, "type"));
3576             }
3578             if ($flags =~ m/r/) {
3579                 $flags_string = "Read";
3580             }
3581             if ($flags =~ m/w/) {
3582                 if ($flags_string) { $flags_string .= " / "; }
3583                 $flags_string .= "Write";
3584             }
3585             if ($flags =~ m/x/) {
3586                 if ($flags_string) { $flags_string .= " / "; }
3587                 $flags_string .= "Construct";
3588             }
3589             if ($flags =~ m/X/) {
3590                 if ($flags_string) { $flags_string .= " / "; }
3591                 $flags_string .= "Construct Only";
3592             }
3594             $AllSymbols{$symbol} = 1;
3595             my $blurb;
3596             if (defined($SymbolDocs{$symbol}) &&
3597                 !IsEmptyDoc($SymbolDocs{$symbol})) {
3598                 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3599                 #print ".. [$SymbolDocs{$symbol}][$blurb]\n";
3600                 $AllDocumentedSymbols{$symbol} = 1;
3601             }
3602             else {
3603                 if (!($ArgBlurbs[$i] eq "")) {
3604                     $AllDocumentedSymbols{$symbol} = 1;
3605                 } else {
3606                     # FIXME: print a warning?
3607                     #print ".. no description\n";
3608                 }
3609                 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
3610             }
3612             my $pad1 = " " x (24 - length ($name));
3613             my $pad2 = " " x (20 - length ($type));
3615              my $arg_synop = "  &quot;<link linkend=\"$id\">$name</link>&quot;$pad1 $type_output $pad2 : $flags_string\n";
3616             my $arg_desc = "<refsect2 id=\"$id\" role=\"property\"><title>The <literal>&quot;$name&quot;</literal> $kind</title>\n";
3617             $arg_desc .= MakeIndexterms($symbol, $id);
3618             $arg_desc .= "\n";
3619             $arg_desc .= OutputSymbolExtraLinks($symbol);
3621             $arg_desc .= "<programlisting>  &quot;$name&quot;$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
3622             $arg_desc .= &MakeDeprecationNote($symbol);
3623             $arg_desc .= $blurb;
3624             if ($range ne "") {
3625                 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
3626             }
3627             if ($default ne "") {
3628                 $arg_desc .= "<para>Default value: $default_output</para>\n";
3629             }
3630             $arg_desc .= OutputSymbolTraits ($symbol);
3631             $arg_desc .= "</refsect2>\n";
3633             if ($flags =~ m/c/) {
3634                 $child_synop .= $arg_synop;
3635                 $child_desc .= $arg_desc;
3636             }
3637             elsif ($flags =~ m/s/) {
3638                 $style_synop .= $arg_synop;
3639                 $style_desc .= $arg_desc;
3640             }
3641             else {
3642                 $synop .= $arg_synop;
3643                 $desc .= $arg_desc;
3644             }
3645         }
3646     }
3647     return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
3651 #############################################################################
3652 # Function    : ReadSourceDocumentation
3653 # Description : This reads in the documentation embedded in comment blocks
3654 #                in the source code (for Gnome).
3656 #                Parameter descriptions override any in the template files.
3657 #                Function descriptions are placed before any description from
3658 #                the template files.
3660 #                It recursively descends the source directory looking for .c
3661 #                files and scans them looking for specially-formatted comment
3662 #                blocks.
3664 # Arguments   : $source_dir - the directory to scan.
3665 #############m###############################################################
3667 sub ReadSourceDocumentation {
3668     my ($source_dir) = @_;
3669     my ($file, $dir, @suffix_list, $suffix);
3671     # prepend entries from @SOURCE_DIR
3672     for my $dir (@SOURCE_DIRS) {
3673         # Check if the filename is in the ignore list.
3674         if ($source_dir =~ m%^\Q$dir\E/(.*)$% and $IGNORE_FILES =~ m/(\s|^)\Q$1\E(\s|$)/) {
3675             @TRACE@("Skipping source directory: $source_dir");
3676             return;
3677         }
3678     }
3680     @TRACE@("Scanning source directory: $source_dir");
3682     # This array holds any subdirectories found.
3683     my (@subdirs) = ();
3685     @suffix_list = split (/,/, $SOURCE_SUFFIXES);
3687     opendir (SRCDIR, $source_dir)
3688         || die "Can't open source directory $source_dir: $!";
3690     foreach $file (readdir (SRCDIR)) {
3691       if ($file =~ /^\./) {
3692         next;
3693       } elsif (-d "$source_dir/$file") {
3694         push (@subdirs, $file);
3695       } elsif (@suffix_list) {
3696         foreach $suffix (@suffix_list) {
3697           if ($file =~ m/\.\Q${suffix}\E$/) {
3698             &ScanSourceFile ("$source_dir/$file");
3699           }
3700         }
3701       } elsif ($file =~ m/\.[ch]$/) {
3702         &ScanSourceFile ("$source_dir/$file");
3703       }
3704     }
3705     closedir (SRCDIR);
3707     # Now recursively scan the subdirectories.
3708     foreach $dir (@subdirs) {
3709         &ReadSourceDocumentation ("$source_dir/$dir");
3710     }
3714 #############################################################################
3715 # Function    : ScanSourceFile
3716 # Description : Scans one source file looking for specially-formatted comment
3717 #                blocks. Later &MergeSourceDocumentation is used to merge any
3718 #                documentation found with the documentation already read in
3719 #                from the template files.
3721 # Arguments   : $file - the file to scan.
3722 #############################################################################
3724 sub ScanSourceFile {
3725     my ($file) = @_;
3726     my $basename;
3728     # prepend entries from @SOURCE_DIR
3729     for my $dir (@SOURCE_DIRS) {
3730         # Check if the filename is in the ignore list.
3731         if ($file =~ m%^\Q$dir\E/(.*)$% and $IGNORE_FILES =~ m/(\s|^)\Q$1\E(\s|$)/) {
3732             @TRACE@("Skipping source file: $file");
3733             return;
3734         }
3735     }
3737     if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
3738         $basename = $1;
3739     } else {
3740         &LogWarning ($file, 1, "Can't find basename for this filename.");
3741         $basename = $file;
3742     }
3744     # Check if the basename is in the list of files to ignore.
3745     if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
3746         @TRACE@("Skipping source file: $file");
3747         return;
3748     }
3750     @TRACE@("Scanning source file: $file");
3752     open (SRCFILE, $file)
3753         || die "Can't open $file: $!";
3754     my $in_comment_block = 0;
3755     my $symbol;
3756     my $in_part = "";
3757     my ($description, $return_desc, $return_start, $return_style);
3758     my ($since_desc, $stability_desc, $deprecated_desc);
3759     my $current_param;
3760     my $ignore_broken_returns;
3761     my @params;
3762     while (<SRCFILE>) {
3763         # Look for the start of a comment block.
3764         if (!$in_comment_block) {
3765             if (m%^\s*/\*.*\*/%) {
3766                 #one-line comment - not gtkdoc
3767             } elsif (m%^\s*/\*\*\s%) {
3768                 #print "Found comment block start\n";
3770                 $in_comment_block = 1;
3772                 # Reset all the symbol data.
3773                 $symbol = "";
3774                 $in_part = "";
3775                 $description = "";
3776                 $return_desc = "";
3777                 $return_style = "";
3778                 $since_desc = "";
3779                 $deprecated_desc = "";
3780                 $stability_desc = "";
3781                 $current_param = -1;
3782                 $ignore_broken_returns = 0;
3783                 @params = ();
3784             }
3785             next;
3786         }
3788         # We're in a comment block. Check if we've found the end of it.
3789         if (m%^\s*\*+/%) {
3790             if (!$symbol) {
3791                 # maybe its not even meant to be a gtk-doc comment?
3792                 &LogWarning ($file, $., "Symbol name not found at the start of the comment block.");
3793             } else {
3794                 # Add the return value description onto the end of the params.
3795                 if ($return_desc) {
3796                     push (@params, "Returns");
3797                     push (@params, $return_desc);
3798                     if ($return_style eq 'broken') {
3799                         &LogWarning ($file, $., "Free-form return value description in $symbol. Use `Returns:' to avoid ambiguities.");
3800                     }
3801                 }
3802                 # Convert special SGML characters
3803                 $description = &ConvertSGMLChars ($symbol, $description);
3804                 my $k;
3805                 for ($k = 1; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3806                     $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
3807                 }
3809                 # Handle Section docs
3810                 if ($symbol =~ m/SECTION:\s*(.*)/) {
3811                     my $real_symbol=$1;
3812                     my $key;
3814                     if (scalar %KnownSymbols) {
3815                         if ((! defined($KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"})) || $KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"} != 1) {
3816                             &LogWarning ($file, $., "Section $real_symbol is not defined in the $MODULE-sections.txt file.");
3817                         }
3818                     }
3820                     #print "SECTION DOCS found in source for : '$real_symbol'\n";
3821                     $ignore_broken_returns = 1;
3822                     for ($k = 0; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3823                         #print "   '".$params[$k]."'\n";
3824                         $params[$k] = "\L$params[$k]";
3825                         undef $key;
3826                         if ($params[$k] eq "short_description") {
3827                             $key = "$TMPL_DIR/$real_symbol:Short_Description";
3828                         } elsif ($params[$k] eq "see_also") {
3829                             $key = "$TMPL_DIR/$real_symbol:See_Also";
3830                         } elsif ($params[$k] eq "title") {
3831                             $key = "$TMPL_DIR/$real_symbol:Title";
3832                         } elsif ($params[$k] eq "stability") {
3833                             $key = "$TMPL_DIR/$real_symbol:Stability_Level";
3834                         } elsif ($params[$k] eq "section_id") {
3835                             $key = "$TMPL_DIR/$real_symbol:Section_Id";
3836                         } elsif ($params[$k] eq "include") {
3837                             $key = "$TMPL_DIR/$real_symbol:Include";
3838                         } elsif ($params[$k] eq "image") {
3839                             $key = "$TMPL_DIR/$real_symbol:Image";
3840                         }
3841                         if (defined($key)) {
3842                             $SourceSymbolDocs{$key}=$params[$k+1];
3843                             $SourceSymbolSourceFile{$key} = $file;
3844                             $SourceSymbolSourceLine{$key} = $.;
3845                         }
3846                     }
3847                     $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
3848                     $SourceSymbolSourceFile{"$TMPL_DIR/$real_symbol:Long_Description"} = $file;
3849                     $SourceSymbolSourceLine{"$TMPL_DIR/$real_symbol:Long_Description"} = $.;
3850                     #$SourceSymbolTypes{$symbol} = "SECTION";
3851                 } else {
3852                     #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
3853                     $SourceSymbolDocs{$symbol} = $description;
3854                     $SourceSymbolParams{$symbol} = [ @params ];
3855                     # FIXME $SourceSymbolTypes{$symbol} = "STRUCT,SIGNAL,ARG,FUNCTION,MACRO";
3856                     #if (defined $DeclarationTypes{$symbol}) {
3857                     #    $SourceSymbolTypes{$symbol} = $DeclarationTypes{$symbol}
3858                     #}
3859                     $SourceSymbolSourceFile{$symbol} = $file;
3860                     $SourceSymbolSourceLine{$symbol} = $.;
3861                 }
3863                 if ($since_desc) {
3864                      ($since_desc, my @extra_lines) = split ("\n", $since_desc);
3865                      $since_desc =~ s/^\s+//;
3866                      $since_desc =~ s/\s+$//;
3867                      #print "Since($symbol) : [$since_desc]\n";
3868                      $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
3869                      if(scalar @extra_lines) {
3870                          &LogWarning ($file, $., "multi-line since docs found");
3871                      }
3872                 }
3874                 if ($stability_desc) {
3875                     $stability_desc = &ParseStabilityLevel($stability_desc, $file, $., "Stability level for $symbol");
3876                     $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
3877                 }
3879                 if ($deprecated_desc) {
3880                     if (exists $Deprecated{$symbol}) {
3881                     }
3882                     else {
3883                          # don't warn for signals and properties
3884                          #if ($symbol !~ m/::?(.*)/) {
3885                          if (defined $DeclarationTypes{$symbol}) {
3886                              &LogWarning ($file, $.,
3887                                  "$symbol is deprecated in the inline comments, but no deprecation guards were found around the declaration.".
3888                                  " (See the --deprecated-guards option for gtkdoc-scan.)");
3889                          }
3890                     }
3891                     $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
3892                 }
3893             }
3895             $in_comment_block = 0;
3896             next;
3897         }
3899         # Get rid of ' * ' at start of every line in the comment block.
3900         s%^\s*\*\s?%%;
3901         # But make sure we don't get rid of the newline at the end.
3902         if (!$_) {
3903             $_ = "\n";
3904         }
3905         #print "DEBUG: scanning :$_";
3907         # If we haven't found the symbol name yet, look for it.
3908         if (!$symbol) {
3909             if (m%^\s*(SECTION:\s*\S+)%) {
3910                 $symbol = $1;
3911                 #print "SECTION DOCS found in source for : '$symbol'\n";
3912                 $ignore_broken_returns = 1;
3913             } elsif (m%^\s*([\w:-]*\w)\s*:?\s*(\([a-z ]+\)\s*)*$%) {
3914                 $symbol = $1;
3915                 #print "SYMBOL DOCS found in source for : '$symbol'\n";
3916             }
3917             next;
3918         }
3920         if ($in_part eq "description") {
3921             # Get rid of 'Description:'
3922             s%^\s*Description:%%;
3923         }
3925         if (m/^\s*(returns:|return\s+value:)/i) {
3926             if ($return_style eq 'broken') {
3927                 $description .= $return_start . $return_desc;
3928             }
3929             $return_start = $1;
3930             if ($return_style eq 'sane') {
3931                 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3932             }
3933             $return_style = 'sane';
3934             $ignore_broken_returns = 1;
3935             $return_desc = $';
3936             $in_part = "return";
3937             next;
3938         } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3939             $return_start = $1;
3940             $return_style = 'broken';
3941             $return_desc = $';
3942             $in_part = "return";
3943             next;
3944         } elsif (m%^\s*since:%i) {
3945             # we're in param section and have not seen the blank line
3946             if($in_part ne "") {
3947               $since_desc = $';
3948               $in_part = "since";
3949               next;
3950             }
3951         } elsif (m%^\s*deprecated:%i) {
3952             # we're in param section and have not seen the blank line
3953             if($in_part ne "") {
3954               $deprecated_desc = $';
3955               $in_part = "deprecated";
3956               next;
3957             }
3958         } elsif (m%^\s*stability:%i) {
3959             $stability_desc = $';
3960             $in_part = "stability";
3961             next;
3962         }
3964         if ($in_part eq "description") {
3965             $description .= $_;
3966             next;
3967         } elsif ($in_part eq "return") {
3968             $return_desc .= $_;
3969             next;
3970         } elsif ($in_part eq "since") {
3971             $since_desc .= $_;
3972             next;
3973         } elsif ($in_part eq "stability") {
3974             $stability_desc .= $_;
3975             next;
3976         } elsif ($in_part eq "deprecated") {
3977             $deprecated_desc .= $_;
3978             next;
3979         }
3981         # We must be in the parameters. Check for the empty line below them.
3982         if (m%^\s*$%) {
3983             $in_part = "description";
3984             next;
3985         }
3987         # Look for a parameter name.
3988         if (m%^\s*@(\S+)\s*:\s*%) {
3989             my $param_name = $1;
3990             my $param_desc = $';
3992             #print "Found parameter: $param_name\n";
3993             # Allow varargs variations
3994             if ($param_name =~ m/^\.\.\.$/) {
3995                 $param_name = "...";
3996             }
3997             if ("\L$param_name" eq "returns") {
3998                 $return_style = 'sane';
3999                 $ignore_broken_returns = 1;
4000             }
4001             @TRACE@("Found param for symbol $symbol : '$param_name'= '$_'");
4003             push (@params, $param_name);
4004             push (@params, $param_desc);
4005             $current_param += $PARAM_FIELD_COUNT;
4006             next;
4007         }
4009         # We must be in the middle of a parameter description, so add it on
4010         # to the last element in @params.
4011         if ($current_param == -1) {
4012             &LogWarning ($file, $., "Parsing comment block file : parameter expected.");
4013         } else {
4014             $params[$#params] .= $_;
4015         }
4016     }
4017     close (SRCFILE);
4020 #############################################################################
4021 # Function    : OutputMissingDocumentation
4022 # Description : Outputs report of documentation coverage to a file
4024 # Arguments   : none
4025 #############################################################################
4027 sub OutputMissingDocumentation {
4028     my $old_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.txt";
4029     my $new_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.new";
4031     my $n_documented = 0;
4032     my $n_incomplete = 0;
4033     my $total = 0;
4034     my $symbol;
4035     my $percent;
4036     my $msg;
4037     my $buffer = "";
4038     my $buffer_deprecated = "";
4039     my $buffer_descriptions = "";
4041     open(UNDOCUMENTED, ">$new_undocumented_file")
4042       || die "Can't create $new_undocumented_file";
4044     foreach $symbol (sort (keys (%AllSymbols))) {
4045         # FIXME: should we print LogWarnings for undocumented stuff?
4046         # DEBUG
4047         #my $ssfile = &GetSymbolSourceFile($symbol);
4048         #my $ssline = &GetSymbolSourceLine($symbol);
4049         #my $location = "defined at " . (defined($ssfile)?$ssfile:"?") . ":" . (defined($ssline)?$ssline:"0") . "\n";
4050         # DEBUG
4051         if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include|Section_Id|Image)/) {
4052             $total++;
4053             if (exists ($AllDocumentedSymbols{$symbol})) {
4054                 $n_documented++;
4055                 if (exists ($AllIncompleteSymbols{$symbol})) {
4056                     $n_incomplete++;
4057                     $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4058                     #$buffer .= "\t0: ".$location;
4059                 }
4060             } elsif (exists $Deprecated{$symbol}) {
4061                 if (exists ($AllIncompleteSymbols{$symbol})) {
4062                     $n_incomplete++;
4063                     $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4064                     #$buffer .= "\t1a: ".$location;
4065                 } else {
4066                     $buffer_deprecated .= $symbol . "\n";
4067                     #$buffer .= "\t1b: ".$location;
4068                 }
4069             } else {
4070                 if (exists ($AllIncompleteSymbols{$symbol})) {
4071                     $n_incomplete++;
4072                     $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4073                     #$buffer .= "\t2a: ".$location;
4074                 } else {
4075                     $buffer .= $symbol . "\n";
4076                     #$buffer .= "\t2b: ".$location;
4077                 }
4078             }
4079         } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
4080             $total++;
4081             #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
4082             #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
4083             #print "%%%% $symbol : $len1,$len2\n";
4084             if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
4085             || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
4086               $n_documented++;
4087             } else {
4088               # cut off the leading namespace ($TMPL_DIR)
4089               $symbol =~ m/^.*\/(.*)$/;
4090               $buffer_descriptions .= $1 . "\n";
4091             }
4092         }
4093     }
4095     $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
4097     if ($total == 0) {
4098       $percent = 100;
4099     } else {
4100       $percent = ($n_documented / $total) * 100.0;
4101     }
4103     printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
4104     print UNDOCUMENTED "$n_documented symbols documented.\n";
4105     print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
4106     print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
4108     print UNDOCUMENTED $buffer;
4109     close (UNDOCUMENTED);
4111     return &UpdateFileIfChanged ($old_undocumented_file, $new_undocumented_file, 0);
4113     printf "%.0f%% symbol docs coverage", $percent;
4114     print "($n_documented symbols documented, $n_incomplete symbols incomplete, " . ($total - $n_documented) . " not documented)\n";
4115     print "See $MODULE-undocumented.txt for a list of missing docs.\nThe doc coverage percentage doesn't include intro sections.\n";
4119 #############################################################################
4120 # Function    : OutputUndeclaredSymbols
4121 # Description : Outputs symbols that are listed in the section file, but not
4122 #               declaration is found in the sources
4124 # Arguments   : none
4125 #############################################################################
4127 sub OutputUndeclaredSymbols {
4128     my $old_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.txt";
4129     my $new_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.new";
4131     open(UNDECLARED, ">$new_undeclared_file")
4132         || die "Can't create $new_undeclared_file";
4134     if (%UndeclaredSymbols) {
4135         print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
4136         print UNDECLARED "\n";
4137         print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
4138     }
4139     close(UNDECLARED);
4141     return &UpdateFileIfChanged ($old_undeclared_file, $new_undeclared_file, 0);
4144 #############################################################################
4145 # Function    : OutputUnusedSymbols
4146 # Description : Outputs symbols that are documented in comments, but not
4147 #               declared in the sources
4149 # Arguments   : none
4150 #############################################################################
4152 sub OutputUnusedSymbols {
4153     my $num_unused = 0;
4154     my $old_unused_file = "$ROOT_DIR/$MODULE-unused.txt";
4155     my $new_unused_file = "$ROOT_DIR/$MODULE-unused.new";
4157     open (UNUSED, ">$new_unused_file")
4158         || die "Can't open $new_unused_file";
4159     my ($symbol);
4160     foreach $symbol (sort keys (%Declarations)) {
4161         if (!defined ($DeclarationOutput{$symbol})) {
4162             print (UNUSED "$symbol\n");
4163             $num_unused++;
4164         }
4165     }
4166     foreach $symbol (sort (keys (%AllUnusedSymbols))) {
4167         print (UNUSED "$symbol(" . $AllUnusedSymbols{$symbol} . ")\n");
4168         $num_unused++;
4169     }
4170     close (UNUSED);
4171     if ($num_unused != 0) {
4172         &LogWarning ($old_unused_file, 1, "$num_unused unused declarations.".
4173             "They should be added to $MODULE-sections.txt in the appropriate place.");
4174     }
4176     return &UpdateFileIfChanged ($old_unused_file, $new_unused_file, 0);
4180 #############################################################################
4181 # Function    : OutputAllSymbols
4182 # Description : Outputs list of all symbols to a file
4184 # Arguments   : none
4185 #############################################################################
4187 sub OutputAllSymbols {
4188      my $n_documented = 0;
4189      my $total = 0;
4190      my $symbol;
4191      my $percent;
4192      my $msg;
4194      open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
4195           || die "Can't create $ROOT_DIR/$MODULE-symbols.txt: $!";
4197      foreach $symbol (sort (keys (%AllSymbols))) {
4198           print SYMBOLS $symbol . "\n";
4199      }
4201      close (SYMBOLS);
4204 #############################################################################
4205 # Function    : OutputSymbolsWithoutSince
4206 # Description : Outputs list of all symbols without a since tag to a file
4208 # Arguments   : none
4209 #############################################################################
4211 sub OutputSymbolsWithoutSince {
4212      my $n_documented = 0;
4213      my $total = 0;
4214      my $symbol;
4215      my $percent;
4216      my $msg;
4218      open (SYMBOLS, ">$ROOT_DIR/$MODULE-nosince.txt")
4219           || die "Can't create $ROOT_DIR/$MODULE-nosince.txt: $!";
4221      foreach $symbol (sort (keys (%SourceSymbolDocs))) {
4222          if (!defined $Since{$symbol}) {
4223              print SYMBOLS $symbol . "\n";
4224          }
4225      }
4227      close (SYMBOLS);
4231 #############################################################################
4232 # Function    : MergeSourceDocumentation
4233 # Description : This merges documentation read from a source file into the
4234 #                documentation read in from a template file.
4236 #                Parameter descriptions override any in the template files.
4237 #                Function descriptions are placed before any description from
4238 #                the template files.
4240 # Arguments   : none
4241 #############################################################################
4243 sub MergeSourceDocumentation {
4244     my $symbol;
4245     my @Symbols;
4247     if (scalar %SymbolDocs) {
4248         @Symbols=keys (%SymbolDocs);
4249         #print "num existing entries: ".(scalar @Symbols)."\n";
4250         #print "  ",$Symbols[0], " ",$Symbols[1],"\n";
4251     }
4252     else {
4253         # filter scanned declarations, with what we suppress from -sections.txt
4254         my %tmp = ();
4255         foreach $symbol (keys (%Declarations)) {
4256             if (defined($KnownSymbols{$symbol}) && $KnownSymbols{$symbol} == 1) {
4257                 $tmp{$symbol}=1;
4258             }
4259         }
4260         # , add the rest from -sections.txt
4261         foreach $symbol (keys (%KnownSymbols)) {
4262             if ($KnownSymbols{$symbol} == 1) {
4263                 $tmp{$symbol}=1;
4264             }
4265         }
4266         # and add whats found in the source
4267         foreach $symbol (keys (%SourceSymbolDocs)) {
4268             $tmp{$symbol}=1;
4269         }
4270         @Symbols = keys (%tmp);
4271         #print "num source entries: ".(scalar @Symbols)."\n";
4272     }
4273     foreach $symbol (@Symbols) {
4274         $AllSymbols{$symbol} = 1;
4276         my $have_tmpl_docs = 0;
4278         ## see if the symbol is documented in template
4279         my $tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4280         my $check_tmpl_doc =$tmpl_doc;
4281         # remove all xml-tags and whitespaces
4282         $check_tmpl_doc =~ s/<.*?>//g;
4283         $check_tmpl_doc =~ s/\s//g;
4284         # anything left ?
4285         if ($check_tmpl_doc ne "") {
4286             $have_tmpl_docs = 1;
4287             #print "## [$check_tmpl_doc]\n";
4288         } else {
4289             # if the docs have just an empty para, don't merge that.
4290             $check_tmpl_doc = $tmpl_doc;
4291             $check_tmpl_doc =~ s/(\s|\n)//msg;
4292             if ($check_tmpl_doc eq "<para></para>") {
4293                $tmpl_doc = "";
4294             }
4295         }
4297         if (exists ($SourceSymbolDocs{$symbol})) {
4298             my $type = $DeclarationTypes {$symbol};
4300             #print "merging [$symbol] from source\n";
4302             my $item = "Parameter";
4303             if (defined ($type)) {
4304                 if ($type eq 'STRUCT') {
4305                     $item = "Field";
4306                 } elsif ($type eq 'ENUM') {
4307                     $item = "Value";
4308                 } elsif ($type eq 'UNION') {
4309                     $item = "Field";
4310                 }
4311             } else {
4312                 $type="SIGNAL";
4313             }
4315             my $src_doc = $SourceSymbolDocs{$symbol};
4316             # remove leading and training whitespaces
4317             $src_doc =~ s/^\s+//;
4318             $src_doc =~ s/\s+$//;
4320             # Don't output warnings for overridden titles as titles are
4321             # automatically generated in the -sections.txt file, and thus they
4322             # are often overridden.
4323             if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
4324                 # check if content is different
4325                 if ($tmpl_doc ne $src_doc) {
4326                     #print "[$tmpl_doc] [$src_doc]\n";
4327                     &LogWarning ($SourceSymbolSourceFile{$symbol}, $SourceSymbolSourceLine{$symbol},
4328                         "Documentation in template ".$SymbolSourceFile{$symbol}.":".$SymbolSourceLine{$symbol}." for $symbol being overridden by inline comments.");
4329                 }
4330             }
4332             if ($src_doc ne "") {
4333                  $AllDocumentedSymbols{$symbol} = 1;
4334             }
4336             # Convert <!--PARAMETERS--> with any blank lines around it to
4337             # a </para> followed by <!--PARAMETERS--> followed by <para>.
4338             $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
4340             # Do not add <para> to nothing, it breaks missing docs checks.
4341             my $src_doc_para = "";
4342             if ($src_doc ne "") {
4343                 # Expand markdown (and do paragraphs)
4344                 $src_doc_para = &ConvertMarkDown ($src_doc, $symbol);
4345                 ## fixup xml markup
4346                 # FIXME: this is questionable, as we can't make assumtions on the content really
4347                 #$src_doc_para =~ s%^<para>\n(<refsect[1-9])%$1%gms;
4348                 #$src_doc_para =~ s%^<para>\n<para>%<para>%gms;
4349                 #$src_doc_para =~ s%(</refsect[1-9]>)\n</para>$%$1%gms;
4350                 #print "$symbol : [$src_doc][$src_doc_para]\n";
4351             }
4353             if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
4354                 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4355             } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
4356                 # For the title/summary/see also section docs we don't want to
4357                 # add any <para> tags.
4358                 $SymbolDocs{$symbol} = "$src_doc"
4359             } else {
4360                 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4361             }
4363             # merge parameters
4364             if ($symbol =~ m/.*::.*/) {
4365                 # For signals we prefer the param names from the source docs,
4366                 # since the ones from the templates are likely to contain the
4367                 # artificial argn names which are generated by gtkdoc-scangobj.
4368                 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4369                 # FIXME: we need to check for empty docs here as well!
4370             } else {
4371                 # The templates contain the definitive parameter names and order,
4372                 # so we will not change that. We only override the actual text.
4373                 my $tmpl_params = $SymbolParams{$symbol};
4374                 if (!defined ($tmpl_params)) {
4375                     #print "No merge needed for $symbol\n";
4376                     $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4377                     #  FIXME: we still like to get the number of params and merge
4378                     #  1) we would noticed that params have been removed/renamed
4379                     #  2) we would catch undocumented params
4380                     #  params are not (yet) exported in -decl.txt so that we
4381                     #  could easily grab them :/
4382                 } else {
4383                     my $params = $SourceSymbolParams{$symbol};
4384                     my $j;
4385                     #print "Merge needed for $symbol, tmpl_params: ",$#$tmpl_params,", source_params: ",$#$params," \n";
4386                     for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4387                         my $tmpl_param_name = $$tmpl_params[$j];
4389                         # Try to find the param in the source comment documentation.
4390                         my $found = 0;
4391                         my $k;
4392                         #print "  try merge param $tmpl_param_name\n";
4393                         for ($k = 0; $k <= $#$params; $k += $PARAM_FIELD_COUNT) {
4394                             my $param_name = $$params[$k];
4395                             my $param_desc = $$params[$k + 1];
4397                             #print "    test param  $param_name\n";
4398                             # We accept changes in case, since the Gnome source
4399                             # docs contain a lot of these.
4400                             if ("\L$param_name" eq "\L$tmpl_param_name") {
4401                                 $found = 1;
4403                                 # Override the description.
4404                                 $$tmpl_params[$j + 1] = $param_desc;
4406                                 # Set the name to "" to mark it as used.
4407                                 $$params[$k] = "";
4408                                 last;
4409                             }
4410                         }
4412                         # If it looks like the parameters are there, but not
4413                         # in the right place, try to explain a bit better.
4414                         if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
4415                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4416                                 "Parameters for $symbol must start on the line immediately after the function or macro name.");
4417                         }
4418                     }
4420                     # Now we output a warning if parameters have been described which
4421                     # do not exist.
4422                     for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
4423                         my $param_name = $$params[$j];
4424                         if ($param_name) {
4425                             # the template builder cannot detect if a macro returns
4426                             # a result or not
4427                             if(($type eq "MACRO") && ($param_name eq "Returns")) {
4428                                 # FIXME: do we need to add it then to tmpl_params[] ?
4429                                 my $num=$#$tmpl_params;
4430                                 #print "  adding Returns: to macro docs for $symbol.\n";
4431                                 $$tmpl_params[$num+1]="Returns";
4432                                 $$tmpl_params[$num+2]=$$params[$j+1];
4433                                 next;
4434                             }
4435                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4436                                 "$item described in source code comment block but does not exist. $type: $symbol $item: $param_name.");
4437                         }
4438                     }
4439                 }
4440             }
4441         } else {
4442             if ($have_tmpl_docs) {
4443                 $AllDocumentedSymbols{$symbol} = 1;
4444                 #print "merging [$symbol] from template\n";
4445             }
4446             else {
4447                 #print "[$symbol] undocumented\n";
4448             }
4449         }
4451         # if this symbol is documented, check if docs are complete
4452         $check_tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4453         # remove all xml-tags and whitespaces
4454         $check_tmpl_doc =~ s/<.*?>//g;
4455         $check_tmpl_doc =~ s/\s//g;
4456         if ($check_tmpl_doc ne "") {
4457             my $tmpl_params = $SymbolParams{$symbol};
4458             if (defined ($tmpl_params)) {
4459                 my $type = $DeclarationTypes {$symbol};
4461                 my $item = "Parameter";
4462                 if (defined ($type)) {
4463                     if ($type eq 'STRUCT') {
4464                         $item = "Field";
4465                     } elsif ($type eq 'ENUM') {
4466                         $item = "Value";
4467                     } elsif ($type eq 'UNION') {
4468                         $item = "Field";
4469                     }
4470                 } else {
4471                     $type="SIGNAL";
4472                 }
4474                 #print "Check param docs for $symbol, tmpl_params: ",$#$tmpl_params," entries, type=$type\n";
4476                 if ($#$tmpl_params > 0) {
4477                     my $j;
4478                     for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4479                         # Output a warning if the parameter is empty and
4480                         # remember for stats.
4481                         my $tmpl_param_name = $$tmpl_params[$j];
4482                         my $tmpl_param_desc = $$tmpl_params[$j + 1];
4483                         if ($tmpl_param_name ne "void" && $tmpl_param_desc !~ m/\S/) {
4484                             if (exists ($AllIncompleteSymbols{$symbol})) {
4485                                 $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
4486                             } else {
4487                                 $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
4488                             }
4489                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4490                                 "$item description for $symbol"."::"."$tmpl_param_name is missing in source code comment block.");
4491                         }
4492                     }
4493                 }
4494                 else {
4495                     if ($#$tmpl_params == 0) {
4496                         $AllIncompleteSymbols{$symbol}="<items>";
4497                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4498                             "$item descriptions for $symbol are missing in source code comment block.");
4499                     }
4500                     # $#$tmpl_params==-1 means we don't know about parameters
4501                     # this unfortunately does not tell if there should be some
4502                 }
4503             }
4504         }
4505    }
4506    #print "num doc entries: ".(scalar %SymbolDocs)."\n";
4509 #############################################################################
4510 # Function    : IsEmptyDoc
4511 # Description : Check if a doc-string is empty. Its also regarded as empty if
4512 #               it only consist of whitespace or e.g. FIXME.
4513 # Arguments   : the doc-string
4514 #############################################################################
4515 sub IsEmptyDoc {
4516     my ($doc) = @_;
4518     if ($doc =~ /^\s*$/) {
4519         return 1;
4520     }
4522     if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
4523         return 1;
4524     }
4526     return 0;
4530 #############################################################################
4531 # Function    : ConvertMarkDown
4532 # Description : Converts mark down syntax to the respective docbook, but only
4533 #               outside CDATA and <programlisting> tags.
4534 #               http://de.wikipedia.org/wiki/Markdown
4535 #               Code snippets have been takesn from
4536 #               http://daringfireball.net/projects/markdown/
4537 #                 Copyright (c) 2004 John Gruber
4538 # Arguments   : the doc-string, the symbol name
4539 #############################################################################
4540 my $md_in_refsect2;
4541 sub ConvertMarkDown {
4542     my ($text, $symbol) = @_;
4544     # reset state
4545     $md_in_refsect2=0;
4547     # convert
4548     $text = &ModifyXMLElements ($text, $symbol,
4549                                "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
4550                                \&ConvertMarkDownEndTag,
4551                                \&ConvertMarkDownCallback);
4552     # encapsulate and terminate
4553     $text = "<para>\n$text\n</para>";
4554     if ($md_in_refsect2==1) {
4555         $text = "$text</refsect2>"
4556     }
4557     return $text
4560 sub ConvertMarkDownEndTag {
4561   if ($_[0] eq "<!\[CDATA\[") {
4562     return "]]>";
4563   } elsif ($_[0] eq "|[") {
4564     return "]\\|";
4565   } else {
4566     return "</programlisting>";
4567   }
4570 sub ConvertMarkDownCallback {
4571   my ($text, $symbol, $tag) = @_;
4573   # If we're not in CDATA or a <programlisting> we convert blank lines so
4574   # they start a new <para>.
4575   if ($tag eq "") {
4576     my $end_of_para="";
4577     my $end_of_section="";
4578     my $have_list=0;
4580     $end_of_para = "$end_of_para</para>";
4581     $end_of_section = "$end_of_section</para>";
4582     if ($md_in_refsect2==1) {
4583         $end_of_section= "$end_of_section</refsect2>";
4584     }
4586     # TODO(ensonic): it would be nice to add id parameters to the refsect2 elements
4588     # Setext-style headers:
4589     #          Header 1
4590     #          ========
4591     #
4592     #          Header 2
4593     #          --------
4594     #
4595     if($text =~ s%^\n(.+)[ \t]*\n=+[ \t]*\n\n%$end_of_section<refsect2><title>$1</title><para>\n%gm) {
4596         $md_in_refsect2=1;
4597     }
4599     # atx-style headers:
4600     #        # Header 1
4601     #        ## Header 2
4602     #        ## Header 2 with closing hashes ##
4603     #        ...
4604     #        ###### Header 6
4605     #
4606     if($text =~ s%^\n\#[ \t]*(.+?)[ \t]*\#\n+%$end_of_section<refsect2><title>$1</title><para>\n%gm) {
4607         $md_in_refsect2=1;
4608     }
4610     # Simple (unnested) lists:
4611     #   Please select:
4612     #   - item 1
4613     #   - item 2 with loooong
4614     #     description
4615     #   - item 3
4616     #
4617     #   New paragraph.
4618     $text.="\n"; # we need a new line to avoid too complicated matching rules below
4619     if ($text =~ s%(?<=\n)-\s+(.+?)(?=(?:\n-\s+)|(?:\n\n)|(?:\n$))%<listitem><para>$1</para></listitem>%gs) {
4620         $text =~ s%(?<!</listitem>)(\n<listitem>)%\n<itemizedlist>$1%g;
4621         $text =~ s%(</listitem>\n)(?!<listitem>)%$1</itemizedlist>\n%g;
4622     }
4623     chomp $text;
4625     # Make Paragraphs on blank lines
4626     $text =~ s%\n{2,}%\n$end_of_para\n<para>\n%g;
4627   }
4629   return $text;
4633 #############################################################################
4634 # LIBRARY FUNCTIONS -        These functions are used in both gtkdoc-mkdb and
4635 #                        gtkdoc-mktmpl and should eventually be moved to a
4636 #                        separate library.
4637 #############################################################################
4639 #############################################################################
4640 # Function    : ReadDeclarationsFile
4641 # Description : This reads in a file containing the function/macro/enum etc.
4642 #                declarations.
4644 #                Note that in some cases there are several declarations with
4645 #                the same name, e.g. for conditional macros. In this case we
4646 #                set a flag in the %DeclarationConditional hash so the
4647 #                declaration is not shown in the docs.
4649 #                If a macro and a function have the same name, e.g. for
4650 #                gtk_object_ref, the function declaration takes precedence.
4652 #                Some opaque structs are just declared with 'typedef struct
4653 #                _name name;' in which case the declaration may be empty.
4654 #                The structure may have been found later in the header, so
4655 #                that overrides the empty declaration.
4657 # Arguments   : $file - the declarations file to read
4658 #                $override - if declarations in this file should override
4659 #                        any current declaration.
4660 #############################################################################
4662 sub ReadDeclarationsFile {
4663     my ($file, $override) = @_;
4665     if ($override == 0) {
4666         %Declarations = ();
4667         %DeclarationTypes = ();
4668         %DeclarationConditional = ();
4669         %DeclarationOutput = ();
4670     }
4672     open (INPUT, $file)
4673         || die "Can't open $file: $!";
4674     my $declaration_type = "";
4675     my $declaration_name;
4676     my $declaration;
4677     my $is_deprecated = 0;
4678     while (<INPUT>) {
4679         if (!$declaration_type) {
4680             if (m/^<([^>]+)>/) {
4681                 $declaration_type = $1;
4682                 $declaration_name = "";
4683                 #print "Found declaration: $declaration_type\n";
4684                 $declaration = "";
4685             }
4686         } else {
4687             if (m%^<NAME>(.*)</NAME>%) {
4688                 $declaration_name = $1;
4689             } elsif (m%^<DEPRECATED/>%) {
4690                 $is_deprecated = 1;
4691             } elsif (m%^</$declaration_type>%) {
4692                 #print "Found end of declaration: $declaration_name\n";
4693                 # Check that the declaration has a name
4694                 if ($declaration_name eq "") {
4695                     print "ERROR: $declaration_type has no name $file:$.\n";
4696                 }
4698                 # If the declaration is an empty typedef struct _XXX XXX
4699                 # set the flag to indicate the struct has a typedef.
4700                 if ($declaration_type eq 'STRUCT'
4701                     && $declaration =~ m/^\s*$/) {
4702                     #print "Struct has typedef: $declaration_name\n";
4703                     $StructHasTypedef{$declaration_name} = 1;
4704                 }
4706                 # Check if the symbol is already defined.
4707                 if (defined ($Declarations{$declaration_name})
4708                     && $override == 0) {
4709                     # Function declarations take precedence.
4710                     if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
4711                         # Ignore it.
4712                     } elsif ($declaration_type eq 'FUNCTION') {
4713                         if ($is_deprecated) {
4714                             $Deprecated{$declaration_name} = "";
4715                         }
4716                         $Declarations{$declaration_name} = $declaration;
4717                         $DeclarationTypes{$declaration_name} = $declaration_type;
4718                     } elsif ($DeclarationTypes{$declaration_name}
4719                               eq $declaration_type) {
4720                         # If the existing declaration is empty, or is just a
4721                         # forward declaration of a struct, override it.
4722                         if ($declaration_type eq 'STRUCT') {
4723                             if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4724                                 if ($is_deprecated) {
4725                                     $Deprecated{$declaration_name} = "";
4726                                 }
4727                                 $Declarations{$declaration_name} = $declaration;
4728                             } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4729                                 # Ignore an empty or forward declaration.
4730                             } else {
4731                                 &LogWarning ($file, $., "Structure $declaration_name has multiple definitions.");
4732                             }
4733                         } else {
4734                             # set flag in %DeclarationConditional hash for
4735                             # multiply defined macros/typedefs.
4736                             $DeclarationConditional{$declaration_name} = 1;
4737                         }
4738                     } else {
4739                         &LogWarning ($file, $., "$declaration_name has multiple definitions.");
4740                     }
4741                 } else {
4742                     if ($is_deprecated) {
4743                         $Deprecated{$declaration_name} = "";
4744                     }
4745                     $Declarations{$declaration_name} = $declaration;
4746                     $DeclarationTypes{$declaration_name} = $declaration_type;
4747                 }
4749                 $declaration_type = "";
4750                 $is_deprecated = 0;
4751             } else {
4752                 $declaration .= $_;
4753             }
4754         }
4755     }
4756     close (INPUT);
4760 #############################################################################
4761 # Function    : ReadSignalsFile
4762 # Description : This reads in an existing file which contains information on
4763 #                all GTK signals. It creates the arrays @SignalNames and
4764 #                @SignalPrototypes containing info on the signals. The first
4765 #                line of the SignalPrototype is the return type of the signal
4766 #                handler. The remaining lines are the parameters passed to it.
4767 #                The last parameter, "gpointer user_data" is always the same
4768 #                so is not included.
4769 # Arguments   : $file - the file containing the signal handler prototype
4770 #                        information.
4771 #############################################################################
4773 sub ReadSignalsFile {
4774     my ($file) = @_;
4776     my $in_signal = 0;
4777     my $signal_object;
4778     my $signal_name;
4779     my $signal_returns;
4780     my $signal_flags;
4781     my $signal_prototype;
4783     # Reset the signal info.
4784     @SignalObjects = ();
4785     @SignalNames = ();
4786     @SignalReturns = ();
4787     @SignalFlags = ();
4788     @SignalPrototypes = ();
4790     if (! -f $file) {
4791         return;
4792     }
4793     if (!open (INPUT, $file)) {
4794         warn "Can't open $file - skipping signals\n";
4795         return;
4796     }
4797     while (<INPUT>) {
4798         if (!$in_signal) {
4799             if (m/^<SIGNAL>/) {
4800                 $in_signal = 1;
4801                 $signal_object = "";
4802                 $signal_name = "";
4803                 $signal_returns = "";
4804                 $signal_prototype = "";
4805             }
4806         } else {
4807             if (m/^<NAME>(.*)<\/NAME>/) {
4808                 $signal_name = $1;
4809                 if ($signal_name =~ m/^(.*)::(.*)$/) {
4810                     $signal_object = $1;
4811                     ($signal_name = $2) =~ s/_/-/g;
4812                     #print "Found signal: $signal_name\n";
4813                 } else {
4814                     &LogWarning ($file, $., "Invalid signal name: $signal_name.");
4815                 }
4816             } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
4817                 $signal_returns = $1;
4818             } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4819                 $signal_flags = $1;
4820             } elsif (m%^</SIGNAL>%) {
4821                 #print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
4822                 push (@SignalObjects, $signal_object);
4823                 push (@SignalNames, $signal_name);
4824                 push (@SignalReturns, $signal_returns);
4825                 push (@SignalFlags, $signal_flags);
4826                 push (@SignalPrototypes, $signal_prototype);
4827                 $in_signal = 0;
4828             } else {
4829                 $signal_prototype .= $_;
4830             }
4831         }
4832     }
4833     close (INPUT);
4837 #############################################################################
4838 # Function    : ReadTemplateFile
4839 # Description : This reads in the manually-edited documentation file
4840 #               corresponding to the file currently being created, so we can
4841 #               insert the documentation at the appropriate places.
4842 #               It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
4843 #               is a hash of arrays.
4844 #               NOTE: This function is duplicated in gtkdoc-mktmpl (but
4845 #               slightly different).
4846 # Arguments   : $docsfile - the template file to read in.
4847 #               $skip_unused_params - 1 if the unused parameters should be
4848 #                 skipped.
4849 #############################################################################
4851 sub ReadTemplateFile {
4852     my ($docsfile, $skip_unused_params) = @_;
4854     my $template = "$docsfile.sgml";
4855     if (! -f $template) {
4856         #print "File doesn't exist: $template\n";
4857         return 0;
4858     }
4860     # start with empty hashes, we merge the source comment for each file
4861     # afterwards
4862     %SymbolDocs = ();
4863     %SymbolTypes = ();
4864     %SymbolParams = ();
4866     my $current_type = "";        # Type of symbol being read.
4867     my $current_symbol = "";        # Name of symbol being read.
4868     my $symbol_doc = "";                # Description of symbol being read.
4869     my @params;                        # Parameter names and descriptions of current
4870                                 #   function/macro/function typedef.
4871     my $current_param = -1;        # Index of parameter currently being read.
4872                                 #   Note that the param array contains pairs
4873                                 #   of param name & description.
4874     my $in_unused_params = 0;        # True if we are reading in the unused params.
4875     my $in_deprecated = 0;
4876     my $in_since = 0;
4877     my $in_stability = 0;
4879     open (DOCS, "$template")
4880         || die "Can't open $template: $!";
4882     @TRACE@("reading template $template");
4884     while (<DOCS>) {
4885         if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
4886             my $type = $1;
4887             my $symbol = $2;
4888             if ($symbol eq "Title"
4889                 || $symbol eq "Short_Description"
4890                 || $symbol eq "Long_Description"
4891                 || $symbol eq "See_Also"
4892                 || $symbol eq "Stability_Level"
4893                 || $symbol eq "Include"
4894                 || $symbol eq "Image") {
4896                 $symbol = $docsfile . ":" . $symbol;
4897             }
4899             #print "Found symbol: $symbol\n";
4900             # Remember file and line for the symbol
4901             $SymbolSourceFile{$symbol} = $template;
4902             $SymbolSourceLine{$symbol} = $.;
4904             # Store previous symbol, but remove any trailing blank lines.
4905             if ($current_symbol ne "") {
4906                 $symbol_doc =~ s/\s+$//;
4907                 $SymbolTypes{$current_symbol} = $current_type;
4908                 $SymbolDocs{$current_symbol} = $symbol_doc;
4910                 # Check that the stability level is valid.
4911                 if ($StabilityLevel{$current_symbol}) {
4912                     $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4913                 }
4915                 if ($current_param >= 0) {
4916                     $SymbolParams{$current_symbol} = [ @params ];
4917                 } else {
4918                     # Delete any existing params in case we are overriding a
4919                     # previously read template.
4920                     delete $SymbolParams{$current_symbol};
4921                 }
4922             }
4923             $current_type = $type;
4924             $current_symbol = $symbol;
4925             $current_param = -1;
4926             $in_unused_params = 0;
4927             $in_deprecated = 0;
4928             $in_since = 0;
4929             $in_stability = 0;
4930             $symbol_doc = "";
4931             @params = ();
4933         } elsif (m/^<!-- # Unused Parameters # -->/) {
4934             #print "DEBUG: Found unused parameters\n";
4935             $in_unused_params = 1;
4936             next;
4938         } elsif ($in_unused_params && $skip_unused_params) {
4939             # When outputting the DocBook we skip unused parameters.
4940             #print "DEBUG: Skipping unused param: $_";
4941             next;
4943         } else {
4944             # Check if param found. Need to handle "..." and "format...".
4945             if (s/^\@([\w\.]+):\040?//) {
4946                 my $param_name = $1;
4947                 my $param_desc = $_;
4948                 # Allow variations of 'Returns'
4949                 if ($param_name =~ m/^[Rr]eturns?$/) {
4950                     $param_name = "Returns";
4951                 }
4952                 # Allow varargs variations
4953                 if ($param_name =~ m/^.*\.\.\.$/) {
4954                     $param_name = "...";
4955                 }
4957                 # strip trailing whitespaces and blank lines
4958                 s/\s+\n$/\n/m;
4959                 s/\n+$/\n/sm;
4960                 @TRACE@("Found param for symbol $current_symbol : '$param_name'= '$_'");
4962                 if ($param_name eq "Deprecated") {
4963                     $in_deprecated = 1;
4964                     $Deprecated{$current_symbol} = $_;
4965                 } elsif ($param_name eq "Since") {
4966                     $in_since = 1;
4967                     chomp;
4968                     $Since{$current_symbol} = $_;
4969                 } elsif ($param_name eq "Stability") {
4970                     $in_stability = 1;
4971                     $StabilityLevel{$current_symbol} = $_;
4972                 } else {
4973                     push (@params, $param_name);
4974                     push (@params, $param_desc);
4975                     $current_param += $PARAM_FIELD_COUNT;
4976                 }
4977             } else {
4978                 # strip trailing whitespaces and blank lines
4979                 s/\s+\n$/\n/m;
4980                 s/\n+$/\n/sm;
4982                 if (!m/^\s+$/) {
4983                     if ($in_deprecated) {
4984                         $Deprecated{$current_symbol} .= $_;
4985                     } elsif ($in_since) {
4986                         &LogWarning ($template, $., "multi-line since docs found");
4987                         #$Since{$current_symbol} .= $_;
4988                     } elsif ($in_stability) {
4989                         $StabilityLevel{$current_symbol} .= $_;
4990                     } elsif ($current_param >= 0) {
4991                         $params[$current_param] .= $_;
4992                     } else {
4993                         $symbol_doc .= $_;
4994                     }
4995                 }
4996             }
4997         }
4998     }
5000     # Remember to finish the current symbol doccs.
5001     if ($current_symbol ne "") {
5003         $symbol_doc =~ s/\s+$//;
5004         $SymbolTypes{$current_symbol} = $current_type;
5005         $SymbolDocs{$current_symbol} = $symbol_doc;
5007         # Check that the stability level is valid.
5008         if ($StabilityLevel{$current_symbol}) {
5009             $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
5010         }
5012         if ($current_param >= 0) {
5013             $SymbolParams{$current_symbol} = [ @params ];
5014         } else {
5015             # Delete any existing params in case we are overriding a
5016             # previously read template.
5017             delete $SymbolParams{$current_symbol};
5018         }
5019     }
5021     close (DOCS);
5022     return 1;
5026 #############################################################################
5027 # Function    : ReadObjectHierarchy
5028 # Description : This reads in the $MODULE-hierarchy.txt file containing all
5029 #                the GtkObject subclasses described in this module (and their
5030 #                ancestors).
5031 #                It places them in the @Objects array, and places their level
5032 #                in the object hierarchy in the @ObjectLevels array, at the
5033 #                same index. GtkObject, the root object, has a level of 1.
5035 #               FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
5036 #               as it goes along, this should be split out into a separate
5037 #               function.
5039 # Arguments   : none
5040 #############################################################################
5042 sub ReadObjectHierarchy {
5043     @Objects = ();
5044     @ObjectLevels = ();
5046     if (! -f $OBJECT_TREE_FILE) {
5047         return;
5048     }
5049     if (!open (INPUT, $OBJECT_TREE_FILE)) {
5050         warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
5051         return;
5052     }
5054     # FIXME: use $OUTPUT_FORMAT
5055     # my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.$OUTPUT_FORMAT";
5056     my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
5057     my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
5059     open (OUTPUT, ">$new_tree_index")
5060         || die "Can't create $new_tree_index: $!";
5062     if ($OUTPUT_FORMAT eq "xml") {
5063         my $tree_header = $doctype_header;
5065         $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
5066         print (OUTPUT "$tree_header");
5067     }
5068     print (OUTPUT "<screen>\n");
5070     # Only emit objects if they are supposed to be documented, or if
5071     # they have documented children. To implement this, we maintain a
5072     # stack of pending objects which will be emitted if a documented
5073     # child turns up.
5074     my @pending_objects = ();
5075     my @pending_levels = ();
5076     my $root;
5077     while (<INPUT>) {
5078         if (m/\S+/) {
5079             my $object = $&;
5080             my $level = (length($`)) / 2 + 1;
5081             my $xref = "";
5083             if ($level == 1) {
5084                 $root = $object;
5085             }
5087             while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
5088                 my $pobject = pop(@pending_objects);
5089                 my $plevel = pop(@pending_levels);
5090             }
5092                push (@pending_objects, $object);
5093             push (@pending_levels, $level);
5095             if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5096                    while ($#pending_levels >= 0) {
5097                     $object = shift @pending_objects;
5098                     $level = shift @pending_levels;
5099                        $xref = &MakeXRef ($object);
5101                      print (OUTPUT ' ' x ($level * 4), "$xref\n");
5102                     push (@Objects, $object);
5103                     push (@ObjectLevels, $level);
5104                     $ObjectRoots{$object} = $root;
5105                 }
5106             }
5107             #else {
5108             #    LogWarning ($OBJECT_TREE_FILE, $., "unknown type $object");
5109             #}
5110         }
5111     }
5112     print (OUTPUT "</screen>\n");
5114     close (INPUT);
5115     close (OUTPUT);
5117     &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
5119     &OutputObjectList;
5122 #############################################################################
5123 # Function    : ReadInterfaces
5124 # Description : This reads in the $MODULE.interfaces file.
5126 # Arguments   : none
5127 #############################################################################
5129 sub ReadInterfaces {
5130     %Interfaces = ();
5132     if (! -f $INTERFACES_FILE) {
5133         return;
5134     }
5135     if (!open (INPUT, $INTERFACES_FILE)) {
5136         warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
5137         return;
5138     }
5140     while (<INPUT>) {
5141        chomp;
5142        my ($object, @ifaces) = split;
5143        if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5144            my @knownIfaces = ();
5146            # filter out private interfaces, but leave foreign interfaces
5147            foreach my $iface (@ifaces) {
5148                if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
5149                    push (@knownIfaces, $iface);
5150                }
5151              }
5153            $Interfaces{$object} = join(' ', @knownIfaces);
5154        }
5155     }
5156     close (INPUT);
5159 #############################################################################
5160 # Function    : ReadPrerequisites
5161 # Description : This reads in the $MODULE.prerequisites file.
5163 # Arguments   : none
5164 #############################################################################
5166 sub ReadPrerequisites {
5167     %Prerequisites = ();
5169     if (! -f $PREREQUISITES_FILE) {
5170         return;
5171     }
5172     if (!open (INPUT, $PREREQUISITES_FILE)) {
5173         warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
5174         return;
5175     }
5177     while (<INPUT>) {
5178        chomp;
5179        my ($iface, @prereqs) = split;
5180        if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
5181            my @knownPrereqs = ();
5183            # filter out private prerequisites, but leave foreign prerequisites
5184            foreach my $prereq (@prereqs) {
5185                if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
5186                   push (@knownPrereqs, $prereq);
5187                }
5188            }
5190            $Prerequisites{$iface} = join(' ', @knownPrereqs);
5191        }
5192     }
5193     close (INPUT);
5196 #############################################################################
5197 # Function    : ReadArgsFile
5198 # Description : This reads in an existing file which contains information on
5199 #                all GTK args. It creates the arrays @ArgObjects, @ArgNames,
5200 #                @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
5201 #               on the args.
5202 # Arguments   : $file - the file containing the arg information.
5203 #############################################################################
5205 sub ReadArgsFile {
5206     my ($file) = @_;
5208     my $in_arg = 0;
5209     my $arg_object;
5210     my $arg_name;
5211     my $arg_type;
5212     my $arg_flags;
5213     my $arg_nick;
5214     my $arg_blurb;
5215     my $arg_default;
5216     my $arg_range;
5218     # Reset the args info.
5219     @ArgObjects = ();
5220     @ArgNames = ();
5221     @ArgTypes = ();
5222     @ArgFlags = ();
5223     @ArgNicks = ();
5224     @ArgBlurbs = ();
5225     @ArgDefaults = ();
5226     @ArgRanges = ();
5228     if (! -f $file) {
5229         return;
5230     }
5231     if (!open (INPUT, $file)) {
5232         warn "Can't open $file - skipping args\n";
5233         return;
5234     }
5235     while (<INPUT>) {
5236         if (!$in_arg) {
5237             if (m/^<ARG>/) {
5238                 $in_arg = 1;
5239                 $arg_object = "";
5240                 $arg_name = "";
5241                 $arg_type = "";
5242                 $arg_flags = "";
5243                 $arg_nick = "";
5244                 $arg_blurb = "";
5245                 $arg_default = "";
5246                 $arg_range = "";
5247             }
5248         } else {
5249             if (m/^<NAME>(.*)<\/NAME>/) {
5250                 $arg_name = $1;
5251                 if ($arg_name =~ m/^(.*)::(.*)$/) {
5252                     $arg_object = $1;
5253                     ($arg_name = $2) =~ s/_/-/g;
5254                     #print "Found arg: $arg_name\n";
5255                 } else {
5256                     &LogWarning ($file, $., "Invalid argument name: $arg_name");
5257                 }
5258             } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
5259                 $arg_type = $1;
5260             } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
5261                 $arg_range = $1;
5262             } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
5263                 $arg_flags = $1;
5264             } elsif (m/^<NICK>(.*)<\/NICK>/) {
5265                 $arg_nick = $1;
5266             } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
5267                 $arg_blurb = $1;
5268                 if ($arg_blurb eq "(null)") {
5269                   $arg_blurb = "";
5270                   &LogWarning ($file, $., "Property ${arg_object}:${arg_name} has no documentation.");
5271                 }
5272             } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
5273                 $arg_default = $1;
5274             } elsif (m%^</ARG>%) {
5275                 #print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
5276                 push (@ArgObjects, $arg_object);
5277                 push (@ArgNames, $arg_name);
5278                 push (@ArgTypes, $arg_type);
5279                 push (@ArgRanges, $arg_range);
5280                 push (@ArgFlags, $arg_flags);
5281                 push (@ArgNicks, $arg_nick);
5282                 push (@ArgBlurbs, $arg_blurb);
5283                 push (@ArgDefaults, $arg_default);
5284                 $in_arg = 0;
5285             }
5286         }
5287     }
5288     close (INPUT);
5292 #############################################################################
5293 # Function    : CheckIsObject
5294 # Description : Returns 1 if the given name is a GObject or a subclass.
5295 #                It uses the global @Objects array.
5296 #                Note that the @Objects array only contains classes in the
5297 #                current module and their ancestors - not all GObject classes.
5298 # Arguments   : $name - the name to check.
5299 #############################################################################
5301 sub CheckIsObject {
5302     my ($name) = @_;
5303     my $root = $ObjectRoots{$name};
5304     # Let GBoxed pass as an object here to get -struct appended to the id
5305     # and prevent conflicts with sections.
5306     return defined($root) and $root ne 'GEnum' and $root ne 'GFlags';
5310 #############################################################################
5311 # Function    : MakeReturnField
5312 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
5313 # Arguments   : $str - the string to pad.
5314 #############################################################################
5316 sub MakeReturnField {
5317     my ($str) = @_;
5319     return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));
5322 #############################################################################
5323 # Function    : GetSymbolSourceFile
5324 # Description : Get the filename where the symbol docs where taken from.
5325 # Arguments   : $symbol - the symbol name
5326 #############################################################################
5328 sub GetSymbolSourceFile {
5329     my ($symbol) = @_;
5331     if (defined($SourceSymbolSourceFile{$symbol})) {
5332         return $SourceSymbolSourceFile{$symbol};
5333     } elsif (defined($SymbolSourceFile{$symbol})) {
5334         return $SymbolSourceFile{$symbol};
5335     } else {
5336         return "";
5337     }
5340 #############################################################################
5341 # Function    : GetSymbolSourceLine
5342 # Description : Get the file line where the symbol docs where taken from.
5343 # Arguments   : $symbol - the symbol name
5344 #############################################################################
5346 sub GetSymbolSourceLine {
5347     my ($symbol) = @_;
5349     if (defined($SourceSymbolSourceLine{$symbol})) {
5350         return $SourceSymbolSourceLine{$symbol};
5351     } elsif (defined($SymbolSourceLine{$symbol})) {
5352         return $SymbolSourceLine{$symbol};
5353     } else {
5354         return 0;
5355     }