File: bin2data.pl

package info (click to toggle)
vmelilo 1.5.2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 432 kB
  • ctags: 919
  • sloc: ansic: 8,210; makefile: 157; asm: 122; perl: 18
file content (22 lines) | stat: -rwxr-xr-x 415 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#! /usr/bin/perl

if (@ARGV != 2) {
	print "Usage : <source file> <label>\n";
	exit;
}

open (FILE, $ARGV[0]) || die "can't open source file \"$ARGV[0]\"";

print "unsigned char $ARGV[1]\[] = {";
$lines = 0;
while (read(FILE, $data, 16)) {
	@bytes = unpack "C*", $data;
	print "," if $lines++;
	print "\n\t";
	$i = 1; 
	foreach (@bytes) {
		printf "0x%02x", $_;
		print "," if ($i++ < @bytes);
	}
}
print "\n};\n";