aboutsummaryrefslogtreecommitdiffstats
path: root/bin2c.pl
diff options
context:
space:
mode:
Diffstat (limited to 'bin2c.pl')
-rw-r--r--bin2c.pl26
1 files changed, 23 insertions, 3 deletions
diff --git a/bin2c.pl b/bin2c.pl
index 5ef1c034..2bd95d59 100644
--- a/bin2c.pl
+++ b/bin2c.pl
@@ -18,12 +18,14 @@
eval { use bytes; };
eval { binmode STDIN; };
-if ( $#ARGV != 0 ) {
- print STDERR "Usage: $0 table_name < input_file > output_file\n";
+($table_name, $pad) = @ARGV;
+
+if ( !defined($table_name) ) {
+ print STDERR "Usage: $0 table_name [pad] < input_file > output_file\n";
exit 1;
}
-($table_name) = @ARGV;
+$pad = 1 if ($pad < 1);
printf "unsigned char %s[] = {\n", $table_name;
@@ -49,6 +51,24 @@ while ( ($n = read(STDIN, $data, 4096)) > 0 ) {
}
}
+$align = $total_len % $pad;
+if ($align != 0) {
+ $n = $pad - $align;
+ $total_len += $n;
+ for ( $i = 0 ; $i < $n ; $i++ ) {
+ if ( $pos >= $linelen ) {
+ print ",\n\t";
+ $pos = 0;
+ } elsif ( $pos > 0 ) {
+ print ", ";
+ } else {
+ print "\t";
+ }
+ print '0x00';
+ $pos++;
+ }
+}
+
printf "\n};\n\nunsigned int %s_len = %u;\n", $table_name, $total_len;
@st = stat STDIN;