forked from misc0110/pdf-webslides
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resconv.c
45 lines (41 loc) · 1.04 KB
/
resconv.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
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
char* replace_name(char* in) {
char* out = strdup(in);
for(int i = 0; i < strlen(out); i++) {
if(out[i] == '/' || out[i] == '.') out[i] = '_';
}
return out;
}
int main(int argc, char* argv[]) {
if(argc != 2) {
printf("Usage: %s <file>\n", argv[0]);
return 1;
}
FILE* f = fopen(argv[1], "rb");
if(!f) {
printf("Could not open file %s\n", argv[1]);
return 1;
}
fseek(f, 0, SEEK_END);
size_t len = ftell(f);
fseek(f, 0, SEEK_SET);
char* data = malloc(len + 1);
fread(data, len, 1, f);
fclose(f);
char* name = replace_name(argv[1]);
printf("unsigned char %s[] = {", name);
for(int i = 0; i < (int)len; i++) {
printf("0x%02x", (unsigned char)(data[i]));
if(i < (int)len - 1) {
printf(", ");
}
}
printf(", 0};\nunsigned int %s_len = %d;\n", name, (int)len);
fflush(stdout);
free(name);
free(data);
return 0;
}