|
diff --git a/Makefile b/Makefile
|
|
|
1 |
CC ?= tcc |
| 1 |
RAYLIB := raylib-5.5_linux_amd64 |
2 |
RAYLIB := raylib-5.5_linux_amd64 |
| 2 |
LUA := lua-5.4.8 |
3 |
LUA := lua-5.4.8 |
| 3 |
|
|
|
| 4 |
CC ?= tcc |
|
|
| 5 |
CFLAGS := -std=c99 -v -g -I./vendor/$(RAYLIB)/include -I./vendor/$(LUA)/src |
4 |
CFLAGS := -std=c99 -v -g -I./vendor/$(RAYLIB)/include -I./vendor/$(LUA)/src |
| 6 |
LDFLAGS := -L./vendor/$(RAYLIB)/lib -lraylib -L./vendor/$(LUA)/src -llua -lm |
5 |
LDFLAGS := -L./vendor/$(RAYLIB)/lib -lraylib -L./vendor/$(LUA)/src -llua -lm |
| 7 |
PROG := bidi |
6 |
PROG := bidi |
|
|
7 |
PROG_C := main.c |
| 8 |
|
8 |
|
| 9 |
$(PROG): lua *.c |
9 |
$(PROG): lua hexdump $(PROG_C) |
| 10 |
$(CC) $(CFLAGS) *.c -o $(PROG) $(LDFLAGS) |
10 |
$(CC) $(CFLAGS) $(PROG_C) -o $(PROG) $(LDFLAGS) |
|
|
11 |
|
|
|
12 |
hexdump: hexdump.c |
|
|
13 |
$(CC) -std=c99 -o hexdump hexdump.c |
| 11 |
|
14 |
|
| 12 |
lua: |
15 |
lua: |
| 13 |
cd vendor/$(LUA) && make |
16 |
cd vendor/$(LUA) && make |
|
diff --git a/hexdump.c b/hexdump.c
|
|
|
1 |
#include <stdio.h> |
|
|
2 |
#include <stdlib.h> |
|
|
3 |
|
|
|
4 |
int main(int argc, char *argv[]) { |
|
|
5 |
if (argc < 3) { |
|
|
6 |
fprintf(stderr, "Usage: %s <input_file> <array_name>\n", argv[0]); |
|
|
7 |
return 1; |
|
|
8 |
} |
|
|
9 |
|
|
|
10 |
const char *filename = argv[1]; |
|
|
11 |
const char *array_name = argv[2]; |
|
|
12 |
|
|
|
13 |
FILE *f = fopen(filename, "rb"); |
|
|
14 |
if (!f) { |
|
|
15 |
perror("fopen"); |
|
|
16 |
return 1; |
|
|
17 |
} |
|
|
18 |
|
|
|
19 |
fseek(f, 0, SEEK_END); |
|
|
20 |
long size = ftell(f); |
|
|
21 |
rewind(f); |
|
|
22 |
|
|
|
23 |
unsigned char *buffer = malloc(size); |
|
|
24 |
if (!buffer) { |
|
|
25 |
perror("malloc"); |
|
|
26 |
fclose(f); |
|
|
27 |
return 1; |
|
|
28 |
} |
|
|
29 |
|
|
|
30 |
if (fread(buffer, 1, size, f) != (size_t)size) { |
|
|
31 |
perror("fread"); |
|
|
32 |
free(buffer); |
|
|
33 |
fclose(f); |
|
|
34 |
return 1; |
|
|
35 |
} |
|
|
36 |
|
|
|
37 |
// Generate include guard |
|
|
38 |
printf("#ifndef %s_H\n", array_name); |
|
|
39 |
printf("#define %s_H\n\n", array_name); |
|
|
40 |
|
|
|
41 |
printf("unsigned char %s[] = {\n", array_name); |
|
|
42 |
for (long i = 0; i < size; i++) { |
|
|
43 |
if (i % 12 == 0) printf("\t"); |
|
|
44 |
printf("0x%02x", buffer[i]); |
|
|
45 |
if (i != size - 1) printf(", "); |
|
|
46 |
if ((i + 1) % 12 == 0) printf("\n"); |
|
|
47 |
} |
|
|
48 |
if (size % 12 != 0) printf("\n"); |
|
|
49 |
printf("};\n"); |
|
|
50 |
printf("unsigned int %s_len = %ld;\n", array_name, size); |
|
|
51 |
|
|
|
52 |
printf("\n#endif // %s_H\n", array_name); |
|
|
53 |
|
|
|
54 |
free(buffer); |
|
|
55 |
fclose(f); |
|
|
56 |
return 0; |
|
|
57 |
} |