rnd-20060726-1-src
[rocksndiamonds.git] / src / libgame / misc.c
index 10996510b7f8c29a4b4b22520558cf4ceab86b86..a810b6d11072c89d0389712014ae6b54cfb3063f 100644 (file)
@@ -470,7 +470,7 @@ static char *getLastPathSeparatorPtr(char *filename)
   return last_separator;
 }
 
-static char *getBaseNamePtr(char *filename)
+char *getBaseNamePtr(char *filename)
 {
   char *last_separator = getLastPathSeparatorPtr(filename);
 
@@ -750,6 +750,45 @@ void GetOptions(char *argv[], void (*print_usage_function)(void))
       /* when doing batch processing, always enable verbose mode (warnings) */
       options.verbose = TRUE;
     }
+#if 1
+#if DEBUG
+#if defined(TARGET_SDL)
+    else if (strncmp(option, "-SDL_ListModes", option_len) == 0)
+    {
+      SDL_Rect **modes;
+      int i;
+
+      SDL_Init(SDL_INIT_VIDEO);
+
+      /* get available fullscreen/hardware modes */
+      modes=SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE);
+
+      /* check if there are any modes available */
+      if (modes == (SDL_Rect **)0)
+      {
+       printf("No modes available!\n");
+
+       exit(-1);
+      }
+
+      /* check if our resolution is restricted */
+      if (modes == (SDL_Rect **)-1)
+      {
+       printf("All resolutions available.\n");
+      }
+      else
+      {
+       /* print valid modes */
+       printf("Available Modes:\n");
+       for(i = 0; modes[i]; i++)
+         printf("  %d x %d\n", modes[i]->w, modes[i]->h);
+      }
+
+      exit(0);
+    }
+#endif
+#endif
+#endif
     else if (*option == '-')
     {
       Error(ERR_EXIT_HELP, "unrecognized option '%s'", option_str);
@@ -1041,17 +1080,27 @@ boolean getFileChunk(FILE *file, char *chunk_name, int *chunk_size,
   return (feof(file) || ferror(file) ? FALSE : TRUE);
 }
 
-void putFileChunk(FILE *file, char *chunk_name, int chunk_size,
-                 int byte_order)
+int putFileChunk(FILE *file, char *chunk_name, int chunk_size,
+                int byte_order)
 {
+  int num_bytes = 0;
+
   /* write chunk name */
-  fputs(chunk_name, file);
+  if (file != NULL)
+    fputs(chunk_name, file);
+
+  num_bytes += strlen(chunk_name);
 
   if (chunk_size >= 0)
   {
     /* write chunk size */
-    putFile32BitInteger(file, chunk_size, byte_order);
+    if (file != NULL)
+      putFile32BitInteger(file, chunk_size, byte_order);
+
+    num_bytes += 4;
   }
+
+  return num_bytes;
 }
 
 int getFileVersion(FILE *file)
@@ -1065,17 +1114,22 @@ int getFileVersion(FILE *file)
                       version_build);
 }
 
-void putFileVersion(FILE *file, int version)
+int putFileVersion(FILE *file, int version)
 {
-  int version_major = VERSION_MAJOR(version);
-  int version_minor = VERSION_MINOR(version);
-  int version_patch = VERSION_PATCH(version);
-  int version_build = VERSION_BUILD(version);
+  if (file != NULL)
+  {
+    int version_major = VERSION_MAJOR(version);
+    int version_minor = VERSION_MINOR(version);
+    int version_patch = VERSION_PATCH(version);
+    int version_build = VERSION_BUILD(version);
 
-  fputc(version_major, file);
-  fputc(version_minor, file);
-  fputc(version_patch, file);
-  fputc(version_build, file);
+    fputc(version_major, file);
+    fputc(version_minor, file);
+    fputc(version_patch, file);
+    fputc(version_build, file);
+  }
+
+  return 4;
 }
 
 void ReadBytesFromFile(FILE *file, byte *buffer, unsigned long bytes)