rnd-20020519-2-src
[rocksndiamonds.git] / src / libgame / misc.c
index 6992ff230bdda9b61150c91bcc9a39252832aab8..c59749ff92e94c71888d2dad04dc23d6d76df1cf 100644 (file)
@@ -14,9 +14,6 @@
 #include <time.h>
 #include <sys/time.h>
 #include <sys/types.h>
-/*
-#include <sys/stat.h>
-*/
 #include <stdarg.h>
 #include <ctype.h>
 #include <string.h>
@@ -115,7 +112,7 @@ static void sleep_milliseconds(unsigned long milliseconds_delay)
   boolean do_busy_waiting = (milliseconds_delay < 5 ? TRUE : FALSE);
 
 #if defined(PLATFORM_MSDOS)
-  /* don't use select() to perform waiting operations under DOS/Windows
+  /* don't use select() to perform waiting operations under DOS
      environment; always use a busy loop for waiting instead */
   do_busy_waiting = TRUE;
 #endif
@@ -159,12 +156,13 @@ boolean FrameReached(unsigned long *frame_counter_var,
 {
   unsigned long actual_frame_counter = FrameCounter;
 
-  if (actual_frame_counter < *frame_counter_var+frame_delay &&
+  if (actual_frame_counter < *frame_counter_var + frame_delay &&
       actual_frame_counter >= *frame_counter_var)
-    return(FALSE);
+    return FALSE;
 
   *frame_counter_var = actual_frame_counter;
-  return(TRUE);
+
+  return TRUE;
 }
 
 boolean DelayReached(unsigned long *counter_var,
@@ -174,10 +172,11 @@ boolean DelayReached(unsigned long *counter_var,
 
   if (actual_counter < *counter_var + delay &&
       actual_counter >= *counter_var)
-    return(FALSE);
+    return FALSE;
 
   *counter_var = actual_counter;
-  return(TRUE);
+
+  return TRUE;
 }
 
 void WaitUntilDelayReached(unsigned long *counter_var, unsigned long delay)
@@ -435,6 +434,7 @@ void GetOptions(char *argv[])
   options.network = FALSE;
   options.verbose = FALSE;
   options.debug = FALSE;
+  options.debug_command = NULL;
 
   while (*options_left)
   {
@@ -472,19 +472,23 @@ void GetOptions(char *argv[])
       Error(ERR_EXIT_HELP, "unrecognized option '%s'", option);
     else if (strncmp(option, "-help", option_len) == 0)
     {
-      printf("Usage: %s [options] [server.name [port]]\n"
+      printf("Usage: %s [options] [<server host> [<server port>]]\n"
             "Options:\n"
             "  -d, --display <host>[:<scr>]  X server display\n"
             "  -b, --basepath <directory>    alternative base directory\n"
             "  -l, --level <directory>       alternative level directory\n"
             "  -g, --graphics <directory>    alternative graphics directory\n"
-            "  -s, --sounds <directory>      alternative graphics directory\n"
-            "  -m, --music <directory>       alternative graphics directory\n"
+            "  -s, --sounds <directory>      alternative sounds directory\n"
+            "  -m, --music <directory>       alternative music directory\n"
             "  -n, --network                 network multiplayer game\n"
             "      --serveronly              only start network server\n"
             "  -v, --verbose                 verbose mode\n"
             "      --debug                   display debugging information\n",
             program.command_basename);
+
+      if (options.debug)
+       printf("      --debug-command <command> execute special command\n");
+
       exit(0);
     }
     else if (strncmp(option, "-display", option_len) == 0)
@@ -563,6 +567,15 @@ void GetOptions(char *argv[])
     {
       options.debug = TRUE;
     }
+    else if (strncmp(option, "-debug-command", option_len) == 0)
+    {
+      if (option_arg == NULL)
+       Error(ERR_EXIT_HELP, "option '%s' requires an argument", option_str);
+
+      options.debug_command = option_arg;
+      if (option_arg == next_option)
+       options_left++;
+    }
     else if (*option == '-')
     {
       Error(ERR_EXIT_HELP, "unrecognized option '%s'", option_str);
@@ -806,7 +819,7 @@ void putFileChunk(FILE *file, char *chunk_name, int chunk_size,
 
 void ReadUnusedBytesFromFile(FILE *file, unsigned long bytes)
 {
-  while (bytes--)
+  while (bytes-- && !feof(file))
     fgetc(file);
 }
 
@@ -1159,6 +1172,40 @@ char getCharFromKey(Key key)
 }
 
 
+/* ========================================================================= */
+/* functions for checking filenames                                          */
+/* ========================================================================= */
+
+boolean FileIsGraphic(char *filename)
+{
+  if (strlen(filename) > 4 &&
+      strcmp(&filename[strlen(filename) - 4], ".pcx") == 0)
+    return TRUE;
+
+  return FALSE;
+}
+
+boolean FileIsSound(char *basename)
+{
+  if (strlen(basename) > 4 &&
+      strcmp(&basename[strlen(basename) - 4], ".wav") == 0)
+    return TRUE;
+
+  return FALSE;
+}
+
+boolean FileIsMusic(char *basename)
+{
+  if (strlen(basename) > 4 &&
+      (strcmp(&basename[strlen(basename) - 4], ".mod") == 0 ||
+       strcmp(&basename[strlen(basename) - 4], ".MOD") == 0 ||
+       strncmp(basename, "mod.", 4) == 0 ||
+       strncmp(basename, "MOD.", 4) == 0))
+    return TRUE;
+
+  return FALSE;
+}
+
 /* ========================================================================= */
 /* functions only needed for non-Unix (non-command-line) systems */
 /* ========================================================================= */