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 = "";
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' => \$SGML_MODE,
66 'default-stability' => \$DEFAULT_STABILITY,
67 'default-includes' => \$DEFAULT_INCLUDES,
68 'output-format' => \$OUTPUT_FORMAT,
69 'name-space' => \$NAME_SPACE,
70 'outputallsymbols' => \$OUTPUT_ALL_SYMBOLS,
71 'outputsymbolswithoutsince' => \$OUTPUT_SYMBOLS_WITHOUT_SINCE
73 GetOptions(\%optctl, "module=s", "source-dir:s", "source-suffixes:s",
74 "ignore-files:s", "output-dir:s", "tmpl-dir:s", "version", "outputallsymbols",
75 "outputsymbolswithoutsince",
76 "expand-content-files:s", "main-sgml-file:s", "extra-db-files:s", "help",
77 "sgml-mode", "default-stability:s", "default-includes:s", "output-format:s",
89 if ($DEFAULT_STABILITY && $DEFAULT_STABILITY ne "Stable"
90 && $DEFAULT_STABILITY ne "Private" && $DEFAULT_STABILITY ne "Unstable") {
96 gtkdoc-mkdb version @VERSION@ - generate docbook files
98 --module=MODULE_NAME Name of the doc module being parsed
99 --source-dir=DIRNAME Directories which contain inline reference material
100 --source-suffixes=SUFFIXES Suffixes of source files to scan, comma-separated
101 --ignore-files=FILES Files or directories which should not be scanned
102 May be used more than once for multiple directories
103 --output-dir=DIRNAME Directory to put the generated DocBook files in
104 --tmpl-dir=DIRNAME Directory in which template files may be found
105 --main-sgml-file=FILE File containing the toplevel DocBook file.
106 --expand-content-files=FILES Extra DocBook files to expand abbreviations in.
107 --output-format=FORMAT Format to use for the generated docbook, XML or SGML.
108 --sgml-mode Allow DocBook markup in inline documentation.
109 --default-stability=LEVEL Specify default stability Level. Valid values are
110 Stable, Unstable, or Private.
111 --default-includes=FILENAMES Specify default includes for section Synopsis
112 --name-space=NS Omit namespace in index.
113 --version Print the version of this program
114 --help Print this help
119 my ($empty_element_end, $doctype_header);
121 # autodetect output format
122 if (! defined($OUTPUT_FORMAT) || ($OUTPUT_FORMAT eq "")) {
123 if (!$MAIN_SGML_FILE) {
124 if (-e "${MODULE}-docs.xml") {
125 $OUTPUT_FORMAT = "xml";
127 $OUTPUT_FORMAT = "sgml";
130 if ($MAIN_SGML_FILE =~ m/.*\.(.*ml)$/i) {
131 $OUTPUT_FORMAT = lc($1);
136 $OUTPUT_FORMAT = lc($OUTPUT_FORMAT);
139 #print "DEBUG: output-format: [$OUTPUT_FORMAT]\n";
141 if ($OUTPUT_FORMAT eq "xml") {
142 if (!$MAIN_SGML_FILE) {
143 # backwards compatibility
144 if (-e "${MODULE}-docs.sgml") {
145 $MAIN_SGML_FILE = "${MODULE}-docs.sgml";
147 $MAIN_SGML_FILE = "${MODULE}-docs.xml";
150 $empty_element_end = "/>";
152 if (-e $MAIN_SGML_FILE) {
153 open(INPUT, "<$MAIN_SGML_FILE") || die "Can't open $MAIN_SGML_FILE";
154 $doctype_header = "";
156 if (/^\s*<(book|chapter|article)/) {
157 # check that the top-level tag or the doctype decl contain the xinclude namespace decl
158 if (($_ !~ m/http:\/\/www.w3.org\/200[13]\/XInclude/) && ($doctype_header !~ m/http:\/\/www.w3.org\/200[13]\/XInclude/m)) {
159 $doctype_header = "";
163 $doctype_header .= $_;
166 $doctype_header =~ s/<!DOCTYPE \w+/<!DOCTYPE refentry/;
167 # if there are SYSTEM ENTITIES here, we should prepend "../" to the path
168 # FIXME: not sure if we can do this now, as people already work-around the problem
169 # $doctype_header =~ s#<!ENTITY % ([a-zA-Z-]+) SYSTEM \"([^/][a-zA-Z./]+)\">#<!ENTITY % $1 SYSTEM \"../$2\">#g;
172 "<?xml version=\"1.0\"?>\n" .
173 "<!DOCTYPE refentry PUBLIC \"-//OASIS//DTD DocBook XML V4.3//EN\"\n" .
174 " \"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd\"\n" .
176 " <!ENTITY % local.common.attrib \"xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'\">\n" .
180 if (!$MAIN_SGML_FILE) {
181 $MAIN_SGML_FILE = "${MODULE}-docs.sgml";
183 $empty_element_end = ">";
184 $doctype_header = "";
189 # All the files are written in subdirectories beneath here.
190 $TMPL_DIR = $TMPL_DIR ? $TMPL_DIR : "$ROOT_DIR/tmpl";
192 # This is where we put all the DocBook output.
193 $SGML_OUTPUT_DIR = $SGML_OUTPUT_DIR ? $SGML_OUTPUT_DIR : "$ROOT_DIR/$OUTPUT_FORMAT";
195 # This file contains the object hierarchy.
196 my $OBJECT_TREE_FILE = "$ROOT_DIR/$MODULE.hierarchy";
198 # This file contains the interfaces.
199 my $INTERFACES_FILE = "$ROOT_DIR/$MODULE.interfaces";
201 # This file contains the prerequisites.
202 my $PREREQUISITES_FILE = "$ROOT_DIR/$MODULE.prerequisites";
204 # This file contains signal arguments and names.
205 my $SIGNALS_FILE = "$ROOT_DIR/$MODULE.signals";
207 # The file containing Arg information.
208 my $ARGS_FILE = "$ROOT_DIR/$MODULE.args";
210 # These global arrays store information on signals. Each signal has an entry
211 # in each of these arrays at the same index, like a multi-dimensional array.
212 my @SignalObjects; # The GtkObject which emits the signal.
213 my @SignalNames; # The signal name.
214 my @SignalReturns; # The return type.
215 my @SignalFlags; # Flags for the signal
216 my @SignalPrototypes; # The rest of the prototype of the signal handler.
218 # These global arrays store information on Args. Each Arg has an entry
219 # in each of these arrays at the same index, like a multi-dimensional array.
220 my @ArgObjects; # The GtkObject which has the Arg.
221 my @ArgNames; # The Arg name.
222 my @ArgTypes; # The Arg type - gint, GtkArrowType etc.
223 my @ArgFlags; # How the Arg can be used - readable/writable etc.
224 my @ArgNicks; # The nickname of the Arg.
225 my @ArgBlurbs; # Docstring of the Arg.
226 my @ArgDefaults; # Default value of the Arg.
227 my @ArgRanges; # The range of the Arg type
228 # These global hashes store declaration info keyed on a symbol name.
230 my %DeclarationTypes;
231 my %DeclarationConditional;
232 my %DeclarationOutput;
236 my %StructHasTypedef;
238 # These global hashes store the existing documentation.
242 my %SymbolSourceFile;
243 my %SymbolSourceLine;
245 # These global hashes store documentation scanned from the source files.
246 my %SourceSymbolDocs;
247 my %SourceSymbolParams;
248 my %SourceSymbolSourceFile;
249 my %SourceSymbolSourceLine;
251 # all documentation goes in here, so we can do coverage analysis
253 my %AllIncompleteSymbols;
254 my %AllUnusedSymbols;
255 my %AllDocumentedSymbols;
257 # Undeclared yet documented symbols
258 my %UndeclaredSymbols;
260 # These global arrays store GObject, subclasses and the hierarchy.
267 # holds the symbols which are mentioned in $MODULE-sections.txt and in which
268 # section they are defined
273 # collects index entries
274 my %IndexEntriesFull;
275 my %IndexEntriesSince;
276 my %IndexEntriesDeprecated;
278 # Standard C preprocessor directives, which we ignore for '#' abbreviations.
279 my %PreProcessorDirectives;
280 $PreProcessorDirectives{"assert"} = 1;
281 $PreProcessorDirectives{"define"} = 1;
282 $PreProcessorDirectives{"elif"} = 1;
283 $PreProcessorDirectives{"else"} = 1;
284 $PreProcessorDirectives{"endif"} = 1;
285 $PreProcessorDirectives{"error"} = 1;
286 $PreProcessorDirectives{"if"} = 1;
287 $PreProcessorDirectives{"ifdef"} = 1;
288 $PreProcessorDirectives{"ifndef"} = 1;
289 $PreProcessorDirectives{"include"} = 1;
290 $PreProcessorDirectives{"line"} = 1;
291 $PreProcessorDirectives{"pragma"} = 1;
292 $PreProcessorDirectives{"unassert"} = 1;
293 $PreProcessorDirectives{"undef"} = 1;
294 $PreProcessorDirectives{"warning"} = 1;
296 # remember used annotation (to write minimal glossary)
299 my %AnnotationDefinition = (
300 'allow-none' => "NULL is ok, both for passing and for returning.",
301 'array' => "Parameter points to an array of items.",
302 'default' => "Default parameter value (for in case the <acronym>shadows</acronym>-to function has less parameters).",
303 'element-type' => "Generics and defining elements of containers and arrays.",
304 'error-domains' => "Typed errors. Similar to throws in Java.",
305 'in' => "Parameter for input. Default is <acronym>transfer none</acronym>.",
306 'inout' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
307 'in-out' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
308 'not-error' => "A GError parameter is not to be handled like a normal GError.",
309 'out' => "Parameter for returning results. Default is <acronym>transfer full</acronym>.",
310 'transfer container' => "Free data container after the code is done.",
311 'transfer full' => "Free data after the code is done.",
312 'transfer none' => "Don't free data after the code is done.",
313 'scope call' => "The callback is valid only during the call to the method.",
314 'scope async' => "The callback is valid until first called.",
315 'scope notfied' => "The callback is valid until the GDestroyNotify argument is called."
318 # Create the root DocBook output directory if it doens't exist.
319 if (! -e $SGML_OUTPUT_DIR) {
320 mkdir ("$SGML_OUTPUT_DIR", 0777)
321 || die "Can't create directory: $SGML_OUTPUT_DIR";
324 # Function and other declaration output settings.
325 my $RETURN_TYPE_FIELD_WIDTH = 20;
326 my $SYMBOL_FIELD_WIDTH = 36;
327 my $SIGNAL_FIELD_WIDTH = 16;
328 my $PARAM_FIELD_COUNT = 2;
330 &ReadKnownSymbols ("$ROOT_DIR/$MODULE-sections.txt");
331 &ReadSignalsFile ($SIGNALS_FILE);
332 &ReadArgsFile ($ARGS_FILE);
333 &ReadObjectHierarchy;
337 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-decl.txt", 0);
338 if (-f "$ROOT_DIR/$MODULE-overrides.txt") {
339 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-overrides.txt", 1);
342 for my $dir (@SOURCE_DIRS) {
343 &ReadSourceDocumentation ($dir);
346 my $changed = &OutputSGML ("$ROOT_DIR/$MODULE-sections.txt");
348 # If any of the DocBook SGML files have changed, update the timestamp file (so
349 # it can be used for Makefile dependencies).
350 if ($changed || ! -e "$ROOT_DIR/sgml.stamp") {
352 # try to detect the common prefix
353 # GtkWidget, GTK_WIDGET, gtk_widget -> gtk
354 if ($NAME_SPACE eq "") {
361 foreach my $symbol (keys(%IndexEntriesFull)) {
362 if(($NAME_SPACE eq "") || $symbol =~ /^$NAME_SPACE/i) {
363 if (length($symbol)>$pos) {
364 $letter=substr($symbol,$pos,1);
365 # stop prefix scanning
366 if ($letter eq "_") {
370 # Should we also stop on a uppercase char, if last was lowercase
371 # GtkWidget, if we have the 'W' and had the 't' before
372 # or should we count upper and lowercase, and stop one 2nd uppercase, if we already had a lowercase
373 # GtkWidget, the 'W' would be the 2nd uppercase and with 't','k' we had lowercase chars before
374 # need to recound each time as this is per symbol
375 $prefix{uc($letter)}++;
379 if ($letter ne "" && $letter ne "_") {
382 foreach $letter (keys(%prefix)) {
383 #print "$letter: $prefix{$letter}.\n";
384 if ($prefix{$letter}>$maxsymbols) {
386 $maxsymbols=$prefix{$letter};
389 $ratio = scalar(keys(%IndexEntriesFull)) / $prefix{$maxletter};
390 #print "most symbols start with $maxletter, that is ". (100 * $ratio) ." %\n";
393 $NAME_SPACE .= $maxletter;
400 } while ($ratio > 0.9);
401 #print "most symbols start with $NAME_SPACE\n";
405 &OutputDeprecatedIndex;
407 &OutputAnnotationGlossary;
409 open (TIMESTAMP, ">$ROOT_DIR/sgml.stamp")
410 || die "Can't create $ROOT_DIR/sgml.stamp: $!";
411 print (TIMESTAMP "timestamp");
415 #############################################################################
416 # Function : OutputObjectList
417 # Description : This outputs the alphabetical list of objects, in a columned
419 # FIXME: Currently this also outputs ancestor objects
420 # which may not actually be in this module.
422 #############################################################################
424 sub OutputObjectList {
427 # FIXME: use $OUTPUT_FORMAT
428 # my $old_object_index = "$SGML_OUTPUT_DIR/object_index.$OUTPUT_FORMAT";
429 my $old_object_index = "$SGML_OUTPUT_DIR/object_index.sgml";
430 my $new_object_index = "$SGML_OUTPUT_DIR/object_index.new";
432 open (OUTPUT, ">$new_object_index")
433 || die "Can't create $new_object_index: $!";
435 if ($OUTPUT_FORMAT eq "xml") {
436 my $header = $doctype_header;
438 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE informaltable/;
439 print (OUTPUT "$header");
442 print (OUTPUT <<EOF);
443 <informaltable pgwide="1" frame="none">
444 <tgroup cols="$cols">
445 <colspec colwidth="1*"${empty_element_end}
446 <colspec colwidth="1*"${empty_element_end}
447 <colspec colwidth="1*"${empty_element_end}
453 foreach $object (sort (@Objects)) {
454 my $xref = &MakeXRef ($object);
455 if ($count % $cols == 0) { print (OUTPUT "<row>\n"); }
456 print (OUTPUT "<entry>$xref</entry>\n");
457 if ($count % $cols == ($cols - 1)) { print (OUTPUT "</row>\n"); }
461 # emit an empty row, since empty tables are invalid
462 print (OUTPUT "<row><entry> </entry></row>\n");
465 if ($count % $cols > 0) {
466 print (OUTPUT "</row>\n");
470 print (OUTPUT <<EOF);
471 </tbody></tgroup></informaltable>
475 &UpdateFileIfChanged ($old_object_index, $new_object_index, 0);
479 #############################################################################
480 # Function : OutputSGML
481 # Description : This collects the output for each section of the docs, and
482 # outputs each file when the end of the section is found.
483 # Arguments : $file - the $MODULE-sections.txt file which contains all of
484 # the functions/macros/structs etc. being documented, organised
485 # into sections and subsections.
486 #############################################################################
491 #print "Reading: $file\n";
493 || die "Can't open $file: $!";
496 my $book_bottom = "";
497 my $includes = (defined $DEFAULT_INCLUDES) ? $DEFAULT_INCLUDES : "";
498 my $section_includes = "";
507 my $signals_synop = "";
508 my $signals_desc = "";
510 my $child_args_synop = "";
511 my $style_args_synop = "";
513 my $child_args_desc = "";
514 my $style_args_desc = "";
517 my $implementations = "";
518 my $prerequisites = "";
520 my @file_objects = ();
522 my %symbol_def_line = ();
524 # merge the source docs, in case there are no templates
525 &MergeSourceDocumentation;
531 } elsif (m/^<SECTION>/) {
537 %symbol_def_line = ();
539 } elsif (m/^<SUBSECTION\s*(.*)>/i) {
543 } elsif (m/^<SUBSECTION>/) {
545 } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
547 #print "Section: $title\n";
549 # We don't want warnings if object & class structs aren't used.
550 $DeclarationOutput{$title} = 1;
551 $DeclarationOutput{"${title}Class"} = 1;
552 $DeclarationOutput{"${title}Iface"} = 1;
553 $DeclarationOutput{"${title}Interface"} = 1;
555 } elsif (m/^<FILE>(.*)<\/FILE>/) {
557 if (! defined $templates{$filename}) {
558 if (&ReadTemplateFile ("$TMPL_DIR/$filename", 1)) {
559 &MergeSourceDocumentation;
560 $templates{$filename}=$.;
563 &LogWarning ($file, $., "Double <FILE>$filename</FILE> entry. ".
564 "Previous occurrence on line ".$templates{$filename}.".");
566 if (($title eq "") and (defined $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"})) {
567 $title = $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"};
568 # Remove trailing blanks
572 } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
574 $section_includes = $1;
576 if (defined $DEFAULT_INCLUDES) {
577 &LogWarning ($file, $., "Default <INCLUDE> being overridden by command line option.");
584 } elsif (m/^<\/SECTION>/) {
585 #print "End of section: $title\n";
586 if ($num_symbols > 0) {
588 if ($OUTPUT_FORMAT eq "xml") {
589 $book_bottom .= " <xi:include href=\"xml/$filename.xml\"/>\n";
591 $book_top.="<!ENTITY $section_id SYSTEM \"sgml/$filename.sgml\">\n";
592 $book_bottom .= " &$section_id;\n";
595 if (defined ($SourceSymbolDocs{"$TMPL_DIR/$filename:Include"})) {
596 if ($section_includes) {
597 &LogWarning ($file, $., "Section <INCLUDE> being overridden by inline comments.");
599 $section_includes = $SourceSymbolDocs{"$TMPL_DIR/$filename:Include"};
601 if ($section_includes eq "") {
602 $section_includes = $includes;
605 $signals_synop =~ s/^\n*//g;
606 $signals_synop =~ s/\n+$/\n/g;
607 if ($signals_synop ne '') {
608 $signals_synop = <<EOF;
609 <refsect1 id="$section_id.signals" role="signal_proto">
610 <title role="signal_proto.title">Signals</title>
612 ${signals_synop}</synopsis>
615 $signals_desc =~ s/^\n*//g;
616 $signals_desc =~ s/\n+$/\n/g;
617 $signals_desc =~ s/(\s|\n)+$//ms;
618 $signals_desc = <<EOF;
619 <refsect1 id="$section_id.signal-details" role="signals">
620 <title role="signals.title">Signal Details</title>
626 $args_synop =~ s/^\n*//g;
627 $args_synop =~ s/\n+$/\n/g;
628 if ($args_synop ne '') {
630 <refsect1 id="$section_id.properties" role="properties">
631 <title role="properties.title">Properties</title>
633 ${args_synop}</synopsis>
636 $args_desc =~ s/^\n*//g;
637 $args_desc =~ s/\n+$/\n/g;
638 $args_desc =~ s/(\s|\n)+$//ms;
640 <refsect1 id="$section_id.property-details" role="property_details">
641 <title role="property_details.title">Property Details</title>
647 $child_args_synop =~ s/^\n*//g;
648 $child_args_synop =~ s/\n+$/\n/g;
649 if ($child_args_synop ne '') {
650 $args_synop .= <<EOF;
651 <refsect1 id="$section_id.child-properties" role="child_properties">
652 <title role="child_properties.title">Child Properties</title>
654 ${child_args_synop}</synopsis>
657 $child_args_desc =~ s/^\n*//g;
658 $child_args_desc =~ s/\n+$/\n/g;
659 $child_args_desc =~ s/(\s|\n)+$//ms;
661 <refsect1 id="$section_id.child-property-details" role="child_property_details">
662 <title role="child_property_details.title">Child Property Details</title>
668 $style_args_synop =~ s/^\n*//g;
669 $style_args_synop =~ s/\n+$/\n/g;
670 if ($style_args_synop ne '') {
671 $args_synop .= <<EOF;
672 <refsect1 id="$section_id.style-properties" role="style_properties">
673 <title role="style_properties.title">Style Properties</title>
675 ${style_args_synop}</synopsis>
678 $style_args_desc =~ s/^\n*//g;
679 $style_args_desc =~ s/\n+$/\n/g;
680 $style_args_desc =~ s/(\s|\n)+$//ms;
682 <refsect1 id="$section_id.style-property-details" role="style_properties_details">
683 <title role="style_properties_details.title">Style Property Details</title>
689 $hierarchy =~ s/^\n*//g;
690 $hierarchy =~ s/\n+$/\n/g;
691 $hierarchy =~ s/(\s|\n)+$//ms;
692 if ($hierarchy ne "") {
694 <refsect1 id="$section_id.object-hierarchy" role="object_hierarchy">
695 <title role="object_hierarchy.title">Object Hierarchy</title>
701 $interfaces =~ s/^\n*//g;
702 $interfaces =~ s/\n+$/\n/g;
703 $interfaces =~ s/(\s|\n)+$//ms;
704 if ($interfaces ne "") {
706 <refsect1 id="$section_id.implemented-interfaces" role="impl_interfaces">
707 <title role="impl_interfaces.title">Implemented Interfaces</title>
713 $implementations =~ s/^\n*//g;
714 $implementations =~ s/\n+$/\n/g;
715 $implementations =~ s/(\s|\n)+$//ms;
716 if ($implementations ne "") {
717 $implementations = <<EOF;
718 <refsect1 id="$section_id.implementations" role="implementations">
719 <title role="implementations.title">Known Implementations</title>
725 $prerequisites =~ s/^\n*//g;
726 $prerequisites =~ s/\n+$/\n/g;
727 $prerequisites =~ s/(\s|\n)+$//ms;
728 if ($prerequisites ne "") {
729 $prerequisites = <<EOF;
730 <refsect1 id="$section_id.prerequisites" role="prerequisites">
731 <title role="prerequisites.title">Prerequisites</title>
737 $derived =~ s/^\n*//g;
738 $derived =~ s/\n+$/\n/g;
739 $derived =~ s/(\s|\n)+$//ms;
740 if ($derived ne "") {
742 <refsect1 id="$section_id.derived-interfaces" role="derived_interfaces">
743 <title role="derived_interfaces.title">Known Derived Interfaces</title>
749 $synopsis =~ s/^\n*//g;
750 $synopsis =~ s/\n+$/\n/g;
751 my $file_changed = &OutputSGMLFile ($filename, $title, $section_id,
753 \$synopsis, \$details,
754 \$signals_synop, \$signals_desc,
755 \$args_synop, \$args_desc,
756 \$hierarchy, \$interfaces,
758 \$prerequisites, \$derived,
768 $section_includes = "";
772 $child_args_synop = "";
773 $style_args_synop = "";
775 $child_args_desc = "";
776 $style_args_desc = "";
779 $implementations = "";
783 } elsif (m/^(\S+)/) {
785 #print " Symbol: $symbol\n";
787 # check for duplicate entries
788 if (! defined $symbol_def_line{$symbol}) {
789 my $declaration = $Declarations{$symbol};
790 if (defined ($declaration)) {
791 # We don't want standard macros/functions of GObjects,
792 # or private declarations.
793 if ($subsection ne "Standard" && $subsection ne "Private") {
794 if (&CheckIsObject ($symbol)) {
795 push @file_objects, $symbol;
797 my ($synop, $desc) = &OutputDeclaration ($symbol,
799 my ($sig_synop, $sig_desc) = &GetSignals ($symbol);
800 my ($arg_synop, $child_arg_synop, $style_arg_synop,
801 $arg_desc, $child_arg_desc, $style_arg_desc) = &GetArgs ($symbol);
802 my $hier = &GetHierarchy ($symbol);
803 my $ifaces = &GetInterfaces ($symbol);
804 my $impls = &GetImplementations ($symbol);
805 my $prereqs = &GetPrerequisites ($symbol);
806 my $der = &GetDerived ($symbol);
809 $signals_synop .= $sig_synop;
810 $signals_desc .= $sig_desc;
811 $args_synop .= $arg_synop;
812 $child_args_synop .= $child_arg_synop;
813 $style_args_synop .= $style_arg_synop;
814 $args_desc .= $arg_desc;
815 $child_args_desc .= $child_arg_desc;
816 $style_args_desc .= $style_arg_desc;
818 $interfaces .= $ifaces;
819 $implementations .= $impls;
820 $prerequisites .= $prereqs;
824 # Note that the declaration has been output.
825 $DeclarationOutput{$symbol} = 1;
826 } elsif ($subsection ne "Standard" && $subsection ne "Private") {
827 $UndeclaredSymbols{$symbol} = 1;
828 &LogWarning ($file, $., "No declaration found for $symbol.");
831 $symbol_def_line{$symbol}=$.;
833 if ($section_id eq "") {
834 if($title eq "" && $filename eq "") {
835 &LogWarning ($file, $., "Section has no title and no file.");
837 # FIXME: one of those would be enough
838 # filename should be an internal detail for gtk-doc
841 } elsif ($filename eq "") {
844 $filename =~ s/\s/_/g;
846 $section_id = $SourceSymbolDocs{"$TMPL_DIR/$filename:Section_Id"};
847 if (defined ($section_id) && $section_id !~ m/^\s*$/) {
848 # Remove trailing blanks and use as is
849 $section_id =~ s/\s+$//;
850 } elsif (&CheckIsObject ($title)) {
851 # GObjects use their class name as the ID.
852 $section_id = &CreateValidSGMLID ($title);
854 $section_id = &CreateValidSGMLID ("$MODULE-$title");
857 $SymbolSection{$symbol}=$title;
858 $SymbolSectionId{$symbol}=$section_id;
861 &LogWarning ($file, $., "Double symbol entry for $symbol. ".
862 "Previous occurrence on line ".$symbol_def_line{$symbol}.".");
868 &OutputMissingDocumentation;
869 &OutputUndeclaredSymbols;
870 &OutputUnusedSymbols;
872 if ($OUTPUT_ALL_SYMBOLS) {
875 if ($OUTPUT_SYMBOLS_WITHOUT_SINCE) {
876 &OutputSymbolsWithoutSince;
879 for $filename (split (' ', $EXPAND_CONTENT_FILES)) {
880 my $file_changed = &OutputExtraFile ($filename);
886 &OutputBook ($book_top, $book_bottom);
891 #############################################################################
892 # Function : OutputIndex
893 # Description : This writes an indexlist that can be included into the main-
894 # document into an <index> tag.
895 #############################################################################
898 my ($basename, $apiindexref ) = @_;
899 my %apiindex = %{$apiindexref};
900 my $old_index = "$SGML_OUTPUT_DIR/$basename.xml";
901 my $new_index = "$SGML_OUTPUT_DIR/$basename.new";
902 my $lastletter = " ";
907 open (OUTPUT, ">$new_index")
908 || die "Can't create $new_index";
910 my $header = $doctype_header;
911 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE indexdiv/;
913 print (OUTPUT "$header<indexdiv>\n");
915 #print "generate $basename index (".%apiindex." entries)\n";
917 # do a case insensitive sort while chopping off the prefix
919 sort { $$a{criteria} cmp $$b{criteria} }
920 map { my $x = uc($_); $x =~ s/^$NAME_SPACE\_?(.*)/$1/i; { criteria => $x, original => $_, short => $1 } }
923 $symbol = $$hash{original};
924 if (defined($$hash{short})) {
925 $short_symbol = $$hash{short};
927 $short_symbol = $symbol;
930 # generate a short symbol description
931 my $symbol_desc = "";
932 my $symbol_section = "";
933 my $symbol_section_id = "";
934 my $symbol_type = "";
935 if (defined($DeclarationTypes{$symbol})) {
936 $symbol_type = lc($DeclarationTypes{$symbol});
938 if ($symbol_type eq "") {
939 #print "trying symbol $symbol\n";
940 if ($symbol =~ m/(.*)::(.*)/) {
944 #print " trying object signal ${oname}:$osym in ".$#SignalNames." signals\n";
945 for ($i = 0; $i <= $#SignalNames; $i++) {
946 if ($SignalNames[$i] eq $osym) {
947 $symbol_type = "object signal";
948 if (defined($SymbolSection{$oname})) {
949 $symbol_section = $SymbolSection{$oname};
950 $symbol_section_id = $SymbolSectionId{$oname};
955 } elsif ($symbol =~ m/(.*):(.*)/) {
959 #print " trying object property ${oname}::$osym in ".$#ArgNames." properties\n";
960 for ($i = 0; $i <= $#ArgNames; $i++) {
961 #print " ".$ArgNames[$i]."\n";
962 if ($ArgNames[$i] eq $osym) {
963 $symbol_type = "object property";
964 if (defined($SymbolSection{$oname})) {
965 $symbol_section = $SymbolSection{$oname};
966 $symbol_section_id = $SymbolSectionId{$oname};
973 if (defined($SymbolSection{$symbol})) {
974 $symbol_section = $SymbolSection{$symbol};
975 $symbol_section_id = $SymbolSectionId{$symbol};
978 if ($symbol_type ne "") {
979 $symbol_desc=", $symbol_type";
980 if ($symbol_section ne "") {
981 $symbol_desc.=" in <link linkend=\"$symbol_section_id\">$symbol_section</link>";
982 #$symbol_desc.=" in ". &ExpandAbbreviations($symbol, "#$symbol_section");
986 my $curletter = uc(substr($short_symbol,0,1));
987 my $id = $apiindex{$symbol};
989 #print " add symbol $symbol with $id to index in section $curletter\n";
991 if ($curletter ne $lastletter) {
992 $lastletter = $curletter;
995 print (OUTPUT "</indexdiv>\n");
997 print (OUTPUT "<indexdiv><title>$curletter</title>\n");
1001 print (OUTPUT <<EOF);
1002 <indexentry><primaryie linkends="$id"><link linkend="$id">$symbol</link>$symbol_desc</primaryie></indexentry>
1006 if ($divopen == 1) {
1007 print (OUTPUT "</indexdiv>\n");
1009 print (OUTPUT "</indexdiv>\n");
1012 &UpdateFileIfChanged ($old_index, $new_index, 0);
1016 #############################################################################
1017 # Function : OutputIndexFull
1018 # Description : This writes the full api indexlist that can be included into the
1019 # main document into an <index> tag.
1020 #############################################################################
1022 sub OutputIndexFull {
1023 &OutputIndex ("api-index-full", \%IndexEntriesFull);
1027 #############################################################################
1028 # Function : OutputDeprecatedIndex
1029 # Description : This writes the deprecated api indexlist that can be included
1030 # into the main document into an <index> tag.
1031 #############################################################################
1033 sub OutputDeprecatedIndex {
1034 &OutputIndex ("api-index-deprecated", \%IndexEntriesDeprecated);
1038 #############################################################################
1039 # Function : OutputSinceIndexes
1040 # Description : This writes the 'since' api indexlists that can be included into
1041 # the main document into an <index> tag.
1042 #############################################################################
1044 sub OutputSinceIndexes {
1045 my @sinces = keys %{{ map { $_ => 1 } values %Since }};
1047 foreach my $version (@sinces) {
1048 #print "Since : [$version]\n";
1049 # TODO make filtered hash
1050 #my %index = grep { $Since{$_} eq $version } %IndexEntriesSince;
1051 my %index = map { $_ => $IndexEntriesSince{$_} } grep { $Since{$_} eq $version } keys %IndexEntriesSince;
1053 &OutputIndex ("api-index-$version", \%index);
1057 #############################################################################
1058 # Function : OutputAnnotationGlossary
1059 # Description : This writes a glossary of the used annotation terms into a
1060 # separate glossary file that can be included into the main
1062 #############################################################################
1064 sub OutputAnnotationGlossary {
1065 my $old_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.xml";
1066 my $new_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.new";
1067 my $lastletter = " ";
1070 # if there are no annotations used return
1071 return if (! keys(%AnnotationsUsed));
1073 # add acronyms that are referenced from acronym text
1075 foreach my $annotation (keys(%AnnotationsUsed)) {
1076 if(defined($AnnotationDefinition{$annotation})) {
1077 if($AnnotationDefinition{$annotation} =~ m/<acronym>([\w ]+)<\/acronym>/) {
1078 if (!exists($AnnotationsUsed{$1})) {
1079 $AnnotationsUsed{$1} = 1;
1086 open (OUTPUT, ">$new_glossary")
1087 || die "Can't create $new_glossary";
1089 my $header = $doctype_header;
1090 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE glossary/;
1092 print (OUTPUT <<EOF);
1094 <glossary id="annotation-glossary">
1095 <title>Annotation Glossary</title>
1098 foreach my $annotation (keys(%AnnotationsUsed)) {
1099 if(defined($AnnotationDefinition{$annotation})) {
1100 my $def = $AnnotationDefinition{$annotation};
1101 my $curletter = uc(substr($annotation,0,1));
1103 if ($curletter ne $lastletter) {
1104 $lastletter = $curletter;
1106 if ($divopen == 1) {
1107 print (OUTPUT "</glossdiv>\n");
1109 print (OUTPUT "<glossdiv><title>$curletter</title>\n");
1112 print (OUTPUT <<EOF);
1114 <glossterm><anchor id="annotation-glossterm-$annotation"/>$annotation</glossterm>
1123 if ($divopen == 1) {
1124 print (OUTPUT "</glossdiv>\n");
1126 print (OUTPUT "</glossary>\n");
1129 &UpdateFileIfChanged ($old_glossary, $new_glossary, 0);
1132 #############################################################################
1133 # Function : ReadKnownSymbols
1134 # Description : This collects the names of non-private symbols from the
1135 # $MODULE-sections.txt file.
1136 # Arguments : $file - the $MODULE-sections.txt file which contains all of
1137 # the functions/macros/structs etc. being documented, organised
1138 # into sections and subsections.
1139 #############################################################################
1141 sub ReadKnownSymbols {
1144 my $subsection = "";
1146 #print "Reading: $file\n";
1148 || die "Can't open $file: $!";
1154 } elsif (m/^<SECTION>/) {
1157 } elsif (m/^<SUBSECTION\s*(.*)>/i) {
1160 } elsif (m/^<SUBSECTION>/) {
1163 } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
1166 } elsif (m/^<FILE>(.*)<\/FILE>/) {
1167 $KnownSymbols{"$TMPL_DIR/$1:Long_Description"} = 1;
1168 $KnownSymbols{"$TMPL_DIR/$1:Short_Description"} = 1;
1171 } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
1174 } elsif (m/^<\/SECTION>/) {
1177 } elsif (m/^(\S+)/) {
1180 if ($subsection ne "Standard" && $subsection ne "Private") {
1181 $KnownSymbols{$symbol} = 1;
1184 $KnownSymbols{$symbol} = 0;
1192 #############################################################################
1193 # Function : OutputDeclaration
1194 # Description : Returns the synopsis and detailed description DocBook
1195 # describing one function/macro etc.
1196 # Arguments : $symbol - the name of the function/macro begin described.
1197 # $declaration - the declaration of the function/macro.
1198 #############################################################################
1200 sub OutputDeclaration {
1201 my ($symbol, $declaration) = @_;
1203 my $type = $DeclarationTypes {$symbol};
1204 if ($type eq 'MACRO') {
1205 return &OutputMacro ($symbol, $declaration);
1206 } elsif ($type eq 'TYPEDEF') {
1207 return &OutputTypedef ($symbol, $declaration);
1208 } elsif ($type eq 'STRUCT') {
1209 return &OutputStruct ($symbol, $declaration);
1210 } elsif ($type eq 'ENUM') {
1211 return &OutputEnum ($symbol, $declaration);
1212 } elsif ($type eq 'UNION') {
1213 return &OutputUnion ($symbol, $declaration);
1214 } elsif ($type eq 'VARIABLE') {
1215 return &OutputVariable ($symbol, $declaration);
1216 } elsif ($type eq 'FUNCTION') {
1217 return &OutputFunction ($symbol, $declaration, $type);
1218 } elsif ($type eq 'USER_FUNCTION') {
1219 return &OutputFunction ($symbol, $declaration, $type);
1221 die "Unknown symbol type";
1226 #############################################################################
1227 # Function : OutputSymbolTraits
1228 # Description : Returns the Since and StabilityLevel paragraphs for a symbol.
1229 # Arguments : $symbol - the name of the function/macro begin described.
1230 #############################################################################
1232 sub OutputSymbolTraits {
1236 if (exists $Since{$symbol}) {
1237 $desc .= "<para role=\"since\">Since $Since{$symbol}</para>";
1239 if (exists $StabilityLevel{$symbol}) {
1240 $desc .= "<para role=\"stability\">Stability Level: $StabilityLevel{$symbol}</para>";
1245 #############################################################################
1246 # Function : Outpu{Symbol,Section}ExtraLinks
1247 # Description : Returns extralinks for the symbol (if enabled).
1248 # Arguments : $symbol - the name of the function/macro begin described.
1249 #############################################################################
1253 return undef unless defined $text;
1255 # Build a char to hex map
1258 $escapes{chr($_)} = sprintf("%%%02X", $_);
1261 # Default unsafe characters. RFC 2732 ^(uric - reserved)
1262 $text =~ s/([^A-Za-z0-9\-_.!~*'()])/$escapes{$1}/g;
1267 sub OutputSymbolExtraLinks {
1271 if (0) { # NEW FEATURE: needs configurability
1272 my $sstr = &uri_escape($symbol);
1273 my $mstr = &uri_escape($MODULE);
1275 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1276 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&symbol=$sstr">edit documentation</ulink>
1282 sub OutputSectionExtraLinks {
1283 my ($symbol,$docsymbol) = @_;
1286 if (0) { # NEW FEATURE: needs configurability
1287 my $sstr = &uri_escape($symbol);
1288 my $mstr = &uri_escape($MODULE);
1289 my $dsstr = &uri_escape($docsymbol);
1291 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1292 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&symbol=$dsstr">edit documentation</ulink>
1299 #############################################################################
1300 # Function : OutputMacro
1301 # Description : Returns the synopsis and detailed description of a macro.
1302 # Arguments : $symbol - the macro.
1303 # $declaration - the declaration of the macro.
1304 #############################################################################
1307 my ($symbol, $declaration) = @_;
1308 my $id = &CreateValidSGMLID ($symbol);
1309 my $condition = &MakeConditionDescription ($symbol);
1310 my $synop = &MakeReturnField("#define") . "<link linkend=\"$id\">$symbol</link>";
1313 my @fields = ParseMacroDeclaration($declaration, \&CreateValidSGML);
1314 my $title = $symbol . (@fields ? "()" : "");
1316 $desc = "<refsect2 id=\"$id\" role=\"macro\"$condition>\n<title>$title</title>\n";
1317 $desc .= MakeIndexterms($symbol, $id);
1319 $desc .= OutputSymbolExtraLinks($symbol);
1322 if (length ($symbol) < $SYMBOL_FIELD_WIDTH) {
1323 $synop .= (' ' x ($SYMBOL_FIELD_WIDTH - length ($symbol)));
1327 for (my $i = 1; $i <= $#fields; $i += 2) {
1328 my $field_name = $fields[$i];
1331 $synop .= "$field_name";
1334 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1342 # Don't output the macro definition if is is a conditional macro or it
1343 # looks like a function, i.e. starts with "g_" or "_?gnome_", or it is
1344 # longer than 2 lines, otherwise we get lots of complicated macros like
1346 if (!defined ($DeclarationConditional{$symbol}) && ($symbol !~ m/^g_/)
1347 && ($symbol !~ m/^_?gnome_/) && (($declaration =~ tr/\n//) < 2)) {
1348 my $decl_out = &CreateValidSGML ($declaration);
1349 $desc .= "<programlisting>$decl_out</programlisting>\n";
1351 $desc .= "<programlisting>" . &MakeReturnField("#define") . "$symbol";
1352 if ($declaration =~ m/^\s*#\s*define\s+\w+(\([^\)]*\))/) {
1354 my $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH - length ("#define "));
1355 # Align each line so that if should all line up OK.
1356 $args =~ s/\n/\n$pad/gm;
1357 $desc .= &CreateValidSGML ($args);
1359 $desc .= "</programlisting>\n";
1362 $desc .= &MakeDeprecationNote($symbol);
1364 my $parameters = &OutputParamDescriptions ("MACRO", $symbol, @fields);
1365 my $parameters_output = 0;
1367 if (defined ($SymbolDocs{$symbol})) {
1368 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1370 # Try to insert the parameter table at the author's desired position.
1371 # Otherwise we need to tag it onto the end.
1372 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1373 $parameters_output = 1;
1375 $desc .= $symbol_docs;
1378 if ($parameters_output == 0) {
1379 $desc .= $parameters;
1382 $desc .= OutputSymbolTraits ($symbol);
1383 $desc .= "</refsect2>\n";
1384 return ($synop, $desc);
1388 #############################################################################
1389 # Function : OutputTypedef
1390 # Description : Returns the synopsis and detailed description of a typedef.
1391 # Arguments : $symbol - the typedef.
1392 # $declaration - the declaration of the typedef,
1393 # e.g. 'typedef unsigned int guint;'
1394 #############################################################################
1397 my ($symbol, $declaration) = @_;
1398 my $id = &CreateValidSGMLID ($symbol);
1399 my $condition = &MakeConditionDescription ($symbol);
1400 my $synop = &MakeReturnField("typedef") . "<link linkend=\"$id\">$symbol</link>;\n";
1401 my $desc = "<refsect2 id=\"$id\" role=\"typedef\"$condition>\n<title>$symbol</title>\n";
1403 $desc .= MakeIndexterms($symbol, $id);
1405 $desc .= OutputSymbolExtraLinks($symbol);
1407 if (!defined ($DeclarationConditional{$symbol})) {
1408 my $decl_out = &CreateValidSGML ($declaration);
1409 $desc .= "<programlisting>$decl_out</programlisting>\n";
1412 $desc .= &MakeDeprecationNote($symbol);
1414 if (defined ($SymbolDocs{$symbol})) {
1415 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1417 $desc .= OutputSymbolTraits ($symbol);
1418 $desc .= "</refsect2>\n";
1419 return ($synop, $desc);
1423 #############################################################################
1424 # Function : OutputStruct
1425 # Description : Returns the synopsis and detailed description of a struct.
1426 # We check if it is a object struct, and if so we only output
1427 # parts of it that are noted as public fields.
1428 # We also use a different SGML ID for object structs, since the
1429 # original ID is used for the entire RefEntry.
1430 # Arguments : $symbol - the struct.
1431 # $declaration - the declaration of the struct.
1432 #############################################################################
1435 my ($symbol, $declaration) = @_;
1437 my $is_object_struct = 0;
1438 my $default_to_public = 1;
1439 if (&CheckIsObject ($symbol)) {
1440 #print "Found object struct: $symbol\n";
1441 $is_object_struct = 1;
1442 $default_to_public = 0;
1447 if ($is_object_struct) {
1448 $id = &CreateValidSGMLID ($symbol . "_struct");
1449 $condition = &MakeConditionDescription ($symbol . "_struct");
1451 $id = &CreateValidSGMLID ($symbol);
1452 $condition = &MakeConditionDescription ($symbol);
1455 # Determine if it is a simple struct or it also has a typedef.
1456 my $has_typedef = 0;
1457 if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1464 # For structs with typedefs we just output the struct name.
1465 $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1466 $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>$symbol</title>\n";
1468 $synop = &MakeReturnField("struct") . "<link linkend=\"$id\">$symbol</link>;\n";
1469 $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>struct $symbol</title>\n";
1472 $desc .= MakeIndexterms($symbol, $id);
1474 $desc .= OutputSymbolExtraLinks($symbol);
1476 # Form a pretty-printed, private-data-removed form of the declaration
1479 if ($declaration =~ m/^\s*$/) {
1480 #print "Found opaque struct: $symbol\n";
1481 $decl_out = "typedef struct _$symbol $symbol;";
1482 } elsif ($declaration =~ m/^\s*struct\s+\w+\s*;\s*$/) {
1483 #print "Found opaque struct: $symbol\n";
1484 $decl_out = "struct $symbol;";
1486 my $public = $default_to_public;
1487 my $new_declaration = "";
1489 my $decl = $declaration;
1491 if ($decl =~ m/^\s*(typedef\s+)?struct\s*\w*\s*(?:\/\*.*\*\/)?\s*{(.*)}\s*\w*\s*;\s*$/s) {
1492 my $struct_contents = $2;
1494 foreach $decl_line (split (/\n/, $struct_contents)) {
1495 #print "Struct line: $decl_line\n";
1496 if ($decl_line =~ m%/\*\s*<\s*public\s*>\s*\*/%) {
1498 } elsif ($decl_line =~ m%/\*\s*<\s*(private|protected)\s*>\s*\*/%) {
1501 $new_declaration .= $decl_line . "\n";
1505 if ($new_declaration) {
1506 # Strip any blank lines off the ends.
1507 $new_declaration =~ s/^\s*\n//;
1508 $new_declaration =~ s/\n\s*$/\n/;
1511 $decl_out = "typedef struct {\n" . $new_declaration
1514 $decl_out = "struct $symbol {\n" . $new_declaration
1519 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1520 "Couldn't parse struct:\n$declaration");
1523 # If we couldn't parse the struct or it was all private, output an
1524 # empty struct declaration.
1525 if ($decl_out eq "") {
1527 $decl_out = "typedef struct _$symbol $symbol;";
1529 $decl_out = "struct $symbol;";
1534 $decl_out = &CreateValidSGML ($decl_out);
1535 $desc .= "<programlisting>$decl_out</programlisting>\n";
1537 $desc .= &MakeDeprecationNote($symbol);
1539 if (defined ($SymbolDocs{$symbol})) {
1540 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1543 # Create a table of fields and descriptions
1545 # FIXME: Inserting  's into the produced type declarations here would
1546 # improve the output in most situations ... except for function
1547 # members of structs!
1548 my @fields = ParseStructDeclaration($declaration, !$default_to_public,
1551 "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1553 my $params = $SymbolParams{$symbol};
1555 # If no parameters are filled in, we don't generate the description
1556 # table, for backwards compatibility
1559 if (defined $params) {
1560 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1561 if ($params->[$i] =~ /\S/) {
1569 my %field_descrs = @$params;
1570 my $missing_parameters = "";
1571 my $unused_parameters = "";
1573 $desc .= "<variablelist role=\"struct\">\n";
1575 my $field_name = shift @fields;
1576 my $text = shift @fields;
1577 my $field_descr = $field_descrs{$field_name};
1578 my $param_annotations = "";
1580 $desc .= "<varlistentry><term>$text</term>\n";
1581 if (defined $field_descr) {
1582 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1583 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1584 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1585 delete $field_descrs{$field_name};
1587 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1588 "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1589 if ($missing_parameters ne "") {
1590 $missing_parameters .= ", ".$field_name;
1592 $missing_parameters = $field_name;
1594 $desc .= "<listitem />\n";
1596 $desc .= "</varlistentry>\n";
1598 $desc .= "</variablelist>";
1599 foreach my $field_name (keys %field_descrs) {
1600 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1601 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1602 if ($unused_parameters ne "") {
1603 $unused_parameters .= ", ".$field_name;
1605 $unused_parameters = $field_name;
1609 # remember missing/unused parameters (needed in tmpl-free build)
1610 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1611 $AllIncompleteSymbols{$symbol}=$missing_parameters;
1613 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1614 $AllUnusedSymbols{$symbol}=$unused_parameters;
1618 if (scalar(@fields) > 0) {
1619 if (! exists ($AllIncompleteSymbols{$symbol})) {
1620 $AllIncompleteSymbols{$symbol}="<items>";
1621 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1622 "Field descriptions for $symbol are missing in source code comment block.");
1627 $desc .= OutputSymbolTraits ($symbol);
1628 $desc .= "</refsect2>\n";
1629 return ($synop, $desc);
1633 #############################################################################
1634 # Function : OutputUnion
1635 # Description : Returns the synopsis and detailed description of a union.
1636 # Arguments : $symbol - the union.
1637 # $declaration - the declaration of the union.
1638 #############################################################################
1641 my ($symbol, $declaration) = @_;
1642 my $id = &CreateValidSGMLID ($symbol);
1643 my $condition = &MakeConditionDescription ($symbol);
1645 # Determine if it is a simple struct or it also has a typedef.
1646 my $has_typedef = 0;
1647 if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1654 # For unions with typedefs we just output the union name.
1655 $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1656 $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>$symbol</title>\n";
1658 $synop = &MakeReturnField("union") . "<link linkend=\"$id\">$symbol</link>;\n";
1659 $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>union $symbol</title>\n";
1662 $desc .= MakeIndexterms($symbol, $id);
1664 $desc .= OutputSymbolExtraLinks($symbol);
1666 # FIXME: we do more for structs
1667 my $decl_out = &CreateValidSGML ($declaration);
1668 $desc .= "<programlisting>$decl_out</programlisting>\n";
1670 $desc .= &MakeDeprecationNote($symbol);
1672 if (defined ($SymbolDocs{$symbol})) {
1673 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1676 # Create a table of fields and descriptions
1678 # FIXME: Inserting  's into the produced type declarations here would
1679 # improve the output in most situations ... except for function
1680 # members of structs!
1681 my @fields = ParseStructDeclaration($declaration, 0,
1684 "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1686 my $params = $SymbolParams{$symbol};
1688 # If no parameters are filled in, we don't generate the description
1689 # table, for backwards compatibility
1692 if (defined $params) {
1693 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1694 if ($params->[$i] =~ /\S/) {
1702 my %field_descrs = @$params;
1703 my $missing_parameters = "";
1704 my $unused_parameters = "";
1706 $desc .= "<variablelist role=\"union\">\n";
1708 my $field_name = shift @fields;
1709 my $text = shift @fields;
1710 my $field_descr = $field_descrs{$field_name};
1711 my $param_annotations = "";
1713 $desc .= "<varlistentry><term>$text</term>\n";
1714 if (defined $field_descr) {
1715 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1716 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1717 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1718 delete $field_descrs{$field_name};
1720 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1721 "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1722 if ($missing_parameters ne "") {
1723 $missing_parameters .= ", ".$field_name;
1725 $missing_parameters = $field_name;
1727 $desc .= "<listitem />\n";
1729 $desc .= "</varlistentry>\n";
1731 $desc .= "</variablelist>";
1732 foreach my $field_name (keys %field_descrs) {
1733 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1734 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1735 if ($unused_parameters ne "") {
1736 $unused_parameters .= ", ".$field_name;
1738 $unused_parameters = $field_name;
1742 # remember missing/unused parameters (needed in tmpl-free build)
1743 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1744 $AllIncompleteSymbols{$symbol}=$missing_parameters;
1746 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1747 $AllUnusedSymbols{$symbol}=$unused_parameters;
1751 if (scalar(@fields) > 0) {
1752 if (! exists ($AllIncompleteSymbols{$symbol})) {
1753 $AllIncompleteSymbols{$symbol}="<items>";
1754 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1755 "Field descriptions for $symbol are missing in source code comment block.");
1760 $desc .= OutputSymbolTraits ($symbol);
1761 $desc .= "</refsect2>\n";
1762 return ($synop, $desc);
1766 #############################################################################
1767 # Function : OutputEnum
1768 # Description : Returns the synopsis and detailed description of a enum.
1769 # Arguments : $symbol - the enum.
1770 # $declaration - the declaration of the enum.
1771 #############################################################################
1774 my ($symbol, $declaration) = @_;
1775 my $id = &CreateValidSGMLID ($symbol);
1776 my $condition = &MakeConditionDescription ($symbol);
1777 my $synop = &MakeReturnField("enum") . "<link linkend=\"$id\">$symbol</link>;\n";
1778 my $desc = "<refsect2 id=\"$id\" role=\"enum\"$condition>\n<title>enum $symbol</title>\n";
1780 $desc .= MakeIndexterms($symbol, $id);
1782 $desc .= OutputSymbolExtraLinks($symbol);
1784 my $decl_out = &CreateValidSGML ($declaration);
1785 $desc .= "<programlisting>$decl_out</programlisting>\n";
1787 $desc .= &MakeDeprecationNote($symbol);
1789 if (defined ($SymbolDocs{$symbol})) {
1790 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1793 # Create a table of fields and descriptions
1795 my @fields = ParseEnumDeclaration($declaration);
1796 my $params = $SymbolParams{$symbol};
1798 # If no parameters are filled in, we don't generate the description
1799 # table, for backwards compatibility
1802 if (defined $params) {
1803 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1804 if ($params->[$i] =~ /\S/) {
1812 my %field_descrs = @$params;
1813 my $missing_parameters = "";
1814 my $unused_parameters = "";
1816 $desc .= "<variablelist role=\"enum\">\n";
1817 for my $field_name (@fields) {
1818 my $field_descr = $field_descrs{$field_name};
1819 my $param_annotations = "";
1821 $id = &CreateValidSGMLID ($field_name);
1822 $condition = &MakeConditionDescription ($field_name);
1823 $desc .= "<varlistentry id=\"$id\" role=\"constant\"$condition>\n<term><literal>$field_name</literal></term>\n";
1824 if (defined $field_descr) {
1825 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1826 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1827 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1828 delete $field_descrs{$field_name};
1830 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1831 "Value description for $symbol"."::"."$field_name is missing in source code comment block.");
1832 if ($missing_parameters ne "") {
1833 $missing_parameters .= ", ".$field_name;
1835 $missing_parameters = $field_name;
1837 $desc .= "<listitem />\n";
1839 $desc .= "</varlistentry>\n";
1841 $desc .= "</variablelist>";
1842 foreach my $field_name (keys %field_descrs) {
1843 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1844 "Value description for $symbol"."::"."$field_name is not used from source code comment block.");
1845 if ($unused_parameters ne "") {
1846 $unused_parameters .= ", ".$field_name;
1848 $unused_parameters = $field_name;
1852 # remember missing/unused parameters (needed in tmpl-free build)
1853 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1854 $AllIncompleteSymbols{$symbol}=$missing_parameters;
1856 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1857 $AllUnusedSymbols{$symbol}=$unused_parameters;
1861 if (scalar(@fields) > 0) {
1862 if (! exists ($AllIncompleteSymbols{$symbol})) {
1863 $AllIncompleteSymbols{$symbol}="<items>";
1864 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1865 "Value descriptions for $symbol are missing in source code comment block.");
1870 $desc .= OutputSymbolTraits ($symbol);
1871 $desc .= "</refsect2>\n";
1872 return ($synop, $desc);
1876 #############################################################################
1877 # Function : OutputVariable
1878 # Description : Returns the synopsis and detailed description of a variable.
1879 # Arguments : $symbol - the extern'ed variable.
1880 # $declaration - the declaration of the variable.
1881 #############################################################################
1883 sub OutputVariable {
1884 my ($symbol, $declaration) = @_;
1885 my $id = &CreateValidSGMLID ($symbol);
1886 my $condition = &MakeConditionDescription ($symbol);
1889 if ($declaration =~ m/^\s*extern\s+((const\s+|signed\s+|unsigned\s+)*\w+)(\s+\*+|\*+|\s)(\s*)([A-Za-z]\w*)\s*;/) {
1890 my $mod = defined ($1) ? $1 : "";
1891 my $ptr = defined ($3) ? $3 : "";
1892 my $space = defined ($4) ? $4 : "";
1893 $synop = &MakeReturnField("extern") . "$mod$ptr$space<link linkend=\"$id\">$symbol</link>;\n";
1896 $synop = &MakeReturnField("extern") . "<link linkend=\"$id\">$symbol</link>;\n";
1899 my $desc = "<refsect2 id=\"$id\" role=\"variable\"$condition>\n<title>$symbol</title>\n";
1901 $desc .= MakeIndexterms($symbol, $id);
1903 $desc .= OutputSymbolExtraLinks($symbol);
1905 my $decl_out = &CreateValidSGML ($declaration);
1906 $desc .= "<programlisting>$decl_out</programlisting>\n";
1908 $desc .= &MakeDeprecationNote($symbol);
1910 if (defined ($SymbolDocs{$symbol})) {
1911 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1913 $desc .= OutputSymbolTraits ($symbol);
1914 $desc .= "</refsect2>\n";
1915 return ($synop, $desc);
1919 #############################################################################
1920 # Function : OutputFunction
1921 # Description : Returns the synopsis and detailed description of a function.
1922 # Arguments : $symbol - the function.
1923 # $declaration - the declaration of the function.
1924 #############################################################################
1926 sub OutputFunction {
1927 my ($symbol, $declaration, $symbol_type) = @_;
1928 my $id = &CreateValidSGMLID ($symbol);
1929 my $condition = &MakeConditionDescription ($symbol);
1931 # Take out the return type $1 $3 $4
1932 $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//;
1933 my $type_modifier = defined($1) ? $1 : "";
1936 #print "$symbol pointer is $pointer\n";
1937 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1939 #if ($symbol_type eq 'USER_FUNCTION') {
1940 # $start = "typedef ";
1943 # We output const rather than G_CONST_RETURN.
1944 $type_modifier =~ s/G_CONST_RETURN/const/g;
1945 $pointer =~ s/G_CONST_RETURN/const/g;
1946 $pointer =~ s/^\s+/ /g;
1948 my $ret_type_len = length ($start) + length ($type_modifier)
1949 + length ($pointer) + length ($type);
1950 my $ret_type_output;
1952 if ($ret_type_len < $RETURN_TYPE_FIELD_WIDTH) {
1953 $ret_type_output = "$start$type_modifier$xref$pointer"
1954 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
1957 #$ret_type_output = "$start$type_modifier$xref$pointer\n" . (' ' x $RETURN_TYPE_FIELD_WIDTH);
1959 $ret_type_output = "$start$type_modifier$xref$pointer ";
1960 $symbol_len = $ret_type_len + 1 - $RETURN_TYPE_FIELD_WIDTH;
1963 $symbol_len += length ($symbol);
1964 my $char1 = my $char2 = my $char3 = "";
1965 if ($symbol_type eq 'USER_FUNCTION') {
1972 my ($symbol_output, $symbol_desc_output);
1973 if ($symbol_len < $SYMBOL_FIELD_WIDTH) {
1974 $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3"
1975 . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1976 $symbol_desc_output = "$char1$char2$symbol$char3"
1977 . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1979 $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3\n"
1980 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1981 $symbol_desc_output = "$char1$char2$symbol$char3\n"
1982 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1985 my $synop = $ret_type_output . $symbol_output . '(';
1986 my $desc = "<refsect2 id=\"$id\" role=\"function\"$condition>\n<title>${symbol} ()</title>\n";
1988 $desc .= MakeIndexterms($symbol, $id);
1990 $desc .= OutputSymbolExtraLinks($symbol);
1992 $desc .= "<programlisting>${ret_type_output}$symbol_desc_output(";
1994 my @fields = ParseFunctionDeclaration($declaration, \&MakeXRef,
1996 &tagify($_[0],"parameter");
1999 for (my $i = 1; $i <= $#fields; $i += 2) {
2000 my $field_name = $fields[$i];
2002 if ($field_name eq "Varargs") {
2003 $field_name = "...";
2007 $synop .= "$field_name";
2008 $desc .= "$field_name";
2011 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2014 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2021 $desc .= ");</programlisting>\n";
2023 $desc .= &MakeDeprecationNote($symbol);
2025 my $parameters = &OutputParamDescriptions ("FUNCTION", $symbol, @fields);
2026 my $parameters_output = 0;
2028 if (defined ($SymbolDocs{$symbol})) {
2029 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
2031 # Try to insert the parameter table at the author's desired position.
2032 # Otherwise we need to tag it onto the end.
2033 # FIXME: document that in the user manual and make it useable for other
2035 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
2036 $parameters_output = 1;
2038 $desc .= $symbol_docs;
2041 if ($parameters_output == 0) {
2042 $desc .= $parameters;
2045 $desc .= OutputSymbolTraits ($symbol);
2046 $desc .= "</refsect2>\n";
2047 return ($synop, $desc);
2051 #############################################################################
2052 # Function : OutputParamDescriptions
2053 # Description : Returns the DocBook output describing the parameters of a
2054 # function, macro or signal handler.
2055 # Arguments : $symbol_type - 'FUNCTION', 'MACRO' or 'SIGNAL'. Signal
2056 # handlers have an implicit user_data parameter last.
2057 # $symbol - the name of the function/macro being described.
2058 # @fields - parsed fields from the declaration, used to determine
2059 # undocumented/unused entries
2060 #############################################################################
2062 sub OutputParamDescriptions {
2063 my ($symbol_type, $symbol, @fields) = @_;
2065 my $params = $SymbolParams{$symbol};
2067 my %field_descrs = ();
2070 %field_descrs = @fields;
2071 delete $field_descrs{"void"};
2072 delete $field_descrs{"Returns"};
2075 if (defined $params) {
2077 my $params_desc = "";
2078 my $missing_parameters = "";
2079 my $unused_parameters = "";
2082 for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
2083 my $param_name = $$params[$j];
2084 my $param_desc = $$params[$j + 1];
2085 my $param_annotations = "";
2087 ($param_desc,$param_annotations) = & ExpandAnnotation($symbol, $param_desc);
2088 $param_desc = &ExpandAbbreviations($symbol, $param_desc);
2089 $param_desc .= $param_annotations;
2090 if ($param_name eq "Returns") {
2091 $returns = "$param_desc";
2092 } elsif ($param_name eq "void") {
2093 #print "!!!! void in params for $symbol?\n";
2096 if (!defined $field_descrs{$param_name}) {
2097 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2098 "Parameter description for $symbol"."::"."$param_name is not used from source code comment block.");
2099 if ($unused_parameters ne "") {
2100 $unused_parameters .= ", ".$param_name;
2102 $unused_parameters = $param_name;
2105 delete $field_descrs{$param_name};
2108 if ($param_name eq "Varargs") {
2109 $param_name = "...";
2111 if($param_desc ne "") {
2112 $params_desc .= "<varlistentry><term><parameter>$param_name</parameter> :</term>\n<listitem><simpara>$param_desc</simpara></listitem></varlistentry>\n";
2117 foreach my $param_name (keys %field_descrs) {
2118 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2119 "Parameter description for $symbol"."::"."$param_name is missing in source code comment block.");
2120 if ($missing_parameters ne "") {
2121 $missing_parameters .= ", ".$param_name;
2123 $missing_parameters = $param_name;
2127 # Signals have an implicit user_data parameter which we describe.
2128 if ($symbol_type eq "SIGNAL") {
2129 $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";
2132 # Start a table if we need one.
2133 if ($params_desc || $returns) {
2134 $output .= "<variablelist role=\"params\">\n";
2135 if ($params_desc ne "") {
2136 #$output .= "<varlistentry><term>Parameters:</term><listitem></listitem></varlistentry>\n";
2137 $output .= $params_desc;
2140 # Output the returns info last.
2142 $output .= "<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>$returns</simpara></listitem></varlistentry>\n";
2146 $output .= "</variablelist>";
2149 # remember missing/unused parameters (needed in tmpl-free build)
2150 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
2151 $AllIncompleteSymbols{$symbol}=$missing_parameters;
2153 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
2154 $AllUnusedSymbols{$symbol}=$unused_parameters;
2157 if (($num_params == 0) && @fields && (scalar(keys(%field_descrs)) > 0)) {
2158 if (! exists ($AllIncompleteSymbols{$symbol})) {
2159 $AllIncompleteSymbols{$symbol}="<parameters>";
2167 #############################################################################
2168 # Function : ParseStabilityLevel
2169 # Description : Parses a stability level and outputs a warning if it isn't
2171 # Arguments : $stability - the stability text.
2172 # $file, $line - context for error message
2173 # $message - description of where the level is from, to use in
2174 # any error message.
2175 # Returns : The parsed stability level string.
2176 #############################################################################
2178 sub ParseStabilityLevel {
2179 my ($stability, $file, $line, $message) = @_;
2181 $stability =~ s/^\s*//;
2182 $stability =~ s/\s*$//;
2183 if ($stability =~ m/^stable$/i) {
2184 $stability = "Stable";
2185 } elsif ($stability =~ m/^unstable$/i) {
2186 $stability = "Unstable";
2187 } elsif ($stability =~ m/^private$/i) {
2188 $stability = "Private";
2190 &LogWarning ($file, $line, "$message is $stability.".
2191 "It should be one of these: Stable, Unstable, or Private.");
2197 #############################################################################
2198 # Function : OutputSGMLFile
2199 # Description : Outputs the final DocBook file for one section.
2200 # Arguments : $file - the name of the file.
2201 # $title - the title from the $MODULE-sections.txt file, which
2202 # will be overridden by the title in the template file.
2203 # $section_id - the SGML id to use for the toplevel tag.
2204 # $includes - comma-separates list of include files added at top
2205 # of synopsis, with '<' '>' around them (if not already enclosed in "").
2206 # $synopsis - reference to the DocBook for the Synopsis part.
2207 # $details - reference to the DocBook for the Details part.
2208 # $signal_synop - reference to the DocBook for the Signal Synopsis part
2209 # $signal_desc - reference to the DocBook for the Signal Description part
2210 # $args_synop - reference to the DocBook for the Arg Synopsis part
2211 # $args_desc - reference to the DocBook for the Arg Description part
2212 # $hierarchy - reference to the DocBook for the Object Hierarchy part
2213 # $interfaces - reference to the DocBook for the Interfaces part
2214 # $implementations - reference to the DocBook for the Known Implementations part
2215 # $prerequisites - reference to the DocBook for the Prerequisites part
2216 # $derived - reference to the DocBook for the Derived Interfaces part
2217 # $file_objects - reference to an array of objects in this file
2218 #############################################################################
2220 sub OutputSGMLFile {
2221 my ($file, $title, $section_id, $includes, $synopsis, $details, $signals_synop, $signals_desc, $args_synop, $args_desc, $hierarchy, $interfaces, $implementations, $prerequisites, $derived, $file_objects) = @_;
2223 #print "Output sgml for file $file with title '$title'\n";
2225 # The edited title overrides the one from the sections file.
2226 my $new_title = $SymbolDocs{"$TMPL_DIR/$file:Title"};
2227 if (defined ($new_title) && $new_title !~ m/^\s*$/) {
2228 $title = $new_title;
2229 #print "Found title: $title\n";
2231 my $short_desc = $SymbolDocs{"$TMPL_DIR/$file:Short_Description"};
2232 if (!defined ($short_desc) || $short_desc =~ m/^\s*$/) {
2235 $short_desc = &ExpandAbbreviations("$title:Short_description",
2237 #print "Found short_desc: $short_desc";
2239 my $long_desc = $SymbolDocs{"$TMPL_DIR/$file:Long_Description"};
2240 if (!defined ($long_desc) || $long_desc =~ m/^\s*$/) {
2243 $long_desc = &ExpandAbbreviations("$title:Long_description",
2245 #print "Found long_desc: $long_desc";
2247 my $see_also = $SymbolDocs{"$TMPL_DIR/$file:See_Also"};
2248 if (!defined ($see_also) || $see_also =~ m%^\s*(<para>)?\s*(</para>)?\s*$%) {
2251 $see_also = &ExpandAbbreviations("$title:See_Also", $see_also);
2252 #print "Found see_also: $see_also";
2255 $see_also = "<refsect1 id=\"$section_id.see-also\">\n<title>See Also</title>\n$see_also\n</refsect1>\n";
2257 my $stability = $SymbolDocs{"$TMPL_DIR/$file:Stability_Level"};
2258 if (!defined ($stability) || $stability =~ m/^\s*$/) {
2261 $stability = &ParseStabilityLevel($stability, $file, $., "Section stability level");
2262 #print "Found stability: $stability";
2265 $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$stability, unless otherwise indicated\n</refsect1>\n";
2266 } elsif ($DEFAULT_STABILITY) {
2267 $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$DEFAULT_STABILITY, unless otherwise indicated\n</refsect1>\n";
2270 my $image = $SymbolDocs{"$TMPL_DIR/$file:Image"};
2271 if (!defined ($image) || $image =~ m/^\s*$/) {
2279 if ($image =~ /jpe?g$/i) {
2280 $format = "format='JPEG'";
2281 } elsif ($image =~ /png$/i) {
2282 $format = "format='PNG'";
2283 } elsif ($image =~ /svg$/i) {
2284 $format = "format='SVG'";
2289 $image = " <inlinegraphic fileref='$image' $format/>\n"
2292 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
2294 my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
2297 my $include_output = "";
2299 foreach $include (split (/,/, $includes)) {
2300 if ($include =~ m/^\".+\"$/) {
2301 $include_output .= "#include ${include}\n";
2304 $include =~ s/^\s+|\s+$//gs;
2305 $include_output .= "#include <${include}>\n";
2308 if ($include_output ne '') {
2309 $include_output = "\n$include_output\n";
2312 my $extralinks = OutputSectionExtraLinks($title,"Section:$file");
2314 my $old_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT";
2315 my $new_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT.new";
2317 open (OUTPUT, ">$new_sgml_file")
2318 || die "Can't create $new_sgml_file: $!";
2320 my $object_anchors = "";
2321 foreach my $object (@$file_objects) {
2322 next if ($object eq $section_id);
2323 my $id = CreateValidSGMLID($object);
2324 #print "Debug: Adding anchor for $object\n";
2325 $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
2328 # We used to output this, but is messes up our UpdateFileIfChanged code
2329 # since it changes every day (and it is only used in the man pages):
2330 # "<refentry id="$section_id" revision="$mday $month $year">"
2332 if ($OUTPUT_FORMAT eq "xml") {
2333 print OUTPUT $doctype_header;
2337 <refentry id="$section_id">
2339 <refentrytitle role="top_of_page" id="$section_id.top_of_page">$title</refentrytitle>
2340 <manvolnum>3</manvolnum>
2343 $image</refmiscinfo>
2346 <refname>$title</refname>
2347 <refpurpose>$short_desc</refpurpose>
2350 <refsynopsisdiv id="$section_id.synopsis" role="synopsis">
2351 <title role="synopsis.title">Synopsis</title>
2353 <synopsis>$include_output$${synopsis}</synopsis>
2355 $$hierarchy$$prerequisites$$derived$$interfaces$$implementations$$args_synop$$signals_synop
2356 <refsect1 id="$section_id.description" role="desc">
2357 <title role="desc.title">Description</title>
2358 $extralinks$long_desc
2360 <refsect1 id="$section_id.details" role="details">
2361 <title role="details.title">Details</title>
2364 $$args_desc$$signals_desc$see_also
2369 return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2373 #############################################################################
2374 # Function : OutputExtraFile
2375 # Description : Copies an "extra" DocBook file into the output directory,
2376 # expanding abbreviations
2377 # Arguments : $file - the source file.
2378 #############################################################################
2379 sub OutputExtraFile {
2384 ($basename = $file) =~ s!^.*/!!;
2386 my $old_sgml_file = "$SGML_OUTPUT_DIR/$basename";
2387 my $new_sgml_file = "$SGML_OUTPUT_DIR/$basename.new";
2391 open(EXTRA_FILE, "<$file") || die "Can't open $file";
2395 $contents = <EXTRA_FILE>;
2398 open (OUTPUT, ">$new_sgml_file")
2399 || die "Can't create $new_sgml_file: $!";
2401 print OUTPUT &ExpandAbbreviations ("$basename file", $contents);
2404 return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2406 #############################################################################
2407 # Function : OutputBook
2408 # Description : Outputs the SGML entities that need to be included into the
2409 # main SGML file for the module.
2410 # Arguments : $book_top - the declarations of the entities, which are added
2411 # at the top of the main SGML file.
2412 # $book_bottom - the references to the entities, which are
2413 # added in the main SGML file at the desired position.
2414 #############################################################################
2417 my ($book_top, $book_bottom) = @_;
2419 my $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top";
2420 my $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top.new";
2422 open (OUTPUT, ">$new_file")
2423 || die "Can't create $new_file: $!";
2424 print OUTPUT $book_top;
2427 &UpdateFileIfChanged ($old_file, $new_file, 0);
2430 $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom";
2431 $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom.new";
2433 open (OUTPUT, ">$new_file")
2434 || die "Can't create $new_file: $!";
2435 print OUTPUT $book_bottom;
2438 &UpdateFileIfChanged ($old_file, $new_file, 0);
2441 # If the main SGML/XML file hasn't been created yet, we create it here.
2442 # The user can tweak it later.
2443 if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
2444 open (OUTPUT, ">$MAIN_SGML_FILE")
2445 || die "Can't create $MAIN_SGML_FILE: $!";
2447 if ($OUTPUT_FORMAT eq "xml") {
2449 <?xml version="1.0"?>
2450 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
2451 "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
2453 <!ENTITY % local.common.attrib "xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'">
2459 <!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
2468 <title>$MODULE Reference Manual</title>
2470 for $MODULE [VERSION].
2471 The latest version of this documentation can be found on-line at
2472 <ulink role="online-location" url="http://[SERVER]/$MODULE/index.html">http://[SERVER]/$MODULE/</ulink>.
2477 <title>[Insert title here]</title>
2481 if (-e $OBJECT_TREE_FILE) {
2483 <chapter id="object-tree">
2484 <title>Object Hierarchy</title>
2485 <xi:include href="xml/tree_index.sgml"/>
2491 <index id="api-index-full">
2492 <title>API Index</title>
2493 <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
2496 <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
2505 #############################################################################
2506 # Function : CreateValidSGML
2507 # Description : This turns any chars which are used in SGML into entities,
2508 # e.g. '<' into '<'
2509 # Arguments : $text - the text to turn into proper SGML.
2510 #############################################################################
2512 sub CreateValidSGML {
2514 $text =~ s/&/&/g; # Do this first, or the others get messed up.
2515 $text =~ s/</</g;
2516 $text =~ s/>/>/g;
2517 # browers render single tabs inconsistently
2518 $text =~ s/([^\s])\t([^\s])/$1 $2/g;
2522 #############################################################################
2523 # Function : ConvertSGMLChars
2524 # Description : This is used for text in source code comment blocks, to turn
2525 # chars which are used in SGML into entities, e.g. '<' into
2526 # '<'. Depending on $SGML_MODE, this is done
2527 # unconditionally or only if the character doesn't seem to be
2528 # part of an SGML construct (tag or entity reference).
2529 # Arguments : $text - the text to turn into proper SGML.
2530 #############################################################################
2532 sub ConvertSGMLChars {
2533 my ($symbol, $text) = @_;
2536 # For the SGML mode only convert to entities outside CDATA sections.
2537 return &ModifyXMLElements ($text, $symbol,
2538 "<!\\[CDATA\\[|<programlisting[^>]*>",
2539 \&ConvertSGMLCharsEndTag,
2540 \&ConvertSGMLCharsCallback);
2542 # For the simple non-sgml mode, convert to entities everywhere.
2543 $text =~ s/&/&/g; # Do this first, or the others get messed up.
2544 $text =~ s/</</g;
2545 $text =~ s/>/>/g;
2551 sub ConvertSGMLCharsEndTag {
2552 if ($_[0] eq "<!\[CDATA\[") {
2555 return "</programlisting>";
2559 sub ConvertSGMLCharsCallback {
2560 my ($text, $symbol, $tag) = @_;
2562 if ($tag =~ m/^<programlisting/) {
2563 # We can handle <programlisting> specially here.
2564 return &ModifyXMLElements ($text, $symbol,
2566 \&ConvertSGMLCharsEndTag,
2567 \&ConvertSGMLCharsCallback2);
2568 } elsif ($tag eq "") {
2569 # If we're not in CDATA convert to entities.
2570 $text =~ s/&(?![a-zA-Z#]+;)/&/g; # Do this first, or the others get messed up.
2571 $text =~ s/<(?![a-zA-Z\/!])/</g;
2572 $text =~ s/(?<![a-zA-Z0-9"'\/-])>/>/g;
2574 # Handle "#include <xxxxx>"
2575 $text =~ s/#include(\s+)<([^>]+)>/#include$1<$2>/g;
2581 sub ConvertSGMLCharsCallback2 {
2582 my ($text, $symbol, $tag) = @_;
2584 # If we're not in CDATA convert to entities.
2585 # We could handle <programlisting> differently, though I'm not sure it helps.
2587 # replace only if its not a tag
2588 $text =~ s/&(?![a-zA-Z#]+;)/&/g; # Do this first, or the others get messed up.
2589 $text =~ s/<(?![a-zA-Z\/!])/</g;
2590 $text =~ s/(?<![a-zA-Z0-9"'\/-])>/>/g;
2592 # Handle "#include <xxxxx>"
2593 $text =~ s/#include(\s+)<([^>]+)>/#include$1<$2>/g;
2599 #############################################################################
2600 # Function : ExpandAnnotation
2601 # Description : This turns annotations into acronym tags.
2602 # Arguments : $symbol - the symbol being documented, for error messages.
2603 # $text - the text to expand.
2604 #############################################################################
2605 sub ExpandAnnotation {
2606 my ($symbol, $param_desc) = @_;
2607 my $param_annotations = "";
2609 # look for annotations at the start of the comment
2610 if ($param_desc =~ m%^\s*\(([^)]*)\):%) {
2613 my $annotation_extra = "";
2616 @annotations = split(/\)\s*\(/,$1);
2617 foreach $annotation (@annotations) {
2618 # need to search for the longest key-match in %AnnotationDefinition
2620 my $match_annotation="";
2622 foreach $annotationdef (keys %AnnotationDefinition) {
2623 if ($annotation =~ m/^$annotationdef/) {
2624 if (length($annotationdef)>$match_length) {
2625 $match_length=length($annotationdef);
2626 $match_annotation=$annotationdef;
2630 if ($match_annotation ne "") {
2631 if ($annotation =~ m%$match_annotation\s+(.*)%) {
2632 $annotation_extra = " $1";
2634 $AnnotationsUsed{$match_annotation} = 1;
2635 $param_annotations .= "[<acronym>$match_annotation</acronym>$annotation_extra]";
2638 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2639 "unknown annotation \"$annotation\" in documentation for $symbol.");
2640 $param_annotations .= "[$annotation]";
2644 $param_desc =~ m/^(.*?)\.*\s*$/s;
2645 $param_desc = "$1. ";
2647 if ($param_annotations ne "") {
2648 $param_annotations = "<emphasis role=\"annotation\">$param_annotations</emphasis>";
2650 return ($param_desc, $param_annotations);
2653 #############################################################################
2654 # Function : ExpandAbbreviations
2655 # Description : This turns the abbreviations function(), macro(), @param,
2656 # %constant, and #symbol into appropriate DocBook markup.
2657 # CDATA sections and <programlisting> parts are skipped.
2658 # Arguments : $symbol - the symbol being documented, for error messages.
2659 # $text - the text to expand.
2660 #############################################################################
2662 sub ExpandAbbreviations {
2663 my ($symbol, $text) = @_;
2665 # Convert "|[" and "]|" into the start and end of program listing examples.
2666 # FIXME: we like to have a way to specify parameters e.g. language="c"
2667 $text =~ s%\|\[%<informalexample><programlisting>%g;
2668 $text =~ s%\]\|%</programlisting></informalexample>%g;
2669 # TODO: check for a xml comment after |[ and pick the language attribute from
2672 # keep CDATA unmodified, preserve ulink tags (ideally we preseve all tags
2674 return &ModifyXMLElements ($text, $symbol,
2675 "<!\\[CDATA\\[|<ulink[^>]*>|<programlisting[^>]*>|<!DOCTYPE",
2676 \&ExpandAbbreviationsEndTag,
2677 \&ExpandAbbreviationsCallback);
2681 # Returns the end tag corresponding to the given start tag.
2682 sub ExpandAbbreviationsEndTag {
2683 my ($start_tag) = @_;
2685 if ($start_tag eq "<!\[CDATA\[") {
2687 } elsif ($start_tag eq "<!DOCTYPE") {
2689 } elsif ($start_tag =~ m/<(\w+)/) {
2694 # Called inside or outside each CDATA or <programlisting> section.
2695 sub ExpandAbbreviationsCallback {
2696 my ($text, $symbol, $tag) = @_;
2698 if ($tag =~ m/^<programlisting/) {
2699 # Handle any embedded CDATA sections.
2700 return &ModifyXMLElements ($text, $symbol,
2702 \&ExpandAbbreviationsEndTag,
2703 \&ExpandAbbreviationsCallback2);
2704 } elsif ($tag eq "") {
2705 # We are outside any CDATA or <programlisting> sections, so we expand
2706 # any gtk-doc abbreviations.
2708 # Convert 'function()' or 'macro()'.
2709 # if there is abc_*_def() we don't want to make a link to _def()
2710 # FIXME: also handle abc(....) : but that would need to be done recursively :/
2711 $text =~ s/([^\*.\w])(\w+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2712 # handle #Object.func()
2713 $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2715 # Convert '@param', but not '\@param'.
2716 $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)/$1<parameter>$2<\/parameter>/g;
2717 $text =~ s/\\\@/\@/g;
2719 # Convert '%constant', but not '\%constant'.
2720 # Also allow negative numbers, e.g. %-1.
2721 $text =~ s/(\A|[^\\])\%(-?\w+)/$1.&MakeXRef($2, &tagify($2, "literal"));/eg;
2722 $text =~ s/\\\%/\%/g;
2724 # Convert '#symbol', but not '\#symbol'.
2725 $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)/$1.&MakeHashXRef($2, "type");/eg;
2729 # FIXME: should we skip urls that are already tagged? (e.g. <literal>http://...</literal>)
2730 # this is apparently also called for markup and not just for plain text
2732 #$text =~ s%(http|https|ftp)://(.*?)((?:\s|,|\)|\]|\<|\.\s))%<ulink url="$1://$2">$2</ulink>$3%g;
2734 # TODO: optionally check all words from $text against internal symbols and
2735 # warn if those could be xreffed, but miss a %,# or ()
2741 # This is called inside a <programlisting>
2742 sub ExpandAbbreviationsCallback2 {
2743 my ($text, $symbol, $tag) = @_;
2746 # We are inside a <programlisting> but outside any CDATA sections,
2747 # so we expand any gtk-doc abbreviations.
2748 # FIXME: why is this different from &ExpandAbbreviationsCallback(),
2749 # why not just call it
2750 $text =~ s/#(\w+)/&MakeHashXRef($1, "");/eg;
2757 my ($symbol, $tag) = @_;;
2760 # Check for things like '#include', '#define', and skip them.
2761 if ($PreProcessorDirectives{$symbol}) {
2765 # Get rid of any special '-struct' suffix.
2766 $text =~ s/-struct$//;
2768 # If the symbol is in the form "Object::signal", then change the symbol to
2769 # "Object-signal" and use "signal" as the text.
2770 if ($symbol =~ s/::/-/) {
2774 # If the symbol is in the form "Object:property", then change the symbol to
2775 # "Object--property" and use "property" as the text.
2776 if ($symbol =~ s/:/--/) {
2781 $text = tagify ($text, $tag);
2784 return &MakeXRef($symbol, $text);
2788 #############################################################################
2789 # Function : ModifyXMLElements
2790 # Description : Looks for given XML element tags within the text, and calls
2791 # the callback on pieces of text inside & outside those elements.
2792 # Used for special handling of text inside things like CDATA
2793 # and <programlisting>.
2794 # Arguments : $text - the text.
2795 # $symbol - the symbol currently being documented (only used for
2797 # $start_tag_regexp - the regular expression to match start tags.
2798 # e.g. "<!\\[CDATA\\[|<programlisting[^>]*>" to match
2799 # CDATA sections or programlisting elements.
2800 # $end_tag_func - function which is passed the matched start tag
2801 # and should return the appropriate end tag string.
2802 # $callback - callback called with each part of the text. It is
2803 # called with a piece of text, the symbol being
2804 # documented, and the matched start tag or "" if the text
2805 # is outside the XML elements being matched.
2806 #############################################################################
2807 sub ModifyXMLElements {
2808 my ($text, $symbol, $start_tag_regexp, $end_tag_func, $callback) = @_;
2809 my ($before_tag, $start_tag, $end_tag_regexp, $end_tag);
2812 while ($text =~ m/$start_tag_regexp/s) {
2813 $before_tag = $`; # Prematch for last successful match string
2814 $start_tag = $&; # Last successful match
2815 $text = $'; # Postmatch for last successful match string
2817 $result .= &$callback ($before_tag, $symbol, "");
2818 $result .= $start_tag;
2820 # get the mathing end-tag for current tag
2821 $end_tag_regexp = &$end_tag_func ($start_tag);
2823 if ($text =~ m/$end_tag_regexp/s) {
2828 $result .= &$callback ($before_tag, $symbol, $start_tag);
2829 $result .= $end_tag;
2831 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2832 "Can't find tag end: $end_tag_regexp in docs for: $symbol.");
2833 # Just assume it is all inside the tag.
2834 $result .= &$callback ($text, $symbol, $start_tag);
2839 # Handle any remaining text outside the tags.
2840 $result .= &$callback ($text, $symbol, "");
2849 # Adds a tag around some text.
2850 # e.g tagify("Text", "literal") => "<literal>Text</literal>".
2852 my ($text, $elem) = @_;
2853 return "<" . $elem . ">" . $text . "</" . $elem . ">";
2857 #############################################################################
2858 # Function : MakeXRef
2859 # Description : This returns a cross-reference link to the given symbol.
2860 # Though it doesn't try to do this for a few standard C types
2861 # that it knows won't be in the documentation.
2862 # Arguments : $symbol - the symbol to try to create a XRef to.
2863 # $text - text text to put inside the XRef, defaults to $symbol
2864 #############################################################################
2867 my ($symbol, $text) = ($_[0], $_[1]);
2869 $symbol =~ s/^\s+//;
2870 $symbol =~ s/\s+$//;
2872 if (!defined($text)) {
2875 # Get rid of special '-struct' suffix.
2876 $text =~ s/-struct$//;
2879 if ($symbol =~ m/ /) {
2883 #print "Getting type link for $symbol -> $text\n";
2885 my $symbol_id = &CreateValidSGMLID ($symbol);
2886 return "<link linkend=\"$symbol_id\">$text</link>";
2890 #############################################################################
2891 # Function : MakeIndexterms
2892 # Description : This returns a indexterm elements for the given symbol
2893 # Arguments : $symbol - the symbol to create indexterms for
2894 #############################################################################
2896 sub MakeIndexterms {
2897 my ($symbol, $id) = @_;
2901 # make the index useful, by ommiting the namespace when sorting
2902 if ($NAME_SPACE ne "") {
2903 if ($symbol =~ m/^$NAME_SPACE\_?(.*)/i) {
2904 $sortas=" sortas=\"$1\"";
2908 if (exists $Deprecated{$symbol}) {
2909 $terms .= "<indexterm zone=\"$id\" role=\"deprecated\"><primary$sortas>$symbol</primary></indexterm>";
2910 $IndexEntriesDeprecated{$symbol}=$id;
2911 $IndexEntriesFull{$symbol}=$id;
2913 if (exists $Since{$symbol}) {
2914 my $since = $Since{$symbol};
2918 $terms .= "<indexterm zone=\"$id\" role=\"$since\"><primary$sortas>$symbol</primary></indexterm>";
2920 $IndexEntriesSince{$symbol}=$id;
2921 $IndexEntriesFull{$symbol}=$id;
2924 $terms .= "<indexterm zone=\"$id\"><primary$sortas>$symbol</primary></indexterm>";
2925 $IndexEntriesFull{$symbol}=$id;
2931 #############################################################################
2932 # Function : MakeDeprecationNote
2933 # Description : This returns a deprecation warning for the given symbol.
2934 # Arguments : $symbol - the symbol to try to create a warning for.
2935 #############################################################################
2937 sub MakeDeprecationNote {
2938 my ($symbol) = $_[0];
2941 if (exists $Deprecated{$symbol}) {
2942 $desc .= "<warning>";
2944 if ($Deprecated{$symbol} =~ /^\s*([0-9\.]+)\s*:/) {
2945 $desc .= "<para><literal>$symbol</literal> has been deprecated since version $1 and should not be used in newly-written code.";
2947 $desc .= "<para><literal>$symbol</literal> is deprecated and should not be used in newly-written code.";
2949 if ($Deprecated{$symbol} ne "") {
2950 $note = &ExpandAbbreviations($symbol, $Deprecated{$symbol});
2951 $note =~ s/^\s*([0-9\.]+)\s*:\s*//;
2954 $note =~ s%\n{2,}%\n</para>\n<para>\n%g;
2955 $desc .= " " . $note;
2957 $desc .= "</para></warning>\n";
2962 #############################################################################
2963 # Function : MakeConditionDescription
2964 # Description : This returns a sumary of conditions for the given symbol.
2965 # Arguments : $symbol - the symbol to try to create the sumary.
2966 #############################################################################
2968 sub MakeConditionDescription {
2969 my ($symbol) = $_[0];
2972 if (exists $Deprecated{$symbol}) {
2977 if ($Deprecated{$symbol} =~ /^\s*(.*?)\s*$/) {
2978 $desc .= "deprecated:$1";
2980 $desc .= "deprecated";
2984 if (exists $Since{$symbol}) {
2989 if ($Since{$symbol} =~ /^\s*(.*?)\s*$/) {
2990 $desc .= "since:$1";
2996 if (exists $StabilityLevel{$symbol}) {
3000 $desc .= "stability:".$StabilityLevel{$symbol};
3004 $desc=" condition=\"".$desc."\"";
3005 #print "condition for '$symbol' = '$desc'\n";
3010 #############################################################################
3011 # Function : GetHierarchy
3012 # Description : Returns the DocBook output describing the ancestors and
3013 # immediate children of a GObject subclass. It uses the
3014 # global @Objects and @ObjectLevels arrays to walk the tree.
3015 # Arguments : $object - the GtkObject subclass.
3016 #############################################################################
3021 # Find object in the objects array.
3027 for ($i = 0; $i < @Objects; $i++) {
3029 if ($ObjectLevels[$i] <= $level) {
3032 elsif ($ObjectLevels[$i] == $level + 1) {
3033 push (@children, $Objects[$i]);
3036 elsif ($Objects[$i] eq $object) {
3039 $level = $ObjectLevels[$i];
3046 # Walk up the hierarchy, pushing ancestors onto the ancestors array.
3048 push (@ancestors, $object);
3049 #print "Level: $level\n";
3050 while ($level > 1) {
3052 if ($ObjectLevels[$j] < $level) {
3053 push (@ancestors, $Objects[$j]);
3054 $level = $ObjectLevels[$j];
3055 #print "Level: $level\n";
3059 # Output the ancestors list, indented and with links.
3060 my $hierarchy = "<synopsis>\n";
3062 for ($i = $#ancestors; $i >= 0; $i--) {
3064 # Don't add a link to the current object, i.e. when i == 0.
3066 my $ancestor_id = &CreateValidSGMLID ($ancestors[$i]);
3067 $link_text = "<link linkend=\"$ancestor_id\">$ancestors[$i]</link>";
3069 $link_text = "$ancestors[$i]";
3072 $hierarchy .= " $link_text\n";
3074 # $hierarchy .= ' ' x ($level * 6 - 3) . "|\n";
3075 $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3079 for ($i = 0; $i <= $#children; $i++) {
3080 my $id = &CreateValidSGMLID ($children[$i]);
3081 my $link_text = "<link linkend=\"$id\">$children[$i]</link>";
3082 $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3084 $hierarchy .= "</synopsis>\n";
3090 #############################################################################
3091 # Function : GetInterfaces
3092 # Description : Returns the DocBook output describing the interfaces
3093 # implemented by a class. It uses the global %Interfaces hash.
3094 # Arguments : $object - the GtkObject subclass.
3095 #############################################################################
3102 # Find object in the objects array.
3103 if (exists($Interfaces{$object})) {
3104 my @ifaces = split(' ', $Interfaces{$object});
3109 for ($i = 0; $i <= $#ifaces; $i++) {
3110 my $id = &CreateValidSGMLID ($ifaces[$i]);
3111 $text .= " <link linkend=\"$id\">$ifaces[$i]</link>";
3112 if ($i < $#ifaces - 1) {
3115 elsif ($i < $#ifaces) {
3130 #############################################################################
3131 # Function : GetImplementations
3132 # Description : Returns the DocBook output describing the implementations
3133 # of an interface. It uses the global %Interfaces hash.
3134 # Arguments : $object - the GtkObject subclass.
3135 #############################################################################
3137 sub GetImplementations {
3142 foreach my $key (keys %Interfaces) {
3143 if ($Interfaces{$key} =~ /\b$object\b/) {
3144 push (@impls, $key);
3148 @impls = sort @impls;
3151 $object is implemented by
3153 for ($i = 0; $i <= $#impls; $i++) {
3154 my $id = &CreateValidSGMLID ($impls[$i]);
3155 $text .= " <link linkend=\"$id\">$impls[$i]</link>";
3156 if ($i < $#impls - 1) {
3159 elsif ($i < $#impls) {
3174 #############################################################################
3175 # Function : GetPrerequisites
3176 # Description : Returns the DocBook output describing the prerequisites
3177 # of an interface. It uses the global %Prerequisites hash.
3178 # Arguments : $iface - the interface.
3179 #############################################################################
3181 sub GetPrerequisites {
3186 if (exists($Prerequisites{$iface})) {
3191 my @prereqs = split(' ', $Prerequisites{$iface});
3192 for ($i = 0; $i <= $#prereqs; $i++) {
3193 my $id = &CreateValidSGMLID ($prereqs[$i]);
3194 $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
3195 if ($i < $#prereqs - 1) {
3198 elsif ($i < $#prereqs) {
3212 #############################################################################
3213 # Function : GetDerived
3214 # Description : Returns the DocBook output describing the derived interfaces
3215 # of an interface. It uses the global %Prerequisites hash.
3216 # Arguments : $iface - the interface.
3217 #############################################################################
3225 foreach my $key (keys %Prerequisites) {
3226 if ($Prerequisites{$key} =~ /\b$iface\b/) {
3227 push (@derived, $key);
3230 if ($#derived >= 0) {
3231 @derived = sort @derived;
3234 $iface is required by
3236 for ($i = 0; $i <= $#derived; $i++) {
3237 my $id = &CreateValidSGMLID ($derived[$i]);
3238 $text .= " <link linkend=\"$id\">$derived[$i]</link>";
3239 if ($i < $#derived - 1) {
3242 elsif ($i < $#derived) {
3257 #############################################################################
3258 # Function : GetSignals
3259 # Description : Returns the synopsis and detailed description DocBook output
3260 # for the signal handlers of a given GtkObject subclass.
3261 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
3262 #############################################################################
3270 for ($i = 0; $i <= $#SignalObjects; $i++) {
3271 if ($SignalObjects[$i] eq $object) {
3272 #print "Found signal: $SignalNames[$i]\n";
3273 my $name = $SignalNames[$i];
3274 my $symbol = "${object}::${name}";
3275 my $id = &CreateValidSGMLID ("$object-$name");
3277 my $pad = ' ' x (46 - length($name));
3278 $synop .= " "<link linkend=\"$id\">$name</link>"$pad ";
3280 $desc .= "<refsect2 id=\"$id\" role=\"signal\"><title>The <literal>"$name"</literal> signal</title>\n";
3281 $desc .= MakeIndexterms($symbol, $id);
3283 $desc .= OutputSymbolExtraLinks($symbol);
3285 $desc .= "<programlisting>";
3287 $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
3288 my $type_modifier = defined($1) ? $1 : "";
3291 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
3293 my $ret_type_len = length ($type_modifier) + length ($pointer)
3295 my $ret_type_output = "$type_modifier$xref$pointer"
3296 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
3298 $desc .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
3300 my $sourceparams = $SourceSymbolParams{$symbol};
3301 my @params = split ("\n", $SignalPrototypes[$i]);
3304 my $type_len = length("gpointer");
3305 my $name_len = length("user_data");
3306 # do two passes, the first one is to calculate padding
3307 for ($l = 0; $l < 2; $l++) {
3308 for ($j = 0; $j <= $#params; $j++) {
3309 # allow alphanumerics, '_', '[' & ']' in param names
3310 if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
3313 if (defined($sourceparams)) {
3314 $name = $$sourceparams[$PARAM_FIELD_COUNT * $j];
3319 if (!defined($name)) {
3323 if (length($type) + length($pointer) > $type_len) {
3324 $type_len = length($type) + length($pointer);
3326 if (length($name) > $name_len) {
3327 $name_len = length($name);
3331 $xref = &MakeXRef ($type, &tagify($type, "type"));
3332 $pad = ' ' x ($type_len - length($type) - length($pointer));
3333 $desc .= "$xref$pad $pointer$name,\n";
3334 $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
3337 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3338 "Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]");
3342 $xref = &MakeXRef ("gpointer", &tagify("gpointer", "type"));
3343 $pad = ' ' x ($type_len - length("gpointer"));
3344 $desc .= "$xref$pad user_data)";
3346 my $flags = $SignalFlags[$i];
3347 my $flags_string = "";
3349 if (defined ($flags)) {
3350 if ($flags =~ m/f/) {
3351 $flags_string = "Run First";
3353 elsif ($flags =~ m/l/) {
3354 $flags_string = "Run Last";
3356 elsif ($flags =~ m/c/) {
3357 $flags_string = "Cleanup";
3359 if ($flags =~ m/r/) {
3360 if ($flags_string) { $flags_string .= " / "; }
3361 $flags_string .= "No Recursion";
3363 if ($flags =~ m/d/) {
3364 if ($flags_string) { $flags_string .= " / "; }
3365 $flags_string .= "Has Details";
3367 if ($flags =~ m/a/) {
3368 if ($flags_string) { $flags_string .= " / "; }
3369 $flags_string .= "Action";
3371 if ($flags =~ m/h/) {
3372 if ($flags_string) { $flags_string .= " / "; }
3373 $flags_string .= "No Hooks";
3379 $synop .= ": $flags_string\n";
3381 $pad = ' ' x (5 + $name_len - length("user_data"));
3382 $desc .= "$pad : $flags_string</programlisting>\n";
3387 $desc .= "</programlisting>\n";
3390 $desc .= &MakeDeprecationNote($symbol);
3392 my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
3393 my $parameters_output = 0;
3395 $AllSymbols{$symbol} = 1;
3396 if (defined ($SymbolDocs{$symbol})) {
3397 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3399 # Try to insert the parameter table at the author's desired
3400 # position. Otherwise we need to tag it onto the end.
3401 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
3402 $parameters_output = 1;
3404 $desc .= $symbol_docs;
3406 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
3407 $AllDocumentedSymbols{$symbol} = 1;
3411 if ($parameters_output == 0) {
3412 $desc .= $parameters;
3414 $desc .= OutputSymbolTraits ($symbol);
3415 $desc .= "</refsect2>";
3418 return ($synop, $desc);
3422 #############################################################################
3423 # Function : GetArgs
3424 # Description : Returns the synopsis and detailed description DocBook output
3425 # for the Args of a given GtkObject subclass.
3426 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
3427 #############################################################################
3433 my $child_synop = "";
3434 my $child_desc = "";
3435 my $style_synop = "";
3436 my $style_desc = "";
3439 for ($i = 0; $i <= $#ArgObjects; $i++) {
3440 if ($ArgObjects[$i] eq $object) {
3441 #print "Found arg: $ArgNames[$i]\n";
3442 my $name = $ArgNames[$i];
3443 my $flags = $ArgFlags[$i];
3444 my $flags_string = "";
3448 if ($flags =~ m/c/) {
3449 $kind = "child property";
3452 elsif ($flags =~ m/s/) {
3453 $kind = "style property";
3460 # Remember only one colon so we don't clash with signals.
3461 my $symbol = "${object}:${name}";
3462 # use two dashes and ev. an extra separator here for the same reason.
3463 my $id = &CreateValidSGMLID ("$object--$id_sep$name");
3465 my $type = $ArgTypes[$i];
3467 my $range = $ArgRanges[$i];
3468 my $range_output = CreateValidSGML ($range);
3469 my $default = $ArgDefaults[$i];
3470 my $default_output = CreateValidSGML ($default);
3472 if ($type eq "GtkString") {
3475 if ($type eq "GtkSignal") {
3476 $type = "GtkSignalFunc, gpointer";
3477 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
3478 . &MakeXRef ("gpointer");
3479 } elsif ($type =~ m/^(\w+)\*$/) {
3480 $type_output = &MakeXRef ($1, &tagify($1, "type")) . "*";
3482 $type_output = &MakeXRef ($type, &tagify($type, "type"));
3485 if ($flags =~ m/r/) {
3486 $flags_string = "Read";
3488 if ($flags =~ m/w/) {
3489 if ($flags_string) { $flags_string .= " / "; }
3490 $flags_string .= "Write";
3492 if ($flags =~ m/x/) {
3493 if ($flags_string) { $flags_string .= " / "; }
3494 $flags_string .= "Construct";
3496 if ($flags =~ m/X/) {
3497 if ($flags_string) { $flags_string .= " / "; }
3498 $flags_string .= "Construct Only";
3501 $AllSymbols{$symbol} = 1;
3503 if (defined($SymbolDocs{$symbol}) &&
3504 !IsEmptyDoc($SymbolDocs{$symbol})) {
3505 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3506 #print ".. [$SymbolDocs{$symbol}][$blurb]\n";
3507 $AllDocumentedSymbols{$symbol} = 1;
3510 if (!($ArgBlurbs[$i] eq "")) {
3511 $AllDocumentedSymbols{$symbol} = 1;
3513 # FIXME: print a warning?
3514 #print ".. no description\n";
3516 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
3519 my $pad1 = " " x (24 - length ($name));
3520 my $pad2 = " " x (20 - length ($type));
3522 my $arg_synop = " "<link linkend=\"$id\">$name</link>"$pad1 $type_output $pad2 : $flags_string\n";
3523 my $arg_desc = "<refsect2 id=\"$id\" role=\"property\"><title>The <literal>"$name"</literal> $kind</title>\n";
3524 $arg_desc .= MakeIndexterms($symbol, $id);
3526 $arg_desc .= OutputSymbolExtraLinks($symbol);
3528 $arg_desc .= "<programlisting> "$name"$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
3529 $arg_desc .= &MakeDeprecationNote($symbol);
3530 $arg_desc .= $blurb;
3532 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
3534 if ($default ne "") {
3535 $arg_desc .= "<para>Default value: $default_output</para>\n";
3537 $arg_desc .= OutputSymbolTraits ($symbol);
3538 $arg_desc .= "</refsect2>\n";
3540 if ($flags =~ m/c/) {
3541 $child_synop .= $arg_synop;
3542 $child_desc .= $arg_desc;
3544 elsif ($flags =~ m/s/) {
3545 $style_synop .= $arg_synop;
3546 $style_desc .= $arg_desc;
3549 $synop .= $arg_synop;
3554 return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
3558 #############################################################################
3559 # Function : ReadSourceDocumentation
3560 # Description : This reads in the documentation embedded in comment blocks
3561 # in the source code (for Gnome).
3563 # Parameter descriptions override any in the template files.
3564 # Function descriptions are placed before any description from
3565 # the template files.
3567 # It recursively descends the source directory looking for .c
3568 # files and scans them looking for specially-formatted comment
3571 # Arguments : $source_dir - the directory to scan.
3572 #############m###############################################################
3574 sub ReadSourceDocumentation {
3575 my ($source_dir) = @_;
3576 my ($file, $dir, @suffix_list, $suffix);
3577 #print "Scanning source directory: $source_dir\n";
3579 # This array holds any subdirectories found.
3582 @suffix_list = split (/,/, $SOURCE_SUFFIXES);
3584 opendir (SRCDIR, $source_dir)
3585 || die "Can't open source directory $source_dir: $!";
3587 foreach $file (readdir (SRCDIR)) {
3588 if ($file =~ /^\./) {
3590 } elsif (-d "$source_dir/$file") {
3591 push (@subdirs, $file);
3592 } elsif (@suffix_list) {
3593 foreach $suffix (@suffix_list) {
3594 if ($file =~ m/\.\Q${suffix}\E$/) {
3595 &ScanSourceFile ("$source_dir/$file");
3598 } elsif ($file =~ m/\.[ch]$/) {
3599 &ScanSourceFile ("$source_dir/$file");
3604 # Now recursively scan the subdirectories.
3605 foreach $dir (@subdirs) {
3606 next if ($IGNORE_FILES =~ m/(\s|^)\Q${dir}\E(\s|$)/);
3607 &ReadSourceDocumentation ("$source_dir/$dir");
3612 #############################################################################
3613 # Function : ScanSourceFile
3614 # Description : Scans one source file looking for specially-formatted comment
3615 # blocks. Later &MergeSourceDocumentation is used to merge any
3616 # documentation found with the documentation already read in
3617 # from the template files.
3619 # Arguments : $file - the file to scan.
3620 #############################################################################
3622 sub ScanSourceFile {
3626 if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
3629 &LogWarning ($file, 1, "Can't find basename for this filename.");
3633 # Check if the basename is in the list of files to ignore.
3634 if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
3638 #print "DEBUG: Scanning $file\n";
3640 open (SRCFILE, $file)
3641 || die "Can't open $file: $!";
3642 my $in_comment_block = 0;
3644 my ($in_description, $in_return, $in_since, $in_stability, $in_deprecated);
3645 my ($description, $return_desc, $return_start, $return_style);
3646 my ($since_desc, $stability_desc, $deprecated_desc);
3648 my $ignore_broken_returns;
3651 # Look for the start of a comment block.
3652 if (!$in_comment_block) {
3653 if (m%^\s*/\*.*\*/%) {
3654 #one-line comment - not gtkdoc
3655 } elsif (m%^\s*/\*\*\s%) {
3656 #print "Found comment block start\n";
3658 $in_comment_block = 1;
3660 # Reset all the symbol data.
3662 $in_description = 0;
3671 $deprecated_desc = "";
3672 $stability_desc = "";
3673 $current_param = -1;
3674 $ignore_broken_returns = 0;
3680 # We're in a comment block. Check if we've found the end of it.
3683 # maybe its not even meant to be a gtk-doc comment?
3684 &LogWarning ($file, $., "Symbol name not found at the start of the comment block.");
3686 # Add the return value description onto the end of the params.
3688 push (@params, "Returns");
3689 push (@params, $return_desc);
3690 if ($return_style eq 'broken') {
3691 &LogWarning ($file, $., "Free-form return value description in $symbol. Use `Returns:' to avoid ambiguities.");
3694 # Convert special SGML characters
3695 $description = &ConvertSGMLChars ($symbol, $description);
3697 for ($k = 1; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3698 $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
3701 # Handle Section docs
3702 if ($symbol =~ m/SECTION:\s*(.*)/) {
3706 if (scalar %KnownSymbols) {
3707 if ((! defined($KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"})) || $KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"} != 1) {
3708 &LogWarning ($file, $., "Section $real_symbol is not defined in the $MODULE-section.txt file.");
3712 #print "SECTION DOCS found in source for : '$real_symbol'\n";
3713 $ignore_broken_returns = 1;
3714 for ($k = 0; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3715 #print " '".$params[$k]."'\n";
3716 $params[$k] = "\L$params[$k]";
3718 if ($params[$k] eq "short_description") {
3719 $key = "$TMPL_DIR/$real_symbol:Short_Description";
3720 } elsif ($params[$k] eq "see_also") {
3721 $key = "$TMPL_DIR/$real_symbol:See_Also";
3722 } elsif ($params[$k] eq "title") {
3723 $key = "$TMPL_DIR/$real_symbol:Title";
3724 } elsif ($params[$k] eq "stability") {
3725 $key = "$TMPL_DIR/$real_symbol:Stability_Level";
3726 } elsif ($params[$k] eq "section_id") {
3727 $key = "$TMPL_DIR/$real_symbol:Section_Id";
3728 } elsif ($params[$k] eq "include") {
3729 $key = "$TMPL_DIR/$real_symbol:Include";
3730 } elsif ($params[$k] eq "image") {
3731 $key = "$TMPL_DIR/$real_symbol:Image";
3733 if (defined($key)) {
3734 $SourceSymbolDocs{$key}=$params[$k+1];
3735 $SourceSymbolSourceFile{$key} = $file;
3736 $SourceSymbolSourceLine{$key} = $.;
3739 $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
3740 $SourceSymbolSourceFile{"$TMPL_DIR/$real_symbol:Long_Description"} = $file;
3741 $SourceSymbolSourceLine{"$TMPL_DIR/$real_symbol:Long_Description"} = $.;
3742 #$SourceSymbolTypes{$symbol} = "SECTION";
3744 #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
3745 $SourceSymbolDocs{$symbol} = $description;
3746 $SourceSymbolParams{$symbol} = [ @params ];
3747 # FIXME $SourceSymbolTypes{$symbol} = "STRUCT,SIGNAL,ARG,FUNCTION,MACRO";
3748 #if (defined $DeclarationTypes{$symbol}) {
3749 # $SourceSymbolTypes{$symbol} = $DeclarationTypes{$symbol}
3751 $SourceSymbolSourceFile{$symbol} = $file;
3752 $SourceSymbolSourceLine{$symbol} = $.;
3756 ($since_desc, my @extra_lines) = split ("\n", $since_desc);
3757 $since_desc =~ s/^\s+//;
3758 $since_desc =~ s/\s+$//;
3759 #print "Since($symbol) : [$since_desc]\n";
3760 $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
3761 if(scalar @extra_lines) {
3762 &LogWarning ($file, $., "multi-line since docs found");
3766 if ($stability_desc) {
3767 $stability_desc = &ParseStabilityLevel($stability_desc, $file, $., "Stability level for $symbol");
3768 $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
3771 if ($deprecated_desc) {
3772 if (exists $Deprecated{$symbol}) {
3775 # don't warn for signals and properties
3776 #if ($symbol !~ m/::?(.*)/) {
3777 if (defined $DeclarationTypes{$symbol}) {
3778 &LogWarning ($file, $.,
3779 "$symbol is deprecated in the inline comments, but no deprecation guards were found around the declaration.".
3780 " (See the --deprecated-guards option for gtkdoc-scan.)");
3783 $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
3787 $in_comment_block = 0;
3791 # Get rid of ' * ' at start of every line in the comment block.
3793 # But make sure we don't get rid of the newline at the end.
3797 #print "DEBUG: scanning :$_";
3799 # If we haven't found the symbol name yet, look for it.
3801 if (m%^\s*(SECTION:\s*\S+)%) {
3803 #print "SECTION DOCS found in source for : '$symbol'\n";
3804 $ignore_broken_returns = 1;
3805 } elsif (m%^\s*([\w:-]*\w)\s*:?\s*(\([a-z ]+\)\s*)*$%) {
3807 #print "SYMBOL DOCS found in source for : '$symbol'\n";
3812 # If we're in the return value description, add it to the end.
3814 # If we find another valid returns line, we assume that the first
3815 # one was really part of the description.
3816 if (m/^\s*(returns:|return\s+value:)/i) {
3817 if ($return_style eq 'broken') {
3818 $description .= $return_start . $return_desc;
3821 if ($return_style eq 'sane') {
3822 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3824 $return_style = 'sane';
3825 $ignore_broken_returns = 1;
3827 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3828 $description .= $return_start . $return_desc;
3830 $return_style = 'broken';
3832 } elsif (m%^\s*since:%i) {
3836 } elsif (m%^\s*stability:%i) {
3837 $stability_desc = $';
3840 } elsif (m%^\s*deprecated:%i) {
3841 $deprecated_desc = $';
3851 if (m/^\s*(returns:|return\s+value:)/i) {
3852 if ($return_style eq 'broken') {
3853 $description .= $return_start . $return_desc;
3856 if ($return_style eq 'sane') {
3857 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3859 $return_style = 'sane';
3860 $ignore_broken_returns = 1;
3864 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3866 $return_style = 'broken';
3870 } elsif (m%^\s*deprecated:%i) {
3871 $deprecated_desc = $';
3874 } elsif (m%^\s*stability:%i) {
3875 $stability_desc = $';
3884 if ($in_stability) {
3885 if (m/^\s*(returns:|return\s+value:)/i) {
3886 if ($return_style eq 'broken') {
3887 $description .= $return_start . $return_desc;
3890 if ($return_style eq 'sane') {
3891 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3893 $return_style = 'sane';
3894 $ignore_broken_returns = 1;
3898 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3900 $return_style = 'broken';
3904 } elsif (m%^\s*deprecated:%i) {
3905 $deprecated_desc = $';
3908 } elsif (m%^\s*since:%i) {
3913 $stability_desc .= $_;
3918 if ($in_deprecated) {
3919 if (m/^\s*(returns:|return\s+value:)/i) {
3920 if ($return_style eq 'broken') {
3921 $description .= $return_start . $return_desc;
3924 if ($return_style eq 'sane') {
3925 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3927 $return_style = 'sane';
3928 $ignore_broken_returns = 1;
3932 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3934 $return_style = 'broken';
3938 } elsif (m%^\s*since:%i) {
3942 } elsif (m%^\s*stability:%i) {
3943 $stability_desc = $';
3947 $deprecated_desc .= $_;
3952 # If we're in the description part, check for the 'Returns:' line.
3953 # If that isn't found, add the text to the end.
3954 if ($in_description) {
3955 # Get rid of 'Description:'
3956 s%^\s*Description:%%;
3958 if (m/^\s*(returns:|return\s+value:)/i) {
3959 if ($return_style eq 'broken') {
3960 $description .= $return_start . $return_desc;
3963 if ($return_style eq 'sane') {
3964 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3966 $return_style = 'sane';
3967 $ignore_broken_returns = 1;
3971 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3973 $return_style = 'broken';
3977 } elsif (m%^\s*since:%i) {
3981 } elsif (m%^\s*deprecated:%i) {
3982 $deprecated_desc = $';
3985 } elsif (m%^\s*stability:%i) {
3986 $stability_desc = $';
3995 # We must be in the parameters. Check for the empty line below them.
3997 $in_description = 1;
4001 # Look for a parameter name.
4002 if (m%^\s*@(\S+)\s*:\s*%) {
4003 my $param_name = $1;
4004 my $param_desc = $';
4006 #print "Found parameter: $param_name\n";
4007 # Allow '...' as the Varargs parameter.
4008 if ($param_name eq "...") {
4009 $param_name = "Varargs";
4011 if ("\L$param_name" eq "returns") {
4012 $return_style = 'sane';
4013 $ignore_broken_returns = 1;
4015 push (@params, $param_name);
4016 push (@params, $param_desc);
4017 $current_param += $PARAM_FIELD_COUNT;
4021 # We must be in the middle of a parameter description, so add it on
4022 # to the last element in @params.
4023 if ($current_param == -1) {
4024 &LogWarning ($file, $., "Parsing comment block file : parameter expected.");
4026 $params[$#params] .= $_;
4032 #############################################################################
4033 # Function : OutputMissingDocumentation
4034 # Description : Outputs report of documentation coverage to a file
4037 #############################################################################
4039 sub OutputMissingDocumentation {
4040 my $old_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.txt";
4041 my $new_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.new";
4043 my $n_documented = 0;
4044 my $n_incomplete = 0;
4050 my $buffer_deprecated = "";
4051 my $buffer_descriptions = "";
4053 open(UNDOCUMENTED, ">$new_undocumented_file")
4054 || die "Can't create $new_undocumented_file";
4056 foreach $symbol (sort (keys (%AllSymbols))) {
4057 # FIXME: should we print LogWarnings for undocumented stuff?
4059 #my $ssfile = &GetSymbolSourceFile($symbol);
4060 #my $ssline = &GetSymbolSourceLine($symbol);
4061 #my $location = "defined at " . (defined($ssfile)?$ssfile:"?") . ":" . (defined($ssline)?$ssline:"0") . "\n";
4063 if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include|Section_Id|Image)/) {
4065 if (exists ($AllDocumentedSymbols{$symbol})) {
4067 if (exists ($AllIncompleteSymbols{$symbol})) {
4069 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4070 #$buffer .= "\t0: ".$location;
4072 } elsif (exists $Deprecated{$symbol}) {
4073 if (exists ($AllIncompleteSymbols{$symbol})) {
4075 $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4076 #$buffer .= "\t1a: ".$location;
4078 $buffer_deprecated .= $symbol . "\n";
4079 #$buffer .= "\t1b: ".$location;
4082 if (exists ($AllIncompleteSymbols{$symbol})) {
4084 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4085 #$buffer .= "\t2a: ".$location;
4087 $buffer .= $symbol . "\n";
4088 #$buffer .= "\t2b: ".$location;
4091 } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
4093 #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
4094 #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
4095 #print "%%%% $symbol : $len1,$len2\n";
4096 if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
4097 || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
4100 # cut off the leading namespace ($TMPL_DIR)
4101 $symbol =~ m/^.*\/(.*)$/;
4102 $buffer_descriptions .= $1 . "\n";
4107 $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
4112 $percent = ($n_documented / $total) * 100.0;
4115 printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
4116 print UNDOCUMENTED "$n_documented symbols documented.\n";
4117 print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
4118 print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
4120 print UNDOCUMENTED $buffer;
4121 close (UNDOCUMENTED);
4123 return &UpdateFileIfChanged ($old_undocumented_file, $new_undocumented_file, 0);
4125 printf "%.0f%% symbol docs coverage", $percent;
4126 print "($n_documented symbols documented, $n_incomplete symbols incomplete, " . ($total - $n_documented) . " not documented)\n";
4127 print "See $MODULE-undocumented.txt for a list of missing docs.\nThe doc coverage percentage doesn't include intro sections.\n";
4131 #############################################################################
4132 # Function : OutputUndeclaredSymbols
4133 # Description : Outputs symbols that are listed in the section file, but not
4134 # declaration is found in the sources
4137 #############################################################################
4139 sub OutputUndeclaredSymbols {
4140 my $old_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.txt";
4141 my $new_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.new";
4143 open(UNDECLARED, ">$new_undeclared_file")
4144 || die "Can't create $new_undeclared_file";
4146 if (%UndeclaredSymbols) {
4147 print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
4148 print UNDECLARED "\n";
4149 print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
4153 return &UpdateFileIfChanged ($old_undeclared_file, $new_undeclared_file, 0);
4156 #############################################################################
4157 # Function : OutputUnusedSymbols
4158 # Description : Outputs symbols that are documented in comments, but not
4159 # declared in the sources
4162 #############################################################################
4164 sub OutputUnusedSymbols {
4166 my $old_unused_file = "$ROOT_DIR/$MODULE-unused.txt";
4167 my $new_unused_file = "$ROOT_DIR/$MODULE-unused.new";
4169 open (UNUSED, ">$new_unused_file")
4170 || die "Can't open $new_unused_file";
4172 foreach $symbol (sort keys (%Declarations)) {
4173 if (!defined ($DeclarationOutput{$symbol})) {
4174 print (UNUSED "$symbol\n");
4178 foreach $symbol (sort (keys (%AllUnusedSymbols))) {
4179 print (UNUSED "$symbol(" . $AllUnusedSymbols{$symbol} . ")\n");
4183 if ($num_unused != 0) {
4184 &LogWarning ($old_unused_file, 1, "$num_unused unused declarations.".
4185 "They should be added to $MODULE-sections.txt in the appropriate place.");
4188 return &UpdateFileIfChanged ($old_unused_file, $new_unused_file, 0);
4192 #############################################################################
4193 # Function : OutputAllSymbols
4194 # Description : Outputs list of all symbols to a file
4197 #############################################################################
4199 sub OutputAllSymbols {
4200 my $n_documented = 0;
4206 open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
4207 || die "Can't create $ROOT_DIR/$MODULE-symbols.txt: $!";
4209 foreach $symbol (sort (keys (%AllSymbols))) {
4210 print SYMBOLS $symbol . "\n";
4216 #############################################################################
4217 # Function : OutputSymbolsWithoutSince
4218 # Description : Outputs list of all symbols without a since tag to a file
4221 #############################################################################
4223 sub OutputSymbolsWithoutSince {
4224 my $n_documented = 0;
4230 open (SYMBOLS, ">$ROOT_DIR/$MODULE-nosince.txt")
4231 || die "Can't create $ROOT_DIR/$MODULE-nosince.txt: $!";
4233 foreach $symbol (sort (keys (%SourceSymbolDocs))) {
4234 if (!defined $Since{$symbol}) {
4235 print SYMBOLS $symbol . "\n";
4243 #############################################################################
4244 # Function : MergeSourceDocumentation
4245 # Description : This merges documentation read from a source file into the
4246 # documentation read in from a template file.
4248 # Parameter descriptions override any in the template files.
4249 # Function descriptions are placed before any description from
4250 # the template files.
4253 #############################################################################
4255 sub MergeSourceDocumentation {
4259 if (scalar %SymbolDocs) {
4260 @Symbols=keys (%SymbolDocs);
4261 #print "num existing entries: ".(scalar @Symbols)."\n";
4262 #print " ",$Symbols[0], " ",$Symbols[1],"\n";
4265 # filter scanned declarations, with what we suppress from -sections.txt
4267 foreach $symbol (keys (%Declarations)) {
4268 if (defined($KnownSymbols{$symbol}) && $KnownSymbols{$symbol} == 1) {
4272 # , add the rest from -sections.txt
4273 foreach $symbol (keys (%KnownSymbols)) {
4274 if ($KnownSymbols{$symbol} == 1) {
4278 # and add whats found in the source
4279 foreach $symbol (keys (%SourceSymbolDocs)) {
4282 @Symbols = keys (%tmp);
4283 #print "num source entries: ".(scalar @Symbols)."\n";
4285 foreach $symbol (@Symbols) {
4286 $AllSymbols{$symbol} = 1;
4288 my $have_tmpl_docs = 0;
4290 ## See if the symbol is documented in template
4291 my $tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4292 my $check_tmpl_doc =$tmpl_doc;
4293 # remove all xml-tags and whitespaces (don't kill <include href="..."> tags)
4294 $check_tmpl_doc =~ s/<\/?[a-z]+>//gi;
4295 $check_tmpl_doc =~ s/\s//g;
4297 if ($check_tmpl_doc ne "") {
4298 $have_tmpl_docs = 1;
4299 #print "## [$check_tmpl_doc]\n";
4304 if (exists ($SourceSymbolDocs{$symbol})) {
4305 my $type = $DeclarationTypes {$symbol};
4307 #print "merging [$symbol] from source\n";
4309 my $item = "Parameter";
4310 if (defined ($type)) {
4311 if ($type eq 'STRUCT') {
4313 } elsif ($type eq 'ENUM') {
4315 } elsif ($type eq 'UNION') {
4322 my $src_doc = $SourceSymbolDocs{$symbol};
4323 # remove leading and training whitespaces
4324 $src_doc =~ s/^\s+//;
4325 $src_doc =~ s/\s+$//;
4327 # Don't output warnings for overridden titles as titles are
4328 # automatically generated in the -sections.txt file, and thus they
4329 # are often overridden.
4330 if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
4331 # check if content is different
4332 if ($tmpl_doc ne $src_doc) {
4333 #print "[$tmpl_doc] [$src_doc]\n";
4334 &LogWarning ($SourceSymbolSourceFile{$symbol}, $SourceSymbolSourceLine{$symbol},
4335 "Documentation in template ".$SymbolSourceFile{$symbol}.":".$SymbolSourceLine{$symbol}." for $symbol being overridden by inline comments.");
4339 if ($src_doc ne "") {
4340 $AllDocumentedSymbols{$symbol} = 1;
4343 # Convert <!--PARAMETERS--> with any blank lines around it to
4344 # a </para> followed by <!--PARAMETERS--> followed by <para>.
4345 $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
4347 # Do not add <para> to nothing, it breaks missing docs checks.
4348 my $src_doc_para = "";
4349 if ($src_doc ne "") {
4350 # If there is a blank line, finish the paragraph and start another.
4351 $src_doc = &ConvertBlankLines ($src_doc, $symbol);
4352 $src_doc_para = "<para>\n$src_doc\n</para>";
4354 # FIXME: this is questionable, as we can't make assumtions on the content really
4355 #$src_doc_para =~ s%^<para>\n(<refsect[1-9])%$1%gms;
4356 #$src_doc_para =~ s%^<para>\n<para>%<para>%gms;
4357 #$src_doc_para =~ s%(</refsect[1-9]>)\n</para>$%$1%gms;
4358 #print "$symbol : [$src_doc][$src_doc_para]\n";
4361 if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
4362 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4363 } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
4364 # For the title/summary/see also section docs we don't want to
4365 # add any <para> tags.
4366 $SymbolDocs{$symbol} = "$src_doc"
4368 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4372 if ($symbol =~ m/.*::.*/) {
4373 # For signals we prefer the param names from the source docs,
4374 # since the ones from the templates are likely to contain the
4375 # artificial argn names which are generated by gtkdoc-scangobj.
4376 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4377 # FIXME: we need to check for empty docs here as well!
4379 # The templates contain the definitive parameter names and order,
4380 # so we will not change that. We only override the actual text.
4381 my $tmpl_params = $SymbolParams{$symbol};
4382 if (!defined ($tmpl_params)) {
4383 #print "No merge needed for $symbol\n";
4384 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4385 # FIXME: we still like to get the number of params and merge
4386 # 1) we would noticed that params have been removed/renamed
4387 # 2) we would catch undocumented params
4388 # params are not (yet) exported in -decl.txt so that we
4389 # could easily grab them :/
4391 my $params = $SourceSymbolParams{$symbol};
4393 #print "Merge needed for $symbol, tmpl_params: ",$#$tmpl_params,", source_params: ",$#$params," \n";
4394 for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4395 my $tmpl_param_name = $$tmpl_params[$j];
4397 # Allow '...' as the Varargs parameter.
4398 if ($tmpl_param_name eq "...") {
4399 $tmpl_param_name = "Varargs";
4402 # Try to find the param in the source comment documentation.
4405 #print " try merge param $tmpl_param_name\n";
4406 for ($k = 0; $k <= $#$params; $k += $PARAM_FIELD_COUNT) {
4407 my $param_name = $$params[$k];
4408 my $param_desc = $$params[$k + 1];
4410 #print " test param $param_name\n";
4411 # We accept changes in case, since the Gnome source
4412 # docs contain a lot of these.
4413 if ("\L$param_name" eq "\L$tmpl_param_name") {
4416 # Override the description.
4417 $$tmpl_params[$j + 1] = $param_desc;
4419 # Set the name to "" to mark it as used.
4425 # If it looks like the parameters are there, but not
4426 # in the right place, try to explain a bit better.
4427 if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
4428 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4429 "Parameters for $symbol must start on the line immediately after the function or macro name.");
4433 # Now we output a warning if parameters have been described which
4435 for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
4436 my $param_name = $$params[$j];
4438 # the template builder cannot detect if a macro returns
4440 if(($type eq "MACRO") && ($param_name eq "Returns")) {
4441 # FIXME: do we need to add it then to tmpl_params[] ?
4442 my $num=$#$tmpl_params;
4443 #print " adding Returns: to macro docs for $symbol.\n";
4444 $$tmpl_params[$num+1]="Returns";
4445 $$tmpl_params[$num+2]=$$params[$j+1];
4448 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4449 "$item described in source code comment block but does not exist. $type: $symbol $item: $param_name.");
4455 if ($have_tmpl_docs) {
4456 $AllDocumentedSymbols{$symbol} = 1;
4457 #print "merging [$symbol] from template\n";
4460 #print "[$symbol] undocumented\n";
4464 # if this symbol is documented, check if docs are complete
4465 $check_tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4466 # remove all xml-tags and whitespaces
4467 #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
4468 $check_tmpl_doc =~ s/<.*?>//g;
4469 $check_tmpl_doc =~ s/\s//g;
4470 if ($check_tmpl_doc ne "") {
4471 my $tmpl_params = $SymbolParams{$symbol};
4472 if (defined ($tmpl_params)) {
4473 my $type = $DeclarationTypes {$symbol};
4475 my $item = "Parameter";
4476 if (defined ($type)) {
4477 if ($type eq 'STRUCT') {
4479 } elsif ($type eq 'ENUM') {
4481 } elsif ($type eq 'UNION') {
4488 #print "Check param docs for $symbol, tmpl_params: ",$#$tmpl_params," entries, type=$type\n";
4490 if ($#$tmpl_params > 0) {
4492 for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4493 # Output a warning if the parameter is empty and
4494 # remember for stats.
4495 my $tmpl_param_name = $$tmpl_params[$j];
4496 my $tmpl_param_desc = $$tmpl_params[$j + 1];
4497 if ($tmpl_param_name ne "void" && $tmpl_param_desc !~ m/\S/) {
4498 if (exists ($AllIncompleteSymbols{$symbol})) {
4499 $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
4501 $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
4503 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4504 "$item description for $symbol"."::"."$tmpl_param_name is missing in source code comment block.");
4509 if ($#$tmpl_params == 0) {
4510 $AllIncompleteSymbols{$symbol}="<items>";
4511 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4512 "$item descriptions for $symbol are missing in source code comment block.");
4514 # $#$tmpl_params==-1 means we don't know about parameters
4515 # this unfortunately does not tell if there should be some
4520 #print "num doc entries: ".(scalar %SymbolDocs)."\n";
4523 #############################################################################
4524 # Function : IsEmptyDoc
4525 # Description : Check if a doc-string is empty. Its also regarded as empty if
4526 # it only consist of whitespace or e.g. FIXME.
4527 # Arguments : the doc-string
4528 #############################################################################
4532 if ($doc =~ /^\s*$/) {
4536 if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
4544 # This converts blank lines to "</para><para>", but only outside CDATA and
4545 # <programlisting> tags.
4546 sub ConvertBlankLines {
4547 return &ModifyXMLElements ($_[0], $_[1],
4548 "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
4549 \&ConvertBlankLinesEndTag,
4550 \&ConvertBlankLinesCallback);
4554 sub ConvertBlankLinesEndTag {
4555 if ($_[0] eq "<!\[CDATA\[") {
4557 } elsif ($_[0] eq "|[") {
4560 return "</programlisting>";
4564 sub ConvertBlankLinesCallback {
4565 my ($text, $symbol, $tag) = @_;
4567 # If we're not in CDATA or a <programlisting> we convert blank lines so
4568 # they start a new <para>.
4570 $text =~ s%\n{2,}%\n</para>\n<para>\n%g;
4577 #############################################################################
4578 # LIBRARY FUNCTIONS - These functions are used in both gtkdoc-mkdb and
4579 # gtkdoc-mktmpl and should eventually be moved to a
4581 #############################################################################
4583 #############################################################################
4584 # Function : ReadDeclarationsFile
4585 # Description : This reads in a file containing the function/macro/enum etc.
4588 # Note that in some cases there are several declarations with
4589 # the same name, e.g. for conditional macros. In this case we
4590 # set a flag in the %DeclarationConditional hash so the
4591 # declaration is not shown in the docs.
4593 # If a macro and a function have the same name, e.g. for
4594 # gtk_object_ref, the function declaration takes precedence.
4596 # Some opaque structs are just declared with 'typedef struct
4597 # _name name;' in which case the declaration may be empty.
4598 # The structure may have been found later in the header, so
4599 # that overrides the empty declaration.
4601 # Arguments : $file - the declarations file to read
4602 # $override - if declarations in this file should override
4603 # any current declaration.
4604 #############################################################################
4606 sub ReadDeclarationsFile {
4607 my ($file, $override) = @_;
4609 if ($override == 0) {
4611 %DeclarationTypes = ();
4612 %DeclarationConditional = ();
4613 %DeclarationOutput = ();
4617 || die "Can't open $file: $!";
4618 my $declaration_type = "";
4619 my $declaration_name;
4621 my $is_deprecated = 0;
4623 if (!$declaration_type) {
4624 if (m/^<([^>]+)>/) {
4625 $declaration_type = $1;
4626 $declaration_name = "";
4627 #print "Found declaration: $declaration_type\n";
4631 if (m%^<NAME>(.*)</NAME>%) {
4632 $declaration_name = $1;
4633 } elsif (m%^<DEPRECATED/>%) {
4635 } elsif (m%^</$declaration_type>%) {
4636 #print "Found end of declaration: $declaration_name\n";
4637 # Check that the declaration has a name
4638 if ($declaration_name eq "") {
4639 print "ERROR: $declaration_type has no name $file:$.\n";
4642 # If the declaration is an empty typedef struct _XXX XXX
4643 # set the flag to indicate the struct has a typedef.
4644 if ($declaration_type eq 'STRUCT'
4645 && $declaration =~ m/^\s*$/) {
4646 #print "Struct has typedef: $declaration_name\n";
4647 $StructHasTypedef{$declaration_name} = 1;
4650 # Check if the symbol is already defined.
4651 if (defined ($Declarations{$declaration_name})
4652 && $override == 0) {
4653 # Function declarations take precedence.
4654 if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
4656 } elsif ($declaration_type eq 'FUNCTION') {
4657 if ($is_deprecated) {
4658 $Deprecated{$declaration_name} = "";
4660 $Declarations{$declaration_name} = $declaration;
4661 $DeclarationTypes{$declaration_name} = $declaration_type;
4662 } elsif ($DeclarationTypes{$declaration_name}
4663 eq $declaration_type) {
4664 # If the existing declaration is empty, or is just a
4665 # forward declaration of a struct, override it.
4666 if ($declaration_type eq 'STRUCT') {
4667 if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4668 if ($is_deprecated) {
4669 $Deprecated{$declaration_name} = "";
4671 $Declarations{$declaration_name} = $declaration;
4672 } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4673 # Ignore an empty or forward declaration.
4675 &LogWarning ($file, $., "Structure $declaration_name has multiple definitions.");
4678 # set flag in %DeclarationConditional hash for
4679 # multiply defined macros/typedefs.
4680 $DeclarationConditional{$declaration_name} = 1;
4683 &LogWarning ($file, $., "$declaration_name has multiple definitions.");
4686 if ($is_deprecated) {
4687 $Deprecated{$declaration_name} = "";
4689 $Declarations{$declaration_name} = $declaration;
4690 $DeclarationTypes{$declaration_name} = $declaration_type;
4693 $declaration_type = "";
4704 #############################################################################
4705 # Function : ReadSignalsFile
4706 # Description : This reads in an existing file which contains information on
4707 # all GTK signals. It creates the arrays @SignalNames and
4708 # @SignalPrototypes containing info on the signals. The first
4709 # line of the SignalPrototype is the return type of the signal
4710 # handler. The remaining lines are the parameters passed to it.
4711 # The last parameter, "gpointer user_data" is always the same
4712 # so is not included.
4713 # Arguments : $file - the file containing the signal handler prototype
4715 #############################################################################
4717 sub ReadSignalsFile {
4725 my $signal_prototype;
4727 # Reset the signal info.
4728 @SignalObjects = ();
4730 @SignalReturns = ();
4732 @SignalPrototypes = ();
4737 if (!open (INPUT, $file)) {
4738 warn "Can't open $file - skipping signals\n";
4745 $signal_object = "";
4747 $signal_returns = "";
4748 $signal_prototype = "";
4751 if (m/^<NAME>(.*)<\/NAME>/) {
4753 if ($signal_name =~ m/^(.*)::(.*)$/) {
4754 $signal_object = $1;
4755 ($signal_name = $2) =~ s/_/-/g;
4756 #print "Found signal: $signal_name\n";
4758 &LogWarning ($file, $., "Invalid signal name: $signal_name.");
4760 } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
4761 $signal_returns = $1;
4762 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4764 } elsif (m%^</SIGNAL>%) {
4765 #print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
4766 push (@SignalObjects, $signal_object);
4767 push (@SignalNames, $signal_name);
4768 push (@SignalReturns, $signal_returns);
4769 push (@SignalFlags, $signal_flags);
4770 push (@SignalPrototypes, $signal_prototype);
4773 $signal_prototype .= $_;
4781 #############################################################################
4782 # Function : ReadTemplateFile
4783 # Description : This reads in the manually-edited documentation file
4784 # corresponding to the file currently being created, so we can
4785 # insert the documentation at the appropriate places.
4786 # It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
4787 # is a hash of arrays.
4788 # NOTE: This function is duplicated in gtkdoc-mktmpl (but
4789 # slightly different).
4790 # Arguments : $docsfile - the template file to read in.
4791 # $skip_unused_params - 1 if the unused parameters should be
4793 #############################################################################
4795 sub ReadTemplateFile {
4796 my ($docsfile, $skip_unused_params) = @_;
4798 my $template = "$docsfile.sgml";
4799 if (! -f $template) {
4800 #print "File doesn't exist: $template\n";
4803 #print "Reading $template\n";
4805 # start with empty hashes, we merge the source comment for each file
4811 my $current_type = ""; # Type of symbol being read.
4812 my $current_symbol = ""; # Name of symbol being read.
4813 my $symbol_doc = ""; # Description of symbol being read.
4814 my @params; # Parameter names and descriptions of current
4815 # function/macro/function typedef.
4816 my $current_param = -1; # Index of parameter currently being read.
4817 # Note that the param array contains pairs
4818 # of param name & description.
4819 my $in_unused_params = 0; # True if we are reading in the unused params.
4820 my $in_deprecated = 0;
4822 my $in_stability = 0;
4824 open (DOCS, "$template")
4825 || die "Can't open $template: $!";
4827 if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
4830 if ($symbol eq "Title"
4831 || $symbol eq "Short_Description"
4832 || $symbol eq "Long_Description"
4833 || $symbol eq "See_Also"
4834 || $symbol eq "Stability_Level"
4835 || $symbol eq "Include"
4836 || $symbol eq "Image") {
4838 $symbol = $docsfile . ":" . $symbol;
4841 #print "Found symbol: $symbol\n";
4842 # Remember file and line for the symbol
4843 $SymbolSourceFile{$symbol} = $template;
4844 $SymbolSourceLine{$symbol} = $.;
4846 # Store previous symbol, but remove any trailing blank lines.
4847 if ($current_symbol ne "") {
4848 $symbol_doc =~ s/\s+$//;
4849 $SymbolTypes{$current_symbol} = $current_type;
4850 $SymbolDocs{$current_symbol} = $symbol_doc;
4852 # Check that the stability level is valid.
4853 if ($StabilityLevel{$current_symbol}) {
4854 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4857 if ($current_param >= 0) {
4858 $SymbolParams{$current_symbol} = [ @params ];
4860 # Delete any existing params in case we are overriding a
4861 # previously read template.
4862 delete $SymbolParams{$current_symbol};
4865 $current_type = $type;
4866 $current_symbol = $symbol;
4867 $current_param = -1;
4868 $in_unused_params = 0;
4875 } elsif (m/^<!-- # Unused Parameters # -->/) {
4876 #print "DEBUG: Found unused parameters\n";
4877 $in_unused_params = 1;
4880 } elsif ($in_unused_params && $skip_unused_params) {
4881 # When outputting the DocBook we skip unused parameters.
4882 #print "DEBUG: Skipping unused param: $_";
4886 # Check if param found. Need to handle "..." and "format...".
4887 if (s/^\@([\w\.]+):\040?//) {
4888 my $param_name = $1;
4889 my $param_desc = $_;
4890 # Allow variations of 'Returns'
4891 if ($param_name =~ m/^[Rr]eturns?$/) {
4892 $param_name = "Returns";
4895 # strip trailing whitespaces and blank lines
4898 #print "Found param for symbol $current_symbol : '$param_name'= '$_'";
4900 if ($param_name eq "Deprecated") {
4902 $Deprecated{$current_symbol} = $_;
4903 } elsif ($param_name eq "Since") {
4906 $Since{$current_symbol} = $_;
4907 } elsif ($param_name eq "Stability") {
4909 $StabilityLevel{$current_symbol} = $_;
4911 push (@params, $param_name);
4912 push (@params, $param_desc);
4913 $current_param += $PARAM_FIELD_COUNT;
4916 # strip trailing whitespaces and blank lines
4921 if ($in_deprecated) {
4922 $Deprecated{$current_symbol} .= $_;
4923 } elsif ($in_since) {
4924 &LogWarning ($template, $., "multi-line since docs found");
4925 #$Since{$current_symbol} .= $_;
4926 } elsif ($in_stability) {
4927 $StabilityLevel{$current_symbol} .= $_;
4928 } elsif ($current_param >= 0) {
4929 $params[$current_param] .= $_;
4938 # Remember to finish the current symbol doccs.
4939 if ($current_symbol ne "") {
4941 $symbol_doc =~ s/\s+$//;
4942 $SymbolTypes{$current_symbol} = $current_type;
4943 $SymbolDocs{$current_symbol} = $symbol_doc;
4945 # Check that the stability level is valid.
4946 if ($StabilityLevel{$current_symbol}) {
4947 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4950 if ($current_param >= 0) {
4951 $SymbolParams{$current_symbol} = [ @params ];
4953 # Delete any existing params in case we are overriding a
4954 # previously read template.
4955 delete $SymbolParams{$current_symbol};
4964 #############################################################################
4965 # Function : ReadObjectHierarchy
4966 # Description : This reads in the $MODULE-hierarchy.txt file containing all
4967 # the GtkObject subclasses described in this module (and their
4969 # It places them in the @Objects array, and places their level
4970 # in the object hierarchy in the @ObjectLevels array, at the
4971 # same index. GtkObject, the root object, has a level of 1.
4973 # FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
4974 # as it goes along, this should be split out into a separate
4978 #############################################################################
4980 sub ReadObjectHierarchy {
4984 if (! -f $OBJECT_TREE_FILE) {
4987 if (!open (INPUT, $OBJECT_TREE_FILE)) {
4988 warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
4992 # FIXME: use $OUTPUT_FORMAT
4993 # my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.$OUTPUT_FORMAT";
4994 my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
4995 my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
4997 open (OUTPUT, ">$new_tree_index")
4998 || die "Can't create $new_tree_index: $!";
5000 if ($OUTPUT_FORMAT eq "xml") {
5001 my $tree_header = $doctype_header;
5003 $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
5004 print (OUTPUT "$tree_header");
5006 print (OUTPUT "<screen>\n");
5008 # Only emit objects if they are supposed to be documented, or if
5009 # they have documented children. To implement this, we maintain a
5010 # stack of pending objects which will be emitted if a documented
5012 my @pending_objects = ();
5013 my @pending_levels = ();
5017 my $level = (length($`)) / 2 + 1;
5020 while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
5021 my $pobject = pop(@pending_objects);
5022 my $plevel = pop(@pending_levels);
5025 push (@pending_objects, $object);
5026 push (@pending_levels, $level);
5028 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5029 while ($#pending_levels >= 0) {
5030 $object = shift @pending_objects;
5031 $level = shift @pending_levels;
5032 $xref = &MakeXRef ($object);
5034 print (OUTPUT ' ' x ($level * 4), "$xref\n");
5035 push (@Objects, $object);
5036 push (@ObjectLevels, $level);
5040 # LogWarning ($OBJECT_TREE_FILE, $., "unknown type $object");
5044 print (OUTPUT "</screen>\n");
5049 &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
5054 #############################################################################
5055 # Function : ReadInterfaces
5056 # Description : This reads in the $MODULE.interfaces file.
5059 #############################################################################
5061 sub ReadInterfaces {
5064 if (! -f $INTERFACES_FILE) {
5067 if (!open (INPUT, $INTERFACES_FILE)) {
5068 warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
5074 my ($object, @ifaces) = split;
5075 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5076 my @knownIfaces = ();
5078 # filter out private interfaces, but leave foreign interfaces
5079 foreach my $iface (@ifaces) {
5080 if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
5081 push (@knownIfaces, $iface);
5085 $Interfaces{$object} = join(' ', @knownIfaces);
5091 #############################################################################
5092 # Function : ReadPrerequisites
5093 # Description : This reads in the $MODULE.prerequisites file.
5096 #############################################################################
5098 sub ReadPrerequisites {
5099 %Prerequisites = ();
5101 if (! -f $PREREQUISITES_FILE) {
5104 if (!open (INPUT, $PREREQUISITES_FILE)) {
5105 warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
5111 my ($iface, @prereqs) = split;
5112 if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
5113 my @knownPrereqs = ();
5115 # filter out private prerequisites, but leave foreign prerequisites
5116 foreach my $prereq (@prereqs) {
5117 if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
5118 push (@knownPrereqs, $prereq);
5122 $Prerequisites{$iface} = join(' ', @knownPrereqs);
5128 #############################################################################
5129 # Function : ReadArgsFile
5130 # Description : This reads in an existing file which contains information on
5131 # all GTK args. It creates the arrays @ArgObjects, @ArgNames,
5132 # @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
5134 # Arguments : $file - the file containing the arg information.
5135 #############################################################################
5150 # Reset the args info.
5163 if (!open (INPUT, $file)) {
5164 warn "Can't open $file - skipping args\n";
5181 if (m/^<NAME>(.*)<\/NAME>/) {
5183 if ($arg_name =~ m/^(.*)::(.*)$/) {
5185 ($arg_name = $2) =~ s/_/-/g;
5186 #print "Found arg: $arg_name\n";
5188 &LogWarning ($file, $., "Invalid argument name: $arg_name");
5190 } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
5192 } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
5194 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
5196 } elsif (m/^<NICK>(.*)<\/NICK>/) {
5198 } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
5200 if ($arg_blurb eq "(null)") {
5202 &LogWarning ($file, $., "Property ${arg_object}:${arg_name} has no documentation.");
5204 } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
5206 } elsif (m%^</ARG>%) {
5207 #print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
5208 push (@ArgObjects, $arg_object);
5209 push (@ArgNames, $arg_name);
5210 push (@ArgTypes, $arg_type);
5211 push (@ArgRanges, $arg_range);
5212 push (@ArgFlags, $arg_flags);
5213 push (@ArgNicks, $arg_nick);
5214 push (@ArgBlurbs, $arg_blurb);
5215 push (@ArgDefaults, $arg_default);
5224 #############################################################################
5225 # Function : CheckIsObject
5226 # Description : Returns 1 if the given name is a GObject or a subclass.
5227 # It uses the global @Objects array.
5228 # Note that the @Objects array only contains classes in the
5229 # current module and their ancestors - not all GObject classes.
5230 # Arguments : $name - the name to check.
5231 #############################################################################
5237 foreach $object (@Objects) {
5238 if ($object eq $name) {
5246 #############################################################################
5247 # Function : MakeReturnField
5248 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
5249 # Arguments : $str - the string to pad.
5250 #############################################################################
5252 sub MakeReturnField {
5255 return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));
5258 #############################################################################
5259 # Function : GetSymbolSourceFile
5260 # Description : Get the filename where the symbol docs where taken from.
5261 # Arguments : $symbol - the symbol name
5262 #############################################################################
5264 sub GetSymbolSourceFile {
5267 if (defined($SourceSymbolSourceFile{$symbol})) {
5268 return $SourceSymbolSourceFile{$symbol};
5269 } elsif (defined($SymbolSourceFile{$symbol})) {
5270 return $SymbolSourceFile{$symbol};
5276 #############################################################################
5277 # Function : GetSymbolSourceLine
5278 # Description : Get the file line where the symbol docs where taken from.
5279 # Arguments : $symbol - the symbol name
5280 #############################################################################
5282 sub GetSymbolSourceLine {
5285 if (defined($SourceSymbolSourceLine{$symbol})) {
5286 return $SourceSymbolSourceLine{$symbol};
5287 } elsif (defined($SymbolSourceLine{$symbol})) {
5288 return $SymbolSourceLine{$symbol};