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