From: Holger Schemel Date: Fri, 25 Apr 2003 00:01:03 +0000 (+0200) Subject: rnd-20030425-2-src X-Git-Tag: 3.0.0^2~82 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=0eaa7d33772143903b8a93abac8f1dce5422fa66;p=rocksndiamonds.git rnd-20030425-2-src --- diff --git a/src/conftime.h b/src/conftime.h index 3d1c12ce..a14a5fb5 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2003-04-25 00:20]" +#define COMPILE_DATE_STRING "[2003-04-25 01:16]" diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 11c0c185..10656e46 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -1884,11 +1884,7 @@ void LoadArtworkConfig(struct ArtworkListInfo *artwork_info) int num_ext3_suffixes = artwork_info->num_ext3_suffixes; int num_ignore_tokens = artwork_info->num_ignore_tokens; char *filename = getCustomArtworkConfigFilename(artwork_info->type); - SetupFileHash *setup_file_hash; - SetupFileHash *extra_file_hash = NULL; -#if 0 - SetupFileHash *list; -#endif + SetupFileHash *setup_file_hash, *extra_file_hash; char *known_token_value = KNOWN_TOKEN_VALUE; int i, j, k, l; @@ -1936,59 +1932,32 @@ void LoadArtworkConfig(struct ArtworkListInfo *artwork_info) if (filename == NULL) return; - printf("::: THIS 0\n"); - if ((setup_file_hash = loadSetupFileHash(filename)) == NULL) return; - printf("::: THIS 1 [%d]\n", num_file_list_entries); - /* read parameters for all known config file tokens */ for (i=0; inext) - { - if (strcmp(list->value, known_token_value) != 0) - { - if (extra_file_hash == NULL) - extra_file_hash = newSetupFileHash(list->token, list->value); - else - setHashEntry(extra_file_hash, list->token, list->value); - } - } -#else + extra_file_hash = newSetupFileHash(); BEGIN_HASH_ITERATION(setup_file_hash, itr) { if (strcmp(HASH_ITERATION_VALUE(itr), known_token_value) != 0) - { - if (extra_file_hash == NULL) - extra_file_hash = newSetupFileHash(); - setHashEntry(extra_file_hash, HASH_ITERATION_TOKEN(itr), HASH_ITERATION_VALUE(itr)); - } } END_HASH_ITERATION(setup_file_hash, itr) -#endif - /* at this point, we do not need the config file list anymore -- free it */ + /* at this point, we do not need the config file hash anymore -- free it */ freeSetupFileHash(setup_file_hash); /* now try to determine valid, dynamically defined config tokens */ -#if 0 - for (list = extra_file_hash; list != NULL; list = list->next) -#endif - BEGIN_HASH_ITERATION(extra_file_hash, itr) { struct FileInfo **dynamic_file_list = @@ -2204,12 +2173,12 @@ void LoadArtworkConfig(struct ArtworkListInfo *artwork_info) if (extra_file_hash != NULL && options.verbose && IS_PARENT_PROCESS()) { + SetupFileList *setup_file_list, *list; boolean dynamic_tokens_found = FALSE; boolean unknown_tokens_found = FALSE; -#if 0 - for (list = extra_file_hash; list != NULL; list = list->next) -#endif + if ((setup_file_list = loadSetupFileList(filename)) == NULL) + Error(ERR_EXIT, "loadSetupFileHash works, but loadSetupFileList fails"); BEGIN_HASH_ITERATION(extra_file_hash, itr) { @@ -2226,16 +2195,13 @@ void LoadArtworkConfig(struct ArtworkListInfo *artwork_info) Error(ERR_RETURN_LINE, "-"); Error(ERR_RETURN, "dynamic token(s) found:"); -#if 0 - for (list = extra_file_hash; list != NULL; list = list->next) -#endif - - BEGIN_HASH_ITERATION(extra_file_hash, itr) + for (list = setup_file_list; list != NULL; list = list->next) { - if (strcmp(HASH_ITERATION_VALUE(itr), known_token_value) == 0) - Error(ERR_RETURN, "- dynamic token: '%s'",HASH_ITERATION_TOKEN(itr)); + char *value = getHashEntry(extra_file_hash, list->token); + + if (value != NULL && strcmp(value, known_token_value) == 0) + Error(ERR_RETURN, "- dynamic token: '%s'", list->token); } - END_HASH_ITERATION(extra_file_hash, itr) Error(ERR_RETURN_LINE, "-"); } @@ -2247,19 +2213,18 @@ void LoadArtworkConfig(struct ArtworkListInfo *artwork_info) Error(ERR_RETURN, "warning: unknown token(s) found in config file:"); Error(ERR_RETURN, "- config file: '%s'", filename); -#if 0 - for (list = extra_file_hash; list != NULL; list = list->next) -#endif - - BEGIN_HASH_ITERATION(extra_file_hash, itr) + for (list = setup_file_list; list != NULL; list = list->next) { - if (strcmp(HASH_ITERATION_VALUE(itr), known_token_value) != 0) - Error(ERR_RETURN, "- unknown token: '%s'",HASH_ITERATION_TOKEN(itr)); + char *value = getHashEntry(extra_file_hash, list->token); + + if (value != NULL && strcmp(value, known_token_value) != 0) + Error(ERR_RETURN, "- dynamic token: '%s'", list->token); } - END_HASH_ITERATION(extra_file_hash, itr) Error(ERR_RETURN_LINE, "-"); } + + freeSetupFileList(setup_file_list); } freeSetupFileHash(extra_file_hash); diff --git a/src/libgame/setup.c b/src/libgame/setup.c index 940d6bad..1e9a56e2 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -1066,7 +1066,7 @@ SetupFileList *newSetupFileList(char *token, char *value) return new; } -char *getTokenValue(SetupFileList *list, char *token) +char *getListEntry(SetupFileList *list, char *token) { if (list == NULL) return NULL; @@ -1074,10 +1074,10 @@ char *getTokenValue(SetupFileList *list, char *token) if (strcmp(list->token, token) == 0) return list->value; else - return getTokenValue(list->next, token); + return getListEntry(list->next, token); } -void setTokenValue(SetupFileList *list, char *token, char *value) +void setListEntry(SetupFileList *list, char *token, char *value) { if (list == NULL) return; @@ -1092,7 +1092,7 @@ void setTokenValue(SetupFileList *list, char *token, char *value) else if (list->next == NULL) list->next = newSetupFileList(token, value); else - setTokenValue(list->next, token, value); + setListEntry(list->next, token, value); } #ifdef DEBUG @@ -1221,14 +1221,19 @@ static void printSetupFileHash(SetupFileHash *hash) #endif #endif -SetupFileHash *loadSetupFileHash(char *filename) +static void *loadSetupFileData(char *filename, boolean use_hash) { int line_len; char line[MAX_LINE_LEN]; char *token, *value, *line_ptr; - SetupFileHash *setup_file_hash = newSetupFileHash(); + void *setup_file_data; FILE *file; + if (use_hash) + setup_file_data = newSetupFileHash(); + else + setup_file_data = newSetupFileList("", ""); + if (!(file = fopen(filename, MODE_READ))) { Error(ERR_WARN, "cannot open configuration file '%s'", filename); @@ -1288,15 +1293,46 @@ SetupFileHash *loadSetupFileHash(char *filename) break; if (*token && *value) - setHashEntry(setup_file_hash, token, value); + { + if (use_hash) + setHashEntry((SetupFileHash *)setup_file_data, token, value); + else + setListEntry((SetupFileList *)setup_file_data, token, value); + } } fclose(file); - if (hashtable_count(setup_file_hash) == 0) - Error(ERR_WARN, "configuration file '%s' is empty", filename); + if (use_hash) + { + if (hashtable_count((SetupFileHash *)setup_file_data) == 0) + Error(ERR_WARN, "configuration file '%s' is empty", filename); + } + else + { + SetupFileList *setup_file_list = (SetupFileList *)setup_file_data; + SetupFileList *first_valid_list_entry = setup_file_list->next; + + /* free empty list header */ + setup_file_list->next = NULL; + freeSetupFileList(setup_file_list); + setup_file_data = first_valid_list_entry; + + if (first_valid_list_entry == NULL) + Error(ERR_WARN, "configuration file '%s' is empty", filename); + } + + return setup_file_data; +} + +SetupFileList *loadSetupFileList(char *filename) +{ + return (SetupFileList *)loadSetupFileData(filename, FALSE); +} - return setup_file_hash; +SetupFileHash *loadSetupFileHash(char *filename) +{ + return (SetupFileHash *)loadSetupFileData(filename, TRUE); } void checkSetupFileHashIdentifier(SetupFileHash *setup_file_hash, diff --git a/src/libgame/setup.h b/src/libgame/setup.h index d6c88b29..9b444033 100644 --- a/src/libgame/setup.h +++ b/src/libgame/setup.h @@ -231,6 +231,7 @@ void freeSetupFileList(struct SetupFileList *); struct SetupFileList *newSetupFileList(char *, char *); char *getListEntry(struct SetupFileList *, char *); void setListEntry(struct SetupFileList *, char *, char *); +SetupFileList *loadSetupFileList(char *); void freeSetupFileHash(SetupFileHash *); SetupFileHash *newSetupFileHash();