rnd-20131028-1-src
[rocksndiamonds.git] / src / files.c
index 21aea23846ba9d6a060261331174d87e07e84472..0f74fc00a00e31f9ed5843ce4be57b0e40ccfa71 100644 (file)
@@ -3364,7 +3364,8 @@ static void LoadLevelFromFileInfo_RND(struct LevelInfo *level,
   else /* check for pre-2.0 file format with cookie string */
   {
     strcpy(cookie, chunk_name);
-    fgets(&cookie[4], MAX_LINE_LEN - 4, file);
+    if (fgets(&cookie[4], MAX_LINE_LEN - 4, file) == NULL)
+      cookie[4] = '\0';
     if (strlen(cookie) > 0 && cookie[strlen(cookie) - 1] == '\n')
       cookie[strlen(cookie) - 1] = '\0';
 
@@ -6416,7 +6417,8 @@ static void LoadLevelFromFileInfo_DC(struct LevelInfo *level,
   if (level_file_info->packed)
   {
     /* read "magic bytes" from start of file */
-    fgets(magic_bytes, num_magic_bytes + 1, file);
+    if (fgets(magic_bytes, num_magic_bytes + 1, file) == NULL)
+      magic_bytes[0] = '\0';
 
     /* check "magic bytes" for correct file format */
     if (!strPrefix(magic_bytes, "DC2"))
@@ -8799,7 +8801,8 @@ void LoadTapeFromFilename(char *filename)
   else /* check for pre-2.0 file format with cookie string */
   {
     strcpy(cookie, chunk_name);
-    fgets(&cookie[4], MAX_LINE_LEN - 4, file);
+    if (fgets(&cookie[4], MAX_LINE_LEN - 4, file) == NULL)
+      cookie[4] = '\0';
     if (strlen(cookie) > 0 && cookie[strlen(cookie) - 1] == '\n')
       cookie[strlen(cookie) - 1] = '\0';
 
@@ -9142,7 +9145,8 @@ void LoadScore(int nr)
     return;
 
   /* check file identifier */
-  fgets(cookie, MAX_LINE_LEN, file);
+  if (fgets(cookie, MAX_LINE_LEN, file) == NULL)
+    cookie[0] = '\0';
   if (strlen(cookie) > 0 && cookie[strlen(cookie) - 1] == '\n')
     cookie[strlen(cookie) - 1] = '\0';
 
@@ -9155,10 +9159,12 @@ void LoadScore(int nr)
 
   for (i = 0; i < MAX_SCORE_ENTRIES; i++)
   {
-    fscanf(file, "%d", &highscore[i].Score);
-    fgets(line, MAX_LINE_LEN, file);
+    if (fscanf(file, "%d", &highscore[i].Score) == EOF)
+      Error(ERR_WARN, "fscanf() failed; %s", strerror(errno));
+    if (fgets(line, MAX_LINE_LEN, file) == NULL)
+      line[0] = '\0';
 
-    if (line[strlen(line) - 1] == '\n')
+    if (strlen(line) > 0 && line[strlen(line) - 1] == '\n')
       line[strlen(line) - 1] = '\0';
 
     for (line_ptr = line; *line_ptr; line_ptr++)
@@ -9240,8 +9246,11 @@ void SaveScore(int nr)
 #define SETUP_TOKEN_OVERRIDE_LEVEL_GRAPHICS    30
 #define SETUP_TOKEN_OVERRIDE_LEVEL_SOUNDS      31
 #define SETUP_TOKEN_OVERRIDE_LEVEL_MUSIC       32
+#define SETUP_TOKEN_VOLUME_SIMPLE              33
+#define SETUP_TOKEN_VOLUME_LOOPS               34
+#define SETUP_TOKEN_VOLUME_MUSIC               35
 
-#define NUM_GLOBAL_SETUP_TOKENS                        33
+#define NUM_GLOBAL_SETUP_TOKENS                        36
 
 /* editor setup */
 #define SETUP_TOKEN_EDITOR_EL_BOULDERDASH      0
@@ -9384,6 +9393,9 @@ static struct TokenInfo global_setup_tokens[] =
   { TYPE_SWITCH3,&si.override_level_graphics, "override_level_graphics"        },
   { TYPE_SWITCH3,&si.override_level_sounds,   "override_level_sounds"  },
   { TYPE_SWITCH3,&si.override_level_music,    "override_level_music"   },
+  { TYPE_INTEGER,&si.volume_simple,           "volume_simple"          },
+  { TYPE_INTEGER,&si.volume_loops,            "volume_loops"           },
+  { TYPE_INTEGER,&si.volume_music,            "volume_music"           },
 };
 
 static boolean not_used = FALSE;
@@ -9554,6 +9566,10 @@ static void setSetupInfoToDefaults(struct SetupInfo *si)
   si->override_level_sounds = FALSE;
   si->override_level_music = FALSE;
 
+  si->volume_simple = 100;     /* percent */
+  si->volume_loops = 100;      /* percent */
+  si->volume_music = 100;      /* percent */
+
   si->editor.el_boulderdash            = TRUE;
   si->editor.el_emerald_mine           = TRUE;
   si->editor.el_emerald_mine_club      = TRUE;
@@ -9816,7 +9832,8 @@ void SaveSetup()
   {
     /* just to make things nicer :) */
     if (i == SETUP_TOKEN_PLAYER_NAME + 1 ||
-       i == SETUP_TOKEN_GRAPHICS_SET)
+       i == SETUP_TOKEN_GRAPHICS_SET ||
+       i == SETUP_TOKEN_VOLUME_SIMPLE)
       fprintf(file, "\n");
 
     fprintf(file, "%s\n", getSetupLine(global_setup_tokens, "", i));