4 # gtk-doc - GTK DocBook documentation generator.
5 # Copyright (C) 1998 Damon Chaplin
6 # 2007,2008,2009 Stefan Kost
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #############################################################################
24 # Script : gtkdoc-mkdb
25 # Description : This creates the DocBook files from the edited templates.
26 #############################################################################
31 push @INC, '@PACKAGE_DATA_DIR@';
32 require "gtkdoc-common.pl";
36 # name of documentation module
41 my $SOURCE_SUFFIXES = "";
42 my $IGNORE_FILES = "";
46 my $EXPAND_CONTENT_FILES = "";
48 my $DEFAULT_STABILITY;
52 my $OUTPUT_ALL_SYMBOLS;
53 my $OUTPUT_SYMBOLS_WITHOUT_SINCE;
55 my %optctl = ('module' => \$MODULE,
56 'source-dir' => \@SOURCE_DIRS,
57 'source-suffixes' => \$SOURCE_SUFFIXES,
58 'ignore-files' => \$IGNORE_FILES,
59 'output-dir' => \$SGML_OUTPUT_DIR,
60 'tmpl-dir' => \$TMPL_DIR,
61 'version' => \$PRINT_VERSION,
62 'help' => \$PRINT_HELP,
63 'main-sgml-file' => \$MAIN_SGML_FILE,
64 'expand-content-files' => \$EXPAND_CONTENT_FILES,
65 'sgml-mode' => \$SGML_MODE,
66 'default-stability' => \$DEFAULT_STABILITY,
67 'default-includes' => \$DEFAULT_INCLUDES,
68 'output-format' => \$OUTPUT_FORMAT,
69 'name-space' => \$NAME_SPACE,
70 'outputallsymbols' => \$OUTPUT_ALL_SYMBOLS,
71 'outputsymbolswithoutsince' => \$OUTPUT_SYMBOLS_WITHOUT_SINCE
73 GetOptions(\%optctl, "module=s", "source-dir:s", "source-suffixes:s",
74 "ignore-files:s", "output-dir:s", "tmpl-dir:s", "version", "outputallsymbols",
75 "outputsymbolswithoutsince",
76 "expand-content-files:s", "main-sgml-file:s", "extra-db-files:s", "help",
77 "sgml-mode", "default-stability:s", "default-includes:s", "output-format:s",
89 if ($DEFAULT_STABILITY && $DEFAULT_STABILITY ne "Stable"
90 && $DEFAULT_STABILITY ne "Private" && $DEFAULT_STABILITY ne "Unstable") {
96 gtkdoc-mkdb version @VERSION@ - generate docbook files
98 --module=MODULE_NAME Name of the doc module being parsed
99 --source-dir=DIRNAME Directories which contain inline reference material
100 --source-suffixes=SUFFIXES Suffixes of source files to scan, comma-separated
101 --ignore-files=FILES Files or directories which should not be scanned
102 May be used more than once for multiple directories
103 --output-dir=DIRNAME Directory to put the generated DocBook files in
104 --tmpl-dir=DIRNAME Directory in which template files may be found
105 --main-sgml-file=FILE File containing the toplevel DocBook file.
106 --expand-content-files=FILES Extra DocBook files to expand abbreviations in.
107 --output-format=FORMAT Format to use for the generated docbook, XML or SGML.
108 --sgml-mode Allow DocBook markup in inline documentation.
109 --default-stability=LEVEL Specify default stability Level. Valid values are
110 Stable, Unstable, or Private.
111 --default-includes=FILENAMES Specify default includes for section Synopsis
112 --name-space=NS Omit namespace in index.
113 --version Print the version of this program
114 --help Print this help
119 my ($empty_element_end, $doctype_header);
121 if (lc($OUTPUT_FORMAT) eq "xml") {
122 if (!$MAIN_SGML_FILE) {
123 # backwards compatibility
124 if (-e "${MODULE}-docs.sgml") {
125 $MAIN_SGML_FILE="${MODULE}-docs.sgml";
127 $MAIN_SGML_FILE="${MODULE}-docs.xml";
130 $OUTPUT_FORMAT = "xml";
131 $empty_element_end = "/>";
133 if (-e $MAIN_SGML_FILE) {
134 open(INPUT, "<$MAIN_SGML_FILE") || die "Can't open $MAIN_SGML_FILE";
135 $doctype_header = "";
137 if (/^\s*<(book|chapter|article)/) {
138 if ($_ !~ m/http:\/\/www.w3.org\/200[13]\/XInclude/) {
139 $doctype_header = "";
143 $doctype_header .= $_;
148 "<?xml version=\"1.0\"?>\n" .
149 "<!DOCTYPE book PUBLIC \"-//OASIS//DTD DocBook XML V4.3//EN\"\n" .
150 " \"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd\">\n";
152 $doctype_header =~ s/<!DOCTYPE \w+/<!DOCTYPE refentry/;
154 if (!$MAIN_SGML_FILE) {
155 $MAIN_SGML_FILE="${MODULE}-docs.sgml";
157 $OUTPUT_FORMAT = "sgml";
158 $doctype_header = "";
159 $empty_element_end = ">";
164 # All the files are written in subdirectories beneath here.
165 $TMPL_DIR = $TMPL_DIR ? $TMPL_DIR : "$ROOT_DIR/tmpl";
167 # This is where we put all the DocBook output.
168 $SGML_OUTPUT_DIR = $SGML_OUTPUT_DIR ? $SGML_OUTPUT_DIR : "$ROOT_DIR/$OUTPUT_FORMAT";
170 # This file contains the object hierarchy.
171 my $OBJECT_TREE_FILE = "$ROOT_DIR/$MODULE.hierarchy";
173 # This file contains the interfaces.
174 my $INTERFACES_FILE = "$ROOT_DIR/$MODULE.interfaces";
176 # This file contains the prerequisites.
177 my $PREREQUISITES_FILE = "$ROOT_DIR/$MODULE.prerequisites";
179 # This file contains signal arguments and names.
180 my $SIGNALS_FILE = "$ROOT_DIR/$MODULE.signals";
182 # The file containing Arg information.
183 my $ARGS_FILE = "$ROOT_DIR/$MODULE.args";
185 # These global arrays store information on signals. Each signal has an entry
186 # in each of these arrays at the same index, like a multi-dimensional array.
187 my @SignalObjects; # The GtkObject which emits the signal.
188 my @SignalNames; # The signal name.
189 my @SignalReturns; # The return type.
190 my @SignalFlags; # Flags for the signal
191 my @SignalPrototypes; # The rest of the prototype of the signal handler.
193 # These global arrays store information on Args. Each Arg has an entry
194 # in each of these arrays at the same index, like a multi-dimensional array.
195 my @ArgObjects; # The GtkObject which has the Arg.
196 my @ArgNames; # The Arg name.
197 my @ArgTypes; # The Arg type - gint, GtkArrowType etc.
198 my @ArgFlags; # How the Arg can be used - readable/writable etc.
199 my @ArgNicks; # The nickname of the Arg.
200 my @ArgBlurbs; # Docstring of the Arg.
201 my @ArgDefaults; # Default value of the Arg.
202 my @ArgRanges; # The range of the Arg type
203 # These global hashes store declaration info keyed on a symbol name.
205 my %DeclarationTypes;
206 my %DeclarationConditional;
207 my %DeclarationOutput;
211 my %StructHasTypedef;
213 # These global hashes store the existing documentation.
217 my %SymbolSourceFile;
218 my %SymbolSourceLine;
220 # These global hashes store documentation scanned from the source files.
221 my %SourceSymbolDocs;
222 my %SourceSymbolParams;
223 my %SourceSymbolSourceFile;
224 my %SourceSymbolSourceLine;
226 # all documentation goes in here, so we can do coverage analysis
228 my %AllIncompleteSymbols;
229 my %AllDocumentedSymbols;
231 # Undeclared yet documented symbols
232 my %UndeclaredSymbols;
234 # These global arrays store GObject, subclasses and the hierarchy.
241 # holds the symbols which are mentioned in $MODULE-sections.txt
244 # collects index entries
245 my %IndexEntriesFull;
246 my %IndexEntriesSince;
247 my %IndexEntriesDeprecated;
249 # Standard C preprocessor directives, which we ignore for '#' abbreviations.
250 my %PreProcessorDirectives;
251 $PreProcessorDirectives{"assert"} = 1;
252 $PreProcessorDirectives{"define"} = 1;
253 $PreProcessorDirectives{"elif"} = 1;
254 $PreProcessorDirectives{"else"} = 1;
255 $PreProcessorDirectives{"endif"} = 1;
256 $PreProcessorDirectives{"error"} = 1;
257 $PreProcessorDirectives{"if"} = 1;
258 $PreProcessorDirectives{"ifdef"} = 1;
259 $PreProcessorDirectives{"ifndef"} = 1;
260 $PreProcessorDirectives{"include"} = 1;
261 $PreProcessorDirectives{"line"} = 1;
262 $PreProcessorDirectives{"pragma"} = 1;
263 $PreProcessorDirectives{"unassert"} = 1;
264 $PreProcessorDirectives{"undef"} = 1;
265 $PreProcessorDirectives{"warning"} = 1;
267 # remember used annotation (to write minimal glossary)
270 my %AnnotationDefinition = (
271 'allow-none' => "NULL is ok, both for passing and for returning.",
272 'array' => "Parameter points to an array of items.",
273 'default' => "Default parameter value (for in case the <acronym>shadows</acronym>-to function has less parameters).",
274 'element-type' => "Generics and defining elements of containers and arrays.",
275 'error-domains' => "Typed errors. Similar to throws in Java.",
276 'in' => "Parameter for input. Default is <acronym>transfer none</acronym>.",
277 'inout' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
278 'in-out' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
279 'not-error' => "A GError parameter is not to be handled like a normal GError.",
280 'out' => "Parameter for returning results. Default is <acronym>transfer full</acronym>.",
281 'transfer container' => "Free data container after the code is done.",
282 'transfer full' => "Free data after the code is done.",
283 'transfer none' => "Don't free data after the code is done."
286 # Create the root DocBook output directory if it doens't exist.
287 if (! -e $SGML_OUTPUT_DIR) {
288 mkdir ("$SGML_OUTPUT_DIR", 0777)
289 || die "Can't create directory: $SGML_OUTPUT_DIR";
292 # Function and other declaration output settings.
293 my $RETURN_TYPE_FIELD_WIDTH = 20;
294 my $SYMBOL_FIELD_WIDTH = 36;
295 my $SIGNAL_FIELD_WIDTH = 16;
296 my $PARAM_FIELD_COUNT = 2;
298 &ReadKnownSymbols ("$ROOT_DIR/$MODULE-sections.txt");
299 &ReadSignalsFile ($SIGNALS_FILE);
300 &ReadArgsFile ($ARGS_FILE);
301 &ReadObjectHierarchy;
305 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-decl.txt", 0);
306 if (-f "$ROOT_DIR/$MODULE-overrides.txt") {
307 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-overrides.txt", 1);
310 for my $dir (@SOURCE_DIRS) {
311 &ReadSourceDocumentation ($dir);
314 my $changed = &OutputSGML ("$ROOT_DIR/$MODULE-sections.txt");
316 # If any of the DocBook SGML files have changed, update the timestamp file (so
317 # it can be used for Makefile dependencies).
318 if ($changed || ! -e "$ROOT_DIR/sgml.stamp") {
320 # try to detect the common prefix
321 # GtkWidget, GTK_WIDGET, gtk_widget -> gtk
322 if ($NAME_SPACE eq "") {
329 foreach my $symbol (keys(%IndexEntriesFull)) {
330 if(($NAME_SPACE eq "") || $symbol =~ /^$NAME_SPACE/i) {
331 if (length($symbol)>$pos) {
332 $letter=substr($symbol,$pos,1);
333 # stop prefix scanning
334 if ($letter eq "_") {
338 # Should we also stop on a uppercase char, if last was lowercase
339 # GtkWidget, if we have the 'W' and had the 't' before
340 # or should we count upper and lowercase, and stop one 2nd uppercase, if we already had a lowercase
341 # GtkWidget, the 'W' would be the 2nd uppercase and with 't','k' we had lowercase chars before
342 # need to recound each time as this is per symbol
343 $prefix{uc($letter)}++;
347 if ($letter ne "" && $letter ne "_") {
350 foreach $letter (keys(%prefix)) {
351 #print "$letter: $prefix{$letter}.\n";
352 if ($prefix{$letter}>$maxsymbols) {
354 $maxsymbols=$prefix{$letter};
357 $ratio = scalar(keys(%IndexEntriesFull)) / $prefix{$maxletter};
358 #print "most symbols start with $maxletter, that is ". (100 * $ratio) ." %\n";
361 $NAME_SPACE .= $maxletter;
368 } while ($ratio > 0.9);
369 #print "most symbols start with $NAME_SPACE\n";
373 &OutputDeprecatedIndex;
375 &OutputAnnotationGlossary;
377 open (TIMESTAMP, ">$ROOT_DIR/sgml.stamp")
378 || die "Can't create $ROOT_DIR/sgml.stamp: $!";
379 print (TIMESTAMP "timestamp");
383 #############################################################################
384 # Function : OutputObjectList
385 # Description : This outputs the alphabetical list of objects, in a columned
387 # FIXME: Currently this also outputs ancestor objects
388 # which may not actually be in this module.
390 #############################################################################
392 sub OutputObjectList {
395 # FIXME: use $OUTPUT_FORMAT
396 # my $old_object_index = "$SGML_OUTPUT_DIR/object_index.$OUTPUT_FORMAT";
397 my $old_object_index = "$SGML_OUTPUT_DIR/object_index.sgml";
398 my $new_object_index = "$SGML_OUTPUT_DIR/object_index.new";
400 open (OUTPUT, ">$new_object_index")
401 || die "Can't create $new_object_index: $!";
403 if (lc($OUTPUT_FORMAT) eq "xml") {
404 my $header = $doctype_header;
406 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE informaltable/;
407 print (OUTPUT "$header");
410 print (OUTPUT <<EOF);
411 <informaltable pgwide="1" frame="none">
412 <tgroup cols="$cols">
413 <colspec colwidth="1*"${empty_element_end}
414 <colspec colwidth="1*"${empty_element_end}
415 <colspec colwidth="1*"${empty_element_end}
421 foreach $object (sort (@Objects)) {
422 my $xref = &MakeXRef ($object);
423 if ($count % $cols == 0) { print (OUTPUT "<row>\n"); }
424 print (OUTPUT "<entry>$xref</entry>\n");
425 if ($count % $cols == ($cols - 1)) { print (OUTPUT "</row>\n"); }
429 # emit an empty row, since empty tables are invalid
430 print (OUTPUT "<row><entry> </entry></row>\n");
433 print (OUTPUT "</row>\n");
436 print (OUTPUT <<EOF);
437 </tbody></tgroup></informaltable>
441 &UpdateFileIfChanged ($old_object_index, $new_object_index, 0);
445 #############################################################################
446 # Function : OutputSGML
447 # Description : This collects the output for each section of the docs, and
448 # outputs each file when the end of the section is found.
449 # Arguments : $file - the $MODULE-sections.txt file which contains all of
450 # the functions/macros/structs etc. being documented, organised
451 # into sections and subsections.
452 #############################################################################
457 #print "Reading: $file\n";
459 || die "Can't open $file: $!";
462 my $book_bottom = "";
463 my $includes = (defined $DEFAULT_INCLUDES) ? $DEFAULT_INCLUDES : "";
464 my $section_includes = "";
472 my $signals_synop = "";
473 my $signals_desc = "";
475 my $child_args_synop = "";
476 my $style_args_synop = "";
478 my $child_args_desc = "";
479 my $style_args_desc = "";
482 my $implementations = "";
483 my $prerequisites = "";
485 my @file_objects = ();
489 # merge the source docs, in case there are no templates
490 &MergeSourceDocumentation;
496 } elsif (m/^<SECTION>/) {
504 } elsif (m/^<SUBSECTION\s*(.*)>/i) {
508 } elsif (m/^<SUBSECTION>/) {
510 } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
512 #print "Section: $title\n";
514 # We don't want warnings if object & class structs aren't used.
515 $DeclarationOutput{$title} = 1;
516 $DeclarationOutput{"${title}Class"} = 1;
517 $DeclarationOutput{"${title}Iface"} = 1;
518 $DeclarationOutput{"${title}Interface"} = 1;
520 } elsif (m/^<FILE>(.*)<\/FILE>/) {
522 if (! defined $templates{$filename}) {
523 if (&ReadTemplateFile ("$TMPL_DIR/$filename", 1)) {
524 &MergeSourceDocumentation;
525 $templates{$filename}=$.;
528 &LogWarning ($file, $., "Double <FILE>$filename</FILE> entry. ".
529 "Previous occurrence on line ".$templates{$filename}.".");
532 } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
534 $section_includes = $1;
536 if (defined $DEFAULT_INCLUDES) {
537 &LogWarning ($file, $., "Default <INCLUDE> being overridden by command line option.");
544 } elsif (m/^<\/SECTION>/) {
545 if($title eq "" && $filename eq "") {
546 &LogWarning ($file, $., "Section has no title and no file.");
548 # FIXME: one of those would be enough
552 if ($filename eq "") {
555 #print "End of section: $title\n";
557 $filename =~ s/\s/_/g;
559 my $section_id = $SourceSymbolDocs{"$TMPL_DIR/$filename:Section_Id"};
560 if (defined ($section_id) && $section_id !~ m/^\s*$/) {
561 # Remove trailing blanks and use as is
562 $section_id =~ s/\s+$//;
563 } elsif (&CheckIsObject ($title)) {
564 # GtkObjects use their class name as the ID.
565 $section_id = &CreateValidSGMLID ($title);
567 $section_id = &CreateValidSGMLID ("$MODULE-$title");
570 if ($num_symbols > 0) {
572 if (lc($OUTPUT_FORMAT) eq "xml") {
573 $book_bottom .= " <xi:include href=\"xml/$filename.xml\"/>\n";
575 $book_top.="<!ENTITY $section_id SYSTEM \"sgml/$filename.sgml\">\n";
576 $book_bottom .= " &$section_id;\n";
579 if (defined ($SourceSymbolDocs{"$TMPL_DIR/$filename:Include"})) {
580 if ($section_includes) {
581 &LogWarning ($file, $., "Section <INCLUDE> being overridden by inline comments.");
583 $section_includes = $SourceSymbolDocs{"$TMPL_DIR/$filename:Include"};
585 if ($section_includes eq "") {
586 $section_includes = $includes;
589 $signals_synop =~ s/^\n*//g;
590 $signals_synop =~ s/\n+$/\n/g;
591 if ($signals_synop ne '') {
592 $signals_synop = <<EOF;
593 <refsect1 id="$section_id.signals" role="signal_proto">
594 <title role="signal_proto.title">Signals</title>
596 ${signals_synop}</synopsis>
599 $signals_desc =~ s/^\n*//g;
600 $signals_desc =~ s/\n+$/\n/g;
601 $signals_desc =~ s/(\s|\n)+$//ms;
602 $signals_desc = <<EOF;
603 <refsect1 id="$section_id.signal-details" role="signals">
604 <title role="signals.title">Signal Details</title>
610 $args_synop =~ s/^\n*//g;
611 $args_synop =~ s/\n+$/\n/g;
612 if ($args_synop ne '') {
614 <refsect1 id="$section_id.properties" role="properties">
615 <title role="properties.title">Properties</title>
617 ${args_synop}</synopsis>
620 $args_desc =~ s/^\n*//g;
621 $args_desc =~ s/\n+$/\n/g;
622 $args_desc =~ s/(\s|\n)+$//ms;
624 <refsect1 id="$section_id.property-details" role="property_details">
625 <title role="property_details.title">Property Details</title>
631 $child_args_synop =~ s/^\n*//g;
632 $child_args_synop =~ s/\n+$/\n/g;
633 if ($child_args_synop ne '') {
634 $args_synop .= <<EOF;
635 <refsect1 id="$section_id.child-properties" role="child_properties">
636 <title role="child_properties.title">Child Properties</title>
638 ${child_args_synop}</synopsis>
641 $child_args_desc =~ s/^\n*//g;
642 $child_args_desc =~ s/\n+$/\n/g;
643 $child_args_desc =~ s/(\s|\n)+$//ms;
645 <refsect1 id="$section_id.child-property-details" role="child_property_details">
646 <title role="child_property_details.title">Child Property Details</title>
652 $style_args_synop =~ s/^\n*//g;
653 $style_args_synop =~ s/\n+$/\n/g;
654 if ($style_args_synop ne '') {
655 $args_synop .= <<EOF;
656 <refsect1 id="$section_id.style-properties" role="style_properties">
657 <title role="style_properties.title">Style Properties</title>
659 ${style_args_synop}</synopsis>
662 $style_args_desc =~ s/^\n*//g;
663 $style_args_desc =~ s/\n+$/\n/g;
664 $style_args_desc =~ s/(\s|\n)+$//ms;
666 <refsect1 id="$section_id.style-property-details" role="style_properties_details">
667 <title role="style_properties_details.title">Style Property Details</title>
673 $hierarchy =~ s/^\n*//g;
674 $hierarchy =~ s/\n+$/\n/g;
675 $hierarchy =~ s/(\s|\n)+$//ms;
676 if ($hierarchy ne "") {
678 <refsect1 id="$section_id.object-hierarchy" role="object_hierarchy">
679 <title role="object_hierarchy.title">Object Hierarchy</title>
685 $interfaces =~ s/^\n*//g;
686 $interfaces =~ s/\n+$/\n/g;
687 $interfaces =~ s/(\s|\n)+$//ms;
688 if ($interfaces ne "") {
690 <refsect1 id="$section_id.implemented-interfaces" role="impl_interfaces">
691 <title role="impl_interfaces.title">Implemented Interfaces</title>
697 $implementations =~ s/^\n*//g;
698 $implementations =~ s/\n+$/\n/g;
699 $implementations =~ s/(\s|\n)+$//ms;
700 if ($implementations ne "") {
701 $implementations = <<EOF;
702 <refsect1 id="$section_id.implementations" role="implementations">
703 <title role="implementations.title">Known Implementations</title>
709 $prerequisites =~ s/^\n*//g;
710 $prerequisites =~ s/\n+$/\n/g;
711 $prerequisites =~ s/(\s|\n)+$//ms;
712 if ($prerequisites ne "") {
713 $prerequisites = <<EOF;
714 <refsect1 id="$section_id.prerequisites" role="prerequisites">
715 <title role="prerequisites.title">Prerequisites</title>
721 $derived =~ s/^\n*//g;
722 $derived =~ s/\n+$/\n/g;
723 $derived =~ s/(\s|\n)+$//ms;
724 if ($derived ne "") {
726 <refsect1 id="$section_id.derived-interfaces" role="derived_interfaces">
727 <title role="derived_interfaces.title">Known Derived Interfaces</title>
733 $synopsis =~ s/^\n*//g;
734 $synopsis =~ s/\n+$/\n/g;
735 my $file_changed = &OutputSGMLFile ($filename, $title, $section_id,
737 \$synopsis, \$details,
738 \$signals_synop, \$signals_desc,
739 \$args_synop, \$args_desc,
740 \$hierarchy, \$interfaces,
742 \$prerequisites, \$derived,
751 $section_includes = "";
755 $child_args_synop = "";
756 $style_args_synop = "";
758 $child_args_desc = "";
759 $style_args_desc = "";
762 $implementations = "";
766 } elsif (m/^(\S+)/) {
768 #print " Symbol: $symbol\n";
770 # FIXME: check for duplicate entries
771 if (! defined $symbols{$symbol}) {
772 my $declaration = $Declarations{$symbol};
773 if (defined ($declaration)) {
774 # We don't want standard macros/functions of GtkObjects,
775 # or private declarations.
776 if ($subsection ne "Standard" && $subsection ne "Private") {
777 if (&CheckIsObject ($symbol)) {
778 push @file_objects, $symbol;
780 my ($synop, $desc) = &OutputDeclaration ($symbol,
782 my ($sig_synop, $sig_desc) = &GetSignals ($symbol);
783 my ($arg_synop, $child_arg_synop, $style_arg_synop,
784 $arg_desc, $child_arg_desc, $style_arg_desc) = &GetArgs ($symbol);
785 my $hier = &GetHierarchy ($symbol);
786 my $ifaces = &GetInterfaces ($symbol);
787 my $impls = &GetImplementations ($symbol);
788 my $prereqs = &GetPrerequisites ($symbol);
789 my $der = &GetDerived ($symbol);
792 $signals_synop .= $sig_synop;
793 $signals_desc .= $sig_desc;
794 $args_synop .= $arg_synop;
795 $child_args_synop .= $child_arg_synop;
796 $style_args_synop .= $style_arg_synop;
797 $args_desc .= $arg_desc;
798 $child_args_desc .= $child_arg_desc;
799 $style_args_desc .= $style_arg_desc;
801 $interfaces .= $ifaces;
802 $implementations .= $impls;
803 $prerequisites .= $prereqs;
807 # Note that the declaration has been output.
808 $DeclarationOutput{$symbol} = 1;
809 } elsif ($subsection ne "Standard" && $subsection ne "Private") {
810 $UndeclaredSymbols{$symbol} = 1;
811 &LogWarning ($file, $., "No declaration found for $symbol.");
814 $symbols{$symbol}=$.;
817 &LogWarning ($file, $., "Double symbol entry for $symbol. ".
818 "Previous occurrence on line ".$symbols{$symbol}.".");
824 &OutputMissingDocumentation;
825 &OutputUndeclaredSymbols;
827 if ($OUTPUT_ALL_SYMBOLS) {
830 if ($OUTPUT_SYMBOLS_WITHOUT_SINCE) {
831 &OutputSymbolsWithoutSince;
834 for $filename (split (' ', $EXPAND_CONTENT_FILES)) {
835 my $file_changed = &OutputExtraFile ($filename);
841 &OutputBook ($book_top, $book_bottom);
846 #############################################################################
847 # Function : OutputIndex
848 # Description : This writes an indexlist that can be included into the main-
849 # document into an <index> tag.
850 #############################################################################
853 my ($basename, $apiindexref ) = @_;
854 my %apiindex = %{$apiindexref};
855 my $old_index = "$SGML_OUTPUT_DIR/$basename.xml";
856 my $new_index = "$SGML_OUTPUT_DIR/$basename.new";
857 my $lastletter = " ";
862 open (OUTPUT, ">$new_index")
863 || die "Can't create $new_index";
865 my $header = $doctype_header;
866 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE indexdiv/;
868 print (OUTPUT "$header<indexdiv>\n");
870 #print "generate $basename index (".%apiindex." entries)\n";
872 # do a case insensitive sort while chopping off the prefix
874 sort { $$a{criteria} cmp $$b{criteria} }
875 map { my $x = uc($_); $x =~ s/^$NAME_SPACE\_?(.*)/$1/i; { criteria => $x, original => $_, short => $1 } }
878 $symbol = $$hash{original};
879 if (defined($$hash{short})) {
880 $short_symbol = $$hash{short};
882 $short_symbol = $symbol;
885 # generate a short symbol description
886 my $symbol_desc = "";
887 my $symbol_type = lc($DeclarationTypes{$symbol});
888 if ($symbol_type eq "") {
889 if ($symbol =~ m/.*?::(.*)/) {
892 for ($i = 0; $i <= $#ArgNames; $i++) {
893 if ($ArgNames[$i] eq $osym) {
894 $symbol_type = "object property";
898 } elsif ($symbol =~ m/.*?:(.*)/) {
901 for ($i = 0; $i <= $#SignalNames; $i++) {
902 if ($SignalNames[$i] eq $osym) {
903 $symbol_type = "object signal";
909 if ($symbol_type ne "") {
910 $symbol_desc=", $symbol_type";
913 my $curletter = uc(substr($short_symbol,0,1));
914 my $id = $apiindex{$symbol};
916 #print " add symbol $symbol with $id to index in section $curletter\n";
918 if ($curletter ne $lastletter) {
919 $lastletter = $curletter;
922 print (OUTPUT "</indexdiv>\n");
924 print (OUTPUT "<indexdiv><title>$curletter</title>\n");
928 print (OUTPUT <<EOF);
929 <indexentry><primaryie linkends="$id"><link linkend="$id">$symbol</link>$symbol_desc</primaryie></indexentry>
934 print (OUTPUT "</indexdiv>\n");
936 print (OUTPUT "</indexdiv>\n");
939 &UpdateFileIfChanged ($old_index, $new_index, 0);
943 #############################################################################
944 # Function : OutputIndexFull
945 # Description : This writes the full api indexlist that can be included into the
946 # main document into an <index> tag.
947 #############################################################################
949 sub OutputIndexFull {
950 &OutputIndex ("api-index-full", \%IndexEntriesFull);
954 #############################################################################
955 # Function : OutputDeprecatedIndex
956 # Description : This writes the deprecated api indexlist that can be included
957 # into the main document into an <index> tag.
958 #############################################################################
960 sub OutputDeprecatedIndex {
961 &OutputIndex ("api-index-deprecated", \%IndexEntriesDeprecated);
965 #############################################################################
966 # Function : OutputSinceIndexes
967 # Description : This writes the 'since' api indexlists that can be included into
968 # the main document into an <index> tag.
969 #############################################################################
971 sub OutputSinceIndexes {
972 my @sinces = keys %{{ map { $_ => 1 } values %Since }};
974 foreach my $version (@sinces) {
975 #print "Since : [$version]\n";
976 # todo make filtered hash
977 #my %index = grep { $Since{$_} eq $version } %IndexEntriesSince;
978 my %index = map { $_ => $IndexEntriesSince{$_} } grep { $Since{$_} eq $version } keys %IndexEntriesSince;
980 &OutputIndex ("api-index-$version", \%index);
984 #############################################################################
985 # Function : OutputAnnotationGlossary
986 # Description : This writes a glossary of the used annotation terms into a
987 # separate glossary file that can be included into the main
989 #############################################################################
991 sub OutputAnnotationGlossary {
992 my $old_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.xml";
993 my $new_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.new";
994 my $lastletter = " ";
997 # if there are no annotations used return
998 return if (! keys(%AnnotationsUsed));
1000 # add acronyms that are referenced from acronym text
1002 foreach my $annotation (keys(%AnnotationsUsed)) {
1003 if($AnnotationDefinition{$annotation} =~ m/<acronym>([\w ]+)<\/acronym>/) {
1004 if (!exists($AnnotationsUsed{$1})) {
1005 $AnnotationsUsed{$1} = 1;
1011 open (OUTPUT, ">$new_glossary")
1012 || die "Can't create $new_glossary";
1014 my $header = $doctype_header;
1015 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE glossary/;
1017 print (OUTPUT <<EOF);
1019 <glossary id="annotation-glossary">
1020 <title>Annotation Glossary</title>
1023 foreach my $annotation (keys(%AnnotationsUsed)) {
1024 my $def = $AnnotationDefinition{$annotation};
1025 my $curletter = uc(substr($annotation,0,1));
1027 if ($curletter ne $lastletter) {
1028 $lastletter = $curletter;
1030 if ($divopen == 1) {
1031 print (OUTPUT "</glossdiv>\n");
1033 print (OUTPUT "<glossdiv><title>$curletter</title>\n");
1036 print (OUTPUT <<EOF);
1038 <glossterm><anchor id="annotation-glossterm-$annotation"/>$annotation</glossterm>
1046 if ($divopen == 1) {
1047 print (OUTPUT "</glossdiv>\n");
1049 print (OUTPUT "</glossary>\n");
1052 &UpdateFileIfChanged ($old_glossary, $new_glossary, 0);
1055 #############################################################################
1056 # Function : ReadKnownSymbols
1057 # Description : This collects the names of non-private symbols from the
1058 # $MODULE-sections.txt file.
1059 # Arguments : $file - the $MODULE-sections.txt file which contains all of
1060 # the functions/macros/structs etc. being documented, organised
1061 # into sections and subsections.
1062 #############################################################################
1064 sub ReadKnownSymbols {
1067 my $subsection = "";
1069 #print "Reading: $file\n";
1071 || die "Can't open $file: $!";
1077 } elsif (m/^<SECTION>/) {
1080 } elsif (m/^<SUBSECTION\s*(.*)>/i) {
1083 } elsif (m/^<SUBSECTION>/) {
1086 } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
1089 } elsif (m/^<FILE>(.*)<\/FILE>/) {
1090 $KnownSymbols{"$TMPL_DIR/$1:Long_Description"} = 1;
1091 $KnownSymbols{"$TMPL_DIR/$1:Short_Description"} = 1;
1094 } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
1097 } elsif (m/^<\/SECTION>/) {
1100 } elsif (m/^(\S+)/) {
1103 if ($subsection ne "Standard" && $subsection ne "Private") {
1104 $KnownSymbols{$symbol} = 1;
1107 $KnownSymbols{$symbol} = 0;
1115 #############################################################################
1116 # Function : OutputDeclaration
1117 # Description : Returns the synopsis and detailed description DocBook
1118 # describing one function/macro etc.
1119 # Arguments : $symbol - the name of the function/macro begin described.
1120 # $declaration - the declaration of the function/macro.
1121 #############################################################################
1123 sub OutputDeclaration {
1124 my ($symbol, $declaration) = @_;
1126 my $type = $DeclarationTypes {$symbol};
1127 if ($type eq 'MACRO') {
1128 return &OutputMacro ($symbol, $declaration);
1129 } elsif ($type eq 'TYPEDEF') {
1130 return &OutputTypedef ($symbol, $declaration);
1131 } elsif ($type eq 'STRUCT') {
1132 return &OutputStruct ($symbol, $declaration);
1133 } elsif ($type eq 'ENUM') {
1134 return &OutputEnum ($symbol, $declaration);
1135 } elsif ($type eq 'UNION') {
1136 return &OutputUnion ($symbol, $declaration);
1137 } elsif ($type eq 'VARIABLE') {
1138 return &OutputVariable ($symbol, $declaration);
1139 } elsif ($type eq 'FUNCTION') {
1140 return &OutputFunction ($symbol, $declaration, $type);
1141 } elsif ($type eq 'USER_FUNCTION') {
1142 return &OutputFunction ($symbol, $declaration, $type);
1144 die "Unknown symbol type";
1149 #############################################################################
1150 # Function : OutputSymbolTraits
1151 # Description : Returns the Since and StabilityLevel paragraphs for a symbol.
1152 # Arguments : $symbol - the name of the function/macro begin described.
1153 #############################################################################
1155 sub OutputSymbolTraits {
1159 if (exists $Since{$symbol}) {
1160 $desc .= "<para role=\"since\">Since $Since{$symbol}</para>";
1162 if (exists $StabilityLevel{$symbol}) {
1163 $desc .= "<para role=\"stability\">Stability Level: $StabilityLevel{$symbol}</para>";
1168 #############################################################################
1169 # Function : Outpu{Symbol,Section}ExtraLinks
1170 # Description : Returns extralinks for the symbol (if enabled).
1171 # Arguments : $symbol - the name of the function/macro begin described.
1172 #############################################################################
1176 return undef unless defined $text;
1178 # Build a char to hex map
1181 $escapes{chr($_)} = sprintf("%%%02X", $_);
1184 # Default unsafe characters. RFC 2732 ^(uric - reserved)
1185 $text =~ s/([^A-Za-z0-9\-_.!~*'()])/$escapes{$1}/g;
1190 sub OutputSymbolExtraLinks {
1194 if (0) { # NEW FEATURE: needs configurability
1195 my $sstr = &uri_escape($symbol);
1196 my $mstr = &uri_escape($MODULE);
1198 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1199 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&symbol=$sstr">edit documentation</ulink>
1205 sub OutputSectionExtraLinks {
1206 my ($symbol,$docsymbol) = @_;
1209 if (0) { # NEW FEATURE: needs configurability
1210 my $sstr = &uri_escape($symbol);
1211 my $mstr = &uri_escape($MODULE);
1212 my $dsstr = &uri_escape($docsymbol);
1214 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1215 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&symbol=$dsstr">edit documentation</ulink>
1222 #############################################################################
1223 # Function : OutputMacro
1224 # Description : Returns the synopsis and detailed description of a macro.
1225 # Arguments : $symbol - the macro.
1226 # $declaration - the declaration of the macro.
1227 #############################################################################
1230 my ($symbol, $declaration) = @_;
1231 my $id = &CreateValidSGMLID ($symbol);
1232 my $condition = &MakeConditionDescription ($symbol);
1233 my $synop = &MakeReturnField("#define") . "<link linkend=\"$id\">$symbol</link>";
1239 if ($declaration =~ m/^\s*#\s*define(\s+)\w+(\([^\)]*\))/) {
1243 if (length ($symbol) < $SYMBOL_FIELD_WIDTH) {
1244 $synop .= (' ' x ($SYMBOL_FIELD_WIDTH - length ($symbol)));
1247 # Try to align all the lines of args correctly.
1248 $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH + $SYMBOL_FIELD_WIDTH + 1);
1249 my $args_padded = $args;
1250 $args_padded =~ s/ *\\\n */\n$pad/gm;
1251 $synop .= &CreateValidSGML ($args_padded);
1255 my $title = $symbol . ($args ? "()" : "");
1256 $desc = "<refsect2 id=\"$id\" role=\"macro\"$condition>\n<title>$title</title>\n";
1257 $desc .= MakeIndexterms($symbol, $id);
1259 $desc .= OutputSymbolExtraLinks($symbol);
1261 # Don't output the macro definition if is is a conditional macro or it
1262 # looks like a function, i.e. starts with "g_" or "_?gnome_", or it is
1263 # longer than 2 lines, otherwise we get lots of complicated macros like
1265 if (!defined ($DeclarationConditional{$symbol}) && ($symbol !~ m/^g_/)
1266 && ($symbol !~ m/^_?gnome_/) && (($declaration =~ tr/\n//) < 2)) {
1267 my $decl_out = &CreateValidSGML ($declaration);
1268 $desc .= "<programlisting>$decl_out</programlisting>\n";
1270 $desc .= "<programlisting>" . &MakeReturnField("#define") . "$symbol";
1271 # Align each line so that if should all line up OK.
1272 $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH - length ("#define "));
1273 $args =~ s/\n/\n$pad/gm;
1274 $desc .= &CreateValidSGML ($args);
1275 $desc .= "</programlisting>\n";
1278 $desc .= &MakeDeprecationNote($symbol);
1280 my $parameters = &OutputParamDescriptions ("MACRO", $symbol);
1281 my $parameters_output = 0;
1283 if (defined ($SymbolDocs{$symbol})) {
1284 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1286 # Try to insert the parameter table at the author's desired position.
1287 # Otherwise we need to tag it onto the end.
1288 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1289 $parameters_output = 1;
1291 $desc .= $symbol_docs;
1294 if ($parameters_output == 0) {
1295 $desc .= $parameters;
1298 $desc .= OutputSymbolTraits ($symbol);
1299 $desc .= "</refsect2>\n";
1300 return ($synop, $desc);
1304 #############################################################################
1305 # Function : OutputTypedef
1306 # Description : Returns the synopsis and detailed description of a typedef.
1307 # Arguments : $symbol - the typedef.
1308 # $declaration - the declaration of the typedef,
1309 # e.g. 'typedef unsigned int guint;'
1310 #############################################################################
1313 my ($symbol, $declaration) = @_;
1314 my $id = &CreateValidSGMLID ($symbol);
1315 my $condition = &MakeConditionDescription ($symbol);
1316 my $synop = &MakeReturnField("typedef") . "<link linkend=\"$id\">$symbol</link>;\n";
1317 my $desc = "<refsect2 id=\"$id\" role=\"typedef\"$condition>\n<title>$symbol</title>\n";
1319 $desc .= MakeIndexterms($symbol, $id);
1321 $desc .= OutputSymbolExtraLinks($symbol);
1323 if (!defined ($DeclarationConditional{$symbol})) {
1324 my $decl_out = &CreateValidSGML ($declaration);
1325 $desc .= "<programlisting>$decl_out</programlisting>\n";
1328 $desc .= &MakeDeprecationNote($symbol);
1330 if (defined ($SymbolDocs{$symbol})) {
1331 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1333 $desc .= OutputSymbolTraits ($symbol);
1334 $desc .= "</refsect2>\n";
1335 return ($synop, $desc);
1339 #############################################################################
1340 # Function : OutputStruct
1341 # Description : Returns the synopsis and detailed description of a struct.
1342 # We check if it is a widget struct, and if so we only output
1343 # parts of it that are noted as public fields.
1344 # We also use a different SGML ID for widget structs, since the
1345 # original ID is used for the entire RefEntry.
1346 # Arguments : $symbol - the struct.
1347 # $declaration - the declaration of the struct.
1348 #############################################################################
1351 my ($symbol, $declaration) = @_;
1353 my $is_widget_struct = 0;
1354 my $default_to_public = 1;
1355 if (&CheckIsObject ($symbol)) {
1356 #print "Found widget struct: $symbol\n";
1357 $is_widget_struct = 1;
1358 $default_to_public = 0;
1363 if ($is_widget_struct) {
1364 $id = &CreateValidSGMLID ($symbol . "_struct");
1365 $condition = &MakeConditionDescription ($symbol . "_struct");
1367 $id = &CreateValidSGMLID ($symbol);
1368 $condition = &MakeConditionDescription ($symbol);
1371 # Determine if it is a simple struct or it also has a typedef.
1372 my $has_typedef = 0;
1373 if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1380 # For structs with typedefs we just output the struct name.
1381 $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1382 $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>$symbol</title>\n";
1384 $synop = &MakeReturnField("struct") . "<link linkend=\"$id\">$symbol</link>;\n";
1385 $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>struct $symbol</title>\n";
1388 $desc .= MakeIndexterms($symbol, $id);
1390 $desc .= OutputSymbolExtraLinks($symbol);
1392 # Form a pretty-printed, private-data-removed form of the declaration
1395 if ($declaration =~ m/^\s*$/) {
1396 #print "Found opaque struct: $symbol\n";
1397 $decl_out = "typedef struct _$symbol $symbol;";
1398 } elsif ($declaration =~ m/^\s*struct\s+\w+\s*;\s*$/) {
1399 #print "Found opaque struct: $symbol\n";
1400 $decl_out = "struct $symbol;";
1402 my $public = $default_to_public;
1403 my $new_declaration = "";
1405 my $decl = $declaration;
1407 if ($decl =~ m/^\s*(typedef\s+)?struct\s*\w*\s*(?:\/\*.*\*\/)?\s*{(.*)}\s*\w*\s*;\s*$/s) {
1408 my $struct_contents = $2;
1410 foreach $decl_line (split (/\n/, $struct_contents)) {
1411 #print "Struct line: $decl_line\n";
1412 if ($decl_line =~ m%/\*\s*<\s*public\s*>\s*\*/%) {
1414 } elsif ($decl_line =~ m%/\*\s*<\s*(private|protected)\s*>\s*\*/%) {
1417 $new_declaration .= $decl_line . "\n";
1421 if ($new_declaration) {
1422 # Strip any blank lines off the ends.
1423 $new_declaration =~ s/^\s*\n//;
1424 $new_declaration =~ s/\n\s*$/\n/;
1427 $decl_out = "typedef struct {\n" . $new_declaration
1430 $decl_out = "struct $symbol {\n" . $new_declaration
1435 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1436 "Couldn't parse struct:\n$declaration");
1439 # If we couldn't parse the struct or it was all private, output an
1440 # empty struct declaration.
1441 if ($decl_out eq "") {
1443 $decl_out = "typedef struct _$symbol $symbol;";
1445 $decl_out = "struct $symbol;";
1450 $decl_out = &CreateValidSGML ($decl_out);
1451 $desc .= "<programlisting>$decl_out</programlisting>\n";
1453 $desc .= &MakeDeprecationNote($symbol);
1455 if (defined ($SymbolDocs{$symbol})) {
1456 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1459 # Create a table of fields and descriptions
1461 # FIXME: Inserting  's into the produced type declarations here would
1462 # improve the output in most situations ... except for function
1463 # members of structs!
1464 my @fields = ParseStructDeclaration($declaration, !$default_to_public,
1467 "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1469 my $params = $SymbolParams{$symbol};
1471 # If no parameters are filled in, we don't generate the description
1472 # table, for backwards compatibility
1475 if (defined $params) {
1476 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1477 if ($params->[$i] =~ /\S/) {
1485 my %field_descrs = @$params;
1488 <variablelist role="struct">
1491 my $field_name = shift @fields;
1492 my $text = shift @fields;
1493 my $field_descr = $field_descrs{$field_name};
1494 my $param_annotations = "";
1496 $desc .= "<varlistentry><term>$text</term>\n";
1497 if (defined $field_descr) {
1498 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1499 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1500 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1502 $desc .= "<listitem><simpara /></listitem>\n";
1504 $desc .= "</varlistentry>\n";
1507 $desc .= "</variablelist>";
1509 $desc .= OutputSymbolTraits ($symbol);
1510 $desc .= "</refsect2>\n";
1511 return ($synop, $desc);
1515 #############################################################################
1516 # Function : OutputEnum
1517 # Description : Returns the synopsis and detailed description of a enum.
1518 # Arguments : $symbol - the enum.
1519 # $declaration - the declaration of the enum.
1520 #############################################################################
1523 my ($symbol, $declaration) = @_;
1524 my $id = &CreateValidSGMLID ($symbol);
1525 my $condition = &MakeConditionDescription ($symbol);
1526 my $synop = &MakeReturnField("enum") . "<link linkend=\"$id\">$symbol</link>;\n";
1527 my $desc = "<refsect2 id=\"$id\" role=\"enum\"$condition>\n<title>enum $symbol</title>\n";
1529 $desc .= MakeIndexterms($symbol, $id);
1531 $desc .= OutputSymbolExtraLinks($symbol);
1533 my $decl_out = &CreateValidSGML ($declaration);
1534 $desc .= "<programlisting>$decl_out</programlisting>\n";
1536 $desc .= &MakeDeprecationNote($symbol);
1538 if (defined ($SymbolDocs{$symbol})) {
1539 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1542 # Create a table of fields and descriptions
1544 my @members = ParseEnumDeclaration($declaration);
1545 my $params = $SymbolParams{$symbol};
1547 # If no parameters are filled in, we don't generate the description
1548 # table, for backwards compatibility
1551 if (defined $params) {
1552 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1553 if ($params->[$i] =~ /\S/) {
1561 my %member_descrs = @$params;
1564 <variablelist role="enum">
1566 for my $member_name (@members) {
1567 my $member_descr = $member_descrs{$member_name};
1568 my $param_annotations = "";
1570 $id = &CreateValidSGMLID ($member_name);
1571 $condition = &MakeConditionDescription ($member_name);
1572 $desc .= "<varlistentry id=\"$id\" role=\"constant\"$condition>\n<term><literal>$member_name</literal></term>\n";
1573 if (defined $member_descr) {
1574 ($member_descr,$param_annotations) = &ExpandAnnotation($symbol, $member_descr);
1575 $member_descr = &ExpandAbbreviations($symbol, $member_descr);
1576 $desc .= "<listitem><simpara>$member_descr$param_annotations</simpara></listitem>\n";
1578 $desc .= "<listitem></listitem>\n";
1580 $desc .= "</varlistentry>\n";
1583 $desc .= "</variablelist>";
1586 $desc .= OutputSymbolTraits ($symbol);
1587 $desc .= "</refsect2>\n";
1588 return ($synop, $desc);
1592 #############################################################################
1593 # Function : OutputUnion
1594 # Description : Returns the synopsis and detailed description of a union.
1595 # Arguments : $symbol - the union.
1596 # $declaration - the declaration of the union.
1597 #############################################################################
1600 my ($symbol, $declaration) = @_;
1601 my $id = &CreateValidSGMLID ($symbol);
1602 my $condition = &MakeConditionDescription ($symbol);
1603 my $synop = &MakeReturnField("union") . "<link linkend=\"$id\">$symbol</link>;\n";
1604 my $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>union $symbol</title>\n";
1606 $desc .= MakeIndexterms($symbol, $id);
1608 $desc .= OutputSymbolExtraLinks($symbol);
1610 my $decl_out = &CreateValidSGML ($declaration);
1611 $desc .= "<programlisting>$decl_out</programlisting>\n";
1613 $desc .= &MakeDeprecationNote($symbol);
1615 if (defined ($SymbolDocs{$symbol})) {
1616 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1618 $desc .= OutputSymbolTraits ($symbol);
1619 $desc .= "</refsect2>\n";
1620 return ($synop, $desc);
1624 #############################################################################
1625 # Function : OutputVariable
1626 # Description : Returns the synopsis and detailed description of a variable.
1627 # Arguments : $symbol - the extern'ed variable.
1628 # $declaration - the declaration of the variable.
1629 #############################################################################
1631 sub OutputVariable {
1632 my ($symbol, $declaration) = @_;
1633 my $id = &CreateValidSGMLID ($symbol);
1634 my $condition = &MakeConditionDescription ($symbol);
1637 if ($declaration =~ m/^\s*extern\s+((const\s+|unsigned\s+)*\w+)(\s+\*+|\*+|\s)(\s*)([A-Za-z]\w*)\s*;/) {
1638 my $mod = defined ($1) ? $1 : "";
1639 my $ptr = defined ($3) ? $3 : "";
1640 my $space = defined ($4) ? $4 : "";
1641 $synop = &MakeReturnField("extern") . "$mod$ptr$space<link linkend=\"$id\">$symbol</link>;\n";
1644 $synop = &MakeReturnField("extern") . "<link linkend=\"$id\">$symbol</link>;\n";
1647 my $desc = "<refsect2 id=\"$id\" role=\"variable\"$condition>\n<title>$symbol</title>\n";
1649 $desc .= MakeIndexterms($symbol, $id);
1651 $desc .= OutputSymbolExtraLinks($symbol);
1653 my $decl_out = &CreateValidSGML ($declaration);
1654 $desc .= "<programlisting>$decl_out</programlisting>\n";
1656 $desc .= &MakeDeprecationNote($symbol);
1658 if (defined ($SymbolDocs{$symbol})) {
1659 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1661 $desc .= OutputSymbolTraits ($symbol);
1662 $desc .= "</refsect2>\n";
1663 return ($synop, $desc);
1667 #############################################################################
1668 # Function : OutputFunction
1669 # Description : Returns the synopsis and detailed description of a function.
1670 # Arguments : $symbol - the function.
1671 # $declaration - the declaration of the function.
1672 #############################################################################
1674 sub OutputFunction {
1675 my ($symbol, $declaration, $symbol_type) = @_;
1676 my $id = &CreateValidSGMLID ($symbol);
1677 my $condition = &MakeConditionDescription ($symbol);
1679 # Take out the return type $1 $3 $4
1680 $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//;
1681 my $type_modifier = defined($1) ? $1 : "";
1684 #print "$symbol pointer is $pointer\n";
1685 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1687 #if ($symbol_type eq 'USER_FUNCTION') {
1688 # $start = "typedef ";
1691 # We output const rather than G_CONST_RETURN.
1692 $type_modifier =~ s/G_CONST_RETURN/const/g;
1693 $pointer =~ s/G_CONST_RETURN/const/g;
1694 $pointer =~ s/^\s+/ /g;
1696 my $ret_type_len = length ($start) + length ($type_modifier)
1697 + length ($pointer) + length ($type);
1698 my $ret_type_output;
1700 if ($ret_type_len < $RETURN_TYPE_FIELD_WIDTH) {
1701 $ret_type_output = "$start$type_modifier$xref$pointer"
1702 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
1705 # $ret_type_output = "$start$type_modifier$xref$pointer\n"
1706 # . (' ' x $RETURN_TYPE_FIELD_WIDTH);
1708 $ret_type_output = "$start$type_modifier$xref$pointer ";
1709 $symbol_len = $ret_type_len + 1 - $RETURN_TYPE_FIELD_WIDTH;
1712 $symbol_len += length ($symbol);
1713 my $char1 = my $char2 = my $char3 = "";
1714 if ($symbol_type eq 'USER_FUNCTION') {
1721 my ($symbol_output, $symbol_desc_output);
1722 if ($symbol_len < $SYMBOL_FIELD_WIDTH) {
1723 $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3"
1724 . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1725 $symbol_desc_output = "$char1$char2$symbol$char3"
1726 . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1728 $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3\n"
1729 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1730 $symbol_desc_output = "$char1$char2$symbol$char3\n"
1731 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1734 my $synop = $ret_type_output . $symbol_output . '(';
1735 my $desc = "<refsect2 id=\"$id\" role=\"function\"$condition>\n<title>${symbol} ()</title>\n";
1737 $desc .= MakeIndexterms($symbol, $id);
1739 $desc .= OutputSymbolExtraLinks($symbol);
1741 $desc .= "<programlisting>${ret_type_output}$symbol_desc_output(";
1744 while ($declaration ne "") {
1745 #print "$declaration";
1747 if ($declaration =~ s/^[\s,]+//) {
1748 # skip whitespace and commas
1751 } elsif ($declaration =~ s/^void\s*[,\n]//) {
1755 } elsif ($declaration =~ s/^...\s*[,\n]//) {
1756 if ($param_num == 0) {
1761 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1764 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1768 # allow alphanumerics, '_', '[' & ']' in param names
1769 # Try to match a standard parameter (keep in sync with gtkdoc-mktmpl)
1771 } 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]//) {
1772 my $pre = defined($1) ? $1 : "";
1774 my $ptr = defined($3) ? $3 : "";
1775 my $name = defined($4) ? $4 : "";
1776 my $array = defined($5) ? $5 : "";
1782 if ($ptr && $ptr !~ m/\*$/) { $ptr .= " "; }
1784 #print "$symbol: '$pre' '$type' '$ptr' '$name' '$array'\n";
1786 if (($name eq "") && $pre =~ m/^((un)?signed .*)\s?/ ) {
1792 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1793 my $label = "$pre$xref $ptr$name$array";
1795 #print "$symbol: '$pre' '$type' '$ptr' '$name' '$array'\n";
1797 if ($param_num == 0) {
1802 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1805 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1809 # Try to match parameters which are functions (keep in sync with gtkdoc-mktmpl)
1810 # $1 $2 $3 $4 $5 $7 $8
1811 } 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]//) {
1812 my $mod1 = defined($1) ? $1 : "";
1813 if (defined($2)) { $mod1 .= $2; }
1816 my $mod2 = defined($5) ? $5 : "";
1819 my $func_params = defined($8) ? $8 : "";
1821 #if (!defined($type)) { print "## no type\n"; };
1822 #if (!defined($ptr1)) { print "## no ptr1\n"; };
1823 #if (!defined($func_ptr)) { print "## no func_ptr\n"; };
1824 #if (!defined($name)) { print "## no name\n"; };
1826 if ($ptr1 && $ptr1 !~ m/\*$/) { $ptr1 .= " "; }
1827 $func_ptr =~ s/\s+//g;
1828 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1829 my $label = "$mod1$xref$ptr1$mod2 ($func_ptr$name) ($func_params)";
1831 #print "Type: [$mod1][$xref][$ptr1][$mod2] ([$func_ptr][$name]) ($func_params)\n";
1832 if ($param_num == 0) {
1837 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1840 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1845 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1846 "Can't parse args for function $symbol: $declaration");
1852 $desc .= ");</programlisting>\n";
1854 $desc .= &MakeDeprecationNote($symbol);
1856 my $parameters = &OutputParamDescriptions ("FUNCTION", $symbol);
1857 my $parameters_output = 0;
1859 if (defined ($SymbolDocs{$symbol})) {
1860 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1862 # Try to insert the parameter table at the author's desired position.
1863 # Otherwise we need to tag it onto the end.
1864 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1865 $parameters_output = 1;
1867 $desc .= $symbol_docs;
1870 if ($parameters_output == 0) {
1871 $desc .= $parameters;
1874 $desc .= OutputSymbolTraits ($symbol);
1875 $desc .= "</refsect2>\n";
1876 return ($synop, $desc);
1880 #############################################################################
1881 # Function : OutputParamDescriptions
1882 # Description : Returns the DocBook output describing the parameters of a
1883 # function, macro or signal handler.
1884 # Arguments : $symbol_type - 'FUNCTION', 'MACRO' or 'SIGNAL'. Signal
1885 # handlers have an implicit user_data parameter last.
1886 # $symbol - the name of the function/macro being described.
1887 #############################################################################
1889 sub OutputParamDescriptions {
1890 my ($symbol_type, $symbol) = @_;
1892 if (defined ($SymbolParams{$symbol})) {
1894 my $params = $SymbolParams{$symbol};
1895 my $params_desc = "";
1897 for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
1898 my $param_name = $$params[$j];
1899 my $param_desc = $$params[$j + 1];
1900 my $param_annotations = "";
1902 ($param_desc,$param_annotations) = & ExpandAnnotation($symbol, $param_desc);
1903 $param_desc = &ExpandAbbreviations($symbol, $param_desc);
1904 if ($param_name eq "Returns") {
1905 $returns = "$param_desc$param_annotations";
1907 if ($param_name eq "Varargs") {
1908 $param_name = "...";
1910 $params_desc .= "<varlistentry><term><parameter>$param_name</parameter> :</term>\n<listitem><simpara>$param_desc$param_annotations</simpara></listitem></varlistentry>\n";
1914 # Signals have an implicit user_data parameter which we describe.
1915 if ($symbol_type eq "SIGNAL") {
1916 $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";
1919 # Start a table if we need one.
1920 if ($params_desc || $returns) {
1921 $output .= "<variablelist role=\"params\">\n";
1922 if ($params_desc ne "") {
1923 #$output .= "<varlistentry><term>Parameters:</term><listitem></listitem></varlistentry>\n";
1924 $output .= $params_desc;
1927 # Output the returns info last.
1929 $output .= "<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>$returns</simpara></listitem></varlistentry>\n";
1933 $output .= "</variablelist>";
1940 #############################################################################
1941 # Function : ParseStabilityLevel
1942 # Description : Parses a stability level and outputs a warning if it isn't
1944 # Arguments : $stability - the stability text.
1945 # $file, $line - context for error message
1946 # $message - description of where the level is from, to use in
1947 # any error message.
1948 # Returns : The parsed stability level string.
1949 #############################################################################
1951 sub ParseStabilityLevel {
1952 my ($stability, $file, $line, $message) = @_;
1954 $stability =~ s/^\s*//;
1955 $stability =~ s/\s*$//;
1956 if ($stability =~ m/^stable$/i) {
1957 $stability = "Stable";
1958 } elsif ($stability =~ m/^unstable$/i) {
1959 $stability = "Unstable";
1960 } elsif ($stability =~ m/^private$/i) {
1961 $stability = "Private";
1963 &LogWarning ($file, $line, "$message is $stability.".
1964 "It should be one of these: Stable, Unstable, or Private.");
1970 #############################################################################
1971 # Function : OutputSGMLFile
1972 # Description : Outputs the final DocBook file for one section.
1973 # Arguments : $file - the name of the file.
1974 # $title - the title from the $MODULE-sections.txt file, which
1975 # will be overridden by the title in the template file.
1976 # $section_id - the SGML id to use for the toplevel tag.
1977 # $includes - comma-separates list of include files added at top
1978 # of synopsis, with '<' '>' around them (if not already enclosed in "").
1979 # $synopsis - reference to the DocBook for the Synopsis part.
1980 # $details - reference to the DocBook for the Details part.
1981 # $signal_synop - reference to the DocBook for the Signal Synopsis part
1982 # $signal_desc - reference to the DocBook for the Signal Description part
1983 # $args_synop - reference to the DocBook for the Arg Synopsis part
1984 # $args_desc - reference to the DocBook for the Arg Description part
1985 # $hierarchy - reference to the DocBook for the Object Hierarchy part
1986 # $interfaces - reference to the DocBook for the Interfaces part
1987 # $implementations - reference to the DocBook for the Known Implementations part
1988 # $prerequisites - reference to the DocBook for the Prerequisites part
1989 # $derived - reference to the DocBook for the Derived Interfaces part
1990 # $file_objects - reference to an array of objects in this file
1991 #############################################################################
1993 sub OutputSGMLFile {
1994 my ($file, $title, $section_id, $includes, $synopsis, $details, $signals_synop, $signals_desc, $args_synop, $args_desc, $hierarchy, $interfaces, $implementations, $prerequisites, $derived, $file_objects) = @_;
1996 #print "Output sgml for file $file with title '$title'\n";
1998 # The edited title overrides the one from the sections file.
1999 my $new_title = $SymbolDocs{"$TMPL_DIR/$file:Title"};
2000 if (defined ($new_title) && $new_title !~ m/^\s*$/) {
2001 $title = $new_title;
2002 #print "Found title: $title\n";
2004 my $short_desc = $SymbolDocs{"$TMPL_DIR/$file:Short_Description"};
2005 if (!defined ($short_desc) || $short_desc =~ m/^\s*$/) {
2008 $short_desc = &ExpandAbbreviations("$title:Short_description",
2010 #print "Found short_desc: $short_desc";
2012 my $long_desc = $SymbolDocs{"$TMPL_DIR/$file:Long_Description"};
2013 if (!defined ($long_desc) || $long_desc =~ m/^\s*$/) {
2016 $long_desc = &ExpandAbbreviations("$title:Long_description",
2018 #print "Found long_desc: $long_desc";
2020 my $see_also = $SymbolDocs{"$TMPL_DIR/$file:See_Also"};
2021 if (!defined ($see_also) || $see_also =~ m%^\s*(<para>)?\s*(</para>)?\s*$%) {
2024 $see_also = &ExpandAbbreviations("$title:See_Also", $see_also);
2025 #print "Found see_also: $see_also";
2028 $see_also = "<refsect1 id=\"$section_id.see-also\">\n<title>See Also</title>\n$see_also\n</refsect1>\n";
2030 my $stability = $SymbolDocs{"$TMPL_DIR/$file:Stability_Level"};
2031 if (!defined ($stability) || $stability =~ m/^\s*$/) {
2034 $stability = &ParseStabilityLevel($stability, $file, $., "Section stability level");
2035 #print "Found stability: $stability";
2038 $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$stability, unless otherwise indicated\n</refsect1>\n";
2039 } elsif ($DEFAULT_STABILITY) {
2040 $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$DEFAULT_STABILITY, unless otherwise indicated\n</refsect1>\n";
2043 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
2045 my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
2048 my $include_output = "";
2050 foreach $include (split (/,/, $includes)) {
2051 if ($include =~ m/^\".+\"$/) {
2052 $include_output .= "#include ${include}\n";
2055 $include =~ s/^\s+|\s+$//gs;
2056 $include_output .= "#include <${include}>\n";
2059 if ($include_output ne '') {
2060 $include_output = "\n$include_output\n";
2063 my $extralinks = OutputSectionExtraLinks($title,"Section:$file");
2065 my $old_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT";
2066 my $new_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT.new";
2068 open (OUTPUT, ">$new_sgml_file")
2069 || die "Can't create $new_sgml_file: $!";
2071 my $object_anchors = "";
2072 foreach my $object (@$file_objects) {
2073 next if ($object eq $section_id);
2074 my $id = CreateValidSGMLID($object);
2075 #print "Debug: Adding anchor for $object\n";
2076 $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
2079 # We used to output this, but is messes up our UpdateFileIfChanged code
2080 # since it changes every day (and it is only used in the man pages):
2081 # "<refentry id="$section_id" revision="$mday $month $year">"
2083 if (lc($OUTPUT_FORMAT) eq "xml") {
2084 print OUTPUT $doctype_header;
2088 <refentry id="$section_id">
2090 <refentrytitle role="top_of_page" id="$section_id.top_of_page">$title</refentrytitle>
2091 <manvolnum>3</manvolnum>
2092 <refmiscinfo>\U$MODULE\E Library</refmiscinfo>
2095 <refname>$title</refname>
2096 <refpurpose>$short_desc</refpurpose>
2099 <refsynopsisdiv id="$section_id.synopsis" role="synopsis">
2100 <title role="synopsis.title">Synopsis</title>
2102 <synopsis>$include_output$${synopsis}</synopsis>
2104 $$hierarchy$$prerequisites$$derived$$interfaces$$implementations$$args_synop$$signals_synop
2105 <refsect1 id="$section_id.description" role="desc">
2106 <title role="desc.title">Description</title>
2107 $extralinks$long_desc
2109 <refsect1 id="$section_id.details" role="details">
2110 <title role="details.title">Details</title>
2113 $$args_desc$$signals_desc$see_also
2118 return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2122 #############################################################################
2123 # Function : OutputExtraFile
2124 # Description : Copies an "extra" DocBook file into the output directory,
2125 # expanding abbreviations
2126 # Arguments : $file - the source file.
2127 #############################################################################
2128 sub OutputExtraFile {
2133 ($basename = $file) =~ s!^.*/!!;
2135 my $old_sgml_file = "$SGML_OUTPUT_DIR/$basename";
2136 my $new_sgml_file = "$SGML_OUTPUT_DIR/$basename.new";
2140 open(EXTRA_FILE, "<$file") || die "Can't open $file";
2144 $contents = <EXTRA_FILE>;
2147 open (OUTPUT, ">$new_sgml_file")
2148 || die "Can't create $new_sgml_file: $!";
2150 print OUTPUT &ExpandAbbreviations ("$basename file", $contents);
2153 return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2155 #############################################################################
2156 # Function : OutputBook
2157 # Description : Outputs the SGML entities that need to be included into the
2158 # main SGML file for the module.
2159 # Arguments : $book_top - the declarations of the entities, which are added
2160 # at the top of the main SGML file.
2161 # $book_bottom - the references to the entities, which are
2162 # added in the main SGML file at the desired position.
2163 #############################################################################
2166 my ($book_top, $book_bottom) = @_;
2168 my $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top";
2169 my $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top.new";
2171 open (OUTPUT, ">$new_file")
2172 || die "Can't create $new_file: $!";
2173 print OUTPUT $book_top;
2176 &UpdateFileIfChanged ($old_file, $new_file, 0);
2179 $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom";
2180 $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom.new";
2182 open (OUTPUT, ">$new_file")
2183 || die "Can't create $new_file: $!";
2184 print OUTPUT $book_bottom;
2187 &UpdateFileIfChanged ($old_file, $new_file, 0);
2190 # If the main SGML file hasn't been created yet, we create it here.
2191 # The user can tweak it later.
2192 if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
2193 open (OUTPUT, ">$MAIN_SGML_FILE")
2194 || die "Can't create $MAIN_SGML_FILE: $!";
2196 if (lc($OUTPUT_FORMAT) eq "xml") {
2198 <?xml version="1.0"?>
2199 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
2200 "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
2202 <!ENTITY % local.common.attrib "xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'">
2208 <!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
2217 <title>$MODULE Reference Manual</title>
2219 for $MODULE [VERSION].
2220 The latest version of this documentation can be found on-line at
2221 <ulink role="online-location" url="http://[SERVER]/$MODULE/index.html">http://[SERVER]/$MODULE/</ulink>.
2226 <title>[Insert title here]</title>
2230 if (-e $OBJECT_TREE_FILE) {
2232 <chapter id="object-tree">
2233 <title>Object Hierarchy</title>
2234 <xi:include href="xml/tree_index.sgml"/>
2240 <index id="api-index-full">
2241 <title>API Index</title>
2242 <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
2245 <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
2254 #############################################################################
2255 # Function : CreateValidSGML
2256 # Description : This turns any chars which are used in SGML into entities,
2257 # e.g. '<' into '<'
2258 # Arguments : $text - the text to turn into proper SGML.
2259 #############################################################################
2261 sub CreateValidSGML {
2263 $text =~ s/&/&/g; # Do this first, or the others get messed up.
2264 $text =~ s/</</g;
2265 $text =~ s/>/>/g;
2266 # browers render single tabs inconsistently
2267 $text =~ s/([^\s])\t([^\s])/$1 $2/g;
2271 #############################################################################
2272 # Function : ConvertSGMLChars
2273 # Description : This is used for text in source code comment blocks, to turn
2274 # chars which are used in SGML into entities, e.g. '<' into
2275 # '<'. Depending on $SGML_MODE, this is done
2276 # unconditionally or only if the character doesn't seem to be
2277 # part of an SGML construct (tag or entity reference).
2278 # Arguments : $text - the text to turn into proper SGML.
2279 #############################################################################
2281 sub ConvertSGMLChars {
2282 my ($symbol, $text) = @_;
2285 # For the SGML mode only convert to entities outside CDATA sections.
2286 return &ModifyXMLElements ($text, $symbol,
2287 "<!\\[CDATA\\[|<programlisting[^>]*>",
2288 \&ConvertSGMLCharsEndTag,
2289 \&ConvertSGMLCharsCallback);
2291 # For the simple non-sgml mode, convert to entities everywhere.
2292 $text =~ s/&/&/g; # Do this first, or the others get messed up.
2293 $text =~ s/</</g;
2294 $text =~ s/>/>/g;
2300 sub ConvertSGMLCharsEndTag {
2301 if ($_[0] eq "<!\[CDATA\[") {
2304 return "</programlisting>";
2308 sub ConvertSGMLCharsCallback {
2309 my ($text, $symbol, $tag) = @_;
2311 if ($tag =~ m/^<programlisting/) {
2312 # We can handle <programlisting> specially here.
2313 return &ModifyXMLElements ($text, $symbol,
2315 \&ConvertSGMLCharsEndTag,
2316 \&ConvertSGMLCharsCallback2);
2317 } elsif ($tag eq "") {
2318 # If we're not in CDATA convert to entities.
2319 $text =~ s/&(?![a-zA-Z#]+;)/&/g; # Do this first, or the others get messed up.
2320 $text =~ s/<(?![a-zA-Z\/!])/</g;
2321 $text =~ s/(?<![a-zA-Z0-9"'\/-])>/>/g;
2323 # Handle "#include <xxxxx>"
2324 $text =~ s/#include(\s+)<([^>]+)>/#include$1<$2>/g;
2330 sub ConvertSGMLCharsCallback2 {
2331 my ($text, $symbol, $tag) = @_;
2333 # If we're not in CDATA convert to entities.
2334 # We could handle <programlisting> differently, though I'm not sure it helps.
2336 # replace only if its not a tag
2337 $text =~ s/&(?![a-zA-Z#]+;)/&/g; # Do this first, or the others get messed up.
2338 $text =~ s/<(?![a-zA-Z\/!])/</g;
2339 $text =~ s/(?<![a-zA-Z0-9"'\/-])>/>/g;
2341 # Handle "#include <xxxxx>"
2342 $text =~ s/#include(\s+)<([^>]+)>/#include$1<$2>/g;
2348 #############################################################################
2349 # Function : ExpandAnnotation
2350 # Description : This turns annotations into acrony tags.
2351 # Arguments : $symbol - the symbol being documented, for error messages.
2352 # $text - the text to expand.
2353 #############################################################################
2354 sub ExpandAnnotation {
2355 my ($symbol, $param_desc) = @_;
2356 my $param_annotations = "";
2358 if ($param_desc =~ m%\s*\((.*)\):%) {
2361 my $annotation_extra = "";
2364 @annotations = split(/\)\s*\(/,$1);
2365 foreach $annotation (@annotations) {
2366 # need to search for the longest key-match in %AnnotationDefinition
2368 my $match_annotation="";
2370 foreach $annotationdef (keys %AnnotationDefinition) {
2371 if ($annotation =~ m/^$annotationdef/) {
2372 if (length($annotationdef)>$match_length) {
2373 $match_length=length($annotationdef);
2374 $match_annotation=$annotationdef;
2378 if ($match_annotation ne "") {
2379 if ($annotation =~ m%$match_annotation\s+(.*)%) {
2380 $annotation_extra = " $1";
2382 $AnnotationsUsed{$match_annotation} = 1;
2383 $param_annotations .= "<acronym>$match_annotation</acronym>$annotation_extra. ";
2386 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2387 "unknown annotation \"$annotation\" in documentation for $symbol.");
2388 $param_annotations=$annotation;
2392 $param_desc =~ m/^(.*)\.*\s*$/;
2393 $param_desc = "$1. ";
2395 return ($param_desc, $param_annotations);
2398 #############################################################################
2399 # Function : ExpandAbbreviations
2400 # Description : This turns the abbreviations function(), macro(), @param,
2401 # %constant, and #symbol into appropriate DocBook markup.
2402 # CDATA sections and <programlisting> parts are skipped.
2403 # Arguments : $symbol - the symbol being documented, for error messages.
2404 # $text - the text to expand.
2405 #############################################################################
2407 sub ExpandAbbreviations {
2408 my ($symbol, $text) = @_;
2410 # Convert "|[" and "]|" into the start and end of program listing examples.
2411 $text =~ s%\|\[%<informalexample><programlisting>%g;
2412 $text =~ s%\]\|%</programlisting></informalexample>%g;
2413 # TODO: check for a xml comment after |[ and pick the language attribute from
2416 # keep CDATA unmodified, preserve ulink tags (ideally we preseve all tags
2418 return &ModifyXMLElements ($text, $symbol,
2419 "<!\\[CDATA\\[|<ulink[^>]*>|<programlisting[^>]*>|<!DOCTYPE",
2420 \&ExpandAbbreviationsEndTag,
2421 \&ExpandAbbreviationsCallback);
2425 # Returns the end tag corresponding to the given start tag.
2426 sub ExpandAbbreviationsEndTag {
2427 my ($start_tag) = @_;
2429 if ($start_tag eq "<!\[CDATA\[") {
2431 } elsif ($start_tag eq "<!DOCTYPE") {
2433 } elsif ($start_tag =~ m/<(\w+)/) {
2438 # Called inside or outside each CDATA or <programlisting> section.
2439 sub ExpandAbbreviationsCallback {
2440 my ($text, $symbol, $tag) = @_;
2442 if ($tag =~ m/^<programlisting/) {
2443 # Handle any embedded CDATA sections.
2444 return &ModifyXMLElements ($text, $symbol,
2446 \&ExpandAbbreviationsEndTag,
2447 \&ExpandAbbreviationsCallback2);
2448 } elsif ($tag eq "") {
2449 # We are outside any CDATA or <programlisting> sections, so we expand
2450 # any gtk-doc abbreviations.
2452 # Convert 'function()' or 'macro()'.
2453 # if there is abc_*_def() we don't want to make a link to _def()
2454 # FIXME: also handle abc(....) : but that would need to be done recursively :/
2455 $text =~ s/([^\*.\w])(\w+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2456 # handle #Object.func()
2457 $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2459 # Convert '@param', but not '\@param'.
2460 $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)/$1<parameter>$2<\/parameter>/g;
2461 $text =~ s/\\\@/\@/g;
2463 # Convert '%constant', but not '\%constant'.
2464 # Also allow negative numbers, e.g. %-1.
2465 $text =~ s/(\A|[^\\])\%(-?\w+)/$1.&MakeXRef($2, &tagify($2, "literal"));/eg;
2466 $text =~ s/\\\%/\%/g;
2468 # Convert '#symbol', but not '\#symbol'.
2469 $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)/$1.&MakeHashXRef($2, "type");/eg;
2473 # FIXME: should we skip urls that are already tagged? (e.g. <literal>http://...</literal>)
2474 # this is apparently also called for markup and not just for plain text
2476 #$text =~ s%(http|https|ftp)://(.*?)((?:\s|,|\)|\]|\<|\.\s))%<ulink url="$1://$2">$2</ulink>$3%g;
2482 # This is called inside a <programlisting>
2483 sub ExpandAbbreviationsCallback2 {
2484 my ($text, $symbol, $tag) = @_;
2487 # We are inside a <programlisting> but outside any CDATA sections,
2488 # so we expand any gtk-doc abbreviations.
2489 # FIXME: why is this different from &ExpandAbbreviationsCallback(),
2490 # why not just call it
2491 $text =~ s/#(\w+)/&MakeHashXRef($1, "");/eg;
2498 my ($symbol, $tag) = @_;;
2501 # Check for things like '#include', '#define', and skip them.
2502 if ($PreProcessorDirectives{$symbol}) {
2506 # Get rid of any special '-struct' suffix.
2507 $text =~ s/-struct$//;
2509 # If the symbol is in the form "Object::signal", then change the symbol to
2510 # "Object-signal" and use "signal" as the text.
2511 if ($symbol =~ s/::/-/) {
2515 # If the symbol is in the form "Object:property", then change the symbol to
2516 # "Object--property" and use "property" as the text.
2517 if ($symbol =~ s/:/--/) {
2522 $text = tagify ($text, $tag);
2525 return &MakeXRef($symbol, $text);
2529 #############################################################################
2530 # Function : ModifyXMLElements
2531 # Description : Looks for given XML element tags within the text, and calls
2532 # the callback on pieces of text inside & outside those elements.
2533 # Used for special handling of text inside things like CDATA
2534 # and <programlisting>.
2535 # Arguments : $text - the text.
2536 # $symbol - the symbol currently being documented (only used for
2538 # $start_tag_regexp - the regular expression to match start tags.
2539 # e.g. "<!\\[CDATA\\[|<programlisting[^>]*>" to match
2540 # CDATA sections or programlisting elements.
2541 # $end_tag_func - function which is passed the matched start tag
2542 # and should return the appropriate end tag string.
2543 # $callback - callback called with each part of the text. It is
2544 # called with a piece of text, the symbol being
2545 # documented, and the matched start tag or "" if the text
2546 # is outside the XML elements being matched.
2547 #############################################################################
2548 sub ModifyXMLElements {
2549 my ($text, $symbol, $start_tag_regexp, $end_tag_func, $callback) = @_;
2550 my ($before_tag, $start_tag, $end_tag_regexp, $end_tag);
2553 while ($text =~ m/$start_tag_regexp/s) {
2554 $before_tag = $`; # Prematch for last successful match string
2555 $start_tag = $&; # Last successful match
2556 $text = $'; # Postmatch for last successful match string
2558 $result .= &$callback ($before_tag, $symbol, "");
2559 $result .= $start_tag;
2561 # get the mathing end-tag for current tag
2562 $end_tag_regexp = &$end_tag_func ($start_tag);
2564 if ($text =~ m/$end_tag_regexp/s) {
2569 $result .= &$callback ($before_tag, $symbol, $start_tag);
2570 $result .= $end_tag;
2572 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2573 "Can't find tag end: $end_tag_regexp in docs for: $symbol.");
2574 # Just assume it is all inside the tag.
2575 $result .= &$callback ($text, $symbol, $start_tag);
2580 # Handle any remaining text outside the tags.
2581 $result .= &$callback ($text, $symbol, "");
2590 # Adds a tag around some text.
2591 # e.g tagify("Text", "literal") => "<literal>Text</literal>".
2593 my ($text, $elem) = @_;
2594 return "<" . $elem . ">" . $text . "</" . $elem . ">";
2598 #############################################################################
2599 # Function : MakeXRef
2600 # Description : This returns a cross-reference link to the given symbol.
2601 # Though it doesn't try to do this for a few standard C types
2602 # that it knows won't be in the documentation.
2603 # Arguments : $symbol - the symbol to try to create a XRef to.
2604 # $text - text text to put inside the XRef, defaults to $symbol
2605 #############################################################################
2608 my ($symbol, $text) = ($_[0], $_[1]);
2610 $symbol =~ s/^\s+//;
2611 $symbol =~ s/\s+$//;
2613 if (!defined($text)) {
2616 # Get rid of special '-struct' suffix.
2617 $text =~ s/-struct$//;
2620 if ($symbol =~ m/ /) {
2624 #print "Getting type link for $symbol -> $text\n";
2626 my $symbol_id = &CreateValidSGMLID ($symbol);
2627 return "<link linkend=\"$symbol_id\">$text</link>";
2631 #############################################################################
2632 # Function : MakeIndexterms
2633 # Description : This returns a indexterm elements for the given symbol
2634 # Arguments : $symbol - the symbol to create indexterms for
2635 #############################################################################
2637 sub MakeIndexterms {
2638 my ($symbol, $id) = @_;
2642 # make the index useful, by ommiting the namespace when sorting
2643 if ($NAME_SPACE ne "") {
2644 if ($symbol =~ m/^$NAME_SPACE\_?(.*)/i) {
2645 $sortas=" sortas=\"$1\"";
2649 if (exists $Deprecated{$symbol}) {
2650 $terms .= "<indexterm zone=\"$id\" role=\"deprecated\"><primary$sortas>$symbol</primary></indexterm>";
2651 $IndexEntriesDeprecated{$symbol}=$id;
2652 $IndexEntriesFull{$symbol}=$id;
2654 if (exists $Since{$symbol}) {
2655 my $since = $Since{$symbol};
2659 $terms .= "<indexterm zone=\"$id\" role=\"$since\"><primary$sortas>$symbol</primary></indexterm>";
2661 $IndexEntriesSince{$symbol}=$id;
2662 $IndexEntriesFull{$symbol}=$id;
2665 $terms .= "<indexterm zone=\"$id\"><primary$sortas>$symbol</primary></indexterm>";
2666 $IndexEntriesFull{$symbol}=$id;
2672 #############################################################################
2673 # Function : MakeDeprecationNote
2674 # Description : This returns a deprecation warning for the given symbol.
2675 # Arguments : $symbol - the symbol to try to create a warning for.
2676 #############################################################################
2678 sub MakeDeprecationNote {
2679 my ($symbol) = $_[0];
2682 if (exists $Deprecated{$symbol}) {
2683 $desc .= "<warning>";
2685 if ($Deprecated{$symbol} =~ /^\s*([0-9\.]+)\s*:/) {
2686 $desc .= "<para><literal>$symbol</literal> has been deprecated since version $1 and should not be used in newly-written code.";
2688 $desc .= "<para><literal>$symbol</literal> is deprecated and should not be used in newly-written code.";
2690 if ($Deprecated{$symbol} ne "") {
2691 $note = &ExpandAbbreviations($symbol, $Deprecated{$symbol});
2692 $note =~ s/^\s*([0-9\.]+)\s*:\s*//;
2695 $note =~ s%\n{2,}%\n</para>\n<para>\n%g;
2696 $desc .= " " . $note;
2698 $desc .= "</para></warning>\n";
2703 #############################################################################
2704 # Function : MakeConditionDescription
2705 # Description : This returns a sumary of conditions for the given symbol.
2706 # Arguments : $symbol - the symbol to try to create the sumary.
2707 #############################################################################
2709 sub MakeConditionDescription {
2710 my ($symbol) = $_[0];
2713 if (exists $Deprecated{$symbol}) {
2718 if ($Deprecated{$symbol} =~ /^\s*(.*?)\s*$/) {
2719 $desc .= "deprecated:$1";
2721 $desc .= "deprecated";
2725 if (exists $Since{$symbol}) {
2730 if ($Since{$symbol} =~ /^\s*(.*?)\s*$/) {
2731 $desc .= "since:$1";
2737 if (exists $StabilityLevel{$symbol}) {
2741 $desc .= "stability:".$StabilityLevel{$symbol};
2745 $desc=" condition=\"".$desc."\"";
2746 #print "condition for '$symbol' = '$desc'\n";
2751 #############################################################################
2752 # Function : GetHierarchy
2753 # Description : Returns the DocBook output describing the ancestors and
2754 # immediate children of a GObject subclass. It uses the
2755 # global @Objects and @ObjectLevels arrays to walk the tree.
2756 # Arguments : $object - the GtkObject subclass.
2757 #############################################################################
2762 # Find object in the objects array.
2768 for ($i = 0; $i < @Objects; $i++) {
2770 if ($ObjectLevels[$i] <= $level) {
2773 elsif ($ObjectLevels[$i] == $level + 1) {
2774 push (@children, $Objects[$i]);
2777 elsif ($Objects[$i] eq $object) {
2780 $level = $ObjectLevels[$i];
2787 # Walk up the hierarchy, pushing ancestors onto the ancestors array.
2789 push (@ancestors, $object);
2790 #print "Level: $level\n";
2791 while ($level > 1) {
2793 if ($ObjectLevels[$j] < $level) {
2794 push (@ancestors, $Objects[$j]);
2795 $level = $ObjectLevels[$j];
2796 #print "Level: $level\n";
2800 # Output the ancestors list, indented and with links.
2801 my $hierarchy = "<synopsis>\n";
2803 for ($i = $#ancestors; $i >= 0; $i--) {
2805 # Don't add a link to the current widget, i.e. when i == 0.
2807 my $ancestor_id = &CreateValidSGMLID ($ancestors[$i]);
2808 $link_text = "<link linkend=\"$ancestor_id\">$ancestors[$i]</link>";
2810 $link_text = "$ancestors[$i]";
2813 $hierarchy .= " $link_text\n";
2815 # $hierarchy .= ' ' x ($level * 6 - 3) . "|\n";
2816 $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
2820 for ($i = 0; $i <= $#children; $i++) {
2821 my $id = &CreateValidSGMLID ($children[$i]);
2822 my $link_text = "<link linkend=\"$id\">$children[$i]</link>";
2823 $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
2825 $hierarchy .= "</synopsis>\n";
2831 #############################################################################
2832 # Function : GetInterfaces
2833 # Description : Returns the DocBook output describing the interfaces
2834 # implemented by a class. It uses the global %Interfaces hash.
2835 # Arguments : $object - the GtkObject subclass.
2836 #############################################################################
2843 # Find object in the objects array.
2844 if (exists($Interfaces{$object})) {
2845 my @ifaces = split(' ', $Interfaces{$object});
2850 for ($i = 0; $i <= $#ifaces; $i++) {
2851 my $id = &CreateValidSGMLID ($ifaces[$i]);
2852 $text .= " <link linkend=\"$id\">$ifaces[$i]</link>";
2853 if ($i < $#ifaces - 1) {
2856 elsif ($i < $#ifaces) {
2871 #############################################################################
2872 # Function : GetImplementations
2873 # Description : Returns the DocBook output describing the implementations
2874 # of an interface. It uses the global %Interfaces hash.
2875 # Arguments : $object - the GtkObject subclass.
2876 #############################################################################
2878 sub GetImplementations {
2883 foreach my $key (keys %Interfaces) {
2884 if ($Interfaces{$key} =~ /\b$object\b/) {
2885 push (@impls, $key);
2891 $object is implemented by
2893 for ($i = 0; $i <= $#impls; $i++) {
2894 my $id = &CreateValidSGMLID ($impls[$i]);
2895 $text .= " <link linkend=\"$id\">$impls[$i]</link>";
2896 if ($i < $#impls - 1) {
2899 elsif ($i < $#impls) {
2914 #############################################################################
2915 # Function : GetPrerequisites
2916 # Description : Returns the DocBook output describing the prerequisites
2917 # of an interface. It uses the global %Prerequisites hash.
2918 # Arguments : $iface - the interface.
2919 #############################################################################
2921 sub GetPrerequisites {
2926 if (exists($Prerequisites{$iface})) {
2931 my @prereqs = split(' ', $Prerequisites{$iface});
2932 for ($i = 0; $i <= $#prereqs; $i++) {
2933 my $id = &CreateValidSGMLID ($prereqs[$i]);
2934 $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
2935 if ($i < $#prereqs - 1) {
2938 elsif ($i < $#prereqs) {
2952 #############################################################################
2953 # Function : GetDerived
2954 # Description : Returns the DocBook output describing the derived interfaces
2955 # of an interface. It uses the global %Prerequisites hash.
2956 # Arguments : $iface - the interface.
2957 #############################################################################
2965 foreach my $key (keys %Prerequisites) {
2966 if ($Prerequisites{$key} =~ /\b$iface\b/) {
2967 push (@derived, $key);
2970 if ($#derived >= 0) {
2973 $iface is required by
2975 for ($i = 0; $i <= $#derived; $i++) {
2976 my $id = &CreateValidSGMLID ($derived[$i]);
2977 $text .= " <link linkend=\"$id\">$derived[$i]</link>";
2978 if ($i < $#derived - 1) {
2981 elsif ($i < $#derived) {
2996 #############################################################################
2997 # Function : GetSignals
2998 # Description : Returns the synopsis and detailed description DocBook output
2999 # for the signal handlers of a given GtkObject subclass.
3000 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
3001 #############################################################################
3009 for ($i = 0; $i <= $#SignalObjects; $i++) {
3010 if ($SignalObjects[$i] eq $object) {
3011 #print "Found signal: $SignalNames[$i]\n";
3012 my $name = $SignalNames[$i];
3013 my $symbol = "${object}::${name}";
3014 my $id = &CreateValidSGMLID ("$object-$name");
3016 my $pad = ' ' x (46 - length($name));
3017 $synop .= " "<link linkend=\"$id\">$name</link>"$pad ";
3019 $desc .= "<refsect2 id=\"$id\" role=\"signal\"><title>The <literal>"$name"</literal> signal</title>\n";
3020 $desc .= MakeIndexterms($symbol, $id);
3022 $desc .= OutputSymbolExtraLinks($symbol);
3024 $desc .= "<programlisting>";
3026 $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
3027 my $type_modifier = defined($1) ? $1 : "";
3030 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
3032 my $ret_type_len = length ($type_modifier) + length ($pointer)
3034 my $ret_type_output = "$type_modifier$xref$pointer"
3035 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
3037 $desc .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
3039 my $sourceparams = $SourceSymbolParams{$symbol};
3040 my @params = split ("\n", $SignalPrototypes[$i]);
3043 my $type_len = length("gpointer");
3044 my $name_len = length("user_data");
3045 # do two passes, the first one is to calculate padding
3046 for ($l = 0; $l < 2; $l++) {
3047 for ($j = 0; $j <= $#params; $j++) {
3048 # allow alphanumerics, '_', '[' & ']' in param names
3049 if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
3052 if (defined($sourceparams)) {
3053 $name = $$sourceparams[$PARAM_FIELD_COUNT * $j];
3058 if (!defined($name)) {
3062 if (length($type) + length($pointer) > $type_len) {
3063 $type_len = length($type) + length($pointer);
3065 if (length($name) > $name_len) {
3066 $name_len = length($name);
3070 $xref = &MakeXRef ($type, &tagify($type, "type"));
3071 $pad = ' ' x ($type_len - length($type) - length($pointer));
3072 $desc .= "$xref$pad $pointer$name,\n";
3073 $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
3076 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3077 "Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]");
3081 $xref = &MakeXRef ("gpointer", &tagify("gpointer", "type"));
3082 $pad = ' ' x ($type_len - length("gpointer"));
3083 $desc .= "$xref$pad user_data)";
3085 my $flags = $SignalFlags[$i];
3086 my $flags_string = "";
3088 if (defined ($flags)) {
3089 if ($flags =~ m/f/) {
3090 $flags_string = "Run First";
3092 elsif ($flags =~ m/l/) {
3093 $flags_string = "Run Last";
3095 elsif ($flags =~ m/c/) {
3096 $flags_string = "Cleanup";
3098 if ($flags =~ m/r/) {
3099 if ($flags_string) { $flags_string .= " / "; }
3100 $flags_string .= "No Recursion";
3102 if ($flags =~ m/d/) {
3103 if ($flags_string) { $flags_string .= " / "; }
3104 $flags_string .= "Has Details";
3106 if ($flags =~ m/a/) {
3107 if ($flags_string) { $flags_string .= " / "; }
3108 $flags_string .= "Action";
3110 if ($flags =~ m/h/) {
3111 if ($flags_string) { $flags_string .= " / "; }
3112 $flags_string .= "No Hooks";
3118 $synop .= ": $flags_string\n";
3120 $pad = ' ' x (5 + $name_len - length("user_data"));
3121 $desc .= "$pad : $flags_string</programlisting>\n";
3126 $desc .= "</programlisting>\n";
3129 $desc .= &MakeDeprecationNote($symbol);
3131 my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
3132 my $parameters_output = 0;
3134 $AllSymbols{$symbol} = 1;
3135 if (defined ($SymbolDocs{$symbol})) {
3136 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3138 # Try to insert the parameter table at the author's desired
3139 # position. Otherwise we need to tag it onto the end.
3140 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
3141 $parameters_output = 1;
3143 $desc .= $symbol_docs;
3145 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
3146 $AllDocumentedSymbols{$symbol} = 1;
3150 if ($parameters_output == 0) {
3151 $desc .= $parameters;
3153 $desc .= OutputSymbolTraits ($symbol);
3154 $desc .= "</refsect2>";
3157 return ($synop, $desc);
3161 #############################################################################
3162 # Function : GetArgs
3163 # Description : Returns the synopsis and detailed description DocBook output
3164 # for the Args of a given GtkObject subclass.
3165 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
3166 #############################################################################
3172 my $child_synop = "";
3173 my $child_desc = "";
3174 my $style_synop = "";
3175 my $style_desc = "";
3178 for ($i = 0; $i <= $#ArgObjects; $i++) {
3179 if ($ArgObjects[$i] eq $object) {
3180 #print "Found arg: $ArgNames[$i]\n";
3181 my $name = $ArgNames[$i];
3182 my $flags = $ArgFlags[$i];
3183 my $flags_string = "";
3187 if ($flags =~ m/c/) {
3188 $kind = "child property";
3191 elsif ($flags =~ m/s/) {
3192 $kind = "style property";
3199 # Remember only one colon so we don't clash with signals.
3200 my $symbol = "${object}:${name}";
3201 # use two dashes and ev. an extra separator here for the same reason.
3202 my $id = &CreateValidSGMLID ("$object--$id_sep$name");
3204 my $type = $ArgTypes[$i];
3206 my $range = $ArgRanges[$i];
3207 my $range_output = CreateValidSGML ($range);
3208 my $default = $ArgDefaults[$i];
3209 my $default_output = CreateValidSGML ($default);
3211 if ($type eq "GtkString") {
3214 if ($type eq "GtkSignal") {
3215 $type = "GtkSignalFunc, gpointer";
3216 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
3217 . &MakeXRef ("gpointer");
3218 } elsif ($type =~ m/^(\w+)\*$/) {
3219 $type_output = &MakeXRef ($1, &tagify($1, "type")) . "*";
3221 $type_output = &MakeXRef ($type, &tagify($type, "type"));
3224 if ($flags =~ m/r/) {
3225 $flags_string = "Read";
3227 if ($flags =~ m/w/) {
3228 if ($flags_string) { $flags_string .= " / "; }
3229 $flags_string .= "Write";
3231 if ($flags =~ m/x/) {
3232 if ($flags_string) { $flags_string .= " / "; }
3233 $flags_string .= "Construct";
3235 if ($flags =~ m/X/) {
3236 if ($flags_string) { $flags_string .= " / "; }
3237 $flags_string .= "Construct Only";
3240 $AllSymbols{$symbol} = 1;
3242 if (defined($SymbolDocs{$symbol}) &&
3243 !IsEmptyDoc($SymbolDocs{$symbol})) {
3244 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3245 #print ".. [$SymbolDocs{$symbol}][$blurb]\n";
3246 $AllDocumentedSymbols{$symbol} = 1;
3249 if (!($ArgBlurbs[$i] eq "")) {
3250 $AllDocumentedSymbols{$symbol} = 1;
3252 # FIXME: print a warning?
3253 #print ".. no description\n";
3255 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
3258 my $pad1 = " " x (24 - length ($name));
3259 my $pad2 = " " x (20 - length ($type));
3261 my $arg_synop = " "<link linkend=\"$id\">$name</link>"$pad1 $type_output $pad2 : $flags_string\n";
3262 my $arg_desc = "<refsect2 id=\"$id\" role=\"property\"><title>The <literal>"$name"</literal> $kind</title>\n";
3263 $arg_desc .= MakeIndexterms($symbol, $id);
3265 $arg_desc .= OutputSymbolExtraLinks($symbol);
3267 $arg_desc .= "<programlisting> "$name"$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
3268 $arg_desc .= &MakeDeprecationNote($symbol);
3269 $arg_desc .= $blurb;
3271 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
3273 if ($default ne "") {
3274 $arg_desc .= "<para>Default value: $default_output</para>\n";
3276 $arg_desc .= OutputSymbolTraits ($symbol);
3277 $arg_desc .= "</refsect2>\n";
3279 if ($flags =~ m/c/) {
3280 $child_synop .= $arg_synop;
3281 $child_desc .= $arg_desc;
3283 elsif ($flags =~ m/s/) {
3284 $style_synop .= $arg_synop;
3285 $style_desc .= $arg_desc;
3288 $synop .= $arg_synop;
3293 return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
3297 #############################################################################
3298 # Function : ReadSourceDocumentation
3299 # Description : This reads in the documentation embedded in comment blocks
3300 # in the source code (for Gnome).
3302 # Parameter descriptions override any in the template files.
3303 # Function descriptions are placed before any description from
3304 # the template files.
3306 # It recursively descends the source directory looking for .c
3307 # files and scans them looking for specially-formatted comment
3310 # Arguments : $source_dir - the directory to scan.
3311 #############m###############################################################
3313 sub ReadSourceDocumentation {
3314 my ($source_dir) = @_;
3315 my ($file, $dir, @suffix_list, $suffix);
3316 #print "Scanning source directory: $source_dir\n";
3318 # This array holds any subdirectories found.
3321 @suffix_list = split (/,/, $SOURCE_SUFFIXES);
3323 opendir (SRCDIR, $source_dir)
3324 || die "Can't open source directory $source_dir: $!";
3326 foreach $file (readdir (SRCDIR)) {
3327 if ($file =~ /^\./) {
3329 } elsif (-d "$source_dir/$file") {
3330 push (@subdirs, $file);
3331 } elsif (@suffix_list) {
3332 foreach $suffix (@suffix_list) {
3333 if ($file =~ m/\.\Q${suffix}\E$/) {
3334 &ScanSourceFile ("$source_dir/$file");
3337 } elsif ($file =~ m/\.[ch]$/) {
3338 &ScanSourceFile ("$source_dir/$file");
3343 # Now recursively scan the subdirectories.
3344 foreach $dir (@subdirs) {
3345 next if ($IGNORE_FILES =~ m/(\s|^)\Q${dir}\E(\s|$)/);
3346 &ReadSourceDocumentation ("$source_dir/$dir");
3351 #############################################################################
3352 # Function : ScanSourceFile
3353 # Description : Scans one source file looking for specially-formatted comment
3354 # blocks. Later &MergeSourceDocumentation is used to merge any
3355 # documentation found with the documentation already read in
3356 # from the template files.
3358 # Arguments : $file - the file to scan.
3359 #############################################################################
3361 sub ScanSourceFile {
3365 if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
3368 &LogWarning ($file, 1, "Can't find basename for this filename.");
3372 # Check if the basename is in the list of files to ignore.
3373 if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
3377 #print "DEBUG: Scanning $file\n";
3379 open (SRCFILE, $file)
3380 || die "Can't open $file: $!";
3381 my $in_comment_block = 0;
3383 my ($in_description, $in_return, $in_since, $in_stability, $in_deprecated);
3384 my ($description, $return_desc, $return_start, $return_style);
3385 my ($since_desc, $stability_desc, $deprecated_desc);
3387 my $ignore_broken_returns;
3390 # Look for the start of a comment block.
3391 if (!$in_comment_block) {
3392 if (m%^\s*/\*.*\*/%) {
3393 #one-line comment - not gtkdoc
3394 } elsif (m%^\s*/\*\*\s%) {
3395 #print "Found comment block start\n";
3397 $in_comment_block = 1;
3399 # Reset all the symbol data.
3401 $in_description = 0;
3410 $deprecated_desc = "";
3411 $stability_desc = "";
3412 $current_param = -1;
3413 $ignore_broken_returns = 0;
3419 # We're in a comment block. Check if we've found the end of it.
3422 # maybe its not even meant to be a gtk-doc comment?
3423 &LogWarning ($file, $., "Symbol name not found at the start of the comment block.");
3425 # Add the return value description onto the end of the params.
3427 push (@params, "Returns");
3428 push (@params, $return_desc);
3429 if ($return_style eq 'broken') {
3430 &LogWarning ($file, $., "Free-form return value description in $symbol. Use `Returns:' to avoid ambiguities.");
3433 # Convert special SGML characters
3434 $description = &ConvertSGMLChars ($symbol, $description);
3436 for ($k = 1; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3437 $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
3440 # Handle Section docs
3441 if ($symbol =~ m/SECTION:\s*(.*)/) {
3445 if (scalar %KnownSymbols) {
3446 if ((! defined($KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"})) || $KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"} != 1) {
3447 &LogWarning ($file, $., "Section $real_symbol is not defined in the $MODULE-section.txt file.");
3451 #print "SECTION DOCS found in source for : '$real_symbol'\n";
3452 $ignore_broken_returns = 1;
3453 for ($k = 0; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3454 #print " '".$params[$k]."'\n";
3455 $params[$k] = "\L$params[$k]";
3457 if ($params[$k] eq "short_description") {
3458 $key = "$TMPL_DIR/$real_symbol:Short_Description";
3459 } elsif ($params[$k] eq "see_also") {
3460 $key = "$TMPL_DIR/$real_symbol:See_Also";
3461 } elsif ($params[$k] eq "title") {
3462 $key = "$TMPL_DIR/$real_symbol:Title";
3463 } elsif ($params[$k] eq "stability") {
3464 $key = "$TMPL_DIR/$real_symbol:Stability_Level";
3465 } elsif ($params[$k] eq "section_id") {
3466 $key = "$TMPL_DIR/$real_symbol:Section_Id";
3467 } elsif ($params[$k] eq "include") {
3468 $key = "$TMPL_DIR/$real_symbol:Include";
3470 if (defined($key)) {
3471 $SourceSymbolDocs{$key}=$params[$k+1];
3472 $SourceSymbolSourceFile{$key} = $file;
3473 $SourceSymbolSourceLine{$key} = $.;
3476 $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
3477 $SourceSymbolSourceFile{"$TMPL_DIR/$real_symbol:Long_Description"} = $file;
3478 $SourceSymbolSourceLine{"$TMPL_DIR/$real_symbol:Long_Description"} = $.;
3479 #$SourceSymbolTypes{$symbol} = "SECTION";
3481 #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
3482 $SourceSymbolDocs{$symbol} = $description;
3483 $SourceSymbolParams{$symbol} = [ @params ];
3484 # FIXME $SourceSymbolTypes{$symbol} = "STRUCT,SIGNAL,ARG,FUNCTION,MACRO";
3485 #if (defined $DeclarationTypes{$symbol}) {
3486 # $SourceSymbolTypes{$symbol} = $DeclarationTypes{$symbol}
3488 $SourceSymbolSourceFile{$symbol} = $file;
3489 $SourceSymbolSourceLine{$symbol} = $.;
3493 ($since_desc, my @extra_lines) = split ("\n", $since_desc);
3494 $since_desc =~ s/^\s+//;
3495 $since_desc =~ s/\s+$//;
3496 #print "Since($symbol) : [$since_desc]\n";
3497 $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
3498 if(scalar @extra_lines) {
3499 &LogWarning ($file, $., "multi-line since docs found");
3503 if ($stability_desc) {
3504 $stability_desc = &ParseStabilityLevel($stability_desc, $file, $., "Stability level for $symbol");
3505 $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
3508 if ($deprecated_desc) {
3509 if (exists $Deprecated{$symbol}) {
3512 # don't warn for signals and properties
3513 #if ($symbol !~ m/::?(.*)/) {
3514 if (defined $DeclarationTypes{$symbol}) {
3515 &LogWarning ($file, $.,
3516 "$symbol is deprecated in the inline comments, but no deprecation guards were found around the declaration.".
3517 " (See the --deprecated-guards option for gtkdoc-scan.)");
3520 $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
3524 $in_comment_block = 0;
3528 # Get rid of ' * ' at start of every line in the comment block.
3530 # But make sure we don't get rid of the newline at the end.
3534 #print "DEBUG: scanning :$_";
3536 # If we haven't found the symbol name yet, look for it.
3538 if (m%^\s*(SECTION:\s*\S+)%) {
3540 #print "SECTION DOCS found in source for : '$symbol'\n";
3541 $ignore_broken_returns = 1;
3542 } elsif (m%^\s*([\w:-]*\w)\s*:?\s*$%) {
3544 #print "SYMBOL DOCS found in source for : '$symbol'\n";
3549 # If we're in the return value description, add it to the end.
3551 # If we find another valid returns line, we assume that the first
3552 # one was really part of the description.
3553 if (m/^\s*(returns:|return\s+value:)/i) {
3554 if ($return_style eq 'broken') {
3555 $description .= $return_start . $return_desc;
3558 if ($return_style eq 'sane') {
3559 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3561 $return_style = 'sane';
3562 $ignore_broken_returns = 1;
3564 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3565 $description .= $return_start . $return_desc;
3567 $return_style = 'broken';
3569 } elsif (m%^\s*since:%i) {
3573 } elsif (m%^\s*stability:%i) {
3574 $stability_desc = $';
3577 } elsif (m%^\s*deprecated:%i) {
3578 $deprecated_desc = $';
3588 if (m/^\s*(returns:|return\s+value:)/i) {
3589 if ($return_style eq 'broken') {
3590 $description .= $return_start . $return_desc;
3593 if ($return_style eq 'sane') {
3594 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3596 $return_style = 'sane';
3597 $ignore_broken_returns = 1;
3601 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3603 $return_style = 'broken';
3607 } elsif (m%^\s*deprecated:%i) {
3608 $deprecated_desc = $';
3611 } elsif (m%^\s*stability:%i) {
3612 $stability_desc = $';
3621 if ($in_stability) {
3622 if (m/^\s*(returns:|return\s+value:)/i) {
3623 if ($return_style eq 'broken') {
3624 $description .= $return_start . $return_desc;
3627 if ($return_style eq 'sane') {
3628 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3630 $return_style = 'sane';
3631 $ignore_broken_returns = 1;
3635 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3637 $return_style = 'broken';
3641 } elsif (m%^\s*deprecated:%i) {
3642 $deprecated_desc = $';
3645 } elsif (m%^\s*since:%i) {
3650 $stability_desc .= $_;
3655 if ($in_deprecated) {
3656 if (m/^\s*(returns:|return\s+value:)/i) {
3657 if ($return_style eq 'broken') {
3658 $description .= $return_start . $return_desc;
3661 if ($return_style eq 'sane') {
3662 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3664 $return_style = 'sane';
3665 $ignore_broken_returns = 1;
3669 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3671 $return_style = 'broken';
3675 } elsif (m%^\s*since:%i) {
3679 } elsif (m%^\s*stability:%i) {
3680 $stability_desc = $';
3684 $deprecated_desc .= $_;
3689 # If we're in the description part, check for the 'Returns:' line.
3690 # If that isn't found, add the text to the end.
3691 if ($in_description) {
3692 # Get rid of 'Description:'
3693 s%^\s*Description:%%;
3695 if (m/^\s*(returns:|return\s+value:)/i) {
3696 if ($return_style eq 'broken') {
3697 $description .= $return_start . $return_desc;
3700 if ($return_style eq 'sane') {
3701 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3703 $return_style = 'sane';
3704 $ignore_broken_returns = 1;
3708 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3710 $return_style = 'broken';
3714 } elsif (m%^\s*since:%i) {
3718 } elsif (m%^\s*deprecated:%i) {
3719 $deprecated_desc = $';
3722 } elsif (m%^\s*stability:%i) {
3723 $stability_desc = $';
3732 # We must be in the parameters. Check for the empty line below them.
3734 $in_description = 1;
3738 # Look for a parameter name.
3739 if (m%^\s*@(\S+)\s*:%) {
3740 my $param_name = $1;
3741 my $param_desc = $';
3742 #print "Found parameter: $param_name\n";
3743 # Allow '...' as the Varargs parameter.
3744 if ($param_name eq "...") {
3745 $param_name = "Varargs";
3747 if ("\L$param_name" eq "returns") {
3748 $return_style = 'sane';
3749 $ignore_broken_returns = 1;
3751 push (@params, $param_name);
3752 push (@params, $param_desc);
3753 $current_param += $PARAM_FIELD_COUNT;
3757 # We must be in the middle of a parameter description, so add it on
3758 # to the last element in @params.
3759 if ($current_param == -1) {
3760 &LogWarning ($file, $., "Parsing comment block file : parameter expected.");
3762 $params[$#params] .= $_;
3768 #############################################################################
3769 # Function : OutputMissingDocumentation
3770 # Description : Outputs report of documentation coverage to a file
3773 #############################################################################
3775 sub OutputMissingDocumentation {
3776 my $n_documented = 0;
3777 my $n_incomplete = 0;
3783 my $buffer_deprecated = "";
3784 my $buffer_descriptions = "";
3786 open (UNDOCUMENTED, ">$ROOT_DIR/$MODULE-undocumented.txt")
3787 || die "Can't create $ROOT_DIR/$MODULE-undocumented.txt: $!";
3789 foreach $symbol (sort (keys (%AllSymbols))) {
3790 # FIXME: should we print LogWarnings for undocumented stuff?
3792 #my $ssfile = &GetSymbolSourceFile($symbol);
3793 #my $ssline = &GetSymbolSourceLine($symbol);
3794 #my $location = "defined at " . (defined($ssfile)?$ssfile:"?") . ":" . (defined($ssline)?$ssline:"0") . "\n";
3796 if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include|Section_Id)/) {
3798 if (exists ($AllDocumentedSymbols{$symbol})) {
3800 if (exists ($AllIncompleteSymbols{$symbol})) {
3802 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3803 #$buffer .= "\t0: ".$location;
3805 } elsif (exists $Deprecated{$symbol}) {
3806 if (exists ($AllIncompleteSymbols{$symbol})) {
3808 $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3809 #$buffer .= "\t1a: ".$location;
3811 $buffer_deprecated .= $symbol . "\n";
3812 #$buffer .= "\t1b: ".$location;
3815 if (exists ($AllIncompleteSymbols{$symbol})) {
3817 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3818 #$buffer .= "\t2a: ".$location;
3820 $buffer .= $symbol . "\n";
3821 #$buffer .= "\t2b: ".$location;
3824 } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
3826 #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
3827 #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
3828 #print "%%%% $symbol : $len1,$len2\n";
3829 if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
3830 || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
3833 # cut off the leading namespace ($TMPL_DIR)
3834 $symbol =~ m/^.*\/(.*)$/;
3835 $buffer_descriptions .= $1 . "\n";
3840 $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
3845 $percent = ($n_documented / $total) * 100.0;
3848 printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
3849 print UNDOCUMENTED "$n_documented symbols documented.\n";
3850 print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
3851 print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
3853 print UNDOCUMENTED $buffer;
3855 close (UNDOCUMENTED);
3857 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);
3861 #############################################################################
3862 # Function : OutputUndeclaredSymbols
3863 # Description : Outputs symbols that are undeclared yet documented to a file
3866 #############################################################################
3868 sub OutputUndeclaredSymbols {
3869 open(UNDECLARED, ">$ROOT_DIR/$MODULE-undeclared.txt")
3870 || die "Can't create $ROOT_DIR/$MODULE-undeclared.txt";
3872 if (%UndeclaredSymbols) {
3873 print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
3874 print UNDECLARED "\n";
3875 print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
3881 #############################################################################
3882 # Function : OutputAllSymbols
3883 # Description : Outputs list of all symbols to a file
3886 #############################################################################
3888 sub OutputAllSymbols {
3889 my $n_documented = 0;
3895 open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
3896 || die "Can't create $ROOT_DIR/$MODULE-symbols.txt: $!";
3898 foreach $symbol (sort (keys (%AllSymbols))) {
3899 print SYMBOLS $symbol . "\n";
3905 #############################################################################
3906 # Function : OutputSymbolsWithoutSince
3907 # Description : Outputs list of all symbols without a since tag to a file
3910 #############################################################################
3912 sub OutputSymbolsWithoutSince {
3913 my $n_documented = 0;
3919 open (SYMBOLS, ">$ROOT_DIR/$MODULE-nosince.txt")
3920 || die "Can't create $ROOT_DIR/$MODULE-nosince.txt: $!";
3922 foreach $symbol (sort (keys (%SourceSymbolDocs))) {
3923 if (!defined $Since{$symbol}) {
3924 print SYMBOLS $symbol . "\n";
3932 #############################################################################
3933 # Function : MergeSourceDocumentation
3934 # Description : This merges documentation read from a source file into the
3935 # documentation read in from a template file.
3937 # Parameter descriptions override any in the template files.
3938 # Function descriptions are placed before any description from
3939 # the template files.
3942 #############################################################################
3944 sub MergeSourceDocumentation {
3948 if (scalar %SymbolDocs) {
3949 @Symbols=keys (%SymbolDocs);
3950 #print "num existing entries: ".(scalar @Symbols)."\n";
3951 #print " ",$Symbols[0], " ",$Symbols[1],"\n";
3954 # filter scanned declarations, with what we suppress from -sections.txt
3956 foreach $symbol (keys (%Declarations)) {
3957 if (defined($KnownSymbols{$symbol}) && $KnownSymbols{$symbol} == 1) {
3961 # , add the rest from -sections.txt
3962 foreach $symbol (keys (%KnownSymbols)) {
3963 if ($KnownSymbols{$symbol} == 1) {
3967 # and add whats found in the source
3968 foreach $symbol (keys (%SourceSymbolDocs)) {
3971 @Symbols = keys (%tmp);
3972 #print "num source entries: ".(scalar @Symbols)."\n";
3974 foreach $symbol (@Symbols) {
3975 $AllSymbols{$symbol} = 1;
3977 my $have_tmpl_docs = 0;
3979 ## See if the symbol is documented in template
3980 my $tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
3981 my $check_tmpl_doc =$tmpl_doc;
3982 # remove all xml-tags and whitespaces
3983 #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
3984 $check_tmpl_doc =~ s/<.*?>//g;
3985 $check_tmpl_doc =~ s/\s//g;
3987 if ($check_tmpl_doc ne "") {
3988 $have_tmpl_docs = 1;
3989 #print "## [$check_tmpl_doc]\n";
3994 if (exists ($SourceSymbolDocs{$symbol})) {
3995 my $type = $DeclarationTypes {$symbol};
3997 #print "merging [$symbol] from source\n";
3999 my $item = "Parameter";
4000 if (defined ($type)) {
4001 if ($type eq 'STRUCT') {
4003 } elsif ($type eq 'ENUM') {
4005 } elsif ($type eq 'UNION') {
4012 my $src_doc = $SourceSymbolDocs{$symbol};
4013 # remove leading and training whitespaces
4014 $src_doc =~ s/^\s+//;
4015 $src_doc =~ s/\s+$//;
4017 # Don't output warnings for overridden titles as titles are
4018 # automatically generated in the -sections.txt file, and thus they
4019 # are often overridden.
4020 if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
4021 # check if content is different
4022 if ($tmpl_doc ne $src_doc) {
4023 #print "[$tmpl_doc] [$src_doc]\n";
4024 &LogWarning ($SourceSymbolSourceFile{$symbol}, $SourceSymbolSourceLine{$symbol},
4025 "Documentation in template ".$SymbolSourceFile{$symbol}.":".$SymbolSourceLine{$symbol}." for $symbol being overridden by inline comments.");
4029 if ($src_doc ne "") {
4030 $AllDocumentedSymbols{$symbol} = 1;
4033 # Convert <!--PARAMETERS--> with any blank lines around it to
4034 # a </para> followed by <!--PARAMETERS--> followed by <para>.
4035 $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
4037 # If there is a blank line, finish the paragraph and start another.
4038 $src_doc = &ConvertBlankLines ($src_doc, $symbol);
4039 # Do not add <para> to nothing, it breaks missing docs checks.
4040 my $src_doc_para = "";
4042 $src_doc_para = "<para>\n$src_doc</para>\n";
4043 #print "$symbol : [$src_doc][$src_doc_para]\n";
4046 if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
4047 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4048 } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
4049 # For the title/summary/see also section docs we don't want to
4050 # add any <para> tags.
4051 $SymbolDocs{$symbol} = "$src_doc"
4053 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4057 if ($symbol =~ m/.*::.*/) {
4058 # For signals we prefer the param names from the source docs,
4059 # since the ones from the templates are likely to contain the
4060 # artificial argn names which are generated by gtkdoc-scangobj.
4061 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4062 # FIXME: we need to check for empty docs here as well!
4064 # The templates contain the definitive parameter names and order,
4065 # so we will not change that. We only override the actual text.
4066 my $tmpl_params = $SymbolParams{$symbol};
4067 if (!defined ($tmpl_params)) {
4068 #print "No merge needed for $symbol\n";
4069 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4070 # FIXME: we still like to get the number of params and merge
4071 # 1) we would noticed that params have been removed/renamed
4072 # 2) we would catch undocumented params
4073 # params are not (yet) exported in -decl.txt so that we
4074 # could easily grab them :/
4076 my $params = $SourceSymbolParams{$symbol};
4078 #print "Merge needed for $symbol, tmpl_params: ",$#$tmpl_params,", source_params: ",$#$params," \n";
4079 for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4080 my $tmpl_param_name = $$tmpl_params[$j];
4082 # Allow '...' as the Varargs parameter.
4083 if ($tmpl_param_name eq "...") {
4084 $tmpl_param_name = "Varargs";
4087 # Try to find the param in the source comment documentation.
4090 #print " try merge param $tmpl_param_name\n";
4091 for ($k = 0; $k <= $#$params; $k += $PARAM_FIELD_COUNT) {
4092 my $param_name = $$params[$k];
4093 my $param_desc = $$params[$k + 1];
4095 #print " test param $param_name\n";
4096 # We accept changes in case, since the Gnome source
4097 # docs contain a lot of these.
4098 if ("\L$param_name" eq "\L$tmpl_param_name") {
4101 # Override the description.
4102 $$tmpl_params[$j + 1] = $param_desc;
4104 # Set the name to "" to mark it as used.
4110 # If it looks like the parameters are there, but not
4111 # in the right place, try to explain a bit better.
4112 if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
4113 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4114 "Parameters for $symbol must start on the line immediately after the function or macro name.");
4118 # Now we output a warning if parameters have been described which
4120 for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
4121 my $param_name = $$params[$j];
4123 # the template builder cannot detect if a macro returns
4125 if(($type eq "MACRO") && ($param_name eq "Returns")) {
4126 # FIXME: do we need to add it then to tmpl_params[] ?
4127 my $num=$#$tmpl_params;
4128 #print " adding Returns: to macro docs for $symbol.\n";
4129 $$tmpl_params[$num+1]="Returns";
4130 $$tmpl_params[$num+2]=$$params[$j+1];
4133 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4134 "$item described in source code comment block but does not exist. $type: $symbol $item: $param_name.");
4140 if ($have_tmpl_docs) {
4141 $AllDocumentedSymbols{$symbol} = 1;
4142 #print "merging [$symbol] from template\n";
4145 #print "[$symbol] undocumented\n";
4149 # if this symbol is documented, check if docs are complete
4150 $check_tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4151 # remove all xml-tags and whitespaces
4152 #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
4153 $check_tmpl_doc =~ s/<.*?>//g;
4154 $check_tmpl_doc =~ s/\s//g;
4155 if ($check_tmpl_doc ne "") {
4156 my $tmpl_params = $SymbolParams{$symbol};
4157 if (defined ($tmpl_params)) {
4158 my $type = $DeclarationTypes {$symbol};
4160 my $item = "Parameter";
4161 if (defined ($type)) {
4162 if ($type eq 'STRUCT') {
4164 } elsif ($type eq 'ENUM') {
4166 } elsif ($type eq 'UNION') {
4173 #print "Check param docs for $symbol, tmpl_params: ",$#$tmpl_params," entries, type=$type\n";
4175 if ($#$tmpl_params > 0) {
4177 for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4178 # Output a warning if the parameter is empty and
4179 # remember for stats.
4180 my $tmpl_param_name = $$tmpl_params[$j];
4181 my $tmpl_param_desc = $$tmpl_params[$j + 1];
4182 if ($tmpl_param_desc !~ m/\S/) {
4183 if (exists ($AllIncompleteSymbols{$symbol})) {
4184 $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
4186 $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
4188 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4189 "$item description for $symbol"."::"."$tmpl_param_name is missing in source code comment block.");
4194 if ($#$tmpl_params == 0) {
4195 $AllIncompleteSymbols{$symbol}="<items>";
4196 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4197 "$item descriptions for $symbol are missing in source code comment block.");
4199 # $#$tmpl_params==-1 means we don't know about parameters
4200 # this unfortunately does not tell if there should be some
4205 #print "num doc entries: ".(scalar %SymbolDocs)."\n";
4208 #############################################################################
4209 # Function : IsEmptyDoc
4210 # Description : Check if a doc-string is empty. Its also regarded as empty if
4211 # it only consist of whitespace or e.g. FIXME.
4212 # Arguments : the doc-string
4213 #############################################################################
4217 if ($doc =~ /^\s*$/) {
4221 if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
4229 # This converts blank lines to "</para><para>", but only outside CDATA and
4230 # <programlisting> tags.
4231 sub ConvertBlankLines {
4232 return &ModifyXMLElements ($_[0], $_[1],
4233 "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
4234 \&ConvertBlankLinesEndTag,
4235 \&ConvertBlankLinesCallback);
4239 sub ConvertBlankLinesEndTag {
4240 if ($_[0] eq "<!\[CDATA\[") {
4242 } elsif ($_[0] eq "|[") {
4245 return "</programlisting>";
4249 sub ConvertBlankLinesCallback {
4250 my ($text, $symbol, $tag) = @_;
4252 # If we're not in CDATA or a <programlisting> we convert blank lines so
4253 # they start a new <para>.
4255 $text =~ s%\n{2,}%\n</para>\n<para>\n%g;
4262 #############################################################################
4263 # LIBRARY FUNCTIONS - These functions are used in both gtkdoc-mkdb and
4264 # gtkdoc-mktmpl and should eventually be moved to a
4266 #############################################################################
4268 #############################################################################
4269 # Function : ReadDeclarationsFile
4270 # Description : This reads in a file containing the function/macro/enum etc.
4273 # Note that in some cases there are several declarations with
4274 # the same name, e.g. for conditional macros. In this case we
4275 # set a flag in the %DeclarationConditional hash so the
4276 # declaration is not shown in the docs.
4278 # If a macro and a function have the same name, e.g. for
4279 # gtk_object_ref, the function declaration takes precedence.
4281 # Some opaque structs are just declared with 'typedef struct
4282 # _name name;' in which case the declaration may be empty.
4283 # The structure may have been found later in the header, so
4284 # that overrides the empty declaration.
4286 # Arguments : $file - the declarations file to read
4287 # $override - if declarations in this file should override
4288 # any current declaration.
4289 #############################################################################
4291 sub ReadDeclarationsFile {
4292 my ($file, $override) = @_;
4294 if ($override == 0) {
4296 %DeclarationTypes = ();
4297 %DeclarationConditional = ();
4298 %DeclarationOutput = ();
4302 || die "Can't open $file: $!";
4303 my $declaration_type = "";
4304 my $declaration_name;
4306 my $is_deprecated = 0;
4308 if (!$declaration_type) {
4309 if (m/^<([^>]+)>/) {
4310 $declaration_type = $1;
4311 $declaration_name = "";
4312 #print "Found declaration: $declaration_type\n";
4316 if (m%^<NAME>(.*)</NAME>%) {
4317 $declaration_name = $1;
4318 } elsif (m%^<DEPRECATED/>%) {
4320 } elsif (m%^</$declaration_type>%) {
4321 #print "Found end of declaration: $declaration_name\n";
4322 # Check that the declaration has a name
4323 if ($declaration_name eq "") {
4324 print "ERROR: $declaration_type has no name $file:$.\n";
4327 # If the declaration is an empty typedef struct _XXX XXX
4328 # set the flag to indicate the struct has a typedef.
4329 if ($declaration_type eq 'STRUCT'
4330 && $declaration =~ m/^\s*$/) {
4331 #print "Struct has typedef: $declaration_name\n";
4332 $StructHasTypedef{$declaration_name} = 1;
4335 # Check if the symbol is already defined.
4336 if (defined ($Declarations{$declaration_name})
4337 && $override == 0) {
4338 # Function declarations take precedence.
4339 if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
4341 } elsif ($declaration_type eq 'FUNCTION') {
4342 if ($is_deprecated) {
4343 $Deprecated{$declaration_name} = "";
4345 $Declarations{$declaration_name} = $declaration;
4346 $DeclarationTypes{$declaration_name} = $declaration_type;
4347 } elsif ($DeclarationTypes{$declaration_name}
4348 eq $declaration_type) {
4349 # If the existing declaration is empty, or is just a
4350 # forward declaration of a struct, override it.
4351 if ($declaration_type eq 'STRUCT') {
4352 if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4353 if ($is_deprecated) {
4354 $Deprecated{$declaration_name} = "";
4356 $Declarations{$declaration_name} = $declaration;
4357 } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4358 # Ignore an empty or forward declaration.
4360 &LogWarning ($file, $., "Structure $declaration_name has multiple definitions.");
4363 # set flag in %DeclarationConditional hash for
4364 # multiply defined macros/typedefs.
4365 $DeclarationConditional{$declaration_name} = 1;
4368 &LogWarning ($file, $., "$declaration_name has multiple definitions.");
4371 if ($is_deprecated) {
4372 $Deprecated{$declaration_name} = "";
4374 $Declarations{$declaration_name} = $declaration;
4375 $DeclarationTypes{$declaration_name} = $declaration_type;
4378 $declaration_type = "";
4389 #############################################################################
4390 # Function : ReadSignalsFile
4391 # Description : This reads in an existing file which contains information on
4392 # all GTK signals. It creates the arrays @SignalNames and
4393 # @SignalPrototypes containing info on the signals. The first
4394 # line of the SignalPrototype is the return type of the signal
4395 # handler. The remaining lines are the parameters passed to it.
4396 # The last parameter, "gpointer user_data" is always the same
4397 # so is not included.
4398 # Arguments : $file - the file containing the signal handler prototype
4400 #############################################################################
4402 sub ReadSignalsFile {
4410 my $signal_prototype;
4412 # Reset the signal info.
4413 @SignalObjects = ();
4415 @SignalReturns = ();
4417 @SignalPrototypes = ();
4422 if (!open (INPUT, $file)) {
4423 warn "Can't open $file - skipping signals\n";
4430 $signal_object = "";
4432 $signal_returns = "";
4433 $signal_prototype = "";
4436 if (m/^<NAME>(.*)<\/NAME>/) {
4438 if ($signal_name =~ m/^(.*)::(.*)$/) {
4439 $signal_object = $1;
4440 ($signal_name = $2) =~ s/_/-/g;
4441 #print "Found signal: $signal_name\n";
4443 &LogWarning ($file, $., "Invalid signal name: $signal_name.");
4445 } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
4446 $signal_returns = $1;
4447 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4449 } elsif (m%^</SIGNAL>%) {
4450 #print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
4451 push (@SignalObjects, $signal_object);
4452 push (@SignalNames, $signal_name);
4453 push (@SignalReturns, $signal_returns);
4454 push (@SignalFlags, $signal_flags);
4455 push (@SignalPrototypes, $signal_prototype);
4458 $signal_prototype .= $_;
4466 #############################################################################
4467 # Function : ReadTemplateFile
4468 # Description : This reads in the manually-edited documentation file
4469 # corresponding to the file currently being created, so we can
4470 # insert the documentation at the appropriate places.
4471 # It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
4472 # is a hash of arrays.
4473 # NOTE: This function is duplicated in gtkdoc-mktmpl (but
4474 # slightly different).
4475 # Arguments : $docsfile - the template file to read in.
4476 # $skip_unused_params - 1 if the unused parameters should be
4478 #############################################################################
4480 sub ReadTemplateFile {
4481 my ($docsfile, $skip_unused_params) = @_;
4483 my $template = "$docsfile.sgml";
4484 if (! -f $template) {
4485 #print "File doesn't exist: $template\n";
4488 #print "Reading $template\n";
4490 # start with empty hashes, we merge the source comment for each file
4496 my $current_type = ""; # Type of symbol being read.
4497 my $current_symbol = ""; # Name of symbol being read.
4498 my $symbol_doc = ""; # Description of symbol being read.
4499 my @params; # Parameter names and descriptions of current
4500 # function/macro/function typedef.
4501 my $current_param = -1; # Index of parameter currently being read.
4502 # Note that the param array contains pairs
4503 # of param name & description.
4504 my $in_unused_params = 0; # True if we are reading in the unused params.
4505 my $in_deprecated = 0;
4507 my $in_stability = 0;
4509 open (DOCS, "$template")
4510 || die "Can't open $template: $!";
4512 if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
4515 if ($symbol eq "Title"
4516 || $symbol eq "Short_Description"
4517 || $symbol eq "Long_Description"
4518 || $symbol eq "See_Also"
4519 || $symbol eq "Stability_Level"
4520 || $symbol eq "Include") {
4522 $symbol = $docsfile . ":" . $symbol;
4525 #print "Found symbol: $symbol\n";
4526 # Remember file and line for the symbol
4527 $SymbolSourceFile{$symbol} = $template;
4528 $SymbolSourceLine{$symbol} = $.;
4530 # Store previous symbol, but remove any trailing blank lines.
4531 if ($current_symbol ne "") {
4532 $symbol_doc =~ s/\s+$//;
4533 $SymbolTypes{$current_symbol} = $current_type;
4534 $SymbolDocs{$current_symbol} = $symbol_doc;
4536 # Check that the stability level is valid.
4537 if ($StabilityLevel{$current_symbol}) {
4538 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4541 if ($current_param >= 0) {
4542 $SymbolParams{$current_symbol} = [ @params ];
4544 # Delete any existing params in case we are overriding a
4545 # previously read template.
4546 delete $SymbolParams{$current_symbol};
4549 $current_type = $type;
4550 $current_symbol = $symbol;
4551 $current_param = -1;
4552 $in_unused_params = 0;
4559 } elsif (m/^<!-- # Unused Parameters # -->/) {
4560 #print "DEBUG: Found unused parameters\n";
4561 $in_unused_params = 1;
4564 } elsif ($in_unused_params && $skip_unused_params) {
4565 # When outputting the DocBook we skip unused parameters.
4566 #print "DEBUG: Skipping unused param: $_";
4570 # Check if param found. Need to handle "..." and "format...".
4571 if (s/^\@([\w\.]+):\040?//) {
4572 my $param_name = $1;
4573 my $param_desc = $_;
4574 # Allow variations of 'Returns'
4575 if ($param_name =~ m/^[Rr]eturns?$/) {
4576 $param_name = "Returns";
4579 # strip trailing whitespaces and blank lines
4582 #print "Found param for symbol $current_symbol : '$param_name'= '$_'";
4584 if ($param_name eq "Deprecated") {
4586 $Deprecated{$current_symbol} = $_;
4587 } elsif ($param_name eq "Since") {
4590 $Since{$current_symbol} = $_;
4591 } elsif ($param_name eq "Stability") {
4593 $StabilityLevel{$current_symbol} = $_;
4595 push (@params, $param_name);
4596 push (@params, $param_desc);
4597 $current_param += $PARAM_FIELD_COUNT;
4600 # strip trailing whitespaces and blank lines
4605 if ($in_deprecated) {
4606 $Deprecated{$current_symbol} .= $_;
4607 } elsif ($in_since) {
4608 &LogWarning ($template, $., "multi-line since docs found");
4609 #$Since{$current_symbol} .= $_;
4610 } elsif ($in_stability) {
4611 $StabilityLevel{$current_symbol} .= $_;
4612 } elsif ($current_param >= 0) {
4613 $params[$current_param] .= $_;
4622 # Remember to finish the current symbol doccs.
4623 if ($current_symbol ne "") {
4625 $symbol_doc =~ s/\s+$//;
4626 $SymbolTypes{$current_symbol} = $current_type;
4627 $SymbolDocs{$current_symbol} = $symbol_doc;
4629 # Check that the stability level is valid.
4630 if ($StabilityLevel{$current_symbol}) {
4631 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4634 if ($current_param >= 0) {
4635 $SymbolParams{$current_symbol} = [ @params ];
4637 # Delete any existing params in case we are overriding a
4638 # previously read template.
4639 delete $SymbolParams{$current_symbol};
4648 #############################################################################
4649 # Function : ReadObjectHierarchy
4650 # Description : This reads in the $MODULE-hierarchy.txt file containing all
4651 # the GtkObject subclasses described in this module (and their
4653 # It places them in the @Objects array, and places their level
4654 # in the widget hierarchy in the @ObjectLevels array, at the
4655 # same index. GtkObject, the root object, has a level of 1.
4657 # FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
4658 # as it goes along, this should be split out into a separate
4662 #############################################################################
4664 sub ReadObjectHierarchy {
4668 if (! -f $OBJECT_TREE_FILE) {
4671 if (!open (INPUT, $OBJECT_TREE_FILE)) {
4672 warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
4676 # FIXME: use $OUTPUT_FORMAT
4677 # my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.$OUTPUT_FORMAT";
4678 my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
4679 my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
4681 open (OUTPUT, ">$new_tree_index")
4682 || die "Can't create $new_tree_index: $!";
4684 if (lc($OUTPUT_FORMAT) eq "xml") {
4685 my $tree_header = $doctype_header;
4687 $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
4688 print (OUTPUT "$tree_header");
4690 print (OUTPUT "<screen>\n");
4692 # Only emit objects if they are supposed to be documented, or if
4693 # they have documented children. To implement this, we maintain a
4694 # stack of pending objects which will be emitted if a documented
4696 my @pending_objects = ();
4697 my @pending_levels = ();
4701 my $level = (length($`)) / 2 + 1;
4704 while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
4705 my $pobject = pop(@pending_objects);
4706 my $plevel = pop(@pending_levels);
4709 push (@pending_objects, $object);
4710 push (@pending_levels, $level);
4712 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
4713 while ($#pending_levels >= 0) {
4714 $object = shift @pending_objects;
4715 $level = shift @pending_levels;
4716 $xref = &MakeXRef ($object);
4718 print (OUTPUT ' ' x ($level * 4), "$xref\n");
4719 push (@Objects, $object);
4720 push (@ObjectLevels, $level);
4725 print (OUTPUT "</screen>\n");
4730 &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
4735 #############################################################################
4736 # Function : ReadInterfaces
4737 # Description : This reads in the $MODULE.interfaces file.
4740 #############################################################################
4742 sub ReadInterfaces {
4745 if (! -f $INTERFACES_FILE) {
4748 if (!open (INPUT, $INTERFACES_FILE)) {
4749 warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
4755 my ($object, @ifaces) = split;
4756 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
4757 my @knownIfaces = ();
4759 # filter out private interfaces, but leave foreign interfaces
4760 foreach my $iface (@ifaces) {
4761 if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
4762 push (@knownIfaces, $iface);
4766 $Interfaces{$object} = join(' ', @knownIfaces);
4772 #############################################################################
4773 # Function : ReadPrerequisites
4774 # Description : This reads in the $MODULE.prerequisites file.
4777 #############################################################################
4779 sub ReadPrerequisites {
4780 %Prerequisites = ();
4782 if (! -f $PREREQUISITES_FILE) {
4785 if (!open (INPUT, $PREREQUISITES_FILE)) {
4786 warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
4792 my ($iface, @prereqs) = split;
4793 if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
4794 my @knownPrereqs = ();
4796 # filter out private prerequisites, but leave foreign prerequisites
4797 foreach my $prereq (@prereqs) {
4798 if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
4799 push (@knownPrereqs, $prereq);
4803 $Prerequisites{$iface} = join(' ', @knownPrereqs);
4809 #############################################################################
4810 # Function : ReadArgsFile
4811 # Description : This reads in an existing file which contains information on
4812 # all GTK args. It creates the arrays @ArgObjects, @ArgNames,
4813 # @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
4815 # Arguments : $file - the file containing the arg information.
4816 #############################################################################
4831 # Reset the args info.
4844 if (!open (INPUT, $file)) {
4845 warn "Can't open $file - skipping args\n";
4862 if (m/^<NAME>(.*)<\/NAME>/) {
4864 if ($arg_name =~ m/^(.*)::(.*)$/) {
4866 ($arg_name = $2) =~ s/_/-/g;
4867 #print "Found arg: $arg_name\n";
4869 &LogWarning ($file, $., "Invalid argument name: $arg_name");
4871 } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
4873 } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
4875 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4877 } elsif (m/^<NICK>(.*)<\/NICK>/) {
4879 } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
4881 if ($arg_blurb eq "(null)") {
4883 &LogWarning ($file, $., "Property ${arg_object}:${arg_name} has no documentation.");
4885 } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
4887 } elsif (m%^</ARG>%) {
4888 #print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
4889 push (@ArgObjects, $arg_object);
4890 push (@ArgNames, $arg_name);
4891 push (@ArgTypes, $arg_type);
4892 push (@ArgRanges, $arg_range);
4893 push (@ArgFlags, $arg_flags);
4894 push (@ArgNicks, $arg_nick);
4895 push (@ArgBlurbs, $arg_blurb);
4896 push (@ArgDefaults, $arg_default);
4905 #############################################################################
4906 # Function : CheckIsObject
4907 # Description : Returns 1 if the given name is a GtkObject or a subclass.
4908 # It uses the global @Objects array.
4909 # Note that the @Objects array only contains classes in the
4910 # current module and their ancestors - not all GTK classes.
4911 # Arguments : $name - the name to check.
4912 #############################################################################
4918 foreach $object (@Objects) {
4919 if ($object eq $name) {
4927 #############################################################################
4928 # Function : MakeReturnField
4929 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
4930 # Arguments : $str - the string to pad.
4931 #############################################################################
4933 sub MakeReturnField {
4936 return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));
4939 #############################################################################
4940 # Function : GetSymbolSourceFile
4941 # Description : Get the filename where the symbol docs where taken from.
4942 # Arguments : $symbol - the symbol name
4943 #############################################################################
4945 sub GetSymbolSourceFile {
4948 if (defined($SourceSymbolSourceFile{$symbol})) {
4949 return $SourceSymbolSourceFile{$symbol};
4950 } elsif (defined($SymbolSourceFile{$symbol})) {
4951 return $SymbolSourceFile{$symbol};
4957 #############################################################################
4958 # Function : GetSymbolSourceLine
4959 # Description : Get the file line where the symbol docs where taken from.
4960 # Arguments : $symbol - the symbol name
4961 #############################################################################
4963 sub GetSymbolSourceLine {
4966 if (defined($SourceSymbolSourceLine{$symbol})) {
4967 return $SourceSymbolSourceLine{$symbol};
4968 } elsif (defined($SymbolSourceLine{$symbol})) {
4969 return $SymbolSourceLine{$symbol};