diff options
Diffstat (limited to 'src/precedent.c')
| -rw-r--r-- | src/precedent.c | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/src/precedent.c b/src/precedent.c index 81555b9..8be2ad3 100644 --- a/src/precedent.c +++ b/src/precedent.c @@ -39,7 +39,11 @@ int main(int argc, char** argv) { char* baseDir = malloc((strlen(dirName) + 2) * sizeof(char)); strcpy(baseDir, dirName); strcat(baseDir, "/"); - sym_t* finalSymbol = parse_symbol_final(read_file(path)); + char* finalContent = preprocess(read_file(path), baseDir); + sym_t* finalSymbol = parse_symbol_final(finalContent); + free(pathCpy); + free(baseDir); + free(finalContent); if (visual) { printf("--BEGIN VISUALIZATION--\n"); write_symbol_visual(finalSymbol, 0); @@ -47,13 +51,13 @@ int main(int argc, char** argv) { } init_eval(); eval(finalSymbol); - free(dirName); - free(pathCpy); - free(baseDir); return 0; } char* read_file(char* path) { FILE* file = fopen(path, "r"); + if (file == NULL) { + printf("file %s does not exist\n", path); + } fseek(file, 0, SEEK_END); unsigned long int length = ftell(file); fseek(file, 0, SEEK_SET); @@ -63,18 +67,16 @@ char* read_file(char* path) { out[length] = '\0'; return out; } -/* wtf */ char* preprocess(char* str, char* baseDir) { - char* final = str; while (1) { int i = 0; while (str[i] != '@') { i++; if (str[i] == '\0') { - printf("%s\n", final); - return final; + return str; } } + str[i] = ' '; i++; char* includeName = malloc(20 * sizeof(char)); int f = 0; @@ -84,21 +86,17 @@ char* preprocess(char* str, char* baseDir) { i++; f++; } - final = str; includeName[f] = '\0'; char* path = malloc((strlen(baseDir) + strlen(includeName) + 1) * sizeof(char)); strcpy(path, baseDir); strcat(path, includeName); char* toInclude = preprocess(read_file(path), baseDir); - char* newStr = malloc((strlen(toInclude) + strlen(final) + 1) * sizeof(char)); + char* newStr = malloc((strlen(toInclude) + strlen(str) + 1) * sizeof(char)); strcpy(newStr, toInclude); - strcat(newStr, final); - /* + strcat(newStr, str); + str = newStr; free(includeName); free(path); - free(str); free(toInclude); - */ - final = newStr; } } |
