aboutsummaryrefslogtreecommitdiff
path: root/src/util/makeblob.pl
blob: 14fd49c4fc4a64025209fb18fab73d57e6f9bbcc (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#! /usr/bin/perl -w

use strict;

my $items_per_line = 16;
my $items_per_file = 128 * 1024;

$#ARGV == 1 or die;

my $arrangement = $ARGV[0];
my $thorn = $ARGV[1];
$thorn ne '' or die;

print <<EOF;
/* This is an auto-generated file -- do not edit */

\#include <stddef.h>

struct datainfo
{
  unsigned char const * data;
  size_t length;
  struct datainfo const * next;
};

struct sourceinfo
{
  struct datainfo const * first;
  char const * arrangement;
  char const * thorn;
};

struct datainfo const cactus_data_0000_$thorn;
struct sourceinfo const cactus_source_$thorn =
{
  & cactus_data_0000_$thorn,
  \"$arrangement\",
  \"$thorn\"
};
EOF

my $done = 0;
for (my $fcount = 0; ! $done; ++ $fcount)
{
    printf "\n";
    printf "static unsigned char const data_%04d [] = {", $fcount;
    my $count;
    for ($count = 0; $count < $items_per_file; ++ $count)
    {
        my $ch = getc;
        if (! defined $ch)
        {
            $done = 1;
            last;
        }
        if ($count != 0)
        {
            printf ",";
        }
        if ($count % $items_per_line == 0)
        {
            printf "\n";
            printf "  ";
        }
        printf "%3d", ord $ch;
    }
    printf "\n";
    printf "};\n";
    printf "\n";
    if (! $done)
    {
        printf "struct datainfo const cactus_data_%04d_%s;\n", $fcount + 1, $thorn;
    }
    printf "struct datainfo const cactus_data_%04d_%s =\n", $fcount, $thorn;
    printf "{\n";
    printf "  data_%04d,\n", $fcount;
    printf "  %dUL,\n", $count;
    if (! $done)
    {
        printf "  & cactus_data_%04d_%s\n", $fcount + 1, $thorn;
    }
    else
    {
        printf "  NULL\n";
    }
    printf "};\n";
}