(file) Return to chexify.pl CVS log (file) (dir) Up to [RizwankCVS] / group3 / wine / tools

Diff for /group3/wine/tools/chexify.pl between version 1.2 and 1.5

version 1.2, 2005/02/25 08:00:17 version 1.5, 2005/02/26 02:10:50
Line 1 
Line 1 
 #!/usr/bin/perl #!/usr/bin/perl
 # hexify.pl  # chexify.pl
 # Takes a list of filenames on stdin and create a C data array for each one. # Takes a list of filenames on stdin and create a C data array for each one.
 # Copyright Dan Kegel, Rizwan Kassim 2005 # Copyright Dan Kegel, Rizwan Kassim 2005
 # Licensed under LGPL # Licensed under LGPL
  
 # no input record separator  
 undef $/;  use English;
   use strict;
   
   
   my $file;       #each of the files we are working on
   my $varname;    #file name converted to variable name
   my $buffer;     #buffer to store the hexified contents of a file till output
   my $readcount;   #number of chars actually read
   
   
   # no input record separator to just slurp everything
   undef $INPUT_RECORD_SEPARATOR;
  
 foreach $file (@ARGV) { foreach $file (@ARGV) {
        open FILE, $file || die;         open(FILE, $file) or die("Can't open $file : $OS_ERROR");
        binmode FILE;        binmode FILE;
  
        # munge filename into C variable name        # munge filename into C variable name
        $varname = $file;        $varname = $file;
        $varname =~ s/\./_/;        $varname =~ s/\./_/;
  
              #name of the file
        print "const static char name_$varname"."[] = \"$file\";\n";        print "const static char name_$varname"."[] = \"$file\";\n";
          #hex contents of the file
              #BUG:have to get rid of the last comma
        print "const static char file_$varname"."[] = {\n";        print "const static char file_$varname"."[] = {\n";
        while (read(FILE, $buffer, 16)) {  
   
   
          while ( $readcount=read(FILE, $buffer, 16) ) {
   
                              die("Read error in $file:$OS_ERROR") unless defined($readcount);
                $buffer =~ s/(.|\n)/'0x' . unpack('H2', $1).', '/ge;                $buffer =~ s/(.|\n)/'0x' . unpack('H2', $1).', '/ge;
                              $buffer =~ s/(, )$//g if($readcount < 16);
                print "\t$buffer\n";                print "\t$buffer\n";
   
        }        }
        print "const static int size_$varname"." = sizeof(file_$varname);\n";         print "};\n";
        close FILE;        close FILE;
              #size of the file
        print "};\n\n";         print "const static int size_$varname"." = sizeof(file_$varname);\n\n";
 } }


Legend:
Removed from v.1.2  
changed lines
  Added in v.1.5

Rizwan Kassim
Powered by
ViewCVS 0.9.2