X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fsetup.c;h=00168642fb95fb9665f46805699c6194a560f7ea;hb=891c39ca37c4fea5f6cc4ca40f913a56c68ef495;hp=8ba46e0be7e7a4772f5f90f78ab6cd424d2757d8;hpb=3607ef8e4000754063935d908053d564de92c0a2;p=rocksndiamonds.git diff --git a/src/libgame/setup.c b/src/libgame/setup.c index 8ba46e0b..00168642 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -405,6 +405,30 @@ char *getSetupFilename() return filename; } +char *getEditorSetupFilename() +{ + static char *filename = NULL; + + if (filename != NULL) + free(filename); + + filename = getPath2(getSetupDir(), EDITORSETUP_FILENAME); + + return filename; +} + +char *getElementInfoFilename() +{ + static char *filename = NULL; + + if (filename != NULL) + free(filename); + + filename = getPath2(getCurrentLevelDir(), ELEMENTINFO_FILENAME); + + return filename; +} + static char *getCorrectedArtworkBasename(char *basename) { char *basename_corrected = basename; @@ -1210,6 +1234,17 @@ SetupFileList *setListEntry(SetupFileList *list, char *token, char *value) return setListEntry(list->next, token, value); } +SetupFileList *addListEntry(SetupFileList *list, char *token, char *value) +{ + if (list == NULL) + return NULL; + + if (list->next == NULL) + return (list->next = newSetupFileList(token, value)); + else + return addListEntry(list->next, token, value); +} + #ifdef DEBUG static void printSetupFileList(SetupFileList *list) { @@ -1275,6 +1310,9 @@ SetupFileHash *newSetupFileHash() SetupFileHash *new_hash = create_hashtable(16, 0.75, get_hash_from_key, keys_are_equal); + if (new_hash == NULL) + Error(ERR_EXIT, "create_hashtable() failed -- out of memory"); + return new_hash; } @@ -1387,7 +1425,11 @@ static void *loadSetupFileData(char *filename, boolean use_hash) if (line_ptr < line + line_len) value = line_ptr + 1; else +#if 1 + value = "true"; /* treat tokens without value as "true" */ +#else value = "\0"; +#endif /* cut leading whitespaces from value */ for (; *value; value++) @@ -1399,7 +1441,7 @@ static void *loadSetupFileData(char *filename, boolean use_hash) if (use_hash) setHashEntry((SetupFileHash *)setup_file_data, token, value); else - insert_ptr = setListEntry((SetupFileList *)insert_ptr, token, value); + insert_ptr = addListEntry((SetupFileList *)insert_ptr, token, value); } } @@ -2618,17 +2660,15 @@ char *getSetupLine(struct TokenInfo *token_info, char *prefix, int token_nr) void LoadLevelSetup_LastSeries() { - char *filename; - SetupFileHash *level_setup_hash = NULL; - - /* always start with reliable default values */ - leveldir_current = getFirstValidTreeInfoEntry(leveldir_first); - /* ----------------------------------------------------------------------- */ /* ~/./levelsetup.conf */ /* ----------------------------------------------------------------------- */ - filename = getPath2(getSetupDir(), LEVELSETUP_FILENAME); + char *filename = getPath2(getSetupDir(), LEVELSETUP_FILENAME); + SetupFileHash *level_setup_hash = NULL; + + /* always start with reliable default values */ + leveldir_current = getFirstValidTreeInfoEntry(leveldir_first); if ((level_setup_hash = loadSetupFileHash(filename))) { @@ -2652,17 +2692,15 @@ void LoadLevelSetup_LastSeries() void SaveLevelSetup_LastSeries() { - char *filename; - char *level_subdir = leveldir_current->filename; - FILE *file; - /* ----------------------------------------------------------------------- */ /* ~/./levelsetup.conf */ /* ----------------------------------------------------------------------- */ - InitUserDataDirectory(); + char *filename = getPath2(getSetupDir(), LEVELSETUP_FILENAME); + char *level_subdir = leveldir_current->filename; + FILE *file; - filename = getPath2(getSetupDir(), LEVELSETUP_FILENAME); + InitUserDataDirectory(); if (!(file = fopen(filename, MODE_WRITE))) {