X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fmisc.c;h=d28b48dff26ceb9580949eaf674b14f990e3f686;hb=0838017832a108ba365ea0efb851fc8c4d5f3aa5;hp=eb3e7a0f6ba58faa9b0b105fe46edcf9d3edcf1f;hpb=2ad9cd3aeb8b97f1cb869dd70f26abd0f7468a81;p=rocksndiamonds.git diff --git a/src/libgame/misc.c b/src/libgame/misc.c index eb3e7a0f..d28b48df 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -106,7 +106,7 @@ char *int2str(int number, int size) if (size > 20) size = 20; - if (size) + if (size > 0) { sprintf(s, " %09d", number); return &s[strlen(s) - size]; @@ -156,6 +156,11 @@ int log_2(unsigned int x) return e; } +boolean getTokenValueFromString(char *string, char **token, char **value) +{ + return getTokenValueFromSetupLine(string, token, value); +} + /* ------------------------------------------------------------------------- */ /* counter functions */ @@ -552,6 +557,21 @@ char *getStringCopy(char *s) return s_copy; } +char *getStringCopyN(char *s, int n) +{ + char *s_copy; + int s_len = MAX(0, n); + + if (s == NULL) + return NULL; + + s_copy = checked_malloc(s_len + 1); + strncpy(s_copy, s, s_len); + s[s_len] = '\0'; + + return s_copy; +} + char *getStringToLower(char *s) { char *s_copy = checked_malloc(strlen(s) + 1); @@ -579,6 +599,14 @@ boolean strEqual(char *s1, char *s2) strcmp(s1, s2) == 0); } +boolean strEqualN(char *s1, char *s2, int n) +{ + return (s1 == NULL && s2 == NULL ? TRUE : + s1 == NULL && s2 != NULL ? FALSE : + s1 != NULL && s2 == NULL ? FALSE : + strncmp(s1, s2, n) == 0); +} + /* ------------------------------------------------------------------------- */ /* command line option handling functions */ @@ -1782,7 +1810,15 @@ int get_parameter_value(char *value_raw, char *suffix, int type) { result = (strEqual(value, "left") ? ALIGN_LEFT : strEqual(value, "right") ? ALIGN_RIGHT : - strEqual(value, "center") ? ALIGN_CENTER : ALIGN_DEFAULT); + strEqual(value, "center") ? ALIGN_CENTER : + strEqual(value, "middle") ? ALIGN_CENTER : ALIGN_DEFAULT); + } + else if (strEqual(suffix, ".valign")) + { + result = (strEqual(value, "top") ? VALIGN_TOP : + strEqual(value, "bottom") ? VALIGN_BOTTOM : + strEqual(value, "middle") ? VALIGN_MIDDLE : + strEqual(value, "center") ? VALIGN_MIDDLE : VALIGN_DEFAULT); } else if (strEqual(suffix, ".anim_mode")) { @@ -1798,8 +1834,6 @@ int get_parameter_value(char *value_raw, char *suffix, int type) string_has_parameter(value, "horizontal") ? ANIM_HORIZONTAL : string_has_parameter(value, "vertical") ? ANIM_VERTICAL : string_has_parameter(value, "centered") ? ANIM_CENTERED : - string_has_parameter(value, "fade") ? ANIM_FADE : - string_has_parameter(value, "crossfade") ? ANIM_CROSSFADE : ANIM_DEFAULT); if (string_has_parameter(value, "reverse")) @@ -1811,6 +1845,18 @@ int get_parameter_value(char *value_raw, char *suffix, int type) if (string_has_parameter(value, "static_panel")) result |= ANIM_STATIC_PANEL; } + else if (strEqual(suffix, ".fade_mode")) + { + result = (string_has_parameter(value, "none") ? FADE_MODE_NONE : + string_has_parameter(value, "fade") ? FADE_MODE_FADE : + string_has_parameter(value, "crossfade") ? FADE_MODE_CROSSFADE : + string_has_parameter(value, "melt") ? FADE_MODE_MELT : + FADE_MODE_DEFAULT); + } + else if (strEqualN(suffix, ".font", 5)) /* (may also be ".font_xyz") */ + { + result = gfx.get_font_from_token_function(value); + } else /* generic parameter of type integer or boolean */ { result = (strEqual(value, ARG_UNDEFINED) ? ARG_UNDEFINED_VALUE : @@ -1824,7 +1870,7 @@ int get_parameter_value(char *value_raw, char *suffix, int type) return result; } -int get_auto_parameter_value(char *token, char *value_raw) +int get_token_parameter_value(char *token, char *value_raw) { char *suffix; @@ -1835,6 +1881,21 @@ int get_auto_parameter_value(char *token, char *value_raw) if (suffix == NULL) suffix = token; +#if 0 + if (strncmp(suffix, ".font", 5) == 0) + { + int i; + + /* !!! OPTIMIZE THIS BY USING HASH !!! */ + for (i = 0; i < NUM_FONTS; i++) + if (strEqual(value_raw, font_info[i].token_name)) + return i; + + /* if font not found, use reliable default value */ + return FONT_INITIAL_1; + } +#endif + return get_parameter_value(value_raw, suffix, TYPE_INTEGER); } @@ -2683,7 +2744,7 @@ static void LoadCustomArtwork(struct ArtworkListInfo *artwork_info, struct FileInfo *file_list_entry) { #if 0 - printf("GOT CUSTOM ARTWORK FILE '%s'\n", filename); + printf("GOT CUSTOM ARTWORK FILE '%s'\n", file_list_entry->filename); #endif if (strEqual(file_list_entry->filename, UNDEFINED_FILENAME))