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 # the annotations are defined at:
300 # http://live.gnome.org/GObjectIntrospection/Annotations
301 my %AnnotationDefinition = (
302 'allow-none' => "NULL is ok, both for passing and for returning.",
303 'array' => "Parameter points to an array of items.",
304 'default' => "Default parameter value (for in case the <acronym>shadows</acronym>-to function has less parameters).",
305 'element-type' => "Generics and defining elements of containers and arrays.",
306 'error-domains' => "Typed errors. Similar to throws in Java.",
307 'in' => "Parameter for input. Default is <acronym>transfer none</acronym>.",
308 'inout' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
309 'in-out' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
310 'not-error' => "A GError parameter is not to be handled like a normal GError.",
311 'out' => "Parameter for returning results. Default is <acronym>transfer full</acronym>.",
312 'transfer container' => "Free data container after the code is done.",
313 'transfer full' => "Free data after the code is done.",
314 'transfer none' => "Don't free data after the code is done.",
315 'scope call' => "The callback is valid only during the call to the method.",
316 'scope async' => "The callback is valid until first called.",
317 'scope notfied' => "The callback is valid until the GDestroyNotify argument is called.",
318 'type' => "Override the parsed C type with given type"
321 # Create the root DocBook output directory if it doens't exist.
322 if (! -e $SGML_OUTPUT_DIR) {
323 mkdir ("$SGML_OUTPUT_DIR", 0777)
324 || die "Can't create directory: $SGML_OUTPUT_DIR";
327 # Function and other declaration output settings.
328 my $RETURN_TYPE_FIELD_WIDTH = 20;
329 my $SYMBOL_FIELD_WIDTH = 36;
330 my $SIGNAL_FIELD_WIDTH = 16;
331 my $PARAM_FIELD_COUNT = 2;
333 &ReadKnownSymbols ("$ROOT_DIR/$MODULE-sections.txt");
334 &ReadSignalsFile ($SIGNALS_FILE);
335 &ReadArgsFile ($ARGS_FILE);
336 &ReadObjectHierarchy;
340 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-decl.txt", 0);
341 if (-f "$ROOT_DIR/$MODULE-overrides.txt") {
342 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-overrides.txt", 1);
345 for my $dir (@SOURCE_DIRS) {
346 &ReadSourceDocumentation ($dir);
349 my $changed = &OutputSGML ("$ROOT_DIR/$MODULE-sections.txt");
351 # If any of the DocBook SGML files have changed, update the timestamp file (so
352 # it can be used for Makefile dependencies).
353 if ($changed || ! -e "$ROOT_DIR/sgml.stamp") {
355 # try to detect the common prefix
356 # GtkWidget, GTK_WIDGET, gtk_widget -> gtk
357 if ($NAME_SPACE eq "") {
364 foreach my $symbol (keys(%IndexEntriesFull)) {
365 if(($NAME_SPACE eq "") || $symbol =~ /^$NAME_SPACE/i) {
366 if (length($symbol)>$pos) {
367 $letter=substr($symbol,$pos,1);
368 # stop prefix scanning
369 if ($letter eq "_") {
373 # Should we also stop on a uppercase char, if last was lowercase
374 # GtkWidget, if we have the 'W' and had the 't' before
375 # or should we count upper and lowercase, and stop one 2nd uppercase, if we already had a lowercase
376 # GtkWidget, the 'W' would be the 2nd uppercase and with 't','k' we had lowercase chars before
377 # need to recound each time as this is per symbol
378 $prefix{uc($letter)}++;
382 if ($letter ne "" && $letter ne "_") {
385 foreach $letter (keys(%prefix)) {
386 #print "$letter: $prefix{$letter}.\n";
387 if ($prefix{$letter}>$maxsymbols) {
389 $maxsymbols=$prefix{$letter};
392 $ratio = scalar(keys(%IndexEntriesFull)) / $prefix{$maxletter};
393 #print "most symbols start with $maxletter, that is ". (100 * $ratio) ." %\n";
396 $NAME_SPACE .= $maxletter;
403 } while ($ratio > 0.9);
404 #print "most symbols start with $NAME_SPACE\n";
408 &OutputDeprecatedIndex;
410 &OutputAnnotationGlossary;
412 open (TIMESTAMP, ">$ROOT_DIR/sgml.stamp")
413 || die "Can't create $ROOT_DIR/sgml.stamp: $!";
414 print (TIMESTAMP "timestamp");
418 #############################################################################
419 # Function : OutputObjectList
420 # Description : This outputs the alphabetical list of objects, in a columned
422 # FIXME: Currently this also outputs ancestor objects
423 # which may not actually be in this module.
425 #############################################################################
427 sub OutputObjectList {
430 # FIXME: use $OUTPUT_FORMAT
431 # my $old_object_index = "$SGML_OUTPUT_DIR/object_index.$OUTPUT_FORMAT";
432 my $old_object_index = "$SGML_OUTPUT_DIR/object_index.sgml";
433 my $new_object_index = "$SGML_OUTPUT_DIR/object_index.new";
435 open (OUTPUT, ">$new_object_index")
436 || die "Can't create $new_object_index: $!";
438 if ($OUTPUT_FORMAT eq "xml") {
439 my $header = $doctype_header;
441 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE informaltable/;
442 print (OUTPUT "$header");
445 print (OUTPUT <<EOF);
446 <informaltable pgwide="1" frame="none">
447 <tgroup cols="$cols">
448 <colspec colwidth="1*"${empty_element_end}
449 <colspec colwidth="1*"${empty_element_end}
450 <colspec colwidth="1*"${empty_element_end}
456 foreach $object (sort (@Objects)) {
457 my $xref = &MakeXRef ($object);
458 if ($count % $cols == 0) { print (OUTPUT "<row>\n"); }
459 print (OUTPUT "<entry>$xref</entry>\n");
460 if ($count % $cols == ($cols - 1)) { print (OUTPUT "</row>\n"); }
464 # emit an empty row, since empty tables are invalid
465 print (OUTPUT "<row><entry> </entry></row>\n");
468 if ($count % $cols > 0) {
469 print (OUTPUT "</row>\n");
473 print (OUTPUT <<EOF);
474 </tbody></tgroup></informaltable>
478 &UpdateFileIfChanged ($old_object_index, $new_object_index, 0);
482 #############################################################################
483 # Function : OutputSGML
484 # Description : This collects the output for each section of the docs, and
485 # outputs each file when the end of the section is found.
486 # Arguments : $file - the $MODULE-sections.txt file which contains all of
487 # the functions/macros/structs etc. being documented, organised
488 # into sections and subsections.
489 #############################################################################
494 #print "Reading: $file\n";
496 || die "Can't open $file: $!";
499 my $book_bottom = "";
500 my $includes = (defined $DEFAULT_INCLUDES) ? $DEFAULT_INCLUDES : "";
501 my $section_includes = "";
510 my $signals_synop = "";
511 my $signals_desc = "";
513 my $child_args_synop = "";
514 my $style_args_synop = "";
516 my $child_args_desc = "";
517 my $style_args_desc = "";
520 my $implementations = "";
521 my $prerequisites = "";
523 my @file_objects = ();
525 my %symbol_def_line = ();
527 # merge the source docs, in case there are no templates
528 &MergeSourceDocumentation;
534 } elsif (m/^<SECTION>/) {
540 %symbol_def_line = ();
542 } elsif (m/^<SUBSECTION\s*(.*)>/i) {
546 } elsif (m/^<SUBSECTION>/) {
548 } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
550 #print "Section: $title\n";
552 # We don't want warnings if object & class structs aren't used.
553 $DeclarationOutput{$title} = 1;
554 $DeclarationOutput{"${title}Class"} = 1;
555 $DeclarationOutput{"${title}Iface"} = 1;
556 $DeclarationOutput{"${title}Interface"} = 1;
558 } elsif (m/^<FILE>(.*)<\/FILE>/) {
560 if (! defined $templates{$filename}) {
561 if (&ReadTemplateFile ("$TMPL_DIR/$filename", 1)) {
562 &MergeSourceDocumentation;
563 $templates{$filename}=$.;
566 &LogWarning ($file, $., "Double <FILE>$filename</FILE> entry. ".
567 "Previous occurrence on line ".$templates{$filename}.".");
569 if (($title eq "") and (defined $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"})) {
570 $title = $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"};
571 # Remove trailing blanks
575 } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
577 $section_includes = $1;
579 if (defined $DEFAULT_INCLUDES) {
580 &LogWarning ($file, $., "Default <INCLUDE> being overridden by command line option.");
587 } elsif (m/^<\/SECTION>/) {
588 #print "End of section: $title\n";
589 if ($num_symbols > 0) {
591 if ($OUTPUT_FORMAT eq "xml") {
592 $book_bottom .= " <xi:include href=\"xml/$filename.xml\"/>\n";
594 $book_top.="<!ENTITY $section_id SYSTEM \"sgml/$filename.sgml\">\n";
595 $book_bottom .= " &$section_id;\n";
598 if (defined ($SourceSymbolDocs{"$TMPL_DIR/$filename:Include"})) {
599 if ($section_includes) {
600 &LogWarning ($file, $., "Section <INCLUDE> being overridden by inline comments.");
602 $section_includes = $SourceSymbolDocs{"$TMPL_DIR/$filename:Include"};
604 if ($section_includes eq "") {
605 $section_includes = $includes;
608 $signals_synop =~ s/^\n*//g;
609 $signals_synop =~ s/\n+$/\n/g;
610 if ($signals_synop ne '') {
611 $signals_synop = <<EOF;
612 <refsect1 id="$section_id.signals" role="signal_proto">
613 <title role="signal_proto.title">Signals</title>
615 ${signals_synop}</synopsis>
618 $signals_desc =~ s/^\n*//g;
619 $signals_desc =~ s/\n+$/\n/g;
620 $signals_desc =~ s/(\s|\n)+$//ms;
621 $signals_desc = <<EOF;
622 <refsect1 id="$section_id.signal-details" role="signals">
623 <title role="signals.title">Signal Details</title>
629 $args_synop =~ s/^\n*//g;
630 $args_synop =~ s/\n+$/\n/g;
631 if ($args_synop ne '') {
633 <refsect1 id="$section_id.properties" role="properties">
634 <title role="properties.title">Properties</title>
636 ${args_synop}</synopsis>
639 $args_desc =~ s/^\n*//g;
640 $args_desc =~ s/\n+$/\n/g;
641 $args_desc =~ s/(\s|\n)+$//ms;
643 <refsect1 id="$section_id.property-details" role="property_details">
644 <title role="property_details.title">Property Details</title>
650 $child_args_synop =~ s/^\n*//g;
651 $child_args_synop =~ s/\n+$/\n/g;
652 if ($child_args_synop ne '') {
653 $args_synop .= <<EOF;
654 <refsect1 id="$section_id.child-properties" role="child_properties">
655 <title role="child_properties.title">Child Properties</title>
657 ${child_args_synop}</synopsis>
660 $child_args_desc =~ s/^\n*//g;
661 $child_args_desc =~ s/\n+$/\n/g;
662 $child_args_desc =~ s/(\s|\n)+$//ms;
664 <refsect1 id="$section_id.child-property-details" role="child_property_details">
665 <title role="child_property_details.title">Child Property Details</title>
671 $style_args_synop =~ s/^\n*//g;
672 $style_args_synop =~ s/\n+$/\n/g;
673 if ($style_args_synop ne '') {
674 $args_synop .= <<EOF;
675 <refsect1 id="$section_id.style-properties" role="style_properties">
676 <title role="style_properties.title">Style Properties</title>
678 ${style_args_synop}</synopsis>
681 $style_args_desc =~ s/^\n*//g;
682 $style_args_desc =~ s/\n+$/\n/g;
683 $style_args_desc =~ s/(\s|\n)+$//ms;
685 <refsect1 id="$section_id.style-property-details" role="style_properties_details">
686 <title role="style_properties_details.title">Style Property Details</title>
692 $hierarchy =~ s/^\n*//g;
693 $hierarchy =~ s/\n+$/\n/g;
694 $hierarchy =~ s/(\s|\n)+$//ms;
695 if ($hierarchy ne "") {
697 <refsect1 id="$section_id.object-hierarchy" role="object_hierarchy">
698 <title role="object_hierarchy.title">Object Hierarchy</title>
704 $interfaces =~ s/^\n*//g;
705 $interfaces =~ s/\n+$/\n/g;
706 $interfaces =~ s/(\s|\n)+$//ms;
707 if ($interfaces ne "") {
709 <refsect1 id="$section_id.implemented-interfaces" role="impl_interfaces">
710 <title role="impl_interfaces.title">Implemented Interfaces</title>
716 $implementations =~ s/^\n*//g;
717 $implementations =~ s/\n+$/\n/g;
718 $implementations =~ s/(\s|\n)+$//ms;
719 if ($implementations ne "") {
720 $implementations = <<EOF;
721 <refsect1 id="$section_id.implementations" role="implementations">
722 <title role="implementations.title">Known Implementations</title>
728 $prerequisites =~ s/^\n*//g;
729 $prerequisites =~ s/\n+$/\n/g;
730 $prerequisites =~ s/(\s|\n)+$//ms;
731 if ($prerequisites ne "") {
732 $prerequisites = <<EOF;
733 <refsect1 id="$section_id.prerequisites" role="prerequisites">
734 <title role="prerequisites.title">Prerequisites</title>
740 $derived =~ s/^\n*//g;
741 $derived =~ s/\n+$/\n/g;
742 $derived =~ s/(\s|\n)+$//ms;
743 if ($derived ne "") {
745 <refsect1 id="$section_id.derived-interfaces" role="derived_interfaces">
746 <title role="derived_interfaces.title">Known Derived Interfaces</title>
752 $synopsis =~ s/^\n*//g;
753 $synopsis =~ s/\n+$/\n/g;
754 my $file_changed = &OutputSGMLFile ($filename, $title, $section_id,
756 \$synopsis, \$details,
757 \$signals_synop, \$signals_desc,
758 \$args_synop, \$args_desc,
759 \$hierarchy, \$interfaces,
761 \$prerequisites, \$derived,
771 $section_includes = "";
775 $child_args_synop = "";
776 $style_args_synop = "";
778 $child_args_desc = "";
779 $style_args_desc = "";
782 $implementations = "";
786 } elsif (m/^(\S+)/) {
788 #print " Symbol: $symbol\n";
790 # check for duplicate entries
791 if (! defined $symbol_def_line{$symbol}) {
792 my $declaration = $Declarations{$symbol};
793 if (defined ($declaration)) {
794 # We don't want standard macros/functions of GObjects,
795 # or private declarations.
796 if ($subsection ne "Standard" && $subsection ne "Private") {
797 if (&CheckIsObject ($symbol)) {
798 push @file_objects, $symbol;
800 my ($synop, $desc) = &OutputDeclaration ($symbol,
802 my ($sig_synop, $sig_desc) = &GetSignals ($symbol);
803 my ($arg_synop, $child_arg_synop, $style_arg_synop,
804 $arg_desc, $child_arg_desc, $style_arg_desc) = &GetArgs ($symbol);
805 my $hier = &GetHierarchy ($symbol);
806 my $ifaces = &GetInterfaces ($symbol);
807 my $impls = &GetImplementations ($symbol);
808 my $prereqs = &GetPrerequisites ($symbol);
809 my $der = &GetDerived ($symbol);
812 $signals_synop .= $sig_synop;
813 $signals_desc .= $sig_desc;
814 $args_synop .= $arg_synop;
815 $child_args_synop .= $child_arg_synop;
816 $style_args_synop .= $style_arg_synop;
817 $args_desc .= $arg_desc;
818 $child_args_desc .= $child_arg_desc;
819 $style_args_desc .= $style_arg_desc;
821 $interfaces .= $ifaces;
822 $implementations .= $impls;
823 $prerequisites .= $prereqs;
827 # Note that the declaration has been output.
828 $DeclarationOutput{$symbol} = 1;
829 } elsif ($subsection ne "Standard" && $subsection ne "Private") {
830 $UndeclaredSymbols{$symbol} = 1;
831 &LogWarning ($file, $., "No declaration found for $symbol.");
834 $symbol_def_line{$symbol}=$.;
836 if ($section_id eq "") {
837 if($title eq "" && $filename eq "") {
838 &LogWarning ($file, $., "Section has no title and no file.");
840 # FIXME: one of those would be enough
841 # filename should be an internal detail for gtk-doc
844 } elsif ($filename eq "") {
847 $filename =~ s/\s/_/g;
849 $section_id = $SourceSymbolDocs{"$TMPL_DIR/$filename:Section_Id"};
850 if (defined ($section_id) && $section_id !~ m/^\s*$/) {
851 # Remove trailing blanks and use as is
852 $section_id =~ s/\s+$//;
853 } elsif (&CheckIsObject ($title)) {
854 # GObjects use their class name as the ID.
855 $section_id = &CreateValidSGMLID ($title);
857 $section_id = &CreateValidSGMLID ("$MODULE-$title");
860 $SymbolSection{$symbol}=$title;
861 $SymbolSectionId{$symbol}=$section_id;
864 &LogWarning ($file, $., "Double symbol entry for $symbol. ".
865 "Previous occurrence on line ".$symbol_def_line{$symbol}.".");
871 &OutputMissingDocumentation;
872 &OutputUndeclaredSymbols;
873 &OutputUnusedSymbols;
875 if ($OUTPUT_ALL_SYMBOLS) {
878 if ($OUTPUT_SYMBOLS_WITHOUT_SINCE) {
879 &OutputSymbolsWithoutSince;
882 for $filename (split (' ', $EXPAND_CONTENT_FILES)) {
883 my $file_changed = &OutputExtraFile ($filename);
889 &OutputBook ($book_top, $book_bottom);
894 #############################################################################
895 # Function : OutputIndex
896 # Description : This writes an indexlist that can be included into the main-
897 # document into an <index> tag.
898 #############################################################################
901 my ($basename, $apiindexref ) = @_;
902 my %apiindex = %{$apiindexref};
903 my $old_index = "$SGML_OUTPUT_DIR/$basename.xml";
904 my $new_index = "$SGML_OUTPUT_DIR/$basename.new";
905 my $lastletter = " ";
910 open (OUTPUT, ">$new_index")
911 || die "Can't create $new_index";
913 my $header = $doctype_header;
914 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE indexdiv/;
916 print (OUTPUT "$header<indexdiv>\n");
918 #print "generate $basename index (".%apiindex." entries)\n";
920 # do a case insensitive sort while chopping off the prefix
922 sort { $$a{criteria} cmp $$b{criteria} }
923 map { my $x = uc($_); $x =~ s/^$NAME_SPACE\_?(.*)/$1/i; { criteria => $x, original => $_, short => $1 } }
926 $symbol = $$hash{original};
927 if (defined($$hash{short})) {
928 $short_symbol = $$hash{short};
930 $short_symbol = $symbol;
933 # generate a short symbol description
934 my $symbol_desc = "";
935 my $symbol_section = "";
936 my $symbol_section_id = "";
937 my $symbol_type = "";
938 if (defined($DeclarationTypes{$symbol})) {
939 $symbol_type = lc($DeclarationTypes{$symbol});
941 if ($symbol_type eq "") {
942 #print "trying symbol $symbol\n";
943 if ($symbol =~ m/(.*)::(.*)/) {
947 #print " trying object signal ${oname}:$osym in ".$#SignalNames." signals\n";
948 for ($i = 0; $i <= $#SignalNames; $i++) {
949 if ($SignalNames[$i] eq $osym) {
950 $symbol_type = "object signal";
951 if (defined($SymbolSection{$oname})) {
952 $symbol_section = $SymbolSection{$oname};
953 $symbol_section_id = $SymbolSectionId{$oname};
958 } elsif ($symbol =~ m/(.*):(.*)/) {
962 #print " trying object property ${oname}::$osym in ".$#ArgNames." properties\n";
963 for ($i = 0; $i <= $#ArgNames; $i++) {
964 #print " ".$ArgNames[$i]."\n";
965 if ($ArgNames[$i] eq $osym) {
966 $symbol_type = "object property";
967 if (defined($SymbolSection{$oname})) {
968 $symbol_section = $SymbolSection{$oname};
969 $symbol_section_id = $SymbolSectionId{$oname};
976 if (defined($SymbolSection{$symbol})) {
977 $symbol_section = $SymbolSection{$symbol};
978 $symbol_section_id = $SymbolSectionId{$symbol};
981 if ($symbol_type ne "") {
982 $symbol_desc=", $symbol_type";
983 if ($symbol_section ne "") {
984 $symbol_desc.=" in <link linkend=\"$symbol_section_id\">$symbol_section</link>";
985 #$symbol_desc.=" in ". &ExpandAbbreviations($symbol, "#$symbol_section");
989 my $curletter = uc(substr($short_symbol,0,1));
990 my $id = $apiindex{$symbol};
992 #print " add symbol $symbol with $id to index in section $curletter\n";
994 if ($curletter ne $lastletter) {
995 $lastletter = $curletter;
998 print (OUTPUT "</indexdiv>\n");
1000 print (OUTPUT "<indexdiv><title>$curletter</title>\n");
1004 print (OUTPUT <<EOF);
1005 <indexentry><primaryie linkends="$id"><link linkend="$id">$symbol</link>$symbol_desc</primaryie></indexentry>
1009 if ($divopen == 1) {
1010 print (OUTPUT "</indexdiv>\n");
1012 print (OUTPUT "</indexdiv>\n");
1015 &UpdateFileIfChanged ($old_index, $new_index, 0);
1019 #############################################################################
1020 # Function : OutputIndexFull
1021 # Description : This writes the full api indexlist that can be included into the
1022 # main document into an <index> tag.
1023 #############################################################################
1025 sub OutputIndexFull {
1026 &OutputIndex ("api-index-full", \%IndexEntriesFull);
1030 #############################################################################
1031 # Function : OutputDeprecatedIndex
1032 # Description : This writes the deprecated api indexlist that can be included
1033 # into the main document into an <index> tag.
1034 #############################################################################
1036 sub OutputDeprecatedIndex {
1037 &OutputIndex ("api-index-deprecated", \%IndexEntriesDeprecated);
1041 #############################################################################
1042 # Function : OutputSinceIndexes
1043 # Description : This writes the 'since' api indexlists that can be included into
1044 # the main document into an <index> tag.
1045 #############################################################################
1047 sub OutputSinceIndexes {
1048 my @sinces = keys %{{ map { $_ => 1 } values %Since }};
1050 foreach my $version (@sinces) {
1051 #print "Since : [$version]\n";
1052 # TODO make filtered hash
1053 #my %index = grep { $Since{$_} eq $version } %IndexEntriesSince;
1054 my %index = map { $_ => $IndexEntriesSince{$_} } grep { $Since{$_} eq $version } keys %IndexEntriesSince;
1056 &OutputIndex ("api-index-$version", \%index);
1060 #############################################################################
1061 # Function : OutputAnnotationGlossary
1062 # Description : This writes a glossary of the used annotation terms into a
1063 # separate glossary file that can be included into the main
1065 #############################################################################
1067 sub OutputAnnotationGlossary {
1068 my $old_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.xml";
1069 my $new_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.new";
1070 my $lastletter = " ";
1073 # if there are no annotations used return
1074 return if (! keys(%AnnotationsUsed));
1076 # add acronyms that are referenced from acronym text
1078 foreach my $annotation (keys(%AnnotationsUsed)) {
1079 if(defined($AnnotationDefinition{$annotation})) {
1080 if($AnnotationDefinition{$annotation} =~ m/<acronym>([\w ]+)<\/acronym>/) {
1081 if (!exists($AnnotationsUsed{$1})) {
1082 $AnnotationsUsed{$1} = 1;
1089 open (OUTPUT, ">$new_glossary")
1090 || die "Can't create $new_glossary";
1092 my $header = $doctype_header;
1093 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE glossary/;
1095 print (OUTPUT <<EOF);
1097 <glossary id="annotation-glossary">
1098 <title>Annotation Glossary</title>
1101 foreach my $annotation (keys(%AnnotationsUsed)) {
1102 if(defined($AnnotationDefinition{$annotation})) {
1103 my $def = $AnnotationDefinition{$annotation};
1104 my $curletter = uc(substr($annotation,0,1));
1106 if ($curletter ne $lastletter) {
1107 $lastletter = $curletter;
1109 if ($divopen == 1) {
1110 print (OUTPUT "</glossdiv>\n");
1112 print (OUTPUT "<glossdiv><title>$curletter</title>\n");
1115 print (OUTPUT <<EOF);
1117 <glossterm><anchor id="annotation-glossterm-$annotation"/>$annotation</glossterm>
1126 if ($divopen == 1) {
1127 print (OUTPUT "</glossdiv>\n");
1129 print (OUTPUT "</glossary>\n");
1132 &UpdateFileIfChanged ($old_glossary, $new_glossary, 0);
1135 #############################################################################
1136 # Function : ReadKnownSymbols
1137 # Description : This collects the names of non-private symbols from the
1138 # $MODULE-sections.txt file.
1139 # Arguments : $file - the $MODULE-sections.txt file which contains all of
1140 # the functions/macros/structs etc. being documented, organised
1141 # into sections and subsections.
1142 #############################################################################
1144 sub ReadKnownSymbols {
1147 my $subsection = "";
1149 #print "Reading: $file\n";
1151 || die "Can't open $file: $!";
1157 } elsif (m/^<SECTION>/) {
1160 } elsif (m/^<SUBSECTION\s*(.*)>/i) {
1163 } elsif (m/^<SUBSECTION>/) {
1166 } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
1169 } elsif (m/^<FILE>(.*)<\/FILE>/) {
1170 $KnownSymbols{"$TMPL_DIR/$1:Long_Description"} = 1;
1171 $KnownSymbols{"$TMPL_DIR/$1:Short_Description"} = 1;
1174 } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
1177 } elsif (m/^<\/SECTION>/) {
1180 } elsif (m/^(\S+)/) {
1183 if ($subsection ne "Standard" && $subsection ne "Private") {
1184 $KnownSymbols{$symbol} = 1;
1187 $KnownSymbols{$symbol} = 0;
1195 #############################################################################
1196 # Function : OutputDeclaration
1197 # Description : Returns the synopsis and detailed description DocBook
1198 # describing one function/macro etc.
1199 # Arguments : $symbol - the name of the function/macro begin described.
1200 # $declaration - the declaration of the function/macro.
1201 #############################################################################
1203 sub OutputDeclaration {
1204 my ($symbol, $declaration) = @_;
1206 my $type = $DeclarationTypes {$symbol};
1207 if ($type eq 'MACRO') {
1208 return &OutputMacro ($symbol, $declaration);
1209 } elsif ($type eq 'TYPEDEF') {
1210 return &OutputTypedef ($symbol, $declaration);
1211 } elsif ($type eq 'STRUCT') {
1212 return &OutputStruct ($symbol, $declaration);
1213 } elsif ($type eq 'ENUM') {
1214 return &OutputEnum ($symbol, $declaration);
1215 } elsif ($type eq 'UNION') {
1216 return &OutputUnion ($symbol, $declaration);
1217 } elsif ($type eq 'VARIABLE') {
1218 return &OutputVariable ($symbol, $declaration);
1219 } elsif ($type eq 'FUNCTION') {
1220 return &OutputFunction ($symbol, $declaration, $type);
1221 } elsif ($type eq 'USER_FUNCTION') {
1222 return &OutputFunction ($symbol, $declaration, $type);
1224 die "Unknown symbol type";
1229 #############################################################################
1230 # Function : OutputSymbolTraits
1231 # Description : Returns the Since and StabilityLevel paragraphs for a symbol.
1232 # Arguments : $symbol - the name of the function/macro begin described.
1233 #############################################################################
1235 sub OutputSymbolTraits {
1239 if (exists $Since{$symbol}) {
1240 $desc .= "<para role=\"since\">Since $Since{$symbol}</para>";
1242 if (exists $StabilityLevel{$symbol}) {
1243 $desc .= "<para role=\"stability\">Stability Level: $StabilityLevel{$symbol}</para>";
1248 #############################################################################
1249 # Function : Outpu{Symbol,Section}ExtraLinks
1250 # Description : Returns extralinks for the symbol (if enabled).
1251 # Arguments : $symbol - the name of the function/macro begin described.
1252 #############################################################################
1256 return undef unless defined $text;
1258 # Build a char to hex map
1261 $escapes{chr($_)} = sprintf("%%%02X", $_);
1264 # Default unsafe characters. RFC 2732 ^(uric - reserved)
1265 $text =~ s/([^A-Za-z0-9\-_.!~*'()])/$escapes{$1}/g;
1270 sub OutputSymbolExtraLinks {
1274 if (0) { # NEW FEATURE: needs configurability
1275 my $sstr = &uri_escape($symbol);
1276 my $mstr = &uri_escape($MODULE);
1278 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1279 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&symbol=$sstr">edit documentation</ulink>
1285 sub OutputSectionExtraLinks {
1286 my ($symbol,$docsymbol) = @_;
1289 if (0) { # NEW FEATURE: needs configurability
1290 my $sstr = &uri_escape($symbol);
1291 my $mstr = &uri_escape($MODULE);
1292 my $dsstr = &uri_escape($docsymbol);
1294 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1295 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&symbol=$dsstr">edit documentation</ulink>
1302 #############################################################################
1303 # Function : OutputMacro
1304 # Description : Returns the synopsis and detailed description of a macro.
1305 # Arguments : $symbol - the macro.
1306 # $declaration - the declaration of the macro.
1307 #############################################################################
1310 my ($symbol, $declaration) = @_;
1311 my $id = &CreateValidSGMLID ($symbol);
1312 my $condition = &MakeConditionDescription ($symbol);
1313 my $synop = &MakeReturnField("#define") . "<link linkend=\"$id\">$symbol</link>";
1316 my @fields = ParseMacroDeclaration($declaration, \&CreateValidSGML);
1317 my $title = $symbol . (@fields ? "()" : "");
1319 $desc = "<refsect2 id=\"$id\" role=\"macro\"$condition>\n<title>$title</title>\n";
1320 $desc .= MakeIndexterms($symbol, $id);
1322 $desc .= OutputSymbolExtraLinks($symbol);
1325 if (length ($symbol) < $SYMBOL_FIELD_WIDTH) {
1326 $synop .= (' ' x ($SYMBOL_FIELD_WIDTH - length ($symbol)));
1330 for (my $i = 1; $i <= $#fields; $i += 2) {
1331 my $field_name = $fields[$i];
1334 $synop .= "$field_name";
1337 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1345 # Don't output the macro definition if is is a conditional macro or it
1346 # looks like a function, i.e. starts with "g_" or "_?gnome_", or it is
1347 # longer than 2 lines, otherwise we get lots of complicated macros like
1349 if (!defined ($DeclarationConditional{$symbol}) && ($symbol !~ m/^g_/)
1350 && ($symbol !~ m/^_?gnome_/) && (($declaration =~ tr/\n//) < 2)) {
1351 my $decl_out = &CreateValidSGML ($declaration);
1352 $desc .= "<programlisting>$decl_out</programlisting>\n";
1354 $desc .= "<programlisting>" . &MakeReturnField("#define") . "$symbol";
1355 if ($declaration =~ m/^\s*#\s*define\s+\w+(\([^\)]*\))/) {
1357 my $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH - length ("#define "));
1358 # Align each line so that if should all line up OK.
1359 $args =~ s/\n/\n$pad/gm;
1360 $desc .= &CreateValidSGML ($args);
1362 $desc .= "</programlisting>\n";
1365 $desc .= &MakeDeprecationNote($symbol);
1367 my $parameters = &OutputParamDescriptions ("MACRO", $symbol, @fields);
1368 my $parameters_output = 0;
1370 if (defined ($SymbolDocs{$symbol})) {
1371 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1373 # Try to insert the parameter table at the author's desired position.
1374 # Otherwise we need to tag it onto the end.
1375 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1376 $parameters_output = 1;
1378 $desc .= $symbol_docs;
1381 if ($parameters_output == 0) {
1382 $desc .= $parameters;
1385 $desc .= OutputSymbolTraits ($symbol);
1386 $desc .= "</refsect2>\n";
1387 return ($synop, $desc);
1391 #############################################################################
1392 # Function : OutputTypedef
1393 # Description : Returns the synopsis and detailed description of a typedef.
1394 # Arguments : $symbol - the typedef.
1395 # $declaration - the declaration of the typedef,
1396 # e.g. 'typedef unsigned int guint;'
1397 #############################################################################
1400 my ($symbol, $declaration) = @_;
1401 my $id = &CreateValidSGMLID ($symbol);
1402 my $condition = &MakeConditionDescription ($symbol);
1403 my $synop = &MakeReturnField("typedef") . "<link linkend=\"$id\">$symbol</link>;\n";
1404 my $desc = "<refsect2 id=\"$id\" role=\"typedef\"$condition>\n<title>$symbol</title>\n";
1406 $desc .= MakeIndexterms($symbol, $id);
1408 $desc .= OutputSymbolExtraLinks($symbol);
1410 if (!defined ($DeclarationConditional{$symbol})) {
1411 my $decl_out = &CreateValidSGML ($declaration);
1412 $desc .= "<programlisting>$decl_out</programlisting>\n";
1415 $desc .= &MakeDeprecationNote($symbol);
1417 if (defined ($SymbolDocs{$symbol})) {
1418 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1420 $desc .= OutputSymbolTraits ($symbol);
1421 $desc .= "</refsect2>\n";
1422 return ($synop, $desc);
1426 #############################################################################
1427 # Function : OutputStruct
1428 # Description : Returns the synopsis and detailed description of a struct.
1429 # We check if it is a object struct, and if so we only output
1430 # parts of it that are noted as public fields.
1431 # We also use a different SGML ID for object structs, since the
1432 # original ID is used for the entire RefEntry.
1433 # Arguments : $symbol - the struct.
1434 # $declaration - the declaration of the struct.
1435 #############################################################################
1438 my ($symbol, $declaration) = @_;
1440 my $is_object_struct = 0;
1441 my $default_to_public = 1;
1442 if (&CheckIsObject ($symbol)) {
1443 #print "Found object struct: $symbol\n";
1444 $is_object_struct = 1;
1445 $default_to_public = 0;
1450 if ($is_object_struct) {
1451 $id = &CreateValidSGMLID ($symbol . "_struct");
1452 $condition = &MakeConditionDescription ($symbol . "_struct");
1454 $id = &CreateValidSGMLID ($symbol);
1455 $condition = &MakeConditionDescription ($symbol);
1458 # Determine if it is a simple struct or it also has a typedef.
1459 my $has_typedef = 0;
1460 if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1467 # For structs with typedefs we just output the struct name.
1468 $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1469 $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>$symbol</title>\n";
1471 $synop = &MakeReturnField("struct") . "<link linkend=\"$id\">$symbol</link>;\n";
1472 $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>struct $symbol</title>\n";
1475 $desc .= MakeIndexterms($symbol, $id);
1477 $desc .= OutputSymbolExtraLinks($symbol);
1479 # Form a pretty-printed, private-data-removed form of the declaration
1482 if ($declaration =~ m/^\s*$/) {
1483 #print "Found opaque struct: $symbol\n";
1484 $decl_out = "typedef struct _$symbol $symbol;";
1485 } elsif ($declaration =~ m/^\s*struct\s+\w+\s*;\s*$/) {
1486 #print "Found opaque struct: $symbol\n";
1487 $decl_out = "struct $symbol;";
1489 my $public = $default_to_public;
1490 my $new_declaration = "";
1492 my $decl = $declaration;
1494 if ($decl =~ m/^\s*(typedef\s+)?struct\s*\w*\s*(?:\/\*.*\*\/)?\s*{(.*)}\s*\w*\s*;\s*$/s) {
1495 my $struct_contents = $2;
1497 foreach $decl_line (split (/\n/, $struct_contents)) {
1498 #print "Struct line: $decl_line\n";
1499 if ($decl_line =~ m%/\*\s*<\s*public\s*>\s*\*/%) {
1501 } elsif ($decl_line =~ m%/\*\s*<\s*(private|protected)\s*>\s*\*/%) {
1504 $new_declaration .= $decl_line . "\n";
1508 if ($new_declaration) {
1509 # Strip any blank lines off the ends.
1510 $new_declaration =~ s/^\s*\n//;
1511 $new_declaration =~ s/\n\s*$/\n/;
1514 $decl_out = "typedef struct {\n" . $new_declaration
1517 $decl_out = "struct $symbol {\n" . $new_declaration
1522 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1523 "Couldn't parse struct:\n$declaration");
1526 # If we couldn't parse the struct or it was all private, output an
1527 # empty struct declaration.
1528 if ($decl_out eq "") {
1530 $decl_out = "typedef struct _$symbol $symbol;";
1532 $decl_out = "struct $symbol;";
1537 $decl_out = &CreateValidSGML ($decl_out);
1538 $desc .= "<programlisting>$decl_out</programlisting>\n";
1540 $desc .= &MakeDeprecationNote($symbol);
1542 if (defined ($SymbolDocs{$symbol})) {
1543 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1546 # Create a table of fields and descriptions
1548 # FIXME: Inserting  's into the produced type declarations here would
1549 # improve the output in most situations ... except for function
1550 # members of structs!
1551 my @fields = ParseStructDeclaration($declaration, !$default_to_public,
1554 "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1556 my $params = $SymbolParams{$symbol};
1558 # If no parameters are filled in, we don't generate the description
1559 # table, for backwards compatibility
1562 if (defined $params) {
1563 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1564 if ($params->[$i] =~ /\S/) {
1572 my %field_descrs = @$params;
1573 my $missing_parameters = "";
1574 my $unused_parameters = "";
1576 $desc .= "<variablelist role=\"struct\">\n";
1578 my $field_name = shift @fields;
1579 my $text = shift @fields;
1580 my $field_descr = $field_descrs{$field_name};
1581 my $param_annotations = "";
1583 $desc .= "<varlistentry><term>$text</term>\n";
1584 if (defined $field_descr) {
1585 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1586 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1587 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1588 delete $field_descrs{$field_name};
1590 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1591 "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1592 if ($missing_parameters ne "") {
1593 $missing_parameters .= ", ".$field_name;
1595 $missing_parameters = $field_name;
1597 $desc .= "<listitem />\n";
1599 $desc .= "</varlistentry>\n";
1601 $desc .= "</variablelist>";
1602 foreach my $field_name (keys %field_descrs) {
1603 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1604 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1605 if ($unused_parameters ne "") {
1606 $unused_parameters .= ", ".$field_name;
1608 $unused_parameters = $field_name;
1612 # remember missing/unused parameters (needed in tmpl-free build)
1613 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1614 $AllIncompleteSymbols{$symbol}=$missing_parameters;
1616 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1617 $AllUnusedSymbols{$symbol}=$unused_parameters;
1621 if (scalar(@fields) > 0) {
1622 if (! exists ($AllIncompleteSymbols{$symbol})) {
1623 $AllIncompleteSymbols{$symbol}="<items>";
1624 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1625 "Field descriptions for $symbol are missing in source code comment block.");
1630 $desc .= OutputSymbolTraits ($symbol);
1631 $desc .= "</refsect2>\n";
1632 return ($synop, $desc);
1636 #############################################################################
1637 # Function : OutputUnion
1638 # Description : Returns the synopsis and detailed description of a union.
1639 # Arguments : $symbol - the union.
1640 # $declaration - the declaration of the union.
1641 #############################################################################
1644 my ($symbol, $declaration) = @_;
1645 my $id = &CreateValidSGMLID ($symbol);
1646 my $condition = &MakeConditionDescription ($symbol);
1648 # Determine if it is a simple struct or it also has a typedef.
1649 my $has_typedef = 0;
1650 if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1657 # For unions with typedefs we just output the union name.
1658 $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1659 $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>$symbol</title>\n";
1661 $synop = &MakeReturnField("union") . "<link linkend=\"$id\">$symbol</link>;\n";
1662 $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>union $symbol</title>\n";
1665 $desc .= MakeIndexterms($symbol, $id);
1667 $desc .= OutputSymbolExtraLinks($symbol);
1669 # FIXME: we do more for structs
1670 my $decl_out = &CreateValidSGML ($declaration);
1671 $desc .= "<programlisting>$decl_out</programlisting>\n";
1673 $desc .= &MakeDeprecationNote($symbol);
1675 if (defined ($SymbolDocs{$symbol})) {
1676 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1679 # Create a table of fields and descriptions
1681 # FIXME: Inserting  's into the produced type declarations here would
1682 # improve the output in most situations ... except for function
1683 # members of structs!
1684 my @fields = ParseStructDeclaration($declaration, 0,
1687 "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1689 my $params = $SymbolParams{$symbol};
1691 # If no parameters are filled in, we don't generate the description
1692 # table, for backwards compatibility
1695 if (defined $params) {
1696 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1697 if ($params->[$i] =~ /\S/) {
1705 my %field_descrs = @$params;
1706 my $missing_parameters = "";
1707 my $unused_parameters = "";
1709 $desc .= "<variablelist role=\"union\">\n";
1711 my $field_name = shift @fields;
1712 my $text = shift @fields;
1713 my $field_descr = $field_descrs{$field_name};
1714 my $param_annotations = "";
1716 $desc .= "<varlistentry><term>$text</term>\n";
1717 if (defined $field_descr) {
1718 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1719 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1720 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1721 delete $field_descrs{$field_name};
1723 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1724 "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1725 if ($missing_parameters ne "") {
1726 $missing_parameters .= ", ".$field_name;
1728 $missing_parameters = $field_name;
1730 $desc .= "<listitem />\n";
1732 $desc .= "</varlistentry>\n";
1734 $desc .= "</variablelist>";
1735 foreach my $field_name (keys %field_descrs) {
1736 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1737 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1738 if ($unused_parameters ne "") {
1739 $unused_parameters .= ", ".$field_name;
1741 $unused_parameters = $field_name;
1745 # remember missing/unused parameters (needed in tmpl-free build)
1746 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1747 $AllIncompleteSymbols{$symbol}=$missing_parameters;
1749 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1750 $AllUnusedSymbols{$symbol}=$unused_parameters;
1754 if (scalar(@fields) > 0) {
1755 if (! exists ($AllIncompleteSymbols{$symbol})) {
1756 $AllIncompleteSymbols{$symbol}="<items>";
1757 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1758 "Field descriptions for $symbol are missing in source code comment block.");
1763 $desc .= OutputSymbolTraits ($symbol);
1764 $desc .= "</refsect2>\n";
1765 return ($synop, $desc);
1769 #############################################################################
1770 # Function : OutputEnum
1771 # Description : Returns the synopsis and detailed description of a enum.
1772 # Arguments : $symbol - the enum.
1773 # $declaration - the declaration of the enum.
1774 #############################################################################
1777 my ($symbol, $declaration) = @_;
1778 my $id = &CreateValidSGMLID ($symbol);
1779 my $condition = &MakeConditionDescription ($symbol);
1780 my $synop = &MakeReturnField("enum") . "<link linkend=\"$id\">$symbol</link>;\n";
1781 my $desc = "<refsect2 id=\"$id\" role=\"enum\"$condition>\n<title>enum $symbol</title>\n";
1783 $desc .= MakeIndexterms($symbol, $id);
1785 $desc .= OutputSymbolExtraLinks($symbol);
1787 my $decl_out = &CreateValidSGML ($declaration);
1788 $desc .= "<programlisting>$decl_out</programlisting>\n";
1790 $desc .= &MakeDeprecationNote($symbol);
1792 if (defined ($SymbolDocs{$symbol})) {
1793 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1796 # Create a table of fields and descriptions
1798 my @fields = ParseEnumDeclaration($declaration);
1799 my $params = $SymbolParams{$symbol};
1801 # If no parameters are filled in, we don't generate the description
1802 # table, for backwards compatibility
1805 if (defined $params) {
1806 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1807 if ($params->[$i] =~ /\S/) {
1815 my %field_descrs = @$params;
1816 my $missing_parameters = "";
1817 my $unused_parameters = "";
1819 $desc .= "<variablelist role=\"enum\">\n";
1820 for my $field_name (@fields) {
1821 my $field_descr = $field_descrs{$field_name};
1822 my $param_annotations = "";
1824 $id = &CreateValidSGMLID ($field_name);
1825 $condition = &MakeConditionDescription ($field_name);
1826 $desc .= "<varlistentry id=\"$id\" role=\"constant\"$condition>\n<term><literal>$field_name</literal></term>\n";
1827 if (defined $field_descr) {
1828 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1829 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1830 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1831 delete $field_descrs{$field_name};
1833 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1834 "Value description for $symbol"."::"."$field_name is missing in source code comment block.");
1835 if ($missing_parameters ne "") {
1836 $missing_parameters .= ", ".$field_name;
1838 $missing_parameters = $field_name;
1840 $desc .= "<listitem />\n";
1842 $desc .= "</varlistentry>\n";
1844 $desc .= "</variablelist>";
1845 foreach my $field_name (keys %field_descrs) {
1846 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1847 "Value description for $symbol"."::"."$field_name is not used from source code comment block.");
1848 if ($unused_parameters ne "") {
1849 $unused_parameters .= ", ".$field_name;
1851 $unused_parameters = $field_name;
1855 # remember missing/unused parameters (needed in tmpl-free build)
1856 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1857 $AllIncompleteSymbols{$symbol}=$missing_parameters;
1859 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1860 $AllUnusedSymbols{$symbol}=$unused_parameters;
1864 if (scalar(@fields) > 0) {
1865 if (! exists ($AllIncompleteSymbols{$symbol})) {
1866 $AllIncompleteSymbols{$symbol}="<items>";
1867 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1868 "Value descriptions for $symbol are missing in source code comment block.");
1873 $desc .= OutputSymbolTraits ($symbol);
1874 $desc .= "</refsect2>\n";
1875 return ($synop, $desc);
1879 #############################################################################
1880 # Function : OutputVariable
1881 # Description : Returns the synopsis and detailed description of a variable.
1882 # Arguments : $symbol - the extern'ed variable.
1883 # $declaration - the declaration of the variable.
1884 #############################################################################
1886 sub OutputVariable {
1887 my ($symbol, $declaration) = @_;
1888 my $id = &CreateValidSGMLID ($symbol);
1889 my $condition = &MakeConditionDescription ($symbol);
1892 if ($declaration =~ m/^\s*extern\s+((const\s+|signed\s+|unsigned\s+)*\w+)(\s+\*+|\*+|\s)(\s*)([A-Za-z]\w*)\s*;/) {
1893 my $mod = defined ($1) ? $1 : "";
1894 my $ptr = defined ($3) ? $3 : "";
1895 my $space = defined ($4) ? $4 : "";
1896 $synop = &MakeReturnField("extern") . "$mod$ptr$space<link linkend=\"$id\">$symbol</link>;\n";
1899 $synop = &MakeReturnField("extern") . "<link linkend=\"$id\">$symbol</link>;\n";
1902 my $desc = "<refsect2 id=\"$id\" role=\"variable\"$condition>\n<title>$symbol</title>\n";
1904 $desc .= MakeIndexterms($symbol, $id);
1906 $desc .= OutputSymbolExtraLinks($symbol);
1908 my $decl_out = &CreateValidSGML ($declaration);
1909 $desc .= "<programlisting>$decl_out</programlisting>\n";
1911 $desc .= &MakeDeprecationNote($symbol);
1913 if (defined ($SymbolDocs{$symbol})) {
1914 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1916 $desc .= OutputSymbolTraits ($symbol);
1917 $desc .= "</refsect2>\n";
1918 return ($synop, $desc);
1922 #############################################################################
1923 # Function : OutputFunction
1924 # Description : Returns the synopsis and detailed description of a function.
1925 # Arguments : $symbol - the function.
1926 # $declaration - the declaration of the function.
1927 #############################################################################
1929 sub OutputFunction {
1930 my ($symbol, $declaration, $symbol_type) = @_;
1931 my $id = &CreateValidSGMLID ($symbol);
1932 my $condition = &MakeConditionDescription ($symbol);
1934 # Take out the return type $1 $3 $4
1935 $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//;
1936 my $type_modifier = defined($1) ? $1 : "";
1939 #print "$symbol pointer is $pointer\n";
1940 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1942 #if ($symbol_type eq 'USER_FUNCTION') {
1943 # $start = "typedef ";
1946 # We output const rather than G_CONST_RETURN.
1947 $type_modifier =~ s/G_CONST_RETURN/const/g;
1948 $pointer =~ s/G_CONST_RETURN/const/g;
1949 $pointer =~ s/^\s+/ /g;
1951 my $ret_type_len = length ($start) + length ($type_modifier)
1952 + length ($pointer) + length ($type);
1953 my $ret_type_output;
1955 if ($ret_type_len < $RETURN_TYPE_FIELD_WIDTH) {
1956 $ret_type_output = "$start$type_modifier$xref$pointer"
1957 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
1960 #$ret_type_output = "$start$type_modifier$xref$pointer\n" . (' ' x $RETURN_TYPE_FIELD_WIDTH);
1962 $ret_type_output = "$start$type_modifier$xref$pointer ";
1963 $symbol_len = $ret_type_len + 1 - $RETURN_TYPE_FIELD_WIDTH;
1966 $symbol_len += length ($symbol);
1967 my $char1 = my $char2 = my $char3 = "";
1968 if ($symbol_type eq 'USER_FUNCTION') {
1975 my ($symbol_output, $symbol_desc_output);
1976 if ($symbol_len < $SYMBOL_FIELD_WIDTH) {
1977 $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3"
1978 . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1979 $symbol_desc_output = "$char1$char2$symbol$char3"
1980 . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1982 $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3\n"
1983 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1984 $symbol_desc_output = "$char1$char2$symbol$char3\n"
1985 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1988 my $synop = $ret_type_output . $symbol_output . '(';
1989 my $desc = "<refsect2 id=\"$id\" role=\"function\"$condition>\n<title>${symbol} ()</title>\n";
1991 $desc .= MakeIndexterms($symbol, $id);
1993 $desc .= OutputSymbolExtraLinks($symbol);
1995 $desc .= "<programlisting>${ret_type_output}$symbol_desc_output(";
1997 my @fields = ParseFunctionDeclaration($declaration, \&MakeXRef,
1999 &tagify($_[0],"parameter");
2002 for (my $i = 1; $i <= $#fields; $i += 2) {
2003 my $field_name = $fields[$i];
2005 if ($field_name eq "Varargs") {
2006 $field_name = "...";
2010 $synop .= "$field_name";
2011 $desc .= "$field_name";
2014 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2017 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2024 $desc .= ");</programlisting>\n";
2026 $desc .= &MakeDeprecationNote($symbol);
2028 my $parameters = &OutputParamDescriptions ("FUNCTION", $symbol, @fields);
2029 my $parameters_output = 0;
2031 if (defined ($SymbolDocs{$symbol})) {
2032 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
2034 # Try to insert the parameter table at the author's desired position.
2035 # Otherwise we need to tag it onto the end.
2036 # FIXME: document that in the user manual and make it useable for other
2038 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
2039 $parameters_output = 1;
2041 $desc .= $symbol_docs;
2044 if ($parameters_output == 0) {
2045 $desc .= $parameters;
2048 $desc .= OutputSymbolTraits ($symbol);
2049 $desc .= "</refsect2>\n";
2050 return ($synop, $desc);
2054 #############################################################################
2055 # Function : OutputParamDescriptions
2056 # Description : Returns the DocBook output describing the parameters of a
2057 # function, macro or signal handler.
2058 # Arguments : $symbol_type - 'FUNCTION', 'MACRO' or 'SIGNAL'. Signal
2059 # handlers have an implicit user_data parameter last.
2060 # $symbol - the name of the function/macro being described.
2061 # @fields - parsed fields from the declaration, used to determine
2062 # undocumented/unused entries
2063 #############################################################################
2065 sub OutputParamDescriptions {
2066 my ($symbol_type, $symbol, @fields) = @_;
2068 my $params = $SymbolParams{$symbol};
2070 my %field_descrs = ();
2073 %field_descrs = @fields;
2074 delete $field_descrs{"void"};
2075 delete $field_descrs{"Returns"};
2078 if (defined $params) {
2080 my $params_desc = "";
2081 my $missing_parameters = "";
2082 my $unused_parameters = "";
2085 for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
2086 my $param_name = $$params[$j];
2087 my $param_desc = $$params[$j + 1];
2088 my $param_annotations = "";
2090 ($param_desc,$param_annotations) = & ExpandAnnotation($symbol, $param_desc);
2091 $param_desc = &ExpandAbbreviations($symbol, $param_desc);
2092 $param_desc .= $param_annotations;
2093 if ($param_name eq "Returns") {
2094 $returns = "$param_desc";
2095 } elsif ($param_name eq "void") {
2096 #print "!!!! void in params for $symbol?\n";
2099 if (!defined $field_descrs{$param_name}) {
2100 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2101 "Parameter description for $symbol"."::"."$param_name is not used from source code comment block.");
2102 if ($unused_parameters ne "") {
2103 $unused_parameters .= ", ".$param_name;
2105 $unused_parameters = $param_name;
2108 delete $field_descrs{$param_name};
2111 if ($param_name eq "Varargs") {
2112 $param_name = "...";
2114 if($param_desc ne "") {
2115 $params_desc .= "<varlistentry><term><parameter>$param_name</parameter> :</term>\n<listitem><simpara>$param_desc</simpara></listitem></varlistentry>\n";
2120 foreach my $param_name (keys %field_descrs) {
2121 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2122 "Parameter description for $symbol"."::"."$param_name is missing in source code comment block.");
2123 if ($missing_parameters ne "") {
2124 $missing_parameters .= ", ".$param_name;
2126 $missing_parameters = $param_name;
2130 # Signals have an implicit user_data parameter which we describe.
2131 if ($symbol_type eq "SIGNAL") {
2132 $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";
2135 # Start a table if we need one.
2136 if ($params_desc || $returns) {
2137 $output .= "<variablelist role=\"params\">\n";
2138 if ($params_desc ne "") {
2139 #$output .= "<varlistentry><term>Parameters:</term><listitem></listitem></varlistentry>\n";
2140 $output .= $params_desc;
2143 # Output the returns info last.
2145 $output .= "<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>$returns</simpara></listitem></varlistentry>\n";
2149 $output .= "</variablelist>";
2152 # remember missing/unused parameters (needed in tmpl-free build)
2153 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
2154 $AllIncompleteSymbols{$symbol}=$missing_parameters;
2156 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
2157 $AllUnusedSymbols{$symbol}=$unused_parameters;
2160 if (($num_params == 0) && @fields && (scalar(keys(%field_descrs)) > 0)) {
2161 if (! exists ($AllIncompleteSymbols{$symbol})) {
2162 $AllIncompleteSymbols{$symbol}="<parameters>";
2170 #############################################################################
2171 # Function : ParseStabilityLevel
2172 # Description : Parses a stability level and outputs a warning if it isn't
2174 # Arguments : $stability - the stability text.
2175 # $file, $line - context for error message
2176 # $message - description of where the level is from, to use in
2177 # any error message.
2178 # Returns : The parsed stability level string.
2179 #############################################################################
2181 sub ParseStabilityLevel {
2182 my ($stability, $file, $line, $message) = @_;
2184 $stability =~ s/^\s*//;
2185 $stability =~ s/\s*$//;
2186 if ($stability =~ m/^stable$/i) {
2187 $stability = "Stable";
2188 } elsif ($stability =~ m/^unstable$/i) {
2189 $stability = "Unstable";
2190 } elsif ($stability =~ m/^private$/i) {
2191 $stability = "Private";
2193 &LogWarning ($file, $line, "$message is $stability.".
2194 "It should be one of these: Stable, Unstable, or Private.");
2200 #############################################################################
2201 # Function : OutputSGMLFile
2202 # Description : Outputs the final DocBook file for one section.
2203 # Arguments : $file - the name of the file.
2204 # $title - the title from the $MODULE-sections.txt file, which
2205 # will be overridden by the title in the template file.
2206 # $section_id - the SGML id to use for the toplevel tag.
2207 # $includes - comma-separates list of include files added at top
2208 # of synopsis, with '<' '>' around them (if not already enclosed in "").
2209 # $synopsis - reference to the DocBook for the Synopsis part.
2210 # $details - reference to the DocBook for the Details part.
2211 # $signal_synop - reference to the DocBook for the Signal Synopsis part
2212 # $signal_desc - reference to the DocBook for the Signal Description part
2213 # $args_synop - reference to the DocBook for the Arg Synopsis part
2214 # $args_desc - reference to the DocBook for the Arg Description part
2215 # $hierarchy - reference to the DocBook for the Object Hierarchy part
2216 # $interfaces - reference to the DocBook for the Interfaces part
2217 # $implementations - reference to the DocBook for the Known Implementations part
2218 # $prerequisites - reference to the DocBook for the Prerequisites part
2219 # $derived - reference to the DocBook for the Derived Interfaces part
2220 # $file_objects - reference to an array of objects in this file
2221 #############################################################################
2223 sub OutputSGMLFile {
2224 my ($file, $title, $section_id, $includes, $synopsis, $details, $signals_synop, $signals_desc, $args_synop, $args_desc, $hierarchy, $interfaces, $implementations, $prerequisites, $derived, $file_objects) = @_;
2226 #print "Output sgml for file $file with title '$title'\n";
2228 # The edited title overrides the one from the sections file.
2229 my $new_title = $SymbolDocs{"$TMPL_DIR/$file:Title"};
2230 if (defined ($new_title) && $new_title !~ m/^\s*$/) {
2231 $title = $new_title;
2232 #print "Found title: $title\n";
2234 my $short_desc = $SymbolDocs{"$TMPL_DIR/$file:Short_Description"};
2235 if (!defined ($short_desc) || $short_desc =~ m/^\s*$/) {
2238 $short_desc = &ExpandAbbreviations("$title:Short_description",
2240 #print "Found short_desc: $short_desc";
2242 my $long_desc = $SymbolDocs{"$TMPL_DIR/$file:Long_Description"};
2243 if (!defined ($long_desc) || $long_desc =~ m/^\s*$/) {
2246 $long_desc = &ExpandAbbreviations("$title:Long_description",
2248 #print "Found long_desc: $long_desc";
2250 my $see_also = $SymbolDocs{"$TMPL_DIR/$file:See_Also"};
2251 if (!defined ($see_also) || $see_also =~ m%^\s*(<para>)?\s*(</para>)?\s*$%) {
2254 $see_also = &ExpandAbbreviations("$title:See_Also", $see_also);
2255 #print "Found see_also: $see_also";
2258 $see_also = "<refsect1 id=\"$section_id.see-also\">\n<title>See Also</title>\n$see_also\n</refsect1>\n";
2260 my $stability = $SymbolDocs{"$TMPL_DIR/$file:Stability_Level"};
2261 if (!defined ($stability) || $stability =~ m/^\s*$/) {
2264 $stability = &ParseStabilityLevel($stability, $file, $., "Section stability level");
2265 #print "Found stability: $stability";
2268 $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$stability, unless otherwise indicated\n</refsect1>\n";
2269 } elsif ($DEFAULT_STABILITY) {
2270 $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$DEFAULT_STABILITY, unless otherwise indicated\n</refsect1>\n";
2273 my $image = $SymbolDocs{"$TMPL_DIR/$file:Image"};
2274 if (!defined ($image) || $image =~ m/^\s*$/) {
2282 if ($image =~ /jpe?g$/i) {
2283 $format = "format='JPEG'";
2284 } elsif ($image =~ /png$/i) {
2285 $format = "format='PNG'";
2286 } elsif ($image =~ /svg$/i) {
2287 $format = "format='SVG'";
2292 $image = " <inlinegraphic fileref='$image' $format/>\n"
2295 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
2297 my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
2300 my $include_output = "";
2302 foreach $include (split (/,/, $includes)) {
2303 if ($include =~ m/^\".+\"$/) {
2304 $include_output .= "#include ${include}\n";
2307 $include =~ s/^\s+|\s+$//gs;
2308 $include_output .= "#include <${include}>\n";
2311 if ($include_output ne '') {
2312 $include_output = "\n$include_output\n";
2315 my $extralinks = OutputSectionExtraLinks($title,"Section:$file");
2317 my $old_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT";
2318 my $new_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT.new";
2320 open (OUTPUT, ">$new_sgml_file")
2321 || die "Can't create $new_sgml_file: $!";
2323 my $object_anchors = "";
2324 foreach my $object (@$file_objects) {
2325 next if ($object eq $section_id);
2326 my $id = CreateValidSGMLID($object);
2327 #print "Debug: Adding anchor for $object\n";
2328 $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
2331 # We used to output this, but is messes up our UpdateFileIfChanged code
2332 # since it changes every day (and it is only used in the man pages):
2333 # "<refentry id="$section_id" revision="$mday $month $year">"
2335 if ($OUTPUT_FORMAT eq "xml") {
2336 print OUTPUT $doctype_header;
2340 <refentry id="$section_id">
2342 <refentrytitle role="top_of_page" id="$section_id.top_of_page">$title</refentrytitle>
2343 <manvolnum>3</manvolnum>
2346 $image</refmiscinfo>
2349 <refname>$title</refname>
2350 <refpurpose>$short_desc</refpurpose>
2353 <refsynopsisdiv id="$section_id.synopsis" role="synopsis">
2354 <title role="synopsis.title">Synopsis</title>
2356 <synopsis>$include_output$${synopsis}</synopsis>
2358 $$hierarchy$$prerequisites$$derived$$interfaces$$implementations$$args_synop$$signals_synop
2359 <refsect1 id="$section_id.description" role="desc">
2360 <title role="desc.title">Description</title>
2361 $extralinks$long_desc
2363 <refsect1 id="$section_id.details" role="details">
2364 <title role="details.title">Details</title>
2367 $$args_desc$$signals_desc$see_also
2372 return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2376 #############################################################################
2377 # Function : OutputExtraFile
2378 # Description : Copies an "extra" DocBook file into the output directory,
2379 # expanding abbreviations
2380 # Arguments : $file - the source file.
2381 #############################################################################
2382 sub OutputExtraFile {
2387 ($basename = $file) =~ s!^.*/!!;
2389 my $old_sgml_file = "$SGML_OUTPUT_DIR/$basename";
2390 my $new_sgml_file = "$SGML_OUTPUT_DIR/$basename.new";
2394 open(EXTRA_FILE, "<$file") || die "Can't open $file";
2398 $contents = <EXTRA_FILE>;
2401 open (OUTPUT, ">$new_sgml_file")
2402 || die "Can't create $new_sgml_file: $!";
2404 print OUTPUT &ExpandAbbreviations ("$basename file", $contents);
2407 return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2409 #############################################################################
2410 # Function : OutputBook
2411 # Description : Outputs the SGML entities that need to be included into the
2412 # main SGML file for the module.
2413 # Arguments : $book_top - the declarations of the entities, which are added
2414 # at the top of the main SGML file.
2415 # $book_bottom - the references to the entities, which are
2416 # added in the main SGML file at the desired position.
2417 #############################################################################
2420 my ($book_top, $book_bottom) = @_;
2422 my $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top";
2423 my $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top.new";
2425 open (OUTPUT, ">$new_file")
2426 || die "Can't create $new_file: $!";
2427 print OUTPUT $book_top;
2430 &UpdateFileIfChanged ($old_file, $new_file, 0);
2433 $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom";
2434 $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom.new";
2436 open (OUTPUT, ">$new_file")
2437 || die "Can't create $new_file: $!";
2438 print OUTPUT $book_bottom;
2441 &UpdateFileIfChanged ($old_file, $new_file, 0);
2444 # If the main SGML/XML file hasn't been created yet, we create it here.
2445 # The user can tweak it later.
2446 if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
2447 open (OUTPUT, ">$MAIN_SGML_FILE")
2448 || die "Can't create $MAIN_SGML_FILE: $!";
2450 if ($OUTPUT_FORMAT eq "xml") {
2452 <?xml version="1.0"?>
2453 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
2454 "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
2456 <!ENTITY % local.common.attrib "xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'">
2462 <!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
2471 <title>$MODULE Reference Manual</title>
2473 for $MODULE [VERSION].
2474 The latest version of this documentation can be found on-line at
2475 <ulink role="online-location" url="http://[SERVER]/$MODULE/index.html">http://[SERVER]/$MODULE/</ulink>.
2480 <title>[Insert title here]</title>
2484 if (-e $OBJECT_TREE_FILE) {
2486 <chapter id="object-tree">
2487 <title>Object Hierarchy</title>
2488 <xi:include href="xml/tree_index.sgml"/>
2494 <index id="api-index-full">
2495 <title>API Index</title>
2496 <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
2499 <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
2508 #############################################################################
2509 # Function : CreateValidSGML
2510 # Description : This turns any chars which are used in SGML into entities,
2511 # e.g. '<' into '<'
2512 # Arguments : $text - the text to turn into proper SGML.
2513 #############################################################################
2515 sub CreateValidSGML {
2517 $text =~ s/&/&/g; # Do this first, or the others get messed up.
2518 $text =~ s/</</g;
2519 $text =~ s/>/>/g;
2520 # browers render single tabs inconsistently
2521 $text =~ s/([^\s])\t([^\s])/$1 $2/g;
2525 #############################################################################
2526 # Function : ConvertSGMLChars
2527 # Description : This is used for text in source code comment blocks, to turn
2528 # chars which are used in SGML into entities, e.g. '<' into
2529 # '<'. Depending on $SGML_MODE, this is done
2530 # unconditionally or only if the character doesn't seem to be
2531 # part of an SGML construct (tag or entity reference).
2532 # Arguments : $text - the text to turn into proper SGML.
2533 #############################################################################
2535 sub ConvertSGMLChars {
2536 my ($symbol, $text) = @_;
2539 # For the SGML mode only convert to entities outside CDATA sections.
2540 return &ModifyXMLElements ($text, $symbol,
2541 "<!\\[CDATA\\[|<programlisting[^>]*>",
2542 \&ConvertSGMLCharsEndTag,
2543 \&ConvertSGMLCharsCallback);
2545 # For the simple non-sgml mode, convert to entities everywhere.
2546 $text =~ s/&/&/g; # Do this first, or the others get messed up.
2547 $text =~ s/</</g;
2548 $text =~ s/>/>/g;
2554 sub ConvertSGMLCharsEndTag {
2555 if ($_[0] eq "<!\[CDATA\[") {
2558 return "</programlisting>";
2562 sub ConvertSGMLCharsCallback {
2563 my ($text, $symbol, $tag) = @_;
2565 if ($tag =~ m/^<programlisting/) {
2566 # We can handle <programlisting> specially here.
2567 return &ModifyXMLElements ($text, $symbol,
2569 \&ConvertSGMLCharsEndTag,
2570 \&ConvertSGMLCharsCallback2);
2571 } elsif ($tag eq "") {
2572 # If we're not in CDATA convert to entities.
2573 $text =~ s/&(?![a-zA-Z#]+;)/&/g; # Do this first, or the others get messed up.
2574 $text =~ s/<(?![a-zA-Z\/!])/</g;
2575 $text =~ s/(?<![a-zA-Z0-9"'\/-])>/>/g;
2577 # Handle "#include <xxxxx>"
2578 $text =~ s/#include(\s+)<([^>]+)>/#include$1<$2>/g;
2584 sub ConvertSGMLCharsCallback2 {
2585 my ($text, $symbol, $tag) = @_;
2587 # If we're not in CDATA convert to entities.
2588 # We could handle <programlisting> differently, though I'm not sure it helps.
2590 # replace only if its not a tag
2591 $text =~ s/&(?![a-zA-Z#]+;)/&/g; # Do this first, or the others get messed up.
2592 $text =~ s/<(?![a-zA-Z\/!])/</g;
2593 $text =~ s/(?<![a-zA-Z0-9"'\/-])>/>/g;
2595 # Handle "#include <xxxxx>"
2596 $text =~ s/#include(\s+)<([^>]+)>/#include$1<$2>/g;
2602 #############################################################################
2603 # Function : ExpandAnnotation
2604 # Description : This turns annotations into acronym tags.
2605 # Arguments : $symbol - the symbol being documented, for error messages.
2606 # $text - the text to expand.
2607 #############################################################################
2608 sub ExpandAnnotation {
2609 my ($symbol, $param_desc) = @_;
2610 my $param_annotations = "";
2612 # look for annotations at the start of the comment
2613 if ($param_desc =~ m%^\s*\(([^)]*)\):%) {
2616 my $annotation_extra = "";
2619 @annotations = split(/\)\s*\(/,$1);
2620 foreach $annotation (@annotations) {
2621 # need to search for the longest key-match in %AnnotationDefinition
2623 my $match_annotation="";
2625 foreach $annotationdef (keys %AnnotationDefinition) {
2626 if ($annotation =~ m/^$annotationdef/) {
2627 if (length($annotationdef)>$match_length) {
2628 $match_length=length($annotationdef);
2629 $match_annotation=$annotationdef;
2633 if ($match_annotation ne "") {
2634 if ($annotation =~ m%$match_annotation\s+(.*)%) {
2635 $annotation_extra = " $1";
2637 $AnnotationsUsed{$match_annotation} = 1;
2638 $param_annotations .= "[<acronym>$match_annotation</acronym>$annotation_extra]";
2641 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2642 "unknown annotation \"$annotation\" in documentation for $symbol.");
2643 $param_annotations .= "[$annotation]";
2647 $param_desc =~ m/^(.*?)\.*\s*$/s;
2648 $param_desc = "$1. ";
2650 if ($param_annotations ne "") {
2651 $param_annotations = "<emphasis role=\"annotation\">$param_annotations</emphasis>";
2653 return ($param_desc, $param_annotations);
2656 #############################################################################
2657 # Function : ExpandAbbreviations
2658 # Description : This turns the abbreviations function(), macro(), @param,
2659 # %constant, and #symbol into appropriate DocBook markup.
2660 # CDATA sections and <programlisting> parts are skipped.
2661 # Arguments : $symbol - the symbol being documented, for error messages.
2662 # $text - the text to expand.
2663 #############################################################################
2665 sub ExpandAbbreviations {
2666 my ($symbol, $text) = @_;
2668 # Convert "|[" and "]|" into the start and end of program listing examples.
2669 # FIXME: we like to have a way to specify parameters e.g. language="c"
2670 $text =~ s%\|\[%<informalexample><programlisting>%g;
2671 $text =~ s%\]\|%</programlisting></informalexample>%g;
2672 # TODO: check for a xml comment after |[ and pick the language attribute from
2675 # keep CDATA unmodified, preserve ulink tags (ideally we preseve all tags
2677 return &ModifyXMLElements ($text, $symbol,
2678 "<!\\[CDATA\\[|<ulink[^>]*>|<programlisting[^>]*>|<!DOCTYPE",
2679 \&ExpandAbbreviationsEndTag,
2680 \&ExpandAbbreviationsCallback);
2684 # Returns the end tag corresponding to the given start tag.
2685 sub ExpandAbbreviationsEndTag {
2686 my ($start_tag) = @_;
2688 if ($start_tag eq "<!\[CDATA\[") {
2690 } elsif ($start_tag eq "<!DOCTYPE") {
2692 } elsif ($start_tag =~ m/<(\w+)/) {
2697 # Called inside or outside each CDATA or <programlisting> section.
2698 sub ExpandAbbreviationsCallback {
2699 my ($text, $symbol, $tag) = @_;
2701 if ($tag =~ m/^<programlisting/) {
2702 # Handle any embedded CDATA sections.
2703 return &ModifyXMLElements ($text, $symbol,
2705 \&ExpandAbbreviationsEndTag,
2706 \&ExpandAbbreviationsCallback2);
2707 } elsif ($tag eq "") {
2708 # We are outside any CDATA or <programlisting> sections, so we expand
2709 # any gtk-doc abbreviations.
2711 # Convert 'function()' or 'macro()'.
2712 # if there is abc_*_def() we don't want to make a link to _def()
2713 # FIXME: also handle abc(....) : but that would need to be done recursively :/
2714 $text =~ s/([^\*.\w])(\w+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2715 # handle #Object.func()
2716 $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2718 # Convert '@param', but not '\@param'.
2719 $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)/$1<parameter>$2<\/parameter>/g;
2720 $text =~ s/\\\@/\@/g;
2722 # Convert '%constant', but not '\%constant'.
2723 # Also allow negative numbers, e.g. %-1.
2724 $text =~ s/(\A|[^\\])\%(-?\w+)/$1.&MakeXRef($2, &tagify($2, "literal"));/eg;
2725 $text =~ s/\\\%/\%/g;
2727 # Convert '#symbol', but not '\#symbol'.
2728 $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)/$1.&MakeHashXRef($2, "type");/eg;
2732 # FIXME: should we skip urls that are already tagged? (e.g. <literal>http://...</literal>)
2733 # this is apparently also called for markup and not just for plain text
2735 #$text =~ s%(http|https|ftp)://(.*?)((?:\s|,|\)|\]|\<|\.\s))%<ulink url="$1://$2">$2</ulink>$3%g;
2737 # TODO: optionally check all words from $text against internal symbols and
2738 # warn if those could be xreffed, but miss a %,# or ()
2744 # This is called inside a <programlisting>
2745 sub ExpandAbbreviationsCallback2 {
2746 my ($text, $symbol, $tag) = @_;
2749 # We are inside a <programlisting> but outside any CDATA sections,
2750 # so we expand any gtk-doc abbreviations.
2751 # FIXME: why is this different from &ExpandAbbreviationsCallback(),
2752 # why not just call it
2753 $text =~ s/#(\w+)/&MakeHashXRef($1, "");/eg;
2760 my ($symbol, $tag) = @_;;
2763 # Check for things like '#include', '#define', and skip them.
2764 if ($PreProcessorDirectives{$symbol}) {
2768 # Get rid of any special '-struct' suffix.
2769 $text =~ s/-struct$//;
2771 # If the symbol is in the form "Object::signal", then change the symbol to
2772 # "Object-signal" and use "signal" as the text.
2773 if ($symbol =~ s/::/-/) {
2777 # If the symbol is in the form "Object:property", then change the symbol to
2778 # "Object--property" and use "property" as the text.
2779 if ($symbol =~ s/:/--/) {
2784 $text = tagify ($text, $tag);
2787 return &MakeXRef($symbol, $text);
2791 #############################################################################
2792 # Function : ModifyXMLElements
2793 # Description : Looks for given XML element tags within the text, and calls
2794 # the callback on pieces of text inside & outside those elements.
2795 # Used for special handling of text inside things like CDATA
2796 # and <programlisting>.
2797 # Arguments : $text - the text.
2798 # $symbol - the symbol currently being documented (only used for
2800 # $start_tag_regexp - the regular expression to match start tags.
2801 # e.g. "<!\\[CDATA\\[|<programlisting[^>]*>" to match
2802 # CDATA sections or programlisting elements.
2803 # $end_tag_func - function which is passed the matched start tag
2804 # and should return the appropriate end tag string.
2805 # $callback - callback called with each part of the text. It is
2806 # called with a piece of text, the symbol being
2807 # documented, and the matched start tag or "" if the text
2808 # is outside the XML elements being matched.
2809 #############################################################################
2810 sub ModifyXMLElements {
2811 my ($text, $symbol, $start_tag_regexp, $end_tag_func, $callback) = @_;
2812 my ($before_tag, $start_tag, $end_tag_regexp, $end_tag);
2815 while ($text =~ m/$start_tag_regexp/s) {
2816 $before_tag = $`; # Prematch for last successful match string
2817 $start_tag = $&; # Last successful match
2818 $text = $'; # Postmatch for last successful match string
2820 $result .= &$callback ($before_tag, $symbol, "");
2821 $result .= $start_tag;
2823 # get the mathing end-tag for current tag
2824 $end_tag_regexp = &$end_tag_func ($start_tag);
2826 if ($text =~ m/$end_tag_regexp/s) {
2831 $result .= &$callback ($before_tag, $symbol, $start_tag);
2832 $result .= $end_tag;
2834 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2835 "Can't find tag end: $end_tag_regexp in docs for: $symbol.");
2836 # Just assume it is all inside the tag.
2837 $result .= &$callback ($text, $symbol, $start_tag);
2842 # Handle any remaining text outside the tags.
2843 $result .= &$callback ($text, $symbol, "");
2852 # Adds a tag around some text.
2853 # e.g tagify("Text", "literal") => "<literal>Text</literal>".
2855 my ($text, $elem) = @_;
2856 return "<" . $elem . ">" . $text . "</" . $elem . ">";
2860 #############################################################################
2861 # Function : MakeXRef
2862 # Description : This returns a cross-reference link to the given symbol.
2863 # Though it doesn't try to do this for a few standard C types
2864 # that it knows won't be in the documentation.
2865 # Arguments : $symbol - the symbol to try to create a XRef to.
2866 # $text - text text to put inside the XRef, defaults to $symbol
2867 #############################################################################
2870 my ($symbol, $text) = ($_[0], $_[1]);
2872 $symbol =~ s/^\s+//;
2873 $symbol =~ s/\s+$//;
2875 if (!defined($text)) {
2878 # Get rid of special '-struct' suffix.
2879 $text =~ s/-struct$//;
2882 if ($symbol =~ m/ /) {
2886 #print "Getting type link for $symbol -> $text\n";
2888 my $symbol_id = &CreateValidSGMLID ($symbol);
2889 return "<link linkend=\"$symbol_id\">$text</link>";
2893 #############################################################################
2894 # Function : MakeIndexterms
2895 # Description : This returns a indexterm elements for the given symbol
2896 # Arguments : $symbol - the symbol to create indexterms for
2897 #############################################################################
2899 sub MakeIndexterms {
2900 my ($symbol, $id) = @_;
2904 # make the index useful, by ommiting the namespace when sorting
2905 if ($NAME_SPACE ne "") {
2906 if ($symbol =~ m/^$NAME_SPACE\_?(.*)/i) {
2907 $sortas=" sortas=\"$1\"";
2911 if (exists $Deprecated{$symbol}) {
2912 $terms .= "<indexterm zone=\"$id\" role=\"deprecated\"><primary$sortas>$symbol</primary></indexterm>";
2913 $IndexEntriesDeprecated{$symbol}=$id;
2914 $IndexEntriesFull{$symbol}=$id;
2916 if (exists $Since{$symbol}) {
2917 my $since = $Since{$symbol};
2921 $terms .= "<indexterm zone=\"$id\" role=\"$since\"><primary$sortas>$symbol</primary></indexterm>";
2923 $IndexEntriesSince{$symbol}=$id;
2924 $IndexEntriesFull{$symbol}=$id;
2927 $terms .= "<indexterm zone=\"$id\"><primary$sortas>$symbol</primary></indexterm>";
2928 $IndexEntriesFull{$symbol}=$id;
2934 #############################################################################
2935 # Function : MakeDeprecationNote
2936 # Description : This returns a deprecation warning for the given symbol.
2937 # Arguments : $symbol - the symbol to try to create a warning for.
2938 #############################################################################
2940 sub MakeDeprecationNote {
2941 my ($symbol) = $_[0];
2944 if (exists $Deprecated{$symbol}) {
2945 $desc .= "<warning>";
2947 if ($Deprecated{$symbol} =~ /^\s*([0-9\.]+)\s*:/) {
2948 $desc .= "<para><literal>$symbol</literal> has been deprecated since version $1 and should not be used in newly-written code.";
2950 $desc .= "<para><literal>$symbol</literal> is deprecated and should not be used in newly-written code.";
2952 if ($Deprecated{$symbol} ne "") {
2953 $note = &ExpandAbbreviations($symbol, $Deprecated{$symbol});
2954 $note =~ s/^\s*([0-9\.]+)\s*:\s*//;
2957 $note =~ s%\n{2,}%\n</para>\n<para>\n%g;
2958 $desc .= " " . $note;
2960 $desc .= "</para></warning>\n";
2965 #############################################################################
2966 # Function : MakeConditionDescription
2967 # Description : This returns a sumary of conditions for the given symbol.
2968 # Arguments : $symbol - the symbol to try to create the sumary.
2969 #############################################################################
2971 sub MakeConditionDescription {
2972 my ($symbol) = $_[0];
2975 if (exists $Deprecated{$symbol}) {
2980 if ($Deprecated{$symbol} =~ /^\s*(.*?)\s*$/) {
2981 $desc .= "deprecated:$1";
2983 $desc .= "deprecated";
2987 if (exists $Since{$symbol}) {
2992 if ($Since{$symbol} =~ /^\s*(.*?)\s*$/) {
2993 $desc .= "since:$1";
2999 if (exists $StabilityLevel{$symbol}) {
3003 $desc .= "stability:".$StabilityLevel{$symbol};
3007 $desc=" condition=\"".$desc."\"";
3008 #print "condition for '$symbol' = '$desc'\n";
3013 #############################################################################
3014 # Function : GetHierarchy
3015 # Description : Returns the DocBook output describing the ancestors and
3016 # immediate children of a GObject subclass. It uses the
3017 # global @Objects and @ObjectLevels arrays to walk the tree.
3018 # Arguments : $object - the GtkObject subclass.
3019 #############################################################################
3024 # Find object in the objects array.
3030 for ($i = 0; $i < @Objects; $i++) {
3032 if ($ObjectLevels[$i] <= $level) {
3035 elsif ($ObjectLevels[$i] == $level + 1) {
3036 push (@children, $Objects[$i]);
3039 elsif ($Objects[$i] eq $object) {
3042 $level = $ObjectLevels[$i];
3049 # Walk up the hierarchy, pushing ancestors onto the ancestors array.
3051 push (@ancestors, $object);
3052 #print "Level: $level\n";
3053 while ($level > 1) {
3055 if ($ObjectLevels[$j] < $level) {
3056 push (@ancestors, $Objects[$j]);
3057 $level = $ObjectLevels[$j];
3058 #print "Level: $level\n";
3062 # Output the ancestors list, indented and with links.
3063 my $hierarchy = "<synopsis>\n";
3065 for ($i = $#ancestors; $i >= 0; $i--) {
3067 # Don't add a link to the current object, i.e. when i == 0.
3069 my $ancestor_id = &CreateValidSGMLID ($ancestors[$i]);
3070 $link_text = "<link linkend=\"$ancestor_id\">$ancestors[$i]</link>";
3072 $link_text = "$ancestors[$i]";
3075 $hierarchy .= " $link_text\n";
3077 # $hierarchy .= ' ' x ($level * 6 - 3) . "|\n";
3078 $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3082 for ($i = 0; $i <= $#children; $i++) {
3083 my $id = &CreateValidSGMLID ($children[$i]);
3084 my $link_text = "<link linkend=\"$id\">$children[$i]</link>";
3085 $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3087 $hierarchy .= "</synopsis>\n";
3093 #############################################################################
3094 # Function : GetInterfaces
3095 # Description : Returns the DocBook output describing the interfaces
3096 # implemented by a class. It uses the global %Interfaces hash.
3097 # Arguments : $object - the GtkObject subclass.
3098 #############################################################################
3105 # Find object in the objects array.
3106 if (exists($Interfaces{$object})) {
3107 my @ifaces = split(' ', $Interfaces{$object});
3112 for ($i = 0; $i <= $#ifaces; $i++) {
3113 my $id = &CreateValidSGMLID ($ifaces[$i]);
3114 $text .= " <link linkend=\"$id\">$ifaces[$i]</link>";
3115 if ($i < $#ifaces - 1) {
3118 elsif ($i < $#ifaces) {
3133 #############################################################################
3134 # Function : GetImplementations
3135 # Description : Returns the DocBook output describing the implementations
3136 # of an interface. It uses the global %Interfaces hash.
3137 # Arguments : $object - the GtkObject subclass.
3138 #############################################################################
3140 sub GetImplementations {
3145 foreach my $key (keys %Interfaces) {
3146 if ($Interfaces{$key} =~ /\b$object\b/) {
3147 push (@impls, $key);
3151 @impls = sort @impls;
3154 $object is implemented by
3156 for ($i = 0; $i <= $#impls; $i++) {
3157 my $id = &CreateValidSGMLID ($impls[$i]);
3158 $text .= " <link linkend=\"$id\">$impls[$i]</link>";
3159 if ($i < $#impls - 1) {
3162 elsif ($i < $#impls) {
3177 #############################################################################
3178 # Function : GetPrerequisites
3179 # Description : Returns the DocBook output describing the prerequisites
3180 # of an interface. It uses the global %Prerequisites hash.
3181 # Arguments : $iface - the interface.
3182 #############################################################################
3184 sub GetPrerequisites {
3189 if (exists($Prerequisites{$iface})) {
3194 my @prereqs = split(' ', $Prerequisites{$iface});
3195 for ($i = 0; $i <= $#prereqs; $i++) {
3196 my $id = &CreateValidSGMLID ($prereqs[$i]);
3197 $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
3198 if ($i < $#prereqs - 1) {
3201 elsif ($i < $#prereqs) {
3215 #############################################################################
3216 # Function : GetDerived
3217 # Description : Returns the DocBook output describing the derived interfaces
3218 # of an interface. It uses the global %Prerequisites hash.
3219 # Arguments : $iface - the interface.
3220 #############################################################################
3228 foreach my $key (keys %Prerequisites) {
3229 if ($Prerequisites{$key} =~ /\b$iface\b/) {
3230 push (@derived, $key);
3233 if ($#derived >= 0) {
3234 @derived = sort @derived;
3237 $iface is required by
3239 for ($i = 0; $i <= $#derived; $i++) {
3240 my $id = &CreateValidSGMLID ($derived[$i]);
3241 $text .= " <link linkend=\"$id\">$derived[$i]</link>";
3242 if ($i < $#derived - 1) {
3245 elsif ($i < $#derived) {
3260 #############################################################################
3261 # Function : GetSignals
3262 # Description : Returns the synopsis and detailed description DocBook output
3263 # for the signal handlers of a given GtkObject subclass.
3264 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
3265 #############################################################################
3273 for ($i = 0; $i <= $#SignalObjects; $i++) {
3274 if ($SignalObjects[$i] eq $object) {
3275 #print "Found signal: $SignalNames[$i]\n";
3276 my $name = $SignalNames[$i];
3277 my $symbol = "${object}::${name}";
3278 my $id = &CreateValidSGMLID ("$object-$name");
3280 my $pad = ' ' x (46 - length($name));
3281 $synop .= " "<link linkend=\"$id\">$name</link>"$pad ";
3283 $desc .= "<refsect2 id=\"$id\" role=\"signal\"><title>The <literal>"$name"</literal> signal</title>\n";
3284 $desc .= MakeIndexterms($symbol, $id);
3286 $desc .= OutputSymbolExtraLinks($symbol);
3288 $desc .= "<programlisting>";
3290 $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
3291 my $type_modifier = defined($1) ? $1 : "";
3294 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
3296 my $ret_type_len = length ($type_modifier) + length ($pointer)
3298 my $ret_type_output = "$type_modifier$xref$pointer"
3299 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
3301 $desc .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
3303 my $sourceparams = $SourceSymbolParams{$symbol};
3304 my @params = split ("\n", $SignalPrototypes[$i]);
3307 my $type_len = length("gpointer");
3308 my $name_len = length("user_data");
3309 # do two passes, the first one is to calculate padding
3310 for ($l = 0; $l < 2; $l++) {
3311 for ($j = 0; $j <= $#params; $j++) {
3312 # allow alphanumerics, '_', '[' & ']' in param names
3313 if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
3316 if (defined($sourceparams)) {
3317 $name = $$sourceparams[$PARAM_FIELD_COUNT * $j];
3322 if (!defined($name)) {
3326 if (length($type) + length($pointer) > $type_len) {
3327 $type_len = length($type) + length($pointer);
3329 if (length($name) > $name_len) {
3330 $name_len = length($name);
3334 $xref = &MakeXRef ($type, &tagify($type, "type"));
3335 $pad = ' ' x ($type_len - length($type) - length($pointer));
3336 $desc .= "$xref$pad $pointer$name,\n";
3337 $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
3340 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3341 "Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]");
3345 $xref = &MakeXRef ("gpointer", &tagify("gpointer", "type"));
3346 $pad = ' ' x ($type_len - length("gpointer"));
3347 $desc .= "$xref$pad user_data)";
3349 my $flags = $SignalFlags[$i];
3350 my $flags_string = "";
3352 if (defined ($flags)) {
3353 if ($flags =~ m/f/) {
3354 $flags_string = "Run First";
3356 elsif ($flags =~ m/l/) {
3357 $flags_string = "Run Last";
3359 elsif ($flags =~ m/c/) {
3360 $flags_string = "Cleanup";
3362 if ($flags =~ m/r/) {
3363 if ($flags_string) { $flags_string .= " / "; }
3364 $flags_string .= "No Recursion";
3366 if ($flags =~ m/d/) {
3367 if ($flags_string) { $flags_string .= " / "; }
3368 $flags_string .= "Has Details";
3370 if ($flags =~ m/a/) {
3371 if ($flags_string) { $flags_string .= " / "; }
3372 $flags_string .= "Action";
3374 if ($flags =~ m/h/) {
3375 if ($flags_string) { $flags_string .= " / "; }
3376 $flags_string .= "No Hooks";
3382 $synop .= ": $flags_string\n";
3384 $pad = ' ' x (5 + $name_len - length("user_data"));
3385 $desc .= "$pad : $flags_string</programlisting>\n";
3390 $desc .= "</programlisting>\n";
3393 $desc .= &MakeDeprecationNote($symbol);
3395 my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
3396 my $parameters_output = 0;
3398 $AllSymbols{$symbol} = 1;
3399 if (defined ($SymbolDocs{$symbol})) {
3400 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3402 # Try to insert the parameter table at the author's desired
3403 # position. Otherwise we need to tag it onto the end.
3404 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
3405 $parameters_output = 1;
3407 $desc .= $symbol_docs;
3409 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
3410 $AllDocumentedSymbols{$symbol} = 1;
3414 if ($parameters_output == 0) {
3415 $desc .= $parameters;
3417 $desc .= OutputSymbolTraits ($symbol);
3418 $desc .= "</refsect2>";
3421 return ($synop, $desc);
3425 #############################################################################
3426 # Function : GetArgs
3427 # Description : Returns the synopsis and detailed description DocBook output
3428 # for the Args of a given GtkObject subclass.
3429 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
3430 #############################################################################
3436 my $child_synop = "";
3437 my $child_desc = "";
3438 my $style_synop = "";
3439 my $style_desc = "";
3442 for ($i = 0; $i <= $#ArgObjects; $i++) {
3443 if ($ArgObjects[$i] eq $object) {
3444 #print "Found arg: $ArgNames[$i]\n";
3445 my $name = $ArgNames[$i];
3446 my $flags = $ArgFlags[$i];
3447 my $flags_string = "";
3451 if ($flags =~ m/c/) {
3452 $kind = "child property";
3455 elsif ($flags =~ m/s/) {
3456 $kind = "style property";
3463 # Remember only one colon so we don't clash with signals.
3464 my $symbol = "${object}:${name}";
3465 # use two dashes and ev. an extra separator here for the same reason.
3466 my $id = &CreateValidSGMLID ("$object--$id_sep$name");
3468 my $type = $ArgTypes[$i];
3470 my $range = $ArgRanges[$i];
3471 my $range_output = CreateValidSGML ($range);
3472 my $default = $ArgDefaults[$i];
3473 my $default_output = CreateValidSGML ($default);
3475 if ($type eq "GtkString") {
3478 if ($type eq "GtkSignal") {
3479 $type = "GtkSignalFunc, gpointer";
3480 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
3481 . &MakeXRef ("gpointer");
3482 } elsif ($type =~ m/^(\w+)\*$/) {
3483 $type_output = &MakeXRef ($1, &tagify($1, "type")) . "*";
3485 $type_output = &MakeXRef ($type, &tagify($type, "type"));
3488 if ($flags =~ m/r/) {
3489 $flags_string = "Read";
3491 if ($flags =~ m/w/) {
3492 if ($flags_string) { $flags_string .= " / "; }
3493 $flags_string .= "Write";
3495 if ($flags =~ m/x/) {
3496 if ($flags_string) { $flags_string .= " / "; }
3497 $flags_string .= "Construct";
3499 if ($flags =~ m/X/) {
3500 if ($flags_string) { $flags_string .= " / "; }
3501 $flags_string .= "Construct Only";
3504 $AllSymbols{$symbol} = 1;
3506 if (defined($SymbolDocs{$symbol}) &&
3507 !IsEmptyDoc($SymbolDocs{$symbol})) {
3508 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3509 #print ".. [$SymbolDocs{$symbol}][$blurb]\n";
3510 $AllDocumentedSymbols{$symbol} = 1;
3513 if (!($ArgBlurbs[$i] eq "")) {
3514 $AllDocumentedSymbols{$symbol} = 1;
3516 # FIXME: print a warning?
3517 #print ".. no description\n";
3519 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
3522 my $pad1 = " " x (24 - length ($name));
3523 my $pad2 = " " x (20 - length ($type));
3525 my $arg_synop = " "<link linkend=\"$id\">$name</link>"$pad1 $type_output $pad2 : $flags_string\n";
3526 my $arg_desc = "<refsect2 id=\"$id\" role=\"property\"><title>The <literal>"$name"</literal> $kind</title>\n";
3527 $arg_desc .= MakeIndexterms($symbol, $id);
3529 $arg_desc .= OutputSymbolExtraLinks($symbol);
3531 $arg_desc .= "<programlisting> "$name"$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
3532 $arg_desc .= &MakeDeprecationNote($symbol);
3533 $arg_desc .= $blurb;
3535 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
3537 if ($default ne "") {
3538 $arg_desc .= "<para>Default value: $default_output</para>\n";
3540 $arg_desc .= OutputSymbolTraits ($symbol);
3541 $arg_desc .= "</refsect2>\n";
3543 if ($flags =~ m/c/) {
3544 $child_synop .= $arg_synop;
3545 $child_desc .= $arg_desc;
3547 elsif ($flags =~ m/s/) {
3548 $style_synop .= $arg_synop;
3549 $style_desc .= $arg_desc;
3552 $synop .= $arg_synop;
3557 return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
3561 #############################################################################
3562 # Function : ReadSourceDocumentation
3563 # Description : This reads in the documentation embedded in comment blocks
3564 # in the source code (for Gnome).
3566 # Parameter descriptions override any in the template files.
3567 # Function descriptions are placed before any description from
3568 # the template files.
3570 # It recursively descends the source directory looking for .c
3571 # files and scans them looking for specially-formatted comment
3574 # Arguments : $source_dir - the directory to scan.
3575 #############m###############################################################
3577 sub ReadSourceDocumentation {
3578 my ($source_dir) = @_;
3579 my ($file, $dir, @suffix_list, $suffix);
3580 #print "Scanning source directory: $source_dir\n";
3582 # This array holds any subdirectories found.
3585 @suffix_list = split (/,/, $SOURCE_SUFFIXES);
3587 opendir (SRCDIR, $source_dir)
3588 || die "Can't open source directory $source_dir: $!";
3590 foreach $file (readdir (SRCDIR)) {
3591 if ($file =~ /^\./) {
3593 } elsif (-d "$source_dir/$file") {
3594 push (@subdirs, $file);
3595 } elsif (@suffix_list) {
3596 foreach $suffix (@suffix_list) {
3597 if ($file =~ m/\.\Q${suffix}\E$/) {
3598 &ScanSourceFile ("$source_dir/$file");
3601 } elsif ($file =~ m/\.[ch]$/) {
3602 &ScanSourceFile ("$source_dir/$file");
3607 # Now recursively scan the subdirectories.
3608 foreach $dir (@subdirs) {
3609 next if ($IGNORE_FILES =~ m/(\s|^)\Q${dir}\E(\s|$)/);
3610 &ReadSourceDocumentation ("$source_dir/$dir");
3615 #############################################################################
3616 # Function : ScanSourceFile
3617 # Description : Scans one source file looking for specially-formatted comment
3618 # blocks. Later &MergeSourceDocumentation is used to merge any
3619 # documentation found with the documentation already read in
3620 # from the template files.
3622 # Arguments : $file - the file to scan.
3623 #############################################################################
3625 sub ScanSourceFile {
3629 if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
3632 &LogWarning ($file, 1, "Can't find basename for this filename.");
3636 # Check if the basename is in the list of files to ignore.
3637 if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
3641 #print "DEBUG: Scanning $file\n";
3643 open (SRCFILE, $file)
3644 || die "Can't open $file: $!";
3645 my $in_comment_block = 0;
3647 my ($in_description, $in_return, $in_since, $in_stability, $in_deprecated);
3648 my ($description, $return_desc, $return_start, $return_style);
3649 my ($since_desc, $stability_desc, $deprecated_desc);
3651 my $ignore_broken_returns;
3654 # Look for the start of a comment block.
3655 if (!$in_comment_block) {
3656 if (m%^\s*/\*.*\*/%) {
3657 #one-line comment - not gtkdoc
3658 } elsif (m%^\s*/\*\*\s%) {
3659 #print "Found comment block start\n";
3661 $in_comment_block = 1;
3663 # Reset all the symbol data.
3665 $in_description = 0;
3674 $deprecated_desc = "";
3675 $stability_desc = "";
3676 $current_param = -1;
3677 $ignore_broken_returns = 0;
3683 # We're in a comment block. Check if we've found the end of it.
3686 # maybe its not even meant to be a gtk-doc comment?
3687 &LogWarning ($file, $., "Symbol name not found at the start of the comment block.");
3689 # Add the return value description onto the end of the params.
3691 push (@params, "Returns");
3692 push (@params, $return_desc);
3693 if ($return_style eq 'broken') {
3694 &LogWarning ($file, $., "Free-form return value description in $symbol. Use `Returns:' to avoid ambiguities.");
3697 # Convert special SGML characters
3698 $description = &ConvertSGMLChars ($symbol, $description);
3700 for ($k = 1; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3701 $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
3704 # Handle Section docs
3705 if ($symbol =~ m/SECTION:\s*(.*)/) {
3709 if (scalar %KnownSymbols) {
3710 if ((! defined($KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"})) || $KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"} != 1) {
3711 &LogWarning ($file, $., "Section $real_symbol is not defined in the $MODULE-section.txt file.");
3715 #print "SECTION DOCS found in source for : '$real_symbol'\n";
3716 $ignore_broken_returns = 1;
3717 for ($k = 0; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3718 #print " '".$params[$k]."'\n";
3719 $params[$k] = "\L$params[$k]";
3721 if ($params[$k] eq "short_description") {
3722 $key = "$TMPL_DIR/$real_symbol:Short_Description";
3723 } elsif ($params[$k] eq "see_also") {
3724 $key = "$TMPL_DIR/$real_symbol:See_Also";
3725 } elsif ($params[$k] eq "title") {
3726 $key = "$TMPL_DIR/$real_symbol:Title";
3727 } elsif ($params[$k] eq "stability") {
3728 $key = "$TMPL_DIR/$real_symbol:Stability_Level";
3729 } elsif ($params[$k] eq "section_id") {
3730 $key = "$TMPL_DIR/$real_symbol:Section_Id";
3731 } elsif ($params[$k] eq "include") {
3732 $key = "$TMPL_DIR/$real_symbol:Include";
3733 } elsif ($params[$k] eq "image") {
3734 $key = "$TMPL_DIR/$real_symbol:Image";
3736 if (defined($key)) {
3737 $SourceSymbolDocs{$key}=$params[$k+1];
3738 $SourceSymbolSourceFile{$key} = $file;
3739 $SourceSymbolSourceLine{$key} = $.;
3742 $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
3743 $SourceSymbolSourceFile{"$TMPL_DIR/$real_symbol:Long_Description"} = $file;
3744 $SourceSymbolSourceLine{"$TMPL_DIR/$real_symbol:Long_Description"} = $.;
3745 #$SourceSymbolTypes{$symbol} = "SECTION";
3747 #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
3748 $SourceSymbolDocs{$symbol} = $description;
3749 $SourceSymbolParams{$symbol} = [ @params ];
3750 # FIXME $SourceSymbolTypes{$symbol} = "STRUCT,SIGNAL,ARG,FUNCTION,MACRO";
3751 #if (defined $DeclarationTypes{$symbol}) {
3752 # $SourceSymbolTypes{$symbol} = $DeclarationTypes{$symbol}
3754 $SourceSymbolSourceFile{$symbol} = $file;
3755 $SourceSymbolSourceLine{$symbol} = $.;
3759 ($since_desc, my @extra_lines) = split ("\n", $since_desc);
3760 $since_desc =~ s/^\s+//;
3761 $since_desc =~ s/\s+$//;
3762 #print "Since($symbol) : [$since_desc]\n";
3763 $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
3764 if(scalar @extra_lines) {
3765 &LogWarning ($file, $., "multi-line since docs found");
3769 if ($stability_desc) {
3770 $stability_desc = &ParseStabilityLevel($stability_desc, $file, $., "Stability level for $symbol");
3771 $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
3774 if ($deprecated_desc) {
3775 if (exists $Deprecated{$symbol}) {
3778 # don't warn for signals and properties
3779 #if ($symbol !~ m/::?(.*)/) {
3780 if (defined $DeclarationTypes{$symbol}) {
3781 &LogWarning ($file, $.,
3782 "$symbol is deprecated in the inline comments, but no deprecation guards were found around the declaration.".
3783 " (See the --deprecated-guards option for gtkdoc-scan.)");
3786 $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
3790 $in_comment_block = 0;
3794 # Get rid of ' * ' at start of every line in the comment block.
3796 # But make sure we don't get rid of the newline at the end.
3800 #print "DEBUG: scanning :$_";
3802 # If we haven't found the symbol name yet, look for it.
3804 if (m%^\s*(SECTION:\s*\S+)%) {
3806 #print "SECTION DOCS found in source for : '$symbol'\n";
3807 $ignore_broken_returns = 1;
3808 } elsif (m%^\s*([\w:-]*\w)\s*:?\s*(\([a-z ]+\)\s*)*$%) {
3810 #print "SYMBOL DOCS found in source for : '$symbol'\n";
3815 # If we're in the return value description, add it to the end.
3817 # If we find another valid returns line, we assume that the first
3818 # one was really part of the description.
3819 if (m/^\s*(returns:|return\s+value:)/i) {
3820 if ($return_style eq 'broken') {
3821 $description .= $return_start . $return_desc;
3824 if ($return_style eq 'sane') {
3825 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3827 $return_style = 'sane';
3828 $ignore_broken_returns = 1;
3830 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3831 $description .= $return_start . $return_desc;
3833 $return_style = 'broken';
3835 } elsif (m%^\s*since:%i) {
3839 } elsif (m%^\s*stability:%i) {
3840 $stability_desc = $';
3843 } elsif (m%^\s*deprecated:%i) {
3844 $deprecated_desc = $';
3854 if (m/^\s*(returns:|return\s+value:)/i) {
3855 if ($return_style eq 'broken') {
3856 $description .= $return_start . $return_desc;
3859 if ($return_style eq 'sane') {
3860 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3862 $return_style = 'sane';
3863 $ignore_broken_returns = 1;
3867 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3869 $return_style = 'broken';
3873 } elsif (m%^\s*deprecated:%i) {
3874 $deprecated_desc = $';
3877 } elsif (m%^\s*stability:%i) {
3878 $stability_desc = $';
3887 if ($in_stability) {
3888 if (m/^\s*(returns:|return\s+value:)/i) {
3889 if ($return_style eq 'broken') {
3890 $description .= $return_start . $return_desc;
3893 if ($return_style eq 'sane') {
3894 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3896 $return_style = 'sane';
3897 $ignore_broken_returns = 1;
3901 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3903 $return_style = 'broken';
3907 } elsif (m%^\s*deprecated:%i) {
3908 $deprecated_desc = $';
3911 } elsif (m%^\s*since:%i) {
3916 $stability_desc .= $_;
3921 if ($in_deprecated) {
3922 if (m/^\s*(returns:|return\s+value:)/i) {
3923 if ($return_style eq 'broken') {
3924 $description .= $return_start . $return_desc;
3927 if ($return_style eq 'sane') {
3928 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3930 $return_style = 'sane';
3931 $ignore_broken_returns = 1;
3935 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3937 $return_style = 'broken';
3941 } elsif (m%^\s*since:%i) {
3945 } elsif (m%^\s*stability:%i) {
3946 $stability_desc = $';
3950 $deprecated_desc .= $_;
3955 # If we're in the description part, check for the 'Returns:' line.
3956 # If that isn't found, add the text to the end.
3957 if ($in_description) {
3958 # Get rid of 'Description:'
3959 s%^\s*Description:%%;
3961 if (m/^\s*(returns:|return\s+value:)/i) {
3962 if ($return_style eq 'broken') {
3963 $description .= $return_start . $return_desc;
3966 if ($return_style eq 'sane') {
3967 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3969 $return_style = 'sane';
3970 $ignore_broken_returns = 1;
3974 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3976 $return_style = 'broken';
3980 } elsif (m%^\s*since:%i) {
3984 } elsif (m%^\s*deprecated:%i) {
3985 $deprecated_desc = $';
3988 } elsif (m%^\s*stability:%i) {
3989 $stability_desc = $';
3998 # We must be in the parameters. Check for the empty line below them.
4000 $in_description = 1;
4004 # Look for a parameter name.
4005 if (m%^\s*@(\S+)\s*:\s*%) {
4006 my $param_name = $1;
4007 my $param_desc = $';
4009 #print "Found parameter: $param_name\n";
4010 # Allow '...' as the Varargs parameter.
4011 if ($param_name eq "...") {
4012 $param_name = "Varargs";
4014 if ("\L$param_name" eq "returns") {
4015 $return_style = 'sane';
4016 $ignore_broken_returns = 1;
4018 push (@params, $param_name);
4019 push (@params, $param_desc);
4020 $current_param += $PARAM_FIELD_COUNT;
4024 # We must be in the middle of a parameter description, so add it on
4025 # to the last element in @params.
4026 if ($current_param == -1) {
4027 &LogWarning ($file, $., "Parsing comment block file : parameter expected.");
4029 $params[$#params] .= $_;
4035 #############################################################################
4036 # Function : OutputMissingDocumentation
4037 # Description : Outputs report of documentation coverage to a file
4040 #############################################################################
4042 sub OutputMissingDocumentation {
4043 my $old_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.txt";
4044 my $new_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.new";
4046 my $n_documented = 0;
4047 my $n_incomplete = 0;
4053 my $buffer_deprecated = "";
4054 my $buffer_descriptions = "";
4056 open(UNDOCUMENTED, ">$new_undocumented_file")
4057 || die "Can't create $new_undocumented_file";
4059 foreach $symbol (sort (keys (%AllSymbols))) {
4060 # FIXME: should we print LogWarnings for undocumented stuff?
4062 #my $ssfile = &GetSymbolSourceFile($symbol);
4063 #my $ssline = &GetSymbolSourceLine($symbol);
4064 #my $location = "defined at " . (defined($ssfile)?$ssfile:"?") . ":" . (defined($ssline)?$ssline:"0") . "\n";
4066 if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include|Section_Id|Image)/) {
4068 if (exists ($AllDocumentedSymbols{$symbol})) {
4070 if (exists ($AllIncompleteSymbols{$symbol})) {
4072 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4073 #$buffer .= "\t0: ".$location;
4075 } elsif (exists $Deprecated{$symbol}) {
4076 if (exists ($AllIncompleteSymbols{$symbol})) {
4078 $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4079 #$buffer .= "\t1a: ".$location;
4081 $buffer_deprecated .= $symbol . "\n";
4082 #$buffer .= "\t1b: ".$location;
4085 if (exists ($AllIncompleteSymbols{$symbol})) {
4087 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4088 #$buffer .= "\t2a: ".$location;
4090 $buffer .= $symbol . "\n";
4091 #$buffer .= "\t2b: ".$location;
4094 } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
4096 #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
4097 #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
4098 #print "%%%% $symbol : $len1,$len2\n";
4099 if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
4100 || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
4103 # cut off the leading namespace ($TMPL_DIR)
4104 $symbol =~ m/^.*\/(.*)$/;
4105 $buffer_descriptions .= $1 . "\n";
4110 $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
4115 $percent = ($n_documented / $total) * 100.0;
4118 printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
4119 print UNDOCUMENTED "$n_documented symbols documented.\n";
4120 print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
4121 print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
4123 print UNDOCUMENTED $buffer;
4124 close (UNDOCUMENTED);
4126 return &UpdateFileIfChanged ($old_undocumented_file, $new_undocumented_file, 0);
4128 printf "%.0f%% symbol docs coverage", $percent;
4129 print "($n_documented symbols documented, $n_incomplete symbols incomplete, " . ($total - $n_documented) . " not documented)\n";
4130 print "See $MODULE-undocumented.txt for a list of missing docs.\nThe doc coverage percentage doesn't include intro sections.\n";
4134 #############################################################################
4135 # Function : OutputUndeclaredSymbols
4136 # Description : Outputs symbols that are listed in the section file, but not
4137 # declaration is found in the sources
4140 #############################################################################
4142 sub OutputUndeclaredSymbols {
4143 my $old_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.txt";
4144 my $new_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.new";
4146 open(UNDECLARED, ">$new_undeclared_file")
4147 || die "Can't create $new_undeclared_file";
4149 if (%UndeclaredSymbols) {
4150 print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
4151 print UNDECLARED "\n";
4152 print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
4156 return &UpdateFileIfChanged ($old_undeclared_file, $new_undeclared_file, 0);
4159 #############################################################################
4160 # Function : OutputUnusedSymbols
4161 # Description : Outputs symbols that are documented in comments, but not
4162 # declared in the sources
4165 #############################################################################
4167 sub OutputUnusedSymbols {
4169 my $old_unused_file = "$ROOT_DIR/$MODULE-unused.txt";
4170 my $new_unused_file = "$ROOT_DIR/$MODULE-unused.new";
4172 open (UNUSED, ">$new_unused_file")
4173 || die "Can't open $new_unused_file";
4175 foreach $symbol (sort keys (%Declarations)) {
4176 if (!defined ($DeclarationOutput{$symbol})) {
4177 print (UNUSED "$symbol\n");
4181 foreach $symbol (sort (keys (%AllUnusedSymbols))) {
4182 print (UNUSED "$symbol(" . $AllUnusedSymbols{$symbol} . ")\n");
4186 if ($num_unused != 0) {
4187 &LogWarning ($old_unused_file, 1, "$num_unused unused declarations.".
4188 "They should be added to $MODULE-sections.txt in the appropriate place.");
4191 return &UpdateFileIfChanged ($old_unused_file, $new_unused_file, 0);
4195 #############################################################################
4196 # Function : OutputAllSymbols
4197 # Description : Outputs list of all symbols to a file
4200 #############################################################################
4202 sub OutputAllSymbols {
4203 my $n_documented = 0;
4209 open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
4210 || die "Can't create $ROOT_DIR/$MODULE-symbols.txt: $!";
4212 foreach $symbol (sort (keys (%AllSymbols))) {
4213 print SYMBOLS $symbol . "\n";
4219 #############################################################################
4220 # Function : OutputSymbolsWithoutSince
4221 # Description : Outputs list of all symbols without a since tag to a file
4224 #############################################################################
4226 sub OutputSymbolsWithoutSince {
4227 my $n_documented = 0;
4233 open (SYMBOLS, ">$ROOT_DIR/$MODULE-nosince.txt")
4234 || die "Can't create $ROOT_DIR/$MODULE-nosince.txt: $!";
4236 foreach $symbol (sort (keys (%SourceSymbolDocs))) {
4237 if (!defined $Since{$symbol}) {
4238 print SYMBOLS $symbol . "\n";
4246 #############################################################################
4247 # Function : MergeSourceDocumentation
4248 # Description : This merges documentation read from a source file into the
4249 # documentation read in from a template file.
4251 # Parameter descriptions override any in the template files.
4252 # Function descriptions are placed before any description from
4253 # the template files.
4256 #############################################################################
4258 sub MergeSourceDocumentation {
4262 if (scalar %SymbolDocs) {
4263 @Symbols=keys (%SymbolDocs);
4264 #print "num existing entries: ".(scalar @Symbols)."\n";
4265 #print " ",$Symbols[0], " ",$Symbols[1],"\n";
4268 # filter scanned declarations, with what we suppress from -sections.txt
4270 foreach $symbol (keys (%Declarations)) {
4271 if (defined($KnownSymbols{$symbol}) && $KnownSymbols{$symbol} == 1) {
4275 # , add the rest from -sections.txt
4276 foreach $symbol (keys (%KnownSymbols)) {
4277 if ($KnownSymbols{$symbol} == 1) {
4281 # and add whats found in the source
4282 foreach $symbol (keys (%SourceSymbolDocs)) {
4285 @Symbols = keys (%tmp);
4286 #print "num source entries: ".(scalar @Symbols)."\n";
4288 foreach $symbol (@Symbols) {
4289 $AllSymbols{$symbol} = 1;
4291 my $have_tmpl_docs = 0;
4293 ## See if the symbol is documented in template
4294 my $tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4295 my $check_tmpl_doc =$tmpl_doc;
4296 # remove all xml-tags and whitespaces (don't kill <include href="..."> tags)
4297 $check_tmpl_doc =~ s/<\/?[a-z]+>//gi;
4298 $check_tmpl_doc =~ s/\s//g;
4300 if ($check_tmpl_doc ne "") {
4301 $have_tmpl_docs = 1;
4302 #print "## [$check_tmpl_doc]\n";
4307 if (exists ($SourceSymbolDocs{$symbol})) {
4308 my $type = $DeclarationTypes {$symbol};
4310 #print "merging [$symbol] from source\n";
4312 my $item = "Parameter";
4313 if (defined ($type)) {
4314 if ($type eq 'STRUCT') {
4316 } elsif ($type eq 'ENUM') {
4318 } elsif ($type eq 'UNION') {
4325 my $src_doc = $SourceSymbolDocs{$symbol};
4326 # remove leading and training whitespaces
4327 $src_doc =~ s/^\s+//;
4328 $src_doc =~ s/\s+$//;
4330 # Don't output warnings for overridden titles as titles are
4331 # automatically generated in the -sections.txt file, and thus they
4332 # are often overridden.
4333 if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
4334 # check if content is different
4335 if ($tmpl_doc ne $src_doc) {
4336 #print "[$tmpl_doc] [$src_doc]\n";
4337 &LogWarning ($SourceSymbolSourceFile{$symbol}, $SourceSymbolSourceLine{$symbol},
4338 "Documentation in template ".$SymbolSourceFile{$symbol}.":".$SymbolSourceLine{$symbol}." for $symbol being overridden by inline comments.");
4342 if ($src_doc ne "") {
4343 $AllDocumentedSymbols{$symbol} = 1;
4346 # Convert <!--PARAMETERS--> with any blank lines around it to
4347 # a </para> followed by <!--PARAMETERS--> followed by <para>.
4348 $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
4350 # Do not add <para> to nothing, it breaks missing docs checks.
4351 my $src_doc_para = "";
4352 if ($src_doc ne "") {
4353 # If there is a blank line, finish the paragraph and start another.
4354 $src_doc = &ConvertBlankLines ($src_doc, $symbol);
4355 $src_doc_para = "<para>\n$src_doc\n</para>";
4357 # FIXME: this is questionable, as we can't make assumtions on the content really
4358 #$src_doc_para =~ s%^<para>\n(<refsect[1-9])%$1%gms;
4359 #$src_doc_para =~ s%^<para>\n<para>%<para>%gms;
4360 #$src_doc_para =~ s%(</refsect[1-9]>)\n</para>$%$1%gms;
4361 #print "$symbol : [$src_doc][$src_doc_para]\n";
4364 if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
4365 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4366 } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
4367 # For the title/summary/see also section docs we don't want to
4368 # add any <para> tags.
4369 $SymbolDocs{$symbol} = "$src_doc"
4371 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4375 if ($symbol =~ m/.*::.*/) {
4376 # For signals we prefer the param names from the source docs,
4377 # since the ones from the templates are likely to contain the
4378 # artificial argn names which are generated by gtkdoc-scangobj.
4379 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4380 # FIXME: we need to check for empty docs here as well!
4382 # The templates contain the definitive parameter names and order,
4383 # so we will not change that. We only override the actual text.
4384 my $tmpl_params = $SymbolParams{$symbol};
4385 if (!defined ($tmpl_params)) {
4386 #print "No merge needed for $symbol\n";
4387 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4388 # FIXME: we still like to get the number of params and merge
4389 # 1) we would noticed that params have been removed/renamed
4390 # 2) we would catch undocumented params
4391 # params are not (yet) exported in -decl.txt so that we
4392 # could easily grab them :/
4394 my $params = $SourceSymbolParams{$symbol};
4396 #print "Merge needed for $symbol, tmpl_params: ",$#$tmpl_params,", source_params: ",$#$params," \n";
4397 for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4398 my $tmpl_param_name = $$tmpl_params[$j];
4400 # Allow '...' as the Varargs parameter.
4401 if ($tmpl_param_name eq "...") {
4402 $tmpl_param_name = "Varargs";
4405 # Try to find the param in the source comment documentation.
4408 #print " try merge param $tmpl_param_name\n";
4409 for ($k = 0; $k <= $#$params; $k += $PARAM_FIELD_COUNT) {
4410 my $param_name = $$params[$k];
4411 my $param_desc = $$params[$k + 1];
4413 #print " test param $param_name\n";
4414 # We accept changes in case, since the Gnome source
4415 # docs contain a lot of these.
4416 if ("\L$param_name" eq "\L$tmpl_param_name") {
4419 # Override the description.
4420 $$tmpl_params[$j + 1] = $param_desc;
4422 # Set the name to "" to mark it as used.
4428 # If it looks like the parameters are there, but not
4429 # in the right place, try to explain a bit better.
4430 if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
4431 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4432 "Parameters for $symbol must start on the line immediately after the function or macro name.");
4436 # Now we output a warning if parameters have been described which
4438 for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
4439 my $param_name = $$params[$j];
4441 # the template builder cannot detect if a macro returns
4443 if(($type eq "MACRO") && ($param_name eq "Returns")) {
4444 # FIXME: do we need to add it then to tmpl_params[] ?
4445 my $num=$#$tmpl_params;
4446 #print " adding Returns: to macro docs for $symbol.\n";
4447 $$tmpl_params[$num+1]="Returns";
4448 $$tmpl_params[$num+2]=$$params[$j+1];
4451 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4452 "$item described in source code comment block but does not exist. $type: $symbol $item: $param_name.");
4458 if ($have_tmpl_docs) {
4459 $AllDocumentedSymbols{$symbol} = 1;
4460 #print "merging [$symbol] from template\n";
4463 #print "[$symbol] undocumented\n";
4467 # if this symbol is documented, check if docs are complete
4468 $check_tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4469 # remove all xml-tags and whitespaces
4470 #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
4471 $check_tmpl_doc =~ s/<.*?>//g;
4472 $check_tmpl_doc =~ s/\s//g;
4473 if ($check_tmpl_doc ne "") {
4474 my $tmpl_params = $SymbolParams{$symbol};
4475 if (defined ($tmpl_params)) {
4476 my $type = $DeclarationTypes {$symbol};
4478 my $item = "Parameter";
4479 if (defined ($type)) {
4480 if ($type eq 'STRUCT') {
4482 } elsif ($type eq 'ENUM') {
4484 } elsif ($type eq 'UNION') {
4491 #print "Check param docs for $symbol, tmpl_params: ",$#$tmpl_params," entries, type=$type\n";
4493 if ($#$tmpl_params > 0) {
4495 for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4496 # Output a warning if the parameter is empty and
4497 # remember for stats.
4498 my $tmpl_param_name = $$tmpl_params[$j];
4499 my $tmpl_param_desc = $$tmpl_params[$j + 1];
4500 if ($tmpl_param_name ne "void" && $tmpl_param_desc !~ m/\S/) {
4501 if (exists ($AllIncompleteSymbols{$symbol})) {
4502 $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
4504 $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
4506 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4507 "$item description for $symbol"."::"."$tmpl_param_name is missing in source code comment block.");
4512 if ($#$tmpl_params == 0) {
4513 $AllIncompleteSymbols{$symbol}="<items>";
4514 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4515 "$item descriptions for $symbol are missing in source code comment block.");
4517 # $#$tmpl_params==-1 means we don't know about parameters
4518 # this unfortunately does not tell if there should be some
4523 #print "num doc entries: ".(scalar %SymbolDocs)."\n";
4526 #############################################################################
4527 # Function : IsEmptyDoc
4528 # Description : Check if a doc-string is empty. Its also regarded as empty if
4529 # it only consist of whitespace or e.g. FIXME.
4530 # Arguments : the doc-string
4531 #############################################################################
4535 if ($doc =~ /^\s*$/) {
4539 if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
4547 # This converts blank lines to "</para><para>", but only outside CDATA and
4548 # <programlisting> tags.
4549 sub ConvertBlankLines {
4550 return &ModifyXMLElements ($_[0], $_[1],
4551 "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
4552 \&ConvertBlankLinesEndTag,
4553 \&ConvertBlankLinesCallback);
4557 sub ConvertBlankLinesEndTag {
4558 if ($_[0] eq "<!\[CDATA\[") {
4560 } elsif ($_[0] eq "|[") {
4563 return "</programlisting>";
4567 sub ConvertBlankLinesCallback {
4568 my ($text, $symbol, $tag) = @_;
4570 # If we're not in CDATA or a <programlisting> we convert blank lines so
4571 # they start a new <para>.
4573 $text =~ s%\n{2,}%\n</para>\n<para>\n%g;
4580 #############################################################################
4581 # LIBRARY FUNCTIONS - These functions are used in both gtkdoc-mkdb and
4582 # gtkdoc-mktmpl and should eventually be moved to a
4584 #############################################################################
4586 #############################################################################
4587 # Function : ReadDeclarationsFile
4588 # Description : This reads in a file containing the function/macro/enum etc.
4591 # Note that in some cases there are several declarations with
4592 # the same name, e.g. for conditional macros. In this case we
4593 # set a flag in the %DeclarationConditional hash so the
4594 # declaration is not shown in the docs.
4596 # If a macro and a function have the same name, e.g. for
4597 # gtk_object_ref, the function declaration takes precedence.
4599 # Some opaque structs are just declared with 'typedef struct
4600 # _name name;' in which case the declaration may be empty.
4601 # The structure may have been found later in the header, so
4602 # that overrides the empty declaration.
4604 # Arguments : $file - the declarations file to read
4605 # $override - if declarations in this file should override
4606 # any current declaration.
4607 #############################################################################
4609 sub ReadDeclarationsFile {
4610 my ($file, $override) = @_;
4612 if ($override == 0) {
4614 %DeclarationTypes = ();
4615 %DeclarationConditional = ();
4616 %DeclarationOutput = ();
4620 || die "Can't open $file: $!";
4621 my $declaration_type = "";
4622 my $declaration_name;
4624 my $is_deprecated = 0;
4626 if (!$declaration_type) {
4627 if (m/^<([^>]+)>/) {
4628 $declaration_type = $1;
4629 $declaration_name = "";
4630 #print "Found declaration: $declaration_type\n";
4634 if (m%^<NAME>(.*)</NAME>%) {
4635 $declaration_name = $1;
4636 } elsif (m%^<DEPRECATED/>%) {
4638 } elsif (m%^</$declaration_type>%) {
4639 #print "Found end of declaration: $declaration_name\n";
4640 # Check that the declaration has a name
4641 if ($declaration_name eq "") {
4642 print "ERROR: $declaration_type has no name $file:$.\n";
4645 # If the declaration is an empty typedef struct _XXX XXX
4646 # set the flag to indicate the struct has a typedef.
4647 if ($declaration_type eq 'STRUCT'
4648 && $declaration =~ m/^\s*$/) {
4649 #print "Struct has typedef: $declaration_name\n";
4650 $StructHasTypedef{$declaration_name} = 1;
4653 # Check if the symbol is already defined.
4654 if (defined ($Declarations{$declaration_name})
4655 && $override == 0) {
4656 # Function declarations take precedence.
4657 if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
4659 } elsif ($declaration_type eq 'FUNCTION') {
4660 if ($is_deprecated) {
4661 $Deprecated{$declaration_name} = "";
4663 $Declarations{$declaration_name} = $declaration;
4664 $DeclarationTypes{$declaration_name} = $declaration_type;
4665 } elsif ($DeclarationTypes{$declaration_name}
4666 eq $declaration_type) {
4667 # If the existing declaration is empty, or is just a
4668 # forward declaration of a struct, override it.
4669 if ($declaration_type eq 'STRUCT') {
4670 if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4671 if ($is_deprecated) {
4672 $Deprecated{$declaration_name} = "";
4674 $Declarations{$declaration_name} = $declaration;
4675 } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4676 # Ignore an empty or forward declaration.
4678 &LogWarning ($file, $., "Structure $declaration_name has multiple definitions.");
4681 # set flag in %DeclarationConditional hash for
4682 # multiply defined macros/typedefs.
4683 $DeclarationConditional{$declaration_name} = 1;
4686 &LogWarning ($file, $., "$declaration_name has multiple definitions.");
4689 if ($is_deprecated) {
4690 $Deprecated{$declaration_name} = "";
4692 $Declarations{$declaration_name} = $declaration;
4693 $DeclarationTypes{$declaration_name} = $declaration_type;
4696 $declaration_type = "";
4707 #############################################################################
4708 # Function : ReadSignalsFile
4709 # Description : This reads in an existing file which contains information on
4710 # all GTK signals. It creates the arrays @SignalNames and
4711 # @SignalPrototypes containing info on the signals. The first
4712 # line of the SignalPrototype is the return type of the signal
4713 # handler. The remaining lines are the parameters passed to it.
4714 # The last parameter, "gpointer user_data" is always the same
4715 # so is not included.
4716 # Arguments : $file - the file containing the signal handler prototype
4718 #############################################################################
4720 sub ReadSignalsFile {
4728 my $signal_prototype;
4730 # Reset the signal info.
4731 @SignalObjects = ();
4733 @SignalReturns = ();
4735 @SignalPrototypes = ();
4740 if (!open (INPUT, $file)) {
4741 warn "Can't open $file - skipping signals\n";
4748 $signal_object = "";
4750 $signal_returns = "";
4751 $signal_prototype = "";
4754 if (m/^<NAME>(.*)<\/NAME>/) {
4756 if ($signal_name =~ m/^(.*)::(.*)$/) {
4757 $signal_object = $1;
4758 ($signal_name = $2) =~ s/_/-/g;
4759 #print "Found signal: $signal_name\n";
4761 &LogWarning ($file, $., "Invalid signal name: $signal_name.");
4763 } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
4764 $signal_returns = $1;
4765 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4767 } elsif (m%^</SIGNAL>%) {
4768 #print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
4769 push (@SignalObjects, $signal_object);
4770 push (@SignalNames, $signal_name);
4771 push (@SignalReturns, $signal_returns);
4772 push (@SignalFlags, $signal_flags);
4773 push (@SignalPrototypes, $signal_prototype);
4776 $signal_prototype .= $_;
4784 #############################################################################
4785 # Function : ReadTemplateFile
4786 # Description : This reads in the manually-edited documentation file
4787 # corresponding to the file currently being created, so we can
4788 # insert the documentation at the appropriate places.
4789 # It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
4790 # is a hash of arrays.
4791 # NOTE: This function is duplicated in gtkdoc-mktmpl (but
4792 # slightly different).
4793 # Arguments : $docsfile - the template file to read in.
4794 # $skip_unused_params - 1 if the unused parameters should be
4796 #############################################################################
4798 sub ReadTemplateFile {
4799 my ($docsfile, $skip_unused_params) = @_;
4801 my $template = "$docsfile.sgml";
4802 if (! -f $template) {
4803 #print "File doesn't exist: $template\n";
4806 #print "Reading $template\n";
4808 # start with empty hashes, we merge the source comment for each file
4814 my $current_type = ""; # Type of symbol being read.
4815 my $current_symbol = ""; # Name of symbol being read.
4816 my $symbol_doc = ""; # Description of symbol being read.
4817 my @params; # Parameter names and descriptions of current
4818 # function/macro/function typedef.
4819 my $current_param = -1; # Index of parameter currently being read.
4820 # Note that the param array contains pairs
4821 # of param name & description.
4822 my $in_unused_params = 0; # True if we are reading in the unused params.
4823 my $in_deprecated = 0;
4825 my $in_stability = 0;
4827 open (DOCS, "$template")
4828 || die "Can't open $template: $!";
4830 if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
4833 if ($symbol eq "Title"
4834 || $symbol eq "Short_Description"
4835 || $symbol eq "Long_Description"
4836 || $symbol eq "See_Also"
4837 || $symbol eq "Stability_Level"
4838 || $symbol eq "Include"
4839 || $symbol eq "Image") {
4841 $symbol = $docsfile . ":" . $symbol;
4844 #print "Found symbol: $symbol\n";
4845 # Remember file and line for the symbol
4846 $SymbolSourceFile{$symbol} = $template;
4847 $SymbolSourceLine{$symbol} = $.;
4849 # Store previous symbol, but remove any trailing blank lines.
4850 if ($current_symbol ne "") {
4851 $symbol_doc =~ s/\s+$//;
4852 $SymbolTypes{$current_symbol} = $current_type;
4853 $SymbolDocs{$current_symbol} = $symbol_doc;
4855 # Check that the stability level is valid.
4856 if ($StabilityLevel{$current_symbol}) {
4857 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4860 if ($current_param >= 0) {
4861 $SymbolParams{$current_symbol} = [ @params ];
4863 # Delete any existing params in case we are overriding a
4864 # previously read template.
4865 delete $SymbolParams{$current_symbol};
4868 $current_type = $type;
4869 $current_symbol = $symbol;
4870 $current_param = -1;
4871 $in_unused_params = 0;
4878 } elsif (m/^<!-- # Unused Parameters # -->/) {
4879 #print "DEBUG: Found unused parameters\n";
4880 $in_unused_params = 1;
4883 } elsif ($in_unused_params && $skip_unused_params) {
4884 # When outputting the DocBook we skip unused parameters.
4885 #print "DEBUG: Skipping unused param: $_";
4889 # Check if param found. Need to handle "..." and "format...".
4890 if (s/^\@([\w\.]+):\040?//) {
4891 my $param_name = $1;
4892 my $param_desc = $_;
4893 # Allow variations of 'Returns'
4894 if ($param_name =~ m/^[Rr]eturns?$/) {
4895 $param_name = "Returns";
4898 # strip trailing whitespaces and blank lines
4901 #print "Found param for symbol $current_symbol : '$param_name'= '$_'";
4903 if ($param_name eq "Deprecated") {
4905 $Deprecated{$current_symbol} = $_;
4906 } elsif ($param_name eq "Since") {
4909 $Since{$current_symbol} = $_;
4910 } elsif ($param_name eq "Stability") {
4912 $StabilityLevel{$current_symbol} = $_;
4914 push (@params, $param_name);
4915 push (@params, $param_desc);
4916 $current_param += $PARAM_FIELD_COUNT;
4919 # strip trailing whitespaces and blank lines
4924 if ($in_deprecated) {
4925 $Deprecated{$current_symbol} .= $_;
4926 } elsif ($in_since) {
4927 &LogWarning ($template, $., "multi-line since docs found");
4928 #$Since{$current_symbol} .= $_;
4929 } elsif ($in_stability) {
4930 $StabilityLevel{$current_symbol} .= $_;
4931 } elsif ($current_param >= 0) {
4932 $params[$current_param] .= $_;
4941 # Remember to finish the current symbol doccs.
4942 if ($current_symbol ne "") {
4944 $symbol_doc =~ s/\s+$//;
4945 $SymbolTypes{$current_symbol} = $current_type;
4946 $SymbolDocs{$current_symbol} = $symbol_doc;
4948 # Check that the stability level is valid.
4949 if ($StabilityLevel{$current_symbol}) {
4950 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4953 if ($current_param >= 0) {
4954 $SymbolParams{$current_symbol} = [ @params ];
4956 # Delete any existing params in case we are overriding a
4957 # previously read template.
4958 delete $SymbolParams{$current_symbol};
4967 #############################################################################
4968 # Function : ReadObjectHierarchy
4969 # Description : This reads in the $MODULE-hierarchy.txt file containing all
4970 # the GtkObject subclasses described in this module (and their
4972 # It places them in the @Objects array, and places their level
4973 # in the object hierarchy in the @ObjectLevels array, at the
4974 # same index. GtkObject, the root object, has a level of 1.
4976 # FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
4977 # as it goes along, this should be split out into a separate
4981 #############################################################################
4983 sub ReadObjectHierarchy {
4987 if (! -f $OBJECT_TREE_FILE) {
4990 if (!open (INPUT, $OBJECT_TREE_FILE)) {
4991 warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
4995 # FIXME: use $OUTPUT_FORMAT
4996 # my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.$OUTPUT_FORMAT";
4997 my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
4998 my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
5000 open (OUTPUT, ">$new_tree_index")
5001 || die "Can't create $new_tree_index: $!";
5003 if ($OUTPUT_FORMAT eq "xml") {
5004 my $tree_header = $doctype_header;
5006 $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
5007 print (OUTPUT "$tree_header");
5009 print (OUTPUT "<screen>\n");
5011 # Only emit objects if they are supposed to be documented, or if
5012 # they have documented children. To implement this, we maintain a
5013 # stack of pending objects which will be emitted if a documented
5015 my @pending_objects = ();
5016 my @pending_levels = ();
5020 my $level = (length($`)) / 2 + 1;
5023 while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
5024 my $pobject = pop(@pending_objects);
5025 my $plevel = pop(@pending_levels);
5028 push (@pending_objects, $object);
5029 push (@pending_levels, $level);
5031 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5032 while ($#pending_levels >= 0) {
5033 $object = shift @pending_objects;
5034 $level = shift @pending_levels;
5035 $xref = &MakeXRef ($object);
5037 print (OUTPUT ' ' x ($level * 4), "$xref\n");
5038 push (@Objects, $object);
5039 push (@ObjectLevels, $level);
5043 # LogWarning ($OBJECT_TREE_FILE, $., "unknown type $object");
5047 print (OUTPUT "</screen>\n");
5052 &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
5057 #############################################################################
5058 # Function : ReadInterfaces
5059 # Description : This reads in the $MODULE.interfaces file.
5062 #############################################################################
5064 sub ReadInterfaces {
5067 if (! -f $INTERFACES_FILE) {
5070 if (!open (INPUT, $INTERFACES_FILE)) {
5071 warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
5077 my ($object, @ifaces) = split;
5078 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5079 my @knownIfaces = ();
5081 # filter out private interfaces, but leave foreign interfaces
5082 foreach my $iface (@ifaces) {
5083 if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
5084 push (@knownIfaces, $iface);
5088 $Interfaces{$object} = join(' ', @knownIfaces);
5094 #############################################################################
5095 # Function : ReadPrerequisites
5096 # Description : This reads in the $MODULE.prerequisites file.
5099 #############################################################################
5101 sub ReadPrerequisites {
5102 %Prerequisites = ();
5104 if (! -f $PREREQUISITES_FILE) {
5107 if (!open (INPUT, $PREREQUISITES_FILE)) {
5108 warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
5114 my ($iface, @prereqs) = split;
5115 if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
5116 my @knownPrereqs = ();
5118 # filter out private prerequisites, but leave foreign prerequisites
5119 foreach my $prereq (@prereqs) {
5120 if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
5121 push (@knownPrereqs, $prereq);
5125 $Prerequisites{$iface} = join(' ', @knownPrereqs);
5131 #############################################################################
5132 # Function : ReadArgsFile
5133 # Description : This reads in an existing file which contains information on
5134 # all GTK args. It creates the arrays @ArgObjects, @ArgNames,
5135 # @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
5137 # Arguments : $file - the file containing the arg information.
5138 #############################################################################
5153 # Reset the args info.
5166 if (!open (INPUT, $file)) {
5167 warn "Can't open $file - skipping args\n";
5184 if (m/^<NAME>(.*)<\/NAME>/) {
5186 if ($arg_name =~ m/^(.*)::(.*)$/) {
5188 ($arg_name = $2) =~ s/_/-/g;
5189 #print "Found arg: $arg_name\n";
5191 &LogWarning ($file, $., "Invalid argument name: $arg_name");
5193 } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
5195 } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
5197 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
5199 } elsif (m/^<NICK>(.*)<\/NICK>/) {
5201 } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
5203 if ($arg_blurb eq "(null)") {
5205 &LogWarning ($file, $., "Property ${arg_object}:${arg_name} has no documentation.");
5207 } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
5209 } elsif (m%^</ARG>%) {
5210 #print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
5211 push (@ArgObjects, $arg_object);
5212 push (@ArgNames, $arg_name);
5213 push (@ArgTypes, $arg_type);
5214 push (@ArgRanges, $arg_range);
5215 push (@ArgFlags, $arg_flags);
5216 push (@ArgNicks, $arg_nick);
5217 push (@ArgBlurbs, $arg_blurb);
5218 push (@ArgDefaults, $arg_default);
5227 #############################################################################
5228 # Function : CheckIsObject
5229 # Description : Returns 1 if the given name is a GObject or a subclass.
5230 # It uses the global @Objects array.
5231 # Note that the @Objects array only contains classes in the
5232 # current module and their ancestors - not all GObject classes.
5233 # Arguments : $name - the name to check.
5234 #############################################################################
5240 foreach $object (@Objects) {
5241 if ($object eq $name) {
5249 #############################################################################
5250 # Function : MakeReturnField
5251 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
5252 # Arguments : $str - the string to pad.
5253 #############################################################################
5255 sub MakeReturnField {
5258 return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));
5261 #############################################################################
5262 # Function : GetSymbolSourceFile
5263 # Description : Get the filename where the symbol docs where taken from.
5264 # Arguments : $symbol - the symbol name
5265 #############################################################################
5267 sub GetSymbolSourceFile {
5270 if (defined($SourceSymbolSourceFile{$symbol})) {
5271 return $SourceSymbolSourceFile{$symbol};
5272 } elsif (defined($SymbolSourceFile{$symbol})) {
5273 return $SymbolSourceFile{$symbol};
5279 #############################################################################
5280 # Function : GetSymbolSourceLine
5281 # Description : Get the file line where the symbol docs where taken from.
5282 # Arguments : $symbol - the symbol name
5283 #############################################################################
5285 sub GetSymbolSourceLine {
5288 if (defined($SourceSymbolSourceLine{$symbol})) {
5289 return $SourceSymbolSourceLine{$symbol};
5290 } elsif (defined($SymbolSourceLine{$symbol})) {
5291 return $SymbolSourceLine{$symbol};