#!/usr/local/bin/perl

# Script: bin2pl.pl
# Author: David Bennett
# Version: 1.0
# Date: 11-9-00
# Description: Convert a binary file to a perl array.
# Usage:  bin2pl.pl {binary file}
#
# Example: bin2pl.pl clearpixel.gif
#
# Output:
#
# $VAR=[
#   0x47,0x49,0x46,0x38,0x39,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,
#   0xFF,0xFF,0xFF,0x00,0x00,0x00,0x21,0xF9,0x04,0x01,0x01,0x00,0x00,
#   0x00,0x2C,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,
#   0x44,0x01,0x00,0x3B
# ];
#

undef($/);
open BINARY,"<$ARGV[0]";
my $bin=<BINARY>;
close BINARY;
print "\$VAR=[\n  ";
my $j;
my $len=length($bin);
for (my $i=0; $i<$len; $i++) {
  printf("0x%02X%s",ord(substr($bin,$i,1)),$i<$len-1 ? ',' : '');
  if (++$j > 12) {
    print "\n  ";
    $j = 0;
  }
}
printf("%s%s",$j==0?'':"\n","];\n");
