#include "preprocessor.h" #include "level_types.h" #include #include #include char* get_model_imports(FILE* lfile) { return NULL; } ParsedLevel* process_hash_statements(FILE* lfile) { ParsedLevel* pl = create_pl(); int character; char statement[12]; //bool hash_block = true; // SAFETY: The rest of this function should **NEVER** override this element! This is the only // thing that is preventing an overrun of this segment of memory!! statement[11] = '\0'; while(true) { character = fgetc(lfile); // If the character is EOF, break from the loop; we've done all that we can! // If the character is not a hash, then we don't care about that line and should skip it if(character == EOF) { break; }else if(character != '#') { // We need to skip this entire line, so we have to read until we find a newline or EOF while(true) { //printf("C: %c", character); if(character == '\n' || character == EOF){ break; } character = fgetc(lfile); } continue; } // Iterate over the first few characters (11 at most). If we find a semicolon or space, then add the string // terminator and break out of the inner loop early so we can see what its value is! for(int i = 0; i < 11; i++) { character = fgetc(lfile); if(character == ';' || character == ' ') { statement[i] = '\0'; break; } statement[i] = (char)character; } printf("%s\n", statement); if(!strcmp(statement, "include")){ process_include(lfile, pl); } } return pl; } const size_t MAX_INCLUDE_SIZE = 64; char* process_include(FILE* lfile, ParsedLevel* pl) { int c; char mod[MAX_INCLUDE_SIZE]; // SAFETY: The rest of this function should **NEVER** override this element! This is the only // thing that is preventing an overrun of this segment of memory!! mod[63] = '\n'; while(true) { c = fgetc(lfile); if(c == ';' || c == '\n'){ break; }else if(c == '"' || c == ' ' || c == ','){ continue; } for(int i = 0; i < MAX_INCLUDE_SIZE - 1; i++){ if(c == '"'){ mod[i] = '\0'; break; } mod[i] = c; c = fgetc(lfile); } add_model(pl, mod); } return NULL; }