fixxref: smarter link resolving
[gtk-doc.git] / gtkdoc-mkdb.in
blob44b0f721f10a52185c63aaf6354864b9309531d8
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #############################################################################
24 # Script      : gtkdoc-mkdb
25 # Description : This creates the DocBook files from the edited templates.
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 $MAIN_SGML_FILE;
51 my $EXPAND_CONTENT_FILES = "";
52 my $SGML_MODE;
53 my $DEFAULT_STABILITY;
54 my $DEFAULT_INCLUDES;
55 my $OUTPUT_FORMAT;
56 my $NAME_SPACE = "";
57 my $OUTPUT_ALL_SYMBOLS;
58 my $OUTPUT_SYMBOLS_WITHOUT_SINCE;
60 my %optctl = ('module' => \$MODULE,
61               'source-dir' => \@SOURCE_DIRS,
62               'source-suffixes' => \$SOURCE_SUFFIXES,
63               'ignore-files' => \$IGNORE_FILES,
64               'output-dir' => \$SGML_OUTPUT_DIR,
65               'tmpl-dir' => \$TMPL_DIR,
66               'version' => \$PRINT_VERSION,
67               'help' => \$PRINT_HELP,
68               'main-sgml-file' => \$MAIN_SGML_FILE,
69               'expand-content-files' => \$EXPAND_CONTENT_FILES,
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               'outputallsymbols' => \$OUTPUT_ALL_SYMBOLS,
76               'outputsymbolswithoutsince' => \$OUTPUT_SYMBOLS_WITHOUT_SINCE
77               );
78 GetOptions(\%optctl, "module=s", "source-dir:s", "source-suffixes:s", 
79     "ignore-files:s", "output-dir:s", "tmpl-dir:s", "version", "outputallsymbols",
80     "outputsymbolswithoutsince",
81     "expand-content-files:s", "main-sgml-file:s", "extra-db-files:s", "help",
82     "sgml-mode", "default-stability:s", "default-includes:s", "output-format:s",
83     "name-space:s");
85 if ($PRINT_VERSION) {
86     print "@VERSION@\n";
87     exit 0;
90 if (!$MODULE) {
91     $PRINT_HELP = 1;
94 if ($DEFAULT_STABILITY && $DEFAULT_STABILITY ne "Stable"
95     && $DEFAULT_STABILITY ne "Private" && $DEFAULT_STABILITY ne "Unstable") {
96     $PRINT_HELP = 1;
99 if ($PRINT_HELP) {
100     print <<EOF;
101 gtkdoc-mkdb version @VERSION@ - generate docbook files
103 --module=MODULE_NAME       Name of the doc module being parsed
104 --source-dir=DIRNAME       Directories which contain inline reference material
105 --source-suffixes=SUFFIXES Suffixes of source files to scan, comma-separated
106 --ignore-files=FILES       Files or directories which should not be scanned
107                            May be used more than once for multiple directories
108 --output-dir=DIRNAME       Directory to put the generated DocBook files in
109 --tmpl-dir=DIRNAME         Directory in which template files may be found
110 --main-sgml-file=FILE      File containing the toplevel DocBook file.
111 --expand-content-files=FILES Extra DocBook files to expand abbreviations in.
112 --output-format=FORMAT     Format to use for the generated docbook, XML or SGML.
113 --sgml-mode                Allow DocBook markup in inline documentation.
114 --default-stability=LEVEL  Specify default stability Level. Valid values are
115                            Stable, Unstable, or Private.
116 --default-includes=FILENAMES Specify default includes for section Synopsis
117 --name-space=NS            Omit namespace in index.
118 --version                  Print the version of this program
119 --help                     Print this help
121     exit 0;
124 my ($empty_element_end, $doctype_header);
126 if (lc($OUTPUT_FORMAT) eq "xml") {
127     if (!$MAIN_SGML_FILE) {
128         # backwards compatibility
129         if (-e "${MODULE}-docs.sgml") {
130             $MAIN_SGML_FILE="${MODULE}-docs.sgml";
131         } else {
132             $MAIN_SGML_FILE="${MODULE}-docs.xml";
133         }
134     }
135     $OUTPUT_FORMAT = "xml";
136     $empty_element_end = "/>";
138     if (-e $MAIN_SGML_FILE) {
139         open(INPUT, "<$MAIN_SGML_FILE") || die "Can't open $MAIN_SGML_FILE";
140         $doctype_header = "";
141         while (<INPUT>) {
142             if (/^\s*<(book|chapter|article)/) {
143                 if ($_ !~ m/http:\/\/www.w3.org\/200[13]\/XInclude/) {
144                     $doctype_header = "";
145                 }
146                 last;
147             }
148             $doctype_header .= $_;
149         }
150         close(INPUT);
151     } else {
152         $doctype_header =
153 "<?xml version=\"1.0\"?>\n" .
154 "<!DOCTYPE book PUBLIC \"-//OASIS//DTD DocBook XML V4.3//EN\"\n" .
155 "               \"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd\">\n";
156     }
157     $doctype_header =~ s/<!DOCTYPE \w+/<!DOCTYPE refentry/;
158 } else {
159     if (!$MAIN_SGML_FILE) {
160         $MAIN_SGML_FILE="${MODULE}-docs.sgml";
161     }
162     $OUTPUT_FORMAT = "sgml";
163     $doctype_header = "";
164     $empty_element_end = ">";
167 my $ROOT_DIR = ".";
169 # All the files are written in subdirectories beneath here.
170 $TMPL_DIR = $TMPL_DIR ? $TMPL_DIR : "$ROOT_DIR/tmpl";
172 # This is where we put all the DocBook output.
173 $SGML_OUTPUT_DIR = $SGML_OUTPUT_DIR ? $SGML_OUTPUT_DIR : "$ROOT_DIR/$OUTPUT_FORMAT";
175 # This file contains the object hierarchy.
176 my $OBJECT_TREE_FILE = "$ROOT_DIR/$MODULE.hierarchy";
178 # This file contains the interfaces.
179 my $INTERFACES_FILE = "$ROOT_DIR/$MODULE.interfaces";
181 # This file contains the prerequisites.
182 my $PREREQUISITES_FILE = "$ROOT_DIR/$MODULE.prerequisites";
184 # This file contains signal arguments and names.
185 my $SIGNALS_FILE = "$ROOT_DIR/$MODULE.signals";
187 # The file containing Arg information.
188 my $ARGS_FILE = "$ROOT_DIR/$MODULE.args";
190 # These global arrays store information on signals. Each signal has an entry
191 # in each of these arrays at the same index, like a multi-dimensional array.
192 my @SignalObjects;      # The GtkObject which emits the signal.
193 my @SignalNames;        # The signal name.
194 my @SignalReturns;      # The return type.
195 my @SignalFlags;        # Flags for the signal
196 my @SignalPrototypes;   # The rest of the prototype of the signal handler.
198 # These global arrays store information on Args. Each Arg has an entry
199 # in each of these arrays at the same index, like a multi-dimensional array.
200 my @ArgObjects;         # The GtkObject which has the Arg.
201 my @ArgNames;           # The Arg name.
202 my @ArgTypes;           # The Arg type - gint, GtkArrowType etc.
203 my @ArgFlags;           # How the Arg can be used - readable/writable etc.
204 my @ArgNicks;           # The nickname of the Arg.
205 my @ArgBlurbs;          # Docstring of the Arg.
206 my @ArgDefaults;        # Default value of the Arg.
207 my @ArgRanges;          # The range of the Arg type
208 # These global hashes store declaration info keyed on a symbol name.
209 my %Declarations;
210 my %DeclarationTypes;
211 my %DeclarationConditional;
212 my %DeclarationOutput;
213 my %Deprecated;
214 my %Since;
215 my %StabilityLevel;
216 my %StructHasTypedef;
218 # These global hashes store the existing documentation.
219 my %SymbolDocs;
220 my %SymbolTypes;
221 my %SymbolParams;
222 my %SymbolSourceFile;
223 my %SymbolSourceLine;
225 # These global hashes store documentation scanned from the source files.
226 my %SourceSymbolDocs;
227 my %SourceSymbolParams;
228 my %SourceSymbolSourceFile;
229 my %SourceSymbolSourceLine;
231 # all documentation goes in here, so we can do coverage analysis
232 my %AllSymbols;
233 my %AllIncompleteSymbols;
234 my %AllDocumentedSymbols;
236 # Undeclared yet documented symbols
237 my %UndeclaredSymbols;
239 # These global arrays store GObject, subclasses and the hierarchy.
240 my @Objects;
241 my @ObjectLevels;
243 my %Interfaces;
244 my %Prerequisites;
246 # holds the symbols which are mentioned in $MODULE-sections.txt
247 my %KnownSymbols;
249 # collects index entries
250 my %IndexEntriesFull;
251 my %IndexEntriesSince;
252 my %IndexEntriesDeprecated;
254 # Standard C preprocessor directives, which we ignore for '#' abbreviations.
255 my %PreProcessorDirectives;
256 $PreProcessorDirectives{"assert"} = 1;
257 $PreProcessorDirectives{"define"} = 1;
258 $PreProcessorDirectives{"elif"} = 1;
259 $PreProcessorDirectives{"else"} = 1;
260 $PreProcessorDirectives{"endif"} = 1;
261 $PreProcessorDirectives{"error"} = 1;
262 $PreProcessorDirectives{"if"} = 1;
263 $PreProcessorDirectives{"ifdef"} = 1;
264 $PreProcessorDirectives{"ifndef"} = 1;
265 $PreProcessorDirectives{"include"} = 1;
266 $PreProcessorDirectives{"line"} = 1;
267 $PreProcessorDirectives{"pragma"} = 1;
268 $PreProcessorDirectives{"unassert"} = 1;
269 $PreProcessorDirectives{"undef"} = 1;
270 $PreProcessorDirectives{"warning"} = 1;
272 # remember used annotation (to write minimal glossary)
273 my %AnnotationsUsed;
275 my %AnnotationDefinition = (
276     'allow-none' => "NULL is ok, both for passing and for returning.",
277     'array' => "Parameter points to an array of items.",
278     'default' => "Default parameter value (for in case the <acronym>shadows</acronym>-to function has less parameters).",
279     'element-type' => "Generics and defining elements of containers and arrays.",
280     'error-domains' => "Typed errors. Similar to throws in Java.",
281     'in' => "Parameter for input. Default is <acronym>transfer none</acronym>.",
282     'inout' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
283     'in-out' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
284     'not-error' => "A GError parameter is not to be handled like a normal GError.",
285     'out' => "Parameter for returning results. Default is <acronym>transfer full</acronym>.",
286     'transfer container' => "Free data container after the code is done.",
287     'transfer full' => "Free data after the code is done.",
288     'transfer none' => "Don't free data after the code is done."
291 # Create the root DocBook output directory if it doens't exist.
292 if (! -e $SGML_OUTPUT_DIR) {
293     mkdir ("$SGML_OUTPUT_DIR", 0777)
294         || die "Can't create directory: $SGML_OUTPUT_DIR";
297 # Function and other declaration output settings.
298 my $RETURN_TYPE_FIELD_WIDTH = 20;
299 my $SYMBOL_FIELD_WIDTH = 36;
300 my $SIGNAL_FIELD_WIDTH = 16;
301 my $PARAM_FIELD_COUNT = 2;
303 &ReadKnownSymbols ("$ROOT_DIR/$MODULE-sections.txt");
304 &ReadSignalsFile ($SIGNALS_FILE);
305 &ReadArgsFile ($ARGS_FILE);
306 &ReadObjectHierarchy;
307 &ReadInterfaces;
308 &ReadPrerequisites;
310 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-decl.txt", 0);
311 if (-f "$ROOT_DIR/$MODULE-overrides.txt") {
312     &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-overrides.txt", 1);
315 for my $dir (@SOURCE_DIRS) {
316     &ReadSourceDocumentation ($dir);
319 my $changed = &OutputSGML ("$ROOT_DIR/$MODULE-sections.txt");
321 # If any of the DocBook SGML files have changed, update the timestamp file (so
322 # it can be used for Makefile dependencies).
323 if ($changed || ! -e "$ROOT_DIR/sgml.stamp") {
325     # try to detect the common prefix
326     # GtkWidget, GTK_WIDGET, gtk_widget -> gtk
327     if ($NAME_SPACE eq "") {
328         $NAME_SPACE="";
329         my $pos=0;
330         my $ratio=0.0;
331         do {
332             my %prefix;
333             my $letter="";
334             foreach my $symbol (keys(%IndexEntriesFull)) {
335                 if(($NAME_SPACE eq "") || $symbol =~ /^$NAME_SPACE/i) {
336                     if (length($symbol)>$pos) {
337                         $letter=substr($symbol,$pos,1);
338                         # stop prefix scanning
339                         if ($letter eq "_") {
340                             # stop on "_"
341                             last;
342                         }
343                         # Should we also stop on a uppercase char, if last was lowercase
344                         #   GtkWidget, if we have the 'W' and had the 't' before
345                         # or should we count upper and lowercase, and stop one 2nd uppercase, if we already had a lowercase
346                         #   GtkWidget, the 'W' would be the 2nd uppercase and with 't','k' we had lowercase chars before
347                         # need to recound each time as this is per symbol
348                         $prefix{uc($letter)}++;
349                     }
350                 }
351             }
352             if ($letter ne "" && $letter ne "_") {
353                 my $maxletter="";
354                 my $maxsymbols=0;
355                 foreach $letter (keys(%prefix)) {
356                     #print "$letter: $prefix{$letter}.\n";
357                     if ($prefix{$letter}>$maxsymbols) {
358                         $maxletter=$letter;
359                         $maxsymbols=$prefix{$letter};
360                     }
361                 }
362                 $ratio = scalar(keys(%IndexEntriesFull)) / $prefix{$maxletter};
363                 #print "most symbols start with $maxletter, that is ". (100 * $ratio) ." %\n";
364                 if ($ratio > 0.9) {
365                     # do another round
366                     $NAME_SPACE .= $maxletter;
367                 }
368                 $pos++;
369             }
370             else {
371                 $ratio=0.0;
372             }
373         } while ($ratio > 0.9);
374         #print "most symbols start with $NAME_SPACE\n";
375     }
377     &OutputIndexFull;
378     &OutputDeprecatedIndex;
379     &OutputSinceIndexes;
380     &OutputAnnotationGlossary;
382     open (TIMESTAMP, ">$ROOT_DIR/sgml.stamp")
383         || die "Can't create $ROOT_DIR/sgml.stamp: $!";
384     print (TIMESTAMP "timestamp");
385     close (TIMESTAMP);
388 #############################################################################
389 # Function    : OutputObjectList
390 # Description : This outputs the alphabetical list of objects, in a columned
391 #               table.
392 #               FIXME: Currently this also outputs ancestor objects
393 #               which may not actually be in this module.
394 # Arguments   : none
395 #############################################################################
397 sub OutputObjectList {
398     my $cols = 3;
399     
400     # FIXME: use $OUTPUT_FORMAT
401     # my $old_object_index = "$SGML_OUTPUT_DIR/object_index.$OUTPUT_FORMAT";
402     my $old_object_index = "$SGML_OUTPUT_DIR/object_index.sgml";
403     my $new_object_index = "$SGML_OUTPUT_DIR/object_index.new";
405     open (OUTPUT, ">$new_object_index")
406         || die "Can't create $new_object_index: $!";
408     if (lc($OUTPUT_FORMAT) eq "xml") {
409         my $header = $doctype_header;
411         $header =~ s/<!DOCTYPE \w+/<!DOCTYPE informaltable/;
412         print (OUTPUT "$header");
413     }
415     print (OUTPUT <<EOF);
416 <informaltable pgwide="1" frame="none">
417 <tgroup cols="$cols">
418 <colspec colwidth="1*"${empty_element_end}
419 <colspec colwidth="1*"${empty_element_end}
420 <colspec colwidth="1*"${empty_element_end}
421 <tbody>
424     my $count = 0;
425     my $object;
426     foreach $object (sort (@Objects)) {
427         my $xref = &MakeXRef ($object);
428         if ($count % $cols == 0) { print (OUTPUT "<row>\n"); }
429         print (OUTPUT "<entry>$xref</entry>\n");
430         if ($count % $cols == ($cols - 1)) { print (OUTPUT "</row>\n"); }
431         $count++;
432     }
433     if ($count == 0) {
434         # emit an empty row, since empty tables are invalid
435         print (OUTPUT "<row><entry> </entry></row>\n");
436     }
437     else {
438         print (OUTPUT "</row>\n");
439     }
441     print (OUTPUT <<EOF);
442 </tbody></tgroup></informaltable>
444     close (OUTPUT);
446     &UpdateFileIfChanged ($old_object_index, $new_object_index, 0);
450 #############################################################################
451 # Function    : OutputSGML
452 # Description : This collects the output for each section of the docs, and
453 #               outputs each file when the end of the section is found.
454 # Arguments   : $file - the $MODULE-sections.txt file which contains all of
455 #               the functions/macros/structs etc. being documented, organised
456 #               into sections and subsections.
457 #############################################################################
459 sub OutputSGML {
460     my ($file) = @_;
462     #print "Reading: $file\n";
463     open (INPUT, $file)
464         || die "Can't open $file: $!";
465     my $filename = "";
466     my $book_top = "";
467     my $book_bottom = "";
468     my $includes = (defined $DEFAULT_INCLUDES) ? $DEFAULT_INCLUDES : "";
469     my $section_includes = "";
470     my $in_section = 0;
471     my $title = "";
472     my $subsection = "";
473     my $synopsis;
474     my $details;
475     my $num_symbols;
476     my $changed = 0;
477     my $signals_synop = "";
478     my $signals_desc = "";
479     my $args_synop = "";
480     my $child_args_synop = "";
481     my $style_args_synop = "";
482     my $args_desc = "";
483     my $child_args_desc = "";
484     my $style_args_desc = "";
485     my $hierarchy = "";
486     my $interfaces = "";
487     my $implementations = "";
488     my $prerequisites = "";
489     my $derived = "";
490     my @file_objects = ();
491     my %templates = ();
492     my %symbols = ();
494     # merge the source docs, in case there are no templates
495     &MergeSourceDocumentation;
497     while (<INPUT>) {
498         if (m/^#/) {
499             next;
501         } elsif (m/^<SECTION>/) {
502             $synopsis = "";
503             $details = "";
504             $num_symbols = 0;
505             $in_section = 1;
506             @file_objects = ();
507             %symbols = ();
509         } elsif (m/^<SUBSECTION\s*(.*)>/i) {
510             $synopsis .= "\n";
511             $subsection = $1;
513         } elsif (m/^<SUBSECTION>/) {
515         } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
516             $title = $1;
517             #print "Section: $title\n";
519             # We don't want warnings if object & class structs aren't used.
520             $DeclarationOutput{$title} = 1;
521             $DeclarationOutput{"${title}Class"} = 1;
522             $DeclarationOutput{"${title}Iface"} = 1;
523             $DeclarationOutput{"${title}Interface"} = 1;
525         } elsif (m/^<FILE>(.*)<\/FILE>/) {
526             $filename = $1;
527             if (! defined $templates{$filename}) {
528                if (&ReadTemplateFile ("$TMPL_DIR/$filename", 1)) {
529                    &MergeSourceDocumentation;
530                    $templates{$filename}=$.;
531                }
532             } else {
533                 &LogWarning ($file, $., "Double <FILE>$filename</FILE> entry. ".
534                     "Previous occurrence on line ".$templates{$filename}.".");
535             }
537         } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
538             if ($in_section) {
539                 $section_includes = $1;
540             } else {
541                 if (defined $DEFAULT_INCLUDES) {
542                     &LogWarning ($file, $., "Default <INCLUDE> being overridden by command line option.");
543                 }
544                 else {
545                     $includes = $1;
546                 }
547             }
549         } elsif (m/^<\/SECTION>/) {
550             if($title eq "" && $filename eq "") {
551                 &LogWarning ($file, $., "Section has no title and no file.");
552             }
553             # FIXME: one of those would be enough
554             if ($title eq "") {
555                 $title = $filename;
556             }
557             if ($filename eq "") {
558                 $filename = $title;
559             }
560             #print "End of section: $title\n";
562             $filename =~ s/\s/_/g;
564             my $section_id = $SourceSymbolDocs{"$TMPL_DIR/$filename:Section_Id"};
565             if (defined ($section_id) && $section_id !~ m/^\s*$/) {
566                 # Do nothing. Use section_id as it is.
567             } elsif (&CheckIsObject ($title)) {
568                 # GtkObjects use their class name as the ID.
569                 $section_id = &CreateValidSGMLID ($title);
570             } else {
571                 $section_id = &CreateValidSGMLID ("$MODULE-$title");
572             }
574             if ($num_symbols > 0) {
575                 # collect documents
576                 if (lc($OUTPUT_FORMAT) eq "xml") {
577                     $book_bottom .= "    <xi:include href=\"xml/$filename.xml\"/>\n";
578                 } else {
579                     $book_top.="<!ENTITY $section_id SYSTEM \"sgml/$filename.sgml\">\n";
580                     $book_bottom .= "    &$section_id;\n";
581                 }
583                 if (defined ($SourceSymbolDocs{"$TMPL_DIR/$filename:Include"})) {
584                     if ($section_includes) {
585                         &LogWarning ($file, $., "Section <INCLUDE> being overridden by inline comments.");
586                     }
587                     $section_includes = $SourceSymbolDocs{"$TMPL_DIR/$filename:Include"};
588                 }
589                 if ($section_includes eq "") {
590                     $section_includes = $includes;
591                 }
593                  $signals_synop =~ s/^\n*//g;
594                  $signals_synop =~ s/\n+$/\n/g;
595                 if ($signals_synop ne '') {
596                     $signals_synop = <<EOF;
597 <refsect1 id="$section_id.signals" role="signal_proto">
598 <title role="signal_proto.title">Signals</title>
599 <synopsis>
600 ${signals_synop}</synopsis>
601 </refsect1>
603                      $signals_desc =~ s/^\n*//g;
604                      $signals_desc =~ s/\n+$/\n/g;
605                      $signals_desc =~ s/(\s|\n)+$//ms;
606                     $signals_desc  = <<EOF;
607 <refsect1 id="$section_id.signal-details" role="signals">
608 <title role="signals.title">Signal Details</title>
609 $signals_desc
610 </refsect1>
612                 }
614                  $args_synop =~ s/^\n*//g;
615                  $args_synop =~ s/\n+$/\n/g;
616                 if ($args_synop ne '') {
617                     $args_synop = <<EOF;
618 <refsect1 id="$section_id.properties" role="properties">
619 <title role="properties.title">Properties</title>
620 <synopsis>
621 ${args_synop}</synopsis>
622 </refsect1>
624                      $args_desc =~ s/^\n*//g;
625                      $args_desc =~ s/\n+$/\n/g;
626                      $args_desc =~ s/(\s|\n)+$//ms;
627                     $args_desc  = <<EOF;
628 <refsect1 id="$section_id.property-details" role="property_details">
629 <title role="property_details.title">Property Details</title>
630 $args_desc
631 </refsect1>
633                 }
635                  $child_args_synop =~ s/^\n*//g;
636                  $child_args_synop =~ s/\n+$/\n/g;
637                 if ($child_args_synop ne '') {
638                     $args_synop .= <<EOF;
639 <refsect1 id="$section_id.child-properties" role="child_properties">
640 <title role="child_properties.title">Child Properties</title>
641 <synopsis>
642 ${child_args_synop}</synopsis>
643 </refsect1>
645                      $child_args_desc =~ s/^\n*//g;
646                      $child_args_desc =~ s/\n+$/\n/g;
647                      $child_args_desc =~ s/(\s|\n)+$//ms;
648                     $args_desc .= <<EOF;
649 <refsect1 id="$section_id.child-property-details" role="child_property_details">
650 <title role="child_property_details.title">Child Property Details</title>
651 $child_args_desc
652 </refsect1>
654                 }
656                  $style_args_synop =~ s/^\n*//g;
657                  $style_args_synop =~ s/\n+$/\n/g;
658                 if ($style_args_synop ne '') {
659                     $args_synop .= <<EOF;
660 <refsect1 id="$section_id.style-properties" role="style_properties">
661 <title role="style_properties.title">Style Properties</title>
662 <synopsis>
663 ${style_args_synop}</synopsis>
664 </refsect1>
666                      $style_args_desc =~ s/^\n*//g;
667                      $style_args_desc =~ s/\n+$/\n/g;
668                      $style_args_desc =~ s/(\s|\n)+$//ms;
669                     $args_desc .= <<EOF;
670 <refsect1 id="$section_id.style-property-details" role="style_properties_details">
671 <title role="style_properties_details.title">Style Property Details</title>
672 $style_args_desc
673 </refsect1>
675                 }
677                  $hierarchy =~ s/^\n*//g;
678                  $hierarchy =~ s/\n+$/\n/g;
679                  $hierarchy =~ s/(\s|\n)+$//ms;
680                 if ($hierarchy ne "") {
681                     $hierarchy = <<EOF;
682 <refsect1 id="$section_id.object-hierarchy" role="object_hierarchy">
683 <title role="object_hierarchy.title">Object Hierarchy</title>
684 $hierarchy
685 </refsect1>
687                 }
689                  $interfaces =~ s/^\n*//g;
690                  $interfaces =~ s/\n+$/\n/g;
691                  $interfaces =~ s/(\s|\n)+$//ms;
692                 if ($interfaces ne "") {
693                     $interfaces = <<EOF;
694 <refsect1 id="$section_id.implemented-interfaces" role="impl_interfaces">
695 <title role="impl_interfaces.title">Implemented Interfaces</title>
696 $interfaces
697 </refsect1>
699                 }
701                  $implementations =~ s/^\n*//g;
702                  $implementations =~ s/\n+$/\n/g;
703                  $implementations =~ s/(\s|\n)+$//ms;
704                 if ($implementations ne "") {
705                     $implementations = <<EOF;
706 <refsect1 id="$section_id.implementations" role="implementations">
707 <title role="implementations.title">Known Implementations</title>
708 $implementations
709 </refsect1>
711                 }
713                  $prerequisites =~ s/^\n*//g;
714                  $prerequisites =~ s/\n+$/\n/g;
715                  $prerequisites =~ s/(\s|\n)+$//ms;
716                 if ($prerequisites ne "") {
717                     $prerequisites = <<EOF;
718 <refsect1 id="$section_id.prerequisites" role="prerequisites">
719 <title role="prerequisites.title">Prerequisites</title>
720 $prerequisites
721 </refsect1>
723                 }
725                  $derived =~ s/^\n*//g;
726                  $derived =~ s/\n+$/\n/g;
727                  $derived =~ s/(\s|\n)+$//ms;
728                 if ($derived ne "") {
729                     $derived = <<EOF;
730 <refsect1 id="$section_id.derived-interfaces" role="derived_interfaces">
731 <title role="derived_interfaces.title">Known Derived Interfaces</title>
732 $derived
733 </refsect1>
735                 }
737                 $synopsis =~ s/^\n*//g;
738                 $synopsis =~ s/\n+$/\n/g;
739                 my $file_changed = &OutputSGMLFile ($filename, $title, $section_id,
740                                                     $section_includes,
741                                                     \$synopsis, \$details,
742                                                     \$signals_synop, \$signals_desc,
743                                                     \$args_synop, \$args_desc,
744                                                     \$hierarchy, \$interfaces,
745                                                     \$implementations,
746                                                     \$prerequisites, \$derived,
747                                                     \@file_objects);
748                 if ($file_changed) {
749                     $changed = 1;
750                 }
751             }
752             $title = "";
753             $subsection = "";
754             $in_section = 0;
755             $section_includes = "";
756             $signals_synop = "";
757             $signals_desc = "";
758             $args_synop = "";
759             $child_args_synop = "";
760             $style_args_synop = "";
761             $args_desc = "";
762             $child_args_desc = "";
763             $style_args_desc = "";
764             $hierarchy = "";
765             $interfaces = "";
766             $implementations = "";
767             $prerequisites = "";
768             $derived = "";
770         } elsif (m/^(\S+)/) {
771             my $symbol = $1;
772             #print "  Symbol: $symbol\n";
774             # FIXME: check for duplicate entries
775             if (! defined $symbols{$symbol}) {
776                 my $declaration = $Declarations{$symbol};
777                 if (defined ($declaration)) {
778                     # We don't want standard macros/functions of GtkObjects,
779                     # or private declarations.
780                     if ($subsection ne "Standard" && $subsection ne "Private") {
781                         if (&CheckIsObject ($symbol)) {
782                             push @file_objects, $symbol;
783                         }
784                         my ($synop, $desc) = &OutputDeclaration ($symbol,
785                                                                  $declaration);
786                         my ($sig_synop, $sig_desc) = &GetSignals ($symbol);
787                         my ($arg_synop, $child_arg_synop, $style_arg_synop,
788                             $arg_desc, $child_arg_desc, $style_arg_desc) = &GetArgs ($symbol);
789                         my $hier = &GetHierarchy ($symbol);
790                         my $ifaces = &GetInterfaces ($symbol);
791                         my $impls = &GetImplementations ($symbol);
792                         my $prereqs = &GetPrerequisites ($symbol);
793                         my $der = &GetDerived ($symbol);
794                         $synopsis .= $synop;
795                         $details .= $desc;
796                         $signals_synop .= $sig_synop;
797                         $signals_desc .= $sig_desc;
798                         $args_synop .= $arg_synop;
799                         $child_args_synop .= $child_arg_synop;
800                         $style_args_synop .= $style_arg_synop;
801                         $args_desc .= $arg_desc;
802                         $child_args_desc .= $child_arg_desc;
803                         $style_args_desc .= $style_arg_desc;
804                         $hierarchy .= $hier;
805                         $interfaces .= $ifaces;
806                         $implementations .= $impls;
807                         $prerequisites .= $prereqs;
808                         $derived .= $der;
809                     }
810     
811                     # Note that the declaration has been output.
812                     $DeclarationOutput{$symbol} = 1;
813                 } elsif ($subsection ne "Standard" && $subsection ne "Private") {
814                     $UndeclaredSymbols{$symbol} = 1;
815                     &LogWarning ($file, $., "No declaration found for $symbol.");
816                 }
817                 $num_symbols++;
818                 $symbols{$symbol}=$.;
819             }
820             else {
821                 &LogWarning ($file, $., "Double symbol entry for $symbol. ".
822                     "Previous occurrence on line ".$symbols{$symbol}.".");
823             }
824         }
825     }
826     close (INPUT);
828     &OutputMissingDocumentation;
829     &OutputUndeclaredSymbols;
831     if ($OUTPUT_ALL_SYMBOLS) {
832         &OutputAllSymbols;
833     }
834     if ($OUTPUT_SYMBOLS_WITHOUT_SINCE) {
835         &OutputSymbolsWithoutSince;
836     }
838     for $filename (split (' ', $EXPAND_CONTENT_FILES)) {
839         my $file_changed = &OutputExtraFile ($filename);
840         if ($file_changed) {
841             $changed = 1;
842         }
843     }
845     &OutputBook ($book_top, $book_bottom);
847     return $changed;
850 #############################################################################
851 # Function    : OutputIndex
852 # Description : This writes an indexlist that can be included into the main-
853 #               document into an <index> tag.
854 #############################################################################
856 sub OutputIndex {
857     my ($basename, $apiindexref ) = @_;
858     my %apiindex = %{$apiindexref};
859     my $old_index = "$SGML_OUTPUT_DIR/$basename.xml";
860     my $new_index = "$SGML_OUTPUT_DIR/$basename.new";
861     my $lastletter = " ";
862     my $divopen = 0;
863     my $symbol;
864     my $short_symbol;
866     open (OUTPUT, ">$new_index")
867         || die "Can't create $new_index";
869     my $header = $doctype_header;
870     $header =~ s/<!DOCTYPE \w+/<!DOCTYPE indexdiv/;
872     print (OUTPUT "$header<indexdiv>\n");
874     #print "generate $basename index (".%apiindex." entries)\n";
875     
876     # do a case insensitive sort while chopping off the prefix
877     foreach my $hash (
878         sort { $$a{criteria} cmp $$b{criteria} }
879         map { my $x = uc($_); $x =~ s/^$NAME_SPACE\_?(.*)/$1/i; { criteria => $x, original => $_, short => $1 } } 
880         keys %apiindex) {
882         $symbol = $$hash{original};
883         if(defined($$hash{short})) {
884             $short_symbol = $$hash{short};
885         } else {
886             $short_symbol = $symbol;
887         }
889         my $curletter = uc(substr($short_symbol,0,1));
890         my $id = $apiindex{$symbol};
892         #print "  add symbol $symbol with $id to index in section $curletter\n";
894         if ($curletter ne $lastletter) {
895             $lastletter = $curletter;
897             if ($divopen == 1) {
898                 print (OUTPUT "</indexdiv>\n");
899             }
900             print (OUTPUT "<indexdiv><title>$curletter</title>\n");
901             $divopen = 1;
902         }
904         print (OUTPUT <<EOF);
905 <indexentry><primaryie linkends="$id"><link linkend="$id">$symbol</link></primaryie></indexentry>
907     }
909     if ($divopen == 1) {
910         print (OUTPUT "</indexdiv>\n");
911     }
912     print (OUTPUT "</indexdiv>\n");
913     close (OUTPUT);
915     &UpdateFileIfChanged ($old_index, $new_index, 0);
919 #############################################################################
920 # Function    : OutputIndexFull
921 # Description : This writes the full api indexlist that can be included into the
922 #               main document into an <index> tag.
923 #############################################################################
925 sub OutputIndexFull {
926     &OutputIndex ("api-index-full", \%IndexEntriesFull);
930 #############################################################################
931 # Function    : OutputDeprecatedIndex
932 # Description : This writes the deprecated api indexlist that can be included
933 #               into the main document into an <index> tag.
934 #############################################################################
936 sub OutputDeprecatedIndex {
937     &OutputIndex ("api-index-deprecated", \%IndexEntriesDeprecated);
941 #############################################################################
942 # Function    : OutputSinceIndexes
943 # Description : This writes the 'since' api indexlists that can be included into
944 #               the main document into an <index> tag.
945 #############################################################################
947 sub OutputSinceIndexes {
948     my @sinces = keys %{{ map { $_ => 1 } values %Since }};
950     foreach my $version (@sinces) {
951         #print "Since : [$version]\n";
952         # todo make filtered hash
953         #my %index = grep { $Since{$_} eq $version } %IndexEntriesSince;
954         my %index = map { $_ => $IndexEntriesSince{$_} } grep { $Since{$_} eq $version } keys %IndexEntriesSince;
956         &OutputIndex ("api-index-$version", \%index);
957     }
960 #############################################################################
961 # Function    : OutputAnnotationGlossary
962 # Description : This writes a glossary of the used annotation terms into a
963 #               separate glossary file that can be included into the main
964 #               document.
965 #############################################################################
967 sub OutputAnnotationGlossary {
968     my $old_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.xml";
969     my $new_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.new";
970     my $lastletter = " ";
971     my $divopen = 0;
973     # TODO: if there are no annotations used return
974     return if (! keys(%AnnotationsUsed));
976     open (OUTPUT, ">$new_glossary")
977         || die "Can't create $new_glossary";
979     my $header = $doctype_header;
980     $header =~ s/<!DOCTYPE \w+/<!DOCTYPE glossary/;
982     print (OUTPUT  <<EOF);
983 $header
984 <glossary id="annotation-glossary">
985   <title>Annotation Glossary</title>
988     foreach my $annotation (keys(%AnnotationsUsed)) {
989         my $def = $AnnotationDefinition{$annotation};
990         my $curletter = uc(substr($annotation,0,1));
992         if ($curletter ne $lastletter) {
993             $lastletter = $curletter;
994       
995             if ($divopen == 1) {
996                 print (OUTPUT "</glossdiv>\n");
997             }
998             print (OUTPUT "<glossdiv><title>$curletter</title>\n");
999             $divopen = 1;
1000         }
1001         print (OUTPUT <<EOF);
1002     <glossentry>
1003       <glossterm><anchor id="annotation-glossterm-$annotation"/>$annotation</glossterm>
1004       <glossdef>
1005         <para>$def</para>
1006       </glossdef>
1007     </glossentry>
1009     }
1011     if ($divopen == 1) {
1012         print (OUTPUT "</glossdiv>\n");
1013     }
1014     print (OUTPUT "</glossary>\n");
1015     close (OUTPUT);
1017     &UpdateFileIfChanged ($old_glossary, $new_glossary, 0);
1020 #############################################################################
1021 # Function    : ReadKnownSymbols
1022 # Description : This collects the names of non-private symbols from the
1023 #               $MODULE-sections.txt file.
1024 # Arguments   : $file - the $MODULE-sections.txt file which contains all of
1025 #               the functions/macros/structs etc. being documented, organised
1026 #               into sections and subsections.
1027 #############################################################################
1029 sub ReadKnownSymbols {
1030     my ($file) = @_;
1032     my $subsection = "";
1034     #print "Reading: $file\n";
1035     open (INPUT, $file)
1036         || die "Can't open $file: $!";
1038     while (<INPUT>) {
1039         if (m/^#/) {
1040             next;
1042         } elsif (m/^<SECTION>/) {
1043             $subsection = "";
1045         } elsif (m/^<SUBSECTION\s*(.*)>/i) {
1046             $subsection = $1;
1048         } elsif (m/^<SUBSECTION>/) {
1049             next;
1051         } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
1052             next;
1054         } elsif (m/^<FILE>(.*)<\/FILE>/) {
1055             $KnownSymbols{"$TMPL_DIR/$1:Long_Description"} = 1;
1056             $KnownSymbols{"$TMPL_DIR/$1:Short_Description"} = 1;
1057             next;
1059         } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
1060             next;
1062         } elsif (m/^<\/SECTION>/) {
1063             next;
1065         } elsif (m/^(\S+)/) {
1066             my $symbol = $1;
1068             if ($subsection ne "Standard" && $subsection ne "Private") {
1069                 $KnownSymbols{$symbol} = 1;
1070             }
1071             else {
1072                 $KnownSymbols{$symbol} = 0;
1073             }
1074         }
1075     }
1076     close (INPUT);
1080 #############################################################################
1081 # Function    : OutputDeclaration
1082 # Description : Returns the synopsis and detailed description DocBook
1083 #               describing one function/macro etc.
1084 # Arguments   : $symbol - the name of the function/macro begin described.
1085 #               $declaration - the declaration of the function/macro.
1086 #############################################################################
1088 sub OutputDeclaration {
1089     my ($symbol, $declaration) = @_;
1091     my $type = $DeclarationTypes {$symbol};
1092     if ($type eq 'MACRO') {
1093         return &OutputMacro ($symbol, $declaration);
1094     } elsif ($type eq 'TYPEDEF') {
1095         return &OutputTypedef ($symbol, $declaration);
1096     } elsif ($type eq 'STRUCT') {
1097         return &OutputStruct ($symbol, $declaration);
1098     } elsif ($type eq 'ENUM') {
1099         return &OutputEnum ($symbol, $declaration);
1100     } elsif ($type eq 'UNION') {
1101         return &OutputUnion ($symbol, $declaration);
1102     } elsif ($type eq 'VARIABLE') {
1103         return &OutputVariable ($symbol, $declaration);
1105     } elsif ($type eq 'FUNCTION') {
1106         return &OutputFunction ($symbol, $declaration, $type);
1107     } elsif ($type eq 'USER_FUNCTION') {
1108         return &OutputFunction ($symbol, $declaration, $type);
1109     } else {
1110         die "Unknown symbol type";
1111     }
1115 #############################################################################
1116 # Function    : OutputSymbolTraits
1117 # Description : Returns the Since and StabilityLevel paragraphs for a symbol.
1118 # Arguments   : $symbol - the name of the function/macro begin described.
1119 #############################################################################
1121 sub OutputSymbolTraits {
1122     my ($symbol) = @_;
1123     my $desc = "";
1125     if (exists $Since{$symbol}) {
1126         $desc .= "<para role=\"since\">Since $Since{$symbol}</para>";
1127     }
1128     if (exists $StabilityLevel{$symbol}) {
1129         $desc .= "<para role=\"stability\">Stability Level: $StabilityLevel{$symbol}</para>";
1130     }
1131     return $desc;
1134 #############################################################################
1135 # Function    : Outpu{Symbol,Section}ExtraLinks
1136 # Description : Returns extralinks for the symbol (if enabled).
1137 # Arguments   : $symbol - the name of the function/macro begin described.
1138 #############################################################################
1140 sub uri_escape {
1141     my $text = $_[0];
1142     return undef unless defined $text;
1144     # Build a char to hex map
1145     my %escapes = ();
1146     for (0..255) {
1147             $escapes{chr($_)} = sprintf("%%%02X", $_);
1148     }
1150     # Default unsafe characters.  RFC 2732 ^(uric - reserved)
1151     $text =~ s/([^A-Za-z0-9\-_.!~*'()])/$escapes{$1}/g;
1153     return $text;
1156 sub OutputSymbolExtraLinks {
1157     my ($symbol) = @_;
1158     my $desc = "";
1160     if (0) { # NEW FEATURE: needs configurability
1161     my $sstr = &uri_escape($symbol);
1162     my $mstr = &uri_escape($MODULE);
1163     $desc .= <<EOF;
1164 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1165 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&amp;symbol=$sstr">edit documentation</ulink>
1167     }
1168     return $desc;
1171 sub OutputSectionExtraLinks {
1172     my ($symbol,$docsymbol) = @_;
1173     my $desc = "";
1175     if (0) { # NEW FEATURE: needs configurability
1176     my $sstr = &uri_escape($symbol);
1177     my $mstr = &uri_escape($MODULE);
1178     my $dsstr = &uri_escape($docsymbol);
1179     $desc .= <<EOF;
1180 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1181 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&amp;symbol=$dsstr">edit documentation</ulink>
1183     }
1184     return $desc;
1188 #############################################################################
1189 # Function    : OutputMacro
1190 # Description : Returns the synopsis and detailed description of a macro.
1191 # Arguments   : $symbol - the macro.
1192 #               $declaration - the declaration of the macro.
1193 #############################################################################
1195 sub OutputMacro {
1196     my ($symbol, $declaration) = @_;
1197     my $id = &CreateValidSGMLID ($symbol);
1198     my $condition = &MakeConditionDescription ($symbol);
1199     my $synop = &MakeReturnField("#define") . "<link linkend=\"$id\">$symbol</link>";
1200     my $desc;
1201     my $padding = "";
1202     my $args = "";
1203     my $pad;
1205     if ($declaration =~ m/^\s*#\s*define(\s+)\w+(\([^\)]*\))/) {
1206         $padding = $1;
1207         $args = $2;
1209         if (length ($symbol) < $SYMBOL_FIELD_WIDTH) {
1210             $synop .= (' ' x ($SYMBOL_FIELD_WIDTH - length ($symbol)));
1211         }
1213         # Try to align all the lines of args correctly.
1214         $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH + $SYMBOL_FIELD_WIDTH + 1);
1215         my $args_padded = $args;
1216         $args_padded =~ s/ *\\\n */\n$pad/gm;
1217         $synop .= &CreateValidSGML ($args_padded);
1218     }
1219     $synop .= "\n";
1221     my $title = $symbol . ($args ? "()" : "");
1222     $desc = "<refsect2 id=\"$id\" role=\"macro\"$condition>\n<title>$title</title>\n";
1223     $desc .= MakeIndexterms($symbol, $id);
1224     $desc .= "\n";
1225     $desc .= OutputSymbolExtraLinks($symbol);
1227     # Don't output the macro definition if is is a conditional macro or it
1228     # looks like a function, i.e. starts with "g_" or "_?gnome_", or it is
1229     # longer than 2 lines, otherwise we get lots of complicated macros like
1230     # g_assert.
1231     if (!defined ($DeclarationConditional{$symbol}) && ($symbol !~ m/^g_/)
1232         && ($symbol !~ m/^_?gnome_/) && (($declaration =~ tr/\n//) < 2)) {
1233         my $decl_out = &CreateValidSGML ($declaration);
1234         $desc .= "<programlisting>$decl_out</programlisting>\n";
1235     } else {
1236         $desc .= "<programlisting>" . &MakeReturnField("#define") . "$symbol";
1237         # Align each line so that if should all line up OK.
1238         $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH - length ("#define "));
1239         $args =~ s/\n/\n$pad/gm;
1240         $desc .= &CreateValidSGML ($args);
1241         $desc .= "</programlisting>\n";
1242     }
1244     $desc .= &MakeDeprecationNote($symbol);
1246     my $parameters = &OutputParamDescriptions ("MACRO", $symbol);
1247     my $parameters_output = 0;
1249     if (defined ($SymbolDocs{$symbol})) {
1250         my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1252         # Try to insert the parameter table at the author's desired position.
1253         # Otherwise we need to tag it onto the end.
1254         if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1255           $parameters_output = 1;
1256         }
1257         $desc .= $symbol_docs;
1258     }
1260     if ($parameters_output == 0) {
1261         $desc .= $parameters;
1262     }
1264     $desc .= OutputSymbolTraits ($symbol);
1265     $desc .= "</refsect2>\n";
1266     return ($synop, $desc);
1270 #############################################################################
1271 # Function    : OutputTypedef
1272 # Description : Returns the synopsis and detailed description of a typedef.
1273 # Arguments   : $symbol - the typedef.
1274 #               $declaration - the declaration of the typedef,
1275 #                 e.g. 'typedef unsigned int guint;'
1276 #############################################################################
1278 sub OutputTypedef {
1279     my ($symbol, $declaration) = @_;
1280     my $id = &CreateValidSGMLID ($symbol);
1281     my $condition = &MakeConditionDescription ($symbol);
1282     my $synop = &MakeReturnField("typedef") . "<link linkend=\"$id\">$symbol</link>;\n";
1283     my $desc = "<refsect2 id=\"$id\" role=\"typedef\"$condition>\n<title>$symbol</title>\n";
1285     $desc .= MakeIndexterms($symbol, $id);
1286     $desc .= "\n";
1287     $desc .= OutputSymbolExtraLinks($symbol);
1289     if (!defined ($DeclarationConditional{$symbol})) {
1290         my $decl_out = &CreateValidSGML ($declaration);
1291         $desc .= "<programlisting>$decl_out</programlisting>\n";
1292     }
1294     $desc .= &MakeDeprecationNote($symbol);
1296     if (defined ($SymbolDocs{$symbol})) {
1297         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1298     }
1299     $desc .= OutputSymbolTraits ($symbol);
1300     $desc .= "</refsect2>\n";
1301     return ($synop, $desc);
1305 #############################################################################
1306 # Function    : OutputStruct
1307 # Description : Returns the synopsis and detailed description of a struct.
1308 #               We check if it is a widget struct, and if so we only output
1309 #               parts of it that are noted as public fields.
1310 #               We also use a different SGML ID for widget structs, since the
1311 #               original ID is used for the entire RefEntry.
1312 # Arguments   : $symbol - the struct.
1313 #               $declaration - the declaration of the struct.
1314 #############################################################################
1316 sub OutputStruct {
1317     my ($symbol, $declaration) = @_;
1319     my $is_widget_struct = 0;
1320     my $default_to_public = 1;
1321     if (&CheckIsObject ($symbol)) {
1322     #print "Found widget struct: $symbol\n";
1323     $is_widget_struct = 1;
1324         $default_to_public = 0;
1325     }
1327     my $id;
1328     my $condition;
1329     if ($is_widget_struct) {
1330         $id = &CreateValidSGMLID ($symbol . "_struct");
1331         $condition = &MakeConditionDescription ($symbol . "_struct");
1332     } else {
1333         $id = &CreateValidSGMLID ($symbol);
1334         $condition = &MakeConditionDescription ($symbol);
1335     }
1337     # Determine if it is a simple struct or it also has a typedef.
1338     my $has_typedef = 0;
1339     if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1340       $has_typedef = 1;
1341     }
1343     my $synop;
1344     my $desc;
1345     if ($has_typedef) {
1346         # For structs with typedefs we just output the struct name.
1347         $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1348         $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>$symbol</title>\n";
1349     } else {
1350         $synop = &MakeReturnField("struct") . "<link linkend=\"$id\">$symbol</link>;\n";
1351         $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>struct $symbol</title>\n";
1352     }
1354     $desc .= MakeIndexterms($symbol, $id);
1355     $desc .= "\n";
1356     $desc .= OutputSymbolExtraLinks($symbol);
1358     # Form a pretty-printed, private-data-removed form of the declaration
1360     my $decl_out = "";
1361     if ($declaration =~ m/^\s*$/) {
1362         #print "Found opaque struct: $symbol\n";
1363         $decl_out = "typedef struct _$symbol $symbol;";
1364     } elsif ($declaration =~ m/^\s*struct\s+\w+\s*;\s*$/) {
1365         #print "Found opaque struct: $symbol\n";
1366         $decl_out = "struct $symbol;";
1367     } else {
1368         my $public = $default_to_public;
1369         my $new_declaration = "";
1370         my $decl_line;
1371         my $decl = $declaration;
1373         if ($decl =~ m/^\s*(typedef\s+)?struct\s*\w*\s*(?:\/\*.*\*\/)?\s*{(.*)}\s*\w*\s*;\s*$/s) {
1374             my $struct_contents = $2;
1376             foreach $decl_line (split (/\n/, $struct_contents)) {
1377                 #print "Struct line: $decl_line\n";
1378                 if ($decl_line =~ m%/\*\s*<\s*public\s*>\s*\*/%) {
1379                     $public = 1;
1380                 } elsif ($decl_line =~ m%/\*\s*<\s*(private|protected)\s*>\s*\*/%) {
1381                     $public = 0;
1382                 } elsif ($public) {
1383                     $new_declaration .= $decl_line . "\n";
1384                 }
1385             }
1387             if ($new_declaration) {
1388                 # Strip any blank lines off the ends.
1389                 $new_declaration =~ s/^\s*\n//;
1390                 $new_declaration =~ s/\n\s*$/\n/;
1392                 if ($has_typedef) {
1393                     $decl_out = "typedef struct {\n" . $new_declaration
1394                       . "} $symbol;\n";
1395                 } else {
1396                     $decl_out = "struct $symbol {\n" . $new_declaration
1397                       . "};\n";
1398                 }
1399             }
1400         } else {
1401             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1402                 "Couldn't parse struct:\n$declaration");
1403         }
1405         # If we couldn't parse the struct or it was all private, output an
1406         # empty struct declaration.
1407         if ($decl_out eq "") {
1408             if ($has_typedef) {
1409                 $decl_out = "typedef struct _$symbol $symbol;";
1410             } else {
1411                 $decl_out = "struct $symbol;";
1412             }
1413         }
1414     }
1416     $decl_out = &CreateValidSGML ($decl_out);
1417     $desc .= "<programlisting>$decl_out</programlisting>\n";
1419     $desc .= &MakeDeprecationNote($symbol);
1421     if (defined ($SymbolDocs{$symbol})) {
1422         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1423     }
1425     # Create a table of fields and descriptions
1427     # FIXME: Inserting &#160's into the produced type declarations here would
1428     #        improve the output in most situations ... except for function
1429     #        members of structs!
1430     my @fields = ParseStructDeclaration($declaration, !$default_to_public,
1431                                         0, \&MakeXRef,
1432                                         sub {
1433                                             "<structfield id=\"$id.$_[0]\">$_[0]</structfield>";
1434                                         });
1435     my $params = $SymbolParams{$symbol};
1437     # If no parameters are filled in, we don't generate the description
1438     # table, for backwards compatibility
1440     my $found = 0;
1441     if (defined $params) {
1442         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1443             if ($params->[$i] =~ /\S/) {
1444                 $found = 1;
1445                 last;
1446             }
1447         }
1448     }
1450     if ($found) {
1451         my %field_descrs = @$params;
1453             $desc .= <<EOF;
1454 <variablelist role="struct">
1456         while (@fields) {
1457             my $field_name = shift @fields;
1458             my $text = shift @fields;
1459             my $field_descr = $field_descrs{$field_name};
1460             my $param_annotations = "";
1462             $desc .= "<varlistentry><term>$text</term>\n";
1463             if (defined $field_descr) {
1464                 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1465                 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1466                 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1467             } else {
1468                 $desc .= "<listitem><simpara /></listitem>\n";
1469             }
1470             $desc .= "</varlistentry>\n";
1471         }
1473         $desc .= "</variablelist>";
1474     }
1475     $desc .= OutputSymbolTraits ($symbol);
1476     $desc .= "</refsect2>\n";
1477     return ($synop, $desc);
1481 #############################################################################
1482 # Function    : OutputEnum
1483 # Description : Returns the synopsis and detailed description of a enum.
1484 # Arguments   : $symbol - the enum.
1485 #               $declaration - the declaration of the enum.
1486 #############################################################################
1488 sub OutputEnum {
1489     my ($symbol, $declaration) = @_;
1490     my $id = &CreateValidSGMLID ($symbol);
1491     my $condition = &MakeConditionDescription ($symbol);
1492     my $synop = &MakeReturnField("enum") . "<link linkend=\"$id\">$symbol</link>;\n";
1493     my $desc = "<refsect2 id=\"$id\" role=\"enum\"$condition>\n<title>enum $symbol</title>\n";
1495     $desc .= MakeIndexterms($symbol, $id);
1496     $desc .= "\n";
1497     $desc .= OutputSymbolExtraLinks($symbol);
1499     my $decl_out = &CreateValidSGML ($declaration);
1500     $desc .= "<programlisting>$decl_out</programlisting>\n";
1502     $desc .= &MakeDeprecationNote($symbol);
1504     if (defined ($SymbolDocs{$symbol})) {
1505         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1506     }
1508     # Create a table of fields and descriptions
1510     my @members = ParseEnumDeclaration($declaration);
1511     my $params = $SymbolParams{$symbol};
1513     # If no parameters are filled in, we don't generate the description
1514     # table, for backwards compatibility
1516     my $found = 0;
1517     if (defined $params) {
1518         for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1519             if ($params->[$i] =~ /\S/) {
1520                 $found = 1;
1521                 last;
1522             }
1523         }
1524     }
1526     if ($found) {
1527         my %member_descrs = @$params;
1529             $desc .= <<EOF;
1530 <variablelist role="enum">
1532         for my $member_name (@members) {
1533             my $member_descr = $member_descrs{$member_name};
1534             my $param_annotations = "";
1536             $id = &CreateValidSGMLID ($member_name);
1537             $condition = &MakeConditionDescription ($member_name);
1538             $desc .= "<varlistentry id=\"$id\" role=\"constant\"$condition>\n<term><literal>$member_name</literal></term>\n";
1539             if (defined $member_descr) {
1540                 ($member_descr,$param_annotations) = &ExpandAnnotation($symbol, $member_descr);
1541                 $member_descr = &ExpandAbbreviations($symbol, $member_descr);
1542                 $desc .= "<listitem><simpara>$member_descr$param_annotations</simpara></listitem>\n";
1543             } else {
1544                 $desc .= "<listitem></listitem>\n";
1545             }
1546             $desc .= "</varlistentry>\n";
1547         }
1549         $desc .= "</variablelist>";
1550     }
1552     $desc .= OutputSymbolTraits ($symbol);
1553     $desc .= "</refsect2>\n";
1554     return ($synop, $desc);
1558 #############################################################################
1559 # Function    : OutputUnion
1560 # Description : Returns the synopsis and detailed description of a union.
1561 # Arguments   : $symbol - the union.
1562 #               $declaration - the declaration of the union.
1563 #############################################################################
1565 sub OutputUnion {
1566     my ($symbol, $declaration) = @_;
1567     my $id = &CreateValidSGMLID ($symbol);
1568     my $condition = &MakeConditionDescription ($symbol);
1569     my $synop = &MakeReturnField("union") . "<link linkend=\"$id\">$symbol</link>;\n";
1570     my $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>union $symbol</title>\n";
1572     $desc .= MakeIndexterms($symbol, $id);
1573     $desc .= "\n";
1574     $desc .= OutputSymbolExtraLinks($symbol);
1576     my $decl_out = &CreateValidSGML ($declaration);
1577     $desc .= "<programlisting>$decl_out</programlisting>\n";
1579     $desc .= &MakeDeprecationNote($symbol);
1581     if (defined ($SymbolDocs{$symbol})) {
1582         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1583     }
1584     $desc .= OutputSymbolTraits ($symbol);
1585     $desc .= "</refsect2>\n";
1586     return ($synop, $desc);
1590 #############################################################################
1591 # Function    : OutputVariable
1592 # Description : Returns the synopsis and detailed description of a variable.
1593 # Arguments   : $symbol - the extern'ed variable.
1594 #               $declaration - the declaration of the variable.
1595 #############################################################################
1597 sub OutputVariable {
1598     my ($symbol, $declaration) = @_;
1599     my $id = &CreateValidSGMLID ($symbol);
1600     my $condition = &MakeConditionDescription ($symbol);
1602     my $synop;
1603     if ($declaration =~ m/^\s*extern\s+((const\s+|unsigned\s+)*\w+)(\s+\*+|\*+|\s)(\s*)([A-Za-z]\w*)\s*;/) {
1604         my $mod = defined ($1) ? $1 : "";
1605         my $ptr = defined ($3) ? $3 : "";
1606         my $space = defined ($4) ? $4 : "";
1607         $synop = &MakeReturnField("extern") . "$mod$ptr$space<link linkend=\"$id\">$symbol</link>;\n";
1609     } else {
1610         $synop = &MakeReturnField("extern") . "<link linkend=\"$id\">$symbol</link>;\n";
1611     }
1613     my $desc = "<refsect2 id=\"$id\" role=\"variable\"$condition>\n<title>$symbol</title>\n";
1615     $desc .= MakeIndexterms($symbol, $id);
1616     $desc .= "\n";
1617     $desc .= OutputSymbolExtraLinks($symbol);
1619     my $decl_out = &CreateValidSGML ($declaration);
1620     $desc .= "<programlisting>$decl_out</programlisting>\n";
1622     $desc .= &MakeDeprecationNote($symbol);
1624     if (defined ($SymbolDocs{$symbol})) {
1625         $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1626     }
1627     $desc .= OutputSymbolTraits ($symbol);
1628     $desc .= "</refsect2>\n";
1629     return ($synop, $desc);
1633 #############################################################################
1634 # Function    : OutputFunction
1635 # Description : Returns the synopsis and detailed description of a function.
1636 # Arguments   : $symbol - the function.
1637 #               $declaration - the declaration of the function.
1638 #############################################################################
1640 sub OutputFunction {
1641     my ($symbol, $declaration, $symbol_type) = @_;
1642     my $id = &CreateValidSGMLID ($symbol);
1643     my $condition = &MakeConditionDescription ($symbol);
1645     # Take out the return type     $1                                                                           $3   $4
1646     $declaration =~ s/<RETURNS>\s*((const\s+|G_CONST_RETURN\s+|unsigned\s+|long\s+|short\s+|struct\s+|enum\s+)*)(\w+)(\s*\**\s*(const|G_CONST_RETURN)?\s*\**\s*(restrict)?\s*)<\/RETURNS>\n//;
1647     my $type_modifier = defined($1) ? $1 : "";
1648     my $type = $3;
1649     my $pointer = $4;
1650     #print "$symbol pointer is $pointer\n";
1651     my $xref = &MakeXRef ($type);
1652     my $start = "";
1653     #if ($symbol_type eq 'USER_FUNCTION') {
1654     #    $start = "typedef ";
1655     #}
1657     # We output const rather than G_CONST_RETURN.
1658     $type_modifier =~ s/G_CONST_RETURN/const/g;
1659     $pointer =~ s/G_CONST_RETURN/const/g;
1660     $pointer =~ s/^\s+/ /g;
1662     my $ret_type_len = length ($start) + length ($type_modifier)
1663         + length ($pointer) + length ($type);
1664     my $ret_type_output;
1665     my $symbol_len;
1666     if ($ret_type_len < $RETURN_TYPE_FIELD_WIDTH) {
1667         $ret_type_output = "$start$type_modifier$xref$pointer"
1668             . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
1669         $symbol_len = 0;
1670     } else {
1671 #       $ret_type_output = "$start$type_modifier$xref$pointer\n"
1672 #           . (' ' x $RETURN_TYPE_FIELD_WIDTH);
1674         $ret_type_output = "$start$type_modifier$xref$pointer ";
1675         $symbol_len = $ret_type_len + 1 - $RETURN_TYPE_FIELD_WIDTH;
1676     }
1678     $symbol_len += length ($symbol);
1679     my $char1 = my $char2 = my $char3 = "";
1680     if ($symbol_type eq 'USER_FUNCTION') {
1681         $symbol_len += 3;
1682         $char1 = "(";
1683         $char2 = "*";
1684         $char3 = ")";
1685     }
1687     my ($symbol_output, $symbol_desc_output);
1688     if ($symbol_len < $SYMBOL_FIELD_WIDTH) {
1689         $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3"
1690             . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1691         $symbol_desc_output = "$char1$char2$symbol$char3"
1692             . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1693     } else {
1694         $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3\n"
1695             . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1696         $symbol_desc_output = "$char1$char2$symbol$char3\n"
1697             . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1698     }
1700     my $synop = $ret_type_output . $symbol_output . '(';
1701     my $desc = "<refsect2 id=\"$id\" role=\"function\"$condition>\n<title>${symbol} ()</title>\n";
1703     $desc .= MakeIndexterms($symbol, $id);
1704     $desc .= "\n";
1705     $desc .= OutputSymbolExtraLinks($symbol);
1707     $desc  .= "<programlisting>${ret_type_output}$symbol_desc_output(";
1709     my $param_num = 0;
1710     while ($declaration ne "") {
1711         #print "$declaration";
1713         if ($declaration =~ s/^[\s,]+//) {
1714             # skip whitespace and commas
1715             next;
1717         } elsif ($declaration =~ s/^void\s*[,\n]//) {
1718             $synop .= "void";
1719             $desc  .= "void";
1721         } elsif ($declaration =~ s/^...\s*[,\n]//) {
1722             if ($param_num == 0) {
1723                 $synop .= "...";
1724                 $desc  .= "...";
1725             } else {
1726                 $synop .= ",\n"
1727                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1728                     . " ...";
1729                 $desc  .= ",\n"
1730                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1731                     . " ...";
1732             }
1734         # allow alphanumerics, '_', '[' & ']' in param names
1735         # Try to match a standard parameter (keep in sync with gtkdoc-mktmpl)
1736         #                                $1                                                                                                                                    $2                             $3                                                           $4       $5
1737         } 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]//) {
1738             my $pre     = defined($1) ? $1 : "";
1739             my $type    = $2;
1740             my $ptr     = defined($3) ? $3 : "";
1741             my $name    = defined($4) ? $4 : "";
1742             my $array   = defined($5) ? $5 : "";
1744             $pre  =~ s/\s+/ /g;
1745             $type =~ s/\s+/ /g;
1746             $ptr  =~ s/\s+/ /g;
1747             $ptr  =~ s/\s+$//;
1748             if ($ptr && $ptr !~ m/\*$/) { $ptr .= " "; }
1750             #print "$symbol: '$pre' '$type' '$ptr' '$name' '$array'\n";
1752             if (($name eq "") && $pre =~ m/^((un)?signed .*)\s?/ ) {
1753                 $name = $type;
1754                 $type = "$1";
1755                 $pre = "";
1756             }
1758             my $xref = &MakeXRef ($type);
1759             my $label   = "$pre$xref $ptr$name$array";
1761             #print "$symbol: '$pre' '$type' '$ptr' '$name' '$array'\n";
1763             if ($param_num == 0) {
1764                 $synop .= "$label";
1765                 $desc  .= "$label";
1766             } else {
1767                 $synop .= ",\n"
1768                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1769                     . " $label";
1770                 $desc  .= ",\n"
1771                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1772                     . " $label";
1773             }
1775         # Try to match parameters which are functions (keep in sync with gtkdoc-mktmpl)
1776         #                              $1                                       $2          $3      $4                        $5                    $7             $8
1777         } 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]//) {
1778             my $mod1 = defined($1) ? $1 : "";
1779             if (defined($2)) { $mod1 .= $2; }
1780             my $type = $3;
1781             my $ptr1 = $4;
1782             my $mod2 = defined($5) ? $5 : "";
1783             my $func_ptr = $6;
1784             my $name = $7;
1785             my $func_params = defined($8) ? $8 : "";
1786             
1787             #if (!defined($type)) { print "## no type\n"; };
1788             #if (!defined($ptr1)) { print "## no ptr1\n"; };
1789             #if (!defined($func_ptr)) { print "## no func_ptr\n"; };
1790             #if (!defined($name)) { print "## no name\n"; };
1792             if ($ptr1 && $ptr1 !~ m/\*$/) { $ptr1 .= " "; }
1793             $func_ptr  =~ s/\s+//g;
1794             my $xref = &MakeXRef ($type);
1795             my $label = "$mod1$xref$ptr1$mod2 ($func_ptr$name) ($func_params)";
1797             #print "Type: [$mod1][$xref][$ptr1][$mod2] ([$func_ptr][$name]) ($func_params)\n";
1798             if ($param_num == 0) {
1799                 $synop .= "$label";
1800                 $desc  .= "$label";
1801             } else {
1802                 $synop .= ",\n"
1803                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1804                     . " $label";
1805                 $desc  .= ",\n"
1806                     . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1807                     . " $label";
1808             }
1810         } else {
1811             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1812                 "Can't parse args for function $symbol: $declaration");
1813             last;
1814         }
1815         $param_num++;
1816     }
1817     $synop .= ");\n";
1818     $desc  .= ");</programlisting>\n";
1820     $desc .= &MakeDeprecationNote($symbol);
1822     my $parameters = &OutputParamDescriptions ("FUNCTION", $symbol);
1823     my $parameters_output = 0;
1825     if (defined ($SymbolDocs{$symbol})) {
1826         my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1828         # Try to insert the parameter table at the author's desired position.
1829         # Otherwise we need to tag it onto the end.
1830         if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1831           $parameters_output = 1;
1832         }
1833         $desc .= $symbol_docs;
1834     }
1836     if ($parameters_output == 0) {
1837         $desc .= $parameters;
1838     }
1840     $desc .= OutputSymbolTraits ($symbol);
1841     $desc .= "</refsect2>\n";
1842     return ($synop, $desc);
1846 #############################################################################
1847 # Function    : OutputParamDescriptions
1848 # Description : Returns the DocBook output describing the parameters of a
1849 #               function, macro or signal handler.
1850 # Arguments   : $symbol_type - 'FUNCTION', 'MACRO' or 'SIGNAL'. Signal
1851 #                 handlers have an implicit user_data parameter last.
1852 #               $symbol - the name of the function/macro being described.
1853 #############################################################################
1855 sub OutputParamDescriptions {
1856     my ($symbol_type, $symbol) = @_;
1857     my $output = "";
1858     if (defined ($SymbolParams{$symbol})) {
1859         my $returns = "";
1860         my $params = $SymbolParams{$symbol};
1861         my $params_desc = "";
1862         my $j;
1863         for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
1864             my $param_name = $$params[$j];
1865             my $param_desc = $$params[$j + 1];
1866             my $param_annotations = "";
1868             ($param_desc,$param_annotations) = & ExpandAnnotation($symbol, $param_desc);
1869             $param_desc = &ExpandAbbreviations($symbol, $param_desc);
1870             if ($param_name eq "Returns") {
1871                 $returns = "$param_desc$param_annotations";
1872             } else {
1873                 if ($param_name eq "Varargs") {
1874                     $param_name = "...";
1875                 }
1876                 $params_desc .= "<varlistentry><term><parameter>$param_name</parameter>&#160;:</term>\n<listitem><simpara>$param_desc$param_annotations</simpara></listitem></varlistentry>\n";
1877             }
1878         }
1880         # Signals have an implicit user_data parameter which we describe.
1881         if ($symbol_type eq "SIGNAL") {
1882             $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";
1883         }
1885         # Start a table if we need one.
1886         if ($params_desc || $returns) {
1887             $output .= "<variablelist role=\"params\">\n";
1888             if ($params_desc ne "") {
1889                 #$output .= "<varlistentry><term>Parameters:</term><listitem></listitem></varlistentry>\n";
1890                 $output .= $params_desc;
1891             }
1893             # Output the returns info last.
1894             if ($returns) {
1895                 $output .= "<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara>$returns</simpara></listitem></varlistentry>\n";
1896             }
1898             # Finish the table.
1899             $output .= "</variablelist>";
1900         }
1901     }
1902     return $output;
1906 #############################################################################
1907 # Function    : ParseStabilityLevel
1908 # Description : Parses a stability level and outputs a warning if it isn't
1909 #               valid.
1910 # Arguments   : $stability - the stability text.
1911 #               $file, $line - context for error message
1912 #               $message - description of where the level is from, to use in
1913 #               any error message.
1914 # Returns     : The parsed stability level string.
1915 #############################################################################
1917 sub ParseStabilityLevel {
1918     my ($stability, $file, $line, $message) = @_;
1920     $stability =~ s/^\s*//;
1921     $stability =~ s/\s*$//;
1922     if ($stability =~ m/^stable$/i) {
1923         $stability = "Stable";
1924     } elsif ($stability =~ m/^unstable$/i) {
1925         $stability = "Unstable";
1926     } elsif ($stability =~ m/^private$/i) {
1927         $stability = "Private";
1928     } else {
1929         &LogWarning ($file, $line, "$message is $stability.".
1930             "It should be one of these: Stable, Unstable, or Private.");
1931     }
1932     return $stability;
1936 #############################################################################
1937 # Function    : OutputSGMLFile
1938 # Description : Outputs the final DocBook file for one section.
1939 # Arguments   : $file - the name of the file.
1940 #               $title - the title from the $MODULE-sections.txt file, which
1941 #                 will be overridden by the title in the template file.
1942 #               $section_id - the SGML id to use for the toplevel tag.
1943 #               $includes - comma-separates list of include files added at top
1944 #                 of synopsis, with '<' '>' around them (if not already enclosed in "").
1945 #               $synopsis - reference to the DocBook for the Synopsis part.
1946 #               $details - reference to the DocBook for the Details part.
1947 #               $signal_synop - reference to the DocBook for the Signal Synopsis part
1948 #               $signal_desc - reference to the DocBook for the Signal Description part
1949 #               $args_synop - reference to the DocBook for the Arg Synopsis part
1950 #               $args_desc - reference to the DocBook for the Arg Description part
1951 #               $hierarchy - reference to the DocBook for the Object Hierarchy part
1952 #               $interfaces - reference to the DocBook for the Interfaces part
1953 #               $implementations - reference to the DocBook for the Known Implementations part
1954 #               $prerequisites - reference to the DocBook for the Prerequisites part
1955 #               $derived - reference to the DocBook for the Derived Interfaces part
1956 #               $file_objects - reference to an array of objects in this file
1957 #############################################################################
1959 sub OutputSGMLFile {
1960     my ($file, $title, $section_id, $includes, $synopsis, $details, $signals_synop, $signals_desc, $args_synop, $args_desc, $hierarchy, $interfaces, $implementations, $prerequisites, $derived, $file_objects) = @_;
1962     #print "Output sgml for file $file with title '$title'\n";
1963     
1964     # The edited title overrides the one from the sections file.
1965     my $new_title = $SymbolDocs{"$TMPL_DIR/$file:Title"};
1966     if (defined ($new_title) && $new_title !~ m/^\s*$/) {
1967         $title = $new_title;
1968         #print "Found title: $title\n";
1969     }
1970     my $short_desc = $SymbolDocs{"$TMPL_DIR/$file:Short_Description"};
1971     if (!defined ($short_desc) || $short_desc =~ m/^\s*$/) {
1972         $short_desc = "";
1973     } else {
1974         $short_desc = &ExpandAbbreviations("$title:Short_description",
1975                                            $short_desc);
1976         #print "Found short_desc: $short_desc";
1977     }
1978     my $long_desc = $SymbolDocs{"$TMPL_DIR/$file:Long_Description"};
1979     if (!defined ($long_desc) || $long_desc =~ m/^\s*$/) {
1980         $long_desc = "";
1981     } else {
1982         $long_desc = &ExpandAbbreviations("$title:Long_description",
1983                                           $long_desc);
1984         #print "Found long_desc: $long_desc";
1985     }
1986     my $see_also = $SymbolDocs{"$TMPL_DIR/$file:See_Also"};
1987     if (!defined ($see_also) || $see_also =~ m%^\s*(<para>)?\s*(</para>)?\s*$%) {
1988         $see_also = "";
1989     } else {
1990         $see_also = &ExpandAbbreviations("$title:See_Also", $see_also);
1991         #print "Found see_also: $see_also";
1992     }
1993     if ($see_also) {
1994         $see_also = "<refsect1 id=\"$section_id.see-also\">\n<title>See Also</title>\n$see_also\n</refsect1>\n";
1995     }
1996     my $stability = $SymbolDocs{"$TMPL_DIR/$file:Stability_Level"};
1997     if (!defined ($stability) || $stability =~ m/^\s*$/) {
1998         $stability = "";
1999     } else {
2000         $stability = &ParseStabilityLevel($stability, $file, $., "Section stability level");
2001         #print "Found stability: $stability";
2002     }
2003     if ($stability) {
2004         $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$stability, unless otherwise indicated\n</refsect1>\n";
2005     } elsif ($DEFAULT_STABILITY) {
2006         $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$DEFAULT_STABILITY, unless otherwise indicated\n</refsect1>\n";
2007     }
2009     my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
2010         gmtime (time);
2011     my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
2012     $year += 1900;
2014     my $include_output = "";
2015     my $include;
2016     foreach $include (split (/,/, $includes)) {
2017         if ($include =~ m/^\".+\"$/) {
2018             $include_output .= "#include ${include}\n";
2019         }
2020         else {
2021             $include =~ s/^\s+|\s+$//gs;
2022             $include_output .= "#include &lt;${include}&gt;\n";
2023         }
2024     }
2025     if ($include_output ne '') {
2026         $include_output = "\n$include_output\n";
2027     }
2028     
2029     my $extralinks = OutputSectionExtraLinks($title,"Section:$file");
2031     my $old_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT";
2032     my $new_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT.new";
2034     open (OUTPUT, ">$new_sgml_file")
2035         || die "Can't create $new_sgml_file: $!";
2037     my $object_anchors = "";
2038     foreach my $object (@$file_objects) {
2039         next if ($object eq $section_id);
2040         my $id = CreateValidSGMLID($object);
2041         #print "Debug: Adding anchor for $object\n";
2042         $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
2043     }
2045     # We used to output this, but is messes up our UpdateFileIfChanged code
2046     # since it changes every day (and it is only used in the man pages):
2047     # "<refentry id="$section_id" revision="$mday $month $year">"
2049     if (lc($OUTPUT_FORMAT) eq "xml") {
2050         print OUTPUT $doctype_header;
2051     }
2053     print OUTPUT <<EOF;
2054 <refentry id="$section_id">
2055 <refmeta>
2056 <refentrytitle role="top_of_page" id="$section_id.top_of_page">$title</refentrytitle>
2057 <manvolnum>3</manvolnum>
2058 <refmiscinfo>\U$MODULE\E Library</refmiscinfo>
2059 </refmeta>
2060 <refnamediv>
2061 <refname>$title</refname>
2062 <refpurpose>$short_desc</refpurpose>
2063 </refnamediv>
2064 $stability
2065 <refsynopsisdiv id="$section_id.synopsis" role="synopsis">
2066 <title role="synopsis.title">Synopsis</title>
2067 $object_anchors
2068 <synopsis>$include_output$${synopsis}</synopsis>
2069 </refsynopsisdiv>
2070 $$hierarchy$$prerequisites$$derived$$interfaces$$implementations$$args_synop$$signals_synop
2071 <refsect1 id="$section_id.description" role="desc">
2072 <title role="desc.title">Description</title>
2073 $extralinks$long_desc
2074 </refsect1>
2075 <refsect1 id="$section_id.details" role="details">
2076 <title role="details.title">Details</title>
2077 $$details
2078 </refsect1>
2079 $$args_desc$$signals_desc$see_also
2080 </refentry>
2082     close (OUTPUT);
2084     return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2088 #############################################################################
2089 # Function    : OutputExtraFile
2090 # Description : Copies an "extra" DocBook file into the output directory,
2091 #               expanding abbreviations
2092 # Arguments   : $file - the source file.
2093 #############################################################################
2094 sub OutputExtraFile {
2095     my ($file) = @_;
2097     my $basename;
2099     ($basename = $file) =~ s!^.*/!!;
2101     my $old_sgml_file = "$SGML_OUTPUT_DIR/$basename";
2102     my $new_sgml_file = "$SGML_OUTPUT_DIR/$basename.new";
2104     my $contents;
2106     open(EXTRA_FILE, "<$file") || die "Can't open $file";
2108     {
2109         local $/;
2110         $contents = <EXTRA_FILE>;
2111     }
2113     open (OUTPUT, ">$new_sgml_file")
2114         || die "Can't create $new_sgml_file: $!";
2116     print OUTPUT &ExpandAbbreviations ("$basename file", $contents);
2117     close (OUTPUT);
2119     return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2121 #############################################################################
2122 # Function    : OutputBook
2123 # Description : Outputs the SGML entities that need to be included into the
2124 #               main SGML file for the module.
2125 # Arguments   : $book_top - the declarations of the entities, which are added
2126 #                 at the top of the main SGML file.
2127 #               $book_bottom - the references to the entities, which are
2128 #                 added in the main SGML file at the desired position.
2129 #############################################################################
2131 sub OutputBook {
2132     my ($book_top, $book_bottom) = @_;
2134     my $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top";
2135     my $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top.new";
2137     open (OUTPUT, ">$new_file")
2138         || die "Can't create $new_file: $!";
2139     print OUTPUT $book_top;
2140     close (OUTPUT);
2142     &UpdateFileIfChanged ($old_file, $new_file, 0);
2145     $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom";
2146     $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom.new";
2148     open (OUTPUT, ">$new_file")
2149         || die "Can't create $new_file: $!";
2150     print OUTPUT $book_bottom;
2151     close (OUTPUT);
2153     &UpdateFileIfChanged ($old_file, $new_file, 0);
2156     # If the main SGML file hasn't been created yet, we create it here.
2157     # The user can tweak it later.
2158     if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
2159       open (OUTPUT, ">$MAIN_SGML_FILE")
2160         || die "Can't create $MAIN_SGML_FILE: $!";
2162       if (lc($OUTPUT_FORMAT) eq "xml") {
2163           print OUTPUT <<EOF;
2164 <?xml version="1.0"?>
2165 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
2166                "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
2168   <!ENTITY % local.common.attrib "xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'">
2170 <book id="index">
2172       } else {
2173         print OUTPUT <<EOF;
2174 <!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
2175 $book_top
2177 <book id="index">
2179       }
2181 print OUTPUT <<EOF;
2182   <bookinfo>
2183     <title>$MODULE Reference Manual</title>
2184     <releaseinfo>
2185       for $MODULE [VERSION].
2186       The latest version of this documentation can be found on-line at
2187       <ulink role="online-location" url="http://[SERVER]/$MODULE/index.html">http://[SERVER]/$MODULE/</ulink>.
2188     </releaseinfo>
2189   </bookinfo>
2191   <chapter>
2192     <title>[Insert title here]</title>
2193     $book_bottom
2194   </chapter>
2196   if (-e $OBJECT_TREE_FILE) {
2197     print OUTPUT <<EOF;
2198   <chapter id="object-tree">
2199     <title>Object Hierarchy</title>
2200      <xi:include href="xml/tree_index.sgml"/>
2201   </chapter>
2203   }
2205 print OUTPUT <<EOF;
2206   <index id="api-index-full">
2207     <title>API Index</title>
2208     <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
2209   </index>
2211   <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
2212 </book>
2215       close (OUTPUT);
2216     }
2220 #############################################################################
2221 # Function    : CreateValidSGML
2222 # Description : This turns any chars which are used in SGML into entities,
2223 #               e.g. '<' into '&lt;'
2224 # Arguments   : $text - the text to turn into proper SGML.
2225 #############################################################################
2227 sub CreateValidSGML {
2228     my ($text) = @_;
2229     $text =~ s/&/&amp;/g;       # Do this first, or the others get messed up.
2230     $text =~ s/</&lt;/g;
2231     $text =~ s/>/&gt;/g;
2232     # browers render single tabs inconsistently
2233     $text =~ s/([^\s])\t([^\s])/$1&#160;$2/g;
2234     return $text;
2237 #############################################################################
2238 # Function    : ConvertSGMLChars
2239 # Description : This is used for text in source code comment blocks, to turn
2240 #               chars which are used in SGML into entities, e.g. '<' into
2241 #               '&lt;'. Depending on $SGML_MODE, this is done
2242 #               unconditionally or only if the character doesn't seem to be
2243 #               part of an SGML construct (tag or entity reference).
2244 # Arguments   : $text - the text to turn into proper SGML.
2245 #############################################################################
2247 sub ConvertSGMLChars {
2248     my ($symbol, $text) = @_;
2250     if ($SGML_MODE) {
2251         # For the SGML mode only convert to entities outside CDATA sections.
2252         return &ModifyXMLElements ($text, $symbol,
2253                                    "<!\\[CDATA\\[|<programlisting[^>]*>",
2254                                    \&ConvertSGMLCharsEndTag,
2255                                    \&ConvertSGMLCharsCallback);
2256     } else {
2257         # For the simple non-sgml mode, convert to entities everywhere.
2258         $text =~ s/&/&amp;/g;   # Do this first, or the others get messed up.
2259         $text =~ s/</&lt;/g;
2260         $text =~ s/>/&gt;/g;
2261         return $text;
2262     }
2266 sub ConvertSGMLCharsEndTag {
2267   if ($_[0] eq "<!\[CDATA\[") {
2268     return "]]>";
2269   } else {
2270     return "</programlisting>";
2271   }
2274 sub ConvertSGMLCharsCallback {
2275   my ($text, $symbol, $tag) = @_;
2277   if ($tag =~ m/^<programlisting/) {
2278     # We can handle <programlisting> specially here.
2279     return &ModifyXMLElements ($text, $symbol,
2280                                "<!\\[CDATA\\[",
2281                                \&ConvertSGMLCharsEndTag,
2282                                \&ConvertSGMLCharsCallback2);
2283   } elsif ($tag eq "") {
2284     # If we're not in CDATA convert to entities.
2285     $text =~ s/&(?![a-zA-Z#]+;)/&amp;/g;        # Do this first, or the others get messed up.
2286     $text =~ s/<(?![a-zA-Z\/!])/&lt;/g;
2287     $text =~ s/(?<![a-zA-Z0-9"'\/-])>/&gt;/g;
2289     # Handle "#include <xxxxx>"
2290     $text =~ s/#include(\s+)<([^>]+)>/#include$1&lt;$2&gt;/g;
2291   }
2293   return $text;
2296 sub ConvertSGMLCharsCallback2 {
2297   my ($text, $symbol, $tag) = @_;
2299   # If we're not in CDATA convert to entities.
2300   # We could handle <programlisting> differently, though I'm not sure it helps.
2301   if ($tag eq "") {
2302     # replace only if its not a tag
2303     $text =~ s/&(?![a-zA-Z#]+;)/&amp;/g;        # Do this first, or the others get messed up.
2304     $text =~ s/<(?![a-zA-Z\/!])/&lt;/g;
2305     $text =~ s/(?<![a-zA-Z0-9"'\/-])>/&gt;/g;
2307     # Handle "#include <xxxxx>"
2308     $text =~ s/#include(\s+)<([^>]+)>/#include$1&lt;$2&gt;/g;
2309   }
2311   return $text;
2314 #############################################################################
2315 # Function    : ExpandAnnotation
2316 # Description : This turns annotations into acrony tags.
2317 # Arguments   : $symbol - the symbol being documented, for error messages.
2318 #               $text - the text to expand.
2319 #############################################################################
2320 sub ExpandAnnotation {
2321     my ($symbol, $param_desc) = @_;
2322     my $param_annotations = "";
2323     
2324     if ($param_desc =~ m%\s*\((.*)\):%) {
2325         my @annotations;
2326         my $annotation;
2327         my $annotation_extra = "";
2328         $param_desc = $';
2329     
2330         @annotations = split(/\)\s*\(/,$1);
2331         foreach $annotation (@annotations) {
2332             # need to search for the longest key-match in %AnnotationDefinition
2333             my $match_length=0;
2334             my $match_annotation="";
2335             my $annotationdef;
2336             foreach $annotationdef (keys %AnnotationDefinition) {
2337                 if ($annotation =~ m/^$annotationdef/) {
2338                     if (length($annotationdef)>$match_length) {
2339                         $match_length=length($annotationdef);
2340                         $match_annotation=$annotationdef;
2341                     }
2342                 }
2343             }
2344             if ($match_annotation ne "") {
2345                 if ($annotation =~ m%$match_annotation\s+(.*)%) {
2346                     $annotation_extra = " $1";
2347                 }
2348                 $AnnotationsUsed{$match_annotation} = 1;
2349                 $param_annotations .= "<acronym>$match_annotation</acronym>$annotation_extra. ";
2350             }
2351             else {
2352                 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2353                     "unknown annotation \"$annotation\" in documentation for $symbol.");
2354                 $param_annotations=$annotation;
2355             }
2356         }
2357         chomp($param_desc);
2358         $param_desc =~ m/^(.*)\.*\s*$/;
2359         $param_desc = "$1. ";
2360     }    
2361     return ($param_desc, $param_annotations);
2364 #############################################################################
2365 # Function    : ExpandAbbreviations
2366 # Description : This turns the abbreviations function(), macro(), @param,
2367 #               %constant, and #symbol into appropriate DocBook markup.
2368 #               CDATA sections and <programlisting> parts are skipped.
2369 # Arguments   : $symbol - the symbol being documented, for error messages.
2370 #               $text - the text to expand.
2371 #############################################################################
2373 sub ExpandAbbreviations {
2374   my ($symbol, $text) = @_;
2376   # Convert "|[" and "]|" into the start and end of program listing examples.
2377   $text =~ s%\|\[%<informalexample><programlisting>%g;
2378   $text =~ s%\]\|%</programlisting></informalexample>%g;
2379   # TODO: check for a xml comment after |[ and pick the language attribute from
2380   # that
2382   # keep CDATA unmodified, preserve ulink tags (ideally we preseve all tags
2383   # as such)
2384   return &ModifyXMLElements ($text, $symbol,
2385                              "<!\\[CDATA\\[|<ulink[^>]*>|<programlisting[^>]*>|<!DOCTYPE",
2386                              \&ExpandAbbreviationsEndTag,
2387                              \&ExpandAbbreviationsCallback);
2391 # Returns the end tag corresponding to the given start tag.
2392 sub ExpandAbbreviationsEndTag {
2393   my ($start_tag) = @_;
2395   if ($start_tag eq "<!\[CDATA\[") {
2396     return "]]>";
2397   } elsif ($start_tag eq "<!DOCTYPE") {
2398     return "]>";
2399   } elsif ($start_tag =~ m/<(\w+)/) {
2400     return "</$1>";
2401   }
2404 # Called inside or outside each CDATA or <programlisting> section.
2405 sub ExpandAbbreviationsCallback {
2406   my ($text, $symbol, $tag) = @_;
2408   if ($tag =~ m/^<programlisting/) {
2409     # Handle any embedded CDATA sections.
2410     return &ModifyXMLElements ($text, $symbol,
2411                                "<!\\[CDATA\\[",
2412                                \&ExpandAbbreviationsEndTag,
2413                                \&ExpandAbbreviationsCallback2);
2414   } elsif ($tag eq "") {
2415     # We are outside any CDATA or <programlisting> sections, so we expand
2416     # any gtk-doc abbreviations.
2418     # Convert 'function()' or 'macro()'.
2419     $text =~ s/(\w+)\s*\(\)/&MakeXRef($1, &tagify($1 . "()", "function"));/eg;
2421     # Convert '@param', but not '\@param'.
2422     $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)/$1<parameter>$2<\/parameter>/g;
2423     $text =~ s/\\\@/\@/g;
2425     # Convert '%constant', but not '\%constant'.
2426     # Also allow negative numbers, e.g. %-1.
2427     $text =~ s/(\A|[^\\])\%(-?\w+)/$1.&MakeXRef($2, &tagify($2, "literal"));/eg;
2428     $text =~ s/\\\%/\%/g;
2430     # Convert '#symbol', but not '\#symbol'.
2431     $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)/$1.&MakeHashXRef($2, "type");/eg;
2432     $text =~ s/\\#/#/g;
2433     
2434     # Expand urls
2435     # FIXME: should we skip urls that are already tagged? (e.g. <literal>http://...</literal>)
2436     # this is apparently also called for markup and not just for plain text
2437     # disable for now.
2438     #$text =~ s%(http|https|ftp)://(.*?)((?:\s|,|\)|\]|\<|\.\s))%<ulink url="$1://$2">$2</ulink>$3%g;
2439   }
2441   return $text;
2444 # This is called inside a <programlisting>
2445 sub ExpandAbbreviationsCallback2 {
2446   my ($text, $symbol, $tag) = @_;
2448   if ($tag eq "") {
2449     # We are inside a <programlisting> but outside any CDATA sections,
2450     # so we expand any gtk-doc abbreviations.
2451     # FIXME: why is this different from &ExpandAbbreviationsCallback(),
2452     #        why not just call it
2453     $text =~ s/#(\w+)/&MakeHashXRef($1, "");/eg;
2454   }
2456   return $text;
2459 sub MakeHashXRef {
2460     my ($symbol, $tag) = @_;;
2461     my $text = $symbol;
2463     # Check for things like '#include', '#define', and skip them.
2464     if ($PreProcessorDirectives{$symbol}) {
2465       return "#$symbol";
2466     }
2468     # Get rid of any special '-struct' suffix.
2469     $text =~ s/-struct$//;
2471     # If the symbol is in the form "Object::signal", then change the symbol to
2472     # "Object-signal" and use "signal" as the text.
2473     if ($symbol =~ s/::/-/) {
2474       $text = "\"$'\"";
2475     }
2477     # If the symbol is in the form "Object:property", then change the symbol to
2478     # "Object--property" and use "property" as the text.
2479     if ($symbol =~ s/:/--/) {
2480       $text = "\"$'\"";
2481     }
2483     if ($tag ne "") {
2484       $text = tagify ($text, $tag);
2485     }
2486     
2487     return &MakeXRef($symbol, $text);
2491 #############################################################################
2492 # Function    : ModifyXMLElements
2493 # Description : Looks for given XML element tags within the text, and calls
2494 #               the callback on pieces of text inside & outside those elements.
2495 #               Used for special handling of text inside things like CDATA
2496 #               and <programlisting>.
2497 # Arguments   : $text - the text.
2498 #               $symbol - the symbol currently being documented (only used for
2499 #                      error messages).
2500 #               $start_tag_regexp - the regular expression to match start tags.
2501 #                      e.g. "<!\\[CDATA\\[|<programlisting[^>]*>" to match
2502 #                      CDATA sections or programlisting elements.
2503 #               $end_tag_func - function which is passed the matched start tag
2504 #                      and should return the appropriate end tag string.
2505 #               $callback - callback called with each part of the text. It is
2506 #                      called with a piece of text, the symbol being
2507 #                      documented, and the matched start tag or "" if the text
2508 #                      is outside the XML elements being matched.
2509 #############################################################################
2510 sub ModifyXMLElements {
2511     my ($text, $symbol, $start_tag_regexp, $end_tag_func, $callback) = @_;
2512     my ($before_tag, $start_tag, $end_tag_regexp, $end_tag);
2513     my $result = "";
2515     while ($text =~ m/$start_tag_regexp/s) {
2516       $before_tag = $`; # Prematch for last successful match string
2517       $start_tag = $&;  # Last successful match
2518       $text = $';       # Postmatch for last successful match string
2520       $result .= &$callback ($before_tag, $symbol, "");
2521       $result .= $start_tag;
2523       # get the mathing end-tag for current tag
2524       $end_tag_regexp = &$end_tag_func ($start_tag);
2526       if ($text =~ m/$end_tag_regexp/s) {
2527         $before_tag = $`;
2528         $end_tag = $&;
2529         $text = $';
2531         $result .= &$callback ($before_tag, $symbol, $start_tag);
2532         $result .= $end_tag;
2533       } else {
2534         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2535             "Can't find tag end: $end_tag_regexp in docs for: $symbol.");
2536         # Just assume it is all inside the tag.
2537         $result .= &$callback ($text, $symbol, $start_tag);
2538         $text = "";
2539       }
2540     }
2542     # Handle any remaining text outside the tags.
2543     $result .= &$callback ($text, $symbol, "");
2545     return $result;
2548 sub noop {
2549   return $_[0];
2552 # Adds a tag around some text.
2553 # e.g tagify("Text", "literal") => "<literal>Text</literal>".
2554 sub tagify {
2555    my ($text, $elem) = @_;
2556    return "<" . $elem . ">" . $text . "</" . $elem . ">";
2560 #############################################################################
2561 # Function    : MakeXRef
2562 # Description : This returns a cross-reference link to the given symbol.
2563 #               Though it doesn't try to do this for a few standard C types
2564 #               that it knows won't be in the documentation.
2565 # Arguments   : $symbol - the symbol to try to create a XRef to.
2566 #               $text - text text to put inside the XRef, defaults to $symbol
2567 #############################################################################
2569 sub MakeXRef {
2570     my ($symbol, $text) = ($_[0], $_[1]);
2572     $symbol =~ s/^\s+//;
2573     $symbol =~ s/\s+$//;
2575     if (!defined($text)) {
2576         $text = $symbol;
2578         # Get rid of special '-struct' suffix.
2579         $text =~ s/-struct$//;
2580     }
2582     if ($symbol =~ m/ /) {
2583         return "$text";
2584     }
2586     #print "Getting type link for $symbol -> $text\n";
2588     my $symbol_id = &CreateValidSGMLID ($symbol);
2589     return "<link linkend=\"$symbol_id\">$text</link>";
2593 #############################################################################
2594 # Function    : MakeIndexterms
2595 # Description : This returns a indexterm elements for the given symbol
2596 # Arguments   : $symbol - the symbol to create indexterms for
2597 #############################################################################
2599 sub MakeIndexterms {
2600   my ($symbol, $id) = @_;
2601   my $terms =  "";
2602   my $sortas = "";
2603   
2604   # make the index useful, by ommiting the namespace when sorting
2605   if ($NAME_SPACE ne "") {
2606     if ($symbol =~ m/^$NAME_SPACE\_?(.*)/i) {
2607        $sortas=" sortas=\"$1\"";
2608     }
2609   }
2611   if (exists $Deprecated{$symbol}) {
2612       $terms .= "<indexterm zone=\"$id\" role=\"deprecated\"><primary$sortas>$symbol</primary></indexterm>";
2613       $IndexEntriesDeprecated{$symbol}=$id;
2614       $IndexEntriesFull{$symbol}=$id;
2615   }
2616   if (exists $Since{$symbol}) {
2617      my $since = $Since{$symbol};
2618      $since =~ s/^\s+//;
2619      $since =~ s/\s+$//;
2620      if ($since ne "") {
2621          $terms .= "<indexterm zone=\"$id\" role=\"$since\"><primary$sortas>$symbol</primary></indexterm>";
2622      }
2623      $IndexEntriesSince{$symbol}=$id;
2624      $IndexEntriesFull{$symbol}=$id;
2625   }
2626   if ($terms eq "") {
2627      $terms .= "<indexterm zone=\"$id\"><primary$sortas>$symbol</primary></indexterm>";
2628      $IndexEntriesFull{$symbol}=$id;
2629   }
2631   return $terms;
2634 #############################################################################
2635 # Function    : MakeDeprecationNote
2636 # Description : This returns a deprecation warning for the given symbol.
2637 # Arguments   : $symbol - the symbol to try to create a warning for.
2638 #############################################################################
2640 sub MakeDeprecationNote {
2641     my ($symbol) = $_[0];
2642     my $desc = "";
2643     my $note = "";
2644     if (exists $Deprecated{$symbol}) {
2645         $desc .= "<warning>";
2647         if ($Deprecated{$symbol} =~ /^\s*([0-9\.]+)\s*:/) {
2648                 $desc .= "<para><literal>$symbol</literal> has been deprecated since version $1 and should not be used in newly-written code.";
2649         } else {
2650                 $desc .= "<para><literal>$symbol</literal> is deprecated and should not be used in newly-written code.";
2651         }
2652         if ($Deprecated{$symbol} ne "") {
2653             $note = &ExpandAbbreviations($symbol, $Deprecated{$symbol});
2654             $note =~ s/^\s*([0-9\.]+)\s*:\s*//;
2655             $note =~ s/^\s+//;
2656             $note =~ s/\s+$//;
2657             $note =~ s%\n{2,}%\n</para>\n<para>\n%g;
2658             $desc .= " " . $note;
2659         }
2660         $desc .= "</para></warning>\n";
2661     }
2662     return $desc;
2665 #############################################################################
2666 # Function    : MakeConditionDescription
2667 # Description : This returns a sumary of conditions for the given symbol.
2668 # Arguments   : $symbol - the symbol to try to create the sumary.
2669 #############################################################################
2671 sub MakeConditionDescription {
2672     my ($symbol) = $_[0];
2673     my $desc = "";
2675     if (exists $Deprecated{$symbol}) {
2676         if ($desc ne "") {
2677             $desc .= "|";
2678         }
2680         if ($Deprecated{$symbol} =~ /^\s*(.*?)\s*$/) {
2681                 $desc .= "deprecated:$1";
2682         } else {
2683                 $desc .= "deprecated";
2684         }
2685     }
2687     if (exists $Since{$symbol}) {
2688         if ($desc ne "") {
2689             $desc .= "|";
2690         }
2692         if ($Since{$symbol} =~ /^\s*(.*?)\s*$/) {
2693                 $desc .= "since:$1";
2694         } else {
2695                 $desc .= "since";
2696         }
2697     }
2699     if (exists $StabilityLevel{$symbol}) {
2700         if ($desc ne "") {
2701             $desc .= "|";
2702         }
2703         $desc .= "stability:".$StabilityLevel{$symbol};
2704     }
2706     if ($desc ne "") {
2707         $desc=" condition=\"".$desc."\"";
2708         #print "condition for '$symbol' = '$desc'\n";
2709     }
2710     return $desc;
2713 #############################################################################
2714 # Function    : GetHierarchy
2715 # Description : Returns the DocBook output describing the ancestors and
2716 #               immediate children of a GObject subclass. It uses the
2717 #               global @Objects and @ObjectLevels arrays to walk the tree.
2718 # Arguments   : $object - the GtkObject subclass.
2719 #############################################################################
2721 sub GetHierarchy {
2722     my ($object) = @_;
2724     # Find object in the objects array.
2725     my $found = 0;
2726     my @children = ();
2727     my $i;
2728     my $level;
2729     my $j;
2730     for ($i = 0; $i < @Objects; $i++) {
2731         if ($found) {
2732             if ($ObjectLevels[$i] <= $level) {
2733             last;
2734         }
2735             elsif ($ObjectLevels[$i] == $level + 1) {
2736                 push (@children, $Objects[$i]);
2737             }
2738         }
2739         elsif ($Objects[$i] eq $object) {
2740             $found = 1;
2741             $j = $i;
2742             $level = $ObjectLevels[$i];
2743         }
2744     }
2745     if (!$found) {
2746         return "";
2747     }
2749     # Walk up the hierarchy, pushing ancestors onto the ancestors array.
2750     my @ancestors = ();
2751     push (@ancestors, $object);
2752     #print "Level: $level\n";
2753     while ($level > 1) {
2754         $j--;
2755         if ($ObjectLevels[$j] < $level) {
2756             push (@ancestors, $Objects[$j]);
2757             $level = $ObjectLevels[$j];
2758             #print "Level: $level\n";
2759         }
2760     }
2762     # Output the ancestors list, indented and with links.
2763     my $hierarchy = "<synopsis>\n";
2764     $level = 0;
2765     for ($i = $#ancestors; $i >= 0; $i--) {
2766         my $link_text;
2767         # Don't add a link to the current widget, i.e. when i == 0.
2768         if ($i > 0) {
2769             my $ancestor_id = &CreateValidSGMLID ($ancestors[$i]);
2770             $link_text = "<link linkend=\"$ancestor_id\">$ancestors[$i]</link>";
2771         } else {
2772             $link_text = "$ancestors[$i]";
2773         }
2774         if ($level == 0) {
2775             $hierarchy .= "  $link_text\n";
2776         } else {
2777 #           $hierarchy .= ' ' x ($level * 6 - 3) . "|\n";
2778             $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
2779         }
2780         $level++;
2781     }
2782     for ($i = 0; $i <= $#children; $i++) {
2783       my $id = &CreateValidSGMLID ($children[$i]);
2784       my $link_text = "<link linkend=\"$id\">$children[$i]</link>";
2785       $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
2786     }
2787     $hierarchy .= "</synopsis>\n";
2789     return $hierarchy;
2793 #############################################################################
2794 # Function    : GetInterfaces
2795 # Description : Returns the DocBook output describing the interfaces
2796 #               implemented by a class. It uses the global %Interfaces hash.
2797 # Arguments   : $object - the GtkObject subclass.
2798 #############################################################################
2800 sub GetInterfaces {
2801     my ($object) = @_;
2802     my $text = "";
2803     my $i;
2805     # Find object in the objects array.
2806     if (exists($Interfaces{$object})) {
2807         my @ifaces = split(' ', $Interfaces{$object});
2808         $text = <<EOF;
2809 <para>
2810 $object implements
2812         for ($i = 0; $i <= $#ifaces; $i++) {
2813             my $id = &CreateValidSGMLID ($ifaces[$i]);
2814             $text .= " <link linkend=\"$id\">$ifaces[$i]</link>";
2815             if ($i < $#ifaces - 1) {
2816                 $text .= ', ';
2817             }
2818             elsif ($i < $#ifaces) {
2819                 $text .= ' and ';
2820             }
2821             else {
2822                 $text .= '.';
2823             }
2824         }
2825         $text .= <<EOF;
2826 </para>
2828     }
2830     return $text;
2833 #############################################################################
2834 # Function    : GetImplementations
2835 # Description : Returns the DocBook output describing the implementations
2836 #               of an interface. It uses the global %Interfaces hash.
2837 # Arguments   : $object - the GtkObject subclass.
2838 #############################################################################
2840 sub GetImplementations {
2841     my ($object) = @_;
2842     my @impls = ();
2843     my $text = "";
2844     my $i;
2845     foreach my $key (keys %Interfaces) {
2846         if ($Interfaces{$key} =~ /\b$object\b/) {
2847             push (@impls, $key);
2848         }
2849     }
2850     if ($#impls >= 0) {
2851         $text = <<EOF;
2852 <para>
2853 $object is implemented by
2855         for ($i = 0; $i <= $#impls; $i++) {
2856             my $id = &CreateValidSGMLID ($impls[$i]);
2857             $text .= " <link linkend=\"$id\">$impls[$i]</link>";
2858             if ($i < $#impls - 1) {
2859                 $text .= ', ';
2860             }
2861             elsif ($i < $#impls) {
2862                 $text .= ' and ';
2863             }
2864             else {
2865                 $text .= '.';
2866             }
2867         }
2868         $text .= <<EOF;
2869 </para>
2871     }
2872     return $text;
2876 #############################################################################
2877 # Function    : GetPrerequisites
2878 # Description : Returns the DocBook output describing the prerequisites
2879 #               of an interface. It uses the global %Prerequisites hash.
2880 # Arguments   : $iface - the interface.
2881 #############################################################################
2883 sub GetPrerequisites {
2884     my ($iface) = @_;
2885     my $text = "";
2886     my $i;
2888     if (exists($Prerequisites{$iface})) {
2889         $text = <<EOF;
2890 <para>
2891 $iface requires
2893         my @prereqs = split(' ', $Prerequisites{$iface});
2894         for ($i = 0; $i <= $#prereqs; $i++) {
2895             my $id = &CreateValidSGMLID ($prereqs[$i]);
2896             $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
2897             if ($i < $#prereqs - 1) {
2898                 $text .= ', ';
2899             }
2900             elsif ($i < $#prereqs) {
2901                 $text .= ' and ';
2902             }
2903             else {
2904                 $text .= '.';
2905             }
2906         }
2907         $text .= <<EOF;
2908 </para>
2910     }
2911     return $text;
2914 #############################################################################
2915 # Function    : GetDerived
2916 # Description : Returns the DocBook output describing the derived interfaces
2917 #               of an interface. It uses the global %Prerequisites hash.
2918 # Arguments   : $iface - the interface.
2919 #############################################################################
2921 sub GetDerived {
2922     my ($iface) = @_;
2923     my $text = "";
2924     my $i;
2926     my @derived = ();
2927     foreach my $key (keys %Prerequisites) {
2928         if ($Prerequisites{$key} =~ /\b$iface\b/) {
2929             push (@derived, $key);
2930         }
2931     }
2932     if ($#derived >= 0) {
2933         $text = <<EOF;
2934 <para>
2935 $iface is required by
2937         for ($i = 0; $i <= $#derived; $i++) {
2938             my $id = &CreateValidSGMLID ($derived[$i]);
2939             $text .= " <link linkend=\"$id\">$derived[$i]</link>";
2940             if ($i < $#derived - 1) {
2941                 $text .= ', ';
2942             }
2943             elsif ($i < $#derived) {
2944                 $text .= ' and ';
2945             }
2946             else {
2947                 $text .= '.';
2948             }
2949         }
2950         $text .= <<EOF;
2951 </para>
2953     }
2954     return $text;
2958 #############################################################################
2959 # Function    : GetSignals
2960 # Description : Returns the synopsis and detailed description DocBook output
2961 #               for the signal handlers of a given GtkObject subclass.
2962 # Arguments   : $object - the GtkObject subclass, e.g. 'GtkButton'.
2963 #############################################################################
2965 sub GetSignals {
2966     my ($object) = @_;
2967     my $synop = "";
2968     my $desc = "";
2970     my $i;
2971     for ($i = 0; $i <= $#SignalObjects; $i++) {
2972         if ($SignalObjects[$i] eq $object) {
2973             #print "Found signal: $SignalNames[$i]\n";
2974             my $name = $SignalNames[$i];
2975             my $symbol = "${object}::${name}";
2976             my $id = &CreateValidSGMLID ("$object-$name");
2978             my $pad = ' ' x (46 - length($name));
2979             $synop .= "  &quot;<link linkend=\"$id\">$name</link>&quot;$pad ";
2981             $desc .= "<refsect2 id=\"$id\" role=\"signal\"><title>The <literal>&quot;$name&quot;</literal> signal</title>\n";
2982             $desc .= MakeIndexterms($symbol, $id);
2983             $desc .= "\n";
2984             $desc .= OutputSymbolExtraLinks($symbol);
2986             $desc .= "<programlisting>";
2988             $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
2989             my $type_modifier = defined($1) ? $1 : "";
2990             my $type = $2;
2991             my $pointer = $3;
2992             my $xref = &MakeXRef ($type);
2994             my $ret_type_len = length ($type_modifier) + length ($pointer)
2995                 + length ($type);
2996             my $ret_type_output = "$type_modifier$xref$pointer"
2997                 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
2999             $desc  .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
3001             my $sourceparams = $SourceSymbolParams{$symbol};
3002             my @params = split ("\n", $SignalPrototypes[$i]);
3003             my $j;
3004             my $l;
3005             my $type_len = length("gpointer");
3006             my $name_len = length("user_data");
3007             # do two passes, the first one is to calculate padding
3008             for ($l = 0; $l < 2; $l++) {
3009                 for ($j = 0; $j <= $#params; $j++) {
3010                     # allow alphanumerics, '_', '[' & ']' in param names
3011                     if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
3012                         $type = $1;
3013                         $pointer = $2;
3014                         if (defined($sourceparams)) {
3015                             $name = $$sourceparams[$PARAM_FIELD_COUNT * $j];
3016                         }
3017                         else {
3018                             $name = $3;
3019                         }
3020                         if (!defined($name)) {
3021                             $name = "arg$j";
3022                         }
3023                         if ($l == 0) {
3024                             if (length($type) + length($pointer) > $type_len) {
3025                                 $type_len = length($type) + length($pointer);
3026                             }
3027                             if (length($name) > $name_len) {
3028                                 $name_len = length($name);
3029                             }
3030                         }
3031                         else {
3032                             $xref = &MakeXRef ($type);
3033                             $pad = ' ' x ($type_len - length($type) - length($pointer));
3034                             $desc .= "$xref$pad $pointer$name,\n";
3035                             $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
3036                         }
3037                     } else {
3038                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3039                              "Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]");
3040                     }
3041                 }
3042             }
3043             $xref = &MakeXRef ("gpointer");
3044             $pad = ' ' x ($type_len - length("gpointer"));
3045             $desc  .= "$xref$pad user_data)";
3047             my $flags = $SignalFlags[$i];
3048             my $flags_string = "";
3050             if (defined ($flags)) {
3051               if ($flags =~ m/f/) {
3052                 $flags_string = "Run First";
3053               }
3054               elsif ($flags =~ m/l/) {
3055                 $flags_string = "Run Last";
3056               }
3057               elsif ($flags =~ m/c/) {
3058                 $flags_string = "Cleanup";
3059               }
3060               if ($flags =~ m/r/) {
3061                 if ($flags_string) { $flags_string .= " / "; }
3062                 $flags_string .= "No Recursion";
3063               }
3064               if ($flags =~ m/d/) {
3065                 if ($flags_string) { $flags_string .= " / "; }
3066                 $flags_string .= "Has Details";
3067               }
3068               if ($flags =~ m/a/) {
3069                 if ($flags_string) { $flags_string .= " / "; }
3070                 $flags_string .= "Action";
3071               }
3072               if ($flags =~ m/h/) {
3073                 if ($flags_string) { $flags_string .= " / "; }
3074                 $flags_string .= "No Hooks";
3075               }
3076             }
3078             if ($flags_string)
3079               {
3080                 $synop .= ": $flags_string\n";
3082                 $pad = ' ' x (5 + $name_len - length("user_data"));
3083                 $desc  .= "$pad : $flags_string</programlisting>\n";
3084               }
3085             else
3086               {
3087                 $synop .= "\n";
3088                 $desc  .= "</programlisting>\n";
3089               }
3091             $desc .= &MakeDeprecationNote($symbol);
3093             my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
3094             my $parameters_output = 0;
3096             $AllSymbols{$symbol} = 1;
3097             if (defined ($SymbolDocs{$symbol})) {
3098                 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3100                 # Try to insert the parameter table at the author's desired
3101                 # position. Otherwise we need to tag it onto the end.
3102                 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
3103                   $parameters_output = 1;
3104                 }
3105                 $desc .= $symbol_docs;
3107                 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
3108                     $AllDocumentedSymbols{$symbol} = 1;
3109                 }
3110             }
3112             if ($parameters_output == 0) {
3113                 $desc .= $parameters;
3114               }
3115             $desc .= OutputSymbolTraits ($symbol);
3116             $desc .= "</refsect2>";
3117         }
3118     }
3119     return ($synop, $desc);
3123 #############################################################################
3124 # Function    : GetArgs
3125 # Description : Returns the synopsis and detailed description DocBook output
3126 #               for the Args of a given GtkObject subclass.
3127 # Arguments   : $object - the GtkObject subclass, e.g. 'GtkButton'.
3128 #############################################################################
3130 sub GetArgs {
3131     my ($object) = @_;
3132     my $synop = "";
3133     my $desc = "";
3134     my $child_synop = "";
3135     my $child_desc = "";
3136     my $style_synop = "";
3137     my $style_desc = "";
3139     my $i;
3140     for ($i = 0; $i <= $#ArgObjects; $i++) {
3141         if ($ArgObjects[$i] eq $object) {
3142             #print "Found arg: $ArgNames[$i]\n";
3143             my $name = $ArgNames[$i];
3144             my $flags = $ArgFlags[$i];
3145             my $flags_string = "";
3146             my $kind = "";
3147             my $id_sep = "";
3149             if ($flags =~ m/c/) {
3150                 $kind = "child property";
3151                 $id_sep = "c-";
3152             }
3153             elsif ($flags =~ m/s/) {
3154                 $kind = "style property";
3155                 $id_sep = "s-";
3156             }
3157             else {
3158                 $kind = "property";
3159             }
3161             # Remember only one colon so we don't clash with signals.
3162             my $symbol = "${object}:${name}";
3163             # use two dashes and ev. an extra separator here for the same reason.
3164             my $id = &CreateValidSGMLID ("$object--$id_sep$name");
3166             my $type = $ArgTypes[$i];
3167             my $type_output;
3168             my $range = $ArgRanges[$i];
3169             my $range_output = CreateValidSGML ($range);
3170             my $default = $ArgDefaults[$i];
3171             my $default_output = CreateValidSGML ($default);
3173             if ($type eq "GtkString") {
3174                 $type = "char*";
3175             }
3176             if ($type eq "GtkSignal") {
3177                 $type = "GtkSignalFunc, gpointer";
3178                 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
3179                     . &MakeXRef ("gpointer");
3180             } elsif ($type =~ m/^(\w+)\*$/) {
3181                 $type_output = &MakeXRef ($1) . "*";
3182             } else {
3183                 $type_output = &MakeXRef ($type);
3184             }
3186             if ($flags =~ m/r/) {
3187                 $flags_string = "Read";
3188             }
3189             if ($flags =~ m/w/) {
3190                 if ($flags_string) { $flags_string .= " / "; }
3191                 $flags_string .= "Write";
3192             }
3193             if ($flags =~ m/x/) {
3194                 if ($flags_string) { $flags_string .= " / "; }
3195                 $flags_string .= "Construct";
3196             }
3197             if ($flags =~ m/X/) {
3198                 if ($flags_string) { $flags_string .= " / "; }
3199                 $flags_string .= "Construct Only";
3200             }
3202             $AllSymbols{$symbol} = 1;
3203             my $blurb;
3204             if (defined($SymbolDocs{$symbol}) &&
3205                 !IsEmptyDoc($SymbolDocs{$symbol})) {
3206                 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3207                 #print ".. [$SymbolDocs{$symbol}][$blurb]\n";
3208                 $AllDocumentedSymbols{$symbol} = 1;
3209             }
3210             else {
3211                 if (!($ArgBlurbs[$i] eq "")) {
3212                     $AllDocumentedSymbols{$symbol} = 1;
3213                 } else {
3214                     # FIXME: print a warning?
3215                     #print ".. no description\n";
3216                 }
3217                 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
3218             }
3220             my $pad1 = " " x (24 - length ($name));
3221             my $pad2 = " " x (20 - length ($type));
3223             my $arg_synop = "  &quot;<link linkend=\"$id\">$name</link>&quot;$pad1 $type_output $pad2 : $flags_string\n";
3224             my $arg_desc = "<refsect2 id=\"$id\" role=\"property\"><title>The <literal>&quot;$name&quot;</literal> $kind</title>\n";
3225             $arg_desc .= MakeIndexterms($symbol, $id);
3226             $arg_desc .= "\n";
3227             $arg_desc .= OutputSymbolExtraLinks($symbol);
3229             $arg_desc .= "<programlisting>  &quot;$name&quot;$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
3230             $arg_desc .= &MakeDeprecationNote($symbol);
3231             $arg_desc .= $blurb;
3232             if ($range ne "") {
3233                 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
3234             }
3235             if ($default ne "") {
3236                 $arg_desc .= "<para>Default value: $default_output</para>\n";
3237             }
3238             $arg_desc .= OutputSymbolTraits ($symbol);
3239             $arg_desc .= "</refsect2>\n";
3241             if ($flags =~ m/c/) {
3242                 $child_synop .= $arg_synop;
3243                 $child_desc .= $arg_desc;
3244             }
3245             elsif ($flags =~ m/s/) {
3246                 $style_synop .= $arg_synop;
3247                 $style_desc .= $arg_desc;
3248             }
3249             else {
3250                 $synop .= $arg_synop;
3251                 $desc .= $arg_desc;
3252             }
3253         }
3254     }
3255     return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
3259 #############################################################################
3260 # Function    : ReadSourceDocumentation
3261 # Description : This reads in the documentation embedded in comment blocks
3262 #               in the source code (for Gnome).
3264 #               Parameter descriptions override any in the template files.
3265 #               Function descriptions are placed before any description from
3266 #               the template files.
3268 #               It recursively descends the source directory looking for .c
3269 #               files and scans them looking for specially-formatted comment
3270 #               blocks.
3272 # Arguments   : $source_dir - the directory to scan.
3273 #############m###############################################################
3275 sub ReadSourceDocumentation {
3276     my ($source_dir) = @_;
3277     my ($file, $dir, @suffix_list, $suffix);
3278     #print "Scanning source directory: $source_dir\n";
3280     # This array holds any subdirectories found.
3281     my (@subdirs) = ();
3283     @suffix_list = split (/,/, $SOURCE_SUFFIXES);
3285     opendir (SRCDIR, $source_dir)
3286         || die "Can't open source directory $source_dir: $!";
3288     foreach $file (readdir (SRCDIR)) {
3289       if ($file =~ /^\./) {
3290         next;
3291       } elsif (-d "$source_dir/$file") {
3292         push (@subdirs, $file);
3293       } elsif (@suffix_list) {
3294         foreach $suffix (@suffix_list) {
3295           if ($file =~ m/\.\Q${suffix}\E$/) {
3296             &ScanSourceFile ("$source_dir/$file");
3297           }
3298         }
3299       } elsif ($file =~ m/\.[ch]$/) {
3300         &ScanSourceFile ("$source_dir/$file");
3301       }
3302     }
3303     closedir (SRCDIR);
3305     # Now recursively scan the subdirectories.
3306     foreach $dir (@subdirs) {
3307         next if ($IGNORE_FILES =~ m/(\s|^)\Q${dir}\E(\s|$)/);
3308         &ReadSourceDocumentation ("$source_dir/$dir");
3309     }
3313 #############################################################################
3314 # Function    : ScanSourceFile
3315 # Description : Scans one source file looking for specially-formatted comment
3316 #               blocks. Later &MergeSourceDocumentation is used to merge any
3317 #               documentation found with the documentation already read in
3318 #               from the template files.
3320 # Arguments   : $file - the file to scan.
3321 #############################################################################
3323 sub ScanSourceFile {
3324     my ($file) = @_;
3325     my $basename;
3327     if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
3328         $basename = $1;
3329     } else {
3330         &LogWarning ($file, 1, "Can't find basename for this filename.");
3331         $basename = $file;
3332     }
3334     # Check if the basename is in the list of files to ignore.
3335     if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
3336         return;
3337     }
3339     #print "DEBUG: Scanning $file\n";
3341     open (SRCFILE, $file)
3342         || die "Can't open $file: $!";
3343     my $in_comment_block = 0;
3344     my $symbol;
3345     my ($in_description, $in_return, $in_since, $in_stability, $in_deprecated);
3346     my ($description, $return_desc, $return_start, $return_style);
3347     my ($since_desc, $stability_desc, $deprecated_desc);
3348     my $current_param;
3349     my $ignore_broken_returns;
3350     my @params;
3351     while (<SRCFILE>) {
3352         # Look for the start of a comment block.
3353         if (!$in_comment_block) {
3354             if (m%^\s*/\*.*\*/%) {
3355                 #one-line comment - not gtkdoc
3356             } elsif (m%^\s*/\*\*\s%) {
3357                 #print "Found comment block start\n";
3359                 $in_comment_block = 1;
3361                 # Reset all the symbol data.
3362                 $symbol = "";
3363                 $in_description = 0;
3364                 $in_return = 0;
3365                 $in_since = 0;
3366                 $in_deprecated = 0;
3367                 $in_stability = 0;
3368                 $description = "";
3369                 $return_desc = "";
3370                 $return_style = "";
3371                 $since_desc = "";
3372                 $deprecated_desc = "";
3373                 $stability_desc = "";
3374                 $current_param = -1;
3375                 $ignore_broken_returns = 0;
3376                 @params = ();
3377             }
3378             next;
3379         }
3381         # We're in a comment block. Check if we've found the end of it.
3382         if (m%^\s*\*+/%) {
3383             if (!$symbol) {
3384                 # maybe its not even meant to be a gtk-doc comment?
3385                 &LogWarning ($file, $., "Symbol name not found at the start of the comment block.");
3386             } else {
3387                 # Add the return value description onto the end of the params.
3388                 if ($return_desc) {
3389                     push (@params, "Returns");
3390                     push (@params, $return_desc);
3391                     if ($return_style eq 'broken') {
3392                         &LogWarning ($file, $., "Free-form return value description in $symbol. Use `Returns:' to avoid ambiguities.");
3393                     }
3394                 }
3395                 # Convert special SGML characters
3396                 $description = &ConvertSGMLChars ($symbol, $description);
3397                 my $k;
3398                 for ($k = 1; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3399                     $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
3400                 }
3402                 # Handle Section docs
3403                 if ($symbol =~ m/SECTION:\s*(.*)/) {
3404                     my $real_symbol=$1;
3405                     my $key;
3407                     if (scalar %KnownSymbols) {
3408                         if ((! defined($KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"})) || $KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"} != 1) {
3409                             &LogWarning ($file, $., "Section $real_symbol is not defined in the $MODULE-section.txt file.");
3410                         }
3411                     }
3413                     #print "SECTION DOCS found in source for : '$real_symbol'\n";
3414                     $ignore_broken_returns = 1;
3415                     for ($k = 0; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3416                         #print "   '".$params[$k]."'\n";
3417                         $params[$k] = "\L$params[$k]";
3418                         undef $key;
3419                         if ($params[$k] eq "short_description") {
3420                             $key = "$TMPL_DIR/$real_symbol:Short_Description";
3421                         } elsif ($params[$k] eq "see_also") {
3422                             $key = "$TMPL_DIR/$real_symbol:See_Also";
3423                         } elsif ($params[$k] eq "title") {
3424                             $key = "$TMPL_DIR/$real_symbol:Title";
3425                         } elsif ($params[$k] eq "stability") {
3426                             $key = "$TMPL_DIR/$real_symbol:Stability_Level";
3427                         } elsif ($params[$k] eq "section_id") {
3428                             $key = "$TMPL_DIR/$real_symbol:Section_Id";
3429                         } elsif ($params[$k] eq "include") {
3430                             $key = "$TMPL_DIR/$real_symbol:Include";
3431                         }
3432                         if (defined($key)) {
3433                             $SourceSymbolDocs{$key}=$params[$k+1];
3434                             $SourceSymbolSourceFile{$key} = $file;
3435                             $SourceSymbolSourceLine{$key} = $.;
3436                         }
3437                     }
3438                     $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
3439                     $SourceSymbolSourceFile{"$TMPL_DIR/$real_symbol:Long_Description"} = $file;
3440                     $SourceSymbolSourceLine{"$TMPL_DIR/$real_symbol:Long_Description"} = $.;
3441                     #$SourceSymbolTypes{$symbol} = "SECTION";
3442                 } else {
3443                     #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
3444                     $SourceSymbolDocs{$symbol} = $description;
3445                     $SourceSymbolParams{$symbol} = [ @params ];
3446                     # FIXME $SourceSymbolTypes{$symbol} = "STRUCT,SIGNAL,ARG,FUNCTION,MACRO";
3447                     #if (defined $DeclarationTypes{$symbol}) {
3448                     #    $SourceSymbolTypes{$symbol} = $DeclarationTypes{$symbol}
3449                     #}
3450                     $SourceSymbolSourceFile{$symbol} = $file;
3451                     $SourceSymbolSourceLine{$symbol} = $.;
3452                 }
3454                 if ($since_desc) {
3455                      ($since_desc, my @extra_lines) = split ("\n", $since_desc);
3456                      $since_desc =~ s/^\s+//;
3457                      $since_desc =~ s/\s+$//;
3458                      #print "Since($symbol) : [$since_desc]\n";
3459                      $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
3460                      if(scalar @extra_lines) {
3461                          &LogWarning ($file, $., "multi-line since docs found");
3462                      }
3463                 }
3465                 if ($stability_desc) {
3466                     $stability_desc = &ParseStabilityLevel($stability_desc, $file, $., "Stability level for $symbol");
3467                     $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
3468                 }
3470                 if ($deprecated_desc) {
3471                     if (exists $Deprecated{$symbol}) {
3472                     }
3473                     else {
3474                          # don't warn for signals and properties
3475                          #if ($symbol !~ m/::?(.*)/) {
3476                          if (defined $DeclarationTypes{$symbol}) {
3477                              &LogWarning ($file, $., 
3478                                  "$symbol is deprecated in the inline comments, but no deprecation guards were found around the declaration.".
3479                                  " (See the --deprecated-guards option for gtkdoc-scan.)");
3480                          }
3481                     }
3482                     $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
3483                 }
3484             }
3486             $in_comment_block = 0;
3487             next;
3488         }
3490         # Get rid of ' * ' at start of every line in the comment block.
3491         s%^\s*\*\s?%%;
3492         # But make sure we don't get rid of the newline at the end.
3493         if (!$_) {
3494             $_ = "\n";
3495         }
3496         #print "DEBUG: scanning :$_";
3498         # If we haven't found the symbol name yet, look for it.
3499         if (!$symbol) {
3500             if (m%^\s*(SECTION:\s*\S+)%) {
3501                 $symbol = $1;
3502                 #print "SECTION DOCS found in source for : '$symbol'\n";
3503                 $ignore_broken_returns = 1;
3504             } elsif (m%^\s*([\w:-]*\w)\s*:?\s*$%) {
3505                 $symbol = $1;
3506                 #print "SYMBOL DOCS found in source for : '$symbol'\n";
3507             }
3508             next;
3509         }
3511         # If we're in the return value description, add it to the end.
3512         if ($in_return) {
3513             # If we find another valid returns line, we assume that the first
3514             # one was really part of the description.
3515             if (m/^\s*(returns:|return\s+value:)/i) {
3516                 if ($return_style eq 'broken') {
3517                     $description .= $return_start . $return_desc;
3518                 }
3519                 $return_start = $1;
3520                 if ($return_style eq 'sane') {
3521                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3522                 }
3523                 $return_style = 'sane';
3524                 $ignore_broken_returns = 1;
3525                 $return_desc = $';
3526             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3527                 $description .= $return_start . $return_desc;
3528                 $return_start = $1;
3529                 $return_style = 'broken';
3530                 $return_desc = $';
3531             } elsif (m%^\s*since:%i) {
3532                 $since_desc = $';
3533                 $in_since = 1;
3534                 $in_return = 0;
3535             } elsif (m%^\s*stability:%i) {
3536                 $stability_desc = $';
3537                 $in_stability = 1;
3538                 $in_return = 0;
3539             } elsif (m%^\s*deprecated:%i) {
3540                 $deprecated_desc = $';
3541                 $in_deprecated = 1;
3542                 $in_return = 0;
3543             } else {
3544                 $return_desc .= $_;
3545             }
3546             next;
3547         }
3549         if ($in_since) {
3550             if (m/^\s*(returns:|return\s+value:)/i) {
3551                 if ($return_style eq 'broken') {
3552                     $description .= $return_start . $return_desc;
3553                 }
3554                 $return_start = $1;
3555                 if ($return_style eq 'sane') {
3556                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3557                 }
3558                 $return_style = 'sane';
3559                 $ignore_broken_returns = 1;
3560                 $return_desc = $';
3561                 $in_return = 1;
3562                 $in_since = 0;
3563             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3564                 $return_start = $1;
3565                 $return_style = 'broken';
3566                 $return_desc = $';
3567                 $in_return = 1;
3568                 $in_since = 0;
3569             } elsif (m%^\s*deprecated:%i) {
3570                 $deprecated_desc = $';
3571                 $in_deprecated = 1;
3572                 $in_since = 0;
3573             } elsif (m%^\s*stability:%i) {
3574                 $stability_desc = $';
3575                 $in_stability = 1;
3576                 $in_since = 0;
3577             } else {
3578                 $since_desc .= $_;
3579             }
3580             next;
3581         }
3583         if ($in_stability) {
3584             if (m/^\s*(returns:|return\s+value:)/i) {
3585                 if ($return_style eq 'broken') {
3586                     $description .= $return_start . $return_desc;
3587                 }
3588                 $return_start = $1;
3589                 if ($return_style eq 'sane') {
3590                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3591                 }
3592                 $return_style = 'sane';
3593                 $ignore_broken_returns = 1;
3594                 $return_desc = $';
3595                 $in_return = 1;
3596                 $in_stability = 0;
3597             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3598                 $return_start = $1;
3599                 $return_style = 'broken';
3600                 $return_desc = $';
3601                 $in_return = 1;
3602                 $in_stability = 0;
3603             } elsif (m%^\s*deprecated:%i) {
3604                 $deprecated_desc = $';
3605                 $in_deprecated = 1;
3606                 $in_stability = 0;
3607             } elsif (m%^\s*since:%i) {
3608                 $since_desc = $';
3609                 $in_since = 1;
3610                 $in_stability = 0;
3611             } else {
3612                 $stability_desc .= $_;
3613             }
3614             next;
3615         }
3617         if ($in_deprecated) {
3618             if (m/^\s*(returns:|return\s+value:)/i) {
3619                 if ($return_style eq 'broken') {
3620                     $description .= $return_start . $return_desc;
3621                 }
3622                 $return_start = $1;
3623                 if ($return_style eq 'sane') {
3624                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3625                 }
3626                 $return_style = 'sane';
3627                 $ignore_broken_returns = 1;
3628                 $return_desc = $';
3629                 $in_return = 1;
3630                 $in_deprecated = 0;
3631             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3632                 $return_start = $1;
3633                 $return_style = 'broken';
3634                 $return_desc = $';
3635                 $in_return = 1;
3636                 $in_deprecated = 0;
3637             } elsif (m%^\s*since:%i) {
3638                 $since_desc = $';
3639                 $in_since = 1;
3640                 $in_deprecated = 0;
3641             } elsif (m%^\s*stability:%i) {
3642                 $stability_desc = $';
3643                 $in_stability = 1;
3644                 $in_deprecated = 0;
3645             } else {
3646                 $deprecated_desc .= $_;
3647             }
3648             next;
3649         }
3651         # If we're in the description part, check for the 'Returns:' line.
3652         # If that isn't found, add the text to the end.
3653         if ($in_description) {
3654             # Get rid of 'Description:'
3655             s%^\s*Description:%%;
3657             if (m/^\s*(returns:|return\s+value:)/i) {
3658                 if ($return_style eq 'broken') {
3659                     $description .= $return_start . $return_desc;
3660                 }
3661                 $return_start = $1;
3662                 if ($return_style eq 'sane') {
3663                     &LogWarning ($file, $., "Multiple Returns for $symbol.");
3664                 }
3665                 $return_style = 'sane';
3666                 $ignore_broken_returns = 1;
3667                 $return_desc = $';
3668                 $in_return = 1;
3669                 next;
3670             } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3671                 $return_start = $1;
3672                 $return_style = 'broken';
3673                 $return_desc = $';
3674                 $in_return = 1;
3675                 next;
3676             } elsif (m%^\s*since:%i) {
3677                 $since_desc = $';
3678                 $in_since = 1;
3679                 next;
3680             } elsif (m%^\s*deprecated:%i) {
3681                 $deprecated_desc = $';
3682                 $in_deprecated = 1;
3683                 next;
3684             } elsif (m%^\s*stability:%i) {
3685                 $stability_desc = $';
3686                 $in_stability = 1;
3687                 next;
3688             }
3690             $description .= $_;
3691             next;
3692         }
3694         # We must be in the parameters. Check for the empty line below them.
3695         if (m%^\s*$%) {
3696             $in_description = 1;
3697             next;
3698         }
3700         # Look for a parameter name.
3701         if (m%^\s*@(\S+)\s*:%) {
3702             my $param_name = $1;
3703             my $param_desc = $';
3704             #print "Found parameter: $param_name\n";
3705             # Allow '...' as the Varargs parameter.
3706             if ($param_name eq "...") {
3707                 $param_name = "Varargs";
3708             }
3709             if ("\L$param_name" eq "returns") {
3710                 $return_style = 'sane';
3711                 $ignore_broken_returns = 1;
3712             }
3713             push (@params, $param_name);
3714             push (@params, $param_desc);
3715             $current_param += $PARAM_FIELD_COUNT;
3716             next;
3717         }
3719         # We must be in the middle of a parameter description, so add it on
3720         # to the last element in @params.
3721         if ($current_param == -1) {
3722             &LogWarning ($file, $., "Parsing comment block file : parameter expected.");
3723         } else {
3724             $params[$#params] .= $_;
3725         }
3726     }
3727     close (SRCFILE);
3730 #############################################################################
3731 # Function    : OutputMissingDocumentation
3732 # Description : Outputs report of documentation coverage to a file
3734 # Arguments   : none
3735 #############################################################################
3737 sub OutputMissingDocumentation {
3738     my $n_documented = 0;
3739     my $n_incomplete = 0;
3740     my $total = 0;
3741     my $symbol;
3742     my $percent;
3743     my $msg;
3744     my $buffer = "";
3745     my $buffer_deprecated = "";
3746     my $buffer_descriptions = "";
3747     
3748     open (UNDOCUMENTED, ">$ROOT_DIR/$MODULE-undocumented.txt")
3749       || die "Can't create $ROOT_DIR/$MODULE-undocumented.txt: $!";
3750     
3751     foreach $symbol (sort (keys (%AllSymbols))) {
3752         # FIXME: should we print LogWarnings for undocumented stuff?
3753         # DEBUG
3754         #my $ssfile = &GetSymbolSourceFile($symbol);
3755         #my $ssline = &GetSymbolSourceLine($symbol);
3756         #my $location = "defined at " . (defined($ssfile)?$ssfile:"?") . ":" . (defined($ssline)?$ssline:"0") . "\n";
3757         # DEBUG
3758         if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include|Section_Id)/) {
3759             $total++;
3760             if (exists ($AllDocumentedSymbols{$symbol})) {
3761                 $n_documented++;
3762                 if (exists ($AllIncompleteSymbols{$symbol})) {
3763                     $n_incomplete++;
3764                     $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3765                     #$buffer .= "\t0: ".$location;
3766                 }
3767             } elsif (exists $Deprecated{$symbol}) {
3768                 if (exists ($AllIncompleteSymbols{$symbol})) {
3769                     $n_incomplete++;
3770                     $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3771                     #$buffer .= "\t1a: ".$location;
3772                 } else {
3773                     $buffer_deprecated .= $symbol . "\n";
3774                     #$buffer .= "\t1b: ".$location;
3775                 }
3776             } else {
3777                 if (exists ($AllIncompleteSymbols{$symbol})) {
3778                     $n_incomplete++;
3779                     $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3780                     #$buffer .= "\t2a: ".$location;
3781                 } else {
3782                     $buffer .= $symbol . "\n";
3783                     #$buffer .= "\t2b: ".$location;
3784                 }
3785             }
3786         } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
3787             $total++;
3788             #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
3789             #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
3790             #print "%%%% $symbol : $len1,$len2\n";
3791             if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
3792             || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
3793               $n_documented++;
3794             } else {
3795               # cut off the leading namespace ($TMPL_DIR)
3796               $symbol =~ m/^.*\/(.*)$/;
3797               $buffer_descriptions .= $1 . "\n";
3798             }
3799         }
3800     }
3801     
3802     $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
3803     
3804     if ($total == 0) {
3805       $percent = 100;
3806     } else {
3807       $percent = ($n_documented / $total) * 100.0;
3808     }
3809     
3810     printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
3811     print UNDOCUMENTED "$n_documented symbols documented.\n";
3812     print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
3813     print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
3814     
3815     print UNDOCUMENTED $buffer;
3816     
3817     close (UNDOCUMENTED);
3818     
3819     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);
3823 #############################################################################
3824 # Function    : OutputUndeclaredSymbols
3825 # Description : Outputs symbols that are undeclared yet documented to a file
3827 # Arguments   : none
3828 #############################################################################
3830 sub OutputUndeclaredSymbols {
3831     open(UNDECLARED, ">$ROOT_DIR/$MODULE-undeclared.txt")
3832         || die "Can't create $ROOT_DIR/$MODULE-undeclared.txt";
3834     if (%UndeclaredSymbols) {
3835         print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
3836         print UNDECLARED "\n";
3837         print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
3838     }
3839     close(UNDECLARED);
3843 #############################################################################
3844 # Function    : OutputAllSymbols
3845 # Description : Outputs list of all symbols to a file
3847 # Arguments   : none
3848 #############################################################################
3850 sub OutputAllSymbols {
3851      my $n_documented = 0;
3852      my $total = 0;
3853      my $symbol;
3854      my $percent;
3855      my $msg;
3857      open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
3858           || die "Can't create $ROOT_DIR/$MODULE-symbols.txt: $!";
3860      foreach $symbol (sort (keys (%AllSymbols))) {
3861           print SYMBOLS $symbol . "\n";
3862      }
3864      close (SYMBOLS);
3867 #############################################################################
3868 # Function    : OutputSymbolsWithoutSince
3869 # Description : Outputs list of all symbols without a since tag to a file
3871 # Arguments   : none
3872 #############################################################################
3874 sub OutputSymbolsWithoutSince {
3875      my $n_documented = 0;
3876      my $total = 0;
3877      my $symbol;
3878      my $percent;
3879      my $msg;
3881      open (SYMBOLS, ">$ROOT_DIR/$MODULE-nosince.txt")
3882           || die "Can't create $ROOT_DIR/$MODULE-nosince.txt: $!";
3884      foreach $symbol (sort (keys (%SourceSymbolDocs))) {
3885          if (!defined $Since{$symbol}) {
3886              print SYMBOLS $symbol . "\n";
3887          }
3888      }
3890      close (SYMBOLS);
3894 #############################################################################
3895 # Function    : MergeSourceDocumentation
3896 # Description : This merges documentation read from a source file into the
3897 #               documentation read in from a template file.
3899 #               Parameter descriptions override any in the template files.
3900 #               Function descriptions are placed before any description from
3901 #               the template files.
3903 # Arguments   : none
3904 #############################################################################
3906 sub MergeSourceDocumentation {
3907     my $symbol;
3908     my @Symbols;
3910     if (scalar %SymbolDocs) {
3911         @Symbols=keys (%SymbolDocs);
3912         #print "num existing entries: ".(scalar @Symbols)."\n";
3913         #print "  ",$Symbols[0], " ",$Symbols[1],"\n";
3914     }
3915     else {
3916         # filter scanned declarations, with what we suppress from -sections.txt
3917         my %tmp = ();
3918         foreach $symbol (keys (%Declarations)) {
3919             if (defined($KnownSymbols{$symbol}) && $KnownSymbols{$symbol} == 1) {
3920                 $tmp{$symbol}=1;
3921             }
3922         }
3923         # , add the rest from -sections.txt
3924         foreach $symbol (keys (%KnownSymbols)) {
3925             if ($KnownSymbols{$symbol} == 1) {
3926                 $tmp{$symbol}=1;
3927             }
3928         }
3929         # and add whats found in the source
3930         foreach $symbol (keys (%SourceSymbolDocs)) {
3931             $tmp{$symbol}=1;
3932         }
3933         @Symbols = keys (%tmp);
3934         #print "num source entries: ".(scalar @Symbols)."\n";
3935     }
3936     foreach $symbol (@Symbols) {
3937         $AllSymbols{$symbol} = 1;
3939         my $have_tmpl_docs = 0;
3941         ## See if the symbol is documented in template
3942         my $tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
3943         my $check_tmpl_doc =$tmpl_doc;
3944         # remove all xml-tags and whitespaces
3945         #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
3946         $check_tmpl_doc =~ s/<.*?>//g;
3947         $check_tmpl_doc =~ s/\s//g;
3948         # anything left ?
3949         if ($check_tmpl_doc ne "") {
3950             $have_tmpl_docs = 1;
3951             #print "## [$check_tmpl_doc]\n";
3952         } else {
3953             $tmpl_doc = "";
3954         }
3956         if (exists ($SourceSymbolDocs{$symbol})) {
3957             my $type = $DeclarationTypes {$symbol};
3959             #print "merging [$symbol] from source\n";
3961             my $item = "Parameter";
3962             if (defined ($type)) {
3963                 if ($type eq 'STRUCT') {
3964                     $item = "Field";
3965                 } elsif ($type eq 'ENUM') {
3966                     $item = "Value";
3967                 } elsif ($type eq 'UNION') {
3968                     $item = "Field";
3969                 }
3970             } else {
3971                 $type="SIGNAL";
3972             }
3974             my $src_doc = $SourceSymbolDocs{$symbol};
3975             # remove leading and training whitespaces
3976             $src_doc =~ s/^\s+//;
3977             $src_doc =~ s/\s+$//;
3979             # Don't output warnings for overridden titles as titles are
3980             # automatically generated in the -sections.txt file, and thus they
3981             # are often overridden.
3982             if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
3983                 # check if content is different
3984                 if ($tmpl_doc ne $src_doc) {
3985                     #print "[$tmpl_doc] [$src_doc]\n";
3986                     &LogWarning ($SourceSymbolSourceFile{$symbol}, $SourceSymbolSourceLine{$symbol},
3987                         "Documentation in template ".$SymbolSourceFile{$symbol}.":".$SymbolSourceLine{$symbol}." for $symbol being overridden by inline comments.");
3988                 }
3989             }
3991             if ($src_doc ne "") {
3992                  $AllDocumentedSymbols{$symbol} = 1;
3993             }
3995             # Convert <!--PARAMETERS--> with any blank lines around it to
3996             # a </para> followed by <!--PARAMETERS--> followed by <para>.
3997             $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
3999             # If there is a blank line, finish the paragraph and start another.
4000             $src_doc = &ConvertBlankLines ($src_doc, $symbol);
4001             # Do not add <para> to nothing, it breaks missing docs checks.
4002             my $src_doc_para = "";
4003             if ($src_doc) {
4004                 $src_doc_para = "<para>\n$src_doc</para>\n";
4005                 #print "$symbol : [$src_doc][$src_doc_para]\n";
4006             }
4008             if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
4009                 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4010             } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
4011                 # For the title/summary/see also section docs we don't want to
4012                 # add any <para> tags.
4013                 $SymbolDocs{$symbol} = "$src_doc"
4014             } else {
4015                 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4016             }
4018             # merge parameters
4019             if ($symbol =~ m/.*::.*/) {
4020                 # For signals we prefer the param names from the source docs,
4021                 # since the ones from the templates are likely to contain the
4022                 # artificial argn names which are generated by gtkdoc-scangobj.
4023                 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4024                 # FIXME: we need to check for empty docs here as well!
4025             } else {
4026                 # The templates contain the definitive parameter names and order,
4027                 # so we will not change that. We only override the actual text.
4028                 my $tmpl_params = $SymbolParams{$symbol};
4029                 if (!defined ($tmpl_params)) {
4030                     #print "No merge needed for $symbol\n";
4031                     $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4032                     #  FIXME: we still like to get the number of params and merge
4033                     #  1) we would noticed that params have been removed/renamed
4034                     #  2) we would catch undocumented params
4035                     #  params are not (yet) exported in -decl.txt so that we
4036                     #  could easily grab them :/
4037                 } else {
4038                     my $params = $SourceSymbolParams{$symbol};
4039                     my $j;
4040                     #print "Merge needed for $symbol, tmpl_params: ",$#$tmpl_params,", source_params: ",$#$params," \n";
4041                     for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4042                         my $tmpl_param_name = $$tmpl_params[$j];
4044                         # Allow '...' as the Varargs parameter.
4045                         if ($tmpl_param_name eq "...") {
4046                             $tmpl_param_name = "Varargs";
4047                         }
4049                         # Try to find the param in the source comment documentation.
4050                         my $found = 0;
4051                         my $k;
4052                         #print "  try merge param $tmpl_param_name\n";
4053                         for ($k = 0; $k <= $#$params; $k += $PARAM_FIELD_COUNT) {
4054                             my $param_name = $$params[$k];
4055                             my $param_desc = $$params[$k + 1];
4057                             #print "    test param  $param_name\n";
4058                             # We accept changes in case, since the Gnome source
4059                             # docs contain a lot of these.
4060                             if ("\L$param_name" eq "\L$tmpl_param_name") {
4061                                 $found = 1;
4063                                 # Override the description.
4064                                 $$tmpl_params[$j + 1] = $param_desc;
4066                                 # Set the name to "" to mark it as used.
4067                                 $$params[$k] = "";
4068                                 last;
4069                             }
4070                         }
4072                         # If it looks like the parameters are there, but not
4073                         # in the right place, try to explain a bit better.
4074                         if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
4075                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4076                                 "Parameters for $symbol must start on the line immediately after the function or macro name.");
4077                         }
4078                     }
4080                     # Now we output a warning if parameters have been described which
4081                     # do not exist.
4082                     for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
4083                         my $param_name = $$params[$j];
4084                         if ($param_name) {
4085                             # the template builder cannot detect if a macro returns
4086                             # a result or not
4087                             if(($type eq "MACRO") && ($param_name eq "Returns")) {
4088                                 # FIXME: do we need to add it then to tmpl_params[] ?
4089                                 my $num=$#$tmpl_params;
4090                                 #print "  adding Returns: to macro docs for $symbol.\n";
4091                                 $$tmpl_params[$num+1]="Returns";
4092                                 $$tmpl_params[$num+2]=$$params[$j+1];
4093                                 next;
4094                             }
4095                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4096                                 "$item described in source code comment block but does not exist. $type: $symbol $item: $param_name.");
4097                         }
4098                     }
4099                 }
4100             }
4101         } else {
4102             if ($have_tmpl_docs) {
4103                 $AllDocumentedSymbols{$symbol} = 1;
4104                 #print "merging [$symbol] from template\n";
4105             }
4106             else {
4107                 #print "[$symbol] undocumented\n";
4108             }
4109         }
4111         # if this symbol is documented, check if docs are complete
4112         $check_tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4113         # remove all xml-tags and whitespaces
4114         #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
4115         $check_tmpl_doc =~ s/<.*?>//g;
4116         $check_tmpl_doc =~ s/\s//g;
4117         if ($check_tmpl_doc ne "") {
4118             my $tmpl_params = $SymbolParams{$symbol};
4119             if (defined ($tmpl_params)) {
4120                 my $type = $DeclarationTypes {$symbol};
4122                 my $item = "Parameter";
4123                 if (defined ($type)) {
4124                     if ($type eq 'STRUCT') {
4125                         $item = "Field";
4126                     } elsif ($type eq 'ENUM') {
4127                         $item = "Value";
4128                     } elsif ($type eq 'UNION') {
4129                         $item = "Field";
4130                     }
4131                 } else {
4132                     $type="SIGNAL";
4133                 }
4135                 #print "Check param docs for $symbol, tmpl_params: ",$#$tmpl_params," entries, type=$type\n";
4137                 if ($#$tmpl_params > 0) {
4138                     my $j;
4139                     for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4140                         # Output a warning if the parameter is empty and
4141                         # remember for stats.
4142                         my $tmpl_param_name = $$tmpl_params[$j];
4143                         my $tmpl_param_desc = $$tmpl_params[$j + 1];
4144                         if ($tmpl_param_desc !~ m/\S/) {
4145                             if (exists ($AllIncompleteSymbols{$symbol})) {
4146                                 $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
4147                             } else {
4148                                 $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
4149                             }
4150                             &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4151                                 "$item description for $symbol"."::"."$tmpl_param_name is missing in source code comment block.");
4152                         }
4153                     }
4154                 }
4155                 else {
4156                     if ($#$tmpl_params == 0) {
4157                         $AllIncompleteSymbols{$symbol}="<items>";
4158                         &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4159                             "$item descriptions for $symbol are missing in source code comment block.");
4160                     }
4161                     # $#$tmpl_params==-1 means we don't know about parameters
4162                     # this unfortunately does not tell if there should be some
4163                 }
4164             }
4165         }
4166    }
4167    #print "num doc entries: ".(scalar %SymbolDocs)."\n";
4170 #############################################################################
4171 # Function    : IsEmptyDoc
4172 # Description : Check if a doc-string is empty. Its also regarded as empty if
4173 #               it only consist of whitespace or e.g. FIXME.
4174 # Arguments   : the doc-string
4175 #############################################################################
4176 sub IsEmptyDoc {
4177     my ($doc) = @_;
4178     
4179     if ($doc =~ /^\s*$/) {
4180         return 1;
4181     }
4183     if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
4184         return 1;
4185     }
4187     return 0;
4191 # This converts blank lines to "</para><para>", but only outside CDATA and
4192 # <programlisting> tags.
4193 sub ConvertBlankLines {
4194     return &ModifyXMLElements ($_[0], $_[1],
4195                                "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
4196                                \&ConvertBlankLinesEndTag,
4197                                \&ConvertBlankLinesCallback);
4201 sub ConvertBlankLinesEndTag {
4202   if ($_[0] eq "<!\[CDATA\[") {
4203     return "]]>";
4204   } elsif ($_[0] eq "|[") {
4205     return "]\\|";
4206   } else {
4207     return "</programlisting>";
4208   }
4211 sub ConvertBlankLinesCallback {
4212   my ($text, $symbol, $tag) = @_;
4214   # If we're not in CDATA or a <programlisting> we convert blank lines so
4215   # they start a new <para>.
4216   if ($tag eq "") {
4217     $text =~ s%\n{2,}%\n</para>\n<para>\n%g;
4218   }
4220   return $text;
4224 #############################################################################
4225 # LIBRARY FUNCTIONS -   These functions are used in both gtkdoc-mkdb and
4226 #                       gtkdoc-mktmpl and should eventually be moved to a
4227 #                       separate library.
4228 #############################################################################
4230 #############################################################################
4231 # Function    : ReadDeclarationsFile
4232 # Description : This reads in a file containing the function/macro/enum etc.
4233 #               declarations.
4235 #               Note that in some cases there are several declarations with
4236 #               the same name, e.g. for conditional macros. In this case we
4237 #               set a flag in the %DeclarationConditional hash so the
4238 #               declaration is not shown in the docs.
4240 #               If a macro and a function have the same name, e.g. for
4241 #               gtk_object_ref, the function declaration takes precedence.
4243 #               Some opaque structs are just declared with 'typedef struct
4244 #               _name name;' in which case the declaration may be empty.
4245 #               The structure may have been found later in the header, so
4246 #               that overrides the empty declaration.
4248 # Arguments   : $file - the declarations file to read
4249 #               $override - if declarations in this file should override
4250 #                       any current declaration.
4251 #############################################################################
4253 sub ReadDeclarationsFile {
4254     my ($file, $override) = @_;
4256     if ($override == 0) {
4257         %Declarations = ();
4258         %DeclarationTypes = ();
4259         %DeclarationConditional = ();
4260         %DeclarationOutput = ();
4261     }
4263     open (INPUT, $file)
4264         || die "Can't open $file: $!";
4265     my $declaration_type = "";
4266     my $declaration_name;
4267     my $declaration;
4268     my $is_deprecated = 0;
4269     while (<INPUT>) {
4270         if (!$declaration_type) {
4271             if (m/^<([^>]+)>/) {
4272                 $declaration_type = $1;
4273                 $declaration_name = "";
4274                 #print "Found declaration: $declaration_type\n";
4275                 $declaration = "";
4276             }
4277         } else {
4278             if (m%^<NAME>(.*)</NAME>%) {
4279                 $declaration_name = $1;
4280             } elsif (m%^<DEPRECATED/>%) {
4281                 $is_deprecated = 1;
4282             } elsif (m%^</$declaration_type>%) {
4283                 #print "Found end of declaration: $declaration_name\n";
4284                 # Check that the declaration has a name
4285                 if ($declaration_name eq "") {
4286                     print "ERROR: $declaration_type has no name $file:$.\n";
4287                 }
4289                 # If the declaration is an empty typedef struct _XXX XXX
4290                 # set the flag to indicate the struct has a typedef.
4291                 if ($declaration_type eq 'STRUCT'
4292                     && $declaration =~ m/^\s*$/) {
4293                     #print "Struct has typedef: $declaration_name\n";
4294                     $StructHasTypedef{$declaration_name} = 1;
4295                 }
4297                 # Check if the symbol is already defined.
4298                 if (defined ($Declarations{$declaration_name})
4299                     && $override == 0) {
4300                     # Function declarations take precedence.
4301                     if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
4302                         # Ignore it.
4303                     } elsif ($declaration_type eq 'FUNCTION') {
4304                         if ($is_deprecated) {
4305                             $Deprecated{$declaration_name} = "";
4306                         }
4307                         $Declarations{$declaration_name} = $declaration;
4308                         $DeclarationTypes{$declaration_name} = $declaration_type;
4309                     } elsif ($DeclarationTypes{$declaration_name}
4310                               eq $declaration_type) {
4311                         # If the existing declaration is empty, or is just a
4312                         # forward declaration of a struct, override it.
4313                         if ($declaration_type eq 'STRUCT') {
4314                             if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4315                                 if ($is_deprecated) {
4316                                     $Deprecated{$declaration_name} = "";
4317                                 }
4318                                 $Declarations{$declaration_name} = $declaration;
4319                             } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4320                                 # Ignore an empty or forward declaration.
4321                             } else {
4322                                 &LogWarning ($file, $., "Structure $declaration_name has multiple definitions.");
4323                             }
4324                         } else {
4325                             # set flag in %DeclarationConditional hash for
4326                             # multiply defined macros/typedefs.
4327                             $DeclarationConditional{$declaration_name} = 1;
4328                         }
4329                     } else {
4330                         &LogWarning ($file, $., "$declaration_name has multiple definitions.");
4331                     }
4332                 } else {
4333                     if ($is_deprecated) {
4334                         $Deprecated{$declaration_name} = "";
4335                     }
4336                     $Declarations{$declaration_name} = $declaration;
4337                     $DeclarationTypes{$declaration_name} = $declaration_type;
4338                 }
4340                 $declaration_type = "";
4341                 $is_deprecated = 0;
4342             } else {
4343                 $declaration .= $_;
4344             }
4345         }
4346     }
4347     close (INPUT);
4351 #############################################################################
4352 # Function    : ReadSignalsFile
4353 # Description : This reads in an existing file which contains information on
4354 #               all GTK signals. It creates the arrays @SignalNames and
4355 #               @SignalPrototypes containing info on the signals. The first
4356 #               line of the SignalPrototype is the return type of the signal
4357 #               handler. The remaining lines are the parameters passed to it.
4358 #               The last parameter, "gpointer user_data" is always the same
4359 #               so is not included.
4360 # Arguments   : $file - the file containing the signal handler prototype
4361 #                       information.
4362 #############################################################################
4364 sub ReadSignalsFile {
4365     my ($file) = @_;
4367     my $in_signal = 0;
4368     my $signal_object;
4369     my $signal_name;
4370     my $signal_returns;
4371     my $signal_flags;
4372     my $signal_prototype;
4374     # Reset the signal info.
4375     @SignalObjects = ();
4376     @SignalNames = ();
4377     @SignalReturns = ();
4378     @SignalFlags = ();
4379     @SignalPrototypes = ();
4381     if (! -f $file) {
4382         return;
4383     }
4384     if (!open (INPUT, $file)) {
4385         warn "Can't open $file - skipping signals\n";
4386         return;
4387     }
4388     while (<INPUT>) {
4389         if (!$in_signal) {
4390             if (m/^<SIGNAL>/) {
4391                 $in_signal = 1;
4392                 $signal_object = "";
4393                 $signal_name = "";
4394                 $signal_returns = "";
4395                 $signal_prototype = "";
4396             }
4397         } else {
4398             if (m/^<NAME>(.*)<\/NAME>/) {
4399                 $signal_name = $1;
4400                 if ($signal_name =~ m/^(.*)::(.*)$/) {
4401                     $signal_object = $1;
4402                     ($signal_name = $2) =~ s/_/-/g;
4403                     #print "Found signal: $signal_name\n";
4404                 } else {
4405                     &LogWarning ($file, $., "Invalid signal name: $signal_name.");
4406                 }
4407             } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
4408                 $signal_returns = $1;
4409             } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4410                 $signal_flags = $1;
4411             } elsif (m%^</SIGNAL>%) {
4412                 #print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
4413                 push (@SignalObjects, $signal_object);
4414                 push (@SignalNames, $signal_name);
4415                 push (@SignalReturns, $signal_returns);
4416                 push (@SignalFlags, $signal_flags);
4417                 push (@SignalPrototypes, $signal_prototype);
4418                 $in_signal = 0;
4419             } else {
4420                 $signal_prototype .= $_;
4421             }
4422         }
4423     }
4424     close (INPUT);
4428 #############################################################################
4429 # Function    : ReadTemplateFile
4430 # Description : This reads in the manually-edited documentation file
4431 #               corresponding to the file currently being created, so we can
4432 #               insert the documentation at the appropriate places.
4433 #               It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
4434 #               is a hash of arrays.
4435 #               NOTE: This function is duplicated in gtkdoc-mktmpl (but
4436 #               slightly different).
4437 # Arguments   : $docsfile - the template file to read in.
4438 #               $skip_unused_params - 1 if the unused parameters should be
4439 #                       skipped.
4440 #############################################################################
4442 sub ReadTemplateFile {
4443     my ($docsfile, $skip_unused_params) = @_;
4445     my $template = "$docsfile.sgml";
4446     if (! -f $template) {
4447         #print "File doesn't exist: $template\n";
4448         return 0;
4449     }
4450     #print "Reading $template\n";
4452     # start with empty hashes, we merge the source comment for each file
4453     # afterwards
4454     %SymbolDocs = ();
4455     %SymbolTypes = ();
4456     %SymbolParams = ();
4458     my $current_type = "";      # Type of symbol being read.
4459     my $current_symbol = "";    # Name of symbol being read.
4460     my $symbol_doc = "";                # Description of symbol being read.
4461     my @params;                 # Parameter names and descriptions of current
4462                                 #   function/macro/function typedef.
4463     my $current_param = -1;     # Index of parameter currently being read.
4464                                 #   Note that the param array contains pairs
4465                                 #   of param name & description.
4466     my $in_unused_params = 0;   # True if we are reading in the unused params.
4467     my $in_deprecated = 0;
4468     my $in_since = 0;
4469     my $in_stability = 0;
4471     open (DOCS, "$template")
4472         || die "Can't open $template: $!";
4473     while (<DOCS>) {
4474         if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
4475             my $type = $1;
4476             my $symbol = $2;
4477             if ($symbol eq "Title"
4478                 || $symbol eq "Short_Description"
4479                 || $symbol eq "Long_Description"
4480                 || $symbol eq "See_Also"
4481                 || $symbol eq "Stability_Level"
4482                 || $symbol eq "Include") {
4484                 $symbol = $docsfile . ":" . $symbol;
4485             }
4487             #print "Found symbol: $symbol\n";
4488             # Remember file and line for the symbol
4489             $SymbolSourceFile{$symbol} = $template;
4490             $SymbolSourceLine{$symbol} = $.;
4492             # Store previous symbol, but remove any trailing blank lines.
4493             if ($current_symbol ne "") {
4494                 $symbol_doc =~ s/\s+$//;
4495                 $SymbolTypes{$current_symbol} = $current_type;
4496                 $SymbolDocs{$current_symbol} = $symbol_doc;
4498                 # Check that the stability level is valid.
4499                 if ($StabilityLevel{$current_symbol}) {
4500                     $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4501                 }
4503                 if ($current_param >= 0) {
4504                     $SymbolParams{$current_symbol} = [ @params ];
4505                 } else {
4506                     # Delete any existing params in case we are overriding a
4507                     # previously read template.
4508                     delete $SymbolParams{$current_symbol};
4509                 }
4510             }
4511             $current_type = $type;
4512             $current_symbol = $symbol;
4513             $current_param = -1;
4514             $in_unused_params = 0;
4515             $in_deprecated = 0;
4516             $in_since = 0;
4517             $in_stability = 0;
4518             $symbol_doc = "";
4519             @params = ();
4521         } elsif (m/^<!-- # Unused Parameters # -->/) {
4522             #print "DEBUG: Found unused parameters\n";
4523             $in_unused_params = 1;
4524             next;
4526         } elsif ($in_unused_params && $skip_unused_params) {
4527             # When outputting the DocBook we skip unused parameters.
4528             #print "DEBUG: Skipping unused param: $_";
4529             next;
4531         } else {
4532             # Check if param found. Need to handle "..." and "format...".
4533             if (s/^\@([\w\.]+):\040?//) {
4534                 my $param_name = $1;
4535                 my $param_desc = $_;
4536                 # Allow variations of 'Returns'
4537                 if ($param_name =~ m/^[Rr]eturns?$/) {
4538                     $param_name = "Returns";
4539                 }
4541                 # strip trailing whitespaces and blank lines
4542                 s/\s+\n$/\n/m;
4543                 s/\n+$/\n/sm;
4544                 #print "Found param for symbol $current_symbol : '$param_name'= '$_'";
4546                 if ($param_name eq "Deprecated") {
4547                     $in_deprecated = 1;
4548                     $Deprecated{$current_symbol} = $_;
4549                 } elsif ($param_name eq "Since") {
4550                     $in_since = 1;
4551                     chomp;
4552                     $Since{$current_symbol} = $_;
4553                 } elsif ($param_name eq "Stability") {
4554                     $in_stability = 1;
4555                     $StabilityLevel{$current_symbol} = $_;
4556                 } else {
4557                     push (@params, $param_name);
4558                     push (@params, $param_desc);
4559                     $current_param += $PARAM_FIELD_COUNT;
4560                 }
4561             } else {
4562                 # strip trailing whitespaces and blank lines
4563                 s/\s+\n$/\n/m;
4564                 s/\n+$/\n/sm;
4565                 
4566                 if (!m/^\s+$/) {
4567                     if ($in_deprecated) {
4568                         $Deprecated{$current_symbol} .= $_;
4569                     } elsif ($in_since) {
4570                         &LogWarning ($template, $., "multi-line since docs found");
4571                         #$Since{$current_symbol} .= $_;
4572                     } elsif ($in_stability) {
4573                         $StabilityLevel{$current_symbol} .= $_;
4574                     } elsif ($current_param >= 0) {
4575                         $params[$current_param] .= $_;
4576                     } else {
4577                         $symbol_doc .= $_;
4578                     }
4579                 }
4580             }
4581         }
4582     }
4584     # Remember to finish the current symbol doccs.
4585     if ($current_symbol ne "") {
4587         $symbol_doc =~ s/\s+$//;
4588         $SymbolTypes{$current_symbol} = $current_type;
4589         $SymbolDocs{$current_symbol} = $symbol_doc;
4591         # Check that the stability level is valid.
4592         if ($StabilityLevel{$current_symbol}) {
4593             $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4594         }
4596         if ($current_param >= 0) {
4597             $SymbolParams{$current_symbol} = [ @params ];
4598         } else {
4599             # Delete any existing params in case we are overriding a
4600             # previously read template.
4601             delete $SymbolParams{$current_symbol};
4602         }
4603     }
4605     close (DOCS);
4606     return 1;
4610 #############################################################################
4611 # Function    : ReadObjectHierarchy
4612 # Description : This reads in the $MODULE-hierarchy.txt file containing all
4613 #               the GtkObject subclasses described in this module (and their
4614 #               ancestors).
4615 #               It places them in the @Objects array, and places their level
4616 #               in the widget hierarchy in the @ObjectLevels array, at the
4617 #               same index. GtkObject, the root object, has a level of 1.
4619 #               FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
4620 #               as it goes along, this should be split out into a separate
4621 #               function.
4623 # Arguments   : none
4624 #############################################################################
4626 sub ReadObjectHierarchy {
4627     @Objects = ();
4628     @ObjectLevels = ();
4630     if (! -f $OBJECT_TREE_FILE) {
4631         return;
4632     }
4633     if (!open (INPUT, $OBJECT_TREE_FILE)) {
4634         warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
4635         return;
4636     }
4638     # FIXME: use $OUTPUT_FORMAT
4639     # my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.$OUTPUT_FORMAT";
4640     my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
4641     my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
4643     open (OUTPUT, ">$new_tree_index")
4644         || die "Can't create $new_tree_index: $!";
4646     if (lc($OUTPUT_FORMAT) eq "xml") {
4647         my $tree_header = $doctype_header;
4649         $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
4650         print (OUTPUT "$tree_header");
4651     }
4652     print (OUTPUT "<screen>\n");
4654     # Only emit objects if they are supposed to be documented, or if
4655     # they have documented children. To implement this, we maintain a
4656     # stack of pending objects which will be emitted if a documented
4657     # child turns up.
4658     my @pending_objects = ();
4659     my @pending_levels = ();
4660     while (<INPUT>) {
4661         if (m/\S+/) {
4662             my $object = $&;
4663             my $level = (length($`)) / 2 + 1;
4664             my $xref = "";
4666             while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
4667                 my $pobject = pop(@pending_objects);
4668                 my $plevel = pop(@pending_levels);
4669             }
4671             push (@pending_objects, $object);
4672             push (@pending_levels, $level);
4674             if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
4675                 while ($#pending_levels >= 0) {
4676                     $object = shift @pending_objects;
4677                     $level = shift @pending_levels;
4678                     $xref = &MakeXRef ($object);
4680                     print (OUTPUT ' ' x ($level * 4), "$xref\n");
4681                     push (@Objects, $object);
4682                     push (@ObjectLevels, $level);
4683                 }
4684             }
4685         }
4686     }
4687     print (OUTPUT "</screen>\n");
4689     close (INPUT);
4690     close (OUTPUT);
4692     &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
4694     &OutputObjectList;
4697 #############################################################################
4698 # Function    : ReadInterfaces
4699 # Description : This reads in the $MODULE.interfaces file.
4701 # Arguments   : none
4702 #############################################################################
4704 sub ReadInterfaces {
4705     %Interfaces = ();
4707     if (! -f $INTERFACES_FILE) {
4708         return;
4709     }
4710     if (!open (INPUT, $INTERFACES_FILE)) {
4711         warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
4712         return;
4713     }
4715     while (<INPUT>) {
4716        chomp;
4717        my ($object, @ifaces) = split;
4718        if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
4719            my @knownIfaces = ();
4721            # filter out private interfaces, but leave foreign interfaces
4722            foreach my $iface (@ifaces) {
4723                if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
4724                    push (@knownIfaces, $iface);
4725                }
4726              }
4728            $Interfaces{$object} = join(' ', @knownIfaces);
4729        }
4730     }
4731     close (INPUT);
4734 #############################################################################
4735 # Function    : ReadPrerequisites
4736 # Description : This reads in the $MODULE.prerequisites file.
4738 # Arguments   : none
4739 #############################################################################
4741 sub ReadPrerequisites {
4742     %Prerequisites = ();
4744     if (! -f $PREREQUISITES_FILE) {
4745         return;
4746     }
4747     if (!open (INPUT, $PREREQUISITES_FILE)) {
4748         warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
4749         return;
4750     }
4752     while (<INPUT>) {
4753        chomp;
4754        my ($iface, @prereqs) = split;
4755        if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
4756            my @knownPrereqs = ();
4758            # filter out private prerequisites, but leave foreign prerequisites
4759            foreach my $prereq (@prereqs) {
4760                if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
4761                   push (@knownPrereqs, $prereq);
4762                }
4763            }
4765            $Prerequisites{$iface} = join(' ', @knownPrereqs);
4766        }
4767     }
4768     close (INPUT);
4771 #############################################################################
4772 # Function    : ReadArgsFile
4773 # Description : This reads in an existing file which contains information on
4774 #               all GTK args. It creates the arrays @ArgObjects, @ArgNames,
4775 #               @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
4776 #               on the args.
4777 # Arguments   : $file - the file containing the arg information.
4778 #############################################################################
4780 sub ReadArgsFile {
4781     my ($file) = @_;
4783     my $in_arg = 0;
4784     my $arg_object;
4785     my $arg_name;
4786     my $arg_type;
4787     my $arg_flags;
4788     my $arg_nick;
4789     my $arg_blurb;
4790     my $arg_default;
4791     my $arg_range;
4793     # Reset the args info.
4794     @ArgObjects = ();
4795     @ArgNames = ();
4796     @ArgTypes = ();
4797     @ArgFlags = ();
4798     @ArgNicks = ();
4799     @ArgBlurbs = ();
4800     @ArgDefaults = ();
4801     @ArgRanges = ();
4803     if (! -f $file) {
4804         return;
4805     }
4806     if (!open (INPUT, $file)) {
4807         warn "Can't open $file - skipping args\n";
4808         return;
4809     }
4810     while (<INPUT>) {
4811         if (!$in_arg) {
4812             if (m/^<ARG>/) {
4813                 $in_arg = 1;
4814                 $arg_object = "";
4815                 $arg_name = "";
4816                 $arg_type = "";
4817                 $arg_flags = "";
4818                 $arg_nick = "";
4819                 $arg_blurb = "";
4820                 $arg_default = "";
4821                 $arg_range = "";
4822             }
4823         } else {
4824             if (m/^<NAME>(.*)<\/NAME>/) {
4825                 $arg_name = $1;
4826                 if ($arg_name =~ m/^(.*)::(.*)$/) {
4827                     $arg_object = $1;
4828                     ($arg_name = $2) =~ s/_/-/g;
4829                     #print "Found arg: $arg_name\n";
4830                 } else {
4831                     &LogWarning ($file, $., "Invalid argument name: $arg_name");
4832                 }
4833             } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
4834                 $arg_type = $1;
4835             } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
4836                 $arg_range = $1;
4837             } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4838                 $arg_flags = $1;
4839             } elsif (m/^<NICK>(.*)<\/NICK>/) {
4840                 $arg_nick = $1;
4841             } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
4842                 $arg_blurb = $1;
4843                 if ($arg_blurb eq "(null)") {
4844                   $arg_blurb = "";
4845                   &LogWarning ($file, $., "Property ${arg_object}:${arg_name} has no documentation.");
4846                 }
4847             } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
4848                 $arg_default = $1;
4849             } elsif (m%^</ARG>%) {
4850                 #print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
4851                 push (@ArgObjects, $arg_object);
4852                 push (@ArgNames, $arg_name);
4853                 push (@ArgTypes, $arg_type);
4854                 push (@ArgRanges, $arg_range);
4855                 push (@ArgFlags, $arg_flags);
4856                 push (@ArgNicks, $arg_nick);
4857                 push (@ArgBlurbs, $arg_blurb);
4858                 push (@ArgDefaults, $arg_default);
4859                 $in_arg = 0;
4860             }
4861         }
4862     }
4863     close (INPUT);
4867 #############################################################################
4868 # Function    : CheckIsObject
4869 # Description : Returns 1 if the given name is a GtkObject or a subclass.
4870 #               It uses the global @Objects array.
4871 #               Note that the @Objects array only contains classes in the
4872 #               current module and their ancestors - not all GTK classes.
4873 # Arguments   : $name - the name to check.
4874 #############################################################################
4876 sub CheckIsObject {
4877     my ($name) = @_;
4879     my $object;
4880     foreach $object (@Objects) {
4881         if ($object eq $name) {
4882             return 1;
4883         }
4884     }
4885     return 0;
4889 #############################################################################
4890 # Function    : MakeReturnField
4891 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
4892 # Arguments   : $str - the string to pad.
4893 #############################################################################
4895 sub MakeReturnField {
4896     my ($str) = @_;
4898     return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));
4901 #############################################################################
4902 # Function    : GetSymbolSourceFile
4903 # Description : Get the filename where the symbol docs where taken from.
4904 # Arguments   : $symbol - the symbol name
4905 #############################################################################
4907 sub GetSymbolSourceFile {
4908     my ($symbol) = @_;
4910     if (defined($SourceSymbolSourceFile{$symbol})) {
4911         return $SourceSymbolSourceFile{$symbol};
4912     } elsif (defined($SymbolSourceFile{$symbol})) {
4913         return $SymbolSourceFile{$symbol};
4914     } else {
4915         return "";
4916     }
4919 #############################################################################
4920 # Function    : GetSymbolSourceLine
4921 # Description : Get the file line where the symbol docs where taken from.
4922 # Arguments   : $symbol - the symbol name
4923 #############################################################################
4925 sub GetSymbolSourceLine {
4926     my ($symbol) = @_;
4928     if (defined($SourceSymbolSourceLine{$symbol})) {
4929         return $SourceSymbolSourceLine{$symbol};
4930     } elsif (defined($SymbolSourceLine{$symbol})) {
4931         return $SymbolSourceLine{$symbol};
4932     } else {
4933         return 0;
4934     }