4 # gtk-doc - GTK DocBook documentation generator.
5 # Copyright (C) 1998 Damon Chaplin
6 # 2007,2008 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.
27 # NOTE: When creating SGML IDS, we append ":CAPS" to all
28 # all-caps identifiers to prevent name clashes. (It basically
29 # never is the case that mixed-case identifiers would collide.)
30 # See the CreateValidSGMLID function.
31 #############################################################################
36 push @INC, '@PACKAGE_DATA_DIR@';
37 require "gtkdoc-common.pl";
41 # name of documentation module
46 my $SOURCE_SUFFIXES = "";
47 my $IGNORE_FILES = "";
51 my $EXPAND_CONTENT_FILES = "";
53 my $DEFAULT_STABILITY;
57 my $OUTPUT_ALL_SYMBOLS;
58 my $OUTPUT_SYMBOLS_WITHOUT_SINCE;
60 my %optctl = ('module' => \$MODULE,
61 'source-dir' => \@SOURCE_DIRS,
62 'source-suffixes' => \$SOURCE_SUFFIXES,
63 'ignore-files' => \$IGNORE_FILES,
64 'output-dir' => \$SGML_OUTPUT_DIR,
65 'tmpl-dir' => \$TMPL_DIR,
66 'version' => \$PRINT_VERSION,
67 'help' => \$PRINT_HELP,
68 'main-sgml-file' => \$MAIN_SGML_FILE,
69 'expand-content-files' => \$EXPAND_CONTENT_FILES,
70 'sgml-mode' => \$SGML_MODE,
71 'default-stability' => \$DEFAULT_STABILITY,
72 'default-includes' => \$DEFAULT_INCLUDES,
73 'output-format' => \$OUTPUT_FORMAT,
74 'name-space' => \$NAME_SPACE,
75 'outputallsymbols' => \$OUTPUT_ALL_SYMBOLS,
76 'outputsymbolswithoutsince' => \$OUTPUT_SYMBOLS_WITHOUT_SINCE
78 GetOptions(\%optctl, "module=s", "source-dir:s", "source-suffixes:s",
79 "ignore-files:s", "output-dir:s", "tmpl-dir:s", "version", "outputallsymbols",
80 "outputsymbolswithoutsince",
81 "expand-content-files:s", "main-sgml-file:s", "extra-db-files:s", "help",
82 "sgml-mode", "default-stability:s", "default-includes:s", "output-format:s",
94 if ($DEFAULT_STABILITY && $DEFAULT_STABILITY ne "Stable"
95 && $DEFAULT_STABILITY ne "Private" && $DEFAULT_STABILITY ne "Unstable") {
101 gtkdoc-mkdb version @VERSION@ - generate docbook files
103 --module=MODULE_NAME Name of the doc module being parsed
104 --source-dir=DIRNAME Directories which contain inline reference material
105 --source-suffixes=SUFFIXES Suffixes of source files to scan, comma-separated
106 --ignore-files=FILES Files or directories which should not be scanned
107 May be used more than once for multiple directories
108 --output-dir=DIRNAME Directory to put the generated DocBook files in
109 --tmpl-dir=DIRNAME Directory in which template files may be found
110 --main-sgml-file=FILE File containing the toplevel DocBook file.
111 --expand-content-files=FILES Extra DocBook files to expand abbreviations in.
112 --output-format=FORMAT Format to use for the generated docbook, XML or SGML.
113 --sgml-mode Allow DocBook markup in inline documentation.
114 --default-stability=LEVEL Specify default stability Level. Valid values are
115 Stable, Unstable, or Private.
116 --default-includes=FILENAMES Specify default includes for section Synopsis
117 --name-space=NS Omit namespace in index.
118 --version Print the version of this program
119 --help Print this help
124 my ($empty_element_end, $doctype_header);
126 if (lc($OUTPUT_FORMAT) eq "xml") {
127 if (!$MAIN_SGML_FILE) {
128 # backwards compatibility
129 if (-e "${MODULE}-docs.sgml") {
130 $MAIN_SGML_FILE="${MODULE}-docs.sgml";
132 $MAIN_SGML_FILE="${MODULE}-docs.xml";
135 $OUTPUT_FORMAT = "xml";
136 $empty_element_end = "/>";
138 if (-e $MAIN_SGML_FILE) {
139 open(INPUT, "<$MAIN_SGML_FILE") || die "Can't open $MAIN_SGML_FILE";
140 $doctype_header = "";
142 if (/^\s*<(book|chapter|article)/) {
143 if ($_ !~ m/http:\/\/www.w3.org\/200[13]\/XInclude/) {
144 $doctype_header = "";
148 $doctype_header .= $_;
153 "<?xml version=\"1.0\"?>\n" .
154 "<!DOCTYPE book PUBLIC \"-//OASIS//DTD DocBook XML V4.3//EN\"\n" .
155 " \"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd\">\n";
157 $doctype_header =~ s/<!DOCTYPE \w+/<!DOCTYPE refentry/;
159 if (!$MAIN_SGML_FILE) {
160 $MAIN_SGML_FILE="${MODULE}-docs.sgml";
162 $OUTPUT_FORMAT = "sgml";
163 $doctype_header = "";
164 $empty_element_end = ">";
169 # All the files are written in subdirectories beneath here.
170 $TMPL_DIR = $TMPL_DIR ? $TMPL_DIR : "$ROOT_DIR/tmpl";
172 # This is where we put all the DocBook output.
173 $SGML_OUTPUT_DIR = $SGML_OUTPUT_DIR ? $SGML_OUTPUT_DIR : "$ROOT_DIR/$OUTPUT_FORMAT";
175 # This file contains the object hierarchy.
176 my $OBJECT_TREE_FILE = "$ROOT_DIR/$MODULE.hierarchy";
178 # This file contains the interfaces.
179 my $INTERFACES_FILE = "$ROOT_DIR/$MODULE.interfaces";
181 # This file contains the prerequisites.
182 my $PREREQUISITES_FILE = "$ROOT_DIR/$MODULE.prerequisites";
184 # This file contains signal arguments and names.
185 my $SIGNALS_FILE = "$ROOT_DIR/$MODULE.signals";
187 # The file containing Arg information.
188 my $ARGS_FILE = "$ROOT_DIR/$MODULE.args";
190 # These global arrays store information on signals. Each signal has an entry
191 # in each of these arrays at the same index, like a multi-dimensional array.
192 my @SignalObjects; # The GtkObject which emits the signal.
193 my @SignalNames; # The signal name.
194 my @SignalReturns; # The return type.
195 my @SignalFlags; # Flags for the signal
196 my @SignalPrototypes; # The rest of the prototype of the signal handler.
198 # These global arrays store information on Args. Each Arg has an entry
199 # in each of these arrays at the same index, like a multi-dimensional array.
200 my @ArgObjects; # The GtkObject which has the Arg.
201 my @ArgNames; # The Arg name.
202 my @ArgTypes; # The Arg type - gint, GtkArrowType etc.
203 my @ArgFlags; # How the Arg can be used - readable/writable etc.
204 my @ArgNicks; # The nickname of the Arg.
205 my @ArgBlurbs; # Docstring of the Arg.
206 my @ArgDefaults; # Default value of the Arg.
207 my @ArgRanges; # The range of the Arg type
208 # These global hashes store declaration info keyed on a symbol name.
210 my %DeclarationTypes;
211 my %DeclarationConditional;
212 my %DeclarationOutput;
216 my %StructHasTypedef;
218 # These global hashes store the existing documentation.
222 my %SymbolSourceFile;
223 my %SymbolSourceLine;
225 # These global hashes store documentation scanned from the source files.
226 my %SourceSymbolDocs;
227 my %SourceSymbolParams;
228 my %SourceSymbolSourceFile;
229 my %SourceSymbolSourceLine;
231 # all documentation goes in here, so we can do coverage analysis
233 my %AllIncompleteSymbols;
234 my %AllDocumentedSymbols;
236 # Undeclared yet documented symbols
237 my %UndeclaredSymbols;
239 # These global arrays store GObject, subclasses and the hierarchy.
246 # holds the symbols which are mentioned in $MODULE-sections.txt
249 # collects index entries
250 my %IndexEntriesFull;
251 my %IndexEntriesSince;
252 my %IndexEntriesDeprecated;
254 # Standard C preprocessor directives, which we ignore for '#' abbreviations.
255 my %PreProcessorDirectives;
256 $PreProcessorDirectives{"assert"} = 1;
257 $PreProcessorDirectives{"define"} = 1;
258 $PreProcessorDirectives{"elif"} = 1;
259 $PreProcessorDirectives{"else"} = 1;
260 $PreProcessorDirectives{"endif"} = 1;
261 $PreProcessorDirectives{"error"} = 1;
262 $PreProcessorDirectives{"if"} = 1;
263 $PreProcessorDirectives{"ifdef"} = 1;
264 $PreProcessorDirectives{"ifndef"} = 1;
265 $PreProcessorDirectives{"include"} = 1;
266 $PreProcessorDirectives{"line"} = 1;
267 $PreProcessorDirectives{"pragma"} = 1;
268 $PreProcessorDirectives{"unassert"} = 1;
269 $PreProcessorDirectives{"undef"} = 1;
270 $PreProcessorDirectives{"warning"} = 1;
272 # remember used annotation (to write minimal glossary)
275 my %AnnotationDefinition = (
276 'allow-none' => "NULL is ok, both for passing and for returning.",
277 'array' => "Parameter points to an array of items.",
278 'default' => "Default parameter value (for in case the <acronym>shadows</acronym>-to function has less parameters).",
279 'element-type' => "Generics and defining elements of containers and arrays.",
280 'error-domains' => "Typed errors. Similar to throws in Java.",
281 'in' => "Parameter for input. Default is <acronym>transfer none</acronym>.",
282 'inout' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
283 'in-out' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
284 'not-error' => "A GError parameter is not to be handled like a normal GError.",
285 'out' => "Parameter for returning results. Default is <acronym>transfer full</acronym>.",
286 'transfer container' => "Free data container after the code is done.",
287 'transfer full' => "Free data after the code is done.",
288 'transfer none' => "Don't free data after the code is done."
291 # Create the root DocBook output directory if it doens't exist.
292 if (! -e $SGML_OUTPUT_DIR) {
293 mkdir ("$SGML_OUTPUT_DIR", 0777)
294 || die "Can't create directory: $SGML_OUTPUT_DIR";
297 # Function and other declaration output settings.
298 my $RETURN_TYPE_FIELD_WIDTH = 20;
299 my $SYMBOL_FIELD_WIDTH = 36;
300 my $SIGNAL_FIELD_WIDTH = 16;
301 my $PARAM_FIELD_COUNT = 2;
303 &ReadKnownSymbols ("$ROOT_DIR/$MODULE-sections.txt");
304 &ReadSignalsFile ($SIGNALS_FILE);
305 &ReadArgsFile ($ARGS_FILE);
306 &ReadObjectHierarchy;
310 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-decl.txt", 0);
311 if (-f "$ROOT_DIR/$MODULE-overrides.txt") {
312 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-overrides.txt", 1);
315 for my $dir (@SOURCE_DIRS) {
316 &ReadSourceDocumentation ($dir);
319 my $changed = &OutputSGML ("$ROOT_DIR/$MODULE-sections.txt");
321 # If any of the DocBook SGML files have changed, update the timestamp file (so
322 # it can be used for Makefile dependencies).
323 if ($changed || ! -e "$ROOT_DIR/sgml.stamp") {
325 # try to detect the common prefix
326 # GtkWidget, GTK_WIDGET, gtk_widget -> gtk
327 if ($NAME_SPACE eq "") {
334 foreach my $symbol (keys(%IndexEntriesFull)) {
335 if(($NAME_SPACE eq "") || $symbol =~ /^$NAME_SPACE/i) {
336 if (length($symbol)>$pos) {
337 $letter=substr($symbol,$pos,1);
338 # stop prefix scanning
339 if ($letter eq "_") {
343 # Should we also stop on a uppercase char, if last was lowercase
344 # GtkWidget, if we have the 'W' and had the 't' before
345 # or should we count upper and lowercase, and stop one 2nd uppercase, if we already had a lowercase
346 # GtkWidget, the 'W' would be the 2nd uppercase and with 't','k' we had lowercase chars before
347 # need to recound each time as this is per symbol
348 $prefix{uc($letter)}++;
352 if ($letter ne "" && $letter ne "_") {
355 foreach $letter (keys(%prefix)) {
356 #print "$letter: $prefix{$letter}.\n";
357 if ($prefix{$letter}>$maxsymbols) {
359 $maxsymbols=$prefix{$letter};
362 $ratio = scalar(keys(%IndexEntriesFull)) / $prefix{$maxletter};
363 #print "most symbols start with $maxletter, that is ". (100 * $ratio) ." %\n";
366 $NAME_SPACE .= $maxletter;
373 } while ($ratio > 0.9);
374 #print "most symbols start with $NAME_SPACE\n";
378 &OutputDeprecatedIndex;
380 &OutputAnnotationGlossary;
382 open (TIMESTAMP, ">$ROOT_DIR/sgml.stamp")
383 || die "Can't create $ROOT_DIR/sgml.stamp: $!";
384 print (TIMESTAMP "timestamp");
388 #############################################################################
389 # Function : OutputObjectList
390 # Description : This outputs the alphabetical list of objects, in a columned
392 # FIXME: Currently this also outputs ancestor objects
393 # which may not actually be in this module.
395 #############################################################################
397 sub OutputObjectList {
400 # FIXME: use $OUTPUT_FORMAT
401 # my $old_object_index = "$SGML_OUTPUT_DIR/object_index.$OUTPUT_FORMAT";
402 my $old_object_index = "$SGML_OUTPUT_DIR/object_index.sgml";
403 my $new_object_index = "$SGML_OUTPUT_DIR/object_index.new";
405 open (OUTPUT, ">$new_object_index")
406 || die "Can't create $new_object_index: $!";
408 if (lc($OUTPUT_FORMAT) eq "xml") {
409 my $header = $doctype_header;
411 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE informaltable/;
412 print (OUTPUT "$header");
415 print (OUTPUT <<EOF);
416 <informaltable pgwide="1" frame="none">
417 <tgroup cols="$cols">
418 <colspec colwidth="1*"${empty_element_end}
419 <colspec colwidth="1*"${empty_element_end}
420 <colspec colwidth="1*"${empty_element_end}
426 foreach $object (sort (@Objects)) {
427 my $xref = &MakeXRef ($object);
428 if ($count % $cols == 0) { print (OUTPUT "<row>\n"); }
429 print (OUTPUT "<entry>$xref</entry>\n");
430 if ($count % $cols == ($cols - 1)) { print (OUTPUT "</row>\n"); }
434 # emit an empty row, since empty tables are invalid
435 print (OUTPUT "<row><entry> </entry></row>\n");
438 print (OUTPUT "</row>\n");
441 print (OUTPUT <<EOF);
442 </tbody></tgroup></informaltable>
446 &UpdateFileIfChanged ($old_object_index, $new_object_index, 0);
450 #############################################################################
451 # Function : OutputSGML
452 # Description : This collects the output for each section of the docs, and
453 # outputs each file when the end of the section is found.
454 # Arguments : $file - the $MODULE-sections.txt file which contains all of
455 # the functions/macros/structs etc. being documented, organised
456 # into sections and subsections.
457 #############################################################################
462 #print "Reading: $file\n";
464 || die "Can't open $file: $!";
467 my $book_bottom = "";
468 my $includes = (defined $DEFAULT_INCLUDES) ? $DEFAULT_INCLUDES : "";
469 my $section_includes = "";
477 my $signals_synop = "";
478 my $signals_desc = "";
480 my $child_args_synop = "";
481 my $style_args_synop = "";
483 my $child_args_desc = "";
484 my $style_args_desc = "";
487 my $implementations = "";
488 my $prerequisites = "";
490 my @file_objects = ();
494 # merge the source docs, in case there are no templates
495 &MergeSourceDocumentation;
501 } elsif (m/^<SECTION>/) {
509 } elsif (m/^<SUBSECTION\s*(.*)>/i) {
513 } elsif (m/^<SUBSECTION>/) {
515 } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
517 #print "Section: $title\n";
519 # We don't want warnings if object & class structs aren't used.
520 $DeclarationOutput{$title} = 1;
521 $DeclarationOutput{"${title}Class"} = 1;
522 $DeclarationOutput{"${title}Iface"} = 1;
523 $DeclarationOutput{"${title}Interface"} = 1;
525 } elsif (m/^<FILE>(.*)<\/FILE>/) {
527 if (! defined $templates{$filename}) {
528 if (&ReadTemplateFile ("$TMPL_DIR/$filename", 1)) {
529 &MergeSourceDocumentation;
530 $templates{$filename}=$.;
533 &LogWarning ($file, $., "Double <FILE>$filename</FILE> entry. ".
534 "Previous occurrence on line ".$templates{$filename}.".");
537 } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
539 $section_includes = $1;
541 if (defined $DEFAULT_INCLUDES) {
542 &LogWarning ($file, $., "Default <INCLUDE> being overridden by command line option.");
549 } elsif (m/^<\/SECTION>/) {
550 if($title eq "" && $filename eq "") {
551 &LogWarning ($file, $., "Section has no title and no file.");
553 # FIXME: one of those would be enough
557 if ($filename eq "") {
560 #print "End of section: $title\n";
562 $filename =~ s/\s/_/g;
564 my $section_id = $SourceSymbolDocs{"$TMPL_DIR/$filename:Section_Id"};
565 if (defined ($section_id) && $section_id !~ m/^\s*$/) {
566 # Do nothing. Use section_id as it is.
567 } elsif (&CheckIsObject ($title)) {
568 # GtkObjects use their class name as the ID.
569 $section_id = &CreateValidSGMLID ($title);
571 $section_id = &CreateValidSGMLID ("$MODULE-$title");
574 if ($num_symbols > 0) {
576 if (lc($OUTPUT_FORMAT) eq "xml") {
577 $book_bottom .= " <xi:include href=\"xml/$filename.xml\"/>\n";
579 $book_top.="<!ENTITY $section_id SYSTEM \"sgml/$filename.sgml\">\n";
580 $book_bottom .= " &$section_id;\n";
583 if (defined ($SourceSymbolDocs{"$TMPL_DIR/$filename:Include"})) {
584 if ($section_includes) {
585 &LogWarning ($file, $., "Section <INCLUDE> being overridden by inline comments.");
587 $section_includes = $SourceSymbolDocs{"$TMPL_DIR/$filename:Include"};
589 if ($section_includes eq "") {
590 $section_includes = $includes;
593 $signals_synop =~ s/^\n*//g;
594 $signals_synop =~ s/\n+$/\n/g;
595 if ($signals_synop ne '') {
596 $signals_synop = <<EOF;
597 <refsect1 id="$section_id.signals" role="signal_proto">
598 <title role="signal_proto.title">Signals</title>
600 ${signals_synop}</synopsis>
603 $signals_desc =~ s/^\n*//g;
604 $signals_desc =~ s/\n+$/\n/g;
605 $signals_desc =~ s/(\s|\n)+$//ms;
606 $signals_desc = <<EOF;
607 <refsect1 id="$section_id.signal-details" role="signals">
608 <title role="signals.title">Signal Details</title>
614 $args_synop =~ s/^\n*//g;
615 $args_synop =~ s/\n+$/\n/g;
616 if ($args_synop ne '') {
618 <refsect1 id="$section_id.properties" role="properties">
619 <title role="properties.title">Properties</title>
621 ${args_synop}</synopsis>
624 $args_desc =~ s/^\n*//g;
625 $args_desc =~ s/\n+$/\n/g;
626 $args_desc =~ s/(\s|\n)+$//ms;
628 <refsect1 id="$section_id.property-details" role="property_details">
629 <title role="property_details.title">Property Details</title>
635 $child_args_synop =~ s/^\n*//g;
636 $child_args_synop =~ s/\n+$/\n/g;
637 if ($child_args_synop ne '') {
638 $args_synop .= <<EOF;
639 <refsect1 id="$section_id.child-properties" role="child_properties">
640 <title role="child_properties.title">Child Properties</title>
642 ${child_args_synop}</synopsis>
645 $child_args_desc =~ s/^\n*//g;
646 $child_args_desc =~ s/\n+$/\n/g;
647 $child_args_desc =~ s/(\s|\n)+$//ms;
649 <refsect1 id="$section_id.child-property-details" role="child_property_details">
650 <title role="child_property_details.title">Child Property Details</title>
656 $style_args_synop =~ s/^\n*//g;
657 $style_args_synop =~ s/\n+$/\n/g;
658 if ($style_args_synop ne '') {
659 $args_synop .= <<EOF;
660 <refsect1 id="$section_id.style-properties" role="style_properties">
661 <title role="style_properties.title">Style Properties</title>
663 ${style_args_synop}</synopsis>
666 $style_args_desc =~ s/^\n*//g;
667 $style_args_desc =~ s/\n+$/\n/g;
668 $style_args_desc =~ s/(\s|\n)+$//ms;
670 <refsect1 id="$section_id.style-property-details" role="style_properties_details">
671 <title role="style_properties_details.title">Style Property Details</title>
677 $hierarchy =~ s/^\n*//g;
678 $hierarchy =~ s/\n+$/\n/g;
679 $hierarchy =~ s/(\s|\n)+$//ms;
680 if ($hierarchy ne "") {
682 <refsect1 id="$section_id.object-hierarchy" role="object_hierarchy">
683 <title role="object_hierarchy.title">Object Hierarchy</title>
689 $interfaces =~ s/^\n*//g;
690 $interfaces =~ s/\n+$/\n/g;
691 $interfaces =~ s/(\s|\n)+$//ms;
692 if ($interfaces ne "") {
694 <refsect1 id="$section_id.implemented-interfaces" role="impl_interfaces">
695 <title role="impl_interfaces.title">Implemented Interfaces</title>
701 $implementations =~ s/^\n*//g;
702 $implementations =~ s/\n+$/\n/g;
703 $implementations =~ s/(\s|\n)+$//ms;
704 if ($implementations ne "") {
705 $implementations = <<EOF;
706 <refsect1 id="$section_id.implementations" role="implementations">
707 <title role="implementations.title">Known Implementations</title>
713 $prerequisites =~ s/^\n*//g;
714 $prerequisites =~ s/\n+$/\n/g;
715 $prerequisites =~ s/(\s|\n)+$//ms;
716 if ($prerequisites ne "") {
717 $prerequisites = <<EOF;
718 <refsect1 id="$section_id.prerequisites" role="prerequisites">
719 <title role="prerequisites.title">Prerequisites</title>
725 $derived =~ s/^\n*//g;
726 $derived =~ s/\n+$/\n/g;
727 $derived =~ s/(\s|\n)+$//ms;
728 if ($derived ne "") {
730 <refsect1 id="$section_id.derived-interfaces" role="derived_interfaces">
731 <title role="derived_interfaces.title">Known Derived Interfaces</title>
737 $synopsis =~ s/^\n*//g;
738 $synopsis =~ s/\n+$/\n/g;
739 my $file_changed = &OutputSGMLFile ($filename, $title, $section_id,
741 \$synopsis, \$details,
742 \$signals_synop, \$signals_desc,
743 \$args_synop, \$args_desc,
744 \$hierarchy, \$interfaces,
746 \$prerequisites, \$derived,
755 $section_includes = "";
759 $child_args_synop = "";
760 $style_args_synop = "";
762 $child_args_desc = "";
763 $style_args_desc = "";
766 $implementations = "";
770 } elsif (m/^(\S+)/) {
772 #print " Symbol: $symbol\n";
774 # FIXME: check for duplicate entries
775 if (! defined $symbols{$symbol}) {
776 my $declaration = $Declarations{$symbol};
777 if (defined ($declaration)) {
778 # We don't want standard macros/functions of GtkObjects,
779 # or private declarations.
780 if ($subsection ne "Standard" && $subsection ne "Private") {
781 if (&CheckIsObject ($symbol)) {
782 push @file_objects, $symbol;
784 my ($synop, $desc) = &OutputDeclaration ($symbol,
786 my ($sig_synop, $sig_desc) = &GetSignals ($symbol);
787 my ($arg_synop, $child_arg_synop, $style_arg_synop,
788 $arg_desc, $child_arg_desc, $style_arg_desc) = &GetArgs ($symbol);
789 my $hier = &GetHierarchy ($symbol);
790 my $ifaces = &GetInterfaces ($symbol);
791 my $impls = &GetImplementations ($symbol);
792 my $prereqs = &GetPrerequisites ($symbol);
793 my $der = &GetDerived ($symbol);
796 $signals_synop .= $sig_synop;
797 $signals_desc .= $sig_desc;
798 $args_synop .= $arg_synop;
799 $child_args_synop .= $child_arg_synop;
800 $style_args_synop .= $style_arg_synop;
801 $args_desc .= $arg_desc;
802 $child_args_desc .= $child_arg_desc;
803 $style_args_desc .= $style_arg_desc;
805 $interfaces .= $ifaces;
806 $implementations .= $impls;
807 $prerequisites .= $prereqs;
811 # Note that the declaration has been output.
812 $DeclarationOutput{$symbol} = 1;
813 } elsif ($subsection ne "Standard" && $subsection ne "Private") {
814 $UndeclaredSymbols{$symbol} = 1;
815 &LogWarning ($file, $., "No declaration found for $symbol.");
818 $symbols{$symbol}=$.;
821 &LogWarning ($file, $., "Double symbol entry for $symbol. ".
822 "Previous occurrence on line ".$symbols{$symbol}.".");
828 &OutputMissingDocumentation;
829 &OutputUndeclaredSymbols;
831 if ($OUTPUT_ALL_SYMBOLS) {
834 if ($OUTPUT_SYMBOLS_WITHOUT_SINCE) {
835 &OutputSymbolsWithoutSince;
838 for $filename (split (' ', $EXPAND_CONTENT_FILES)) {
839 my $file_changed = &OutputExtraFile ($filename);
845 &OutputBook ($book_top, $book_bottom);
850 #############################################################################
851 # Function : OutputIndex
852 # Description : This writes an indexlist that can be included into the main-
853 # document into an <index> tag.
854 #############################################################################
857 my ($basename, $apiindexref ) = @_;
858 my %apiindex = %{$apiindexref};
859 my $old_index = "$SGML_OUTPUT_DIR/$basename.xml";
860 my $new_index = "$SGML_OUTPUT_DIR/$basename.new";
861 my $lastletter = " ";
866 open (OUTPUT, ">$new_index")
867 || die "Can't create $new_index";
869 my $header = $doctype_header;
870 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE indexdiv/;
872 print (OUTPUT "$header<indexdiv>\n");
874 #print "generate $basename index (".%apiindex." entries)\n";
876 # do a case insensitive sort while chopping off the prefix
878 sort { $$a{criteria} cmp $$b{criteria} }
879 map { my $x = uc($_); $x =~ s/^$NAME_SPACE\_?(.*)/$1/i; { criteria => $x, original => $_, short => $1 } }
882 $symbol = $$hash{original};
883 if(defined($$hash{short})) {
884 $short_symbol = $$hash{short};
886 $short_symbol = $symbol;
889 my $curletter = uc(substr($short_symbol,0,1));
890 my $id = $apiindex{$symbol};
892 #print " add symbol $symbol with $id to index in section $curletter\n";
894 if ($curletter ne $lastletter) {
895 $lastletter = $curletter;
898 print (OUTPUT "</indexdiv>\n");
900 print (OUTPUT "<indexdiv><title>$curletter</title>\n");
904 print (OUTPUT <<EOF);
905 <indexentry><primaryie linkends="$id"><link linkend="$id">$symbol</link></primaryie></indexentry>
910 print (OUTPUT "</indexdiv>\n");
912 print (OUTPUT "</indexdiv>\n");
915 &UpdateFileIfChanged ($old_index, $new_index, 0);
919 #############################################################################
920 # Function : OutputIndexFull
921 # Description : This writes the full api indexlist that can be included into the
922 # main document into an <index> tag.
923 #############################################################################
925 sub OutputIndexFull {
926 &OutputIndex ("api-index-full", \%IndexEntriesFull);
930 #############################################################################
931 # Function : OutputDeprecatedIndex
932 # Description : This writes the deprecated api indexlist that can be included
933 # into the main document into an <index> tag.
934 #############################################################################
936 sub OutputDeprecatedIndex {
937 &OutputIndex ("api-index-deprecated", \%IndexEntriesDeprecated);
941 #############################################################################
942 # Function : OutputSinceIndexes
943 # Description : This writes the 'since' api indexlists that can be included into
944 # the main document into an <index> tag.
945 #############################################################################
947 sub OutputSinceIndexes {
948 my @sinces = keys %{{ map { $_ => 1 } values %Since }};
950 foreach my $version (@sinces) {
951 #print "Since : [$version]\n";
952 # todo make filtered hash
953 #my %index = grep { $Since{$_} eq $version } %IndexEntriesSince;
954 my %index = map { $_ => $IndexEntriesSince{$_} } grep { $Since{$_} eq $version } keys %IndexEntriesSince;
956 &OutputIndex ("api-index-$version", \%index);
960 #############################################################################
961 # Function : OutputAnnotationGlossary
962 # Description : This writes a glossary of the used annotation terms into a
963 # separate glossary file that can be included into the main
965 #############################################################################
967 sub OutputAnnotationGlossary {
968 my $old_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.xml";
969 my $new_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.new";
970 my $lastletter = " ";
973 # if there are no annotations used return
974 return if (! keys(%AnnotationsUsed));
976 # add acronyms that are referenced from acronym text
978 foreach my $annotation (keys(%AnnotationsUsed)) {
979 if($AnnotationDefinition{$annotation} =~ m/<acronym>([\w ]+)<\/acronym>/) {
980 if (!exists($AnnotationsUsed{$1})) {
981 $AnnotationsUsed{$1} = 1;
987 open (OUTPUT, ">$new_glossary")
988 || die "Can't create $new_glossary";
990 my $header = $doctype_header;
991 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE glossary/;
993 print (OUTPUT <<EOF);
995 <glossary id="annotation-glossary">
996 <title>Annotation Glossary</title>
999 foreach my $annotation (keys(%AnnotationsUsed)) {
1000 my $def = $AnnotationDefinition{$annotation};
1001 my $curletter = uc(substr($annotation,0,1));
1003 if ($curletter ne $lastletter) {
1004 $lastletter = $curletter;
1006 if ($divopen == 1) {
1007 print (OUTPUT "</glossdiv>\n");
1009 print (OUTPUT "<glossdiv><title>$curletter</title>\n");
1012 print (OUTPUT <<EOF);
1014 <glossterm><anchor id="annotation-glossterm-$annotation"/>$annotation</glossterm>
1022 if ($divopen == 1) {
1023 print (OUTPUT "</glossdiv>\n");
1025 print (OUTPUT "</glossary>\n");
1028 &UpdateFileIfChanged ($old_glossary, $new_glossary, 0);
1031 #############################################################################
1032 # Function : ReadKnownSymbols
1033 # Description : This collects the names of non-private symbols from the
1034 # $MODULE-sections.txt file.
1035 # Arguments : $file - the $MODULE-sections.txt file which contains all of
1036 # the functions/macros/structs etc. being documented, organised
1037 # into sections and subsections.
1038 #############################################################################
1040 sub ReadKnownSymbols {
1043 my $subsection = "";
1045 #print "Reading: $file\n";
1047 || die "Can't open $file: $!";
1053 } elsif (m/^<SECTION>/) {
1056 } elsif (m/^<SUBSECTION\s*(.*)>/i) {
1059 } elsif (m/^<SUBSECTION>/) {
1062 } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
1065 } elsif (m/^<FILE>(.*)<\/FILE>/) {
1066 $KnownSymbols{"$TMPL_DIR/$1:Long_Description"} = 1;
1067 $KnownSymbols{"$TMPL_DIR/$1:Short_Description"} = 1;
1070 } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
1073 } elsif (m/^<\/SECTION>/) {
1076 } elsif (m/^(\S+)/) {
1079 if ($subsection ne "Standard" && $subsection ne "Private") {
1080 $KnownSymbols{$symbol} = 1;
1083 $KnownSymbols{$symbol} = 0;
1091 #############################################################################
1092 # Function : OutputDeclaration
1093 # Description : Returns the synopsis and detailed description DocBook
1094 # describing one function/macro etc.
1095 # Arguments : $symbol - the name of the function/macro begin described.
1096 # $declaration - the declaration of the function/macro.
1097 #############################################################################
1099 sub OutputDeclaration {
1100 my ($symbol, $declaration) = @_;
1102 my $type = $DeclarationTypes {$symbol};
1103 if ($type eq 'MACRO') {
1104 return &OutputMacro ($symbol, $declaration);
1105 } elsif ($type eq 'TYPEDEF') {
1106 return &OutputTypedef ($symbol, $declaration);
1107 } elsif ($type eq 'STRUCT') {
1108 return &OutputStruct ($symbol, $declaration);
1109 } elsif ($type eq 'ENUM') {
1110 return &OutputEnum ($symbol, $declaration);
1111 } elsif ($type eq 'UNION') {
1112 return &OutputUnion ($symbol, $declaration);
1113 } elsif ($type eq 'VARIABLE') {
1114 return &OutputVariable ($symbol, $declaration);
1116 } elsif ($type eq 'FUNCTION') {
1117 return &OutputFunction ($symbol, $declaration, $type);
1118 } elsif ($type eq 'USER_FUNCTION') {
1119 return &OutputFunction ($symbol, $declaration, $type);
1121 die "Unknown symbol type";
1126 #############################################################################
1127 # Function : OutputSymbolTraits
1128 # Description : Returns the Since and StabilityLevel paragraphs for a symbol.
1129 # Arguments : $symbol - the name of the function/macro begin described.
1130 #############################################################################
1132 sub OutputSymbolTraits {
1136 if (exists $Since{$symbol}) {
1137 $desc .= "<para role=\"since\">Since $Since{$symbol}</para>";
1139 if (exists $StabilityLevel{$symbol}) {
1140 $desc .= "<para role=\"stability\">Stability Level: $StabilityLevel{$symbol}</para>";
1145 #############################################################################
1146 # Function : Outpu{Symbol,Section}ExtraLinks
1147 # Description : Returns extralinks for the symbol (if enabled).
1148 # Arguments : $symbol - the name of the function/macro begin described.
1149 #############################################################################
1153 return undef unless defined $text;
1155 # Build a char to hex map
1158 $escapes{chr($_)} = sprintf("%%%02X", $_);
1161 # Default unsafe characters. RFC 2732 ^(uric - reserved)
1162 $text =~ s/([^A-Za-z0-9\-_.!~*'()])/$escapes{$1}/g;
1167 sub OutputSymbolExtraLinks {
1171 if (0) { # NEW FEATURE: needs configurability
1172 my $sstr = &uri_escape($symbol);
1173 my $mstr = &uri_escape($MODULE);
1175 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1176 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&symbol=$sstr">edit documentation</ulink>
1182 sub OutputSectionExtraLinks {
1183 my ($symbol,$docsymbol) = @_;
1186 if (0) { # NEW FEATURE: needs configurability
1187 my $sstr = &uri_escape($symbol);
1188 my $mstr = &uri_escape($MODULE);
1189 my $dsstr = &uri_escape($docsymbol);
1191 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1192 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&symbol=$dsstr">edit documentation</ulink>
1199 #############################################################################
1200 # Function : OutputMacro
1201 # Description : Returns the synopsis and detailed description of a macro.
1202 # Arguments : $symbol - the macro.
1203 # $declaration - the declaration of the macro.
1204 #############################################################################
1207 my ($symbol, $declaration) = @_;
1208 my $id = &CreateValidSGMLID ($symbol);
1209 my $condition = &MakeConditionDescription ($symbol);
1210 my $synop = &MakeReturnField("#define") . "<link linkend=\"$id\">$symbol</link>";
1216 if ($declaration =~ m/^\s*#\s*define(\s+)\w+(\([^\)]*\))/) {
1220 if (length ($symbol) < $SYMBOL_FIELD_WIDTH) {
1221 $synop .= (' ' x ($SYMBOL_FIELD_WIDTH - length ($symbol)));
1224 # Try to align all the lines of args correctly.
1225 $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH + $SYMBOL_FIELD_WIDTH + 1);
1226 my $args_padded = $args;
1227 $args_padded =~ s/ *\\\n */\n$pad/gm;
1228 $synop .= &CreateValidSGML ($args_padded);
1232 my $title = $symbol . ($args ? "()" : "");
1233 $desc = "<refsect2 id=\"$id\" role=\"macro\"$condition>\n<title>$title</title>\n";
1234 $desc .= MakeIndexterms($symbol, $id);
1236 $desc .= OutputSymbolExtraLinks($symbol);
1238 # Don't output the macro definition if is is a conditional macro or it
1239 # looks like a function, i.e. starts with "g_" or "_?gnome_", or it is
1240 # longer than 2 lines, otherwise we get lots of complicated macros like
1242 if (!defined ($DeclarationConditional{$symbol}) && ($symbol !~ m/^g_/)
1243 && ($symbol !~ m/^_?gnome_/) && (($declaration =~ tr/\n//) < 2)) {
1244 my $decl_out = &CreateValidSGML ($declaration);
1245 $desc .= "<programlisting>$decl_out</programlisting>\n";
1247 $desc .= "<programlisting>" . &MakeReturnField("#define") . "$symbol";
1248 # Align each line so that if should all line up OK.
1249 $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH - length ("#define "));
1250 $args =~ s/\n/\n$pad/gm;
1251 $desc .= &CreateValidSGML ($args);
1252 $desc .= "</programlisting>\n";
1255 $desc .= &MakeDeprecationNote($symbol);
1257 my $parameters = &OutputParamDescriptions ("MACRO", $symbol);
1258 my $parameters_output = 0;
1260 if (defined ($SymbolDocs{$symbol})) {
1261 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1263 # Try to insert the parameter table at the author's desired position.
1264 # Otherwise we need to tag it onto the end.
1265 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1266 $parameters_output = 1;
1268 $desc .= $symbol_docs;
1271 if ($parameters_output == 0) {
1272 $desc .= $parameters;
1275 $desc .= OutputSymbolTraits ($symbol);
1276 $desc .= "</refsect2>\n";
1277 return ($synop, $desc);
1281 #############################################################################
1282 # Function : OutputTypedef
1283 # Description : Returns the synopsis and detailed description of a typedef.
1284 # Arguments : $symbol - the typedef.
1285 # $declaration - the declaration of the typedef,
1286 # e.g. 'typedef unsigned int guint;'
1287 #############################################################################
1290 my ($symbol, $declaration) = @_;
1291 my $id = &CreateValidSGMLID ($symbol);
1292 my $condition = &MakeConditionDescription ($symbol);
1293 my $synop = &MakeReturnField("typedef") . "<link linkend=\"$id\">$symbol</link>;\n";
1294 my $desc = "<refsect2 id=\"$id\" role=\"typedef\"$condition>\n<title>$symbol</title>\n";
1296 $desc .= MakeIndexterms($symbol, $id);
1298 $desc .= OutputSymbolExtraLinks($symbol);
1300 if (!defined ($DeclarationConditional{$symbol})) {
1301 my $decl_out = &CreateValidSGML ($declaration);
1302 $desc .= "<programlisting>$decl_out</programlisting>\n";
1305 $desc .= &MakeDeprecationNote($symbol);
1307 if (defined ($SymbolDocs{$symbol})) {
1308 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1310 $desc .= OutputSymbolTraits ($symbol);
1311 $desc .= "</refsect2>\n";
1312 return ($synop, $desc);
1316 #############################################################################
1317 # Function : OutputStruct
1318 # Description : Returns the synopsis and detailed description of a struct.
1319 # We check if it is a widget struct, and if so we only output
1320 # parts of it that are noted as public fields.
1321 # We also use a different SGML ID for widget structs, since the
1322 # original ID is used for the entire RefEntry.
1323 # Arguments : $symbol - the struct.
1324 # $declaration - the declaration of the struct.
1325 #############################################################################
1328 my ($symbol, $declaration) = @_;
1330 my $is_widget_struct = 0;
1331 my $default_to_public = 1;
1332 if (&CheckIsObject ($symbol)) {
1333 #print "Found widget struct: $symbol\n";
1334 $is_widget_struct = 1;
1335 $default_to_public = 0;
1340 if ($is_widget_struct) {
1341 $id = &CreateValidSGMLID ($symbol . "_struct");
1342 $condition = &MakeConditionDescription ($symbol . "_struct");
1344 $id = &CreateValidSGMLID ($symbol);
1345 $condition = &MakeConditionDescription ($symbol);
1348 # Determine if it is a simple struct or it also has a typedef.
1349 my $has_typedef = 0;
1350 if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1357 # For structs with typedefs we just output the struct name.
1358 $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1359 $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>$symbol</title>\n";
1361 $synop = &MakeReturnField("struct") . "<link linkend=\"$id\">$symbol</link>;\n";
1362 $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>struct $symbol</title>\n";
1365 $desc .= MakeIndexterms($symbol, $id);
1367 $desc .= OutputSymbolExtraLinks($symbol);
1369 # Form a pretty-printed, private-data-removed form of the declaration
1372 if ($declaration =~ m/^\s*$/) {
1373 #print "Found opaque struct: $symbol\n";
1374 $decl_out = "typedef struct _$symbol $symbol;";
1375 } elsif ($declaration =~ m/^\s*struct\s+\w+\s*;\s*$/) {
1376 #print "Found opaque struct: $symbol\n";
1377 $decl_out = "struct $symbol;";
1379 my $public = $default_to_public;
1380 my $new_declaration = "";
1382 my $decl = $declaration;
1384 if ($decl =~ m/^\s*(typedef\s+)?struct\s*\w*\s*(?:\/\*.*\*\/)?\s*{(.*)}\s*\w*\s*;\s*$/s) {
1385 my $struct_contents = $2;
1387 foreach $decl_line (split (/\n/, $struct_contents)) {
1388 #print "Struct line: $decl_line\n";
1389 if ($decl_line =~ m%/\*\s*<\s*public\s*>\s*\*/%) {
1391 } elsif ($decl_line =~ m%/\*\s*<\s*(private|protected)\s*>\s*\*/%) {
1394 $new_declaration .= $decl_line . "\n";
1398 if ($new_declaration) {
1399 # Strip any blank lines off the ends.
1400 $new_declaration =~ s/^\s*\n//;
1401 $new_declaration =~ s/\n\s*$/\n/;
1404 $decl_out = "typedef struct {\n" . $new_declaration
1407 $decl_out = "struct $symbol {\n" . $new_declaration
1412 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1413 "Couldn't parse struct:\n$declaration");
1416 # If we couldn't parse the struct or it was all private, output an
1417 # empty struct declaration.
1418 if ($decl_out eq "") {
1420 $decl_out = "typedef struct _$symbol $symbol;";
1422 $decl_out = "struct $symbol;";
1427 $decl_out = &CreateValidSGML ($decl_out);
1428 $desc .= "<programlisting>$decl_out</programlisting>\n";
1430 $desc .= &MakeDeprecationNote($symbol);
1432 if (defined ($SymbolDocs{$symbol})) {
1433 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1436 # Create a table of fields and descriptions
1438 # FIXME: Inserting  's into the produced type declarations here would
1439 # improve the output in most situations ... except for function
1440 # members of structs!
1441 my @fields = ParseStructDeclaration($declaration, !$default_to_public,
1444 "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1446 my $params = $SymbolParams{$symbol};
1448 # If no parameters are filled in, we don't generate the description
1449 # table, for backwards compatibility
1452 if (defined $params) {
1453 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1454 if ($params->[$i] =~ /\S/) {
1462 my %field_descrs = @$params;
1465 <variablelist role="struct">
1468 my $field_name = shift @fields;
1469 my $text = shift @fields;
1470 my $field_descr = $field_descrs{$field_name};
1471 my $param_annotations = "";
1473 $desc .= "<varlistentry><term>$text</term>\n";
1474 if (defined $field_descr) {
1475 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1476 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1477 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1479 $desc .= "<listitem><simpara /></listitem>\n";
1481 $desc .= "</varlistentry>\n";
1484 $desc .= "</variablelist>";
1486 $desc .= OutputSymbolTraits ($symbol);
1487 $desc .= "</refsect2>\n";
1488 return ($synop, $desc);
1492 #############################################################################
1493 # Function : OutputEnum
1494 # Description : Returns the synopsis and detailed description of a enum.
1495 # Arguments : $symbol - the enum.
1496 # $declaration - the declaration of the enum.
1497 #############################################################################
1500 my ($symbol, $declaration) = @_;
1501 my $id = &CreateValidSGMLID ($symbol);
1502 my $condition = &MakeConditionDescription ($symbol);
1503 my $synop = &MakeReturnField("enum") . "<link linkend=\"$id\">$symbol</link>;\n";
1504 my $desc = "<refsect2 id=\"$id\" role=\"enum\"$condition>\n<title>enum $symbol</title>\n";
1506 $desc .= MakeIndexterms($symbol, $id);
1508 $desc .= OutputSymbolExtraLinks($symbol);
1510 my $decl_out = &CreateValidSGML ($declaration);
1511 $desc .= "<programlisting>$decl_out</programlisting>\n";
1513 $desc .= &MakeDeprecationNote($symbol);
1515 if (defined ($SymbolDocs{$symbol})) {
1516 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1519 # Create a table of fields and descriptions
1521 my @members = ParseEnumDeclaration($declaration);
1522 my $params = $SymbolParams{$symbol};
1524 # If no parameters are filled in, we don't generate the description
1525 # table, for backwards compatibility
1528 if (defined $params) {
1529 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1530 if ($params->[$i] =~ /\S/) {
1538 my %member_descrs = @$params;
1541 <variablelist role="enum">
1543 for my $member_name (@members) {
1544 my $member_descr = $member_descrs{$member_name};
1545 my $param_annotations = "";
1547 $id = &CreateValidSGMLID ($member_name);
1548 $condition = &MakeConditionDescription ($member_name);
1549 $desc .= "<varlistentry id=\"$id\" role=\"constant\"$condition>\n<term><literal>$member_name</literal></term>\n";
1550 if (defined $member_descr) {
1551 ($member_descr,$param_annotations) = &ExpandAnnotation($symbol, $member_descr);
1552 $member_descr = &ExpandAbbreviations($symbol, $member_descr);
1553 $desc .= "<listitem><simpara>$member_descr$param_annotations</simpara></listitem>\n";
1555 $desc .= "<listitem></listitem>\n";
1557 $desc .= "</varlistentry>\n";
1560 $desc .= "</variablelist>";
1563 $desc .= OutputSymbolTraits ($symbol);
1564 $desc .= "</refsect2>\n";
1565 return ($synop, $desc);
1569 #############################################################################
1570 # Function : OutputUnion
1571 # Description : Returns the synopsis and detailed description of a union.
1572 # Arguments : $symbol - the union.
1573 # $declaration - the declaration of the union.
1574 #############################################################################
1577 my ($symbol, $declaration) = @_;
1578 my $id = &CreateValidSGMLID ($symbol);
1579 my $condition = &MakeConditionDescription ($symbol);
1580 my $synop = &MakeReturnField("union") . "<link linkend=\"$id\">$symbol</link>;\n";
1581 my $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>union $symbol</title>\n";
1583 $desc .= MakeIndexterms($symbol, $id);
1585 $desc .= OutputSymbolExtraLinks($symbol);
1587 my $decl_out = &CreateValidSGML ($declaration);
1588 $desc .= "<programlisting>$decl_out</programlisting>\n";
1590 $desc .= &MakeDeprecationNote($symbol);
1592 if (defined ($SymbolDocs{$symbol})) {
1593 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1595 $desc .= OutputSymbolTraits ($symbol);
1596 $desc .= "</refsect2>\n";
1597 return ($synop, $desc);
1601 #############################################################################
1602 # Function : OutputVariable
1603 # Description : Returns the synopsis and detailed description of a variable.
1604 # Arguments : $symbol - the extern'ed variable.
1605 # $declaration - the declaration of the variable.
1606 #############################################################################
1608 sub OutputVariable {
1609 my ($symbol, $declaration) = @_;
1610 my $id = &CreateValidSGMLID ($symbol);
1611 my $condition = &MakeConditionDescription ($symbol);
1614 if ($declaration =~ m/^\s*extern\s+((const\s+|unsigned\s+)*\w+)(\s+\*+|\*+|\s)(\s*)([A-Za-z]\w*)\s*;/) {
1615 my $mod = defined ($1) ? $1 : "";
1616 my $ptr = defined ($3) ? $3 : "";
1617 my $space = defined ($4) ? $4 : "";
1618 $synop = &MakeReturnField("extern") . "$mod$ptr$space<link linkend=\"$id\">$symbol</link>;\n";
1621 $synop = &MakeReturnField("extern") . "<link linkend=\"$id\">$symbol</link>;\n";
1624 my $desc = "<refsect2 id=\"$id\" role=\"variable\"$condition>\n<title>$symbol</title>\n";
1626 $desc .= MakeIndexterms($symbol, $id);
1628 $desc .= OutputSymbolExtraLinks($symbol);
1630 my $decl_out = &CreateValidSGML ($declaration);
1631 $desc .= "<programlisting>$decl_out</programlisting>\n";
1633 $desc .= &MakeDeprecationNote($symbol);
1635 if (defined ($SymbolDocs{$symbol})) {
1636 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1638 $desc .= OutputSymbolTraits ($symbol);
1639 $desc .= "</refsect2>\n";
1640 return ($synop, $desc);
1644 #############################################################################
1645 # Function : OutputFunction
1646 # Description : Returns the synopsis and detailed description of a function.
1647 # Arguments : $symbol - the function.
1648 # $declaration - the declaration of the function.
1649 #############################################################################
1651 sub OutputFunction {
1652 my ($symbol, $declaration, $symbol_type) = @_;
1653 my $id = &CreateValidSGMLID ($symbol);
1654 my $condition = &MakeConditionDescription ($symbol);
1656 # Take out the return type $1 $3 $4
1657 $declaration =~ s/<RETURNS>\s*((const\s+|G_CONST_RETURN\s+|unsigned\s+|long\s+|short\s+|struct\s+|enum\s+)*)(\w+)(\s*\**\s*(const|G_CONST_RETURN)?\s*\**\s*(restrict)?\s*)<\/RETURNS>\n//;
1658 my $type_modifier = defined($1) ? $1 : "";
1661 #print "$symbol pointer is $pointer\n";
1662 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1664 #if ($symbol_type eq 'USER_FUNCTION') {
1665 # $start = "typedef ";
1668 # We output const rather than G_CONST_RETURN.
1669 $type_modifier =~ s/G_CONST_RETURN/const/g;
1670 $pointer =~ s/G_CONST_RETURN/const/g;
1671 $pointer =~ s/^\s+/ /g;
1673 my $ret_type_len = length ($start) + length ($type_modifier)
1674 + length ($pointer) + length ($type);
1675 my $ret_type_output;
1677 if ($ret_type_len < $RETURN_TYPE_FIELD_WIDTH) {
1678 $ret_type_output = "$start$type_modifier$xref$pointer"
1679 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
1682 # $ret_type_output = "$start$type_modifier$xref$pointer\n"
1683 # . (' ' x $RETURN_TYPE_FIELD_WIDTH);
1685 $ret_type_output = "$start$type_modifier$xref$pointer ";
1686 $symbol_len = $ret_type_len + 1 - $RETURN_TYPE_FIELD_WIDTH;
1689 $symbol_len += length ($symbol);
1690 my $char1 = my $char2 = my $char3 = "";
1691 if ($symbol_type eq 'USER_FUNCTION') {
1698 my ($symbol_output, $symbol_desc_output);
1699 if ($symbol_len < $SYMBOL_FIELD_WIDTH) {
1700 $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3"
1701 . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1702 $symbol_desc_output = "$char1$char2$symbol$char3"
1703 . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1705 $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3\n"
1706 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1707 $symbol_desc_output = "$char1$char2$symbol$char3\n"
1708 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1711 my $synop = $ret_type_output . $symbol_output . '(';
1712 my $desc = "<refsect2 id=\"$id\" role=\"function\"$condition>\n<title>${symbol} ()</title>\n";
1714 $desc .= MakeIndexterms($symbol, $id);
1716 $desc .= OutputSymbolExtraLinks($symbol);
1718 $desc .= "<programlisting>${ret_type_output}$symbol_desc_output(";
1721 while ($declaration ne "") {
1722 #print "$declaration";
1724 if ($declaration =~ s/^[\s,]+//) {
1725 # skip whitespace and commas
1728 } elsif ($declaration =~ s/^void\s*[,\n]//) {
1732 } elsif ($declaration =~ s/^...\s*[,\n]//) {
1733 if ($param_num == 0) {
1738 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1741 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1745 # allow alphanumerics, '_', '[' & ']' in param names
1746 # Try to match a standard parameter (keep in sync with gtkdoc-mktmpl)
1748 } elsif ($declaration =~ s/^\s*((?:G_CONST_RETURN|G_GNUC_UNUSED|unsigned long|unsigned short|signed long|signed short|unsigned|signed|long|short|volatile|const)\s+)*((?:struct\b|enum\b)?\s*\w+)\s*((?:(?:const\b|restrict\b)?\s*\*?\s*(?:const\b|restrict\b)?\s*)*)(\w+)?\s*((?:\[\S*\])*)\s*[,\n]//) {
1749 my $pre = defined($1) ? $1 : "";
1751 my $ptr = defined($3) ? $3 : "";
1752 my $name = defined($4) ? $4 : "";
1753 my $array = defined($5) ? $5 : "";
1759 if ($ptr && $ptr !~ m/\*$/) { $ptr .= " "; }
1761 #print "$symbol: '$pre' '$type' '$ptr' '$name' '$array'\n";
1763 if (($name eq "") && $pre =~ m/^((un)?signed .*)\s?/ ) {
1769 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1770 my $label = "$pre$xref $ptr$name$array";
1772 #print "$symbol: '$pre' '$type' '$ptr' '$name' '$array'\n";
1774 if ($param_num == 0) {
1779 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1782 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1786 # Try to match parameters which are functions (keep in sync with gtkdoc-mktmpl)
1787 # $1 $2 $3 $4 $5 $7 $8
1788 } elsif ($declaration =~ s/^(const\s+|G_CONST_RETURN\s+|unsigned\s+)*(struct\s+)?(\w+)\s*(\**)\s*(?:restrict\b)?\s*(const\s+)?\(\s*\*+\s*(\w+)\s*\)\s*\(([^)]*)\)\s*[,\n]//) {
1789 my $mod1 = defined($1) ? $1 : "";
1790 if (defined($2)) { $mod1 .= $2; }
1793 my $mod2 = defined($5) ? $5 : "";
1796 my $func_params = defined($8) ? $8 : "";
1798 #if (!defined($type)) { print "## no type\n"; };
1799 #if (!defined($ptr1)) { print "## no ptr1\n"; };
1800 #if (!defined($func_ptr)) { print "## no func_ptr\n"; };
1801 #if (!defined($name)) { print "## no name\n"; };
1803 if ($ptr1 && $ptr1 !~ m/\*$/) { $ptr1 .= " "; }
1804 $func_ptr =~ s/\s+//g;
1805 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1806 my $label = "$mod1$xref$ptr1$mod2 ($func_ptr$name) ($func_params)";
1808 #print "Type: [$mod1][$xref][$ptr1][$mod2] ([$func_ptr][$name]) ($func_params)\n";
1809 if ($param_num == 0) {
1814 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1817 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1822 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1823 "Can't parse args for function $symbol: $declaration");
1829 $desc .= ");</programlisting>\n";
1831 $desc .= &MakeDeprecationNote($symbol);
1833 my $parameters = &OutputParamDescriptions ("FUNCTION", $symbol);
1834 my $parameters_output = 0;
1836 if (defined ($SymbolDocs{$symbol})) {
1837 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1839 # Try to insert the parameter table at the author's desired position.
1840 # Otherwise we need to tag it onto the end.
1841 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1842 $parameters_output = 1;
1844 $desc .= $symbol_docs;
1847 if ($parameters_output == 0) {
1848 $desc .= $parameters;
1851 $desc .= OutputSymbolTraits ($symbol);
1852 $desc .= "</refsect2>\n";
1853 return ($synop, $desc);
1857 #############################################################################
1858 # Function : OutputParamDescriptions
1859 # Description : Returns the DocBook output describing the parameters of a
1860 # function, macro or signal handler.
1861 # Arguments : $symbol_type - 'FUNCTION', 'MACRO' or 'SIGNAL'. Signal
1862 # handlers have an implicit user_data parameter last.
1863 # $symbol - the name of the function/macro being described.
1864 #############################################################################
1866 sub OutputParamDescriptions {
1867 my ($symbol_type, $symbol) = @_;
1869 if (defined ($SymbolParams{$symbol})) {
1871 my $params = $SymbolParams{$symbol};
1872 my $params_desc = "";
1874 for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
1875 my $param_name = $$params[$j];
1876 my $param_desc = $$params[$j + 1];
1877 my $param_annotations = "";
1879 ($param_desc,$param_annotations) = & ExpandAnnotation($symbol, $param_desc);
1880 $param_desc = &ExpandAbbreviations($symbol, $param_desc);
1881 if ($param_name eq "Returns") {
1882 $returns = "$param_desc$param_annotations";
1884 if ($param_name eq "Varargs") {
1885 $param_name = "...";
1887 $params_desc .= "<varlistentry><term><parameter>$param_name</parameter> :</term>\n<listitem><simpara>$param_desc$param_annotations</simpara></listitem></varlistentry>\n";
1891 # Signals have an implicit user_data parameter which we describe.
1892 if ($symbol_type eq "SIGNAL") {
1893 $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";
1896 # Start a table if we need one.
1897 if ($params_desc || $returns) {
1898 $output .= "<variablelist role=\"params\">\n";
1899 if ($params_desc ne "") {
1900 #$output .= "<varlistentry><term>Parameters:</term><listitem></listitem></varlistentry>\n";
1901 $output .= $params_desc;
1904 # Output the returns info last.
1906 $output .= "<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>$returns</simpara></listitem></varlistentry>\n";
1910 $output .= "</variablelist>";
1917 #############################################################################
1918 # Function : ParseStabilityLevel
1919 # Description : Parses a stability level and outputs a warning if it isn't
1921 # Arguments : $stability - the stability text.
1922 # $file, $line - context for error message
1923 # $message - description of where the level is from, to use in
1924 # any error message.
1925 # Returns : The parsed stability level string.
1926 #############################################################################
1928 sub ParseStabilityLevel {
1929 my ($stability, $file, $line, $message) = @_;
1931 $stability =~ s/^\s*//;
1932 $stability =~ s/\s*$//;
1933 if ($stability =~ m/^stable$/i) {
1934 $stability = "Stable";
1935 } elsif ($stability =~ m/^unstable$/i) {
1936 $stability = "Unstable";
1937 } elsif ($stability =~ m/^private$/i) {
1938 $stability = "Private";
1940 &LogWarning ($file, $line, "$message is $stability.".
1941 "It should be one of these: Stable, Unstable, or Private.");
1947 #############################################################################
1948 # Function : OutputSGMLFile
1949 # Description : Outputs the final DocBook file for one section.
1950 # Arguments : $file - the name of the file.
1951 # $title - the title from the $MODULE-sections.txt file, which
1952 # will be overridden by the title in the template file.
1953 # $section_id - the SGML id to use for the toplevel tag.
1954 # $includes - comma-separates list of include files added at top
1955 # of synopsis, with '<' '>' around them (if not already enclosed in "").
1956 # $synopsis - reference to the DocBook for the Synopsis part.
1957 # $details - reference to the DocBook for the Details part.
1958 # $signal_synop - reference to the DocBook for the Signal Synopsis part
1959 # $signal_desc - reference to the DocBook for the Signal Description part
1960 # $args_synop - reference to the DocBook for the Arg Synopsis part
1961 # $args_desc - reference to the DocBook for the Arg Description part
1962 # $hierarchy - reference to the DocBook for the Object Hierarchy part
1963 # $interfaces - reference to the DocBook for the Interfaces part
1964 # $implementations - reference to the DocBook for the Known Implementations part
1965 # $prerequisites - reference to the DocBook for the Prerequisites part
1966 # $derived - reference to the DocBook for the Derived Interfaces part
1967 # $file_objects - reference to an array of objects in this file
1968 #############################################################################
1970 sub OutputSGMLFile {
1971 my ($file, $title, $section_id, $includes, $synopsis, $details, $signals_synop, $signals_desc, $args_synop, $args_desc, $hierarchy, $interfaces, $implementations, $prerequisites, $derived, $file_objects) = @_;
1973 #print "Output sgml for file $file with title '$title'\n";
1975 # The edited title overrides the one from the sections file.
1976 my $new_title = $SymbolDocs{"$TMPL_DIR/$file:Title"};
1977 if (defined ($new_title) && $new_title !~ m/^\s*$/) {
1978 $title = $new_title;
1979 #print "Found title: $title\n";
1981 my $short_desc = $SymbolDocs{"$TMPL_DIR/$file:Short_Description"};
1982 if (!defined ($short_desc) || $short_desc =~ m/^\s*$/) {
1985 $short_desc = &ExpandAbbreviations("$title:Short_description",
1987 #print "Found short_desc: $short_desc";
1989 my $long_desc = $SymbolDocs{"$TMPL_DIR/$file:Long_Description"};
1990 if (!defined ($long_desc) || $long_desc =~ m/^\s*$/) {
1993 $long_desc = &ExpandAbbreviations("$title:Long_description",
1995 #print "Found long_desc: $long_desc";
1997 my $see_also = $SymbolDocs{"$TMPL_DIR/$file:See_Also"};
1998 if (!defined ($see_also) || $see_also =~ m%^\s*(<para>)?\s*(</para>)?\s*$%) {
2001 $see_also = &ExpandAbbreviations("$title:See_Also", $see_also);
2002 #print "Found see_also: $see_also";
2005 $see_also = "<refsect1 id=\"$section_id.see-also\">\n<title>See Also</title>\n$see_also\n</refsect1>\n";
2007 my $stability = $SymbolDocs{"$TMPL_DIR/$file:Stability_Level"};
2008 if (!defined ($stability) || $stability =~ m/^\s*$/) {
2011 $stability = &ParseStabilityLevel($stability, $file, $., "Section stability level");
2012 #print "Found stability: $stability";
2015 $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$stability, unless otherwise indicated\n</refsect1>\n";
2016 } elsif ($DEFAULT_STABILITY) {
2017 $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$DEFAULT_STABILITY, unless otherwise indicated\n</refsect1>\n";
2020 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
2022 my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
2025 my $include_output = "";
2027 foreach $include (split (/,/, $includes)) {
2028 if ($include =~ m/^\".+\"$/) {
2029 $include_output .= "#include ${include}\n";
2032 $include =~ s/^\s+|\s+$//gs;
2033 $include_output .= "#include <${include}>\n";
2036 if ($include_output ne '') {
2037 $include_output = "\n$include_output\n";
2040 my $extralinks = OutputSectionExtraLinks($title,"Section:$file");
2042 my $old_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT";
2043 my $new_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT.new";
2045 open (OUTPUT, ">$new_sgml_file")
2046 || die "Can't create $new_sgml_file: $!";
2048 my $object_anchors = "";
2049 foreach my $object (@$file_objects) {
2050 next if ($object eq $section_id);
2051 my $id = CreateValidSGMLID($object);
2052 #print "Debug: Adding anchor for $object\n";
2053 $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
2056 # We used to output this, but is messes up our UpdateFileIfChanged code
2057 # since it changes every day (and it is only used in the man pages):
2058 # "<refentry id="$section_id" revision="$mday $month $year">"
2060 if (lc($OUTPUT_FORMAT) eq "xml") {
2061 print OUTPUT $doctype_header;
2065 <refentry id="$section_id">
2067 <refentrytitle role="top_of_page" id="$section_id.top_of_page">$title</refentrytitle>
2068 <manvolnum>3</manvolnum>
2069 <refmiscinfo>\U$MODULE\E Library</refmiscinfo>
2072 <refname>$title</refname>
2073 <refpurpose>$short_desc</refpurpose>
2076 <refsynopsisdiv id="$section_id.synopsis" role="synopsis">
2077 <title role="synopsis.title">Synopsis</title>
2079 <synopsis>$include_output$${synopsis}</synopsis>
2081 $$hierarchy$$prerequisites$$derived$$interfaces$$implementations$$args_synop$$signals_synop
2082 <refsect1 id="$section_id.description" role="desc">
2083 <title role="desc.title">Description</title>
2084 $extralinks$long_desc
2086 <refsect1 id="$section_id.details" role="details">
2087 <title role="details.title">Details</title>
2090 $$args_desc$$signals_desc$see_also
2095 return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2099 #############################################################################
2100 # Function : OutputExtraFile
2101 # Description : Copies an "extra" DocBook file into the output directory,
2102 # expanding abbreviations
2103 # Arguments : $file - the source file.
2104 #############################################################################
2105 sub OutputExtraFile {
2110 ($basename = $file) =~ s!^.*/!!;
2112 my $old_sgml_file = "$SGML_OUTPUT_DIR/$basename";
2113 my $new_sgml_file = "$SGML_OUTPUT_DIR/$basename.new";
2117 open(EXTRA_FILE, "<$file") || die "Can't open $file";
2121 $contents = <EXTRA_FILE>;
2124 open (OUTPUT, ">$new_sgml_file")
2125 || die "Can't create $new_sgml_file: $!";
2127 print OUTPUT &ExpandAbbreviations ("$basename file", $contents);
2130 return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2132 #############################################################################
2133 # Function : OutputBook
2134 # Description : Outputs the SGML entities that need to be included into the
2135 # main SGML file for the module.
2136 # Arguments : $book_top - the declarations of the entities, which are added
2137 # at the top of the main SGML file.
2138 # $book_bottom - the references to the entities, which are
2139 # added in the main SGML file at the desired position.
2140 #############################################################################
2143 my ($book_top, $book_bottom) = @_;
2145 my $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top";
2146 my $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top.new";
2148 open (OUTPUT, ">$new_file")
2149 || die "Can't create $new_file: $!";
2150 print OUTPUT $book_top;
2153 &UpdateFileIfChanged ($old_file, $new_file, 0);
2156 $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom";
2157 $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom.new";
2159 open (OUTPUT, ">$new_file")
2160 || die "Can't create $new_file: $!";
2161 print OUTPUT $book_bottom;
2164 &UpdateFileIfChanged ($old_file, $new_file, 0);
2167 # If the main SGML file hasn't been created yet, we create it here.
2168 # The user can tweak it later.
2169 if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
2170 open (OUTPUT, ">$MAIN_SGML_FILE")
2171 || die "Can't create $MAIN_SGML_FILE: $!";
2173 if (lc($OUTPUT_FORMAT) eq "xml") {
2175 <?xml version="1.0"?>
2176 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
2177 "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
2179 <!ENTITY % local.common.attrib "xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'">
2185 <!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
2194 <title>$MODULE Reference Manual</title>
2196 for $MODULE [VERSION].
2197 The latest version of this documentation can be found on-line at
2198 <ulink role="online-location" url="http://[SERVER]/$MODULE/index.html">http://[SERVER]/$MODULE/</ulink>.
2203 <title>[Insert title here]</title>
2207 if (-e $OBJECT_TREE_FILE) {
2209 <chapter id="object-tree">
2210 <title>Object Hierarchy</title>
2211 <xi:include href="xml/tree_index.sgml"/>
2217 <index id="api-index-full">
2218 <title>API Index</title>
2219 <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
2222 <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
2231 #############################################################################
2232 # Function : CreateValidSGML
2233 # Description : This turns any chars which are used in SGML into entities,
2234 # e.g. '<' into '<'
2235 # Arguments : $text - the text to turn into proper SGML.
2236 #############################################################################
2238 sub CreateValidSGML {
2240 $text =~ s/&/&/g; # Do this first, or the others get messed up.
2241 $text =~ s/</</g;
2242 $text =~ s/>/>/g;
2243 # browers render single tabs inconsistently
2244 $text =~ s/([^\s])\t([^\s])/$1 $2/g;
2248 #############################################################################
2249 # Function : ConvertSGMLChars
2250 # Description : This is used for text in source code comment blocks, to turn
2251 # chars which are used in SGML into entities, e.g. '<' into
2252 # '<'. Depending on $SGML_MODE, this is done
2253 # unconditionally or only if the character doesn't seem to be
2254 # part of an SGML construct (tag or entity reference).
2255 # Arguments : $text - the text to turn into proper SGML.
2256 #############################################################################
2258 sub ConvertSGMLChars {
2259 my ($symbol, $text) = @_;
2262 # For the SGML mode only convert to entities outside CDATA sections.
2263 return &ModifyXMLElements ($text, $symbol,
2264 "<!\\[CDATA\\[|<programlisting[^>]*>",
2265 \&ConvertSGMLCharsEndTag,
2266 \&ConvertSGMLCharsCallback);
2268 # For the simple non-sgml mode, convert to entities everywhere.
2269 $text =~ s/&/&/g; # Do this first, or the others get messed up.
2270 $text =~ s/</</g;
2271 $text =~ s/>/>/g;
2277 sub ConvertSGMLCharsEndTag {
2278 if ($_[0] eq "<!\[CDATA\[") {
2281 return "</programlisting>";
2285 sub ConvertSGMLCharsCallback {
2286 my ($text, $symbol, $tag) = @_;
2288 if ($tag =~ m/^<programlisting/) {
2289 # We can handle <programlisting> specially here.
2290 return &ModifyXMLElements ($text, $symbol,
2292 \&ConvertSGMLCharsEndTag,
2293 \&ConvertSGMLCharsCallback2);
2294 } elsif ($tag eq "") {
2295 # If we're not in CDATA convert to entities.
2296 $text =~ s/&(?![a-zA-Z#]+;)/&/g; # Do this first, or the others get messed up.
2297 $text =~ s/<(?![a-zA-Z\/!])/</g;
2298 $text =~ s/(?<![a-zA-Z0-9"'\/-])>/>/g;
2300 # Handle "#include <xxxxx>"
2301 $text =~ s/#include(\s+)<([^>]+)>/#include$1<$2>/g;
2307 sub ConvertSGMLCharsCallback2 {
2308 my ($text, $symbol, $tag) = @_;
2310 # If we're not in CDATA convert to entities.
2311 # We could handle <programlisting> differently, though I'm not sure it helps.
2313 # replace only if its not a tag
2314 $text =~ s/&(?![a-zA-Z#]+;)/&/g; # Do this first, or the others get messed up.
2315 $text =~ s/<(?![a-zA-Z\/!])/</g;
2316 $text =~ s/(?<![a-zA-Z0-9"'\/-])>/>/g;
2318 # Handle "#include <xxxxx>"
2319 $text =~ s/#include(\s+)<([^>]+)>/#include$1<$2>/g;
2325 #############################################################################
2326 # Function : ExpandAnnotation
2327 # Description : This turns annotations into acrony tags.
2328 # Arguments : $symbol - the symbol being documented, for error messages.
2329 # $text - the text to expand.
2330 #############################################################################
2331 sub ExpandAnnotation {
2332 my ($symbol, $param_desc) = @_;
2333 my $param_annotations = "";
2335 if ($param_desc =~ m%\s*\((.*)\):%) {
2338 my $annotation_extra = "";
2341 @annotations = split(/\)\s*\(/,$1);
2342 foreach $annotation (@annotations) {
2343 # need to search for the longest key-match in %AnnotationDefinition
2345 my $match_annotation="";
2347 foreach $annotationdef (keys %AnnotationDefinition) {
2348 if ($annotation =~ m/^$annotationdef/) {
2349 if (length($annotationdef)>$match_length) {
2350 $match_length=length($annotationdef);
2351 $match_annotation=$annotationdef;
2355 if ($match_annotation ne "") {
2356 if ($annotation =~ m%$match_annotation\s+(.*)%) {
2357 $annotation_extra = " $1";
2359 $AnnotationsUsed{$match_annotation} = 1;
2360 $param_annotations .= "<acronym>$match_annotation</acronym>$annotation_extra. ";
2363 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2364 "unknown annotation \"$annotation\" in documentation for $symbol.");
2365 $param_annotations=$annotation;
2369 $param_desc =~ m/^(.*)\.*\s*$/;
2370 $param_desc = "$1. ";
2372 return ($param_desc, $param_annotations);
2375 #############################################################################
2376 # Function : ExpandAbbreviations
2377 # Description : This turns the abbreviations function(), macro(), @param,
2378 # %constant, and #symbol into appropriate DocBook markup.
2379 # CDATA sections and <programlisting> parts are skipped.
2380 # Arguments : $symbol - the symbol being documented, for error messages.
2381 # $text - the text to expand.
2382 #############################################################################
2384 sub ExpandAbbreviations {
2385 my ($symbol, $text) = @_;
2387 # Convert "|[" and "]|" into the start and end of program listing examples.
2388 $text =~ s%\|\[%<informalexample><programlisting>%g;
2389 $text =~ s%\]\|%</programlisting></informalexample>%g;
2390 # TODO: check for a xml comment after |[ and pick the language attribute from
2393 # keep CDATA unmodified, preserve ulink tags (ideally we preseve all tags
2395 return &ModifyXMLElements ($text, $symbol,
2396 "<!\\[CDATA\\[|<ulink[^>]*>|<programlisting[^>]*>|<!DOCTYPE",
2397 \&ExpandAbbreviationsEndTag,
2398 \&ExpandAbbreviationsCallback);
2402 # Returns the end tag corresponding to the given start tag.
2403 sub ExpandAbbreviationsEndTag {
2404 my ($start_tag) = @_;
2406 if ($start_tag eq "<!\[CDATA\[") {
2408 } elsif ($start_tag eq "<!DOCTYPE") {
2410 } elsif ($start_tag =~ m/<(\w+)/) {
2415 # Called inside or outside each CDATA or <programlisting> section.
2416 sub ExpandAbbreviationsCallback {
2417 my ($text, $symbol, $tag) = @_;
2419 if ($tag =~ m/^<programlisting/) {
2420 # Handle any embedded CDATA sections.
2421 return &ModifyXMLElements ($text, $symbol,
2423 \&ExpandAbbreviationsEndTag,
2424 \&ExpandAbbreviationsCallback2);
2425 } elsif ($tag eq "") {
2426 # We are outside any CDATA or <programlisting> sections, so we expand
2427 # any gtk-doc abbreviations.
2429 # Convert 'function()' or 'macro()'.
2430 # if there is abc_*_def() we don't want to make a link to _def()
2431 # FIXME: also handle abc(....) : but that would need to be done recursively :/
2432 $text =~ s/([^\*.\w])(\w+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2433 # handle #Object.func()
2434 $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2436 # Convert '@param', but not '\@param'.
2437 $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)/$1<parameter>$2<\/parameter>/g;
2438 $text =~ s/\\\@/\@/g;
2440 # Convert '%constant', but not '\%constant'.
2441 # Also allow negative numbers, e.g. %-1.
2442 $text =~ s/(\A|[^\\])\%(-?\w+)/$1.&MakeXRef($2, &tagify($2, "literal"));/eg;
2443 $text =~ s/\\\%/\%/g;
2445 # Convert '#symbol', but not '\#symbol'.
2446 $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)/$1.&MakeHashXRef($2, "type");/eg;
2450 # FIXME: should we skip urls that are already tagged? (e.g. <literal>http://...</literal>)
2451 # this is apparently also called for markup and not just for plain text
2453 #$text =~ s%(http|https|ftp)://(.*?)((?:\s|,|\)|\]|\<|\.\s))%<ulink url="$1://$2">$2</ulink>$3%g;
2459 # This is called inside a <programlisting>
2460 sub ExpandAbbreviationsCallback2 {
2461 my ($text, $symbol, $tag) = @_;
2464 # We are inside a <programlisting> but outside any CDATA sections,
2465 # so we expand any gtk-doc abbreviations.
2466 # FIXME: why is this different from &ExpandAbbreviationsCallback(),
2467 # why not just call it
2468 $text =~ s/#(\w+)/&MakeHashXRef($1, "");/eg;
2475 my ($symbol, $tag) = @_;;
2478 # Check for things like '#include', '#define', and skip them.
2479 if ($PreProcessorDirectives{$symbol}) {
2483 # Get rid of any special '-struct' suffix.
2484 $text =~ s/-struct$//;
2486 # If the symbol is in the form "Object::signal", then change the symbol to
2487 # "Object-signal" and use "signal" as the text.
2488 if ($symbol =~ s/::/-/) {
2492 # If the symbol is in the form "Object:property", then change the symbol to
2493 # "Object--property" and use "property" as the text.
2494 if ($symbol =~ s/:/--/) {
2499 $text = tagify ($text, $tag);
2502 return &MakeXRef($symbol, $text);
2506 #############################################################################
2507 # Function : ModifyXMLElements
2508 # Description : Looks for given XML element tags within the text, and calls
2509 # the callback on pieces of text inside & outside those elements.
2510 # Used for special handling of text inside things like CDATA
2511 # and <programlisting>.
2512 # Arguments : $text - the text.
2513 # $symbol - the symbol currently being documented (only used for
2515 # $start_tag_regexp - the regular expression to match start tags.
2516 # e.g. "<!\\[CDATA\\[|<programlisting[^>]*>" to match
2517 # CDATA sections or programlisting elements.
2518 # $end_tag_func - function which is passed the matched start tag
2519 # and should return the appropriate end tag string.
2520 # $callback - callback called with each part of the text. It is
2521 # called with a piece of text, the symbol being
2522 # documented, and the matched start tag or "" if the text
2523 # is outside the XML elements being matched.
2524 #############################################################################
2525 sub ModifyXMLElements {
2526 my ($text, $symbol, $start_tag_regexp, $end_tag_func, $callback) = @_;
2527 my ($before_tag, $start_tag, $end_tag_regexp, $end_tag);
2530 while ($text =~ m/$start_tag_regexp/s) {
2531 $before_tag = $`; # Prematch for last successful match string
2532 $start_tag = $&; # Last successful match
2533 $text = $'; # Postmatch for last successful match string
2535 $result .= &$callback ($before_tag, $symbol, "");
2536 $result .= $start_tag;
2538 # get the mathing end-tag for current tag
2539 $end_tag_regexp = &$end_tag_func ($start_tag);
2541 if ($text =~ m/$end_tag_regexp/s) {
2546 $result .= &$callback ($before_tag, $symbol, $start_tag);
2547 $result .= $end_tag;
2549 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2550 "Can't find tag end: $end_tag_regexp in docs for: $symbol.");
2551 # Just assume it is all inside the tag.
2552 $result .= &$callback ($text, $symbol, $start_tag);
2557 # Handle any remaining text outside the tags.
2558 $result .= &$callback ($text, $symbol, "");
2567 # Adds a tag around some text.
2568 # e.g tagify("Text", "literal") => "<literal>Text</literal>".
2570 my ($text, $elem) = @_;
2571 return "<" . $elem . ">" . $text . "</" . $elem . ">";
2575 #############################################################################
2576 # Function : MakeXRef
2577 # Description : This returns a cross-reference link to the given symbol.
2578 # Though it doesn't try to do this for a few standard C types
2579 # that it knows won't be in the documentation.
2580 # Arguments : $symbol - the symbol to try to create a XRef to.
2581 # $text - text text to put inside the XRef, defaults to $symbol
2582 #############################################################################
2585 my ($symbol, $text) = ($_[0], $_[1]);
2587 $symbol =~ s/^\s+//;
2588 $symbol =~ s/\s+$//;
2590 if (!defined($text)) {
2593 # Get rid of special '-struct' suffix.
2594 $text =~ s/-struct$//;
2597 if ($symbol =~ m/ /) {
2601 #print "Getting type link for $symbol -> $text\n";
2603 my $symbol_id = &CreateValidSGMLID ($symbol);
2604 return "<link linkend=\"$symbol_id\">$text</link>";
2608 #############################################################################
2609 # Function : MakeIndexterms
2610 # Description : This returns a indexterm elements for the given symbol
2611 # Arguments : $symbol - the symbol to create indexterms for
2612 #############################################################################
2614 sub MakeIndexterms {
2615 my ($symbol, $id) = @_;
2619 # make the index useful, by ommiting the namespace when sorting
2620 if ($NAME_SPACE ne "") {
2621 if ($symbol =~ m/^$NAME_SPACE\_?(.*)/i) {
2622 $sortas=" sortas=\"$1\"";
2626 if (exists $Deprecated{$symbol}) {
2627 $terms .= "<indexterm zone=\"$id\" role=\"deprecated\"><primary$sortas>$symbol</primary></indexterm>";
2628 $IndexEntriesDeprecated{$symbol}=$id;
2629 $IndexEntriesFull{$symbol}=$id;
2631 if (exists $Since{$symbol}) {
2632 my $since = $Since{$symbol};
2636 $terms .= "<indexterm zone=\"$id\" role=\"$since\"><primary$sortas>$symbol</primary></indexterm>";
2638 $IndexEntriesSince{$symbol}=$id;
2639 $IndexEntriesFull{$symbol}=$id;
2642 $terms .= "<indexterm zone=\"$id\"><primary$sortas>$symbol</primary></indexterm>";
2643 $IndexEntriesFull{$symbol}=$id;
2649 #############################################################################
2650 # Function : MakeDeprecationNote
2651 # Description : This returns a deprecation warning for the given symbol.
2652 # Arguments : $symbol - the symbol to try to create a warning for.
2653 #############################################################################
2655 sub MakeDeprecationNote {
2656 my ($symbol) = $_[0];
2659 if (exists $Deprecated{$symbol}) {
2660 $desc .= "<warning>";
2662 if ($Deprecated{$symbol} =~ /^\s*([0-9\.]+)\s*:/) {
2663 $desc .= "<para><literal>$symbol</literal> has been deprecated since version $1 and should not be used in newly-written code.";
2665 $desc .= "<para><literal>$symbol</literal> is deprecated and should not be used in newly-written code.";
2667 if ($Deprecated{$symbol} ne "") {
2668 $note = &ExpandAbbreviations($symbol, $Deprecated{$symbol});
2669 $note =~ s/^\s*([0-9\.]+)\s*:\s*//;
2672 $note =~ s%\n{2,}%\n</para>\n<para>\n%g;
2673 $desc .= " " . $note;
2675 $desc .= "</para></warning>\n";
2680 #############################################################################
2681 # Function : MakeConditionDescription
2682 # Description : This returns a sumary of conditions for the given symbol.
2683 # Arguments : $symbol - the symbol to try to create the sumary.
2684 #############################################################################
2686 sub MakeConditionDescription {
2687 my ($symbol) = $_[0];
2690 if (exists $Deprecated{$symbol}) {
2695 if ($Deprecated{$symbol} =~ /^\s*(.*?)\s*$/) {
2696 $desc .= "deprecated:$1";
2698 $desc .= "deprecated";
2702 if (exists $Since{$symbol}) {
2707 if ($Since{$symbol} =~ /^\s*(.*?)\s*$/) {
2708 $desc .= "since:$1";
2714 if (exists $StabilityLevel{$symbol}) {
2718 $desc .= "stability:".$StabilityLevel{$symbol};
2722 $desc=" condition=\"".$desc."\"";
2723 #print "condition for '$symbol' = '$desc'\n";
2728 #############################################################################
2729 # Function : GetHierarchy
2730 # Description : Returns the DocBook output describing the ancestors and
2731 # immediate children of a GObject subclass. It uses the
2732 # global @Objects and @ObjectLevels arrays to walk the tree.
2733 # Arguments : $object - the GtkObject subclass.
2734 #############################################################################
2739 # Find object in the objects array.
2745 for ($i = 0; $i < @Objects; $i++) {
2747 if ($ObjectLevels[$i] <= $level) {
2750 elsif ($ObjectLevels[$i] == $level + 1) {
2751 push (@children, $Objects[$i]);
2754 elsif ($Objects[$i] eq $object) {
2757 $level = $ObjectLevels[$i];
2764 # Walk up the hierarchy, pushing ancestors onto the ancestors array.
2766 push (@ancestors, $object);
2767 #print "Level: $level\n";
2768 while ($level > 1) {
2770 if ($ObjectLevels[$j] < $level) {
2771 push (@ancestors, $Objects[$j]);
2772 $level = $ObjectLevels[$j];
2773 #print "Level: $level\n";
2777 # Output the ancestors list, indented and with links.
2778 my $hierarchy = "<synopsis>\n";
2780 for ($i = $#ancestors; $i >= 0; $i--) {
2782 # Don't add a link to the current widget, i.e. when i == 0.
2784 my $ancestor_id = &CreateValidSGMLID ($ancestors[$i]);
2785 $link_text = "<link linkend=\"$ancestor_id\">$ancestors[$i]</link>";
2787 $link_text = "$ancestors[$i]";
2790 $hierarchy .= " $link_text\n";
2792 # $hierarchy .= ' ' x ($level * 6 - 3) . "|\n";
2793 $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
2797 for ($i = 0; $i <= $#children; $i++) {
2798 my $id = &CreateValidSGMLID ($children[$i]);
2799 my $link_text = "<link linkend=\"$id\">$children[$i]</link>";
2800 $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
2802 $hierarchy .= "</synopsis>\n";
2808 #############################################################################
2809 # Function : GetInterfaces
2810 # Description : Returns the DocBook output describing the interfaces
2811 # implemented by a class. It uses the global %Interfaces hash.
2812 # Arguments : $object - the GtkObject subclass.
2813 #############################################################################
2820 # Find object in the objects array.
2821 if (exists($Interfaces{$object})) {
2822 my @ifaces = split(' ', $Interfaces{$object});
2827 for ($i = 0; $i <= $#ifaces; $i++) {
2828 my $id = &CreateValidSGMLID ($ifaces[$i]);
2829 $text .= " <link linkend=\"$id\">$ifaces[$i]</link>";
2830 if ($i < $#ifaces - 1) {
2833 elsif ($i < $#ifaces) {
2848 #############################################################################
2849 # Function : GetImplementations
2850 # Description : Returns the DocBook output describing the implementations
2851 # of an interface. It uses the global %Interfaces hash.
2852 # Arguments : $object - the GtkObject subclass.
2853 #############################################################################
2855 sub GetImplementations {
2860 foreach my $key (keys %Interfaces) {
2861 if ($Interfaces{$key} =~ /\b$object\b/) {
2862 push (@impls, $key);
2868 $object is implemented by
2870 for ($i = 0; $i <= $#impls; $i++) {
2871 my $id = &CreateValidSGMLID ($impls[$i]);
2872 $text .= " <link linkend=\"$id\">$impls[$i]</link>";
2873 if ($i < $#impls - 1) {
2876 elsif ($i < $#impls) {
2891 #############################################################################
2892 # Function : GetPrerequisites
2893 # Description : Returns the DocBook output describing the prerequisites
2894 # of an interface. It uses the global %Prerequisites hash.
2895 # Arguments : $iface - the interface.
2896 #############################################################################
2898 sub GetPrerequisites {
2903 if (exists($Prerequisites{$iface})) {
2908 my @prereqs = split(' ', $Prerequisites{$iface});
2909 for ($i = 0; $i <= $#prereqs; $i++) {
2910 my $id = &CreateValidSGMLID ($prereqs[$i]);
2911 $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
2912 if ($i < $#prereqs - 1) {
2915 elsif ($i < $#prereqs) {
2929 #############################################################################
2930 # Function : GetDerived
2931 # Description : Returns the DocBook output describing the derived interfaces
2932 # of an interface. It uses the global %Prerequisites hash.
2933 # Arguments : $iface - the interface.
2934 #############################################################################
2942 foreach my $key (keys %Prerequisites) {
2943 if ($Prerequisites{$key} =~ /\b$iface\b/) {
2944 push (@derived, $key);
2947 if ($#derived >= 0) {
2950 $iface is required by
2952 for ($i = 0; $i <= $#derived; $i++) {
2953 my $id = &CreateValidSGMLID ($derived[$i]);
2954 $text .= " <link linkend=\"$id\">$derived[$i]</link>";
2955 if ($i < $#derived - 1) {
2958 elsif ($i < $#derived) {
2973 #############################################################################
2974 # Function : GetSignals
2975 # Description : Returns the synopsis and detailed description DocBook output
2976 # for the signal handlers of a given GtkObject subclass.
2977 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
2978 #############################################################################
2986 for ($i = 0; $i <= $#SignalObjects; $i++) {
2987 if ($SignalObjects[$i] eq $object) {
2988 #print "Found signal: $SignalNames[$i]\n";
2989 my $name = $SignalNames[$i];
2990 my $symbol = "${object}::${name}";
2991 my $id = &CreateValidSGMLID ("$object-$name");
2993 my $pad = ' ' x (46 - length($name));
2994 $synop .= " "<link linkend=\"$id\">$name</link>"$pad ";
2996 $desc .= "<refsect2 id=\"$id\" role=\"signal\"><title>The <literal>"$name"</literal> signal</title>\n";
2997 $desc .= MakeIndexterms($symbol, $id);
2999 $desc .= OutputSymbolExtraLinks($symbol);
3001 $desc .= "<programlisting>";
3003 $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
3004 my $type_modifier = defined($1) ? $1 : "";
3007 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
3009 my $ret_type_len = length ($type_modifier) + length ($pointer)
3011 my $ret_type_output = "$type_modifier$xref$pointer"
3012 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
3014 $desc .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
3016 my $sourceparams = $SourceSymbolParams{$symbol};
3017 my @params = split ("\n", $SignalPrototypes[$i]);
3020 my $type_len = length("gpointer");
3021 my $name_len = length("user_data");
3022 # do two passes, the first one is to calculate padding
3023 for ($l = 0; $l < 2; $l++) {
3024 for ($j = 0; $j <= $#params; $j++) {
3025 # allow alphanumerics, '_', '[' & ']' in param names
3026 if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
3029 if (defined($sourceparams)) {
3030 $name = $$sourceparams[$PARAM_FIELD_COUNT * $j];
3035 if (!defined($name)) {
3039 if (length($type) + length($pointer) > $type_len) {
3040 $type_len = length($type) + length($pointer);
3042 if (length($name) > $name_len) {
3043 $name_len = length($name);
3047 $xref = &MakeXRef ($type, &tagify($type, "type"));
3048 $pad = ' ' x ($type_len - length($type) - length($pointer));
3049 $desc .= "$xref$pad $pointer$name,\n";
3050 $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
3053 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3054 "Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]");
3058 $xref = &MakeXRef ("gpointer", &tagify("gpointer", "type"));
3059 $pad = ' ' x ($type_len - length("gpointer"));
3060 $desc .= "$xref$pad user_data)";
3062 my $flags = $SignalFlags[$i];
3063 my $flags_string = "";
3065 if (defined ($flags)) {
3066 if ($flags =~ m/f/) {
3067 $flags_string = "Run First";
3069 elsif ($flags =~ m/l/) {
3070 $flags_string = "Run Last";
3072 elsif ($flags =~ m/c/) {
3073 $flags_string = "Cleanup";
3075 if ($flags =~ m/r/) {
3076 if ($flags_string) { $flags_string .= " / "; }
3077 $flags_string .= "No Recursion";
3079 if ($flags =~ m/d/) {
3080 if ($flags_string) { $flags_string .= " / "; }
3081 $flags_string .= "Has Details";
3083 if ($flags =~ m/a/) {
3084 if ($flags_string) { $flags_string .= " / "; }
3085 $flags_string .= "Action";
3087 if ($flags =~ m/h/) {
3088 if ($flags_string) { $flags_string .= " / "; }
3089 $flags_string .= "No Hooks";
3095 $synop .= ": $flags_string\n";
3097 $pad = ' ' x (5 + $name_len - length("user_data"));
3098 $desc .= "$pad : $flags_string</programlisting>\n";
3103 $desc .= "</programlisting>\n";
3106 $desc .= &MakeDeprecationNote($symbol);
3108 my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
3109 my $parameters_output = 0;
3111 $AllSymbols{$symbol} = 1;
3112 if (defined ($SymbolDocs{$symbol})) {
3113 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3115 # Try to insert the parameter table at the author's desired
3116 # position. Otherwise we need to tag it onto the end.
3117 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
3118 $parameters_output = 1;
3120 $desc .= $symbol_docs;
3122 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
3123 $AllDocumentedSymbols{$symbol} = 1;
3127 if ($parameters_output == 0) {
3128 $desc .= $parameters;
3130 $desc .= OutputSymbolTraits ($symbol);
3131 $desc .= "</refsect2>";
3134 return ($synop, $desc);
3138 #############################################################################
3139 # Function : GetArgs
3140 # Description : Returns the synopsis and detailed description DocBook output
3141 # for the Args of a given GtkObject subclass.
3142 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
3143 #############################################################################
3149 my $child_synop = "";
3150 my $child_desc = "";
3151 my $style_synop = "";
3152 my $style_desc = "";
3155 for ($i = 0; $i <= $#ArgObjects; $i++) {
3156 if ($ArgObjects[$i] eq $object) {
3157 #print "Found arg: $ArgNames[$i]\n";
3158 my $name = $ArgNames[$i];
3159 my $flags = $ArgFlags[$i];
3160 my $flags_string = "";
3164 if ($flags =~ m/c/) {
3165 $kind = "child property";
3168 elsif ($flags =~ m/s/) {
3169 $kind = "style property";
3176 # Remember only one colon so we don't clash with signals.
3177 my $symbol = "${object}:${name}";
3178 # use two dashes and ev. an extra separator here for the same reason.
3179 my $id = &CreateValidSGMLID ("$object--$id_sep$name");
3181 my $type = $ArgTypes[$i];
3183 my $range = $ArgRanges[$i];
3184 my $range_output = CreateValidSGML ($range);
3185 my $default = $ArgDefaults[$i];
3186 my $default_output = CreateValidSGML ($default);
3188 if ($type eq "GtkString") {
3191 if ($type eq "GtkSignal") {
3192 $type = "GtkSignalFunc, gpointer";
3193 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
3194 . &MakeXRef ("gpointer");
3195 } elsif ($type =~ m/^(\w+)\*$/) {
3196 $type_output = &MakeXRef ($1, &tagify($1, "type")) . "*";
3198 $type_output = &MakeXRef ($type, &tagify($type, "type"));
3201 if ($flags =~ m/r/) {
3202 $flags_string = "Read";
3204 if ($flags =~ m/w/) {
3205 if ($flags_string) { $flags_string .= " / "; }
3206 $flags_string .= "Write";
3208 if ($flags =~ m/x/) {
3209 if ($flags_string) { $flags_string .= " / "; }
3210 $flags_string .= "Construct";
3212 if ($flags =~ m/X/) {
3213 if ($flags_string) { $flags_string .= " / "; }
3214 $flags_string .= "Construct Only";
3217 $AllSymbols{$symbol} = 1;
3219 if (defined($SymbolDocs{$symbol}) &&
3220 !IsEmptyDoc($SymbolDocs{$symbol})) {
3221 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3222 #print ".. [$SymbolDocs{$symbol}][$blurb]\n";
3223 $AllDocumentedSymbols{$symbol} = 1;
3226 if (!($ArgBlurbs[$i] eq "")) {
3227 $AllDocumentedSymbols{$symbol} = 1;
3229 # FIXME: print a warning?
3230 #print ".. no description\n";
3232 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
3235 my $pad1 = " " x (24 - length ($name));
3236 my $pad2 = " " x (20 - length ($type));
3238 my $arg_synop = " "<link linkend=\"$id\">$name</link>"$pad1 $type_output $pad2 : $flags_string\n";
3239 my $arg_desc = "<refsect2 id=\"$id\" role=\"property\"><title>The <literal>"$name"</literal> $kind</title>\n";
3240 $arg_desc .= MakeIndexterms($symbol, $id);
3242 $arg_desc .= OutputSymbolExtraLinks($symbol);
3244 $arg_desc .= "<programlisting> "$name"$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
3245 $arg_desc .= &MakeDeprecationNote($symbol);
3246 $arg_desc .= $blurb;
3248 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
3250 if ($default ne "") {
3251 $arg_desc .= "<para>Default value: $default_output</para>\n";
3253 $arg_desc .= OutputSymbolTraits ($symbol);
3254 $arg_desc .= "</refsect2>\n";
3256 if ($flags =~ m/c/) {
3257 $child_synop .= $arg_synop;
3258 $child_desc .= $arg_desc;
3260 elsif ($flags =~ m/s/) {
3261 $style_synop .= $arg_synop;
3262 $style_desc .= $arg_desc;
3265 $synop .= $arg_synop;
3270 return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
3274 #############################################################################
3275 # Function : ReadSourceDocumentation
3276 # Description : This reads in the documentation embedded in comment blocks
3277 # in the source code (for Gnome).
3279 # Parameter descriptions override any in the template files.
3280 # Function descriptions are placed before any description from
3281 # the template files.
3283 # It recursively descends the source directory looking for .c
3284 # files and scans them looking for specially-formatted comment
3287 # Arguments : $source_dir - the directory to scan.
3288 #############m###############################################################
3290 sub ReadSourceDocumentation {
3291 my ($source_dir) = @_;
3292 my ($file, $dir, @suffix_list, $suffix);
3293 #print "Scanning source directory: $source_dir\n";
3295 # This array holds any subdirectories found.
3298 @suffix_list = split (/,/, $SOURCE_SUFFIXES);
3300 opendir (SRCDIR, $source_dir)
3301 || die "Can't open source directory $source_dir: $!";
3303 foreach $file (readdir (SRCDIR)) {
3304 if ($file =~ /^\./) {
3306 } elsif (-d "$source_dir/$file") {
3307 push (@subdirs, $file);
3308 } elsif (@suffix_list) {
3309 foreach $suffix (@suffix_list) {
3310 if ($file =~ m/\.\Q${suffix}\E$/) {
3311 &ScanSourceFile ("$source_dir/$file");
3314 } elsif ($file =~ m/\.[ch]$/) {
3315 &ScanSourceFile ("$source_dir/$file");
3320 # Now recursively scan the subdirectories.
3321 foreach $dir (@subdirs) {
3322 next if ($IGNORE_FILES =~ m/(\s|^)\Q${dir}\E(\s|$)/);
3323 &ReadSourceDocumentation ("$source_dir/$dir");
3328 #############################################################################
3329 # Function : ScanSourceFile
3330 # Description : Scans one source file looking for specially-formatted comment
3331 # blocks. Later &MergeSourceDocumentation is used to merge any
3332 # documentation found with the documentation already read in
3333 # from the template files.
3335 # Arguments : $file - the file to scan.
3336 #############################################################################
3338 sub ScanSourceFile {
3342 if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
3345 &LogWarning ($file, 1, "Can't find basename for this filename.");
3349 # Check if the basename is in the list of files to ignore.
3350 if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
3354 #print "DEBUG: Scanning $file\n";
3356 open (SRCFILE, $file)
3357 || die "Can't open $file: $!";
3358 my $in_comment_block = 0;
3360 my ($in_description, $in_return, $in_since, $in_stability, $in_deprecated);
3361 my ($description, $return_desc, $return_start, $return_style);
3362 my ($since_desc, $stability_desc, $deprecated_desc);
3364 my $ignore_broken_returns;
3367 # Look for the start of a comment block.
3368 if (!$in_comment_block) {
3369 if (m%^\s*/\*.*\*/%) {
3370 #one-line comment - not gtkdoc
3371 } elsif (m%^\s*/\*\*\s%) {
3372 #print "Found comment block start\n";
3374 $in_comment_block = 1;
3376 # Reset all the symbol data.
3378 $in_description = 0;
3387 $deprecated_desc = "";
3388 $stability_desc = "";
3389 $current_param = -1;
3390 $ignore_broken_returns = 0;
3396 # We're in a comment block. Check if we've found the end of it.
3399 # maybe its not even meant to be a gtk-doc comment?
3400 &LogWarning ($file, $., "Symbol name not found at the start of the comment block.");
3402 # Add the return value description onto the end of the params.
3404 push (@params, "Returns");
3405 push (@params, $return_desc);
3406 if ($return_style eq 'broken') {
3407 &LogWarning ($file, $., "Free-form return value description in $symbol. Use `Returns:' to avoid ambiguities.");
3410 # Convert special SGML characters
3411 $description = &ConvertSGMLChars ($symbol, $description);
3413 for ($k = 1; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3414 $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
3417 # Handle Section docs
3418 if ($symbol =~ m/SECTION:\s*(.*)/) {
3422 if (scalar %KnownSymbols) {
3423 if ((! defined($KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"})) || $KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"} != 1) {
3424 &LogWarning ($file, $., "Section $real_symbol is not defined in the $MODULE-section.txt file.");
3428 #print "SECTION DOCS found in source for : '$real_symbol'\n";
3429 $ignore_broken_returns = 1;
3430 for ($k = 0; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3431 #print " '".$params[$k]."'\n";
3432 $params[$k] = "\L$params[$k]";
3434 if ($params[$k] eq "short_description") {
3435 $key = "$TMPL_DIR/$real_symbol:Short_Description";
3436 } elsif ($params[$k] eq "see_also") {
3437 $key = "$TMPL_DIR/$real_symbol:See_Also";
3438 } elsif ($params[$k] eq "title") {
3439 $key = "$TMPL_DIR/$real_symbol:Title";
3440 } elsif ($params[$k] eq "stability") {
3441 $key = "$TMPL_DIR/$real_symbol:Stability_Level";
3442 } elsif ($params[$k] eq "section_id") {
3443 $key = "$TMPL_DIR/$real_symbol:Section_Id";
3444 } elsif ($params[$k] eq "include") {
3445 $key = "$TMPL_DIR/$real_symbol:Include";
3447 if (defined($key)) {
3448 $SourceSymbolDocs{$key}=$params[$k+1];
3449 $SourceSymbolSourceFile{$key} = $file;
3450 $SourceSymbolSourceLine{$key} = $.;
3453 $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
3454 $SourceSymbolSourceFile{"$TMPL_DIR/$real_symbol:Long_Description"} = $file;
3455 $SourceSymbolSourceLine{"$TMPL_DIR/$real_symbol:Long_Description"} = $.;
3456 #$SourceSymbolTypes{$symbol} = "SECTION";
3458 #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
3459 $SourceSymbolDocs{$symbol} = $description;
3460 $SourceSymbolParams{$symbol} = [ @params ];
3461 # FIXME $SourceSymbolTypes{$symbol} = "STRUCT,SIGNAL,ARG,FUNCTION,MACRO";
3462 #if (defined $DeclarationTypes{$symbol}) {
3463 # $SourceSymbolTypes{$symbol} = $DeclarationTypes{$symbol}
3465 $SourceSymbolSourceFile{$symbol} = $file;
3466 $SourceSymbolSourceLine{$symbol} = $.;
3470 ($since_desc, my @extra_lines) = split ("\n", $since_desc);
3471 $since_desc =~ s/^\s+//;
3472 $since_desc =~ s/\s+$//;
3473 #print "Since($symbol) : [$since_desc]\n";
3474 $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
3475 if(scalar @extra_lines) {
3476 &LogWarning ($file, $., "multi-line since docs found");
3480 if ($stability_desc) {
3481 $stability_desc = &ParseStabilityLevel($stability_desc, $file, $., "Stability level for $symbol");
3482 $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
3485 if ($deprecated_desc) {
3486 if (exists $Deprecated{$symbol}) {
3489 # don't warn for signals and properties
3490 #if ($symbol !~ m/::?(.*)/) {
3491 if (defined $DeclarationTypes{$symbol}) {
3492 &LogWarning ($file, $.,
3493 "$symbol is deprecated in the inline comments, but no deprecation guards were found around the declaration.".
3494 " (See the --deprecated-guards option for gtkdoc-scan.)");
3497 $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
3501 $in_comment_block = 0;
3505 # Get rid of ' * ' at start of every line in the comment block.
3507 # But make sure we don't get rid of the newline at the end.
3511 #print "DEBUG: scanning :$_";
3513 # If we haven't found the symbol name yet, look for it.
3515 if (m%^\s*(SECTION:\s*\S+)%) {
3517 #print "SECTION DOCS found in source for : '$symbol'\n";
3518 $ignore_broken_returns = 1;
3519 } elsif (m%^\s*([\w:-]*\w)\s*:?\s*$%) {
3521 #print "SYMBOL DOCS found in source for : '$symbol'\n";
3526 # If we're in the return value description, add it to the end.
3528 # If we find another valid returns line, we assume that the first
3529 # one was really part of the description.
3530 if (m/^\s*(returns:|return\s+value:)/i) {
3531 if ($return_style eq 'broken') {
3532 $description .= $return_start . $return_desc;
3535 if ($return_style eq 'sane') {
3536 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3538 $return_style = 'sane';
3539 $ignore_broken_returns = 1;
3541 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3542 $description .= $return_start . $return_desc;
3544 $return_style = 'broken';
3546 } elsif (m%^\s*since:%i) {
3550 } elsif (m%^\s*stability:%i) {
3551 $stability_desc = $';
3554 } elsif (m%^\s*deprecated:%i) {
3555 $deprecated_desc = $';
3565 if (m/^\s*(returns:|return\s+value:)/i) {
3566 if ($return_style eq 'broken') {
3567 $description .= $return_start . $return_desc;
3570 if ($return_style eq 'sane') {
3571 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3573 $return_style = 'sane';
3574 $ignore_broken_returns = 1;
3578 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3580 $return_style = 'broken';
3584 } elsif (m%^\s*deprecated:%i) {
3585 $deprecated_desc = $';
3588 } elsif (m%^\s*stability:%i) {
3589 $stability_desc = $';
3598 if ($in_stability) {
3599 if (m/^\s*(returns:|return\s+value:)/i) {
3600 if ($return_style eq 'broken') {
3601 $description .= $return_start . $return_desc;
3604 if ($return_style eq 'sane') {
3605 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3607 $return_style = 'sane';
3608 $ignore_broken_returns = 1;
3612 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3614 $return_style = 'broken';
3618 } elsif (m%^\s*deprecated:%i) {
3619 $deprecated_desc = $';
3622 } elsif (m%^\s*since:%i) {
3627 $stability_desc .= $_;
3632 if ($in_deprecated) {
3633 if (m/^\s*(returns:|return\s+value:)/i) {
3634 if ($return_style eq 'broken') {
3635 $description .= $return_start . $return_desc;
3638 if ($return_style eq 'sane') {
3639 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3641 $return_style = 'sane';
3642 $ignore_broken_returns = 1;
3646 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3648 $return_style = 'broken';
3652 } elsif (m%^\s*since:%i) {
3656 } elsif (m%^\s*stability:%i) {
3657 $stability_desc = $';
3661 $deprecated_desc .= $_;
3666 # If we're in the description part, check for the 'Returns:' line.
3667 # If that isn't found, add the text to the end.
3668 if ($in_description) {
3669 # Get rid of 'Description:'
3670 s%^\s*Description:%%;
3672 if (m/^\s*(returns:|return\s+value:)/i) {
3673 if ($return_style eq 'broken') {
3674 $description .= $return_start . $return_desc;
3677 if ($return_style eq 'sane') {
3678 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3680 $return_style = 'sane';
3681 $ignore_broken_returns = 1;
3685 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3687 $return_style = 'broken';
3691 } elsif (m%^\s*since:%i) {
3695 } elsif (m%^\s*deprecated:%i) {
3696 $deprecated_desc = $';
3699 } elsif (m%^\s*stability:%i) {
3700 $stability_desc = $';
3709 # We must be in the parameters. Check for the empty line below them.
3711 $in_description = 1;
3715 # Look for a parameter name.
3716 if (m%^\s*@(\S+)\s*:%) {
3717 my $param_name = $1;
3718 my $param_desc = $';
3719 #print "Found parameter: $param_name\n";
3720 # Allow '...' as the Varargs parameter.
3721 if ($param_name eq "...") {
3722 $param_name = "Varargs";
3724 if ("\L$param_name" eq "returns") {
3725 $return_style = 'sane';
3726 $ignore_broken_returns = 1;
3728 push (@params, $param_name);
3729 push (@params, $param_desc);
3730 $current_param += $PARAM_FIELD_COUNT;
3734 # We must be in the middle of a parameter description, so add it on
3735 # to the last element in @params.
3736 if ($current_param == -1) {
3737 &LogWarning ($file, $., "Parsing comment block file : parameter expected.");
3739 $params[$#params] .= $_;
3745 #############################################################################
3746 # Function : OutputMissingDocumentation
3747 # Description : Outputs report of documentation coverage to a file
3750 #############################################################################
3752 sub OutputMissingDocumentation {
3753 my $n_documented = 0;
3754 my $n_incomplete = 0;
3760 my $buffer_deprecated = "";
3761 my $buffer_descriptions = "";
3763 open (UNDOCUMENTED, ">$ROOT_DIR/$MODULE-undocumented.txt")
3764 || die "Can't create $ROOT_DIR/$MODULE-undocumented.txt: $!";
3766 foreach $symbol (sort (keys (%AllSymbols))) {
3767 # FIXME: should we print LogWarnings for undocumented stuff?
3769 #my $ssfile = &GetSymbolSourceFile($symbol);
3770 #my $ssline = &GetSymbolSourceLine($symbol);
3771 #my $location = "defined at " . (defined($ssfile)?$ssfile:"?") . ":" . (defined($ssline)?$ssline:"0") . "\n";
3773 if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include|Section_Id)/) {
3775 if (exists ($AllDocumentedSymbols{$symbol})) {
3777 if (exists ($AllIncompleteSymbols{$symbol})) {
3779 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3780 #$buffer .= "\t0: ".$location;
3782 } elsif (exists $Deprecated{$symbol}) {
3783 if (exists ($AllIncompleteSymbols{$symbol})) {
3785 $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3786 #$buffer .= "\t1a: ".$location;
3788 $buffer_deprecated .= $symbol . "\n";
3789 #$buffer .= "\t1b: ".$location;
3792 if (exists ($AllIncompleteSymbols{$symbol})) {
3794 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3795 #$buffer .= "\t2a: ".$location;
3797 $buffer .= $symbol . "\n";
3798 #$buffer .= "\t2b: ".$location;
3801 } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
3803 #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
3804 #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
3805 #print "%%%% $symbol : $len1,$len2\n";
3806 if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
3807 || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
3810 # cut off the leading namespace ($TMPL_DIR)
3811 $symbol =~ m/^.*\/(.*)$/;
3812 $buffer_descriptions .= $1 . "\n";
3817 $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
3822 $percent = ($n_documented / $total) * 100.0;
3825 printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
3826 print UNDOCUMENTED "$n_documented symbols documented.\n";
3827 print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
3828 print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
3830 print UNDOCUMENTED $buffer;
3832 close (UNDOCUMENTED);
3834 printf (("%.0f%% symbol docs coverage ($n_documented symbols documented, $n_incomplete symbols incomplete, " . ($total - $n_documented) . " not documented)\nSee $MODULE-undocumented.txt for a list of missing docs.\nThe doc coverage percentage doesn't include intro sections.\n"), $percent);
3838 #############################################################################
3839 # Function : OutputUndeclaredSymbols
3840 # Description : Outputs symbols that are undeclared yet documented to a file
3843 #############################################################################
3845 sub OutputUndeclaredSymbols {
3846 open(UNDECLARED, ">$ROOT_DIR/$MODULE-undeclared.txt")
3847 || die "Can't create $ROOT_DIR/$MODULE-undeclared.txt";
3849 if (%UndeclaredSymbols) {
3850 print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
3851 print UNDECLARED "\n";
3852 print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
3858 #############################################################################
3859 # Function : OutputAllSymbols
3860 # Description : Outputs list of all symbols to a file
3863 #############################################################################
3865 sub OutputAllSymbols {
3866 my $n_documented = 0;
3872 open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
3873 || die "Can't create $ROOT_DIR/$MODULE-symbols.txt: $!";
3875 foreach $symbol (sort (keys (%AllSymbols))) {
3876 print SYMBOLS $symbol . "\n";
3882 #############################################################################
3883 # Function : OutputSymbolsWithoutSince
3884 # Description : Outputs list of all symbols without a since tag to a file
3887 #############################################################################
3889 sub OutputSymbolsWithoutSince {
3890 my $n_documented = 0;
3896 open (SYMBOLS, ">$ROOT_DIR/$MODULE-nosince.txt")
3897 || die "Can't create $ROOT_DIR/$MODULE-nosince.txt: $!";
3899 foreach $symbol (sort (keys (%SourceSymbolDocs))) {
3900 if (!defined $Since{$symbol}) {
3901 print SYMBOLS $symbol . "\n";
3909 #############################################################################
3910 # Function : MergeSourceDocumentation
3911 # Description : This merges documentation read from a source file into the
3912 # documentation read in from a template file.
3914 # Parameter descriptions override any in the template files.
3915 # Function descriptions are placed before any description from
3916 # the template files.
3919 #############################################################################
3921 sub MergeSourceDocumentation {
3925 if (scalar %SymbolDocs) {
3926 @Symbols=keys (%SymbolDocs);
3927 #print "num existing entries: ".(scalar @Symbols)."\n";
3928 #print " ",$Symbols[0], " ",$Symbols[1],"\n";
3931 # filter scanned declarations, with what we suppress from -sections.txt
3933 foreach $symbol (keys (%Declarations)) {
3934 if (defined($KnownSymbols{$symbol}) && $KnownSymbols{$symbol} == 1) {
3938 # , add the rest from -sections.txt
3939 foreach $symbol (keys (%KnownSymbols)) {
3940 if ($KnownSymbols{$symbol} == 1) {
3944 # and add whats found in the source
3945 foreach $symbol (keys (%SourceSymbolDocs)) {
3948 @Symbols = keys (%tmp);
3949 #print "num source entries: ".(scalar @Symbols)."\n";
3951 foreach $symbol (@Symbols) {
3952 $AllSymbols{$symbol} = 1;
3954 my $have_tmpl_docs = 0;
3956 ## See if the symbol is documented in template
3957 my $tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
3958 my $check_tmpl_doc =$tmpl_doc;
3959 # remove all xml-tags and whitespaces
3960 #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
3961 $check_tmpl_doc =~ s/<.*?>//g;
3962 $check_tmpl_doc =~ s/\s//g;
3964 if ($check_tmpl_doc ne "") {
3965 $have_tmpl_docs = 1;
3966 #print "## [$check_tmpl_doc]\n";
3971 if (exists ($SourceSymbolDocs{$symbol})) {
3972 my $type = $DeclarationTypes {$symbol};
3974 #print "merging [$symbol] from source\n";
3976 my $item = "Parameter";
3977 if (defined ($type)) {
3978 if ($type eq 'STRUCT') {
3980 } elsif ($type eq 'ENUM') {
3982 } elsif ($type eq 'UNION') {
3989 my $src_doc = $SourceSymbolDocs{$symbol};
3990 # remove leading and training whitespaces
3991 $src_doc =~ s/^\s+//;
3992 $src_doc =~ s/\s+$//;
3994 # Don't output warnings for overridden titles as titles are
3995 # automatically generated in the -sections.txt file, and thus they
3996 # are often overridden.
3997 if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
3998 # check if content is different
3999 if ($tmpl_doc ne $src_doc) {
4000 #print "[$tmpl_doc] [$src_doc]\n";
4001 &LogWarning ($SourceSymbolSourceFile{$symbol}, $SourceSymbolSourceLine{$symbol},
4002 "Documentation in template ".$SymbolSourceFile{$symbol}.":".$SymbolSourceLine{$symbol}." for $symbol being overridden by inline comments.");
4006 if ($src_doc ne "") {
4007 $AllDocumentedSymbols{$symbol} = 1;
4010 # Convert <!--PARAMETERS--> with any blank lines around it to
4011 # a </para> followed by <!--PARAMETERS--> followed by <para>.
4012 $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
4014 # If there is a blank line, finish the paragraph and start another.
4015 $src_doc = &ConvertBlankLines ($src_doc, $symbol);
4016 # Do not add <para> to nothing, it breaks missing docs checks.
4017 my $src_doc_para = "";
4019 $src_doc_para = "<para>\n$src_doc</para>\n";
4020 #print "$symbol : [$src_doc][$src_doc_para]\n";
4023 if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
4024 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4025 } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
4026 # For the title/summary/see also section docs we don't want to
4027 # add any <para> tags.
4028 $SymbolDocs{$symbol} = "$src_doc"
4030 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4034 if ($symbol =~ m/.*::.*/) {
4035 # For signals we prefer the param names from the source docs,
4036 # since the ones from the templates are likely to contain the
4037 # artificial argn names which are generated by gtkdoc-scangobj.
4038 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4039 # FIXME: we need to check for empty docs here as well!
4041 # The templates contain the definitive parameter names and order,
4042 # so we will not change that. We only override the actual text.
4043 my $tmpl_params = $SymbolParams{$symbol};
4044 if (!defined ($tmpl_params)) {
4045 #print "No merge needed for $symbol\n";
4046 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4047 # FIXME: we still like to get the number of params and merge
4048 # 1) we would noticed that params have been removed/renamed
4049 # 2) we would catch undocumented params
4050 # params are not (yet) exported in -decl.txt so that we
4051 # could easily grab them :/
4053 my $params = $SourceSymbolParams{$symbol};
4055 #print "Merge needed for $symbol, tmpl_params: ",$#$tmpl_params,", source_params: ",$#$params," \n";
4056 for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4057 my $tmpl_param_name = $$tmpl_params[$j];
4059 # Allow '...' as the Varargs parameter.
4060 if ($tmpl_param_name eq "...") {
4061 $tmpl_param_name = "Varargs";
4064 # Try to find the param in the source comment documentation.
4067 #print " try merge param $tmpl_param_name\n";
4068 for ($k = 0; $k <= $#$params; $k += $PARAM_FIELD_COUNT) {
4069 my $param_name = $$params[$k];
4070 my $param_desc = $$params[$k + 1];
4072 #print " test param $param_name\n";
4073 # We accept changes in case, since the Gnome source
4074 # docs contain a lot of these.
4075 if ("\L$param_name" eq "\L$tmpl_param_name") {
4078 # Override the description.
4079 $$tmpl_params[$j + 1] = $param_desc;
4081 # Set the name to "" to mark it as used.
4087 # If it looks like the parameters are there, but not
4088 # in the right place, try to explain a bit better.
4089 if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
4090 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4091 "Parameters for $symbol must start on the line immediately after the function or macro name.");
4095 # Now we output a warning if parameters have been described which
4097 for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
4098 my $param_name = $$params[$j];
4100 # the template builder cannot detect if a macro returns
4102 if(($type eq "MACRO") && ($param_name eq "Returns")) {
4103 # FIXME: do we need to add it then to tmpl_params[] ?
4104 my $num=$#$tmpl_params;
4105 #print " adding Returns: to macro docs for $symbol.\n";
4106 $$tmpl_params[$num+1]="Returns";
4107 $$tmpl_params[$num+2]=$$params[$j+1];
4110 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4111 "$item described in source code comment block but does not exist. $type: $symbol $item: $param_name.");
4117 if ($have_tmpl_docs) {
4118 $AllDocumentedSymbols{$symbol} = 1;
4119 #print "merging [$symbol] from template\n";
4122 #print "[$symbol] undocumented\n";
4126 # if this symbol is documented, check if docs are complete
4127 $check_tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4128 # remove all xml-tags and whitespaces
4129 #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
4130 $check_tmpl_doc =~ s/<.*?>//g;
4131 $check_tmpl_doc =~ s/\s//g;
4132 if ($check_tmpl_doc ne "") {
4133 my $tmpl_params = $SymbolParams{$symbol};
4134 if (defined ($tmpl_params)) {
4135 my $type = $DeclarationTypes {$symbol};
4137 my $item = "Parameter";
4138 if (defined ($type)) {
4139 if ($type eq 'STRUCT') {
4141 } elsif ($type eq 'ENUM') {
4143 } elsif ($type eq 'UNION') {
4150 #print "Check param docs for $symbol, tmpl_params: ",$#$tmpl_params," entries, type=$type\n";
4152 if ($#$tmpl_params > 0) {
4154 for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4155 # Output a warning if the parameter is empty and
4156 # remember for stats.
4157 my $tmpl_param_name = $$tmpl_params[$j];
4158 my $tmpl_param_desc = $$tmpl_params[$j + 1];
4159 if ($tmpl_param_desc !~ m/\S/) {
4160 if (exists ($AllIncompleteSymbols{$symbol})) {
4161 $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
4163 $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
4165 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4166 "$item description for $symbol"."::"."$tmpl_param_name is missing in source code comment block.");
4171 if ($#$tmpl_params == 0) {
4172 $AllIncompleteSymbols{$symbol}="<items>";
4173 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4174 "$item descriptions for $symbol are missing in source code comment block.");
4176 # $#$tmpl_params==-1 means we don't know about parameters
4177 # this unfortunately does not tell if there should be some
4182 #print "num doc entries: ".(scalar %SymbolDocs)."\n";
4185 #############################################################################
4186 # Function : IsEmptyDoc
4187 # Description : Check if a doc-string is empty. Its also regarded as empty if
4188 # it only consist of whitespace or e.g. FIXME.
4189 # Arguments : the doc-string
4190 #############################################################################
4194 if ($doc =~ /^\s*$/) {
4198 if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
4206 # This converts blank lines to "</para><para>", but only outside CDATA and
4207 # <programlisting> tags.
4208 sub ConvertBlankLines {
4209 return &ModifyXMLElements ($_[0], $_[1],
4210 "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
4211 \&ConvertBlankLinesEndTag,
4212 \&ConvertBlankLinesCallback);
4216 sub ConvertBlankLinesEndTag {
4217 if ($_[0] eq "<!\[CDATA\[") {
4219 } elsif ($_[0] eq "|[") {
4222 return "</programlisting>";
4226 sub ConvertBlankLinesCallback {
4227 my ($text, $symbol, $tag) = @_;
4229 # If we're not in CDATA or a <programlisting> we convert blank lines so
4230 # they start a new <para>.
4232 $text =~ s%\n{2,}%\n</para>\n<para>\n%g;
4239 #############################################################################
4240 # LIBRARY FUNCTIONS - These functions are used in both gtkdoc-mkdb and
4241 # gtkdoc-mktmpl and should eventually be moved to a
4243 #############################################################################
4245 #############################################################################
4246 # Function : ReadDeclarationsFile
4247 # Description : This reads in a file containing the function/macro/enum etc.
4250 # Note that in some cases there are several declarations with
4251 # the same name, e.g. for conditional macros. In this case we
4252 # set a flag in the %DeclarationConditional hash so the
4253 # declaration is not shown in the docs.
4255 # If a macro and a function have the same name, e.g. for
4256 # gtk_object_ref, the function declaration takes precedence.
4258 # Some opaque structs are just declared with 'typedef struct
4259 # _name name;' in which case the declaration may be empty.
4260 # The structure may have been found later in the header, so
4261 # that overrides the empty declaration.
4263 # Arguments : $file - the declarations file to read
4264 # $override - if declarations in this file should override
4265 # any current declaration.
4266 #############################################################################
4268 sub ReadDeclarationsFile {
4269 my ($file, $override) = @_;
4271 if ($override == 0) {
4273 %DeclarationTypes = ();
4274 %DeclarationConditional = ();
4275 %DeclarationOutput = ();
4279 || die "Can't open $file: $!";
4280 my $declaration_type = "";
4281 my $declaration_name;
4283 my $is_deprecated = 0;
4285 if (!$declaration_type) {
4286 if (m/^<([^>]+)>/) {
4287 $declaration_type = $1;
4288 $declaration_name = "";
4289 #print "Found declaration: $declaration_type\n";
4293 if (m%^<NAME>(.*)</NAME>%) {
4294 $declaration_name = $1;
4295 } elsif (m%^<DEPRECATED/>%) {
4297 } elsif (m%^</$declaration_type>%) {
4298 #print "Found end of declaration: $declaration_name\n";
4299 # Check that the declaration has a name
4300 if ($declaration_name eq "") {
4301 print "ERROR: $declaration_type has no name $file:$.\n";
4304 # If the declaration is an empty typedef struct _XXX XXX
4305 # set the flag to indicate the struct has a typedef.
4306 if ($declaration_type eq 'STRUCT'
4307 && $declaration =~ m/^\s*$/) {
4308 #print "Struct has typedef: $declaration_name\n";
4309 $StructHasTypedef{$declaration_name} = 1;
4312 # Check if the symbol is already defined.
4313 if (defined ($Declarations{$declaration_name})
4314 && $override == 0) {
4315 # Function declarations take precedence.
4316 if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
4318 } elsif ($declaration_type eq 'FUNCTION') {
4319 if ($is_deprecated) {
4320 $Deprecated{$declaration_name} = "";
4322 $Declarations{$declaration_name} = $declaration;
4323 $DeclarationTypes{$declaration_name} = $declaration_type;
4324 } elsif ($DeclarationTypes{$declaration_name}
4325 eq $declaration_type) {
4326 # If the existing declaration is empty, or is just a
4327 # forward declaration of a struct, override it.
4328 if ($declaration_type eq 'STRUCT') {
4329 if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4330 if ($is_deprecated) {
4331 $Deprecated{$declaration_name} = "";
4333 $Declarations{$declaration_name} = $declaration;
4334 } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4335 # Ignore an empty or forward declaration.
4337 &LogWarning ($file, $., "Structure $declaration_name has multiple definitions.");
4340 # set flag in %DeclarationConditional hash for
4341 # multiply defined macros/typedefs.
4342 $DeclarationConditional{$declaration_name} = 1;
4345 &LogWarning ($file, $., "$declaration_name has multiple definitions.");
4348 if ($is_deprecated) {
4349 $Deprecated{$declaration_name} = "";
4351 $Declarations{$declaration_name} = $declaration;
4352 $DeclarationTypes{$declaration_name} = $declaration_type;
4355 $declaration_type = "";
4366 #############################################################################
4367 # Function : ReadSignalsFile
4368 # Description : This reads in an existing file which contains information on
4369 # all GTK signals. It creates the arrays @SignalNames and
4370 # @SignalPrototypes containing info on the signals. The first
4371 # line of the SignalPrototype is the return type of the signal
4372 # handler. The remaining lines are the parameters passed to it.
4373 # The last parameter, "gpointer user_data" is always the same
4374 # so is not included.
4375 # Arguments : $file - the file containing the signal handler prototype
4377 #############################################################################
4379 sub ReadSignalsFile {
4387 my $signal_prototype;
4389 # Reset the signal info.
4390 @SignalObjects = ();
4392 @SignalReturns = ();
4394 @SignalPrototypes = ();
4399 if (!open (INPUT, $file)) {
4400 warn "Can't open $file - skipping signals\n";
4407 $signal_object = "";
4409 $signal_returns = "";
4410 $signal_prototype = "";
4413 if (m/^<NAME>(.*)<\/NAME>/) {
4415 if ($signal_name =~ m/^(.*)::(.*)$/) {
4416 $signal_object = $1;
4417 ($signal_name = $2) =~ s/_/-/g;
4418 #print "Found signal: $signal_name\n";
4420 &LogWarning ($file, $., "Invalid signal name: $signal_name.");
4422 } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
4423 $signal_returns = $1;
4424 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4426 } elsif (m%^</SIGNAL>%) {
4427 #print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
4428 push (@SignalObjects, $signal_object);
4429 push (@SignalNames, $signal_name);
4430 push (@SignalReturns, $signal_returns);
4431 push (@SignalFlags, $signal_flags);
4432 push (@SignalPrototypes, $signal_prototype);
4435 $signal_prototype .= $_;
4443 #############################################################################
4444 # Function : ReadTemplateFile
4445 # Description : This reads in the manually-edited documentation file
4446 # corresponding to the file currently being created, so we can
4447 # insert the documentation at the appropriate places.
4448 # It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
4449 # is a hash of arrays.
4450 # NOTE: This function is duplicated in gtkdoc-mktmpl (but
4451 # slightly different).
4452 # Arguments : $docsfile - the template file to read in.
4453 # $skip_unused_params - 1 if the unused parameters should be
4455 #############################################################################
4457 sub ReadTemplateFile {
4458 my ($docsfile, $skip_unused_params) = @_;
4460 my $template = "$docsfile.sgml";
4461 if (! -f $template) {
4462 #print "File doesn't exist: $template\n";
4465 #print "Reading $template\n";
4467 # start with empty hashes, we merge the source comment for each file
4473 my $current_type = ""; # Type of symbol being read.
4474 my $current_symbol = ""; # Name of symbol being read.
4475 my $symbol_doc = ""; # Description of symbol being read.
4476 my @params; # Parameter names and descriptions of current
4477 # function/macro/function typedef.
4478 my $current_param = -1; # Index of parameter currently being read.
4479 # Note that the param array contains pairs
4480 # of param name & description.
4481 my $in_unused_params = 0; # True if we are reading in the unused params.
4482 my $in_deprecated = 0;
4484 my $in_stability = 0;
4486 open (DOCS, "$template")
4487 || die "Can't open $template: $!";
4489 if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
4492 if ($symbol eq "Title"
4493 || $symbol eq "Short_Description"
4494 || $symbol eq "Long_Description"
4495 || $symbol eq "See_Also"
4496 || $symbol eq "Stability_Level"
4497 || $symbol eq "Include") {
4499 $symbol = $docsfile . ":" . $symbol;
4502 #print "Found symbol: $symbol\n";
4503 # Remember file and line for the symbol
4504 $SymbolSourceFile{$symbol} = $template;
4505 $SymbolSourceLine{$symbol} = $.;
4507 # Store previous symbol, but remove any trailing blank lines.
4508 if ($current_symbol ne "") {
4509 $symbol_doc =~ s/\s+$//;
4510 $SymbolTypes{$current_symbol} = $current_type;
4511 $SymbolDocs{$current_symbol} = $symbol_doc;
4513 # Check that the stability level is valid.
4514 if ($StabilityLevel{$current_symbol}) {
4515 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4518 if ($current_param >= 0) {
4519 $SymbolParams{$current_symbol} = [ @params ];
4521 # Delete any existing params in case we are overriding a
4522 # previously read template.
4523 delete $SymbolParams{$current_symbol};
4526 $current_type = $type;
4527 $current_symbol = $symbol;
4528 $current_param = -1;
4529 $in_unused_params = 0;
4536 } elsif (m/^<!-- # Unused Parameters # -->/) {
4537 #print "DEBUG: Found unused parameters\n";
4538 $in_unused_params = 1;
4541 } elsif ($in_unused_params && $skip_unused_params) {
4542 # When outputting the DocBook we skip unused parameters.
4543 #print "DEBUG: Skipping unused param: $_";
4547 # Check if param found. Need to handle "..." and "format...".
4548 if (s/^\@([\w\.]+):\040?//) {
4549 my $param_name = $1;
4550 my $param_desc = $_;
4551 # Allow variations of 'Returns'
4552 if ($param_name =~ m/^[Rr]eturns?$/) {
4553 $param_name = "Returns";
4556 # strip trailing whitespaces and blank lines
4559 #print "Found param for symbol $current_symbol : '$param_name'= '$_'";
4561 if ($param_name eq "Deprecated") {
4563 $Deprecated{$current_symbol} = $_;
4564 } elsif ($param_name eq "Since") {
4567 $Since{$current_symbol} = $_;
4568 } elsif ($param_name eq "Stability") {
4570 $StabilityLevel{$current_symbol} = $_;
4572 push (@params, $param_name);
4573 push (@params, $param_desc);
4574 $current_param += $PARAM_FIELD_COUNT;
4577 # strip trailing whitespaces and blank lines
4582 if ($in_deprecated) {
4583 $Deprecated{$current_symbol} .= $_;
4584 } elsif ($in_since) {
4585 &LogWarning ($template, $., "multi-line since docs found");
4586 #$Since{$current_symbol} .= $_;
4587 } elsif ($in_stability) {
4588 $StabilityLevel{$current_symbol} .= $_;
4589 } elsif ($current_param >= 0) {
4590 $params[$current_param] .= $_;
4599 # Remember to finish the current symbol doccs.
4600 if ($current_symbol ne "") {
4602 $symbol_doc =~ s/\s+$//;
4603 $SymbolTypes{$current_symbol} = $current_type;
4604 $SymbolDocs{$current_symbol} = $symbol_doc;
4606 # Check that the stability level is valid.
4607 if ($StabilityLevel{$current_symbol}) {
4608 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4611 if ($current_param >= 0) {
4612 $SymbolParams{$current_symbol} = [ @params ];
4614 # Delete any existing params in case we are overriding a
4615 # previously read template.
4616 delete $SymbolParams{$current_symbol};
4625 #############################################################################
4626 # Function : ReadObjectHierarchy
4627 # Description : This reads in the $MODULE-hierarchy.txt file containing all
4628 # the GtkObject subclasses described in this module (and their
4630 # It places them in the @Objects array, and places their level
4631 # in the widget hierarchy in the @ObjectLevels array, at the
4632 # same index. GtkObject, the root object, has a level of 1.
4634 # FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
4635 # as it goes along, this should be split out into a separate
4639 #############################################################################
4641 sub ReadObjectHierarchy {
4645 if (! -f $OBJECT_TREE_FILE) {
4648 if (!open (INPUT, $OBJECT_TREE_FILE)) {
4649 warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
4653 # FIXME: use $OUTPUT_FORMAT
4654 # my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.$OUTPUT_FORMAT";
4655 my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
4656 my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
4658 open (OUTPUT, ">$new_tree_index")
4659 || die "Can't create $new_tree_index: $!";
4661 if (lc($OUTPUT_FORMAT) eq "xml") {
4662 my $tree_header = $doctype_header;
4664 $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
4665 print (OUTPUT "$tree_header");
4667 print (OUTPUT "<screen>\n");
4669 # Only emit objects if they are supposed to be documented, or if
4670 # they have documented children. To implement this, we maintain a
4671 # stack of pending objects which will be emitted if a documented
4673 my @pending_objects = ();
4674 my @pending_levels = ();
4678 my $level = (length($`)) / 2 + 1;
4681 while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
4682 my $pobject = pop(@pending_objects);
4683 my $plevel = pop(@pending_levels);
4686 push (@pending_objects, $object);
4687 push (@pending_levels, $level);
4689 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
4690 while ($#pending_levels >= 0) {
4691 $object = shift @pending_objects;
4692 $level = shift @pending_levels;
4693 $xref = &MakeXRef ($object);
4695 print (OUTPUT ' ' x ($level * 4), "$xref\n");
4696 push (@Objects, $object);
4697 push (@ObjectLevels, $level);
4702 print (OUTPUT "</screen>\n");
4707 &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
4712 #############################################################################
4713 # Function : ReadInterfaces
4714 # Description : This reads in the $MODULE.interfaces file.
4717 #############################################################################
4719 sub ReadInterfaces {
4722 if (! -f $INTERFACES_FILE) {
4725 if (!open (INPUT, $INTERFACES_FILE)) {
4726 warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
4732 my ($object, @ifaces) = split;
4733 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
4734 my @knownIfaces = ();
4736 # filter out private interfaces, but leave foreign interfaces
4737 foreach my $iface (@ifaces) {
4738 if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
4739 push (@knownIfaces, $iface);
4743 $Interfaces{$object} = join(' ', @knownIfaces);
4749 #############################################################################
4750 # Function : ReadPrerequisites
4751 # Description : This reads in the $MODULE.prerequisites file.
4754 #############################################################################
4756 sub ReadPrerequisites {
4757 %Prerequisites = ();
4759 if (! -f $PREREQUISITES_FILE) {
4762 if (!open (INPUT, $PREREQUISITES_FILE)) {
4763 warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
4769 my ($iface, @prereqs) = split;
4770 if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
4771 my @knownPrereqs = ();
4773 # filter out private prerequisites, but leave foreign prerequisites
4774 foreach my $prereq (@prereqs) {
4775 if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
4776 push (@knownPrereqs, $prereq);
4780 $Prerequisites{$iface} = join(' ', @knownPrereqs);
4786 #############################################################################
4787 # Function : ReadArgsFile
4788 # Description : This reads in an existing file which contains information on
4789 # all GTK args. It creates the arrays @ArgObjects, @ArgNames,
4790 # @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
4792 # Arguments : $file - the file containing the arg information.
4793 #############################################################################
4808 # Reset the args info.
4821 if (!open (INPUT, $file)) {
4822 warn "Can't open $file - skipping args\n";
4839 if (m/^<NAME>(.*)<\/NAME>/) {
4841 if ($arg_name =~ m/^(.*)::(.*)$/) {
4843 ($arg_name = $2) =~ s/_/-/g;
4844 #print "Found arg: $arg_name\n";
4846 &LogWarning ($file, $., "Invalid argument name: $arg_name");
4848 } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
4850 } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
4852 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4854 } elsif (m/^<NICK>(.*)<\/NICK>/) {
4856 } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
4858 if ($arg_blurb eq "(null)") {
4860 &LogWarning ($file, $., "Property ${arg_object}:${arg_name} has no documentation.");
4862 } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
4864 } elsif (m%^</ARG>%) {
4865 #print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
4866 push (@ArgObjects, $arg_object);
4867 push (@ArgNames, $arg_name);
4868 push (@ArgTypes, $arg_type);
4869 push (@ArgRanges, $arg_range);
4870 push (@ArgFlags, $arg_flags);
4871 push (@ArgNicks, $arg_nick);
4872 push (@ArgBlurbs, $arg_blurb);
4873 push (@ArgDefaults, $arg_default);
4882 #############################################################################
4883 # Function : CheckIsObject
4884 # Description : Returns 1 if the given name is a GtkObject or a subclass.
4885 # It uses the global @Objects array.
4886 # Note that the @Objects array only contains classes in the
4887 # current module and their ancestors - not all GTK classes.
4888 # Arguments : $name - the name to check.
4889 #############################################################################
4895 foreach $object (@Objects) {
4896 if ($object eq $name) {
4904 #############################################################################
4905 # Function : MakeReturnField
4906 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
4907 # Arguments : $str - the string to pad.
4908 #############################################################################
4910 sub MakeReturnField {
4913 return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));
4916 #############################################################################
4917 # Function : GetSymbolSourceFile
4918 # Description : Get the filename where the symbol docs where taken from.
4919 # Arguments : $symbol - the symbol name
4920 #############################################################################
4922 sub GetSymbolSourceFile {
4925 if (defined($SourceSymbolSourceFile{$symbol})) {
4926 return $SourceSymbolSourceFile{$symbol};
4927 } elsif (defined($SymbolSourceFile{$symbol})) {
4928 return $SymbolSourceFile{$symbol};
4934 #############################################################################
4935 # Function : GetSymbolSourceLine
4936 # Description : Get the file line where the symbol docs where taken from.
4937 # Arguments : $symbol - the symbol name
4938 #############################################################################
4940 sub GetSymbolSourceLine {
4943 if (defined($SourceSymbolSourceLine{$symbol})) {
4944 return $SourceSymbolSourceLine{$symbol};
4945 } elsif (defined($SymbolSourceLine{$symbol})) {
4946 return $SymbolSourceLine{$symbol};