#include "joystick.h"
#include "text.h"
#include "misc.h"
+#include "hash.h"
/* file names and filename extensions */
#if !defined(PLATFORM_MSDOS)
static char *getScoreDir(char *level_subdir)
{
static char *score_dir = NULL;
- char *data_dir = options.rw_base_directory;
+ char *data_dir = getCommonDataDir();
char *score_subdir = SCORES_DIRECTORY;
if (score_dir)
char *artwork_path;
if (leveldir_current == NULL)
- return NOT_AVAILABLE;
+ return UNDEFINED_FILENAME;
artwork_path =
(type == TREE_TYPE_GRAPHICS_DIR ? leveldir_current->graphics_path :
type == TREE_TYPE_SOUNDS_DIR ? leveldir_current->sounds_path :
type == TREE_TYPE_MUSIC_DIR ? leveldir_current->music_path :
- NOT_AVAILABLE);
+ UNDEFINED_FILENAME);
return artwork_path;
}
static char *getCorrectedImageBasename(char *basename)
{
- char *result = basename;
+ char *basename_corrected = basename;
#if defined(PLATFORM_MSDOS)
if (program.filename_prefix != NULL)
int prefix_len = strlen(program.filename_prefix);
if (strncmp(basename, program.filename_prefix, prefix_len) == 0)
- result = &basename[prefix_len];
- }
-#endif
+ basename_corrected = &basename[prefix_len];
- return result;
-}
+ /* if corrected filename is still longer than standard MS-DOS filename
+ size (8 characters + 1 dot + 3 characters file extension), shorten
+ filename by writing file extension after 8th basename character */
+ if (strlen(basename_corrected) > 8+1+3)
+ {
+ static char *msdos_filename = NULL;
-static boolean fileExists(char *filename)
-{
-#if 0
- printf("checking file '%s'\n", filename);
+ if (msdos_filename != NULL)
+ free(msdos_filename);
+
+ msdos_filename = getStringCopy(basename_corrected);
+ strncpy(&msdos_filename[8], &basename[strlen(basename) - 1+3], 1+3 + 1);
+ }
+ }
#endif
- return (access(filename, F_OK) == 0);
+ return basename_corrected;
}
char *getCustomImageFilename(char *basename)
if (fileExists(filename))
return filename;
+ free(filename);
+
/* 2nd try: look for special artwork in current level series directory */
filename = getPath3(getCurrentLevelDir(), GRAPHICS_DIRECTORY, basename);
if (fileExists(filename))
return filename;
+
+ free(filename);
}
/* 3rd try: look for special artwork in configured artwork directory */
if (fileExists(filename))
return filename;
+ free(filename);
+
/* 4th try: look for default artwork in new default artwork directory */
filename = getPath2(getDefaultGraphicsDir(GRAPHICS_SUBDIR), basename);
if (fileExists(filename))
return filename;
+ free(filename);
+
/* 5th try: look for default artwork in old default artwork directory */
filename = getPath2(options.graphics_directory, basename);
if (fileExists(filename))
if (fileExists(filename))
return filename;
+ free(filename);
+
/* 2nd try: look for special artwork in current level series directory */
filename = getPath3(getCurrentLevelDir(), SOUNDS_DIRECTORY, basename);
if (fileExists(filename))
return filename;
+
+ free(filename);
}
/* 3rd try: look for special artwork in configured artwork directory */
if (fileExists(filename))
return filename;
+ free(filename);
+
/* 4th try: look for default artwork in new default artwork directory */
filename = getPath2(getDefaultSoundsDir(SOUNDS_SUBDIR), basename);
if (fileExists(filename))
return filename;
+ free(filename);
+
/* 5th try: look for default artwork in old default artwork directory */
filename = getPath2(options.sounds_directory, basename);
if (fileExists(filename))
return NULL; /* cannot find specified artwork file anywhere */
}
-char *getCustomSoundConfigFilename()
+char *getCustomArtworkFilename(char *basename, int type)
+{
+ if (type == ARTWORK_TYPE_GRAPHICS)
+ return getCustomImageFilename(basename);
+ else if (type == ARTWORK_TYPE_SOUNDS)
+ return getCustomSoundFilename(basename);
+ else
+ return UNDEFINED_FILENAME;
+}
+
+char *getCustomArtworkConfigFilename(int type)
{
- return getCustomSoundFilename(SOUNDSINFO_FILENAME);
+ return getCustomArtworkFilename(ARTWORKINFO_FILENAME(type), type);
}
char *getCustomMusicDirectory(void)
if (fileExists(directory))
return directory;
+ free(directory);
+
/* 2nd try: look for special artwork in current level series directory */
directory = getPath2(getCurrentLevelDir(), MUSIC_DIRECTORY);
if (fileExists(directory))
return directory;
+
+ free(directory);
}
/* 3rd try: look for special artwork in configured artwork directory */
if (fileExists(directory))
return directory;
+ free(directory);
+
/* 4th try: look for default artwork in new default artwork directory */
directory = getStringCopy(getDefaultMusicDir(MUSIC_SUBDIR));
if (fileExists(directory))
return directory;
+ free(directory);
+
/* 5th try: look for default artwork in old default artwork directory */
directory = getStringCopy(options.music_directory);
if (fileExists(directory))
void InitScoreDirectory(char *level_subdir)
{
+ createDirectory(getCommonDataDir(), "common data", PERMS_PUBLIC);
createDirectory(getScoreDir(NULL), "main score", PERMS_PUBLIC);
createDirectory(getScoreDir(level_subdir), "level score", PERMS_PUBLIC);
}
{
static char *userdata_dir = NULL;
- if (!userdata_dir)
+ if (userdata_dir == NULL)
+ userdata_dir = getPath2(getHomeDir(), program.userdata_directory);
+
+ return userdata_dir;
+}
+
+char *getCommonDataDir(void)
+{
+ static char *common_data_dir = NULL;
+
+#if defined(PLATFORM_WIN32)
+ if (common_data_dir == NULL)
{
- char *home_dir = getHomeDir();
- char *data_dir = program.userdata_directory;
+ char *dir = checked_malloc(MAX_PATH + 1);
- userdata_dir = getPath2(home_dir, data_dir);
+ if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_COMMON_DOCUMENTS, NULL, 0, dir))
+ && strcmp(dir, "") != 0) /* empty for Windows 95/98 */
+ common_data_dir = getPath2(dir, program.userdata_directory);
+ else
+ common_data_dir = options.rw_base_directory;
}
+#else
+ if (common_data_dir == NULL)
+ common_data_dir = options.rw_base_directory;
+#endif
- return userdata_dir;
+ return common_data_dir;
}
char *getSetupDir()
}
/* ------------------------------------------------------------------------- */
-/* setup file list handling functions */
+/* setup file list and hash handling functions */
/* ------------------------------------------------------------------------- */
-int get_string_integer_value(char *s)
+char *getFormattedSetupEntry(char *token, char *value)
{
- static char *number_text[][3] =
- {
- { "0", "zero", "null", },
- { "1", "one", "first" },
- { "2", "two", "second" },
- { "3", "three", "third" },
- { "4", "four", "fourth" },
- { "5", "five", "fifth" },
- { "6", "six", "sixth" },
- { "7", "seven", "seventh" },
- { "8", "eight", "eighth" },
- { "9", "nine", "ninth" },
- { "10", "ten", "tenth" },
- { "11", "eleven", "eleventh" },
- { "12", "twelve", "twelfth" },
- };
+ int i;
+ static char entry[MAX_LINE_LEN];
- int i, j;
- char *s_lower = getStringToLower(s);
- int result = -1;
+ /* start with the token and some spaces to format output line */
+ sprintf(entry, "%s:", token);
+ for (i=strlen(entry); i<TOKEN_VALUE_POSITION; i++)
+ strcat(entry, " ");
- for (i=0; i<13; i++)
- for (j=0; j<3; j++)
- if (strcmp(s_lower, number_text[i][j]) == 0)
- result = i;
+ /* continue with the token's value */
+ strcat(entry, value);
- if (result == -1)
- result = atoi(s);
+ return entry;
+}
+
+SetupFileList *newSetupFileList(char *token, char *value)
+{
+ SetupFileList *new = checked_malloc(sizeof(SetupFileList));
- free(s_lower);
+ new->token = getStringCopy(token);
+ new->value = getStringCopy(value);
+
+ new->next = NULL;
- return result;
+ return new;
}
-boolean get_string_boolean_value(char *s)
+void freeSetupFileList(SetupFileList *list)
{
- char *s_lower = getStringToLower(s);
- boolean result = FALSE;
+ if (list == NULL)
+ return;
- if (strcmp(s_lower, "true") == 0 ||
- strcmp(s_lower, "yes") == 0 ||
- strcmp(s_lower, "on") == 0 ||
- get_string_integer_value(s) == 1)
- result = TRUE;
+ if (list->token)
+ free(list->token);
+ if (list->value)
+ free(list->value);
+ if (list->next)
+ freeSetupFileList(list->next);
+ free(list);
+}
- free(s_lower);
+char *getListEntry(SetupFileList *list, char *token)
+{
+ if (list == NULL)
+ return NULL;
- return result;
+ if (strcmp(list->token, token) == 0)
+ return list->value;
+ else
+ return getListEntry(list->next, token);
}
-char *getFormattedSetupEntry(char *token, char *value)
+void setListEntry(SetupFileList *list, char *token, char *value)
{
- int i;
- static char entry[MAX_LINE_LEN];
-
- /* start with the token and some spaces to format output line */
- sprintf(entry, "%s:", token);
- for (i=strlen(entry); i<TOKEN_VALUE_POSITION; i++)
- strcat(entry, " ");
+ if (list == NULL)
+ return;
- /* continue with the token's value */
- strcat(entry, value);
+ if (strcmp(list->token, token) == 0)
+ {
+ if (list->value)
+ free(list->value);
- return entry;
+ list->value = getStringCopy(value);
+ }
+ else if (list->next == NULL)
+ list->next = newSetupFileList(token, value);
+ else
+ setListEntry(list->next, token, value);
}
-void freeSetupFileList(struct SetupFileList *setup_file_list)
+#ifdef DEBUG
+static void printSetupFileList(SetupFileList *list)
{
- if (!setup_file_list)
+ if (!list)
return;
- if (setup_file_list->token)
- free(setup_file_list->token);
- if (setup_file_list->value)
- free(setup_file_list->value);
- if (setup_file_list->next)
- freeSetupFileList(setup_file_list->next);
- free(setup_file_list);
+ printf("token: '%s'\n", list->token);
+ printf("value: '%s'\n", list->value);
+
+ printSetupFileList(list->next);
}
+#endif
+
+#ifdef DEBUG
+DEFINE_HASHTABLE_INSERT(insert_hash_entry, char, char);
+DEFINE_HASHTABLE_SEARCH(search_hash_entry, char, char);
+DEFINE_HASHTABLE_CHANGE(change_hash_entry, char, char);
+DEFINE_HASHTABLE_REMOVE(remove_hash_entry, char, char);
+#else
+#define insert_hash_entry hashtable_insert
+#define search_hash_entry hashtable_search
+#define change_hash_entry hashtable_change
+#define remove_hash_entry hashtable_remove
+#endif
-static struct SetupFileList *newSetupFileList(char *token, char *value)
+static unsigned int get_hash_from_key(void *key)
{
- struct SetupFileList *new = checked_malloc(sizeof(struct SetupFileList));
+ /*
+ djb2
- new->token = checked_malloc(strlen(token) + 1);
- strcpy(new->token, token);
+ This algorithm (k=33) was first reported by Dan Bernstein many years ago in
+ 'comp.lang.c'. Another version of this algorithm (now favored by Bernstein)
+ uses XOR: hash(i) = hash(i - 1) * 33 ^ str[i]; the magic of number 33 (why
+ it works better than many other constants, prime or not) has never been
+ adequately explained.
- new->value = checked_malloc(strlen(value) + 1);
- strcpy(new->value, value);
+ If you just want to have a good hash function, and cannot wait, djb2
+ is one of the best string hash functions i know. It has excellent
+ distribution and speed on many different sets of keys and table sizes.
+ You are not likely to do better with one of the "well known" functions
+ such as PJW, K&R, etc.
- new->next = NULL;
+ Ozan (oz) Yigit [http://www.cs.yorku.ca/~oz/hash.html]
+ */
- return new;
+ char *str = (char *)key;
+ unsigned int hash = 5381;
+ int c;
+
+ while ((c = *str++))
+ hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
+
+ return hash;
}
-char *getTokenValue(struct SetupFileList *setup_file_list, char *token)
+static int keys_are_equal(void *key1, void *key2)
{
- if (!setup_file_list)
- return NULL;
+ return (strcmp((char *)key1, (char *)key2) == 0);
+}
- if (strcmp(setup_file_list->token, token) == 0)
- return setup_file_list->value;
- else
- return getTokenValue(setup_file_list->next, token);
+SetupFileHash *newSetupFileHash()
+{
+ SetupFileHash *new_hash =
+ create_hashtable(16, 0.75, get_hash_from_key, keys_are_equal);
+
+ return new_hash;
}
-static void setTokenValue(struct SetupFileList *setup_file_list,
- char *token, char *value)
+void freeSetupFileHash(SetupFileHash *hash)
{
- if (!setup_file_list)
+ if (hash == NULL)
return;
- if (strcmp(setup_file_list->token, token) == 0)
- {
- free(setup_file_list->value);
- setup_file_list->value = checked_malloc(strlen(value) + 1);
- strcpy(setup_file_list->value, value);
- }
- else if (setup_file_list->next == NULL)
- setup_file_list->next = newSetupFileList(token, value);
- else
- setTokenValue(setup_file_list->next, token, value);
+ hashtable_destroy(hash, 1); /* 1 == also free values stored in hash */
}
-#ifdef DEBUG
-static void printSetupFileList(struct SetupFileList *setup_file_list)
+char *getHashEntry(SetupFileHash *hash, char *token)
{
- if (!setup_file_list)
+ if (hash == NULL)
+ return NULL;
+
+ return search_hash_entry(hash, token);
+}
+
+void setHashEntry(SetupFileHash *hash, char *token, char *value)
+{
+ char *value_copy;
+
+ if (hash == NULL)
return;
- printf("token: '%s'\n", setup_file_list->token);
- printf("value: '%s'\n", setup_file_list->value);
+ value_copy = getStringCopy(value);
+
+ /* change value; if it does not exist, insert it as new */
+ if (!change_hash_entry(hash, token, value_copy))
+ if (!insert_hash_entry(hash, getStringCopy(token), value_copy))
+ Error(ERR_EXIT, "cannot insert into hash -- aborting");
+}
- printSetupFileList(setup_file_list->next);
+#if 0
+#ifdef DEBUG
+static void printSetupFileHash(SetupFileHash *hash)
+{
+ BEGIN_HASH_ITERATION(hash, itr)
+ {
+ printf("token: '%s'\n", HASH_ITERATION_TOKEN(itr));
+ printf("value: '%s'\n", HASH_ITERATION_VALUE(itr));
+ }
+ END_HASH_ITERATION(hash, itr)
}
#endif
+#endif
-struct SetupFileList *loadSetupFileList(char *filename)
+static void *loadSetupFileData(char *filename, boolean use_hash)
{
int line_len;
char line[MAX_LINE_LEN];
char *token, *value, *line_ptr;
- struct SetupFileList *setup_file_list = newSetupFileList("", "");
- struct SetupFileList *first_valid_list_entry;
-
+ 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);
break;
if (*token && *value)
- setTokenValue(setup_file_list, token, value);
+ {
+ if (use_hash)
+ setHashEntry((SetupFileHash *)setup_file_data, token, value);
+ else
+ setListEntry((SetupFileList *)setup_file_data, token, value);
+ }
}
fclose(file);
- first_valid_list_entry = setup_file_list->next;
+ 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);
+ /* 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);
+ if (first_valid_list_entry == NULL)
+ Error(ERR_WARN, "configuration file '%s' is empty", filename);
+ }
- return first_valid_list_entry;
+ return setup_file_data;
}
-void checkSetupFileListIdentifier(struct SetupFileList *setup_file_list,
- char *identifier)
+SetupFileList *loadSetupFileList(char *filename)
{
- if (!setup_file_list)
- return;
+ return (SetupFileList *)loadSetupFileData(filename, FALSE);
+}
- if (strcmp(setup_file_list->token, TOKEN_STR_FILE_IDENTIFIER) == 0)
- {
- if (!checkCookieString(setup_file_list->value, identifier))
- {
- Error(ERR_WARN, "configuration file has wrong file identifier");
- return;
- }
- else
- return;
- }
+SetupFileHash *loadSetupFileHash(char *filename)
+{
+ return (SetupFileHash *)loadSetupFileData(filename, TRUE);
+}
- if (setup_file_list->next)
- checkSetupFileListIdentifier(setup_file_list->next, identifier);
- else
- {
+void checkSetupFileHashIdentifier(SetupFileHash *setup_file_hash,
+ char *identifier)
+{
+ char *value = getHashEntry(setup_file_hash, TOKEN_STR_FILE_IDENTIFIER);
+
+ if (value == NULL)
Error(ERR_WARN, "configuration file has no file identifier");
- return;
- }
+ else if (!checkCookieString(value, identifier))
+ Error(ERR_WARN, "configuration file has wrong file identifier");
}
ldi->graphics_set = NULL;
ldi->sounds_set = NULL;
ldi->music_set = NULL;
- ldi->graphics_path = getStringCopy(NOT_AVAILABLE);
- ldi->sounds_path = getStringCopy(NOT_AVAILABLE);
- ldi->music_path = getStringCopy(NOT_AVAILABLE);
+ ldi->graphics_path = getStringCopy(UNDEFINED_FILENAME);
+ ldi->sounds_path = getStringCopy(UNDEFINED_FILENAME);
+ ldi->music_path = getStringCopy(UNDEFINED_FILENAME);
ldi->levels = 0;
ldi->first_level = 0;
ldi->last_level = 0;
{
case TYPE_BOOLEAN:
case TYPE_SWITCH:
- *(boolean *)setup_value = get_string_boolean_value(token_value);
+ *(boolean *)setup_value = get_boolean_from_string(token_value);
break;
case TYPE_KEY:
break;
case TYPE_INTEGER:
- *(int *)setup_value = get_string_integer_value(token_value);
+ *(int *)setup_value = get_integer_from_string(token_value);
break;
case TYPE_STRING:
{
char *directory_path = getPath2(level_directory, directory_name);
char *filename = getPath2(directory_path, LEVELINFO_FILENAME);
- struct SetupFileList *setup_file_list = loadSetupFileList(filename);
+ SetupFileHash *setup_file_hash = loadSetupFileHash(filename);
LevelDirTree *leveldir_new = NULL;
int i;
- if (setup_file_list == NULL)
+ if (setup_file_hash == NULL)
{
Error(ERR_WARN, "ignoring level directory '%s'", directory_path);
leveldir_new->filename = getStringCopy(directory_name);
- checkSetupFileListIdentifier(setup_file_list, getCookie("LEVELINFO"));
+ checkSetupFileHashIdentifier(setup_file_hash, getCookie("LEVELINFO"));
/* set all structure fields according to the token/value pairs */
ldi = *leveldir_new;
for (i=0; i<NUM_LEVELINFO_TOKENS; i++)
setSetupInfo(levelinfo_tokens, i,
- getTokenValue(setup_file_list, levelinfo_tokens[i].text));
+ getHashEntry(setup_file_hash, levelinfo_tokens[i].text));
*leveldir_new = ldi;
if (strcmp(leveldir_new->name, ANONYMOUS_NAME) == 0)
pushTreeInfo(node_first, leveldir_new);
- freeSetupFileList(setup_file_list);
+ freeSetupFileHash(setup_file_hash);
if (leveldir_new->level_group)
{
{
char *directory_path = getPath2(base_directory, directory_name);
char *filename = getPath2(directory_path, ARTWORKINFO_FILENAME(type));
- struct SetupFileList *setup_file_list = NULL;
+ SetupFileHash *setup_file_hash = NULL;
TreeInfo *artwork_new = NULL;
int i;
if (access(filename, F_OK) == 0) /* file exists */
- setup_file_list = loadSetupFileList(filename);
+ setup_file_hash = loadSetupFileHash(filename);
- if (setup_file_list == NULL) /* no config file -- look for artwork files */
+ if (setup_file_hash == NULL) /* no config file -- look for artwork files */
{
DIR *dir;
struct dirent *dir_entry;
artwork_new->filename = getStringCopy(directory_name);
- if (setup_file_list) /* (before defining ".color" and ".class_desc") */
+ if (setup_file_hash) /* (before defining ".color" and ".class_desc") */
{
#if 0
- checkSetupFileListIdentifier(setup_file_list, getCookie("..."));
+ checkSetupFileHashIdentifier(setup_file_hash, getCookie("..."));
#endif
/* set all structure fields according to the token/value pairs */
ldi = *artwork_new;
for (i=0; i<NUM_LEVELINFO_TOKENS; i++)
setSetupInfo(levelinfo_tokens, i,
- getTokenValue(setup_file_list, levelinfo_tokens[i].text));
+ getHashEntry(setup_file_hash, levelinfo_tokens[i].text));
*artwork_new = ldi;
if (strcmp(artwork_new->name, ANONYMOUS_NAME) == 0)
artwork_new->user_defined =
(artwork_new->basepath == OPTIONS_ARTWORK_DIRECTORY(type) ? FALSE : TRUE);
- /* (may use ".sort_priority" from "setup_file_list" above) */
+ /* (may use ".sort_priority" from "setup_file_hash" above) */
artwork_new->color = ARTWORKCOLOR(artwork_new);
artwork_new->class_desc = getLevelClassDescription(artwork_new);
- if (setup_file_list == NULL) /* (after determining ".user_defined") */
+ if (setup_file_hash == NULL) /* (after determining ".user_defined") */
{
if (artwork_new->name != NULL)
free(artwork_new->name);
pushTreeInfo(node_first, artwork_new);
- freeSetupFileList(setup_file_list);
+ freeSetupFileHash(setup_file_hash);
free(directory_path);
free(filename);
setTreeInfoToDefaults(artwork_new, type);
- artwork_new->filename = getStringCopy(NOT_AVAILABLE);
- artwork_new->fullpath = getStringCopy(NOT_AVAILABLE);
- artwork_new->basepath = getStringCopy(NOT_AVAILABLE);
+ artwork_new->filename = getStringCopy(UNDEFINED_FILENAME);
+ artwork_new->fullpath = getStringCopy(UNDEFINED_FILENAME);
+ artwork_new->basepath = getStringCopy(UNDEFINED_FILENAME);
if (artwork_new->name != NULL)
free(artwork_new->name);
- artwork_new->identifier = getStringCopy(NOT_AVAILABLE);
- artwork_new->name = getStringCopy(NOT_AVAILABLE);
- artwork_new->name_sorting = getStringCopy(NOT_AVAILABLE);
+ artwork_new->identifier = getStringCopy(UNDEFINED_FILENAME);
+ artwork_new->name = getStringCopy(UNDEFINED_FILENAME);
+ artwork_new->name_sorting = getStringCopy(UNDEFINED_FILENAME);
return artwork_new;
}
ldi.first_level = 1;
ldi.sort_priority = LEVELCLASS_USER_START;
ldi.readonly = FALSE;
+ ldi.graphics_set = getStringCopy(GRAPHICS_SUBDIR);
+ ldi.sounds_set = getStringCopy(SOUNDS_SUBDIR);
+ ldi.music_set = getStringCopy(MUSIC_SUBDIR);
fprintf(file, "%s\n\n", getFormattedSetupEntry(TOKEN_STR_FILE_IDENTIFIER,
getCookie("LEVELINFO")));
void LoadLevelSetup_LastSeries()
{
char *filename;
- struct SetupFileList *level_setup_list = NULL;
+ SetupFileHash *level_setup_hash = NULL;
/* always start with reliable default values */
leveldir_current = getFirstValidTreeInfoEntry(leveldir_first);
filename = getPath2(getSetupDir(), LEVELSETUP_FILENAME);
- if ((level_setup_list = loadSetupFileList(filename)))
+ if ((level_setup_hash = loadSetupFileHash(filename)))
{
char *last_level_series =
- getTokenValue(level_setup_list, TOKEN_STR_LAST_LEVEL_SERIES);
+ getHashEntry(level_setup_hash, TOKEN_STR_LAST_LEVEL_SERIES);
leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
last_level_series);
if (leveldir_current == NULL)
leveldir_current = getFirstValidTreeInfoEntry(leveldir_first);
- checkSetupFileListIdentifier(level_setup_list, getCookie("LEVELSETUP"));
+ checkSetupFileHashIdentifier(level_setup_hash, getCookie("LEVELSETUP"));
- freeSetupFileList(level_setup_list);
+ freeSetupFileHash(level_setup_hash);
}
else
Error(ERR_WARN, "using default setup values");
levelnum_value = atoi(levelnum_str);
+#if 0
if (levelnum_value < leveldir_current->first_level)
{
Error(ERR_WARN, "additional level %d found", levelnum_value);
Error(ERR_WARN, "additional level %d found", levelnum_value);
leveldir_current->last_level = levelnum_value;
}
+#endif
}
}
void LoadLevelSetup_SeriesInfo()
{
char *filename;
- struct SetupFileList *level_setup_list = NULL;
+ SetupFileHash *level_setup_hash = NULL;
char *level_subdir = leveldir_current->filename;
/* always start with reliable default values */
filename = getPath2(getLevelSetupDir(level_subdir), LEVELSETUP_FILENAME);
- if ((level_setup_list = loadSetupFileList(filename)))
+ if ((level_setup_hash = loadSetupFileHash(filename)))
{
char *token_value;
- token_value = getTokenValue(level_setup_list, TOKEN_STR_LAST_PLAYED_LEVEL);
+ token_value = getHashEntry(level_setup_hash, TOKEN_STR_LAST_PLAYED_LEVEL);
if (token_value)
{
level_nr = leveldir_current->last_level;
}
- token_value = getTokenValue(level_setup_list, TOKEN_STR_HANDICAP_LEVEL);
+ token_value = getHashEntry(level_setup_hash, TOKEN_STR_HANDICAP_LEVEL);
if (token_value)
{
leveldir_current->handicap_level = level_nr;
}
- checkSetupFileListIdentifier(level_setup_list, getCookie("LEVELSETUP"));
+ checkSetupFileHashIdentifier(level_setup_hash, getCookie("LEVELSETUP"));
- freeSetupFileList(level_setup_list);
+ freeSetupFileHash(level_setup_hash);
}
else
Error(ERR_WARN, "using default setup values");