ossp-pkg/iselect/etc/asc2c
#!/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.
##
$filein = $ARGV[0];
$fileout = $ARGV[1];
$name = $ARGV[2];
$version = $ARGV[3];
if ($#ARGV ne 3) {
printf(STDERR "Usage: $0 ascii-file c-file buffer-name version\n");
exit(1);
}
open(IN, "<$filein");
open(OUTC, ">$fileout.c");
print OUTC "/* $fileout.c -- automatically generated by asc2c */\n";
print OUTC "\n";
print OUTC "#include <stdio.h>\n";
print OUTC "\n";
print OUTC "char *$name\[\] = {\\\n";
while (<IN>) {
s|\n$||;
s|\\|\\\\|g;
s|\"|\\\"|g;
s|\@V\@|$version|g;
printf(OUTC "\"%s\",\n", $_);
}
print OUTC "NULL };\n";
print OUTC "\n";
print OUTC "/*EOF*/\n";
$filename = "$fileout.h";
$filename =~ tr|a-z.|A-Z_|;
close(IN);
close(OUTC);
##EOF##