1 eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
2 & eval 'exec perl -S $0 $argv:q'
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.
33 print STDERR
"$0 (", $lineno, "): Unbalanced macro pairs\n" if ($indent < 0);
34 $retv = $indent - 1 if ($indent > 0);
41 print OUT
" " x
&get_indent
(), "<!-- $comment -->\n";
47 my $standalone = shift;
49 print OUT
" " x
&get_indent
(), "<$name";
54 print OUT
" ", pop (@attnames), '="', pop (@attvalues), '"';
73 print OUT
" " x
&get_indent
(), "</$name>\n";
86 if ($ARGV[0] =~ m/^-i/i) {
90 elsif ($ARGV[0] =~ m/^-o/i) {
92 $outfile = "$ARGV[0]";
94 elsif ($ARGV[0] =~ m/^-verbose/i) {
97 elsif ($ARGV[0] =~ m/^-nocomment/i) {
100 elsif ($ARGV[0] =~ m/^-(\?|h|help)/i) { # Help information
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
115 elsif ($ARGV[0] =~ m/^-/) {
116 warn "$0: unknown option $ARGV[0]\n";
120 die "unknow argument\n";
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";
139 open (FH
, "< $infile");
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) {
157 print "INPUT =\n$_\n" if ($verbose);
159 if (s/^\s*\#(.*)//) {
161 print "# $1\n" if ($verbose);
164 acexml_start
("module", 0);
165 print "open module\n" if ($verbose);
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+"([^"]*)")?//) {
181 acexml_start
("streamdef");
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);
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+("(.*)"))?//) {
208 acexml_start
("streamdef", 0);
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+)//) {
222 push @attnames, ("id");
223 push @attvalues, ("$name");
224 acexml_start
("stream", 0);
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+"([^"]*)")?//) {
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);
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+("(.*)"))?//) {
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+)//) {
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+)//) {
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+)//) {
289 push @attnames, ("id");
290 push @attvalues, ("$name");
291 acexml_start
("suspend", 1);
292 print "suspend $name\n" if ($verbose);
299 acexml_end
("ACE_Svc_Conf");