X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fsetup.c;h=b1e3b4439756a3307269cd94a56b6362775c294c;hb=2f5368f25e34c02cb5ff7a012aa96198442231cb;hp=f9063d5d5726037190925b93177bb24fb42fa90b;hpb=b645a25fff77d62a36c744fa4047a3c0e5929341;p=rocksndiamonds.git diff --git a/src/libgame/setup.c b/src/libgame/setup.c index f9063d5d..b1e3b443 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -108,23 +108,6 @@ static char *getUserLevelDir(char *level_subdir) return userlevel_dir; } -static char *getTapeDir(char *level_subdir) -{ - static char *tape_dir = NULL; - char *data_dir = getUserDataDir(); - char *tape_subdir = TAPES_DIRECTORY; - - if (tape_dir) - free(tape_dir); - - if (level_subdir != NULL) - tape_dir = getPath3(data_dir, tape_subdir, level_subdir); - else - tape_dir = getPath2(data_dir, tape_subdir); - - return tape_dir; -} - static char *getScoreDir(char *level_subdir) { static char *score_dir = NULL; @@ -180,6 +163,37 @@ static char *getCurrentLevelDir() return getLevelDirFromTreeInfo(leveldir_current); } +static char *getTapeDir(char *level_subdir) +{ + static char *tape_dir = NULL; + char *data_dir = getUserDataDir(); + char *tape_subdir = TAPES_DIRECTORY; + + if (tape_dir) + free(tape_dir); + + if (level_subdir != NULL) + tape_dir = getPath3(data_dir, tape_subdir, level_subdir); + else + tape_dir = getPath2(data_dir, tape_subdir); + + return tape_dir; +} + +static char *getSolutionTapeDir() +{ + static char *tape_dir = NULL; + char *data_dir = getCurrentLevelDir(); + char *tape_subdir = TAPES_DIRECTORY; + + if (tape_dir) + free(tape_dir); + + tape_dir = getPath2(data_dir, tape_subdir); + + return tape_dir; +} + static char *getDefaultGraphicsDir(char *graphics_subdir) { static char *graphics_dir = NULL; @@ -379,6 +393,20 @@ char *getTapeFilename(int nr) return filename; } +char *getSolutionTapeFilename(int nr) +{ + static char *filename = NULL; + char basename[MAX_FILENAME_LEN]; + + if (filename != NULL) + free(filename); + + sprintf(basename, "%03d.%s", nr, TAPEFILE_EXTENSION); + filename = getPath2(getSolutionTapeDir(), basename); + + return filename; +} + char *getScoreFilename(int nr) { static char *filename = NULL; @@ -1206,6 +1234,10 @@ char *getFormattedSetupEntry(char *token, char *value) int i; static char entry[MAX_LINE_LEN]; + /* if value is an empty string, just return token without value */ + if (*value == '\0') + return token; + /* start with the token and some spaces to format output line */ sprintf(entry, "%s:", token); for (i = strlen(entry); i < TOKEN_VALUE_POSITION; i++) @@ -1387,6 +1419,14 @@ void setHashEntry(SetupFileHash *hash, char *token, char *value) Error(ERR_EXIT, "cannot insert into hash -- aborting"); } +char *removeHashEntry(SetupFileHash *hash, char *token) +{ + if (hash == NULL) + return NULL; + + return remove_hash_entry(hash, token); +} + #if 0 #ifdef DEBUG static void printSetupFileHash(SetupFileHash *hash) @@ -1403,7 +1443,6 @@ static void printSetupFileHash(SetupFileHash *hash) static void *loadSetupFileData(char *filename, boolean use_hash) { - int line_len; char line[MAX_LINE_LEN], previous_line[MAX_LINE_LEN]; char *token, *value, *line_ptr; void *setup_file_data, *insert_ptr = NULL; @@ -1478,38 +1517,37 @@ static void *loadSetupFileData(char *filename, boolean use_hash) if (*line == '\0') continue; - line_len = strlen(line); - /* cut leading whitespaces from token */ for (token = line; *token; token++) if (*token != ' ' && *token != '\t') break; - /* find end of token */ + /* start with empty value as reliable default */ + value = ""; + + /* find end of token to determine start of value */ for (line_ptr = token; *line_ptr; line_ptr++) { if (*line_ptr == ' ' || *line_ptr == '\t' || *line_ptr == ':') { - *line_ptr = '\0'; + *line_ptr = '\0'; /* terminate token string */ + value = line_ptr + 1; /* set beginning of value */ + break; } } - 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++) if (*value != ' ' && *value != '\t') break; - if (*token && *value) +#if 0 + if (*value == '\0') + value = "true"; /* treat tokens without value as "true" */ +#endif + + if (*token) { if (use_hash) setHashEntry((SetupFileHash *)setup_file_data, token, value);