aboutsummaryrefslogtreecommitdiff
path: root/src/util/makeblob.c
blob: 15af99f6a8c35062d30a490531fa05be81b464b8 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* $Header$ */

#include <assert.h>
#include <stdio.h>

int
main (int argc, char * * argv)
{
  char const * arrangement;
  char const * thorn;
  char const * output;
#if 0
  char filename [10000];
#endif
  FILE * file;
  int fcount;
  int done;
  unsigned long count;
  unsigned long const items_per_line = 16;
  unsigned long const items_per_file = 1024 * 1024;
  
  assert (argc == 4);
  arrangement = argv[1];
  assert (arrangement);
  thorn = argv[2];
  assert (thorn);
  output = argv[3];
  assert (output);
  
#if 0
  snprintf (filename, sizeof filename, "%s.c", output);
  file = fopen (filename, "w");
  assert (file);
#endif
  file = stdout;
  
  fprintf (file, "/* This is an auto-generated file -- do not edit */\n");
  fprintf (file, "\n");
  fprintf (file, "#include <stddef.h>\n");
  fprintf (file, "\n");
  fprintf (file, "struct datainfo\n");
  fprintf (file, "{\n");
  fprintf (file, "  unsigned char const * data;\n");
  fprintf (file, "  size_t length;\n");
  fprintf (file, "  struct datainfo const * next;\n");
  fprintf (file, "};\n");
  fprintf (file, "\n");
  fprintf (file, "struct sourceinfo\n");
  fprintf (file, "{\n");
  fprintf (file, "  struct datainfo const * first;\n");
  fprintf (file, "  char const * arrangement;\n");
  fprintf (file, "  char const * thorn;\n");
  fprintf (file, "};\n");
  
  fprintf (file, "\n");
  fprintf (file, "struct datainfo const cactus_data_%04d_%s;\n", 0, thorn);
  fprintf (file, "struct sourceinfo const cactus_source_%s =\n", thorn);
  fprintf (file, "{\n");
  fprintf (file, "  & cactus_data_%04d_%s,\n", 0, thorn);
  fprintf (file, "  \"%s\",\n", arrangement);
  fprintf (file, "  \"%s\"\n", thorn);
  fprintf (file, "};\n");
  
  for (fcount = 0, done = 0; ! done; ++ fcount)
  {
#if 0
    snprintf (filename, sizeof filename, "%s-%04d.c", output, fcount);
    file = fopen (filename, "w");
    assert (file);
    
    fprintf (file, "/* This is an auto-generated file -- do not edit */\n");
    fprintf (file, "\n");
    fprintf (file, "#include <stddef.h>\n");
    fprintf (file, "\n");
    fprintf (file, "struct datainfo\n");
    fprintf (file, "{\n");
    fprintf (file, "  unsigned char const * data;\n");
    fprintf (file, "  size_t length;\n");
    fprintf (file, "  struct datainfo const * next;\n");
    fprintf (file, "};\n");
    fprintf (file, "\n");
    fprintf (file, "struct sourceinfo\n");
    fprintf (file, "{\n");
    fprintf (file, "  struct datainfo const * first;\n");
    fprintf (file, "  char const * arrangement;\n");
    fprintf (file, "  char const * thorn;\n");
    fprintf (file, "};\n");
#endif
    
    fprintf (file, "\n");
    fprintf (file, "static unsigned char const data_%04d [] = {", fcount);
    for (count = 0; count < items_per_file; ++ count)
    {
      int const ch = getc (stdin);
      if (feof (stdin))
      {
        done = 1;
        break;
      }
      if (ferror (stdin)) return 1;
      if (count != 0)
      {
        fprintf (file, ",");
      }
      if (count % items_per_line == 0)
      {
        fprintf (file, "\n");
      }
      fprintf (file, "%3d", ch);
    }
    fprintf (file, "\n");
    fprintf (file, "};\n");
    fprintf (file, "\n");
    if (! done)
    {
      fprintf (file, "struct datainfo const cactus_data_%04d_%s;\n",
               fcount + 1, thorn);
    }
    fprintf (file, "struct datainfo const cactus_data_%04d_%s =\n",
             fcount, thorn);
    fprintf (file, "{\n");
    fprintf (file, "  data_%04d,\n", fcount);
    fprintf (file, "  %luUL,\n", count);
    if (! done)
    {
      fprintf (file, "  & cactus_data_%04d_%s\n", fcount + 1, thorn);
    }
    else
    {
      fprintf (file, "  NULL\n");
    }
    fprintf (file, "};\n");
    
#if 0
    fclose (file);
#endif
  }
  
#if 0
  fclose (file);
#endif
  
  return 0;
}