Add a long annotated parameter description (regression test for #613611)
[gtk-doc.git] / gtkdoc-mkdb.in
blobd8ef68f57d8da7260d773e5318c53b2037bbda23
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 $SGML_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' => \$SGML_MODE,
66               'default-stability' => \$DEFAULT_STABILITY,
67               'default-includes' => \$DEFAULT_INCLUDES,
68               'output-format' => \$OUTPUT_FORMAT,
69               'name-space' => \$NAME_SPACE,
70               'outputallsymbols' => \$OUTPUT_ALL_SYMBOLS,
71               'outputsymbolswithoutsince' => \$OUTPUT_SYMBOLS_WITHOUT_SINCE
72               );
73 GetOptions(\%optctl, "module=s", "source-dir:s", "source-suffixes:s", 
74     "ignore-files:s", "output-dir:s", "tmpl-dir:s", "version", "outputallsymbols",
75     "outputsymbolswithoutsince",
76     "expand-content-files:s", "main-sgml-file:s", "extra-db-files:s", "help",
77     "sgml-mode", "default-stability:s", "default-includes:s", "output-format:s",
78     "name-space:s");
80 if ($PRINT_VERSION) {
81     print "@VERSION@\n";
82     exit 0;
85 if (!$MODULE) {
86     $PRINT_HELP = 1;
89 if ($DEFAULT_STABILITY && $DEFAULT_STABILITY ne "Stable"
90     && $DEFAULT_STABILITY ne "Private" && $DEFAULT_STABILITY ne "Unstable") {
91     $PRINT_HELP = 1;
94 if ($PRINT_HELP) {
95     print <<EOF;
96 gtkdoc-mkdb version @VERSION@ - generate docbook files
98 --module=MODULE_NAME       Name of the doc module being parsed
99 --source-dir=DIRNAME       Directories which contain inline reference material
100 --source-suffixes=SUFFIXES Suffixes of source files to scan, comma-separated
101 --ignore-files=FILES       Files or directories which should not be scanned
102                            May be used more than once for multiple directories
103 --output-dir=DIRNAME       Directory to put the generated DocBook files in
104 --tmpl-dir=DIRNAME         Directory in which template files may be found
105 --main-sgml-file=FILE      File containing the toplevel DocBook file.
106 --expand-content-files=FILES Extra DocBook files to expand abbreviations in.
107 --output-format=FORMAT     Format to use for the generated docbook, XML or SGML.
108 --sgml-mode                Allow DocBook markup in inline documentation.
109 --default-stability=LEVEL  Specify default stability Level. Valid values are
110                            Stable, Unstable, or Private.
111 --default-includes=FILENAMES Specify default includes for section Synopsis
112 --name-space=NS            Omit namespace in index.
113 --version                  Print the version of this program
114 --help                     Print this help
116     exit 0;
119 my ($empty_element_end, $doctype_header);
121 # autodetect output format
122 if (! defined($OUTPUT_FORMAT) || ($OUTPUT_FORMAT eq "")) {
123     if (!$MAIN_SGML_FILE) {
124         if (-e "${MODULE}-docs.xml") {
125             $OUTPUT_FORMAT = "xml";
126         } else {
127             $OUTPUT_FORMAT = "sgml";
128         }
129     } else {
130         if ($MAIN_SGML_FILE =~ m/.*\.(.*ml)$/i) {
131             $OUTPUT_FORMAT = lc($1);
132         }
133     }
134     
135 } else {
136     $OUTPUT_FORMAT = lc($OUTPUT_FORMAT);
139 #print "DEBUG: output-format: [$OUTPUT_FORMAT]\n";
141 if ($OUTPUT_FORMAT eq "xml") {
142     if (!$MAIN_SGML_FILE) {
143         # backwards compatibility
144         if (-e "${MODULE}-docs.sgml") {
145             $MAIN_SGML_FILE = "${MODULE}-docs.sgml";
146         } else {
147             $MAIN_SGML_FILE = "${MODULE}-docs.xml";
148         }
149     }
150     $empty_element_end = "/>";
152     if (-e $MAIN_SGML_FILE) {
153         open(INPUT, "<$MAIN_SGML_FILE") || die "Can't open $MAIN_SGML_FILE";
154         $doctype_header = "";
155         while (<INPUT>) {
156             if (/^\s*<(book|chapter|article)/) {
157                 # check that the top-level tag or the doctype decl contain the xinclude namespace decl
158                 if (($_ !~ m/http:\/\/www.w3.org\/200[13]\/XInclude/) && ($doctype_header !~ m/http:\/\/www.w3.org\/200[13]\/XInclude/m)) {
159                     $doctype_header = "";
160                 }
161                 last;
162             }
163             $doctype_header .= $_;
164         }
165         close(INPUT);
166     } else {
167         $doctype_header =
168 "<?xml version=\"1.0\"?>\n" .
169 "<!DOCTYPE book PUBLIC \"-//OASIS//DTD DocBook XML V4.3//EN\"\n" .
170 "               \"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd\"\n" .
171 "[\n" .
172 "  <!ENTITY % local.common.attrib \"xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'\">\n" .
173 "]>\n";
174     }
175     $doctype_header =~ s/<!DOCTYPE \w+/<!DOCTYPE refentry/;
176 } else {
177     if (!$MAIN_SGML_FILE) {
178         $MAIN_SGML_FILE = "${MODULE}-docs.sgml";
179     }
180     $empty_element_end = ">";
181     $doctype_header = "";
184 my $ROOT_DIR = ".";
186 # All the files are written in subdirectories beneath here.
187 $TMPL_DIR = $TMPL_DIR ? $TMPL_DIR : "$ROOT_DIR/tmpl";
189 # This is where we put all the DocBook output.
190 $SGML_OUTPUT_DIR = $SGML_OUTPUT_DIR ? $SGML_OUTPUT_DIR : "$ROOT_DIR/$OUTPUT_FORMAT";
192 # This file contains the object hierarchy.
193 my $OBJECT_TREE_FILE = "$ROOT_DIR/$MODULE.hierarchy";
195 # This file contains the interfaces.
196 my $INTERFACES_FILE = "$ROOT_DIR/$MODULE.interfaces";
198 # This file contains the prerequisites.
199 my $PREREQUISITES_FILE = "$ROOT_DIR/$MODULE.prerequisites";
201 # This file contains signal arguments and names.
202 my $SIGNALS_FILE = "$ROOT_DIR/$MODULE.signals";
204 # The file containing Arg information.
205 my $ARGS_FILE = "$ROOT_DIR/$MODULE.args";
207 # These global arrays store information on signals. Each signal has an entry
208 # in each of these arrays at the same index, like a multi-dimensional array.
209 my @SignalObjects;      # The GtkObject which emits the signal.
210 my @SignalNames;        # The signal name.
211 my @SignalReturns;      # The return type.
212 my @SignalFlags;        # Flags for the signal
213 my @SignalPrototypes;   # The rest of the prototype of the signal handler.
215 # These global arrays store information on Args. Each Arg has an entry
216 # in each of these arrays at the same index, like a multi-dimensional array.
217 my @ArgObjects;         # The GtkObject which has the Arg.
218 my @ArgNames;           # The Arg name.
219 my @ArgTypes;           # The Arg type - gint, GtkArrowType etc.
220 my @ArgFlags;           # How the Arg can be used - readable/writable etc.
221 my @ArgNicks;           # The nickname of the Arg.
222 my @ArgBlurbs;          # Docstring of the Arg.
223 my @ArgDefaults;        # Default value of the Arg.
224 my @ArgRanges;          # The range of the Arg type
225 # These global hashes store declaration info keyed on a symbol name.
226 my %Declarations;
227 my %DeclarationTypes;
228 my %DeclarationConditional;
229 my %DeclarationOutput;
230 my %Deprecated;
231 my %Since;
232 my %StabilityLevel;
233 my %StructHasTypedef;
235 # These global hashes store the existing documentation.
236 my %SymbolDocs;
237 my %SymbolTypes;
238 my %SymbolParams;
239 my %SymbolSourceFile;
240 my %SymbolSourceLine;
242 # These global hashes store documentation scanned from the source files.
243 my %SourceSymbolDocs;
244 my %SourceSymbolParams;
245 my %SourceSymbolSourceFile;
246 my %SourceSymbolSourceLine;
248 # all documentation goes in here, so we can do coverage analysis
249 my %AllSymbols;
250 my %AllIncompleteSymbols;
251 my %AllUnusedSymbols;
252 my %AllDocumentedSymbols;
254 # Undeclared yet documented symbols
255 my %UndeclaredSymbols;
257 # These global arrays store GObject, subclasses and the hierarchy.
258 my @Objects;
259 my @ObjectLevels;
261 my %Interfaces;
262 my %Prerequisites;
264 # holds the symbols which are mentioned in $MODULE-sections.txt and in which
265 # section they are defined
266 my %KnownSymbols;
267 my %SymbolSection;
268 my %SymbolSectionId;
270 # collects index entries
271 my %IndexEntriesFull;
272 my %IndexEntriesSince;
273 my %IndexEntriesDeprecated;
275 # Standard C preprocessor directives, which we ignore for '#' abbreviations.
276 my %PreProcessorDirectives;
277 $PreProcessorDirectives{"assert"} = 1;
278 $PreProcessorDirectives{"define"} = 1;
279 $PreProcessorDirectives{"elif"} = 1;
280 $PreProcessorDirectives{"else"} = 1;
281 $PreProcessorDirectives{"endif"} = 1;
282 $PreProcessorDirectives{"error"} = 1;
283 $PreProcessorDirectives{"if"} = 1;
284 $PreProcessorDirectives{"ifdef"} = 1;
285 $PreProcessorDirectives{"ifndef"} = 1;
286 $PreProcessorDirectives{"include"} = 1;
287 $PreProcessorDirectives{"line"} = 1;
288 $PreProcessorDirectives{"pragma"} = 1;
289 $PreProcessorDirectives{"unassert"} = 1;
290 $PreProcessorDirectives{"undef"} = 1;
291 $PreProcessorDirectives{"warning"} = 1;
293 # remember used annotation (to write minimal glossary)
294 my %AnnotationsUsed;
296 my %AnnotationDefinition = (
297     'allow-none' => "NULL is ok, both for passing and for returning.",
298     'array' => "Parameter points to an array of items.",
299     'default' => "Default parameter value (for in case the <acronym>shadows</acronym>-to function has less parameters).",
300     'element-type' => "Generics and defining elements of containers and arrays.",
301     'error-domains' => "Typed errors. Similar to throws in Java.",
302     'in' => "Parameter for input. Default is <acronym>transfer none</acronym>.",
303     'inout' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
304     'in-out' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
305     'not-error' => "A GError parameter is not to be handled like a normal GError.",
306     'out' => "Parameter for returning results. Default is <acronym>transfer full</acronym>.",
307     'transfer container' => "Free data container after the code is done.",
308     'transfer full' => "Free data after the code is done.",
309     'transfer none' => "Don't free data after the code is done."
312 # Create the root DocBook output directory if it doens't exist.
313 if (! -e $SGML_OUTPUT_DIR) {
314     mkdir ("$SGML_OUTPUT_DIR", 0777)
315         || die "Can't create directory: $SGML_OUTPUT_DIR";
318 # Function and other declaration output settings.
319 my $RETURN_TYPE_FIELD_WIDTH = 20;
320 my $SYMBOL_FIELD_WIDTH = 36;
321 my $SIGNAL_FIELD_WIDTH = 16;
322 my $PARAM_FIELD_COUNT = 2;
324 &ReadKnownSymbols ("$ROOT_DIR/$MODULE-sections.txt");
325 &ReadSignalsFile ($SIGNALS_FILE);
326 &ReadArgsFile ($ARGS_FILE);
327 &ReadObjectHierarchy;
328 &ReadInterfaces;
329 &ReadPrerequisites;
331 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-decl.txt", 0);
332 if (-f "$ROOT_DIR/$MODULE-overrides.txt") {
333     &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-overrides.txt", 1);
336 for my $dir (@SOURCE_DIRS) {
337     &ReadSourceDocumentation ($dir);
340 my $changed = &OutputSGML ("$ROOT_DIR/$MODULE-sections.txt");
342 # If any of the DocBook SGML files have changed, update the timestamp file (so
343 # it can be used for Makefile dependencies).
344 if ($changed || ! -e "$ROOT_DIR/sgml.stamp") {
346     # try to detect the common prefix
347     # GtkWidget, GTK_WIDGET, gtk_widget -> gtk
348     if ($NAME_SPACE eq "") {
349         $NAME_SPACE="";
350         my $pos=0;
351         my $ratio=0.0;
352         do {
353             my %prefix;
354             my $letter="";
355             foreach my $symbol (keys(%IndexEntriesFull)) {
356                 if(($NAME_SPACE eq "") || $symbol =~ /^$NAME_SPACE/i) {
357                     if (length($symbol)>$pos) {
358                         $letter=substr($symbol,$pos,1);
359                         # stop prefix scanning
360                         if ($letter eq "_") {
361                             # stop on "_"
362                             last;
363                         }
364                         # Should we also stop on a uppercase char, if last was lowercase
365                         #   GtkWidget, if we have the 'W' and had the 't' before
366                         # or should we count upper and lowercase, and stop one 2nd uppercase, if we already had a lowercase
367                         #   GtkWidget, the 'W' would be the 2nd uppercase and with 't','k' we had lowercase chars before
368                         # need to recound each time as this is per symbol
369                         $prefix{uc($letter)}++;
370                     }
371                 }
372             }
373             if ($letter ne "" && $letter ne "_") {
374                 my $maxletter="";
375                 my $maxsymbols=0;
376                 foreach $letter (keys(%prefix)) {
377                     #print "$letter: $prefix{$letter}.\n";
378                     if ($prefix{$letter}>$maxsymbols) {
379                         $maxletter=$letter;
380                         $maxsymbols=$prefix{$letter};
381                     }
382                 }
383                 $ratio = scalar(keys(%IndexEntriesFull)) / $prefix{$maxletter};
384                 #print "most symbols start with $maxletter, that is ". (100 * $ratio) ." %\n";
385                 if ($ratio > 0.9) {
386                     # do another round
387                     $NAME_SPACE .= $maxletter;
388                 }
389                 $pos++;
390             }
391             else {
392                 $ratio=0.0;
393             }
394         } while ($ratio > 0.9);
395         #print "most symbols start with $NAME_SPACE\n";
396     }
398     &OutputIndexFull;
399     &OutputDeprecatedIndex;
400     &OutputSinceIndexes;
401     &OutputAnnotationGlossary;
403     open (TIMESTAMP, ">$ROOT_DIR/sgml.stamp")
404         || die "Can't create $ROOT_DIR/sgml.stamp: $!";
405     print (TIMESTAMP "timestamp");
406     close (TIMESTAMP);
409 #############################################################################
410 # Function    : OutputObjectList
411 # Description : This outputs the alphabetical list of objects, in a columned
412 #               table.
413 #               FIXME: Currently this also outputs ancestor objects
414 #               which may not actually be in this module.
415 # Arguments   : none
416 #############################################################################
418 sub OutputObjectList {
419     my $cols = 3;
420     
421     # FIXME: use $OUTPUT_FORMAT
422     # my $old_object_index = "$SGML_OUTPUT_DIR/object_index.$OUTPUT_FORMAT";
423     my $old_object_index = "$SGML_OUTPUT_DIR/object_index.sgml";
424     my $new_object_index = "$SGML_OUTPUT_DIR/object_index.new";
426     open (OUTPUT, ">$new_object_index")
427         || die "Can't create $new_object_index: $!";
429     if ($OUTPUT_FORMAT eq "xml") {
430         my $header = $doctype_header;
432         $header =~ s/<!DOCTYPE \w+/<!DOCTYPE informaltable/;
433         print (OUTPUT "$header");
434     }
436     print (OUTPUT <<EOF);
437 <informaltable pgwide="1" frame="none">
438 <tgroup cols="$cols">
439 <colspec colwidth="1*"${empty_element_end}
440 <colspec colwidth="1*"${empty_element_end}
441 <colspec colwidth="1*"${empty_element_end}
442 <tbody>
445     my $count = 0;
446     my $object;
447     foreach $object (sort (@Objects)) {
448         my $xref = &MakeXRef ($object);
449         if ($count % $cols == 0) { print (OUTPUT "<row>\n"); }
450         print (OUTPUT "<entry>$xref</entry>\n");
451         if ($count % $cols == ($cols - 1)) { print (OUTPUT "</row>\n"); }
452         $count++;
453     }
454     if ($count == 0) {
455         # emit an empty row, since empty tables are invalid
456         print (OUTPUT "<row><entry> </entry></row>\n");
457     }
458     else {
459         print (OUTPUT "</row>\n");
460     }
462     print (OUTPUT <<EOF);
463 </tbody></tgroup></informaltable>
465     close (OUTPUT);
467     &UpdateFileIfChanged ($old_object_index, $new_object_index, 0);
471 #############################################################################
472 # Function    : OutputSGML
473 # Description : This collects the output for each section of the docs, and
474 #               outputs each file when the end of the section is found.
475 # Arguments   : $file - the $MODULE-sections.txt file which contains all of
476 #               the functions/macros/structs etc. being documented, organised
477 #               into sections and subsections.
478 #############################################################################
480 sub OutputSGML {
481     my ($file) = @_;
483     #print "Reading: $file\n";
484     open (INPUT, $file)
485         || die "Can't open $file: $!";
486     my $filename = "";
487     my $book_top = "";
488     my $book_bottom = "";
489     my $includes = (defined $DEFAULT_INCLUDES) ? $DEFAULT_INCLUDES : "";
490     my $section_includes = "";
491     my $in_section = 0;
492     my $title = "";
493     my $section_id = "";
494     my $subsection = "";
495     my $synopsis;
496     my $details;
497     my $num_symbols;
498     my $changed = 0;
499     my $signals_synop = "";
500     my $signals_desc = "";
501     my $args_synop = "";
502     my $child_args_synop = "";
503     my $style_args_synop = "";
504     my $args_desc = "";
505     my $child_args_desc = "";
506     my $style_args_desc = "";
507     my $hierarchy = "";
508     my $interfaces = "";
509     my $implementations = "";
510     my $prerequisites = "";
511     my $derived = "";
512     my @file_objects = ();
513     my %templates = ();
514     my %symbol_def_line = ();
516     # merge the source docs, in case there are no templates
517     &MergeSourceDocumentation;
519     while (<INPUT>) {
520         if (m/^#/) {
521             next;
523         } elsif (m/^<SECTION>/) {
524             $synopsis = "";
525             $details = "";
526             $num_symbols = 0;
527             $in_section = 1;
528             @file_objects = ();
529             %symbol_def_line = ();
531         } elsif (m/^<SUBSECTION\s*(.*)>/i) {
532             $synopsis .= "\n";
533             $subsection = $1;
535         } elsif (m/^<SUBSECTION>/) {
537         } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
538             $title = $1;
539             #print "Section: $title\n";
541             # We don't want warnings if object & class structs aren't used.
542             $DeclarationOutput{$title} = 1;
543             $DeclarationOutput{"${title}Class"} = 1;
544             $DeclarationOutput{"${title}Iface"} = 1;
545             $DeclarationOutput{"${title}Interface"} = 1;
547         } elsif (m/^<FILE>(.*)<\/FILE>/) {
548             $filename = $1;
549             if (! defined $templates{$filename}) {
550                if (&ReadTemplateFile ("$TMPL_DIR/$filename", 1)) {
551                    &MergeSourceDocumentation;
552                    $templates{$filename}=$.;
553                }
554             } else {
555                 &LogWarning ($file, $., "Double <FILE>$filename</FILE> entry. ".
556                     "Previous occurrence on line ".$templates{$filename}.".");
557             }
558             if (($title eq "") and (defined $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"})) {
559                 $title = $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"};
560                 # Remove trailing blanks
561                 $title =~ s/\s+$//;
562            }
564         } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
565             if ($in_section) {
566                 $section_includes = $1;
567             } else {
568                 if (defined $DEFAULT_INCLUDES) {
569                     &LogWarning ($file, $., "Default <INCLUDE> being overridden by command line option.");
570                 }
571                 else {
572                     $includes = $1;
573                 }
574             }
576         } elsif (m/^<\/SECTION>/) {
577             #print "End of section: $title\n";
578             if ($num_symbols > 0) {
579                 # collect documents
580                 if ($OUTPUT_FORMAT eq "xml") {
581                     $book_bottom .= "    <xi:include href=\"xml/$filename.xml\"/>\n";
582                 } else {
583                     $book_top.="<!ENTITY $section_id SYSTEM \"sgml/$filename.sgml\">\n";
584                     $book_bottom .= "    &$section_id;\n";
585                 }
587                 if (defined ($SourceSymbolDocs{"$TMPL_DIR/$filename:Include"})) {
588                     if ($section_includes) {
589                         &LogWarning ($file, $., "Section <INCLUDE> being overridden by inline comments.");
590                     }
591                     $section_includes = $SourceSymbolDocs{"$TMPL_DIR/$filename:Include"};
592                 }
593                 if ($section_includes eq "") {
594                     $section_includes = $includes;
595                 }
597                  $signals_synop =~ s/^\n*//g;
598                  $signals_synop =~ s/\n+$/\n/g;
599                 if ($signals_synop ne '') {
600                     $signals_synop = <<EOF;
601 <refsect1 id="$section_id.signals" role="signal_proto">
602 <title role="signal_proto.title">Signals</title>
603 <synopsis>
604 ${signals_synop}</synopsis>
605 </refsect1>
607                      $signals_desc =~ s/^\n*//g;
608                      $signals_desc =~ s/\n+$/\n/g;
609                      $signals_desc =~ s/(\s|\n)+$//ms;
610                     $signals_desc  = <<EOF;
611 <refsect1 id="$section_id.signal-details" role="signals">
612 <title role="signals.title">Signal Details</title>
613 $signals_desc
614 </refsect1>
616                 }
618                  $args_synop =~ s/^\n*//g;
619                  $args_synop =~ s/\n+$/\n/g;
620                 if ($args_synop ne '') {
621                     $args_synop = <<EOF;
622 <refsect1 id="$section_id.properties" role="properties">
623 <title role="properties.title">Properties</title>
624 <synopsis>
625 ${args_synop}</synopsis>
626 </refsect1>
628                      $args_desc =~ s/^\n*//g;
629                      $args_desc =~ s/\n+$/\n/g;
630                      $args_desc =~ s/(\s|\n)+$//ms;
631                     $args_desc  = <<EOF;
632 <refsect1 id="$section_id.property-details" role="property_details">
633 <title role="property_details.title">Property Details</title>
634 $args_desc
635 </refsect1>
637                 }
639                  $child_args_synop =~ s/^\n*//g;
640                  $child_args_synop =~ s/\n+$/\n/g;
641                 if ($child_args_synop ne '') {
642                     $args_synop .= <<EOF;
643 <refsect1 id="$section_id.child-properties" role="child_properties">
644 <title role="child_properties.title">Child Properties</title>
645 <synopsis>
646 ${child_args_synop}</synopsis>
647 </refsect1>
649                      $child_args_desc =~ s/^\n*//g;
650                      $child_args_desc =~ s/\n+$/\n/g;
651                      $child_args_desc =~ s/(\s|\n)+$//ms;
652                     $args_desc .= <<EOF;
653 <refsect1 id="$section_id.child-property-details" role="child_property_details">
654 <title role="child_property_details.title">Child Property Details</title>
655 $child_args_desc
656 </refsect1>
658                 }
660                  $style_args_synop =~ s/^\n*//g;
661                  $style_args_synop =~ s/\n+$/\n/g;
662                 if ($style_args_synop ne '') {
663                     $args_synop .= <<EOF;
664 <refsect1 id="$section_id.style-properties" role="style_properties">
665 <title role="style_properties.title">Style Properties</title>
666 <synopsis>
667 ${style_args_synop}</synopsis>
668 </refsect1>
670                      $style_args_desc =~ s/^\n*//g;
671                      $style_args_desc =~ s/\n+$/\n/g;
672                      $style_args_desc =~ s/(\s|\n)+$//ms;
673                     $args_desc .= <<EOF;
674 <refsect1 id="$section_id.style-property-details" role="style_properties_details">
675 <title role="style_properties_details.title">Style Property Details</title>
676 $style_args_desc
677 </refsect1>
679                 }
681                  $hierarchy =~ s/^\n*//g;
682                  $hierarchy =~ s/\n+$/\n/g;
683                  $hierarchy =~ s/(\s|\n)+$//ms;
684                 if ($hierarchy ne "") {
685                     $hierarchy = <<EOF;
686 <refsect1 id="$section_id.object-hierarchy" role="object_hierarchy">
687 <title role="object_hierarchy.title">Object Hierarchy</title>
688 $hierarchy
689 </refsect1>
691                 }
693                  $interfaces =~ s/^\n*//g;
694                  $interfaces =~ s/\n+$/\n/g;
695                  $interfaces =~ s/(\s|\n)+$//ms;
696                 if ($interfaces ne "") {
697                     $interfaces = <<EOF;
698 <refsect1 id="$section_id.implemented-interfaces" role="impl_interfaces">
699 <title role="impl_interfaces.title">Implemented Interfaces</title>
700 $interfaces
701 </refsect1>
703                 }
705                  $implementations =~ s/^\n*//g;
706                  $implementations =~ s/\n+$/\n/g;
707                  $implementations =~ s/(\s|\n)+$//ms;
708                 if ($implementations ne "") {
709                     $implementations = <<EOF;
710 <refsect1 id="$section_id.implementations" role="implementations">
711 <title role="implementations.title">Known Implementations</title>
712 $implementations
713 </refsect1>
715                 }
717                  $prerequisites =~ s/^\n*//g;
718                  $prerequisites =~ s/\n+$/\n/g;
719                  $prerequisites =~ s/(\s|\n)+$//ms;
720                 if ($prerequisites ne "") {
721                     $prerequisites = <<EOF;
722 <refsect1 id="$section_id.prerequisites" role="prerequisites">
723 <title role="prerequisites.title">Prerequisites</title>
724 $prerequisites
725 </refsect1>
727                 }
729                  $derived =~ s/^\n*//g;
730                  $derived =~ s/\n+$/\n/g;
731                  $derived =~ s/(\s|\n)+$//ms;
732                 if ($derived ne "") {
733                     $derived = <<EOF;
734 <refsect1 id="$section_id.derived-interfaces" role="derived_interfaces">
735 <title role="derived_interfaces.title">Known Derived Interfaces</title>
736 $derived
737 </refsect1>
739                 }
741                 $synopsis =~ s/^\n*//g;
742                 $synopsis =~ s/\n+$/\n/g;
743                 my $file_changed = &OutputSGMLFile ($filename, $title, $section_id,
744                                                     $section_includes,
745                                                     \$synopsis, \$details,
746                                                     \$signals_synop, \$signals_desc,
747                                                     \$args_synop, \$args_desc,
748                                                     \$hierarchy, \$interfaces,
749                                                     \$implementations,
750                                                     \$prerequisites, \$derived,
751                                                     \@file_objects);
752                 if ($file_changed) {
753                     $changed = 1;
754                 }
755             }
756             $title = "";
757             $section_id = "";
758             $subsection = "";
759             $in_section = 0;
760             $section_includes = "";
761             $signals_synop = "";
762             $signals_desc = "";
763             $args_synop = "";
764             $child_args_synop = "";
765             $style_args_synop = "";
766             $args_desc = "";
767             $child_args_desc = "";
768             $style_args_desc = "";
769             $hierarchy = "";
770             $interfaces = "";
771             $implementations = "";
772             $prerequisites = "";
773             $derived = "";
775         } elsif (m/^(\S+)/) {
776             my $symbol = $1;
777             #print "  Symbol: $symbol\n";
779             # check for duplicate entries
780             if (! defined $symbol_def_line{$symbol}) {
781                 my $declaration = $Declarations{$symbol};
782                 if (defined ($declaration)) {
783                     # We don't want standard macros/functions of GObjects,
784                     # or private declarations.
785                     if ($subsection ne "Standard" && $subsection ne "Private") {
786                         if (&CheckIsObject ($symbol)) {
787                             push @file_objects, $symbol;
788                         }
789                         my ($synop, $desc) = &OutputDeclaration ($symbol,
790                                                                  $declaration);
791                         my ($sig_synop, $sig_desc) = &GetSignals ($symbol);
792                         my ($arg_synop, $child_arg_synop, $style_arg_synop,
793                             $arg_desc, $child_arg_desc, $style_arg_desc) = &GetArgs ($symbol);
794                         my $hier = &GetHierarchy ($symbol);
795                         my $ifaces = &GetInterfaces ($symbol);
796                         my $impls = &GetImplementations ($symbol);
797                         my $prereqs = &GetPrerequisites ($symbol);
798                         my $der = &GetDerived ($symbol);
799                         $synopsis .= $synop;
800                         $details .= $desc;
801                         $signals_synop .= $sig_synop;
802                         $signals_desc .= $sig_desc;
803                         $args_synop .= $arg_synop;
804                         $child_args_synop .= $child_arg_synop;
805                         $style_args_synop .= $style_arg_synop;
806                         $args_desc .= $arg_desc;
807                         $child_args_desc .= $child_arg_desc;
808                         $style_args_desc .= $style_arg_desc;
809                         $hierarchy .= $hier;
810                         $interfaces .= $ifaces;
811                         $implementations .= $impls;
812                         $prerequisites .= $prereqs;
813                         $derived .= $der;
814                     }
815     
816                     # Note that the declaration has been output.
817                     $DeclarationOutput{$symbol} = 1;
818                 } elsif ($subsection ne "Standard" && $subsection ne "Private") {
819                     $UndeclaredSymbols{$symbol} = 1;
820                     &LogWarning ($file, $., "No declaration found for $symbol.");
821                 }
822                 $num_symbols++;
823                 $symbol_def_line{$symbol}=$.;
825                 if ($section_id eq "") {
826                     if($title eq "" && $filename eq "") {
827                         &LogWarning ($file, $., "Section has no title and no file.");
828                     }
829                     # FIXME: one of those would be enough
830                     # filename should be an internal detail for gtk-doc
831                     if ($title eq "") {
832                         $title = $filename;
833                     } elsif ($filename eq "") {
834                         $filename = $title;
835                     }
836                     $filename =~ s/\s/_/g;
837         
838                     $section_id = $SourceSymbolDocs{"$TMPL_DIR/$filename:Section_Id"};
839                     if (defined ($section_id) && $section_id !~ m/^\s*$/) {
840                         # Remove trailing blanks and use as is
841                         $section_id =~ s/\s+$//;
842                     } elsif (&CheckIsObject ($title)) {
843                         # GObjects use their class name as the ID.
844                         $section_id = &CreateValidSGMLID ($title);
845                     } else {
846                         $section_id = &CreateValidSGMLID ("$MODULE-$title");
847                     }
848                 }
849                 $SymbolSection{$symbol}=$title;
850                 $SymbolSectionId{$symbol}=$section_id;
851             }
852             else {
853                 &LogWarning ($file, $., "Double symbol entry for $symbol. ".
854                     "Previous occurrence on line ".$symbol_def_line{$symbol}.".");
855             }
856         }
857     }
858     close (INPUT);
860     &OutputMissingDocumentation;
861     &OutputUndeclaredSymbols;
862     &OutputUnusedSymbols;
864     if ($OUTPUT_ALL_SYMBOLS) {
865         &OutputAllSymbols;
866     }
867     if ($OUTPUT_SYMBOLS_WITHOUT_SINCE) {
868         &OutputSymbolsWithoutSince;
869     }
871     for $filename (split (' ', $EXPAND_CONTENT_FILES)) {
872         my $file_changed = &OutputExtraFile ($filename);
873         if ($file_changed) {
874             $changed = 1;
875         }
876     }
878     &OutputBook ($book_top, $book_bottom);
880     return $changed;
883 #############################################################################
884 # Function    : OutputIndex
885 # Description : This writes an indexlist that can be included into the main-
886 #               document into an <index> tag.
887 #############################################################################
889 sub OutputIndex {
890     my ($basename, $apiindexref ) = @_;
891     my %apiindex = %{$apiindexref};
892     my $old_index = "$SGML_OUTPUT_DIR/$basename.xml";
893     my $new_index = "$SGML_OUTPUT_DIR/$basename.new";
894     my $lastletter = " ";
895     my $divopen = 0;
896     my $symbol;
897     my $short_symbol;
899     open (OUTPUT, ">$new_index")
900         || die "Can't create $new_index";
902     my $header = $doctype_header;
903     $header =~ s/<!DOCTYPE \w+/<!DOCTYPE indexdiv/;
905     print (OUTPUT "$header<indexdiv>\n");
907     #print "generate $basename index (".%apiindex." entries)\n";
908     
909     # do a case insensitive sort while chopping off the prefix
910     foreach my $hash (
911         sort { $$a{criteria} cmp $$b{criteria} }
912         map { my $x = uc($_); $x =~ s/^$NAME_SPACE\_?(.*)/$1/i; { criteria => $x, original => $_, short => $1 } } 
913         keys %apiindex) {
915         $symbol = $$hash{original};
916         if (defined($$hash{short})) {
917             $short_symbol = $$hash{short};
918         } else {
919             $short_symbol = $symbol;
920         }
922         # generate a short symbol description
923         my $symbol_desc = "";
924         my $symbol_section = "";
925         my $symbol_section_id = "";
926         my $symbol_type = lc($DeclarationTypes{$symbol});
927         if ($symbol_type eq "") {
928             #print "trying symbol $symbol\n";
929             if ($symbol =~ m/(.*)::(.*)/) {
930                 my $oname = $1;
931                 my $osym = $2;
932                 my $i;
933                 #print "  trying object signal ${oname}:$osym in ".$#SignalNames." signals\n";
934                 for ($i = 0; $i <= $#SignalNames; $i++) {
935                     if ($SignalNames[$i] eq $osym) {
936                         $symbol_type = "object signal";
937                         if (defined($SymbolSection{$oname})) {
938                            $symbol_section = $SymbolSection{$oname};
939                            $symbol_section_id = $SymbolSectionId{$oname};
940                         }
941                         last;
942                     }
943                 }
944             } elsif ($symbol =~ m/(.*):(.*)/) {
945                 my $oname = $1;
946                 my $osym = $2;
947                 my $i;
948                 #print "  trying object property ${oname}::$osym in ".$#ArgNames." properties\n";
949                 for ($i = 0; $i <= $#ArgNames; $i++) {
950                     #print "    ".$ArgNames[$i]."\n";
951                     if ($ArgNames[$i] eq $osym) {
952                         $symbol_type = "object property";
953                         if (defined($SymbolSection{$oname})) {
954                            $symbol_section = $SymbolSection{$oname};
955                            $symbol_section_id = $SymbolSectionId{$oname};
956                         }
957                         last;
958                     }
959                 }
960             }
961         } else {
962            if (defined($SymbolSection{$symbol})) {
963                $symbol_section = $SymbolSection{$symbol};
964                $symbol_section_id = $SymbolSectionId{$symbol};
965            }
966         }
967         if ($symbol_type ne "") {
968            $symbol_desc=", $symbol_type";
969            if ($symbol_section ne "") {
970                $symbol_desc.=" in <link linkend=\"$symbol_section_id\">$symbol_section</link>";
971                #$symbol_desc.=" in ". &ExpandAbbreviations($symbol, "#$symbol_section");
972            }
973         }
975         my $curletter = uc(substr($short_symbol,0,1));
976         my $id = $apiindex{$symbol};
978         #print "  add symbol $symbol with $id to index in section $curletter\n";
980         if ($curletter ne $lastletter) {
981             $lastletter = $curletter;
983             if ($divopen == 1) {
984                 print (OUTPUT "</indexdiv>\n");
985             }
986             print (OUTPUT "<indexdiv><title>$curletter</title>\n");
987             $divopen = 1;
988         }
990         print (OUTPUT <<EOF);
991 <indexentry><primaryie linkends="$id"><link linkend="$id">$symbol</link>$symbol_desc</primaryie></indexentry>
993     }
995     if ($divopen == 1) {
996         print (OUTPUT "</indexdiv>\n");
997     }
998     print (OUTPUT "</indexdiv>\n");
999     close (OUTPUT);
1001     &UpdateFileIfChanged ($old_index, $new_index, 0);
1005 #############################################################################
1006 # Function    : OutputIndexFull
1007 # Description : This writes the full api indexlist that can be included into the
1008 #               main document into an <index> tag.
1009 #############################################################################
1011 sub OutputIndexFull {
1012     &OutputIndex ("api-index-full", \%IndexEntriesFull);
1016 #############################################################################
1017 # Function    : OutputDeprecatedIndex
1018 # Description : This writes the deprecated api indexlist that can be included
1019 #               into the main document into an <index> tag.
1020 #############################################################################
1022 sub OutputDeprecatedIndex {
1023     &OutputIndex ("api-index-deprecated", \%IndexEntriesDeprecated);
1027 #############################################################################
1028 # Function    : OutputSinceIndexes
1029 # Description : This writes the 'since' api indexlists that can be included into
1030 #               the main document into an <index> tag.
1031 #############################################################################
1033 sub OutputSinceIndexes {
1034     my @sinces = keys %{{ map { $_ => 1 } values %Since }};
1036     foreach my $version (@sinces) {
1037         #print "Since : [$version]\n";
1038         # TODO make filtered hash
1039         #my %index = grep { $Since{$_} eq $version } %IndexEntriesSince;
1040         my %index = map { $_ => $IndexEntriesSince{$_} } grep { $Since{$_} eq $version } keys %IndexEntriesSince;
1042         &OutputIndex ("api-index-$version", \%index);
1043     }
1046 #############################################################################
1047 # Function    : OutputAnnotationGlossary
1048 # Description : This writes a glossary of the used annotation terms into a
1049 #               separate glossary file that can be included into the main
1050 #               document.
1051 #############################################################################
1053 sub OutputAnnotationGlossary {
1054     my $old_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.xml";
1055     my $new_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.new";
1056     my $lastletter = " ";
1057     my $divopen = 0;
1059     # if there are no annotations used return
1060     return if (! keys(%AnnotationsUsed));
1062     # add acronyms that are referenced from acronym text
1063 rerun:
1064     foreach my $annotation (keys(%AnnotationsUsed)) {
1065         if($AnnotationDefinition{$annotation} =~ m/<acronym>([\w ]+)<\/acronym>/) {
1066             if (!exists($AnnotationsUsed{$1})) {
1067                 $AnnotationsUsed{$1} = 1;
1068                 goto rerun;
1069             }
1070         }
1071     }
1073     open (OUTPUT, ">$new_glossary")
1074         || die "Can't create $new_glossary";
1076     my $header = $doctype_header;
1077     $header =~ s/<!DOCTYPE \w+/<!DOCTYPE glossary/;
1079     print (OUTPUT  <<EOF);
1080 $header
1081 <glossary id="annotation-glossary">
1082   <title>Annotation Glossary</title>
1085     foreach my $annotation (keys(%AnnotationsUsed)) {
1086         my $def = $AnnotationDefinition{$annotation};
1087         my $curletter = uc(substr($annotation,0,1));
1089         if ($curletter ne $lastletter) {
1090             $lastletter = $curletter;
1091       
1092             if ($divopen == 1) {
1093                 print (OUTPUT "</glossdiv>\n");
1094             }
1095             print (OUTPUT "<glossdiv><title>$curletter</title>\n");
1096             $divopen = 1;
1097         }
1098         print (OUTPUT <<EOF);
1099     <glossentry>
1100       <glossterm><anchor id="annotation-glossterm-$annotation"/>$annotation</glossterm>
1101       <glossdef>
1102         <para>$def</para>
1103       </glossdef>
1104     </glossentry>
1106     }
1108     if ($divopen == 1) {
1109         print (OUTPUT "</glossdiv>\n");
1110     }
1111     print (OUTPUT "</glossary>\n");
1112     close (OUTPUT);
1114     &UpdateFileIfChanged ($old_glossary, $new_glossary, 0);
1117 #############################################################################
1118 # Function    : ReadKnownSymbols
1119 # Description : This collects the names of non-private symbols from the
1120 #               $MODULE-sections.txt file.
1121 # Arguments   : $file - the $MODULE-sections.txt file which contains all of
1122 #               the functions/macros/structs etc. being documented, organised
1123 #               into sections and subsections.
1124 #############################################################################
1126 sub ReadKnownSymbols {
1127     my ($file) = @_;
1129     my $subsection = "";
1131     #print "Reading: $file\n";
1132     open (INPUT, $file)
1133         || die "Can't open $file: $!";
1135     while (<INPUT>) {
1136         if (m/^#/) {
1137             next;
1139         } elsif (m/^<SECTION>/) {
1140             $subsection = "";
1142         } elsif (m/^<SUBSECTION\s*(.*)>/i) {
1143             $subsection = $1;
1145         } elsif (m/^<SUBSECTION>/) {
1146             next;
1148         } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
1149             next;
1151         } elsif (m/^<FILE>(.*)<\/FILE>/) {
1152             $KnownSymbols{"$TMPL_DIR/$1:Long_Description"} = 1;
1153             $KnownSymbols{"$TMPL_DIR/$1:Short_Description"} = 1;
1154             next;
1156         } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
1157             next;
1159         } elsif (m/^<\/SECTION>/) {
1160             next;
1162         } elsif (m/^(\S+)/) {
1163             my $symbol = $1;
1165             if ($subsection ne "Standard" && $subsection ne "Private") {
1166                 $KnownSymbols{$symbol} = 1;
1167             }
1168             else {
1169                 $KnownSymbols{$symbol} = 0;
1170             }
1171         }
1172     }
1173     close (INPUT);
1177 #############################################################################
1178 # Function    : OutputDeclaration
1179 # Description : Returns the synopsis and detailed description DocBook
1180 #               describing one function/macro etc.
1181 # Arguments   : $symbol - the name of the function/macro begin described.
1182 #               $declaration - the declaration of the function/macro.
1183 #############################################################################
1185 sub OutputDeclaration {
1186     my ($symbol, $declaration) = @_;
1188     my $type = $DeclarationTypes {$symbol};
1189     if ($type eq 'MACRO') {
1190         return &OutputMacro ($symbol, $declaration);
1191     } elsif ($type eq 'TYPEDEF') {
1192         return &OutputTypedef ($symbol, $declaration);
1193     } elsif ($type eq 'STRUCT') {
1194         return &OutputStruct ($symbol, $declaration);
1195     } elsif ($type eq 'ENUM') {
1196         return &OutputEnum ($symbol, $declaration);
1197     } elsif ($type eq 'UNION') {
1198         return &OutputUnion ($symbol, $declaration);
1199     } elsif ($type eq 'VARIABLE') {
1200         return &OutputVariable ($symbol, $declaration);
1201     } elsif ($type eq 'FUNCTION') {
1202         return &OutputFunction ($symbol, $declaration, $type);
1203     } elsif ($type eq 'USER_FUNCTION') {
1204         return &OutputFunction ($symbol, $declaration, $type);
1205     } else {
1206         die "Unknown symbol type";
1207     }
1211 #############################################################################
1212 # Function    : OutputSymbolTraits
1213 # Description : Returns the Since and StabilityLevel paragraphs for a symbol.
1214 # Arguments   : $symbol - the name of the function/macro begin described.
1215 #############################################################################
1217 sub OutputSymbolTraits {
1218     my ($symbol) = @_;
1219     my $desc = "";
1221     if (exists $Since{$symbol}) {
1222         $desc .= "<para role=\"since\">Since $Since{$symbol}</para>";
1223     }
1224     if (exists $StabilityLevel{$symbol}) {
1225         $desc .= "<para role=\"stability\">Stability Level: $StabilityLevel{$symbol}</para>";
1226     }
1227     return $desc;
1230 #############################################################################
1231 # Function    : Outpu{Symbol,Section}ExtraLinks
1232 # Description : Returns extralinks for the symbol (if enabled).
1233 # Arguments   : $symbol - the name of the function/macro begin described.
1234 #############################################################################
1236 sub uri_escape {
1237     my $text = $_[0];
1238     return undef unless defined $text;
1240     # Build a char to hex map
1241     my %escapes = ();
1242     for (0..255) {
1243             $escapes{chr($_)} = sprintf("%%%02X", $_);
1244     }
1246     # Default unsafe characters.  RFC 2732 ^(uric - reserved)
1247     $text =~ s/([^A-Za-z0-9\-_.!~*'()])/$escapes{$1}/g;
1249     return $text;
1252 sub OutputSymbolExtraLinks {
1253     my ($symbol) = @_;
1254     my $desc = "";
1256     if (0) { # NEW FEATURE: needs configurability
1257     my $sstr = &uri_escape($symbol);
1258     my $mstr = &uri_escape($MODULE);
1259     $desc .= <<EOF;
1260 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1261 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&amp;symbol=$sstr">edit documentation</ulink>
1263     }
1264     return $desc;
1267 sub OutputSectionExtraLinks {
1268     my ($symbol,$docsymbol) = @_;
1269     my $desc = "";
1271     if (0) { # NEW FEATURE: needs configurability
1272     my $sstr = &uri_escape($symbol);
1273     my $mstr = &uri_escape($MODULE);
1274     my $dsstr = &uri_escape($docsymbol);
1275     $desc .= <<EOF;
1276 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1277 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&amp;symbol=$dsstr">edit documentation</ulink>
1279     }
1280     return $desc;
1284 #############################################################################
1285 # Function    : OutputMacro
1286 # Description : Returns the synopsis and detailed description of a macro.
1287 # Arguments   : $symbol - the macro.
1288 #               $declaration - the declaration of the macro.
1289 #############################################################################
1291 sub OutputMacro {
1292     my ($symbol, $declaration) = @_;
1293     my $id = &CreateValidSGMLID ($symbol);
1294     my $condition = &MakeConditionDescription ($symbol);
1295     my $synop = &MakeReturnField("#define") . "<link linkend=\"$id\">$symbol</link>";
1296     my $desc;
1298     my @fields = ParseMacroDeclaration($declaration, \&CreateValidSGML);
1299     my $title = $symbol . (@fields ? "()" : "");
1301     $desc = "<refsect2 id=\"$id\" role=\"macro\"$condition>\n<title>$title</title>\n";
1302     $desc .= MakeIndexterms($symbol, $id);
1303     $desc .= "\n";
1304     $desc .= OutputSymbolExtraLinks($symbol);
1306     if (@fields) {
1307         if (length ($symbol) < $SYMBOL_FIELD_WIDTH) {
1308             $synop .= (' ' x ($SYMBOL_FIELD_WIDTH - length ($symbol)));
1309         }
1310     
1311         $synop .= "(";
1312         for (my $i = 1; $i <= $#fields; $i += 2) {
1313             my $field_name = $fields[$i];
1315             if ($i == 1) {
1316                 $synop .= "$field_name";
1317             } else {
1318                 $synop .= ",\n"
1319                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1320                     . " $field_name";
1321             }
1322         }
1323         $synop .= ")";
1324     }
1325     $synop .= "\n";
1327     # Don't output the macro definition if is is a conditional macro or it
1328     # looks like a function, i.e. starts with "g_" or "_?gnome_", or it is
1329     # longer than 2 lines, otherwise we get lots of complicated macros like
1330     # g_assert.
1331     if (!defined ($DeclarationConditional{$symbol}) && ($symbol !~ m/^g_/)
1332         && ($symbol !~ m/^_?gnome_/) && (($declaration =~ tr/\n//) < 2)) {
1333         my $decl_out = &CreateValidSGML ($declaration);
1334         $desc .= "<programlisting>$decl_out</programlisting>\n";
1335     } else {
1336         $desc .= "<programlisting>" . &MakeReturnField("#define") . "$symbol";
1337         if ($declaration =~ m/^\s*#\s*define\s+\w+(\([^\)]*\))/) {
1338             my $args = $1;
1339             my $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH - length ("#define "));
1340             # Align each line so that if should all line up OK.
1341             $args =~ s/\n/\n$pad/gm;
1342             $desc .= &CreateValidSGML ($args);
1343         }
1344         $desc .= "</programlisting>\n";
1345     }
1347     $desc .= &MakeDeprecationNote($symbol);
1349     my $parameters = &OutputParamDescriptions ("MACRO", $symbol, @fields);
1350     my $parameters_output = 0;
1352     if (defined ($SymbolDocs{$symbol})) {
1353         my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1355         # Try to insert the parameter table at the author's desired position.
1356         # Otherwise we need to tag it onto the end.
1357         if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1358           $parameters_output = 1;
1359         }
1360         $desc .= $symbol_docs;
1361     }
1363     if ($parameters_output == 0) {
1364         $desc .= $parameters;
1365     }
1367     $desc .= OutputSymbolTraits ($symbol);
1368     $desc .= "</refsect2>\n";
1369     return ($synop, $desc);
1373 #############################################################################
1374 # Function    : OutputTypedef
1375 # Description : Returns the synopsis and detailed description of a typedef.
1376 # Arguments   : $symbol - the typedef.
1377 #               $declaration - the declaration of the typedef,
1378 #                 e.g. 'typedef unsigned int guint;'
1379 #############################################################################
1381 sub OutputTypedef {
1382     my ($symbol, $declaration) = @_;
1383     my $id = &CreateValidSGMLID ($symbol);
1384     my $condition = &MakeConditionDescription ($symbol);
1385     my $synop = &MakeReturnField("typedef") . "<link linkend=\"$id\">$symbol</link>;\n";
1386     my $desc = "<refsect2 id=\"$id\" role=\"typedef\"$condition>\n<title>$symbol</title>\n";
1388     $desc .= MakeIndexterms($symbol, $id);
1389     $desc .= "\n";
1390     $desc .= OutputSymbolExtraLinks($symbol);
1392     if (!defined ($DeclarationConditional{$symbol})) {
1393         my $decl_out = &CreateValidSGML ($declaration);
1394         $desc .= "<programlisting>$decl_out</programlisting>\n";
1395     }
1397     $desc .= &MakeDeprecationNote($symbol);
1399     if (defined ($SymbolDocs{$symbol})) {
1400         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1401     }
1402     $desc .= OutputSymbolTraits ($symbol);
1403     $desc .= "</refsect2>\n";
1404     return ($synop, $desc);
1408 #############################################################################
1409 # Function    : OutputStruct
1410 # Description : Returns the synopsis and detailed description of a struct.
1411 #               We check if it is a object struct, and if so we only output
1412 #               parts of it that are noted as public fields.
1413 #               We also use a different SGML ID for object structs, since the
1414 #               original ID is used for the entire RefEntry.
1415 # Arguments   : $symbol - the struct.
1416 #               $declaration - the declaration of the struct.
1417 #############################################################################
1419 sub OutputStruct {
1420     my ($symbol, $declaration) = @_;
1422     my $is_object_struct = 0;
1423     my $default_to_public = 1;
1424     if (&CheckIsObject ($symbol)) {
1425         #print "Found object struct: $symbol\n";
1426         $is_object_struct = 1;
1427         $default_to_public = 0;
1428     }
1430     my $id;
1431     my $condition;
1432     if ($is_object_struct) {
1433         $id = &CreateValidSGMLID ($symbol . "_struct");
1434         $condition = &MakeConditionDescription ($symbol . "_struct");
1435     } else {
1436         $id = &CreateValidSGMLID ($symbol);
1437         $condition = &MakeConditionDescription ($symbol);
1438     }
1440     # Determine if it is a simple struct or it also has a typedef.
1441     my $has_typedef = 0;
1442     if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1443       $has_typedef = 1;
1444     }
1446     my $synop;
1447     my $desc;
1448     if ($has_typedef) {
1449         # For structs with typedefs we just output the struct name.
1450         $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1451         $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>$symbol</title>\n";
1452     } else {
1453         $synop = &MakeReturnField("struct") . "<link linkend=\"$id\">$symbol</link>;\n";
1454         $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>struct $symbol</title>\n";
1455     }
1457     $desc .= MakeIndexterms($symbol, $id);
1458     $desc .= "\n";
1459     $desc .= OutputSymbolExtraLinks($symbol);
1461     # Form a pretty-printed, private-data-removed form of the declaration
1463     my $decl_out = "";
1464     if ($declaration =~ m/^\s*$/) {
1465         #print "Found opaque struct: $symbol\n";
1466         $decl_out = "typedef struct _$symbol $symbol;";
1467     } elsif ($declaration =~ m/^\s*struct\s+\w+\s*;\s*$/) {
1468         #print "Found opaque struct: $symbol\n";
1469         $decl_out = "struct $symbol;";
1470     } else {
1471         my $public = $default_to_public;
1472         my $new_declaration = "";
1473         my $decl_line;
1474         my $decl = $declaration;
1476         if ($decl =~ m/^\s*(typedef\s+)?struct\s*\w*\s*(?:\/\*.*\*\/)?\s*{(.*)}\s*\w*\s*;\s*$/s) {
1477             my $struct_contents = $2;
1479             foreach $decl_line (split (/\n/, $struct_contents)) {
1480                 #print "Struct line: $decl_line\n";
1481                 if ($decl_line =~ m%/\*\s*<\s*public\s*>\s*\*/%) {
1482                     $public = 1;
1483                 } elsif ($decl_line =~ m%/\*\s*<\s*(private|protected)\s*>\s*\*/%) {
1484                     $public = 0;
1485                 } elsif ($public) {
1486                     $new_declaration .= $decl_line . "\n";
1487                 }
1488             }
1490             if ($new_declaration) {
1491                 # Strip any blank lines off the ends.
1492                 $new_declaration =~ s/^\s*\n//;
1493                 $new_declaration =~ s/\n\s*$/\n/;
1495                 if ($has_typedef) {
1496                     $decl_out = "typedef struct {\n" . $new_declaration
1497                       . "} $symbol;\n";
1498                 } else {
1499                     $decl_out = "struct $symbol {\n" . $new_declaration
1500                       . "};\n";
1501                 }
1502             }
1503         } else {
1504             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1505                 "Couldn't parse struct:\n$declaration");
1506         }
1508         # If we couldn't parse the struct or it was all private, output an
1509         # empty struct declaration.
1510         if ($decl_out eq "") {
1511             if ($has_typedef) {
1512                 $decl_out = "typedef struct _$symbol $symbol;";
1513             } else {
1514                 $decl_out = "struct $symbol;";
1515             }
1516         }
1517     }
1519     $decl_out = &CreateValidSGML ($decl_out);
1520     $desc .= "<programlisting>$decl_out</programlisting>\n";
1522     $desc .= &MakeDeprecationNote($symbol);
1524     if (defined ($SymbolDocs{$symbol})) {
1525         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1526     }
1528     # Create a table of fields and descriptions
1530     # FIXME: Inserting &#160's into the produced type declarations here would
1531     #        improve the output in most situations ... except for function
1532     #        members of structs!
1533     my @fields = ParseStructDeclaration($declaration, !$default_to_public,
1534                                         0, \&MakeXRef,
1535                                         sub {
1536                                             "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1537                                         });
1538     my $params = $SymbolParams{$symbol};
1540     # If no parameters are filled in, we don't generate the description
1541     # table, for backwards compatibility
1543     my $found = 0;
1544     if (defined $params) {
1545         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1546             if ($params->[$i] =~ /\S/) {
1547                 $found = 1;
1548                 last;
1549             }
1550         }
1551     }
1553     if ($found) {
1554         my %field_descrs = @$params;
1555         my $missing_parameters = "";
1556         my $unused_parameters = "";
1558         $desc .= "<variablelist role=\"struct\">\n";
1559         while (@fields) {
1560             my $field_name = shift @fields;
1561             my $text = shift @fields;
1562             my $field_descr = $field_descrs{$field_name};
1563             my $param_annotations = "";
1565             $desc .= "<varlistentry><term>$text</term>\n";
1566             if (defined $field_descr) {
1567                 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1568                 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1569                 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1570                 delete $field_descrs{$field_name};
1571             } else {
1572                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1573                     "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1574                 if ($missing_parameters ne "") {
1575                   $missing_parameters .= ", ".$field_name;
1576                 } else {
1577                     $missing_parameters = $field_name;
1578                 }
1579                 $desc .= "<listitem />\n";
1580             }
1581             $desc .= "</varlistentry>\n";
1582         }
1583         $desc .= "</variablelist>";
1584         foreach my $field_name (keys %field_descrs) {
1585             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1586                 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1587             if ($unused_parameters ne "") {
1588               $unused_parameters .= ", ".$field_name;
1589             } else {
1590                $unused_parameters = $field_name;
1591             }
1592         }
1594         # remember missing/unused parameters (needed in tmpl-free build)
1595         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1596             $AllIncompleteSymbols{$symbol}=$missing_parameters;
1597         }
1598         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1599             $AllUnusedSymbols{$symbol}=$unused_parameters;
1600         }
1601     }
1602     else {
1603         if (scalar(@fields) > 0) {
1604             if (! exists ($AllIncompleteSymbols{$symbol})) {
1605                 $AllIncompleteSymbols{$symbol}="<items>";
1606                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1607                     "Field descriptions for $symbol are missing in source code comment block.");
1608             }
1609         }
1610     }
1612     $desc .= OutputSymbolTraits ($symbol);
1613     $desc .= "</refsect2>\n";
1614     return ($synop, $desc);
1618 #############################################################################
1619 # Function    : OutputUnion
1620 # Description : Returns the synopsis and detailed description of a union.
1621 # Arguments   : $symbol - the union.
1622 #               $declaration - the declaration of the union.
1623 #############################################################################
1625 sub OutputUnion {
1626     my ($symbol, $declaration) = @_;
1627     my $id = &CreateValidSGMLID ($symbol);
1628     my $condition = &MakeConditionDescription ($symbol);
1630     # Determine if it is a simple struct or it also has a typedef.
1631     my $has_typedef = 0;
1632     if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1633       $has_typedef = 1;
1634     }
1636     my $synop;
1637     my $desc;
1638     if ($has_typedef) {
1639         # For unions with typedefs we just output the union name.
1640         $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1641         $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>$symbol</title>\n";
1642     } else {
1643         $synop = &MakeReturnField("union") . "<link linkend=\"$id\">$symbol</link>;\n";
1644         $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>union $symbol</title>\n";
1645     }
1647     $desc .= MakeIndexterms($symbol, $id);
1648     $desc .= "\n";
1649     $desc .= OutputSymbolExtraLinks($symbol);
1651     # FIXME: we do more for structs
1652     my $decl_out = &CreateValidSGML ($declaration);
1653     $desc .= "<programlisting>$decl_out</programlisting>\n";
1655     $desc .= &MakeDeprecationNote($symbol);
1657     if (defined ($SymbolDocs{$symbol})) {
1658         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1659     }
1661     # Create a table of fields and descriptions
1663     # FIXME: Inserting &#160's into the produced type declarations here would
1664     #        improve the output in most situations ... except for function
1665     #        members of structs!
1666     my @fields = ParseStructDeclaration($declaration, 0,
1667                                         0, \&MakeXRef,
1668                                         sub {
1669                                             "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1670                                         });
1671     my $params = $SymbolParams{$symbol};
1673     # If no parameters are filled in, we don't generate the description
1674     # table, for backwards compatibility
1676     my $found = 0;
1677     if (defined $params) {
1678         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1679             if ($params->[$i] =~ /\S/) {
1680                 $found = 1;
1681                 last;
1682             }
1683         }
1684     }
1686     if ($found) {
1687         my %field_descrs = @$params;
1688         my $missing_parameters = "";
1689         my $unused_parameters = "";
1691         $desc .= "<variablelist role=\"union\">\n";
1692         while (@fields) {
1693             my $field_name = shift @fields;
1694             my $text = shift @fields;
1695             my $field_descr = $field_descrs{$field_name};
1696             my $param_annotations = "";
1698             $desc .= "<varlistentry><term>$text</term>\n";
1699             if (defined $field_descr) {
1700                 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1701                 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1702                 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1703                 delete $field_descrs{$field_name};
1704             } else {
1705                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1706                     "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1707                 if ($missing_parameters ne "") {
1708                     $missing_parameters .= ", ".$field_name;
1709                 } else {
1710                     $missing_parameters = $field_name;
1711                 }
1712                 $desc .= "<listitem />\n";
1713             }
1714             $desc .= "</varlistentry>\n";
1715         }
1716         $desc .= "</variablelist>";
1717         foreach my $field_name (keys %field_descrs) {
1718             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1719                 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1720             if ($unused_parameters ne "") {
1721               $unused_parameters .= ", ".$field_name;
1722             } else {
1723                $unused_parameters = $field_name;
1724             }
1725         }
1727         # remember missing/unused parameters (needed in tmpl-free build)
1728         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1729             $AllIncompleteSymbols{$symbol}=$missing_parameters;
1730         }
1731         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1732             $AllUnusedSymbols{$symbol}=$unused_parameters;
1733         }
1734     }
1735     else {
1736         if (scalar(@fields) > 0) {
1737             if (! exists ($AllIncompleteSymbols{$symbol})) {
1738                 $AllIncompleteSymbols{$symbol}="<items>";
1739                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1740                     "Field descriptions for $symbol are missing in source code comment block.");
1741             }
1742         }
1743     }
1745     $desc .= OutputSymbolTraits ($symbol);
1746     $desc .= "</refsect2>\n";
1747     return ($synop, $desc);
1751 #############################################################################
1752 # Function    : OutputEnum
1753 # Description : Returns the synopsis and detailed description of a enum.
1754 # Arguments   : $symbol - the enum.
1755 #               $declaration - the declaration of the enum.
1756 #############################################################################
1758 sub OutputEnum {
1759     my ($symbol, $declaration) = @_;
1760     my $id = &CreateValidSGMLID ($symbol);
1761     my $condition = &MakeConditionDescription ($symbol);
1762     my $synop = &MakeReturnField("enum") . "<link linkend=\"$id\">$symbol</link>;\n";
1763     my $desc = "<refsect2 id=\"$id\" role=\"enum\"$condition>\n<title>enum $symbol</title>\n";
1765     $desc .= MakeIndexterms($symbol, $id);
1766     $desc .= "\n";
1767     $desc .= OutputSymbolExtraLinks($symbol);
1769     my $decl_out = &CreateValidSGML ($declaration);
1770     $desc .= "<programlisting>$decl_out</programlisting>\n";
1772     $desc .= &MakeDeprecationNote($symbol);
1774     if (defined ($SymbolDocs{$symbol})) {
1775         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1776     }
1778     # Create a table of fields and descriptions
1780     my @fields = ParseEnumDeclaration($declaration);
1781     my $params = $SymbolParams{$symbol};
1783     # If no parameters are filled in, we don't generate the description
1784     # table, for backwards compatibility
1786     my $found = 0;
1787     if (defined $params) {
1788         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1789             if ($params->[$i] =~ /\S/) {
1790                 $found = 1;
1791                 last;
1792             }
1793         }
1794     }
1796     if ($found) {
1797         my %field_descrs = @$params;
1798         my $missing_parameters = "";
1799         my $unused_parameters = "";
1801         $desc .= "<variablelist role=\"enum\">\n";
1802         for my $field_name (@fields) {
1803             my $field_descr = $field_descrs{$field_name};
1804             my $param_annotations = "";
1806             $id = &CreateValidSGMLID ($field_name);
1807             $condition = &MakeConditionDescription ($field_name);
1808             $desc .= "<varlistentry id=\"$id\" role=\"constant\"$condition>\n<term><literal>$field_name</literal></term>\n";
1809             if (defined $field_descr) {
1810                 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1811                 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1812                 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1813                 delete $field_descrs{$field_name};
1814             } else {
1815                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1816                     "Value description for $symbol"."::"."$field_name is missing in source code comment block.");
1817                 if ($missing_parameters ne "") {
1818                   $missing_parameters .= ", ".$field_name;
1819                 } else {
1820                     $missing_parameters = $field_name;
1821                 }
1822                 $desc .= "<listitem />\n";
1823             }
1824             $desc .= "</varlistentry>\n";
1825         }
1826         $desc .= "</variablelist>";
1827         foreach my $field_name (keys %field_descrs) {
1828             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1829                 "Value description for $symbol"."::"."$field_name is not used from source code comment block.");
1830             if ($unused_parameters ne "") {
1831               $unused_parameters .= ", ".$field_name;
1832             } else {
1833                $unused_parameters = $field_name;
1834             }
1835         }
1837         # remember missing/unused parameters (needed in tmpl-free build)
1838         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1839             $AllIncompleteSymbols{$symbol}=$missing_parameters;
1840         }
1841         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1842             $AllUnusedSymbols{$symbol}=$unused_parameters;
1843         }
1844     }
1845     else {
1846         if (scalar(@fields) > 0) {
1847             if (! exists ($AllIncompleteSymbols{$symbol})) {
1848                 $AllIncompleteSymbols{$symbol}="<items>";
1849                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1850                     "Value descriptions for $symbol are missing in source code comment block.");
1851             }
1852         }
1853     }
1855     $desc .= OutputSymbolTraits ($symbol);
1856     $desc .= "</refsect2>\n";
1857     return ($synop, $desc);
1861 #############################################################################
1862 # Function    : OutputVariable
1863 # Description : Returns the synopsis and detailed description of a variable.
1864 # Arguments   : $symbol - the extern'ed variable.
1865 #               $declaration - the declaration of the variable.
1866 #############################################################################
1868 sub OutputVariable {
1869     my ($symbol, $declaration) = @_;
1870     my $id = &CreateValidSGMLID ($symbol);
1871     my $condition = &MakeConditionDescription ($symbol);
1873     my $synop;
1874     if ($declaration =~ m/^\s*extern\s+((const\s+|signed\s+|unsigned\s+)*\w+)(\s+\*+|\*+|\s)(\s*)([A-Za-z]\w*)\s*;/) {
1875         my $mod = defined ($1) ? $1 : "";
1876         my $ptr = defined ($3) ? $3 : "";
1877         my $space = defined ($4) ? $4 : "";
1878         $synop = &MakeReturnField("extern") . "$mod$ptr$space<link linkend=\"$id\">$symbol</link>;\n";
1880     } else {
1881         $synop = &MakeReturnField("extern") . "<link linkend=\"$id\">$symbol</link>;\n";
1882     }
1884     my $desc = "<refsect2 id=\"$id\" role=\"variable\"$condition>\n<title>$symbol</title>\n";
1886     $desc .= MakeIndexterms($symbol, $id);
1887     $desc .= "\n";
1888     $desc .= OutputSymbolExtraLinks($symbol);
1890     my $decl_out = &CreateValidSGML ($declaration);
1891     $desc .= "<programlisting>$decl_out</programlisting>\n";
1893     $desc .= &MakeDeprecationNote($symbol);
1895     if (defined ($SymbolDocs{$symbol})) {
1896         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1897     }
1898     $desc .= OutputSymbolTraits ($symbol);
1899     $desc .= "</refsect2>\n";
1900     return ($synop, $desc);
1904 #############################################################################
1905 # Function    : OutputFunction
1906 # Description : Returns the synopsis and detailed description of a function.
1907 # Arguments   : $symbol - the function.
1908 #               $declaration - the declaration of the function.
1909 #############################################################################
1911 sub OutputFunction {
1912     my ($symbol, $declaration, $symbol_type) = @_;
1913     my $id = &CreateValidSGMLID ($symbol);
1914     my $condition = &MakeConditionDescription ($symbol);
1916     # Take out the return type     $1                                                                                     $3   $4
1917     $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//;
1918     my $type_modifier = defined($1) ? $1 : "";
1919     my $type = $3;
1920     my $pointer = $4;
1921     #print "$symbol pointer is $pointer\n";
1922     my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1923     my $start = "";
1924     #if ($symbol_type eq 'USER_FUNCTION') {
1925     #    $start = "typedef ";
1926     #}
1928     # We output const rather than G_CONST_RETURN.
1929     $type_modifier =~ s/G_CONST_RETURN/const/g;
1930     $pointer =~ s/G_CONST_RETURN/const/g;
1931     $pointer =~ s/^\s+/ /g;
1933     my $ret_type_len = length ($start) + length ($type_modifier)
1934         + length ($pointer) + length ($type);
1935     my $ret_type_output;
1936     my $symbol_len;
1937     if ($ret_type_len < $RETURN_TYPE_FIELD_WIDTH) {
1938         $ret_type_output = "$start$type_modifier$xref$pointer"
1939             . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
1940         $symbol_len = 0;
1941     } else {
1942         #$ret_type_output = "$start$type_modifier$xref$pointer\n" . (' ' x $RETURN_TYPE_FIELD_WIDTH);
1944         $ret_type_output = "$start$type_modifier$xref$pointer ";
1945         $symbol_len = $ret_type_len + 1 - $RETURN_TYPE_FIELD_WIDTH;
1946     }
1948     $symbol_len += length ($symbol);
1949     my $char1 = my $char2 = my $char3 = "";
1950     if ($symbol_type eq 'USER_FUNCTION') {
1951         $symbol_len += 3;
1952         $char1 = "(";
1953         $char2 = "*";
1954         $char3 = ")";
1955     }
1957     my ($symbol_output, $symbol_desc_output);
1958     if ($symbol_len < $SYMBOL_FIELD_WIDTH) {
1959         $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3"
1960             . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1961         $symbol_desc_output = "$char1$char2$symbol$char3"
1962             . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1963     } else {
1964         $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3\n"
1965             . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1966         $symbol_desc_output = "$char1$char2$symbol$char3\n"
1967             . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1968     }
1970     my $synop = $ret_type_output . $symbol_output . '(';
1971     my $desc = "<refsect2 id=\"$id\" role=\"function\"$condition>\n<title>${symbol} ()</title>\n";
1973     $desc .= MakeIndexterms($symbol, $id);
1974     $desc .= "\n";
1975     $desc .= OutputSymbolExtraLinks($symbol);
1977     $desc  .= "<programlisting>${ret_type_output}$symbol_desc_output(";
1978     
1979     my @fields = ParseFunctionDeclaration($declaration, \&MakeXRef,
1980                                         sub {
1981                                             &tagify($_[0],"parameter");
1982                                         });
1983     
1984     for (my $i = 1; $i <= $#fields; $i += 2) {
1985         my $field_name = $fields[$i];
1986         
1987         if ($field_name eq "Varargs") {
1988             $field_name = "...";
1989         }
1991         if ($i == 1) {
1992             $synop .= "$field_name";
1993             $desc  .= "$field_name";
1994         } else {
1995             $synop .= ",\n"
1996                 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1997                 . " $field_name";
1998             $desc  .= ",\n"
1999                 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2000                 . " $field_name";
2001         }
2002         
2003     }
2005     $synop .= ");\n";
2006     $desc  .= ");</programlisting>\n";
2008     $desc .= &MakeDeprecationNote($symbol);
2010     my $parameters = &OutputParamDescriptions ("FUNCTION", $symbol, @fields);
2011     my $parameters_output = 0;
2013     if (defined ($SymbolDocs{$symbol})) {
2014         my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
2016         # Try to insert the parameter table at the author's desired position.
2017         # Otherwise we need to tag it onto the end.
2018         # FIXME: document that in the user manual and make it useable for other
2019         # types too
2020         if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
2021           $parameters_output = 1;
2022         }
2023         $desc .= $symbol_docs;
2024     }
2026     if ($parameters_output == 0) {
2027         $desc .= $parameters;
2028     }
2030     $desc .= OutputSymbolTraits ($symbol);
2031     $desc .= "</refsect2>\n";
2032     return ($synop, $desc);
2036 #############################################################################
2037 # Function    : OutputParamDescriptions
2038 # Description : Returns the DocBook output describing the parameters of a
2039 #               function, macro or signal handler.
2040 # Arguments   : $symbol_type - 'FUNCTION', 'MACRO' or 'SIGNAL'. Signal
2041 #                 handlers have an implicit user_data parameter last.
2042 #               $symbol - the name of the function/macro being described.
2043 #               @fields - parsed fields from the declaration, used to determine
2044 #                  undocumented/unused entries
2045 #############################################################################
2047 sub OutputParamDescriptions {
2048     my ($symbol_type, $symbol, @fields) = @_;
2049     my $output = "";
2050     my $params = $SymbolParams{$symbol};
2051     my $num_params = 0;
2052     my %field_descrs = ();
2054     if (@fields) {
2055         %field_descrs = @fields;
2056         delete $field_descrs{"void"};
2057         delete $field_descrs{"Returns"};
2058     }
2060     if (defined $params) {
2061         my $returns = "";
2062         my $params_desc = "";
2063         my $missing_parameters = "";
2064         my $unused_parameters = "";
2065         my $j;
2067         for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
2068             my $param_name = $$params[$j];
2069             my $param_desc = $$params[$j + 1];
2070             my $param_annotations = "";
2071             
2072             ($param_desc,$param_annotations) = & ExpandAnnotation($symbol, $param_desc);
2073             $param_desc = &ExpandAbbreviations($symbol, $param_desc);
2074             $param_desc .= $param_annotations;
2075             if ($param_name eq "Returns") {
2076                 $returns = "$param_desc";
2077             } elsif ($param_name eq "void") {
2078                 #print "!!!! void in params for $symbol?\n";
2079             } else {
2080                 if (@fields) {
2081                     if (!defined $field_descrs{$param_name}) {
2082                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2083                             "Parameter description for $symbol"."::"."$param_name is not used from source code comment block.");
2084                         if ($unused_parameters ne "") {
2085                           $unused_parameters .= ", ".$param_name;
2086                         } else {
2087                            $unused_parameters = $param_name;
2088                         }
2089                     } else {
2090                         delete $field_descrs{$param_name};
2091                     }
2092                 }
2093                 if ($param_name eq "Varargs") {
2094                     $param_name = "...";
2095                 }
2096                 if($param_desc ne "") {
2097                     $params_desc .= "<varlistentry><term><parameter>$param_name</parameter>&#160;:</term>\n<listitem><simpara>$param_desc</simpara></listitem></varlistentry>\n";
2098                     $num_params++;
2099                 }
2100             }
2101         }
2102         foreach my $param_name (keys %field_descrs) {
2103             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2104                 "Parameter description for $symbol"."::"."$param_name is missing in source code comment block.");
2105             if ($missing_parameters ne "") {
2106               $missing_parameters .= ", ".$param_name;
2107             } else {
2108                $missing_parameters = $param_name;
2109             }
2110         }
2112         # Signals have an implicit user_data parameter which we describe.
2113         if ($symbol_type eq "SIGNAL") {
2114             $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";
2115         }
2117         # Start a table if we need one.
2118         if ($params_desc || $returns) {
2119             $output .= "<variablelist role=\"params\">\n";
2120             if ($params_desc ne "") {
2121                 #$output .= "<varlistentry><term>Parameters:</term><listitem></listitem></varlistentry>\n";
2122                 $output .= $params_desc;
2123             }
2125             # Output the returns info last.
2126             if ($returns) {
2127                 $output .= "<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara>$returns</simpara></listitem></varlistentry>\n";
2128             }
2130             # Finish the table.
2131             $output .= "</variablelist>";
2132         }
2134         # remember missing/unused parameters (needed in tmpl-free build)
2135         if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
2136             $AllIncompleteSymbols{$symbol}=$missing_parameters;
2137         }
2138         if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
2139             $AllUnusedSymbols{$symbol}=$unused_parameters;
2140         }
2141     }
2142     if (($num_params == 0) && @fields && (scalar(keys(%field_descrs)) > 0)) {
2143         if (! exists ($AllIncompleteSymbols{$symbol})) {
2144             $AllIncompleteSymbols{$symbol}="<parameters>";
2145         }
2146     }
2147     
2148     return $output;
2152 #############################################################################
2153 # Function    : ParseStabilityLevel
2154 # Description : Parses a stability level and outputs a warning if it isn't
2155 #               valid.
2156 # Arguments   : $stability - the stability text.
2157 #               $file, $line - context for error message
2158 #               $message - description of where the level is from, to use in
2159 #               any error message.
2160 # Returns     : The parsed stability level string.
2161 #############################################################################
2163 sub ParseStabilityLevel {
2164     my ($stability, $file, $line, $message) = @_;
2166     $stability =~ s/^\s*//;
2167     $stability =~ s/\s*$//;
2168     if ($stability =~ m/^stable$/i) {
2169         $stability = "Stable";
2170     } elsif ($stability =~ m/^unstable$/i) {
2171         $stability = "Unstable";
2172     } elsif ($stability =~ m/^private$/i) {
2173         $stability = "Private";
2174     } else {
2175         &LogWarning ($file, $line, "$message is $stability.".
2176             "It should be one of these: Stable, Unstable, or Private.");
2177     }
2178     return $stability;
2182 #############################################################################
2183 # Function    : OutputSGMLFile
2184 # Description : Outputs the final DocBook file for one section.
2185 # Arguments   : $file - the name of the file.
2186 #               $title - the title from the $MODULE-sections.txt file, which
2187 #                 will be overridden by the title in the template file.
2188 #               $section_id - the SGML id to use for the toplevel tag.
2189 #               $includes - comma-separates list of include files added at top
2190 #                 of synopsis, with '<' '>' around them (if not already enclosed in "").
2191 #               $synopsis - reference to the DocBook for the Synopsis part.
2192 #               $details - reference to the DocBook for the Details part.
2193 #               $signal_synop - reference to the DocBook for the Signal Synopsis part
2194 #               $signal_desc - reference to the DocBook for the Signal Description part
2195 #               $args_synop - reference to the DocBook for the Arg Synopsis part
2196 #               $args_desc - reference to the DocBook for the Arg Description part
2197 #               $hierarchy - reference to the DocBook for the Object Hierarchy part
2198 #               $interfaces - reference to the DocBook for the Interfaces part
2199 #               $implementations - reference to the DocBook for the Known Implementations part
2200 #               $prerequisites - reference to the DocBook for the Prerequisites part
2201 #               $derived - reference to the DocBook for the Derived Interfaces part
2202 #               $file_objects - reference to an array of objects in this file
2203 #############################################################################
2205 sub OutputSGMLFile {
2206     my ($file, $title, $section_id, $includes, $synopsis, $details, $signals_synop, $signals_desc, $args_synop, $args_desc, $hierarchy, $interfaces, $implementations, $prerequisites, $derived, $file_objects) = @_;
2208     #print "Output sgml for file $file with title '$title'\n";
2209     
2210     # The edited title overrides the one from the sections file.
2211     my $new_title = $SymbolDocs{"$TMPL_DIR/$file:Title"};
2212     if (defined ($new_title) && $new_title !~ m/^\s*$/) {
2213         $title = $new_title;
2214         #print "Found title: $title\n";
2215     }
2216     my $short_desc = $SymbolDocs{"$TMPL_DIR/$file:Short_Description"};
2217     if (!defined ($short_desc) || $short_desc =~ m/^\s*$/) {
2218         $short_desc = "";
2219     } else {
2220         $short_desc = &ExpandAbbreviations("$title:Short_description",
2221                                            $short_desc);
2222         #print "Found short_desc: $short_desc";
2223     }
2224     my $long_desc = $SymbolDocs{"$TMPL_DIR/$file:Long_Description"};
2225     if (!defined ($long_desc) || $long_desc =~ m/^\s*$/) {
2226         $long_desc = "";
2227     } else {
2228         $long_desc = &ExpandAbbreviations("$title:Long_description",
2229                                           $long_desc);
2230         #print "Found long_desc: $long_desc";
2231     }
2232     my $see_also = $SymbolDocs{"$TMPL_DIR/$file:See_Also"};
2233     if (!defined ($see_also) || $see_also =~ m%^\s*(<para>)?\s*(</para>)?\s*$%) {
2234         $see_also = "";
2235     } else {
2236         $see_also = &ExpandAbbreviations("$title:See_Also", $see_also);
2237         #print "Found see_also: $see_also";
2238     }
2239     if ($see_also) {
2240         $see_also = "<refsect1 id=\"$section_id.see-also\">\n<title>See Also</title>\n$see_also\n</refsect1>\n";
2241     }
2242     my $stability = $SymbolDocs{"$TMPL_DIR/$file:Stability_Level"};
2243     if (!defined ($stability) || $stability =~ m/^\s*$/) {
2244         $stability = "";
2245     } else {
2246         $stability = &ParseStabilityLevel($stability, $file, $., "Section stability level");
2247         #print "Found stability: $stability";
2248     }
2249     if ($stability) {
2250         $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$stability, unless otherwise indicated\n</refsect1>\n";
2251     } elsif ($DEFAULT_STABILITY) {
2252         $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$DEFAULT_STABILITY, unless otherwise indicated\n</refsect1>\n";
2253     }
2255     my $image = $SymbolDocs{"$TMPL_DIR/$file:Image"};
2256     if (!defined ($image) || $image =~ m/^\s*$/) {
2257       $image = "";
2258     } else {
2259       $image =~ s/^\s*//;
2260       $image =~ s/\s*$//;
2262       my $format;
2264       if ($image =~ /jpe?g$/i) {
2265         $format = "format='JPEG'";
2266       } elsif ($image =~ /png$/i) {
2267         $format = "format='PNG'";
2268       } elsif ($image =~ /svg$/i) {
2269         $format = "format='SVG'";
2270       } else {
2271         $format = "";
2272       }
2274       $image = "  <inlinegraphic fileref='$image' $format/>\n"
2275     }
2277     my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
2278         gmtime (time);
2279     my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
2280     $year += 1900;
2282     my $include_output = "";
2283     my $include;
2284     foreach $include (split (/,/, $includes)) {
2285         if ($include =~ m/^\".+\"$/) {
2286             $include_output .= "#include ${include}\n";
2287         }
2288         else {
2289             $include =~ s/^\s+|\s+$//gs;
2290             $include_output .= "#include &lt;${include}&gt;\n";
2291         }
2292     }
2293     if ($include_output ne '') {
2294         $include_output = "\n$include_output\n";
2295     }
2296     
2297     my $extralinks = OutputSectionExtraLinks($title,"Section:$file");
2299     my $old_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT";
2300     my $new_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT.new";
2302     open (OUTPUT, ">$new_sgml_file")
2303         || die "Can't create $new_sgml_file: $!";
2305     my $object_anchors = "";
2306     foreach my $object (@$file_objects) {
2307         next if ($object eq $section_id);
2308         my $id = CreateValidSGMLID($object);
2309         #print "Debug: Adding anchor for $object\n";
2310         $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
2311     }
2313     # We used to output this, but is messes up our UpdateFileIfChanged code
2314     # since it changes every day (and it is only used in the man pages):
2315     # "<refentry id="$section_id" revision="$mday $month $year">"
2317     if ($OUTPUT_FORMAT eq "xml") {
2318         print OUTPUT $doctype_header;
2319     }
2321     print OUTPUT <<EOF;
2322 <refentry id="$section_id">
2323 <refmeta>
2324 <refentrytitle role="top_of_page" id="$section_id.top_of_page">$title</refentrytitle>
2325 <manvolnum>3</manvolnum>
2326 <refmiscinfo>
2327   \U$MODULE\E Library
2328 $image</refmiscinfo>
2329 </refmeta>
2330 <refnamediv>
2331 <refname>$title</refname>
2332 <refpurpose>$short_desc</refpurpose>
2333 </refnamediv>
2334 $stability
2335 <refsynopsisdiv id="$section_id.synopsis" role="synopsis">
2336 <title role="synopsis.title">Synopsis</title>
2337 $object_anchors
2338 <synopsis>$include_output$${synopsis}</synopsis>
2339 </refsynopsisdiv>
2340 $$hierarchy$$prerequisites$$derived$$interfaces$$implementations$$args_synop$$signals_synop
2341 <refsect1 id="$section_id.description" role="desc">
2342 <title role="desc.title">Description</title>
2343 $extralinks$long_desc
2344 </refsect1>
2345 <refsect1 id="$section_id.details" role="details">
2346 <title role="details.title">Details</title>
2347 $$details
2348 </refsect1>
2349 $$args_desc$$signals_desc$see_also
2350 </refentry>
2352     close (OUTPUT);
2354     return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2358 #############################################################################
2359 # Function    : OutputExtraFile
2360 # Description : Copies an "extra" DocBook file into the output directory,
2361 #               expanding abbreviations
2362 # Arguments   : $file - the source file.
2363 #############################################################################
2364 sub OutputExtraFile {
2365     my ($file) = @_;
2367     my $basename;
2369     ($basename = $file) =~ s!^.*/!!;
2371     my $old_sgml_file = "$SGML_OUTPUT_DIR/$basename";
2372     my $new_sgml_file = "$SGML_OUTPUT_DIR/$basename.new";
2374     my $contents;
2376     open(EXTRA_FILE, "<$file") || die "Can't open $file";
2378     {
2379         local $/;
2380         $contents = <EXTRA_FILE>;
2381     }
2383     open (OUTPUT, ">$new_sgml_file")
2384         || die "Can't create $new_sgml_file: $!";
2386     print OUTPUT &ExpandAbbreviations ("$basename file", $contents);
2387     close (OUTPUT);
2389     return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2391 #############################################################################
2392 # Function    : OutputBook
2393 # Description : Outputs the SGML entities that need to be included into the
2394 #               main SGML file for the module.
2395 # Arguments   : $book_top - the declarations of the entities, which are added
2396 #                 at the top of the main SGML file.
2397 #               $book_bottom - the references to the entities, which are
2398 #                 added in the main SGML file at the desired position.
2399 #############################################################################
2401 sub OutputBook {
2402     my ($book_top, $book_bottom) = @_;
2404     my $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top";
2405     my $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top.new";
2407     open (OUTPUT, ">$new_file")
2408         || die "Can't create $new_file: $!";
2409     print OUTPUT $book_top;
2410     close (OUTPUT);
2412     &UpdateFileIfChanged ($old_file, $new_file, 0);
2415     $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom";
2416     $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom.new";
2418     open (OUTPUT, ">$new_file")
2419         || die "Can't create $new_file: $!";
2420     print OUTPUT $book_bottom;
2421     close (OUTPUT);
2423     &UpdateFileIfChanged ($old_file, $new_file, 0);
2426     # If the main SGML/XML file hasn't been created yet, we create it here.
2427     # The user can tweak it later.
2428     if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
2429       open (OUTPUT, ">$MAIN_SGML_FILE")
2430         || die "Can't create $MAIN_SGML_FILE: $!";
2432       if ($OUTPUT_FORMAT eq "xml") {
2433           print OUTPUT <<EOF;
2434 <?xml version="1.0"?>
2435 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
2436                "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
2438   <!ENTITY % local.common.attrib "xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'">
2440 <book id="index">
2442       } else {
2443         print OUTPUT <<EOF;
2444 <!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
2445 $book_top
2447 <book id="index">
2449       }
2451 print OUTPUT <<EOF;
2452   <bookinfo>
2453     <title>$MODULE Reference Manual</title>
2454     <releaseinfo>
2455       for $MODULE [VERSION].
2456       The latest version of this documentation can be found on-line at
2457       <ulink role="online-location" url="http://[SERVER]/$MODULE/index.html">http://[SERVER]/$MODULE/</ulink>.
2458     </releaseinfo>
2459   </bookinfo>
2461   <chapter>
2462     <title>[Insert title here]</title>
2463     $book_bottom
2464   </chapter>
2466   if (-e $OBJECT_TREE_FILE) {
2467     print OUTPUT <<EOF;
2468   <chapter id="object-tree">
2469     <title>Object Hierarchy</title>
2470      <xi:include href="xml/tree_index.sgml"/>
2471   </chapter>
2473   }
2475 print OUTPUT <<EOF;
2476   <index id="api-index-full">
2477     <title>API Index</title>
2478     <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
2479   </index>
2481   <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
2482 </book>
2485       close (OUTPUT);
2486     }
2490 #############################################################################
2491 # Function    : CreateValidSGML
2492 # Description : This turns any chars which are used in SGML into entities,
2493 #               e.g. '<' into '&lt;'
2494 # Arguments   : $text - the text to turn into proper SGML.
2495 #############################################################################
2497 sub CreateValidSGML {
2498     my ($text) = @_;
2499     $text =~ s/&/&amp;/g;       # Do this first, or the others get messed up.
2500     $text =~ s/</&lt;/g;
2501     $text =~ s/>/&gt;/g;
2502     # browers render single tabs inconsistently
2503     $text =~ s/([^\s])\t([^\s])/$1&#160;$2/g;
2504     return $text;
2507 #############################################################################
2508 # Function    : ConvertSGMLChars
2509 # Description : This is used for text in source code comment blocks, to turn
2510 #               chars which are used in SGML into entities, e.g. '<' into
2511 #               '&lt;'. Depending on $SGML_MODE, this is done
2512 #               unconditionally or only if the character doesn't seem to be
2513 #               part of an SGML construct (tag or entity reference).
2514 # Arguments   : $text - the text to turn into proper SGML.
2515 #############################################################################
2517 sub ConvertSGMLChars {
2518     my ($symbol, $text) = @_;
2520     if ($SGML_MODE) {
2521         # For the SGML mode only convert to entities outside CDATA sections.
2522         return &ModifyXMLElements ($text, $symbol,
2523                                    "<!\\[CDATA\\[|<programlisting[^>]*>",
2524                                    \&ConvertSGMLCharsEndTag,
2525                                    \&ConvertSGMLCharsCallback);
2526     } else {
2527         # For the simple non-sgml mode, convert to entities everywhere.
2528         $text =~ s/&/&amp;/g;   # Do this first, or the others get messed up.
2529         $text =~ s/</&lt;/g;
2530         $text =~ s/>/&gt;/g;
2531         return $text;
2532     }
2536 sub ConvertSGMLCharsEndTag {
2537   if ($_[0] eq "<!\[CDATA\[") {
2538     return "]]>";
2539   } else {
2540     return "</programlisting>";
2541   }
2544 sub ConvertSGMLCharsCallback {
2545   my ($text, $symbol, $tag) = @_;
2547   if ($tag =~ m/^<programlisting/) {
2548     # We can handle <programlisting> specially here.
2549     return &ModifyXMLElements ($text, $symbol,
2550                                "<!\\[CDATA\\[",
2551                                \&ConvertSGMLCharsEndTag,
2552                                \&ConvertSGMLCharsCallback2);
2553   } elsif ($tag eq "") {
2554     # If we're not in CDATA convert to entities.
2555     $text =~ s/&(?![a-zA-Z#]+;)/&amp;/g;        # Do this first, or the others get messed up.
2556     $text =~ s/<(?![a-zA-Z\/!])/&lt;/g;
2557     $text =~ s/(?<![a-zA-Z0-9"'\/-])>/&gt;/g;
2559     # Handle "#include <xxxxx>"
2560     $text =~ s/#include(\s+)<([^>]+)>/#include$1&lt;$2&gt;/g;
2561   }
2563   return $text;
2566 sub ConvertSGMLCharsCallback2 {
2567   my ($text, $symbol, $tag) = @_;
2569   # If we're not in CDATA convert to entities.
2570   # We could handle <programlisting> differently, though I'm not sure it helps.
2571   if ($tag eq "") {
2572     # replace only if its not a tag
2573     $text =~ s/&(?![a-zA-Z#]+;)/&amp;/g;        # Do this first, or the others get messed up.
2574     $text =~ s/<(?![a-zA-Z\/!])/&lt;/g;
2575     $text =~ s/(?<![a-zA-Z0-9"'\/-])>/&gt;/g;
2577     # Handle "#include <xxxxx>"
2578     $text =~ s/#include(\s+)<([^>]+)>/#include$1&lt;$2&gt;/g;
2579   }
2581   return $text;
2584 #############################################################################
2585 # Function    : ExpandAnnotation
2586 # Description : This turns annotations into acrony tags.
2587 # Arguments   : $symbol - the symbol being documented, for error messages.
2588 #               $text - the text to expand.
2589 #############################################################################
2590 sub ExpandAnnotation {
2591     my ($symbol, $param_desc) = @_;
2592     my $param_annotations = "";
2593     
2594     if ($param_desc =~ m%\s*\((.*)\):%) {
2595         my @annotations;
2596         my $annotation;
2597         my $annotation_extra = "";
2598         $param_desc = $';
2599     
2600         @annotations = split(/\)\s*\(/,$1);
2601         foreach $annotation (@annotations) {
2602             # need to search for the longest key-match in %AnnotationDefinition
2603             my $match_length=0;
2604             my $match_annotation="";
2605             my $annotationdef;
2606             foreach $annotationdef (keys %AnnotationDefinition) {
2607                 if ($annotation =~ m/^$annotationdef/) {
2608                     if (length($annotationdef)>$match_length) {
2609                         $match_length=length($annotationdef);
2610                         $match_annotation=$annotationdef;
2611                     }
2612                 }
2613             }
2614             if ($match_annotation ne "") {
2615                 if ($annotation =~ m%$match_annotation\s+(.*)%) {
2616                     $annotation_extra = " $1";
2617                 }
2618                 $AnnotationsUsed{$match_annotation} = 1;
2619                 $param_annotations .= "<acronym>$match_annotation</acronym>$annotation_extra. ";
2620             }
2621             else {
2622                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2623                     "unknown annotation \"$annotation\" in documentation for $symbol.");
2624                 $param_annotations=$annotation;
2625             }
2626         }
2627         chomp($param_desc);
2628         $param_desc =~ m/^(.*)\.*\s*$/s;
2629         $param_desc = "$1. ";
2630     }    
2631     return ($param_desc, $param_annotations);
2634 #############################################################################
2635 # Function    : ExpandAbbreviations
2636 # Description : This turns the abbreviations function(), macro(), @param,
2637 #               %constant, and #symbol into appropriate DocBook markup.
2638 #               CDATA sections and <programlisting> parts are skipped.
2639 # Arguments   : $symbol - the symbol being documented, for error messages.
2640 #               $text - the text to expand.
2641 #############################################################################
2643 sub ExpandAbbreviations {
2644   my ($symbol, $text) = @_;
2646   # Convert "|[" and "]|" into the start and end of program listing examples.
2647   $text =~ s%\|\[%<informalexample><programlisting>%g;
2648   $text =~ s%\]\|%</programlisting></informalexample>%g;
2649   # TODO: check for a xml comment after |[ and pick the language attribute from
2650   # that
2652   # keep CDATA unmodified, preserve ulink tags (ideally we preseve all tags
2653   # as such)
2654   return &ModifyXMLElements ($text, $symbol,
2655                              "<!\\[CDATA\\[|<ulink[^>]*>|<programlisting[^>]*>|<!DOCTYPE",
2656                              \&ExpandAbbreviationsEndTag,
2657                              \&ExpandAbbreviationsCallback);
2661 # Returns the end tag corresponding to the given start tag.
2662 sub ExpandAbbreviationsEndTag {
2663   my ($start_tag) = @_;
2665   if ($start_tag eq "<!\[CDATA\[") {
2666     return "]]>";
2667   } elsif ($start_tag eq "<!DOCTYPE") {
2668     return "]>";
2669   } elsif ($start_tag =~ m/<(\w+)/) {
2670     return "</$1>";
2671   }
2674 # Called inside or outside each CDATA or <programlisting> section.
2675 sub ExpandAbbreviationsCallback {
2676   my ($text, $symbol, $tag) = @_;
2678   if ($tag =~ m/^<programlisting/) {
2679     # Handle any embedded CDATA sections.
2680     return &ModifyXMLElements ($text, $symbol,
2681                                "<!\\[CDATA\\[",
2682                                \&ExpandAbbreviationsEndTag,
2683                                \&ExpandAbbreviationsCallback2);
2684   } elsif ($tag eq "") {
2685     # We are outside any CDATA or <programlisting> sections, so we expand
2686     # any gtk-doc abbreviations.
2688     # Convert 'function()' or 'macro()'.
2689     # if there is abc_*_def() we don't want to make a link to _def()
2690     # FIXME: also handle abc(....) : but that would need to be done recursively :/
2691     $text =~ s/([^\*.\w])(\w+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2692     # handle #Object.func()
2693     $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2695     # Convert '@param', but not '\@param'.
2696     $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)/$1<parameter>$2<\/parameter>/g;
2697     $text =~ s/\\\@/\@/g;
2699     # Convert '%constant', but not '\%constant'.
2700     # Also allow negative numbers, e.g. %-1.
2701     $text =~ s/(\A|[^\\])\%(-?\w+)/$1.&MakeXRef($2, &tagify($2, "literal"));/eg;
2702     $text =~ s/\\\%/\%/g;
2704     # Convert '#symbol', but not '\#symbol'.
2705     $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)/$1.&MakeHashXRef($2, "type");/eg;
2706     $text =~ s/\\#/#/g;
2707     
2708     # Expand urls
2709     # FIXME: should we skip urls that are already tagged? (e.g. <literal>http://...</literal>)
2710     # this is apparently also called for markup and not just for plain text
2711     # disable for now.
2712     #$text =~ s%(http|https|ftp)://(.*?)((?:\s|,|\)|\]|\<|\.\s))%<ulink url="$1://$2">$2</ulink>$3%g;
2714     # TODO: optionally check all words from $text against internal symbols and
2715     # warn if those could be xreffed, but miss a %,# or ()
2716   }
2718   return $text;
2721 # This is called inside a <programlisting>
2722 sub ExpandAbbreviationsCallback2 {
2723   my ($text, $symbol, $tag) = @_;
2725   if ($tag eq "") {
2726     # We are inside a <programlisting> but outside any CDATA sections,
2727     # so we expand any gtk-doc abbreviations.
2728     # FIXME: why is this different from &ExpandAbbreviationsCallback(),
2729     #        why not just call it
2730     $text =~ s/#(\w+)/&MakeHashXRef($1, "");/eg;
2731   }
2733   return $text;
2736 sub MakeHashXRef {
2737     my ($symbol, $tag) = @_;;
2738     my $text = $symbol;
2740     # Check for things like '#include', '#define', and skip them.
2741     if ($PreProcessorDirectives{$symbol}) {
2742       return "#$symbol";
2743     }
2745     # Get rid of any special '-struct' suffix.
2746     $text =~ s/-struct$//;
2748     # If the symbol is in the form "Object::signal", then change the symbol to
2749     # "Object-signal" and use "signal" as the text.
2750     if ($symbol =~ s/::/-/) {
2751       $text = "\"$'\"";
2752     }
2754     # If the symbol is in the form "Object:property", then change the symbol to
2755     # "Object--property" and use "property" as the text.
2756     if ($symbol =~ s/:/--/) {
2757       $text = "\"$'\"";
2758     }
2760     if ($tag ne "") {
2761       $text = tagify ($text, $tag);
2762     }
2763     
2764     return &MakeXRef($symbol, $text);
2768 #############################################################################
2769 # Function    : ModifyXMLElements
2770 # Description : Looks for given XML element tags within the text, and calls
2771 #               the callback on pieces of text inside & outside those elements.
2772 #               Used for special handling of text inside things like CDATA
2773 #               and <programlisting>.
2774 # Arguments   : $text - the text.
2775 #               $symbol - the symbol currently being documented (only used for
2776 #                      error messages).
2777 #               $start_tag_regexp - the regular expression to match start tags.
2778 #                      e.g. "<!\\[CDATA\\[|<programlisting[^>]*>" to match
2779 #                      CDATA sections or programlisting elements.
2780 #               $end_tag_func - function which is passed the matched start tag
2781 #                      and should return the appropriate end tag string.
2782 #               $callback - callback called with each part of the text. It is
2783 #                      called with a piece of text, the symbol being
2784 #                      documented, and the matched start tag or "" if the text
2785 #                      is outside the XML elements being matched.
2786 #############################################################################
2787 sub ModifyXMLElements {
2788     my ($text, $symbol, $start_tag_regexp, $end_tag_func, $callback) = @_;
2789     my ($before_tag, $start_tag, $end_tag_regexp, $end_tag);
2790     my $result = "";
2792     while ($text =~ m/$start_tag_regexp/s) {
2793       $before_tag = $`; # Prematch for last successful match string
2794       $start_tag = $&;  # Last successful match
2795       $text = $';       # Postmatch for last successful match string
2797       $result .= &$callback ($before_tag, $symbol, "");
2798       $result .= $start_tag;
2800       # get the mathing end-tag for current tag
2801       $end_tag_regexp = &$end_tag_func ($start_tag);
2803       if ($text =~ m/$end_tag_regexp/s) {
2804         $before_tag = $`;
2805         $end_tag = $&;
2806         $text = $';
2808         $result .= &$callback ($before_tag, $symbol, $start_tag);
2809         $result .= $end_tag;
2810       } else {
2811         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2812             "Can't find tag end: $end_tag_regexp in docs for: $symbol.");
2813         # Just assume it is all inside the tag.
2814         $result .= &$callback ($text, $symbol, $start_tag);
2815         $text = "";
2816       }
2817     }
2819     # Handle any remaining text outside the tags.
2820     $result .= &$callback ($text, $symbol, "");
2822     return $result;
2825 sub noop {
2826   return $_[0];
2829 # Adds a tag around some text.
2830 # e.g tagify("Text", "literal") => "<literal>Text</literal>".
2831 sub tagify {
2832    my ($text, $elem) = @_;
2833    return "<" . $elem . ">" . $text . "</" . $elem . ">";
2837 #############################################################################
2838 # Function    : MakeXRef
2839 # Description : This returns a cross-reference link to the given symbol.
2840 #               Though it doesn't try to do this for a few standard C types
2841 #               that it knows won't be in the documentation.
2842 # Arguments   : $symbol - the symbol to try to create a XRef to.
2843 #               $text - text text to put inside the XRef, defaults to $symbol
2844 #############################################################################
2846 sub MakeXRef {
2847     my ($symbol, $text) = ($_[0], $_[1]);
2849     $symbol =~ s/^\s+//;
2850     $symbol =~ s/\s+$//;
2852     if (!defined($text)) {
2853         $text = $symbol;
2855         # Get rid of special '-struct' suffix.
2856         $text =~ s/-struct$//;
2857     }
2859     if ($symbol =~ m/ /) {
2860         return "$text";
2861     }
2863     #print "Getting type link for $symbol -> $text\n";
2865     my $symbol_id = &CreateValidSGMLID ($symbol);
2866     return "<link linkend=\"$symbol_id\">$text</link>";
2870 #############################################################################
2871 # Function    : MakeIndexterms
2872 # Description : This returns a indexterm elements for the given symbol
2873 # Arguments   : $symbol - the symbol to create indexterms for
2874 #############################################################################
2876 sub MakeIndexterms {
2877   my ($symbol, $id) = @_;
2878   my $terms =  "";
2879   my $sortas = "";
2880   
2881   # make the index useful, by ommiting the namespace when sorting
2882   if ($NAME_SPACE ne "") {
2883     if ($symbol =~ m/^$NAME_SPACE\_?(.*)/i) {
2884        $sortas=" sortas=\"$1\"";
2885     }
2886   }
2888   if (exists $Deprecated{$symbol}) {
2889       $terms .= "<indexterm zone=\"$id\" role=\"deprecated\"><primary$sortas>$symbol</primary></indexterm>";
2890       $IndexEntriesDeprecated{$symbol}=$id;
2891       $IndexEntriesFull{$symbol}=$id;
2892   }
2893   if (exists $Since{$symbol}) {
2894      my $since = $Since{$symbol};
2895      $since =~ s/^\s+//;
2896      $since =~ s/\s+$//;
2897      if ($since ne "") {
2898          $terms .= "<indexterm zone=\"$id\" role=\"$since\"><primary$sortas>$symbol</primary></indexterm>";
2899      }
2900      $IndexEntriesSince{$symbol}=$id;
2901      $IndexEntriesFull{$symbol}=$id;
2902   }
2903   if ($terms eq "") {
2904      $terms .= "<indexterm zone=\"$id\"><primary$sortas>$symbol</primary></indexterm>";
2905      $IndexEntriesFull{$symbol}=$id;
2906   }
2908   return $terms;
2911 #############################################################################
2912 # Function    : MakeDeprecationNote
2913 # Description : This returns a deprecation warning for the given symbol.
2914 # Arguments   : $symbol - the symbol to try to create a warning for.
2915 #############################################################################
2917 sub MakeDeprecationNote {
2918     my ($symbol) = $_[0];
2919     my $desc = "";
2920     my $note = "";
2921     if (exists $Deprecated{$symbol}) {
2922         $desc .= "<warning>";
2924         if ($Deprecated{$symbol} =~ /^\s*([0-9\.]+)\s*:/) {
2925                 $desc .= "<para><literal>$symbol</literal> has been deprecated since version $1 and should not be used in newly-written code.";
2926         } else {
2927                 $desc .= "<para><literal>$symbol</literal> is deprecated and should not be used in newly-written code.";
2928         }
2929         if ($Deprecated{$symbol} ne "") {
2930             $note = &ExpandAbbreviations($symbol, $Deprecated{$symbol});
2931             $note =~ s/^\s*([0-9\.]+)\s*:\s*//;
2932             $note =~ s/^\s+//;
2933             $note =~ s/\s+$//;
2934             $note =~ s%\n{2,}%\n</para>\n<para>\n%g;
2935             $desc .= " " . $note;
2936         }
2937         $desc .= "</para></warning>\n";
2938     }
2939     return $desc;
2942 #############################################################################
2943 # Function    : MakeConditionDescription
2944 # Description : This returns a sumary of conditions for the given symbol.
2945 # Arguments   : $symbol - the symbol to try to create the sumary.
2946 #############################################################################
2948 sub MakeConditionDescription {
2949     my ($symbol) = $_[0];
2950     my $desc = "";
2952     if (exists $Deprecated{$symbol}) {
2953         if ($desc ne "") {
2954             $desc .= "|";
2955         }
2957         if ($Deprecated{$symbol} =~ /^\s*(.*?)\s*$/) {
2958                 $desc .= "deprecated:$1";
2959         } else {
2960                 $desc .= "deprecated";
2961         }
2962     }
2964     if (exists $Since{$symbol}) {
2965         if ($desc ne "") {
2966             $desc .= "|";
2967         }
2969         if ($Since{$symbol} =~ /^\s*(.*?)\s*$/) {
2970                 $desc .= "since:$1";
2971         } else {
2972                 $desc .= "since";
2973         }
2974     }
2976     if (exists $StabilityLevel{$symbol}) {
2977         if ($desc ne "") {
2978             $desc .= "|";
2979         }
2980         $desc .= "stability:".$StabilityLevel{$symbol};
2981     }
2983     if ($desc ne "") {
2984         $desc=" condition=\"".$desc."\"";
2985         #print "condition for '$symbol' = '$desc'\n";
2986     }
2987     return $desc;
2990 #############################################################################
2991 # Function    : GetHierarchy
2992 # Description : Returns the DocBook output describing the ancestors and
2993 #               immediate children of a GObject subclass. It uses the
2994 #               global @Objects and @ObjectLevels arrays to walk the tree.
2995 # Arguments   : $object - the GtkObject subclass.
2996 #############################################################################
2998 sub GetHierarchy {
2999     my ($object) = @_;
3001     # Find object in the objects array.
3002     my $found = 0;
3003     my @children = ();
3004     my $i;
3005     my $level;
3006     my $j;
3007     for ($i = 0; $i < @Objects; $i++) {
3008         if ($found) {
3009             if ($ObjectLevels[$i] <= $level) {
3010             last;
3011         }
3012             elsif ($ObjectLevels[$i] == $level + 1) {
3013                 push (@children, $Objects[$i]);
3014             }
3015         }
3016         elsif ($Objects[$i] eq $object) {
3017             $found = 1;
3018             $j = $i;
3019             $level = $ObjectLevels[$i];
3020         }
3021     }
3022     if (!$found) {
3023         return "";
3024     }
3026     # Walk up the hierarchy, pushing ancestors onto the ancestors array.
3027     my @ancestors = ();
3028     push (@ancestors, $object);
3029     #print "Level: $level\n";
3030     while ($level > 1) {
3031         $j--;
3032         if ($ObjectLevels[$j] < $level) {
3033             push (@ancestors, $Objects[$j]);
3034             $level = $ObjectLevels[$j];
3035             #print "Level: $level\n";
3036         }
3037     }
3039     # Output the ancestors list, indented and with links.
3040     my $hierarchy = "<synopsis>\n";
3041     $level = 0;
3042     for ($i = $#ancestors; $i >= 0; $i--) {
3043         my $link_text;
3044         # Don't add a link to the current object, i.e. when i == 0.
3045         if ($i > 0) {
3046             my $ancestor_id = &CreateValidSGMLID ($ancestors[$i]);
3047             $link_text = "<link linkend=\"$ancestor_id\">$ancestors[$i]</link>";
3048         } else {
3049             $link_text = "$ancestors[$i]";
3050         }
3051         if ($level == 0) {
3052             $hierarchy .= "  $link_text\n";
3053         } else {
3054 #           $hierarchy .= ' ' x ($level * 6 - 3) . "|\n";
3055             $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3056         }
3057         $level++;
3058     }
3059     for ($i = 0; $i <= $#children; $i++) {
3060       my $id = &CreateValidSGMLID ($children[$i]);
3061       my $link_text = "<link linkend=\"$id\">$children[$i]</link>";
3062       $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3063     }
3064     $hierarchy .= "</synopsis>\n";
3066     return $hierarchy;
3070 #############################################################################
3071 # Function    : GetInterfaces
3072 # Description : Returns the DocBook output describing the interfaces
3073 #               implemented by a class. It uses the global %Interfaces hash.
3074 # Arguments   : $object - the GtkObject subclass.
3075 #############################################################################
3077 sub GetInterfaces {
3078     my ($object) = @_;
3079     my $text = "";
3080     my $i;
3082     # Find object in the objects array.
3083     if (exists($Interfaces{$object})) {
3084         my @ifaces = split(' ', $Interfaces{$object});
3085         $text = <<EOF;
3086 <para>
3087 $object implements
3089         for ($i = 0; $i <= $#ifaces; $i++) {
3090             my $id = &CreateValidSGMLID ($ifaces[$i]);
3091             $text .= " <link linkend=\"$id\">$ifaces[$i]</link>";
3092             if ($i < $#ifaces - 1) {
3093                 $text .= ', ';
3094             }
3095             elsif ($i < $#ifaces) {
3096                 $text .= ' and ';
3097             }
3098             else {
3099                 $text .= '.';
3100             }
3101         }
3102         $text .= <<EOF;
3103 </para>
3105     }
3107     return $text;
3110 #############################################################################
3111 # Function    : GetImplementations
3112 # Description : Returns the DocBook output describing the implementations
3113 #               of an interface. It uses the global %Interfaces hash.
3114 # Arguments   : $object - the GtkObject subclass.
3115 #############################################################################
3117 sub GetImplementations {
3118     my ($object) = @_;
3119     my @impls = ();
3120     my $text = "";
3121     my $i;
3122     foreach my $key (keys %Interfaces) {
3123         if ($Interfaces{$key} =~ /\b$object\b/) {
3124             push (@impls, $key);
3125         }
3126     }
3127     if ($#impls >= 0) {
3128         @impls = sort @impls;
3129         $text = <<EOF;
3130 <para>
3131 $object is implemented by
3133         for ($i = 0; $i <= $#impls; $i++) {
3134             my $id = &CreateValidSGMLID ($impls[$i]);
3135             $text .= " <link linkend=\"$id\">$impls[$i]</link>";
3136             if ($i < $#impls - 1) {
3137                 $text .= ', ';
3138             }
3139             elsif ($i < $#impls) {
3140                 $text .= ' and ';
3141             }
3142             else {
3143                 $text .= '.';
3144             }
3145         }
3146         $text .= <<EOF;
3147 </para>
3149     }
3150     return $text;
3154 #############################################################################
3155 # Function    : GetPrerequisites
3156 # Description : Returns the DocBook output describing the prerequisites
3157 #               of an interface. It uses the global %Prerequisites hash.
3158 # Arguments   : $iface - the interface.
3159 #############################################################################
3161 sub GetPrerequisites {
3162     my ($iface) = @_;
3163     my $text = "";
3164     my $i;
3166     if (exists($Prerequisites{$iface})) {
3167         $text = <<EOF;
3168 <para>
3169 $iface requires
3171         my @prereqs = split(' ', $Prerequisites{$iface});
3172         for ($i = 0; $i <= $#prereqs; $i++) {
3173             my $id = &CreateValidSGMLID ($prereqs[$i]);
3174             $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
3175             if ($i < $#prereqs - 1) {
3176                 $text .= ', ';
3177             }
3178             elsif ($i < $#prereqs) {
3179                 $text .= ' and ';
3180             }
3181             else {
3182                 $text .= '.';
3183             }
3184         }
3185         $text .= <<EOF;
3186 </para>
3188     }
3189     return $text;
3192 #############################################################################
3193 # Function    : GetDerived
3194 # Description : Returns the DocBook output describing the derived interfaces
3195 #               of an interface. It uses the global %Prerequisites hash.
3196 # Arguments   : $iface - the interface.
3197 #############################################################################
3199 sub GetDerived {
3200     my ($iface) = @_;
3201     my $text = "";
3202     my $i;
3204     my @derived = ();
3205     foreach my $key (keys %Prerequisites) {
3206         if ($Prerequisites{$key} =~ /\b$iface\b/) {
3207             push (@derived, $key);
3208         }
3209     }
3210     if ($#derived >= 0) {
3211         @derived = sort @derived;
3212         $text = <<EOF;
3213 <para>
3214 $iface is required by
3216         for ($i = 0; $i <= $#derived; $i++) {
3217             my $id = &CreateValidSGMLID ($derived[$i]);
3218             $text .= " <link linkend=\"$id\">$derived[$i]</link>";
3219             if ($i < $#derived - 1) {
3220                 $text .= ', ';
3221             }
3222             elsif ($i < $#derived) {
3223                 $text .= ' and ';
3224             }
3225             else {
3226                 $text .= '.';
3227             }
3228         }
3229         $text .= <<EOF;
3230 </para>
3232     }
3233     return $text;
3237 #############################################################################
3238 # Function    : GetSignals
3239 # Description : Returns the synopsis and detailed description DocBook output
3240 #               for the signal handlers of a given GtkObject subclass.
3241 # Arguments   : $object - the GtkObject subclass, e.g. 'GtkButton'.
3242 #############################################################################
3244 sub GetSignals {
3245     my ($object) = @_;
3246     my $synop = "";
3247     my $desc = "";
3249     my $i;
3250     for ($i = 0; $i <= $#SignalObjects; $i++) {
3251         if ($SignalObjects[$i] eq $object) {
3252             #print "Found signal: $SignalNames[$i]\n";
3253             my $name = $SignalNames[$i];
3254             my $symbol = "${object}::${name}";
3255             my $id = &CreateValidSGMLID ("$object-$name");
3257             my $pad = ' ' x (46 - length($name));
3258             $synop .= "  &quot;<link linkend=\"$id\">$name</link>&quot;$pad ";
3260             $desc .= "<refsect2 id=\"$id\" role=\"signal\"><title>The <literal>&quot;$name&quot;</literal> signal</title>\n";
3261             $desc .= MakeIndexterms($symbol, $id);
3262             $desc .= "\n";
3263             $desc .= OutputSymbolExtraLinks($symbol);
3265             $desc .= "<programlisting>";
3267             $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
3268             my $type_modifier = defined($1) ? $1 : "";
3269             my $type = $2;
3270             my $pointer = $3;
3271             my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
3273             my $ret_type_len = length ($type_modifier) + length ($pointer)
3274                 + length ($type);
3275             my $ret_type_output = "$type_modifier$xref$pointer"
3276                 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
3278             $desc  .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
3280             my $sourceparams = $SourceSymbolParams{$symbol};
3281             my @params = split ("\n", $SignalPrototypes[$i]);
3282             my $j;
3283             my $l;
3284             my $type_len = length("gpointer");
3285             my $name_len = length("user_data");
3286             # do two passes, the first one is to calculate padding
3287             for ($l = 0; $l < 2; $l++) {
3288                 for ($j = 0; $j <= $#params; $j++) {
3289                     # allow alphanumerics, '_', '[' & ']' in param names
3290                     if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
3291                         $type = $1;
3292                         $pointer = $2;
3293                         if (defined($sourceparams)) {
3294                             $name = $$sourceparams[$PARAM_FIELD_COUNT * $j];
3295                         }
3296                         else {
3297                             $name = $3;
3298                         }
3299                         if (!defined($name)) {
3300                             $name = "arg$j";
3301                         }
3302                         if ($l == 0) {
3303                             if (length($type) + length($pointer) > $type_len) {
3304                                 $type_len = length($type) + length($pointer);
3305                             }
3306                             if (length($name) > $name_len) {
3307                                 $name_len = length($name);
3308                             }
3309                         }
3310                         else {
3311                             $xref = &MakeXRef ($type, &tagify($type, "type"));
3312                             $pad = ' ' x ($type_len - length($type) - length($pointer));
3313                             $desc .= "$xref$pad $pointer$name,\n";
3314                             $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
3315                         }
3316                     } else {
3317                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3318                              "Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]");
3319                     }
3320                 }
3321             }
3322             $xref = &MakeXRef ("gpointer", &tagify("gpointer", "type"));
3323             $pad = ' ' x ($type_len - length("gpointer"));
3324             $desc  .= "$xref$pad user_data)";
3326             my $flags = $SignalFlags[$i];
3327             my $flags_string = "";
3329             if (defined ($flags)) {
3330               if ($flags =~ m/f/) {
3331                 $flags_string = "Run First";
3332               }
3333               elsif ($flags =~ m/l/) {
3334                 $flags_string = "Run Last";
3335               }
3336               elsif ($flags =~ m/c/) {
3337                 $flags_string = "Cleanup";
3338               }
3339               if ($flags =~ m/r/) {
3340                 if ($flags_string) { $flags_string .= " / "; }
3341                 $flags_string .= "No Recursion";
3342               }
3343               if ($flags =~ m/d/) {
3344                 if ($flags_string) { $flags_string .= " / "; }
3345                 $flags_string .= "Has Details";
3346               }
3347               if ($flags =~ m/a/) {
3348                 if ($flags_string) { $flags_string .= " / "; }
3349                 $flags_string .= "Action";
3350               }
3351               if ($flags =~ m/h/) {
3352                 if ($flags_string) { $flags_string .= " / "; }
3353                 $flags_string .= "No Hooks";
3354               }
3355             }
3357             if ($flags_string)
3358               {
3359                 $synop .= ": $flags_string\n";
3361                 $pad = ' ' x (5 + $name_len - length("user_data"));
3362                 $desc  .= "$pad : $flags_string</programlisting>\n";
3363               }
3364             else
3365               {
3366                 $synop .= "\n";
3367                 $desc  .= "</programlisting>\n";
3368               }
3370             $desc .= &MakeDeprecationNote($symbol);
3372             my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
3373             my $parameters_output = 0;
3375             $AllSymbols{$symbol} = 1;
3376             if (defined ($SymbolDocs{$symbol})) {
3377                 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3379                 # Try to insert the parameter table at the author's desired
3380                 # position. Otherwise we need to tag it onto the end.
3381                 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
3382                   $parameters_output = 1;
3383                 }
3384                 $desc .= $symbol_docs;
3386                 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
3387                     $AllDocumentedSymbols{$symbol} = 1;
3388                 }
3389             }
3391             if ($parameters_output == 0) {
3392                 $desc .= $parameters;
3393               }
3394             $desc .= OutputSymbolTraits ($symbol);
3395             $desc .= "</refsect2>";
3396         }
3397     }
3398     return ($synop, $desc);
3402 #############################################################################
3403 # Function    : GetArgs
3404 # Description : Returns the synopsis and detailed description DocBook output
3405 #               for the Args of a given GtkObject subclass.
3406 # Arguments   : $object - the GtkObject subclass, e.g. 'GtkButton'.
3407 #############################################################################
3409 sub GetArgs {
3410     my ($object) = @_;
3411     my $synop = "";
3412     my $desc = "";
3413     my $child_synop = "";
3414     my $child_desc = "";
3415     my $style_synop = "";
3416     my $style_desc = "";
3418     my $i;
3419     for ($i = 0; $i <= $#ArgObjects; $i++) {
3420         if ($ArgObjects[$i] eq $object) {
3421             #print "Found arg: $ArgNames[$i]\n";
3422             my $name = $ArgNames[$i];
3423             my $flags = $ArgFlags[$i];
3424             my $flags_string = "";
3425             my $kind = "";
3426             my $id_sep = "";
3428             if ($flags =~ m/c/) {
3429                 $kind = "child property";
3430                 $id_sep = "c-";
3431             }
3432             elsif ($flags =~ m/s/) {
3433                 $kind = "style property";
3434                 $id_sep = "s-";
3435             }
3436             else {
3437                 $kind = "property";
3438             }
3440             # Remember only one colon so we don't clash with signals.
3441             my $symbol = "${object}:${name}";
3442             # use two dashes and ev. an extra separator here for the same reason.
3443             my $id = &CreateValidSGMLID ("$object--$id_sep$name");
3445             my $type = $ArgTypes[$i];
3446             my $type_output;
3447             my $range = $ArgRanges[$i];
3448             my $range_output = CreateValidSGML ($range);
3449             my $default = $ArgDefaults[$i];
3450             my $default_output = CreateValidSGML ($default);
3452             if ($type eq "GtkString") {
3453                 $type = "char*";
3454             }
3455             if ($type eq "GtkSignal") {
3456                 $type = "GtkSignalFunc, gpointer";
3457                 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
3458                     . &MakeXRef ("gpointer");
3459             } elsif ($type =~ m/^(\w+)\*$/) {
3460                 $type_output = &MakeXRef ($1, &tagify($1, "type")) . "*";
3461             } else {
3462                 $type_output = &MakeXRef ($type, &tagify($type, "type"));
3463             }
3465             if ($flags =~ m/r/) {
3466                 $flags_string = "Read";
3467             }
3468             if ($flags =~ m/w/) {
3469                 if ($flags_string) { $flags_string .= " / "; }
3470                 $flags_string .= "Write";
3471             }
3472             if ($flags =~ m/x/) {
3473                 if ($flags_string) { $flags_string .= " / "; }
3474                 $flags_string .= "Construct";
3475             }
3476             if ($flags =~ m/X/) {
3477                 if ($flags_string) { $flags_string .= " / "; }
3478                 $flags_string .= "Construct Only";
3479             }
3481             $AllSymbols{$symbol} = 1;
3482             my $blurb;
3483             if (defined($SymbolDocs{$symbol}) &&
3484                 !IsEmptyDoc($SymbolDocs{$symbol})) {
3485                 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3486                 #print ".. [$SymbolDocs{$symbol}][$blurb]\n";
3487                 $AllDocumentedSymbols{$symbol} = 1;
3488             }
3489             else {
3490                 if (!($ArgBlurbs[$i] eq "")) {
3491                     $AllDocumentedSymbols{$symbol} = 1;
3492                 } else {
3493                     # FIXME: print a warning?
3494                     #print ".. no description\n";
3495                 }
3496                 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
3497             }
3499             my $pad1 = " " x (24 - length ($name));
3500             my $pad2 = " " x (20 - length ($type));
3502             my $arg_synop = "  &quot;<link linkend=\"$id\">$name</link>&quot;$pad1 $type_output $pad2 : $flags_string\n";
3503             my $arg_desc = "<refsect2 id=\"$id\" role=\"property\"><title>The <literal>&quot;$name&quot;</literal> $kind</title>\n";
3504             $arg_desc .= MakeIndexterms($symbol, $id);
3505             $arg_desc .= "\n";
3506             $arg_desc .= OutputSymbolExtraLinks($symbol);
3508             $arg_desc .= "<programlisting>  &quot;$name&quot;$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
3509             $arg_desc .= &MakeDeprecationNote($symbol);
3510             $arg_desc .= $blurb;
3511             if ($range ne "") {
3512                 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
3513             }
3514             if ($default ne "") {
3515                 $arg_desc .= "<para>Default value: $default_output</para>\n";
3516             }
3517             $arg_desc .= OutputSymbolTraits ($symbol);
3518             $arg_desc .= "</refsect2>\n";
3520             if ($flags =~ m/c/) {
3521                 $child_synop .= $arg_synop;
3522                 $child_desc .= $arg_desc;
3523             }
3524             elsif ($flags =~ m/s/) {
3525                 $style_synop .= $arg_synop;
3526                 $style_desc .= $arg_desc;
3527             }
3528             else {
3529                 $synop .= $arg_synop;
3530                 $desc .= $arg_desc;
3531             }
3532         }
3533     }
3534     return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
3538 #############################################################################
3539 # Function    : ReadSourceDocumentation
3540 # Description : This reads in the documentation embedded in comment blocks
3541 #               in the source code (for Gnome).
3543 #               Parameter descriptions override any in the template files.
3544 #               Function descriptions are placed before any description from
3545 #               the template files.
3547 #               It recursively descends the source directory looking for .c
3548 #               files and scans them looking for specially-formatted comment
3549 #               blocks.
3551 # Arguments   : $source_dir - the directory to scan.
3552 #############m###############################################################
3554 sub ReadSourceDocumentation {
3555     my ($source_dir) = @_;
3556     my ($file, $dir, @suffix_list, $suffix);
3557     #print "Scanning source directory: $source_dir\n";
3559     # This array holds any subdirectories found.
3560     my (@subdirs) = ();
3562     @suffix_list = split (/,/, $SOURCE_SUFFIXES);
3564     opendir (SRCDIR, $source_dir)
3565         || die "Can't open source directory $source_dir: $!";
3567     foreach $file (readdir (SRCDIR)) {
3568       if ($file =~ /^\./) {
3569         next;
3570       } elsif (-d "$source_dir/$file") {
3571         push (@subdirs, $file);
3572       } elsif (@suffix_list) {
3573         foreach $suffix (@suffix_list) {
3574           if ($file =~ m/\.\Q${suffix}\E$/) {
3575             &ScanSourceFile ("$source_dir/$file");
3576           }
3577         }
3578       } elsif ($file =~ m/\.[ch]$/) {
3579         &ScanSourceFile ("$source_dir/$file");
3580       }
3581     }
3582     closedir (SRCDIR);
3584     # Now recursively scan the subdirectories.
3585     foreach $dir (@subdirs) {
3586         next if ($IGNORE_FILES =~ m/(\s|^)\Q${dir}\E(\s|$)/);
3587         &ReadSourceDocumentation ("$source_dir/$dir");
3588     }
3592 #############################################################################
3593 # Function    : ScanSourceFile
3594 # Description : Scans one source file looking for specially-formatted comment
3595 #               blocks. Later &MergeSourceDocumentation is used to merge any
3596 #               documentation found with the documentation already read in
3597 #               from the template files.
3599 # Arguments   : $file - the file to scan.
3600 #############################################################################
3602 sub ScanSourceFile {
3603     my ($file) = @_;
3604     my $basename;
3606     if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
3607         $basename = $1;
3608     } else {
3609         &LogWarning ($file, 1, "Can't find basename for this filename.");
3610         $basename = $file;
3611     }
3613     # Check if the basename is in the list of files to ignore.
3614     if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
3615         return;
3616     }
3618     #print "DEBUG: Scanning $file\n";
3620     open (SRCFILE, $file)
3621         || die "Can't open $file: $!";
3622     my $in_comment_block = 0;
3623     my $symbol;
3624     my ($in_description, $in_return, $in_since, $in_stability, $in_deprecated);
3625     my ($description, $return_desc, $return_start, $return_style);
3626     my ($since_desc, $stability_desc, $deprecated_desc);
3627     my $current_param;
3628     my $ignore_broken_returns;
3629     my @params;
3630     while (<SRCFILE>) {
3631         # Look for the start of a comment block.
3632         if (!$in_comment_block) {
3633             if (m%^\s*/\*.*\*/%) {
3634                 #one-line comment - not gtkdoc
3635             } elsif (m%^\s*/\*\*\s%) {
3636                 #print "Found comment block start\n";
3638                 $in_comment_block = 1;
3640                 # Reset all the symbol data.
3641                 $symbol = "";
3642                 $in_description = 0;
3643                 $in_return = 0;
3644                 $in_since = 0;
3645                 $in_deprecated = 0;
3646                 $in_stability = 0;
3647                 $description = "";
3648                 $return_desc = "";
3649                 $return_style = "";
3650                 $since_desc = "";
3651                 $deprecated_desc = "";
3652                 $stability_desc = "";
3653                 $current_param = -1;
3654                 $ignore_broken_returns = 0;
3655                 @params = ();
3656             }
3657             next;
3658         }
3660         # We're in a comment block. Check if we've found the end of it.
3661         if (m%^\s*\*+/%) {
3662             if (!$symbol) {
3663                 # maybe its not even meant to be a gtk-doc comment?
3664                 &LogWarning ($file, $., "Symbol name not found at the start of the comment block.");
3665             } else {
3666                 # Add the return value description onto the end of the params.
3667                 if ($return_desc) {
3668                     push (@params, "Returns");
3669                     push (@params, $return_desc);
3670                     if ($return_style eq 'broken') {
3671                         &LogWarning ($file, $., "Free-form return value description in $symbol. Use `Returns:' to avoid ambiguities.");
3672                     }
3673                 }
3674                 # Convert special SGML characters
3675                 $description = &ConvertSGMLChars ($symbol, $description);
3676                 my $k;
3677                 for ($k = 1; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3678                     $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
3679                 }
3681                 # Handle Section docs
3682                 if ($symbol =~ m/SECTION:\s*(.*)/) {
3683                     my $real_symbol=$1;
3684                     my $key;
3686                     if (scalar %KnownSymbols) {
3687                         if ((! defined($KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"})) || $KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"} != 1) {
3688                             &LogWarning ($file, $., "Section $real_symbol is not defined in the $MODULE-section.txt file.");
3689                         }
3690                     }
3692                     #print "SECTION DOCS found in source for : '$real_symbol'\n";
3693                     $ignore_broken_returns = 1;
3694                     for ($k = 0; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3695                         #print "   '".$params[$k]."'\n";
3696                         $params[$k] = "\L$params[$k]";
3697                         undef $key;
3698                         if ($params[$k] eq "short_description") {
3699                             $key = "$TMPL_DIR/$real_symbol:Short_Description";
3700                         } elsif ($params[$k] eq "see_also") {
3701                             $key = "$TMPL_DIR/$real_symbol:See_Also";
3702                         } elsif ($params[$k] eq "title") {
3703                             $key = "$TMPL_DIR/$real_symbol:Title";
3704                         } elsif ($params[$k] eq "stability") {
3705                             $key = "$TMPL_DIR/$real_symbol:Stability_Level";
3706                         } elsif ($params[$k] eq "section_id") {
3707                             $key = "$TMPL_DIR/$real_symbol:Section_Id";
3708                         } elsif ($params[$k] eq "include") {
3709                             $key = "$TMPL_DIR/$real_symbol:Include";
3710                         } elsif ($params[$k] eq "image") {
3711                             $key = "$TMPL_DIR/$real_symbol:Image";
3712                         }
3713                         if (defined($key)) {
3714                             $SourceSymbolDocs{$key}=$params[$k+1];
3715                             $SourceSymbolSourceFile{$key} = $file;
3716                             $SourceSymbolSourceLine{$key} = $.;
3717                         }
3718                     }
3719                     $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
3720                     $SourceSymbolSourceFile{"$TMPL_DIR/$real_symbol:Long_Description"} = $file;
3721                     $SourceSymbolSourceLine{"$TMPL_DIR/$real_symbol:Long_Description"} = $.;
3722                     #$SourceSymbolTypes{$symbol} = "SECTION";
3723                 } else {
3724                     #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
3725                     $SourceSymbolDocs{$symbol} = $description;
3726                     $SourceSymbolParams{$symbol} = [ @params ];
3727                     # FIXME $SourceSymbolTypes{$symbol} = "STRUCT,SIGNAL,ARG,FUNCTION,MACRO";
3728                     #if (defined $DeclarationTypes{$symbol}) {
3729                     #    $SourceSymbolTypes{$symbol} = $DeclarationTypes{$symbol}
3730                     #}
3731                     $SourceSymbolSourceFile{$symbol} = $file;
3732                     $SourceSymbolSourceLine{$symbol} = $.;
3733                 }
3735                 if ($since_desc) {
3736                      ($since_desc, my @extra_lines) = split ("\n", $since_desc);
3737                      $since_desc =~ s/^\s+//;
3738                      $since_desc =~ s/\s+$//;
3739                      #print "Since($symbol) : [$since_desc]\n";
3740                      $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
3741                      if(scalar @extra_lines) {
3742                          &LogWarning ($file, $., "multi-line since docs found");
3743                      }
3744                 }
3746                 if ($stability_desc) {
3747                     $stability_desc = &ParseStabilityLevel($stability_desc, $file, $., "Stability level for $symbol");
3748                     $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
3749                 }
3751                 if ($deprecated_desc) {
3752                     if (exists $Deprecated{$symbol}) {
3753                     }
3754                     else {
3755                          # don't warn for signals and properties
3756                          #if ($symbol !~ m/::?(.*)/) {
3757                          if (defined $DeclarationTypes{$symbol}) {
3758                              &LogWarning ($file, $., 
3759                                  "$symbol is deprecated in the inline comments, but no deprecation guards were found around the declaration.".
3760                                  " (See the --deprecated-guards option for gtkdoc-scan.)");
3761                          }
3762                     }
3763                     $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
3764                 }
3765             }
3767             $in_comment_block = 0;
3768             next;
3769         }
3771         # Get rid of ' * ' at start of every line in the comment block.
3772         s%^\s*\*\s?%%;
3773         # But make sure we don't get rid of the newline at the end.
3774         if (!$_) {
3775             $_ = "\n";
3776         }
3777         #print "DEBUG: scanning :$_";
3779         # If we haven't found the symbol name yet, look for it.
3780         if (!$symbol) {
3781             if (m%^\s*(SECTION:\s*\S+)%) {
3782                 $symbol = $1;
3783                 #print "SECTION DOCS found in source for : '$symbol'\n";
3784                 $ignore_broken_returns = 1;
3785             } elsif (m%^\s*([\w:-]*\w)\s*:?\s*$%) {
3786                 $symbol = $1;
3787                 #print "SYMBOL DOCS found in source for : '$symbol'\n";
3788             }
3789             next;
3790         }
3792         # If we're in the return value description, add it to the end.
3793         if ($in_return) {
3794             # If we find another valid returns line, we assume that the first
3795             # one was really part of the description.
3796             if (m/^\s*(returns:|return\s+value:)/i) {
3797                 if ($return_style eq 'broken') {
3798                     $description .= $return_start . $return_desc;
3799                 }
3800                 $return_start = $1;
3801                 if ($return_style eq 'sane') {
3802                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3803                 }
3804                 $return_style = 'sane';
3805                 $ignore_broken_returns = 1;
3806                 $return_desc = $';
3807             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3808                 $description .= $return_start . $return_desc;
3809                 $return_start = $1;
3810                 $return_style = 'broken';
3811                 $return_desc = $';
3812             } elsif (m%^\s*since:%i) {
3813                 $since_desc = $';
3814                 $in_since = 1;
3815                 $in_return = 0;
3816             } elsif (m%^\s*stability:%i) {
3817                 $stability_desc = $';
3818                 $in_stability = 1;
3819                 $in_return = 0;
3820             } elsif (m%^\s*deprecated:%i) {
3821                 $deprecated_desc = $';
3822                 $in_deprecated = 1;
3823                 $in_return = 0;
3824             } else {
3825                 $return_desc .= $_;
3826             }
3827             next;
3828         }
3830         if ($in_since) {
3831             if (m/^\s*(returns:|return\s+value:)/i) {
3832                 if ($return_style eq 'broken') {
3833                     $description .= $return_start . $return_desc;
3834                 }
3835                 $return_start = $1;
3836                 if ($return_style eq 'sane') {
3837                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3838                 }
3839                 $return_style = 'sane';
3840                 $ignore_broken_returns = 1;
3841                 $return_desc = $';
3842                 $in_return = 1;
3843                 $in_since = 0;
3844             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3845                 $return_start = $1;
3846                 $return_style = 'broken';
3847                 $return_desc = $';
3848                 $in_return = 1;
3849                 $in_since = 0;
3850             } elsif (m%^\s*deprecated:%i) {
3851                 $deprecated_desc = $';
3852                 $in_deprecated = 1;
3853                 $in_since = 0;
3854             } elsif (m%^\s*stability:%i) {
3855                 $stability_desc = $';
3856                 $in_stability = 1;
3857                 $in_since = 0;
3858             } else {
3859                 $since_desc .= $_;
3860             }
3861             next;
3862         }
3864         if ($in_stability) {
3865             if (m/^\s*(returns:|return\s+value:)/i) {
3866                 if ($return_style eq 'broken') {
3867                     $description .= $return_start . $return_desc;
3868                 }
3869                 $return_start = $1;
3870                 if ($return_style eq 'sane') {
3871                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3872                 }
3873                 $return_style = 'sane';
3874                 $ignore_broken_returns = 1;
3875                 $return_desc = $';
3876                 $in_return = 1;
3877                 $in_stability = 0;
3878             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3879                 $return_start = $1;
3880                 $return_style = 'broken';
3881                 $return_desc = $';
3882                 $in_return = 1;
3883                 $in_stability = 0;
3884             } elsif (m%^\s*deprecated:%i) {
3885                 $deprecated_desc = $';
3886                 $in_deprecated = 1;
3887                 $in_stability = 0;
3888             } elsif (m%^\s*since:%i) {
3889                 $since_desc = $';
3890                 $in_since = 1;
3891                 $in_stability = 0;
3892             } else {
3893                 $stability_desc .= $_;
3894             }
3895             next;
3896         }
3898         if ($in_deprecated) {
3899             if (m/^\s*(returns:|return\s+value:)/i) {
3900                 if ($return_style eq 'broken') {
3901                     $description .= $return_start . $return_desc;
3902                 }
3903                 $return_start = $1;
3904                 if ($return_style eq 'sane') {
3905                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3906                 }
3907                 $return_style = 'sane';
3908                 $ignore_broken_returns = 1;
3909                 $return_desc = $';
3910                 $in_return = 1;
3911                 $in_deprecated = 0;
3912             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3913                 $return_start = $1;
3914                 $return_style = 'broken';
3915                 $return_desc = $';
3916                 $in_return = 1;
3917                 $in_deprecated = 0;
3918             } elsif (m%^\s*since:%i) {
3919                 $since_desc = $';
3920                 $in_since = 1;
3921                 $in_deprecated = 0;
3922             } elsif (m%^\s*stability:%i) {
3923                 $stability_desc = $';
3924                 $in_stability = 1;
3925                 $in_deprecated = 0;
3926             } else {
3927                 $deprecated_desc .= $_;
3928             }
3929             next;
3930         }
3932         # If we're in the description part, check for the 'Returns:' line.
3933         # If that isn't found, add the text to the end.
3934         if ($in_description) {
3935             # Get rid of 'Description:'
3936             s%^\s*Description:%%;
3938             if (m/^\s*(returns:|return\s+value:)/i) {
3939                 if ($return_style eq 'broken') {
3940                     $description .= $return_start . $return_desc;
3941                 }
3942                 $return_start = $1;
3943                 if ($return_style eq 'sane') {
3944                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3945                 }
3946                 $return_style = 'sane';
3947                 $ignore_broken_returns = 1;
3948                 $return_desc = $';
3949                 $in_return = 1;
3950                 next;
3951             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3952                 $return_start = $1;
3953                 $return_style = 'broken';
3954                 $return_desc = $';
3955                 $in_return = 1;
3956                 next;
3957             } elsif (m%^\s*since:%i) {
3958                 $since_desc = $';
3959                 $in_since = 1;
3960                 next;
3961             } elsif (m%^\s*deprecated:%i) {
3962                 $deprecated_desc = $';
3963                 $in_deprecated = 1;
3964                 next;
3965             } elsif (m%^\s*stability:%i) {
3966                 $stability_desc = $';
3967                 $in_stability = 1;
3968                 next;
3969             }
3971             $description .= $_;
3972             next;
3973         }
3975         # We must be in the parameters. Check for the empty line below them.
3976         if (m%^\s*$%) {
3977             $in_description = 1;
3978             next;
3979         }
3981         # Look for a parameter name.
3982         if (m%^\s*@(\S+)\s*:\s*%) {
3983             my $param_name = $1;
3984             my $param_desc = $';
3986             #print "Found parameter: $param_name\n";
3987             # Allow '...' as the Varargs parameter.
3988             if ($param_name eq "...") {
3989                 $param_name = "Varargs";
3990             }
3991             if ("\L$param_name" eq "returns") {
3992                 $return_style = 'sane';
3993                 $ignore_broken_returns = 1;
3994             }
3995             push (@params, $param_name);
3996             push (@params, $param_desc);
3997             $current_param += $PARAM_FIELD_COUNT;
3998             next;
3999         }
4001         # We must be in the middle of a parameter description, so add it on
4002         # to the last element in @params.
4003         if ($current_param == -1) {
4004             &LogWarning ($file, $., "Parsing comment block file : parameter expected.");
4005         } else {
4006             $params[$#params] .= $_;
4007         }
4008     }
4009     close (SRCFILE);
4012 #############################################################################
4013 # Function    : OutputMissingDocumentation
4014 # Description : Outputs report of documentation coverage to a file
4016 # Arguments   : none
4017 #############################################################################
4019 sub OutputMissingDocumentation {
4020     my $old_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.txt";
4021     my $new_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.new";
4023     my $n_documented = 0;
4024     my $n_incomplete = 0;
4025     my $total = 0;
4026     my $symbol;
4027     my $percent;
4028     my $msg;
4029     my $buffer = "";
4030     my $buffer_deprecated = "";
4031     my $buffer_descriptions = "";
4032     
4033     open(UNDOCUMENTED, ">$new_undocumented_file")
4034       || die "Can't create $new_undocumented_file";
4035     
4036     foreach $symbol (sort (keys (%AllSymbols))) {
4037         # FIXME: should we print LogWarnings for undocumented stuff?
4038         # DEBUG
4039         #my $ssfile = &GetSymbolSourceFile($symbol);
4040         #my $ssline = &GetSymbolSourceLine($symbol);
4041         #my $location = "defined at " . (defined($ssfile)?$ssfile:"?") . ":" . (defined($ssline)?$ssline:"0") . "\n";
4042         # DEBUG
4043         if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include|Section_Id|Image)/) {
4044             $total++;
4045             if (exists ($AllDocumentedSymbols{$symbol})) {
4046                 $n_documented++;
4047                 if (exists ($AllIncompleteSymbols{$symbol})) {
4048                     $n_incomplete++;
4049                     $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4050                     #$buffer .= "\t0: ".$location;
4051                 }
4052             } elsif (exists $Deprecated{$symbol}) {
4053                 if (exists ($AllIncompleteSymbols{$symbol})) {
4054                     $n_incomplete++;
4055                     $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4056                     #$buffer .= "\t1a: ".$location;
4057                 } else {
4058                     $buffer_deprecated .= $symbol . "\n";
4059                     #$buffer .= "\t1b: ".$location;
4060                 }
4061             } else {
4062                 if (exists ($AllIncompleteSymbols{$symbol})) {
4063                     $n_incomplete++;
4064                     $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4065                     #$buffer .= "\t2a: ".$location;
4066                 } else {
4067                     $buffer .= $symbol . "\n";
4068                     #$buffer .= "\t2b: ".$location;
4069                 }
4070             }
4071         } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
4072             $total++;
4073             #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
4074             #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
4075             #print "%%%% $symbol : $len1,$len2\n";
4076             if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
4077             || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
4078               $n_documented++;
4079             } else {
4080               # cut off the leading namespace ($TMPL_DIR)
4081               $symbol =~ m/^.*\/(.*)$/;
4082               $buffer_descriptions .= $1 . "\n";
4083             }
4084         }
4085     }
4086     
4087     $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
4088     
4089     if ($total == 0) {
4090       $percent = 100;
4091     } else {
4092       $percent = ($n_documented / $total) * 100.0;
4093     }
4094     
4095     printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
4096     print UNDOCUMENTED "$n_documented symbols documented.\n";
4097     print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
4098     print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
4099     
4100     print UNDOCUMENTED $buffer;
4101     close (UNDOCUMENTED);
4102     
4103     return &UpdateFileIfChanged ($old_undocumented_file, $new_undocumented_file, 0);
4104     
4105     printf "%.0f%% symbol docs coverage", $percent;
4106     print "($n_documented symbols documented, $n_incomplete symbols incomplete, " . ($total - $n_documented) . " not documented)\n";
4107     print "See $MODULE-undocumented.txt for a list of missing docs.\nThe doc coverage percentage doesn't include intro sections.\n";
4111 #############################################################################
4112 # Function    : OutputUndeclaredSymbols
4113 # Description : Outputs symbols that are listed in the section file, but not
4114 #               declaration is found in the sources
4116 # Arguments   : none
4117 #############################################################################
4119 sub OutputUndeclaredSymbols {
4120     my $old_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.txt";
4121     my $new_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.new";
4123     open(UNDECLARED, ">$new_undeclared_file")
4124         || die "Can't create $new_undeclared_file";
4126     if (%UndeclaredSymbols) {
4127         print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
4128         print UNDECLARED "\n";
4129         print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
4130     }
4131     close(UNDECLARED);
4133     return &UpdateFileIfChanged ($old_undeclared_file, $new_undeclared_file, 0);
4136 #############################################################################
4137 # Function    : OutputUnusedSymbols
4138 # Description : Outputs symbols that are documented in comments, but not
4139 #               declared in the sources
4141 # Arguments   : none
4142 #############################################################################
4144 sub OutputUnusedSymbols {
4145     my $num_unused = 0;
4146     my $old_unused_file = "$ROOT_DIR/$MODULE-unused.txt";
4147     my $new_unused_file = "$ROOT_DIR/$MODULE-unused.new";
4149     open (UNUSED, ">$new_unused_file")
4150         || die "Can't open $new_unused_file";
4151     my ($symbol);
4152     foreach $symbol (sort keys (%Declarations)) {
4153         if (!defined ($DeclarationOutput{$symbol})) {
4154             print (UNUSED "$symbol\n");
4155             $num_unused++;
4156         }
4157     }
4158     foreach $symbol (sort (keys (%AllUnusedSymbols))) {
4159         print (UNUSED "$symbol(" . $AllUnusedSymbols{$symbol} . ")\n");
4160         $num_unused++;
4161     }
4162     close (UNUSED);
4163     if ($num_unused != 0) {
4164         &LogWarning ($old_unused_file, 1, "$num_unused unused declarations.".
4165             "They should be added to $MODULE-sections.txt in the appropriate place.");
4166     }
4167     
4168     return &UpdateFileIfChanged ($old_unused_file, $new_unused_file, 0); 
4172 #############################################################################
4173 # Function    : OutputAllSymbols
4174 # Description : Outputs list of all symbols to a file
4176 # Arguments   : none
4177 #############################################################################
4179 sub OutputAllSymbols {
4180      my $n_documented = 0;
4181      my $total = 0;
4182      my $symbol;
4183      my $percent;
4184      my $msg;
4186      open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
4187           || die "Can't create $ROOT_DIR/$MODULE-symbols.txt: $!";
4189      foreach $symbol (sort (keys (%AllSymbols))) {
4190           print SYMBOLS $symbol . "\n";
4191      }
4193      close (SYMBOLS);
4196 #############################################################################
4197 # Function    : OutputSymbolsWithoutSince
4198 # Description : Outputs list of all symbols without a since tag to a file
4200 # Arguments   : none
4201 #############################################################################
4203 sub OutputSymbolsWithoutSince {
4204      my $n_documented = 0;
4205      my $total = 0;
4206      my $symbol;
4207      my $percent;
4208      my $msg;
4210      open (SYMBOLS, ">$ROOT_DIR/$MODULE-nosince.txt")
4211           || die "Can't create $ROOT_DIR/$MODULE-nosince.txt: $!";
4213      foreach $symbol (sort (keys (%SourceSymbolDocs))) {
4214          if (!defined $Since{$symbol}) {
4215              print SYMBOLS $symbol . "\n";
4216          }
4217      }
4219      close (SYMBOLS);
4223 #############################################################################
4224 # Function    : MergeSourceDocumentation
4225 # Description : This merges documentation read from a source file into the
4226 #               documentation read in from a template file.
4228 #               Parameter descriptions override any in the template files.
4229 #               Function descriptions are placed before any description from
4230 #               the template files.
4232 # Arguments   : none
4233 #############################################################################
4235 sub MergeSourceDocumentation {
4236     my $symbol;
4237     my @Symbols;
4239     if (scalar %SymbolDocs) {
4240         @Symbols=keys (%SymbolDocs);
4241         #print "num existing entries: ".(scalar @Symbols)."\n";
4242         #print "  ",$Symbols[0], " ",$Symbols[1],"\n";
4243     }
4244     else {
4245         # filter scanned declarations, with what we suppress from -sections.txt
4246         my %tmp = ();
4247         foreach $symbol (keys (%Declarations)) {
4248             if (defined($KnownSymbols{$symbol}) && $KnownSymbols{$symbol} == 1) {
4249                 $tmp{$symbol}=1;
4250             }
4251         }
4252         # , add the rest from -sections.txt
4253         foreach $symbol (keys (%KnownSymbols)) {
4254             if ($KnownSymbols{$symbol} == 1) {
4255                 $tmp{$symbol}=1;
4256             }
4257         }
4258         # and add whats found in the source
4259         foreach $symbol (keys (%SourceSymbolDocs)) {
4260             $tmp{$symbol}=1;
4261         }
4262         @Symbols = keys (%tmp);
4263         #print "num source entries: ".(scalar @Symbols)."\n";
4264     }
4265     foreach $symbol (@Symbols) {
4266         $AllSymbols{$symbol} = 1;
4268         my $have_tmpl_docs = 0;
4270         ## See if the symbol is documented in template
4271         my $tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4272         my $check_tmpl_doc =$tmpl_doc;
4273         # remove all xml-tags and whitespaces
4274         #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
4275         $check_tmpl_doc =~ s/<.*?>//g;
4276         $check_tmpl_doc =~ s/\s//g;
4277         # anything left ?
4278         if ($check_tmpl_doc ne "") {
4279             $have_tmpl_docs = 1;
4280             #print "## [$check_tmpl_doc]\n";
4281         } else {
4282             $tmpl_doc = "";
4283         }
4285         if (exists ($SourceSymbolDocs{$symbol})) {
4286             my $type = $DeclarationTypes {$symbol};
4288             #print "merging [$symbol] from source\n";
4290             my $item = "Parameter";
4291             if (defined ($type)) {
4292                 if ($type eq 'STRUCT') {
4293                     $item = "Field";
4294                 } elsif ($type eq 'ENUM') {
4295                     $item = "Value";
4296                 } elsif ($type eq 'UNION') {
4297                     $item = "Field";
4298                 }
4299             } else {
4300                 $type="SIGNAL";
4301             }
4303             my $src_doc = $SourceSymbolDocs{$symbol};
4304             # remove leading and training whitespaces
4305             $src_doc =~ s/^\s+//;
4306             $src_doc =~ s/\s+$//;
4308             # Don't output warnings for overridden titles as titles are
4309             # automatically generated in the -sections.txt file, and thus they
4310             # are often overridden.
4311             if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
4312                 # check if content is different
4313                 if ($tmpl_doc ne $src_doc) {
4314                     #print "[$tmpl_doc] [$src_doc]\n";
4315                     &LogWarning ($SourceSymbolSourceFile{$symbol}, $SourceSymbolSourceLine{$symbol},
4316                         "Documentation in template ".$SymbolSourceFile{$symbol}.":".$SymbolSourceLine{$symbol}." for $symbol being overridden by inline comments.");
4317                 }
4318             }
4320             if ($src_doc ne "") {
4321                  $AllDocumentedSymbols{$symbol} = 1;
4322             }
4324             # Convert <!--PARAMETERS--> with any blank lines around it to
4325             # a </para> followed by <!--PARAMETERS--> followed by <para>.
4326             $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
4328             # Do not add <para> to nothing, it breaks missing docs checks.
4329             my $src_doc_para = "";
4330             if ($src_doc ne "") {
4331                 # If there is a blank line, finish the paragraph and start another.
4332                 $src_doc = &ConvertBlankLines ($src_doc, $symbol);
4333                 $src_doc_para = "<para>\n$src_doc\n</para>";
4334                 # fixup xml markup
4335                 $src_doc_para =~ s%<para>\n<refsect2%<refsect2%gms;
4336                 $src_doc_para =~ s%</refsect2>\n</para>%</refsect2>%gms;
4337                 #print "$symbol : [$src_doc][$src_doc_para]\n";
4338             }
4340             if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
4341                 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4342             } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
4343                 # For the title/summary/see also section docs we don't want to
4344                 # add any <para> tags.
4345                 $SymbolDocs{$symbol} = "$src_doc"
4346             } else {
4347                 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4348             }
4350             # merge parameters
4351             if ($symbol =~ m/.*::.*/) {
4352                 # For signals we prefer the param names from the source docs,
4353                 # since the ones from the templates are likely to contain the
4354                 # artificial argn names which are generated by gtkdoc-scangobj.
4355                 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4356                 # FIXME: we need to check for empty docs here as well!
4357             } else {
4358                 # The templates contain the definitive parameter names and order,
4359                 # so we will not change that. We only override the actual text.
4360                 my $tmpl_params = $SymbolParams{$symbol};
4361                 if (!defined ($tmpl_params)) {
4362                     #print "No merge needed for $symbol\n";
4363                     $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4364                     #  FIXME: we still like to get the number of params and merge
4365                     #  1) we would noticed that params have been removed/renamed
4366                     #  2) we would catch undocumented params
4367                     #  params are not (yet) exported in -decl.txt so that we
4368                     #  could easily grab them :/
4369                 } else {
4370                     my $params = $SourceSymbolParams{$symbol};
4371                     my $j;
4372                     #print "Merge needed for $symbol, tmpl_params: ",$#$tmpl_params,", source_params: ",$#$params," \n";
4373                     for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4374                         my $tmpl_param_name = $$tmpl_params[$j];
4376                         # Allow '...' as the Varargs parameter.
4377                         if ($tmpl_param_name eq "...") {
4378                             $tmpl_param_name = "Varargs";
4379                         }
4381                         # Try to find the param in the source comment documentation.
4382                         my $found = 0;
4383                         my $k;
4384                         #print "  try merge param $tmpl_param_name\n";
4385                         for ($k = 0; $k <= $#$params; $k += $PARAM_FIELD_COUNT) {
4386                             my $param_name = $$params[$k];
4387                             my $param_desc = $$params[$k + 1];
4389                             #print "    test param  $param_name\n";
4390                             # We accept changes in case, since the Gnome source
4391                             # docs contain a lot of these.
4392                             if ("\L$param_name" eq "\L$tmpl_param_name") {
4393                                 $found = 1;
4395                                 # Override the description.
4396                                 $$tmpl_params[$j + 1] = $param_desc;
4398                                 # Set the name to "" to mark it as used.
4399                                 $$params[$k] = "";
4400                                 last;
4401                             }
4402                         }
4404                         # If it looks like the parameters are there, but not
4405                         # in the right place, try to explain a bit better.
4406                         if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
4407                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4408                                 "Parameters for $symbol must start on the line immediately after the function or macro name.");
4409                         }
4410                     }
4412                     # Now we output a warning if parameters have been described which
4413                     # do not exist.
4414                     for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
4415                         my $param_name = $$params[$j];
4416                         if ($param_name) {
4417                             # the template builder cannot detect if a macro returns
4418                             # a result or not
4419                             if(($type eq "MACRO") && ($param_name eq "Returns")) {
4420                                 # FIXME: do we need to add it then to tmpl_params[] ?
4421                                 my $num=$#$tmpl_params;
4422                                 #print "  adding Returns: to macro docs for $symbol.\n";
4423                                 $$tmpl_params[$num+1]="Returns";
4424                                 $$tmpl_params[$num+2]=$$params[$j+1];
4425                                 next;
4426                             }
4427                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4428                                 "$item described in source code comment block but does not exist. $type: $symbol $item: $param_name.");
4429                         }
4430                     }
4431                 }
4432             }
4433         } else {
4434             if ($have_tmpl_docs) {
4435                 $AllDocumentedSymbols{$symbol} = 1;
4436                 #print "merging [$symbol] from template\n";
4437             }
4438             else {
4439                 #print "[$symbol] undocumented\n";
4440             }
4441         }
4443         # if this symbol is documented, check if docs are complete
4444         $check_tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4445         # remove all xml-tags and whitespaces
4446         #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
4447         $check_tmpl_doc =~ s/<.*?>//g;
4448         $check_tmpl_doc =~ s/\s//g;
4449         if ($check_tmpl_doc ne "") {
4450             my $tmpl_params = $SymbolParams{$symbol};
4451             if (defined ($tmpl_params)) {
4452                 my $type = $DeclarationTypes {$symbol};
4454                 my $item = "Parameter";
4455                 if (defined ($type)) {
4456                     if ($type eq 'STRUCT') {
4457                         $item = "Field";
4458                     } elsif ($type eq 'ENUM') {
4459                         $item = "Value";
4460                     } elsif ($type eq 'UNION') {
4461                         $item = "Field";
4462                     }
4463                 } else {
4464                     $type="SIGNAL";
4465                 }
4467                 #print "Check param docs for $symbol, tmpl_params: ",$#$tmpl_params," entries, type=$type\n";
4469                 if ($#$tmpl_params > 0) {
4470                     my $j;
4471                     for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4472                         # Output a warning if the parameter is empty and
4473                         # remember for stats.
4474                         my $tmpl_param_name = $$tmpl_params[$j];
4475                         my $tmpl_param_desc = $$tmpl_params[$j + 1];
4476                         if ($tmpl_param_name ne "void" && $tmpl_param_desc !~ m/\S/) {
4477                             if (exists ($AllIncompleteSymbols{$symbol})) {
4478                                 $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
4479                             } else {
4480                                 $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
4481                             }
4482                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4483                                 "$item description for $symbol"."::"."$tmpl_param_name is missing in source code comment block.");
4484                         }
4485                     }
4486                 }
4487                 else {
4488                     if ($#$tmpl_params == 0) {
4489                         $AllIncompleteSymbols{$symbol}="<items>";
4490                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4491                             "$item descriptions for $symbol are missing in source code comment block.");
4492                     }
4493                     # $#$tmpl_params==-1 means we don't know about parameters
4494                     # this unfortunately does not tell if there should be some
4495                 }
4496             }
4497         }
4498    }
4499    #print "num doc entries: ".(scalar %SymbolDocs)."\n";
4502 #############################################################################
4503 # Function    : IsEmptyDoc
4504 # Description : Check if a doc-string is empty. Its also regarded as empty if
4505 #               it only consist of whitespace or e.g. FIXME.
4506 # Arguments   : the doc-string
4507 #############################################################################
4508 sub IsEmptyDoc {
4509     my ($doc) = @_;
4510     
4511     if ($doc =~ /^\s*$/) {
4512         return 1;
4513     }
4515     if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
4516         return 1;
4517     }
4519     return 0;
4523 # This converts blank lines to "</para><para>", but only outside CDATA and
4524 # <programlisting> tags.
4525 sub ConvertBlankLines {
4526     return &ModifyXMLElements ($_[0], $_[1],
4527                                "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
4528                                \&ConvertBlankLinesEndTag,
4529                                \&ConvertBlankLinesCallback);
4533 sub ConvertBlankLinesEndTag {
4534   if ($_[0] eq "<!\[CDATA\[") {
4535     return "]]>";
4536   } elsif ($_[0] eq "|[") {
4537     return "]\\|";
4538   } else {
4539     return "</programlisting>";
4540   }
4543 sub ConvertBlankLinesCallback {
4544   my ($text, $symbol, $tag) = @_;
4546   # If we're not in CDATA or a <programlisting> we convert blank lines so
4547   # they start a new <para>.
4548   if ($tag eq "") {
4549     $text =~ s%\n{2,}%\n</para>\n<para>\n%g;
4550   }
4552   return $text;
4556 #############################################################################
4557 # LIBRARY FUNCTIONS -   These functions are used in both gtkdoc-mkdb and
4558 #                       gtkdoc-mktmpl and should eventually be moved to a
4559 #                       separate library.
4560 #############################################################################
4562 #############################################################################
4563 # Function    : ReadDeclarationsFile
4564 # Description : This reads in a file containing the function/macro/enum etc.
4565 #               declarations.
4567 #               Note that in some cases there are several declarations with
4568 #               the same name, e.g. for conditional macros. In this case we
4569 #               set a flag in the %DeclarationConditional hash so the
4570 #               declaration is not shown in the docs.
4572 #               If a macro and a function have the same name, e.g. for
4573 #               gtk_object_ref, the function declaration takes precedence.
4575 #               Some opaque structs are just declared with 'typedef struct
4576 #               _name name;' in which case the declaration may be empty.
4577 #               The structure may have been found later in the header, so
4578 #               that overrides the empty declaration.
4580 # Arguments   : $file - the declarations file to read
4581 #               $override - if declarations in this file should override
4582 #                       any current declaration.
4583 #############################################################################
4585 sub ReadDeclarationsFile {
4586     my ($file, $override) = @_;
4588     if ($override == 0) {
4589         %Declarations = ();
4590         %DeclarationTypes = ();
4591         %DeclarationConditional = ();
4592         %DeclarationOutput = ();
4593     }
4595     open (INPUT, $file)
4596         || die "Can't open $file: $!";
4597     my $declaration_type = "";
4598     my $declaration_name;
4599     my $declaration;
4600     my $is_deprecated = 0;
4601     while (<INPUT>) {
4602         if (!$declaration_type) {
4603             if (m/^<([^>]+)>/) {
4604                 $declaration_type = $1;
4605                 $declaration_name = "";
4606                 #print "Found declaration: $declaration_type\n";
4607                 $declaration = "";
4608             }
4609         } else {
4610             if (m%^<NAME>(.*)</NAME>%) {
4611                 $declaration_name = $1;
4612             } elsif (m%^<DEPRECATED/>%) {
4613                 $is_deprecated = 1;
4614             } elsif (m%^</$declaration_type>%) {
4615                 #print "Found end of declaration: $declaration_name\n";
4616                 # Check that the declaration has a name
4617                 if ($declaration_name eq "") {
4618                     print "ERROR: $declaration_type has no name $file:$.\n";
4619                 }
4621                 # If the declaration is an empty typedef struct _XXX XXX
4622                 # set the flag to indicate the struct has a typedef.
4623                 if ($declaration_type eq 'STRUCT'
4624                     && $declaration =~ m/^\s*$/) {
4625                     #print "Struct has typedef: $declaration_name\n";
4626                     $StructHasTypedef{$declaration_name} = 1;
4627                 }
4629                 # Check if the symbol is already defined.
4630                 if (defined ($Declarations{$declaration_name})
4631                     && $override == 0) {
4632                     # Function declarations take precedence.
4633                     if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
4634                         # Ignore it.
4635                     } elsif ($declaration_type eq 'FUNCTION') {
4636                         if ($is_deprecated) {
4637                             $Deprecated{$declaration_name} = "";
4638                         }
4639                         $Declarations{$declaration_name} = $declaration;
4640                         $DeclarationTypes{$declaration_name} = $declaration_type;
4641                     } elsif ($DeclarationTypes{$declaration_name}
4642                               eq $declaration_type) {
4643                         # If the existing declaration is empty, or is just a
4644                         # forward declaration of a struct, override it.
4645                         if ($declaration_type eq 'STRUCT') {
4646                             if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4647                                 if ($is_deprecated) {
4648                                     $Deprecated{$declaration_name} = "";
4649                                 }
4650                                 $Declarations{$declaration_name} = $declaration;
4651                             } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4652                                 # Ignore an empty or forward declaration.
4653                             } else {
4654                                 &LogWarning ($file, $., "Structure $declaration_name has multiple definitions.");
4655                             }
4656                         } else {
4657                             # set flag in %DeclarationConditional hash for
4658                             # multiply defined macros/typedefs.
4659                             $DeclarationConditional{$declaration_name} = 1;
4660                         }
4661                     } else {
4662                         &LogWarning ($file, $., "$declaration_name has multiple definitions.");
4663                     }
4664                 } else {
4665                     if ($is_deprecated) {
4666                         $Deprecated{$declaration_name} = "";
4667                     }
4668                     $Declarations{$declaration_name} = $declaration;
4669                     $DeclarationTypes{$declaration_name} = $declaration_type;
4670                 }
4672                 $declaration_type = "";
4673                 $is_deprecated = 0;
4674             } else {
4675                 $declaration .= $_;
4676             }
4677         }
4678     }
4679     close (INPUT);
4683 #############################################################################
4684 # Function    : ReadSignalsFile
4685 # Description : This reads in an existing file which contains information on
4686 #               all GTK signals. It creates the arrays @SignalNames and
4687 #               @SignalPrototypes containing info on the signals. The first
4688 #               line of the SignalPrototype is the return type of the signal
4689 #               handler. The remaining lines are the parameters passed to it.
4690 #               The last parameter, "gpointer user_data" is always the same
4691 #               so is not included.
4692 # Arguments   : $file - the file containing the signal handler prototype
4693 #                       information.
4694 #############################################################################
4696 sub ReadSignalsFile {
4697     my ($file) = @_;
4699     my $in_signal = 0;
4700     my $signal_object;
4701     my $signal_name;
4702     my $signal_returns;
4703     my $signal_flags;
4704     my $signal_prototype;
4706     # Reset the signal info.
4707     @SignalObjects = ();
4708     @SignalNames = ();
4709     @SignalReturns = ();
4710     @SignalFlags = ();
4711     @SignalPrototypes = ();
4713     if (! -f $file) {
4714         return;
4715     }
4716     if (!open (INPUT, $file)) {
4717         warn "Can't open $file - skipping signals\n";
4718         return;
4719     }
4720     while (<INPUT>) {
4721         if (!$in_signal) {
4722             if (m/^<SIGNAL>/) {
4723                 $in_signal = 1;
4724                 $signal_object = "";
4725                 $signal_name = "";
4726                 $signal_returns = "";
4727                 $signal_prototype = "";
4728             }
4729         } else {
4730             if (m/^<NAME>(.*)<\/NAME>/) {
4731                 $signal_name = $1;
4732                 if ($signal_name =~ m/^(.*)::(.*)$/) {
4733                     $signal_object = $1;
4734                     ($signal_name = $2) =~ s/_/-/g;
4735                     #print "Found signal: $signal_name\n";
4736                 } else {
4737                     &LogWarning ($file, $., "Invalid signal name: $signal_name.");
4738                 }
4739             } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
4740                 $signal_returns = $1;
4741             } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4742                 $signal_flags = $1;
4743             } elsif (m%^</SIGNAL>%) {
4744                 #print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
4745                 push (@SignalObjects, $signal_object);
4746                 push (@SignalNames, $signal_name);
4747                 push (@SignalReturns, $signal_returns);
4748                 push (@SignalFlags, $signal_flags);
4749                 push (@SignalPrototypes, $signal_prototype);
4750                 $in_signal = 0;
4751             } else {
4752                 $signal_prototype .= $_;
4753             }
4754         }
4755     }
4756     close (INPUT);
4760 #############################################################################
4761 # Function    : ReadTemplateFile
4762 # Description : This reads in the manually-edited documentation file
4763 #               corresponding to the file currently being created, so we can
4764 #               insert the documentation at the appropriate places.
4765 #               It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
4766 #               is a hash of arrays.
4767 #               NOTE: This function is duplicated in gtkdoc-mktmpl (but
4768 #               slightly different).
4769 # Arguments   : $docsfile - the template file to read in.
4770 #               $skip_unused_params - 1 if the unused parameters should be
4771 #                       skipped.
4772 #############################################################################
4774 sub ReadTemplateFile {
4775     my ($docsfile, $skip_unused_params) = @_;
4777     my $template = "$docsfile.sgml";
4778     if (! -f $template) {
4779         #print "File doesn't exist: $template\n";
4780         return 0;
4781     }
4782     #print "Reading $template\n";
4784     # start with empty hashes, we merge the source comment for each file
4785     # afterwards
4786     %SymbolDocs = ();
4787     %SymbolTypes = ();
4788     %SymbolParams = ();
4790     my $current_type = "";      # Type of symbol being read.
4791     my $current_symbol = "";    # Name of symbol being read.
4792     my $symbol_doc = "";                # Description of symbol being read.
4793     my @params;                 # Parameter names and descriptions of current
4794                                 #   function/macro/function typedef.
4795     my $current_param = -1;     # Index of parameter currently being read.
4796                                 #   Note that the param array contains pairs
4797                                 #   of param name & description.
4798     my $in_unused_params = 0;   # True if we are reading in the unused params.
4799     my $in_deprecated = 0;
4800     my $in_since = 0;
4801     my $in_stability = 0;
4803     open (DOCS, "$template")
4804         || die "Can't open $template: $!";
4805     while (<DOCS>) {
4806         if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
4807             my $type = $1;
4808             my $symbol = $2;
4809             if ($symbol eq "Title"
4810                 || $symbol eq "Short_Description"
4811                 || $symbol eq "Long_Description"
4812                 || $symbol eq "See_Also"
4813                 || $symbol eq "Stability_Level"
4814                 || $symbol eq "Include"
4815                 || $symbol eq "Image") {
4817                 $symbol = $docsfile . ":" . $symbol;
4818             }
4820             #print "Found symbol: $symbol\n";
4821             # Remember file and line for the symbol
4822             $SymbolSourceFile{$symbol} = $template;
4823             $SymbolSourceLine{$symbol} = $.;
4825             # Store previous symbol, but remove any trailing blank lines.
4826             if ($current_symbol ne "") {
4827                 $symbol_doc =~ s/\s+$//;
4828                 $SymbolTypes{$current_symbol} = $current_type;
4829                 $SymbolDocs{$current_symbol} = $symbol_doc;
4831                 # Check that the stability level is valid.
4832                 if ($StabilityLevel{$current_symbol}) {
4833                     $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4834                 }
4836                 if ($current_param >= 0) {
4837                     $SymbolParams{$current_symbol} = [ @params ];
4838                 } else {
4839                     # Delete any existing params in case we are overriding a
4840                     # previously read template.
4841                     delete $SymbolParams{$current_symbol};
4842                 }
4843             }
4844             $current_type = $type;
4845             $current_symbol = $symbol;
4846             $current_param = -1;
4847             $in_unused_params = 0;
4848             $in_deprecated = 0;
4849             $in_since = 0;
4850             $in_stability = 0;
4851             $symbol_doc = "";
4852             @params = ();
4854         } elsif (m/^<!-- # Unused Parameters # -->/) {
4855             #print "DEBUG: Found unused parameters\n";
4856             $in_unused_params = 1;
4857             next;
4859         } elsif ($in_unused_params && $skip_unused_params) {
4860             # When outputting the DocBook we skip unused parameters.
4861             #print "DEBUG: Skipping unused param: $_";
4862             next;
4864         } else {
4865             # Check if param found. Need to handle "..." and "format...".
4866             if (s/^\@([\w\.]+):\040?//) {
4867                 my $param_name = $1;
4868                 my $param_desc = $_;
4869                 # Allow variations of 'Returns'
4870                 if ($param_name =~ m/^[Rr]eturns?$/) {
4871                     $param_name = "Returns";
4872                 }
4874                 # strip trailing whitespaces and blank lines
4875                 s/\s+\n$/\n/m;
4876                 s/\n+$/\n/sm;
4877                 #print "Found param for symbol $current_symbol : '$param_name'= '$_'";
4879                 if ($param_name eq "Deprecated") {
4880                     $in_deprecated = 1;
4881                     $Deprecated{$current_symbol} = $_;
4882                 } elsif ($param_name eq "Since") {
4883                     $in_since = 1;
4884                     chomp;
4885                     $Since{$current_symbol} = $_;
4886                 } elsif ($param_name eq "Stability") {
4887                     $in_stability = 1;
4888                     $StabilityLevel{$current_symbol} = $_;
4889                 } else {
4890                     push (@params, $param_name);
4891                     push (@params, $param_desc);
4892                     $current_param += $PARAM_FIELD_COUNT;
4893                 }
4894             } else {
4895                 # strip trailing whitespaces and blank lines
4896                 s/\s+\n$/\n/m;
4897                 s/\n+$/\n/sm;
4898                 
4899                 if (!m/^\s+$/) {
4900                     if ($in_deprecated) {
4901                         $Deprecated{$current_symbol} .= $_;
4902                     } elsif ($in_since) {
4903                         &LogWarning ($template, $., "multi-line since docs found");
4904                         #$Since{$current_symbol} .= $_;
4905                     } elsif ($in_stability) {
4906                         $StabilityLevel{$current_symbol} .= $_;
4907                     } elsif ($current_param >= 0) {
4908                         $params[$current_param] .= $_;
4909                     } else {
4910                         $symbol_doc .= $_;
4911                     }
4912                 }
4913             }
4914         }
4915     }
4917     # Remember to finish the current symbol doccs.
4918     if ($current_symbol ne "") {
4920         $symbol_doc =~ s/\s+$//;
4921         $SymbolTypes{$current_symbol} = $current_type;
4922         $SymbolDocs{$current_symbol} = $symbol_doc;
4924         # Check that the stability level is valid.
4925         if ($StabilityLevel{$current_symbol}) {
4926             $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4927         }
4929         if ($current_param >= 0) {
4930             $SymbolParams{$current_symbol} = [ @params ];
4931         } else {
4932             # Delete any existing params in case we are overriding a
4933             # previously read template.
4934             delete $SymbolParams{$current_symbol};
4935         }
4936     }
4938     close (DOCS);
4939     return 1;
4943 #############################################################################
4944 # Function    : ReadObjectHierarchy
4945 # Description : This reads in the $MODULE-hierarchy.txt file containing all
4946 #               the GtkObject subclasses described in this module (and their
4947 #               ancestors).
4948 #               It places them in the @Objects array, and places their level
4949 #               in the object hierarchy in the @ObjectLevels array, at the
4950 #               same index. GtkObject, the root object, has a level of 1.
4952 #               FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
4953 #               as it goes along, this should be split out into a separate
4954 #               function.
4956 # Arguments   : none
4957 #############################################################################
4959 sub ReadObjectHierarchy {
4960     @Objects = ();
4961     @ObjectLevels = ();
4963     if (! -f $OBJECT_TREE_FILE) {
4964         return;
4965     }
4966     if (!open (INPUT, $OBJECT_TREE_FILE)) {
4967         warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
4968         return;
4969     }
4971     # FIXME: use $OUTPUT_FORMAT
4972     # my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.$OUTPUT_FORMAT";
4973     my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
4974     my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
4976     open (OUTPUT, ">$new_tree_index")
4977         || die "Can't create $new_tree_index: $!";
4979     if ($OUTPUT_FORMAT eq "xml") {
4980         my $tree_header = $doctype_header;
4982         $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
4983         print (OUTPUT "$tree_header");
4984     }
4985     print (OUTPUT "<screen>\n");
4987     # Only emit objects if they are supposed to be documented, or if
4988     # they have documented children. To implement this, we maintain a
4989     # stack of pending objects which will be emitted if a documented
4990     # child turns up.
4991     my @pending_objects = ();
4992     my @pending_levels = ();
4993     while (<INPUT>) {
4994         if (m/\S+/) {
4995             my $object = $&;
4996             my $level = (length($`)) / 2 + 1;
4997             my $xref = "";
4999             while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
5000                 my $pobject = pop(@pending_objects);
5001                 my $plevel = pop(@pending_levels);
5002             }
5004             push (@pending_objects, $object);
5005             push (@pending_levels, $level);
5007             if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5008                 while ($#pending_levels >= 0) {
5009                     $object = shift @pending_objects;
5010                     $level = shift @pending_levels;
5011                     $xref = &MakeXRef ($object);
5013                     print (OUTPUT ' ' x ($level * 4), "$xref\n");
5014                     push (@Objects, $object);
5015                     push (@ObjectLevels, $level);
5016                 }
5017             }
5018             #else {
5019             #    LogWarning ($OBJECT_TREE_FILE, $., "unknown type $object");
5020             #}
5021         }
5022     }
5023     print (OUTPUT "</screen>\n");
5025     close (INPUT);
5026     close (OUTPUT);
5028     &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
5030     &OutputObjectList;
5033 #############################################################################
5034 # Function    : ReadInterfaces
5035 # Description : This reads in the $MODULE.interfaces file.
5037 # Arguments   : none
5038 #############################################################################
5040 sub ReadInterfaces {
5041     %Interfaces = ();
5043     if (! -f $INTERFACES_FILE) {
5044         return;
5045     }
5046     if (!open (INPUT, $INTERFACES_FILE)) {
5047         warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
5048         return;
5049     }
5051     while (<INPUT>) {
5052        chomp;
5053        my ($object, @ifaces) = split;
5054        if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5055            my @knownIfaces = ();
5057            # filter out private interfaces, but leave foreign interfaces
5058            foreach my $iface (@ifaces) {
5059                if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
5060                    push (@knownIfaces, $iface);
5061                }
5062              }
5064            $Interfaces{$object} = join(' ', @knownIfaces);
5065        }
5066     }
5067     close (INPUT);
5070 #############################################################################
5071 # Function    : ReadPrerequisites
5072 # Description : This reads in the $MODULE.prerequisites file.
5074 # Arguments   : none
5075 #############################################################################
5077 sub ReadPrerequisites {
5078     %Prerequisites = ();
5080     if (! -f $PREREQUISITES_FILE) {
5081         return;
5082     }
5083     if (!open (INPUT, $PREREQUISITES_FILE)) {
5084         warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
5085         return;
5086     }
5088     while (<INPUT>) {
5089        chomp;
5090        my ($iface, @prereqs) = split;
5091        if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
5092            my @knownPrereqs = ();
5094            # filter out private prerequisites, but leave foreign prerequisites
5095            foreach my $prereq (@prereqs) {
5096                if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
5097                   push (@knownPrereqs, $prereq);
5098                }
5099            }
5101            $Prerequisites{$iface} = join(' ', @knownPrereqs);
5102        }
5103     }
5104     close (INPUT);
5107 #############################################################################
5108 # Function    : ReadArgsFile
5109 # Description : This reads in an existing file which contains information on
5110 #               all GTK args. It creates the arrays @ArgObjects, @ArgNames,
5111 #               @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
5112 #               on the args.
5113 # Arguments   : $file - the file containing the arg information.
5114 #############################################################################
5116 sub ReadArgsFile {
5117     my ($file) = @_;
5119     my $in_arg = 0;
5120     my $arg_object;
5121     my $arg_name;
5122     my $arg_type;
5123     my $arg_flags;
5124     my $arg_nick;
5125     my $arg_blurb;
5126     my $arg_default;
5127     my $arg_range;
5129     # Reset the args info.
5130     @ArgObjects = ();
5131     @ArgNames = ();
5132     @ArgTypes = ();
5133     @ArgFlags = ();
5134     @ArgNicks = ();
5135     @ArgBlurbs = ();
5136     @ArgDefaults = ();
5137     @ArgRanges = ();
5139     if (! -f $file) {
5140         return;
5141     }
5142     if (!open (INPUT, $file)) {
5143         warn "Can't open $file - skipping args\n";
5144         return;
5145     }
5146     while (<INPUT>) {
5147         if (!$in_arg) {
5148             if (m/^<ARG>/) {
5149                 $in_arg = 1;
5150                 $arg_object = "";
5151                 $arg_name = "";
5152                 $arg_type = "";
5153                 $arg_flags = "";
5154                 $arg_nick = "";
5155                 $arg_blurb = "";
5156                 $arg_default = "";
5157                 $arg_range = "";
5158             }
5159         } else {
5160             if (m/^<NAME>(.*)<\/NAME>/) {
5161                 $arg_name = $1;
5162                 if ($arg_name =~ m/^(.*)::(.*)$/) {
5163                     $arg_object = $1;
5164                     ($arg_name = $2) =~ s/_/-/g;
5165                     #print "Found arg: $arg_name\n";
5166                 } else {
5167                     &LogWarning ($file, $., "Invalid argument name: $arg_name");
5168                 }
5169             } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
5170                 $arg_type = $1;
5171             } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
5172                 $arg_range = $1;
5173             } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
5174                 $arg_flags = $1;
5175             } elsif (m/^<NICK>(.*)<\/NICK>/) {
5176                 $arg_nick = $1;
5177             } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
5178                 $arg_blurb = $1;
5179                 if ($arg_blurb eq "(null)") {
5180                   $arg_blurb = "";
5181                   &LogWarning ($file, $., "Property ${arg_object}:${arg_name} has no documentation.");
5182                 }
5183             } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
5184                 $arg_default = $1;
5185             } elsif (m%^</ARG>%) {
5186                 #print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
5187                 push (@ArgObjects, $arg_object);
5188                 push (@ArgNames, $arg_name);
5189                 push (@ArgTypes, $arg_type);
5190                 push (@ArgRanges, $arg_range);
5191                 push (@ArgFlags, $arg_flags);
5192                 push (@ArgNicks, $arg_nick);
5193                 push (@ArgBlurbs, $arg_blurb);
5194                 push (@ArgDefaults, $arg_default);
5195                 $in_arg = 0;
5196             }
5197         }
5198     }
5199     close (INPUT);
5203 #############################################################################
5204 # Function    : CheckIsObject
5205 # Description : Returns 1 if the given name is a GObject or a subclass.
5206 #               It uses the global @Objects array.
5207 #               Note that the @Objects array only contains classes in the
5208 #               current module and their ancestors - not all GObject classes.
5209 # Arguments   : $name - the name to check.
5210 #############################################################################
5212 sub CheckIsObject {
5213     my ($name) = @_;
5215     my $object;
5216     foreach $object (@Objects) {
5217         if ($object eq $name) {
5218             return 1;
5219         }
5220     }
5221     return 0;
5225 #############################################################################
5226 # Function    : MakeReturnField
5227 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
5228 # Arguments   : $str - the string to pad.
5229 #############################################################################
5231 sub MakeReturnField {
5232     my ($str) = @_;
5234     return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));
5237 #############################################################################
5238 # Function    : GetSymbolSourceFile
5239 # Description : Get the filename where the symbol docs where taken from.
5240 # Arguments   : $symbol - the symbol name
5241 #############################################################################
5243 sub GetSymbolSourceFile {
5244     my ($symbol) = @_;
5246     if (defined($SourceSymbolSourceFile{$symbol})) {
5247         return $SourceSymbolSourceFile{$symbol};
5248     } elsif (defined($SymbolSourceFile{$symbol})) {
5249         return $SymbolSourceFile{$symbol};
5250     } else {
5251         return "";
5252     }
5255 #############################################################################
5256 # Function    : GetSymbolSourceLine
5257 # Description : Get the file line where the symbol docs where taken from.
5258 # Arguments   : $symbol - the symbol name
5259 #############################################################################
5261 sub GetSymbolSourceLine {
5262     my ($symbol) = @_;
5264     if (defined($SourceSymbolSourceLine{$symbol})) {
5265         return $SourceSymbolSourceLine{$symbol};
5266     } elsif (defined($SymbolSourceLine{$symbol})) {
5267         return $SymbolSourceLine{$symbol};
5268     } else {
5269         return 0;
5270     }