Merge pull request #2240 from DOCGroup/revert-2239-jwi-pi23
[ACE_TAO.git] / ACE / bin / svcconf-convert.pl
blob76b6e4cfed9aa51370f749ba5900fb1bcd0a400c
1 eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
2 & eval 'exec perl -S $0 $argv:q'
3 if 0;
6 # File: svcconf-convert.pl:
7 # Purpose: This perl script convert classic svc.conf file into XML svc.conf file format.
8 # Usage: svcconf-convert.pl [-i infile] [-o outfile] [-verbose] [-nocomment]
9 # -i: Specify the input classic svc.conf filename.
10 # If omitted, the default input filename is "svc.conf".
11 # -o: Specify the output XML svc.conf filename.
12 # If this argument is omitted, the resulting XML file will be written
13 # to file called <input filename>.xml.
14 # -verbose: Verbose output.
15 # -nocomment: Remove all comments. Use this argument if you have comments
16 # mixing in the middle of a classic svc.conf directive.
18 $indent = 0;
20 sub inc_indent
22 $indent += 2;
25 sub dec_indent
27 $indent -= 2;
30 sub get_indent
32 $retv = 0;
33 print STDERR "$0 (", $lineno, "): Unbalanced macro pairs\n" if ($indent < 0);
34 $retv = $indent - 1 if ($indent > 0);
35 $retv;
38 sub acexml_comment
40 my $comment = shift;
41 print OUT " " x &get_indent (), "<!-- $comment -->\n";
44 sub acexml_start
46 my $name = shift;
47 my $standalone = shift;
49 print OUT " " x &get_indent (), "<$name";
52 while (@attnames)
54 print OUT " ", pop (@attnames), '="', pop (@attvalues), '"';
57 if ($standalone != 0)
59 print OUT "/>\n";
61 else
63 print OUT ">\n";
64 inc_indent ();
68 sub acexml_end
70 my $name = shift;
72 dec_indent ();
73 print OUT " " x &get_indent (), "</$name>\n";
76 $verbose = 0;
77 $nocomment = 0;
78 @attvalues = ();
79 @attnames = ();
80 $stream = "";
81 $infile = "";
82 $outfile = "";
84 while ( $#ARGV >= 0)
86 if ($ARGV[0] =~ m/^-i/i) {
87 shift;
88 $infile = "$ARGV[0]";
90 elsif ($ARGV[0] =~ m/^-o/i) {
91 shift;
92 $outfile = "$ARGV[0]";
94 elsif ($ARGV[0] =~ m/^-verbose/i) {
95 $verbose = 1;
97 elsif ($ARGV[0] =~ m/^-nocomment/i) {
98 $nocomment = 1;
100 elsif ($ARGV[0] =~ m/^-(\?|h|help)/i) { # Help information
101 print
102 " Usage: svcconf-convert.pl [-i infile] [-o outfile] [-verbose] [-nocomment]
103 -i: Specify the input classic svc.conf filename.
104 If omitted, the default input filename is 'svc.conf'.
105 -o: Specify the output XML svc.conf filename.
106 If this argument is omitted, the resulting XML file will
107 be written to file called <input filename>.xml.
108 -verbose: Verbose output.
109 -nocomment: Remove all comments. Use this argument if you
110 have comments mixing in the middle of a classic
111 svc.conf directive.
113 exit;
115 elsif ($ARGV[0] =~ m/^-/) {
116 warn "$0: unknown option $ARGV[0]\n";
117 exit 1;
119 else {
120 die "unknow argument\n";
122 shift;
125 if ($infile eq "") {
126 print "Using default svc.conf name\n" if ($verbose != 0);
127 $infile = "svc.conf";
131 if ($outfile eq "") {
132 $outfile = "$infile.xml";
134 print "OUTFILE = $outfile \n" if ($verbose);
136 open (OUT, "> $outfile") or die "Unable to open $outfile\n";
138 undef $/;
139 open (FH, "< $infile");
140 $_ = <FH>;
142 if ($nocomment) {
143 if (s/^\#(.*)$//mg) {
144 print "ts = $_\n" if ($verbose != 0);
148 print "------------------------------------------------------------\n" if ($verbose != 0);
150 print OUT "<?xml version='1.0'?>\n";
151 print OUT "<!-- Converted from $infile by svcconf-convert.pl -->\n";
152 acexml_start ("ACE_Svc_Conf", 0);
154 while (length ($_) != 0) {
155 s/^\s*$//mg;
157 print "INPUT =\n$_\n" if ($verbose);
158 PARSE: {
159 if (s/^\s*\#(.*)//) {
160 acexml_comment ($1);
161 print "# $1\n" if ($verbose);
163 if (s/^\s*{//) {
164 acexml_start ("module", 0);
165 print "open module\n" if ($verbose);
168 if (s/^\s*}//) {
169 acexml_end ("module");
170 acexml_end ($stream);
171 print "close module\n" if ($verbose);
174 if (s/^\s*stream\s+dynamic\s+(\w+)\s+(\w+)\s*\*\s*(\S+):(\S+)\s*\(\s*\)(\s+(active|inactive))?(\s+"([^"]*)")?//) {
175 $name = $1;
176 $type = $2;
177 $path = $3;
178 $init = $4;
179 $state = $6;
180 $param = $8;
181 acexml_start ("streamdef");
182 if ($status ne "") {
183 push @attnames, ("status");
184 push @attvalues, ("$state");
186 push @attnames, ("type");
187 push @attvalues, ("$type");
188 push @attnames, ("id");
189 push @attvalues, ("$name");
190 acexml_start ("dynamic", 0);
191 if ($param ne "") {
192 push @attnames, ("params");
193 push @attvalues, ("$param");
195 push @attnames, ("init");
196 push @attvalues, ("$init");
197 push @attnames, ("path");
198 push @attvalues, ("$path");
199 acexml_start ("initializer", 1);
200 acexml_end ("dynamic");
201 $stream = "streamdef";
202 print "stream dynamic $name $type * $init:$path \"$param\" $state\n" if ($verbose);
205 if (s/^\s*stream\s+static\s+(\w+)(\s+("(.*)"))?//) {
206 $name = $1;
207 $param = $4;
208 acexml_start ("streamdef", 0);
209 if ($param ne "") {
210 push @attnames, ("params");
211 push @attvalues, ("$param");
213 push @attnames, ("id");
214 push @attvalues, ("$name");
215 acexml_start ("static", 1);
216 $stream = "streamdef";
217 print "static $name \"$param\"\n" if ($verbose);
220 if (s/^\s*stream\s+(\w+)//) {
221 $name = $1;
222 push @attnames, ("id");
223 push @attvalues, ("$name");
224 acexml_start ("stream", 0);
225 $stream = "stream";
226 print "stream $name\n" if ($verbose);
229 if (s/^\s*dynamic\s+(\w+)\s+(\w+)\s*\*\s*(\S+):(\S+)\s*\(\s*\)(\s+(active|inactive))?(\s+"([^"]*)")?//) {
230 $name = $1;
231 $type = $2;
232 $path = $3;
233 $init = $4;
234 $state = $6;
235 $param = $8;
236 if ($status ne "") {
237 push @attnames, ("status");
238 push @attvalues, ("$state");
240 push @attnames, ("type");
241 push @attvalues, ("$type");
242 push @attnames, ("id");
243 push @attvalues, ("$name");
244 acexml_start ("dynamic", 0);
245 if ($param ne "") {
246 push @attnames, ("params");
247 push @attvalues, ("$param");
249 push @attnames, ("init");
250 push @attvalues, ("$init");
251 push @attnames, ("path");
252 push @attvalues, ("$path");
253 acexml_start ("initializer", 1);
254 acexml_end ("dynamic");
255 print "dynamic $name $type * $init:$path \"$param\" $state\n" if ($verbose);
258 if (s/^\s*static\s+(\w+)(\s+("(.*)"))?//) {
259 $name = $1;
260 $param = $4;
261 if ($param ne "") {
262 push @attnames, ("params");
263 push @attvalues, ("$param");
265 push @attnames, ("id");
266 push @attvalues, ("$name");
267 acexml_start ("static", 1);
268 print "static $name \"$param\"\n" if ($verbose);
271 if ( s/^\s*resume\s+(\w+)//) {
272 $name = $1;
273 push @attnames, ("id");
274 push @attvalues, ("$name");
275 acexml_start ("resume", 1);
276 print "resume $name\n" if ($verbose);
279 if ( s/^\s*remove\s+(\w+)//) {
280 $name = $1;
281 push @attnames, ("id");
282 push @attvalues, ("$name");
283 acexml_start ("remove", 1);
284 print "remove $name\n" if ($verbose);
287 if ( s/^\s*suspend\s+(\w+)//) {
288 $name = $1;
289 push @attnames, ("id");
290 push @attvalues, ("$name");
291 acexml_start ("suspend", 1);
292 print "suspend $name\n" if ($verbose);
295 $nothing = 1;
299 acexml_end ("ACE_Svc_Conf");