2023-11-30 15:07:20 +00:00
|
|
|
#define STACK_ALLOC_SIZE (128*1024*1024)
|
2023-11-30 13:33:49 +00:00
|
|
|
#include "v4k.c"
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
if (argc != 2) {
|
|
|
|
fprintf(stderr, "usage: %s [file]\n", argv[0]);
|
|
|
|
fprintf(stderr, "file: %s\n", "source file to process");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *buf = file_read(argv[1]);
|
|
|
|
if (!buf) {
|
|
|
|
fprintf(stderr, "error: %s\n", "file does not exist!");
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
file_delete(argv[1]);
|
|
|
|
|
|
|
|
// determine swap mode
|
|
|
|
char mode = strstri(buf, "//@#line 1 \"") == NULL;
|
|
|
|
char **lines = strsplit(buf, "\n");
|
|
|
|
|
2023-11-30 15:07:20 +00:00
|
|
|
printf("Switching #line %s\n", mode?"ON":"OFF");
|
|
|
|
|
2023-11-30 13:33:49 +00:00
|
|
|
for (int i = 0; i < array_count(lines); i++) {
|
2023-11-30 15:07:20 +00:00
|
|
|
char *line = STRDUP(lines[i]); //@leak
|
2023-11-30 13:33:49 +00:00
|
|
|
if (!mode) {
|
|
|
|
strrepl(&line, "//@#line 1 \"", "#line 1 \"");
|
|
|
|
} else {
|
|
|
|
strrepl(&line, "#line 1 \"", "//@#line 1 \"");
|
|
|
|
}
|
|
|
|
|
2023-11-30 15:07:20 +00:00
|
|
|
file_append(argv[1], va("%s\n", line), strlen(line)+1);
|
2023-11-30 13:33:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|