4 # gtk-doc - GTK DocBook documentation generator.
5 # Copyright (C) 1998 Damon Chaplin
6 # 2007,2008,2009 Stefan Kost
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #############################################################################
24 # Script : gtkdoc-mkdb
25 # Description : This creates the DocBook files from the edited templates.
26 #############################################################################
31 push @INC, '@PACKAGE_DATA_DIR@';
32 require "gtkdoc-common.pl";
36 # name of documentation module
41 my $SOURCE_SUFFIXES = "";
42 my $IGNORE_FILES = "";
46 my $EXPAND_CONTENT_FILES = "";
47 my $INLINE_MARKUP_MODE;
48 my $DEFAULT_STABILITY;
52 my $OUTPUT_ALL_SYMBOLS;
53 my $OUTPUT_SYMBOLS_WITHOUT_SINCE;
55 my %optctl = ('module' => \$MODULE,
56 'source-dir' => \@SOURCE_DIRS,
57 'source-suffixes' => \$SOURCE_SUFFIXES,
58 'ignore-files' => \$IGNORE_FILES,
59 'output-dir' => \$SGML_OUTPUT_DIR,
60 'tmpl-dir' => \$TMPL_DIR,
61 'version' => \$PRINT_VERSION,
62 'help' => \$PRINT_HELP,
63 'main-sgml-file' => \$MAIN_SGML_FILE,
64 'expand-content-files' => \$EXPAND_CONTENT_FILES,
65 'sgml-mode' => \$INLINE_MARKUP_MODE,
66 'xml-mode' => \$INLINE_MARKUP_MODE,
67 'default-stability' => \$DEFAULT_STABILITY,
68 'default-includes' => \$DEFAULT_INCLUDES,
69 'output-format' => \$OUTPUT_FORMAT,
70 'name-space' => \$NAME_SPACE,
71 'outputallsymbols' => \$OUTPUT_ALL_SYMBOLS,
72 'outputsymbolswithoutsince' => \$OUTPUT_SYMBOLS_WITHOUT_SINCE
74 GetOptions(\%optctl, "module=s", "source-dir:s", "source-suffixes:s",
75 "ignore-files:s", "output-dir:s", "tmpl-dir:s", "version", "outputallsymbols",
76 "outputsymbolswithoutsince",
77 "expand-content-files:s", "main-sgml-file:s", "extra-db-files:s", "help",
78 "sgml-mode", "xml-mode", "default-stability:s", "default-includes:s",
79 "output-format:s", "name-space:s");
90 if ($DEFAULT_STABILITY && $DEFAULT_STABILITY ne "Stable"
91 && $DEFAULT_STABILITY ne "Private" && $DEFAULT_STABILITY ne "Unstable") {
97 gtkdoc-mkdb version @VERSION@ - generate docbook files
99 --module=MODULE_NAME Name of the doc module being parsed
100 --source-dir=DIRNAME Directories which contain inline reference material
101 --source-suffixes=SUFFIXES Suffixes of source files to scan, comma-separated
102 --ignore-files=FILES Files or directories which should not be scanned
103 May be used more than once for multiple directories
104 --output-dir=DIRNAME Directory to put the generated DocBook files in
105 --tmpl-dir=DIRNAME Directory in which template files may be found
106 --main-sgml-file=FILE File containing the toplevel DocBook file.
107 --expand-content-files=FILES Extra DocBook files to expand abbreviations in.
108 --output-format=FORMAT Format to use for the generated docbook, XML or SGML.
109 --{xml,sgml}-mode Allow DocBook markup in inline documentation.
110 --default-stability=LEVEL Specify default stability Level. Valid values are
111 Stable, Unstable, or Private.
112 --default-includes=FILENAMES Specify default includes for section Synopsis
113 --name-space=NS Omit namespace in index.
114 --version Print the version of this program
115 --help Print this help
120 my ($empty_element_end, $doctype_header);
122 # autodetect output format
123 if (! defined($OUTPUT_FORMAT) || ($OUTPUT_FORMAT eq "")) {
124 if (!$MAIN_SGML_FILE) {
125 if (-e "${MODULE}-docs.xml") {
126 $OUTPUT_FORMAT = "xml";
128 $OUTPUT_FORMAT = "sgml";
131 if ($MAIN_SGML_FILE =~ m/.*\.(.*ml)$/i) {
132 $OUTPUT_FORMAT = lc($1);
137 $OUTPUT_FORMAT = lc($OUTPUT_FORMAT);
140 #print "DEBUG: output-format: [$OUTPUT_FORMAT]\n";
142 if ($OUTPUT_FORMAT eq "xml") {
143 if (!$MAIN_SGML_FILE) {
144 # backwards compatibility
145 if (-e "${MODULE}-docs.sgml") {
146 $MAIN_SGML_FILE = "${MODULE}-docs.sgml";
148 $MAIN_SGML_FILE = "${MODULE}-docs.xml";
151 $empty_element_end = "/>";
153 if (-e $MAIN_SGML_FILE) {
154 open(INPUT, "<$MAIN_SGML_FILE") || die "Can't open $MAIN_SGML_FILE";
155 $doctype_header = "";
157 if (/^\s*<(book|chapter|article)/) {
158 # check that the top-level tag or the doctype decl contain the xinclude namespace decl
159 if (($_ !~ m/http:\/\/www.w3.org\/200[13]\/XInclude/) && ($doctype_header !~ m/http:\/\/www.w3.org\/200[13]\/XInclude/m)) {
160 $doctype_header = "";
164 $doctype_header .= $_;
167 $doctype_header =~ s/<!DOCTYPE \w+/<!DOCTYPE refentry/;
168 # if there are SYSTEM ENTITIES here, we should prepend "../" to the path
169 # FIXME: not sure if we can do this now, as people already work-around the problem
170 # $doctype_header =~ s#<!ENTITY % ([a-zA-Z-]+) SYSTEM \"([^/][a-zA-Z./]+)\">#<!ENTITY % $1 SYSTEM \"../$2\">#g;
173 "<?xml version=\"1.0\"?>\n" .
174 "<!DOCTYPE refentry PUBLIC \"-//OASIS//DTD DocBook XML V4.3//EN\"\n" .
175 " \"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd\"\n" .
177 " <!ENTITY % local.common.attrib \"xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'\">\n" .
181 if (!$MAIN_SGML_FILE) {
182 $MAIN_SGML_FILE = "${MODULE}-docs.sgml";
184 $empty_element_end = ">";
185 $doctype_header = "";
190 # All the files are written in subdirectories beneath here.
191 $TMPL_DIR = $TMPL_DIR ? $TMPL_DIR : "$ROOT_DIR/tmpl";
193 # This is where we put all the DocBook output.
194 $SGML_OUTPUT_DIR = $SGML_OUTPUT_DIR ? $SGML_OUTPUT_DIR : "$ROOT_DIR/$OUTPUT_FORMAT";
196 # This file contains the object hierarchy.
197 my $OBJECT_TREE_FILE = "$ROOT_DIR/$MODULE.hierarchy";
199 # This file contains the interfaces.
200 my $INTERFACES_FILE = "$ROOT_DIR/$MODULE.interfaces";
202 # This file contains the prerequisites.
203 my $PREREQUISITES_FILE = "$ROOT_DIR/$MODULE.prerequisites";
205 # This file contains signal arguments and names.
206 my $SIGNALS_FILE = "$ROOT_DIR/$MODULE.signals";
208 # The file containing Arg information.
209 my $ARGS_FILE = "$ROOT_DIR/$MODULE.args";
211 # These global arrays store information on signals. Each signal has an entry
212 # in each of these arrays at the same index, like a multi-dimensional array.
213 my @SignalObjects; # The GtkObject which emits the signal.
214 my @SignalNames; # The signal name.
215 my @SignalReturns; # The return type.
216 my @SignalFlags; # Flags for the signal
217 my @SignalPrototypes; # The rest of the prototype of the signal handler.
219 # These global arrays store information on Args. Each Arg has an entry
220 # in each of these arrays at the same index, like a multi-dimensional array.
221 my @ArgObjects; # The GtkObject which has the Arg.
222 my @ArgNames; # The Arg name.
223 my @ArgTypes; # The Arg type - gint, GtkArrowType etc.
224 my @ArgFlags; # How the Arg can be used - readable/writable etc.
225 my @ArgNicks; # The nickname of the Arg.
226 my @ArgBlurbs; # Docstring of the Arg.
227 my @ArgDefaults; # Default value of the Arg.
228 my @ArgRanges; # The range of the Arg type
229 # These global hashes store declaration info keyed on a symbol name.
231 my %DeclarationTypes;
232 my %DeclarationConditional;
233 my %DeclarationOutput;
237 my %StructHasTypedef;
239 # These global hashes store the existing documentation.
243 my %SymbolSourceFile;
244 my %SymbolSourceLine;
246 # These global hashes store documentation scanned from the source files.
247 my %SourceSymbolDocs;
248 my %SourceSymbolParams;
249 my %SourceSymbolSourceFile;
250 my %SourceSymbolSourceLine;
252 # all documentation goes in here, so we can do coverage analysis
254 my %AllIncompleteSymbols;
255 my %AllUnusedSymbols;
256 my %AllDocumentedSymbols;
258 # Undeclared yet documented symbols
259 my %UndeclaredSymbols;
261 # These global arrays store GObject, subclasses and the hierarchy.
268 # holds the symbols which are mentioned in $MODULE-sections.txt and in which
269 # section they are defined
274 # collects index entries
275 my %IndexEntriesFull;
276 my %IndexEntriesSince;
277 my %IndexEntriesDeprecated;
279 # Standard C preprocessor directives, which we ignore for '#' abbreviations.
280 my %PreProcessorDirectives;
281 $PreProcessorDirectives{"assert"} = 1;
282 $PreProcessorDirectives{"define"} = 1;
283 $PreProcessorDirectives{"elif"} = 1;
284 $PreProcessorDirectives{"else"} = 1;
285 $PreProcessorDirectives{"endif"} = 1;
286 $PreProcessorDirectives{"error"} = 1;
287 $PreProcessorDirectives{"if"} = 1;
288 $PreProcessorDirectives{"ifdef"} = 1;
289 $PreProcessorDirectives{"ifndef"} = 1;
290 $PreProcessorDirectives{"include"} = 1;
291 $PreProcessorDirectives{"line"} = 1;
292 $PreProcessorDirectives{"pragma"} = 1;
293 $PreProcessorDirectives{"unassert"} = 1;
294 $PreProcessorDirectives{"undef"} = 1;
295 $PreProcessorDirectives{"warning"} = 1;
297 # remember used annotation (to write minimal glossary)
300 # the annotations are defined at:
301 # http://live.gnome.org/GObjectIntrospection/Annotations
302 my %AnnotationDefinition = (
303 'allow-none' => "NULL is ok, both for passing and for returning.",
304 'array' => "Parameter points to an array of items.",
305 'default' => "Default parameter value (for in case the <acronym>shadows</acronym>-to function has less parameters).",
306 'element-type' => "Generics and defining elements of containers and arrays.",
307 'error-domains' => "Typed errors. Similar to throws in Java.",
308 'in' => "Parameter for input. Default is <acronym>transfer none</acronym>.",
309 'inout' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
310 'in-out' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
311 'not-error' => "A GError parameter is not to be handled like a normal GError.",
312 'out' => "Parameter for returning results. Default is <acronym>transfer full</acronym>.",
313 'transfer container' => "Free data container after the code is done.",
314 'transfer full' => "Free data after the code is done.",
315 'transfer none' => "Don't free data after the code is done.",
316 'scope call' => "The callback is valid only during the call to the method.",
317 'scope async' => "The callback is valid until first called.",
318 'scope notified' => "The callback is valid until the GDestroyNotify argument is called.",
319 'type' => "Override the parsed C type with given type"
322 # Create the root DocBook output directory if it doens't exist.
323 if (! -e $SGML_OUTPUT_DIR) {
324 mkdir ("$SGML_OUTPUT_DIR", 0777)
325 || die "Can't create directory: $SGML_OUTPUT_DIR";
328 # Function and other declaration output settings.
329 my $RETURN_TYPE_FIELD_WIDTH = 20;
330 my $SYMBOL_FIELD_WIDTH = 36;
331 my $SIGNAL_FIELD_WIDTH = 16;
332 my $PARAM_FIELD_COUNT = 2;
334 &ReadKnownSymbols ("$ROOT_DIR/$MODULE-sections.txt");
335 &ReadSignalsFile ($SIGNALS_FILE);
336 &ReadArgsFile ($ARGS_FILE);
337 &ReadObjectHierarchy;
341 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-decl.txt", 0);
342 if (-f "$ROOT_DIR/$MODULE-overrides.txt") {
343 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-overrides.txt", 1);
346 for my $dir (@SOURCE_DIRS) {
347 &ReadSourceDocumentation ($dir);
350 my $changed = &OutputSGML ("$ROOT_DIR/$MODULE-sections.txt");
352 # If any of the DocBook SGML files have changed, update the timestamp file (so
353 # it can be used for Makefile dependencies).
354 if ($changed || ! -e "$ROOT_DIR/sgml.stamp") {
356 # try to detect the common prefix
357 # GtkWidget, GTK_WIDGET, gtk_widget -> gtk
358 if ($NAME_SPACE eq "") {
365 foreach my $symbol (keys(%IndexEntriesFull)) {
366 if(($NAME_SPACE eq "") || $symbol =~ /^$NAME_SPACE/i) {
367 if (length($symbol)>$pos) {
368 $letter=substr($symbol,$pos,1);
369 # stop prefix scanning
370 if ($letter eq "_") {
374 # Should we also stop on a uppercase char, if last was lowercase
375 # GtkWidget, if we have the 'W' and had the 't' before
376 # or should we count upper and lowercase, and stop one 2nd uppercase, if we already had a lowercase
377 # GtkWidget, the 'W' would be the 2nd uppercase and with 't','k' we had lowercase chars before
378 # need to recound each time as this is per symbol
379 $prefix{uc($letter)}++;
383 if ($letter ne "" && $letter ne "_") {
386 foreach $letter (keys(%prefix)) {
387 #print "$letter: $prefix{$letter}.\n";
388 if ($prefix{$letter}>$maxsymbols) {
390 $maxsymbols=$prefix{$letter};
393 $ratio = scalar(keys(%IndexEntriesFull)) / $prefix{$maxletter};
394 #print "most symbols start with $maxletter, that is ". (100 * $ratio) ." %\n";
397 $NAME_SPACE .= $maxletter;
404 } while ($ratio > 0.9);
405 #print "most symbols start with $NAME_SPACE\n";
409 &OutputDeprecatedIndex;
411 &OutputAnnotationGlossary;
413 open (TIMESTAMP, ">$ROOT_DIR/sgml.stamp")
414 || die "Can't create $ROOT_DIR/sgml.stamp: $!";
415 print (TIMESTAMP "timestamp");
419 #############################################################################
420 # Function : OutputObjectList
421 # Description : This outputs the alphabetical list of objects, in a columned
423 # FIXME: Currently this also outputs ancestor objects
424 # which may not actually be in this module.
426 #############################################################################
428 sub OutputObjectList {
431 # FIXME: use $OUTPUT_FORMAT
432 # my $old_object_index = "$SGML_OUTPUT_DIR/object_index.$OUTPUT_FORMAT";
433 my $old_object_index = "$SGML_OUTPUT_DIR/object_index.sgml";
434 my $new_object_index = "$SGML_OUTPUT_DIR/object_index.new";
436 open (OUTPUT, ">$new_object_index")
437 || die "Can't create $new_object_index: $!";
439 if ($OUTPUT_FORMAT eq "xml") {
440 my $header = $doctype_header;
442 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE informaltable/;
443 print (OUTPUT "$header");
446 print (OUTPUT <<EOF);
447 <informaltable pgwide="1" frame="none">
448 <tgroup cols="$cols">
449 <colspec colwidth="1*"${empty_element_end}
450 <colspec colwidth="1*"${empty_element_end}
451 <colspec colwidth="1*"${empty_element_end}
457 foreach $object (sort (@Objects)) {
458 my $xref = &MakeXRef ($object);
459 if ($count % $cols == 0) { print (OUTPUT "<row>\n"); }
460 print (OUTPUT "<entry>$xref</entry>\n");
461 if ($count % $cols == ($cols - 1)) { print (OUTPUT "</row>\n"); }
465 # emit an empty row, since empty tables are invalid
466 print (OUTPUT "<row><entry> </entry></row>\n");
469 if ($count % $cols > 0) {
470 print (OUTPUT "</row>\n");
474 print (OUTPUT <<EOF);
475 </tbody></tgroup></informaltable>
479 &UpdateFileIfChanged ($old_object_index, $new_object_index, 0);
483 #############################################################################
484 # Function : OutputSGML
485 # Description : This collects the output for each section of the docs, and
486 # outputs each file when the end of the section is found.
487 # Arguments : $file - the $MODULE-sections.txt file which contains all of
488 # the functions/macros/structs etc. being documented, organised
489 # into sections and subsections.
490 #############################################################################
495 #print "Reading: $file\n";
497 || die "Can't open $file: $!";
500 my $book_bottom = "";
501 my $includes = (defined $DEFAULT_INCLUDES) ? $DEFAULT_INCLUDES : "";
502 my $section_includes = "";
511 my $signals_synop = "";
512 my $signals_desc = "";
514 my $child_args_synop = "";
515 my $style_args_synop = "";
517 my $child_args_desc = "";
518 my $style_args_desc = "";
521 my $implementations = "";
522 my $prerequisites = "";
524 my @file_objects = ();
526 my %symbol_def_line = ();
528 # merge the source docs, in case there are no templates
529 &MergeSourceDocumentation;
535 } elsif (m/^<SECTION>/) {
541 %symbol_def_line = ();
543 } elsif (m/^<SUBSECTION\s*(.*)>/i) {
547 } elsif (m/^<SUBSECTION>/) {
549 } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
551 #print "Section: $title\n";
553 # We don't want warnings if object & class structs aren't used.
554 $DeclarationOutput{$title} = 1;
555 $DeclarationOutput{"${title}Class"} = 1;
556 $DeclarationOutput{"${title}Iface"} = 1;
557 $DeclarationOutput{"${title}Interface"} = 1;
559 } elsif (m/^<FILE>(.*)<\/FILE>/) {
561 if (! defined $templates{$filename}) {
562 if (&ReadTemplateFile ("$TMPL_DIR/$filename", 1)) {
563 &MergeSourceDocumentation;
564 $templates{$filename}=$.;
567 &LogWarning ($file, $., "Double <FILE>$filename</FILE> entry. ".
568 "Previous occurrence on line ".$templates{$filename}.".");
570 if (($title eq "") and (defined $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"})) {
571 $title = $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"};
572 # Remove trailing blanks
576 } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
578 $section_includes = $1;
580 if (defined $DEFAULT_INCLUDES) {
581 &LogWarning ($file, $., "Default <INCLUDE> being overridden by command line option.");
588 } elsif (m/^<\/SECTION>/) {
589 #print "End of section: $title\n";
590 if ($num_symbols > 0) {
592 if ($OUTPUT_FORMAT eq "xml") {
593 $book_bottom .= " <xi:include href=\"xml/$filename.xml\"/>\n";
595 $book_top.="<!ENTITY $section_id SYSTEM \"sgml/$filename.sgml\">\n";
596 $book_bottom .= " &$section_id;\n";
599 if (defined ($SourceSymbolDocs{"$TMPL_DIR/$filename:Include"})) {
600 if ($section_includes) {
601 &LogWarning ($file, $., "Section <INCLUDE> being overridden by inline comments.");
603 $section_includes = $SourceSymbolDocs{"$TMPL_DIR/$filename:Include"};
605 if ($section_includes eq "") {
606 $section_includes = $includes;
609 $signals_synop =~ s/^\n*//g;
610 $signals_synop =~ s/\n+$/\n/g;
611 if ($signals_synop ne '') {
612 $signals_synop = <<EOF;
613 <refsect1 id="$section_id.signals" role="signal_proto">
614 <title role="signal_proto.title">Signals</title>
616 ${signals_synop}</synopsis>
619 $signals_desc =~ s/^\n*//g;
620 $signals_desc =~ s/\n+$/\n/g;
621 $signals_desc =~ s/(\s|\n)+$//ms;
622 $signals_desc = <<EOF;
623 <refsect1 id="$section_id.signal-details" role="signals">
624 <title role="signals.title">Signal Details</title>
630 $args_synop =~ s/^\n*//g;
631 $args_synop =~ s/\n+$/\n/g;
632 if ($args_synop ne '') {
634 <refsect1 id="$section_id.properties" role="properties">
635 <title role="properties.title">Properties</title>
637 ${args_synop}</synopsis>
640 $args_desc =~ s/^\n*//g;
641 $args_desc =~ s/\n+$/\n/g;
642 $args_desc =~ s/(\s|\n)+$//ms;
644 <refsect1 id="$section_id.property-details" role="property_details">
645 <title role="property_details.title">Property Details</title>
651 $child_args_synop =~ s/^\n*//g;
652 $child_args_synop =~ s/\n+$/\n/g;
653 if ($child_args_synop ne '') {
654 $args_synop .= <<EOF;
655 <refsect1 id="$section_id.child-properties" role="child_properties">
656 <title role="child_properties.title">Child Properties</title>
658 ${child_args_synop}</synopsis>
661 $child_args_desc =~ s/^\n*//g;
662 $child_args_desc =~ s/\n+$/\n/g;
663 $child_args_desc =~ s/(\s|\n)+$//ms;
665 <refsect1 id="$section_id.child-property-details" role="child_property_details">
666 <title role="child_property_details.title">Child Property Details</title>
672 $style_args_synop =~ s/^\n*//g;
673 $style_args_synop =~ s/\n+$/\n/g;
674 if ($style_args_synop ne '') {
675 $args_synop .= <<EOF;
676 <refsect1 id="$section_id.style-properties" role="style_properties">
677 <title role="style_properties.title">Style Properties</title>
679 ${style_args_synop}</synopsis>
682 $style_args_desc =~ s/^\n*//g;
683 $style_args_desc =~ s/\n+$/\n/g;
684 $style_args_desc =~ s/(\s|\n)+$//ms;
686 <refsect1 id="$section_id.style-property-details" role="style_properties_details">
687 <title role="style_properties_details.title">Style Property Details</title>
693 $hierarchy =~ s/^\n*//g;
694 $hierarchy =~ s/\n+$/\n/g;
695 $hierarchy =~ s/(\s|\n)+$//ms;
696 if ($hierarchy ne "") {
698 <refsect1 id="$section_id.object-hierarchy" role="object_hierarchy">
699 <title role="object_hierarchy.title">Object Hierarchy</title>
705 $interfaces =~ s/^\n*//g;
706 $interfaces =~ s/\n+$/\n/g;
707 $interfaces =~ s/(\s|\n)+$//ms;
708 if ($interfaces ne "") {
710 <refsect1 id="$section_id.implemented-interfaces" role="impl_interfaces">
711 <title role="impl_interfaces.title">Implemented Interfaces</title>
717 $implementations =~ s/^\n*//g;
718 $implementations =~ s/\n+$/\n/g;
719 $implementations =~ s/(\s|\n)+$//ms;
720 if ($implementations ne "") {
721 $implementations = <<EOF;
722 <refsect1 id="$section_id.implementations" role="implementations">
723 <title role="implementations.title">Known Implementations</title>
729 $prerequisites =~ s/^\n*//g;
730 $prerequisites =~ s/\n+$/\n/g;
731 $prerequisites =~ s/(\s|\n)+$//ms;
732 if ($prerequisites ne "") {
733 $prerequisites = <<EOF;
734 <refsect1 id="$section_id.prerequisites" role="prerequisites">
735 <title role="prerequisites.title">Prerequisites</title>
741 $derived =~ s/^\n*//g;
742 $derived =~ s/\n+$/\n/g;
743 $derived =~ s/(\s|\n)+$//ms;
744 if ($derived ne "") {
746 <refsect1 id="$section_id.derived-interfaces" role="derived_interfaces">
747 <title role="derived_interfaces.title">Known Derived Interfaces</title>
753 $synopsis =~ s/^\n*//g;
754 $synopsis =~ s/\n+$/\n/g;
755 my $file_changed = &OutputSGMLFile ($filename, $title, $section_id,
757 \$synopsis, \$details,
758 \$signals_synop, \$signals_desc,
759 \$args_synop, \$args_desc,
760 \$hierarchy, \$interfaces,
762 \$prerequisites, \$derived,
772 $section_includes = "";
776 $child_args_synop = "";
777 $style_args_synop = "";
779 $child_args_desc = "";
780 $style_args_desc = "";
783 $implementations = "";
787 } elsif (m/^(\S+)/) {
789 #print " Symbol: $symbol\n";
791 # check for duplicate entries
792 if (! defined $symbol_def_line{$symbol}) {
793 my $declaration = $Declarations{$symbol};
794 if (defined ($declaration)) {
795 # We don't want standard macros/functions of GObjects,
796 # or private declarations.
797 if ($subsection ne "Standard" && $subsection ne "Private") {
798 if (&CheckIsObject ($symbol)) {
799 push @file_objects, $symbol;
801 my ($synop, $desc) = &OutputDeclaration ($symbol,
803 my ($sig_synop, $sig_desc) = &GetSignals ($symbol);
804 my ($arg_synop, $child_arg_synop, $style_arg_synop,
805 $arg_desc, $child_arg_desc, $style_arg_desc) = &GetArgs ($symbol);
806 my $hier = &GetHierarchy ($symbol);
807 my $ifaces = &GetInterfaces ($symbol);
808 my $impls = &GetImplementations ($symbol);
809 my $prereqs = &GetPrerequisites ($symbol);
810 my $der = &GetDerived ($symbol);
813 $signals_synop .= $sig_synop;
814 $signals_desc .= $sig_desc;
815 $args_synop .= $arg_synop;
816 $child_args_synop .= $child_arg_synop;
817 $style_args_synop .= $style_arg_synop;
818 $args_desc .= $arg_desc;
819 $child_args_desc .= $child_arg_desc;
820 $style_args_desc .= $style_arg_desc;
822 $interfaces .= $ifaces;
823 $implementations .= $impls;
824 $prerequisites .= $prereqs;
828 # Note that the declaration has been output.
829 $DeclarationOutput{$symbol} = 1;
830 } elsif ($subsection ne "Standard" && $subsection ne "Private") {
831 $UndeclaredSymbols{$symbol} = 1;
832 &LogWarning ($file, $., "No declaration found for $symbol.");
835 $symbol_def_line{$symbol}=$.;
837 if ($section_id eq "") {
838 if($title eq "" && $filename eq "") {
839 &LogWarning ($file, $., "Section has no title and no file.");
841 # FIXME: one of those would be enough
842 # filename should be an internal detail for gtk-doc
845 } elsif ($filename eq "") {
848 $filename =~ s/\s/_/g;
850 $section_id = $SourceSymbolDocs{"$TMPL_DIR/$filename:Section_Id"};
851 if (defined ($section_id) && $section_id !~ m/^\s*$/) {
852 # Remove trailing blanks and use as is
853 $section_id =~ s/\s+$//;
854 } elsif (&CheckIsObject ($title)) {
855 # GObjects use their class name as the ID.
856 $section_id = &CreateValidSGMLID ($title);
858 $section_id = &CreateValidSGMLID ("$MODULE-$title");
861 $SymbolSection{$symbol}=$title;
862 $SymbolSectionId{$symbol}=$section_id;
865 &LogWarning ($file, $., "Double symbol entry for $symbol. ".
866 "Previous occurrence on line ".$symbol_def_line{$symbol}.".");
872 &OutputMissingDocumentation;
873 &OutputUndeclaredSymbols;
874 &OutputUnusedSymbols;
876 if ($OUTPUT_ALL_SYMBOLS) {
879 if ($OUTPUT_SYMBOLS_WITHOUT_SINCE) {
880 &OutputSymbolsWithoutSince;
883 for $filename (split (' ', $EXPAND_CONTENT_FILES)) {
884 my $file_changed = &OutputExtraFile ($filename);
890 &OutputBook ($book_top, $book_bottom);
895 #############################################################################
896 # Function : OutputIndex
897 # Description : This writes an indexlist that can be included into the main-
898 # document into an <index> tag.
899 #############################################################################
902 my ($basename, $apiindexref ) = @_;
903 my %apiindex = %{$apiindexref};
904 my $old_index = "$SGML_OUTPUT_DIR/$basename.xml";
905 my $new_index = "$SGML_OUTPUT_DIR/$basename.new";
906 my $lastletter = " ";
911 open (OUTPUT, ">$new_index")
912 || die "Can't create $new_index";
914 my $header = $doctype_header;
915 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE indexdiv/;
917 print (OUTPUT "$header<indexdiv>\n");
919 #print "generate $basename index (".%apiindex." entries)\n";
921 # do a case insensitive sort while chopping off the prefix
923 sort { $$a{criteria} cmp $$b{criteria} }
924 map { my $x = uc($_); $x =~ s/^$NAME_SPACE\_?(.*)/$1/i; { criteria => $x, original => $_, short => $1 } }
927 $symbol = $$hash{original};
928 if (defined($$hash{short})) {
929 $short_symbol = $$hash{short};
931 $short_symbol = $symbol;
934 # generate a short symbol description
935 my $symbol_desc = "";
936 my $symbol_section = "";
937 my $symbol_section_id = "";
938 my $symbol_type = "";
939 if (defined($DeclarationTypes{$symbol})) {
940 $symbol_type = lc($DeclarationTypes{$symbol});
942 if ($symbol_type eq "") {
943 #print "trying symbol $symbol\n";
944 if ($symbol =~ m/(.*)::(.*)/) {
948 #print " trying object signal ${oname}:$osym in ".$#SignalNames." signals\n";
949 for ($i = 0; $i <= $#SignalNames; $i++) {
950 if ($SignalNames[$i] eq $osym) {
951 $symbol_type = "object signal";
952 if (defined($SymbolSection{$oname})) {
953 $symbol_section = $SymbolSection{$oname};
954 $symbol_section_id = $SymbolSectionId{$oname};
959 } elsif ($symbol =~ m/(.*):(.*)/) {
963 #print " trying object property ${oname}::$osym in ".$#ArgNames." properties\n";
964 for ($i = 0; $i <= $#ArgNames; $i++) {
965 #print " ".$ArgNames[$i]."\n";
966 if ($ArgNames[$i] eq $osym) {
967 $symbol_type = "object property";
968 if (defined($SymbolSection{$oname})) {
969 $symbol_section = $SymbolSection{$oname};
970 $symbol_section_id = $SymbolSectionId{$oname};
977 if (defined($SymbolSection{$symbol})) {
978 $symbol_section = $SymbolSection{$symbol};
979 $symbol_section_id = $SymbolSectionId{$symbol};
982 if ($symbol_type ne "") {
983 $symbol_desc=", $symbol_type";
984 if ($symbol_section ne "") {
985 $symbol_desc.=" in <link linkend=\"$symbol_section_id\">$symbol_section</link>";
986 #$symbol_desc.=" in ". &ExpandAbbreviations($symbol, "#$symbol_section");
990 my $curletter = uc(substr($short_symbol,0,1));
991 my $id = $apiindex{$symbol};
993 #print " add symbol $symbol with $id to index in section $curletter\n";
995 if ($curletter ne $lastletter) {
996 $lastletter = $curletter;
999 print (OUTPUT "</indexdiv>\n");
1001 print (OUTPUT "<indexdiv><title>$curletter</title>\n");
1005 print (OUTPUT <<EOF);
1006 <indexentry><primaryie linkends="$id"><link linkend="$id">$symbol</link>$symbol_desc</primaryie></indexentry>
1010 if ($divopen == 1) {
1011 print (OUTPUT "</indexdiv>\n");
1013 print (OUTPUT "</indexdiv>\n");
1016 &UpdateFileIfChanged ($old_index, $new_index, 0);
1020 #############################################################################
1021 # Function : OutputIndexFull
1022 # Description : This writes the full api indexlist that can be included into the
1023 # main document into an <index> tag.
1024 #############################################################################
1026 sub OutputIndexFull {
1027 &OutputIndex ("api-index-full", \%IndexEntriesFull);
1031 #############################################################################
1032 # Function : OutputDeprecatedIndex
1033 # Description : This writes the deprecated api indexlist that can be included
1034 # into the main document into an <index> tag.
1035 #############################################################################
1037 sub OutputDeprecatedIndex {
1038 &OutputIndex ("api-index-deprecated", \%IndexEntriesDeprecated);
1042 #############################################################################
1043 # Function : OutputSinceIndexes
1044 # Description : This writes the 'since' api indexlists that can be included into
1045 # the main document into an <index> tag.
1046 #############################################################################
1048 sub OutputSinceIndexes {
1049 my @sinces = keys %{{ map { $_ => 1 } values %Since }};
1051 foreach my $version (@sinces) {
1052 #print "Since : [$version]\n";
1053 # TODO make filtered hash
1054 #my %index = grep { $Since{$_} eq $version } %IndexEntriesSince;
1055 my %index = map { $_ => $IndexEntriesSince{$_} } grep { $Since{$_} eq $version } keys %IndexEntriesSince;
1057 &OutputIndex ("api-index-$version", \%index);
1061 #############################################################################
1062 # Function : OutputAnnotationGlossary
1063 # Description : This writes a glossary of the used annotation terms into a
1064 # separate glossary file that can be included into the main
1066 #############################################################################
1068 sub OutputAnnotationGlossary {
1069 my $old_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.xml";
1070 my $new_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.new";
1071 my $lastletter = " ";
1074 # if there are no annotations used return
1075 return if (! keys(%AnnotationsUsed));
1077 # add acronyms that are referenced from acronym text
1079 foreach my $annotation (keys(%AnnotationsUsed)) {
1080 if(defined($AnnotationDefinition{$annotation})) {
1081 if($AnnotationDefinition{$annotation} =~ m/<acronym>([\w ]+)<\/acronym>/) {
1082 if (!exists($AnnotationsUsed{$1})) {
1083 $AnnotationsUsed{$1} = 1;
1090 open (OUTPUT, ">$new_glossary")
1091 || die "Can't create $new_glossary";
1093 my $header = $doctype_header;
1094 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE glossary/;
1096 print (OUTPUT <<EOF);
1098 <glossary id="annotation-glossary">
1099 <title>Annotation Glossary</title>
1102 foreach my $annotation (keys(%AnnotationsUsed)) {
1103 if(defined($AnnotationDefinition{$annotation})) {
1104 my $def = $AnnotationDefinition{$annotation};
1105 my $curletter = uc(substr($annotation,0,1));
1107 if ($curletter ne $lastletter) {
1108 $lastletter = $curletter;
1110 if ($divopen == 1) {
1111 print (OUTPUT "</glossdiv>\n");
1113 print (OUTPUT "<glossdiv><title>$curletter</title>\n");
1116 print (OUTPUT <<EOF);
1118 <glossterm><anchor id="annotation-glossterm-$annotation"/>$annotation</glossterm>
1127 if ($divopen == 1) {
1128 print (OUTPUT "</glossdiv>\n");
1130 print (OUTPUT "</glossary>\n");
1133 &UpdateFileIfChanged ($old_glossary, $new_glossary, 0);
1136 #############################################################################
1137 # Function : ReadKnownSymbols
1138 # Description : This collects the names of non-private symbols from the
1139 # $MODULE-sections.txt file.
1140 # Arguments : $file - the $MODULE-sections.txt file which contains all of
1141 # the functions/macros/structs etc. being documented, organised
1142 # into sections and subsections.
1143 #############################################################################
1145 sub ReadKnownSymbols {
1148 my $subsection = "";
1150 #print "Reading: $file\n";
1152 || die "Can't open $file: $!";
1158 } elsif (m/^<SECTION>/) {
1161 } elsif (m/^<SUBSECTION\s*(.*)>/i) {
1164 } elsif (m/^<SUBSECTION>/) {
1167 } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
1170 } elsif (m/^<FILE>(.*)<\/FILE>/) {
1171 $KnownSymbols{"$TMPL_DIR/$1:Long_Description"} = 1;
1172 $KnownSymbols{"$TMPL_DIR/$1:Short_Description"} = 1;
1175 } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
1178 } elsif (m/^<\/SECTION>/) {
1181 } elsif (m/^(\S+)/) {
1184 if ($subsection ne "Standard" && $subsection ne "Private") {
1185 $KnownSymbols{$symbol} = 1;
1188 $KnownSymbols{$symbol} = 0;
1196 #############################################################################
1197 # Function : OutputDeclaration
1198 # Description : Returns the synopsis and detailed description DocBook
1199 # describing one function/macro etc.
1200 # Arguments : $symbol - the name of the function/macro begin described.
1201 # $declaration - the declaration of the function/macro.
1202 #############################################################################
1204 sub OutputDeclaration {
1205 my ($symbol, $declaration) = @_;
1207 my $type = $DeclarationTypes {$symbol};
1208 if ($type eq 'MACRO') {
1209 return &OutputMacro ($symbol, $declaration);
1210 } elsif ($type eq 'TYPEDEF') {
1211 return &OutputTypedef ($symbol, $declaration);
1212 } elsif ($type eq 'STRUCT') {
1213 return &OutputStruct ($symbol, $declaration);
1214 } elsif ($type eq 'ENUM') {
1215 return &OutputEnum ($symbol, $declaration);
1216 } elsif ($type eq 'UNION') {
1217 return &OutputUnion ($symbol, $declaration);
1218 } elsif ($type eq 'VARIABLE') {
1219 return &OutputVariable ($symbol, $declaration);
1220 } elsif ($type eq 'FUNCTION') {
1221 return &OutputFunction ($symbol, $declaration, $type);
1222 } elsif ($type eq 'USER_FUNCTION') {
1223 return &OutputFunction ($symbol, $declaration, $type);
1225 die "Unknown symbol type";
1230 #############################################################################
1231 # Function : OutputSymbolTraits
1232 # Description : Returns the Since and StabilityLevel paragraphs for a symbol.
1233 # Arguments : $symbol - the name of the function/macro begin described.
1234 #############################################################################
1236 sub OutputSymbolTraits {
1240 if (exists $Since{$symbol}) {
1241 $desc .= "<para role=\"since\">Since $Since{$symbol}</para>";
1243 if (exists $StabilityLevel{$symbol}) {
1244 $desc .= "<para role=\"stability\">Stability Level: $StabilityLevel{$symbol}</para>";
1249 #############################################################################
1250 # Function : Outpu{Symbol,Section}ExtraLinks
1251 # Description : Returns extralinks for the symbol (if enabled).
1252 # Arguments : $symbol - the name of the function/macro begin described.
1253 #############################################################################
1257 return undef unless defined $text;
1259 # Build a char to hex map
1262 $escapes{chr($_)} = sprintf("%%%02X", $_);
1265 # Default unsafe characters. RFC 2732 ^(uric - reserved)
1266 $text =~ s/([^A-Za-z0-9\-_.!~*'()])/$escapes{$1}/g;
1271 sub OutputSymbolExtraLinks {
1275 if (0) { # NEW FEATURE: needs configurability
1276 my $sstr = &uri_escape($symbol);
1277 my $mstr = &uri_escape($MODULE);
1279 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1280 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&symbol=$sstr">edit documentation</ulink>
1286 sub OutputSectionExtraLinks {
1287 my ($symbol,$docsymbol) = @_;
1290 if (0) { # NEW FEATURE: needs configurability
1291 my $sstr = &uri_escape($symbol);
1292 my $mstr = &uri_escape($MODULE);
1293 my $dsstr = &uri_escape($docsymbol);
1295 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1296 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&symbol=$dsstr">edit documentation</ulink>
1303 #############################################################################
1304 # Function : OutputMacro
1305 # Description : Returns the synopsis and detailed description of a macro.
1306 # Arguments : $symbol - the macro.
1307 # $declaration - the declaration of the macro.
1308 #############################################################################
1311 my ($symbol, $declaration) = @_;
1312 my $id = &CreateValidSGMLID ($symbol);
1313 my $condition = &MakeConditionDescription ($symbol);
1314 my $synop = &MakeReturnField("#define") . "<link linkend=\"$id\">$symbol</link>";
1317 my @fields = ParseMacroDeclaration($declaration, \&CreateValidSGML);
1318 my $title = $symbol . (@fields ? "()" : "");
1320 $desc = "<refsect2 id=\"$id\" role=\"macro\"$condition>\n<title>$title</title>\n";
1321 $desc .= MakeIndexterms($symbol, $id);
1323 $desc .= OutputSymbolExtraLinks($symbol);
1326 if (length ($symbol) < $SYMBOL_FIELD_WIDTH) {
1327 $synop .= (' ' x ($SYMBOL_FIELD_WIDTH - length ($symbol)));
1331 for (my $i = 1; $i <= $#fields; $i += 2) {
1332 my $field_name = $fields[$i];
1335 $synop .= "$field_name";
1338 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1346 # Don't output the macro definition if is is a conditional macro or it
1347 # looks like a function, i.e. starts with "g_" or "_?gnome_", or it is
1348 # longer than 2 lines, otherwise we get lots of complicated macros like
1350 if (!defined ($DeclarationConditional{$symbol}) && ($symbol !~ m/^g_/)
1351 && ($symbol !~ m/^_?gnome_/) && (($declaration =~ tr/\n//) < 2)) {
1352 my $decl_out = &CreateValidSGML ($declaration);
1353 $desc .= "<programlisting>$decl_out</programlisting>\n";
1355 $desc .= "<programlisting>" . &MakeReturnField("#define") . "$symbol";
1356 if ($declaration =~ m/^\s*#\s*define\s+\w+(\([^\)]*\))/) {
1358 my $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH - length ("#define "));
1359 # Align each line so that if should all line up OK.
1360 $args =~ s/\n/\n$pad/gm;
1361 $desc .= &CreateValidSGML ($args);
1363 $desc .= "</programlisting>\n";
1366 $desc .= &MakeDeprecationNote($symbol);
1368 my $parameters = &OutputParamDescriptions ("MACRO", $symbol, @fields);
1369 my $parameters_output = 0;
1371 if (defined ($SymbolDocs{$symbol})) {
1372 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1374 # Try to insert the parameter table at the author's desired position.
1375 # Otherwise we need to tag it onto the end.
1376 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1377 $parameters_output = 1;
1379 $desc .= $symbol_docs;
1382 if ($parameters_output == 0) {
1383 $desc .= $parameters;
1386 $desc .= OutputSymbolTraits ($symbol);
1387 $desc .= "</refsect2>\n";
1388 return ($synop, $desc);
1392 #############################################################################
1393 # Function : OutputTypedef
1394 # Description : Returns the synopsis and detailed description of a typedef.
1395 # Arguments : $symbol - the typedef.
1396 # $declaration - the declaration of the typedef,
1397 # e.g. 'typedef unsigned int guint;'
1398 #############################################################################
1401 my ($symbol, $declaration) = @_;
1402 my $id = &CreateValidSGMLID ($symbol);
1403 my $condition = &MakeConditionDescription ($symbol);
1404 my $synop = &MakeReturnField("typedef") . "<link linkend=\"$id\">$symbol</link>;\n";
1405 my $desc = "<refsect2 id=\"$id\" role=\"typedef\"$condition>\n<title>$symbol</title>\n";
1407 $desc .= MakeIndexterms($symbol, $id);
1409 $desc .= OutputSymbolExtraLinks($symbol);
1411 if (!defined ($DeclarationConditional{$symbol})) {
1412 my $decl_out = &CreateValidSGML ($declaration);
1413 $desc .= "<programlisting>$decl_out</programlisting>\n";
1416 $desc .= &MakeDeprecationNote($symbol);
1418 if (defined ($SymbolDocs{$symbol})) {
1419 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1421 $desc .= OutputSymbolTraits ($symbol);
1422 $desc .= "</refsect2>\n";
1423 return ($synop, $desc);
1427 #############################################################################
1428 # Function : OutputStruct
1429 # Description : Returns the synopsis and detailed description of a struct.
1430 # We check if it is a object struct, and if so we only output
1431 # parts of it that are noted as public fields.
1432 # We also use a different SGML ID for object structs, since the
1433 # original ID is used for the entire RefEntry.
1434 # Arguments : $symbol - the struct.
1435 # $declaration - the declaration of the struct.
1436 #############################################################################
1439 my ($symbol, $declaration) = @_;
1441 my $is_object_struct = 0;
1442 my $default_to_public = 1;
1443 if (&CheckIsObject ($symbol)) {
1444 #print "Found object struct: $symbol\n";
1445 $is_object_struct = 1;
1446 $default_to_public = 0;
1451 if ($is_object_struct) {
1452 $id = &CreateValidSGMLID ($symbol . "_struct");
1453 $condition = &MakeConditionDescription ($symbol . "_struct");
1455 $id = &CreateValidSGMLID ($symbol);
1456 $condition = &MakeConditionDescription ($symbol);
1459 # Determine if it is a simple struct or it also has a typedef.
1460 my $has_typedef = 0;
1461 if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1468 # For structs with typedefs we just output the struct name.
1469 $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1470 $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>$symbol</title>\n";
1472 $synop = &MakeReturnField("struct") . "<link linkend=\"$id\">$symbol</link>;\n";
1473 $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>struct $symbol</title>\n";
1476 $desc .= MakeIndexterms($symbol, $id);
1478 $desc .= OutputSymbolExtraLinks($symbol);
1480 # Form a pretty-printed, private-data-removed form of the declaration
1483 if ($declaration =~ m/^\s*$/) {
1484 #print "Found opaque struct: $symbol\n";
1485 $decl_out = "typedef struct _$symbol $symbol;";
1486 } elsif ($declaration =~ m/^\s*struct\s+\w+\s*;\s*$/) {
1487 #print "Found opaque struct: $symbol\n";
1488 $decl_out = "struct $symbol;";
1490 my $public = $default_to_public;
1491 my $new_declaration = "";
1493 my $decl = $declaration;
1495 if ($decl =~ m/^\s*(typedef\s+)?struct\s*\w*\s*(?:\/\*.*\*\/)?\s*{(.*)}\s*\w*\s*;\s*$/s) {
1496 my $struct_contents = $2;
1498 foreach $decl_line (split (/\n/, $struct_contents)) {
1499 #print "Struct line: $decl_line\n";
1500 if ($decl_line =~ m%/\*\s*<\s*public\s*>\s*\*/%) {
1502 } elsif ($decl_line =~ m%/\*\s*<\s*(private|protected)\s*>\s*\*/%) {
1505 $new_declaration .= $decl_line . "\n";
1509 if ($new_declaration) {
1510 # Strip any blank lines off the ends.
1511 $new_declaration =~ s/^\s*\n//;
1512 $new_declaration =~ s/\n\s*$/\n/;
1515 $decl_out = "typedef struct {\n" . $new_declaration
1518 $decl_out = "struct $symbol {\n" . $new_declaration
1523 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1524 "Couldn't parse struct:\n$declaration");
1527 # If we couldn't parse the struct or it was all private, output an
1528 # empty struct declaration.
1529 if ($decl_out eq "") {
1531 $decl_out = "typedef struct _$symbol $symbol;";
1533 $decl_out = "struct $symbol;";
1538 $decl_out = &CreateValidSGML ($decl_out);
1539 $desc .= "<programlisting>$decl_out</programlisting>\n";
1541 $desc .= &MakeDeprecationNote($symbol);
1543 if (defined ($SymbolDocs{$symbol})) {
1544 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1547 # Create a table of fields and descriptions
1549 # FIXME: Inserting  's into the produced type declarations here would
1550 # improve the output in most situations ... except for function
1551 # members of structs!
1552 my @fields = ParseStructDeclaration($declaration, !$default_to_public,
1555 "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1557 my $params = $SymbolParams{$symbol};
1559 # If no parameters are filled in, we don't generate the description
1560 # table, for backwards compatibility
1563 if (defined $params) {
1564 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1565 if ($params->[$i] =~ /\S/) {
1573 my %field_descrs = @$params;
1574 my $missing_parameters = "";
1575 my $unused_parameters = "";
1577 $desc .= "<variablelist role=\"struct\">\n";
1579 my $field_name = shift @fields;
1580 my $text = shift @fields;
1581 my $field_descr = $field_descrs{$field_name};
1582 my $param_annotations = "";
1584 $desc .= "<varlistentry><term>$text</term>\n";
1585 if (defined $field_descr) {
1586 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1587 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1588 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1589 delete $field_descrs{$field_name};
1591 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1592 "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1593 if ($missing_parameters ne "") {
1594 $missing_parameters .= ", ".$field_name;
1596 $missing_parameters = $field_name;
1598 $desc .= "<listitem />\n";
1600 $desc .= "</varlistentry>\n";
1602 $desc .= "</variablelist>";
1603 foreach my $field_name (keys %field_descrs) {
1604 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1605 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1606 if ($unused_parameters ne "") {
1607 $unused_parameters .= ", ".$field_name;
1609 $unused_parameters = $field_name;
1613 # remember missing/unused parameters (needed in tmpl-free build)
1614 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1615 $AllIncompleteSymbols{$symbol}=$missing_parameters;
1617 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1618 $AllUnusedSymbols{$symbol}=$unused_parameters;
1622 if (scalar(@fields) > 0) {
1623 if (! exists ($AllIncompleteSymbols{$symbol})) {
1624 $AllIncompleteSymbols{$symbol}="<items>";
1625 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1626 "Field descriptions for $symbol are missing in source code comment block.");
1631 $desc .= OutputSymbolTraits ($symbol);
1632 $desc .= "</refsect2>\n";
1633 return ($synop, $desc);
1637 #############################################################################
1638 # Function : OutputUnion
1639 # Description : Returns the synopsis and detailed description of a union.
1640 # Arguments : $symbol - the union.
1641 # $declaration - the declaration of the union.
1642 #############################################################################
1645 my ($symbol, $declaration) = @_;
1646 my $id = &CreateValidSGMLID ($symbol);
1647 my $condition = &MakeConditionDescription ($symbol);
1649 # Determine if it is a simple struct or it also has a typedef.
1650 my $has_typedef = 0;
1651 if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1658 # For unions with typedefs we just output the union name.
1659 $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1660 $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>$symbol</title>\n";
1662 $synop = &MakeReturnField("union") . "<link linkend=\"$id\">$symbol</link>;\n";
1663 $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>union $symbol</title>\n";
1666 $desc .= MakeIndexterms($symbol, $id);
1668 $desc .= OutputSymbolExtraLinks($symbol);
1670 # FIXME: we do more for structs
1671 my $decl_out = &CreateValidSGML ($declaration);
1672 $desc .= "<programlisting>$decl_out</programlisting>\n";
1674 $desc .= &MakeDeprecationNote($symbol);
1676 if (defined ($SymbolDocs{$symbol})) {
1677 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1680 # Create a table of fields and descriptions
1682 # FIXME: Inserting  's into the produced type declarations here would
1683 # improve the output in most situations ... except for function
1684 # members of structs!
1685 my @fields = ParseStructDeclaration($declaration, 0,
1688 "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1690 my $params = $SymbolParams{$symbol};
1692 # If no parameters are filled in, we don't generate the description
1693 # table, for backwards compatibility
1696 if (defined $params) {
1697 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1698 if ($params->[$i] =~ /\S/) {
1706 my %field_descrs = @$params;
1707 my $missing_parameters = "";
1708 my $unused_parameters = "";
1710 $desc .= "<variablelist role=\"union\">\n";
1712 my $field_name = shift @fields;
1713 my $text = shift @fields;
1714 my $field_descr = $field_descrs{$field_name};
1715 my $param_annotations = "";
1717 $desc .= "<varlistentry><term>$text</term>\n";
1718 if (defined $field_descr) {
1719 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1720 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1721 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1722 delete $field_descrs{$field_name};
1724 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1725 "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1726 if ($missing_parameters ne "") {
1727 $missing_parameters .= ", ".$field_name;
1729 $missing_parameters = $field_name;
1731 $desc .= "<listitem />\n";
1733 $desc .= "</varlistentry>\n";
1735 $desc .= "</variablelist>";
1736 foreach my $field_name (keys %field_descrs) {
1737 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1738 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1739 if ($unused_parameters ne "") {
1740 $unused_parameters .= ", ".$field_name;
1742 $unused_parameters = $field_name;
1746 # remember missing/unused parameters (needed in tmpl-free build)
1747 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1748 $AllIncompleteSymbols{$symbol}=$missing_parameters;
1750 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1751 $AllUnusedSymbols{$symbol}=$unused_parameters;
1755 if (scalar(@fields) > 0) {
1756 if (! exists ($AllIncompleteSymbols{$symbol})) {
1757 $AllIncompleteSymbols{$symbol}="<items>";
1758 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1759 "Field descriptions for $symbol are missing in source code comment block.");
1764 $desc .= OutputSymbolTraits ($symbol);
1765 $desc .= "</refsect2>\n";
1766 return ($synop, $desc);
1770 #############################################################################
1771 # Function : OutputEnum
1772 # Description : Returns the synopsis and detailed description of a enum.
1773 # Arguments : $symbol - the enum.
1774 # $declaration - the declaration of the enum.
1775 #############################################################################
1778 my ($symbol, $declaration) = @_;
1779 my $id = &CreateValidSGMLID ($symbol);
1780 my $condition = &MakeConditionDescription ($symbol);
1781 my $synop = &MakeReturnField("enum") . "<link linkend=\"$id\">$symbol</link>;\n";
1782 my $desc = "<refsect2 id=\"$id\" role=\"enum\"$condition>\n<title>enum $symbol</title>\n";
1784 $desc .= MakeIndexterms($symbol, $id);
1786 $desc .= OutputSymbolExtraLinks($symbol);
1788 my $decl_out = &CreateValidSGML ($declaration);
1789 $desc .= "<programlisting>$decl_out</programlisting>\n";
1791 $desc .= &MakeDeprecationNote($symbol);
1793 if (defined ($SymbolDocs{$symbol})) {
1794 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1797 # Create a table of fields and descriptions
1799 my @fields = ParseEnumDeclaration($declaration);
1800 my $params = $SymbolParams{$symbol};
1802 # If no parameters are filled in, we don't generate the description
1803 # table, for backwards compatibility
1806 if (defined $params) {
1807 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1808 if ($params->[$i] =~ /\S/) {
1816 my %field_descrs = @$params;
1817 my $missing_parameters = "";
1818 my $unused_parameters = "";
1820 $desc .= "<variablelist role=\"enum\">\n";
1821 for my $field_name (@fields) {
1822 my $field_descr = $field_descrs{$field_name};
1823 my $param_annotations = "";
1825 $id = &CreateValidSGMLID ($field_name);
1826 $condition = &MakeConditionDescription ($field_name);
1827 $desc .= "<varlistentry id=\"$id\" role=\"constant\"$condition>\n<term><literal>$field_name</literal></term>\n";
1828 if (defined $field_descr) {
1829 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1830 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1831 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1832 delete $field_descrs{$field_name};
1834 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1835 "Value description for $symbol"."::"."$field_name is missing in source code comment block.");
1836 if ($missing_parameters ne "") {
1837 $missing_parameters .= ", ".$field_name;
1839 $missing_parameters = $field_name;
1841 $desc .= "<listitem />\n";
1843 $desc .= "</varlistentry>\n";
1845 $desc .= "</variablelist>";
1846 foreach my $field_name (keys %field_descrs) {
1847 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1848 "Value description for $symbol"."::"."$field_name is not used from source code comment block.");
1849 if ($unused_parameters ne "") {
1850 $unused_parameters .= ", ".$field_name;
1852 $unused_parameters = $field_name;
1856 # remember missing/unused parameters (needed in tmpl-free build)
1857 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1858 $AllIncompleteSymbols{$symbol}=$missing_parameters;
1860 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1861 $AllUnusedSymbols{$symbol}=$unused_parameters;
1865 if (scalar(@fields) > 0) {
1866 if (! exists ($AllIncompleteSymbols{$symbol})) {
1867 $AllIncompleteSymbols{$symbol}="<items>";
1868 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1869 "Value descriptions for $symbol are missing in source code comment block.");
1874 $desc .= OutputSymbolTraits ($symbol);
1875 $desc .= "</refsect2>\n";
1876 return ($synop, $desc);
1880 #############################################################################
1881 # Function : OutputVariable
1882 # Description : Returns the synopsis and detailed description of a variable.
1883 # Arguments : $symbol - the extern'ed variable.
1884 # $declaration - the declaration of the variable.
1885 #############################################################################
1887 sub OutputVariable {
1888 my ($symbol, $declaration) = @_;
1889 my $id = &CreateValidSGMLID ($symbol);
1890 my $condition = &MakeConditionDescription ($symbol);
1893 if ($declaration =~ m/^\s*extern\s+((const\s+|signed\s+|unsigned\s+)*\w+)(\s+\*+|\*+|\s)(\s*)([A-Za-z]\w*)\s*;/) {
1894 my $mod = defined ($1) ? $1 : "";
1895 my $ptr = defined ($3) ? $3 : "";
1896 my $space = defined ($4) ? $4 : "";
1897 $synop = &MakeReturnField("extern") . "$mod$ptr$space<link linkend=\"$id\">$symbol</link>;\n";
1900 $synop = &MakeReturnField("extern") . "<link linkend=\"$id\">$symbol</link>;\n";
1903 my $desc = "<refsect2 id=\"$id\" role=\"variable\"$condition>\n<title>$symbol</title>\n";
1905 $desc .= MakeIndexterms($symbol, $id);
1907 $desc .= OutputSymbolExtraLinks($symbol);
1909 my $decl_out = &CreateValidSGML ($declaration);
1910 $desc .= "<programlisting>$decl_out</programlisting>\n";
1912 $desc .= &MakeDeprecationNote($symbol);
1914 if (defined ($SymbolDocs{$symbol})) {
1915 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1917 $desc .= OutputSymbolTraits ($symbol);
1918 $desc .= "</refsect2>\n";
1919 return ($synop, $desc);
1923 #############################################################################
1924 # Function : OutputFunction
1925 # Description : Returns the synopsis and detailed description of a function.
1926 # Arguments : $symbol - the function.
1927 # $declaration - the declaration of the function.
1928 #############################################################################
1930 sub OutputFunction {
1931 my ($symbol, $declaration, $symbol_type) = @_;
1932 my $id = &CreateValidSGMLID ($symbol);
1933 my $condition = &MakeConditionDescription ($symbol);
1935 # Take out the return type $1 $3 $4
1936 $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//;
1937 my $type_modifier = defined($1) ? $1 : "";
1940 #print "$symbol pointer is $pointer\n";
1941 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1943 #if ($symbol_type eq 'USER_FUNCTION') {
1944 # $start = "typedef ";
1947 # We output const rather than G_CONST_RETURN.
1948 $type_modifier =~ s/G_CONST_RETURN/const/g;
1949 $pointer =~ s/G_CONST_RETURN/const/g;
1950 $pointer =~ s/^\s+/ /g;
1952 my $ret_type_len = length ($start) + length ($type_modifier)
1953 + length ($pointer) + length ($type);
1954 my $ret_type_output;
1956 if ($ret_type_len < $RETURN_TYPE_FIELD_WIDTH) {
1957 $ret_type_output = "$start$type_modifier$xref$pointer"
1958 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
1961 #$ret_type_output = "$start$type_modifier$xref$pointer\n" . (' ' x $RETURN_TYPE_FIELD_WIDTH);
1963 $ret_type_output = "$start$type_modifier$xref$pointer ";
1964 $symbol_len = $ret_type_len + 1 - $RETURN_TYPE_FIELD_WIDTH;
1967 $symbol_len += length ($symbol);
1968 my $char1 = my $char2 = my $char3 = "";
1969 if ($symbol_type eq 'USER_FUNCTION') {
1976 my ($symbol_output, $symbol_desc_output);
1977 if ($symbol_len < $SYMBOL_FIELD_WIDTH) {
1978 $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3"
1979 . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1980 $symbol_desc_output = "$char1$char2$symbol$char3"
1981 . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1983 $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3\n"
1984 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1985 $symbol_desc_output = "$char1$char2$symbol$char3\n"
1986 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1989 my $synop = $ret_type_output . $symbol_output . '(';
1990 my $desc = "<refsect2 id=\"$id\" role=\"function\"$condition>\n<title>${symbol} ()</title>\n";
1992 $desc .= MakeIndexterms($symbol, $id);
1994 $desc .= OutputSymbolExtraLinks($symbol);
1996 $desc .= "<programlisting>${ret_type_output}$symbol_desc_output(";
1998 my @fields = ParseFunctionDeclaration($declaration, \&MakeXRef,
2000 &tagify($_[0],"parameter");
2003 for (my $i = 1; $i <= $#fields; $i += 2) {
2004 my $field_name = $fields[$i];
2006 if ($field_name eq "Varargs") {
2007 $field_name = "...";
2011 $synop .= "$field_name";
2012 $desc .= "$field_name";
2015 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2018 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2025 $desc .= ");</programlisting>\n";
2027 $desc .= &MakeDeprecationNote($symbol);
2029 my $parameters = &OutputParamDescriptions ("FUNCTION", $symbol, @fields);
2030 my $parameters_output = 0;
2032 if (defined ($SymbolDocs{$symbol})) {
2033 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
2035 # Try to insert the parameter table at the author's desired position.
2036 # Otherwise we need to tag it onto the end.
2037 # FIXME: document that in the user manual and make it useable for other
2039 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
2040 $parameters_output = 1;
2042 $desc .= $symbol_docs;
2045 if ($parameters_output == 0) {
2046 $desc .= $parameters;
2049 $desc .= OutputSymbolTraits ($symbol);
2050 $desc .= "</refsect2>\n";
2051 return ($synop, $desc);
2055 #############################################################################
2056 # Function : OutputParamDescriptions
2057 # Description : Returns the DocBook output describing the parameters of a
2058 # function, macro or signal handler.
2059 # Arguments : $symbol_type - 'FUNCTION', 'MACRO' or 'SIGNAL'. Signal
2060 # handlers have an implicit user_data parameter last.
2061 # $symbol - the name of the function/macro being described.
2062 # @fields - parsed fields from the declaration, used to determine
2063 # undocumented/unused entries
2064 #############################################################################
2066 sub OutputParamDescriptions {
2067 my ($symbol_type, $symbol, @fields) = @_;
2069 my $params = $SymbolParams{$symbol};
2071 my %field_descrs = ();
2074 %field_descrs = @fields;
2075 delete $field_descrs{"void"};
2076 delete $field_descrs{"Returns"};
2079 if (defined $params) {
2081 my $params_desc = "";
2082 my $missing_parameters = "";
2083 my $unused_parameters = "";
2086 for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
2087 my $param_name = $$params[$j];
2088 my $param_desc = $$params[$j + 1];
2089 my $param_annotations = "";
2091 ($param_desc,$param_annotations) = & ExpandAnnotation($symbol, $param_desc);
2092 $param_desc = &ExpandAbbreviations($symbol, $param_desc);
2093 $param_desc .= $param_annotations;
2094 if ($param_name eq "Returns") {
2095 $returns = "$param_desc";
2096 } elsif ($param_name eq "void") {
2097 #print "!!!! void in params for $symbol?\n";
2100 if (!defined $field_descrs{$param_name}) {
2101 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2102 "Parameter description for $symbol"."::"."$param_name is not used from source code comment block.");
2103 if ($unused_parameters ne "") {
2104 $unused_parameters .= ", ".$param_name;
2106 $unused_parameters = $param_name;
2109 delete $field_descrs{$param_name};
2112 if ($param_name eq "Varargs") {
2113 $param_name = "...";
2115 if($param_desc ne "") {
2116 $params_desc .= "<varlistentry><term><parameter>$param_name</parameter> :</term>\n<listitem><simpara>$param_desc</simpara></listitem></varlistentry>\n";
2121 foreach my $param_name (keys %field_descrs) {
2122 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2123 "Parameter description for $symbol"."::"."$param_name is missing in source code comment block.");
2124 if ($missing_parameters ne "") {
2125 $missing_parameters .= ", ".$param_name;
2127 $missing_parameters = $param_name;
2131 # Signals have an implicit user_data parameter which we describe.
2132 if ($symbol_type eq "SIGNAL") {
2133 $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";
2136 # Start a table if we need one.
2137 if ($params_desc || $returns) {
2138 $output .= "<variablelist role=\"params\">\n";
2139 if ($params_desc ne "") {
2140 #$output .= "<varlistentry><term>Parameters:</term><listitem></listitem></varlistentry>\n";
2141 $output .= $params_desc;
2144 # Output the returns info last.
2146 $output .= "<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>$returns</simpara></listitem></varlistentry>\n";
2150 $output .= "</variablelist>";
2153 # remember missing/unused parameters (needed in tmpl-free build)
2154 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
2155 $AllIncompleteSymbols{$symbol}=$missing_parameters;
2157 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
2158 $AllUnusedSymbols{$symbol}=$unused_parameters;
2161 if (($num_params == 0) && @fields && (scalar(keys(%field_descrs)) > 0)) {
2162 if (! exists ($AllIncompleteSymbols{$symbol})) {
2163 $AllIncompleteSymbols{$symbol}="<parameters>";
2171 #############################################################################
2172 # Function : ParseStabilityLevel
2173 # Description : Parses a stability level and outputs a warning if it isn't
2175 # Arguments : $stability - the stability text.
2176 # $file, $line - context for error message
2177 # $message - description of where the level is from, to use in
2178 # any error message.
2179 # Returns : The parsed stability level string.
2180 #############################################################################
2182 sub ParseStabilityLevel {
2183 my ($stability, $file, $line, $message) = @_;
2185 $stability =~ s/^\s*//;
2186 $stability =~ s/\s*$//;
2187 if ($stability =~ m/^stable$/i) {
2188 $stability = "Stable";
2189 } elsif ($stability =~ m/^unstable$/i) {
2190 $stability = "Unstable";
2191 } elsif ($stability =~ m/^private$/i) {
2192 $stability = "Private";
2194 &LogWarning ($file, $line, "$message is $stability.".
2195 "It should be one of these: Stable, Unstable, or Private.");
2201 #############################################################################
2202 # Function : OutputSGMLFile
2203 # Description : Outputs the final DocBook file for one section.
2204 # Arguments : $file - the name of the file.
2205 # $title - the title from the $MODULE-sections.txt file, which
2206 # will be overridden by the title in the template file.
2207 # $section_id - the SGML id to use for the toplevel tag.
2208 # $includes - comma-separates list of include files added at top
2209 # of synopsis, with '<' '>' around them (if not already enclosed in "").
2210 # $synopsis - reference to the DocBook for the Synopsis part.
2211 # $details - reference to the DocBook for the Details part.
2212 # $signal_synop - reference to the DocBook for the Signal Synopsis part
2213 # $signal_desc - reference to the DocBook for the Signal Description part
2214 # $args_synop - reference to the DocBook for the Arg Synopsis part
2215 # $args_desc - reference to the DocBook for the Arg Description part
2216 # $hierarchy - reference to the DocBook for the Object Hierarchy part
2217 # $interfaces - reference to the DocBook for the Interfaces part
2218 # $implementations - reference to the DocBook for the Known Implementations part
2219 # $prerequisites - reference to the DocBook for the Prerequisites part
2220 # $derived - reference to the DocBook for the Derived Interfaces part
2221 # $file_objects - reference to an array of objects in this file
2222 #############################################################################
2224 sub OutputSGMLFile {
2225 my ($file, $title, $section_id, $includes, $synopsis, $details, $signals_synop, $signals_desc, $args_synop, $args_desc, $hierarchy, $interfaces, $implementations, $prerequisites, $derived, $file_objects) = @_;
2227 #print "Output sgml for file $file with title '$title'\n";
2229 # The edited title overrides the one from the sections file.
2230 my $new_title = $SymbolDocs{"$TMPL_DIR/$file:Title"};
2231 if (defined ($new_title) && $new_title !~ m/^\s*$/) {
2232 $title = $new_title;
2233 #print "Found title: $title\n";
2235 my $short_desc = $SymbolDocs{"$TMPL_DIR/$file:Short_Description"};
2236 if (!defined ($short_desc) || $short_desc =~ m/^\s*$/) {
2239 $short_desc = &ExpandAbbreviations("$title:Short_description",
2241 #print "Found short_desc: $short_desc";
2243 my $long_desc = $SymbolDocs{"$TMPL_DIR/$file:Long_Description"};
2244 if (!defined ($long_desc) || $long_desc =~ m/^\s*$/) {
2247 $long_desc = &ExpandAbbreviations("$title:Long_description",
2249 #print "Found long_desc: $long_desc";
2251 my $see_also = $SymbolDocs{"$TMPL_DIR/$file:See_Also"};
2252 if (!defined ($see_also) || $see_also =~ m%^\s*(<para>)?\s*(</para>)?\s*$%) {
2255 $see_also = &ExpandAbbreviations("$title:See_Also", $see_also);
2256 #print "Found see_also: $see_also";
2259 $see_also = "<refsect1 id=\"$section_id.see-also\">\n<title>See Also</title>\n$see_also\n</refsect1>\n";
2261 my $stability = $SymbolDocs{"$TMPL_DIR/$file:Stability_Level"};
2262 if (!defined ($stability) || $stability =~ m/^\s*$/) {
2265 $stability = &ParseStabilityLevel($stability, $file, $., "Section stability level");
2266 #print "Found stability: $stability";
2269 $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$stability, unless otherwise indicated\n</refsect1>\n";
2270 } elsif ($DEFAULT_STABILITY) {
2271 $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$DEFAULT_STABILITY, unless otherwise indicated\n</refsect1>\n";
2274 my $image = $SymbolDocs{"$TMPL_DIR/$file:Image"};
2275 if (!defined ($image) || $image =~ m/^\s*$/) {
2283 if ($image =~ /jpe?g$/i) {
2284 $format = "format='JPEG'";
2285 } elsif ($image =~ /png$/i) {
2286 $format = "format='PNG'";
2287 } elsif ($image =~ /svg$/i) {
2288 $format = "format='SVG'";
2293 $image = " <inlinegraphic fileref='$image' $format/>\n"
2296 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
2298 my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
2301 my $include_output = "";
2303 foreach $include (split (/,/, $includes)) {
2304 if ($include =~ m/^\".+\"$/) {
2305 $include_output .= "#include ${include}\n";
2308 $include =~ s/^\s+|\s+$//gs;
2309 $include_output .= "#include <${include}>\n";
2312 if ($include_output ne '') {
2313 $include_output = "\n$include_output\n";
2316 my $extralinks = OutputSectionExtraLinks($title,"Section:$file");
2318 my $old_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT";
2319 my $new_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT.new";
2321 open (OUTPUT, ">$new_sgml_file")
2322 || die "Can't create $new_sgml_file: $!";
2324 my $object_anchors = "";
2325 foreach my $object (@$file_objects) {
2326 next if ($object eq $section_id);
2327 my $id = CreateValidSGMLID($object);
2328 #print "Debug: Adding anchor for $object\n";
2329 $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
2332 # We used to output this, but is messes up our UpdateFileIfChanged code
2333 # since it changes every day (and it is only used in the man pages):
2334 # "<refentry id="$section_id" revision="$mday $month $year">"
2336 if ($OUTPUT_FORMAT eq "xml") {
2337 print OUTPUT $doctype_header;
2341 <refentry id="$section_id">
2343 <refentrytitle role="top_of_page" id="$section_id.top_of_page">$title</refentrytitle>
2344 <manvolnum>3</manvolnum>
2347 $image</refmiscinfo>
2350 <refname>$title</refname>
2351 <refpurpose>$short_desc</refpurpose>
2354 <refsynopsisdiv id="$section_id.synopsis" role="synopsis">
2355 <title role="synopsis.title">Synopsis</title>
2357 <synopsis>$include_output$${synopsis}</synopsis>
2359 $$hierarchy$$prerequisites$$derived$$interfaces$$implementations$$args_synop$$signals_synop
2360 <refsect1 id="$section_id.description" role="desc">
2361 <title role="desc.title">Description</title>
2362 $extralinks$long_desc
2364 <refsect1 id="$section_id.details" role="details">
2365 <title role="details.title">Details</title>
2368 $$args_desc$$signals_desc$see_also
2373 return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2377 #############################################################################
2378 # Function : OutputExtraFile
2379 # Description : Copies an "extra" DocBook file into the output directory,
2380 # expanding abbreviations
2381 # Arguments : $file - the source file.
2382 #############################################################################
2383 sub OutputExtraFile {
2388 ($basename = $file) =~ s!^.*/!!;
2390 my $old_sgml_file = "$SGML_OUTPUT_DIR/$basename";
2391 my $new_sgml_file = "$SGML_OUTPUT_DIR/$basename.new";
2395 open(EXTRA_FILE, "<$file") || die "Can't open $file";
2399 $contents = <EXTRA_FILE>;
2402 open (OUTPUT, ">$new_sgml_file")
2403 || die "Can't create $new_sgml_file: $!";
2405 print OUTPUT &ExpandAbbreviations ("$basename file", $contents);
2408 return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2410 #############################################################################
2411 # Function : OutputBook
2412 # Description : Outputs the SGML entities that need to be included into the
2413 # main SGML file for the module.
2414 # Arguments : $book_top - the declarations of the entities, which are added
2415 # at the top of the main SGML file.
2416 # $book_bottom - the references to the entities, which are
2417 # added in the main SGML file at the desired position.
2418 #############################################################################
2421 my ($book_top, $book_bottom) = @_;
2423 my $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top";
2424 my $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top.new";
2426 open (OUTPUT, ">$new_file")
2427 || die "Can't create $new_file: $!";
2428 print OUTPUT $book_top;
2431 &UpdateFileIfChanged ($old_file, $new_file, 0);
2434 $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom";
2435 $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom.new";
2437 open (OUTPUT, ">$new_file")
2438 || die "Can't create $new_file: $!";
2439 print OUTPUT $book_bottom;
2442 &UpdateFileIfChanged ($old_file, $new_file, 0);
2445 # If the main SGML/XML file hasn't been created yet, we create it here.
2446 # The user can tweak it later.
2447 if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
2448 open (OUTPUT, ">$MAIN_SGML_FILE")
2449 || die "Can't create $MAIN_SGML_FILE: $!";
2451 if ($OUTPUT_FORMAT eq "xml") {
2453 <?xml version="1.0"?>
2454 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
2455 "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
2457 <!ENTITY % local.common.attrib "xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'">
2463 <!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
2472 <title>$MODULE Reference Manual</title>
2474 for $MODULE [VERSION].
2475 The latest version of this documentation can be found on-line at
2476 <ulink role="online-location" url="http://[SERVER]/$MODULE/index.html">http://[SERVER]/$MODULE/</ulink>.
2481 <title>[Insert title here]</title>
2485 if (-e $OBJECT_TREE_FILE) {
2487 <chapter id="object-tree">
2488 <title>Object Hierarchy</title>
2489 <xi:include href="xml/tree_index.sgml"/>
2495 <index id="api-index-full">
2496 <title>API Index</title>
2497 <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
2499 <index id="deprecated-api-index" role="deprecated">
2500 <title>Index of deprecated API</title>
2501 <xi:include href="xml/api-index-deprecated.xml"><xi:fallback /></xi:include>
2504 <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
2513 #############################################################################
2514 # Function : CreateValidSGML
2515 # Description : This turns any chars which are used in SGML into entities,
2516 # e.g. '<' into '<'
2517 # Arguments : $text - the text to turn into proper SGML.
2518 #############################################################################
2520 sub CreateValidSGML {
2522 $text =~ s/&/&/g; # Do this first, or the others get messed up.
2523 $text =~ s/</</g;
2524 $text =~ s/>/>/g;
2525 # browers render single tabs inconsistently
2526 $text =~ s/([^\s])\t([^\s])/$1 $2/g;
2530 #############################################################################
2531 # Function : ConvertSGMLChars
2532 # Description : This is used for text in source code comment blocks, to turn
2533 # chars which are used in SGML into entities, e.g. '<' into
2534 # '<'. Depending on $INLINE_MARKUP_MODE, this is done
2535 # unconditionally or only if the character doesn't seem to be
2536 # part of an SGML construct (tag or entity reference).
2537 # Arguments : $text - the text to turn into proper SGML.
2538 #############################################################################
2540 sub ConvertSGMLChars {
2541 my ($symbol, $text) = @_;
2543 if ($INLINE_MARKUP_MODE) {
2544 # For the XML/SGML mode only convert to entities outside CDATA sections.
2545 return &ModifyXMLElements ($text, $symbol,
2546 "<!\\[CDATA\\[|<programlisting[^>]*>",
2547 \&ConvertSGMLCharsEndTag,
2548 \&ConvertSGMLCharsCallback);
2550 # For the simple non-sgml mode, convert to entities everywhere.
2551 $text =~ s/&/&/g; # Do this first, or the others get messed up.
2552 $text =~ s/</</g;
2553 $text =~ s/>/>/g;
2559 sub ConvertSGMLCharsEndTag {
2560 if ($_[0] eq "<!\[CDATA\[") {
2563 return "</programlisting>";
2567 sub ConvertSGMLCharsCallback {
2568 my ($text, $symbol, $tag) = @_;
2570 if ($tag =~ m/^<programlisting/) {
2571 # We can handle <programlisting> specially here.
2572 return &ModifyXMLElements ($text, $symbol,
2574 \&ConvertSGMLCharsEndTag,
2575 \&ConvertSGMLCharsCallback2);
2576 } elsif ($tag eq "") {
2577 # If we're not in CDATA convert to entities.
2578 $text =~ s/&(?![a-zA-Z#]+;)/&/g; # Do this first, or the others get messed up.
2579 $text =~ s/<(?![a-zA-Z\/!])/</g;
2580 $text =~ s/(?<![a-zA-Z0-9"'\/-])>/>/g;
2582 # Handle "#include <xxxxx>"
2583 $text =~ s/#include(\s+)<([^>]+)>/#include$1<$2>/g;
2589 sub ConvertSGMLCharsCallback2 {
2590 my ($text, $symbol, $tag) = @_;
2592 # If we're not in CDATA convert to entities.
2593 # We could handle <programlisting> differently, though I'm not sure it helps.
2595 # replace only if its not a tag
2596 $text =~ s/&(?![a-zA-Z#]+;)/&/g; # Do this first, or the others get messed up.
2597 $text =~ s/<(?![a-zA-Z\/!])/</g;
2598 $text =~ s/(?<![a-zA-Z0-9"'\/-])>/>/g;
2600 # Handle "#include <xxxxx>"
2601 $text =~ s/#include(\s+)<([^>]+)>/#include$1<$2>/g;
2607 #############################################################################
2608 # Function : ExpandAnnotation
2609 # Description : This turns annotations into acronym tags.
2610 # Arguments : $symbol - the symbol being documented, for error messages.
2611 # $text - the text to expand.
2612 #############################################################################
2613 sub ExpandAnnotation {
2614 my ($symbol, $param_desc) = @_;
2615 my $param_annotations = "";
2617 # look for annotations at the start of the comment part
2618 if ($param_desc =~ m%^\s*\((.*?)\):%) {
2623 @annotations = split(/\)\s*\(/,$1);
2624 foreach $annotation (@annotations) {
2625 # need to search for the longest key-match in %AnnotationDefinition
2627 my $match_annotation="";
2629 foreach $annotationdef (keys %AnnotationDefinition) {
2630 if ($annotation =~ m/^$annotationdef/) {
2631 if (length($annotationdef)>$match_length) {
2632 $match_length=length($annotationdef);
2633 $match_annotation=$annotationdef;
2637 my $annotation_extra = "";
2638 if ($match_annotation ne "") {
2639 if ($annotation =~ m%$match_annotation\s+(.*)%) {
2640 $annotation_extra = " $1";
2642 $AnnotationsUsed{$match_annotation} = 1;
2643 $param_annotations .= "[<acronym>$match_annotation</acronym>$annotation_extra]";
2646 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2647 "unknown annotation \"$annotation\" in documentation for $symbol.");
2648 $param_annotations .= "[$annotation]";
2652 $param_desc =~ m/^(.*?)\.*\s*$/s;
2653 $param_desc = "$1. ";
2655 if ($param_annotations ne "") {
2656 $param_annotations = "<emphasis role=\"annotation\">$param_annotations</emphasis>";
2658 return ($param_desc, $param_annotations);
2661 #############################################################################
2662 # Function : ExpandAbbreviations
2663 # Description : This turns the abbreviations function(), macro(), @param,
2664 # %constant, and #symbol into appropriate DocBook markup.
2665 # CDATA sections and <programlisting> parts are skipped.
2666 # Arguments : $symbol - the symbol being documented, for error messages.
2667 # $text - the text to expand.
2668 #############################################################################
2670 sub ExpandAbbreviations {
2671 my ($symbol, $text) = @_;
2673 # Convert "|[" and "]|" into the start and end of program listing examples.
2674 # FIXME: we like to have a way to specify parameters e.g. language="c"
2675 $text =~ s%\|\[%<informalexample><programlisting>%g;
2676 $text =~ s%\]\|%</programlisting></informalexample>%g;
2677 # TODO: check for a xml comment after |[ and pick the language attribute from
2680 # keep CDATA unmodified, preserve ulink tags (ideally we preseve all tags
2682 return &ModifyXMLElements ($text, $symbol,
2683 "<!\\[CDATA\\[|<ulink[^>]*>|<programlisting[^>]*>|<!DOCTYPE",
2684 \&ExpandAbbreviationsEndTag,
2685 \&ExpandAbbreviationsCallback);
2689 # Returns the end tag corresponding to the given start tag.
2690 sub ExpandAbbreviationsEndTag {
2691 my ($start_tag) = @_;
2693 if ($start_tag eq "<!\[CDATA\[") {
2695 } elsif ($start_tag eq "<!DOCTYPE") {
2697 } elsif ($start_tag =~ m/<(\w+)/) {
2702 # Called inside or outside each CDATA or <programlisting> section.
2703 sub ExpandAbbreviationsCallback {
2704 my ($text, $symbol, $tag) = @_;
2706 if ($tag =~ m/^<programlisting/) {
2707 # Handle any embedded CDATA sections.
2708 return &ModifyXMLElements ($text, $symbol,
2710 \&ExpandAbbreviationsEndTag,
2711 \&ExpandAbbreviationsCallback2);
2712 } elsif ($tag eq "") {
2713 # We are outside any CDATA or <programlisting> sections, so we expand
2714 # any gtk-doc abbreviations.
2716 # Convert 'function()' or 'macro()'.
2717 # if there is abc_*_def() we don't want to make a link to _def()
2718 # FIXME: also handle abc(....) : but that would need to be done recursively :/
2719 $text =~ s/([^\*.\w])(\w+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2720 # handle #Object.func()
2721 $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2723 # Convert '@param', but not '\@param'.
2724 $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)/$1<parameter>$2<\/parameter>/g;
2725 $text =~ s/\\\@/\@/g;
2727 # Convert '%constant', but not '\%constant'.
2728 # Also allow negative numbers, e.g. %-1.
2729 $text =~ s/(\A|[^\\])\%(-?\w+)/$1.&MakeXRef($2, &tagify($2, "literal"));/eg;
2730 $text =~ s/\\\%/\%/g;
2732 # Convert '#symbol', but not '\#symbol'.
2733 $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)/$1.&MakeHashXRef($2, "type");/eg;
2737 # FIXME: should we skip urls that are already tagged? (e.g. <literal>http://...</literal>)
2738 # this is apparently also called for markup and not just for plain text
2740 #$text =~ s%(http|https|ftp)://(.*?)((?:\s|,|\)|\]|\<|\.\s))%<ulink url="$1://$2">$2</ulink>$3%g;
2742 # TODO: optionally check all words from $text against internal symbols and
2743 # warn if those could be xreffed, but miss a %,# or ()
2749 # This is called inside a <programlisting>
2750 sub ExpandAbbreviationsCallback2 {
2751 my ($text, $symbol, $tag) = @_;
2754 # We are inside a <programlisting> but outside any CDATA sections,
2755 # so we expand any gtk-doc abbreviations.
2756 # FIXME: why is this different from &ExpandAbbreviationsCallback(),
2757 # why not just call it
2758 $text =~ s/#(\w+)/&MakeHashXRef($1, "");/eg;
2765 my ($symbol, $tag) = @_;;
2768 # Check for things like '#include', '#define', and skip them.
2769 if ($PreProcessorDirectives{$symbol}) {
2773 # Get rid of any special '-struct' suffix.
2774 $text =~ s/-struct$//;
2776 # If the symbol is in the form "Object::signal", then change the symbol to
2777 # "Object-signal" and use "signal" as the text.
2778 if ($symbol =~ s/::/-/) {
2782 # If the symbol is in the form "Object:property", then change the symbol to
2783 # "Object--property" and use "property" as the text.
2784 if ($symbol =~ s/:/--/) {
2789 $text = tagify ($text, $tag);
2792 return &MakeXRef($symbol, $text);
2796 #############################################################################
2797 # Function : ModifyXMLElements
2798 # Description : Looks for given XML element tags within the text, and calls
2799 # the callback on pieces of text inside & outside those elements.
2800 # Used for special handling of text inside things like CDATA
2801 # and <programlisting>.
2802 # Arguments : $text - the text.
2803 # $symbol - the symbol currently being documented (only used for
2805 # $start_tag_regexp - the regular expression to match start tags.
2806 # e.g. "<!\\[CDATA\\[|<programlisting[^>]*>" to match
2807 # CDATA sections or programlisting elements.
2808 # $end_tag_func - function which is passed the matched start tag
2809 # and should return the appropriate end tag string.
2810 # $callback - callback called with each part of the text. It is
2811 # called with a piece of text, the symbol being
2812 # documented, and the matched start tag or "" if the text
2813 # is outside the XML elements being matched.
2814 #############################################################################
2815 sub ModifyXMLElements {
2816 my ($text, $symbol, $start_tag_regexp, $end_tag_func, $callback) = @_;
2817 my ($before_tag, $start_tag, $end_tag_regexp, $end_tag);
2820 while ($text =~ m/$start_tag_regexp/s) {
2821 $before_tag = $`; # Prematch for last successful match string
2822 $start_tag = $&; # Last successful match
2823 $text = $'; # Postmatch for last successful match string
2825 $result .= &$callback ($before_tag, $symbol, "");
2826 $result .= $start_tag;
2828 # get the mathing end-tag for current tag
2829 $end_tag_regexp = &$end_tag_func ($start_tag);
2831 if ($text =~ m/$end_tag_regexp/s) {
2836 $result .= &$callback ($before_tag, $symbol, $start_tag);
2837 $result .= $end_tag;
2839 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2840 "Can't find tag end: $end_tag_regexp in docs for: $symbol.");
2841 # Just assume it is all inside the tag.
2842 $result .= &$callback ($text, $symbol, $start_tag);
2847 # Handle any remaining text outside the tags.
2848 $result .= &$callback ($text, $symbol, "");
2857 # Adds a tag around some text.
2858 # e.g tagify("Text", "literal") => "<literal>Text</literal>".
2860 my ($text, $elem) = @_;
2861 return "<" . $elem . ">" . $text . "</" . $elem . ">";
2865 #############################################################################
2866 # Function : MakeXRef
2867 # Description : This returns a cross-reference link to the given symbol.
2868 # Though it doesn't try to do this for a few standard C types
2869 # that it knows won't be in the documentation.
2870 # Arguments : $symbol - the symbol to try to create a XRef to.
2871 # $text - text text to put inside the XRef, defaults to $symbol
2872 #############################################################################
2875 my ($symbol, $text) = ($_[0], $_[1]);
2877 $symbol =~ s/^\s+//;
2878 $symbol =~ s/\s+$//;
2880 if (!defined($text)) {
2883 # Get rid of special '-struct' suffix.
2884 $text =~ s/-struct$//;
2887 if ($symbol =~ m/ /) {
2891 #print "Getting type link for $symbol -> $text\n";
2893 my $symbol_id = &CreateValidSGMLID ($symbol);
2894 return "<link linkend=\"$symbol_id\">$text</link>";
2898 #############################################################################
2899 # Function : MakeIndexterms
2900 # Description : This returns a indexterm elements for the given symbol
2901 # Arguments : $symbol - the symbol to create indexterms for
2902 #############################################################################
2904 sub MakeIndexterms {
2905 my ($symbol, $id) = @_;
2909 # make the index useful, by ommiting the namespace when sorting
2910 if ($NAME_SPACE ne "") {
2911 if ($symbol =~ m/^$NAME_SPACE\_?(.*)/i) {
2912 $sortas=" sortas=\"$1\"";
2916 if (exists $Deprecated{$symbol}) {
2917 $terms .= "<indexterm zone=\"$id\" role=\"deprecated\"><primary$sortas>$symbol</primary></indexterm>";
2918 $IndexEntriesDeprecated{$symbol}=$id;
2919 $IndexEntriesFull{$symbol}=$id;
2921 if (exists $Since{$symbol}) {
2922 my $since = $Since{$symbol};
2926 $terms .= "<indexterm zone=\"$id\" role=\"$since\"><primary$sortas>$symbol</primary></indexterm>";
2928 $IndexEntriesSince{$symbol}=$id;
2929 $IndexEntriesFull{$symbol}=$id;
2932 $terms .= "<indexterm zone=\"$id\"><primary$sortas>$symbol</primary></indexterm>";
2933 $IndexEntriesFull{$symbol}=$id;
2939 #############################################################################
2940 # Function : MakeDeprecationNote
2941 # Description : This returns a deprecation warning for the given symbol.
2942 # Arguments : $symbol - the symbol to try to create a warning for.
2943 #############################################################################
2945 sub MakeDeprecationNote {
2946 my ($symbol) = $_[0];
2949 if (exists $Deprecated{$symbol}) {
2950 $desc .= "<warning>";
2952 if ($Deprecated{$symbol} =~ /^\s*([0-9\.]+)\s*:/) {
2953 $desc .= "<para><literal>$symbol</literal> has been deprecated since version $1 and should not be used in newly-written code.";
2955 $desc .= "<para><literal>$symbol</literal> is deprecated and should not be used in newly-written code.";
2957 if ($Deprecated{$symbol} ne "") {
2958 $note = &ExpandAbbreviations($symbol, $Deprecated{$symbol});
2959 $note =~ s/^\s*([0-9\.]+)\s*:\s*//;
2962 $note =~ s%\n{2,}%\n</para>\n<para>\n%g;
2963 $desc .= " " . $note;
2965 $desc .= "</para></warning>\n";
2970 #############################################################################
2971 # Function : MakeConditionDescription
2972 # Description : This returns a sumary of conditions for the given symbol.
2973 # Arguments : $symbol - the symbol to try to create the sumary.
2974 #############################################################################
2976 sub MakeConditionDescription {
2977 my ($symbol) = $_[0];
2980 if (exists $Deprecated{$symbol}) {
2985 if ($Deprecated{$symbol} =~ /^\s*(.*?)\s*$/) {
2986 $desc .= "deprecated:$1";
2988 $desc .= "deprecated";
2992 if (exists $Since{$symbol}) {
2997 if ($Since{$symbol} =~ /^\s*(.*?)\s*$/) {
2998 $desc .= "since:$1";
3004 if (exists $StabilityLevel{$symbol}) {
3008 $desc .= "stability:".$StabilityLevel{$symbol};
3012 $desc=" condition=\"".$desc."\"";
3013 #print "condition for '$symbol' = '$desc'\n";
3018 #############################################################################
3019 # Function : GetHierarchy
3020 # Description : Returns the DocBook output describing the ancestors and
3021 # immediate children of a GObject subclass. It uses the
3022 # global @Objects and @ObjectLevels arrays to walk the tree.
3023 # Arguments : $object - the GtkObject subclass.
3024 #############################################################################
3029 # Find object in the objects array.
3035 for ($i = 0; $i < @Objects; $i++) {
3037 if ($ObjectLevels[$i] <= $level) {
3040 elsif ($ObjectLevels[$i] == $level + 1) {
3041 push (@children, $Objects[$i]);
3044 elsif ($Objects[$i] eq $object) {
3047 $level = $ObjectLevels[$i];
3054 # Walk up the hierarchy, pushing ancestors onto the ancestors array.
3056 push (@ancestors, $object);
3057 #print "Level: $level\n";
3058 while ($level > 1) {
3060 if ($ObjectLevels[$j] < $level) {
3061 push (@ancestors, $Objects[$j]);
3062 $level = $ObjectLevels[$j];
3063 #print "Level: $level\n";
3067 # Output the ancestors list, indented and with links.
3068 my $hierarchy = "<synopsis>\n";
3070 for ($i = $#ancestors; $i >= 0; $i--) {
3072 # Don't add a link to the current object, i.e. when i == 0.
3074 my $ancestor_id = &CreateValidSGMLID ($ancestors[$i]);
3075 $link_text = "<link linkend=\"$ancestor_id\">$ancestors[$i]</link>";
3077 $link_text = "$ancestors[$i]";
3080 $hierarchy .= " $link_text\n";
3082 # $hierarchy .= ' ' x ($level * 6 - 3) . "|\n";
3083 $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3087 for ($i = 0; $i <= $#children; $i++) {
3088 my $id = &CreateValidSGMLID ($children[$i]);
3089 my $link_text = "<link linkend=\"$id\">$children[$i]</link>";
3090 $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3092 $hierarchy .= "</synopsis>\n";
3098 #############################################################################
3099 # Function : GetInterfaces
3100 # Description : Returns the DocBook output describing the interfaces
3101 # implemented by a class. It uses the global %Interfaces hash.
3102 # Arguments : $object - the GtkObject subclass.
3103 #############################################################################
3110 # Find object in the objects array.
3111 if (exists($Interfaces{$object})) {
3112 my @ifaces = split(' ', $Interfaces{$object});
3117 for ($i = 0; $i <= $#ifaces; $i++) {
3118 my $id = &CreateValidSGMLID ($ifaces[$i]);
3119 $text .= " <link linkend=\"$id\">$ifaces[$i]</link>";
3120 if ($i < $#ifaces - 1) {
3123 elsif ($i < $#ifaces) {
3138 #############################################################################
3139 # Function : GetImplementations
3140 # Description : Returns the DocBook output describing the implementations
3141 # of an interface. It uses the global %Interfaces hash.
3142 # Arguments : $object - the GtkObject subclass.
3143 #############################################################################
3145 sub GetImplementations {
3150 foreach my $key (keys %Interfaces) {
3151 if ($Interfaces{$key} =~ /\b$object\b/) {
3152 push (@impls, $key);
3156 @impls = sort @impls;
3159 $object is implemented by
3161 for ($i = 0; $i <= $#impls; $i++) {
3162 my $id = &CreateValidSGMLID ($impls[$i]);
3163 $text .= " <link linkend=\"$id\">$impls[$i]</link>";
3164 if ($i < $#impls - 1) {
3167 elsif ($i < $#impls) {
3182 #############################################################################
3183 # Function : GetPrerequisites
3184 # Description : Returns the DocBook output describing the prerequisites
3185 # of an interface. It uses the global %Prerequisites hash.
3186 # Arguments : $iface - the interface.
3187 #############################################################################
3189 sub GetPrerequisites {
3194 if (exists($Prerequisites{$iface})) {
3199 my @prereqs = split(' ', $Prerequisites{$iface});
3200 for ($i = 0; $i <= $#prereqs; $i++) {
3201 my $id = &CreateValidSGMLID ($prereqs[$i]);
3202 $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
3203 if ($i < $#prereqs - 1) {
3206 elsif ($i < $#prereqs) {
3220 #############################################################################
3221 # Function : GetDerived
3222 # Description : Returns the DocBook output describing the derived interfaces
3223 # of an interface. It uses the global %Prerequisites hash.
3224 # Arguments : $iface - the interface.
3225 #############################################################################
3233 foreach my $key (keys %Prerequisites) {
3234 if ($Prerequisites{$key} =~ /\b$iface\b/) {
3235 push (@derived, $key);
3238 if ($#derived >= 0) {
3239 @derived = sort @derived;
3242 $iface is required by
3244 for ($i = 0; $i <= $#derived; $i++) {
3245 my $id = &CreateValidSGMLID ($derived[$i]);
3246 $text .= " <link linkend=\"$id\">$derived[$i]</link>";
3247 if ($i < $#derived - 1) {
3250 elsif ($i < $#derived) {
3265 #############################################################################
3266 # Function : GetSignals
3267 # Description : Returns the synopsis and detailed description DocBook output
3268 # for the signal handlers of a given GtkObject subclass.
3269 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
3270 #############################################################################
3278 for ($i = 0; $i <= $#SignalObjects; $i++) {
3279 if ($SignalObjects[$i] eq $object) {
3280 #print "Found signal: $SignalNames[$i]\n";
3281 my $name = $SignalNames[$i];
3282 my $symbol = "${object}::${name}";
3283 my $id = &CreateValidSGMLID ("$object-$name");
3285 my $pad = ' ' x (46 - length($name));
3286 $synop .= " "<link linkend=\"$id\">$name</link>"$pad ";
3288 $desc .= "<refsect2 id=\"$id\" role=\"signal\"><title>The <literal>"$name"</literal> signal</title>\n";
3289 $desc .= MakeIndexterms($symbol, $id);
3291 $desc .= OutputSymbolExtraLinks($symbol);
3293 $desc .= "<programlisting>";
3295 $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
3296 my $type_modifier = defined($1) ? $1 : "";
3299 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
3301 my $ret_type_len = length ($type_modifier) + length ($pointer)
3303 my $ret_type_output = "$type_modifier$xref$pointer"
3304 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
3306 $desc .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
3308 my $sourceparams = $SourceSymbolParams{$symbol};
3309 my @params = split ("\n", $SignalPrototypes[$i]);
3312 my $type_len = length("gpointer");
3313 my $name_len = length("user_data");
3314 # do two passes, the first one is to calculate padding
3315 for ($l = 0; $l < 2; $l++) {
3316 for ($j = 0; $j <= $#params; $j++) {
3317 # allow alphanumerics, '_', '[' & ']' in param names
3318 if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
3321 if (defined($sourceparams)) {
3322 $name = $$sourceparams[$PARAM_FIELD_COUNT * $j];
3327 if (!defined($name)) {
3331 if (length($type) + length($pointer) > $type_len) {
3332 $type_len = length($type) + length($pointer);
3334 if (length($name) > $name_len) {
3335 $name_len = length($name);
3339 $xref = &MakeXRef ($type, &tagify($type, "type"));
3340 $pad = ' ' x ($type_len - length($type) - length($pointer));
3341 $desc .= "$xref$pad $pointer$name,\n";
3342 $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
3345 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3346 "Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]");
3350 $xref = &MakeXRef ("gpointer", &tagify("gpointer", "type"));
3351 $pad = ' ' x ($type_len - length("gpointer"));
3352 $desc .= "$xref$pad user_data)";
3354 my $flags = $SignalFlags[$i];
3355 my $flags_string = "";
3357 if (defined ($flags)) {
3358 if ($flags =~ m/f/) {
3359 $flags_string = "<link linkend=\"G-SIGNAL-RUN-FIRST:CAPS\"><literal>Run First</literal></link>";
3361 elsif ($flags =~ m/l/) {
3362 $flags_string = "<link linkend=\"G-SIGNAL-RUN-LAST:CAPS\"><literal>Run Last</literal></link>";
3364 elsif ($flags =~ m/c/) {
3365 $flags_string = "<link linkend=\"G-SIGNAL-RUN-CLEANUP:CAPS\"><literal>Cleanup</literal></link>";
3366 $flags_string = "Cleanup";
3368 if ($flags =~ m/r/) {
3369 if ($flags_string) { $flags_string .= " / "; }
3370 $flags_string = "<link linkend=\"G-SIGNAL-NO-RECURSE:CAPS\"><literal>No Recursion</literal></link>";
3372 if ($flags =~ m/d/) {
3373 if ($flags_string) { $flags_string .= " / "; }
3374 $flags_string = "<link linkend=\"G-SIGNAL-DETAILED:CAPS\"><literal>Has Details</literal></link>";
3376 if ($flags =~ m/a/) {
3377 if ($flags_string) { $flags_string .= " / "; }
3378 $flags_string = "<link linkend=\"G-SIGNAL-ACTION:CAPS\"><literal>Action</literal></link>";
3380 if ($flags =~ m/h/) {
3381 if ($flags_string) { $flags_string .= " / "; }
3382 $flags_string = "<link linkend=\"G-SIGNAL-NO-HOOKS:CAPS\"><literal>No Hooks</literal></link>";
3388 $synop .= ": $flags_string\n";
3390 $pad = ' ' x (5 + $name_len - length("user_data"));
3391 $desc .= "$pad : $flags_string</programlisting>\n";
3396 $desc .= "</programlisting>\n";
3399 $desc .= &MakeDeprecationNote($symbol);
3401 my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
3402 my $parameters_output = 0;
3404 $AllSymbols{$symbol} = 1;
3405 if (defined ($SymbolDocs{$symbol})) {
3406 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3408 # Try to insert the parameter table at the author's desired
3409 # position. Otherwise we need to tag it onto the end.
3410 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
3411 $parameters_output = 1;
3413 $desc .= $symbol_docs;
3415 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
3416 $AllDocumentedSymbols{$symbol} = 1;
3420 if ($parameters_output == 0) {
3421 $desc .= $parameters;
3423 $desc .= OutputSymbolTraits ($symbol);
3424 $desc .= "</refsect2>";
3427 return ($synop, $desc);
3431 #############################################################################
3432 # Function : GetArgs
3433 # Description : Returns the synopsis and detailed description DocBook output
3434 # for the Args of a given GtkObject subclass.
3435 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
3436 #############################################################################
3442 my $child_synop = "";
3443 my $child_desc = "";
3444 my $style_synop = "";
3445 my $style_desc = "";
3448 for ($i = 0; $i <= $#ArgObjects; $i++) {
3449 if ($ArgObjects[$i] eq $object) {
3450 #print "Found arg: $ArgNames[$i]\n";
3451 my $name = $ArgNames[$i];
3452 my $flags = $ArgFlags[$i];
3453 my $flags_string = "";
3457 if ($flags =~ m/c/) {
3458 $kind = "child property";
3461 elsif ($flags =~ m/s/) {
3462 $kind = "style property";
3469 # Remember only one colon so we don't clash with signals.
3470 my $symbol = "${object}:${name}";
3471 # use two dashes and ev. an extra separator here for the same reason.
3472 my $id = &CreateValidSGMLID ("$object--$id_sep$name");
3474 my $type = $ArgTypes[$i];
3476 my $range = $ArgRanges[$i];
3477 my $range_output = CreateValidSGML ($range);
3478 my $default = $ArgDefaults[$i];
3479 my $default_output = CreateValidSGML ($default);
3481 if ($type eq "GtkString") {
3484 if ($type eq "GtkSignal") {
3485 $type = "GtkSignalFunc, gpointer";
3486 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
3487 . &MakeXRef ("gpointer");
3488 } elsif ($type =~ m/^(\w+)\*$/) {
3489 $type_output = &MakeXRef ($1, &tagify($1, "type")) . "*";
3491 $type_output = &MakeXRef ($type, &tagify($type, "type"));
3494 if ($flags =~ m/r/) {
3495 $flags_string = "Read";
3497 if ($flags =~ m/w/) {
3498 if ($flags_string) { $flags_string .= " / "; }
3499 $flags_string .= "Write";
3501 if ($flags =~ m/x/) {
3502 if ($flags_string) { $flags_string .= " / "; }
3503 $flags_string .= "Construct";
3505 if ($flags =~ m/X/) {
3506 if ($flags_string) { $flags_string .= " / "; }
3507 $flags_string .= "Construct Only";
3510 $AllSymbols{$symbol} = 1;
3512 if (defined($SymbolDocs{$symbol}) &&
3513 !IsEmptyDoc($SymbolDocs{$symbol})) {
3514 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3515 #print ".. [$SymbolDocs{$symbol}][$blurb]\n";
3516 $AllDocumentedSymbols{$symbol} = 1;
3519 if (!($ArgBlurbs[$i] eq "")) {
3520 $AllDocumentedSymbols{$symbol} = 1;
3522 # FIXME: print a warning?
3523 #print ".. no description\n";
3525 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
3528 my $pad1 = " " x (24 - length ($name));
3529 my $pad2 = " " x (20 - length ($type));
3531 my $arg_synop = " "<link linkend=\"$id\">$name</link>"$pad1 $type_output $pad2 : $flags_string\n";
3532 my $arg_desc = "<refsect2 id=\"$id\" role=\"property\"><title>The <literal>"$name"</literal> $kind</title>\n";
3533 $arg_desc .= MakeIndexterms($symbol, $id);
3535 $arg_desc .= OutputSymbolExtraLinks($symbol);
3537 $arg_desc .= "<programlisting> "$name"$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
3538 $arg_desc .= &MakeDeprecationNote($symbol);
3539 $arg_desc .= $blurb;
3541 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
3543 if ($default ne "") {
3544 $arg_desc .= "<para>Default value: $default_output</para>\n";
3546 $arg_desc .= OutputSymbolTraits ($symbol);
3547 $arg_desc .= "</refsect2>\n";
3549 if ($flags =~ m/c/) {
3550 $child_synop .= $arg_synop;
3551 $child_desc .= $arg_desc;
3553 elsif ($flags =~ m/s/) {
3554 $style_synop .= $arg_synop;
3555 $style_desc .= $arg_desc;
3558 $synop .= $arg_synop;
3563 return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
3567 #############################################################################
3568 # Function : ReadSourceDocumentation
3569 # Description : This reads in the documentation embedded in comment blocks
3570 # in the source code (for Gnome).
3572 # Parameter descriptions override any in the template files.
3573 # Function descriptions are placed before any description from
3574 # the template files.
3576 # It recursively descends the source directory looking for .c
3577 # files and scans them looking for specially-formatted comment
3580 # Arguments : $source_dir - the directory to scan.
3581 #############m###############################################################
3583 sub ReadSourceDocumentation {
3584 my ($source_dir) = @_;
3585 my ($file, $dir, @suffix_list, $suffix);
3586 #print "Scanning source directory: $source_dir\n";
3588 # This array holds any subdirectories found.
3591 @suffix_list = split (/,/, $SOURCE_SUFFIXES);
3593 opendir (SRCDIR, $source_dir)
3594 || die "Can't open source directory $source_dir: $!";
3596 foreach $file (readdir (SRCDIR)) {
3597 if ($file =~ /^\./) {
3599 } elsif (-d "$source_dir/$file") {
3600 push (@subdirs, $file);
3601 } elsif (@suffix_list) {
3602 foreach $suffix (@suffix_list) {
3603 if ($file =~ m/\.\Q${suffix}\E$/) {
3604 &ScanSourceFile ("$source_dir/$file");
3607 } elsif ($file =~ m/\.[ch]$/) {
3608 &ScanSourceFile ("$source_dir/$file");
3613 # Now recursively scan the subdirectories.
3614 foreach $dir (@subdirs) {
3615 next if ($IGNORE_FILES =~ m/(\s|^)\Q${dir}\E(\s|$)/);
3616 &ReadSourceDocumentation ("$source_dir/$dir");
3621 #############################################################################
3622 # Function : ScanSourceFile
3623 # Description : Scans one source file looking for specially-formatted comment
3624 # blocks. Later &MergeSourceDocumentation is used to merge any
3625 # documentation found with the documentation already read in
3626 # from the template files.
3628 # Arguments : $file - the file to scan.
3629 #############################################################################
3631 sub ScanSourceFile {
3635 if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
3638 &LogWarning ($file, 1, "Can't find basename for this filename.");
3642 # Check if the basename is in the list of files to ignore.
3643 if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
3647 #print "DEBUG: Scanning $file\n";
3649 open (SRCFILE, $file)
3650 || die "Can't open $file: $!";
3651 my $in_comment_block = 0;
3653 my ($in_description, $in_return, $in_since, $in_stability, $in_deprecated);
3654 my ($description, $return_desc, $return_start, $return_style);
3655 my ($since_desc, $stability_desc, $deprecated_desc);
3657 my $ignore_broken_returns;
3660 # Look for the start of a comment block.
3661 if (!$in_comment_block) {
3662 if (m%^\s*/\*.*\*/%) {
3663 #one-line comment - not gtkdoc
3664 } elsif (m%^\s*/\*\*\s%) {
3665 #print "Found comment block start\n";
3667 $in_comment_block = 1;
3669 # Reset all the symbol data.
3671 $in_description = 0;
3680 $deprecated_desc = "";
3681 $stability_desc = "";
3682 $current_param = -1;
3683 $ignore_broken_returns = 0;
3689 # We're in a comment block. Check if we've found the end of it.
3692 # maybe its not even meant to be a gtk-doc comment?
3693 &LogWarning ($file, $., "Symbol name not found at the start of the comment block.");
3695 # Add the return value description onto the end of the params.
3697 push (@params, "Returns");
3698 push (@params, $return_desc);
3699 if ($return_style eq 'broken') {
3700 &LogWarning ($file, $., "Free-form return value description in $symbol. Use `Returns:' to avoid ambiguities.");
3703 # Convert special SGML characters
3704 $description = &ConvertSGMLChars ($symbol, $description);
3706 for ($k = 1; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3707 $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
3710 # Handle Section docs
3711 if ($symbol =~ m/SECTION:\s*(.*)/) {
3715 if (scalar %KnownSymbols) {
3716 if ((! defined($KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"})) || $KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"} != 1) {
3717 &LogWarning ($file, $., "Section $real_symbol is not defined in the $MODULE-section.txt file.");
3721 #print "SECTION DOCS found in source for : '$real_symbol'\n";
3722 $ignore_broken_returns = 1;
3723 for ($k = 0; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3724 #print " '".$params[$k]."'\n";
3725 $params[$k] = "\L$params[$k]";
3727 if ($params[$k] eq "short_description") {
3728 $key = "$TMPL_DIR/$real_symbol:Short_Description";
3729 } elsif ($params[$k] eq "see_also") {
3730 $key = "$TMPL_DIR/$real_symbol:See_Also";
3731 } elsif ($params[$k] eq "title") {
3732 $key = "$TMPL_DIR/$real_symbol:Title";
3733 } elsif ($params[$k] eq "stability") {
3734 $key = "$TMPL_DIR/$real_symbol:Stability_Level";
3735 } elsif ($params[$k] eq "section_id") {
3736 $key = "$TMPL_DIR/$real_symbol:Section_Id";
3737 } elsif ($params[$k] eq "include") {
3738 $key = "$TMPL_DIR/$real_symbol:Include";
3739 } elsif ($params[$k] eq "image") {
3740 $key = "$TMPL_DIR/$real_symbol:Image";
3742 if (defined($key)) {
3743 $SourceSymbolDocs{$key}=$params[$k+1];
3744 $SourceSymbolSourceFile{$key} = $file;
3745 $SourceSymbolSourceLine{$key} = $.;
3748 $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
3749 $SourceSymbolSourceFile{"$TMPL_DIR/$real_symbol:Long_Description"} = $file;
3750 $SourceSymbolSourceLine{"$TMPL_DIR/$real_symbol:Long_Description"} = $.;
3751 #$SourceSymbolTypes{$symbol} = "SECTION";
3753 #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
3754 $SourceSymbolDocs{$symbol} = $description;
3755 $SourceSymbolParams{$symbol} = [ @params ];
3756 # FIXME $SourceSymbolTypes{$symbol} = "STRUCT,SIGNAL,ARG,FUNCTION,MACRO";
3757 #if (defined $DeclarationTypes{$symbol}) {
3758 # $SourceSymbolTypes{$symbol} = $DeclarationTypes{$symbol}
3760 $SourceSymbolSourceFile{$symbol} = $file;
3761 $SourceSymbolSourceLine{$symbol} = $.;
3765 ($since_desc, my @extra_lines) = split ("\n", $since_desc);
3766 $since_desc =~ s/^\s+//;
3767 $since_desc =~ s/\s+$//;
3768 #print "Since($symbol) : [$since_desc]\n";
3769 $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
3770 if(scalar @extra_lines) {
3771 &LogWarning ($file, $., "multi-line since docs found");
3775 if ($stability_desc) {
3776 $stability_desc = &ParseStabilityLevel($stability_desc, $file, $., "Stability level for $symbol");
3777 $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
3780 if ($deprecated_desc) {
3781 if (exists $Deprecated{$symbol}) {
3784 # don't warn for signals and properties
3785 #if ($symbol !~ m/::?(.*)/) {
3786 if (defined $DeclarationTypes{$symbol}) {
3787 &LogWarning ($file, $.,
3788 "$symbol is deprecated in the inline comments, but no deprecation guards were found around the declaration.".
3789 " (See the --deprecated-guards option for gtkdoc-scan.)");
3792 $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
3796 $in_comment_block = 0;
3800 # Get rid of ' * ' at start of every line in the comment block.
3802 # But make sure we don't get rid of the newline at the end.
3806 #print "DEBUG: scanning :$_";
3808 # If we haven't found the symbol name yet, look for it.
3810 if (m%^\s*(SECTION:\s*\S+)%) {
3812 #print "SECTION DOCS found in source for : '$symbol'\n";
3813 $ignore_broken_returns = 1;
3814 } elsif (m%^\s*([\w:-]*\w)\s*:?\s*(\([a-z ]+\)\s*)*$%) {
3816 #print "SYMBOL DOCS found in source for : '$symbol'\n";
3821 # If we're in the return value description, add it to the end.
3823 # If we find another valid returns line, we assume that the first
3824 # one was really part of the description.
3825 if (m/^\s*(returns:|return\s+value:)/i) {
3826 if ($return_style eq 'broken') {
3827 $description .= $return_start . $return_desc;
3830 if ($return_style eq 'sane') {
3831 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3833 $return_style = 'sane';
3834 $ignore_broken_returns = 1;
3836 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3837 $description .= $return_start . $return_desc;
3839 $return_style = 'broken';
3841 } elsif (m%^\s*since:%i) {
3845 } elsif (m%^\s*stability:%i) {
3846 $stability_desc = $';
3849 } elsif (m%^\s*deprecated:%i) {
3850 $deprecated_desc = $';
3860 if (m/^\s*(returns:|return\s+value:)/i) {
3861 if ($return_style eq 'broken') {
3862 $description .= $return_start . $return_desc;
3865 if ($return_style eq 'sane') {
3866 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3868 $return_style = 'sane';
3869 $ignore_broken_returns = 1;
3873 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3875 $return_style = 'broken';
3879 } elsif (m%^\s*deprecated:%i) {
3880 $deprecated_desc = $';
3883 } elsif (m%^\s*stability:%i) {
3884 $stability_desc = $';
3893 if ($in_stability) {
3894 if (m/^\s*(returns:|return\s+value:)/i) {
3895 if ($return_style eq 'broken') {
3896 $description .= $return_start . $return_desc;
3899 if ($return_style eq 'sane') {
3900 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3902 $return_style = 'sane';
3903 $ignore_broken_returns = 1;
3907 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3909 $return_style = 'broken';
3913 } elsif (m%^\s*deprecated:%i) {
3914 $deprecated_desc = $';
3917 } elsif (m%^\s*since:%i) {
3922 $stability_desc .= $_;
3927 if ($in_deprecated) {
3928 if (m/^\s*(returns:|return\s+value:)/i) {
3929 if ($return_style eq 'broken') {
3930 $description .= $return_start . $return_desc;
3933 if ($return_style eq 'sane') {
3934 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3936 $return_style = 'sane';
3937 $ignore_broken_returns = 1;
3941 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3943 $return_style = 'broken';
3947 } elsif (m%^\s*since:%i) {
3951 } elsif (m%^\s*stability:%i) {
3952 $stability_desc = $';
3956 $deprecated_desc .= $_;
3961 # If we're in the description part, check for the 'Returns:' line.
3962 # If that isn't found, add the text to the end.
3963 if ($in_description) {
3964 # Get rid of 'Description:'
3965 s%^\s*Description:%%;
3967 if (m/^\s*(returns:|return\s+value:)/i) {
3968 if ($return_style eq 'broken') {
3969 $description .= $return_start . $return_desc;
3972 if ($return_style eq 'sane') {
3973 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3975 $return_style = 'sane';
3976 $ignore_broken_returns = 1;
3980 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3982 $return_style = 'broken';
3986 } elsif (m%^\s*since:%i) {
3990 } elsif (m%^\s*deprecated:%i) {
3991 $deprecated_desc = $';
3994 } elsif (m%^\s*stability:%i) {
3995 $stability_desc = $';
4004 # We must be in the parameters. Check for the empty line below them.
4006 $in_description = 1;
4010 # Look for a parameter name.
4011 if (m%^\s*@(\S+)\s*:\s*%) {
4012 my $param_name = $1;
4013 my $param_desc = $';
4015 #print "Found parameter: $param_name\n";
4016 # Allow '...' as the Varargs parameter.
4017 if ($param_name eq "...") {
4018 $param_name = "Varargs";
4020 if ("\L$param_name" eq "returns") {
4021 $return_style = 'sane';
4022 $ignore_broken_returns = 1;
4024 push (@params, $param_name);
4025 push (@params, $param_desc);
4026 $current_param += $PARAM_FIELD_COUNT;
4030 # We must be in the middle of a parameter description, so add it on
4031 # to the last element in @params.
4032 if ($current_param == -1) {
4033 &LogWarning ($file, $., "Parsing comment block file : parameter expected.");
4035 $params[$#params] .= $_;
4041 #############################################################################
4042 # Function : OutputMissingDocumentation
4043 # Description : Outputs report of documentation coverage to a file
4046 #############################################################################
4048 sub OutputMissingDocumentation {
4049 my $old_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.txt";
4050 my $new_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.new";
4052 my $n_documented = 0;
4053 my $n_incomplete = 0;
4059 my $buffer_deprecated = "";
4060 my $buffer_descriptions = "";
4062 open(UNDOCUMENTED, ">$new_undocumented_file")
4063 || die "Can't create $new_undocumented_file";
4065 foreach $symbol (sort (keys (%AllSymbols))) {
4066 # FIXME: should we print LogWarnings for undocumented stuff?
4068 #my $ssfile = &GetSymbolSourceFile($symbol);
4069 #my $ssline = &GetSymbolSourceLine($symbol);
4070 #my $location = "defined at " . (defined($ssfile)?$ssfile:"?") . ":" . (defined($ssline)?$ssline:"0") . "\n";
4072 if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include|Section_Id|Image)/) {
4074 if (exists ($AllDocumentedSymbols{$symbol})) {
4076 if (exists ($AllIncompleteSymbols{$symbol})) {
4078 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4079 #$buffer .= "\t0: ".$location;
4081 } elsif (exists $Deprecated{$symbol}) {
4082 if (exists ($AllIncompleteSymbols{$symbol})) {
4084 $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4085 #$buffer .= "\t1a: ".$location;
4087 $buffer_deprecated .= $symbol . "\n";
4088 #$buffer .= "\t1b: ".$location;
4091 if (exists ($AllIncompleteSymbols{$symbol})) {
4093 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4094 #$buffer .= "\t2a: ".$location;
4096 $buffer .= $symbol . "\n";
4097 #$buffer .= "\t2b: ".$location;
4100 } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
4102 #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
4103 #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
4104 #print "%%%% $symbol : $len1,$len2\n";
4105 if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
4106 || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
4109 # cut off the leading namespace ($TMPL_DIR)
4110 $symbol =~ m/^.*\/(.*)$/;
4111 $buffer_descriptions .= $1 . "\n";
4116 $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
4121 $percent = ($n_documented / $total) * 100.0;
4124 printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
4125 print UNDOCUMENTED "$n_documented symbols documented.\n";
4126 print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
4127 print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
4129 print UNDOCUMENTED $buffer;
4130 close (UNDOCUMENTED);
4132 return &UpdateFileIfChanged ($old_undocumented_file, $new_undocumented_file, 0);
4134 printf "%.0f%% symbol docs coverage", $percent;
4135 print "($n_documented symbols documented, $n_incomplete symbols incomplete, " . ($total - $n_documented) . " not documented)\n";
4136 print "See $MODULE-undocumented.txt for a list of missing docs.\nThe doc coverage percentage doesn't include intro sections.\n";
4140 #############################################################################
4141 # Function : OutputUndeclaredSymbols
4142 # Description : Outputs symbols that are listed in the section file, but not
4143 # declaration is found in the sources
4146 #############################################################################
4148 sub OutputUndeclaredSymbols {
4149 my $old_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.txt";
4150 my $new_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.new";
4152 open(UNDECLARED, ">$new_undeclared_file")
4153 || die "Can't create $new_undeclared_file";
4155 if (%UndeclaredSymbols) {
4156 print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
4157 print UNDECLARED "\n";
4158 print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
4162 return &UpdateFileIfChanged ($old_undeclared_file, $new_undeclared_file, 0);
4165 #############################################################################
4166 # Function : OutputUnusedSymbols
4167 # Description : Outputs symbols that are documented in comments, but not
4168 # declared in the sources
4171 #############################################################################
4173 sub OutputUnusedSymbols {
4175 my $old_unused_file = "$ROOT_DIR/$MODULE-unused.txt";
4176 my $new_unused_file = "$ROOT_DIR/$MODULE-unused.new";
4178 open (UNUSED, ">$new_unused_file")
4179 || die "Can't open $new_unused_file";
4181 foreach $symbol (sort keys (%Declarations)) {
4182 if (!defined ($DeclarationOutput{$symbol})) {
4183 print (UNUSED "$symbol\n");
4187 foreach $symbol (sort (keys (%AllUnusedSymbols))) {
4188 print (UNUSED "$symbol(" . $AllUnusedSymbols{$symbol} . ")\n");
4192 if ($num_unused != 0) {
4193 &LogWarning ($old_unused_file, 1, "$num_unused unused declarations.".
4194 "They should be added to $MODULE-sections.txt in the appropriate place.");
4197 return &UpdateFileIfChanged ($old_unused_file, $new_unused_file, 0);
4201 #############################################################################
4202 # Function : OutputAllSymbols
4203 # Description : Outputs list of all symbols to a file
4206 #############################################################################
4208 sub OutputAllSymbols {
4209 my $n_documented = 0;
4215 open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
4216 || die "Can't create $ROOT_DIR/$MODULE-symbols.txt: $!";
4218 foreach $symbol (sort (keys (%AllSymbols))) {
4219 print SYMBOLS $symbol . "\n";
4225 #############################################################################
4226 # Function : OutputSymbolsWithoutSince
4227 # Description : Outputs list of all symbols without a since tag to a file
4230 #############################################################################
4232 sub OutputSymbolsWithoutSince {
4233 my $n_documented = 0;
4239 open (SYMBOLS, ">$ROOT_DIR/$MODULE-nosince.txt")
4240 || die "Can't create $ROOT_DIR/$MODULE-nosince.txt: $!";
4242 foreach $symbol (sort (keys (%SourceSymbolDocs))) {
4243 if (!defined $Since{$symbol}) {
4244 print SYMBOLS $symbol . "\n";
4252 #############################################################################
4253 # Function : MergeSourceDocumentation
4254 # Description : This merges documentation read from a source file into the
4255 # documentation read in from a template file.
4257 # Parameter descriptions override any in the template files.
4258 # Function descriptions are placed before any description from
4259 # the template files.
4262 #############################################################################
4264 sub MergeSourceDocumentation {
4268 if (scalar %SymbolDocs) {
4269 @Symbols=keys (%SymbolDocs);
4270 #print "num existing entries: ".(scalar @Symbols)."\n";
4271 #print " ",$Symbols[0], " ",$Symbols[1],"\n";
4274 # filter scanned declarations, with what we suppress from -sections.txt
4276 foreach $symbol (keys (%Declarations)) {
4277 if (defined($KnownSymbols{$symbol}) && $KnownSymbols{$symbol} == 1) {
4281 # , add the rest from -sections.txt
4282 foreach $symbol (keys (%KnownSymbols)) {
4283 if ($KnownSymbols{$symbol} == 1) {
4287 # and add whats found in the source
4288 foreach $symbol (keys (%SourceSymbolDocs)) {
4291 @Symbols = keys (%tmp);
4292 #print "num source entries: ".(scalar @Symbols)."\n";
4294 foreach $symbol (@Symbols) {
4295 $AllSymbols{$symbol} = 1;
4297 my $have_tmpl_docs = 0;
4299 ## See if the symbol is documented in template
4300 my $tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4301 my $check_tmpl_doc =$tmpl_doc;
4302 # remove all xml-tags and whitespaces (don't kill <include href="..."> tags)
4303 $check_tmpl_doc =~ s/<\/?[a-z]+>//gi;
4304 $check_tmpl_doc =~ s/\s//g;
4306 if ($check_tmpl_doc ne "") {
4307 $have_tmpl_docs = 1;
4308 #print "## [$check_tmpl_doc]\n";
4313 if (exists ($SourceSymbolDocs{$symbol})) {
4314 my $type = $DeclarationTypes {$symbol};
4316 #print "merging [$symbol] from source\n";
4318 my $item = "Parameter";
4319 if (defined ($type)) {
4320 if ($type eq 'STRUCT') {
4322 } elsif ($type eq 'ENUM') {
4324 } elsif ($type eq 'UNION') {
4331 my $src_doc = $SourceSymbolDocs{$symbol};
4332 # remove leading and training whitespaces
4333 $src_doc =~ s/^\s+//;
4334 $src_doc =~ s/\s+$//;
4336 # Don't output warnings for overridden titles as titles are
4337 # automatically generated in the -sections.txt file, and thus they
4338 # are often overridden.
4339 if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
4340 # check if content is different
4341 if ($tmpl_doc ne $src_doc) {
4342 #print "[$tmpl_doc] [$src_doc]\n";
4343 &LogWarning ($SourceSymbolSourceFile{$symbol}, $SourceSymbolSourceLine{$symbol},
4344 "Documentation in template ".$SymbolSourceFile{$symbol}.":".$SymbolSourceLine{$symbol}." for $symbol being overridden by inline comments.");
4348 if ($src_doc ne "") {
4349 $AllDocumentedSymbols{$symbol} = 1;
4352 # Convert <!--PARAMETERS--> with any blank lines around it to
4353 # a </para> followed by <!--PARAMETERS--> followed by <para>.
4354 $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
4356 # Do not add <para> to nothing, it breaks missing docs checks.
4357 my $src_doc_para = "";
4358 if ($src_doc ne "") {
4359 # If there is a blank line, finish the paragraph and start another.
4360 $src_doc = &ConvertBlankLines ($src_doc, $symbol);
4361 $src_doc_para = "<para>\n$src_doc\n</para>";
4363 # FIXME: this is questionable, as we can't make assumtions on the content really
4364 #$src_doc_para =~ s%^<para>\n(<refsect[1-9])%$1%gms;
4365 #$src_doc_para =~ s%^<para>\n<para>%<para>%gms;
4366 #$src_doc_para =~ s%(</refsect[1-9]>)\n</para>$%$1%gms;
4367 #print "$symbol : [$src_doc][$src_doc_para]\n";
4370 if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
4371 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4372 } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
4373 # For the title/summary/see also section docs we don't want to
4374 # add any <para> tags.
4375 $SymbolDocs{$symbol} = "$src_doc"
4377 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4381 if ($symbol =~ m/.*::.*/) {
4382 # For signals we prefer the param names from the source docs,
4383 # since the ones from the templates are likely to contain the
4384 # artificial argn names which are generated by gtkdoc-scangobj.
4385 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4386 # FIXME: we need to check for empty docs here as well!
4388 # The templates contain the definitive parameter names and order,
4389 # so we will not change that. We only override the actual text.
4390 my $tmpl_params = $SymbolParams{$symbol};
4391 if (!defined ($tmpl_params)) {
4392 #print "No merge needed for $symbol\n";
4393 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4394 # FIXME: we still like to get the number of params and merge
4395 # 1) we would noticed that params have been removed/renamed
4396 # 2) we would catch undocumented params
4397 # params are not (yet) exported in -decl.txt so that we
4398 # could easily grab them :/
4400 my $params = $SourceSymbolParams{$symbol};
4402 #print "Merge needed for $symbol, tmpl_params: ",$#$tmpl_params,", source_params: ",$#$params," \n";
4403 for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4404 my $tmpl_param_name = $$tmpl_params[$j];
4406 # Allow '...' as the Varargs parameter.
4407 if ($tmpl_param_name eq "...") {
4408 $tmpl_param_name = "Varargs";
4411 # Try to find the param in the source comment documentation.
4414 #print " try merge param $tmpl_param_name\n";
4415 for ($k = 0; $k <= $#$params; $k += $PARAM_FIELD_COUNT) {
4416 my $param_name = $$params[$k];
4417 my $param_desc = $$params[$k + 1];
4419 #print " test param $param_name\n";
4420 # We accept changes in case, since the Gnome source
4421 # docs contain a lot of these.
4422 if ("\L$param_name" eq "\L$tmpl_param_name") {
4425 # Override the description.
4426 $$tmpl_params[$j + 1] = $param_desc;
4428 # Set the name to "" to mark it as used.
4434 # If it looks like the parameters are there, but not
4435 # in the right place, try to explain a bit better.
4436 if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
4437 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4438 "Parameters for $symbol must start on the line immediately after the function or macro name.");
4442 # Now we output a warning if parameters have been described which
4444 for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
4445 my $param_name = $$params[$j];
4447 # the template builder cannot detect if a macro returns
4449 if(($type eq "MACRO") && ($param_name eq "Returns")) {
4450 # FIXME: do we need to add it then to tmpl_params[] ?
4451 my $num=$#$tmpl_params;
4452 #print " adding Returns: to macro docs for $symbol.\n";
4453 $$tmpl_params[$num+1]="Returns";
4454 $$tmpl_params[$num+2]=$$params[$j+1];
4457 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4458 "$item described in source code comment block but does not exist. $type: $symbol $item: $param_name.");
4464 if ($have_tmpl_docs) {
4465 $AllDocumentedSymbols{$symbol} = 1;
4466 #print "merging [$symbol] from template\n";
4469 #print "[$symbol] undocumented\n";
4473 # if this symbol is documented, check if docs are complete
4474 $check_tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4475 # remove all xml-tags and whitespaces
4476 #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
4477 $check_tmpl_doc =~ s/<.*?>//g;
4478 $check_tmpl_doc =~ s/\s//g;
4479 if ($check_tmpl_doc ne "") {
4480 my $tmpl_params = $SymbolParams{$symbol};
4481 if (defined ($tmpl_params)) {
4482 my $type = $DeclarationTypes {$symbol};
4484 my $item = "Parameter";
4485 if (defined ($type)) {
4486 if ($type eq 'STRUCT') {
4488 } elsif ($type eq 'ENUM') {
4490 } elsif ($type eq 'UNION') {
4497 #print "Check param docs for $symbol, tmpl_params: ",$#$tmpl_params," entries, type=$type\n";
4499 if ($#$tmpl_params > 0) {
4501 for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4502 # Output a warning if the parameter is empty and
4503 # remember for stats.
4504 my $tmpl_param_name = $$tmpl_params[$j];
4505 my $tmpl_param_desc = $$tmpl_params[$j + 1];
4506 if ($tmpl_param_name ne "void" && $tmpl_param_desc !~ m/\S/) {
4507 if (exists ($AllIncompleteSymbols{$symbol})) {
4508 $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
4510 $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
4512 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4513 "$item description for $symbol"."::"."$tmpl_param_name is missing in source code comment block.");
4518 if ($#$tmpl_params == 0) {
4519 $AllIncompleteSymbols{$symbol}="<items>";
4520 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4521 "$item descriptions for $symbol are missing in source code comment block.");
4523 # $#$tmpl_params==-1 means we don't know about parameters
4524 # this unfortunately does not tell if there should be some
4529 #print "num doc entries: ".(scalar %SymbolDocs)."\n";
4532 #############################################################################
4533 # Function : IsEmptyDoc
4534 # Description : Check if a doc-string is empty. Its also regarded as empty if
4535 # it only consist of whitespace or e.g. FIXME.
4536 # Arguments : the doc-string
4537 #############################################################################
4541 if ($doc =~ /^\s*$/) {
4545 if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
4553 # This converts blank lines to "</para><para>", but only outside CDATA and
4554 # <programlisting> tags.
4555 sub ConvertBlankLines {
4556 return &ModifyXMLElements ($_[0], $_[1],
4557 "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
4558 \&ConvertBlankLinesEndTag,
4559 \&ConvertBlankLinesCallback);
4563 sub ConvertBlankLinesEndTag {
4564 if ($_[0] eq "<!\[CDATA\[") {
4566 } elsif ($_[0] eq "|[") {
4569 return "</programlisting>";
4573 sub ConvertBlankLinesCallback {
4574 my ($text, $symbol, $tag) = @_;
4576 # If we're not in CDATA or a <programlisting> we convert blank lines so
4577 # they start a new <para>.
4579 $text =~ s%\n{2,}%\n</para>\n<para>\n%g;
4586 #############################################################################
4587 # LIBRARY FUNCTIONS - These functions are used in both gtkdoc-mkdb and
4588 # gtkdoc-mktmpl and should eventually be moved to a
4590 #############################################################################
4592 #############################################################################
4593 # Function : ReadDeclarationsFile
4594 # Description : This reads in a file containing the function/macro/enum etc.
4597 # Note that in some cases there are several declarations with
4598 # the same name, e.g. for conditional macros. In this case we
4599 # set a flag in the %DeclarationConditional hash so the
4600 # declaration is not shown in the docs.
4602 # If a macro and a function have the same name, e.g. for
4603 # gtk_object_ref, the function declaration takes precedence.
4605 # Some opaque structs are just declared with 'typedef struct
4606 # _name name;' in which case the declaration may be empty.
4607 # The structure may have been found later in the header, so
4608 # that overrides the empty declaration.
4610 # Arguments : $file - the declarations file to read
4611 # $override - if declarations in this file should override
4612 # any current declaration.
4613 #############################################################################
4615 sub ReadDeclarationsFile {
4616 my ($file, $override) = @_;
4618 if ($override == 0) {
4620 %DeclarationTypes = ();
4621 %DeclarationConditional = ();
4622 %DeclarationOutput = ();
4626 || die "Can't open $file: $!";
4627 my $declaration_type = "";
4628 my $declaration_name;
4630 my $is_deprecated = 0;
4632 if (!$declaration_type) {
4633 if (m/^<([^>]+)>/) {
4634 $declaration_type = $1;
4635 $declaration_name = "";
4636 #print "Found declaration: $declaration_type\n";
4640 if (m%^<NAME>(.*)</NAME>%) {
4641 $declaration_name = $1;
4642 } elsif (m%^<DEPRECATED/>%) {
4644 } elsif (m%^</$declaration_type>%) {
4645 #print "Found end of declaration: $declaration_name\n";
4646 # Check that the declaration has a name
4647 if ($declaration_name eq "") {
4648 print "ERROR: $declaration_type has no name $file:$.\n";
4651 # If the declaration is an empty typedef struct _XXX XXX
4652 # set the flag to indicate the struct has a typedef.
4653 if ($declaration_type eq 'STRUCT'
4654 && $declaration =~ m/^\s*$/) {
4655 #print "Struct has typedef: $declaration_name\n";
4656 $StructHasTypedef{$declaration_name} = 1;
4659 # Check if the symbol is already defined.
4660 if (defined ($Declarations{$declaration_name})
4661 && $override == 0) {
4662 # Function declarations take precedence.
4663 if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
4665 } elsif ($declaration_type eq 'FUNCTION') {
4666 if ($is_deprecated) {
4667 $Deprecated{$declaration_name} = "";
4669 $Declarations{$declaration_name} = $declaration;
4670 $DeclarationTypes{$declaration_name} = $declaration_type;
4671 } elsif ($DeclarationTypes{$declaration_name}
4672 eq $declaration_type) {
4673 # If the existing declaration is empty, or is just a
4674 # forward declaration of a struct, override it.
4675 if ($declaration_type eq 'STRUCT') {
4676 if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4677 if ($is_deprecated) {
4678 $Deprecated{$declaration_name} = "";
4680 $Declarations{$declaration_name} = $declaration;
4681 } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4682 # Ignore an empty or forward declaration.
4684 &LogWarning ($file, $., "Structure $declaration_name has multiple definitions.");
4687 # set flag in %DeclarationConditional hash for
4688 # multiply defined macros/typedefs.
4689 $DeclarationConditional{$declaration_name} = 1;
4692 &LogWarning ($file, $., "$declaration_name has multiple definitions.");
4695 if ($is_deprecated) {
4696 $Deprecated{$declaration_name} = "";
4698 $Declarations{$declaration_name} = $declaration;
4699 $DeclarationTypes{$declaration_name} = $declaration_type;
4702 $declaration_type = "";
4713 #############################################################################
4714 # Function : ReadSignalsFile
4715 # Description : This reads in an existing file which contains information on
4716 # all GTK signals. It creates the arrays @SignalNames and
4717 # @SignalPrototypes containing info on the signals. The first
4718 # line of the SignalPrototype is the return type of the signal
4719 # handler. The remaining lines are the parameters passed to it.
4720 # The last parameter, "gpointer user_data" is always the same
4721 # so is not included.
4722 # Arguments : $file - the file containing the signal handler prototype
4724 #############################################################################
4726 sub ReadSignalsFile {
4734 my $signal_prototype;
4736 # Reset the signal info.
4737 @SignalObjects = ();
4739 @SignalReturns = ();
4741 @SignalPrototypes = ();
4746 if (!open (INPUT, $file)) {
4747 warn "Can't open $file - skipping signals\n";
4754 $signal_object = "";
4756 $signal_returns = "";
4757 $signal_prototype = "";
4760 if (m/^<NAME>(.*)<\/NAME>/) {
4762 if ($signal_name =~ m/^(.*)::(.*)$/) {
4763 $signal_object = $1;
4764 ($signal_name = $2) =~ s/_/-/g;
4765 #print "Found signal: $signal_name\n";
4767 &LogWarning ($file, $., "Invalid signal name: $signal_name.");
4769 } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
4770 $signal_returns = $1;
4771 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4773 } elsif (m%^</SIGNAL>%) {
4774 #print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
4775 push (@SignalObjects, $signal_object);
4776 push (@SignalNames, $signal_name);
4777 push (@SignalReturns, $signal_returns);
4778 push (@SignalFlags, $signal_flags);
4779 push (@SignalPrototypes, $signal_prototype);
4782 $signal_prototype .= $_;
4790 #############################################################################
4791 # Function : ReadTemplateFile
4792 # Description : This reads in the manually-edited documentation file
4793 # corresponding to the file currently being created, so we can
4794 # insert the documentation at the appropriate places.
4795 # It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
4796 # is a hash of arrays.
4797 # NOTE: This function is duplicated in gtkdoc-mktmpl (but
4798 # slightly different).
4799 # Arguments : $docsfile - the template file to read in.
4800 # $skip_unused_params - 1 if the unused parameters should be
4802 #############################################################################
4804 sub ReadTemplateFile {
4805 my ($docsfile, $skip_unused_params) = @_;
4807 my $template = "$docsfile.sgml";
4808 if (! -f $template) {
4809 #print "File doesn't exist: $template\n";
4812 #print "Reading $template\n";
4814 # start with empty hashes, we merge the source comment for each file
4820 my $current_type = ""; # Type of symbol being read.
4821 my $current_symbol = ""; # Name of symbol being read.
4822 my $symbol_doc = ""; # Description of symbol being read.
4823 my @params; # Parameter names and descriptions of current
4824 # function/macro/function typedef.
4825 my $current_param = -1; # Index of parameter currently being read.
4826 # Note that the param array contains pairs
4827 # of param name & description.
4828 my $in_unused_params = 0; # True if we are reading in the unused params.
4829 my $in_deprecated = 0;
4831 my $in_stability = 0;
4833 open (DOCS, "$template")
4834 || die "Can't open $template: $!";
4836 if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
4839 if ($symbol eq "Title"
4840 || $symbol eq "Short_Description"
4841 || $symbol eq "Long_Description"
4842 || $symbol eq "See_Also"
4843 || $symbol eq "Stability_Level"
4844 || $symbol eq "Include"
4845 || $symbol eq "Image") {
4847 $symbol = $docsfile . ":" . $symbol;
4850 #print "Found symbol: $symbol\n";
4851 # Remember file and line for the symbol
4852 $SymbolSourceFile{$symbol} = $template;
4853 $SymbolSourceLine{$symbol} = $.;
4855 # Store previous symbol, but remove any trailing blank lines.
4856 if ($current_symbol ne "") {
4857 $symbol_doc =~ s/\s+$//;
4858 $SymbolTypes{$current_symbol} = $current_type;
4859 $SymbolDocs{$current_symbol} = $symbol_doc;
4861 # Check that the stability level is valid.
4862 if ($StabilityLevel{$current_symbol}) {
4863 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4866 if ($current_param >= 0) {
4867 $SymbolParams{$current_symbol} = [ @params ];
4869 # Delete any existing params in case we are overriding a
4870 # previously read template.
4871 delete $SymbolParams{$current_symbol};
4874 $current_type = $type;
4875 $current_symbol = $symbol;
4876 $current_param = -1;
4877 $in_unused_params = 0;
4884 } elsif (m/^<!-- # Unused Parameters # -->/) {
4885 #print "DEBUG: Found unused parameters\n";
4886 $in_unused_params = 1;
4889 } elsif ($in_unused_params && $skip_unused_params) {
4890 # When outputting the DocBook we skip unused parameters.
4891 #print "DEBUG: Skipping unused param: $_";
4895 # Check if param found. Need to handle "..." and "format...".
4896 if (s/^\@([\w\.]+):\040?//) {
4897 my $param_name = $1;
4898 my $param_desc = $_;
4899 # Allow variations of 'Returns'
4900 if ($param_name =~ m/^[Rr]eturns?$/) {
4901 $param_name = "Returns";
4904 # strip trailing whitespaces and blank lines
4907 #print "Found param for symbol $current_symbol : '$param_name'= '$_'";
4909 if ($param_name eq "Deprecated") {
4911 $Deprecated{$current_symbol} = $_;
4912 } elsif ($param_name eq "Since") {
4915 $Since{$current_symbol} = $_;
4916 } elsif ($param_name eq "Stability") {
4918 $StabilityLevel{$current_symbol} = $_;
4920 push (@params, $param_name);
4921 push (@params, $param_desc);
4922 $current_param += $PARAM_FIELD_COUNT;
4925 # strip trailing whitespaces and blank lines
4930 if ($in_deprecated) {
4931 $Deprecated{$current_symbol} .= $_;
4932 } elsif ($in_since) {
4933 &LogWarning ($template, $., "multi-line since docs found");
4934 #$Since{$current_symbol} .= $_;
4935 } elsif ($in_stability) {
4936 $StabilityLevel{$current_symbol} .= $_;
4937 } elsif ($current_param >= 0) {
4938 $params[$current_param] .= $_;
4947 # Remember to finish the current symbol doccs.
4948 if ($current_symbol ne "") {
4950 $symbol_doc =~ s/\s+$//;
4951 $SymbolTypes{$current_symbol} = $current_type;
4952 $SymbolDocs{$current_symbol} = $symbol_doc;
4954 # Check that the stability level is valid.
4955 if ($StabilityLevel{$current_symbol}) {
4956 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4959 if ($current_param >= 0) {
4960 $SymbolParams{$current_symbol} = [ @params ];
4962 # Delete any existing params in case we are overriding a
4963 # previously read template.
4964 delete $SymbolParams{$current_symbol};
4973 #############################################################################
4974 # Function : ReadObjectHierarchy
4975 # Description : This reads in the $MODULE-hierarchy.txt file containing all
4976 # the GtkObject subclasses described in this module (and their
4978 # It places them in the @Objects array, and places their level
4979 # in the object hierarchy in the @ObjectLevels array, at the
4980 # same index. GtkObject, the root object, has a level of 1.
4982 # FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
4983 # as it goes along, this should be split out into a separate
4987 #############################################################################
4989 sub ReadObjectHierarchy {
4993 if (! -f $OBJECT_TREE_FILE) {
4996 if (!open (INPUT, $OBJECT_TREE_FILE)) {
4997 warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
5001 # FIXME: use $OUTPUT_FORMAT
5002 # my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.$OUTPUT_FORMAT";
5003 my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
5004 my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
5006 open (OUTPUT, ">$new_tree_index")
5007 || die "Can't create $new_tree_index: $!";
5009 if ($OUTPUT_FORMAT eq "xml") {
5010 my $tree_header = $doctype_header;
5012 $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
5013 print (OUTPUT "$tree_header");
5015 print (OUTPUT "<screen>\n");
5017 # Only emit objects if they are supposed to be documented, or if
5018 # they have documented children. To implement this, we maintain a
5019 # stack of pending objects which will be emitted if a documented
5021 my @pending_objects = ();
5022 my @pending_levels = ();
5026 my $level = (length($`)) / 2 + 1;
5029 while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
5030 my $pobject = pop(@pending_objects);
5031 my $plevel = pop(@pending_levels);
5034 push (@pending_objects, $object);
5035 push (@pending_levels, $level);
5037 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5038 while ($#pending_levels >= 0) {
5039 $object = shift @pending_objects;
5040 $level = shift @pending_levels;
5041 $xref = &MakeXRef ($object);
5043 print (OUTPUT ' ' x ($level * 4), "$xref\n");
5044 push (@Objects, $object);
5045 push (@ObjectLevels, $level);
5049 # LogWarning ($OBJECT_TREE_FILE, $., "unknown type $object");
5053 print (OUTPUT "</screen>\n");
5058 &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
5063 #############################################################################
5064 # Function : ReadInterfaces
5065 # Description : This reads in the $MODULE.interfaces file.
5068 #############################################################################
5070 sub ReadInterfaces {
5073 if (! -f $INTERFACES_FILE) {
5076 if (!open (INPUT, $INTERFACES_FILE)) {
5077 warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
5083 my ($object, @ifaces) = split;
5084 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5085 my @knownIfaces = ();
5087 # filter out private interfaces, but leave foreign interfaces
5088 foreach my $iface (@ifaces) {
5089 if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
5090 push (@knownIfaces, $iface);
5094 $Interfaces{$object} = join(' ', @knownIfaces);
5100 #############################################################################
5101 # Function : ReadPrerequisites
5102 # Description : This reads in the $MODULE.prerequisites file.
5105 #############################################################################
5107 sub ReadPrerequisites {
5108 %Prerequisites = ();
5110 if (! -f $PREREQUISITES_FILE) {
5113 if (!open (INPUT, $PREREQUISITES_FILE)) {
5114 warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
5120 my ($iface, @prereqs) = split;
5121 if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
5122 my @knownPrereqs = ();
5124 # filter out private prerequisites, but leave foreign prerequisites
5125 foreach my $prereq (@prereqs) {
5126 if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
5127 push (@knownPrereqs, $prereq);
5131 $Prerequisites{$iface} = join(' ', @knownPrereqs);
5137 #############################################################################
5138 # Function : ReadArgsFile
5139 # Description : This reads in an existing file which contains information on
5140 # all GTK args. It creates the arrays @ArgObjects, @ArgNames,
5141 # @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
5143 # Arguments : $file - the file containing the arg information.
5144 #############################################################################
5159 # Reset the args info.
5172 if (!open (INPUT, $file)) {
5173 warn "Can't open $file - skipping args\n";
5190 if (m/^<NAME>(.*)<\/NAME>/) {
5192 if ($arg_name =~ m/^(.*)::(.*)$/) {
5194 ($arg_name = $2) =~ s/_/-/g;
5195 #print "Found arg: $arg_name\n";
5197 &LogWarning ($file, $., "Invalid argument name: $arg_name");
5199 } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
5201 } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
5203 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
5205 } elsif (m/^<NICK>(.*)<\/NICK>/) {
5207 } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
5209 if ($arg_blurb eq "(null)") {
5211 &LogWarning ($file, $., "Property ${arg_object}:${arg_name} has no documentation.");
5213 } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
5215 } elsif (m%^</ARG>%) {
5216 #print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
5217 push (@ArgObjects, $arg_object);
5218 push (@ArgNames, $arg_name);
5219 push (@ArgTypes, $arg_type);
5220 push (@ArgRanges, $arg_range);
5221 push (@ArgFlags, $arg_flags);
5222 push (@ArgNicks, $arg_nick);
5223 push (@ArgBlurbs, $arg_blurb);
5224 push (@ArgDefaults, $arg_default);
5233 #############################################################################
5234 # Function : CheckIsObject
5235 # Description : Returns 1 if the given name is a GObject or a subclass.
5236 # It uses the global @Objects array.
5237 # Note that the @Objects array only contains classes in the
5238 # current module and their ancestors - not all GObject classes.
5239 # Arguments : $name - the name to check.
5240 #############################################################################
5246 foreach $object (@Objects) {
5247 if ($object eq $name) {
5255 #############################################################################
5256 # Function : MakeReturnField
5257 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
5258 # Arguments : $str - the string to pad.
5259 #############################################################################
5261 sub MakeReturnField {
5264 return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));
5267 #############################################################################
5268 # Function : GetSymbolSourceFile
5269 # Description : Get the filename where the symbol docs where taken from.
5270 # Arguments : $symbol - the symbol name
5271 #############################################################################
5273 sub GetSymbolSourceFile {
5276 if (defined($SourceSymbolSourceFile{$symbol})) {
5277 return $SourceSymbolSourceFile{$symbol};
5278 } elsif (defined($SymbolSourceFile{$symbol})) {
5279 return $SymbolSourceFile{$symbol};
5285 #############################################################################
5286 # Function : GetSymbolSourceLine
5287 # Description : Get the file line where the symbol docs where taken from.
5288 # Arguments : $symbol - the symbol name
5289 #############################################################################
5291 sub GetSymbolSourceLine {
5294 if (defined($SourceSymbolSourceLine{$symbol})) {
5295 return $SourceSymbolSourceLine{$symbol};
5296 } elsif (defined($SymbolSourceLine{$symbol})) {
5297 return $SymbolSourceLine{$symbol};