From: Holger Schemel Date: Mon, 19 Feb 2018 21:48:35 +0000 (+0100) Subject: added trimming (removing leading and trailing spaces) for SP level titles X-Git-Tag: 4.0.1.2~2 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=dd70de09c4ba312d1b945585dba68b2a2d025bb9;p=rocksndiamonds.git added trimming (removing leading and trailing spaces) for SP level titles --- diff --git a/src/files.c b/src/files.c index 6c150ea0..757e32a3 100644 --- a/src/files.c +++ b/src/files.c @@ -3664,7 +3664,7 @@ void CopyNativeLevel_SP_to_RND(struct LevelInfo *level) { struct LevelInfo_SP *level_sp = level->native_sp_level; LevelInfoType *header = &level_sp->header; - int i, x, y; + int i, j, x, y; level->fieldx = level_sp->width; level->fieldy = level_sp->height; @@ -3688,9 +3688,20 @@ void CopyNativeLevel_SP_to_RND(struct LevelInfo *level) level->initial_player_gravity[i] = (header->InitialGravity == 1 ? TRUE : FALSE); + /* skip leading spaces */ for (i = 0; i < SP_LEVEL_NAME_LEN; i++) - level->name[i] = header->LevelTitle[i]; - level->name[SP_LEVEL_NAME_LEN] = '\0'; + if (header->LevelTitle[i] != ' ') + break; + + /* copy level title */ + for (j = 0; i < SP_LEVEL_NAME_LEN; i++, j++) + level->name[j] = header->LevelTitle[i]; + level->name[j] = '\0'; + + /* cut trailing spaces */ + for (; j > 0; j--) + if (level->name[j - 1] == ' ' && level->name[j] == '\0') + level->name[j - 1] = '\0'; level->gems_needed = header->InfotronsNeeded;