1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#! /usr/bin/perl -w
use strict;
my $input;
my $header;
my $comment;
@ARGV == 2 or die "Usage: $0 <infile> <outfile>\n";
$input = $ARGV[0];
$header = $ARGV[1];
open(IF, "$input") or die "Failed to write '$input': $!\n";
open(HF, ">$header") or die "Failed to write '$header': $!\n";
while(<IF>) {
chomp;
undef $comment;
s/\r//; # CRLF -> LF
if(s/\s*[;#]\s*(.*?)$//) { # Comments
$comment = $1;
}
if(/^\s*$/) { # Empty lines
next;
}
my ($slic0, $slic1, $slic2, $slic3, $len, @data) = split;
die "Bad input (len=$len)" if hex($len) != @data;
my $slic = "$slic3$slic2$slic1$slic0";
die "Bad slic address '$slic'" if length($slic) != 8;
grep(s/\w+/0x$&/g, ($slic, $len, @data));
my $str = join(", ", @data);
print HF "S_($slic,\t$len,\t$str),\t";
} continue {
if(defined($comment)) {
print HF "// $comment";
}
print HF "\n";
}
|