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+|signed\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+|signed\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*$/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);
3128 @impls = sort @impls;
3131 $object is implemented by
3133 for ($i = 0; $i <= $#impls; $i++) {
3134 my $id = &CreateValidSGMLID ($impls[$i]);
3135 $text .= " <link linkend=\"$id\">$impls[$i]</link>";
3136 if ($i < $#impls - 1) {
3139 elsif ($i < $#impls) {
3154 #############################################################################
3155 # Function : GetPrerequisites
3156 # Description : Returns the DocBook output describing the prerequisites
3157 # of an interface. It uses the global %Prerequisites hash.
3158 # Arguments : $iface - the interface.
3159 #############################################################################
3161 sub GetPrerequisites {
3166 if (exists($Prerequisites{$iface})) {
3171 my @prereqs = split(' ', $Prerequisites{$iface});
3172 for ($i = 0; $i <= $#prereqs; $i++) {
3173 my $id = &CreateValidSGMLID ($prereqs[$i]);
3174 $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
3175 if ($i < $#prereqs - 1) {
3178 elsif ($i < $#prereqs) {
3192 #############################################################################
3193 # Function : GetDerived
3194 # Description : Returns the DocBook output describing the derived interfaces
3195 # of an interface. It uses the global %Prerequisites hash.
3196 # Arguments : $iface - the interface.
3197 #############################################################################
3205 foreach my $key (keys %Prerequisites) {
3206 if ($Prerequisites{$key} =~ /\b$iface\b/) {
3207 push (@derived, $key);
3210 if ($#derived >= 0) {
3211 @derived = sort @derived;
3214 $iface is required by
3216 for ($i = 0; $i <= $#derived; $i++) {
3217 my $id = &CreateValidSGMLID ($derived[$i]);
3218 $text .= " <link linkend=\"$id\">$derived[$i]</link>";
3219 if ($i < $#derived - 1) {
3222 elsif ($i < $#derived) {
3237 #############################################################################
3238 # Function : GetSignals
3239 # Description : Returns the synopsis and detailed description DocBook output
3240 # for the signal handlers of a given GtkObject subclass.
3241 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
3242 #############################################################################
3250 for ($i = 0; $i <= $#SignalObjects; $i++) {
3251 if ($SignalObjects[$i] eq $object) {
3252 #print "Found signal: $SignalNames[$i]\n";
3253 my $name = $SignalNames[$i];
3254 my $symbol = "${object}::${name}";
3255 my $id = &CreateValidSGMLID ("$object-$name");
3257 my $pad = ' ' x (46 - length($name));
3258 $synop .= " "<link linkend=\"$id\">$name</link>"$pad ";
3260 $desc .= "<refsect2 id=\"$id\" role=\"signal\"><title>The <literal>"$name"</literal> signal</title>\n";
3261 $desc .= MakeIndexterms($symbol, $id);
3263 $desc .= OutputSymbolExtraLinks($symbol);
3265 $desc .= "<programlisting>";
3267 $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
3268 my $type_modifier = defined($1) ? $1 : "";
3271 my $xref = &MakeXRef ($type, &tagify($type, "returnvalue"));
3273 my $ret_type_len = length ($type_modifier) + length ($pointer)
3275 my $ret_type_output = "$type_modifier$xref$pointer"
3276 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
3278 $desc .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
3280 my $sourceparams = $SourceSymbolParams{$symbol};
3281 my @params = split ("\n", $SignalPrototypes[$i]);
3284 my $type_len = length("gpointer");
3285 my $name_len = length("user_data");
3286 # do two passes, the first one is to calculate padding
3287 for ($l = 0; $l < 2; $l++) {
3288 for ($j = 0; $j <= $#params; $j++) {
3289 # allow alphanumerics, '_', '[' & ']' in param names
3290 if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
3293 if (defined($sourceparams)) {
3294 $name = $$sourceparams[$PARAM_FIELD_COUNT * $j];
3299 if (!defined($name)) {
3303 if (length($type) + length($pointer) > $type_len) {
3304 $type_len = length($type) + length($pointer);
3306 if (length($name) > $name_len) {
3307 $name_len = length($name);
3311 $xref = &MakeXRef ($type, &tagify($type, "type"));
3312 $pad = ' ' x ($type_len - length($type) - length($pointer));
3313 $desc .= "$xref$pad $pointer$name,\n";
3314 $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
3317 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3318 "Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]");
3322 $xref = &MakeXRef ("gpointer", &tagify("gpointer", "type"));
3323 $pad = ' ' x ($type_len - length("gpointer"));
3324 $desc .= "$xref$pad user_data)";
3326 my $flags = $SignalFlags[$i];
3327 my $flags_string = "";
3329 if (defined ($flags)) {
3330 if ($flags =~ m/f/) {
3331 $flags_string = "Run First";
3333 elsif ($flags =~ m/l/) {
3334 $flags_string = "Run Last";
3336 elsif ($flags =~ m/c/) {
3337 $flags_string = "Cleanup";
3339 if ($flags =~ m/r/) {
3340 if ($flags_string) { $flags_string .= " / "; }
3341 $flags_string .= "No Recursion";
3343 if ($flags =~ m/d/) {
3344 if ($flags_string) { $flags_string .= " / "; }
3345 $flags_string .= "Has Details";
3347 if ($flags =~ m/a/) {
3348 if ($flags_string) { $flags_string .= " / "; }
3349 $flags_string .= "Action";
3351 if ($flags =~ m/h/) {
3352 if ($flags_string) { $flags_string .= " / "; }
3353 $flags_string .= "No Hooks";
3359 $synop .= ": $flags_string\n";
3361 $pad = ' ' x (5 + $name_len - length("user_data"));
3362 $desc .= "$pad : $flags_string</programlisting>\n";
3367 $desc .= "</programlisting>\n";
3370 $desc .= &MakeDeprecationNote($symbol);
3372 my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
3373 my $parameters_output = 0;
3375 $AllSymbols{$symbol} = 1;
3376 if (defined ($SymbolDocs{$symbol})) {
3377 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3379 # Try to insert the parameter table at the author's desired
3380 # position. Otherwise we need to tag it onto the end.
3381 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
3382 $parameters_output = 1;
3384 $desc .= $symbol_docs;
3386 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
3387 $AllDocumentedSymbols{$symbol} = 1;
3391 if ($parameters_output == 0) {
3392 $desc .= $parameters;
3394 $desc .= OutputSymbolTraits ($symbol);
3395 $desc .= "</refsect2>";
3398 return ($synop, $desc);
3402 #############################################################################
3403 # Function : GetArgs
3404 # Description : Returns the synopsis and detailed description DocBook output
3405 # for the Args of a given GtkObject subclass.
3406 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
3407 #############################################################################
3413 my $child_synop = "";
3414 my $child_desc = "";
3415 my $style_synop = "";
3416 my $style_desc = "";
3419 for ($i = 0; $i <= $#ArgObjects; $i++) {
3420 if ($ArgObjects[$i] eq $object) {
3421 #print "Found arg: $ArgNames[$i]\n";
3422 my $name = $ArgNames[$i];
3423 my $flags = $ArgFlags[$i];
3424 my $flags_string = "";
3428 if ($flags =~ m/c/) {
3429 $kind = "child property";
3432 elsif ($flags =~ m/s/) {
3433 $kind = "style property";
3440 # Remember only one colon so we don't clash with signals.
3441 my $symbol = "${object}:${name}";
3442 # use two dashes and ev. an extra separator here for the same reason.
3443 my $id = &CreateValidSGMLID ("$object--$id_sep$name");
3445 my $type = $ArgTypes[$i];
3447 my $range = $ArgRanges[$i];
3448 my $range_output = CreateValidSGML ($range);
3449 my $default = $ArgDefaults[$i];
3450 my $default_output = CreateValidSGML ($default);
3452 if ($type eq "GtkString") {
3455 if ($type eq "GtkSignal") {
3456 $type = "GtkSignalFunc, gpointer";
3457 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
3458 . &MakeXRef ("gpointer");
3459 } elsif ($type =~ m/^(\w+)\*$/) {
3460 $type_output = &MakeXRef ($1, &tagify($1, "type")) . "*";
3462 $type_output = &MakeXRef ($type, &tagify($type, "type"));
3465 if ($flags =~ m/r/) {
3466 $flags_string = "Read";
3468 if ($flags =~ m/w/) {
3469 if ($flags_string) { $flags_string .= " / "; }
3470 $flags_string .= "Write";
3472 if ($flags =~ m/x/) {
3473 if ($flags_string) { $flags_string .= " / "; }
3474 $flags_string .= "Construct";
3476 if ($flags =~ m/X/) {
3477 if ($flags_string) { $flags_string .= " / "; }
3478 $flags_string .= "Construct Only";
3481 $AllSymbols{$symbol} = 1;
3483 if (defined($SymbolDocs{$symbol}) &&
3484 !IsEmptyDoc($SymbolDocs{$symbol})) {
3485 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
3486 #print ".. [$SymbolDocs{$symbol}][$blurb]\n";
3487 $AllDocumentedSymbols{$symbol} = 1;
3490 if (!($ArgBlurbs[$i] eq "")) {
3491 $AllDocumentedSymbols{$symbol} = 1;
3493 # FIXME: print a warning?
3494 #print ".. no description\n";
3496 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
3499 my $pad1 = " " x (24 - length ($name));
3500 my $pad2 = " " x (20 - length ($type));
3502 my $arg_synop = " "<link linkend=\"$id\">$name</link>"$pad1 $type_output $pad2 : $flags_string\n";
3503 my $arg_desc = "<refsect2 id=\"$id\" role=\"property\"><title>The <literal>"$name"</literal> $kind</title>\n";
3504 $arg_desc .= MakeIndexterms($symbol, $id);
3506 $arg_desc .= OutputSymbolExtraLinks($symbol);
3508 $arg_desc .= "<programlisting> "$name"$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
3509 $arg_desc .= &MakeDeprecationNote($symbol);
3510 $arg_desc .= $blurb;
3512 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
3514 if ($default ne "") {
3515 $arg_desc .= "<para>Default value: $default_output</para>\n";
3517 $arg_desc .= OutputSymbolTraits ($symbol);
3518 $arg_desc .= "</refsect2>\n";
3520 if ($flags =~ m/c/) {
3521 $child_synop .= $arg_synop;
3522 $child_desc .= $arg_desc;
3524 elsif ($flags =~ m/s/) {
3525 $style_synop .= $arg_synop;
3526 $style_desc .= $arg_desc;
3529 $synop .= $arg_synop;
3534 return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
3538 #############################################################################
3539 # Function : ReadSourceDocumentation
3540 # Description : This reads in the documentation embedded in comment blocks
3541 # in the source code (for Gnome).
3543 # Parameter descriptions override any in the template files.
3544 # Function descriptions are placed before any description from
3545 # the template files.
3547 # It recursively descends the source directory looking for .c
3548 # files and scans them looking for specially-formatted comment
3551 # Arguments : $source_dir - the directory to scan.
3552 #############m###############################################################
3554 sub ReadSourceDocumentation {
3555 my ($source_dir) = @_;
3556 my ($file, $dir, @suffix_list, $suffix);
3557 #print "Scanning source directory: $source_dir\n";
3559 # This array holds any subdirectories found.
3562 @suffix_list = split (/,/, $SOURCE_SUFFIXES);
3564 opendir (SRCDIR, $source_dir)
3565 || die "Can't open source directory $source_dir: $!";
3567 foreach $file (readdir (SRCDIR)) {
3568 if ($file =~ /^\./) {
3570 } elsif (-d "$source_dir/$file") {
3571 push (@subdirs, $file);
3572 } elsif (@suffix_list) {
3573 foreach $suffix (@suffix_list) {
3574 if ($file =~ m/\.\Q${suffix}\E$/) {
3575 &ScanSourceFile ("$source_dir/$file");
3578 } elsif ($file =~ m/\.[ch]$/) {
3579 &ScanSourceFile ("$source_dir/$file");
3584 # Now recursively scan the subdirectories.
3585 foreach $dir (@subdirs) {
3586 next if ($IGNORE_FILES =~ m/(\s|^)\Q${dir}\E(\s|$)/);
3587 &ReadSourceDocumentation ("$source_dir/$dir");
3592 #############################################################################
3593 # Function : ScanSourceFile
3594 # Description : Scans one source file looking for specially-formatted comment
3595 # blocks. Later &MergeSourceDocumentation is used to merge any
3596 # documentation found with the documentation already read in
3597 # from the template files.
3599 # Arguments : $file - the file to scan.
3600 #############################################################################
3602 sub ScanSourceFile {
3606 if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
3609 &LogWarning ($file, 1, "Can't find basename for this filename.");
3613 # Check if the basename is in the list of files to ignore.
3614 if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
3618 #print "DEBUG: Scanning $file\n";
3620 open (SRCFILE, $file)
3621 || die "Can't open $file: $!";
3622 my $in_comment_block = 0;
3624 my ($in_description, $in_return, $in_since, $in_stability, $in_deprecated);
3625 my ($description, $return_desc, $return_start, $return_style);
3626 my ($since_desc, $stability_desc, $deprecated_desc);
3628 my $ignore_broken_returns;
3631 # Look for the start of a comment block.
3632 if (!$in_comment_block) {
3633 if (m%^\s*/\*.*\*/%) {
3634 #one-line comment - not gtkdoc
3635 } elsif (m%^\s*/\*\*\s%) {
3636 #print "Found comment block start\n";
3638 $in_comment_block = 1;
3640 # Reset all the symbol data.
3642 $in_description = 0;
3651 $deprecated_desc = "";
3652 $stability_desc = "";
3653 $current_param = -1;
3654 $ignore_broken_returns = 0;
3660 # We're in a comment block. Check if we've found the end of it.
3663 # maybe its not even meant to be a gtk-doc comment?
3664 &LogWarning ($file, $., "Symbol name not found at the start of the comment block.");
3666 # Add the return value description onto the end of the params.
3668 push (@params, "Returns");
3669 push (@params, $return_desc);
3670 if ($return_style eq 'broken') {
3671 &LogWarning ($file, $., "Free-form return value description in $symbol. Use `Returns:' to avoid ambiguities.");
3674 # Convert special SGML characters
3675 $description = &ConvertSGMLChars ($symbol, $description);
3677 for ($k = 1; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3678 $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
3681 # Handle Section docs
3682 if ($symbol =~ m/SECTION:\s*(.*)/) {
3686 if (scalar %KnownSymbols) {
3687 if ((! defined($KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"})) || $KnownSymbols{"$TMPL_DIR/$real_symbol:Long_Description"} != 1) {
3688 &LogWarning ($file, $., "Section $real_symbol is not defined in the $MODULE-section.txt file.");
3692 #print "SECTION DOCS found in source for : '$real_symbol'\n";
3693 $ignore_broken_returns = 1;
3694 for ($k = 0; $k <= $#params; $k += $PARAM_FIELD_COUNT) {
3695 #print " '".$params[$k]."'\n";
3696 $params[$k] = "\L$params[$k]";
3698 if ($params[$k] eq "short_description") {
3699 $key = "$TMPL_DIR/$real_symbol:Short_Description";
3700 } elsif ($params[$k] eq "see_also") {
3701 $key = "$TMPL_DIR/$real_symbol:See_Also";
3702 } elsif ($params[$k] eq "title") {
3703 $key = "$TMPL_DIR/$real_symbol:Title";
3704 } elsif ($params[$k] eq "stability") {
3705 $key = "$TMPL_DIR/$real_symbol:Stability_Level";
3706 } elsif ($params[$k] eq "section_id") {
3707 $key = "$TMPL_DIR/$real_symbol:Section_Id";
3708 } elsif ($params[$k] eq "include") {
3709 $key = "$TMPL_DIR/$real_symbol:Include";
3710 } elsif ($params[$k] eq "image") {
3711 $key = "$TMPL_DIR/$real_symbol:Image";
3713 if (defined($key)) {
3714 $SourceSymbolDocs{$key}=$params[$k+1];
3715 $SourceSymbolSourceFile{$key} = $file;
3716 $SourceSymbolSourceLine{$key} = $.;
3719 $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
3720 $SourceSymbolSourceFile{"$TMPL_DIR/$real_symbol:Long_Description"} = $file;
3721 $SourceSymbolSourceLine{"$TMPL_DIR/$real_symbol:Long_Description"} = $.;
3722 #$SourceSymbolTypes{$symbol} = "SECTION";
3724 #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
3725 $SourceSymbolDocs{$symbol} = $description;
3726 $SourceSymbolParams{$symbol} = [ @params ];
3727 # FIXME $SourceSymbolTypes{$symbol} = "STRUCT,SIGNAL,ARG,FUNCTION,MACRO";
3728 #if (defined $DeclarationTypes{$symbol}) {
3729 # $SourceSymbolTypes{$symbol} = $DeclarationTypes{$symbol}
3731 $SourceSymbolSourceFile{$symbol} = $file;
3732 $SourceSymbolSourceLine{$symbol} = $.;
3736 ($since_desc, my @extra_lines) = split ("\n", $since_desc);
3737 $since_desc =~ s/^\s+//;
3738 $since_desc =~ s/\s+$//;
3739 #print "Since($symbol) : [$since_desc]\n";
3740 $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
3741 if(scalar @extra_lines) {
3742 &LogWarning ($file, $., "multi-line since docs found");
3746 if ($stability_desc) {
3747 $stability_desc = &ParseStabilityLevel($stability_desc, $file, $., "Stability level for $symbol");
3748 $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
3751 if ($deprecated_desc) {
3752 if (exists $Deprecated{$symbol}) {
3755 # don't warn for signals and properties
3756 #if ($symbol !~ m/::?(.*)/) {
3757 if (defined $DeclarationTypes{$symbol}) {
3758 &LogWarning ($file, $.,
3759 "$symbol is deprecated in the inline comments, but no deprecation guards were found around the declaration.".
3760 " (See the --deprecated-guards option for gtkdoc-scan.)");
3763 $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
3767 $in_comment_block = 0;
3771 # Get rid of ' * ' at start of every line in the comment block.
3773 # But make sure we don't get rid of the newline at the end.
3777 #print "DEBUG: scanning :$_";
3779 # If we haven't found the symbol name yet, look for it.
3781 if (m%^\s*(SECTION:\s*\S+)%) {
3783 #print "SECTION DOCS found in source for : '$symbol'\n";
3784 $ignore_broken_returns = 1;
3785 } elsif (m%^\s*([\w:-]*\w)\s*:?\s*$%) {
3787 #print "SYMBOL DOCS found in source for : '$symbol'\n";
3792 # If we're in the return value description, add it to the end.
3794 # If we find another valid returns line, we assume that the first
3795 # one was really part of the description.
3796 if (m/^\s*(returns:|return\s+value:)/i) {
3797 if ($return_style eq 'broken') {
3798 $description .= $return_start . $return_desc;
3801 if ($return_style eq 'sane') {
3802 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3804 $return_style = 'sane';
3805 $ignore_broken_returns = 1;
3807 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3808 $description .= $return_start . $return_desc;
3810 $return_style = 'broken';
3812 } elsif (m%^\s*since:%i) {
3816 } elsif (m%^\s*stability:%i) {
3817 $stability_desc = $';
3820 } elsif (m%^\s*deprecated:%i) {
3821 $deprecated_desc = $';
3831 if (m/^\s*(returns:|return\s+value:)/i) {
3832 if ($return_style eq 'broken') {
3833 $description .= $return_start . $return_desc;
3836 if ($return_style eq 'sane') {
3837 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3839 $return_style = 'sane';
3840 $ignore_broken_returns = 1;
3844 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3846 $return_style = 'broken';
3850 } elsif (m%^\s*deprecated:%i) {
3851 $deprecated_desc = $';
3854 } elsif (m%^\s*stability:%i) {
3855 $stability_desc = $';
3864 if ($in_stability) {
3865 if (m/^\s*(returns:|return\s+value:)/i) {
3866 if ($return_style eq 'broken') {
3867 $description .= $return_start . $return_desc;
3870 if ($return_style eq 'sane') {
3871 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3873 $return_style = 'sane';
3874 $ignore_broken_returns = 1;
3878 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3880 $return_style = 'broken';
3884 } elsif (m%^\s*deprecated:%i) {
3885 $deprecated_desc = $';
3888 } elsif (m%^\s*since:%i) {
3893 $stability_desc .= $_;
3898 if ($in_deprecated) {
3899 if (m/^\s*(returns:|return\s+value:)/i) {
3900 if ($return_style eq 'broken') {
3901 $description .= $return_start . $return_desc;
3904 if ($return_style eq 'sane') {
3905 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3907 $return_style = 'sane';
3908 $ignore_broken_returns = 1;
3912 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3914 $return_style = 'broken';
3918 } elsif (m%^\s*since:%i) {
3922 } elsif (m%^\s*stability:%i) {
3923 $stability_desc = $';
3927 $deprecated_desc .= $_;
3932 # If we're in the description part, check for the 'Returns:' line.
3933 # If that isn't found, add the text to the end.
3934 if ($in_description) {
3935 # Get rid of 'Description:'
3936 s%^\s*Description:%%;
3938 if (m/^\s*(returns:|return\s+value:)/i) {
3939 if ($return_style eq 'broken') {
3940 $description .= $return_start . $return_desc;
3943 if ($return_style eq 'sane') {
3944 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3946 $return_style = 'sane';
3947 $ignore_broken_returns = 1;
3951 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3953 $return_style = 'broken';
3957 } elsif (m%^\s*since:%i) {
3961 } elsif (m%^\s*deprecated:%i) {
3962 $deprecated_desc = $';
3965 } elsif (m%^\s*stability:%i) {
3966 $stability_desc = $';
3975 # We must be in the parameters. Check for the empty line below them.
3977 $in_description = 1;
3981 # Look for a parameter name.
3982 if (m%^\s*@(\S+)\s*:\s*%) {
3983 my $param_name = $1;
3984 my $param_desc = $';
3986 #print "Found parameter: $param_name\n";
3987 # Allow '...' as the Varargs parameter.
3988 if ($param_name eq "...") {
3989 $param_name = "Varargs";
3991 if ("\L$param_name" eq "returns") {
3992 $return_style = 'sane';
3993 $ignore_broken_returns = 1;
3995 push (@params, $param_name);
3996 push (@params, $param_desc);
3997 $current_param += $PARAM_FIELD_COUNT;
4001 # We must be in the middle of a parameter description, so add it on
4002 # to the last element in @params.
4003 if ($current_param == -1) {
4004 &LogWarning ($file, $., "Parsing comment block file : parameter expected.");
4006 $params[$#params] .= $_;
4012 #############################################################################
4013 # Function : OutputMissingDocumentation
4014 # Description : Outputs report of documentation coverage to a file
4017 #############################################################################
4019 sub OutputMissingDocumentation {
4020 my $old_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.txt";
4021 my $new_undocumented_file = "$ROOT_DIR/$MODULE-undocumented.new";
4023 my $n_documented = 0;
4024 my $n_incomplete = 0;
4030 my $buffer_deprecated = "";
4031 my $buffer_descriptions = "";
4033 open(UNDOCUMENTED, ">$new_undocumented_file")
4034 || die "Can't create $new_undocumented_file";
4036 foreach $symbol (sort (keys (%AllSymbols))) {
4037 # FIXME: should we print LogWarnings for undocumented stuff?
4039 #my $ssfile = &GetSymbolSourceFile($symbol);
4040 #my $ssline = &GetSymbolSourceLine($symbol);
4041 #my $location = "defined at " . (defined($ssfile)?$ssfile:"?") . ":" . (defined($ssline)?$ssline:"0") . "\n";
4043 if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include|Section_Id|Image)/) {
4045 if (exists ($AllDocumentedSymbols{$symbol})) {
4047 if (exists ($AllIncompleteSymbols{$symbol})) {
4049 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4050 #$buffer .= "\t0: ".$location;
4052 } elsif (exists $Deprecated{$symbol}) {
4053 if (exists ($AllIncompleteSymbols{$symbol})) {
4055 $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4056 #$buffer .= "\t1a: ".$location;
4058 $buffer_deprecated .= $symbol . "\n";
4059 #$buffer .= "\t1b: ".$location;
4062 if (exists ($AllIncompleteSymbols{$symbol})) {
4064 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
4065 #$buffer .= "\t2a: ".$location;
4067 $buffer .= $symbol . "\n";
4068 #$buffer .= "\t2b: ".$location;
4071 } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
4073 #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
4074 #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
4075 #print "%%%% $symbol : $len1,$len2\n";
4076 if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
4077 || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
4080 # cut off the leading namespace ($TMPL_DIR)
4081 $symbol =~ m/^.*\/(.*)$/;
4082 $buffer_descriptions .= $1 . "\n";
4087 $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
4092 $percent = ($n_documented / $total) * 100.0;
4095 printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
4096 print UNDOCUMENTED "$n_documented symbols documented.\n";
4097 print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
4098 print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
4100 print UNDOCUMENTED $buffer;
4101 close (UNDOCUMENTED);
4103 return &UpdateFileIfChanged ($old_undocumented_file, $new_undocumented_file, 0);
4105 printf "%.0f%% symbol docs coverage", $percent;
4106 print "($n_documented symbols documented, $n_incomplete symbols incomplete, " . ($total - $n_documented) . " not documented)\n";
4107 print "See $MODULE-undocumented.txt for a list of missing docs.\nThe doc coverage percentage doesn't include intro sections.\n";
4111 #############################################################################
4112 # Function : OutputUndeclaredSymbols
4113 # Description : Outputs symbols that are listed in the section file, but not
4114 # declaration is found in the sources
4117 #############################################################################
4119 sub OutputUndeclaredSymbols {
4120 my $old_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.txt";
4121 my $new_undeclared_file = "$ROOT_DIR/$MODULE-undeclared.new";
4123 open(UNDECLARED, ">$new_undeclared_file")
4124 || die "Can't create $new_undeclared_file";
4126 if (%UndeclaredSymbols) {
4127 print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
4128 print UNDECLARED "\n";
4129 print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
4133 return &UpdateFileIfChanged ($old_undeclared_file, $new_undeclared_file, 0);
4136 #############################################################################
4137 # Function : OutputUnusedSymbols
4138 # Description : Outputs symbols that are documented in comments, but not
4139 # declared in the sources
4142 #############################################################################
4144 sub OutputUnusedSymbols {
4146 my $old_unused_file = "$ROOT_DIR/$MODULE-unused.txt";
4147 my $new_unused_file = "$ROOT_DIR/$MODULE-unused.new";
4149 open (UNUSED, ">$new_unused_file")
4150 || die "Can't open $new_unused_file";
4152 foreach $symbol (sort keys (%Declarations)) {
4153 if (!defined ($DeclarationOutput{$symbol})) {
4154 print (UNUSED "$symbol\n");
4158 foreach $symbol (sort (keys (%AllUnusedSymbols))) {
4159 print (UNUSED "$symbol(" . $AllUnusedSymbols{$symbol} . ")\n");
4163 if ($num_unused != 0) {
4164 &LogWarning ($old_unused_file, 1, "$num_unused unused declarations.".
4165 "They should be added to $MODULE-sections.txt in the appropriate place.");
4168 return &UpdateFileIfChanged ($old_unused_file, $new_unused_file, 0);
4172 #############################################################################
4173 # Function : OutputAllSymbols
4174 # Description : Outputs list of all symbols to a file
4177 #############################################################################
4179 sub OutputAllSymbols {
4180 my $n_documented = 0;
4186 open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
4187 || die "Can't create $ROOT_DIR/$MODULE-symbols.txt: $!";
4189 foreach $symbol (sort (keys (%AllSymbols))) {
4190 print SYMBOLS $symbol . "\n";
4196 #############################################################################
4197 # Function : OutputSymbolsWithoutSince
4198 # Description : Outputs list of all symbols without a since tag to a file
4201 #############################################################################
4203 sub OutputSymbolsWithoutSince {
4204 my $n_documented = 0;
4210 open (SYMBOLS, ">$ROOT_DIR/$MODULE-nosince.txt")
4211 || die "Can't create $ROOT_DIR/$MODULE-nosince.txt: $!";
4213 foreach $symbol (sort (keys (%SourceSymbolDocs))) {
4214 if (!defined $Since{$symbol}) {
4215 print SYMBOLS $symbol . "\n";
4223 #############################################################################
4224 # Function : MergeSourceDocumentation
4225 # Description : This merges documentation read from a source file into the
4226 # documentation read in from a template file.
4228 # Parameter descriptions override any in the template files.
4229 # Function descriptions are placed before any description from
4230 # the template files.
4233 #############################################################################
4235 sub MergeSourceDocumentation {
4239 if (scalar %SymbolDocs) {
4240 @Symbols=keys (%SymbolDocs);
4241 #print "num existing entries: ".(scalar @Symbols)."\n";
4242 #print " ",$Symbols[0], " ",$Symbols[1],"\n";
4245 # filter scanned declarations, with what we suppress from -sections.txt
4247 foreach $symbol (keys (%Declarations)) {
4248 if (defined($KnownSymbols{$symbol}) && $KnownSymbols{$symbol} == 1) {
4252 # , add the rest from -sections.txt
4253 foreach $symbol (keys (%KnownSymbols)) {
4254 if ($KnownSymbols{$symbol} == 1) {
4258 # and add whats found in the source
4259 foreach $symbol (keys (%SourceSymbolDocs)) {
4262 @Symbols = keys (%tmp);
4263 #print "num source entries: ".(scalar @Symbols)."\n";
4265 foreach $symbol (@Symbols) {
4266 $AllSymbols{$symbol} = 1;
4268 my $have_tmpl_docs = 0;
4270 ## See if the symbol is documented in template
4271 my $tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4272 my $check_tmpl_doc =$tmpl_doc;
4273 # remove all xml-tags and whitespaces
4274 #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
4275 $check_tmpl_doc =~ s/<.*?>//g;
4276 $check_tmpl_doc =~ s/\s//g;
4278 if ($check_tmpl_doc ne "") {
4279 $have_tmpl_docs = 1;
4280 #print "## [$check_tmpl_doc]\n";
4285 if (exists ($SourceSymbolDocs{$symbol})) {
4286 my $type = $DeclarationTypes {$symbol};
4288 #print "merging [$symbol] from source\n";
4290 my $item = "Parameter";
4291 if (defined ($type)) {
4292 if ($type eq 'STRUCT') {
4294 } elsif ($type eq 'ENUM') {
4296 } elsif ($type eq 'UNION') {
4303 my $src_doc = $SourceSymbolDocs{$symbol};
4304 # remove leading and training whitespaces
4305 $src_doc =~ s/^\s+//;
4306 $src_doc =~ s/\s+$//;
4308 # Don't output warnings for overridden titles as titles are
4309 # automatically generated in the -sections.txt file, and thus they
4310 # are often overridden.
4311 if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
4312 # check if content is different
4313 if ($tmpl_doc ne $src_doc) {
4314 #print "[$tmpl_doc] [$src_doc]\n";
4315 &LogWarning ($SourceSymbolSourceFile{$symbol}, $SourceSymbolSourceLine{$symbol},
4316 "Documentation in template ".$SymbolSourceFile{$symbol}.":".$SymbolSourceLine{$symbol}." for $symbol being overridden by inline comments.");
4320 if ($src_doc ne "") {
4321 $AllDocumentedSymbols{$symbol} = 1;
4324 # Convert <!--PARAMETERS--> with any blank lines around it to
4325 # a </para> followed by <!--PARAMETERS--> followed by <para>.
4326 $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
4328 # Do not add <para> to nothing, it breaks missing docs checks.
4329 my $src_doc_para = "";
4330 if ($src_doc ne "") {
4331 # If there is a blank line, finish the paragraph and start another.
4332 $src_doc = &ConvertBlankLines ($src_doc, $symbol);
4333 $src_doc_para = "<para>\n$src_doc\n</para>";
4335 $src_doc_para =~ s%<para>\n<refsect2%<refsect2%gms;
4336 $src_doc_para =~ s%</refsect2>\n</para>%</refsect2>%gms;
4337 #print "$symbol : [$src_doc][$src_doc_para]\n";
4340 if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
4341 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4342 } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
4343 # For the title/summary/see also section docs we don't want to
4344 # add any <para> tags.
4345 $SymbolDocs{$symbol} = "$src_doc"
4347 $SymbolDocs{$symbol} = "$src_doc_para$tmpl_doc";
4351 if ($symbol =~ m/.*::.*/) {
4352 # For signals we prefer the param names from the source docs,
4353 # since the ones from the templates are likely to contain the
4354 # artificial argn names which are generated by gtkdoc-scangobj.
4355 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4356 # FIXME: we need to check for empty docs here as well!
4358 # The templates contain the definitive parameter names and order,
4359 # so we will not change that. We only override the actual text.
4360 my $tmpl_params = $SymbolParams{$symbol};
4361 if (!defined ($tmpl_params)) {
4362 #print "No merge needed for $symbol\n";
4363 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
4364 # FIXME: we still like to get the number of params and merge
4365 # 1) we would noticed that params have been removed/renamed
4366 # 2) we would catch undocumented params
4367 # params are not (yet) exported in -decl.txt so that we
4368 # could easily grab them :/
4370 my $params = $SourceSymbolParams{$symbol};
4372 #print "Merge needed for $symbol, tmpl_params: ",$#$tmpl_params,", source_params: ",$#$params," \n";
4373 for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4374 my $tmpl_param_name = $$tmpl_params[$j];
4376 # Allow '...' as the Varargs parameter.
4377 if ($tmpl_param_name eq "...") {
4378 $tmpl_param_name = "Varargs";
4381 # Try to find the param in the source comment documentation.
4384 #print " try merge param $tmpl_param_name\n";
4385 for ($k = 0; $k <= $#$params; $k += $PARAM_FIELD_COUNT) {
4386 my $param_name = $$params[$k];
4387 my $param_desc = $$params[$k + 1];
4389 #print " test param $param_name\n";
4390 # We accept changes in case, since the Gnome source
4391 # docs contain a lot of these.
4392 if ("\L$param_name" eq "\L$tmpl_param_name") {
4395 # Override the description.
4396 $$tmpl_params[$j + 1] = $param_desc;
4398 # Set the name to "" to mark it as used.
4404 # If it looks like the parameters are there, but not
4405 # in the right place, try to explain a bit better.
4406 if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
4407 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4408 "Parameters for $symbol must start on the line immediately after the function or macro name.");
4412 # Now we output a warning if parameters have been described which
4414 for ($j = 0; $j <= $#$params; $j += $PARAM_FIELD_COUNT) {
4415 my $param_name = $$params[$j];
4417 # the template builder cannot detect if a macro returns
4419 if(($type eq "MACRO") && ($param_name eq "Returns")) {
4420 # FIXME: do we need to add it then to tmpl_params[] ?
4421 my $num=$#$tmpl_params;
4422 #print " adding Returns: to macro docs for $symbol.\n";
4423 $$tmpl_params[$num+1]="Returns";
4424 $$tmpl_params[$num+2]=$$params[$j+1];
4427 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4428 "$item described in source code comment block but does not exist. $type: $symbol $item: $param_name.");
4434 if ($have_tmpl_docs) {
4435 $AllDocumentedSymbols{$symbol} = 1;
4436 #print "merging [$symbol] from template\n";
4439 #print "[$symbol] undocumented\n";
4443 # if this symbol is documented, check if docs are complete
4444 $check_tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
4445 # remove all xml-tags and whitespaces
4446 #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
4447 $check_tmpl_doc =~ s/<.*?>//g;
4448 $check_tmpl_doc =~ s/\s//g;
4449 if ($check_tmpl_doc ne "") {
4450 my $tmpl_params = $SymbolParams{$symbol};
4451 if (defined ($tmpl_params)) {
4452 my $type = $DeclarationTypes {$symbol};
4454 my $item = "Parameter";
4455 if (defined ($type)) {
4456 if ($type eq 'STRUCT') {
4458 } elsif ($type eq 'ENUM') {
4460 } elsif ($type eq 'UNION') {
4467 #print "Check param docs for $symbol, tmpl_params: ",$#$tmpl_params," entries, type=$type\n";
4469 if ($#$tmpl_params > 0) {
4471 for ($j = 0; $j <= $#$tmpl_params; $j += $PARAM_FIELD_COUNT) {
4472 # Output a warning if the parameter is empty and
4473 # remember for stats.
4474 my $tmpl_param_name = $$tmpl_params[$j];
4475 my $tmpl_param_desc = $$tmpl_params[$j + 1];
4476 if ($tmpl_param_name ne "void" && $tmpl_param_desc !~ m/\S/) {
4477 if (exists ($AllIncompleteSymbols{$symbol})) {
4478 $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
4480 $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
4482 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4483 "$item description for $symbol"."::"."$tmpl_param_name is missing in source code comment block.");
4488 if ($#$tmpl_params == 0) {
4489 $AllIncompleteSymbols{$symbol}="<items>";
4490 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
4491 "$item descriptions for $symbol are missing in source code comment block.");
4493 # $#$tmpl_params==-1 means we don't know about parameters
4494 # this unfortunately does not tell if there should be some
4499 #print "num doc entries: ".(scalar %SymbolDocs)."\n";
4502 #############################################################################
4503 # Function : IsEmptyDoc
4504 # Description : Check if a doc-string is empty. Its also regarded as empty if
4505 # it only consist of whitespace or e.g. FIXME.
4506 # Arguments : the doc-string
4507 #############################################################################
4511 if ($doc =~ /^\s*$/) {
4515 if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
4523 # This converts blank lines to "</para><para>", but only outside CDATA and
4524 # <programlisting> tags.
4525 sub ConvertBlankLines {
4526 return &ModifyXMLElements ($_[0], $_[1],
4527 "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
4528 \&ConvertBlankLinesEndTag,
4529 \&ConvertBlankLinesCallback);
4533 sub ConvertBlankLinesEndTag {
4534 if ($_[0] eq "<!\[CDATA\[") {
4536 } elsif ($_[0] eq "|[") {
4539 return "</programlisting>";
4543 sub ConvertBlankLinesCallback {
4544 my ($text, $symbol, $tag) = @_;
4546 # If we're not in CDATA or a <programlisting> we convert blank lines so
4547 # they start a new <para>.
4549 $text =~ s%\n{2,}%\n</para>\n<para>\n%g;
4556 #############################################################################
4557 # LIBRARY FUNCTIONS - These functions are used in both gtkdoc-mkdb and
4558 # gtkdoc-mktmpl and should eventually be moved to a
4560 #############################################################################
4562 #############################################################################
4563 # Function : ReadDeclarationsFile
4564 # Description : This reads in a file containing the function/macro/enum etc.
4567 # Note that in some cases there are several declarations with
4568 # the same name, e.g. for conditional macros. In this case we
4569 # set a flag in the %DeclarationConditional hash so the
4570 # declaration is not shown in the docs.
4572 # If a macro and a function have the same name, e.g. for
4573 # gtk_object_ref, the function declaration takes precedence.
4575 # Some opaque structs are just declared with 'typedef struct
4576 # _name name;' in which case the declaration may be empty.
4577 # The structure may have been found later in the header, so
4578 # that overrides the empty declaration.
4580 # Arguments : $file - the declarations file to read
4581 # $override - if declarations in this file should override
4582 # any current declaration.
4583 #############################################################################
4585 sub ReadDeclarationsFile {
4586 my ($file, $override) = @_;
4588 if ($override == 0) {
4590 %DeclarationTypes = ();
4591 %DeclarationConditional = ();
4592 %DeclarationOutput = ();
4596 || die "Can't open $file: $!";
4597 my $declaration_type = "";
4598 my $declaration_name;
4600 my $is_deprecated = 0;
4602 if (!$declaration_type) {
4603 if (m/^<([^>]+)>/) {
4604 $declaration_type = $1;
4605 $declaration_name = "";
4606 #print "Found declaration: $declaration_type\n";
4610 if (m%^<NAME>(.*)</NAME>%) {
4611 $declaration_name = $1;
4612 } elsif (m%^<DEPRECATED/>%) {
4614 } elsif (m%^</$declaration_type>%) {
4615 #print "Found end of declaration: $declaration_name\n";
4616 # Check that the declaration has a name
4617 if ($declaration_name eq "") {
4618 print "ERROR: $declaration_type has no name $file:$.\n";
4621 # If the declaration is an empty typedef struct _XXX XXX
4622 # set the flag to indicate the struct has a typedef.
4623 if ($declaration_type eq 'STRUCT'
4624 && $declaration =~ m/^\s*$/) {
4625 #print "Struct has typedef: $declaration_name\n";
4626 $StructHasTypedef{$declaration_name} = 1;
4629 # Check if the symbol is already defined.
4630 if (defined ($Declarations{$declaration_name})
4631 && $override == 0) {
4632 # Function declarations take precedence.
4633 if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
4635 } elsif ($declaration_type eq 'FUNCTION') {
4636 if ($is_deprecated) {
4637 $Deprecated{$declaration_name} = "";
4639 $Declarations{$declaration_name} = $declaration;
4640 $DeclarationTypes{$declaration_name} = $declaration_type;
4641 } elsif ($DeclarationTypes{$declaration_name}
4642 eq $declaration_type) {
4643 # If the existing declaration is empty, or is just a
4644 # forward declaration of a struct, override it.
4645 if ($declaration_type eq 'STRUCT') {
4646 if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4647 if ($is_deprecated) {
4648 $Deprecated{$declaration_name} = "";
4650 $Declarations{$declaration_name} = $declaration;
4651 } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
4652 # Ignore an empty or forward declaration.
4654 &LogWarning ($file, $., "Structure $declaration_name has multiple definitions.");
4657 # set flag in %DeclarationConditional hash for
4658 # multiply defined macros/typedefs.
4659 $DeclarationConditional{$declaration_name} = 1;
4662 &LogWarning ($file, $., "$declaration_name has multiple definitions.");
4665 if ($is_deprecated) {
4666 $Deprecated{$declaration_name} = "";
4668 $Declarations{$declaration_name} = $declaration;
4669 $DeclarationTypes{$declaration_name} = $declaration_type;
4672 $declaration_type = "";
4683 #############################################################################
4684 # Function : ReadSignalsFile
4685 # Description : This reads in an existing file which contains information on
4686 # all GTK signals. It creates the arrays @SignalNames and
4687 # @SignalPrototypes containing info on the signals. The first
4688 # line of the SignalPrototype is the return type of the signal
4689 # handler. The remaining lines are the parameters passed to it.
4690 # The last parameter, "gpointer user_data" is always the same
4691 # so is not included.
4692 # Arguments : $file - the file containing the signal handler prototype
4694 #############################################################################
4696 sub ReadSignalsFile {
4704 my $signal_prototype;
4706 # Reset the signal info.
4707 @SignalObjects = ();
4709 @SignalReturns = ();
4711 @SignalPrototypes = ();
4716 if (!open (INPUT, $file)) {
4717 warn "Can't open $file - skipping signals\n";
4724 $signal_object = "";
4726 $signal_returns = "";
4727 $signal_prototype = "";
4730 if (m/^<NAME>(.*)<\/NAME>/) {
4732 if ($signal_name =~ m/^(.*)::(.*)$/) {
4733 $signal_object = $1;
4734 ($signal_name = $2) =~ s/_/-/g;
4735 #print "Found signal: $signal_name\n";
4737 &LogWarning ($file, $., "Invalid signal name: $signal_name.");
4739 } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
4740 $signal_returns = $1;
4741 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4743 } elsif (m%^</SIGNAL>%) {
4744 #print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
4745 push (@SignalObjects, $signal_object);
4746 push (@SignalNames, $signal_name);
4747 push (@SignalReturns, $signal_returns);
4748 push (@SignalFlags, $signal_flags);
4749 push (@SignalPrototypes, $signal_prototype);
4752 $signal_prototype .= $_;
4760 #############################################################################
4761 # Function : ReadTemplateFile
4762 # Description : This reads in the manually-edited documentation file
4763 # corresponding to the file currently being created, so we can
4764 # insert the documentation at the appropriate places.
4765 # It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
4766 # is a hash of arrays.
4767 # NOTE: This function is duplicated in gtkdoc-mktmpl (but
4768 # slightly different).
4769 # Arguments : $docsfile - the template file to read in.
4770 # $skip_unused_params - 1 if the unused parameters should be
4772 #############################################################################
4774 sub ReadTemplateFile {
4775 my ($docsfile, $skip_unused_params) = @_;
4777 my $template = "$docsfile.sgml";
4778 if (! -f $template) {
4779 #print "File doesn't exist: $template\n";
4782 #print "Reading $template\n";
4784 # start with empty hashes, we merge the source comment for each file
4790 my $current_type = ""; # Type of symbol being read.
4791 my $current_symbol = ""; # Name of symbol being read.
4792 my $symbol_doc = ""; # Description of symbol being read.
4793 my @params; # Parameter names and descriptions of current
4794 # function/macro/function typedef.
4795 my $current_param = -1; # Index of parameter currently being read.
4796 # Note that the param array contains pairs
4797 # of param name & description.
4798 my $in_unused_params = 0; # True if we are reading in the unused params.
4799 my $in_deprecated = 0;
4801 my $in_stability = 0;
4803 open (DOCS, "$template")
4804 || die "Can't open $template: $!";
4806 if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
4809 if ($symbol eq "Title"
4810 || $symbol eq "Short_Description"
4811 || $symbol eq "Long_Description"
4812 || $symbol eq "See_Also"
4813 || $symbol eq "Stability_Level"
4814 || $symbol eq "Include"
4815 || $symbol eq "Image") {
4817 $symbol = $docsfile . ":" . $symbol;
4820 #print "Found symbol: $symbol\n";
4821 # Remember file and line for the symbol
4822 $SymbolSourceFile{$symbol} = $template;
4823 $SymbolSourceLine{$symbol} = $.;
4825 # Store previous symbol, but remove any trailing blank lines.
4826 if ($current_symbol ne "") {
4827 $symbol_doc =~ s/\s+$//;
4828 $SymbolTypes{$current_symbol} = $current_type;
4829 $SymbolDocs{$current_symbol} = $symbol_doc;
4831 # Check that the stability level is valid.
4832 if ($StabilityLevel{$current_symbol}) {
4833 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4836 if ($current_param >= 0) {
4837 $SymbolParams{$current_symbol} = [ @params ];
4839 # Delete any existing params in case we are overriding a
4840 # previously read template.
4841 delete $SymbolParams{$current_symbol};
4844 $current_type = $type;
4845 $current_symbol = $symbol;
4846 $current_param = -1;
4847 $in_unused_params = 0;
4854 } elsif (m/^<!-- # Unused Parameters # -->/) {
4855 #print "DEBUG: Found unused parameters\n";
4856 $in_unused_params = 1;
4859 } elsif ($in_unused_params && $skip_unused_params) {
4860 # When outputting the DocBook we skip unused parameters.
4861 #print "DEBUG: Skipping unused param: $_";
4865 # Check if param found. Need to handle "..." and "format...".
4866 if (s/^\@([\w\.]+):\040?//) {
4867 my $param_name = $1;
4868 my $param_desc = $_;
4869 # Allow variations of 'Returns'
4870 if ($param_name =~ m/^[Rr]eturns?$/) {
4871 $param_name = "Returns";
4874 # strip trailing whitespaces and blank lines
4877 #print "Found param for symbol $current_symbol : '$param_name'= '$_'";
4879 if ($param_name eq "Deprecated") {
4881 $Deprecated{$current_symbol} = $_;
4882 } elsif ($param_name eq "Since") {
4885 $Since{$current_symbol} = $_;
4886 } elsif ($param_name eq "Stability") {
4888 $StabilityLevel{$current_symbol} = $_;
4890 push (@params, $param_name);
4891 push (@params, $param_desc);
4892 $current_param += $PARAM_FIELD_COUNT;
4895 # strip trailing whitespaces and blank lines
4900 if ($in_deprecated) {
4901 $Deprecated{$current_symbol} .= $_;
4902 } elsif ($in_since) {
4903 &LogWarning ($template, $., "multi-line since docs found");
4904 #$Since{$current_symbol} .= $_;
4905 } elsif ($in_stability) {
4906 $StabilityLevel{$current_symbol} .= $_;
4907 } elsif ($current_param >= 0) {
4908 $params[$current_param] .= $_;
4917 # Remember to finish the current symbol doccs.
4918 if ($current_symbol ne "") {
4920 $symbol_doc =~ s/\s+$//;
4921 $SymbolTypes{$current_symbol} = $current_type;
4922 $SymbolDocs{$current_symbol} = $symbol_doc;
4924 # Check that the stability level is valid.
4925 if ($StabilityLevel{$current_symbol}) {
4926 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4929 if ($current_param >= 0) {
4930 $SymbolParams{$current_symbol} = [ @params ];
4932 # Delete any existing params in case we are overriding a
4933 # previously read template.
4934 delete $SymbolParams{$current_symbol};
4943 #############################################################################
4944 # Function : ReadObjectHierarchy
4945 # Description : This reads in the $MODULE-hierarchy.txt file containing all
4946 # the GtkObject subclasses described in this module (and their
4948 # It places them in the @Objects array, and places their level
4949 # in the object hierarchy in the @ObjectLevels array, at the
4950 # same index. GtkObject, the root object, has a level of 1.
4952 # FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
4953 # as it goes along, this should be split out into a separate
4957 #############################################################################
4959 sub ReadObjectHierarchy {
4963 if (! -f $OBJECT_TREE_FILE) {
4966 if (!open (INPUT, $OBJECT_TREE_FILE)) {
4967 warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
4971 # FIXME: use $OUTPUT_FORMAT
4972 # my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.$OUTPUT_FORMAT";
4973 my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
4974 my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
4976 open (OUTPUT, ">$new_tree_index")
4977 || die "Can't create $new_tree_index: $!";
4979 if ($OUTPUT_FORMAT eq "xml") {
4980 my $tree_header = $doctype_header;
4982 $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
4983 print (OUTPUT "$tree_header");
4985 print (OUTPUT "<screen>\n");
4987 # Only emit objects if they are supposed to be documented, or if
4988 # they have documented children. To implement this, we maintain a
4989 # stack of pending objects which will be emitted if a documented
4991 my @pending_objects = ();
4992 my @pending_levels = ();
4996 my $level = (length($`)) / 2 + 1;
4999 while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
5000 my $pobject = pop(@pending_objects);
5001 my $plevel = pop(@pending_levels);
5004 push (@pending_objects, $object);
5005 push (@pending_levels, $level);
5007 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5008 while ($#pending_levels >= 0) {
5009 $object = shift @pending_objects;
5010 $level = shift @pending_levels;
5011 $xref = &MakeXRef ($object);
5013 print (OUTPUT ' ' x ($level * 4), "$xref\n");
5014 push (@Objects, $object);
5015 push (@ObjectLevels, $level);
5019 # LogWarning ($OBJECT_TREE_FILE, $., "unknown type $object");
5023 print (OUTPUT "</screen>\n");
5028 &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
5033 #############################################################################
5034 # Function : ReadInterfaces
5035 # Description : This reads in the $MODULE.interfaces file.
5038 #############################################################################
5040 sub ReadInterfaces {
5043 if (! -f $INTERFACES_FILE) {
5046 if (!open (INPUT, $INTERFACES_FILE)) {
5047 warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
5053 my ($object, @ifaces) = split;
5054 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
5055 my @knownIfaces = ();
5057 # filter out private interfaces, but leave foreign interfaces
5058 foreach my $iface (@ifaces) {
5059 if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
5060 push (@knownIfaces, $iface);
5064 $Interfaces{$object} = join(' ', @knownIfaces);
5070 #############################################################################
5071 # Function : ReadPrerequisites
5072 # Description : This reads in the $MODULE.prerequisites file.
5075 #############################################################################
5077 sub ReadPrerequisites {
5078 %Prerequisites = ();
5080 if (! -f $PREREQUISITES_FILE) {
5083 if (!open (INPUT, $PREREQUISITES_FILE)) {
5084 warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
5090 my ($iface, @prereqs) = split;
5091 if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
5092 my @knownPrereqs = ();
5094 # filter out private prerequisites, but leave foreign prerequisites
5095 foreach my $prereq (@prereqs) {
5096 if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
5097 push (@knownPrereqs, $prereq);
5101 $Prerequisites{$iface} = join(' ', @knownPrereqs);
5107 #############################################################################
5108 # Function : ReadArgsFile
5109 # Description : This reads in an existing file which contains information on
5110 # all GTK args. It creates the arrays @ArgObjects, @ArgNames,
5111 # @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
5113 # Arguments : $file - the file containing the arg information.
5114 #############################################################################
5129 # Reset the args info.
5142 if (!open (INPUT, $file)) {
5143 warn "Can't open $file - skipping args\n";
5160 if (m/^<NAME>(.*)<\/NAME>/) {
5162 if ($arg_name =~ m/^(.*)::(.*)$/) {
5164 ($arg_name = $2) =~ s/_/-/g;
5165 #print "Found arg: $arg_name\n";
5167 &LogWarning ($file, $., "Invalid argument name: $arg_name");
5169 } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
5171 } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
5173 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
5175 } elsif (m/^<NICK>(.*)<\/NICK>/) {
5177 } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
5179 if ($arg_blurb eq "(null)") {
5181 &LogWarning ($file, $., "Property ${arg_object}:${arg_name} has no documentation.");
5183 } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
5185 } elsif (m%^</ARG>%) {
5186 #print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
5187 push (@ArgObjects, $arg_object);
5188 push (@ArgNames, $arg_name);
5189 push (@ArgTypes, $arg_type);
5190 push (@ArgRanges, $arg_range);
5191 push (@ArgFlags, $arg_flags);
5192 push (@ArgNicks, $arg_nick);
5193 push (@ArgBlurbs, $arg_blurb);
5194 push (@ArgDefaults, $arg_default);
5203 #############################################################################
5204 # Function : CheckIsObject
5205 # Description : Returns 1 if the given name is a GObject or a subclass.
5206 # It uses the global @Objects array.
5207 # Note that the @Objects array only contains classes in the
5208 # current module and their ancestors - not all GObject classes.
5209 # Arguments : $name - the name to check.
5210 #############################################################################
5216 foreach $object (@Objects) {
5217 if ($object eq $name) {
5225 #############################################################################
5226 # Function : MakeReturnField
5227 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
5228 # Arguments : $str - the string to pad.
5229 #############################################################################
5231 sub MakeReturnField {
5234 return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));
5237 #############################################################################
5238 # Function : GetSymbolSourceFile
5239 # Description : Get the filename where the symbol docs where taken from.
5240 # Arguments : $symbol - the symbol name
5241 #############################################################################
5243 sub GetSymbolSourceFile {
5246 if (defined($SourceSymbolSourceFile{$symbol})) {
5247 return $SourceSymbolSourceFile{$symbol};
5248 } elsif (defined($SymbolSourceFile{$symbol})) {
5249 return $SymbolSourceFile{$symbol};
5255 #############################################################################
5256 # Function : GetSymbolSourceLine
5257 # Description : Get the file line where the symbol docs where taken from.
5258 # Arguments : $symbol - the symbol name
5259 #############################################################################
5261 sub GetSymbolSourceLine {
5264 if (defined($SourceSymbolSourceLine{$symbol})) {
5265 return $SourceSymbolSourceLine{$symbol};
5266 } elsif (defined($SymbolSourceLine{$symbol})) {
5267 return $SymbolSourceLine{$symbol};