#!/usr/bin/perl -w if ($#ARGV != 1) { print "so2h.pl \n"; exit 1; } my $success; my $number_read; my $buffer; my $is_compressed = 0; my $compressedname = $ARGV[0]; my $uncompressedsize; my $compressedsize; $success = open INPUT, "file -bi $ARGV[0]|"; unless ($success) { die "failed to open input from file \n"; exit 1; } $number_read = read(INPUT, $buffer, 32); if ($buffer =~ "application/x-gzip") { $is_compressed = 1; # # determine file size # my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat($ARGV[0]); $compressedsize = $size; # # figure out how big the file is uncompressed # my @pathlist = split('/', $ARGV[0]); my $filename = $pathlist[$#pathlist]; $uncompressedname = "/tmp/$filename"; system("gunzip -c $ARGV[0] > $uncompressedname"); ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat($uncompressedname); $uncompressedsize = $size; unlink($uncompressedname); } else { # # how big is original uncompressed file? # my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat($ARGV[0]); $uncompressedsize = $size; # # compress file and determine its size # my @pathlist = split('/', $ARGV[0]); my $filename = $pathlist[$#pathlist]; $compressedname = "/tmp/$filename.gz"; system("gzip -nfc $ARGV[0] > $compressedname"); ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat($compressedname); $compressedsize = $size; } close INPUT; $success = open INPUT, "$compressedname"; unless ($success) { die "failed to open input file $compressedname\n"; exit 1; } $success = open OUTPUT, ">$ARGV[1].h"; unless ($success) { print "failed to open output\n"; exit 1; } my $license = < 0) { print OUTPUT "\t"; $neednewline = 1; } for (; $i < $compressedsize; $i += 1) { $number_read = read(INPUT, $binary, 1); my $a = unpack("C", $binary); $buf = sprintf("U 0x%02X, ", $a); print OUTPUT $buf; } if ($neednewline) { print OUTPUT "\n"; } print OUTPUT "};\n"; # unlink temporary compressed file if ($is_compressed == 0) { unlink($compressedname); }