root/libinstaller/bin2c.pl

Revision 0fa4369624b4637a7e36ed22e89a759031f08327, 1.7 KB (checked in by H. Peter Anvin <hpa@…>, 3 years ago)

FAT: change DOS installer to EXE; additional 32K limit fixes

Additional fixes for the 32K limits in the installers. In the case
of the DOS installer, that means changing it from COM format to EXE
format (since COM format has a 63K hard limit); retain the name
syslinux.com for user compatibility, though (DOS doesn't care what the
extension except for pathname search; if it finds an MZ EXE header it
will use it.)

With the change to EXE means having to handle more than one segment.
Since we don't have a real DOS compiler we have to wing it a bit.

Signed-off-by: H. Peter Anvin <hpa@…>

  • Property mode set to 100755
Line 
1#!/usr/bin/perl
2## -----------------------------------------------------------------------
3##
4##   Copyright 1998-2008 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.
11##
12## -----------------------------------------------------------------------
13
14#
15# bin2c.pl: binary file to C source converter
16#
17
18eval { use bytes; };
19eval { binmode STDIN; };
20
21($table_name, $pad) = @ARGV;
22
23if ( !defined($table_name) ) {
24    print STDERR "Usage: $0 table_name [pad] < input_file > output_file\n";
25    exit 1;
26}
27
28$pad = 1 if ($pad < 1);
29
30printf "unsigned char %s[] = {\n", $table_name;
31
32$pos = 0;
33$linelen = 8;
34
35$total_len = 0;
36
37while ( ($n = read(STDIN, $data, 4096)) > 0 ) {
38    $total_len += $n;
39    for ( $i = 0 ; $i < $n ; $i++ ) {
40        $byte = substr($data, $i, 1);
41        if ( $pos >= $linelen ) {
42            print ",\n\t";
43            $pos = 0;
44        } elsif ( $pos > 0 ) {
45            print ", ";
46        } else {
47            print "\t";
48        }
49        printf("0x%02x", unpack("C", $byte));
50        $pos++;
51    }
52}
53
54$align = $total_len % $pad;
55if ($align != 0) {
56    $n = $pad - $align;
57    $total_len += $n;
58    for ( $i = 0 ; $i < $n ; $i++ ) {
59        if ( $pos >= $linelen ) {
60            print ",\n\t";
61            $pos = 0;
62        } elsif ( $pos > 0 ) {
63            print ", ";
64        } else {
65            print "\t";
66        }
67        print '0x00';
68        $pos++;
69    }
70}
71
72printf "\n};\n\nconst unsigned int %s_len = %u;\n", $table_name, $total_len;
73
74@st = stat STDIN;
75
76printf "\nconst int %s_mtime = %d;\n", $table_name, $st[9];
77
78exit 0;
Note: See TracBrowser for help on using the browser.