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 and in which
242 # section they are defined
247 # collects index entries
248 my %IndexEntriesFull;
249 my %IndexEntriesSince;
250 my %IndexEntriesDeprecated;
252 # Standard C preprocessor directives, which we ignore for '#' abbreviations.
253 my %PreProcessorDirectives;
254 $PreProcessorDirectives{"assert"} = 1;
255 $PreProcessorDirectives{"define"} = 1;
256 $PreProcessorDirectives{"elif"} = 1;
257 $PreProcessorDirectives{"else"} = 1;
258 $PreProcessorDirectives{"endif"} = 1;
259 $PreProcessorDirectives{"error"} = 1;
260 $PreProcessorDirectives{"if"} = 1;
261 $PreProcessorDirectives{"ifdef"} = 1;
262 $PreProcessorDirectives{"ifndef"} = 1;
263 $PreProcessorDirectives{"include"} = 1;
264 $PreProcessorDirectives{"line"} = 1;
265 $PreProcessorDirectives{"pragma"} = 1;
266 $PreProcessorDirectives{"unassert"} = 1;
267 $PreProcessorDirectives{"undef"} = 1;
268 $PreProcessorDirectives{"warning"} = 1;
270 # remember used annotation (to write minimal glossary)
273 my %AnnotationDefinition = (
274 'allow-none' => "NULL is ok, both for passing and for returning.",
275 'array' => "Parameter points to an array of items.",
276 'default' => "Default parameter value (for in case the <acronym>shadows</acronym>-to function has less parameters).",
277 'element-type' => "Generics and defining elements of containers and arrays.",
278 'error-domains' => "Typed errors. Similar to throws in Java.",
279 'in' => "Parameter for input. Default is <acronym>transfer none</acronym>.",
280 'inout' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
281 'in-out' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
282 'not-error' => "A GError parameter is not to be handled like a normal GError.",
283 'out' => "Parameter for returning results. Default is <acronym>transfer full</acronym>.",
284 'transfer container' => "Free data container after the code is done.",
285 'transfer full' => "Free data after the code is done.",
286 'transfer none' => "Don't free data after the code is done."
289 # Create the root DocBook output directory if it doens't exist.
290 if (! -e $SGML_OUTPUT_DIR) {
291 mkdir ("$SGML_OUTPUT_DIR", 0777)
292 || die "Can't create directory: $SGML_OUTPUT_DIR";
295 # Function and other declaration output settings.
296 my $RETURN_TYPE_FIELD_WIDTH = 20;
297 my $SYMBOL_FIELD_WIDTH = 36;
298 my $SIGNAL_FIELD_WIDTH = 16;
299 my $PARAM_FIELD_COUNT = 2;
301 &ReadKnownSymbols ("$ROOT_DIR/$MODULE-sections.txt");
302 &ReadSignalsFile ($SIGNALS_FILE);
303 &ReadArgsFile ($ARGS_FILE);
304 &ReadObjectHierarchy;
308 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-decl.txt", 0);
309 if (-f "$ROOT_DIR/$MODULE-overrides.txt") {
310 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-overrides.txt", 1);
313 for my $dir (@SOURCE_DIRS) {
314 &ReadSourceDocumentation ($dir);
317 my $changed = &OutputSGML ("$ROOT_DIR/$MODULE-sections.txt");
319 # If any of the DocBook SGML files have changed, update the timestamp file (so
320 # it can be used for Makefile dependencies).
321 if ($changed || ! -e "$ROOT_DIR/sgml.stamp") {
323 # try to detect the common prefix
324 # GtkWidget, GTK_WIDGET, gtk_widget -> gtk
325 if ($NAME_SPACE eq "") {
332 foreach my $symbol (keys(%IndexEntriesFull)) {
333 if(($NAME_SPACE eq "") || $symbol =~ /^$NAME_SPACE/i) {
334 if (length($symbol)>$pos) {
335 $letter=substr($symbol,$pos,1);
336 # stop prefix scanning
337 if ($letter eq "_") {
341 # Should we also stop on a uppercase char, if last was lowercase
342 # GtkWidget, if we have the 'W' and had the 't' before
343 # or should we count upper and lowercase, and stop one 2nd uppercase, if we already had a lowercase
344 # GtkWidget, the 'W' would be the 2nd uppercase and with 't','k' we had lowercase chars before
345 # need to recound each time as this is per symbol
346 $prefix{uc($letter)}++;
350 if ($letter ne "" && $letter ne "_") {
353 foreach $letter (keys(%prefix)) {
354 #print "$letter: $prefix{$letter}.\n";
355 if ($prefix{$letter}>$maxsymbols) {
357 $maxsymbols=$prefix{$letter};
360 $ratio = scalar(keys(%IndexEntriesFull)) / $prefix{$maxletter};
361 #print "most symbols start with $maxletter, that is ". (100 * $ratio) ." %\n";
364 $NAME_SPACE .= $maxletter;
371 } while ($ratio > 0.9);
372 #print "most symbols start with $NAME_SPACE\n";
376 &OutputDeprecatedIndex;
378 &OutputAnnotationGlossary;
380 open (TIMESTAMP, ">$ROOT_DIR/sgml.stamp")
381 || die "Can't create $ROOT_DIR/sgml.stamp: $!";
382 print (TIMESTAMP "timestamp");
386 #############################################################################
387 # Function : OutputObjectList
388 # Description : This outputs the alphabetical list of objects, in a columned
390 # FIXME: Currently this also outputs ancestor objects
391 # which may not actually be in this module.
393 #############################################################################
395 sub OutputObjectList {
398 # FIXME: use $OUTPUT_FORMAT
399 # my $old_object_index = "$SGML_OUTPUT_DIR/object_index.$OUTPUT_FORMAT";
400 my $old_object_index = "$SGML_OUTPUT_DIR/object_index.sgml";
401 my $new_object_index = "$SGML_OUTPUT_DIR/object_index.new";
403 open (OUTPUT, ">$new_object_index")
404 || die "Can't create $new_object_index: $!";
406 if (lc($OUTPUT_FORMAT) eq "xml") {
407 my $header = $doctype_header;
409 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE informaltable/;
410 print (OUTPUT "$header");
413 print (OUTPUT <<EOF);
414 <informaltable pgwide="1" frame="none">
415 <tgroup cols="$cols">
416 <colspec colwidth="1*"${empty_element_end}
417 <colspec colwidth="1*"${empty_element_end}
418 <colspec colwidth="1*"${empty_element_end}
424 foreach $object (sort (@Objects)) {
425 my $xref = &MakeXRef ($object);
426 if ($count % $cols == 0) { print (OUTPUT "<row>\n"); }
427 print (OUTPUT "<entry>$xref</entry>\n");
428 if ($count % $cols == ($cols - 1)) { print (OUTPUT "</row>\n"); }
432 # emit an empty row, since empty tables are invalid
433 print (OUTPUT "<row><entry> </entry></row>\n");
436 print (OUTPUT "</row>\n");
439 print (OUTPUT <<EOF);
440 </tbody></tgroup></informaltable>
444 &UpdateFileIfChanged ($old_object_index, $new_object_index, 0);
448 #############################################################################
449 # Function : OutputSGML
450 # Description : This collects the output for each section of the docs, and
451 # outputs each file when the end of the section is found.
452 # Arguments : $file - the $MODULE-sections.txt file which contains all of
453 # the functions/macros/structs etc. being documented, organised
454 # into sections and subsections.
455 #############################################################################
460 #print "Reading: $file\n";
462 || die "Can't open $file: $!";
465 my $book_bottom = "";
466 my $includes = (defined $DEFAULT_INCLUDES) ? $DEFAULT_INCLUDES : "";
467 my $section_includes = "";
476 my $signals_synop = "";
477 my $signals_desc = "";
479 my $child_args_synop = "";
480 my $style_args_synop = "";
482 my $child_args_desc = "";
483 my $style_args_desc = "";
486 my $implementations = "";
487 my $prerequisites = "";
489 my @file_objects = ();
491 my %symbol_def_line = ();
493 # merge the source docs, in case there are no templates
494 &MergeSourceDocumentation;
500 } elsif (m/^<SECTION>/) {
506 %symbol_def_line = ();
508 } elsif (m/^<SUBSECTION\s*(.*)>/i) {
512 } elsif (m/^<SUBSECTION>/) {
514 } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
516 #print "Section: $title\n";
518 # We don't want warnings if object & class structs aren't used.
519 $DeclarationOutput{$title} = 1;
520 $DeclarationOutput{"${title}Class"} = 1;
521 $DeclarationOutput{"${title}Iface"} = 1;
522 $DeclarationOutput{"${title}Interface"} = 1;
524 } elsif (m/^<FILE>(.*)<\/FILE>/) {
526 if (! defined $templates{$filename}) {
527 if (&ReadTemplateFile ("$TMPL_DIR/$filename", 1)) {
528 &MergeSourceDocumentation;
529 $templates{$filename}=$.;
532 &LogWarning ($file, $., "Double <FILE>$filename</FILE> entry. ".
533 "Previous occurrence on line ".$templates{$filename}.".");
535 if (($title eq "") and (defined $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"})) {
536 $title = $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"};
537 # Remove trailing blanks
541 } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
543 $section_includes = $1;
545 if (defined $DEFAULT_INCLUDES) {
546 &LogWarning ($file, $., "Default <INCLUDE> being overridden by command line option.");
553 } elsif (m/^<\/SECTION>/) {
554 #print "End of section: $title\n";
555 if ($num_symbols > 0) {
557 if (lc($OUTPUT_FORMAT) eq "xml") {
558 $book_bottom .= " <xi:include href=\"xml/$filename.xml\"/>\n";
560 $book_top.="<!ENTITY $section_id SYSTEM \"sgml/$filename.sgml\">\n";
561 $book_bottom .= " &$section_id;\n";
564 if (defined ($SourceSymbolDocs{"$TMPL_DIR/$filename:Include"})) {
565 if ($section_includes) {
566 &LogWarning ($file, $., "Section <INCLUDE> being overridden by inline comments.");
568 $section_includes = $SourceSymbolDocs{"$TMPL_DIR/$filename:Include"};
570 if ($section_includes eq "") {
571 $section_includes = $includes;
574 $signals_synop =~ s/^\n*//g;
575 $signals_synop =~ s/\n+$/\n/g;
576 if ($signals_synop ne '') {
577 $signals_synop = <<EOF;
578 <refsect1 id="$section_id.signals" role="signal_proto">
579 <title role="signal_proto.title">Signals</title>
581 ${signals_synop}</synopsis>
584 $signals_desc =~ s/^\n*//g;
585 $signals_desc =~ s/\n+$/\n/g;
586 $signals_desc =~ s/(\s|\n)+$//ms;
587 $signals_desc = <<EOF;
588 <refsect1 id="$section_id.signal-details" role="signals">
589 <title role="signals.title">Signal Details</title>
595 $args_synop =~ s/^\n*//g;
596 $args_synop =~ s/\n+$/\n/g;
597 if ($args_synop ne '') {
599 <refsect1 id="$section_id.properties" role="properties">
600 <title role="properties.title">Properties</title>
602 ${args_synop}</synopsis>
605 $args_desc =~ s/^\n*//g;
606 $args_desc =~ s/\n+$/\n/g;
607 $args_desc =~ s/(\s|\n)+$//ms;
609 <refsect1 id="$section_id.property-details" role="property_details">
610 <title role="property_details.title">Property Details</title>
616 $child_args_synop =~ s/^\n*//g;
617 $child_args_synop =~ s/\n+$/\n/g;
618 if ($child_args_synop ne '') {
619 $args_synop .= <<EOF;
620 <refsect1 id="$section_id.child-properties" role="child_properties">
621 <title role="child_properties.title">Child Properties</title>
623 ${child_args_synop}</synopsis>
626 $child_args_desc =~ s/^\n*//g;
627 $child_args_desc =~ s/\n+$/\n/g;
628 $child_args_desc =~ s/(\s|\n)+$//ms;
630 <refsect1 id="$section_id.child-property-details" role="child_property_details">
631 <title role="child_property_details.title">Child Property Details</title>
637 $style_args_synop =~ s/^\n*//g;
638 $style_args_synop =~ s/\n+$/\n/g;
639 if ($style_args_synop ne '') {
640 $args_synop .= <<EOF;
641 <refsect1 id="$section_id.style-properties" role="style_properties">
642 <title role="style_properties.title">Style Properties</title>
644 ${style_args_synop}</synopsis>
647 $style_args_desc =~ s/^\n*//g;
648 $style_args_desc =~ s/\n+$/\n/g;
649 $style_args_desc =~ s/(\s|\n)+$//ms;
651 <refsect1 id="$section_id.style-property-details" role="style_properties_details">
652 <title role="style_properties_details.title">Style Property Details</title>
658 $hierarchy =~ s/^\n*//g;
659 $hierarchy =~ s/\n+$/\n/g;
660 $hierarchy =~ s/(\s|\n)+$//ms;
661 if ($hierarchy ne "") {
663 <refsect1 id="$section_id.object-hierarchy" role="object_hierarchy">
664 <title role="object_hierarchy.title">Object Hierarchy</title>
670 $interfaces =~ s/^\n*//g;
671 $interfaces =~ s/\n+$/\n/g;
672 $interfaces =~ s/(\s|\n)+$//ms;
673 if ($interfaces ne "") {
675 <refsect1 id="$section_id.implemented-interfaces" role="impl_interfaces">
676 <title role="impl_interfaces.title">Implemented Interfaces</title>
682 $implementations =~ s/^\n*//g;
683 $implementations =~ s/\n+$/\n/g;
684 $implementations =~ s/(\s|\n)+$//ms;
685 if ($implementations ne "") {
686 $implementations = <<EOF;
687 <refsect1 id="$section_id.implementations" role="implementations">
688 <title role="implementations.title">Known Implementations</title>
694 $prerequisites =~ s/^\n*//g;
695 $prerequisites =~ s/\n+$/\n/g;
696 $prerequisites =~ s/(\s|\n)+$//ms;
697 if ($prerequisites ne "") {
698 $prerequisites = <<EOF;
699 <refsect1 id="$section_id.prerequisites" role="prerequisites">
700 <title role="prerequisites.title">Prerequisites</title>
706 $derived =~ s/^\n*//g;
707 $derived =~ s/\n+$/\n/g;
708 $derived =~ s/(\s|\n)+$//ms;
709 if ($derived ne "") {
711 <refsect1 id="$section_id.derived-interfaces" role="derived_interfaces">
712 <title role="derived_interfaces.title">Known Derived Interfaces</title>
718 $synopsis =~ s/^\n*//g;
719 $synopsis =~ s/\n+$/\n/g;
720 my $file_changed = &OutputSGMLFile ($filename, $title, $section_id,
722 \$synopsis, \$details,
723 \$signals_synop, \$signals_desc,
724 \$args_synop, \$args_desc,
725 \$hierarchy, \$interfaces,
727 \$prerequisites, \$derived,
737 $section_includes = "";
741 $child_args_synop = "";
742 $style_args_synop = "";
744 $child_args_desc = "";
745 $style_args_desc = "";
748 $implementations = "";
752 } elsif (m/^(\S+)/) {
754 #print " Symbol: $symbol\n";
756 # check for duplicate entries
757 if (! defined $symbol_def_line{$symbol}) {
758 my $declaration = $Declarations{$symbol};
759 if (defined ($declaration)) {
760 # We don't want standard macros/functions of GObjects,
761 # or private declarations.
762 if ($subsection ne "Standard" && $subsection ne "Private") {
763 if (&CheckIsObject ($symbol)) {
764 push @file_objects, $symbol;
766 my ($synop, $desc) = &OutputDeclaration ($symbol,
768 my ($sig_synop, $sig_desc) = &GetSignals ($symbol);
769 my ($arg_synop, $child_arg_synop, $style_arg_synop,
770 $arg_desc, $child_arg_desc, $style_arg_desc) = &GetArgs ($symbol);
771 my $hier = &GetHierarchy ($symbol);
772 my $ifaces = &GetInterfaces ($symbol);
773 my $impls = &GetImplementations ($symbol);
774 my $prereqs = &GetPrerequisites ($symbol);
775 my $der = &GetDerived ($symbol);
778 $signals_synop .= $sig_synop;
779 $signals_desc .= $sig_desc;
780 $args_synop .= $arg_synop;
781 $child_args_synop .= $child_arg_synop;
782 $style_args_synop .= $style_arg_synop;
783 $args_desc .= $arg_desc;
784 $child_args_desc .= $child_arg_desc;
785 $style_args_desc .= $style_arg_desc;
787 $interfaces .= $ifaces;
788 $implementations .= $impls;
789 $prerequisites .= $prereqs;
793 # Note that the declaration has been output.
794 $DeclarationOutput{$symbol} = 1;
795 } elsif ($subsection ne "Standard" && $subsection ne "Private") {
796 $UndeclaredSymbols{$symbol} = 1;
797 &LogWarning ($file, $., "No declaration found for $symbol.");
800 $symbol_def_line{$symbol}=$.;
802 if ($section_id eq "") {
803 if($title eq "" && $filename eq "") {
804 &LogWarning ($file, $., "Section has no title and no file.");
806 # FIXME: one of those would be enough
807 # filename should be an internal detail for gtk-doc
810 } elsif ($filename eq "") {
813 $filename =~ s/\s/_/g;
815 $section_id = $SourceSymbolDocs{"$TMPL_DIR/$filename:Section_Id"};
816 if (defined ($section_id) && $section_id !~ m/^\s*$/) {
817 # Remove trailing blanks and use as is
818 $section_id =~ s/\s+$//;
819 } elsif (&CheckIsObject ($title)) {
820 # GObjects use their class name as the ID.
821 $section_id = &CreateValidSGMLID ($title);
823 $section_id = &CreateValidSGMLID ("$MODULE-$title");
826 $SymbolSection{$symbol}=$title;
827 $SymbolSectionId{$symbol}=$section_id;
830 &LogWarning ($file, $., "Double symbol entry for $symbol. ".
831 "Previous occurrence on line ".$symbol_def_line{$symbol}.".");
837 &OutputMissingDocumentation;
838 &OutputUndeclaredSymbols;
840 if ($OUTPUT_ALL_SYMBOLS) {
843 if ($OUTPUT_SYMBOLS_WITHOUT_SINCE) {
844 &OutputSymbolsWithoutSince;
847 for $filename (split (' ', $EXPAND_CONTENT_FILES)) {
848 my $file_changed = &OutputExtraFile ($filename);
854 &OutputBook ($book_top, $book_bottom);
859 #############################################################################
860 # Function : OutputIndex
861 # Description : This writes an indexlist that can be included into the main-
862 # document into an <index> tag.
863 #############################################################################
866 my ($basename, $apiindexref ) = @_;
867 my %apiindex = %{$apiindexref};
868 my $old_index = "$SGML_OUTPUT_DIR/$basename.xml";
869 my $new_index = "$SGML_OUTPUT_DIR/$basename.new";
870 my $lastletter = " ";
875 open (OUTPUT, ">$new_index")
876 || die "Can't create $new_index";
878 my $header = $doctype_header;
879 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE indexdiv/;
881 print (OUTPUT "$header<indexdiv>\n");
883 #print "generate $basename index (".%apiindex." entries)\n";
885 # do a case insensitive sort while chopping off the prefix
887 sort { $$a{criteria} cmp $$b{criteria} }
888 map { my $x = uc($_); $x =~ s/^$NAME_SPACE\_?(.*)/$1/i; { criteria => $x, original => $_, short => $1 } }
891 $symbol = $$hash{original};
892 if (defined($$hash{short})) {
893 $short_symbol = $$hash{short};
895 $short_symbol = $symbol;
898 # generate a short symbol description
899 my $symbol_desc = "";
900 my $symbol_section = "";
901 my $symbol_section_id = "";
902 my $symbol_type = lc($DeclarationTypes{$symbol});
903 if ($symbol_type eq "") {
904 #print "trying symbol $symbol\n";
905 if ($symbol =~ m/(.*)::(.*)/) {
909 #print " trying object signal ${oname}:$osym in ".$#SignalNames." signals\n";
910 for ($i = 0; $i <= $#SignalNames; $i++) {
911 if ($SignalNames[$i] eq $osym) {
912 $symbol_type = "object signal";
913 if (defined($SymbolSection{$oname})) {
914 $symbol_section = $SymbolSection{$oname};
915 $symbol_section_id = $SymbolSectionId{$oname};
920 } elsif ($symbol =~ m/(.*):(.*)/) {
924 #print " trying object property ${oname}::$osym in ".$#ArgNames." properties\n";
925 for ($i = 0; $i <= $#ArgNames; $i++) {
926 #print " ".$ArgNames[$i]."\n";
927 if ($ArgNames[$i] eq $osym) {
928 $symbol_type = "object property";
929 if (defined($SymbolSection{$oname})) {
930 $symbol_section = $SymbolSection{$oname};
931 $symbol_section_id = $SymbolSectionId{$oname};
938 if (defined($SymbolSection{$symbol})) {
939 $symbol_section = $SymbolSection{$symbol};
940 $symbol_section_id = $SymbolSectionId{$symbol};
943 if ($symbol_type ne "") {
944 $symbol_desc=", $symbol_type";
945 if ($symbol_section ne "") {
946 $symbol_desc.=" in <link linkend=\"$symbol_section_id\">$symbol_section</link>";
947 #$symbol_desc.=" in ". &ExpandAbbreviations($symbol, "#$symbol_section");
951 my $curletter = uc(substr($short_symbol,0,1));
952 my $id = $apiindex{$symbol};
954 #print " add symbol $symbol with $id to index in section $curletter\n";
956 if ($curletter ne $lastletter) {
957 $lastletter = $curletter;
960 print (OUTPUT "</indexdiv>\n");
962 print (OUTPUT "<indexdiv><title>$curletter</title>\n");
966 print (OUTPUT <<EOF);
967 <indexentry><primaryie linkends="$id"><link linkend="$id">$symbol</link>$symbol_desc</primaryie></indexentry>
972 print (OUTPUT "</indexdiv>\n");
974 print (OUTPUT "</indexdiv>\n");
977 &UpdateFileIfChanged ($old_index, $new_index, 0);
981 #############################################################################
982 # Function : OutputIndexFull
983 # Description : This writes the full api indexlist that can be included into the
984 # main document into an <index> tag.
985 #############################################################################
987 sub OutputIndexFull {
988 &OutputIndex ("api-index-full", \%IndexEntriesFull);
992 #############################################################################
993 # Function : OutputDeprecatedIndex
994 # Description : This writes the deprecated api indexlist that can be included
995 # into the main document into an <index> tag.
996 #############################################################################
998 sub OutputDeprecatedIndex {
999 &OutputIndex ("api-index-deprecated", \%IndexEntriesDeprecated);
1003 #############################################################################
1004 # Function : OutputSinceIndexes
1005 # Description : This writes the 'since' api indexlists that can be included into
1006 # the main document into an <index> tag.
1007 #############################################################################
1009 sub OutputSinceIndexes {
1010 my @sinces = keys %{{ map { $_ => 1 } values %Since }};
1012 foreach my $version (@sinces) {
1013 #print "Since : [$version]\n";
1014 # TODO make filtered hash
1015 #my %index = grep { $Since{$_} eq $version } %IndexEntriesSince;
1016 my %index = map { $_ => $IndexEntriesSince{$_} } grep { $Since{$_} eq $version } keys %IndexEntriesSince;
1018 &OutputIndex ("api-index-$version", \%index);
1022 #############################################################################
1023 # Function : OutputAnnotationGlossary
1024 # Description : This writes a glossary of the used annotation terms into a
1025 # separate glossary file that can be included into the main
1027 #############################################################################
1029 sub OutputAnnotationGlossary {
1030 my $old_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.xml";
1031 my $new_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.new";
1032 my $lastletter = " ";
1035 # if there are no annotations used return
1036 return if (! keys(%AnnotationsUsed));
1038 # add acronyms that are referenced from acronym text
1040 foreach my $annotation (keys(%AnnotationsUsed)) {
1041 if($AnnotationDefinition{$annotation} =~ m/<acronym>([\w ]+)<\/acronym>/) {
1042 if (!exists($AnnotationsUsed{$1})) {
1043 $AnnotationsUsed{$1} = 1;
1049 open (OUTPUT, ">$new_glossary")
1050 || die "Can't create $new_glossary";
1052 my $header = $doctype_header;
1053 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE glossary/;
1055 print (OUTPUT <<EOF);
1057 <glossary id="annotation-glossary">
1058 <title>Annotation Glossary</title>
1061 foreach my $annotation (keys(%AnnotationsUsed)) {
1062 my $def = $AnnotationDefinition{$annotation};
1063 my $curletter = uc(substr($annotation,0,1));
1065 if ($curletter ne $lastletter) {
1066 $lastletter = $curletter;
1068 if ($divopen == 1) {
1069 print (OUTPUT "</glossdiv>\n");
1071 print (OUTPUT "<glossdiv><title>$curletter</title>\n");
1074 print (OUTPUT <<EOF);
1076 <glossterm><anchor id="annotation-glossterm-$annotation"/>$annotation</glossterm>
1084 if ($divopen == 1) {
1085 print (OUTPUT "</glossdiv>\n");
1087 print (OUTPUT "</glossary>\n");
1090 &UpdateFileIfChanged ($old_glossary, $new_glossary, 0);
1093 #############################################################################
1094 # Function : ReadKnownSymbols
1095 # Description : This collects the names of non-private symbols from the
1096 # $MODULE-sections.txt file.
1097 # Arguments : $file - the $MODULE-sections.txt file which contains all of
1098 # the functions/macros/structs etc. being documented, organised
1099 # into sections and subsections.
1100 #############################################################################
1102 sub ReadKnownSymbols {
1105 my $subsection = "";
1107 #print "Reading: $file\n";
1109 || die "Can't open $file: $!";
1115 } elsif (m/^<SECTION>/) {
1118 } elsif (m/^<SUBSECTION\s*(.*)>/i) {
1121 } elsif (m/^<SUBSECTION>/) {
1124 } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
1127 } elsif (m/^<FILE>(.*)<\/FILE>/) {
1128 $KnownSymbols{"$TMPL_DIR/$1:Long_Description"} = 1;
1129 $KnownSymbols{"$TMPL_DIR/$1:Short_Description"} = 1;
1132 } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
1135 } elsif (m/^<\/SECTION>/) {
1138 } elsif (m/^(\S+)/) {
1141 if ($subsection ne "Standard" && $subsection ne "Private") {
1142 $KnownSymbols{$symbol} = 1;
1145 $KnownSymbols{$symbol} = 0;
1153 #############################################################################
1154 # Function : OutputDeclaration
1155 # Description : Returns the synopsis and detailed description DocBook
1156 # describing one function/macro etc.
1157 # Arguments : $symbol - the name of the function/macro begin described.
1158 # $declaration - the declaration of the function/macro.
1159 #############################################################################
1161 sub OutputDeclaration {
1162 my ($symbol, $declaration) = @_;
1164 my $type = $DeclarationTypes {$symbol};
1165 if ($type eq 'MACRO') {
1166 return &OutputMacro ($symbol, $declaration);
1167 } elsif ($type eq 'TYPEDEF') {
1168 return &OutputTypedef ($symbol, $declaration);
1169 } elsif ($type eq 'STRUCT') {
1170 return &OutputStruct ($symbol, $declaration);
1171 } elsif ($type eq 'ENUM') {
1172 return &OutputEnum ($symbol, $declaration);
1173 } elsif ($type eq 'UNION') {
1174 return &OutputUnion ($symbol, $declaration);
1175 } elsif ($type eq 'VARIABLE') {
1176 return &OutputVariable ($symbol, $declaration);
1177 } elsif ($type eq 'FUNCTION') {
1178 return &OutputFunction ($symbol, $declaration, $type);
1179 } elsif ($type eq 'USER_FUNCTION') {
1180 return &OutputFunction ($symbol, $declaration, $type);
1182 die "Unknown symbol type";
1187 #############################################################################
1188 # Function : OutputSymbolTraits
1189 # Description : Returns the Since and StabilityLevel paragraphs for a symbol.
1190 # Arguments : $symbol - the name of the function/macro begin described.
1191 #############################################################################
1193 sub OutputSymbolTraits {
1197 if (exists $Since{$symbol}) {
1198 $desc .= "<para role=\"since\">Since $Since{$symbol}</para>";
1200 if (exists $StabilityLevel{$symbol}) {
1201 $desc .= "<para role=\"stability\">Stability Level: $StabilityLevel{$symbol}</para>";
1206 #############################################################################
1207 # Function : Outpu{Symbol,Section}ExtraLinks
1208 # Description : Returns extralinks for the symbol (if enabled).
1209 # Arguments : $symbol - the name of the function/macro begin described.
1210 #############################################################################
1214 return undef unless defined $text;
1216 # Build a char to hex map
1219 $escapes{chr($_)} = sprintf("%%%02X", $_);
1222 # Default unsafe characters. RFC 2732 ^(uric - reserved)
1223 $text =~ s/([^A-Za-z0-9\-_.!~*'()])/$escapes{$1}/g;
1228 sub OutputSymbolExtraLinks {
1232 if (0) { # NEW FEATURE: needs configurability
1233 my $sstr = &uri_escape($symbol);
1234 my $mstr = &uri_escape($MODULE);
1236 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1237 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&symbol=$sstr">edit documentation</ulink>
1243 sub OutputSectionExtraLinks {
1244 my ($symbol,$docsymbol) = @_;
1247 if (0) { # NEW FEATURE: needs configurability
1248 my $sstr = &uri_escape($symbol);
1249 my $mstr = &uri_escape($MODULE);
1250 my $dsstr = &uri_escape($docsymbol);
1252 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1253 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&symbol=$dsstr">edit documentation</ulink>
1260 #############################################################################
1261 # Function : OutputMacro
1262 # Description : Returns the synopsis and detailed description of a macro.
1263 # Arguments : $symbol - the macro.
1264 # $declaration - the declaration of the macro.
1265 #############################################################################
1268 my ($symbol, $declaration) = @_;
1269 my $id = &CreateValidSGMLID ($symbol);
1270 my $condition = &MakeConditionDescription ($symbol);
1271 my $synop = &MakeReturnField("#define") . "<link linkend=\"$id\">$symbol</link>";
1277 if ($declaration =~ m/^\s*#\s*define(\s+)\w+(\([^\)]*\))/) {
1281 if (length ($symbol) < $SYMBOL_FIELD_WIDTH) {
1282 $synop .= (' ' x ($SYMBOL_FIELD_WIDTH - length ($symbol)));
1285 # Try to align all the lines of args correctly.
1286 $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH + $SYMBOL_FIELD_WIDTH + 1);
1287 my $args_padded = $args;
1288 $args_padded =~ s/ *\\\n */\n$pad/gm;
1289 $synop .= &CreateValidSGML ($args_padded);
1293 my $title = $symbol . ($args ? "()" : "");
1294 $desc = "<refsect2 id=\"$id\" role=\"macro\"$condition>\n<title>$title</title>\n";
1295 $desc .= MakeIndexterms($symbol, $id);
1297 $desc .= OutputSymbolExtraLinks($symbol);
1299 # Don't output the macro definition if is is a conditional macro or it
1300 # looks like a function, i.e. starts with "g_" or "_?gnome_", or it is
1301 # longer than 2 lines, otherwise we get lots of complicated macros like
1303 if (!defined ($DeclarationConditional{$symbol}) && ($symbol !~ m/^g_/)
1304 && ($symbol !~ m/^_?gnome_/) && (($declaration =~ tr/\n//) < 2)) {
1305 my $decl_out = &CreateValidSGML ($declaration);
1306 $desc .= "<programlisting>$decl_out</programlisting>\n";
1308 $desc .= "<programlisting>" . &MakeReturnField("#define") . "$symbol";
1309 # Align each line so that if should all line up OK.
1310 $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH - length ("#define "));
1311 $args =~ s/\n/\n$pad/gm;
1312 $desc .= &CreateValidSGML ($args);
1313 $desc .= "</programlisting>\n";
1316 $desc .= &MakeDeprecationNote($symbol);
1318 my $parameters = &OutputParamDescriptions ("MACRO", $symbol);
1319 my $parameters_output = 0;
1321 if (defined ($SymbolDocs{$symbol})) {
1322 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1324 # Try to insert the parameter table at the author's desired position.
1325 # Otherwise we need to tag it onto the end.
1326 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1327 $parameters_output = 1;
1329 $desc .= $symbol_docs;
1332 if ($parameters_output == 0) {
1333 $desc .= $parameters;
1336 $desc .= OutputSymbolTraits ($symbol);
1337 $desc .= "</refsect2>\n";
1338 return ($synop, $desc);
1342 #############################################################################
1343 # Function : OutputTypedef
1344 # Description : Returns the synopsis and detailed description of a typedef.
1345 # Arguments : $symbol - the typedef.
1346 # $declaration - the declaration of the typedef,
1347 # e.g. 'typedef unsigned int guint;'
1348 #############################################################################
1351 my ($symbol, $declaration) = @_;
1352 my $id = &CreateValidSGMLID ($symbol);
1353 my $condition = &MakeConditionDescription ($symbol);
1354 my $synop = &MakeReturnField("typedef") . "<link linkend=\"$id\">$symbol</link>;\n";
1355 my $desc = "<refsect2 id=\"$id\" role=\"typedef\"$condition>\n<title>$symbol</title>\n";
1357 $desc .= MakeIndexterms($symbol, $id);
1359 $desc .= OutputSymbolExtraLinks($symbol);
1361 if (!defined ($DeclarationConditional{$symbol})) {
1362 my $decl_out = &CreateValidSGML ($declaration);
1363 $desc .= "<programlisting>$decl_out</programlisting>\n";
1366 $desc .= &MakeDeprecationNote($symbol);
1368 if (defined ($SymbolDocs{$symbol})) {
1369 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1371 $desc .= OutputSymbolTraits ($symbol);
1372 $desc .= "</refsect2>\n";
1373 return ($synop, $desc);
1377 #############################################################################
1378 # Function : OutputStruct
1379 # Description : Returns the synopsis and detailed description of a struct.
1380 # We check if it is a object struct, and if so we only output
1381 # parts of it that are noted as public fields.
1382 # We also use a different SGML ID for object structs, since the
1383 # original ID is used for the entire RefEntry.
1384 # Arguments : $symbol - the struct.
1385 # $declaration - the declaration of the struct.
1386 #############################################################################
1389 my ($symbol, $declaration) = @_;
1391 my $is_object_struct = 0;
1392 my $default_to_public = 1;
1393 if (&CheckIsObject ($symbol)) {
1394 #print "Found object struct: $symbol\n";
1395 $is_object_struct = 1;
1396 $default_to_public = 0;
1401 if ($is_object_struct) {
1402 $id = &CreateValidSGMLID ($symbol . "_struct");
1403 $condition = &MakeConditionDescription ($symbol . "_struct");
1405 $id = &CreateValidSGMLID ($symbol);
1406 $condition = &MakeConditionDescription ($symbol);
1409 # Determine if it is a simple struct or it also has a typedef.
1410 my $has_typedef = 0;
1411 if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1418 # For structs with typedefs we just output the struct name.
1419 $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1420 $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>$symbol</title>\n";
1422 $synop = &MakeReturnField("struct") . "<link linkend=\"$id\">$symbol</link>;\n";
1423 $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>struct $symbol</title>\n";
1426 $desc .= MakeIndexterms($symbol, $id);
1428 $desc .= OutputSymbolExtraLinks($symbol);
1430 # Form a pretty-printed, private-data-removed form of the declaration
1433 if ($declaration =~ m/^\s*$/) {
1434 #print "Found opaque struct: $symbol\n";
1435 $decl_out = "typedef struct _$symbol $symbol;";
1436 } elsif ($declaration =~ m/^\s*struct\s+\w+\s*;\s*$/) {
1437 #print "Found opaque struct: $symbol\n";
1438 $decl_out = "struct $symbol;";
1440 my $public = $default_to_public;
1441 my $new_declaration = "";
1443 my $decl = $declaration;
1445 if ($decl =~ m/^\s*(typedef\s+)?struct\s*\w*\s*(?:\/\*.*\*\/)?\s*{(.*)}\s*\w*\s*;\s*$/s) {
1446 my $struct_contents = $2;
1448 foreach $decl_line (split (/\n/, $struct_contents)) {
1449 #print "Struct line: $decl_line\n";
1450 if ($decl_line =~ m%/\*\s*<\s*public\s*>\s*\*/%) {
1452 } elsif ($decl_line =~ m%/\*\s*<\s*(private|protected)\s*>\s*\*/%) {
1455 $new_declaration .= $decl_line . "\n";
1459 if ($new_declaration) {
1460 # Strip any blank lines off the ends.
1461 $new_declaration =~ s/^\s*\n//;
1462 $new_declaration =~ s/\n\s*$/\n/;
1465 $decl_out = "typedef struct {\n" . $new_declaration
1468 $decl_out = "struct $symbol {\n" . $new_declaration
1473 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1474 "Couldn't parse struct:\n$declaration");
1477 # If we couldn't parse the struct or it was all private, output an
1478 # empty struct declaration.
1479 if ($decl_out eq "") {
1481 $decl_out = "typedef struct _$symbol $symbol;";
1483 $decl_out = "struct $symbol;";
1488 $decl_out = &CreateValidSGML ($decl_out);
1489 $desc .= "<programlisting>$decl_out</programlisting>\n";
1491 $desc .= &MakeDeprecationNote($symbol);
1493 if (defined ($SymbolDocs{$symbol})) {
1494 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1497 # Create a table of fields and descriptions
1499 # FIXME: Inserting  's into the produced type declarations here would
1500 # improve the output in most situations ... except for function
1501 # members of structs!
1502 my @fields = ParseStructDeclaration($declaration, !$default_to_public,
1505 "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1507 my $params = $SymbolParams{$symbol};
1509 # If no parameters are filled in, we don't generate the description
1510 # table, for backwards compatibility
1513 if (defined $params) {
1514 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1515 if ($params->[$i] =~ /\S/) {
1523 my %field_descrs = @$params;
1524 my $missing_parameters = "";
1526 $desc .= "<variablelist role=\"struct\">\n";
1528 my $field_name = shift @fields;
1529 my $text = shift @fields;
1530 my $field_descr = $field_descrs{$field_name};
1531 my $param_annotations = "";
1533 $desc .= "<varlistentry><term>$text</term>\n";
1534 if (defined $field_descr) {
1535 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1536 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1537 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1539 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1540 "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1541 if ($missing_parameters ne "") {
1542 $missing_parameters .= ", ".$field_name;
1544 $missing_parameters = $field_name;
1546 $desc .= "<listitem />\n";
1548 $desc .= "</varlistentry>\n";
1550 $desc .= "</variablelist>";
1552 # remember missing parameters (needed in tmpl-free build)
1553 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1554 $AllIncompleteSymbols{$symbol}=$missing_parameters;
1558 if (scalar(@fields) > 0) {
1559 if (! exists ($AllIncompleteSymbols{$symbol})) {
1560 $AllIncompleteSymbols{$symbol}="<items>";
1561 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1562 "Field descriptions for $symbol are missing in source code comment block.");
1567 $desc .= OutputSymbolTraits ($symbol);
1568 $desc .= "</refsect2>\n";
1569 return ($synop, $desc);
1573 #############################################################################
1574 # Function : OutputUnion
1575 # Description : Returns the synopsis and detailed description of a union.
1576 # Arguments : $symbol - the union.
1577 # $declaration - the declaration of the union.
1578 #############################################################################
1581 my ($symbol, $declaration) = @_;
1582 my $id = &CreateValidSGMLID ($symbol);
1583 my $condition = &MakeConditionDescription ($symbol);
1585 # Determine if it is a simple struct or it also has a typedef.
1586 my $has_typedef = 0;
1587 if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1594 # For unions with typedefs we just output the union name.
1595 $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1596 $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>$symbol</title>\n";
1598 $synop = &MakeReturnField("union") . "<link linkend=\"$id\">$symbol</link>;\n";
1599 $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>union $symbol</title>\n";
1602 $desc .= MakeIndexterms($symbol, $id);
1604 $desc .= OutputSymbolExtraLinks($symbol);
1606 # FIXME: we do more for structs
1607 my $decl_out = &CreateValidSGML ($declaration);
1608 $desc .= "<programlisting>$decl_out</programlisting>\n";
1610 $desc .= &MakeDeprecationNote($symbol);
1612 if (defined ($SymbolDocs{$symbol})) {
1613 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1616 # Create a table of fields and descriptions
1618 # FIXME: Inserting  's into the produced type declarations here would
1619 # improve the output in most situations ... except for function
1620 # members of structs!
1621 my @fields = ParseStructDeclaration($declaration, 0,
1624 "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1626 my $params = $SymbolParams{$symbol};
1628 # If no parameters are filled in, we don't generate the description
1629 # table, for backwards compatibility
1632 if (defined $params) {
1633 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1634 if ($params->[$i] =~ /\S/) {
1642 my %field_descrs = @$params;
1643 my $missing_parameters = "";
1645 $desc .= "<variablelist role=\"union\">\n";
1647 my $field_name = shift @fields;
1648 my $text = shift @fields;
1649 my $field_descr = $field_descrs{$field_name};
1650 my $param_annotations = "";
1652 $desc .= "<varlistentry><term>$text</term>\n";
1653 if (defined $field_descr) {
1654 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1655 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1656 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1658 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1659 "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1660 if ($missing_parameters ne "") {
1661 $missing_parameters .= ", ".$field_name;
1663 $missing_parameters = $field_name;
1665 $desc .= "<listitem />\n";
1667 $desc .= "</varlistentry>\n";
1669 $desc .= "</variablelist>";
1671 # remember missing parameters (needed in tmpl-free build)
1672 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1673 $AllIncompleteSymbols{$symbol}=$missing_parameters;
1677 if (scalar(@fields) > 0) {
1678 if (! exists ($AllIncompleteSymbols{$symbol})) {
1679 $AllIncompleteSymbols{$symbol}="<items>";
1680 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1681 "Field descriptions for $symbol are missing in source code comment block.");
1686 $desc .= OutputSymbolTraits ($symbol);
1687 $desc .= "</refsect2>\n";
1688 return ($synop, $desc);
1692 #############################################################################
1693 # Function : OutputEnum
1694 # Description : Returns the synopsis and detailed description of a enum.
1695 # Arguments : $symbol - the enum.
1696 # $declaration - the declaration of the enum.
1697 #############################################################################
1700 my ($symbol, $declaration) = @_;
1701 my $id = &CreateValidSGMLID ($symbol);
1702 my $condition = &MakeConditionDescription ($symbol);
1703 my $synop = &MakeReturnField("enum") . "<link linkend=\"$id\">$symbol</link>;\n";
1704 my $desc = "<refsect2 id=\"$id\" role=\"enum\"$condition>\n<title>enum $symbol</title>\n";
1706 $desc .= MakeIndexterms($symbol, $id);
1708 $desc .= OutputSymbolExtraLinks($symbol);
1710 my $decl_out = &CreateValidSGML ($declaration);
1711 $desc .= "<programlisting>$decl_out</programlisting>\n";
1713 $desc .= &MakeDeprecationNote($symbol);
1715 if (defined ($SymbolDocs{$symbol})) {
1716 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1719 # Create a table of fields and descriptions
1721 my @fields = ParseEnumDeclaration($declaration);
1722 my $params = $SymbolParams{$symbol};
1724 # If no parameters are filled in, we don't generate the description
1725 # table, for backwards compatibility
1728 if (defined $params) {
1729 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1730 if ($params->[$i] =~ /\S/) {
1738 my %field_descrs = @$params;
1739 my $missing_parameters = "";
1741 $desc .= "<variablelist role=\"enum\">\n";
1742 for my $field_name (@fields) {
1743 my $field_descr = $field_descrs{$field_name};
1744 my $param_annotations = "";
1746 $id = &CreateValidSGMLID ($field_name);
1747 $condition = &MakeConditionDescription ($field_name);
1748 $desc .= "<varlistentry id=\"$id\" role=\"constant\"$condition>\n<term><literal>$field_name</literal></term>\n";
1749 if (defined $field_descr) {
1750 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1751 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1752 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1754 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1755 "Value description for $symbol"."::"."$field_name is missing in source code comment block.");
1756 if ($missing_parameters ne "") {
1757 $missing_parameters .= ", ".$field_name;
1759 $missing_parameters = $field_name;
1761 $desc .= "<listitem />\n";
1763 $desc .= "</varlistentry>\n";
1765 $desc .= "</variablelist>";
1767 # remember missing parameters (needed in tmpl-free build)
1768 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1769 $AllIncompleteSymbols{$symbol}=$missing_parameters;
1773 if (scalar(@fields) > 0) {
1774 if (! exists ($AllIncompleteSymbols{$symbol})) {
1775 $AllIncompleteSymbols{$symbol}="<items>";
1776 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1777 "Value descriptions for $symbol are missing in source code comment block.");
1782 $desc .= OutputSymbolTraits ($symbol);
1783 $desc .= "</refsect2>\n";
1784 return ($synop, $desc);
1788 #############################################################################
1789 # Function : OutputVariable
1790 # Description : Returns the synopsis and detailed description of a variable.
1791 # Arguments : $symbol - the extern'ed variable.
1792 # $declaration - the declaration of the variable.
1793 #############################################################################
1795 sub OutputVariable {
1796 my ($symbol, $declaration) = @_;
1797 my $id = &CreateValidSGMLID ($symbol);
1798 my $condition = &MakeConditionDescription ($symbol);
1801 if ($declaration =~ m/^\s*extern\s+((const\s+|unsigned\s+)*\w+)(\s+\*+|\*+|\s)(\s*)([A-Za-z]\w*)\s*;/) {
1802 my $mod = defined ($1) ? $1 : "";
1803 my $ptr = defined ($3) ? $3 : "";
1804 my $space = defined ($4) ? $4 : "";
1805 $synop = &MakeReturnField("extern") . "$mod$ptr$space<link linkend=\"$id\">$symbol</link>;\n";
1808 $synop = &MakeReturnField("extern") . "<link linkend=\"$id\">$symbol</link>;\n";
1811 my $desc = "<refsect2 id=\"$id\" role=\"variable\"$condition>\n<title>$symbol</title>\n";
1813 $desc .= MakeIndexterms($symbol, $id);
1815 $desc .= OutputSymbolExtraLinks($symbol);
1817 my $decl_out = &CreateValidSGML ($declaration);
1818 $desc .= "<programlisting>$decl_out</programlisting>\n";
1820 $desc .= &MakeDeprecationNote($symbol);
1822 if (defined ($SymbolDocs{$symbol})) {
1823 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1825 $desc .= OutputSymbolTraits ($symbol);
1826 $desc .= "</refsect2>\n";
1827 return ($synop, $desc);
1831 #############################################################################
1832 # Function : OutputFunction
1833 # Description : Returns the synopsis and detailed description of a function.
1834 # Arguments : $symbol - the function.
1835 # $declaration - the declaration of the function.
1836 #############################################################################
1838 sub OutputFunction {
1839 my ($symbol, $declaration, $symbol_type) = @_;
1840 my $id = &CreateValidSGMLID ($symbol);
1841 my $condition = &MakeConditionDescription ($symbol);
1843 # Take out the return type $1 $3 $4
1844 $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//;
1845 my $type_modifier = defined($1) ? $1 : "";
1848 #print "$symbol pointer is $pointer\n";
1849 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1851 #if ($symbol_type eq 'USER_FUNCTION') {
1852 # $start = "typedef ";
1855 # We output const rather than G_CONST_RETURN.
1856 $type_modifier =~ s/G_CONST_RETURN/const/g;
1857 $pointer =~ s/G_CONST_RETURN/const/g;
1858 $pointer =~ s/^\s+/ /g;
1860 my $ret_type_len = length ($start) + length ($type_modifier)
1861 + length ($pointer) + length ($type);
1862 my $ret_type_output;
1864 if ($ret_type_len < $RETURN_TYPE_FIELD_WIDTH) {
1865 $ret_type_output = "$start$type_modifier$xref$pointer"
1866 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
1869 #$ret_type_output = "$start$type_modifier$xref$pointer\n" . (' ' x $RETURN_TYPE_FIELD_WIDTH);
1871 $ret_type_output = "$start$type_modifier$xref$pointer ";
1872 $symbol_len = $ret_type_len + 1 - $RETURN_TYPE_FIELD_WIDTH;
1875 $symbol_len += length ($symbol);
1876 my $char1 = my $char2 = my $char3 = "";
1877 if ($symbol_type eq 'USER_FUNCTION') {
1884 my ($symbol_output, $symbol_desc_output);
1885 if ($symbol_len < $SYMBOL_FIELD_WIDTH) {
1886 $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3"
1887 . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1888 $symbol_desc_output = "$char1$char2$symbol$char3"
1889 . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1891 $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3\n"
1892 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1893 $symbol_desc_output = "$char1$char2$symbol$char3\n"
1894 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1897 my $synop = $ret_type_output . $symbol_output . '(';
1898 my $desc = "<refsect2 id=\"$id\" role=\"function\"$condition>\n<title>${symbol} ()</title>\n";
1900 $desc .= MakeIndexterms($symbol, $id);
1902 $desc .= OutputSymbolExtraLinks($symbol);
1904 $desc .= "<programlisting>${ret_type_output}$symbol_desc_output(";
1907 while ($declaration ne "") {
1908 #print "$declaration";
1910 if ($declaration =~ s/^[\s,]+//) {
1911 # skip whitespace and commas
1914 } elsif ($declaration =~ s/^void\s*[,\n]//) {
1918 } elsif ($declaration =~ s/^...\s*[,\n]//) {
1919 if ($param_num == 0) {
1924 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1927 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1931 # allow alphanumerics, '_', '[' & ']' in param names
1932 # Try to match a standard parameter (keep in sync with gtkdoc-mktmpl)
1934 } 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]//) {
1935 my $pre = defined($1) ? $1 : "";
1937 my $ptr = defined($3) ? $3 : "";
1938 my $name = defined($4) ? $4 : "";
1939 my $array = defined($5) ? $5 : "";
1945 if ($ptr && $ptr !~ m/\*$/) { $ptr .= " "; }
1947 #print "$symbol: '$pre' '$type' '$ptr' '$name' '$array'\n";
1949 if (($name eq "") && $pre =~ m/^((un)?signed .*)\s?/ ) {
1955 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1956 my $label = "$pre$xref $ptr$name$array";
1958 #print "$symbol: '$pre' '$type' '$ptr' '$name' '$array'\n";
1960 if ($param_num == 0) {
1965 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1968 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1972 # Try to match parameters which are functions (keep in sync with gtkdoc-mktmpl)
1973 # $1 $2 $3 $4 $5 $7 $8
1974 } 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]//) {
1975 my $mod1 = defined($1) ? $1 : "";
1976 if (defined($2)) { $mod1 .= $2; }
1979 my $mod2 = defined($5) ? $5 : "";
1982 my $func_params = defined($8) ? $8 : "";
1984 #if (!defined($type)) { print "## no type\n"; };
1985 #if (!defined($ptr1)) { print "## no ptr1\n"; };
1986 #if (!defined($func_ptr)) { print "## no func_ptr\n"; };
1987 #if (!defined($name)) { print "## no name\n"; };
1989 if ($ptr1 && $ptr1 !~ m/\*$/) { $ptr1 .= " "; }
1990 $func_ptr =~ s/\s+//g;
1991 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1992 my $label = "$mod1$xref$ptr1$mod2 ($func_ptr$name) ($func_params)";
1994 #print "Type: [$mod1][$xref][$ptr1][$mod2] ([$func_ptr][$name]) ($func_params)\n";
1995 if ($param_num == 0) {
2000 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2003 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2008 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2009 "Can't parse args for function $symbol: $declaration");
2015 $desc .= ");</programlisting>\n";
2017 $desc .= &MakeDeprecationNote($symbol);
2019 my $parameters = &OutputParamDescriptions ("FUNCTION", $symbol);
2020 my $parameters_output = 0;
2022 if (defined ($SymbolDocs{$symbol})) {
2023 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
2025 # Try to insert the parameter table at the author's desired position.
2026 # Otherwise we need to tag it onto the end.
2027 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
2028 $parameters_output = 1;
2030 $desc .= $symbol_docs;
2033 if ($parameters_output == 0) {
2034 $desc .= $parameters;
2037 $desc .= OutputSymbolTraits ($symbol);
2038 $desc .= "</refsect2>\n";
2039 return ($synop, $desc);
2043 #############################################################################
2044 # Function : OutputParamDescriptions
2045 # Description : Returns the DocBook output describing the parameters of a
2046 # function, macro or signal handler.
2047 # Arguments : $symbol_type - 'FUNCTION', 'MACRO' or 'SIGNAL'. Signal
2048 # handlers have an implicit user_data parameter last.
2049 # $symbol - the name of the function/macro being described.
2050 #############################################################################
2052 sub OutputParamDescriptions {
2053 my ($symbol_type, $symbol) = @_;
2055 if (defined ($SymbolParams{$symbol})) {
2057 my $params = $SymbolParams{$symbol};
2058 my $params_desc = "";
2060 for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
2061 my $param_name = $$params[$j];
2062 my $param_desc = $$params[$j + 1];
2063 my $param_annotations = "";
2065 ($param_desc,$param_annotations) = & ExpandAnnotation($symbol, $param_desc);
2066 $param_desc = &ExpandAbbreviations($symbol, $param_desc);
2067 if ($param_name eq "Returns") {
2068 $returns = "$param_desc$param_annotations";
2070 if ($param_name eq "Varargs") {
2071 $param_name = "...";
2073 $params_desc .= "<varlistentry><term><parameter>$param_name</parameter> :</term>\n<listitem><simpara>$param_desc$param_annotations</simpara></listitem></varlistentry>\n";
2077 # Signals have an implicit user_data parameter which we describe.
2078 if ($symbol_type eq "SIGNAL") {
2079 $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";
2082 # Start a table if we need one.
2083 if ($params_desc || $returns) {
2084 $output .= "<variablelist role=\"params\">\n";
2085 if ($params_desc ne "") {
2086 #$output .= "<varlistentry><term>Parameters:</term><listitem></listitem></varlistentry>\n";
2087 $output .= $params_desc;
2090 # Output the returns info last.
2092 $output .= "<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>$returns</simpara></listitem></varlistentry>\n";
2096 $output .= "</variablelist>";
2103 #############################################################################
2104 # Function : ParseStabilityLevel
2105 # Description : Parses a stability level and outputs a warning if it isn't
2107 # Arguments : $stability - the stability text.
2108 # $file, $line - context for error message
2109 # $message - description of where the level is from, to use in
2110 # any error message.
2111 # Returns : The parsed stability level string.
2112 #############################################################################
2114 sub ParseStabilityLevel {
2115 my ($stability, $file, $line, $message) = @_;
2117 $stability =~ s/^\s*//;
2118 $stability =~ s/\s*$//;
2119 if ($stability =~ m/^stable$/i) {
2120 $stability = "Stable";
2121 } elsif ($stability =~ m/^unstable$/i) {
2122 $stability = "Unstable";
2123 } elsif ($stability =~ m/^private$/i) {
2124 $stability = "Private";
2126 &LogWarning ($file, $line, "$message is $stability.".
2127 "It should be one of these: Stable, Unstable, or Private.");
2133 #############################################################################
2134 # Function : OutputSGMLFile
2135 # Description : Outputs the final DocBook file for one section.
2136 # Arguments : $file - the name of the file.
2137 # $title - the title from the $MODULE-sections.txt file, which
2138 # will be overridden by the title in the template file.
2139 # $section_id - the SGML id to use for the toplevel tag.
2140 # $includes - comma-separates list of include files added at top
2141 # of synopsis, with '<' '>' around them (if not already enclosed in "").
2142 # $synopsis - reference to the DocBook for the Synopsis part.
2143 # $details - reference to the DocBook for the Details part.
2144 # $signal_synop - reference to the DocBook for the Signal Synopsis part
2145 # $signal_desc - reference to the DocBook for the Signal Description part
2146 # $args_synop - reference to the DocBook for the Arg Synopsis part
2147 # $args_desc - reference to the DocBook for the Arg Description part
2148 # $hierarchy - reference to the DocBook for the Object Hierarchy part
2149 # $interfaces - reference to the DocBook for the Interfaces part
2150 # $implementations - reference to the DocBook for the Known Implementations part
2151 # $prerequisites - reference to the DocBook for the Prerequisites part
2152 # $derived - reference to the DocBook for the Derived Interfaces part
2153 # $file_objects - reference to an array of objects in this file
2154 #############################################################################
2156 sub OutputSGMLFile {
2157 my ($file, $title, $section_id, $includes, $synopsis, $details, $signals_synop, $signals_desc, $args_synop, $args_desc, $hierarchy, $interfaces, $implementations, $prerequisites, $derived, $file_objects) = @_;
2159 #print "Output sgml for file $file with title '$title'\n";
2161 # The edited title overrides the one from the sections file.
2162 my $new_title = $SymbolDocs{"$TMPL_DIR/$file:Title"};
2163 if (defined ($new_title) && $new_title !~ m/^\s*$/) {
2164 $title = $new_title;
2165 #print "Found title: $title\n";
2167 my $short_desc = $SymbolDocs{"$TMPL_DIR/$file:Short_Description"};
2168 if (!defined ($short_desc) || $short_desc =~ m/^\s*$/) {
2171 $short_desc = &ExpandAbbreviations("$title:Short_description",
2173 #print "Found short_desc: $short_desc";
2175 my $long_desc = $SymbolDocs{"$TMPL_DIR/$file:Long_Description"};
2176 if (!defined ($long_desc) || $long_desc =~ m/^\s*$/) {
2179 $long_desc = &ExpandAbbreviations("$title:Long_description",
2181 #print "Found long_desc: $long_desc";
2183 my $see_also = $SymbolDocs{"$TMPL_DIR/$file:See_Also"};
2184 if (!defined ($see_also) || $see_also =~ m%^\s*(<para>)?\s*(</para>)?\s*$%) {
2187 $see_also = &ExpandAbbreviations("$title:See_Also", $see_also);
2188 #print "Found see_also: $see_also";
2191 $see_also = "<refsect1 id=\"$section_id.see-also\">\n<title>See Also</title>\n$see_also\n</refsect1>\n";
2193 my $stability = $SymbolDocs{"$TMPL_DIR/$file:Stability_Level"};
2194 if (!defined ($stability) || $stability =~ m/^\s*$/) {
2197 $stability = &ParseStabilityLevel($stability, $file, $., "Section stability level");
2198 #print "Found stability: $stability";
2201 $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$stability, unless otherwise indicated\n</refsect1>\n";
2202 } elsif ($DEFAULT_STABILITY) {
2203 $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$DEFAULT_STABILITY, unless otherwise indicated\n</refsect1>\n";
2206 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
2208 my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
2211 my $include_output = "";
2213 foreach $include (split (/,/, $includes)) {
2214 if ($include =~ m/^\".+\"$/) {
2215 $include_output .= "#include ${include}\n";
2218 $include =~ s/^\s+|\s+$//gs;
2219 $include_output .= "#include <${include}>\n";
2222 if ($include_output ne '') {
2223 $include_output = "\n$include_output\n";
2226 my $extralinks = OutputSectionExtraLinks($title,"Section:$file");
2228 my $old_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT";
2229 my $new_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT.new";
2231 open (OUTPUT, ">$new_sgml_file")
2232 || die "Can't create $new_sgml_file: $!";
2234 my $object_anchors = "";
2235 foreach my $object (@$file_objects) {
2236 next if ($object eq $section_id);
2237 my $id = CreateValidSGMLID($object);
2238 #print "Debug: Adding anchor for $object\n";
2239 $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
2242 # We used to output this, but is messes up our UpdateFileIfChanged code
2243 # since it changes every day (and it is only used in the man pages):
2244 # "<refentry id="$section_id" revision="$mday $month $year">"
2246 if (lc($OUTPUT_FORMAT) eq "xml") {
2247 print OUTPUT $doctype_header;
2251 <refentry id="$section_id">
2253 <refentrytitle role="top_of_page" id="$section_id.top_of_page">$title</refentrytitle>
2254 <manvolnum>3</manvolnum>
2255 <refmiscinfo>\U$MODULE\E Library</refmiscinfo>
2258 <refname>$title</refname>
2259 <refpurpose>$short_desc</refpurpose>
2262 <refsynopsisdiv id="$section_id.synopsis" role="synopsis">
2263 <title role="synopsis.title">Synopsis</title>
2265 <synopsis>$include_output$${synopsis}</synopsis>
2267 $$hierarchy$$prerequisites$$derived$$interfaces$$implementations$$args_synop$$signals_synop
2268 <refsect1 id="$section_id.description" role="desc">
2269 <title role="desc.title">Description</title>
2270 $extralinks$long_desc
2272 <refsect1 id="$section_id.details" role="details">
2273 <title role="details.title">Details</title>
2276 $$args_desc$$signals_desc$see_also
2281 return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2285 #############################################################################
2286 # Function : OutputExtraFile
2287 # Description : Copies an "extra" DocBook file into the output directory,
2288 # expanding abbreviations
2289 # Arguments : $file - the source file.
2290 #############################################################################
2291 sub OutputExtraFile {
2296 ($basename = $file) =~ s!^.*/!!;
2298 my $old_sgml_file = "$SGML_OUTPUT_DIR/$basename";
2299 my $new_sgml_file = "$SGML_OUTPUT_DIR/$basename.new";
2303 open(EXTRA_FILE, "<$file") || die "Can't open $file";
2307 $contents = <EXTRA_FILE>;
2310 open (OUTPUT, ">$new_sgml_file")
2311 || die "Can't create $new_sgml_file: $!";
2313 print OUTPUT &ExpandAbbreviations ("$basename file", $contents);
2316 return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2318 #############################################################################
2319 # Function : OutputBook
2320 # Description : Outputs the SGML entities that need to be included into the
2321 # main SGML file for the module.
2322 # Arguments : $book_top - the declarations of the entities, which are added
2323 # at the top of the main SGML file.
2324 # $book_bottom - the references to the entities, which are
2325 # added in the main SGML file at the desired position.
2326 #############################################################################
2329 my ($book_top, $book_bottom) = @_;
2331 my $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top";
2332 my $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top.new";
2334 open (OUTPUT, ">$new_file")
2335 || die "Can't create $new_file: $!";
2336 print OUTPUT $book_top;
2339 &UpdateFileIfChanged ($old_file, $new_file, 0);
2342 $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom";
2343 $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom.new";
2345 open (OUTPUT, ">$new_file")
2346 || die "Can't create $new_file: $!";
2347 print OUTPUT $book_bottom;
2350 &UpdateFileIfChanged ($old_file, $new_file, 0);
2353 # If the main SGML file hasn't been created yet, we create it here.
2354 # The user can tweak it later.
2355 if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
2356 open (OUTPUT, ">$MAIN_SGML_FILE")
2357 || die "Can't create $MAIN_SGML_FILE: $!";
2359 if (lc($OUTPUT_FORMAT) eq "xml") {
2361 <?xml version="1.0"?>
2362 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
2363 "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
2365 <!ENTITY % local.common.attrib "xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'">
2371 <!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
2380 <title>$MODULE Reference Manual</title>
2382 for $MODULE [VERSION].
2383 The latest version of this documentation can be found on-line at
2384 <ulink role="online-location" url="http://[SERVER]/$MODULE/index.html">http://[SERVER]/$MODULE/</ulink>.
2389 <title>[Insert title here]</title>
2393 if (-e $OBJECT_TREE_FILE) {
2395 <chapter id="object-tree">
2396 <title>Object Hierarchy</title>
2397 <xi:include href="xml/tree_index.sgml"/>
2403 <index id="api-index-full">
2404 <title>API Index</title>
2405 <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
2408 <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
2417 #############################################################################
2418 # Function : CreateValidSGML
2419 # Description : This turns any chars which are used in SGML into entities,
2420 # e.g. '<' into '<'
2421 # Arguments : $text - the text to turn into proper SGML.
2422 #############################################################################
2424 sub CreateValidSGML {
2426 $text =~ s/&/&/g; # Do this first, or the others get messed up.
2427 $text =~ s/</</g;
2428 $text =~ s/>/>/g;
2429 # browers render single tabs inconsistently
2430 $text =~ s/([^\s])\t([^\s])/$1 $2/g;
2434 #############################################################################
2435 # Function : ConvertSGMLChars
2436 # Description : This is used for text in source code comment blocks, to turn
2437 # chars which are used in SGML into entities, e.g. '<' into
2438 # '<'. Depending on $SGML_MODE, this is done
2439 # unconditionally or only if the character doesn't seem to be
2440 # part of an SGML construct (tag or entity reference).
2441 # Arguments : $text - the text to turn into proper SGML.
2442 #############################################################################
2444 sub ConvertSGMLChars {
2445 my ($symbol, $text) = @_;
2448 # For the SGML mode only convert to entities outside CDATA sections.
2449 return &ModifyXMLElements ($text, $symbol,
2450 "<!\\[CDATA\\[|<programlisting[^>]*>",
2451 \&ConvertSGMLCharsEndTag,
2452 \&ConvertSGMLCharsCallback);
2454 # For the simple non-sgml mode, convert to entities everywhere.
2455 $text =~ s/&/&/g; # Do this first, or the others get messed up.
2456 $text =~ s/</</g;
2457 $text =~ s/>/>/g;
2463 sub ConvertSGMLCharsEndTag {
2464 if ($_[0] eq "<!\[CDATA\[") {
2467 return "</programlisting>";
2471 sub ConvertSGMLCharsCallback {
2472 my ($text, $symbol, $tag) = @_;
2474 if ($tag =~ m/^<programlisting/) {
2475 # We can handle <programlisting> specially here.
2476 return &ModifyXMLElements ($text, $symbol,
2478 \&ConvertSGMLCharsEndTag,
2479 \&ConvertSGMLCharsCallback2);
2480 } elsif ($tag eq "") {
2481 # If we're not in CDATA convert to entities.
2482 $text =~ s/&(?![a-zA-Z#]+;)/&/g; # Do this first, or the others get messed up.
2483 $text =~ s/<(?![a-zA-Z\/!])/</g;
2484 $text =~ s/(?<![a-zA-Z0-9"'\/-])>/>/g;
2486 # Handle "#include <xxxxx>"
2487 $text =~ s/#include(\s+)<([^>]+)>/#include$1<$2>/g;
2493 sub ConvertSGMLCharsCallback2 {
2494 my ($text, $symbol, $tag) = @_;
2496 # If we're not in CDATA convert to entities.
2497 # We could handle <programlisting> differently, though I'm not sure it helps.
2499 # replace only if its not a tag
2500 $text =~ s/&(?![a-zA-Z#]+;)/&/g; # Do this first, or the others get messed up.
2501 $text =~ s/<(?![a-zA-Z\/!])/</g;
2502 $text =~ s/(?<![a-zA-Z0-9"'\/-])>/>/g;
2504 # Handle "#include <xxxxx>"
2505 $text =~ s/#include(\s+)<([^>]+)>/#include$1<$2>/g;
2511 #############################################################################
2512 # Function : ExpandAnnotation
2513 # Description : This turns annotations into acrony tags.
2514 # Arguments : $symbol - the symbol being documented, for error messages.
2515 # $text - the text to expand.
2516 #############################################################################
2517 sub ExpandAnnotation {
2518 my ($symbol, $param_desc) = @_;
2519 my $param_annotations = "";
2521 if ($param_desc =~ m%\s*\((.*)\):%) {
2524 my $annotation_extra = "";
2527 @annotations = split(/\)\s*\(/,$1);
2528 foreach $annotation (@annotations) {
2529 # need to search for the longest key-match in %AnnotationDefinition
2531 my $match_annotation="";
2533 foreach $annotationdef (keys %AnnotationDefinition) {
2534 if ($annotation =~ m/^$annotationdef/) {
2535 if (length($annotationdef)>$match_length) {
2536 $match_length=length($annotationdef);
2537 $match_annotation=$annotationdef;
2541 if ($match_annotation ne "") {
2542 if ($annotation =~ m%$match_annotation\s+(.*)%) {
2543 $annotation_extra = " $1";
2545 $AnnotationsUsed{$match_annotation} = 1;
2546 $param_annotations .= "<acronym>$match_annotation</acronym>$annotation_extra. ";
2549 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2550 "unknown annotation \"$annotation\" in documentation for $symbol.");
2551 $param_annotations=$annotation;
2555 $param_desc =~ m/^(.*)\.*\s*$/;
2556 $param_desc = "$1. ";
2558 return ($param_desc, $param_annotations);
2561 #############################################################################
2562 # Function : ExpandAbbreviations
2563 # Description : This turns the abbreviations function(), macro(), @param,
2564 # %constant, and #symbol into appropriate DocBook markup.
2565 # CDATA sections and <programlisting> parts are skipped.
2566 # Arguments : $symbol - the symbol being documented, for error messages.
2567 # $text - the text to expand.
2568 #############################################################################
2570 sub ExpandAbbreviations {
2571 my ($symbol, $text) = @_;
2573 # Convert "|[" and "]|" into the start and end of program listing examples.
2574 $text =~ s%\|\[%<informalexample><programlisting>%g;
2575 $text =~ s%\]\|%</programlisting></informalexample>%g;
2576 # TODO: check for a xml comment after |[ and pick the language attribute from
2579 # keep CDATA unmodified, preserve ulink tags (ideally we preseve all tags
2581 return &ModifyXMLElements ($text, $symbol,
2582 "<!\\[CDATA\\[|<ulink[^>]*>|<programlisting[^>]*>|<!DOCTYPE",
2583 \&ExpandAbbreviationsEndTag,
2584 \&ExpandAbbreviationsCallback);
2588 # Returns the end tag corresponding to the given start tag.
2589 sub ExpandAbbreviationsEndTag {
2590 my ($start_tag) = @_;
2592 if ($start_tag eq "<!\[CDATA\[") {
2594 } elsif ($start_tag eq "<!DOCTYPE") {
2596 } elsif ($start_tag =~ m/<(\w+)/) {
2601 # Called inside or outside each CDATA or <programlisting> section.
2602 sub ExpandAbbreviationsCallback {
2603 my ($text, $symbol, $tag) = @_;
2605 if ($tag =~ m/^<programlisting/) {
2606 # Handle any embedded CDATA sections.
2607 return &ModifyXMLElements ($text, $symbol,
2609 \&ExpandAbbreviationsEndTag,
2610 \&ExpandAbbreviationsCallback2);
2611 } elsif ($tag eq "") {
2612 # We are outside any CDATA or <programlisting> sections, so we expand
2613 # any gtk-doc abbreviations.
2615 # Convert 'function()' or 'macro()'.
2616 # if there is abc_*_def() we don't want to make a link to _def()
2617 # FIXME: also handle abc(....) : but that would need to be done recursively :/
2618 $text =~ s/([^\*.\w])(\w+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2619 # handle #Object.func()
2620 $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2622 # Convert '@param', but not '\@param'.
2623 $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)/$1<parameter>$2<\/parameter>/g;
2624 $text =~ s/\\\@/\@/g;
2626 # Convert '%constant', but not '\%constant'.
2627 # Also allow negative numbers, e.g. %-1.
2628 $text =~ s/(\A|[^\\])\%(-?\w+)/$1.&MakeXRef($2, &tagify($2, "literal"));/eg;
2629 $text =~ s/\\\%/\%/g;
2631 # Convert '#symbol', but not '\#symbol'.
2632 $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)/$1.&MakeHashXRef($2, "type");/eg;
2636 # FIXME: should we skip urls that are already tagged? (e.g. <literal>http://...</literal>)
2637 # this is apparently also called for markup and not just for plain text
2639 #$text =~ s%(http|https|ftp)://(.*?)((?:\s|,|\)|\]|\<|\.\s))%<ulink url="$1://$2">$2</ulink>$3%g;
2641 # TODO: optionally check all words from $text against internal symbols and
2642 # warn if those could be xreffed, but miss a %,# or ()
2648 # This is called inside a <programlisting>
2649 sub ExpandAbbreviationsCallback2 {
2650 my ($text, $symbol, $tag) = @_;
2653 # We are inside a <programlisting> but outside any CDATA sections,
2654 # so we expand any gtk-doc abbreviations.
2655 # FIXME: why is this different from &ExpandAbbreviationsCallback(),
2656 # why not just call it
2657 $text =~ s/#(\w+)/&MakeHashXRef($1, "");/eg;
2664 my ($symbol, $tag) = @_;;
2667 # Check for things like '#include', '#define', and skip them.
2668 if ($PreProcessorDirectives{$symbol}) {
2672 # Get rid of any special '-struct' suffix.
2673 $text =~ s/-struct$//;
2675 # If the symbol is in the form "Object::signal", then change the symbol to
2676 # "Object-signal" and use "signal" as the text.
2677 if ($symbol =~ s/::/-/) {
2681 # If the symbol is in the form "Object:property", then change the symbol to
2682 # "Object--property" and use "property" as the text.
2683 if ($symbol =~ s/:/--/) {
2688 $text = tagify ($text, $tag);
2691 return &MakeXRef($symbol, $text);
2695 #############################################################################
2696 # Function : ModifyXMLElements
2697 # Description : Looks for given XML element tags within the text, and calls
2698 # the callback on pieces of text inside & outside those elements.
2699 # Used for special handling of text inside things like CDATA
2700 # and <programlisting>.
2701 # Arguments : $text - the text.
2702 # $symbol - the symbol currently being documented (only used for
2704 # $start_tag_regexp - the regular expression to match start tags.
2705 # e.g. "<!\\[CDATA\\[|<programlisting[^>]*>" to match
2706 # CDATA sections or programlisting elements.
2707 # $end_tag_func - function which is passed the matched start tag
2708 # and should return the appropriate end tag string.
2709 # $callback - callback called with each part of the text. It is
2710 # called with a piece of text, the symbol being
2711 # documented, and the matched start tag or "" if the text
2712 # is outside the XML elements being matched.
2713 #############################################################################
2714 sub ModifyXMLElements {
2715 my ($text, $symbol, $start_tag_regexp, $end_tag_func, $callback) = @_;
2716 my ($before_tag, $start_tag, $end_tag_regexp, $end_tag);
2719 while ($text =~ m/$start_tag_regexp/s) {
2720 $before_tag = $`; # Prematch for last successful match string
2721 $start_tag = $&; # Last successful match
2722 $text = $'; # Postmatch for last successful match string
2724 $result .= &$callback ($before_tag, $symbol, "");
2725 $result .= $start_tag;
2727 # get the mathing end-tag for current tag
2728 $end_tag_regexp = &$end_tag_func ($start_tag);
2730 if ($text =~ m/$end_tag_regexp/s) {
2735 $result .= &$callback ($before_tag, $symbol, $start_tag);
2736 $result .= $end_tag;
2738 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2739 "Can't find tag end: $end_tag_regexp in docs for: $symbol.");
2740 # Just assume it is all inside the tag.
2741 $result .= &$callback ($text, $symbol, $start_tag);
2746 # Handle any remaining text outside the tags.
2747 $result .= &$callback ($text, $symbol, "");
2756 # Adds a tag around some text.
2757 # e.g tagify("Text", "literal") => "<literal>Text</literal>".
2759 my ($text, $elem) = @_;
2760 return "<" . $elem . ">" . $text . "</" . $elem . ">";
2764 #############################################################################
2765 # Function : MakeXRef
2766 # Description : This returns a cross-reference link to the given symbol.
2767 # Though it doesn't try to do this for a few standard C types
2768 # that it knows won't be in the documentation.
2769 # Arguments : $symbol - the symbol to try to create a XRef to.
2770 # $text - text text to put inside the XRef, defaults to $symbol
2771 #############################################################################
2774 my ($symbol, $text) = ($_[0], $_[1]);
2776 $symbol =~ s/^\s+//;
2777 $symbol =~ s/\s+$//;
2779 if (!defined($text)) {
2782 # Get rid of special '-struct' suffix.
2783 $text =~ s/-struct$//;
2786 if ($symbol =~ m/ /) {
2790 #print "Getting type link for $symbol -> $text\n";
2792 my $symbol_id = &CreateValidSGMLID ($symbol);
2793 return "<link linkend=\"$symbol_id\">$text</link>";
2797 #############################################################################
2798 # Function : MakeIndexterms
2799 # Description : This returns a indexterm elements for the given symbol
2800 # Arguments : $symbol - the symbol to create indexterms for
2801 #############################################################################
2803 sub MakeIndexterms {
2804 my ($symbol, $id) = @_;
2808 # make the index useful, by ommiting the namespace when sorting
2809 if ($NAME_SPACE ne "") {
2810 if ($symbol =~ m/^$NAME_SPACE\_?(.*)/i) {
2811 $sortas=" sortas=\"$1\"";
2815 if (exists $Deprecated{$symbol}) {
2816 $terms .= "<indexterm zone=\"$id\" role=\"deprecated\"><primary$sortas>$symbol</primary></indexterm>";
2817 $IndexEntriesDeprecated{$symbol}=$id;
2818 $IndexEntriesFull{$symbol}=$id;
2820 if (exists $Since{$symbol}) {
2821 my $since = $Since{$symbol};
2825 $terms .= "<indexterm zone=\"$id\" role=\"$since\"><primary$sortas>$symbol</primary></indexterm>";
2827 $IndexEntriesSince{$symbol}=$id;
2828 $IndexEntriesFull{$symbol}=$id;
2831 $terms .= "<indexterm zone=\"$id\"><primary$sortas>$symbol</primary></indexterm>";
2832 $IndexEntriesFull{$symbol}=$id;
2838 #############################################################################
2839 # Function : MakeDeprecationNote
2840 # Description : This returns a deprecation warning for the given symbol.
2841 # Arguments : $symbol - the symbol to try to create a warning for.
2842 #############################################################################
2844 sub MakeDeprecationNote {
2845 my ($symbol) = $_[0];
2848 if (exists $Deprecated{$symbol}) {
2849 $desc .= "<warning>";
2851 if ($Deprecated{$symbol} =~ /^\s*([0-9\.]+)\s*:/) {
2852 $desc .= "<para><literal>$symbol</literal> has been deprecated since version $1 and should not be used in newly-written code.";
2854 $desc .= "<para><literal>$symbol</literal> is deprecated and should not be used in newly-written code.";
2856 if ($Deprecated{$symbol} ne "") {
2857 $note = &ExpandAbbreviations($symbol, $Deprecated{$symbol});
2858 $note =~ s/^\s*([0-9\.]+)\s*:\s*//;
2861 $note =~ s%\n{2,}%\n</para>\n<para>\n%g;
2862 $desc .= " " . $note;
2864 $desc .= "</para></warning>\n";
2869 #############################################################################
2870 # Function : MakeConditionDescription
2871 # Description : This returns a sumary of conditions for the given symbol.
2872 # Arguments : $symbol - the symbol to try to create the sumary.
2873 #############################################################################
2875 sub MakeConditionDescription {
2876 my ($symbol) = $_[0];
2879 if (exists $Deprecated{$symbol}) {
2884 if ($Deprecated{$symbol} =~ /^\s*(.*?)\s*$/) {
2885 $desc .= "deprecated:$1";
2887 $desc .= "deprecated";
2891 if (exists $Since{$symbol}) {
2896 if ($Since{$symbol} =~ /^\s*(.*?)\s*$/) {
2897 $desc .= "since:$1";
2903 if (exists $StabilityLevel{$symbol}) {
2907 $desc .= "stability:".$StabilityLevel{$symbol};
2911 $desc=" condition=\"".$desc."\"";
2912 #print "condition for '$symbol' = '$desc'\n";
2917 #############################################################################
2918 # Function : GetHierarchy
2919 # Description : Returns the DocBook output describing the ancestors and
2920 # immediate children of a GObject subclass. It uses the
2921 # global @Objects and @ObjectLevels arrays to walk the tree.
2922 # Arguments : $object - the GtkObject subclass.
2923 #############################################################################
2928 # Find object in the objects array.
2934 for ($i = 0; $i < @Objects; $i++) {
2936 if ($ObjectLevels[$i] <= $level) {
2939 elsif ($ObjectLevels[$i] == $level + 1) {
2940 push (@children, $Objects[$i]);
2943 elsif ($Objects[$i] eq $object) {
2946 $level = $ObjectLevels[$i];
2953 # Walk up the hierarchy, pushing ancestors onto the ancestors array.
2955 push (@ancestors, $object);
2956 #print "Level: $level\n";
2957 while ($level > 1) {
2959 if ($ObjectLevels[$j] < $level) {
2960 push (@ancestors, $Objects[$j]);
2961 $level = $ObjectLevels[$j];
2962 #print "Level: $level\n";
2966 # Output the ancestors list, indented and with links.
2967 my $hierarchy = "<synopsis>\n";
2969 for ($i = $#ancestors; $i >= 0; $i--) {
2971 # Don't add a link to the current object, i.e. when i == 0.
2973 my $ancestor_id = &CreateValidSGMLID ($ancestors[$i]);
2974 $link_text = "<link linkend=\"$ancestor_id\">$ancestors[$i]</link>";
2976 $link_text = "$ancestors[$i]";
2979 $hierarchy .= " $link_text\n";
2981 # $hierarchy .= ' ' x ($level * 6 - 3) . "|\n";
2982 $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
2986 for ($i = 0; $i <= $#children; $i++) {
2987 my $id = &CreateValidSGMLID ($children[$i]);
2988 my $link_text = "<link linkend=\"$id\">$children[$i]</link>";
2989 $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
2991 $hierarchy .= "</synopsis>\n";
2997 #############################################################################
2998 # Function : GetInterfaces
2999 # Description : Returns the DocBook output describing the interfaces
3000 # implemented by a class. It uses the global %Interfaces hash.
3001 # Arguments : $object - the GtkObject subclass.
3002 #############################################################################
3009 # Find object in the objects array.
3010 if (exists($Interfaces{$object})) {
3011 my @ifaces = split(' ', $Interfaces{$object});
3016 for ($i = 0; $i <= $#ifaces; $i++) {
3017 my $id = &CreateValidSGMLID ($ifaces[$i]);
3018 $text .= " <link linkend=\"$id\">$ifaces[$i]</link>";
3019 if ($i < $#ifaces - 1) {
3022 elsif ($i < $#ifaces) {
3037 #############################################################################
3038 # Function : GetImplementations
3039 # Description : Returns the DocBook output describing the implementations
3040 # of an interface. It uses the global %Interfaces hash.
3041 # Arguments : $object - the GtkObject subclass.
3042 #############################################################################
3044 sub GetImplementations {
3049 foreach my $key (keys %Interfaces) {
3050 if ($Interfaces{$key} =~ /\b$object\b/) {
3051 push (@impls, $key);
3057 $object is implemented by
3059 for ($i = 0; $i <= $#impls; $i++) {
3060 my $id = &CreateValidSGMLID ($impls[$i]);
3061 $text .= " <link linkend=\"$id\">$impls[$i]</link>";
3062 if ($i < $#impls - 1) {
3065 elsif ($i < $#impls) {
3080 #############################################################################
3081 # Function : GetPrerequisites
3082 # Description : Returns the DocBook output describing the prerequisites
3083 # of an interface. It uses the global %Prerequisites hash.
3084 # Arguments : $iface - the interface.
3085 #############################################################################
3087 sub GetPrerequisites {
3092 if (exists($Prerequisites{$iface})) {
3097 my @prereqs = split(' ', $Prerequisites{$iface});
3098 for ($i = 0; $i <= $#prereqs; $i++) {
3099 my $id = &CreateValidSGMLID ($prereqs[$i]);
3100 $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
3101 if ($i < $#prereqs - 1) {
3104 elsif ($i < $#prereqs) {
3118 #############################################################################
3119 # Function : GetDerived
3120 # Description : Returns the DocBook output describing the derived interfaces
3121 # of an interface. It uses the global %Prerequisites hash.
3122 # Arguments : $iface - the interface.
3123 #############################################################################
3131 foreach my $key (keys %Prerequisites) {
3132 if ($Prerequisites{$key} =~ /\b$iface\b/) {
3133 push (@derived, $key);
3136 if ($#derived >= 0) {
3139 $iface is required by
3141 for ($i = 0; $i <= $#derived; $i++) {
3142 my $id = &CreateValidSGMLID ($derived[$i]);
3143 $text .= " <link linkend=\"$id\">$derived[$i]</link>";
3144 if ($i < $#derived - 1) {
3147 elsif ($i < $#derived) {
3162 #############################################################################
3163 # Function : GetSignals
3164 # Description : Returns the synopsis and detailed description DocBook output
3165 # for the signal handlers of a given GtkObject subclass.
3166 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
3167 #############################################################################
3175 for ($i = 0; $i <= $#SignalObjects; $i++) {
3176 if ($SignalObjects[$i] eq $object) {
3177 #print "Found signal: $SignalNames[$i]\n";
3178 my $name = $SignalNames[$i];
3179 my $symbol = "${object}::${name}";
3180 my $id = &CreateValidSGMLID ("$object-$name");
3182 my $pad = ' ' x (46 - length($name));
3183 $synop .= " "<link linkend=\"$id\">$name</link>"$pad ";
3185 $desc .= "<refsect2 id=\"$id\" role=\"signal\"><title>The <literal>"$name"</literal> signal</title>\n";
3186 $desc .= MakeIndexterms($symbol, $id);
3188 $desc .= OutputSymbolExtraLinks($symbol);
3190 $desc .= "<programlisting>";
3192 $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
3193 my $type_modifier = defined($1) ? $1 : "";
3196 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
3198 my $ret_type_len = length ($type_modifier) + length ($pointer)
3200 my $ret_type_output = "$type_modifier$xref$pointer"
3201 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
3203 $desc .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
3205 my $sourceparams = $SourceSymbolParams{$symbol};
3206 my @params = split ("\n", $SignalPrototypes[$i]);
3209 my $type_len = length("gpointer");
3210 my $name_len = length("user_data");
3211 # do two passes, the first one is to calculate padding
3212 for ($l = 0; $l < 2; $l++) {
3213 for ($j = 0; $j <= $#params; $j++) {
3214 # allow alphanumerics, '_', '[' & ']' in param names
3215 if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
3218 if (defined($sourceparams)) {
3219 $name = $$sourceparams[$PARAM_FIELD_COUNT * $j];
3224 if (!defined($name)) {
3228 if (length($type) + length($pointer) > $type_len) {
3229 $type_len = length($type) + length($pointer);
3231 if (length($name) > $name_len) {
3232 $name_len = length($name);
3236 $xref = &MakeXRef ($type, &tagify($type, "type"));
3237 $pad = ' ' x ($type_len - length($type) - length($pointer));
3238 $desc .= "$xref$pad $pointer$name,\n";
3239 $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
3242 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3243 "Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]");
3247 $xref = &MakeXRef ("gpointer", &tagify("gpointer", "type"));
3248 $pad = ' ' x ($type_len - length("gpointer"));
3249 $desc .= "$xref$pad user_data)";
3251 my $flags = $SignalFlags[$i];
3252 my $flags_string = "";
3254 if (defined ($flags)) {
3255 if ($flags =~ m/f/) {
3256 $flags_string = "Run First";
3258 elsif ($flags =~ m/l/) {
3259 $flags_string = "Run Last";
3261 elsif ($flags =~ m/c/) {
3262 $flags_string = "Cleanup";
3264 if ($flags =~ m/r/) {
3265 if ($flags_string) { $flags_string .= " / "; }
3266 $flags_string .= "No Recursion";
3268 if ($flags =~ m/d/) {
3269 if ($flags_string) { $flags_string .= " / "; }
3270 $flags_string .= "Has Details";
3272 if ($flags =~ m/a/) {
3273 if ($flags_string) { $flags_string .= " / "; }
3274 $flags_string .= "Action";
3276 if ($flags =~ m/h/) {
3277 if ($flags_string) { $flags_string .= " / "; }
3278 $flags_string .= "No Hooks";
3284 $synop .= ": $flags_string\n";
3286 $pad = ' ' x (5 + $name_len - length("user_data"));
3287 $desc .= "$pad : $flags_string</programlisting>\n";
3292 $desc .= "</programlisting>\n";
3295 $desc .= &MakeDeprecationNote($symbol);
3297 my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
3298 my $parameters_output = 0;
3300 $AllSymbols{$symbol} = 1;
3301 if (defined ($SymbolDocs{$symbol})) {
3302 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3304 # Try to insert the parameter table at the author's desired
3305 # position. Otherwise we need to tag it onto the end.
3306 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
3307 $parameters_output = 1;
3309 $desc .= $symbol_docs;
3311 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
3312 $AllDocumentedSymbols{$symbol} = 1;
3316 if ($parameters_output == 0) {
3317 $desc .= $parameters;
3319 $desc .= OutputSymbolTraits ($symbol);
3320 $desc .= "</refsect2>";
3323 return ($synop, $desc);
3327 #############################################################################
3328 # Function : GetArgs
3329 # Description : Returns the synopsis and detailed description DocBook output
3330 # for the Args of a given GtkObject subclass.
3331 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
3332 #############################################################################
3338 my $child_synop = "";
3339 my $child_desc = "";
3340 my $style_synop = "";
3341 my $style_desc = "";
3344 for ($i = 0; $i <= $#ArgObjects; $i++) {
3345 if ($ArgObjects[$i] eq $object) {
3346 #print "Found arg: $ArgNames[$i]\n";
3347 my $name = $ArgNames[$i];
3348 my $flags = $ArgFlags[$i];
3349 my $flags_string = "";
3353 if ($flags =~ m/c/) {
3354 $kind = "child property";
3357 elsif ($flags =~ m/s/) {
3358 $kind = "style property";
3365 # Remember only one colon so we don't clash with signals.
3366 my $symbol = "${object}:${name}";
3367 # use two dashes and ev. an extra separator here for the same reason.
3368 my $id = &CreateValidSGMLID ("$object--$id_sep$name");
3370 my $type = $ArgTypes[$i];
3372 my $range = $ArgRanges[$i];
3373 my $range_output = CreateValidSGML ($range);
3374 my $default = $ArgDefaults[$i];
3375 my $default_output = CreateValidSGML ($default);
3377 if ($type eq "GtkString") {
3380 if ($type eq "GtkSignal") {
3381 $type = "GtkSignalFunc, gpointer";
3382 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
3383 . &MakeXRef ("gpointer");
3384 } elsif ($type =~ m/^(\w+)\*$/) {
3385 $type_output = &MakeXRef ($1, &tagify($1, "type")) . "*";
3387 $type_output = &MakeXRef ($type, &tagify($type, "type"));
3390 if ($flags =~ m/r/) {
3391 $flags_string = "Read";
3393 if ($flags =~ m/w/) {
3394 if ($flags_string) { $flags_string .= " / "; }
3395 $flags_string .= "Write";
3397 if ($flags =~ m/x/) {
3398 if ($flags_string) { $flags_string .= " / "; }
3399 $flags_string .= "Construct";
3401 if ($flags =~ m/X/) {
3402 if ($flags_string) { $flags_string .= " / "; }
3403 $flags_string .= "Construct Only";
3406 $AllSymbols{$symbol} = 1;
3408 if (defined($SymbolDocs{$symbol}) &&
3409 !IsEmptyDoc($SymbolDocs{$symbol})) {
3410 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3411 #print ".. [$SymbolDocs{$symbol}][$blurb]\n";
3412 $AllDocumentedSymbols{$symbol} = 1;
3415 if (!($ArgBlurbs[$i] eq "")) {
3416 $AllDocumentedSymbols{$symbol} = 1;
3418 # FIXME: print a warning?
3419 #print ".. no description\n";
3421 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
3424 my $pad1 = " " x (24 - length ($name));
3425 my $pad2 = " " x (20 - length ($type));
3427 my $arg_synop = " "<link linkend=\"$id\">$name</link>"$pad1 $type_output $pad2 : $flags_string\n";
3428 my $arg_desc = "<refsect2 id=\"$id\" role=\"property\"><title>The <literal>"$name"</literal> $kind</title>\n";
3429 $arg_desc .= MakeIndexterms($symbol, $id);
3431 $arg_desc .= OutputSymbolExtraLinks($symbol);
3433 $arg_desc .= "<programlisting> "$name"$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
3434 $arg_desc .= &MakeDeprecationNote($symbol);
3435 $arg_desc .= $blurb;
3437 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
3439 if ($default ne "") {
3440 $arg_desc .= "<para>Default value: $default_output</para>\n";
3442 $arg_desc .= OutputSymbolTraits ($symbol);
3443 $arg_desc .= "</refsect2>\n";
3445 if ($flags =~ m/c/) {
3446 $child_synop .= $arg_synop;
3447 $child_desc .= $arg_desc;
3449 elsif ($flags =~ m/s/) {
3450 $style_synop .= $arg_synop;
3451 $style_desc .= $arg_desc;
3454 $synop .= $arg_synop;
3459 return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
3463 #############################################################################
3464 # Function : ReadSourceDocumentation
3465 # Description : This reads in the documentation embedded in comment blocks
3466 # in the source code (for Gnome).
3468 # Parameter descriptions override any in the template files.
3469 # Function descriptions are placed before any description from
3470 # the template files.
3472 # It recursively descends the source directory looking for .c
3473 # files and scans them looking for specially-formatted comment
3476 # Arguments : $source_dir - the directory to scan.
3477 #############m###############################################################
3479 sub ReadSourceDocumentation {
3480 my ($source_dir) = @_;
3481 my ($file, $dir, @suffix_list, $suffix);
3482 #print "Scanning source directory: $source_dir\n";
3484 # This array holds any subdirectories found.
3487 @suffix_list = split (/,/, $SOURCE_SUFFIXES);
3489 opendir (SRCDIR, $source_dir)
3490 || die "Can't open source directory $source_dir: $!";
3492 foreach $file (readdir (SRCDIR)) {
3493 if ($file =~ /^\./) {
3495 } elsif (-d "$source_dir/$file") {
3496 push (@subdirs, $file);
3497 } elsif (@suffix_list) {
3498 foreach $suffix (@suffix_list) {
3499 if ($file =~ m/\.\Q${suffix}\E$/) {
3500 &ScanSourceFile ("$source_dir/$file");
3503 } elsif ($file =~ m/\.[ch]$/) {
3504 &ScanSourceFile ("$source_dir/$file");
3509 # Now recursively scan the subdirectories.
3510 foreach $dir (@subdirs) {
3511 next if ($IGNORE_FILES =~ m/(\s|^)\Q${dir}\E(\s|$)/);
3512 &ReadSourceDocumentation ("$source_dir/$dir");
3517 #############################################################################
3518 # Function : ScanSourceFile
3519 # Description : Scans one source file looking for specially-formatted comment
3520 # blocks. Later &MergeSourceDocumentation is used to merge any
3521 # documentation found with the documentation already read in
3522 # from the template files.
3524 # Arguments : $file - the file to scan.
3525 #############################################################################
3527 sub ScanSourceFile {
3531 if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
3534 &LogWarning ($file, 1, "Can't find basename for this filename.");
3538 # Check if the basename is in the list of files to ignore.
3539 if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
3543 #print "DEBUG: Scanning $file\n";
3545 open (SRCFILE, $file)
3546 || die "Can't open $file: $!";
3547 my $in_comment_block = 0;
3549 my ($in_description, $in_return, $in_since, $in_stability, $in_deprecated);
3550 my ($description, $return_desc, $return_start, $return_style);
3551 my ($since_desc, $stability_desc, $deprecated_desc);
3553 my $ignore_broken_returns;
3556 # Look for the start of a comment block.
3557 if (!$in_comment_block) {
3558 if (m%^\s*/\*.*\*/%) {
3559 #one-line comment - not gtkdoc
3560 } elsif (m%^\s*/\*\*\s%) {
3561 #print "Found comment block start\n";
3563 $in_comment_block = 1;
3565 # Reset all the symbol data.
3567 $in_description = 0;
3576 $deprecated_desc = "";
3577 $stability_desc = "";
3578 $current_param = -1;
3579 $ignore_broken_returns = 0;
3585 # We're in a comment block. Check if we've found the end of it.
3588 # maybe its not even meant to be a gtk-doc comment?
3589 &LogWarning ($file, $., "Symbol name not found at the start of the comment block.");
3591 # Add the return value description onto the end of the params.
3593 push (@params, "Returns");
3594 push (@params, $return_desc);
3595 if ($return_style eq 'broken') {
3596 &LogWarning ($file, $., "Free-form return value description in $symbol. Use `Returns:' to avoid ambiguities.");
3599 # Convert special SGML characters
3600 $description = &ConvertSGMLChars ($symbol, $description);
3602 for ($k = 1; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3603 $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
3606 # Handle Section docs
3607 if ($symbol =~ m/SECTION:\s*(.*)/) {
3611 if (scalar %KnownSymbols) {
3612 if ((! defined($KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"})) || $KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"} != 1) {
3613 &LogWarning ($file, $., "Section $real_symbol is not defined in the $MODULE-section.txt file.");
3617 #print "SECTION DOCS found in source for : '$real_symbol'\n";
3618 $ignore_broken_returns = 1;
3619 for ($k = 0; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3620 #print " '".$params[$k]."'\n";
3621 $params[$k] = "\L$params[$k]";
3623 if ($params[$k] eq "short_description") {
3624 $key = "$TMPL_DIR/$real_symbol:Short_Description";
3625 } elsif ($params[$k] eq "see_also") {
3626 $key = "$TMPL_DIR/$real_symbol:See_Also";
3627 } elsif ($params[$k] eq "title") {
3628 $key = "$TMPL_DIR/$real_symbol:Title";
3629 } elsif ($params[$k] eq "stability") {
3630 $key = "$TMPL_DIR/$real_symbol:Stability_Level";
3631 } elsif ($params[$k] eq "section_id") {
3632 $key = "$TMPL_DIR/$real_symbol:Section_Id";
3633 } elsif ($params[$k] eq "include") {
3634 $key = "$TMPL_DIR/$real_symbol:Include";
3636 if (defined($key)) {
3637 $SourceSymbolDocs{$key}=$params[$k+1];
3638 $SourceSymbolSourceFile{$key} = $file;
3639 $SourceSymbolSourceLine{$key} = $.;
3642 $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
3643 $SourceSymbolSourceFile{"$TMPL_DIR/$real_symbol:Long_Description"} = $file;
3644 $SourceSymbolSourceLine{"$TMPL_DIR/$real_symbol:Long_Description"} = $.;
3645 #$SourceSymbolTypes{$symbol} = "SECTION";
3647 #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
3648 $SourceSymbolDocs{$symbol} = $description;
3649 $SourceSymbolParams{$symbol} = [ @params ];
3650 # FIXME $SourceSymbolTypes{$symbol} = "STRUCT,SIGNAL,ARG,FUNCTION,MACRO";
3651 #if (defined $DeclarationTypes{$symbol}) {
3652 # $SourceSymbolTypes{$symbol} = $DeclarationTypes{$symbol}
3654 $SourceSymbolSourceFile{$symbol} = $file;
3655 $SourceSymbolSourceLine{$symbol} = $.;
3659 ($since_desc, my @extra_lines) = split ("\n", $since_desc);
3660 $since_desc =~ s/^\s+//;
3661 $since_desc =~ s/\s+$//;
3662 #print "Since($symbol) : [$since_desc]\n";
3663 $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
3664 if(scalar @extra_lines) {
3665 &LogWarning ($file, $., "multi-line since docs found");
3669 if ($stability_desc) {
3670 $stability_desc = &ParseStabilityLevel($stability_desc, $file, $., "Stability level for $symbol");
3671 $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
3674 if ($deprecated_desc) {
3675 if (exists $Deprecated{$symbol}) {
3678 # don't warn for signals and properties
3679 #if ($symbol !~ m/::?(.*)/) {
3680 if (defined $DeclarationTypes{$symbol}) {
3681 &LogWarning ($file, $.,
3682 "$symbol is deprecated in the inline comments, but no deprecation guards were found around the declaration.".
3683 " (See the --deprecated-guards option for gtkdoc-scan.)");
3686 $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
3690 $in_comment_block = 0;
3694 # Get rid of ' * ' at start of every line in the comment block.
3696 # But make sure we don't get rid of the newline at the end.
3700 #print "DEBUG: scanning :$_";
3702 # If we haven't found the symbol name yet, look for it.
3704 if (m%^\s*(SECTION:\s*\S+)%) {
3706 #print "SECTION DOCS found in source for : '$symbol'\n";
3707 $ignore_broken_returns = 1;
3708 } elsif (m%^\s*([\w:-]*\w)\s*:?\s*$%) {
3710 #print "SYMBOL DOCS found in source for : '$symbol'\n";
3715 # If we're in the return value description, add it to the end.
3717 # If we find another valid returns line, we assume that the first
3718 # one was really part of the description.
3719 if (m/^\s*(returns:|return\s+value:)/i) {
3720 if ($return_style eq 'broken') {
3721 $description .= $return_start . $return_desc;
3724 if ($return_style eq 'sane') {
3725 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3727 $return_style = 'sane';
3728 $ignore_broken_returns = 1;
3730 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3731 $description .= $return_start . $return_desc;
3733 $return_style = 'broken';
3735 } elsif (m%^\s*since:%i) {
3739 } elsif (m%^\s*stability:%i) {
3740 $stability_desc = $';
3743 } elsif (m%^\s*deprecated:%i) {
3744 $deprecated_desc = $';
3754 if (m/^\s*(returns:|return\s+value:)/i) {
3755 if ($return_style eq 'broken') {
3756 $description .= $return_start . $return_desc;
3759 if ($return_style eq 'sane') {
3760 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3762 $return_style = 'sane';
3763 $ignore_broken_returns = 1;
3767 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3769 $return_style = 'broken';
3773 } elsif (m%^\s*deprecated:%i) {
3774 $deprecated_desc = $';
3777 } elsif (m%^\s*stability:%i) {
3778 $stability_desc = $';
3787 if ($in_stability) {
3788 if (m/^\s*(returns:|return\s+value:)/i) {
3789 if ($return_style eq 'broken') {
3790 $description .= $return_start . $return_desc;
3793 if ($return_style eq 'sane') {
3794 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3796 $return_style = 'sane';
3797 $ignore_broken_returns = 1;
3801 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3803 $return_style = 'broken';
3807 } elsif (m%^\s*deprecated:%i) {
3808 $deprecated_desc = $';
3811 } elsif (m%^\s*since:%i) {
3816 $stability_desc .= $_;
3821 if ($in_deprecated) {
3822 if (m/^\s*(returns:|return\s+value:)/i) {
3823 if ($return_style eq 'broken') {
3824 $description .= $return_start . $return_desc;
3827 if ($return_style eq 'sane') {
3828 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3830 $return_style = 'sane';
3831 $ignore_broken_returns = 1;
3835 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3837 $return_style = 'broken';
3841 } elsif (m%^\s*since:%i) {
3845 } elsif (m%^\s*stability:%i) {
3846 $stability_desc = $';
3850 $deprecated_desc .= $_;
3855 # If we're in the description part, check for the 'Returns:' line.
3856 # If that isn't found, add the text to the end.
3857 if ($in_description) {
3858 # Get rid of 'Description:'
3859 s%^\s*Description:%%;
3861 if (m/^\s*(returns:|return\s+value:)/i) {
3862 if ($return_style eq 'broken') {
3863 $description .= $return_start . $return_desc;
3866 if ($return_style eq 'sane') {
3867 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3869 $return_style = 'sane';
3870 $ignore_broken_returns = 1;
3874 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3876 $return_style = 'broken';
3880 } elsif (m%^\s*since:%i) {
3884 } elsif (m%^\s*deprecated:%i) {
3885 $deprecated_desc = $';
3888 } elsif (m%^\s*stability:%i) {
3889 $stability_desc = $';
3898 # We must be in the parameters. Check for the empty line below them.
3900 $in_description = 1;
3904 # Look for a parameter name.
3905 if (m%^\s*@(\S+)\s*:\s*%) {
3906 my $param_name = $1;
3907 my $param_desc = $';
3909 #print "Found parameter: $param_name\n";
3910 # Allow '...' as the Varargs parameter.
3911 if ($param_name eq "...") {
3912 $param_name = "Varargs";
3914 if ("\L$param_name" eq "returns") {
3915 $return_style = 'sane';
3916 $ignore_broken_returns = 1;
3918 push (@params, $param_name);
3919 push (@params, $param_desc);
3920 $current_param += $PARAM_FIELD_COUNT;
3924 # We must be in the middle of a parameter description, so add it on
3925 # to the last element in @params.
3926 if ($current_param == -1) {
3927 &LogWarning ($file, $., "Parsing comment block file : parameter expected.");
3929 $params[$#params] .= $_;
3935 #############################################################################
3936 # Function : OutputMissingDocumentation
3937 # Description : Outputs report of documentation coverage to a file
3940 #############################################################################
3942 sub OutputMissingDocumentation {
3943 my $n_documented = 0;
3944 my $n_incomplete = 0;
3950 my $buffer_deprecated = "";
3951 my $buffer_descriptions = "";
3953 open (UNDOCUMENTED, ">$ROOT_DIR/$MODULE-undocumented.txt")
3954 || die "Can't create $ROOT_DIR/$MODULE-undocumented.txt: $!";
3956 foreach $symbol (sort (keys (%AllSymbols))) {
3957 # FIXME: should we print LogWarnings for undocumented stuff?
3959 #my $ssfile = &GetSymbolSourceFile($symbol);
3960 #my $ssline = &GetSymbolSourceLine($symbol);
3961 #my $location = "defined at " . (defined($ssfile)?$ssfile:"?") . ":" . (defined($ssline)?$ssline:"0") . "\n";
3963 if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include|Section_Id)/) {
3965 if (exists ($AllDocumentedSymbols{$symbol})) {
3967 if (exists ($AllIncompleteSymbols{$symbol})) {
3969 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3970 #$buffer .= "\t0: ".$location;
3972 } elsif (exists $Deprecated{$symbol}) {
3973 if (exists ($AllIncompleteSymbols{$symbol})) {
3975 $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3976 #$buffer .= "\t1a: ".$location;
3978 $buffer_deprecated .= $symbol . "\n";
3979 #$buffer .= "\t1b: ".$location;
3982 if (exists ($AllIncompleteSymbols{$symbol})) {
3984 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3985 #$buffer .= "\t2a: ".$location;
3987 $buffer .= $symbol . "\n";
3988 #$buffer .= "\t2b: ".$location;
3991 } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
3993 #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
3994 #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
3995 #print "%%%% $symbol : $len1,$len2\n";
3996 if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
3997 || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
4000 # cut off the leading namespace ($TMPL_DIR)
4001 $symbol =~ m/^.*\/(.*)$/;
4002 $buffer_descriptions .= $1 . "\n";
4007 $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
4012 $percent = ($n_documented / $total) * 100.0;
4015 printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
4016 print UNDOCUMENTED "$n_documented symbols documented.\n";
4017 print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
4018 print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
4020 print UNDOCUMENTED $buffer;
4022 close (UNDOCUMENTED);
4024 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);
4028 #############################################################################
4029 # Function : OutputUndeclaredSymbols
4030 # Description : Outputs symbols that are undeclared yet documented to a file
4033 #############################################################################
4035 sub OutputUndeclaredSymbols {
4036 open(UNDECLARED, ">$ROOT_DIR/$MODULE-undeclared.txt")
4037 || die "Can't create $ROOT_DIR/$MODULE-undeclared.txt";
4039 if (%UndeclaredSymbols) {
4040 print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
4041 print UNDECLARED "\n";
4042 print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
4048 #############################################################################
4049 # Function : OutputAllSymbols
4050 # Description : Outputs list of all symbols to a file
4053 #############################################################################
4055 sub OutputAllSymbols {
4056 my $n_documented = 0;
4062 open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
4063 || die "Can't create $ROOT_DIR/$MODULE-symbols.txt: $!";
4065 foreach $symbol (sort (keys (%AllSymbols))) {
4066 print SYMBOLS $symbol . "\n";
4072 #############################################################################
4073 # Function : OutputSymbolsWithoutSince
4074 # Description : Outputs list of all symbols without a since tag to a file
4077 #############################################################################
4079 sub OutputSymbolsWithoutSince {
4080 my $n_documented = 0;
4086 open (SYMBOLS, ">$ROOT_DIR/$MODULE-nosince.txt")
4087 || die "Can't create $ROOT_DIR/$MODULE-nosince.txt: $!";
4089 foreach $symbol (sort (keys (%SourceSymbolDocs))) {
4090 if (!defined $Since{$symbol}) {
4091 print SYMBOLS $symbol . "\n";
4099 #############################################################################
4100 # Function : MergeSourceDocumentation
4101 # Description : This merges documentation read from a source file into the
4102 # documentation read in from a template file.
4104 # Parameter descriptions override any in the template files.
4105 # Function descriptions are placed before any description from
4106 # the template files.
4109 #############################################################################
4111 sub MergeSourceDocumentation {
4115 if (scalar %SymbolDocs) {
4116 @Symbols=keys (%SymbolDocs);
4117 #print "num existing entries: ".(scalar @Symbols)."\n";
4118 #print " ",$Symbols[0], " ",$Symbols[1],"\n";
4121 # filter scanned declarations, with what we suppress from -sections.txt
4123 foreach $symbol (keys (%Declarations)) {
4124 if (defined($KnownSymbols{$symbol}) && $KnownSymbols{$symbol} == 1) {
4128 # , add the rest from -sections.txt
4129 foreach $symbol (keys (%KnownSymbols)) {
4130 if ($KnownSymbols{$symbol} == 1) {
4134 # and add whats found in the source
4135 foreach $symbol (keys (%SourceSymbolDocs)) {
4138 @Symbols = keys (%tmp);
4139 #print "num source entries: ".(scalar @Symbols)."\n";
4141 foreach $symbol (@Symbols) {
4142 $AllSymbols{$symbol} = 1;
4144 my $have_tmpl_docs = 0;
4146 ## See if the symbol is documented in template
4147 my $tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4148 my $check_tmpl_doc =$tmpl_doc;
4149 # remove all xml-tags and whitespaces
4150 #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
4151 $check_tmpl_doc =~ s/<.*?>//g;
4152 $check_tmpl_doc =~ s/\s//g;
4154 if ($check_tmpl_doc ne "") {
4155 $have_tmpl_docs = 1;
4156 #print "## [$check_tmpl_doc]\n";
4161 if (exists ($SourceSymbolDocs{$symbol})) {
4162 my $type = $DeclarationTypes {$symbol};
4164 #print "merging [$symbol] from source\n";
4166 my $item = "Parameter";
4167 if (defined ($type)) {
4168 if ($type eq 'STRUCT') {
4170 } elsif ($type eq 'ENUM') {
4172 } elsif ($type eq 'UNION') {
4179 my $src_doc = $SourceSymbolDocs{$symbol};
4180 # remove leading and training whitespaces
4181 $src_doc =~ s/^\s+//;
4182 $src_doc =~ s/\s+$//;
4184 # Don't output warnings for overridden titles as titles are
4185 # automatically generated in the -sections.txt file, and thus they
4186 # are often overridden.
4187 if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
4188 # check if content is different
4189 if ($tmpl_doc ne $src_doc) {
4190 #print "[$tmpl_doc] [$src_doc]\n";
4191 &LogWarning ($SourceSymbolSourceFile{$symbol}, $SourceSymbolSourceLine{$symbol},
4192 "Documentation in template ".$SymbolSourceFile{$symbol}.":".$SymbolSourceLine{$symbol}." for $symbol being overridden by inline comments.");
4196 if ($src_doc ne "") {
4197 $AllDocumentedSymbols{$symbol} = 1;
4200 # Convert <!--PARAMETERS--> with any blank lines around it to
4201 # a </para> followed by <!--PARAMETERS--> followed by <para>.
4202 $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
4204 # If there is a blank line, finish the paragraph and start another.
4205 $src_doc = &ConvertBlankLines ($src_doc, $symbol);
4206 # Do not add <para> to nothing, it breaks missing docs checks.
4207 my $src_doc_para = "";
4209 $src_doc_para = "<para>\n$src_doc</para>\n";
4210 #print "$symbol : [$src_doc][$src_doc_para]\n";
4213 if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
4214 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4215 } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
4216 # For the title/summary/see also section docs we don't want to
4217 # add any <para> tags.
4218 $SymbolDocs{$symbol} = "$src_doc"
4220 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4224 if ($symbol =~ m/.*::.*/) {
4225 # For signals we prefer the param names from the source docs,
4226 # since the ones from the templates are likely to contain the
4227 # artificial argn names which are generated by gtkdoc-scangobj.
4228 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4229 # FIXME: we need to check for empty docs here as well!
4231 # The templates contain the definitive parameter names and order,
4232 # so we will not change that. We only override the actual text.
4233 my $tmpl_params = $SymbolParams{$symbol};
4234 if (!defined ($tmpl_params)) {
4235 #print "No merge needed for $symbol\n";
4236 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4237 # FIXME: we still like to get the number of params and merge
4238 # 1) we would noticed that params have been removed/renamed
4239 # 2) we would catch undocumented params
4240 # params are not (yet) exported in -decl.txt so that we
4241 # could easily grab them :/
4243 my $params = $SourceSymbolParams{$symbol};
4245 #print "Merge needed for $symbol, tmpl_params: ",$#$tmpl_params,", source_params: ",$#$params," \n";
4246 for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4247 my $tmpl_param_name = $$tmpl_params[$j];
4249 # Allow '...' as the Varargs parameter.
4250 if ($tmpl_param_name eq "...") {
4251 $tmpl_param_name = "Varargs";
4254 # Try to find the param in the source comment documentation.
4257 #print " try merge param $tmpl_param_name\n";
4258 for ($k = 0; $k <= $#$params; $k += $PARAM_FIELD_COUNT) {
4259 my $param_name = $$params[$k];
4260 my $param_desc = $$params[$k + 1];
4262 #print " test param $param_name\n";
4263 # We accept changes in case, since the Gnome source
4264 # docs contain a lot of these.
4265 if ("\L$param_name" eq "\L$tmpl_param_name") {
4268 # Override the description.
4269 $$tmpl_params[$j + 1] = $param_desc;
4271 # Set the name to "" to mark it as used.
4277 # If it looks like the parameters are there, but not
4278 # in the right place, try to explain a bit better.
4279 if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
4280 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4281 "Parameters for $symbol must start on the line immediately after the function or macro name.");
4285 # Now we output a warning if parameters have been described which
4287 for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
4288 my $param_name = $$params[$j];
4290 # the template builder cannot detect if a macro returns
4292 if(($type eq "MACRO") && ($param_name eq "Returns")) {
4293 # FIXME: do we need to add it then to tmpl_params[] ?
4294 my $num=$#$tmpl_params;
4295 #print " adding Returns: to macro docs for $symbol.\n";
4296 $$tmpl_params[$num+1]="Returns";
4297 $$tmpl_params[$num+2]=$$params[$j+1];
4300 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4301 "$item described in source code comment block but does not exist. $type: $symbol $item: $param_name.");
4307 if ($have_tmpl_docs) {
4308 $AllDocumentedSymbols{$symbol} = 1;
4309 #print "merging [$symbol] from template\n";
4312 #print "[$symbol] undocumented\n";
4316 # if this symbol is documented, check if docs are complete
4317 $check_tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4318 # remove all xml-tags and whitespaces
4319 #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
4320 $check_tmpl_doc =~ s/<.*?>//g;
4321 $check_tmpl_doc =~ s/\s//g;
4322 if ($check_tmpl_doc ne "") {
4323 my $tmpl_params = $SymbolParams{$symbol};
4324 if (defined ($tmpl_params)) {
4325 my $type = $DeclarationTypes {$symbol};
4327 my $item = "Parameter";
4328 if (defined ($type)) {
4329 if ($type eq 'STRUCT') {
4331 } elsif ($type eq 'ENUM') {
4333 } elsif ($type eq 'UNION') {
4340 #print "Check param docs for $symbol, tmpl_params: ",$#$tmpl_params," entries, type=$type\n";
4342 if ($#$tmpl_params > 0) {
4344 for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4345 # Output a warning if the parameter is empty and
4346 # remember for stats.
4347 my $tmpl_param_name = $$tmpl_params[$j];
4348 my $tmpl_param_desc = $$tmpl_params[$j + 1];
4349 if ($tmpl_param_desc !~ m/\S/) {
4350 if (exists ($AllIncompleteSymbols{$symbol})) {
4351 $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
4353 $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
4355 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4356 "$item description for $symbol"."::"."$tmpl_param_name is missing in source code comment block.");
4361 if ($#$tmpl_params == 0) {
4362 $AllIncompleteSymbols{$symbol}="<items>";
4363 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4364 "$item descriptions for $symbol are missing in source code comment block.");
4366 # $#$tmpl_params==-1 means we don't know about parameters
4367 # this unfortunately does not tell if there should be some
4372 #print "num doc entries: ".(scalar %SymbolDocs)."\n";
4375 #############################################################################
4376 # Function : IsEmptyDoc
4377 # Description : Check if a doc-string is empty. Its also regarded as empty if
4378 # it only consist of whitespace or e.g. FIXME.
4379 # Arguments : the doc-string
4380 #############################################################################
4384 if ($doc =~ /^\s*$/) {
4388 if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
4396 # This converts blank lines to "</para><para>", but only outside CDATA and
4397 # <programlisting> tags.
4398 sub ConvertBlankLines {
4399 return &ModifyXMLElements ($_[0], $_[1],
4400 "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
4401 \&ConvertBlankLinesEndTag,
4402 \&ConvertBlankLinesCallback);
4406 sub ConvertBlankLinesEndTag {
4407 if ($_[0] eq "<!\[CDATA\[") {
4409 } elsif ($_[0] eq "|[") {
4412 return "</programlisting>";
4416 sub ConvertBlankLinesCallback {
4417 my ($text, $symbol, $tag) = @_;
4419 # If we're not in CDATA or a <programlisting> we convert blank lines so
4420 # they start a new <para>.
4422 $text =~ s%\n{2,}%\n</para>\n<para>\n%g;
4429 #############################################################################
4430 # LIBRARY FUNCTIONS - These functions are used in both gtkdoc-mkdb and
4431 # gtkdoc-mktmpl and should eventually be moved to a
4433 #############################################################################
4435 #############################################################################
4436 # Function : ReadDeclarationsFile
4437 # Description : This reads in a file containing the function/macro/enum etc.
4440 # Note that in some cases there are several declarations with
4441 # the same name, e.g. for conditional macros. In this case we
4442 # set a flag in the %DeclarationConditional hash so the
4443 # declaration is not shown in the docs.
4445 # If a macro and a function have the same name, e.g. for
4446 # gtk_object_ref, the function declaration takes precedence.
4448 # Some opaque structs are just declared with 'typedef struct
4449 # _name name;' in which case the declaration may be empty.
4450 # The structure may have been found later in the header, so
4451 # that overrides the empty declaration.
4453 # Arguments : $file - the declarations file to read
4454 # $override - if declarations in this file should override
4455 # any current declaration.
4456 #############################################################################
4458 sub ReadDeclarationsFile {
4459 my ($file, $override) = @_;
4461 if ($override == 0) {
4463 %DeclarationTypes = ();
4464 %DeclarationConditional = ();
4465 %DeclarationOutput = ();
4469 || die "Can't open $file: $!";
4470 my $declaration_type = "";
4471 my $declaration_name;
4473 my $is_deprecated = 0;
4475 if (!$declaration_type) {
4476 if (m/^<([^>]+)>/) {
4477 $declaration_type = $1;
4478 $declaration_name = "";
4479 #print "Found declaration: $declaration_type\n";
4483 if (m%^<NAME>(.*)</NAME>%) {
4484 $declaration_name = $1;
4485 } elsif (m%^<DEPRECATED/>%) {
4487 } elsif (m%^</$declaration_type>%) {
4488 #print "Found end of declaration: $declaration_name\n";
4489 # Check that the declaration has a name
4490 if ($declaration_name eq "") {
4491 print "ERROR: $declaration_type has no name $file:$.\n";
4494 # If the declaration is an empty typedef struct _XXX XXX
4495 # set the flag to indicate the struct has a typedef.
4496 if ($declaration_type eq 'STRUCT'
4497 && $declaration =~ m/^\s*$/) {
4498 #print "Struct has typedef: $declaration_name\n";
4499 $StructHasTypedef{$declaration_name} = 1;
4502 # Check if the symbol is already defined.
4503 if (defined ($Declarations{$declaration_name})
4504 && $override == 0) {
4505 # Function declarations take precedence.
4506 if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
4508 } elsif ($declaration_type eq 'FUNCTION') {
4509 if ($is_deprecated) {
4510 $Deprecated{$declaration_name} = "";
4512 $Declarations{$declaration_name} = $declaration;
4513 $DeclarationTypes{$declaration_name} = $declaration_type;
4514 } elsif ($DeclarationTypes{$declaration_name}
4515 eq $declaration_type) {
4516 # If the existing declaration is empty, or is just a
4517 # forward declaration of a struct, override it.
4518 if ($declaration_type eq 'STRUCT') {
4519 if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4520 if ($is_deprecated) {
4521 $Deprecated{$declaration_name} = "";
4523 $Declarations{$declaration_name} = $declaration;
4524 } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4525 # Ignore an empty or forward declaration.
4527 &LogWarning ($file, $., "Structure $declaration_name has multiple definitions.");
4530 # set flag in %DeclarationConditional hash for
4531 # multiply defined macros/typedefs.
4532 $DeclarationConditional{$declaration_name} = 1;
4535 &LogWarning ($file, $., "$declaration_name has multiple definitions.");
4538 if ($is_deprecated) {
4539 $Deprecated{$declaration_name} = "";
4541 $Declarations{$declaration_name} = $declaration;
4542 $DeclarationTypes{$declaration_name} = $declaration_type;
4545 $declaration_type = "";
4556 #############################################################################
4557 # Function : ReadSignalsFile
4558 # Description : This reads in an existing file which contains information on
4559 # all GTK signals. It creates the arrays @SignalNames and
4560 # @SignalPrototypes containing info on the signals. The first
4561 # line of the SignalPrototype is the return type of the signal
4562 # handler. The remaining lines are the parameters passed to it.
4563 # The last parameter, "gpointer user_data" is always the same
4564 # so is not included.
4565 # Arguments : $file - the file containing the signal handler prototype
4567 #############################################################################
4569 sub ReadSignalsFile {
4577 my $signal_prototype;
4579 # Reset the signal info.
4580 @SignalObjects = ();
4582 @SignalReturns = ();
4584 @SignalPrototypes = ();
4589 if (!open (INPUT, $file)) {
4590 warn "Can't open $file - skipping signals\n";
4597 $signal_object = "";
4599 $signal_returns = "";
4600 $signal_prototype = "";
4603 if (m/^<NAME>(.*)<\/NAME>/) {
4605 if ($signal_name =~ m/^(.*)::(.*)$/) {
4606 $signal_object = $1;
4607 ($signal_name = $2) =~ s/_/-/g;
4608 #print "Found signal: $signal_name\n";
4610 &LogWarning ($file, $., "Invalid signal name: $signal_name.");
4612 } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
4613 $signal_returns = $1;
4614 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4616 } elsif (m%^</SIGNAL>%) {
4617 #print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
4618 push (@SignalObjects, $signal_object);
4619 push (@SignalNames, $signal_name);
4620 push (@SignalReturns, $signal_returns);
4621 push (@SignalFlags, $signal_flags);
4622 push (@SignalPrototypes, $signal_prototype);
4625 $signal_prototype .= $_;
4633 #############################################################################
4634 # Function : ReadTemplateFile
4635 # Description : This reads in the manually-edited documentation file
4636 # corresponding to the file currently being created, so we can
4637 # insert the documentation at the appropriate places.
4638 # It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
4639 # is a hash of arrays.
4640 # NOTE: This function is duplicated in gtkdoc-mktmpl (but
4641 # slightly different).
4642 # Arguments : $docsfile - the template file to read in.
4643 # $skip_unused_params - 1 if the unused parameters should be
4645 #############################################################################
4647 sub ReadTemplateFile {
4648 my ($docsfile, $skip_unused_params) = @_;
4650 my $template = "$docsfile.sgml";
4651 if (! -f $template) {
4652 #print "File doesn't exist: $template\n";
4655 #print "Reading $template\n";
4657 # start with empty hashes, we merge the source comment for each file
4663 my $current_type = ""; # Type of symbol being read.
4664 my $current_symbol = ""; # Name of symbol being read.
4665 my $symbol_doc = ""; # Description of symbol being read.
4666 my @params; # Parameter names and descriptions of current
4667 # function/macro/function typedef.
4668 my $current_param = -1; # Index of parameter currently being read.
4669 # Note that the param array contains pairs
4670 # of param name & description.
4671 my $in_unused_params = 0; # True if we are reading in the unused params.
4672 my $in_deprecated = 0;
4674 my $in_stability = 0;
4676 open (DOCS, "$template")
4677 || die "Can't open $template: $!";
4679 if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
4682 if ($symbol eq "Title"
4683 || $symbol eq "Short_Description"
4684 || $symbol eq "Long_Description"
4685 || $symbol eq "See_Also"
4686 || $symbol eq "Stability_Level"
4687 || $symbol eq "Include") {
4689 $symbol = $docsfile . ":" . $symbol;
4692 #print "Found symbol: $symbol\n";
4693 # Remember file and line for the symbol
4694 $SymbolSourceFile{$symbol} = $template;
4695 $SymbolSourceLine{$symbol} = $.;
4697 # Store previous symbol, but remove any trailing blank lines.
4698 if ($current_symbol ne "") {
4699 $symbol_doc =~ s/\s+$//;
4700 $SymbolTypes{$current_symbol} = $current_type;
4701 $SymbolDocs{$current_symbol} = $symbol_doc;
4703 # Check that the stability level is valid.
4704 if ($StabilityLevel{$current_symbol}) {
4705 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4708 if ($current_param >= 0) {
4709 $SymbolParams{$current_symbol} = [ @params ];
4711 # Delete any existing params in case we are overriding a
4712 # previously read template.
4713 delete $SymbolParams{$current_symbol};
4716 $current_type = $type;
4717 $current_symbol = $symbol;
4718 $current_param = -1;
4719 $in_unused_params = 0;
4726 } elsif (m/^<!-- # Unused Parameters # -->/) {
4727 #print "DEBUG: Found unused parameters\n";
4728 $in_unused_params = 1;
4731 } elsif ($in_unused_params && $skip_unused_params) {
4732 # When outputting the DocBook we skip unused parameters.
4733 #print "DEBUG: Skipping unused param: $_";
4737 # Check if param found. Need to handle "..." and "format...".
4738 if (s/^\@([\w\.]+):\040?//) {
4739 my $param_name = $1;
4740 my $param_desc = $_;
4741 # Allow variations of 'Returns'
4742 if ($param_name =~ m/^[Rr]eturns?$/) {
4743 $param_name = "Returns";
4746 # strip trailing whitespaces and blank lines
4749 #print "Found param for symbol $current_symbol : '$param_name'= '$_'";
4751 if ($param_name eq "Deprecated") {
4753 $Deprecated{$current_symbol} = $_;
4754 } elsif ($param_name eq "Since") {
4757 $Since{$current_symbol} = $_;
4758 } elsif ($param_name eq "Stability") {
4760 $StabilityLevel{$current_symbol} = $_;
4762 push (@params, $param_name);
4763 push (@params, $param_desc);
4764 $current_param += $PARAM_FIELD_COUNT;
4767 # strip trailing whitespaces and blank lines
4772 if ($in_deprecated) {
4773 $Deprecated{$current_symbol} .= $_;
4774 } elsif ($in_since) {
4775 &LogWarning ($template, $., "multi-line since docs found");
4776 #$Since{$current_symbol} .= $_;
4777 } elsif ($in_stability) {
4778 $StabilityLevel{$current_symbol} .= $_;
4779 } elsif ($current_param >= 0) {
4780 $params[$current_param] .= $_;
4789 # Remember to finish the current symbol doccs.
4790 if ($current_symbol ne "") {
4792 $symbol_doc =~ s/\s+$//;
4793 $SymbolTypes{$current_symbol} = $current_type;
4794 $SymbolDocs{$current_symbol} = $symbol_doc;
4796 # Check that the stability level is valid.
4797 if ($StabilityLevel{$current_symbol}) {
4798 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4801 if ($current_param >= 0) {
4802 $SymbolParams{$current_symbol} = [ @params ];
4804 # Delete any existing params in case we are overriding a
4805 # previously read template.
4806 delete $SymbolParams{$current_symbol};
4815 #############################################################################
4816 # Function : ReadObjectHierarchy
4817 # Description : This reads in the $MODULE-hierarchy.txt file containing all
4818 # the GtkObject subclasses described in this module (and their
4820 # It places them in the @Objects array, and places their level
4821 # in the object hierarchy in the @ObjectLevels array, at the
4822 # same index. GtkObject, the root object, has a level of 1.
4824 # FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
4825 # as it goes along, this should be split out into a separate
4829 #############################################################################
4831 sub ReadObjectHierarchy {
4835 if (! -f $OBJECT_TREE_FILE) {
4838 if (!open (INPUT, $OBJECT_TREE_FILE)) {
4839 warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
4843 # FIXME: use $OUTPUT_FORMAT
4844 # my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.$OUTPUT_FORMAT";
4845 my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
4846 my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
4848 open (OUTPUT, ">$new_tree_index")
4849 || die "Can't create $new_tree_index: $!";
4851 if (lc($OUTPUT_FORMAT) eq "xml") {
4852 my $tree_header = $doctype_header;
4854 $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
4855 print (OUTPUT "$tree_header");
4857 print (OUTPUT "<screen>\n");
4859 # Only emit objects if they are supposed to be documented, or if
4860 # they have documented children. To implement this, we maintain a
4861 # stack of pending objects which will be emitted if a documented
4863 my @pending_objects = ();
4864 my @pending_levels = ();
4868 my $level = (length($`)) / 2 + 1;
4871 while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
4872 my $pobject = pop(@pending_objects);
4873 my $plevel = pop(@pending_levels);
4876 push (@pending_objects, $object);
4877 push (@pending_levels, $level);
4879 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
4880 while ($#pending_levels >= 0) {
4881 $object = shift @pending_objects;
4882 $level = shift @pending_levels;
4883 $xref = &MakeXRef ($object);
4885 print (OUTPUT ' ' x ($level * 4), "$xref\n");
4886 push (@Objects, $object);
4887 push (@ObjectLevels, $level);
4891 # LogWarning ($OBJECT_TREE_FILE, $., "unknown type $object");
4895 print (OUTPUT "</screen>\n");
4900 &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
4905 #############################################################################
4906 # Function : ReadInterfaces
4907 # Description : This reads in the $MODULE.interfaces file.
4910 #############################################################################
4912 sub ReadInterfaces {
4915 if (! -f $INTERFACES_FILE) {
4918 if (!open (INPUT, $INTERFACES_FILE)) {
4919 warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
4925 my ($object, @ifaces) = split;
4926 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
4927 my @knownIfaces = ();
4929 # filter out private interfaces, but leave foreign interfaces
4930 foreach my $iface (@ifaces) {
4931 if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
4932 push (@knownIfaces, $iface);
4936 $Interfaces{$object} = join(' ', @knownIfaces);
4942 #############################################################################
4943 # Function : ReadPrerequisites
4944 # Description : This reads in the $MODULE.prerequisites file.
4947 #############################################################################
4949 sub ReadPrerequisites {
4950 %Prerequisites = ();
4952 if (! -f $PREREQUISITES_FILE) {
4955 if (!open (INPUT, $PREREQUISITES_FILE)) {
4956 warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
4962 my ($iface, @prereqs) = split;
4963 if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
4964 my @knownPrereqs = ();
4966 # filter out private prerequisites, but leave foreign prerequisites
4967 foreach my $prereq (@prereqs) {
4968 if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
4969 push (@knownPrereqs, $prereq);
4973 $Prerequisites{$iface} = join(' ', @knownPrereqs);
4979 #############################################################################
4980 # Function : ReadArgsFile
4981 # Description : This reads in an existing file which contains information on
4982 # all GTK args. It creates the arrays @ArgObjects, @ArgNames,
4983 # @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
4985 # Arguments : $file - the file containing the arg information.
4986 #############################################################################
5001 # Reset the args info.
5014 if (!open (INPUT, $file)) {
5015 warn "Can't open $file - skipping args\n";
5032 if (m/^<NAME>(.*)<\/NAME>/) {
5034 if ($arg_name =~ m/^(.*)::(.*)$/) {
5036 ($arg_name = $2) =~ s/_/-/g;
5037 #print "Found arg: $arg_name\n";
5039 &LogWarning ($file, $., "Invalid argument name: $arg_name");
5041 } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
5043 } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
5045 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
5047 } elsif (m/^<NICK>(.*)<\/NICK>/) {
5049 } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
5051 if ($arg_blurb eq "(null)") {
5053 &LogWarning ($file, $., "Property ${arg_object}:${arg_name} has no documentation.");
5055 } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
5057 } elsif (m%^</ARG>%) {
5058 #print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
5059 push (@ArgObjects, $arg_object);
5060 push (@ArgNames, $arg_name);
5061 push (@ArgTypes, $arg_type);
5062 push (@ArgRanges, $arg_range);
5063 push (@ArgFlags, $arg_flags);
5064 push (@ArgNicks, $arg_nick);
5065 push (@ArgBlurbs, $arg_blurb);
5066 push (@ArgDefaults, $arg_default);
5075 #############################################################################
5076 # Function : CheckIsObject
5077 # Description : Returns 1 if the given name is a GObject or a subclass.
5078 # It uses the global @Objects array.
5079 # Note that the @Objects array only contains classes in the
5080 # current module and their ancestors - not all GObject classes.
5081 # Arguments : $name - the name to check.
5082 #############################################################################
5088 foreach $object (@Objects) {
5089 if ($object eq $name) {
5097 #############################################################################
5098 # Function : MakeReturnField
5099 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
5100 # Arguments : $str - the string to pad.
5101 #############################################################################
5103 sub MakeReturnField {
5106 return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));
5109 #############################################################################
5110 # Function : GetSymbolSourceFile
5111 # Description : Get the filename where the symbol docs where taken from.
5112 # Arguments : $symbol - the symbol name
5113 #############################################################################
5115 sub GetSymbolSourceFile {
5118 if (defined($SourceSymbolSourceFile{$symbol})) {
5119 return $SourceSymbolSourceFile{$symbol};
5120 } elsif (defined($SymbolSourceFile{$symbol})) {
5121 return $SymbolSourceFile{$symbol};
5127 #############################################################################
5128 # Function : GetSymbolSourceLine
5129 # Description : Get the file line where the symbol docs where taken from.
5130 # Arguments : $symbol - the symbol name
5131 #############################################################################
5133 sub GetSymbolSourceLine {
5136 if (defined($SourceSymbolSourceLine{$symbol})) {
5137 return $SourceSymbolSourceLine{$symbol};
5138 } elsif (defined($SymbolSourceLine{$symbol})) {
5139 return $SymbolSourceLine{$symbol};