[sr-dev] git:andrei/cdefs2doc: doc: dump_rpcs.pl: support for docbook output

Andrei Pelinescu-Onciul andrei at iptel.org
Wed Feb 17 17:38:53 CET 2010


Module: sip-router
Branch: andrei/cdefs2doc
Commit: 1b86219cfd0b0a08a26e90d902303f83801ac39c
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=1b86219cfd0b0a08a26e90d902303f83801ac39c

Author: Andrei Pelinescu-Onciul <andrei at iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei at iptel.org>
Date:   Wed Feb 17 17:19:11 2010 +0100

doc: dump_rpcs.pl: support for docbook output

Added support for generating docbook output (by using the
 --docbook option).

---

 doc/scripts/cdefs2doc/dump_rpcs.pl |  103 +++++++++++++++++++++++++++++++++---
 1 files changed, 95 insertions(+), 8 deletions(-)

diff --git a/doc/scripts/cdefs2doc/dump_rpcs.pl b/doc/scripts/cdefs2doc/dump_rpcs.pl
index 7cac705..706ec80 100755
--- a/doc/scripts/cdefs2doc/dump_rpcs.pl
+++ b/doc/scripts/cdefs2doc/dump_rpcs.pl
@@ -66,8 +66,12 @@ my %rpc_docs; # hash containing rpc_doc_varname -> doc_string mappings
 my ($rpc_grp_name, $rpc_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_rpcline="RPCLINE";
 
 
 sub show_patch
@@ -114,6 +118,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
@@ -129,6 +134,37 @@ Options:
 
 }
 
+
+
+# escape a string for xml use
+# params: string to be escaped
+# return: escaped string
+sub xml_escape{
+	my $s=shift;
+	my %escapes = (
+		'"' => '&quot;',
+		"'" => '&apos;',
+		'&' => '&amp;',
+		'<' => '&lt;',
+		'>' => '&gt;'
+	);
+	
+	$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)
@@ -150,6 +186,7 @@ sub expr_op0{
 if ($#ARGV < 0 || ! GetOptions(	'help|h|?' => \$opt_help,
 								'file|f=s' => \$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,
@@ -169,6 +206,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_rpcline="RPCLINE";
+}elsif (defined $opt_docbook){
+	$output_format_header="DOCBOOK_HEADER";
+	$output_format_footer="DOCBOOK_FOOTER";
+	$output_format_rpcline="DOCBOOK_RPCLINE";
+}
+
 if (! defined $opt_is_tu){
 	# file is not a gcc translation-unit dump
 	# => we have to create one
@@ -337,23 +384,25 @@ if (@rpc_exports > 0){
 	}
 	# dump the configuration in txt mode
 	if (defined $opt_force_grp_name) {
-		$rpc_grp_name=$opt_force_grp_name;
+		$rpc_grp_name=output_esc($opt_force_grp_name);
 	}elsif (!defined $rpc_grp_name && defined $opt_grp_name) {
-		$rpc_grp_name=$opt_grp_name;
+		$rpc_grp_name=output_esc($opt_grp_name);
 	}
-	$~ = "HEADER"; write;
-	$~ = "RPCLINE" ;
+	$~ = $output_format_header; write;
+	$~ = $output_format_rpcline ;
 	for $l (@rpc_exports){
 		($name, $desc, $flags)=@{$l};
 		$extra_txt="";
 		$desc=(defined $rpc_docs{$desc} && $rpc_docs{$desc} ne "")?
-				$rpc_docs{$desc}:
-				"Documentation missing ($desc).";
+				output_esc($rpc_docs{$desc}):
+				output_esc("Documentation missing ($desc).");
 		$i++;
-		$extra_txt.="Returns an array." if ($flags & 1 );
+		$extra_txt.=output_esc("Returns an array.") if ($flags & 1 );
+		$name=output_esc($name);
 		# generate txt description
 		write;
 	}
+	$~ = $output_format_footer; write;
 }else{
 	die "no rpc exports found in $file\n";
 }
@@ -378,6 +427,9 @@ RPC Exports@*
 
 .
 
+format FOOTER =
+.
+
 format RPCLINE =
 @>. @*
 $i, $name
@@ -387,3 +439,38 @@ $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="rpc_exports@*">
+(valid_grp_name $rpc_grp_name) ? "." . $rpc_grp_name : ""
+	<title>
+RPC Exports@*
+(valid_grp_name $rpc_grp_name) ? " for " . $rpc_grp_name : ""
+	</title>
+
+
+.
+
+format DOCBOOK_FOOTER =
+</chapter>
+.
+
+
+format DOCBOOK_RPCLINE =
+<section id="@*"><title>@*</title>
+$name, $name
+<para>
+~~      ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+        $desc
+</para>
+<para>
+~~      ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+        $extra_txt
+</para>
+</section>
+
+.




More information about the sr-dev mailing list