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 widget 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 widget 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_widget_struct = 0;
1392 my $default_to_public = 1;
1393 if (&CheckIsObject ($symbol)) {
1394 #print "Found widget struct: $symbol\n";
1395 $is_widget_struct = 1;
1396 $default_to_public = 0;
1401 if ($is_widget_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;
1526 <variablelist role="struct">
1529 my $field_name = shift @fields;
1530 my $text = shift @fields;
1531 my $field_descr = $field_descrs{$field_name};
1532 my $param_annotations = "";
1534 $desc .= "<varlistentry><term>$text</term>\n";
1535 if (defined $field_descr) {
1536 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1537 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1538 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1540 $desc .= "<listitem><simpara /></listitem>\n";
1542 $desc .= "</varlistentry>\n";
1545 $desc .= "</variablelist>";
1547 $desc .= OutputSymbolTraits ($symbol);
1548 $desc .= "</refsect2>\n";
1549 return ($synop, $desc);
1553 #############################################################################
1554 # Function : OutputEnum
1555 # Description : Returns the synopsis and detailed description of a enum.
1556 # Arguments : $symbol - the enum.
1557 # $declaration - the declaration of the enum.
1558 #############################################################################
1561 my ($symbol, $declaration) = @_;
1562 my $id = &CreateValidSGMLID ($symbol);
1563 my $condition = &MakeConditionDescription ($symbol);
1564 my $synop = &MakeReturnField("enum") . "<link linkend=\"$id\">$symbol</link>;\n";
1565 my $desc = "<refsect2 id=\"$id\" role=\"enum\"$condition>\n<title>enum $symbol</title>\n";
1567 $desc .= MakeIndexterms($symbol, $id);
1569 $desc .= OutputSymbolExtraLinks($symbol);
1571 my $decl_out = &CreateValidSGML ($declaration);
1572 $desc .= "<programlisting>$decl_out</programlisting>\n";
1574 $desc .= &MakeDeprecationNote($symbol);
1576 if (defined ($SymbolDocs{$symbol})) {
1577 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1580 # Create a table of fields and descriptions
1582 my @members = ParseEnumDeclaration($declaration);
1583 my $params = $SymbolParams{$symbol};
1585 # If no parameters are filled in, we don't generate the description
1586 # table, for backwards compatibility
1589 if (defined $params) {
1590 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1591 if ($params->[$i] =~ /\S/) {
1599 my %member_descrs = @$params;
1602 <variablelist role="enum">
1604 for my $member_name (@members) {
1605 my $member_descr = $member_descrs{$member_name};
1606 my $param_annotations = "";
1608 $id = &CreateValidSGMLID ($member_name);
1609 $condition = &MakeConditionDescription ($member_name);
1610 $desc .= "<varlistentry id=\"$id\" role=\"constant\"$condition>\n<term><literal>$member_name</literal></term>\n";
1611 if (defined $member_descr) {
1612 ($member_descr,$param_annotations) = &ExpandAnnotation($symbol, $member_descr);
1613 $member_descr = &ExpandAbbreviations($symbol, $member_descr);
1614 $desc .= "<listitem><simpara>$member_descr$param_annotations</simpara></listitem>\n";
1616 $desc .= "<listitem></listitem>\n";
1618 $desc .= "</varlistentry>\n";
1621 $desc .= "</variablelist>";
1624 $desc .= OutputSymbolTraits ($symbol);
1625 $desc .= "</refsect2>\n";
1626 return ($synop, $desc);
1630 #############################################################################
1631 # Function : OutputUnion
1632 # Description : Returns the synopsis and detailed description of a union.
1633 # Arguments : $symbol - the union.
1634 # $declaration - the declaration of the union.
1635 #############################################################################
1638 my ($symbol, $declaration) = @_;
1639 my $id = &CreateValidSGMLID ($symbol);
1640 my $condition = &MakeConditionDescription ($symbol);
1642 # Determine if it is a simple struct or it also has a typedef.
1643 my $has_typedef = 0;
1644 if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1651 # For unions with typedefs we just output the union name.
1652 $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1653 $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>$symbol</title>\n";
1655 $synop = &MakeReturnField("union") . "<link linkend=\"$id\">$symbol</link>;\n";
1656 $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>union $symbol</title>\n";
1659 $desc .= MakeIndexterms($symbol, $id);
1661 $desc .= OutputSymbolExtraLinks($symbol);
1663 # FIXME: we do more for structs
1664 my $decl_out = &CreateValidSGML ($declaration);
1665 $desc .= "<programlisting>$decl_out</programlisting>\n";
1667 $desc .= &MakeDeprecationNote($symbol);
1669 if (defined ($SymbolDocs{$symbol})) {
1670 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1673 # Create a table of fields and descriptions
1675 # FIXME: Inserting  's into the produced type declarations here would
1676 # improve the output in most situations ... except for function
1677 # members of structs!
1678 my @fields = ParseStructDeclaration($declaration, 0,
1681 "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1683 my $params = $SymbolParams{$symbol};
1685 # If no parameters are filled in, we don't generate the description
1686 # table, for backwards compatibility
1689 if (defined $params) {
1690 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1691 if ($params->[$i] =~ /\S/) {
1699 my %field_descrs = @$params;
1702 <variablelist role="struct">
1705 my $field_name = shift @fields;
1706 my $text = shift @fields;
1707 my $field_descr = $field_descrs{$field_name};
1708 my $param_annotations = "";
1710 $desc .= "<varlistentry><term>$text</term>\n";
1711 if (defined $field_descr) {
1712 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1713 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1714 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1716 $desc .= "<listitem><simpara /></listitem>\n";
1718 $desc .= "</varlistentry>\n";
1721 $desc .= "</variablelist>";
1723 $desc .= OutputSymbolTraits ($symbol);
1724 $desc .= "</refsect2>\n";
1725 return ($synop, $desc);
1729 #############################################################################
1730 # Function : OutputVariable
1731 # Description : Returns the synopsis and detailed description of a variable.
1732 # Arguments : $symbol - the extern'ed variable.
1733 # $declaration - the declaration of the variable.
1734 #############################################################################
1736 sub OutputVariable {
1737 my ($symbol, $declaration) = @_;
1738 my $id = &CreateValidSGMLID ($symbol);
1739 my $condition = &MakeConditionDescription ($symbol);
1742 if ($declaration =~ m/^\s*extern\s+((const\s+|unsigned\s+)*\w+)(\s+\*+|\*+|\s)(\s*)([A-Za-z]\w*)\s*;/) {
1743 my $mod = defined ($1) ? $1 : "";
1744 my $ptr = defined ($3) ? $3 : "";
1745 my $space = defined ($4) ? $4 : "";
1746 $synop = &MakeReturnField("extern") . "$mod$ptr$space<link linkend=\"$id\">$symbol</link>;\n";
1749 $synop = &MakeReturnField("extern") . "<link linkend=\"$id\">$symbol</link>;\n";
1752 my $desc = "<refsect2 id=\"$id\" role=\"variable\"$condition>\n<title>$symbol</title>\n";
1754 $desc .= MakeIndexterms($symbol, $id);
1756 $desc .= OutputSymbolExtraLinks($symbol);
1758 my $decl_out = &CreateValidSGML ($declaration);
1759 $desc .= "<programlisting>$decl_out</programlisting>\n";
1761 $desc .= &MakeDeprecationNote($symbol);
1763 if (defined ($SymbolDocs{$symbol})) {
1764 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1766 $desc .= OutputSymbolTraits ($symbol);
1767 $desc .= "</refsect2>\n";
1768 return ($synop, $desc);
1772 #############################################################################
1773 # Function : OutputFunction
1774 # Description : Returns the synopsis and detailed description of a function.
1775 # Arguments : $symbol - the function.
1776 # $declaration - the declaration of the function.
1777 #############################################################################
1779 sub OutputFunction {
1780 my ($symbol, $declaration, $symbol_type) = @_;
1781 my $id = &CreateValidSGMLID ($symbol);
1782 my $condition = &MakeConditionDescription ($symbol);
1784 # Take out the return type $1 $3 $4
1785 $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//;
1786 my $type_modifier = defined($1) ? $1 : "";
1789 #print "$symbol pointer is $pointer\n";
1790 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1792 #if ($symbol_type eq 'USER_FUNCTION') {
1793 # $start = "typedef ";
1796 # We output const rather than G_CONST_RETURN.
1797 $type_modifier =~ s/G_CONST_RETURN/const/g;
1798 $pointer =~ s/G_CONST_RETURN/const/g;
1799 $pointer =~ s/^\s+/ /g;
1801 my $ret_type_len = length ($start) + length ($type_modifier)
1802 + length ($pointer) + length ($type);
1803 my $ret_type_output;
1805 if ($ret_type_len < $RETURN_TYPE_FIELD_WIDTH) {
1806 $ret_type_output = "$start$type_modifier$xref$pointer"
1807 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
1810 # $ret_type_output = "$start$type_modifier$xref$pointer\n"
1811 # . (' ' x $RETURN_TYPE_FIELD_WIDTH);
1813 $ret_type_output = "$start$type_modifier$xref$pointer ";
1814 $symbol_len = $ret_type_len + 1 - $RETURN_TYPE_FIELD_WIDTH;
1817 $symbol_len += length ($symbol);
1818 my $char1 = my $char2 = my $char3 = "";
1819 if ($symbol_type eq 'USER_FUNCTION') {
1826 my ($symbol_output, $symbol_desc_output);
1827 if ($symbol_len < $SYMBOL_FIELD_WIDTH) {
1828 $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3"
1829 . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1830 $symbol_desc_output = "$char1$char2$symbol$char3"
1831 . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1833 $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3\n"
1834 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1835 $symbol_desc_output = "$char1$char2$symbol$char3\n"
1836 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1839 my $synop = $ret_type_output . $symbol_output . '(';
1840 my $desc = "<refsect2 id=\"$id\" role=\"function\"$condition>\n<title>${symbol} ()</title>\n";
1842 $desc .= MakeIndexterms($symbol, $id);
1844 $desc .= OutputSymbolExtraLinks($symbol);
1846 $desc .= "<programlisting>${ret_type_output}$symbol_desc_output(";
1849 while ($declaration ne "") {
1850 #print "$declaration";
1852 if ($declaration =~ s/^[\s,]+//) {
1853 # skip whitespace and commas
1856 } elsif ($declaration =~ s/^void\s*[,\n]//) {
1860 } elsif ($declaration =~ s/^...\s*[,\n]//) {
1861 if ($param_num == 0) {
1866 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1869 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1873 # allow alphanumerics, '_', '[' & ']' in param names
1874 # Try to match a standard parameter (keep in sync with gtkdoc-mktmpl)
1876 } 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]//) {
1877 my $pre = defined($1) ? $1 : "";
1879 my $ptr = defined($3) ? $3 : "";
1880 my $name = defined($4) ? $4 : "";
1881 my $array = defined($5) ? $5 : "";
1887 if ($ptr && $ptr !~ m/\*$/) { $ptr .= " "; }
1889 #print "$symbol: '$pre' '$type' '$ptr' '$name' '$array'\n";
1891 if (($name eq "") && $pre =~ m/^((un)?signed .*)\s?/ ) {
1897 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1898 my $label = "$pre$xref $ptr$name$array";
1900 #print "$symbol: '$pre' '$type' '$ptr' '$name' '$array'\n";
1902 if ($param_num == 0) {
1907 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1910 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1914 # Try to match parameters which are functions (keep in sync with gtkdoc-mktmpl)
1915 # $1 $2 $3 $4 $5 $7 $8
1916 } 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]//) {
1917 my $mod1 = defined($1) ? $1 : "";
1918 if (defined($2)) { $mod1 .= $2; }
1921 my $mod2 = defined($5) ? $5 : "";
1924 my $func_params = defined($8) ? $8 : "";
1926 #if (!defined($type)) { print "## no type\n"; };
1927 #if (!defined($ptr1)) { print "## no ptr1\n"; };
1928 #if (!defined($func_ptr)) { print "## no func_ptr\n"; };
1929 #if (!defined($name)) { print "## no name\n"; };
1931 if ($ptr1 && $ptr1 !~ m/\*$/) { $ptr1 .= " "; }
1932 $func_ptr =~ s/\s+//g;
1933 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1934 my $label = "$mod1$xref$ptr1$mod2 ($func_ptr$name) ($func_params)";
1936 #print "Type: [$mod1][$xref][$ptr1][$mod2] ([$func_ptr][$name]) ($func_params)\n";
1937 if ($param_num == 0) {
1942 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1945 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1950 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1951 "Can't parse args for function $symbol: $declaration");
1957 $desc .= ");</programlisting>\n";
1959 $desc .= &MakeDeprecationNote($symbol);
1961 my $parameters = &OutputParamDescriptions ("FUNCTION", $symbol);
1962 my $parameters_output = 0;
1964 if (defined ($SymbolDocs{$symbol})) {
1965 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1967 # Try to insert the parameter table at the author's desired position.
1968 # Otherwise we need to tag it onto the end.
1969 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1970 $parameters_output = 1;
1972 $desc .= $symbol_docs;
1975 if ($parameters_output == 0) {
1976 $desc .= $parameters;
1979 $desc .= OutputSymbolTraits ($symbol);
1980 $desc .= "</refsect2>\n";
1981 return ($synop, $desc);
1985 #############################################################################
1986 # Function : OutputParamDescriptions
1987 # Description : Returns the DocBook output describing the parameters of a
1988 # function, macro or signal handler.
1989 # Arguments : $symbol_type - 'FUNCTION', 'MACRO' or 'SIGNAL'. Signal
1990 # handlers have an implicit user_data parameter last.
1991 # $symbol - the name of the function/macro being described.
1992 #############################################################################
1994 sub OutputParamDescriptions {
1995 my ($symbol_type, $symbol) = @_;
1997 if (defined ($SymbolParams{$symbol})) {
1999 my $params = $SymbolParams{$symbol};
2000 my $params_desc = "";
2002 for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
2003 my $param_name = $$params[$j];
2004 my $param_desc = $$params[$j + 1];
2005 my $param_annotations = "";
2007 ($param_desc,$param_annotations) = & ExpandAnnotation($symbol, $param_desc);
2008 $param_desc = &ExpandAbbreviations($symbol, $param_desc);
2009 if ($param_name eq "Returns") {
2010 $returns = "$param_desc$param_annotations";
2012 if ($param_name eq "Varargs") {
2013 $param_name = "...";
2015 $params_desc .= "<varlistentry><term><parameter>$param_name</parameter> :</term>\n<listitem><simpara>$param_desc$param_annotations</simpara></listitem></varlistentry>\n";
2019 # Signals have an implicit user_data parameter which we describe.
2020 if ($symbol_type eq "SIGNAL") {
2021 $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";
2024 # Start a table if we need one.
2025 if ($params_desc || $returns) {
2026 $output .= "<variablelist role=\"params\">\n";
2027 if ($params_desc ne "") {
2028 #$output .= "<varlistentry><term>Parameters:</term><listitem></listitem></varlistentry>\n";
2029 $output .= $params_desc;
2032 # Output the returns info last.
2034 $output .= "<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>$returns</simpara></listitem></varlistentry>\n";
2038 $output .= "</variablelist>";
2045 #############################################################################
2046 # Function : ParseStabilityLevel
2047 # Description : Parses a stability level and outputs a warning if it isn't
2049 # Arguments : $stability - the stability text.
2050 # $file, $line - context for error message
2051 # $message - description of where the level is from, to use in
2052 # any error message.
2053 # Returns : The parsed stability level string.
2054 #############################################################################
2056 sub ParseStabilityLevel {
2057 my ($stability, $file, $line, $message) = @_;
2059 $stability =~ s/^\s*//;
2060 $stability =~ s/\s*$//;
2061 if ($stability =~ m/^stable$/i) {
2062 $stability = "Stable";
2063 } elsif ($stability =~ m/^unstable$/i) {
2064 $stability = "Unstable";
2065 } elsif ($stability =~ m/^private$/i) {
2066 $stability = "Private";
2068 &LogWarning ($file, $line, "$message is $stability.".
2069 "It should be one of these: Stable, Unstable, or Private.");
2075 #############################################################################
2076 # Function : OutputSGMLFile
2077 # Description : Outputs the final DocBook file for one section.
2078 # Arguments : $file - the name of the file.
2079 # $title - the title from the $MODULE-sections.txt file, which
2080 # will be overridden by the title in the template file.
2081 # $section_id - the SGML id to use for the toplevel tag.
2082 # $includes - comma-separates list of include files added at top
2083 # of synopsis, with '<' '>' around them (if not already enclosed in "").
2084 # $synopsis - reference to the DocBook for the Synopsis part.
2085 # $details - reference to the DocBook for the Details part.
2086 # $signal_synop - reference to the DocBook for the Signal Synopsis part
2087 # $signal_desc - reference to the DocBook for the Signal Description part
2088 # $args_synop - reference to the DocBook for the Arg Synopsis part
2089 # $args_desc - reference to the DocBook for the Arg Description part
2090 # $hierarchy - reference to the DocBook for the Object Hierarchy part
2091 # $interfaces - reference to the DocBook for the Interfaces part
2092 # $implementations - reference to the DocBook for the Known Implementations part
2093 # $prerequisites - reference to the DocBook for the Prerequisites part
2094 # $derived - reference to the DocBook for the Derived Interfaces part
2095 # $file_objects - reference to an array of objects in this file
2096 #############################################################################
2098 sub OutputSGMLFile {
2099 my ($file, $title, $section_id, $includes, $synopsis, $details, $signals_synop, $signals_desc, $args_synop, $args_desc, $hierarchy, $interfaces, $implementations, $prerequisites, $derived, $file_objects) = @_;
2101 #print "Output sgml for file $file with title '$title'\n";
2103 # The edited title overrides the one from the sections file.
2104 my $new_title = $SymbolDocs{"$TMPL_DIR/$file:Title"};
2105 if (defined ($new_title) && $new_title !~ m/^\s*$/) {
2106 $title = $new_title;
2107 #print "Found title: $title\n";
2109 my $short_desc = $SymbolDocs{"$TMPL_DIR/$file:Short_Description"};
2110 if (!defined ($short_desc) || $short_desc =~ m/^\s*$/) {
2113 $short_desc = &ExpandAbbreviations("$title:Short_description",
2115 #print "Found short_desc: $short_desc";
2117 my $long_desc = $SymbolDocs{"$TMPL_DIR/$file:Long_Description"};
2118 if (!defined ($long_desc) || $long_desc =~ m/^\s*$/) {
2121 $long_desc = &ExpandAbbreviations("$title:Long_description",
2123 #print "Found long_desc: $long_desc";
2125 my $see_also = $SymbolDocs{"$TMPL_DIR/$file:See_Also"};
2126 if (!defined ($see_also) || $see_also =~ m%^\s*(<para>)?\s*(</para>)?\s*$%) {
2129 $see_also = &ExpandAbbreviations("$title:See_Also", $see_also);
2130 #print "Found see_also: $see_also";
2133 $see_also = "<refsect1 id=\"$section_id.see-also\">\n<title>See Also</title>\n$see_also\n</refsect1>\n";
2135 my $stability = $SymbolDocs{"$TMPL_DIR/$file:Stability_Level"};
2136 if (!defined ($stability) || $stability =~ m/^\s*$/) {
2139 $stability = &ParseStabilityLevel($stability, $file, $., "Section stability level");
2140 #print "Found stability: $stability";
2143 $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$stability, unless otherwise indicated\n</refsect1>\n";
2144 } elsif ($DEFAULT_STABILITY) {
2145 $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$DEFAULT_STABILITY, unless otherwise indicated\n</refsect1>\n";
2148 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
2150 my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
2153 my $include_output = "";
2155 foreach $include (split (/,/, $includes)) {
2156 if ($include =~ m/^\".+\"$/) {
2157 $include_output .= "#include ${include}\n";
2160 $include =~ s/^\s+|\s+$//gs;
2161 $include_output .= "#include <${include}>\n";
2164 if ($include_output ne '') {
2165 $include_output = "\n$include_output\n";
2168 my $extralinks = OutputSectionExtraLinks($title,"Section:$file");
2170 my $old_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT";
2171 my $new_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT.new";
2173 open (OUTPUT, ">$new_sgml_file")
2174 || die "Can't create $new_sgml_file: $!";
2176 my $object_anchors = "";
2177 foreach my $object (@$file_objects) {
2178 next if ($object eq $section_id);
2179 my $id = CreateValidSGMLID($object);
2180 #print "Debug: Adding anchor for $object\n";
2181 $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
2184 # We used to output this, but is messes up our UpdateFileIfChanged code
2185 # since it changes every day (and it is only used in the man pages):
2186 # "<refentry id="$section_id" revision="$mday $month $year">"
2188 if (lc($OUTPUT_FORMAT) eq "xml") {
2189 print OUTPUT $doctype_header;
2193 <refentry id="$section_id">
2195 <refentrytitle role="top_of_page" id="$section_id.top_of_page">$title</refentrytitle>
2196 <manvolnum>3</manvolnum>
2197 <refmiscinfo>\U$MODULE\E Library</refmiscinfo>
2200 <refname>$title</refname>
2201 <refpurpose>$short_desc</refpurpose>
2204 <refsynopsisdiv id="$section_id.synopsis" role="synopsis">
2205 <title role="synopsis.title">Synopsis</title>
2207 <synopsis>$include_output$${synopsis}</synopsis>
2209 $$hierarchy$$prerequisites$$derived$$interfaces$$implementations$$args_synop$$signals_synop
2210 <refsect1 id="$section_id.description" role="desc">
2211 <title role="desc.title">Description</title>
2212 $extralinks$long_desc
2214 <refsect1 id="$section_id.details" role="details">
2215 <title role="details.title">Details</title>
2218 $$args_desc$$signals_desc$see_also
2223 return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2227 #############################################################################
2228 # Function : OutputExtraFile
2229 # Description : Copies an "extra" DocBook file into the output directory,
2230 # expanding abbreviations
2231 # Arguments : $file - the source file.
2232 #############################################################################
2233 sub OutputExtraFile {
2238 ($basename = $file) =~ s!^.*/!!;
2240 my $old_sgml_file = "$SGML_OUTPUT_DIR/$basename";
2241 my $new_sgml_file = "$SGML_OUTPUT_DIR/$basename.new";
2245 open(EXTRA_FILE, "<$file") || die "Can't open $file";
2249 $contents = <EXTRA_FILE>;
2252 open (OUTPUT, ">$new_sgml_file")
2253 || die "Can't create $new_sgml_file: $!";
2255 print OUTPUT &ExpandAbbreviations ("$basename file", $contents);
2258 return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2260 #############################################################################
2261 # Function : OutputBook
2262 # Description : Outputs the SGML entities that need to be included into the
2263 # main SGML file for the module.
2264 # Arguments : $book_top - the declarations of the entities, which are added
2265 # at the top of the main SGML file.
2266 # $book_bottom - the references to the entities, which are
2267 # added in the main SGML file at the desired position.
2268 #############################################################################
2271 my ($book_top, $book_bottom) = @_;
2273 my $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top";
2274 my $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top.new";
2276 open (OUTPUT, ">$new_file")
2277 || die "Can't create $new_file: $!";
2278 print OUTPUT $book_top;
2281 &UpdateFileIfChanged ($old_file, $new_file, 0);
2284 $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom";
2285 $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom.new";
2287 open (OUTPUT, ">$new_file")
2288 || die "Can't create $new_file: $!";
2289 print OUTPUT $book_bottom;
2292 &UpdateFileIfChanged ($old_file, $new_file, 0);
2295 # If the main SGML file hasn't been created yet, we create it here.
2296 # The user can tweak it later.
2297 if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
2298 open (OUTPUT, ">$MAIN_SGML_FILE")
2299 || die "Can't create $MAIN_SGML_FILE: $!";
2301 if (lc($OUTPUT_FORMAT) eq "xml") {
2303 <?xml version="1.0"?>
2304 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
2305 "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
2307 <!ENTITY % local.common.attrib "xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'">
2313 <!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
2322 <title>$MODULE Reference Manual</title>
2324 for $MODULE [VERSION].
2325 The latest version of this documentation can be found on-line at
2326 <ulink role="online-location" url="http://[SERVER]/$MODULE/index.html">http://[SERVER]/$MODULE/</ulink>.
2331 <title>[Insert title here]</title>
2335 if (-e $OBJECT_TREE_FILE) {
2337 <chapter id="object-tree">
2338 <title>Object Hierarchy</title>
2339 <xi:include href="xml/tree_index.sgml"/>
2345 <index id="api-index-full">
2346 <title>API Index</title>
2347 <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
2350 <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
2359 #############################################################################
2360 # Function : CreateValidSGML
2361 # Description : This turns any chars which are used in SGML into entities,
2362 # e.g. '<' into '<'
2363 # Arguments : $text - the text to turn into proper SGML.
2364 #############################################################################
2366 sub CreateValidSGML {
2368 $text =~ s/&/&/g; # Do this first, or the others get messed up.
2369 $text =~ s/</</g;
2370 $text =~ s/>/>/g;
2371 # browers render single tabs inconsistently
2372 $text =~ s/([^\s])\t([^\s])/$1 $2/g;
2376 #############################################################################
2377 # Function : ConvertSGMLChars
2378 # Description : This is used for text in source code comment blocks, to turn
2379 # chars which are used in SGML into entities, e.g. '<' into
2380 # '<'. Depending on $SGML_MODE, this is done
2381 # unconditionally or only if the character doesn't seem to be
2382 # part of an SGML construct (tag or entity reference).
2383 # Arguments : $text - the text to turn into proper SGML.
2384 #############################################################################
2386 sub ConvertSGMLChars {
2387 my ($symbol, $text) = @_;
2390 # For the SGML mode only convert to entities outside CDATA sections.
2391 return &ModifyXMLElements ($text, $symbol,
2392 "<!\\[CDATA\\[|<programlisting[^>]*>",
2393 \&ConvertSGMLCharsEndTag,
2394 \&ConvertSGMLCharsCallback);
2396 # For the simple non-sgml mode, convert to entities everywhere.
2397 $text =~ s/&/&/g; # Do this first, or the others get messed up.
2398 $text =~ s/</</g;
2399 $text =~ s/>/>/g;
2405 sub ConvertSGMLCharsEndTag {
2406 if ($_[0] eq "<!\[CDATA\[") {
2409 return "</programlisting>";
2413 sub ConvertSGMLCharsCallback {
2414 my ($text, $symbol, $tag) = @_;
2416 if ($tag =~ m/^<programlisting/) {
2417 # We can handle <programlisting> specially here.
2418 return &ModifyXMLElements ($text, $symbol,
2420 \&ConvertSGMLCharsEndTag,
2421 \&ConvertSGMLCharsCallback2);
2422 } elsif ($tag eq "") {
2423 # If we're not in CDATA convert to entities.
2424 $text =~ s/&(?![a-zA-Z#]+;)/&/g; # Do this first, or the others get messed up.
2425 $text =~ s/<(?![a-zA-Z\/!])/</g;
2426 $text =~ s/(?<![a-zA-Z0-9"'\/-])>/>/g;
2428 # Handle "#include <xxxxx>"
2429 $text =~ s/#include(\s+)<([^>]+)>/#include$1<$2>/g;
2435 sub ConvertSGMLCharsCallback2 {
2436 my ($text, $symbol, $tag) = @_;
2438 # If we're not in CDATA convert to entities.
2439 # We could handle <programlisting> differently, though I'm not sure it helps.
2441 # replace only if its not a tag
2442 $text =~ s/&(?![a-zA-Z#]+;)/&/g; # Do this first, or the others get messed up.
2443 $text =~ s/<(?![a-zA-Z\/!])/</g;
2444 $text =~ s/(?<![a-zA-Z0-9"'\/-])>/>/g;
2446 # Handle "#include <xxxxx>"
2447 $text =~ s/#include(\s+)<([^>]+)>/#include$1<$2>/g;
2453 #############################################################################
2454 # Function : ExpandAnnotation
2455 # Description : This turns annotations into acrony tags.
2456 # Arguments : $symbol - the symbol being documented, for error messages.
2457 # $text - the text to expand.
2458 #############################################################################
2459 sub ExpandAnnotation {
2460 my ($symbol, $param_desc) = @_;
2461 my $param_annotations = "";
2463 if ($param_desc =~ m%\s*\((.*)\):%) {
2466 my $annotation_extra = "";
2469 @annotations = split(/\)\s*\(/,$1);
2470 foreach $annotation (@annotations) {
2471 # need to search for the longest key-match in %AnnotationDefinition
2473 my $match_annotation="";
2475 foreach $annotationdef (keys %AnnotationDefinition) {
2476 if ($annotation =~ m/^$annotationdef/) {
2477 if (length($annotationdef)>$match_length) {
2478 $match_length=length($annotationdef);
2479 $match_annotation=$annotationdef;
2483 if ($match_annotation ne "") {
2484 if ($annotation =~ m%$match_annotation\s+(.*)%) {
2485 $annotation_extra = " $1";
2487 $AnnotationsUsed{$match_annotation} = 1;
2488 $param_annotations .= "<acronym>$match_annotation</acronym>$annotation_extra. ";
2491 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2492 "unknown annotation \"$annotation\" in documentation for $symbol.");
2493 $param_annotations=$annotation;
2497 $param_desc =~ m/^(.*)\.*\s*$/;
2498 $param_desc = "$1. ";
2500 return ($param_desc, $param_annotations);
2503 #############################################################################
2504 # Function : ExpandAbbreviations
2505 # Description : This turns the abbreviations function(), macro(), @param,
2506 # %constant, and #symbol into appropriate DocBook markup.
2507 # CDATA sections and <programlisting> parts are skipped.
2508 # Arguments : $symbol - the symbol being documented, for error messages.
2509 # $text - the text to expand.
2510 #############################################################################
2512 sub ExpandAbbreviations {
2513 my ($symbol, $text) = @_;
2515 # Convert "|[" and "]|" into the start and end of program listing examples.
2516 $text =~ s%\|\[%<informalexample><programlisting>%g;
2517 $text =~ s%\]\|%</programlisting></informalexample>%g;
2518 # TODO: check for a xml comment after |[ and pick the language attribute from
2521 # TODO: optionally check all words from $text against internal symbols and
2522 # warn if those could be xreffed, but miss a %,# or ()
2524 # keep CDATA unmodified, preserve ulink tags (ideally we preseve all tags
2526 return &ModifyXMLElements ($text, $symbol,
2527 "<!\\[CDATA\\[|<ulink[^>]*>|<programlisting[^>]*>|<!DOCTYPE",
2528 \&ExpandAbbreviationsEndTag,
2529 \&ExpandAbbreviationsCallback);
2533 # Returns the end tag corresponding to the given start tag.
2534 sub ExpandAbbreviationsEndTag {
2535 my ($start_tag) = @_;
2537 if ($start_tag eq "<!\[CDATA\[") {
2539 } elsif ($start_tag eq "<!DOCTYPE") {
2541 } elsif ($start_tag =~ m/<(\w+)/) {
2546 # Called inside or outside each CDATA or <programlisting> section.
2547 sub ExpandAbbreviationsCallback {
2548 my ($text, $symbol, $tag) = @_;
2550 if ($tag =~ m/^<programlisting/) {
2551 # Handle any embedded CDATA sections.
2552 return &ModifyXMLElements ($text, $symbol,
2554 \&ExpandAbbreviationsEndTag,
2555 \&ExpandAbbreviationsCallback2);
2556 } elsif ($tag eq "") {
2557 # We are outside any CDATA or <programlisting> sections, so we expand
2558 # any gtk-doc abbreviations.
2560 # Convert 'function()' or 'macro()'.
2561 # if there is abc_*_def() we don't want to make a link to _def()
2562 # FIXME: also handle abc(....) : but that would need to be done recursively :/
2563 $text =~ s/([^\*.\w])(\w+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2564 # handle #Object.func()
2565 $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2567 # Convert '@param', but not '\@param'.
2568 $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)/$1<parameter>$2<\/parameter>/g;
2569 $text =~ s/\\\@/\@/g;
2571 # Convert '%constant', but not '\%constant'.
2572 # Also allow negative numbers, e.g. %-1.
2573 $text =~ s/(\A|[^\\])\%(-?\w+)/$1.&MakeXRef($2, &tagify($2, "literal"));/eg;
2574 $text =~ s/\\\%/\%/g;
2576 # Convert '#symbol', but not '\#symbol'.
2577 $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)/$1.&MakeHashXRef($2, "type");/eg;
2581 # FIXME: should we skip urls that are already tagged? (e.g. <literal>http://...</literal>)
2582 # this is apparently also called for markup and not just for plain text
2584 #$text =~ s%(http|https|ftp)://(.*?)((?:\s|,|\)|\]|\<|\.\s))%<ulink url="$1://$2">$2</ulink>$3%g;
2590 # This is called inside a <programlisting>
2591 sub ExpandAbbreviationsCallback2 {
2592 my ($text, $symbol, $tag) = @_;
2595 # We are inside a <programlisting> but outside any CDATA sections,
2596 # so we expand any gtk-doc abbreviations.
2597 # FIXME: why is this different from &ExpandAbbreviationsCallback(),
2598 # why not just call it
2599 $text =~ s/#(\w+)/&MakeHashXRef($1, "");/eg;
2606 my ($symbol, $tag) = @_;;
2609 # Check for things like '#include', '#define', and skip them.
2610 if ($PreProcessorDirectives{$symbol}) {
2614 # Get rid of any special '-struct' suffix.
2615 $text =~ s/-struct$//;
2617 # If the symbol is in the form "Object::signal", then change the symbol to
2618 # "Object-signal" and use "signal" as the text.
2619 if ($symbol =~ s/::/-/) {
2623 # If the symbol is in the form "Object:property", then change the symbol to
2624 # "Object--property" and use "property" as the text.
2625 if ($symbol =~ s/:/--/) {
2630 $text = tagify ($text, $tag);
2633 return &MakeXRef($symbol, $text);
2637 #############################################################################
2638 # Function : ModifyXMLElements
2639 # Description : Looks for given XML element tags within the text, and calls
2640 # the callback on pieces of text inside & outside those elements.
2641 # Used for special handling of text inside things like CDATA
2642 # and <programlisting>.
2643 # Arguments : $text - the text.
2644 # $symbol - the symbol currently being documented (only used for
2646 # $start_tag_regexp - the regular expression to match start tags.
2647 # e.g. "<!\\[CDATA\\[|<programlisting[^>]*>" to match
2648 # CDATA sections or programlisting elements.
2649 # $end_tag_func - function which is passed the matched start tag
2650 # and should return the appropriate end tag string.
2651 # $callback - callback called with each part of the text. It is
2652 # called with a piece of text, the symbol being
2653 # documented, and the matched start tag or "" if the text
2654 # is outside the XML elements being matched.
2655 #############################################################################
2656 sub ModifyXMLElements {
2657 my ($text, $symbol, $start_tag_regexp, $end_tag_func, $callback) = @_;
2658 my ($before_tag, $start_tag, $end_tag_regexp, $end_tag);
2661 while ($text =~ m/$start_tag_regexp/s) {
2662 $before_tag = $`; # Prematch for last successful match string
2663 $start_tag = $&; # Last successful match
2664 $text = $'; # Postmatch for last successful match string
2666 $result .= &$callback ($before_tag, $symbol, "");
2667 $result .= $start_tag;
2669 # get the mathing end-tag for current tag
2670 $end_tag_regexp = &$end_tag_func ($start_tag);
2672 if ($text =~ m/$end_tag_regexp/s) {
2677 $result .= &$callback ($before_tag, $symbol, $start_tag);
2678 $result .= $end_tag;
2680 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2681 "Can't find tag end: $end_tag_regexp in docs for: $symbol.");
2682 # Just assume it is all inside the tag.
2683 $result .= &$callback ($text, $symbol, $start_tag);
2688 # Handle any remaining text outside the tags.
2689 $result .= &$callback ($text, $symbol, "");
2698 # Adds a tag around some text.
2699 # e.g tagify("Text", "literal") => "<literal>Text</literal>".
2701 my ($text, $elem) = @_;
2702 return "<" . $elem . ">" . $text . "</" . $elem . ">";
2706 #############################################################################
2707 # Function : MakeXRef
2708 # Description : This returns a cross-reference link to the given symbol.
2709 # Though it doesn't try to do this for a few standard C types
2710 # that it knows won't be in the documentation.
2711 # Arguments : $symbol - the symbol to try to create a XRef to.
2712 # $text - text text to put inside the XRef, defaults to $symbol
2713 #############################################################################
2716 my ($symbol, $text) = ($_[0], $_[1]);
2718 $symbol =~ s/^\s+//;
2719 $symbol =~ s/\s+$//;
2721 if (!defined($text)) {
2724 # Get rid of special '-struct' suffix.
2725 $text =~ s/-struct$//;
2728 if ($symbol =~ m/ /) {
2732 #print "Getting type link for $symbol -> $text\n";
2734 my $symbol_id = &CreateValidSGMLID ($symbol);
2735 return "<link linkend=\"$symbol_id\">$text</link>";
2739 #############################################################################
2740 # Function : MakeIndexterms
2741 # Description : This returns a indexterm elements for the given symbol
2742 # Arguments : $symbol - the symbol to create indexterms for
2743 #############################################################################
2745 sub MakeIndexterms {
2746 my ($symbol, $id) = @_;
2750 # make the index useful, by ommiting the namespace when sorting
2751 if ($NAME_SPACE ne "") {
2752 if ($symbol =~ m/^$NAME_SPACE\_?(.*)/i) {
2753 $sortas=" sortas=\"$1\"";
2757 if (exists $Deprecated{$symbol}) {
2758 $terms .= "<indexterm zone=\"$id\" role=\"deprecated\"><primary$sortas>$symbol</primary></indexterm>";
2759 $IndexEntriesDeprecated{$symbol}=$id;
2760 $IndexEntriesFull{$symbol}=$id;
2762 if (exists $Since{$symbol}) {
2763 my $since = $Since{$symbol};
2767 $terms .= "<indexterm zone=\"$id\" role=\"$since\"><primary$sortas>$symbol</primary></indexterm>";
2769 $IndexEntriesSince{$symbol}=$id;
2770 $IndexEntriesFull{$symbol}=$id;
2773 $terms .= "<indexterm zone=\"$id\"><primary$sortas>$symbol</primary></indexterm>";
2774 $IndexEntriesFull{$symbol}=$id;
2780 #############################################################################
2781 # Function : MakeDeprecationNote
2782 # Description : This returns a deprecation warning for the given symbol.
2783 # Arguments : $symbol - the symbol to try to create a warning for.
2784 #############################################################################
2786 sub MakeDeprecationNote {
2787 my ($symbol) = $_[0];
2790 if (exists $Deprecated{$symbol}) {
2791 $desc .= "<warning>";
2793 if ($Deprecated{$symbol} =~ /^\s*([0-9\.]+)\s*:/) {
2794 $desc .= "<para><literal>$symbol</literal> has been deprecated since version $1 and should not be used in newly-written code.";
2796 $desc .= "<para><literal>$symbol</literal> is deprecated and should not be used in newly-written code.";
2798 if ($Deprecated{$symbol} ne "") {
2799 $note = &ExpandAbbreviations($symbol, $Deprecated{$symbol});
2800 $note =~ s/^\s*([0-9\.]+)\s*:\s*//;
2803 $note =~ s%\n{2,}%\n</para>\n<para>\n%g;
2804 $desc .= " " . $note;
2806 $desc .= "</para></warning>\n";
2811 #############################################################################
2812 # Function : MakeConditionDescription
2813 # Description : This returns a sumary of conditions for the given symbol.
2814 # Arguments : $symbol - the symbol to try to create the sumary.
2815 #############################################################################
2817 sub MakeConditionDescription {
2818 my ($symbol) = $_[0];
2821 if (exists $Deprecated{$symbol}) {
2826 if ($Deprecated{$symbol} =~ /^\s*(.*?)\s*$/) {
2827 $desc .= "deprecated:$1";
2829 $desc .= "deprecated";
2833 if (exists $Since{$symbol}) {
2838 if ($Since{$symbol} =~ /^\s*(.*?)\s*$/) {
2839 $desc .= "since:$1";
2845 if (exists $StabilityLevel{$symbol}) {
2849 $desc .= "stability:".$StabilityLevel{$symbol};
2853 $desc=" condition=\"".$desc."\"";
2854 #print "condition for '$symbol' = '$desc'\n";
2859 #############################################################################
2860 # Function : GetHierarchy
2861 # Description : Returns the DocBook output describing the ancestors and
2862 # immediate children of a GObject subclass. It uses the
2863 # global @Objects and @ObjectLevels arrays to walk the tree.
2864 # Arguments : $object - the GtkObject subclass.
2865 #############################################################################
2870 # Find object in the objects array.
2876 for ($i = 0; $i < @Objects; $i++) {
2878 if ($ObjectLevels[$i] <= $level) {
2881 elsif ($ObjectLevels[$i] == $level + 1) {
2882 push (@children, $Objects[$i]);
2885 elsif ($Objects[$i] eq $object) {
2888 $level = $ObjectLevels[$i];
2895 # Walk up the hierarchy, pushing ancestors onto the ancestors array.
2897 push (@ancestors, $object);
2898 #print "Level: $level\n";
2899 while ($level > 1) {
2901 if ($ObjectLevels[$j] < $level) {
2902 push (@ancestors, $Objects[$j]);
2903 $level = $ObjectLevels[$j];
2904 #print "Level: $level\n";
2908 # Output the ancestors list, indented and with links.
2909 my $hierarchy = "<synopsis>\n";
2911 for ($i = $#ancestors; $i >= 0; $i--) {
2913 # Don't add a link to the current widget, i.e. when i == 0.
2915 my $ancestor_id = &CreateValidSGMLID ($ancestors[$i]);
2916 $link_text = "<link linkend=\"$ancestor_id\">$ancestors[$i]</link>";
2918 $link_text = "$ancestors[$i]";
2921 $hierarchy .= " $link_text\n";
2923 # $hierarchy .= ' ' x ($level * 6 - 3) . "|\n";
2924 $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
2928 for ($i = 0; $i <= $#children; $i++) {
2929 my $id = &CreateValidSGMLID ($children[$i]);
2930 my $link_text = "<link linkend=\"$id\">$children[$i]</link>";
2931 $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
2933 $hierarchy .= "</synopsis>\n";
2939 #############################################################################
2940 # Function : GetInterfaces
2941 # Description : Returns the DocBook output describing the interfaces
2942 # implemented by a class. It uses the global %Interfaces hash.
2943 # Arguments : $object - the GtkObject subclass.
2944 #############################################################################
2951 # Find object in the objects array.
2952 if (exists($Interfaces{$object})) {
2953 my @ifaces = split(' ', $Interfaces{$object});
2958 for ($i = 0; $i <= $#ifaces; $i++) {
2959 my $id = &CreateValidSGMLID ($ifaces[$i]);
2960 $text .= " <link linkend=\"$id\">$ifaces[$i]</link>";
2961 if ($i < $#ifaces - 1) {
2964 elsif ($i < $#ifaces) {
2979 #############################################################################
2980 # Function : GetImplementations
2981 # Description : Returns the DocBook output describing the implementations
2982 # of an interface. It uses the global %Interfaces hash.
2983 # Arguments : $object - the GtkObject subclass.
2984 #############################################################################
2986 sub GetImplementations {
2991 foreach my $key (keys %Interfaces) {
2992 if ($Interfaces{$key} =~ /\b$object\b/) {
2993 push (@impls, $key);
2999 $object is implemented by
3001 for ($i = 0; $i <= $#impls; $i++) {
3002 my $id = &CreateValidSGMLID ($impls[$i]);
3003 $text .= " <link linkend=\"$id\">$impls[$i]</link>";
3004 if ($i < $#impls - 1) {
3007 elsif ($i < $#impls) {
3022 #############################################################################
3023 # Function : GetPrerequisites
3024 # Description : Returns the DocBook output describing the prerequisites
3025 # of an interface. It uses the global %Prerequisites hash.
3026 # Arguments : $iface - the interface.
3027 #############################################################################
3029 sub GetPrerequisites {
3034 if (exists($Prerequisites{$iface})) {
3039 my @prereqs = split(' ', $Prerequisites{$iface});
3040 for ($i = 0; $i <= $#prereqs; $i++) {
3041 my $id = &CreateValidSGMLID ($prereqs[$i]);
3042 $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
3043 if ($i < $#prereqs - 1) {
3046 elsif ($i < $#prereqs) {
3060 #############################################################################
3061 # Function : GetDerived
3062 # Description : Returns the DocBook output describing the derived interfaces
3063 # of an interface. It uses the global %Prerequisites hash.
3064 # Arguments : $iface - the interface.
3065 #############################################################################
3073 foreach my $key (keys %Prerequisites) {
3074 if ($Prerequisites{$key} =~ /\b$iface\b/) {
3075 push (@derived, $key);
3078 if ($#derived >= 0) {
3081 $iface is required by
3083 for ($i = 0; $i <= $#derived; $i++) {
3084 my $id = &CreateValidSGMLID ($derived[$i]);
3085 $text .= " <link linkend=\"$id\">$derived[$i]</link>";
3086 if ($i < $#derived - 1) {
3089 elsif ($i < $#derived) {
3104 #############################################################################
3105 # Function : GetSignals
3106 # Description : Returns the synopsis and detailed description DocBook output
3107 # for the signal handlers of a given GtkObject subclass.
3108 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
3109 #############################################################################
3117 for ($i = 0; $i <= $#SignalObjects; $i++) {
3118 if ($SignalObjects[$i] eq $object) {
3119 #print "Found signal: $SignalNames[$i]\n";
3120 my $name = $SignalNames[$i];
3121 my $symbol = "${object}::${name}";
3122 my $id = &CreateValidSGMLID ("$object-$name");
3124 my $pad = ' ' x (46 - length($name));
3125 $synop .= " "<link linkend=\"$id\">$name</link>"$pad ";
3127 $desc .= "<refsect2 id=\"$id\" role=\"signal\"><title>The <literal>"$name"</literal> signal</title>\n";
3128 $desc .= MakeIndexterms($symbol, $id);
3130 $desc .= OutputSymbolExtraLinks($symbol);
3132 $desc .= "<programlisting>";
3134 $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
3135 my $type_modifier = defined($1) ? $1 : "";
3138 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
3140 my $ret_type_len = length ($type_modifier) + length ($pointer)
3142 my $ret_type_output = "$type_modifier$xref$pointer"
3143 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
3145 $desc .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
3147 my $sourceparams = $SourceSymbolParams{$symbol};
3148 my @params = split ("\n", $SignalPrototypes[$i]);
3151 my $type_len = length("gpointer");
3152 my $name_len = length("user_data");
3153 # do two passes, the first one is to calculate padding
3154 for ($l = 0; $l < 2; $l++) {
3155 for ($j = 0; $j <= $#params; $j++) {
3156 # allow alphanumerics, '_', '[' & ']' in param names
3157 if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
3160 if (defined($sourceparams)) {
3161 $name = $$sourceparams[$PARAM_FIELD_COUNT * $j];
3166 if (!defined($name)) {
3170 if (length($type) + length($pointer) > $type_len) {
3171 $type_len = length($type) + length($pointer);
3173 if (length($name) > $name_len) {
3174 $name_len = length($name);
3178 $xref = &MakeXRef ($type, &tagify($type, "type"));
3179 $pad = ' ' x ($type_len - length($type) - length($pointer));
3180 $desc .= "$xref$pad $pointer$name,\n";
3181 $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
3184 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3185 "Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]");
3189 $xref = &MakeXRef ("gpointer", &tagify("gpointer", "type"));
3190 $pad = ' ' x ($type_len - length("gpointer"));
3191 $desc .= "$xref$pad user_data)";
3193 my $flags = $SignalFlags[$i];
3194 my $flags_string = "";
3196 if (defined ($flags)) {
3197 if ($flags =~ m/f/) {
3198 $flags_string = "Run First";
3200 elsif ($flags =~ m/l/) {
3201 $flags_string = "Run Last";
3203 elsif ($flags =~ m/c/) {
3204 $flags_string = "Cleanup";
3206 if ($flags =~ m/r/) {
3207 if ($flags_string) { $flags_string .= " / "; }
3208 $flags_string .= "No Recursion";
3210 if ($flags =~ m/d/) {
3211 if ($flags_string) { $flags_string .= " / "; }
3212 $flags_string .= "Has Details";
3214 if ($flags =~ m/a/) {
3215 if ($flags_string) { $flags_string .= " / "; }
3216 $flags_string .= "Action";
3218 if ($flags =~ m/h/) {
3219 if ($flags_string) { $flags_string .= " / "; }
3220 $flags_string .= "No Hooks";
3226 $synop .= ": $flags_string\n";
3228 $pad = ' ' x (5 + $name_len - length("user_data"));
3229 $desc .= "$pad : $flags_string</programlisting>\n";
3234 $desc .= "</programlisting>\n";
3237 $desc .= &MakeDeprecationNote($symbol);
3239 my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
3240 my $parameters_output = 0;
3242 $AllSymbols{$symbol} = 1;
3243 if (defined ($SymbolDocs{$symbol})) {
3244 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3246 # Try to insert the parameter table at the author's desired
3247 # position. Otherwise we need to tag it onto the end.
3248 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
3249 $parameters_output = 1;
3251 $desc .= $symbol_docs;
3253 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
3254 $AllDocumentedSymbols{$symbol} = 1;
3258 if ($parameters_output == 0) {
3259 $desc .= $parameters;
3261 $desc .= OutputSymbolTraits ($symbol);
3262 $desc .= "</refsect2>";
3265 return ($synop, $desc);
3269 #############################################################################
3270 # Function : GetArgs
3271 # Description : Returns the synopsis and detailed description DocBook output
3272 # for the Args of a given GtkObject subclass.
3273 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
3274 #############################################################################
3280 my $child_synop = "";
3281 my $child_desc = "";
3282 my $style_synop = "";
3283 my $style_desc = "";
3286 for ($i = 0; $i <= $#ArgObjects; $i++) {
3287 if ($ArgObjects[$i] eq $object) {
3288 #print "Found arg: $ArgNames[$i]\n";
3289 my $name = $ArgNames[$i];
3290 my $flags = $ArgFlags[$i];
3291 my $flags_string = "";
3295 if ($flags =~ m/c/) {
3296 $kind = "child property";
3299 elsif ($flags =~ m/s/) {
3300 $kind = "style property";
3307 # Remember only one colon so we don't clash with signals.
3308 my $symbol = "${object}:${name}";
3309 # use two dashes and ev. an extra separator here for the same reason.
3310 my $id = &CreateValidSGMLID ("$object--$id_sep$name");
3312 my $type = $ArgTypes[$i];
3314 my $range = $ArgRanges[$i];
3315 my $range_output = CreateValidSGML ($range);
3316 my $default = $ArgDefaults[$i];
3317 my $default_output = CreateValidSGML ($default);
3319 if ($type eq "GtkString") {
3322 if ($type eq "GtkSignal") {
3323 $type = "GtkSignalFunc, gpointer";
3324 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
3325 . &MakeXRef ("gpointer");
3326 } elsif ($type =~ m/^(\w+)\*$/) {
3327 $type_output = &MakeXRef ($1, &tagify($1, "type")) . "*";
3329 $type_output = &MakeXRef ($type, &tagify($type, "type"));
3332 if ($flags =~ m/r/) {
3333 $flags_string = "Read";
3335 if ($flags =~ m/w/) {
3336 if ($flags_string) { $flags_string .= " / "; }
3337 $flags_string .= "Write";
3339 if ($flags =~ m/x/) {
3340 if ($flags_string) { $flags_string .= " / "; }
3341 $flags_string .= "Construct";
3343 if ($flags =~ m/X/) {
3344 if ($flags_string) { $flags_string .= " / "; }
3345 $flags_string .= "Construct Only";
3348 $AllSymbols{$symbol} = 1;
3350 if (defined($SymbolDocs{$symbol}) &&
3351 !IsEmptyDoc($SymbolDocs{$symbol})) {
3352 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3353 #print ".. [$SymbolDocs{$symbol}][$blurb]\n";
3354 $AllDocumentedSymbols{$symbol} = 1;
3357 if (!($ArgBlurbs[$i] eq "")) {
3358 $AllDocumentedSymbols{$symbol} = 1;
3360 # FIXME: print a warning?
3361 #print ".. no description\n";
3363 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
3366 my $pad1 = " " x (24 - length ($name));
3367 my $pad2 = " " x (20 - length ($type));
3369 my $arg_synop = " "<link linkend=\"$id\">$name</link>"$pad1 $type_output $pad2 : $flags_string\n";
3370 my $arg_desc = "<refsect2 id=\"$id\" role=\"property\"><title>The <literal>"$name"</literal> $kind</title>\n";
3371 $arg_desc .= MakeIndexterms($symbol, $id);
3373 $arg_desc .= OutputSymbolExtraLinks($symbol);
3375 $arg_desc .= "<programlisting> "$name"$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
3376 $arg_desc .= &MakeDeprecationNote($symbol);
3377 $arg_desc .= $blurb;
3379 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
3381 if ($default ne "") {
3382 $arg_desc .= "<para>Default value: $default_output</para>\n";
3384 $arg_desc .= OutputSymbolTraits ($symbol);
3385 $arg_desc .= "</refsect2>\n";
3387 if ($flags =~ m/c/) {
3388 $child_synop .= $arg_synop;
3389 $child_desc .= $arg_desc;
3391 elsif ($flags =~ m/s/) {
3392 $style_synop .= $arg_synop;
3393 $style_desc .= $arg_desc;
3396 $synop .= $arg_synop;
3401 return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
3405 #############################################################################
3406 # Function : ReadSourceDocumentation
3407 # Description : This reads in the documentation embedded in comment blocks
3408 # in the source code (for Gnome).
3410 # Parameter descriptions override any in the template files.
3411 # Function descriptions are placed before any description from
3412 # the template files.
3414 # It recursively descends the source directory looking for .c
3415 # files and scans them looking for specially-formatted comment
3418 # Arguments : $source_dir - the directory to scan.
3419 #############m###############################################################
3421 sub ReadSourceDocumentation {
3422 my ($source_dir) = @_;
3423 my ($file, $dir, @suffix_list, $suffix);
3424 #print "Scanning source directory: $source_dir\n";
3426 # This array holds any subdirectories found.
3429 @suffix_list = split (/,/, $SOURCE_SUFFIXES);
3431 opendir (SRCDIR, $source_dir)
3432 || die "Can't open source directory $source_dir: $!";
3434 foreach $file (readdir (SRCDIR)) {
3435 if ($file =~ /^\./) {
3437 } elsif (-d "$source_dir/$file") {
3438 push (@subdirs, $file);
3439 } elsif (@suffix_list) {
3440 foreach $suffix (@suffix_list) {
3441 if ($file =~ m/\.\Q${suffix}\E$/) {
3442 &ScanSourceFile ("$source_dir/$file");
3445 } elsif ($file =~ m/\.[ch]$/) {
3446 &ScanSourceFile ("$source_dir/$file");
3451 # Now recursively scan the subdirectories.
3452 foreach $dir (@subdirs) {
3453 next if ($IGNORE_FILES =~ m/(\s|^)\Q${dir}\E(\s|$)/);
3454 &ReadSourceDocumentation ("$source_dir/$dir");
3459 #############################################################################
3460 # Function : ScanSourceFile
3461 # Description : Scans one source file looking for specially-formatted comment
3462 # blocks. Later &MergeSourceDocumentation is used to merge any
3463 # documentation found with the documentation already read in
3464 # from the template files.
3466 # Arguments : $file - the file to scan.
3467 #############################################################################
3469 sub ScanSourceFile {
3473 if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
3476 &LogWarning ($file, 1, "Can't find basename for this filename.");
3480 # Check if the basename is in the list of files to ignore.
3481 if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
3485 #print "DEBUG: Scanning $file\n";
3487 open (SRCFILE, $file)
3488 || die "Can't open $file: $!";
3489 my $in_comment_block = 0;
3491 my ($in_description, $in_return, $in_since, $in_stability, $in_deprecated);
3492 my ($description, $return_desc, $return_start, $return_style);
3493 my ($since_desc, $stability_desc, $deprecated_desc);
3495 my $ignore_broken_returns;
3498 # Look for the start of a comment block.
3499 if (!$in_comment_block) {
3500 if (m%^\s*/\*.*\*/%) {
3501 #one-line comment - not gtkdoc
3502 } elsif (m%^\s*/\*\*\s%) {
3503 #print "Found comment block start\n";
3505 $in_comment_block = 1;
3507 # Reset all the symbol data.
3509 $in_description = 0;
3518 $deprecated_desc = "";
3519 $stability_desc = "";
3520 $current_param = -1;
3521 $ignore_broken_returns = 0;
3527 # We're in a comment block. Check if we've found the end of it.
3530 # maybe its not even meant to be a gtk-doc comment?
3531 &LogWarning ($file, $., "Symbol name not found at the start of the comment block.");
3533 # Add the return value description onto the end of the params.
3535 push (@params, "Returns");
3536 push (@params, $return_desc);
3537 if ($return_style eq 'broken') {
3538 &LogWarning ($file, $., "Free-form return value description in $symbol. Use `Returns:' to avoid ambiguities.");
3541 # Convert special SGML characters
3542 $description = &ConvertSGMLChars ($symbol, $description);
3544 for ($k = 1; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3545 $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
3548 # Handle Section docs
3549 if ($symbol =~ m/SECTION:\s*(.*)/) {
3553 if (scalar %KnownSymbols) {
3554 if ((! defined($KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"})) || $KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"} != 1) {
3555 &LogWarning ($file, $., "Section $real_symbol is not defined in the $MODULE-section.txt file.");
3559 #print "SECTION DOCS found in source for : '$real_symbol'\n";
3560 $ignore_broken_returns = 1;
3561 for ($k = 0; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3562 #print " '".$params[$k]."'\n";
3563 $params[$k] = "\L$params[$k]";
3565 if ($params[$k] eq "short_description") {
3566 $key = "$TMPL_DIR/$real_symbol:Short_Description";
3567 } elsif ($params[$k] eq "see_also") {
3568 $key = "$TMPL_DIR/$real_symbol:See_Also";
3569 } elsif ($params[$k] eq "title") {
3570 $key = "$TMPL_DIR/$real_symbol:Title";
3571 } elsif ($params[$k] eq "stability") {
3572 $key = "$TMPL_DIR/$real_symbol:Stability_Level";
3573 } elsif ($params[$k] eq "section_id") {
3574 $key = "$TMPL_DIR/$real_symbol:Section_Id";
3575 } elsif ($params[$k] eq "include") {
3576 $key = "$TMPL_DIR/$real_symbol:Include";
3578 if (defined($key)) {
3579 $SourceSymbolDocs{$key}=$params[$k+1];
3580 $SourceSymbolSourceFile{$key} = $file;
3581 $SourceSymbolSourceLine{$key} = $.;
3584 $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
3585 $SourceSymbolSourceFile{"$TMPL_DIR/$real_symbol:Long_Description"} = $file;
3586 $SourceSymbolSourceLine{"$TMPL_DIR/$real_symbol:Long_Description"} = $.;
3587 #$SourceSymbolTypes{$symbol} = "SECTION";
3589 #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
3590 $SourceSymbolDocs{$symbol} = $description;
3591 $SourceSymbolParams{$symbol} = [ @params ];
3592 # FIXME $SourceSymbolTypes{$symbol} = "STRUCT,SIGNAL,ARG,FUNCTION,MACRO";
3593 #if (defined $DeclarationTypes{$symbol}) {
3594 # $SourceSymbolTypes{$symbol} = $DeclarationTypes{$symbol}
3596 $SourceSymbolSourceFile{$symbol} = $file;
3597 $SourceSymbolSourceLine{$symbol} = $.;
3601 ($since_desc, my @extra_lines) = split ("\n", $since_desc);
3602 $since_desc =~ s/^\s+//;
3603 $since_desc =~ s/\s+$//;
3604 #print "Since($symbol) : [$since_desc]\n";
3605 $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
3606 if(scalar @extra_lines) {
3607 &LogWarning ($file, $., "multi-line since docs found");
3611 if ($stability_desc) {
3612 $stability_desc = &ParseStabilityLevel($stability_desc, $file, $., "Stability level for $symbol");
3613 $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
3616 if ($deprecated_desc) {
3617 if (exists $Deprecated{$symbol}) {
3620 # don't warn for signals and properties
3621 #if ($symbol !~ m/::?(.*)/) {
3622 if (defined $DeclarationTypes{$symbol}) {
3623 &LogWarning ($file, $.,
3624 "$symbol is deprecated in the inline comments, but no deprecation guards were found around the declaration.".
3625 " (See the --deprecated-guards option for gtkdoc-scan.)");
3628 $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
3632 $in_comment_block = 0;
3636 # Get rid of ' * ' at start of every line in the comment block.
3638 # But make sure we don't get rid of the newline at the end.
3642 #print "DEBUG: scanning :$_";
3644 # If we haven't found the symbol name yet, look for it.
3646 if (m%^\s*(SECTION:\s*\S+)%) {
3648 #print "SECTION DOCS found in source for : '$symbol'\n";
3649 $ignore_broken_returns = 1;
3650 } elsif (m%^\s*([\w:-]*\w)\s*:?\s*$%) {
3652 #print "SYMBOL DOCS found in source for : '$symbol'\n";
3657 # If we're in the return value description, add it to the end.
3659 # If we find another valid returns line, we assume that the first
3660 # one was really part of the description.
3661 if (m/^\s*(returns:|return\s+value:)/i) {
3662 if ($return_style eq 'broken') {
3663 $description .= $return_start . $return_desc;
3666 if ($return_style eq 'sane') {
3667 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3669 $return_style = 'sane';
3670 $ignore_broken_returns = 1;
3672 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3673 $description .= $return_start . $return_desc;
3675 $return_style = 'broken';
3677 } elsif (m%^\s*since:%i) {
3681 } elsif (m%^\s*stability:%i) {
3682 $stability_desc = $';
3685 } elsif (m%^\s*deprecated:%i) {
3686 $deprecated_desc = $';
3696 if (m/^\s*(returns:|return\s+value:)/i) {
3697 if ($return_style eq 'broken') {
3698 $description .= $return_start . $return_desc;
3701 if ($return_style eq 'sane') {
3702 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3704 $return_style = 'sane';
3705 $ignore_broken_returns = 1;
3709 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3711 $return_style = 'broken';
3715 } elsif (m%^\s*deprecated:%i) {
3716 $deprecated_desc = $';
3719 } elsif (m%^\s*stability:%i) {
3720 $stability_desc = $';
3729 if ($in_stability) {
3730 if (m/^\s*(returns:|return\s+value:)/i) {
3731 if ($return_style eq 'broken') {
3732 $description .= $return_start . $return_desc;
3735 if ($return_style eq 'sane') {
3736 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3738 $return_style = 'sane';
3739 $ignore_broken_returns = 1;
3743 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3745 $return_style = 'broken';
3749 } elsif (m%^\s*deprecated:%i) {
3750 $deprecated_desc = $';
3753 } elsif (m%^\s*since:%i) {
3758 $stability_desc .= $_;
3763 if ($in_deprecated) {
3764 if (m/^\s*(returns:|return\s+value:)/i) {
3765 if ($return_style eq 'broken') {
3766 $description .= $return_start . $return_desc;
3769 if ($return_style eq 'sane') {
3770 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3772 $return_style = 'sane';
3773 $ignore_broken_returns = 1;
3777 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3779 $return_style = 'broken';
3783 } elsif (m%^\s*since:%i) {
3787 } elsif (m%^\s*stability:%i) {
3788 $stability_desc = $';
3792 $deprecated_desc .= $_;
3797 # If we're in the description part, check for the 'Returns:' line.
3798 # If that isn't found, add the text to the end.
3799 if ($in_description) {
3800 # Get rid of 'Description:'
3801 s%^\s*Description:%%;
3803 if (m/^\s*(returns:|return\s+value:)/i) {
3804 if ($return_style eq 'broken') {
3805 $description .= $return_start . $return_desc;
3808 if ($return_style eq 'sane') {
3809 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3811 $return_style = 'sane';
3812 $ignore_broken_returns = 1;
3816 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3818 $return_style = 'broken';
3822 } elsif (m%^\s*since:%i) {
3826 } elsif (m%^\s*deprecated:%i) {
3827 $deprecated_desc = $';
3830 } elsif (m%^\s*stability:%i) {
3831 $stability_desc = $';
3840 # We must be in the parameters. Check for the empty line below them.
3842 $in_description = 1;
3846 # Look for a parameter name.
3847 if (m%^\s*@(\S+)\s*:\s*%) {
3848 my $param_name = $1;
3849 my $param_desc = $';
3851 #print "Found parameter: $param_name\n";
3852 # Allow '...' as the Varargs parameter.
3853 if ($param_name eq "...") {
3854 $param_name = "Varargs";
3856 if ("\L$param_name" eq "returns") {
3857 $return_style = 'sane';
3858 $ignore_broken_returns = 1;
3860 push (@params, $param_name);
3861 push (@params, $param_desc);
3862 $current_param += $PARAM_FIELD_COUNT;
3866 # We must be in the middle of a parameter description, so add it on
3867 # to the last element in @params.
3868 if ($current_param == -1) {
3869 &LogWarning ($file, $., "Parsing comment block file : parameter expected.");
3871 $params[$#params] .= $_;
3877 #############################################################################
3878 # Function : OutputMissingDocumentation
3879 # Description : Outputs report of documentation coverage to a file
3882 #############################################################################
3884 sub OutputMissingDocumentation {
3885 my $n_documented = 0;
3886 my $n_incomplete = 0;
3892 my $buffer_deprecated = "";
3893 my $buffer_descriptions = "";
3895 open (UNDOCUMENTED, ">$ROOT_DIR/$MODULE-undocumented.txt")
3896 || die "Can't create $ROOT_DIR/$MODULE-undocumented.txt: $!";
3898 foreach $symbol (sort (keys (%AllSymbols))) {
3899 # FIXME: should we print LogWarnings for undocumented stuff?
3901 #my $ssfile = &GetSymbolSourceFile($symbol);
3902 #my $ssline = &GetSymbolSourceLine($symbol);
3903 #my $location = "defined at " . (defined($ssfile)?$ssfile:"?") . ":" . (defined($ssline)?$ssline:"0") . "\n";
3905 if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include|Section_Id)/) {
3907 if (exists ($AllDocumentedSymbols{$symbol})) {
3909 if (exists ($AllIncompleteSymbols{$symbol})) {
3911 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3912 #$buffer .= "\t0: ".$location;
3914 } elsif (exists $Deprecated{$symbol}) {
3915 if (exists ($AllIncompleteSymbols{$symbol})) {
3917 $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3918 #$buffer .= "\t1a: ".$location;
3920 $buffer_deprecated .= $symbol . "\n";
3921 #$buffer .= "\t1b: ".$location;
3924 if (exists ($AllIncompleteSymbols{$symbol})) {
3926 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3927 #$buffer .= "\t2a: ".$location;
3929 $buffer .= $symbol . "\n";
3930 #$buffer .= "\t2b: ".$location;
3933 } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
3935 #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
3936 #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
3937 #print "%%%% $symbol : $len1,$len2\n";
3938 if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
3939 || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
3942 # cut off the leading namespace ($TMPL_DIR)
3943 $symbol =~ m/^.*\/(.*)$/;
3944 $buffer_descriptions .= $1 . "\n";
3949 $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
3954 $percent = ($n_documented / $total) * 100.0;
3957 printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
3958 print UNDOCUMENTED "$n_documented symbols documented.\n";
3959 print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
3960 print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
3962 print UNDOCUMENTED $buffer;
3964 close (UNDOCUMENTED);
3966 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);
3970 #############################################################################
3971 # Function : OutputUndeclaredSymbols
3972 # Description : Outputs symbols that are undeclared yet documented to a file
3975 #############################################################################
3977 sub OutputUndeclaredSymbols {
3978 open(UNDECLARED, ">$ROOT_DIR/$MODULE-undeclared.txt")
3979 || die "Can't create $ROOT_DIR/$MODULE-undeclared.txt";
3981 if (%UndeclaredSymbols) {
3982 print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
3983 print UNDECLARED "\n";
3984 print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
3990 #############################################################################
3991 # Function : OutputAllSymbols
3992 # Description : Outputs list of all symbols to a file
3995 #############################################################################
3997 sub OutputAllSymbols {
3998 my $n_documented = 0;
4004 open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
4005 || die "Can't create $ROOT_DIR/$MODULE-symbols.txt: $!";
4007 foreach $symbol (sort (keys (%AllSymbols))) {
4008 print SYMBOLS $symbol . "\n";
4014 #############################################################################
4015 # Function : OutputSymbolsWithoutSince
4016 # Description : Outputs list of all symbols without a since tag to a file
4019 #############################################################################
4021 sub OutputSymbolsWithoutSince {
4022 my $n_documented = 0;
4028 open (SYMBOLS, ">$ROOT_DIR/$MODULE-nosince.txt")
4029 || die "Can't create $ROOT_DIR/$MODULE-nosince.txt: $!";
4031 foreach $symbol (sort (keys (%SourceSymbolDocs))) {
4032 if (!defined $Since{$symbol}) {
4033 print SYMBOLS $symbol . "\n";
4041 #############################################################################
4042 # Function : MergeSourceDocumentation
4043 # Description : This merges documentation read from a source file into the
4044 # documentation read in from a template file.
4046 # Parameter descriptions override any in the template files.
4047 # Function descriptions are placed before any description from
4048 # the template files.
4051 #############################################################################
4053 sub MergeSourceDocumentation {
4057 if (scalar %SymbolDocs) {
4058 @Symbols=keys (%SymbolDocs);
4059 #print "num existing entries: ".(scalar @Symbols)."\n";
4060 #print " ",$Symbols[0], " ",$Symbols[1],"\n";
4063 # filter scanned declarations, with what we suppress from -sections.txt
4065 foreach $symbol (keys (%Declarations)) {
4066 if (defined($KnownSymbols{$symbol}) && $KnownSymbols{$symbol} == 1) {
4070 # , add the rest from -sections.txt
4071 foreach $symbol (keys (%KnownSymbols)) {
4072 if ($KnownSymbols{$symbol} == 1) {
4076 # and add whats found in the source
4077 foreach $symbol (keys (%SourceSymbolDocs)) {
4080 @Symbols = keys (%tmp);
4081 #print "num source entries: ".(scalar @Symbols)."\n";
4083 foreach $symbol (@Symbols) {
4084 $AllSymbols{$symbol} = 1;
4086 my $have_tmpl_docs = 0;
4088 ## See if the symbol is documented in template
4089 my $tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4090 my $check_tmpl_doc =$tmpl_doc;
4091 # remove all xml-tags and whitespaces
4092 #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
4093 $check_tmpl_doc =~ s/<.*?>//g;
4094 $check_tmpl_doc =~ s/\s//g;
4096 if ($check_tmpl_doc ne "") {
4097 $have_tmpl_docs = 1;
4098 #print "## [$check_tmpl_doc]\n";
4103 if (exists ($SourceSymbolDocs{$symbol})) {
4104 my $type = $DeclarationTypes {$symbol};
4106 #print "merging [$symbol] from source\n";
4108 my $item = "Parameter";
4109 if (defined ($type)) {
4110 if ($type eq 'STRUCT') {
4112 } elsif ($type eq 'ENUM') {
4114 } elsif ($type eq 'UNION') {
4121 my $src_doc = $SourceSymbolDocs{$symbol};
4122 # remove leading and training whitespaces
4123 $src_doc =~ s/^\s+//;
4124 $src_doc =~ s/\s+$//;
4126 # Don't output warnings for overridden titles as titles are
4127 # automatically generated in the -sections.txt file, and thus they
4128 # are often overridden.
4129 if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
4130 # check if content is different
4131 if ($tmpl_doc ne $src_doc) {
4132 #print "[$tmpl_doc] [$src_doc]\n";
4133 &LogWarning ($SourceSymbolSourceFile{$symbol}, $SourceSymbolSourceLine{$symbol},
4134 "Documentation in template ".$SymbolSourceFile{$symbol}.":".$SymbolSourceLine{$symbol}." for $symbol being overridden by inline comments.");
4138 if ($src_doc ne "") {
4139 $AllDocumentedSymbols{$symbol} = 1;
4142 # Convert <!--PARAMETERS--> with any blank lines around it to
4143 # a </para> followed by <!--PARAMETERS--> followed by <para>.
4144 $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
4146 # If there is a blank line, finish the paragraph and start another.
4147 $src_doc = &ConvertBlankLines ($src_doc, $symbol);
4148 # Do not add <para> to nothing, it breaks missing docs checks.
4149 my $src_doc_para = "";
4151 $src_doc_para = "<para>\n$src_doc</para>\n";
4152 #print "$symbol : [$src_doc][$src_doc_para]\n";
4155 if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
4156 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4157 } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
4158 # For the title/summary/see also section docs we don't want to
4159 # add any <para> tags.
4160 $SymbolDocs{$symbol} = "$src_doc"
4162 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4166 if ($symbol =~ m/.*::.*/) {
4167 # For signals we prefer the param names from the source docs,
4168 # since the ones from the templates are likely to contain the
4169 # artificial argn names which are generated by gtkdoc-scangobj.
4170 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4171 # FIXME: we need to check for empty docs here as well!
4173 # The templates contain the definitive parameter names and order,
4174 # so we will not change that. We only override the actual text.
4175 my $tmpl_params = $SymbolParams{$symbol};
4176 if (!defined ($tmpl_params)) {
4177 #print "No merge needed for $symbol\n";
4178 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4179 # FIXME: we still like to get the number of params and merge
4180 # 1) we would noticed that params have been removed/renamed
4181 # 2) we would catch undocumented params
4182 # params are not (yet) exported in -decl.txt so that we
4183 # could easily grab them :/
4185 my $params = $SourceSymbolParams{$symbol};
4187 #print "Merge needed for $symbol, tmpl_params: ",$#$tmpl_params,", source_params: ",$#$params," \n";
4188 for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4189 my $tmpl_param_name = $$tmpl_params[$j];
4191 # Allow '...' as the Varargs parameter.
4192 if ($tmpl_param_name eq "...") {
4193 $tmpl_param_name = "Varargs";
4196 # Try to find the param in the source comment documentation.
4199 #print " try merge param $tmpl_param_name\n";
4200 for ($k = 0; $k <= $#$params; $k += $PARAM_FIELD_COUNT) {
4201 my $param_name = $$params[$k];
4202 my $param_desc = $$params[$k + 1];
4204 #print " test param $param_name\n";
4205 # We accept changes in case, since the Gnome source
4206 # docs contain a lot of these.
4207 if ("\L$param_name" eq "\L$tmpl_param_name") {
4210 # Override the description.
4211 $$tmpl_params[$j + 1] = $param_desc;
4213 # Set the name to "" to mark it as used.
4219 # If it looks like the parameters are there, but not
4220 # in the right place, try to explain a bit better.
4221 if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
4222 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4223 "Parameters for $symbol must start on the line immediately after the function or macro name.");
4227 # Now we output a warning if parameters have been described which
4229 for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
4230 my $param_name = $$params[$j];
4232 # the template builder cannot detect if a macro returns
4234 if(($type eq "MACRO") && ($param_name eq "Returns")) {
4235 # FIXME: do we need to add it then to tmpl_params[] ?
4236 my $num=$#$tmpl_params;
4237 #print " adding Returns: to macro docs for $symbol.\n";
4238 $$tmpl_params[$num+1]="Returns";
4239 $$tmpl_params[$num+2]=$$params[$j+1];
4242 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4243 "$item described in source code comment block but does not exist. $type: $symbol $item: $param_name.");
4249 if ($have_tmpl_docs) {
4250 $AllDocumentedSymbols{$symbol} = 1;
4251 #print "merging [$symbol] from template\n";
4254 #print "[$symbol] undocumented\n";
4258 # if this symbol is documented, check if docs are complete
4259 $check_tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4260 # remove all xml-tags and whitespaces
4261 #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
4262 $check_tmpl_doc =~ s/<.*?>//g;
4263 $check_tmpl_doc =~ s/\s//g;
4264 if ($check_tmpl_doc ne "") {
4265 my $tmpl_params = $SymbolParams{$symbol};
4266 if (defined ($tmpl_params)) {
4267 my $type = $DeclarationTypes {$symbol};
4269 my $item = "Parameter";
4270 if (defined ($type)) {
4271 if ($type eq 'STRUCT') {
4273 } elsif ($type eq 'ENUM') {
4275 } elsif ($type eq 'UNION') {
4282 #print "Check param docs for $symbol, tmpl_params: ",$#$tmpl_params," entries, type=$type\n";
4284 if ($#$tmpl_params > 0) {
4286 for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4287 # Output a warning if the parameter is empty and
4288 # remember for stats.
4289 my $tmpl_param_name = $$tmpl_params[$j];
4290 my $tmpl_param_desc = $$tmpl_params[$j + 1];
4291 if ($tmpl_param_desc !~ m/\S/) {
4292 if (exists ($AllIncompleteSymbols{$symbol})) {
4293 $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
4295 $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
4297 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4298 "$item description for $symbol"."::"."$tmpl_param_name is missing in source code comment block.");
4303 if ($#$tmpl_params == 0) {
4304 $AllIncompleteSymbols{$symbol}="<items>";
4305 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4306 "$item descriptions for $symbol are missing in source code comment block.");
4308 # $#$tmpl_params==-1 means we don't know about parameters
4309 # this unfortunately does not tell if there should be some
4314 #print "num doc entries: ".(scalar %SymbolDocs)."\n";
4317 #############################################################################
4318 # Function : IsEmptyDoc
4319 # Description : Check if a doc-string is empty. Its also regarded as empty if
4320 # it only consist of whitespace or e.g. FIXME.
4321 # Arguments : the doc-string
4322 #############################################################################
4326 if ($doc =~ /^\s*$/) {
4330 if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
4338 # This converts blank lines to "</para><para>", but only outside CDATA and
4339 # <programlisting> tags.
4340 sub ConvertBlankLines {
4341 return &ModifyXMLElements ($_[0], $_[1],
4342 "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
4343 \&ConvertBlankLinesEndTag,
4344 \&ConvertBlankLinesCallback);
4348 sub ConvertBlankLinesEndTag {
4349 if ($_[0] eq "<!\[CDATA\[") {
4351 } elsif ($_[0] eq "|[") {
4354 return "</programlisting>";
4358 sub ConvertBlankLinesCallback {
4359 my ($text, $symbol, $tag) = @_;
4361 # If we're not in CDATA or a <programlisting> we convert blank lines so
4362 # they start a new <para>.
4364 $text =~ s%\n{2,}%\n</para>\n<para>\n%g;
4371 #############################################################################
4372 # LIBRARY FUNCTIONS - These functions are used in both gtkdoc-mkdb and
4373 # gtkdoc-mktmpl and should eventually be moved to a
4375 #############################################################################
4377 #############################################################################
4378 # Function : ReadDeclarationsFile
4379 # Description : This reads in a file containing the function/macro/enum etc.
4382 # Note that in some cases there are several declarations with
4383 # the same name, e.g. for conditional macros. In this case we
4384 # set a flag in the %DeclarationConditional hash so the
4385 # declaration is not shown in the docs.
4387 # If a macro and a function have the same name, e.g. for
4388 # gtk_object_ref, the function declaration takes precedence.
4390 # Some opaque structs are just declared with 'typedef struct
4391 # _name name;' in which case the declaration may be empty.
4392 # The structure may have been found later in the header, so
4393 # that overrides the empty declaration.
4395 # Arguments : $file - the declarations file to read
4396 # $override - if declarations in this file should override
4397 # any current declaration.
4398 #############################################################################
4400 sub ReadDeclarationsFile {
4401 my ($file, $override) = @_;
4403 if ($override == 0) {
4405 %DeclarationTypes = ();
4406 %DeclarationConditional = ();
4407 %DeclarationOutput = ();
4411 || die "Can't open $file: $!";
4412 my $declaration_type = "";
4413 my $declaration_name;
4415 my $is_deprecated = 0;
4417 if (!$declaration_type) {
4418 if (m/^<([^>]+)>/) {
4419 $declaration_type = $1;
4420 $declaration_name = "";
4421 #print "Found declaration: $declaration_type\n";
4425 if (m%^<NAME>(.*)</NAME>%) {
4426 $declaration_name = $1;
4427 } elsif (m%^<DEPRECATED/>%) {
4429 } elsif (m%^</$declaration_type>%) {
4430 #print "Found end of declaration: $declaration_name\n";
4431 # Check that the declaration has a name
4432 if ($declaration_name eq "") {
4433 print "ERROR: $declaration_type has no name $file:$.\n";
4436 # If the declaration is an empty typedef struct _XXX XXX
4437 # set the flag to indicate the struct has a typedef.
4438 if ($declaration_type eq 'STRUCT'
4439 && $declaration =~ m/^\s*$/) {
4440 #print "Struct has typedef: $declaration_name\n";
4441 $StructHasTypedef{$declaration_name} = 1;
4444 # Check if the symbol is already defined.
4445 if (defined ($Declarations{$declaration_name})
4446 && $override == 0) {
4447 # Function declarations take precedence.
4448 if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
4450 } elsif ($declaration_type eq 'FUNCTION') {
4451 if ($is_deprecated) {
4452 $Deprecated{$declaration_name} = "";
4454 $Declarations{$declaration_name} = $declaration;
4455 $DeclarationTypes{$declaration_name} = $declaration_type;
4456 } elsif ($DeclarationTypes{$declaration_name}
4457 eq $declaration_type) {
4458 # If the existing declaration is empty, or is just a
4459 # forward declaration of a struct, override it.
4460 if ($declaration_type eq 'STRUCT') {
4461 if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4462 if ($is_deprecated) {
4463 $Deprecated{$declaration_name} = "";
4465 $Declarations{$declaration_name} = $declaration;
4466 } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4467 # Ignore an empty or forward declaration.
4469 &LogWarning ($file, $., "Structure $declaration_name has multiple definitions.");
4472 # set flag in %DeclarationConditional hash for
4473 # multiply defined macros/typedefs.
4474 $DeclarationConditional{$declaration_name} = 1;
4477 &LogWarning ($file, $., "$declaration_name has multiple definitions.");
4480 if ($is_deprecated) {
4481 $Deprecated{$declaration_name} = "";
4483 $Declarations{$declaration_name} = $declaration;
4484 $DeclarationTypes{$declaration_name} = $declaration_type;
4487 $declaration_type = "";
4498 #############################################################################
4499 # Function : ReadSignalsFile
4500 # Description : This reads in an existing file which contains information on
4501 # all GTK signals. It creates the arrays @SignalNames and
4502 # @SignalPrototypes containing info on the signals. The first
4503 # line of the SignalPrototype is the return type of the signal
4504 # handler. The remaining lines are the parameters passed to it.
4505 # The last parameter, "gpointer user_data" is always the same
4506 # so is not included.
4507 # Arguments : $file - the file containing the signal handler prototype
4509 #############################################################################
4511 sub ReadSignalsFile {
4519 my $signal_prototype;
4521 # Reset the signal info.
4522 @SignalObjects = ();
4524 @SignalReturns = ();
4526 @SignalPrototypes = ();
4531 if (!open (INPUT, $file)) {
4532 warn "Can't open $file - skipping signals\n";
4539 $signal_object = "";
4541 $signal_returns = "";
4542 $signal_prototype = "";
4545 if (m/^<NAME>(.*)<\/NAME>/) {
4547 if ($signal_name =~ m/^(.*)::(.*)$/) {
4548 $signal_object = $1;
4549 ($signal_name = $2) =~ s/_/-/g;
4550 #print "Found signal: $signal_name\n";
4552 &LogWarning ($file, $., "Invalid signal name: $signal_name.");
4554 } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
4555 $signal_returns = $1;
4556 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4558 } elsif (m%^</SIGNAL>%) {
4559 #print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
4560 push (@SignalObjects, $signal_object);
4561 push (@SignalNames, $signal_name);
4562 push (@SignalReturns, $signal_returns);
4563 push (@SignalFlags, $signal_flags);
4564 push (@SignalPrototypes, $signal_prototype);
4567 $signal_prototype .= $_;
4575 #############################################################################
4576 # Function : ReadTemplateFile
4577 # Description : This reads in the manually-edited documentation file
4578 # corresponding to the file currently being created, so we can
4579 # insert the documentation at the appropriate places.
4580 # It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
4581 # is a hash of arrays.
4582 # NOTE: This function is duplicated in gtkdoc-mktmpl (but
4583 # slightly different).
4584 # Arguments : $docsfile - the template file to read in.
4585 # $skip_unused_params - 1 if the unused parameters should be
4587 #############################################################################
4589 sub ReadTemplateFile {
4590 my ($docsfile, $skip_unused_params) = @_;
4592 my $template = "$docsfile.sgml";
4593 if (! -f $template) {
4594 #print "File doesn't exist: $template\n";
4597 #print "Reading $template\n";
4599 # start with empty hashes, we merge the source comment for each file
4605 my $current_type = ""; # Type of symbol being read.
4606 my $current_symbol = ""; # Name of symbol being read.
4607 my $symbol_doc = ""; # Description of symbol being read.
4608 my @params; # Parameter names and descriptions of current
4609 # function/macro/function typedef.
4610 my $current_param = -1; # Index of parameter currently being read.
4611 # Note that the param array contains pairs
4612 # of param name & description.
4613 my $in_unused_params = 0; # True if we are reading in the unused params.
4614 my $in_deprecated = 0;
4616 my $in_stability = 0;
4618 open (DOCS, "$template")
4619 || die "Can't open $template: $!";
4621 if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
4624 if ($symbol eq "Title"
4625 || $symbol eq "Short_Description"
4626 || $symbol eq "Long_Description"
4627 || $symbol eq "See_Also"
4628 || $symbol eq "Stability_Level"
4629 || $symbol eq "Include") {
4631 $symbol = $docsfile . ":" . $symbol;
4634 #print "Found symbol: $symbol\n";
4635 # Remember file and line for the symbol
4636 $SymbolSourceFile{$symbol} = $template;
4637 $SymbolSourceLine{$symbol} = $.;
4639 # Store previous symbol, but remove any trailing blank lines.
4640 if ($current_symbol ne "") {
4641 $symbol_doc =~ s/\s+$//;
4642 $SymbolTypes{$current_symbol} = $current_type;
4643 $SymbolDocs{$current_symbol} = $symbol_doc;
4645 # Check that the stability level is valid.
4646 if ($StabilityLevel{$current_symbol}) {
4647 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4650 if ($current_param >= 0) {
4651 $SymbolParams{$current_symbol} = [ @params ];
4653 # Delete any existing params in case we are overriding a
4654 # previously read template.
4655 delete $SymbolParams{$current_symbol};
4658 $current_type = $type;
4659 $current_symbol = $symbol;
4660 $current_param = -1;
4661 $in_unused_params = 0;
4668 } elsif (m/^<!-- # Unused Parameters # -->/) {
4669 #print "DEBUG: Found unused parameters\n";
4670 $in_unused_params = 1;
4673 } elsif ($in_unused_params && $skip_unused_params) {
4674 # When outputting the DocBook we skip unused parameters.
4675 #print "DEBUG: Skipping unused param: $_";
4679 # Check if param found. Need to handle "..." and "format...".
4680 if (s/^\@([\w\.]+):\040?//) {
4681 my $param_name = $1;
4682 my $param_desc = $_;
4683 # Allow variations of 'Returns'
4684 if ($param_name =~ m/^[Rr]eturns?$/) {
4685 $param_name = "Returns";
4688 # strip trailing whitespaces and blank lines
4691 #print "Found param for symbol $current_symbol : '$param_name'= '$_'";
4693 if ($param_name eq "Deprecated") {
4695 $Deprecated{$current_symbol} = $_;
4696 } elsif ($param_name eq "Since") {
4699 $Since{$current_symbol} = $_;
4700 } elsif ($param_name eq "Stability") {
4702 $StabilityLevel{$current_symbol} = $_;
4704 push (@params, $param_name);
4705 push (@params, $param_desc);
4706 $current_param += $PARAM_FIELD_COUNT;
4709 # strip trailing whitespaces and blank lines
4714 if ($in_deprecated) {
4715 $Deprecated{$current_symbol} .= $_;
4716 } elsif ($in_since) {
4717 &LogWarning ($template, $., "multi-line since docs found");
4718 #$Since{$current_symbol} .= $_;
4719 } elsif ($in_stability) {
4720 $StabilityLevel{$current_symbol} .= $_;
4721 } elsif ($current_param >= 0) {
4722 $params[$current_param] .= $_;
4731 # Remember to finish the current symbol doccs.
4732 if ($current_symbol ne "") {
4734 $symbol_doc =~ s/\s+$//;
4735 $SymbolTypes{$current_symbol} = $current_type;
4736 $SymbolDocs{$current_symbol} = $symbol_doc;
4738 # Check that the stability level is valid.
4739 if ($StabilityLevel{$current_symbol}) {
4740 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4743 if ($current_param >= 0) {
4744 $SymbolParams{$current_symbol} = [ @params ];
4746 # Delete any existing params in case we are overriding a
4747 # previously read template.
4748 delete $SymbolParams{$current_symbol};
4757 #############################################################################
4758 # Function : ReadObjectHierarchy
4759 # Description : This reads in the $MODULE-hierarchy.txt file containing all
4760 # the GtkObject subclasses described in this module (and their
4762 # It places them in the @Objects array, and places their level
4763 # in the widget hierarchy in the @ObjectLevels array, at the
4764 # same index. GtkObject, the root object, has a level of 1.
4766 # FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
4767 # as it goes along, this should be split out into a separate
4771 #############################################################################
4773 sub ReadObjectHierarchy {
4777 if (! -f $OBJECT_TREE_FILE) {
4780 if (!open (INPUT, $OBJECT_TREE_FILE)) {
4781 warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
4785 # FIXME: use $OUTPUT_FORMAT
4786 # my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.$OUTPUT_FORMAT";
4787 my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
4788 my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
4790 open (OUTPUT, ">$new_tree_index")
4791 || die "Can't create $new_tree_index: $!";
4793 if (lc($OUTPUT_FORMAT) eq "xml") {
4794 my $tree_header = $doctype_header;
4796 $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
4797 print (OUTPUT "$tree_header");
4799 print (OUTPUT "<screen>\n");
4801 # Only emit objects if they are supposed to be documented, or if
4802 # they have documented children. To implement this, we maintain a
4803 # stack of pending objects which will be emitted if a documented
4805 my @pending_objects = ();
4806 my @pending_levels = ();
4810 my $level = (length($`)) / 2 + 1;
4813 while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
4814 my $pobject = pop(@pending_objects);
4815 my $plevel = pop(@pending_levels);
4818 push (@pending_objects, $object);
4819 push (@pending_levels, $level);
4821 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
4822 while ($#pending_levels >= 0) {
4823 $object = shift @pending_objects;
4824 $level = shift @pending_levels;
4825 $xref = &MakeXRef ($object);
4827 print (OUTPUT ' ' x ($level * 4), "$xref\n");
4828 push (@Objects, $object);
4829 push (@ObjectLevels, $level);
4833 # LogWarning ($OBJECT_TREE_FILE, $., "unknown type $object");
4837 print (OUTPUT "</screen>\n");
4842 &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
4847 #############################################################################
4848 # Function : ReadInterfaces
4849 # Description : This reads in the $MODULE.interfaces file.
4852 #############################################################################
4854 sub ReadInterfaces {
4857 if (! -f $INTERFACES_FILE) {
4860 if (!open (INPUT, $INTERFACES_FILE)) {
4861 warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
4867 my ($object, @ifaces) = split;
4868 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
4869 my @knownIfaces = ();
4871 # filter out private interfaces, but leave foreign interfaces
4872 foreach my $iface (@ifaces) {
4873 if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
4874 push (@knownIfaces, $iface);
4878 $Interfaces{$object} = join(' ', @knownIfaces);
4884 #############################################################################
4885 # Function : ReadPrerequisites
4886 # Description : This reads in the $MODULE.prerequisites file.
4889 #############################################################################
4891 sub ReadPrerequisites {
4892 %Prerequisites = ();
4894 if (! -f $PREREQUISITES_FILE) {
4897 if (!open (INPUT, $PREREQUISITES_FILE)) {
4898 warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
4904 my ($iface, @prereqs) = split;
4905 if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
4906 my @knownPrereqs = ();
4908 # filter out private prerequisites, but leave foreign prerequisites
4909 foreach my $prereq (@prereqs) {
4910 if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
4911 push (@knownPrereqs, $prereq);
4915 $Prerequisites{$iface} = join(' ', @knownPrereqs);
4921 #############################################################################
4922 # Function : ReadArgsFile
4923 # Description : This reads in an existing file which contains information on
4924 # all GTK args. It creates the arrays @ArgObjects, @ArgNames,
4925 # @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
4927 # Arguments : $file - the file containing the arg information.
4928 #############################################################################
4943 # Reset the args info.
4956 if (!open (INPUT, $file)) {
4957 warn "Can't open $file - skipping args\n";
4974 if (m/^<NAME>(.*)<\/NAME>/) {
4976 if ($arg_name =~ m/^(.*)::(.*)$/) {
4978 ($arg_name = $2) =~ s/_/-/g;
4979 #print "Found arg: $arg_name\n";
4981 &LogWarning ($file, $., "Invalid argument name: $arg_name");
4983 } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
4985 } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
4987 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4989 } elsif (m/^<NICK>(.*)<\/NICK>/) {
4991 } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
4993 if ($arg_blurb eq "(null)") {
4995 &LogWarning ($file, $., "Property ${arg_object}:${arg_name} has no documentation.");
4997 } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
4999 } elsif (m%^</ARG>%) {
5000 #print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
5001 push (@ArgObjects, $arg_object);
5002 push (@ArgNames, $arg_name);
5003 push (@ArgTypes, $arg_type);
5004 push (@ArgRanges, $arg_range);
5005 push (@ArgFlags, $arg_flags);
5006 push (@ArgNicks, $arg_nick);
5007 push (@ArgBlurbs, $arg_blurb);
5008 push (@ArgDefaults, $arg_default);
5017 #############################################################################
5018 # Function : CheckIsObject
5019 # Description : Returns 1 if the given name is a GObject or a subclass.
5020 # It uses the global @Objects array.
5021 # Note that the @Objects array only contains classes in the
5022 # current module and their ancestors - not all GObject classes.
5023 # Arguments : $name - the name to check.
5024 #############################################################################
5030 foreach $object (@Objects) {
5031 if ($object eq $name) {
5039 #############################################################################
5040 # Function : MakeReturnField
5041 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
5042 # Arguments : $str - the string to pad.
5043 #############################################################################
5045 sub MakeReturnField {
5048 return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));
5051 #############################################################################
5052 # Function : GetSymbolSourceFile
5053 # Description : Get the filename where the symbol docs where taken from.
5054 # Arguments : $symbol - the symbol name
5055 #############################################################################
5057 sub GetSymbolSourceFile {
5060 if (defined($SourceSymbolSourceFile{$symbol})) {
5061 return $SourceSymbolSourceFile{$symbol};
5062 } elsif (defined($SymbolSourceFile{$symbol})) {
5063 return $SymbolSourceFile{$symbol};
5069 #############################################################################
5070 # Function : GetSymbolSourceLine
5071 # Description : Get the file line where the symbol docs where taken from.
5072 # Arguments : $symbol - the symbol name
5073 #############################################################################
5075 sub GetSymbolSourceLine {
5078 if (defined($SourceSymbolSourceLine{$symbol})) {
5079 return $SourceSymbolSourceLine{$symbol};
5080 } elsif (defined($SymbolSourceLine{$symbol})) {
5081 return $SymbolSourceLine{$symbol};