forked from pikhq/cmako
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen-system.c
37 lines (35 loc) · 862 Bytes
/
gen-system.c
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
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
printf("#include <stdint.h>\n"
"#include <SDL.h>\n"
"#include \"mako-vm.h\"\n"
"#ifndef NAME\n"
"#define NAME \"\"\n"
"#endif\n"
"char *argv0;\n"
"int32_t mem[] = {");
while(!feof(stdin)) {
uint8_t buf[4];
int n = fread(buf, sizeof *buf, 4, stdin);
if(ferror(stdin)) goto onerr;
if(n == 0) break;
if(n != 4) {
fprintf(stderr, "%s: The file was invalid.\n", argv[0]);
exit(1);
}
printf("0x%04X,", (int32_t)buf[0] << 24 | (int32_t)buf[1] << 16 | (int32_t)buf[2] << 8 | (int32_t)buf[3]);
}
printf("0};\n"
"int main(int argc, char **argv)\n"
"{\n"
"\targv0 = argv[0];\n"
"\trun_vm(mem, NAME);\n"
"}\n");
exit(0);
onerr:
perror(argv[0]);
exit(1);
}