Skip to content

Commit

Permalink
simplified CR/LF removal from level name in saves.
Browse files Browse the repository at this point in the history
  • Loading branch information
sezero committed Sep 24, 2023
1 parent 3d8827d commit 22e57e0
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions Quake/host_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -990,36 +990,36 @@ Host_SavegameComment
Writes a SAVEGAME_COMMENT_LENGTH character comment describing the current
===============
*/
static void Host_SavegameComment (char *text)
static void Host_SavegameComment (char text[SAVEGAME_COMMENT_LENGTH + 1])
{
int i;
char kills[20];
char *p1, *p2;
char *p;

for (i = 0; i < SAVEGAME_COMMENT_LENGTH; i++)
text[i] = ' ';

// Remove CR/LFs from level name to avoid broken saves, e.g. with autumn_sp map:
// https://celephais.net/board/view_thread.php?id=60452&start=3666
p1 = strchr(cl.levelname, '\n');
p2 = strchr(cl.levelname, '\r');
if (p1 != NULL) *p1 = 0;
if (p2 != NULL) *p2 = 0;
text[SAVEGAME_COMMENT_LENGTH] = '\0';

i = (int) strlen(cl.levelname);
if (i > 22) i = 22;
memcpy (text, cl.levelname, (size_t)i);

// Remove CR/LFs from level name to avoid broken saves, e.g. with autumn_sp map:
// https://celephais.net/board/view_thread.php?id=60452&start=3666
while ((p = strchr(text, '\n')) != NULL)
*p = ' ';
while ((p = strchr(text, '\r')) != NULL)
*p = ' ';

sprintf (kills,"kills:%3i/%3i", cl.stats[STAT_MONSTERS], cl.stats[STAT_TOTALMONSTERS]);
memcpy (text+22, kills, strlen(kills));

// convert space to _ to make stdio happy
for (i = 0; i < SAVEGAME_COMMENT_LENGTH; i++)
{
if (text[i] == ' ')
text[i] = '_';
}
if (p1 != NULL) *p1 = '\n';
if (p2 != NULL) *p2 = '\r';
text[SAVEGAME_COMMENT_LENGTH] = '\0';
}

/*
Expand Down

0 comments on commit 22e57e0

Please sign in to comment.