added trimming (removing leading and trailing spaces) for SP level titles
authorHolger Schemel <info@artsoft.org>
Mon, 19 Feb 2018 21:48:35 +0000 (22:48 +0100)
committerHolger Schemel <info@artsoft.org>
Mon, 19 Feb 2018 21:48:35 +0000 (22:48 +0100)
src/files.c

index 6c150ea0f86b3ea4be3de7cc8a7ed79b252036c2..757e32a3e63cc821ab87db56f7b010be0b57230b 100644 (file)
@@ -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;