changed warnings and debug output to use new generic logging functions
[rocksndiamonds.git] / src / init.c
index 2b43180b42f937d8bb27bf2fb4d4ceea0b6cb754..bbf62e674f8dd9cb60416716ea11d4cf4628dd62 100644 (file)
@@ -1224,13 +1224,13 @@ static int get_graphic_parameter_value(char *value_raw, char *suffix, int type)
 
     if (value == NULL)
     {
-      Error(ERR_INFO_LINE, "-");
-      Error(ERR_INFO, "warning: error found in config file:");
-      Error(ERR_INFO, "- config file: '%s'", getImageConfigFilename());
-      Error(ERR_INFO, "error: invalid element token '%s'", value_raw);
-      Error(ERR_INFO, "custom graphic rejected for this element/action");
-      Error(ERR_INFO, "fallback done to undefined element for this graphic");
-      Error(ERR_INFO_LINE, "-");
+      Warn("---");
+      Warn("error found in config file:");
+      Warn("- config file: '%s'", getImageConfigFilename());
+      Warn("error: invalid element token '%s'", value_raw);
+      Warn("custom graphic rejected for this element/action");
+      Warn("fallback done to undefined element for this graphic");
+      Warn("---");
     }
 
     return (value != NULL ? atoi(value) : EL_UNDEFINED);
@@ -1242,13 +1242,13 @@ static int get_graphic_parameter_value(char *value_raw, char *suffix, int type)
 
     if (value == NULL)
     {
-      Error(ERR_INFO_LINE, "-");
-      Error(ERR_INFO, "warning: error found in config file:");
-      Error(ERR_INFO, "- config file: '%s'", getImageConfigFilename());
-      Error(ERR_INFO, "error: invalid graphic token '%s'", value_raw);
-      Error(ERR_INFO, "custom graphic rejected for this element/action");
-      Error(ERR_INFO, "fallback done to 'char_exclam' for this graphic");
-      Error(ERR_INFO_LINE, "-");
+      Warn("---");
+      Warn("error found in config file:");
+      Warn("- config file: '%s'", getImageConfigFilename());
+      Warn("error: invalid graphic token '%s'", value_raw);
+      Warn("custom graphic rejected for this element/action");
+      Warn("fallback done to 'char_exclam' for this graphic");
+      Warn("---");
     }
 
     return (value != NULL ? atoi(value) : fallback_graphic);
@@ -1379,20 +1379,20 @@ static void set_graphic_parameters_ext(int graphic, int *parameter,
   {
     if (g->width <= 0)
     {
-      Error(ERR_INFO_LINE, "-");
-      Error(ERR_WARN, "invalid value %d for '%s.width' (fallback done to %d)",
-           g->width, getTokenFromImageID(graphic), TILEX);
-      Error(ERR_INFO_LINE, "-");
+      Warn("---");
+      Warn("invalid value %d for '%s.width' (fallback done to %d)",
+          g->width, getTokenFromImageID(graphic), TILEX);
+      Warn("---");
 
       g->width = TILEX;                // will be checked to be inside bitmap later
     }
 
     if (g->height <= 0)
     {
-      Error(ERR_INFO_LINE, "-");
-      Error(ERR_WARN, "invalid value %d for '%s.height' (fallback done to %d)",
-           g->height, getTokenFromImageID(graphic), TILEY);
-      Error(ERR_INFO_LINE, "-");
+      Warn("---");
+      Warn("invalid value %d for '%s.height' (fallback done to %d)",
+          g->height, getTokenFromImageID(graphic), TILEY);
+      Warn("---");
 
       g->height = TILEY;       // will be checked to be inside bitmap later
     }
@@ -1650,18 +1650,18 @@ static void set_cloned_graphic_parameters(int graphic)
 
   if (num_references_followed >= max_num_images)
   {
-    Error(ERR_INFO_LINE, "-");
-    Error(ERR_INFO, "warning: error found in config file:");
-    Error(ERR_INFO, "- config file: '%s'", getImageConfigFilename());
-    Error(ERR_INFO, "- config token: '%s'", getTokenFromImageID(graphic));
-    Error(ERR_INFO, "error: loop discovered when resolving cloned graphics");
-    Error(ERR_INFO, "custom graphic rejected for this element/action");
+    Warn("---");
+    Warn("error found in config file:");
+    Warn("- config file: '%s'", getImageConfigFilename());
+    Warn("- config token: '%s'", getTokenFromImageID(graphic));
+    Warn("error: loop discovered when resolving cloned graphics");
+    Warn("custom graphic rejected for this element/action");
 
     if (graphic == fallback_graphic)
       Error(ERR_EXIT, "no fallback graphic available");
 
-    Error(ERR_INFO, "fallback done to 'char_exclam' for this graphic");
-    Error(ERR_INFO_LINE, "-");
+    Warn("fallback done to 'char_exclam' for this graphic");
+    Warn("---");
 
     graphic_info[graphic] = graphic_info[fallback_graphic];
   }
@@ -1800,22 +1800,21 @@ static void InitGraphicInfo(void)
        src_x + width  > src_bitmap_width ||
        src_y + height > src_bitmap_height)
     {
-      Error(ERR_INFO_LINE, "-");
-      Error(ERR_INFO, "warning: error found in config file:");
-      Error(ERR_INFO, "- config file: '%s'", getImageConfigFilename());
-      Error(ERR_INFO, "- config token: '%s'", getTokenFromImageID(i));
-      Error(ERR_INFO, "- image file: '%s'", src_bitmap->source_filename);
-      Error(ERR_INFO, "- frame size: %d, %d", width, height);
-      Error(ERR_INFO,
-           "error: first animation frame out of bounds (%d, %d) [%d, %d]",
-           src_x, src_y, src_bitmap_width, src_bitmap_height);
-      Error(ERR_INFO, "custom graphic rejected for this element/action");
+      Warn("---");
+      Warn("error found in config file:");
+      Warn("- config file: '%s'", getImageConfigFilename());
+      Warn("- config token: '%s'", getTokenFromImageID(i));
+      Warn("- image file: '%s'", src_bitmap->source_filename);
+      Warn("- frame size: %d, %d", width, height);
+      Warn("error: first animation frame out of bounds (%d, %d) [%d, %d]",
+          src_x, src_y, src_bitmap_width, src_bitmap_height);
+      Warn("custom graphic rejected for this element/action");
 
       if (i == fallback_graphic)
        Error(ERR_EXIT, "no fallback graphic available");
 
-      Error(ERR_INFO, "fallback done to 'char_exclam' for this graphic");
-      Error(ERR_INFO_LINE, "-");
+      Warn("fallback done to 'char_exclam' for this graphic");
+      Warn("---");
 
       graphic_info[i] = graphic_info[fallback_graphic];
 
@@ -1832,22 +1831,21 @@ static void InitGraphicInfo(void)
        src_x + width  > src_bitmap_width ||
        src_y + height > src_bitmap_height)
     {
-      Error(ERR_INFO_LINE, "-");
-      Error(ERR_INFO, "warning: error found in config file:");
-      Error(ERR_INFO, "- config file: '%s'", getImageConfigFilename());
-      Error(ERR_INFO, "- config token: '%s'", getTokenFromImageID(i));
-      Error(ERR_INFO, "- image file: '%s'", src_bitmap->source_filename);
-      Error(ERR_INFO, "- frame size: %d, %d", width, height);
-      Error(ERR_INFO,
-           "error: last animation frame (%d) out of bounds (%d, %d) [%d, %d]",
-           last_frame, src_x, src_y, src_bitmap_width, src_bitmap_height);
-      Error(ERR_INFO, "custom graphic rejected for this element/action");
+      Warn("---");
+      Warn("error found in config file:");
+      Warn("- config file: '%s'", getImageConfigFilename());
+      Warn("- config token: '%s'", getTokenFromImageID(i));
+      Warn("- image file: '%s'", src_bitmap->source_filename);
+      Warn("- frame size: %d, %d", width, height);
+      Warn("error: last animation frame (%d) out of bounds (%d, %d) [%d, %d]",
+          last_frame, src_x, src_y, src_bitmap_width, src_bitmap_height);
+      Warn("custom graphic rejected for this element/action");
 
       if (i == fallback_graphic)
        Error(ERR_EXIT, "no fallback graphic available");
 
-      Error(ERR_INFO, "fallback done to 'char_exclam' for this graphic");
-      Error(ERR_INFO_LINE, "-");
+      Warn("fallback done to 'char_exclam' for this graphic");
+      Warn("---");
 
       graphic_info[i] = graphic_info[fallback_graphic];
     }
@@ -2442,7 +2440,7 @@ static void ResolveGroupElementExt(int group_element, int recursion_depth)
 
   if (recursion_depth > NUM_GROUP_ELEMENTS)    // recursion too deep
   {
-    Error(ERR_WARN, "recursion too deep when resolving group element %d",
+    Warn("recursion too deep when resolving group element %d",
          group_element - EL_GROUP_START + 1);
 
     // replace element which caused too deep recursion by question mark
@@ -4900,6 +4898,7 @@ static void InitGlobal(void)
   }
 
   global.autoplay_leveldir = NULL;
+  global.patchtapes_leveldir = NULL;
   global.convert_leveldir = NULL;
   global.create_images_dir = NULL;
 
@@ -5031,18 +5030,20 @@ static void Execute_Command(char *command)
 
     exit(0);
   }
-  else if (strPrefix(command, "autotest ") ||
-          strPrefix(command, "autoplay ") ||
+  else if (strPrefix(command, "autoplay ") ||
           strPrefix(command, "autoffwd ") ||
-          strPrefix(command, "autowarp "))
+          strPrefix(command, "autowarp ") ||
+          strPrefix(command, "autotest ") ||
+          strPrefix(command, "autofix "))
   {
-    char *str_ptr = getStringCopy(&command[9]);        // read command parameters
+    char *str_ptr = getStringCopy(&command[8]);        // read command parameters
 
     global.autoplay_mode =
-      (strPrefix(command, "autotest") ? AUTOPLAY_MODE_TEST :
-       strPrefix(command, "autoplay") ? AUTOPLAY_MODE_PLAY :
+      (strPrefix(command, "autoplay") ? AUTOPLAY_MODE_PLAY :
        strPrefix(command, "autoffwd") ? AUTOPLAY_MODE_FFWD :
        strPrefix(command, "autowarp") ? AUTOPLAY_MODE_WARP :
+       strPrefix(command, "autotest") ? AUTOPLAY_MODE_TEST :
+       strPrefix(command, "autofix")  ? AUTOPLAY_MODE_FIX :
        AUTOPLAY_MODE_NONE);
 
     while (*str_ptr != '\0')                   // continue parsing string
@@ -5077,9 +5078,68 @@ static void Execute_Command(char *command)
        str_ptr++;
     }
 
-    if (global.autoplay_mode == AUTOPLAY_MODE_TEST)
+    if (global.autoplay_mode & AUTOPLAY_WARP_NO_DISPLAY)
       program.headless = TRUE;
   }
+  else if (strPrefix(command, "patch tapes "))
+  {
+    char *str_ptr = getStringCopy(&command[12]); // read command parameters
+
+    // skip leading whitespace
+    while (*str_ptr == ' ' || *str_ptr == '\t')
+      str_ptr++;
+
+    if (*str_ptr == '\0')
+      Error(ERR_EXIT, "cannot find MODE in command '%s'", command);
+
+    global.patchtapes_mode = str_ptr;          // store patch mode
+
+    // advance to next whitespace (or end of string)
+    while (*str_ptr != ' ' && *str_ptr != '\t' && *str_ptr != '\0')
+      str_ptr++;
+
+    while (*str_ptr != '\0')                   // continue parsing string
+    {
+      // cut leading whitespace from string, replace it by string terminator
+      while (*str_ptr == ' ' || *str_ptr == '\t')
+       *str_ptr++ = '\0';
+
+      if (*str_ptr == '\0')                    // end of string reached
+       break;
+
+      if (global.patchtapes_leveldir == NULL)  // read level set string
+      {
+       global.patchtapes_leveldir = str_ptr;
+       global.patchtapes_all = TRUE;           // default: patch all tapes
+
+       for (i = 0; i < MAX_TAPES_PER_SET; i++)
+         global.patchtapes_level[i] = FALSE;
+      }
+      else                                     // read level number string
+      {
+       int level_nr = atoi(str_ptr);           // get level_nr value
+
+       if (level_nr >= 0 && level_nr < MAX_TAPES_PER_SET)
+         global.patchtapes_level[level_nr] = TRUE;
+
+       global.patchtapes_all = FALSE;
+      }
+
+      // advance string pointer to the next whitespace (or end of string)
+      while (*str_ptr != ' ' && *str_ptr != '\t' && *str_ptr != '\0')
+       str_ptr++;
+    }
+
+    if (global.patchtapes_leveldir == NULL)
+    {
+      if (strEqual(global.patchtapes_mode, "help"))
+       global.patchtapes_leveldir = UNDEFINED_LEVELSET;
+      else
+       Error(ERR_EXIT, "cannot find LEVELDIR in command '%s'", command);
+    }
+
+    program.headless = TRUE;
+  }
   else if (strPrefix(command, "convert "))
   {
     char *str_copy = getStringCopy(strchr(command, ' ') + 1);
@@ -6093,7 +6153,7 @@ void OpenAll(void)
 #if defined(PLATFORM_UNIX)
     NetworkServer(network.server_port, TRUE);
 #else
-    Error(ERR_WARN, "networking only supported in Unix version");
+    Warn("networking only supported in Unix version");
 #endif
 
     exit(0);                   // never reached, server loops forever
@@ -6164,7 +6224,12 @@ void OpenAll(void)
 
   if (global.autoplay_leveldir)
   {
-    AutoPlayTape();
+    AutoPlayTapes();
+    return;
+  }
+  else if (global.patchtapes_leveldir)
+  {
+    PatchTapes();
     return;
   }
   else if (global.convert_leveldir)
@@ -6193,16 +6258,16 @@ void OpenAll(void)
   DrawMainMenu();
 
 #if 0
-  Error(ERR_DEBUG, "::: SDL_GetBasePath() == '%s'",
+  Debug("internal:path", "SDL_GetBasePath() == '%s'",
        SDL_GetBasePath());
-  Error(ERR_DEBUG, "::: SDL_GetPrefPath() == '%s'",
+  Debug("internal:path", "SDL_GetPrefPath() == '%s'",
        SDL_GetPrefPath("artsoft", "rocksndiamonds"));
 #if defined(PLATFORM_ANDROID)
-  Error(ERR_DEBUG, "::: SDL_AndroidGetInternalStoragePath() == '%s'",
+  Debug("internal:path", "SDL_AndroidGetInternalStoragePath() == '%s'",
        SDL_AndroidGetInternalStoragePath());
-  Error(ERR_DEBUG, "::: SDL_AndroidGetExternalStoragePath() == '%s'",
+  Debug("internal:path", "SDL_AndroidGetExternalStoragePath() == '%s'",
        SDL_AndroidGetExternalStoragePath());
-  Error(ERR_DEBUG, "::: SDL_AndroidGetExternalStorageState() == '%s'",
+  Debug("internal:path", "SDL_AndroidGetExternalStorageState() == '%s'",
        (SDL_AndroidGetExternalStorageState() &
         SDL_ANDROID_EXTERNAL_STORAGE_WRITE ? "writable" :
         SDL_AndroidGetExternalStorageState() &