updated contact info in source file headers
[rocksndiamonds.git] / src / libgame / misc.c
index 7c2f4353851cb803d8dc8bd43fd1474e65711df8..8a7c94d60acd22985fb44830cd165acf05a34732 100644 (file)
@@ -1,15 +1,13 @@
-/***********************************************************
-* Artsoft Retro-Game Library                               *
-*----------------------------------------------------------*
-* (c) 1994-2006 Artsoft Entertainment                      *
-*               Holger Schemel                             *
-*               Detmolder Strasse 189                      *
-*               33604 Bielefeld                            *
-*               Germany                                    *
-*               e-mail: info@artsoft.org                   *
-*----------------------------------------------------------*
-* misc.c                                                   *
-***********************************************************/
+// ============================================================================
+// Artsoft Retro-Game Library
+// ----------------------------------------------------------------------------
+// (c) 1995-2014 by Artsoft Entertainment
+//                         Holger Schemel
+//                 info@artsoft.org
+//                 http://www.artsoft.org/
+// ----------------------------------------------------------------------------
+// misc.c
+// ============================================================================
 
 #include <time.h>
 #include <sys/time.h>
@@ -233,20 +231,7 @@ static unsigned int getCurrentMS()
 {
   return SDL_GetTicks();
 }
-
-#else /* !TARGET_SDL */
-
-#if defined(PLATFORM_UNIX)
-static unsigned int getCurrentMS()
-{
-  struct timeval current_time;
-
-  gettimeofday(&current_time, NULL);
-
-  return current_time.tv_sec * 1000 + current_time.tv_usec / 1000;
-}
-#endif /* PLATFORM_UNIX */
-#endif /* !TARGET_SDL */
+#endif
 
 static unsigned int mainCounter(int mode)
 {
@@ -283,29 +268,7 @@ static unsigned int mainCounter(int mode)
 
   return counter_ms;           /* return milliseconds since last init */
 }
-
-#else /* !TARGET_SDL */
-
-#if defined(PLATFORM_UNIX)
-static unsigned int mainCounter(int mode)
-{
-  static struct timeval base_time = { 0, 0 };
-  struct timeval current_time;
-  unsigned int counter_ms;
-
-  gettimeofday(&current_time, NULL);
-
-  /* reset base time in case of counter initializing or wrap-around */
-  if (mode == INIT_COUNTER || current_time.tv_sec < base_time.tv_sec)
-    base_time = current_time;
-
-  counter_ms = (current_time.tv_sec  - base_time.tv_sec)  * 1000
-             + (current_time.tv_usec - base_time.tv_usec) / 1000;
-
-  return counter_ms;           /* return milliseconds since last init */
-}
-#endif /* PLATFORM_UNIX */
-#endif /* !TARGET_SDL */
+#endif
 
 #endif
 
@@ -340,8 +303,6 @@ static void sleep_milliseconds(unsigned int milliseconds_delay)
   {
 #if defined(TARGET_SDL)
     SDL_Delay(milliseconds_delay);
-#elif defined(TARGET_ALLEGRO)
-    rest(milliseconds_delay);
 #else
     struct timeval delay;
 
@@ -802,7 +763,9 @@ boolean strSuffixLower(char *s, char *suffix)
 /* command line option handling functions                                    */
 /* ------------------------------------------------------------------------- */
 
-void GetOptions(char *argv[], void (*print_usage_function)(void))
+void GetOptions(char *argv[],
+               void (*print_usage_function)(void),
+               void (*print_version_function)(void))
 {
   char *ro_base_path = RO_BASE_PATH;
   char *rw_base_path = RW_BASE_PATH;
@@ -899,7 +862,9 @@ void GetOptions(char *argv[], void (*print_usage_function)(void))
     option_len = strlen(option);
 
     if (strEqual(option, "-"))
+    {
       Error(ERR_EXIT_HELP, "unrecognized option '%s'", option);
+    }
     else if (strncmp(option, "-help", option_len) == 0)
     {
       print_usage_function();
@@ -977,10 +942,6 @@ void GetOptions(char *argv[], void (*print_usage_function)(void))
     {
       options.serveronly = TRUE;
     }
-    else if (strncmp(option, "-verbose", option_len) == 0)
-    {
-      options.verbose = TRUE;
-    }
     else if (strncmp(option, "-debug", option_len) == 0)
     {
       options.debug = TRUE;
@@ -989,6 +950,17 @@ void GetOptions(char *argv[], void (*print_usage_function)(void))
     {
       options.debug_x11_sync = TRUE;
     }
+    else if (strncmp(option, "-verbose", option_len) == 0)
+    {
+      options.verbose = TRUE;
+    }
+    else if (strncmp(option, "-version", option_len) == 0 ||
+            strncmp(option, "-V", option_len) == 0)
+    {
+      print_version_function();
+
+      exit(0);
+    }
     else if (strPrefix(option, "-D"))
     {
 #if 1
@@ -3728,6 +3700,9 @@ void openErrorFile()
     Error(ERR_WARN, "cannot open file '%s' for writing: %s",
          program.error_filename, strerror(errno));
   }
+
+  /* error output should be unbuffered so it is not truncated in a crash */
+  setbuf(program.error_file, NULL);
 }
 
 void closeErrorFile()