3 # Check number of params
4 die "Usage: cvt-cfg.pl input output varname\n" unless ($#ARGV == 2);
7 $InputName = shift (@ARGV);
8 $OutputName = shift (@ARGV);
9 $VarName = shift (@ARGV);
12 open (IN, "<$InputName") or die "Cannot open $InputName\n";
13 open (OUT, ">$OutputName") or die "Cannot open $OutputName\n";
15 # Print the header to the output file
16 print OUT "static char $VarName" . "[] = \n";
18 # Read from input, print to output
19 while ($Line = <IN>) {
24 # Separate an existing comment. No need to be overly clever, just ignore
25 # semicolons in strings.
26 if ($Line =~ /(.*?)(\s*)(;\s*)(.*?)\s*$/) {
35 # Remove leading and trailing spaces
36 $Line =~ s/^\s*|\s*$//g;
41 print OUT "/* $Comment */\n";
46 # Replace control chars
52 print OUT "\"$Line\\n\"";
54 # Add a comment if we have one
56 print OUT "$CommentSpace/* $Comment */";
63 # Terminate the variable declaration