Module: sip-router
Branch: andrei/cdefs2doc
Commit: 088a8a7c3214823a16f55f95b90aa6071721b49b
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=088a8a7…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Thu Feb 18 12:31:59 2010 +0100
doc: dump_selects.pl: support for docbook output
Added support for generating docbook output (by using the
--docbook option).
---
doc/scripts/cdefs2doc/dump_selects.pl | 100 ++++++++++++++++++++++++++++++---
1 files changed, 91 insertions(+), 9 deletions(-)
diff --git a/doc/scripts/cdefs2doc/dump_selects.pl
b/doc/scripts/cdefs2doc/dump_selects.pl
index 5de697e..84a1cda 100755
--- a/doc/scripts/cdefs2doc/dump_selects.pl
+++ b/doc/scripts/cdefs2doc/dump_selects.pl
@@ -63,8 +63,12 @@ my @core_exports; # filled with select definitions from core (if -c is
used)
my ($sel_grp_name, $sel_var_name);
my ($opt_help, $opt_txt, $opt_is_tu, $dbg, $opt_grp_name, $opt_patch);
-my $opt_force_grp_name;
+my ($opt_force_grp_name, $opt_docbook);
+# default output formats
+my $output_format_header="HEADER";
+my $output_format_footer="FOOTER";
+my $output_format_selline="SELLINE";
sub show_patch
@@ -113,6 +117,7 @@ Options:
is autodetected (see also -g).
--gcc gcc_name - run gcc_name instead of gcc.
-t | --txt - text mode output.
+ --docbook | --xml - docbook output (xml).
-T | --tu - the input file is in raw gcc translation
unit format (as produced by
gcc -fdump-translation-unit -c ). If not
@@ -128,6 +133,37 @@ Options:
}
+
+
+# escape a string for xml use
+# params: string to be escaped
+# return: escaped string
+sub xml_escape{
+ my $s=shift;
+ my %escapes = (
+ '"' => '"',
+ "'" => ''',
+ '&' => '&',
+ '<' => '<',
+ '>' => '>'
+ );
+
+ $s=~s/(["'&<>])/$escapes{$1}/g;
+ return $s;
+}
+
+
+
+# escape a string according with the output requirements
+# params: string to be escaped
+# return: escaped string
+sub output_esc{
+ return xml_escape(shift) if defined $opt_docbook;
+ return shift;
+}
+
+
+
# eliminate casts and expressions.
# (always go on the first operand)
# params: node (GCC::Node)
@@ -454,6 +490,7 @@ if ($#ARGV < 0 || ! GetOptions( 'help|h|?' =>
\$opt_help,
'file|f=s' => \$file,
'core|c=s' => \$core_file,
'txt|t' => \$opt_txt,
+ 'docbook|xml' => \$opt_docbook,
'tu|T' => \$opt_is_tu,
'source|src|s=s' => \$src_fname,
'defs|d=s'=>\$c_defs,
@@ -473,6 +510,16 @@ if ($#ARGV < 0 || ! GetOptions( 'help|h|?' =>
\$opt_help,
do { show_patch(); exit 0; } if (defined $opt_patch);
do { select(STDERR); help(); exit 1 } if (!defined $file);
+if (defined $opt_txt){
+ $output_format_header="HEADER";
+ $output_format_footer="FOOTER";
+ $output_format_selline="SELLINE";
+}elsif (defined $opt_docbook){
+ $output_format_header="DOCBOOK_HEADER";
+ $output_format_footer="DOCBOOK_FOOTER";
+ $output_format_selline="DOCBOOK_SELLINE";
+}
+
process_file($file, \@sel_exports, defined $opt_is_tu);
process_file($core_file, \@core_exports, 0) if (defined $core_file);
print(STDERR "Done.\n") if $dbg;
@@ -485,23 +532,24 @@ if (@sel_exports > 0){
$i=0;
# dump the configuration in txt mode
if (defined $opt_force_grp_name) {
- $sel_grp_name=$opt_force_grp_name;
+ $sel_grp_name=output_esc($opt_force_grp_name);
}elsif (!defined $sel_grp_name && defined $opt_grp_name) {
- $sel_grp_name=$opt_grp_name;
+ $sel_grp_name=output_esc($opt_grp_name);
}
print(STDERR "Generating select list...\n") if $dbg;
my @sels = gen_selects "0";
- $~ = "HEADER"; write;
- $~ = "SELLINE" ;
+ $~ = $output_format_header; write;
+ $~ = $output_format_selline ;
for $s (@sels){
- $extra_txt="";
- $desc="";
- $name=$s;
+ $extra_txt=output_esc("");
+ $desc=output_esc("");
+ $name=output_esc($s);
$i++;
- #$extra_txt.="Returns an array." if ($flags & 1 );
+ #$extra_txt.=output_esc("Returns an array.") if ($flags & 1 );
# generate txt description
write;
}
+ $~ = $output_format_footer; write;
}else{
die "no selects found in $file\n";
}
@@ -526,6 +574,9 @@ Selects@*
.
+format FOOTER =
+.
+
format SELLINE =
@>>. @*
$i, $name
@@ -534,3 +585,34 @@ $i, $name
~~
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$extra_txt
.
+
+
+format DOCBOOK_HEADER =
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- this file is autogenerated, do not edit! -->
+<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
+ "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
+<chapter id="select_list@*">
+(valid_grp_name $sel_grp_name) ? "." . $sel_grp_name : ""
+ <title>Selects List@*</title>
+(valid_grp_name $sel_grp_name) ? " for " . $sel_grp_name : ""
+ <orderedlist>
+
+
+.
+
+format DOCBOOK_FOOTER =
+ </orderedlist>
+</chapter>
+.
+
+format DOCBOOK_SELLINE =
+ <listitem>@*
+ $name
+~~<para>^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
</para>
+ $desc
+~~<para>^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
</para>
+ $extra_txt
+ </listitem>
+
+.