From: chaoskagami Date: Mon, 25 Aug 2014 02:12:16 +0000 (-0400) Subject: Adding lookahead broke jump, firstlines and lastlines. After determining the cause... X-Git-Tag: stable-2~10 X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;h=9e8af12f2b964df5d92890091e7aae1bdb288565;p=vn%2Fvndc.git Adding lookahead broke jump, firstlines and lastlines. After determining the cause (ordering issue, where I was memsetting ugh) it is fixed. Reloading saves also does not cause mass hysteria. --- diff --git a/bin/vndc.x86_64 b/bin/vndc.x86_64 index 3523bfb..0f8601b 100755 Binary files a/bin/vndc.x86_64 and b/bin/vndc.x86_64 differ diff --git a/buildscripts/build.generic b/buildscripts/build.generic index 5f636a0..8215677 100755 --- a/buildscripts/build.generic +++ b/buildscripts/build.generic @@ -11,7 +11,7 @@ SRC=$ROOT/ LIB=$ROOT/external/lib BIN=$ROOT/bin -CXXFLAGS="-DGIT_REV=\"$(git rev-parse HEAD)\"" +CXXFLAGS="-g -DGIT_REV=\"$(git rev-parse HEAD)\"" source buildscripts/mk diff --git a/vndc/include/Data.hpp b/vndc/include/Data.hpp index 48883a0..add415f 100644 --- a/vndc/include/Data.hpp +++ b/vndc/include/Data.hpp @@ -34,6 +34,7 @@ class DataContainer { bool verbose = false; int currentLine = 0; bool skip_key_on = false; + bool eof = false; char* window_name; char* next_line = NULL; // Used for voice-detect. // It's impossible to parse without lookahead. diff --git a/vndc/src/Parse.cpp b/vndc/src/Parse.cpp index a4accd4..3a550bc 100644 --- a/vndc/src/Parse.cpp +++ b/vndc/src/Parse.cpp @@ -142,8 +142,6 @@ void ParseCmd(char* line) { } else if(!strcmp(tokens[0], "goto")) op_goto(tokens[1]); - else if(!strcmp(tokens[0], "label")) {} - // Nuthin. else if(!strcmp(tokens[0], "cleartext")) op_cleartext(); @@ -224,16 +222,7 @@ void Parse() { // Load the next line to this one. char* line = GetData()->next_line; - if(line == NULL) { - // We've reached EOF. - op_jump(GetData()->main_scr[0], NULL, true); - } - - GetData()->next_line = (char*)calloc(sizeof(char), 400); - // Load the next line. - fgets(GetData()->next_line, 400, GetData()->accessScriptHandle); - - char* line_copy = GetData()->next_line; + char* line_copy = line; while(line_copy[0] == ' ' || line_copy[0] == '\t') { line_copy[0] = '\0'; @@ -246,17 +235,22 @@ void Parse() { line_copy[i] = '\0'; } + GetData()->next_line = (char*)calloc(sizeof(char), 400); + fgets(GetData()->next_line, 400, GetData()->accessScriptHandle); + // Execute the current line. - if(strlen(line) != 0) { - ParseCmd(line); + if(strlen(line_copy) != 0) { + ParseCmd(line_copy); } free(line); + // Load the next line. + // The next line is null, because the file is finished. - if(feof(GetData()->accessScriptHandle)) { - free(GetData()->next_line); - GetData()->next_line = NULL; + if(feof(GetData()->accessScriptHandle) && strlen(GetData()->next_line) == 0) { + // We've reached EOF. Jump back and return. + op_jump(GetData()->main_scr[0], NULL, true); } return; diff --git a/vndc/src/op_jump.cpp b/vndc/src/op_jump.cpp index a58b4d9..7650ab8 100644 --- a/vndc/src/op_jump.cpp +++ b/vndc/src/op_jump.cpp @@ -5,13 +5,12 @@ /* * Implements jump vnds function. * jump file - * The parser actually does most of the work. This - * just kind of gives it a nudge ans says 'reload k' */ void op_jump(char* file, int* lineTo, bool isSave) { if (GetData()->if_fail != 0) return; + memset(GetData()->current_scr, 0, 400); if(!isSave) snprintf(GetData()->current_scr, 400, "script/%s", file); @@ -30,6 +29,7 @@ void op_jump(char* file, int* lineTo, bool isSave) { GetData()->accessScriptHandle = fopen(GetData()->current_scr, "r"); if(GetData()->accessScriptHandle == NULL) { printf("[error] Failed to open script file %s.\n", GetData()->current_scr); + exit(-1); } @@ -50,16 +50,4 @@ void op_jump(char* file, int* lineTo, bool isSave) { // Load the next line. fgets(GetData()->next_line, 400, GetData()->accessScriptHandle); - char* line_copy = GetData()->next_line; - - while(line_copy[0] == ' ' || line_copy[0] == '\t') { - line_copy[0] = '\0'; - line_copy = &line_copy[1]; - } - - // Remove all '\n' from the buffer line - for(int i=0; i < (int)strlen(line_copy); i++) { - if (line_copy[i] == '\n') - line_copy[i] = '\0'; - } }