Rev 8793 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
8687 | turbocat | 1 | // export_table_gen |
2 | // Copyright (C) maxcodehack and turbocat2001, 2021 |
||
3 | |||
4 | #include |
||
5 | #include |
||
6 | |||
7 | int main(int argc, char** argv) { |
||
8 | if (argc != 3) { |
||
9 | printf("Usage: %s |
||
10 | return 0; |
||
11 | } |
||
12 | FILE *input, *output; |
||
13 | if ((input = fopen(argv[1], "r")) == NULL) |
||
14 | { |
||
15 | printf("error: file \"%s\" not found\n", argv[1]); |
||
16 | return 1; |
||
17 | } |
||
18 | char buf[10000]; |
||
19 | // Head |
||
20 | strcpy(buf, \ |
||
21 | "#include |
||
22 | "#include |
||
23 | "#include |
||
24 | "#include |
||
25 | "#include |
||
26 | "#include |
||
27 | "#include |
||
28 | "#include |
||
9094 | turbocat | 29 | "ksys_dll_t EXPORTS[] = {\n"); |
8687 | turbocat | 30 | |
31 | // Generate |
||
32 | char symbol[256]; |
||
33 | while(fscanf(input, "%s", symbol) != EOF) { |
||
34 | if(symbol[0]!='!'){ |
||
35 | char temp[256]; |
||
36 | sprintf(temp, "{\"%s\", &%s},\n", symbol, symbol); |
||
37 | strcat(buf, temp); |
||
38 | } |
||
39 | } |
||
40 | strcat(buf, "NULL,\n};"); |
||
41 | fclose(input); |
||
42 | |||
43 | // Output generated |
||
44 | output = fopen(argv[2], "w"); |
||
45 | if (output == NULL) |
||
46 | { |
||
47 | printf("Unable to write to file: '%s'!\n", argv[2]); |
||
48 | return 1; |
||
49 | } |
||
50 | |||
51 | fputs(buf, output); |
||
52 | fclose(output); |
||
53 | |||
54 | printf("Done, check %s!\n", argv[2]); |
||
55 | |||
56 | return 0; |
||
57 | } |