4 # gtk-doc - GTK DocBook documentation generator.
5 # Copyright (C) 1998 Damon Chaplin
6 # 2007,2008,2009 Stefan Kost
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #############################################################################
24 # Script : gtkdoc-mkdb
25 # Description : This creates the DocBook files from the edited templates.
26 #############################################################################
31 push @INC, '@PACKAGE_DATA_DIR@';
32 require "gtkdoc-common.pl";
36 # name of documentation module
41 my $SOURCE_SUFFIXES = "";
42 my $IGNORE_FILES = "";
46 my $EXPAND_CONTENT_FILES = "";
47 my $INLINE_MARKUP_MODE;
48 my $DEFAULT_STABILITY;
52 my $OUTPUT_ALL_SYMBOLS;
53 my $OUTPUT_SYMBOLS_WITHOUT_SINCE;
55 my %optctl = ('module' => \$MODULE,
56 'source-dir' => \@SOURCE_DIRS,
57 'source-suffixes' => \$SOURCE_SUFFIXES,
58 'ignore-files' => \$IGNORE_FILES,
59 'output-dir' => \$SGML_OUTPUT_DIR,
60 'tmpl-dir' => \$TMPL_DIR,
61 'version' => \$PRINT_VERSION,
62 'help' => \$PRINT_HELP,
63 'main-sgml-file' => \$MAIN_SGML_FILE,
64 'expand-content-files' => \$EXPAND_CONTENT_FILES,
65 'sgml-mode' => \$INLINE_MARKUP_MODE,
66 'xml-mode' => \$INLINE_MARKUP_MODE,
67 'default-stability' => \$DEFAULT_STABILITY,
68 'default-includes' => \$DEFAULT_INCLUDES,
69 'output-format' => \$OUTPUT_FORMAT,
70 'name-space' => \$NAME_SPACE,
71 'outputallsymbols' => \$OUTPUT_ALL_SYMBOLS,
72 'outputsymbolswithoutsince' => \$OUTPUT_SYMBOLS_WITHOUT_SINCE
74 GetOptions(\%optctl, "module=s", "source-dir:s", "source-suffixes:s",
75 "ignore-files:s", "output-dir:s", "tmpl-dir:s", "version", "outputallsymbols",
76 "outputsymbolswithoutsince",
77 "expand-content-files:s", "main-sgml-file:s", "extra-db-files:s", "help",
78 "sgml-mode", "xml-mode", "default-stability:s", "default-includes:s",
79 "output-format:s", "name-space:s");
90 if ($DEFAULT_STABILITY && $DEFAULT_STABILITY ne "Stable"
91 && $DEFAULT_STABILITY ne "Private" && $DEFAULT_STABILITY ne "Unstable") {
97 gtkdoc-mkdb version @VERSION@ - generate docbook files
99 --module=MODULE_NAME Name of the doc module being parsed
100 --source-dir=DIRNAME Directories which contain inline reference material
101 --source-suffixes=SUFFIXES Suffixes of source files to scan, comma-separated
102 --ignore-files=FILES Files or directories which should not be scanned
103 May be used more than once for multiple directories
104 --output-dir=DIRNAME Directory to put the generated DocBook files in
105 --tmpl-dir=DIRNAME Directory in which template files may be found
106 --main-sgml-file=FILE File containing the toplevel DocBook file.
107 --expand-content-files=FILES Extra DocBook files to expand abbreviations in.
108 --output-format=FORMAT Format to use for the generated docbook, XML or SGML.
109 --{xml,sgml}-mode Allow DocBook markup in inline documentation.
110 --default-stability=LEVEL Specify default stability Level. Valid values are
111 Stable, Unstable, or Private.
112 --default-includes=FILENAMES Specify default includes for section Synopsis
113 --name-space=NS Omit namespace in index.
114 --version Print the version of this program
115 --help Print this help
120 my ($empty_element_end, $doctype_header);
122 # autodetect output format
123 if (! defined($OUTPUT_FORMAT) || ($OUTPUT_FORMAT eq "")) {
124 if (!$MAIN_SGML_FILE) {
125 if (-e "${MODULE}-docs.xml") {
126 $OUTPUT_FORMAT = "xml";
128 $OUTPUT_FORMAT = "sgml";
131 if ($MAIN_SGML_FILE =~ m/.*\.(.*ml)$/i) {
132 $OUTPUT_FORMAT = lc($1);
137 $OUTPUT_FORMAT = lc($OUTPUT_FORMAT);
140 #print "DEBUG: output-format: [$OUTPUT_FORMAT]\n";
142 if ($OUTPUT_FORMAT eq "xml") {
143 if (!$MAIN_SGML_FILE) {
144 # backwards compatibility
145 if (-e "${MODULE}-docs.sgml") {
146 $MAIN_SGML_FILE = "${MODULE}-docs.sgml";
148 $MAIN_SGML_FILE = "${MODULE}-docs.xml";
151 $empty_element_end = "/>";
153 if (-e $MAIN_SGML_FILE) {
154 open(INPUT, "<$MAIN_SGML_FILE") || die "Can't open $MAIN_SGML_FILE";
155 $doctype_header = "";
157 if (/^\s*<(book|chapter|article)/) {
158 # check that the top-level tag or the doctype decl contain the xinclude namespace decl
159 if (($_ !~ m/http:\/\/www.w3.org\/200[13]\/XInclude/) && ($doctype_header !~ m/http:\/\/www.w3.org\/200[13]\/XInclude/m)) {
160 $doctype_header = "";
164 $doctype_header .= $_;
167 $doctype_header =~ s/<!DOCTYPE \w+/<!DOCTYPE refentry/;
168 # if there are SYSTEM ENTITIES here, we should prepend "../" to the path
169 # FIXME: not sure if we can do this now, as people already work-around the problem
170 # $doctype_header =~ s#<!ENTITY % ([a-zA-Z-]+) SYSTEM \"([^/][a-zA-Z./]+)\">#<!ENTITY % $1 SYSTEM \"../$2\">#g;
173 "<?xml version=\"1.0\"?>\n" .
174 "<!DOCTYPE refentry PUBLIC \"-//OASIS//DTD DocBook XML V4.3//EN\"\n" .
175 " \"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd\"\n" .
177 " <!ENTITY % local.common.attrib \"xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'\">\n" .
181 if (!$MAIN_SGML_FILE) {
182 $MAIN_SGML_FILE = "${MODULE}-docs.sgml";
184 $empty_element_end = ">";
185 $doctype_header = "";
190 # All the files are written in subdirectories beneath here.
191 $TMPL_DIR = $TMPL_DIR ? $TMPL_DIR : "$ROOT_DIR/tmpl";
193 # This is where we put all the DocBook output.
194 $SGML_OUTPUT_DIR = $SGML_OUTPUT_DIR ? $SGML_OUTPUT_DIR : "$ROOT_DIR/$OUTPUT_FORMAT";
196 # This file contains the object hierarchy.
197 my $OBJECT_TREE_FILE = "$ROOT_DIR/$MODULE.hierarchy";
199 # This file contains the interfaces.
200 my $INTERFACES_FILE = "$ROOT_DIR/$MODULE.interfaces";
202 # This file contains the prerequisites.
203 my $PREREQUISITES_FILE = "$ROOT_DIR/$MODULE.prerequisites";
205 # This file contains signal arguments and names.
206 my $SIGNALS_FILE = "$ROOT_DIR/$MODULE.signals";
208 # The file containing Arg information.
209 my $ARGS_FILE = "$ROOT_DIR/$MODULE.args";
211 # These global arrays store information on signals. Each signal has an entry
212 # in each of these arrays at the same index, like a multi-dimensional array.
213 my @SignalObjects; # The GtkObject which emits the signal.
214 my @SignalNames; # The signal name.
215 my @SignalReturns; # The return type.
216 my @SignalFlags; # Flags for the signal
217 my @SignalPrototypes; # The rest of the prototype of the signal handler.
219 # These global arrays store information on Args. Each Arg has an entry
220 # in each of these arrays at the same index, like a multi-dimensional array.
221 my @ArgObjects; # The GtkObject which has the Arg.
222 my @ArgNames; # The Arg name.
223 my @ArgTypes; # The Arg type - gint, GtkArrowType etc.
224 my @ArgFlags; # How the Arg can be used - readable/writable etc.
225 my @ArgNicks; # The nickname of the Arg.
226 my @ArgBlurbs; # Docstring of the Arg.
227 my @ArgDefaults; # Default value of the Arg.
228 my @ArgRanges; # The range of the Arg type
229 # These global hashes store declaration info keyed on a symbol name.
231 my %DeclarationTypes;
232 my %DeclarationConditional;
233 my %DeclarationOutput;
237 my %StructHasTypedef;
239 # These global hashes store the existing documentation.
243 my %SymbolSourceFile;
244 my %SymbolSourceLine;
246 # These global hashes store documentation scanned from the source files.
247 my %SourceSymbolDocs;
248 my %SourceSymbolParams;
249 my %SourceSymbolSourceFile;
250 my %SourceSymbolSourceLine;
252 # all documentation goes in here, so we can do coverage analysis
254 my %AllIncompleteSymbols;
255 my %AllUnusedSymbols;
256 my %AllDocumentedSymbols;
258 # Undeclared yet documented symbols
259 my %UndeclaredSymbols;
261 # These global arrays store GObject, subclasses and the hierarchy (also of
262 # non-object derived types).
270 # holds the symbols which are mentioned in $MODULE-sections.txt and in which
271 # section they are defined
276 # collects index entries
277 my %IndexEntriesFull;
278 my %IndexEntriesSince;
279 my %IndexEntriesDeprecated;
281 # Standard C preprocessor directives, which we ignore for '#' abbreviations.
282 my %PreProcessorDirectives;
283 $PreProcessorDirectives{"assert"} = 1;
284 $PreProcessorDirectives{"define"} = 1;
285 $PreProcessorDirectives{"elif"} = 1;
286 $PreProcessorDirectives{"else"} = 1;
287 $PreProcessorDirectives{"endif"} = 1;
288 $PreProcessorDirectives{"error"} = 1;
289 $PreProcessorDirectives{"if"} = 1;
290 $PreProcessorDirectives{"ifdef"} = 1;
291 $PreProcessorDirectives{"ifndef"} = 1;
292 $PreProcessorDirectives{"include"} = 1;
293 $PreProcessorDirectives{"line"} = 1;
294 $PreProcessorDirectives{"pragma"} = 1;
295 $PreProcessorDirectives{"unassert"} = 1;
296 $PreProcessorDirectives{"undef"} = 1;
297 $PreProcessorDirectives{"warning"} = 1;
299 # remember used annotation (to write minimal glossary)
302 # the annotations are defined at:
303 # https://live.gnome.org/GObjectIntrospection/Annotations
304 my %AnnotationDefinition = (
305 'allow-none' => "NULL is ok, both for passing and for returning.",
306 'array' => "Parameter points to an array of items.",
307 'attribute' => "Free-form custom annotation.",
308 'closure' => "This parameter is a 'user_data', for callbacks; many bindings can pass NULL here.",
309 'default' => "Default parameter value (for in case the <acronym>shadows</acronym>-to function has less parameters).",
310 'element-type' => "Generics and defining elements of containers and arrays.",
311 'error-domains' => "Typed errors. Similar to throws in Java.",
312 'in' => "Parameter for input. Default is <acronym>transfer none</acronym>.",
313 'inout' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
314 'in-out' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
315 'not-error' => "A GError parameter is not to be handled like a normal GError.",
316 'out' => "Parameter for returning results. Default is <acronym>transfer full</acronym>.",
317 'out caller-allocates' => "Out parameter, where caller must allocate storage.",
318 'out callee-allocates' => "Out parameter, where caller must allocate storage.",
319 'transfer container' => "Free data container after the code is done.",
320 'transfer floating' => "Alias for <acronym>transfer none</acronym>, used for objects with floating refs.",
321 'transfer full' => "Free data after the code is done.",
322 'transfer none' => "Don't free data after the code is done.",
323 'scope call' => "The callback is valid only during the call to the method.",
324 'scope async' => "The callback is valid until first called.",
325 'scope notified' => "The callback is valid until the GDestroyNotify argument is called.",
326 'skip' => "Exposed in C code, not necessarily available in other languages.",
327 'type' => "Override the parsed C type with given type."
330 # Create the root DocBook output directory if it doens't exist.
331 if (! -e $SGML_OUTPUT_DIR) {
332 mkdir ("$SGML_OUTPUT_DIR", 0777)
333 || die "Can't create directory: $SGML_OUTPUT_DIR";
336 # Function and other declaration output settings.
337 my $RETURN_TYPE_FIELD_WIDTH = 20;
338 my $SYMBOL_FIELD_WIDTH = 36;
339 my $SIGNAL_FIELD_WIDTH = 16;
340 my $PARAM_FIELD_COUNT = 2;
342 &ReadKnownSymbols ("$ROOT_DIR/$MODULE-sections.txt");
343 &ReadSignalsFile ($SIGNALS_FILE);
344 &ReadArgsFile ($ARGS_FILE);
345 &ReadObjectHierarchy;
349 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-decl.txt", 0);
350 if (-f "$ROOT_DIR/$MODULE-overrides.txt") {
351 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-overrides.txt", 1);
354 for my $dir (@SOURCE_DIRS) {
355 &ReadSourceDocumentation ($dir);
358 my $changed = &OutputSGML ("$ROOT_DIR/$MODULE-sections.txt");
360 # If any of the DocBook SGML files have changed, update the timestamp file (so
361 # it can be used for Makefile dependencies).
362 if ($changed || ! -e "$ROOT_DIR/sgml.stamp") {
364 # try to detect the common prefix
365 # GtkWidget, GTK_WIDGET, gtk_widget -> gtk
366 if ($NAME_SPACE eq "") {
373 foreach my $symbol (keys(%IndexEntriesFull)) {
374 if(($NAME_SPACE eq "") || $symbol =~ /^$NAME_SPACE/i) {
375 if (length($symbol)>$pos) {
376 $letter=substr($symbol,$pos,1);
377 # stop prefix scanning
378 if ($letter eq "_") {
382 # Should we also stop on a uppercase char, if last was lowercase
383 # GtkWidget, if we have the 'W' and had the 't' before
384 # or should we count upper and lowercase, and stop one 2nd uppercase, if we already had a lowercase
385 # GtkWidget, the 'W' would be the 2nd uppercase and with 't','k' we had lowercase chars before
386 # need to recound each time as this is per symbol
387 $prefix{uc($letter)}++;
391 if ($letter ne "" && $letter ne "_") {
394 foreach $letter (keys(%prefix)) {
395 #print "$letter: $prefix{$letter}.\n";
396 if ($prefix{$letter}>$maxsymbols) {
398 $maxsymbols=$prefix{$letter};
401 $ratio = scalar(keys(%IndexEntriesFull)) / $prefix{$maxletter};
402 #print "most symbols start with $maxletter, that is ". (100 * $ratio) ." %\n";
405 $NAME_SPACE .= $maxletter;
412 } while ($ratio > 0.9);
413 #print "most symbols start with $NAME_SPACE\n";
417 &OutputDeprecatedIndex;
419 &OutputAnnotationGlossary;
421 open (TIMESTAMP, ">$ROOT_DIR/sgml.stamp")
422 || die "Can't create $ROOT_DIR/sgml.stamp: $!";
423 print (TIMESTAMP "timestamp");
427 #############################################################################
428 # Function : OutputObjectList
429 # Description : This outputs the alphabetical list of objects, in a columned
431 # FIXME: Currently this also outputs ancestor objects
432 # which may not actually be in this module.
434 #############################################################################
436 sub OutputObjectList {
439 # FIXME: use $OUTPUT_FORMAT
440 # my $old_object_index = "$SGML_OUTPUT_DIR/object_index.$OUTPUT_FORMAT";
441 my $old_object_index = "$SGML_OUTPUT_DIR/object_index.sgml";
442 my $new_object_index = "$SGML_OUTPUT_DIR/object_index.new";
444 open (OUTPUT, ">$new_object_index")
445 || die "Can't create $new_object_index: $!";
447 if ($OUTPUT_FORMAT eq "xml") {
448 my $header = $doctype_header;
450 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE informaltable/;
451 print (OUTPUT "$header");
454 print (OUTPUT <<EOF);
455 <informaltable pgwide="1" frame="none">
456 <tgroup cols="$cols">
457 <colspec colwidth="1*"${empty_element_end}
458 <colspec colwidth="1*"${empty_element_end}
459 <colspec colwidth="1*"${empty_element_end}
465 foreach $object (sort (@Objects)) {
466 my $xref = &MakeXRef ($object);
467 if ($count % $cols == 0) { print (OUTPUT "<row>\n"); }
468 print (OUTPUT "<entry>$xref</entry>\n");
469 if ($count % $cols == ($cols - 1)) { print (OUTPUT "</row>\n"); }
473 # emit an empty row, since empty tables are invalid
474 print (OUTPUT "<row><entry> </entry></row>\n");
477 if ($count % $cols > 0) {
478 print (OUTPUT "</row>\n");
482 print (OUTPUT <<EOF);
483 </tbody></tgroup></informaltable>
487 &UpdateFileIfChanged ($old_object_index, $new_object_index, 0);
490 #############################################################################
491 # Function : TrimTextBlock
492 # Description : Trims extra whitespace. Empty lines inside a block are
494 # Arguments : $desc - the text block to trim. May contain newlines.
495 #############################################################################
500 # strip leading spaces on the block
502 # strip trailing spaces on every line
503 $desc =~ s/\s+$/\n/mg;
509 #############################################################################
510 # Function : OutputSGML
511 # Description : This collects the output for each section of the docs, and
512 # outputs each file when the end of the section is found.
513 # Arguments : $file - the $MODULE-sections.txt file which contains all of
514 # the functions/macros/structs etc. being documented, organised
515 # into sections and subsections.
516 #############################################################################
521 #print "Reading: $file\n";
523 || die "Can't open $file: $!";
526 my $book_bottom = "";
527 my $includes = (defined $DEFAULT_INCLUDES) ? $DEFAULT_INCLUDES : "";
528 my $section_includes = "";
537 my $signals_synop = "";
538 my $signals_desc = "";
540 my $child_args_synop = "";
541 my $style_args_synop = "";
543 my $child_args_desc = "";
544 my $style_args_desc = "";
547 my $implementations = "";
548 my $prerequisites = "";
550 my @file_objects = ();
552 my %symbol_def_line = ();
554 # merge the source docs, in case there are no templates
555 &MergeSourceDocumentation;
561 } elsif (m/^<SECTION>/) {
567 %symbol_def_line = ();
569 } elsif (m/^<SUBSECTION\s*(.*)>/i) {
573 } elsif (m/^<SUBSECTION>/) {
575 } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
577 #print "Section: $title\n";
579 # We don't want warnings if object & class structs aren't used.
580 $DeclarationOutput{$title} = 1;
581 $DeclarationOutput{"${title}Class"} = 1;
582 $DeclarationOutput{"${title}Iface"} = 1;
583 $DeclarationOutput{"${title}Interface"} = 1;
585 } elsif (m/^<FILE>(.*)<\/FILE>/) {
587 if (! defined $templates{$filename}) {
588 if (&ReadTemplateFile ("$TMPL_DIR/$filename", 1)) {
589 &MergeSourceDocumentation;
590 $templates{$filename}=$.;
593 &LogWarning ($file, $., "Double <FILE>$filename</FILE> entry. ".
594 "Previous occurrence on line ".$templates{$filename}.".");
596 if (($title eq "") and (defined $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"})) {
597 $title = $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"};
598 # Remove trailing blanks
602 } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
604 $section_includes = $1;
606 if (defined $DEFAULT_INCLUDES) {
607 &LogWarning ($file, $., "Default <INCLUDE> being overridden by command line option.");
614 } elsif (m/^<\/SECTION>/) {
615 #print "End of section: $title\n";
616 if ($num_symbols > 0) {
618 if ($OUTPUT_FORMAT eq "xml") {
619 $book_bottom .= " <xi:include href=\"xml/$filename.xml\"/>\n";
621 $book_top.="<!ENTITY $section_id SYSTEM \"sgml/$filename.sgml\">\n";
622 $book_bottom .= " &$section_id;\n";
625 if (defined ($SourceSymbolDocs{"$TMPL_DIR/$filename:Include"})) {
626 if ($section_includes) {
627 &LogWarning ($file, $., "Section <INCLUDE> being overridden by inline comments.");
629 $section_includes = $SourceSymbolDocs{"$TMPL_DIR/$filename:Include"};
631 if ($section_includes eq "") {
632 $section_includes = $includes;
635 $signals_synop =~ s/^\n*//g;
636 $signals_synop =~ s/\n+$/\n/g;
637 if ($signals_synop ne '') {
638 $signals_synop = <<EOF;
639 <refsect1 id="$section_id.signals" role="signal_proto">
640 <title role="signal_proto.title">Signals</title>
642 ${signals_synop}</synopsis>
645 $signals_desc = TrimTextBlock($signals_desc);
646 $signals_desc = <<EOF;
647 <refsect1 id="$section_id.signal-details" role="signals">
648 <title role="signals.title">Signal Details</title>
654 $args_synop =~ s/^\n*//g;
655 $args_synop =~ s/\n+$/\n/g;
656 if ($args_synop ne '') {
658 <refsect1 id="$section_id.properties" role="properties">
659 <title role="properties.title">Properties</title>
661 ${args_synop}</synopsis>
664 $args_desc = TrimTextBlock($args_desc);
666 <refsect1 id="$section_id.property-details" role="property_details">
667 <title role="property_details.title">Property Details</title>
673 $child_args_synop =~ s/^\n*//g;
674 $child_args_synop =~ s/\n+$/\n/g;
675 if ($child_args_synop ne '') {
676 $args_synop .= <<EOF;
677 <refsect1 id="$section_id.child-properties" role="child_properties">
678 <title role="child_properties.title">Child Properties</title>
680 ${child_args_synop}</synopsis>
683 $child_args_desc = TrimTextBlock($child_args_desc);
685 <refsect1 id="$section_id.child-property-details" role="child_property_details">
686 <title role="child_property_details.title">Child Property Details</title>
692 $style_args_synop =~ s/^\n*//g;
693 $style_args_synop =~ s/\n+$/\n/g;
694 if ($style_args_synop ne '') {
695 $args_synop .= <<EOF;
696 <refsect1 id="$section_id.style-properties" role="style_properties">
697 <title role="style_properties.title">Style Properties</title>
699 ${style_args_synop}</synopsis>
702 $style_args_desc = TrimTextBlock($style_args_desc);
704 <refsect1 id="$section_id.style-property-details" role="style_properties_details">
705 <title role="style_properties_details.title">Style Property Details</title>
711 $hierarchy = TrimTextBlock($hierarchy);
712 if ($hierarchy ne "") {
714 <refsect1 id="$section_id.object-hierarchy" role="object_hierarchy">
715 <title role="object_hierarchy.title">Object Hierarchy</title>
721 $interfaces =~ TrimTextBlock($interfaces);
722 if ($interfaces ne "") {
724 <refsect1 id="$section_id.implemented-interfaces" role="impl_interfaces">
725 <title role="impl_interfaces.title">Implemented Interfaces</title>
731 $implementations = TrimTextBlock($implementations);
732 if ($implementations ne "") {
733 $implementations = <<EOF;
734 <refsect1 id="$section_id.implementations" role="implementations">
735 <title role="implementations.title">Known Implementations</title>
741 $prerequisites = TrimTextBlock($prerequisites);
742 if ($prerequisites ne "") {
743 $prerequisites = <<EOF;
744 <refsect1 id="$section_id.prerequisites" role="prerequisites">
745 <title role="prerequisites.title">Prerequisites</title>
751 $derived = TrimTextBlock($derived);
752 if ($derived ne "") {
754 <refsect1 id="$section_id.derived-interfaces" role="derived_interfaces">
755 <title role="derived_interfaces.title">Known Derived Interfaces</title>
761 $synopsis =~ s/^\n*//g;
762 $synopsis =~ s/\n+$/\n/g;
763 my $file_changed = &OutputSGMLFile ($filename, $title, $section_id,
765 \$synopsis, \$details,
766 \$signals_synop, \$signals_desc,
767 \$args_synop, \$args_desc,
768 \$hierarchy, \$interfaces,
770 \$prerequisites, \$derived,
780 $section_includes = "";
784 $child_args_synop = "";
785 $style_args_synop = "";
787 $child_args_desc = "";
788 $style_args_desc = "";
791 $implementations = "";
795 } elsif (m/^(\S+)/) {
797 #print " Symbol: $symbol\n";
799 # check for duplicate entries
800 if (! defined $symbol_def_line{$symbol}) {
801 my $declaration = $Declarations{$symbol};
802 if (defined ($declaration)) {
803 # We don't want standard macros/functions of GObjects,
804 # or private declarations.
805 if ($subsection ne "Standard" && $subsection ne "Private") {
806 if (&CheckIsObject ($symbol)) {
807 push @file_objects, $symbol;
809 my ($synop, $desc) = &OutputDeclaration ($symbol,
811 my ($sig_synop, $sig_desc) = &GetSignals ($symbol);
812 my ($arg_synop, $child_arg_synop, $style_arg_synop,
813 $arg_desc, $child_arg_desc, $style_arg_desc) = &GetArgs ($symbol);
814 my $hier = &GetHierarchy ($symbol);
815 my $ifaces = &GetInterfaces ($symbol);
816 my $impls = &GetImplementations ($symbol);
817 my $prereqs = &GetPrerequisites ($symbol);
818 my $der = &GetDerived ($symbol);
821 $signals_synop .= $sig_synop;
822 $signals_desc .= $sig_desc;
823 $args_synop .= $arg_synop;
824 $child_args_synop .= $child_arg_synop;
825 $style_args_synop .= $style_arg_synop;
826 $args_desc .= $arg_desc;
827 $child_args_desc .= $child_arg_desc;
828 $style_args_desc .= $style_arg_desc;
830 $interfaces .= $ifaces;
831 $implementations .= $impls;
832 $prerequisites .= $prereqs;
836 # Note that the declaration has been output.
837 $DeclarationOutput{$symbol} = 1;
838 } elsif ($subsection ne "Standard" && $subsection ne "Private") {
839 $UndeclaredSymbols{$symbol} = 1;
840 &LogWarning ($file, $., "No declaration found for $symbol.");
843 $symbol_def_line{$symbol}=$.;
845 if ($section_id eq "") {
846 if($title eq "" && $filename eq "") {
847 &LogWarning ($file, $., "Section has no title and no file.");
849 # FIXME: one of those would be enough
850 # filename should be an internal detail for gtk-doc
853 } elsif ($filename eq "") {
856 $filename =~ s/\s/_/g;
858 $section_id = $SourceSymbolDocs{"$TMPL_DIR/$filename:Section_Id"};
859 if (defined ($section_id) && $section_id !~ m/^\s*$/) {
860 # Remove trailing blanks and use as is
861 $section_id =~ s/\s+$//;
862 } elsif (&CheckIsObject ($title)) {
863 # GObjects use their class name as the ID.
864 $section_id = &CreateValidSGMLID ($title);
866 $section_id = &CreateValidSGMLID ("$MODULE-$title");
869 $SymbolSection{$symbol}=$title;
870 $SymbolSectionId{$symbol}=$section_id;
873 &LogWarning ($file, $., "Double symbol entry for $symbol. ".
874 "Previous occurrence on line ".$symbol_def_line{$symbol}.".");
880 &OutputMissingDocumentation;
881 &OutputUndeclaredSymbols;
882 &OutputUnusedSymbols;
884 if ($OUTPUT_ALL_SYMBOLS) {
887 if ($OUTPUT_SYMBOLS_WITHOUT_SINCE) {
888 &OutputSymbolsWithoutSince;
891 for $filename (split (' ', $EXPAND_CONTENT_FILES)) {
892 my $file_changed = &OutputExtraFile ($filename);
898 &OutputBook ($book_top, $book_bottom);
903 #############################################################################
904 # Function : OutputIndex
905 # Description : This writes an indexlist that can be included into the main-
906 # document into an <index> tag.
907 #############################################################################
910 my ($basename, $apiindexref ) = @_;
911 my %apiindex = %{$apiindexref};
912 my $old_index = "$SGML_OUTPUT_DIR/$basename.xml";
913 my $new_index = "$SGML_OUTPUT_DIR/$basename.new";
914 my $lastletter = " ";
919 open (OUTPUT, ">$new_index")
920 || die "Can't create $new_index";
922 my $header = $doctype_header;
923 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE indexdiv/;
925 print (OUTPUT "$header<indexdiv>\n");
927 #print "generate $basename index (".%apiindex." entries)\n";
929 # do a case insensitive sort while chopping off the prefix
931 sort { $$a{criteria} cmp $$b{criteria} }
932 map { my $x = uc($_); $x =~ s/^$NAME_SPACE\_?(.*)/$1/i; { criteria => $x, original => $_, short => $1 } }
935 $symbol = $$hash{original};
936 if (defined($$hash{short})) {
937 $short_symbol = $$hash{short};
939 $short_symbol = $symbol;
942 # generate a short symbol description
943 my $symbol_desc = "";
944 my $symbol_section = "";
945 my $symbol_section_id = "";
946 my $symbol_type = "";
947 if (defined($DeclarationTypes{$symbol})) {
948 $symbol_type = lc($DeclarationTypes{$symbol});
950 if ($symbol_type eq "") {
951 #print "trying symbol $symbol\n";
952 if ($symbol =~ m/(.*)::(.*)/) {
956 #print " trying object signal ${oname}:$osym in ".$#SignalNames." signals\n";
957 for ($i = 0; $i <= $#SignalNames; $i++) {
958 if ($SignalNames[$i] eq $osym) {
959 $symbol_type = "object signal";
960 if (defined($SymbolSection{$oname})) {
961 $symbol_section = $SymbolSection{$oname};
962 $symbol_section_id = $SymbolSectionId{$oname};
967 } elsif ($symbol =~ m/(.*):(.*)/) {
971 #print " trying object property ${oname}::$osym in ".$#ArgNames." properties\n";
972 for ($i = 0; $i <= $#ArgNames; $i++) {
973 #print " ".$ArgNames[$i]."\n";
974 if ($ArgNames[$i] eq $osym) {
975 $symbol_type = "object property";
976 if (defined($SymbolSection{$oname})) {
977 $symbol_section = $SymbolSection{$oname};
978 $symbol_section_id = $SymbolSectionId{$oname};
985 if (defined($SymbolSection{$symbol})) {
986 $symbol_section = $SymbolSection{$symbol};
987 $symbol_section_id = $SymbolSectionId{$symbol};
990 if ($symbol_type ne "") {
991 $symbol_desc=", $symbol_type";
992 if ($symbol_section ne "") {
993 $symbol_desc.=" in <link linkend=\"$symbol_section_id\">$symbol_section</link>";
994 #$symbol_desc.=" in ". &ExpandAbbreviations($symbol, "#$symbol_section");
998 my $curletter = uc(substr($short_symbol,0,1));
999 my $id = $apiindex{$symbol};
1001 #print " add symbol $symbol with $id to index in section $curletter\n";
1003 if ($curletter ne $lastletter) {
1004 $lastletter = $curletter;
1006 if ($divopen == 1) {
1007 print (OUTPUT "</indexdiv>\n");
1009 print (OUTPUT "<indexdiv><title>$curletter</title>\n");
1013 print (OUTPUT <<EOF);
1014 <indexentry><primaryie linkends="$id"><link linkend="$id">$symbol</link>$symbol_desc</primaryie></indexentry>
1018 if ($divopen == 1) {
1019 print (OUTPUT "</indexdiv>\n");
1021 print (OUTPUT "</indexdiv>\n");
1024 &UpdateFileIfChanged ($old_index, $new_index, 0);
1028 #############################################################################
1029 # Function : OutputIndexFull
1030 # Description : This writes the full api indexlist that can be included into the
1031 # main document into an <index> tag.
1032 #############################################################################
1034 sub OutputIndexFull {
1035 &OutputIndex ("api-index-full", \%IndexEntriesFull);
1039 #############################################################################
1040 # Function : OutputDeprecatedIndex
1041 # Description : This writes the deprecated api indexlist that can be included
1042 # into the main document into an <index> tag.
1043 #############################################################################
1045 sub OutputDeprecatedIndex {
1046 &OutputIndex ("api-index-deprecated", \%IndexEntriesDeprecated);
1050 #############################################################################
1051 # Function : OutputSinceIndexes
1052 # Description : This writes the 'since' api indexlists that can be included into
1053 # the main document into an <index> tag.
1054 #############################################################################
1056 sub OutputSinceIndexes {
1057 my @sinces = keys %{{ map { $_ => 1 } values %Since }};
1059 foreach my $version (@sinces) {
1060 #print "Since : [$version]\n";
1061 # TODO make filtered hash
1062 #my %index = grep { $Since{$_} eq $version } %IndexEntriesSince;
1063 my %index = map { $_ => $IndexEntriesSince{$_} } grep { $Since{$_} eq $version } keys %IndexEntriesSince;
1065 &OutputIndex ("api-index-$version", \%index);
1069 #############################################################################
1070 # Function : OutputAnnotationGlossary
1071 # Description : This writes a glossary of the used annotation terms into a
1072 # separate glossary file that can be included into the main
1074 #############################################################################
1076 sub OutputAnnotationGlossary {
1077 my $old_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.xml";
1078 my $new_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.new";
1079 my $lastletter = " ";
1082 # if there are no annotations used return
1083 return if (! keys(%AnnotationsUsed));
1085 # add acronyms that are referenced from acronym text
1087 foreach my $annotation (keys(%AnnotationsUsed)) {
1088 if(defined($AnnotationDefinition{$annotation})) {
1089 if($AnnotationDefinition{$annotation} =~ m/<acronym>([\w ]+)<\/acronym>/) {
1090 if (!exists($AnnotationsUsed{$1})) {
1091 $AnnotationsUsed{$1} = 1;
1098 open (OUTPUT, ">$new_glossary")
1099 || die "Can't create $new_glossary";
1101 my $header = $doctype_header;
1102 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE glossary/;
1104 print (OUTPUT <<EOF);
1106 <glossary id="annotation-glossary">
1107 <title>Annotation Glossary</title>
1110 foreach my $annotation (keys(%AnnotationsUsed)) {
1111 if(defined($AnnotationDefinition{$annotation})) {
1112 my $def = $AnnotationDefinition{$annotation};
1113 my $curletter = uc(substr($annotation,0,1));
1115 if ($curletter ne $lastletter) {
1116 $lastletter = $curletter;
1118 if ($divopen == 1) {
1119 print (OUTPUT "</glossdiv>\n");
1121 print (OUTPUT "<glossdiv><title>$curletter</title>\n");
1124 print (OUTPUT <<EOF);
1126 <glossterm><anchor id="annotation-glossterm-$annotation"/>$annotation</glossterm>
1135 if ($divopen == 1) {
1136 print (OUTPUT "</glossdiv>\n");
1138 print (OUTPUT "</glossary>\n");
1141 &UpdateFileIfChanged ($old_glossary, $new_glossary, 0);
1144 #############################################################################
1145 # Function : ReadKnownSymbols
1146 # Description : This collects the names of non-private symbols from the
1147 # $MODULE-sections.txt file.
1148 # Arguments : $file - the $MODULE-sections.txt file which contains all of
1149 # the functions/macros/structs etc. being documented, organised
1150 # into sections and subsections.
1151 #############################################################################
1153 sub ReadKnownSymbols {
1156 my $subsection = "";
1158 #print "Reading: $file\n";
1160 || die "Can't open $file: $!";
1166 } elsif (m/^<SECTION>/) {
1169 } elsif (m/^<SUBSECTION\s*(.*)>/i) {
1172 } elsif (m/^<SUBSECTION>/) {
1175 } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
1178 } elsif (m/^<FILE>(.*)<\/FILE>/) {
1179 $KnownSymbols{"$TMPL_DIR/$1:Long_Description"} = 1;
1180 $KnownSymbols{"$TMPL_DIR/$1:Short_Description"} = 1;
1183 } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
1186 } elsif (m/^<\/SECTION>/) {
1189 } elsif (m/^(\S+)/) {
1192 if ($subsection ne "Standard" && $subsection ne "Private") {
1193 $KnownSymbols{$symbol} = 1;
1196 $KnownSymbols{$symbol} = 0;
1204 #############################################################################
1205 # Function : OutputDeclaration
1206 # Description : Returns the synopsis and detailed description DocBook
1207 # describing one function/macro etc.
1208 # Arguments : $symbol - the name of the function/macro begin described.
1209 # $declaration - the declaration of the function/macro.
1210 #############################################################################
1212 sub OutputDeclaration {
1213 my ($symbol, $declaration) = @_;
1215 my $type = $DeclarationTypes {$symbol};
1216 if ($type eq 'MACRO') {
1217 return &OutputMacro ($symbol, $declaration);
1218 } elsif ($type eq 'TYPEDEF') {
1219 return &OutputTypedef ($symbol, $declaration);
1220 } elsif ($type eq 'STRUCT') {
1221 return &OutputStruct ($symbol, $declaration);
1222 } elsif ($type eq 'ENUM') {
1223 return &OutputEnum ($symbol, $declaration);
1224 } elsif ($type eq 'UNION') {
1225 return &OutputUnion ($symbol, $declaration);
1226 } elsif ($type eq 'VARIABLE') {
1227 return &OutputVariable ($symbol, $declaration);
1228 } elsif ($type eq 'FUNCTION') {
1229 return &OutputFunction ($symbol, $declaration, $type);
1230 } elsif ($type eq 'USER_FUNCTION') {
1231 return &OutputFunction ($symbol, $declaration, $type);
1233 die "Unknown symbol type";
1238 #############################################################################
1239 # Function : OutputSymbolTraits
1240 # Description : Returns the Since and StabilityLevel paragraphs for a symbol.
1241 # Arguments : $symbol - the name of the function/macro begin described.
1242 #############################################################################
1244 sub OutputSymbolTraits {
1248 if (exists $Since{$symbol}) {
1249 $desc .= "<para role=\"since\">Since $Since{$symbol}</para>";
1251 if (exists $StabilityLevel{$symbol}) {
1252 $desc .= "<para role=\"stability\">Stability Level: $StabilityLevel{$symbol}</para>";
1257 #############################################################################
1258 # Function : Outpu{Symbol,Section}ExtraLinks
1259 # Description : Returns extralinks for the symbol (if enabled).
1260 # Arguments : $symbol - the name of the function/macro begin described.
1261 #############################################################################
1265 return undef unless defined $text;
1267 # Build a char to hex map
1270 $escapes{chr($_)} = sprintf("%%%02X", $_);
1273 # Default unsafe characters. RFC 2732 ^(uric - reserved)
1274 $text =~ s/([^A-Za-z0-9\-_.!~*'()])/$escapes{$1}/g;
1279 sub OutputSymbolExtraLinks {
1283 if (0) { # NEW FEATURE: needs configurability
1284 my $sstr = &uri_escape($symbol);
1285 my $mstr = &uri_escape($MODULE);
1287 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1288 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&symbol=$sstr">edit documentation</ulink>
1294 sub OutputSectionExtraLinks {
1295 my ($symbol,$docsymbol) = @_;
1298 if (0) { # NEW FEATURE: needs configurability
1299 my $sstr = &uri_escape($symbol);
1300 my $mstr = &uri_escape($MODULE);
1301 my $dsstr = &uri_escape($docsymbol);
1303 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1304 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&symbol=$dsstr">edit documentation</ulink>
1311 #############################################################################
1312 # Function : OutputMacro
1313 # Description : Returns the synopsis and detailed description of a macro.
1314 # Arguments : $symbol - the macro.
1315 # $declaration - the declaration of the macro.
1316 #############################################################################
1319 my ($symbol, $declaration) = @_;
1320 my $id = &CreateValidSGMLID ($symbol);
1321 my $condition = &MakeConditionDescription ($symbol);
1322 my $synop = &MakeReturnField("#define") . "<link linkend=\"$id\">$symbol</link>";
1325 my @fields = ParseMacroDeclaration($declaration, \&CreateValidSGML);
1326 my $title = $symbol . (@fields ? "()" : "");
1328 $desc = "<refsect2 id=\"$id\" role=\"macro\"$condition>\n<title>$title</title>\n";
1329 $desc .= MakeIndexterms($symbol, $id);
1331 $desc .= OutputSymbolExtraLinks($symbol);
1334 if (length ($symbol) < $SYMBOL_FIELD_WIDTH) {
1335 $synop .= (' ' x ($SYMBOL_FIELD_WIDTH - length ($symbol)));
1339 for (my $i = 1; $i <= $#fields; $i += 2) {
1340 my $field_name = $fields[$i];
1343 $synop .= "$field_name";
1346 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1354 # Don't output the macro definition if is is a conditional macro or it
1355 # looks like a function, i.e. starts with "g_" or "_?gnome_", or it is
1356 # longer than 2 lines, otherwise we get lots of complicated macros like
1358 if (!defined ($DeclarationConditional{$symbol}) && ($symbol !~ m/^g_/)
1359 && ($symbol !~ m/^_?gnome_/) && (($declaration =~ tr/\n//) < 2)) {
1360 my $decl_out = &CreateValidSGML ($declaration);
1361 $desc .= "<programlisting>$decl_out</programlisting>\n";
1363 $desc .= "<programlisting>" . &MakeReturnField("#define") . "$symbol";
1364 if ($declaration =~ m/^\s*#\s*define\s+\w+(\([^\)]*\))/) {
1366 my $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH - length ("#define "));
1367 # Align each line so that if should all line up OK.
1368 $args =~ s/\n/\n$pad/gm;
1369 $desc .= &CreateValidSGML ($args);
1371 $desc .= "</programlisting>\n";
1374 $desc .= &MakeDeprecationNote($symbol);
1376 my $parameters = &OutputParamDescriptions ("MACRO", $symbol, @fields);
1377 my $parameters_output = 0;
1379 if (defined ($SymbolDocs{$symbol})) {
1380 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1382 # Try to insert the parameter table at the author's desired position.
1383 # Otherwise we need to tag it onto the end.
1384 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1385 $parameters_output = 1;
1387 $desc .= $symbol_docs;
1390 if ($parameters_output == 0) {
1391 $desc .= $parameters;
1394 $desc .= OutputSymbolTraits ($symbol);
1395 $desc .= "</refsect2>\n";
1396 return ($synop, $desc);
1400 #############################################################################
1401 # Function : OutputTypedef
1402 # Description : Returns the synopsis and detailed description of a typedef.
1403 # Arguments : $symbol - the typedef.
1404 # $declaration - the declaration of the typedef,
1405 # e.g. 'typedef unsigned int guint;'
1406 #############################################################################
1409 my ($symbol, $declaration) = @_;
1410 my $id = &CreateValidSGMLID ($symbol);
1411 my $condition = &MakeConditionDescription ($symbol);
1412 my $synop = &MakeReturnField("typedef") . "<link linkend=\"$id\">$symbol</link>;\n";
1413 my $desc = "<refsect2 id=\"$id\" role=\"typedef\"$condition>\n<title>$symbol</title>\n";
1415 $desc .= MakeIndexterms($symbol, $id);
1417 $desc .= OutputSymbolExtraLinks($symbol);
1419 if (!defined ($DeclarationConditional{$symbol})) {
1420 my $decl_out = &CreateValidSGML ($declaration);
1421 $desc .= "<programlisting>$decl_out</programlisting>\n";
1424 $desc .= &MakeDeprecationNote($symbol);
1426 if (defined ($SymbolDocs{$symbol})) {
1427 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1429 $desc .= OutputSymbolTraits ($symbol);
1430 $desc .= "</refsect2>\n";
1431 return ($synop, $desc);
1435 #############################################################################
1436 # Function : OutputStruct
1437 # Description : Returns the synopsis and detailed description of a struct.
1438 # We check if it is a object struct, and if so we only output
1439 # parts of it that are noted as public fields.
1440 # We also use a different SGML ID for object structs, since the
1441 # original ID is used for the entire RefEntry.
1442 # Arguments : $symbol - the struct.
1443 # $declaration - the declaration of the struct.
1444 #############################################################################
1447 my ($symbol, $declaration) = @_;
1450 my $default_to_public = 1;
1451 if (&CheckIsObject ($symbol)) {
1452 #print "Found struct gtype: $symbol\n";
1454 $default_to_public = $ObjectRoots{$symbol} eq 'GBoxed';
1460 $id = &CreateValidSGMLID ($symbol . "_struct");
1461 $condition = &MakeConditionDescription ($symbol . "_struct");
1463 $id = &CreateValidSGMLID ($symbol);
1464 $condition = &MakeConditionDescription ($symbol);
1467 # Determine if it is a simple struct or it also has a typedef.
1468 my $has_typedef = 0;
1469 if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1476 # For structs with typedefs we just output the struct name.
1477 $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1478 $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>$symbol</title>\n";
1480 $synop = &MakeReturnField("struct") . "<link linkend=\"$id\">$symbol</link>;\n";
1481 $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>struct $symbol</title>\n";
1484 $desc .= MakeIndexterms($symbol, $id);
1486 $desc .= OutputSymbolExtraLinks($symbol);
1488 # Form a pretty-printed, private-data-removed form of the declaration
1491 if ($declaration =~ m/^\s*$/) {
1492 #print "Found opaque struct: $symbol\n";
1493 $decl_out = "typedef struct _$symbol $symbol;";
1494 } elsif ($declaration =~ m/^\s*struct\s+\w+\s*;\s*$/) {
1495 #print "Found opaque struct: $symbol\n";
1496 $decl_out = "struct $symbol;";
1498 my $public = $default_to_public;
1499 my $new_declaration = "";
1501 my $decl = $declaration;
1503 if ($decl =~ m/^\s*(typedef\s+)?struct\s*\w*\s*(?:\/\*.*\*\/)?\s*{(.*)}\s*\w*\s*;\s*$/s) {
1504 my $struct_contents = $2;
1506 foreach $decl_line (split (/\n/, $struct_contents)) {
1507 #print "Struct line: $decl_line\n";
1508 if ($decl_line =~ m%/\*\s*<\s*public\s*>\s*\*/%) {
1510 } elsif ($decl_line =~ m%/\*\s*<\s*(private|protected)\s*>\s*\*/%) {
1513 $new_declaration .= $decl_line . "\n";
1517 if ($new_declaration) {
1518 # Strip any blank lines off the ends.
1519 $new_declaration =~ s/^\s*\n//;
1520 $new_declaration =~ s/\n\s*$/\n/;
1523 $decl_out = "typedef struct {\n" . $new_declaration
1526 $decl_out = "struct $symbol {\n" . $new_declaration
1531 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1532 "Couldn't parse struct:\n$declaration");
1535 # If we couldn't parse the struct or it was all private, output an
1536 # empty struct declaration.
1537 if ($decl_out eq "") {
1539 $decl_out = "typedef struct _$symbol $symbol;";
1541 $decl_out = "struct $symbol;";
1546 $decl_out = &CreateValidSGML ($decl_out);
1547 $desc .= "<programlisting>$decl_out</programlisting>\n";
1549 $desc .= &MakeDeprecationNote($symbol);
1551 if (defined ($SymbolDocs{$symbol})) {
1552 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1555 # Create a table of fields and descriptions
1557 # FIXME: Inserting  's into the produced type declarations here would
1558 # improve the output in most situations ... except for function
1559 # members of structs!
1560 my @fields = ParseStructDeclaration($declaration, !$default_to_public,
1563 "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1565 my $params = $SymbolParams{$symbol};
1567 # If no parameters are filled in, we don't generate the description
1568 # table, for backwards compatibility.
1571 if (defined $params) {
1572 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1573 if ($params->[$i] =~ /\S/) {
1581 my %field_descrs = @$params;
1582 my $missing_parameters = "";
1583 my $unused_parameters = "";
1585 $desc .= "<variablelist role=\"struct\">\n";
1587 my $field_name = shift @fields;
1588 my $text = shift @fields;
1589 my $field_descr = $field_descrs{$field_name};
1590 my $param_annotations = "";
1592 $desc .= "<varlistentry><term>$text</term>\n";
1593 if (defined $field_descr) {
1594 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1595 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1596 $field_descr .= $param_annotations;
1598 $field_descr =~ s/^(\s|\n)+//msg;
1599 $field_descr =~ s/(\s|\n)+$//msg;
1600 $desc .= "<listitem><simpara>$field_descr</simpara></listitem>\n";
1601 delete $field_descrs{$field_name};
1603 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1604 "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1605 if ($missing_parameters ne "") {
1606 $missing_parameters .= ", ".$field_name;
1608 $missing_parameters = $field_name;
1610 $desc .= "<listitem />\n";
1612 $desc .= "</varlistentry>\n";
1614 $desc .= "</variablelist>";
1615 foreach my $field_name (keys %field_descrs) {
1616 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1617 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1618 if ($unused_parameters ne "") {
1619 $unused_parameters .= ", ".$field_name;
1621 $unused_parameters = $field_name;
1625 # remember missing/unused parameters (needed in tmpl-free build)
1626 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1627 $AllIncompleteSymbols{$symbol}=$missing_parameters;
1629 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1630 $AllUnusedSymbols{$symbol}=$unused_parameters;
1634 if (scalar(@fields) > 0) {
1635 if (! exists ($AllIncompleteSymbols{$symbol})) {
1636 $AllIncompleteSymbols{$symbol}="<items>";
1637 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1638 "Field descriptions for struct $symbol are missing in source code comment block.");
1639 @TRACE@("Remaining structs fields: ".@fields.":".join(',',@fields)."\n");
1644 $desc .= OutputSymbolTraits ($symbol);
1645 $desc .= "</refsect2>\n";
1646 return ($synop, $desc);
1650 #############################################################################
1651 # Function : OutputUnion
1652 # Description : Returns the synopsis and detailed description of a union.
1653 # Arguments : $symbol - the union.
1654 # $declaration - the declaration of the union.
1655 #############################################################################
1658 my ($symbol, $declaration) = @_;
1659 my $id = &CreateValidSGMLID ($symbol);
1660 my $condition = &MakeConditionDescription ($symbol);
1662 # Determine if it is a simple struct or it also has a typedef.
1663 my $has_typedef = 0;
1664 if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1671 # For unions with typedefs we just output the union name.
1672 $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1673 $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>$symbol</title>\n";
1675 $synop = &MakeReturnField("union") . "<link linkend=\"$id\">$symbol</link>;\n";
1676 $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>union $symbol</title>\n";
1679 $desc .= MakeIndexterms($symbol, $id);
1681 $desc .= OutputSymbolExtraLinks($symbol);
1683 # FIXME: we do more for structs
1684 my $decl_out = &CreateValidSGML ($declaration);
1685 $desc .= "<programlisting>$decl_out</programlisting>\n";
1687 $desc .= &MakeDeprecationNote($symbol);
1689 if (defined ($SymbolDocs{$symbol})) {
1690 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1693 # Create a table of fields and descriptions
1695 # FIXME: Inserting  's into the produced type declarations here would
1696 # improve the output in most situations ... except for function
1697 # members of structs!
1698 my @fields = ParseStructDeclaration($declaration, 0,
1701 "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1703 my $params = $SymbolParams{$symbol};
1705 # If no parameters are filled in, we don't generate the description
1706 # table, for backwards compatibility
1709 if (defined $params) {
1710 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1711 if ($params->[$i] =~ /\S/) {
1719 my %field_descrs = @$params;
1720 my $missing_parameters = "";
1721 my $unused_parameters = "";
1723 $desc .= "<variablelist role=\"union\">\n";
1725 my $field_name = shift @fields;
1726 my $text = shift @fields;
1727 my $field_descr = $field_descrs{$field_name};
1728 my $param_annotations = "";
1730 $desc .= "<varlistentry><term>$text</term>\n";
1731 if (defined $field_descr) {
1732 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1733 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1734 $field_descr .= $param_annotations;
1736 $field_descr =~ s/^(\s|\n)+//msg;
1737 $field_descr =~ s/(\s|\n)+$//msg;
1738 $desc .= "<listitem><simpara>$field_descr</simpara></listitem>\n";
1739 delete $field_descrs{$field_name};
1741 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1742 "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1743 if ($missing_parameters ne "") {
1744 $missing_parameters .= ", ".$field_name;
1746 $missing_parameters = $field_name;
1748 $desc .= "<listitem />\n";
1750 $desc .= "</varlistentry>\n";
1752 $desc .= "</variablelist>";
1753 foreach my $field_name (keys %field_descrs) {
1754 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1755 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1756 if ($unused_parameters ne "") {
1757 $unused_parameters .= ", ".$field_name;
1759 $unused_parameters = $field_name;
1763 # remember missing/unused parameters (needed in tmpl-free build)
1764 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1765 $AllIncompleteSymbols{$symbol}=$missing_parameters;
1767 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1768 $AllUnusedSymbols{$symbol}=$unused_parameters;
1772 if (scalar(@fields) > 0) {
1773 if (! exists ($AllIncompleteSymbols{$symbol})) {
1774 $AllIncompleteSymbols{$symbol}="<items>";
1775 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1776 "Field descriptions for union $symbol are missing in source code comment block.");
1777 @TRACE@("Remaining union fields: ".@fields.":".join(',',@fields)."\n");
1782 $desc .= OutputSymbolTraits ($symbol);
1783 $desc .= "</refsect2>\n";
1784 return ($synop, $desc);
1788 #############################################################################
1789 # Function : OutputEnum
1790 # Description : Returns the synopsis and detailed description of a enum.
1791 # Arguments : $symbol - the enum.
1792 # $declaration - the declaration of the enum.
1793 #############################################################################
1796 my ($symbol, $declaration) = @_;
1799 if (&CheckIsObject ($symbol)) {
1800 #print "Found enum gtype: $symbol\n";
1807 $id = &CreateValidSGMLID ($symbol . "_enum");
1808 $condition = &MakeConditionDescription ($symbol . "_enum");
1810 $id = &CreateValidSGMLID ($symbol);
1811 $condition = &MakeConditionDescription ($symbol);
1814 my $synop = &MakeReturnField("enum") . "<link linkend=\"$id\">$symbol</link>;\n";
1815 my $desc = "<refsect2 id=\"$id\" role=\"enum\"$condition>\n<title>enum $symbol</title>\n";
1817 $desc .= MakeIndexterms($symbol, $id);
1819 $desc .= OutputSymbolExtraLinks($symbol);
1823 my $new_declaration = "";
1825 my $decl = $declaration;
1827 if ($decl =~ m/^\s*(typedef\s+)?enum\s*\w*\s*(?:\/\*.*\*\/)?\s*{(.*)}\s*\w*\s*;\s*$/s) {
1828 my $has_typedef = defined($1) ? 1 : 0;
1829 my $enum_contents = $2;
1831 foreach $decl_line (split (/\n/, $enum_contents)) {
1832 #print "Enum line: $decl_line\n";
1833 if ($decl_line =~ m%/\*\s*<\s*public\s*>\s*\*/%) {
1835 } elsif ($decl_line =~ m%/\*\s*<\s*(private|protected)\s*>\s*\*/%) {
1838 $new_declaration .= $decl_line . "\n";
1842 if ($new_declaration) {
1843 # Strip any blank lines off the ends.
1844 $new_declaration =~ s/^\s*\n//;
1845 $new_declaration =~ s/\n\s*$/\n/;
1848 $decl_out = "typedef enum {\n" . $new_declaration
1851 $decl_out = "enum $symbol {\n" . $new_declaration
1857 $decl_out = &CreateValidSGML ($decl_out);
1858 $desc .= "<programlisting>$decl_out</programlisting>\n";
1860 $desc .= &MakeDeprecationNote($symbol);
1862 if (defined ($SymbolDocs{$symbol})) {
1863 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1866 # Create a table of fields and descriptions
1868 my @fields = ParseEnumDeclaration($declaration);
1869 my $params = $SymbolParams{$symbol};
1871 # If nothing at all is documented log a single summary warning at the end.
1872 # Otherwise, warn about each undocumented item.
1875 if (defined $params) {
1876 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1877 if ($params->[$i] =~ /\S/) {
1884 my %field_descrs = (defined $params ? @$params : ());
1885 my $missing_parameters = "";
1886 my $unused_parameters = "";
1888 $desc .= "<variablelist role=\"enum\">\n";
1889 for my $field_name (@fields) {
1890 my $field_descr = $field_descrs{$field_name};
1891 my $param_annotations = "";
1893 $id = &CreateValidSGMLID ($field_name);
1894 $condition = &MakeConditionDescription ($field_name);
1895 $desc .= "<varlistentry id=\"$id\" role=\"constant\"$condition>\n<term><literal>$field_name</literal></term>\n";
1896 if (defined $field_descr) {
1897 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1898 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1899 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1900 delete $field_descrs{$field_name};
1903 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1904 "Value description for $symbol"."::"."$field_name is missing in source code comment block.");
1905 if ($missing_parameters ne "") {
1906 $missing_parameters .= ", ".$field_name;
1908 $missing_parameters = $field_name;
1911 $desc .= "<listitem />\n";
1913 $desc .= "</varlistentry>\n";
1915 $desc .= "</variablelist>";
1916 foreach my $field_name (keys %field_descrs) {
1917 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1918 "Value description for $symbol"."::"."$field_name is not used from source code comment block.");
1919 if ($unused_parameters ne "") {
1920 $unused_parameters .= ", ".$field_name;
1922 $unused_parameters = $field_name;
1926 # remember missing/unused parameters (needed in tmpl-free build)
1927 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1928 $AllIncompleteSymbols{$symbol}=$missing_parameters;
1930 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1931 $AllUnusedSymbols{$symbol}=$unused_parameters;
1935 if (scalar(@fields) > 0) {
1936 if (! exists ($AllIncompleteSymbols{$symbol})) {
1937 $AllIncompleteSymbols{$symbol}="<items>";
1938 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1939 "Value descriptions for $symbol are missing in source code comment block.");
1944 $desc .= OutputSymbolTraits ($symbol);
1945 $desc .= "</refsect2>\n";
1946 return ($synop, $desc);
1950 #############################################################################
1951 # Function : OutputVariable
1952 # Description : Returns the synopsis and detailed description of a variable.
1953 # Arguments : $symbol - the extern'ed variable.
1954 # $declaration - the declaration of the variable.
1955 #############################################################################
1957 sub OutputVariable {
1958 my ($symbol, $declaration) = @_;
1959 my $id = &CreateValidSGMLID ($symbol);
1960 my $condition = &MakeConditionDescription ($symbol);
1962 @TRACE@("ouputing variable: '$symbol' '$declaration'");
1965 if ($declaration =~ m/^\s*extern\s+((const\s+|signed\s+|unsigned\s+|long\s+|short\s+)*\w+)(\s+\*+|\*+|\s)(\s*)(const\s+)*([A-Za-z]\w*)\s*;/) {
1966 my $mod1 = defined ($1) ? $1 : "";
1967 my $ptr = defined ($3) ? $3 : "";
1968 my $space = defined ($4) ? $4 : "";
1969 my $mod2 = defined ($5) ? $5 : "";
1970 $synop = &MakeReturnField("extern $mod1$ptr$space$mod2") . "<link linkend=\"$id\">$symbol</link>;\n";
1971 } elsif ($declaration =~ m/^\s*((const\s+|signed\s+|unsigned\s+|long\s+|short\s+)*\w+)(\s+\*+|\*+|\s)(\s*)(const\s+)*([A-Za-z]\w*)\s*=/) {
1972 my $mod1 = defined ($1) ? $1 : "";
1973 my $ptr = defined ($3) ? $3 : "";
1974 my $space = defined ($4) ? $4 : "";
1975 my $mod2 = defined ($5) ? $5 : "";
1976 $synop = &MakeReturnField("$mod1$ptr$space$mod2") . "<link linkend=\"$id\">$symbol</link>;\n";
1979 $synop = &MakeReturnField("extern") . "<link linkend=\"$id\">$symbol</link>;\n";
1982 my $desc = "<refsect2 id=\"$id\" role=\"variable\"$condition>\n<title>$symbol</title>\n";
1984 $desc .= MakeIndexterms($symbol, $id);
1986 $desc .= OutputSymbolExtraLinks($symbol);
1988 my $decl_out = &CreateValidSGML ($declaration);
1989 $desc .= "<programlisting>$decl_out</programlisting>\n";
1991 $desc .= &MakeDeprecationNote($symbol);
1993 if (defined ($SymbolDocs{$symbol})) {
1994 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1996 $desc .= OutputSymbolTraits ($symbol);
1997 $desc .= "</refsect2>\n";
1998 return ($synop, $desc);
2002 #############################################################################
2003 # Function : OutputFunction
2004 # Description : Returns the synopsis and detailed description of a function.
2005 # Arguments : $symbol - the function.
2006 # $declaration - the declaration of the function.
2007 #############################################################################
2009 sub OutputFunction {
2010 my ($symbol, $declaration, $symbol_type) = @_;
2011 my $id = &CreateValidSGMLID ($symbol);
2012 my $condition = &MakeConditionDescription ($symbol);
2014 # Take out the return type $1 $2 $3
2015 $declaration =~ s/<RETURNS>\s*((?:const\s+|G_CONST_RETURN\s+|signed\s+|unsigned\s+|long\s+|short\s+|struct\s+|enum\s+)*)(\w+)(\s*\**\s*(?:const|G_CONST_RETURN)?\s*\**\s*(?:restrict)?\s*)<\/RETURNS>\n//;
2016 my $type_modifier = defined($1) ? $1 : "";
2019 # Trim trailing spaces as we are going to pad to $RETURN_TYPE_FIELD_WIDTH below anyway
2020 $pointer =~ s/\s+$//;
2021 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
2023 #if ($symbol_type eq 'USER_FUNCTION') {
2024 # $start = "typedef ";
2027 # We output const rather than G_CONST_RETURN.
2028 $type_modifier =~ s/G_CONST_RETURN/const/g;
2029 $pointer =~ s/G_CONST_RETURN/const/g;
2030 $pointer =~ s/^\s+/ /g;
2032 my $ret_type_len = length ($start) + length ($type_modifier)+ length ($type)
2033 + length ($pointer);
2034 my $ret_type_output;
2036 if ($ret_type_len < $RETURN_TYPE_FIELD_WIDTH) {
2037 $ret_type_output = "$start$type_modifier$xref$pointer"
2038 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
2041 #$ret_type_output = "$start$type_modifier$xref$pointer\n" . (' ' x $RETURN_TYPE_FIELD_WIDTH);
2043 $ret_type_output = "$start$type_modifier$xref$pointer ";
2044 $symbol_len = $ret_type_len + 1 - $RETURN_TYPE_FIELD_WIDTH;
2046 #@TRACE@("$symbol ret type output: [$ret_type_output], $ret_type_len");
2048 $symbol_len += length ($symbol);
2049 my $char1 = my $char2 = my $char3 = "";
2050 if ($symbol_type eq 'USER_FUNCTION') {
2057 my ($symbol_output, $symbol_desc_output);
2058 if ($symbol_len < $SYMBOL_FIELD_WIDTH) {
2059 $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3"
2060 . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
2061 $symbol_desc_output = "$char1$char2$symbol$char3"
2062 . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
2064 $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3\n"
2065 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
2066 $symbol_desc_output = "$char1$char2$symbol$char3\n"
2067 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
2070 my $synop = $ret_type_output . $symbol_output . '(';
2071 my $desc = "<refsect2 id=\"$id\" role=\"function\"$condition>\n<title>${symbol} ()</title>\n";
2073 $desc .= MakeIndexterms($symbol, $id);
2075 $desc .= OutputSymbolExtraLinks($symbol);
2077 $desc .= "<programlisting>${ret_type_output}$symbol_desc_output(";
2079 my @fields = ParseFunctionDeclaration($declaration, \&MakeXRef,
2081 &tagify($_[0],"parameter");
2084 for (my $i = 1; $i <= $#fields; $i += 2) {
2085 my $field_name = $fields[$i];
2088 $synop .= "$field_name";
2089 $desc .= "$field_name";
2092 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2095 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2102 $desc .= ");</programlisting>\n";
2104 $desc .= &MakeDeprecationNote($symbol);
2106 my $parameters = &OutputParamDescriptions ("FUNCTION", $symbol, @fields);
2107 my $parameters_output = 0;
2109 if (defined ($SymbolDocs{$symbol})) {
2110 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
2112 # Try to insert the parameter table at the author's desired position.
2113 # Otherwise we need to tag it onto the end.
2114 # FIXME: document that in the user manual and make it useable for other
2116 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
2117 $parameters_output = 1;
2119 $desc .= $symbol_docs;
2122 if ($parameters_output == 0) {
2123 $desc .= $parameters;
2126 $desc .= OutputSymbolTraits ($symbol);
2127 $desc .= "</refsect2>\n";
2128 return ($synop, $desc);
2132 #############################################################################
2133 # Function : OutputParamDescriptions
2134 # Description : Returns the DocBook output describing the parameters of a
2135 # function, macro or signal handler.
2136 # Arguments : $symbol_type - 'FUNCTION', 'MACRO' or 'SIGNAL'. Signal
2137 # handlers have an implicit user_data parameter last.
2138 # $symbol - the name of the function/macro being described.
2139 # @fields - parsed fields from the declaration, used to determine
2140 # undocumented/unused entries
2141 #############################################################################
2143 sub OutputParamDescriptions {
2144 my ($symbol_type, $symbol, @fields) = @_;
2146 my $params = $SymbolParams{$symbol};
2148 my %field_descrs = ();
2151 %field_descrs = @fields;
2152 delete $field_descrs{"void"};
2153 delete $field_descrs{"Returns"};
2156 if (defined $params) {
2158 my $params_desc = "";
2159 my $missing_parameters = "";
2160 my $unused_parameters = "";
2163 for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
2164 my $param_name = $$params[$j];
2165 my $param_desc = $$params[$j + 1];
2166 my $param_annotations = "";
2168 ($param_desc,$param_annotations) = & ExpandAnnotation($symbol, $param_desc);
2169 $param_desc = &ExpandAbbreviations($symbol, $param_desc);
2170 $param_desc .= $param_annotations;
2172 $param_desc =~ s/^(\s|\n)+//msg;
2173 $param_desc =~ s/(\s|\n)+$//msg;
2174 if ($param_name eq "Returns") {
2175 $returns = "$param_desc";
2176 } elsif ($param_name eq "void") {
2177 #print "!!!! void in params for $symbol?\n";
2180 if (!defined $field_descrs{$param_name}) {
2181 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2182 "Parameter description for $symbol"."::"."$param_name is not used from source code comment block.");
2183 if ($unused_parameters ne "") {
2184 $unused_parameters .= ", ".$param_name;
2186 $unused_parameters = $param_name;
2189 delete $field_descrs{$param_name};
2192 if($param_desc ne "") {
2193 $params_desc .= "<varlistentry><term><parameter>$param_name</parameter> :</term>\n<listitem><simpara>$param_desc</simpara></listitem></varlistentry>\n";
2198 foreach my $param_name (keys %field_descrs) {
2199 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2200 "Parameter description for $symbol"."::"."$param_name is missing in source code comment block.");
2201 if ($missing_parameters ne "") {
2202 $missing_parameters .= ", ".$param_name;
2204 $missing_parameters = $param_name;
2208 # Signals have an implicit user_data parameter which we describe.
2209 if ($symbol_type eq "SIGNAL") {
2210 $params_desc .= "<varlistentry><term><parameter>user_data</parameter> :</term>\n<listitem><simpara>user data set when the signal handler was connected.</simpara></listitem></varlistentry>\n";
2213 # Start a table if we need one.
2214 if ($params_desc || $returns) {
2215 $output .= "<variablelist role=\"params\">\n";
2216 if ($params_desc ne "") {
2217 #$output .= "<varlistentry><term>Parameters:</term><listitem></listitem></varlistentry>\n";
2218 $output .= $params_desc;
2221 # Output the returns info last
2223 $output .= "<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>$returns</simpara></listitem></varlistentry>\n";
2227 $output .= "</variablelist>";
2230 # remember missing/unused parameters (needed in tmpl-free build)
2231 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
2232 $AllIncompleteSymbols{$symbol}=$missing_parameters;
2234 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
2235 $AllUnusedSymbols{$symbol}=$unused_parameters;
2238 if (($num_params == 0) && @fields && (scalar(keys(%field_descrs)) > 0)) {
2239 if (! exists ($AllIncompleteSymbols{$symbol})) {
2240 $AllIncompleteSymbols{$symbol}="<parameters>";
2248 #############################################################################
2249 # Function : ParseStabilityLevel
2250 # Description : Parses a stability level and outputs a warning if it isn't
2252 # Arguments : $stability - the stability text.
2253 # $file, $line - context for error message
2254 # $message - description of where the level is from, to use in
2255 # any error message.
2256 # Returns : The parsed stability level string.
2257 #############################################################################
2259 sub ParseStabilityLevel {
2260 my ($stability, $file, $line, $message) = @_;
2262 $stability =~ s/^\s*//;
2263 $stability =~ s/\s*$//;
2264 if ($stability =~ m/^stable$/i) {
2265 $stability = "Stable";
2266 } elsif ($stability =~ m/^unstable$/i) {
2267 $stability = "Unstable";
2268 } elsif ($stability =~ m/^private$/i) {
2269 $stability = "Private";
2271 &LogWarning ($file, $line, "$message is $stability.".
2272 "It should be one of these: Stable, Unstable, or Private.");
2278 #############################################################################
2279 # Function : OutputSGMLFile
2280 # Description : Outputs the final DocBook file for one section.
2281 # Arguments : $file - the name of the file.
2282 # $title - the title from the $MODULE-sections.txt file, which
2283 # will be overridden by the title in the template file.
2284 # $section_id - the SGML id to use for the toplevel tag.
2285 # $includes - comma-separates list of include files added at top of
2286 # synopsis, with '<' '>' around them (if not already enclosed in "").
2287 # $synopsis - reference to the DocBook for the Synopsis part.
2288 # $details - reference to the DocBook for the Details part.
2289 # $signal_synop - reference to the DocBook for the Signal Synopsis part
2290 # $signal_desc - reference to the DocBook for the Signal Description part
2291 # $args_synop - reference to the DocBook for the Arg Synopsis part
2292 # $args_desc - reference to the DocBook for the Arg Description part
2293 # $hierarchy - reference to the DocBook for the Object Hierarchy part
2294 # $interfaces - reference to the DocBook for the Interfaces part
2295 # $implementations - reference to the DocBook for the Known Implementations part
2296 # $prerequisites - reference to the DocBook for the Prerequisites part
2297 # $derived - reference to the DocBook for the Derived Interfaces part
2298 # $file_objects - reference to an array of objects in this file
2299 #############################################################################
2301 sub OutputSGMLFile {
2302 my ($file, $title, $section_id, $includes, $synopsis, $details, $signals_synop, $signals_desc, $args_synop, $args_desc, $hierarchy, $interfaces, $implementations, $prerequisites, $derived, $file_objects) = @_;
2304 #print "Output sgml for file $file with title '$title'\n";
2306 # The edited title overrides the one from the sections file.
2307 my $new_title = $SymbolDocs{"$TMPL_DIR/$file:Title"};
2308 if (defined ($new_title) && $new_title !~ m/^\s*$/) {
2309 $title = $new_title;
2310 #print "Found title: $title\n";
2312 my $short_desc = $SymbolDocs{"$TMPL_DIR/$file:Short_Description"};
2313 if (!defined ($short_desc) || $short_desc =~ m/^\s*$/) {
2316 $short_desc = &ExpandAbbreviations("$title:Short_description",
2318 #print "Found short_desc: $short_desc";
2320 my $long_desc = $SymbolDocs{"$TMPL_DIR/$file:Long_Description"};
2321 if (!defined ($long_desc) || $long_desc =~ m/^\s*$/) {
2324 $long_desc = &ExpandAbbreviations("$title:Long_description",
2326 #print "Found long_desc: $long_desc";
2328 my $see_also = $SymbolDocs{"$TMPL_DIR/$file:See_Also"};
2329 if (!defined ($see_also) || $see_also =~ m%^\s*(<para>)?\s*(</para>)?\s*$%) {
2332 $see_also = &ExpandAbbreviations("$title:See_Also", $see_also);
2333 #print "Found see_also: $see_also";
2336 $see_also = "<refsect1 id=\"$section_id.see-also\">\n<title>See Also</title>\n$see_also\n</refsect1>\n";
2338 my $stability = $SymbolDocs{"$TMPL_DIR/$file:Stability_Level"};
2339 if (!defined ($stability) || $stability =~ m/^\s*$/) {
2342 $stability = &ParseStabilityLevel($stability, $file, $., "Section stability level");
2343 #print "Found stability: $stability";
2346 $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$stability, unless otherwise indicated\n</refsect1>\n";
2347 } elsif ($DEFAULT_STABILITY) {
2348 $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$DEFAULT_STABILITY, unless otherwise indicated\n</refsect1>\n";
2351 my $image = $SymbolDocs{"$TMPL_DIR/$file:Image"};
2352 if (!defined ($image) || $image =~ m/^\s*$/) {
2360 if ($image =~ /jpe?g$/i) {
2361 $format = "format='JPEG'";
2362 } elsif ($image =~ /png$/i) {
2363 $format = "format='PNG'";
2364 } elsif ($image =~ /svg$/i) {
2365 $format = "format='SVG'";
2370 $image = " <inlinegraphic fileref='$image' $format/>\n"
2373 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
2375 my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
2378 my $include_output = "";
2380 foreach $include (split (/,/, $includes)) {
2381 if ($include =~ m/^\".+\"$/) {
2382 $include_output .= "#include ${include}\n";
2385 $include =~ s/^\s+|\s+$//gs;
2386 $include_output .= "#include <${include}>\n";
2389 if ($include_output ne '') {
2390 $include_output = "\n$include_output\n";
2393 my $extralinks = OutputSectionExtraLinks($title,"Section:$file");
2395 my $old_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT";
2396 my $new_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT.new";
2398 open (OUTPUT, ">$new_sgml_file")
2399 || die "Can't create $new_sgml_file: $!";
2401 my $object_anchors = "";
2402 foreach my $object (@$file_objects) {
2403 next if ($object eq $section_id);
2404 my $id = CreateValidSGMLID($object);
2405 #print "Debug: Adding anchor for $object\n";
2406 $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
2409 # We used to output this, but is messes up our UpdateFileIfChanged code
2410 # since it changes every day (and it is only used in the man pages):
2411 # "<refentry id="$section_id" revision="$mday $month $year">"
2413 if ($OUTPUT_FORMAT eq "xml") {
2414 print OUTPUT $doctype_header;
2418 <refentry id="$section_id">
2420 <refentrytitle role="top_of_page" id="$section_id.top_of_page">$title</refentrytitle>
2421 <manvolnum>3</manvolnum>
2424 $image</refmiscinfo>
2427 <refname>$title</refname>
2428 <refpurpose>$short_desc</refpurpose>
2431 <refsynopsisdiv id="$section_id.synopsis" role="synopsis">
2432 <title role="synopsis.title">Synopsis</title>
2434 <synopsis>$include_output$${synopsis}</synopsis>
2436 $$hierarchy$$prerequisites$$derived$$interfaces$$implementations$$args_synop$$signals_synop
2437 <refsect1 id="$section_id.description" role="desc">
2438 <title role="desc.title">Description</title>
2439 $extralinks$long_desc
2441 <refsect1 id="$section_id.details" role="details">
2442 <title role="details.title">Details</title>
2445 $$args_desc$$signals_desc$see_also
2450 return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2454 #############################################################################
2455 # Function : OutputExtraFile
2456 # Description : Copies an "extra" DocBook file into the output directory,
2457 # expanding abbreviations
2458 # Arguments : $file - the source file.
2459 #############################################################################
2460 sub OutputExtraFile {
2465 ($basename = $file) =~ s!^.*/!!;
2467 my $old_sgml_file = "$SGML_OUTPUT_DIR/$basename";
2468 my $new_sgml_file = "$SGML_OUTPUT_DIR/$basename.new";
2472 open(EXTRA_FILE, "<$file") || die "Can't open $file";
2476 $contents = <EXTRA_FILE>;
2479 open (OUTPUT, ">$new_sgml_file")
2480 || die "Can't create $new_sgml_file: $!";
2482 print OUTPUT &ExpandAbbreviations ("$basename file", $contents);
2485 return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2487 #############################################################################
2488 # Function : OutputBook
2489 # Description : Outputs the SGML entities that need to be included into the
2490 # main SGML file for the module.
2491 # Arguments : $book_top - the declarations of the entities, which are added
2492 # at the top of the main SGML file.
2493 # $book_bottom - the references to the entities, which are
2494 # added in the main SGML file at the desired position.
2495 #############################################################################
2498 my ($book_top, $book_bottom) = @_;
2500 my $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top";
2501 my $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top.new";
2503 open (OUTPUT, ">$new_file")
2504 || die "Can't create $new_file: $!";
2505 print OUTPUT $book_top;
2508 &UpdateFileIfChanged ($old_file, $new_file, 0);
2511 $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom";
2512 $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom.new";
2514 open (OUTPUT, ">$new_file")
2515 || die "Can't create $new_file: $!";
2516 print OUTPUT $book_bottom;
2519 &UpdateFileIfChanged ($old_file, $new_file, 0);
2522 # If the main SGML/XML file hasn't been created yet, we create it here.
2523 # The user can tweak it later.
2524 if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
2525 open (OUTPUT, ">$MAIN_SGML_FILE")
2526 || die "Can't create $MAIN_SGML_FILE: $!";
2528 if ($OUTPUT_FORMAT eq "xml") {
2530 <?xml version="1.0"?>
2531 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
2532 "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
2534 <!ENTITY % local.common.attrib "xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'">
2540 <!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
2549 <title>$MODULE Reference Manual</title>
2551 for $MODULE [VERSION].
2552 The latest version of this documentation can be found on-line at
2553 <ulink role="online-location" url="http://[SERVER]/$MODULE/index.html">http://[SERVER]/$MODULE/</ulink>.
2558 <title>[Insert title here]</title>
2562 if (-e $OBJECT_TREE_FILE) {
2564 <chapter id="object-tree">
2565 <title>Object Hierarchy</title>
2566 <xi:include href="xml/tree_index.sgml"/>
2572 <index id="api-index-full">
2573 <title>API Index</title>
2574 <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
2576 <index id="deprecated-api-index" role="deprecated">
2577 <title>Index of deprecated API</title>
2578 <xi:include href="xml/api-index-deprecated.xml"><xi:fallback /></xi:include>
2581 <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
2590 #############################################################################
2591 # Function : CreateValidSGML
2592 # Description : This turns any chars which are used in SGML into entities,
2593 # e.g. '<' into '<'
2594 # Arguments : $text - the text to turn into proper SGML.
2595 #############################################################################
2597 sub CreateValidSGML {
2599 $text =~ s/&/&/g; # Do this first, or the others get messed up.
2600 $text =~ s/</</g;
2601 $text =~ s/>/>/g;
2602 # browers render single tabs inconsistently
2603 $text =~ s/([^\s])\t([^\s])/$1 $2/g;
2607 #############################################################################
2608 # Function : ConvertSGMLChars
2609 # Description : This is used for text in source code comment blocks, to turn
2610 # chars which are used in SGML into entities, e.g. '<' into
2611 # '<'. Depending on $INLINE_MARKUP_MODE, this is done
2612 # unconditionally or only if the character doesn't seem to be
2613 # part of an SGML construct (tag or entity reference).
2614 # Arguments : $text - the text to turn into proper SGML.
2615 #############################################################################
2617 sub ConvertSGMLChars {
2618 my ($symbol, $text) = @_;
2620 if ($INLINE_MARKUP_MODE) {
2621 # For the XML/SGML mode only convert to entities outside CDATA sections.
2622 return &ModifyXMLElements ($text, $symbol,
2623 "<!\\[CDATA\\[|<programlisting[^>]*>",
2624 \&ConvertSGMLCharsEndTag,
2625 \&ConvertSGMLCharsCallback);
2627 # For the simple non-sgml mode, convert to entities everywhere.
2628 $text =~ s/&/&/g; # Do this first, or the others get messed up.
2629 $text =~ s/</</g;
2630 $text =~ s/>/>/g;
2636 sub ConvertSGMLCharsEndTag {
2637 if ($_[0] eq "<!\[CDATA\[") {
2640 return "</programlisting>";
2644 sub ConvertSGMLCharsCallback {
2645 my ($text, $symbol, $tag) = @_;
2647 if ($tag =~ m/^<programlisting/) {
2648 # We can handle <programlisting> specially here.
2649 return &ModifyXMLElements ($text, $symbol,
2651 \&ConvertSGMLCharsEndTag,
2652 \&ConvertSGMLCharsCallback2);
2653 } elsif ($tag eq "") {
2654 # If we're not in CDATA convert to entities.
2655 $text =~ s/&(?![a-zA-Z#]+;)/&/g; # Do this first, or the others get messed up.
2656 $text =~ s/<(?![a-zA-Z\/!])/</g;
2657 $text =~ s/(?<![a-zA-Z0-9"'\/-])>/>/g;
2659 # Handle "#include <xxxxx>"
2660 $text =~ s/#include(\s+)<([^>]+)>/#include$1<$2>/g;
2666 sub ConvertSGMLCharsCallback2 {
2667 my ($text, $symbol, $tag) = @_;
2669 # If we're not in CDATA convert to entities.
2670 # We could handle <programlisting> differently, though I'm not sure it helps.
2672 # replace only if its not a tag
2673 $text =~ s/&(?![a-zA-Z#]+;)/&/g; # Do this first, or the others get messed up.
2674 $text =~ s/<(?![a-zA-Z\/!])/</g;
2675 $text =~ s/(?<![a-zA-Z0-9"'\/-])>/>/g;
2677 # Handle "#include <xxxxx>"
2678 $text =~ s/#include(\s+)<([^>]+)>/#include$1<$2>/g;
2684 #############################################################################
2685 # Function : ExpandAnnotation
2686 # Description : This turns annotations into acronym tags.
2687 # Arguments : $symbol - the symbol being documented, for error messages.
2688 # $text - the text to expand.
2689 #############################################################################
2690 sub ExpandAnnotation {
2691 my ($symbol, $param_desc) = @_;
2692 my $param_annotations = "";
2694 # look for annotations at the start of the comment part
2695 if ($param_desc =~ m%^\s*\((.*?)\):%) {
2700 @annotations = split(/\)\s*\(/,$1);
2701 foreach $annotation (@annotations) {
2702 # need to search for the longest key-match in %AnnotationDefinition
2704 my $match_annotation="";
2706 foreach $annotationdef (keys %AnnotationDefinition) {
2707 if ($annotation =~ m/^$annotationdef/) {
2708 if (length($annotationdef)>$match_length) {
2709 $match_length=length($annotationdef);
2710 $match_annotation=$annotationdef;
2714 my $annotation_extra = "";
2715 if ($match_annotation ne "") {
2716 if ($annotation =~ m%$match_annotation\s+(.*)%) {
2717 $annotation_extra = " $1";
2719 $AnnotationsUsed{$match_annotation} = 1;
2720 $param_annotations .= "[<acronym>$match_annotation</acronym>$annotation_extra]";
2723 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2724 "unknown annotation \"$annotation\" in documentation for $symbol.");
2725 $param_annotations .= "[$annotation]";
2729 $param_desc =~ m/^(.*?)\.*\s*$/s;
2730 $param_desc = "$1. ";
2732 if ($param_annotations ne "") {
2733 $param_annotations = "<emphasis role=\"annotation\">$param_annotations</emphasis>";
2735 return ($param_desc, $param_annotations);
2738 #############################################################################
2739 # Function : ExpandAbbreviations
2740 # Description : This turns the abbreviations function(), macro(), @param,
2741 # %constant, and #symbol into appropriate DocBook markup.
2742 # CDATA sections and <programlisting> parts are skipped.
2743 # Arguments : $symbol - the symbol being documented, for error messages.
2744 # $text - the text to expand.
2745 #############################################################################
2747 sub ExpandAbbreviations {
2748 my ($symbol, $text) = @_;
2750 # Convert "|[" and "]|" into the start and end of program listing examples.
2751 # FIXME: we like to have a way to specify parameters e.g. language="c"
2752 $text =~ s%\|\[%<informalexample><programlisting>%g;
2753 $text =~ s%\]\|%</programlisting></informalexample>%g;
2754 # TODO: check for a xml comment after |[ and pick the language attribute from
2757 # keep CDATA unmodified, preserve ulink tags (ideally we preseve all tags
2759 return &ModifyXMLElements ($text, $symbol,
2760 "<!\\[CDATA\\[|<ulink[^>]*>|<programlisting[^>]*>|<!DOCTYPE",
2761 \&ExpandAbbreviationsEndTag,
2762 \&ExpandAbbreviationsCallback);
2766 # Returns the end tag (as a regexp) corresponding to the given start tag.
2767 sub ExpandAbbreviationsEndTag {
2768 my ($start_tag) = @_;
2770 if ($start_tag eq "<!\[CDATA\[") {
2772 } elsif ($start_tag eq "<!DOCTYPE") {
2774 } elsif ($start_tag =~ m/<(\w+)/) {
2779 # Called inside or outside each CDATA or <programlisting> section.
2780 sub ExpandAbbreviationsCallback {
2781 my ($text, $symbol, $tag) = @_;
2783 if ($tag =~ m/^<programlisting/) {
2784 # Handle any embedded CDATA sections.
2785 return &ModifyXMLElements ($text, $symbol,
2787 \&ExpandAbbreviationsEndTag,
2788 \&ExpandAbbreviationsCallback2);
2789 } elsif ($tag eq "") {
2790 # We are outside any CDATA or <programlisting> sections, so we expand
2791 # any gtk-doc abbreviations.
2793 # Convert '@param()'
2794 # FIXME: we could make those also links ($symbol.$2), but that would be less
2795 # useful as the link target is a few lines up or down
2796 $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)\s*\(\)/$1<parameter>$2()<\/parameter>/g;
2798 # Convert 'function()' or 'macro()'.
2799 # if there is abc_*_def() we don't want to make a link to _def()
2800 # FIXME: also handle abc(def(....)) : but that would need to be done recursively :/
2801 $text =~ s/([^\*.\w])(\w+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2802 # handle #Object.func()
2803 $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2805 # Convert '@param', but not '\@param'.
2806 $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)/$1<parameter>$2<\/parameter>/g;
2807 $text =~ s/\\\@/\@/g;
2809 # Convert '%constant', but not '\%constant'.
2810 # Also allow negative numbers, e.g. %-1.
2811 $text =~ s/(\A|[^\\])\%(-?\w+)/$1.&MakeXRef($2, &tagify($2, "literal"));/eg;
2812 $text =~ s/\\\%/\%/g;
2814 # Convert '#symbol', but not '\#symbol'.
2815 $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)/$1.&MakeHashXRef($2, "type");/eg;
2819 # FIXME: should we skip urls that are already tagged? (e.g. <literal>http://...</literal>)
2820 # this is apparently also called for markup and not just for plain text
2822 #$text =~ s%(http|https|ftp)://(.*?)((?:\s|,|\)|\]|\<|\.\s))%<ulink url="$1://$2">$2</ulink>$3%g;
2824 # TODO: optionally check all words from $text against internal symbols and
2825 # warn if those could be xreffed, but miss a %,# or ()
2831 # This is called inside a <programlisting>
2832 sub ExpandAbbreviationsCallback2 {
2833 my ($text, $symbol, $tag) = @_;
2836 # We are inside a <programlisting> but outside any CDATA sections,
2837 # so we expand any gtk-doc abbreviations.
2838 # FIXME: why is this different from &ExpandAbbreviationsCallback(),
2839 # why not just call it
2840 $text =~ s/#(\w+)/&MakeHashXRef($1, "");/eg;
2847 my ($symbol, $tag) = @_;;
2850 # Check for things like '#include', '#define', and skip them.
2851 if ($PreProcessorDirectives{$symbol}) {
2855 # Get rid of special suffixes ('-struct','-enum').
2856 $text =~ s/-struct$//;
2857 $text =~ s/-enum$//;
2859 # If the symbol is in the form "Object::signal", then change the symbol to
2860 # "Object-signal" and use "signal" as the text.
2861 if ($symbol =~ s/::/-/) {
2865 # If the symbol is in the form "Object:property", then change the symbol to
2866 # "Object--property" and use "property" as the text.
2867 if ($symbol =~ s/:/--/) {
2872 $text = tagify ($text, $tag);
2875 return &MakeXRef($symbol, $text);
2879 #############################################################################
2880 # Function : ModifyXMLElements
2881 # Description : Looks for given XML element tags within the text, and calls
2882 # the callback on pieces of text inside & outside those elements.
2883 # Used for special handling of text inside things like CDATA
2884 # and <programlisting>.
2885 # Arguments : $text - the text.
2886 # $symbol - the symbol currently being documented (only used for
2888 # $start_tag_regexp - the regular expression to match start tags.
2889 # e.g. "<!\\[CDATA\\[|<programlisting[^>]*>" to match
2890 # CDATA sections or programlisting elements.
2891 # $end_tag_func - function which is passed the matched start tag
2892 # and should return the appropriate end tag string regexp.
2893 # $callback - callback called with each part of the text. It is
2894 # called with a piece of text, the symbol being
2895 # documented, and the matched start tag or "" if the text
2896 # is outside the XML elements being matched.
2897 #############################################################################
2898 sub ModifyXMLElements {
2899 my ($text, $symbol, $start_tag_regexp, $end_tag_func, $callback) = @_;
2900 my ($before_tag, $start_tag, $end_tag_regexp, $end_tag);
2903 while ($text =~ m/$start_tag_regexp/s) {
2904 $before_tag = $`; # Prematch for last successful match string
2905 $start_tag = $&; # Last successful match
2906 $text = $'; # Postmatch for last successful match string
2908 $result .= &$callback ($before_tag, $symbol, "");
2909 $result .= $start_tag;
2911 # get the matching end-tag for current tag
2912 $end_tag_regexp = &$end_tag_func ($start_tag);
2914 if ($text =~ m/$end_tag_regexp/s) {
2919 $result .= &$callback ($before_tag, $symbol, $start_tag);
2920 $result .= $end_tag;
2922 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2923 "Can't find tag end: $end_tag_regexp in docs for: $symbol.");
2924 # Just assume it is all inside the tag.
2925 $result .= &$callback ($text, $symbol, $start_tag);
2930 # Handle any remaining text outside the tags.
2931 $result .= &$callback ($text, $symbol, "");
2940 # Adds a tag around some text.
2941 # e.g tagify("Text", "literal") => "<literal>Text</literal>".
2943 my ($text, $elem) = @_;
2944 return "<" . $elem . ">" . $text . "</" . $elem . ">";
2948 #############################################################################
2949 # Function : MakeXRef
2950 # Description : This returns a cross-reference link to the given symbol.
2951 # Though it doesn't try to do this for a few standard C types
2952 # that it knows won't be in the documentation.
2953 # Arguments : $symbol - the symbol to try to create a XRef to.
2954 # $text - text text to put inside the XRef, defaults to $symbol
2955 #############################################################################
2958 my ($symbol, $text) = ($_[0], $_[1]);
2960 $symbol =~ s/^\s+//;
2961 $symbol =~ s/\s+$//;
2963 if (!defined($text)) {
2966 # Get rid of special suffixes ('-struct','-enum').
2967 $text =~ s/-struct$//;
2968 $text =~ s/-enum$//;
2971 if ($symbol =~ m/ /) {
2975 #print "Getting type link for $symbol -> $text\n";
2977 my $symbol_id = &CreateValidSGMLID ($symbol);
2978 return "<link linkend=\"$symbol_id\">$text</link>";
2982 #############################################################################
2983 # Function : MakeIndexterms
2984 # Description : This returns a indexterm elements for the given symbol
2985 # Arguments : $symbol - the symbol to create indexterms for
2986 #############################################################################
2988 sub MakeIndexterms {
2989 my ($symbol, $id) = @_;
2993 # make the index useful, by ommiting the namespace when sorting
2994 if ($NAME_SPACE ne "") {
2995 if ($symbol =~ m/^$NAME_SPACE\_?(.*)/i) {
2996 $sortas=" sortas=\"$1\"";
3000 if (exists $Deprecated{$symbol}) {
3001 $terms .= "<indexterm zone=\"$id\" role=\"deprecated\"><primary$sortas>$symbol</primary></indexterm>";
3002 $IndexEntriesDeprecated{$symbol}=$id;
3003 $IndexEntriesFull{$symbol}=$id;
3005 if (exists $Since{$symbol}) {
3006 my $since = $Since{$symbol};
3010 $terms .= "<indexterm zone=\"$id\" role=\"$since\"><primary$sortas>$symbol</primary></indexterm>";
3012 $IndexEntriesSince{$symbol}=$id;
3013 $IndexEntriesFull{$symbol}=$id;
3016 $terms .= "<indexterm zone=\"$id\"><primary$sortas>$symbol</primary></indexterm>";
3017 $IndexEntriesFull{$symbol}=$id;
3023 #############################################################################
3024 # Function : MakeDeprecationNote
3025 # Description : This returns a deprecation warning for the given symbol.
3026 # Arguments : $symbol - the symbol to try to create a warning for.
3027 #############################################################################
3029 sub MakeDeprecationNote {
3030 my ($symbol) = $_[0];
3033 if (exists $Deprecated{$symbol}) {
3034 $desc .= "<warning>";
3036 if ($Deprecated{$symbol} =~ /^\s*([0-9\.]+)\s*:/) {
3037 $desc .= "<para><literal>$symbol</literal> has been deprecated since version $1 and should not be used in newly-written code.";
3039 $desc .= "<para><literal>$symbol</literal> is deprecated and should not be used in newly-written code.";
3041 if ($Deprecated{$symbol} ne "") {
3042 $note = &ExpandAbbreviations($symbol, $Deprecated{$symbol});
3043 $note =~ s/^\s*([0-9\.]+)\s*:\s*//;
3046 $note =~ s%\n{2,}%\n</para>\n<para>\n%g;
3047 $desc .= " " . $note;
3049 $desc .= "</para></warning>\n";
3054 #############################################################################
3055 # Function : MakeConditionDescription
3056 # Description : This returns a sumary of conditions for the given symbol.
3057 # Arguments : $symbol - the symbol to try to create the sumary.
3058 #############################################################################
3060 sub MakeConditionDescription {
3061 my ($symbol) = $_[0];
3064 if (exists $Deprecated{$symbol}) {
3069 if ($Deprecated{$symbol} =~ /^\s*(.*?)\s*$/) {
3070 $desc .= "deprecated:$1";
3072 $desc .= "deprecated";
3076 if (exists $Since{$symbol}) {
3081 if ($Since{$symbol} =~ /^\s*(.*?)\s*$/) {
3082 $desc .= "since:$1";
3088 if (exists $StabilityLevel{$symbol}) {
3092 $desc .= "stability:".$StabilityLevel{$symbol};
3096 $desc=" condition=\"".$desc."\"";
3097 #print "condition for '$symbol' = '$desc'\n";
3102 #############################################################################
3103 # Function : GetHierarchy
3104 # Description : Returns the DocBook output describing the ancestors and
3105 # immediate children of a GObject subclass. It uses the
3106 # global @Objects and @ObjectLevels arrays to walk the tree.
3107 # Arguments : $object - the GtkObject subclass.
3108 #############################################################################
3113 # Find object in the objects array.
3119 for ($i = 0; $i < @Objects; $i++) {
3121 if ($ObjectLevels[$i] <= $level) {
3124 elsif ($ObjectLevels[$i] == $level + 1) {
3125 push (@children, $Objects[$i]);
3128 elsif ($Objects[$i] eq $object) {
3131 $level = $ObjectLevels[$i];
3138 # Walk up the hierarchy, pushing ancestors onto the ancestors array.
3140 push (@ancestors, $object);
3141 #print "Level: $level\n";
3142 while ($level > 1) {
3144 if ($ObjectLevels[$j] < $level) {
3145 push (@ancestors, $Objects[$j]);
3146 $level = $ObjectLevels[$j];
3147 #print "Level: $level\n";
3151 # Output the ancestors list, indented and with links.
3152 my $hierarchy = "<synopsis>\n";
3154 for ($i = $#ancestors; $i >= 0; $i--) {
3156 # Don't add a link to the current object, i.e. when i == 0.
3158 my $ancestor_id = &CreateValidSGMLID ($ancestors[$i]);
3159 $link_text = "<link linkend=\"$ancestor_id\">$ancestors[$i]</link>";
3161 $link_text = "$ancestors[$i]";
3164 $hierarchy .= " $link_text\n";
3166 # $hierarchy .= ' ' x ($level * 6 - 3) . "|\n";
3167 $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3171 for ($i = 0; $i <= $#children; $i++) {
3172 my $id = &CreateValidSGMLID ($children[$i]);
3173 my $link_text = "<link linkend=\"$id\">$children[$i]</link>";
3174 $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3176 $hierarchy .= "</synopsis>\n";
3182 #############################################################################
3183 # Function : GetInterfaces
3184 # Description : Returns the DocBook output describing the interfaces
3185 # implemented by a class. It uses the global %Interfaces hash.
3186 # Arguments : $object - the GtkObject subclass.
3187 #############################################################################
3194 # Find object in the objects array.
3195 if (exists($Interfaces{$object})) {
3196 my @ifaces = split(' ', $Interfaces{$object});
3201 for ($i = 0; $i <= $#ifaces; $i++) {
3202 my $id = &CreateValidSGMLID ($ifaces[$i]);
3203 $text .= " <link linkend=\"$id\">$ifaces[$i]</link>";
3204 if ($i < $#ifaces - 1) {
3207 elsif ($i < $#ifaces) {
3222 #############################################################################
3223 # Function : GetImplementations
3224 # Description : Returns the DocBook output describing the implementations
3225 # of an interface. It uses the global %Interfaces hash.
3226 # Arguments : $object - the GtkObject subclass.
3227 #############################################################################
3229 sub GetImplementations {
3234 foreach my $key (keys %Interfaces) {
3235 if ($Interfaces{$key} =~ /\b$object\b/) {
3236 push (@impls, $key);
3240 @impls = sort @impls;
3243 $object is implemented by
3245 for ($i = 0; $i <= $#impls; $i++) {
3246 my $id = &CreateValidSGMLID ($impls[$i]);
3247 $text .= " <link linkend=\"$id\">$impls[$i]</link>";
3248 if ($i < $#impls - 1) {
3251 elsif ($i < $#impls) {
3266 #############################################################################
3267 # Function : GetPrerequisites
3268 # Description : Returns the DocBook output describing the prerequisites
3269 # of an interface. It uses the global %Prerequisites hash.
3270 # Arguments : $iface - the interface.
3271 #############################################################################
3273 sub GetPrerequisites {
3278 if (exists($Prerequisites{$iface})) {
3283 my @prereqs = split(' ', $Prerequisites{$iface});
3284 for ($i = 0; $i <= $#prereqs; $i++) {
3285 my $id = &CreateValidSGMLID ($prereqs[$i]);
3286 $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
3287 if ($i < $#prereqs - 1) {
3290 elsif ($i < $#prereqs) {
3304 #############################################################################
3305 # Function : GetDerived
3306 # Description : Returns the DocBook output describing the derived interfaces
3307 # of an interface. It uses the global %Prerequisites hash.
3308 # Arguments : $iface - the interface.
3309 #############################################################################
3317 foreach my $key (keys %Prerequisites) {
3318 if ($Prerequisites{$key} =~ /\b$iface\b/) {
3319 push (@derived, $key);
3322 if ($#derived >= 0) {
3323 @derived = sort @derived;
3326 $iface is required by
3328 for ($i = 0; $i <= $#derived; $i++) {
3329 my $id = &CreateValidSGMLID ($derived[$i]);
3330 $text .= " <link linkend=\"$id\">$derived[$i]</link>";
3331 if ($i < $#derived - 1) {
3334 elsif ($i < $#derived) {
3349 #############################################################################
3350 # Function : GetSignals
3351 # Description : Returns the synopsis and detailed description DocBook output
3352 # for the signal handlers of a given GtkObject subclass.
3353 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
3354 #############################################################################
3362 for ($i = 0; $i <= $#SignalObjects; $i++) {
3363 if ($SignalObjects[$i] eq $object) {
3364 #print "Found signal: $SignalNames[$i]\n";
3365 my $name = $SignalNames[$i];
3366 my $symbol = "${object}::${name}";
3367 my $id = &CreateValidSGMLID ("$object-$name");
3369 my $pad = ' ' x (46 - length($name));
3370 $synop .= " "<link linkend=\"$id\">$name</link>"$pad ";
3372 $desc .= "<refsect2 id=\"$id\" role=\"signal\"><title>The <literal>"$name"</literal> signal</title>\n";
3373 $desc .= MakeIndexterms($symbol, $id);
3375 $desc .= OutputSymbolExtraLinks($symbol);
3377 $desc .= "<programlisting>";
3379 $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
3380 my $type_modifier = defined($1) ? $1 : "";
3383 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
3385 my $ret_type_len = length ($type_modifier) + length ($pointer)
3387 my $ret_type_output = "$type_modifier$xref$pointer"
3388 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
3390 $desc .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
3392 my $sourceparams = $SourceSymbolParams{$symbol};
3393 my @params = split ("\n", $SignalPrototypes[$i]);
3396 my $type_len = length("gpointer");
3397 my $name_len = length("user_data");
3398 # do two passes, the first one is to calculate padding
3399 for ($l = 0; $l < 2; $l++) {
3400 for ($j = 0; $j <= $#params; $j++) {
3401 # allow alphanumerics, '_', '[' & ']' in param names
3402 if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
3405 if (defined($sourceparams)) {
3406 $name = $$sourceparams[$PARAM_FIELD_COUNT * $j];
3411 if (!defined($name)) {
3415 if (length($type) + length($pointer) > $type_len) {
3416 $type_len = length($type) + length($pointer);
3418 if (length($name) > $name_len) {
3419 $name_len = length($name);
3423 $xref = &MakeXRef ($type, &tagify($type, "type"));
3424 $pad = ' ' x ($type_len - length($type) - length($pointer));
3425 $desc .= "$xref$pad $pointer$name,\n";
3426 $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
3429 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3430 "Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]");
3434 $xref = &MakeXRef ("gpointer", &tagify("gpointer", "type"));
3435 $pad = ' ' x ($type_len - length("gpointer"));
3436 $desc .= "$xref$pad user_data)";
3438 my $flags = $SignalFlags[$i];
3439 my $flags_string = "";
3441 if (defined ($flags)) {
3442 if ($flags =~ m/f/) {
3443 $flags_string = "<link linkend=\"G-SIGNAL-RUN-FIRST:CAPS\"><literal>Run First</literal></link>";
3445 elsif ($flags =~ m/l/) {
3446 $flags_string = "<link linkend=\"G-SIGNAL-RUN-LAST:CAPS\"><literal>Run Last</literal></link>";
3448 elsif ($flags =~ m/c/) {
3449 $flags_string = "<link linkend=\"G-SIGNAL-RUN-CLEANUP:CAPS\"><literal>Cleanup</literal></link>";
3450 $flags_string = "Cleanup";
3452 if ($flags =~ m/r/) {
3453 if ($flags_string) { $flags_string .= " / "; }
3454 $flags_string = "<link linkend=\"G-SIGNAL-NO-RECURSE:CAPS\"><literal>No Recursion</literal></link>";
3456 if ($flags =~ m/d/) {
3457 if ($flags_string) { $flags_string .= " / "; }
3458 $flags_string = "<link linkend=\"G-SIGNAL-DETAILED:CAPS\"><literal>Has Details</literal></link>";
3460 if ($flags =~ m/a/) {
3461 if ($flags_string) { $flags_string .= " / "; }
3462 $flags_string = "<link linkend=\"G-SIGNAL-ACTION:CAPS\"><literal>Action</literal></link>";
3464 if ($flags =~ m/h/) {
3465 if ($flags_string) { $flags_string .= " / "; }
3466 $flags_string = "<link linkend=\"G-SIGNAL-NO-HOOKS:CAPS\"><literal>No Hooks</literal></link>";
3472 $synop .= ": $flags_string\n";
3474 $pad = ' ' x (5 + $name_len - length("user_data"));
3475 $desc .= "$pad : $flags_string</programlisting>\n";
3480 $desc .= "</programlisting>\n";
3483 $desc .= &MakeDeprecationNote($symbol);
3485 my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
3486 my $parameters_output = 0;
3488 $AllSymbols{$symbol} = 1;
3489 if (defined ($SymbolDocs{$symbol})) {
3490 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3492 # Try to insert the parameter table at the author's desired
3493 # position. Otherwise we need to tag it onto the end.
3494 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
3495 $parameters_output = 1;
3497 $desc .= $symbol_docs;
3499 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
3500 $AllDocumentedSymbols{$symbol} = 1;
3504 if ($parameters_output == 0) {
3505 $desc .= $parameters;
3507 $desc .= OutputSymbolTraits ($symbol);
3508 $desc .= "</refsect2>";
3511 return ($synop, $desc);
3515 #############################################################################
3516 # Function : GetArgs
3517 # Description : Returns the synopsis and detailed description DocBook output
3518 # for the Args of a given GtkObject subclass.
3519 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
3520 #############################################################################
3526 my $child_synop = "";
3527 my $child_desc = "";
3528 my $style_synop = "";
3529 my $style_desc = "";
3532 for ($i = 0; $i <= $#ArgObjects; $i++) {
3533 if ($ArgObjects[$i] eq $object) {
3534 #print "Found arg: $ArgNames[$i]\n";
3535 my $name = $ArgNames[$i];
3536 my $flags = $ArgFlags[$i];
3537 my $flags_string = "";
3541 if ($flags =~ m/c/) {
3542 $kind = "child property";
3545 elsif ($flags =~ m/s/) {
3546 $kind = "style property";
3553 # Remember only one colon so we don't clash with signals.
3554 my $symbol = "${object}:${name}";
3555 # use two dashes and ev. an extra separator here for the same reason.
3556 my $id = &CreateValidSGMLID ("$object--$id_sep$name");
3558 my $type = $ArgTypes[$i];
3560 my $range = $ArgRanges[$i];
3561 my $range_output = CreateValidSGML ($range);
3562 my $default = $ArgDefaults[$i];
3563 my $default_output = CreateValidSGML ($default);
3565 if ($type eq "GtkString") {
3568 if ($type eq "GtkSignal") {
3569 $type = "GtkSignalFunc, gpointer";
3570 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
3571 . &MakeXRef ("gpointer");
3572 } elsif ($type =~ m/^(\w+)\*$/) {
3573 $type_output = &MakeXRef ($1, &tagify($1, "type")) . "*";
3575 $type_output = &MakeXRef ($type, &tagify($type, "type"));
3578 if ($flags =~ m/r/) {
3579 $flags_string = "Read";
3581 if ($flags =~ m/w/) {
3582 if ($flags_string) { $flags_string .= " / "; }
3583 $flags_string .= "Write";
3585 if ($flags =~ m/x/) {
3586 if ($flags_string) { $flags_string .= " / "; }
3587 $flags_string .= "Construct";
3589 if ($flags =~ m/X/) {
3590 if ($flags_string) { $flags_string .= " / "; }
3591 $flags_string .= "Construct Only";
3594 $AllSymbols{$symbol} = 1;
3596 if (defined($SymbolDocs{$symbol}) &&
3597 !IsEmptyDoc($SymbolDocs{$symbol})) {
3598 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3599 #print ".. [$SymbolDocs{$symbol}][$blurb]\n";
3600 $AllDocumentedSymbols{$symbol} = 1;
3603 if (!($ArgBlurbs[$i] eq "")) {
3604 $AllDocumentedSymbols{$symbol} = 1;
3606 # FIXME: print a warning?
3607 #print ".. no description\n";
3609 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
3612 my $pad1 = " " x (24 - length ($name));
3613 my $pad2 = " " x (20 - length ($type));
3615 my $arg_synop = " "<link linkend=\"$id\">$name</link>"$pad1 $type_output $pad2 : $flags_string\n";
3616 my $arg_desc = "<refsect2 id=\"$id\" role=\"property\"><title>The <literal>"$name"</literal> $kind</title>\n";
3617 $arg_desc .= MakeIndexterms($symbol, $id);
3619 $arg_desc .= OutputSymbolExtraLinks($symbol);
3621 $arg_desc .= "<programlisting> "$name"$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
3622 $arg_desc .= &MakeDeprecationNote($symbol);
3623 $arg_desc .= $blurb;
3625 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
3627 if ($default ne "") {
3628 $arg_desc .= "<para>Default value: $default_output</para>\n";
3630 $arg_desc .= OutputSymbolTraits ($symbol);
3631 $arg_desc .= "</refsect2>\n";
3633 if ($flags =~ m/c/) {
3634 $child_synop .= $arg_synop;
3635 $child_desc .= $arg_desc;
3637 elsif ($flags =~ m/s/) {
3638 $style_synop .= $arg_synop;
3639 $style_desc .= $arg_desc;
3642 $synop .= $arg_synop;
3647 return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
3651 #############################################################################
3652 # Function : ReadSourceDocumentation
3653 # Description : This reads in the documentation embedded in comment blocks
3654 # in the source code (for Gnome).
3656 # Parameter descriptions override any in the template files.
3657 # Function descriptions are placed before any description from
3658 # the template files.
3660 # It recursively descends the source directory looking for .c
3661 # files and scans them looking for specially-formatted comment
3664 # Arguments : $source_dir - the directory to scan.
3665 #############m###############################################################
3667 sub ReadSourceDocumentation {
3668 my ($source_dir) = @_;
3669 my ($file, $dir, @suffix_list, $suffix);
3671 # prepend entries from @SOURCE_DIR
3672 for my $dir (@SOURCE_DIRS) {
3673 # Check if the filename is in the ignore list.
3674 if ($source_dir =~ m%^\Q$dir\E/(.*)$% and $IGNORE_FILES =~ m/(\s|^)\Q$1\E(\s|$)/) {
3675 @TRACE@("Skipping source directory: $source_dir");
3680 @TRACE@("Scanning source directory: $source_dir");
3682 # This array holds any subdirectories found.
3685 @suffix_list = split (/,/, $SOURCE_SUFFIXES);
3687 opendir (SRCDIR, $source_dir)
3688 || die "Can't open source directory $source_dir: $!";
3690 foreach $file (readdir (SRCDIR)) {
3691 if ($file =~ /^\./) {
3693 } elsif (-d "$source_dir/$file") {
3694 push (@subdirs, $file);
3695 } elsif (@suffix_list) {
3696 foreach $suffix (@suffix_list) {
3697 if ($file =~ m/\.\Q${suffix}\E$/) {
3698 &ScanSourceFile ("$source_dir/$file");
3701 } elsif ($file =~ m/\.[ch]$/) {
3702 &ScanSourceFile ("$source_dir/$file");
3707 # Now recursively scan the subdirectories.
3708 foreach $dir (@subdirs) {
3709 &ReadSourceDocumentation ("$source_dir/$dir");
3714 #############################################################################
3715 # Function : ScanSourceFile
3716 # Description : Scans one source file looking for specially-formatted comment
3717 # blocks. Later &MergeSourceDocumentation is used to merge any
3718 # documentation found with the documentation already read in
3719 # from the template files.
3721 # Arguments : $file - the file to scan.
3722 #############################################################################
3724 sub ScanSourceFile {
3728 # prepend entries from @SOURCE_DIR
3729 for my $dir (@SOURCE_DIRS) {
3730 # Check if the filename is in the ignore list.
3731 if ($file =~ m%^\Q$dir\E/(.*)$% and $IGNORE_FILES =~ m/(\s|^)\Q$1\E(\s|$)/) {
3732 @TRACE@("Skipping source file: $file");
3737 if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
3740 &LogWarning ($file, 1, "Can't find basename for this filename.");
3744 # Check if the basename is in the list of files to ignore.
3745 if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
3746 @TRACE@("Skipping source file: $file");
3750 @TRACE@("Scanning source file: $file");
3752 open (SRCFILE, $file)
3753 || die "Can't open $file: $!";
3754 my $in_comment_block = 0;
3757 my ($description, $return_desc, $return_start, $return_style);
3758 my ($since_desc, $stability_desc, $deprecated_desc);
3760 my $ignore_broken_returns;
3763 # Look for the start of a comment block.
3764 if (!$in_comment_block) {
3765 if (m%^\s*/\*.*\*/%) {
3766 #one-line comment - not gtkdoc
3767 } elsif (m%^\s*/\*\*\s%) {
3768 #print "Found comment block start\n";
3770 $in_comment_block = 1;
3772 # Reset all the symbol data.
3779 $deprecated_desc = "";
3780 $stability_desc = "";
3781 $current_param = -1;
3782 $ignore_broken_returns = 0;
3788 # We're in a comment block. Check if we've found the end of it.
3791 # maybe its not even meant to be a gtk-doc comment?
3792 &LogWarning ($file, $., "Symbol name not found at the start of the comment block.");
3794 # Add the return value description onto the end of the params.
3796 push (@params, "Returns");
3797 push (@params, $return_desc);
3798 if ($return_style eq 'broken') {
3799 &LogWarning ($file, $., "Free-form return value description in $symbol. Use `Returns:' to avoid ambiguities.");
3802 # Convert special SGML characters
3803 $description = &ConvertSGMLChars ($symbol, $description);
3805 for ($k = 1; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3806 $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
3809 # Handle Section docs
3810 if ($symbol =~ m/SECTION:\s*(.*)/) {
3814 if (scalar %KnownSymbols) {
3815 if ((! defined($KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"})) || $KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"} != 1) {
3816 &LogWarning ($file, $., "Section $real_symbol is not defined in the $MODULE-sections.txt file.");
3820 #print "SECTION DOCS found in source for : '$real_symbol'\n";
3821 $ignore_broken_returns = 1;
3822 for ($k = 0; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3823 #print " '".$params[$k]."'\n";
3824 $params[$k] = "\L$params[$k]";
3826 if ($params[$k] eq "short_description") {
3827 $key = "$TMPL_DIR/$real_symbol:Short_Description";
3828 } elsif ($params[$k] eq "see_also") {
3829 $key = "$TMPL_DIR/$real_symbol:See_Also";
3830 } elsif ($params[$k] eq "title") {
3831 $key = "$TMPL_DIR/$real_symbol:Title";
3832 } elsif ($params[$k] eq "stability") {
3833 $key = "$TMPL_DIR/$real_symbol:Stability_Level";
3834 } elsif ($params[$k] eq "section_id") {
3835 $key = "$TMPL_DIR/$real_symbol:Section_Id";
3836 } elsif ($params[$k] eq "include") {
3837 $key = "$TMPL_DIR/$real_symbol:Include";
3838 } elsif ($params[$k] eq "image") {
3839 $key = "$TMPL_DIR/$real_symbol:Image";
3841 if (defined($key)) {
3842 $SourceSymbolDocs{$key}=$params[$k+1];
3843 $SourceSymbolSourceFile{$key} = $file;
3844 $SourceSymbolSourceLine{$key} = $.;
3847 $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
3848 $SourceSymbolSourceFile{"$TMPL_DIR/$real_symbol:Long_Description"} = $file;
3849 $SourceSymbolSourceLine{"$TMPL_DIR/$real_symbol:Long_Description"} = $.;
3850 #$SourceSymbolTypes{$symbol} = "SECTION";
3852 #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
3853 $SourceSymbolDocs{$symbol} = $description;
3854 $SourceSymbolParams{$symbol} = [ @params ];
3855 # FIXME $SourceSymbolTypes{$symbol} = "STRUCT,SIGNAL,ARG,FUNCTION,MACRO";
3856 #if (defined $DeclarationTypes{$symbol}) {
3857 # $SourceSymbolTypes{$symbol} = $DeclarationTypes{$symbol}
3859 $SourceSymbolSourceFile{$symbol} = $file;
3860 $SourceSymbolSourceLine{$symbol} = $.;
3864 ($since_desc, my @extra_lines) = split ("\n", $since_desc);
3865 $since_desc =~ s/^\s+//;
3866 $since_desc =~ s/\s+$//;
3867 #print "Since($symbol) : [$since_desc]\n";
3868 $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
3869 if(scalar @extra_lines) {
3870 &LogWarning ($file, $., "multi-line since docs found");
3874 if ($stability_desc) {
3875 $stability_desc = &ParseStabilityLevel($stability_desc, $file, $., "Stability level for $symbol");
3876 $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
3879 if ($deprecated_desc) {
3880 if (exists $Deprecated{$symbol}) {
3883 # don't warn for signals and properties
3884 #if ($symbol !~ m/::?(.*)/) {
3885 if (defined $DeclarationTypes{$symbol}) {
3886 &LogWarning ($file, $.,
3887 "$symbol is deprecated in the inline comments, but no deprecation guards were found around the declaration.".
3888 " (See the --deprecated-guards option for gtkdoc-scan.)");
3891 $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
3895 $in_comment_block = 0;
3899 # Get rid of ' * ' at start of every line in the comment block.
3901 # But make sure we don't get rid of the newline at the end.
3905 #print "DEBUG: scanning :$_";
3907 # If we haven't found the symbol name yet, look for it.
3909 if (m%^\s*(SECTION:\s*\S+)%) {
3911 #print "SECTION DOCS found in source for : '$symbol'\n";
3912 $ignore_broken_returns = 1;
3913 } elsif (m%^\s*([\w:-]*\w)\s*:?\s*(\([a-z ]+\)\s*)*$%) {
3915 #print "SYMBOL DOCS found in source for : '$symbol'\n";
3920 if ($in_part eq "description") {
3921 # Get rid of 'Description:'
3922 s%^\s*Description:%%;
3925 if (m/^\s*(returns:|return\s+value:)/i) {
3926 if ($return_style eq 'broken') {
3927 $description .= $return_start . $return_desc;
3930 if ($return_style eq 'sane') {
3931 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3933 $return_style = 'sane';
3934 $ignore_broken_returns = 1;
3936 $in_part = "return";
3938 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3940 $return_style = 'broken';
3942 $in_part = "return";
3944 } elsif (m%^\s*since:%i) {
3945 # we're in param section and have not seen the blank line
3946 if($in_part ne "") {
3951 } elsif (m%^\s*deprecated:%i) {
3952 # we're in param section and have not seen the blank line
3953 if($in_part ne "") {
3954 $deprecated_desc = $';
3955 $in_part = "deprecated";
3958 } elsif (m%^\s*stability:%i) {
3959 $stability_desc = $';
3960 $in_part = "stability";
3964 if ($in_part eq "description") {
3967 } elsif ($in_part eq "return") {
3970 } elsif ($in_part eq "since") {
3973 } elsif ($in_part eq "stability") {
3974 $stability_desc .= $_;
3976 } elsif ($in_part eq "deprecated") {
3977 $deprecated_desc .= $_;
3981 # We must be in the parameters. Check for the empty line below them.
3983 $in_part = "description";
3987 # Look for a parameter name.
3988 if (m%^\s*@(\S+)\s*:\s*%) {
3989 my $param_name = $1;
3990 my $param_desc = $';
3992 #print "Found parameter: $param_name\n";
3993 # Allow varargs variations
3994 if ($param_name =~ m/^\.\.\.$/) {
3995 $param_name = "...";
3997 if ("\L$param_name" eq "returns") {
3998 $return_style = 'sane';
3999 $ignore_broken_returns = 1;
4001 @TRACE@("Found param for symbol $symbol : '$param_name'= '$_'");
4003 push (@params, $param_name);
4004 push (@params, $param_desc);
4005 $current_param += $PARAM_FIELD_COUNT;
4009 # We must be in the middle of a parameter description, so add it on
4010 # to the last element in @params.
4011 if ($current_param == -1) {
4012 &LogWarning ($file, $., "Parsing comment block file : parameter expected.");
4014 $params[$#params] .= $_;
4020 #############################################################################
4021 # Function : OutputMissingDocumentation
4022 # Description : Outputs report of documentation coverage to a file
4025 #############################################################################
4027 sub OutputMissingDocumentation {
4028 my $old_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.txt";
4029 my $new_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.new";
4031 my $n_documented = 0;
4032 my $n_incomplete = 0;
4038 my $buffer_deprecated = "";
4039 my $buffer_descriptions = "";
4041 open(UNDOCUMENTED, ">$new_undocumented_file")
4042 || die "Can't create $new_undocumented_file";
4044 foreach $symbol (sort (keys (%AllSymbols))) {
4045 # FIXME: should we print LogWarnings for undocumented stuff?
4047 #my $ssfile = &GetSymbolSourceFile($symbol);
4048 #my $ssline = &GetSymbolSourceLine($symbol);
4049 #my $location = "defined at " . (defined($ssfile)?$ssfile:"?") . ":" . (defined($ssline)?$ssline:"0") . "\n";
4051 if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include|Section_Id|Image)/) {
4053 if (exists ($AllDocumentedSymbols{$symbol})) {
4055 if (exists ($AllIncompleteSymbols{$symbol})) {
4057 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4058 #$buffer .= "\t0: ".$location;
4060 } elsif (exists $Deprecated{$symbol}) {
4061 if (exists ($AllIncompleteSymbols{$symbol})) {
4063 $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4064 #$buffer .= "\t1a: ".$location;
4066 $buffer_deprecated .= $symbol . "\n";
4067 #$buffer .= "\t1b: ".$location;
4070 if (exists ($AllIncompleteSymbols{$symbol})) {
4072 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4073 #$buffer .= "\t2a: ".$location;
4075 $buffer .= $symbol . "\n";
4076 #$buffer .= "\t2b: ".$location;
4079 } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
4081 #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
4082 #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
4083 #print "%%%% $symbol : $len1,$len2\n";
4084 if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
4085 || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
4088 # cut off the leading namespace ($TMPL_DIR)
4089 $symbol =~ m/^.*\/(.*)$/;
4090 $buffer_descriptions .= $1 . "\n";
4095 $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
4100 $percent = ($n_documented / $total) * 100.0;
4103 printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
4104 print UNDOCUMENTED "$n_documented symbols documented.\n";
4105 print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
4106 print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
4108 print UNDOCUMENTED $buffer;
4109 close (UNDOCUMENTED);
4111 return &UpdateFileIfChanged ($old_undocumented_file, $new_undocumented_file, 0);
4113 printf "%.0f%% symbol docs coverage", $percent;
4114 print "($n_documented symbols documented, $n_incomplete symbols incomplete, " . ($total - $n_documented) . " not documented)\n";
4115 print "See $MODULE-undocumented.txt for a list of missing docs.\nThe doc coverage percentage doesn't include intro sections.\n";
4119 #############################################################################
4120 # Function : OutputUndeclaredSymbols
4121 # Description : Outputs symbols that are listed in the section file, but not
4122 # declaration is found in the sources
4125 #############################################################################
4127 sub OutputUndeclaredSymbols {
4128 my $old_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.txt";
4129 my $new_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.new";
4131 open(UNDECLARED, ">$new_undeclared_file")
4132 || die "Can't create $new_undeclared_file";
4134 if (%UndeclaredSymbols) {
4135 print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
4136 print UNDECLARED "\n";
4137 print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
4141 return &UpdateFileIfChanged ($old_undeclared_file, $new_undeclared_file, 0);
4144 #############################################################################
4145 # Function : OutputUnusedSymbols
4146 # Description : Outputs symbols that are documented in comments, but not
4147 # declared in the sources
4150 #############################################################################
4152 sub OutputUnusedSymbols {
4154 my $old_unused_file = "$ROOT_DIR/$MODULE-unused.txt";
4155 my $new_unused_file = "$ROOT_DIR/$MODULE-unused.new";
4157 open (UNUSED, ">$new_unused_file")
4158 || die "Can't open $new_unused_file";
4160 foreach $symbol (sort keys (%Declarations)) {
4161 if (!defined ($DeclarationOutput{$symbol})) {
4162 print (UNUSED "$symbol\n");
4166 foreach $symbol (sort (keys (%AllUnusedSymbols))) {
4167 print (UNUSED "$symbol(" . $AllUnusedSymbols{$symbol} . ")\n");
4171 if ($num_unused != 0) {
4172 &LogWarning ($old_unused_file, 1, "$num_unused unused declarations.".
4173 "They should be added to $MODULE-sections.txt in the appropriate place.");
4176 return &UpdateFileIfChanged ($old_unused_file, $new_unused_file, 0);
4180 #############################################################################
4181 # Function : OutputAllSymbols
4182 # Description : Outputs list of all symbols to a file
4185 #############################################################################
4187 sub OutputAllSymbols {
4188 my $n_documented = 0;
4194 open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
4195 || die "Can't create $ROOT_DIR/$MODULE-symbols.txt: $!";
4197 foreach $symbol (sort (keys (%AllSymbols))) {
4198 print SYMBOLS $symbol . "\n";
4204 #############################################################################
4205 # Function : OutputSymbolsWithoutSince
4206 # Description : Outputs list of all symbols without a since tag to a file
4209 #############################################################################
4211 sub OutputSymbolsWithoutSince {
4212 my $n_documented = 0;
4218 open (SYMBOLS, ">$ROOT_DIR/$MODULE-nosince.txt")
4219 || die "Can't create $ROOT_DIR/$MODULE-nosince.txt: $!";
4221 foreach $symbol (sort (keys (%SourceSymbolDocs))) {
4222 if (!defined $Since{$symbol}) {
4223 print SYMBOLS $symbol . "\n";
4231 #############################################################################
4232 # Function : MergeSourceDocumentation
4233 # Description : This merges documentation read from a source file into the
4234 # documentation read in from a template file.
4236 # Parameter descriptions override any in the template files.
4237 # Function descriptions are placed before any description from
4238 # the template files.
4241 #############################################################################
4243 sub MergeSourceDocumentation {
4247 if (scalar %SymbolDocs) {
4248 @Symbols=keys (%SymbolDocs);
4249 #print "num existing entries: ".(scalar @Symbols)."\n";
4250 #print " ",$Symbols[0], " ",$Symbols[1],"\n";
4253 # filter scanned declarations, with what we suppress from -sections.txt
4255 foreach $symbol (keys (%Declarations)) {
4256 if (defined($KnownSymbols{$symbol}) && $KnownSymbols{$symbol} == 1) {
4260 # , add the rest from -sections.txt
4261 foreach $symbol (keys (%KnownSymbols)) {
4262 if ($KnownSymbols{$symbol} == 1) {
4266 # and add whats found in the source
4267 foreach $symbol (keys (%SourceSymbolDocs)) {
4270 @Symbols = keys (%tmp);
4271 #print "num source entries: ".(scalar @Symbols)."\n";
4273 foreach $symbol (@Symbols) {
4274 $AllSymbols{$symbol} = 1;
4276 my $have_tmpl_docs = 0;
4278 ## see if the symbol is documented in template
4279 my $tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4280 my $check_tmpl_doc =$tmpl_doc;
4281 # remove all xml-tags and whitespaces
4282 $check_tmpl_doc =~ s/<.*?>//g;
4283 $check_tmpl_doc =~ s/\s//g;
4285 if ($check_tmpl_doc ne "") {
4286 $have_tmpl_docs = 1;
4287 #print "## [$check_tmpl_doc]\n";
4289 # if the docs have just an empty para, don't merge that.
4290 $check_tmpl_doc = $tmpl_doc;
4291 $check_tmpl_doc =~ s/(\s|\n)//msg;
4292 if ($check_tmpl_doc eq "<para></para>") {
4297 if (exists ($SourceSymbolDocs{$symbol})) {
4298 my $type = $DeclarationTypes {$symbol};
4300 #print "merging [$symbol] from source\n";
4302 my $item = "Parameter";
4303 if (defined ($type)) {
4304 if ($type eq 'STRUCT') {
4306 } elsif ($type eq 'ENUM') {
4308 } elsif ($type eq 'UNION') {
4315 my $src_doc = $SourceSymbolDocs{$symbol};
4316 # remove leading and training whitespaces
4317 $src_doc =~ s/^\s+//;
4318 $src_doc =~ s/\s+$//;
4320 # Don't output warnings for overridden titles as titles are
4321 # automatically generated in the -sections.txt file, and thus they
4322 # are often overridden.
4323 if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
4324 # check if content is different
4325 if ($tmpl_doc ne $src_doc) {
4326 #print "[$tmpl_doc] [$src_doc]\n";
4327 &LogWarning ($SourceSymbolSourceFile{$symbol}, $SourceSymbolSourceLine{$symbol},
4328 "Documentation in template ".$SymbolSourceFile{$symbol}.":".$SymbolSourceLine{$symbol}." for $symbol being overridden by inline comments.");
4332 if ($src_doc ne "") {
4333 $AllDocumentedSymbols{$symbol} = 1;
4336 # Convert <!--PARAMETERS--> with any blank lines around it to
4337 # a </para> followed by <!--PARAMETERS--> followed by <para>.
4338 $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
4340 # Do not add <para> to nothing, it breaks missing docs checks.
4341 my $src_doc_para = "";
4342 if ($src_doc ne "") {
4343 # Expand markdown (and do paragraphs)
4344 $src_doc_para = &ConvertMarkDown ($src_doc, $symbol);
4346 # FIXME: this is questionable, as we can't make assumtions on the content really
4347 #$src_doc_para =~ s%^<para>\n(<refsect[1-9])%$1%gms;
4348 #$src_doc_para =~ s%^<para>\n<para>%<para>%gms;
4349 #$src_doc_para =~ s%(</refsect[1-9]>)\n</para>$%$1%gms;
4350 #print "$symbol : [$src_doc][$src_doc_para]\n";
4353 if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
4354 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4355 } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
4356 # For the title/summary/see also section docs we don't want to
4357 # add any <para> tags.
4358 $SymbolDocs{$symbol} = "$src_doc"
4360 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4364 if ($symbol =~ m/.*::.*/) {
4365 # For signals we prefer the param names from the source docs,
4366 # since the ones from the templates are likely to contain the
4367 # artificial argn names which are generated by gtkdoc-scangobj.
4368 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4369 # FIXME: we need to check for empty docs here as well!
4371 # The templates contain the definitive parameter names and order,
4372 # so we will not change that. We only override the actual text.
4373 my $tmpl_params = $SymbolParams{$symbol};
4374 if (!defined ($tmpl_params)) {
4375 #print "No merge needed for $symbol\n";
4376 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4377 # FIXME: we still like to get the number of params and merge
4378 # 1) we would noticed that params have been removed/renamed
4379 # 2) we would catch undocumented params
4380 # params are not (yet) exported in -decl.txt so that we
4381 # could easily grab them :/
4383 my $params = $SourceSymbolParams{$symbol};
4385 #print "Merge needed for $symbol, tmpl_params: ",$#$tmpl_params,", source_params: ",$#$params," \n";
4386 for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4387 my $tmpl_param_name = $$tmpl_params[$j];
4389 # Try to find the param in the source comment documentation.
4392 #print " try merge param $tmpl_param_name\n";
4393 for ($k = 0; $k <= $#$params; $k += $PARAM_FIELD_COUNT) {
4394 my $param_name = $$params[$k];
4395 my $param_desc = $$params[$k + 1];
4397 #print " test param $param_name\n";
4398 # We accept changes in case, since the Gnome source
4399 # docs contain a lot of these.
4400 if ("\L$param_name" eq "\L$tmpl_param_name") {
4403 # Override the description.
4404 $$tmpl_params[$j + 1] = $param_desc;
4406 # Set the name to "" to mark it as used.
4412 # If it looks like the parameters are there, but not
4413 # in the right place, try to explain a bit better.
4414 if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
4415 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4416 "Parameters for $symbol must start on the line immediately after the function or macro name.");
4420 # Now we output a warning if parameters have been described which
4422 for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
4423 my $param_name = $$params[$j];
4425 # the template builder cannot detect if a macro returns
4427 if(($type eq "MACRO") && ($param_name eq "Returns")) {
4428 # FIXME: do we need to add it then to tmpl_params[] ?
4429 my $num=$#$tmpl_params;
4430 #print " adding Returns: to macro docs for $symbol.\n";
4431 $$tmpl_params[$num+1]="Returns";
4432 $$tmpl_params[$num+2]=$$params[$j+1];
4435 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4436 "$item described in source code comment block but does not exist. $type: $symbol $item: $param_name.");
4442 if ($have_tmpl_docs) {
4443 $AllDocumentedSymbols{$symbol} = 1;
4444 #print "merging [$symbol] from template\n";
4447 #print "[$symbol] undocumented\n";
4451 # if this symbol is documented, check if docs are complete
4452 $check_tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4453 # remove all xml-tags and whitespaces
4454 $check_tmpl_doc =~ s/<.*?>//g;
4455 $check_tmpl_doc =~ s/\s//g;
4456 if ($check_tmpl_doc ne "") {
4457 my $tmpl_params = $SymbolParams{$symbol};
4458 if (defined ($tmpl_params)) {
4459 my $type = $DeclarationTypes {$symbol};
4461 my $item = "Parameter";
4462 if (defined ($type)) {
4463 if ($type eq 'STRUCT') {
4465 } elsif ($type eq 'ENUM') {
4467 } elsif ($type eq 'UNION') {
4474 #print "Check param docs for $symbol, tmpl_params: ",$#$tmpl_params," entries, type=$type\n";
4476 if ($#$tmpl_params > 0) {
4478 for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4479 # Output a warning if the parameter is empty and
4480 # remember for stats.
4481 my $tmpl_param_name = $$tmpl_params[$j];
4482 my $tmpl_param_desc = $$tmpl_params[$j + 1];
4483 if ($tmpl_param_name ne "void" && $tmpl_param_desc !~ m/\S/) {
4484 if (exists ($AllIncompleteSymbols{$symbol})) {
4485 $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
4487 $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
4489 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4490 "$item description for $symbol"."::"."$tmpl_param_name is missing in source code comment block.");
4495 if ($#$tmpl_params == 0) {
4496 $AllIncompleteSymbols{$symbol}="<items>";
4497 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4498 "$item descriptions for $symbol are missing in source code comment block.");
4500 # $#$tmpl_params==-1 means we don't know about parameters
4501 # this unfortunately does not tell if there should be some
4506 #print "num doc entries: ".(scalar %SymbolDocs)."\n";
4509 #############################################################################
4510 # Function : IsEmptyDoc
4511 # Description : Check if a doc-string is empty. Its also regarded as empty if
4512 # it only consist of whitespace or e.g. FIXME.
4513 # Arguments : the doc-string
4514 #############################################################################
4518 if ($doc =~ /^\s*$/) {
4522 if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
4530 #############################################################################
4531 # Function : ConvertMarkDown
4532 # Description : Converts mark down syntax to the respective docbook, but only
4533 # outside CDATA and <programlisting> tags.
4534 # http://de.wikipedia.org/wiki/Markdown
4535 # Code snippets have been takesn from
4536 # http://daringfireball.net/projects/markdown/
4537 # Copyright (c) 2004 John Gruber
4538 # Arguments : the doc-string, the symbol name
4539 #############################################################################
4541 sub ConvertMarkDown {
4542 my ($text, $symbol) = @_;
4548 $text = &ModifyXMLElements ($text, $symbol,
4549 "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
4550 \&ConvertMarkDownEndTag,
4551 \&ConvertMarkDownCallback);
4552 # encapsulate and terminate
4553 $text = "<para>\n$text\n</para>";
4554 if ($md_in_refsect2==1) {
4555 $text = "$text</refsect2>"
4560 sub ConvertMarkDownEndTag {
4561 if ($_[0] eq "<!\[CDATA\[") {
4563 } elsif ($_[0] eq "|[") {
4566 return "</programlisting>";
4570 sub ConvertMarkDownCallback {
4571 my ($text, $symbol, $tag) = @_;
4573 # If we're not in CDATA or a <programlisting> we convert blank lines so
4574 # they start a new <para>.
4577 my $end_of_section="";
4580 $end_of_para = "$end_of_para</para>";
4581 $end_of_section = "$end_of_section</para>";
4582 if ($md_in_refsect2==1) {
4583 $end_of_section= "$end_of_section</refsect2>";
4586 # TODO(ensonic): it would be nice to add id parameters to the refsect2 elements
4588 # Setext-style headers:
4595 if($text =~ s%^\n(.+)[ \t]*\n=+[ \t]*\n\n%$end_of_section<refsect2><title>$1</title><para>\n%gm) {
4599 # atx-style headers:
4602 # ## Header 2 with closing hashes ##
4606 if($text =~ s%^\n\#[ \t]*(.+?)[ \t]*\#\n+%$end_of_section<refsect2><title>$1</title><para>\n%gm) {
4610 # Simple (unnested) lists:
4613 # - item 2 with loooong
4618 $text.="\n"; # we need a new line to avoid too complicated matching rules below
4619 if ($text =~ s%(?<=\n)-\s+(.+?)(?=(?:\n-\s+)|(?:\n\n)|(?:\n$))%<listitem><para>$1</para></listitem>%gs) {
4620 $text =~ s%(?<!</listitem>)(\n<listitem>)%\n<itemizedlist>$1%g;
4621 $text =~ s%(</listitem>\n)(?!<listitem>)%$1</itemizedlist>\n%g;
4625 # Make Paragraphs on blank lines
4626 $text =~ s%\n{2,}%\n$end_of_para\n<para>\n%g;
4633 #############################################################################
4634 # LIBRARY FUNCTIONS - These functions are used in both gtkdoc-mkdb and
4635 # gtkdoc-mktmpl and should eventually be moved to a
4637 #############################################################################
4639 #############################################################################
4640 # Function : ReadDeclarationsFile
4641 # Description : This reads in a file containing the function/macro/enum etc.
4644 # Note that in some cases there are several declarations with
4645 # the same name, e.g. for conditional macros. In this case we
4646 # set a flag in the %DeclarationConditional hash so the
4647 # declaration is not shown in the docs.
4649 # If a macro and a function have the same name, e.g. for
4650 # gtk_object_ref, the function declaration takes precedence.
4652 # Some opaque structs are just declared with 'typedef struct
4653 # _name name;' in which case the declaration may be empty.
4654 # The structure may have been found later in the header, so
4655 # that overrides the empty declaration.
4657 # Arguments : $file - the declarations file to read
4658 # $override - if declarations in this file should override
4659 # any current declaration.
4660 #############################################################################
4662 sub ReadDeclarationsFile {
4663 my ($file, $override) = @_;
4665 if ($override == 0) {
4667 %DeclarationTypes = ();
4668 %DeclarationConditional = ();
4669 %DeclarationOutput = ();
4673 || die "Can't open $file: $!";
4674 my $declaration_type = "";
4675 my $declaration_name;
4677 my $is_deprecated = 0;
4679 if (!$declaration_type) {
4680 if (m/^<([^>]+)>/) {
4681 $declaration_type = $1;
4682 $declaration_name = "";
4683 #print "Found declaration: $declaration_type\n";
4687 if (m%^<NAME>(.*)</NAME>%) {
4688 $declaration_name = $1;
4689 } elsif (m%^<DEPRECATED/>%) {
4691 } elsif (m%^</$declaration_type>%) {
4692 #print "Found end of declaration: $declaration_name\n";
4693 # Check that the declaration has a name
4694 if ($declaration_name eq "") {
4695 print "ERROR: $declaration_type has no name $file:$.\n";
4698 # If the declaration is an empty typedef struct _XXX XXX
4699 # set the flag to indicate the struct has a typedef.
4700 if ($declaration_type eq 'STRUCT'
4701 && $declaration =~ m/^\s*$/) {
4702 #print "Struct has typedef: $declaration_name\n";
4703 $StructHasTypedef{$declaration_name} = 1;
4706 # Check if the symbol is already defined.
4707 if (defined ($Declarations{$declaration_name})
4708 && $override == 0) {
4709 # Function declarations take precedence.
4710 if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
4712 } elsif ($declaration_type eq 'FUNCTION') {
4713 if ($is_deprecated) {
4714 $Deprecated{$declaration_name} = "";
4716 $Declarations{$declaration_name} = $declaration;
4717 $DeclarationTypes{$declaration_name} = $declaration_type;
4718 } elsif ($DeclarationTypes{$declaration_name}
4719 eq $declaration_type) {
4720 # If the existing declaration is empty, or is just a
4721 # forward declaration of a struct, override it.
4722 if ($declaration_type eq 'STRUCT') {
4723 if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4724 if ($is_deprecated) {
4725 $Deprecated{$declaration_name} = "";
4727 $Declarations{$declaration_name} = $declaration;
4728 } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4729 # Ignore an empty or forward declaration.
4731 &LogWarning ($file, $., "Structure $declaration_name has multiple definitions.");
4734 # set flag in %DeclarationConditional hash for
4735 # multiply defined macros/typedefs.
4736 $DeclarationConditional{$declaration_name} = 1;
4739 &LogWarning ($file, $., "$declaration_name has multiple definitions.");
4742 if ($is_deprecated) {
4743 $Deprecated{$declaration_name} = "";
4745 $Declarations{$declaration_name} = $declaration;
4746 $DeclarationTypes{$declaration_name} = $declaration_type;
4749 $declaration_type = "";
4760 #############################################################################
4761 # Function : ReadSignalsFile
4762 # Description : This reads in an existing file which contains information on
4763 # all GTK signals. It creates the arrays @SignalNames and
4764 # @SignalPrototypes containing info on the signals. The first
4765 # line of the SignalPrototype is the return type of the signal
4766 # handler. The remaining lines are the parameters passed to it.
4767 # The last parameter, "gpointer user_data" is always the same
4768 # so is not included.
4769 # Arguments : $file - the file containing the signal handler prototype
4771 #############################################################################
4773 sub ReadSignalsFile {
4781 my $signal_prototype;
4783 # Reset the signal info.
4784 @SignalObjects = ();
4786 @SignalReturns = ();
4788 @SignalPrototypes = ();
4793 if (!open (INPUT, $file)) {
4794 warn "Can't open $file - skipping signals\n";
4801 $signal_object = "";
4803 $signal_returns = "";
4804 $signal_prototype = "";
4807 if (m/^<NAME>(.*)<\/NAME>/) {
4809 if ($signal_name =~ m/^(.*)::(.*)$/) {
4810 $signal_object = $1;
4811 ($signal_name = $2) =~ s/_/-/g;
4812 #print "Found signal: $signal_name\n";
4814 &LogWarning ($file, $., "Invalid signal name: $signal_name.");
4816 } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
4817 $signal_returns = $1;
4818 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4820 } elsif (m%^</SIGNAL>%) {
4821 #print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
4822 push (@SignalObjects, $signal_object);
4823 push (@SignalNames, $signal_name);
4824 push (@SignalReturns, $signal_returns);
4825 push (@SignalFlags, $signal_flags);
4826 push (@SignalPrototypes, $signal_prototype);
4829 $signal_prototype .= $_;
4837 #############################################################################
4838 # Function : ReadTemplateFile
4839 # Description : This reads in the manually-edited documentation file
4840 # corresponding to the file currently being created, so we can
4841 # insert the documentation at the appropriate places.
4842 # It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
4843 # is a hash of arrays.
4844 # NOTE: This function is duplicated in gtkdoc-mktmpl (but
4845 # slightly different).
4846 # Arguments : $docsfile - the template file to read in.
4847 # $skip_unused_params - 1 if the unused parameters should be
4849 #############################################################################
4851 sub ReadTemplateFile {
4852 my ($docsfile, $skip_unused_params) = @_;
4854 my $template = "$docsfile.sgml";
4855 if (! -f $template) {
4856 #print "File doesn't exist: $template\n";
4860 # start with empty hashes, we merge the source comment for each file
4866 my $current_type = ""; # Type of symbol being read.
4867 my $current_symbol = ""; # Name of symbol being read.
4868 my $symbol_doc = ""; # Description of symbol being read.
4869 my @params; # Parameter names and descriptions of current
4870 # function/macro/function typedef.
4871 my $current_param = -1; # Index of parameter currently being read.
4872 # Note that the param array contains pairs
4873 # of param name & description.
4874 my $in_unused_params = 0; # True if we are reading in the unused params.
4875 my $in_deprecated = 0;
4877 my $in_stability = 0;
4879 open (DOCS, "$template")
4880 || die "Can't open $template: $!";
4882 @TRACE@("reading template $template");
4885 if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
4888 if ($symbol eq "Title"
4889 || $symbol eq "Short_Description"
4890 || $symbol eq "Long_Description"
4891 || $symbol eq "See_Also"
4892 || $symbol eq "Stability_Level"
4893 || $symbol eq "Include"
4894 || $symbol eq "Image") {
4896 $symbol = $docsfile . ":" . $symbol;
4899 #print "Found symbol: $symbol\n";
4900 # Remember file and line for the symbol
4901 $SymbolSourceFile{$symbol} = $template;
4902 $SymbolSourceLine{$symbol} = $.;
4904 # Store previous symbol, but remove any trailing blank lines.
4905 if ($current_symbol ne "") {
4906 $symbol_doc =~ s/\s+$//;
4907 $SymbolTypes{$current_symbol} = $current_type;
4908 $SymbolDocs{$current_symbol} = $symbol_doc;
4910 # Check that the stability level is valid.
4911 if ($StabilityLevel{$current_symbol}) {
4912 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4915 if ($current_param >= 0) {
4916 $SymbolParams{$current_symbol} = [ @params ];
4918 # Delete any existing params in case we are overriding a
4919 # previously read template.
4920 delete $SymbolParams{$current_symbol};
4923 $current_type = $type;
4924 $current_symbol = $symbol;
4925 $current_param = -1;
4926 $in_unused_params = 0;
4933 } elsif (m/^<!-- # Unused Parameters # -->/) {
4934 #print "DEBUG: Found unused parameters\n";
4935 $in_unused_params = 1;
4938 } elsif ($in_unused_params && $skip_unused_params) {
4939 # When outputting the DocBook we skip unused parameters.
4940 #print "DEBUG: Skipping unused param: $_";
4944 # Check if param found. Need to handle "..." and "format...".
4945 if (s/^\@([\w\.]+):\040?//) {
4946 my $param_name = $1;
4947 my $param_desc = $_;
4948 # Allow variations of 'Returns'
4949 if ($param_name =~ m/^[Rr]eturns?$/) {
4950 $param_name = "Returns";
4952 # Allow varargs variations
4953 if ($param_name =~ m/^.*\.\.\.$/) {
4954 $param_name = "...";
4957 # strip trailing whitespaces and blank lines
4960 @TRACE@("Found param for symbol $current_symbol : '$param_name'= '$_'");
4962 if ($param_name eq "Deprecated") {
4964 $Deprecated{$current_symbol} = $_;
4965 } elsif ($param_name eq "Since") {
4968 $Since{$current_symbol} = $_;
4969 } elsif ($param_name eq "Stability") {
4971 $StabilityLevel{$current_symbol} = $_;
4973 push (@params, $param_name);
4974 push (@params, $param_desc);
4975 $current_param += $PARAM_FIELD_COUNT;
4978 # strip trailing whitespaces and blank lines
4983 if ($in_deprecated) {
4984 $Deprecated{$current_symbol} .= $_;
4985 } elsif ($in_since) {
4986 &LogWarning ($template, $., "multi-line since docs found");
4987 #$Since{$current_symbol} .= $_;
4988 } elsif ($in_stability) {
4989 $StabilityLevel{$current_symbol} .= $_;
4990 } elsif ($current_param >= 0) {
4991 $params[$current_param] .= $_;
5000 # Remember to finish the current symbol doccs.
5001 if ($current_symbol ne "") {
5003 $symbol_doc =~ s/\s+$//;
5004 $SymbolTypes{$current_symbol} = $current_type;
5005 $SymbolDocs{$current_symbol} = $symbol_doc;
5007 # Check that the stability level is valid.
5008 if ($StabilityLevel{$current_symbol}) {
5009 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
5012 if ($current_param >= 0) {
5013 $SymbolParams{$current_symbol} = [ @params ];
5015 # Delete any existing params in case we are overriding a
5016 # previously read template.
5017 delete $SymbolParams{$current_symbol};
5026 #############################################################################
5027 # Function : ReadObjectHierarchy
5028 # Description : This reads in the $MODULE-hierarchy.txt file containing all
5029 # the GtkObject subclasses described in this module (and their
5031 # It places them in the @Objects array, and places their level
5032 # in the object hierarchy in the @ObjectLevels array, at the
5033 # same index. GtkObject, the root object, has a level of 1.
5035 # FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
5036 # as it goes along, this should be split out into a separate
5040 #############################################################################
5042 sub ReadObjectHierarchy {
5046 if (! -f $OBJECT_TREE_FILE) {
5049 if (!open (INPUT, $OBJECT_TREE_FILE)) {
5050 warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
5054 # FIXME: use $OUTPUT_FORMAT
5055 # my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.$OUTPUT_FORMAT";
5056 my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
5057 my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
5059 open (OUTPUT, ">$new_tree_index")
5060 || die "Can't create $new_tree_index: $!";
5062 if ($OUTPUT_FORMAT eq "xml") {
5063 my $tree_header = $doctype_header;
5065 $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
5066 print (OUTPUT "$tree_header");
5068 print (OUTPUT "<screen>\n");
5070 # Only emit objects if they are supposed to be documented, or if
5071 # they have documented children. To implement this, we maintain a
5072 # stack of pending objects which will be emitted if a documented
5074 my @pending_objects = ();
5075 my @pending_levels = ();
5080 my $level = (length($`)) / 2 + 1;
5087 while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
5088 my $pobject = pop(@pending_objects);
5089 my $plevel = pop(@pending_levels);
5092 push (@pending_objects, $object);
5093 push (@pending_levels, $level);
5095 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5096 while ($#pending_levels >= 0) {
5097 $object = shift @pending_objects;
5098 $level = shift @pending_levels;
5099 $xref = &MakeXRef ($object);
5101 print (OUTPUT ' ' x ($level * 4), "$xref\n");
5102 push (@Objects, $object);
5103 push (@ObjectLevels, $level);
5104 $ObjectRoots{$object} = $root;
5108 # LogWarning ($OBJECT_TREE_FILE, $., "unknown type $object");
5112 print (OUTPUT "</screen>\n");
5117 &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
5122 #############################################################################
5123 # Function : ReadInterfaces
5124 # Description : This reads in the $MODULE.interfaces file.
5127 #############################################################################
5129 sub ReadInterfaces {
5132 if (! -f $INTERFACES_FILE) {
5135 if (!open (INPUT, $INTERFACES_FILE)) {
5136 warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
5142 my ($object, @ifaces) = split;
5143 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5144 my @knownIfaces = ();
5146 # filter out private interfaces, but leave foreign interfaces
5147 foreach my $iface (@ifaces) {
5148 if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
5149 push (@knownIfaces, $iface);
5153 $Interfaces{$object} = join(' ', @knownIfaces);
5159 #############################################################################
5160 # Function : ReadPrerequisites
5161 # Description : This reads in the $MODULE.prerequisites file.
5164 #############################################################################
5166 sub ReadPrerequisites {
5167 %Prerequisites = ();
5169 if (! -f $PREREQUISITES_FILE) {
5172 if (!open (INPUT, $PREREQUISITES_FILE)) {
5173 warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
5179 my ($iface, @prereqs) = split;
5180 if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
5181 my @knownPrereqs = ();
5183 # filter out private prerequisites, but leave foreign prerequisites
5184 foreach my $prereq (@prereqs) {
5185 if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
5186 push (@knownPrereqs, $prereq);
5190 $Prerequisites{$iface} = join(' ', @knownPrereqs);
5196 #############################################################################
5197 # Function : ReadArgsFile
5198 # Description : This reads in an existing file which contains information on
5199 # all GTK args. It creates the arrays @ArgObjects, @ArgNames,
5200 # @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
5202 # Arguments : $file - the file containing the arg information.
5203 #############################################################################
5218 # Reset the args info.
5231 if (!open (INPUT, $file)) {
5232 warn "Can't open $file - skipping args\n";
5249 if (m/^<NAME>(.*)<\/NAME>/) {
5251 if ($arg_name =~ m/^(.*)::(.*)$/) {
5253 ($arg_name = $2) =~ s/_/-/g;
5254 #print "Found arg: $arg_name\n";
5256 &LogWarning ($file, $., "Invalid argument name: $arg_name");
5258 } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
5260 } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
5262 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
5264 } elsif (m/^<NICK>(.*)<\/NICK>/) {
5266 } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
5268 if ($arg_blurb eq "(null)") {
5270 &LogWarning ($file, $., "Property ${arg_object}:${arg_name} has no documentation.");
5272 } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
5274 } elsif (m%^</ARG>%) {
5275 #print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
5276 push (@ArgObjects, $arg_object);
5277 push (@ArgNames, $arg_name);
5278 push (@ArgTypes, $arg_type);
5279 push (@ArgRanges, $arg_range);
5280 push (@ArgFlags, $arg_flags);
5281 push (@ArgNicks, $arg_nick);
5282 push (@ArgBlurbs, $arg_blurb);
5283 push (@ArgDefaults, $arg_default);
5292 #############################################################################
5293 # Function : CheckIsObject
5294 # Description : Returns 1 if the given name is a GObject or a subclass.
5295 # It uses the global @Objects array.
5296 # Note that the @Objects array only contains classes in the
5297 # current module and their ancestors - not all GObject classes.
5298 # Arguments : $name - the name to check.
5299 #############################################################################
5303 my $root = $ObjectRoots{$name};
5304 # Let GBoxed pass as an object here to get -struct appended to the id
5305 # and prevent conflicts with sections.
5306 return defined($root) and $root ne 'GEnum' and $root ne 'GFlags';
5310 #############################################################################
5311 # Function : MakeReturnField
5312 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
5313 # Arguments : $str - the string to pad.
5314 #############################################################################
5316 sub MakeReturnField {
5319 return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));
5322 #############################################################################
5323 # Function : GetSymbolSourceFile
5324 # Description : Get the filename where the symbol docs where taken from.
5325 # Arguments : $symbol - the symbol name
5326 #############################################################################
5328 sub GetSymbolSourceFile {
5331 if (defined($SourceSymbolSourceFile{$symbol})) {
5332 return $SourceSymbolSourceFile{$symbol};
5333 } elsif (defined($SymbolSourceFile{$symbol})) {
5334 return $SymbolSourceFile{$symbol};
5340 #############################################################################
5341 # Function : GetSymbolSourceLine
5342 # Description : Get the file line where the symbol docs where taken from.
5343 # Arguments : $symbol - the symbol name
5344 #############################################################################
5346 sub GetSymbolSourceLine {
5349 if (defined($SourceSymbolSourceLine{$symbol})) {
5350 return $SourceSymbolSourceLine{$symbol};
5351 } elsif (defined($SymbolSourceLine{$symbol})) {
5352 return $SymbolSourceLine{$symbol};