X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fsetup.c;h=bc8a1a34740bb1b31ab92b928dfba63cffa8b8b4;hb=9f7cd608c28ded86b2c2e649c776220ae27df038;hp=985c160a245b9f3b16f33ecedb2e9a79b4c99c9c;hpb=04cfb5daeff6cbceef152fc01ad5852407c0c918;p=rocksndiamonds.git diff --git a/src/libgame/setup.c b/src/libgame/setup.c index 985c160a..bc8a1a34 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -1609,11 +1609,15 @@ static void printSetupFileHash(SetupFileHash *hash) #define ALLOW_TOKEN_VALUE_SEPARATOR_BEING_WHITESPACE 1 #define CHECK_TOKEN_VALUE_SEPARATOR__WARN_IF_MISSING 0 +#define CHECK_TOKEN__WARN_IF_ALREADY_EXISTS_IN_HASH 0 static boolean token_value_separator_found = FALSE; #if CHECK_TOKEN_VALUE_SEPARATOR__WARN_IF_MISSING static boolean token_value_separator_warning = FALSE; #endif +#if CHECK_TOKEN__WARN_IF_ALREADY_EXISTS_IN_HASH +static boolean token_already_exists_warning = FALSE; +#endif static boolean getTokenValueFromSetupLineExt(char *line, char **token_ptr, char **value_ptr, @@ -1776,6 +1780,10 @@ static boolean loadSetupFileData(void *setup_file_data, char *filename, token_value_separator_warning = FALSE; #endif +#if CHECK_TOKEN__WARN_IF_ALREADY_EXISTS_IN_HASH + token_already_exists_warning = FALSE; +#endif + if (!(file = fopen(filename, MODE_READ))) { Error(ERR_WARN, "cannot open configuration file '%s'", filename); @@ -1874,9 +1882,34 @@ static boolean loadSetupFileData(void *setup_file_data, char *filename, else { if (is_hash) + { +#if CHECK_TOKEN__WARN_IF_ALREADY_EXISTS_IN_HASH + char *old_value = + getHashEntry((SetupFileHash *)setup_file_data, token); + + if (old_value != NULL) + { + if (!token_already_exists_warning) + { + Error(ERR_INFO_LINE, "-"); + Error(ERR_WARN, "duplicate token(s) found in config file:"); + Error(ERR_INFO, "- config file: '%s'", filename); + + token_already_exists_warning = TRUE; + } + + Error(ERR_INFO, "- token: '%s' (in line %d)", token, line_nr); + Error(ERR_INFO, " old value: '%s'", old_value); + Error(ERR_INFO, " new value: '%s'", value); + } +#endif + setHashEntry((SetupFileHash *)setup_file_data, token, value); + } else + { insert_ptr = addListEntry((SetupFileList *)insert_ptr, token, value); + } token_count++; } @@ -1890,6 +1923,11 @@ static boolean loadSetupFileData(void *setup_file_data, char *filename, Error(ERR_INFO_LINE, "-"); #endif +#if CHECK_TOKEN__WARN_IF_ALREADY_EXISTS_IN_HASH + if (token_already_exists_warning) + Error(ERR_INFO_LINE, "-"); +#endif + if (token_count == 0) Error(ERR_WARN, "configuration file '%s' is empty", filename);