Generate unique ids for properties, style and child properties.
[gtk-doc.git] / gtkdoc-mkdb.in
blob71b9fcb444d014592c67fa0e5a3445f905aef016
1 #!@PERL@ -w
2 # -*- cperl -*-
4 # gtk-doc - GTK DocBook documentation generator.
5 # Copyright (C) 1998  Damon Chaplin
6 #               2007,2008  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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #############################################################################
24 # Script      : gtkdoc-mkdb
25 # Description : This creates the DocBook files from the edited templates.
27 #               NOTE: When creating SGML IDS, we append ":CAPS" to all
28 #               all-caps identifiers to prevent name clashes. (It basically
29 #               never is the case that mixed-case identifiers would collide.)
30 #               See the CreateValidSGMLID function.
31 #############################################################################
33 use strict;
34 use Getopt::Long;
36 unshift @INC, '@PACKAGE_DATA_DIR@';
37 require "gtkdoc-common.pl";
39 # Options
41 # name of documentation module
42 my $MODULE;
43 my $TMPL_DIR;
44 my $SGML_OUTPUT_DIR;
45 my @SOURCE_DIRS;
46 my $SOURCE_SUFFIXES = "";
47 my $IGNORE_FILES = "";
48 my $PRINT_VERSION;
49 my $PRINT_HELP;
50 my $OUTPUT_ALL_SYMBOLS;
51 my $MAIN_SGML_FILE;
52 my $EXPAND_CONTENT_FILES = "";
53 my $SGML_MODE;
54 my $DEFAULT_STABILITY;
55 my $DEFAULT_INCLUDES;
56 my $OUTPUT_FORMAT;
57 my $NAME_SPACE = "";
59 my %optctl = ('module' => \$MODULE,
60               'source-dir' => \@SOURCE_DIRS,
61               'source-suffixes' => \$SOURCE_SUFFIXES,
62               'ignore-files' => \$IGNORE_FILES,
63               'output-dir' => \$SGML_OUTPUT_DIR,
64               'tmpl-dir' => \$TMPL_DIR,
65               'version' => \$PRINT_VERSION,
66               'help' => \$PRINT_HELP,
67               'main-sgml-file' => \$MAIN_SGML_FILE,
68               'expand-content-files' => \$EXPAND_CONTENT_FILES,
69               'outputallsymbols' => \$OUTPUT_ALL_SYMBOLS,
70               'sgml-mode' => \$SGML_MODE,
71               'default-stability' => \$DEFAULT_STABILITY,
72               'default-includes' => \$DEFAULT_INCLUDES,
73               'output-format' => \$OUTPUT_FORMAT,
74               'name-space' => \$NAME_SPACE);
75 GetOptions(\%optctl, "module=s", "source-dir:s", "source-suffixes:s", 
76     "ignore-files:s", "output-dir:s", "tmpl-dir:s", "version", "outputallsymbols",
77      "expand-content-files:s", "main-sgml-file:s", "extra-db-files:s", "help",
78      "sgml-mode", "default-stability:s", "default-includes:s", "output-format:s",
79      "name-space:s");
81 if ($PRINT_VERSION) {
82     print "@VERSION@\n";
83     exit 0;
86 if (!$MODULE) {
87     $PRINT_HELP = 1;
90 if ($DEFAULT_STABILITY && $DEFAULT_STABILITY ne "Stable"
91     && $DEFAULT_STABILITY ne "Private" && $DEFAULT_STABILITY ne "Unstable") {
92     $PRINT_HELP = 1;
95 if ($PRINT_HELP) {
96     print <<EOF;
97 gtkdoc-mkdb version @VERSION@
99 --module=MODULE_NAME       Name of the doc module being parsed
100 --source-dir=DIRNAME       Directories which contain inline reference material
101 --source-suffixes=SUFFIXES Suffixes of source files to scan, comma-separated
102 --ignore-files=FILES       Files or directories which should not be scanned
103                            May be used more than once for multiple directories
104 --output-dir=DIRNAME       Directory to put the generated DocBook files in
105 --tmpl-dir=DIRNAME         Directory in which template files may be found
106 --main-sgml-file=FILE      File containing the toplevel DocBook file.
107 --expand-content-files=FILES Extra DocBook files to expand abbreviations in.
108 --output-format=FORMAT     Format to use for the generated docbook, XML or SGML.
109 --sgml-mode                Allow DocBook markup in inline documentation.
110 --default-stability=LEVEL  Specify default stability Level. Valid values are
111                            Stable, Unstable, or Private.
112 --default-includes=FILENAMES Specify default includes for section Synopsis
113 --name-space=NS            Omit namespace in index.
114 --version                  Print the version of this program
115 --help                     Print this help
117     exit 0;
120 my ($empty_element_end, $doctype_header);
122 if (lc($OUTPUT_FORMAT) eq "xml") {
123     if (!$MAIN_SGML_FILE) {
124         # backwards compatibility
125         if (-e "${MODULE}-docs.sgml") {
126             $MAIN_SGML_FILE="${MODULE}-docs.sgml";
127         } else {
128             $MAIN_SGML_FILE="${MODULE}-docs.xml";
129         }
130     }
131     $OUTPUT_FORMAT = "xml";
132     $empty_element_end = "/>";
134     if (-e $MAIN_SGML_FILE) {
135         open(INPUT, "<$MAIN_SGML_FILE") || die "Can't open $MAIN_SGML_FILE";
136         $doctype_header = "";
137         while (<INPUT>) {
138             if (/^\s*<(book|chapter|article)/) {
139                 if ($_ !~ m/http:\/\/www.w3.org\/200[13]\/XInclude/) {
140                     $doctype_header = "";
141                 }
142                 last;
143             }
144             $doctype_header .= $_;
145         }
146         close(INPUT);
147     } else {
148         $doctype_header =
149 "<?xml version=\"1.0\"?>\n" .
150 "<!DOCTYPE book PUBLIC \"-//OASIS//DTD DocBook XML V4.3//EN\"\n" .
151 "               \"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd\">\n";
152     }
153     $doctype_header =~ s/<!DOCTYPE \w+/<!DOCTYPE refentry/;
154 } else {
155     if (!$MAIN_SGML_FILE) {
156         $MAIN_SGML_FILE="${MODULE}-docs.sgml";
157     }
158     $OUTPUT_FORMAT = "sgml";
159     $doctype_header = "";
160     $empty_element_end = ">";
163 my $ROOT_DIR = ".";
165 # All the files are written in subdirectories beneath here.
166 $TMPL_DIR = $TMPL_DIR ? $TMPL_DIR : "$ROOT_DIR/tmpl";
168 # This is where we put all the DocBook output.
169 $SGML_OUTPUT_DIR = $SGML_OUTPUT_DIR ? $SGML_OUTPUT_DIR : "$ROOT_DIR/$OUTPUT_FORMAT";
171 # This file contains the object hierarchy.
172 my $OBJECT_TREE_FILE = "$ROOT_DIR/$MODULE.hierarchy";
174 # This file contains the interfaces.
175 my $INTERFACES_FILE = "$ROOT_DIR/$MODULE.interfaces";
177 # This file contains the prerequisites.
178 my $PREREQUISITES_FILE = "$ROOT_DIR/$MODULE.prerequisites";
180 # This file contains signal arguments and names.
181 my $SIGNALS_FILE = "$ROOT_DIR/$MODULE.signals";
183 # The file containing Arg information.
184 my $ARGS_FILE = "$ROOT_DIR/$MODULE.args";
186 # These global arrays store information on signals. Each signal has an entry
187 # in each of these arrays at the same index, like a multi-dimensional array.
188 my @SignalObjects;      # The GtkObject which emits the signal.
189 my @SignalNames;        # The signal name.
190 my @SignalReturns;      # The return type.
191 my @SignalFlags;        # Flags for the signal
192 my @SignalPrototypes;   # The rest of the prototype of the signal handler.
194 # These global arrays store information on Args. Each Arg has an entry
195 # in each of these arrays at the same index, like a multi-dimensional array.
196 my @ArgObjects;         # The GtkObject which has the Arg.
197 my @ArgNames;           # The Arg name.
198 my @ArgTypes;           # The Arg type - gint, GtkArrowType etc.
199 my @ArgFlags;           # How the Arg can be used - readable/writable etc.
200 my @ArgNicks;           # The nickname of the Arg.
201 my @ArgBlurbs;          # Docstring of the Arg.
202 my @ArgDefaults;        # Default value of the Arg.
203 my @ArgRanges;          # The range of the Arg type
204 # These global hashes store declaration info keyed on a symbol name.
205 my %Declarations;
206 my %DeclarationTypes;
207 my %DeclarationConditional;
208 my %DeclarationOutput;
209 my %Deprecated;
210 my %Since;
211 my %StabilityLevel;
212 my %StructHasTypedef;
214 # These global hashes store the existing documentation.
215 my %SymbolDocs;
216 my %SymbolTypes;
217 my %SymbolParams;
218 my %SymbolSourceFile;
219 my %SymbolSourceLine;
221 # These global hashes store documentation scanned from the source files.
222 my %SourceSymbolDocs;
223 my %SourceSymbolParams;
224 my %SourceSymbolSourceFile;
225 my %SourceSymbolSourceLine;
227 # all documentation goes in here, so we can do coverage analysis
228 my %AllSymbols;
229 my %AllIncompleteSymbols;
230 my %AllDocumentedSymbols;
232 # Undeclared yet documented symbols
233 my %UndeclaredSymbols;
235 # These global arrays store GObject, subclasses and the hierarchy.
236 my @Objects;
237 my @ObjectLevels;
239 my %Interfaces;
240 my %Prerequisites;
242 # holds the symbols which are mentioned in $MODULE-sections.txt
243 my %KnownSymbols;
245 # collects index entries
246 my %IndexEntriesFull;
247 my %IndexEntriesSince;
248 my %IndexEntriesDeprecated;
250 # Standard C preprocessor directives, which we ignore for '#' abbreviations.
251 my %PreProcessorDirectives;
252 $PreProcessorDirectives{"assert"} = 1;
253 $PreProcessorDirectives{"define"} = 1;
254 $PreProcessorDirectives{"elif"} = 1;
255 $PreProcessorDirectives{"else"} = 1;
256 $PreProcessorDirectives{"endif"} = 1;
257 $PreProcessorDirectives{"error"} = 1;
258 $PreProcessorDirectives{"if"} = 1;
259 $PreProcessorDirectives{"ifdef"} = 1;
260 $PreProcessorDirectives{"ifndef"} = 1;
261 $PreProcessorDirectives{"include"} = 1;
262 $PreProcessorDirectives{"line"} = 1;
263 $PreProcessorDirectives{"pragma"} = 1;
264 $PreProcessorDirectives{"unassert"} = 1;
265 $PreProcessorDirectives{"undef"} = 1;
266 $PreProcessorDirectives{"warning"} = 1;
268 # Create the root DocBook output directory if it doens't exist.
269 if (! -e $SGML_OUTPUT_DIR) {
270     mkdir ("$SGML_OUTPUT_DIR", 0777)
271         || die "Can't create directory: $SGML_OUTPUT_DIR";
274 # Function and other declaration output settings.
275 my $RETURN_TYPE_FIELD_WIDTH = 20;
276 my $SYMBOL_FIELD_WIDTH = 36;
277 my $SIGNAL_FIELD_WIDTH = 16;
279 &ReadKnownSymbols ("$ROOT_DIR/$MODULE-sections.txt");
280 &ReadSignalsFile ($SIGNALS_FILE);
281 &ReadArgsFile ($ARGS_FILE);
282 &ReadObjectHierarchy;
283 &ReadInterfaces;
284 &ReadPrerequisites;
286 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-decl.txt", 0);
287 if (-f "$ROOT_DIR/$MODULE-overrides.txt") {
288     &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-overrides.txt", 1);
291 for my $dir (@SOURCE_DIRS) {
292     &ReadSourceDocumentation ($dir);
295 my $changed = &OutputSGML ("$ROOT_DIR/$MODULE-sections.txt");
297 # If any of the DocBook SGML files have changed, update the timestamp file (so
298 # it can be used for Makefile dependencies).
299 if ($changed || ! -e "$ROOT_DIR/sgml.stamp") {
301     &OutputIndexFull;
302     &OutputDeprecatedIndex;
303     &OutputSinceIndexes;
305     open (TIMESTAMP, ">$ROOT_DIR/sgml.stamp")
306         || die "Can't create $ROOT_DIR/sgml.stamp: $!";
307     print (TIMESTAMP "timestamp");
308     close (TIMESTAMP);
311 #############################################################################
312 # Function    : OutputObjectList
313 # Description : This outputs the alphabetical list of objects, in a columned
314 #               table. FIXME: Currently this also outputs ancestor objects
315 #               which may not actually be in this module.
316 # Arguments   : none
317 #############################################################################
319 sub OutputObjectList {
320     my $cols = 3;
321     
322     # FIXME: use $OUTPUT_FORMAT
323     # my $old_object_index = "$SGML_OUTPUT_DIR/object_index.$OUTPUT_FORMAT";
324     my $old_object_index = "$SGML_OUTPUT_DIR/object_index.sgml";
325     my $new_object_index = "$SGML_OUTPUT_DIR/object_index.new";
327     open (OUTPUT, ">$new_object_index")
328         || die "Can't create $new_object_index: $!";
330     if (lc($OUTPUT_FORMAT) eq "xml") {
331         my $header = $doctype_header;
333         $header =~ s/<!DOCTYPE \w+/<!DOCTYPE informaltable/;
334         print (OUTPUT "$header");
335     }
337     print (OUTPUT <<EOF);
338 <informaltable pgwide="1" frame="none">
339 <tgroup cols="$cols">
340 <colspec colwidth="1*"${empty_element_end}
341 <colspec colwidth="1*"${empty_element_end}
342 <colspec colwidth="1*"${empty_element_end}
343 <tbody>
346     my $count = 0;
347     my $object;
348     foreach $object (sort (@Objects)) {
349         my $xref = &MakeXRef ($object);
350         if ($count % $cols == 0) { print (OUTPUT "<row>\n"); }
351         print (OUTPUT "<entry>$xref</entry>\n");
352         if ($count % $cols == ($cols - 1)) { print (OUTPUT "</row>\n"); }
353         $count++;
354     }
355     if ($count == 0) {
356         # emit an empty row, since empty tables are invalid
357         print (OUTPUT "<row><entry> </entry></row>\n");
358     }
359     else {
360         print (OUTPUT "</row>\n");
361     }
363     print (OUTPUT <<EOF);
364 </tbody></tgroup></informaltable>
366     close (OUTPUT);
368     &UpdateFileIfChanged ($old_object_index, $new_object_index, 0);
372 #############################################################################
373 # Function    : OutputSGML
374 # Description : This collects the output for each section of the docs, and
375 #               outputs each file when the end of the section is found.
376 # Arguments   : $file - the $MODULE-sections.txt file which contains all of
377 #               the functions/macros/structs etc. being documented, organised
378 #               into sections and subsections.
379 #############################################################################
381 sub OutputSGML {
382     my ($file) = @_;
384     #print "Reading: $file\n";
385     open (INPUT, $file)
386         || die "Can't open $file: $!";
387     my $filename = "";
388     my $book_top = "";
389     my $book_bottom = "";
390     my $includes = (defined $DEFAULT_INCLUDES) ? $DEFAULT_INCLUDES : "";
391     my $section_includes = "";
392     my $in_section = 0;
393     my $title = "";
394     my $subsection = "";
395     my $synopsis;
396     my $details;
397     my $num_symbols;
398     my $changed = 0;
399     my $signals_synop = "";
400     my $signals_desc = "";
401     my $args_synop = "";
402     my $child_args_synop = "";
403     my $style_args_synop = "";
404     my $args_desc = "";
405     my $child_args_desc = "";
406     my $style_args_desc = "";
407     my $hierarchy = "";
408     my $interfaces = "";
409     my $implementations = "";
410     my $prerequisites = "";
411     my $derived = "";
412     my @file_objects = ();
413     my %templates = ();
414     my %symbols = ();
416     # merge the source docs, in case there are no templates
417     &MergeSourceDocumentation;
419     while (<INPUT>) {
420         if (m/^#/) {
421             next;
423         } elsif (m/^<SECTION>/) {
424             $synopsis = "";
425             $details = "";
426             $num_symbols = 0;
427             $in_section = 1;
428             @file_objects = ();
429             %symbols = ();
431         } elsif (m/^<SUBSECTION\s*(.*)>/i) {
432             $synopsis .= "\n";
433             $subsection = $1;
435         } elsif (m/^<SUBSECTION>/) {
437         } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
438             $title = $1;
439             #print "Section: $title\n";
441             # We don't want warnings if object & class structs aren't used.
442             $DeclarationOutput{$title} = 1;
443             $DeclarationOutput{"${title}Class"} = 1;
445         } elsif (m/^<FILE>(.*)<\/FILE>/) {
446             $filename = $1;
447             if (! defined $templates{$filename}) {
448                if (&ReadTemplateFile ("$TMPL_DIR/$filename", 1)) {
449                    &MergeSourceDocumentation;
450                    $templates{$filename}=$.;
451                }
452             } else {
453                 &LogWarning ($file, $., "Double <FILE>$filename</FILE> entry. ".
454                     "Previous occurrence on line ".$templates{$filename}.".");
455             }
457         } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
458             if ($in_section) {
459                 $section_includes = $1;
460             } else {
461                 if (defined $DEFAULT_INCLUDES) {
462                     &LogWarning ($file, $., "Default <INCLUDE> being overridden by command line option.");
463                 }
464                 else {
465                     $includes = $1;
466                 }
467             }
469         } elsif (m/^<\/SECTION>/) {
470             if($title eq "" && $filename eq "") {
471                 &LogWarning ($file, $., "Section has no title and no file.");
472             }
473             # FIXME: one of those would be enough
474             if ($title eq "") {
475                 $title = $filename;
476             }
477             if ($filename eq "") {
478                 $filename = $title;
479             }
480             #print "End of section: $title\n";
482             $filename =~ s/\s/_/g;
484             my $section_id = $SourceSymbolDocs{"$TMPL_DIR/$filename:Section_Id"};
485             if (defined ($section_id) && $section_id !~ m/^\s*$/) {
486                 # Do nothing. Use section_id as it is.
487             } elsif (&CheckIsObject ($title)) {
488                 # GtkObjects use their class name as the ID.
489                 $section_id = &CreateValidSGMLID ($title);
490             } else {
491                 $section_id = &CreateValidSGMLID ("$MODULE-$title");
492             }
494             if ($num_symbols > 0) {
495                 # collect documents
496                 if (lc($OUTPUT_FORMAT) eq "xml") {
497                     $book_bottom .= "    <xi:include href=\"xml/$filename.xml\"/>\n";
498                 } else {
499                     $book_top.="<!ENTITY $section_id SYSTEM \"sgml/$filename.sgml\">\n";
500                     $book_bottom .= "    &$section_id;\n";
501                 }
503                 if (defined ($SourceSymbolDocs{"$TMPL_DIR/$filename:Include"})) {
504                     if ($section_includes) {
505                         &LogWarning ($file, $., "Section <INCLUDE> being overridden by inline comments.");
506                     }
507                     $section_includes = $SourceSymbolDocs{"$TMPL_DIR/$filename:Include"};
508                 }
509                 if ($section_includes eq "") {
510                     $section_includes = $includes;
511                 }
513                  $signals_synop =~ s/^\n*//g;
514                  $signals_synop =~ s/\n+$/\n/g;
515                 if ($signals_synop ne '') {
516                     $signals_synop = <<EOF;
517 <refsect1 id="$section_id.signals" role="signal_proto">
518 <title role="signal_proto.title">Signals</title>
519 <synopsis>
520 ${signals_synop}</synopsis>
521 </refsect1>
523                      $signals_desc =~ s/^\n*//g;
524                      $signals_desc =~ s/\n+$/\n/g;
525                      $signals_desc =~ s/(\s|\n)+$//ms;
526                     $signals_desc  = <<EOF;
527 <refsect1 id="$section_id.signal-details" role="signals">
528 <title role="signals.title">Signal Details</title>
529 $signals_desc
530 </refsect1>
532                 }
534                  $args_synop =~ s/^\n*//g;
535                  $args_synop =~ s/\n+$/\n/g;
536                 if ($args_synop ne '') {
537                     $args_synop = <<EOF;
538 <refsect1 id="$section_id.properties" role="properties">
539 <title role="properties.title">Properties</title>
540 <synopsis>
541 ${args_synop}</synopsis>
542 </refsect1>
544                      $args_desc =~ s/^\n*//g;
545                      $args_desc =~ s/\n+$/\n/g;
546                      $args_desc =~ s/(\s|\n)+$//ms;
547                     $args_desc  = <<EOF;
548 <refsect1 id="$section_id.property-details" role="property_details">
549 <title role="property_details.title">Property Details</title>
550 $args_desc
551 </refsect1>
553                 }
555                  $child_args_synop =~ s/^\n*//g;
556                  $child_args_synop =~ s/\n+$/\n/g;
557                 if ($child_args_synop ne '') {
558                     $args_synop .= <<EOF;
559 <refsect1 id="$section_id.child-properties" role="child_properties">
560 <title role="child_properties.title">Child Properties</title>
561 <synopsis>
562 ${child_args_synop}</synopsis>
563 </refsect1>
565                      $child_args_desc =~ s/^\n*//g;
566                      $child_args_desc =~ s/\n+$/\n/g;
567                      $child_args_desc =~ s/(\s|\n)+$//ms;
568                     $args_desc .= <<EOF;
569 <refsect1 id="$section_id.child-property-details" role="child_property_details">
570 <title role="child_property_details.title">Child Property Details</title>
571 $child_args_desc
572 </refsect1>
574                 }
576                  $style_args_synop =~ s/^\n*//g;
577                  $style_args_synop =~ s/\n+$/\n/g;
578                 if ($style_args_synop ne '') {
579                     $args_synop .= <<EOF;
580 <refsect1 id="$section_id.style-properties" role="style_properties">
581 <title role="style_properties.title">Style Properties</title>
582 <synopsis>
583 ${style_args_synop}</synopsis>
584 </refsect1>
586                      $style_args_desc =~ s/^\n*//g;
587                      $style_args_desc =~ s/\n+$/\n/g;
588                      $style_args_desc =~ s/(\s|\n)+$//ms;
589                     $args_desc .= <<EOF;
590 <refsect1 id="$section_id.style-property-details" role="style_properties_details">
591 <title role="style_properties_details.title">Style Property Details</title>
592 $style_args_desc
593 </refsect1>
595                 }
597                  $hierarchy =~ s/^\n*//g;
598                  $hierarchy =~ s/\n+$/\n/g;
599                  $hierarchy =~ s/(\s|\n)+$//ms;
600                 if ($hierarchy ne "") {
601                     $hierarchy = <<EOF;
602 <refsect1 id="$section_id.object-hierarchy" role="object_hierarchy">
603 <title role="object_hierarchy.title">Object Hierarchy</title>
604 $hierarchy
605 </refsect1>
607                 }
609                  $interfaces =~ s/^\n*//g;
610                  $interfaces =~ s/\n+$/\n/g;
611                  $interfaces =~ s/(\s|\n)+$//ms;
612                 if ($interfaces ne "") {
613                     $interfaces = <<EOF;
614 <refsect1 id="$section_id.implemented-interfaces" role="impl_interfaces">
615 <title role="impl_interfaces.title">Implemented Interfaces</title>
616 $interfaces
617 </refsect1>
619                 }
621                  $implementations =~ s/^\n*//g;
622                  $implementations =~ s/\n+$/\n/g;
623                  $implementations =~ s/(\s|\n)+$//ms;
624                 if ($implementations ne "") {
625                     $implementations = <<EOF;
626 <refsect1 id="$section_id.implementations" role="implementations">
627 <title role="implementations.title">Known Implementations</title>
628 $implementations
629 </refsect1>
631                 }
633                  $prerequisites =~ s/^\n*//g;
634                  $prerequisites =~ s/\n+$/\n/g;
635                  $prerequisites =~ s/(\s|\n)+$//ms;
636                 if ($prerequisites ne "") {
637                     $prerequisites = <<EOF;
638 <refsect1 id="$section_id.prerequisites" role="prerequisites">
639 <title role="prerequisites.title">Prerequisites</title>
640 $prerequisites
641 </refsect1>
643                 }
645                  $derived =~ s/^\n*//g;
646                  $derived =~ s/\n+$/\n/g;
647                  $derived =~ s/(\s|\n)+$//ms;
648                 if ($derived ne "") {
649                     $derived = <<EOF;
650 <refsect1 id="$section_id.derived-interfaces" role="derived_interfaces">
651 <title role="derived_interfaces.title">Known Derived Interfaces</title>
652 $derived
653 </refsect1>
655                 }
657                 $synopsis =~ s/^\n*//g;
658                 $synopsis =~ s/\n+$/\n/g;
659                 my $file_changed = &OutputSGMLFile ($filename, $title, $section_id,
660                                                     $section_includes,
661                                                     \$synopsis, \$details,
662                                                     \$signals_synop, \$signals_desc,
663                                                     \$args_synop, \$args_desc,
664                                                     \$hierarchy, \$interfaces,
665                                                     \$implementations,
666                                                     \$prerequisites, \$derived,
667                                                     \@file_objects);
668                 if ($file_changed) {
669                     $changed = 1;
670                 }
671             }
672             $title = "";
673             $subsection = "";
674             $in_section = 0;
675             $section_includes = "";
676             $signals_synop = "";
677             $signals_desc = "";
678             $args_synop = "";
679             $child_args_synop = "";
680             $style_args_synop = "";
681             $args_desc = "";
682             $child_args_desc = "";
683             $style_args_desc = "";
684             $hierarchy = "";
685             $interfaces = "";
686             $implementations = "";
687             $prerequisites = "";
688             $derived = "";
690         } elsif (m/^(\S+)/) {
691             my $symbol = $1;
692             #print "  Symbol: $symbol\n";
694             # FIXME: check for duplicate entries
695             if (! defined $symbols{$symbol}) {
696                 my $declaration = $Declarations{$symbol};
697                 if (defined ($declaration)) {
698                     # We don't want standard macros/functions of GtkObjects,
699                     # or private declarations.
700                     if ($subsection ne "Standard" && $subsection ne "Private") {
701                         if (&CheckIsObject ($symbol)) {
702                             push @file_objects, $symbol;
703                         }
704                         my ($synop, $desc) = &OutputDeclaration ($symbol,
705                                                                  $declaration);
706                         my ($sig_synop, $sig_desc) = &GetSignals ($symbol);
707                         my ($arg_synop, $child_arg_synop, $style_arg_synop,
708                             $arg_desc, $child_arg_desc, $style_arg_desc) = &GetArgs ($symbol);
709                         my $hier = &GetHierarchy ($symbol);
710                         my $ifaces = &GetInterfaces ($symbol);
711                         my $impls = &GetImplementations ($symbol);
712                         my $prereqs = &GetPrerequisites ($symbol);
713                         my $der = &GetDerived ($symbol);
714                         $synopsis .= $synop;
715                         $details .= $desc;
716                         $signals_synop .= $sig_synop;
717                         $signals_desc .= $sig_desc;
718                         $args_synop .= $arg_synop;
719                         $child_args_synop .= $child_arg_synop;
720                         $style_args_synop .= $style_arg_synop;
721                         $args_desc .= $arg_desc;
722                         $child_args_desc .= $child_arg_desc;
723                         $style_args_desc .= $style_arg_desc;
724                         $hierarchy .= $hier;
725                         $interfaces .= $ifaces;
726                         $implementations .= $impls;
727                         $prerequisites .= $prereqs;
728                         $derived .= $der;
729                     }
730     
731                     # Note that the declaration has been output.
732                     $DeclarationOutput{$symbol} = 1;
733                 } elsif ($subsection ne "Standard" && $subsection ne "Private") {
734                     $UndeclaredSymbols{$symbol} = 1;
735                     &LogWarning ($file, $., "No declaration found for $symbol.");
736                 }
737                 $num_symbols++;
738                 $symbols{$symbol}=$.;
739             }
740             else {
741                 &LogWarning ($file, $., "Double symbol entry for $symbol. ".
742                     "Previous occurrence on line ".$symbols{$symbol}.".");
743             }
744         }
745     }
746     close (INPUT);
748     &OutputMissingDocumentation;
749     &OutputUndeclaredSymbols;
751     if ($OUTPUT_ALL_SYMBOLS) {
752         &OutputAllSymbols;
753     }
755     for $filename (split (' ', $EXPAND_CONTENT_FILES)) {
756         my $file_changed = &OutputExtraFile ($filename);
757         if ($file_changed) {
758             $changed = 1;
759         }
760     }
762     &OutputBook ($book_top, $book_bottom);
764     return $changed;
767 #############################################################################
768 # Function    : OutputIndex
769 # Description : This writes an indexlist that can be included into the main-
770 #               document into an <index> tag.
771 #############################################################################
773 sub OutputIndex {
774     my ($basename, $apiindexref ) = @_;
775     my %apiindex = %{$apiindexref};
776     my $old_index = "$SGML_OUTPUT_DIR/$basename.xml";
777     my $new_index = "$SGML_OUTPUT_DIR/$basename.new";
778     my $lastletter = " ";
779     my $divopen = 0;
780     my $symbol;
781     my $short_symbol;
783     open (OUTPUT, ">$new_index")
784         || die "Can't create $new_index";
786     my $header = $doctype_header;
787     $header =~ s/<!DOCTYPE \w+/<!DOCTYPE indexdiv/;
789     print (OUTPUT "$header<indexdiv>\n");
791     #print "generate $basename index (".%apiindex." entries)\n";
792     
793     # do a case insensitive sort while chopping off the prefix
794     foreach my $hash (
795         sort { $$a{kriterium} cmp $$b{kriterium} }
796         map { my $x = uc($_); $x =~ s/^$NAME_SPACE\_?(.*)/$1/i; { kriterium => $x, original => $_, short => $1 } } 
797         keys %apiindex) {
799         $symbol = $$hash{original};
800         $short_symbol = $$hash{short};
802         my $xref = &MakeXRef ($symbol);
803         my $curletter = uc(substr($short_symbol,0,1));
804         my $id = $apiindex{$symbol};
805         
806         #print "  add symbol $symbol with $id to index\n";
808         if ($curletter ne $lastletter) {
809             $lastletter = $curletter;
810       
811             if ($divopen == 1) {
812                 print (OUTPUT "</indexdiv>\n");
813             }
814             print (OUTPUT "<indexdiv><title>$curletter</title>\n");
815             $divopen = 1;
816         }
818         print (OUTPUT <<EOF);
819 <indexentry><primaryie linkends="$id">$xref</primaryie></indexentry>
821     }
823     if ($divopen == 1) {
824         print (OUTPUT "</indexdiv>\n");
825     }
826     print (OUTPUT "</indexdiv>\n");
827     close (OUTPUT);
829     &UpdateFileIfChanged ($old_index, $new_index, 0);
833 #############################################################################
834 # Function    : OutputIndexFull
835 # Description : This writes the full api indexlist that can be included into the
836 #               main document into an <index> tag.
837 #############################################################################
839 sub OutputIndexFull {
840     &OutputIndex ("api-index-full", \%IndexEntriesFull);
844 #############################################################################
845 # Function    : OutputDeprecatedIndex
846 # Description : This writes the deprecated api indexlist that can be included
847 #               into the main document into an <index> tag.
848 #############################################################################
850 sub OutputDeprecatedIndex {
851     &OutputIndex ("api-index-deprecated", \%IndexEntriesDeprecated);
855 #############################################################################
856 # Function    : OutputSinceIndexes
857 # Description : This writes the 'since' api indexlists that can be included into
858 #               the main document into an <index> tag.
859 #############################################################################
861 sub OutputSinceIndexes {
862     my @sinces = keys %{{ map { $_ => 1 } values %Since }};
864     foreach my $version (@sinces) {
865         #print "Since : [$version]\n";
866         # todo make filtered hash
867         #my %index = grep { $Since{$_} eq $version } %IndexEntriesSince;
868         my %index = map { $_ => $IndexEntriesSince{$_} } grep { $Since{$_} eq $version } keys %IndexEntriesSince;
870         &OutputIndex ("api-index-$version", \%index);
871     }
875 #############################################################################
876 # Function    : ReadKnownSymbols
877 # Description : This collects the names of non-private symbols from the
878 #               $MODULE-sections.txt file.
879 # Arguments   : $file - the $MODULE-sections.txt file which contains all of
880 #               the functions/macros/structs etc. being documented, organised
881 #               into sections and subsections.
882 #############################################################################
884 sub ReadKnownSymbols {
885     my ($file) = @_;
887     my $subsection = "";
889     #print "Reading: $file\n";
890     open (INPUT, $file)
891         || die "Can't open $file: $!";
893     while (<INPUT>) {
894         if (m/^#/) {
895             next;
897         } elsif (m/^<SECTION>/) {
898             $subsection = "";
900         } elsif (m/^<SUBSECTION\s*(.*)>/i) {
901             $subsection = $1;
903         } elsif (m/^<SUBSECTION>/) {
904             next;
906         } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
907             next;
909         } elsif (m/^<FILE>(.*)<\/FILE>/) {
910             next;
912         } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
913             next;
915         } elsif (m/^<\/SECTION>/) {
916             next;
918         } elsif (m/^(\S+)/) {
919             my $symbol = $1;
921             if ($subsection ne "Standard" && $subsection ne "Private") {
922                 $KnownSymbols{$symbol} = 1;
923             }
924             else {
925                 $KnownSymbols{$symbol} = 0;
926             }
927         }
928     }
929     close (INPUT);
933 #############################################################################
934 # Function    : OutputDeclaration
935 # Description : Returns the synopsis and detailed description DocBook
936 #               describing one function/macro etc.
937 # Arguments   : $symbol - the name of the function/macro begin described.
938 #               $declaration - the declaration of the function/macro.
939 #############################################################################
941 sub OutputDeclaration {
942     my ($symbol, $declaration) = @_;
944     my $type = $DeclarationTypes {$symbol};
945     if ($type eq 'MACRO') {
946         return &OutputMacro ($symbol, $declaration);
947     } elsif ($type eq 'TYPEDEF') {
948         return &OutputTypedef ($symbol, $declaration);
949     } elsif ($type eq 'STRUCT') {
950         return &OutputStruct ($symbol, $declaration);
951     } elsif ($type eq 'ENUM') {
952         return &OutputEnum ($symbol, $declaration);
953     } elsif ($type eq 'UNION') {
954         return &OutputUnion ($symbol, $declaration);
955     } elsif ($type eq 'VARIABLE') {
956         return &OutputVariable ($symbol, $declaration);
958     } elsif ($type eq 'FUNCTION') {
959         return &OutputFunction ($symbol, $declaration, $type);
960     } elsif ($type eq 'USER_FUNCTION') {
961         return &OutputFunction ($symbol, $declaration, $type);
962     } else {
963         die "Unknown symbol type";
964     }
968 #############################################################################
969 # Function    : OutputSymbolTraits
970 # Description : Returns the Since and StabilityLevel paragraphs for a symbol.
971 # Arguments   : $symbol - the name of the function/macro begin described.
972 #############################################################################
974 sub OutputSymbolTraits {
975     my ($symbol) = @_;
976     my $desc = "";
978     if (exists $Since{$symbol}) {
979         $desc .= "<para role=\"since\">Since $Since{$symbol}</para>";
980     }
981     if (exists $StabilityLevel{$symbol}) {
982         $desc .= "<para role=\"stability\">Stability Level: $StabilityLevel{$symbol}</para>";
983     }
984     return $desc;
988 #############################################################################
989 # Function    : OutputMacro
990 # Description : Returns the synopsis and detailed description of a macro.
991 # Arguments   : $symbol - the macro.
992 #               $declaration - the declaration of the macro.
993 #############################################################################
995 sub OutputMacro {
996     my ($symbol, $declaration) = @_;
997     my $id = &CreateValidSGMLID ($symbol);
998     my $condition = &MakeConditionDescription ($symbol);
999     my $synop = &MakeReturnField("#define") . "<link linkend=\"$id\">$symbol</link>";
1000     my $desc;
1001     my $padding = "";
1002     my $args = "";
1003     my $pad;
1005     if ($declaration =~ m/^\s*#\s*define(\s+)\w+(\([^\)]*\))/) {
1006         $padding = $1;
1007         $args = $2;
1009         if (length ($symbol) < $SYMBOL_FIELD_WIDTH) {
1010             $synop .= (' ' x ($SYMBOL_FIELD_WIDTH - length ($symbol)));
1011         }
1013         # Try to align all the lines of args correctly.
1014         $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH + $SYMBOL_FIELD_WIDTH + 1);
1015         my $args_padded = $args;
1016         $args_padded =~ s/ *\\\n */\n$pad/gm;
1017         $synop .= &CreateValidSGML ($args_padded);
1018     }
1019     $synop .= "\n";
1021     my $title = $symbol . ($args ? "()" : "");
1022     $desc = "<refsect2 id=\"$id\" role=\"macro\"$condition>\n<title>$title</title>\n";
1023     $desc .= MakeIndexterms($symbol, $id);
1025     # Don't output the macro definition if is is a conditional macro or it
1026     # looks like a function, i.e. starts with "g_" or "_?gnome_", or it is
1027     # longer than 2 lines, otherwise we get lots of complicated macros like
1028     # g_assert.
1029     if (!defined ($DeclarationConditional{$symbol}) && ($symbol !~ m/^g_/)
1030         && ($symbol !~ m/^_?gnome_/) && (($declaration =~ tr/\n//) < 2)) {
1031         $declaration = &CreateValidSGML ($declaration);
1032         $desc .= "<programlisting>$declaration</programlisting>\n";
1033     } else {
1034         $desc .= "<programlisting>" . &MakeReturnField("#define") . "$symbol";
1035         # Align each line so that if should all line up OK.
1036         $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH - length ("#define "));
1037         $args =~ s/\n/\n$pad/gm;
1038         $desc .= &CreateValidSGML ($args);
1039         $desc .= "</programlisting>\n";
1040     }
1042     $desc .= &MakeDeprecationNote($symbol);
1044     my $parameters = &OutputParamDescriptions ("MACRO", $symbol);
1045     my $parameters_output = 0;
1047     if (defined ($SymbolDocs{$symbol})) {
1048         my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1050         # Try to insert the parameter table at the author's desired position.
1051         # Otherwise we need to tag it onto the end.
1052         if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1053           $parameters_output = 1;
1054         }
1055         $desc .= $symbol_docs;
1056     }
1058     if ($parameters_output == 0) {
1059         $desc .= $parameters;
1060     }
1062     $desc .= OutputSymbolTraits ($symbol);
1063     $desc .= "</refsect2>\n";
1064     return ($synop, $desc);
1068 #############################################################################
1069 # Function    : OutputTypedef
1070 # Description : Returns the synopsis and detailed description of a typedef.
1071 # Arguments   : $symbol - the typedef.
1072 #               $declaration - the declaration of the typedef,
1073 #                 e.g. 'typedef unsigned int guint;'
1074 #############################################################################
1076 sub OutputTypedef {
1077     my ($symbol, $declaration) = @_;
1078     my $id = &CreateValidSGMLID ($symbol);
1079     my $condition = &MakeConditionDescription ($symbol);
1080     my $synop = &MakeReturnField("typedef") . "<link linkend=\"$id\">$symbol</link>;\n";
1081     my $desc = "<refsect2 id=\"$id\" role=\"typedef\"$condition>\n<title>$symbol</title>\n";
1083     $desc .= MakeIndexterms($symbol, $id);
1085     if (!defined ($DeclarationConditional{$symbol})) {
1086         $declaration = &CreateValidSGML ($declaration);
1087         $desc .= "<programlisting>$declaration</programlisting>\n";
1088     }
1090     $desc .= &MakeDeprecationNote($symbol);
1092     if (defined ($SymbolDocs{$symbol})) {
1093         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1094     }
1095     $desc .= OutputSymbolTraits ($symbol);
1096     $desc .= "</refsect2>\n";
1097     return ($synop, $desc);
1101 #############################################################################
1102 # Function    : OutputStruct
1103 # Description : Returns the synopsis and detailed description of a struct.
1104 #               We check if it is a widget struct, and if so we only output
1105 #               parts of it that are noted as public fields.
1106 #               We also use a different SGML ID for widget structs, since the
1107 #               original ID is used for the entire RefEntry.
1108 # Arguments   : $symbol - the struct.
1109 #               $declaration - the declaration of the struct.
1110 #############################################################################
1112 sub OutputStruct {
1113     my ($symbol, $declaration) = @_;
1115     my $is_widget_struct = 0;
1116     my $default_to_public = 1;
1117     if (&CheckIsObject ($symbol)) {
1118     #print "Found widget struct: $symbol\n";
1119     $is_widget_struct = 1;
1120         $default_to_public = 0;
1121     }
1123     my $id;
1124     my $condition;
1125     if ($is_widget_struct) {
1126         $id = &CreateValidSGMLID ($symbol . "_struct");
1127         $condition = &MakeConditionDescription ($symbol . "_struct");
1128     } else {
1129         $id = &CreateValidSGMLID ($symbol);
1130         $condition = &MakeConditionDescription ($symbol);
1131     }
1133     # Determine if it is a simple struct or it also has a typedef.
1134     my $has_typedef = 0;
1135     if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1136       $has_typedef = 1;
1137     }
1139     my $synop;
1140     my $desc;
1141     if ($has_typedef) {
1142         # For structs with typedefs we just output the struct name.
1143         $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1144         $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>$symbol</title>\n";
1145     } else {
1146         $synop = &MakeReturnField("struct") . "<link linkend=\"$id\">$symbol</link>;\n";
1147         $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>struct $symbol</title>\n";
1148     }
1150     $desc .= MakeIndexterms($symbol, $id);
1152     # Form a pretty-printed, private-data-removed form of the declaration
1154     my $decl_out = "";
1155     if ($declaration =~ m/^\s*$/) {
1156         #print "Found opaque struct: $symbol\n";
1157         $decl_out = "typedef struct _$symbol $symbol;";
1158     } elsif ($declaration =~ m/^\s*struct\s+\w+\s*;\s*$/) {
1159         #print "Found opaque struct: $symbol\n";
1160         $decl_out = "struct $symbol;";
1161     } else {
1162         my $public = $default_to_public;
1163         my $new_declaration = "";
1164         my $decl_line;
1165         my $decl = $declaration;
1167         if ($decl =~ m/^\s*(typedef\s+)?struct\s*\w*\s*(?:\/\*.*\*\/)?\s*{(.*)}\s*\w*\s*;\s*$/s) {
1168             my $struct_contents = $2;
1170             foreach $decl_line (split (/\n/, $struct_contents)) {
1171                 #print "Struct line: $decl_line\n";
1172                 if ($decl_line =~ m%/\*\s*<\s*public\s*>\s*\*/%) {
1173                     $public = 1;
1174                 } elsif ($decl_line =~ m%/\*\s*<\s*(private|protected)\s*>\s*\*/%) {
1175                     $public = 0;
1176                 } elsif ($public) {
1177                     $new_declaration .= $decl_line . "\n";
1178                 }
1179             }
1181             if ($new_declaration) {
1182                 # Strip any blank lines off the ends.
1183                 $new_declaration =~ s/^\s*\n//;
1184                 $new_declaration =~ s/\n\s*$/\n/;
1186                 if ($has_typedef) {
1187                     $decl_out = "typedef struct {\n" . $new_declaration
1188                       . "} $symbol;\n";
1189                 } else {
1190                     $decl_out = "struct $symbol {\n" . $new_declaration
1191                       . "};\n";
1192                 }
1193             }
1194         } else {
1195             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1196                 "Couldn't parse struct:\n$declaration");
1197         }
1199         # If we couldn't parse the struct or it was all private, output an
1200         # empty struct declaration.
1201         if ($decl_out eq "") {
1202             if ($has_typedef) {
1203                 $decl_out = "typedef struct _$symbol $symbol;";
1204             } else {
1205                 $decl_out = "struct $symbol;";
1206             }
1207         }
1208     }
1210     $decl_out = &CreateValidSGML ($decl_out);
1211     $desc .= "<programlisting>$decl_out</programlisting>\n";
1213     $desc .= &MakeDeprecationNote($symbol);
1215     if (defined ($SymbolDocs{$symbol})) {
1216         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1217     }
1219     # Create a table of fields and descriptions
1221     # FIXME: Inserting &#160's into the produced type declarations here would
1222     #        improve the output in most situations ... except for function
1223     #        members of structs!
1224     my @fields = ParseStructDeclaration($declaration, !$default_to_public,
1225                                         0, \&MakeXRef,
1226                                         sub {
1227                                             "<structfield>$_[0]</structfield>";
1228                                         });
1229     my $params = $SymbolParams{$symbol};
1231     # If no parameters are filled in, we don't generate the description
1232     # table, for backwards compatibility
1234     my $found = 0;
1235     if (defined $params) {
1236         for (my $i = 1; $i <= $#$params; $i += 2) {
1237             if ($params->[$i] =~ /\S/) {
1238                 $found = 1;
1239                 last;
1240             }
1241         }
1242     }
1244     if ($found) {
1245         my %field_descrs = @$params;
1247             $desc .= <<EOF;
1248 <variablelist role="struct">
1250         while (@fields) {
1251             my $field_name = shift @fields;
1252             my $text = shift @fields;
1253             my $field_descr = $field_descrs{$field_name};
1255             $desc .= "<varlistentry>\n<term>$text</term>\n";
1256             if (defined $field_descr) {
1257                 $desc .= "<listitem><simpara>".&ExpandAbbreviations($symbol, $field_descr)."</simpara></listitem>\n";
1258             } else {
1259                 $desc .= "<listitem><simpara /></listitem>\n";
1260             }
1261             $desc .= "</varlistentry>\n";
1262         }
1264         $desc .= "</variablelist>";
1265     }
1266     $desc .= OutputSymbolTraits ($symbol);
1267     $desc .= "</refsect2>\n";
1268     return ($synop, $desc);
1272 #############################################################################
1273 # Function    : OutputEnum
1274 # Description : Returns the synopsis and detailed description of a enum.
1275 # Arguments   : $symbol - the enum.
1276 #               $declaration - the declaration of the enum.
1277 #############################################################################
1279 sub OutputEnum {
1280     my ($symbol, $declaration) = @_;
1281     my $id = &CreateValidSGMLID ($symbol);
1282     my $condition = &MakeConditionDescription ($symbol);
1283     my $synop = &MakeReturnField("enum") . "<link linkend=\"$id\">$symbol</link>;\n";
1284     my $desc = "<refsect2 id=\"$id\" role=\"enum\"$condition>\n<title>enum $symbol</title>\n";
1286     $desc .= MakeIndexterms($symbol, $id);
1288     $declaration = &CreateValidSGML ($declaration);
1289     $desc .= "<programlisting>$declaration</programlisting>\n";
1291     $desc .= &MakeDeprecationNote($symbol);
1293     if (defined ($SymbolDocs{$symbol})) {
1294         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1295     }
1297     # Create a table of fields and descriptions
1299     my @members = ParseEnumDeclaration($declaration);
1300     my $params = $SymbolParams{$symbol};
1302     # If no parameters are filled in, we don't generate the description
1303     # table, for backwards compatibility
1305     my $found = 0;
1306     if (defined $params) {
1307         for (my $i = 1; $i <= $#$params; $i += 2) {
1308             if ($params->[$i] =~ /\S/) {
1309                 $found = 1;
1310                 last;
1311             }
1312         }
1313     }
1315     if ($found) {
1316         my %member_descrs = @$params;
1318             $desc .= <<EOF;
1319 <variablelist role="enum">
1321         for my $member_name (@members) {
1322             my $member_descr = $member_descrs{$member_name};
1324             $id = &CreateValidSGMLID ($member_name);
1325             $condition = &MakeConditionDescription ($member_name);
1326             $desc .= "<varlistentry id=\"$id\" role=\"constant\"$condition>\n<term><literal>$member_name</literal></term>\n";
1327             if (defined $member_descr) {
1328                 $desc .= "<listitem><simpara>".&ExpandAbbreviations($symbol, $member_descr)."</simpara></listitem>\n";
1329             } else {
1330                 $desc .= "<listitem></listitem>\n";
1331             }
1332             $desc .= "</varlistentry>\n";
1333         }
1335         $desc .= "</variablelist>";
1336     }
1338     $desc .= OutputSymbolTraits ($symbol);
1339     $desc .= "</refsect2>\n";
1340     return ($synop, $desc);
1344 #############################################################################
1345 # Function    : OutputUnion
1346 # Description : Returns the synopsis and detailed description of a union.
1347 # Arguments   : $symbol - the union.
1348 #               $declaration - the declaration of the union.
1349 #############################################################################
1351 sub OutputUnion {
1352     my ($symbol, $declaration) = @_;
1353     my $id = &CreateValidSGMLID ($symbol);
1354     my $condition = &MakeConditionDescription ($symbol);
1355     my $synop = &MakeReturnField("union") . "<link linkend=\"$id\">$symbol</link>;\n";
1356     my $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>union $symbol</title>\n";
1358     $desc .= MakeIndexterms($symbol, $id);
1360     $declaration = &CreateValidSGML ($declaration);
1361     $desc .= "<programlisting>$declaration</programlisting>\n";
1363     $desc .= &MakeDeprecationNote($symbol);
1365     if (defined ($SymbolDocs{$symbol})) {
1366         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1367     }
1368     $desc .= OutputSymbolTraits ($symbol);
1369     $desc .= "</refsect2>\n";
1370     return ($synop, $desc);
1374 #############################################################################
1375 # Function    : OutputVariable
1376 # Description : Returns the synopsis and detailed description of a variable.
1377 # Arguments   : $symbol - the extern'ed variable.
1378 #               $declaration - the declaration of the variable.
1379 #############################################################################
1381 sub OutputVariable {
1382     my ($symbol, $declaration) = @_;
1383     my $id = &CreateValidSGMLID ($symbol);
1384     my $condition = &MakeConditionDescription ($symbol);
1386     my $synop;
1387     if ($declaration =~ m/^\s*extern\s+((const\s+|unsigned\s+)*\w+)(\s+\*+|\*+|\s)(\s*)([A-Za-z]\w*)\s*;/) {
1388         my $mod = defined ($1) ? $1 : "";
1389         my $ptr = defined ($3) ? $3 : "";
1390         my $space = defined ($4) ? $4 : "";
1391         $synop = &MakeReturnField("extern") . "$mod$ptr$space<link linkend=\"$id\">$symbol</link>;\n";
1393     } else {
1394         $synop = &MakeReturnField("extern") . "<link linkend=\"$id\">$symbol</link>;\n";
1395     }
1397     my $desc = "<refsect2 id=\"$id\" role=\"variable\"$condition>\n<title>$symbol</title>\n";
1399     $desc .= MakeIndexterms($symbol, $id);
1401     $declaration = &CreateValidSGML ($declaration);
1402     $desc .= "<programlisting>$declaration</programlisting>\n";
1404     $desc .= &MakeDeprecationNote($symbol);
1406     if (defined ($SymbolDocs{$symbol})) {
1407         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1408     }
1409     $desc .= OutputSymbolTraits ($symbol);
1410     $desc .= "</refsect2>\n";
1411     return ($synop, $desc);
1415 #############################################################################
1416 # Function    : OutputFunction
1417 # Description : Returns the synopsis and detailed description of a function.
1418 # Arguments   : $symbol - the function.
1419 #               $declaration - the declaration of the function.
1420 #############################################################################
1422 sub OutputFunction {
1423     my ($symbol, $declaration, $symbol_type) = @_;
1424     my $id = &CreateValidSGMLID ($symbol);
1425     my $condition = &MakeConditionDescription ($symbol);
1427     # Take out the return type     $1                                                           $3   $4
1428     $declaration =~ s/<RETURNS>\s*((const\s+|G_CONST_RETURN\s+|unsigned\s+|struct\s+|enum\s+)*)(\w+)(\s*\**\s*(const|G_CONST_RETURN)?\s*\**\s*(restrict)?\s*)<\/RETURNS>\n//;
1429     my $type_modifier = defined($1) ? $1 : "";
1430     my $type = $3;
1431     my $pointer = $4;
1432     #print "$symbol pointer is $pointer\n";
1433     my $xref = &MakeXRef ($type);
1434     my $start = "";
1435     #if ($symbol_type eq 'USER_FUNCTION') {
1436     #    $start = "typedef ";
1437     #}
1439     # We output const rather than G_CONST_RETURN.
1440     $type_modifier =~ s/G_CONST_RETURN/const/g;
1441     $pointer =~ s/G_CONST_RETURN/const/g;
1442     $pointer =~ s/^\s+/ /g;
1444     my $ret_type_len = length ($start) + length ($type_modifier)
1445         + length ($pointer) + length ($type);
1446     my $ret_type_output;
1447     my $symbol_len;
1448     if ($ret_type_len < $RETURN_TYPE_FIELD_WIDTH) {
1449         $ret_type_output = "$start$type_modifier$xref$pointer"
1450             . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
1451         $symbol_len = 0;
1452     } else {
1453 #       $ret_type_output = "$start$type_modifier$xref$pointer\n"
1454 #           . (' ' x $RETURN_TYPE_FIELD_WIDTH);
1456         $ret_type_output = "$start$type_modifier$xref$pointer ";
1457         $symbol_len = $ret_type_len + 1 - $RETURN_TYPE_FIELD_WIDTH;
1458     }
1460     $symbol_len += length ($symbol);
1461     my $char1 = my $char2 = my $char3 = "";
1462     if ($symbol_type eq 'USER_FUNCTION') {
1463         $symbol_len += 3;
1464         $char1 = "(";
1465         $char2 = "*";
1466         $char3 = ")";
1467     }
1469     my ($symbol_output, $symbol_desc_output);
1470     if ($symbol_len < $SYMBOL_FIELD_WIDTH) {
1471         $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3"
1472             . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1473         $symbol_desc_output = "$char1$char2$symbol$char3"
1474             . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1475     } else {
1476         $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3\n"
1477             . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1478         $symbol_desc_output = "$char1$char2$symbol$char3\n"
1479             . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1480     }
1482     my $synop = $ret_type_output . $symbol_output . '(';
1483     my $desc = "<refsect2 id=\"$id\" role=\"function\"$condition>\n<title>${symbol} ()</title>\n";
1485     $desc .= MakeIndexterms($symbol, $id);
1487     $desc  .= "<programlisting>${ret_type_output}$symbol_desc_output(";
1489     my $param_num = 0;
1490     while ($declaration ne "") {
1491         #print "$declaration";
1493         if ($declaration =~ s/^[\s,]+//) {
1494             # skip whitespace and commas
1495             next;
1497         } elsif ($declaration =~ s/^void\s*[,\n]//) {
1498             $synop .= "void";
1499             $desc  .= "void";
1501         } elsif ($declaration =~ s/^...\s*[,\n]//) {
1502             if ($param_num == 0) {
1503                 $synop .= "...";
1504                 $desc  .= "...";
1505             } else {
1506                 $synop .= ",\n"
1507                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1508                     . " ...";
1509                 $desc  .= ",\n"
1510                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1511                     . " ...";
1512             }
1514         # allow alphanumerics, '_', '[' & ']' in param names
1515         # Try to match a standard parameter (keep in sync with gtkdoc-mktmpl)
1516         #                                $1                                                                                                                                    $2                             $3                                                           $4       $5
1517         } elsif ($declaration =~ s/^\s*((?:G_CONST_RETURN|G_GNUC_UNUSED|unsigned long|unsigned short|signed long|signed short|unsigned|signed|long|short|volatile|const)\s+)*((?:struct\b|enum\b)?\s*\w+)\s*((?:(?:const\b|restrict\b)?\s*\*?\s*(?:const\b|restrict\b)?\s*)*)(\w+)?\s*((?:\[\S*\])*)\s*[,\n]//) {
1518             my $pre     = defined($1) ? $1 : "";
1519             my $type    = $2;
1520             my $ptr     = defined($3) ? $3 : "";
1521             my $name    = defined($4) ? $4 : "";
1522             my $array   = defined($5) ? $5 : "";
1524             $pre  =~ s/\s+/ /g;
1525             $type =~ s/\s+/ /g;
1526             $ptr  =~ s/\s+/ /g;
1527             $ptr  =~ s/\s+$//;
1528             if ($ptr && $ptr !~ m/\*$/) { $ptr .= " "; }
1530             #print "$symbol: '$pre' '$type' '$ptr' '$name' '$array'\n";
1532             if (($name eq "") && $pre =~ m/^((un)?signed .*)\s?/ ) {
1533                 $name = $type;
1534                 $type = "$1";
1535                 $pre = "";
1536             }
1538             my $xref = &MakeXRef ($type);
1539             my $label   = "$pre$xref $ptr$name$array";
1541             #print "$symbol: '$pre' '$type' '$ptr' '$name' '$array'\n";
1543             if ($param_num == 0) {
1544                 $synop .= "$label";
1545                 $desc  .= "$label";
1546             } else {
1547                 $synop .= ",\n"
1548                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1549                     . " $label";
1550                 $desc  .= ",\n"
1551                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1552                     . " $label";
1553             }
1555         # Try to match parameters which are functions (keep in sync with gtkdoc-mktmpl)
1556         #                              $1                                       $2          $3      $4                        $5                    $7             $8
1557         } elsif ($declaration =~ s/^(const\s+|G_CONST_RETURN\s+|unsigned\s+)*(struct\s+)?(\w+)\s*(\**)\s*(?:restrict\b)?\s*(const\s+)?\(\s*\*+\s*(\w+)\s*\)\s*\(([^)]*)\)\s*[,\n]//) {
1558             my $mod1 = defined($1) ? $1 : "";
1559             if (defined($2)) { $mod1 .= $2; }
1560             my $type = $3;
1561             my $ptr1 = $4;
1562             my $mod2 = defined($5) ? $5 : "";
1563             my $func_ptr = $6;
1564             my $name = $7;
1565             my $func_params = defined($8) ? $8 : "";
1566             
1567             #if (!defined($type)) { print "## no type\n"; };
1568             #if (!defined($ptr1)) { print "## no ptr1\n"; };
1569             #if (!defined($func_ptr)) { print "## no func_ptr\n"; };
1570             #if (!defined($name)) { print "## no name\n"; };
1572             if ($ptr1 && $ptr1 !~ m/\*$/) { $ptr1 .= " "; }
1573             $func_ptr  =~ s/\s+//g;
1574             my $xref = &MakeXRef ($type);
1575             my $label = "$mod1$xref$ptr1$mod2 ($func_ptr$name) ($func_params)";
1577             #print "Type: [$mod1][$xref][$ptr1][$mod2] ([$func_ptr][$name]) ($func_params)\n";
1578             if ($param_num == 0) {
1579                 $synop .= "$label";
1580                 $desc  .= "$label";
1581             } else {
1582                 $synop .= ",\n"
1583                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1584                     . " $label";
1585                 $desc  .= ",\n"
1586                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1587                     . " $label";
1588             }
1590         } else {
1591             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1592                 "Can't parse args for function $symbol: $declaration");
1593             last;
1594         }
1595         $param_num++;
1596     }
1597     $synop .= ");\n";
1598     $desc  .= ");</programlisting>\n";
1600     $desc .= &MakeDeprecationNote($symbol);
1602     my $parameters = &OutputParamDescriptions ("FUNCTION", $symbol);
1603     my $parameters_output = 0;
1605     if (defined ($SymbolDocs{$symbol})) {
1606         my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1608         # Try to insert the parameter table at the author's desired position.
1609         # Otherwise we need to tag it onto the end.
1610         if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1611           $parameters_output = 1;
1612         }
1613         $desc .= $symbol_docs;
1614     }
1616     if ($parameters_output == 0) {
1617         $desc .= $parameters;
1618     }
1620     $desc .= OutputSymbolTraits ($symbol);
1621     $desc .= "</refsect2>\n";
1622     return ($synop, $desc);
1626 #############################################################################
1627 # Function    : OutputParamDescriptions
1628 # Description : Returns the DocBook output describing the parameters of a
1629 #               function, macro or signal handler.
1630 # Arguments   : $symbol_type - 'FUNCTION', 'MACRO' or 'SIGNAL'. Signal
1631 #                 handlers have an implicit user_data parameter last.
1632 #               $symbol - the name of the function/macro being described.
1633 #############################################################################
1635 sub OutputParamDescriptions {
1636     my ($symbol_type, $symbol) = @_;
1637     my $output = "";
1638     if (defined ($SymbolParams{$symbol})) {
1639         my $returns = "";
1640         my $params = $SymbolParams{$symbol};
1641         my $params_desc = "";
1642         my $j;
1643         for ($j = 0; $j <= $#$params; $j += 2) {
1644             my $param_name = $$params[$j];
1645             my $param = $$params[$j + 1];
1646             if ($param_name eq "Returns") {
1647                 $returns = &ExpandAbbreviations($symbol, $param);
1648             } else {
1649                 if ($param_name eq "Varargs") {
1650                     $param_name = "...";
1651                 }
1652                 $param = &ExpandAbbreviations($symbol, $param);
1653                 $params_desc .= "<varlistentry><term><parameter>$param_name</parameter>&#160;:</term>\n<listitem><simpara>$param</simpara></listitem></varlistentry>\n";
1654             }
1655         }
1657         # Signals have an implicit user_data parameter which we describe.
1658         if ($symbol_type eq "SIGNAL") {
1659             $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";
1660         }
1662         # Start a table if we need one.
1663         if ($params_desc || $returns) {
1664             $output .= <<EOF;
1665 <variablelist role="params">
1668             if ($params_desc ne "") {
1669 #               $output .= "<varlistentry><term>Parameters:</term><listitem></listitem></varlistentry>\n";
1670                 $output .= $params_desc;
1671             }
1673             # Output the returns info last.
1674             if ($returns) {
1675                 $output .= "<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara>$returns</simpara></listitem></varlistentry>\n";
1676             }
1678             # Finish the table.
1679             $output .= "</variablelist>";
1680         }
1681     }
1682     return $output;
1686 #############################################################################
1687 # Function    : ParseStabilityLevel
1688 # Description : Parses a stability level and outputs a warning if it isn't
1689 #               valid.
1690 # Arguments   : $stability - the stability text.
1691 #               $file, $line - context for error message
1692 #               $message - description of where the level is from, to use in
1693 #               any error message.
1694 # Returns     : The parsed stability level string.
1695 #############################################################################
1697 sub ParseStabilityLevel {
1698     my ($stability, $file, $line, $message) = @_;
1700     $stability =~ s/^\s*//;
1701     $stability =~ s/\s*$//;
1702     if ($stability =~ m/^stable$/i) {
1703         $stability = "Stable";
1704     } elsif ($stability =~ m/^unstable$/i) {
1705         $stability = "Unstable";
1706     } elsif ($stability =~ m/^private$/i) {
1707         $stability = "Private";
1708     } else {
1709         &LogWarning ($file, $line, "$message is $stability.".
1710             "It should be one of these: Stable, Unstable, or Private.");
1711     }
1712     return $stability;
1716 #############################################################################
1717 # Function    : OutputSGMLFile
1718 # Description : Outputs the final DocBook file for one section.
1719 # Arguments   : $file - the name of the file.
1720 #               $title - the title from the $MODULE-sections.txt file, which
1721 #                 will be overridden by the title in the template file.
1722 #               $section_id - the SGML id to use for the toplevel tag.
1723 #               $includes - comma-separates list of include files added at top
1724 #                 of synopsis, with '<' '>' around them (if not already enclosed in "").
1725 #               $synopsis - reference to the DocBook for the Synopsis part.
1726 #               $details - reference to the DocBook for the Details part.
1727 #               $signal_synop - reference to the DocBook for the Signal Synopsis part
1728 #               $signal_desc - reference to the DocBook for the Signal Description part
1729 #               $args_synop - reference to the DocBook for the Arg Synopsis part
1730 #               $args_desc - reference to the DocBook for the Arg Description part
1731 #               $hierarchy - reference to the DocBook for the Object Hierarchy part
1732 #               $interfaces - reference to the DocBook for the Interfaces part
1733 #               $implementations - reference to the DocBook for the Known Implementations part
1734 #               $prerequisites - reference to the DocBook for the Prerequisites part
1735 #               $derived - reference to the DocBook for the Derived Interfaces part
1736 #               $file_objects - reference to an array of objects in this file
1737 #############################################################################
1739 sub OutputSGMLFile {
1740     my ($file, $title, $section_id, $includes, $synopsis, $details, $signals_synop, $signals_desc, $args_synop, $args_desc, $hierarchy, $interfaces, $implementations, $prerequisites, $derived, $file_objects) = @_;
1742     #print "Output sgml for file $file with title '$title'\n";
1743     
1744     # The edited title overrides the one from the sections file.
1745     my $new_title = $SymbolDocs{"$TMPL_DIR/$file:Title"};
1746     if (defined ($new_title) && $new_title !~ m/^\s*$/) {
1747         $title = $new_title;
1748         #print "Found title: $title\n";
1749     }
1750     my $short_desc = $SymbolDocs{"$TMPL_DIR/$file:Short_Description"};
1751     if (!defined ($short_desc) || $short_desc =~ m/^\s*$/) {
1752         $short_desc = "";
1753     } else {
1754         $short_desc = &ExpandAbbreviations("$title:Short_description",
1755                                            $short_desc);
1756         #print "Found short_desc: $short_desc";
1757     }
1758     my $long_desc = $SymbolDocs{"$TMPL_DIR/$file:Long_Description"};
1759     if (!defined ($long_desc) || $long_desc =~ m/^\s*$/) {
1760         $long_desc = "";
1761     } else {
1762         $long_desc = &ExpandAbbreviations("$title:Long_description",
1763                                           $long_desc);
1764         #print "Found long_desc: $long_desc";
1765     }
1766     my $see_also = $SymbolDocs{"$TMPL_DIR/$file:See_Also"};
1767     if (!defined ($see_also) || $see_also =~ m%^\s*(<para>)?\s*(</para>)?\s*$%) {
1768         $see_also = "";
1769     } else {
1770         $see_also = &ExpandAbbreviations("$title:See_Also", $see_also);
1771         #print "Found see_also: $see_also";
1772     }
1773     if ($see_also) {
1774         $see_also = "<refsect1 id=\"$section_id.see-also\">\n<title>See Also</title>\n$see_also\n</refsect1>\n";
1775     }
1776     my $stability = $SymbolDocs{"$TMPL_DIR/$file:Stability_Level"};
1777     if (!defined ($stability) || $stability =~ m/^\s*$/) {
1778         $stability = "";
1779     } else {
1780         $stability = &ParseStabilityLevel($stability, $file, $., "Section stability level");
1781         #print "Found stability: $stability";
1782     }
1783     if ($stability) {
1784         $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$stability, unless otherwise indicated\n</refsect1>\n";
1785     } elsif ($DEFAULT_STABILITY) {
1786         $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$DEFAULT_STABILITY, unless otherwise indicated\n</refsect1>\n";
1787     }
1789     my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
1790         gmtime (time);
1791     my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
1792     $year += 1900;
1794     my $include_output = "";
1795     my $include;
1796     foreach $include (split (/,/, $includes)) {
1797         if ($include =~ m/^\".+\"$/) {
1798             $include_output .= "#include ${include}\n";
1799         }
1800         else {
1801             $include =~ s/^\s+|\s+$//gs;
1802             $include_output .= "#include &lt;${include}&gt;\n";
1803         }
1804     }
1805     if ($include_output ne '') {
1806         $include_output = "\n$include_output\n";
1807     }
1809     my $old_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT";
1810     my $new_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT.new";
1812     open (OUTPUT, ">$new_sgml_file")
1813         || die "Can't create $new_sgml_file: $!";
1815     my $object_anchors = "";
1816     foreach my $object (@$file_objects) {
1817         next if ($object eq $section_id);
1818         my $id = CreateValidSGMLID($object);
1819         #print "Debug: Adding anchor for $object\n";
1820         $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
1821     }
1823     # We used to output this, but is messes up our UpdateFileIfChanged code
1824     # since it changes every day (and it is only used in the man pages):
1825     # "<refentry id="$section_id" revision="$mday $month $year">"
1827     if (lc($OUTPUT_FORMAT) eq "xml") {
1828         print OUTPUT $doctype_header;
1829     }
1831     print OUTPUT <<EOF;
1832 <refentry id="$section_id">
1833 <refmeta>
1834 <refentrytitle role="top_of_page" id="$section_id.top_of_page">$title</refentrytitle>
1835 <manvolnum>3</manvolnum>
1836 <refmiscinfo>\U$MODULE\E Library</refmiscinfo>
1837 </refmeta>
1839 <refnamediv>
1840 <refname>$title</refname>
1841 <refpurpose>$short_desc</refpurpose>
1842 </refnamediv>
1843 $stability
1844 <refsynopsisdiv id="$section_id.synopsis" role="synopsis">
1845 <title role="synopsis.title">Synopsis</title>
1846 $object_anchors
1847 <synopsis>
1848 $include_output$${synopsis}</synopsis>
1849 </refsynopsisdiv>
1851 $$hierarchy
1852 $$prerequisites
1853 $$derived
1854 $$interfaces
1855 $$implementations
1856 $$args_synop
1857 $$signals_synop
1859 <refsect1 id="$section_id.description" role="desc">
1860 <title role="desc.title">Description</title>
1861 $long_desc
1862 </refsect1>
1864 <refsect1 id="$section_id.details" role="details">
1865 <title role="details.title">Details</title>
1866 $$details
1867 </refsect1>
1868 $$args_desc
1869 $$signals_desc
1871 $see_also
1872 </refentry>
1874     close (OUTPUT);
1876     return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
1880 #############################################################################
1881 # Function    : OutputExtraFile
1882 # Description : Copies an "extra" DocBook file into the output directory,
1883 #               expanding abbreviations
1884 # Arguments   : $file - the source file.
1885 #############################################################################
1886 sub OutputExtraFile {
1887     my ($file) = @_;
1889     my $basename;
1891     ($basename = $file) =~ s!^.*/!!;
1893     my $old_sgml_file = "$SGML_OUTPUT_DIR/$basename";
1894     my $new_sgml_file = "$SGML_OUTPUT_DIR/$basename.new";
1896     my $contents;
1898     open(EXTRA_FILE, "<$file") || die "Can't open $file";
1900     {
1901         local $/;
1902         $contents = <EXTRA_FILE>;
1903     }
1905     open (OUTPUT, ">$new_sgml_file")
1906         || die "Can't create $new_sgml_file: $!";
1908     print OUTPUT &ExpandAbbreviations ("$basename file", $contents);
1909     close (OUTPUT);
1911     return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
1913 #############################################################################
1914 # Function    : OutputBook
1915 # Description : Outputs the SGML entities that need to be included into the
1916 #               main SGML file for the module.
1917 # Arguments   : $book_top - the declarations of the entities, which are added
1918 #                 at the top of the main SGML file.
1919 #               $book_bottom - the references to the entities, which are
1920 #                 added in the main SGML file at the desired position.
1921 #############################################################################
1923 sub OutputBook {
1924     my ($book_top, $book_bottom) = @_;
1926     my $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top";
1927     my $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top.new";
1929     open (OUTPUT, ">$new_file")
1930         || die "Can't create $new_file: $!";
1931     print OUTPUT $book_top;
1932     close (OUTPUT);
1934     &UpdateFileIfChanged ($old_file, $new_file, 0);
1937     $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom";
1938     $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom.new";
1940     open (OUTPUT, ">$new_file")
1941         || die "Can't create $new_file: $!";
1942     print OUTPUT $book_bottom;
1943     close (OUTPUT);
1945     &UpdateFileIfChanged ($old_file, $new_file, 0);
1948     # If the main SGML file hasn't been created yet, we create it here.
1949     # The user can tweak it later.
1950     if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
1951       open (OUTPUT, ">$MAIN_SGML_FILE")
1952         || die "Can't create $MAIN_SGML_FILE: $!";
1954       if (lc($OUTPUT_FORMAT) eq "xml") {
1955           print OUTPUT <<EOF;
1956 <?xml version="1.0"?>
1957 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
1958                "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
1960   <!ENTITY % local.common.attrib "xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'">
1962 <book id="index">
1964       } else {
1965         print OUTPUT <<EOF;
1966 <!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
1968         print OUTPUT $book_top;
1969         print OUTPUT <<EOF;
1971 <book id="index">
1973       }
1975 print OUTPUT <<EOF;
1976   <bookinfo>
1977     <title>$MODULE Reference Manual</title>
1978     <releaseinfo>
1979       for $MODULE [VERSION]
1980       The latest version of this documentation can be found on-line at
1981       <ulink role="online-location" url="http://[SERVER]/$MODULE/index.html">http://[SERVER]/$MODULE/</ulink>.
1982     </releaseinfo>
1983   </bookinfo>
1985   <chapter>
1986     <title>[Insert title here]</title>
1988       print OUTPUT $book_bottom;
1990       print OUTPUT <<EOF;
1991   </chapter>
1992 </book>
1995       close (OUTPUT);
1996     }
2000 #############################################################################
2001 # Function    : CreateValidSGMLID
2002 # Description : Creates a valid SGML 'id' from the given string.
2003 #               NOTE: SGML ids are case-insensitive, so we have a few special
2004 #                     cases to avoid clashes of ids.
2005 # Arguments   : $id - the string to be converted into a valid SGML id.
2006 #############################################################################
2008 sub CreateValidSGMLID {
2009     my ($id) = $_[0];
2011     # Append ":CAPS" to all all-caps identifiers
2013     # Special case, '_' would end up as '' so we use 'gettext-macro' instead.
2014     if ($id eq "_") { return "gettext-macro"; }
2016     if ($id !~ /[a-z]/) { $id .= ":CAPS" };
2018     $id =~ s/[_ ]/-/g;
2019     $id =~ s/[,\.]//g;
2020     $id =~ s/^-*//;
2021     $id =~ s/::/-/g;
2022     $id =~ s/:/--/g;
2024     return $id;
2028 #############################################################################
2029 # Function    : CreateValidSGML
2030 # Description : This turns any chars which are used in SGML into entities,
2031 #               e.g. '<' into '&lt;'
2032 # Arguments   : $text - the text to turn into proper SGML.
2033 #############################################################################
2035 sub CreateValidSGML {
2036     my ($text) = @_;
2037     $text =~ s/&/&amp;/g;       # Do this first, or the others get messed up.
2038     $text =~ s/</&lt;/g;
2039     $text =~ s/>/&gt;/g;
2040     return $text;
2043 #############################################################################
2044 # Function    : ConvertSGMLChars
2045 # Description : This is used for text in source code comment blocks, to turn
2046 #               chars which are used in SGML into entities, e.g. '<' into
2047 #               '&lt;'. Depending on $SGML_MODE, this is done
2048 #               unconditionally or only if the character doesn't seem to be
2049 #               part of an SGML construct (tag or entity reference).
2050 # Arguments   : $text - the text to turn into proper SGML.
2051 #############################################################################
2053 sub ConvertSGMLChars {
2054     my ($symbol, $text) = @_;
2056     if ($SGML_MODE) {
2057         # For the SGML mode only convert to entities outside CDATA sections.
2058         return &ModifyXMLElements ($text, $symbol,
2059                                    "<!\\[CDATA\\[|<programlisting[^>]*>",
2060                                    \&ConvertSGMLCharsEndTag,
2061                                    \&ConvertSGMLCharsCallback);
2062     } else {
2063         # For the simple non-sgml mode, convert to entities everywhere.
2064         $text =~ s/&/&amp;/g;   # Do this first, or the others get messed up.
2065         $text =~ s/</&lt;/g;
2066         $text =~ s/>/&gt;/g;
2067         return $text;
2068     }
2072 sub ConvertSGMLCharsEndTag {
2073   if ($_[0] eq "<!\[CDATA\[") {
2074     return "]]>";
2075   } else {
2076     return "</programlisting>";
2077   }
2080 sub ConvertSGMLCharsCallback {
2081   my ($text, $symbol, $tag) = @_;
2083   if ($tag =~ m/^<programlisting/) {
2084     # We can handle <programlisting> specially here.
2085     return &ModifyXMLElements ($text, $symbol,
2086                                "<!\\[CDATA\\[",
2087                                \&ConvertSGMLCharsEndTag,
2088                                \&ConvertSGMLCharsCallback2);
2089   } elsif ($tag eq "") {
2090     # If we're not in CDATA convert to entities.
2091     $text =~ s/&(?![a-zA-Z#]+;)/&amp;/g;        # Do this first, or the others get messed up.
2092     $text =~ s/<(?![a-zA-Z\/!])/&lt;/g;
2093     $text =~ s/(?<![a-zA-Z0-9"'\/-])>/&gt;/g;
2095     # Handle "#include <xxxxx>"
2096     $text =~ s/#include(\s+)<([^>]+)>/#include$1&lt;$2&gt;/g;
2097   }
2099   return $text;
2102 sub ConvertSGMLCharsCallback2 {
2103   my ($text, $symbol, $tag) = @_;
2105   # If we're not in CDATA convert to entities.
2106   # We could handle <programlisting> differently, though I'm not sure it helps.
2107   if ($tag eq "") {
2108     # replace only if its not a tag
2109     $text =~ s/&(?![a-zA-Z#]+;)/&amp;/g;        # Do this first, or the others get messed up.
2110     $text =~ s/<(?![a-zA-Z\/!])/&lt;/g;
2111     $text =~ s/(?<![a-zA-Z0-9"'\/-])>/&gt;/g;
2113     # Handle "#include <xxxxx>"
2114     $text =~ s/#include(\s+)<([^>]+)>/#include$1&lt;$2&gt;/g;
2115   }
2117   return $text;
2121 #############################################################################
2122 # Function    : ExpandAbbreviations
2123 # Description : This turns the abbreviations function(), macro(), @param,
2124 #               %constant, and #symbol into appropriate DocBook markup.
2125 #               CDATA sections and <programlisting> parts are skipped.
2126 # Arguments   : $symbol - the symbol being documented, for error messages.
2127 #               $text - the text to expand.
2128 #############################################################################
2130 sub ExpandAbbreviations {
2131   my ($symbol, $text) = @_;
2133   # Convert "|[" and "]|" into the start and end of program listing examples.
2134   $text =~ s%\|\[%<informalexample><programlisting>%g;
2135   $text =~ s%\]\|%</programlisting></informalexample>%g;
2137   # keep CDATA unmodified, preserve ulink tags (ideally we preseve all tags
2138   # as such)
2139   return &ModifyXMLElements ($text, $symbol,
2140                              "<!\\[CDATA\\[|<ulink[^>]*>|<programlisting[^>]*>",
2141                              \&ExpandAbbreviationsEndTag,
2142                              \&ExpandAbbreviationsCallback);
2146 # Returns the end tag corresponding to the given start tag.
2147 sub ExpandAbbreviationsEndTag {
2148   my ($start_tag) = @_;
2150   if ($start_tag eq "<!\[CDATA\[") {
2151     return "]]>";
2152   } elsif ($start_tag =~ m/<(\w+)/) {
2153     return "</$1>";
2154   }
2157 # Called inside or outside each CDATA or <programlisting> section.
2158 sub ExpandAbbreviationsCallback {
2159   my ($text, $symbol, $tag) = @_;
2161   if ($tag =~ m/^<programlisting/) {
2162     # Handle any embedded CDATA sections.
2163     return &ModifyXMLElements ($text, $symbol,
2164                                "<!\\[CDATA\\[",
2165                                \&ExpandAbbreviationsEndTag,
2166                                \&ExpandAbbreviationsCallback2);
2167   } elsif ($tag eq "") {
2168     # We are outside any CDATA or <programlisting> sections, so we expand
2169     # any gtk-doc abbreviations.
2171     # Convert 'function()' or 'macro()'.
2172     $text =~ s/(\w+)\s*\(\)/&MakeXRef($1, &tagify($1 . "()", "function"));/eg;
2174     # Convert '@param', but not '\@param'.
2175     #$text =~ s/\@(\w+((\.|->)\w+)*)/<parameter>$1<\/parameter>/g;
2176     $text =~ s/([^\\])\@(\w+((\.|->)\w+)*)/$1<parameter>$2<\/parameter>/g;
2177     $text =~ s/\\\@/\@/g;
2179     # Convert '%constant', but not '\%constant'.
2180     # Also allow negative numbers, e.g. %-1.
2181     #$text =~ s/\%(-?\w+)/&MakeXRef($1, &tagify($1, "literal"));/eg;
2182     $text =~ s/([^\\])\%(-?\w+)/$1.&MakeXRef($2, &tagify($2, "literal"));/eg;
2183     $text =~ s/\\\%/\%/g;
2185     # Convert '#symbol', but not '\#symbol'.
2186     #$text =~ s/#([\w\-:]+)/&MakeHashXRef($1, "type");/eg;
2187     $text =~ s/([^\\])#([\w\-:]+)/$1.&MakeHashXRef($2, "type");/eg;
2188     $text =~ s/\\#/#/g;
2189   }
2191   return $text;
2194 # This is called inside a <programlisting>
2195 sub ExpandAbbreviationsCallback2 {
2196   my ($text, $symbol, $tag) = @_;
2198   if ($tag eq "") {
2199     # We are inside a <programlisting> but outside any CDATA sections,
2200     # so we expand any gtk-doc abbreviations.
2201     # FIXME: why is this different from &ExpandAbbreviationsCallback(),
2202     #        why not just call it
2203     $text =~ s/#(\w+)/&MakeHashXRef($1, "");/eg;
2204   }
2206   return $text;
2209 sub MakeHashXRef {
2210     my ($symbol, $tag) = @_;;
2211     my $text = $symbol;
2213     # Check for things like '#include', '#define', and skip them.
2214     if ($PreProcessorDirectives{$symbol}) {
2215       return "#$symbol";
2216     }
2218     # Get rid of any special '-struct' suffix.
2219     $text =~ s/-struct$//;
2221     # If the symbol is in the form "Object::signal", then change the symbol to
2222     # "Object-signal" and use "signal" as the text.
2223     if ($symbol =~ s/::/-/) {
2224       $text = "\"$'\"";
2225     }
2227     # If the symbol is in the form "Object:property", then change the symbol to
2228     # "Object--property" and use "property" as the text.
2229     if ($symbol =~ s/:/--/) {
2230       $text = "\"$'\"";
2231     }
2233     if ($tag ne "") {
2234       $text = tagify ($text, $tag);
2235     }
2237     return &MakeXRef($symbol, $text);
2241 #############################################################################
2242 # Function    : ModifyXMLElements
2243 # Description : Looks for given XML element tags within the text, and calls
2244 #               the callback on pieces of text inside & outside those elements.
2245 #               Used for special handling of text inside things like CDATA
2246 #               and <programlisting>.
2247 # Arguments   : $text - the text.
2248 #               $symbol - the symbol currently being documented (only used for
2249 #                      error messages).
2250 #               $start_tag_regexp - the regular expression to match start tags.
2251 #                      e.g. "<!\\[CDATA\\[|<programlisting[^>]*>" to match
2252 #                      CDATA sections or programlisting elements.
2253 #               $end_tag_func - function which is passed the matched start tag
2254 #                      and should return the appropriate end tag string.
2255 #               $callback - callback called with each part of the text. It is
2256 #                      called with a piece of text, the symbol being
2257 #                      documented, and the matched start tag or "" if the text
2258 #                      is outside the XML elements being matched.
2259 #############################################################################
2260 sub ModifyXMLElements {
2261     my ($text, $symbol, $start_tag_regexp, $end_tag_func, $callback) = @_;
2262     my ($before_tag, $start_tag, $end_tag_regexp, $end_tag);
2263     my $result = "";
2265     while ($text =~ m/$start_tag_regexp/s) {
2266       $before_tag = $`; # Prematch for last successful match string
2267       $start_tag = $&;  # Last successful match
2268       $text = $';       # Postmatch for last successful match string
2270       $result .= &$callback ($before_tag, $symbol, "");
2271       $result .= $start_tag;
2273       # get the mathing end-tag for current tag
2274       $end_tag_regexp = &$end_tag_func ($start_tag);
2276       if ($text =~ m/$end_tag_regexp/s) {
2277         $before_tag = $`;
2278         $end_tag = $&;
2279         $text = $';
2281         $result .= &$callback ($before_tag, $symbol, $start_tag);
2282         $result .= $end_tag;
2283       } else {
2284         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2285             "Can't find tag end: $end_tag_regexp in docs for: $symbol.");
2286         # Just assume it is all inside the tag.
2287         $result .= &$callback ($text, $symbol, $start_tag);
2288         $text = "";
2289       }
2290     }
2292     # Handle any remaining text outside the tags.
2293     $result .= &$callback ($text, $symbol, "");
2295     return $result;
2298 sub noop {
2299   return $_[0];
2302 # Adds a tag around some text.
2303 # e.g tagify("Text", "literal") => "<literal>Text</literal>".
2304 sub tagify {
2305    my ($text, $elem) = @_;
2306    return "<" . $elem . ">" . $text . "</" . $elem . ">";
2310 #############################################################################
2311 # Function    : MakeXRef
2312 # Description : This returns a cross-reference link to the given symbol.
2313 #               Though it doesn't try to do this for a few standard C types
2314 #               that it knows won't be in the documentation.
2315 # Arguments   : $symbol - the symbol to try to create a XRef to.
2316 #               $text - text text to put inside the XRef, defaults to $symbol
2317 #############################################################################
2319 sub MakeXRef {
2320     my ($symbol, $text) = ($_[0], $_[1]);
2321     if (!defined($text)) {
2322         $text = $symbol;
2324         # Get rid of special '-struct' suffix.
2325         $text =~ s/-struct$//;
2326     }
2328     #print "Getting type link for $symbol -> $text\n";
2330     my $symbol_id = &CreateValidSGMLID ($symbol);
2331     return "<link linkend=\"$symbol_id\">$text</link>";
2335 #############################################################################
2336 # Function    : MakeIndexterms
2337 # Description : This returns a indexterm elements for the given symbol
2338 # Arguments   : $symbol - the symbol to create indexterms for
2339 #############################################################################
2341 sub MakeIndexterms {
2342   my ($symbol, $id) = @_;
2343   my $terms =  "";
2344   my $sortas = "";
2345   
2346   # make the index useful, by ommiting the namespace when sorting
2347   if (defined($NAME_SPACE)) {
2348     if ($symbol =~ m/^$NAME_SPACE\_?(.*)/i) {
2349        $sortas=" sortas=\"$1\"";
2350     }
2351   }
2353   if (exists $Deprecated{$symbol}) {
2354       $terms .= "<indexterm zone=\"$id\" role=\"deprecated\"><primary$sortas>$symbol</primary></indexterm>";
2355       $IndexEntriesDeprecated{$symbol}=$id;
2356       $IndexEntriesFull{$symbol}=$id;
2357   }
2358   if (exists $Since{$symbol}) {
2359      my $since = $Since{$symbol};
2360      $since =~ s/^\s+//;
2361      $since =~ s/\s+$//;
2362      if ($since ne "") {
2363          $terms .= "<indexterm zone=\"$id\" role=\"$since\"><primary$sortas>$symbol</primary></indexterm>";
2364      }
2365      $IndexEntriesSince{$symbol}=$id;
2366      $IndexEntriesFull{$symbol}=$id;
2367   }
2368   if ($terms eq "") {
2369      $terms .= "<indexterm zone=\"$id\"><primary$sortas>$symbol</primary></indexterm>";
2370      $IndexEntriesFull{$symbol}=$id;
2371   }
2373   return $terms;
2376 #############################################################################
2377 # Function    : MakeDeprecationNote
2378 # Description : This returns a deprecation warning for the given symbol.
2379 # Arguments   : $symbol - the symbol to try to create a warning for.
2380 #############################################################################
2382 sub MakeDeprecationNote {
2383     my ($symbol) = $_[0];
2384     my $desc = "";
2385     my $note = "";
2386     if (exists $Deprecated{$symbol}) {
2387         $desc .= "<warning>";
2389         if ($Deprecated{$symbol} =~ /^\s*([0-9\.]+)\s*:/) {
2390                 $desc .= "<para><literal>$symbol</literal> has been deprecated since version $1 and should not be used in newly-written code.";
2391         } else {
2392                 $desc .= "<para><literal>$symbol</literal> is deprecated and should not be used in newly-written code.";
2393         }
2394         if ($Deprecated{$symbol} ne "") {
2395             $note = &ExpandAbbreviations($symbol, $Deprecated{$symbol});
2396             $note =~ s/^\s*([0-9\.]+)\s*:\s*//;
2397             $note =~ s/^\s+//;
2398             $note =~ s/\s+$//;
2399             $note =~ s%\n{2,}%\n</para>\n<para>\n%g;
2400             $desc .= " " . $note;
2401         }
2402         $desc .= "</para></warning>\n";
2403     }
2404     return $desc;
2407 #############################################################################
2408 # Function    : MakeConditionDescription
2409 # Description : This returns a sumary of conditions for the given symbol.
2410 # Arguments   : $symbol - the symbol to try to create the sumary.
2411 #############################################################################
2413 sub MakeConditionDescription {
2414     my ($symbol) = $_[0];
2415     my $desc = "";
2417     if (exists $Deprecated{$symbol}) {
2418         if ($desc ne "") {
2419             $desc .= "|";
2420         }
2422         if ($Deprecated{$symbol} =~ /^\s*(.*?)\s*$/) {
2423                 $desc .= "deprecated:$1";
2424         } else {
2425                 $desc .= "deprecated";
2426         }
2427     }
2429     if (exists $Since{$symbol}) {
2430         if ($desc ne "") {
2431             $desc .= "|";
2432         }
2434         if ($Since{$symbol} =~ /^\s*(.*?)\s*$/) {
2435                 $desc .= "since:$1";
2436         } else {
2437                 $desc .= "since";
2438         }
2439     }
2441     if (exists $StabilityLevel{$symbol}) {
2442         if ($desc ne "") {
2443             $desc .= "|";
2444         }
2445         $desc .= "stability:".$StabilityLevel{$symbol};
2446     }
2448     if ($desc ne "") {
2449         $desc=" condition=\"".$desc."\"";
2450         #print "condition for '$symbol' = '$desc'\n";
2451     }
2452     return $desc;
2455 #############################################################################
2456 # Function    : GetHierarchy
2457 # Description : Returns the DocBook output describing the ancestors and
2458 #               immediate children of a GObject subclass. It uses the
2459 #               global @Objects and @ObjectLevels arrays to walk the tree.
2460 # Arguments   : $object - the GtkObject subclass.
2461 #############################################################################
2463 sub GetHierarchy {
2464     my ($object) = @_;
2466     # Find object in the objects array.
2467     my $found = 0;
2468     my @children = ();
2469     my $i;
2470     my $level;
2471     my $j;
2472     for ($i = 0; $i < @Objects; $i++) {
2473         if ($found) {
2474             if ($ObjectLevels[$i] <= $level) {
2475             last;
2476         }
2477             elsif ($ObjectLevels[$i] == $level + 1) {
2478                 push (@children, $Objects[$i]);
2479             }
2480         }
2481         elsif ($Objects[$i] eq $object) {
2482             $found = 1;
2483             $j = $i;
2484             $level = $ObjectLevels[$i];
2485         }
2486     }
2487     if (!$found) {
2488         return "";
2489     }
2491     # Walk up the hierarchy, pushing ancestors onto the ancestors array.
2492     my @ancestors = ();
2493     push (@ancestors, $object);
2494     #print "Level: $level\n";
2495     while ($level > 1) {
2496         $j--;
2497         if ($ObjectLevels[$j] < $level) {
2498             push (@ancestors, $Objects[$j]);
2499             $level = $ObjectLevels[$j];
2500             #print "Level: $level\n";
2501         }
2502     }
2504     # Output the ancestors list, indented and with links.
2505     my $hierarchy = "<synopsis>\n";
2506     $level = 0;
2507     for ($i = $#ancestors; $i >= 0; $i--) {
2508         my $link_text;
2509         # Don't add a link to the current widget, i.e. when i == 0.
2510         if ($i > 0) {
2511             my $ancestor_id = &CreateValidSGMLID ($ancestors[$i]);
2512             $link_text = "<link linkend=\"$ancestor_id\">$ancestors[$i]</link>";
2513         } else {
2514             $link_text = "$ancestors[$i]";
2515         }
2516         if ($level == 0) {
2517             $hierarchy .= "  $link_text\n";
2518         } else {
2519 #           $hierarchy .= ' ' x ($level * 6 - 3) . "|\n";
2520             $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
2521         }
2522         $level++;
2523     }
2524     for ($i = 0; $i <= $#children; $i++) {
2525       my $id = &CreateValidSGMLID ($children[$i]);
2526       my $link_text = "<link linkend=\"$id\">$children[$i]</link>";
2527       $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
2528     }
2529     $hierarchy .= "</synopsis>\n";
2531     return $hierarchy;
2535 #############################################################################
2536 # Function    : GetInterfaces
2537 # Description : Returns the DocBook output describing the interfaces
2538 #               implemented by a class. It uses the global %Interfaces hash.
2539 # Arguments   : $object - the GtkObject subclass.
2540 #############################################################################
2542 sub GetInterfaces {
2543     my ($object) = @_;
2544     my $text = "";
2545     my $i;
2547     # Find object in the objects array.
2548     if (exists($Interfaces{$object})) {
2549         my @ifaces = split(' ', $Interfaces{$object});
2550         $text = <<EOF;
2551 <para>
2552 $object implements
2554         for ($i = 0; $i <= $#ifaces; $i++) {
2555             my $id = &CreateValidSGMLID ($ifaces[$i]);
2556             $text .= " <link linkend=\"$id\">$ifaces[$i]</link>";
2557             if ($i < $#ifaces - 1) {
2558                 $text .= ', ';
2559             }
2560             elsif ($i < $#ifaces) {
2561                 $text .= ' and ';
2562             }
2563             else {
2564                 $text .= '.';
2565             }
2566         }
2567         $text .= <<EOF;
2568 </para>
2570     }
2572     return $text;
2575 #############################################################################
2576 # Function    : GetImplementations
2577 # Description : Returns the DocBook output describing the implementations
2578 #               of an interface. It uses the global %Interfaces hash.
2579 # Arguments   : $object - the GtkObject subclass.
2580 #############################################################################
2582 sub GetImplementations {
2583     my ($object) = @_;
2584     my @impls = ();
2585     my $text = "";
2586     my $i;
2587     foreach my $key (keys %Interfaces) {
2588         if ($Interfaces{$key} =~ /\b$object\b/) {
2589             push (@impls, $key);
2590         }
2591     }
2592     if ($#impls >= 0) {
2593         $text = <<EOF;
2594 <para>
2595 $object is implemented by
2597         for ($i = 0; $i <= $#impls; $i++) {
2598             my $id = &CreateValidSGMLID ($impls[$i]);
2599             $text .= " <link linkend=\"$id\">$impls[$i]</link>";
2600             if ($i < $#impls - 1) {
2601                 $text .= ', ';
2602             }
2603             elsif ($i < $#impls) {
2604                 $text .= ' and ';
2605             }
2606             else {
2607                 $text .= '.';
2608             }
2609         }
2610         $text .= <<EOF;
2611 </para>
2613     }
2614     return $text;
2618 #############################################################################
2619 # Function    : GetPrerequisites
2620 # Description : Returns the DocBook output describing the prerequisites
2621 #               of an interface. It uses the global %Prerequisites hash.
2622 # Arguments   : $iface - the interface.
2623 #############################################################################
2625 sub GetPrerequisites {
2626     my ($iface) = @_;
2627     my $text = "";
2628     my $i;
2630     if (exists($Prerequisites{$iface})) {
2631         $text = <<EOF;
2632 <para>
2633 $iface requires
2635         my @prereqs = split(' ', $Prerequisites{$iface});
2636         for ($i = 0; $i <= $#prereqs; $i++) {
2637             my $id = &CreateValidSGMLID ($prereqs[$i]);
2638             $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
2639             if ($i < $#prereqs - 1) {
2640                 $text .= ', ';
2641             }
2642             elsif ($i < $#prereqs) {
2643                 $text .= ' and ';
2644             }
2645             else {
2646                 $text .= '.';
2647             }
2648         }
2649         $text .= <<EOF;
2650 </para>
2652     }
2653     return $text;
2656 #############################################################################
2657 # Function    : GetDerived
2658 # Description : Returns the DocBook output describing the derived interfaces
2659 #               of an interface. It uses the global %Prerequisites hash.
2660 # Arguments   : $iface - the interface.
2661 #############################################################################
2663 sub GetDerived {
2664     my ($iface) = @_;
2665     my $text = "";
2666     my $i;
2668     my @derived = ();
2669     foreach my $key (keys %Prerequisites) {
2670         if ($Prerequisites{$key} =~ /\b$iface\b/) {
2671             push (@derived, $key);
2672         }
2673     }
2674     if ($#derived >= 0) {
2675         $text = <<EOF;
2676 <para>
2677 $iface is required by
2679         for ($i = 0; $i <= $#derived; $i++) {
2680             my $id = &CreateValidSGMLID ($derived[$i]);
2681             $text .= " <link linkend=\"$id\">$derived[$i]</link>";
2682             if ($i < $#derived - 1) {
2683                 $text .= ', ';
2684             }
2685             elsif ($i < $#derived) {
2686                 $text .= ' and ';
2687             }
2688             else {
2689                 $text .= '.';
2690             }
2691         }
2692         $text .= <<EOF;
2693 </para>
2695     }
2696     return $text;
2700 #############################################################################
2701 # Function    : GetSignals
2702 # Description : Returns the synopsis and detailed description DocBook output
2703 #               for the signal handlers of a given GtkObject subclass.
2704 # Arguments   : $object - the GtkObject subclass, e.g. 'GtkButton'.
2705 #############################################################################
2707 sub GetSignals {
2708     my ($object) = @_;
2709     my $synop = "";
2710     my $desc = "";
2712     my $i;
2713     for ($i = 0; $i <= $#SignalObjects; $i++) {
2714         if ($SignalObjects[$i] eq $object) {
2715             #print "Found signal: $SignalNames[$i]\n";
2716             my $name = $SignalNames[$i];
2717             my $symbol = "${object}::${name}";
2718             my $id = &CreateValidSGMLID ("$object-$name");
2720             my $pad = ' ' x (46 - length($name));
2721             $synop .= "  &quot;<link linkend=\"$id\">$name</link>&quot;$pad ";
2723             $desc .= "<refsect2 id=\"$id\"><title>The <literal>&quot;$name&quot;</literal> signal</title>\n";
2724             $desc .= MakeIndexterms($symbol, $id);
2725             $desc .= "<programlisting>";
2727             $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
2728             my $type_modifier = defined($1) ? $1 : "";
2729             my $type = $2;
2730             my $pointer = $3;
2731             my $xref = &MakeXRef ($type);
2733             my $ret_type_len = length ($type_modifier) + length ($pointer)
2734                 + length ($type);
2735             my $ret_type_output = "$type_modifier$xref$pointer"
2736                 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
2738             $desc  .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
2740             my $sourceparams = $SourceSymbolParams{$symbol};
2741             my @params = split ("\n", $SignalPrototypes[$i]);
2742             my $j;
2743             my $l;
2744             my $type_len = length("gpointer");
2745             my $name_len = length("user_data");
2746             # do two passes, the first one is to calculate padding
2747             for ($l = 0; $l < 2; $l++) {
2748                 for ($j = 0; $j <= $#params; $j++) {
2749                     # allow alphanumerics, '_', '[' & ']' in param names
2750                     if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
2751                         $type = $1;
2752                         $pointer = $2;
2753                         if (defined($sourceparams)) {
2754                             $name = $$sourceparams[2 * $j];
2755                         }
2756                         else {
2757                             $name = $3;
2758                         }
2759                         if (!defined($name)) {
2760                             $name = "arg$j";
2761                         }
2762                         if ($l == 0) {
2763                             if (length($type) + length($pointer) > $type_len) {
2764                                 $type_len = length($type) + length($pointer);
2765                             }
2766                             if (length($name) > $name_len) {
2767                                 $name_len = length($name);
2768                             }
2769                         }
2770                         else {
2771                             $xref = &MakeXRef ($type);
2772                             $pad = ' ' x ($type_len - length($type) - length($pointer));
2773                             $desc .= "$xref$pad $pointer$name,\n";
2774                             $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
2775                         }
2776                     } else {
2777                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2778                              "Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]");
2779                     }
2780                 }
2781             }
2782             $xref = &MakeXRef ("gpointer");
2783             $pad = ' ' x ($type_len - length("gpointer"));
2784             $desc  .= "$xref$pad user_data)";
2786             my $flags = $SignalFlags[$i];
2787             my $flags_string = "";
2789             if (defined ($flags)) {
2790               if ($flags =~ m/f/) {
2791                 $flags_string = "Run First";
2792               }
2793               elsif ($flags =~ m/l/) {
2794                 $flags_string = "Run Last";
2795               }
2796               elsif ($flags =~ m/c/) {
2797                 $flags_string = "Cleanup";
2798               }
2799               if ($flags =~ m/r/) {
2800                 if ($flags_string) { $flags_string .= " / "; }
2801                 $flags_string .= "No Recursion";
2802               }
2803               if ($flags =~ m/d/) {
2804                 if ($flags_string) { $flags_string .= " / "; }
2805                 $flags_string .= "Has Details";
2806               }
2807               if ($flags =~ m/a/) {
2808                 if ($flags_string) { $flags_string .= " / "; }
2809                 $flags_string .= "Action";
2810               }
2811               if ($flags =~ m/h/) {
2812                 if ($flags_string) { $flags_string .= " / "; }
2813                 $flags_string .= "No Hooks";
2814               }
2815             }
2817             if ($flags_string)
2818               {
2819                 $synop .= ": $flags_string\n";
2821                 $pad = ' ' x (5 + $name_len - length("user_data"));
2822                 $desc  .= "$pad : $flags_string</programlisting>\n";
2823               }
2824             else
2825               {
2826                 $synop .= "\n";
2827                 $desc  .= "</programlisting>\n";
2828               }
2830             my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
2831             my $parameters_output = 0;
2833             $AllSymbols{$symbol} = 1;
2834             if (defined ($SymbolDocs{$symbol})) {
2835                 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
2837                 # Try to insert the parameter table at the author's desired
2838                 # position. Otherwise we need to tag it onto the end.
2839                 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
2840                   $parameters_output = 1;
2841                 }
2842                 $desc .= $symbol_docs;
2844                 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
2845                     $AllDocumentedSymbols{$symbol} = 1;
2846                 }
2847             }
2849             if ($parameters_output == 0) {
2850                 $desc .= $parameters;
2851               }
2853             if (exists $Since{$symbol}) {
2854               $desc .= "<para>Since $Since{$symbol}</para>";
2855             }
2856             if (exists $StabilityLevel{$symbol}) {
2857               $desc .= "<para>Stability Level: $StabilityLevel{$symbol}</para>";
2858             }
2859             $desc .= "</refsect2>";
2860         }
2861     }
2862     return ($synop, $desc);
2866 #############################################################################
2867 # Function    : GetArgs
2868 # Description : Returns the synopsis and detailed description DocBook output
2869 #               for the Args of a given GtkObject subclass.
2870 # Arguments   : $object - the GtkObject subclass, e.g. 'GtkButton'.
2871 #############################################################################
2873 sub GetArgs {
2874     my ($object) = @_;
2875     my $synop = "";
2876     my $desc = "";
2877     my $child_synop = "";
2878     my $child_desc = "";
2879     my $style_synop = "";
2880     my $style_desc = "";
2882     my $i;
2883     for ($i = 0; $i <= $#ArgObjects; $i++) {
2884         if ($ArgObjects[$i] eq $object) {
2885             #print "Found arg: $ArgNames[$i]\n";
2886             my $name = $ArgNames[$i];
2887             my $flags = $ArgFlags[$i];
2888             my $flags_string = "";
2889             my $kind = "";
2890             my $id_sep = "";
2892             if ($flags =~ m/c/) {
2893                 $kind = "child property";
2894                 $id_sep = "c-";
2895             }
2896             elsif ($flags =~ m/s/) {
2897                 $kind = "style property";
2898                 $id_sep = "s-";
2899             }
2900             else {
2901                 $kind = "property";
2902             }
2904             # Remember only one colon so we don't clash with signals.
2905             my $symbol = "${object}:${name}";
2906             # use two dashes and ev. an extra separator here for the same reason.
2907             my $id = &CreateValidSGMLID ("$object--$id_sep$name");
2909             my $type = $ArgTypes[$i];
2910             my $type_output;
2911             my $range = $ArgRanges[$i];
2912             my $range_output = CreateValidSGML($range);
2913             my $default = $ArgDefaults[$i];
2914             my $default_output = CreateValidSGML($default);
2916             if ($type eq "GtkString") {
2917                 $type = "char*";
2918             }
2919             if ($type eq "GtkSignal") {
2920                 $type = "GtkSignalFunc, gpointer";
2921                 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
2922                     . &MakeXRef ("gpointer");
2923             } elsif ($type =~ m/^(\w+)\*$/) {
2924                 $type_output = &MakeXRef ($1) . "*";
2925             } else {
2926                 $type_output = &MakeXRef ($type);
2927             }
2929             if ($flags =~ m/r/) {
2930                 $flags_string = "Read";
2931             }
2932             if ($flags =~ m/w/) {
2933                 if ($flags_string) { $flags_string .= " / "; }
2934                 $flags_string .= "Write";
2935             }
2936             if ($flags =~ m/x/) {
2937                 if ($flags_string) { $flags_string .= " / "; }
2938                 $flags_string .= "Construct";
2939             }
2940             if ($flags =~ m/X/) {
2941                 if ($flags_string) { $flags_string .= " / "; }
2942                 $flags_string .= "Construct Only";
2943             }
2945             $AllSymbols{$symbol} = 1;
2946             my $blurb;
2947             if (defined($SymbolDocs{$symbol}) &&
2948                 !IsEmptyDoc($SymbolDocs{$symbol})) {
2949                 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
2950                 $AllDocumentedSymbols{$symbol} = 1;
2951             }
2952             else {
2953                 if (!($ArgBlurbs[$i] eq "")) {
2954                     $AllDocumentedSymbols{$symbol} = 1;
2955                 }
2956                 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
2957             }
2959             my $pad1 = " " x (24 - length ($name));
2960             my $pad2 = " " x (20 - length ($type));
2962             my $arg_synop = "  &quot;<link linkend=\"$id\">$name</link>&quot;$pad1 $type_output $pad2 : $flags_string\n";
2963             my $arg_desc = "<refsect2 id=\"$id\"><title>The <literal>&quot;$name&quot;</literal> $kind</title>\n";
2964             $arg_desc .= MakeIndexterms($symbol, $id);
2965             $arg_desc .= "<programlisting>  &quot;$name&quot;$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
2966             $arg_desc .= $blurb;
2967             if ($range ne "") {
2968                 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
2969             }
2970             if ($default ne "") {
2971                 $arg_desc .= "<para>Default value: $default_output</para>\n";
2972             }
2973             if (exists $Since{$symbol}) {
2974               $arg_desc .= "<para>Since $Since{$symbol}</para>\n";
2975             }
2976             if (exists $StabilityLevel{$symbol}) {
2977               $arg_desc .= "<para>Stability Level $StabilityLevel{$symbol}</para>\n";
2978             }
2979             $arg_desc .= "</refsect2>\n";
2981             if ($flags =~ m/c/) {
2982                 $child_synop .= $arg_synop;
2983                 $child_desc .= $arg_desc;
2984             }
2985             elsif ($flags =~ m/s/) {
2986                 $style_synop .= $arg_synop;
2987                 $style_desc .= $arg_desc;
2988             }
2989             else {
2990                 $synop .= $arg_synop;
2991                 $desc .= $arg_desc;
2992             }
2993         }
2994     }
2995     return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
2999 #############################################################################
3000 # Function    : ReadSourceDocumentation
3001 # Description : This reads in the documentation embedded in comment blocks
3002 #               in the source code (for Gnome).
3004 #               Parameter descriptions override any in the template files.
3005 #               Function descriptions are placed before any description from
3006 #               the template files.
3008 #               It recursively descends the source directory looking for .c
3009 #               files and scans them looking for specially-formatted comment
3010 #               blocks.
3012 # Arguments   : $source_dir - the directory to scan.
3013 #############m###############################################################
3015 sub ReadSourceDocumentation {
3016     my ($source_dir) = @_;
3017     my ($file, $dir, @suffix_list, $suffix);
3018     #print "Scanning source directory: $source_dir\n";
3020     # This array holds any subdirectories found.
3021     my (@subdirs) = ();
3023     @suffix_list = split (/,/, $SOURCE_SUFFIXES);
3025     opendir (SRCDIR, $source_dir)
3026         || die "Can't open source directory $source_dir: $!";
3028     foreach $file (readdir (SRCDIR)) {
3029       if ($file =~ /^\./) {
3030         next;
3031       } elsif (-d "$source_dir/$file") {
3032         push (@subdirs, $file);
3033       } elsif (@suffix_list) {
3034         foreach $suffix (@suffix_list) {
3035           if ($file =~ m/\.\Q${suffix}\E$/) {
3036             &ScanSourceFile ("$source_dir/$file");
3037           }
3038         }
3039       } elsif ($file =~ m/\.[ch]$/) {
3040         &ScanSourceFile ("$source_dir/$file");
3041       }
3042     }
3043     closedir (SRCDIR);
3045     # Now recursively scan the subdirectories.
3046     foreach $dir (@subdirs) {
3047         next if ($IGNORE_FILES =~ m/(\s|^)\Q${dir}\E(\s|$)/);
3048         &ReadSourceDocumentation ("$source_dir/$dir");
3049     }
3053 #############################################################################
3054 # Function    : ScanSourceFile
3055 # Description : Scans one source file looking for specially-formatted comment
3056 #               blocks. Later &MergeSourceDocumentation is used to merge any
3057 #               documentation found with the documentation already read in
3058 #               from the template files.
3060 # Arguments   : $file - the file to scan.
3061 #############################################################################
3063 sub ScanSourceFile {
3064     my ($file) = @_;
3065     my $basename;
3067     if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
3068         $basename = $1;
3069     } else {
3070         &LogWarning ($file, 1, "Can't find basename for this filename.");
3071         $basename = $file;
3072     }
3074     # Check if the basename is in the list of files to ignore.
3075     if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
3076         return;
3077     }
3079     #print "DEBUG: Scanning $file\n";
3081     open (SRCFILE, $file)
3082         || die "Can't open $file: $!";
3083     my $in_comment_block = 0;
3084     my $symbol;
3085     my ($in_description, $in_return, $in_since, $in_stability, $in_deprecated);
3086     my ($description, $return_desc, $return_start, $return_style);
3087     my ($since_desc, $stability_desc, $deprecated_desc);
3088     my $current_param;
3089     my $ignore_broken_returns;
3090     my @params;
3091     while (<SRCFILE>) {
3092         # Look for the start of a comment block.
3093         if (!$in_comment_block) {
3094             if (m%^\s*/\*.*\*/%) {
3095                 #one-line comment - not gtkdoc
3096             } elsif (m%^\s*/\*\*\s%) {
3097                 #print "Found comment block start\n";
3099                 $in_comment_block = 1;
3101                 # Reset all the symbol data.
3102                 $symbol = "";
3103                 $in_description = 0;
3104                 $in_return = 0;
3105                 $in_since = 0;
3106                 $in_deprecated = 0;
3107                 $in_stability = 0;
3108                 $description = "";
3109                 $return_desc = "";
3110                 $return_style = "";
3111                 $since_desc = "";
3112                 $deprecated_desc = "";
3113                 $stability_desc = "";
3114                 $current_param = -1;
3115                 $ignore_broken_returns = 0;
3116                 @params = ();
3117             }
3118             next;
3119         }
3121         # We're in a comment block. Check if we've found the end of it.
3122         if (m%^\s*\*+/%) {
3123             if (!$symbol) {
3124                 &LogWarning ($file, $., "Symbol name not found at the start of the comment block.");
3125             } else {
3126                 # Add the return value description onto the end of the params.
3127                 if ($return_desc) {
3128                     push (@params, "Returns");
3129                     push (@params, $return_desc);
3130                     if ($return_style eq 'broken') {
3131                         &LogWarning ($file, $., "Free-form return value description in $symbol. Use `Returns:' to avoid ambiguities.");
3132                     }
3133                 }
3134                 # Convert special SGML characters
3135                 $description = &ConvertSGMLChars ($symbol, $description);
3136                 my $k;
3137                 for ($k = 1; $k <= $#params; $k += 2) {
3138                     $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
3139                 }
3141                 # Handle Section docs
3142                 if ($symbol =~ m/SECTION:\s*(.*)/) {
3143                     my $real_symbol=$1;
3144                     my $key;
3146                     #print "SECTION DOCS found in source for : '$real_symbol'\n";
3147                     $ignore_broken_returns = 1;
3148                     for ($k = 0; $k <= $#params; $k += 2) {
3149                         #print "   '".$params[$k]."'\n";
3150                         $params[$k] = "\L$params[$k]";
3151                         undef $key;
3152                         if ($params[$k] eq "short_description") {
3153                             $key = "$TMPL_DIR/$real_symbol:Short_Description";
3154                         } elsif ($params[$k] eq "see_also") {
3155                             $key = "$TMPL_DIR/$real_symbol:See_Also";
3156                         } elsif ($params[$k] eq "title") {
3157                             $key = "$TMPL_DIR/$real_symbol:Title";
3158                         } elsif ($params[$k] eq "stability") {
3159                             $key = "$TMPL_DIR/$real_symbol:Stability_Level";
3160                         } elsif ($params[$k] eq "section_id") {
3161                             $key = "$TMPL_DIR/$real_symbol:Section_Id";
3162                         } elsif ($params[$k] eq "include") {
3163                             $key = "$TMPL_DIR/$real_symbol:Include";
3164                         }
3165                         if (defined($key)) {
3166                             $SourceSymbolDocs{$key}=$params[$k+1];
3167                             $SourceSymbolSourceFile{$key} = $file;
3168                             $SourceSymbolSourceLine{$key} = $.;
3169                         }
3170                     }
3171                     $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
3172                     $SourceSymbolSourceFile{"$TMPL_DIR/$real_symbol:Long_Description"} = $file;
3173                     $SourceSymbolSourceLine{"$TMPL_DIR/$real_symbol:Long_Description"} = $.;
3174                     #$SourceSymbolTypes{$symbol} = "SECTION";
3175                 } else {
3176                     #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
3177                     $SourceSymbolDocs{$symbol} = $description;
3178                     $SourceSymbolParams{$symbol} = [ @params ];
3179                     # FIXME $SourceSymbolTypes{$symbol} = "STRUCT,SIGNAL,ARG,FUNCTION,MACRO";
3180                     #if (defined $DeclarationTypes{$symbol}) {
3181                     #    $SourceSymbolTypes{$symbol} = $DeclarationTypes{$symbol}
3182                     #}
3183                     $SourceSymbolSourceFile{$symbol} = $file;
3184                     $SourceSymbolSourceLine{$symbol} = $.;
3185                 }
3187                 if ($since_desc) {
3188                      ($since_desc, my @extra_lines) = split ("\n", $since_desc);
3189                      $since_desc =~ s/^\s+//;
3190                      $since_desc =~ s/\s+$//;
3191                      #print "Since($symbol) : [$since_desc]\n";
3192                      $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
3193                      if(scalar @extra_lines) {
3194                          &LogWarning ($file, $., "multi-line since docs found");
3195                      }
3196                 }
3198                 if ($stability_desc) {
3199                     $stability_desc = &ParseStabilityLevel($stability_desc, $file, $., "Stability level for $symbol");
3200                     $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
3201                 }
3203                 if ($deprecated_desc) {
3204                     if (exists $Deprecated{$symbol}) {
3205                     }
3206                     else {
3207                          # don't warn for signals and properties
3208                          #if ($symbol !~ m/::?(.*)/) {
3209                          if (defined $DeclarationTypes{$symbol}) {
3210                              &LogWarning ($file, $., 
3211                                  "$symbol is deprecated in the inline comments, but no deprecation guards were found around the declaration.".
3212                                  " (See the --deprecated-guards option for gtkdoc-scan.)");
3213                          }
3214                     }
3215                     $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
3216                 }
3217             }
3219             $in_comment_block = 0;
3220             next;
3221         }
3223         # Get rid of ' * ' at start of every line in the comment block.
3224         s%^\s*\*\s?%%;
3225         # But make sure we don't get rid of the newline at the end.
3226         if (!$_) {
3227             $_ = "\n";
3228         }
3229         #print "DEBUG: scanning :$_";
3231         # If we haven't found the symbol name yet, look for it.
3232         if (!$symbol) {
3233             if (m%^\s*(SECTION:\s*\S+)%) {
3234                 $symbol = $1;
3235                 #print "SECTION DOCS found in source for : '$symbol'\n";
3236                 $ignore_broken_returns = 1;
3237             } elsif (m%^\s*([\w:-]*\w)\s*:?%) {
3238                 $symbol = $1;
3239                 #print "SYMBOL DOCS found in source for : '$symbol'\n";
3240             }
3241             next;
3242         }
3244         # If we're in the return value description, add it to the end.
3245         if ($in_return) {
3246             # If we find another valid returns line, we assume that the first
3247             # one was really part of the description.
3248             if (m/^\s*(returns:|return\s+value:)/i) {
3249                 if ($return_style eq 'broken') {
3250                     $description .= $return_start . $return_desc;
3251                 }
3252                 $return_start = $1;
3253                 if ($return_style eq 'sane') {
3254                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3255                 }
3256                 $return_style = 'sane';
3257                 $ignore_broken_returns = 1;
3258                 $return_desc = $';
3259             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3260                 $description .= $return_start . $return_desc;
3261                 $return_start = $1;
3262                 $return_style = 'broken';
3263                 $return_desc = $';
3264             } elsif (m%^\s*since:%i) {
3265                 $since_desc = $';
3266                 $in_since = 1;
3267                 $in_return = 0;
3268             } elsif (m%^\s*stability:%i) {
3269                 $stability_desc = $';
3270                 $in_stability = 1;
3271                 $in_return = 0;
3272             } elsif (m%^\s*deprecated:%i) {
3273                 $deprecated_desc = $';
3274                 $in_deprecated = 1;
3275                 $in_return = 0;
3276             } else {
3277                 $return_desc .= $_;
3278             }
3279             next;
3280         }
3282         if ($in_since) {
3283             if (m/^\s*(returns:|return\s+value:)/i) {
3284                 if ($return_style eq 'broken') {
3285                     $description .= $return_start . $return_desc;
3286                 }
3287                 $return_start = $1;
3288                 if ($return_style eq 'sane') {
3289                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3290                 }
3291                 $return_style = 'sane';
3292                 $ignore_broken_returns = 1;
3293                 $return_desc = $';
3294                 $in_return = 1;
3295                 $in_since = 0;
3296             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3297                 $return_start = $1;
3298                 $return_style = 'broken';
3299                 $return_desc = $';
3300                 $in_return = 1;
3301                 $in_since = 0;
3302             } elsif (m%^\s*deprecated:%i) {
3303                 $deprecated_desc = $';
3304                 $in_deprecated = 1;
3305                 $in_since = 0;
3306             } elsif (m%^\s*stability:%i) {
3307                 $stability_desc = $';
3308                 $in_stability = 1;
3309                 $in_since = 0;
3310             } else {
3311                 $since_desc .= $_;
3312             }
3313             next;
3314         }
3316         if ($in_stability) {
3317             if (m/^\s*(returns:|return\s+value:)/i) {
3318                 if ($return_style eq 'broken') {
3319                     $description .= $return_start . $return_desc;
3320                 }
3321                 $return_start = $1;
3322                 if ($return_style eq 'sane') {
3323                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3324                 }
3325                 $return_style = 'sane';
3326                 $ignore_broken_returns = 1;
3327                 $return_desc = $';
3328                 $in_return = 1;
3329                 $in_stability = 0;
3330             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3331                 $return_start = $1;
3332                 $return_style = 'broken';
3333                 $return_desc = $';
3334                 $in_return = 1;
3335                 $in_stability = 0;
3336             } elsif (m%^\s*deprecated:%i) {
3337                 $deprecated_desc = $';
3338                 $in_deprecated = 1;
3339                 $in_stability = 0;
3340             } elsif (m%^\s*since:%i) {
3341                 $since_desc = $';
3342                 $in_since = 1;
3343                 $in_stability = 0;
3344             } else {
3345                 $stability_desc .= $_;
3346             }
3347             next;
3348         }
3350         if ($in_deprecated) {
3351             if (m/^\s*(returns:|return\s+value:)/i) {
3352                 if ($return_style eq 'broken') {
3353                     $description .= $return_start . $return_desc;
3354                 }
3355                 $return_start = $1;
3356                 if ($return_style eq 'sane') {
3357                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3358                 }
3359                 $return_style = 'sane';
3360                 $ignore_broken_returns = 1;
3361                 $return_desc = $';
3362                 $in_return = 1;
3363                 $in_deprecated = 0;
3364             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3365                 $return_start = $1;
3366                 $return_style = 'broken';
3367                 $return_desc = $';
3368                 $in_return = 1;
3369                 $in_deprecated = 0;
3370             } elsif (m%^\s*since:%i) {
3371                 $since_desc = $';
3372                 $in_since = 1;
3373                 $in_deprecated = 0;
3374             } elsif (m%^\s*stability:%i) {
3375                 $stability_desc = $';
3376                 $in_stability = 1;
3377                 $in_deprecated = 0;
3378             } else {
3379                 $deprecated_desc .= $_;
3380             }
3381             next;
3382         }
3384         # If we're in the description part, check for the 'Returns:' line.
3385         # If that isn't found, add the text to the end.
3386         if ($in_description) {
3387             # Get rid of 'Description:'
3388             s%^\s*Description:%%;
3390             if (m/^\s*(returns:|return\s+value:)/i) {
3391                 if ($return_style eq 'broken') {
3392                     $description .= $return_start . $return_desc;
3393                 }
3394                 $return_start = $1;
3395                 if ($return_style eq 'sane') {
3396                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3397                 }
3398                 $return_style = 'sane';
3399                 $ignore_broken_returns = 1;
3400                 $return_desc = $';
3401                 $in_return = 1;
3402                 next;
3403             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3404                 $return_start = $1;
3405                 $return_style = 'broken';
3406                 $return_desc = $';
3407                 $in_return = 1;
3408                 next;
3409             } elsif (m%^\s*since:%i) {
3410                 $since_desc = $';
3411                 $in_since = 1;
3412                 next;
3413             } elsif (m%^\s*deprecated:%i) {
3414                 $deprecated_desc = $';
3415                 $in_deprecated = 1;
3416                 next;
3417             } elsif (m%^\s*stability:%i) {
3418                 $stability_desc = $';
3419                 $in_stability = 1;
3420                 next;
3421             }
3423             $description .= $_;
3424             next;
3425         }
3427         # We must be in the parameters. Check for the empty line below them.
3428         if (m%^\s*$%) {
3429             $in_description = 1;
3430             next;
3431         }
3433         # Look for a parameter name.
3434         if (m%^\s*@(\S+)\s*:%) {
3435             my $param_name = $1;
3436             #print "Found parameter: $param_name\n";
3437             # Allow '...' as the Varargs parameter.
3438             if ($param_name eq "...") {
3439                 $param_name = "Varargs";
3440             }
3441             if ("\L$param_name" eq "returns") {
3442                 $return_style = 'sane';
3443                 $ignore_broken_returns = 1;
3444             }
3445             push (@params, $param_name);
3446             push (@params, $');
3447             $current_param += 2;
3448             next;
3449         }
3451         # We must be in the middle of a parameter description, so add it on
3452         # to the last element in @params.
3453         if ($current_param == -1) {
3454             &LogWarning ($file, $., "Parsing comment block file : parameter expected.");
3455         } else {
3456             $params[$#params] .= $_;
3457         }
3458     }
3459     close (SRCFILE);
3462 #############################################################################
3463 # Function    : OutputMissingDocumentation
3464 # Description : Outputs report of documentation coverage to a file
3466 # Arguments   : none
3467 #############################################################################
3469 sub OutputMissingDocumentation {
3470      my $n_documented = 0;
3471      my $n_incomplete = 0;
3472      my $total = 0;
3473      my $symbol;
3474      my $percent;
3475      my $msg;
3476      my $buffer = "";
3477      my $buffer_deprecated = "";
3478      my $buffer_descriptions = "";
3480      open (UNDOCUMENTED, ">$ROOT_DIR/$MODULE-undocumented.txt")
3481           || die "Can't create $ROOT_DIR/$MODULE-undocumented.txt: $!";
3483      foreach $symbol (sort (keys (%AllSymbols))) {
3484           if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include)/) {
3485               $total++;
3486               if (exists ($AllDocumentedSymbols{$symbol})) {
3487                   $n_documented++;
3488                   if (exists ($AllIncompleteSymbols{$symbol})) {
3489                       $n_incomplete++;
3490                       $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3491                   }
3492               } elsif (exists $Deprecated{$symbol}) {
3493                   if (exists ($AllIncompleteSymbols{$symbol})) {
3494                       $n_incomplete++;
3495                       $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3496                   } else {
3497                       $buffer_deprecated .= $symbol . "\n";
3498                   }
3499               } else {
3500                   if (exists ($AllIncompleteSymbols{$symbol})) {
3501                       $n_incomplete++;
3502                       $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3503                   } else {
3504                       $buffer .= $symbol . "\n";
3505                   }
3506               }
3507           } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
3508               $total++;
3509               #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
3510               #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
3511               #print "%%%% $symbol : $len1,$len2\n";
3512               if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
3513               || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
3514                   $n_documented++;
3515               } else {
3516                   $symbol =~ m/^.*\/(.*)$/;
3517                   $buffer_descriptions .= $1 . "\n";
3518               }
3519           }
3520      }
3522      $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
3524      if ($total == 0) {
3525           $percent = 100;
3526      } else {
3527           $percent = ($n_documented / $total) * 100.0;
3528      }
3530      printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
3531      print UNDOCUMENTED "$n_documented symbols documented.\n";
3532      print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
3533      print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
3535      print UNDOCUMENTED $buffer;
3537      close (UNDOCUMENTED);
3539      printf (("%.0f%% symbol docs coverage ($n_documented symbols documented, $n_incomplete symbols incomplete, " . ($total - $n_documented) . " not documented)\nSee $MODULE-undocumented.txt for a list of missing docs.\nThe doc coverage percentage doesn't include intro sections.\n"), $percent);
3543 #############################################################################
3544 # Function    : OutputUndeclaredSymbols
3545 # Description : Outputs symbols that are undeclared yet documented to a file
3547 # Arguments   : none
3548 #############################################################################
3550 sub OutputUndeclaredSymbols {
3551     open(UNDECLARED, ">$ROOT_DIR/$MODULE-undeclared.txt")
3552         || die "Can't create $ROOT_DIR/$MODULE-undeclared.txt";
3554     if (%UndeclaredSymbols) {
3555         print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
3556         print UNDECLARED "\n";
3557         print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
3558     }
3559     close(UNDECLARED);
3563 #############################################################################
3564 # Function    : OutputAllSymbols
3565 # Description : Outputs list of all symbols to a file
3567 # Arguments   : none
3568 #############################################################################
3570 sub OutputAllSymbols {
3571      my $n_documented = 0;
3572      my $total = 0;
3573      my $symbol;
3574      my $percent;
3575      my $msg;
3577      open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
3578           || die "Can't create $ROOT_DIR/$MODULE-symbols.txt: $!";
3580      foreach $symbol (sort (keys (%AllSymbols))) {
3581           print SYMBOLS $symbol . "\n"
3582      }
3584      close (SYMBOLS);
3588 #############################################################################
3589 # Function    : MergeSourceDocumentation
3590 # Description : This merges documentation read from a source file into the
3591 #               documentation read in from a template file.
3593 #               Parameter descriptions override any in the template files.
3594 #               Function descriptions are placed before any description from
3595 #               the template files.
3597 # Arguments   : none
3598 #############################################################################
3600 sub MergeSourceDocumentation {
3601     my $symbol;
3602     my @Symbols;
3604     if (scalar %SymbolDocs) {
3605         @Symbols=keys (%SymbolDocs);
3606         #print "num existing entries: ".(scalar @Symbols)."\n";
3607         #print "  ",$Symbols[0], " ",$Symbols[1],"\n";
3608     }
3609     else {
3610         # filter scanned declarations, with what we suppress from -sections.txt
3611         my %tmp = ();
3612         foreach $symbol (keys (%Declarations)) {
3613             if ($KnownSymbols{$symbol}) {
3614                 $tmp{$symbol}=1;
3615             }
3616         }
3617         # and add whats found in the source
3618         foreach $symbol (keys (%SourceSymbolDocs)) {
3619             $tmp{$symbol}=1;
3620         }
3621         @Symbols = keys (%tmp);
3622         #print "num source entries: ".(scalar @Symbols)."\n";
3623     }
3624     foreach $symbol (@Symbols) {
3625         $AllSymbols{$symbol} = 1;
3627         my $have_tmpl_docs = 0;
3629         ## See if the symbol is documented in template
3630         my $tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
3631         my $check_tmpl_doc =$tmpl_doc;
3632         # remove all xml-tags and whitespaces
3633         #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
3634         $check_tmpl_doc =~ s/<.*?>//g;
3635         $check_tmpl_doc =~ s/\s//g;
3636         # anything left ?
3637         if ($check_tmpl_doc ne "") {
3638             $have_tmpl_docs = 1;
3639             #print "## [$check_tmpl_doc]\n";
3640         }
3642         if (exists ($SourceSymbolDocs{$symbol})) {
3643             my $type = $DeclarationTypes {$symbol};
3645             #print "merging [$symbol] from source\n";
3647             my $item = "Parameter";
3648             if (defined ($type)) {
3649                 if ($type eq 'STRUCT') {
3650                     $item = "Field";
3651                 } elsif ($type eq 'ENUM') {
3652                     $item = "Value";
3653                 } elsif ($type eq 'UNION') {
3654                     $item = "Field";
3655                 }
3656             } else {
3657                 $type="SIGNAL";
3658             }
3660             my $src_doc = $SourceSymbolDocs{$symbol};
3661             # remove leading and training whitespaces
3662             $src_doc =~ s/^\s+//;
3663             $src_doc =~ s/\s+$//;
3665             # Don't output warnings for overridden titles as titles are
3666             # automatically generated in the -sections.txt file, and thus they
3667             # are often overridden.
3668             if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
3669                 # check if content is different
3670                 if ($tmpl_doc ne $src_doc) {
3671                     #print "[$tmpl_doc] [$src_doc]\n";
3672                     &LogWarning ($SourceSymbolSourceFile{$symbol}, $SourceSymbolSourceLine{$symbol},
3673                         "Documentation in template ".$SymbolSourceFile{$symbol}.":".$SymbolSourceLine{$symbol}." for $symbol being overridden by inline comments.");
3674                 }
3675             }
3677             if ($src_doc ne "") {
3678                  $AllDocumentedSymbols{$symbol} = 1;
3679             }
3681             # Convert <!--PARAMETERS--> with any blank lines around it to
3682             # a </para> followed by <!--PARAMETERS--> followed by <para>.
3683             $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
3685             # If there is a blank line, finish the paragraph and start another.
3686             $src_doc = &ConvertBlankLines ($src_doc, $symbol);
3688             if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
3689                 $SymbolDocs{$symbol} = "<para>\n$src_doc</para>\n$tmpl_doc";
3690             } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
3691                 # For the title/summary/see also section docs we don't want to
3692                 # add any <para> tags.
3693                 $SymbolDocs{$symbol} = "$src_doc"
3694             } else {
3695                 $SymbolDocs{$symbol} = "<para>\n$src_doc</para>\n$tmpl_doc";
3696             }
3698             # merge parameters
3699             if ($symbol =~ m/.*::.*/) {
3700                 # For signals we prefer the param names from the source docs,
3701                 # since the ones from the templates are likely to contain the
3702                 # artificial argn names which are generated by gtkdoc-scangobj.
3703                 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
3704                 # FIXME: we need to check for empty docs here as well!
3705             } else {
3706                 # The templates contain the definitive parameter names and order,
3707                 # so we will not change that. We only override the actual text.
3708                 my $tmpl_params = $SymbolParams{$symbol};
3709                 if (!defined ($tmpl_params)) {
3710                     #print "No merge needed for $symbol\n";
3711                     $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
3712                 } else {
3713                     my $params = $SourceSymbolParams{$symbol};
3714                     my $j;
3715                     #print "Merge needed for $symbol, tmpl_params: ",$#$tmpl_params,", source_params: ",$#$params," \n";
3716                     for ($j = 0; $j <= $#$tmpl_params; $j += 2) {
3717                         my $tmpl_param_name = $$tmpl_params[$j];
3719                         # Allow '...' as the Varargs parameter.
3720                         if ($tmpl_param_name eq "...") {
3721                             $tmpl_param_name = "Varargs";
3722                         }
3724                         # Try to find the param in the source comment documentation.
3725                         my $found = 0;
3726                         my $k;
3727                         for ($k = 0; $k <= $#$params; $k += 2) {
3728                             my $param_name = $$params[$k];
3729                             my $param_desc = $$params[$k + 1];
3731                             # We accept changes in case, since the Gnome source docs
3732                             # contain a lot of these.
3733                             if ("\L$param_name" eq "\L$tmpl_param_name") {
3734                                 $found = 1;
3736                                 # Override the description.
3737                                 $$tmpl_params[$j + 1] = $param_desc;
3739                                 # Set the name to "" to mark it as used.
3740                                 $$params[$k] = "";
3741                                 last;
3742                             }
3743                         }
3745                         # If it looks like the parameters are there, but not
3746                         # in the right place, try to explain a bit better.
3747                         if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
3748                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3749                                 "Parameters for $symbol must start on the line immediately after the function or macro name.");
3750                         }
3751                     }
3753                     # Now we output a warning if parameters have been described which
3754                     # do not exist.
3755                     for ($j = 0; $j <= $#$params; $j += 2) {
3756                         my $param_name = $$params[$j];
3757                         if ($param_name) {
3758                             # the template builder cannot detect if a macro returns
3759                             # a result or not
3760                             if(($type eq "MACRO") && ($param_name eq "Returns")) {
3761                                 next;
3762                             }
3763                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3764                                 "$item described in source code comment block but does not exist. $type: $symbol $item: $param_name.");
3765                         }
3766                     }
3767                 }
3768             }
3769         } else {
3770             if ($have_tmpl_docs) {
3771                 $AllDocumentedSymbols{$symbol} = 1;
3772                 #print "merging [$symbol] from template\n";
3773             }
3774             else {
3775                 #print "[$symbol] undocumented\n";
3776             }
3777         }
3779         # if this symbol is documented, check if docs are complete
3780         $check_tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
3781         # remove all xml-tags and whitespaces
3782         #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
3783         $check_tmpl_doc =~ s/<.*?>//g;
3784         $check_tmpl_doc =~ s/\s//g;
3785         if ($check_tmpl_doc ne "") {
3786             my $tmpl_params = $SymbolParams{$symbol};
3787             if (defined ($tmpl_params)) {
3788                 my $type = $DeclarationTypes {$symbol};
3790                 my $item = "Parameter";
3791                 if (defined ($type)) {
3792                     if ($type eq 'STRUCT') {
3793                         $item = "Field";
3794                     } elsif ($type eq 'ENUM') {
3795                         $item = "Value";
3796                     } elsif ($type eq 'UNION') {
3797                         $item = "Field";
3798                     }
3799                 } else {
3800                     $type="SIGNAL";
3801                 }
3803                 #print "Check param docs for $symbol, tmpl_params: ",$#$tmpl_params,"\n";
3805                 my $j;
3806                 for ($j = 0; $j <= $#$tmpl_params; $j += 2) {
3807                     # Output a warning if the parameter is empty and
3808                     # remember for stats.
3809                     my $tmpl_param_name = $$tmpl_params[$j];
3810                     my $tmpl_param_desc = $$tmpl_params[$j + 1];
3811                     if ($tmpl_param_desc !~ m/\S/) {
3812                         if (exists ($AllIncompleteSymbols{$symbol})) {
3813                             $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
3814                         } else {
3815                             $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
3816                         }
3817                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3818                             "$item description for $tmpl_param_name is missing in source code comment block.");
3819                     }
3820                 }
3821             }
3822         }
3823    }
3824    #print "num doc entries: ".(scalar %SymbolDocs)."\n";
3827 sub IsEmptyDoc {
3828     my ($doc) = @_;
3830     if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
3831         return 1;
3832     } else {
3833         return 0;
3834     }
3838 # This converts blank lines to "</para><para>", but only outside CDATA and
3839 # <programlisting> tags.
3840 sub ConvertBlankLines {
3841     return &ModifyXMLElements ($_[0], $_[1],
3842                                "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
3843                                \&ConvertBlankLinesEndTag,
3844                                \&ConvertBlankLinesCallback);
3848 sub ConvertBlankLinesEndTag {
3849   if ($_[0] eq "<!\[CDATA\[") {
3850     return "]]>";
3851   } elsif ($_[0] eq "|[") {
3852     return "]\\|";
3853   } else {
3854     return "</programlisting>";
3855   }
3858 sub ConvertBlankLinesCallback {
3859   my ($text, $symbol, $tag) = @_;
3861   # If we're not in CDATA or a <programlisting> we convert blank lines so
3862   # they start a new <para>.
3863   if ($tag eq "") {
3864     $text =~ s%\n{2,}%\n</para>\n<para>\n%g;
3865   }
3867   return $text;
3871 #############################################################################
3872 # LIBRARY FUNCTIONS -   These functions are used in both gtkdoc-mkdb and
3873 #                       gtkdoc-mktmpl and should eventually be moved to a
3874 #                       separate library.
3875 #############################################################################
3877 #############################################################################
3878 # Function    : ReadDeclarationsFile
3879 # Description : This reads in a file containing the function/macro/enum etc.
3880 #               declarations.
3882 #               Note that in some cases there are several declarations with
3883 #               the same name, e.g. for conditional macros. In this case we
3884 #               set a flag in the %DeclarationConditional hash so the
3885 #               declaration is not shown in the docs.
3887 #               If a macro and a function have the same name, e.g. for
3888 #               gtk_object_ref, the function declaration takes precedence.
3890 #               Some opaque structs are just declared with 'typedef struct
3891 #               _name name;' in which case the declaration may be empty.
3892 #               The structure may have been found later in the header, so
3893 #               that overrides the empty declaration.
3895 # Arguments   : $file - the declarations file to read
3896 #               $override - if declarations in this file should override
3897 #                       any current declaration.
3898 #############################################################################
3900 sub ReadDeclarationsFile {
3901     my ($file, $override) = @_;
3903     if ($override == 0) {
3904         %Declarations = ();
3905         %DeclarationTypes = ();
3906         %DeclarationConditional = ();
3907         %DeclarationOutput = ();
3908     }
3910     open (INPUT, $file)
3911         || die "Can't open $file: $!";
3912     my $declaration_type = "";
3913     my $declaration_name;
3914     my $declaration;
3915     my $is_deprecated = 0;
3916     while (<INPUT>) {
3917         if (!$declaration_type) {
3918             if (m/^<([^>]+)>/) {
3919                 $declaration_type = $1;
3920                 $declaration_name = "";
3921                 #print "Found declaration: $declaration_type\n";
3922                 $declaration = "";
3923             }
3924         } else {
3925             if (m%^<NAME>(.*)</NAME>%) {
3926                 $declaration_name = $1;
3927             } elsif (m%^<DEPRECATED/>%) {
3928                 $is_deprecated = 1;
3929             } elsif (m%^</$declaration_type>%) {
3930                 #print "Found end of declaration: $declaration_name\n";
3931                 # Check that the declaration has a name
3932                 if ($declaration_name eq "") {
3933                     print "ERROR: $declaration_type has no name $file:$.\n";
3934                 }
3936                 # If the declaration is an empty typedef struct _XXX XXX
3937                 # set the flag to indicate the struct has a typedef.
3938                 if ($declaration_type eq 'STRUCT'
3939                     && $declaration =~ m/^\s*$/) {
3940                     #print "Struct has typedef: $declaration_name\n";
3941                     $StructHasTypedef{$declaration_name} = 1;
3942                 }
3944                 # Check if the symbol is already defined.
3945                 if (defined ($Declarations{$declaration_name})
3946                     && $override == 0) {
3947                     # Function declarations take precedence.
3948                     if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
3949                         # Ignore it.
3950                     } elsif ($declaration_type eq 'FUNCTION') {
3951                         if ($is_deprecated) {
3952                             $Deprecated{$declaration_name} = "";
3953                         }
3954                         $Declarations{$declaration_name} = $declaration;
3955                         $DeclarationTypes{$declaration_name} = $declaration_type;
3956                     } elsif ($DeclarationTypes{$declaration_name}
3957                               eq $declaration_type) {
3958                         # If the existing declaration is empty, or is just a
3959                         # forward declaration of a struct, override it.
3960                         if ($declaration_type eq 'STRUCT') {
3961                             if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
3962                                 if ($is_deprecated) {
3963                                     $Deprecated{$declaration_name} = "";
3964                                 }
3965                                 $Declarations{$declaration_name} = $declaration;
3966                             } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
3967                                 # Ignore an empty or forward declaration.
3968                             } else {
3969                                 &LogWarning ($file, $., "Structure $declaration_name has multiple definitions.");
3970                             }
3971                         } else {
3972                             # set flag in %DeclarationConditional hash for
3973                             # multiply defined macros/typedefs.
3974                             $DeclarationConditional{$declaration_name} = 1;
3975                         }
3976                     } else {
3977                         &LogWarning ($file, $., "$declaration_name has multiple definitions.");
3978                     }
3979                 } else {
3980                     if ($is_deprecated) {
3981                         $Deprecated{$declaration_name} = "";
3982                     }
3983                     $Declarations{$declaration_name} = $declaration;
3984                     $DeclarationTypes{$declaration_name} = $declaration_type;
3985                 }
3987                 $declaration_type = "";
3988                 $is_deprecated = 0;
3989             } else {
3990                 $declaration .= $_;
3991             }
3992         }
3993     }
3994     close (INPUT);
3998 #############################################################################
3999 # Function    : ReadSignalsFile
4000 # Description : This reads in an existing file which contains information on
4001 #               all GTK signals. It creates the arrays @SignalNames and
4002 #               @SignalPrototypes containing info on the signals. The first
4003 #               line of the SignalPrototype is the return type of the signal
4004 #               handler. The remaining lines are the parameters passed to it.
4005 #               The last parameter, "gpointer user_data" is always the same
4006 #               so is not included.
4007 # Arguments   : $file - the file containing the signal handler prototype
4008 #                       information.
4009 #############################################################################
4011 sub ReadSignalsFile {
4012     my ($file) = @_;
4014     my $in_signal = 0;
4015     my $signal_object;
4016     my $signal_name;
4017     my $signal_returns;
4018     my $signal_flags;
4019     my $signal_prototype;
4021     # Reset the signal info.
4022     @SignalObjects = ();
4023     @SignalNames = ();
4024     @SignalReturns = ();
4025     @SignalFlags = ();
4026     @SignalPrototypes = ();
4028     if (! -f $file) {
4029         return;
4030     }
4031     if (!open (INPUT, $file)) {
4032         warn "Can't open $file - skipping signals\n";
4033         return;
4034     }
4035     while (<INPUT>) {
4036         if (!$in_signal) {
4037             if (m/^<SIGNAL>/) {
4038                 $in_signal = 1;
4039                 $signal_object = "";
4040                 $signal_name = "";
4041                 $signal_returns = "";
4042                 $signal_prototype = "";
4043             }
4044         } else {
4045             if (m/^<NAME>(.*)<\/NAME>/) {
4046                 $signal_name = $1;
4047                 if ($signal_name =~ m/^(.*)::(.*)$/) {
4048                     $signal_object = $1;
4049                     ($signal_name = $2) =~ s/_/-/g;
4050                     #print "Found signal: $signal_name\n";
4051                 } else {
4052                     &LogWarning ($file, $., "Invalid signal name: $signal_name.");
4053                 }
4054             } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
4055                 $signal_returns = $1;
4056             } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4057                 $signal_flags = $1;
4058             } elsif (m%^</SIGNAL>%) {
4059                 #print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
4060                 push (@SignalObjects, $signal_object);
4061                 push (@SignalNames, $signal_name);
4062                 push (@SignalReturns, $signal_returns);
4063                 push (@SignalFlags, $signal_flags);
4064                 push (@SignalPrototypes, $signal_prototype);
4065                 $in_signal = 0;
4066             } else {
4067                 $signal_prototype .= $_;
4068             }
4069         }
4070     }
4071     close (INPUT);
4075 #############################################################################
4076 # Function    : ReadTemplateFile
4077 # Description : This reads in the manually-edited documentation file
4078 #               corresponding to the file currently being created, so we can
4079 #               insert the documentation at the appropriate places.
4080 #               It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
4081 #               is a hash of arrays.
4082 #               NOTE: This function is duplicated in gtkdoc-mktmpl (but
4083 #               slightly different).
4084 # Arguments   : $docsfile - the template file to read in.
4085 #               $skip_unused_params - 1 if the unused parameters should be
4086 #                       skipped.
4087 #############################################################################
4089 sub ReadTemplateFile {
4090     my ($docsfile, $skip_unused_params) = @_;
4092     my $template = "$docsfile.sgml";
4093     if (! -f $template) {
4094         #print "File doesn't exist: $template\n";
4095         return 0;
4096     }
4097     #print "Reading $template\n";
4099     # start with empty hashes, we merge the source comment for each file
4100     # afterwards
4101     %SymbolDocs = ();
4102     %SymbolTypes = ();
4103     %SymbolParams = ();
4105     my $current_type = "";      # Type of symbol being read.
4106     my $current_symbol = "";    # Name of symbol being read.
4107     my $symbol_doc = "";                # Description of symbol being read.
4108     my @params;                 # Parameter names and descriptions of current
4109                                 #   function/macro/function typedef.
4110     my $current_param = -1;     # Index of parameter currently being read.
4111                                 #   Note that the param array contains pairs
4112                                 #   of param name & description.
4113     my $in_unused_params = 0;   # True if we are reading in the unused params.
4114     my $in_deprecated = 0;
4115     my $in_since = 0;
4116     my $in_stability = 0;
4118     open (DOCS, "$template")
4119         || die "Can't open $template: $!";
4120     while (<DOCS>) {
4121         if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
4122             my $type = $1;
4123             my $symbol = $2;
4124             if ($symbol eq "Title"
4125                 || $symbol eq "Short_Description"
4126                 || $symbol eq "Long_Description"
4127                 || $symbol eq "See_Also"
4128                 || $symbol eq "Stability_Level"
4129                 || $symbol eq "Include") {
4131                 $symbol = $docsfile . ":" . $symbol;
4132             }
4134             #print "Found symbol: $symbol\n";
4135             # Remember file and line for the symbol
4136             $SymbolSourceFile{$symbol} = $template;
4137             $SymbolSourceLine{$symbol} = $.;
4139             # Store previous symbol, but remove any trailing blank lines.
4140             if ($current_symbol ne "") {
4141                 $symbol_doc =~ s/\s+$//;
4142                 $SymbolTypes{$current_symbol} = $current_type;
4143                 $SymbolDocs{$current_symbol} = $symbol_doc;
4145                 # Check that the stability level is valid.
4146                 if ($StabilityLevel{$current_symbol}) {
4147                     $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4148                 }
4150                 if ($current_param >= 0) {
4151                     $SymbolParams{$current_symbol} = [ @params ];
4152                 } else {
4153                     # Delete any existing params in case we are overriding a
4154                     # previously read template.
4155                     delete $SymbolParams{$current_symbol};
4156                 }
4157             }
4158             $current_type = $type;
4159             $current_symbol = $symbol;
4160             $current_param = -1;
4161             $in_unused_params = 0;
4162             $in_deprecated = 0;
4163             $in_since = 0;
4164             $in_stability = 0;
4165             $symbol_doc = "";
4166             @params = ();
4168         } elsif (m/^<!-- # Unused Parameters # -->/) {
4169             #print "DEBUG: Found unused parameters\n";
4170             $in_unused_params = 1;
4171             next;
4173         } elsif ($in_unused_params && $skip_unused_params) {
4174             # When outputting the DocBook we skip unused parameters.
4175             #print "DEBUG: Skipping unused param: $_";
4176             next;
4178         } else {
4179             # Check if param found. Need to handle "..." and "format...".
4180             if (s/^\@([\w\.]+):\040?//) {
4181                 my $param_name = $1;
4182                 # Allow variations of 'Returns'
4183                 if ($param_name =~ m/^[Rr]eturns?$/) {
4184                     $param_name = "Returns";
4185                 }
4187                 # strip trailing whitespaces and blank lines
4188                 s/\s+\n$/\n/m;
4189                 s/\n+$/\n/sm;
4190                 #print "Found param for symbol $current_symbol : '$param_name'= '$_'";
4192                 if ($param_name eq "Deprecated") {
4193                     $in_deprecated = 1;
4194                     $Deprecated{$current_symbol} = $_;
4195                 } elsif ($param_name eq "Since") {
4196                     $in_since = 1;
4197                     chomp;
4198                     $Since{$current_symbol} = $_;
4199                 } elsif ($param_name eq "Stability") {
4200                     $in_stability = 1;
4201                     $StabilityLevel{$current_symbol} = $_;
4202                 } else {
4203                     push (@params, $param_name);
4204                     push (@params, $_);
4205                     $current_param += 2;
4206                 }
4207             } else {
4208                 # strip trailing whitespaces and blank lines
4209                 s/\s+\n$/\n/m;
4210                 s/\n+$/\n/sm;
4211                 
4212                 if (!m/^\s+$/) {
4213                     if ($in_deprecated) {
4214                         $Deprecated{$current_symbol} .= $_;
4215                     } elsif ($in_since) {
4216                         &LogWarning ($template, $., "multi-line since docs found");
4217                         #$Since{$current_symbol} .= $_;
4218                     } elsif ($in_stability) {
4219                         $StabilityLevel{$current_symbol} .= $_;
4220                     } elsif ($current_param >= 0) {
4221                         $params[$current_param] .= $_;
4222                     } else {
4223                         $symbol_doc .= $_;
4224                     }
4225                 }
4226             }
4227         }
4228     }
4230     # Remember to finish the current symbol doccs.
4231     if ($current_symbol ne "") {
4233         $symbol_doc =~ s/\s+$//;
4234         $SymbolTypes{$current_symbol} = $current_type;
4235         $SymbolDocs{$current_symbol} = $symbol_doc;
4237         # Check that the stability level is valid.
4238         if ($StabilityLevel{$current_symbol}) {
4239             $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4240         }
4242         if ($current_param >= 0) {
4243             $SymbolParams{$current_symbol} = [ @params ];
4244         } else {
4245             # Delete any existing params in case we are overriding a
4246             # previously read template.
4247             delete $SymbolParams{$current_symbol};
4248         }
4249     }
4251     close (DOCS);
4252     return 1;
4256 #############################################################################
4257 # Function    : ReadObjectHierarchy
4258 # Description : This reads in the $MODULE-hierarchy.txt file containing all
4259 #               the GtkObject subclasses described in this module (and their
4260 #               ancestors).
4261 #               It places them in the @Objects array, and places their level
4262 #               in the widget hierarchy in the @ObjectLevels array, at the
4263 #               same index. GtkObject, the root object, has a level of 1.
4265 #               FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
4266 #               as it goes along, this should be split out into a separate
4267 #               function.
4269 # Arguments   : none
4270 #############################################################################
4272 sub ReadObjectHierarchy {
4273     @Objects = ();
4274     @ObjectLevels = ();
4276     if (! -f $OBJECT_TREE_FILE) {
4277         return;
4278     }
4279     if (!open (INPUT, $OBJECT_TREE_FILE)) {
4280         warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
4281         return;
4282     }
4284     # FIXME: use $OUTPUT_FORMAT
4285     # my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.$OUTPUT_FORMAT";
4286     my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
4287     my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
4289     open (OUTPUT, ">$new_tree_index")
4290         || die "Can't create $new_tree_index: $!";
4292     if (lc($OUTPUT_FORMAT) eq "xml") {
4293         my $tree_header = $doctype_header;
4295         $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
4296         print (OUTPUT "$tree_header");
4297     }
4298     print (OUTPUT "<screen>\n");
4300     # Only emit objects if they are supposed to be documented, or if
4301     # they have documented children. To implement this, we maintain a
4302     # stack of pending objects which will be emitted if a documented
4303     # child turns up.
4304     my @pending_objects = ();
4305     my @pending_levels = ();
4306     while (<INPUT>) {
4307         if (m/\S+/) {
4308             my $object = $&;
4309             my $level = (length($`)) / 2 + 1;
4310             my $xref = "";
4312             while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
4313                 my $pobject = pop(@pending_objects);
4314                 my $plevel = pop(@pending_levels);
4315             }
4317             push (@pending_objects, $object);
4318             push (@pending_levels, $level);
4320             if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
4321                 while ($#pending_levels >= 0) {
4322                     $object = shift @pending_objects;
4323                     $level = shift @pending_levels;
4324                     $xref = &MakeXRef ($object);
4326                     print (OUTPUT ' ' x ($level * 4), "$xref\n");
4327                     push (@Objects, $object);
4328                     push (@ObjectLevels, $level);
4329                 }
4330             }
4331         }
4332     }
4333     print (OUTPUT "</screen>\n");
4335     close (INPUT);
4336     close (OUTPUT);
4338     &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
4340     &OutputObjectList;
4343 #############################################################################
4344 # Function    : ReadInterfaces
4345 # Description : This reads in the $MODULE.interfaces file.
4347 # Arguments   : none
4348 #############################################################################
4350 sub ReadInterfaces {
4351     %Interfaces = ();
4353     if (! -f $INTERFACES_FILE) {
4354         return;
4355     }
4356     if (!open (INPUT, $INTERFACES_FILE)) {
4357         warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
4358         return;
4359     }
4361     while (<INPUT>) {
4362        chomp;
4363        my ($object, @ifaces) = split;
4364        if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
4365            my @knownIfaces = ();
4367            # filter out private interfaces, but leave foreign interfaces
4368            foreach my $iface (@ifaces) {
4369                if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
4370                    push (@knownIfaces, $iface);
4371                }
4372              }
4374            $Interfaces{$object} = join(' ', @knownIfaces);
4375        }
4376     }
4377     close (INPUT);
4380 #############################################################################
4381 # Function    : ReadPrerequisites
4382 # Description : This reads in the $MODULE.prerequisites file.
4384 # Arguments   : none
4385 #############################################################################
4387 sub ReadPrerequisites {
4388     %Prerequisites = ();
4390     if (! -f $PREREQUISITES_FILE) {
4391         return;
4392     }
4393     if (!open (INPUT, $PREREQUISITES_FILE)) {
4394         warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
4395         return;
4396     }
4398     while (<INPUT>) {
4399        chomp;
4400        my ($iface, @prereqs) = split;
4401        if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
4402            my @knownPrereqs = ();
4404            # filter out private prerequisites, but leave foreign prerequisites
4405            foreach my $prereq (@prereqs) {
4406                if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
4407                   push (@knownPrereqs, $prereq);
4408                }
4409            }
4411            $Prerequisites{$iface} = join(' ', @knownPrereqs);
4412        }
4413     }
4414     close (INPUT);
4417 #############################################################################
4418 # Function    : ReadArgsFile
4419 # Description : This reads in an existing file which contains information on
4420 #               all GTK args. It creates the arrays @ArgObjects, @ArgNames,
4421 #               @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
4422 #               on the args.
4423 # Arguments   : $file - the file containing the arg information.
4424 #############################################################################
4426 sub ReadArgsFile {
4427     my ($file) = @_;
4429     my $in_arg = 0;
4430     my $arg_object;
4431     my $arg_name;
4432     my $arg_type;
4433     my $arg_flags;
4434     my $arg_nick;
4435     my $arg_blurb;
4436     my $arg_default;
4437     my $arg_range;
4439     # Reset the args info.
4440     @ArgObjects = ();
4441     @ArgNames = ();
4442     @ArgTypes = ();
4443     @ArgFlags = ();
4444     @ArgNicks = ();
4445     @ArgBlurbs = ();
4446     @ArgDefaults = ();
4447     @ArgRanges = ();
4449     if (! -f $file) {
4450         return;
4451     }
4452     if (!open (INPUT, $file)) {
4453         warn "Can't open $file - skipping args\n";
4454         return;
4455     }
4456     while (<INPUT>) {
4457         if (!$in_arg) {
4458             if (m/^<ARG>/) {
4459                 $in_arg = 1;
4460                 $arg_object = "";
4461                 $arg_name = "";
4462                 $arg_type = "";
4463                 $arg_flags = "";
4464                 $arg_nick = "";
4465                 $arg_blurb = "";
4466                 $arg_default = "";
4467                 $arg_range = "";
4468             }
4469         } else {
4470             if (m/^<NAME>(.*)<\/NAME>/) {
4471                 $arg_name = $1;
4472                 if ($arg_name =~ m/^(.*)::(.*)$/) {
4473                     $arg_object = $1;
4474                     ($arg_name = $2) =~ s/_/-/g;
4475                     #print "Found arg: $arg_name\n";
4476                 } else {
4477                     &LogWarning ($file, $., "Invalid argument name: $arg_name");
4478                 }
4479             } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
4480                 $arg_type = $1;
4481             } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
4482                 $arg_range = $1;
4483             } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4484                 $arg_flags = $1;
4485             } elsif (m/^<NICK>(.*)<\/NICK>/) {
4486                 $arg_nick = $1;
4487             } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
4488                 $arg_blurb = $1;
4489                 if ($arg_blurb eq "(null)") {
4490                   $arg_blurb = "";
4491                   &LogWarning ($file, $., "Property ${arg_object}:${arg_name} has no documentation.");
4492                 }
4493             } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
4494                 $arg_default = $1;
4495             } elsif (m%^</ARG>%) {
4496                 #print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
4497                 push (@ArgObjects, $arg_object);
4498                 push (@ArgNames, $arg_name);
4499                 push (@ArgTypes, $arg_type);
4500                 push (@ArgRanges, $arg_range);
4501                 push (@ArgFlags, $arg_flags);
4502                 push (@ArgNicks, $arg_nick);
4503                 push (@ArgBlurbs, $arg_blurb);
4504                 push (@ArgDefaults, $arg_default);
4505                 $in_arg = 0;
4506             }
4507         }
4508     }
4509     close (INPUT);
4513 #############################################################################
4514 # Function    : CheckIsObject
4515 # Description : Returns 1 if the given name is a GtkObject or a subclass.
4516 #               It uses the global @Objects array.
4517 #               Note that the @Objects array only contains classes in the
4518 #               current module and their ancestors - not all GTK classes.
4519 # Arguments   : $name - the name to check.
4520 #############################################################################
4522 sub CheckIsObject {
4523     my ($name) = @_;
4525     my $object;
4526     foreach $object (@Objects) {
4527         if ($object eq $name) {
4528             return 1;
4529         }
4530     }
4531     return 0;
4535 #############################################################################
4536 # Function    : MakeReturnField
4537 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
4538 # Arguments   : $str - the string to pad.
4539 #############################################################################
4541 sub MakeReturnField {
4542     my ($str) = @_;
4544     return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));
4547 #############################################################################
4548 # Function    : GetSymbolSourceFile
4549 # Description : Get the filename where the symbol docs where taken from.
4550 # Arguments   : $symbol - the symbol name
4551 #############################################################################
4553 sub GetSymbolSourceFile {
4554     my ($symbol) = @_;
4556     if (defined($SourceSymbolSourceFile{$symbol})) {
4557         return $SourceSymbolSourceFile{$symbol};
4558     } elsif (defined($SymbolSourceFile{$symbol})) {
4559         return $SymbolSourceFile{$symbol};
4560     } else {
4561         return "";
4562     }
4565 #############################################################################
4566 # Function    : GetSymbolSourceLine
4567 # Description : Get the file line where the symbol docs where taken from.
4568 # Arguments   : $symbol - the symbol name
4569 #############################################################################
4571 sub GetSymbolSourceLine {
4572     my ($symbol) = @_;
4574     if (defined($SourceSymbolSourceLine{$symbol})) {
4575         return $SourceSymbolSourceLine{$symbol};
4576     } elsif (defined($SymbolSourceLine{$symbol})) {
4577         return $SymbolSourceLine{$symbol};
4578     } else {
4579         return 0;
4580     }