Stefan Kamphausen
mail@skamphausen.de
http://www.skamphausen.de
Description:
This script takes a C source code file as input and converts
it to C source code that will printf exactly that file.
I uses an array of translation rules so it should be expandable
(and maybe they're not complete yet?).
If you use this together with a little elisp snippet that
puts the output of a programm into the current buffer it is
quite useful.
#!/usr/bin/perl -w
$usage = "$0 c-source-file\n".
"Converts a C source into printf's for another C File.\n";
die $usage unless $ARGV[0];
$cfile = $ARGV[0];
@rules = ('\x5C' => "\x5C"."\x5C",
'"' => '\"',
"'" => "\'",
'%' => '%%');
open(C,"<$cfile") or die "Couldn't open source file.\n$!";
while (<C>) {
chomp;
$line = $_;
for ($i=0;$i<$#rules;$i+=2) {
$line =~ s($rules[$i])($rules[$i+1])g;
}
print "printf(\"$line\\n\");\n";
}