X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fsetup.c;h=f9063d5d5726037190925b93177bb24fb42fa90b;hb=b645a25fff77d62a36c744fa4047a3c0e5929341;hp=3ba6745deb17c313c1d55f640b9f2d8bdd7e4571;hpb=d292f0ad61b32968ca4a6750b93ac7e5b99ff00d;p=rocksndiamonds.git diff --git a/src/libgame/setup.c b/src/libgame/setup.c index 3ba6745d..f9063d5d 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -417,6 +417,58 @@ char *getEditorSetupFilename() return filename; } +char *getHelpAnimFilename() +{ + static char *filename = NULL; + + if (filename != NULL) + free(filename); + + filename = getPath2(getCurrentLevelDir(), HELPANIM_FILENAME); + + return filename; +} + +char *getHelpTextFilename() +{ + static char *filename = NULL; + + if (filename != NULL) + free(filename); + + filename = getPath2(getCurrentLevelDir(), HELPTEXT_FILENAME); + + return filename; +} + +char *getLevelSetInfoFilename() +{ + static char *filename = NULL; + char *basenames[] = + { + "readme", + "readme.txt", + "README", + "README.txt", + "README.TXT", + + NULL + }; + int i; + + for (i = 0; basenames[i] != NULL; i++) + { + if (filename != NULL) + free(filename); + + filename = getPath2(getCurrentLevelDir(), basenames[i]); + if (fileExists(filename)) + return filename; + } + + return NULL; +} + static char *getCorrectedArtworkBasename(char *basename) { char *basename_corrected = basename; @@ -886,7 +938,7 @@ void dumpTreeInfo(TreeInfo *node, int depth) while (node) { - for (i=0; i<(depth + 1) * 3; i++) + for (i = 0; i < (depth + 1) * 3; i++) printf(" "); #if 1 @@ -932,7 +984,7 @@ void sortTreeInfo(TreeInfo **node_first, compare_function); /* update the linkage of list elements with the sorted node array */ - for (i=0; inext = sort_array[i + 1]; sort_array[num_nodes - 1]->next = NULL; @@ -1156,7 +1208,7 @@ char *getFormattedSetupEntry(char *token, char *value) /* start with the token and some spaces to format output line */ sprintf(entry, "%s:", token); - for (i=strlen(entry); inext, 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) { @@ -1341,9 +1404,10 @@ static void printSetupFileHash(SetupFileHash *hash) static void *loadSetupFileData(char *filename, boolean use_hash) { int line_len; - char line[MAX_LINE_LEN]; + char line[MAX_LINE_LEN], previous_line[MAX_LINE_LEN]; char *token, *value, *line_ptr; void *setup_file_data, *insert_ptr = NULL; + boolean read_continued_line = FALSE; FILE *file; if (use_hash) @@ -1357,16 +1421,48 @@ static void *loadSetupFileData(char *filename, boolean use_hash) return NULL; } - while(!feof(file)) + while (!feof(file)) { /* read next line of input file */ if (!fgets(line, MAX_LINE_LEN, file)) break; - /* cut trailing comment or whitespace from input line */ + /* cut trailing newline or carriage return */ + for (line_ptr = &line[strlen(line)]; line_ptr >= line; line_ptr--) + if ((*line_ptr == '\n' || *line_ptr == '\r') && *(line_ptr + 1) == '\0') + *line_ptr = '\0'; + + if (read_continued_line) + { + /* cut leading whitespaces from input line */ + for (line_ptr = line; *line_ptr; line_ptr++) + if (*line_ptr != ' ' && *line_ptr != '\t') + break; + + /* append new line to existing line, if there is enough space */ + if (strlen(previous_line) + strlen(line_ptr) < MAX_LINE_LEN) + strcat(previous_line, line_ptr); + + strcpy(line, previous_line); /* copy storage buffer to line */ + + read_continued_line = FALSE; + } + + /* if the last character is '\', continue at next line */ + if (strlen(line) > 0 && line[strlen(line) - 1] == '\\') + { + line[strlen(line) - 1] = '\0'; /* cut off trailing backslash */ + strcpy(previous_line, line); /* copy line to storage buffer */ + + read_continued_line = TRUE; + + continue; + } + + /* cut trailing comment from input line */ for (line_ptr = line; *line_ptr; line_ptr++) { - if (*line_ptr == '#' || *line_ptr == '\n' || *line_ptr == '\r') + if (*line_ptr == '#') { *line_ptr = '\0'; break; @@ -1374,8 +1470,8 @@ static void *loadSetupFileData(char *filename, boolean use_hash) } /* cut trailing whitespaces from input line */ - for (line_ptr = &line[strlen(line)]; line_ptr > line; line_ptr--) - if ((*line_ptr == ' ' || *line_ptr == '\t') && line_ptr[1] == '\0') + for (line_ptr = &line[strlen(line)]; line_ptr >= line; line_ptr--) + if ((*line_ptr == ' ' || *line_ptr == '\t') && *(line_ptr + 1) == '\0') *line_ptr = '\0'; /* ignore empty lines */ @@ -1418,7 +1514,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); } } @@ -1863,7 +1959,7 @@ static boolean LoadLevelInfoFromLevelConf(TreeInfo **node_first, /* set all structure fields according to the token/value pairs */ ldi = *leveldir_new; - for (i=0; i