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 # http://live.gnome.org/GObjectIntrospection/Annotations
304 my %AnnotationDefinition = (
305 'allow-none' => "NULL is ok, both for passing and for returning.",
306 'array' => "Parameter points to an array of items.",
307 'attribute' => "Free-form custom annotation.",
308 'closure' => "This parameter is a 'user_data', for callbacks; many bindings can pass NULL here.",
309 'default' => "Default parameter value (for in case the <acronym>shadows</acronym>-to function has less parameters).",
310 'element-type' => "Generics and defining elements of containers and arrays.",
311 'error-domains' => "Typed errors. Similar to throws in Java.",
312 'in' => "Parameter for input. Default is <acronym>transfer none</acronym>.",
313 'inout' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
314 'in-out' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
315 'not-error' => "A GError parameter is not to be handled like a normal GError.",
316 'out' => "Parameter for returning results. Default is <acronym>transfer full</acronym>.",
317 'out caller-allocates' => "Out parameter, where caller must allocate storage.",
318 'out callee-allocates' => "Out parameter, where caller must allocate storage.",
319 'transfer container' => "Free data container after the code is done.",
320 'transfer full' => "Free data after the code is done.",
321 'transfer none' => "Don't free data after the code is done.",
322 'scope call' => "The callback is valid only during the call to the method.",
323 'scope async' => "The callback is valid until first called.",
324 'scope notified' => "The callback is valid until the GDestroyNotify argument is called.",
325 'skip' => "Exposed in C code, not necessarily available in other languages.",
326 'type' => "Override the parsed C type with given type."
329 # Create the root DocBook output directory if it doens't exist.
330 if (! -e $SGML_OUTPUT_DIR) {
331 mkdir ("$SGML_OUTPUT_DIR", 0777)
332 || die "Can't create directory: $SGML_OUTPUT_DIR";
335 # Function and other declaration output settings.
336 my $RETURN_TYPE_FIELD_WIDTH = 20;
337 my $SYMBOL_FIELD_WIDTH = 36;
338 my $SIGNAL_FIELD_WIDTH = 16;
339 my $PARAM_FIELD_COUNT = 2;
341 &ReadKnownSymbols ("$ROOT_DIR/$MODULE-sections.txt");
342 &ReadSignalsFile ($SIGNALS_FILE);
343 &ReadArgsFile ($ARGS_FILE);
344 &ReadObjectHierarchy;
348 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-decl.txt", 0);
349 if (-f "$ROOT_DIR/$MODULE-overrides.txt") {
350 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-overrides.txt", 1);
353 for my $dir (@SOURCE_DIRS) {
354 &ReadSourceDocumentation ($dir);
357 my $changed = &OutputSGML ("$ROOT_DIR/$MODULE-sections.txt");
359 # If any of the DocBook SGML files have changed, update the timestamp file (so
360 # it can be used for Makefile dependencies).
361 if ($changed || ! -e "$ROOT_DIR/sgml.stamp") {
363 # try to detect the common prefix
364 # GtkWidget, GTK_WIDGET, gtk_widget -> gtk
365 if ($NAME_SPACE eq "") {
372 foreach my $symbol (keys(%IndexEntriesFull)) {
373 if(($NAME_SPACE eq "") || $symbol =~ /^$NAME_SPACE/i) {
374 if (length($symbol)>$pos) {
375 $letter=substr($symbol,$pos,1);
376 # stop prefix scanning
377 if ($letter eq "_") {
381 # Should we also stop on a uppercase char, if last was lowercase
382 # GtkWidget, if we have the 'W' and had the 't' before
383 # or should we count upper and lowercase, and stop one 2nd uppercase, if we already had a lowercase
384 # GtkWidget, the 'W' would be the 2nd uppercase and with 't','k' we had lowercase chars before
385 # need to recound each time as this is per symbol
386 $prefix{uc($letter)}++;
390 if ($letter ne "" && $letter ne "_") {
393 foreach $letter (keys(%prefix)) {
394 #print "$letter: $prefix{$letter}.\n";
395 if ($prefix{$letter}>$maxsymbols) {
397 $maxsymbols=$prefix{$letter};
400 $ratio = scalar(keys(%IndexEntriesFull)) / $prefix{$maxletter};
401 #print "most symbols start with $maxletter, that is ". (100 * $ratio) ." %\n";
404 $NAME_SPACE .= $maxletter;
411 } while ($ratio > 0.9);
412 #print "most symbols start with $NAME_SPACE\n";
416 &OutputDeprecatedIndex;
418 &OutputAnnotationGlossary;
420 open (TIMESTAMP, ">$ROOT_DIR/sgml.stamp")
421 || die "Can't create $ROOT_DIR/sgml.stamp: $!";
422 print (TIMESTAMP "timestamp");
426 #############################################################################
427 # Function : OutputObjectList
428 # Description : This outputs the alphabetical list of objects, in a columned
430 # FIXME: Currently this also outputs ancestor objects
431 # which may not actually be in this module.
433 #############################################################################
435 sub OutputObjectList {
438 # FIXME: use $OUTPUT_FORMAT
439 # my $old_object_index = "$SGML_OUTPUT_DIR/object_index.$OUTPUT_FORMAT";
440 my $old_object_index = "$SGML_OUTPUT_DIR/object_index.sgml";
441 my $new_object_index = "$SGML_OUTPUT_DIR/object_index.new";
443 open (OUTPUT, ">$new_object_index")
444 || die "Can't create $new_object_index: $!";
446 if ($OUTPUT_FORMAT eq "xml") {
447 my $header = $doctype_header;
449 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE informaltable/;
450 print (OUTPUT "$header");
453 print (OUTPUT <<EOF);
454 <informaltable pgwide="1" frame="none">
455 <tgroup cols="$cols">
456 <colspec colwidth="1*"${empty_element_end}
457 <colspec colwidth="1*"${empty_element_end}
458 <colspec colwidth="1*"${empty_element_end}
464 foreach $object (sort (@Objects)) {
465 my $xref = &MakeXRef ($object);
466 if ($count % $cols == 0) { print (OUTPUT "<row>\n"); }
467 print (OUTPUT "<entry>$xref</entry>\n");
468 if ($count % $cols == ($cols - 1)) { print (OUTPUT "</row>\n"); }
472 # emit an empty row, since empty tables are invalid
473 print (OUTPUT "<row><entry> </entry></row>\n");
476 if ($count % $cols > 0) {
477 print (OUTPUT "</row>\n");
481 print (OUTPUT <<EOF);
482 </tbody></tgroup></informaltable>
486 &UpdateFileIfChanged ($old_object_index, $new_object_index, 0);
490 #############################################################################
491 # Function : OutputSGML
492 # Description : This collects the output for each section of the docs, and
493 # outputs each file when the end of the section is found.
494 # Arguments : $file - the $MODULE-sections.txt file which contains all of
495 # the functions/macros/structs etc. being documented, organised
496 # into sections and subsections.
497 #############################################################################
502 #print "Reading: $file\n";
504 || die "Can't open $file: $!";
507 my $book_bottom = "";
508 my $includes = (defined $DEFAULT_INCLUDES) ? $DEFAULT_INCLUDES : "";
509 my $section_includes = "";
518 my $signals_synop = "";
519 my $signals_desc = "";
521 my $child_args_synop = "";
522 my $style_args_synop = "";
524 my $child_args_desc = "";
525 my $style_args_desc = "";
528 my $implementations = "";
529 my $prerequisites = "";
531 my @file_objects = ();
533 my %symbol_def_line = ();
535 # merge the source docs, in case there are no templates
536 &MergeSourceDocumentation;
542 } elsif (m/^<SECTION>/) {
548 %symbol_def_line = ();
550 } elsif (m/^<SUBSECTION\s*(.*)>/i) {
554 } elsif (m/^<SUBSECTION>/) {
556 } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
558 #print "Section: $title\n";
560 # We don't want warnings if object & class structs aren't used.
561 $DeclarationOutput{$title} = 1;
562 $DeclarationOutput{"${title}Class"} = 1;
563 $DeclarationOutput{"${title}Iface"} = 1;
564 $DeclarationOutput{"${title}Interface"} = 1;
566 } elsif (m/^<FILE>(.*)<\/FILE>/) {
568 if (! defined $templates{$filename}) {
569 if (&ReadTemplateFile ("$TMPL_DIR/$filename", 1)) {
570 &MergeSourceDocumentation;
571 $templates{$filename}=$.;
574 &LogWarning ($file, $., "Double <FILE>$filename</FILE> entry. ".
575 "Previous occurrence on line ".$templates{$filename}.".");
577 if (($title eq "") and (defined $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"})) {
578 $title = $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"};
579 # Remove trailing blanks
583 } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
585 $section_includes = $1;
587 if (defined $DEFAULT_INCLUDES) {
588 &LogWarning ($file, $., "Default <INCLUDE> being overridden by command line option.");
595 } elsif (m/^<\/SECTION>/) {
596 #print "End of section: $title\n";
597 if ($num_symbols > 0) {
599 if ($OUTPUT_FORMAT eq "xml") {
600 $book_bottom .= " <xi:include href=\"xml/$filename.xml\"/>\n";
602 $book_top.="<!ENTITY $section_id SYSTEM \"sgml/$filename.sgml\">\n";
603 $book_bottom .= " &$section_id;\n";
606 if (defined ($SourceSymbolDocs{"$TMPL_DIR/$filename:Include"})) {
607 if ($section_includes) {
608 &LogWarning ($file, $., "Section <INCLUDE> being overridden by inline comments.");
610 $section_includes = $SourceSymbolDocs{"$TMPL_DIR/$filename:Include"};
612 if ($section_includes eq "") {
613 $section_includes = $includes;
616 $signals_synop =~ s/^\n*//g;
617 $signals_synop =~ s/\n+$/\n/g;
618 if ($signals_synop ne '') {
619 $signals_synop = <<EOF;
620 <refsect1 id="$section_id.signals" role="signal_proto">
621 <title role="signal_proto.title">Signals</title>
623 ${signals_synop}</synopsis>
626 $signals_desc =~ s/^\n*//g;
627 $signals_desc =~ s/\n+$/\n/g;
628 $signals_desc =~ s/(\s|\n)+$//ms;
629 $signals_desc = <<EOF;
630 <refsect1 id="$section_id.signal-details" role="signals">
631 <title role="signals.title">Signal Details</title>
637 $args_synop =~ s/^\n*//g;
638 $args_synop =~ s/\n+$/\n/g;
639 if ($args_synop ne '') {
641 <refsect1 id="$section_id.properties" role="properties">
642 <title role="properties.title">Properties</title>
644 ${args_synop}</synopsis>
647 $args_desc =~ s/^\n*//g;
648 $args_desc =~ s/\n+$/\n/g;
649 $args_desc =~ s/(\s|\n)+$//ms;
651 <refsect1 id="$section_id.property-details" role="property_details">
652 <title role="property_details.title">Property Details</title>
658 $child_args_synop =~ s/^\n*//g;
659 $child_args_synop =~ s/\n+$/\n/g;
660 if ($child_args_synop ne '') {
661 $args_synop .= <<EOF;
662 <refsect1 id="$section_id.child-properties" role="child_properties">
663 <title role="child_properties.title">Child Properties</title>
665 ${child_args_synop}</synopsis>
668 $child_args_desc =~ s/^\n*//g;
669 $child_args_desc =~ s/\n+$/\n/g;
670 $child_args_desc =~ s/(\s|\n)+$//ms;
672 <refsect1 id="$section_id.child-property-details" role="child_property_details">
673 <title role="child_property_details.title">Child Property Details</title>
679 $style_args_synop =~ s/^\n*//g;
680 $style_args_synop =~ s/\n+$/\n/g;
681 if ($style_args_synop ne '') {
682 $args_synop .= <<EOF;
683 <refsect1 id="$section_id.style-properties" role="style_properties">
684 <title role="style_properties.title">Style Properties</title>
686 ${style_args_synop}</synopsis>
689 $style_args_desc =~ s/^\n*//g;
690 $style_args_desc =~ s/\n+$/\n/g;
691 $style_args_desc =~ s/(\s|\n)+$//ms;
693 <refsect1 id="$section_id.style-property-details" role="style_properties_details">
694 <title role="style_properties_details.title">Style Property Details</title>
700 $hierarchy =~ s/^\n*//g;
701 $hierarchy =~ s/\n+$/\n/g;
702 $hierarchy =~ s/(\s|\n)+$//ms;
703 if ($hierarchy ne "") {
705 <refsect1 id="$section_id.object-hierarchy" role="object_hierarchy">
706 <title role="object_hierarchy.title">Object Hierarchy</title>
712 $interfaces =~ s/^\n*//g;
713 $interfaces =~ s/\n+$/\n/g;
714 $interfaces =~ s/(\s|\n)+$//ms;
715 if ($interfaces ne "") {
717 <refsect1 id="$section_id.implemented-interfaces" role="impl_interfaces">
718 <title role="impl_interfaces.title">Implemented Interfaces</title>
724 $implementations =~ s/^\n*//g;
725 $implementations =~ s/\n+$/\n/g;
726 $implementations =~ s/(\s|\n)+$//ms;
727 if ($implementations ne "") {
728 $implementations = <<EOF;
729 <refsect1 id="$section_id.implementations" role="implementations">
730 <title role="implementations.title">Known Implementations</title>
736 $prerequisites =~ s/^\n*//g;
737 $prerequisites =~ s/\n+$/\n/g;
738 $prerequisites =~ s/(\s|\n)+$//ms;
739 if ($prerequisites ne "") {
740 $prerequisites = <<EOF;
741 <refsect1 id="$section_id.prerequisites" role="prerequisites">
742 <title role="prerequisites.title">Prerequisites</title>
748 $derived =~ s/^\n*//g;
749 $derived =~ s/\n+$/\n/g;
750 $derived =~ s/(\s|\n)+$//ms;
751 if ($derived ne "") {
753 <refsect1 id="$section_id.derived-interfaces" role="derived_interfaces">
754 <title role="derived_interfaces.title">Known Derived Interfaces</title>
760 $synopsis =~ s/^\n*//g;
761 $synopsis =~ s/\n+$/\n/g;
762 my $file_changed = &OutputSGMLFile ($filename, $title, $section_id,
764 \$synopsis, \$details,
765 \$signals_synop, \$signals_desc,
766 \$args_synop, \$args_desc,
767 \$hierarchy, \$interfaces,
769 \$prerequisites, \$derived,
779 $section_includes = "";
783 $child_args_synop = "";
784 $style_args_synop = "";
786 $child_args_desc = "";
787 $style_args_desc = "";
790 $implementations = "";
794 } elsif (m/^(\S+)/) {
796 #print " Symbol: $symbol\n";
798 # check for duplicate entries
799 if (! defined $symbol_def_line{$symbol}) {
800 my $declaration = $Declarations{$symbol};
801 if (defined ($declaration)) {
802 # We don't want standard macros/functions of GObjects,
803 # or private declarations.
804 if ($subsection ne "Standard" && $subsection ne "Private") {
805 if (&CheckIsObject ($symbol)) {
806 push @file_objects, $symbol;
808 my ($synop, $desc) = &OutputDeclaration ($symbol,
810 my ($sig_synop, $sig_desc) = &GetSignals ($symbol);
811 my ($arg_synop, $child_arg_synop, $style_arg_synop,
812 $arg_desc, $child_arg_desc, $style_arg_desc) = &GetArgs ($symbol);
813 my $hier = &GetHierarchy ($symbol);
814 my $ifaces = &GetInterfaces ($symbol);
815 my $impls = &GetImplementations ($symbol);
816 my $prereqs = &GetPrerequisites ($symbol);
817 my $der = &GetDerived ($symbol);
820 $signals_synop .= $sig_synop;
821 $signals_desc .= $sig_desc;
822 $args_synop .= $arg_synop;
823 $child_args_synop .= $child_arg_synop;
824 $style_args_synop .= $style_arg_synop;
825 $args_desc .= $arg_desc;
826 $child_args_desc .= $child_arg_desc;
827 $style_args_desc .= $style_arg_desc;
829 $interfaces .= $ifaces;
830 $implementations .= $impls;
831 $prerequisites .= $prereqs;
835 # Note that the declaration has been output.
836 $DeclarationOutput{$symbol} = 1;
837 } elsif ($subsection ne "Standard" && $subsection ne "Private") {
838 $UndeclaredSymbols{$symbol} = 1;
839 &LogWarning ($file, $., "No declaration found for $symbol.");
842 $symbol_def_line{$symbol}=$.;
844 if ($section_id eq "") {
845 if($title eq "" && $filename eq "") {
846 &LogWarning ($file, $., "Section has no title and no file.");
848 # FIXME: one of those would be enough
849 # filename should be an internal detail for gtk-doc
852 } elsif ($filename eq "") {
855 $filename =~ s/\s/_/g;
857 $section_id = $SourceSymbolDocs{"$TMPL_DIR/$filename:Section_Id"};
858 if (defined ($section_id) && $section_id !~ m/^\s*$/) {
859 # Remove trailing blanks and use as is
860 $section_id =~ s/\s+$//;
861 } elsif (&CheckIsObject ($title)) {
862 # GObjects use their class name as the ID.
863 $section_id = &CreateValidSGMLID ($title);
865 $section_id = &CreateValidSGMLID ("$MODULE-$title");
868 $SymbolSection{$symbol}=$title;
869 $SymbolSectionId{$symbol}=$section_id;
872 &LogWarning ($file, $., "Double symbol entry for $symbol. ".
873 "Previous occurrence on line ".$symbol_def_line{$symbol}.".");
879 &OutputMissingDocumentation;
880 &OutputUndeclaredSymbols;
881 &OutputUnusedSymbols;
883 if ($OUTPUT_ALL_SYMBOLS) {
886 if ($OUTPUT_SYMBOLS_WITHOUT_SINCE) {
887 &OutputSymbolsWithoutSince;
890 for $filename (split (' ', $EXPAND_CONTENT_FILES)) {
891 my $file_changed = &OutputExtraFile ($filename);
897 &OutputBook ($book_top, $book_bottom);
902 #############################################################################
903 # Function : OutputIndex
904 # Description : This writes an indexlist that can be included into the main-
905 # document into an <index> tag.
906 #############################################################################
909 my ($basename, $apiindexref ) = @_;
910 my %apiindex = %{$apiindexref};
911 my $old_index = "$SGML_OUTPUT_DIR/$basename.xml";
912 my $new_index = "$SGML_OUTPUT_DIR/$basename.new";
913 my $lastletter = " ";
918 open (OUTPUT, ">$new_index")
919 || die "Can't create $new_index";
921 my $header = $doctype_header;
922 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE indexdiv/;
924 print (OUTPUT "$header<indexdiv>\n");
926 #print "generate $basename index (".%apiindex." entries)\n";
928 # do a case insensitive sort while chopping off the prefix
930 sort { $$a{criteria} cmp $$b{criteria} }
931 map { my $x = uc($_); $x =~ s/^$NAME_SPACE\_?(.*)/$1/i; { criteria => $x, original => $_, short => $1 } }
934 $symbol = $$hash{original};
935 if (defined($$hash{short})) {
936 $short_symbol = $$hash{short};
938 $short_symbol = $symbol;
941 # generate a short symbol description
942 my $symbol_desc = "";
943 my $symbol_section = "";
944 my $symbol_section_id = "";
945 my $symbol_type = "";
946 if (defined($DeclarationTypes{$symbol})) {
947 $symbol_type = lc($DeclarationTypes{$symbol});
949 if ($symbol_type eq "") {
950 #print "trying symbol $symbol\n";
951 if ($symbol =~ m/(.*)::(.*)/) {
955 #print " trying object signal ${oname}:$osym in ".$#SignalNames." signals\n";
956 for ($i = 0; $i <= $#SignalNames; $i++) {
957 if ($SignalNames[$i] eq $osym) {
958 $symbol_type = "object signal";
959 if (defined($SymbolSection{$oname})) {
960 $symbol_section = $SymbolSection{$oname};
961 $symbol_section_id = $SymbolSectionId{$oname};
966 } elsif ($symbol =~ m/(.*):(.*)/) {
970 #print " trying object property ${oname}::$osym in ".$#ArgNames." properties\n";
971 for ($i = 0; $i <= $#ArgNames; $i++) {
972 #print " ".$ArgNames[$i]."\n";
973 if ($ArgNames[$i] eq $osym) {
974 $symbol_type = "object property";
975 if (defined($SymbolSection{$oname})) {
976 $symbol_section = $SymbolSection{$oname};
977 $symbol_section_id = $SymbolSectionId{$oname};
984 if (defined($SymbolSection{$symbol})) {
985 $symbol_section = $SymbolSection{$symbol};
986 $symbol_section_id = $SymbolSectionId{$symbol};
989 if ($symbol_type ne "") {
990 $symbol_desc=", $symbol_type";
991 if ($symbol_section ne "") {
992 $symbol_desc.=" in <link linkend=\"$symbol_section_id\">$symbol_section</link>";
993 #$symbol_desc.=" in ". &ExpandAbbreviations($symbol, "#$symbol_section");
997 my $curletter = uc(substr($short_symbol,0,1));
998 my $id = $apiindex{$symbol};
1000 #print " add symbol $symbol with $id to index in section $curletter\n";
1002 if ($curletter ne $lastletter) {
1003 $lastletter = $curletter;
1005 if ($divopen == 1) {
1006 print (OUTPUT "</indexdiv>\n");
1008 print (OUTPUT "<indexdiv><title>$curletter</title>\n");
1012 print (OUTPUT <<EOF);
1013 <indexentry><primaryie linkends="$id"><link linkend="$id">$symbol</link>$symbol_desc</primaryie></indexentry>
1017 if ($divopen == 1) {
1018 print (OUTPUT "</indexdiv>\n");
1020 print (OUTPUT "</indexdiv>\n");
1023 &UpdateFileIfChanged ($old_index, $new_index, 0);
1027 #############################################################################
1028 # Function : OutputIndexFull
1029 # Description : This writes the full api indexlist that can be included into the
1030 # main document into an <index> tag.
1031 #############################################################################
1033 sub OutputIndexFull {
1034 &OutputIndex ("api-index-full", \%IndexEntriesFull);
1038 #############################################################################
1039 # Function : OutputDeprecatedIndex
1040 # Description : This writes the deprecated api indexlist that can be included
1041 # into the main document into an <index> tag.
1042 #############################################################################
1044 sub OutputDeprecatedIndex {
1045 &OutputIndex ("api-index-deprecated", \%IndexEntriesDeprecated);
1049 #############################################################################
1050 # Function : OutputSinceIndexes
1051 # Description : This writes the 'since' api indexlists that can be included into
1052 # the main document into an <index> tag.
1053 #############################################################################
1055 sub OutputSinceIndexes {
1056 my @sinces = keys %{{ map { $_ => 1 } values %Since }};
1058 foreach my $version (@sinces) {
1059 #print "Since : [$version]\n";
1060 # TODO make filtered hash
1061 #my %index = grep { $Since{$_} eq $version } %IndexEntriesSince;
1062 my %index = map { $_ => $IndexEntriesSince{$_} } grep { $Since{$_} eq $version } keys %IndexEntriesSince;
1064 &OutputIndex ("api-index-$version", \%index);
1068 #############################################################################
1069 # Function : OutputAnnotationGlossary
1070 # Description : This writes a glossary of the used annotation terms into a
1071 # separate glossary file that can be included into the main
1073 #############################################################################
1075 sub OutputAnnotationGlossary {
1076 my $old_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.xml";
1077 my $new_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.new";
1078 my $lastletter = " ";
1081 # if there are no annotations used return
1082 return if (! keys(%AnnotationsUsed));
1084 # add acronyms that are referenced from acronym text
1086 foreach my $annotation (keys(%AnnotationsUsed)) {
1087 if(defined($AnnotationDefinition{$annotation})) {
1088 if($AnnotationDefinition{$annotation} =~ m/<acronym>([\w ]+)<\/acronym>/) {
1089 if (!exists($AnnotationsUsed{$1})) {
1090 $AnnotationsUsed{$1} = 1;
1097 open (OUTPUT, ">$new_glossary")
1098 || die "Can't create $new_glossary";
1100 my $header = $doctype_header;
1101 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE glossary/;
1103 print (OUTPUT <<EOF);
1105 <glossary id="annotation-glossary">
1106 <title>Annotation Glossary</title>
1109 foreach my $annotation (keys(%AnnotationsUsed)) {
1110 if(defined($AnnotationDefinition{$annotation})) {
1111 my $def = $AnnotationDefinition{$annotation};
1112 my $curletter = uc(substr($annotation,0,1));
1114 if ($curletter ne $lastletter) {
1115 $lastletter = $curletter;
1117 if ($divopen == 1) {
1118 print (OUTPUT "</glossdiv>\n");
1120 print (OUTPUT "<glossdiv><title>$curletter</title>\n");
1123 print (OUTPUT <<EOF);
1125 <glossterm><anchor id="annotation-glossterm-$annotation"/>$annotation</glossterm>
1134 if ($divopen == 1) {
1135 print (OUTPUT "</glossdiv>\n");
1137 print (OUTPUT "</glossary>\n");
1140 &UpdateFileIfChanged ($old_glossary, $new_glossary, 0);
1143 #############################################################################
1144 # Function : ReadKnownSymbols
1145 # Description : This collects the names of non-private symbols from the
1146 # $MODULE-sections.txt file.
1147 # Arguments : $file - the $MODULE-sections.txt file which contains all of
1148 # the functions/macros/structs etc. being documented, organised
1149 # into sections and subsections.
1150 #############################################################################
1152 sub ReadKnownSymbols {
1155 my $subsection = "";
1157 #print "Reading: $file\n";
1159 || die "Can't open $file: $!";
1165 } elsif (m/^<SECTION>/) {
1168 } elsif (m/^<SUBSECTION\s*(.*)>/i) {
1171 } elsif (m/^<SUBSECTION>/) {
1174 } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
1177 } elsif (m/^<FILE>(.*)<\/FILE>/) {
1178 $KnownSymbols{"$TMPL_DIR/$1:Long_Description"} = 1;
1179 $KnownSymbols{"$TMPL_DIR/$1:Short_Description"} = 1;
1182 } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
1185 } elsif (m/^<\/SECTION>/) {
1188 } elsif (m/^(\S+)/) {
1191 if ($subsection ne "Standard" && $subsection ne "Private") {
1192 $KnownSymbols{$symbol} = 1;
1195 $KnownSymbols{$symbol} = 0;
1203 #############################################################################
1204 # Function : OutputDeclaration
1205 # Description : Returns the synopsis and detailed description DocBook
1206 # describing one function/macro etc.
1207 # Arguments : $symbol - the name of the function/macro begin described.
1208 # $declaration - the declaration of the function/macro.
1209 #############################################################################
1211 sub OutputDeclaration {
1212 my ($symbol, $declaration) = @_;
1214 my $type = $DeclarationTypes {$symbol};
1215 if ($type eq 'MACRO') {
1216 return &OutputMacro ($symbol, $declaration);
1217 } elsif ($type eq 'TYPEDEF') {
1218 return &OutputTypedef ($symbol, $declaration);
1219 } elsif ($type eq 'STRUCT') {
1220 return &OutputStruct ($symbol, $declaration);
1221 } elsif ($type eq 'ENUM') {
1222 return &OutputEnum ($symbol, $declaration);
1223 } elsif ($type eq 'UNION') {
1224 return &OutputUnion ($symbol, $declaration);
1225 } elsif ($type eq 'VARIABLE') {
1226 return &OutputVariable ($symbol, $declaration);
1227 } elsif ($type eq 'FUNCTION') {
1228 return &OutputFunction ($symbol, $declaration, $type);
1229 } elsif ($type eq 'USER_FUNCTION') {
1230 return &OutputFunction ($symbol, $declaration, $type);
1232 die "Unknown symbol type";
1237 #############################################################################
1238 # Function : OutputSymbolTraits
1239 # Description : Returns the Since and StabilityLevel paragraphs for a symbol.
1240 # Arguments : $symbol - the name of the function/macro begin described.
1241 #############################################################################
1243 sub OutputSymbolTraits {
1247 if (exists $Since{$symbol}) {
1248 $desc .= "<para role=\"since\">Since $Since{$symbol}</para>";
1250 if (exists $StabilityLevel{$symbol}) {
1251 $desc .= "<para role=\"stability\">Stability Level: $StabilityLevel{$symbol}</para>";
1256 #############################################################################
1257 # Function : Outpu{Symbol,Section}ExtraLinks
1258 # Description : Returns extralinks for the symbol (if enabled).
1259 # Arguments : $symbol - the name of the function/macro begin described.
1260 #############################################################################
1264 return undef unless defined $text;
1266 # Build a char to hex map
1269 $escapes{chr($_)} = sprintf("%%%02X", $_);
1272 # Default unsafe characters. RFC 2732 ^(uric - reserved)
1273 $text =~ s/([^A-Za-z0-9\-_.!~*'()])/$escapes{$1}/g;
1278 sub OutputSymbolExtraLinks {
1282 if (0) { # NEW FEATURE: needs configurability
1283 my $sstr = &uri_escape($symbol);
1284 my $mstr = &uri_escape($MODULE);
1286 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1287 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&symbol=$sstr">edit documentation</ulink>
1293 sub OutputSectionExtraLinks {
1294 my ($symbol,$docsymbol) = @_;
1297 if (0) { # NEW FEATURE: needs configurability
1298 my $sstr = &uri_escape($symbol);
1299 my $mstr = &uri_escape($MODULE);
1300 my $dsstr = &uri_escape($docsymbol);
1302 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1303 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&symbol=$dsstr">edit documentation</ulink>
1310 #############################################################################
1311 # Function : OutputMacro
1312 # Description : Returns the synopsis and detailed description of a macro.
1313 # Arguments : $symbol - the macro.
1314 # $declaration - the declaration of the macro.
1315 #############################################################################
1318 my ($symbol, $declaration) = @_;
1319 my $id = &CreateValidSGMLID ($symbol);
1320 my $condition = &MakeConditionDescription ($symbol);
1321 my $synop = &MakeReturnField("#define") . "<link linkend=\"$id\">$symbol</link>";
1324 my @fields = ParseMacroDeclaration($declaration, \&CreateValidSGML);
1325 my $title = $symbol . (@fields ? "()" : "");
1327 $desc = "<refsect2 id=\"$id\" role=\"macro\"$condition>\n<title>$title</title>\n";
1328 $desc .= MakeIndexterms($symbol, $id);
1330 $desc .= OutputSymbolExtraLinks($symbol);
1333 if (length ($symbol) < $SYMBOL_FIELD_WIDTH) {
1334 $synop .= (' ' x ($SYMBOL_FIELD_WIDTH - length ($symbol)));
1338 for (my $i = 1; $i <= $#fields; $i += 2) {
1339 my $field_name = $fields[$i];
1342 $synop .= "$field_name";
1345 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1353 # Don't output the macro definition if is is a conditional macro or it
1354 # looks like a function, i.e. starts with "g_" or "_?gnome_", or it is
1355 # longer than 2 lines, otherwise we get lots of complicated macros like
1357 if (!defined ($DeclarationConditional{$symbol}) && ($symbol !~ m/^g_/)
1358 && ($symbol !~ m/^_?gnome_/) && (($declaration =~ tr/\n//) < 2)) {
1359 my $decl_out = &CreateValidSGML ($declaration);
1360 $desc .= "<programlisting>$decl_out</programlisting>\n";
1362 $desc .= "<programlisting>" . &MakeReturnField("#define") . "$symbol";
1363 if ($declaration =~ m/^\s*#\s*define\s+\w+(\([^\)]*\))/) {
1365 my $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH - length ("#define "));
1366 # Align each line so that if should all line up OK.
1367 $args =~ s/\n/\n$pad/gm;
1368 $desc .= &CreateValidSGML ($args);
1370 $desc .= "</programlisting>\n";
1373 $desc .= &MakeDeprecationNote($symbol);
1375 my $parameters = &OutputParamDescriptions ("MACRO", $symbol, @fields);
1376 my $parameters_output = 0;
1378 if (defined ($SymbolDocs{$symbol})) {
1379 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1381 # Try to insert the parameter table at the author's desired position.
1382 # Otherwise we need to tag it onto the end.
1383 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1384 $parameters_output = 1;
1386 $desc .= $symbol_docs;
1389 if ($parameters_output == 0) {
1390 $desc .= $parameters;
1393 $desc .= OutputSymbolTraits ($symbol);
1394 $desc .= "</refsect2>\n";
1395 return ($synop, $desc);
1399 #############################################################################
1400 # Function : OutputTypedef
1401 # Description : Returns the synopsis and detailed description of a typedef.
1402 # Arguments : $symbol - the typedef.
1403 # $declaration - the declaration of the typedef,
1404 # e.g. 'typedef unsigned int guint;'
1405 #############################################################################
1408 my ($symbol, $declaration) = @_;
1409 my $id = &CreateValidSGMLID ($symbol);
1410 my $condition = &MakeConditionDescription ($symbol);
1411 my $synop = &MakeReturnField("typedef") . "<link linkend=\"$id\">$symbol</link>;\n";
1412 my $desc = "<refsect2 id=\"$id\" role=\"typedef\"$condition>\n<title>$symbol</title>\n";
1414 $desc .= MakeIndexterms($symbol, $id);
1416 $desc .= OutputSymbolExtraLinks($symbol);
1418 if (!defined ($DeclarationConditional{$symbol})) {
1419 my $decl_out = &CreateValidSGML ($declaration);
1420 $desc .= "<programlisting>$decl_out</programlisting>\n";
1423 $desc .= &MakeDeprecationNote($symbol);
1425 if (defined ($SymbolDocs{$symbol})) {
1426 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1428 $desc .= OutputSymbolTraits ($symbol);
1429 $desc .= "</refsect2>\n";
1430 return ($synop, $desc);
1434 #############################################################################
1435 # Function : OutputStruct
1436 # Description : Returns the synopsis and detailed description of a struct.
1437 # We check if it is a object struct, and if so we only output
1438 # parts of it that are noted as public fields.
1439 # We also use a different SGML ID for object structs, since the
1440 # original ID is used for the entire RefEntry.
1441 # Arguments : $symbol - the struct.
1442 # $declaration - the declaration of the struct.
1443 #############################################################################
1446 my ($symbol, $declaration) = @_;
1449 my $default_to_public = 1;
1450 if (&CheckIsObject ($symbol)) {
1451 #print "Found struct gtype: $symbol\n";
1453 $default_to_public = $ObjectRoots{$symbol} eq 'GBoxed';
1459 $id = &CreateValidSGMLID ($symbol . "_struct");
1460 $condition = &MakeConditionDescription ($symbol . "_struct");
1462 $id = &CreateValidSGMLID ($symbol);
1463 $condition = &MakeConditionDescription ($symbol);
1466 # Determine if it is a simple struct or it also has a typedef.
1467 my $has_typedef = 0;
1468 if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1475 # For structs with typedefs we just output the struct name.
1476 $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1477 $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>$symbol</title>\n";
1479 $synop = &MakeReturnField("struct") . "<link linkend=\"$id\">$symbol</link>;\n";
1480 $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>struct $symbol</title>\n";
1483 $desc .= MakeIndexterms($symbol, $id);
1485 $desc .= OutputSymbolExtraLinks($symbol);
1487 # Form a pretty-printed, private-data-removed form of the declaration
1490 if ($declaration =~ m/^\s*$/) {
1491 #print "Found opaque struct: $symbol\n";
1492 $decl_out = "typedef struct _$symbol $symbol;";
1493 } elsif ($declaration =~ m/^\s*struct\s+\w+\s*;\s*$/) {
1494 #print "Found opaque struct: $symbol\n";
1495 $decl_out = "struct $symbol;";
1497 my $public = $default_to_public;
1498 my $new_declaration = "";
1500 my $decl = $declaration;
1502 if ($decl =~ m/^\s*(typedef\s+)?struct\s*\w*\s*(?:\/\*.*\*\/)?\s*{(.*)}\s*\w*\s*;\s*$/s) {
1503 my $struct_contents = $2;
1505 foreach $decl_line (split (/\n/, $struct_contents)) {
1506 #print "Struct line: $decl_line\n";
1507 if ($decl_line =~ m%/\*\s*<\s*public\s*>\s*\*/%) {
1509 } elsif ($decl_line =~ m%/\*\s*<\s*(private|protected)\s*>\s*\*/%) {
1512 $new_declaration .= $decl_line . "\n";
1516 if ($new_declaration) {
1517 # Strip any blank lines off the ends.
1518 $new_declaration =~ s/^\s*\n//;
1519 $new_declaration =~ s/\n\s*$/\n/;
1522 $decl_out = "typedef struct {\n" . $new_declaration
1525 $decl_out = "struct $symbol {\n" . $new_declaration
1530 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1531 "Couldn't parse struct:\n$declaration");
1534 # If we couldn't parse the struct or it was all private, output an
1535 # empty struct declaration.
1536 if ($decl_out eq "") {
1538 $decl_out = "typedef struct _$symbol $symbol;";
1540 $decl_out = "struct $symbol;";
1545 $decl_out = &CreateValidSGML ($decl_out);
1546 $desc .= "<programlisting>$decl_out</programlisting>\n";
1548 $desc .= &MakeDeprecationNote($symbol);
1550 if (defined ($SymbolDocs{$symbol})) {
1551 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1554 # Create a table of fields and descriptions
1556 # FIXME: Inserting  's into the produced type declarations here would
1557 # improve the output in most situations ... except for function
1558 # members of structs!
1559 my @fields = ParseStructDeclaration($declaration, !$default_to_public,
1562 "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1564 my $params = $SymbolParams{$symbol};
1566 # If no parameters are filled in, we don't generate the description
1567 # table, for backwards compatibility.
1570 if (defined $params) {
1571 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1572 if ($params->[$i] =~ /\S/) {
1580 my %field_descrs = @$params;
1581 my $missing_parameters = "";
1582 my $unused_parameters = "";
1584 $desc .= "<variablelist role=\"struct\">\n";
1586 my $field_name = shift @fields;
1587 my $text = shift @fields;
1588 my $field_descr = $field_descrs{$field_name};
1589 my $param_annotations = "";
1591 $desc .= "<varlistentry><term>$text</term>\n";
1592 if (defined $field_descr) {
1593 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1594 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1595 $field_descr .= $param_annotations;
1597 $field_descr =~ s/^(\s|\n)+//msg;
1598 $field_descr =~ s/(\s|\n)+$//msg;
1599 $desc .= "<listitem><simpara>$field_descr</simpara></listitem>\n";
1600 delete $field_descrs{$field_name};
1602 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1603 "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1604 if ($missing_parameters ne "") {
1605 $missing_parameters .= ", ".$field_name;
1607 $missing_parameters = $field_name;
1609 $desc .= "<listitem />\n";
1611 $desc .= "</varlistentry>\n";
1613 $desc .= "</variablelist>";
1614 foreach my $field_name (keys %field_descrs) {
1615 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1616 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1617 if ($unused_parameters ne "") {
1618 $unused_parameters .= ", ".$field_name;
1620 $unused_parameters = $field_name;
1624 # remember missing/unused parameters (needed in tmpl-free build)
1625 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1626 $AllIncompleteSymbols{$symbol}=$missing_parameters;
1628 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1629 $AllUnusedSymbols{$symbol}=$unused_parameters;
1633 if (scalar(@fields) > 0) {
1634 if (! exists ($AllIncompleteSymbols{$symbol})) {
1635 $AllIncompleteSymbols{$symbol}="<items>";
1636 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1637 "Field descriptions for struct $symbol are missing in source code comment block.");
1638 @TRACE@("Remaining structs fields: ".@fields.":".join(',',@fields)."\n");
1643 $desc .= OutputSymbolTraits ($symbol);
1644 $desc .= "</refsect2>\n";
1645 return ($synop, $desc);
1649 #############################################################################
1650 # Function : OutputUnion
1651 # Description : Returns the synopsis and detailed description of a union.
1652 # Arguments : $symbol - the union.
1653 # $declaration - the declaration of the union.
1654 #############################################################################
1657 my ($symbol, $declaration) = @_;
1658 my $id = &CreateValidSGMLID ($symbol);
1659 my $condition = &MakeConditionDescription ($symbol);
1661 # Determine if it is a simple struct or it also has a typedef.
1662 my $has_typedef = 0;
1663 if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1670 # For unions with typedefs we just output the union name.
1671 $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1672 $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>$symbol</title>\n";
1674 $synop = &MakeReturnField("union") . "<link linkend=\"$id\">$symbol</link>;\n";
1675 $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>union $symbol</title>\n";
1678 $desc .= MakeIndexterms($symbol, $id);
1680 $desc .= OutputSymbolExtraLinks($symbol);
1682 # FIXME: we do more for structs
1683 my $decl_out = &CreateValidSGML ($declaration);
1684 $desc .= "<programlisting>$decl_out</programlisting>\n";
1686 $desc .= &MakeDeprecationNote($symbol);
1688 if (defined ($SymbolDocs{$symbol})) {
1689 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1692 # Create a table of fields and descriptions
1694 # FIXME: Inserting  's into the produced type declarations here would
1695 # improve the output in most situations ... except for function
1696 # members of structs!
1697 my @fields = ParseStructDeclaration($declaration, 0,
1700 "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1702 my $params = $SymbolParams{$symbol};
1704 # If no parameters are filled in, we don't generate the description
1705 # table, for backwards compatibility
1708 if (defined $params) {
1709 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1710 if ($params->[$i] =~ /\S/) {
1718 my %field_descrs = @$params;
1719 my $missing_parameters = "";
1720 my $unused_parameters = "";
1722 $desc .= "<variablelist role=\"union\">\n";
1724 my $field_name = shift @fields;
1725 my $text = shift @fields;
1726 my $field_descr = $field_descrs{$field_name};
1727 my $param_annotations = "";
1729 $desc .= "<varlistentry><term>$text</term>\n";
1730 if (defined $field_descr) {
1731 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1732 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1733 $field_descr .= $param_annotations;
1735 $field_descr =~ s/^(\s|\n)+//msg;
1736 $field_descr =~ s/(\s|\n)+$//msg;
1737 $desc .= "<listitem><simpara>$field_descr</simpara></listitem>\n";
1738 delete $field_descrs{$field_name};
1740 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1741 "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1742 if ($missing_parameters ne "") {
1743 $missing_parameters .= ", ".$field_name;
1745 $missing_parameters = $field_name;
1747 $desc .= "<listitem />\n";
1749 $desc .= "</varlistentry>\n";
1751 $desc .= "</variablelist>";
1752 foreach my $field_name (keys %field_descrs) {
1753 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1754 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1755 if ($unused_parameters ne "") {
1756 $unused_parameters .= ", ".$field_name;
1758 $unused_parameters = $field_name;
1762 # remember missing/unused parameters (needed in tmpl-free build)
1763 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1764 $AllIncompleteSymbols{$symbol}=$missing_parameters;
1766 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1767 $AllUnusedSymbols{$symbol}=$unused_parameters;
1771 if (scalar(@fields) > 0) {
1772 if (! exists ($AllIncompleteSymbols{$symbol})) {
1773 $AllIncompleteSymbols{$symbol}="<items>";
1774 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1775 "Field descriptions for union $symbol are missing in source code comment block.");
1776 @TRACE@("Remaining union fields: ".@fields.":".join(',',@fields)."\n");
1781 $desc .= OutputSymbolTraits ($symbol);
1782 $desc .= "</refsect2>\n";
1783 return ($synop, $desc);
1787 #############################################################################
1788 # Function : OutputEnum
1789 # Description : Returns the synopsis and detailed description of a enum.
1790 # Arguments : $symbol - the enum.
1791 # $declaration - the declaration of the enum.
1792 #############################################################################
1795 my ($symbol, $declaration) = @_;
1798 if (&CheckIsObject ($symbol)) {
1799 #print "Found enum gtype: $symbol\n";
1806 $id = &CreateValidSGMLID ($symbol . "_enum");
1807 $condition = &MakeConditionDescription ($symbol . "_enum");
1809 $id = &CreateValidSGMLID ($symbol);
1810 $condition = &MakeConditionDescription ($symbol);
1813 my $synop = &MakeReturnField("enum") . "<link linkend=\"$id\">$symbol</link>;\n";
1814 my $desc = "<refsect2 id=\"$id\" role=\"enum\"$condition>\n<title>enum $symbol</title>\n";
1816 $desc .= MakeIndexterms($symbol, $id);
1818 $desc .= OutputSymbolExtraLinks($symbol);
1822 my $new_declaration = "";
1824 my $decl = $declaration;
1826 if ($decl =~ m/^\s*(typedef\s+)?enum\s*\w*\s*(?:\/\*.*\*\/)?\s*{(.*)}\s*\w*\s*;\s*$/s) {
1827 my $has_typedef = defined($1) ? 1 : 0;
1828 my $enum_contents = $2;
1830 foreach $decl_line (split (/\n/, $enum_contents)) {
1831 #print "Enum line: $decl_line\n";
1832 if ($decl_line =~ m%/\*\s*<\s*public\s*>\s*\*/%) {
1834 } elsif ($decl_line =~ m%/\*\s*<\s*(private|protected)\s*>\s*\*/%) {
1837 $new_declaration .= $decl_line . "\n";
1841 if ($new_declaration) {
1842 # Strip any blank lines off the ends.
1843 $new_declaration =~ s/^\s*\n//;
1844 $new_declaration =~ s/\n\s*$/\n/;
1847 $decl_out = "typedef enum {\n" . $new_declaration
1850 $decl_out = "enum $symbol {\n" . $new_declaration
1856 $decl_out = &CreateValidSGML ($decl_out);
1857 $desc .= "<programlisting>$decl_out</programlisting>\n";
1859 $desc .= &MakeDeprecationNote($symbol);
1861 if (defined ($SymbolDocs{$symbol})) {
1862 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1865 # Create a table of fields and descriptions
1867 my @fields = ParseEnumDeclaration($declaration);
1868 my $params = $SymbolParams{$symbol};
1870 # If no parameters are filled in, we don't generate the description
1871 # table, for backwards compatibility
1874 if (defined $params) {
1875 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1876 if ($params->[$i] =~ /\S/) {
1884 my %field_descrs = @$params;
1885 my $missing_parameters = "";
1886 my $unused_parameters = "";
1888 $desc .= "<variablelist role=\"enum\">\n";
1889 for my $field_name (@fields) {
1890 my $field_descr = $field_descrs{$field_name};
1891 my $param_annotations = "";
1893 $id = &CreateValidSGMLID ($field_name);
1894 $condition = &MakeConditionDescription ($field_name);
1895 $desc .= "<varlistentry id=\"$id\" role=\"constant\"$condition>\n<term><literal>$field_name</literal></term>\n";
1896 if (defined $field_descr) {
1897 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1898 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1899 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1900 delete $field_descrs{$field_name};
1902 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1903 "Value description for $symbol"."::"."$field_name is missing in source code comment block.");
1904 if ($missing_parameters ne "") {
1905 $missing_parameters .= ", ".$field_name;
1907 $missing_parameters = $field_name;
1909 $desc .= "<listitem />\n";
1911 $desc .= "</varlistentry>\n";
1913 $desc .= "</variablelist>";
1914 foreach my $field_name (keys %field_descrs) {
1915 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1916 "Value description for $symbol"."::"."$field_name is not used from source code comment block.");
1917 if ($unused_parameters ne "") {
1918 $unused_parameters .= ", ".$field_name;
1920 $unused_parameters = $field_name;
1924 # remember missing/unused parameters (needed in tmpl-free build)
1925 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1926 $AllIncompleteSymbols{$symbol}=$missing_parameters;
1928 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1929 $AllUnusedSymbols{$symbol}=$unused_parameters;
1933 if (scalar(@fields) > 0) {
1934 if (! exists ($AllIncompleteSymbols{$symbol})) {
1935 $AllIncompleteSymbols{$symbol}="<items>";
1936 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1937 "Value descriptions for $symbol are missing in source code comment block.");
1942 $desc .= OutputSymbolTraits ($symbol);
1943 $desc .= "</refsect2>\n";
1944 return ($synop, $desc);
1948 #############################################################################
1949 # Function : OutputVariable
1950 # Description : Returns the synopsis and detailed description of a variable.
1951 # Arguments : $symbol - the extern'ed variable.
1952 # $declaration - the declaration of the variable.
1953 #############################################################################
1955 sub OutputVariable {
1956 my ($symbol, $declaration) = @_;
1957 my $id = &CreateValidSGMLID ($symbol);
1958 my $condition = &MakeConditionDescription ($symbol);
1960 @TRACE@("ouputing variable: '$symbol' '$declaration'");
1963 if ($declaration =~ m/^\s*extern\s+((const\s+|signed\s+|unsigned\s+|long\s+|short\s+)*\w+)(\s+\*+|\*+|\s)(\s*)(const\s+)*([A-Za-z]\w*)\s*;/) {
1964 my $mod1 = defined ($1) ? $1 : "";
1965 my $ptr = defined ($3) ? $3 : "";
1966 my $space = defined ($4) ? $4 : "";
1967 my $mod2 = defined ($5) ? $5 : "";
1968 $synop = &MakeReturnField("extern $mod1$ptr$space$mod2") . "<link linkend=\"$id\">$symbol</link>;\n";
1969 } elsif ($declaration =~ m/^\s*((const\s+|signed\s+|unsigned\s+|long\s+|short\s+)*\w+)(\s+\*+|\*+|\s)(\s*)(const\s+)*([A-Za-z]\w*)\s*=/) {
1970 my $mod1 = defined ($1) ? $1 : "";
1971 my $ptr = defined ($3) ? $3 : "";
1972 my $space = defined ($4) ? $4 : "";
1973 my $mod2 = defined ($5) ? $5 : "";
1974 $synop = &MakeReturnField("$mod1$ptr$space$mod2") . "<link linkend=\"$id\">$symbol</link>;\n";
1977 $synop = &MakeReturnField("extern") . "<link linkend=\"$id\">$symbol</link>;\n";
1980 my $desc = "<refsect2 id=\"$id\" role=\"variable\"$condition>\n<title>$symbol</title>\n";
1982 $desc .= MakeIndexterms($symbol, $id);
1984 $desc .= OutputSymbolExtraLinks($symbol);
1986 my $decl_out = &CreateValidSGML ($declaration);
1987 $desc .= "<programlisting>$decl_out</programlisting>\n";
1989 $desc .= &MakeDeprecationNote($symbol);
1991 if (defined ($SymbolDocs{$symbol})) {
1992 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1994 $desc .= OutputSymbolTraits ($symbol);
1995 $desc .= "</refsect2>\n";
1996 return ($synop, $desc);
2000 #############################################################################
2001 # Function : OutputFunction
2002 # Description : Returns the synopsis and detailed description of a function.
2003 # Arguments : $symbol - the function.
2004 # $declaration - the declaration of the function.
2005 #############################################################################
2007 sub OutputFunction {
2008 my ($symbol, $declaration, $symbol_type) = @_;
2009 my $id = &CreateValidSGMLID ($symbol);
2010 my $condition = &MakeConditionDescription ($symbol);
2012 # Take out the return type $1 $2 $3
2013 $declaration =~ s/<RETURNS>\s*((?:const\s+|G_CONST_RETURN\s+|signed\s+|unsigned\s+|long\s+|short\s+|struct\s+|enum\s+)*)(\w+)(\s*\**\s*(?:const|G_CONST_RETURN)?\s*\**\s*(?:restrict)?\s*)<\/RETURNS>\n//;
2014 my $type_modifier = defined($1) ? $1 : "";
2017 # Trim trailing spaces as we are going to pad to $RETURN_TYPE_FIELD_WIDTH below anyway
2018 $pointer =~ s/\s+$//;
2019 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
2021 #if ($symbol_type eq 'USER_FUNCTION') {
2022 # $start = "typedef ";
2025 # We output const rather than G_CONST_RETURN.
2026 $type_modifier =~ s/G_CONST_RETURN/const/g;
2027 $pointer =~ s/G_CONST_RETURN/const/g;
2028 $pointer =~ s/^\s+/ /g;
2030 my $ret_type_len = length ($start) + length ($type_modifier)+ length ($type)
2031 + length ($pointer);
2032 my $ret_type_output;
2034 if ($ret_type_len < $RETURN_TYPE_FIELD_WIDTH) {
2035 $ret_type_output = "$start$type_modifier$xref$pointer"
2036 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
2039 #$ret_type_output = "$start$type_modifier$xref$pointer\n" . (' ' x $RETURN_TYPE_FIELD_WIDTH);
2041 $ret_type_output = "$start$type_modifier$xref$pointer ";
2042 $symbol_len = $ret_type_len + 1 - $RETURN_TYPE_FIELD_WIDTH;
2044 #@TRACE@("$symbol ret type output: [$ret_type_output], $ret_type_len");
2046 $symbol_len += length ($symbol);
2047 my $char1 = my $char2 = my $char3 = "";
2048 if ($symbol_type eq 'USER_FUNCTION') {
2055 my ($symbol_output, $symbol_desc_output);
2056 if ($symbol_len < $SYMBOL_FIELD_WIDTH) {
2057 $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3"
2058 . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
2059 $symbol_desc_output = "$char1$char2$symbol$char3"
2060 . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
2062 $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3\n"
2063 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
2064 $symbol_desc_output = "$char1$char2$symbol$char3\n"
2065 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
2068 my $synop = $ret_type_output . $symbol_output . '(';
2069 my $desc = "<refsect2 id=\"$id\" role=\"function\"$condition>\n<title>${symbol} ()</title>\n";
2071 $desc .= MakeIndexterms($symbol, $id);
2073 $desc .= OutputSymbolExtraLinks($symbol);
2075 $desc .= "<programlisting>${ret_type_output}$symbol_desc_output(";
2077 my @fields = ParseFunctionDeclaration($declaration, \&MakeXRef,
2079 &tagify($_[0],"parameter");
2082 for (my $i = 1; $i <= $#fields; $i += 2) {
2083 my $field_name = $fields[$i];
2086 $synop .= "$field_name";
2087 $desc .= "$field_name";
2090 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2093 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2100 $desc .= ");</programlisting>\n";
2102 $desc .= &MakeDeprecationNote($symbol);
2104 my $parameters = &OutputParamDescriptions ("FUNCTION", $symbol, @fields);
2105 my $parameters_output = 0;
2107 if (defined ($SymbolDocs{$symbol})) {
2108 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
2110 # Try to insert the parameter table at the author's desired position.
2111 # Otherwise we need to tag it onto the end.
2112 # FIXME: document that in the user manual and make it useable for other
2114 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
2115 $parameters_output = 1;
2117 $desc .= $symbol_docs;
2120 if ($parameters_output == 0) {
2121 $desc .= $parameters;
2124 $desc .= OutputSymbolTraits ($symbol);
2125 $desc .= "</refsect2>\n";
2126 return ($synop, $desc);
2130 #############################################################################
2131 # Function : OutputParamDescriptions
2132 # Description : Returns the DocBook output describing the parameters of a
2133 # function, macro or signal handler.
2134 # Arguments : $symbol_type - 'FUNCTION', 'MACRO' or 'SIGNAL'. Signal
2135 # handlers have an implicit user_data parameter last.
2136 # $symbol - the name of the function/macro being described.
2137 # @fields - parsed fields from the declaration, used to determine
2138 # undocumented/unused entries
2139 #############################################################################
2141 sub OutputParamDescriptions {
2142 my ($symbol_type, $symbol, @fields) = @_;
2144 my $params = $SymbolParams{$symbol};
2146 my %field_descrs = ();
2149 %field_descrs = @fields;
2150 delete $field_descrs{"void"};
2151 delete $field_descrs{"Returns"};
2154 if (defined $params) {
2156 my $params_desc = "";
2157 my $missing_parameters = "";
2158 my $unused_parameters = "";
2161 for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
2162 my $param_name = $$params[$j];
2163 my $param_desc = $$params[$j + 1];
2164 my $param_annotations = "";
2166 ($param_desc,$param_annotations) = & ExpandAnnotation($symbol, $param_desc);
2167 $param_desc = &ExpandAbbreviations($symbol, $param_desc);
2168 $param_desc .= $param_annotations;
2170 $param_desc =~ s/^(\s|\n)+//msg;
2171 $param_desc =~ s/(\s|\n)+$//msg;
2172 if ($param_name eq "Returns") {
2173 $returns = "$param_desc";
2174 } elsif ($param_name eq "void") {
2175 #print "!!!! void in params for $symbol?\n";
2178 if (!defined $field_descrs{$param_name}) {
2179 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2180 "Parameter description for $symbol"."::"."$param_name is not used from source code comment block.");
2181 if ($unused_parameters ne "") {
2182 $unused_parameters .= ", ".$param_name;
2184 $unused_parameters = $param_name;
2187 delete $field_descrs{$param_name};
2190 if($param_desc ne "") {
2191 $params_desc .= "<varlistentry><term><parameter>$param_name</parameter> :</term>\n<listitem><simpara>$param_desc</simpara></listitem></varlistentry>\n";
2196 foreach my $param_name (keys %field_descrs) {
2197 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2198 "Parameter description for $symbol"."::"."$param_name is missing in source code comment block.");
2199 if ($missing_parameters ne "") {
2200 $missing_parameters .= ", ".$param_name;
2202 $missing_parameters = $param_name;
2206 # Signals have an implicit user_data parameter which we describe.
2207 if ($symbol_type eq "SIGNAL") {
2208 $params_desc .= "<varlistentry><term><parameter>user_data</parameter> :</term>\n<listitem><simpara>user data set when the signal handler was connected.</simpara></listitem></varlistentry>\n";
2211 # Start a table if we need one.
2212 if ($params_desc || $returns) {
2213 $output .= "<variablelist role=\"params\">\n";
2214 if ($params_desc ne "") {
2215 #$output .= "<varlistentry><term>Parameters:</term><listitem></listitem></varlistentry>\n";
2216 $output .= $params_desc;
2219 # Output the returns info last
2221 $output .= "<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>$returns</simpara></listitem></varlistentry>\n";
2225 $output .= "</variablelist>";
2228 # remember missing/unused parameters (needed in tmpl-free build)
2229 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
2230 $AllIncompleteSymbols{$symbol}=$missing_parameters;
2232 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
2233 $AllUnusedSymbols{$symbol}=$unused_parameters;
2236 if (($num_params == 0) && @fields && (scalar(keys(%field_descrs)) > 0)) {
2237 if (! exists ($AllIncompleteSymbols{$symbol})) {
2238 $AllIncompleteSymbols{$symbol}="<parameters>";
2246 #############################################################################
2247 # Function : ParseStabilityLevel
2248 # Description : Parses a stability level and outputs a warning if it isn't
2250 # Arguments : $stability - the stability text.
2251 # $file, $line - context for error message
2252 # $message - description of where the level is from, to use in
2253 # any error message.
2254 # Returns : The parsed stability level string.
2255 #############################################################################
2257 sub ParseStabilityLevel {
2258 my ($stability, $file, $line, $message) = @_;
2260 $stability =~ s/^\s*//;
2261 $stability =~ s/\s*$//;
2262 if ($stability =~ m/^stable$/i) {
2263 $stability = "Stable";
2264 } elsif ($stability =~ m/^unstable$/i) {
2265 $stability = "Unstable";
2266 } elsif ($stability =~ m/^private$/i) {
2267 $stability = "Private";
2269 &LogWarning ($file, $line, "$message is $stability.".
2270 "It should be one of these: Stable, Unstable, or Private.");
2276 #############################################################################
2277 # Function : OutputSGMLFile
2278 # Description : Outputs the final DocBook file for one section.
2279 # Arguments : $file - the name of the file.
2280 # $title - the title from the $MODULE-sections.txt file, which
2281 # will be overridden by the title in the template file.
2282 # $section_id - the SGML id to use for the toplevel tag.
2283 # $includes - comma-separates list of include files added at top of
2284 # synopsis, with '<' '>' around them (if not already enclosed in "").
2285 # $synopsis - reference to the DocBook for the Synopsis part.
2286 # $details - reference to the DocBook for the Details part.
2287 # $signal_synop - reference to the DocBook for the Signal Synopsis part
2288 # $signal_desc - reference to the DocBook for the Signal Description part
2289 # $args_synop - reference to the DocBook for the Arg Synopsis part
2290 # $args_desc - reference to the DocBook for the Arg Description part
2291 # $hierarchy - reference to the DocBook for the Object Hierarchy part
2292 # $interfaces - reference to the DocBook for the Interfaces part
2293 # $implementations - reference to the DocBook for the Known Implementations part
2294 # $prerequisites - reference to the DocBook for the Prerequisites part
2295 # $derived - reference to the DocBook for the Derived Interfaces part
2296 # $file_objects - reference to an array of objects in this file
2297 #############################################################################
2299 sub OutputSGMLFile {
2300 my ($file, $title, $section_id, $includes, $synopsis, $details, $signals_synop, $signals_desc, $args_synop, $args_desc, $hierarchy, $interfaces, $implementations, $prerequisites, $derived, $file_objects) = @_;
2302 #print "Output sgml for file $file with title '$title'\n";
2304 # The edited title overrides the one from the sections file.
2305 my $new_title = $SymbolDocs{"$TMPL_DIR/$file:Title"};
2306 if (defined ($new_title) && $new_title !~ m/^\s*$/) {
2307 $title = $new_title;
2308 #print "Found title: $title\n";
2310 my $short_desc = $SymbolDocs{"$TMPL_DIR/$file:Short_Description"};
2311 if (!defined ($short_desc) || $short_desc =~ m/^\s*$/) {
2314 $short_desc = &ExpandAbbreviations("$title:Short_description",
2316 #print "Found short_desc: $short_desc";
2318 my $long_desc = $SymbolDocs{"$TMPL_DIR/$file:Long_Description"};
2319 if (!defined ($long_desc) || $long_desc =~ m/^\s*$/) {
2322 $long_desc = &ExpandAbbreviations("$title:Long_description",
2324 #print "Found long_desc: $long_desc";
2326 my $see_also = $SymbolDocs{"$TMPL_DIR/$file:See_Also"};
2327 if (!defined ($see_also) || $see_also =~ m%^\s*(<para>)?\s*(</para>)?\s*$%) {
2330 $see_also = &ExpandAbbreviations("$title:See_Also", $see_also);
2331 #print "Found see_also: $see_also";
2334 $see_also = "<refsect1 id=\"$section_id.see-also\">\n<title>See Also</title>\n$see_also\n</refsect1>\n";
2336 my $stability = $SymbolDocs{"$TMPL_DIR/$file:Stability_Level"};
2337 if (!defined ($stability) || $stability =~ m/^\s*$/) {
2340 $stability = &ParseStabilityLevel($stability, $file, $., "Section stability level");
2341 #print "Found stability: $stability";
2344 $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$stability, unless otherwise indicated\n</refsect1>\n";
2345 } elsif ($DEFAULT_STABILITY) {
2346 $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$DEFAULT_STABILITY, unless otherwise indicated\n</refsect1>\n";
2349 my $image = $SymbolDocs{"$TMPL_DIR/$file:Image"};
2350 if (!defined ($image) || $image =~ m/^\s*$/) {
2358 if ($image =~ /jpe?g$/i) {
2359 $format = "format='JPEG'";
2360 } elsif ($image =~ /png$/i) {
2361 $format = "format='PNG'";
2362 } elsif ($image =~ /svg$/i) {
2363 $format = "format='SVG'";
2368 $image = " <inlinegraphic fileref='$image' $format/>\n"
2371 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
2373 my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
2376 my $include_output = "";
2378 foreach $include (split (/,/, $includes)) {
2379 if ($include =~ m/^\".+\"$/) {
2380 $include_output .= "#include ${include}\n";
2383 $include =~ s/^\s+|\s+$//gs;
2384 $include_output .= "#include <${include}>\n";
2387 if ($include_output ne '') {
2388 $include_output = "\n$include_output\n";
2391 my $extralinks = OutputSectionExtraLinks($title,"Section:$file");
2393 my $old_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT";
2394 my $new_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT.new";
2396 open (OUTPUT, ">$new_sgml_file")
2397 || die "Can't create $new_sgml_file: $!";
2399 my $object_anchors = "";
2400 foreach my $object (@$file_objects) {
2401 next if ($object eq $section_id);
2402 my $id = CreateValidSGMLID($object);
2403 #print "Debug: Adding anchor for $object\n";
2404 $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
2407 # We used to output this, but is messes up our UpdateFileIfChanged code
2408 # since it changes every day (and it is only used in the man pages):
2409 # "<refentry id="$section_id" revision="$mday $month $year">"
2411 if ($OUTPUT_FORMAT eq "xml") {
2412 print OUTPUT $doctype_header;
2416 <refentry id="$section_id">
2418 <refentrytitle role="top_of_page" id="$section_id.top_of_page">$title</refentrytitle>
2419 <manvolnum>3</manvolnum>
2422 $image</refmiscinfo>
2425 <refname>$title</refname>
2426 <refpurpose>$short_desc</refpurpose>
2429 <refsynopsisdiv id="$section_id.synopsis" role="synopsis">
2430 <title role="synopsis.title">Synopsis</title>
2432 <synopsis>$include_output$${synopsis}</synopsis>
2434 $$hierarchy$$prerequisites$$derived$$interfaces$$implementations$$args_synop$$signals_synop
2435 <refsect1 id="$section_id.description" role="desc">
2436 <title role="desc.title">Description</title>
2437 $extralinks$long_desc
2439 <refsect1 id="$section_id.details" role="details">
2440 <title role="details.title">Details</title>
2443 $$args_desc$$signals_desc$see_also
2448 return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2452 #############################################################################
2453 # Function : OutputExtraFile
2454 # Description : Copies an "extra" DocBook file into the output directory,
2455 # expanding abbreviations
2456 # Arguments : $file - the source file.
2457 #############################################################################
2458 sub OutputExtraFile {
2463 ($basename = $file) =~ s!^.*/!!;
2465 my $old_sgml_file = "$SGML_OUTPUT_DIR/$basename";
2466 my $new_sgml_file = "$SGML_OUTPUT_DIR/$basename.new";
2470 open(EXTRA_FILE, "<$file") || die "Can't open $file";
2474 $contents = <EXTRA_FILE>;
2477 open (OUTPUT, ">$new_sgml_file")
2478 || die "Can't create $new_sgml_file: $!";
2480 print OUTPUT &ExpandAbbreviations ("$basename file", $contents);
2483 return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2485 #############################################################################
2486 # Function : OutputBook
2487 # Description : Outputs the SGML entities that need to be included into the
2488 # main SGML file for the module.
2489 # Arguments : $book_top - the declarations of the entities, which are added
2490 # at the top of the main SGML file.
2491 # $book_bottom - the references to the entities, which are
2492 # added in the main SGML file at the desired position.
2493 #############################################################################
2496 my ($book_top, $book_bottom) = @_;
2498 my $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top";
2499 my $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top.new";
2501 open (OUTPUT, ">$new_file")
2502 || die "Can't create $new_file: $!";
2503 print OUTPUT $book_top;
2506 &UpdateFileIfChanged ($old_file, $new_file, 0);
2509 $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom";
2510 $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom.new";
2512 open (OUTPUT, ">$new_file")
2513 || die "Can't create $new_file: $!";
2514 print OUTPUT $book_bottom;
2517 &UpdateFileIfChanged ($old_file, $new_file, 0);
2520 # If the main SGML/XML file hasn't been created yet, we create it here.
2521 # The user can tweak it later.
2522 if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
2523 open (OUTPUT, ">$MAIN_SGML_FILE")
2524 || die "Can't create $MAIN_SGML_FILE: $!";
2526 if ($OUTPUT_FORMAT eq "xml") {
2528 <?xml version="1.0"?>
2529 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
2530 "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
2532 <!ENTITY % local.common.attrib "xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'">
2538 <!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
2547 <title>$MODULE Reference Manual</title>
2549 for $MODULE [VERSION].
2550 The latest version of this documentation can be found on-line at
2551 <ulink role="online-location" url="http://[SERVER]/$MODULE/index.html">http://[SERVER]/$MODULE/</ulink>.
2556 <title>[Insert title here]</title>
2560 if (-e $OBJECT_TREE_FILE) {
2562 <chapter id="object-tree">
2563 <title>Object Hierarchy</title>
2564 <xi:include href="xml/tree_index.sgml"/>
2570 <index id="api-index-full">
2571 <title>API Index</title>
2572 <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
2574 <index id="deprecated-api-index" role="deprecated">
2575 <title>Index of deprecated API</title>
2576 <xi:include href="xml/api-index-deprecated.xml"><xi:fallback /></xi:include>
2579 <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
2588 #############################################################################
2589 # Function : CreateValidSGML
2590 # Description : This turns any chars which are used in SGML into entities,
2591 # e.g. '<' into '<'
2592 # Arguments : $text - the text to turn into proper SGML.
2593 #############################################################################
2595 sub CreateValidSGML {
2597 $text =~ s/&/&/g; # Do this first, or the others get messed up.
2598 $text =~ s/</</g;
2599 $text =~ s/>/>/g;
2600 # browers render single tabs inconsistently
2601 $text =~ s/([^\s])\t([^\s])/$1 $2/g;
2605 #############################################################################
2606 # Function : ConvertSGMLChars
2607 # Description : This is used for text in source code comment blocks, to turn
2608 # chars which are used in SGML into entities, e.g. '<' into
2609 # '<'. Depending on $INLINE_MARKUP_MODE, this is done
2610 # unconditionally or only if the character doesn't seem to be
2611 # part of an SGML construct (tag or entity reference).
2612 # Arguments : $text - the text to turn into proper SGML.
2613 #############################################################################
2615 sub ConvertSGMLChars {
2616 my ($symbol, $text) = @_;
2618 if ($INLINE_MARKUP_MODE) {
2619 # For the XML/SGML mode only convert to entities outside CDATA sections.
2620 return &ModifyXMLElements ($text, $symbol,
2621 "<!\\[CDATA\\[|<programlisting[^>]*>",
2622 \&ConvertSGMLCharsEndTag,
2623 \&ConvertSGMLCharsCallback);
2625 # For the simple non-sgml mode, convert to entities everywhere.
2626 $text =~ s/&/&/g; # Do this first, or the others get messed up.
2627 $text =~ s/</</g;
2628 $text =~ s/>/>/g;
2634 sub ConvertSGMLCharsEndTag {
2635 if ($_[0] eq "<!\[CDATA\[") {
2638 return "</programlisting>";
2642 sub ConvertSGMLCharsCallback {
2643 my ($text, $symbol, $tag) = @_;
2645 if ($tag =~ m/^<programlisting/) {
2646 # We can handle <programlisting> specially here.
2647 return &ModifyXMLElements ($text, $symbol,
2649 \&ConvertSGMLCharsEndTag,
2650 \&ConvertSGMLCharsCallback2);
2651 } elsif ($tag eq "") {
2652 # If we're not in CDATA convert to entities.
2653 $text =~ s/&(?![a-zA-Z#]+;)/&/g; # Do this first, or the others get messed up.
2654 $text =~ s/<(?![a-zA-Z\/!])/</g;
2655 $text =~ s/(?<![a-zA-Z0-9"'\/-])>/>/g;
2657 # Handle "#include <xxxxx>"
2658 $text =~ s/#include(\s+)<([^>]+)>/#include$1<$2>/g;
2664 sub ConvertSGMLCharsCallback2 {
2665 my ($text, $symbol, $tag) = @_;
2667 # If we're not in CDATA convert to entities.
2668 # We could handle <programlisting> differently, though I'm not sure it helps.
2670 # replace only if its not a tag
2671 $text =~ s/&(?![a-zA-Z#]+;)/&/g; # Do this first, or the others get messed up.
2672 $text =~ s/<(?![a-zA-Z\/!])/</g;
2673 $text =~ s/(?<![a-zA-Z0-9"'\/-])>/>/g;
2675 # Handle "#include <xxxxx>"
2676 $text =~ s/#include(\s+)<([^>]+)>/#include$1<$2>/g;
2682 #############################################################################
2683 # Function : ExpandAnnotation
2684 # Description : This turns annotations into acronym tags.
2685 # Arguments : $symbol - the symbol being documented, for error messages.
2686 # $text - the text to expand.
2687 #############################################################################
2688 sub ExpandAnnotation {
2689 my ($symbol, $param_desc) = @_;
2690 my $param_annotations = "";
2692 # look for annotations at the start of the comment part
2693 if ($param_desc =~ m%^\s*\((.*?)\):%) {
2698 @annotations = split(/\)\s*\(/,$1);
2699 foreach $annotation (@annotations) {
2700 # need to search for the longest key-match in %AnnotationDefinition
2702 my $match_annotation="";
2704 foreach $annotationdef (keys %AnnotationDefinition) {
2705 if ($annotation =~ m/^$annotationdef/) {
2706 if (length($annotationdef)>$match_length) {
2707 $match_length=length($annotationdef);
2708 $match_annotation=$annotationdef;
2712 my $annotation_extra = "";
2713 if ($match_annotation ne "") {
2714 if ($annotation =~ m%$match_annotation\s+(.*)%) {
2715 $annotation_extra = " $1";
2717 $AnnotationsUsed{$match_annotation} = 1;
2718 $param_annotations .= "[<acronym>$match_annotation</acronym>$annotation_extra]";
2721 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2722 "unknown annotation \"$annotation\" in documentation for $symbol.");
2723 $param_annotations .= "[$annotation]";
2727 $param_desc =~ m/^(.*?)\.*\s*$/s;
2728 $param_desc = "$1. ";
2730 if ($param_annotations ne "") {
2731 $param_annotations = "<emphasis role=\"annotation\">$param_annotations</emphasis>";
2733 return ($param_desc, $param_annotations);
2736 #############################################################################
2737 # Function : ExpandAbbreviations
2738 # Description : This turns the abbreviations function(), macro(), @param,
2739 # %constant, and #symbol into appropriate DocBook markup.
2740 # CDATA sections and <programlisting> parts are skipped.
2741 # Arguments : $symbol - the symbol being documented, for error messages.
2742 # $text - the text to expand.
2743 #############################################################################
2745 sub ExpandAbbreviations {
2746 my ($symbol, $text) = @_;
2748 # Convert "|[" and "]|" into the start and end of program listing examples.
2749 # FIXME: we like to have a way to specify parameters e.g. language="c"
2750 $text =~ s%\|\[%<informalexample><programlisting>%g;
2751 $text =~ s%\]\|%</programlisting></informalexample>%g;
2752 # TODO: check for a xml comment after |[ and pick the language attribute from
2755 # keep CDATA unmodified, preserve ulink tags (ideally we preseve all tags
2757 return &ModifyXMLElements ($text, $symbol,
2758 "<!\\[CDATA\\[|<ulink[^>]*>|<programlisting[^>]*>|<!DOCTYPE",
2759 \&ExpandAbbreviationsEndTag,
2760 \&ExpandAbbreviationsCallback);
2764 # Returns the end tag (as a regexp) corresponding to the given start tag.
2765 sub ExpandAbbreviationsEndTag {
2766 my ($start_tag) = @_;
2768 if ($start_tag eq "<!\[CDATA\[") {
2770 } elsif ($start_tag eq "<!DOCTYPE") {
2772 } elsif ($start_tag =~ m/<(\w+)/) {
2777 # Called inside or outside each CDATA or <programlisting> section.
2778 sub ExpandAbbreviationsCallback {
2779 my ($text, $symbol, $tag) = @_;
2781 if ($tag =~ m/^<programlisting/) {
2782 # Handle any embedded CDATA sections.
2783 return &ModifyXMLElements ($text, $symbol,
2785 \&ExpandAbbreviationsEndTag,
2786 \&ExpandAbbreviationsCallback2);
2787 } elsif ($tag eq "") {
2788 # We are outside any CDATA or <programlisting> sections, so we expand
2789 # any gtk-doc abbreviations.
2791 # Convert '@param()'
2792 # FIXME: we could make those also links ($symbol.$2), but that would be less
2793 # useful as the link target is a few lines up or down
2794 $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)\s*\(\)/$1<parameter>$2()<\/parameter>/g;
2796 # Convert 'function()' or 'macro()'.
2797 # if there is abc_*_def() we don't want to make a link to _def()
2798 # FIXME: also handle abc(def(....)) : but that would need to be done recursively :/
2799 $text =~ s/([^\*.\w])(\w+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2800 # handle #Object.func()
2801 $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2803 # Convert '@param', but not '\@param'.
2804 $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)/$1<parameter>$2<\/parameter>/g;
2805 $text =~ s/\\\@/\@/g;
2807 # Convert '%constant', but not '\%constant'.
2808 # Also allow negative numbers, e.g. %-1.
2809 $text =~ s/(\A|[^\\])\%(-?\w+)/$1.&MakeXRef($2, &tagify($2, "literal"));/eg;
2810 $text =~ s/\\\%/\%/g;
2812 # Convert '#symbol', but not '\#symbol'.
2813 $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)/$1.&MakeHashXRef($2, "type");/eg;
2817 # FIXME: should we skip urls that are already tagged? (e.g. <literal>http://...</literal>)
2818 # this is apparently also called for markup and not just for plain text
2820 #$text =~ s%(http|https|ftp)://(.*?)((?:\s|,|\)|\]|\<|\.\s))%<ulink url="$1://$2">$2</ulink>$3%g;
2822 # TODO: optionally check all words from $text against internal symbols and
2823 # warn if those could be xreffed, but miss a %,# or ()
2829 # This is called inside a <programlisting>
2830 sub ExpandAbbreviationsCallback2 {
2831 my ($text, $symbol, $tag) = @_;
2834 # We are inside a <programlisting> but outside any CDATA sections,
2835 # so we expand any gtk-doc abbreviations.
2836 # FIXME: why is this different from &ExpandAbbreviationsCallback(),
2837 # why not just call it
2838 $text =~ s/#(\w+)/&MakeHashXRef($1, "");/eg;
2845 my ($symbol, $tag) = @_;;
2848 # Check for things like '#include', '#define', and skip them.
2849 if ($PreProcessorDirectives{$symbol}) {
2853 # Get rid of special suffixes ('-struct','-enum').
2854 $text =~ s/-struct$//;
2855 $text =~ s/-enum$//;
2857 # If the symbol is in the form "Object::signal", then change the symbol to
2858 # "Object-signal" and use "signal" as the text.
2859 if ($symbol =~ s/::/-/) {
2863 # If the symbol is in the form "Object:property", then change the symbol to
2864 # "Object--property" and use "property" as the text.
2865 if ($symbol =~ s/:/--/) {
2870 $text = tagify ($text, $tag);
2873 return &MakeXRef($symbol, $text);
2877 #############################################################################
2878 # Function : ModifyXMLElements
2879 # Description : Looks for given XML element tags within the text, and calls
2880 # the callback on pieces of text inside & outside those elements.
2881 # Used for special handling of text inside things like CDATA
2882 # and <programlisting>.
2883 # Arguments : $text - the text.
2884 # $symbol - the symbol currently being documented (only used for
2886 # $start_tag_regexp - the regular expression to match start tags.
2887 # e.g. "<!\\[CDATA\\[|<programlisting[^>]*>" to match
2888 # CDATA sections or programlisting elements.
2889 # $end_tag_func - function which is passed the matched start tag
2890 # and should return the appropriate end tag string regexp.
2891 # $callback - callback called with each part of the text. It is
2892 # called with a piece of text, the symbol being
2893 # documented, and the matched start tag or "" if the text
2894 # is outside the XML elements being matched.
2895 #############################################################################
2896 sub ModifyXMLElements {
2897 my ($text, $symbol, $start_tag_regexp, $end_tag_func, $callback) = @_;
2898 my ($before_tag, $start_tag, $end_tag_regexp, $end_tag);
2901 while ($text =~ m/$start_tag_regexp/s) {
2902 $before_tag = $`; # Prematch for last successful match string
2903 $start_tag = $&; # Last successful match
2904 $text = $'; # Postmatch for last successful match string
2906 $result .= &$callback ($before_tag, $symbol, "");
2907 $result .= $start_tag;
2909 # get the matching end-tag for current tag
2910 $end_tag_regexp = &$end_tag_func ($start_tag);
2912 if ($text =~ m/$end_tag_regexp/s) {
2917 $result .= &$callback ($before_tag, $symbol, $start_tag);
2918 $result .= $end_tag;
2920 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2921 "Can't find tag end: $end_tag_regexp in docs for: $symbol.");
2922 # Just assume it is all inside the tag.
2923 $result .= &$callback ($text, $symbol, $start_tag);
2928 # Handle any remaining text outside the tags.
2929 $result .= &$callback ($text, $symbol, "");
2938 # Adds a tag around some text.
2939 # e.g tagify("Text", "literal") => "<literal>Text</literal>".
2941 my ($text, $elem) = @_;
2942 return "<" . $elem . ">" . $text . "</" . $elem . ">";
2946 #############################################################################
2947 # Function : MakeXRef
2948 # Description : This returns a cross-reference link to the given symbol.
2949 # Though it doesn't try to do this for a few standard C types
2950 # that it knows won't be in the documentation.
2951 # Arguments : $symbol - the symbol to try to create a XRef to.
2952 # $text - text text to put inside the XRef, defaults to $symbol
2953 #############################################################################
2956 my ($symbol, $text) = ($_[0], $_[1]);
2958 $symbol =~ s/^\s+//;
2959 $symbol =~ s/\s+$//;
2961 if (!defined($text)) {
2964 # Get rid of special suffixes ('-struct','-enum').
2965 $text =~ s/-struct$//;
2966 $text =~ s/-enum$//;
2969 if ($symbol =~ m/ /) {
2973 #print "Getting type link for $symbol -> $text\n";
2975 my $symbol_id = &CreateValidSGMLID ($symbol);
2976 return "<link linkend=\"$symbol_id\">$text</link>";
2980 #############################################################################
2981 # Function : MakeIndexterms
2982 # Description : This returns a indexterm elements for the given symbol
2983 # Arguments : $symbol - the symbol to create indexterms for
2984 #############################################################################
2986 sub MakeIndexterms {
2987 my ($symbol, $id) = @_;
2991 # make the index useful, by ommiting the namespace when sorting
2992 if ($NAME_SPACE ne "") {
2993 if ($symbol =~ m/^$NAME_SPACE\_?(.*)/i) {
2994 $sortas=" sortas=\"$1\"";
2998 if (exists $Deprecated{$symbol}) {
2999 $terms .= "<indexterm zone=\"$id\" role=\"deprecated\"><primary$sortas>$symbol</primary></indexterm>";
3000 $IndexEntriesDeprecated{$symbol}=$id;
3001 $IndexEntriesFull{$symbol}=$id;
3003 if (exists $Since{$symbol}) {
3004 my $since = $Since{$symbol};
3008 $terms .= "<indexterm zone=\"$id\" role=\"$since\"><primary$sortas>$symbol</primary></indexterm>";
3010 $IndexEntriesSince{$symbol}=$id;
3011 $IndexEntriesFull{$symbol}=$id;
3014 $terms .= "<indexterm zone=\"$id\"><primary$sortas>$symbol</primary></indexterm>";
3015 $IndexEntriesFull{$symbol}=$id;
3021 #############################################################################
3022 # Function : MakeDeprecationNote
3023 # Description : This returns a deprecation warning for the given symbol.
3024 # Arguments : $symbol - the symbol to try to create a warning for.
3025 #############################################################################
3027 sub MakeDeprecationNote {
3028 my ($symbol) = $_[0];
3031 if (exists $Deprecated{$symbol}) {
3032 $desc .= "<warning>";
3034 if ($Deprecated{$symbol} =~ /^\s*([0-9\.]+)\s*:/) {
3035 $desc .= "<para><literal>$symbol</literal> has been deprecated since version $1 and should not be used in newly-written code.";
3037 $desc .= "<para><literal>$symbol</literal> is deprecated and should not be used in newly-written code.";
3039 if ($Deprecated{$symbol} ne "") {
3040 $note = &ExpandAbbreviations($symbol, $Deprecated{$symbol});
3041 $note =~ s/^\s*([0-9\.]+)\s*:\s*//;
3044 $note =~ s%\n{2,}%\n</para>\n<para>\n%g;
3045 $desc .= " " . $note;
3047 $desc .= "</para></warning>\n";
3052 #############################################################################
3053 # Function : MakeConditionDescription
3054 # Description : This returns a sumary of conditions for the given symbol.
3055 # Arguments : $symbol - the symbol to try to create the sumary.
3056 #############################################################################
3058 sub MakeConditionDescription {
3059 my ($symbol) = $_[0];
3062 if (exists $Deprecated{$symbol}) {
3067 if ($Deprecated{$symbol} =~ /^\s*(.*?)\s*$/) {
3068 $desc .= "deprecated:$1";
3070 $desc .= "deprecated";
3074 if (exists $Since{$symbol}) {
3079 if ($Since{$symbol} =~ /^\s*(.*?)\s*$/) {
3080 $desc .= "since:$1";
3086 if (exists $StabilityLevel{$symbol}) {
3090 $desc .= "stability:".$StabilityLevel{$symbol};
3094 $desc=" condition=\"".$desc."\"";
3095 #print "condition for '$symbol' = '$desc'\n";
3100 #############################################################################
3101 # Function : GetHierarchy
3102 # Description : Returns the DocBook output describing the ancestors and
3103 # immediate children of a GObject subclass. It uses the
3104 # global @Objects and @ObjectLevels arrays to walk the tree.
3105 # Arguments : $object - the GtkObject subclass.
3106 #############################################################################
3111 # Find object in the objects array.
3117 for ($i = 0; $i < @Objects; $i++) {
3119 if ($ObjectLevels[$i] <= $level) {
3122 elsif ($ObjectLevels[$i] == $level + 1) {
3123 push (@children, $Objects[$i]);
3126 elsif ($Objects[$i] eq $object) {
3129 $level = $ObjectLevels[$i];
3136 # Walk up the hierarchy, pushing ancestors onto the ancestors array.
3138 push (@ancestors, $object);
3139 #print "Level: $level\n";
3140 while ($level > 1) {
3142 if ($ObjectLevels[$j] < $level) {
3143 push (@ancestors, $Objects[$j]);
3144 $level = $ObjectLevels[$j];
3145 #print "Level: $level\n";
3149 # Output the ancestors list, indented and with links.
3150 my $hierarchy = "<synopsis>\n";
3152 for ($i = $#ancestors; $i >= 0; $i--) {
3154 # Don't add a link to the current object, i.e. when i == 0.
3156 my $ancestor_id = &CreateValidSGMLID ($ancestors[$i]);
3157 $link_text = "<link linkend=\"$ancestor_id\">$ancestors[$i]</link>";
3159 $link_text = "$ancestors[$i]";
3162 $hierarchy .= " $link_text\n";
3164 # $hierarchy .= ' ' x ($level * 6 - 3) . "|\n";
3165 $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3169 for ($i = 0; $i <= $#children; $i++) {
3170 my $id = &CreateValidSGMLID ($children[$i]);
3171 my $link_text = "<link linkend=\"$id\">$children[$i]</link>";
3172 $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3174 $hierarchy .= "</synopsis>\n";
3180 #############################################################################
3181 # Function : GetInterfaces
3182 # Description : Returns the DocBook output describing the interfaces
3183 # implemented by a class. It uses the global %Interfaces hash.
3184 # Arguments : $object - the GtkObject subclass.
3185 #############################################################################
3192 # Find object in the objects array.
3193 if (exists($Interfaces{$object})) {
3194 my @ifaces = split(' ', $Interfaces{$object});
3199 for ($i = 0; $i <= $#ifaces; $i++) {
3200 my $id = &CreateValidSGMLID ($ifaces[$i]);
3201 $text .= " <link linkend=\"$id\">$ifaces[$i]</link>";
3202 if ($i < $#ifaces - 1) {
3205 elsif ($i < $#ifaces) {
3220 #############################################################################
3221 # Function : GetImplementations
3222 # Description : Returns the DocBook output describing the implementations
3223 # of an interface. It uses the global %Interfaces hash.
3224 # Arguments : $object - the GtkObject subclass.
3225 #############################################################################
3227 sub GetImplementations {
3232 foreach my $key (keys %Interfaces) {
3233 if ($Interfaces{$key} =~ /\b$object\b/) {
3234 push (@impls, $key);
3238 @impls = sort @impls;
3241 $object is implemented by
3243 for ($i = 0; $i <= $#impls; $i++) {
3244 my $id = &CreateValidSGMLID ($impls[$i]);
3245 $text .= " <link linkend=\"$id\">$impls[$i]</link>";
3246 if ($i < $#impls - 1) {
3249 elsif ($i < $#impls) {
3264 #############################################################################
3265 # Function : GetPrerequisites
3266 # Description : Returns the DocBook output describing the prerequisites
3267 # of an interface. It uses the global %Prerequisites hash.
3268 # Arguments : $iface - the interface.
3269 #############################################################################
3271 sub GetPrerequisites {
3276 if (exists($Prerequisites{$iface})) {
3281 my @prereqs = split(' ', $Prerequisites{$iface});
3282 for ($i = 0; $i <= $#prereqs; $i++) {
3283 my $id = &CreateValidSGMLID ($prereqs[$i]);
3284 $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
3285 if ($i < $#prereqs - 1) {
3288 elsif ($i < $#prereqs) {
3302 #############################################################################
3303 # Function : GetDerived
3304 # Description : Returns the DocBook output describing the derived interfaces
3305 # of an interface. It uses the global %Prerequisites hash.
3306 # Arguments : $iface - the interface.
3307 #############################################################################
3315 foreach my $key (keys %Prerequisites) {
3316 if ($Prerequisites{$key} =~ /\b$iface\b/) {
3317 push (@derived, $key);
3320 if ($#derived >= 0) {
3321 @derived = sort @derived;
3324 $iface is required by
3326 for ($i = 0; $i <= $#derived; $i++) {
3327 my $id = &CreateValidSGMLID ($derived[$i]);
3328 $text .= " <link linkend=\"$id\">$derived[$i]</link>";
3329 if ($i < $#derived - 1) {
3332 elsif ($i < $#derived) {
3347 #############################################################################
3348 # Function : GetSignals
3349 # Description : Returns the synopsis and detailed description DocBook output
3350 # for the signal handlers of a given GtkObject subclass.
3351 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
3352 #############################################################################
3360 for ($i = 0; $i <= $#SignalObjects; $i++) {
3361 if ($SignalObjects[$i] eq $object) {
3362 #print "Found signal: $SignalNames[$i]\n";
3363 my $name = $SignalNames[$i];
3364 my $symbol = "${object}::${name}";
3365 my $id = &CreateValidSGMLID ("$object-$name");
3367 my $pad = ' ' x (46 - length($name));
3368 $synop .= " "<link linkend=\"$id\">$name</link>"$pad ";
3370 $desc .= "<refsect2 id=\"$id\" role=\"signal\"><title>The <literal>"$name"</literal> signal</title>\n";
3371 $desc .= MakeIndexterms($symbol, $id);
3373 $desc .= OutputSymbolExtraLinks($symbol);
3375 $desc .= "<programlisting>";
3377 $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
3378 my $type_modifier = defined($1) ? $1 : "";
3381 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
3383 my $ret_type_len = length ($type_modifier) + length ($pointer)
3385 my $ret_type_output = "$type_modifier$xref$pointer"
3386 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
3388 $desc .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
3390 my $sourceparams = $SourceSymbolParams{$symbol};
3391 my @params = split ("\n", $SignalPrototypes[$i]);
3394 my $type_len = length("gpointer");
3395 my $name_len = length("user_data");
3396 # do two passes, the first one is to calculate padding
3397 for ($l = 0; $l < 2; $l++) {
3398 for ($j = 0; $j <= $#params; $j++) {
3399 # allow alphanumerics, '_', '[' & ']' in param names
3400 if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
3403 if (defined($sourceparams)) {
3404 $name = $$sourceparams[$PARAM_FIELD_COUNT * $j];
3409 if (!defined($name)) {
3413 if (length($type) + length($pointer) > $type_len) {
3414 $type_len = length($type) + length($pointer);
3416 if (length($name) > $name_len) {
3417 $name_len = length($name);
3421 $xref = &MakeXRef ($type, &tagify($type, "type"));
3422 $pad = ' ' x ($type_len - length($type) - length($pointer));
3423 $desc .= "$xref$pad $pointer$name,\n";
3424 $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
3427 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3428 "Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]");
3432 $xref = &MakeXRef ("gpointer", &tagify("gpointer", "type"));
3433 $pad = ' ' x ($type_len - length("gpointer"));
3434 $desc .= "$xref$pad user_data)";
3436 my $flags = $SignalFlags[$i];
3437 my $flags_string = "";
3439 if (defined ($flags)) {
3440 if ($flags =~ m/f/) {
3441 $flags_string = "<link linkend=\"G-SIGNAL-RUN-FIRST:CAPS\"><literal>Run First</literal></link>";
3443 elsif ($flags =~ m/l/) {
3444 $flags_string = "<link linkend=\"G-SIGNAL-RUN-LAST:CAPS\"><literal>Run Last</literal></link>";
3446 elsif ($flags =~ m/c/) {
3447 $flags_string = "<link linkend=\"G-SIGNAL-RUN-CLEANUP:CAPS\"><literal>Cleanup</literal></link>";
3448 $flags_string = "Cleanup";
3450 if ($flags =~ m/r/) {
3451 if ($flags_string) { $flags_string .= " / "; }
3452 $flags_string = "<link linkend=\"G-SIGNAL-NO-RECURSE:CAPS\"><literal>No Recursion</literal></link>";
3454 if ($flags =~ m/d/) {
3455 if ($flags_string) { $flags_string .= " / "; }
3456 $flags_string = "<link linkend=\"G-SIGNAL-DETAILED:CAPS\"><literal>Has Details</literal></link>";
3458 if ($flags =~ m/a/) {
3459 if ($flags_string) { $flags_string .= " / "; }
3460 $flags_string = "<link linkend=\"G-SIGNAL-ACTION:CAPS\"><literal>Action</literal></link>";
3462 if ($flags =~ m/h/) {
3463 if ($flags_string) { $flags_string .= " / "; }
3464 $flags_string = "<link linkend=\"G-SIGNAL-NO-HOOKS:CAPS\"><literal>No Hooks</literal></link>";
3470 $synop .= ": $flags_string\n";
3472 $pad = ' ' x (5 + $name_len - length("user_data"));
3473 $desc .= "$pad : $flags_string</programlisting>\n";
3478 $desc .= "</programlisting>\n";
3481 $desc .= &MakeDeprecationNote($symbol);
3483 my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
3484 my $parameters_output = 0;
3486 $AllSymbols{$symbol} = 1;
3487 if (defined ($SymbolDocs{$symbol})) {
3488 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3490 # Try to insert the parameter table at the author's desired
3491 # position. Otherwise we need to tag it onto the end.
3492 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
3493 $parameters_output = 1;
3495 $desc .= $symbol_docs;
3497 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
3498 $AllDocumentedSymbols{$symbol} = 1;
3502 if ($parameters_output == 0) {
3503 $desc .= $parameters;
3505 $desc .= OutputSymbolTraits ($symbol);
3506 $desc .= "</refsect2>";
3509 return ($synop, $desc);
3513 #############################################################################
3514 # Function : GetArgs
3515 # Description : Returns the synopsis and detailed description DocBook output
3516 # for the Args of a given GtkObject subclass.
3517 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
3518 #############################################################################
3524 my $child_synop = "";
3525 my $child_desc = "";
3526 my $style_synop = "";
3527 my $style_desc = "";
3530 for ($i = 0; $i <= $#ArgObjects; $i++) {
3531 if ($ArgObjects[$i] eq $object) {
3532 #print "Found arg: $ArgNames[$i]\n";
3533 my $name = $ArgNames[$i];
3534 my $flags = $ArgFlags[$i];
3535 my $flags_string = "";
3539 if ($flags =~ m/c/) {
3540 $kind = "child property";
3543 elsif ($flags =~ m/s/) {
3544 $kind = "style property";
3551 # Remember only one colon so we don't clash with signals.
3552 my $symbol = "${object}:${name}";
3553 # use two dashes and ev. an extra separator here for the same reason.
3554 my $id = &CreateValidSGMLID ("$object--$id_sep$name");
3556 my $type = $ArgTypes[$i];
3558 my $range = $ArgRanges[$i];
3559 my $range_output = CreateValidSGML ($range);
3560 my $default = $ArgDefaults[$i];
3561 my $default_output = CreateValidSGML ($default);
3563 if ($type eq "GtkString") {
3566 if ($type eq "GtkSignal") {
3567 $type = "GtkSignalFunc, gpointer";
3568 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
3569 . &MakeXRef ("gpointer");
3570 } elsif ($type =~ m/^(\w+)\*$/) {
3571 $type_output = &MakeXRef ($1, &tagify($1, "type")) . "*";
3573 $type_output = &MakeXRef ($type, &tagify($type, "type"));
3576 if ($flags =~ m/r/) {
3577 $flags_string = "Read";
3579 if ($flags =~ m/w/) {
3580 if ($flags_string) { $flags_string .= " / "; }
3581 $flags_string .= "Write";
3583 if ($flags =~ m/x/) {
3584 if ($flags_string) { $flags_string .= " / "; }
3585 $flags_string .= "Construct";
3587 if ($flags =~ m/X/) {
3588 if ($flags_string) { $flags_string .= " / "; }
3589 $flags_string .= "Construct Only";
3592 $AllSymbols{$symbol} = 1;
3594 if (defined($SymbolDocs{$symbol}) &&
3595 !IsEmptyDoc($SymbolDocs{$symbol})) {
3596 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3597 #print ".. [$SymbolDocs{$symbol}][$blurb]\n";
3598 $AllDocumentedSymbols{$symbol} = 1;
3601 if (!($ArgBlurbs[$i] eq "")) {
3602 $AllDocumentedSymbols{$symbol} = 1;
3604 # FIXME: print a warning?
3605 #print ".. no description\n";
3607 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
3610 my $pad1 = " " x (24 - length ($name));
3611 my $pad2 = " " x (20 - length ($type));
3613 my $arg_synop = " "<link linkend=\"$id\">$name</link>"$pad1 $type_output $pad2 : $flags_string\n";
3614 my $arg_desc = "<refsect2 id=\"$id\" role=\"property\"><title>The <literal>"$name"</literal> $kind</title>\n";
3615 $arg_desc .= MakeIndexterms($symbol, $id);
3617 $arg_desc .= OutputSymbolExtraLinks($symbol);
3619 $arg_desc .= "<programlisting> "$name"$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
3620 $arg_desc .= &MakeDeprecationNote($symbol);
3621 $arg_desc .= $blurb;
3623 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
3625 if ($default ne "") {
3626 $arg_desc .= "<para>Default value: $default_output</para>\n";
3628 $arg_desc .= OutputSymbolTraits ($symbol);
3629 $arg_desc .= "</refsect2>\n";
3631 if ($flags =~ m/c/) {
3632 $child_synop .= $arg_synop;
3633 $child_desc .= $arg_desc;
3635 elsif ($flags =~ m/s/) {
3636 $style_synop .= $arg_synop;
3637 $style_desc .= $arg_desc;
3640 $synop .= $arg_synop;
3645 return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
3649 #############################################################################
3650 # Function : ReadSourceDocumentation
3651 # Description : This reads in the documentation embedded in comment blocks
3652 # in the source code (for Gnome).
3654 # Parameter descriptions override any in the template files.
3655 # Function descriptions are placed before any description from
3656 # the template files.
3658 # It recursively descends the source directory looking for .c
3659 # files and scans them looking for specially-formatted comment
3662 # Arguments : $source_dir - the directory to scan.
3663 #############m###############################################################
3665 sub ReadSourceDocumentation {
3666 my ($source_dir) = @_;
3667 my ($file, $dir, @suffix_list, $suffix);
3669 # prepend entries from @SOURCE_DIR
3670 for my $dir (@SOURCE_DIRS) {
3671 # Check if the filename is in the ignore list.
3672 if ($source_dir =~ m%^\Q$dir\E/(.*)$% and $IGNORE_FILES =~ m/(\s|^)\Q$1\E(\s|$)/) {
3673 @TRACE@("Skipping source directory: $source_dir");
3678 @TRACE@("Scanning source directory: $source_dir");
3680 # This array holds any subdirectories found.
3683 @suffix_list = split (/,/, $SOURCE_SUFFIXES);
3685 opendir (SRCDIR, $source_dir)
3686 || die "Can't open source directory $source_dir: $!";
3688 foreach $file (readdir (SRCDIR)) {
3689 if ($file =~ /^\./) {
3691 } elsif (-d "$source_dir/$file") {
3692 push (@subdirs, $file);
3693 } elsif (@suffix_list) {
3694 foreach $suffix (@suffix_list) {
3695 if ($file =~ m/\.\Q${suffix}\E$/) {
3696 &ScanSourceFile ("$source_dir/$file");
3699 } elsif ($file =~ m/\.[ch]$/) {
3700 &ScanSourceFile ("$source_dir/$file");
3705 # Now recursively scan the subdirectories.
3706 foreach $dir (@subdirs) {
3707 &ReadSourceDocumentation ("$source_dir/$dir");
3712 #############################################################################
3713 # Function : ScanSourceFile
3714 # Description : Scans one source file looking for specially-formatted comment
3715 # blocks. Later &MergeSourceDocumentation is used to merge any
3716 # documentation found with the documentation already read in
3717 # from the template files.
3719 # Arguments : $file - the file to scan.
3720 #############################################################################
3722 sub ScanSourceFile {
3726 # prepend entries from @SOURCE_DIR
3727 for my $dir (@SOURCE_DIRS) {
3728 # Check if the filename is in the ignore list.
3729 if ($file =~ m%^\Q$dir\E/(.*)$% and $IGNORE_FILES =~ m/(\s|^)\Q$1\E(\s|$)/) {
3730 @TRACE@("Skipping source file: $file");
3735 if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
3738 &LogWarning ($file, 1, "Can't find basename for this filename.");
3742 # Check if the basename is in the list of files to ignore.
3743 if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
3744 @TRACE@("Skipping source file: $file");
3748 @TRACE@("Scanning source file: $file");
3750 open (SRCFILE, $file)
3751 || die "Can't open $file: $!";
3752 my $in_comment_block = 0;
3755 my ($description, $return_desc, $return_start, $return_style);
3756 my ($since_desc, $stability_desc, $deprecated_desc);
3758 my $ignore_broken_returns;
3761 # Look for the start of a comment block.
3762 if (!$in_comment_block) {
3763 if (m%^\s*/\*.*\*/%) {
3764 #one-line comment - not gtkdoc
3765 } elsif (m%^\s*/\*\*\s%) {
3766 #print "Found comment block start\n";
3768 $in_comment_block = 1;
3770 # Reset all the symbol data.
3777 $deprecated_desc = "";
3778 $stability_desc = "";
3779 $current_param = -1;
3780 $ignore_broken_returns = 0;
3786 # We're in a comment block. Check if we've found the end of it.
3789 # maybe its not even meant to be a gtk-doc comment?
3790 &LogWarning ($file, $., "Symbol name not found at the start of the comment block.");
3792 # Add the return value description onto the end of the params.
3794 push (@params, "Returns");
3795 push (@params, $return_desc);
3796 if ($return_style eq 'broken') {
3797 &LogWarning ($file, $., "Free-form return value description in $symbol. Use `Returns:' to avoid ambiguities.");
3800 # Convert special SGML characters
3801 $description = &ConvertSGMLChars ($symbol, $description);
3803 for ($k = 1; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3804 $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
3807 # Handle Section docs
3808 if ($symbol =~ m/SECTION:\s*(.*)/) {
3812 if (scalar %KnownSymbols) {
3813 if ((! defined($KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"})) || $KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"} != 1) {
3814 &LogWarning ($file, $., "Section $real_symbol is not defined in the $MODULE-sections.txt file.");
3818 #print "SECTION DOCS found in source for : '$real_symbol'\n";
3819 $ignore_broken_returns = 1;
3820 for ($k = 0; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3821 #print " '".$params[$k]."'\n";
3822 $params[$k] = "\L$params[$k]";
3824 if ($params[$k] eq "short_description") {
3825 $key = "$TMPL_DIR/$real_symbol:Short_Description";
3826 } elsif ($params[$k] eq "see_also") {
3827 $key = "$TMPL_DIR/$real_symbol:See_Also";
3828 } elsif ($params[$k] eq "title") {
3829 $key = "$TMPL_DIR/$real_symbol:Title";
3830 } elsif ($params[$k] eq "stability") {
3831 $key = "$TMPL_DIR/$real_symbol:Stability_Level";
3832 } elsif ($params[$k] eq "section_id") {
3833 $key = "$TMPL_DIR/$real_symbol:Section_Id";
3834 } elsif ($params[$k] eq "include") {
3835 $key = "$TMPL_DIR/$real_symbol:Include";
3836 } elsif ($params[$k] eq "image") {
3837 $key = "$TMPL_DIR/$real_symbol:Image";
3839 if (defined($key)) {
3840 $SourceSymbolDocs{$key}=$params[$k+1];
3841 $SourceSymbolSourceFile{$key} = $file;
3842 $SourceSymbolSourceLine{$key} = $.;
3845 $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
3846 $SourceSymbolSourceFile{"$TMPL_DIR/$real_symbol:Long_Description"} = $file;
3847 $SourceSymbolSourceLine{"$TMPL_DIR/$real_symbol:Long_Description"} = $.;
3848 #$SourceSymbolTypes{$symbol} = "SECTION";
3850 #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
3851 $SourceSymbolDocs{$symbol} = $description;
3852 $SourceSymbolParams{$symbol} = [ @params ];
3853 # FIXME $SourceSymbolTypes{$symbol} = "STRUCT,SIGNAL,ARG,FUNCTION,MACRO";
3854 #if (defined $DeclarationTypes{$symbol}) {
3855 # $SourceSymbolTypes{$symbol} = $DeclarationTypes{$symbol}
3857 $SourceSymbolSourceFile{$symbol} = $file;
3858 $SourceSymbolSourceLine{$symbol} = $.;
3862 ($since_desc, my @extra_lines) = split ("\n", $since_desc);
3863 $since_desc =~ s/^\s+//;
3864 $since_desc =~ s/\s+$//;
3865 #print "Since($symbol) : [$since_desc]\n";
3866 $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
3867 if(scalar @extra_lines) {
3868 &LogWarning ($file, $., "multi-line since docs found");
3872 if ($stability_desc) {
3873 $stability_desc = &ParseStabilityLevel($stability_desc, $file, $., "Stability level for $symbol");
3874 $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
3877 if ($deprecated_desc) {
3878 if (exists $Deprecated{$symbol}) {
3881 # don't warn for signals and properties
3882 #if ($symbol !~ m/::?(.*)/) {
3883 if (defined $DeclarationTypes{$symbol}) {
3884 &LogWarning ($file, $.,
3885 "$symbol is deprecated in the inline comments, but no deprecation guards were found around the declaration.".
3886 " (See the --deprecated-guards option for gtkdoc-scan.)");
3889 $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
3893 $in_comment_block = 0;
3897 # Get rid of ' * ' at start of every line in the comment block.
3899 # But make sure we don't get rid of the newline at the end.
3903 #print "DEBUG: scanning :$_";
3905 # If we haven't found the symbol name yet, look for it.
3907 if (m%^\s*(SECTION:\s*\S+)%) {
3909 #print "SECTION DOCS found in source for : '$symbol'\n";
3910 $ignore_broken_returns = 1;
3911 } elsif (m%^\s*([\w:-]*\w)\s*:?\s*(\([a-z ]+\)\s*)*$%) {
3913 #print "SYMBOL DOCS found in source for : '$symbol'\n";
3918 if ($in_part eq "description") {
3919 # Get rid of 'Description:'
3920 s%^\s*Description:%%;
3923 if (m/^\s*(returns:|return\s+value:)/i) {
3924 if ($return_style eq 'broken') {
3925 $description .= $return_start . $return_desc;
3928 if ($return_style eq 'sane') {
3929 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3931 $return_style = 'sane';
3932 $ignore_broken_returns = 1;
3934 $in_part = "return";
3936 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3938 $return_style = 'broken';
3940 $in_part = "return";
3942 } elsif (m%^\s*since:%i) {
3943 # we're in param section and have not seen the blank line
3944 if($in_part ne "") {
3949 } elsif (m%^\s*deprecated:%i) {
3950 # we're in param section and have not seen the blank line
3951 if($in_part ne "") {
3952 $deprecated_desc = $';
3953 $in_part = "deprecated";
3956 } elsif (m%^\s*stability:%i) {
3957 $stability_desc = $';
3958 $in_part = "stability";
3962 if ($in_part eq "description") {
3965 } elsif ($in_part eq "return") {
3968 } elsif ($in_part eq "since") {
3971 } elsif ($in_part eq "stability") {
3972 $stability_desc .= $_;
3974 } elsif ($in_part eq "deprecated") {
3975 $deprecated_desc .= $_;
3979 # We must be in the parameters. Check for the empty line below them.
3981 $in_part = "description";
3985 # Look for a parameter name.
3986 if (m%^\s*@(\S+)\s*:\s*%) {
3987 my $param_name = $1;
3988 my $param_desc = $';
3990 #print "Found parameter: $param_name\n";
3991 # Allow varargs variations
3992 if ($param_name =~ m/^.*\.\.\.$/) {
3993 $param_name = "...";
3995 if ("\L$param_name" eq "returns") {
3996 $return_style = 'sane';
3997 $ignore_broken_returns = 1;
3999 @TRACE@("Found param for symbol $symbol : '$param_name'= '$_'");
4001 push (@params, $param_name);
4002 push (@params, $param_desc);
4003 $current_param += $PARAM_FIELD_COUNT;
4007 # We must be in the middle of a parameter description, so add it on
4008 # to the last element in @params.
4009 if ($current_param == -1) {
4010 &LogWarning ($file, $., "Parsing comment block file : parameter expected.");
4012 $params[$#params] .= $_;
4018 #############################################################################
4019 # Function : OutputMissingDocumentation
4020 # Description : Outputs report of documentation coverage to a file
4023 #############################################################################
4025 sub OutputMissingDocumentation {
4026 my $old_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.txt";
4027 my $new_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.new";
4029 my $n_documented = 0;
4030 my $n_incomplete = 0;
4036 my $buffer_deprecated = "";
4037 my $buffer_descriptions = "";
4039 open(UNDOCUMENTED, ">$new_undocumented_file")
4040 || die "Can't create $new_undocumented_file";
4042 foreach $symbol (sort (keys (%AllSymbols))) {
4043 # FIXME: should we print LogWarnings for undocumented stuff?
4045 #my $ssfile = &GetSymbolSourceFile($symbol);
4046 #my $ssline = &GetSymbolSourceLine($symbol);
4047 #my $location = "defined at " . (defined($ssfile)?$ssfile:"?") . ":" . (defined($ssline)?$ssline:"0") . "\n";
4049 if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include|Section_Id|Image)/) {
4051 if (exists ($AllDocumentedSymbols{$symbol})) {
4053 if (exists ($AllIncompleteSymbols{$symbol})) {
4055 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4056 #$buffer .= "\t0: ".$location;
4058 } elsif (exists $Deprecated{$symbol}) {
4059 if (exists ($AllIncompleteSymbols{$symbol})) {
4061 $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4062 #$buffer .= "\t1a: ".$location;
4064 $buffer_deprecated .= $symbol . "\n";
4065 #$buffer .= "\t1b: ".$location;
4068 if (exists ($AllIncompleteSymbols{$symbol})) {
4070 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4071 #$buffer .= "\t2a: ".$location;
4073 $buffer .= $symbol . "\n";
4074 #$buffer .= "\t2b: ".$location;
4077 } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
4079 #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
4080 #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
4081 #print "%%%% $symbol : $len1,$len2\n";
4082 if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
4083 || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
4086 # cut off the leading namespace ($TMPL_DIR)
4087 $symbol =~ m/^.*\/(.*)$/;
4088 $buffer_descriptions .= $1 . "\n";
4093 $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
4098 $percent = ($n_documented / $total) * 100.0;
4101 printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
4102 print UNDOCUMENTED "$n_documented symbols documented.\n";
4103 print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
4104 print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
4106 print UNDOCUMENTED $buffer;
4107 close (UNDOCUMENTED);
4109 return &UpdateFileIfChanged ($old_undocumented_file, $new_undocumented_file, 0);
4111 printf "%.0f%% symbol docs coverage", $percent;
4112 print "($n_documented symbols documented, $n_incomplete symbols incomplete, " . ($total - $n_documented) . " not documented)\n";
4113 print "See $MODULE-undocumented.txt for a list of missing docs.\nThe doc coverage percentage doesn't include intro sections.\n";
4117 #############################################################################
4118 # Function : OutputUndeclaredSymbols
4119 # Description : Outputs symbols that are listed in the section file, but not
4120 # declaration is found in the sources
4123 #############################################################################
4125 sub OutputUndeclaredSymbols {
4126 my $old_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.txt";
4127 my $new_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.new";
4129 open(UNDECLARED, ">$new_undeclared_file")
4130 || die "Can't create $new_undeclared_file";
4132 if (%UndeclaredSymbols) {
4133 print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
4134 print UNDECLARED "\n";
4135 print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
4139 return &UpdateFileIfChanged ($old_undeclared_file, $new_undeclared_file, 0);
4142 #############################################################################
4143 # Function : OutputUnusedSymbols
4144 # Description : Outputs symbols that are documented in comments, but not
4145 # declared in the sources
4148 #############################################################################
4150 sub OutputUnusedSymbols {
4152 my $old_unused_file = "$ROOT_DIR/$MODULE-unused.txt";
4153 my $new_unused_file = "$ROOT_DIR/$MODULE-unused.new";
4155 open (UNUSED, ">$new_unused_file")
4156 || die "Can't open $new_unused_file";
4158 foreach $symbol (sort keys (%Declarations)) {
4159 if (!defined ($DeclarationOutput{$symbol})) {
4160 print (UNUSED "$symbol\n");
4164 foreach $symbol (sort (keys (%AllUnusedSymbols))) {
4165 print (UNUSED "$symbol(" . $AllUnusedSymbols{$symbol} . ")\n");
4169 if ($num_unused != 0) {
4170 &LogWarning ($old_unused_file, 1, "$num_unused unused declarations.".
4171 "They should be added to $MODULE-sections.txt in the appropriate place.");
4174 return &UpdateFileIfChanged ($old_unused_file, $new_unused_file, 0);
4178 #############################################################################
4179 # Function : OutputAllSymbols
4180 # Description : Outputs list of all symbols to a file
4183 #############################################################################
4185 sub OutputAllSymbols {
4186 my $n_documented = 0;
4192 open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
4193 || die "Can't create $ROOT_DIR/$MODULE-symbols.txt: $!";
4195 foreach $symbol (sort (keys (%AllSymbols))) {
4196 print SYMBOLS $symbol . "\n";
4202 #############################################################################
4203 # Function : OutputSymbolsWithoutSince
4204 # Description : Outputs list of all symbols without a since tag to a file
4207 #############################################################################
4209 sub OutputSymbolsWithoutSince {
4210 my $n_documented = 0;
4216 open (SYMBOLS, ">$ROOT_DIR/$MODULE-nosince.txt")
4217 || die "Can't create $ROOT_DIR/$MODULE-nosince.txt: $!";
4219 foreach $symbol (sort (keys (%SourceSymbolDocs))) {
4220 if (!defined $Since{$symbol}) {
4221 print SYMBOLS $symbol . "\n";
4229 #############################################################################
4230 # Function : MergeSourceDocumentation
4231 # Description : This merges documentation read from a source file into the
4232 # documentation read in from a template file.
4234 # Parameter descriptions override any in the template files.
4235 # Function descriptions are placed before any description from
4236 # the template files.
4239 #############################################################################
4241 sub MergeSourceDocumentation {
4245 if (scalar %SymbolDocs) {
4246 @Symbols=keys (%SymbolDocs);
4247 #print "num existing entries: ".(scalar @Symbols)."\n";
4248 #print " ",$Symbols[0], " ",$Symbols[1],"\n";
4251 # filter scanned declarations, with what we suppress from -sections.txt
4253 foreach $symbol (keys (%Declarations)) {
4254 if (defined($KnownSymbols{$symbol}) && $KnownSymbols{$symbol} == 1) {
4258 # , add the rest from -sections.txt
4259 foreach $symbol (keys (%KnownSymbols)) {
4260 if ($KnownSymbols{$symbol} == 1) {
4264 # and add whats found in the source
4265 foreach $symbol (keys (%SourceSymbolDocs)) {
4268 @Symbols = keys (%tmp);
4269 #print "num source entries: ".(scalar @Symbols)."\n";
4271 foreach $symbol (@Symbols) {
4272 $AllSymbols{$symbol} = 1;
4274 my $have_tmpl_docs = 0;
4276 ## see if the symbol is documented in template
4277 my $tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4278 my $check_tmpl_doc =$tmpl_doc;
4279 # remove all xml-tags and whitespaces
4280 $check_tmpl_doc =~ s/<.*?>//g;
4281 $check_tmpl_doc =~ s/\s//g;
4283 if ($check_tmpl_doc ne "") {
4284 $have_tmpl_docs = 1;
4285 #print "## [$check_tmpl_doc]\n";
4287 # if the docs have just an empty para, don't merge that.
4288 $check_tmpl_doc = $tmpl_doc;
4289 $check_tmpl_doc =~ s/(\s|\n)//msg;
4290 if ($check_tmpl_doc eq "<para></para>") {
4295 if (exists ($SourceSymbolDocs{$symbol})) {
4296 my $type = $DeclarationTypes {$symbol};
4298 #print "merging [$symbol] from source\n";
4300 my $item = "Parameter";
4301 if (defined ($type)) {
4302 if ($type eq 'STRUCT') {
4304 } elsif ($type eq 'ENUM') {
4306 } elsif ($type eq 'UNION') {
4313 my $src_doc = $SourceSymbolDocs{$symbol};
4314 # remove leading and training whitespaces
4315 $src_doc =~ s/^\s+//;
4316 $src_doc =~ s/\s+$//;
4318 # Don't output warnings for overridden titles as titles are
4319 # automatically generated in the -sections.txt file, and thus they
4320 # are often overridden.
4321 if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
4322 # check if content is different
4323 if ($tmpl_doc ne $src_doc) {
4324 #print "[$tmpl_doc] [$src_doc]\n";
4325 &LogWarning ($SourceSymbolSourceFile{$symbol}, $SourceSymbolSourceLine{$symbol},
4326 "Documentation in template ".$SymbolSourceFile{$symbol}.":".$SymbolSourceLine{$symbol}." for $symbol being overridden by inline comments.");
4330 if ($src_doc ne "") {
4331 $AllDocumentedSymbols{$symbol} = 1;
4334 # Convert <!--PARAMETERS--> with any blank lines around it to
4335 # a </para> followed by <!--PARAMETERS--> followed by <para>.
4336 $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
4338 # Do not add <para> to nothing, it breaks missing docs checks.
4339 my $src_doc_para = "";
4340 if ($src_doc ne "") {
4341 # Expand markdown (and do paragraphs)
4342 $src_doc_para = &ConvertMarkDown ($src_doc, $symbol);
4344 # FIXME: this is questionable, as we can't make assumtions on the content really
4345 #$src_doc_para =~ s%^<para>\n(<refsect[1-9])%$1%gms;
4346 #$src_doc_para =~ s%^<para>\n<para>%<para>%gms;
4347 #$src_doc_para =~ s%(</refsect[1-9]>)\n</para>$%$1%gms;
4348 #print "$symbol : [$src_doc][$src_doc_para]\n";
4351 if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
4352 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4353 } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
4354 # For the title/summary/see also section docs we don't want to
4355 # add any <para> tags.
4356 $SymbolDocs{$symbol} = "$src_doc"
4358 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4362 if ($symbol =~ m/.*::.*/) {
4363 # For signals we prefer the param names from the source docs,
4364 # since the ones from the templates are likely to contain the
4365 # artificial argn names which are generated by gtkdoc-scangobj.
4366 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4367 # FIXME: we need to check for empty docs here as well!
4369 # The templates contain the definitive parameter names and order,
4370 # so we will not change that. We only override the actual text.
4371 my $tmpl_params = $SymbolParams{$symbol};
4372 if (!defined ($tmpl_params)) {
4373 #print "No merge needed for $symbol\n";
4374 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4375 # FIXME: we still like to get the number of params and merge
4376 # 1) we would noticed that params have been removed/renamed
4377 # 2) we would catch undocumented params
4378 # params are not (yet) exported in -decl.txt so that we
4379 # could easily grab them :/
4381 my $params = $SourceSymbolParams{$symbol};
4383 #print "Merge needed for $symbol, tmpl_params: ",$#$tmpl_params,", source_params: ",$#$params," \n";
4384 for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4385 my $tmpl_param_name = $$tmpl_params[$j];
4387 # Try to find the param in the source comment documentation.
4390 #print " try merge param $tmpl_param_name\n";
4391 for ($k = 0; $k <= $#$params; $k += $PARAM_FIELD_COUNT) {
4392 my $param_name = $$params[$k];
4393 my $param_desc = $$params[$k + 1];
4395 #print " test param $param_name\n";
4396 # We accept changes in case, since the Gnome source
4397 # docs contain a lot of these.
4398 if ("\L$param_name" eq "\L$tmpl_param_name") {
4401 # Override the description.
4402 $$tmpl_params[$j + 1] = $param_desc;
4404 # Set the name to "" to mark it as used.
4410 # If it looks like the parameters are there, but not
4411 # in the right place, try to explain a bit better.
4412 if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
4413 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4414 "Parameters for $symbol must start on the line immediately after the function or macro name.");
4418 # Now we output a warning if parameters have been described which
4420 for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
4421 my $param_name = $$params[$j];
4423 # the template builder cannot detect if a macro returns
4425 if(($type eq "MACRO") && ($param_name eq "Returns")) {
4426 # FIXME: do we need to add it then to tmpl_params[] ?
4427 my $num=$#$tmpl_params;
4428 #print " adding Returns: to macro docs for $symbol.\n";
4429 $$tmpl_params[$num+1]="Returns";
4430 $$tmpl_params[$num+2]=$$params[$j+1];
4433 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4434 "$item described in source code comment block but does not exist. $type: $symbol $item: $param_name.");
4440 if ($have_tmpl_docs) {
4441 $AllDocumentedSymbols{$symbol} = 1;
4442 #print "merging [$symbol] from template\n";
4445 #print "[$symbol] undocumented\n";
4449 # if this symbol is documented, check if docs are complete
4450 $check_tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4451 # remove all xml-tags and whitespaces
4452 $check_tmpl_doc =~ s/<.*?>//g;
4453 $check_tmpl_doc =~ s/\s//g;
4454 if ($check_tmpl_doc ne "") {
4455 my $tmpl_params = $SymbolParams{$symbol};
4456 if (defined ($tmpl_params)) {
4457 my $type = $DeclarationTypes {$symbol};
4459 my $item = "Parameter";
4460 if (defined ($type)) {
4461 if ($type eq 'STRUCT') {
4463 } elsif ($type eq 'ENUM') {
4465 } elsif ($type eq 'UNION') {
4472 #print "Check param docs for $symbol, tmpl_params: ",$#$tmpl_params," entries, type=$type\n";
4474 if ($#$tmpl_params > 0) {
4476 for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4477 # Output a warning if the parameter is empty and
4478 # remember for stats.
4479 my $tmpl_param_name = $$tmpl_params[$j];
4480 my $tmpl_param_desc = $$tmpl_params[$j + 1];
4481 if ($tmpl_param_name ne "void" && $tmpl_param_desc !~ m/\S/) {
4482 if (exists ($AllIncompleteSymbols{$symbol})) {
4483 $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
4485 $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
4487 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4488 "$item description for $symbol"."::"."$tmpl_param_name is missing in source code comment block.");
4493 if ($#$tmpl_params == 0) {
4494 $AllIncompleteSymbols{$symbol}="<items>";
4495 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4496 "$item descriptions for $symbol are missing in source code comment block.");
4498 # $#$tmpl_params==-1 means we don't know about parameters
4499 # this unfortunately does not tell if there should be some
4504 #print "num doc entries: ".(scalar %SymbolDocs)."\n";
4507 #############################################################################
4508 # Function : IsEmptyDoc
4509 # Description : Check if a doc-string is empty. Its also regarded as empty if
4510 # it only consist of whitespace or e.g. FIXME.
4511 # Arguments : the doc-string
4512 #############################################################################
4516 if ($doc =~ /^\s*$/) {
4520 if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
4528 #############################################################################
4529 # Function : ConvertMarkDown
4530 # Description : Converts mark down syntax to the respective docbook, but only
4531 # outside CDATA and <programlisting> tags.
4532 # http://de.wikipedia.org/wiki/Markdown
4533 # Code snippets have been takesn from
4534 # http://daringfireball.net/projects/markdown/
4535 # Copyright (c) 2004 John Gruber
4536 # Arguments : the doc-string, the symbol name
4537 #############################################################################
4539 sub ConvertMarkDown {
4540 my ($text, $symbol) = @_;
4546 $text = &ModifyXMLElements ($text, $symbol,
4547 "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
4548 \&ConvertMarkDownEndTag,
4549 \&ConvertMarkDownCallback);
4550 # encapsulate and terminate
4551 $text = "<para>\n$text\n</para>";
4552 if ($md_in_refsect2==1) {
4553 $text = "$text</refsect2>"
4558 sub ConvertMarkDownEndTag {
4559 if ($_[0] eq "<!\[CDATA\[") {
4561 } elsif ($_[0] eq "|[") {
4564 return "</programlisting>";
4568 sub ConvertMarkDownCallback {
4569 my ($text, $symbol, $tag) = @_;
4571 # If we're not in CDATA or a <programlisting> we convert blank lines so
4572 # they start a new <para>.
4575 my $end_of_section="";
4578 $end_of_para = "$end_of_para</para>";
4579 $end_of_section = "$end_of_section</para>";
4580 if ($md_in_refsect2==1) {
4581 $end_of_section= "$end_of_section</refsect2>";
4584 # Setext-style headers:
4591 if($text =~ s%^\n(.+)[ \t]*\n=+[ \t]*\n\n%$end_of_section<refsect2><title>$1</title><para>\n%gm) {
4595 # atx-style headers:
4598 # ## Header 2 with closing hashes ##
4602 if($text =~ s%^\n\#[ \t]*(.+?)[ \t]*\#\n+%$end_of_section<refsect2><title>$1</title><para>\n%gm) {
4606 # Simple (unnested) lists:
4609 # - item 2 with loooong
4614 $text.="\n"; # we need a new line to avoid too complicated matching rules below
4615 if ($text =~ s%(?<=\n)-\s+(.+?)(?=(?:\n-\s+)|(?:\n\n)|(?:\n$))%<listitem><para>$1</para></listitem>%gs) {
4616 $text =~ s%(?<!</listitem>)(\n<listitem>)%\n<itemizedlist>$1%g;
4617 $text =~ s%(</listitem>\n)(?!<listitem>)%$1</itemizedlist>\n%g;
4621 # Make Paragraphs on blank lines
4622 $text =~ s%\n{2,}%\n$end_of_para\n<para>\n%g;
4629 #############################################################################
4630 # LIBRARY FUNCTIONS - These functions are used in both gtkdoc-mkdb and
4631 # gtkdoc-mktmpl and should eventually be moved to a
4633 #############################################################################
4635 #############################################################################
4636 # Function : ReadDeclarationsFile
4637 # Description : This reads in a file containing the function/macro/enum etc.
4640 # Note that in some cases there are several declarations with
4641 # the same name, e.g. for conditional macros. In this case we
4642 # set a flag in the %DeclarationConditional hash so the
4643 # declaration is not shown in the docs.
4645 # If a macro and a function have the same name, e.g. for
4646 # gtk_object_ref, the function declaration takes precedence.
4648 # Some opaque structs are just declared with 'typedef struct
4649 # _name name;' in which case the declaration may be empty.
4650 # The structure may have been found later in the header, so
4651 # that overrides the empty declaration.
4653 # Arguments : $file - the declarations file to read
4654 # $override - if declarations in this file should override
4655 # any current declaration.
4656 #############################################################################
4658 sub ReadDeclarationsFile {
4659 my ($file, $override) = @_;
4661 if ($override == 0) {
4663 %DeclarationTypes = ();
4664 %DeclarationConditional = ();
4665 %DeclarationOutput = ();
4669 || die "Can't open $file: $!";
4670 my $declaration_type = "";
4671 my $declaration_name;
4673 my $is_deprecated = 0;
4675 if (!$declaration_type) {
4676 if (m/^<([^>]+)>/) {
4677 $declaration_type = $1;
4678 $declaration_name = "";
4679 #print "Found declaration: $declaration_type\n";
4683 if (m%^<NAME>(.*)</NAME>%) {
4684 $declaration_name = $1;
4685 } elsif (m%^<DEPRECATED/>%) {
4687 } elsif (m%^</$declaration_type>%) {
4688 #print "Found end of declaration: $declaration_name\n";
4689 # Check that the declaration has a name
4690 if ($declaration_name eq "") {
4691 print "ERROR: $declaration_type has no name $file:$.\n";
4694 # If the declaration is an empty typedef struct _XXX XXX
4695 # set the flag to indicate the struct has a typedef.
4696 if ($declaration_type eq 'STRUCT'
4697 && $declaration =~ m/^\s*$/) {
4698 #print "Struct has typedef: $declaration_name\n";
4699 $StructHasTypedef{$declaration_name} = 1;
4702 # Check if the symbol is already defined.
4703 if (defined ($Declarations{$declaration_name})
4704 && $override == 0) {
4705 # Function declarations take precedence.
4706 if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
4708 } elsif ($declaration_type eq 'FUNCTION') {
4709 if ($is_deprecated) {
4710 $Deprecated{$declaration_name} = "";
4712 $Declarations{$declaration_name} = $declaration;
4713 $DeclarationTypes{$declaration_name} = $declaration_type;
4714 } elsif ($DeclarationTypes{$declaration_name}
4715 eq $declaration_type) {
4716 # If the existing declaration is empty, or is just a
4717 # forward declaration of a struct, override it.
4718 if ($declaration_type eq 'STRUCT') {
4719 if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4720 if ($is_deprecated) {
4721 $Deprecated{$declaration_name} = "";
4723 $Declarations{$declaration_name} = $declaration;
4724 } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4725 # Ignore an empty or forward declaration.
4727 &LogWarning ($file, $., "Structure $declaration_name has multiple definitions.");
4730 # set flag in %DeclarationConditional hash for
4731 # multiply defined macros/typedefs.
4732 $DeclarationConditional{$declaration_name} = 1;
4735 &LogWarning ($file, $., "$declaration_name has multiple definitions.");
4738 if ($is_deprecated) {
4739 $Deprecated{$declaration_name} = "";
4741 $Declarations{$declaration_name} = $declaration;
4742 $DeclarationTypes{$declaration_name} = $declaration_type;
4745 $declaration_type = "";
4756 #############################################################################
4757 # Function : ReadSignalsFile
4758 # Description : This reads in an existing file which contains information on
4759 # all GTK signals. It creates the arrays @SignalNames and
4760 # @SignalPrototypes containing info on the signals. The first
4761 # line of the SignalPrototype is the return type of the signal
4762 # handler. The remaining lines are the parameters passed to it.
4763 # The last parameter, "gpointer user_data" is always the same
4764 # so is not included.
4765 # Arguments : $file - the file containing the signal handler prototype
4767 #############################################################################
4769 sub ReadSignalsFile {
4777 my $signal_prototype;
4779 # Reset the signal info.
4780 @SignalObjects = ();
4782 @SignalReturns = ();
4784 @SignalPrototypes = ();
4789 if (!open (INPUT, $file)) {
4790 warn "Can't open $file - skipping signals\n";
4797 $signal_object = "";
4799 $signal_returns = "";
4800 $signal_prototype = "";
4803 if (m/^<NAME>(.*)<\/NAME>/) {
4805 if ($signal_name =~ m/^(.*)::(.*)$/) {
4806 $signal_object = $1;
4807 ($signal_name = $2) =~ s/_/-/g;
4808 #print "Found signal: $signal_name\n";
4810 &LogWarning ($file, $., "Invalid signal name: $signal_name.");
4812 } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
4813 $signal_returns = $1;
4814 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4816 } elsif (m%^</SIGNAL>%) {
4817 #print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
4818 push (@SignalObjects, $signal_object);
4819 push (@SignalNames, $signal_name);
4820 push (@SignalReturns, $signal_returns);
4821 push (@SignalFlags, $signal_flags);
4822 push (@SignalPrototypes, $signal_prototype);
4825 $signal_prototype .= $_;
4833 #############################################################################
4834 # Function : ReadTemplateFile
4835 # Description : This reads in the manually-edited documentation file
4836 # corresponding to the file currently being created, so we can
4837 # insert the documentation at the appropriate places.
4838 # It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
4839 # is a hash of arrays.
4840 # NOTE: This function is duplicated in gtkdoc-mktmpl (but
4841 # slightly different).
4842 # Arguments : $docsfile - the template file to read in.
4843 # $skip_unused_params - 1 if the unused parameters should be
4845 #############################################################################
4847 sub ReadTemplateFile {
4848 my ($docsfile, $skip_unused_params) = @_;
4850 my $template = "$docsfile.sgml";
4851 if (! -f $template) {
4852 #print "File doesn't exist: $template\n";
4856 # start with empty hashes, we merge the source comment for each file
4862 my $current_type = ""; # Type of symbol being read.
4863 my $current_symbol = ""; # Name of symbol being read.
4864 my $symbol_doc = ""; # Description of symbol being read.
4865 my @params; # Parameter names and descriptions of current
4866 # function/macro/function typedef.
4867 my $current_param = -1; # Index of parameter currently being read.
4868 # Note that the param array contains pairs
4869 # of param name & description.
4870 my $in_unused_params = 0; # True if we are reading in the unused params.
4871 my $in_deprecated = 0;
4873 my $in_stability = 0;
4875 open (DOCS, "$template")
4876 || die "Can't open $template: $!";
4878 @TRACE@("reading template $template");
4881 if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
4884 if ($symbol eq "Title"
4885 || $symbol eq "Short_Description"
4886 || $symbol eq "Long_Description"
4887 || $symbol eq "See_Also"
4888 || $symbol eq "Stability_Level"
4889 || $symbol eq "Include"
4890 || $symbol eq "Image") {
4892 $symbol = $docsfile . ":" . $symbol;
4895 #print "Found symbol: $symbol\n";
4896 # Remember file and line for the symbol
4897 $SymbolSourceFile{$symbol} = $template;
4898 $SymbolSourceLine{$symbol} = $.;
4900 # Store previous symbol, but remove any trailing blank lines.
4901 if ($current_symbol ne "") {
4902 $symbol_doc =~ s/\s+$//;
4903 $SymbolTypes{$current_symbol} = $current_type;
4904 $SymbolDocs{$current_symbol} = $symbol_doc;
4906 # Check that the stability level is valid.
4907 if ($StabilityLevel{$current_symbol}) {
4908 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4911 if ($current_param >= 0) {
4912 $SymbolParams{$current_symbol} = [ @params ];
4914 # Delete any existing params in case we are overriding a
4915 # previously read template.
4916 delete $SymbolParams{$current_symbol};
4919 $current_type = $type;
4920 $current_symbol = $symbol;
4921 $current_param = -1;
4922 $in_unused_params = 0;
4929 } elsif (m/^<!-- # Unused Parameters # -->/) {
4930 #print "DEBUG: Found unused parameters\n";
4931 $in_unused_params = 1;
4934 } elsif ($in_unused_params && $skip_unused_params) {
4935 # When outputting the DocBook we skip unused parameters.
4936 #print "DEBUG: Skipping unused param: $_";
4940 # Check if param found. Need to handle "..." and "format...".
4941 if (s/^\@([\w\.]+):\040?//) {
4942 my $param_name = $1;
4943 my $param_desc = $_;
4944 # Allow variations of 'Returns'
4945 if ($param_name =~ m/^[Rr]eturns?$/) {
4946 $param_name = "Returns";
4948 # Allow varargs variations
4949 if ($param_name =~ m/^.*\.\.\.$/) {
4950 $param_name = "...";
4953 # strip trailing whitespaces and blank lines
4956 @TRACE@("Found param for symbol $current_symbol : '$param_name'= '$_'");
4958 if ($param_name eq "Deprecated") {
4960 $Deprecated{$current_symbol} = $_;
4961 } elsif ($param_name eq "Since") {
4964 $Since{$current_symbol} = $_;
4965 } elsif ($param_name eq "Stability") {
4967 $StabilityLevel{$current_symbol} = $_;
4969 push (@params, $param_name);
4970 push (@params, $param_desc);
4971 $current_param += $PARAM_FIELD_COUNT;
4974 # strip trailing whitespaces and blank lines
4979 if ($in_deprecated) {
4980 $Deprecated{$current_symbol} .= $_;
4981 } elsif ($in_since) {
4982 &LogWarning ($template, $., "multi-line since docs found");
4983 #$Since{$current_symbol} .= $_;
4984 } elsif ($in_stability) {
4985 $StabilityLevel{$current_symbol} .= $_;
4986 } elsif ($current_param >= 0) {
4987 $params[$current_param] .= $_;
4996 # Remember to finish the current symbol doccs.
4997 if ($current_symbol ne "") {
4999 $symbol_doc =~ s/\s+$//;
5000 $SymbolTypes{$current_symbol} = $current_type;
5001 $SymbolDocs{$current_symbol} = $symbol_doc;
5003 # Check that the stability level is valid.
5004 if ($StabilityLevel{$current_symbol}) {
5005 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
5008 if ($current_param >= 0) {
5009 $SymbolParams{$current_symbol} = [ @params ];
5011 # Delete any existing params in case we are overriding a
5012 # previously read template.
5013 delete $SymbolParams{$current_symbol};
5022 #############################################################################
5023 # Function : ReadObjectHierarchy
5024 # Description : This reads in the $MODULE-hierarchy.txt file containing all
5025 # the GtkObject subclasses described in this module (and their
5027 # It places them in the @Objects array, and places their level
5028 # in the object hierarchy in the @ObjectLevels array, at the
5029 # same index. GtkObject, the root object, has a level of 1.
5031 # FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
5032 # as it goes along, this should be split out into a separate
5036 #############################################################################
5038 sub ReadObjectHierarchy {
5042 if (! -f $OBJECT_TREE_FILE) {
5045 if (!open (INPUT, $OBJECT_TREE_FILE)) {
5046 warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
5050 # FIXME: use $OUTPUT_FORMAT
5051 # my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.$OUTPUT_FORMAT";
5052 my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
5053 my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
5055 open (OUTPUT, ">$new_tree_index")
5056 || die "Can't create $new_tree_index: $!";
5058 if ($OUTPUT_FORMAT eq "xml") {
5059 my $tree_header = $doctype_header;
5061 $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
5062 print (OUTPUT "$tree_header");
5064 print (OUTPUT "<screen>\n");
5066 # Only emit objects if they are supposed to be documented, or if
5067 # they have documented children. To implement this, we maintain a
5068 # stack of pending objects which will be emitted if a documented
5070 my @pending_objects = ();
5071 my @pending_levels = ();
5076 my $level = (length($`)) / 2 + 1;
5083 while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
5084 my $pobject = pop(@pending_objects);
5085 my $plevel = pop(@pending_levels);
5088 push (@pending_objects, $object);
5089 push (@pending_levels, $level);
5091 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5092 while ($#pending_levels >= 0) {
5093 $object = shift @pending_objects;
5094 $level = shift @pending_levels;
5095 $xref = &MakeXRef ($object);
5097 print (OUTPUT ' ' x ($level * 4), "$xref\n");
5098 push (@Objects, $object);
5099 push (@ObjectLevels, $level);
5100 $ObjectRoots{$object} = $root;
5104 # LogWarning ($OBJECT_TREE_FILE, $., "unknown type $object");
5108 print (OUTPUT "</screen>\n");
5113 &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
5118 #############################################################################
5119 # Function : ReadInterfaces
5120 # Description : This reads in the $MODULE.interfaces file.
5123 #############################################################################
5125 sub ReadInterfaces {
5128 if (! -f $INTERFACES_FILE) {
5131 if (!open (INPUT, $INTERFACES_FILE)) {
5132 warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
5138 my ($object, @ifaces) = split;
5139 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5140 my @knownIfaces = ();
5142 # filter out private interfaces, but leave foreign interfaces
5143 foreach my $iface (@ifaces) {
5144 if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
5145 push (@knownIfaces, $iface);
5149 $Interfaces{$object} = join(' ', @knownIfaces);
5155 #############################################################################
5156 # Function : ReadPrerequisites
5157 # Description : This reads in the $MODULE.prerequisites file.
5160 #############################################################################
5162 sub ReadPrerequisites {
5163 %Prerequisites = ();
5165 if (! -f $PREREQUISITES_FILE) {
5168 if (!open (INPUT, $PREREQUISITES_FILE)) {
5169 warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
5175 my ($iface, @prereqs) = split;
5176 if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
5177 my @knownPrereqs = ();
5179 # filter out private prerequisites, but leave foreign prerequisites
5180 foreach my $prereq (@prereqs) {
5181 if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
5182 push (@knownPrereqs, $prereq);
5186 $Prerequisites{$iface} = join(' ', @knownPrereqs);
5192 #############################################################################
5193 # Function : ReadArgsFile
5194 # Description : This reads in an existing file which contains information on
5195 # all GTK args. It creates the arrays @ArgObjects, @ArgNames,
5196 # @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
5198 # Arguments : $file - the file containing the arg information.
5199 #############################################################################
5214 # Reset the args info.
5227 if (!open (INPUT, $file)) {
5228 warn "Can't open $file - skipping args\n";
5245 if (m/^<NAME>(.*)<\/NAME>/) {
5247 if ($arg_name =~ m/^(.*)::(.*)$/) {
5249 ($arg_name = $2) =~ s/_/-/g;
5250 #print "Found arg: $arg_name\n";
5252 &LogWarning ($file, $., "Invalid argument name: $arg_name");
5254 } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
5256 } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
5258 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
5260 } elsif (m/^<NICK>(.*)<\/NICK>/) {
5262 } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
5264 if ($arg_blurb eq "(null)") {
5266 &LogWarning ($file, $., "Property ${arg_object}:${arg_name} has no documentation.");
5268 } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
5270 } elsif (m%^</ARG>%) {
5271 #print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
5272 push (@ArgObjects, $arg_object);
5273 push (@ArgNames, $arg_name);
5274 push (@ArgTypes, $arg_type);
5275 push (@ArgRanges, $arg_range);
5276 push (@ArgFlags, $arg_flags);
5277 push (@ArgNicks, $arg_nick);
5278 push (@ArgBlurbs, $arg_blurb);
5279 push (@ArgDefaults, $arg_default);
5288 #############################################################################
5289 # Function : CheckIsObject
5290 # Description : Returns 1 if the given name is a GObject or a subclass.
5291 # It uses the global @Objects array.
5292 # Note that the @Objects array only contains classes in the
5293 # current module and their ancestors - not all GObject classes.
5294 # Arguments : $name - the name to check.
5295 #############################################################################
5299 my $root = $ObjectRoots{$name};
5300 # Let GBoxed pass as an object here to get -struct appended to the id
5301 # and prevent conflicts with sections.
5302 return defined($root) and $root ne 'GEnum' and $root ne 'GFlags';
5306 #############################################################################
5307 # Function : MakeReturnField
5308 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
5309 # Arguments : $str - the string to pad.
5310 #############################################################################
5312 sub MakeReturnField {
5315 return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));
5318 #############################################################################
5319 # Function : GetSymbolSourceFile
5320 # Description : Get the filename where the symbol docs where taken from.
5321 # Arguments : $symbol - the symbol name
5322 #############################################################################
5324 sub GetSymbolSourceFile {
5327 if (defined($SourceSymbolSourceFile{$symbol})) {
5328 return $SourceSymbolSourceFile{$symbol};
5329 } elsif (defined($SymbolSourceFile{$symbol})) {
5330 return $SymbolSourceFile{$symbol};
5336 #############################################################################
5337 # Function : GetSymbolSourceLine
5338 # Description : Get the file line where the symbol docs where taken from.
5339 # Arguments : $symbol - the symbol name
5340 #############################################################################
5342 sub GetSymbolSourceLine {
5345 if (defined($SourceSymbolSourceLine{$symbol})) {
5346 return $SourceSymbolSourceLine{$symbol};
5347 } elsif (defined($SymbolSourceLine{$symbol})) {
5348 return $SymbolSourceLine{$symbol};