1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#!/usr/bin/env perl
## asc2c -- convert an ASCII file into a statically initialised
## C array of characters
##
## Copyright (c) Ralf S. Engelschall, All Rights Reserved.
use strict;
use warnings;
use autodie;
my ( $in_fn, $out_fn, $name ) = @ARGV;
if ( @ARGV != 3 )
{
die "Usage: $0 ascii-file c-file buffer-name\n";
}
open( my $in_fh, '<', $in_fn );
open( my $out_c_fh, '>', "$out_fn.c" );
$out_c_fh->print(
"/* $in_fn.c -- automatically generated by asc2c */\n",
"\n", "char *$name = \\\n",
);
while ( my $l = <$in_fh> )
{
chomp $l;
$l =~ s|\\|\\\\|g;
$l =~ s|\"|\\\"|g;
printf {$out_c_fh} "\"%s\\n\"\\\n", $l;
}
print {$out_c_fh} ";\n\n/*EOF*/\n";
close($in_fh);
close($out_c_fh);
|