4 # gtk-doc - GTK DocBook documentation generator.
5 # Copyright (C) 1998 Damon Chaplin
6 # 2007,2008 Stefan Kost
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #############################################################################
24 # Script : gtkdoc-mkdb
25 # Description : This creates the DocBook files from the edited templates.
27 # NOTE: When creating SGML IDS, we append ":CAPS" to all
28 # all-caps identifiers to prevent name clashes. (It basically
29 # never is the case that mixed-case identifiers would collide.)
30 # See the CreateValidSGMLID function.
31 #############################################################################
36 unshift @INC, '@PACKAGE_DATA_DIR@';
37 require "gtkdoc-common.pl";
41 # name of documentation module
46 my $SOURCE_SUFFIXES = "";
47 my $IGNORE_FILES = "";
51 my $EXPAND_CONTENT_FILES = "";
53 my $DEFAULT_STABILITY;
57 my $OUTPUT_ALL_SYMBOLS;
58 my $OUTPUT_SYMBOLS_WITHOUT_SINCE;
60 my %optctl = ('module' => \$MODULE,
61 'source-dir' => \@SOURCE_DIRS,
62 'source-suffixes' => \$SOURCE_SUFFIXES,
63 'ignore-files' => \$IGNORE_FILES,
64 'output-dir' => \$SGML_OUTPUT_DIR,
65 'tmpl-dir' => \$TMPL_DIR,
66 'version' => \$PRINT_VERSION,
67 'help' => \$PRINT_HELP,
68 'main-sgml-file' => \$MAIN_SGML_FILE,
69 'expand-content-files' => \$EXPAND_CONTENT_FILES,
70 'sgml-mode' => \$SGML_MODE,
71 'default-stability' => \$DEFAULT_STABILITY,
72 'default-includes' => \$DEFAULT_INCLUDES,
73 'output-format' => \$OUTPUT_FORMAT,
74 'name-space' => \$NAME_SPACE,
75 'outputallsymbols' => \$OUTPUT_ALL_SYMBOLS,
76 'outputsymbolswithoutsince' => \$OUTPUT_SYMBOLS_WITHOUT_SINCE
78 GetOptions(\%optctl, "module=s", "source-dir:s", "source-suffixes:s",
79 "ignore-files:s", "output-dir:s", "tmpl-dir:s", "version", "outputallsymbols",
80 "outputsymbolswithoutsince",
81 "expand-content-files:s", "main-sgml-file:s", "extra-db-files:s", "help",
82 "sgml-mode", "default-stability:s", "default-includes:s", "output-format:s",
94 if ($DEFAULT_STABILITY && $DEFAULT_STABILITY ne "Stable"
95 && $DEFAULT_STABILITY ne "Private" && $DEFAULT_STABILITY ne "Unstable") {
101 gtkdoc-mkdb version @VERSION@ - generate docbook files
103 --module=MODULE_NAME Name of the doc module being parsed
104 --source-dir=DIRNAME Directories which contain inline reference material
105 --source-suffixes=SUFFIXES Suffixes of source files to scan, comma-separated
106 --ignore-files=FILES Files or directories which should not be scanned
107 May be used more than once for multiple directories
108 --output-dir=DIRNAME Directory to put the generated DocBook files in
109 --tmpl-dir=DIRNAME Directory in which template files may be found
110 --main-sgml-file=FILE File containing the toplevel DocBook file.
111 --expand-content-files=FILES Extra DocBook files to expand abbreviations in.
112 --output-format=FORMAT Format to use for the generated docbook, XML or SGML.
113 --sgml-mode Allow DocBook markup in inline documentation.
114 --default-stability=LEVEL Specify default stability Level. Valid values are
115 Stable, Unstable, or Private.
116 --default-includes=FILENAMES Specify default includes for section Synopsis
117 --name-space=NS Omit namespace in index.
118 --version Print the version of this program
119 --help Print this help
124 my ($empty_element_end, $doctype_header);
126 if (lc($OUTPUT_FORMAT) eq "xml") {
127 if (!$MAIN_SGML_FILE) {
128 # backwards compatibility
129 if (-e "${MODULE}-docs.sgml") {
130 $MAIN_SGML_FILE="${MODULE}-docs.sgml";
132 $MAIN_SGML_FILE="${MODULE}-docs.xml";
135 $OUTPUT_FORMAT = "xml";
136 $empty_element_end = "/>";
138 if (-e $MAIN_SGML_FILE) {
139 open(INPUT, "<$MAIN_SGML_FILE") || die "Can't open $MAIN_SGML_FILE";
140 $doctype_header = "";
142 if (/^\s*<(book|chapter|article)/) {
143 if ($_ !~ m/http:\/\/www.w3.org\/200[13]\/XInclude/) {
144 $doctype_header = "";
148 $doctype_header .= $_;
153 "<?xml version=\"1.0\"?>\n" .
154 "<!DOCTYPE book PUBLIC \"-//OASIS//DTD DocBook XML V4.3//EN\"\n" .
155 " \"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd\">\n";
157 $doctype_header =~ s/<!DOCTYPE \w+/<!DOCTYPE refentry/;
159 if (!$MAIN_SGML_FILE) {
160 $MAIN_SGML_FILE="${MODULE}-docs.sgml";
162 $OUTPUT_FORMAT = "sgml";
163 $doctype_header = "";
164 $empty_element_end = ">";
169 # All the files are written in subdirectories beneath here.
170 $TMPL_DIR = $TMPL_DIR ? $TMPL_DIR : "$ROOT_DIR/tmpl";
172 # This is where we put all the DocBook output.
173 $SGML_OUTPUT_DIR = $SGML_OUTPUT_DIR ? $SGML_OUTPUT_DIR : "$ROOT_DIR/$OUTPUT_FORMAT";
175 # This file contains the object hierarchy.
176 my $OBJECT_TREE_FILE = "$ROOT_DIR/$MODULE.hierarchy";
178 # This file contains the interfaces.
179 my $INTERFACES_FILE = "$ROOT_DIR/$MODULE.interfaces";
181 # This file contains the prerequisites.
182 my $PREREQUISITES_FILE = "$ROOT_DIR/$MODULE.prerequisites";
184 # This file contains signal arguments and names.
185 my $SIGNALS_FILE = "$ROOT_DIR/$MODULE.signals";
187 # The file containing Arg information.
188 my $ARGS_FILE = "$ROOT_DIR/$MODULE.args";
190 # These global arrays store information on signals. Each signal has an entry
191 # in each of these arrays at the same index, like a multi-dimensional array.
192 my @SignalObjects; # The GtkObject which emits the signal.
193 my @SignalNames; # The signal name.
194 my @SignalReturns; # The return type.
195 my @SignalFlags; # Flags for the signal
196 my @SignalPrototypes; # The rest of the prototype of the signal handler.
198 # These global arrays store information on Args. Each Arg has an entry
199 # in each of these arrays at the same index, like a multi-dimensional array.
200 my @ArgObjects; # The GtkObject which has the Arg.
201 my @ArgNames; # The Arg name.
202 my @ArgTypes; # The Arg type - gint, GtkArrowType etc.
203 my @ArgFlags; # How the Arg can be used - readable/writable etc.
204 my @ArgNicks; # The nickname of the Arg.
205 my @ArgBlurbs; # Docstring of the Arg.
206 my @ArgDefaults; # Default value of the Arg.
207 my @ArgRanges; # The range of the Arg type
208 # These global hashes store declaration info keyed on a symbol name.
210 my %DeclarationTypes;
211 my %DeclarationConditional;
212 my %DeclarationOutput;
216 my %StructHasTypedef;
218 # These global hashes store the existing documentation.
222 my %SymbolSourceFile;
223 my %SymbolSourceLine;
225 # These global hashes store documentation scanned from the source files.
226 my %SourceSymbolDocs;
227 my %SourceSymbolParams;
228 my %SourceSymbolSourceFile;
229 my %SourceSymbolSourceLine;
231 # all documentation goes in here, so we can do coverage analysis
233 my %AllIncompleteSymbols;
234 my %AllDocumentedSymbols;
236 # Undeclared yet documented symbols
237 my %UndeclaredSymbols;
239 # These global arrays store GObject, subclasses and the hierarchy.
246 # holds the symbols which are mentioned in $MODULE-sections.txt
249 # collects index entries
250 my %IndexEntriesFull;
251 my %IndexEntriesSince;
252 my %IndexEntriesDeprecated;
254 # Standard C preprocessor directives, which we ignore for '#' abbreviations.
255 my %PreProcessorDirectives;
256 $PreProcessorDirectives{"assert"} = 1;
257 $PreProcessorDirectives{"define"} = 1;
258 $PreProcessorDirectives{"elif"} = 1;
259 $PreProcessorDirectives{"else"} = 1;
260 $PreProcessorDirectives{"endif"} = 1;
261 $PreProcessorDirectives{"error"} = 1;
262 $PreProcessorDirectives{"if"} = 1;
263 $PreProcessorDirectives{"ifdef"} = 1;
264 $PreProcessorDirectives{"ifndef"} = 1;
265 $PreProcessorDirectives{"include"} = 1;
266 $PreProcessorDirectives{"line"} = 1;
267 $PreProcessorDirectives{"pragma"} = 1;
268 $PreProcessorDirectives{"unassert"} = 1;
269 $PreProcessorDirectives{"undef"} = 1;
270 $PreProcessorDirectives{"warning"} = 1;
272 # remember used annotation (to write minimal glossary)
275 my %AnnotationDefinition = (
276 'allow-none' => "NULL is ok, both for passing and for returning.",
277 'array' => "Parameter points to an array of items.",
278 'default' => "Default parameter value (for in case the <acronym>shadows</acronym>-to function has less parameters).",
279 'element-type' => "Generics and defining elements of containers and arrays.",
280 'error-domains' => "Typed errors. Similar to throws in Java.",
281 'in' => "Parameter for input. Default is <acronym>transfer none</acronym>.",
282 'inout' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
283 'in-out' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
284 'not-error' => "A GError parameter is not to be handled like a normal GError.",
285 'out' => "Parameter for returning results. Default is <acronym>transfer full</acronym>.",
286 'transfer container' => "Free data container after the code is done.",
287 'transfer full' => "Free data after the code is done.",
288 'transfer none' => "Don't free data after the code is done."
291 # Create the root DocBook output directory if it doens't exist.
292 if (! -e $SGML_OUTPUT_DIR) {
293 mkdir ("$SGML_OUTPUT_DIR", 0777)
294 || die "Can't create directory: $SGML_OUTPUT_DIR";
297 # Function and other declaration output settings.
298 my $RETURN_TYPE_FIELD_WIDTH = 20;
299 my $SYMBOL_FIELD_WIDTH = 36;
300 my $SIGNAL_FIELD_WIDTH = 16;
301 my $PARAM_FIELD_COUNT = 2;
303 &ReadKnownSymbols ("$ROOT_DIR/$MODULE-sections.txt");
304 &ReadSignalsFile ($SIGNALS_FILE);
305 &ReadArgsFile ($ARGS_FILE);
306 &ReadObjectHierarchy;
310 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-decl.txt", 0);
311 if (-f "$ROOT_DIR/$MODULE-overrides.txt") {
312 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-overrides.txt", 1);
315 for my $dir (@SOURCE_DIRS) {
316 &ReadSourceDocumentation ($dir);
319 my $changed = &OutputSGML ("$ROOT_DIR/$MODULE-sections.txt");
321 # If any of the DocBook SGML files have changed, update the timestamp file (so
322 # it can be used for Makefile dependencies).
323 if ($changed || ! -e "$ROOT_DIR/sgml.stamp") {
325 # try to detect the common prefix
326 # GtkWidget, GTK_WIDGET, gtk_widget -> gtk
327 if ($NAME_SPACE eq "") {
334 foreach my $symbol (keys(%IndexEntriesFull)) {
335 if(($NAME_SPACE eq "") || $symbol =~ /^$NAME_SPACE/i) {
336 if (length($symbol)>$pos) {
337 $letter=substr($symbol,$pos,1);
338 # stop prefix scanning
339 if ($letter eq "_") {
343 # Should we also stop on a uppercase char, if last was lowercase
344 # GtkWidget, if we have the 'W' and had the 't' before
345 # or should we count upper and lowercase, and stop one 2nd uppercase, if we already had a lowercase
346 # GtkWidget, the 'W' would be the 2nd uppercase and with 't','k' we had lowercase chars before
347 # need to recound each time as this is per symbol
348 $prefix{uc($letter)}++;
352 if ($letter ne "" && $letter ne "_") {
355 foreach $letter (keys(%prefix)) {
356 #print "$letter: $prefix{$letter}.\n";
357 if ($prefix{$letter}>$maxsymbols) {
359 $maxsymbols=$prefix{$letter};
362 $ratio = scalar(keys(%IndexEntriesFull)) / $prefix{$maxletter};
363 #print "most symbols start with $maxletter, that is ". (100 * $ratio) ." %\n";
366 $NAME_SPACE .= $maxletter;
373 } while ($ratio > 0.9);
374 #print "most symbols start with $NAME_SPACE\n";
378 &OutputDeprecatedIndex;
380 &OutputAnnotationGlossary;
382 open (TIMESTAMP, ">$ROOT_DIR/sgml.stamp")
383 || die "Can't create $ROOT_DIR/sgml.stamp: $!";
384 print (TIMESTAMP "timestamp");
388 #############################################################################
389 # Function : OutputObjectList
390 # Description : This outputs the alphabetical list of objects, in a columned
392 # FIXME: Currently this also outputs ancestor objects
393 # which may not actually be in this module.
395 #############################################################################
397 sub OutputObjectList {
400 # FIXME: use $OUTPUT_FORMAT
401 # my $old_object_index = "$SGML_OUTPUT_DIR/object_index.$OUTPUT_FORMAT";
402 my $old_object_index = "$SGML_OUTPUT_DIR/object_index.sgml";
403 my $new_object_index = "$SGML_OUTPUT_DIR/object_index.new";
405 open (OUTPUT, ">$new_object_index")
406 || die "Can't create $new_object_index: $!";
408 if (lc($OUTPUT_FORMAT) eq "xml") {
409 my $header = $doctype_header;
411 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE informaltable/;
412 print (OUTPUT "$header");
415 print (OUTPUT <<EOF);
416 <informaltable pgwide="1" frame="none">
417 <tgroup cols="$cols">
418 <colspec colwidth="1*"${empty_element_end}
419 <colspec colwidth="1*"${empty_element_end}
420 <colspec colwidth="1*"${empty_element_end}
426 foreach $object (sort (@Objects)) {
427 my $xref = &MakeXRef ($object);
428 if ($count % $cols == 0) { print (OUTPUT "<row>\n"); }
429 print (OUTPUT "<entry>$xref</entry>\n");
430 if ($count % $cols == ($cols - 1)) { print (OUTPUT "</row>\n"); }
434 # emit an empty row, since empty tables are invalid
435 print (OUTPUT "<row><entry> </entry></row>\n");
438 print (OUTPUT "</row>\n");
441 print (OUTPUT <<EOF);
442 </tbody></tgroup></informaltable>
446 &UpdateFileIfChanged ($old_object_index, $new_object_index, 0);
450 #############################################################################
451 # Function : OutputSGML
452 # Description : This collects the output for each section of the docs, and
453 # outputs each file when the end of the section is found.
454 # Arguments : $file - the $MODULE-sections.txt file which contains all of
455 # the functions/macros/structs etc. being documented, organised
456 # into sections and subsections.
457 #############################################################################
462 #print "Reading: $file\n";
464 || die "Can't open $file: $!";
467 my $book_bottom = "";
468 my $includes = (defined $DEFAULT_INCLUDES) ? $DEFAULT_INCLUDES : "";
469 my $section_includes = "";
477 my $signals_synop = "";
478 my $signals_desc = "";
480 my $child_args_synop = "";
481 my $style_args_synop = "";
483 my $child_args_desc = "";
484 my $style_args_desc = "";
487 my $implementations = "";
488 my $prerequisites = "";
490 my @file_objects = ();
494 # merge the source docs, in case there are no templates
495 &MergeSourceDocumentation;
501 } elsif (m/^<SECTION>/) {
509 } elsif (m/^<SUBSECTION\s*(.*)>/i) {
513 } elsif (m/^<SUBSECTION>/) {
515 } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
517 #print "Section: $title\n";
519 # We don't want warnings if object & class structs aren't used.
520 $DeclarationOutput{$title} = 1;
521 $DeclarationOutput{"${title}Class"} = 1;
522 $DeclarationOutput{"${title}Iface"} = 1;
523 $DeclarationOutput{"${title}Interface"} = 1;
525 } elsif (m/^<FILE>(.*)<\/FILE>/) {
527 if (! defined $templates{$filename}) {
528 if (&ReadTemplateFile ("$TMPL_DIR/$filename", 1)) {
529 &MergeSourceDocumentation;
530 $templates{$filename}=$.;
533 &LogWarning ($file, $., "Double <FILE>$filename</FILE> entry. ".
534 "Previous occurrence on line ".$templates{$filename}.".");
537 } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
539 $section_includes = $1;
541 if (defined $DEFAULT_INCLUDES) {
542 &LogWarning ($file, $., "Default <INCLUDE> being overridden by command line option.");
549 } elsif (m/^<\/SECTION>/) {
550 if($title eq "" && $filename eq "") {
551 &LogWarning ($file, $., "Section has no title and no file.");
553 # FIXME: one of those would be enough
557 if ($filename eq "") {
560 #print "End of section: $title\n";
562 $filename =~ s/\s/_/g;
564 my $section_id = $SourceSymbolDocs{"$TMPL_DIR/$filename:Section_Id"};
565 if (defined ($section_id) && $section_id !~ m/^\s*$/) {
566 # Do nothing. Use section_id as it is.
567 } elsif (&CheckIsObject ($title)) {
568 # GtkObjects use their class name as the ID.
569 $section_id = &CreateValidSGMLID ($title);
571 $section_id = &CreateValidSGMLID ("$MODULE-$title");
574 if ($num_symbols > 0) {
576 if (lc($OUTPUT_FORMAT) eq "xml") {
577 $book_bottom .= " <xi:include href=\"xml/$filename.xml\"/>\n";
579 $book_top.="<!ENTITY $section_id SYSTEM \"sgml/$filename.sgml\">\n";
580 $book_bottom .= " &$section_id;\n";
583 if (defined ($SourceSymbolDocs{"$TMPL_DIR/$filename:Include"})) {
584 if ($section_includes) {
585 &LogWarning ($file, $., "Section <INCLUDE> being overridden by inline comments.");
587 $section_includes = $SourceSymbolDocs{"$TMPL_DIR/$filename:Include"};
589 if ($section_includes eq "") {
590 $section_includes = $includes;
593 $signals_synop =~ s/^\n*//g;
594 $signals_synop =~ s/\n+$/\n/g;
595 if ($signals_synop ne '') {
596 $signals_synop = <<EOF;
597 <refsect1 id="$section_id.signals" role="signal_proto">
598 <title role="signal_proto.title">Signals</title>
600 ${signals_synop}</synopsis>
603 $signals_desc =~ s/^\n*//g;
604 $signals_desc =~ s/\n+$/\n/g;
605 $signals_desc =~ s/(\s|\n)+$//ms;
606 $signals_desc = <<EOF;
607 <refsect1 id="$section_id.signal-details" role="signals">
608 <title role="signals.title">Signal Details</title>
614 $args_synop =~ s/^\n*//g;
615 $args_synop =~ s/\n+$/\n/g;
616 if ($args_synop ne '') {
618 <refsect1 id="$section_id.properties" role="properties">
619 <title role="properties.title">Properties</title>
621 ${args_synop}</synopsis>
624 $args_desc =~ s/^\n*//g;
625 $args_desc =~ s/\n+$/\n/g;
626 $args_desc =~ s/(\s|\n)+$//ms;
628 <refsect1 id="$section_id.property-details" role="property_details">
629 <title role="property_details.title">Property Details</title>
635 $child_args_synop =~ s/^\n*//g;
636 $child_args_synop =~ s/\n+$/\n/g;
637 if ($child_args_synop ne '') {
638 $args_synop .= <<EOF;
639 <refsect1 id="$section_id.child-properties" role="child_properties">
640 <title role="child_properties.title">Child Properties</title>
642 ${child_args_synop}</synopsis>
645 $child_args_desc =~ s/^\n*//g;
646 $child_args_desc =~ s/\n+$/\n/g;
647 $child_args_desc =~ s/(\s|\n)+$//ms;
649 <refsect1 id="$section_id.child-property-details" role="child_property_details">
650 <title role="child_property_details.title">Child Property Details</title>
656 $style_args_synop =~ s/^\n*//g;
657 $style_args_synop =~ s/\n+$/\n/g;
658 if ($style_args_synop ne '') {
659 $args_synop .= <<EOF;
660 <refsect1 id="$section_id.style-properties" role="style_properties">
661 <title role="style_properties.title">Style Properties</title>
663 ${style_args_synop}</synopsis>
666 $style_args_desc =~ s/^\n*//g;
667 $style_args_desc =~ s/\n+$/\n/g;
668 $style_args_desc =~ s/(\s|\n)+$//ms;
670 <refsect1 id="$section_id.style-property-details" role="style_properties_details">
671 <title role="style_properties_details.title">Style Property Details</title>
677 $hierarchy =~ s/^\n*//g;
678 $hierarchy =~ s/\n+$/\n/g;
679 $hierarchy =~ s/(\s|\n)+$//ms;
680 if ($hierarchy ne "") {
682 <refsect1 id="$section_id.object-hierarchy" role="object_hierarchy">
683 <title role="object_hierarchy.title">Object Hierarchy</title>
689 $interfaces =~ s/^\n*//g;
690 $interfaces =~ s/\n+$/\n/g;
691 $interfaces =~ s/(\s|\n)+$//ms;
692 if ($interfaces ne "") {
694 <refsect1 id="$section_id.implemented-interfaces" role="impl_interfaces">
695 <title role="impl_interfaces.title">Implemented Interfaces</title>
701 $implementations =~ s/^\n*//g;
702 $implementations =~ s/\n+$/\n/g;
703 $implementations =~ s/(\s|\n)+$//ms;
704 if ($implementations ne "") {
705 $implementations = <<EOF;
706 <refsect1 id="$section_id.implementations" role="implementations">
707 <title role="implementations.title">Known Implementations</title>
713 $prerequisites =~ s/^\n*//g;
714 $prerequisites =~ s/\n+$/\n/g;
715 $prerequisites =~ s/(\s|\n)+$//ms;
716 if ($prerequisites ne "") {
717 $prerequisites = <<EOF;
718 <refsect1 id="$section_id.prerequisites" role="prerequisites">
719 <title role="prerequisites.title">Prerequisites</title>
725 $derived =~ s/^\n*//g;
726 $derived =~ s/\n+$/\n/g;
727 $derived =~ s/(\s|\n)+$//ms;
728 if ($derived ne "") {
730 <refsect1 id="$section_id.derived-interfaces" role="derived_interfaces">
731 <title role="derived_interfaces.title">Known Derived Interfaces</title>
737 $synopsis =~ s/^\n*//g;
738 $synopsis =~ s/\n+$/\n/g;
739 my $file_changed = &OutputSGMLFile ($filename, $title, $section_id,
741 \$synopsis, \$details,
742 \$signals_synop, \$signals_desc,
743 \$args_synop, \$args_desc,
744 \$hierarchy, \$interfaces,
746 \$prerequisites, \$derived,
755 $section_includes = "";
759 $child_args_synop = "";
760 $style_args_synop = "";
762 $child_args_desc = "";
763 $style_args_desc = "";
766 $implementations = "";
770 } elsif (m/^(\S+)/) {
772 #print " Symbol: $symbol\n";
774 # FIXME: check for duplicate entries
775 if (! defined $symbols{$symbol}) {
776 my $declaration = $Declarations{$symbol};
777 if (defined ($declaration)) {
778 # We don't want standard macros/functions of GtkObjects,
779 # or private declarations.
780 if ($subsection ne "Standard" && $subsection ne "Private") {
781 if (&CheckIsObject ($symbol)) {
782 push @file_objects, $symbol;
784 my ($synop, $desc) = &OutputDeclaration ($symbol,
786 my ($sig_synop, $sig_desc) = &GetSignals ($symbol);
787 my ($arg_synop, $child_arg_synop, $style_arg_synop,
788 $arg_desc, $child_arg_desc, $style_arg_desc) = &GetArgs ($symbol);
789 my $hier = &GetHierarchy ($symbol);
790 my $ifaces = &GetInterfaces ($symbol);
791 my $impls = &GetImplementations ($symbol);
792 my $prereqs = &GetPrerequisites ($symbol);
793 my $der = &GetDerived ($symbol);
796 $signals_synop .= $sig_synop;
797 $signals_desc .= $sig_desc;
798 $args_synop .= $arg_synop;
799 $child_args_synop .= $child_arg_synop;
800 $style_args_synop .= $style_arg_synop;
801 $args_desc .= $arg_desc;
802 $child_args_desc .= $child_arg_desc;
803 $style_args_desc .= $style_arg_desc;
805 $interfaces .= $ifaces;
806 $implementations .= $impls;
807 $prerequisites .= $prereqs;
811 # Note that the declaration has been output.
812 $DeclarationOutput{$symbol} = 1;
813 } elsif ($subsection ne "Standard" && $subsection ne "Private") {
814 $UndeclaredSymbols{$symbol} = 1;
815 &LogWarning ($file, $., "No declaration found for $symbol.");
818 $symbols{$symbol}=$.;
821 &LogWarning ($file, $., "Double symbol entry for $symbol. ".
822 "Previous occurrence on line ".$symbols{$symbol}.".");
828 &OutputMissingDocumentation;
829 &OutputUndeclaredSymbols;
831 if ($OUTPUT_ALL_SYMBOLS) {
834 if ($OUTPUT_SYMBOLS_WITHOUT_SINCE) {
835 &OutputSymbolsWithoutSince;
838 for $filename (split (' ', $EXPAND_CONTENT_FILES)) {
839 my $file_changed = &OutputExtraFile ($filename);
845 &OutputBook ($book_top, $book_bottom);
850 #############################################################################
851 # Function : OutputIndex
852 # Description : This writes an indexlist that can be included into the main-
853 # document into an <index> tag.
854 #############################################################################
857 my ($basename, $apiindexref ) = @_;
858 my %apiindex = %{$apiindexref};
859 my $old_index = "$SGML_OUTPUT_DIR/$basename.xml";
860 my $new_index = "$SGML_OUTPUT_DIR/$basename.new";
861 my $lastletter = " ";
866 open (OUTPUT, ">$new_index")
867 || die "Can't create $new_index";
869 my $header = $doctype_header;
870 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE indexdiv/;
872 print (OUTPUT "$header<indexdiv>\n");
874 #print "generate $basename index (".%apiindex." entries)\n";
876 # do a case insensitive sort while chopping off the prefix
878 sort { $$a{criteria} cmp $$b{criteria} }
879 map { my $x = uc($_); $x =~ s/^$NAME_SPACE\_?(.*)/$1/i; { criteria => $x, original => $_, short => $1 } }
882 $symbol = $$hash{original};
883 if(defined($$hash{short})) {
884 $short_symbol = $$hash{short};
886 $short_symbol = $symbol;
889 my $curletter = uc(substr($short_symbol,0,1));
890 my $id = $apiindex{$symbol};
892 #print " add symbol $symbol with $id to index in section $curletter\n";
894 if ($curletter ne $lastletter) {
895 $lastletter = $curletter;
898 print (OUTPUT "</indexdiv>\n");
900 print (OUTPUT "<indexdiv><title>$curletter</title>\n");
904 print (OUTPUT <<EOF);
905 <indexentry><primaryie linkends="$id"><link linkend="$id">$symbol</link></primaryie></indexentry>
910 print (OUTPUT "</indexdiv>\n");
912 print (OUTPUT "</indexdiv>\n");
915 &UpdateFileIfChanged ($old_index, $new_index, 0);
919 #############################################################################
920 # Function : OutputIndexFull
921 # Description : This writes the full api indexlist that can be included into the
922 # main document into an <index> tag.
923 #############################################################################
925 sub OutputIndexFull {
926 &OutputIndex ("api-index-full", \%IndexEntriesFull);
930 #############################################################################
931 # Function : OutputDeprecatedIndex
932 # Description : This writes the deprecated api indexlist that can be included
933 # into the main document into an <index> tag.
934 #############################################################################
936 sub OutputDeprecatedIndex {
937 &OutputIndex ("api-index-deprecated", \%IndexEntriesDeprecated);
941 #############################################################################
942 # Function : OutputSinceIndexes
943 # Description : This writes the 'since' api indexlists that can be included into
944 # the main document into an <index> tag.
945 #############################################################################
947 sub OutputSinceIndexes {
948 my @sinces = keys %{{ map { $_ => 1 } values %Since }};
950 foreach my $version (@sinces) {
951 #print "Since : [$version]\n";
952 # todo make filtered hash
953 #my %index = grep { $Since{$_} eq $version } %IndexEntriesSince;
954 my %index = map { $_ => $IndexEntriesSince{$_} } grep { $Since{$_} eq $version } keys %IndexEntriesSince;
956 &OutputIndex ("api-index-$version", \%index);
960 #############################################################################
961 # Function : OutputAnnotationGlossary
962 # Description : This writes a glossary of the used annotation terms into a
963 # separate glossary file that can be included into the main
965 #############################################################################
967 sub OutputAnnotationGlossary {
968 my $old_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.xml";
969 my $new_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.new";
970 my $lastletter = " ";
973 # TODO: if there are no annotations used return
974 return if (! keys(%AnnotationsUsed));
976 open (OUTPUT, ">$new_glossary")
977 || die "Can't create $new_glossary";
979 my $header = $doctype_header;
980 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE glossary/;
982 print (OUTPUT <<EOF);
984 <glossary id="annotation-glossary">
985 <title>Annotation Glossary</title>
988 foreach my $annotation (keys(%AnnotationsUsed)) {
989 my $def = $AnnotationDefinition{$annotation};
990 my $curletter = uc(substr($annotation,0,1));
992 if ($curletter ne $lastletter) {
993 $lastletter = $curletter;
996 print (OUTPUT "</glossdiv>\n");
998 print (OUTPUT "<glossdiv><title>$curletter</title>\n");
1001 print (OUTPUT <<EOF);
1003 <glossterm><anchor id="annotation-glossterm-$annotation"/>$annotation</glossterm>
1011 if ($divopen == 1) {
1012 print (OUTPUT "</glossdiv>\n");
1014 print (OUTPUT "</glossary>\n");
1017 &UpdateFileIfChanged ($old_glossary, $new_glossary, 0);
1020 #############################################################################
1021 # Function : ReadKnownSymbols
1022 # Description : This collects the names of non-private symbols from the
1023 # $MODULE-sections.txt file.
1024 # Arguments : $file - the $MODULE-sections.txt file which contains all of
1025 # the functions/macros/structs etc. being documented, organised
1026 # into sections and subsections.
1027 #############################################################################
1029 sub ReadKnownSymbols {
1032 my $subsection = "";
1034 #print "Reading: $file\n";
1036 || die "Can't open $file: $!";
1042 } elsif (m/^<SECTION>/) {
1045 } elsif (m/^<SUBSECTION\s*(.*)>/i) {
1048 } elsif (m/^<SUBSECTION>/) {
1051 } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
1054 } elsif (m/^<FILE>(.*)<\/FILE>/) {
1055 $KnownSymbols{"$TMPL_DIR/$1:Long_Description"} = 1;
1056 $KnownSymbols{"$TMPL_DIR/$1:Short_Description"} = 1;
1059 } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
1062 } elsif (m/^<\/SECTION>/) {
1065 } elsif (m/^(\S+)/) {
1068 if ($subsection ne "Standard" && $subsection ne "Private") {
1069 $KnownSymbols{$symbol} = 1;
1072 $KnownSymbols{$symbol} = 0;
1080 #############################################################################
1081 # Function : OutputDeclaration
1082 # Description : Returns the synopsis and detailed description DocBook
1083 # describing one function/macro etc.
1084 # Arguments : $symbol - the name of the function/macro begin described.
1085 # $declaration - the declaration of the function/macro.
1086 #############################################################################
1088 sub OutputDeclaration {
1089 my ($symbol, $declaration) = @_;
1091 my $type = $DeclarationTypes {$symbol};
1092 if ($type eq 'MACRO') {
1093 return &OutputMacro ($symbol, $declaration);
1094 } elsif ($type eq 'TYPEDEF') {
1095 return &OutputTypedef ($symbol, $declaration);
1096 } elsif ($type eq 'STRUCT') {
1097 return &OutputStruct ($symbol, $declaration);
1098 } elsif ($type eq 'ENUM') {
1099 return &OutputEnum ($symbol, $declaration);
1100 } elsif ($type eq 'UNION') {
1101 return &OutputUnion ($symbol, $declaration);
1102 } elsif ($type eq 'VARIABLE') {
1103 return &OutputVariable ($symbol, $declaration);
1105 } elsif ($type eq 'FUNCTION') {
1106 return &OutputFunction ($symbol, $declaration, $type);
1107 } elsif ($type eq 'USER_FUNCTION') {
1108 return &OutputFunction ($symbol, $declaration, $type);
1110 die "Unknown symbol type";
1115 #############################################################################
1116 # Function : OutputSymbolTraits
1117 # Description : Returns the Since and StabilityLevel paragraphs for a symbol.
1118 # Arguments : $symbol - the name of the function/macro begin described.
1119 #############################################################################
1121 sub OutputSymbolTraits {
1125 if (exists $Since{$symbol}) {
1126 $desc .= "<para role=\"since\">Since $Since{$symbol}</para>";
1128 if (exists $StabilityLevel{$symbol}) {
1129 $desc .= "<para role=\"stability\">Stability Level: $StabilityLevel{$symbol}</para>";
1134 #############################################################################
1135 # Function : Outpu{Symbol,Section}ExtraLinks
1136 # Description : Returns extralinks for the symbol (if enabled).
1137 # Arguments : $symbol - the name of the function/macro begin described.
1138 #############################################################################
1142 return undef unless defined $text;
1144 # Build a char to hex map
1147 $escapes{chr($_)} = sprintf("%%%02X", $_);
1150 # Default unsafe characters. RFC 2732 ^(uric - reserved)
1151 $text =~ s/([^A-Za-z0-9\-_.!~*'()])/$escapes{$1}/g;
1156 sub OutputSymbolExtraLinks {
1160 if (0) { # NEW FEATURE: needs configurability
1161 my $sstr = &uri_escape($symbol);
1162 my $mstr = &uri_escape($MODULE);
1164 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1165 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&symbol=$sstr">edit documentation</ulink>
1171 sub OutputSectionExtraLinks {
1172 my ($symbol,$docsymbol) = @_;
1175 if (0) { # NEW FEATURE: needs configurability
1176 my $sstr = &uri_escape($symbol);
1177 my $mstr = &uri_escape($MODULE);
1178 my $dsstr = &uri_escape($docsymbol);
1180 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1181 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&symbol=$dsstr">edit documentation</ulink>
1188 #############################################################################
1189 # Function : OutputMacro
1190 # Description : Returns the synopsis and detailed description of a macro.
1191 # Arguments : $symbol - the macro.
1192 # $declaration - the declaration of the macro.
1193 #############################################################################
1196 my ($symbol, $declaration) = @_;
1197 my $id = &CreateValidSGMLID ($symbol);
1198 my $condition = &MakeConditionDescription ($symbol);
1199 my $synop = &MakeReturnField("#define") . "<link linkend=\"$id\">$symbol</link>";
1205 if ($declaration =~ m/^\s*#\s*define(\s+)\w+(\([^\)]*\))/) {
1209 if (length ($symbol) < $SYMBOL_FIELD_WIDTH) {
1210 $synop .= (' ' x ($SYMBOL_FIELD_WIDTH - length ($symbol)));
1213 # Try to align all the lines of args correctly.
1214 $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH + $SYMBOL_FIELD_WIDTH + 1);
1215 my $args_padded = $args;
1216 $args_padded =~ s/ *\\\n */\n$pad/gm;
1217 $synop .= &CreateValidSGML ($args_padded);
1221 my $title = $symbol . ($args ? "()" : "");
1222 $desc = "<refsect2 id=\"$id\" role=\"macro\"$condition>\n<title>$title</title>\n";
1223 $desc .= MakeIndexterms($symbol, $id);
1225 $desc .= OutputSymbolExtraLinks($symbol);
1227 # Don't output the macro definition if is is a conditional macro or it
1228 # looks like a function, i.e. starts with "g_" or "_?gnome_", or it is
1229 # longer than 2 lines, otherwise we get lots of complicated macros like
1231 if (!defined ($DeclarationConditional{$symbol}) && ($symbol !~ m/^g_/)
1232 && ($symbol !~ m/^_?gnome_/) && (($declaration =~ tr/\n//) < 2)) {
1233 my $decl_out = &CreateValidSGML ($declaration);
1234 $desc .= "<programlisting>$decl_out</programlisting>\n";
1236 $desc .= "<programlisting>" . &MakeReturnField("#define") . "$symbol";
1237 # Align each line so that if should all line up OK.
1238 $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH - length ("#define "));
1239 $args =~ s/\n/\n$pad/gm;
1240 $desc .= &CreateValidSGML ($args);
1241 $desc .= "</programlisting>\n";
1244 $desc .= &MakeDeprecationNote($symbol);
1246 my $parameters = &OutputParamDescriptions ("MACRO", $symbol);
1247 my $parameters_output = 0;
1249 if (defined ($SymbolDocs{$symbol})) {
1250 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1252 # Try to insert the parameter table at the author's desired position.
1253 # Otherwise we need to tag it onto the end.
1254 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1255 $parameters_output = 1;
1257 $desc .= $symbol_docs;
1260 if ($parameters_output == 0) {
1261 $desc .= $parameters;
1264 $desc .= OutputSymbolTraits ($symbol);
1265 $desc .= "</refsect2>\n";
1266 return ($synop, $desc);
1270 #############################################################################
1271 # Function : OutputTypedef
1272 # Description : Returns the synopsis and detailed description of a typedef.
1273 # Arguments : $symbol - the typedef.
1274 # $declaration - the declaration of the typedef,
1275 # e.g. 'typedef unsigned int guint;'
1276 #############################################################################
1279 my ($symbol, $declaration) = @_;
1280 my $id = &CreateValidSGMLID ($symbol);
1281 my $condition = &MakeConditionDescription ($symbol);
1282 my $synop = &MakeReturnField("typedef") . "<link linkend=\"$id\">$symbol</link>;\n";
1283 my $desc = "<refsect2 id=\"$id\" role=\"typedef\"$condition>\n<title>$symbol</title>\n";
1285 $desc .= MakeIndexterms($symbol, $id);
1287 $desc .= OutputSymbolExtraLinks($symbol);
1289 if (!defined ($DeclarationConditional{$symbol})) {
1290 my $decl_out = &CreateValidSGML ($declaration);
1291 $desc .= "<programlisting>$decl_out</programlisting>\n";
1294 $desc .= &MakeDeprecationNote($symbol);
1296 if (defined ($SymbolDocs{$symbol})) {
1297 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1299 $desc .= OutputSymbolTraits ($symbol);
1300 $desc .= "</refsect2>\n";
1301 return ($synop, $desc);
1305 #############################################################################
1306 # Function : OutputStruct
1307 # Description : Returns the synopsis and detailed description of a struct.
1308 # We check if it is a widget struct, and if so we only output
1309 # parts of it that are noted as public fields.
1310 # We also use a different SGML ID for widget structs, since the
1311 # original ID is used for the entire RefEntry.
1312 # Arguments : $symbol - the struct.
1313 # $declaration - the declaration of the struct.
1314 #############################################################################
1317 my ($symbol, $declaration) = @_;
1319 my $is_widget_struct = 0;
1320 my $default_to_public = 1;
1321 if (&CheckIsObject ($symbol)) {
1322 #print "Found widget struct: $symbol\n";
1323 $is_widget_struct = 1;
1324 $default_to_public = 0;
1329 if ($is_widget_struct) {
1330 $id = &CreateValidSGMLID ($symbol . "_struct");
1331 $condition = &MakeConditionDescription ($symbol . "_struct");
1333 $id = &CreateValidSGMLID ($symbol);
1334 $condition = &MakeConditionDescription ($symbol);
1337 # Determine if it is a simple struct or it also has a typedef.
1338 my $has_typedef = 0;
1339 if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1346 # For structs with typedefs we just output the struct name.
1347 $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1348 $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>$symbol</title>\n";
1350 $synop = &MakeReturnField("struct") . "<link linkend=\"$id\">$symbol</link>;\n";
1351 $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>struct $symbol</title>\n";
1354 $desc .= MakeIndexterms($symbol, $id);
1356 $desc .= OutputSymbolExtraLinks($symbol);
1358 # Form a pretty-printed, private-data-removed form of the declaration
1361 if ($declaration =~ m/^\s*$/) {
1362 #print "Found opaque struct: $symbol\n";
1363 $decl_out = "typedef struct _$symbol $symbol;";
1364 } elsif ($declaration =~ m/^\s*struct\s+\w+\s*;\s*$/) {
1365 #print "Found opaque struct: $symbol\n";
1366 $decl_out = "struct $symbol;";
1368 my $public = $default_to_public;
1369 my $new_declaration = "";
1371 my $decl = $declaration;
1373 if ($decl =~ m/^\s*(typedef\s+)?struct\s*\w*\s*(?:\/\*.*\*\/)?\s*{(.*)}\s*\w*\s*;\s*$/s) {
1374 my $struct_contents = $2;
1376 foreach $decl_line (split (/\n/, $struct_contents)) {
1377 #print "Struct line: $decl_line\n";
1378 if ($decl_line =~ m%/\*\s*<\s*public\s*>\s*\*/%) {
1380 } elsif ($decl_line =~ m%/\*\s*<\s*(private|protected)\s*>\s*\*/%) {
1383 $new_declaration .= $decl_line . "\n";
1387 if ($new_declaration) {
1388 # Strip any blank lines off the ends.
1389 $new_declaration =~ s/^\s*\n//;
1390 $new_declaration =~ s/\n\s*$/\n/;
1393 $decl_out = "typedef struct {\n" . $new_declaration
1396 $decl_out = "struct $symbol {\n" . $new_declaration
1401 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1402 "Couldn't parse struct:\n$declaration");
1405 # If we couldn't parse the struct or it was all private, output an
1406 # empty struct declaration.
1407 if ($decl_out eq "") {
1409 $decl_out = "typedef struct _$symbol $symbol;";
1411 $decl_out = "struct $symbol;";
1416 $decl_out = &CreateValidSGML ($decl_out);
1417 $desc .= "<programlisting>$decl_out</programlisting>\n";
1419 $desc .= &MakeDeprecationNote($symbol);
1421 if (defined ($SymbolDocs{$symbol})) {
1422 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1425 # Create a table of fields and descriptions
1427 # FIXME: Inserting  's into the produced type declarations here would
1428 # improve the output in most situations ... except for function
1429 # members of structs!
1430 my @fields = ParseStructDeclaration($declaration, !$default_to_public,
1433 "<structfield id=\"$id.$_[0]\">$_[0]</structfield>";
1435 my $params = $SymbolParams{$symbol};
1437 # If no parameters are filled in, we don't generate the description
1438 # table, for backwards compatibility
1441 if (defined $params) {
1442 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1443 if ($params->[$i] =~ /\S/) {
1451 my %field_descrs = @$params;
1454 <variablelist role="struct">
1457 my $field_name = shift @fields;
1458 my $text = shift @fields;
1459 my $field_descr = $field_descrs{$field_name};
1460 my $param_annotations = "";
1462 $desc .= "<varlistentry><term>$text</term>\n";
1463 if (defined $field_descr) {
1464 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1465 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1466 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1468 $desc .= "<listitem><simpara /></listitem>\n";
1470 $desc .= "</varlistentry>\n";
1473 $desc .= "</variablelist>";
1475 $desc .= OutputSymbolTraits ($symbol);
1476 $desc .= "</refsect2>\n";
1477 return ($synop, $desc);
1481 #############################################################################
1482 # Function : OutputEnum
1483 # Description : Returns the synopsis and detailed description of a enum.
1484 # Arguments : $symbol - the enum.
1485 # $declaration - the declaration of the enum.
1486 #############################################################################
1489 my ($symbol, $declaration) = @_;
1490 my $id = &CreateValidSGMLID ($symbol);
1491 my $condition = &MakeConditionDescription ($symbol);
1492 my $synop = &MakeReturnField("enum") . "<link linkend=\"$id\">$symbol</link>;\n";
1493 my $desc = "<refsect2 id=\"$id\" role=\"enum\"$condition>\n<title>enum $symbol</title>\n";
1495 $desc .= MakeIndexterms($symbol, $id);
1497 $desc .= OutputSymbolExtraLinks($symbol);
1499 my $decl_out = &CreateValidSGML ($declaration);
1500 $desc .= "<programlisting>$decl_out</programlisting>\n";
1502 $desc .= &MakeDeprecationNote($symbol);
1504 if (defined ($SymbolDocs{$symbol})) {
1505 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1508 # Create a table of fields and descriptions
1510 my @members = ParseEnumDeclaration($declaration);
1511 my $params = $SymbolParams{$symbol};
1513 # If no parameters are filled in, we don't generate the description
1514 # table, for backwards compatibility
1517 if (defined $params) {
1518 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1519 if ($params->[$i] =~ /\S/) {
1527 my %member_descrs = @$params;
1530 <variablelist role="enum">
1532 for my $member_name (@members) {
1533 my $member_descr = $member_descrs{$member_name};
1534 my $param_annotations = "";
1536 $id = &CreateValidSGMLID ($member_name);
1537 $condition = &MakeConditionDescription ($member_name);
1538 $desc .= "<varlistentry id=\"$id\" role=\"constant\"$condition>\n<term><literal>$member_name</literal></term>\n";
1539 if (defined $member_descr) {
1540 ($member_descr,$param_annotations) = &ExpandAnnotation($symbol, $member_descr);
1541 $member_descr = &ExpandAbbreviations($symbol, $member_descr);
1542 $desc .= "<listitem><simpara>$member_descr$param_annotations</simpara></listitem>\n";
1544 $desc .= "<listitem></listitem>\n";
1546 $desc .= "</varlistentry>\n";
1549 $desc .= "</variablelist>";
1552 $desc .= OutputSymbolTraits ($symbol);
1553 $desc .= "</refsect2>\n";
1554 return ($synop, $desc);
1558 #############################################################################
1559 # Function : OutputUnion
1560 # Description : Returns the synopsis and detailed description of a union.
1561 # Arguments : $symbol - the union.
1562 # $declaration - the declaration of the union.
1563 #############################################################################
1566 my ($symbol, $declaration) = @_;
1567 my $id = &CreateValidSGMLID ($symbol);
1568 my $condition = &MakeConditionDescription ($symbol);
1569 my $synop = &MakeReturnField("union") . "<link linkend=\"$id\">$symbol</link>;\n";
1570 my $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>union $symbol</title>\n";
1572 $desc .= MakeIndexterms($symbol, $id);
1574 $desc .= OutputSymbolExtraLinks($symbol);
1576 my $decl_out = &CreateValidSGML ($declaration);
1577 $desc .= "<programlisting>$decl_out</programlisting>\n";
1579 $desc .= &MakeDeprecationNote($symbol);
1581 if (defined ($SymbolDocs{$symbol})) {
1582 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1584 $desc .= OutputSymbolTraits ($symbol);
1585 $desc .= "</refsect2>\n";
1586 return ($synop, $desc);
1590 #############################################################################
1591 # Function : OutputVariable
1592 # Description : Returns the synopsis and detailed description of a variable.
1593 # Arguments : $symbol - the extern'ed variable.
1594 # $declaration - the declaration of the variable.
1595 #############################################################################
1597 sub OutputVariable {
1598 my ($symbol, $declaration) = @_;
1599 my $id = &CreateValidSGMLID ($symbol);
1600 my $condition = &MakeConditionDescription ($symbol);
1603 if ($declaration =~ m/^\s*extern\s+((const\s+|unsigned\s+)*\w+)(\s+\*+|\*+|\s)(\s*)([A-Za-z]\w*)\s*;/) {
1604 my $mod = defined ($1) ? $1 : "";
1605 my $ptr = defined ($3) ? $3 : "";
1606 my $space = defined ($4) ? $4 : "";
1607 $synop = &MakeReturnField("extern") . "$mod$ptr$space<link linkend=\"$id\">$symbol</link>;\n";
1610 $synop = &MakeReturnField("extern") . "<link linkend=\"$id\">$symbol</link>;\n";
1613 my $desc = "<refsect2 id=\"$id\" role=\"variable\"$condition>\n<title>$symbol</title>\n";
1615 $desc .= MakeIndexterms($symbol, $id);
1617 $desc .= OutputSymbolExtraLinks($symbol);
1619 my $decl_out = &CreateValidSGML ($declaration);
1620 $desc .= "<programlisting>$decl_out</programlisting>\n";
1622 $desc .= &MakeDeprecationNote($symbol);
1624 if (defined ($SymbolDocs{$symbol})) {
1625 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1627 $desc .= OutputSymbolTraits ($symbol);
1628 $desc .= "</refsect2>\n";
1629 return ($synop, $desc);
1633 #############################################################################
1634 # Function : OutputFunction
1635 # Description : Returns the synopsis and detailed description of a function.
1636 # Arguments : $symbol - the function.
1637 # $declaration - the declaration of the function.
1638 #############################################################################
1640 sub OutputFunction {
1641 my ($symbol, $declaration, $symbol_type) = @_;
1642 my $id = &CreateValidSGMLID ($symbol);
1643 my $condition = &MakeConditionDescription ($symbol);
1645 # Take out the return type $1 $3 $4
1646 $declaration =~ s/<RETURNS>\s*((const\s+|G_CONST_RETURN\s+|unsigned\s+|struct\s+|enum\s+)*)(\w+)(\s*\**\s*(const|G_CONST_RETURN)?\s*\**\s*(restrict)?\s*)<\/RETURNS>\n//;
1647 my $type_modifier = defined($1) ? $1 : "";
1650 #print "$symbol pointer is $pointer\n";
1651 my $xref = &MakeXRef ($type);
1653 #if ($symbol_type eq 'USER_FUNCTION') {
1654 # $start = "typedef ";
1657 # We output const rather than G_CONST_RETURN.
1658 $type_modifier =~ s/G_CONST_RETURN/const/g;
1659 $pointer =~ s/G_CONST_RETURN/const/g;
1660 $pointer =~ s/^\s+/ /g;
1662 my $ret_type_len = length ($start) + length ($type_modifier)
1663 + length ($pointer) + length ($type);
1664 my $ret_type_output;
1666 if ($ret_type_len < $RETURN_TYPE_FIELD_WIDTH) {
1667 $ret_type_output = "$start$type_modifier$xref$pointer"
1668 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
1671 # $ret_type_output = "$start$type_modifier$xref$pointer\n"
1672 # . (' ' x $RETURN_TYPE_FIELD_WIDTH);
1674 $ret_type_output = "$start$type_modifier$xref$pointer ";
1675 $symbol_len = $ret_type_len + 1 - $RETURN_TYPE_FIELD_WIDTH;
1678 $symbol_len += length ($symbol);
1679 my $char1 = my $char2 = my $char3 = "";
1680 if ($symbol_type eq 'USER_FUNCTION') {
1687 my ($symbol_output, $symbol_desc_output);
1688 if ($symbol_len < $SYMBOL_FIELD_WIDTH) {
1689 $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3"
1690 . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1691 $symbol_desc_output = "$char1$char2$symbol$char3"
1692 . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1694 $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3\n"
1695 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1696 $symbol_desc_output = "$char1$char2$symbol$char3\n"
1697 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1700 my $synop = $ret_type_output . $symbol_output . '(';
1701 my $desc = "<refsect2 id=\"$id\" role=\"function\"$condition>\n<title>${symbol} ()</title>\n";
1703 $desc .= MakeIndexterms($symbol, $id);
1705 $desc .= OutputSymbolExtraLinks($symbol);
1707 $desc .= "<programlisting>${ret_type_output}$symbol_desc_output(";
1710 while ($declaration ne "") {
1711 #print "$declaration";
1713 if ($declaration =~ s/^[\s,]+//) {
1714 # skip whitespace and commas
1717 } elsif ($declaration =~ s/^void\s*[,\n]//) {
1721 } elsif ($declaration =~ s/^...\s*[,\n]//) {
1722 if ($param_num == 0) {
1727 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1730 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1734 # allow alphanumerics, '_', '[' & ']' in param names
1735 # Try to match a standard parameter (keep in sync with gtkdoc-mktmpl)
1737 } 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]//) {
1738 my $pre = defined($1) ? $1 : "";
1740 my $ptr = defined($3) ? $3 : "";
1741 my $name = defined($4) ? $4 : "";
1742 my $array = defined($5) ? $5 : "";
1748 if ($ptr && $ptr !~ m/\*$/) { $ptr .= " "; }
1750 #print "$symbol: '$pre' '$type' '$ptr' '$name' '$array'\n";
1752 if (($name eq "") && $pre =~ m/^((un)?signed .*)\s?/ ) {
1758 my $xref = &MakeXRef ($type);
1759 my $label = "$pre$xref $ptr$name$array";
1761 #print "$symbol: '$pre' '$type' '$ptr' '$name' '$array'\n";
1763 if ($param_num == 0) {
1768 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1771 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1775 # Try to match parameters which are functions (keep in sync with gtkdoc-mktmpl)
1776 # $1 $2 $3 $4 $5 $7 $8
1777 } 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]//) {
1778 my $mod1 = defined($1) ? $1 : "";
1779 if (defined($2)) { $mod1 .= $2; }
1782 my $mod2 = defined($5) ? $5 : "";
1785 my $func_params = defined($8) ? $8 : "";
1787 #if (!defined($type)) { print "## no type\n"; };
1788 #if (!defined($ptr1)) { print "## no ptr1\n"; };
1789 #if (!defined($func_ptr)) { print "## no func_ptr\n"; };
1790 #if (!defined($name)) { print "## no name\n"; };
1792 if ($ptr1 && $ptr1 !~ m/\*$/) { $ptr1 .= " "; }
1793 $func_ptr =~ s/\s+//g;
1794 my $xref = &MakeXRef ($type);
1795 my $label = "$mod1$xref$ptr1$mod2 ($func_ptr$name) ($func_params)";
1797 #print "Type: [$mod1][$xref][$ptr1][$mod2] ([$func_ptr][$name]) ($func_params)\n";
1798 if ($param_num == 0) {
1803 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1806 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1811 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1812 "Can't parse args for function $symbol: $declaration");
1818 $desc .= ");</programlisting>\n";
1820 $desc .= &MakeDeprecationNote($symbol);
1822 my $parameters = &OutputParamDescriptions ("FUNCTION", $symbol);
1823 my $parameters_output = 0;
1825 if (defined ($SymbolDocs{$symbol})) {
1826 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1828 # Try to insert the parameter table at the author's desired position.
1829 # Otherwise we need to tag it onto the end.
1830 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1831 $parameters_output = 1;
1833 $desc .= $symbol_docs;
1836 if ($parameters_output == 0) {
1837 $desc .= $parameters;
1840 $desc .= OutputSymbolTraits ($symbol);
1841 $desc .= "</refsect2>\n";
1842 return ($synop, $desc);
1846 #############################################################################
1847 # Function : OutputParamDescriptions
1848 # Description : Returns the DocBook output describing the parameters of a
1849 # function, macro or signal handler.
1850 # Arguments : $symbol_type - 'FUNCTION', 'MACRO' or 'SIGNAL'. Signal
1851 # handlers have an implicit user_data parameter last.
1852 # $symbol - the name of the function/macro being described.
1853 #############################################################################
1855 sub OutputParamDescriptions {
1856 my ($symbol_type, $symbol) = @_;
1858 if (defined ($SymbolParams{$symbol})) {
1860 my $params = $SymbolParams{$symbol};
1861 my $params_desc = "";
1863 for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
1864 my $param_name = $$params[$j];
1865 my $param_desc = $$params[$j + 1];
1866 my $param_annotations = "";
1868 ($param_desc,$param_annotations) = & ExpandAnnotation($symbol, $param_desc);
1869 $param_desc = &ExpandAbbreviations($symbol, $param_desc);
1870 if ($param_name eq "Returns") {
1871 $returns = "$param_desc$param_annotations";
1873 if ($param_name eq "Varargs") {
1874 $param_name = "...";
1876 $params_desc .= "<varlistentry><term><parameter>$param_name</parameter> :</term>\n<listitem><simpara>$param_desc$param_annotations</simpara></listitem></varlistentry>\n";
1880 # Signals have an implicit user_data parameter which we describe.
1881 if ($symbol_type eq "SIGNAL") {
1882 $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";
1885 # Start a table if we need one.
1886 if ($params_desc || $returns) {
1887 $output .= "<variablelist role=\"params\">\n";
1888 if ($params_desc ne "") {
1889 #$output .= "<varlistentry><term>Parameters:</term><listitem></listitem></varlistentry>\n";
1890 $output .= $params_desc;
1893 # Output the returns info last.
1895 $output .= "<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>$returns</simpara></listitem></varlistentry>\n";
1899 $output .= "</variablelist>";
1906 #############################################################################
1907 # Function : ParseStabilityLevel
1908 # Description : Parses a stability level and outputs a warning if it isn't
1910 # Arguments : $stability - the stability text.
1911 # $file, $line - context for error message
1912 # $message - description of where the level is from, to use in
1913 # any error message.
1914 # Returns : The parsed stability level string.
1915 #############################################################################
1917 sub ParseStabilityLevel {
1918 my ($stability, $file, $line, $message) = @_;
1920 $stability =~ s/^\s*//;
1921 $stability =~ s/\s*$//;
1922 if ($stability =~ m/^stable$/i) {
1923 $stability = "Stable";
1924 } elsif ($stability =~ m/^unstable$/i) {
1925 $stability = "Unstable";
1926 } elsif ($stability =~ m/^private$/i) {
1927 $stability = "Private";
1929 &LogWarning ($file, $line, "$message is $stability.".
1930 "It should be one of these: Stable, Unstable, or Private.");
1936 #############################################################################
1937 # Function : OutputSGMLFile
1938 # Description : Outputs the final DocBook file for one section.
1939 # Arguments : $file - the name of the file.
1940 # $title - the title from the $MODULE-sections.txt file, which
1941 # will be overridden by the title in the template file.
1942 # $section_id - the SGML id to use for the toplevel tag.
1943 # $includes - comma-separates list of include files added at top
1944 # of synopsis, with '<' '>' around them (if not already enclosed in "").
1945 # $synopsis - reference to the DocBook for the Synopsis part.
1946 # $details - reference to the DocBook for the Details part.
1947 # $signal_synop - reference to the DocBook for the Signal Synopsis part
1948 # $signal_desc - reference to the DocBook for the Signal Description part
1949 # $args_synop - reference to the DocBook for the Arg Synopsis part
1950 # $args_desc - reference to the DocBook for the Arg Description part
1951 # $hierarchy - reference to the DocBook for the Object Hierarchy part
1952 # $interfaces - reference to the DocBook for the Interfaces part
1953 # $implementations - reference to the DocBook for the Known Implementations part
1954 # $prerequisites - reference to the DocBook for the Prerequisites part
1955 # $derived - reference to the DocBook for the Derived Interfaces part
1956 # $file_objects - reference to an array of objects in this file
1957 #############################################################################
1959 sub OutputSGMLFile {
1960 my ($file, $title, $section_id, $includes, $synopsis, $details, $signals_synop, $signals_desc, $args_synop, $args_desc, $hierarchy, $interfaces, $implementations, $prerequisites, $derived, $file_objects) = @_;
1962 #print "Output sgml for file $file with title '$title'\n";
1964 # The edited title overrides the one from the sections file.
1965 my $new_title = $SymbolDocs{"$TMPL_DIR/$file:Title"};
1966 if (defined ($new_title) && $new_title !~ m/^\s*$/) {
1967 $title = $new_title;
1968 #print "Found title: $title\n";
1970 my $short_desc = $SymbolDocs{"$TMPL_DIR/$file:Short_Description"};
1971 if (!defined ($short_desc) || $short_desc =~ m/^\s*$/) {
1974 $short_desc = &ExpandAbbreviations("$title:Short_description",
1976 #print "Found short_desc: $short_desc";
1978 my $long_desc = $SymbolDocs{"$TMPL_DIR/$file:Long_Description"};
1979 if (!defined ($long_desc) || $long_desc =~ m/^\s*$/) {
1982 $long_desc = &ExpandAbbreviations("$title:Long_description",
1984 #print "Found long_desc: $long_desc";
1986 my $see_also = $SymbolDocs{"$TMPL_DIR/$file:See_Also"};
1987 if (!defined ($see_also) || $see_also =~ m%^\s*(<para>)?\s*(</para>)?\s*$%) {
1990 $see_also = &ExpandAbbreviations("$title:See_Also", $see_also);
1991 #print "Found see_also: $see_also";
1994 $see_also = "<refsect1 id=\"$section_id.see-also\">\n<title>See Also</title>\n$see_also\n</refsect1>\n";
1996 my $stability = $SymbolDocs{"$TMPL_DIR/$file:Stability_Level"};
1997 if (!defined ($stability) || $stability =~ m/^\s*$/) {
2000 $stability = &ParseStabilityLevel($stability, $file, $., "Section stability level");
2001 #print "Found stability: $stability";
2004 $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$stability, unless otherwise indicated\n</refsect1>\n";
2005 } elsif ($DEFAULT_STABILITY) {
2006 $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$DEFAULT_STABILITY, unless otherwise indicated\n</refsect1>\n";
2009 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
2011 my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
2014 my $include_output = "";
2016 foreach $include (split (/,/, $includes)) {
2017 if ($include =~ m/^\".+\"$/) {
2018 $include_output .= "#include ${include}\n";
2021 $include =~ s/^\s+|\s+$//gs;
2022 $include_output .= "#include <${include}>\n";
2025 if ($include_output ne '') {
2026 $include_output = "\n$include_output\n";
2029 my $extralinks = OutputSectionExtraLinks($title,"Section:$file");
2031 my $old_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT";
2032 my $new_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT.new";
2034 open (OUTPUT, ">$new_sgml_file")
2035 || die "Can't create $new_sgml_file: $!";
2037 my $object_anchors = "";
2038 foreach my $object (@$file_objects) {
2039 next if ($object eq $section_id);
2040 my $id = CreateValidSGMLID($object);
2041 #print "Debug: Adding anchor for $object\n";
2042 $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
2045 # We used to output this, but is messes up our UpdateFileIfChanged code
2046 # since it changes every day (and it is only used in the man pages):
2047 # "<refentry id="$section_id" revision="$mday $month $year">"
2049 if (lc($OUTPUT_FORMAT) eq "xml") {
2050 print OUTPUT $doctype_header;
2054 <refentry id="$section_id">
2056 <refentrytitle role="top_of_page" id="$section_id.top_of_page">$title</refentrytitle>
2057 <manvolnum>3</manvolnum>
2058 <refmiscinfo>\U$MODULE\E Library</refmiscinfo>
2061 <refname>$title</refname>
2062 <refpurpose>$short_desc</refpurpose>
2065 <refsynopsisdiv id="$section_id.synopsis" role="synopsis">
2066 <title role="synopsis.title">Synopsis</title>
2068 <synopsis>$include_output$${synopsis}</synopsis>
2070 $$hierarchy$$prerequisites$$derived$$interfaces$$implementations$$args_synop$$signals_synop
2071 <refsect1 id="$section_id.description" role="desc">
2072 <title role="desc.title">Description</title>
2073 $extralinks$long_desc
2075 <refsect1 id="$section_id.details" role="details">
2076 <title role="details.title">Details</title>
2079 $$args_desc$$signals_desc$see_also
2084 return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2088 #############################################################################
2089 # Function : OutputExtraFile
2090 # Description : Copies an "extra" DocBook file into the output directory,
2091 # expanding abbreviations
2092 # Arguments : $file - the source file.
2093 #############################################################################
2094 sub OutputExtraFile {
2099 ($basename = $file) =~ s!^.*/!!;
2101 my $old_sgml_file = "$SGML_OUTPUT_DIR/$basename";
2102 my $new_sgml_file = "$SGML_OUTPUT_DIR/$basename.new";
2106 open(EXTRA_FILE, "<$file") || die "Can't open $file";
2110 $contents = <EXTRA_FILE>;
2113 open (OUTPUT, ">$new_sgml_file")
2114 || die "Can't create $new_sgml_file: $!";
2116 print OUTPUT &ExpandAbbreviations ("$basename file", $contents);
2119 return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2121 #############################################################################
2122 # Function : OutputBook
2123 # Description : Outputs the SGML entities that need to be included into the
2124 # main SGML file for the module.
2125 # Arguments : $book_top - the declarations of the entities, which are added
2126 # at the top of the main SGML file.
2127 # $book_bottom - the references to the entities, which are
2128 # added in the main SGML file at the desired position.
2129 #############################################################################
2132 my ($book_top, $book_bottom) = @_;
2134 my $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top";
2135 my $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top.new";
2137 open (OUTPUT, ">$new_file")
2138 || die "Can't create $new_file: $!";
2139 print OUTPUT $book_top;
2142 &UpdateFileIfChanged ($old_file, $new_file, 0);
2145 $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom";
2146 $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom.new";
2148 open (OUTPUT, ">$new_file")
2149 || die "Can't create $new_file: $!";
2150 print OUTPUT $book_bottom;
2153 &UpdateFileIfChanged ($old_file, $new_file, 0);
2156 # If the main SGML file hasn't been created yet, we create it here.
2157 # The user can tweak it later.
2158 if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
2159 open (OUTPUT, ">$MAIN_SGML_FILE")
2160 || die "Can't create $MAIN_SGML_FILE: $!";
2162 if (lc($OUTPUT_FORMAT) eq "xml") {
2164 <?xml version="1.0"?>
2165 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
2166 "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
2168 <!ENTITY % local.common.attrib "xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'">
2174 <!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
2183 <title>$MODULE Reference Manual</title>
2185 for $MODULE [VERSION].
2186 The latest version of this documentation can be found on-line at
2187 <ulink role="online-location" url="http://[SERVER]/$MODULE/index.html">http://[SERVER]/$MODULE/</ulink>.
2192 <title>[Insert title here]</title>
2196 if (-e $OBJECT_TREE_FILE) {
2198 <chapter id="object-tree">
2199 <title>Object Hierarchy</title>
2200 <xi:include href="xml/tree_index.sgml"/>
2206 <index id="api-index-full">
2207 <title>API Index</title>
2208 <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
2211 <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
2220 #############################################################################
2221 # Function : CreateValidSGMLID
2222 # Description : Creates a valid SGML 'id' from the given string.
2223 # According to http://www.w3.org/TR/html4/types.html#type-id
2224 # "ID and NAME tokens must begin with a letter ([A-Za-z]) and
2225 # may be followed by any number of letters, digits ([0-9]),
2226 # hyphens ("-"), underscores ("_"), colons (":"), and
2229 # NOTE: SGML ids are case-insensitive, so we have a few special
2230 # cases to avoid clashes of ids.
2231 # Arguments : $id - the string to be converted into a valid SGML id.
2232 #############################################################################
2234 sub CreateValidSGMLID {
2237 # Special case, '_' would end up as '' so we use 'gettext-macro' instead.
2238 if ($id eq "_") { return "gettext-macro"; }
2246 # Append ":CAPS" to all all-caps identifiers
2247 if ($id !~ /[a-z]/ && $id !~ /-CAPS$/) { $id .= ":CAPS" };
2253 #############################################################################
2254 # Function : CreateValidSGML
2255 # Description : This turns any chars which are used in SGML into entities,
2256 # e.g. '<' into '<'
2257 # Arguments : $text - the text to turn into proper SGML.
2258 #############################################################################
2260 sub CreateValidSGML {
2262 $text =~ s/&/&/g; # Do this first, or the others get messed up.
2263 $text =~ s/</</g;
2264 $text =~ s/>/>/g;
2265 # browers render single tabs inconsistently
2266 $text =~ s/([^\s])\t([^\s])/$1 $2/g;
2270 #############################################################################
2271 # Function : ConvertSGMLChars
2272 # Description : This is used for text in source code comment blocks, to turn
2273 # chars which are used in SGML into entities, e.g. '<' into
2274 # '<'. Depending on $SGML_MODE, this is done
2275 # unconditionally or only if the character doesn't seem to be
2276 # part of an SGML construct (tag or entity reference).
2277 # Arguments : $text - the text to turn into proper SGML.
2278 #############################################################################
2280 sub ConvertSGMLChars {
2281 my ($symbol, $text) = @_;
2284 # For the SGML mode only convert to entities outside CDATA sections.
2285 return &ModifyXMLElements ($text, $symbol,
2286 "<!\\[CDATA\\[|<programlisting[^>]*>",
2287 \&ConvertSGMLCharsEndTag,
2288 \&ConvertSGMLCharsCallback);
2290 # For the simple non-sgml mode, convert to entities everywhere.
2291 $text =~ s/&/&/g; # Do this first, or the others get messed up.
2292 $text =~ s/</</g;
2293 $text =~ s/>/>/g;
2299 sub ConvertSGMLCharsEndTag {
2300 if ($_[0] eq "<!\[CDATA\[") {
2303 return "</programlisting>";
2307 sub ConvertSGMLCharsCallback {
2308 my ($text, $symbol, $tag) = @_;
2310 if ($tag =~ m/^<programlisting/) {
2311 # We can handle <programlisting> specially here.
2312 return &ModifyXMLElements ($text, $symbol,
2314 \&ConvertSGMLCharsEndTag,
2315 \&ConvertSGMLCharsCallback2);
2316 } elsif ($tag eq "") {
2317 # If we're not in CDATA convert to entities.
2318 $text =~ s/&(?![a-zA-Z#]+;)/&/g; # Do this first, or the others get messed up.
2319 $text =~ s/<(?![a-zA-Z\/!])/</g;
2320 $text =~ s/(?<![a-zA-Z0-9"'\/-])>/>/g;
2322 # Handle "#include <xxxxx>"
2323 $text =~ s/#include(\s+)<([^>]+)>/#include$1<$2>/g;
2329 sub ConvertSGMLCharsCallback2 {
2330 my ($text, $symbol, $tag) = @_;
2332 # If we're not in CDATA convert to entities.
2333 # We could handle <programlisting> differently, though I'm not sure it helps.
2335 # replace only if its not a tag
2336 $text =~ s/&(?![a-zA-Z#]+;)/&/g; # Do this first, or the others get messed up.
2337 $text =~ s/<(?![a-zA-Z\/!])/</g;
2338 $text =~ s/(?<![a-zA-Z0-9"'\/-])>/>/g;
2340 # Handle "#include <xxxxx>"
2341 $text =~ s/#include(\s+)<([^>]+)>/#include$1<$2>/g;
2347 #############################################################################
2348 # Function : ExpandAnnotation
2349 # Description : This turns annotations into acrony tags.
2350 # Arguments : $symbol - the symbol being documented, for error messages.
2351 # $text - the text to expand.
2352 #############################################################################
2353 sub ExpandAnnotation {
2354 my ($symbol, $param_desc) = @_;
2355 my $param_annotations = "";
2357 if ($param_desc =~ m%\s*\((.*)\):%) {
2360 my $annotation_extra = "";
2363 @annotations = split(/\)\s*\(/,$1);
2364 foreach $annotation (@annotations) {
2365 # need to search for the longest key-match in %AnnotationDefinition
2367 my $match_annotation="";
2369 foreach $annotationdef (keys %AnnotationDefinition) {
2370 if ($annotation =~ m/^$annotationdef/) {
2371 if (length($annotationdef)>$match_length) {
2372 $match_length=length($annotationdef);
2373 $match_annotation=$annotationdef;
2377 if ($match_annotation ne "") {
2378 if ($annotation =~ m%$match_annotation\s+(.*)%) {
2379 $annotation_extra = " $1";
2381 $AnnotationsUsed{$match_annotation} = 1;
2382 $param_annotations .= "<acronym>$match_annotation</acronym>$annotation_extra. ";
2385 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2386 "unknown annotation \"$annotation\" in documentation for $symbol.");
2387 $param_annotations=$annotation;
2391 $param_desc =~ m/^(.*)\.*\s*$/;
2392 $param_desc = "$1. ";
2394 return ($param_desc, $param_annotations);
2397 #############################################################################
2398 # Function : ExpandAbbreviations
2399 # Description : This turns the abbreviations function(), macro(), @param,
2400 # %constant, and #symbol into appropriate DocBook markup.
2401 # CDATA sections and <programlisting> parts are skipped.
2402 # Arguments : $symbol - the symbol being documented, for error messages.
2403 # $text - the text to expand.
2404 #############################################################################
2406 sub ExpandAbbreviations {
2407 my ($symbol, $text) = @_;
2409 # Convert "|[" and "]|" into the start and end of program listing examples.
2410 $text =~ s%\|\[%<informalexample><programlisting>%g;
2411 $text =~ s%\]\|%</programlisting></informalexample>%g;
2412 # TODO: check for a xml comment after |[ and pick the language attribute from
2415 # keep CDATA unmodified, preserve ulink tags (ideally we preseve all tags
2417 return &ModifyXMLElements ($text, $symbol,
2418 "<!\\[CDATA\\[|<ulink[^>]*>|<programlisting[^>]*>|<!DOCTYPE",
2419 \&ExpandAbbreviationsEndTag,
2420 \&ExpandAbbreviationsCallback);
2424 # Returns the end tag corresponding to the given start tag.
2425 sub ExpandAbbreviationsEndTag {
2426 my ($start_tag) = @_;
2428 if ($start_tag eq "<!\[CDATA\[") {
2430 } elsif ($start_tag eq "<!DOCTYPE") {
2432 } elsif ($start_tag =~ m/<(\w+)/) {
2437 # Called inside or outside each CDATA or <programlisting> section.
2438 sub ExpandAbbreviationsCallback {
2439 my ($text, $symbol, $tag) = @_;
2441 if ($tag =~ m/^<programlisting/) {
2442 # Handle any embedded CDATA sections.
2443 return &ModifyXMLElements ($text, $symbol,
2445 \&ExpandAbbreviationsEndTag,
2446 \&ExpandAbbreviationsCallback2);
2447 } elsif ($tag eq "") {
2448 # We are outside any CDATA or <programlisting> sections, so we expand
2449 # any gtk-doc abbreviations.
2451 # Convert 'function()' or 'macro()'.
2452 $text =~ s/(\w+)\s*\(\)/&MakeXRef($1, &tagify($1 . "()", "function"));/eg;
2454 # Convert '@param', but not '\@param'.
2455 $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)/$1<parameter>$2<\/parameter>/g;
2456 $text =~ s/\\\@/\@/g;
2458 # Convert '%constant', but not '\%constant'.
2459 # Also allow negative numbers, e.g. %-1.
2460 $text =~ s/(\A|[^\\])\%(-?\w+)/$1.&MakeXRef($2, &tagify($2, "literal"));/eg;
2461 $text =~ s/\\\%/\%/g;
2463 # Convert '#symbol', but not '\#symbol'.
2464 $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)/$1.&MakeHashXRef($2, "type");/eg;
2468 # FIXME: should we skip urls that are already tagged? (e.g. <literal>http://...</literal>)
2469 # this is apparently also called for markup and not just for plain text
2471 #$text =~ s%(http|https|ftp)://(.*?)((?:\s|,|\)|\]|\<|\.\s))%<ulink url="$1://$2">$2</ulink>$3%g;
2477 # This is called inside a <programlisting>
2478 sub ExpandAbbreviationsCallback2 {
2479 my ($text, $symbol, $tag) = @_;
2482 # We are inside a <programlisting> but outside any CDATA sections,
2483 # so we expand any gtk-doc abbreviations.
2484 # FIXME: why is this different from &ExpandAbbreviationsCallback(),
2485 # why not just call it
2486 $text =~ s/#(\w+)/&MakeHashXRef($1, "");/eg;
2493 my ($symbol, $tag) = @_;;
2496 # Check for things like '#include', '#define', and skip them.
2497 if ($PreProcessorDirectives{$symbol}) {
2501 # Get rid of any special '-struct' suffix.
2502 $text =~ s/-struct$//;
2504 # If the symbol is in the form "Object::signal", then change the symbol to
2505 # "Object-signal" and use "signal" as the text.
2506 if ($symbol =~ s/::/-/) {
2510 # If the symbol is in the form "Object:property", then change the symbol to
2511 # "Object--property" and use "property" as the text.
2512 if ($symbol =~ s/:/--/) {
2517 $text = tagify ($text, $tag);
2520 return &MakeXRef($symbol, $text);
2524 #############################################################################
2525 # Function : ModifyXMLElements
2526 # Description : Looks for given XML element tags within the text, and calls
2527 # the callback on pieces of text inside & outside those elements.
2528 # Used for special handling of text inside things like CDATA
2529 # and <programlisting>.
2530 # Arguments : $text - the text.
2531 # $symbol - the symbol currently being documented (only used for
2533 # $start_tag_regexp - the regular expression to match start tags.
2534 # e.g. "<!\\[CDATA\\[|<programlisting[^>]*>" to match
2535 # CDATA sections or programlisting elements.
2536 # $end_tag_func - function which is passed the matched start tag
2537 # and should return the appropriate end tag string.
2538 # $callback - callback called with each part of the text. It is
2539 # called with a piece of text, the symbol being
2540 # documented, and the matched start tag or "" if the text
2541 # is outside the XML elements being matched.
2542 #############################################################################
2543 sub ModifyXMLElements {
2544 my ($text, $symbol, $start_tag_regexp, $end_tag_func, $callback) = @_;
2545 my ($before_tag, $start_tag, $end_tag_regexp, $end_tag);
2548 while ($text =~ m/$start_tag_regexp/s) {
2549 $before_tag = $`; # Prematch for last successful match string
2550 $start_tag = $&; # Last successful match
2551 $text = $'; # Postmatch for last successful match string
2553 $result .= &$callback ($before_tag, $symbol, "");
2554 $result .= $start_tag;
2556 # get the mathing end-tag for current tag
2557 $end_tag_regexp = &$end_tag_func ($start_tag);
2559 if ($text =~ m/$end_tag_regexp/s) {
2564 $result .= &$callback ($before_tag, $symbol, $start_tag);
2565 $result .= $end_tag;
2567 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2568 "Can't find tag end: $end_tag_regexp in docs for: $symbol.");
2569 # Just assume it is all inside the tag.
2570 $result .= &$callback ($text, $symbol, $start_tag);
2575 # Handle any remaining text outside the tags.
2576 $result .= &$callback ($text, $symbol, "");
2585 # Adds a tag around some text.
2586 # e.g tagify("Text", "literal") => "<literal>Text</literal>".
2588 my ($text, $elem) = @_;
2589 return "<" . $elem . ">" . $text . "</" . $elem . ">";
2593 #############################################################################
2594 # Function : MakeXRef
2595 # Description : This returns a cross-reference link to the given symbol.
2596 # Though it doesn't try to do this for a few standard C types
2597 # that it knows won't be in the documentation.
2598 # Arguments : $symbol - the symbol to try to create a XRef to.
2599 # $text - text text to put inside the XRef, defaults to $symbol
2600 #############################################################################
2603 my ($symbol, $text) = ($_[0], $_[1]);
2604 if (!defined($text)) {
2607 # Get rid of special '-struct' suffix.
2608 $text =~ s/-struct$//;
2611 #print "Getting type link for $symbol -> $text\n";
2613 my $symbol_id = &CreateValidSGMLID ($symbol);
2614 return "<link linkend=\"$symbol_id\">$text</link>";
2618 #############################################################################
2619 # Function : MakeIndexterms
2620 # Description : This returns a indexterm elements for the given symbol
2621 # Arguments : $symbol - the symbol to create indexterms for
2622 #############################################################################
2624 sub MakeIndexterms {
2625 my ($symbol, $id) = @_;
2629 # make the index useful, by ommiting the namespace when sorting
2630 if ($NAME_SPACE ne "") {
2631 if ($symbol =~ m/^$NAME_SPACE\_?(.*)/i) {
2632 $sortas=" sortas=\"$1\"";
2636 if (exists $Deprecated{$symbol}) {
2637 $terms .= "<indexterm zone=\"$id\" role=\"deprecated\"><primary$sortas>$symbol</primary></indexterm>";
2638 $IndexEntriesDeprecated{$symbol}=$id;
2639 $IndexEntriesFull{$symbol}=$id;
2641 if (exists $Since{$symbol}) {
2642 my $since = $Since{$symbol};
2646 $terms .= "<indexterm zone=\"$id\" role=\"$since\"><primary$sortas>$symbol</primary></indexterm>";
2648 $IndexEntriesSince{$symbol}=$id;
2649 $IndexEntriesFull{$symbol}=$id;
2652 $terms .= "<indexterm zone=\"$id\"><primary$sortas>$symbol</primary></indexterm>";
2653 $IndexEntriesFull{$symbol}=$id;
2659 #############################################################################
2660 # Function : MakeDeprecationNote
2661 # Description : This returns a deprecation warning for the given symbol.
2662 # Arguments : $symbol - the symbol to try to create a warning for.
2663 #############################################################################
2665 sub MakeDeprecationNote {
2666 my ($symbol) = $_[0];
2669 if (exists $Deprecated{$symbol}) {
2670 $desc .= "<warning>";
2672 if ($Deprecated{$symbol} =~ /^\s*([0-9\.]+)\s*:/) {
2673 $desc .= "<para><literal>$symbol</literal> has been deprecated since version $1 and should not be used in newly-written code.";
2675 $desc .= "<para><literal>$symbol</literal> is deprecated and should not be used in newly-written code.";
2677 if ($Deprecated{$symbol} ne "") {
2678 $note = &ExpandAbbreviations($symbol, $Deprecated{$symbol});
2679 $note =~ s/^\s*([0-9\.]+)\s*:\s*//;
2682 $note =~ s%\n{2,}%\n</para>\n<para>\n%g;
2683 $desc .= " " . $note;
2685 $desc .= "</para></warning>\n";
2690 #############################################################################
2691 # Function : MakeConditionDescription
2692 # Description : This returns a sumary of conditions for the given symbol.
2693 # Arguments : $symbol - the symbol to try to create the sumary.
2694 #############################################################################
2696 sub MakeConditionDescription {
2697 my ($symbol) = $_[0];
2700 if (exists $Deprecated{$symbol}) {
2705 if ($Deprecated{$symbol} =~ /^\s*(.*?)\s*$/) {
2706 $desc .= "deprecated:$1";
2708 $desc .= "deprecated";
2712 if (exists $Since{$symbol}) {
2717 if ($Since{$symbol} =~ /^\s*(.*?)\s*$/) {
2718 $desc .= "since:$1";
2724 if (exists $StabilityLevel{$symbol}) {
2728 $desc .= "stability:".$StabilityLevel{$symbol};
2732 $desc=" condition=\"".$desc."\"";
2733 #print "condition for '$symbol' = '$desc'\n";
2738 #############################################################################
2739 # Function : GetHierarchy
2740 # Description : Returns the DocBook output describing the ancestors and
2741 # immediate children of a GObject subclass. It uses the
2742 # global @Objects and @ObjectLevels arrays to walk the tree.
2743 # Arguments : $object - the GtkObject subclass.
2744 #############################################################################
2749 # Find object in the objects array.
2755 for ($i = 0; $i < @Objects; $i++) {
2757 if ($ObjectLevels[$i] <= $level) {
2760 elsif ($ObjectLevels[$i] == $level + 1) {
2761 push (@children, $Objects[$i]);
2764 elsif ($Objects[$i] eq $object) {
2767 $level = $ObjectLevels[$i];
2774 # Walk up the hierarchy, pushing ancestors onto the ancestors array.
2776 push (@ancestors, $object);
2777 #print "Level: $level\n";
2778 while ($level > 1) {
2780 if ($ObjectLevels[$j] < $level) {
2781 push (@ancestors, $Objects[$j]);
2782 $level = $ObjectLevels[$j];
2783 #print "Level: $level\n";
2787 # Output the ancestors list, indented and with links.
2788 my $hierarchy = "<synopsis>\n";
2790 for ($i = $#ancestors; $i >= 0; $i--) {
2792 # Don't add a link to the current widget, i.e. when i == 0.
2794 my $ancestor_id = &CreateValidSGMLID ($ancestors[$i]);
2795 $link_text = "<link linkend=\"$ancestor_id\">$ancestors[$i]</link>";
2797 $link_text = "$ancestors[$i]";
2800 $hierarchy .= " $link_text\n";
2802 # $hierarchy .= ' ' x ($level * 6 - 3) . "|\n";
2803 $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
2807 for ($i = 0; $i <= $#children; $i++) {
2808 my $id = &CreateValidSGMLID ($children[$i]);
2809 my $link_text = "<link linkend=\"$id\">$children[$i]</link>";
2810 $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
2812 $hierarchy .= "</synopsis>\n";
2818 #############################################################################
2819 # Function : GetInterfaces
2820 # Description : Returns the DocBook output describing the interfaces
2821 # implemented by a class. It uses the global %Interfaces hash.
2822 # Arguments : $object - the GtkObject subclass.
2823 #############################################################################
2830 # Find object in the objects array.
2831 if (exists($Interfaces{$object})) {
2832 my @ifaces = split(' ', $Interfaces{$object});
2837 for ($i = 0; $i <= $#ifaces; $i++) {
2838 my $id = &CreateValidSGMLID ($ifaces[$i]);
2839 $text .= " <link linkend=\"$id\">$ifaces[$i]</link>";
2840 if ($i < $#ifaces - 1) {
2843 elsif ($i < $#ifaces) {
2858 #############################################################################
2859 # Function : GetImplementations
2860 # Description : Returns the DocBook output describing the implementations
2861 # of an interface. It uses the global %Interfaces hash.
2862 # Arguments : $object - the GtkObject subclass.
2863 #############################################################################
2865 sub GetImplementations {
2870 foreach my $key (keys %Interfaces) {
2871 if ($Interfaces{$key} =~ /\b$object\b/) {
2872 push (@impls, $key);
2878 $object is implemented by
2880 for ($i = 0; $i <= $#impls; $i++) {
2881 my $id = &CreateValidSGMLID ($impls[$i]);
2882 $text .= " <link linkend=\"$id\">$impls[$i]</link>";
2883 if ($i < $#impls - 1) {
2886 elsif ($i < $#impls) {
2901 #############################################################################
2902 # Function : GetPrerequisites
2903 # Description : Returns the DocBook output describing the prerequisites
2904 # of an interface. It uses the global %Prerequisites hash.
2905 # Arguments : $iface - the interface.
2906 #############################################################################
2908 sub GetPrerequisites {
2913 if (exists($Prerequisites{$iface})) {
2918 my @prereqs = split(' ', $Prerequisites{$iface});
2919 for ($i = 0; $i <= $#prereqs; $i++) {
2920 my $id = &CreateValidSGMLID ($prereqs[$i]);
2921 $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
2922 if ($i < $#prereqs - 1) {
2925 elsif ($i < $#prereqs) {
2939 #############################################################################
2940 # Function : GetDerived
2941 # Description : Returns the DocBook output describing the derived interfaces
2942 # of an interface. It uses the global %Prerequisites hash.
2943 # Arguments : $iface - the interface.
2944 #############################################################################
2952 foreach my $key (keys %Prerequisites) {
2953 if ($Prerequisites{$key} =~ /\b$iface\b/) {
2954 push (@derived, $key);
2957 if ($#derived >= 0) {
2960 $iface is required by
2962 for ($i = 0; $i <= $#derived; $i++) {
2963 my $id = &CreateValidSGMLID ($derived[$i]);
2964 $text .= " <link linkend=\"$id\">$derived[$i]</link>";
2965 if ($i < $#derived - 1) {
2968 elsif ($i < $#derived) {
2983 #############################################################################
2984 # Function : GetSignals
2985 # Description : Returns the synopsis and detailed description DocBook output
2986 # for the signal handlers of a given GtkObject subclass.
2987 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
2988 #############################################################################
2996 for ($i = 0; $i <= $#SignalObjects; $i++) {
2997 if ($SignalObjects[$i] eq $object) {
2998 #print "Found signal: $SignalNames[$i]\n";
2999 my $name = $SignalNames[$i];
3000 my $symbol = "${object}::${name}";
3001 my $id = &CreateValidSGMLID ("$object-$name");
3003 my $pad = ' ' x (46 - length($name));
3004 $synop .= " "<link linkend=\"$id\">$name</link>"$pad ";
3006 $desc .= "<refsect2 id=\"$id\" role=\"signal\"><title>The <literal>"$name"</literal> signal</title>\n";
3007 $desc .= MakeIndexterms($symbol, $id);
3009 $desc .= OutputSymbolExtraLinks($symbol);
3011 $desc .= "<programlisting>";
3013 $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
3014 my $type_modifier = defined($1) ? $1 : "";
3017 my $xref = &MakeXRef ($type);
3019 my $ret_type_len = length ($type_modifier) + length ($pointer)
3021 my $ret_type_output = "$type_modifier$xref$pointer"
3022 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
3024 $desc .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
3026 my $sourceparams = $SourceSymbolParams{$symbol};
3027 my @params = split ("\n", $SignalPrototypes[$i]);
3030 my $type_len = length("gpointer");
3031 my $name_len = length("user_data");
3032 # do two passes, the first one is to calculate padding
3033 for ($l = 0; $l < 2; $l++) {
3034 for ($j = 0; $j <= $#params; $j++) {
3035 # allow alphanumerics, '_', '[' & ']' in param names
3036 if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
3039 if (defined($sourceparams)) {
3040 $name = $$sourceparams[$PARAM_FIELD_COUNT * $j];
3045 if (!defined($name)) {
3049 if (length($type) + length($pointer) > $type_len) {
3050 $type_len = length($type) + length($pointer);
3052 if (length($name) > $name_len) {
3053 $name_len = length($name);
3057 $xref = &MakeXRef ($type);
3058 $pad = ' ' x ($type_len - length($type) - length($pointer));
3059 $desc .= "$xref$pad $pointer$name,\n";
3060 $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
3063 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3064 "Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]");
3068 $xref = &MakeXRef ("gpointer");
3069 $pad = ' ' x ($type_len - length("gpointer"));
3070 $desc .= "$xref$pad user_data)";
3072 my $flags = $SignalFlags[$i];
3073 my $flags_string = "";
3075 if (defined ($flags)) {
3076 if ($flags =~ m/f/) {
3077 $flags_string = "Run First";
3079 elsif ($flags =~ m/l/) {
3080 $flags_string = "Run Last";
3082 elsif ($flags =~ m/c/) {
3083 $flags_string = "Cleanup";
3085 if ($flags =~ m/r/) {
3086 if ($flags_string) { $flags_string .= " / "; }
3087 $flags_string .= "No Recursion";
3089 if ($flags =~ m/d/) {
3090 if ($flags_string) { $flags_string .= " / "; }
3091 $flags_string .= "Has Details";
3093 if ($flags =~ m/a/) {
3094 if ($flags_string) { $flags_string .= " / "; }
3095 $flags_string .= "Action";
3097 if ($flags =~ m/h/) {
3098 if ($flags_string) { $flags_string .= " / "; }
3099 $flags_string .= "No Hooks";
3105 $synop .= ": $flags_string\n";
3107 $pad = ' ' x (5 + $name_len - length("user_data"));
3108 $desc .= "$pad : $flags_string</programlisting>\n";
3113 $desc .= "</programlisting>\n";
3116 $desc .= &MakeDeprecationNote($symbol);
3118 my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
3119 my $parameters_output = 0;
3121 $AllSymbols{$symbol} = 1;
3122 if (defined ($SymbolDocs{$symbol})) {
3123 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3125 # Try to insert the parameter table at the author's desired
3126 # position. Otherwise we need to tag it onto the end.
3127 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
3128 $parameters_output = 1;
3130 $desc .= $symbol_docs;
3132 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
3133 $AllDocumentedSymbols{$symbol} = 1;
3137 if ($parameters_output == 0) {
3138 $desc .= $parameters;
3140 $desc .= OutputSymbolTraits ($symbol);
3141 $desc .= "</refsect2>";
3144 return ($synop, $desc);
3148 #############################################################################
3149 # Function : GetArgs
3150 # Description : Returns the synopsis and detailed description DocBook output
3151 # for the Args of a given GtkObject subclass.
3152 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
3153 #############################################################################
3159 my $child_synop = "";
3160 my $child_desc = "";
3161 my $style_synop = "";
3162 my $style_desc = "";
3165 for ($i = 0; $i <= $#ArgObjects; $i++) {
3166 if ($ArgObjects[$i] eq $object) {
3167 #print "Found arg: $ArgNames[$i]\n";
3168 my $name = $ArgNames[$i];
3169 my $flags = $ArgFlags[$i];
3170 my $flags_string = "";
3174 if ($flags =~ m/c/) {
3175 $kind = "child property";
3178 elsif ($flags =~ m/s/) {
3179 $kind = "style property";
3186 # Remember only one colon so we don't clash with signals.
3187 my $symbol = "${object}:${name}";
3188 # use two dashes and ev. an extra separator here for the same reason.
3189 my $id = &CreateValidSGMLID ("$object--$id_sep$name");
3191 my $type = $ArgTypes[$i];
3193 my $range = $ArgRanges[$i];
3194 my $range_output = CreateValidSGML ($range);
3195 my $default = $ArgDefaults[$i];
3196 my $default_output = CreateValidSGML ($default);
3198 if ($type eq "GtkString") {
3201 if ($type eq "GtkSignal") {
3202 $type = "GtkSignalFunc, gpointer";
3203 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
3204 . &MakeXRef ("gpointer");
3205 } elsif ($type =~ m/^(\w+)\*$/) {
3206 $type_output = &MakeXRef ($1) . "*";
3208 $type_output = &MakeXRef ($type);
3211 if ($flags =~ m/r/) {
3212 $flags_string = "Read";
3214 if ($flags =~ m/w/) {
3215 if ($flags_string) { $flags_string .= " / "; }
3216 $flags_string .= "Write";
3218 if ($flags =~ m/x/) {
3219 if ($flags_string) { $flags_string .= " / "; }
3220 $flags_string .= "Construct";
3222 if ($flags =~ m/X/) {
3223 if ($flags_string) { $flags_string .= " / "; }
3224 $flags_string .= "Construct Only";
3227 $AllSymbols{$symbol} = 1;
3229 if (defined($SymbolDocs{$symbol}) &&
3230 !IsEmptyDoc($SymbolDocs{$symbol})) {
3231 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3232 #print ".. [$SymbolDocs{$symbol}][$blurb]\n";
3233 $AllDocumentedSymbols{$symbol} = 1;
3236 if (!($ArgBlurbs[$i] eq "")) {
3237 $AllDocumentedSymbols{$symbol} = 1;
3239 # FIXME: print a warning?
3240 #print ".. no description\n";
3242 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
3245 my $pad1 = " " x (24 - length ($name));
3246 my $pad2 = " " x (20 - length ($type));
3248 my $arg_synop = " "<link linkend=\"$id\">$name</link>"$pad1 $type_output $pad2 : $flags_string\n";
3249 my $arg_desc = "<refsect2 id=\"$id\" role=\"property\"><title>The <literal>"$name"</literal> $kind</title>\n";
3250 $arg_desc .= MakeIndexterms($symbol, $id);
3252 $arg_desc .= OutputSymbolExtraLinks($symbol);
3254 $arg_desc .= "<programlisting> "$name"$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
3255 $arg_desc .= &MakeDeprecationNote($symbol);
3256 $arg_desc .= $blurb;
3258 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
3260 if ($default ne "") {
3261 $arg_desc .= "<para>Default value: $default_output</para>\n";
3263 $arg_desc .= OutputSymbolTraits ($symbol);
3264 $arg_desc .= "</refsect2>\n";
3266 if ($flags =~ m/c/) {
3267 $child_synop .= $arg_synop;
3268 $child_desc .= $arg_desc;
3270 elsif ($flags =~ m/s/) {
3271 $style_synop .= $arg_synop;
3272 $style_desc .= $arg_desc;
3275 $synop .= $arg_synop;
3280 return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
3284 #############################################################################
3285 # Function : ReadSourceDocumentation
3286 # Description : This reads in the documentation embedded in comment blocks
3287 # in the source code (for Gnome).
3289 # Parameter descriptions override any in the template files.
3290 # Function descriptions are placed before any description from
3291 # the template files.
3293 # It recursively descends the source directory looking for .c
3294 # files and scans them looking for specially-formatted comment
3297 # Arguments : $source_dir - the directory to scan.
3298 #############m###############################################################
3300 sub ReadSourceDocumentation {
3301 my ($source_dir) = @_;
3302 my ($file, $dir, @suffix_list, $suffix);
3303 #print "Scanning source directory: $source_dir\n";
3305 # This array holds any subdirectories found.
3308 @suffix_list = split (/,/, $SOURCE_SUFFIXES);
3310 opendir (SRCDIR, $source_dir)
3311 || die "Can't open source directory $source_dir: $!";
3313 foreach $file (readdir (SRCDIR)) {
3314 if ($file =~ /^\./) {
3316 } elsif (-d "$source_dir/$file") {
3317 push (@subdirs, $file);
3318 } elsif (@suffix_list) {
3319 foreach $suffix (@suffix_list) {
3320 if ($file =~ m/\.\Q${suffix}\E$/) {
3321 &ScanSourceFile ("$source_dir/$file");
3324 } elsif ($file =~ m/\.[ch]$/) {
3325 &ScanSourceFile ("$source_dir/$file");
3330 # Now recursively scan the subdirectories.
3331 foreach $dir (@subdirs) {
3332 next if ($IGNORE_FILES =~ m/(\s|^)\Q${dir}\E(\s|$)/);
3333 &ReadSourceDocumentation ("$source_dir/$dir");
3338 #############################################################################
3339 # Function : ScanSourceFile
3340 # Description : Scans one source file looking for specially-formatted comment
3341 # blocks. Later &MergeSourceDocumentation is used to merge any
3342 # documentation found with the documentation already read in
3343 # from the template files.
3345 # Arguments : $file - the file to scan.
3346 #############################################################################
3348 sub ScanSourceFile {
3352 if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
3355 &LogWarning ($file, 1, "Can't find basename for this filename.");
3359 # Check if the basename is in the list of files to ignore.
3360 if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
3364 #print "DEBUG: Scanning $file\n";
3366 open (SRCFILE, $file)
3367 || die "Can't open $file: $!";
3368 my $in_comment_block = 0;
3370 my ($in_description, $in_return, $in_since, $in_stability, $in_deprecated);
3371 my ($description, $return_desc, $return_start, $return_style);
3372 my ($since_desc, $stability_desc, $deprecated_desc);
3374 my $ignore_broken_returns;
3377 # Look for the start of a comment block.
3378 if (!$in_comment_block) {
3379 if (m%^\s*/\*.*\*/%) {
3380 #one-line comment - not gtkdoc
3381 } elsif (m%^\s*/\*\*\s%) {
3382 #print "Found comment block start\n";
3384 $in_comment_block = 1;
3386 # Reset all the symbol data.
3388 $in_description = 0;
3397 $deprecated_desc = "";
3398 $stability_desc = "";
3399 $current_param = -1;
3400 $ignore_broken_returns = 0;
3406 # We're in a comment block. Check if we've found the end of it.
3409 # maybe its not even meant to be a gtk-doc comment?
3410 &LogWarning ($file, $., "Symbol name not found at the start of the comment block.");
3412 # Add the return value description onto the end of the params.
3414 push (@params, "Returns");
3415 push (@params, $return_desc);
3416 if ($return_style eq 'broken') {
3417 &LogWarning ($file, $., "Free-form return value description in $symbol. Use `Returns:' to avoid ambiguities.");
3420 # Convert special SGML characters
3421 $description = &ConvertSGMLChars ($symbol, $description);
3423 for ($k = 1; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3424 $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
3427 # Handle Section docs
3428 if ($symbol =~ m/SECTION:\s*(.*)/) {
3432 if (scalar %KnownSymbols) {
3433 if ((! defined($KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"})) || $KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"} != 1) {
3434 &LogWarning ($file, $., "Section $real_symbol is not defined in the $MODULE-section.txt file.");
3438 #print "SECTION DOCS found in source for : '$real_symbol'\n";
3439 $ignore_broken_returns = 1;
3440 for ($k = 0; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3441 #print " '".$params[$k]."'\n";
3442 $params[$k] = "\L$params[$k]";
3444 if ($params[$k] eq "short_description") {
3445 $key = "$TMPL_DIR/$real_symbol:Short_Description";
3446 } elsif ($params[$k] eq "see_also") {
3447 $key = "$TMPL_DIR/$real_symbol:See_Also";
3448 } elsif ($params[$k] eq "title") {
3449 $key = "$TMPL_DIR/$real_symbol:Title";
3450 } elsif ($params[$k] eq "stability") {
3451 $key = "$TMPL_DIR/$real_symbol:Stability_Level";
3452 } elsif ($params[$k] eq "section_id") {
3453 $key = "$TMPL_DIR/$real_symbol:Section_Id";
3454 } elsif ($params[$k] eq "include") {
3455 $key = "$TMPL_DIR/$real_symbol:Include";
3457 if (defined($key)) {
3458 $SourceSymbolDocs{$key}=$params[$k+1];
3459 $SourceSymbolSourceFile{$key} = $file;
3460 $SourceSymbolSourceLine{$key} = $.;
3463 $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
3464 $SourceSymbolSourceFile{"$TMPL_DIR/$real_symbol:Long_Description"} = $file;
3465 $SourceSymbolSourceLine{"$TMPL_DIR/$real_symbol:Long_Description"} = $.;
3466 #$SourceSymbolTypes{$symbol} = "SECTION";
3468 #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
3469 $SourceSymbolDocs{$symbol} = $description;
3470 $SourceSymbolParams{$symbol} = [ @params ];
3471 # FIXME $SourceSymbolTypes{$symbol} = "STRUCT,SIGNAL,ARG,FUNCTION,MACRO";
3472 #if (defined $DeclarationTypes{$symbol}) {
3473 # $SourceSymbolTypes{$symbol} = $DeclarationTypes{$symbol}
3475 $SourceSymbolSourceFile{$symbol} = $file;
3476 $SourceSymbolSourceLine{$symbol} = $.;
3480 ($since_desc, my @extra_lines) = split ("\n", $since_desc);
3481 $since_desc =~ s/^\s+//;
3482 $since_desc =~ s/\s+$//;
3483 #print "Since($symbol) : [$since_desc]\n";
3484 $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
3485 if(scalar @extra_lines) {
3486 &LogWarning ($file, $., "multi-line since docs found");
3490 if ($stability_desc) {
3491 $stability_desc = &ParseStabilityLevel($stability_desc, $file, $., "Stability level for $symbol");
3492 $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
3495 if ($deprecated_desc) {
3496 if (exists $Deprecated{$symbol}) {
3499 # don't warn for signals and properties
3500 #if ($symbol !~ m/::?(.*)/) {
3501 if (defined $DeclarationTypes{$symbol}) {
3502 &LogWarning ($file, $.,
3503 "$symbol is deprecated in the inline comments, but no deprecation guards were found around the declaration.".
3504 " (See the --deprecated-guards option for gtkdoc-scan.)");
3507 $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
3511 $in_comment_block = 0;
3515 # Get rid of ' * ' at start of every line in the comment block.
3517 # But make sure we don't get rid of the newline at the end.
3521 #print "DEBUG: scanning :$_";
3523 # If we haven't found the symbol name yet, look for it.
3525 if (m%^\s*(SECTION:\s*\S+)%) {
3527 #print "SECTION DOCS found in source for : '$symbol'\n";
3528 $ignore_broken_returns = 1;
3529 } elsif (m%^\s*([\w:-]*\w)\s*:?\s*$%) {
3531 #print "SYMBOL DOCS found in source for : '$symbol'\n";
3536 # If we're in the return value description, add it to the end.
3538 # If we find another valid returns line, we assume that the first
3539 # one was really part of the description.
3540 if (m/^\s*(returns:|return\s+value:)/i) {
3541 if ($return_style eq 'broken') {
3542 $description .= $return_start . $return_desc;
3545 if ($return_style eq 'sane') {
3546 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3548 $return_style = 'sane';
3549 $ignore_broken_returns = 1;
3551 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3552 $description .= $return_start . $return_desc;
3554 $return_style = 'broken';
3556 } elsif (m%^\s*since:%i) {
3560 } elsif (m%^\s*stability:%i) {
3561 $stability_desc = $';
3564 } elsif (m%^\s*deprecated:%i) {
3565 $deprecated_desc = $';
3575 if (m/^\s*(returns:|return\s+value:)/i) {
3576 if ($return_style eq 'broken') {
3577 $description .= $return_start . $return_desc;
3580 if ($return_style eq 'sane') {
3581 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3583 $return_style = 'sane';
3584 $ignore_broken_returns = 1;
3588 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3590 $return_style = 'broken';
3594 } elsif (m%^\s*deprecated:%i) {
3595 $deprecated_desc = $';
3598 } elsif (m%^\s*stability:%i) {
3599 $stability_desc = $';
3608 if ($in_stability) {
3609 if (m/^\s*(returns:|return\s+value:)/i) {
3610 if ($return_style eq 'broken') {
3611 $description .= $return_start . $return_desc;
3614 if ($return_style eq 'sane') {
3615 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3617 $return_style = 'sane';
3618 $ignore_broken_returns = 1;
3622 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3624 $return_style = 'broken';
3628 } elsif (m%^\s*deprecated:%i) {
3629 $deprecated_desc = $';
3632 } elsif (m%^\s*since:%i) {
3637 $stability_desc .= $_;
3642 if ($in_deprecated) {
3643 if (m/^\s*(returns:|return\s+value:)/i) {
3644 if ($return_style eq 'broken') {
3645 $description .= $return_start . $return_desc;
3648 if ($return_style eq 'sane') {
3649 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3651 $return_style = 'sane';
3652 $ignore_broken_returns = 1;
3656 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3658 $return_style = 'broken';
3662 } elsif (m%^\s*since:%i) {
3666 } elsif (m%^\s*stability:%i) {
3667 $stability_desc = $';
3671 $deprecated_desc .= $_;
3676 # If we're in the description part, check for the 'Returns:' line.
3677 # If that isn't found, add the text to the end.
3678 if ($in_description) {
3679 # Get rid of 'Description:'
3680 s%^\s*Description:%%;
3682 if (m/^\s*(returns:|return\s+value:)/i) {
3683 if ($return_style eq 'broken') {
3684 $description .= $return_start . $return_desc;
3687 if ($return_style eq 'sane') {
3688 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3690 $return_style = 'sane';
3691 $ignore_broken_returns = 1;
3695 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3697 $return_style = 'broken';
3701 } elsif (m%^\s*since:%i) {
3705 } elsif (m%^\s*deprecated:%i) {
3706 $deprecated_desc = $';
3709 } elsif (m%^\s*stability:%i) {
3710 $stability_desc = $';
3719 # We must be in the parameters. Check for the empty line below them.
3721 $in_description = 1;
3725 # Look for a parameter name.
3726 if (m%^\s*@(\S+)\s*:%) {
3727 my $param_name = $1;
3728 my $param_desc = $';
3729 #print "Found parameter: $param_name\n";
3730 # Allow '...' as the Varargs parameter.
3731 if ($param_name eq "...") {
3732 $param_name = "Varargs";
3734 if ("\L$param_name" eq "returns") {
3735 $return_style = 'sane';
3736 $ignore_broken_returns = 1;
3738 push (@params, $param_name);
3739 push (@params, $param_desc);
3740 $current_param += $PARAM_FIELD_COUNT;
3744 # We must be in the middle of a parameter description, so add it on
3745 # to the last element in @params.
3746 if ($current_param == -1) {
3747 &LogWarning ($file, $., "Parsing comment block file : parameter expected.");
3749 $params[$#params] .= $_;
3755 #############################################################################
3756 # Function : OutputMissingDocumentation
3757 # Description : Outputs report of documentation coverage to a file
3760 #############################################################################
3762 sub OutputMissingDocumentation {
3763 my $n_documented = 0;
3764 my $n_incomplete = 0;
3770 my $buffer_deprecated = "";
3771 my $buffer_descriptions = "";
3773 open (UNDOCUMENTED, ">$ROOT_DIR/$MODULE-undocumented.txt")
3774 || die "Can't create $ROOT_DIR/$MODULE-undocumented.txt: $!";
3776 foreach $symbol (sort (keys (%AllSymbols))) {
3777 # FIXME: should we print LogWarnings for undocumented stuff?
3779 #my $ssfile = &GetSymbolSourceFile($symbol);
3780 #my $ssline = &GetSymbolSourceLine($symbol);
3781 #my $location = "defined at " . (defined($ssfile)?$ssfile:"?") . ":" . (defined($ssline)?$ssline:"0") . "\n";
3783 if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include|Section_Id)/) {
3785 if (exists ($AllDocumentedSymbols{$symbol})) {
3787 if (exists ($AllIncompleteSymbols{$symbol})) {
3789 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3790 #$buffer .= "\t0: ".$location;
3792 } elsif (exists $Deprecated{$symbol}) {
3793 if (exists ($AllIncompleteSymbols{$symbol})) {
3795 $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3796 #$buffer .= "\t1a: ".$location;
3798 $buffer_deprecated .= $symbol . "\n";
3799 #$buffer .= "\t1b: ".$location;
3802 if (exists ($AllIncompleteSymbols{$symbol})) {
3804 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3805 #$buffer .= "\t2a: ".$location;
3807 $buffer .= $symbol . "\n";
3808 #$buffer .= "\t2b: ".$location;
3811 } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
3813 #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
3814 #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
3815 #print "%%%% $symbol : $len1,$len2\n";
3816 if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
3817 || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
3820 # cut off the leading namespace ($TMPL_DIR)
3821 $symbol =~ m/^.*\/(.*)$/;
3822 $buffer_descriptions .= $1 . "\n";
3827 $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
3832 $percent = ($n_documented / $total) * 100.0;
3835 printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
3836 print UNDOCUMENTED "$n_documented symbols documented.\n";
3837 print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
3838 print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
3840 print UNDOCUMENTED $buffer;
3842 close (UNDOCUMENTED);
3844 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);
3848 #############################################################################
3849 # Function : OutputUndeclaredSymbols
3850 # Description : Outputs symbols that are undeclared yet documented to a file
3853 #############################################################################
3855 sub OutputUndeclaredSymbols {
3856 open(UNDECLARED, ">$ROOT_DIR/$MODULE-undeclared.txt")
3857 || die "Can't create $ROOT_DIR/$MODULE-undeclared.txt";
3859 if (%UndeclaredSymbols) {
3860 print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
3861 print UNDECLARED "\n";
3862 print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
3868 #############################################################################
3869 # Function : OutputAllSymbols
3870 # Description : Outputs list of all symbols to a file
3873 #############################################################################
3875 sub OutputAllSymbols {
3876 my $n_documented = 0;
3882 open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
3883 || die "Can't create $ROOT_DIR/$MODULE-symbols.txt: $!";
3885 foreach $symbol (sort (keys (%AllSymbols))) {
3886 print SYMBOLS $symbol . "\n";
3892 #############################################################################
3893 # Function : OutputSymbolsWithoutSince
3894 # Description : Outputs list of all symbols without a since tag to a file
3897 #############################################################################
3899 sub OutputSymbolsWithoutSince {
3900 my $n_documented = 0;
3906 open (SYMBOLS, ">$ROOT_DIR/$MODULE-nosince.txt")
3907 || die "Can't create $ROOT_DIR/$MODULE-nosince.txt: $!";
3909 foreach $symbol (sort (keys (%SourceSymbolDocs))) {
3910 if (!defined $Since{$symbol}) {
3911 print SYMBOLS $symbol . "\n";
3919 #############################################################################
3920 # Function : MergeSourceDocumentation
3921 # Description : This merges documentation read from a source file into the
3922 # documentation read in from a template file.
3924 # Parameter descriptions override any in the template files.
3925 # Function descriptions are placed before any description from
3926 # the template files.
3929 #############################################################################
3931 sub MergeSourceDocumentation {
3935 if (scalar %SymbolDocs) {
3936 @Symbols=keys (%SymbolDocs);
3937 #print "num existing entries: ".(scalar @Symbols)."\n";
3938 #print " ",$Symbols[0], " ",$Symbols[1],"\n";
3941 # filter scanned declarations, with what we suppress from -sections.txt
3943 foreach $symbol (keys (%Declarations)) {
3944 if (defined($KnownSymbols{$symbol}) && $KnownSymbols{$symbol} == 1) {
3948 # , add the rest from -sections.txt
3949 foreach $symbol (keys (%KnownSymbols)) {
3950 if ($KnownSymbols{$symbol} == 1) {
3954 # and add whats found in the source
3955 foreach $symbol (keys (%SourceSymbolDocs)) {
3958 @Symbols = keys (%tmp);
3959 #print "num source entries: ".(scalar @Symbols)."\n";
3961 foreach $symbol (@Symbols) {
3962 $AllSymbols{$symbol} = 1;
3964 my $have_tmpl_docs = 0;
3966 ## See if the symbol is documented in template
3967 my $tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
3968 my $check_tmpl_doc =$tmpl_doc;
3969 # remove all xml-tags and whitespaces
3970 #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
3971 $check_tmpl_doc =~ s/<.*?>//g;
3972 $check_tmpl_doc =~ s/\s//g;
3974 if ($check_tmpl_doc ne "") {
3975 $have_tmpl_docs = 1;
3976 #print "## [$check_tmpl_doc]\n";
3981 if (exists ($SourceSymbolDocs{$symbol})) {
3982 my $type = $DeclarationTypes {$symbol};
3984 #print "merging [$symbol] from source\n";
3986 my $item = "Parameter";
3987 if (defined ($type)) {
3988 if ($type eq 'STRUCT') {
3990 } elsif ($type eq 'ENUM') {
3992 } elsif ($type eq 'UNION') {
3999 my $src_doc = $SourceSymbolDocs{$symbol};
4000 # remove leading and training whitespaces
4001 $src_doc =~ s/^\s+//;
4002 $src_doc =~ s/\s+$//;
4004 # Don't output warnings for overridden titles as titles are
4005 # automatically generated in the -sections.txt file, and thus they
4006 # are often overridden.
4007 if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
4008 # check if content is different
4009 if ($tmpl_doc ne $src_doc) {
4010 #print "[$tmpl_doc] [$src_doc]\n";
4011 &LogWarning ($SourceSymbolSourceFile{$symbol}, $SourceSymbolSourceLine{$symbol},
4012 "Documentation in template ".$SymbolSourceFile{$symbol}.":".$SymbolSourceLine{$symbol}." for $symbol being overridden by inline comments.");
4016 if ($src_doc ne "") {
4017 $AllDocumentedSymbols{$symbol} = 1;
4020 # Convert <!--PARAMETERS--> with any blank lines around it to
4021 # a </para> followed by <!--PARAMETERS--> followed by <para>.
4022 $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
4024 # If there is a blank line, finish the paragraph and start another.
4025 $src_doc = &ConvertBlankLines ($src_doc, $symbol);
4026 # Do not add <para> to nothing, it breaks missing docs checks.
4027 my $src_doc_para = "";
4029 $src_doc_para = "<para>\n$src_doc</para>\n";
4030 #print "$symbol : [$src_doc][$src_doc_para]\n";
4033 if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
4034 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4035 } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
4036 # For the title/summary/see also section docs we don't want to
4037 # add any <para> tags.
4038 $SymbolDocs{$symbol} = "$src_doc"
4040 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4044 if ($symbol =~ m/.*::.*/) {
4045 # For signals we prefer the param names from the source docs,
4046 # since the ones from the templates are likely to contain the
4047 # artificial argn names which are generated by gtkdoc-scangobj.
4048 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4049 # FIXME: we need to check for empty docs here as well!
4051 # The templates contain the definitive parameter names and order,
4052 # so we will not change that. We only override the actual text.
4053 my $tmpl_params = $SymbolParams{$symbol};
4054 if (!defined ($tmpl_params)) {
4055 #print "No merge needed for $symbol\n";
4056 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4057 # FIXME: we still like to get the number of params and merge
4058 # 1) we would noticed that params have been removed/renamed
4059 # 2) we would catch undocumented params
4060 # params are not (yet) exported in -decl.txt so that we
4061 # could easily grab them :/
4063 my $params = $SourceSymbolParams{$symbol};
4065 #print "Merge needed for $symbol, tmpl_params: ",$#$tmpl_params,", source_params: ",$#$params," \n";
4066 for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4067 my $tmpl_param_name = $$tmpl_params[$j];
4069 # Allow '...' as the Varargs parameter.
4070 if ($tmpl_param_name eq "...") {
4071 $tmpl_param_name = "Varargs";
4074 # Try to find the param in the source comment documentation.
4077 #print " try merge param $tmpl_param_name\n";
4078 for ($k = 0; $k <= $#$params; $k += $PARAM_FIELD_COUNT) {
4079 my $param_name = $$params[$k];
4080 my $param_desc = $$params[$k + 1];
4082 #print " test param $param_name\n";
4083 # We accept changes in case, since the Gnome source
4084 # docs contain a lot of these.
4085 if ("\L$param_name" eq "\L$tmpl_param_name") {
4088 # Override the description.
4089 $$tmpl_params[$j + 1] = $param_desc;
4091 # Set the name to "" to mark it as used.
4097 # If it looks like the parameters are there, but not
4098 # in the right place, try to explain a bit better.
4099 if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
4100 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4101 "Parameters for $symbol must start on the line immediately after the function or macro name.");
4105 # Now we output a warning if parameters have been described which
4107 for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
4108 my $param_name = $$params[$j];
4110 # the template builder cannot detect if a macro returns
4112 if(($type eq "MACRO") && ($param_name eq "Returns")) {
4113 # FIXME: do we need to add it then to tmpl_params[] ?
4114 my $num=$#$tmpl_params;
4115 #print " adding Returns: to macro docs for $symbol.\n";
4116 $$tmpl_params[$num+1]="Returns";
4117 $$tmpl_params[$num+2]=$$params[$j+1];
4120 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4121 "$item described in source code comment block but does not exist. $type: $symbol $item: $param_name.");
4127 if ($have_tmpl_docs) {
4128 $AllDocumentedSymbols{$symbol} = 1;
4129 #print "merging [$symbol] from template\n";
4132 #print "[$symbol] undocumented\n";
4136 # if this symbol is documented, check if docs are complete
4137 $check_tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4138 # remove all xml-tags and whitespaces
4139 #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
4140 $check_tmpl_doc =~ s/<.*?>//g;
4141 $check_tmpl_doc =~ s/\s//g;
4142 if ($check_tmpl_doc ne "") {
4143 my $tmpl_params = $SymbolParams{$symbol};
4144 if (defined ($tmpl_params)) {
4145 my $type = $DeclarationTypes {$symbol};
4147 my $item = "Parameter";
4148 if (defined ($type)) {
4149 if ($type eq 'STRUCT') {
4151 } elsif ($type eq 'ENUM') {
4153 } elsif ($type eq 'UNION') {
4160 #print "Check param docs for $symbol, tmpl_params: ",$#$tmpl_params," entries, type=$type\n";
4162 if ($#$tmpl_params > 0) {
4164 for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4165 # Output a warning if the parameter is empty and
4166 # remember for stats.
4167 my $tmpl_param_name = $$tmpl_params[$j];
4168 my $tmpl_param_desc = $$tmpl_params[$j + 1];
4169 if ($tmpl_param_desc !~ m/\S/) {
4170 if (exists ($AllIncompleteSymbols{$symbol})) {
4171 $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
4173 $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
4175 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4176 "$item description for $symbol"."::"."$tmpl_param_name is missing in source code comment block.");
4181 if ($#$tmpl_params == 0) {
4182 $AllIncompleteSymbols{$symbol}="<items>";
4183 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4184 "$item descriptions for $symbol are missing in source code comment block.");
4186 # $#$tmpl_params==-1 means we don't know about parameters
4187 # this unfortunately does not tell if there should be some
4192 #print "num doc entries: ".(scalar %SymbolDocs)."\n";
4195 #############################################################################
4196 # Function : IsEmptyDoc
4197 # Description : Check if a doc-string is empty. Its also regarded as empty if
4198 # it only consist of whitespace or e.g. FIXME.
4199 # Arguments : the doc-string
4200 #############################################################################
4204 if ($doc =~ /^\s*$/) {
4208 if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
4216 # This converts blank lines to "</para><para>", but only outside CDATA and
4217 # <programlisting> tags.
4218 sub ConvertBlankLines {
4219 return &ModifyXMLElements ($_[0], $_[1],
4220 "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
4221 \&ConvertBlankLinesEndTag,
4222 \&ConvertBlankLinesCallback);
4226 sub ConvertBlankLinesEndTag {
4227 if ($_[0] eq "<!\[CDATA\[") {
4229 } elsif ($_[0] eq "|[") {
4232 return "</programlisting>";
4236 sub ConvertBlankLinesCallback {
4237 my ($text, $symbol, $tag) = @_;
4239 # If we're not in CDATA or a <programlisting> we convert blank lines so
4240 # they start a new <para>.
4242 $text =~ s%\n{2,}%\n</para>\n<para>\n%g;
4249 #############################################################################
4250 # LIBRARY FUNCTIONS - These functions are used in both gtkdoc-mkdb and
4251 # gtkdoc-mktmpl and should eventually be moved to a
4253 #############################################################################
4255 #############################################################################
4256 # Function : ReadDeclarationsFile
4257 # Description : This reads in a file containing the function/macro/enum etc.
4260 # Note that in some cases there are several declarations with
4261 # the same name, e.g. for conditional macros. In this case we
4262 # set a flag in the %DeclarationConditional hash so the
4263 # declaration is not shown in the docs.
4265 # If a macro and a function have the same name, e.g. for
4266 # gtk_object_ref, the function declaration takes precedence.
4268 # Some opaque structs are just declared with 'typedef struct
4269 # _name name;' in which case the declaration may be empty.
4270 # The structure may have been found later in the header, so
4271 # that overrides the empty declaration.
4273 # Arguments : $file - the declarations file to read
4274 # $override - if declarations in this file should override
4275 # any current declaration.
4276 #############################################################################
4278 sub ReadDeclarationsFile {
4279 my ($file, $override) = @_;
4281 if ($override == 0) {
4283 %DeclarationTypes = ();
4284 %DeclarationConditional = ();
4285 %DeclarationOutput = ();
4289 || die "Can't open $file: $!";
4290 my $declaration_type = "";
4291 my $declaration_name;
4293 my $is_deprecated = 0;
4295 if (!$declaration_type) {
4296 if (m/^<([^>]+)>/) {
4297 $declaration_type = $1;
4298 $declaration_name = "";
4299 #print "Found declaration: $declaration_type\n";
4303 if (m%^<NAME>(.*)</NAME>%) {
4304 $declaration_name = $1;
4305 } elsif (m%^<DEPRECATED/>%) {
4307 } elsif (m%^</$declaration_type>%) {
4308 #print "Found end of declaration: $declaration_name\n";
4309 # Check that the declaration has a name
4310 if ($declaration_name eq "") {
4311 print "ERROR: $declaration_type has no name $file:$.\n";
4314 # If the declaration is an empty typedef struct _XXX XXX
4315 # set the flag to indicate the struct has a typedef.
4316 if ($declaration_type eq 'STRUCT'
4317 && $declaration =~ m/^\s*$/) {
4318 #print "Struct has typedef: $declaration_name\n";
4319 $StructHasTypedef{$declaration_name} = 1;
4322 # Check if the symbol is already defined.
4323 if (defined ($Declarations{$declaration_name})
4324 && $override == 0) {
4325 # Function declarations take precedence.
4326 if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
4328 } elsif ($declaration_type eq 'FUNCTION') {
4329 if ($is_deprecated) {
4330 $Deprecated{$declaration_name} = "";
4332 $Declarations{$declaration_name} = $declaration;
4333 $DeclarationTypes{$declaration_name} = $declaration_type;
4334 } elsif ($DeclarationTypes{$declaration_name}
4335 eq $declaration_type) {
4336 # If the existing declaration is empty, or is just a
4337 # forward declaration of a struct, override it.
4338 if ($declaration_type eq 'STRUCT') {
4339 if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4340 if ($is_deprecated) {
4341 $Deprecated{$declaration_name} = "";
4343 $Declarations{$declaration_name} = $declaration;
4344 } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4345 # Ignore an empty or forward declaration.
4347 &LogWarning ($file, $., "Structure $declaration_name has multiple definitions.");
4350 # set flag in %DeclarationConditional hash for
4351 # multiply defined macros/typedefs.
4352 $DeclarationConditional{$declaration_name} = 1;
4355 &LogWarning ($file, $., "$declaration_name has multiple definitions.");
4358 if ($is_deprecated) {
4359 $Deprecated{$declaration_name} = "";
4361 $Declarations{$declaration_name} = $declaration;
4362 $DeclarationTypes{$declaration_name} = $declaration_type;
4365 $declaration_type = "";
4376 #############################################################################
4377 # Function : ReadSignalsFile
4378 # Description : This reads in an existing file which contains information on
4379 # all GTK signals. It creates the arrays @SignalNames and
4380 # @SignalPrototypes containing info on the signals. The first
4381 # line of the SignalPrototype is the return type of the signal
4382 # handler. The remaining lines are the parameters passed to it.
4383 # The last parameter, "gpointer user_data" is always the same
4384 # so is not included.
4385 # Arguments : $file - the file containing the signal handler prototype
4387 #############################################################################
4389 sub ReadSignalsFile {
4397 my $signal_prototype;
4399 # Reset the signal info.
4400 @SignalObjects = ();
4402 @SignalReturns = ();
4404 @SignalPrototypes = ();
4409 if (!open (INPUT, $file)) {
4410 warn "Can't open $file - skipping signals\n";
4417 $signal_object = "";
4419 $signal_returns = "";
4420 $signal_prototype = "";
4423 if (m/^<NAME>(.*)<\/NAME>/) {
4425 if ($signal_name =~ m/^(.*)::(.*)$/) {
4426 $signal_object = $1;
4427 ($signal_name = $2) =~ s/_/-/g;
4428 #print "Found signal: $signal_name\n";
4430 &LogWarning ($file, $., "Invalid signal name: $signal_name.");
4432 } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
4433 $signal_returns = $1;
4434 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4436 } elsif (m%^</SIGNAL>%) {
4437 #print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
4438 push (@SignalObjects, $signal_object);
4439 push (@SignalNames, $signal_name);
4440 push (@SignalReturns, $signal_returns);
4441 push (@SignalFlags, $signal_flags);
4442 push (@SignalPrototypes, $signal_prototype);
4445 $signal_prototype .= $_;
4453 #############################################################################
4454 # Function : ReadTemplateFile
4455 # Description : This reads in the manually-edited documentation file
4456 # corresponding to the file currently being created, so we can
4457 # insert the documentation at the appropriate places.
4458 # It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
4459 # is a hash of arrays.
4460 # NOTE: This function is duplicated in gtkdoc-mktmpl (but
4461 # slightly different).
4462 # Arguments : $docsfile - the template file to read in.
4463 # $skip_unused_params - 1 if the unused parameters should be
4465 #############################################################################
4467 sub ReadTemplateFile {
4468 my ($docsfile, $skip_unused_params) = @_;
4470 my $template = "$docsfile.sgml";
4471 if (! -f $template) {
4472 #print "File doesn't exist: $template\n";
4475 #print "Reading $template\n";
4477 # start with empty hashes, we merge the source comment for each file
4483 my $current_type = ""; # Type of symbol being read.
4484 my $current_symbol = ""; # Name of symbol being read.
4485 my $symbol_doc = ""; # Description of symbol being read.
4486 my @params; # Parameter names and descriptions of current
4487 # function/macro/function typedef.
4488 my $current_param = -1; # Index of parameter currently being read.
4489 # Note that the param array contains pairs
4490 # of param name & description.
4491 my $in_unused_params = 0; # True if we are reading in the unused params.
4492 my $in_deprecated = 0;
4494 my $in_stability = 0;
4496 open (DOCS, "$template")
4497 || die "Can't open $template: $!";
4499 if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
4502 if ($symbol eq "Title"
4503 || $symbol eq "Short_Description"
4504 || $symbol eq "Long_Description"
4505 || $symbol eq "See_Also"
4506 || $symbol eq "Stability_Level"
4507 || $symbol eq "Include") {
4509 $symbol = $docsfile . ":" . $symbol;
4512 #print "Found symbol: $symbol\n";
4513 # Remember file and line for the symbol
4514 $SymbolSourceFile{$symbol} = $template;
4515 $SymbolSourceLine{$symbol} = $.;
4517 # Store previous symbol, but remove any trailing blank lines.
4518 if ($current_symbol ne "") {
4519 $symbol_doc =~ s/\s+$//;
4520 $SymbolTypes{$current_symbol} = $current_type;
4521 $SymbolDocs{$current_symbol} = $symbol_doc;
4523 # Check that the stability level is valid.
4524 if ($StabilityLevel{$current_symbol}) {
4525 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4528 if ($current_param >= 0) {
4529 $SymbolParams{$current_symbol} = [ @params ];
4531 # Delete any existing params in case we are overriding a
4532 # previously read template.
4533 delete $SymbolParams{$current_symbol};
4536 $current_type = $type;
4537 $current_symbol = $symbol;
4538 $current_param = -1;
4539 $in_unused_params = 0;
4546 } elsif (m/^<!-- # Unused Parameters # -->/) {
4547 #print "DEBUG: Found unused parameters\n";
4548 $in_unused_params = 1;
4551 } elsif ($in_unused_params && $skip_unused_params) {
4552 # When outputting the DocBook we skip unused parameters.
4553 #print "DEBUG: Skipping unused param: $_";
4557 # Check if param found. Need to handle "..." and "format...".
4558 if (s/^\@([\w\.]+):\040?//) {
4559 my $param_name = $1;
4560 my $param_desc = $_;
4561 # Allow variations of 'Returns'
4562 if ($param_name =~ m/^[Rr]eturns?$/) {
4563 $param_name = "Returns";
4566 # strip trailing whitespaces and blank lines
4569 #print "Found param for symbol $current_symbol : '$param_name'= '$_'";
4571 if ($param_name eq "Deprecated") {
4573 $Deprecated{$current_symbol} = $_;
4574 } elsif ($param_name eq "Since") {
4577 $Since{$current_symbol} = $_;
4578 } elsif ($param_name eq "Stability") {
4580 $StabilityLevel{$current_symbol} = $_;
4582 push (@params, $param_name);
4583 push (@params, $param_desc);
4584 $current_param += $PARAM_FIELD_COUNT;
4587 # strip trailing whitespaces and blank lines
4592 if ($in_deprecated) {
4593 $Deprecated{$current_symbol} .= $_;
4594 } elsif ($in_since) {
4595 &LogWarning ($template, $., "multi-line since docs found");
4596 #$Since{$current_symbol} .= $_;
4597 } elsif ($in_stability) {
4598 $StabilityLevel{$current_symbol} .= $_;
4599 } elsif ($current_param >= 0) {
4600 $params[$current_param] .= $_;
4609 # Remember to finish the current symbol doccs.
4610 if ($current_symbol ne "") {
4612 $symbol_doc =~ s/\s+$//;
4613 $SymbolTypes{$current_symbol} = $current_type;
4614 $SymbolDocs{$current_symbol} = $symbol_doc;
4616 # Check that the stability level is valid.
4617 if ($StabilityLevel{$current_symbol}) {
4618 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4621 if ($current_param >= 0) {
4622 $SymbolParams{$current_symbol} = [ @params ];
4624 # Delete any existing params in case we are overriding a
4625 # previously read template.
4626 delete $SymbolParams{$current_symbol};
4635 #############################################################################
4636 # Function : ReadObjectHierarchy
4637 # Description : This reads in the $MODULE-hierarchy.txt file containing all
4638 # the GtkObject subclasses described in this module (and their
4640 # It places them in the @Objects array, and places their level
4641 # in the widget hierarchy in the @ObjectLevels array, at the
4642 # same index. GtkObject, the root object, has a level of 1.
4644 # FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
4645 # as it goes along, this should be split out into a separate
4649 #############################################################################
4651 sub ReadObjectHierarchy {
4655 if (! -f $OBJECT_TREE_FILE) {
4658 if (!open (INPUT, $OBJECT_TREE_FILE)) {
4659 warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
4663 # FIXME: use $OUTPUT_FORMAT
4664 # my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.$OUTPUT_FORMAT";
4665 my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
4666 my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
4668 open (OUTPUT, ">$new_tree_index")
4669 || die "Can't create $new_tree_index: $!";
4671 if (lc($OUTPUT_FORMAT) eq "xml") {
4672 my $tree_header = $doctype_header;
4674 $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
4675 print (OUTPUT "$tree_header");
4677 print (OUTPUT "<screen>\n");
4679 # Only emit objects if they are supposed to be documented, or if
4680 # they have documented children. To implement this, we maintain a
4681 # stack of pending objects which will be emitted if a documented
4683 my @pending_objects = ();
4684 my @pending_levels = ();
4688 my $level = (length($`)) / 2 + 1;
4691 while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
4692 my $pobject = pop(@pending_objects);
4693 my $plevel = pop(@pending_levels);
4696 push (@pending_objects, $object);
4697 push (@pending_levels, $level);
4699 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
4700 while ($#pending_levels >= 0) {
4701 $object = shift @pending_objects;
4702 $level = shift @pending_levels;
4703 $xref = &MakeXRef ($object);
4705 print (OUTPUT ' ' x ($level * 4), "$xref\n");
4706 push (@Objects, $object);
4707 push (@ObjectLevels, $level);
4712 print (OUTPUT "</screen>\n");
4717 &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
4722 #############################################################################
4723 # Function : ReadInterfaces
4724 # Description : This reads in the $MODULE.interfaces file.
4727 #############################################################################
4729 sub ReadInterfaces {
4732 if (! -f $INTERFACES_FILE) {
4735 if (!open (INPUT, $INTERFACES_FILE)) {
4736 warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
4742 my ($object, @ifaces) = split;
4743 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
4744 my @knownIfaces = ();
4746 # filter out private interfaces, but leave foreign interfaces
4747 foreach my $iface (@ifaces) {
4748 if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
4749 push (@knownIfaces, $iface);
4753 $Interfaces{$object} = join(' ', @knownIfaces);
4759 #############################################################################
4760 # Function : ReadPrerequisites
4761 # Description : This reads in the $MODULE.prerequisites file.
4764 #############################################################################
4766 sub ReadPrerequisites {
4767 %Prerequisites = ();
4769 if (! -f $PREREQUISITES_FILE) {
4772 if (!open (INPUT, $PREREQUISITES_FILE)) {
4773 warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
4779 my ($iface, @prereqs) = split;
4780 if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
4781 my @knownPrereqs = ();
4783 # filter out private prerequisites, but leave foreign prerequisites
4784 foreach my $prereq (@prereqs) {
4785 if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
4786 push (@knownPrereqs, $prereq);
4790 $Prerequisites{$iface} = join(' ', @knownPrereqs);
4796 #############################################################################
4797 # Function : ReadArgsFile
4798 # Description : This reads in an existing file which contains information on
4799 # all GTK args. It creates the arrays @ArgObjects, @ArgNames,
4800 # @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
4802 # Arguments : $file - the file containing the arg information.
4803 #############################################################################
4818 # Reset the args info.
4831 if (!open (INPUT, $file)) {
4832 warn "Can't open $file - skipping args\n";
4849 if (m/^<NAME>(.*)<\/NAME>/) {
4851 if ($arg_name =~ m/^(.*)::(.*)$/) {
4853 ($arg_name = $2) =~ s/_/-/g;
4854 #print "Found arg: $arg_name\n";
4856 &LogWarning ($file, $., "Invalid argument name: $arg_name");
4858 } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
4860 } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
4862 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4864 } elsif (m/^<NICK>(.*)<\/NICK>/) {
4866 } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
4868 if ($arg_blurb eq "(null)") {
4870 &LogWarning ($file, $., "Property ${arg_object}:${arg_name} has no documentation.");
4872 } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
4874 } elsif (m%^</ARG>%) {
4875 #print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
4876 push (@ArgObjects, $arg_object);
4877 push (@ArgNames, $arg_name);
4878 push (@ArgTypes, $arg_type);
4879 push (@ArgRanges, $arg_range);
4880 push (@ArgFlags, $arg_flags);
4881 push (@ArgNicks, $arg_nick);
4882 push (@ArgBlurbs, $arg_blurb);
4883 push (@ArgDefaults, $arg_default);
4892 #############################################################################
4893 # Function : CheckIsObject
4894 # Description : Returns 1 if the given name is a GtkObject or a subclass.
4895 # It uses the global @Objects array.
4896 # Note that the @Objects array only contains classes in the
4897 # current module and their ancestors - not all GTK classes.
4898 # Arguments : $name - the name to check.
4899 #############################################################################
4905 foreach $object (@Objects) {
4906 if ($object eq $name) {
4914 #############################################################################
4915 # Function : MakeReturnField
4916 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
4917 # Arguments : $str - the string to pad.
4918 #############################################################################
4920 sub MakeReturnField {
4923 return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));
4926 #############################################################################
4927 # Function : GetSymbolSourceFile
4928 # Description : Get the filename where the symbol docs where taken from.
4929 # Arguments : $symbol - the symbol name
4930 #############################################################################
4932 sub GetSymbolSourceFile {
4935 if (defined($SourceSymbolSourceFile{$symbol})) {
4936 return $SourceSymbolSourceFile{$symbol};
4937 } elsif (defined($SymbolSourceFile{$symbol})) {
4938 return $SymbolSourceFile{$symbol};
4944 #############################################################################
4945 # Function : GetSymbolSourceLine
4946 # Description : Get the file line where the symbol docs where taken from.
4947 # Arguments : $symbol - the symbol name
4948 #############################################################################
4950 sub GetSymbolSourceLine {
4953 if (defined($SourceSymbolSourceLine{$symbol})) {
4954 return $SourceSymbolSourceLine{$symbol};
4955 } elsif (defined($SymbolSourceLine{$symbol})) {
4956 return $SymbolSourceLine{$symbol};