rnd-20140115-1-src
[rocksndiamonds.git] / src / libgame / misc.c
index d0746a46a1f650b4a1fcc2c5dcb8dbfac715f819..38c062dec0724f267527d79649c54c78e8bfb1fc 100644 (file)
@@ -708,7 +708,7 @@ char *getPath3(char *path1, char *path2, char *path3)
   return getStringCat3WithSeparator(path1, path2, path3, STRING_PATH_SEPARATOR);
 }
 
-char *getStringCopy(char *s)
+char *getStringCopy(const char *s)
 {
   char *s_copy;
 
@@ -721,7 +721,7 @@ char *getStringCopy(char *s)
   return s_copy;
 }
 
-char *getStringCopyN(char *s, int n)
+char *getStringCopyN(const char *s, int n)
 {
   char *s_copy;
   int s_len = MAX(0, n);
@@ -736,7 +736,18 @@ char *getStringCopyN(char *s, int n)
   return s_copy;
 }
 
-char *getStringToLower(char *s)
+char *getStringCopyNStatic(const char *s, int n)
+{
+  static char *s_copy = NULL;
+
+  checked_free(s_copy);
+
+  s_copy = getStringCopyN(s, n);
+
+  return s_copy;
+}
+
+char *getStringToLower(const char *s)
 {
   char *s_copy = checked_malloc(strlen(s) + 1);
   char *s_ptr = s_copy;
@@ -1057,15 +1068,17 @@ void GetOptions(char *argv[], void (*print_usage_function)(void))
 /* error handling functions                                                  */
 /* ------------------------------------------------------------------------- */
 
+#define MAX_INTERNAL_ERROR_SIZE                1024
+
 /* used by SetError() and GetError() to store internal error messages */
-static char internal_error[1024];      /* this is bad */
+static char internal_error[MAX_INTERNAL_ERROR_SIZE];
 
 void SetError(char *format, ...)
 {
   va_list ap;
 
   va_start(ap, format);
-  vsprintf(internal_error, format, ap);
+  vsnprintf(internal_error, MAX_INTERNAL_ERROR_SIZE, format, ap);
   va_end(ap);
 }
 
@@ -1644,7 +1657,7 @@ void translate_keyname(Key *keysym, char **x11name, char **name, int mode)
     { KSYM_braceright, "XK_braceright",        "brace right" },
     { KSYM_asciitilde, "XK_asciitilde",        "~" },
 
-    /* special (non-ASCII) keys */
+    /* special (non-ASCII) keys (ISO-Latin-1) */
     { KSYM_degree,     "XK_degree",            "°" },
     { KSYM_Adiaeresis, "XK_Adiaeresis",        "Ä" },
     { KSYM_Odiaeresis, "XK_Odiaeresis",        "Ö" },
@@ -1654,6 +1667,21 @@ void translate_keyname(Key *keysym, char **x11name, char **name, int mode)
     { KSYM_udiaeresis, "XK_udiaeresis",        "ü" },
     { KSYM_ssharp,     "XK_ssharp",            "sharp s" },
 
+#if defined(TARGET_SDL2)
+    /* special (non-ASCII) keys (UTF-8, for reverse mapping only) */
+    { KSYM_degree,     "XK_degree",            "\xc2\xb0" },
+    { KSYM_Adiaeresis, "XK_Adiaeresis",        "\xc3\x84" },
+    { KSYM_Odiaeresis, "XK_Odiaeresis",        "\xc3\x96" },
+    { KSYM_Udiaeresis, "XK_Udiaeresis",        "\xc3\x9c" },
+    { KSYM_adiaeresis, "XK_adiaeresis",        "\xc3\xa4" },
+    { KSYM_odiaeresis, "XK_odiaeresis",        "\xc3\xb6" },
+    { KSYM_udiaeresis, "XK_udiaeresis",        "\xc3\xbc" },
+    { KSYM_ssharp,     "XK_ssharp",            "\xc3\x9f" },
+
+    /* other keys (for reverse mapping only) */
+    { KSYM_space,      "XK_space",             " " },
+#endif
+
 #if defined(TARGET_SDL2)
     /* keypad keys are not in numerical order in SDL2 */
     { KSYM_KP_0,       "XK_KP_0",              "keypad 0" },
@@ -2481,13 +2509,22 @@ boolean fileHasSuffix(char *basename, char *suffix)
   return FALSE;
 }
 
+#if defined(TARGET_SDL)
+static boolean FileCouldBeArtwork(char *basename)
+{
+  return (!strEqual(basename, ".") &&
+         !strEqual(basename, "..") &&
+         !fileHasSuffix(basename, "txt") &&
+         !fileHasSuffix(basename, "conf"));
+}
+#endif
+
 boolean FileIsGraphic(char *filename)
 {
   char *basename = getBaseNamePtr(filename);
 
 #if defined(TARGET_SDL)
-  return (!fileHasSuffix(basename, "txt") &&
-         !fileHasSuffix(basename, "conf"));
+  return FileCouldBeArtwork(basename);
 #else
   return fileHasSuffix(basename, "pcx");
 #endif
@@ -2498,8 +2535,7 @@ boolean FileIsSound(char *filename)
   char *basename = getBaseNamePtr(filename);
 
 #if defined(TARGET_SDL)
-  return (!fileHasSuffix(basename, "txt") &&
-         !fileHasSuffix(basename, "conf"));
+  return FileCouldBeArtwork(basename);
 #else
   return fileHasSuffix(basename, "wav");
 #endif
@@ -2510,8 +2546,7 @@ boolean FileIsMusic(char *filename)
   char *basename = getBaseNamePtr(filename);
 
 #if defined(TARGET_SDL)
-  return (!fileHasSuffix(basename, "txt") &&
-         !fileHasSuffix(basename, "conf"));
+  return FileCouldBeArtwork(basename);
 #else
   if (FileIsSound(basename))
     return TRUE;
@@ -3755,7 +3790,7 @@ void NotifyUserAboutErrorFile()
 
 #if DEBUG
 
-#define DEBUG_PRINT_INIT_TIMESTAMPS            TRUE
+#define DEBUG_PRINT_INIT_TIMESTAMPS            FALSE
 #define DEBUG_PRINT_INIT_TIMESTAMPS_DEPTH      10
 
 #define DEBUG_NUM_TIMESTAMPS                   10