X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fmisc.c;h=259fb4dede6a1f3a41bf0fcf34e3cffffafa8d0d;hb=98c00f2bbb6bbb40e6ac5f989963638122acd17c;hp=883dd7d2afd7b18cc4b94db45622b2f12f012883;hpb=466733e5fd75e0d705bf80dddb48468c4c9885a7;p=rocksndiamonds.git diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 883dd7d2..259fb4de 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -606,6 +606,48 @@ char *getPath3(char *path1, char *path2, char *path3) return getStringCat3WithSeparator(path1, path2, path3, STRING_PATH_SEPARATOR); } +char *getImg2(char *path1, char *path2) +{ + char *filename = getPath2(path1, path2); + + if (!fileExists(filename) && strSuffix(path2, ".png")) + { + // backward compatibility: if PNG file not found, check for PCX file + char *path2pcx = getStringCopy(path2); + + strcpy(&path2pcx[strlen(path2pcx) - 3], "pcx"); + + free(filename); + + filename = getPath2(path1, path2pcx); + + free(path2pcx); + } + + return filename; +} + +char *getImg3(char *path1, char *path2, char *path3) +{ + char *filename = getPath3(path1, path2, path3); + + if (!fileExists(filename) && strSuffix(path3, ".png")) + { + // backward compatibility: if PNG file not found, check for PCX file + char *path3pcx = getStringCopy(path3); + + strcpy(&path3pcx[strlen(path3pcx) - 3], "pcx"); + + free(filename); + + filename = getPath3(path1, path2, path3pcx); + + free(path3pcx); + } + + return filename; +} + char *getStringCopy(const char *s) { char *s_copy; @@ -760,7 +802,6 @@ void GetOptions(char *argv[], options.network = FALSE; options.verbose = FALSE; options.debug = FALSE; - options.debug_x11_sync = FALSE; #if 1 options.verbose = TRUE; @@ -888,10 +929,6 @@ void GetOptions(char *argv[], { options.debug = TRUE; } - else if (strncmp(option, "-debug-x11-sync", option_len) == 0) - { - options.debug_x11_sync = TRUE; - } else if (strncmp(option, "-verbose", option_len) == 0) { options.verbose = TRUE; @@ -1010,6 +1047,9 @@ void Error(int mode, char *format, ...) if (mode & ERR_WARN) fprintf_nonewline(program.error_file, "warning: "); + if (mode & ERR_EXIT) + fprintf_nonewline(program.error_file, "fatal error: "); + va_start(ap, format); vfprintf_newline(program.error_file, format, ap); va_end(ap); @@ -1418,7 +1458,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 (ISO-Latin-1) */ + /* special (non-ASCII) keys */ { KSYM_degree, "XK_degree", "degree" }, { KSYM_Adiaeresis, "XK_Adiaeresis", "A umlaut" }, { KSYM_Odiaeresis, "XK_Odiaeresis", "O umlaut" }, @@ -1699,6 +1739,26 @@ Key getKeyFromX11KeyName(char *x11name) char getCharFromKey(Key key) { + static struct + { + Key key; + byte key_char; + } translate_key_char[] = + { + /* special (non-ASCII) keys (ISO-8859-1) */ + { KSYM_degree, CHAR_BYTE_DEGREE }, + { KSYM_Adiaeresis, CHAR_BYTE_UMLAUT_A }, + { KSYM_Odiaeresis, CHAR_BYTE_UMLAUT_O }, + { KSYM_Udiaeresis, CHAR_BYTE_UMLAUT_U }, + { KSYM_adiaeresis, CHAR_BYTE_UMLAUT_a }, + { KSYM_odiaeresis, CHAR_BYTE_UMLAUT_o }, + { KSYM_udiaeresis, CHAR_BYTE_UMLAUT_u }, + { KSYM_ssharp, CHAR_BYTE_SHARP_S }, + + /* end-of-array identifier */ + { 0, 0 } + }; + char *keyname = getKeyNameFromKey(key); char c = 0; @@ -1706,6 +1766,21 @@ char getCharFromKey(Key key) c = keyname[0]; else if (strEqual(keyname, "space")) c = ' '; + else + { + int i = 0; + + do + { + if (key == translate_key_char[i].key) + { + c = translate_key_char[i].key_char; + + break; + } + } + while (translate_key_char[++i].key_char); + } return c; } @@ -2176,7 +2251,9 @@ boolean directoryExists(char *dir_name) if (dir_name == NULL) return FALSE; - boolean success = (access(dir_name, F_OK) == 0); + struct stat file_status; + boolean success = (stat(dir_name, &file_status) == 0 && + (file_status.st_mode & S_IFMT) == S_IFDIR); #if defined(PLATFORM_ANDROID) if (!success) @@ -2264,40 +2341,37 @@ boolean fileHasSuffix(char *basename, char *suffix) return FALSE; } -static boolean FileCouldBeArtwork(char *basename) +static boolean FileCouldBeArtwork(char *filename) { + char *basename = getBaseNamePtr(filename); + return (!strEqual(basename, ".") && !strEqual(basename, "..") && !fileHasSuffix(basename, "txt") && - !fileHasSuffix(basename, "conf")); + !fileHasSuffix(basename, "conf") && + !directoryExists(filename)); } boolean FileIsGraphic(char *filename) { - char *basename = getBaseNamePtr(filename); - - return FileCouldBeArtwork(basename); + return FileCouldBeArtwork(filename); } boolean FileIsSound(char *filename) { - char *basename = getBaseNamePtr(filename); - - return FileCouldBeArtwork(basename); + return FileCouldBeArtwork(filename); } boolean FileIsMusic(char *filename) { - char *basename = getBaseNamePtr(filename); - - return FileCouldBeArtwork(basename); + return FileCouldBeArtwork(filename); } -boolean FileIsArtworkType(char *basename, int type) +boolean FileIsArtworkType(char *filename, int type) { - if ((type == TREE_TYPE_GRAPHICS_DIR && FileIsGraphic(basename)) || - (type == TREE_TYPE_SOUNDS_DIR && FileIsSound(basename)) || - (type == TREE_TYPE_MUSIC_DIR && FileIsMusic(basename))) + if ((type == TREE_TYPE_GRAPHICS_DIR && FileIsGraphic(filename)) || + (type == TREE_TYPE_SOUNDS_DIR && FileIsSound(filename)) || + (type == TREE_TYPE_MUSIC_DIR && FileIsMusic(filename))) return TRUE; return FALSE;