From 22e57e0eaec62f31f277f9d39f84c356a2835a5c Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Sun, 24 Sep 2023 23:33:20 +0300 Subject: [PATCH] simplified CR/LF removal from level name in saves. --- Quake/host_cmd.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Quake/host_cmd.c b/Quake/host_cmd.c index 4225632a7..b57347ff7 100644 --- a/Quake/host_cmd.c +++ b/Quake/host_cmd.c @@ -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'; } /*