Module: sip-router Branch: andrei/cdefs2doc Commit: becac8950fdfb89585e864bcf838ee30a59f2950 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=becac895...
Author: Andrei Pelinescu-Onciul andrei@iptel.org Committer: Andrei Pelinescu-Onciul andrei@iptel.org Date: Wed Feb 17 22:27:01 2010 +0100
doc: dump_cfg_defs.pl: support for docbook output
Added support for generating docbook output (by using the --docbook option).
---
doc/scripts/cdefs2doc/dump_cfg_defs.pl | 107 +++++++++++++++++++++++++++++-- 1 files changed, 100 insertions(+), 7 deletions(-)
diff --git a/doc/scripts/cdefs2doc/dump_cfg_defs.pl b/doc/scripts/cdefs2doc/dump_cfg_defs.pl index 1dd9759..48e199b 100755 --- a/doc/scripts/cdefs2doc/dump_cfg_defs.pl +++ b/doc/scripts/cdefs2doc/dump_cfg_defs.pl @@ -72,8 +72,12 @@ my @cfg_default; # filled with config var defaults my ($cfg_grp_name, $def_cfg_name, $cfg_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_varline="VARLINE2";
sub show_patch @@ -121,6 +125,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 @@ -136,6 +141,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) @@ -157,6 +193,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, @@ -176,6 +213,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_varline="VARLINE2"; +}elsif (defined $opt_docbook){ + $output_format_header="DOCBOOK_HEADER"; + $output_format_footer="DOCBOOK_FOOTER"; + $output_format_varline="DOCBOOK_VARLINE"; +} + if (! defined $opt_is_tu){ # file is not a gcc translation-unit dump # => we have to create one @@ -342,17 +389,17 @@ if (@cfg_defs > 0){ } # dump the configuration in txt mode if (defined $opt_force_grp_name) { - $cfg_grp_name=$opt_force_grp_name; + $cfg_grp_name=output_esc($opt_force_grp_name); }elsif (!defined $cfg_grp_name && defined $opt_grp_name) { - $cfg_grp_name=$opt_grp_name; + $cfg_grp_name=output_esc($opt_grp_name); } - $~ = "HEADER"; write; - $~ = "VARLINE2" ; + $~ = $output_format_header; write; + $~ = $output_format_varline ; for $l (@cfg_defs){ ($name, $flags, $min, $max, $desc)=@{$l}; $type=""; $extra_txt=""; - $default= ($no>0) ? $cfg_default[$i] : ""; + $default= ($no>0) ? output_esc($cfg_default[$i]) : ""; $i++; if ($min==0 && $max==0) { @@ -373,10 +420,13 @@ if (@cfg_defs > 0){ } $extra_txt.="Read-only." if ($flags & 128 ); - $desc.="."; + $extra_txt=output_esc($extra_txt); + $desc=output_esc($desc . "."); + $name=output_esc($name); # generate txt description write; } + $~ = $output_format_footer; write; }else{ die "no configuration variables found in $file\n"; } @@ -401,6 +451,9 @@ Configuration Variables@*
.
+format FOOTER = +. + format VARLINE = @>. @<<<<<<<<<<<<<<<<<<< - ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $i, $name, $desc @@ -432,3 +485,43 @@ $i, (valid_grp_name $cfg_grp_name)?$cfg_grp_name . "." . $name : $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="config_vars@*"> +(valid_grp_name $cfg_grp_name) ? "." . $cfg_grp_name : "" + <title> Configuration Variables@*</title> +(valid_grp_name $cfg_grp_name) ? " for " . $cfg_grp_name : "" + + +. + +format DOCBOOK_FOOTER = +</chapter> +. + +format DOCBOOK_VARLINE = +<section id="@*"> + (valid_grp_name $cfg_grp_name)?$cfg_grp_name . "." . $name : $name + <title>@*</title> + (valid_grp_name $cfg_grp_name)?$cfg_grp_name . "." . $name : $name + <para> +~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + $desc + </para> +~ <para>Default value: @*.</para> + $default +~ <para>Range: @* - @*.</para> + $min, $max +~ <para>Type: @*.</para> + $type + <para> +~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + $extra_txt + </para> +</section> + +.