Adding debian version 3.20-2.
[syslinux-debian/hramrach.git] / bin2c.pl
blob5ef1c0346eae3bbf6b16d07407ab62322e196c1e
1 #!/usr/bin/perl
2 ## -----------------------------------------------------------------------
3 ##
4 ## Copyright 1998-2004 H. Peter Anvin - All Rights Reserved
5 ##
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
18 eval { use bytes; };
19 eval { binmode STDIN; };
21 if ( $#ARGV != 0 ) {
22 print STDERR "Usage: $0 table_name < input_file > output_file\n";
23 exit 1;
26 ($table_name) = @ARGV;
28 printf "unsigned char %s[] = {\n", $table_name;
30 $pos = 0;
31 $linelen = 8;
33 $total_len = 0;
35 while ( ($n = read(STDIN, $data, 4096)) > 0 ) {
36 $total_len += $n;
37 for ( $i = 0 ; $i < $n ; $i++ ) {
38 $byte = substr($data, $i, 1);
39 if ( $pos >= $linelen ) {
40 print ",\n\t";
41 $pos = 0;
42 } elsif ( $pos > 0 ) {
43 print ", ";
44 } else {
45 print "\t";
47 printf("0x%02x", unpack("C", $byte));
48 $pos++;
52 printf "\n};\n\nunsigned int %s_len = %u;\n", $table_name, $total_len;
54 @st = stat STDIN;
56 printf "\nint %s_mtime = %d;\n", $table_name, $st[9];
58 exit 0;