2 ## -----------------------------------------------------------------------
4 ## Copyright 1998-2004 H. Peter Anvin - All Rights Reserved
6 ## This program is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation, Inc., 53 Temple Place Ste 330,
9 ## Boston MA 02111-1307, USA; either version 2 of the License, or
10 ## (at your option) any later version; incorporated herein by reference.
12 ## -----------------------------------------------------------------------
15 # bin2c.pl: binary file to C source converter
19 eval { binmode STDIN
; };
22 print STDERR
"Usage: $0 table_name < input_file > output_file\n";
26 ($table_name) = @ARGV;
28 printf "unsigned char %s[] = {\n", $table_name;
35 while ( ($n = read(STDIN
, $data, 4096)) > 0 ) {
37 for ( $i = 0 ; $i < $n ; $i++ ) {
38 $byte = substr($data, $i, 1);
39 if ( $pos >= $linelen ) {
42 } elsif ( $pos > 0 ) {
47 printf("0x%02x", unpack("C", $byte));
52 printf "\n};\n\nunsigned int %s_len = %u;\n", $table_name, $total_len;
56 printf "\nint %s_mtime = %d;\n", $table_name, $st[9];