X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fmisc.c;h=d0bc9fa9401067173c21224ceedbb687af35015d;hb=4fcf5c6436d34bdc44bc534d21d9ec95bf072333;hp=bde3ea638ccc744881a3d393fdf50190adf174bf;hpb=c9735f4510c07f163fc103d61ba4e0d2010c2032;p=rocksndiamonds.git diff --git a/src/libgame/misc.c b/src/libgame/misc.c index bde3ea63..d0bc9fa9 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -458,6 +458,7 @@ static void printUsage() " \"print graphicsinfo.conf\" print default graphics config\n" " \"print soundsinfo.conf\" print default sounds config\n" " \"print musicinfo.conf\" print default music config\n" + " \"dump level FILE\" dump level data from FILE\n" " \"dump tape FILE\" dump tape data from FILE\n" " \"autoplay LEVELDIR\" play level tapes for LEVELDIR\n" "\n", @@ -1234,6 +1235,63 @@ char getCharFromKey(Key key) } +/* ------------------------------------------------------------------------- */ +/* functions to translate string identifiers to integer or boolean value */ +/* ------------------------------------------------------------------------- */ + +int get_integer_from_string(char *s) +{ + static char *number_text[][3] = + { + { "0", "zero", "null", }, + { "1", "one", "first" }, + { "2", "two", "second" }, + { "3", "three", "third" }, + { "4", "four", "fourth" }, + { "5", "five", "fifth" }, + { "6", "six", "sixth" }, + { "7", "seven", "seventh" }, + { "8", "eight", "eighth" }, + { "9", "nine", "ninth" }, + { "10", "ten", "tenth" }, + { "11", "eleven", "eleventh" }, + { "12", "twelve", "twelfth" }, + }; + + int i, j; + char *s_lower = getStringToLower(s); + int result = -1; + + for (i=0; i<13; i++) + for (j=0; j<3; j++) + if (strcmp(s_lower, number_text[i][j]) == 0) + result = i; + + if (result == -1) + result = atoi(s); + + free(s_lower); + + return result; +} + +boolean get_boolean_from_string(char *s) +{ + char *s_lower = getStringToLower(s); + boolean result = FALSE; + + if (strcmp(s_lower, "true") == 0 || + strcmp(s_lower, "yes") == 0 || + strcmp(s_lower, "on") == 0 || + get_integer_from_string(s) == 1) + result = TRUE; + + free(s_lower); + + return result; +} + + /* ========================================================================= */ /* functions for generic lists */ /* ========================================================================= */ @@ -1369,6 +1427,13 @@ boolean FileIsArtworkType(char *basename, int type) /* functions for loading artwork configuration information */ /* ========================================================================= */ +static int get_parameter_value(int type, char *value) +{ + return (type == TYPE_INTEGER ? get_integer_from_string(value) : + type == TYPE_BOOLEAN ? get_boolean_from_string(value) : + -1); +} + struct FileInfo *getFileListFromConfigList(struct ConfigInfo *config_list, struct ConfigInfo *suffix_list, int num_file_list_entries) @@ -1400,7 +1465,8 @@ struct FileInfo *getFileListFromConfigList(struct ConfigInfo *config_list, for (j=0; jfile_list; + struct ConfigInfo *suffix_list = artwork_info->suffix_list; + int num_file_list_entries = artwork_info->num_file_list_entries; + int num_suffix_list_entries = artwork_info->num_suffix_list_entries; + char *filename = getCustomArtworkConfigFilename(artwork_info->type); + struct SetupFileList *setup_file_list; + char *known_token_value = "[KNOWN_TOKEN]"; + int i, j; + + if (!options.verbose) + return; + + if (filename == NULL) + return; + + if ((setup_file_list = loadSetupFileList(filename)) == NULL) + return; + + for (i=0; ivalue, known_token_value) != 0) + { + Error(ERR_RETURN, "custom artwork configuration warning:"); + Error(ERR_RETURN, "- config file: '%s'", filename); + Error(ERR_RETURN, "- config token: '%s'", setup_file_list->token); + Error(ERR_WARN, "token not recognized"); + } + + setup_file_list = setup_file_list->next; + } + + freeSetupFileList(setup_file_list); +} +#endif + static void LoadArtworkConfig(struct ArtworkListInfo *artwork_info) { struct FileInfo *file_list = artwork_info->file_list; @@ -1474,6 +1608,7 @@ static void LoadArtworkConfig(struct ArtworkListInfo *artwork_info) int num_suffix_list_entries = artwork_info->num_suffix_list_entries; char *filename = getCustomArtworkConfigFilename(artwork_info->type); struct SetupFileList *setup_file_list; + char *known_token_value = "[KNOWN_TOKEN]"; int i, j; #if 0 @@ -1494,41 +1629,80 @@ static void LoadArtworkConfig(struct ArtworkListInfo *artwork_info) if (filename == NULL) return; - if ((setup_file_list = loadSetupFileList(filename))) + if ((setup_file_list = loadSetupFileList(filename)) == NULL) + return; + + for (i=0; i '%s'\n", file_list[i].filename); - else - printf("-> UNDEFINED [-> '%s']\n", file_list[i].default_filename); + if (strcmp(setup_file_list->value, known_token_value) != 0) + { + Error(ERR_RETURN, "custom artwork configuration warning:"); + Error(ERR_RETURN, "- config file: '%s'", filename); + Error(ERR_RETURN, "- config token: '%s'", setup_file_list->token); + Error(ERR_WARN, "token not recognized"); + } + + setup_file_list = setup_file_list->next; } -#endif } + + freeSetupFileList(setup_file_list); + +#if 0 + for (i=0; i '%s'\n", file_list[i].filename); + else + printf("-> UNDEFINED [-> '%s']\n", file_list[i].default_filename); + } +#endif } static void deleteArtworkListEntry(struct ArtworkListInfo *artwork_info, @@ -1711,6 +1885,9 @@ void ReloadCustomArtworkList(struct ArtworkListInfo *artwork_info) struct FileInfo *file_list = artwork_info->file_list; int i; +#if 0 + CheckArtworkConfig(artwork_info); +#endif LoadArtworkConfig(artwork_info); #if 0