+ int len_token = strlen(token);
+ int len_suffix = strlen(suffix);
+
+ if (start_pos < 0) /* compare suffix from end of string */
+ start_pos += len_token;
+
+ if (start_pos < 0 || start_pos + len_suffix > len_token)
+ return FALSE;
+
+ if (strncmp(&token[start_pos], suffix, len_suffix) != 0)
+ return FALSE;
+
+ if (token[start_pos + len_suffix] == '\0')
+ return TRUE;
+
+ if (token[start_pos + len_suffix] == '.')
+ return TRUE;
+
+ return FALSE;
+}
+
+#define KNOWN_TOKEN_VALUE "[KNOWN_TOKEN_VALUE]"
+
+static void read_token_parameters(SetupFileHash *setup_file_hash,
+ struct ConfigTypeInfo *suffix_list,
+ struct FileInfo *file_list_entry)
+{
+ /* check for config token that is the base token without any suffixes */
+ char *filename = getHashEntry(setup_file_hash, file_list_entry->token);
+ char *known_token_value = KNOWN_TOKEN_VALUE;
+ int i;
+
+ if (filename != NULL)
+ {
+ setString(&file_list_entry->filename, filename);
+
+ /* when file definition found, set all parameters to default values */
+ for (i = 0; suffix_list[i].token != NULL; i++)
+ setString(&file_list_entry->parameter[i], suffix_list[i].value);
+
+ file_list_entry->redefined = TRUE;
+
+ /* mark config file token as well known from default config */
+ setHashEntry(setup_file_hash, file_list_entry->token, known_token_value);
+ }
+
+ /* check for config tokens that can be build by base token and suffixes */
+ 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);
+
+ if (value != NULL)
+ {
+ setString(&file_list_entry->parameter[i], value);
+
+ /* mark config file token as well known from default config */
+ setHashEntry(setup_file_hash, token, known_token_value);
+ }
+
+ free(token);
+ }
+}
+
+static void add_dynamic_file_list_entry(struct FileInfo **list,
+ int *num_list_entries,
+ SetupFileHash *extra_file_hash,
+ 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 *);
+
+ (*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);
+}
+
+static void add_property_mapping(struct PropertyMapping **list,
+ int *num_list_entries,
+ int base_index, int ext1_index,
+ int ext2_index, int ext3_index,
+ int artwork_index)
+{
+ struct PropertyMapping *new_list_entry;
+
+ (*num_list_entries)++;
+ *list = checked_realloc(*list,
+ *num_list_entries * sizeof(struct PropertyMapping));
+ new_list_entry = &(*list)[*num_list_entries - 1];
+
+ new_list_entry->base_index = base_index;
+ new_list_entry->ext1_index = ext1_index;
+ new_list_entry->ext2_index = ext2_index;
+ new_list_entry->ext3_index = ext3_index;
+
+ new_list_entry->artwork_index = artwork_index;
+}
+
+static void LoadArtworkConfigFromFilename(struct ArtworkListInfo *artwork_info,
+ char *filename)
+{
+ struct FileInfo *file_list = artwork_info->file_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;
+ char **ext3_suffixes = artwork_info->ext3_suffixes;
+ char **ignore_tokens = artwork_info->ignore_tokens;
+ int num_file_list_entries = artwork_info->num_file_list_entries;
+ int num_suffix_list_entries = artwork_info->num_suffix_list_entries;
+ int num_base_prefixes = artwork_info->num_base_prefixes;
+ int num_ext1_suffixes = artwork_info->num_ext1_suffixes;
+ 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, *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 < num_file_list_entries; i++)
+ read_token_parameters(valid_file_hash, suffix_list, &file_list[i]);
+
+ /* set all tokens that can be ignored here to "known" keyword */
+ for (i = 0; i < num_ignore_tokens; i++)
+ setHashEntry(valid_file_hash, ignore_tokens[i], known_token_value);
+
+ /* copy all unknown config file tokens to extra config hash */
+ extra_file_hash = newSetupFileHash();
+ BEGIN_HASH_ITERATION(valid_file_hash, itr)
+ {
+ char *value = HASH_ITERATION_VALUE(itr);
+
+ if (!strEqual(value, known_token_value))
+ setHashEntry(extra_file_hash, HASH_ITERATION_TOKEN(itr), value);
+ }
+ END_HASH_ITERATION(valid_file_hash, itr)
+
+ /* at this point, we do not need the valid file hash anymore -- free it */
+ freeSetupFileHash(valid_file_hash);
+
+ /* now try to determine valid, dynamically defined config tokens */
+
+ BEGIN_HASH_ITERATION(extra_file_hash, itr)
+ {
+ struct FileInfo **dynamic_file_list =
+ &artwork_info->dynamic_file_list;
+ int *num_dynamic_file_list_entries =
+ &artwork_info->num_dynamic_file_list_entries;
+ struct PropertyMapping **property_mapping =
+ &artwork_info->property_mapping;
+ int *num_property_mapping_entries =
+ &artwork_info->num_property_mapping_entries;
+ int current_summarized_file_list_entry =
+ artwork_info->num_file_list_entries +
+ artwork_info->num_dynamic_file_list_entries;
+ char *token = HASH_ITERATION_TOKEN(itr);
+ int len_token = strlen(token);
+ int start_pos;
+ boolean base_prefix_found = FALSE;
+ boolean parameter_suffix_found = FALSE;
+
+#if 0
+ printf("::: examining '%s' -> '%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++)
+ {
+ int len_suffix = strlen(suffix_list[i].token);
+
+ if (token_suffix_match(token, suffix_list[i].token, -len_suffix))
+ parameter_suffix_found = TRUE;
+ }
+
+ 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++)
+ {
+ char *base_prefix = base_prefixes[i];
+ int len_base_prefix = strlen(base_prefix);
+ boolean ext1_suffix_found = FALSE;
+ boolean ext2_suffix_found = FALSE;
+ boolean ext3_suffix_found = FALSE;
+ boolean exact_match = FALSE;
+ int base_index = -1;
+ int ext1_index = -1;
+ int ext2_index = -1;
+ int ext3_index = -1;
+
+ base_prefix_found = token_suffix_match(token, base_prefix, start_pos);
+
+ if (!base_prefix_found)
+ continue;
+
+ base_index = i;
+
+ if (start_pos + len_base_prefix == len_token) /* exact match */
+ {
+ exact_match = TRUE;
+
+ add_dynamic_file_list_entry(dynamic_file_list,
+ num_dynamic_file_list_entries,
+ extra_file_hash,
+ suffix_list,
+ num_suffix_list_entries,
+ token);
+ add_property_mapping(property_mapping,
+ num_property_mapping_entries,
+ base_index, -1, -1, -1,
+ current_summarized_file_list_entry);
+ continue;
+ }
+
+#if 0
+ if (IS_PARENT_PROCESS())
+ printf("---> examining token '%s': search 1st suffix ...\n", token);
+#endif
+
+ /* ---------- step 1: search for matching first suffix ---------- */
+
+ start_pos += len_base_prefix;
+ for (j = 0; j < num_ext1_suffixes && !ext1_suffix_found; j++)
+ {
+ char *ext1_suffix = ext1_suffixes[j];
+ int len_ext1_suffix = strlen(ext1_suffix);
+
+ ext1_suffix_found = token_suffix_match(token, ext1_suffix, start_pos);
+
+ if (!ext1_suffix_found)
+ continue;
+
+ ext1_index = j;
+
+ if (start_pos + len_ext1_suffix == len_token) /* exact match */
+ {
+ exact_match = TRUE;
+
+ add_dynamic_file_list_entry(dynamic_file_list,
+ num_dynamic_file_list_entries,
+ extra_file_hash,
+ suffix_list,
+ num_suffix_list_entries,
+ token);
+ add_property_mapping(property_mapping,
+ num_property_mapping_entries,
+ base_index, ext1_index, -1, -1,
+ current_summarized_file_list_entry);
+ continue;
+ }
+
+ start_pos += len_ext1_suffix;
+ }
+
+ if (exact_match)
+ break;
+
+#if 0
+ if (IS_PARENT_PROCESS())
+ printf("---> examining token '%s': search 2nd suffix ...\n", token);