#!/usr/bin/perl

## embedded code creator for c
# (c) 2012 F00L.DE 
# by raudi <raudi.s at web dot de>

## check for arguments
# 1 - FILENAME
if (!defined $ARGV[0]) {
  print "Usage: $0 <filename>\n";
  exit(1);
}

## init vars
$filename = $ARGV[0];
$count = 0;
$byte;


## begin code declaration
$output = "char code[] = \"";

## turn all bytes to hex
open(FILE, "<".$filename);
binmode(FILE);
while (read (FILE, $byte, 1) != 0) {
	if ($count == 8) {
		$output .= "\"\n\"";
		$count = 0;
	}
	$output .= sprintf("\\x%02X", ord($byte));
	$count++;
}

## end code declaration
$output .= "\";\n";
print $output;

