X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Flibgame%2Fmisc.c;h=59a273e15b6607f5d771123bfec43ca98cfeb2a0;hp=2a132858f3653e725cdd27160197d5a91b1b2717;hb=51dcb2097c619c5f9ba924a7edb4a3bdd6a6986e;hpb=4fe9164460ddbdc1077604bac5c418f02fd8fa2b diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 2a132858..59a273e1 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -1615,6 +1615,27 @@ boolean FileIsArtworkType(char *basename, int type) /* functions for loading artwork configuration information */ /* ------------------------------------------------------------------------- */ +char *get_mapped_token(char *token) +{ + /* !!! make this dynamically configurable (init.c:InitArtworkConfig) !!! */ + static char *map_token_prefix[][2] = + { + { "char_procent", "char_percent" }, + { NULL, } + }; + int i; + + for (i = 0; map_token_prefix[i][0] != NULL; i++) + { + int len_token_prefix = strlen(map_token_prefix[i][0]); + + if (strncmp(token, map_token_prefix[i][0], len_token_prefix) == 0) + return getStringCat2(map_token_prefix[i][1], &token[len_token_prefix]); + } + + return NULL; +} + /* This function checks if a string of the format "string1, string2, ..." exactly contains a string . */ @@ -2000,34 +2021,20 @@ static void LoadArtworkConfigFromFilename(struct ArtworkListInfo *artwork_info, /* map deprecated to current tokens (using prefix match and replace) */ BEGIN_HASH_ITERATION(valid_file_hash, itr) { - /* !!! make this dynamically configurable (init.c:InitArtworkConfig) !!! */ - static char *map_token_prefix[][2] = - { /* old prefix -> new prefix */ - { "char_procent", "char_percent" }, - { NULL, NULL } - }; char *token = HASH_ITERATION_TOKEN(itr); + char *mapped_token = get_mapped_token(token); - for (i = 0; map_token_prefix[i][0] != NULL; i++) + if (mapped_token != NULL) { - int token_prefix_length = strlen(map_token_prefix[i][0]); - - if (strncmp(token, map_token_prefix[i][0], token_prefix_length) == 0) - { - char *value = HASH_ITERATION_VALUE(itr); - char *mapped_token = getStringCat2(map_token_prefix[i][1], - &token[token_prefix_length]); - - /* add mapped token */ - setHashEntry(valid_file_hash, mapped_token, value); + char *value = HASH_ITERATION_VALUE(itr); - /* ignore old token (by setting it to "known" keyword) */ - setHashEntry(valid_file_hash, token, known_token_value); + /* add mapped token */ + setHashEntry(valid_file_hash, mapped_token, value); - free(mapped_token); + /* ignore old token (by setting it to "known" keyword) */ + setHashEntry(valid_file_hash, token, known_token_value); - break; - } + free(mapped_token); } } END_HASH_ITERATION(valid_file_hash, itr)