From bed37f3e870106eb363b472810f75c536a27b604 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Sat, 27 Jan 2018 19:51:17 +0300 Subject: [PATCH 1/2] fixed end detection in project files --- src/console.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/console.c b/src/console.c index fb38313..8c07acf 100644 --- a/src/console.c +++ b/src/console.c @@ -28,6 +28,7 @@ #include "ext/file_dialog.h" #include +#include #define CONSOLE_CURSOR_COLOR ((tic_color_red)) #define CONSOLE_BACK_TEXT_COLOR ((tic_color_dark_gray)) @@ -692,7 +693,7 @@ static bool loadTextSection(const char* project, const char* comment, char* dst, { makeTag(BinarySections[i].tag, tag, b); - sprintf(tagbuf, "\n%s <%s>\n", comment, tag); + sprintf(tagbuf, "\n%s <%s>", comment, tag); const char* ptr = SDL_strstr(project, tagbuf); @@ -702,7 +703,7 @@ static bool loadTextSection(const char* project, const char* comment, char* dst, } { - sprintf(tagbuf, "\n%s \n", comment); + sprintf(tagbuf, "\n%s ", comment); const char* ptr = SDL_strstr(project, tagbuf); @@ -720,10 +721,17 @@ static bool loadTextSection(const char* project, const char* comment, char* dst, return done; } +static inline const char* getLineEnd(const char* ptr) +{ + while(*ptr && isspace(*ptr) && *ptr++ != '\n'); + + return ptr; +} + static bool loadTextSectionBank(const char* project, const char* comment, const char* tag, char* dst, s32 size) { char tagbuf[64]; - sprintf(tagbuf, "%s <%s>\n", comment, tag); + sprintf(tagbuf, "%s <%s>", comment, tag); const char* start = SDL_strstr(project, tagbuf); bool done = false; @@ -731,6 +739,7 @@ static bool loadTextSectionBank(const char* project, const char* comment, const if(start) { start += strlen(tagbuf); + start = getLineEnd(start); sprintf(tagbuf, "\n%s ", comment, tag); const char* end = SDL_strstr(start, tagbuf); @@ -749,7 +758,7 @@ static bool loadTextSectionBank(const char* project, const char* comment, const static bool loadBinarySection(const char* project, const char* comment, const char* tag, s32 count, void* dst, s32 size, bool flip) { char tagbuf[64]; - sprintf(tagbuf, "%s <%s>\n", comment, tag); + sprintf(tagbuf, "%s <%s>", comment, tag); const char* start = SDL_strstr(project, tagbuf); bool done = false; @@ -757,6 +766,7 @@ static bool loadBinarySection(const char* project, const char* comment, const ch if(start) { start += strlen(tagbuf); + start = getLineEnd(start); sprintf(tagbuf, "\n%s ", comment, tag); const char* end = SDL_strstr(start, tagbuf); @@ -779,6 +789,8 @@ static bool loadBinarySection(const char* project, const char* comment, const ch ptr += sizeof("-- 999:") - 1; str2buf(ptr, size*2, (u8*)dst + size*index, flip); ptr += size*2 + 1; + + ptr = getLineEnd(ptr); } else break; } From 4a60393a1cc9ac3554c88a74e86cf8015d95c630 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Wed, 31 Jan 2018 17:37:43 +0300 Subject: [PATCH 2/2] Code from other banks gets added to bank 0, if using external editor. #516 --- src/console.c | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/src/console.c b/src/console.c index 8c07acf..9e7e3b3 100644 --- a/src/console.c +++ b/src/console.c @@ -684,32 +684,13 @@ static bool loadTextSection(const char* project, const char* comment, char* dst, const char* end = project + strlen(project); { - char tagbuf[64]; - char tag[16]; + char tagstart[16]; + sprintf(tagstart, "\n%s <", comment); - for(s32 i = 0; i < COUNT_OF(BinarySections); i++) - { - for(s32 b = 0; b < TIC_BANKS; b++) - { - makeTag(BinarySections[i].tag, tag, b); + const char* ptr = SDL_strstr(project, tagstart); - sprintf(tagbuf, "\n%s <%s>", comment, tag); - - const char* ptr = SDL_strstr(project, tagbuf); - - if(ptr && ptr < end) - end = ptr; - } - } - - { - sprintf(tagbuf, "\n%s ", comment); - - const char* ptr = SDL_strstr(project, tagbuf); - - if(ptr && ptr < end) - end = ptr; - } + if(ptr && ptr < end) + end = ptr; } if(end > start)