summaryrefslogtreecommitdiff
path: root/cesar/ce/rx/bitloading/test/src/data2c.pl
blob: 2a720a4c0bf5e18283222a293bed11b46ce330e8 (plain)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/perl
# Usage: data2c.pl <table_name> < data_file
use Getopt::Std;
my $name = shift @ARGV;

getopts("fdum:l");

my $col;
my $line = 0;
# Type.
my $type = "u32";
# Special characters after data.
my $post = "";
my $max_carrier = 1155;
if (defined ($opt_m))
{
   $max_carrier = $opt_m;
}

while (<>)
{
    if (not defined ($opt_f) or 75..$.==75+$max_carrier-1)
    {
        # Remove carriage return.
        chomp;
        # Remove space at end of line.
        s/\s+$//;
        # Compute coloms count only the first time.
        if (not defined ($col))
        {
            # Count tabulation.
            $col = 1 + y/\t/\t/;
            # Type.
            my $type = "u32";
            if (defined ($opt_d))
            {
                $type = "s64";
            }
            if (defined ($opt_u))
            {
                $type = "u64";
                $post = "ull";
            }
            if (defined ($opt_l))
            {
                $type = "s64";
                $post = "ll";
            }
            print <<EOF;
/* Autogenerated file, do not edit. */
static const u8 ${name}_width = $col;
static $type ${name}[][$col] = {
EOF
        }
        # Replace unsupported value by 0.
        s/\d\.\d{6}e\+\d{2,3}/0/g;
        # Replace tabulation by comma (between two values).
        s/\t/${post}, /g;
        # Print line.
        print "    { ${_}$post },\n";
        $line++;
    }
}
# Close table.
print <<EOF;
};
static const u32 ${name}_height = $line;
EOF