X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fmisc.c;h=7c8291961ee5a7c8fe2217e70ffce318c1dcc41a;hb=2c03953e712c427c94c02cdb1e15cd9e99e9e116;hp=b0244aa627ff6de461e6d99b72a2f43905bba53f;hpb=93806fb4c23f4b6ef58d9562e908a1b89ece869d;p=rocksndiamonds.git diff --git a/src/libgame/misc.c b/src/libgame/misc.c index b0244aa6..7c829196 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -159,12 +159,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 +175,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) @@ -806,7 +808,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); } @@ -818,7 +820,8 @@ void WriteUnusedBytesToFile(FILE *file, unsigned long bytes) #define TRANSLATE_KEYSYM_TO_KEYNAME 0 #define TRANSLATE_KEYSYM_TO_X11KEYNAME 1 -#define TRANSLATE_X11KEYNAME_TO_KEYSYM 2 +#define TRANSLATE_KEYNAME_TO_KEYSYM 2 +#define TRANSLATE_X11KEYNAME_TO_KEYSYM 3 void translate_keyname(Key *keysym, char **x11name, char **name, int mode) { @@ -1005,6 +1008,26 @@ void translate_keyname(Key *keysym, char **x11name, char **name, int mode) *x11name = name_buffer; } + else if (mode == TRANSLATE_KEYNAME_TO_KEYSYM) + { + Key key = KSYM_UNDEFINED; + + i = 0; + do + { + if (strcmp(translate_key[i].name, *name) == 0) + { + key = translate_key[i].key; + break; + } + } + while (translate_key[++i].x11name); + + if (key == KSYM_UNDEFINED) + Error(ERR_WARN, "getKeyFromKeyName(): not completely implemented"); + + *keysym = key; + } else if (mode == TRANSLATE_X11KEYNAME_TO_KEYSYM) { Key key = KSYM_UNDEFINED; @@ -1106,6 +1129,14 @@ char *getX11KeyNameFromKey(Key key) return x11name; } +Key getKeyFromKeyName(char *name) +{ + Key key; + + translate_keyname(&key, NULL, &name, TRANSLATE_KEYNAME_TO_KEYSYM); + return key; +} + Key getKeyFromX11KeyName(char *x11name) { Key key; @@ -1130,6 +1161,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 *filename) +{ + if (strlen(filename) > 4 && + strcmp(&filename[strlen(filename) - 4], ".wav") == 0) + return TRUE; + + return FALSE; +} + +boolean FileIsMusic(char *filename) +{ + if (strlen(filename) > 4 && + (strcmp(&filename[strlen(filename) - 4], ".mod") == 0 || + strcmp(&filename[strlen(filename) - 4], ".MOD") == 0 || + strncmp(filename, "mod.", 4) == 0 || + strncmp(filename, "MOD.", 4) == 0)) + return TRUE; + + return FALSE; +} + /* ========================================================================= */ /* functions only needed for non-Unix (non-command-line) systems */ /* ========================================================================= */