3 # From a binary image containing a user program, generate
4 # C code initializing a User_Program struct.
8 use strict qw(refs vars);
11 if ( scalar(@ARGV) != 3 ) {
12 print STDERR "usage: mkuprog <filename> <progname> <entry addr>\n";
16 my $filename = shift @ARGV;
17 my $progname = shift @ARGV;
18 my $entryAddr = shift @ARGV;
20 my $fh = new FileHandle("<$filename");
21 (defined $fh) || die "Couldn't open $filename: $!\n";
24 my $dataArrayName = $progname . "Data";
25 my $structName = $progname . "Prog";
26 print "const unsigned char $dataArrayName"."[] = {\n";
30 my $buf = chr(0) x $LINEWIDTH;
33 while ( ($n = read( $fh, $buf, $LINEWIDTH )) > 0 ) {
37 for ( $i = 0; $i < $n; $i++ ) {
38 my $c = ord( substr($buf, $i, 1) );
39 printf( "0x%x,", $c );
49 const struct User_Program $structName = {