Updated French translation: fixed some wrong XML tags
[gtk-doc.git] / gtkdoc-mkdb.in
blob2dafbeadcc573f116c901bafc083b8eb4a46eedb
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 # http://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 full' => "Free data after the code is done.",
321     'transfer none' => "Don't free data after the code is done.",
322     'scope call' => "The callback is valid only during the call to the method.",
323     'scope async' => "The callback is valid until first called.",
324     'scope notified' => "The callback is valid until the GDestroyNotify argument is called.",
325     'skip' => "Exposed in C code, not necessarily available in other languages.",
326     'type' => "Override the parsed C type with given type."
329 # Create the root DocBook output directory if it doens't exist.
330 if (! -e $SGML_OUTPUT_DIR) {
331     mkdir ("$SGML_OUTPUT_DIR", 0777)
332         || die "Can't create directory: $SGML_OUTPUT_DIR";
335 # Function and other declaration output settings.
336 my $RETURN_TYPE_FIELD_WIDTH = 20;
337 my $SYMBOL_FIELD_WIDTH = 36;
338 my $SIGNAL_FIELD_WIDTH = 16;
339 my $PARAM_FIELD_COUNT = 2;
341 &ReadKnownSymbols ("$ROOT_DIR/$MODULE-sections.txt");
342 &ReadSignalsFile ($SIGNALS_FILE);
343 &ReadArgsFile ($ARGS_FILE);
344 &ReadObjectHierarchy;
345 &ReadInterfaces;
346 &ReadPrerequisites;
348 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-decl.txt", 0);
349 if (-f "$ROOT_DIR/$MODULE-overrides.txt") {
350     &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-overrides.txt", 1);
353 for my $dir (@SOURCE_DIRS) {
354     &ReadSourceDocumentation ($dir);
357 my $changed = &OutputSGML ("$ROOT_DIR/$MODULE-sections.txt");
359 # If any of the DocBook SGML files have changed, update the timestamp file (so
360 # it can be used for Makefile dependencies).
361 if ($changed || ! -e "$ROOT_DIR/sgml.stamp") {
363     # try to detect the common prefix
364     # GtkWidget, GTK_WIDGET, gtk_widget -> gtk
365     if ($NAME_SPACE eq "") {
366         $NAME_SPACE="";
367         my $pos=0;
368         my $ratio=0.0;
369         do {
370             my %prefix;
371             my $letter="";
372             foreach my $symbol (keys(%IndexEntriesFull)) {
373                 if(($NAME_SPACE eq "") || $symbol =~ /^$NAME_SPACE/i) {
374                     if (length($symbol)>$pos) {
375                         $letter=substr($symbol,$pos,1);
376                         # stop prefix scanning
377                         if ($letter eq "_") {
378                             # stop on "_"
379                             last;
380                         }
381                         # Should we also stop on a uppercase char, if last was lowercase
382                         #   GtkWidget, if we have the 'W' and had the 't' before
383                         # or should we count upper and lowercase, and stop one 2nd uppercase, if we already had a lowercase
384                         #   GtkWidget, the 'W' would be the 2nd uppercase and with 't','k' we had lowercase chars before
385                         # need to recound each time as this is per symbol
386                         $prefix{uc($letter)}++;
387                     }
388                 }
389             }
390             if ($letter ne "" && $letter ne "_") {
391                 my $maxletter="";
392                 my $maxsymbols=0;
393                 foreach $letter (keys(%prefix)) {
394                     #print "$letter: $prefix{$letter}.\n";
395                     if ($prefix{$letter}>$maxsymbols) {
396                         $maxletter=$letter;
397                         $maxsymbols=$prefix{$letter};
398                     }
399                 }
400                 $ratio = scalar(keys(%IndexEntriesFull)) / $prefix{$maxletter};
401                 #print "most symbols start with $maxletter, that is ". (100 * $ratio) ." %\n";
402                 if ($ratio > 0.9) {
403                     # do another round
404                     $NAME_SPACE .= $maxletter;
405                 }
406                 $pos++;
407             }
408             else {
409                 $ratio=0.0;
410             }
411         } while ($ratio > 0.9);
412         #print "most symbols start with $NAME_SPACE\n";
413     }
415     &OutputIndexFull;
416     &OutputDeprecatedIndex;
417     &OutputSinceIndexes;
418     &OutputAnnotationGlossary;
420     open (TIMESTAMP, ">$ROOT_DIR/sgml.stamp")
421         || die "Can't create $ROOT_DIR/sgml.stamp: $!";
422     print (TIMESTAMP "timestamp");
423     close (TIMESTAMP);
426 #############################################################################
427 # Function    : OutputObjectList
428 # Description : This outputs the alphabetical list of objects, in a columned
429 #                table.
430 #               FIXME: Currently this also outputs ancestor objects
431 #                which may not actually be in this module.
432 # Arguments   : none
433 #############################################################################
435 sub OutputObjectList {
436     my $cols = 3;
438     # FIXME: use $OUTPUT_FORMAT
439     # my $old_object_index = "$SGML_OUTPUT_DIR/object_index.$OUTPUT_FORMAT";
440     my $old_object_index = "$SGML_OUTPUT_DIR/object_index.sgml";
441     my $new_object_index = "$SGML_OUTPUT_DIR/object_index.new";
443     open (OUTPUT, ">$new_object_index")
444         || die "Can't create $new_object_index: $!";
446     if ($OUTPUT_FORMAT eq "xml") {
447         my $header = $doctype_header;
449         $header =~ s/<!DOCTYPE \w+/<!DOCTYPE informaltable/;
450         print (OUTPUT "$header");
451     }
453     print (OUTPUT <<EOF);
454 <informaltable pgwide="1" frame="none">
455 <tgroup cols="$cols">
456 <colspec colwidth="1*"${empty_element_end}
457 <colspec colwidth="1*"${empty_element_end}
458 <colspec colwidth="1*"${empty_element_end}
459 <tbody>
462     my $count = 0;
463     my $object;
464     foreach $object (sort (@Objects)) {
465         my $xref = &MakeXRef ($object);
466         if ($count % $cols == 0) { print (OUTPUT "<row>\n"); }
467         print (OUTPUT "<entry>$xref</entry>\n");
468         if ($count % $cols == ($cols - 1)) { print (OUTPUT "</row>\n"); }
469         $count++;
470     }
471     if ($count == 0) {
472         # emit an empty row, since empty tables are invalid
473         print (OUTPUT "<row><entry> </entry></row>\n");
474     }
475     else {
476         if ($count % $cols > 0) {
477             print (OUTPUT "</row>\n");
478         }
479     }
481     print (OUTPUT <<EOF);
482 </tbody></tgroup></informaltable>
484     close (OUTPUT);
486     &UpdateFileIfChanged ($old_object_index, $new_object_index, 0);
490 #############################################################################
491 # Function    : OutputSGML
492 # Description : This collects the output for each section of the docs, and
493 #                outputs each file when the end of the section is found.
494 # Arguments   : $file - the $MODULE-sections.txt file which contains all of
495 #                the functions/macros/structs etc. being documented, organised
496 #                into sections and subsections.
497 #############################################################################
499 sub OutputSGML {
500     my ($file) = @_;
502     #print "Reading: $file\n";
503     open (INPUT, $file)
504         || die "Can't open $file: $!";
505     my $filename = "";
506     my $book_top = "";
507     my $book_bottom = "";
508     my $includes = (defined $DEFAULT_INCLUDES) ? $DEFAULT_INCLUDES : "";
509     my $section_includes = "";
510     my $in_section = 0;
511     my $title = "";
512     my $section_id = "";
513     my $subsection = "";
514     my $synopsis;
515     my $details;
516     my $num_symbols;
517     my $changed = 0;
518     my $signals_synop = "";
519     my $signals_desc = "";
520     my $args_synop = "";
521     my $child_args_synop = "";
522     my $style_args_synop = "";
523     my $args_desc = "";
524     my $child_args_desc = "";
525     my $style_args_desc = "";
526     my $hierarchy = "";
527     my $interfaces = "";
528     my $implementations = "";
529     my $prerequisites = "";
530     my $derived = "";
531     my @file_objects = ();
532     my %templates = ();
533     my %symbol_def_line = ();
535     # merge the source docs, in case there are no templates
536     &MergeSourceDocumentation;
538     while (<INPUT>) {
539         if (m/^#/) {
540             next;
542         } elsif (m/^<SECTION>/) {
543             $synopsis = "";
544             $details = "";
545             $num_symbols = 0;
546             $in_section = 1;
547             @file_objects = ();
548             %symbol_def_line = ();
550         } elsif (m/^<SUBSECTION\s*(.*)>/i) {
551             $synopsis .= "\n";
552             $subsection = $1;
554         } elsif (m/^<SUBSECTION>/) {
556         } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
557             $title = $1;
558             #print "Section: $title\n";
560             # We don't want warnings if object & class structs aren't used.
561             $DeclarationOutput{$title} = 1;
562             $DeclarationOutput{"${title}Class"} = 1;
563             $DeclarationOutput{"${title}Iface"} = 1;
564             $DeclarationOutput{"${title}Interface"} = 1;
566         } elsif (m/^<FILE>(.*)<\/FILE>/) {
567             $filename = $1;
568             if (! defined $templates{$filename}) {
569                if (&ReadTemplateFile ("$TMPL_DIR/$filename", 1)) {
570                    &MergeSourceDocumentation;
571                    $templates{$filename}=$.;
572                }
573             } else {
574                 &LogWarning ($file, $., "Double <FILE>$filename</FILE> entry. ".
575                     "Previous occurrence on line ".$templates{$filename}.".");
576             }
577             if (($title eq "") and (defined $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"})) {
578                 $title = $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"};
579                  # Remove trailing blanks
580                 $title =~ s/\s+$//;
581            }
583         } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
584             if ($in_section) {
585                 $section_includes = $1;
586             } else {
587                 if (defined $DEFAULT_INCLUDES) {
588                     &LogWarning ($file, $., "Default <INCLUDE> being overridden by command line option.");
589                 }
590                 else {
591                     $includes = $1;
592                 }
593             }
595         } elsif (m/^<\/SECTION>/) {
596             #print "End of section: $title\n";
597             if ($num_symbols > 0) {
598                 # collect documents
599                 if ($OUTPUT_FORMAT eq "xml") {
600                     $book_bottom .= "    <xi:include href=\"xml/$filename.xml\"/>\n";
601                 } else {
602                     $book_top.="<!ENTITY $section_id SYSTEM \"sgml/$filename.sgml\">\n";
603                     $book_bottom .= "    &$section_id;\n";
604                 }
606                 if (defined ($SourceSymbolDocs{"$TMPL_DIR/$filename:Include"})) {
607                     if ($section_includes) {
608                         &LogWarning ($file, $., "Section <INCLUDE> being overridden by inline comments.");
609                     }
610                     $section_includes = $SourceSymbolDocs{"$TMPL_DIR/$filename:Include"};
611                 }
612                 if ($section_includes eq "") {
613                     $section_includes = $includes;
614                 }
616                  $signals_synop =~ s/^\n*//g;
617                  $signals_synop =~ s/\n+$/\n/g;
618                 if ($signals_synop ne '') {
619                     $signals_synop = <<EOF;
620 <refsect1 id="$section_id.signals" role="signal_proto">
621 <title role="signal_proto.title">Signals</title>
622 <synopsis>
623 ${signals_synop}</synopsis>
624 </refsect1>
626                      $signals_desc =~ s/^\n*//g;
627                      $signals_desc =~ s/\n+$/\n/g;
628                      $signals_desc =~ s/(\s|\n)+$//ms;
629                     $signals_desc  = <<EOF;
630 <refsect1 id="$section_id.signal-details" role="signals">
631 <title role="signals.title">Signal Details</title>
632 $signals_desc
633 </refsect1>
635                 }
637                  $args_synop =~ s/^\n*//g;
638                  $args_synop =~ s/\n+$/\n/g;
639                 if ($args_synop ne '') {
640                     $args_synop = <<EOF;
641 <refsect1 id="$section_id.properties" role="properties">
642 <title role="properties.title">Properties</title>
643 <synopsis>
644 ${args_synop}</synopsis>
645 </refsect1>
647                      $args_desc =~ s/^\n*//g;
648                      $args_desc =~ s/\n+$/\n/g;
649                      $args_desc =~ s/(\s|\n)+$//ms;
650                     $args_desc  = <<EOF;
651 <refsect1 id="$section_id.property-details" role="property_details">
652 <title role="property_details.title">Property Details</title>
653 $args_desc
654 </refsect1>
656                 }
658                  $child_args_synop =~ s/^\n*//g;
659                  $child_args_synop =~ s/\n+$/\n/g;
660                 if ($child_args_synop ne '') {
661                     $args_synop .= <<EOF;
662 <refsect1 id="$section_id.child-properties" role="child_properties">
663 <title role="child_properties.title">Child Properties</title>
664 <synopsis>
665 ${child_args_synop}</synopsis>
666 </refsect1>
668                      $child_args_desc =~ s/^\n*//g;
669                      $child_args_desc =~ s/\n+$/\n/g;
670                      $child_args_desc =~ s/(\s|\n)+$//ms;
671                     $args_desc .= <<EOF;
672 <refsect1 id="$section_id.child-property-details" role="child_property_details">
673 <title role="child_property_details.title">Child Property Details</title>
674 $child_args_desc
675 </refsect1>
677                 }
679                  $style_args_synop =~ s/^\n*//g;
680                  $style_args_synop =~ s/\n+$/\n/g;
681                 if ($style_args_synop ne '') {
682                     $args_synop .= <<EOF;
683 <refsect1 id="$section_id.style-properties" role="style_properties">
684 <title role="style_properties.title">Style Properties</title>
685 <synopsis>
686 ${style_args_synop}</synopsis>
687 </refsect1>
689                      $style_args_desc =~ s/^\n*//g;
690                      $style_args_desc =~ s/\n+$/\n/g;
691                      $style_args_desc =~ s/(\s|\n)+$//ms;
692                     $args_desc .= <<EOF;
693 <refsect1 id="$section_id.style-property-details" role="style_properties_details">
694 <title role="style_properties_details.title">Style Property Details</title>
695 $style_args_desc
696 </refsect1>
698                 }
700                  $hierarchy =~ s/^\n*//g;
701                  $hierarchy =~ s/\n+$/\n/g;
702                  $hierarchy =~ s/(\s|\n)+$//ms;
703                 if ($hierarchy ne "") {
704                     $hierarchy = <<EOF;
705 <refsect1 id="$section_id.object-hierarchy" role="object_hierarchy">
706 <title role="object_hierarchy.title">Object Hierarchy</title>
707 $hierarchy
708 </refsect1>
710                 }
712                  $interfaces =~ s/^\n*//g;
713                  $interfaces =~ s/\n+$/\n/g;
714                  $interfaces =~ s/(\s|\n)+$//ms;
715                 if ($interfaces ne "") {
716                     $interfaces = <<EOF;
717 <refsect1 id="$section_id.implemented-interfaces" role="impl_interfaces">
718 <title role="impl_interfaces.title">Implemented Interfaces</title>
719 $interfaces
720 </refsect1>
722                 }
724                  $implementations =~ s/^\n*//g;
725                  $implementations =~ s/\n+$/\n/g;
726                  $implementations =~ s/(\s|\n)+$//ms;
727                 if ($implementations ne "") {
728                     $implementations = <<EOF;
729 <refsect1 id="$section_id.implementations" role="implementations">
730 <title role="implementations.title">Known Implementations</title>
731 $implementations
732 </refsect1>
734                 }
736                  $prerequisites =~ s/^\n*//g;
737                  $prerequisites =~ s/\n+$/\n/g;
738                  $prerequisites =~ s/(\s|\n)+$//ms;
739                 if ($prerequisites ne "") {
740                     $prerequisites = <<EOF;
741 <refsect1 id="$section_id.prerequisites" role="prerequisites">
742 <title role="prerequisites.title">Prerequisites</title>
743 $prerequisites
744 </refsect1>
746                 }
748                  $derived =~ s/^\n*//g;
749                  $derived =~ s/\n+$/\n/g;
750                  $derived =~ s/(\s|\n)+$//ms;
751                 if ($derived ne "") {
752                     $derived = <<EOF;
753 <refsect1 id="$section_id.derived-interfaces" role="derived_interfaces">
754 <title role="derived_interfaces.title">Known Derived Interfaces</title>
755 $derived
756 </refsect1>
758                 }
760                 $synopsis =~ s/^\n*//g;
761                 $synopsis =~ s/\n+$/\n/g;
762                 my $file_changed = &OutputSGMLFile ($filename, $title, $section_id,
763                                                     $section_includes,
764                                                     \$synopsis, \$details,
765                                                     \$signals_synop, \$signals_desc,
766                                                     \$args_synop, \$args_desc,
767                                                     \$hierarchy, \$interfaces,
768                                                     \$implementations,
769                                                     \$prerequisites, \$derived,
770                                                     \@file_objects);
771                 if ($file_changed) {
772                     $changed = 1;
773                 }
774             }
775             $title = "";
776             $section_id = "";
777             $subsection = "";
778             $in_section = 0;
779             $section_includes = "";
780             $signals_synop = "";
781             $signals_desc = "";
782             $args_synop = "";
783             $child_args_synop = "";
784             $style_args_synop = "";
785             $args_desc = "";
786             $child_args_desc = "";
787             $style_args_desc = "";
788             $hierarchy = "";
789              $interfaces = "";
790              $implementations = "";
791             $prerequisites = "";
792             $derived = "";
794         } elsif (m/^(\S+)/) {
795             my $symbol = $1;
796             #print "  Symbol: $symbol\n";
798             # check for duplicate entries
799             if (! defined $symbol_def_line{$symbol}) {
800                 my $declaration = $Declarations{$symbol};
801                 if (defined ($declaration)) {
802                     # We don't want standard macros/functions of GObjects,
803                     # or private declarations.
804                     if ($subsection ne "Standard" && $subsection ne "Private") {
805                         if (&CheckIsObject ($symbol)) {
806                             push @file_objects, $symbol;
807                         }
808                         my ($synop, $desc) = &OutputDeclaration ($symbol,
809                                                                  $declaration);
810                         my ($sig_synop, $sig_desc) = &GetSignals ($symbol);
811                         my ($arg_synop, $child_arg_synop, $style_arg_synop,
812                             $arg_desc, $child_arg_desc, $style_arg_desc) = &GetArgs ($symbol);
813                         my $hier = &GetHierarchy ($symbol);
814                         my $ifaces = &GetInterfaces ($symbol);
815                         my $impls = &GetImplementations ($symbol);
816                         my $prereqs = &GetPrerequisites ($symbol);
817                         my $der = &GetDerived ($symbol);
818                         $synopsis .= $synop;
819                         $details .= $desc;
820                         $signals_synop .= $sig_synop;
821                         $signals_desc .= $sig_desc;
822                         $args_synop .= $arg_synop;
823                         $child_args_synop .= $child_arg_synop;
824                         $style_args_synop .= $style_arg_synop;
825                         $args_desc .= $arg_desc;
826                         $child_args_desc .= $child_arg_desc;
827                         $style_args_desc .= $style_arg_desc;
828                         $hierarchy .= $hier;
829                         $interfaces .= $ifaces;
830                         $implementations .= $impls;
831                         $prerequisites .= $prereqs;
832                         $derived .= $der;
833                     }
835                     # Note that the declaration has been output.
836                     $DeclarationOutput{$symbol} = 1;
837                 } elsif ($subsection ne "Standard" && $subsection ne "Private") {
838                     $UndeclaredSymbols{$symbol} = 1;
839                     &LogWarning ($file, $., "No declaration found for $symbol.");
840                 }
841                 $num_symbols++;
842                 $symbol_def_line{$symbol}=$.;
844                 if ($section_id eq "") {
845                     if($title eq "" && $filename eq "") {
846                         &LogWarning ($file, $., "Section has no title and no file.");
847                     }
848                     # FIXME: one of those would be enough
849                     # filename should be an internal detail for gtk-doc
850                     if ($title eq "") {
851                         $title = $filename;
852                     } elsif ($filename eq "") {
853                         $filename = $title;
854                     }
855                     $filename =~ s/\s/_/g;
857                     $section_id = $SourceSymbolDocs{"$TMPL_DIR/$filename:Section_Id"};
858                     if (defined ($section_id) && $section_id !~ m/^\s*$/) {
859                         # Remove trailing blanks and use as is
860                         $section_id =~ s/\s+$//;
861                     } elsif (&CheckIsObject ($title)) {
862                         # GObjects use their class name as the ID.
863                         $section_id = &CreateValidSGMLID ($title);
864                     } else {
865                         $section_id = &CreateValidSGMLID ("$MODULE-$title");
866                     }
867                 }
868                 $SymbolSection{$symbol}=$title;
869                 $SymbolSectionId{$symbol}=$section_id;
870             }
871             else {
872                 &LogWarning ($file, $., "Double symbol entry for $symbol. ".
873                     "Previous occurrence on line ".$symbol_def_line{$symbol}.".");
874             }
875         }
876     }
877     close (INPUT);
879     &OutputMissingDocumentation;
880     &OutputUndeclaredSymbols;
881     &OutputUnusedSymbols;
883     if ($OUTPUT_ALL_SYMBOLS) {
884         &OutputAllSymbols;
885     }
886     if ($OUTPUT_SYMBOLS_WITHOUT_SINCE) {
887         &OutputSymbolsWithoutSince;
888     }
890     for $filename (split (' ', $EXPAND_CONTENT_FILES)) {
891         my $file_changed = &OutputExtraFile ($filename);
892         if ($file_changed) {
893             $changed = 1;
894         }
895     }
897     &OutputBook ($book_top, $book_bottom);
899     return $changed;
902 #############################################################################
903 # Function    : OutputIndex
904 # Description : This writes an indexlist that can be included into the main-
905 #               document into an <index> tag.
906 #############################################################################
908 sub OutputIndex {
909     my ($basename, $apiindexref ) = @_;
910     my %apiindex = %{$apiindexref};
911     my $old_index = "$SGML_OUTPUT_DIR/$basename.xml";
912     my $new_index = "$SGML_OUTPUT_DIR/$basename.new";
913     my $lastletter = " ";
914     my $divopen = 0;
915     my $symbol;
916     my $short_symbol;
918     open (OUTPUT, ">$new_index")
919         || die "Can't create $new_index";
921     my $header = $doctype_header;
922     $header =~ s/<!DOCTYPE \w+/<!DOCTYPE indexdiv/;
924     print (OUTPUT "$header<indexdiv>\n");
926     #print "generate $basename index (".%apiindex." entries)\n";
928     # do a case insensitive sort while chopping off the prefix
929     foreach my $hash (
930         sort { $$a{criteria} cmp $$b{criteria} }
931         map { my $x = uc($_); $x =~ s/^$NAME_SPACE\_?(.*)/$1/i; { criteria => $x, original => $_, short => $1 } }
932         keys %apiindex) {
934         $symbol = $$hash{original};
935         if (defined($$hash{short})) {
936             $short_symbol = $$hash{short};
937         } else {
938             $short_symbol = $symbol;
939         }
941         # generate a short symbol description
942         my $symbol_desc = "";
943         my $symbol_section = "";
944         my $symbol_section_id = "";
945         my $symbol_type = "";
946         if (defined($DeclarationTypes{$symbol})) {
947           $symbol_type = lc($DeclarationTypes{$symbol});
948         }
949         if ($symbol_type eq "") {
950             #print "trying symbol $symbol\n";
951             if ($symbol =~ m/(.*)::(.*)/) {
952                 my $oname = $1;
953                 my $osym = $2;
954                 my $i;
955                 #print "  trying object signal ${oname}:$osym in ".$#SignalNames." signals\n";
956                 for ($i = 0; $i <= $#SignalNames; $i++) {
957                     if ($SignalNames[$i] eq $osym) {
958                         $symbol_type = "object signal";
959                         if (defined($SymbolSection{$oname})) {
960                            $symbol_section = $SymbolSection{$oname};
961                            $symbol_section_id = $SymbolSectionId{$oname};
962                         }
963                         last;
964                     }
965                 }
966             } elsif ($symbol =~ m/(.*):(.*)/) {
967                 my $oname = $1;
968                 my $osym = $2;
969                 my $i;
970                 #print "  trying object property ${oname}::$osym in ".$#ArgNames." properties\n";
971                 for ($i = 0; $i <= $#ArgNames; $i++) {
972                     #print "    ".$ArgNames[$i]."\n";
973                     if ($ArgNames[$i] eq $osym) {
974                         $symbol_type = "object property";
975                         if (defined($SymbolSection{$oname})) {
976                            $symbol_section = $SymbolSection{$oname};
977                            $symbol_section_id = $SymbolSectionId{$oname};
978                         }
979                         last;
980                     }
981                 }
982             }
983         } else {
984            if (defined($SymbolSection{$symbol})) {
985                $symbol_section = $SymbolSection{$symbol};
986                $symbol_section_id = $SymbolSectionId{$symbol};
987            }
988         }
989         if ($symbol_type ne "") {
990            $symbol_desc=", $symbol_type";
991            if ($symbol_section ne "") {
992                $symbol_desc.=" in <link linkend=\"$symbol_section_id\">$symbol_section</link>";
993                #$symbol_desc.=" in ". &ExpandAbbreviations($symbol, "#$symbol_section");
994            }
995         }
997         my $curletter = uc(substr($short_symbol,0,1));
998         my $id = $apiindex{$symbol};
1000         #print "  add symbol $symbol with $id to index in section $curletter\n";
1002         if ($curletter ne $lastletter) {
1003             $lastletter = $curletter;
1005             if ($divopen == 1) {
1006                 print (OUTPUT "</indexdiv>\n");
1007             }
1008             print (OUTPUT "<indexdiv><title>$curletter</title>\n");
1009             $divopen = 1;
1010         }
1012         print (OUTPUT <<EOF);
1013 <indexentry><primaryie linkends="$id"><link linkend="$id">$symbol</link>$symbol_desc</primaryie></indexentry>
1015     }
1017     if ($divopen == 1) {
1018         print (OUTPUT "</indexdiv>\n");
1019     }
1020     print (OUTPUT "</indexdiv>\n");
1021     close (OUTPUT);
1023     &UpdateFileIfChanged ($old_index, $new_index, 0);
1027 #############################################################################
1028 # Function    : OutputIndexFull
1029 # Description : This writes the full api indexlist that can be included into the
1030 #               main document into an <index> tag.
1031 #############################################################################
1033 sub OutputIndexFull {
1034     &OutputIndex ("api-index-full", \%IndexEntriesFull);
1038 #############################################################################
1039 # Function    : OutputDeprecatedIndex
1040 # Description : This writes the deprecated api indexlist that can be included
1041 #               into the main document into an <index> tag.
1042 #############################################################################
1044 sub OutputDeprecatedIndex {
1045     &OutputIndex ("api-index-deprecated", \%IndexEntriesDeprecated);
1049 #############################################################################
1050 # Function    : OutputSinceIndexes
1051 # Description : This writes the 'since' api indexlists that can be included into
1052 #               the main document into an <index> tag.
1053 #############################################################################
1055 sub OutputSinceIndexes {
1056     my @sinces = keys %{{ map { $_ => 1 } values %Since }};
1058     foreach my $version (@sinces) {
1059         #print "Since : [$version]\n";
1060         # TODO make filtered hash
1061         #my %index = grep { $Since{$_} eq $version } %IndexEntriesSince;
1062         my %index = map { $_ => $IndexEntriesSince{$_} } grep { $Since{$_} eq $version } keys %IndexEntriesSince;
1064         &OutputIndex ("api-index-$version", \%index);
1065     }
1068 #############################################################################
1069 # Function    : OutputAnnotationGlossary
1070 # Description : This writes a glossary of the used annotation terms into a
1071 #               separate glossary file that can be included into the main
1072 #               document.
1073 #############################################################################
1075 sub OutputAnnotationGlossary {
1076     my $old_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.xml";
1077     my $new_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.new";
1078     my $lastletter = " ";
1079     my $divopen = 0;
1081     # if there are no annotations used return
1082     return if (! keys(%AnnotationsUsed));
1084     # add acronyms that are referenced from acronym text
1085 rerun:
1086     foreach my $annotation (keys(%AnnotationsUsed)) {
1087         if(defined($AnnotationDefinition{$annotation})) {
1088             if($AnnotationDefinition{$annotation} =~ m/<acronym>([\w ]+)<\/acronym>/) {
1089                 if (!exists($AnnotationsUsed{$1})) {
1090                     $AnnotationsUsed{$1} = 1;
1091                     goto rerun;
1092                 }
1093             }
1094         }
1095     }
1097     open (OUTPUT, ">$new_glossary")
1098         || die "Can't create $new_glossary";
1100     my $header = $doctype_header;
1101     $header =~ s/<!DOCTYPE \w+/<!DOCTYPE glossary/;
1103     print (OUTPUT  <<EOF);
1104 $header
1105 <glossary id="annotation-glossary">
1106   <title>Annotation Glossary</title>
1109     foreach my $annotation (keys(%AnnotationsUsed)) {
1110         if(defined($AnnotationDefinition{$annotation})) {
1111             my $def = $AnnotationDefinition{$annotation};
1112             my $curletter = uc(substr($annotation,0,1));
1114             if ($curletter ne $lastletter) {
1115                 $lastletter = $curletter;
1117                 if ($divopen == 1) {
1118                     print (OUTPUT "</glossdiv>\n");
1119                 }
1120                 print (OUTPUT "<glossdiv><title>$curletter</title>\n");
1121                 $divopen = 1;
1122             }
1123             print (OUTPUT <<EOF);
1124     <glossentry>
1125       <glossterm><anchor id="annotation-glossterm-$annotation"/>$annotation</glossterm>
1126       <glossdef>
1127         <para>$def</para>
1128       </glossdef>
1129     </glossentry>
1131         }
1132     }
1134     if ($divopen == 1) {
1135         print (OUTPUT "</glossdiv>\n");
1136     }
1137     print (OUTPUT "</glossary>\n");
1138     close (OUTPUT);
1140     &UpdateFileIfChanged ($old_glossary, $new_glossary, 0);
1143 #############################################################################
1144 # Function    : ReadKnownSymbols
1145 # Description : This collects the names of non-private symbols from the
1146 #               $MODULE-sections.txt file.
1147 # Arguments   : $file - the $MODULE-sections.txt file which contains all of
1148 #                the functions/macros/structs etc. being documented, organised
1149 #                into sections and subsections.
1150 #############################################################################
1152 sub ReadKnownSymbols {
1153     my ($file) = @_;
1155     my $subsection = "";
1157     #print "Reading: $file\n";
1158     open (INPUT, $file)
1159         || die "Can't open $file: $!";
1161     while (<INPUT>) {
1162         if (m/^#/) {
1163             next;
1165         } elsif (m/^<SECTION>/) {
1166             $subsection = "";
1168         } elsif (m/^<SUBSECTION\s*(.*)>/i) {
1169             $subsection = $1;
1171         } elsif (m/^<SUBSECTION>/) {
1172             next;
1174         } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
1175             next;
1177         } elsif (m/^<FILE>(.*)<\/FILE>/) {
1178             $KnownSymbols{"$TMPL_DIR/$1:Long_Description"} = 1;
1179             $KnownSymbols{"$TMPL_DIR/$1:Short_Description"} = 1;
1180             next;
1182         } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
1183             next;
1185         } elsif (m/^<\/SECTION>/) {
1186             next;
1188         } elsif (m/^(\S+)/) {
1189             my $symbol = $1;
1191             if ($subsection ne "Standard" && $subsection ne "Private") {
1192                 $KnownSymbols{$symbol} = 1;
1193             }
1194             else {
1195                 $KnownSymbols{$symbol} = 0;
1196             }
1197         }
1198     }
1199     close (INPUT);
1203 #############################################################################
1204 # Function    : OutputDeclaration
1205 # Description : Returns the synopsis and detailed description DocBook
1206 #                describing one function/macro etc.
1207 # Arguments   : $symbol - the name of the function/macro begin described.
1208 #                $declaration - the declaration of the function/macro.
1209 #############################################################################
1211 sub OutputDeclaration {
1212     my ($symbol, $declaration) = @_;
1214     my $type = $DeclarationTypes {$symbol};
1215     if ($type eq 'MACRO') {
1216         return &OutputMacro ($symbol, $declaration);
1217     } elsif ($type eq 'TYPEDEF') {
1218         return &OutputTypedef ($symbol, $declaration);
1219     } elsif ($type eq 'STRUCT') {
1220         return &OutputStruct ($symbol, $declaration);
1221     } elsif ($type eq 'ENUM') {
1222         return &OutputEnum ($symbol, $declaration);
1223     } elsif ($type eq 'UNION') {
1224         return &OutputUnion ($symbol, $declaration);
1225     } elsif ($type eq 'VARIABLE') {
1226         return &OutputVariable ($symbol, $declaration);
1227     } elsif ($type eq 'FUNCTION') {
1228         return &OutputFunction ($symbol, $declaration, $type);
1229     } elsif ($type eq 'USER_FUNCTION') {
1230         return &OutputFunction ($symbol, $declaration, $type);
1231     } else {
1232         die "Unknown symbol type";
1233     }
1237 #############################################################################
1238 # Function    : OutputSymbolTraits
1239 # Description : Returns the Since and StabilityLevel paragraphs for a symbol.
1240 # Arguments   : $symbol - the name of the function/macro begin described.
1241 #############################################################################
1243 sub OutputSymbolTraits {
1244     my ($symbol) = @_;
1245     my $desc = "";
1247     if (exists $Since{$symbol}) {
1248         $desc .= "<para role=\"since\">Since $Since{$symbol}</para>";
1249     }
1250     if (exists $StabilityLevel{$symbol}) {
1251         $desc .= "<para role=\"stability\">Stability Level: $StabilityLevel{$symbol}</para>";
1252     }
1253     return $desc;
1256 #############################################################################
1257 # Function    : Outpu{Symbol,Section}ExtraLinks
1258 # Description : Returns extralinks for the symbol (if enabled).
1259 # Arguments   : $symbol - the name of the function/macro begin described.
1260 #############################################################################
1262 sub uri_escape {
1263     my $text = $_[0];
1264     return undef unless defined $text;
1266     # Build a char to hex map
1267     my %escapes = ();
1268     for (0..255) {
1269             $escapes{chr($_)} = sprintf("%%%02X", $_);
1270     }
1272     # Default unsafe characters.  RFC 2732 ^(uric - reserved)
1273     $text =~ s/([^A-Za-z0-9\-_.!~*'()])/$escapes{$1}/g;
1275     return $text;
1278 sub OutputSymbolExtraLinks {
1279     my ($symbol) = @_;
1280     my $desc = "";
1282     if (0) { # NEW FEATURE: needs configurability
1283     my $sstr = &uri_escape($symbol);
1284     my $mstr = &uri_escape($MODULE);
1285     $desc .= <<EOF;
1286 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1287 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&amp;symbol=$sstr">edit documentation</ulink>
1289     }
1290     return $desc;
1293 sub OutputSectionExtraLinks {
1294     my ($symbol,$docsymbol) = @_;
1295     my $desc = "";
1297     if (0) { # NEW FEATURE: needs configurability
1298     my $sstr = &uri_escape($symbol);
1299     my $mstr = &uri_escape($MODULE);
1300     my $dsstr = &uri_escape($docsymbol);
1301     $desc .= <<EOF;
1302 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1303 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&amp;symbol=$dsstr">edit documentation</ulink>
1305     }
1306     return $desc;
1310 #############################################################################
1311 # Function    : OutputMacro
1312 # Description : Returns the synopsis and detailed description of a macro.
1313 # Arguments   : $symbol - the macro.
1314 #                $declaration - the declaration of the macro.
1315 #############################################################################
1317 sub OutputMacro {
1318     my ($symbol, $declaration) = @_;
1319     my $id = &CreateValidSGMLID ($symbol);
1320     my $condition = &MakeConditionDescription ($symbol);
1321     my $synop = &MakeReturnField("#define") . "<link linkend=\"$id\">$symbol</link>";
1322     my $desc;
1324     my @fields = ParseMacroDeclaration($declaration, \&CreateValidSGML);
1325     my $title = $symbol . (@fields ? "()" : "");
1327     $desc = "<refsect2 id=\"$id\" role=\"macro\"$condition>\n<title>$title</title>\n";
1328     $desc .= MakeIndexterms($symbol, $id);
1329     $desc .= "\n";
1330     $desc .= OutputSymbolExtraLinks($symbol);
1332     if (@fields) {
1333         if (length ($symbol) < $SYMBOL_FIELD_WIDTH) {
1334             $synop .= (' ' x ($SYMBOL_FIELD_WIDTH - length ($symbol)));
1335         }
1337         $synop .= "(";
1338         for (my $i = 1; $i <= $#fields; $i += 2) {
1339             my $field_name = $fields[$i];
1341             if ($i == 1) {
1342                 $synop .= "$field_name";
1343             } else {
1344                 $synop .= ",\n"
1345                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1346                     . " $field_name";
1347             }
1348         }
1349         $synop .= ")";
1350     }
1351     $synop .= "\n";
1353     # Don't output the macro definition if is is a conditional macro or it
1354     # looks like a function, i.e. starts with "g_" or "_?gnome_", or it is
1355     # longer than 2 lines, otherwise we get lots of complicated macros like
1356     # g_assert.
1357     if (!defined ($DeclarationConditional{$symbol}) && ($symbol !~ m/^g_/)
1358         && ($symbol !~ m/^_?gnome_/) && (($declaration =~ tr/\n//) < 2)) {
1359         my $decl_out = &CreateValidSGML ($declaration);
1360         $desc .= "<programlisting>$decl_out</programlisting>\n";
1361     } else {
1362         $desc .= "<programlisting>" . &MakeReturnField("#define") . "$symbol";
1363         if ($declaration =~ m/^\s*#\s*define\s+\w+(\([^\)]*\))/) {
1364             my $args = $1;
1365             my $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH - length ("#define "));
1366             # Align each line so that if should all line up OK.
1367             $args =~ s/\n/\n$pad/gm;
1368             $desc .= &CreateValidSGML ($args);
1369         }
1370         $desc .= "</programlisting>\n";
1371     }
1373     $desc .= &MakeDeprecationNote($symbol);
1375     my $parameters = &OutputParamDescriptions ("MACRO", $symbol, @fields);
1376     my $parameters_output = 0;
1378     if (defined ($SymbolDocs{$symbol})) {
1379         my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1381         # Try to insert the parameter table at the author's desired position.
1382         # Otherwise we need to tag it onto the end.
1383         if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1384           $parameters_output = 1;
1385         }
1386         $desc .= $symbol_docs;
1387     }
1389     if ($parameters_output == 0) {
1390         $desc .= $parameters;
1391     }
1393     $desc .= OutputSymbolTraits ($symbol);
1394     $desc .= "</refsect2>\n";
1395     return ($synop, $desc);
1399 #############################################################################
1400 # Function    : OutputTypedef
1401 # Description : Returns the synopsis and detailed description of a typedef.
1402 # Arguments   : $symbol - the typedef.
1403 #                $declaration - the declaration of the typedef,
1404 #                  e.g. 'typedef unsigned int guint;'
1405 #############################################################################
1407 sub OutputTypedef {
1408     my ($symbol, $declaration) = @_;
1409     my $id = &CreateValidSGMLID ($symbol);
1410     my $condition = &MakeConditionDescription ($symbol);
1411     my $synop = &MakeReturnField("typedef") . "<link linkend=\"$id\">$symbol</link>;\n";
1412     my $desc = "<refsect2 id=\"$id\" role=\"typedef\"$condition>\n<title>$symbol</title>\n";
1414     $desc .= MakeIndexterms($symbol, $id);
1415     $desc .= "\n";
1416     $desc .= OutputSymbolExtraLinks($symbol);
1418     if (!defined ($DeclarationConditional{$symbol})) {
1419         my $decl_out = &CreateValidSGML ($declaration);
1420         $desc .= "<programlisting>$decl_out</programlisting>\n";
1421     }
1423     $desc .= &MakeDeprecationNote($symbol);
1425     if (defined ($SymbolDocs{$symbol})) {
1426         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1427     }
1428     $desc .= OutputSymbolTraits ($symbol);
1429     $desc .= "</refsect2>\n";
1430     return ($synop, $desc);
1434 #############################################################################
1435 # Function    : OutputStruct
1436 # Description : Returns the synopsis and detailed description of a struct.
1437 #                We check if it is a object struct, and if so we only output
1438 #                parts of it that are noted as public fields.
1439 #                We also use a different SGML ID for object structs, since the
1440 #                original ID is used for the entire RefEntry.
1441 # Arguments   : $symbol - the struct.
1442 #                $declaration - the declaration of the struct.
1443 #############################################################################
1445 sub OutputStruct {
1446     my ($symbol, $declaration) = @_;
1448     my $is_gtype = 0;
1449     my $default_to_public = 1;
1450     if (&CheckIsObject ($symbol)) {
1451         #print "Found struct gtype: $symbol\n";
1452         $is_gtype = 1;
1453         $default_to_public = $ObjectRoots{$symbol} eq 'GBoxed';
1454     }
1456     my $id;
1457     my $condition;
1458     if ($is_gtype) {
1459         $id = &CreateValidSGMLID ($symbol . "_struct");
1460         $condition = &MakeConditionDescription ($symbol . "_struct");
1461     } else {
1462         $id = &CreateValidSGMLID ($symbol);
1463         $condition = &MakeConditionDescription ($symbol);
1464     }
1466     # Determine if it is a simple struct or it also has a typedef.
1467     my $has_typedef = 0;
1468     if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1469       $has_typedef = 1;
1470     }
1472     my $synop;
1473     my $desc;
1474     if ($has_typedef) {
1475         # For structs with typedefs we just output the struct name.
1476         $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1477         $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>$symbol</title>\n";
1478     } else {
1479         $synop = &MakeReturnField("struct") . "<link linkend=\"$id\">$symbol</link>;\n";
1480         $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>struct $symbol</title>\n";
1481     }
1483     $desc .= MakeIndexterms($symbol, $id);
1484     $desc .= "\n";
1485     $desc .= OutputSymbolExtraLinks($symbol);
1487     # Form a pretty-printed, private-data-removed form of the declaration
1489     my $decl_out = "";
1490     if ($declaration =~ m/^\s*$/) {
1491         #print "Found opaque struct: $symbol\n";
1492         $decl_out = "typedef struct _$symbol $symbol;";
1493     } elsif ($declaration =~ m/^\s*struct\s+\w+\s*;\s*$/) {
1494         #print "Found opaque struct: $symbol\n";
1495         $decl_out = "struct $symbol;";
1496     } else {
1497         my $public = $default_to_public;
1498         my $new_declaration = "";
1499         my $decl_line;
1500         my $decl = $declaration;
1502         if ($decl =~ m/^\s*(typedef\s+)?struct\s*\w*\s*(?:\/\*.*\*\/)?\s*{(.*)}\s*\w*\s*;\s*$/s) {
1503             my $struct_contents = $2;
1505             foreach $decl_line (split (/\n/, $struct_contents)) {
1506                 #print "Struct line: $decl_line\n";
1507                 if ($decl_line =~ m%/\*\s*<\s*public\s*>\s*\*/%) {
1508                     $public = 1;
1509                 } elsif ($decl_line =~ m%/\*\s*<\s*(private|protected)\s*>\s*\*/%) {
1510                     $public = 0;
1511                 } elsif ($public) {
1512                     $new_declaration .= $decl_line . "\n";
1513                 }
1514             }
1516             if ($new_declaration) {
1517                 # Strip any blank lines off the ends.
1518                 $new_declaration =~ s/^\s*\n//;
1519                 $new_declaration =~ s/\n\s*$/\n/;
1521                 if ($has_typedef) {
1522                     $decl_out = "typedef struct {\n" . $new_declaration
1523                       . "} $symbol;\n";
1524                 } else {
1525                     $decl_out = "struct $symbol {\n" . $new_declaration
1526                       . "};\n";
1527                 }
1528             }
1529         } else {
1530             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1531                 "Couldn't parse struct:\n$declaration");
1532         }
1534         # If we couldn't parse the struct or it was all private, output an
1535         # empty struct declaration.
1536         if ($decl_out eq "") {
1537             if ($has_typedef) {
1538                 $decl_out = "typedef struct _$symbol $symbol;";
1539             } else {
1540                 $decl_out = "struct $symbol;";
1541             }
1542         }
1543     }
1545     $decl_out = &CreateValidSGML ($decl_out);
1546     $desc .= "<programlisting>$decl_out</programlisting>\n";
1548     $desc .= &MakeDeprecationNote($symbol);
1550     if (defined ($SymbolDocs{$symbol})) {
1551         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1552     }
1554     # Create a table of fields and descriptions
1556     # FIXME: Inserting &#160's into the produced type declarations here would
1557     #        improve the output in most situations ... except for function
1558     #        members of structs!
1559     my @fields = ParseStructDeclaration($declaration, !$default_to_public,
1560                                         0, \&MakeXRef,
1561                                         sub {
1562                                             "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1563                                         });
1564     my $params = $SymbolParams{$symbol};
1566     # If no parameters are filled in, we don't generate the description
1567     # table, for backwards compatibility.
1569     my $found = 0;
1570     if (defined $params) {
1571         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1572             if ($params->[$i] =~ /\S/) {
1573                 $found = 1;
1574                 last;
1575             }
1576         }
1577     }
1579     if ($found) {
1580         my %field_descrs = @$params;
1581         my $missing_parameters = "";
1582         my $unused_parameters = "";
1584         $desc .= "<variablelist role=\"struct\">\n";
1585         while (@fields) {
1586             my $field_name = shift @fields;
1587             my $text = shift @fields;
1588             my $field_descr = $field_descrs{$field_name};
1589             my $param_annotations = "";
1591             $desc .= "<varlistentry><term>$text</term>\n";
1592             if (defined $field_descr) {
1593                 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1594                 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1595                 $field_descr .= $param_annotations;
1596                 # trim
1597                 $field_descr =~ s/^(\s|\n)+//msg;
1598                 $field_descr =~ s/(\s|\n)+$//msg;
1599                 $desc .= "<listitem><simpara>$field_descr</simpara></listitem>\n";
1600                 delete $field_descrs{$field_name};
1601             } else {
1602                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1603                     "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1604                 if ($missing_parameters ne "") {
1605                   $missing_parameters .= ", ".$field_name;
1606                 } else {
1607                     $missing_parameters = $field_name;
1608                 }
1609                 $desc .= "<listitem />\n";
1610             }
1611             $desc .= "</varlistentry>\n";
1612         }
1613         $desc .= "</variablelist>";
1614         foreach my $field_name (keys %field_descrs) {
1615             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1616                 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1617             if ($unused_parameters ne "") {
1618               $unused_parameters .= ", ".$field_name;
1619             } else {
1620                $unused_parameters = $field_name;
1621             }
1622         }
1624         # remember missing/unused parameters (needed in tmpl-free build)
1625         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1626             $AllIncompleteSymbols{$symbol}=$missing_parameters;
1627         }
1628         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1629             $AllUnusedSymbols{$symbol}=$unused_parameters;
1630         }
1631     }
1632     else {
1633         if (scalar(@fields) > 0) {
1634             if (! exists ($AllIncompleteSymbols{$symbol})) {
1635                 $AllIncompleteSymbols{$symbol}="<items>";
1636                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1637                     "Field descriptions for struct $symbol are missing in source code comment block.");
1638                 @TRACE@("Remaining structs fields: ".@fields.":".join(',',@fields)."\n");
1639             }
1640         }
1641     }
1643     $desc .= OutputSymbolTraits ($symbol);
1644     $desc .= "</refsect2>\n";
1645     return ($synop, $desc);
1649 #############################################################################
1650 # Function    : OutputUnion
1651 # Description : Returns the synopsis and detailed description of a union.
1652 # Arguments   : $symbol - the union.
1653 #                $declaration - the declaration of the union.
1654 #############################################################################
1656 sub OutputUnion {
1657     my ($symbol, $declaration) = @_;
1658     my $id = &CreateValidSGMLID ($symbol);
1659     my $condition = &MakeConditionDescription ($symbol);
1661     # Determine if it is a simple struct or it also has a typedef.
1662     my $has_typedef = 0;
1663     if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1664       $has_typedef = 1;
1665     }
1667     my $synop;
1668     my $desc;
1669     if ($has_typedef) {
1670         # For unions with typedefs we just output the union name.
1671         $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1672         $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>$symbol</title>\n";
1673     } else {
1674         $synop = &MakeReturnField("union") . "<link linkend=\"$id\">$symbol</link>;\n";
1675         $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>union $symbol</title>\n";
1676     }
1678     $desc .= MakeIndexterms($symbol, $id);
1679     $desc .= "\n";
1680     $desc .= OutputSymbolExtraLinks($symbol);
1682     # FIXME: we do more for structs
1683     my $decl_out = &CreateValidSGML ($declaration);
1684     $desc .= "<programlisting>$decl_out</programlisting>\n";
1686     $desc .= &MakeDeprecationNote($symbol);
1688     if (defined ($SymbolDocs{$symbol})) {
1689         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1690     }
1692     # Create a table of fields and descriptions
1694     # FIXME: Inserting &#160's into the produced type declarations here would
1695     #        improve the output in most situations ... except for function
1696     #        members of structs!
1697     my @fields = ParseStructDeclaration($declaration, 0,
1698                                         0, \&MakeXRef,
1699                                         sub {
1700                                             "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1701                                         });
1702     my $params = $SymbolParams{$symbol};
1704     # If no parameters are filled in, we don't generate the description
1705     # table, for backwards compatibility
1707     my $found = 0;
1708     if (defined $params) {
1709         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1710             if ($params->[$i] =~ /\S/) {
1711                 $found = 1;
1712                 last;
1713             }
1714         }
1715     }
1717     if ($found) {
1718         my %field_descrs = @$params;
1719         my $missing_parameters = "";
1720         my $unused_parameters = "";
1722         $desc .= "<variablelist role=\"union\">\n";
1723         while (@fields) {
1724             my $field_name = shift @fields;
1725             my $text = shift @fields;
1726             my $field_descr = $field_descrs{$field_name};
1727             my $param_annotations = "";
1729             $desc .= "<varlistentry><term>$text</term>\n";
1730             if (defined $field_descr) {
1731                 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1732                 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1733                 $field_descr .= $param_annotations;
1734                 # trim
1735                 $field_descr =~ s/^(\s|\n)+//msg;
1736                 $field_descr =~ s/(\s|\n)+$//msg;
1737                 $desc .= "<listitem><simpara>$field_descr</simpara></listitem>\n";
1738                 delete $field_descrs{$field_name};
1739             } else {
1740                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1741                     "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1742                 if ($missing_parameters ne "") {
1743                     $missing_parameters .= ", ".$field_name;
1744                 } else {
1745                     $missing_parameters = $field_name;
1746                 }
1747                 $desc .= "<listitem />\n";
1748             }
1749             $desc .= "</varlistentry>\n";
1750         }
1751         $desc .= "</variablelist>";
1752         foreach my $field_name (keys %field_descrs) {
1753             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1754                 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1755             if ($unused_parameters ne "") {
1756               $unused_parameters .= ", ".$field_name;
1757             } else {
1758                $unused_parameters = $field_name;
1759             }
1760         }
1762         # remember missing/unused parameters (needed in tmpl-free build)
1763         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1764             $AllIncompleteSymbols{$symbol}=$missing_parameters;
1765         }
1766         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1767             $AllUnusedSymbols{$symbol}=$unused_parameters;
1768         }
1769     }
1770     else {
1771         if (scalar(@fields) > 0) {
1772             if (! exists ($AllIncompleteSymbols{$symbol})) {
1773                 $AllIncompleteSymbols{$symbol}="<items>";
1774                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1775                     "Field descriptions for union $symbol are missing in source code comment block.");
1776                 @TRACE@("Remaining union fields: ".@fields.":".join(',',@fields)."\n");
1777             }
1778         }
1779     }
1781     $desc .= OutputSymbolTraits ($symbol);
1782     $desc .= "</refsect2>\n";
1783     return ($synop, $desc);
1787 #############################################################################
1788 # Function    : OutputEnum
1789 # Description : Returns the synopsis and detailed description of a enum.
1790 # Arguments   : $symbol - the enum.
1791 #                $declaration - the declaration of the enum.
1792 #############################################################################
1794 sub OutputEnum {
1795     my ($symbol, $declaration) = @_;
1797     my $is_gtype = 0;
1798     if (&CheckIsObject ($symbol)) {
1799         #print "Found enum gtype: $symbol\n";
1800         $is_gtype = 1;
1801     }
1803     my $id;
1804     my $condition;
1805     if ($is_gtype) {
1806         $id = &CreateValidSGMLID ($symbol . "_enum");
1807         $condition = &MakeConditionDescription ($symbol . "_enum");
1808     } else {
1809         $id = &CreateValidSGMLID ($symbol);
1810         $condition = &MakeConditionDescription ($symbol);
1811     }
1813     my $synop = &MakeReturnField("enum") . "<link linkend=\"$id\">$symbol</link>;\n";
1814     my $desc = "<refsect2 id=\"$id\" role=\"enum\"$condition>\n<title>enum $symbol</title>\n";
1816     $desc .= MakeIndexterms($symbol, $id);
1817     $desc .= "\n";
1818     $desc .= OutputSymbolExtraLinks($symbol);
1820     my $decl_out = "";
1821     my $public = 1;
1822     my $new_declaration = "";
1823     my $decl_line;
1824     my $decl = $declaration;
1826     if ($decl =~ m/^\s*(typedef\s+)?enum\s*\w*\s*(?:\/\*.*\*\/)?\s*{(.*)}\s*\w*\s*;\s*$/s) {
1827         my $has_typedef = defined($1) ? 1 : 0;
1828         my $enum_contents = $2;
1830         foreach $decl_line (split (/\n/, $enum_contents)) {
1831             #print "Enum line: $decl_line\n";
1832             if ($decl_line =~ m%/\*\s*<\s*public\s*>\s*\*/%) {
1833                 $public = 1;
1834             } elsif ($decl_line =~ m%/\*\s*<\s*(private|protected)\s*>\s*\*/%) {
1835                 $public = 0;
1836             } elsif ($public) {
1837                 $new_declaration .= $decl_line . "\n";
1838             }
1839         }
1841         if ($new_declaration) {
1842             # Strip any blank lines off the ends.
1843             $new_declaration =~ s/^\s*\n//;
1844             $new_declaration =~ s/\n\s*$/\n/;
1846             if ($has_typedef) {
1847                 $decl_out = "typedef enum {\n" . $new_declaration
1848                   . "} $symbol;\n";
1849             } else {
1850                 $decl_out = "enum $symbol {\n" . $new_declaration
1851                   . "};\n";
1852             }
1853         }
1854     }
1856     $decl_out = &CreateValidSGML ($decl_out);
1857     $desc .= "<programlisting>$decl_out</programlisting>\n";
1859     $desc .= &MakeDeprecationNote($symbol);
1861     if (defined ($SymbolDocs{$symbol})) {
1862         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1863     }
1865     # Create a table of fields and descriptions
1867     my @fields = ParseEnumDeclaration($declaration);
1868     my $params = $SymbolParams{$symbol};
1870     # If no parameters are filled in, we don't generate the description
1871     # table, for backwards compatibility
1873     my $found = 0;
1874     if (defined $params) {
1875         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1876             if ($params->[$i] =~ /\S/) {
1877                 $found = 1;
1878                 last;
1879             }
1880         }
1881     }
1883     if ($found) {
1884         my %field_descrs = @$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                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1903                     "Value description for $symbol"."::"."$field_name is missing in source code comment block.");
1904                 if ($missing_parameters ne "") {
1905                   $missing_parameters .= ", ".$field_name;
1906                 } else {
1907                     $missing_parameters = $field_name;
1908                 }
1909                 $desc .= "<listitem />\n";
1910             }
1911             $desc .= "</varlistentry>\n";
1912         }
1913         $desc .= "</variablelist>";
1914         foreach my $field_name (keys %field_descrs) {
1915             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1916                 "Value description for $symbol"."::"."$field_name is not used from source code comment block.");
1917             if ($unused_parameters ne "") {
1918               $unused_parameters .= ", ".$field_name;
1919             } else {
1920                $unused_parameters = $field_name;
1921             }
1922         }
1924         # remember missing/unused parameters (needed in tmpl-free build)
1925         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1926             $AllIncompleteSymbols{$symbol}=$missing_parameters;
1927         }
1928         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1929             $AllUnusedSymbols{$symbol}=$unused_parameters;
1930         }
1931     }
1932     else {
1933         if (scalar(@fields) > 0) {
1934             if (! exists ($AllIncompleteSymbols{$symbol})) {
1935                 $AllIncompleteSymbols{$symbol}="<items>";
1936                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1937                     "Value descriptions for $symbol are missing in source code comment block.");
1938             }
1939         }
1940     }
1942     $desc .= OutputSymbolTraits ($symbol);
1943     $desc .= "</refsect2>\n";
1944     return ($synop, $desc);
1948 #############################################################################
1949 # Function    : OutputVariable
1950 # Description : Returns the synopsis and detailed description of a variable.
1951 # Arguments   : $symbol - the extern'ed variable.
1952 #                $declaration - the declaration of the variable.
1953 #############################################################################
1955 sub OutputVariable {
1956     my ($symbol, $declaration) = @_;
1957     my $id = &CreateValidSGMLID ($symbol);
1958     my $condition = &MakeConditionDescription ($symbol);
1959     
1960     @TRACE@("ouputing variable: '$symbol' '$declaration'");
1962     my $synop;
1963     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*;/) {
1964         my $mod1 = defined ($1) ? $1 : "";
1965         my $ptr = defined ($3) ? $3 : "";
1966         my $space = defined ($4) ? $4 : "";
1967         my $mod2 = defined ($5) ? $5 : "";
1968         $synop = &MakeReturnField("extern $mod1$ptr$space$mod2") . "<link linkend=\"$id\">$symbol</link>;\n";
1969     } 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*=/) {
1970         my $mod1 = defined ($1) ? $1 : "";
1971         my $ptr = defined ($3) ? $3 : "";
1972         my $space = defined ($4) ? $4 : "";
1973         my $mod2 = defined ($5) ? $5 : "";
1974         $synop = &MakeReturnField("$mod1$ptr$space$mod2") . "<link linkend=\"$id\">$symbol</link>;\n";
1976     } else {
1977         $synop = &MakeReturnField("extern") . "<link linkend=\"$id\">$symbol</link>;\n";
1978     }
1980     my $desc = "<refsect2 id=\"$id\" role=\"variable\"$condition>\n<title>$symbol</title>\n";
1982     $desc .= MakeIndexterms($symbol, $id);
1983     $desc .= "\n";
1984     $desc .= OutputSymbolExtraLinks($symbol);
1986     my $decl_out = &CreateValidSGML ($declaration);
1987     $desc .= "<programlisting>$decl_out</programlisting>\n";
1989     $desc .= &MakeDeprecationNote($symbol);
1991     if (defined ($SymbolDocs{$symbol})) {
1992         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1993     }
1994     $desc .= OutputSymbolTraits ($symbol);
1995     $desc .= "</refsect2>\n";
1996     return ($synop, $desc);
2000 #############################################################################
2001 # Function    : OutputFunction
2002 # Description : Returns the synopsis and detailed description of a function.
2003 # Arguments   : $symbol - the function.
2004 #                $declaration - the declaration of the function.
2005 #############################################################################
2007 sub OutputFunction {
2008     my ($symbol, $declaration, $symbol_type) = @_;
2009     my $id = &CreateValidSGMLID ($symbol);
2010     my $condition = &MakeConditionDescription ($symbol);
2012     # Take out the return type     $1                                                                                       $2   $3
2013     $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//;
2014     my $type_modifier = defined($1) ? $1 : "";
2015     my $type = $2;
2016     my $pointer = $3;
2017     # Trim trailing spaces as we are going to pad to $RETURN_TYPE_FIELD_WIDTH below anyway
2018     $pointer =~ s/\s+$//;
2019     my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
2020     my $start = "";
2021     #if ($symbol_type eq 'USER_FUNCTION') {
2022     #    $start = "typedef ";
2023     #}
2025     # We output const rather than G_CONST_RETURN.
2026     $type_modifier =~ s/G_CONST_RETURN/const/g;
2027     $pointer =~ s/G_CONST_RETURN/const/g;
2028     $pointer =~ s/^\s+/ /g;
2030     my $ret_type_len = length ($start) + length ($type_modifier)+ length ($type)
2031         + length ($pointer);
2032     my $ret_type_output;
2033     my $symbol_len;
2034     if ($ret_type_len < $RETURN_TYPE_FIELD_WIDTH) {
2035         $ret_type_output = "$start$type_modifier$xref$pointer"
2036             . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
2037         $symbol_len = 0;
2038     } else {
2039         #$ret_type_output = "$start$type_modifier$xref$pointer\n" . (' ' x $RETURN_TYPE_FIELD_WIDTH);
2041         $ret_type_output = "$start$type_modifier$xref$pointer ";
2042         $symbol_len = $ret_type_len + 1 - $RETURN_TYPE_FIELD_WIDTH;
2043     }
2044     #@TRACE@("$symbol ret type output: [$ret_type_output], $ret_type_len");
2046     $symbol_len += length ($symbol);
2047     my $char1 = my $char2 = my $char3 = "";
2048     if ($symbol_type eq 'USER_FUNCTION') {
2049         $symbol_len += 3;
2050         $char1 = "(";
2051         $char2 = "*";
2052         $char3 = ")";
2053     }
2055     my ($symbol_output, $symbol_desc_output);
2056     if ($symbol_len < $SYMBOL_FIELD_WIDTH) {
2057         $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3"
2058             . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
2059         $symbol_desc_output = "$char1$char2$symbol$char3"
2060             . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
2061     } else {
2062         $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3\n"
2063             . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
2064         $symbol_desc_output = "$char1$char2$symbol$char3\n"
2065             . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
2066     }
2068     my $synop = $ret_type_output . $symbol_output . '(';
2069     my $desc = "<refsect2 id=\"$id\" role=\"function\"$condition>\n<title>${symbol} ()</title>\n";
2071     $desc .= MakeIndexterms($symbol, $id);
2072     $desc .= "\n";
2073     $desc .= OutputSymbolExtraLinks($symbol);
2075     $desc  .= "<programlisting>${ret_type_output}$symbol_desc_output(";
2077     my @fields = ParseFunctionDeclaration($declaration, \&MakeXRef,
2078                                         sub {
2079                                             &tagify($_[0],"parameter");
2080                                         });
2082     for (my $i = 1; $i <= $#fields; $i += 2) {
2083         my $field_name = $fields[$i];
2085         if ($i == 1) {
2086             $synop .= "$field_name";
2087             $desc  .= "$field_name";
2088         } else {
2089             $synop .= ",\n"
2090                 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2091                 . " $field_name";
2092             $desc  .= ",\n"
2093                 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2094                 . " $field_name";
2095         }
2097     }
2099     $synop .= ");\n";
2100     $desc  .= ");</programlisting>\n";
2102     $desc .= &MakeDeprecationNote($symbol);
2104     my $parameters = &OutputParamDescriptions ("FUNCTION", $symbol, @fields);
2105     my $parameters_output = 0;
2107     if (defined ($SymbolDocs{$symbol})) {
2108         my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
2110         # Try to insert the parameter table at the author's desired position.
2111         # Otherwise we need to tag it onto the end.
2112         # FIXME: document that in the user manual and make it useable for other
2113         # types too
2114         if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
2115           $parameters_output = 1;
2116         }
2117         $desc .= $symbol_docs;
2118     }
2120     if ($parameters_output == 0) {
2121         $desc .= $parameters;
2122     }
2124     $desc .= OutputSymbolTraits ($symbol);
2125     $desc .= "</refsect2>\n";
2126     return ($synop, $desc);
2130 #############################################################################
2131 # Function    : OutputParamDescriptions
2132 # Description : Returns the DocBook output describing the parameters of a
2133 #                function, macro or signal handler.
2134 # Arguments   : $symbol_type - 'FUNCTION', 'MACRO' or 'SIGNAL'. Signal
2135 #                  handlers have an implicit user_data parameter last.
2136 #                $symbol - the name of the function/macro being described.
2137 #               @fields - parsed fields from the declaration, used to determine
2138 #                  undocumented/unused entries
2139 #############################################################################
2141 sub OutputParamDescriptions {
2142     my ($symbol_type, $symbol, @fields) = @_;
2143     my $output = "";
2144     my $params = $SymbolParams{$symbol};
2145     my $num_params = 0;
2146     my %field_descrs = ();
2148     if (@fields) {
2149         %field_descrs = @fields;
2150         delete $field_descrs{"void"};
2151         delete $field_descrs{"Returns"};
2152     }
2154     if (defined $params) {
2155         my $returns = "";
2156         my $params_desc = "";
2157         my $missing_parameters = "";
2158         my $unused_parameters = "";
2159         my $j;
2161         for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
2162             my $param_name = $$params[$j];
2163             my $param_desc = $$params[$j + 1];
2164             my $param_annotations = "";
2166             ($param_desc,$param_annotations) = & ExpandAnnotation($symbol, $param_desc);
2167             $param_desc = &ExpandAbbreviations($symbol, $param_desc);
2168             $param_desc .= $param_annotations;
2169             # trim
2170             $param_desc =~ s/^(\s|\n)+//msg;
2171             $param_desc =~ s/(\s|\n)+$//msg;
2172             if ($param_name eq "Returns") {
2173                 $returns = "$param_desc";
2174             } elsif ($param_name eq "void") {
2175                 #print "!!!! void in params for $symbol?\n";
2176             } else {
2177                 if (@fields) {
2178                     if (!defined $field_descrs{$param_name}) {
2179                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2180                             "Parameter description for $symbol"."::"."$param_name is not used from source code comment block.");
2181                         if ($unused_parameters ne "") {
2182                           $unused_parameters .= ", ".$param_name;
2183                         } else {
2184                            $unused_parameters = $param_name;
2185                         }
2186                     } else {
2187                         delete $field_descrs{$param_name};
2188                     }
2189                 }
2190                 if($param_desc ne "") {
2191                     $params_desc .= "<varlistentry><term><parameter>$param_name</parameter>&#160;:</term>\n<listitem><simpara>$param_desc</simpara></listitem></varlistentry>\n";
2192                     $num_params++;
2193                 }
2194             }
2195         }
2196         foreach my $param_name (keys %field_descrs) {
2197             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2198                 "Parameter description for $symbol"."::"."$param_name is missing in source code comment block.");
2199             if ($missing_parameters ne "") {
2200               $missing_parameters .= ", ".$param_name;
2201             } else {
2202                $missing_parameters = $param_name;
2203             }
2204         }
2206         # Signals have an implicit user_data parameter which we describe.
2207         if ($symbol_type eq "SIGNAL") {
2208             $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";
2209         }
2211         # Start a table if we need one.
2212         if ($params_desc || $returns) {
2213             $output .= "<variablelist role=\"params\">\n";
2214             if ($params_desc ne "") {
2215                 #$output .= "<varlistentry><term>Parameters:</term><listitem></listitem></varlistentry>\n";
2216                 $output .= $params_desc;
2217             }
2219             # Output the returns info last
2220             if ($returns) {
2221                 $output .= "<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara>$returns</simpara></listitem></varlistentry>\n";
2222             }
2224             # Finish the table.
2225             $output .= "</variablelist>";
2226         }
2228         # remember missing/unused parameters (needed in tmpl-free build)
2229         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
2230             $AllIncompleteSymbols{$symbol}=$missing_parameters;
2231         }
2232         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
2233             $AllUnusedSymbols{$symbol}=$unused_parameters;
2234         }
2235     }
2236     if (($num_params == 0) && @fields && (scalar(keys(%field_descrs)) > 0)) {
2237         if (! exists ($AllIncompleteSymbols{$symbol})) {
2238             $AllIncompleteSymbols{$symbol}="<parameters>";
2239         }
2240     }
2242     return $output;
2246 #############################################################################
2247 # Function    : ParseStabilityLevel
2248 # Description : Parses a stability level and outputs a warning if it isn't
2249 #               valid.
2250 # Arguments   : $stability - the stability text.
2251 #                $file, $line - context for error message
2252 #                $message - description of where the level is from, to use in
2253 #               any error message.
2254 # Returns     : The parsed stability level string.
2255 #############################################################################
2257 sub ParseStabilityLevel {
2258     my ($stability, $file, $line, $message) = @_;
2260     $stability =~ s/^\s*//;
2261     $stability =~ s/\s*$//;
2262     if ($stability =~ m/^stable$/i) {
2263         $stability = "Stable";
2264     } elsif ($stability =~ m/^unstable$/i) {
2265         $stability = "Unstable";
2266     } elsif ($stability =~ m/^private$/i) {
2267         $stability = "Private";
2268     } else {
2269         &LogWarning ($file, $line, "$message is $stability.".
2270             "It should be one of these: Stable, Unstable, or Private.");
2271     }
2272     return $stability;
2276 #############################################################################
2277 # Function    : OutputSGMLFile
2278 # Description : Outputs the final DocBook file for one section.
2279 # Arguments   : $file - the name of the file.
2280 #               $title - the title from the $MODULE-sections.txt file, which
2281 #                 will be overridden by the title in the template file.
2282 #               $section_id - the SGML id to use for the toplevel tag.
2283 #               $includes - comma-separates list of include files added at top of
2284 #                 synopsis, with '<' '>' around them (if not already enclosed in "").
2285 #               $synopsis - reference to the DocBook for the Synopsis part.
2286 #               $details - reference to the DocBook for the Details part.
2287 #               $signal_synop - reference to the DocBook for the Signal Synopsis part
2288 #               $signal_desc - reference to the DocBook for the Signal Description part
2289 #               $args_synop - reference to the DocBook for the Arg Synopsis part
2290 #               $args_desc - reference to the DocBook for the Arg Description part
2291 #               $hierarchy - reference to the DocBook for the Object Hierarchy part
2292 #               $interfaces - reference to the DocBook for the Interfaces part
2293 #               $implementations - reference to the DocBook for the Known Implementations part
2294 #               $prerequisites - reference to the DocBook for the Prerequisites part
2295 #               $derived - reference to the DocBook for the Derived Interfaces part
2296 #               $file_objects - reference to an array of objects in this file
2297 #############################################################################
2299 sub OutputSGMLFile {
2300     my ($file, $title, $section_id, $includes, $synopsis, $details, $signals_synop, $signals_desc, $args_synop, $args_desc, $hierarchy, $interfaces, $implementations, $prerequisites, $derived, $file_objects) = @_;
2302     #print "Output sgml for file $file with title '$title'\n";
2304     # The edited title overrides the one from the sections file.
2305     my $new_title = $SymbolDocs{"$TMPL_DIR/$file:Title"};
2306     if (defined ($new_title) && $new_title !~ m/^\s*$/) {
2307         $title = $new_title;
2308         #print "Found title: $title\n";
2309     }
2310     my $short_desc = $SymbolDocs{"$TMPL_DIR/$file:Short_Description"};
2311     if (!defined ($short_desc) || $short_desc =~ m/^\s*$/) {
2312         $short_desc = "";
2313     } else {
2314         $short_desc = &ExpandAbbreviations("$title:Short_description",
2315                                            $short_desc);
2316         #print "Found short_desc: $short_desc";
2317     }
2318     my $long_desc = $SymbolDocs{"$TMPL_DIR/$file:Long_Description"};
2319     if (!defined ($long_desc) || $long_desc =~ m/^\s*$/) {
2320         $long_desc = "";
2321     } else {
2322         $long_desc = &ExpandAbbreviations("$title:Long_description",
2323                                           $long_desc);
2324         #print "Found long_desc: $long_desc";
2325     }
2326     my $see_also = $SymbolDocs{"$TMPL_DIR/$file:See_Also"};
2327     if (!defined ($see_also) || $see_also =~ m%^\s*(<para>)?\s*(</para>)?\s*$%) {
2328         $see_also = "";
2329     } else {
2330         $see_also = &ExpandAbbreviations("$title:See_Also", $see_also);
2331         #print "Found see_also: $see_also";
2332     }
2333     if ($see_also) {
2334         $see_also = "<refsect1 id=\"$section_id.see-also\">\n<title>See Also</title>\n$see_also\n</refsect1>\n";
2335     }
2336     my $stability = $SymbolDocs{"$TMPL_DIR/$file:Stability_Level"};
2337     if (!defined ($stability) || $stability =~ m/^\s*$/) {
2338         $stability = "";
2339     } else {
2340         $stability = &ParseStabilityLevel($stability, $file, $., "Section stability level");
2341         #print "Found stability: $stability";
2342     }
2343     if ($stability) {
2344         $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$stability, unless otherwise indicated\n</refsect1>\n";
2345     } elsif ($DEFAULT_STABILITY) {
2346         $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$DEFAULT_STABILITY, unless otherwise indicated\n</refsect1>\n";
2347     }
2349     my $image = $SymbolDocs{"$TMPL_DIR/$file:Image"};
2350     if (!defined ($image) || $image =~ m/^\s*$/) {
2351       $image = "";
2352     } else {
2353       $image =~ s/^\s*//;
2354       $image =~ s/\s*$//;
2356       my $format;
2358       if ($image =~ /jpe?g$/i) {
2359         $format = "format='JPEG'";
2360       } elsif ($image =~ /png$/i) {
2361         $format = "format='PNG'";
2362       } elsif ($image =~ /svg$/i) {
2363         $format = "format='SVG'";
2364       } else {
2365         $format = "";
2366       }
2368       $image = "  <inlinegraphic fileref='$image' $format/>\n"
2369     }
2371     my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
2372         gmtime (time);
2373     my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
2374     $year += 1900;
2376     my $include_output = "";
2377     my $include;
2378     foreach $include (split (/,/, $includes)) {
2379         if ($include =~ m/^\".+\"$/) {
2380             $include_output .= "#include ${include}\n";
2381         }
2382         else {
2383             $include =~ s/^\s+|\s+$//gs;
2384             $include_output .= "#include &lt;${include}&gt;\n";
2385         }
2386     }
2387     if ($include_output ne '') {
2388         $include_output = "\n$include_output\n";
2389     }
2391     my $extralinks = OutputSectionExtraLinks($title,"Section:$file");
2393     my $old_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT";
2394     my $new_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT.new";
2396     open (OUTPUT, ">$new_sgml_file")
2397         || die "Can't create $new_sgml_file: $!";
2399     my $object_anchors = "";
2400     foreach my $object (@$file_objects) {
2401         next if ($object eq $section_id);
2402         my $id = CreateValidSGMLID($object);
2403         #print "Debug: Adding anchor for $object\n";
2404         $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
2405     }
2407     # We used to output this, but is messes up our UpdateFileIfChanged code
2408     # since it changes every day (and it is only used in the man pages):
2409     # "<refentry id="$section_id" revision="$mday $month $year">"
2411     if ($OUTPUT_FORMAT eq "xml") {
2412         print OUTPUT $doctype_header;
2413     }
2415     print OUTPUT <<EOF;
2416 <refentry id="$section_id">
2417 <refmeta>
2418 <refentrytitle role="top_of_page" id="$section_id.top_of_page">$title</refentrytitle>
2419 <manvolnum>3</manvolnum>
2420 <refmiscinfo>
2421   \U$MODULE\E Library
2422 $image</refmiscinfo>
2423 </refmeta>
2424 <refnamediv>
2425 <refname>$title</refname>
2426 <refpurpose>$short_desc</refpurpose>
2427 </refnamediv>
2428 $stability
2429 <refsynopsisdiv id="$section_id.synopsis" role="synopsis">
2430 <title role="synopsis.title">Synopsis</title>
2431 $object_anchors
2432 <synopsis>$include_output$${synopsis}</synopsis>
2433 </refsynopsisdiv>
2434 $$hierarchy$$prerequisites$$derived$$interfaces$$implementations$$args_synop$$signals_synop
2435 <refsect1 id="$section_id.description" role="desc">
2436 <title role="desc.title">Description</title>
2437 $extralinks$long_desc
2438 </refsect1>
2439 <refsect1 id="$section_id.details" role="details">
2440 <title role="details.title">Details</title>
2441 $$details
2442 </refsect1>
2443 $$args_desc$$signals_desc$see_also
2444 </refentry>
2446     close (OUTPUT);
2448     return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2452 #############################################################################
2453 # Function    : OutputExtraFile
2454 # Description : Copies an "extra" DocBook file into the output directory,
2455 #               expanding abbreviations
2456 # Arguments   : $file - the source file.
2457 #############################################################################
2458 sub OutputExtraFile {
2459     my ($file) = @_;
2461     my $basename;
2463     ($basename = $file) =~ s!^.*/!!;
2465     my $old_sgml_file = "$SGML_OUTPUT_DIR/$basename";
2466     my $new_sgml_file = "$SGML_OUTPUT_DIR/$basename.new";
2468     my $contents;
2470     open(EXTRA_FILE, "<$file") || die "Can't open $file";
2472     {
2473         local $/;
2474         $contents = <EXTRA_FILE>;
2475     }
2477     open (OUTPUT, ">$new_sgml_file")
2478         || die "Can't create $new_sgml_file: $!";
2480     print OUTPUT &ExpandAbbreviations ("$basename file", $contents);
2481     close (OUTPUT);
2483     return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2485 #############################################################################
2486 # Function    : OutputBook
2487 # Description : Outputs the SGML entities that need to be included into the
2488 #                main SGML file for the module.
2489 # Arguments   : $book_top - the declarations of the entities, which are added
2490 #                  at the top of the main SGML file.
2491 #                $book_bottom - the references to the entities, which are
2492 #                  added in the main SGML file at the desired position.
2493 #############################################################################
2495 sub OutputBook {
2496     my ($book_top, $book_bottom) = @_;
2498     my $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top";
2499     my $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top.new";
2501     open (OUTPUT, ">$new_file")
2502         || die "Can't create $new_file: $!";
2503     print OUTPUT $book_top;
2504     close (OUTPUT);
2506     &UpdateFileIfChanged ($old_file, $new_file, 0);
2509     $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom";
2510     $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom.new";
2512     open (OUTPUT, ">$new_file")
2513         || die "Can't create $new_file: $!";
2514     print OUTPUT $book_bottom;
2515     close (OUTPUT);
2517     &UpdateFileIfChanged ($old_file, $new_file, 0);
2520     # If the main SGML/XML file hasn't been created yet, we create it here.
2521     # The user can tweak it later.
2522     if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
2523       open (OUTPUT, ">$MAIN_SGML_FILE")
2524         || die "Can't create $MAIN_SGML_FILE: $!";
2526       if ($OUTPUT_FORMAT eq "xml") {
2527           print OUTPUT <<EOF;
2528 <?xml version="1.0"?>
2529 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
2530                "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
2532   <!ENTITY % local.common.attrib "xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'">
2534 <book id="index">
2536       } else {
2537         print OUTPUT <<EOF;
2538 <!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
2539 $book_top
2541 <book id="index">
2543       }
2545 print OUTPUT <<EOF;
2546   <bookinfo>
2547     <title>$MODULE Reference Manual</title>
2548     <releaseinfo>
2549       for $MODULE [VERSION].
2550       The latest version of this documentation can be found on-line at
2551       <ulink role="online-location" url="http://[SERVER]/$MODULE/index.html">http://[SERVER]/$MODULE/</ulink>.
2552     </releaseinfo>
2553   </bookinfo>
2555   <chapter>
2556     <title>[Insert title here]</title>
2557     $book_bottom
2558   </chapter>
2560   if (-e $OBJECT_TREE_FILE) {
2561     print OUTPUT <<EOF;
2562   <chapter id="object-tree">
2563     <title>Object Hierarchy</title>
2564      <xi:include href="xml/tree_index.sgml"/>
2565   </chapter>
2567   }
2569 print OUTPUT <<EOF;
2570   <index id="api-index-full">
2571     <title>API Index</title>
2572     <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
2573   </index>
2574   <index id="deprecated-api-index" role="deprecated">
2575     <title>Index of deprecated API</title>
2576     <xi:include href="xml/api-index-deprecated.xml"><xi:fallback /></xi:include>
2577   </index>
2579   <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
2580 </book>
2583       close (OUTPUT);
2584     }
2588 #############################################################################
2589 # Function    : CreateValidSGML
2590 # Description : This turns any chars which are used in SGML into entities,
2591 #                e.g. '<' into '&lt;'
2592 # Arguments   : $text - the text to turn into proper SGML.
2593 #############################################################################
2595 sub CreateValidSGML {
2596     my ($text) = @_;
2597     $text =~ s/&/&amp;/g;        # Do this first, or the others get messed up.
2598     $text =~ s/</&lt;/g;
2599     $text =~ s/>/&gt;/g;
2600     # browers render single tabs inconsistently
2601     $text =~ s/([^\s])\t([^\s])/$1&#160;$2/g;
2602     return $text;
2605 #############################################################################
2606 # Function    : ConvertSGMLChars
2607 # Description : This is used for text in source code comment blocks, to turn
2608 #               chars which are used in SGML into entities, e.g. '<' into
2609 #               '&lt;'. Depending on $INLINE_MARKUP_MODE, this is done
2610 #               unconditionally or only if the character doesn't seem to be
2611 #               part of an SGML construct (tag or entity reference).
2612 # Arguments   : $text - the text to turn into proper SGML.
2613 #############################################################################
2615 sub ConvertSGMLChars {
2616     my ($symbol, $text) = @_;
2618     if ($INLINE_MARKUP_MODE) {
2619         # For the XML/SGML mode only convert to entities outside CDATA sections.
2620         return &ModifyXMLElements ($text, $symbol,
2621                                    "<!\\[CDATA\\[|<programlisting[^>]*>",
2622                                    \&ConvertSGMLCharsEndTag,
2623                                    \&ConvertSGMLCharsCallback);
2624     } else {
2625         # For the simple non-sgml mode, convert to entities everywhere.
2626         $text =~ s/&/&amp;/g;        # Do this first, or the others get messed up.
2627         $text =~ s/</&lt;/g;
2628         $text =~ s/>/&gt;/g;
2629         return $text;
2630     }
2634 sub ConvertSGMLCharsEndTag {
2635   if ($_[0] eq "<!\[CDATA\[") {
2636     return "]]>";
2637   } else {
2638     return "</programlisting>";
2639   }
2642 sub ConvertSGMLCharsCallback {
2643   my ($text, $symbol, $tag) = @_;
2645   if ($tag =~ m/^<programlisting/) {
2646     # We can handle <programlisting> specially here.
2647     return &ModifyXMLElements ($text, $symbol,
2648                                "<!\\[CDATA\\[",
2649                                \&ConvertSGMLCharsEndTag,
2650                                \&ConvertSGMLCharsCallback2);
2651   } elsif ($tag eq "") {
2652     # If we're not in CDATA convert to entities.
2653     $text =~ s/&(?![a-zA-Z#]+;)/&amp;/g;        # Do this first, or the others get messed up.
2654     $text =~ s/<(?![a-zA-Z\/!])/&lt;/g;
2655     $text =~ s/(?<![a-zA-Z0-9"'\/-])>/&gt;/g;
2657     # Handle "#include <xxxxx>"
2658     $text =~ s/#include(\s+)<([^>]+)>/#include$1&lt;$2&gt;/g;
2659   }
2661   return $text;
2664 sub ConvertSGMLCharsCallback2 {
2665   my ($text, $symbol, $tag) = @_;
2667   # If we're not in CDATA convert to entities.
2668   # We could handle <programlisting> differently, though I'm not sure it helps.
2669   if ($tag eq "") {
2670     # replace only if its not a tag
2671     $text =~ s/&(?![a-zA-Z#]+;)/&amp;/g;        # Do this first, or the others get messed up.
2672     $text =~ s/<(?![a-zA-Z\/!])/&lt;/g;
2673     $text =~ s/(?<![a-zA-Z0-9"'\/-])>/&gt;/g;
2675     # Handle "#include <xxxxx>"
2676     $text =~ s/#include(\s+)<([^>]+)>/#include$1&lt;$2&gt;/g;
2677   }
2679   return $text;
2682 #############################################################################
2683 # Function    : ExpandAnnotation
2684 # Description : This turns annotations into acronym tags.
2685 # Arguments   : $symbol - the symbol being documented, for error messages.
2686 #                $text - the text to expand.
2687 #############################################################################
2688 sub ExpandAnnotation {
2689     my ($symbol, $param_desc) = @_;
2690     my $param_annotations = "";
2692     # look for annotations at the start of the comment part
2693     if ($param_desc =~ m%^\s*\((.*?)\):%) {
2694         my @annotations;
2695         my $annotation;
2696         $param_desc = $';
2698         @annotations = split(/\)\s*\(/,$1);
2699         foreach $annotation (@annotations) {
2700             # need to search for the longest key-match in %AnnotationDefinition
2701             my $match_length=0;
2702             my $match_annotation="";
2703             my $annotationdef;
2704             foreach $annotationdef (keys %AnnotationDefinition) {
2705                 if ($annotation =~ m/^$annotationdef/) {
2706                     if (length($annotationdef)>$match_length) {
2707                         $match_length=length($annotationdef);
2708                         $match_annotation=$annotationdef;
2709                     }
2710                 }
2711             }
2712             my $annotation_extra = "";
2713             if ($match_annotation ne "") {
2714                 if ($annotation =~ m%$match_annotation\s+(.*)%) {
2715                     $annotation_extra = " $1";
2716                 }
2717                 $AnnotationsUsed{$match_annotation} = 1;
2718                 $param_annotations .= "[<acronym>$match_annotation</acronym>$annotation_extra]";
2719             }
2720             else {
2721                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2722                     "unknown annotation \"$annotation\" in documentation for $symbol.");
2723                 $param_annotations .= "[$annotation]";
2724             }
2725         }
2726         chomp($param_desc);
2727         $param_desc =~ m/^(.*?)\.*\s*$/s;
2728         $param_desc = "$1. ";
2729     }
2730     if ($param_annotations ne "") {
2731         $param_annotations = "<emphasis role=\"annotation\">$param_annotations</emphasis>";
2732     }
2733     return ($param_desc, $param_annotations);
2736 #############################################################################
2737 # Function    : ExpandAbbreviations
2738 # Description : This turns the abbreviations function(), macro(), @param,
2739 #                %constant, and #symbol into appropriate DocBook markup.
2740 #               CDATA sections and <programlisting> parts are skipped.
2741 # Arguments   : $symbol - the symbol being documented, for error messages.
2742 #                $text - the text to expand.
2743 #############################################################################
2745 sub ExpandAbbreviations {
2746   my ($symbol, $text) = @_;
2748   # Convert "|[" and "]|" into the start and end of program listing examples.
2749   # FIXME: we like to have a way to specify parameters e.g. language="c"
2750   $text =~ s%\|\[%<informalexample><programlisting>%g;
2751   $text =~ s%\]\|%</programlisting></informalexample>%g;
2752   # TODO: check for a xml comment after |[ and pick the language attribute from
2753   # that
2755   # keep CDATA unmodified, preserve ulink tags (ideally we preseve all tags
2756   # as such)
2757   return &ModifyXMLElements ($text, $symbol,
2758                              "<!\\[CDATA\\[|<ulink[^>]*>|<programlisting[^>]*>|<!DOCTYPE",
2759                              \&ExpandAbbreviationsEndTag,
2760                              \&ExpandAbbreviationsCallback);
2764 # Returns the end tag (as a regexp) corresponding to the given start tag.
2765 sub ExpandAbbreviationsEndTag {
2766   my ($start_tag) = @_;
2768   if ($start_tag eq "<!\[CDATA\[") {
2769     return "]]>";
2770   } elsif ($start_tag eq "<!DOCTYPE") {
2771     return ">";
2772   } elsif ($start_tag =~ m/<(\w+)/) {
2773     return "</$1>";
2774   }
2777 # Called inside or outside each CDATA or <programlisting> section.
2778 sub ExpandAbbreviationsCallback {
2779   my ($text, $symbol, $tag) = @_;
2781   if ($tag =~ m/^<programlisting/) {
2782     # Handle any embedded CDATA sections.
2783     return &ModifyXMLElements ($text, $symbol,
2784                                "<!\\[CDATA\\[",
2785                                \&ExpandAbbreviationsEndTag,
2786                                \&ExpandAbbreviationsCallback2);
2787   } elsif ($tag eq "") {
2788     # We are outside any CDATA or <programlisting> sections, so we expand
2789     # any gtk-doc abbreviations.
2791     # Convert '@param()'
2792     # FIXME: we could make those also links ($symbol.$2), but that would be less
2793     # useful as the link target is a few lines up or down
2794     $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)\s*\(\)/$1<parameter>$2()<\/parameter>/g;
2796     # Convert 'function()' or 'macro()'.
2797     # if there is abc_*_def() we don't want to make a link to _def()
2798     # FIXME: also handle abc(def(....)) : but that would need to be done recursively :/
2799     $text =~ s/([^\*.\w])(\w+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2800     # handle #Object.func()
2801     $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2803     # Convert '@param', but not '\@param'.
2804     $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)/$1<parameter>$2<\/parameter>/g;
2805     $text =~ s/\\\@/\@/g;
2807     # Convert '%constant', but not '\%constant'.
2808     # Also allow negative numbers, e.g. %-1.
2809     $text =~ s/(\A|[^\\])\%(-?\w+)/$1.&MakeXRef($2, &tagify($2, "literal"));/eg;
2810     $text =~ s/\\\%/\%/g;
2812     # Convert '#symbol', but not '\#symbol'.
2813     $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)/$1.&MakeHashXRef($2, "type");/eg;
2814     $text =~ s/\\#/#/g;
2816     # Expand urls
2817     # FIXME: should we skip urls that are already tagged? (e.g. <literal>http://...</literal>)
2818     # this is apparently also called for markup and not just for plain text
2819     # disable for now.
2820     #$text =~ s%(http|https|ftp)://(.*?)((?:\s|,|\)|\]|\<|\.\s))%<ulink url="$1://$2">$2</ulink>$3%g;
2822     # TODO: optionally check all words from $text against internal symbols and
2823     # warn if those could be xreffed, but miss a %,# or ()
2824   }
2826   return $text;
2829 # This is called inside a <programlisting>
2830 sub ExpandAbbreviationsCallback2 {
2831   my ($text, $symbol, $tag) = @_;
2833   if ($tag eq "") {
2834     # We are inside a <programlisting> but outside any CDATA sections,
2835     # so we expand any gtk-doc abbreviations.
2836     # FIXME: why is this different from &ExpandAbbreviationsCallback(),
2837     #        why not just call it
2838     $text =~ s/#(\w+)/&MakeHashXRef($1, "");/eg;
2839   }
2841   return $text;
2844 sub MakeHashXRef {
2845     my ($symbol, $tag) = @_;;
2846     my $text = $symbol;
2848     # Check for things like '#include', '#define', and skip them.
2849     if ($PreProcessorDirectives{$symbol}) {
2850       return "#$symbol";
2851     }
2853     # Get rid of special suffixes ('-struct','-enum').
2854     $text =~ s/-struct$//;
2855     $text =~ s/-enum$//;
2857     # If the symbol is in the form "Object::signal", then change the symbol to
2858     # "Object-signal" and use "signal" as the text.
2859     if ($symbol =~ s/::/-/) {
2860       $text = "\"$'\"";
2861     }
2863     # If the symbol is in the form "Object:property", then change the symbol to
2864     # "Object--property" and use "property" as the text.
2865     if ($symbol =~ s/:/--/) {
2866       $text = "\"$'\"";
2867     }
2869     if ($tag ne "") {
2870       $text = tagify ($text, $tag);
2871     }
2873     return &MakeXRef($symbol, $text);
2877 #############################################################################
2878 # Function    : ModifyXMLElements
2879 # Description : Looks for given XML element tags within the text, and calls
2880 #               the callback on pieces of text inside & outside those elements.
2881 #               Used for special handling of text inside things like CDATA
2882 #               and <programlisting>.
2883 # Arguments   : $text - the text.
2884 #               $symbol - the symbol currently being documented (only used for
2885 #                      error messages).
2886 #               $start_tag_regexp - the regular expression to match start tags.
2887 #                      e.g. "<!\\[CDATA\\[|<programlisting[^>]*>" to match
2888 #                      CDATA sections or programlisting elements.
2889 #               $end_tag_func - function which is passed the matched start tag
2890 #                      and should return the appropriate end tag string regexp.
2891 #               $callback - callback called with each part of the text. It is
2892 #                      called with a piece of text, the symbol being
2893 #                      documented, and the matched start tag or "" if the text
2894 #                      is outside the XML elements being matched.
2895 #############################################################################
2896 sub ModifyXMLElements {
2897     my ($text, $symbol, $start_tag_regexp, $end_tag_func, $callback) = @_;
2898     my ($before_tag, $start_tag, $end_tag_regexp, $end_tag);
2899     my $result = "";
2901     while ($text =~ m/$start_tag_regexp/s) {
2902       $before_tag = $`; # Prematch for last successful match string
2903       $start_tag = $&;  # Last successful match
2904       $text = $';       # Postmatch for last successful match string
2906       $result .= &$callback ($before_tag, $symbol, "");
2907       $result .= $start_tag;
2909       # get the matching end-tag for current tag
2910       $end_tag_regexp = &$end_tag_func ($start_tag);
2912       if ($text =~ m/$end_tag_regexp/s) {
2913         $before_tag = $`;
2914         $end_tag = $&;
2915         $text = $';
2917         $result .= &$callback ($before_tag, $symbol, $start_tag);
2918         $result .= $end_tag;
2919       } else {
2920         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2921             "Can't find tag end: $end_tag_regexp in docs for: $symbol.");
2922         # Just assume it is all inside the tag.
2923         $result .= &$callback ($text, $symbol, $start_tag);
2924         $text = "";
2925       }
2926     }
2928     # Handle any remaining text outside the tags.
2929     $result .= &$callback ($text, $symbol, "");
2931     return $result;
2934 sub noop {
2935   return $_[0];
2938 # Adds a tag around some text.
2939 # e.g tagify("Text", "literal") => "<literal>Text</literal>".
2940 sub tagify {
2941    my ($text, $elem) = @_;
2942    return "<" . $elem . ">" . $text . "</" . $elem . ">";
2946 #############################################################################
2947 # Function    : MakeXRef
2948 # Description : This returns a cross-reference link to the given symbol.
2949 #                Though it doesn't try to do this for a few standard C types
2950 #                that it        knows won't be in the documentation.
2951 # Arguments   : $symbol - the symbol to try to create a XRef to.
2952 #               $text - text text to put inside the XRef, defaults to $symbol
2953 #############################################################################
2955 sub MakeXRef {
2956     my ($symbol, $text) = ($_[0], $_[1]);
2958     $symbol =~ s/^\s+//;
2959     $symbol =~ s/\s+$//;
2961     if (!defined($text)) {
2962         $text = $symbol;
2964         # Get rid of special suffixes ('-struct','-enum').
2965         $text =~ s/-struct$//;
2966         $text =~ s/-enum$//;
2967     }
2969     if ($symbol =~ m/ /) {
2970         return "$text";
2971     }
2973     #print "Getting type link for $symbol -> $text\n";
2975     my $symbol_id = &CreateValidSGMLID ($symbol);
2976     return "<link linkend=\"$symbol_id\">$text</link>";
2980 #############################################################################
2981 # Function    : MakeIndexterms
2982 # Description : This returns a indexterm elements for the given symbol
2983 # Arguments   : $symbol - the symbol to create indexterms for
2984 #############################################################################
2986 sub MakeIndexterms {
2987   my ($symbol, $id) = @_;
2988   my $terms =  "";
2989   my $sortas = "";
2991   # make the index useful, by ommiting the namespace when sorting
2992   if ($NAME_SPACE ne "") {
2993     if ($symbol =~ m/^$NAME_SPACE\_?(.*)/i) {
2994        $sortas=" sortas=\"$1\"";
2995     }
2996   }
2998   if (exists $Deprecated{$symbol}) {
2999       $terms .= "<indexterm zone=\"$id\" role=\"deprecated\"><primary$sortas>$symbol</primary></indexterm>";
3000       $IndexEntriesDeprecated{$symbol}=$id;
3001       $IndexEntriesFull{$symbol}=$id;
3002   }
3003   if (exists $Since{$symbol}) {
3004      my $since = $Since{$symbol};
3005      $since =~ s/^\s+//;
3006      $since =~ s/\s+$//;
3007      if ($since ne "") {
3008          $terms .= "<indexterm zone=\"$id\" role=\"$since\"><primary$sortas>$symbol</primary></indexterm>";
3009      }
3010      $IndexEntriesSince{$symbol}=$id;
3011      $IndexEntriesFull{$symbol}=$id;
3012   }
3013   if ($terms eq "") {
3014      $terms .= "<indexterm zone=\"$id\"><primary$sortas>$symbol</primary></indexterm>";
3015      $IndexEntriesFull{$symbol}=$id;
3016   }
3018   return $terms;
3021 #############################################################################
3022 # Function    : MakeDeprecationNote
3023 # Description : This returns a deprecation warning for the given symbol.
3024 # Arguments   : $symbol - the symbol to try to create a warning for.
3025 #############################################################################
3027 sub MakeDeprecationNote {
3028     my ($symbol) = $_[0];
3029     my $desc = "";
3030     my $note = "";
3031     if (exists $Deprecated{$symbol}) {
3032         $desc .= "<warning>";
3034         if ($Deprecated{$symbol} =~ /^\s*([0-9\.]+)\s*:/) {
3035                 $desc .= "<para><literal>$symbol</literal> has been deprecated since version $1 and should not be used in newly-written code.";
3036         } else {
3037                 $desc .= "<para><literal>$symbol</literal> is deprecated and should not be used in newly-written code.";
3038         }
3039         if ($Deprecated{$symbol} ne "") {
3040             $note = &ExpandAbbreviations($symbol, $Deprecated{$symbol});
3041             $note =~ s/^\s*([0-9\.]+)\s*:\s*//;
3042             $note =~ s/^\s+//;
3043             $note =~ s/\s+$//;
3044             $note =~ s%\n{2,}%\n</para>\n<para>\n%g;
3045             $desc .= " " . $note;
3046         }
3047         $desc .= "</para></warning>\n";
3048     }
3049     return $desc;
3052 #############################################################################
3053 # Function    : MakeConditionDescription
3054 # Description : This returns a sumary of conditions for the given symbol.
3055 # Arguments   : $symbol - the symbol to try to create the sumary.
3056 #############################################################################
3058 sub MakeConditionDescription {
3059     my ($symbol) = $_[0];
3060     my $desc = "";
3062     if (exists $Deprecated{$symbol}) {
3063         if ($desc ne "") {
3064             $desc .= "|";
3065         }
3067         if ($Deprecated{$symbol} =~ /^\s*(.*?)\s*$/) {
3068                 $desc .= "deprecated:$1";
3069         } else {
3070                 $desc .= "deprecated";
3071         }
3072     }
3074     if (exists $Since{$symbol}) {
3075         if ($desc ne "") {
3076             $desc .= "|";
3077         }
3079         if ($Since{$symbol} =~ /^\s*(.*?)\s*$/) {
3080                 $desc .= "since:$1";
3081         } else {
3082                 $desc .= "since";
3083         }
3084     }
3086     if (exists $StabilityLevel{$symbol}) {
3087         if ($desc ne "") {
3088             $desc .= "|";
3089         }
3090         $desc .= "stability:".$StabilityLevel{$symbol};
3091     }
3093     if ($desc ne "") {
3094         $desc=" condition=\"".$desc."\"";
3095         #print "condition for '$symbol' = '$desc'\n";
3096     }
3097     return $desc;
3100 #############################################################################
3101 # Function    : GetHierarchy
3102 # Description : Returns the DocBook output describing the ancestors and
3103 #               immediate children of a GObject subclass. It uses the
3104 #               global @Objects and @ObjectLevels arrays to walk the tree.
3105 # Arguments   : $object - the GtkObject subclass.
3106 #############################################################################
3108 sub GetHierarchy {
3109     my ($object) = @_;
3111     # Find object in the objects array.
3112     my $found = 0;
3113     my @children = ();
3114     my $i;
3115     my $level;
3116     my $j;
3117     for ($i = 0; $i < @Objects; $i++) {
3118         if ($found) {
3119             if ($ObjectLevels[$i] <= $level) {
3120             last;
3121         }
3122             elsif ($ObjectLevels[$i] == $level + 1) {
3123                 push (@children, $Objects[$i]);
3124             }
3125         }
3126         elsif ($Objects[$i] eq $object) {
3127             $found = 1;
3128             $j = $i;
3129             $level = $ObjectLevels[$i];
3130         }
3131     }
3132     if (!$found) {
3133         return "";
3134     }
3136     # Walk up the hierarchy, pushing ancestors onto the ancestors array.
3137     my @ancestors = ();
3138     push (@ancestors, $object);
3139     #print "Level: $level\n";
3140     while ($level > 1) {
3141         $j--;
3142         if ($ObjectLevels[$j] < $level) {
3143             push (@ancestors, $Objects[$j]);
3144             $level = $ObjectLevels[$j];
3145             #print "Level: $level\n";
3146         }
3147     }
3149     # Output the ancestors list, indented and with links.
3150     my $hierarchy = "<synopsis>\n";
3151     $level = 0;
3152     for ($i = $#ancestors; $i >= 0; $i--) {
3153         my $link_text;
3154         # Don't add a link to the current object, i.e. when i == 0.
3155         if ($i > 0) {
3156             my $ancestor_id = &CreateValidSGMLID ($ancestors[$i]);
3157             $link_text = "<link linkend=\"$ancestor_id\">$ancestors[$i]</link>";
3158         } else {
3159             $link_text = "$ancestors[$i]";
3160         }
3161         if ($level == 0) {
3162             $hierarchy .= "  $link_text\n";
3163         } else {
3164 #            $hierarchy .= ' ' x ($level * 6 - 3) . "|\n";
3165             $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3166         }
3167         $level++;
3168     }
3169     for ($i = 0; $i <= $#children; $i++) {
3170       my $id = &CreateValidSGMLID ($children[$i]);
3171       my $link_text = "<link linkend=\"$id\">$children[$i]</link>";
3172       $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3173     }
3174     $hierarchy .= "</synopsis>\n";
3176     return $hierarchy;
3180 #############################################################################
3181 # Function    : GetInterfaces
3182 # Description : Returns the DocBook output describing the interfaces
3183 #               implemented by a class. It uses the global %Interfaces hash.
3184 # Arguments   : $object - the GtkObject subclass.
3185 #############################################################################
3187 sub GetInterfaces {
3188     my ($object) = @_;
3189     my $text = "";
3190     my $i;
3192     # Find object in the objects array.
3193     if (exists($Interfaces{$object})) {
3194         my @ifaces = split(' ', $Interfaces{$object});
3195         $text = <<EOF;
3196 <para>
3197 $object implements
3199         for ($i = 0; $i <= $#ifaces; $i++) {
3200             my $id = &CreateValidSGMLID ($ifaces[$i]);
3201             $text .= " <link linkend=\"$id\">$ifaces[$i]</link>";
3202             if ($i < $#ifaces - 1) {
3203                 $text .= ', ';
3204             }
3205             elsif ($i < $#ifaces) {
3206                 $text .= ' and ';
3207             }
3208             else {
3209                 $text .= '.';
3210             }
3211         }
3212         $text .= <<EOF;
3213 </para>
3215     }
3217     return $text;
3220 #############################################################################
3221 # Function    : GetImplementations
3222 # Description : Returns the DocBook output describing the implementations
3223 #               of an interface. It uses the global %Interfaces hash.
3224 # Arguments   : $object - the GtkObject subclass.
3225 #############################################################################
3227 sub GetImplementations {
3228     my ($object) = @_;
3229     my @impls = ();
3230     my $text = "";
3231     my $i;
3232     foreach my $key (keys %Interfaces) {
3233         if ($Interfaces{$key} =~ /\b$object\b/) {
3234             push (@impls, $key);
3235         }
3236     }
3237     if ($#impls >= 0) {
3238         @impls = sort @impls;
3239         $text = <<EOF;
3240 <para>
3241 $object is implemented by
3243         for ($i = 0; $i <= $#impls; $i++) {
3244             my $id = &CreateValidSGMLID ($impls[$i]);
3245             $text .= " <link linkend=\"$id\">$impls[$i]</link>";
3246             if ($i < $#impls - 1) {
3247                 $text .= ', ';
3248             }
3249             elsif ($i < $#impls) {
3250                 $text .= ' and ';
3251             }
3252             else {
3253                 $text .= '.';
3254             }
3255         }
3256         $text .= <<EOF;
3257 </para>
3259     }
3260     return $text;
3264 #############################################################################
3265 # Function    : GetPrerequisites
3266 # Description : Returns the DocBook output describing the prerequisites
3267 #               of an interface. It uses the global %Prerequisites hash.
3268 # Arguments   : $iface - the interface.
3269 #############################################################################
3271 sub GetPrerequisites {
3272     my ($iface) = @_;
3273     my $text = "";
3274     my $i;
3276     if (exists($Prerequisites{$iface})) {
3277         $text = <<EOF;
3278 <para>
3279 $iface requires
3281         my @prereqs = split(' ', $Prerequisites{$iface});
3282         for ($i = 0; $i <= $#prereqs; $i++) {
3283             my $id = &CreateValidSGMLID ($prereqs[$i]);
3284             $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
3285             if ($i < $#prereqs - 1) {
3286                 $text .= ', ';
3287             }
3288             elsif ($i < $#prereqs) {
3289                 $text .= ' and ';
3290             }
3291             else {
3292                 $text .= '.';
3293             }
3294         }
3295         $text .= <<EOF;
3296 </para>
3298     }
3299     return $text;
3302 #############################################################################
3303 # Function    : GetDerived
3304 # Description : Returns the DocBook output describing the derived interfaces
3305 #               of an interface. It uses the global %Prerequisites hash.
3306 # Arguments   : $iface - the interface.
3307 #############################################################################
3309 sub GetDerived {
3310     my ($iface) = @_;
3311     my $text = "";
3312     my $i;
3314     my @derived = ();
3315     foreach my $key (keys %Prerequisites) {
3316         if ($Prerequisites{$key} =~ /\b$iface\b/) {
3317             push (@derived, $key);
3318         }
3319     }
3320     if ($#derived >= 0) {
3321         @derived = sort @derived;
3322         $text = <<EOF;
3323 <para>
3324 $iface is required by
3326         for ($i = 0; $i <= $#derived; $i++) {
3327             my $id = &CreateValidSGMLID ($derived[$i]);
3328             $text .= " <link linkend=\"$id\">$derived[$i]</link>";
3329             if ($i < $#derived - 1) {
3330                 $text .= ', ';
3331             }
3332             elsif ($i < $#derived) {
3333                 $text .= ' and ';
3334             }
3335             else {
3336                 $text .= '.';
3337             }
3338         }
3339         $text .= <<EOF;
3340 </para>
3342     }
3343     return $text;
3347 #############################################################################
3348 # Function    : GetSignals
3349 # Description : Returns the synopsis and detailed description DocBook output
3350 #                for the signal handlers of a given GtkObject subclass.
3351 # Arguments   : $object - the GtkObject subclass, e.g. 'GtkButton'.
3352 #############################################################################
3354 sub GetSignals {
3355     my ($object) = @_;
3356     my $synop = "";
3357     my $desc = "";
3359     my $i;
3360     for ($i = 0; $i <= $#SignalObjects; $i++) {
3361         if ($SignalObjects[$i] eq $object) {
3362             #print "Found signal: $SignalNames[$i]\n";
3363             my $name = $SignalNames[$i];
3364             my $symbol = "${object}::${name}";
3365             my $id = &CreateValidSGMLID ("$object-$name");
3367             my $pad = ' ' x (46 - length($name));
3368             $synop .= "  &quot;<link linkend=\"$id\">$name</link>&quot;$pad ";
3370             $desc .= "<refsect2 id=\"$id\" role=\"signal\"><title>The <literal>&quot;$name&quot;</literal> signal</title>\n";
3371             $desc .= MakeIndexterms($symbol, $id);
3372             $desc .= "\n";
3373             $desc .= OutputSymbolExtraLinks($symbol);
3375             $desc .= "<programlisting>";
3377             $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
3378             my $type_modifier = defined($1) ? $1 : "";
3379             my $type = $2;
3380             my $pointer = $3;
3381             my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
3383             my $ret_type_len = length ($type_modifier) + length ($pointer)
3384                 + length ($type);
3385             my $ret_type_output = "$type_modifier$xref$pointer"
3386                 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
3388             $desc  .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
3390             my $sourceparams = $SourceSymbolParams{$symbol};
3391             my @params = split ("\n", $SignalPrototypes[$i]);
3392             my $j;
3393             my $l;
3394             my $type_len = length("gpointer");
3395             my $name_len = length("user_data");
3396             # do two passes, the first one is to calculate padding
3397             for ($l = 0; $l < 2; $l++) {
3398                 for ($j = 0; $j <= $#params; $j++) {
3399                     # allow alphanumerics, '_', '[' & ']' in param names
3400                     if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
3401                         $type = $1;
3402                         $pointer = $2;
3403                         if (defined($sourceparams)) {
3404                             $name = $$sourceparams[$PARAM_FIELD_COUNT * $j];
3405                         }
3406                         else {
3407                             $name = $3;
3408                         }
3409                         if (!defined($name)) {
3410                             $name = "arg$j";
3411                         }
3412                         if ($l == 0) {
3413                             if (length($type) + length($pointer) > $type_len) {
3414                                 $type_len = length($type) + length($pointer);
3415                             }
3416                             if (length($name) > $name_len) {
3417                                 $name_len = length($name);
3418                             }
3419                         }
3420                         else {
3421                             $xref = &MakeXRef ($type, &tagify($type, "type"));
3422                             $pad = ' ' x ($type_len - length($type) - length($pointer));
3423                             $desc .= "$xref$pad $pointer$name,\n";
3424                             $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
3425                         }
3426                     } else {
3427                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3428                              "Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]");
3429                     }
3430                 }
3431             }
3432             $xref = &MakeXRef ("gpointer", &tagify("gpointer", "type"));
3433             $pad = ' ' x ($type_len - length("gpointer"));
3434             $desc  .= "$xref$pad user_data)";
3436             my $flags = $SignalFlags[$i];
3437             my $flags_string = "";
3439             if (defined ($flags)) {
3440               if ($flags =~ m/f/) {
3441                 $flags_string = "<link linkend=\"G-SIGNAL-RUN-FIRST:CAPS\"><literal>Run First</literal></link>";
3442               }
3443               elsif ($flags =~ m/l/) {
3444                 $flags_string = "<link linkend=\"G-SIGNAL-RUN-LAST:CAPS\"><literal>Run Last</literal></link>";
3445               }
3446               elsif ($flags =~ m/c/) {
3447                 $flags_string = "<link linkend=\"G-SIGNAL-RUN-CLEANUP:CAPS\"><literal>Cleanup</literal></link>";
3448                 $flags_string = "Cleanup";
3449               }
3450               if ($flags =~ m/r/) {
3451                 if ($flags_string) { $flags_string .= " / "; }
3452                 $flags_string = "<link linkend=\"G-SIGNAL-NO-RECURSE:CAPS\"><literal>No Recursion</literal></link>";
3453               }
3454               if ($flags =~ m/d/) {
3455                 if ($flags_string) { $flags_string .= " / "; }
3456                 $flags_string = "<link linkend=\"G-SIGNAL-DETAILED:CAPS\"><literal>Has Details</literal></link>";
3457               }
3458               if ($flags =~ m/a/) {
3459                 if ($flags_string) { $flags_string .= " / "; }
3460                 $flags_string = "<link linkend=\"G-SIGNAL-ACTION:CAPS\"><literal>Action</literal></link>";
3461               }
3462               if ($flags =~ m/h/) {
3463                 if ($flags_string) { $flags_string .= " / "; }
3464                 $flags_string = "<link linkend=\"G-SIGNAL-NO-HOOKS:CAPS\"><literal>No Hooks</literal></link>";
3465               }
3466             }
3468             if ($flags_string)
3469               {
3470                 $synop .= ": $flags_string\n";
3472                 $pad = ' ' x (5 + $name_len - length("user_data"));
3473                 $desc  .= "$pad : $flags_string</programlisting>\n";
3474               }
3475             else
3476               {
3477                 $synop .= "\n";
3478                 $desc  .= "</programlisting>\n";
3479               }
3481             $desc .= &MakeDeprecationNote($symbol);
3483             my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
3484             my $parameters_output = 0;
3486             $AllSymbols{$symbol} = 1;
3487             if (defined ($SymbolDocs{$symbol})) {
3488                 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3490                 # Try to insert the parameter table at the author's desired
3491                 # position. Otherwise we need to tag it onto the end.
3492                 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
3493                   $parameters_output = 1;
3494                 }
3495                 $desc .= $symbol_docs;
3497                 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
3498                     $AllDocumentedSymbols{$symbol} = 1;
3499                 }
3500             }
3502             if ($parameters_output == 0) {
3503                 $desc .= $parameters;
3504               }
3505             $desc .= OutputSymbolTraits ($symbol);
3506             $desc .= "</refsect2>";
3507         }
3508     }
3509     return ($synop, $desc);
3513 #############################################################################
3514 # Function    : GetArgs
3515 # Description : Returns the synopsis and detailed description DocBook output
3516 #                for the Args of a given GtkObject subclass.
3517 # Arguments   : $object - the GtkObject subclass, e.g. 'GtkButton'.
3518 #############################################################################
3520 sub GetArgs {
3521     my ($object) = @_;
3522     my $synop = "";
3523     my $desc = "";
3524     my $child_synop = "";
3525     my $child_desc = "";
3526     my $style_synop = "";
3527     my $style_desc = "";
3529     my $i;
3530     for ($i = 0; $i <= $#ArgObjects; $i++) {
3531         if ($ArgObjects[$i] eq $object) {
3532             #print "Found arg: $ArgNames[$i]\n";
3533             my $name = $ArgNames[$i];
3534             my $flags = $ArgFlags[$i];
3535             my $flags_string = "";
3536             my $kind = "";
3537             my $id_sep = "";
3539             if ($flags =~ m/c/) {
3540                 $kind = "child property";
3541                 $id_sep = "c-";
3542             }
3543             elsif ($flags =~ m/s/) {
3544                 $kind = "style property";
3545                 $id_sep = "s-";
3546             }
3547             else {
3548                 $kind = "property";
3549             }
3551             # Remember only one colon so we don't clash with signals.
3552             my $symbol = "${object}:${name}";
3553             # use two dashes and ev. an extra separator here for the same reason.
3554             my $id = &CreateValidSGMLID ("$object--$id_sep$name");
3556             my $type = $ArgTypes[$i];
3557             my $type_output;
3558             my $range = $ArgRanges[$i];
3559             my $range_output = CreateValidSGML ($range);
3560             my $default = $ArgDefaults[$i];
3561             my $default_output = CreateValidSGML ($default);
3563             if ($type eq "GtkString") {
3564                 $type = "char*";
3565             }
3566             if ($type eq "GtkSignal") {
3567                 $type = "GtkSignalFunc, gpointer";
3568                 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
3569                     . &MakeXRef ("gpointer");
3570             } elsif ($type =~ m/^(\w+)\*$/) {
3571                 $type_output = &MakeXRef ($1, &tagify($1, "type")) . "*";
3572             } else {
3573                 $type_output = &MakeXRef ($type, &tagify($type, "type"));
3574             }
3576             if ($flags =~ m/r/) {
3577                 $flags_string = "Read";
3578             }
3579             if ($flags =~ m/w/) {
3580                 if ($flags_string) { $flags_string .= " / "; }
3581                 $flags_string .= "Write";
3582             }
3583             if ($flags =~ m/x/) {
3584                 if ($flags_string) { $flags_string .= " / "; }
3585                 $flags_string .= "Construct";
3586             }
3587             if ($flags =~ m/X/) {
3588                 if ($flags_string) { $flags_string .= " / "; }
3589                 $flags_string .= "Construct Only";
3590             }
3592             $AllSymbols{$symbol} = 1;
3593             my $blurb;
3594             if (defined($SymbolDocs{$symbol}) &&
3595                 !IsEmptyDoc($SymbolDocs{$symbol})) {
3596                 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3597                 #print ".. [$SymbolDocs{$symbol}][$blurb]\n";
3598                 $AllDocumentedSymbols{$symbol} = 1;
3599             }
3600             else {
3601                 if (!($ArgBlurbs[$i] eq "")) {
3602                     $AllDocumentedSymbols{$symbol} = 1;
3603                 } else {
3604                     # FIXME: print a warning?
3605                     #print ".. no description\n";
3606                 }
3607                 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
3608             }
3610             my $pad1 = " " x (24 - length ($name));
3611             my $pad2 = " " x (20 - length ($type));
3613              my $arg_synop = "  &quot;<link linkend=\"$id\">$name</link>&quot;$pad1 $type_output $pad2 : $flags_string\n";
3614             my $arg_desc = "<refsect2 id=\"$id\" role=\"property\"><title>The <literal>&quot;$name&quot;</literal> $kind</title>\n";
3615             $arg_desc .= MakeIndexterms($symbol, $id);
3616             $arg_desc .= "\n";
3617             $arg_desc .= OutputSymbolExtraLinks($symbol);
3619             $arg_desc .= "<programlisting>  &quot;$name&quot;$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
3620             $arg_desc .= &MakeDeprecationNote($symbol);
3621             $arg_desc .= $blurb;
3622             if ($range ne "") {
3623                 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
3624             }
3625             if ($default ne "") {
3626                 $arg_desc .= "<para>Default value: $default_output</para>\n";
3627             }
3628             $arg_desc .= OutputSymbolTraits ($symbol);
3629             $arg_desc .= "</refsect2>\n";
3631             if ($flags =~ m/c/) {
3632                 $child_synop .= $arg_synop;
3633                 $child_desc .= $arg_desc;
3634             }
3635             elsif ($flags =~ m/s/) {
3636                 $style_synop .= $arg_synop;
3637                 $style_desc .= $arg_desc;
3638             }
3639             else {
3640                 $synop .= $arg_synop;
3641                 $desc .= $arg_desc;
3642             }
3643         }
3644     }
3645     return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
3649 #############################################################################
3650 # Function    : ReadSourceDocumentation
3651 # Description : This reads in the documentation embedded in comment blocks
3652 #                in the source code (for Gnome).
3654 #                Parameter descriptions override any in the template files.
3655 #                Function descriptions are placed before any description from
3656 #                the template files.
3658 #                It recursively descends the source directory looking for .c
3659 #                files and scans them looking for specially-formatted comment
3660 #                blocks.
3662 # Arguments   : $source_dir - the directory to scan.
3663 #############m###############################################################
3665 sub ReadSourceDocumentation {
3666     my ($source_dir) = @_;
3667     my ($file, $dir, @suffix_list, $suffix);
3669     # prepend entries from @SOURCE_DIR
3670     for my $dir (@SOURCE_DIRS) {
3671         # Check if the filename is in the ignore list.
3672         if ($source_dir =~ m%^\Q$dir\E/(.*)$% and $IGNORE_FILES =~ m/(\s|^)\Q$1\E(\s|$)/) {
3673             @TRACE@("Skipping source directory: $source_dir");
3674             return;
3675         }
3676     }
3678     @TRACE@("Scanning source directory: $source_dir");
3680     # This array holds any subdirectories found.
3681     my (@subdirs) = ();
3683     @suffix_list = split (/,/, $SOURCE_SUFFIXES);
3685     opendir (SRCDIR, $source_dir)
3686         || die "Can't open source directory $source_dir: $!";
3688     foreach $file (readdir (SRCDIR)) {
3689       if ($file =~ /^\./) {
3690         next;
3691       } elsif (-d "$source_dir/$file") {
3692         push (@subdirs, $file);
3693       } elsif (@suffix_list) {
3694         foreach $suffix (@suffix_list) {
3695           if ($file =~ m/\.\Q${suffix}\E$/) {
3696             &ScanSourceFile ("$source_dir/$file");
3697           }
3698         }
3699       } elsif ($file =~ m/\.[ch]$/) {
3700         &ScanSourceFile ("$source_dir/$file");
3701       }
3702     }
3703     closedir (SRCDIR);
3705     # Now recursively scan the subdirectories.
3706     foreach $dir (@subdirs) {
3707         &ReadSourceDocumentation ("$source_dir/$dir");
3708     }
3712 #############################################################################
3713 # Function    : ScanSourceFile
3714 # Description : Scans one source file looking for specially-formatted comment
3715 #                blocks. Later &MergeSourceDocumentation is used to merge any
3716 #                documentation found with the documentation already read in
3717 #                from the template files.
3719 # Arguments   : $file - the file to scan.
3720 #############################################################################
3722 sub ScanSourceFile {
3723     my ($file) = @_;
3724     my $basename;
3726     # prepend entries from @SOURCE_DIR
3727     for my $dir (@SOURCE_DIRS) {
3728         # Check if the filename is in the ignore list.
3729         if ($file =~ m%^\Q$dir\E/(.*)$% and $IGNORE_FILES =~ m/(\s|^)\Q$1\E(\s|$)/) {
3730             @TRACE@("Skipping source file: $file");
3731             return;
3732         }
3733     }
3735     if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
3736         $basename = $1;
3737     } else {
3738         &LogWarning ($file, 1, "Can't find basename for this filename.");
3739         $basename = $file;
3740     }
3742     # Check if the basename is in the list of files to ignore.
3743     if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
3744         @TRACE@("Skipping source file: $file");
3745         return;
3746     }
3748     @TRACE@("Scanning source file: $file");
3750     open (SRCFILE, $file)
3751         || die "Can't open $file: $!";
3752     my $in_comment_block = 0;
3753     my $symbol;
3754     my $in_part = "";
3755     my ($description, $return_desc, $return_start, $return_style);
3756     my ($since_desc, $stability_desc, $deprecated_desc);
3757     my $current_param;
3758     my $ignore_broken_returns;
3759     my @params;
3760     while (<SRCFILE>) {
3761         # Look for the start of a comment block.
3762         if (!$in_comment_block) {
3763             if (m%^\s*/\*.*\*/%) {
3764                 #one-line comment - not gtkdoc
3765             } elsif (m%^\s*/\*\*\s%) {
3766                 #print "Found comment block start\n";
3768                 $in_comment_block = 1;
3770                 # Reset all the symbol data.
3771                 $symbol = "";
3772                 $in_part = "";
3773                 $description = "";
3774                 $return_desc = "";
3775                 $return_style = "";
3776                 $since_desc = "";
3777                 $deprecated_desc = "";
3778                 $stability_desc = "";
3779                 $current_param = -1;
3780                 $ignore_broken_returns = 0;
3781                 @params = ();
3782             }
3783             next;
3784         }
3786         # We're in a comment block. Check if we've found the end of it.
3787         if (m%^\s*\*+/%) {
3788             if (!$symbol) {
3789                 # maybe its not even meant to be a gtk-doc comment?
3790                 &LogWarning ($file, $., "Symbol name not found at the start of the comment block.");
3791             } else {
3792                 # Add the return value description onto the end of the params.
3793                 if ($return_desc) {
3794                     push (@params, "Returns");
3795                     push (@params, $return_desc);
3796                     if ($return_style eq 'broken') {
3797                         &LogWarning ($file, $., "Free-form return value description in $symbol. Use `Returns:' to avoid ambiguities.");
3798                     }
3799                 }
3800                 # Convert special SGML characters
3801                 $description = &ConvertSGMLChars ($symbol, $description);
3802                 my $k;
3803                 for ($k = 1; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3804                     $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
3805                 }
3807                 # Handle Section docs
3808                 if ($symbol =~ m/SECTION:\s*(.*)/) {
3809                     my $real_symbol=$1;
3810                     my $key;
3812                     if (scalar %KnownSymbols) {
3813                         if ((! defined($KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"})) || $KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"} != 1) {
3814                             &LogWarning ($file, $., "Section $real_symbol is not defined in the $MODULE-section.txt file.");
3815                         }
3816                     }
3818                     #print "SECTION DOCS found in source for : '$real_symbol'\n";
3819                     $ignore_broken_returns = 1;
3820                     for ($k = 0; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3821                         #print "   '".$params[$k]."'\n";
3822                         $params[$k] = "\L$params[$k]";
3823                         undef $key;
3824                         if ($params[$k] eq "short_description") {
3825                             $key = "$TMPL_DIR/$real_symbol:Short_Description";
3826                         } elsif ($params[$k] eq "see_also") {
3827                             $key = "$TMPL_DIR/$real_symbol:See_Also";
3828                         } elsif ($params[$k] eq "title") {
3829                             $key = "$TMPL_DIR/$real_symbol:Title";
3830                         } elsif ($params[$k] eq "stability") {
3831                             $key = "$TMPL_DIR/$real_symbol:Stability_Level";
3832                         } elsif ($params[$k] eq "section_id") {
3833                             $key = "$TMPL_DIR/$real_symbol:Section_Id";
3834                         } elsif ($params[$k] eq "include") {
3835                             $key = "$TMPL_DIR/$real_symbol:Include";
3836                         } elsif ($params[$k] eq "image") {
3837                             $key = "$TMPL_DIR/$real_symbol:Image";
3838                         }
3839                         if (defined($key)) {
3840                             $SourceSymbolDocs{$key}=$params[$k+1];
3841                             $SourceSymbolSourceFile{$key} = $file;
3842                             $SourceSymbolSourceLine{$key} = $.;
3843                         }
3844                     }
3845                     $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
3846                     $SourceSymbolSourceFile{"$TMPL_DIR/$real_symbol:Long_Description"} = $file;
3847                     $SourceSymbolSourceLine{"$TMPL_DIR/$real_symbol:Long_Description"} = $.;
3848                     #$SourceSymbolTypes{$symbol} = "SECTION";
3849                 } else {
3850                     #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
3851                     $SourceSymbolDocs{$symbol} = $description;
3852                     $SourceSymbolParams{$symbol} = [ @params ];
3853                     # FIXME $SourceSymbolTypes{$symbol} = "STRUCT,SIGNAL,ARG,FUNCTION,MACRO";
3854                     #if (defined $DeclarationTypes{$symbol}) {
3855                     #    $SourceSymbolTypes{$symbol} = $DeclarationTypes{$symbol}
3856                     #}
3857                     $SourceSymbolSourceFile{$symbol} = $file;
3858                     $SourceSymbolSourceLine{$symbol} = $.;
3859                 }
3861                 if ($since_desc) {
3862                      ($since_desc, my @extra_lines) = split ("\n", $since_desc);
3863                      $since_desc =~ s/^\s+//;
3864                      $since_desc =~ s/\s+$//;
3865                      #print "Since($symbol) : [$since_desc]\n";
3866                      $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
3867                      if(scalar @extra_lines) {
3868                          &LogWarning ($file, $., "multi-line since docs found");
3869                      }
3870                 }
3872                 if ($stability_desc) {
3873                     $stability_desc = &ParseStabilityLevel($stability_desc, $file, $., "Stability level for $symbol");
3874                     $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
3875                 }
3877                 if ($deprecated_desc) {
3878                     if (exists $Deprecated{$symbol}) {
3879                     }
3880                     else {
3881                          # don't warn for signals and properties
3882                          #if ($symbol !~ m/::?(.*)/) {
3883                          if (defined $DeclarationTypes{$symbol}) {
3884                              &LogWarning ($file, $.,
3885                                  "$symbol is deprecated in the inline comments, but no deprecation guards were found around the declaration.".
3886                                  " (See the --deprecated-guards option for gtkdoc-scan.)");
3887                          }
3888                     }
3889                     $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
3890                 }
3891             }
3893             $in_comment_block = 0;
3894             next;
3895         }
3897         # Get rid of ' * ' at start of every line in the comment block.
3898         s%^\s*\*\s?%%;
3899         # But make sure we don't get rid of the newline at the end.
3900         if (!$_) {
3901             $_ = "\n";
3902         }
3903         #print "DEBUG: scanning :$_";
3905         # If we haven't found the symbol name yet, look for it.
3906         if (!$symbol) {
3907             if (m%^\s*(SECTION:\s*\S+)%) {
3908                 $symbol = $1;
3909                 #print "SECTION DOCS found in source for : '$symbol'\n";
3910                 $ignore_broken_returns = 1;
3911             } elsif (m%^\s*([\w:-]*\w)\s*:?\s*(\([a-z ]+\)\s*)*$%) {
3912                 $symbol = $1;
3913                 #print "SYMBOL DOCS found in source for : '$symbol'\n";
3914             }
3915             next;
3916         }
3918         if ($in_part eq "description") {
3919             # Get rid of 'Description:'
3920             s%^\s*Description:%%;
3921         }
3923         if (m/^\s*(returns:|return\s+value:)/i) {
3924             if ($return_style eq 'broken') {
3925                 $description .= $return_start . $return_desc;
3926             }
3927             $return_start = $1;
3928             if ($return_style eq 'sane') {
3929                 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3930             }
3931             $return_style = 'sane';
3932             $ignore_broken_returns = 1;
3933             $return_desc = $';
3934             $in_part = "return";
3935             next;
3936         } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3937             $return_start = $1;
3938             $return_style = 'broken';
3939             $return_desc = $';
3940             $in_part = "return";
3941             next;
3942         } elsif (m%^\s*since:%i) {
3943             # we're in param section and have not seen the blank line
3944             if($in_part ne "") {
3945               $since_desc = $';
3946               $in_part = "since";
3947               next;
3948             }
3949         } elsif (m%^\s*deprecated:%i) {
3950             # we're in param section and have not seen the blank line
3951             if($in_part ne "") {
3952               $deprecated_desc = $';
3953               $in_part = "deprecated";
3954               next;
3955             }
3956         } elsif (m%^\s*stability:%i) {
3957             $stability_desc = $';
3958             $in_part = "stability";
3959             next;
3960         }
3962         if ($in_part eq "description") {
3963             $description .= $_;
3964             next;
3965         } elsif ($in_part eq "return") {
3966             $return_desc .= $_;
3967             next;
3968         } elsif ($in_part eq "since") {
3969             $since_desc .= $_;
3970             next;
3971         } elsif ($in_part eq "stability") {
3972             $stability_desc .= $_;
3973             next;
3974         } elsif ($in_part eq "deprecated") {
3975             $deprecated_desc .= $_;
3976             next;
3977         }
3979         # We must be in the parameters. Check for the empty line below them.
3980         if (m%^\s*$%) {
3981             $in_part = "description";
3982             next;
3983         }
3985         # Look for a parameter name.
3986         if (m%^\s*@(\S+)\s*:\s*%) {
3987             my $param_name = $1;
3988             my $param_desc = $';
3990             #print "Found parameter: $param_name\n";
3991             # Allow varargs variations
3992             if ($param_name =~ m/^.*\.\.\.$/) {
3993                 $param_name = "...";
3994             }
3995             if ("\L$param_name" eq "returns") {
3996                 $return_style = 'sane';
3997                 $ignore_broken_returns = 1;
3998             }
3999             @TRACE@("Found param for symbol $symbol : '$param_name'= '$_'");
4001             push (@params, $param_name);
4002             push (@params, $param_desc);
4003             $current_param += $PARAM_FIELD_COUNT;
4004             next;
4005         }
4007         # We must be in the middle of a parameter description, so add it on
4008         # to the last element in @params.
4009         if ($current_param == -1) {
4010             &LogWarning ($file, $., "Parsing comment block file : parameter expected.");
4011         } else {
4012             $params[$#params] .= $_;
4013         }
4014     }
4015     close (SRCFILE);
4018 #############################################################################
4019 # Function    : OutputMissingDocumentation
4020 # Description : Outputs report of documentation coverage to a file
4022 # Arguments   : none
4023 #############################################################################
4025 sub OutputMissingDocumentation {
4026     my $old_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.txt";
4027     my $new_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.new";
4029     my $n_documented = 0;
4030     my $n_incomplete = 0;
4031     my $total = 0;
4032     my $symbol;
4033     my $percent;
4034     my $msg;
4035     my $buffer = "";
4036     my $buffer_deprecated = "";
4037     my $buffer_descriptions = "";
4039     open(UNDOCUMENTED, ">$new_undocumented_file")
4040       || die "Can't create $new_undocumented_file";
4042     foreach $symbol (sort (keys (%AllSymbols))) {
4043         # FIXME: should we print LogWarnings for undocumented stuff?
4044         # DEBUG
4045         #my $ssfile = &GetSymbolSourceFile($symbol);
4046         #my $ssline = &GetSymbolSourceLine($symbol);
4047         #my $location = "defined at " . (defined($ssfile)?$ssfile:"?") . ":" . (defined($ssline)?$ssline:"0") . "\n";
4048         # DEBUG
4049         if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include|Section_Id|Image)/) {
4050             $total++;
4051             if (exists ($AllDocumentedSymbols{$symbol})) {
4052                 $n_documented++;
4053                 if (exists ($AllIncompleteSymbols{$symbol})) {
4054                     $n_incomplete++;
4055                     $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4056                     #$buffer .= "\t0: ".$location;
4057                 }
4058             } elsif (exists $Deprecated{$symbol}) {
4059                 if (exists ($AllIncompleteSymbols{$symbol})) {
4060                     $n_incomplete++;
4061                     $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4062                     #$buffer .= "\t1a: ".$location;
4063                 } else {
4064                     $buffer_deprecated .= $symbol . "\n";
4065                     #$buffer .= "\t1b: ".$location;
4066                 }
4067             } else {
4068                 if (exists ($AllIncompleteSymbols{$symbol})) {
4069                     $n_incomplete++;
4070                     $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4071                     #$buffer .= "\t2a: ".$location;
4072                 } else {
4073                     $buffer .= $symbol . "\n";
4074                     #$buffer .= "\t2b: ".$location;
4075                 }
4076             }
4077         } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
4078             $total++;
4079             #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
4080             #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
4081             #print "%%%% $symbol : $len1,$len2\n";
4082             if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
4083             || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
4084               $n_documented++;
4085             } else {
4086               # cut off the leading namespace ($TMPL_DIR)
4087               $symbol =~ m/^.*\/(.*)$/;
4088               $buffer_descriptions .= $1 . "\n";
4089             }
4090         }
4091     }
4093     $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
4095     if ($total == 0) {
4096       $percent = 100;
4097     } else {
4098       $percent = ($n_documented / $total) * 100.0;
4099     }
4101     printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
4102     print UNDOCUMENTED "$n_documented symbols documented.\n";
4103     print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
4104     print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
4106     print UNDOCUMENTED $buffer;
4107     close (UNDOCUMENTED);
4109     return &UpdateFileIfChanged ($old_undocumented_file, $new_undocumented_file, 0);
4111     printf "%.0f%% symbol docs coverage", $percent;
4112     print "($n_documented symbols documented, $n_incomplete symbols incomplete, " . ($total - $n_documented) . " not documented)\n";
4113     print "See $MODULE-undocumented.txt for a list of missing docs.\nThe doc coverage percentage doesn't include intro sections.\n";
4117 #############################################################################
4118 # Function    : OutputUndeclaredSymbols
4119 # Description : Outputs symbols that are listed in the section file, but not
4120 #               declaration is found in the sources
4122 # Arguments   : none
4123 #############################################################################
4125 sub OutputUndeclaredSymbols {
4126     my $old_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.txt";
4127     my $new_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.new";
4129     open(UNDECLARED, ">$new_undeclared_file")
4130         || die "Can't create $new_undeclared_file";
4132     if (%UndeclaredSymbols) {
4133         print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
4134         print UNDECLARED "\n";
4135         print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
4136     }
4137     close(UNDECLARED);
4139     return &UpdateFileIfChanged ($old_undeclared_file, $new_undeclared_file, 0);
4142 #############################################################################
4143 # Function    : OutputUnusedSymbols
4144 # Description : Outputs symbols that are documented in comments, but not
4145 #               declared in the sources
4147 # Arguments   : none
4148 #############################################################################
4150 sub OutputUnusedSymbols {
4151     my $num_unused = 0;
4152     my $old_unused_file = "$ROOT_DIR/$MODULE-unused.txt";
4153     my $new_unused_file = "$ROOT_DIR/$MODULE-unused.new";
4155     open (UNUSED, ">$new_unused_file")
4156         || die "Can't open $new_unused_file";
4157     my ($symbol);
4158     foreach $symbol (sort keys (%Declarations)) {
4159         if (!defined ($DeclarationOutput{$symbol})) {
4160             print (UNUSED "$symbol\n");
4161             $num_unused++;
4162         }
4163     }
4164     foreach $symbol (sort (keys (%AllUnusedSymbols))) {
4165         print (UNUSED "$symbol(" . $AllUnusedSymbols{$symbol} . ")\n");
4166         $num_unused++;
4167     }
4168     close (UNUSED);
4169     if ($num_unused != 0) {
4170         &LogWarning ($old_unused_file, 1, "$num_unused unused declarations.".
4171             "They should be added to $MODULE-sections.txt in the appropriate place.");
4172     }
4174     return &UpdateFileIfChanged ($old_unused_file, $new_unused_file, 0);
4178 #############################################################################
4179 # Function    : OutputAllSymbols
4180 # Description : Outputs list of all symbols to a file
4182 # Arguments   : none
4183 #############################################################################
4185 sub OutputAllSymbols {
4186      my $n_documented = 0;
4187      my $total = 0;
4188      my $symbol;
4189      my $percent;
4190      my $msg;
4192      open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
4193           || die "Can't create $ROOT_DIR/$MODULE-symbols.txt: $!";
4195      foreach $symbol (sort (keys (%AllSymbols))) {
4196           print SYMBOLS $symbol . "\n";
4197      }
4199      close (SYMBOLS);
4202 #############################################################################
4203 # Function    : OutputSymbolsWithoutSince
4204 # Description : Outputs list of all symbols without a since tag to a file
4206 # Arguments   : none
4207 #############################################################################
4209 sub OutputSymbolsWithoutSince {
4210      my $n_documented = 0;
4211      my $total = 0;
4212      my $symbol;
4213      my $percent;
4214      my $msg;
4216      open (SYMBOLS, ">$ROOT_DIR/$MODULE-nosince.txt")
4217           || die "Can't create $ROOT_DIR/$MODULE-nosince.txt: $!";
4219      foreach $symbol (sort (keys (%SourceSymbolDocs))) {
4220          if (!defined $Since{$symbol}) {
4221              print SYMBOLS $symbol . "\n";
4222          }
4223      }
4225      close (SYMBOLS);
4229 #############################################################################
4230 # Function    : MergeSourceDocumentation
4231 # Description : This merges documentation read from a source file into the
4232 #                documentation read in from a template file.
4234 #                Parameter descriptions override any in the template files.
4235 #                Function descriptions are placed before any description from
4236 #                the template files.
4238 # Arguments   : none
4239 #############################################################################
4241 sub MergeSourceDocumentation {
4242     my $symbol;
4243     my @Symbols;
4245     if (scalar %SymbolDocs) {
4246         @Symbols=keys (%SymbolDocs);
4247         #print "num existing entries: ".(scalar @Symbols)."\n";
4248         #print "  ",$Symbols[0], " ",$Symbols[1],"\n";
4249     }
4250     else {
4251         # filter scanned declarations, with what we suppress from -sections.txt
4252         my %tmp = ();
4253         foreach $symbol (keys (%Declarations)) {
4254             if (defined($KnownSymbols{$symbol}) && $KnownSymbols{$symbol} == 1) {
4255                 $tmp{$symbol}=1;
4256             }
4257         }
4258         # , add the rest from -sections.txt
4259         foreach $symbol (keys (%KnownSymbols)) {
4260             if ($KnownSymbols{$symbol} == 1) {
4261                 $tmp{$symbol}=1;
4262             }
4263         }
4264         # and add whats found in the source
4265         foreach $symbol (keys (%SourceSymbolDocs)) {
4266             $tmp{$symbol}=1;
4267         }
4268         @Symbols = keys (%tmp);
4269         #print "num source entries: ".(scalar @Symbols)."\n";
4270     }
4271     foreach $symbol (@Symbols) {
4272         $AllSymbols{$symbol} = 1;
4274         my $have_tmpl_docs = 0;
4276         ## see if the symbol is documented in template
4277         my $tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4278         my $check_tmpl_doc =$tmpl_doc;
4279         # remove all xml-tags and whitespaces
4280         $check_tmpl_doc =~ s/<.*?>//g;
4281         $check_tmpl_doc =~ s/\s//g;
4282         # anything left ?
4283         if ($check_tmpl_doc ne "") {
4284             $have_tmpl_docs = 1;
4285             #print "## [$check_tmpl_doc]\n";
4286         } else {
4287             # if the docs have just an empty para, don't merge that.
4288             $check_tmpl_doc = $tmpl_doc;
4289             $check_tmpl_doc =~ s/(\s|\n)//msg;
4290             if ($check_tmpl_doc eq "<para></para>") {
4291                $tmpl_doc = "";
4292             }
4293         }
4295         if (exists ($SourceSymbolDocs{$symbol})) {
4296             my $type = $DeclarationTypes {$symbol};
4298             #print "merging [$symbol] from source\n";
4300             my $item = "Parameter";
4301             if (defined ($type)) {
4302                 if ($type eq 'STRUCT') {
4303                     $item = "Field";
4304                 } elsif ($type eq 'ENUM') {
4305                     $item = "Value";
4306                 } elsif ($type eq 'UNION') {
4307                     $item = "Field";
4308                 }
4309             } else {
4310                 $type="SIGNAL";
4311             }
4313             my $src_doc = $SourceSymbolDocs{$symbol};
4314             # remove leading and training whitespaces
4315             $src_doc =~ s/^\s+//;
4316             $src_doc =~ s/\s+$//;
4318             # Don't output warnings for overridden titles as titles are
4319             # automatically generated in the -sections.txt file, and thus they
4320             # are often overridden.
4321             if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
4322                 # check if content is different
4323                 if ($tmpl_doc ne $src_doc) {
4324                     #print "[$tmpl_doc] [$src_doc]\n";
4325                     &LogWarning ($SourceSymbolSourceFile{$symbol}, $SourceSymbolSourceLine{$symbol},
4326                         "Documentation in template ".$SymbolSourceFile{$symbol}.":".$SymbolSourceLine{$symbol}." for $symbol being overridden by inline comments.");
4327                 }
4328             }
4330             if ($src_doc ne "") {
4331                  $AllDocumentedSymbols{$symbol} = 1;
4332             }
4334             # Convert <!--PARAMETERS--> with any blank lines around it to
4335             # a </para> followed by <!--PARAMETERS--> followed by <para>.
4336             $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
4338             # Do not add <para> to nothing, it breaks missing docs checks.
4339             my $src_doc_para = "";
4340             if ($src_doc ne "") {
4341                 # Expand markdown (and do paragraphs)
4342                 $src_doc_para = &ConvertMarkDown ($src_doc, $symbol);
4343                 ## fixup xml markup
4344                 # FIXME: this is questionable, as we can't make assumtions on the content really
4345                 #$src_doc_para =~ s%^<para>\n(<refsect[1-9])%$1%gms;
4346                 #$src_doc_para =~ s%^<para>\n<para>%<para>%gms;
4347                 #$src_doc_para =~ s%(</refsect[1-9]>)\n</para>$%$1%gms;
4348                 #print "$symbol : [$src_doc][$src_doc_para]\n";
4349             }
4351             if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
4352                 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4353             } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
4354                 # For the title/summary/see also section docs we don't want to
4355                 # add any <para> tags.
4356                 $SymbolDocs{$symbol} = "$src_doc"
4357             } else {
4358                 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4359             }
4361             # merge parameters
4362             if ($symbol =~ m/.*::.*/) {
4363                 # For signals we prefer the param names from the source docs,
4364                 # since the ones from the templates are likely to contain the
4365                 # artificial argn names which are generated by gtkdoc-scangobj.
4366                 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4367                 # FIXME: we need to check for empty docs here as well!
4368             } else {
4369                 # The templates contain the definitive parameter names and order,
4370                 # so we will not change that. We only override the actual text.
4371                 my $tmpl_params = $SymbolParams{$symbol};
4372                 if (!defined ($tmpl_params)) {
4373                     #print "No merge needed for $symbol\n";
4374                     $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4375                     #  FIXME: we still like to get the number of params and merge
4376                     #  1) we would noticed that params have been removed/renamed
4377                     #  2) we would catch undocumented params
4378                     #  params are not (yet) exported in -decl.txt so that we
4379                     #  could easily grab them :/
4380                 } else {
4381                     my $params = $SourceSymbolParams{$symbol};
4382                     my $j;
4383                     #print "Merge needed for $symbol, tmpl_params: ",$#$tmpl_params,", source_params: ",$#$params," \n";
4384                     for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4385                         my $tmpl_param_name = $$tmpl_params[$j];
4387                         # Try to find the param in the source comment documentation.
4388                         my $found = 0;
4389                         my $k;
4390                         #print "  try merge param $tmpl_param_name\n";
4391                         for ($k = 0; $k <= $#$params; $k += $PARAM_FIELD_COUNT) {
4392                             my $param_name = $$params[$k];
4393                             my $param_desc = $$params[$k + 1];
4395                             #print "    test param  $param_name\n";
4396                             # We accept changes in case, since the Gnome source
4397                             # docs contain a lot of these.
4398                             if ("\L$param_name" eq "\L$tmpl_param_name") {
4399                                 $found = 1;
4401                                 # Override the description.
4402                                 $$tmpl_params[$j + 1] = $param_desc;
4404                                 # Set the name to "" to mark it as used.
4405                                 $$params[$k] = "";
4406                                 last;
4407                             }
4408                         }
4410                         # If it looks like the parameters are there, but not
4411                         # in the right place, try to explain a bit better.
4412                         if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
4413                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4414                                 "Parameters for $symbol must start on the line immediately after the function or macro name.");
4415                         }
4416                     }
4418                     # Now we output a warning if parameters have been described which
4419                     # do not exist.
4420                     for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
4421                         my $param_name = $$params[$j];
4422                         if ($param_name) {
4423                             # the template builder cannot detect if a macro returns
4424                             # a result or not
4425                             if(($type eq "MACRO") && ($param_name eq "Returns")) {
4426                                 # FIXME: do we need to add it then to tmpl_params[] ?
4427                                 my $num=$#$tmpl_params;
4428                                 #print "  adding Returns: to macro docs for $symbol.\n";
4429                                 $$tmpl_params[$num+1]="Returns";
4430                                 $$tmpl_params[$num+2]=$$params[$j+1];
4431                                 next;
4432                             }
4433                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4434                                 "$item described in source code comment block but does not exist. $type: $symbol $item: $param_name.");
4435                         }
4436                     }
4437                 }
4438             }
4439         } else {
4440             if ($have_tmpl_docs) {
4441                 $AllDocumentedSymbols{$symbol} = 1;
4442                 #print "merging [$symbol] from template\n";
4443             }
4444             else {
4445                 #print "[$symbol] undocumented\n";
4446             }
4447         }
4449         # if this symbol is documented, check if docs are complete
4450         $check_tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4451         # remove all xml-tags and whitespaces
4452         $check_tmpl_doc =~ s/<.*?>//g;
4453         $check_tmpl_doc =~ s/\s//g;
4454         if ($check_tmpl_doc ne "") {
4455             my $tmpl_params = $SymbolParams{$symbol};
4456             if (defined ($tmpl_params)) {
4457                 my $type = $DeclarationTypes {$symbol};
4459                 my $item = "Parameter";
4460                 if (defined ($type)) {
4461                     if ($type eq 'STRUCT') {
4462                         $item = "Field";
4463                     } elsif ($type eq 'ENUM') {
4464                         $item = "Value";
4465                     } elsif ($type eq 'UNION') {
4466                         $item = "Field";
4467                     }
4468                 } else {
4469                     $type="SIGNAL";
4470                 }
4472                 #print "Check param docs for $symbol, tmpl_params: ",$#$tmpl_params," entries, type=$type\n";
4474                 if ($#$tmpl_params > 0) {
4475                     my $j;
4476                     for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4477                         # Output a warning if the parameter is empty and
4478                         # remember for stats.
4479                         my $tmpl_param_name = $$tmpl_params[$j];
4480                         my $tmpl_param_desc = $$tmpl_params[$j + 1];
4481                         if ($tmpl_param_name ne "void" && $tmpl_param_desc !~ m/\S/) {
4482                             if (exists ($AllIncompleteSymbols{$symbol})) {
4483                                 $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
4484                             } else {
4485                                 $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
4486                             }
4487                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4488                                 "$item description for $symbol"."::"."$tmpl_param_name is missing in source code comment block.");
4489                         }
4490                     }
4491                 }
4492                 else {
4493                     if ($#$tmpl_params == 0) {
4494                         $AllIncompleteSymbols{$symbol}="<items>";
4495                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4496                             "$item descriptions for $symbol are missing in source code comment block.");
4497                     }
4498                     # $#$tmpl_params==-1 means we don't know about parameters
4499                     # this unfortunately does not tell if there should be some
4500                 }
4501             }
4502         }
4503    }
4504    #print "num doc entries: ".(scalar %SymbolDocs)."\n";
4507 #############################################################################
4508 # Function    : IsEmptyDoc
4509 # Description : Check if a doc-string is empty. Its also regarded as empty if
4510 #               it only consist of whitespace or e.g. FIXME.
4511 # Arguments   : the doc-string
4512 #############################################################################
4513 sub IsEmptyDoc {
4514     my ($doc) = @_;
4516     if ($doc =~ /^\s*$/) {
4517         return 1;
4518     }
4520     if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
4521         return 1;
4522     }
4524     return 0;
4528 #############################################################################
4529 # Function    : ConvertMarkDown
4530 # Description : Converts mark down syntax to the respective docbook, but only
4531 #               outside CDATA and <programlisting> tags.
4532 #               http://de.wikipedia.org/wiki/Markdown
4533 #               Code snippets have been takesn from
4534 #               http://daringfireball.net/projects/markdown/
4535 #                 Copyright (c) 2004 John Gruber
4536 # Arguments   : the doc-string, the symbol name
4537 #############################################################################
4538 my $md_in_refsect2;
4539 sub ConvertMarkDown {
4540     my ($text, $symbol) = @_;
4542     # reset state
4543     $md_in_refsect2=0;
4545     # convert
4546     $text = &ModifyXMLElements ($text, $symbol,
4547                                "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
4548                                \&ConvertMarkDownEndTag,
4549                                \&ConvertMarkDownCallback);
4550     # encapsulate and terminate
4551     $text = "<para>\n$text\n</para>";
4552     if ($md_in_refsect2==1) {
4553         $text = "$text</refsect2>"
4554     }
4555     return $text
4558 sub ConvertMarkDownEndTag {
4559   if ($_[0] eq "<!\[CDATA\[") {
4560     return "]]>";
4561   } elsif ($_[0] eq "|[") {
4562     return "]\\|";
4563   } else {
4564     return "</programlisting>";
4565   }
4568 sub ConvertMarkDownCallback {
4569   my ($text, $symbol, $tag) = @_;
4571   # If we're not in CDATA or a <programlisting> we convert blank lines so
4572   # they start a new <para>.
4573   if ($tag eq "") {
4574     my $end_of_para="";
4575     my $end_of_section="";
4576     my $have_list=0;
4578     $end_of_para = "$end_of_para</para>";
4579     $end_of_section = "$end_of_section</para>";
4580     if ($md_in_refsect2==1) {
4581         $end_of_section= "$end_of_section</refsect2>";
4582     }
4584     # Setext-style headers:
4585     #          Header 1
4586     #          ========
4587     #
4588     #          Header 2
4589     #          --------
4590     #
4591     if($text =~ s%^\n(.+)[ \t]*\n=+[ \t]*\n\n%$end_of_section<refsect2><title>$1</title><para>\n%gm) {
4592         $md_in_refsect2=1;
4593     }
4595     # atx-style headers:
4596     #        # Header 1
4597     #        ## Header 2
4598     #        ## Header 2 with closing hashes ##
4599     #        ...
4600     #        ###### Header 6
4601     #
4602     if($text =~ s%^\n\#[ \t]*(.+?)[ \t]*\#\n+%$end_of_section<refsect2><title>$1</title><para>\n%gm) {
4603         $md_in_refsect2=1;
4604     }
4606     # Simple (unnested) lists:
4607     #   Please select:
4608     #   - item 1
4609     #   - item 2 with loooong
4610     #     description
4611     #   - item 3
4612     #
4613     #   New paragraph.
4614     $text.="\n"; # we need a new line to avoid too complicated matching rules below
4615     if ($text =~ s%(?<=\n)-\s+(.+?)(?=(?:\n-\s+)|(?:\n\n)|(?:\n$))%<listitem><para>$1</para></listitem>%gs) {
4616         $text =~ s%(?<!</listitem>)(\n<listitem>)%\n<itemizedlist>$1%g;
4617         $text =~ s%(</listitem>\n)(?!<listitem>)%$1</itemizedlist>\n%g;
4618     }
4619     chomp $text;
4621     # Make Paragraphs on blank lines
4622     $text =~ s%\n{2,}%\n$end_of_para\n<para>\n%g;
4623   }
4625   return $text;
4629 #############################################################################
4630 # LIBRARY FUNCTIONS -        These functions are used in both gtkdoc-mkdb and
4631 #                        gtkdoc-mktmpl and should eventually be moved to a
4632 #                        separate library.
4633 #############################################################################
4635 #############################################################################
4636 # Function    : ReadDeclarationsFile
4637 # Description : This reads in a file containing the function/macro/enum etc.
4638 #                declarations.
4640 #                Note that in some cases there are several declarations with
4641 #                the same name, e.g. for conditional macros. In this case we
4642 #                set a flag in the %DeclarationConditional hash so the
4643 #                declaration is not shown in the docs.
4645 #                If a macro and a function have the same name, e.g. for
4646 #                gtk_object_ref, the function declaration takes precedence.
4648 #                Some opaque structs are just declared with 'typedef struct
4649 #                _name name;' in which case the declaration may be empty.
4650 #                The structure may have been found later in the header, so
4651 #                that overrides the empty declaration.
4653 # Arguments   : $file - the declarations file to read
4654 #                $override - if declarations in this file should override
4655 #                        any current declaration.
4656 #############################################################################
4658 sub ReadDeclarationsFile {
4659     my ($file, $override) = @_;
4661     if ($override == 0) {
4662         %Declarations = ();
4663         %DeclarationTypes = ();
4664         %DeclarationConditional = ();
4665         %DeclarationOutput = ();
4666     }
4668     open (INPUT, $file)
4669         || die "Can't open $file: $!";
4670     my $declaration_type = "";
4671     my $declaration_name;
4672     my $declaration;
4673     my $is_deprecated = 0;
4674     while (<INPUT>) {
4675         if (!$declaration_type) {
4676             if (m/^<([^>]+)>/) {
4677                 $declaration_type = $1;
4678                 $declaration_name = "";
4679                 #print "Found declaration: $declaration_type\n";
4680                 $declaration = "";
4681             }
4682         } else {
4683             if (m%^<NAME>(.*)</NAME>%) {
4684                 $declaration_name = $1;
4685             } elsif (m%^<DEPRECATED/>%) {
4686                 $is_deprecated = 1;
4687             } elsif (m%^</$declaration_type>%) {
4688                 #print "Found end of declaration: $declaration_name\n";
4689                 # Check that the declaration has a name
4690                 if ($declaration_name eq "") {
4691                     print "ERROR: $declaration_type has no name $file:$.\n";
4692                 }
4694                 # If the declaration is an empty typedef struct _XXX XXX
4695                 # set the flag to indicate the struct has a typedef.
4696                 if ($declaration_type eq 'STRUCT'
4697                     && $declaration =~ m/^\s*$/) {
4698                     #print "Struct has typedef: $declaration_name\n";
4699                     $StructHasTypedef{$declaration_name} = 1;
4700                 }
4702                 # Check if the symbol is already defined.
4703                 if (defined ($Declarations{$declaration_name})
4704                     && $override == 0) {
4705                     # Function declarations take precedence.
4706                     if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
4707                         # Ignore it.
4708                     } elsif ($declaration_type eq 'FUNCTION') {
4709                         if ($is_deprecated) {
4710                             $Deprecated{$declaration_name} = "";
4711                         }
4712                         $Declarations{$declaration_name} = $declaration;
4713                         $DeclarationTypes{$declaration_name} = $declaration_type;
4714                     } elsif ($DeclarationTypes{$declaration_name}
4715                               eq $declaration_type) {
4716                         # If the existing declaration is empty, or is just a
4717                         # forward declaration of a struct, override it.
4718                         if ($declaration_type eq 'STRUCT') {
4719                             if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4720                                 if ($is_deprecated) {
4721                                     $Deprecated{$declaration_name} = "";
4722                                 }
4723                                 $Declarations{$declaration_name} = $declaration;
4724                             } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4725                                 # Ignore an empty or forward declaration.
4726                             } else {
4727                                 &LogWarning ($file, $., "Structure $declaration_name has multiple definitions.");
4728                             }
4729                         } else {
4730                             # set flag in %DeclarationConditional hash for
4731                             # multiply defined macros/typedefs.
4732                             $DeclarationConditional{$declaration_name} = 1;
4733                         }
4734                     } else {
4735                         &LogWarning ($file, $., "$declaration_name has multiple definitions.");
4736                     }
4737                 } else {
4738                     if ($is_deprecated) {
4739                         $Deprecated{$declaration_name} = "";
4740                     }
4741                     $Declarations{$declaration_name} = $declaration;
4742                     $DeclarationTypes{$declaration_name} = $declaration_type;
4743                 }
4745                 $declaration_type = "";
4746                 $is_deprecated = 0;
4747             } else {
4748                 $declaration .= $_;
4749             }
4750         }
4751     }
4752     close (INPUT);
4756 #############################################################################
4757 # Function    : ReadSignalsFile
4758 # Description : This reads in an existing file which contains information on
4759 #                all GTK signals. It creates the arrays @SignalNames and
4760 #                @SignalPrototypes containing info on the signals. The first
4761 #                line of the SignalPrototype is the return type of the signal
4762 #                handler. The remaining lines are the parameters passed to it.
4763 #                The last parameter, "gpointer user_data" is always the same
4764 #                so is not included.
4765 # Arguments   : $file - the file containing the signal handler prototype
4766 #                        information.
4767 #############################################################################
4769 sub ReadSignalsFile {
4770     my ($file) = @_;
4772     my $in_signal = 0;
4773     my $signal_object;
4774     my $signal_name;
4775     my $signal_returns;
4776     my $signal_flags;
4777     my $signal_prototype;
4779     # Reset the signal info.
4780     @SignalObjects = ();
4781     @SignalNames = ();
4782     @SignalReturns = ();
4783     @SignalFlags = ();
4784     @SignalPrototypes = ();
4786     if (! -f $file) {
4787         return;
4788     }
4789     if (!open (INPUT, $file)) {
4790         warn "Can't open $file - skipping signals\n";
4791         return;
4792     }
4793     while (<INPUT>) {
4794         if (!$in_signal) {
4795             if (m/^<SIGNAL>/) {
4796                 $in_signal = 1;
4797                 $signal_object = "";
4798                 $signal_name = "";
4799                 $signal_returns = "";
4800                 $signal_prototype = "";
4801             }
4802         } else {
4803             if (m/^<NAME>(.*)<\/NAME>/) {
4804                 $signal_name = $1;
4805                 if ($signal_name =~ m/^(.*)::(.*)$/) {
4806                     $signal_object = $1;
4807                     ($signal_name = $2) =~ s/_/-/g;
4808                     #print "Found signal: $signal_name\n";
4809                 } else {
4810                     &LogWarning ($file, $., "Invalid signal name: $signal_name.");
4811                 }
4812             } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
4813                 $signal_returns = $1;
4814             } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4815                 $signal_flags = $1;
4816             } elsif (m%^</SIGNAL>%) {
4817                 #print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
4818                 push (@SignalObjects, $signal_object);
4819                 push (@SignalNames, $signal_name);
4820                 push (@SignalReturns, $signal_returns);
4821                 push (@SignalFlags, $signal_flags);
4822                 push (@SignalPrototypes, $signal_prototype);
4823                 $in_signal = 0;
4824             } else {
4825                 $signal_prototype .= $_;
4826             }
4827         }
4828     }
4829     close (INPUT);
4833 #############################################################################
4834 # Function    : ReadTemplateFile
4835 # Description : This reads in the manually-edited documentation file
4836 #                corresponding to the file currently being created, so we can
4837 #                insert the documentation at the appropriate places.
4838 #                It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
4839 #                is a hash of arrays.
4840 #                NOTE: This function is duplicated in gtkdoc-mktmpl (but
4841 #                slightly different).
4842 # Arguments   : $docsfile - the template file to read in.
4843 #                $skip_unused_params - 1 if the unused parameters should be
4844 #                        skipped.
4845 #############################################################################
4847 sub ReadTemplateFile {
4848     my ($docsfile, $skip_unused_params) = @_;
4850     my $template = "$docsfile.sgml";
4851     if (! -f $template) {
4852         #print "File doesn't exist: $template\n";
4853         return 0;
4854     }
4856     # start with empty hashes, we merge the source comment for each file
4857     # afterwards
4858     %SymbolDocs = ();
4859     %SymbolTypes = ();
4860     %SymbolParams = ();
4862     my $current_type = "";        # Type of symbol being read.
4863     my $current_symbol = "";        # Name of symbol being read.
4864     my $symbol_doc = "";                # Description of symbol being read.
4865     my @params;                        # Parameter names and descriptions of current
4866                                 #   function/macro/function typedef.
4867     my $current_param = -1;        # Index of parameter currently being read.
4868                                 #   Note that the param array contains pairs
4869                                 #   of param name & description.
4870     my $in_unused_params = 0;        # True if we are reading in the unused params.
4871     my $in_deprecated = 0;
4872     my $in_since = 0;
4873     my $in_stability = 0;
4875     open (DOCS, "$template")
4876         || die "Can't open $template: $!";
4878     @TRACE@("reading template $template");
4880     while (<DOCS>) {
4881         if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
4882             my $type = $1;
4883             my $symbol = $2;
4884             if ($symbol eq "Title"
4885                 || $symbol eq "Short_Description"
4886                 || $symbol eq "Long_Description"
4887                 || $symbol eq "See_Also"
4888                 || $symbol eq "Stability_Level"
4889                 || $symbol eq "Include"
4890                 || $symbol eq "Image") {
4892                 $symbol = $docsfile . ":" . $symbol;
4893             }
4895             #print "Found symbol: $symbol\n";
4896             # Remember file and line for the symbol
4897             $SymbolSourceFile{$symbol} = $template;
4898             $SymbolSourceLine{$symbol} = $.;
4900             # Store previous symbol, but remove any trailing blank lines.
4901             if ($current_symbol ne "") {
4902                 $symbol_doc =~ s/\s+$//;
4903                 $SymbolTypes{$current_symbol} = $current_type;
4904                 $SymbolDocs{$current_symbol} = $symbol_doc;
4906                 # Check that the stability level is valid.
4907                 if ($StabilityLevel{$current_symbol}) {
4908                     $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4909                 }
4911                 if ($current_param >= 0) {
4912                     $SymbolParams{$current_symbol} = [ @params ];
4913                 } else {
4914                     # Delete any existing params in case we are overriding a
4915                     # previously read template.
4916                     delete $SymbolParams{$current_symbol};
4917                 }
4918             }
4919             $current_type = $type;
4920             $current_symbol = $symbol;
4921             $current_param = -1;
4922             $in_unused_params = 0;
4923             $in_deprecated = 0;
4924             $in_since = 0;
4925             $in_stability = 0;
4926             $symbol_doc = "";
4927             @params = ();
4929         } elsif (m/^<!-- # Unused Parameters # -->/) {
4930             #print "DEBUG: Found unused parameters\n";
4931             $in_unused_params = 1;
4932             next;
4934         } elsif ($in_unused_params && $skip_unused_params) {
4935             # When outputting the DocBook we skip unused parameters.
4936             #print "DEBUG: Skipping unused param: $_";
4937             next;
4939         } else {
4940             # Check if param found. Need to handle "..." and "format...".
4941             if (s/^\@([\w\.]+):\040?//) {
4942                 my $param_name = $1;
4943                 my $param_desc = $_;
4944                 # Allow variations of 'Returns'
4945                 if ($param_name =~ m/^[Rr]eturns?$/) {
4946                     $param_name = "Returns";
4947                 }
4948                 # Allow varargs variations
4949                 if ($param_name =~ m/^.*\.\.\.$/) {
4950                     $param_name = "...";
4951                 }
4953                 # strip trailing whitespaces and blank lines
4954                 s/\s+\n$/\n/m;
4955                 s/\n+$/\n/sm;
4956                 @TRACE@("Found param for symbol $current_symbol : '$param_name'= '$_'");
4958                 if ($param_name eq "Deprecated") {
4959                     $in_deprecated = 1;
4960                     $Deprecated{$current_symbol} = $_;
4961                 } elsif ($param_name eq "Since") {
4962                     $in_since = 1;
4963                     chomp;
4964                     $Since{$current_symbol} = $_;
4965                 } elsif ($param_name eq "Stability") {
4966                     $in_stability = 1;
4967                     $StabilityLevel{$current_symbol} = $_;
4968                 } else {
4969                     push (@params, $param_name);
4970                     push (@params, $param_desc);
4971                     $current_param += $PARAM_FIELD_COUNT;
4972                 }
4973             } else {
4974                 # strip trailing whitespaces and blank lines
4975                 s/\s+\n$/\n/m;
4976                 s/\n+$/\n/sm;
4978                 if (!m/^\s+$/) {
4979                     if ($in_deprecated) {
4980                         $Deprecated{$current_symbol} .= $_;
4981                     } elsif ($in_since) {
4982                         &LogWarning ($template, $., "multi-line since docs found");
4983                         #$Since{$current_symbol} .= $_;
4984                     } elsif ($in_stability) {
4985                         $StabilityLevel{$current_symbol} .= $_;
4986                     } elsif ($current_param >= 0) {
4987                         $params[$current_param] .= $_;
4988                     } else {
4989                         $symbol_doc .= $_;
4990                     }
4991                 }
4992             }
4993         }
4994     }
4996     # Remember to finish the current symbol doccs.
4997     if ($current_symbol ne "") {
4999         $symbol_doc =~ s/\s+$//;
5000         $SymbolTypes{$current_symbol} = $current_type;
5001         $SymbolDocs{$current_symbol} = $symbol_doc;
5003         # Check that the stability level is valid.
5004         if ($StabilityLevel{$current_symbol}) {
5005             $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
5006         }
5008         if ($current_param >= 0) {
5009             $SymbolParams{$current_symbol} = [ @params ];
5010         } else {
5011             # Delete any existing params in case we are overriding a
5012             # previously read template.
5013             delete $SymbolParams{$current_symbol};
5014         }
5015     }
5017     close (DOCS);
5018     return 1;
5022 #############################################################################
5023 # Function    : ReadObjectHierarchy
5024 # Description : This reads in the $MODULE-hierarchy.txt file containing all
5025 #                the GtkObject subclasses described in this module (and their
5026 #                ancestors).
5027 #                It places them in the @Objects array, and places their level
5028 #                in the object hierarchy in the @ObjectLevels array, at the
5029 #                same index. GtkObject, the root object, has a level of 1.
5031 #               FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
5032 #               as it goes along, this should be split out into a separate
5033 #               function.
5035 # Arguments   : none
5036 #############################################################################
5038 sub ReadObjectHierarchy {
5039     @Objects = ();
5040     @ObjectLevels = ();
5042     if (! -f $OBJECT_TREE_FILE) {
5043         return;
5044     }
5045     if (!open (INPUT, $OBJECT_TREE_FILE)) {
5046         warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
5047         return;
5048     }
5050     # FIXME: use $OUTPUT_FORMAT
5051     # my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.$OUTPUT_FORMAT";
5052     my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
5053     my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
5055     open (OUTPUT, ">$new_tree_index")
5056         || die "Can't create $new_tree_index: $!";
5058     if ($OUTPUT_FORMAT eq "xml") {
5059         my $tree_header = $doctype_header;
5061         $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
5062         print (OUTPUT "$tree_header");
5063     }
5064     print (OUTPUT "<screen>\n");
5066     # Only emit objects if they are supposed to be documented, or if
5067     # they have documented children. To implement this, we maintain a
5068     # stack of pending objects which will be emitted if a documented
5069     # child turns up.
5070     my @pending_objects = ();
5071     my @pending_levels = ();
5072     my $root;
5073     while (<INPUT>) {
5074         if (m/\S+/) {
5075             my $object = $&;
5076             my $level = (length($`)) / 2 + 1;
5077             my $xref = "";
5079             if ($level == 1) {
5080                 $root = $object;
5081             }
5083             while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
5084                 my $pobject = pop(@pending_objects);
5085                 my $plevel = pop(@pending_levels);
5086             }
5088                push (@pending_objects, $object);
5089             push (@pending_levels, $level);
5091             if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5092                    while ($#pending_levels >= 0) {
5093                     $object = shift @pending_objects;
5094                     $level = shift @pending_levels;
5095                        $xref = &MakeXRef ($object);
5097                      print (OUTPUT ' ' x ($level * 4), "$xref\n");
5098                     push (@Objects, $object);
5099                     push (@ObjectLevels, $level);
5100                     $ObjectRoots{$object} = $root;
5101                 }
5102             }
5103             #else {
5104             #    LogWarning ($OBJECT_TREE_FILE, $., "unknown type $object");
5105             #}
5106         }
5107     }
5108     print (OUTPUT "</screen>\n");
5110     close (INPUT);
5111     close (OUTPUT);
5113     &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
5115     &OutputObjectList;
5118 #############################################################################
5119 # Function    : ReadInterfaces
5120 # Description : This reads in the $MODULE.interfaces file.
5122 # Arguments   : none
5123 #############################################################################
5125 sub ReadInterfaces {
5126     %Interfaces = ();
5128     if (! -f $INTERFACES_FILE) {
5129         return;
5130     }
5131     if (!open (INPUT, $INTERFACES_FILE)) {
5132         warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
5133         return;
5134     }
5136     while (<INPUT>) {
5137        chomp;
5138        my ($object, @ifaces) = split;
5139        if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5140            my @knownIfaces = ();
5142            # filter out private interfaces, but leave foreign interfaces
5143            foreach my $iface (@ifaces) {
5144                if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
5145                    push (@knownIfaces, $iface);
5146                }
5147              }
5149            $Interfaces{$object} = join(' ', @knownIfaces);
5150        }
5151     }
5152     close (INPUT);
5155 #############################################################################
5156 # Function    : ReadPrerequisites
5157 # Description : This reads in the $MODULE.prerequisites file.
5159 # Arguments   : none
5160 #############################################################################
5162 sub ReadPrerequisites {
5163     %Prerequisites = ();
5165     if (! -f $PREREQUISITES_FILE) {
5166         return;
5167     }
5168     if (!open (INPUT, $PREREQUISITES_FILE)) {
5169         warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
5170         return;
5171     }
5173     while (<INPUT>) {
5174        chomp;
5175        my ($iface, @prereqs) = split;
5176        if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
5177            my @knownPrereqs = ();
5179            # filter out private prerequisites, but leave foreign prerequisites
5180            foreach my $prereq (@prereqs) {
5181                if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
5182                   push (@knownPrereqs, $prereq);
5183                }
5184            }
5186            $Prerequisites{$iface} = join(' ', @knownPrereqs);
5187        }
5188     }
5189     close (INPUT);
5192 #############################################################################
5193 # Function    : ReadArgsFile
5194 # Description : This reads in an existing file which contains information on
5195 #                all GTK args. It creates the arrays @ArgObjects, @ArgNames,
5196 #                @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
5197 #               on the args.
5198 # Arguments   : $file - the file containing the arg information.
5199 #############################################################################
5201 sub ReadArgsFile {
5202     my ($file) = @_;
5204     my $in_arg = 0;
5205     my $arg_object;
5206     my $arg_name;
5207     my $arg_type;
5208     my $arg_flags;
5209     my $arg_nick;
5210     my $arg_blurb;
5211     my $arg_default;
5212     my $arg_range;
5214     # Reset the args info.
5215     @ArgObjects = ();
5216     @ArgNames = ();
5217     @ArgTypes = ();
5218     @ArgFlags = ();
5219     @ArgNicks = ();
5220     @ArgBlurbs = ();
5221     @ArgDefaults = ();
5222     @ArgRanges = ();
5224     if (! -f $file) {
5225         return;
5226     }
5227     if (!open (INPUT, $file)) {
5228         warn "Can't open $file - skipping args\n";
5229         return;
5230     }
5231     while (<INPUT>) {
5232         if (!$in_arg) {
5233             if (m/^<ARG>/) {
5234                 $in_arg = 1;
5235                 $arg_object = "";
5236                 $arg_name = "";
5237                 $arg_type = "";
5238                 $arg_flags = "";
5239                 $arg_nick = "";
5240                 $arg_blurb = "";
5241                 $arg_default = "";
5242                 $arg_range = "";
5243             }
5244         } else {
5245             if (m/^<NAME>(.*)<\/NAME>/) {
5246                 $arg_name = $1;
5247                 if ($arg_name =~ m/^(.*)::(.*)$/) {
5248                     $arg_object = $1;
5249                     ($arg_name = $2) =~ s/_/-/g;
5250                     #print "Found arg: $arg_name\n";
5251                 } else {
5252                     &LogWarning ($file, $., "Invalid argument name: $arg_name");
5253                 }
5254             } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
5255                 $arg_type = $1;
5256             } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
5257                 $arg_range = $1;
5258             } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
5259                 $arg_flags = $1;
5260             } elsif (m/^<NICK>(.*)<\/NICK>/) {
5261                 $arg_nick = $1;
5262             } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
5263                 $arg_blurb = $1;
5264                 if ($arg_blurb eq "(null)") {
5265                   $arg_blurb = "";
5266                   &LogWarning ($file, $., "Property ${arg_object}:${arg_name} has no documentation.");
5267                 }
5268             } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
5269                 $arg_default = $1;
5270             } elsif (m%^</ARG>%) {
5271                 #print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
5272                 push (@ArgObjects, $arg_object);
5273                 push (@ArgNames, $arg_name);
5274                 push (@ArgTypes, $arg_type);
5275                 push (@ArgRanges, $arg_range);
5276                 push (@ArgFlags, $arg_flags);
5277                 push (@ArgNicks, $arg_nick);
5278                 push (@ArgBlurbs, $arg_blurb);
5279                 push (@ArgDefaults, $arg_default);
5280                 $in_arg = 0;
5281             }
5282         }
5283     }
5284     close (INPUT);
5288 #############################################################################
5289 # Function    : CheckIsObject
5290 # Description : Returns 1 if the given name is a GObject or a subclass.
5291 #                It uses the global @Objects array.
5292 #                Note that the @Objects array only contains classes in the
5293 #                current module and their ancestors - not all GObject classes.
5294 # Arguments   : $name - the name to check.
5295 #############################################################################
5297 sub CheckIsObject {
5298     my ($name) = @_;
5299     my $root = $ObjectRoots{$name};
5300     # Let GBoxed pass as an object here to get -struct appended to the id
5301     # and prevent conflicts with sections.
5302     return defined($root) and $root ne 'GEnum' and $root ne 'GFlags';
5306 #############################################################################
5307 # Function    : MakeReturnField
5308 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
5309 # Arguments   : $str - the string to pad.
5310 #############################################################################
5312 sub MakeReturnField {
5313     my ($str) = @_;
5315     return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));
5318 #############################################################################
5319 # Function    : GetSymbolSourceFile
5320 # Description : Get the filename where the symbol docs where taken from.
5321 # Arguments   : $symbol - the symbol name
5322 #############################################################################
5324 sub GetSymbolSourceFile {
5325     my ($symbol) = @_;
5327     if (defined($SourceSymbolSourceFile{$symbol})) {
5328         return $SourceSymbolSourceFile{$symbol};
5329     } elsif (defined($SymbolSourceFile{$symbol})) {
5330         return $SymbolSourceFile{$symbol};
5331     } else {
5332         return "";
5333     }
5336 #############################################################################
5337 # Function    : GetSymbolSourceLine
5338 # Description : Get the file line where the symbol docs where taken from.
5339 # Arguments   : $symbol - the symbol name
5340 #############################################################################
5342 sub GetSymbolSourceLine {
5343     my ($symbol) = @_;
5345     if (defined($SourceSymbolSourceLine{$symbol})) {
5346         return $SourceSymbolSourceLine{$symbol};
5347     } elsif (defined($SymbolSourceLine{$symbol})) {
5348         return $SymbolSourceLine{$symbol};
5349     } else {
5350         return 0;
5351     }