2 ## -----------------------------------------------------------------------
4 ## Copyright 1998-2008 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
; };
21 ($table_name, $pad) = @ARGV;
23 if ( !defined($table_name) ) {
24 print STDERR
"Usage: $0 table_name [pad] < input_file > output_file\n";
28 $pad = 1 if ($pad < 1);
30 printf "unsigned char %s[] = {\n", $table_name;
37 while ( ($n = read(STDIN
, $data, 4096)) > 0 ) {
39 for ( $i = 0 ; $i < $n ; $i++ ) {
40 $byte = substr($data, $i, 1);
41 if ( $pos >= $linelen ) {
44 } elsif ( $pos > 0 ) {
49 printf("0x%02x", unpack("C", $byte));
54 $align = $total_len % $pad;
58 for ( $i = 0 ; $i < $n ; $i++ ) {
59 if ( $pos >= $linelen ) {
62 } elsif ( $pos > 0 ) {
72 printf "\n};\n\nconst unsigned int %s_len = %u;\n", $table_name, $total_len;
76 printf "\nconst int %s_mtime = %d;\n", $table_name, $st[9];