4 # gtk-doc - GTK DocBook documentation generator.
5 # Copyright (C) 1998 Damon Chaplin
6 # 2007,2008,2009 Stefan Kost
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #############################################################################
24 # Script : gtkdoc-mkdb
25 # Description : This creates the DocBook files from the edited templates.
26 #############################################################################
31 push @INC, '@PACKAGE_DATA_DIR@';
32 require "gtkdoc-common.pl";
36 # name of documentation module
41 my $SOURCE_SUFFIXES = "";
42 my $IGNORE_FILES = "";
46 my $EXPAND_CONTENT_FILES = "";
48 my $DEFAULT_STABILITY;
52 my $OUTPUT_ALL_SYMBOLS;
53 my $OUTPUT_SYMBOLS_WITHOUT_SINCE;
55 my %optctl = ('module' => \$MODULE,
56 'source-dir' => \@SOURCE_DIRS,
57 'source-suffixes' => \$SOURCE_SUFFIXES,
58 'ignore-files' => \$IGNORE_FILES,
59 'output-dir' => \$SGML_OUTPUT_DIR,
60 'tmpl-dir' => \$TMPL_DIR,
61 'version' => \$PRINT_VERSION,
62 'help' => \$PRINT_HELP,
63 'main-sgml-file' => \$MAIN_SGML_FILE,
64 'expand-content-files' => \$EXPAND_CONTENT_FILES,
65 'sgml-mode' => \$SGML_MODE,
66 'default-stability' => \$DEFAULT_STABILITY,
67 'default-includes' => \$DEFAULT_INCLUDES,
68 'output-format' => \$OUTPUT_FORMAT,
69 'name-space' => \$NAME_SPACE,
70 'outputallsymbols' => \$OUTPUT_ALL_SYMBOLS,
71 'outputsymbolswithoutsince' => \$OUTPUT_SYMBOLS_WITHOUT_SINCE
73 GetOptions(\%optctl, "module=s", "source-dir:s", "source-suffixes:s",
74 "ignore-files:s", "output-dir:s", "tmpl-dir:s", "version", "outputallsymbols",
75 "outputsymbolswithoutsince",
76 "expand-content-files:s", "main-sgml-file:s", "extra-db-files:s", "help",
77 "sgml-mode", "default-stability:s", "default-includes:s", "output-format:s",
89 if ($DEFAULT_STABILITY && $DEFAULT_STABILITY ne "Stable"
90 && $DEFAULT_STABILITY ne "Private" && $DEFAULT_STABILITY ne "Unstable") {
96 gtkdoc-mkdb version @VERSION@ - generate docbook files
98 --module=MODULE_NAME Name of the doc module being parsed
99 --source-dir=DIRNAME Directories which contain inline reference material
100 --source-suffixes=SUFFIXES Suffixes of source files to scan, comma-separated
101 --ignore-files=FILES Files or directories which should not be scanned
102 May be used more than once for multiple directories
103 --output-dir=DIRNAME Directory to put the generated DocBook files in
104 --tmpl-dir=DIRNAME Directory in which template files may be found
105 --main-sgml-file=FILE File containing the toplevel DocBook file.
106 --expand-content-files=FILES Extra DocBook files to expand abbreviations in.
107 --output-format=FORMAT Format to use for the generated docbook, XML or SGML.
108 --sgml-mode Allow DocBook markup in inline documentation.
109 --default-stability=LEVEL Specify default stability Level. Valid values are
110 Stable, Unstable, or Private.
111 --default-includes=FILENAMES Specify default includes for section Synopsis
112 --name-space=NS Omit namespace in index.
113 --version Print the version of this program
114 --help Print this help
119 my ($empty_element_end, $doctype_header);
121 # autodetect output format
122 if (! defined($OUTPUT_FORMAT) || ($OUTPUT_FORMAT eq "")) {
123 if (!$MAIN_SGML_FILE) {
124 if (-e "${MODULE}-docs.xml") {
125 $OUTPUT_FORMAT = "xml";
127 $OUTPUT_FORMAT = "sgml";
130 if ($MAIN_SGML_FILE =~ m/.*\.(.*ml)$/i) {
131 $OUTPUT_FORMAT = lc($1);
136 $OUTPUT_FORMAT = lc($OUTPUT_FORMAT);
139 #print "DEBUG: output-format: [$OUTPUT_FORMAT]\n";
141 if ($OUTPUT_FORMAT eq "xml") {
142 if (!$MAIN_SGML_FILE) {
143 # backwards compatibility
144 if (-e "${MODULE}-docs.sgml") {
145 $MAIN_SGML_FILE = "${MODULE}-docs.sgml";
147 $MAIN_SGML_FILE = "${MODULE}-docs.xml";
150 $empty_element_end = "/>";
152 if (-e $MAIN_SGML_FILE) {
153 open(INPUT, "<$MAIN_SGML_FILE") || die "Can't open $MAIN_SGML_FILE";
154 $doctype_header = "";
156 if (/^\s*<(book|chapter|article)/) {
157 # check that the top-level tag or the doctype decl contain the xinclude namespace decl
158 if (($_ !~ m/http:\/\/www.w3.org\/200[13]\/XInclude/) && ($doctype_header !~ m/http:\/\/www.w3.org\/200[13]\/XInclude/m)) {
159 $doctype_header = "";
163 $doctype_header .= $_;
168 "<?xml version=\"1.0\"?>\n" .
169 "<!DOCTYPE book PUBLIC \"-//OASIS//DTD DocBook XML V4.3//EN\"\n" .
170 " \"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd\"\n" .
172 " <!ENTITY % local.common.attrib \"xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'\">\n" .
175 $doctype_header =~ s/<!DOCTYPE \w+/<!DOCTYPE refentry/;
177 if (!$MAIN_SGML_FILE) {
178 $MAIN_SGML_FILE = "${MODULE}-docs.sgml";
180 $empty_element_end = ">";
181 $doctype_header = "";
186 # All the files are written in subdirectories beneath here.
187 $TMPL_DIR = $TMPL_DIR ? $TMPL_DIR : "$ROOT_DIR/tmpl";
189 # This is where we put all the DocBook output.
190 $SGML_OUTPUT_DIR = $SGML_OUTPUT_DIR ? $SGML_OUTPUT_DIR : "$ROOT_DIR/$OUTPUT_FORMAT";
192 # This file contains the object hierarchy.
193 my $OBJECT_TREE_FILE = "$ROOT_DIR/$MODULE.hierarchy";
195 # This file contains the interfaces.
196 my $INTERFACES_FILE = "$ROOT_DIR/$MODULE.interfaces";
198 # This file contains the prerequisites.
199 my $PREREQUISITES_FILE = "$ROOT_DIR/$MODULE.prerequisites";
201 # This file contains signal arguments and names.
202 my $SIGNALS_FILE = "$ROOT_DIR/$MODULE.signals";
204 # The file containing Arg information.
205 my $ARGS_FILE = "$ROOT_DIR/$MODULE.args";
207 # These global arrays store information on signals. Each signal has an entry
208 # in each of these arrays at the same index, like a multi-dimensional array.
209 my @SignalObjects; # The GtkObject which emits the signal.
210 my @SignalNames; # The signal name.
211 my @SignalReturns; # The return type.
212 my @SignalFlags; # Flags for the signal
213 my @SignalPrototypes; # The rest of the prototype of the signal handler.
215 # These global arrays store information on Args. Each Arg has an entry
216 # in each of these arrays at the same index, like a multi-dimensional array.
217 my @ArgObjects; # The GtkObject which has the Arg.
218 my @ArgNames; # The Arg name.
219 my @ArgTypes; # The Arg type - gint, GtkArrowType etc.
220 my @ArgFlags; # How the Arg can be used - readable/writable etc.
221 my @ArgNicks; # The nickname of the Arg.
222 my @ArgBlurbs; # Docstring of the Arg.
223 my @ArgDefaults; # Default value of the Arg.
224 my @ArgRanges; # The range of the Arg type
225 # These global hashes store declaration info keyed on a symbol name.
227 my %DeclarationTypes;
228 my %DeclarationConditional;
229 my %DeclarationOutput;
233 my %StructHasTypedef;
235 # These global hashes store the existing documentation.
239 my %SymbolSourceFile;
240 my %SymbolSourceLine;
242 # These global hashes store documentation scanned from the source files.
243 my %SourceSymbolDocs;
244 my %SourceSymbolParams;
245 my %SourceSymbolSourceFile;
246 my %SourceSymbolSourceLine;
248 # all documentation goes in here, so we can do coverage analysis
250 my %AllIncompleteSymbols;
251 my %AllUnusedSymbols;
252 my %AllDocumentedSymbols;
254 # Undeclared yet documented symbols
255 my %UndeclaredSymbols;
257 # These global arrays store GObject, subclasses and the hierarchy.
264 # holds the symbols which are mentioned in $MODULE-sections.txt and in which
265 # section they are defined
270 # collects index entries
271 my %IndexEntriesFull;
272 my %IndexEntriesSince;
273 my %IndexEntriesDeprecated;
275 # Standard C preprocessor directives, which we ignore for '#' abbreviations.
276 my %PreProcessorDirectives;
277 $PreProcessorDirectives{"assert"} = 1;
278 $PreProcessorDirectives{"define"} = 1;
279 $PreProcessorDirectives{"elif"} = 1;
280 $PreProcessorDirectives{"else"} = 1;
281 $PreProcessorDirectives{"endif"} = 1;
282 $PreProcessorDirectives{"error"} = 1;
283 $PreProcessorDirectives{"if"} = 1;
284 $PreProcessorDirectives{"ifdef"} = 1;
285 $PreProcessorDirectives{"ifndef"} = 1;
286 $PreProcessorDirectives{"include"} = 1;
287 $PreProcessorDirectives{"line"} = 1;
288 $PreProcessorDirectives{"pragma"} = 1;
289 $PreProcessorDirectives{"unassert"} = 1;
290 $PreProcessorDirectives{"undef"} = 1;
291 $PreProcessorDirectives{"warning"} = 1;
293 # remember used annotation (to write minimal glossary)
296 my %AnnotationDefinition = (
297 'allow-none' => "NULL is ok, both for passing and for returning.",
298 'array' => "Parameter points to an array of items.",
299 'default' => "Default parameter value (for in case the <acronym>shadows</acronym>-to function has less parameters).",
300 'element-type' => "Generics and defining elements of containers and arrays.",
301 'error-domains' => "Typed errors. Similar to throws in Java.",
302 'in' => "Parameter for input. Default is <acronym>transfer none</acronym>.",
303 'inout' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
304 'in-out' => "Parameter for input and for returning results. Default is <acronym>transfer full</acronym>.",
305 'not-error' => "A GError parameter is not to be handled like a normal GError.",
306 'out' => "Parameter for returning results. Default is <acronym>transfer full</acronym>.",
307 'transfer container' => "Free data container after the code is done.",
308 'transfer full' => "Free data after the code is done.",
309 'transfer none' => "Don't free data after the code is done."
312 # Create the root DocBook output directory if it doens't exist.
313 if (! -e $SGML_OUTPUT_DIR) {
314 mkdir ("$SGML_OUTPUT_DIR", 0777)
315 || die "Can't create directory: $SGML_OUTPUT_DIR";
318 # Function and other declaration output settings.
319 my $RETURN_TYPE_FIELD_WIDTH = 20;
320 my $SYMBOL_FIELD_WIDTH = 36;
321 my $SIGNAL_FIELD_WIDTH = 16;
322 my $PARAM_FIELD_COUNT = 2;
324 &ReadKnownSymbols ("$ROOT_DIR/$MODULE-sections.txt");
325 &ReadSignalsFile ($SIGNALS_FILE);
326 &ReadArgsFile ($ARGS_FILE);
327 &ReadObjectHierarchy;
331 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-decl.txt", 0);
332 if (-f "$ROOT_DIR/$MODULE-overrides.txt") {
333 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-overrides.txt", 1);
336 for my $dir (@SOURCE_DIRS) {
337 &ReadSourceDocumentation ($dir);
340 my $changed = &OutputSGML ("$ROOT_DIR/$MODULE-sections.txt");
342 # If any of the DocBook SGML files have changed, update the timestamp file (so
343 # it can be used for Makefile dependencies).
344 if ($changed || ! -e "$ROOT_DIR/sgml.stamp") {
346 # try to detect the common prefix
347 # GtkWidget, GTK_WIDGET, gtk_widget -> gtk
348 if ($NAME_SPACE eq "") {
355 foreach my $symbol (keys(%IndexEntriesFull)) {
356 if(($NAME_SPACE eq "") || $symbol =~ /^$NAME_SPACE/i) {
357 if (length($symbol)>$pos) {
358 $letter=substr($symbol,$pos,1);
359 # stop prefix scanning
360 if ($letter eq "_") {
364 # Should we also stop on a uppercase char, if last was lowercase
365 # GtkWidget, if we have the 'W' and had the 't' before
366 # or should we count upper and lowercase, and stop one 2nd uppercase, if we already had a lowercase
367 # GtkWidget, the 'W' would be the 2nd uppercase and with 't','k' we had lowercase chars before
368 # need to recound each time as this is per symbol
369 $prefix{uc($letter)}++;
373 if ($letter ne "" && $letter ne "_") {
376 foreach $letter (keys(%prefix)) {
377 #print "$letter: $prefix{$letter}.\n";
378 if ($prefix{$letter}>$maxsymbols) {
380 $maxsymbols=$prefix{$letter};
383 $ratio = scalar(keys(%IndexEntriesFull)) / $prefix{$maxletter};
384 #print "most symbols start with $maxletter, that is ". (100 * $ratio) ." %\n";
387 $NAME_SPACE .= $maxletter;
394 } while ($ratio > 0.9);
395 #print "most symbols start with $NAME_SPACE\n";
399 &OutputDeprecatedIndex;
401 &OutputAnnotationGlossary;
403 open (TIMESTAMP, ">$ROOT_DIR/sgml.stamp")
404 || die "Can't create $ROOT_DIR/sgml.stamp: $!";
405 print (TIMESTAMP "timestamp");
409 #############################################################################
410 # Function : OutputObjectList
411 # Description : This outputs the alphabetical list of objects, in a columned
413 # FIXME: Currently this also outputs ancestor objects
414 # which may not actually be in this module.
416 #############################################################################
418 sub OutputObjectList {
421 # FIXME: use $OUTPUT_FORMAT
422 # my $old_object_index = "$SGML_OUTPUT_DIR/object_index.$OUTPUT_FORMAT";
423 my $old_object_index = "$SGML_OUTPUT_DIR/object_index.sgml";
424 my $new_object_index = "$SGML_OUTPUT_DIR/object_index.new";
426 open (OUTPUT, ">$new_object_index")
427 || die "Can't create $new_object_index: $!";
429 if ($OUTPUT_FORMAT eq "xml") {
430 my $header = $doctype_header;
432 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE informaltable/;
433 print (OUTPUT "$header");
436 print (OUTPUT <<EOF);
437 <informaltable pgwide="1" frame="none">
438 <tgroup cols="$cols">
439 <colspec colwidth="1*"${empty_element_end}
440 <colspec colwidth="1*"${empty_element_end}
441 <colspec colwidth="1*"${empty_element_end}
447 foreach $object (sort (@Objects)) {
448 my $xref = &MakeXRef ($object);
449 if ($count % $cols == 0) { print (OUTPUT "<row>\n"); }
450 print (OUTPUT "<entry>$xref</entry>\n");
451 if ($count % $cols == ($cols - 1)) { print (OUTPUT "</row>\n"); }
455 # emit an empty row, since empty tables are invalid
456 print (OUTPUT "<row><entry> </entry></row>\n");
459 print (OUTPUT "</row>\n");
462 print (OUTPUT <<EOF);
463 </tbody></tgroup></informaltable>
467 &UpdateFileIfChanged ($old_object_index, $new_object_index, 0);
471 #############################################################################
472 # Function : OutputSGML
473 # Description : This collects the output for each section of the docs, and
474 # outputs each file when the end of the section is found.
475 # Arguments : $file - the $MODULE-sections.txt file which contains all of
476 # the functions/macros/structs etc. being documented, organised
477 # into sections and subsections.
478 #############################################################################
483 #print "Reading: $file\n";
485 || die "Can't open $file: $!";
488 my $book_bottom = "";
489 my $includes = (defined $DEFAULT_INCLUDES) ? $DEFAULT_INCLUDES : "";
490 my $section_includes = "";
499 my $signals_synop = "";
500 my $signals_desc = "";
502 my $child_args_synop = "";
503 my $style_args_synop = "";
505 my $child_args_desc = "";
506 my $style_args_desc = "";
509 my $implementations = "";
510 my $prerequisites = "";
512 my @file_objects = ();
514 my %symbol_def_line = ();
516 # merge the source docs, in case there are no templates
517 &MergeSourceDocumentation;
523 } elsif (m/^<SECTION>/) {
529 %symbol_def_line = ();
531 } elsif (m/^<SUBSECTION\s*(.*)>/i) {
535 } elsif (m/^<SUBSECTION>/) {
537 } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
539 #print "Section: $title\n";
541 # We don't want warnings if object & class structs aren't used.
542 $DeclarationOutput{$title} = 1;
543 $DeclarationOutput{"${title}Class"} = 1;
544 $DeclarationOutput{"${title}Iface"} = 1;
545 $DeclarationOutput{"${title}Interface"} = 1;
547 } elsif (m/^<FILE>(.*)<\/FILE>/) {
549 if (! defined $templates{$filename}) {
550 if (&ReadTemplateFile ("$TMPL_DIR/$filename", 1)) {
551 &MergeSourceDocumentation;
552 $templates{$filename}=$.;
555 &LogWarning ($file, $., "Double <FILE>$filename</FILE> entry. ".
556 "Previous occurrence on line ".$templates{$filename}.".");
558 if (($title eq "") and (defined $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"})) {
559 $title = $SourceSymbolDocs{"$TMPL_DIR/$filename:Title"};
560 # Remove trailing blanks
564 } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
566 $section_includes = $1;
568 if (defined $DEFAULT_INCLUDES) {
569 &LogWarning ($file, $., "Default <INCLUDE> being overridden by command line option.");
576 } elsif (m/^<\/SECTION>/) {
577 #print "End of section: $title\n";
578 if ($num_symbols > 0) {
580 if ($OUTPUT_FORMAT eq "xml") {
581 $book_bottom .= " <xi:include href=\"xml/$filename.xml\"/>\n";
583 $book_top.="<!ENTITY $section_id SYSTEM \"sgml/$filename.sgml\">\n";
584 $book_bottom .= " &$section_id;\n";
587 if (defined ($SourceSymbolDocs{"$TMPL_DIR/$filename:Include"})) {
588 if ($section_includes) {
589 &LogWarning ($file, $., "Section <INCLUDE> being overridden by inline comments.");
591 $section_includes = $SourceSymbolDocs{"$TMPL_DIR/$filename:Include"};
593 if ($section_includes eq "") {
594 $section_includes = $includes;
597 $signals_synop =~ s/^\n*//g;
598 $signals_synop =~ s/\n+$/\n/g;
599 if ($signals_synop ne '') {
600 $signals_synop = <<EOF;
601 <refsect1 id="$section_id.signals" role="signal_proto">
602 <title role="signal_proto.title">Signals</title>
604 ${signals_synop}</synopsis>
607 $signals_desc =~ s/^\n*//g;
608 $signals_desc =~ s/\n+$/\n/g;
609 $signals_desc =~ s/(\s|\n)+$//ms;
610 $signals_desc = <<EOF;
611 <refsect1 id="$section_id.signal-details" role="signals">
612 <title role="signals.title">Signal Details</title>
618 $args_synop =~ s/^\n*//g;
619 $args_synop =~ s/\n+$/\n/g;
620 if ($args_synop ne '') {
622 <refsect1 id="$section_id.properties" role="properties">
623 <title role="properties.title">Properties</title>
625 ${args_synop}</synopsis>
628 $args_desc =~ s/^\n*//g;
629 $args_desc =~ s/\n+$/\n/g;
630 $args_desc =~ s/(\s|\n)+$//ms;
632 <refsect1 id="$section_id.property-details" role="property_details">
633 <title role="property_details.title">Property Details</title>
639 $child_args_synop =~ s/^\n*//g;
640 $child_args_synop =~ s/\n+$/\n/g;
641 if ($child_args_synop ne '') {
642 $args_synop .= <<EOF;
643 <refsect1 id="$section_id.child-properties" role="child_properties">
644 <title role="child_properties.title">Child Properties</title>
646 ${child_args_synop}</synopsis>
649 $child_args_desc =~ s/^\n*//g;
650 $child_args_desc =~ s/\n+$/\n/g;
651 $child_args_desc =~ s/(\s|\n)+$//ms;
653 <refsect1 id="$section_id.child-property-details" role="child_property_details">
654 <title role="child_property_details.title">Child Property Details</title>
660 $style_args_synop =~ s/^\n*//g;
661 $style_args_synop =~ s/\n+$/\n/g;
662 if ($style_args_synop ne '') {
663 $args_synop .= <<EOF;
664 <refsect1 id="$section_id.style-properties" role="style_properties">
665 <title role="style_properties.title">Style Properties</title>
667 ${style_args_synop}</synopsis>
670 $style_args_desc =~ s/^\n*//g;
671 $style_args_desc =~ s/\n+$/\n/g;
672 $style_args_desc =~ s/(\s|\n)+$//ms;
674 <refsect1 id="$section_id.style-property-details" role="style_properties_details">
675 <title role="style_properties_details.title">Style Property Details</title>
681 $hierarchy =~ s/^\n*//g;
682 $hierarchy =~ s/\n+$/\n/g;
683 $hierarchy =~ s/(\s|\n)+$//ms;
684 if ($hierarchy ne "") {
686 <refsect1 id="$section_id.object-hierarchy" role="object_hierarchy">
687 <title role="object_hierarchy.title">Object Hierarchy</title>
693 $interfaces =~ s/^\n*//g;
694 $interfaces =~ s/\n+$/\n/g;
695 $interfaces =~ s/(\s|\n)+$//ms;
696 if ($interfaces ne "") {
698 <refsect1 id="$section_id.implemented-interfaces" role="impl_interfaces">
699 <title role="impl_interfaces.title">Implemented Interfaces</title>
705 $implementations =~ s/^\n*//g;
706 $implementations =~ s/\n+$/\n/g;
707 $implementations =~ s/(\s|\n)+$//ms;
708 if ($implementations ne "") {
709 $implementations = <<EOF;
710 <refsect1 id="$section_id.implementations" role="implementations">
711 <title role="implementations.title">Known Implementations</title>
717 $prerequisites =~ s/^\n*//g;
718 $prerequisites =~ s/\n+$/\n/g;
719 $prerequisites =~ s/(\s|\n)+$//ms;
720 if ($prerequisites ne "") {
721 $prerequisites = <<EOF;
722 <refsect1 id="$section_id.prerequisites" role="prerequisites">
723 <title role="prerequisites.title">Prerequisites</title>
729 $derived =~ s/^\n*//g;
730 $derived =~ s/\n+$/\n/g;
731 $derived =~ s/(\s|\n)+$//ms;
732 if ($derived ne "") {
734 <refsect1 id="$section_id.derived-interfaces" role="derived_interfaces">
735 <title role="derived_interfaces.title">Known Derived Interfaces</title>
741 $synopsis =~ s/^\n*//g;
742 $synopsis =~ s/\n+$/\n/g;
743 my $file_changed = &OutputSGMLFile ($filename, $title, $section_id,
745 \$synopsis, \$details,
746 \$signals_synop, \$signals_desc,
747 \$args_synop, \$args_desc,
748 \$hierarchy, \$interfaces,
750 \$prerequisites, \$derived,
760 $section_includes = "";
764 $child_args_synop = "";
765 $style_args_synop = "";
767 $child_args_desc = "";
768 $style_args_desc = "";
771 $implementations = "";
775 } elsif (m/^(\S+)/) {
777 #print " Symbol: $symbol\n";
779 # check for duplicate entries
780 if (! defined $symbol_def_line{$symbol}) {
781 my $declaration = $Declarations{$symbol};
782 if (defined ($declaration)) {
783 # We don't want standard macros/functions of GObjects,
784 # or private declarations.
785 if ($subsection ne "Standard" && $subsection ne "Private") {
786 if (&CheckIsObject ($symbol)) {
787 push @file_objects, $symbol;
789 my ($synop, $desc) = &OutputDeclaration ($symbol,
791 my ($sig_synop, $sig_desc) = &GetSignals ($symbol);
792 my ($arg_synop, $child_arg_synop, $style_arg_synop,
793 $arg_desc, $child_arg_desc, $style_arg_desc) = &GetArgs ($symbol);
794 my $hier = &GetHierarchy ($symbol);
795 my $ifaces = &GetInterfaces ($symbol);
796 my $impls = &GetImplementations ($symbol);
797 my $prereqs = &GetPrerequisites ($symbol);
798 my $der = &GetDerived ($symbol);
801 $signals_synop .= $sig_synop;
802 $signals_desc .= $sig_desc;
803 $args_synop .= $arg_synop;
804 $child_args_synop .= $child_arg_synop;
805 $style_args_synop .= $style_arg_synop;
806 $args_desc .= $arg_desc;
807 $child_args_desc .= $child_arg_desc;
808 $style_args_desc .= $style_arg_desc;
810 $interfaces .= $ifaces;
811 $implementations .= $impls;
812 $prerequisites .= $prereqs;
816 # Note that the declaration has been output.
817 $DeclarationOutput{$symbol} = 1;
818 } elsif ($subsection ne "Standard" && $subsection ne "Private") {
819 $UndeclaredSymbols{$symbol} = 1;
820 &LogWarning ($file, $., "No declaration found for $symbol.");
823 $symbol_def_line{$symbol}=$.;
825 if ($section_id eq "") {
826 if($title eq "" && $filename eq "") {
827 &LogWarning ($file, $., "Section has no title and no file.");
829 # FIXME: one of those would be enough
830 # filename should be an internal detail for gtk-doc
833 } elsif ($filename eq "") {
836 $filename =~ s/\s/_/g;
838 $section_id = $SourceSymbolDocs{"$TMPL_DIR/$filename:Section_Id"};
839 if (defined ($section_id) && $section_id !~ m/^\s*$/) {
840 # Remove trailing blanks and use as is
841 $section_id =~ s/\s+$//;
842 } elsif (&CheckIsObject ($title)) {
843 # GObjects use their class name as the ID.
844 $section_id = &CreateValidSGMLID ($title);
846 $section_id = &CreateValidSGMLID ("$MODULE-$title");
849 $SymbolSection{$symbol}=$title;
850 $SymbolSectionId{$symbol}=$section_id;
853 &LogWarning ($file, $., "Double symbol entry for $symbol. ".
854 "Previous occurrence on line ".$symbol_def_line{$symbol}.".");
860 &OutputMissingDocumentation;
861 &OutputUndeclaredSymbols;
862 &OutputUnusedSymbols;
864 if ($OUTPUT_ALL_SYMBOLS) {
867 if ($OUTPUT_SYMBOLS_WITHOUT_SINCE) {
868 &OutputSymbolsWithoutSince;
871 for $filename (split (' ', $EXPAND_CONTENT_FILES)) {
872 my $file_changed = &OutputExtraFile ($filename);
878 &OutputBook ($book_top, $book_bottom);
883 #############################################################################
884 # Function : OutputIndex
885 # Description : This writes an indexlist that can be included into the main-
886 # document into an <index> tag.
887 #############################################################################
890 my ($basename, $apiindexref ) = @_;
891 my %apiindex = %{$apiindexref};
892 my $old_index = "$SGML_OUTPUT_DIR/$basename.xml";
893 my $new_index = "$SGML_OUTPUT_DIR/$basename.new";
894 my $lastletter = " ";
899 open (OUTPUT, ">$new_index")
900 || die "Can't create $new_index";
902 my $header = $doctype_header;
903 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE indexdiv/;
905 print (OUTPUT "$header<indexdiv>\n");
907 #print "generate $basename index (".%apiindex." entries)\n";
909 # do a case insensitive sort while chopping off the prefix
911 sort { $$a{criteria} cmp $$b{criteria} }
912 map { my $x = uc($_); $x =~ s/^$NAME_SPACE\_?(.*)/$1/i; { criteria => $x, original => $_, short => $1 } }
915 $symbol = $$hash{original};
916 if (defined($$hash{short})) {
917 $short_symbol = $$hash{short};
919 $short_symbol = $symbol;
922 # generate a short symbol description
923 my $symbol_desc = "";
924 my $symbol_section = "";
925 my $symbol_section_id = "";
926 my $symbol_type = lc($DeclarationTypes{$symbol});
927 if ($symbol_type eq "") {
928 #print "trying symbol $symbol\n";
929 if ($symbol =~ m/(.*)::(.*)/) {
933 #print " trying object signal ${oname}:$osym in ".$#SignalNames." signals\n";
934 for ($i = 0; $i <= $#SignalNames; $i++) {
935 if ($SignalNames[$i] eq $osym) {
936 $symbol_type = "object signal";
937 if (defined($SymbolSection{$oname})) {
938 $symbol_section = $SymbolSection{$oname};
939 $symbol_section_id = $SymbolSectionId{$oname};
944 } elsif ($symbol =~ m/(.*):(.*)/) {
948 #print " trying object property ${oname}::$osym in ".$#ArgNames." properties\n";
949 for ($i = 0; $i <= $#ArgNames; $i++) {
950 #print " ".$ArgNames[$i]."\n";
951 if ($ArgNames[$i] eq $osym) {
952 $symbol_type = "object property";
953 if (defined($SymbolSection{$oname})) {
954 $symbol_section = $SymbolSection{$oname};
955 $symbol_section_id = $SymbolSectionId{$oname};
962 if (defined($SymbolSection{$symbol})) {
963 $symbol_section = $SymbolSection{$symbol};
964 $symbol_section_id = $SymbolSectionId{$symbol};
967 if ($symbol_type ne "") {
968 $symbol_desc=", $symbol_type";
969 if ($symbol_section ne "") {
970 $symbol_desc.=" in <link linkend=\"$symbol_section_id\">$symbol_section</link>";
971 #$symbol_desc.=" in ". &ExpandAbbreviations($symbol, "#$symbol_section");
975 my $curletter = uc(substr($short_symbol,0,1));
976 my $id = $apiindex{$symbol};
978 #print " add symbol $symbol with $id to index in section $curletter\n";
980 if ($curletter ne $lastletter) {
981 $lastletter = $curletter;
984 print (OUTPUT "</indexdiv>\n");
986 print (OUTPUT "<indexdiv><title>$curletter</title>\n");
990 print (OUTPUT <<EOF);
991 <indexentry><primaryie linkends="$id"><link linkend="$id">$symbol</link>$symbol_desc</primaryie></indexentry>
996 print (OUTPUT "</indexdiv>\n");
998 print (OUTPUT "</indexdiv>\n");
1001 &UpdateFileIfChanged ($old_index, $new_index, 0);
1005 #############################################################################
1006 # Function : OutputIndexFull
1007 # Description : This writes the full api indexlist that can be included into the
1008 # main document into an <index> tag.
1009 #############################################################################
1011 sub OutputIndexFull {
1012 &OutputIndex ("api-index-full", \%IndexEntriesFull);
1016 #############################################################################
1017 # Function : OutputDeprecatedIndex
1018 # Description : This writes the deprecated api indexlist that can be included
1019 # into the main document into an <index> tag.
1020 #############################################################################
1022 sub OutputDeprecatedIndex {
1023 &OutputIndex ("api-index-deprecated", \%IndexEntriesDeprecated);
1027 #############################################################################
1028 # Function : OutputSinceIndexes
1029 # Description : This writes the 'since' api indexlists that can be included into
1030 # the main document into an <index> tag.
1031 #############################################################################
1033 sub OutputSinceIndexes {
1034 my @sinces = keys %{{ map { $_ => 1 } values %Since }};
1036 foreach my $version (@sinces) {
1037 #print "Since : [$version]\n";
1038 # TODO make filtered hash
1039 #my %index = grep { $Since{$_} eq $version } %IndexEntriesSince;
1040 my %index = map { $_ => $IndexEntriesSince{$_} } grep { $Since{$_} eq $version } keys %IndexEntriesSince;
1042 &OutputIndex ("api-index-$version", \%index);
1046 #############################################################################
1047 # Function : OutputAnnotationGlossary
1048 # Description : This writes a glossary of the used annotation terms into a
1049 # separate glossary file that can be included into the main
1051 #############################################################################
1053 sub OutputAnnotationGlossary {
1054 my $old_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.xml";
1055 my $new_glossary = "$SGML_OUTPUT_DIR/annotation-glossary.new";
1056 my $lastletter = " ";
1059 # if there are no annotations used return
1060 return if (! keys(%AnnotationsUsed));
1062 # add acronyms that are referenced from acronym text
1064 foreach my $annotation (keys(%AnnotationsUsed)) {
1065 if($AnnotationDefinition{$annotation} =~ m/<acronym>([\w ]+)<\/acronym>/) {
1066 if (!exists($AnnotationsUsed{$1})) {
1067 $AnnotationsUsed{$1} = 1;
1073 open (OUTPUT, ">$new_glossary")
1074 || die "Can't create $new_glossary";
1076 my $header = $doctype_header;
1077 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE glossary/;
1079 print (OUTPUT <<EOF);
1081 <glossary id="annotation-glossary">
1082 <title>Annotation Glossary</title>
1085 foreach my $annotation (keys(%AnnotationsUsed)) {
1086 my $def = $AnnotationDefinition{$annotation};
1087 my $curletter = uc(substr($annotation,0,1));
1089 if ($curletter ne $lastletter) {
1090 $lastletter = $curletter;
1092 if ($divopen == 1) {
1093 print (OUTPUT "</glossdiv>\n");
1095 print (OUTPUT "<glossdiv><title>$curletter</title>\n");
1098 print (OUTPUT <<EOF);
1100 <glossterm><anchor id="annotation-glossterm-$annotation"/>$annotation</glossterm>
1108 if ($divopen == 1) {
1109 print (OUTPUT "</glossdiv>\n");
1111 print (OUTPUT "</glossary>\n");
1114 &UpdateFileIfChanged ($old_glossary, $new_glossary, 0);
1117 #############################################################################
1118 # Function : ReadKnownSymbols
1119 # Description : This collects the names of non-private symbols from the
1120 # $MODULE-sections.txt file.
1121 # Arguments : $file - the $MODULE-sections.txt file which contains all of
1122 # the functions/macros/structs etc. being documented, organised
1123 # into sections and subsections.
1124 #############################################################################
1126 sub ReadKnownSymbols {
1129 my $subsection = "";
1131 #print "Reading: $file\n";
1133 || die "Can't open $file: $!";
1139 } elsif (m/^<SECTION>/) {
1142 } elsif (m/^<SUBSECTION\s*(.*)>/i) {
1145 } elsif (m/^<SUBSECTION>/) {
1148 } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
1151 } elsif (m/^<FILE>(.*)<\/FILE>/) {
1152 $KnownSymbols{"$TMPL_DIR/$1:Long_Description"} = 1;
1153 $KnownSymbols{"$TMPL_DIR/$1:Short_Description"} = 1;
1156 } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
1159 } elsif (m/^<\/SECTION>/) {
1162 } elsif (m/^(\S+)/) {
1165 if ($subsection ne "Standard" && $subsection ne "Private") {
1166 $KnownSymbols{$symbol} = 1;
1169 $KnownSymbols{$symbol} = 0;
1177 #############################################################################
1178 # Function : OutputDeclaration
1179 # Description : Returns the synopsis and detailed description DocBook
1180 # describing one function/macro etc.
1181 # Arguments : $symbol - the name of the function/macro begin described.
1182 # $declaration - the declaration of the function/macro.
1183 #############################################################################
1185 sub OutputDeclaration {
1186 my ($symbol, $declaration) = @_;
1188 my $type = $DeclarationTypes {$symbol};
1189 if ($type eq 'MACRO') {
1190 return &OutputMacro ($symbol, $declaration);
1191 } elsif ($type eq 'TYPEDEF') {
1192 return &OutputTypedef ($symbol, $declaration);
1193 } elsif ($type eq 'STRUCT') {
1194 return &OutputStruct ($symbol, $declaration);
1195 } elsif ($type eq 'ENUM') {
1196 return &OutputEnum ($symbol, $declaration);
1197 } elsif ($type eq 'UNION') {
1198 return &OutputUnion ($symbol, $declaration);
1199 } elsif ($type eq 'VARIABLE') {
1200 return &OutputVariable ($symbol, $declaration);
1201 } elsif ($type eq 'FUNCTION') {
1202 return &OutputFunction ($symbol, $declaration, $type);
1203 } elsif ($type eq 'USER_FUNCTION') {
1204 return &OutputFunction ($symbol, $declaration, $type);
1206 die "Unknown symbol type";
1211 #############################################################################
1212 # Function : OutputSymbolTraits
1213 # Description : Returns the Since and StabilityLevel paragraphs for a symbol.
1214 # Arguments : $symbol - the name of the function/macro begin described.
1215 #############################################################################
1217 sub OutputSymbolTraits {
1221 if (exists $Since{$symbol}) {
1222 $desc .= "<para role=\"since\">Since $Since{$symbol}</para>";
1224 if (exists $StabilityLevel{$symbol}) {
1225 $desc .= "<para role=\"stability\">Stability Level: $StabilityLevel{$symbol}</para>";
1230 #############################################################################
1231 # Function : Outpu{Symbol,Section}ExtraLinks
1232 # Description : Returns extralinks for the symbol (if enabled).
1233 # Arguments : $symbol - the name of the function/macro begin described.
1234 #############################################################################
1238 return undef unless defined $text;
1240 # Build a char to hex map
1243 $escapes{chr($_)} = sprintf("%%%02X", $_);
1246 # Default unsafe characters. RFC 2732 ^(uric - reserved)
1247 $text =~ s/([^A-Za-z0-9\-_.!~*'()])/$escapes{$1}/g;
1252 sub OutputSymbolExtraLinks {
1256 if (0) { # NEW FEATURE: needs configurability
1257 my $sstr = &uri_escape($symbol);
1258 my $mstr = &uri_escape($MODULE);
1260 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1261 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&symbol=$sstr">edit documentation</ulink>
1267 sub OutputSectionExtraLinks {
1268 my ($symbol,$docsymbol) = @_;
1271 if (0) { # NEW FEATURE: needs configurability
1272 my $sstr = &uri_escape($symbol);
1273 my $mstr = &uri_escape($MODULE);
1274 my $dsstr = &uri_escape($docsymbol);
1276 <ulink role="extralinks" url="http://www.google.com/codesearch?q=$sstr">code search</ulink>
1277 <ulink role="extralinks" url="http://library.gnome.org/edit?module=$mstr&symbol=$dsstr">edit documentation</ulink>
1284 #############################################################################
1285 # Function : OutputMacro
1286 # Description : Returns the synopsis and detailed description of a macro.
1287 # Arguments : $symbol - the macro.
1288 # $declaration - the declaration of the macro.
1289 #############################################################################
1292 my ($symbol, $declaration) = @_;
1293 my $id = &CreateValidSGMLID ($symbol);
1294 my $condition = &MakeConditionDescription ($symbol);
1295 my $synop = &MakeReturnField("#define") . "<link linkend=\"$id\">$symbol</link>";
1298 my @fields = ParseMacroDeclaration($declaration, \&CreateValidSGML);
1299 my $title = $symbol . (@fields ? "()" : "");
1301 $desc = "<refsect2 id=\"$id\" role=\"macro\"$condition>\n<title>$title</title>\n";
1302 $desc .= MakeIndexterms($symbol, $id);
1304 $desc .= OutputSymbolExtraLinks($symbol);
1307 if (length ($symbol) < $SYMBOL_FIELD_WIDTH) {
1308 $synop .= (' ' x ($SYMBOL_FIELD_WIDTH - length ($symbol)));
1312 for (my $i = 1; $i <= $#fields; $i += 2) {
1313 my $field_name = $fields[$i];
1316 $synop .= "$field_name";
1319 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1327 # Don't output the macro definition if is is a conditional macro or it
1328 # looks like a function, i.e. starts with "g_" or "_?gnome_", or it is
1329 # longer than 2 lines, otherwise we get lots of complicated macros like
1331 if (!defined ($DeclarationConditional{$symbol}) && ($symbol !~ m/^g_/)
1332 && ($symbol !~ m/^_?gnome_/) && (($declaration =~ tr/\n//) < 2)) {
1333 my $decl_out = &CreateValidSGML ($declaration);
1334 $desc .= "<programlisting>$decl_out</programlisting>\n";
1336 $desc .= "<programlisting>" . &MakeReturnField("#define") . "$symbol";
1337 if ($declaration =~ m/^\s*#\s*define\s+\w+(\([^\)]*\))/) {
1339 my $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH - length ("#define "));
1340 # Align each line so that if should all line up OK.
1341 $args =~ s/\n/\n$pad/gm;
1342 $desc .= &CreateValidSGML ($args);
1344 $desc .= "</programlisting>\n";
1347 $desc .= &MakeDeprecationNote($symbol);
1349 my $parameters = &OutputParamDescriptions ("MACRO", $symbol, @fields);
1350 my $parameters_output = 0;
1352 if (defined ($SymbolDocs{$symbol})) {
1353 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1355 # Try to insert the parameter table at the author's desired position.
1356 # Otherwise we need to tag it onto the end.
1357 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1358 $parameters_output = 1;
1360 $desc .= $symbol_docs;
1363 if ($parameters_output == 0) {
1364 $desc .= $parameters;
1367 $desc .= OutputSymbolTraits ($symbol);
1368 $desc .= "</refsect2>\n";
1369 return ($synop, $desc);
1373 #############################################################################
1374 # Function : OutputTypedef
1375 # Description : Returns the synopsis and detailed description of a typedef.
1376 # Arguments : $symbol - the typedef.
1377 # $declaration - the declaration of the typedef,
1378 # e.g. 'typedef unsigned int guint;'
1379 #############################################################################
1382 my ($symbol, $declaration) = @_;
1383 my $id = &CreateValidSGMLID ($symbol);
1384 my $condition = &MakeConditionDescription ($symbol);
1385 my $synop = &MakeReturnField("typedef") . "<link linkend=\"$id\">$symbol</link>;\n";
1386 my $desc = "<refsect2 id=\"$id\" role=\"typedef\"$condition>\n<title>$symbol</title>\n";
1388 $desc .= MakeIndexterms($symbol, $id);
1390 $desc .= OutputSymbolExtraLinks($symbol);
1392 if (!defined ($DeclarationConditional{$symbol})) {
1393 my $decl_out = &CreateValidSGML ($declaration);
1394 $desc .= "<programlisting>$decl_out</programlisting>\n";
1397 $desc .= &MakeDeprecationNote($symbol);
1399 if (defined ($SymbolDocs{$symbol})) {
1400 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1402 $desc .= OutputSymbolTraits ($symbol);
1403 $desc .= "</refsect2>\n";
1404 return ($synop, $desc);
1408 #############################################################################
1409 # Function : OutputStruct
1410 # Description : Returns the synopsis and detailed description of a struct.
1411 # We check if it is a object struct, and if so we only output
1412 # parts of it that are noted as public fields.
1413 # We also use a different SGML ID for object structs, since the
1414 # original ID is used for the entire RefEntry.
1415 # Arguments : $symbol - the struct.
1416 # $declaration - the declaration of the struct.
1417 #############################################################################
1420 my ($symbol, $declaration) = @_;
1422 my $is_object_struct = 0;
1423 my $default_to_public = 1;
1424 if (&CheckIsObject ($symbol)) {
1425 #print "Found object struct: $symbol\n";
1426 $is_object_struct = 1;
1427 $default_to_public = 0;
1432 if ($is_object_struct) {
1433 $id = &CreateValidSGMLID ($symbol . "_struct");
1434 $condition = &MakeConditionDescription ($symbol . "_struct");
1436 $id = &CreateValidSGMLID ($symbol);
1437 $condition = &MakeConditionDescription ($symbol);
1440 # Determine if it is a simple struct or it also has a typedef.
1441 my $has_typedef = 0;
1442 if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1449 # For structs with typedefs we just output the struct name.
1450 $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1451 $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>$symbol</title>\n";
1453 $synop = &MakeReturnField("struct") . "<link linkend=\"$id\">$symbol</link>;\n";
1454 $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>struct $symbol</title>\n";
1457 $desc .= MakeIndexterms($symbol, $id);
1459 $desc .= OutputSymbolExtraLinks($symbol);
1461 # Form a pretty-printed, private-data-removed form of the declaration
1464 if ($declaration =~ m/^\s*$/) {
1465 #print "Found opaque struct: $symbol\n";
1466 $decl_out = "typedef struct _$symbol $symbol;";
1467 } elsif ($declaration =~ m/^\s*struct\s+\w+\s*;\s*$/) {
1468 #print "Found opaque struct: $symbol\n";
1469 $decl_out = "struct $symbol;";
1471 my $public = $default_to_public;
1472 my $new_declaration = "";
1474 my $decl = $declaration;
1476 if ($decl =~ m/^\s*(typedef\s+)?struct\s*\w*\s*(?:\/\*.*\*\/)?\s*{(.*)}\s*\w*\s*;\s*$/s) {
1477 my $struct_contents = $2;
1479 foreach $decl_line (split (/\n/, $struct_contents)) {
1480 #print "Struct line: $decl_line\n";
1481 if ($decl_line =~ m%/\*\s*<\s*public\s*>\s*\*/%) {
1483 } elsif ($decl_line =~ m%/\*\s*<\s*(private|protected)\s*>\s*\*/%) {
1486 $new_declaration .= $decl_line . "\n";
1490 if ($new_declaration) {
1491 # Strip any blank lines off the ends.
1492 $new_declaration =~ s/^\s*\n//;
1493 $new_declaration =~ s/\n\s*$/\n/;
1496 $decl_out = "typedef struct {\n" . $new_declaration
1499 $decl_out = "struct $symbol {\n" . $new_declaration
1504 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1505 "Couldn't parse struct:\n$declaration");
1508 # If we couldn't parse the struct or it was all private, output an
1509 # empty struct declaration.
1510 if ($decl_out eq "") {
1512 $decl_out = "typedef struct _$symbol $symbol;";
1514 $decl_out = "struct $symbol;";
1519 $decl_out = &CreateValidSGML ($decl_out);
1520 $desc .= "<programlisting>$decl_out</programlisting>\n";
1522 $desc .= &MakeDeprecationNote($symbol);
1524 if (defined ($SymbolDocs{$symbol})) {
1525 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1528 # Create a table of fields and descriptions
1530 # FIXME: Inserting  's into the produced type declarations here would
1531 # improve the output in most situations ... except for function
1532 # members of structs!
1533 my @fields = ParseStructDeclaration($declaration, !$default_to_public,
1536 "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1538 my $params = $SymbolParams{$symbol};
1540 # If no parameters are filled in, we don't generate the description
1541 # table, for backwards compatibility
1544 if (defined $params) {
1545 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1546 if ($params->[$i] =~ /\S/) {
1554 my %field_descrs = @$params;
1555 my $missing_parameters = "";
1556 my $unused_parameters = "";
1558 $desc .= "<variablelist role=\"struct\">\n";
1560 my $field_name = shift @fields;
1561 my $text = shift @fields;
1562 my $field_descr = $field_descrs{$field_name};
1563 my $param_annotations = "";
1565 $desc .= "<varlistentry><term>$text</term>\n";
1566 if (defined $field_descr) {
1567 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1568 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1569 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1570 delete $field_descrs{$field_name};
1572 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1573 "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1574 if ($missing_parameters ne "") {
1575 $missing_parameters .= ", ".$field_name;
1577 $missing_parameters = $field_name;
1579 $desc .= "<listitem />\n";
1581 $desc .= "</varlistentry>\n";
1583 $desc .= "</variablelist>";
1584 foreach my $field_name (keys %field_descrs) {
1585 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1586 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1587 if ($unused_parameters ne "") {
1588 $unused_parameters .= ", ".$field_name;
1590 $unused_parameters = $field_name;
1594 # remember missing/unused parameters (needed in tmpl-free build)
1595 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1596 $AllIncompleteSymbols{$symbol}=$missing_parameters;
1598 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1599 $AllUnusedSymbols{$symbol}=$unused_parameters;
1603 if (scalar(@fields) > 0) {
1604 if (! exists ($AllIncompleteSymbols{$symbol})) {
1605 $AllIncompleteSymbols{$symbol}="<items>";
1606 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1607 "Field descriptions for $symbol are missing in source code comment block.");
1612 $desc .= OutputSymbolTraits ($symbol);
1613 $desc .= "</refsect2>\n";
1614 return ($synop, $desc);
1618 #############################################################################
1619 # Function : OutputUnion
1620 # Description : Returns the synopsis and detailed description of a union.
1621 # Arguments : $symbol - the union.
1622 # $declaration - the declaration of the union.
1623 #############################################################################
1626 my ($symbol, $declaration) = @_;
1627 my $id = &CreateValidSGMLID ($symbol);
1628 my $condition = &MakeConditionDescription ($symbol);
1630 # Determine if it is a simple struct or it also has a typedef.
1631 my $has_typedef = 0;
1632 if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1639 # For unions with typedefs we just output the union name.
1640 $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1641 $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>$symbol</title>\n";
1643 $synop = &MakeReturnField("union") . "<link linkend=\"$id\">$symbol</link>;\n";
1644 $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>union $symbol</title>\n";
1647 $desc .= MakeIndexterms($symbol, $id);
1649 $desc .= OutputSymbolExtraLinks($symbol);
1651 # FIXME: we do more for structs
1652 my $decl_out = &CreateValidSGML ($declaration);
1653 $desc .= "<programlisting>$decl_out</programlisting>\n";
1655 $desc .= &MakeDeprecationNote($symbol);
1657 if (defined ($SymbolDocs{$symbol})) {
1658 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1661 # Create a table of fields and descriptions
1663 # FIXME: Inserting  's into the produced type declarations here would
1664 # improve the output in most situations ... except for function
1665 # members of structs!
1666 my @fields = ParseStructDeclaration($declaration, 0,
1669 "<structfield id=\"".&CreateValidSGMLID("$id.$_[0]")."\">$_[0]</structfield>";
1671 my $params = $SymbolParams{$symbol};
1673 # If no parameters are filled in, we don't generate the description
1674 # table, for backwards compatibility
1677 if (defined $params) {
1678 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1679 if ($params->[$i] =~ /\S/) {
1687 my %field_descrs = @$params;
1688 my $missing_parameters = "";
1689 my $unused_parameters = "";
1691 $desc .= "<variablelist role=\"union\">\n";
1693 my $field_name = shift @fields;
1694 my $text = shift @fields;
1695 my $field_descr = $field_descrs{$field_name};
1696 my $param_annotations = "";
1698 $desc .= "<varlistentry><term>$text</term>\n";
1699 if (defined $field_descr) {
1700 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1701 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1702 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1703 delete $field_descrs{$field_name};
1705 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1706 "Field description for $symbol"."::"."$field_name is missing in source code comment block.");
1707 if ($missing_parameters ne "") {
1708 $missing_parameters .= ", ".$field_name;
1710 $missing_parameters = $field_name;
1712 $desc .= "<listitem />\n";
1714 $desc .= "</varlistentry>\n";
1716 $desc .= "</variablelist>";
1717 foreach my $field_name (keys %field_descrs) {
1718 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1719 "Field description for $symbol"."::"."$field_name is not used from source code comment block.");
1720 if ($unused_parameters ne "") {
1721 $unused_parameters .= ", ".$field_name;
1723 $unused_parameters = $field_name;
1727 # remember missing/unused parameters (needed in tmpl-free build)
1728 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1729 $AllIncompleteSymbols{$symbol}=$missing_parameters;
1731 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1732 $AllUnusedSymbols{$symbol}=$unused_parameters;
1736 if (scalar(@fields) > 0) {
1737 if (! exists ($AllIncompleteSymbols{$symbol})) {
1738 $AllIncompleteSymbols{$symbol}="<items>";
1739 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1740 "Field descriptions for $symbol are missing in source code comment block.");
1745 $desc .= OutputSymbolTraits ($symbol);
1746 $desc .= "</refsect2>\n";
1747 return ($synop, $desc);
1751 #############################################################################
1752 # Function : OutputEnum
1753 # Description : Returns the synopsis and detailed description of a enum.
1754 # Arguments : $symbol - the enum.
1755 # $declaration - the declaration of the enum.
1756 #############################################################################
1759 my ($symbol, $declaration) = @_;
1760 my $id = &CreateValidSGMLID ($symbol);
1761 my $condition = &MakeConditionDescription ($symbol);
1762 my $synop = &MakeReturnField("enum") . "<link linkend=\"$id\">$symbol</link>;\n";
1763 my $desc = "<refsect2 id=\"$id\" role=\"enum\"$condition>\n<title>enum $symbol</title>\n";
1765 $desc .= MakeIndexterms($symbol, $id);
1767 $desc .= OutputSymbolExtraLinks($symbol);
1769 my $decl_out = &CreateValidSGML ($declaration);
1770 $desc .= "<programlisting>$decl_out</programlisting>\n";
1772 $desc .= &MakeDeprecationNote($symbol);
1774 if (defined ($SymbolDocs{$symbol})) {
1775 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1778 # Create a table of fields and descriptions
1780 my @fields = ParseEnumDeclaration($declaration);
1781 my $params = $SymbolParams{$symbol};
1783 # If no parameters are filled in, we don't generate the description
1784 # table, for backwards compatibility
1787 if (defined $params) {
1788 for (my $i = 1; $i <= $#$params; $i += $PARAM_FIELD_COUNT) {
1789 if ($params->[$i] =~ /\S/) {
1797 my %field_descrs = @$params;
1798 my $missing_parameters = "";
1799 my $unused_parameters = "";
1801 $desc .= "<variablelist role=\"enum\">\n";
1802 for my $field_name (@fields) {
1803 my $field_descr = $field_descrs{$field_name};
1804 my $param_annotations = "";
1806 $id = &CreateValidSGMLID ($field_name);
1807 $condition = &MakeConditionDescription ($field_name);
1808 $desc .= "<varlistentry id=\"$id\" role=\"constant\"$condition>\n<term><literal>$field_name</literal></term>\n";
1809 if (defined $field_descr) {
1810 ($field_descr,$param_annotations) = &ExpandAnnotation($symbol, $field_descr);
1811 $field_descr = &ExpandAbbreviations($symbol, $field_descr);
1812 $desc .= "<listitem><simpara>$field_descr$param_annotations</simpara></listitem>\n";
1813 delete $field_descrs{$field_name};
1815 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1816 "Value description for $symbol"."::"."$field_name is missing in source code comment block.");
1817 if ($missing_parameters ne "") {
1818 $missing_parameters .= ", ".$field_name;
1820 $missing_parameters = $field_name;
1822 $desc .= "<listitem />\n";
1824 $desc .= "</varlistentry>\n";
1826 $desc .= "</variablelist>";
1827 foreach my $field_name (keys %field_descrs) {
1828 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1829 "Value description for $symbol"."::"."$field_name is not used from source code comment block.");
1830 if ($unused_parameters ne "") {
1831 $unused_parameters .= ", ".$field_name;
1833 $unused_parameters = $field_name;
1837 # remember missing/unused parameters (needed in tmpl-free build)
1838 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
1839 $AllIncompleteSymbols{$symbol}=$missing_parameters;
1841 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
1842 $AllUnusedSymbols{$symbol}=$unused_parameters;
1846 if (scalar(@fields) > 0) {
1847 if (! exists ($AllIncompleteSymbols{$symbol})) {
1848 $AllIncompleteSymbols{$symbol}="<items>";
1849 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1850 "Value descriptions for $symbol are missing in source code comment block.");
1855 $desc .= OutputSymbolTraits ($symbol);
1856 $desc .= "</refsect2>\n";
1857 return ($synop, $desc);
1861 #############################################################################
1862 # Function : OutputVariable
1863 # Description : Returns the synopsis and detailed description of a variable.
1864 # Arguments : $symbol - the extern'ed variable.
1865 # $declaration - the declaration of the variable.
1866 #############################################################################
1868 sub OutputVariable {
1869 my ($symbol, $declaration) = @_;
1870 my $id = &CreateValidSGMLID ($symbol);
1871 my $condition = &MakeConditionDescription ($symbol);
1874 if ($declaration =~ m/^\s*extern\s+((const\s+|unsigned\s+)*\w+)(\s+\*+|\*+|\s)(\s*)([A-Za-z]\w*)\s*;/) {
1875 my $mod = defined ($1) ? $1 : "";
1876 my $ptr = defined ($3) ? $3 : "";
1877 my $space = defined ($4) ? $4 : "";
1878 $synop = &MakeReturnField("extern") . "$mod$ptr$space<link linkend=\"$id\">$symbol</link>;\n";
1881 $synop = &MakeReturnField("extern") . "<link linkend=\"$id\">$symbol</link>;\n";
1884 my $desc = "<refsect2 id=\"$id\" role=\"variable\"$condition>\n<title>$symbol</title>\n";
1886 $desc .= MakeIndexterms($symbol, $id);
1888 $desc .= OutputSymbolExtraLinks($symbol);
1890 my $decl_out = &CreateValidSGML ($declaration);
1891 $desc .= "<programlisting>$decl_out</programlisting>\n";
1893 $desc .= &MakeDeprecationNote($symbol);
1895 if (defined ($SymbolDocs{$symbol})) {
1896 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1898 $desc .= OutputSymbolTraits ($symbol);
1899 $desc .= "</refsect2>\n";
1900 return ($synop, $desc);
1904 #############################################################################
1905 # Function : OutputFunction
1906 # Description : Returns the synopsis and detailed description of a function.
1907 # Arguments : $symbol - the function.
1908 # $declaration - the declaration of the function.
1909 #############################################################################
1911 sub OutputFunction {
1912 my ($symbol, $declaration, $symbol_type) = @_;
1913 my $id = &CreateValidSGMLID ($symbol);
1914 my $condition = &MakeConditionDescription ($symbol);
1916 # Take out the return type $1 $3 $4
1917 $declaration =~ s/<RETURNS>\s*((const\s+|G_CONST_RETURN\s+|unsigned\s+|long\s+|short\s+|struct\s+|enum\s+)*)(\w+)(\s*\**\s*(const|G_CONST_RETURN)?\s*\**\s*(restrict)?\s*)<\/RETURNS>\n//;
1918 my $type_modifier = defined($1) ? $1 : "";
1921 #print "$symbol pointer is $pointer\n";
1922 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
1924 #if ($symbol_type eq 'USER_FUNCTION') {
1925 # $start = "typedef ";
1928 # We output const rather than G_CONST_RETURN.
1929 $type_modifier =~ s/G_CONST_RETURN/const/g;
1930 $pointer =~ s/G_CONST_RETURN/const/g;
1931 $pointer =~ s/^\s+/ /g;
1933 my $ret_type_len = length ($start) + length ($type_modifier)
1934 + length ($pointer) + length ($type);
1935 my $ret_type_output;
1937 if ($ret_type_len < $RETURN_TYPE_FIELD_WIDTH) {
1938 $ret_type_output = "$start$type_modifier$xref$pointer"
1939 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
1942 #$ret_type_output = "$start$type_modifier$xref$pointer\n" . (' ' x $RETURN_TYPE_FIELD_WIDTH);
1944 $ret_type_output = "$start$type_modifier$xref$pointer ";
1945 $symbol_len = $ret_type_len + 1 - $RETURN_TYPE_FIELD_WIDTH;
1948 $symbol_len += length ($symbol);
1949 my $char1 = my $char2 = my $char3 = "";
1950 if ($symbol_type eq 'USER_FUNCTION') {
1957 my ($symbol_output, $symbol_desc_output);
1958 if ($symbol_len < $SYMBOL_FIELD_WIDTH) {
1959 $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3"
1960 . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1961 $symbol_desc_output = "$char1$char2$symbol$char3"
1962 . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1964 $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3\n"
1965 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1966 $symbol_desc_output = "$char1$char2$symbol$char3\n"
1967 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1970 my $synop = $ret_type_output . $symbol_output . '(';
1971 my $desc = "<refsect2 id=\"$id\" role=\"function\"$condition>\n<title>${symbol} ()</title>\n";
1973 $desc .= MakeIndexterms($symbol, $id);
1975 $desc .= OutputSymbolExtraLinks($symbol);
1977 $desc .= "<programlisting>${ret_type_output}$symbol_desc_output(";
1979 my @fields = ParseFunctionDeclaration($declaration, \&MakeXRef,
1981 &tagify($_[0],"parameter");
1984 for (my $i = 1; $i <= $#fields; $i += 2) {
1985 my $field_name = $fields[$i];
1987 if ($field_name eq "Varargs") {
1988 $field_name = "...";
1992 $synop .= "$field_name";
1993 $desc .= "$field_name";
1996 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1999 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
2006 $desc .= ");</programlisting>\n";
2008 $desc .= &MakeDeprecationNote($symbol);
2010 my $parameters = &OutputParamDescriptions ("FUNCTION", $symbol, @fields);
2011 my $parameters_output = 0;
2013 if (defined ($SymbolDocs{$symbol})) {
2014 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
2016 # Try to insert the parameter table at the author's desired position.
2017 # Otherwise we need to tag it onto the end.
2018 # FIXME: document that in the user manual and make it useable for other
2020 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
2021 $parameters_output = 1;
2023 $desc .= $symbol_docs;
2026 if ($parameters_output == 0) {
2027 $desc .= $parameters;
2030 $desc .= OutputSymbolTraits ($symbol);
2031 $desc .= "</refsect2>\n";
2032 return ($synop, $desc);
2036 #############################################################################
2037 # Function : OutputParamDescriptions
2038 # Description : Returns the DocBook output describing the parameters of a
2039 # function, macro or signal handler.
2040 # Arguments : $symbol_type - 'FUNCTION', 'MACRO' or 'SIGNAL'. Signal
2041 # handlers have an implicit user_data parameter last.
2042 # $symbol - the name of the function/macro being described.
2043 # @fields - parsed fields from the declaration, used to determine
2044 # undocumented/unused entries
2045 #############################################################################
2047 sub OutputParamDescriptions {
2048 my ($symbol_type, $symbol, @fields) = @_;
2050 my $params = $SymbolParams{$symbol};
2052 my %field_descrs = ();
2055 %field_descrs = @fields;
2056 delete $field_descrs{"void"};
2057 delete $field_descrs{"Returns"};
2060 if (defined $params) {
2062 my $params_desc = "";
2063 my $missing_parameters = "";
2064 my $unused_parameters = "";
2067 for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
2068 my $param_name = $$params[$j];
2069 my $param_desc = $$params[$j + 1];
2070 my $param_annotations = "";
2072 ($param_desc,$param_annotations) = & ExpandAnnotation($symbol, $param_desc);
2073 $param_desc = &ExpandAbbreviations($symbol, $param_desc);
2074 $param_desc .= $param_annotations;
2075 if ($param_name eq "Returns") {
2076 $returns = "$param_desc";
2077 } elsif ($param_name eq "void") {
2078 #print "!!!! void in params for $symbol?\n";
2081 if (!defined $field_descrs{$param_name}) {
2082 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2083 "Parameter description for $symbol"."::"."$param_name is not used from source code comment block.");
2084 if ($unused_parameters ne "") {
2085 $unused_parameters .= ", ".$param_name;
2087 $unused_parameters = $param_name;
2090 delete $field_descrs{$param_name};
2093 if ($param_name eq "Varargs") {
2094 $param_name = "...";
2096 if($param_desc ne "") {
2097 $params_desc .= "<varlistentry><term><parameter>$param_name</parameter> :</term>\n<listitem><simpara>$param_desc</simpara></listitem></varlistentry>\n";
2102 foreach my $param_name (keys %field_descrs) {
2103 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2104 "Parameter description for $symbol"."::"."$param_name is missing in source code comment block.");
2105 if ($missing_parameters ne "") {
2106 $missing_parameters .= ", ".$param_name;
2108 $missing_parameters = $param_name;
2112 # Signals have an implicit user_data parameter which we describe.
2113 if ($symbol_type eq "SIGNAL") {
2114 $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";
2117 # Start a table if we need one.
2118 if ($params_desc || $returns) {
2119 $output .= "<variablelist role=\"params\">\n";
2120 if ($params_desc ne "") {
2121 #$output .= "<varlistentry><term>Parameters:</term><listitem></listitem></varlistentry>\n";
2122 $output .= $params_desc;
2125 # Output the returns info last.
2127 $output .= "<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>$returns</simpara></listitem></varlistentry>\n";
2131 $output .= "</variablelist>";
2134 # remember missing/unused parameters (needed in tmpl-free build)
2135 if (($missing_parameters ne "") and (! exists ($AllIncompleteSymbols{$symbol}))) {
2136 $AllIncompleteSymbols{$symbol}=$missing_parameters;
2138 if (($unused_parameters ne "") and (! exists ($AllUnusedSymbols{$symbol}))) {
2139 $AllUnusedSymbols{$symbol}=$unused_parameters;
2142 if (($num_params == 0) && @fields && (scalar(keys(%field_descrs)) > 0)) {
2143 if (! exists ($AllIncompleteSymbols{$symbol})) {
2144 $AllIncompleteSymbols{$symbol}="<parameters>";
2152 #############################################################################
2153 # Function : ParseStabilityLevel
2154 # Description : Parses a stability level and outputs a warning if it isn't
2156 # Arguments : $stability - the stability text.
2157 # $file, $line - context for error message
2158 # $message - description of where the level is from, to use in
2159 # any error message.
2160 # Returns : The parsed stability level string.
2161 #############################################################################
2163 sub ParseStabilityLevel {
2164 my ($stability, $file, $line, $message) = @_;
2166 $stability =~ s/^\s*//;
2167 $stability =~ s/\s*$//;
2168 if ($stability =~ m/^stable$/i) {
2169 $stability = "Stable";
2170 } elsif ($stability =~ m/^unstable$/i) {
2171 $stability = "Unstable";
2172 } elsif ($stability =~ m/^private$/i) {
2173 $stability = "Private";
2175 &LogWarning ($file, $line, "$message is $stability.".
2176 "It should be one of these: Stable, Unstable, or Private.");
2182 #############################################################################
2183 # Function : OutputSGMLFile
2184 # Description : Outputs the final DocBook file for one section.
2185 # Arguments : $file - the name of the file.
2186 # $title - the title from the $MODULE-sections.txt file, which
2187 # will be overridden by the title in the template file.
2188 # $section_id - the SGML id to use for the toplevel tag.
2189 # $includes - comma-separates list of include files added at top
2190 # of synopsis, with '<' '>' around them (if not already enclosed in "").
2191 # $synopsis - reference to the DocBook for the Synopsis part.
2192 # $details - reference to the DocBook for the Details part.
2193 # $signal_synop - reference to the DocBook for the Signal Synopsis part
2194 # $signal_desc - reference to the DocBook for the Signal Description part
2195 # $args_synop - reference to the DocBook for the Arg Synopsis part
2196 # $args_desc - reference to the DocBook for the Arg Description part
2197 # $hierarchy - reference to the DocBook for the Object Hierarchy part
2198 # $interfaces - reference to the DocBook for the Interfaces part
2199 # $implementations - reference to the DocBook for the Known Implementations part
2200 # $prerequisites - reference to the DocBook for the Prerequisites part
2201 # $derived - reference to the DocBook for the Derived Interfaces part
2202 # $file_objects - reference to an array of objects in this file
2203 #############################################################################
2205 sub OutputSGMLFile {
2206 my ($file, $title, $section_id, $includes, $synopsis, $details, $signals_synop, $signals_desc, $args_synop, $args_desc, $hierarchy, $interfaces, $implementations, $prerequisites, $derived, $file_objects) = @_;
2208 #print "Output sgml for file $file with title '$title'\n";
2210 # The edited title overrides the one from the sections file.
2211 my $new_title = $SymbolDocs{"$TMPL_DIR/$file:Title"};
2212 if (defined ($new_title) && $new_title !~ m/^\s*$/) {
2213 $title = $new_title;
2214 #print "Found title: $title\n";
2216 my $short_desc = $SymbolDocs{"$TMPL_DIR/$file:Short_Description"};
2217 if (!defined ($short_desc) || $short_desc =~ m/^\s*$/) {
2220 $short_desc = &ExpandAbbreviations("$title:Short_description",
2222 #print "Found short_desc: $short_desc";
2224 my $long_desc = $SymbolDocs{"$TMPL_DIR/$file:Long_Description"};
2225 if (!defined ($long_desc) || $long_desc =~ m/^\s*$/) {
2228 $long_desc = &ExpandAbbreviations("$title:Long_description",
2230 #print "Found long_desc: $long_desc";
2232 my $see_also = $SymbolDocs{"$TMPL_DIR/$file:See_Also"};
2233 if (!defined ($see_also) || $see_also =~ m%^\s*(<para>)?\s*(</para>)?\s*$%) {
2236 $see_also = &ExpandAbbreviations("$title:See_Also", $see_also);
2237 #print "Found see_also: $see_also";
2240 $see_also = "<refsect1 id=\"$section_id.see-also\">\n<title>See Also</title>\n$see_also\n</refsect1>\n";
2242 my $stability = $SymbolDocs{"$TMPL_DIR/$file:Stability_Level"};
2243 if (!defined ($stability) || $stability =~ m/^\s*$/) {
2246 $stability = &ParseStabilityLevel($stability, $file, $., "Section stability level");
2247 #print "Found stability: $stability";
2250 $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$stability, unless otherwise indicated\n</refsect1>\n";
2251 } elsif ($DEFAULT_STABILITY) {
2252 $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$DEFAULT_STABILITY, unless otherwise indicated\n</refsect1>\n";
2255 my $image = $SymbolDocs{"$TMPL_DIR/$file:Image"};
2256 if (!defined ($image) || $image =~ m/^\s*$/) {
2264 if ($image =~ /jpe?g$/i) {
2265 $format = "format='JPEG'";
2266 } elsif ($image =~ /png$/i) {
2267 $format = "format='PNG'";
2268 } elsif ($image =~ /svg$/i) {
2269 $format = "format='SVG'";
2274 $image = " <inlinegraphic fileref='$image' $format/>\n"
2277 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
2279 my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
2282 my $include_output = "";
2284 foreach $include (split (/,/, $includes)) {
2285 if ($include =~ m/^\".+\"$/) {
2286 $include_output .= "#include ${include}\n";
2289 $include =~ s/^\s+|\s+$//gs;
2290 $include_output .= "#include <${include}>\n";
2293 if ($include_output ne '') {
2294 $include_output = "\n$include_output\n";
2297 my $extralinks = OutputSectionExtraLinks($title,"Section:$file");
2299 my $old_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT";
2300 my $new_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT.new";
2302 open (OUTPUT, ">$new_sgml_file")
2303 || die "Can't create $new_sgml_file: $!";
2305 my $object_anchors = "";
2306 foreach my $object (@$file_objects) {
2307 next if ($object eq $section_id);
2308 my $id = CreateValidSGMLID($object);
2309 #print "Debug: Adding anchor for $object\n";
2310 $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
2313 # We used to output this, but is messes up our UpdateFileIfChanged code
2314 # since it changes every day (and it is only used in the man pages):
2315 # "<refentry id="$section_id" revision="$mday $month $year">"
2317 if ($OUTPUT_FORMAT eq "xml") {
2318 print OUTPUT $doctype_header;
2322 <refentry id="$section_id">
2324 <refentrytitle role="top_of_page" id="$section_id.top_of_page">$title</refentrytitle>
2325 <manvolnum>3</manvolnum>
2328 $image</refmiscinfo>
2331 <refname>$title</refname>
2332 <refpurpose>$short_desc</refpurpose>
2335 <refsynopsisdiv id="$section_id.synopsis" role="synopsis">
2336 <title role="synopsis.title">Synopsis</title>
2338 <synopsis>$include_output$${synopsis}</synopsis>
2340 $$hierarchy$$prerequisites$$derived$$interfaces$$implementations$$args_synop$$signals_synop
2341 <refsect1 id="$section_id.description" role="desc">
2342 <title role="desc.title">Description</title>
2343 $extralinks$long_desc
2345 <refsect1 id="$section_id.details" role="details">
2346 <title role="details.title">Details</title>
2349 $$args_desc$$signals_desc$see_also
2354 return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2358 #############################################################################
2359 # Function : OutputExtraFile
2360 # Description : Copies an "extra" DocBook file into the output directory,
2361 # expanding abbreviations
2362 # Arguments : $file - the source file.
2363 #############################################################################
2364 sub OutputExtraFile {
2369 ($basename = $file) =~ s!^.*/!!;
2371 my $old_sgml_file = "$SGML_OUTPUT_DIR/$basename";
2372 my $new_sgml_file = "$SGML_OUTPUT_DIR/$basename.new";
2376 open(EXTRA_FILE, "<$file") || die "Can't open $file";
2380 $contents = <EXTRA_FILE>;
2383 open (OUTPUT, ">$new_sgml_file")
2384 || die "Can't create $new_sgml_file: $!";
2386 print OUTPUT &ExpandAbbreviations ("$basename file", $contents);
2389 return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
2391 #############################################################################
2392 # Function : OutputBook
2393 # Description : Outputs the SGML entities that need to be included into the
2394 # main SGML file for the module.
2395 # Arguments : $book_top - the declarations of the entities, which are added
2396 # at the top of the main SGML file.
2397 # $book_bottom - the references to the entities, which are
2398 # added in the main SGML file at the desired position.
2399 #############################################################################
2402 my ($book_top, $book_bottom) = @_;
2404 my $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top";
2405 my $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top.new";
2407 open (OUTPUT, ">$new_file")
2408 || die "Can't create $new_file: $!";
2409 print OUTPUT $book_top;
2412 &UpdateFileIfChanged ($old_file, $new_file, 0);
2415 $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom";
2416 $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom.new";
2418 open (OUTPUT, ">$new_file")
2419 || die "Can't create $new_file: $!";
2420 print OUTPUT $book_bottom;
2423 &UpdateFileIfChanged ($old_file, $new_file, 0);
2426 # If the main SGML/XML file hasn't been created yet, we create it here.
2427 # The user can tweak it later.
2428 if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
2429 open (OUTPUT, ">$MAIN_SGML_FILE")
2430 || die "Can't create $MAIN_SGML_FILE: $!";
2432 if ($OUTPUT_FORMAT eq "xml") {
2434 <?xml version="1.0"?>
2435 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
2436 "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
2438 <!ENTITY % local.common.attrib "xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'">
2444 <!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
2453 <title>$MODULE Reference Manual</title>
2455 for $MODULE [VERSION].
2456 The latest version of this documentation can be found on-line at
2457 <ulink role="online-location" url="http://[SERVER]/$MODULE/index.html">http://[SERVER]/$MODULE/</ulink>.
2462 <title>[Insert title here]</title>
2466 if (-e $OBJECT_TREE_FILE) {
2468 <chapter id="object-tree">
2469 <title>Object Hierarchy</title>
2470 <xi:include href="xml/tree_index.sgml"/>
2476 <index id="api-index-full">
2477 <title>API Index</title>
2478 <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
2481 <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
2490 #############################################################################
2491 # Function : CreateValidSGML
2492 # Description : This turns any chars which are used in SGML into entities,
2493 # e.g. '<' into '<'
2494 # Arguments : $text - the text to turn into proper SGML.
2495 #############################################################################
2497 sub CreateValidSGML {
2499 $text =~ s/&/&/g; # Do this first, or the others get messed up.
2500 $text =~ s/</</g;
2501 $text =~ s/>/>/g;
2502 # browers render single tabs inconsistently
2503 $text =~ s/([^\s])\t([^\s])/$1 $2/g;
2507 #############################################################################
2508 # Function : ConvertSGMLChars
2509 # Description : This is used for text in source code comment blocks, to turn
2510 # chars which are used in SGML into entities, e.g. '<' into
2511 # '<'. Depending on $SGML_MODE, this is done
2512 # unconditionally or only if the character doesn't seem to be
2513 # part of an SGML construct (tag or entity reference).
2514 # Arguments : $text - the text to turn into proper SGML.
2515 #############################################################################
2517 sub ConvertSGMLChars {
2518 my ($symbol, $text) = @_;
2521 # For the SGML mode only convert to entities outside CDATA sections.
2522 return &ModifyXMLElements ($text, $symbol,
2523 "<!\\[CDATA\\[|<programlisting[^>]*>",
2524 \&ConvertSGMLCharsEndTag,
2525 \&ConvertSGMLCharsCallback);
2527 # For the simple non-sgml mode, convert to entities everywhere.
2528 $text =~ s/&/&/g; # Do this first, or the others get messed up.
2529 $text =~ s/</</g;
2530 $text =~ s/>/>/g;
2536 sub ConvertSGMLCharsEndTag {
2537 if ($_[0] eq "<!\[CDATA\[") {
2540 return "</programlisting>";
2544 sub ConvertSGMLCharsCallback {
2545 my ($text, $symbol, $tag) = @_;
2547 if ($tag =~ m/^<programlisting/) {
2548 # We can handle <programlisting> specially here.
2549 return &ModifyXMLElements ($text, $symbol,
2551 \&ConvertSGMLCharsEndTag,
2552 \&ConvertSGMLCharsCallback2);
2553 } elsif ($tag eq "") {
2554 # If we're not in CDATA convert to entities.
2555 $text =~ s/&(?![a-zA-Z#]+;)/&/g; # Do this first, or the others get messed up.
2556 $text =~ s/<(?![a-zA-Z\/!])/</g;
2557 $text =~ s/(?<![a-zA-Z0-9"'\/-])>/>/g;
2559 # Handle "#include <xxxxx>"
2560 $text =~ s/#include(\s+)<([^>]+)>/#include$1<$2>/g;
2566 sub ConvertSGMLCharsCallback2 {
2567 my ($text, $symbol, $tag) = @_;
2569 # If we're not in CDATA convert to entities.
2570 # We could handle <programlisting> differently, though I'm not sure it helps.
2572 # replace only if its not a tag
2573 $text =~ s/&(?![a-zA-Z#]+;)/&/g; # Do this first, or the others get messed up.
2574 $text =~ s/<(?![a-zA-Z\/!])/</g;
2575 $text =~ s/(?<![a-zA-Z0-9"'\/-])>/>/g;
2577 # Handle "#include <xxxxx>"
2578 $text =~ s/#include(\s+)<([^>]+)>/#include$1<$2>/g;
2584 #############################################################################
2585 # Function : ExpandAnnotation
2586 # Description : This turns annotations into acrony tags.
2587 # Arguments : $symbol - the symbol being documented, for error messages.
2588 # $text - the text to expand.
2589 #############################################################################
2590 sub ExpandAnnotation {
2591 my ($symbol, $param_desc) = @_;
2592 my $param_annotations = "";
2594 if ($param_desc =~ m%\s*\((.*)\):%) {
2597 my $annotation_extra = "";
2600 @annotations = split(/\)\s*\(/,$1);
2601 foreach $annotation (@annotations) {
2602 # need to search for the longest key-match in %AnnotationDefinition
2604 my $match_annotation="";
2606 foreach $annotationdef (keys %AnnotationDefinition) {
2607 if ($annotation =~ m/^$annotationdef/) {
2608 if (length($annotationdef)>$match_length) {
2609 $match_length=length($annotationdef);
2610 $match_annotation=$annotationdef;
2614 if ($match_annotation ne "") {
2615 if ($annotation =~ m%$match_annotation\s+(.*)%) {
2616 $annotation_extra = " $1";
2618 $AnnotationsUsed{$match_annotation} = 1;
2619 $param_annotations .= "<acronym>$match_annotation</acronym>$annotation_extra. ";
2622 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2623 "unknown annotation \"$annotation\" in documentation for $symbol.");
2624 $param_annotations=$annotation;
2628 $param_desc =~ m/^(.*)\.*\s*$/;
2629 $param_desc = "$1. ";
2631 return ($param_desc, $param_annotations);
2634 #############################################################################
2635 # Function : ExpandAbbreviations
2636 # Description : This turns the abbreviations function(), macro(), @param,
2637 # %constant, and #symbol into appropriate DocBook markup.
2638 # CDATA sections and <programlisting> parts are skipped.
2639 # Arguments : $symbol - the symbol being documented, for error messages.
2640 # $text - the text to expand.
2641 #############################################################################
2643 sub ExpandAbbreviations {
2644 my ($symbol, $text) = @_;
2646 # Convert "|[" and "]|" into the start and end of program listing examples.
2647 $text =~ s%\|\[%<informalexample><programlisting>%g;
2648 $text =~ s%\]\|%</programlisting></informalexample>%g;
2649 # TODO: check for a xml comment after |[ and pick the language attribute from
2652 # keep CDATA unmodified, preserve ulink tags (ideally we preseve all tags
2654 return &ModifyXMLElements ($text, $symbol,
2655 "<!\\[CDATA\\[|<ulink[^>]*>|<programlisting[^>]*>|<!DOCTYPE",
2656 \&ExpandAbbreviationsEndTag,
2657 \&ExpandAbbreviationsCallback);
2661 # Returns the end tag corresponding to the given start tag.
2662 sub ExpandAbbreviationsEndTag {
2663 my ($start_tag) = @_;
2665 if ($start_tag eq "<!\[CDATA\[") {
2667 } elsif ($start_tag eq "<!DOCTYPE") {
2669 } elsif ($start_tag =~ m/<(\w+)/) {
2674 # Called inside or outside each CDATA or <programlisting> section.
2675 sub ExpandAbbreviationsCallback {
2676 my ($text, $symbol, $tag) = @_;
2678 if ($tag =~ m/^<programlisting/) {
2679 # Handle any embedded CDATA sections.
2680 return &ModifyXMLElements ($text, $symbol,
2682 \&ExpandAbbreviationsEndTag,
2683 \&ExpandAbbreviationsCallback2);
2684 } elsif ($tag eq "") {
2685 # We are outside any CDATA or <programlisting> sections, so we expand
2686 # any gtk-doc abbreviations.
2688 # Convert 'function()' or 'macro()'.
2689 # if there is abc_*_def() we don't want to make a link to _def()
2690 # FIXME: also handle abc(....) : but that would need to be done recursively :/
2691 $text =~ s/([^\*.\w])(\w+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2692 # handle #Object.func()
2693 $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)\s*\(\)/$1.&MakeXRef($2, &tagify($2 . "()", "function"));/eg;
2695 # Convert '@param', but not '\@param'.
2696 $text =~ s/(\A|[^\\])\@(\w+((\.|->)\w+)*)/$1<parameter>$2<\/parameter>/g;
2697 $text =~ s/\\\@/\@/g;
2699 # Convert '%constant', but not '\%constant'.
2700 # Also allow negative numbers, e.g. %-1.
2701 $text =~ s/(\A|[^\\])\%(-?\w+)/$1.&MakeXRef($2, &tagify($2, "literal"));/eg;
2702 $text =~ s/\\\%/\%/g;
2704 # Convert '#symbol', but not '\#symbol'.
2705 $text =~ s/(\A|[^\\])#([\w\-:\.]+[\w]+)/$1.&MakeHashXRef($2, "type");/eg;
2709 # FIXME: should we skip urls that are already tagged? (e.g. <literal>http://...</literal>)
2710 # this is apparently also called for markup and not just for plain text
2712 #$text =~ s%(http|https|ftp)://(.*?)((?:\s|,|\)|\]|\<|\.\s))%<ulink url="$1://$2">$2</ulink>$3%g;
2714 # TODO: optionally check all words from $text against internal symbols and
2715 # warn if those could be xreffed, but miss a %,# or ()
2721 # This is called inside a <programlisting>
2722 sub ExpandAbbreviationsCallback2 {
2723 my ($text, $symbol, $tag) = @_;
2726 # We are inside a <programlisting> but outside any CDATA sections,
2727 # so we expand any gtk-doc abbreviations.
2728 # FIXME: why is this different from &ExpandAbbreviationsCallback(),
2729 # why not just call it
2730 $text =~ s/#(\w+)/&MakeHashXRef($1, "");/eg;
2737 my ($symbol, $tag) = @_;;
2740 # Check for things like '#include', '#define', and skip them.
2741 if ($PreProcessorDirectives{$symbol}) {
2745 # Get rid of any special '-struct' suffix.
2746 $text =~ s/-struct$//;
2748 # If the symbol is in the form "Object::signal", then change the symbol to
2749 # "Object-signal" and use "signal" as the text.
2750 if ($symbol =~ s/::/-/) {
2754 # If the symbol is in the form "Object:property", then change the symbol to
2755 # "Object--property" and use "property" as the text.
2756 if ($symbol =~ s/:/--/) {
2761 $text = tagify ($text, $tag);
2764 return &MakeXRef($symbol, $text);
2768 #############################################################################
2769 # Function : ModifyXMLElements
2770 # Description : Looks for given XML element tags within the text, and calls
2771 # the callback on pieces of text inside & outside those elements.
2772 # Used for special handling of text inside things like CDATA
2773 # and <programlisting>.
2774 # Arguments : $text - the text.
2775 # $symbol - the symbol currently being documented (only used for
2777 # $start_tag_regexp - the regular expression to match start tags.
2778 # e.g. "<!\\[CDATA\\[|<programlisting[^>]*>" to match
2779 # CDATA sections or programlisting elements.
2780 # $end_tag_func - function which is passed the matched start tag
2781 # and should return the appropriate end tag string.
2782 # $callback - callback called with each part of the text. It is
2783 # called with a piece of text, the symbol being
2784 # documented, and the matched start tag or "" if the text
2785 # is outside the XML elements being matched.
2786 #############################################################################
2787 sub ModifyXMLElements {
2788 my ($text, $symbol, $start_tag_regexp, $end_tag_func, $callback) = @_;
2789 my ($before_tag, $start_tag, $end_tag_regexp, $end_tag);
2792 while ($text =~ m/$start_tag_regexp/s) {
2793 $before_tag = $`; # Prematch for last successful match string
2794 $start_tag = $&; # Last successful match
2795 $text = $'; # Postmatch for last successful match string
2797 $result .= &$callback ($before_tag, $symbol, "");
2798 $result .= $start_tag;
2800 # get the mathing end-tag for current tag
2801 $end_tag_regexp = &$end_tag_func ($start_tag);
2803 if ($text =~ m/$end_tag_regexp/s) {
2808 $result .= &$callback ($before_tag, $symbol, $start_tag);
2809 $result .= $end_tag;
2811 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2812 "Can't find tag end: $end_tag_regexp in docs for: $symbol.");
2813 # Just assume it is all inside the tag.
2814 $result .= &$callback ($text, $symbol, $start_tag);
2819 # Handle any remaining text outside the tags.
2820 $result .= &$callback ($text, $symbol, "");
2829 # Adds a tag around some text.
2830 # e.g tagify("Text", "literal") => "<literal>Text</literal>".
2832 my ($text, $elem) = @_;
2833 return "<" . $elem . ">" . $text . "</" . $elem . ">";
2837 #############################################################################
2838 # Function : MakeXRef
2839 # Description : This returns a cross-reference link to the given symbol.
2840 # Though it doesn't try to do this for a few standard C types
2841 # that it knows won't be in the documentation.
2842 # Arguments : $symbol - the symbol to try to create a XRef to.
2843 # $text - text text to put inside the XRef, defaults to $symbol
2844 #############################################################################
2847 my ($symbol, $text) = ($_[0], $_[1]);
2849 $symbol =~ s/^\s+//;
2850 $symbol =~ s/\s+$//;
2852 if (!defined($text)) {
2855 # Get rid of special '-struct' suffix.
2856 $text =~ s/-struct$//;
2859 if ($symbol =~ m/ /) {
2863 #print "Getting type link for $symbol -> $text\n";
2865 my $symbol_id = &CreateValidSGMLID ($symbol);
2866 return "<link linkend=\"$symbol_id\">$text</link>";
2870 #############################################################################
2871 # Function : MakeIndexterms
2872 # Description : This returns a indexterm elements for the given symbol
2873 # Arguments : $symbol - the symbol to create indexterms for
2874 #############################################################################
2876 sub MakeIndexterms {
2877 my ($symbol, $id) = @_;
2881 # make the index useful, by ommiting the namespace when sorting
2882 if ($NAME_SPACE ne "") {
2883 if ($symbol =~ m/^$NAME_SPACE\_?(.*)/i) {
2884 $sortas=" sortas=\"$1\"";
2888 if (exists $Deprecated{$symbol}) {
2889 $terms .= "<indexterm zone=\"$id\" role=\"deprecated\"><primary$sortas>$symbol</primary></indexterm>";
2890 $IndexEntriesDeprecated{$symbol}=$id;
2891 $IndexEntriesFull{$symbol}=$id;
2893 if (exists $Since{$symbol}) {
2894 my $since = $Since{$symbol};
2898 $terms .= "<indexterm zone=\"$id\" role=\"$since\"><primary$sortas>$symbol</primary></indexterm>";
2900 $IndexEntriesSince{$symbol}=$id;
2901 $IndexEntriesFull{$symbol}=$id;
2904 $terms .= "<indexterm zone=\"$id\"><primary$sortas>$symbol</primary></indexterm>";
2905 $IndexEntriesFull{$symbol}=$id;
2911 #############################################################################
2912 # Function : MakeDeprecationNote
2913 # Description : This returns a deprecation warning for the given symbol.
2914 # Arguments : $symbol - the symbol to try to create a warning for.
2915 #############################################################################
2917 sub MakeDeprecationNote {
2918 my ($symbol) = $_[0];
2921 if (exists $Deprecated{$symbol}) {
2922 $desc .= "<warning>";
2924 if ($Deprecated{$symbol} =~ /^\s*([0-9\.]+)\s*:/) {
2925 $desc .= "<para><literal>$symbol</literal> has been deprecated since version $1 and should not be used in newly-written code.";
2927 $desc .= "<para><literal>$symbol</literal> is deprecated and should not be used in newly-written code.";
2929 if ($Deprecated{$symbol} ne "") {
2930 $note = &ExpandAbbreviations($symbol, $Deprecated{$symbol});
2931 $note =~ s/^\s*([0-9\.]+)\s*:\s*//;
2934 $note =~ s%\n{2,}%\n</para>\n<para>\n%g;
2935 $desc .= " " . $note;
2937 $desc .= "</para></warning>\n";
2942 #############################################################################
2943 # Function : MakeConditionDescription
2944 # Description : This returns a sumary of conditions for the given symbol.
2945 # Arguments : $symbol - the symbol to try to create the sumary.
2946 #############################################################################
2948 sub MakeConditionDescription {
2949 my ($symbol) = $_[0];
2952 if (exists $Deprecated{$symbol}) {
2957 if ($Deprecated{$symbol} =~ /^\s*(.*?)\s*$/) {
2958 $desc .= "deprecated:$1";
2960 $desc .= "deprecated";
2964 if (exists $Since{$symbol}) {
2969 if ($Since{$symbol} =~ /^\s*(.*?)\s*$/) {
2970 $desc .= "since:$1";
2976 if (exists $StabilityLevel{$symbol}) {
2980 $desc .= "stability:".$StabilityLevel{$symbol};
2984 $desc=" condition=\"".$desc."\"";
2985 #print "condition for '$symbol' = '$desc'\n";
2990 #############################################################################
2991 # Function : GetHierarchy
2992 # Description : Returns the DocBook output describing the ancestors and
2993 # immediate children of a GObject subclass. It uses the
2994 # global @Objects and @ObjectLevels arrays to walk the tree.
2995 # Arguments : $object - the GtkObject subclass.
2996 #############################################################################
3001 # Find object in the objects array.
3007 for ($i = 0; $i < @Objects; $i++) {
3009 if ($ObjectLevels[$i] <= $level) {
3012 elsif ($ObjectLevels[$i] == $level + 1) {
3013 push (@children, $Objects[$i]);
3016 elsif ($Objects[$i] eq $object) {
3019 $level = $ObjectLevels[$i];
3026 # Walk up the hierarchy, pushing ancestors onto the ancestors array.
3028 push (@ancestors, $object);
3029 #print "Level: $level\n";
3030 while ($level > 1) {
3032 if ($ObjectLevels[$j] < $level) {
3033 push (@ancestors, $Objects[$j]);
3034 $level = $ObjectLevels[$j];
3035 #print "Level: $level\n";
3039 # Output the ancestors list, indented and with links.
3040 my $hierarchy = "<synopsis>\n";
3042 for ($i = $#ancestors; $i >= 0; $i--) {
3044 # Don't add a link to the current object, i.e. when i == 0.
3046 my $ancestor_id = &CreateValidSGMLID ($ancestors[$i]);
3047 $link_text = "<link linkend=\"$ancestor_id\">$ancestors[$i]</link>";
3049 $link_text = "$ancestors[$i]";
3052 $hierarchy .= " $link_text\n";
3054 # $hierarchy .= ' ' x ($level * 6 - 3) . "|\n";
3055 $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3059 for ($i = 0; $i <= $#children; $i++) {
3060 my $id = &CreateValidSGMLID ($children[$i]);
3061 my $link_text = "<link linkend=\"$id\">$children[$i]</link>";
3062 $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
3064 $hierarchy .= "</synopsis>\n";
3070 #############################################################################
3071 # Function : GetInterfaces
3072 # Description : Returns the DocBook output describing the interfaces
3073 # implemented by a class. It uses the global %Interfaces hash.
3074 # Arguments : $object - the GtkObject subclass.
3075 #############################################################################
3082 # Find object in the objects array.
3083 if (exists($Interfaces{$object})) {
3084 my @ifaces = split(' ', $Interfaces{$object});
3089 for ($i = 0; $i <= $#ifaces; $i++) {
3090 my $id = &CreateValidSGMLID ($ifaces[$i]);
3091 $text .= " <link linkend=\"$id\">$ifaces[$i]</link>";
3092 if ($i < $#ifaces - 1) {
3095 elsif ($i < $#ifaces) {
3110 #############################################################################
3111 # Function : GetImplementations
3112 # Description : Returns the DocBook output describing the implementations
3113 # of an interface. It uses the global %Interfaces hash.
3114 # Arguments : $object - the GtkObject subclass.
3115 #############################################################################
3117 sub GetImplementations {
3122 foreach my $key (keys %Interfaces) {
3123 if ($Interfaces{$key} =~ /\b$object\b/) {
3124 push (@impls, $key);
3130 $object is implemented by
3132 for ($i = 0; $i <= $#impls; $i++) {
3133 my $id = &CreateValidSGMLID ($impls[$i]);
3134 $text .= " <link linkend=\"$id\">$impls[$i]</link>";
3135 if ($i < $#impls - 1) {
3138 elsif ($i < $#impls) {
3153 #############################################################################
3154 # Function : GetPrerequisites
3155 # Description : Returns the DocBook output describing the prerequisites
3156 # of an interface. It uses the global %Prerequisites hash.
3157 # Arguments : $iface - the interface.
3158 #############################################################################
3160 sub GetPrerequisites {
3165 if (exists($Prerequisites{$iface})) {
3170 my @prereqs = split(' ', $Prerequisites{$iface});
3171 for ($i = 0; $i <= $#prereqs; $i++) {
3172 my $id = &CreateValidSGMLID ($prereqs[$i]);
3173 $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
3174 if ($i < $#prereqs - 1) {
3177 elsif ($i < $#prereqs) {
3191 #############################################################################
3192 # Function : GetDerived
3193 # Description : Returns the DocBook output describing the derived interfaces
3194 # of an interface. It uses the global %Prerequisites hash.
3195 # Arguments : $iface - the interface.
3196 #############################################################################
3204 foreach my $key (keys %Prerequisites) {
3205 if ($Prerequisites{$key} =~ /\b$iface\b/) {
3206 push (@derived, $key);
3209 if ($#derived >= 0) {
3212 $iface is required by
3214 for ($i = 0; $i <= $#derived; $i++) {
3215 my $id = &CreateValidSGMLID ($derived[$i]);
3216 $text .= " <link linkend=\"$id\">$derived[$i]</link>";
3217 if ($i < $#derived - 1) {
3220 elsif ($i < $#derived) {
3235 #############################################################################
3236 # Function : GetSignals
3237 # Description : Returns the synopsis and detailed description DocBook output
3238 # for the signal handlers of a given GtkObject subclass.
3239 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
3240 #############################################################################
3248 for ($i = 0; $i <= $#SignalObjects; $i++) {
3249 if ($SignalObjects[$i] eq $object) {
3250 #print "Found signal: $SignalNames[$i]\n";
3251 my $name = $SignalNames[$i];
3252 my $symbol = "${object}::${name}";
3253 my $id = &CreateValidSGMLID ("$object-$name");
3255 my $pad = ' ' x (46 - length($name));
3256 $synop .= " "<link linkend=\"$id\">$name</link>"$pad ";
3258 $desc .= "<refsect2 id=\"$id\" role=\"signal\"><title>The <literal>"$name"</literal> signal</title>\n";
3259 $desc .= MakeIndexterms($symbol, $id);
3261 $desc .= OutputSymbolExtraLinks($symbol);
3263 $desc .= "<programlisting>";
3265 $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
3266 my $type_modifier = defined($1) ? $1 : "";
3269 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
3271 my $ret_type_len = length ($type_modifier) + length ($pointer)
3273 my $ret_type_output = "$type_modifier$xref$pointer"
3274 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
3276 $desc .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
3278 my $sourceparams = $SourceSymbolParams{$symbol};
3279 my @params = split ("\n", $SignalPrototypes[$i]);
3282 my $type_len = length("gpointer");
3283 my $name_len = length("user_data");
3284 # do two passes, the first one is to calculate padding
3285 for ($l = 0; $l < 2; $l++) {
3286 for ($j = 0; $j <= $#params; $j++) {
3287 # allow alphanumerics, '_', '[' & ']' in param names
3288 if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
3291 if (defined($sourceparams)) {
3292 $name = $$sourceparams[$PARAM_FIELD_COUNT * $j];
3297 if (!defined($name)) {
3301 if (length($type) + length($pointer) > $type_len) {
3302 $type_len = length($type) + length($pointer);
3304 if (length($name) > $name_len) {
3305 $name_len = length($name);
3309 $xref = &MakeXRef ($type, &tagify($type, "type"));
3310 $pad = ' ' x ($type_len - length($type) - length($pointer));
3311 $desc .= "$xref$pad $pointer$name,\n";
3312 $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
3315 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3316 "Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]");
3320 $xref = &MakeXRef ("gpointer", &tagify("gpointer", "type"));
3321 $pad = ' ' x ($type_len - length("gpointer"));
3322 $desc .= "$xref$pad user_data)";
3324 my $flags = $SignalFlags[$i];
3325 my $flags_string = "";
3327 if (defined ($flags)) {
3328 if ($flags =~ m/f/) {
3329 $flags_string = "Run First";
3331 elsif ($flags =~ m/l/) {
3332 $flags_string = "Run Last";
3334 elsif ($flags =~ m/c/) {
3335 $flags_string = "Cleanup";
3337 if ($flags =~ m/r/) {
3338 if ($flags_string) { $flags_string .= " / "; }
3339 $flags_string .= "No Recursion";
3341 if ($flags =~ m/d/) {
3342 if ($flags_string) { $flags_string .= " / "; }
3343 $flags_string .= "Has Details";
3345 if ($flags =~ m/a/) {
3346 if ($flags_string) { $flags_string .= " / "; }
3347 $flags_string .= "Action";
3349 if ($flags =~ m/h/) {
3350 if ($flags_string) { $flags_string .= " / "; }
3351 $flags_string .= "No Hooks";
3357 $synop .= ": $flags_string\n";
3359 $pad = ' ' x (5 + $name_len - length("user_data"));
3360 $desc .= "$pad : $flags_string</programlisting>\n";
3365 $desc .= "</programlisting>\n";
3368 $desc .= &MakeDeprecationNote($symbol);
3370 my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
3371 my $parameters_output = 0;
3373 $AllSymbols{$symbol} = 1;
3374 if (defined ($SymbolDocs{$symbol})) {
3375 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3377 # Try to insert the parameter table at the author's desired
3378 # position. Otherwise we need to tag it onto the end.
3379 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
3380 $parameters_output = 1;
3382 $desc .= $symbol_docs;
3384 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
3385 $AllDocumentedSymbols{$symbol} = 1;
3389 if ($parameters_output == 0) {
3390 $desc .= $parameters;
3392 $desc .= OutputSymbolTraits ($symbol);
3393 $desc .= "</refsect2>";
3396 return ($synop, $desc);
3400 #############################################################################
3401 # Function : GetArgs
3402 # Description : Returns the synopsis and detailed description DocBook output
3403 # for the Args of a given GtkObject subclass.
3404 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
3405 #############################################################################
3411 my $child_synop = "";
3412 my $child_desc = "";
3413 my $style_synop = "";
3414 my $style_desc = "";
3417 for ($i = 0; $i <= $#ArgObjects; $i++) {
3418 if ($ArgObjects[$i] eq $object) {
3419 #print "Found arg: $ArgNames[$i]\n";
3420 my $name = $ArgNames[$i];
3421 my $flags = $ArgFlags[$i];
3422 my $flags_string = "";
3426 if ($flags =~ m/c/) {
3427 $kind = "child property";
3430 elsif ($flags =~ m/s/) {
3431 $kind = "style property";
3438 # Remember only one colon so we don't clash with signals.
3439 my $symbol = "${object}:${name}";
3440 # use two dashes and ev. an extra separator here for the same reason.
3441 my $id = &CreateValidSGMLID ("$object--$id_sep$name");
3443 my $type = $ArgTypes[$i];
3445 my $range = $ArgRanges[$i];
3446 my $range_output = CreateValidSGML ($range);
3447 my $default = $ArgDefaults[$i];
3448 my $default_output = CreateValidSGML ($default);
3450 if ($type eq "GtkString") {
3453 if ($type eq "GtkSignal") {
3454 $type = "GtkSignalFunc, gpointer";
3455 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
3456 . &MakeXRef ("gpointer");
3457 } elsif ($type =~ m/^(\w+)\*$/) {
3458 $type_output = &MakeXRef ($1, &tagify($1, "type")) . "*";
3460 $type_output = &MakeXRef ($type, &tagify($type, "type"));
3463 if ($flags =~ m/r/) {
3464 $flags_string = "Read";
3466 if ($flags =~ m/w/) {
3467 if ($flags_string) { $flags_string .= " / "; }
3468 $flags_string .= "Write";
3470 if ($flags =~ m/x/) {
3471 if ($flags_string) { $flags_string .= " / "; }
3472 $flags_string .= "Construct";
3474 if ($flags =~ m/X/) {
3475 if ($flags_string) { $flags_string .= " / "; }
3476 $flags_string .= "Construct Only";
3479 $AllSymbols{$symbol} = 1;
3481 if (defined($SymbolDocs{$symbol}) &&
3482 !IsEmptyDoc($SymbolDocs{$symbol})) {
3483 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3484 #print ".. [$SymbolDocs{$symbol}][$blurb]\n";
3485 $AllDocumentedSymbols{$symbol} = 1;
3488 if (!($ArgBlurbs[$i] eq "")) {
3489 $AllDocumentedSymbols{$symbol} = 1;
3491 # FIXME: print a warning?
3492 #print ".. no description\n";
3494 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
3497 my $pad1 = " " x (24 - length ($name));
3498 my $pad2 = " " x (20 - length ($type));
3500 my $arg_synop = " "<link linkend=\"$id\">$name</link>"$pad1 $type_output $pad2 : $flags_string\n";
3501 my $arg_desc = "<refsect2 id=\"$id\" role=\"property\"><title>The <literal>"$name"</literal> $kind</title>\n";
3502 $arg_desc .= MakeIndexterms($symbol, $id);
3504 $arg_desc .= OutputSymbolExtraLinks($symbol);
3506 $arg_desc .= "<programlisting> "$name"$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
3507 $arg_desc .= &MakeDeprecationNote($symbol);
3508 $arg_desc .= $blurb;
3510 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
3512 if ($default ne "") {
3513 $arg_desc .= "<para>Default value: $default_output</para>\n";
3515 $arg_desc .= OutputSymbolTraits ($symbol);
3516 $arg_desc .= "</refsect2>\n";
3518 if ($flags =~ m/c/) {
3519 $child_synop .= $arg_synop;
3520 $child_desc .= $arg_desc;
3522 elsif ($flags =~ m/s/) {
3523 $style_synop .= $arg_synop;
3524 $style_desc .= $arg_desc;
3527 $synop .= $arg_synop;
3532 return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
3536 #############################################################################
3537 # Function : ReadSourceDocumentation
3538 # Description : This reads in the documentation embedded in comment blocks
3539 # in the source code (for Gnome).
3541 # Parameter descriptions override any in the template files.
3542 # Function descriptions are placed before any description from
3543 # the template files.
3545 # It recursively descends the source directory looking for .c
3546 # files and scans them looking for specially-formatted comment
3549 # Arguments : $source_dir - the directory to scan.
3550 #############m###############################################################
3552 sub ReadSourceDocumentation {
3553 my ($source_dir) = @_;
3554 my ($file, $dir, @suffix_list, $suffix);
3555 #print "Scanning source directory: $source_dir\n";
3557 # This array holds any subdirectories found.
3560 @suffix_list = split (/,/, $SOURCE_SUFFIXES);
3562 opendir (SRCDIR, $source_dir)
3563 || die "Can't open source directory $source_dir: $!";
3565 foreach $file (readdir (SRCDIR)) {
3566 if ($file =~ /^\./) {
3568 } elsif (-d "$source_dir/$file") {
3569 push (@subdirs, $file);
3570 } elsif (@suffix_list) {
3571 foreach $suffix (@suffix_list) {
3572 if ($file =~ m/\.\Q${suffix}\E$/) {
3573 &ScanSourceFile ("$source_dir/$file");
3576 } elsif ($file =~ m/\.[ch]$/) {
3577 &ScanSourceFile ("$source_dir/$file");
3582 # Now recursively scan the subdirectories.
3583 foreach $dir (@subdirs) {
3584 next if ($IGNORE_FILES =~ m/(\s|^)\Q${dir}\E(\s|$)/);
3585 &ReadSourceDocumentation ("$source_dir/$dir");
3590 #############################################################################
3591 # Function : ScanSourceFile
3592 # Description : Scans one source file looking for specially-formatted comment
3593 # blocks. Later &MergeSourceDocumentation is used to merge any
3594 # documentation found with the documentation already read in
3595 # from the template files.
3597 # Arguments : $file - the file to scan.
3598 #############################################################################
3600 sub ScanSourceFile {
3604 if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
3607 &LogWarning ($file, 1, "Can't find basename for this filename.");
3611 # Check if the basename is in the list of files to ignore.
3612 if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
3616 #print "DEBUG: Scanning $file\n";
3618 open (SRCFILE, $file)
3619 || die "Can't open $file: $!";
3620 my $in_comment_block = 0;
3622 my ($in_description, $in_return, $in_since, $in_stability, $in_deprecated);
3623 my ($description, $return_desc, $return_start, $return_style);
3624 my ($since_desc, $stability_desc, $deprecated_desc);
3626 my $ignore_broken_returns;
3629 # Look for the start of a comment block.
3630 if (!$in_comment_block) {
3631 if (m%^\s*/\*.*\*/%) {
3632 #one-line comment - not gtkdoc
3633 } elsif (m%^\s*/\*\*\s%) {
3634 #print "Found comment block start\n";
3636 $in_comment_block = 1;
3638 # Reset all the symbol data.
3640 $in_description = 0;
3649 $deprecated_desc = "";
3650 $stability_desc = "";
3651 $current_param = -1;
3652 $ignore_broken_returns = 0;
3658 # We're in a comment block. Check if we've found the end of it.
3661 # maybe its not even meant to be a gtk-doc comment?
3662 &LogWarning ($file, $., "Symbol name not found at the start of the comment block.");
3664 # Add the return value description onto the end of the params.
3666 push (@params, "Returns");
3667 push (@params, $return_desc);
3668 if ($return_style eq 'broken') {
3669 &LogWarning ($file, $., "Free-form return value description in $symbol. Use `Returns:' to avoid ambiguities.");
3672 # Convert special SGML characters
3673 $description = &ConvertSGMLChars ($symbol, $description);
3675 for ($k = 1; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3676 $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
3679 # Handle Section docs
3680 if ($symbol =~ m/SECTION:\s*(.*)/) {
3684 if (scalar %KnownSymbols) {
3685 if ((! defined($KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"})) || $KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"} != 1) {
3686 &LogWarning ($file, $., "Section $real_symbol is not defined in the $MODULE-section.txt file.");
3690 #print "SECTION DOCS found in source for : '$real_symbol'\n";
3691 $ignore_broken_returns = 1;
3692 for ($k = 0; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3693 #print " '".$params[$k]."'\n";
3694 $params[$k] = "\L$params[$k]";
3696 if ($params[$k] eq "short_description") {
3697 $key = "$TMPL_DIR/$real_symbol:Short_Description";
3698 } elsif ($params[$k] eq "see_also") {
3699 $key = "$TMPL_DIR/$real_symbol:See_Also";
3700 } elsif ($params[$k] eq "title") {
3701 $key = "$TMPL_DIR/$real_symbol:Title";
3702 } elsif ($params[$k] eq "stability") {
3703 $key = "$TMPL_DIR/$real_symbol:Stability_Level";
3704 } elsif ($params[$k] eq "section_id") {
3705 $key = "$TMPL_DIR/$real_symbol:Section_Id";
3706 } elsif ($params[$k] eq "include") {
3707 $key = "$TMPL_DIR/$real_symbol:Include";
3708 } elsif ($params[$k] eq "image") {
3709 $key = "$TMPL_DIR/$real_symbol:Image";
3711 if (defined($key)) {
3712 $SourceSymbolDocs{$key}=$params[$k+1];
3713 $SourceSymbolSourceFile{$key} = $file;
3714 $SourceSymbolSourceLine{$key} = $.;
3717 $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
3718 $SourceSymbolSourceFile{"$TMPL_DIR/$real_symbol:Long_Description"} = $file;
3719 $SourceSymbolSourceLine{"$TMPL_DIR/$real_symbol:Long_Description"} = $.;
3720 #$SourceSymbolTypes{$symbol} = "SECTION";
3722 #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
3723 $SourceSymbolDocs{$symbol} = $description;
3724 $SourceSymbolParams{$symbol} = [ @params ];
3725 # FIXME $SourceSymbolTypes{$symbol} = "STRUCT,SIGNAL,ARG,FUNCTION,MACRO";
3726 #if (defined $DeclarationTypes{$symbol}) {
3727 # $SourceSymbolTypes{$symbol} = $DeclarationTypes{$symbol}
3729 $SourceSymbolSourceFile{$symbol} = $file;
3730 $SourceSymbolSourceLine{$symbol} = $.;
3734 ($since_desc, my @extra_lines) = split ("\n", $since_desc);
3735 $since_desc =~ s/^\s+//;
3736 $since_desc =~ s/\s+$//;
3737 #print "Since($symbol) : [$since_desc]\n";
3738 $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
3739 if(scalar @extra_lines) {
3740 &LogWarning ($file, $., "multi-line since docs found");
3744 if ($stability_desc) {
3745 $stability_desc = &ParseStabilityLevel($stability_desc, $file, $., "Stability level for $symbol");
3746 $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
3749 if ($deprecated_desc) {
3750 if (exists $Deprecated{$symbol}) {
3753 # don't warn for signals and properties
3754 #if ($symbol !~ m/::?(.*)/) {
3755 if (defined $DeclarationTypes{$symbol}) {
3756 &LogWarning ($file, $.,
3757 "$symbol is deprecated in the inline comments, but no deprecation guards were found around the declaration.".
3758 " (See the --deprecated-guards option for gtkdoc-scan.)");
3761 $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
3765 $in_comment_block = 0;
3769 # Get rid of ' * ' at start of every line in the comment block.
3771 # But make sure we don't get rid of the newline at the end.
3775 #print "DEBUG: scanning :$_";
3777 # If we haven't found the symbol name yet, look for it.
3779 if (m%^\s*(SECTION:\s*\S+)%) {
3781 #print "SECTION DOCS found in source for : '$symbol'\n";
3782 $ignore_broken_returns = 1;
3783 } elsif (m%^\s*([\w:-]*\w)\s*:?\s*$%) {
3785 #print "SYMBOL DOCS found in source for : '$symbol'\n";
3790 # If we're in the return value description, add it to the end.
3792 # If we find another valid returns line, we assume that the first
3793 # one was really part of the description.
3794 if (m/^\s*(returns:|return\s+value:)/i) {
3795 if ($return_style eq 'broken') {
3796 $description .= $return_start . $return_desc;
3799 if ($return_style eq 'sane') {
3800 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3802 $return_style = 'sane';
3803 $ignore_broken_returns = 1;
3805 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3806 $description .= $return_start . $return_desc;
3808 $return_style = 'broken';
3810 } elsif (m%^\s*since:%i) {
3814 } elsif (m%^\s*stability:%i) {
3815 $stability_desc = $';
3818 } elsif (m%^\s*deprecated:%i) {
3819 $deprecated_desc = $';
3829 if (m/^\s*(returns:|return\s+value:)/i) {
3830 if ($return_style eq 'broken') {
3831 $description .= $return_start . $return_desc;
3834 if ($return_style eq 'sane') {
3835 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3837 $return_style = 'sane';
3838 $ignore_broken_returns = 1;
3842 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3844 $return_style = 'broken';
3848 } elsif (m%^\s*deprecated:%i) {
3849 $deprecated_desc = $';
3852 } elsif (m%^\s*stability:%i) {
3853 $stability_desc = $';
3862 if ($in_stability) {
3863 if (m/^\s*(returns:|return\s+value:)/i) {
3864 if ($return_style eq 'broken') {
3865 $description .= $return_start . $return_desc;
3868 if ($return_style eq 'sane') {
3869 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3871 $return_style = 'sane';
3872 $ignore_broken_returns = 1;
3876 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3878 $return_style = 'broken';
3882 } elsif (m%^\s*deprecated:%i) {
3883 $deprecated_desc = $';
3886 } elsif (m%^\s*since:%i) {
3891 $stability_desc .= $_;
3896 if ($in_deprecated) {
3897 if (m/^\s*(returns:|return\s+value:)/i) {
3898 if ($return_style eq 'broken') {
3899 $description .= $return_start . $return_desc;
3902 if ($return_style eq 'sane') {
3903 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3905 $return_style = 'sane';
3906 $ignore_broken_returns = 1;
3910 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3912 $return_style = 'broken';
3916 } elsif (m%^\s*since:%i) {
3920 } elsif (m%^\s*stability:%i) {
3921 $stability_desc = $';
3925 $deprecated_desc .= $_;
3930 # If we're in the description part, check for the 'Returns:' line.
3931 # If that isn't found, add the text to the end.
3932 if ($in_description) {
3933 # Get rid of 'Description:'
3934 s%^\s*Description:%%;
3936 if (m/^\s*(returns:|return\s+value:)/i) {
3937 if ($return_style eq 'broken') {
3938 $description .= $return_start . $return_desc;
3941 if ($return_style eq 'sane') {
3942 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3944 $return_style = 'sane';
3945 $ignore_broken_returns = 1;
3949 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3951 $return_style = 'broken';
3955 } elsif (m%^\s*since:%i) {
3959 } elsif (m%^\s*deprecated:%i) {
3960 $deprecated_desc = $';
3963 } elsif (m%^\s*stability:%i) {
3964 $stability_desc = $';
3973 # We must be in the parameters. Check for the empty line below them.
3975 $in_description = 1;
3979 # Look for a parameter name.
3980 if (m%^\s*@(\S+)\s*:\s*%) {
3981 my $param_name = $1;
3982 my $param_desc = $';
3984 #print "Found parameter: $param_name\n";
3985 # Allow '...' as the Varargs parameter.
3986 if ($param_name eq "...") {
3987 $param_name = "Varargs";
3989 if ("\L$param_name" eq "returns") {
3990 $return_style = 'sane';
3991 $ignore_broken_returns = 1;
3993 push (@params, $param_name);
3994 push (@params, $param_desc);
3995 $current_param += $PARAM_FIELD_COUNT;
3999 # We must be in the middle of a parameter description, so add it on
4000 # to the last element in @params.
4001 if ($current_param == -1) {
4002 &LogWarning ($file, $., "Parsing comment block file : parameter expected.");
4004 $params[$#params] .= $_;
4010 #############################################################################
4011 # Function : OutputMissingDocumentation
4012 # Description : Outputs report of documentation coverage to a file
4015 #############################################################################
4017 sub OutputMissingDocumentation {
4018 my $old_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.txt";
4019 my $new_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.new";
4021 my $n_documented = 0;
4022 my $n_incomplete = 0;
4028 my $buffer_deprecated = "";
4029 my $buffer_descriptions = "";
4031 open(UNDOCUMENTED, ">$new_undocumented_file")
4032 || die "Can't create $new_undocumented_file";
4034 foreach $symbol (sort (keys (%AllSymbols))) {
4035 # FIXME: should we print LogWarnings for undocumented stuff?
4037 #my $ssfile = &GetSymbolSourceFile($symbol);
4038 #my $ssline = &GetSymbolSourceLine($symbol);
4039 #my $location = "defined at " . (defined($ssfile)?$ssfile:"?") . ":" . (defined($ssline)?$ssline:"0") . "\n";
4041 if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include|Section_Id|Image)/) {
4043 if (exists ($AllDocumentedSymbols{$symbol})) {
4045 if (exists ($AllIncompleteSymbols{$symbol})) {
4047 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4048 #$buffer .= "\t0: ".$location;
4050 } elsif (exists $Deprecated{$symbol}) {
4051 if (exists ($AllIncompleteSymbols{$symbol})) {
4053 $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4054 #$buffer .= "\t1a: ".$location;
4056 $buffer_deprecated .= $symbol . "\n";
4057 #$buffer .= "\t1b: ".$location;
4060 if (exists ($AllIncompleteSymbols{$symbol})) {
4062 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4063 #$buffer .= "\t2a: ".$location;
4065 $buffer .= $symbol . "\n";
4066 #$buffer .= "\t2b: ".$location;
4069 } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
4071 #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
4072 #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
4073 #print "%%%% $symbol : $len1,$len2\n";
4074 if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
4075 || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
4078 # cut off the leading namespace ($TMPL_DIR)
4079 $symbol =~ m/^.*\/(.*)$/;
4080 $buffer_descriptions .= $1 . "\n";
4085 $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
4090 $percent = ($n_documented / $total) * 100.0;
4093 printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
4094 print UNDOCUMENTED "$n_documented symbols documented.\n";
4095 print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
4096 print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
4098 print UNDOCUMENTED $buffer;
4099 close (UNDOCUMENTED);
4101 return &UpdateFileIfChanged ($old_undocumented_file, $new_undocumented_file, 0);
4103 printf "%.0f%% symbol docs coverage", $percent;
4104 print "($n_documented symbols documented, $n_incomplete symbols incomplete, " . ($total - $n_documented) . " not documented)\n";
4105 print "See $MODULE-undocumented.txt for a list of missing docs.\nThe doc coverage percentage doesn't include intro sections.\n";
4109 #############################################################################
4110 # Function : OutputUndeclaredSymbols
4111 # Description : Outputs symbols that are listed in the section file, but not
4112 # declaration is found in the sources
4115 #############################################################################
4117 sub OutputUndeclaredSymbols {
4118 my $old_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.txt";
4119 my $new_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.new";
4121 open(UNDECLARED, ">$new_undeclared_file")
4122 || die "Can't create $new_undeclared_file";
4124 if (%UndeclaredSymbols) {
4125 print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
4126 print UNDECLARED "\n";
4127 print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
4131 return &UpdateFileIfChanged ($old_undeclared_file, $new_undeclared_file, 0);
4134 #############################################################################
4135 # Function : OutputUnusedSymbols
4136 # Description : Outputs symbols that are documented in comments, but not
4137 # declared in the sources
4140 #############################################################################
4142 sub OutputUnusedSymbols {
4144 my $old_unused_file = "$ROOT_DIR/$MODULE-unused.txt";
4145 my $new_unused_file = "$ROOT_DIR/$MODULE-unused.new";
4147 open (UNUSED, ">$new_unused_file")
4148 || die "Can't open $new_unused_file";
4150 foreach $symbol (sort keys (%Declarations)) {
4151 if (!defined ($DeclarationOutput{$symbol})) {
4152 print (UNUSED "$symbol\n");
4156 foreach $symbol (sort (keys (%AllUnusedSymbols))) {
4157 print (UNUSED "$symbol(" . $AllUnusedSymbols{$symbol} . ")\n");
4161 if ($num_unused != 0) {
4162 &LogWarning ($old_unused_file, 1, "$num_unused unused declarations.".
4163 "They should be added to $MODULE-sections.txt in the appropriate place.");
4166 return &UpdateFileIfChanged ($old_unused_file, $new_unused_file, 0);
4170 #############################################################################
4171 # Function : OutputAllSymbols
4172 # Description : Outputs list of all symbols to a file
4175 #############################################################################
4177 sub OutputAllSymbols {
4178 my $n_documented = 0;
4184 open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
4185 || die "Can't create $ROOT_DIR/$MODULE-symbols.txt: $!";
4187 foreach $symbol (sort (keys (%AllSymbols))) {
4188 print SYMBOLS $symbol . "\n";
4194 #############################################################################
4195 # Function : OutputSymbolsWithoutSince
4196 # Description : Outputs list of all symbols without a since tag to a file
4199 #############################################################################
4201 sub OutputSymbolsWithoutSince {
4202 my $n_documented = 0;
4208 open (SYMBOLS, ">$ROOT_DIR/$MODULE-nosince.txt")
4209 || die "Can't create $ROOT_DIR/$MODULE-nosince.txt: $!";
4211 foreach $symbol (sort (keys (%SourceSymbolDocs))) {
4212 if (!defined $Since{$symbol}) {
4213 print SYMBOLS $symbol . "\n";
4221 #############################################################################
4222 # Function : MergeSourceDocumentation
4223 # Description : This merges documentation read from a source file into the
4224 # documentation read in from a template file.
4226 # Parameter descriptions override any in the template files.
4227 # Function descriptions are placed before any description from
4228 # the template files.
4231 #############################################################################
4233 sub MergeSourceDocumentation {
4237 if (scalar %SymbolDocs) {
4238 @Symbols=keys (%SymbolDocs);
4239 #print "num existing entries: ".(scalar @Symbols)."\n";
4240 #print " ",$Symbols[0], " ",$Symbols[1],"\n";
4243 # filter scanned declarations, with what we suppress from -sections.txt
4245 foreach $symbol (keys (%Declarations)) {
4246 if (defined($KnownSymbols{$symbol}) && $KnownSymbols{$symbol} == 1) {
4250 # , add the rest from -sections.txt
4251 foreach $symbol (keys (%KnownSymbols)) {
4252 if ($KnownSymbols{$symbol} == 1) {
4256 # and add whats found in the source
4257 foreach $symbol (keys (%SourceSymbolDocs)) {
4260 @Symbols = keys (%tmp);
4261 #print "num source entries: ".(scalar @Symbols)."\n";
4263 foreach $symbol (@Symbols) {
4264 $AllSymbols{$symbol} = 1;
4266 my $have_tmpl_docs = 0;
4268 ## See if the symbol is documented in template
4269 my $tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4270 my $check_tmpl_doc =$tmpl_doc;
4271 # remove all xml-tags and whitespaces
4272 #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
4273 $check_tmpl_doc =~ s/<.*?>//g;
4274 $check_tmpl_doc =~ s/\s//g;
4276 if ($check_tmpl_doc ne "") {
4277 $have_tmpl_docs = 1;
4278 #print "## [$check_tmpl_doc]\n";
4283 if (exists ($SourceSymbolDocs{$symbol})) {
4284 my $type = $DeclarationTypes {$symbol};
4286 #print "merging [$symbol] from source\n";
4288 my $item = "Parameter";
4289 if (defined ($type)) {
4290 if ($type eq 'STRUCT') {
4292 } elsif ($type eq 'ENUM') {
4294 } elsif ($type eq 'UNION') {
4301 my $src_doc = $SourceSymbolDocs{$symbol};
4302 # remove leading and training whitespaces
4303 $src_doc =~ s/^\s+//;
4304 $src_doc =~ s/\s+$//;
4306 # Don't output warnings for overridden titles as titles are
4307 # automatically generated in the -sections.txt file, and thus they
4308 # are often overridden.
4309 if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
4310 # check if content is different
4311 if ($tmpl_doc ne $src_doc) {
4312 #print "[$tmpl_doc] [$src_doc]\n";
4313 &LogWarning ($SourceSymbolSourceFile{$symbol}, $SourceSymbolSourceLine{$symbol},
4314 "Documentation in template ".$SymbolSourceFile{$symbol}.":".$SymbolSourceLine{$symbol}." for $symbol being overridden by inline comments.");
4318 if ($src_doc ne "") {
4319 $AllDocumentedSymbols{$symbol} = 1;
4322 # Convert <!--PARAMETERS--> with any blank lines around it to
4323 # a </para> followed by <!--PARAMETERS--> followed by <para>.
4324 $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
4326 # If there is a blank line, finish the paragraph and start another.
4327 $src_doc = &ConvertBlankLines ($src_doc, $symbol);
4328 # Do not add <para> to nothing, it breaks missing docs checks.
4329 my $src_doc_para = "";
4331 $src_doc_para = "<para>\n$src_doc</para>\n";
4332 #print "$symbol : [$src_doc][$src_doc_para]\n";
4335 if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
4336 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4337 } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
4338 # For the title/summary/see also section docs we don't want to
4339 # add any <para> tags.
4340 $SymbolDocs{$symbol} = "$src_doc"
4342 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4346 if ($symbol =~ m/.*::.*/) {
4347 # For signals we prefer the param names from the source docs,
4348 # since the ones from the templates are likely to contain the
4349 # artificial argn names which are generated by gtkdoc-scangobj.
4350 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4351 # FIXME: we need to check for empty docs here as well!
4353 # The templates contain the definitive parameter names and order,
4354 # so we will not change that. We only override the actual text.
4355 my $tmpl_params = $SymbolParams{$symbol};
4356 if (!defined ($tmpl_params)) {
4357 #print "No merge needed for $symbol\n";
4358 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4359 # FIXME: we still like to get the number of params and merge
4360 # 1) we would noticed that params have been removed/renamed
4361 # 2) we would catch undocumented params
4362 # params are not (yet) exported in -decl.txt so that we
4363 # could easily grab them :/
4365 my $params = $SourceSymbolParams{$symbol};
4367 #print "Merge needed for $symbol, tmpl_params: ",$#$tmpl_params,", source_params: ",$#$params," \n";
4368 for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4369 my $tmpl_param_name = $$tmpl_params[$j];
4371 # Allow '...' as the Varargs parameter.
4372 if ($tmpl_param_name eq "...") {
4373 $tmpl_param_name = "Varargs";
4376 # Try to find the param in the source comment documentation.
4379 #print " try merge param $tmpl_param_name\n";
4380 for ($k = 0; $k <= $#$params; $k += $PARAM_FIELD_COUNT) {
4381 my $param_name = $$params[$k];
4382 my $param_desc = $$params[$k + 1];
4384 #print " test param $param_name\n";
4385 # We accept changes in case, since the Gnome source
4386 # docs contain a lot of these.
4387 if ("\L$param_name" eq "\L$tmpl_param_name") {
4390 # Override the description.
4391 $$tmpl_params[$j + 1] = $param_desc;
4393 # Set the name to "" to mark it as used.
4399 # If it looks like the parameters are there, but not
4400 # in the right place, try to explain a bit better.
4401 if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
4402 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4403 "Parameters for $symbol must start on the line immediately after the function or macro name.");
4407 # Now we output a warning if parameters have been described which
4409 for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
4410 my $param_name = $$params[$j];
4412 # the template builder cannot detect if a macro returns
4414 if(($type eq "MACRO") && ($param_name eq "Returns")) {
4415 # FIXME: do we need to add it then to tmpl_params[] ?
4416 my $num=$#$tmpl_params;
4417 #print " adding Returns: to macro docs for $symbol.\n";
4418 $$tmpl_params[$num+1]="Returns";
4419 $$tmpl_params[$num+2]=$$params[$j+1];
4422 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4423 "$item described in source code comment block but does not exist. $type: $symbol $item: $param_name.");
4429 if ($have_tmpl_docs) {
4430 $AllDocumentedSymbols{$symbol} = 1;
4431 #print "merging [$symbol] from template\n";
4434 #print "[$symbol] undocumented\n";
4438 # if this symbol is documented, check if docs are complete
4439 $check_tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4440 # remove all xml-tags and whitespaces
4441 #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
4442 $check_tmpl_doc =~ s/<.*?>//g;
4443 $check_tmpl_doc =~ s/\s//g;
4444 if ($check_tmpl_doc ne "") {
4445 my $tmpl_params = $SymbolParams{$symbol};
4446 if (defined ($tmpl_params)) {
4447 my $type = $DeclarationTypes {$symbol};
4449 my $item = "Parameter";
4450 if (defined ($type)) {
4451 if ($type eq 'STRUCT') {
4453 } elsif ($type eq 'ENUM') {
4455 } elsif ($type eq 'UNION') {
4462 #print "Check param docs for $symbol, tmpl_params: ",$#$tmpl_params," entries, type=$type\n";
4464 if ($#$tmpl_params > 0) {
4466 for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4467 # Output a warning if the parameter is empty and
4468 # remember for stats.
4469 my $tmpl_param_name = $$tmpl_params[$j];
4470 my $tmpl_param_desc = $$tmpl_params[$j + 1];
4471 if ($tmpl_param_name ne "void" && $tmpl_param_desc !~ m/\S/) {
4472 if (exists ($AllIncompleteSymbols{$symbol})) {
4473 $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
4475 $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
4477 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4478 "$item description for $symbol"."::"."$tmpl_param_name is missing in source code comment block.");
4483 if ($#$tmpl_params == 0) {
4484 $AllIncompleteSymbols{$symbol}="<items>";
4485 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4486 "$item descriptions for $symbol are missing in source code comment block.");
4488 # $#$tmpl_params==-1 means we don't know about parameters
4489 # this unfortunately does not tell if there should be some
4494 #print "num doc entries: ".(scalar %SymbolDocs)."\n";
4497 #############################################################################
4498 # Function : IsEmptyDoc
4499 # Description : Check if a doc-string is empty. Its also regarded as empty if
4500 # it only consist of whitespace or e.g. FIXME.
4501 # Arguments : the doc-string
4502 #############################################################################
4506 if ($doc =~ /^\s*$/) {
4510 if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
4518 # This converts blank lines to "</para><para>", but only outside CDATA and
4519 # <programlisting> tags.
4520 sub ConvertBlankLines {
4521 return &ModifyXMLElements ($_[0], $_[1],
4522 "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
4523 \&ConvertBlankLinesEndTag,
4524 \&ConvertBlankLinesCallback);
4528 sub ConvertBlankLinesEndTag {
4529 if ($_[0] eq "<!\[CDATA\[") {
4531 } elsif ($_[0] eq "|[") {
4534 return "</programlisting>";
4538 sub ConvertBlankLinesCallback {
4539 my ($text, $symbol, $tag) = @_;
4541 # If we're not in CDATA or a <programlisting> we convert blank lines so
4542 # they start a new <para>.
4544 $text =~ s%\n{2,}%\n</para>\n<para>\n%g;
4551 #############################################################################
4552 # LIBRARY FUNCTIONS - These functions are used in both gtkdoc-mkdb and
4553 # gtkdoc-mktmpl and should eventually be moved to a
4555 #############################################################################
4557 #############################################################################
4558 # Function : ReadDeclarationsFile
4559 # Description : This reads in a file containing the function/macro/enum etc.
4562 # Note that in some cases there are several declarations with
4563 # the same name, e.g. for conditional macros. In this case we
4564 # set a flag in the %DeclarationConditional hash so the
4565 # declaration is not shown in the docs.
4567 # If a macro and a function have the same name, e.g. for
4568 # gtk_object_ref, the function declaration takes precedence.
4570 # Some opaque structs are just declared with 'typedef struct
4571 # _name name;' in which case the declaration may be empty.
4572 # The structure may have been found later in the header, so
4573 # that overrides the empty declaration.
4575 # Arguments : $file - the declarations file to read
4576 # $override - if declarations in this file should override
4577 # any current declaration.
4578 #############################################################################
4580 sub ReadDeclarationsFile {
4581 my ($file, $override) = @_;
4583 if ($override == 0) {
4585 %DeclarationTypes = ();
4586 %DeclarationConditional = ();
4587 %DeclarationOutput = ();
4591 || die "Can't open $file: $!";
4592 my $declaration_type = "";
4593 my $declaration_name;
4595 my $is_deprecated = 0;
4597 if (!$declaration_type) {
4598 if (m/^<([^>]+)>/) {
4599 $declaration_type = $1;
4600 $declaration_name = "";
4601 #print "Found declaration: $declaration_type\n";
4605 if (m%^<NAME>(.*)</NAME>%) {
4606 $declaration_name = $1;
4607 } elsif (m%^<DEPRECATED/>%) {
4609 } elsif (m%^</$declaration_type>%) {
4610 #print "Found end of declaration: $declaration_name\n";
4611 # Check that the declaration has a name
4612 if ($declaration_name eq "") {
4613 print "ERROR: $declaration_type has no name $file:$.\n";
4616 # If the declaration is an empty typedef struct _XXX XXX
4617 # set the flag to indicate the struct has a typedef.
4618 if ($declaration_type eq 'STRUCT'
4619 && $declaration =~ m/^\s*$/) {
4620 #print "Struct has typedef: $declaration_name\n";
4621 $StructHasTypedef{$declaration_name} = 1;
4624 # Check if the symbol is already defined.
4625 if (defined ($Declarations{$declaration_name})
4626 && $override == 0) {
4627 # Function declarations take precedence.
4628 if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
4630 } elsif ($declaration_type eq 'FUNCTION') {
4631 if ($is_deprecated) {
4632 $Deprecated{$declaration_name} = "";
4634 $Declarations{$declaration_name} = $declaration;
4635 $DeclarationTypes{$declaration_name} = $declaration_type;
4636 } elsif ($DeclarationTypes{$declaration_name}
4637 eq $declaration_type) {
4638 # If the existing declaration is empty, or is just a
4639 # forward declaration of a struct, override it.
4640 if ($declaration_type eq 'STRUCT') {
4641 if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4642 if ($is_deprecated) {
4643 $Deprecated{$declaration_name} = "";
4645 $Declarations{$declaration_name} = $declaration;
4646 } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4647 # Ignore an empty or forward declaration.
4649 &LogWarning ($file, $., "Structure $declaration_name has multiple definitions.");
4652 # set flag in %DeclarationConditional hash for
4653 # multiply defined macros/typedefs.
4654 $DeclarationConditional{$declaration_name} = 1;
4657 &LogWarning ($file, $., "$declaration_name has multiple definitions.");
4660 if ($is_deprecated) {
4661 $Deprecated{$declaration_name} = "";
4663 $Declarations{$declaration_name} = $declaration;
4664 $DeclarationTypes{$declaration_name} = $declaration_type;
4667 $declaration_type = "";
4678 #############################################################################
4679 # Function : ReadSignalsFile
4680 # Description : This reads in an existing file which contains information on
4681 # all GTK signals. It creates the arrays @SignalNames and
4682 # @SignalPrototypes containing info on the signals. The first
4683 # line of the SignalPrototype is the return type of the signal
4684 # handler. The remaining lines are the parameters passed to it.
4685 # The last parameter, "gpointer user_data" is always the same
4686 # so is not included.
4687 # Arguments : $file - the file containing the signal handler prototype
4689 #############################################################################
4691 sub ReadSignalsFile {
4699 my $signal_prototype;
4701 # Reset the signal info.
4702 @SignalObjects = ();
4704 @SignalReturns = ();
4706 @SignalPrototypes = ();
4711 if (!open (INPUT, $file)) {
4712 warn "Can't open $file - skipping signals\n";
4719 $signal_object = "";
4721 $signal_returns = "";
4722 $signal_prototype = "";
4725 if (m/^<NAME>(.*)<\/NAME>/) {
4727 if ($signal_name =~ m/^(.*)::(.*)$/) {
4728 $signal_object = $1;
4729 ($signal_name = $2) =~ s/_/-/g;
4730 #print "Found signal: $signal_name\n";
4732 &LogWarning ($file, $., "Invalid signal name: $signal_name.");
4734 } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
4735 $signal_returns = $1;
4736 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4738 } elsif (m%^</SIGNAL>%) {
4739 #print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
4740 push (@SignalObjects, $signal_object);
4741 push (@SignalNames, $signal_name);
4742 push (@SignalReturns, $signal_returns);
4743 push (@SignalFlags, $signal_flags);
4744 push (@SignalPrototypes, $signal_prototype);
4747 $signal_prototype .= $_;
4755 #############################################################################
4756 # Function : ReadTemplateFile
4757 # Description : This reads in the manually-edited documentation file
4758 # corresponding to the file currently being created, so we can
4759 # insert the documentation at the appropriate places.
4760 # It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
4761 # is a hash of arrays.
4762 # NOTE: This function is duplicated in gtkdoc-mktmpl (but
4763 # slightly different).
4764 # Arguments : $docsfile - the template file to read in.
4765 # $skip_unused_params - 1 if the unused parameters should be
4767 #############################################################################
4769 sub ReadTemplateFile {
4770 my ($docsfile, $skip_unused_params) = @_;
4772 my $template = "$docsfile.sgml";
4773 if (! -f $template) {
4774 #print "File doesn't exist: $template\n";
4777 #print "Reading $template\n";
4779 # start with empty hashes, we merge the source comment for each file
4785 my $current_type = ""; # Type of symbol being read.
4786 my $current_symbol = ""; # Name of symbol being read.
4787 my $symbol_doc = ""; # Description of symbol being read.
4788 my @params; # Parameter names and descriptions of current
4789 # function/macro/function typedef.
4790 my $current_param = -1; # Index of parameter currently being read.
4791 # Note that the param array contains pairs
4792 # of param name & description.
4793 my $in_unused_params = 0; # True if we are reading in the unused params.
4794 my $in_deprecated = 0;
4796 my $in_stability = 0;
4798 open (DOCS, "$template")
4799 || die "Can't open $template: $!";
4801 if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
4804 if ($symbol eq "Title"
4805 || $symbol eq "Short_Description"
4806 || $symbol eq "Long_Description"
4807 || $symbol eq "See_Also"
4808 || $symbol eq "Stability_Level"
4809 || $symbol eq "Include"
4810 || $symbol eq "Image") {
4812 $symbol = $docsfile . ":" . $symbol;
4815 #print "Found symbol: $symbol\n";
4816 # Remember file and line for the symbol
4817 $SymbolSourceFile{$symbol} = $template;
4818 $SymbolSourceLine{$symbol} = $.;
4820 # Store previous symbol, but remove any trailing blank lines.
4821 if ($current_symbol ne "") {
4822 $symbol_doc =~ s/\s+$//;
4823 $SymbolTypes{$current_symbol} = $current_type;
4824 $SymbolDocs{$current_symbol} = $symbol_doc;
4826 # Check that the stability level is valid.
4827 if ($StabilityLevel{$current_symbol}) {
4828 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4831 if ($current_param >= 0) {
4832 $SymbolParams{$current_symbol} = [ @params ];
4834 # Delete any existing params in case we are overriding a
4835 # previously read template.
4836 delete $SymbolParams{$current_symbol};
4839 $current_type = $type;
4840 $current_symbol = $symbol;
4841 $current_param = -1;
4842 $in_unused_params = 0;
4849 } elsif (m/^<!-- # Unused Parameters # -->/) {
4850 #print "DEBUG: Found unused parameters\n";
4851 $in_unused_params = 1;
4854 } elsif ($in_unused_params && $skip_unused_params) {
4855 # When outputting the DocBook we skip unused parameters.
4856 #print "DEBUG: Skipping unused param: $_";
4860 # Check if param found. Need to handle "..." and "format...".
4861 if (s/^\@([\w\.]+):\040?//) {
4862 my $param_name = $1;
4863 my $param_desc = $_;
4864 # Allow variations of 'Returns'
4865 if ($param_name =~ m/^[Rr]eturns?$/) {
4866 $param_name = "Returns";
4869 # strip trailing whitespaces and blank lines
4872 #print "Found param for symbol $current_symbol : '$param_name'= '$_'";
4874 if ($param_name eq "Deprecated") {
4876 $Deprecated{$current_symbol} = $_;
4877 } elsif ($param_name eq "Since") {
4880 $Since{$current_symbol} = $_;
4881 } elsif ($param_name eq "Stability") {
4883 $StabilityLevel{$current_symbol} = $_;
4885 push (@params, $param_name);
4886 push (@params, $param_desc);
4887 $current_param += $PARAM_FIELD_COUNT;
4890 # strip trailing whitespaces and blank lines
4895 if ($in_deprecated) {
4896 $Deprecated{$current_symbol} .= $_;
4897 } elsif ($in_since) {
4898 &LogWarning ($template, $., "multi-line since docs found");
4899 #$Since{$current_symbol} .= $_;
4900 } elsif ($in_stability) {
4901 $StabilityLevel{$current_symbol} .= $_;
4902 } elsif ($current_param >= 0) {
4903 $params[$current_param] .= $_;
4912 # Remember to finish the current symbol doccs.
4913 if ($current_symbol ne "") {
4915 $symbol_doc =~ s/\s+$//;
4916 $SymbolTypes{$current_symbol} = $current_type;
4917 $SymbolDocs{$current_symbol} = $symbol_doc;
4919 # Check that the stability level is valid.
4920 if ($StabilityLevel{$current_symbol}) {
4921 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4924 if ($current_param >= 0) {
4925 $SymbolParams{$current_symbol} = [ @params ];
4927 # Delete any existing params in case we are overriding a
4928 # previously read template.
4929 delete $SymbolParams{$current_symbol};
4938 #############################################################################
4939 # Function : ReadObjectHierarchy
4940 # Description : This reads in the $MODULE-hierarchy.txt file containing all
4941 # the GtkObject subclasses described in this module (and their
4943 # It places them in the @Objects array, and places their level
4944 # in the object hierarchy in the @ObjectLevels array, at the
4945 # same index. GtkObject, the root object, has a level of 1.
4947 # FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
4948 # as it goes along, this should be split out into a separate
4952 #############################################################################
4954 sub ReadObjectHierarchy {
4958 if (! -f $OBJECT_TREE_FILE) {
4961 if (!open (INPUT, $OBJECT_TREE_FILE)) {
4962 warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
4966 # FIXME: use $OUTPUT_FORMAT
4967 # my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.$OUTPUT_FORMAT";
4968 my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
4969 my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
4971 open (OUTPUT, ">$new_tree_index")
4972 || die "Can't create $new_tree_index: $!";
4974 if ($OUTPUT_FORMAT eq "xml") {
4975 my $tree_header = $doctype_header;
4977 $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
4978 print (OUTPUT "$tree_header");
4980 print (OUTPUT "<screen>\n");
4982 # Only emit objects if they are supposed to be documented, or if
4983 # they have documented children. To implement this, we maintain a
4984 # stack of pending objects which will be emitted if a documented
4986 my @pending_objects = ();
4987 my @pending_levels = ();
4991 my $level = (length($`)) / 2 + 1;
4994 while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
4995 my $pobject = pop(@pending_objects);
4996 my $plevel = pop(@pending_levels);
4999 push (@pending_objects, $object);
5000 push (@pending_levels, $level);
5002 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5003 while ($#pending_levels >= 0) {
5004 $object = shift @pending_objects;
5005 $level = shift @pending_levels;
5006 $xref = &MakeXRef ($object);
5008 print (OUTPUT ' ' x ($level * 4), "$xref\n");
5009 push (@Objects, $object);
5010 push (@ObjectLevels, $level);
5014 # LogWarning ($OBJECT_TREE_FILE, $., "unknown type $object");
5018 print (OUTPUT "</screen>\n");
5023 &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
5028 #############################################################################
5029 # Function : ReadInterfaces
5030 # Description : This reads in the $MODULE.interfaces file.
5033 #############################################################################
5035 sub ReadInterfaces {
5038 if (! -f $INTERFACES_FILE) {
5041 if (!open (INPUT, $INTERFACES_FILE)) {
5042 warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
5048 my ($object, @ifaces) = split;
5049 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5050 my @knownIfaces = ();
5052 # filter out private interfaces, but leave foreign interfaces
5053 foreach my $iface (@ifaces) {
5054 if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
5055 push (@knownIfaces, $iface);
5059 $Interfaces{$object} = join(' ', @knownIfaces);
5065 #############################################################################
5066 # Function : ReadPrerequisites
5067 # Description : This reads in the $MODULE.prerequisites file.
5070 #############################################################################
5072 sub ReadPrerequisites {
5073 %Prerequisites = ();
5075 if (! -f $PREREQUISITES_FILE) {
5078 if (!open (INPUT, $PREREQUISITES_FILE)) {
5079 warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
5085 my ($iface, @prereqs) = split;
5086 if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
5087 my @knownPrereqs = ();
5089 # filter out private prerequisites, but leave foreign prerequisites
5090 foreach my $prereq (@prereqs) {
5091 if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
5092 push (@knownPrereqs, $prereq);
5096 $Prerequisites{$iface} = join(' ', @knownPrereqs);
5102 #############################################################################
5103 # Function : ReadArgsFile
5104 # Description : This reads in an existing file which contains information on
5105 # all GTK args. It creates the arrays @ArgObjects, @ArgNames,
5106 # @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
5108 # Arguments : $file - the file containing the arg information.
5109 #############################################################################
5124 # Reset the args info.
5137 if (!open (INPUT, $file)) {
5138 warn "Can't open $file - skipping args\n";
5155 if (m/^<NAME>(.*)<\/NAME>/) {
5157 if ($arg_name =~ m/^(.*)::(.*)$/) {
5159 ($arg_name = $2) =~ s/_/-/g;
5160 #print "Found arg: $arg_name\n";
5162 &LogWarning ($file, $., "Invalid argument name: $arg_name");
5164 } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
5166 } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
5168 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
5170 } elsif (m/^<NICK>(.*)<\/NICK>/) {
5172 } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
5174 if ($arg_blurb eq "(null)") {
5176 &LogWarning ($file, $., "Property ${arg_object}:${arg_name} has no documentation.");
5178 } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
5180 } elsif (m%^</ARG>%) {
5181 #print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
5182 push (@ArgObjects, $arg_object);
5183 push (@ArgNames, $arg_name);
5184 push (@ArgTypes, $arg_type);
5185 push (@ArgRanges, $arg_range);
5186 push (@ArgFlags, $arg_flags);
5187 push (@ArgNicks, $arg_nick);
5188 push (@ArgBlurbs, $arg_blurb);
5189 push (@ArgDefaults, $arg_default);
5198 #############################################################################
5199 # Function : CheckIsObject
5200 # Description : Returns 1 if the given name is a GObject or a subclass.
5201 # It uses the global @Objects array.
5202 # Note that the @Objects array only contains classes in the
5203 # current module and their ancestors - not all GObject classes.
5204 # Arguments : $name - the name to check.
5205 #############################################################################
5211 foreach $object (@Objects) {
5212 if ($object eq $name) {
5220 #############################################################################
5221 # Function : MakeReturnField
5222 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
5223 # Arguments : $str - the string to pad.
5224 #############################################################################
5226 sub MakeReturnField {
5229 return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));
5232 #############################################################################
5233 # Function : GetSymbolSourceFile
5234 # Description : Get the filename where the symbol docs where taken from.
5235 # Arguments : $symbol - the symbol name
5236 #############################################################################
5238 sub GetSymbolSourceFile {
5241 if (defined($SourceSymbolSourceFile{$symbol})) {
5242 return $SourceSymbolSourceFile{$symbol};
5243 } elsif (defined($SymbolSourceFile{$symbol})) {
5244 return $SymbolSourceFile{$symbol};
5250 #############################################################################
5251 # Function : GetSymbolSourceLine
5252 # Description : Get the file line where the symbol docs where taken from.
5253 # Arguments : $symbol - the symbol name
5254 #############################################################################
5256 sub GetSymbolSourceLine {
5259 if (defined($SourceSymbolSourceLine{$symbol})) {
5260 return $SourceSymbolSourceLine{$symbol};
5261 } elsif (defined($SymbolSourceLine{$symbol})) {
5262 return $SymbolSourceLine{$symbol};