mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-17 23:21:22 +00:00
Kind of support line breaks with PAGETEXT. Can't trim trailing whitespace yet.
This commit is contained in:
parent
ef241b4521
commit
a3d000a37e
1 changed files with 12 additions and 27 deletions
|
@ -146,7 +146,7 @@ char *myfgets(char *buf, size_t bufsize, MYFILE *f)
|
|||
return buf;
|
||||
}
|
||||
|
||||
static char *myhashfgets(char *buf, size_t bufsize, MYFILE *f, boolean trim)
|
||||
static char *myhashfgets(char *buf, size_t bufsize, MYFILE *f)
|
||||
{
|
||||
size_t i = 0;
|
||||
if (myfeof(f))
|
||||
|
@ -166,33 +166,15 @@ static char *myhashfgets(char *buf, size_t bufsize, MYFILE *f, boolean trim)
|
|||
dbg_line++;
|
||||
if (c == '#')
|
||||
{
|
||||
if (i > 0)
|
||||
i--; // don't include the hash in our string
|
||||
if (i > 0) // don't let i wrap past 0
|
||||
i--; // don't include hash char in string
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// HACK: BS code to make sure i doesn't wrap past 0
|
||||
// and put the terminator char AFTER the first non-whitespace char
|
||||
// OR at position 0 if the first char is whitespace OR a hash
|
||||
if (trim) // trailing whitespace only
|
||||
{
|
||||
if (i > 0)
|
||||
i--; // current char may be '#', so skip that
|
||||
while (i < bufsize && i > 0 && !myfeof(f))
|
||||
{
|
||||
char c = buf[i];
|
||||
if (i > 0)
|
||||
i--;
|
||||
if ((c != '\r' && c != '\n' && c != ' ') || i == 0)
|
||||
break;
|
||||
}
|
||||
if (buf[i] != '\r' && buf[i] != '\n' && buf[i] != ' ' && buf[i] != '#')
|
||||
i++; // put the null character after the first non-whitespace char
|
||||
}
|
||||
|
||||
if (buf[i] != '#') // don't include hash char in string
|
||||
i++;
|
||||
buf[i] = '\0';
|
||||
CONS_Printf("%s", buf);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
@ -375,7 +357,7 @@ static void readPlayer(MYFILE *f, INT32 num)
|
|||
if (playertext)
|
||||
{
|
||||
strcpy(description[num].notes, playertext);
|
||||
strcat(description[num].notes, myhashfgets(playertext, sizeof (description[num].notes), f, false));
|
||||
strcat(description[num].notes, myhashfgets(playertext, sizeof (description[num].notes), f));
|
||||
}
|
||||
else
|
||||
strcpy(description[num].notes, "");
|
||||
|
@ -1391,7 +1373,7 @@ static void readcutscenescene(MYFILE *f, INT32 num, INT32 scenenum)
|
|||
|
||||
strcat(buffer,
|
||||
myhashfgets(scenetext, bufferlen
|
||||
- strlen(buffer) - 1, f, false));
|
||||
- strlen(buffer) - 1, f));
|
||||
|
||||
// A cutscene overwriting another one...
|
||||
Z_Free(cutscenes[num]->scene[scenenum].text);
|
||||
|
@ -1624,9 +1606,12 @@ static void readtextpromptpage(MYFILE *f, INT32 num, INT32 pagenum)
|
|||
buffer = Z_Malloc(4096, PU_STATIC, NULL);
|
||||
strcpy(buffer, pagetext);
|
||||
|
||||
// \todo trim trailing whitespace before the #
|
||||
// and also support # at the end of a PAGETEXT with no line break
|
||||
|
||||
strcat(buffer,
|
||||
myhashfgets(pagetext, bufferlen
|
||||
- strlen(buffer) - 1, f, true));
|
||||
- strlen(buffer) - 1, f));
|
||||
|
||||
// A text prompt overwriting another one...
|
||||
Z_Free(textprompts[num]->page[pagenum].text);
|
||||
|
|
Loading…
Reference in a new issue