4 # gtk-doc - GTK DocBook documentation generator.
5 # Copyright (C) 1998 Damon Chaplin
6 # 2007,2008,2009 Stefan Kost
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #############################################################################
24 # Script : gtkdoc-mkdb
25 # Description : This creates the DocBook files from the edited templates.
26 #############################################################################
31 push @INC, '@PACKAGE_DATA_DIR@';
32 require "gtkdoc-common.pl";
36 # name of documentation module
41 my $SOURCE_SUFFIXES = "";
42 my $IGNORE_FILES = "";
46 my $EXPAND_CONTENT_FILES = "";
48 my $DEFAULT_STABILITY;
52 my $OUTPUT_ALL_SYMBOLS;
53 my $OUTPUT_SYMBOLS_WITHOUT_SINCE;
55 my %optctl = ('module' => \$MODULE,
56 'source-dir' => \@SOURCE_DIRS,
57 'source-suffixes' => \$SOURCE_SUFFIXES,
58 'ignore-files' => \$IGNORE_FILES,
59 'output-dir' => \$SGML_OUTPUT_DIR,
60 'tmpl-dir' => \$TMPL_DIR,
61 'version' => \$PRINT_VERSION,
62 'help' => \$PRINT_HELP,
63 'main-sgml-file' => \$MAIN_SGML_FILE,
64 'expand-content-files' => \$EXPAND_CONTENT_FILES,
65 'sgml-mode' => \$SGML_MODE,
66 'default-stability' => \$DEFAULT_STABILITY,
67 'default-includes' => \$DEFAULT_INCLUDES,
68 'output-format' => \$OUTPUT_FORMAT,
69 'name-space' => \$NAME_SPACE,
70 'outputallsymbols' => \$OUTPUT_ALL_SYMBOLS,
71 'outputsymbolswithoutsince' => \$OUTPUT_SYMBOLS_WITHOUT_SINCE
73 GetOptions(\%optctl, "module=s", "source-dir:s", "source-suffixes:s",
74 "ignore-files:s", "output-dir:s", "tmpl-dir:s", "version", "outputallsymbols",
75 "outputsymbolswithoutsince",
76 "expand-content-files:s", "main-sgml-file:s", "extra-db-files:s", "help",
77 "sgml-mode", "default-stability:s", "default-includes:s", "output-format:s",
89 if ($DEFAULT_STABILITY && $DEFAULT_STABILITY ne "Stable"
90 && $DEFAULT_STABILITY ne "Private" && $DEFAULT_STABILITY ne "Unstable") {
96 gtkdoc-mkdb version @VERSION@ - generate docbook files
98 --module=MODULE_NAME Name of the doc module being parsed
99 --source-dir=DIRNAME Directories which contain inline reference material
100 --source-suffixes=SUFFIXES Suffixes of source files to scan, comma-separated
101 --ignore-files=FILES Files or directories which should not be scanned
102 May be used more than once for multiple directories
103 --output-dir=DIRNAME Directory to put the generated DocBook files in
104 --tmpl-dir=DIRNAME Directory in which template files may be found
105 --main-sgml-file=FILE File containing the toplevel DocBook file.
106 --expand-content-files=FILES Extra DocBook files to expand abbreviations in.
107 --output-format=FORMAT Format to use for the generated docbook, XML or SGML.
108 --sgml-mode Allow DocBook markup in inline documentation.
109 --default-stability=LEVEL Specify default stability Level. Valid values are
110 Stable, Unstable, or Private.
111 --default-includes=FILENAMES Specify default includes for section Synopsis
112 --name-space=NS Omit namespace in index.
113 --version Print the version of this program
114 --help Print this help
119 my ($empty_element_end, $doctype_header);
121 # autodetect output format
122 if (! defined($OUTPUT_FORMAT) || ($OUTPUT_FORMAT eq "")) {
123 if (!$MAIN_SGML_FILE) {
124 if (-e "${MODULE}-docs.xml") {
125 $OUTPUT_FORMAT = "xml";
127 $OUTPUT_FORMAT = "sgml";
130 if ($MAIN_SGML_FILE =~ m/.*\.(.*ml)$/i) {
131 $OUTPUT_FORMAT = lc($1);
136 $OUTPUT_FORMAT = lc($OUTPUT_FORMAT);
139 #print "DEBUG: output-format: [$OUTPUT_FORMAT]\n";
141 if ($OUTPUT_FORMAT eq "xml") {
142 if (!$MAIN_SGML_FILE) {
143 # backwards compatibility
144 if (-e "${MODULE}-docs.sgml") {
145 $MAIN_SGML_FILE = "${MODULE}-docs.sgml";
147 $MAIN_SGML_FILE = "${MODULE}-docs.xml";
150 $empty_element_end = "/>";
152 if (-e $MAIN_SGML_FILE) {
153 open(INPUT, "<$MAIN_SGML_FILE") || die "Can't open $MAIN_SGML_FILE";
154 $doctype_header = "";
156 if (/^\s*<(book|chapter|article)/) {
157 # check that the top-level tag or the doctype decl contain the xinclude namespace decl
158 if (($_ !~ m/http:\/\/www.w3.org\/200[13]\/XInclude/) && ($doctype_header !~ m/http:\/\/www.w3.org\/200[13]\/XInclude/m)) {
159 $doctype_header = "";
163 $doctype_header .= $_;
168 "<?xml version=\"1.0\"?>\n" .
169 "<!DOCTYPE book PUBLIC \"-//OASIS//DTD DocBook XML V4.3//EN\"\n" .
170 " \"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd\"\n" .
172 " <!ENTITY % local.common.attrib \"xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'\">\n" .
175 $doctype_header =~ s/<!DOCTYPE \w+/<!DOCTYPE refentry/;
177 if (!$MAIN_SGML_FILE) {
178 $MAIN_SGML_FILE = "${MODULE}-docs.sgml";
180 $empty_element_end = ">";
181 $doctype_header = "";
186 # All the files are written in subdirectories beneath here.
187 $TMPL_DIR = $TMPL_DIR ? $TMPL_DIR : "$ROOT_DIR/tmpl";
189 # This is where we put all the DocBook output.
190 $SGML_OUTPUT_DIR = $SGML_OUTPUT_DIR ? $SGML_OUTPUT_DIR : "$ROOT_DIR/$OUTPUT_FORMAT";
192 # This file contains the object hierarchy.
193 my $OBJECT_TREE_FILE = "$ROOT_DIR/$MODULE.hierarchy";
195 # This file contains the interfaces.
196 my $INTERFACES_FILE = "$ROOT_DIR/$MODULE.interfaces";
198 # This file contains the prerequisites.
199 my $PREREQUISITES_FILE = "$ROOT_DIR/$MODULE.prerequisites";
201 # This file contains signal arguments and names.
202 my $SIGNALS_FILE = "$ROOT_DIR/$MODULE.signals";
204 # The file containing Arg information.
205 my $ARGS_FILE = "$ROOT_DIR/$MODULE.args";
207 # These global arrays store information on signals. Each signal has an entry
208 # in each of these arrays at the same index, like a multi-dimensional array.
209 my @SignalObjects; # The GtkObject which emits the signal.
210 my @SignalNames; # The signal name.
211 my @SignalReturns; # The return type.
212 my @SignalFlags; # Flags for the signal
213 my @SignalPrototypes; # The rest of the prototype of the signal handler.
215 # These global arrays store information on Args. Each Arg has an entry
216 # in each of these arrays at the same index, like a multi-dimensional array.
217 my @ArgObjects; # The GtkObject which has the Arg.
218 my @ArgNames; # The Arg name.
219 my @ArgTypes; # The Arg type - gint, GtkArrowType etc.
220 my @ArgFlags; # How the Arg can be used - readable/writable etc.
221 my @ArgNicks; # The nickname of the Arg.
222 my @ArgBlurbs; # Docstring of the Arg.
223 my @ArgDefaults; # Default value of the Arg.
224 my @ArgRanges; # The range of the Arg type
225 # These global hashes store declaration info keyed on a symbol name.
227 my %DeclarationTypes;
228 my %DeclarationConditional;
229 my %DeclarationOutput;
233 my %StructHasTypedef;
235 # These global hashes store the existing documentation.
239 my %SymbolSourceFile;
240 my %SymbolSourceLine;
242 # These global hashes store documentation scanned from the source files.
243 my %SourceSymbolDocs;
244 my %SourceSymbolParams;
245 my %SourceSymbolSourceFile;
246 my %SourceSymbolSourceLine;
248 # all documentation goes in here, so we can do coverage analysis
250 my %AllIncompleteSymbols;
251 my %AllUnusedSymbols;
252 my %AllDocumentedSymbols;
254 # Undeclared yet documented symbols
255 my %UndeclaredSymbols;
257 # These global arrays store GObject, subclasses and the hierarchy.
264 # holds the symbols which are mentioned in $MODULE-sections.txt and in which
265 # section they are defined
270 # collects index entries
271 my %IndexEntriesFull;
272 my %IndexEntriesSince;
273 my %IndexEntriesDeprecated;
275 # Standard C preprocessor directives, which we ignore for '#' abbreviations.
276 my %PreProcessorDirectives;
277 $PreProcessorDirectives{"assert"} = 1;
278 $PreProcessorDirectives{"define"} = 1;
279 $PreProcessorDirectives{"elif"} = 1;
280 $PreProcessorDirectives{"else"} = 1;
281 $PreProcessorDirectives{"endif"} = 1;
282 $PreProcessorDirectives{"error"} = 1;
283 $PreProcessorDirectives{"if"} = 1;
284 $PreProcessorDirectives{"ifdef"} = 1;
285 $PreProcessorDirectives{"ifndef"} = 1;
286 $PreProcessorDirectives{"include"} = 1;
287 $PreProcessorDirectives{"line"} = 1;
288 $PreProcessorDirectives{"pragma"} = 1;
289 $PreProcessorDirectives{"unassert"} = 1;
290 $PreProcessorDirectives{"undef"} = 1;
291 $PreProcessorDirectives{"warning"} = 1;
293 # remember used annotation (to write minimal glossary)
296 my %AnnotationDefinition = (
297 'allow-none' => "NULL is ok, both for passing and for returning.",
298 'array' => "Parameter points to an array of items.",
299 'default' => "Default parameter value (for in case the <acronym>shadows</acronym>-to function has less parameters).",
300 'element-type' => "Generics and defining elements of containers and arrays.",
301 'error-domains' => "Typed errors. Similar to throws in Java.",
302 'in' => "Parameter for input. Default is <acronym>transfer none</acronym>.",
303 'inout' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
304 'in-out' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
305 'not-error' => "A GError parameter is not to be handled like a normal GError.",
306 'out' => "Parameter for returning results. Default is <acronym>transfer full</acronym>.",
307 'transfer container' => "Free data container after the code is done.",
308 'transfer full' => "Free data after the code is done.",
309 'transfer none' => "Don't free data after the code is done.",
310 'scope call' => "The callback is valid only during the call to the method.",
311 'scope async' => "The callback is valid until first called.",
312 'scope notfied' => "The callback is valid until the GDestroyNotify argument is called."
315 # Create the root DocBook output directory if it doens't exist.
316 if (! -e $SGML_OUTPUT_DIR) {
317 mkdir ("$SGML_OUTPUT_DIR", 0777)
318 || die "Can't create directory: $SGML_OUTPUT_DIR";
321 # Function and other declaration output settings.
322 my $RETURN_TYPE_FIELD_WIDTH = 20;
323 my $SYMBOL_FIELD_WIDTH = 36;
324 my $SIGNAL_FIELD_WIDTH = 16;
325 my $PARAM_FIELD_COUNT = 2;
327 &ReadKnownSymbols ("$ROOT_DIR/$MODULE-sections.txt");
328 &ReadSignalsFile ($SIGNALS_FILE);
329 &ReadArgsFile ($ARGS_FILE);
330 &ReadObjectHierarchy;
334 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-decl.txt", 0);
335 if (-f "$ROOT_DIR/$MODULE-overrides.txt") {
336 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-overrides.txt", 1);
339 for my $dir (@SOURCE_DIRS) {
340 &ReadSourceDocumentation ($dir);
343 my $changed = &OutputSGML ("$ROOT_DIR/$MODULE-sections.txt");
345 # If any of the DocBook SGML files have changed, update the timestamp file (so
346 # it can be used for Makefile dependencies).
347 if ($changed || ! -e "$ROOT_DIR/sgml.stamp") {
349 # try to detect the common prefix
350 # GtkWidget, GTK_WIDGET, gtk_widget -> gtk
351 if ($NAME_SPACE eq "") {
358 foreach my $symbol (keys(%IndexEntriesFull)) {
359 if(($NAME_SPACE eq "") || $symbol =~ /^$NAME_SPACE/i) {
360 if (length($symbol)>$pos) {
361 $letter=substr($symbol,$pos,1);
362 # stop prefix scanning
363 if ($letter eq "_") {
367 # Should we also stop on a uppercase char, if last was lowercase
368 # GtkWidget, if we have the 'W' and had the 't' before
369 # or should we count upper and lowercase, and stop one 2nd uppercase, if we already had a lowercase
370 # GtkWidget, the 'W' would be the 2nd uppercase and with 't','k' we had lowercase chars before
371 # need to recound each time as this is per symbol
372 $prefix{uc($letter)}++;
376 if ($letter ne "" && $letter ne "_") {
379 foreach $letter (keys(%prefix)) {
380 #print "$letter: $prefix{$letter}.\n";
381 if ($prefix{$letter}>$maxsymbols) {
383 $maxsymbols=$prefix{$letter};
386 $ratio = scalar(keys(%IndexEntriesFull)) / $prefix{$maxletter};
387 #print "most symbols start with $maxletter, that is ". (100 * $ratio) ." %\n";
390 $NAME_SPACE .= $maxletter;
397 } while ($ratio > 0.9);
398 #print "most symbols start with $NAME_SPACE\n";
402 &OutputDeprecatedIndex;
404 &OutputAnnotationGlossary;
406 open (TIMESTAMP, ">$ROOT_DIR/sgml.stamp")
407 || die "Can't create $ROOT_DIR/sgml.stamp: $!";
408 print (TIMESTAMP "timestamp");
412 #############################################################################
413 # Function : OutputObjectList
414 # Description : This outputs the alphabetical list of objects, in a columned
416 # FIXME: Currently this also outputs ancestor objects
417 # which may not actually be in this module.
419 #############################################################################
421 sub OutputObjectList {
424 # FIXME: use $OUTPUT_FORMAT
425 # my $old_object_index = "$SGML_OUTPUT_DIR/object_index.$OUTPUT_FORMAT";
426 my $old_object_index = "$SGML_OUTPUT_DIR/object_index.sgml";
427 my $new_object_index = "$SGML_OUTPUT_DIR/object_index.new";
429 open (OUTPUT, ">$new_object_index")
430 || die "Can't create $new_object_index: $!";
432 if ($OUTPUT_FORMAT eq "xml") {
433 my $header = $doctype_header;
435 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE informaltable/;
436 print (OUTPUT "$header");
439 print (OUTPUT <<EOF);
440 <informaltable pgwide="1" frame="none">
441 <tgroup cols="$cols">
442 <colspec colwidth="1*"${empty_element_end}
443 <colspec colwidth="1*"${empty_element_end}
444 <colspec colwidth="1*"${empty_element_end}
450 foreach $object (sort (@Objects)) {
451 my $xref = &MakeXRef ($object);
452 if ($count % $cols == 0) { print (OUTPUT "<row>\n"); }
453 print (OUTPUT "<entry>$xref</entry>\n");
454 if ($count % $cols == ($cols - 1)) { print (OUTPUT "</row>\n"); }
458 # emit an empty row, since empty tables are invalid
459 print (OUTPUT "<row><entry> </entry></row>\n");
462 if ($count % $cols > 0) {
463 print (OUTPUT "</row>\n");
467 print (OUTPUT <<EOF);
468 </tbody></tgroup></informaltable>
472 &UpdateFileIfChanged ($old_object_index, $new_object_index, 0);
476 #############################################################################
477 # Function : OutputSGML
478 # Description : This collects the output for each section of the docs, and
479 # outputs each file when the end of the section is found.
480 # Arguments : $file - the $MODULE-sections.txt file which contains all of
481 # the functions/macros/structs etc. being documented, organised
482 # into sections and subsections.
483 #############################################################################
488 #print "Reading: $file\n";
490 || die "Can't open $file: $!";
493 my $book_bottom = "";
494 my $includes = (defined $DEFAULT_INCLUDES) ? $DEFAULT_INCLUDES : "";
495 my $section_includes = "";
504 my $signals_synop = "";
505 my $signals_desc = "";
507 my $child_args_synop = "";
508 my $style_args_synop = "";
510 my $child_args_desc = "";
511 my $style_args_desc = "";
514 my $implementations = "";
515 my $prerequisites = "";
517 my @file_objects = ();
519 my %symbol_def_line = ();
521 # merge the source docs, in case there are no templates
522 &MergeSourceDocumentation;
528 } elsif (m/^<SECTION>/) {
534 %symbol_def_line = ();
536 } elsif (m/^<SUBSECTION\s*(.*)>/i) {
540 } elsif (m/^<SUBSECTION>/) {
542 } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
544 #print "Section: $title\n";
546 # We don't want warnings if object & class structs aren't used.
547 $DeclarationOutput{$title} = 1;
548 $DeclarationOutput{"${title}Class"} = 1;
549 $DeclarationOutput{"${title}Iface"} = 1;
550 $DeclarationOutput{"${title}Interface"} = 1;
552 } elsif (m/^<FILE>(.*)<\/FILE>/) {
554 if (! defined $templates{$filename}) {
555 if (&ReadTemplateFile ("$TMPL_DIR/$filename", 1)) {
556 &MergeSourceDocumentation;
557 $templates{$filename}=$.;
560 &LogWarning ($file, $., "Double <FILE>$filename</FILE> entry. ".
561 "Previous occurrence on line ".$templates{$filename}.".");
563 if (($title eq "") and (defined $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"})) {
564 $title = $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"};
565 # Remove trailing blanks
569 } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
571 $section_includes = $1;
573 if (defined $DEFAULT_INCLUDES) {
574 &LogWarning ($file, $., "Default <INCLUDE> being overridden by command line option.");
581 } elsif (m/^<\/SECTION>/) {
582 #print "End of section: $title\n";
583 if ($num_symbols > 0) {
585 if ($OUTPUT_FORMAT eq "xml") {
586 $book_bottom .= " <xi:include href=\"xml/$filename.xml\"/>\n";
588 $book_top.="<!ENTITY $section_id SYSTEM \"sgml/$filename.sgml\">\n";
589 $book_bottom .= " &$section_id;\n";
592 if (defined ($SourceSymbolDocs{"$TMPL_DIR/$filename:Include"})) {
593 if ($section_includes) {
594 &LogWarning ($file, $., "Section <INCLUDE> being overridden by inline comments.");
596 $section_includes = $SourceSymbolDocs{"$TMPL_DIR/$filename:Include"};
598 if ($section_includes eq "") {
599 $section_includes = $includes;
602 $signals_synop =~ s/^\n*//g;
603 $signals_synop =~ s/\n+$/\n/g;
604 if ($signals_synop ne '') {
605 $signals_synop = <<EOF;
606 <refsect1 id="$section_id.signals" role="signal_proto">
607 <title role="signal_proto.title">Signals</title>
609 ${signals_synop}</synopsis>
612 $signals_desc =~ s/^\n*//g;
613 $signals_desc =~ s/\n+$/\n/g;
614 $signals_desc =~ s/(\s|\n)+$//ms;
615 $signals_desc = <<EOF;
616 <refsect1 id="$section_id.signal-details" role="signals">
617 <title role="signals.title">Signal Details</title>
623 $args_synop =~ s/^\n*//g;
624 $args_synop =~ s/\n+$/\n/g;
625 if ($args_synop ne '') {
627 <refsect1 id="$section_id.properties" role="properties">
628 <title role="properties.title">Properties</title>
630 ${args_synop}</synopsis>
633 $args_desc =~ s/^\n*//g;
634 $args_desc =~ s/\n+$/\n/g;
635 $args_desc =~ s/(\s|\n)+$//ms;
637 <refsect1 id="$section_id.property-details" role="property_details">
638 <title role="property_details.title">Property Details</title>
644 $child_args_synop =~ s/^\n*//g;
645 $child_args_synop =~ s/\n+$/\n/g;
646 if ($child_args_synop ne '') {
647 $args_synop .= <<EOF;
648 <refsect1 id="$section_id.child-properties" role="child_properties">
649 <title role="child_properties.title">Child Properties</title>
651 ${child_args_synop}</synopsis>
654 $child_args_desc =~ s/^\n*//g;
655 $child_args_desc =~ s/\n+$/\n/g;
656 $child_args_desc =~ s/(\s|\n)+$//ms;
658 <refsect1 id="$section_id.child-property-details" role="child_property_details">
659 <title role="child_property_details.title">Child Property Details</title>
665 $style_args_synop =~ s/^\n*//g;
666 $style_args_synop =~ s/\n+$/\n/g;
667 if ($style_args_synop ne '') {
668 $args_synop .= <<EOF;
669 <refsect1 id="$section_id.style-properties" role="style_properties">
670 <title role="style_properties.title">Style Properties</title>
672 ${style_args_synop}</synopsis>
675 $style_args_desc =~ s/^\n*//g;
676 $style_args_desc =~ s/\n+$/\n/g;
677 $style_args_desc =~ s/(\s|\n)+$//ms;
679 <refsect1 id="$section_id.style-property-details" role="style_properties_details">
680 <title role="style_properties_details.title">Style Property Details</title>
686 $hierarchy =~ s/^\n*//g;
687 $hierarchy =~ s/\n+$/\n/g;
688 $hierarchy =~ s/(\s|\n)+$//ms;
689 if ($hierarchy ne "") {
691 <refsect1 id="$section_id.object-hierarchy" role="object_hierarchy">
692 <title role="object_hierarchy.title">Object Hierarchy</title>
698 $interfaces =~ s/^\n*//g;
699 $interfaces =~ s/\n+$/\n/g;
700 $interfaces =~ s/(\s|\n)+$//ms;
701 if ($interfaces ne "") {
703 <refsect1 id="$section_id.implemented-interfaces" role="impl_interfaces">
704 <title role="impl_interfaces.title">Implemented Interfaces</title>
710 $implementations =~ s/^\n*//g;
711 $implementations =~ s/\n+$/\n/g;
712 $implementations =~ s/(\s|\n)+$//ms;
713 if ($implementations ne "") {
714 $implementations = <<EOF;
715 <refsect1 id="$section_id.implementations" role="implementations">
716 <title role="implementations.title">Known Implementations</title>
722 $prerequisites =~ s/^\n*//g;
723 $prerequisites =~ s/\n+$/\n/g;
724 $prerequisites =~ s/(\s|\n)+$//ms;
725 if ($prerequisites ne "") {
726 $prerequisites = <<EOF;
727 <refsect1 id="$section_id.prerequisites" role="prerequisites">
728 <title role="prerequisites.title">Prerequisites</title>
734 $derived =~ s/^\n*//g;
735 $derived =~ s/\n+$/\n/g;
736 $derived =~ s/(\s|\n)+$//ms;
737 if ($derived ne "") {
739 <refsect1 id="$section_id.derived-interfaces" role="derived_interfaces">
740 <title role="derived_interfaces.title">Known Derived Interfaces</title>
746 $synopsis =~ s/^\n*//g;
747 $synopsis =~ s/\n+$/\n/g;
748 my $file_changed = &OutputSGMLFile ($filename, $title, $section_id,
750 \$synopsis, \$details,
751 \$signals_synop, \$signals_desc,
752 \$args_synop, \$args_desc,
753 \$hierarchy, \$interfaces,
755 \$prerequisites, \$derived,
765 $section_includes = "";
769 $child_args_synop = "";
770 $style_args_synop = "";
772 $child_args_desc = "";
773 $style_args_desc = "";
776 $implementations = "";
780 } elsif (m/^(\S+)/) {
782 #print " Symbol: $symbol\n";
784 # check for duplicate entries
785 if (! defined $symbol_def_line{$symbol}) {
786 my $declaration = $Declarations{$symbol};
787 if (defined ($declaration)) {
788 # We don't want standard macros/functions of GObjects,
789 # or private declarations.
790 if ($subsection ne "Standard" && $subsection ne "Private") {
791 if (&CheckIsObject ($symbol)) {
792 push @file_objects, $symbol;
794 my ($synop, $desc) = &OutputDeclaration ($symbol,
796 my ($sig_synop, $sig_desc) = &GetSignals ($symbol);
797 my ($arg_synop, $child_arg_synop, $style_arg_synop,
798 $arg_desc, $child_arg_desc, $style_arg_desc) = &GetArgs ($symbol);
799 my $hier = &GetHierarchy ($symbol);
800 my $ifaces = &GetInterfaces ($symbol);
801 my $impls = &GetImplementations ($symbol);
802 my $prereqs = &GetPrerequisites ($symbol);
803 my $der = &GetDerived ($symbol);
806 $signals_synop .= $sig_synop;
807 $signals_desc .= $sig_desc;
808 $args_synop .= $arg_synop;
809 $child_args_synop .= $child_arg_synop;
810 $style_args_synop .= $style_arg_synop;
811 $args_desc .= $arg_desc;
812 $child_args_desc .= $child_arg_desc;
813 $style_args_desc .= $style_arg_desc;
815 $interfaces .= $ifaces;
816 $implementations .= $impls;
817 $prerequisites .= $prereqs;
821 # Note that the declaration has been output.
822 $DeclarationOutput{$symbol} = 1;
823 } elsif ($subsection ne "Standard" && $subsection ne "Private") {
824 $UndeclaredSymbols{$symbol} = 1;
825 &LogWarning ($file, $., "No declaration found for $symbol.");
828 $symbol_def_line{$symbol}=$.;
830 if ($section_id eq "") {
831 if($title eq "" && $filename eq "") {
832 &LogWarning ($file, $., "Section has no title and no file.");
834 # FIXME: one of those would be enough
835 # filename should be an internal detail for gtk-doc
838 } elsif ($filename eq "") {
841 $filename =~ s/\s/_/g;
843 $section_id = $SourceSymbolDocs{"$TMPL_DIR/$filename:Section_Id"};
844 if (defined ($section_id) && $section_id !~ m/^\s*$/) {
845 # Remove trailing blanks and use as is
846 $section_id =~ s/\s+$//;
847 } elsif (&CheckIsObject ($title)) {
848 # GObjects use their class name as the ID.
849 $section_id = &CreateValidSGMLID ($title);
851 $section_id = &CreateValidSGMLID ("$MODULE-$title");
854 $SymbolSection{$symbol}=$title;
855 $SymbolSectionId{$symbol}=$section_id;
858 &LogWarning ($file, $., "Double symbol entry for $symbol. ".
859 "Previous occurrence on line ".$symbol_def_line{$symbol}.".");
865 &OutputMissingDocumentation;
866 &OutputUndeclaredSymbols;
867 &OutputUnusedSymbols;
869 if ($OUTPUT_ALL_SYMBOLS) {
872 if ($OUTPUT_SYMBOLS_WITHOUT_SINCE) {
873 &OutputSymbolsWithoutSince;
876 for $filename (split (' ', $EXPAND_CONTENT_FILES)) {
877 my $file_changed = &OutputExtraFile ($filename);
883 &OutputBook ($book_top, $book_bottom);
888 #############################################################################
889 # Function : OutputIndex
890 # Description : This writes an indexlist that can be included into the main-
891 # document into an <index> tag.
892 #############################################################################
895 my ($basename, $apiindexref ) = @_;
896 my %apiindex = %{$apiindexref};
897 my $old_index = "$SGML_OUTPUT_DIR/$basename.xml";
898 my $new_index = "$SGML_OUTPUT_DIR/$basename.new";
899 my $lastletter = " ";
904 open (OUTPUT, ">$new_index")
905 || die "Can't create $new_index";
907 my $header = $doctype_header;
908 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE indexdiv/;
910 print (OUTPUT "$header<indexdiv>\n");
912 #print "generate $basename index (".%apiindex." entries)\n";
914 # do a case insensitive sort while chopping off the prefix
916 sort { $$a{criteria} cmp $$b{criteria} }
917 map { my $x = uc($_); $x =~ s/^$NAME_SPACE\_?(.*)/$1/i; { criteria => $x, original => $_, short => $1 } }
920 $symbol = $$hash{original};
921 if (defined($$hash{short})) {
922 $short_symbol = $$hash{short};
924 $short_symbol = $symbol;
927 # generate a short symbol description
928 my $symbol_desc = "";
929 my $symbol_section = "";
930 my $symbol_section_id = "";
931 my $symbol_type = lc($DeclarationTypes{$symbol});
932 if ($symbol_type eq "") {
933 #print "trying symbol $symbol\n";
934 if ($symbol =~ m/(.*)::(.*)/) {
938 #print " trying object signal ${oname}:$osym in ".$#SignalNames." signals\n";
939 for ($i = 0; $i <= $#SignalNames; $i++) {
940 if ($SignalNames[$i] eq $osym) {
941 $symbol_type = "object signal";
942 if (defined($SymbolSection{$oname})) {
943 $symbol_section = $SymbolSection{$oname};
944 $symbol_section_id = $SymbolSectionId{$oname};
949 } elsif ($symbol =~ m/(.*):(.*)/) {
953 #print " trying object property ${oname}::$osym in ".$#ArgNames." properties\n";
954 for ($i = 0; $i <= $#ArgNames; $i++) {
955 #print " ".$ArgNames[$i]."\n";
956 if ($ArgNames[$i] eq $osym) {
957 $symbol_type = "object property";
958 if (defined($SymbolSection{$oname})) {
959 $symbol_section = $SymbolSection{$oname};
960 $symbol_section_id = $SymbolSectionId{$oname};
967 if (defined($SymbolSection{$symbol})) {
968 $symbol_section = $SymbolSection{$symbol};
969 $symbol_section_id = $SymbolSectionId{$symbol};
972 if ($symbol_type ne "") {
973 $symbol_desc=", $symbol_type";
974 if ($symbol_section ne "") {
975 $symbol_desc.=" in <link linkend=\"$symbol_section_id\">$symbol_section</link>";
976 #$symbol_desc.=" in ". &ExpandAbbreviations($symbol, "#$symbol_section");
980 my $curletter = uc(substr($short_symbol,0,1));
981 my $id = $apiindex{$symbol};
983 #print " add symbol $symbol with $id to index in section $curletter\n";
985 if ($curletter ne $lastletter) {
986 $lastletter = $curletter;
989 print (OUTPUT "</indexdiv>\n");
991 print (OUTPUT "<indexdiv><title>$curletter</title>\n");
995 print (OUTPUT <<EOF);
996 <indexentry><primaryie linkends="$id"><link linkend="$id">$symbol</link>$symbol_desc</primaryie></indexentry>
1000 if ($divopen == 1) {
1001 print (OUTPUT "</indexdiv>\n");
1003 print (OUTPUT "</indexdiv>\n");
1006 &UpdateFileIfChanged ($old_index, $new_index, 0);
1010 #############################################################################
1011 # Function : OutputIndexFull
1012 # Description : This writes the full api indexlist that can be included into the
1013 # main document into an <index> tag.
1014 #############################################################################
1016 sub OutputIndexFull {
1017 &OutputIndex ("api-index-full", \%IndexEntriesFull);
1021 #############################################################################
1022 # Function : OutputDeprecatedIndex
1023 # Description : This writes the deprecated api indexlist that can be included
1024 # into the main document into an <index> tag.
1025 #############################################################################
1027 sub OutputDeprecatedIndex {
1028 &OutputIndex ("api-index-deprecated", \%IndexEntriesDeprecated);
1032 #############################################################################
1033 # Function : OutputSinceIndexes
1034 # Description : This writes the 'since' api indexlists that can be included into
1035 # the main document into an <index> tag.
1036 #############################################################################
1038 sub OutputSinceIndexes {
1039 my @sinces = keys %{{ map { $_ => 1 } values %Since }};
1041 foreach my $version (@sinces) {
1042 #print "Since : [$version]\n";
1043 # TODO make filtered hash
1044 #my %index = grep { $Since{$_} eq $version } %IndexEntriesSince;
1045 my %index = map { $_ => $IndexEntriesSince{$_} } grep { $Since{$_} eq $version } keys %IndexEntriesSince;
1047 &OutputIndex ("api-index-$version", \%index);
1051 #############################################################################
1052 # Function : OutputAnnotationGlossary
1053 # Description : This writes a glossary of the used annotation terms into a
1054 # separate glossary file that can be included into the main
1056 #############################################################################
1058 sub OutputAnnotationGlossary {
1059 my $old_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.xml";
1060 my $new_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.new";
1061 my $lastletter = " ";
1064 # if there are no annotations used return
1065 return if (! keys(%AnnotationsUsed));
1067 # add acronyms that are referenced from acronym text
1069 foreach my $annotation (keys(%AnnotationsUsed)) {
1070 if($AnnotationDefinition{$annotation} =~ m/<acronym>([\w ]+)<\/acronym>/) {
1071 if (!exists($AnnotationsUsed{$1})) {
1072 $AnnotationsUsed{$1} = 1;
1078 open (OUTPUT, ">$new_glossary")
1079 || die "Can't create $new_glossary";
1081 my $header = $doctype_header;
1082 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE glossary/;
1084 print (OUTPUT <<EOF);
1086 <glossary id="annotation-glossary">
1087 <title>Annotation Glossary</title>
1090 foreach my $annotation (keys(%AnnotationsUsed)) {
1091 my $def = $AnnotationDefinition{$annotation};
1092 my $curletter = uc(substr($annotation,0,1));
1094 if ($curletter ne $lastletter) {
1095 $lastletter = $curletter;
1097 if ($divopen == 1) {
1098 print (OUTPUT "</glossdiv>\n");
1100 print (OUTPUT "<glossdiv><title>$curletter</title>\n");
1103 print (OUTPUT <<EOF);
1105 <glossterm><anchor id="annotation-glossterm-$annotation"/>$annotation</glossterm>
1113 if ($divopen == 1) {
1114 print (OUTPUT "</glossdiv>\n");
1116 print (OUTPUT "</glossary>\n");
1119 &UpdateFileIfChanged ($old_glossary, $new_glossary, 0);
1122 #############################################################################
1123 # Function : ReadKnownSymbols
1124 # Description : This collects the names of non-private symbols from the
1125 # $MODULE-sections.txt file.
1126 # Arguments : $file - the $MODULE-sections.txt file which contains all of
1127 # the functions/macros/structs etc. being documented, organised
1128 # into sections and subsections.
1129 #############################################################################
1131 sub ReadKnownSymbols {
1134 my $subsection = "";
1136 #print "Reading: $file\n";
1138 || die "Can't open $file: $!";
1144 } elsif (m/^<SECTION>/) {
1147 } elsif (m/^<SUBSECTION\s*(.*)>/i) {
1150 } elsif (m/^<SUBSECTION>/) {
1153 } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
1156 } elsif (m/^<FILE>(.*)<\/FILE>/) {
1157 $KnownSymbols{"$TMPL_DIR/$1:Long_Description"} = 1;
1158 $KnownSymbols{"$TMPL_DIR/$1:Short_Description"} = 1;
1161 } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
1164 } elsif (m/^<\/SECTION>/) {
1167 } elsif (m/^(\S+)/) {
1170 if ($subsection ne "Standard" && $subsection ne "Private") {
1171 $KnownSymbols{$symbol} = 1;
1174 $KnownSymbols{$symbol} = 0;
1182 #############################################################################
1183 # Function : OutputDeclaration
1184 # Description : Returns the synopsis and detailed description DocBook
1185 # describing one function/macro etc.
1186 # Arguments : $symbol - the name of the function/macro begin described.
1187 # $declaration - the declaration of the function/macro.
1188 #############################################################################
1190 sub OutputDeclaration {
1191 my ($symbol, $declaration) = @_;
1193 my $type = $DeclarationTypes {$symbol};
1194 if ($type eq 'MACRO') {
1195 return &OutputMacro ($symbol, $declaration);
1196 } elsif ($type eq 'TYPEDEF') {
1197 return &OutputTypedef ($symbol, $declaration);
1198 } elsif ($type eq 'STRUCT') {
1199 return &OutputStruct ($symbol, $declaration);
1200 } elsif ($type eq 'ENUM') {
1201 return &OutputEnum ($symbol, $declaration);
1202 } elsif ($type eq 'UNION') {
1203 return &OutputUnion ($symbol, $declaration);
1204 } elsif ($type eq 'VARIABLE') {
1205 return &OutputVariable ($symbol, $declaration);
1206 } elsif ($type eq 'FUNCTION') {
1207 return &OutputFunction ($symbol, $declaration, $type);
1208 } elsif ($type eq 'USER_FUNCTION') {
1209 return &OutputFunction ($symbol, $declaration, $type);
1211 die "Unknown symbol type";
1216 #############################################################################
1217 # Function : OutputSymbolTraits
1218 # Description : Returns the Since and StabilityLevel paragraphs for a symbol.
1219 # Arguments : $symbol - the name of the function/macro begin described.
1220 #############################################################################
1222 sub OutputSymbolTraits {
1226 if (exists $Since{$symbol}) {
1227 $desc .= "<para role=\"since\">Since $Since{$symbol}</para>";
1229 if (exists $StabilityLevel{$symbol}) {
1230 $desc .= "<para role=\"stability\">Stability Level: $StabilityLevel{$symbol}</para>";
1235 #############################################################################
1236 # Function : Outpu{Symbol,Section}ExtraLinks
1237 # Description : Returns extralinks for the symbol (if enabled).
1238 # Arguments : $symbol - the name of the function/macro begin described.
1239 #############################################################################
1243 return undef unless defined $text;
1245 # Build a char to hex map
1248 $escapes{chr($_)} = sprintf("%%%02X", $_);
1251 # Default unsafe characters. RFC 2732 ^(uric - reserved)
1252 $text =~ s/([^A-Za-z0-9\-_.!~*'()])/$escapes{$1}/g;
1257 sub OutputSymbolExtraLinks {
1261 if (0) { # NEW FEATURE: needs configurability
1262 my $sstr = &uri_escape($symbol);
1263 my $mstr = &uri_escape($MODULE);
1265 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1266 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&symbol=$sstr">edit documentation</ulink>
1272 sub OutputSectionExtraLinks {
1273 my ($symbol,$docsymbol) = @_;
1276 if (0) { # NEW FEATURE: needs configurability
1277 my $sstr = &uri_escape($symbol);
1278 my $mstr = &uri_escape($MODULE);
1279 my $dsstr = &uri_escape($docsymbol);
1281 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1282 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&symbol=$dsstr">edit documentation</ulink>
1289 #############################################################################
1290 # Function : OutputMacro
1291 # Description : Returns the synopsis and detailed description of a macro.
1292 # Arguments : $symbol - the macro.
1293 # $declaration - the declaration of the macro.
1294 #############################################################################
1297 my ($symbol, $declaration) = @_;
1298 my $id = &CreateValidSGMLID ($symbol);
1299 my $condition = &MakeConditionDescription ($symbol);
1300 my $synop = &MakeReturnField("#define") . "<link linkend=\"$id\">$symbol</link>";
1303 my @fields = ParseMacroDeclaration($declaration, \&CreateValidSGML);
1304 my $title = $symbol . (@fields ? "()" : "");
1306 $desc = "<refsect2 id=\"$id\" role=\"macro\"$condition>\n<title>$title</title>\n";
1307 $desc .= MakeIndexterms($symbol, $id);
1309 $desc .= OutputSymbolExtraLinks($symbol);
1312 if (length ($symbol) < $SYMBOL_FIELD_WIDTH) {
1313 $synop .= (' ' x ($SYMBOL_FIELD_WIDTH - length ($symbol)));
1317 for (my $i = 1; $i <= $#fields; $i += 2) {
1318 my $field_name = $fields[$i];
1321 $synop .= "$field_name";
1324 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1332 # Don't output the macro definition if is is a conditional macro or it
1333 # looks like a function, i.e. starts with "g_" or "_?gnome_", or it is
1334 # longer than 2 lines, otherwise we get lots of complicated macros like
1336 if (!defined ($DeclarationConditional{$symbol}) && ($symbol !~ m/^g_/)
1337 && ($symbol !~ m/^_?gnome_/) && (($declaration =~ tr/\n//) < 2)) {
1338 my $decl_out = &CreateValidSGML ($declaration);
1339 $desc .= "<programlisting>$decl_out</programlisting>\n";
1341 $desc .= "<programlisting>" . &MakeReturnField("#define") . "$symbol";
1342 if ($declaration =~ m/^\s*#\s*define\s+\w+(\([^\)]*\))/) {
1344 my $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH - length ("#define "));
1345 # Align each line so that if should all line up OK.
1346 $args =~ s/\n/\n$pad/gm;
1347 $desc .= &CreateValidSGML ($args);
1349 $desc .= "</programlisting>\n";
1352 $desc .= &MakeDeprecationNote($symbol);
1354 my $parameters = &OutputParamDescriptions ("MACRO", $symbol, @fields);
1355 my $parameters_output = 0;
1357 if (defined ($SymbolDocs{$symbol})) {
1358 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1360 # Try to insert the parameter table at the author's desired position.
1361 # Otherwise we need to tag it onto the end.
1362 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1363 $parameters_output = 1;
1365 $desc .= $symbol_docs;
1368 if ($parameters_output == 0) {
1369 $desc .= $parameters;
1372 $desc .= OutputSymbolTraits ($symbol);
1373 $desc .= "</refsect2>\n";
1374 return ($synop, $desc);
1378 #############################################################################
1379 # Function : OutputTypedef
1380 # Description : Returns the synopsis and detailed description of a typedef.
1381 # Arguments : $symbol - the typedef.
1382 # $declaration - the declaration of the typedef,
1383 # e.g. 'typedef unsigned int guint;'
1384 #############################################################################
1387 my ($symbol, $declaration) = @_;
1388 my $id = &CreateValidSGMLID ($symbol);
1389 my $condition = &MakeConditionDescription ($symbol);
1390 my $synop = &MakeReturnField("typedef") . "<link linkend=\"$id\">$symbol</link>;\n";
1391 my $desc = "<refsect2 id=\"$id\" role=\"typedef\"$condition>\n<title>$symbol</title>\n";
1393 $desc .= MakeIndexterms($symbol, $id);
1395 $desc .= OutputSymbolExtraLinks($symbol);
1397 if (!defined ($DeclarationConditional{$symbol})) {
1398 my $decl_out = &CreateValidSGML ($declaration);
1399 $desc .= "<programlisting>$decl_out</programlisting>\n";
1402 $desc .= &MakeDeprecationNote($symbol);
1404 if (defined ($SymbolDocs{$symbol})) {
1405 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1407 $desc .= OutputSymbolTraits ($symbol);
1408 $desc .= "</refsect2>\n";
1409 return ($synop, $desc);
1413 #############################################################################
1414 # Function : OutputStruct
1415 # Description : Returns the synopsis and detailed description of a struct.
1416 # We check if it is a object struct, and if so we only output
1417 # parts of it that are noted as public fields.
1418 # We also use a different SGML ID for object structs, since the
1419 # original ID is used for the entire RefEntry.
1420 # Arguments : $symbol - the struct.
1421 # $declaration - the declaration of the struct.
1422 #############################################################################
1425 my ($symbol, $declaration) = @_;
1427 my $is_object_struct = 0;
1428 my $default_to_public = 1;
1429 if (&CheckIsObject ($symbol)) {
1430 #print "Found object struct: $symbol\n";
1431 $is_object_struct = 1;
1432 $default_to_public = 0;
1437 if ($is_object_struct) {
1438 $id = &CreateValidSGMLID ($symbol . "_struct");
1439 $condition = &MakeConditionDescription ($symbol . "_struct");
1441 $id = &CreateValidSGMLID ($symbol);
1442 $condition = &MakeConditionDescription ($symbol);
1445 # Determine if it is a simple struct or it also has a typedef.
1446 my $has_typedef = 0;
1447 if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1454 # For structs with typedefs we just output the struct name.
1455 $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1456 $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>$symbol</title>\n";
1458 $synop = &MakeReturnField("struct") . "<link linkend=\"$id\">$symbol</link>;\n";
1459 $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>struct $symbol</title>\n";
1462 $desc .= MakeIndexterms($symbol, $id);
1464 $desc .= OutputSymbolExtraLinks($symbol);
1466 # Form a pretty-printed, private-data-removed form of the declaration
1469 if ($declaration =~ m/^\s*$/) {
1470 #print "Found opaque struct: $symbol\n";
1471 $decl_out = "typedef struct _$symbol $symbol;";
1472 } elsif ($declaration =~ m/^\s*struct\s+\w+\s*;\s*$/) {
1473 #print "Found opaque struct: $symbol\n";
1474 $decl_out = "struct $symbol;";
1476 my $public = $default_to_public;
1477 my $new_declaration = "";
1479 my $decl = $declaration;
1481 if ($decl =~ m/^\s*(typedef\s+)?struct\s*\w*\s*(?:\/\*.*\*\/)?\s*{(.*)}\s*\w*\s*;\s*$/s) {
1482 my $struct_contents = $2;
1484 foreach $decl_line (split (/\n/, $struct_contents)) {
1485 #print "Struct line: $decl_line\n";
1486 if ($decl_line =~ m%/\*\s*<\s*public\s*>\s*\*/%) {
1488 } elsif ($decl_line =~ m%/\*\s*<\s*(private|protected)\s*>\s*\*/%) {
1491 $new_declaration .= $decl_line . "\n";
1495 if ($new_declaration) {
1496 # Strip any blank lines off the ends.
1497 $new_declaration =~ s/^\s*\n//;
1498 $new_declaration =~ s/\n\s*$/\n/;
1501 $decl_out = "typedef struct {\n" . $new_declaration
1504 $decl_out = "struct $symbol {\n" . $new_declaration
1509 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1510 "Couldn't parse struct:\n$declaration");
1513 # If we couldn't parse the struct or it was all private, output an
1514 # empty struct declaration.
1515 if ($decl_out eq "") {
1517 $decl_out = "typedef struct _$symbol $symbol;";
1519 $decl_out = "struct $symbol;";
1524 $decl_out = &CreateValidSGML ($decl_out);
1525 $desc .= "<programlisting>$decl_out</programlisting>\n";
1527 $desc .= &MakeDeprecationNote($symbol);
1529 if (defined ($SymbolDocs{$symbol})) {
1530 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1533 # Create a table of fields and descriptions
1535 # FIXME: Inserting  's into the produced type declarations here would
1536 # improve the output in most situations ... except for function
1537 # members of structs!
1538 my @fields = ParseStructDeclaration($declaration, !$default_to_public,
1541 "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1543 my $params = $SymbolParams{$symbol};
1545 # If no parameters are filled in, we don't generate the description
1546 # table, for backwards compatibility
1549 if (defined $params) {
1550 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1551 if ($params->[$i] =~ /\S/) {
1559 my %field_descrs = @$params;
1560 my $missing_parameters = "";
1561 my $unused_parameters = "";
1563 $desc .= "<variablelist role=\"struct\">\n";
1565 my $field_name = shift @fields;
1566 my $text = shift @fields;
1567 my $field_descr = $field_descrs{$field_name};
1568 my $param_annotations = "";
1570 $desc .= "<varlistentry><term>$text</term>\n";
1571 if (defined $field_descr) {
1572 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1573 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1574 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1575 delete $field_descrs{$field_name};
1577 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1578 "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1579 if ($missing_parameters ne "") {
1580 $missing_parameters .= ", ".$field_name;
1582 $missing_parameters = $field_name;
1584 $desc .= "<listitem />\n";
1586 $desc .= "</varlistentry>\n";
1588 $desc .= "</variablelist>";
1589 foreach my $field_name (keys %field_descrs) {
1590 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1591 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1592 if ($unused_parameters ne "") {
1593 $unused_parameters .= ", ".$field_name;
1595 $unused_parameters = $field_name;
1599 # remember missing/unused parameters (needed in tmpl-free build)
1600 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1601 $AllIncompleteSymbols{$symbol}=$missing_parameters;
1603 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1604 $AllUnusedSymbols{$symbol}=$unused_parameters;
1608 if (scalar(@fields) > 0) {
1609 if (! exists ($AllIncompleteSymbols{$symbol})) {
1610 $AllIncompleteSymbols{$symbol}="<items>";
1611 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1612 "Field descriptions for $symbol are missing in source code comment block.");
1617 $desc .= OutputSymbolTraits ($symbol);
1618 $desc .= "</refsect2>\n";
1619 return ($synop, $desc);
1623 #############################################################################
1624 # Function : OutputUnion
1625 # Description : Returns the synopsis and detailed description of a union.
1626 # Arguments : $symbol - the union.
1627 # $declaration - the declaration of the union.
1628 #############################################################################
1631 my ($symbol, $declaration) = @_;
1632 my $id = &CreateValidSGMLID ($symbol);
1633 my $condition = &MakeConditionDescription ($symbol);
1635 # Determine if it is a simple struct or it also has a typedef.
1636 my $has_typedef = 0;
1637 if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1644 # For unions with typedefs we just output the union name.
1645 $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1646 $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>$symbol</title>\n";
1648 $synop = &MakeReturnField("union") . "<link linkend=\"$id\">$symbol</link>;\n";
1649 $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>union $symbol</title>\n";
1652 $desc .= MakeIndexterms($symbol, $id);
1654 $desc .= OutputSymbolExtraLinks($symbol);
1656 # FIXME: we do more for structs
1657 my $decl_out = &CreateValidSGML ($declaration);
1658 $desc .= "<programlisting>$decl_out</programlisting>\n";
1660 $desc .= &MakeDeprecationNote($symbol);
1662 if (defined ($SymbolDocs{$symbol})) {
1663 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1666 # Create a table of fields and descriptions
1668 # FIXME: Inserting  's into the produced type declarations here would
1669 # improve the output in most situations ... except for function
1670 # members of structs!
1671 my @fields = ParseStructDeclaration($declaration, 0,
1674 "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1676 my $params = $SymbolParams{$symbol};
1678 # If no parameters are filled in, we don't generate the description
1679 # table, for backwards compatibility
1682 if (defined $params) {
1683 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1684 if ($params->[$i] =~ /\S/) {
1692 my %field_descrs = @$params;
1693 my $missing_parameters = "";
1694 my $unused_parameters = "";
1696 $desc .= "<variablelist role=\"union\">\n";
1698 my $field_name = shift @fields;
1699 my $text = shift @fields;
1700 my $field_descr = $field_descrs{$field_name};
1701 my $param_annotations = "";
1703 $desc .= "<varlistentry><term>$text</term>\n";
1704 if (defined $field_descr) {
1705 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1706 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1707 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1708 delete $field_descrs{$field_name};
1710 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1711 "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1712 if ($missing_parameters ne "") {
1713 $missing_parameters .= ", ".$field_name;
1715 $missing_parameters = $field_name;
1717 $desc .= "<listitem />\n";
1719 $desc .= "</varlistentry>\n";
1721 $desc .= "</variablelist>";
1722 foreach my $field_name (keys %field_descrs) {
1723 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1724 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1725 if ($unused_parameters ne "") {
1726 $unused_parameters .= ", ".$field_name;
1728 $unused_parameters = $field_name;
1732 # remember missing/unused parameters (needed in tmpl-free build)
1733 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1734 $AllIncompleteSymbols{$symbol}=$missing_parameters;
1736 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1737 $AllUnusedSymbols{$symbol}=$unused_parameters;
1741 if (scalar(@fields) > 0) {
1742 if (! exists ($AllIncompleteSymbols{$symbol})) {
1743 $AllIncompleteSymbols{$symbol}="<items>";
1744 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1745 "Field descriptions for $symbol are missing in source code comment block.");
1750 $desc .= OutputSymbolTraits ($symbol);
1751 $desc .= "</refsect2>\n";
1752 return ($synop, $desc);
1756 #############################################################################
1757 # Function : OutputEnum
1758 # Description : Returns the synopsis and detailed description of a enum.
1759 # Arguments : $symbol - the enum.
1760 # $declaration - the declaration of the enum.
1761 #############################################################################
1764 my ($symbol, $declaration) = @_;
1765 my $id = &CreateValidSGMLID ($symbol);
1766 my $condition = &MakeConditionDescription ($symbol);
1767 my $synop = &MakeReturnField("enum") . "<link linkend=\"$id\">$symbol</link>;\n";
1768 my $desc = "<refsect2 id=\"$id\" role=\"enum\"$condition>\n<title>enum $symbol</title>\n";
1770 $desc .= MakeIndexterms($symbol, $id);
1772 $desc .= OutputSymbolExtraLinks($symbol);
1774 my $decl_out = &CreateValidSGML ($declaration);
1775 $desc .= "<programlisting>$decl_out</programlisting>\n";
1777 $desc .= &MakeDeprecationNote($symbol);
1779 if (defined ($SymbolDocs{$symbol})) {
1780 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1783 # Create a table of fields and descriptions
1785 my @fields = ParseEnumDeclaration($declaration);
1786 my $params = $SymbolParams{$symbol};
1788 # If no parameters are filled in, we don't generate the description
1789 # table, for backwards compatibility
1792 if (defined $params) {
1793 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1794 if ($params->[$i] =~ /\S/) {
1802 my %field_descrs = @$params;
1803 my $missing_parameters = "";
1804 my $unused_parameters = "";
1806 $desc .= "<variablelist role=\"enum\">\n";
1807 for my $field_name (@fields) {
1808 my $field_descr = $field_descrs{$field_name};
1809 my $param_annotations = "";
1811 $id = &CreateValidSGMLID ($field_name);
1812 $condition = &MakeConditionDescription ($field_name);
1813 $desc .= "<varlistentry id=\"$id\" role=\"constant\"$condition>\n<term><literal>$field_name</literal></term>\n";
1814 if (defined $field_descr) {
1815 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1816 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1817 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1818 delete $field_descrs{$field_name};
1820 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1821 "Value description for $symbol"."::"."$field_name is missing in source code comment block.");
1822 if ($missing_parameters ne "") {
1823 $missing_parameters .= ", ".$field_name;
1825 $missing_parameters = $field_name;
1827 $desc .= "<listitem />\n";
1829 $desc .= "</varlistentry>\n";
1831 $desc .= "</variablelist>";
1832 foreach my $field_name (keys %field_descrs) {
1833 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1834 "Value description for $symbol"."::"."$field_name is not used from source code comment block.");
1835 if ($unused_parameters ne "") {
1836 $unused_parameters .= ", ".$field_name;
1838 $unused_parameters = $field_name;
1842 # remember missing/unused parameters (needed in tmpl-free build)
1843 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1844 $AllIncompleteSymbols{$symbol}=$missing_parameters;
1846 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1847 $AllUnusedSymbols{$symbol}=$unused_parameters;
1851 if (scalar(@fields) > 0) {
1852 if (! exists ($AllIncompleteSymbols{$symbol})) {
1853 $AllIncompleteSymbols{$symbol}="<items>";
1854 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1855 "Value descriptions for $symbol are missing in source code comment block.");
1860 $desc .= OutputSymbolTraits ($symbol);
1861 $desc .= "</refsect2>\n";
1862 return ($synop, $desc);
1866 #############################################################################
1867 # Function : OutputVariable
1868 # Description : Returns the synopsis and detailed description of a variable.
1869 # Arguments : $symbol - the extern'ed variable.
1870 # $declaration - the declaration of the variable.
1871 #############################################################################
1873 sub OutputVariable {
1874 my ($symbol, $declaration) = @_;
1875 my $id = &CreateValidSGMLID ($symbol);
1876 my $condition = &MakeConditionDescription ($symbol);
1879 if ($declaration =~ m/^\s*extern\s+((const\s+|signed\s+|unsigned\s+)*\w+)(\s+\*+|\*+|\s)(\s*)([A-Za-z]\w*)\s*;/) {
1880 my $mod = defined ($1) ? $1 : "";
1881 my $ptr = defined ($3) ? $3 : "";
1882 my $space = defined ($4) ? $4 : "";
1883 $synop = &MakeReturnField("extern") . "$mod$ptr$space<link linkend=\"$id\">$symbol</link>;\n";
1886 $synop = &MakeReturnField("extern") . "<link linkend=\"$id\">$symbol</link>;\n";
1889 my $desc = "<refsect2 id=\"$id\" role=\"variable\"$condition>\n<title>$symbol</title>\n";
1891 $desc .= MakeIndexterms($symbol, $id);
1893 $desc .= OutputSymbolExtraLinks($symbol);
1895 my $decl_out = &CreateValidSGML ($declaration);
1896 $desc .= "<programlisting>$decl_out</programlisting>\n";
1898 $desc .= &MakeDeprecationNote($symbol);
1900 if (defined ($SymbolDocs{$symbol})) {
1901 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1903 $desc .= OutputSymbolTraits ($symbol);
1904 $desc .= "</refsect2>\n";
1905 return ($synop, $desc);
1909 #############################################################################
1910 # Function : OutputFunction
1911 # Description : Returns the synopsis and detailed description of a function.
1912 # Arguments : $symbol - the function.
1913 # $declaration - the declaration of the function.
1914 #############################################################################
1916 sub OutputFunction {
1917 my ($symbol, $declaration, $symbol_type) = @_;
1918 my $id = &CreateValidSGMLID ($symbol);
1919 my $condition = &MakeConditionDescription ($symbol);
1921 # Take out the return type $1 $3 $4
1922 $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//;
1923 my $type_modifier = defined($1) ? $1 : "";
1926 #print "$symbol pointer is $pointer\n";
1927 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1929 #if ($symbol_type eq 'USER_FUNCTION') {
1930 # $start = "typedef ";
1933 # We output const rather than G_CONST_RETURN.
1934 $type_modifier =~ s/G_CONST_RETURN/const/g;
1935 $pointer =~ s/G_CONST_RETURN/const/g;
1936 $pointer =~ s/^\s+/ /g;
1938 my $ret_type_len = length ($start) + length ($type_modifier)
1939 + length ($pointer) + length ($type);
1940 my $ret_type_output;
1942 if ($ret_type_len < $RETURN_TYPE_FIELD_WIDTH) {
1943 $ret_type_output = "$start$type_modifier$xref$pointer"
1944 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
1947 #$ret_type_output = "$start$type_modifier$xref$pointer\n" . (' ' x $RETURN_TYPE_FIELD_WIDTH);
1949 $ret_type_output = "$start$type_modifier$xref$pointer ";
1950 $symbol_len = $ret_type_len + 1 - $RETURN_TYPE_FIELD_WIDTH;
1953 $symbol_len += length ($symbol);
1954 my $char1 = my $char2 = my $char3 = "";
1955 if ($symbol_type eq 'USER_FUNCTION') {
1962 my ($symbol_output, $symbol_desc_output);
1963 if ($symbol_len < $SYMBOL_FIELD_WIDTH) {
1964 $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3"
1965 . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1966 $symbol_desc_output = "$char1$char2$symbol$char3"
1967 . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1969 $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3\n"
1970 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1971 $symbol_desc_output = "$char1$char2$symbol$char3\n"
1972 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1975 my $synop = $ret_type_output . $symbol_output . '(';
1976 my $desc = "<refsect2 id=\"$id\" role=\"function\"$condition>\n<title>${symbol} ()</title>\n";
1978 $desc .= MakeIndexterms($symbol, $id);
1980 $desc .= OutputSymbolExtraLinks($symbol);
1982 $desc .= "<programlisting>${ret_type_output}$symbol_desc_output(";
1984 my @fields = ParseFunctionDeclaration($declaration, \&MakeXRef,
1986 &tagify($_[0],"parameter");
1989 for (my $i = 1; $i <= $#fields; $i += 2) {
1990 my $field_name = $fields[$i];
1992 if ($field_name eq "Varargs") {
1993 $field_name = "...";
1997 $synop .= "$field_name";
1998 $desc .= "$field_name";
2001 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2004 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2011 $desc .= ");</programlisting>\n";
2013 $desc .= &MakeDeprecationNote($symbol);
2015 my $parameters = &OutputParamDescriptions ("FUNCTION", $symbol, @fields);
2016 my $parameters_output = 0;
2018 if (defined ($SymbolDocs{$symbol})) {
2019 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
2021 # Try to insert the parameter table at the author's desired position.
2022 # Otherwise we need to tag it onto the end.
2023 # FIXME: document that in the user manual and make it useable for other
2025 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
2026 $parameters_output = 1;
2028 $desc .= $symbol_docs;
2031 if ($parameters_output == 0) {
2032 $desc .= $parameters;
2035 $desc .= OutputSymbolTraits ($symbol);
2036 $desc .= "</refsect2>\n";
2037 return ($synop, $desc);
2041 #############################################################################
2042 # Function : OutputParamDescriptions
2043 # Description : Returns the DocBook output describing the parameters of a
2044 # function, macro or signal handler.
2045 # Arguments : $symbol_type - 'FUNCTION', 'MACRO' or 'SIGNAL'. Signal
2046 # handlers have an implicit user_data parameter last.
2047 # $symbol - the name of the function/macro being described.
2048 # @fields - parsed fields from the declaration, used to determine
2049 # undocumented/unused entries
2050 #############################################################################
2052 sub OutputParamDescriptions {
2053 my ($symbol_type, $symbol, @fields) = @_;
2055 my $params = $SymbolParams{$symbol};
2057 my %field_descrs = ();
2060 %field_descrs = @fields;
2061 delete $field_descrs{"void"};
2062 delete $field_descrs{"Returns"};
2065 if (defined $params) {
2067 my $params_desc = "";
2068 my $missing_parameters = "";
2069 my $unused_parameters = "";
2072 for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
2073 my $param_name = $$params[$j];
2074 my $param_desc = $$params[$j + 1];
2075 my $param_annotations = "";
2077 ($param_desc,$param_annotations) = & ExpandAnnotation($symbol, $param_desc);
2078 $param_desc = &ExpandAbbreviations($symbol, $param_desc);
2079 $param_desc .= $param_annotations;
2080 if ($param_name eq "Returns") {
2081 $returns = "$param_desc";
2082 } elsif ($param_name eq "void") {
2083 #print "!!!! void in params for $symbol?\n";
2086 if (!defined $field_descrs{$param_name}) {
2087 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2088 "Parameter description for $symbol"."::"."$param_name is not used from source code comment block.");
2089 if ($unused_parameters ne "") {
2090 $unused_parameters .= ", ".$param_name;
2092 $unused_parameters = $param_name;
2095 delete $field_descrs{$param_name};
2098 if ($param_name eq "Varargs") {
2099 $param_name = "...";
2101 if($param_desc ne "") {
2102 $params_desc .= "<varlistentry><term><parameter>$param_name</parameter> :</term>\n<listitem><simpara>$param_desc</simpara></listitem></varlistentry>\n";
2107 foreach my $param_name (keys %field_descrs) {
2108 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2109 "Parameter description for $symbol"."::"."$param_name is missing in source code comment block.");
2110 if ($missing_parameters ne "") {
2111 $missing_parameters .= ", ".$param_name;
2113 $missing_parameters = $param_name;
2117 # Signals have an implicit user_data parameter which we describe.
2118 if ($symbol_type eq "SIGNAL") {
2119 $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";
2122 # Start a table if we need one.
2123 if ($params_desc || $returns) {
2124 $output .= "<variablelist role=\"params\">\n";
2125 if ($params_desc ne "") {
2126 #$output .= "<varlistentry><term>Parameters:</term><listitem></listitem></varlistentry>\n";
2127 $output .= $params_desc;
2130 # Output the returns info last.
2132 $output .= "<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>$returns</simpara></listitem></varlistentry>\n";
2136 $output .= "</variablelist>";
2139 # remember missing/unused parameters (needed in tmpl-free build)
2140 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
2141 $AllIncompleteSymbols{$symbol}=$missing_parameters;
2143 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
2144 $AllUnusedSymbols{$symbol}=$unused_parameters;
2147 if (($num_params == 0) && @fields && (scalar(keys(%field_descrs)) > 0)) {
2148 if (! exists ($AllIncompleteSymbols{$symbol})) {
2149 $AllIncompleteSymbols{$symbol}="<parameters>";
2157 #############################################################################
2158 # Function : ParseStabilityLevel
2159 # Description : Parses a stability level and outputs a warning if it isn't
2161 # Arguments : $stability - the stability text.
2162 # $file, $line - context for error message
2163 # $message - description of where the level is from, to use in
2164 # any error message.
2165 # Returns : The parsed stability level string.
2166 #############################################################################
2168 sub ParseStabilityLevel {
2169 my ($stability, $file, $line, $message) = @_;
2171 $stability =~ s/^\s*//;
2172 $stability =~ s/\s*$//;
2173 if ($stability =~ m/^stable$/i) {
2174 $stability = "Stable";
2175 } elsif ($stability =~ m/^unstable$/i) {
2176 $stability = "Unstable";
2177 } elsif ($stability =~ m/^private$/i) {
2178 $stability = "Private";
2180 &LogWarning ($file, $line, "$message is $stability.".
2181 "It should be one of these: Stable, Unstable, or Private.");
2187 #############################################################################
2188 # Function : OutputSGMLFile
2189 # Description : Outputs the final DocBook file for one section.
2190 # Arguments : $file - the name of the file.
2191 # $title - the title from the $MODULE-sections.txt file, which
2192 # will be overridden by the title in the template file.
2193 # $section_id - the SGML id to use for the toplevel tag.
2194 # $includes - comma-separates list of include files added at top
2195 # of synopsis, with '<' '>' around them (if not already enclosed in "").
2196 # $synopsis - reference to the DocBook for the Synopsis part.
2197 # $details - reference to the DocBook for the Details part.
2198 # $signal_synop - reference to the DocBook for the Signal Synopsis part
2199 # $signal_desc - reference to the DocBook for the Signal Description part
2200 # $args_synop - reference to the DocBook for the Arg Synopsis part
2201 # $args_desc - reference to the DocBook for the Arg Description part
2202 # $hierarchy - reference to the DocBook for the Object Hierarchy part
2203 # $interfaces - reference to the DocBook for the Interfaces part
2204 # $implementations - reference to the DocBook for the Known Implementations part
2205 # $prerequisites - reference to the DocBook for the Prerequisites part
2206 # $derived - reference to the DocBook for the Derived Interfaces part
2207 # $file_objects - reference to an array of objects in this file
2208 #############################################################################
2210 sub OutputSGMLFile {
2211 my ($file, $title, $section_id, $includes, $synopsis, $details, $signals_synop, $signals_desc, $args_synop, $args_desc, $hierarchy, $interfaces, $implementations, $prerequisites, $derived, $file_objects) = @_;
2213 #print "Output sgml for file $file with title '$title'\n";
2215 # The edited title overrides the one from the sections file.
2216 my $new_title = $SymbolDocs{"$TMPL_DIR/$file:Title"};
2217 if (defined ($new_title) && $new_title !~ m/^\s*$/) {
2218 $title = $new_title;
2219 #print "Found title: $title\n";
2221 my $short_desc = $SymbolDocs{"$TMPL_DIR/$file:Short_Description"};
2222 if (!defined ($short_desc) || $short_desc =~ m/^\s*$/) {
2225 $short_desc = &ExpandAbbreviations("$title:Short_description",
2227 #print "Found short_desc: $short_desc";
2229 my $long_desc = $SymbolDocs{"$TMPL_DIR/$file:Long_Description"};
2230 if (!defined ($long_desc) || $long_desc =~ m/^\s*$/) {
2233 $long_desc = &ExpandAbbreviations("$title:Long_description",
2235 #print "Found long_desc: $long_desc";
2237 my $see_also = $SymbolDocs{"$TMPL_DIR/$file:See_Also"};
2238 if (!defined ($see_also) || $see_also =~ m%^\s*(<para>)?\s*(</para>)?\s*$%) {
2241 $see_also = &ExpandAbbreviations("$title:See_Also", $see_also);
2242 #print "Found see_also: $see_also";
2245 $see_also = "<refsect1 id=\"$section_id.see-also\">\n<title>See Also</title>\n$see_also\n</refsect1>\n";
2247 my $stability = $SymbolDocs{"$TMPL_DIR/$file:Stability_Level"};
2248 if (!defined ($stability) || $stability =~ m/^\s*$/) {
2251 $stability = &ParseStabilityLevel($stability, $file, $., "Section stability level");
2252 #print "Found stability: $stability";
2255 $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$stability, unless otherwise indicated\n</refsect1>\n";
2256 } elsif ($DEFAULT_STABILITY) {
2257 $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$DEFAULT_STABILITY, unless otherwise indicated\n</refsect1>\n";
2260 my $image = $SymbolDocs{"$TMPL_DIR/$file:Image"};
2261 if (!defined ($image) || $image =~ m/^\s*$/) {
2269 if ($image =~ /jpe?g$/i) {
2270 $format = "format='JPEG'";
2271 } elsif ($image =~ /png$/i) {
2272 $format = "format='PNG'";
2273 } elsif ($image =~ /svg$/i) {
2274 $format = "format='SVG'";
2279 $image = " <inlinegraphic fileref='$image' $format/>\n"
2282 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
2284 my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
2287 my $include_output = "";
2289 foreach $include (split (/,/, $includes)) {
2290 if ($include =~ m/^\".+\"$/) {
2291 $include_output .= "#include ${include}\n";
2294 $include =~ s/^\s+|\s+$//gs;
2295 $include_output .= "#include <${include}>\n";
2298 if ($include_output ne '') {
2299 $include_output = "\n$include_output\n";
2302 my $extralinks = OutputSectionExtraLinks($title,"Section:$file");
2304 my $old_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT";
2305 my $new_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT.new";
2307 open (OUTPUT, ">$new_sgml_file")
2308 || die "Can't create $new_sgml_file: $!";
2310 my $object_anchors = "";
2311 foreach my $object (@$file_objects) {
2312 next if ($object eq $section_id);
2313 my $id = CreateValidSGMLID($object);
2314 #print "Debug: Adding anchor for $object\n";
2315 $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
2318 # We used to output this, but is messes up our UpdateFileIfChanged code
2319 # since it changes every day (and it is only used in the man pages):
2320 # "<refentry id="$section_id" revision="$mday $month $year">"
2322 if ($OUTPUT_FORMAT eq "xml") {
2323 print OUTPUT $doctype_header;
2327 <refentry id="$section_id">
2329 <refentrytitle role="top_of_page" id="$section_id.top_of_page">$title</refentrytitle>
2330 <manvolnum>3</manvolnum>
2333 $image</refmiscinfo>
2336 <refname>$title</refname>
2337 <refpurpose>$short_desc</refpurpose>
2340 <refsynopsisdiv id="$section_id.synopsis" role="synopsis">
2341 <title role="synopsis.title">Synopsis</title>
2343 <synopsis>$include_output$${synopsis}</synopsis>
2345 $$hierarchy$$prerequisites$$derived$$interfaces$$implementations$$args_synop$$signals_synop
2346 <refsect1 id="$section_id.description" role="desc">
2347 <title role="desc.title">Description</title>
2348 $extralinks$long_desc
2350 <refsect1 id="$section_id.details" role="details">
2351 <title role="details.title">Details</title>
2354 $$args_desc$$signals_desc$see_also
2359 return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2363 #############################################################################
2364 # Function : OutputExtraFile
2365 # Description : Copies an "extra" DocBook file into the output directory,
2366 # expanding abbreviations
2367 # Arguments : $file - the source file.
2368 #############################################################################
2369 sub OutputExtraFile {
2374 ($basename = $file) =~ s!^.*/!!;
2376 my $old_sgml_file = "$SGML_OUTPUT_DIR/$basename";
2377 my $new_sgml_file = "$SGML_OUTPUT_DIR/$basename.new";
2381 open(EXTRA_FILE, "<$file") || die "Can't open $file";
2385 $contents = <EXTRA_FILE>;
2388 open (OUTPUT, ">$new_sgml_file")
2389 || die "Can't create $new_sgml_file: $!";
2391 print OUTPUT &ExpandAbbreviations ("$basename file", $contents);
2394 return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2396 #############################################################################
2397 # Function : OutputBook
2398 # Description : Outputs the SGML entities that need to be included into the
2399 # main SGML file for the module.
2400 # Arguments : $book_top - the declarations of the entities, which are added
2401 # at the top of the main SGML file.
2402 # $book_bottom - the references to the entities, which are
2403 # added in the main SGML file at the desired position.
2404 #############################################################################
2407 my ($book_top, $book_bottom) = @_;
2409 my $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top";
2410 my $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top.new";
2412 open (OUTPUT, ">$new_file")
2413 || die "Can't create $new_file: $!";
2414 print OUTPUT $book_top;
2417 &UpdateFileIfChanged ($old_file, $new_file, 0);
2420 $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom";
2421 $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom.new";
2423 open (OUTPUT, ">$new_file")
2424 || die "Can't create $new_file: $!";
2425 print OUTPUT $book_bottom;
2428 &UpdateFileIfChanged ($old_file, $new_file, 0);
2431 # If the main SGML/XML file hasn't been created yet, we create it here.
2432 # The user can tweak it later.
2433 if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
2434 open (OUTPUT, ">$MAIN_SGML_FILE")
2435 || die "Can't create $MAIN_SGML_FILE: $!";
2437 if ($OUTPUT_FORMAT eq "xml") {
2439 <?xml version="1.0"?>
2440 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
2441 "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
2443 <!ENTITY % local.common.attrib "xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'">
2449 <!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
2458 <title>$MODULE Reference Manual</title>
2460 for $MODULE [VERSION].
2461 The latest version of this documentation can be found on-line at
2462 <ulink role="online-location" url="http://[SERVER]/$MODULE/index.html">http://[SERVER]/$MODULE/</ulink>.
2467 <title>[Insert title here]</title>
2471 if (-e $OBJECT_TREE_FILE) {
2473 <chapter id="object-tree">
2474 <title>Object Hierarchy</title>
2475 <xi:include href="xml/tree_index.sgml"/>
2481 <index id="api-index-full">
2482 <title>API Index</title>
2483 <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
2486 <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
2495 #############################################################################
2496 # Function : CreateValidSGML
2497 # Description : This turns any chars which are used in SGML into entities,
2498 # e.g. '<' into '<'
2499 # Arguments : $text - the text to turn into proper SGML.
2500 #############################################################################
2502 sub CreateValidSGML {
2504 $text =~ s/&/&/g; # Do this first, or the others get messed up.
2505 $text =~ s/</</g;
2506 $text =~ s/>/>/g;
2507 # browers render single tabs inconsistently
2508 $text =~ s/([^\s])\t([^\s])/$1 $2/g;
2512 #############################################################################
2513 # Function : ConvertSGMLChars
2514 # Description : This is used for text in source code comment blocks, to turn
2515 # chars which are used in SGML into entities, e.g. '<' into
2516 # '<'. Depending on $SGML_MODE, this is done
2517 # unconditionally or only if the character doesn't seem to be
2518 # part of an SGML construct (tag or entity reference).
2519 # Arguments : $text - the text to turn into proper SGML.
2520 #############################################################################
2522 sub ConvertSGMLChars {
2523 my ($symbol, $text) = @_;
2526 # For the SGML mode only convert to entities outside CDATA sections.
2527 return &ModifyXMLElements ($text, $symbol,
2528 "<!\\[CDATA\\[|<programlisting[^>]*>",
2529 \&ConvertSGMLCharsEndTag,
2530 \&ConvertSGMLCharsCallback);
2532 # For the simple non-sgml mode, convert to entities everywhere.
2533 $text =~ s/&/&/g; # Do this first, or the others get messed up.
2534 $text =~ s/</</g;
2535 $text =~ s/>/>/g;
2541 sub ConvertSGMLCharsEndTag {
2542 if ($_[0] eq "<!\[CDATA\[") {
2545 return "</programlisting>";
2549 sub ConvertSGMLCharsCallback {
2550 my ($text, $symbol, $tag) = @_;
2552 if ($tag =~ m/^<programlisting/) {
2553 # We can handle <programlisting> specially here.
2554 return &ModifyXMLElements ($text, $symbol,
2556 \&ConvertSGMLCharsEndTag,
2557 \&ConvertSGMLCharsCallback2);
2558 } elsif ($tag eq "") {
2559 # If we're not in CDATA convert to entities.
2560 $text =~ s/&(?![a-zA-Z#]+;)/&/g; # Do this first, or the others get messed up.
2561 $text =~ s/<(?![a-zA-Z\/!])/</g;
2562 $text =~ s/(?<![a-zA-Z0-9"'\/-])>/>/g;
2564 # Handle "#include <xxxxx>"
2565 $text =~ s/#include(\s+)<([^>]+)>/#include$1<$2>/g;
2571 sub ConvertSGMLCharsCallback2 {
2572 my ($text, $symbol, $tag) = @_;
2574 # If we're not in CDATA convert to entities.
2575 # We could handle <programlisting> differently, though I'm not sure it helps.
2577 # replace only if its not a tag
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 #############################################################################
2590 # Function : ExpandAnnotation
2591 # Description : This turns annotations into acrony tags.
2592 # Arguments : $symbol - the symbol being documented, for error messages.
2593 # $text - the text to expand.
2594 #############################################################################
2595 sub ExpandAnnotation {
2596 my ($symbol, $param_desc) = @_;
2597 my $param_annotations = "";
2599 if ($param_desc =~ m%\s*\((.*)\):%) {
2602 my $annotation_extra = "";
2605 @annotations = split(/\)\s*\(/,$1);
2606 foreach $annotation (@annotations) {
2607 # need to search for the longest key-match in %AnnotationDefinition
2609 my $match_annotation="";
2611 foreach $annotationdef (keys %AnnotationDefinition) {
2612 if ($annotation =~ m/^$annotationdef/) {
2613 if (length($annotationdef)>$match_length) {
2614 $match_length=length($annotationdef);
2615 $match_annotation=$annotationdef;
2619 if ($match_annotation ne "") {
2620 if ($annotation =~ m%$match_annotation\s+(.*)%) {
2621 $annotation_extra = " $1";
2623 $AnnotationsUsed{$match_annotation} = 1;
2624 $param_annotations .= "[<acronym>$match_annotation</acronym>$annotation_extra]";
2627 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2628 "unknown annotation \"$annotation\" in documentation for $symbol.");
2629 $param_annotations .= "[$annotation]";
2633 $param_desc =~ m/^(.*?)\.*\s*$/s;
2634 $param_desc = "$1. ";
2636 if ($param_annotations ne "") {
2637 $param_annotations = "<emphasis role=\"annotation\">$param_annotations</emphasis>";
2639 return ($param_desc, $param_annotations);
2642 #############################################################################
2643 # Function : ExpandAbbreviations
2644 # Description : This turns the abbreviations function(), macro(), @param,
2645 # %constant, and #symbol into appropriate DocBook markup.
2646 # CDATA sections and <programlisting> parts are skipped.
2647 # Arguments : $symbol - the symbol being documented, for error messages.
2648 # $text - the text to expand.
2649 #############################################################################
2651 sub ExpandAbbreviations {
2652 my ($symbol, $text) = @_;
2654 # Convert "|[" and "]|" into the start and end of program listing examples.
2655 $text =~ s%\|\[%<informalexample><programlisting>%g;
2656 $text =~ s%\]\|%</programlisting></informalexample>%g;
2657 # TODO: check for a xml comment after |[ and pick the language attribute from
2660 # keep CDATA unmodified, preserve ulink tags (ideally we preseve all tags
2662 return &ModifyXMLElements ($text, $symbol,
2663 "<!\\[CDATA\\[|<ulink[^>]*>|<programlisting[^>]*>|<!DOCTYPE",
2664 \&ExpandAbbreviationsEndTag,
2665 \&ExpandAbbreviationsCallback);
2669 # Returns the end tag corresponding to the given start tag.
2670 sub ExpandAbbreviationsEndTag {
2671 my ($start_tag) = @_;
2673 if ($start_tag eq "<!\[CDATA\[") {
2675 } elsif ($start_tag eq "<!DOCTYPE") {
2677 } elsif ($start_tag =~ m/<(\w+)/) {
2682 # Called inside or outside each CDATA or <programlisting> section.
2683 sub ExpandAbbreviationsCallback {
2684 my ($text, $symbol, $tag) = @_;
2686 if ($tag =~ m/^<programlisting/) {
2687 # Handle any embedded CDATA sections.
2688 return &ModifyXMLElements ($text, $symbol,
2690 \&ExpandAbbreviationsEndTag,
2691 \&ExpandAbbreviationsCallback2);
2692 } elsif ($tag eq "") {
2693 # We are outside any CDATA or <programlisting> sections, so we expand
2694 # any gtk-doc abbreviations.
2696 # Convert 'function()' or 'macro()'.
2697 # if there is abc_*_def() we don't want to make a link to _def()
2698 # FIXME: also handle abc(....) : but that would need to be done recursively :/
2699 $text =~ s/([^\*.\w])(\w+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2700 # handle #Object.func()
2701 $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2703 # Convert '@param', but not '\@param'.
2704 $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)/$1<parameter>$2<\/parameter>/g;
2705 $text =~ s/\\\@/\@/g;
2707 # Convert '%constant', but not '\%constant'.
2708 # Also allow negative numbers, e.g. %-1.
2709 $text =~ s/(\A|[^\\])\%(-?\w+)/$1.&MakeXRef($2, &tagify($2, "literal"));/eg;
2710 $text =~ s/\\\%/\%/g;
2712 # Convert '#symbol', but not '\#symbol'.
2713 $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)/$1.&MakeHashXRef($2, "type");/eg;
2717 # FIXME: should we skip urls that are already tagged? (e.g. <literal>http://...</literal>)
2718 # this is apparently also called for markup and not just for plain text
2720 #$text =~ s%(http|https|ftp)://(.*?)((?:\s|,|\)|\]|\<|\.\s))%<ulink url="$1://$2">$2</ulink>$3%g;
2722 # TODO: optionally check all words from $text against internal symbols and
2723 # warn if those could be xreffed, but miss a %,# or ()
2729 # This is called inside a <programlisting>
2730 sub ExpandAbbreviationsCallback2 {
2731 my ($text, $symbol, $tag) = @_;
2734 # We are inside a <programlisting> but outside any CDATA sections,
2735 # so we expand any gtk-doc abbreviations.
2736 # FIXME: why is this different from &ExpandAbbreviationsCallback(),
2737 # why not just call it
2738 $text =~ s/#(\w+)/&MakeHashXRef($1, "");/eg;
2745 my ($symbol, $tag) = @_;;
2748 # Check for things like '#include', '#define', and skip them.
2749 if ($PreProcessorDirectives{$symbol}) {
2753 # Get rid of any special '-struct' suffix.
2754 $text =~ s/-struct$//;
2756 # If the symbol is in the form "Object::signal", then change the symbol to
2757 # "Object-signal" and use "signal" as the text.
2758 if ($symbol =~ s/::/-/) {
2762 # If the symbol is in the form "Object:property", then change the symbol to
2763 # "Object--property" and use "property" as the text.
2764 if ($symbol =~ s/:/--/) {
2769 $text = tagify ($text, $tag);
2772 return &MakeXRef($symbol, $text);
2776 #############################################################################
2777 # Function : ModifyXMLElements
2778 # Description : Looks for given XML element tags within the text, and calls
2779 # the callback on pieces of text inside & outside those elements.
2780 # Used for special handling of text inside things like CDATA
2781 # and <programlisting>.
2782 # Arguments : $text - the text.
2783 # $symbol - the symbol currently being documented (only used for
2785 # $start_tag_regexp - the regular expression to match start tags.
2786 # e.g. "<!\\[CDATA\\[|<programlisting[^>]*>" to match
2787 # CDATA sections or programlisting elements.
2788 # $end_tag_func - function which is passed the matched start tag
2789 # and should return the appropriate end tag string.
2790 # $callback - callback called with each part of the text. It is
2791 # called with a piece of text, the symbol being
2792 # documented, and the matched start tag or "" if the text
2793 # is outside the XML elements being matched.
2794 #############################################################################
2795 sub ModifyXMLElements {
2796 my ($text, $symbol, $start_tag_regexp, $end_tag_func, $callback) = @_;
2797 my ($before_tag, $start_tag, $end_tag_regexp, $end_tag);
2800 while ($text =~ m/$start_tag_regexp/s) {
2801 $before_tag = $`; # Prematch for last successful match string
2802 $start_tag = $&; # Last successful match
2803 $text = $'; # Postmatch for last successful match string
2805 $result .= &$callback ($before_tag, $symbol, "");
2806 $result .= $start_tag;
2808 # get the mathing end-tag for current tag
2809 $end_tag_regexp = &$end_tag_func ($start_tag);
2811 if ($text =~ m/$end_tag_regexp/s) {
2816 $result .= &$callback ($before_tag, $symbol, $start_tag);
2817 $result .= $end_tag;
2819 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2820 "Can't find tag end: $end_tag_regexp in docs for: $symbol.");
2821 # Just assume it is all inside the tag.
2822 $result .= &$callback ($text, $symbol, $start_tag);
2827 # Handle any remaining text outside the tags.
2828 $result .= &$callback ($text, $symbol, "");
2837 # Adds a tag around some text.
2838 # e.g tagify("Text", "literal") => "<literal>Text</literal>".
2840 my ($text, $elem) = @_;
2841 return "<" . $elem . ">" . $text . "</" . $elem . ">";
2845 #############################################################################
2846 # Function : MakeXRef
2847 # Description : This returns a cross-reference link to the given symbol.
2848 # Though it doesn't try to do this for a few standard C types
2849 # that it knows won't be in the documentation.
2850 # Arguments : $symbol - the symbol to try to create a XRef to.
2851 # $text - text text to put inside the XRef, defaults to $symbol
2852 #############################################################################
2855 my ($symbol, $text) = ($_[0], $_[1]);
2857 $symbol =~ s/^\s+//;
2858 $symbol =~ s/\s+$//;
2860 if (!defined($text)) {
2863 # Get rid of special '-struct' suffix.
2864 $text =~ s/-struct$//;
2867 if ($symbol =~ m/ /) {
2871 #print "Getting type link for $symbol -> $text\n";
2873 my $symbol_id = &CreateValidSGMLID ($symbol);
2874 return "<link linkend=\"$symbol_id\">$text</link>";
2878 #############################################################################
2879 # Function : MakeIndexterms
2880 # Description : This returns a indexterm elements for the given symbol
2881 # Arguments : $symbol - the symbol to create indexterms for
2882 #############################################################################
2884 sub MakeIndexterms {
2885 my ($symbol, $id) = @_;
2889 # make the index useful, by ommiting the namespace when sorting
2890 if ($NAME_SPACE ne "") {
2891 if ($symbol =~ m/^$NAME_SPACE\_?(.*)/i) {
2892 $sortas=" sortas=\"$1\"";
2896 if (exists $Deprecated{$symbol}) {
2897 $terms .= "<indexterm zone=\"$id\" role=\"deprecated\"><primary$sortas>$symbol</primary></indexterm>";
2898 $IndexEntriesDeprecated{$symbol}=$id;
2899 $IndexEntriesFull{$symbol}=$id;
2901 if (exists $Since{$symbol}) {
2902 my $since = $Since{$symbol};
2906 $terms .= "<indexterm zone=\"$id\" role=\"$since\"><primary$sortas>$symbol</primary></indexterm>";
2908 $IndexEntriesSince{$symbol}=$id;
2909 $IndexEntriesFull{$symbol}=$id;
2912 $terms .= "<indexterm zone=\"$id\"><primary$sortas>$symbol</primary></indexterm>";
2913 $IndexEntriesFull{$symbol}=$id;
2919 #############################################################################
2920 # Function : MakeDeprecationNote
2921 # Description : This returns a deprecation warning for the given symbol.
2922 # Arguments : $symbol - the symbol to try to create a warning for.
2923 #############################################################################
2925 sub MakeDeprecationNote {
2926 my ($symbol) = $_[0];
2929 if (exists $Deprecated{$symbol}) {
2930 $desc .= "<warning>";
2932 if ($Deprecated{$symbol} =~ /^\s*([0-9\.]+)\s*:/) {
2933 $desc .= "<para><literal>$symbol</literal> has been deprecated since version $1 and should not be used in newly-written code.";
2935 $desc .= "<para><literal>$symbol</literal> is deprecated and should not be used in newly-written code.";
2937 if ($Deprecated{$symbol} ne "") {
2938 $note = &ExpandAbbreviations($symbol, $Deprecated{$symbol});
2939 $note =~ s/^\s*([0-9\.]+)\s*:\s*//;
2942 $note =~ s%\n{2,}%\n</para>\n<para>\n%g;
2943 $desc .= " " . $note;
2945 $desc .= "</para></warning>\n";
2950 #############################################################################
2951 # Function : MakeConditionDescription
2952 # Description : This returns a sumary of conditions for the given symbol.
2953 # Arguments : $symbol - the symbol to try to create the sumary.
2954 #############################################################################
2956 sub MakeConditionDescription {
2957 my ($symbol) = $_[0];
2960 if (exists $Deprecated{$symbol}) {
2965 if ($Deprecated{$symbol} =~ /^\s*(.*?)\s*$/) {
2966 $desc .= "deprecated:$1";
2968 $desc .= "deprecated";
2972 if (exists $Since{$symbol}) {
2977 if ($Since{$symbol} =~ /^\s*(.*?)\s*$/) {
2978 $desc .= "since:$1";
2984 if (exists $StabilityLevel{$symbol}) {
2988 $desc .= "stability:".$StabilityLevel{$symbol};
2992 $desc=" condition=\"".$desc."\"";
2993 #print "condition for '$symbol' = '$desc'\n";
2998 #############################################################################
2999 # Function : GetHierarchy
3000 # Description : Returns the DocBook output describing the ancestors and
3001 # immediate children of a GObject subclass. It uses the
3002 # global @Objects and @ObjectLevels arrays to walk the tree.
3003 # Arguments : $object - the GtkObject subclass.
3004 #############################################################################
3009 # Find object in the objects array.
3015 for ($i = 0; $i < @Objects; $i++) {
3017 if ($ObjectLevels[$i] <= $level) {
3020 elsif ($ObjectLevels[$i] == $level + 1) {
3021 push (@children, $Objects[$i]);
3024 elsif ($Objects[$i] eq $object) {
3027 $level = $ObjectLevels[$i];
3034 # Walk up the hierarchy, pushing ancestors onto the ancestors array.
3036 push (@ancestors, $object);
3037 #print "Level: $level\n";
3038 while ($level > 1) {
3040 if ($ObjectLevels[$j] < $level) {
3041 push (@ancestors, $Objects[$j]);
3042 $level = $ObjectLevels[$j];
3043 #print "Level: $level\n";
3047 # Output the ancestors list, indented and with links.
3048 my $hierarchy = "<synopsis>\n";
3050 for ($i = $#ancestors; $i >= 0; $i--) {
3052 # Don't add a link to the current object, i.e. when i == 0.
3054 my $ancestor_id = &CreateValidSGMLID ($ancestors[$i]);
3055 $link_text = "<link linkend=\"$ancestor_id\">$ancestors[$i]</link>";
3057 $link_text = "$ancestors[$i]";
3060 $hierarchy .= " $link_text\n";
3062 # $hierarchy .= ' ' x ($level * 6 - 3) . "|\n";
3063 $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3067 for ($i = 0; $i <= $#children; $i++) {
3068 my $id = &CreateValidSGMLID ($children[$i]);
3069 my $link_text = "<link linkend=\"$id\">$children[$i]</link>";
3070 $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3072 $hierarchy .= "</synopsis>\n";
3078 #############################################################################
3079 # Function : GetInterfaces
3080 # Description : Returns the DocBook output describing the interfaces
3081 # implemented by a class. It uses the global %Interfaces hash.
3082 # Arguments : $object - the GtkObject subclass.
3083 #############################################################################
3090 # Find object in the objects array.
3091 if (exists($Interfaces{$object})) {
3092 my @ifaces = split(' ', $Interfaces{$object});
3097 for ($i = 0; $i <= $#ifaces; $i++) {
3098 my $id = &CreateValidSGMLID ($ifaces[$i]);
3099 $text .= " <link linkend=\"$id\">$ifaces[$i]</link>";
3100 if ($i < $#ifaces - 1) {
3103 elsif ($i < $#ifaces) {
3118 #############################################################################
3119 # Function : GetImplementations
3120 # Description : Returns the DocBook output describing the implementations
3121 # of an interface. It uses the global %Interfaces hash.
3122 # Arguments : $object - the GtkObject subclass.
3123 #############################################################################
3125 sub GetImplementations {
3130 foreach my $key (keys %Interfaces) {
3131 if ($Interfaces{$key} =~ /\b$object\b/) {
3132 push (@impls, $key);
3136 @impls = sort @impls;
3139 $object is implemented by
3141 for ($i = 0; $i <= $#impls; $i++) {
3142 my $id = &CreateValidSGMLID ($impls[$i]);
3143 $text .= " <link linkend=\"$id\">$impls[$i]</link>";
3144 if ($i < $#impls - 1) {
3147 elsif ($i < $#impls) {
3162 #############################################################################
3163 # Function : GetPrerequisites
3164 # Description : Returns the DocBook output describing the prerequisites
3165 # of an interface. It uses the global %Prerequisites hash.
3166 # Arguments : $iface - the interface.
3167 #############################################################################
3169 sub GetPrerequisites {
3174 if (exists($Prerequisites{$iface})) {
3179 my @prereqs = split(' ', $Prerequisites{$iface});
3180 for ($i = 0; $i <= $#prereqs; $i++) {
3181 my $id = &CreateValidSGMLID ($prereqs[$i]);
3182 $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
3183 if ($i < $#prereqs - 1) {
3186 elsif ($i < $#prereqs) {
3200 #############################################################################
3201 # Function : GetDerived
3202 # Description : Returns the DocBook output describing the derived interfaces
3203 # of an interface. It uses the global %Prerequisites hash.
3204 # Arguments : $iface - the interface.
3205 #############################################################################
3213 foreach my $key (keys %Prerequisites) {
3214 if ($Prerequisites{$key} =~ /\b$iface\b/) {
3215 push (@derived, $key);
3218 if ($#derived >= 0) {
3219 @derived = sort @derived;
3222 $iface is required by
3224 for ($i = 0; $i <= $#derived; $i++) {
3225 my $id = &CreateValidSGMLID ($derived[$i]);
3226 $text .= " <link linkend=\"$id\">$derived[$i]</link>";
3227 if ($i < $#derived - 1) {
3230 elsif ($i < $#derived) {
3245 #############################################################################
3246 # Function : GetSignals
3247 # Description : Returns the synopsis and detailed description DocBook output
3248 # for the signal handlers of a given GtkObject subclass.
3249 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
3250 #############################################################################
3258 for ($i = 0; $i <= $#SignalObjects; $i++) {
3259 if ($SignalObjects[$i] eq $object) {
3260 #print "Found signal: $SignalNames[$i]\n";
3261 my $name = $SignalNames[$i];
3262 my $symbol = "${object}::${name}";
3263 my $id = &CreateValidSGMLID ("$object-$name");
3265 my $pad = ' ' x (46 - length($name));
3266 $synop .= " "<link linkend=\"$id\">$name</link>"$pad ";
3268 $desc .= "<refsect2 id=\"$id\" role=\"signal\"><title>The <literal>"$name"</literal> signal</title>\n";
3269 $desc .= MakeIndexterms($symbol, $id);
3271 $desc .= OutputSymbolExtraLinks($symbol);
3273 $desc .= "<programlisting>";
3275 $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
3276 my $type_modifier = defined($1) ? $1 : "";
3279 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
3281 my $ret_type_len = length ($type_modifier) + length ($pointer)
3283 my $ret_type_output = "$type_modifier$xref$pointer"
3284 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
3286 $desc .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
3288 my $sourceparams = $SourceSymbolParams{$symbol};
3289 my @params = split ("\n", $SignalPrototypes[$i]);
3292 my $type_len = length("gpointer");
3293 my $name_len = length("user_data");
3294 # do two passes, the first one is to calculate padding
3295 for ($l = 0; $l < 2; $l++) {
3296 for ($j = 0; $j <= $#params; $j++) {
3297 # allow alphanumerics, '_', '[' & ']' in param names
3298 if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
3301 if (defined($sourceparams)) {
3302 $name = $$sourceparams[$PARAM_FIELD_COUNT * $j];
3307 if (!defined($name)) {
3311 if (length($type) + length($pointer) > $type_len) {
3312 $type_len = length($type) + length($pointer);
3314 if (length($name) > $name_len) {
3315 $name_len = length($name);
3319 $xref = &MakeXRef ($type, &tagify($type, "type"));
3320 $pad = ' ' x ($type_len - length($type) - length($pointer));
3321 $desc .= "$xref$pad $pointer$name,\n";
3322 $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
3325 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3326 "Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]");
3330 $xref = &MakeXRef ("gpointer", &tagify("gpointer", "type"));
3331 $pad = ' ' x ($type_len - length("gpointer"));
3332 $desc .= "$xref$pad user_data)";
3334 my $flags = $SignalFlags[$i];
3335 my $flags_string = "";
3337 if (defined ($flags)) {
3338 if ($flags =~ m/f/) {
3339 $flags_string = "Run First";
3341 elsif ($flags =~ m/l/) {
3342 $flags_string = "Run Last";
3344 elsif ($flags =~ m/c/) {
3345 $flags_string = "Cleanup";
3347 if ($flags =~ m/r/) {
3348 if ($flags_string) { $flags_string .= " / "; }
3349 $flags_string .= "No Recursion";
3351 if ($flags =~ m/d/) {
3352 if ($flags_string) { $flags_string .= " / "; }
3353 $flags_string .= "Has Details";
3355 if ($flags =~ m/a/) {
3356 if ($flags_string) { $flags_string .= " / "; }
3357 $flags_string .= "Action";
3359 if ($flags =~ m/h/) {
3360 if ($flags_string) { $flags_string .= " / "; }
3361 $flags_string .= "No Hooks";
3367 $synop .= ": $flags_string\n";
3369 $pad = ' ' x (5 + $name_len - length("user_data"));
3370 $desc .= "$pad : $flags_string</programlisting>\n";
3375 $desc .= "</programlisting>\n";
3378 $desc .= &MakeDeprecationNote($symbol);
3380 my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
3381 my $parameters_output = 0;
3383 $AllSymbols{$symbol} = 1;
3384 if (defined ($SymbolDocs{$symbol})) {
3385 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3387 # Try to insert the parameter table at the author's desired
3388 # position. Otherwise we need to tag it onto the end.
3389 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
3390 $parameters_output = 1;
3392 $desc .= $symbol_docs;
3394 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
3395 $AllDocumentedSymbols{$symbol} = 1;
3399 if ($parameters_output == 0) {
3400 $desc .= $parameters;
3402 $desc .= OutputSymbolTraits ($symbol);
3403 $desc .= "</refsect2>";
3406 return ($synop, $desc);
3410 #############################################################################
3411 # Function : GetArgs
3412 # Description : Returns the synopsis and detailed description DocBook output
3413 # for the Args of a given GtkObject subclass.
3414 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
3415 #############################################################################
3421 my $child_synop = "";
3422 my $child_desc = "";
3423 my $style_synop = "";
3424 my $style_desc = "";
3427 for ($i = 0; $i <= $#ArgObjects; $i++) {
3428 if ($ArgObjects[$i] eq $object) {
3429 #print "Found arg: $ArgNames[$i]\n";
3430 my $name = $ArgNames[$i];
3431 my $flags = $ArgFlags[$i];
3432 my $flags_string = "";
3436 if ($flags =~ m/c/) {
3437 $kind = "child property";
3440 elsif ($flags =~ m/s/) {
3441 $kind = "style property";
3448 # Remember only one colon so we don't clash with signals.
3449 my $symbol = "${object}:${name}";
3450 # use two dashes and ev. an extra separator here for the same reason.
3451 my $id = &CreateValidSGMLID ("$object--$id_sep$name");
3453 my $type = $ArgTypes[$i];
3455 my $range = $ArgRanges[$i];
3456 my $range_output = CreateValidSGML ($range);
3457 my $default = $ArgDefaults[$i];
3458 my $default_output = CreateValidSGML ($default);
3460 if ($type eq "GtkString") {
3463 if ($type eq "GtkSignal") {
3464 $type = "GtkSignalFunc, gpointer";
3465 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
3466 . &MakeXRef ("gpointer");
3467 } elsif ($type =~ m/^(\w+)\*$/) {
3468 $type_output = &MakeXRef ($1, &tagify($1, "type")) . "*";
3470 $type_output = &MakeXRef ($type, &tagify($type, "type"));
3473 if ($flags =~ m/r/) {
3474 $flags_string = "Read";
3476 if ($flags =~ m/w/) {
3477 if ($flags_string) { $flags_string .= " / "; }
3478 $flags_string .= "Write";
3480 if ($flags =~ m/x/) {
3481 if ($flags_string) { $flags_string .= " / "; }
3482 $flags_string .= "Construct";
3484 if ($flags =~ m/X/) {
3485 if ($flags_string) { $flags_string .= " / "; }
3486 $flags_string .= "Construct Only";
3489 $AllSymbols{$symbol} = 1;
3491 if (defined($SymbolDocs{$symbol}) &&
3492 !IsEmptyDoc($SymbolDocs{$symbol})) {
3493 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3494 #print ".. [$SymbolDocs{$symbol}][$blurb]\n";
3495 $AllDocumentedSymbols{$symbol} = 1;
3498 if (!($ArgBlurbs[$i] eq "")) {
3499 $AllDocumentedSymbols{$symbol} = 1;
3501 # FIXME: print a warning?
3502 #print ".. no description\n";
3504 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
3507 my $pad1 = " " x (24 - length ($name));
3508 my $pad2 = " " x (20 - length ($type));
3510 my $arg_synop = " "<link linkend=\"$id\">$name</link>"$pad1 $type_output $pad2 : $flags_string\n";
3511 my $arg_desc = "<refsect2 id=\"$id\" role=\"property\"><title>The <literal>"$name"</literal> $kind</title>\n";
3512 $arg_desc .= MakeIndexterms($symbol, $id);
3514 $arg_desc .= OutputSymbolExtraLinks($symbol);
3516 $arg_desc .= "<programlisting> "$name"$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
3517 $arg_desc .= &MakeDeprecationNote($symbol);
3518 $arg_desc .= $blurb;
3520 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
3522 if ($default ne "") {
3523 $arg_desc .= "<para>Default value: $default_output</para>\n";
3525 $arg_desc .= OutputSymbolTraits ($symbol);
3526 $arg_desc .= "</refsect2>\n";
3528 if ($flags =~ m/c/) {
3529 $child_synop .= $arg_synop;
3530 $child_desc .= $arg_desc;
3532 elsif ($flags =~ m/s/) {
3533 $style_synop .= $arg_synop;
3534 $style_desc .= $arg_desc;
3537 $synop .= $arg_synop;
3542 return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
3546 #############################################################################
3547 # Function : ReadSourceDocumentation
3548 # Description : This reads in the documentation embedded in comment blocks
3549 # in the source code (for Gnome).
3551 # Parameter descriptions override any in the template files.
3552 # Function descriptions are placed before any description from
3553 # the template files.
3555 # It recursively descends the source directory looking for .c
3556 # files and scans them looking for specially-formatted comment
3559 # Arguments : $source_dir - the directory to scan.
3560 #############m###############################################################
3562 sub ReadSourceDocumentation {
3563 my ($source_dir) = @_;
3564 my ($file, $dir, @suffix_list, $suffix);
3565 #print "Scanning source directory: $source_dir\n";
3567 # This array holds any subdirectories found.
3570 @suffix_list = split (/,/, $SOURCE_SUFFIXES);
3572 opendir (SRCDIR, $source_dir)
3573 || die "Can't open source directory $source_dir: $!";
3575 foreach $file (readdir (SRCDIR)) {
3576 if ($file =~ /^\./) {
3578 } elsif (-d "$source_dir/$file") {
3579 push (@subdirs, $file);
3580 } elsif (@suffix_list) {
3581 foreach $suffix (@suffix_list) {
3582 if ($file =~ m/\.\Q${suffix}\E$/) {
3583 &ScanSourceFile ("$source_dir/$file");
3586 } elsif ($file =~ m/\.[ch]$/) {
3587 &ScanSourceFile ("$source_dir/$file");
3592 # Now recursively scan the subdirectories.
3593 foreach $dir (@subdirs) {
3594 next if ($IGNORE_FILES =~ m/(\s|^)\Q${dir}\E(\s|$)/);
3595 &ReadSourceDocumentation ("$source_dir/$dir");
3600 #############################################################################
3601 # Function : ScanSourceFile
3602 # Description : Scans one source file looking for specially-formatted comment
3603 # blocks. Later &MergeSourceDocumentation is used to merge any
3604 # documentation found with the documentation already read in
3605 # from the template files.
3607 # Arguments : $file - the file to scan.
3608 #############################################################################
3610 sub ScanSourceFile {
3614 if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
3617 &LogWarning ($file, 1, "Can't find basename for this filename.");
3621 # Check if the basename is in the list of files to ignore.
3622 if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
3626 #print "DEBUG: Scanning $file\n";
3628 open (SRCFILE, $file)
3629 || die "Can't open $file: $!";
3630 my $in_comment_block = 0;
3632 my ($in_description, $in_return, $in_since, $in_stability, $in_deprecated);
3633 my ($description, $return_desc, $return_start, $return_style);
3634 my ($since_desc, $stability_desc, $deprecated_desc);
3636 my $ignore_broken_returns;
3639 # Look for the start of a comment block.
3640 if (!$in_comment_block) {
3641 if (m%^\s*/\*.*\*/%) {
3642 #one-line comment - not gtkdoc
3643 } elsif (m%^\s*/\*\*\s%) {
3644 #print "Found comment block start\n";
3646 $in_comment_block = 1;
3648 # Reset all the symbol data.
3650 $in_description = 0;
3659 $deprecated_desc = "";
3660 $stability_desc = "";
3661 $current_param = -1;
3662 $ignore_broken_returns = 0;
3668 # We're in a comment block. Check if we've found the end of it.
3671 # maybe its not even meant to be a gtk-doc comment?
3672 &LogWarning ($file, $., "Symbol name not found at the start of the comment block.");
3674 # Add the return value description onto the end of the params.
3676 push (@params, "Returns");
3677 push (@params, $return_desc);
3678 if ($return_style eq 'broken') {
3679 &LogWarning ($file, $., "Free-form return value description in $symbol. Use `Returns:' to avoid ambiguities.");
3682 # Convert special SGML characters
3683 $description = &ConvertSGMLChars ($symbol, $description);
3685 for ($k = 1; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3686 $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
3689 # Handle Section docs
3690 if ($symbol =~ m/SECTION:\s*(.*)/) {
3694 if (scalar %KnownSymbols) {
3695 if ((! defined($KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"})) || $KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"} != 1) {
3696 &LogWarning ($file, $., "Section $real_symbol is not defined in the $MODULE-section.txt file.");
3700 #print "SECTION DOCS found in source for : '$real_symbol'\n";
3701 $ignore_broken_returns = 1;
3702 for ($k = 0; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3703 #print " '".$params[$k]."'\n";
3704 $params[$k] = "\L$params[$k]";
3706 if ($params[$k] eq "short_description") {
3707 $key = "$TMPL_DIR/$real_symbol:Short_Description";
3708 } elsif ($params[$k] eq "see_also") {
3709 $key = "$TMPL_DIR/$real_symbol:See_Also";
3710 } elsif ($params[$k] eq "title") {
3711 $key = "$TMPL_DIR/$real_symbol:Title";
3712 } elsif ($params[$k] eq "stability") {
3713 $key = "$TMPL_DIR/$real_symbol:Stability_Level";
3714 } elsif ($params[$k] eq "section_id") {
3715 $key = "$TMPL_DIR/$real_symbol:Section_Id";
3716 } elsif ($params[$k] eq "include") {
3717 $key = "$TMPL_DIR/$real_symbol:Include";
3718 } elsif ($params[$k] eq "image") {
3719 $key = "$TMPL_DIR/$real_symbol:Image";
3721 if (defined($key)) {
3722 $SourceSymbolDocs{$key}=$params[$k+1];
3723 $SourceSymbolSourceFile{$key} = $file;
3724 $SourceSymbolSourceLine{$key} = $.;
3727 $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
3728 $SourceSymbolSourceFile{"$TMPL_DIR/$real_symbol:Long_Description"} = $file;
3729 $SourceSymbolSourceLine{"$TMPL_DIR/$real_symbol:Long_Description"} = $.;
3730 #$SourceSymbolTypes{$symbol} = "SECTION";
3732 #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
3733 $SourceSymbolDocs{$symbol} = $description;
3734 $SourceSymbolParams{$symbol} = [ @params ];
3735 # FIXME $SourceSymbolTypes{$symbol} = "STRUCT,SIGNAL,ARG,FUNCTION,MACRO";
3736 #if (defined $DeclarationTypes{$symbol}) {
3737 # $SourceSymbolTypes{$symbol} = $DeclarationTypes{$symbol}
3739 $SourceSymbolSourceFile{$symbol} = $file;
3740 $SourceSymbolSourceLine{$symbol} = $.;
3744 ($since_desc, my @extra_lines) = split ("\n", $since_desc);
3745 $since_desc =~ s/^\s+//;
3746 $since_desc =~ s/\s+$//;
3747 #print "Since($symbol) : [$since_desc]\n";
3748 $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
3749 if(scalar @extra_lines) {
3750 &LogWarning ($file, $., "multi-line since docs found");
3754 if ($stability_desc) {
3755 $stability_desc = &ParseStabilityLevel($stability_desc, $file, $., "Stability level for $symbol");
3756 $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
3759 if ($deprecated_desc) {
3760 if (exists $Deprecated{$symbol}) {
3763 # don't warn for signals and properties
3764 #if ($symbol !~ m/::?(.*)/) {
3765 if (defined $DeclarationTypes{$symbol}) {
3766 &LogWarning ($file, $.,
3767 "$symbol is deprecated in the inline comments, but no deprecation guards were found around the declaration.".
3768 " (See the --deprecated-guards option for gtkdoc-scan.)");
3771 $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
3775 $in_comment_block = 0;
3779 # Get rid of ' * ' at start of every line in the comment block.
3781 # But make sure we don't get rid of the newline at the end.
3785 #print "DEBUG: scanning :$_";
3787 # If we haven't found the symbol name yet, look for it.
3789 if (m%^\s*(SECTION:\s*\S+)%) {
3791 #print "SECTION DOCS found in source for : '$symbol'\n";
3792 $ignore_broken_returns = 1;
3793 } elsif (m%^\s*([\w:-]*\w)\s*:?\s*(\([a-z ]+\)\s*)*$%) {
3795 #print "SYMBOL DOCS found in source for : '$symbol'\n";
3800 # If we're in the return value description, add it to the end.
3802 # If we find another valid returns line, we assume that the first
3803 # one was really part of the description.
3804 if (m/^\s*(returns:|return\s+value:)/i) {
3805 if ($return_style eq 'broken') {
3806 $description .= $return_start . $return_desc;
3809 if ($return_style eq 'sane') {
3810 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3812 $return_style = 'sane';
3813 $ignore_broken_returns = 1;
3815 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3816 $description .= $return_start . $return_desc;
3818 $return_style = 'broken';
3820 } elsif (m%^\s*since:%i) {
3824 } elsif (m%^\s*stability:%i) {
3825 $stability_desc = $';
3828 } elsif (m%^\s*deprecated:%i) {
3829 $deprecated_desc = $';
3839 if (m/^\s*(returns:|return\s+value:)/i) {
3840 if ($return_style eq 'broken') {
3841 $description .= $return_start . $return_desc;
3844 if ($return_style eq 'sane') {
3845 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3847 $return_style = 'sane';
3848 $ignore_broken_returns = 1;
3852 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3854 $return_style = 'broken';
3858 } elsif (m%^\s*deprecated:%i) {
3859 $deprecated_desc = $';
3862 } elsif (m%^\s*stability:%i) {
3863 $stability_desc = $';
3872 if ($in_stability) {
3873 if (m/^\s*(returns:|return\s+value:)/i) {
3874 if ($return_style eq 'broken') {
3875 $description .= $return_start . $return_desc;
3878 if ($return_style eq 'sane') {
3879 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3881 $return_style = 'sane';
3882 $ignore_broken_returns = 1;
3886 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3888 $return_style = 'broken';
3892 } elsif (m%^\s*deprecated:%i) {
3893 $deprecated_desc = $';
3896 } elsif (m%^\s*since:%i) {
3901 $stability_desc .= $_;
3906 if ($in_deprecated) {
3907 if (m/^\s*(returns:|return\s+value:)/i) {
3908 if ($return_style eq 'broken') {
3909 $description .= $return_start . $return_desc;
3912 if ($return_style eq 'sane') {
3913 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3915 $return_style = 'sane';
3916 $ignore_broken_returns = 1;
3920 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3922 $return_style = 'broken';
3926 } elsif (m%^\s*since:%i) {
3930 } elsif (m%^\s*stability:%i) {
3931 $stability_desc = $';
3935 $deprecated_desc .= $_;
3940 # If we're in the description part, check for the 'Returns:' line.
3941 # If that isn't found, add the text to the end.
3942 if ($in_description) {
3943 # Get rid of 'Description:'
3944 s%^\s*Description:%%;
3946 if (m/^\s*(returns:|return\s+value:)/i) {
3947 if ($return_style eq 'broken') {
3948 $description .= $return_start . $return_desc;
3951 if ($return_style eq 'sane') {
3952 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3954 $return_style = 'sane';
3955 $ignore_broken_returns = 1;
3959 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3961 $return_style = 'broken';
3965 } elsif (m%^\s*since:%i) {
3969 } elsif (m%^\s*deprecated:%i) {
3970 $deprecated_desc = $';
3973 } elsif (m%^\s*stability:%i) {
3974 $stability_desc = $';
3983 # We must be in the parameters. Check for the empty line below them.
3985 $in_description = 1;
3989 # Look for a parameter name.
3990 if (m%^\s*@(\S+)\s*:\s*%) {
3991 my $param_name = $1;
3992 my $param_desc = $';
3994 #print "Found parameter: $param_name\n";
3995 # Allow '...' as the Varargs parameter.
3996 if ($param_name eq "...") {
3997 $param_name = "Varargs";
3999 if ("\L$param_name" eq "returns") {
4000 $return_style = 'sane';
4001 $ignore_broken_returns = 1;
4003 push (@params, $param_name);
4004 push (@params, $param_desc);
4005 $current_param += $PARAM_FIELD_COUNT;
4009 # We must be in the middle of a parameter description, so add it on
4010 # to the last element in @params.
4011 if ($current_param == -1) {
4012 &LogWarning ($file, $., "Parsing comment block file : parameter expected.");
4014 $params[$#params] .= $_;
4020 #############################################################################
4021 # Function : OutputMissingDocumentation
4022 # Description : Outputs report of documentation coverage to a file
4025 #############################################################################
4027 sub OutputMissingDocumentation {
4028 my $old_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.txt";
4029 my $new_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.new";
4031 my $n_documented = 0;
4032 my $n_incomplete = 0;
4038 my $buffer_deprecated = "";
4039 my $buffer_descriptions = "";
4041 open(UNDOCUMENTED, ">$new_undocumented_file")
4042 || die "Can't create $new_undocumented_file";
4044 foreach $symbol (sort (keys (%AllSymbols))) {
4045 # FIXME: should we print LogWarnings for undocumented stuff?
4047 #my $ssfile = &GetSymbolSourceFile($symbol);
4048 #my $ssline = &GetSymbolSourceLine($symbol);
4049 #my $location = "defined at " . (defined($ssfile)?$ssfile:"?") . ":" . (defined($ssline)?$ssline:"0") . "\n";
4051 if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include|Section_Id|Image)/) {
4053 if (exists ($AllDocumentedSymbols{$symbol})) {
4055 if (exists ($AllIncompleteSymbols{$symbol})) {
4057 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4058 #$buffer .= "\t0: ".$location;
4060 } elsif (exists $Deprecated{$symbol}) {
4061 if (exists ($AllIncompleteSymbols{$symbol})) {
4063 $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4064 #$buffer .= "\t1a: ".$location;
4066 $buffer_deprecated .= $symbol . "\n";
4067 #$buffer .= "\t1b: ".$location;
4070 if (exists ($AllIncompleteSymbols{$symbol})) {
4072 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4073 #$buffer .= "\t2a: ".$location;
4075 $buffer .= $symbol . "\n";
4076 #$buffer .= "\t2b: ".$location;
4079 } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
4081 #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
4082 #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
4083 #print "%%%% $symbol : $len1,$len2\n";
4084 if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
4085 || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
4088 # cut off the leading namespace ($TMPL_DIR)
4089 $symbol =~ m/^.*\/(.*)$/;
4090 $buffer_descriptions .= $1 . "\n";
4095 $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
4100 $percent = ($n_documented / $total) * 100.0;
4103 printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
4104 print UNDOCUMENTED "$n_documented symbols documented.\n";
4105 print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
4106 print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
4108 print UNDOCUMENTED $buffer;
4109 close (UNDOCUMENTED);
4111 return &UpdateFileIfChanged ($old_undocumented_file, $new_undocumented_file, 0);
4113 printf "%.0f%% symbol docs coverage", $percent;
4114 print "($n_documented symbols documented, $n_incomplete symbols incomplete, " . ($total - $n_documented) . " not documented)\n";
4115 print "See $MODULE-undocumented.txt for a list of missing docs.\nThe doc coverage percentage doesn't include intro sections.\n";
4119 #############################################################################
4120 # Function : OutputUndeclaredSymbols
4121 # Description : Outputs symbols that are listed in the section file, but not
4122 # declaration is found in the sources
4125 #############################################################################
4127 sub OutputUndeclaredSymbols {
4128 my $old_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.txt";
4129 my $new_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.new";
4131 open(UNDECLARED, ">$new_undeclared_file")
4132 || die "Can't create $new_undeclared_file";
4134 if (%UndeclaredSymbols) {
4135 print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
4136 print UNDECLARED "\n";
4137 print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
4141 return &UpdateFileIfChanged ($old_undeclared_file, $new_undeclared_file, 0);
4144 #############################################################################
4145 # Function : OutputUnusedSymbols
4146 # Description : Outputs symbols that are documented in comments, but not
4147 # declared in the sources
4150 #############################################################################
4152 sub OutputUnusedSymbols {
4154 my $old_unused_file = "$ROOT_DIR/$MODULE-unused.txt";
4155 my $new_unused_file = "$ROOT_DIR/$MODULE-unused.new";
4157 open (UNUSED, ">$new_unused_file")
4158 || die "Can't open $new_unused_file";
4160 foreach $symbol (sort keys (%Declarations)) {
4161 if (!defined ($DeclarationOutput{$symbol})) {
4162 print (UNUSED "$symbol\n");
4166 foreach $symbol (sort (keys (%AllUnusedSymbols))) {
4167 print (UNUSED "$symbol(" . $AllUnusedSymbols{$symbol} . ")\n");
4171 if ($num_unused != 0) {
4172 &LogWarning ($old_unused_file, 1, "$num_unused unused declarations.".
4173 "They should be added to $MODULE-sections.txt in the appropriate place.");
4176 return &UpdateFileIfChanged ($old_unused_file, $new_unused_file, 0);
4180 #############################################################################
4181 # Function : OutputAllSymbols
4182 # Description : Outputs list of all symbols to a file
4185 #############################################################################
4187 sub OutputAllSymbols {
4188 my $n_documented = 0;
4194 open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
4195 || die "Can't create $ROOT_DIR/$MODULE-symbols.txt: $!";
4197 foreach $symbol (sort (keys (%AllSymbols))) {
4198 print SYMBOLS $symbol . "\n";
4204 #############################################################################
4205 # Function : OutputSymbolsWithoutSince
4206 # Description : Outputs list of all symbols without a since tag to a file
4209 #############################################################################
4211 sub OutputSymbolsWithoutSince {
4212 my $n_documented = 0;
4218 open (SYMBOLS, ">$ROOT_DIR/$MODULE-nosince.txt")
4219 || die "Can't create $ROOT_DIR/$MODULE-nosince.txt: $!";
4221 foreach $symbol (sort (keys (%SourceSymbolDocs))) {
4222 if (!defined $Since{$symbol}) {
4223 print SYMBOLS $symbol . "\n";
4231 #############################################################################
4232 # Function : MergeSourceDocumentation
4233 # Description : This merges documentation read from a source file into the
4234 # documentation read in from a template file.
4236 # Parameter descriptions override any in the template files.
4237 # Function descriptions are placed before any description from
4238 # the template files.
4241 #############################################################################
4243 sub MergeSourceDocumentation {
4247 if (scalar %SymbolDocs) {
4248 @Symbols=keys (%SymbolDocs);
4249 #print "num existing entries: ".(scalar @Symbols)."\n";
4250 #print " ",$Symbols[0], " ",$Symbols[1],"\n";
4253 # filter scanned declarations, with what we suppress from -sections.txt
4255 foreach $symbol (keys (%Declarations)) {
4256 if (defined($KnownSymbols{$symbol}) && $KnownSymbols{$symbol} == 1) {
4260 # , add the rest from -sections.txt
4261 foreach $symbol (keys (%KnownSymbols)) {
4262 if ($KnownSymbols{$symbol} == 1) {
4266 # and add whats found in the source
4267 foreach $symbol (keys (%SourceSymbolDocs)) {
4270 @Symbols = keys (%tmp);
4271 #print "num source entries: ".(scalar @Symbols)."\n";
4273 foreach $symbol (@Symbols) {
4274 $AllSymbols{$symbol} = 1;
4276 my $have_tmpl_docs = 0;
4278 ## See if the symbol is documented in template
4279 my $tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4280 my $check_tmpl_doc =$tmpl_doc;
4281 # remove all xml-tags and whitespaces
4282 #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
4283 $check_tmpl_doc =~ s/<.*?>//g;
4284 $check_tmpl_doc =~ s/\s//g;
4286 if ($check_tmpl_doc ne "") {
4287 $have_tmpl_docs = 1;
4288 #print "## [$check_tmpl_doc]\n";
4293 if (exists ($SourceSymbolDocs{$symbol})) {
4294 my $type = $DeclarationTypes {$symbol};
4296 #print "merging [$symbol] from source\n";
4298 my $item = "Parameter";
4299 if (defined ($type)) {
4300 if ($type eq 'STRUCT') {
4302 } elsif ($type eq 'ENUM') {
4304 } elsif ($type eq 'UNION') {
4311 my $src_doc = $SourceSymbolDocs{$symbol};
4312 # remove leading and training whitespaces
4313 $src_doc =~ s/^\s+//;
4314 $src_doc =~ s/\s+$//;
4316 # Don't output warnings for overridden titles as titles are
4317 # automatically generated in the -sections.txt file, and thus they
4318 # are often overridden.
4319 if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
4320 # check if content is different
4321 if ($tmpl_doc ne $src_doc) {
4322 #print "[$tmpl_doc] [$src_doc]\n";
4323 &LogWarning ($SourceSymbolSourceFile{$symbol}, $SourceSymbolSourceLine{$symbol},
4324 "Documentation in template ".$SymbolSourceFile{$symbol}.":".$SymbolSourceLine{$symbol}." for $symbol being overridden by inline comments.");
4328 if ($src_doc ne "") {
4329 $AllDocumentedSymbols{$symbol} = 1;
4332 # Convert <!--PARAMETERS--> with any blank lines around it to
4333 # a </para> followed by <!--PARAMETERS--> followed by <para>.
4334 $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
4336 # Do not add <para> to nothing, it breaks missing docs checks.
4337 my $src_doc_para = "";
4338 if ($src_doc ne "") {
4339 # If there is a blank line, finish the paragraph and start another.
4340 $src_doc = &ConvertBlankLines ($src_doc, $symbol);
4341 $src_doc_para = "<para>\n$src_doc\n</para>";
4343 $src_doc_para =~ s%<para>\n<refsect2%<refsect2%gms;
4344 $src_doc_para =~ s%</refsect2>\n</para>%</refsect2>%gms;
4345 #print "$symbol : [$src_doc][$src_doc_para]\n";
4348 if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
4349 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4350 } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
4351 # For the title/summary/see also section docs we don't want to
4352 # add any <para> tags.
4353 $SymbolDocs{$symbol} = "$src_doc"
4355 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4359 if ($symbol =~ m/.*::.*/) {
4360 # For signals we prefer the param names from the source docs,
4361 # since the ones from the templates are likely to contain the
4362 # artificial argn names which are generated by gtkdoc-scangobj.
4363 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4364 # FIXME: we need to check for empty docs here as well!
4366 # The templates contain the definitive parameter names and order,
4367 # so we will not change that. We only override the actual text.
4368 my $tmpl_params = $SymbolParams{$symbol};
4369 if (!defined ($tmpl_params)) {
4370 #print "No merge needed for $symbol\n";
4371 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4372 # FIXME: we still like to get the number of params and merge
4373 # 1) we would noticed that params have been removed/renamed
4374 # 2) we would catch undocumented params
4375 # params are not (yet) exported in -decl.txt so that we
4376 # could easily grab them :/
4378 my $params = $SourceSymbolParams{$symbol};
4380 #print "Merge needed for $symbol, tmpl_params: ",$#$tmpl_params,", source_params: ",$#$params," \n";
4381 for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4382 my $tmpl_param_name = $$tmpl_params[$j];
4384 # Allow '...' as the Varargs parameter.
4385 if ($tmpl_param_name eq "...") {
4386 $tmpl_param_name = "Varargs";
4389 # Try to find the param in the source comment documentation.
4392 #print " try merge param $tmpl_param_name\n";
4393 for ($k = 0; $k <= $#$params; $k += $PARAM_FIELD_COUNT) {
4394 my $param_name = $$params[$k];
4395 my $param_desc = $$params[$k + 1];
4397 #print " test param $param_name\n";
4398 # We accept changes in case, since the Gnome source
4399 # docs contain a lot of these.
4400 if ("\L$param_name" eq "\L$tmpl_param_name") {
4403 # Override the description.
4404 $$tmpl_params[$j + 1] = $param_desc;
4406 # Set the name to "" to mark it as used.
4412 # If it looks like the parameters are there, but not
4413 # in the right place, try to explain a bit better.
4414 if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
4415 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4416 "Parameters for $symbol must start on the line immediately after the function or macro name.");
4420 # Now we output a warning if parameters have been described which
4422 for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
4423 my $param_name = $$params[$j];
4425 # the template builder cannot detect if a macro returns
4427 if(($type eq "MACRO") && ($param_name eq "Returns")) {
4428 # FIXME: do we need to add it then to tmpl_params[] ?
4429 my $num=$#$tmpl_params;
4430 #print " adding Returns: to macro docs for $symbol.\n";
4431 $$tmpl_params[$num+1]="Returns";
4432 $$tmpl_params[$num+2]=$$params[$j+1];
4435 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4436 "$item described in source code comment block but does not exist. $type: $symbol $item: $param_name.");
4442 if ($have_tmpl_docs) {
4443 $AllDocumentedSymbols{$symbol} = 1;
4444 #print "merging [$symbol] from template\n";
4447 #print "[$symbol] undocumented\n";
4451 # if this symbol is documented, check if docs are complete
4452 $check_tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4453 # remove all xml-tags and whitespaces
4454 #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
4455 $check_tmpl_doc =~ s/<.*?>//g;
4456 $check_tmpl_doc =~ s/\s//g;
4457 if ($check_tmpl_doc ne "") {
4458 my $tmpl_params = $SymbolParams{$symbol};
4459 if (defined ($tmpl_params)) {
4460 my $type = $DeclarationTypes {$symbol};
4462 my $item = "Parameter";
4463 if (defined ($type)) {
4464 if ($type eq 'STRUCT') {
4466 } elsif ($type eq 'ENUM') {
4468 } elsif ($type eq 'UNION') {
4475 #print "Check param docs for $symbol, tmpl_params: ",$#$tmpl_params," entries, type=$type\n";
4477 if ($#$tmpl_params > 0) {
4479 for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4480 # Output a warning if the parameter is empty and
4481 # remember for stats.
4482 my $tmpl_param_name = $$tmpl_params[$j];
4483 my $tmpl_param_desc = $$tmpl_params[$j + 1];
4484 if ($tmpl_param_name ne "void" && $tmpl_param_desc !~ m/\S/) {
4485 if (exists ($AllIncompleteSymbols{$symbol})) {
4486 $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
4488 $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
4490 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4491 "$item description for $symbol"."::"."$tmpl_param_name is missing in source code comment block.");
4496 if ($#$tmpl_params == 0) {
4497 $AllIncompleteSymbols{$symbol}="<items>";
4498 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4499 "$item descriptions for $symbol are missing in source code comment block.");
4501 # $#$tmpl_params==-1 means we don't know about parameters
4502 # this unfortunately does not tell if there should be some
4507 #print "num doc entries: ".(scalar %SymbolDocs)."\n";
4510 #############################################################################
4511 # Function : IsEmptyDoc
4512 # Description : Check if a doc-string is empty. Its also regarded as empty if
4513 # it only consist of whitespace or e.g. FIXME.
4514 # Arguments : the doc-string
4515 #############################################################################
4519 if ($doc =~ /^\s*$/) {
4523 if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
4531 # This converts blank lines to "</para><para>", but only outside CDATA and
4532 # <programlisting> tags.
4533 sub ConvertBlankLines {
4534 return &ModifyXMLElements ($_[0], $_[1],
4535 "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
4536 \&ConvertBlankLinesEndTag,
4537 \&ConvertBlankLinesCallback);
4541 sub ConvertBlankLinesEndTag {
4542 if ($_[0] eq "<!\[CDATA\[") {
4544 } elsif ($_[0] eq "|[") {
4547 return "</programlisting>";
4551 sub ConvertBlankLinesCallback {
4552 my ($text, $symbol, $tag) = @_;
4554 # If we're not in CDATA or a <programlisting> we convert blank lines so
4555 # they start a new <para>.
4557 $text =~ s%\n{2,}%\n</para>\n<para>\n%g;
4564 #############################################################################
4565 # LIBRARY FUNCTIONS - These functions are used in both gtkdoc-mkdb and
4566 # gtkdoc-mktmpl and should eventually be moved to a
4568 #############################################################################
4570 #############################################################################
4571 # Function : ReadDeclarationsFile
4572 # Description : This reads in a file containing the function/macro/enum etc.
4575 # Note that in some cases there are several declarations with
4576 # the same name, e.g. for conditional macros. In this case we
4577 # set a flag in the %DeclarationConditional hash so the
4578 # declaration is not shown in the docs.
4580 # If a macro and a function have the same name, e.g. for
4581 # gtk_object_ref, the function declaration takes precedence.
4583 # Some opaque structs are just declared with 'typedef struct
4584 # _name name;' in which case the declaration may be empty.
4585 # The structure may have been found later in the header, so
4586 # that overrides the empty declaration.
4588 # Arguments : $file - the declarations file to read
4589 # $override - if declarations in this file should override
4590 # any current declaration.
4591 #############################################################################
4593 sub ReadDeclarationsFile {
4594 my ($file, $override) = @_;
4596 if ($override == 0) {
4598 %DeclarationTypes = ();
4599 %DeclarationConditional = ();
4600 %DeclarationOutput = ();
4604 || die "Can't open $file: $!";
4605 my $declaration_type = "";
4606 my $declaration_name;
4608 my $is_deprecated = 0;
4610 if (!$declaration_type) {
4611 if (m/^<([^>]+)>/) {
4612 $declaration_type = $1;
4613 $declaration_name = "";
4614 #print "Found declaration: $declaration_type\n";
4618 if (m%^<NAME>(.*)</NAME>%) {
4619 $declaration_name = $1;
4620 } elsif (m%^<DEPRECATED/>%) {
4622 } elsif (m%^</$declaration_type>%) {
4623 #print "Found end of declaration: $declaration_name\n";
4624 # Check that the declaration has a name
4625 if ($declaration_name eq "") {
4626 print "ERROR: $declaration_type has no name $file:$.\n";
4629 # If the declaration is an empty typedef struct _XXX XXX
4630 # set the flag to indicate the struct has a typedef.
4631 if ($declaration_type eq 'STRUCT'
4632 && $declaration =~ m/^\s*$/) {
4633 #print "Struct has typedef: $declaration_name\n";
4634 $StructHasTypedef{$declaration_name} = 1;
4637 # Check if the symbol is already defined.
4638 if (defined ($Declarations{$declaration_name})
4639 && $override == 0) {
4640 # Function declarations take precedence.
4641 if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
4643 } elsif ($declaration_type eq 'FUNCTION') {
4644 if ($is_deprecated) {
4645 $Deprecated{$declaration_name} = "";
4647 $Declarations{$declaration_name} = $declaration;
4648 $DeclarationTypes{$declaration_name} = $declaration_type;
4649 } elsif ($DeclarationTypes{$declaration_name}
4650 eq $declaration_type) {
4651 # If the existing declaration is empty, or is just a
4652 # forward declaration of a struct, override it.
4653 if ($declaration_type eq 'STRUCT') {
4654 if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4655 if ($is_deprecated) {
4656 $Deprecated{$declaration_name} = "";
4658 $Declarations{$declaration_name} = $declaration;
4659 } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4660 # Ignore an empty or forward declaration.
4662 &LogWarning ($file, $., "Structure $declaration_name has multiple definitions.");
4665 # set flag in %DeclarationConditional hash for
4666 # multiply defined macros/typedefs.
4667 $DeclarationConditional{$declaration_name} = 1;
4670 &LogWarning ($file, $., "$declaration_name has multiple definitions.");
4673 if ($is_deprecated) {
4674 $Deprecated{$declaration_name} = "";
4676 $Declarations{$declaration_name} = $declaration;
4677 $DeclarationTypes{$declaration_name} = $declaration_type;
4680 $declaration_type = "";
4691 #############################################################################
4692 # Function : ReadSignalsFile
4693 # Description : This reads in an existing file which contains information on
4694 # all GTK signals. It creates the arrays @SignalNames and
4695 # @SignalPrototypes containing info on the signals. The first
4696 # line of the SignalPrototype is the return type of the signal
4697 # handler. The remaining lines are the parameters passed to it.
4698 # The last parameter, "gpointer user_data" is always the same
4699 # so is not included.
4700 # Arguments : $file - the file containing the signal handler prototype
4702 #############################################################################
4704 sub ReadSignalsFile {
4712 my $signal_prototype;
4714 # Reset the signal info.
4715 @SignalObjects = ();
4717 @SignalReturns = ();
4719 @SignalPrototypes = ();
4724 if (!open (INPUT, $file)) {
4725 warn "Can't open $file - skipping signals\n";
4732 $signal_object = "";
4734 $signal_returns = "";
4735 $signal_prototype = "";
4738 if (m/^<NAME>(.*)<\/NAME>/) {
4740 if ($signal_name =~ m/^(.*)::(.*)$/) {
4741 $signal_object = $1;
4742 ($signal_name = $2) =~ s/_/-/g;
4743 #print "Found signal: $signal_name\n";
4745 &LogWarning ($file, $., "Invalid signal name: $signal_name.");
4747 } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
4748 $signal_returns = $1;
4749 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4751 } elsif (m%^</SIGNAL>%) {
4752 #print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
4753 push (@SignalObjects, $signal_object);
4754 push (@SignalNames, $signal_name);
4755 push (@SignalReturns, $signal_returns);
4756 push (@SignalFlags, $signal_flags);
4757 push (@SignalPrototypes, $signal_prototype);
4760 $signal_prototype .= $_;
4768 #############################################################################
4769 # Function : ReadTemplateFile
4770 # Description : This reads in the manually-edited documentation file
4771 # corresponding to the file currently being created, so we can
4772 # insert the documentation at the appropriate places.
4773 # It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
4774 # is a hash of arrays.
4775 # NOTE: This function is duplicated in gtkdoc-mktmpl (but
4776 # slightly different).
4777 # Arguments : $docsfile - the template file to read in.
4778 # $skip_unused_params - 1 if the unused parameters should be
4780 #############################################################################
4782 sub ReadTemplateFile {
4783 my ($docsfile, $skip_unused_params) = @_;
4785 my $template = "$docsfile.sgml";
4786 if (! -f $template) {
4787 #print "File doesn't exist: $template\n";
4790 #print "Reading $template\n";
4792 # start with empty hashes, we merge the source comment for each file
4798 my $current_type = ""; # Type of symbol being read.
4799 my $current_symbol = ""; # Name of symbol being read.
4800 my $symbol_doc = ""; # Description of symbol being read.
4801 my @params; # Parameter names and descriptions of current
4802 # function/macro/function typedef.
4803 my $current_param = -1; # Index of parameter currently being read.
4804 # Note that the param array contains pairs
4805 # of param name & description.
4806 my $in_unused_params = 0; # True if we are reading in the unused params.
4807 my $in_deprecated = 0;
4809 my $in_stability = 0;
4811 open (DOCS, "$template")
4812 || die "Can't open $template: $!";
4814 if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
4817 if ($symbol eq "Title"
4818 || $symbol eq "Short_Description"
4819 || $symbol eq "Long_Description"
4820 || $symbol eq "See_Also"
4821 || $symbol eq "Stability_Level"
4822 || $symbol eq "Include"
4823 || $symbol eq "Image") {
4825 $symbol = $docsfile . ":" . $symbol;
4828 #print "Found symbol: $symbol\n";
4829 # Remember file and line for the symbol
4830 $SymbolSourceFile{$symbol} = $template;
4831 $SymbolSourceLine{$symbol} = $.;
4833 # Store previous symbol, but remove any trailing blank lines.
4834 if ($current_symbol ne "") {
4835 $symbol_doc =~ s/\s+$//;
4836 $SymbolTypes{$current_symbol} = $current_type;
4837 $SymbolDocs{$current_symbol} = $symbol_doc;
4839 # Check that the stability level is valid.
4840 if ($StabilityLevel{$current_symbol}) {
4841 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4844 if ($current_param >= 0) {
4845 $SymbolParams{$current_symbol} = [ @params ];
4847 # Delete any existing params in case we are overriding a
4848 # previously read template.
4849 delete $SymbolParams{$current_symbol};
4852 $current_type = $type;
4853 $current_symbol = $symbol;
4854 $current_param = -1;
4855 $in_unused_params = 0;
4862 } elsif (m/^<!-- # Unused Parameters # -->/) {
4863 #print "DEBUG: Found unused parameters\n";
4864 $in_unused_params = 1;
4867 } elsif ($in_unused_params && $skip_unused_params) {
4868 # When outputting the DocBook we skip unused parameters.
4869 #print "DEBUG: Skipping unused param: $_";
4873 # Check if param found. Need to handle "..." and "format...".
4874 if (s/^\@([\w\.]+):\040?//) {
4875 my $param_name = $1;
4876 my $param_desc = $_;
4877 # Allow variations of 'Returns'
4878 if ($param_name =~ m/^[Rr]eturns?$/) {
4879 $param_name = "Returns";
4882 # strip trailing whitespaces and blank lines
4885 #print "Found param for symbol $current_symbol : '$param_name'= '$_'";
4887 if ($param_name eq "Deprecated") {
4889 $Deprecated{$current_symbol} = $_;
4890 } elsif ($param_name eq "Since") {
4893 $Since{$current_symbol} = $_;
4894 } elsif ($param_name eq "Stability") {
4896 $StabilityLevel{$current_symbol} = $_;
4898 push (@params, $param_name);
4899 push (@params, $param_desc);
4900 $current_param += $PARAM_FIELD_COUNT;
4903 # strip trailing whitespaces and blank lines
4908 if ($in_deprecated) {
4909 $Deprecated{$current_symbol} .= $_;
4910 } elsif ($in_since) {
4911 &LogWarning ($template, $., "multi-line since docs found");
4912 #$Since{$current_symbol} .= $_;
4913 } elsif ($in_stability) {
4914 $StabilityLevel{$current_symbol} .= $_;
4915 } elsif ($current_param >= 0) {
4916 $params[$current_param] .= $_;
4925 # Remember to finish the current symbol doccs.
4926 if ($current_symbol ne "") {
4928 $symbol_doc =~ s/\s+$//;
4929 $SymbolTypes{$current_symbol} = $current_type;
4930 $SymbolDocs{$current_symbol} = $symbol_doc;
4932 # Check that the stability level is valid.
4933 if ($StabilityLevel{$current_symbol}) {
4934 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4937 if ($current_param >= 0) {
4938 $SymbolParams{$current_symbol} = [ @params ];
4940 # Delete any existing params in case we are overriding a
4941 # previously read template.
4942 delete $SymbolParams{$current_symbol};
4951 #############################################################################
4952 # Function : ReadObjectHierarchy
4953 # Description : This reads in the $MODULE-hierarchy.txt file containing all
4954 # the GtkObject subclasses described in this module (and their
4956 # It places them in the @Objects array, and places their level
4957 # in the object hierarchy in the @ObjectLevels array, at the
4958 # same index. GtkObject, the root object, has a level of 1.
4960 # FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
4961 # as it goes along, this should be split out into a separate
4965 #############################################################################
4967 sub ReadObjectHierarchy {
4971 if (! -f $OBJECT_TREE_FILE) {
4974 if (!open (INPUT, $OBJECT_TREE_FILE)) {
4975 warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
4979 # FIXME: use $OUTPUT_FORMAT
4980 # my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.$OUTPUT_FORMAT";
4981 my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
4982 my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
4984 open (OUTPUT, ">$new_tree_index")
4985 || die "Can't create $new_tree_index: $!";
4987 if ($OUTPUT_FORMAT eq "xml") {
4988 my $tree_header = $doctype_header;
4990 $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
4991 print (OUTPUT "$tree_header");
4993 print (OUTPUT "<screen>\n");
4995 # Only emit objects if they are supposed to be documented, or if
4996 # they have documented children. To implement this, we maintain a
4997 # stack of pending objects which will be emitted if a documented
4999 my @pending_objects = ();
5000 my @pending_levels = ();
5004 my $level = (length($`)) / 2 + 1;
5007 while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
5008 my $pobject = pop(@pending_objects);
5009 my $plevel = pop(@pending_levels);
5012 push (@pending_objects, $object);
5013 push (@pending_levels, $level);
5015 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5016 while ($#pending_levels >= 0) {
5017 $object = shift @pending_objects;
5018 $level = shift @pending_levels;
5019 $xref = &MakeXRef ($object);
5021 print (OUTPUT ' ' x ($level * 4), "$xref\n");
5022 push (@Objects, $object);
5023 push (@ObjectLevels, $level);
5027 # LogWarning ($OBJECT_TREE_FILE, $., "unknown type $object");
5031 print (OUTPUT "</screen>\n");
5036 &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
5041 #############################################################################
5042 # Function : ReadInterfaces
5043 # Description : This reads in the $MODULE.interfaces file.
5046 #############################################################################
5048 sub ReadInterfaces {
5051 if (! -f $INTERFACES_FILE) {
5054 if (!open (INPUT, $INTERFACES_FILE)) {
5055 warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
5061 my ($object, @ifaces) = split;
5062 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5063 my @knownIfaces = ();
5065 # filter out private interfaces, but leave foreign interfaces
5066 foreach my $iface (@ifaces) {
5067 if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
5068 push (@knownIfaces, $iface);
5072 $Interfaces{$object} = join(' ', @knownIfaces);
5078 #############################################################################
5079 # Function : ReadPrerequisites
5080 # Description : This reads in the $MODULE.prerequisites file.
5083 #############################################################################
5085 sub ReadPrerequisites {
5086 %Prerequisites = ();
5088 if (! -f $PREREQUISITES_FILE) {
5091 if (!open (INPUT, $PREREQUISITES_FILE)) {
5092 warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
5098 my ($iface, @prereqs) = split;
5099 if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
5100 my @knownPrereqs = ();
5102 # filter out private prerequisites, but leave foreign prerequisites
5103 foreach my $prereq (@prereqs) {
5104 if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
5105 push (@knownPrereqs, $prereq);
5109 $Prerequisites{$iface} = join(' ', @knownPrereqs);
5115 #############################################################################
5116 # Function : ReadArgsFile
5117 # Description : This reads in an existing file which contains information on
5118 # all GTK args. It creates the arrays @ArgObjects, @ArgNames,
5119 # @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
5121 # Arguments : $file - the file containing the arg information.
5122 #############################################################################
5137 # Reset the args info.
5150 if (!open (INPUT, $file)) {
5151 warn "Can't open $file - skipping args\n";
5168 if (m/^<NAME>(.*)<\/NAME>/) {
5170 if ($arg_name =~ m/^(.*)::(.*)$/) {
5172 ($arg_name = $2) =~ s/_/-/g;
5173 #print "Found arg: $arg_name\n";
5175 &LogWarning ($file, $., "Invalid argument name: $arg_name");
5177 } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
5179 } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
5181 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
5183 } elsif (m/^<NICK>(.*)<\/NICK>/) {
5185 } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
5187 if ($arg_blurb eq "(null)") {
5189 &LogWarning ($file, $., "Property ${arg_object}:${arg_name} has no documentation.");
5191 } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
5193 } elsif (m%^</ARG>%) {
5194 #print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
5195 push (@ArgObjects, $arg_object);
5196 push (@ArgNames, $arg_name);
5197 push (@ArgTypes, $arg_type);
5198 push (@ArgRanges, $arg_range);
5199 push (@ArgFlags, $arg_flags);
5200 push (@ArgNicks, $arg_nick);
5201 push (@ArgBlurbs, $arg_blurb);
5202 push (@ArgDefaults, $arg_default);
5211 #############################################################################
5212 # Function : CheckIsObject
5213 # Description : Returns 1 if the given name is a GObject or a subclass.
5214 # It uses the global @Objects array.
5215 # Note that the @Objects array only contains classes in the
5216 # current module and their ancestors - not all GObject classes.
5217 # Arguments : $name - the name to check.
5218 #############################################################################
5224 foreach $object (@Objects) {
5225 if ($object eq $name) {
5233 #############################################################################
5234 # Function : MakeReturnField
5235 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
5236 # Arguments : $str - the string to pad.
5237 #############################################################################
5239 sub MakeReturnField {
5242 return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));
5245 #############################################################################
5246 # Function : GetSymbolSourceFile
5247 # Description : Get the filename where the symbol docs where taken from.
5248 # Arguments : $symbol - the symbol name
5249 #############################################################################
5251 sub GetSymbolSourceFile {
5254 if (defined($SourceSymbolSourceFile{$symbol})) {
5255 return $SourceSymbolSourceFile{$symbol};
5256 } elsif (defined($SymbolSourceFile{$symbol})) {
5257 return $SymbolSourceFile{$symbol};
5263 #############################################################################
5264 # Function : GetSymbolSourceLine
5265 # Description : Get the file line where the symbol docs where taken from.
5266 # Arguments : $symbol - the symbol name
5267 #############################################################################
5269 sub GetSymbolSourceLine {
5272 if (defined($SourceSymbolSourceLine{$symbol})) {
5273 return $SourceSymbolSourceLine{$symbol};
5274 } elsif (defined($SymbolSourceLine{$symbol})) {
5275 return $SymbolSourceLine{$symbol};