fysxasteroids/engine/libraries/oglft/tests/tosrc.pl

31 lines
843 B
Perl

#!/usr/bin/perl
use strict;
# Convert the file given on the commandline into something which
# can be compiled with C and linked into an executable.
# Use the generated object module with the following declarations:
# extern unsigned char ${ARGV[0]}[]; /* Array of data */
# extern int ${ARGV[0]}_size; /* Size of array */
# Note, .'s in the argument filename are converted to _'s
open FILE, $ARGV[0] or die "usage: $0 file";
# "Slurp the whole file"
undef $/;
my $contents = <FILE>;
# Replace .'s in the filename with _'s (since . is an operator in C)
my $label = $ARGV[0];
$label =~ s/\./_/;
print "FT_Byte $label\[\] = {\n";
for ( my $i = 0; $i < length $contents; $i += 16 ) {
print join( ",", unpack( "C*", substr( $contents, $i, 16 ) ) ), ",\n";
}
print "};\n";
print "const int ${label}_size = sizeof( $label );\n";