fixed <tag> end detection in project files
#include "ext/file_dialog.h"
#include <zlib.h>
+#include <ctype.h>
#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 <PALETTE>\n", comment);
+ sprintf(tagbuf, "\n%s <PALETTE>", 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 </%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 </%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;
}
