Debian Codegraph @

code/tools/stringify.c

raw symbols SCIP
1 #include <stdio.h>
2 #include <ctype.h>
3 #include <string.h>
4 #include <libgen.h>
5
6 int main(int argc, char **argv)
7 {
8 FILE *ifp;
9 FILE *ofp;
10 char buffer[1024];
11
12 if(argc < 3)
13 return 1;
14
15 char *inFile = argv[1];
16 char *outFile = argv[2];
17
18 ifp = fopen(inFile, "r");
19 if(!ifp)
20 return 2;
21
22 ofp = fopen(outFile, "w");
23 if(!ofp)
24 return 3;
25
26 // Strip extension
27 char *base = basename(inFile);
28 *strrchr(base, '.') = '\0';
29
30 fprintf(ofp, "const char *fallbackShader_%s =\n", base);
31
32 while(fgets(buffer, sizeof(buffer), ifp))
33 {
34 // Strip trailing whitespace from line
35 char *end = buffer + strlen(buffer) - 1;
36 while(end >= buffer && isspace(*end))
37 end--;
38
39 end[1] = '\0';
40
41 // Write line enquoted, with a newline
42 fprintf(ofp, "\"%s\\n\"\n", buffer);
43 }
44
45 fprintf(ofp, ";\n");
46
47 fclose(ifp);
48 fclose(ofp);
49
50 return 0;
51 }