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 print (OUTPUT "</row>\n");
465 print (OUTPUT <<EOF);
466 </tbody></tgroup></informaltable>
470 &UpdateFileIfChanged ($old_object_index, $new_object_index, 0);
474 #############################################################################
475 # Function : OutputSGML
476 # Description : This collects the output for each section of the docs, and
477 # outputs each file when the end of the section is found.
478 # Arguments : $file - the $MODULE-sections.txt file which contains all of
479 # the functions/macros/structs etc. being documented, organised
480 # into sections and subsections.
481 #############################################################################
486 #print "Reading: $file\n";
488 || die "Can't open $file: $!";
491 my $book_bottom = "";
492 my $includes = (defined $DEFAULT_INCLUDES) ? $DEFAULT_INCLUDES : "";
493 my $section_includes = "";
502 my $signals_synop = "";
503 my $signals_desc = "";
505 my $child_args_synop = "";
506 my $style_args_synop = "";
508 my $child_args_desc = "";
509 my $style_args_desc = "";
512 my $implementations = "";
513 my $prerequisites = "";
515 my @file_objects = ();
517 my %symbol_def_line = ();
519 # merge the source docs, in case there are no templates
520 &MergeSourceDocumentation;
526 } elsif (m/^<SECTION>/) {
532 %symbol_def_line = ();
534 } elsif (m/^<SUBSECTION\s*(.*)>/i) {
538 } elsif (m/^<SUBSECTION>/) {
540 } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
542 #print "Section: $title\n";
544 # We don't want warnings if object & class structs aren't used.
545 $DeclarationOutput{$title} = 1;
546 $DeclarationOutput{"${title}Class"} = 1;
547 $DeclarationOutput{"${title}Iface"} = 1;
548 $DeclarationOutput{"${title}Interface"} = 1;
550 } elsif (m/^<FILE>(.*)<\/FILE>/) {
552 if (! defined $templates{$filename}) {
553 if (&ReadTemplateFile ("$TMPL_DIR/$filename", 1)) {
554 &MergeSourceDocumentation;
555 $templates{$filename}=$.;
558 &LogWarning ($file, $., "Double <FILE>$filename</FILE> entry. ".
559 "Previous occurrence on line ".$templates{$filename}.".");
561 if (($title eq "") and (defined $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"})) {
562 $title = $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"};
563 # Remove trailing blanks
567 } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
569 $section_includes = $1;
571 if (defined $DEFAULT_INCLUDES) {
572 &LogWarning ($file, $., "Default <INCLUDE> being overridden by command line option.");
579 } elsif (m/^<\/SECTION>/) {
580 #print "End of section: $title\n";
581 if ($num_symbols > 0) {
583 if ($OUTPUT_FORMAT eq "xml") {
584 $book_bottom .= " <xi:include href=\"xml/$filename.xml\"/>\n";
586 $book_top.="<!ENTITY $section_id SYSTEM \"sgml/$filename.sgml\">\n";
587 $book_bottom .= " &$section_id;\n";
590 if (defined ($SourceSymbolDocs{"$TMPL_DIR/$filename:Include"})) {
591 if ($section_includes) {
592 &LogWarning ($file, $., "Section <INCLUDE> being overridden by inline comments.");
594 $section_includes = $SourceSymbolDocs{"$TMPL_DIR/$filename:Include"};
596 if ($section_includes eq "") {
597 $section_includes = $includes;
600 $signals_synop =~ s/^\n*//g;
601 $signals_synop =~ s/\n+$/\n/g;
602 if ($signals_synop ne '') {
603 $signals_synop = <<EOF;
604 <refsect1 id="$section_id.signals" role="signal_proto">
605 <title role="signal_proto.title">Signals</title>
607 ${signals_synop}</synopsis>
610 $signals_desc =~ s/^\n*//g;
611 $signals_desc =~ s/\n+$/\n/g;
612 $signals_desc =~ s/(\s|\n)+$//ms;
613 $signals_desc = <<EOF;
614 <refsect1 id="$section_id.signal-details" role="signals">
615 <title role="signals.title">Signal Details</title>
621 $args_synop =~ s/^\n*//g;
622 $args_synop =~ s/\n+$/\n/g;
623 if ($args_synop ne '') {
625 <refsect1 id="$section_id.properties" role="properties">
626 <title role="properties.title">Properties</title>
628 ${args_synop}</synopsis>
631 $args_desc =~ s/^\n*//g;
632 $args_desc =~ s/\n+$/\n/g;
633 $args_desc =~ s/(\s|\n)+$//ms;
635 <refsect1 id="$section_id.property-details" role="property_details">
636 <title role="property_details.title">Property Details</title>
642 $child_args_synop =~ s/^\n*//g;
643 $child_args_synop =~ s/\n+$/\n/g;
644 if ($child_args_synop ne '') {
645 $args_synop .= <<EOF;
646 <refsect1 id="$section_id.child-properties" role="child_properties">
647 <title role="child_properties.title">Child Properties</title>
649 ${child_args_synop}</synopsis>
652 $child_args_desc =~ s/^\n*//g;
653 $child_args_desc =~ s/\n+$/\n/g;
654 $child_args_desc =~ s/(\s|\n)+$//ms;
656 <refsect1 id="$section_id.child-property-details" role="child_property_details">
657 <title role="child_property_details.title">Child Property Details</title>
663 $style_args_synop =~ s/^\n*//g;
664 $style_args_synop =~ s/\n+$/\n/g;
665 if ($style_args_synop ne '') {
666 $args_synop .= <<EOF;
667 <refsect1 id="$section_id.style-properties" role="style_properties">
668 <title role="style_properties.title">Style Properties</title>
670 ${style_args_synop}</synopsis>
673 $style_args_desc =~ s/^\n*//g;
674 $style_args_desc =~ s/\n+$/\n/g;
675 $style_args_desc =~ s/(\s|\n)+$//ms;
677 <refsect1 id="$section_id.style-property-details" role="style_properties_details">
678 <title role="style_properties_details.title">Style Property Details</title>
684 $hierarchy =~ s/^\n*//g;
685 $hierarchy =~ s/\n+$/\n/g;
686 $hierarchy =~ s/(\s|\n)+$//ms;
687 if ($hierarchy ne "") {
689 <refsect1 id="$section_id.object-hierarchy" role="object_hierarchy">
690 <title role="object_hierarchy.title">Object Hierarchy</title>
696 $interfaces =~ s/^\n*//g;
697 $interfaces =~ s/\n+$/\n/g;
698 $interfaces =~ s/(\s|\n)+$//ms;
699 if ($interfaces ne "") {
701 <refsect1 id="$section_id.implemented-interfaces" role="impl_interfaces">
702 <title role="impl_interfaces.title">Implemented Interfaces</title>
708 $implementations =~ s/^\n*//g;
709 $implementations =~ s/\n+$/\n/g;
710 $implementations =~ s/(\s|\n)+$//ms;
711 if ($implementations ne "") {
712 $implementations = <<EOF;
713 <refsect1 id="$section_id.implementations" role="implementations">
714 <title role="implementations.title">Known Implementations</title>
720 $prerequisites =~ s/^\n*//g;
721 $prerequisites =~ s/\n+$/\n/g;
722 $prerequisites =~ s/(\s|\n)+$//ms;
723 if ($prerequisites ne "") {
724 $prerequisites = <<EOF;
725 <refsect1 id="$section_id.prerequisites" role="prerequisites">
726 <title role="prerequisites.title">Prerequisites</title>
732 $derived =~ s/^\n*//g;
733 $derived =~ s/\n+$/\n/g;
734 $derived =~ s/(\s|\n)+$//ms;
735 if ($derived ne "") {
737 <refsect1 id="$section_id.derived-interfaces" role="derived_interfaces">
738 <title role="derived_interfaces.title">Known Derived Interfaces</title>
744 $synopsis =~ s/^\n*//g;
745 $synopsis =~ s/\n+$/\n/g;
746 my $file_changed = &OutputSGMLFile ($filename, $title, $section_id,
748 \$synopsis, \$details,
749 \$signals_synop, \$signals_desc,
750 \$args_synop, \$args_desc,
751 \$hierarchy, \$interfaces,
753 \$prerequisites, \$derived,
763 $section_includes = "";
767 $child_args_synop = "";
768 $style_args_synop = "";
770 $child_args_desc = "";
771 $style_args_desc = "";
774 $implementations = "";
778 } elsif (m/^(\S+)/) {
780 #print " Symbol: $symbol\n";
782 # check for duplicate entries
783 if (! defined $symbol_def_line{$symbol}) {
784 my $declaration = $Declarations{$symbol};
785 if (defined ($declaration)) {
786 # We don't want standard macros/functions of GObjects,
787 # or private declarations.
788 if ($subsection ne "Standard" && $subsection ne "Private") {
789 if (&CheckIsObject ($symbol)) {
790 push @file_objects, $symbol;
792 my ($synop, $desc) = &OutputDeclaration ($symbol,
794 my ($sig_synop, $sig_desc) = &GetSignals ($symbol);
795 my ($arg_synop, $child_arg_synop, $style_arg_synop,
796 $arg_desc, $child_arg_desc, $style_arg_desc) = &GetArgs ($symbol);
797 my $hier = &GetHierarchy ($symbol);
798 my $ifaces = &GetInterfaces ($symbol);
799 my $impls = &GetImplementations ($symbol);
800 my $prereqs = &GetPrerequisites ($symbol);
801 my $der = &GetDerived ($symbol);
804 $signals_synop .= $sig_synop;
805 $signals_desc .= $sig_desc;
806 $args_synop .= $arg_synop;
807 $child_args_synop .= $child_arg_synop;
808 $style_args_synop .= $style_arg_synop;
809 $args_desc .= $arg_desc;
810 $child_args_desc .= $child_arg_desc;
811 $style_args_desc .= $style_arg_desc;
813 $interfaces .= $ifaces;
814 $implementations .= $impls;
815 $prerequisites .= $prereqs;
819 # Note that the declaration has been output.
820 $DeclarationOutput{$symbol} = 1;
821 } elsif ($subsection ne "Standard" && $subsection ne "Private") {
822 $UndeclaredSymbols{$symbol} = 1;
823 &LogWarning ($file, $., "No declaration found for $symbol.");
826 $symbol_def_line{$symbol}=$.;
828 if ($section_id eq "") {
829 if($title eq "" && $filename eq "") {
830 &LogWarning ($file, $., "Section has no title and no file.");
832 # FIXME: one of those would be enough
833 # filename should be an internal detail for gtk-doc
836 } elsif ($filename eq "") {
839 $filename =~ s/\s/_/g;
841 $section_id = $SourceSymbolDocs{"$TMPL_DIR/$filename:Section_Id"};
842 if (defined ($section_id) && $section_id !~ m/^\s*$/) {
843 # Remove trailing blanks and use as is
844 $section_id =~ s/\s+$//;
845 } elsif (&CheckIsObject ($title)) {
846 # GObjects use their class name as the ID.
847 $section_id = &CreateValidSGMLID ($title);
849 $section_id = &CreateValidSGMLID ("$MODULE-$title");
852 $SymbolSection{$symbol}=$title;
853 $SymbolSectionId{$symbol}=$section_id;
856 &LogWarning ($file, $., "Double symbol entry for $symbol. ".
857 "Previous occurrence on line ".$symbol_def_line{$symbol}.".");
863 &OutputMissingDocumentation;
864 &OutputUndeclaredSymbols;
865 &OutputUnusedSymbols;
867 if ($OUTPUT_ALL_SYMBOLS) {
870 if ($OUTPUT_SYMBOLS_WITHOUT_SINCE) {
871 &OutputSymbolsWithoutSince;
874 for $filename (split (' ', $EXPAND_CONTENT_FILES)) {
875 my $file_changed = &OutputExtraFile ($filename);
881 &OutputBook ($book_top, $book_bottom);
886 #############################################################################
887 # Function : OutputIndex
888 # Description : This writes an indexlist that can be included into the main-
889 # document into an <index> tag.
890 #############################################################################
893 my ($basename, $apiindexref ) = @_;
894 my %apiindex = %{$apiindexref};
895 my $old_index = "$SGML_OUTPUT_DIR/$basename.xml";
896 my $new_index = "$SGML_OUTPUT_DIR/$basename.new";
897 my $lastletter = " ";
902 open (OUTPUT, ">$new_index")
903 || die "Can't create $new_index";
905 my $header = $doctype_header;
906 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE indexdiv/;
908 print (OUTPUT "$header<indexdiv>\n");
910 #print "generate $basename index (".%apiindex." entries)\n";
912 # do a case insensitive sort while chopping off the prefix
914 sort { $$a{criteria} cmp $$b{criteria} }
915 map { my $x = uc($_); $x =~ s/^$NAME_SPACE\_?(.*)/$1/i; { criteria => $x, original => $_, short => $1 } }
918 $symbol = $$hash{original};
919 if (defined($$hash{short})) {
920 $short_symbol = $$hash{short};
922 $short_symbol = $symbol;
925 # generate a short symbol description
926 my $symbol_desc = "";
927 my $symbol_section = "";
928 my $symbol_section_id = "";
929 my $symbol_type = lc($DeclarationTypes{$symbol});
930 if ($symbol_type eq "") {
931 #print "trying symbol $symbol\n";
932 if ($symbol =~ m/(.*)::(.*)/) {
936 #print " trying object signal ${oname}:$osym in ".$#SignalNames." signals\n";
937 for ($i = 0; $i <= $#SignalNames; $i++) {
938 if ($SignalNames[$i] eq $osym) {
939 $symbol_type = "object signal";
940 if (defined($SymbolSection{$oname})) {
941 $symbol_section = $SymbolSection{$oname};
942 $symbol_section_id = $SymbolSectionId{$oname};
947 } elsif ($symbol =~ m/(.*):(.*)/) {
951 #print " trying object property ${oname}::$osym in ".$#ArgNames." properties\n";
952 for ($i = 0; $i <= $#ArgNames; $i++) {
953 #print " ".$ArgNames[$i]."\n";
954 if ($ArgNames[$i] eq $osym) {
955 $symbol_type = "object property";
956 if (defined($SymbolSection{$oname})) {
957 $symbol_section = $SymbolSection{$oname};
958 $symbol_section_id = $SymbolSectionId{$oname};
965 if (defined($SymbolSection{$symbol})) {
966 $symbol_section = $SymbolSection{$symbol};
967 $symbol_section_id = $SymbolSectionId{$symbol};
970 if ($symbol_type ne "") {
971 $symbol_desc=", $symbol_type";
972 if ($symbol_section ne "") {
973 $symbol_desc.=" in <link linkend=\"$symbol_section_id\">$symbol_section</link>";
974 #$symbol_desc.=" in ". &ExpandAbbreviations($symbol, "#$symbol_section");
978 my $curletter = uc(substr($short_symbol,0,1));
979 my $id = $apiindex{$symbol};
981 #print " add symbol $symbol with $id to index in section $curletter\n";
983 if ($curletter ne $lastletter) {
984 $lastletter = $curletter;
987 print (OUTPUT "</indexdiv>\n");
989 print (OUTPUT "<indexdiv><title>$curletter</title>\n");
993 print (OUTPUT <<EOF);
994 <indexentry><primaryie linkends="$id"><link linkend="$id">$symbol</link>$symbol_desc</primaryie></indexentry>
999 print (OUTPUT "</indexdiv>\n");
1001 print (OUTPUT "</indexdiv>\n");
1004 &UpdateFileIfChanged ($old_index, $new_index, 0);
1008 #############################################################################
1009 # Function : OutputIndexFull
1010 # Description : This writes the full api indexlist that can be included into the
1011 # main document into an <index> tag.
1012 #############################################################################
1014 sub OutputIndexFull {
1015 &OutputIndex ("api-index-full", \%IndexEntriesFull);
1019 #############################################################################
1020 # Function : OutputDeprecatedIndex
1021 # Description : This writes the deprecated api indexlist that can be included
1022 # into the main document into an <index> tag.
1023 #############################################################################
1025 sub OutputDeprecatedIndex {
1026 &OutputIndex ("api-index-deprecated", \%IndexEntriesDeprecated);
1030 #############################################################################
1031 # Function : OutputSinceIndexes
1032 # Description : This writes the 'since' api indexlists that can be included into
1033 # the main document into an <index> tag.
1034 #############################################################################
1036 sub OutputSinceIndexes {
1037 my @sinces = keys %{{ map { $_ => 1 } values %Since }};
1039 foreach my $version (@sinces) {
1040 #print "Since : [$version]\n";
1041 # TODO make filtered hash
1042 #my %index = grep { $Since{$_} eq $version } %IndexEntriesSince;
1043 my %index = map { $_ => $IndexEntriesSince{$_} } grep { $Since{$_} eq $version } keys %IndexEntriesSince;
1045 &OutputIndex ("api-index-$version", \%index);
1049 #############################################################################
1050 # Function : OutputAnnotationGlossary
1051 # Description : This writes a glossary of the used annotation terms into a
1052 # separate glossary file that can be included into the main
1054 #############################################################################
1056 sub OutputAnnotationGlossary {
1057 my $old_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.xml";
1058 my $new_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.new";
1059 my $lastletter = " ";
1062 # if there are no annotations used return
1063 return if (! keys(%AnnotationsUsed));
1065 # add acronyms that are referenced from acronym text
1067 foreach my $annotation (keys(%AnnotationsUsed)) {
1068 if($AnnotationDefinition{$annotation} =~ m/<acronym>([\w ]+)<\/acronym>/) {
1069 if (!exists($AnnotationsUsed{$1})) {
1070 $AnnotationsUsed{$1} = 1;
1076 open (OUTPUT, ">$new_glossary")
1077 || die "Can't create $new_glossary";
1079 my $header = $doctype_header;
1080 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE glossary/;
1082 print (OUTPUT <<EOF);
1084 <glossary id="annotation-glossary">
1085 <title>Annotation Glossary</title>
1088 foreach my $annotation (keys(%AnnotationsUsed)) {
1089 my $def = $AnnotationDefinition{$annotation};
1090 my $curletter = uc(substr($annotation,0,1));
1092 if ($curletter ne $lastletter) {
1093 $lastletter = $curletter;
1095 if ($divopen == 1) {
1096 print (OUTPUT "</glossdiv>\n");
1098 print (OUTPUT "<glossdiv><title>$curletter</title>\n");
1101 print (OUTPUT <<EOF);
1103 <glossterm><anchor id="annotation-glossterm-$annotation"/>$annotation</glossterm>
1111 if ($divopen == 1) {
1112 print (OUTPUT "</glossdiv>\n");
1114 print (OUTPUT "</glossary>\n");
1117 &UpdateFileIfChanged ($old_glossary, $new_glossary, 0);
1120 #############################################################################
1121 # Function : ReadKnownSymbols
1122 # Description : This collects the names of non-private symbols from the
1123 # $MODULE-sections.txt file.
1124 # Arguments : $file - the $MODULE-sections.txt file which contains all of
1125 # the functions/macros/structs etc. being documented, organised
1126 # into sections and subsections.
1127 #############################################################################
1129 sub ReadKnownSymbols {
1132 my $subsection = "";
1134 #print "Reading: $file\n";
1136 || die "Can't open $file: $!";
1142 } elsif (m/^<SECTION>/) {
1145 } elsif (m/^<SUBSECTION\s*(.*)>/i) {
1148 } elsif (m/^<SUBSECTION>/) {
1151 } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
1154 } elsif (m/^<FILE>(.*)<\/FILE>/) {
1155 $KnownSymbols{"$TMPL_DIR/$1:Long_Description"} = 1;
1156 $KnownSymbols{"$TMPL_DIR/$1:Short_Description"} = 1;
1159 } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
1162 } elsif (m/^<\/SECTION>/) {
1165 } elsif (m/^(\S+)/) {
1168 if ($subsection ne "Standard" && $subsection ne "Private") {
1169 $KnownSymbols{$symbol} = 1;
1172 $KnownSymbols{$symbol} = 0;
1180 #############################################################################
1181 # Function : OutputDeclaration
1182 # Description : Returns the synopsis and detailed description DocBook
1183 # describing one function/macro etc.
1184 # Arguments : $symbol - the name of the function/macro begin described.
1185 # $declaration - the declaration of the function/macro.
1186 #############################################################################
1188 sub OutputDeclaration {
1189 my ($symbol, $declaration) = @_;
1191 my $type = $DeclarationTypes {$symbol};
1192 if ($type eq 'MACRO') {
1193 return &OutputMacro ($symbol, $declaration);
1194 } elsif ($type eq 'TYPEDEF') {
1195 return &OutputTypedef ($symbol, $declaration);
1196 } elsif ($type eq 'STRUCT') {
1197 return &OutputStruct ($symbol, $declaration);
1198 } elsif ($type eq 'ENUM') {
1199 return &OutputEnum ($symbol, $declaration);
1200 } elsif ($type eq 'UNION') {
1201 return &OutputUnion ($symbol, $declaration);
1202 } elsif ($type eq 'VARIABLE') {
1203 return &OutputVariable ($symbol, $declaration);
1204 } elsif ($type eq 'FUNCTION') {
1205 return &OutputFunction ($symbol, $declaration, $type);
1206 } elsif ($type eq 'USER_FUNCTION') {
1207 return &OutputFunction ($symbol, $declaration, $type);
1209 die "Unknown symbol type";
1214 #############################################################################
1215 # Function : OutputSymbolTraits
1216 # Description : Returns the Since and StabilityLevel paragraphs for a symbol.
1217 # Arguments : $symbol - the name of the function/macro begin described.
1218 #############################################################################
1220 sub OutputSymbolTraits {
1224 if (exists $Since{$symbol}) {
1225 $desc .= "<para role=\"since\">Since $Since{$symbol}</para>";
1227 if (exists $StabilityLevel{$symbol}) {
1228 $desc .= "<para role=\"stability\">Stability Level: $StabilityLevel{$symbol}</para>";
1233 #############################################################################
1234 # Function : Outpu{Symbol,Section}ExtraLinks
1235 # Description : Returns extralinks for the symbol (if enabled).
1236 # Arguments : $symbol - the name of the function/macro begin described.
1237 #############################################################################
1241 return undef unless defined $text;
1243 # Build a char to hex map
1246 $escapes{chr($_)} = sprintf("%%%02X", $_);
1249 # Default unsafe characters. RFC 2732 ^(uric - reserved)
1250 $text =~ s/([^A-Za-z0-9\-_.!~*'()])/$escapes{$1}/g;
1255 sub OutputSymbolExtraLinks {
1259 if (0) { # NEW FEATURE: needs configurability
1260 my $sstr = &uri_escape($symbol);
1261 my $mstr = &uri_escape($MODULE);
1263 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1264 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&symbol=$sstr">edit documentation</ulink>
1270 sub OutputSectionExtraLinks {
1271 my ($symbol,$docsymbol) = @_;
1274 if (0) { # NEW FEATURE: needs configurability
1275 my $sstr = &uri_escape($symbol);
1276 my $mstr = &uri_escape($MODULE);
1277 my $dsstr = &uri_escape($docsymbol);
1279 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1280 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&symbol=$dsstr">edit documentation</ulink>
1287 #############################################################################
1288 # Function : OutputMacro
1289 # Description : Returns the synopsis and detailed description of a macro.
1290 # Arguments : $symbol - the macro.
1291 # $declaration - the declaration of the macro.
1292 #############################################################################
1295 my ($symbol, $declaration) = @_;
1296 my $id = &CreateValidSGMLID ($symbol);
1297 my $condition = &MakeConditionDescription ($symbol);
1298 my $synop = &MakeReturnField("#define") . "<link linkend=\"$id\">$symbol</link>";
1301 my @fields = ParseMacroDeclaration($declaration, \&CreateValidSGML);
1302 my $title = $symbol . (@fields ? "()" : "");
1304 $desc = "<refsect2 id=\"$id\" role=\"macro\"$condition>\n<title>$title</title>\n";
1305 $desc .= MakeIndexterms($symbol, $id);
1307 $desc .= OutputSymbolExtraLinks($symbol);
1310 if (length ($symbol) < $SYMBOL_FIELD_WIDTH) {
1311 $synop .= (' ' x ($SYMBOL_FIELD_WIDTH - length ($symbol)));
1315 for (my $i = 1; $i <= $#fields; $i += 2) {
1316 my $field_name = $fields[$i];
1319 $synop .= "$field_name";
1322 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1330 # Don't output the macro definition if is is a conditional macro or it
1331 # looks like a function, i.e. starts with "g_" or "_?gnome_", or it is
1332 # longer than 2 lines, otherwise we get lots of complicated macros like
1334 if (!defined ($DeclarationConditional{$symbol}) && ($symbol !~ m/^g_/)
1335 && ($symbol !~ m/^_?gnome_/) && (($declaration =~ tr/\n//) < 2)) {
1336 my $decl_out = &CreateValidSGML ($declaration);
1337 $desc .= "<programlisting>$decl_out</programlisting>\n";
1339 $desc .= "<programlisting>" . &MakeReturnField("#define") . "$symbol";
1340 if ($declaration =~ m/^\s*#\s*define\s+\w+(\([^\)]*\))/) {
1342 my $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH - length ("#define "));
1343 # Align each line so that if should all line up OK.
1344 $args =~ s/\n/\n$pad/gm;
1345 $desc .= &CreateValidSGML ($args);
1347 $desc .= "</programlisting>\n";
1350 $desc .= &MakeDeprecationNote($symbol);
1352 my $parameters = &OutputParamDescriptions ("MACRO", $symbol, @fields);
1353 my $parameters_output = 0;
1355 if (defined ($SymbolDocs{$symbol})) {
1356 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1358 # Try to insert the parameter table at the author's desired position.
1359 # Otherwise we need to tag it onto the end.
1360 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1361 $parameters_output = 1;
1363 $desc .= $symbol_docs;
1366 if ($parameters_output == 0) {
1367 $desc .= $parameters;
1370 $desc .= OutputSymbolTraits ($symbol);
1371 $desc .= "</refsect2>\n";
1372 return ($synop, $desc);
1376 #############################################################################
1377 # Function : OutputTypedef
1378 # Description : Returns the synopsis and detailed description of a typedef.
1379 # Arguments : $symbol - the typedef.
1380 # $declaration - the declaration of the typedef,
1381 # e.g. 'typedef unsigned int guint;'
1382 #############################################################################
1385 my ($symbol, $declaration) = @_;
1386 my $id = &CreateValidSGMLID ($symbol);
1387 my $condition = &MakeConditionDescription ($symbol);
1388 my $synop = &MakeReturnField("typedef") . "<link linkend=\"$id\">$symbol</link>;\n";
1389 my $desc = "<refsect2 id=\"$id\" role=\"typedef\"$condition>\n<title>$symbol</title>\n";
1391 $desc .= MakeIndexterms($symbol, $id);
1393 $desc .= OutputSymbolExtraLinks($symbol);
1395 if (!defined ($DeclarationConditional{$symbol})) {
1396 my $decl_out = &CreateValidSGML ($declaration);
1397 $desc .= "<programlisting>$decl_out</programlisting>\n";
1400 $desc .= &MakeDeprecationNote($symbol);
1402 if (defined ($SymbolDocs{$symbol})) {
1403 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1405 $desc .= OutputSymbolTraits ($symbol);
1406 $desc .= "</refsect2>\n";
1407 return ($synop, $desc);
1411 #############################################################################
1412 # Function : OutputStruct
1413 # Description : Returns the synopsis and detailed description of a struct.
1414 # We check if it is a object struct, and if so we only output
1415 # parts of it that are noted as public fields.
1416 # We also use a different SGML ID for object structs, since the
1417 # original ID is used for the entire RefEntry.
1418 # Arguments : $symbol - the struct.
1419 # $declaration - the declaration of the struct.
1420 #############################################################################
1423 my ($symbol, $declaration) = @_;
1425 my $is_object_struct = 0;
1426 my $default_to_public = 1;
1427 if (&CheckIsObject ($symbol)) {
1428 #print "Found object struct: $symbol\n";
1429 $is_object_struct = 1;
1430 $default_to_public = 0;
1435 if ($is_object_struct) {
1436 $id = &CreateValidSGMLID ($symbol . "_struct");
1437 $condition = &MakeConditionDescription ($symbol . "_struct");
1439 $id = &CreateValidSGMLID ($symbol);
1440 $condition = &MakeConditionDescription ($symbol);
1443 # Determine if it is a simple struct or it also has a typedef.
1444 my $has_typedef = 0;
1445 if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1452 # For structs with typedefs we just output the struct name.
1453 $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1454 $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>$symbol</title>\n";
1456 $synop = &MakeReturnField("struct") . "<link linkend=\"$id\">$symbol</link>;\n";
1457 $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>struct $symbol</title>\n";
1460 $desc .= MakeIndexterms($symbol, $id);
1462 $desc .= OutputSymbolExtraLinks($symbol);
1464 # Form a pretty-printed, private-data-removed form of the declaration
1467 if ($declaration =~ m/^\s*$/) {
1468 #print "Found opaque struct: $symbol\n";
1469 $decl_out = "typedef struct _$symbol $symbol;";
1470 } elsif ($declaration =~ m/^\s*struct\s+\w+\s*;\s*$/) {
1471 #print "Found opaque struct: $symbol\n";
1472 $decl_out = "struct $symbol;";
1474 my $public = $default_to_public;
1475 my $new_declaration = "";
1477 my $decl = $declaration;
1479 if ($decl =~ m/^\s*(typedef\s+)?struct\s*\w*\s*(?:\/\*.*\*\/)?\s*{(.*)}\s*\w*\s*;\s*$/s) {
1480 my $struct_contents = $2;
1482 foreach $decl_line (split (/\n/, $struct_contents)) {
1483 #print "Struct line: $decl_line\n";
1484 if ($decl_line =~ m%/\*\s*<\s*(public|protected)\s*>\s*\*/%) {
1486 } elsif ($decl_line =~ m%/\*\s*<\s*private\s*>\s*\*/%) {
1489 $new_declaration .= $decl_line . "\n";
1493 if ($new_declaration) {
1494 # Strip any blank lines off the ends.
1495 $new_declaration =~ s/^\s*\n//;
1496 $new_declaration =~ s/\n\s*$/\n/;
1499 $decl_out = "typedef struct {\n" . $new_declaration
1502 $decl_out = "struct $symbol {\n" . $new_declaration
1507 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1508 "Couldn't parse struct:\n$declaration");
1511 # If we couldn't parse the struct or it was all private, output an
1512 # empty struct declaration.
1513 if ($decl_out eq "") {
1515 $decl_out = "typedef struct _$symbol $symbol;";
1517 $decl_out = "struct $symbol;";
1522 $decl_out = &CreateValidSGML ($decl_out);
1523 $desc .= "<programlisting>$decl_out</programlisting>\n";
1525 $desc .= &MakeDeprecationNote($symbol);
1527 if (defined ($SymbolDocs{$symbol})) {
1528 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1531 # Create a table of fields and descriptions
1533 # FIXME: Inserting  's into the produced type declarations here would
1534 # improve the output in most situations ... except for function
1535 # members of structs!
1536 my @fields = ParseStructDeclaration($declaration, !$default_to_public,
1539 "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1541 my $params = $SymbolParams{$symbol};
1543 # If no parameters are filled in, we don't generate the description
1544 # table, for backwards compatibility
1547 if (defined $params) {
1548 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1549 if ($params->[$i] =~ /\S/) {
1557 my %field_descrs = @$params;
1558 my $missing_parameters = "";
1559 my $unused_parameters = "";
1561 $desc .= "<variablelist role=\"struct\">\n";
1563 my $field_name = shift @fields;
1564 my $text = shift @fields;
1565 my $field_descr = $field_descrs{$field_name};
1566 my $param_annotations = "";
1568 $desc .= "<varlistentry><term>$text</term>\n";
1569 if (defined $field_descr) {
1570 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1571 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1572 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1573 delete $field_descrs{$field_name};
1575 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1576 "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1577 if ($missing_parameters ne "") {
1578 $missing_parameters .= ", ".$field_name;
1580 $missing_parameters = $field_name;
1582 $desc .= "<listitem />\n";
1584 $desc .= "</varlistentry>\n";
1586 $desc .= "</variablelist>";
1587 foreach my $field_name (keys %field_descrs) {
1588 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1589 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1590 if ($unused_parameters ne "") {
1591 $unused_parameters .= ", ".$field_name;
1593 $unused_parameters = $field_name;
1597 # remember missing/unused parameters (needed in tmpl-free build)
1598 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1599 $AllIncompleteSymbols{$symbol}=$missing_parameters;
1601 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1602 $AllUnusedSymbols{$symbol}=$unused_parameters;
1606 if (scalar(@fields) > 0) {
1607 if (! exists ($AllIncompleteSymbols{$symbol})) {
1608 $AllIncompleteSymbols{$symbol}="<items>";
1609 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1610 "Field descriptions for $symbol are missing in source code comment block.");
1615 $desc .= OutputSymbolTraits ($symbol);
1616 $desc .= "</refsect2>\n";
1617 return ($synop, $desc);
1621 #############################################################################
1622 # Function : OutputUnion
1623 # Description : Returns the synopsis and detailed description of a union.
1624 # Arguments : $symbol - the union.
1625 # $declaration - the declaration of the union.
1626 #############################################################################
1629 my ($symbol, $declaration) = @_;
1630 my $id = &CreateValidSGMLID ($symbol);
1631 my $condition = &MakeConditionDescription ($symbol);
1633 # Determine if it is a simple struct or it also has a typedef.
1634 my $has_typedef = 0;
1635 if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1642 # For unions with typedefs we just output the union name.
1643 $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1644 $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>$symbol</title>\n";
1646 $synop = &MakeReturnField("union") . "<link linkend=\"$id\">$symbol</link>;\n";
1647 $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>union $symbol</title>\n";
1650 $desc .= MakeIndexterms($symbol, $id);
1652 $desc .= OutputSymbolExtraLinks($symbol);
1654 # FIXME: we do more for structs
1655 my $decl_out = &CreateValidSGML ($declaration);
1656 $desc .= "<programlisting>$decl_out</programlisting>\n";
1658 $desc .= &MakeDeprecationNote($symbol);
1660 if (defined ($SymbolDocs{$symbol})) {
1661 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1664 # Create a table of fields and descriptions
1666 # FIXME: Inserting  's into the produced type declarations here would
1667 # improve the output in most situations ... except for function
1668 # members of structs!
1669 my @fields = ParseStructDeclaration($declaration, 0,
1672 "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1674 my $params = $SymbolParams{$symbol};
1676 # If no parameters are filled in, we don't generate the description
1677 # table, for backwards compatibility
1680 if (defined $params) {
1681 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1682 if ($params->[$i] =~ /\S/) {
1690 my %field_descrs = @$params;
1691 my $missing_parameters = "";
1692 my $unused_parameters = "";
1694 $desc .= "<variablelist role=\"union\">\n";
1696 my $field_name = shift @fields;
1697 my $text = shift @fields;
1698 my $field_descr = $field_descrs{$field_name};
1699 my $param_annotations = "";
1701 $desc .= "<varlistentry><term>$text</term>\n";
1702 if (defined $field_descr) {
1703 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1704 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1705 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1706 delete $field_descrs{$field_name};
1708 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1709 "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1710 if ($missing_parameters ne "") {
1711 $missing_parameters .= ", ".$field_name;
1713 $missing_parameters = $field_name;
1715 $desc .= "<listitem />\n";
1717 $desc .= "</varlistentry>\n";
1719 $desc .= "</variablelist>";
1720 foreach my $field_name (keys %field_descrs) {
1721 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1722 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1723 if ($unused_parameters ne "") {
1724 $unused_parameters .= ", ".$field_name;
1726 $unused_parameters = $field_name;
1730 # remember missing/unused parameters (needed in tmpl-free build)
1731 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1732 $AllIncompleteSymbols{$symbol}=$missing_parameters;
1734 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1735 $AllUnusedSymbols{$symbol}=$unused_parameters;
1739 if (scalar(@fields) > 0) {
1740 if (! exists ($AllIncompleteSymbols{$symbol})) {
1741 $AllIncompleteSymbols{$symbol}="<items>";
1742 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1743 "Field descriptions for $symbol are missing in source code comment block.");
1748 $desc .= OutputSymbolTraits ($symbol);
1749 $desc .= "</refsect2>\n";
1750 return ($synop, $desc);
1754 #############################################################################
1755 # Function : OutputEnum
1756 # Description : Returns the synopsis and detailed description of a enum.
1757 # Arguments : $symbol - the enum.
1758 # $declaration - the declaration of the enum.
1759 #############################################################################
1762 my ($symbol, $declaration) = @_;
1763 my $id = &CreateValidSGMLID ($symbol);
1764 my $condition = &MakeConditionDescription ($symbol);
1765 my $synop = &MakeReturnField("enum") . "<link linkend=\"$id\">$symbol</link>;\n";
1766 my $desc = "<refsect2 id=\"$id\" role=\"enum\"$condition>\n<title>enum $symbol</title>\n";
1768 $desc .= MakeIndexterms($symbol, $id);
1770 $desc .= OutputSymbolExtraLinks($symbol);
1772 my $decl_out = &CreateValidSGML ($declaration);
1773 $desc .= "<programlisting>$decl_out</programlisting>\n";
1775 $desc .= &MakeDeprecationNote($symbol);
1777 if (defined ($SymbolDocs{$symbol})) {
1778 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1781 # Create a table of fields and descriptions
1783 my @fields = ParseEnumDeclaration($declaration);
1784 my $params = $SymbolParams{$symbol};
1786 # If no parameters are filled in, we don't generate the description
1787 # table, for backwards compatibility
1790 if (defined $params) {
1791 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1792 if ($params->[$i] =~ /\S/) {
1800 my %field_descrs = @$params;
1801 my $missing_parameters = "";
1802 my $unused_parameters = "";
1804 $desc .= "<variablelist role=\"enum\">\n";
1805 for my $field_name (@fields) {
1806 my $field_descr = $field_descrs{$field_name};
1807 my $param_annotations = "";
1809 $id = &CreateValidSGMLID ($field_name);
1810 $condition = &MakeConditionDescription ($field_name);
1811 $desc .= "<varlistentry id=\"$id\" role=\"constant\"$condition>\n<term><literal>$field_name</literal></term>\n";
1812 if (defined $field_descr) {
1813 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1814 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1815 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1816 delete $field_descrs{$field_name};
1818 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1819 "Value description for $symbol"."::"."$field_name is missing in source code comment block.");
1820 if ($missing_parameters ne "") {
1821 $missing_parameters .= ", ".$field_name;
1823 $missing_parameters = $field_name;
1825 $desc .= "<listitem />\n";
1827 $desc .= "</varlistentry>\n";
1829 $desc .= "</variablelist>";
1830 foreach my $field_name (keys %field_descrs) {
1831 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1832 "Value description for $symbol"."::"."$field_name is not used from source code comment block.");
1833 if ($unused_parameters ne "") {
1834 $unused_parameters .= ", ".$field_name;
1836 $unused_parameters = $field_name;
1840 # remember missing/unused parameters (needed in tmpl-free build)
1841 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1842 $AllIncompleteSymbols{$symbol}=$missing_parameters;
1844 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1845 $AllUnusedSymbols{$symbol}=$unused_parameters;
1849 if (scalar(@fields) > 0) {
1850 if (! exists ($AllIncompleteSymbols{$symbol})) {
1851 $AllIncompleteSymbols{$symbol}="<items>";
1852 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1853 "Value descriptions for $symbol are missing in source code comment block.");
1858 $desc .= OutputSymbolTraits ($symbol);
1859 $desc .= "</refsect2>\n";
1860 return ($synop, $desc);
1864 #############################################################################
1865 # Function : OutputVariable
1866 # Description : Returns the synopsis and detailed description of a variable.
1867 # Arguments : $symbol - the extern'ed variable.
1868 # $declaration - the declaration of the variable.
1869 #############################################################################
1871 sub OutputVariable {
1872 my ($symbol, $declaration) = @_;
1873 my $id = &CreateValidSGMLID ($symbol);
1874 my $condition = &MakeConditionDescription ($symbol);
1877 if ($declaration =~ m/^\s*extern\s+((const\s+|signed\s+|unsigned\s+)*\w+)(\s+\*+|\*+|\s)(\s*)([A-Za-z]\w*)\s*;/) {
1878 my $mod = defined ($1) ? $1 : "";
1879 my $ptr = defined ($3) ? $3 : "";
1880 my $space = defined ($4) ? $4 : "";
1881 $synop = &MakeReturnField("extern") . "$mod$ptr$space<link linkend=\"$id\">$symbol</link>;\n";
1884 $synop = &MakeReturnField("extern") . "<link linkend=\"$id\">$symbol</link>;\n";
1887 my $desc = "<refsect2 id=\"$id\" role=\"variable\"$condition>\n<title>$symbol</title>\n";
1889 $desc .= MakeIndexterms($symbol, $id);
1891 $desc .= OutputSymbolExtraLinks($symbol);
1893 my $decl_out = &CreateValidSGML ($declaration);
1894 $desc .= "<programlisting>$decl_out</programlisting>\n";
1896 $desc .= &MakeDeprecationNote($symbol);
1898 if (defined ($SymbolDocs{$symbol})) {
1899 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1901 $desc .= OutputSymbolTraits ($symbol);
1902 $desc .= "</refsect2>\n";
1903 return ($synop, $desc);
1907 #############################################################################
1908 # Function : OutputFunction
1909 # Description : Returns the synopsis and detailed description of a function.
1910 # Arguments : $symbol - the function.
1911 # $declaration - the declaration of the function.
1912 #############################################################################
1914 sub OutputFunction {
1915 my ($symbol, $declaration, $symbol_type) = @_;
1916 my $id = &CreateValidSGMLID ($symbol);
1917 my $condition = &MakeConditionDescription ($symbol);
1919 # Take out the return type $1 $3 $4
1920 $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//;
1921 my $type_modifier = defined($1) ? $1 : "";
1924 #print "$symbol pointer is $pointer\n";
1925 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1927 #if ($symbol_type eq 'USER_FUNCTION') {
1928 # $start = "typedef ";
1931 # We output const rather than G_CONST_RETURN.
1932 $type_modifier =~ s/G_CONST_RETURN/const/g;
1933 $pointer =~ s/G_CONST_RETURN/const/g;
1934 $pointer =~ s/^\s+/ /g;
1936 my $ret_type_len = length ($start) + length ($type_modifier)
1937 + length ($pointer) + length ($type);
1938 my $ret_type_output;
1940 if ($ret_type_len < $RETURN_TYPE_FIELD_WIDTH) {
1941 $ret_type_output = "$start$type_modifier$xref$pointer"
1942 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
1945 #$ret_type_output = "$start$type_modifier$xref$pointer\n" . (' ' x $RETURN_TYPE_FIELD_WIDTH);
1947 $ret_type_output = "$start$type_modifier$xref$pointer ";
1948 $symbol_len = $ret_type_len + 1 - $RETURN_TYPE_FIELD_WIDTH;
1951 $symbol_len += length ($symbol);
1952 my $char1 = my $char2 = my $char3 = "";
1953 if ($symbol_type eq 'USER_FUNCTION') {
1960 my ($symbol_output, $symbol_desc_output);
1961 if ($symbol_len < $SYMBOL_FIELD_WIDTH) {
1962 $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3"
1963 . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1964 $symbol_desc_output = "$char1$char2$symbol$char3"
1965 . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1967 $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3\n"
1968 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1969 $symbol_desc_output = "$char1$char2$symbol$char3\n"
1970 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1973 my $synop = $ret_type_output . $symbol_output . '(';
1974 my $desc = "<refsect2 id=\"$id\" role=\"function\"$condition>\n<title>${symbol} ()</title>\n";
1976 $desc .= MakeIndexterms($symbol, $id);
1978 $desc .= OutputSymbolExtraLinks($symbol);
1980 $desc .= "<programlisting>${ret_type_output}$symbol_desc_output(";
1982 my @fields = ParseFunctionDeclaration($declaration, \&MakeXRef,
1984 &tagify($_[0],"parameter");
1987 for (my $i = 1; $i <= $#fields; $i += 2) {
1988 my $field_name = $fields[$i];
1990 if ($field_name eq "Varargs") {
1991 $field_name = "...";
1995 $synop .= "$field_name";
1996 $desc .= "$field_name";
1999 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2002 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2009 $desc .= ");</programlisting>\n";
2011 $desc .= &MakeDeprecationNote($symbol);
2013 my $parameters = &OutputParamDescriptions ("FUNCTION", $symbol, @fields);
2014 my $parameters_output = 0;
2016 if (defined ($SymbolDocs{$symbol})) {
2017 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
2019 # Try to insert the parameter table at the author's desired position.
2020 # Otherwise we need to tag it onto the end.
2021 # FIXME: document that in the user manual and make it useable for other
2023 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
2024 $parameters_output = 1;
2026 $desc .= $symbol_docs;
2029 if ($parameters_output == 0) {
2030 $desc .= $parameters;
2033 $desc .= OutputSymbolTraits ($symbol);
2034 $desc .= "</refsect2>\n";
2035 return ($synop, $desc);
2039 #############################################################################
2040 # Function : OutputParamDescriptions
2041 # Description : Returns the DocBook output describing the parameters of a
2042 # function, macro or signal handler.
2043 # Arguments : $symbol_type - 'FUNCTION', 'MACRO' or 'SIGNAL'. Signal
2044 # handlers have an implicit user_data parameter last.
2045 # $symbol - the name of the function/macro being described.
2046 # @fields - parsed fields from the declaration, used to determine
2047 # undocumented/unused entries
2048 #############################################################################
2050 sub OutputParamDescriptions {
2051 my ($symbol_type, $symbol, @fields) = @_;
2053 my $params = $SymbolParams{$symbol};
2055 my %field_descrs = ();
2058 %field_descrs = @fields;
2059 delete $field_descrs{"void"};
2060 delete $field_descrs{"Returns"};
2063 if (defined $params) {
2065 my $params_desc = "";
2066 my $missing_parameters = "";
2067 my $unused_parameters = "";
2070 for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
2071 my $param_name = $$params[$j];
2072 my $param_desc = $$params[$j + 1];
2073 my $param_annotations = "";
2075 ($param_desc,$param_annotations) = & ExpandAnnotation($symbol, $param_desc);
2076 $param_desc = &ExpandAbbreviations($symbol, $param_desc);
2077 $param_desc .= $param_annotations;
2078 if ($param_name eq "Returns") {
2079 $returns = "$param_desc";
2080 } elsif ($param_name eq "void") {
2081 #print "!!!! void in params for $symbol?\n";
2084 if (!defined $field_descrs{$param_name}) {
2085 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2086 "Parameter description for $symbol"."::"."$param_name is not used from source code comment block.");
2087 if ($unused_parameters ne "") {
2088 $unused_parameters .= ", ".$param_name;
2090 $unused_parameters = $param_name;
2093 delete $field_descrs{$param_name};
2096 if ($param_name eq "Varargs") {
2097 $param_name = "...";
2099 if($param_desc ne "") {
2100 $params_desc .= "<varlistentry><term><parameter>$param_name</parameter> :</term>\n<listitem><simpara>$param_desc</simpara></listitem></varlistentry>\n";
2105 foreach my $param_name (keys %field_descrs) {
2106 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2107 "Parameter description for $symbol"."::"."$param_name is missing in source code comment block.");
2108 if ($missing_parameters ne "") {
2109 $missing_parameters .= ", ".$param_name;
2111 $missing_parameters = $param_name;
2115 # Signals have an implicit user_data parameter which we describe.
2116 if ($symbol_type eq "SIGNAL") {
2117 $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";
2120 # Start a table if we need one.
2121 if ($params_desc || $returns) {
2122 $output .= "<variablelist role=\"params\">\n";
2123 if ($params_desc ne "") {
2124 #$output .= "<varlistentry><term>Parameters:</term><listitem></listitem></varlistentry>\n";
2125 $output .= $params_desc;
2128 # Output the returns info last.
2130 $output .= "<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>$returns</simpara></listitem></varlistentry>\n";
2134 $output .= "</variablelist>";
2137 # remember missing/unused parameters (needed in tmpl-free build)
2138 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
2139 $AllIncompleteSymbols{$symbol}=$missing_parameters;
2141 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
2142 $AllUnusedSymbols{$symbol}=$unused_parameters;
2145 if (($num_params == 0) && @fields && (scalar(keys(%field_descrs)) > 0)) {
2146 if (! exists ($AllIncompleteSymbols{$symbol})) {
2147 $AllIncompleteSymbols{$symbol}="<parameters>";
2155 #############################################################################
2156 # Function : ParseStabilityLevel
2157 # Description : Parses a stability level and outputs a warning if it isn't
2159 # Arguments : $stability - the stability text.
2160 # $file, $line - context for error message
2161 # $message - description of where the level is from, to use in
2162 # any error message.
2163 # Returns : The parsed stability level string.
2164 #############################################################################
2166 sub ParseStabilityLevel {
2167 my ($stability, $file, $line, $message) = @_;
2169 $stability =~ s/^\s*//;
2170 $stability =~ s/\s*$//;
2171 if ($stability =~ m/^stable$/i) {
2172 $stability = "Stable";
2173 } elsif ($stability =~ m/^unstable$/i) {
2174 $stability = "Unstable";
2175 } elsif ($stability =~ m/^private$/i) {
2176 $stability = "Private";
2178 &LogWarning ($file, $line, "$message is $stability.".
2179 "It should be one of these: Stable, Unstable, or Private.");
2185 #############################################################################
2186 # Function : OutputSGMLFile
2187 # Description : Outputs the final DocBook file for one section.
2188 # Arguments : $file - the name of the file.
2189 # $title - the title from the $MODULE-sections.txt file, which
2190 # will be overridden by the title in the template file.
2191 # $section_id - the SGML id to use for the toplevel tag.
2192 # $includes - comma-separates list of include files added at top
2193 # of synopsis, with '<' '>' around them (if not already enclosed in "").
2194 # $synopsis - reference to the DocBook for the Synopsis part.
2195 # $details - reference to the DocBook for the Details part.
2196 # $signal_synop - reference to the DocBook for the Signal Synopsis part
2197 # $signal_desc - reference to the DocBook for the Signal Description part
2198 # $args_synop - reference to the DocBook for the Arg Synopsis part
2199 # $args_desc - reference to the DocBook for the Arg Description part
2200 # $hierarchy - reference to the DocBook for the Object Hierarchy part
2201 # $interfaces - reference to the DocBook for the Interfaces part
2202 # $implementations - reference to the DocBook for the Known Implementations part
2203 # $prerequisites - reference to the DocBook for the Prerequisites part
2204 # $derived - reference to the DocBook for the Derived Interfaces part
2205 # $file_objects - reference to an array of objects in this file
2206 #############################################################################
2208 sub OutputSGMLFile {
2209 my ($file, $title, $section_id, $includes, $synopsis, $details, $signals_synop, $signals_desc, $args_synop, $args_desc, $hierarchy, $interfaces, $implementations, $prerequisites, $derived, $file_objects) = @_;
2211 #print "Output sgml for file $file with title '$title'\n";
2213 # The edited title overrides the one from the sections file.
2214 my $new_title = $SymbolDocs{"$TMPL_DIR/$file:Title"};
2215 if (defined ($new_title) && $new_title !~ m/^\s*$/) {
2216 $title = $new_title;
2217 #print "Found title: $title\n";
2219 my $short_desc = $SymbolDocs{"$TMPL_DIR/$file:Short_Description"};
2220 if (!defined ($short_desc) || $short_desc =~ m/^\s*$/) {
2223 $short_desc = &ExpandAbbreviations("$title:Short_description",
2225 #print "Found short_desc: $short_desc";
2227 my $long_desc = $SymbolDocs{"$TMPL_DIR/$file:Long_Description"};
2228 if (!defined ($long_desc) || $long_desc =~ m/^\s*$/) {
2231 $long_desc = &ExpandAbbreviations("$title:Long_description",
2233 #print "Found long_desc: $long_desc";
2235 my $see_also = $SymbolDocs{"$TMPL_DIR/$file:See_Also"};
2236 if (!defined ($see_also) || $see_also =~ m%^\s*(<para>)?\s*(</para>)?\s*$%) {
2239 $see_also = &ExpandAbbreviations("$title:See_Also", $see_also);
2240 #print "Found see_also: $see_also";
2243 $see_also = "<refsect1 id=\"$section_id.see-also\">\n<title>See Also</title>\n$see_also\n</refsect1>\n";
2245 my $stability = $SymbolDocs{"$TMPL_DIR/$file:Stability_Level"};
2246 if (!defined ($stability) || $stability =~ m/^\s*$/) {
2249 $stability = &ParseStabilityLevel($stability, $file, $., "Section stability level");
2250 #print "Found stability: $stability";
2253 $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$stability, unless otherwise indicated\n</refsect1>\n";
2254 } elsif ($DEFAULT_STABILITY) {
2255 $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$DEFAULT_STABILITY, unless otherwise indicated\n</refsect1>\n";
2258 my $image = $SymbolDocs{"$TMPL_DIR/$file:Image"};
2259 if (!defined ($image) || $image =~ m/^\s*$/) {
2267 if ($image =~ /jpe?g$/i) {
2268 $format = "format='JPEG'";
2269 } elsif ($image =~ /png$/i) {
2270 $format = "format='PNG'";
2271 } elsif ($image =~ /svg$/i) {
2272 $format = "format='SVG'";
2277 $image = " <inlinegraphic fileref='$image' $format/>\n"
2280 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
2282 my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
2285 my $include_output = "";
2287 foreach $include (split (/,/, $includes)) {
2288 if ($include =~ m/^\".+\"$/) {
2289 $include_output .= "#include ${include}\n";
2292 $include =~ s/^\s+|\s+$//gs;
2293 $include_output .= "#include <${include}>\n";
2296 if ($include_output ne '') {
2297 $include_output = "\n$include_output\n";
2300 my $extralinks = OutputSectionExtraLinks($title,"Section:$file");
2302 my $old_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT";
2303 my $new_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT.new";
2305 open (OUTPUT, ">$new_sgml_file")
2306 || die "Can't create $new_sgml_file: $!";
2308 my $object_anchors = "";
2309 foreach my $object (@$file_objects) {
2310 next if ($object eq $section_id);
2311 my $id = CreateValidSGMLID($object);
2312 #print "Debug: Adding anchor for $object\n";
2313 $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
2316 # We used to output this, but is messes up our UpdateFileIfChanged code
2317 # since it changes every day (and it is only used in the man pages):
2318 # "<refentry id="$section_id" revision="$mday $month $year">"
2320 if ($OUTPUT_FORMAT eq "xml") {
2321 print OUTPUT $doctype_header;
2325 <refentry id="$section_id">
2327 <refentrytitle role="top_of_page" id="$section_id.top_of_page">$title</refentrytitle>
2328 <manvolnum>3</manvolnum>
2331 $image</refmiscinfo>
2334 <refname>$title</refname>
2335 <refpurpose>$short_desc</refpurpose>
2338 <refsynopsisdiv id="$section_id.synopsis" role="synopsis">
2339 <title role="synopsis.title">Synopsis</title>
2341 <synopsis>$include_output$${synopsis}</synopsis>
2343 $$hierarchy$$prerequisites$$derived$$interfaces$$implementations$$args_synop$$signals_synop
2344 <refsect1 id="$section_id.description" role="desc">
2345 <title role="desc.title">Description</title>
2346 $extralinks$long_desc
2348 <refsect1 id="$section_id.details" role="details">
2349 <title role="details.title">Details</title>
2352 $$args_desc$$signals_desc$see_also
2357 return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2361 #############################################################################
2362 # Function : OutputExtraFile
2363 # Description : Copies an "extra" DocBook file into the output directory,
2364 # expanding abbreviations
2365 # Arguments : $file - the source file.
2366 #############################################################################
2367 sub OutputExtraFile {
2372 ($basename = $file) =~ s!^.*/!!;
2374 my $old_sgml_file = "$SGML_OUTPUT_DIR/$basename";
2375 my $new_sgml_file = "$SGML_OUTPUT_DIR/$basename.new";
2379 open(EXTRA_FILE, "<$file") || die "Can't open $file";
2383 $contents = <EXTRA_FILE>;
2386 open (OUTPUT, ">$new_sgml_file")
2387 || die "Can't create $new_sgml_file: $!";
2389 print OUTPUT &ExpandAbbreviations ("$basename file", $contents);
2392 return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2394 #############################################################################
2395 # Function : OutputBook
2396 # Description : Outputs the SGML entities that need to be included into the
2397 # main SGML file for the module.
2398 # Arguments : $book_top - the declarations of the entities, which are added
2399 # at the top of the main SGML file.
2400 # $book_bottom - the references to the entities, which are
2401 # added in the main SGML file at the desired position.
2402 #############################################################################
2405 my ($book_top, $book_bottom) = @_;
2407 my $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top";
2408 my $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top.new";
2410 open (OUTPUT, ">$new_file")
2411 || die "Can't create $new_file: $!";
2412 print OUTPUT $book_top;
2415 &UpdateFileIfChanged ($old_file, $new_file, 0);
2418 $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom";
2419 $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom.new";
2421 open (OUTPUT, ">$new_file")
2422 || die "Can't create $new_file: $!";
2423 print OUTPUT $book_bottom;
2426 &UpdateFileIfChanged ($old_file, $new_file, 0);
2429 # If the main SGML/XML file hasn't been created yet, we create it here.
2430 # The user can tweak it later.
2431 if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
2432 open (OUTPUT, ">$MAIN_SGML_FILE")
2433 || die "Can't create $MAIN_SGML_FILE: $!";
2435 if ($OUTPUT_FORMAT eq "xml") {
2437 <?xml version="1.0"?>
2438 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
2439 "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
2441 <!ENTITY % local.common.attrib "xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'">
2447 <!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
2456 <title>$MODULE Reference Manual</title>
2458 for $MODULE [VERSION].
2459 The latest version of this documentation can be found on-line at
2460 <ulink role="online-location" url="http://[SERVER]/$MODULE/index.html">http://[SERVER]/$MODULE/</ulink>.
2465 <title>[Insert title here]</title>
2469 if (-e $OBJECT_TREE_FILE) {
2471 <chapter id="object-tree">
2472 <title>Object Hierarchy</title>
2473 <xi:include href="xml/tree_index.sgml"/>
2479 <index id="api-index-full">
2480 <title>API Index</title>
2481 <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
2484 <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
2493 #############################################################################
2494 # Function : CreateValidSGML
2495 # Description : This turns any chars which are used in SGML into entities,
2496 # e.g. '<' into '<'
2497 # Arguments : $text - the text to turn into proper SGML.
2498 #############################################################################
2500 sub CreateValidSGML {
2502 $text =~ s/&/&/g; # Do this first, or the others get messed up.
2503 $text =~ s/</</g;
2504 $text =~ s/>/>/g;
2505 # browers render single tabs inconsistently
2506 $text =~ s/([^\s])\t([^\s])/$1 $2/g;
2510 #############################################################################
2511 # Function : ConvertSGMLChars
2512 # Description : This is used for text in source code comment blocks, to turn
2513 # chars which are used in SGML into entities, e.g. '<' into
2514 # '<'. Depending on $SGML_MODE, this is done
2515 # unconditionally or only if the character doesn't seem to be
2516 # part of an SGML construct (tag or entity reference).
2517 # Arguments : $text - the text to turn into proper SGML.
2518 #############################################################################
2520 sub ConvertSGMLChars {
2521 my ($symbol, $text) = @_;
2524 # For the SGML mode only convert to entities outside CDATA sections.
2525 return &ModifyXMLElements ($text, $symbol,
2526 "<!\\[CDATA\\[|<programlisting[^>]*>",
2527 \&ConvertSGMLCharsEndTag,
2528 \&ConvertSGMLCharsCallback);
2530 # For the simple non-sgml mode, convert to entities everywhere.
2531 $text =~ s/&/&/g; # Do this first, or the others get messed up.
2532 $text =~ s/</</g;
2533 $text =~ s/>/>/g;
2539 sub ConvertSGMLCharsEndTag {
2540 if ($_[0] eq "<!\[CDATA\[") {
2543 return "</programlisting>";
2547 sub ConvertSGMLCharsCallback {
2548 my ($text, $symbol, $tag) = @_;
2550 if ($tag =~ m/^<programlisting/) {
2551 # We can handle <programlisting> specially here.
2552 return &ModifyXMLElements ($text, $symbol,
2554 \&ConvertSGMLCharsEndTag,
2555 \&ConvertSGMLCharsCallback2);
2556 } elsif ($tag eq "") {
2557 # If we're not in CDATA convert to entities.
2558 $text =~ s/&(?![a-zA-Z#]+;)/&/g; # Do this first, or the others get messed up.
2559 $text =~ s/<(?![a-zA-Z\/!])/</g;
2560 $text =~ s/(?<![a-zA-Z0-9"'\/-])>/>/g;
2562 # Handle "#include <xxxxx>"
2563 $text =~ s/#include(\s+)<([^>]+)>/#include$1<$2>/g;
2569 sub ConvertSGMLCharsCallback2 {
2570 my ($text, $symbol, $tag) = @_;
2572 # If we're not in CDATA convert to entities.
2573 # We could handle <programlisting> differently, though I'm not sure it helps.
2575 # replace only if its not a tag
2576 $text =~ s/&(?![a-zA-Z#]+;)/&/g; # Do this first, or the others get messed up.
2577 $text =~ s/<(?![a-zA-Z\/!])/</g;
2578 $text =~ s/(?<![a-zA-Z0-9"'\/-])>/>/g;
2580 # Handle "#include <xxxxx>"
2581 $text =~ s/#include(\s+)<([^>]+)>/#include$1<$2>/g;
2587 #############################################################################
2588 # Function : ExpandAnnotation
2589 # Description : This turns annotations into acrony tags.
2590 # Arguments : $symbol - the symbol being documented, for error messages.
2591 # $text - the text to expand.
2592 #############################################################################
2593 sub ExpandAnnotation {
2594 my ($symbol, $param_desc) = @_;
2595 my $param_annotations = "";
2597 if ($param_desc =~ m%\s*\((.*)\):%) {
2600 my $annotation_extra = "";
2603 @annotations = split(/\)\s*\(/,$1);
2604 foreach $annotation (@annotations) {
2605 # need to search for the longest key-match in %AnnotationDefinition
2607 my $match_annotation="";
2609 foreach $annotationdef (keys %AnnotationDefinition) {
2610 if ($annotation =~ m/^$annotationdef/) {
2611 if (length($annotationdef)>$match_length) {
2612 $match_length=length($annotationdef);
2613 $match_annotation=$annotationdef;
2617 if ($match_annotation ne "") {
2618 if ($annotation =~ m%$match_annotation\s+(.*)%) {
2619 $annotation_extra = " $1";
2621 $AnnotationsUsed{$match_annotation} = 1;
2622 $param_annotations .= "[<acronym>$match_annotation</acronym>$annotation_extra]";
2625 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2626 "unknown annotation \"$annotation\" in documentation for $symbol.");
2627 $param_annotations .= "[$annotation]";
2631 $param_desc =~ m/^(.*?)\.*\s*$/s;
2632 $param_desc = "$1. ";
2634 if ($param_annotations ne "") {
2635 $param_annotations = "<emphasis role=\"annotation\">$param_annotations</emphasis>";
2637 return ($param_desc, $param_annotations);
2640 #############################################################################
2641 # Function : ExpandAbbreviations
2642 # Description : This turns the abbreviations function(), macro(), @param,
2643 # %constant, and #symbol into appropriate DocBook markup.
2644 # CDATA sections and <programlisting> parts are skipped.
2645 # Arguments : $symbol - the symbol being documented, for error messages.
2646 # $text - the text to expand.
2647 #############################################################################
2649 sub ExpandAbbreviations {
2650 my ($symbol, $text) = @_;
2652 # Convert "|[" and "]|" into the start and end of program listing examples.
2653 $text =~ s%\|\[%<informalexample><programlisting>%g;
2654 $text =~ s%\]\|%</programlisting></informalexample>%g;
2655 # TODO: check for a xml comment after |[ and pick the language attribute from
2658 # keep CDATA unmodified, preserve ulink tags (ideally we preseve all tags
2660 return &ModifyXMLElements ($text, $symbol,
2661 "<!\\[CDATA\\[|<ulink[^>]*>|<programlisting[^>]*>|<!DOCTYPE",
2662 \&ExpandAbbreviationsEndTag,
2663 \&ExpandAbbreviationsCallback);
2667 # Returns the end tag corresponding to the given start tag.
2668 sub ExpandAbbreviationsEndTag {
2669 my ($start_tag) = @_;
2671 if ($start_tag eq "<!\[CDATA\[") {
2673 } elsif ($start_tag eq "<!DOCTYPE") {
2675 } elsif ($start_tag =~ m/<(\w+)/) {
2680 # Called inside or outside each CDATA or <programlisting> section.
2681 sub ExpandAbbreviationsCallback {
2682 my ($text, $symbol, $tag) = @_;
2684 if ($tag =~ m/^<programlisting/) {
2685 # Handle any embedded CDATA sections.
2686 return &ModifyXMLElements ($text, $symbol,
2688 \&ExpandAbbreviationsEndTag,
2689 \&ExpandAbbreviationsCallback2);
2690 } elsif ($tag eq "") {
2691 # We are outside any CDATA or <programlisting> sections, so we expand
2692 # any gtk-doc abbreviations.
2694 # Convert 'function()' or 'macro()'.
2695 # if there is abc_*_def() we don't want to make a link to _def()
2696 # FIXME: also handle abc(....) : but that would need to be done recursively :/
2697 $text =~ s/([^\*.\w])(\w+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2698 # handle #Object.func()
2699 $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2701 # Convert '@param', but not '\@param'.
2702 $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)/$1<parameter>$2<\/parameter>/g;
2703 $text =~ s/\\\@/\@/g;
2705 # Convert '%constant', but not '\%constant'.
2706 # Also allow negative numbers, e.g. %-1.
2707 $text =~ s/(\A|[^\\])\%(-?\w+)/$1.&MakeXRef($2, &tagify($2, "literal"));/eg;
2708 $text =~ s/\\\%/\%/g;
2710 # Convert '#symbol', but not '\#symbol'.
2711 $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)/$1.&MakeHashXRef($2, "type");/eg;
2715 # FIXME: should we skip urls that are already tagged? (e.g. <literal>http://...</literal>)
2716 # this is apparently also called for markup and not just for plain text
2718 #$text =~ s%(http|https|ftp)://(.*?)((?:\s|,|\)|\]|\<|\.\s))%<ulink url="$1://$2">$2</ulink>$3%g;
2720 # TODO: optionally check all words from $text against internal symbols and
2721 # warn if those could be xreffed, but miss a %,# or ()
2727 # This is called inside a <programlisting>
2728 sub ExpandAbbreviationsCallback2 {
2729 my ($text, $symbol, $tag) = @_;
2732 # We are inside a <programlisting> but outside any CDATA sections,
2733 # so we expand any gtk-doc abbreviations.
2734 # FIXME: why is this different from &ExpandAbbreviationsCallback(),
2735 # why not just call it
2736 $text =~ s/#(\w+)/&MakeHashXRef($1, "");/eg;
2743 my ($symbol, $tag) = @_;;
2746 # Check for things like '#include', '#define', and skip them.
2747 if ($PreProcessorDirectives{$symbol}) {
2751 # Get rid of any special '-struct' suffix.
2752 $text =~ s/-struct$//;
2754 # If the symbol is in the form "Object::signal", then change the symbol to
2755 # "Object-signal" and use "signal" as the text.
2756 if ($symbol =~ s/::/-/) {
2760 # If the symbol is in the form "Object:property", then change the symbol to
2761 # "Object--property" and use "property" as the text.
2762 if ($symbol =~ s/:/--/) {
2767 $text = tagify ($text, $tag);
2770 return &MakeXRef($symbol, $text);
2774 #############################################################################
2775 # Function : ModifyXMLElements
2776 # Description : Looks for given XML element tags within the text, and calls
2777 # the callback on pieces of text inside & outside those elements.
2778 # Used for special handling of text inside things like CDATA
2779 # and <programlisting>.
2780 # Arguments : $text - the text.
2781 # $symbol - the symbol currently being documented (only used for
2783 # $start_tag_regexp - the regular expression to match start tags.
2784 # e.g. "<!\\[CDATA\\[|<programlisting[^>]*>" to match
2785 # CDATA sections or programlisting elements.
2786 # $end_tag_func - function which is passed the matched start tag
2787 # and should return the appropriate end tag string.
2788 # $callback - callback called with each part of the text. It is
2789 # called with a piece of text, the symbol being
2790 # documented, and the matched start tag or "" if the text
2791 # is outside the XML elements being matched.
2792 #############################################################################
2793 sub ModifyXMLElements {
2794 my ($text, $symbol, $start_tag_regexp, $end_tag_func, $callback) = @_;
2795 my ($before_tag, $start_tag, $end_tag_regexp, $end_tag);
2798 while ($text =~ m/$start_tag_regexp/s) {
2799 $before_tag = $`; # Prematch for last successful match string
2800 $start_tag = $&; # Last successful match
2801 $text = $'; # Postmatch for last successful match string
2803 $result .= &$callback ($before_tag, $symbol, "");
2804 $result .= $start_tag;
2806 # get the mathing end-tag for current tag
2807 $end_tag_regexp = &$end_tag_func ($start_tag);
2809 if ($text =~ m/$end_tag_regexp/s) {
2814 $result .= &$callback ($before_tag, $symbol, $start_tag);
2815 $result .= $end_tag;
2817 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2818 "Can't find tag end: $end_tag_regexp in docs for: $symbol.");
2819 # Just assume it is all inside the tag.
2820 $result .= &$callback ($text, $symbol, $start_tag);
2825 # Handle any remaining text outside the tags.
2826 $result .= &$callback ($text, $symbol, "");
2835 # Adds a tag around some text.
2836 # e.g tagify("Text", "literal") => "<literal>Text</literal>".
2838 my ($text, $elem) = @_;
2839 return "<" . $elem . ">" . $text . "</" . $elem . ">";
2843 #############################################################################
2844 # Function : MakeXRef
2845 # Description : This returns a cross-reference link to the given symbol.
2846 # Though it doesn't try to do this for a few standard C types
2847 # that it knows won't be in the documentation.
2848 # Arguments : $symbol - the symbol to try to create a XRef to.
2849 # $text - text text to put inside the XRef, defaults to $symbol
2850 #############################################################################
2853 my ($symbol, $text) = ($_[0], $_[1]);
2855 $symbol =~ s/^\s+//;
2856 $symbol =~ s/\s+$//;
2858 if (!defined($text)) {
2861 # Get rid of special '-struct' suffix.
2862 $text =~ s/-struct$//;
2865 if ($symbol =~ m/ /) {
2869 #print "Getting type link for $symbol -> $text\n";
2871 my $symbol_id = &CreateValidSGMLID ($symbol);
2872 return "<link linkend=\"$symbol_id\">$text</link>";
2876 #############################################################################
2877 # Function : MakeIndexterms
2878 # Description : This returns a indexterm elements for the given symbol
2879 # Arguments : $symbol - the symbol to create indexterms for
2880 #############################################################################
2882 sub MakeIndexterms {
2883 my ($symbol, $id) = @_;
2887 # make the index useful, by ommiting the namespace when sorting
2888 if ($NAME_SPACE ne "") {
2889 if ($symbol =~ m/^$NAME_SPACE\_?(.*)/i) {
2890 $sortas=" sortas=\"$1\"";
2894 if (exists $Deprecated{$symbol}) {
2895 $terms .= "<indexterm zone=\"$id\" role=\"deprecated\"><primary$sortas>$symbol</primary></indexterm>";
2896 $IndexEntriesDeprecated{$symbol}=$id;
2897 $IndexEntriesFull{$symbol}=$id;
2899 if (exists $Since{$symbol}) {
2900 my $since = $Since{$symbol};
2904 $terms .= "<indexterm zone=\"$id\" role=\"$since\"><primary$sortas>$symbol</primary></indexterm>";
2906 $IndexEntriesSince{$symbol}=$id;
2907 $IndexEntriesFull{$symbol}=$id;
2910 $terms .= "<indexterm zone=\"$id\"><primary$sortas>$symbol</primary></indexterm>";
2911 $IndexEntriesFull{$symbol}=$id;
2917 #############################################################################
2918 # Function : MakeDeprecationNote
2919 # Description : This returns a deprecation warning for the given symbol.
2920 # Arguments : $symbol - the symbol to try to create a warning for.
2921 #############################################################################
2923 sub MakeDeprecationNote {
2924 my ($symbol) = $_[0];
2927 if (exists $Deprecated{$symbol}) {
2928 $desc .= "<warning>";
2930 if ($Deprecated{$symbol} =~ /^\s*([0-9\.]+)\s*:/) {
2931 $desc .= "<para><literal>$symbol</literal> has been deprecated since version $1 and should not be used in newly-written code.";
2933 $desc .= "<para><literal>$symbol</literal> is deprecated and should not be used in newly-written code.";
2935 if ($Deprecated{$symbol} ne "") {
2936 $note = &ExpandAbbreviations($symbol, $Deprecated{$symbol});
2937 $note =~ s/^\s*([0-9\.]+)\s*:\s*//;
2940 $note =~ s%\n{2,}%\n</para>\n<para>\n%g;
2941 $desc .= " " . $note;
2943 $desc .= "</para></warning>\n";
2948 #############################################################################
2949 # Function : MakeConditionDescription
2950 # Description : This returns a sumary of conditions for the given symbol.
2951 # Arguments : $symbol - the symbol to try to create the sumary.
2952 #############################################################################
2954 sub MakeConditionDescription {
2955 my ($symbol) = $_[0];
2958 if (exists $Deprecated{$symbol}) {
2963 if ($Deprecated{$symbol} =~ /^\s*(.*?)\s*$/) {
2964 $desc .= "deprecated:$1";
2966 $desc .= "deprecated";
2970 if (exists $Since{$symbol}) {
2975 if ($Since{$symbol} =~ /^\s*(.*?)\s*$/) {
2976 $desc .= "since:$1";
2982 if (exists $StabilityLevel{$symbol}) {
2986 $desc .= "stability:".$StabilityLevel{$symbol};
2990 $desc=" condition=\"".$desc."\"";
2991 #print "condition for '$symbol' = '$desc'\n";
2996 #############################################################################
2997 # Function : GetHierarchy
2998 # Description : Returns the DocBook output describing the ancestors and
2999 # immediate children of a GObject subclass. It uses the
3000 # global @Objects and @ObjectLevels arrays to walk the tree.
3001 # Arguments : $object - the GtkObject subclass.
3002 #############################################################################
3007 # Find object in the objects array.
3013 for ($i = 0; $i < @Objects; $i++) {
3015 if ($ObjectLevels[$i] <= $level) {
3018 elsif ($ObjectLevels[$i] == $level + 1) {
3019 push (@children, $Objects[$i]);
3022 elsif ($Objects[$i] eq $object) {
3025 $level = $ObjectLevels[$i];
3032 # Walk up the hierarchy, pushing ancestors onto the ancestors array.
3034 push (@ancestors, $object);
3035 #print "Level: $level\n";
3036 while ($level > 1) {
3038 if ($ObjectLevels[$j] < $level) {
3039 push (@ancestors, $Objects[$j]);
3040 $level = $ObjectLevels[$j];
3041 #print "Level: $level\n";
3045 # Output the ancestors list, indented and with links.
3046 my $hierarchy = "<synopsis>\n";
3048 for ($i = $#ancestors; $i >= 0; $i--) {
3050 # Don't add a link to the current object, i.e. when i == 0.
3052 my $ancestor_id = &CreateValidSGMLID ($ancestors[$i]);
3053 $link_text = "<link linkend=\"$ancestor_id\">$ancestors[$i]</link>";
3055 $link_text = "$ancestors[$i]";
3058 $hierarchy .= " $link_text\n";
3060 # $hierarchy .= ' ' x ($level * 6 - 3) . "|\n";
3061 $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3065 for ($i = 0; $i <= $#children; $i++) {
3066 my $id = &CreateValidSGMLID ($children[$i]);
3067 my $link_text = "<link linkend=\"$id\">$children[$i]</link>";
3068 $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3070 $hierarchy .= "</synopsis>\n";
3076 #############################################################################
3077 # Function : GetInterfaces
3078 # Description : Returns the DocBook output describing the interfaces
3079 # implemented by a class. It uses the global %Interfaces hash.
3080 # Arguments : $object - the GtkObject subclass.
3081 #############################################################################
3088 # Find object in the objects array.
3089 if (exists($Interfaces{$object})) {
3090 my @ifaces = split(' ', $Interfaces{$object});
3095 for ($i = 0; $i <= $#ifaces; $i++) {
3096 my $id = &CreateValidSGMLID ($ifaces[$i]);
3097 $text .= " <link linkend=\"$id\">$ifaces[$i]</link>";
3098 if ($i < $#ifaces - 1) {
3101 elsif ($i < $#ifaces) {
3116 #############################################################################
3117 # Function : GetImplementations
3118 # Description : Returns the DocBook output describing the implementations
3119 # of an interface. It uses the global %Interfaces hash.
3120 # Arguments : $object - the GtkObject subclass.
3121 #############################################################################
3123 sub GetImplementations {
3128 foreach my $key (keys %Interfaces) {
3129 if ($Interfaces{$key} =~ /\b$object\b/) {
3130 push (@impls, $key);
3134 @impls = sort @impls;
3137 $object is implemented by
3139 for ($i = 0; $i <= $#impls; $i++) {
3140 my $id = &CreateValidSGMLID ($impls[$i]);
3141 $text .= " <link linkend=\"$id\">$impls[$i]</link>";
3142 if ($i < $#impls - 1) {
3145 elsif ($i < $#impls) {
3160 #############################################################################
3161 # Function : GetPrerequisites
3162 # Description : Returns the DocBook output describing the prerequisites
3163 # of an interface. It uses the global %Prerequisites hash.
3164 # Arguments : $iface - the interface.
3165 #############################################################################
3167 sub GetPrerequisites {
3172 if (exists($Prerequisites{$iface})) {
3177 my @prereqs = split(' ', $Prerequisites{$iface});
3178 for ($i = 0; $i <= $#prereqs; $i++) {
3179 my $id = &CreateValidSGMLID ($prereqs[$i]);
3180 $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
3181 if ($i < $#prereqs - 1) {
3184 elsif ($i < $#prereqs) {
3198 #############################################################################
3199 # Function : GetDerived
3200 # Description : Returns the DocBook output describing the derived interfaces
3201 # of an interface. It uses the global %Prerequisites hash.
3202 # Arguments : $iface - the interface.
3203 #############################################################################
3211 foreach my $key (keys %Prerequisites) {
3212 if ($Prerequisites{$key} =~ /\b$iface\b/) {
3213 push (@derived, $key);
3216 if ($#derived >= 0) {
3217 @derived = sort @derived;
3220 $iface is required by
3222 for ($i = 0; $i <= $#derived; $i++) {
3223 my $id = &CreateValidSGMLID ($derived[$i]);
3224 $text .= " <link linkend=\"$id\">$derived[$i]</link>";
3225 if ($i < $#derived - 1) {
3228 elsif ($i < $#derived) {
3243 #############################################################################
3244 # Function : GetSignals
3245 # Description : Returns the synopsis and detailed description DocBook output
3246 # for the signal handlers of a given GtkObject subclass.
3247 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
3248 #############################################################################
3256 for ($i = 0; $i <= $#SignalObjects; $i++) {
3257 if ($SignalObjects[$i] eq $object) {
3258 #print "Found signal: $SignalNames[$i]\n";
3259 my $name = $SignalNames[$i];
3260 my $symbol = "${object}::${name}";
3261 my $id = &CreateValidSGMLID ("$object-$name");
3263 my $pad = ' ' x (46 - length($name));
3264 $synop .= " "<link linkend=\"$id\">$name</link>"$pad ";
3266 $desc .= "<refsect2 id=\"$id\" role=\"signal\"><title>The <literal>"$name"</literal> signal</title>\n";
3267 $desc .= MakeIndexterms($symbol, $id);
3269 $desc .= OutputSymbolExtraLinks($symbol);
3271 $desc .= "<programlisting>";
3273 $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
3274 my $type_modifier = defined($1) ? $1 : "";
3277 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
3279 my $ret_type_len = length ($type_modifier) + length ($pointer)
3281 my $ret_type_output = "$type_modifier$xref$pointer"
3282 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
3284 $desc .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
3286 my $sourceparams = $SourceSymbolParams{$symbol};
3287 my @params = split ("\n", $SignalPrototypes[$i]);
3290 my $type_len = length("gpointer");
3291 my $name_len = length("user_data");
3292 # do two passes, the first one is to calculate padding
3293 for ($l = 0; $l < 2; $l++) {
3294 for ($j = 0; $j <= $#params; $j++) {
3295 # allow alphanumerics, '_', '[' & ']' in param names
3296 if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
3299 if (defined($sourceparams)) {
3300 $name = $$sourceparams[$PARAM_FIELD_COUNT * $j];
3305 if (!defined($name)) {
3309 if (length($type) + length($pointer) > $type_len) {
3310 $type_len = length($type) + length($pointer);
3312 if (length($name) > $name_len) {
3313 $name_len = length($name);
3317 $xref = &MakeXRef ($type, &tagify($type, "type"));
3318 $pad = ' ' x ($type_len - length($type) - length($pointer));
3319 $desc .= "$xref$pad $pointer$name,\n";
3320 $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
3323 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3324 "Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]");
3328 $xref = &MakeXRef ("gpointer", &tagify("gpointer", "type"));
3329 $pad = ' ' x ($type_len - length("gpointer"));
3330 $desc .= "$xref$pad user_data)";
3332 my $flags = $SignalFlags[$i];
3333 my $flags_string = "";
3335 if (defined ($flags)) {
3336 if ($flags =~ m/f/) {
3337 $flags_string = "Run First";
3339 elsif ($flags =~ m/l/) {
3340 $flags_string = "Run Last";
3342 elsif ($flags =~ m/c/) {
3343 $flags_string = "Cleanup";
3345 if ($flags =~ m/r/) {
3346 if ($flags_string) { $flags_string .= " / "; }
3347 $flags_string .= "No Recursion";
3349 if ($flags =~ m/d/) {
3350 if ($flags_string) { $flags_string .= " / "; }
3351 $flags_string .= "Has Details";
3353 if ($flags =~ m/a/) {
3354 if ($flags_string) { $flags_string .= " / "; }
3355 $flags_string .= "Action";
3357 if ($flags =~ m/h/) {
3358 if ($flags_string) { $flags_string .= " / "; }
3359 $flags_string .= "No Hooks";
3365 $synop .= ": $flags_string\n";
3367 $pad = ' ' x (5 + $name_len - length("user_data"));
3368 $desc .= "$pad : $flags_string</programlisting>\n";
3373 $desc .= "</programlisting>\n";
3376 $desc .= &MakeDeprecationNote($symbol);
3378 my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
3379 my $parameters_output = 0;
3381 $AllSymbols{$symbol} = 1;
3382 if (defined ($SymbolDocs{$symbol})) {
3383 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3385 # Try to insert the parameter table at the author's desired
3386 # position. Otherwise we need to tag it onto the end.
3387 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
3388 $parameters_output = 1;
3390 $desc .= $symbol_docs;
3392 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
3393 $AllDocumentedSymbols{$symbol} = 1;
3397 if ($parameters_output == 0) {
3398 $desc .= $parameters;
3400 $desc .= OutputSymbolTraits ($symbol);
3401 $desc .= "</refsect2>";
3404 return ($synop, $desc);
3408 #############################################################################
3409 # Function : GetArgs
3410 # Description : Returns the synopsis and detailed description DocBook output
3411 # for the Args of a given GtkObject subclass.
3412 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
3413 #############################################################################
3419 my $child_synop = "";
3420 my $child_desc = "";
3421 my $style_synop = "";
3422 my $style_desc = "";
3425 for ($i = 0; $i <= $#ArgObjects; $i++) {
3426 if ($ArgObjects[$i] eq $object) {
3427 #print "Found arg: $ArgNames[$i]\n";
3428 my $name = $ArgNames[$i];
3429 my $flags = $ArgFlags[$i];
3430 my $flags_string = "";
3434 if ($flags =~ m/c/) {
3435 $kind = "child property";
3438 elsif ($flags =~ m/s/) {
3439 $kind = "style property";
3446 # Remember only one colon so we don't clash with signals.
3447 my $symbol = "${object}:${name}";
3448 # use two dashes and ev. an extra separator here for the same reason.
3449 my $id = &CreateValidSGMLID ("$object--$id_sep$name");
3451 my $type = $ArgTypes[$i];
3453 my $range = $ArgRanges[$i];
3454 my $range_output = CreateValidSGML ($range);
3455 my $default = $ArgDefaults[$i];
3456 my $default_output = CreateValidSGML ($default);
3458 if ($type eq "GtkString") {
3461 if ($type eq "GtkSignal") {
3462 $type = "GtkSignalFunc, gpointer";
3463 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
3464 . &MakeXRef ("gpointer");
3465 } elsif ($type =~ m/^(\w+)\*$/) {
3466 $type_output = &MakeXRef ($1, &tagify($1, "type")) . "*";
3468 $type_output = &MakeXRef ($type, &tagify($type, "type"));
3471 if ($flags =~ m/r/) {
3472 $flags_string = "Read";
3474 if ($flags =~ m/w/) {
3475 if ($flags_string) { $flags_string .= " / "; }
3476 $flags_string .= "Write";
3478 if ($flags =~ m/x/) {
3479 if ($flags_string) { $flags_string .= " / "; }
3480 $flags_string .= "Construct";
3482 if ($flags =~ m/X/) {
3483 if ($flags_string) { $flags_string .= " / "; }
3484 $flags_string .= "Construct Only";
3487 $AllSymbols{$symbol} = 1;
3489 if (defined($SymbolDocs{$symbol}) &&
3490 !IsEmptyDoc($SymbolDocs{$symbol})) {
3491 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3492 #print ".. [$SymbolDocs{$symbol}][$blurb]\n";
3493 $AllDocumentedSymbols{$symbol} = 1;
3496 if (!($ArgBlurbs[$i] eq "")) {
3497 $AllDocumentedSymbols{$symbol} = 1;
3499 # FIXME: print a warning?
3500 #print ".. no description\n";
3502 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
3505 my $pad1 = " " x (24 - length ($name));
3506 my $pad2 = " " x (20 - length ($type));
3508 my $arg_synop = " "<link linkend=\"$id\">$name</link>"$pad1 $type_output $pad2 : $flags_string\n";
3509 my $arg_desc = "<refsect2 id=\"$id\" role=\"property\"><title>The <literal>"$name"</literal> $kind</title>\n";
3510 $arg_desc .= MakeIndexterms($symbol, $id);
3512 $arg_desc .= OutputSymbolExtraLinks($symbol);
3514 $arg_desc .= "<programlisting> "$name"$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
3515 $arg_desc .= &MakeDeprecationNote($symbol);
3516 $arg_desc .= $blurb;
3518 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
3520 if ($default ne "") {
3521 $arg_desc .= "<para>Default value: $default_output</para>\n";
3523 $arg_desc .= OutputSymbolTraits ($symbol);
3524 $arg_desc .= "</refsect2>\n";
3526 if ($flags =~ m/c/) {
3527 $child_synop .= $arg_synop;
3528 $child_desc .= $arg_desc;
3530 elsif ($flags =~ m/s/) {
3531 $style_synop .= $arg_synop;
3532 $style_desc .= $arg_desc;
3535 $synop .= $arg_synop;
3540 return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
3544 #############################################################################
3545 # Function : ReadSourceDocumentation
3546 # Description : This reads in the documentation embedded in comment blocks
3547 # in the source code (for Gnome).
3549 # Parameter descriptions override any in the template files.
3550 # Function descriptions are placed before any description from
3551 # the template files.
3553 # It recursively descends the source directory looking for .c
3554 # files and scans them looking for specially-formatted comment
3557 # Arguments : $source_dir - the directory to scan.
3558 #############m###############################################################
3560 sub ReadSourceDocumentation {
3561 my ($source_dir) = @_;
3562 my ($file, $dir, @suffix_list, $suffix);
3563 #print "Scanning source directory: $source_dir\n";
3565 # This array holds any subdirectories found.
3568 @suffix_list = split (/,/, $SOURCE_SUFFIXES);
3570 opendir (SRCDIR, $source_dir)
3571 || die "Can't open source directory $source_dir: $!";
3573 foreach $file (readdir (SRCDIR)) {
3574 if ($file =~ /^\./) {
3576 } elsif (-d "$source_dir/$file") {
3577 push (@subdirs, $file);
3578 } elsif (@suffix_list) {
3579 foreach $suffix (@suffix_list) {
3580 if ($file =~ m/\.\Q${suffix}\E$/) {
3581 &ScanSourceFile ("$source_dir/$file");
3584 } elsif ($file =~ m/\.[ch]$/) {
3585 &ScanSourceFile ("$source_dir/$file");
3590 # Now recursively scan the subdirectories.
3591 foreach $dir (@subdirs) {
3592 next if ($IGNORE_FILES =~ m/(\s|^)\Q${dir}\E(\s|$)/);
3593 &ReadSourceDocumentation ("$source_dir/$dir");
3598 #############################################################################
3599 # Function : ScanSourceFile
3600 # Description : Scans one source file looking for specially-formatted comment
3601 # blocks. Later &MergeSourceDocumentation is used to merge any
3602 # documentation found with the documentation already read in
3603 # from the template files.
3605 # Arguments : $file - the file to scan.
3606 #############################################################################
3608 sub ScanSourceFile {
3612 if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
3615 &LogWarning ($file, 1, "Can't find basename for this filename.");
3619 # Check if the basename is in the list of files to ignore.
3620 if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
3624 #print "DEBUG: Scanning $file\n";
3626 open (SRCFILE, $file)
3627 || die "Can't open $file: $!";
3628 my $in_comment_block = 0;
3630 my ($in_description, $in_return, $in_since, $in_stability, $in_deprecated);
3631 my ($description, $return_desc, $return_start, $return_style);
3632 my ($since_desc, $stability_desc, $deprecated_desc);
3634 my $ignore_broken_returns;
3637 # Look for the start of a comment block.
3638 if (!$in_comment_block) {
3639 if (m%^\s*/\*.*\*/%) {
3640 #one-line comment - not gtkdoc
3641 } elsif (m%^\s*/\*\*\s%) {
3642 #print "Found comment block start\n";
3644 $in_comment_block = 1;
3646 # Reset all the symbol data.
3648 $in_description = 0;
3657 $deprecated_desc = "";
3658 $stability_desc = "";
3659 $current_param = -1;
3660 $ignore_broken_returns = 0;
3666 # We're in a comment block. Check if we've found the end of it.
3669 # maybe its not even meant to be a gtk-doc comment?
3670 &LogWarning ($file, $., "Symbol name not found at the start of the comment block.");
3672 # Add the return value description onto the end of the params.
3674 push (@params, "Returns");
3675 push (@params, $return_desc);
3676 if ($return_style eq 'broken') {
3677 &LogWarning ($file, $., "Free-form return value description in $symbol. Use `Returns:' to avoid ambiguities.");
3680 # Convert special SGML characters
3681 $description = &ConvertSGMLChars ($symbol, $description);
3683 for ($k = 1; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3684 $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
3687 # Handle Section docs
3688 if ($symbol =~ m/SECTION:\s*(.*)/) {
3692 if (scalar %KnownSymbols) {
3693 if ((! defined($KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"})) || $KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"} != 1) {
3694 &LogWarning ($file, $., "Section $real_symbol is not defined in the $MODULE-section.txt file.");
3698 #print "SECTION DOCS found in source for : '$real_symbol'\n";
3699 $ignore_broken_returns = 1;
3700 for ($k = 0; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3701 #print " '".$params[$k]."'\n";
3702 $params[$k] = "\L$params[$k]";
3704 if ($params[$k] eq "short_description") {
3705 $key = "$TMPL_DIR/$real_symbol:Short_Description";
3706 } elsif ($params[$k] eq "see_also") {
3707 $key = "$TMPL_DIR/$real_symbol:See_Also";
3708 } elsif ($params[$k] eq "title") {
3709 $key = "$TMPL_DIR/$real_symbol:Title";
3710 } elsif ($params[$k] eq "stability") {
3711 $key = "$TMPL_DIR/$real_symbol:Stability_Level";
3712 } elsif ($params[$k] eq "section_id") {
3713 $key = "$TMPL_DIR/$real_symbol:Section_Id";
3714 } elsif ($params[$k] eq "include") {
3715 $key = "$TMPL_DIR/$real_symbol:Include";
3716 } elsif ($params[$k] eq "image") {
3717 $key = "$TMPL_DIR/$real_symbol:Image";
3719 if (defined($key)) {
3720 $SourceSymbolDocs{$key}=$params[$k+1];
3721 $SourceSymbolSourceFile{$key} = $file;
3722 $SourceSymbolSourceLine{$key} = $.;
3725 $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
3726 $SourceSymbolSourceFile{"$TMPL_DIR/$real_symbol:Long_Description"} = $file;
3727 $SourceSymbolSourceLine{"$TMPL_DIR/$real_symbol:Long_Description"} = $.;
3728 #$SourceSymbolTypes{$symbol} = "SECTION";
3730 #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
3731 $SourceSymbolDocs{$symbol} = $description;
3732 $SourceSymbolParams{$symbol} = [ @params ];
3733 # FIXME $SourceSymbolTypes{$symbol} = "STRUCT,SIGNAL,ARG,FUNCTION,MACRO";
3734 #if (defined $DeclarationTypes{$symbol}) {
3735 # $SourceSymbolTypes{$symbol} = $DeclarationTypes{$symbol}
3737 $SourceSymbolSourceFile{$symbol} = $file;
3738 $SourceSymbolSourceLine{$symbol} = $.;
3742 ($since_desc, my @extra_lines) = split ("\n", $since_desc);
3743 $since_desc =~ s/^\s+//;
3744 $since_desc =~ s/\s+$//;
3745 #print "Since($symbol) : [$since_desc]\n";
3746 $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
3747 if(scalar @extra_lines) {
3748 &LogWarning ($file, $., "multi-line since docs found");
3752 if ($stability_desc) {
3753 $stability_desc = &ParseStabilityLevel($stability_desc, $file, $., "Stability level for $symbol");
3754 $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
3757 if ($deprecated_desc) {
3758 if (exists $Deprecated{$symbol}) {
3761 # don't warn for signals and properties
3762 #if ($symbol !~ m/::?(.*)/) {
3763 if (defined $DeclarationTypes{$symbol}) {
3764 &LogWarning ($file, $.,
3765 "$symbol is deprecated in the inline comments, but no deprecation guards were found around the declaration.".
3766 " (See the --deprecated-guards option for gtkdoc-scan.)");
3769 $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
3773 $in_comment_block = 0;
3777 # Get rid of ' * ' at start of every line in the comment block.
3779 # But make sure we don't get rid of the newline at the end.
3783 #print "DEBUG: scanning :$_";
3785 # If we haven't found the symbol name yet, look for it.
3787 if (m%^\s*(SECTION:\s*\S+)%) {
3789 #print "SECTION DOCS found in source for : '$symbol'\n";
3790 $ignore_broken_returns = 1;
3791 } elsif (m%^\s*([\w:-]*\w)\s*:?\s*(\([a-z ]+\)\s*)*$%) {
3793 #print "SYMBOL DOCS found in source for : '$symbol'\n";
3798 # If we're in the return value description, add it to the end.
3800 # If we find another valid returns line, we assume that the first
3801 # one was really part of the description.
3802 if (m/^\s*(returns:|return\s+value:)/i) {
3803 if ($return_style eq 'broken') {
3804 $description .= $return_start . $return_desc;
3807 if ($return_style eq 'sane') {
3808 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3810 $return_style = 'sane';
3811 $ignore_broken_returns = 1;
3813 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3814 $description .= $return_start . $return_desc;
3816 $return_style = 'broken';
3818 } elsif (m%^\s*since:%i) {
3822 } elsif (m%^\s*stability:%i) {
3823 $stability_desc = $';
3826 } elsif (m%^\s*deprecated:%i) {
3827 $deprecated_desc = $';
3837 if (m/^\s*(returns:|return\s+value:)/i) {
3838 if ($return_style eq 'broken') {
3839 $description .= $return_start . $return_desc;
3842 if ($return_style eq 'sane') {
3843 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3845 $return_style = 'sane';
3846 $ignore_broken_returns = 1;
3850 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3852 $return_style = 'broken';
3856 } elsif (m%^\s*deprecated:%i) {
3857 $deprecated_desc = $';
3860 } elsif (m%^\s*stability:%i) {
3861 $stability_desc = $';
3870 if ($in_stability) {
3871 if (m/^\s*(returns:|return\s+value:)/i) {
3872 if ($return_style eq 'broken') {
3873 $description .= $return_start . $return_desc;
3876 if ($return_style eq 'sane') {
3877 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3879 $return_style = 'sane';
3880 $ignore_broken_returns = 1;
3884 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3886 $return_style = 'broken';
3890 } elsif (m%^\s*deprecated:%i) {
3891 $deprecated_desc = $';
3894 } elsif (m%^\s*since:%i) {
3899 $stability_desc .= $_;
3904 if ($in_deprecated) {
3905 if (m/^\s*(returns:|return\s+value:)/i) {
3906 if ($return_style eq 'broken') {
3907 $description .= $return_start . $return_desc;
3910 if ($return_style eq 'sane') {
3911 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3913 $return_style = 'sane';
3914 $ignore_broken_returns = 1;
3918 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3920 $return_style = 'broken';
3924 } elsif (m%^\s*since:%i) {
3928 } elsif (m%^\s*stability:%i) {
3929 $stability_desc = $';
3933 $deprecated_desc .= $_;
3938 # If we're in the description part, check for the 'Returns:' line.
3939 # If that isn't found, add the text to the end.
3940 if ($in_description) {
3941 # Get rid of 'Description:'
3942 s%^\s*Description:%%;
3944 if (m/^\s*(returns:|return\s+value:)/i) {
3945 if ($return_style eq 'broken') {
3946 $description .= $return_start . $return_desc;
3949 if ($return_style eq 'sane') {
3950 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3952 $return_style = 'sane';
3953 $ignore_broken_returns = 1;
3957 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3959 $return_style = 'broken';
3963 } elsif (m%^\s*since:%i) {
3967 } elsif (m%^\s*deprecated:%i) {
3968 $deprecated_desc = $';
3971 } elsif (m%^\s*stability:%i) {
3972 $stability_desc = $';
3981 # We must be in the parameters. Check for the empty line below them.
3983 $in_description = 1;
3987 # Look for a parameter name.
3988 if (m%^\s*@(\S+)\s*:\s*%) {
3989 my $param_name = $1;
3990 my $param_desc = $';
3992 #print "Found parameter: $param_name\n";
3993 # Allow '...' as the Varargs parameter.
3994 if ($param_name eq "...") {
3995 $param_name = "Varargs";
3997 if ("\L$param_name" eq "returns") {
3998 $return_style = 'sane';
3999 $ignore_broken_returns = 1;
4001 push (@params, $param_name);
4002 push (@params, $param_desc);
4003 $current_param += $PARAM_FIELD_COUNT;
4007 # We must be in the middle of a parameter description, so add it on
4008 # to the last element in @params.
4009 if ($current_param == -1) {
4010 &LogWarning ($file, $., "Parsing comment block file : parameter expected.");
4012 $params[$#params] .= $_;
4018 #############################################################################
4019 # Function : OutputMissingDocumentation
4020 # Description : Outputs report of documentation coverage to a file
4023 #############################################################################
4025 sub OutputMissingDocumentation {
4026 my $old_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.txt";
4027 my $new_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.new";
4029 my $n_documented = 0;
4030 my $n_incomplete = 0;
4036 my $buffer_deprecated = "";
4037 my $buffer_descriptions = "";
4039 open(UNDOCUMENTED, ">$new_undocumented_file")
4040 || die "Can't create $new_undocumented_file";
4042 foreach $symbol (sort (keys (%AllSymbols))) {
4043 # FIXME: should we print LogWarnings for undocumented stuff?
4045 #my $ssfile = &GetSymbolSourceFile($symbol);
4046 #my $ssline = &GetSymbolSourceLine($symbol);
4047 #my $location = "defined at " . (defined($ssfile)?$ssfile:"?") . ":" . (defined($ssline)?$ssline:"0") . "\n";
4049 if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include|Section_Id|Image)/) {
4051 if (exists ($AllDocumentedSymbols{$symbol})) {
4053 if (exists ($AllIncompleteSymbols{$symbol})) {
4055 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4056 #$buffer .= "\t0: ".$location;
4058 } elsif (exists $Deprecated{$symbol}) {
4059 if (exists ($AllIncompleteSymbols{$symbol})) {
4061 $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4062 #$buffer .= "\t1a: ".$location;
4064 $buffer_deprecated .= $symbol . "\n";
4065 #$buffer .= "\t1b: ".$location;
4068 if (exists ($AllIncompleteSymbols{$symbol})) {
4070 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4071 #$buffer .= "\t2a: ".$location;
4073 $buffer .= $symbol . "\n";
4074 #$buffer .= "\t2b: ".$location;
4077 } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
4079 #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
4080 #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
4081 #print "%%%% $symbol : $len1,$len2\n";
4082 if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
4083 || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
4086 # cut off the leading namespace ($TMPL_DIR)
4087 $symbol =~ m/^.*\/(.*)$/;
4088 $buffer_descriptions .= $1 . "\n";
4093 $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
4098 $percent = ($n_documented / $total) * 100.0;
4101 printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
4102 print UNDOCUMENTED "$n_documented symbols documented.\n";
4103 print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
4104 print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
4106 print UNDOCUMENTED $buffer;
4107 close (UNDOCUMENTED);
4109 return &UpdateFileIfChanged ($old_undocumented_file, $new_undocumented_file, 0);
4111 printf "%.0f%% symbol docs coverage", $percent;
4112 print "($n_documented symbols documented, $n_incomplete symbols incomplete, " . ($total - $n_documented) . " not documented)\n";
4113 print "See $MODULE-undocumented.txt for a list of missing docs.\nThe doc coverage percentage doesn't include intro sections.\n";
4117 #############################################################################
4118 # Function : OutputUndeclaredSymbols
4119 # Description : Outputs symbols that are listed in the section file, but not
4120 # declaration is found in the sources
4123 #############################################################################
4125 sub OutputUndeclaredSymbols {
4126 my $old_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.txt";
4127 my $new_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.new";
4129 open(UNDECLARED, ">$new_undeclared_file")
4130 || die "Can't create $new_undeclared_file";
4132 if (%UndeclaredSymbols) {
4133 print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
4134 print UNDECLARED "\n";
4135 print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
4139 return &UpdateFileIfChanged ($old_undeclared_file, $new_undeclared_file, 0);
4142 #############################################################################
4143 # Function : OutputUnusedSymbols
4144 # Description : Outputs symbols that are documented in comments, but not
4145 # declared in the sources
4148 #############################################################################
4150 sub OutputUnusedSymbols {
4152 my $old_unused_file = "$ROOT_DIR/$MODULE-unused.txt";
4153 my $new_unused_file = "$ROOT_DIR/$MODULE-unused.new";
4155 open (UNUSED, ">$new_unused_file")
4156 || die "Can't open $new_unused_file";
4158 foreach $symbol (sort keys (%Declarations)) {
4159 if (!defined ($DeclarationOutput{$symbol})) {
4160 print (UNUSED "$symbol\n");
4164 foreach $symbol (sort (keys (%AllUnusedSymbols))) {
4165 print (UNUSED "$symbol(" . $AllUnusedSymbols{$symbol} . ")\n");
4169 if ($num_unused != 0) {
4170 &LogWarning ($old_unused_file, 1, "$num_unused unused declarations.".
4171 "They should be added to $MODULE-sections.txt in the appropriate place.");
4174 return &UpdateFileIfChanged ($old_unused_file, $new_unused_file, 0);
4178 #############################################################################
4179 # Function : OutputAllSymbols
4180 # Description : Outputs list of all symbols to a file
4183 #############################################################################
4185 sub OutputAllSymbols {
4186 my $n_documented = 0;
4192 open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
4193 || die "Can't create $ROOT_DIR/$MODULE-symbols.txt: $!";
4195 foreach $symbol (sort (keys (%AllSymbols))) {
4196 print SYMBOLS $symbol . "\n";
4202 #############################################################################
4203 # Function : OutputSymbolsWithoutSince
4204 # Description : Outputs list of all symbols without a since tag to a file
4207 #############################################################################
4209 sub OutputSymbolsWithoutSince {
4210 my $n_documented = 0;
4216 open (SYMBOLS, ">$ROOT_DIR/$MODULE-nosince.txt")
4217 || die "Can't create $ROOT_DIR/$MODULE-nosince.txt: $!";
4219 foreach $symbol (sort (keys (%SourceSymbolDocs))) {
4220 if (!defined $Since{$symbol}) {
4221 print SYMBOLS $symbol . "\n";
4229 #############################################################################
4230 # Function : MergeSourceDocumentation
4231 # Description : This merges documentation read from a source file into the
4232 # documentation read in from a template file.
4234 # Parameter descriptions override any in the template files.
4235 # Function descriptions are placed before any description from
4236 # the template files.
4239 #############################################################################
4241 sub MergeSourceDocumentation {
4245 if (scalar %SymbolDocs) {
4246 @Symbols=keys (%SymbolDocs);
4247 #print "num existing entries: ".(scalar @Symbols)."\n";
4248 #print " ",$Symbols[0], " ",$Symbols[1],"\n";
4251 # filter scanned declarations, with what we suppress from -sections.txt
4253 foreach $symbol (keys (%Declarations)) {
4254 if (defined($KnownSymbols{$symbol}) && $KnownSymbols{$symbol} == 1) {
4258 # , add the rest from -sections.txt
4259 foreach $symbol (keys (%KnownSymbols)) {
4260 if ($KnownSymbols{$symbol} == 1) {
4264 # and add whats found in the source
4265 foreach $symbol (keys (%SourceSymbolDocs)) {
4268 @Symbols = keys (%tmp);
4269 #print "num source entries: ".(scalar @Symbols)."\n";
4271 foreach $symbol (@Symbols) {
4272 $AllSymbols{$symbol} = 1;
4274 my $have_tmpl_docs = 0;
4276 ## See if the symbol is documented in template
4277 my $tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4278 my $check_tmpl_doc =$tmpl_doc;
4279 # remove all xml-tags and whitespaces
4280 #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
4281 $check_tmpl_doc =~ s/<.*?>//g;
4282 $check_tmpl_doc =~ s/\s//g;
4284 if ($check_tmpl_doc ne "") {
4285 $have_tmpl_docs = 1;
4286 #print "## [$check_tmpl_doc]\n";
4291 if (exists ($SourceSymbolDocs{$symbol})) {
4292 my $type = $DeclarationTypes {$symbol};
4294 #print "merging [$symbol] from source\n";
4296 my $item = "Parameter";
4297 if (defined ($type)) {
4298 if ($type eq 'STRUCT') {
4300 } elsif ($type eq 'ENUM') {
4302 } elsif ($type eq 'UNION') {
4309 my $src_doc = $SourceSymbolDocs{$symbol};
4310 # remove leading and training whitespaces
4311 $src_doc =~ s/^\s+//;
4312 $src_doc =~ s/\s+$//;
4314 # Don't output warnings for overridden titles as titles are
4315 # automatically generated in the -sections.txt file, and thus they
4316 # are often overridden.
4317 if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
4318 # check if content is different
4319 if ($tmpl_doc ne $src_doc) {
4320 #print "[$tmpl_doc] [$src_doc]\n";
4321 &LogWarning ($SourceSymbolSourceFile{$symbol}, $SourceSymbolSourceLine{$symbol},
4322 "Documentation in template ".$SymbolSourceFile{$symbol}.":".$SymbolSourceLine{$symbol}." for $symbol being overridden by inline comments.");
4326 if ($src_doc ne "") {
4327 $AllDocumentedSymbols{$symbol} = 1;
4330 # Convert <!--PARAMETERS--> with any blank lines around it to
4331 # a </para> followed by <!--PARAMETERS--> followed by <para>.
4332 $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
4334 # Do not add <para> to nothing, it breaks missing docs checks.
4335 my $src_doc_para = "";
4336 if ($src_doc ne "") {
4337 # If there is a blank line, finish the paragraph and start another.
4338 $src_doc = &ConvertBlankLines ($src_doc, $symbol);
4339 $src_doc_para = "<para>\n$src_doc\n</para>";
4341 $src_doc_para =~ s%<para>\n<refsect2%<refsect2%gms;
4342 $src_doc_para =~ s%</refsect2>\n</para>%</refsect2>%gms;
4343 #print "$symbol : [$src_doc][$src_doc_para]\n";
4346 if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
4347 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4348 } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
4349 # For the title/summary/see also section docs we don't want to
4350 # add any <para> tags.
4351 $SymbolDocs{$symbol} = "$src_doc"
4353 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4357 if ($symbol =~ m/.*::.*/) {
4358 # For signals we prefer the param names from the source docs,
4359 # since the ones from the templates are likely to contain the
4360 # artificial argn names which are generated by gtkdoc-scangobj.
4361 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4362 # FIXME: we need to check for empty docs here as well!
4364 # The templates contain the definitive parameter names and order,
4365 # so we will not change that. We only override the actual text.
4366 my $tmpl_params = $SymbolParams{$symbol};
4367 if (!defined ($tmpl_params)) {
4368 #print "No merge needed for $symbol\n";
4369 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4370 # FIXME: we still like to get the number of params and merge
4371 # 1) we would noticed that params have been removed/renamed
4372 # 2) we would catch undocumented params
4373 # params are not (yet) exported in -decl.txt so that we
4374 # could easily grab them :/
4376 my $params = $SourceSymbolParams{$symbol};
4378 #print "Merge needed for $symbol, tmpl_params: ",$#$tmpl_params,", source_params: ",$#$params," \n";
4379 for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4380 my $tmpl_param_name = $$tmpl_params[$j];
4382 # Allow '...' as the Varargs parameter.
4383 if ($tmpl_param_name eq "...") {
4384 $tmpl_param_name = "Varargs";
4387 # Try to find the param in the source comment documentation.
4390 #print " try merge param $tmpl_param_name\n";
4391 for ($k = 0; $k <= $#$params; $k += $PARAM_FIELD_COUNT) {
4392 my $param_name = $$params[$k];
4393 my $param_desc = $$params[$k + 1];
4395 #print " test param $param_name\n";
4396 # We accept changes in case, since the Gnome source
4397 # docs contain a lot of these.
4398 if ("\L$param_name" eq "\L$tmpl_param_name") {
4401 # Override the description.
4402 $$tmpl_params[$j + 1] = $param_desc;
4404 # Set the name to "" to mark it as used.
4410 # If it looks like the parameters are there, but not
4411 # in the right place, try to explain a bit better.
4412 if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
4413 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4414 "Parameters for $symbol must start on the line immediately after the function or macro name.");
4418 # Now we output a warning if parameters have been described which
4420 for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
4421 my $param_name = $$params[$j];
4423 # the template builder cannot detect if a macro returns
4425 if(($type eq "MACRO") && ($param_name eq "Returns")) {
4426 # FIXME: do we need to add it then to tmpl_params[] ?
4427 my $num=$#$tmpl_params;
4428 #print " adding Returns: to macro docs for $symbol.\n";
4429 $$tmpl_params[$num+1]="Returns";
4430 $$tmpl_params[$num+2]=$$params[$j+1];
4433 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4434 "$item described in source code comment block but does not exist. $type: $symbol $item: $param_name.");
4440 if ($have_tmpl_docs) {
4441 $AllDocumentedSymbols{$symbol} = 1;
4442 #print "merging [$symbol] from template\n";
4445 #print "[$symbol] undocumented\n";
4449 # if this symbol is documented, check if docs are complete
4450 $check_tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4451 # remove all xml-tags and whitespaces
4452 #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
4453 $check_tmpl_doc =~ s/<.*?>//g;
4454 $check_tmpl_doc =~ s/\s//g;
4455 if ($check_tmpl_doc ne "") {
4456 my $tmpl_params = $SymbolParams{$symbol};
4457 if (defined ($tmpl_params)) {
4458 my $type = $DeclarationTypes {$symbol};
4460 my $item = "Parameter";
4461 if (defined ($type)) {
4462 if ($type eq 'STRUCT') {
4464 } elsif ($type eq 'ENUM') {
4466 } elsif ($type eq 'UNION') {
4473 #print "Check param docs for $symbol, tmpl_params: ",$#$tmpl_params," entries, type=$type\n";
4475 if ($#$tmpl_params > 0) {
4477 for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4478 # Output a warning if the parameter is empty and
4479 # remember for stats.
4480 my $tmpl_param_name = $$tmpl_params[$j];
4481 my $tmpl_param_desc = $$tmpl_params[$j + 1];
4482 if ($tmpl_param_name ne "void" && $tmpl_param_desc !~ m/\S/) {
4483 if (exists ($AllIncompleteSymbols{$symbol})) {
4484 $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
4486 $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
4488 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4489 "$item description for $symbol"."::"."$tmpl_param_name is missing in source code comment block.");
4494 if ($#$tmpl_params == 0) {
4495 $AllIncompleteSymbols{$symbol}="<items>";
4496 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4497 "$item descriptions for $symbol are missing in source code comment block.");
4499 # $#$tmpl_params==-1 means we don't know about parameters
4500 # this unfortunately does not tell if there should be some
4505 #print "num doc entries: ".(scalar %SymbolDocs)."\n";
4508 #############################################################################
4509 # Function : IsEmptyDoc
4510 # Description : Check if a doc-string is empty. Its also regarded as empty if
4511 # it only consist of whitespace or e.g. FIXME.
4512 # Arguments : the doc-string
4513 #############################################################################
4517 if ($doc =~ /^\s*$/) {
4521 if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
4529 # This converts blank lines to "</para><para>", but only outside CDATA and
4530 # <programlisting> tags.
4531 sub ConvertBlankLines {
4532 return &ModifyXMLElements ($_[0], $_[1],
4533 "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
4534 \&ConvertBlankLinesEndTag,
4535 \&ConvertBlankLinesCallback);
4539 sub ConvertBlankLinesEndTag {
4540 if ($_[0] eq "<!\[CDATA\[") {
4542 } elsif ($_[0] eq "|[") {
4545 return "</programlisting>";
4549 sub ConvertBlankLinesCallback {
4550 my ($text, $symbol, $tag) = @_;
4552 # If we're not in CDATA or a <programlisting> we convert blank lines so
4553 # they start a new <para>.
4555 $text =~ s%\n{2,}%\n</para>\n<para>\n%g;
4562 #############################################################################
4563 # LIBRARY FUNCTIONS - These functions are used in both gtkdoc-mkdb and
4564 # gtkdoc-mktmpl and should eventually be moved to a
4566 #############################################################################
4568 #############################################################################
4569 # Function : ReadDeclarationsFile
4570 # Description : This reads in a file containing the function/macro/enum etc.
4573 # Note that in some cases there are several declarations with
4574 # the same name, e.g. for conditional macros. In this case we
4575 # set a flag in the %DeclarationConditional hash so the
4576 # declaration is not shown in the docs.
4578 # If a macro and a function have the same name, e.g. for
4579 # gtk_object_ref, the function declaration takes precedence.
4581 # Some opaque structs are just declared with 'typedef struct
4582 # _name name;' in which case the declaration may be empty.
4583 # The structure may have been found later in the header, so
4584 # that overrides the empty declaration.
4586 # Arguments : $file - the declarations file to read
4587 # $override - if declarations in this file should override
4588 # any current declaration.
4589 #############################################################################
4591 sub ReadDeclarationsFile {
4592 my ($file, $override) = @_;
4594 if ($override == 0) {
4596 %DeclarationTypes = ();
4597 %DeclarationConditional = ();
4598 %DeclarationOutput = ();
4602 || die "Can't open $file: $!";
4603 my $declaration_type = "";
4604 my $declaration_name;
4606 my $is_deprecated = 0;
4608 if (!$declaration_type) {
4609 if (m/^<([^>]+)>/) {
4610 $declaration_type = $1;
4611 $declaration_name = "";
4612 #print "Found declaration: $declaration_type\n";
4616 if (m%^<NAME>(.*)</NAME>%) {
4617 $declaration_name = $1;
4618 } elsif (m%^<DEPRECATED/>%) {
4620 } elsif (m%^</$declaration_type>%) {
4621 #print "Found end of declaration: $declaration_name\n";
4622 # Check that the declaration has a name
4623 if ($declaration_name eq "") {
4624 print "ERROR: $declaration_type has no name $file:$.\n";
4627 # If the declaration is an empty typedef struct _XXX XXX
4628 # set the flag to indicate the struct has a typedef.
4629 if ($declaration_type eq 'STRUCT'
4630 && $declaration =~ m/^\s*$/) {
4631 #print "Struct has typedef: $declaration_name\n";
4632 $StructHasTypedef{$declaration_name} = 1;
4635 # Check if the symbol is already defined.
4636 if (defined ($Declarations{$declaration_name})
4637 && $override == 0) {
4638 # Function declarations take precedence.
4639 if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
4641 } elsif ($declaration_type eq 'FUNCTION') {
4642 if ($is_deprecated) {
4643 $Deprecated{$declaration_name} = "";
4645 $Declarations{$declaration_name} = $declaration;
4646 $DeclarationTypes{$declaration_name} = $declaration_type;
4647 } elsif ($DeclarationTypes{$declaration_name}
4648 eq $declaration_type) {
4649 # If the existing declaration is empty, or is just a
4650 # forward declaration of a struct, override it.
4651 if ($declaration_type eq 'STRUCT') {
4652 if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4653 if ($is_deprecated) {
4654 $Deprecated{$declaration_name} = "";
4656 $Declarations{$declaration_name} = $declaration;
4657 } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4658 # Ignore an empty or forward declaration.
4660 &LogWarning ($file, $., "Structure $declaration_name has multiple definitions.");
4663 # set flag in %DeclarationConditional hash for
4664 # multiply defined macros/typedefs.
4665 $DeclarationConditional{$declaration_name} = 1;
4668 &LogWarning ($file, $., "$declaration_name has multiple definitions.");
4671 if ($is_deprecated) {
4672 $Deprecated{$declaration_name} = "";
4674 $Declarations{$declaration_name} = $declaration;
4675 $DeclarationTypes{$declaration_name} = $declaration_type;
4678 $declaration_type = "";
4689 #############################################################################
4690 # Function : ReadSignalsFile
4691 # Description : This reads in an existing file which contains information on
4692 # all GTK signals. It creates the arrays @SignalNames and
4693 # @SignalPrototypes containing info on the signals. The first
4694 # line of the SignalPrototype is the return type of the signal
4695 # handler. The remaining lines are the parameters passed to it.
4696 # The last parameter, "gpointer user_data" is always the same
4697 # so is not included.
4698 # Arguments : $file - the file containing the signal handler prototype
4700 #############################################################################
4702 sub ReadSignalsFile {
4710 my $signal_prototype;
4712 # Reset the signal info.
4713 @SignalObjects = ();
4715 @SignalReturns = ();
4717 @SignalPrototypes = ();
4722 if (!open (INPUT, $file)) {
4723 warn "Can't open $file - skipping signals\n";
4730 $signal_object = "";
4732 $signal_returns = "";
4733 $signal_prototype = "";
4736 if (m/^<NAME>(.*)<\/NAME>/) {
4738 if ($signal_name =~ m/^(.*)::(.*)$/) {
4739 $signal_object = $1;
4740 ($signal_name = $2) =~ s/_/-/g;
4741 #print "Found signal: $signal_name\n";
4743 &LogWarning ($file, $., "Invalid signal name: $signal_name.");
4745 } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
4746 $signal_returns = $1;
4747 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4749 } elsif (m%^</SIGNAL>%) {
4750 #print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
4751 push (@SignalObjects, $signal_object);
4752 push (@SignalNames, $signal_name);
4753 push (@SignalReturns, $signal_returns);
4754 push (@SignalFlags, $signal_flags);
4755 push (@SignalPrototypes, $signal_prototype);
4758 $signal_prototype .= $_;
4766 #############################################################################
4767 # Function : ReadTemplateFile
4768 # Description : This reads in the manually-edited documentation file
4769 # corresponding to the file currently being created, so we can
4770 # insert the documentation at the appropriate places.
4771 # It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
4772 # is a hash of arrays.
4773 # NOTE: This function is duplicated in gtkdoc-mktmpl (but
4774 # slightly different).
4775 # Arguments : $docsfile - the template file to read in.
4776 # $skip_unused_params - 1 if the unused parameters should be
4778 #############################################################################
4780 sub ReadTemplateFile {
4781 my ($docsfile, $skip_unused_params) = @_;
4783 my $template = "$docsfile.sgml";
4784 if (! -f $template) {
4785 #print "File doesn't exist: $template\n";
4788 #print "Reading $template\n";
4790 # start with empty hashes, we merge the source comment for each file
4796 my $current_type = ""; # Type of symbol being read.
4797 my $current_symbol = ""; # Name of symbol being read.
4798 my $symbol_doc = ""; # Description of symbol being read.
4799 my @params; # Parameter names and descriptions of current
4800 # function/macro/function typedef.
4801 my $current_param = -1; # Index of parameter currently being read.
4802 # Note that the param array contains pairs
4803 # of param name & description.
4804 my $in_unused_params = 0; # True if we are reading in the unused params.
4805 my $in_deprecated = 0;
4807 my $in_stability = 0;
4809 open (DOCS, "$template")
4810 || die "Can't open $template: $!";
4812 if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
4815 if ($symbol eq "Title"
4816 || $symbol eq "Short_Description"
4817 || $symbol eq "Long_Description"
4818 || $symbol eq "See_Also"
4819 || $symbol eq "Stability_Level"
4820 || $symbol eq "Include"
4821 || $symbol eq "Image") {
4823 $symbol = $docsfile . ":" . $symbol;
4826 #print "Found symbol: $symbol\n";
4827 # Remember file and line for the symbol
4828 $SymbolSourceFile{$symbol} = $template;
4829 $SymbolSourceLine{$symbol} = $.;
4831 # Store previous symbol, but remove any trailing blank lines.
4832 if ($current_symbol ne "") {
4833 $symbol_doc =~ s/\s+$//;
4834 $SymbolTypes{$current_symbol} = $current_type;
4835 $SymbolDocs{$current_symbol} = $symbol_doc;
4837 # Check that the stability level is valid.
4838 if ($StabilityLevel{$current_symbol}) {
4839 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4842 if ($current_param >= 0) {
4843 $SymbolParams{$current_symbol} = [ @params ];
4845 # Delete any existing params in case we are overriding a
4846 # previously read template.
4847 delete $SymbolParams{$current_symbol};
4850 $current_type = $type;
4851 $current_symbol = $symbol;
4852 $current_param = -1;
4853 $in_unused_params = 0;
4860 } elsif (m/^<!-- # Unused Parameters # -->/) {
4861 #print "DEBUG: Found unused parameters\n";
4862 $in_unused_params = 1;
4865 } elsif ($in_unused_params && $skip_unused_params) {
4866 # When outputting the DocBook we skip unused parameters.
4867 #print "DEBUG: Skipping unused param: $_";
4871 # Check if param found. Need to handle "..." and "format...".
4872 if (s/^\@([\w\.]+):\040?//) {
4873 my $param_name = $1;
4874 my $param_desc = $_;
4875 # Allow variations of 'Returns'
4876 if ($param_name =~ m/^[Rr]eturns?$/) {
4877 $param_name = "Returns";
4880 # strip trailing whitespaces and blank lines
4883 #print "Found param for symbol $current_symbol : '$param_name'= '$_'";
4885 if ($param_name eq "Deprecated") {
4887 $Deprecated{$current_symbol} = $_;
4888 } elsif ($param_name eq "Since") {
4891 $Since{$current_symbol} = $_;
4892 } elsif ($param_name eq "Stability") {
4894 $StabilityLevel{$current_symbol} = $_;
4896 push (@params, $param_name);
4897 push (@params, $param_desc);
4898 $current_param += $PARAM_FIELD_COUNT;
4901 # strip trailing whitespaces and blank lines
4906 if ($in_deprecated) {
4907 $Deprecated{$current_symbol} .= $_;
4908 } elsif ($in_since) {
4909 &LogWarning ($template, $., "multi-line since docs found");
4910 #$Since{$current_symbol} .= $_;
4911 } elsif ($in_stability) {
4912 $StabilityLevel{$current_symbol} .= $_;
4913 } elsif ($current_param >= 0) {
4914 $params[$current_param] .= $_;
4923 # Remember to finish the current symbol doccs.
4924 if ($current_symbol ne "") {
4926 $symbol_doc =~ s/\s+$//;
4927 $SymbolTypes{$current_symbol} = $current_type;
4928 $SymbolDocs{$current_symbol} = $symbol_doc;
4930 # Check that the stability level is valid.
4931 if ($StabilityLevel{$current_symbol}) {
4932 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4935 if ($current_param >= 0) {
4936 $SymbolParams{$current_symbol} = [ @params ];
4938 # Delete any existing params in case we are overriding a
4939 # previously read template.
4940 delete $SymbolParams{$current_symbol};
4949 #############################################################################
4950 # Function : ReadObjectHierarchy
4951 # Description : This reads in the $MODULE-hierarchy.txt file containing all
4952 # the GtkObject subclasses described in this module (and their
4954 # It places them in the @Objects array, and places their level
4955 # in the object hierarchy in the @ObjectLevels array, at the
4956 # same index. GtkObject, the root object, has a level of 1.
4958 # FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
4959 # as it goes along, this should be split out into a separate
4963 #############################################################################
4965 sub ReadObjectHierarchy {
4969 if (! -f $OBJECT_TREE_FILE) {
4972 if (!open (INPUT, $OBJECT_TREE_FILE)) {
4973 warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
4977 # FIXME: use $OUTPUT_FORMAT
4978 # my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.$OUTPUT_FORMAT";
4979 my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
4980 my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
4982 open (OUTPUT, ">$new_tree_index")
4983 || die "Can't create $new_tree_index: $!";
4985 if ($OUTPUT_FORMAT eq "xml") {
4986 my $tree_header = $doctype_header;
4988 $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
4989 print (OUTPUT "$tree_header");
4991 print (OUTPUT "<screen>\n");
4993 # Only emit objects if they are supposed to be documented, or if
4994 # they have documented children. To implement this, we maintain a
4995 # stack of pending objects which will be emitted if a documented
4997 my @pending_objects = ();
4998 my @pending_levels = ();
5002 my $level = (length($`)) / 2 + 1;
5005 while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
5006 my $pobject = pop(@pending_objects);
5007 my $plevel = pop(@pending_levels);
5010 push (@pending_objects, $object);
5011 push (@pending_levels, $level);
5013 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5014 while ($#pending_levels >= 0) {
5015 $object = shift @pending_objects;
5016 $level = shift @pending_levels;
5017 $xref = &MakeXRef ($object);
5019 print (OUTPUT ' ' x ($level * 4), "$xref\n");
5020 push (@Objects, $object);
5021 push (@ObjectLevels, $level);
5025 # LogWarning ($OBJECT_TREE_FILE, $., "unknown type $object");
5029 print (OUTPUT "</screen>\n");
5034 &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
5039 #############################################################################
5040 # Function : ReadInterfaces
5041 # Description : This reads in the $MODULE.interfaces file.
5044 #############################################################################
5046 sub ReadInterfaces {
5049 if (! -f $INTERFACES_FILE) {
5052 if (!open (INPUT, $INTERFACES_FILE)) {
5053 warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
5059 my ($object, @ifaces) = split;
5060 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5061 my @knownIfaces = ();
5063 # filter out private interfaces, but leave foreign interfaces
5064 foreach my $iface (@ifaces) {
5065 if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
5066 push (@knownIfaces, $iface);
5070 $Interfaces{$object} = join(' ', @knownIfaces);
5076 #############################################################################
5077 # Function : ReadPrerequisites
5078 # Description : This reads in the $MODULE.prerequisites file.
5081 #############################################################################
5083 sub ReadPrerequisites {
5084 %Prerequisites = ();
5086 if (! -f $PREREQUISITES_FILE) {
5089 if (!open (INPUT, $PREREQUISITES_FILE)) {
5090 warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
5096 my ($iface, @prereqs) = split;
5097 if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
5098 my @knownPrereqs = ();
5100 # filter out private prerequisites, but leave foreign prerequisites
5101 foreach my $prereq (@prereqs) {
5102 if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
5103 push (@knownPrereqs, $prereq);
5107 $Prerequisites{$iface} = join(' ', @knownPrereqs);
5113 #############################################################################
5114 # Function : ReadArgsFile
5115 # Description : This reads in an existing file which contains information on
5116 # all GTK args. It creates the arrays @ArgObjects, @ArgNames,
5117 # @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
5119 # Arguments : $file - the file containing the arg information.
5120 #############################################################################
5135 # Reset the args info.
5148 if (!open (INPUT, $file)) {
5149 warn "Can't open $file - skipping args\n";
5166 if (m/^<NAME>(.*)<\/NAME>/) {
5168 if ($arg_name =~ m/^(.*)::(.*)$/) {
5170 ($arg_name = $2) =~ s/_/-/g;
5171 #print "Found arg: $arg_name\n";
5173 &LogWarning ($file, $., "Invalid argument name: $arg_name");
5175 } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
5177 } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
5179 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
5181 } elsif (m/^<NICK>(.*)<\/NICK>/) {
5183 } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
5185 if ($arg_blurb eq "(null)") {
5187 &LogWarning ($file, $., "Property ${arg_object}:${arg_name} has no documentation.");
5189 } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
5191 } elsif (m%^</ARG>%) {
5192 #print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
5193 push (@ArgObjects, $arg_object);
5194 push (@ArgNames, $arg_name);
5195 push (@ArgTypes, $arg_type);
5196 push (@ArgRanges, $arg_range);
5197 push (@ArgFlags, $arg_flags);
5198 push (@ArgNicks, $arg_nick);
5199 push (@ArgBlurbs, $arg_blurb);
5200 push (@ArgDefaults, $arg_default);
5209 #############################################################################
5210 # Function : CheckIsObject
5211 # Description : Returns 1 if the given name is a GObject or a subclass.
5212 # It uses the global @Objects array.
5213 # Note that the @Objects array only contains classes in the
5214 # current module and their ancestors - not all GObject classes.
5215 # Arguments : $name - the name to check.
5216 #############################################################################
5222 foreach $object (@Objects) {
5223 if ($object eq $name) {
5231 #############################################################################
5232 # Function : MakeReturnField
5233 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
5234 # Arguments : $str - the string to pad.
5235 #############################################################################
5237 sub MakeReturnField {
5240 return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));
5243 #############################################################################
5244 # Function : GetSymbolSourceFile
5245 # Description : Get the filename where the symbol docs where taken from.
5246 # Arguments : $symbol - the symbol name
5247 #############################################################################
5249 sub GetSymbolSourceFile {
5252 if (defined($SourceSymbolSourceFile{$symbol})) {
5253 return $SourceSymbolSourceFile{$symbol};
5254 } elsif (defined($SymbolSourceFile{$symbol})) {
5255 return $SymbolSourceFile{$symbol};
5261 #############################################################################
5262 # Function : GetSymbolSourceLine
5263 # Description : Get the file line where the symbol docs where taken from.
5264 # Arguments : $symbol - the symbol name
5265 #############################################################################
5267 sub GetSymbolSourceLine {
5270 if (defined($SourceSymbolSourceLine{$symbol})) {
5271 return $SourceSymbolSourceLine{$symbol};
5272 } elsif (defined($SymbolSourceLine{$symbol})) {
5273 return $SymbolSourceLine{$symbol};