1
0
mirror of https://github.com/cc65/cc65.git synced 2024-11-11 01:05:25 +00:00
cc65/src/ld65/cfg/cvt-cfg.pl
cuz 76b41b3f9a Fixed a typo
git-svn-id: svn://svn.cc65.org/cc65/trunk@1763 b7a2c559-68d2-44c3-8de9-860c34a00d81
2002-12-13 11:26:21 +00:00

68 lines
1.3 KiB
Perl
Executable File

#!/usr/bin/perl
# Check number of params
die "Usage: cvt-cfg.pl input output varname\n" unless ($#ARGV == 2);
# Get the parameters
$InputName = shift (@ARGV);
$OutputName = shift (@ARGV);
$VarName = shift (@ARGV);
# Open both files
open (IN, "<$InputName") or die "Cannot open $InputName\n";
open (OUT, ">$OutputName") or die "Cannot open $OutputName\n";
# Print the header to the output file
print OUT "static const char $VarName [] = \n";
# Read from input, print to output
while ($Line = <IN>) {
# Remove the newline
chomp $Line;
# Separate an existing comment. No need to be overly clever, just ignore
# hash marks in strings.
if ($Line =~ /(.*?)(\s*)(\#\s*)(.*?)\s*$/) {
$Line = $1;
$CommentSpace = $2;
$Comment = $4;
} else {
$CommentSpace = "";
$Comment = "";
}
# Remove leading and trailing spaces
$Line =~ s/^\s*|\s*$//g;
# Replace control chars
$Line =~ s/\\/\\\\/g;
$Line =~ s/\"/\\\"/g;
$Line =~ s/\'/\\\'/g;
# Print to output
print OUT "\"$Line\\n\"";
# Add a comment if we have one
if ($Comment ne "") {
print OUT "$CommentSpace/* $Comment */";
}
# Terminate the line
print OUT "\n";
}
# Terminate the variable declaration
print OUT ";\n";
# Close the files
close IN;
close OUT;
# Done
exit 0;