version 1.4, 2005/02/25 22:55:23
|
version 1.5, 2005/02/26 02:10:50
|
|
|
my $file; #each of the files we are working on | my $file; #each of the files we are working on |
my $varname; #file name converted to variable name | my $varname; #file name converted to variable name |
my $buffer; #buffer to store the hexified contents of a file till output | my $buffer; #buffer to store the hexified contents of a file till output |
|
my $readcount; #number of chars actually read |
|
|
| |
# no input record separator to just slurp everything | # no input record separator to just slurp everything |
undef $INPUT_RECORD_SEPARATOR; | undef $INPUT_RECORD_SEPARATOR; |
|
|
#hex contents of the file | #hex contents of the file |
#BUG:have to get rid of the last comma | #BUG:have to get rid of the last comma |
print "const static char file_$varname"."[] = {\n"; | print "const static char file_$varname"."[] = {\n"; |
while ( read(FILE, $buffer, 16) ) { |
|
|
|
|
|
|
while ( $readcount=read(FILE, $buffer, 16) ) { |
|
|
|
die("Read error in $file:$OS_ERROR") unless defined($readcount); |
$buffer =~ s/(.|\n)/'0x' . unpack('H2', $1).', '/ge; | $buffer =~ s/(.|\n)/'0x' . unpack('H2', $1).', '/ge; |
|
$buffer =~ s/(, )$//g if($readcount < 16); |
print "\t$buffer\n"; | print "\t$buffer\n"; |
|
|
} | } |
print "};\n"; | print "};\n"; |
close FILE; | close FILE; |