X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fmisc.c;h=6f6d68b3fa0831a50a2419ff83c0dfc0ae7023f8;hb=ee749a764df3dfa944c1f9de740ccbeb1cfdef40;hp=9b3f663352d5833598f6fc81885014758e5f05d5;hpb=891c39ca37c4fea5f6cc4ca40f913a56c68ef495;p=rocksndiamonds.git diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 9b3f6633..6f6d68b3 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -41,7 +41,7 @@ void fprintf_line(FILE *stream, char *line_string, int line_length) { int i; - for (i=0; i 2147483647) /* yes, this is a kludge */ + i = 2147483647; + + a = checked_malloc(10 + 1); + + sprintf(a, "%d", i); + + return a; +} + + +/* calculate base-2 logarithm of argument (rounded down to integer; + this function returns the number of the highest bit set in argument) */ + +int log_2(unsigned int x) +{ + int e = 0; + + while ((1 << e) < x) + { + x -= (1 << e); /* for rounding down (rounding up: remove this line) */ + e++; + } + + return e; +} + + /* ------------------------------------------------------------------------- */ /* counter functions */ /* ------------------------------------------------------------------------- */ @@ -167,14 +206,6 @@ static void sleep_milliseconds(unsigned long milliseconds_delay) { boolean do_busy_waiting = (milliseconds_delay < 5 ? TRUE : FALSE); -#if 0 -#if defined(PLATFORM_MSDOS) - /* don't use select() to perform waiting operations under DOS - environment; always use a busy loop for waiting instead */ - do_busy_waiting = TRUE; -#endif -#endif - if (do_busy_waiting) { /* we want to wait only a few ms -- if we assume that we have a @@ -243,7 +274,7 @@ void WaitUntilDelayReached(unsigned long *counter_var, unsigned long delay) { unsigned long actual_counter; - while(1) + while (1) { actual_counter = Counter(); @@ -262,48 +293,6 @@ void WaitUntilDelayReached(unsigned long *counter_var, unsigned long delay) /* random generator functions */ /* ------------------------------------------------------------------------- */ -#if 0 -unsigned int SimpleRND(unsigned int max) -{ - return (random_linux_libc(RND_FREE) % max); -} - -unsigned int InitSimpleRND(long seed) -{ - if (seed == NEW_RANDOMIZE) - { - struct timeval current_time; - - gettimeofday(¤t_time, NULL); - seed = (long)current_time.tv_usec; - } - - srandom_linux_libc(RND_FREE, (unsigned int) seed); - - return (unsigned int) seed; -} - -unsigned int RND(unsigned int max) -{ - return (random_linux_libc(RND_GAME) % max); -} - -unsigned int InitRND(long seed) -{ - if (seed == NEW_RANDOMIZE) - { - struct timeval current_time; - - gettimeofday(¤t_time, NULL); - seed = (long)current_time.tv_usec; - } - - srandom_linux_libc(RND_GAME, (unsigned int) seed); - - return (unsigned int) seed; -} -#endif - unsigned int init_random_number(int nr, long seed) { if (seed == NEW_RANDOMIZE) @@ -323,27 +312,10 @@ unsigned int init_random_number(int nr, long seed) return (unsigned int) seed; } -#if 1 -unsigned int get_random_number(int nr, unsigned int max) +unsigned int get_random_number(int nr, int max) { return (max > 0 ? random_linux_libc(nr) % max : 0); } -#else -unsigned int get_random_number(int nr, unsigned int max) -{ - unsigned int rnd = (max > 0 ? random_linux_libc(nr) % max : 0); - - if (nr == 0 && FrameCounter < 2) - printf("::: %d [%d]\n", rnd, FrameCounter); - -#if 0 - if (nr == 0 && FrameCounter < 2 && rnd == 8) - rnd /= 0; -#endif - - return rnd; -} -#endif /* ------------------------------------------------------------------------- */ @@ -357,26 +329,24 @@ static char *get_corrected_real_name(char *real_name) char *from_ptr = real_name; char *to_ptr = real_name_new; - if (strchr(real_name, 'ß') == NULL) /* name does not contain 'ß' */ - { - strncpy(real_name_new, real_name, MAX_USERNAME_LEN); - real_name_new[MAX_USERNAME_LEN] = '\0'; - - return real_name_new; - } - - /* the user's real name may contain a 'ß' character (german sharp s), - which has no equivalent in upper case letters (which our fonts use) */ + /* copy the name string, but not more than MAX_USERNAME_LEN characters */ while (*from_ptr && (long)(to_ptr - real_name_new) < MAX_USERNAME_LEN - 1) { - if (*from_ptr != 'ß') - *to_ptr++ = *from_ptr++; - else + /* the name field read from "passwd" file may also contain additional + user information, separated by commas, which will be removed here */ + if (*from_ptr == ',') + break; + + /* the user's real name may contain 'ß' characters (german sharp s), + which have no equivalent in upper case letters (used by our fonts) */ + if (*from_ptr == 'ß') { from_ptr++; *to_ptr++ = 's'; *to_ptr++ = 's'; } + else + *to_ptr++ = *from_ptr++; } *to_ptr = '\0'; @@ -478,6 +448,51 @@ char *getHomeDir() } +/* ------------------------------------------------------------------------- */ +/* path manipulation functions */ +/* ------------------------------------------------------------------------- */ + +static char *getLastPathSeparatorPtr(char *filename) +{ + char *last_separator = strrchr(filename, '/'); + +#if !defined(PLATFORM_UNIX) + if (last_separator == NULL) /* also try DOS/Windows variant */ + last_separator = strrchr(filename, '\\'); +#endif + + return last_separator; +} + +static char *getBaseNamePtr(char *filename) +{ + char *last_separator = getLastPathSeparatorPtr(filename); + + if (last_separator != NULL) + return last_separator + 1; /* separator found: strip base path */ + else + return filename; /* no separator found: filename has no path */ +} + +char *getBaseName(char *filename) +{ + return getStringCopy(getBaseNamePtr(filename)); +} + +char *getBasePath(char *filename) +{ + char *basepath = getStringCopy(filename); + char *last_separator = getLastPathSeparatorPtr(basepath); + + if (last_separator != NULL) + *last_separator = '\0'; /* separator found: strip basename */ + else + basepath = "."; /* no separator found: use current path */ + + return basepath; +} + + /* ------------------------------------------------------------------------- */ /* various string functions */ /* ------------------------------------------------------------------------- */ @@ -539,8 +554,7 @@ char *getStringToLower(char *s) void setString(char **old_value, char *new_value) { - if (*old_value != NULL) - free(*old_value); + checked_free(*old_value); *old_value = getStringCopy(new_value); } @@ -552,19 +566,34 @@ void setString(char **old_value, char *new_value) void GetOptions(char *argv[], void (*print_usage_function)(void)) { + char *ro_base_path = RO_BASE_PATH; + char *rw_base_path = RW_BASE_PATH; char **options_left = &argv[1]; +#if !defined(PLATFORM_MACOSX) + /* if the program is configured to start from current directory (default), + determine program package directory (KDE/Konqueror does not do this by + itself and fails otherwise); on Mac OS X, the program binary is stored + in an application package directory -- do not try to use this directory + as the program data directory (Mac OS X handles this correctly anyway) */ + + if (strcmp(ro_base_path, ".") == 0) + ro_base_path = program.command_basepath; + if (strcmp(rw_base_path, ".") == 0) + rw_base_path = program.command_basepath; +#endif + /* initialize global program options */ options.display_name = NULL; options.server_host = NULL; options.server_port = 0; - options.ro_base_directory = RO_BASE_PATH; - options.rw_base_directory = RW_BASE_PATH; - options.level_directory = RO_BASE_PATH "/" LEVELS_DIRECTORY; - options.graphics_directory = RO_BASE_PATH "/" GRAPHICS_DIRECTORY; - options.sounds_directory = RO_BASE_PATH "/" SOUNDS_DIRECTORY; - options.music_directory = RO_BASE_PATH "/" MUSIC_DIRECTORY; - options.docs_directory = RO_BASE_PATH "/" DOCS_DIRECTORY; + options.ro_base_directory = ro_base_path; + options.rw_base_directory = rw_base_path; + options.level_directory = getPath2(ro_base_path, LEVELS_DIRECTORY); + options.graphics_directory = getPath2(ro_base_path, GRAPHICS_DIRECTORY); + options.sounds_directory = getPath2(ro_base_path, SOUNDS_DIRECTORY); + options.music_directory = getPath2(ro_base_path, MUSIC_DIRECTORY); + options.docs_directory = getPath2(ro_base_path, DOCS_DIRECTORY); options.execute_command = NULL; options.serveronly = FALSE; options.network = FALSE; @@ -631,14 +660,17 @@ void GetOptions(char *argv[], void (*print_usage_function)(void)) Error(ERR_EXIT_HELP, "option '%s' requires an argument", option_str); /* this should be extended to separate options for ro and rw data */ - options.ro_base_directory = option_arg; - options.rw_base_directory = option_arg; + options.ro_base_directory = ro_base_path = option_arg; + options.rw_base_directory = rw_base_path = option_arg; if (option_arg == next_option) options_left++; - /* adjust path for level directory accordingly */ - options.level_directory = - getPath2(options.ro_base_directory, LEVELS_DIRECTORY); + /* adjust paths for sub-directories in base directory accordingly */ + options.level_directory = getPath2(ro_base_path, LEVELS_DIRECTORY); + options.graphics_directory = getPath2(ro_base_path, GRAPHICS_DIRECTORY); + options.sounds_directory = getPath2(ro_base_path, SOUNDS_DIRECTORY); + options.music_directory = getPath2(ro_base_path, MUSIC_DIRECTORY); + options.docs_directory = getPath2(ro_base_path, DOCS_DIRECTORY); } else if (strncmp(option, "-levels", option_len) == 0) { @@ -700,6 +732,9 @@ void GetOptions(char *argv[], void (*print_usage_function)(void)) options.execute_command = option_arg; if (option_arg == next_option) options_left++; + + /* when doing batch processing, always enable verbose mode (warnings) */ + options.verbose = TRUE; } else if (*option == '-') { @@ -822,7 +857,7 @@ void Error(int mode, char *format, ...) /* ------------------------------------------------------------------------- */ -/* memory allocation functions */ +/* checked memory allocation and freeing functions */ /* ------------------------------------------------------------------------- */ void *checked_malloc(unsigned long size) @@ -859,6 +894,12 @@ void *checked_realloc(void *ptr, unsigned long size) return ptr; } +void checked_free(void *ptr) +{ + if (ptr != NULL) /* this check should be done by free() anyway */ + free(ptr); +} + /* ------------------------------------------------------------------------- */ /* various helper functions */ @@ -884,27 +925,27 @@ inline void swap_number_pairs(int *x1, int *y1, int *x2, int *y2) *y2 = help_y; } -short getFile16BitInteger(FILE *file, int byte_order) +int getFile16BitInteger(FILE *file, int byte_order) { if (byte_order == BYTE_ORDER_BIG_ENDIAN) - return ((fgetc(file) << 8) | - (fgetc(file) << 0)); + return ((fgetc(file) << 8) | + (fgetc(file) << 0)); else /* BYTE_ORDER_LITTLE_ENDIAN */ - return ((fgetc(file) << 0) | - (fgetc(file) << 8)); + return ((fgetc(file) << 0) | + (fgetc(file) << 8)); } -void putFile16BitInteger(FILE *file, short value, int byte_order) +void putFile16BitInteger(FILE *file, int value, int byte_order) { if (byte_order == BYTE_ORDER_BIG_ENDIAN) { - fputc((value >> 8) & 0xff, file); - fputc((value >> 0) & 0xff, file); + fputc((value >> 8) & 0xff, file); + fputc((value >> 0) & 0xff, file); } else /* BYTE_ORDER_LITTLE_ENDIAN */ { - fputc((value >> 0) & 0xff, file); - fputc((value >> 8) & 0xff, file); + fputc((value >> 0) & 0xff, file); + fputc((value >> 8) & 0xff, file); } } @@ -1242,7 +1283,7 @@ void translate_keyname(Key *keysym, char **x11name, char **name, int mode) char c = name_ptr[6]; if (c >= '0' && c <= '9') - key = KSYM_0 + (Key)(c - '0'); + key = KSYM_KP_0 + (Key)(c - '0'); } else if (strncmp(name_ptr, "XK_F", 4) == 0 && strlen(name_ptr) <= 6) { @@ -1383,8 +1424,8 @@ int get_integer_from_string(char *s) char *s_lower = getStringToLower(s); int result = -1; - for (i=0; number_text[i][0] != NULL; i++) - for (j=0; j < 3; j++) + for (i = 0; number_text[i][0] != NULL; i++) + for (j = 0; j < 3; j++) if (strcmp(s_lower, number_text[i][j]) == 0) result = i; @@ -1433,10 +1474,6 @@ void addNodeToList(ListNode **node_first, char *key, void *content) { ListNode *node_new = newListNode(); -#if 0 - printf("LIST: adding node with key '%s'\n", key); -#endif - node_new->key = getStringCopy(key); node_new->content = content; node_new->next = *node_first; @@ -1449,17 +1486,8 @@ void deleteNodeFromList(ListNode **node_first, char *key, if (node_first == NULL || *node_first == NULL) return; -#if 0 - printf("[CHECKING LIST KEY '%s' == '%s']\n", - (*node_first)->key, key); -#endif - if (strcmp((*node_first)->key, key) == 0) { -#if 0 - printf("[DELETING LIST ENTRY]\n"); -#endif - free((*node_first)->key); if (destructor_function) destructor_function((*node_first)->content); @@ -1506,9 +1534,8 @@ void dumpList(ListNode *node_first) boolean fileExists(char *filename) { -#if 0 - printf("checking file '%s'\n", filename); -#endif + if (filename == NULL) + return FALSE; return (access(filename, F_OK) == 0); } @@ -1518,8 +1545,7 @@ boolean fileHasPrefix(char *basename, char *prefix) static char *basename_lower = NULL; int basename_length, prefix_length; - if (basename_lower != NULL) - free(basename_lower); + checked_free(basename_lower); if (basename == NULL || prefix == NULL) return FALSE; @@ -1541,8 +1567,7 @@ boolean fileHasSuffix(char *basename, char *suffix) static char *basename_lower = NULL; int basename_length, suffix_length; - if (basename_lower != NULL) - free(basename_lower); + checked_free(basename_lower); if (basename == NULL || suffix == NULL) return FALSE; @@ -1559,18 +1584,24 @@ boolean fileHasSuffix(char *basename, char *suffix) return FALSE; } -boolean FileIsGraphic(char *basename) +boolean FileIsGraphic(char *filename) { + char *basename = getBaseNamePtr(filename); + return fileHasSuffix(basename, "pcx"); } -boolean FileIsSound(char *basename) +boolean FileIsSound(char *filename) { + char *basename = getBaseNamePtr(filename); + return fileHasSuffix(basename, "wav"); } -boolean FileIsMusic(char *basename) +boolean FileIsMusic(char *filename) { + char *basename = getBaseNamePtr(filename); + if (FileIsSound(basename)) return TRUE; @@ -1604,6 +1635,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 . */ @@ -1699,7 +1751,7 @@ static void FreeCustomArtworkList(struct ArtworkListInfo *, struct ListNodeInfo ***, int *); struct FileInfo *getFileListFromConfigList(struct ConfigInfo *config_list, - struct ConfigInfo *suffix_list, + struct ConfigTypeInfo *suffix_list, char **ignore_tokens, int num_file_list_entries) { @@ -1711,11 +1763,11 @@ struct FileInfo *getFileListFromConfigList(struct ConfigInfo *config_list, file_list = checked_calloc(num_file_list_entries * sizeof(struct FileInfo)); - for (i=0; suffix_list[i].token != NULL; i++) + for (i = 0; suffix_list[i].token != NULL; i++) num_suffix_list_entries++; /* always start with reliable default values */ - for (i=0; ifilename, filename); /* when file definition found, set all parameters to default values */ - for (i=0; suffix_list[i].token != NULL; i++) + for (i = 0; suffix_list[i].token != NULL; i++) setString(&file_list_entry->parameter[i], suffix_list[i].value); file_list_entry->redefined = TRUE; @@ -1855,19 +1905,9 @@ static void read_token_parameters(SetupFileHash *setup_file_hash, /* mark config file token as well known from default config */ setHashEntry(setup_file_hash, file_list_entry->token, known_token_value); } -#if 0 - else - { - if (strcmp(file_list_entry->filename, - file_list_entry->default_filename) != 0) - printf("___ resetting '%s' to default\n", file_list_entry->token); - - setString(&file_list_entry->filename, file_list_entry->default_filename); - } -#endif /* check for config tokens that can be build by base token and suffixes */ - for (i=0; suffix_list[i].token != NULL; i++) + for (i = 0; suffix_list[i].token != NULL; i++) { char *token = getStringCat2(file_list_entry->token, suffix_list[i].token); char *value = getHashEntry(setup_file_hash, token); @@ -1887,26 +1927,25 @@ static void read_token_parameters(SetupFileHash *setup_file_hash, static void add_dynamic_file_list_entry(struct FileInfo **list, int *num_list_entries, SetupFileHash *extra_file_hash, - struct ConfigInfo *suffix_list, + struct ConfigTypeInfo *suffix_list, int num_suffix_list_entries, char *token) { struct FileInfo *new_list_entry; int parameter_array_size = num_suffix_list_entries * sizeof(char *); -#if 0 - if (IS_PARENT_PROCESS()) - printf("===> found dynamic definition '%s'\n", token); -#endif - (*num_list_entries)++; *list = checked_realloc(*list, *num_list_entries * sizeof(struct FileInfo)); new_list_entry = &(*list)[*num_list_entries - 1]; new_list_entry->token = getStringCopy(token); + new_list_entry->default_filename = NULL; new_list_entry->filename = NULL; new_list_entry->parameter = checked_calloc(parameter_array_size); + new_list_entry->redefined = FALSE; + new_list_entry->fallback_to_default = FALSE; + read_token_parameters(extra_file_hash, suffix_list, new_list_entry); } @@ -1935,7 +1974,7 @@ static void LoadArtworkConfigFromFilename(struct ArtworkListInfo *artwork_info, char *filename) { struct FileInfo *file_list = artwork_info->file_list; - struct ConfigInfo *suffix_list = artwork_info->suffix_list; + struct ConfigTypeInfo *suffix_list = artwork_info->suffix_list; char **base_prefixes = artwork_info->base_prefixes; char **ext1_suffixes = artwork_info->ext1_suffixes; char **ext2_suffixes = artwork_info->ext2_suffixes; @@ -1948,40 +1987,74 @@ static void LoadArtworkConfigFromFilename(struct ArtworkListInfo *artwork_info, int num_ext2_suffixes = artwork_info->num_ext2_suffixes; int num_ext3_suffixes = artwork_info->num_ext3_suffixes; int num_ignore_tokens = artwork_info->num_ignore_tokens; - SetupFileHash *setup_file_hash, *extra_file_hash; + SetupFileHash *setup_file_hash, *valid_file_hash; + SetupFileHash *extra_file_hash, *empty_file_hash; char *known_token_value = KNOWN_TOKEN_VALUE; int i, j, k, l; if (filename == NULL) return; -#if 0 - printf("::: LoadArtworkConfigFromFilename: '%s'\n", filename); -#endif - if ((setup_file_hash = loadSetupFileHash(filename)) == NULL) return; + /* separate valid (defined) from empty (undefined) config token values */ + valid_file_hash = newSetupFileHash(); + empty_file_hash = newSetupFileHash(); + BEGIN_HASH_ITERATION(setup_file_hash, itr) + { + char *value = HASH_ITERATION_VALUE(itr); + + setHashEntry(*value ? valid_file_hash : empty_file_hash, + HASH_ITERATION_TOKEN(itr), value); + } + END_HASH_ITERATION(setup_file_hash, itr) + + /* at this point, we do not need the setup file hash anymore -- free it */ + freeSetupFileHash(setup_file_hash); + + /* map deprecated to current tokens (using prefix match and replace) */ + BEGIN_HASH_ITERATION(valid_file_hash, itr) + { + char *token = HASH_ITERATION_TOKEN(itr); + char *mapped_token = get_mapped_token(token); + + if (mapped_token != NULL) + { + char *value = HASH_ITERATION_VALUE(itr); + + /* add mapped token */ + setHashEntry(valid_file_hash, mapped_token, value); + + /* ignore old token (by setting it to "known" keyword) */ + setHashEntry(valid_file_hash, token, known_token_value); + + free(mapped_token); + } + } + END_HASH_ITERATION(valid_file_hash, itr) + /* read parameters for all known config file tokens */ - for (i=0; i '%s'\n", token, HASH_ITERATION_VALUE(itr)); +#endif + /* skip all parameter definitions (handled by read_token_parameters()) */ - for (i=0; i < num_suffix_list_entries && !parameter_suffix_found; i++) + for (i = 0; i < num_suffix_list_entries && !parameter_suffix_found; i++) { int len_suffix = strlen(suffix_list[i].token); @@ -2013,23 +2090,13 @@ static void LoadArtworkConfigFromFilename(struct ArtworkListInfo *artwork_info, parameter_suffix_found = TRUE; } -#if 0 - if (IS_PARENT_PROCESS()) - { - if (parameter_suffix_found) - printf("---> skipping token '%s' (parameter token)\n", token); - else - printf("---> examining token '%s': search prefix ...\n", token); - } -#endif - if (parameter_suffix_found) continue; /* ---------- step 0: search for matching base prefix ---------- */ start_pos = 0; - for (i=0; i < num_base_prefixes && !base_prefix_found; i++) + for (i = 0; i < num_base_prefixes && !base_prefix_found; i++) { char *base_prefix = base_prefixes[i]; int len_base_prefix = strlen(base_prefix); @@ -2074,7 +2141,7 @@ static void LoadArtworkConfigFromFilename(struct ArtworkListInfo *artwork_info, /* ---------- step 1: search for matching first suffix ---------- */ start_pos += len_base_prefix; - for (j=0; j < num_ext1_suffixes && !ext1_suffix_found; j++) + for (j = 0; j < num_ext1_suffixes && !ext1_suffix_found; j++) { char *ext1_suffix = ext1_suffixes[j]; int len_ext1_suffix = strlen(ext1_suffix); @@ -2116,7 +2183,7 @@ static void LoadArtworkConfigFromFilename(struct ArtworkListInfo *artwork_info, /* ---------- step 2: search for matching second suffix ---------- */ - for (k=0; k < num_ext2_suffixes && !ext2_suffix_found; k++) + for (k = 0; k < num_ext2_suffixes && !ext2_suffix_found; k++) { char *ext2_suffix = ext2_suffixes[k]; int len_ext2_suffix = strlen(ext2_suffix); @@ -2158,7 +2225,7 @@ static void LoadArtworkConfigFromFilename(struct ArtworkListInfo *artwork_info, /* ---------- step 3: search for matching third suffix ---------- */ - for (l=0; l < num_ext3_suffixes && !ext3_suffix_found; l++) + for (l = 0; l < num_ext3_suffixes && !ext3_suffix_found; l++) { char *ext3_suffix = ext3_suffixes[l]; int len_ext3_suffix = strlen(ext3_suffix); @@ -2198,11 +2265,12 @@ static void LoadArtworkConfigFromFilename(struct ArtworkListInfo *artwork_info, artwork_info->sizeof_artwork_list_entry); } - if (extra_file_hash != NULL && options.verbose && IS_PARENT_PROCESS()) + if (options.verbose && IS_PARENT_PROCESS()) { SetupFileList *setup_file_list, *list; boolean dynamic_tokens_found = FALSE; boolean unknown_tokens_found = FALSE; + boolean undefined_values_found = (hashtable_count(empty_file_hash) != 0); if ((setup_file_list = loadSetupFileList(filename)) == NULL) Error(ERR_EXIT, "loadSetupFileHash works, but loadSetupFileList fails"); @@ -2250,13 +2318,31 @@ static void LoadArtworkConfigFromFilename(struct ArtworkListInfo *artwork_info, Error(ERR_RETURN_LINE, "-"); } + if (undefined_values_found) + { + Error(ERR_RETURN_LINE, "-"); + Error(ERR_RETURN, "warning: undefined values found in config file:"); + Error(ERR_RETURN, "- config file: '%s'", filename); + + for (list = setup_file_list; list != NULL; list = list->next) + { + char *value = getHashEntry(empty_file_hash, list->token); + + if (value != NULL) + Error(ERR_RETURN, "- undefined value for token: '%s'", list->token); + } + + Error(ERR_RETURN_LINE, "-"); + } + freeSetupFileList(setup_file_list); } freeSetupFileHash(extra_file_hash); + freeSetupFileHash(empty_file_hash); #if 0 - for (i=0; itype), 150, FC_YELLOW); /* always start with reliable default values */ - for (i=0; idynamic_file_list != NULL) { - for (i=0; inum_dynamic_file_list_entries; i++) + for (i = 0; i < artwork_info->num_dynamic_file_list_entries; i++) { free(artwork_info->dynamic_file_list[i].token); free(artwork_info->dynamic_file_list[i].filename); @@ -2341,19 +2428,9 @@ static void deleteArtworkListEntry(struct ArtworkListInfo *artwork_info, { char *filename = (*listnode)->source_filename; -#if 0 - printf("[decrementing reference counter of artwork '%s']\n", filename); -#endif - if (--(*listnode)->num_references <= 0) - { -#if 0 - printf("[deleting artwork '%s']\n", filename); -#endif - deleteNodeFromList(&artwork_info->content_list, filename, artwork_info->free_artwork); - } *listnode = NULL; } @@ -2361,7 +2438,7 @@ static void deleteArtworkListEntry(struct ArtworkListInfo *artwork_info, static void replaceArtworkListEntry(struct ArtworkListInfo *artwork_info, struct ListNodeInfo **listnode, - char *basename) + struct FileInfo *file_list_entry) { char *init_text[] = { @@ -2371,20 +2448,37 @@ static void replaceArtworkListEntry(struct ArtworkListInfo *artwork_info, }; ListNode *node; + char *basename = file_list_entry->filename; char *filename = getCustomArtworkFilename(basename, artwork_info->type); if (filename == NULL) { - int error_mode = ERR_WARN; + Error(ERR_WARN, "cannot find artwork file '%s'", basename); -#if 1 - /* we can get away without sounds and music, but not without graphics */ - if (*listnode == NULL && artwork_info->type == ARTWORK_TYPE_GRAPHICS) - error_mode = ERR_EXIT; -#endif + basename = file_list_entry->default_filename; - Error(error_mode, "cannot find artwork file '%s'", basename); - return; + /* dynamic artwork has no default filename / skip empty default artwork */ + if (basename == NULL || strcmp(basename, UNDEFINED_FILENAME) == 0) + return; + + file_list_entry->fallback_to_default = TRUE; + + Error(ERR_WARN, "trying default artwork file '%s'", basename); + + filename = getCustomArtworkFilename(basename, artwork_info->type); + + if (filename == NULL) + { + int error_mode = ERR_WARN; + + /* we can get away without sounds and music, but not without graphics */ + if (*listnode == NULL && artwork_info->type == ARTWORK_TYPE_GRAPHICS) + error_mode = ERR_EXIT; + + Error(error_mode, "cannot find default artwork file '%s'", basename); + + return; + } } /* check if the old and the new artwork file are the same */ @@ -2417,10 +2511,6 @@ static void replaceArtworkListEntry(struct ArtworkListInfo *artwork_info, return; } -#if 0 - printf("::: %s: '%s'\n", init_text[artwork_info->type], basename); -#endif - DrawInitText(init_text[artwork_info->type], 120, FC_GREEN); DrawInitText(basename, 150, FC_YELLOW); @@ -2438,11 +2528,9 @@ static void replaceArtworkListEntry(struct ArtworkListInfo *artwork_info, { int error_mode = ERR_WARN; -#if 1 /* we can get away without sounds and music, but not without graphics */ if (artwork_info->type == ARTWORK_TYPE_GRAPHICS) error_mode = ERR_EXIT; -#endif Error(error_mode, "cannot load artwork file '%s'", basename); return; @@ -2451,47 +2539,19 @@ static void replaceArtworkListEntry(struct ArtworkListInfo *artwork_info, static void LoadCustomArtwork(struct ArtworkListInfo *artwork_info, struct ListNodeInfo **listnode, - char *basename) + struct FileInfo *file_list_entry) { #if 0 printf("GOT CUSTOM ARTWORK FILE '%s'\n", filename); #endif - if (strcmp(basename, UNDEFINED_FILENAME) == 0) + if (strcmp(file_list_entry->filename, UNDEFINED_FILENAME) == 0) { deleteArtworkListEntry(artwork_info, listnode); return; } - replaceArtworkListEntry(artwork_info, listnode, basename); -} - -static void LoadArtworkToList(struct ArtworkListInfo *artwork_info, - struct ListNodeInfo **listnode, - char *basename, int list_pos) -{ -#if 0 - if (artwork_info->artwork_list == NULL || - list_pos >= artwork_info->num_file_list_entries) - return; -#endif - -#if 0 - printf("loading artwork '%s' ... [%d]\n", - basename, getNumNodes(artwork_info->content_list)); -#endif - -#if 1 - LoadCustomArtwork(artwork_info, listnode, basename); -#else - LoadCustomArtwork(artwork_info, &artwork_info->artwork_list[list_pos], - basename); -#endif - -#if 0 - printf("loading artwork '%s' done [%d]\n", - basename, getNumNodes(artwork_info->content_list)); -#endif + replaceArtworkListEntry(artwork_info, listnode, file_list_entry); } void ReloadCustomArtworkList(struct ArtworkListInfo *artwork_info) @@ -2503,42 +2563,13 @@ void ReloadCustomArtworkList(struct ArtworkListInfo *artwork_info) artwork_info->num_dynamic_file_list_entries; int i; -#if 0 - printf("DEBUG: reloading %d static artwork files ...\n", - num_file_list_entries); -#endif - - for(i=0; i '%s'\n", file_list[i].token, file_list[i].filename); -#endif + for (i = 0; i < num_file_list_entries; i++) + LoadCustomArtwork(artwork_info, &artwork_info->artwork_list[i], + &file_list[i]); - LoadArtworkToList(artwork_info, &artwork_info->artwork_list[i], - file_list[i].filename, i); - -#if 0 - if (artwork_info->artwork_list[i] == NULL && - strcmp(file_list[i].default_filename, file_list[i].filename) != 0) - { - Error(ERR_WARN, "trying default artwork file '%s'", - file_list[i].default_filename); - - LoadArtworkToList(artwork_info, &artwork_info->artwork_list[i], - file_list[i].default_filename, i); - } -#endif - } - -#if 0 - printf("DEBUG: reloading %d dynamic artwork files ...\n", - num_dynamic_file_list_entries); -#endif - - for(i=0; idynamic_artwork_list[i], - dynamic_file_list[i].filename, i); + for (i = 0; i < num_dynamic_file_list_entries; i++) + LoadCustomArtwork(artwork_info, &artwork_info->dynamic_artwork_list[i], + &dynamic_file_list[i]); #if 0 dumpList(artwork_info->content_list); @@ -2554,7 +2585,7 @@ static void FreeCustomArtworkList(struct ArtworkListInfo *artwork_info, if (*list == NULL) return; - for(i=0; i<*num_list_entries; i++) + for (i = 0; i < *num_list_entries; i++) deleteArtworkListEntry(artwork_info, &(*list)[i]); free(*list); @@ -2567,21 +2598,11 @@ void FreeCustomArtworkLists(struct ArtworkListInfo *artwork_info) if (artwork_info == NULL) return; -#if 0 - printf("%s: FREEING ARTWORK ...\n", - IS_CHILD_PROCESS() ? "CHILD" : "PARENT"); -#endif - FreeCustomArtworkList(artwork_info, &artwork_info->artwork_list, &artwork_info->num_file_list_entries); FreeCustomArtworkList(artwork_info, &artwork_info->dynamic_artwork_list, &artwork_info->num_dynamic_file_list_entries); - -#if 0 - printf("%s: FREEING ARTWORK -- DONE\n", - IS_CHILD_PROCESS() ? "CHILD" : "PARENT"); -#endif }