diff options
Diffstat (limited to 'engines/sci')
-rw-r--r-- | engines/sci/engine/kfile.cpp | 365 | ||||
-rw-r--r-- | engines/sci/engine/savegame.cfsml | 289 | ||||
-rw-r--r-- | engines/sci/engine/savegame.cpp | 2378 | ||||
-rw-r--r-- | engines/sci/engine/scriptdebug.cpp | 22 | ||||
-rw-r--r-- | engines/sci/engine/vm.cpp | 2 | ||||
-rw-r--r-- | engines/sci/include/engine.h | 30 | ||||
-rw-r--r-- | engines/sci/include/vm.h | 12 | ||||
-rw-r--r-- | engines/sci/sci.cpp | 6 | ||||
-rw-r--r-- | engines/sci/sci.h | 3 |
9 files changed, 1683 insertions, 1424 deletions
diff --git a/engines/sci/engine/kfile.cpp b/engines/sci/engine/kfile.cpp index 2b22f6d87a..041784ee27 100644 --- a/engines/sci/engine/kfile.cpp +++ b/engines/sci/engine/kfile.cpp @@ -30,8 +30,10 @@ #endif #include "common/str.h" +#include "common/savefile.h" #include "sci/include/engine.h" +#include "sci/sci.h" #include <errno.h> @@ -43,7 +45,8 @@ static int _savegame_indices_nr = -1; // means 'uninitialized' static struct _savegame_index_struct { int id; - long timestamp; + int date; + int time; } _savegame_indices[MAX_SAVEGAME_NR]; // This assumes modern stream implementations. It may break on DOS. @@ -264,29 +267,6 @@ static void fseek_wrapper(state_t *s, int handle, int offset, int whence) { s->r_acc = make_reg(0, fseek(f, offset, whence)); } -static char *_chdir_savedir(state_t *s) { - char *cwd = sci_getcwd(); - char *save_dir = kernel_dereference_char_pointer(s, make_reg(s->sys_strings_segment, SYS_STRING_SAVEDIR), 0); - - if (chdir(save_dir) && sci_mkpath(save_dir)) { - sciprintf(__FILE__": Can't chdir to savegame dir '%s' or create it\n", save_dir); - free(cwd); - return NULL; - } - - if (!cwd) - cwd = strdup(s->work_dir); - - return cwd; // Potentially try again -} - -static void _chdir_restoredir(char *dir) { - if (chdir(dir)) { - sciprintf(__FILE__": Can't seem to return to previous homedir '%s'\n", dir); - } - free(dir); -} - #define TEST_DIR_OR_QUIT(dir) if (!dir) { return NULL_REG; } reg_t kFGets(state_t *s, int funct_nr, int argc, reg_t *argv) { @@ -314,36 +294,13 @@ reg_t kGetCWD(state_t *s, int funct_nr, int argc, reg_t *argv) { return argv[0]; } -// Returns a dynamically allocated pointer to the name of the requested save dir -char *_k_get_savedir_name(int nr) { - char suffices[] = "0123456789abcdefghijklmnopqrstuvwxyz"; - char *savedir_name = (char*)sci_malloc(strlen(FREESCI_SAVEDIR_PREFIX) + 2); - assert(nr >= 0); - assert(nr < MAX_SAVEGAME_NR); - strcpy(savedir_name, FREESCI_SAVEDIR_PREFIX); - savedir_name[strlen(FREESCI_SAVEDIR_PREFIX)] = suffices[nr]; - savedir_name[strlen(FREESCI_SAVEDIR_PREFIX) + 1] = 0; - - return savedir_name; -} - void delete_savegame(state_t *s, int savedir_nr) { - char *workdir = _chdir_savedir(s); - char *savedir = _k_get_savedir_name(savedir_nr); - char buffer[256]; - - sciprintf("Deleting savegame '%s'\n", savedir); - - sprintf(buffer, "%s/%s.id", savedir, s->game_name); - sci_unlink(buffer); - - sprintf(buffer, "%s/state", savedir); - sci_unlink(buffer); + Common::String filename = ((Sci::SciEngine*)g_engine)->getSavegameName(savedir_nr); - sci_rmdir(savedir); + sciprintf("Deleting savegame '%s'\n", filename.c_str()); - free(savedir); - _chdir_restoredir(workdir); + Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager(); + saveFileMan->removeSavefile(filename.c_str()); } #define K_DEVICE_INFO_GET_DEVICE 0 @@ -553,216 +510,145 @@ int _k_check_file(char *filename, int minfilesize) { return (sci_file_size(filename) < minfilesize); } -int _k_find_savegame_by_name(char *game_id_file, char *name) { - int savedir_nr = -1; - int i; - char *buf = NULL; - - for (i = 0; i < MAX_SAVEGAME_NR; i++) { - if (!chdir((buf = _k_get_savedir_name(i)))) { - char namebuf[32]; // Save game name buffer - FILE *idfile = sci_fopen(game_id_file, "r"); - - if (idfile) { - fgets(namebuf, 31, idfile); - if (strlen(namebuf) > 0) - if (namebuf[strlen(namebuf) - 1] == '\n') - namebuf[strlen(namebuf) - 1] = 0; // Remove trailing newlines - - if (strcmp(name, namebuf) == 0) { - sciprintf("Save game name matched entry %d\n", i); - savedir_nr = i; - } - fclose(idfile); - } - chdir(".."); - } - free(buf); - } - return 0; -} - -#ifdef __DC__ -static long get_file_mtime(int fd) { - /* FIXME (Dreamcast): Not yet implemented */ - return 0; -} - -#else - -#define get_file_mtime(fd) get_file_mtime_Unix(fd) -/* Returns the time of the specified file's last modification -** Parameters: (int) fd: The file descriptor of the file in question -** Returns : (long) An integer value describing the time of the -** file's last modification. -** The only thing that must be ensured is that -** get_file_mtime(f1) > get_file_mtime(f2) -** <=> -** if f1 was modified at a later point in time than the last time -** f2 was modified. -*/ - -static long get_file_mtime_Unix(int fd) { - struct stat fd_stat; - fstat(fd, &fd_stat); - - return fd_stat.st_ctime; -} -#endif - static int _savegame_index_struct_compare(const void *a, const void *b) { - return ((struct _savegame_index_struct *)b)->timestamp - ((struct _savegame_index_struct *)a)->timestamp; + struct _savegame_index_struct *A = (struct _savegame_index_struct *)a; + struct _savegame_index_struct *B = (struct _savegame_index_struct *)b; + + if (B->date != A->date) + return B->date - A->date; + return B->time - A->time; } -static void update_savegame_indices(const char *gfname) { +static void update_savegame_indices() { int i; _savegame_indices_nr = 0; - for (i = 0; i < MAX_SAVEGAME_NR; i++) { - char *dirname = _k_get_savedir_name(i); - int fd; - - if (!chdir(dirname)) { + Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager(); - if (IS_VALID_FD(fd = sci_open(gfname, O_RDONLY))) { - _savegame_indices[_savegame_indices_nr].id = i; - _savegame_indices[_savegame_indices_nr++].timestamp = get_file_mtime(fd); - close(fd); + for (i = 0; i < MAX_SAVEGAME_NR; i++) { + Common::String filename = ((Sci::SciEngine*)g_engine)->getSavegameName(i); + Common::SeekableReadStream *in; + if ((in = saveFileMan->openForLoading(filename.c_str()))) { + SavegameMetadata meta; + if (!get_savegame_metadata(in, &meta)) { + // invalid + delete in; + continue; } - chdir(".."); - } - - free(dirname); - } - - qsort(_savegame_indices, _savegame_indices_nr, sizeof(struct _savegame_index_struct), _savegame_index_struct_compare); -} + delete in; -int test_savegame(state_t *s, char *savegame_id, char *savegame_name, int savegame_name_length) { - FILE *f; - char buffer[80]; - int version = -1; - - chdir(savegame_id); - f = fopen("state", "r"); - - if (!f) return 0; - while (!feof(f)) { - char *seeker; - fgets(buffer, sizeof(buffer), f); - if ((seeker = strstr(buffer, "savegame_version = ")) != NULL) { - seeker += strlen("savegame_version = "); - version = strtol(seeker, NULL, 10); - break; + fprintf(stderr, "Savegame in %s file ok\n", filename.c_str()); + _savegame_indices[_savegame_indices_nr].id = i; + _savegame_indices[_savegame_indices_nr].date = meta.savegame_date; + _savegame_indices[_savegame_indices_nr].time = meta.savegame_time; + _savegame_indices_nr++; } } - fclose(f); - return version >= FREESCI_MINIMUM_SAVEGAME_VERSION && version <= FREESCI_CURRENT_SAVEGAME_VERSION; + qsort(_savegame_indices, _savegame_indices_nr, sizeof(struct _savegame_index_struct), _savegame_index_struct_compare); } reg_t kCheckSaveGame(state_t *s, int funct_nr, int argc, reg_t *argv) { - char *game_id = kernel_dereference_char_pointer(s, argv[0], 0); + //char *game_id = kernel_dereference_char_pointer(s, argv[0], 0); int savedir_nr = UKPV(1); - char *buf = NULL; - char *workdir = _chdir_savedir(s); - TEST_DIR_OR_QUIT(workdir); if (_savegame_indices_nr < 0) { - char *game_id_file_name = (char*)sci_malloc(strlen(game_id) + strlen(FREESCI_ID_SUFFIX) + 1); - - strcpy(game_id_file_name, game_id); - strcat(game_id_file_name, FREESCI_ID_SUFFIX); warning("Savegame index list not initialized"); - update_savegame_indices(game_id_file_name); + update_savegame_indices(); } savedir_nr = _savegame_indices[savedir_nr].id; if (savedir_nr > MAX_SAVEGAME_NR - 1) { - _chdir_restoredir(workdir); return NULL_REG; } - s->r_acc = make_reg(0, test_savegame(s, (buf = _k_get_savedir_name(savedir_nr)), NULL, 0)); + Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager(); + Common::String filename = ((Sci::SciEngine*)g_engine)->getSavegameName(savedir_nr); + Common::SeekableReadStream *in; + if ((in = saveFileMan->openForLoading(filename.c_str()))) { + // found a savegame file - _chdir_restoredir(workdir); - free(buf); + SavegameMetadata meta; + if (!get_savegame_metadata(in, &meta)) { + // invalid + s->r_acc = make_reg(0, 0); + } else { + s->r_acc = make_reg(0, 1); + } + delete in; + } else { + s->r_acc = make_reg(0, 1); + } return s->r_acc; } reg_t kGetSaveFiles(state_t *s, int funct_nr, int argc, reg_t *argv) { - char *game_id = kernel_dereference_char_pointer(s, argv[0], 0); + //char *game_id = kernel_dereference_char_pointer(s, argv[0], 0); char *nametarget = kernel_dereference_char_pointer(s, argv[1], 0); reg_t nametarget_base = argv[1]; reg_t *nameoffsets = kernel_dereference_reg_pointer(s, argv[2], 0); - int gfname_len = strlen(game_id) + strlen(FREESCI_ID_SUFFIX) + 1; - char *gfname = (char*)sci_malloc(gfname_len); int i; - char *workdir = _chdir_savedir(s); - TEST_DIR_OR_QUIT(workdir); - - strcpy(gfname, game_id); - strcat(gfname, FREESCI_ID_SUFFIX); // This file is used to identify in-game savegames - update_savegame_indices(gfname); + update_savegame_indices(); s->r_acc = NULL_REG; + Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager(); for (i = 0; i < _savegame_indices_nr; i++) { - char *savedir_name = _k_get_savedir_name(_savegame_indices[i].id); - FILE *idfile; - - if (!chdir(savedir_name)) { - if ((idfile = sci_fopen(gfname, "r"))) { // Valid game ID file: Assume valid game - char namebuf[SCI_MAX_SAVENAME_LENGTH]; // Save game name buffer - fgets(namebuf, SCI_MAX_SAVENAME_LENGTH - 1, idfile); - if (strlen(namebuf) > 0) { - if (namebuf[strlen(namebuf) - 1] == '\n') - namebuf[strlen(namebuf) - 1] = 0; // Remove trailing newline - - *nameoffsets = s->r_acc; // Store savegame ID - ++s->r_acc.offset; // Increase number of files found - - nameoffsets++; // Make sure the next ID string address is written to the next pointer - strncpy(nametarget, namebuf, SCI_MAX_SAVENAME_LENGTH); // Copy identifier string - *(nametarget + SCI_MAX_SAVENAME_LENGTH - 1) = 0; // Make sure it's terminated - nametarget += SCI_MAX_SAVENAME_LENGTH; // Increase name offset pointer accordingly - nametarget_base.offset += SCI_MAX_SAVENAME_LENGTH; - fclose(idfile); - } + Common::String filename = ((Sci::SciEngine*)g_engine)->getSavegameName(_savegame_indices[i].id); + Common::SeekableReadStream *in; + if ((in = saveFileMan->openForLoading(filename.c_str()))) { + // found a savegame file + + SavegameMetadata meta; + if (!get_savegame_metadata(in, &meta)) { + // invalid + delete in; + continue; + } + + char namebuf[SCI_MAX_SAVENAME_LENGTH]; // Save game name buffer + strncpy(namebuf, meta.savegame_name, SCI_MAX_SAVENAME_LENGTH); + namebuf[SCI_MAX_SAVENAME_LENGTH-1] = 0; + + if (strlen(namebuf) > 0) { + if (namebuf[strlen(namebuf) - 1] == '\n') + namebuf[strlen(namebuf) - 1] = 0; // Remove trailing newline + + *nameoffsets = s->r_acc; // Store savegame ID + ++s->r_acc.offset; // Increase number of files found + + nameoffsets++; // Make sure the next ID string address is written to the next pointer + strncpy(nametarget, namebuf, SCI_MAX_SAVENAME_LENGTH); // Copy identifier string + *(nametarget + SCI_MAX_SAVENAME_LENGTH - 1) = 0; // Make sure it's terminated + nametarget += SCI_MAX_SAVENAME_LENGTH; // Increase name offset pointer accordingly + nametarget_base.offset += SCI_MAX_SAVENAME_LENGTH; } - chdir(".."); + delete in; } - free(savedir_name); } - free(gfname); + //free(gfname); *nametarget = 0; // Terminate list - _chdir_restoredir(workdir); return s->r_acc; } reg_t kSaveGame(state_t *s, int funct_nr, int argc, reg_t *argv) { - char *game_id = (char*)kernel_dereference_bulk_pointer(s, argv[0], 0); - char *savegame_dir; + //char *game_id = (char*)kernel_dereference_bulk_pointer(s, argv[0], 0); int savedir_nr = UKPV(1); int savedir_id; // Savegame ID, derived from savedir_nr and the savegame ID list - char *game_id_file_name = (char*)sci_malloc(strlen(game_id) + strlen(FREESCI_ID_SUFFIX) + 1); char *game_description = (char*)kernel_dereference_bulk_pointer(s, argv[2], 0); - char *workdir = _chdir_savedir(s); char *version = argc > 3 ? strdup((char*)kernel_dereference_bulk_pointer(s, argv[3], 0)) : NULL; - TEST_DIR_OR_QUIT(workdir); s->game_version = version; - strcpy(game_id_file_name, game_id); - strcat(game_id_file_name, FREESCI_ID_SUFFIX); + update_savegame_indices(); - update_savegame_indices(game_id_file_name); + fprintf(stderr, "savedir_nr = %d\n", savedir_nr); if (savedir_nr >= 0 && savedir_nr < _savegame_indices_nr) // Overwrite @@ -770,6 +656,8 @@ reg_t kSaveGame(state_t *s, int funct_nr, int argc, reg_t *argv) { else if (savedir_nr >= 0 && savedir_nr < MAX_SAVEGAME_NR) { int i = 0; + fprintf(stderr, "searching for hole\n"); + savedir_id = 0; // First, look for holes @@ -790,31 +678,29 @@ reg_t kSaveGame(state_t *s, int funct_nr, int argc, reg_t *argv) { return NULL_REG; } - savegame_dir = _k_get_savedir_name(savedir_id); + Common::String filename = ((Sci::SciEngine*)g_engine)->getSavegameName(savedir_id); + Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager(); + Common::OutSaveFile *out; + if (!(out = saveFileMan->openForSaving(filename.c_str()))) { + sciprintf("Error opening savegame \"%s\" for writing\n", filename.c_str()); + s->r_acc = NULL_REG; + return NULL_REG; + } - if (gamestate_save(s, savegame_dir)) { + if (gamestate_save(s, out, game_description)) { sciprintf("Saving the game failed.\n"); s->r_acc = NULL_REG; } else { - FILE *idfile; - - chdir(savegame_dir); - - if ((idfile = sci_fopen(game_id_file_name, "w"))) { - fprintf(idfile, "%s", game_description); - fclose(idfile); - } else { - sciprintf("Creating the game ID file failed.\n"); - sciprintf("You can still restore from inside the debugger with \"restore_game %s\"\n", savegame_dir); + out->finalize(); + if (out->err()) { + delete out; + sciprintf("Writing the savegame failed.\n"); s->r_acc = NULL_REG; + } else { + delete out; + s->r_acc = make_reg(0, 1); } - - chdir(".."); - s->r_acc = make_reg(0, 1); } - free(game_id_file_name); - _chdir_restoredir(workdir); - free(s->game_version); s->game_version = NULL; @@ -824,39 +710,38 @@ reg_t kSaveGame(state_t *s, int funct_nr, int argc, reg_t *argv) { reg_t kRestoreGame(state_t *s, int funct_nr, int argc, reg_t *argv) { char *game_id = (char*)kernel_dereference_bulk_pointer(s, argv[0], 0); int savedir_nr = UKPV(1); - char *workdir = _chdir_savedir(s); - TEST_DIR_OR_QUIT(workdir); if (_savegame_indices_nr < 0) { - char *game_id_file_name = (char*)sci_malloc(strlen(game_id) + strlen(FREESCI_ID_SUFFIX) + 1); - - strcpy(game_id_file_name, game_id); - strcat(game_id_file_name, FREESCI_ID_SUFFIX); warning("Savegame index list not initialized"); - update_savegame_indices(game_id_file_name); + update_savegame_indices(); } savedir_nr = _savegame_indices[savedir_nr].id; if (savedir_nr > -1) { - char *savedir_name = _k_get_savedir_name(savedir_nr); - state_t *newstate = gamestate_restore(s, savedir_name); - - free(savedir_name); - if (newstate) { - s->successor = newstate; - script_abort_flag = SCRIPT_ABORT_WITH_REPLAY; // Abort current game - s->execution_stack_pos = s->execution_stack_base; - } else { - s->r_acc = make_reg(0, 1); - sciprintf("Restoring failed (game_id = '%s').\n", game_id); + Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager(); + Common::String filename = ((Sci::SciEngine*)g_engine)->getSavegameName(savedir_nr); + Common::SeekableReadStream *in; + if ((in = saveFileMan->openForLoading(filename.c_str()))) { + // found a savegame file + + state_t *newstate = gamestate_restore(s, in); + delete in; + + if (newstate) { + s->successor = newstate; + script_abort_flag = SCRIPT_ABORT_WITH_REPLAY; // Abort current game + s->execution_stack_pos = s->execution_stack_base; + } else { + s->r_acc = make_reg(0, 1); + sciprintf("Restoring failed (game_id = '%s').\n", game_id); + } + return s->r_acc; } - } else { - s->r_acc = make_reg(0, 1); - sciprintf("Savegame #%d not found", savedir_nr); } - _chdir_restoredir(workdir); + s->r_acc = make_reg(0, 1); + sciprintf("Savegame #%d not found!\n", savedir_nr); return s->r_acc; } diff --git a/engines/sci/engine/savegame.cfsml b/engines/sci/engine/savegame.cfsml index bc36a5f53d..e9a8edc7e6 100644 --- a/engines/sci/engine/savegame.cfsml +++ b/engines/sci/engine/savegame.cfsml @@ -24,16 +24,19 @@ */ /* Savegame handling for state_t structs. Makes heavy use of cfsml magic. */ -/* DON'T EDIT savegame.c ! Only modify savegame.cfsml, if something needs +/* DON'T EDIT savegame.cpp ! Only modify savegame.cfsml, if something needs ** to be changed. Refer to freesci/docs/misc/cfsml.spec if you don't understand ** savegame.cfsml. If this doesn't solve your problem, contact the maintainer. */ +#include <stdarg.h> #include "sci/include/sci_memory.h" #include "sci/include/gfx_operations.h" #include "sci/include/sfx_engine.h" #include "sci/include/engine.h" #include "sci/engine/heap.h" +#include "common/stream.h" +#include "common/system.h" #ifdef _MSC_VER #include <direct.h> @@ -50,16 +53,77 @@ ** - File input/output state (this is likely not to happen) */ + +const unsigned int PRINTFBUFLEN = 128; +int WSprintf(Common::WriteStream* str, const char *format, ...) { + va_list args; + char buf[PRINTFBUFLEN]; // default buffer to prevent new in common case + char* writebuf = buf; + + unsigned int s = PRINTFBUFLEN; + unsigned int outsize; + while (true) { + va_start(args, format); + outsize = vsnprintf(writebuf, s, format, args); + va_end(args); + + if (outsize == s) { + if (s > 16384) { // there are limits... + delete[] writebuf; + warning("Saving failed: line much too long"); + return 0; + } + s *= 2; + if (writebuf != buf) delete[] writebuf; + writebuf = new char[s]; + } else { + break; + } + } + + uint32 ret = str->write(writebuf, outsize); + + if (writebuf != buf) delete[] writebuf; + + return ret; +} + +// Only supports scanf on a full line +int SRSscanf(Common::SeekableReadStream* str, const char *format, ...) { + assert(strlen(format) > 0 && format[strlen(format)-1] == '\n'); + va_list args; + Common::String line = str->readLine() + "\n"; + + va_start(args, format); + int ret = vsscanf(line.c_str(), format, args); + va_end(args); + + return ret; +} + +int SRSgetc(Common::SeekableReadStream* str) { + char c = str->readSByte(); + if (str->err() || str->eos()) + return EOF; + return c; +} + +char* SRSgets(char* s, int size, Common::SeekableReadStream* str) { + return str->readLine_NEW(s, size); +} + + + static state_t *_global_save_state; // Needed for some graphical stuff. #define FILE_VERSION _global_save_state->savegame_version -void write_reg_t(FILE *fh, reg_t *foo) { - fprintf(fh, PREG, PRINT_REG(*foo)); +void write_reg_t(Common::WriteStream *fh, reg_t *foo) { + WSprintf(fh, PREG, PRINT_REG(*foo)); } -int read_reg_t(FILE *fh, reg_t *foo, const char *lastval, int *line, int *hiteof) { +int read_reg_t(Common::SeekableReadStream *fh, reg_t *foo, const char *lastval, int *line, int *hiteof) { int segment, offset; if (sscanf(lastval, PREG, &segment, &offset) < 2) { @@ -71,22 +135,22 @@ int read_reg_t(FILE *fh, reg_t *foo, const char *lastval, int *line, int *hiteof return 0; } -void write_sci_version(FILE *fh, sci_version_t *foo) { - fprintf(fh, "%d.%03d.%03d", SCI_VERSION_MAJOR(*foo), SCI_VERSION_MINOR(*foo), SCI_VERSION_PATCHLEVEL(*foo)); +void write_sci_version(Common::WriteStream *fh, sci_version_t *foo) { + WSprintf(fh, "%d.%03d.%03d", SCI_VERSION_MAJOR(*foo), SCI_VERSION_MINOR(*foo), SCI_VERSION_PATCHLEVEL(*foo)); } -int read_sci_version(FILE *fh, sci_version_t *foo, const char *lastval, int *line, int *hiteof) { +int read_sci_version(Common::SeekableReadStream *fh, sci_version_t *foo, const char *lastval, int *line, int *hiteof) { return version_parse(lastval, foo); } -void write_PTN(FILE *fh, parse_tree_node_t *foo) { +void write_PTN(Common::WriteStream *fh, parse_tree_node_t *foo) { if (foo->type == PARSE_TREE_NODE_LEAF) - fprintf(fh, "L%d", foo->content.value); + WSprintf(fh, "L%d", foo->content.value); else - fprintf(fh, "B(%d,%d)", foo->content.branches[0], foo->content.branches[1]); + WSprintf(fh, "B(%d,%d)", foo->content.branches[0], foo->content.branches[1]); } -int read_PTN(FILE *fh, parse_tree_node_t *foo, const char *lastval, int *line, int *hiteof) { +int read_PTN(Common::SeekableReadStream *fh, parse_tree_node_t *foo, const char *lastval, int *line, int *hiteof) { if (lastval[0] == 'L') { const char *c = lastval + 1; char *strend; @@ -140,22 +204,22 @@ int read_PTN(FILE *fh, parse_tree_node_t *foo, const char *lastval, int *line, i } -void write_menubar_tp(FILE *fh, menubar_t **foo); -int read_menubar_tp(FILE *fh, menubar_t **foo, const char *lastval, int *line, int *hiteof); +void write_menubar_tp(Common::WriteStream *fh, menubar_t **foo); +int read_menubar_tp(Common::SeekableReadStream *fh, menubar_t **foo, const char *lastval, int *line, int *hiteof); -void write_mem_obj_tp(FILE *fh, mem_obj_t **foo); -int read_mem_obj_tp(FILE *fh, mem_obj_t **foo, const char *lastval, int *line, int *hiteof); +void write_mem_obj_tp(Common::WriteStream *fh, mem_obj_t **foo); +int read_mem_obj_tp(Common::SeekableReadStream *fh, mem_obj_t **foo, const char *lastval, int *line, int *hiteof); -void write_int_hash_map_tp(FILE *fh, int_hash_map_t **foo); -int read_int_hash_map_tp(FILE *fh, int_hash_map_t **foo, const char *lastval, int *line, int *hiteof); +void write_int_hash_map_tp(Common::WriteStream *fh, int_hash_map_t **foo); +int read_int_hash_map_tp(Common::SeekableReadStream *fh, int_hash_map_t **foo, const char *lastval, int *line, int *hiteof); -void write_songlib_t(FILE *fh, songlib_t *foo); -int read_songlib_t(FILE *fh, songlib_t *foo, const char *lastval, int *line, int *hiteof); +void write_songlib_t(Common::WriteStream *fh, songlib_t *foo); +int read_songlib_t(Common::SeekableReadStream *fh, songlib_t *foo, const char *lastval, int *line, int *hiteof); -void write_int_hash_map_node_tp(FILE *fh, int_hash_map_t::node_t **foo); -int read_int_hash_map_node_tp(FILE *fh, int_hash_map_t::node_t **foo, const char *lastval, int *line, int *hiteof); +void write_int_hash_map_node_tp(Common::WriteStream *fh, int_hash_map_t::node_t **foo); +int read_int_hash_map_node_tp(Common::SeekableReadStream *fh, int_hash_map_t::node_t **foo, const char *lastval, int *line, int *hiteof); -int read_song_tp(FILE *fh, song_t **foo, const char *lastval, int *line, int *hiteof); +int read_song_tp(Common::SeekableReadStream *fh, song_t **foo, const char *lastval, int *line, int *hiteof); typedef mem_obj_t *mem_obj_ptr; @@ -254,6 +318,15 @@ RECORD sfx_state_t "sfx_state_t" { songlib_t songlib; } +RECORD SavegameMetadata "SavegameMetadata" { + string savegame_name; + int savegame_version; + string game_version; + sci_version_t version; + int savegame_date; + int savegame_time; +} + RECORD state_t "state_t" { int savegame_version; @@ -382,41 +455,45 @@ RECORD dynmem_t "dynmem_t" { %END CFSML -void write_songlib_t(FILE *fh, songlib_t *songlib) { +void write_songlib_t(Common::WriteStream *fh, songlib_t *songlib) { song_t *seeker = *(songlib->lib); int songcount = song_lib_count(*songlib); - fprintf(fh, "{\n"); - fprintf(fh, "songcount = %d\n", songcount); - fprintf(fh, "list = \n"); - fprintf(fh, "[\n"); + WSprintf(fh, "{\n"); + WSprintf(fh, "songcount = %d\n", songcount); + WSprintf(fh, "list = \n"); + WSprintf(fh, "[\n"); while (seeker) { seeker->restore_time = seeker->it->get_timepos(seeker->it); %CFSMLWRITE song_t seeker INTO fh; seeker = seeker->next; } - fprintf(fh, "]\n"); - fprintf(fh, "}\n"); + WSprintf(fh, "]\n"); + WSprintf(fh, "}\n"); } -int read_songlib_t(FILE *fh, songlib_t *songlib, const char *lastval, int *line, int *hiteof) { +int read_songlib_t(Common::SeekableReadStream *fh, songlib_t *songlib, const char *lastval, int *line, int *hiteof) { int songcount; int i; song_t *newsong; int oldstatus; - fscanf(fh, "{\n"); - fscanf(fh, "songcount = %d\n", &songcount); - fscanf(fh, "list = \n"); - fscanf(fh, "[\n"); + if (strcmp(lastval, "{")) { + _cfsml_error("Opening brackets expected at line %d\n", *line); + return CFSML_FAILURE; + } + // FIXME: error checking + SRSscanf(fh, "songcount = %d\n", &songcount); + SRSscanf(fh, "list = \n"); + SRSscanf(fh, "[\n"); *line += 4; song_lib_init(songlib); for (i = 0; i < songcount; i++) { %CFSMLREAD song_tp &newsong FROM fh ERRVAR *hiteof FIRSTTOKEN lastval LINECOUNTER *line; song_lib_add(*songlib, newsong); } - fscanf(fh, "]\n"); - fscanf(fh, "}\n");; + SRSscanf(fh, "]\n"); + SRSscanf(fh, "}\n"); *line += 2; return 0; } @@ -449,17 +526,17 @@ int mem_obj_string_to_enum(const char *str) { static int bucket_length; -void write_int_hash_map_tp(FILE *fh, int_hash_map_t **foo) { +void write_int_hash_map_tp(Common::WriteStream *fh, int_hash_map_t **foo) { %CFSMLWRITE int_hash_map_t *foo INTO fh; } -void write_song_tp(FILE *fh, song_t **foo) { +void write_song_tp(Common::WriteStream *fh, song_t **foo) { %CFSMLWRITE song_t *foo INTO fh; } song_iterator_t *build_iterator(state_t *s, int song_nr, int type, songit_id_t id); -int read_song_tp(FILE *fh, song_t **foo, const char *lastval, int *line, int *hiteof) { +int read_song_tp(Common::SeekableReadStream *fh, song_t **foo, const char *lastval, int *line, int *hiteof) { char *token; int assignment; *foo = (song_t*) malloc(sizeof(song_t)); @@ -471,27 +548,27 @@ int read_song_tp(FILE *fh, song_t **foo, const char *lastval, int *line, int *hi return 0; } -int read_int_hash_map_tp(FILE *fh, int_hash_map_t **foo, const char *lastval, int *line, int *hiteof) { +int read_int_hash_map_tp(Common::SeekableReadStream *fh, int_hash_map_t **foo, const char *lastval, int *line, int *hiteof) { *foo = new int_hash_map_t; %CFSMLREAD int_hash_map_t (*foo) FROM fh ERRVAR *hiteof FIRSTTOKEN lastval LINECOUNTER *line; (*foo)->holes = NULL; return 0; } -void write_int_hash_map_node_tp(FILE *fh, int_hash_map_t::node_t **foo) { +void write_int_hash_map_node_tp(Common::WriteStream *fh, int_hash_map_t::node_t **foo) { if (!(*foo)) { - fputs("\\null", fh); + WSprintf(fh, "\\null"); } else { - fprintf(fh,"[\n%d=>%d\n", (*foo)->name, (*foo)->value); + WSprintf(fh,"[\n%d=>%d\n", (*foo)->name, (*foo)->value); if ((*foo)->next) { %CFSMLWRITE int_hash_map_node_tp &((*foo)->next) INTO fh; } else - fputc('L', fh); - fputs("]", fh); + WSprintf(fh, "L"); + WSprintf(fh, "]"); } } -int read_int_hash_map_node_tp(FILE *fh, int_hash_map_t::node_t **foo, const char *lastval, int *line, int *hiteof) { +int read_int_hash_map_node_tp(Common::SeekableReadStream *fh, int_hash_map_t::node_t **foo, const char *lastval, int *line, int *hiteof) { static char buffer[80]; if (lastval[0] == '\\') { @@ -505,7 +582,7 @@ int read_int_hash_map_node_tp(FILE *fh, int_hash_map_t::node_t **foo, const char do { (*line)++; - fgets(buffer, 80, fh); + SRSgets(buffer, 80, fh); if (buffer[0] == 'L') { (*foo)->next = NULL; buffer[0] = buffer[1]; @@ -527,16 +604,16 @@ int read_int_hash_map_node_tp(FILE *fh, int_hash_map_t::node_t **foo, const char return 0; } -void write_menubar_tp(FILE *fh, menubar_t **foo) { +void write_menubar_tp(Common::WriteStream *fh, menubar_t **foo) { if (*foo) { %CFSMLWRITE menubar_t (*foo) INTO fh; } else { // Nothing to write - fputs("\\null\\", fh); + WSprintf(fh, "\\null\\"); } } -int read_menubar_tp(FILE *fh, menubar_t **foo, const char *lastval, int *line, int *hiteof) { +int read_menubar_tp(Common::SeekableReadStream *fh, menubar_t **foo, const char *lastval, int *line, int *hiteof) { if (lastval[0] == '\\') { *foo = NULL; // No menu bar } else { @@ -546,8 +623,8 @@ int read_menubar_tp(FILE *fh, menubar_t **foo, const char *lastval, int *line, i return *hiteof; } -void write_mem_obj_t(FILE *fh, mem_obj_t *foo) { - fprintf(fh, "%s\n", mem_obj_string_names[foo->type].name); +void write_mem_obj_t(Common::WriteStream *fh, mem_obj_t *foo) { + WSprintf(fh, "%s\n", mem_obj_string_names[foo->type].name); %CFSMLWRITE int &foo->segmgr_id INTO fh; switch (foo->type) { case MEM_OBJ_SCRIPT: @@ -579,7 +656,7 @@ void write_mem_obj_t(FILE *fh, mem_obj_t *foo) { } } -int read_mem_obj_t(FILE *fh, mem_obj_t *foo, const char *lastval, int *line, int *hiteof) { +int read_mem_obj_t(Common::SeekableReadStream *fh, mem_obj_t *foo, const char *lastval, int *line, int *hiteof) { char buffer[80]; foo->type = mem_obj_string_to_enum(lastval); if (foo->type < 0) { @@ -622,15 +699,15 @@ int read_mem_obj_t(FILE *fh, mem_obj_t *foo, const char *lastval, int *line, int return *hiteof; } -void write_mem_obj_tp(FILE *fh, mem_obj_t **foo) { +void write_mem_obj_tp(Common::WriteStream *fh, mem_obj_t **foo) { if (*foo) { %CFSMLWRITE mem_obj_t (*foo) INTO fh; } else { // Nothing to write - fputs("\\null\\", fh); + WSprintf(fh, "\\null\\"); } } -int read_mem_obj_tp(FILE *fh, mem_obj_t **foo, const char *lastval, int *line, int *hiteof) { +int read_mem_obj_tp(Common::SeekableReadStream *fh, mem_obj_t **foo, const char *lastval, int *line, int *hiteof) { if (lastval[0] == '\\') { *foo = NULL; // No menu bar } else { @@ -648,12 +725,23 @@ void _gamestate_unfrob(state_t *s) { } -int gamestate_save(state_t *s, char *dirname) { - FILE *fh; +int gamestate_save(state_t *s, Common::WriteStream *fh, const char* savename) { sci_dir_t dir; char *filename; int fd; + tm curTime; + g_system->getTimeAndDate(curTime); + + SavegameMetadata *meta = new SavegameMetadata; + meta->savegame_version = FREESCI_CURRENT_SAVEGAME_VERSION; + meta->savegame_name = savename; + meta->version = s->version; + meta->game_version = s->game_version; + meta->savegame_date = ((curTime.tm_mday & 0xFF) << 24) | (((curTime.tm_mon + 1) & 0xFF) << 16) | ((curTime.tm_year + 1900) & 0xFFFF); + meta->savegame_time = ((curTime.tm_hour & 0xFF) << 16) | (((curTime.tm_min) & 0xFF) << 8) | ((curTime.tm_sec) & 0xFF); + fprintf(stderr, "date/time: %d %d\n", meta->savegame_date, meta->savegame_time); + _global_save_state = s; s->savegame_version = FREESCI_CURRENT_SAVEGAME_VERSION; s->dyn_views_list_serial = (s->dyn_views)? s->dyn_views->serial : -2; @@ -665,22 +753,6 @@ int gamestate_save(state_t *s, char *dirname) { return 1; } - scimkdir (dirname, 0700); - - if (chdir(dirname)) { - sciprintf("Could not enter directory '%s'\n", dirname); - return 1; - } - - sci_init_dir(&dir); - filename = sci_find_first(&dir, "*"); - while (filename) { - if (strcmp(filename, "..") && strcmp(filename, ".")) - unlink(filename); // Delete all files in directory - filename = sci_find_next(&dir); - } - sci_finish_find(&dir); - /* if (s->sound_server) { if ((s->sound_server->save)(s, dirname)) { @@ -690,19 +762,16 @@ int gamestate_save(state_t *s, char *dirname) { } } */ - fh = fopen("state", "w" FO_TEXT); - // Calculate the time spent with this game s->game_time = time(NULL) - s->game_start_time.tv_sec; + %CFSMLWRITE SavegameMetadata meta INTO fh; %CFSMLWRITE state_t s INTO fh; - fclose(fh); + delete meta; _gamestate_unfrob(s); - chdir(".."); - return 0; } @@ -948,19 +1017,13 @@ static void reconstruct_sounds(state_t *s) { } } -state_t *gamestate_restore(state_t *s, char *dirname) { - FILE *fh; +state_t *gamestate_restore(state_t *s, Common::SeekableReadStream *fh) { int fd; int i; int read_eof = 0; state_t *retval; songlib_t temp; - if (chdir(dirname)) { - sciprintf("Game state '%s' does not exist\n", dirname); - return NULL; - } - /* if (s->sound_server) { if ((s->sound_server->restore)(s, dirname)) { @@ -978,12 +1041,23 @@ state_t *gamestate_restore(state_t *s, char *dirname) { _global_save_state = retval; retval->gfx_state = s->gfx_state; - fh = fopen("state", "r" FO_TEXT); - if (!fh) { - free(retval); + SavegameMetadata* meta = new SavegameMetadata; + memset(retval, 0, sizeof(SavegameMetadata)); + + %CFSMLREAD-ATOMIC SavegameMetadata meta FROM fh ERRVAR read_eof; + if ((meta->savegame_version < FREESCI_MINIMUM_SAVEGAME_VERSION) || + (meta->savegame_version > FREESCI_CURRENT_SAVEGAME_VERSION)) { + if (meta->savegame_version < FREESCI_MINIMUM_SAVEGAME_VERSION) + sciprintf("Old savegame version detected- can't load\n"); + else + sciprintf("Savegame version is %d- maximum supported is %0d\n", meta->savegame_version, FREESCI_CURRENT_SAVEGAME_VERSION); + + delete meta; return NULL; } + delete meta; + // Backwards compatibility settings retval->dyn_views = NULL; retval->drop_views = NULL; @@ -995,19 +1069,6 @@ state_t *gamestate_restore(state_t *s, char *dirname) { %CFSMLREAD-ATOMIC state_t retval FROM fh ERRVAR read_eof; - fclose(fh); - - if ((retval->savegame_version < FREESCI_MINIMUM_SAVEGAME_VERSION) || (retval->savegame_version > FREESCI_CURRENT_SAVEGAME_VERSION)) { - if (retval->savegame_version < FREESCI_MINIMUM_SAVEGAME_VERSION) - sciprintf("Old savegame version detected- can't load\n"); - else - sciprintf("Savegame version is %d- maximum supported is %0d\n", retval->savegame_version, FREESCI_CURRENT_SAVEGAME_VERSION); - - chdir(".."); - free(retval); - return NULL; - } - sfx_exit(&s->sound); _gamestate_unfrob(retval); @@ -1097,7 +1158,27 @@ state_t *gamestate_restore(state_t *s, char *dirname) { retval->sound.debug = s->sound.debug; reconstruct_sounds(retval); - chdir (".."); - return retval; } + +bool get_savegame_metadata(Common::SeekableReadStream* stream, SavegameMetadata* meta) { + int read_eof = 0; + + %CFSMLREAD-ATOMIC SavegameMetadata meta FROM stream ERRVAR read_eof; + + if (read_eof) + return false; + + if ((meta->savegame_version < FREESCI_MINIMUM_SAVEGAME_VERSION) || + (meta->savegame_version > FREESCI_CURRENT_SAVEGAME_VERSION)) { + if (meta->savegame_version < FREESCI_MINIMUM_SAVEGAME_VERSION) + sciprintf("Old savegame version detected- can't load\n"); + else + sciprintf("Savegame version is %d- maximum supported is %0d\n", meta->savegame_version, FREESCI_CURRENT_SAVEGAME_VERSION); + + return false; + } + + return true; +} + diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index a64f76ccae..c075b03def 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -24,16 +24,19 @@ */ /* Savegame handling for state_t structs. Makes heavy use of cfsml magic. */ -/* DON'T EDIT savegame.c ! Only modify savegame.cfsml, if something needs +/* DON'T EDIT savegame.cpp ! Only modify savegame.cfsml, if something needs ** to be changed. Refer to freesci/docs/misc/cfsml.spec if you don't understand ** savegame.cfsml. If this doesn't solve your problem, contact the maintainer. */ +#include <stdarg.h> #include "sci/include/sci_memory.h" #include "sci/include/gfx_operations.h" #include "sci/include/sfx_engine.h" #include "sci/include/engine.h" #include "sci/engine/heap.h" +#include "common/stream.h" +#include "common/system.h" #ifdef _MSC_VER #include <direct.h> @@ -50,16 +53,77 @@ ** - File input/output state (this is likely not to happen) */ + +const unsigned int PRINTFBUFLEN = 128; +int WSprintf(Common::WriteStream* str, const char *format, ...) { + va_list args; + char buf[PRINTFBUFLEN]; // default buffer to prevent new in common case + char* writebuf = buf; + + unsigned int s = PRINTFBUFLEN; + unsigned int outsize; + while (true) { + va_start(args, format); + outsize = vsnprintf(writebuf, s, format, args); + va_end(args); + + if (outsize == s) { + if (s > 16384) { // there are limits... + delete[] writebuf; + warning("Saving failed: line much too long"); + return 0; + } + s *= 2; + if (writebuf != buf) delete[] writebuf; + writebuf = new char[s]; + } else { + break; + } + } + + uint32 ret = str->write(writebuf, outsize); + + if (writebuf != buf) delete[] writebuf; + + return ret; +} + +// Only supports scanf on a full line +int SRSscanf(Common::SeekableReadStream* str, const char *format, ...) { + assert(strlen(format) > 0 && format[strlen(format)-1] == '\n'); + va_list args; + Common::String line = str->readLine() + "\n"; + + va_start(args, format); + int ret = vsscanf(line.c_str(), format, args); + va_end(args); + + return ret; +} + +int SRSgetc(Common::SeekableReadStream* str) { + char c = str->readSByte(); + if (str->err() || str->eos()) + return EOF; + return c; +} + +char* SRSgets(char* s, int size, Common::SeekableReadStream* str) { + return str->readLine_NEW(s, size); +} + + + static state_t *_global_save_state; // Needed for some graphical stuff. #define FILE_VERSION _global_save_state->savegame_version -void write_reg_t(FILE *fh, reg_t *foo) { - fprintf(fh, PREG, PRINT_REG(*foo)); +void write_reg_t(Common::WriteStream *fh, reg_t *foo) { + WSprintf(fh, PREG, PRINT_REG(*foo)); } -int read_reg_t(FILE *fh, reg_t *foo, const char *lastval, int *line, int *hiteof) { +int read_reg_t(Common::SeekableReadStream *fh, reg_t *foo, const char *lastval, int *line, int *hiteof) { int segment, offset; if (sscanf(lastval, PREG, &segment, &offset) < 2) { @@ -71,22 +135,22 @@ int read_reg_t(FILE *fh, reg_t *foo, const char *lastval, int *line, int *hiteof return 0; } -void write_sci_version(FILE *fh, sci_version_t *foo) { - fprintf(fh, "%d.%03d.%03d", SCI_VERSION_MAJOR(*foo), SCI_VERSION_MINOR(*foo), SCI_VERSION_PATCHLEVEL(*foo)); +void write_sci_version(Common::WriteStream *fh, sci_version_t *foo) { + WSprintf(fh, "%d.%03d.%03d", SCI_VERSION_MAJOR(*foo), SCI_VERSION_MINOR(*foo), SCI_VERSION_PATCHLEVEL(*foo)); } -int read_sci_version(FILE *fh, sci_version_t *foo, const char *lastval, int *line, int *hiteof) { +int read_sci_version(Common::SeekableReadStream *fh, sci_version_t *foo, const char *lastval, int *line, int *hiteof) { return version_parse(lastval, foo); } -void write_PTN(FILE *fh, parse_tree_node_t *foo) { +void write_PTN(Common::WriteStream *fh, parse_tree_node_t *foo) { if (foo->type == PARSE_TREE_NODE_LEAF) - fprintf(fh, "L%d", foo->content.value); + WSprintf(fh, "L%d", foo->content.value); else - fprintf(fh, "B(%d,%d)", foo->content.branches[0], foo->content.branches[1]); + WSprintf(fh, "B(%d,%d)", foo->content.branches[0], foo->content.branches[1]); } -int read_PTN(FILE *fh, parse_tree_node_t *foo, const char *lastval, int *line, int *hiteof) { +int read_PTN(Common::SeekableReadStream *fh, parse_tree_node_t *foo, const char *lastval, int *line, int *hiteof) { if (lastval[0] == 'L') { const char *c = lastval + 1; char *strend; @@ -140,22 +204,22 @@ int read_PTN(FILE *fh, parse_tree_node_t *foo, const char *lastval, int *line, i } -void write_menubar_tp(FILE *fh, menubar_t **foo); -int read_menubar_tp(FILE *fh, menubar_t **foo, const char *lastval, int *line, int *hiteof); +void write_menubar_tp(Common::WriteStream *fh, menubar_t **foo); +int read_menubar_tp(Common::SeekableReadStream *fh, menubar_t **foo, const char *lastval, int *line, int *hiteof); -void write_mem_obj_tp(FILE *fh, mem_obj_t **foo); -int read_mem_obj_tp(FILE *fh, mem_obj_t **foo, const char *lastval, int *line, int *hiteof); +void write_mem_obj_tp(Common::WriteStream *fh, mem_obj_t **foo); +int read_mem_obj_tp(Common::SeekableReadStream *fh, mem_obj_t **foo, const char *lastval, int *line, int *hiteof); -void write_int_hash_map_tp(FILE *fh, int_hash_map_t **foo); -int read_int_hash_map_tp(FILE *fh, int_hash_map_t **foo, const char *lastval, int *line, int *hiteof); +void write_int_hash_map_tp(Common::WriteStream *fh, int_hash_map_t **foo); +int read_int_hash_map_tp(Common::SeekableReadStream *fh, int_hash_map_t **foo, const char *lastval, int *line, int *hiteof); -void write_songlib_t(FILE *fh, songlib_t *foo); -int read_songlib_t(FILE *fh, songlib_t *foo, const char *lastval, int *line, int *hiteof); +void write_songlib_t(Common::WriteStream *fh, songlib_t *foo); +int read_songlib_t(Common::SeekableReadStream *fh, songlib_t *foo, const char *lastval, int *line, int *hiteof); -void write_int_hash_map_node_tp(FILE *fh, int_hash_map_t::node_t **foo); -int read_int_hash_map_node_tp(FILE *fh, int_hash_map_t::node_t **foo, const char *lastval, int *line, int *hiteof); +void write_int_hash_map_node_tp(Common::WriteStream *fh, int_hash_map_t::node_t **foo); +int read_int_hash_map_node_tp(Common::SeekableReadStream *fh, int_hash_map_t::node_t **foo, const char *lastval, int *line, int *hiteof); -int read_song_tp(FILE *fh, song_t **foo, const char *lastval, int *line, int *hiteof); +int read_song_tp(Common::SeekableReadStream *fh, song_t **foo, const char *lastval, int *line, int *hiteof); typedef mem_obj_t *mem_obj_ptr; @@ -173,7 +237,7 @@ RECORD synonym_t "synonym_t" { // Auto-generated CFSML declaration and function block -#line 740 "savegame.cfsml" +#line 739 "savegame.cfsml" #define CFSML_SUCCESS 0 #define CFSML_FAILURE 1 @@ -283,7 +347,7 @@ static char *_cfsml_unmangle_string(const char *s, unsigned int length) { return (char *)sci_realloc(target, strlen(target) + 1); } -static char *_cfsml_get_identifier(FILE *fd, int *line, int *hiteof, int *assignment) { +static char *_cfsml_get_identifier(Common::SeekableReadStream *fd, int *line, int *hiteof, int *assignment) { int c; int mem = 32; int pos = 0; @@ -295,7 +359,7 @@ static char *_cfsml_get_identifier(FILE *fd, int *line, int *hiteof, int *assign _cfsml_last_identifier_retrieved = NULL; } - while (isspace(c = fgetc(fd)) && (c != EOF)); + while (isspace(c = SRSgetc(fd)) && (c != EOF)); if (c == EOF) { _cfsml_error("Unexpected end of file at line %d\n", *line); free(retval); @@ -303,12 +367,11 @@ static char *_cfsml_get_identifier(FILE *fd, int *line, int *hiteof, int *assign return NULL; } - ungetc(c, fd); - - while (((c = fgetc(fd)) != EOF) && ((pos == 0) || (c != '\n')) && (c != '=')) { + int first = 1; + while ((first || (c = SRSgetc(fd)) != EOF) && ((pos == 0) || (c != '\n')) && (c != '=')) { + first = 0; if (pos == mem - 1) // Need more memory? retval = (char *)sci_realloc(retval, mem *= 2); - if (!isspace(c)) { if (done) { _cfsml_error("Single word identifier expected at line %d\n", *line); @@ -348,12 +411,12 @@ static char *_cfsml_get_identifier(FILE *fd, int *line, int *hiteof, int *assign retval = (char *)sci_realloc(retval, mem += 1); retval[pos] = 0; // Terminate string -#line 282 "savegame.cfsml" +#line 281 "savegame.cfsml" return _cfsml_last_identifier_retrieved = retval; } -static char *_cfsml_get_value(FILE *fd, int *line, int *hiteof) { +static char *_cfsml_get_value(Common::SeekableReadStream *fd, int *line, int *hiteof) { int c; int mem = 64; int pos = 0; @@ -364,7 +427,7 @@ static char *_cfsml_get_value(FILE *fd, int *line, int *hiteof) { _cfsml_last_value_retrieved = NULL; } - while (((c = fgetc(fd)) != EOF) && (c != '\n')) { + while (((c = SRSgetc(fd)) != EOF) && (c != '\n')) { if (pos == mem - 1) // Need more memory? retval = (char *)sci_realloc(retval, mem *= 2); @@ -391,151 +454,155 @@ static char *_cfsml_get_value(FILE *fd, int *line, int *hiteof) { retval = (char *)sci_realloc(retval, mem += 1); retval[pos] = 0; // Terminate string -#line 334 "savegame.cfsml" +#line 333 "savegame.cfsml" return (_cfsml_last_value_retrieved = (char *)sci_realloc(retval, strlen(retval) + 1)); // Re-allocate; this value might be used for quite some while (if we are restoring a string) } -#line 384 "savegame.cfsml" -static void _cfsml_write_sfx_state_t(FILE *fh, sfx_state_t* save_struc); -static int _cfsml_read_sfx_state_t(FILE *fh, sfx_state_t* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "savegame.cfsml" +static void _cfsml_write_sfx_state_t(Common::WriteStream *fh, sfx_state_t* save_struc); +static int _cfsml_read_sfx_state_t(Common::SeekableReadStream *fh, sfx_state_t* save_struc, const char *lastval, int *line, int *hiteof); + +#line 383 "savegame.cfsml" +static void _cfsml_write_clone_entry_t(Common::WriteStream *fh, clone_entry_t* save_struc); +static int _cfsml_read_clone_entry_t(Common::SeekableReadStream *fh, clone_entry_t* save_struc, const char *lastval, int *line, int *hiteof); -#line 384 "savegame.cfsml" -static void _cfsml_write_clone_entry_t(FILE *fh, clone_entry_t* save_struc); -static int _cfsml_read_clone_entry_t(FILE *fh, clone_entry_t* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "savegame.cfsml" +static void _cfsml_write_object_t(Common::WriteStream *fh, object_t* save_struc); +static int _cfsml_read_object_t(Common::SeekableReadStream *fh, object_t* save_struc, const char *lastval, int *line, int *hiteof); -#line 384 "savegame.cfsml" -static void _cfsml_write_object_t(FILE *fh, object_t* save_struc); -static int _cfsml_read_object_t(FILE *fh, object_t* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "savegame.cfsml" +static void _cfsml_write_string(Common::WriteStream *fh, char ** save_struc); +static int _cfsml_read_string(Common::SeekableReadStream *fh, char ** save_struc, const char *lastval, int *line, int *hiteof); -#line 384 "savegame.cfsml" -static void _cfsml_write_string(FILE *fh, char ** save_struc); -static int _cfsml_read_string(FILE *fh, char ** save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "savegame.cfsml" +static void _cfsml_write_menubar_t(Common::WriteStream *fh, menubar_t* save_struc); +static int _cfsml_read_menubar_t(Common::SeekableReadStream *fh, menubar_t* save_struc, const char *lastval, int *line, int *hiteof); -#line 384 "savegame.cfsml" -static void _cfsml_write_menubar_t(FILE *fh, menubar_t* save_struc); -static int _cfsml_read_menubar_t(FILE *fh, menubar_t* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "savegame.cfsml" +static void _cfsml_write_size_t(Common::WriteStream *fh, size_t* save_struc); +static int _cfsml_read_size_t(Common::SeekableReadStream *fh, size_t* save_struc, const char *lastval, int *line, int *hiteof); -#line 384 "savegame.cfsml" -static void _cfsml_write_size_t(FILE *fh, size_t* save_struc); -static int _cfsml_read_size_t(FILE *fh, size_t* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "savegame.cfsml" +static void _cfsml_write_list_entry_t(Common::WriteStream *fh, list_entry_t* save_struc); +static int _cfsml_read_list_entry_t(Common::SeekableReadStream *fh, list_entry_t* save_struc, const char *lastval, int *line, int *hiteof); -#line 384 "savegame.cfsml" -static void _cfsml_write_list_entry_t(FILE *fh, list_entry_t* save_struc); -static int _cfsml_read_list_entry_t(FILE *fh, list_entry_t* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "savegame.cfsml" +static void _cfsml_write_int_hash_map_t(Common::WriteStream *fh, int_hash_map_t* save_struc); +static int _cfsml_read_int_hash_map_t(Common::SeekableReadStream *fh, int_hash_map_t* save_struc, const char *lastval, int *line, int *hiteof); -#line 384 "savegame.cfsml" -static void _cfsml_write_int_hash_map_t(FILE *fh, int_hash_map_t* save_struc); -static int _cfsml_read_int_hash_map_t(FILE *fh, int_hash_map_t* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "savegame.cfsml" +static void _cfsml_write_song_t(Common::WriteStream *fh, song_t* save_struc); +static int _cfsml_read_song_t(Common::SeekableReadStream *fh, song_t* save_struc, const char *lastval, int *line, int *hiteof); -#line 384 "savegame.cfsml" -static void _cfsml_write_song_t(FILE *fh, song_t* save_struc); -static int _cfsml_read_song_t(FILE *fh, song_t* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "savegame.cfsml" +static void _cfsml_write_menu_item_t(Common::WriteStream *fh, menu_item_t* save_struc); +static int _cfsml_read_menu_item_t(Common::SeekableReadStream *fh, menu_item_t* save_struc, const char *lastval, int *line, int *hiteof); -#line 384 "savegame.cfsml" -static void _cfsml_write_menu_item_t(FILE *fh, menu_item_t* save_struc); -static int _cfsml_read_menu_item_t(FILE *fh, menu_item_t* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "savegame.cfsml" +static void _cfsml_write_node_entry_t(Common::WriteStream *fh, node_entry_t* save_struc); +static int _cfsml_read_node_entry_t(Common::SeekableReadStream *fh, node_entry_t* save_struc, const char *lastval, int *line, int *hiteof); -#line 384 "savegame.cfsml" -static void _cfsml_write_node_entry_t(FILE *fh, node_entry_t* save_struc); -static int _cfsml_read_node_entry_t(FILE *fh, node_entry_t* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "savegame.cfsml" +static void _cfsml_write_seg_id_t(Common::WriteStream *fh, seg_id_t* save_struc); +static int _cfsml_read_seg_id_t(Common::SeekableReadStream *fh, seg_id_t* save_struc, const char *lastval, int *line, int *hiteof); -#line 384 "savegame.cfsml" -static void _cfsml_write_seg_id_t(FILE *fh, seg_id_t* save_struc); -static int _cfsml_read_seg_id_t(FILE *fh, seg_id_t* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "savegame.cfsml" +static void _cfsml_write_dynmem_t(Common::WriteStream *fh, dynmem_t* save_struc); +static int _cfsml_read_dynmem_t(Common::SeekableReadStream *fh, dynmem_t* save_struc, const char *lastval, int *line, int *hiteof); -#line 384 "savegame.cfsml" -static void _cfsml_write_dynmem_t(FILE *fh, dynmem_t* save_struc); -static int _cfsml_read_dynmem_t(FILE *fh, dynmem_t* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "savegame.cfsml" +static void _cfsml_write_local_variables_t(Common::WriteStream *fh, local_variables_t* save_struc); +static int _cfsml_read_local_variables_t(Common::SeekableReadStream *fh, local_variables_t* save_struc, const char *lastval, int *line, int *hiteof); -#line 384 "savegame.cfsml" -static void _cfsml_write_local_variables_t(FILE *fh, local_variables_t* save_struc); -static int _cfsml_read_local_variables_t(FILE *fh, local_variables_t* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "savegame.cfsml" +static void _cfsml_write_state_t(Common::WriteStream *fh, state_t* save_struc); +static int _cfsml_read_state_t(Common::SeekableReadStream *fh, state_t* save_struc, const char *lastval, int *line, int *hiteof); -#line 384 "savegame.cfsml" -static void _cfsml_write_state_t(FILE *fh, state_t* save_struc); -static int _cfsml_read_state_t(FILE *fh, state_t* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "savegame.cfsml" +static void _cfsml_write_node_table_t(Common::WriteStream *fh, node_table_t* save_struc); +static int _cfsml_read_node_table_t(Common::SeekableReadStream *fh, node_table_t* save_struc, const char *lastval, int *line, int *hiteof); -#line 384 "savegame.cfsml" -static void _cfsml_write_node_table_t(FILE *fh, node_table_t* save_struc); -static int _cfsml_read_node_table_t(FILE *fh, node_table_t* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "savegame.cfsml" +static void _cfsml_write_sys_strings_t(Common::WriteStream *fh, sys_strings_t* save_struc); +static int _cfsml_read_sys_strings_t(Common::SeekableReadStream *fh, sys_strings_t* save_struc, const char *lastval, int *line, int *hiteof); -#line 384 "savegame.cfsml" -static void _cfsml_write_sys_strings_t(FILE *fh, sys_strings_t* save_struc); -static int _cfsml_read_sys_strings_t(FILE *fh, sys_strings_t* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "savegame.cfsml" +static void _cfsml_write_byte(Common::WriteStream *fh, byte* save_struc); +static int _cfsml_read_byte(Common::SeekableReadStream *fh, byte* save_struc, const char *lastval, int *line, int *hiteof); -#line 384 "savegame.cfsml" -static void _cfsml_write_byte(FILE *fh, byte* save_struc); -static int _cfsml_read_byte(FILE *fh, byte* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "savegame.cfsml" +static void _cfsml_write_node_t(Common::WriteStream *fh, node_t* save_struc); +static int _cfsml_read_node_t(Common::SeekableReadStream *fh, node_t* save_struc, const char *lastval, int *line, int *hiteof); -#line 384 "savegame.cfsml" -static void _cfsml_write_node_t(FILE *fh, node_t* save_struc); -static int _cfsml_read_node_t(FILE *fh, node_t* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "savegame.cfsml" +static void _cfsml_write_list_table_t(Common::WriteStream *fh, list_table_t* save_struc); +static int _cfsml_read_list_table_t(Common::SeekableReadStream *fh, list_table_t* save_struc, const char *lastval, int *line, int *hiteof); -#line 384 "savegame.cfsml" -static void _cfsml_write_list_table_t(FILE *fh, list_table_t* save_struc); -static int _cfsml_read_list_table_t(FILE *fh, list_table_t* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "savegame.cfsml" +static void _cfsml_write_class_t(Common::WriteStream *fh, class_t* save_struc); +static int _cfsml_read_class_t(Common::SeekableReadStream *fh, class_t* save_struc, const char *lastval, int *line, int *hiteof); -#line 384 "savegame.cfsml" -static void _cfsml_write_class_t(FILE *fh, class_t* save_struc); -static int _cfsml_read_class_t(FILE *fh, class_t* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "savegame.cfsml" +static void _cfsml_write_song_handle_t(Common::WriteStream *fh, song_handle_t* save_struc); +static int _cfsml_read_song_handle_t(Common::SeekableReadStream *fh, song_handle_t* save_struc, const char *lastval, int *line, int *hiteof); -#line 384 "savegame.cfsml" -static void _cfsml_write_song_handle_t(FILE *fh, song_handle_t* save_struc); -static int _cfsml_read_song_handle_t(FILE *fh, song_handle_t* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "savegame.cfsml" +static void _cfsml_write_int(Common::WriteStream *fh, int* save_struc); +static int _cfsml_read_int(Common::SeekableReadStream *fh, int* save_struc, const char *lastval, int *line, int *hiteof); -#line 384 "savegame.cfsml" -static void _cfsml_write_int(FILE *fh, int* save_struc); -static int _cfsml_read_int(FILE *fh, int* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "savegame.cfsml" +static void _cfsml_write_SavegameMetadata(Common::WriteStream *fh, SavegameMetadata* save_struc); +static int _cfsml_read_SavegameMetadata(Common::SeekableReadStream *fh, SavegameMetadata* save_struc, const char *lastval, int *line, int *hiteof); -#line 384 "savegame.cfsml" -static void _cfsml_write_menu_t(FILE *fh, menu_t* save_struc); -static int _cfsml_read_menu_t(FILE *fh, menu_t* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "savegame.cfsml" +static void _cfsml_write_menu_t(Common::WriteStream *fh, menu_t* save_struc); +static int _cfsml_read_menu_t(Common::SeekableReadStream *fh, menu_t* save_struc, const char *lastval, int *line, int *hiteof); -#line 384 "savegame.cfsml" -static void _cfsml_write_clone_table_t(FILE *fh, clone_table_t* save_struc); -static int _cfsml_read_clone_table_t(FILE *fh, clone_table_t* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "savegame.cfsml" +static void _cfsml_write_clone_table_t(Common::WriteStream *fh, clone_table_t* save_struc); +static int _cfsml_read_clone_table_t(Common::SeekableReadStream *fh, clone_table_t* save_struc, const char *lastval, int *line, int *hiteof); -#line 384 "savegame.cfsml" -static void _cfsml_write_clone_t(FILE *fh, clone_t* save_struc); -static int _cfsml_read_clone_t(FILE *fh, clone_t* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "savegame.cfsml" +static void _cfsml_write_clone_t(Common::WriteStream *fh, clone_t* save_struc); +static int _cfsml_read_clone_t(Common::SeekableReadStream *fh, clone_t* save_struc, const char *lastval, int *line, int *hiteof); -#line 384 "savegame.cfsml" -static void _cfsml_write_list_t(FILE *fh, list_t* save_struc); -static int _cfsml_read_list_t(FILE *fh, list_t* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "savegame.cfsml" +static void _cfsml_write_list_t(Common::WriteStream *fh, list_t* save_struc); +static int _cfsml_read_list_t(Common::SeekableReadStream *fh, list_t* save_struc, const char *lastval, int *line, int *hiteof); -#line 384 "savegame.cfsml" -static void _cfsml_write_sys_string_t(FILE *fh, sys_string_t* save_struc); -static int _cfsml_read_sys_string_t(FILE *fh, sys_string_t* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "savegame.cfsml" +static void _cfsml_write_sys_string_t(Common::WriteStream *fh, sys_string_t* save_struc); +static int _cfsml_read_sys_string_t(Common::SeekableReadStream *fh, sys_string_t* save_struc, const char *lastval, int *line, int *hiteof); -#line 384 "savegame.cfsml" -static void _cfsml_write_script_t(FILE *fh, script_t* save_struc); -static int _cfsml_read_script_t(FILE *fh, script_t* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "savegame.cfsml" +static void _cfsml_write_script_t(Common::WriteStream *fh, script_t* save_struc); +static int _cfsml_read_script_t(Common::SeekableReadStream *fh, script_t* save_struc, const char *lastval, int *line, int *hiteof); -#line 384 "savegame.cfsml" -static void _cfsml_write_seg_manager_t(FILE *fh, seg_manager_t* save_struc); -static int _cfsml_read_seg_manager_t(FILE *fh, seg_manager_t* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "savegame.cfsml" +static void _cfsml_write_seg_manager_t(Common::WriteStream *fh, seg_manager_t* save_struc); +static int _cfsml_read_seg_manager_t(Common::SeekableReadStream *fh, seg_manager_t* save_struc, const char *lastval, int *line, int *hiteof); -#line 396 "savegame.cfsml" +#line 395 "savegame.cfsml" static void -_cfsml_write_sfx_state_t(FILE *fh, sfx_state_t* save_struc) +_cfsml_write_sfx_state_t(Common::WriteStream *fh, sfx_state_t* save_struc) { int min, max, i; -#line 416 "savegame.cfsml" - fprintf(fh, "{\n"); - fprintf(fh, "songlib = "); +#line 415 "savegame.cfsml" + WSprintf(fh, "{\n"); + WSprintf(fh, "songlib = "); write_songlib_t(fh, (songlib_t*) &(save_struc->songlib)); - fprintf(fh, "\n"); - fprintf(fh, "}"); + WSprintf(fh, "\n"); + WSprintf(fh, "}"); } -#line 489 "savegame.cfsml" +#line 488 "savegame.cfsml" static int -_cfsml_read_sfx_state_t(FILE *fh, sfx_state_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_sfx_state_t(Common::SeekableReadStream *fh, sfx_state_t* save_struc, const char *lastval, int *line, int *hiteof) { char *token; int min, max, i; -#line 547 "savegame.cfsml" +#line 546 "savegame.cfsml" int assignment, closed, done; if (strcmp(lastval, "{")) { @@ -567,13 +634,13 @@ _cfsml_read_sfx_state_t(FILE *fh, sfx_state_t* save_struc, const char *lastval, return CFSML_FAILURE; } if (!strcmp(token, "songlib")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (read_songlib_t(fh, (songlib_t*) &(save_struc->songlib), value, line, hiteof)) { _cfsml_error("Token expected by read_songlib_t() for songlib at line %d\n", *line); return CFSML_FAILURE; } } else -#line 703 "savegame.cfsml" +#line 702 "savegame.cfsml" { _cfsml_error("sfx_state_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; @@ -583,30 +650,30 @@ _cfsml_read_sfx_state_t(FILE *fh, sfx_state_t* save_struc, const char *lastval, return CFSML_SUCCESS; } -#line 396 "savegame.cfsml" +#line 395 "savegame.cfsml" static void -_cfsml_write_clone_entry_t(FILE *fh, clone_entry_t* save_struc) +_cfsml_write_clone_entry_t(Common::WriteStream *fh, clone_entry_t* save_struc) { int min, max, i; -#line 416 "savegame.cfsml" - fprintf(fh, "{\n"); - fprintf(fh, "next_free = "); +#line 415 "savegame.cfsml" + WSprintf(fh, "{\n"); + WSprintf(fh, "next_free = "); _cfsml_write_int(fh, (int*) &(save_struc->next_free)); - fprintf(fh, "\n"); - fprintf(fh, "entry = "); + WSprintf(fh, "\n"); + WSprintf(fh, "entry = "); _cfsml_write_clone_t(fh, (clone_t*) &(save_struc->entry)); - fprintf(fh, "\n"); - fprintf(fh, "}"); + WSprintf(fh, "\n"); + WSprintf(fh, "}"); } -#line 489 "savegame.cfsml" +#line 488 "savegame.cfsml" static int -_cfsml_read_clone_entry_t(FILE *fh, clone_entry_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_clone_entry_t(Common::SeekableReadStream *fh, clone_entry_t* save_struc, const char *lastval, int *line, int *hiteof) { char *token; int min, max, i; -#line 547 "savegame.cfsml" +#line 546 "savegame.cfsml" int assignment, closed, done; if (strcmp(lastval, "{")) { @@ -638,20 +705,20 @@ _cfsml_read_clone_entry_t(FILE *fh, clone_entry_t* save_struc, const char *lastv return CFSML_FAILURE; } if (!strcmp(token, "next_free")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->next_free), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for next_free at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "entry")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_clone_t(fh, (clone_t*) &(save_struc->entry), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_clone_t() for entry at line %d\n", *line); return CFSML_FAILURE; } } else -#line 703 "savegame.cfsml" +#line 702 "savegame.cfsml" { _cfsml_error("clone_entry_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; @@ -661,51 +728,51 @@ _cfsml_read_clone_entry_t(FILE *fh, clone_entry_t* save_struc, const char *lastv return CFSML_SUCCESS; } -#line 396 "savegame.cfsml" +#line 395 "savegame.cfsml" static void -_cfsml_write_object_t(FILE *fh, object_t* save_struc) +_cfsml_write_object_t(Common::WriteStream *fh, object_t* save_struc) { int min, max, i; -#line 416 "savegame.cfsml" - fprintf(fh, "{\n"); - fprintf(fh, "flags = "); +#line 415 "savegame.cfsml" + WSprintf(fh, "{\n"); + WSprintf(fh, "flags = "); _cfsml_write_int(fh, (int*) &(save_struc->flags)); - fprintf(fh, "\n"); - fprintf(fh, "pos = "); + WSprintf(fh, "\n"); + WSprintf(fh, "pos = "); write_reg_t(fh, (reg_t*) &(save_struc->pos)); - fprintf(fh, "\n"); - fprintf(fh, "variables_nr = "); + WSprintf(fh, "\n"); + WSprintf(fh, "variables_nr = "); _cfsml_write_int(fh, (int*) &(save_struc->variables_nr)); - fprintf(fh, "\n"); - fprintf(fh, "variable_names_nr = "); + WSprintf(fh, "\n"); + WSprintf(fh, "variable_names_nr = "); _cfsml_write_int(fh, (int*) &(save_struc->variable_names_nr)); - fprintf(fh, "\n"); - fprintf(fh, "methods_nr = "); + WSprintf(fh, "\n"); + WSprintf(fh, "methods_nr = "); _cfsml_write_int(fh, (int*) &(save_struc->methods_nr)); - fprintf(fh, "\n"); - fprintf(fh, "variables = "); + WSprintf(fh, "\n"); + WSprintf(fh, "variables = "); min = max = save_struc->variables_nr; if (!save_struc->variables) min = max = 0; /* Don't write if it points to NULL */ -#line 442 "savegame.cfsml" - fprintf(fh, "[%d][\n", max); +#line 441 "savegame.cfsml" + WSprintf(fh, "[%d][\n", max); for (i = 0; i < min; i++) { write_reg_t(fh, &(save_struc->variables[i])); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); } - fprintf(fh, "]"); - fprintf(fh, "\n"); - fprintf(fh, "}"); + WSprintf(fh, "]"); + WSprintf(fh, "\n"); + WSprintf(fh, "}"); } -#line 489 "savegame.cfsml" +#line 488 "savegame.cfsml" static int -_cfsml_read_object_t(FILE *fh, object_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_object_t(Common::SeekableReadStream *fh, object_t* save_struc, const char *lastval, int *line, int *hiteof) { char *token; int min, max, i; -#line 547 "savegame.cfsml" +#line 546 "savegame.cfsml" int assignment, closed, done; if (strcmp(lastval, "{")) { @@ -737,47 +804,47 @@ _cfsml_read_object_t(FILE *fh, object_t* save_struc, const char *lastval, int *l return CFSML_FAILURE; } if (!strcmp(token, "flags")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->flags), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for flags at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "pos")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (read_reg_t(fh, (reg_t*) &(save_struc->pos), value, line, hiteof)) { _cfsml_error("Token expected by read_reg_t() for pos at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "variables_nr")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->variables_nr), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for variables_nr at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "variable_names_nr")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->variable_names_nr), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for variable_names_nr at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "methods_nr")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->methods_nr), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for methods_nr at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "variables")) { -#line 609 "savegame.cfsml" +#line 608 "savegame.cfsml" if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) { _cfsml_error("Opening brackets expected at line %d\n", *line); return CFSML_FAILURE; } -#line 619 "savegame.cfsml" +#line 618 "savegame.cfsml" // Prepare to restore dynamic array max = strtol(value + 1, NULL, 0); if (max < 0) { @@ -793,11 +860,11 @@ _cfsml_read_object_t(FILE *fh, object_t* save_struc, const char *lastval, int *l _cfsml_register_pointer(save_struc->variables); } else save_struc->variables = NULL; -#line 643 "savegame.cfsml" +#line 642 "savegame.cfsml" done = i = 0; do { if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) { -#line 651 "savegame.cfsml" +#line 650 "savegame.cfsml" _cfsml_error("Token expected at line %d\n", *line); return 1; } @@ -815,7 +882,7 @@ _cfsml_read_object_t(FILE *fh, object_t* save_struc, const char *lastval, int *l } while (!done); save_struc->variables_nr = max ; // Set array size accordingly } else -#line 703 "savegame.cfsml" +#line 702 "savegame.cfsml" { _cfsml_error("object_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; @@ -825,26 +892,26 @@ _cfsml_read_object_t(FILE *fh, object_t* save_struc, const char *lastval, int *l return CFSML_SUCCESS; } -#line 396 "savegame.cfsml" +#line 395 "savegame.cfsml" static void -_cfsml_write_string(FILE *fh, char ** save_struc) +_cfsml_write_string(Common::WriteStream *fh, char ** save_struc) { -#line 406 "savegame.cfsml" +#line 405 "savegame.cfsml" if (!(*save_struc)) - fprintf(fh, "\\null\\"); + WSprintf(fh, "\\null\\"); else { char *token = _cfsml_mangle_string((const char *) *save_struc); - fprintf(fh, "\"%s\"", token); + WSprintf(fh, "\"%s\"", token); free(token); } } -#line 489 "savegame.cfsml" +#line 488 "savegame.cfsml" static int -_cfsml_read_string(FILE *fh, char ** save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_string(Common::SeekableReadStream *fh, char ** save_struc, const char *lastval, int *line, int *hiteof) { char *token; -#line 525 "savegame.cfsml" +#line 524 "savegame.cfsml" if (strcmp(lastval, "\\null\\")) { // null pointer? unsigned int length = strlen(lastval); @@ -869,36 +936,36 @@ _cfsml_read_string(FILE *fh, char ** save_struc, const char *lastval, int *line, } } -#line 396 "savegame.cfsml" +#line 395 "savegame.cfsml" static void -_cfsml_write_menubar_t(FILE *fh, menubar_t* save_struc) +_cfsml_write_menubar_t(Common::WriteStream *fh, menubar_t* save_struc) { int min, max, i; -#line 416 "savegame.cfsml" - fprintf(fh, "{\n"); - fprintf(fh, "menus = "); +#line 415 "savegame.cfsml" + WSprintf(fh, "{\n"); + WSprintf(fh, "menus = "); min = max = save_struc->menus_nr; if (!save_struc->menus) min = max = 0; /* Don't write if it points to NULL */ -#line 442 "savegame.cfsml" - fprintf(fh, "[%d][\n", max); +#line 441 "savegame.cfsml" + WSprintf(fh, "[%d][\n", max); for (i = 0; i < min; i++) { _cfsml_write_menu_t(fh, &(save_struc->menus[i])); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); } - fprintf(fh, "]"); - fprintf(fh, "\n"); - fprintf(fh, "}"); + WSprintf(fh, "]"); + WSprintf(fh, "\n"); + WSprintf(fh, "}"); } -#line 489 "savegame.cfsml" +#line 488 "savegame.cfsml" static int -_cfsml_read_menubar_t(FILE *fh, menubar_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_menubar_t(Common::SeekableReadStream *fh, menubar_t* save_struc, const char *lastval, int *line, int *hiteof) { char *token; int min, max, i; -#line 547 "savegame.cfsml" +#line 546 "savegame.cfsml" int assignment, closed, done; if (strcmp(lastval, "{")) { @@ -930,12 +997,12 @@ _cfsml_read_menubar_t(FILE *fh, menubar_t* save_struc, const char *lastval, int return CFSML_FAILURE; } if (!strcmp(token, "menus")) { -#line 609 "savegame.cfsml" +#line 608 "savegame.cfsml" if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) { _cfsml_error("Opening brackets expected at line %d\n", *line); return CFSML_FAILURE; } -#line 619 "savegame.cfsml" +#line 618 "savegame.cfsml" // Prepare to restore dynamic array max = strtol(value + 1, NULL, 0); if (max < 0) { @@ -951,11 +1018,11 @@ _cfsml_read_menubar_t(FILE *fh, menubar_t* save_struc, const char *lastval, int _cfsml_register_pointer(save_struc->menus); } else save_struc->menus = NULL; -#line 643 "savegame.cfsml" +#line 642 "savegame.cfsml" done = i = 0; do { if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) { -#line 651 "savegame.cfsml" +#line 650 "savegame.cfsml" _cfsml_error("Token expected at line %d\n", *line); return 1; } @@ -973,7 +1040,7 @@ _cfsml_read_menubar_t(FILE *fh, menubar_t* save_struc, const char *lastval, int } while (!done); save_struc->menus_nr = max ; // Set array size accordingly } else -#line 703 "savegame.cfsml" +#line 702 "savegame.cfsml" { _cfsml_error("menubar_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; @@ -983,19 +1050,19 @@ _cfsml_read_menubar_t(FILE *fh, menubar_t* save_struc, const char *lastval, int return CFSML_SUCCESS; } -#line 396 "savegame.cfsml" +#line 395 "savegame.cfsml" static void -_cfsml_write_size_t(FILE *fh, size_t* save_struc) +_cfsml_write_size_t(Common::WriteStream *fh, size_t* save_struc) { - fprintf(fh, "%li", (long)*save_struc); + WSprintf(fh, "%li", (long)*save_struc); } -#line 489 "savegame.cfsml" +#line 488 "savegame.cfsml" static int -_cfsml_read_size_t(FILE *fh, size_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_size_t(Common::SeekableReadStream *fh, size_t* save_struc, const char *lastval, int *line, int *hiteof) { char *token; -#line 513 "savegame.cfsml" +#line 512 "savegame.cfsml" *save_struc = strtol(lastval, &token, 0); if ((*save_struc == 0) && (token == lastval)) { @@ -1009,30 +1076,30 @@ _cfsml_read_size_t(FILE *fh, size_t* save_struc, const char *lastval, int *line, return CFSML_SUCCESS; } -#line 396 "savegame.cfsml" +#line 395 "savegame.cfsml" static void -_cfsml_write_list_entry_t(FILE *fh, list_entry_t* save_struc) +_cfsml_write_list_entry_t(Common::WriteStream *fh, list_entry_t* save_struc) { int min, max, i; -#line 416 "savegame.cfsml" - fprintf(fh, "{\n"); - fprintf(fh, "next_free = "); +#line 415 "savegame.cfsml" + WSprintf(fh, "{\n"); + WSprintf(fh, "next_free = "); _cfsml_write_int(fh, (int*) &(save_struc->next_free)); - fprintf(fh, "\n"); - fprintf(fh, "entry = "); + WSprintf(fh, "\n"); + WSprintf(fh, "entry = "); _cfsml_write_list_t(fh, (list_t*) &(save_struc->entry)); - fprintf(fh, "\n"); - fprintf(fh, "}"); + WSprintf(fh, "\n"); + WSprintf(fh, "}"); } -#line 489 "savegame.cfsml" +#line 488 "savegame.cfsml" static int -_cfsml_read_list_entry_t(FILE *fh, list_entry_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_list_entry_t(Common::SeekableReadStream *fh, list_entry_t* save_struc, const char *lastval, int *line, int *hiteof) { char *token; int min, max, i; -#line 547 "savegame.cfsml" +#line 546 "savegame.cfsml" int assignment, closed, done; if (strcmp(lastval, "{")) { @@ -1064,20 +1131,20 @@ _cfsml_read_list_entry_t(FILE *fh, list_entry_t* save_struc, const char *lastval return CFSML_FAILURE; } if (!strcmp(token, "next_free")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->next_free), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for next_free at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "entry")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_list_t(fh, (list_t*) &(save_struc->entry), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_list_t() for entry at line %d\n", *line); return CFSML_FAILURE; } } else -#line 703 "savegame.cfsml" +#line 702 "savegame.cfsml" { _cfsml_error("list_entry_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; @@ -1087,37 +1154,37 @@ _cfsml_read_list_entry_t(FILE *fh, list_entry_t* save_struc, const char *lastval return CFSML_SUCCESS; } -#line 396 "savegame.cfsml" +#line 395 "savegame.cfsml" static void -_cfsml_write_int_hash_map_t(FILE *fh, int_hash_map_t* save_struc) +_cfsml_write_int_hash_map_t(Common::WriteStream *fh, int_hash_map_t* save_struc) { int min, max, i; -#line 416 "savegame.cfsml" - fprintf(fh, "{\n"); - fprintf(fh, "base_value = "); +#line 415 "savegame.cfsml" + WSprintf(fh, "{\n"); + WSprintf(fh, "base_value = "); _cfsml_write_int(fh, (int*) &(save_struc->base_value)); - fprintf(fh, "\n"); - fprintf(fh, "nodes = "); + WSprintf(fh, "\n"); + WSprintf(fh, "nodes = "); min = max = DCS_INT_HASH_MAX+1; -#line 442 "savegame.cfsml" - fprintf(fh, "[%d][\n", max); +#line 441 "savegame.cfsml" + WSprintf(fh, "[%d][\n", max); for (i = 0; i < min; i++) { write_int_hash_map_node_tp(fh, &(save_struc->nodes[i])); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); } - fprintf(fh, "]"); - fprintf(fh, "\n"); - fprintf(fh, "}"); + WSprintf(fh, "]"); + WSprintf(fh, "\n"); + WSprintf(fh, "}"); } -#line 489 "savegame.cfsml" +#line 488 "savegame.cfsml" static int -_cfsml_read_int_hash_map_t(FILE *fh, int_hash_map_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_int_hash_map_t(Common::SeekableReadStream *fh, int_hash_map_t* save_struc, const char *lastval, int *line, int *hiteof) { char *token; int min, max, i; -#line 547 "savegame.cfsml" +#line 546 "savegame.cfsml" int assignment, closed, done; if (strcmp(lastval, "{")) { @@ -1149,25 +1216,25 @@ _cfsml_read_int_hash_map_t(FILE *fh, int_hash_map_t* save_struc, const char *las return CFSML_FAILURE; } if (!strcmp(token, "base_value")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->base_value), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for base_value at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "nodes")) { -#line 609 "savegame.cfsml" +#line 608 "savegame.cfsml" if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) { _cfsml_error("Opening brackets expected at line %d\n", *line); return CFSML_FAILURE; } // Prepare to restore static array max = DCS_INT_HASH_MAX+1; -#line 643 "savegame.cfsml" +#line 642 "savegame.cfsml" done = i = 0; do { if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) { -#line 651 "savegame.cfsml" +#line 650 "savegame.cfsml" _cfsml_error("Token expected at line %d\n", *line); return 1; } @@ -1184,7 +1251,7 @@ _cfsml_read_int_hash_map_t(FILE *fh, int_hash_map_t* save_struc, const char *las done = 1; } while (!done); } else -#line 703 "savegame.cfsml" +#line 702 "savegame.cfsml" { _cfsml_error("int_hash_map_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; @@ -1194,48 +1261,48 @@ _cfsml_read_int_hash_map_t(FILE *fh, int_hash_map_t* save_struc, const char *las return CFSML_SUCCESS; } -#line 396 "savegame.cfsml" +#line 395 "savegame.cfsml" static void -_cfsml_write_song_t(FILE *fh, song_t* save_struc) +_cfsml_write_song_t(Common::WriteStream *fh, song_t* save_struc) { int min, max, i; -#line 416 "savegame.cfsml" - fprintf(fh, "{\n"); - fprintf(fh, "handle = "); +#line 415 "savegame.cfsml" + WSprintf(fh, "{\n"); + WSprintf(fh, "handle = "); _cfsml_write_song_handle_t(fh, (song_handle_t*) &(save_struc->handle)); - fprintf(fh, "\n"); - fprintf(fh, "resource_num = "); + WSprintf(fh, "\n"); + WSprintf(fh, "resource_num = "); _cfsml_write_int(fh, (int*) &(save_struc->resource_num)); - fprintf(fh, "\n"); - fprintf(fh, "priority = "); + WSprintf(fh, "\n"); + WSprintf(fh, "priority = "); _cfsml_write_int(fh, (int*) &(save_struc->priority)); - fprintf(fh, "\n"); - fprintf(fh, "status = "); + WSprintf(fh, "\n"); + WSprintf(fh, "status = "); _cfsml_write_int(fh, (int*) &(save_struc->status)); - fprintf(fh, "\n"); - fprintf(fh, "restore_behavior = "); + WSprintf(fh, "\n"); + WSprintf(fh, "restore_behavior = "); _cfsml_write_int(fh, (int*) &(save_struc->restore_behavior)); - fprintf(fh, "\n"); - fprintf(fh, "restore_time = "); + WSprintf(fh, "\n"); + WSprintf(fh, "restore_time = "); _cfsml_write_int(fh, (int*) &(save_struc->restore_time)); - fprintf(fh, "\n"); - fprintf(fh, "loops = "); + WSprintf(fh, "\n"); + WSprintf(fh, "loops = "); _cfsml_write_int(fh, (int*) &(save_struc->loops)); - fprintf(fh, "\n"); - fprintf(fh, "hold = "); + WSprintf(fh, "\n"); + WSprintf(fh, "hold = "); _cfsml_write_int(fh, (int*) &(save_struc->hold)); - fprintf(fh, "\n"); - fprintf(fh, "}"); + WSprintf(fh, "\n"); + WSprintf(fh, "}"); } -#line 489 "savegame.cfsml" +#line 488 "savegame.cfsml" static int -_cfsml_read_song_t(FILE *fh, song_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_song_t(Common::SeekableReadStream *fh, song_t* save_struc, const char *lastval, int *line, int *hiteof) { char *token; int min, max, i; -#line 547 "savegame.cfsml" +#line 546 "savegame.cfsml" int assignment, closed, done; if (strcmp(lastval, "{")) { @@ -1267,62 +1334,62 @@ _cfsml_read_song_t(FILE *fh, song_t* save_struc, const char *lastval, int *line, return CFSML_FAILURE; } if (!strcmp(token, "handle")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_song_handle_t(fh, (song_handle_t*) &(save_struc->handle), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_song_handle_t() for handle at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "resource_num")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->resource_num), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for resource_num at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "priority")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->priority), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for priority at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "status")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->status), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for status at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "restore_behavior")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->restore_behavior), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for restore_behavior at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "restore_time")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->restore_time), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for restore_time at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "loops")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->loops), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for loops at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "hold")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->hold), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for hold at line %d\n", *line); return CFSML_FAILURE; } } else -#line 703 "savegame.cfsml" +#line 702 "savegame.cfsml" { _cfsml_error("song_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; @@ -1332,67 +1399,67 @@ _cfsml_read_song_t(FILE *fh, song_t* save_struc, const char *lastval, int *line, return CFSML_SUCCESS; } -#line 396 "savegame.cfsml" +#line 395 "savegame.cfsml" static void -_cfsml_write_menu_item_t(FILE *fh, menu_item_t* save_struc) +_cfsml_write_menu_item_t(Common::WriteStream *fh, menu_item_t* save_struc) { int min, max, i; -#line 416 "savegame.cfsml" - fprintf(fh, "{\n"); - fprintf(fh, "type = "); +#line 415 "savegame.cfsml" + WSprintf(fh, "{\n"); + WSprintf(fh, "type = "); _cfsml_write_int(fh, (int*) &(save_struc->type)); - fprintf(fh, "\n"); - fprintf(fh, "keytext = "); + WSprintf(fh, "\n"); + WSprintf(fh, "keytext = "); _cfsml_write_string(fh, (char **) &(save_struc->keytext)); - fprintf(fh, "\n"); - fprintf(fh, "keytext_size = "); + WSprintf(fh, "\n"); + WSprintf(fh, "keytext_size = "); _cfsml_write_int(fh, (int*) &(save_struc->keytext_size)); - fprintf(fh, "\n"); - fprintf(fh, "flags = "); + WSprintf(fh, "\n"); + WSprintf(fh, "flags = "); _cfsml_write_int(fh, (int*) &(save_struc->flags)); - fprintf(fh, "\n"); - fprintf(fh, "said = "); + WSprintf(fh, "\n"); + WSprintf(fh, "said = "); min = max = MENU_SAID_SPEC_SIZE; -#line 442 "savegame.cfsml" - fprintf(fh, "[%d][\n", max); +#line 441 "savegame.cfsml" + WSprintf(fh, "[%d][\n", max); for (i = 0; i < min; i++) { _cfsml_write_byte(fh, &(save_struc->said[i])); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); } - fprintf(fh, "]"); - fprintf(fh, "\n"); - fprintf(fh, "said_pos = "); + WSprintf(fh, "]"); + WSprintf(fh, "\n"); + WSprintf(fh, "said_pos = "); write_reg_t(fh, (reg_t*) &(save_struc->said_pos)); - fprintf(fh, "\n"); - fprintf(fh, "text = "); + WSprintf(fh, "\n"); + WSprintf(fh, "text = "); _cfsml_write_string(fh, (char **) &(save_struc->text)); - fprintf(fh, "\n"); - fprintf(fh, "text_pos = "); + WSprintf(fh, "\n"); + WSprintf(fh, "text_pos = "); write_reg_t(fh, (reg_t*) &(save_struc->text_pos)); - fprintf(fh, "\n"); - fprintf(fh, "modifiers = "); + WSprintf(fh, "\n"); + WSprintf(fh, "modifiers = "); _cfsml_write_int(fh, (int*) &(save_struc->modifiers)); - fprintf(fh, "\n"); - fprintf(fh, "key = "); + WSprintf(fh, "\n"); + WSprintf(fh, "key = "); _cfsml_write_int(fh, (int*) &(save_struc->key)); - fprintf(fh, "\n"); - fprintf(fh, "enabled = "); + WSprintf(fh, "\n"); + WSprintf(fh, "enabled = "); _cfsml_write_int(fh, (int*) &(save_struc->enabled)); - fprintf(fh, "\n"); - fprintf(fh, "tag = "); + WSprintf(fh, "\n"); + WSprintf(fh, "tag = "); _cfsml_write_int(fh, (int*) &(save_struc->tag)); - fprintf(fh, "\n"); - fprintf(fh, "}"); + WSprintf(fh, "\n"); + WSprintf(fh, "}"); } -#line 489 "savegame.cfsml" +#line 488 "savegame.cfsml" static int -_cfsml_read_menu_item_t(FILE *fh, menu_item_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_menu_item_t(Common::SeekableReadStream *fh, menu_item_t* save_struc, const char *lastval, int *line, int *hiteof) { char *token; int min, max, i; -#line 547 "savegame.cfsml" +#line 546 "savegame.cfsml" int assignment, closed, done; if (strcmp(lastval, "{")) { @@ -1424,46 +1491,46 @@ _cfsml_read_menu_item_t(FILE *fh, menu_item_t* save_struc, const char *lastval, return CFSML_FAILURE; } if (!strcmp(token, "type")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->type), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for type at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "keytext")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_string(fh, (char **) &(save_struc->keytext), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_string() for keytext at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "keytext_size")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->keytext_size), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for keytext_size at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "flags")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->flags), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for flags at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "said")) { -#line 609 "savegame.cfsml" +#line 608 "savegame.cfsml" if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) { _cfsml_error("Opening brackets expected at line %d\n", *line); return CFSML_FAILURE; } // Prepare to restore static array max = MENU_SAID_SPEC_SIZE; -#line 643 "savegame.cfsml" +#line 642 "savegame.cfsml" done = i = 0; do { if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) { -#line 651 "savegame.cfsml" +#line 650 "savegame.cfsml" _cfsml_error("Token expected at line %d\n", *line); return 1; } @@ -1481,55 +1548,55 @@ _cfsml_read_menu_item_t(FILE *fh, menu_item_t* save_struc, const char *lastval, } while (!done); } else if (!strcmp(token, "said_pos")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (read_reg_t(fh, (reg_t*) &(save_struc->said_pos), value, line, hiteof)) { _cfsml_error("Token expected by read_reg_t() for said_pos at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "text")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_string(fh, (char **) &(save_struc->text), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_string() for text at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "text_pos")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (read_reg_t(fh, (reg_t*) &(save_struc->text_pos), value, line, hiteof)) { _cfsml_error("Token expected by read_reg_t() for text_pos at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "modifiers")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->modifiers), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for modifiers at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "key")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->key), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for key at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "enabled")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->enabled), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for enabled at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "tag")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->tag), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for tag at line %d\n", *line); return CFSML_FAILURE; } } else -#line 703 "savegame.cfsml" +#line 702 "savegame.cfsml" { _cfsml_error("menu_item_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; @@ -1539,30 +1606,30 @@ _cfsml_read_menu_item_t(FILE *fh, menu_item_t* save_struc, const char *lastval, return CFSML_SUCCESS; } -#line 396 "savegame.cfsml" +#line 395 "savegame.cfsml" static void -_cfsml_write_node_entry_t(FILE *fh, node_entry_t* save_struc) +_cfsml_write_node_entry_t(Common::WriteStream *fh, node_entry_t* save_struc) { int min, max, i; -#line 416 "savegame.cfsml" - fprintf(fh, "{\n"); - fprintf(fh, "next_free = "); +#line 415 "savegame.cfsml" + WSprintf(fh, "{\n"); + WSprintf(fh, "next_free = "); _cfsml_write_int(fh, (int*) &(save_struc->next_free)); - fprintf(fh, "\n"); - fprintf(fh, "entry = "); + WSprintf(fh, "\n"); + WSprintf(fh, "entry = "); _cfsml_write_node_t(fh, (node_t*) &(save_struc->entry)); - fprintf(fh, "\n"); - fprintf(fh, "}"); + WSprintf(fh, "\n"); + WSprintf(fh, "}"); } -#line 489 "savegame.cfsml" +#line 488 "savegame.cfsml" static int -_cfsml_read_node_entry_t(FILE *fh, node_entry_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_node_entry_t(Common::SeekableReadStream *fh, node_entry_t* save_struc, const char *lastval, int *line, int *hiteof) { char *token; int min, max, i; -#line 547 "savegame.cfsml" +#line 546 "savegame.cfsml" int assignment, closed, done; if (strcmp(lastval, "{")) { @@ -1594,20 +1661,20 @@ _cfsml_read_node_entry_t(FILE *fh, node_entry_t* save_struc, const char *lastval return CFSML_FAILURE; } if (!strcmp(token, "next_free")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->next_free), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for next_free at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "entry")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_node_t(fh, (node_t*) &(save_struc->entry), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_node_t() for entry at line %d\n", *line); return CFSML_FAILURE; } } else -#line 703 "savegame.cfsml" +#line 702 "savegame.cfsml" { _cfsml_error("node_entry_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; @@ -1617,19 +1684,19 @@ _cfsml_read_node_entry_t(FILE *fh, node_entry_t* save_struc, const char *lastval return CFSML_SUCCESS; } -#line 396 "savegame.cfsml" +#line 395 "savegame.cfsml" static void -_cfsml_write_seg_id_t(FILE *fh, seg_id_t* save_struc) +_cfsml_write_seg_id_t(Common::WriteStream *fh, seg_id_t* save_struc) { - fprintf(fh, "%li", (long)*save_struc); + WSprintf(fh, "%li", (long)*save_struc); } -#line 489 "savegame.cfsml" +#line 488 "savegame.cfsml" static int -_cfsml_read_seg_id_t(FILE *fh, seg_id_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_seg_id_t(Common::SeekableReadStream *fh, seg_id_t* save_struc, const char *lastval, int *line, int *hiteof) { char *token; -#line 513 "savegame.cfsml" +#line 512 "savegame.cfsml" *save_struc = strtol(lastval, &token, 0); if ((*save_struc == 0) && (token == lastval)) { @@ -1643,42 +1710,42 @@ _cfsml_read_seg_id_t(FILE *fh, seg_id_t* save_struc, const char *lastval, int *l return CFSML_SUCCESS; } -#line 396 "savegame.cfsml" +#line 395 "savegame.cfsml" static void -_cfsml_write_dynmem_t(FILE *fh, dynmem_t* save_struc) +_cfsml_write_dynmem_t(Common::WriteStream *fh, dynmem_t* save_struc) { int min, max, i; -#line 416 "savegame.cfsml" - fprintf(fh, "{\n"); - fprintf(fh, "size = "); +#line 415 "savegame.cfsml" + WSprintf(fh, "{\n"); + WSprintf(fh, "size = "); _cfsml_write_int(fh, (int*) &(save_struc->size)); - fprintf(fh, "\n"); - fprintf(fh, "description = "); + WSprintf(fh, "\n"); + WSprintf(fh, "description = "); _cfsml_write_string(fh, (char **) &(save_struc->description)); - fprintf(fh, "\n"); - fprintf(fh, "buf = "); + WSprintf(fh, "\n"); + WSprintf(fh, "buf = "); min = max = save_struc->size; if (!save_struc->buf) min = max = 0; /* Don't write if it points to NULL */ -#line 442 "savegame.cfsml" - fprintf(fh, "[%d][\n", max); +#line 441 "savegame.cfsml" + WSprintf(fh, "[%d][\n", max); for (i = 0; i < min; i++) { _cfsml_write_byte(fh, &(save_struc->buf[i])); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); } - fprintf(fh, "]"); - fprintf(fh, "\n"); - fprintf(fh, "}"); + WSprintf(fh, "]"); + WSprintf(fh, "\n"); + WSprintf(fh, "}"); } -#line 489 "savegame.cfsml" +#line 488 "savegame.cfsml" static int -_cfsml_read_dynmem_t(FILE *fh, dynmem_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_dynmem_t(Common::SeekableReadStream *fh, dynmem_t* save_struc, const char *lastval, int *line, int *hiteof) { char *token; int min, max, i; -#line 547 "savegame.cfsml" +#line 546 "savegame.cfsml" int assignment, closed, done; if (strcmp(lastval, "{")) { @@ -1710,26 +1777,26 @@ _cfsml_read_dynmem_t(FILE *fh, dynmem_t* save_struc, const char *lastval, int *l return CFSML_FAILURE; } if (!strcmp(token, "size")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->size), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for size at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "description")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_string(fh, (char **) &(save_struc->description), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_string() for description at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "buf")) { -#line 609 "savegame.cfsml" +#line 608 "savegame.cfsml" if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) { _cfsml_error("Opening brackets expected at line %d\n", *line); return CFSML_FAILURE; } -#line 619 "savegame.cfsml" +#line 618 "savegame.cfsml" // Prepare to restore dynamic array max = strtol(value + 1, NULL, 0); if (max < 0) { @@ -1745,11 +1812,11 @@ _cfsml_read_dynmem_t(FILE *fh, dynmem_t* save_struc, const char *lastval, int *l _cfsml_register_pointer(save_struc->buf); } else save_struc->buf = NULL; -#line 643 "savegame.cfsml" +#line 642 "savegame.cfsml" done = i = 0; do { if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) { -#line 651 "savegame.cfsml" +#line 650 "savegame.cfsml" _cfsml_error("Token expected at line %d\n", *line); return 1; } @@ -1767,7 +1834,7 @@ _cfsml_read_dynmem_t(FILE *fh, dynmem_t* save_struc, const char *lastval, int *l } while (!done); save_struc->size = max ; // Set array size accordingly } else -#line 703 "savegame.cfsml" +#line 702 "savegame.cfsml" { _cfsml_error("dynmem_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; @@ -1777,42 +1844,42 @@ _cfsml_read_dynmem_t(FILE *fh, dynmem_t* save_struc, const char *lastval, int *l return CFSML_SUCCESS; } -#line 396 "savegame.cfsml" +#line 395 "savegame.cfsml" static void -_cfsml_write_local_variables_t(FILE *fh, local_variables_t* save_struc) +_cfsml_write_local_variables_t(Common::WriteStream *fh, local_variables_t* save_struc) { int min, max, i; -#line 416 "savegame.cfsml" - fprintf(fh, "{\n"); - fprintf(fh, "script_id = "); +#line 415 "savegame.cfsml" + WSprintf(fh, "{\n"); + WSprintf(fh, "script_id = "); _cfsml_write_int(fh, (int*) &(save_struc->script_id)); - fprintf(fh, "\n"); - fprintf(fh, "nr = "); + WSprintf(fh, "\n"); + WSprintf(fh, "nr = "); _cfsml_write_int(fh, (int*) &(save_struc->nr)); - fprintf(fh, "\n"); - fprintf(fh, "locals = "); + WSprintf(fh, "\n"); + WSprintf(fh, "locals = "); min = max = save_struc->nr; if (!save_struc->locals) min = max = 0; /* Don't write if it points to NULL */ -#line 442 "savegame.cfsml" - fprintf(fh, "[%d][\n", max); +#line 441 "savegame.cfsml" + WSprintf(fh, "[%d][\n", max); for (i = 0; i < min; i++) { write_reg_t(fh, &(save_struc->locals[i])); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); } - fprintf(fh, "]"); - fprintf(fh, "\n"); - fprintf(fh, "}"); + WSprintf(fh, "]"); + WSprintf(fh, "\n"); + WSprintf(fh, "}"); } -#line 489 "savegame.cfsml" +#line 488 "savegame.cfsml" static int -_cfsml_read_local_variables_t(FILE *fh, local_variables_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_local_variables_t(Common::SeekableReadStream *fh, local_variables_t* save_struc, const char *lastval, int *line, int *hiteof) { char *token; int min, max, i; -#line 547 "savegame.cfsml" +#line 546 "savegame.cfsml" int assignment, closed, done; if (strcmp(lastval, "{")) { @@ -1844,26 +1911,26 @@ _cfsml_read_local_variables_t(FILE *fh, local_variables_t* save_struc, const cha return CFSML_FAILURE; } if (!strcmp(token, "script_id")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->script_id), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for script_id at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "nr")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->nr), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for nr at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "locals")) { -#line 609 "savegame.cfsml" +#line 608 "savegame.cfsml" if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) { _cfsml_error("Opening brackets expected at line %d\n", *line); return CFSML_FAILURE; } -#line 619 "savegame.cfsml" +#line 618 "savegame.cfsml" // Prepare to restore dynamic array max = strtol(value + 1, NULL, 0); if (max < 0) { @@ -1879,11 +1946,11 @@ _cfsml_read_local_variables_t(FILE *fh, local_variables_t* save_struc, const cha _cfsml_register_pointer(save_struc->locals); } else save_struc->locals = NULL; -#line 643 "savegame.cfsml" +#line 642 "savegame.cfsml" done = i = 0; do { if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) { -#line 651 "savegame.cfsml" +#line 650 "savegame.cfsml" _cfsml_error("Token expected at line %d\n", *line); return 1; } @@ -1901,7 +1968,7 @@ _cfsml_read_local_variables_t(FILE *fh, local_variables_t* save_struc, const cha } while (!done); save_struc->nr = max ; // Set array size accordingly } else -#line 703 "savegame.cfsml" +#line 702 "savegame.cfsml" { _cfsml_error("local_variables_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; @@ -1911,63 +1978,63 @@ _cfsml_read_local_variables_t(FILE *fh, local_variables_t* save_struc, const cha return CFSML_SUCCESS; } -#line 396 "savegame.cfsml" +#line 395 "savegame.cfsml" static void -_cfsml_write_state_t(FILE *fh, state_t* save_struc) +_cfsml_write_state_t(Common::WriteStream *fh, state_t* save_struc) { int min, max, i; -#line 416 "savegame.cfsml" - fprintf(fh, "{\n"); - fprintf(fh, "savegame_version = "); +#line 415 "savegame.cfsml" + WSprintf(fh, "{\n"); + WSprintf(fh, "savegame_version = "); _cfsml_write_int(fh, (int*) &(save_struc->savegame_version)); - fprintf(fh, "\n"); - fprintf(fh, "game_version = "); + WSprintf(fh, "\n"); + WSprintf(fh, "game_version = "); _cfsml_write_string(fh, (char **) &(save_struc->game_version)); - fprintf(fh, "\n"); - fprintf(fh, "version = "); + WSprintf(fh, "\n"); + WSprintf(fh, "version = "); write_sci_version(fh, (sci_version_t*) &(save_struc->version)); - fprintf(fh, "\n"); - fprintf(fh, "menubar = "); + WSprintf(fh, "\n"); + WSprintf(fh, "menubar = "); write_menubar_tp(fh, (menubar_t **) &(save_struc->menubar)); - fprintf(fh, "\n"); - fprintf(fh, "status_bar_foreground = "); + WSprintf(fh, "\n"); + WSprintf(fh, "status_bar_foreground = "); _cfsml_write_int(fh, (int*) &(save_struc->status_bar_foreground)); - fprintf(fh, "\n"); - fprintf(fh, "status_bar_background = "); + WSprintf(fh, "\n"); + WSprintf(fh, "status_bar_background = "); _cfsml_write_int(fh, (int*) &(save_struc->status_bar_background)); - fprintf(fh, "\n"); - fprintf(fh, "seg_manager = "); + WSprintf(fh, "\n"); + WSprintf(fh, "seg_manager = "); _cfsml_write_seg_manager_t(fh, (seg_manager_t*) &(save_struc->seg_manager)); - fprintf(fh, "\n"); - fprintf(fh, "classtable_size = "); + WSprintf(fh, "\n"); + WSprintf(fh, "classtable_size = "); _cfsml_write_int(fh, (int*) &(save_struc->classtable_size)); - fprintf(fh, "\n"); - fprintf(fh, "classtable = "); + WSprintf(fh, "\n"); + WSprintf(fh, "classtable = "); min = max = save_struc->classtable_size; if (!save_struc->classtable) min = max = 0; /* Don't write if it points to NULL */ -#line 442 "savegame.cfsml" - fprintf(fh, "[%d][\n", max); +#line 441 "savegame.cfsml" + WSprintf(fh, "[%d][\n", max); for (i = 0; i < min; i++) { _cfsml_write_class_t(fh, &(save_struc->classtable[i])); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); } - fprintf(fh, "]"); - fprintf(fh, "\n"); - fprintf(fh, "sound = "); + WSprintf(fh, "]"); + WSprintf(fh, "\n"); + WSprintf(fh, "sound = "); _cfsml_write_sfx_state_t(fh, (sfx_state_t*) &(save_struc->sound)); - fprintf(fh, "\n"); - fprintf(fh, "}"); + WSprintf(fh, "\n"); + WSprintf(fh, "}"); } -#line 489 "savegame.cfsml" +#line 488 "savegame.cfsml" static int -_cfsml_read_state_t(FILE *fh, state_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_state_t(Common::SeekableReadStream *fh, state_t* save_struc, const char *lastval, int *line, int *hiteof) { char *token; int min, max, i; -#line 547 "savegame.cfsml" +#line 546 "savegame.cfsml" int assignment, closed, done; if (strcmp(lastval, "{")) { @@ -1999,68 +2066,68 @@ _cfsml_read_state_t(FILE *fh, state_t* save_struc, const char *lastval, int *lin return CFSML_FAILURE; } if (!strcmp(token, "savegame_version")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->savegame_version), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for savegame_version at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "game_version")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_string(fh, (char **) &(save_struc->game_version), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_string() for game_version at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "version")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (read_sci_version(fh, (sci_version_t*) &(save_struc->version), value, line, hiteof)) { _cfsml_error("Token expected by read_sci_version() for version at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "menubar")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (read_menubar_tp(fh, (menubar_t **) &(save_struc->menubar), value, line, hiteof)) { _cfsml_error("Token expected by read_menubar_tp() for menubar at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "status_bar_foreground")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->status_bar_foreground), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for status_bar_foreground at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "status_bar_background")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->status_bar_background), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for status_bar_background at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "seg_manager")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_seg_manager_t(fh, (seg_manager_t*) &(save_struc->seg_manager), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_seg_manager_t() for seg_manager at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "classtable_size")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->classtable_size), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for classtable_size at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "classtable")) { -#line 609 "savegame.cfsml" +#line 608 "savegame.cfsml" if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) { _cfsml_error("Opening brackets expected at line %d\n", *line); return CFSML_FAILURE; } -#line 619 "savegame.cfsml" +#line 618 "savegame.cfsml" // Prepare to restore dynamic array max = strtol(value + 1, NULL, 0); if (max < 0) { @@ -2076,11 +2143,11 @@ _cfsml_read_state_t(FILE *fh, state_t* save_struc, const char *lastval, int *lin _cfsml_register_pointer(save_struc->classtable); } else save_struc->classtable = NULL; -#line 643 "savegame.cfsml" +#line 642 "savegame.cfsml" done = i = 0; do { if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) { -#line 651 "savegame.cfsml" +#line 650 "savegame.cfsml" _cfsml_error("Token expected at line %d\n", *line); return 1; } @@ -2099,13 +2166,13 @@ _cfsml_read_state_t(FILE *fh, state_t* save_struc, const char *lastval, int *lin save_struc->classtable_size = max ; // Set array size accordingly } else if (!strcmp(token, "sound")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_sfx_state_t(fh, (sfx_state_t*) &(save_struc->sound), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_sfx_state_t() for sound at line %d\n", *line); return CFSML_FAILURE; } } else -#line 703 "savegame.cfsml" +#line 702 "savegame.cfsml" { _cfsml_error("state_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; @@ -2115,48 +2182,48 @@ _cfsml_read_state_t(FILE *fh, state_t* save_struc, const char *lastval, int *lin return CFSML_SUCCESS; } -#line 396 "savegame.cfsml" +#line 395 "savegame.cfsml" static void -_cfsml_write_node_table_t(FILE *fh, node_table_t* save_struc) +_cfsml_write_node_table_t(Common::WriteStream *fh, node_table_t* save_struc) { int min, max, i; -#line 416 "savegame.cfsml" - fprintf(fh, "{\n"); - fprintf(fh, "entries_nr = "); +#line 415 "savegame.cfsml" + WSprintf(fh, "{\n"); + WSprintf(fh, "entries_nr = "); _cfsml_write_int(fh, (int*) &(save_struc->entries_nr)); - fprintf(fh, "\n"); - fprintf(fh, "first_free = "); + WSprintf(fh, "\n"); + WSprintf(fh, "first_free = "); _cfsml_write_int(fh, (int*) &(save_struc->first_free)); - fprintf(fh, "\n"); - fprintf(fh, "entries_used = "); + WSprintf(fh, "\n"); + WSprintf(fh, "entries_used = "); _cfsml_write_int(fh, (int*) &(save_struc->entries_used)); - fprintf(fh, "\n"); - fprintf(fh, "max_entry = "); + WSprintf(fh, "\n"); + WSprintf(fh, "max_entry = "); _cfsml_write_int(fh, (int*) &(save_struc->max_entry)); - fprintf(fh, "\n"); - fprintf(fh, "table = "); + WSprintf(fh, "\n"); + WSprintf(fh, "table = "); min = max = save_struc->entries_nr; if (!save_struc->table) min = max = 0; /* Don't write if it points to NULL */ -#line 442 "savegame.cfsml" - fprintf(fh, "[%d][\n", max); +#line 441 "savegame.cfsml" + WSprintf(fh, "[%d][\n", max); for (i = 0; i < min; i++) { _cfsml_write_node_entry_t(fh, &(save_struc->table[i])); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); } - fprintf(fh, "]"); - fprintf(fh, "\n"); - fprintf(fh, "}"); + WSprintf(fh, "]"); + WSprintf(fh, "\n"); + WSprintf(fh, "}"); } -#line 489 "savegame.cfsml" +#line 488 "savegame.cfsml" static int -_cfsml_read_node_table_t(FILE *fh, node_table_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_node_table_t(Common::SeekableReadStream *fh, node_table_t* save_struc, const char *lastval, int *line, int *hiteof) { char *token; int min, max, i; -#line 547 "savegame.cfsml" +#line 546 "savegame.cfsml" int assignment, closed, done; if (strcmp(lastval, "{")) { @@ -2188,40 +2255,40 @@ _cfsml_read_node_table_t(FILE *fh, node_table_t* save_struc, const char *lastval return CFSML_FAILURE; } if (!strcmp(token, "entries_nr")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->entries_nr), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for entries_nr at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "first_free")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->first_free), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for first_free at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "entries_used")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->entries_used), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for entries_used at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "max_entry")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->max_entry), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for max_entry at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "table")) { -#line 609 "savegame.cfsml" +#line 608 "savegame.cfsml" if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) { _cfsml_error("Opening brackets expected at line %d\n", *line); return CFSML_FAILURE; } -#line 619 "savegame.cfsml" +#line 618 "savegame.cfsml" // Prepare to restore dynamic array max = strtol(value + 1, NULL, 0); if (max < 0) { @@ -2237,11 +2304,11 @@ _cfsml_read_node_table_t(FILE *fh, node_table_t* save_struc, const char *lastval _cfsml_register_pointer(save_struc->table); } else save_struc->table = NULL; -#line 643 "savegame.cfsml" +#line 642 "savegame.cfsml" done = i = 0; do { if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) { -#line 651 "savegame.cfsml" +#line 650 "savegame.cfsml" _cfsml_error("Token expected at line %d\n", *line); return 1; } @@ -2259,7 +2326,7 @@ _cfsml_read_node_table_t(FILE *fh, node_table_t* save_struc, const char *lastval } while (!done); save_struc->entries_nr = max ; // Set array size accordingly } else -#line 703 "savegame.cfsml" +#line 702 "savegame.cfsml" { _cfsml_error("node_table_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; @@ -2269,34 +2336,34 @@ _cfsml_read_node_table_t(FILE *fh, node_table_t* save_struc, const char *lastval return CFSML_SUCCESS; } -#line 396 "savegame.cfsml" +#line 395 "savegame.cfsml" static void -_cfsml_write_sys_strings_t(FILE *fh, sys_strings_t* save_struc) +_cfsml_write_sys_strings_t(Common::WriteStream *fh, sys_strings_t* save_struc) { int min, max, i; -#line 416 "savegame.cfsml" - fprintf(fh, "{\n"); - fprintf(fh, "strings = "); +#line 415 "savegame.cfsml" + WSprintf(fh, "{\n"); + WSprintf(fh, "strings = "); min = max = SYS_STRINGS_MAX; -#line 442 "savegame.cfsml" - fprintf(fh, "[%d][\n", max); +#line 441 "savegame.cfsml" + WSprintf(fh, "[%d][\n", max); for (i = 0; i < min; i++) { _cfsml_write_sys_string_t(fh, &(save_struc->strings[i])); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); } - fprintf(fh, "]"); - fprintf(fh, "\n"); - fprintf(fh, "}"); + WSprintf(fh, "]"); + WSprintf(fh, "\n"); + WSprintf(fh, "}"); } -#line 489 "savegame.cfsml" +#line 488 "savegame.cfsml" static int -_cfsml_read_sys_strings_t(FILE *fh, sys_strings_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_sys_strings_t(Common::SeekableReadStream *fh, sys_strings_t* save_struc, const char *lastval, int *line, int *hiteof) { char *token; int min, max, i; -#line 547 "savegame.cfsml" +#line 546 "savegame.cfsml" int assignment, closed, done; if (strcmp(lastval, "{")) { @@ -2328,18 +2395,18 @@ _cfsml_read_sys_strings_t(FILE *fh, sys_strings_t* save_struc, const char *lastv return CFSML_FAILURE; } if (!strcmp(token, "strings")) { -#line 609 "savegame.cfsml" +#line 608 "savegame.cfsml" if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) { _cfsml_error("Opening brackets expected at line %d\n", *line); return CFSML_FAILURE; } // Prepare to restore static array max = SYS_STRINGS_MAX; -#line 643 "savegame.cfsml" +#line 642 "savegame.cfsml" done = i = 0; do { if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) { -#line 651 "savegame.cfsml" +#line 650 "savegame.cfsml" _cfsml_error("Token expected at line %d\n", *line); return 1; } @@ -2356,7 +2423,7 @@ _cfsml_read_sys_strings_t(FILE *fh, sys_strings_t* save_struc, const char *lastv done = 1; } while (!done); } else -#line 703 "savegame.cfsml" +#line 702 "savegame.cfsml" { _cfsml_error("sys_strings_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; @@ -2366,19 +2433,19 @@ _cfsml_read_sys_strings_t(FILE *fh, sys_strings_t* save_struc, const char *lastv return CFSML_SUCCESS; } -#line 396 "savegame.cfsml" +#line 395 "savegame.cfsml" static void -_cfsml_write_byte(FILE *fh, byte* save_struc) +_cfsml_write_byte(Common::WriteStream *fh, byte* save_struc) { - fprintf(fh, "%li", (long)*save_struc); + WSprintf(fh, "%li", (long)*save_struc); } -#line 489 "savegame.cfsml" +#line 488 "savegame.cfsml" static int -_cfsml_read_byte(FILE *fh, byte* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_byte(Common::SeekableReadStream *fh, byte* save_struc, const char *lastval, int *line, int *hiteof) { char *token; -#line 513 "savegame.cfsml" +#line 512 "savegame.cfsml" *save_struc = strtol(lastval, &token, 0); if ((*save_struc == 0) && (token == lastval)) { @@ -2392,36 +2459,36 @@ _cfsml_read_byte(FILE *fh, byte* save_struc, const char *lastval, int *line, int return CFSML_SUCCESS; } -#line 396 "savegame.cfsml" +#line 395 "savegame.cfsml" static void -_cfsml_write_node_t(FILE *fh, node_t* save_struc) +_cfsml_write_node_t(Common::WriteStream *fh, node_t* save_struc) { int min, max, i; -#line 416 "savegame.cfsml" - fprintf(fh, "{\n"); - fprintf(fh, "pred = "); +#line 415 "savegame.cfsml" + WSprintf(fh, "{\n"); + WSprintf(fh, "pred = "); write_reg_t(fh, (reg_t*) &(save_struc->pred)); - fprintf(fh, "\n"); - fprintf(fh, "succ = "); + WSprintf(fh, "\n"); + WSprintf(fh, "succ = "); write_reg_t(fh, (reg_t*) &(save_struc->succ)); - fprintf(fh, "\n"); - fprintf(fh, "key = "); + WSprintf(fh, "\n"); + WSprintf(fh, "key = "); write_reg_t(fh, (reg_t*) &(save_struc->key)); - fprintf(fh, "\n"); - fprintf(fh, "value = "); + WSprintf(fh, "\n"); + WSprintf(fh, "value = "); write_reg_t(fh, (reg_t*) &(save_struc->value)); - fprintf(fh, "\n"); - fprintf(fh, "}"); + WSprintf(fh, "\n"); + WSprintf(fh, "}"); } -#line 489 "savegame.cfsml" +#line 488 "savegame.cfsml" static int -_cfsml_read_node_t(FILE *fh, node_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_node_t(Common::SeekableReadStream *fh, node_t* save_struc, const char *lastval, int *line, int *hiteof) { char *token; int min, max, i; -#line 547 "savegame.cfsml" +#line 546 "savegame.cfsml" int assignment, closed, done; if (strcmp(lastval, "{")) { @@ -2453,34 +2520,34 @@ _cfsml_read_node_t(FILE *fh, node_t* save_struc, const char *lastval, int *line, return CFSML_FAILURE; } if (!strcmp(token, "pred")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (read_reg_t(fh, (reg_t*) &(save_struc->pred), value, line, hiteof)) { _cfsml_error("Token expected by read_reg_t() for pred at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "succ")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (read_reg_t(fh, (reg_t*) &(save_struc->succ), value, line, hiteof)) { _cfsml_error("Token expected by read_reg_t() for succ at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "key")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (read_reg_t(fh, (reg_t*) &(save_struc->key), value, line, hiteof)) { _cfsml_error("Token expected by read_reg_t() for key at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "value")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (read_reg_t(fh, (reg_t*) &(save_struc->value), value, line, hiteof)) { _cfsml_error("Token expected by read_reg_t() for value at line %d\n", *line); return CFSML_FAILURE; } } else -#line 703 "savegame.cfsml" +#line 702 "savegame.cfsml" { _cfsml_error("node_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; @@ -2490,48 +2557,48 @@ _cfsml_read_node_t(FILE *fh, node_t* save_struc, const char *lastval, int *line, return CFSML_SUCCESS; } -#line 396 "savegame.cfsml" +#line 395 "savegame.cfsml" static void -_cfsml_write_list_table_t(FILE *fh, list_table_t* save_struc) +_cfsml_write_list_table_t(Common::WriteStream *fh, list_table_t* save_struc) { int min, max, i; -#line 416 "savegame.cfsml" - fprintf(fh, "{\n"); - fprintf(fh, "entries_nr = "); +#line 415 "savegame.cfsml" + WSprintf(fh, "{\n"); + WSprintf(fh, "entries_nr = "); _cfsml_write_int(fh, (int*) &(save_struc->entries_nr)); - fprintf(fh, "\n"); - fprintf(fh, "first_free = "); + WSprintf(fh, "\n"); + WSprintf(fh, "first_free = "); _cfsml_write_int(fh, (int*) &(save_struc->first_free)); - fprintf(fh, "\n"); - fprintf(fh, "entries_used = "); + WSprintf(fh, "\n"); + WSprintf(fh, "entries_used = "); _cfsml_write_int(fh, (int*) &(save_struc->entries_used)); - fprintf(fh, "\n"); - fprintf(fh, "max_entry = "); + WSprintf(fh, "\n"); + WSprintf(fh, "max_entry = "); _cfsml_write_int(fh, (int*) &(save_struc->max_entry)); - fprintf(fh, "\n"); - fprintf(fh, "table = "); + WSprintf(fh, "\n"); + WSprintf(fh, "table = "); min = max = save_struc->entries_nr; if (!save_struc->table) min = max = 0; /* Don't write if it points to NULL */ -#line 442 "savegame.cfsml" - fprintf(fh, "[%d][\n", max); +#line 441 "savegame.cfsml" + WSprintf(fh, "[%d][\n", max); for (i = 0; i < min; i++) { _cfsml_write_list_entry_t(fh, &(save_struc->table[i])); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); } - fprintf(fh, "]"); - fprintf(fh, "\n"); - fprintf(fh, "}"); + WSprintf(fh, "]"); + WSprintf(fh, "\n"); + WSprintf(fh, "}"); } -#line 489 "savegame.cfsml" +#line 488 "savegame.cfsml" static int -_cfsml_read_list_table_t(FILE *fh, list_table_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_list_table_t(Common::SeekableReadStream *fh, list_table_t* save_struc, const char *lastval, int *line, int *hiteof) { char *token; int min, max, i; -#line 547 "savegame.cfsml" +#line 546 "savegame.cfsml" int assignment, closed, done; if (strcmp(lastval, "{")) { @@ -2563,40 +2630,40 @@ _cfsml_read_list_table_t(FILE *fh, list_table_t* save_struc, const char *lastval return CFSML_FAILURE; } if (!strcmp(token, "entries_nr")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->entries_nr), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for entries_nr at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "first_free")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->first_free), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for first_free at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "entries_used")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->entries_used), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for entries_used at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "max_entry")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->max_entry), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for max_entry at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "table")) { -#line 609 "savegame.cfsml" +#line 608 "savegame.cfsml" if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) { _cfsml_error("Opening brackets expected at line %d\n", *line); return CFSML_FAILURE; } -#line 619 "savegame.cfsml" +#line 618 "savegame.cfsml" // Prepare to restore dynamic array max = strtol(value + 1, NULL, 0); if (max < 0) { @@ -2612,11 +2679,11 @@ _cfsml_read_list_table_t(FILE *fh, list_table_t* save_struc, const char *lastval _cfsml_register_pointer(save_struc->table); } else save_struc->table = NULL; -#line 643 "savegame.cfsml" +#line 642 "savegame.cfsml" done = i = 0; do { if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) { -#line 651 "savegame.cfsml" +#line 650 "savegame.cfsml" _cfsml_error("Token expected at line %d\n", *line); return 1; } @@ -2634,7 +2701,7 @@ _cfsml_read_list_table_t(FILE *fh, list_table_t* save_struc, const char *lastval } while (!done); save_struc->entries_nr = max ; // Set array size accordingly } else -#line 703 "savegame.cfsml" +#line 702 "savegame.cfsml" { _cfsml_error("list_table_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; @@ -2644,30 +2711,30 @@ _cfsml_read_list_table_t(FILE *fh, list_table_t* save_struc, const char *lastval return CFSML_SUCCESS; } -#line 396 "savegame.cfsml" +#line 395 "savegame.cfsml" static void -_cfsml_write_class_t(FILE *fh, class_t* save_struc) +_cfsml_write_class_t(Common::WriteStream *fh, class_t* save_struc) { int min, max, i; -#line 416 "savegame.cfsml" - fprintf(fh, "{\n"); - fprintf(fh, "script = "); +#line 415 "savegame.cfsml" + WSprintf(fh, "{\n"); + WSprintf(fh, "script = "); _cfsml_write_int(fh, (int*) &(save_struc->script)); - fprintf(fh, "\n"); - fprintf(fh, "reg = "); + WSprintf(fh, "\n"); + WSprintf(fh, "reg = "); write_reg_t(fh, (reg_t*) &(save_struc->reg)); - fprintf(fh, "\n"); - fprintf(fh, "}"); + WSprintf(fh, "\n"); + WSprintf(fh, "}"); } -#line 489 "savegame.cfsml" +#line 488 "savegame.cfsml" static int -_cfsml_read_class_t(FILE *fh, class_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_class_t(Common::SeekableReadStream *fh, class_t* save_struc, const char *lastval, int *line, int *hiteof) { char *token; int min, max, i; -#line 547 "savegame.cfsml" +#line 546 "savegame.cfsml" int assignment, closed, done; if (strcmp(lastval, "{")) { @@ -2699,20 +2766,20 @@ _cfsml_read_class_t(FILE *fh, class_t* save_struc, const char *lastval, int *lin return CFSML_FAILURE; } if (!strcmp(token, "script")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->script), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for script at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "reg")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (read_reg_t(fh, (reg_t*) &(save_struc->reg), value, line, hiteof)) { _cfsml_error("Token expected by read_reg_t() for reg at line %d\n", *line); return CFSML_FAILURE; } } else -#line 703 "savegame.cfsml" +#line 702 "savegame.cfsml" { _cfsml_error("class_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; @@ -2722,19 +2789,19 @@ _cfsml_read_class_t(FILE *fh, class_t* save_struc, const char *lastval, int *lin return CFSML_SUCCESS; } -#line 396 "savegame.cfsml" +#line 395 "savegame.cfsml" static void -_cfsml_write_song_handle_t(FILE *fh, song_handle_t* save_struc) +_cfsml_write_song_handle_t(Common::WriteStream *fh, song_handle_t* save_struc) { - fprintf(fh, "%li", (long)*save_struc); + WSprintf(fh, "%li", (long)*save_struc); } -#line 489 "savegame.cfsml" +#line 488 "savegame.cfsml" static int -_cfsml_read_song_handle_t(FILE *fh, song_handle_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_song_handle_t(Common::SeekableReadStream *fh, song_handle_t* save_struc, const char *lastval, int *line, int *hiteof) { char *token; -#line 513 "savegame.cfsml" +#line 512 "savegame.cfsml" *save_struc = strtol(lastval, &token, 0); if ((*save_struc == 0) && (token == lastval)) { @@ -2748,19 +2815,19 @@ _cfsml_read_song_handle_t(FILE *fh, song_handle_t* save_struc, const char *lastv return CFSML_SUCCESS; } -#line 396 "savegame.cfsml" +#line 395 "savegame.cfsml" static void -_cfsml_write_int(FILE *fh, int* save_struc) +_cfsml_write_int(Common::WriteStream *fh, int* save_struc) { - fprintf(fh, "%li", (long)*save_struc); + WSprintf(fh, "%li", (long)*save_struc); } -#line 489 "savegame.cfsml" +#line 488 "savegame.cfsml" static int -_cfsml_read_int(FILE *fh, int* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_int(Common::SeekableReadStream *fh, int* save_struc, const char *lastval, int *line, int *hiteof) { char *token; -#line 513 "savegame.cfsml" +#line 512 "savegame.cfsml" *save_struc = strtol(lastval, &token, 0); if ((*save_struc == 0) && (token == lastval)) { @@ -2774,45 +2841,163 @@ _cfsml_read_int(FILE *fh, int* save_struc, const char *lastval, int *line, int * return CFSML_SUCCESS; } -#line 396 "savegame.cfsml" +#line 395 "savegame.cfsml" +static void +_cfsml_write_SavegameMetadata(Common::WriteStream *fh, SavegameMetadata* save_struc) +{ + int min, max, i; + +#line 415 "savegame.cfsml" + WSprintf(fh, "{\n"); + WSprintf(fh, "savegame_name = "); + _cfsml_write_string(fh, (char **) &(save_struc->savegame_name)); + WSprintf(fh, "\n"); + WSprintf(fh, "savegame_version = "); + _cfsml_write_int(fh, (int*) &(save_struc->savegame_version)); + WSprintf(fh, "\n"); + WSprintf(fh, "game_version = "); + _cfsml_write_string(fh, (char **) &(save_struc->game_version)); + WSprintf(fh, "\n"); + WSprintf(fh, "version = "); + write_sci_version(fh, (sci_version_t*) &(save_struc->version)); + WSprintf(fh, "\n"); + WSprintf(fh, "savegame_date = "); + _cfsml_write_int(fh, (int*) &(save_struc->savegame_date)); + WSprintf(fh, "\n"); + WSprintf(fh, "savegame_time = "); + _cfsml_write_int(fh, (int*) &(save_struc->savegame_time)); + WSprintf(fh, "\n"); + WSprintf(fh, "}"); +} + +#line 488 "savegame.cfsml" +static int +_cfsml_read_SavegameMetadata(Common::SeekableReadStream *fh, SavegameMetadata* save_struc, const char *lastval, int *line, int *hiteof) +{ + char *token; + int min, max, i; +#line 546 "savegame.cfsml" + int assignment, closed, done; + + if (strcmp(lastval, "{")) { + _cfsml_error("Reading record SavegameMetadata; expected opening braces in line %d, got \"%s\"\n", *line, lastval); + return CFSML_FAILURE; + }; + closed = 0; + do { + const char *value; + token = _cfsml_get_identifier(fh, line, hiteof, &assignment); + + if (!token) { + _cfsml_error("Expected token at line %d\n", *line); + return CFSML_FAILURE; + } + if (!assignment) { + if (!strcmp(token, "}")) + closed = 1; + else { + _cfsml_error("Expected assignment or closing braces in line %d\n", *line); + return CFSML_FAILURE; + } + } else { + value = ""; + while (!value || !strcmp(value, "")) + value = _cfsml_get_value(fh, line, hiteof); + if (!value) { + _cfsml_error("Expected token at line %d\n", *line); + return CFSML_FAILURE; + } + if (!strcmp(token, "savegame_name")) { +#line 693 "savegame.cfsml" + if (_cfsml_read_string(fh, (char **) &(save_struc->savegame_name), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_string() for savegame_name at line %d\n", *line); + return CFSML_FAILURE; + } + } else + if (!strcmp(token, "savegame_version")) { +#line 693 "savegame.cfsml" + if (_cfsml_read_int(fh, (int*) &(save_struc->savegame_version), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_int() for savegame_version at line %d\n", *line); + return CFSML_FAILURE; + } + } else + if (!strcmp(token, "game_version")) { +#line 693 "savegame.cfsml" + if (_cfsml_read_string(fh, (char **) &(save_struc->game_version), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_string() for game_version at line %d\n", *line); + return CFSML_FAILURE; + } + } else + if (!strcmp(token, "version")) { +#line 693 "savegame.cfsml" + if (read_sci_version(fh, (sci_version_t*) &(save_struc->version), value, line, hiteof)) { + _cfsml_error("Token expected by read_sci_version() for version at line %d\n", *line); + return CFSML_FAILURE; + } + } else + if (!strcmp(token, "savegame_date")) { +#line 693 "savegame.cfsml" + if (_cfsml_read_int(fh, (int*) &(save_struc->savegame_date), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_int() for savegame_date at line %d\n", *line); + return CFSML_FAILURE; + } + } else + if (!strcmp(token, "savegame_time")) { +#line 693 "savegame.cfsml" + if (_cfsml_read_int(fh, (int*) &(save_struc->savegame_time), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_int() for savegame_time at line %d\n", *line); + return CFSML_FAILURE; + } + } else +#line 702 "savegame.cfsml" + { + _cfsml_error("SavegameMetadata: Assignment to invalid identifier '%s' in line %d\n", token, *line); + return CFSML_FAILURE; + } + } + } while (!closed); // Until closing braces are hit + return CFSML_SUCCESS; +} + +#line 395 "savegame.cfsml" static void -_cfsml_write_menu_t(FILE *fh, menu_t* save_struc) +_cfsml_write_menu_t(Common::WriteStream *fh, menu_t* save_struc) { int min, max, i; -#line 416 "savegame.cfsml" - fprintf(fh, "{\n"); - fprintf(fh, "title = "); +#line 415 "savegame.cfsml" + WSprintf(fh, "{\n"); + WSprintf(fh, "title = "); _cfsml_write_string(fh, (char **) &(save_struc->title)); - fprintf(fh, "\n"); - fprintf(fh, "title_width = "); + WSprintf(fh, "\n"); + WSprintf(fh, "title_width = "); _cfsml_write_int(fh, (int*) &(save_struc->title_width)); - fprintf(fh, "\n"); - fprintf(fh, "width = "); + WSprintf(fh, "\n"); + WSprintf(fh, "width = "); _cfsml_write_int(fh, (int*) &(save_struc->width)); - fprintf(fh, "\n"); - fprintf(fh, "items = "); + WSprintf(fh, "\n"); + WSprintf(fh, "items = "); min = max = save_struc->items_nr; if (!save_struc->items) min = max = 0; /* Don't write if it points to NULL */ -#line 442 "savegame.cfsml" - fprintf(fh, "[%d][\n", max); +#line 441 "savegame.cfsml" + WSprintf(fh, "[%d][\n", max); for (i = 0; i < min; i++) { _cfsml_write_menu_item_t(fh, &(save_struc->items[i])); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); } - fprintf(fh, "]"); - fprintf(fh, "\n"); - fprintf(fh, "}"); + WSprintf(fh, "]"); + WSprintf(fh, "\n"); + WSprintf(fh, "}"); } -#line 489 "savegame.cfsml" +#line 488 "savegame.cfsml" static int -_cfsml_read_menu_t(FILE *fh, menu_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_menu_t(Common::SeekableReadStream *fh, menu_t* save_struc, const char *lastval, int *line, int *hiteof) { char *token; int min, max, i; -#line 547 "savegame.cfsml" +#line 546 "savegame.cfsml" int assignment, closed, done; if (strcmp(lastval, "{")) { @@ -2844,33 +3029,33 @@ _cfsml_read_menu_t(FILE *fh, menu_t* save_struc, const char *lastval, int *line, return CFSML_FAILURE; } if (!strcmp(token, "title")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_string(fh, (char **) &(save_struc->title), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_string() for title at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "title_width")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->title_width), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for title_width at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "width")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->width), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for width at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "items")) { -#line 609 "savegame.cfsml" +#line 608 "savegame.cfsml" if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) { _cfsml_error("Opening brackets expected at line %d\n", *line); return CFSML_FAILURE; } -#line 619 "savegame.cfsml" +#line 618 "savegame.cfsml" // Prepare to restore dynamic array max = strtol(value + 1, NULL, 0); if (max < 0) { @@ -2886,11 +3071,11 @@ _cfsml_read_menu_t(FILE *fh, menu_t* save_struc, const char *lastval, int *line, _cfsml_register_pointer(save_struc->items); } else save_struc->items = NULL; -#line 643 "savegame.cfsml" +#line 642 "savegame.cfsml" done = i = 0; do { if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) { -#line 651 "savegame.cfsml" +#line 650 "savegame.cfsml" _cfsml_error("Token expected at line %d\n", *line); return 1; } @@ -2908,7 +3093,7 @@ _cfsml_read_menu_t(FILE *fh, menu_t* save_struc, const char *lastval, int *line, } while (!done); save_struc->items_nr = max ; // Set array size accordingly } else -#line 703 "savegame.cfsml" +#line 702 "savegame.cfsml" { _cfsml_error("menu_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; @@ -2918,48 +3103,48 @@ _cfsml_read_menu_t(FILE *fh, menu_t* save_struc, const char *lastval, int *line, return CFSML_SUCCESS; } -#line 396 "savegame.cfsml" +#line 395 "savegame.cfsml" static void -_cfsml_write_clone_table_t(FILE *fh, clone_table_t* save_struc) +_cfsml_write_clone_table_t(Common::WriteStream *fh, clone_table_t* save_struc) { int min, max, i; -#line 416 "savegame.cfsml" - fprintf(fh, "{\n"); - fprintf(fh, "entries_nr = "); +#line 415 "savegame.cfsml" + WSprintf(fh, "{\n"); + WSprintf(fh, "entries_nr = "); _cfsml_write_int(fh, (int*) &(save_struc->entries_nr)); - fprintf(fh, "\n"); - fprintf(fh, "first_free = "); + WSprintf(fh, "\n"); + WSprintf(fh, "first_free = "); _cfsml_write_int(fh, (int*) &(save_struc->first_free)); - fprintf(fh, "\n"); - fprintf(fh, "entries_used = "); + WSprintf(fh, "\n"); + WSprintf(fh, "entries_used = "); _cfsml_write_int(fh, (int*) &(save_struc->entries_used)); - fprintf(fh, "\n"); - fprintf(fh, "max_entry = "); + WSprintf(fh, "\n"); + WSprintf(fh, "max_entry = "); _cfsml_write_int(fh, (int*) &(save_struc->max_entry)); - fprintf(fh, "\n"); - fprintf(fh, "table = "); + WSprintf(fh, "\n"); + WSprintf(fh, "table = "); min = max = save_struc->entries_nr; if (!save_struc->table) min = max = 0; /* Don't write if it points to NULL */ -#line 442 "savegame.cfsml" - fprintf(fh, "[%d][\n", max); +#line 441 "savegame.cfsml" + WSprintf(fh, "[%d][\n", max); for (i = 0; i < min; i++) { _cfsml_write_clone_entry_t(fh, &(save_struc->table[i])); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); } - fprintf(fh, "]"); - fprintf(fh, "\n"); - fprintf(fh, "}"); + WSprintf(fh, "]"); + WSprintf(fh, "\n"); + WSprintf(fh, "}"); } -#line 489 "savegame.cfsml" +#line 488 "savegame.cfsml" static int -_cfsml_read_clone_table_t(FILE *fh, clone_table_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_clone_table_t(Common::SeekableReadStream *fh, clone_table_t* save_struc, const char *lastval, int *line, int *hiteof) { char *token; int min, max, i; -#line 547 "savegame.cfsml" +#line 546 "savegame.cfsml" int assignment, closed, done; if (strcmp(lastval, "{")) { @@ -2991,40 +3176,40 @@ _cfsml_read_clone_table_t(FILE *fh, clone_table_t* save_struc, const char *lastv return CFSML_FAILURE; } if (!strcmp(token, "entries_nr")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->entries_nr), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for entries_nr at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "first_free")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->first_free), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for first_free at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "entries_used")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->entries_used), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for entries_used at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "max_entry")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->max_entry), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for max_entry at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "table")) { -#line 609 "savegame.cfsml" +#line 608 "savegame.cfsml" if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) { _cfsml_error("Opening brackets expected at line %d\n", *line); return CFSML_FAILURE; } -#line 619 "savegame.cfsml" +#line 618 "savegame.cfsml" // Prepare to restore dynamic array max = strtol(value + 1, NULL, 0); if (max < 0) { @@ -3040,11 +3225,11 @@ _cfsml_read_clone_table_t(FILE *fh, clone_table_t* save_struc, const char *lastv _cfsml_register_pointer(save_struc->table); } else save_struc->table = NULL; -#line 643 "savegame.cfsml" +#line 642 "savegame.cfsml" done = i = 0; do { if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) { -#line 651 "savegame.cfsml" +#line 650 "savegame.cfsml" _cfsml_error("Token expected at line %d\n", *line); return 1; } @@ -3062,7 +3247,7 @@ _cfsml_read_clone_table_t(FILE *fh, clone_table_t* save_struc, const char *lastv } while (!done); save_struc->entries_nr = max ; // Set array size accordingly } else -#line 703 "savegame.cfsml" +#line 702 "savegame.cfsml" { _cfsml_error("clone_table_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; @@ -3072,51 +3257,51 @@ _cfsml_read_clone_table_t(FILE *fh, clone_table_t* save_struc, const char *lastv return CFSML_SUCCESS; } -#line 396 "savegame.cfsml" +#line 395 "savegame.cfsml" static void -_cfsml_write_clone_t(FILE *fh, clone_t* save_struc) +_cfsml_write_clone_t(Common::WriteStream *fh, clone_t* save_struc) { int min, max, i; -#line 416 "savegame.cfsml" - fprintf(fh, "{\n"); - fprintf(fh, "flags = "); +#line 415 "savegame.cfsml" + WSprintf(fh, "{\n"); + WSprintf(fh, "flags = "); _cfsml_write_int(fh, (int*) &(save_struc->flags)); - fprintf(fh, "\n"); - fprintf(fh, "pos = "); + WSprintf(fh, "\n"); + WSprintf(fh, "pos = "); write_reg_t(fh, (reg_t*) &(save_struc->pos)); - fprintf(fh, "\n"); - fprintf(fh, "variables_nr = "); + WSprintf(fh, "\n"); + WSprintf(fh, "variables_nr = "); _cfsml_write_int(fh, (int*) &(save_struc->variables_nr)); - fprintf(fh, "\n"); - fprintf(fh, "variable_names_nr = "); + WSprintf(fh, "\n"); + WSprintf(fh, "variable_names_nr = "); _cfsml_write_int(fh, (int*) &(save_struc->variable_names_nr)); - fprintf(fh, "\n"); - fprintf(fh, "methods_nr = "); + WSprintf(fh, "\n"); + WSprintf(fh, "methods_nr = "); _cfsml_write_int(fh, (int*) &(save_struc->methods_nr)); - fprintf(fh, "\n"); - fprintf(fh, "variables = "); + WSprintf(fh, "\n"); + WSprintf(fh, "variables = "); min = max = save_struc->variables_nr; if (!save_struc->variables) min = max = 0; /* Don't write if it points to NULL */ -#line 442 "savegame.cfsml" - fprintf(fh, "[%d][\n", max); +#line 441 "savegame.cfsml" + WSprintf(fh, "[%d][\n", max); for (i = 0; i < min; i++) { write_reg_t(fh, &(save_struc->variables[i])); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); } - fprintf(fh, "]"); - fprintf(fh, "\n"); - fprintf(fh, "}"); + WSprintf(fh, "]"); + WSprintf(fh, "\n"); + WSprintf(fh, "}"); } -#line 489 "savegame.cfsml" +#line 488 "savegame.cfsml" static int -_cfsml_read_clone_t(FILE *fh, clone_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_clone_t(Common::SeekableReadStream *fh, clone_t* save_struc, const char *lastval, int *line, int *hiteof) { char *token; int min, max, i; -#line 547 "savegame.cfsml" +#line 546 "savegame.cfsml" int assignment, closed, done; if (strcmp(lastval, "{")) { @@ -3148,47 +3333,47 @@ _cfsml_read_clone_t(FILE *fh, clone_t* save_struc, const char *lastval, int *lin return CFSML_FAILURE; } if (!strcmp(token, "flags")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->flags), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for flags at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "pos")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (read_reg_t(fh, (reg_t*) &(save_struc->pos), value, line, hiteof)) { _cfsml_error("Token expected by read_reg_t() for pos at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "variables_nr")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->variables_nr), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for variables_nr at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "variable_names_nr")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->variable_names_nr), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for variable_names_nr at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "methods_nr")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->methods_nr), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for methods_nr at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "variables")) { -#line 609 "savegame.cfsml" +#line 608 "savegame.cfsml" if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) { _cfsml_error("Opening brackets expected at line %d\n", *line); return CFSML_FAILURE; } -#line 619 "savegame.cfsml" +#line 618 "savegame.cfsml" // Prepare to restore dynamic array max = strtol(value + 1, NULL, 0); if (max < 0) { @@ -3204,11 +3389,11 @@ _cfsml_read_clone_t(FILE *fh, clone_t* save_struc, const char *lastval, int *lin _cfsml_register_pointer(save_struc->variables); } else save_struc->variables = NULL; -#line 643 "savegame.cfsml" +#line 642 "savegame.cfsml" done = i = 0; do { if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) { -#line 651 "savegame.cfsml" +#line 650 "savegame.cfsml" _cfsml_error("Token expected at line %d\n", *line); return 1; } @@ -3226,7 +3411,7 @@ _cfsml_read_clone_t(FILE *fh, clone_t* save_struc, const char *lastval, int *lin } while (!done); save_struc->variables_nr = max ; // Set array size accordingly } else -#line 703 "savegame.cfsml" +#line 702 "savegame.cfsml" { _cfsml_error("clone_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; @@ -3236,30 +3421,30 @@ _cfsml_read_clone_t(FILE *fh, clone_t* save_struc, const char *lastval, int *lin return CFSML_SUCCESS; } -#line 396 "savegame.cfsml" +#line 395 "savegame.cfsml" static void -_cfsml_write_list_t(FILE *fh, list_t* save_struc) +_cfsml_write_list_t(Common::WriteStream *fh, list_t* save_struc) { int min, max, i; -#line 416 "savegame.cfsml" - fprintf(fh, "{\n"); - fprintf(fh, "first = "); +#line 415 "savegame.cfsml" + WSprintf(fh, "{\n"); + WSprintf(fh, "first = "); write_reg_t(fh, (reg_t*) &(save_struc->first)); - fprintf(fh, "\n"); - fprintf(fh, "last = "); + WSprintf(fh, "\n"); + WSprintf(fh, "last = "); write_reg_t(fh, (reg_t*) &(save_struc->last)); - fprintf(fh, "\n"); - fprintf(fh, "}"); + WSprintf(fh, "\n"); + WSprintf(fh, "}"); } -#line 489 "savegame.cfsml" +#line 488 "savegame.cfsml" static int -_cfsml_read_list_t(FILE *fh, list_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_list_t(Common::SeekableReadStream *fh, list_t* save_struc, const char *lastval, int *line, int *hiteof) { char *token; int min, max, i; -#line 547 "savegame.cfsml" +#line 546 "savegame.cfsml" int assignment, closed, done; if (strcmp(lastval, "{")) { @@ -3291,20 +3476,20 @@ _cfsml_read_list_t(FILE *fh, list_t* save_struc, const char *lastval, int *line, return CFSML_FAILURE; } if (!strcmp(token, "first")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (read_reg_t(fh, (reg_t*) &(save_struc->first), value, line, hiteof)) { _cfsml_error("Token expected by read_reg_t() for first at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "last")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (read_reg_t(fh, (reg_t*) &(save_struc->last), value, line, hiteof)) { _cfsml_error("Token expected by read_reg_t() for last at line %d\n", *line); return CFSML_FAILURE; } } else -#line 703 "savegame.cfsml" +#line 702 "savegame.cfsml" { _cfsml_error("list_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; @@ -3314,33 +3499,33 @@ _cfsml_read_list_t(FILE *fh, list_t* save_struc, const char *lastval, int *line, return CFSML_SUCCESS; } -#line 396 "savegame.cfsml" +#line 395 "savegame.cfsml" static void -_cfsml_write_sys_string_t(FILE *fh, sys_string_t* save_struc) +_cfsml_write_sys_string_t(Common::WriteStream *fh, sys_string_t* save_struc) { int min, max, i; -#line 416 "savegame.cfsml" - fprintf(fh, "{\n"); - fprintf(fh, "name = "); +#line 415 "savegame.cfsml" + WSprintf(fh, "{\n"); + WSprintf(fh, "name = "); _cfsml_write_string(fh, (char **) &(save_struc->name)); - fprintf(fh, "\n"); - fprintf(fh, "max_size = "); + WSprintf(fh, "\n"); + WSprintf(fh, "max_size = "); _cfsml_write_int(fh, (int*) &(save_struc->max_size)); - fprintf(fh, "\n"); - fprintf(fh, "value = "); + WSprintf(fh, "\n"); + WSprintf(fh, "value = "); _cfsml_write_string(fh, (char **) &(save_struc->value)); - fprintf(fh, "\n"); - fprintf(fh, "}"); + WSprintf(fh, "\n"); + WSprintf(fh, "}"); } -#line 489 "savegame.cfsml" +#line 488 "savegame.cfsml" static int -_cfsml_read_sys_string_t(FILE *fh, sys_string_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_sys_string_t(Common::SeekableReadStream *fh, sys_string_t* save_struc, const char *lastval, int *line, int *hiteof) { char *token; int min, max, i; -#line 547 "savegame.cfsml" +#line 546 "savegame.cfsml" int assignment, closed, done; if (strcmp(lastval, "{")) { @@ -3372,27 +3557,27 @@ _cfsml_read_sys_string_t(FILE *fh, sys_string_t* save_struc, const char *lastval return CFSML_FAILURE; } if (!strcmp(token, "name")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_string(fh, (char **) &(save_struc->name), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_string() for name at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "max_size")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->max_size), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for max_size at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "value")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_string(fh, (char **) &(save_struc->value), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_string() for value at line %d\n", *line); return CFSML_FAILURE; } } else -#line 703 "savegame.cfsml" +#line 702 "savegame.cfsml" { _cfsml_error("sys_string_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; @@ -3402,75 +3587,75 @@ _cfsml_read_sys_string_t(FILE *fh, sys_string_t* save_struc, const char *lastval return CFSML_SUCCESS; } -#line 396 "savegame.cfsml" +#line 395 "savegame.cfsml" static void -_cfsml_write_script_t(FILE *fh, script_t* save_struc) +_cfsml_write_script_t(Common::WriteStream *fh, script_t* save_struc) { int min, max, i; -#line 416 "savegame.cfsml" - fprintf(fh, "{\n"); - fprintf(fh, "nr = "); +#line 415 "savegame.cfsml" + WSprintf(fh, "{\n"); + WSprintf(fh, "nr = "); _cfsml_write_int(fh, (int*) &(save_struc->nr)); - fprintf(fh, "\n"); - fprintf(fh, "buf_size = "); + WSprintf(fh, "\n"); + WSprintf(fh, "buf_size = "); _cfsml_write_size_t(fh, (size_t*) &(save_struc->buf_size)); - fprintf(fh, "\n"); - fprintf(fh, "script_size = "); + WSprintf(fh, "\n"); + WSprintf(fh, "script_size = "); _cfsml_write_size_t(fh, (size_t*) &(save_struc->script_size)); - fprintf(fh, "\n"); - fprintf(fh, "heap_size = "); + WSprintf(fh, "\n"); + WSprintf(fh, "heap_size = "); _cfsml_write_size_t(fh, (size_t*) &(save_struc->heap_size)); - fprintf(fh, "\n"); - fprintf(fh, "obj_indices = "); + WSprintf(fh, "\n"); + WSprintf(fh, "obj_indices = "); write_int_hash_map_tp(fh, (int_hash_map_t **) &(save_struc->obj_indices)); - fprintf(fh, "\n"); - fprintf(fh, "exports_nr = "); + WSprintf(fh, "\n"); + WSprintf(fh, "exports_nr = "); _cfsml_write_int(fh, (int*) &(save_struc->exports_nr)); - fprintf(fh, "\n"); - fprintf(fh, "synonyms_nr = "); + WSprintf(fh, "\n"); + WSprintf(fh, "synonyms_nr = "); _cfsml_write_int(fh, (int*) &(save_struc->synonyms_nr)); - fprintf(fh, "\n"); - fprintf(fh, "lockers = "); + WSprintf(fh, "\n"); + WSprintf(fh, "lockers = "); _cfsml_write_int(fh, (int*) &(save_struc->lockers)); - fprintf(fh, "\n"); - fprintf(fh, "objects_allocated = "); + WSprintf(fh, "\n"); + WSprintf(fh, "objects_allocated = "); _cfsml_write_int(fh, (int*) &(save_struc->objects_allocated)); - fprintf(fh, "\n"); - fprintf(fh, "objects_nr = "); + WSprintf(fh, "\n"); + WSprintf(fh, "objects_nr = "); _cfsml_write_int(fh, (int*) &(save_struc->objects_nr)); - fprintf(fh, "\n"); - fprintf(fh, "objects = "); + WSprintf(fh, "\n"); + WSprintf(fh, "objects = "); min = max = save_struc->objects_allocated; if (!save_struc->objects) min = max = 0; /* Don't write if it points to NULL */ -#line 442 "savegame.cfsml" - fprintf(fh, "[%d][\n", max); +#line 441 "savegame.cfsml" + WSprintf(fh, "[%d][\n", max); for (i = 0; i < min; i++) { _cfsml_write_object_t(fh, &(save_struc->objects[i])); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); } - fprintf(fh, "]"); - fprintf(fh, "\n"); - fprintf(fh, "locals_offset = "); + WSprintf(fh, "]"); + WSprintf(fh, "\n"); + WSprintf(fh, "locals_offset = "); _cfsml_write_int(fh, (int*) &(save_struc->locals_offset)); - fprintf(fh, "\n"); - fprintf(fh, "locals_segment = "); + WSprintf(fh, "\n"); + WSprintf(fh, "locals_segment = "); _cfsml_write_int(fh, (int*) &(save_struc->locals_segment)); - fprintf(fh, "\n"); - fprintf(fh, "marked_as_deleted = "); + WSprintf(fh, "\n"); + WSprintf(fh, "marked_as_deleted = "); _cfsml_write_int(fh, (int*) &(save_struc->marked_as_deleted)); - fprintf(fh, "\n"); - fprintf(fh, "}"); + WSprintf(fh, "\n"); + WSprintf(fh, "}"); } -#line 489 "savegame.cfsml" +#line 488 "savegame.cfsml" static int -_cfsml_read_script_t(FILE *fh, script_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_script_t(Common::SeekableReadStream *fh, script_t* save_struc, const char *lastval, int *line, int *hiteof) { char *token; int min, max, i; -#line 547 "savegame.cfsml" +#line 546 "savegame.cfsml" int assignment, closed, done; if (strcmp(lastval, "{")) { @@ -3502,82 +3687,82 @@ _cfsml_read_script_t(FILE *fh, script_t* save_struc, const char *lastval, int *l return CFSML_FAILURE; } if (!strcmp(token, "nr")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->nr), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for nr at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "buf_size")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_size_t(fh, (size_t*) &(save_struc->buf_size), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_size_t() for buf_size at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "script_size")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_size_t(fh, (size_t*) &(save_struc->script_size), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_size_t() for script_size at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "heap_size")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_size_t(fh, (size_t*) &(save_struc->heap_size), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_size_t() for heap_size at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "obj_indices")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (read_int_hash_map_tp(fh, (int_hash_map_t **) &(save_struc->obj_indices), value, line, hiteof)) { _cfsml_error("Token expected by read_int_hash_map_tp() for obj_indices at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "exports_nr")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->exports_nr), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for exports_nr at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "synonyms_nr")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->synonyms_nr), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for synonyms_nr at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "lockers")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->lockers), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for lockers at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "objects_allocated")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->objects_allocated), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for objects_allocated at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "objects_nr")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->objects_nr), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for objects_nr at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "objects")) { -#line 609 "savegame.cfsml" +#line 608 "savegame.cfsml" if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) { _cfsml_error("Opening brackets expected at line %d\n", *line); return CFSML_FAILURE; } -#line 619 "savegame.cfsml" +#line 618 "savegame.cfsml" // Prepare to restore dynamic array max = strtol(value + 1, NULL, 0); if (max < 0) { @@ -3593,11 +3778,11 @@ _cfsml_read_script_t(FILE *fh, script_t* save_struc, const char *lastval, int *l _cfsml_register_pointer(save_struc->objects); } else save_struc->objects = NULL; -#line 643 "savegame.cfsml" +#line 642 "savegame.cfsml" done = i = 0; do { if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) { -#line 651 "savegame.cfsml" +#line 650 "savegame.cfsml" _cfsml_error("Token expected at line %d\n", *line); return 1; } @@ -3616,27 +3801,27 @@ _cfsml_read_script_t(FILE *fh, script_t* save_struc, const char *lastval, int *l save_struc->objects_allocated = max ; // Set array size accordingly } else if (!strcmp(token, "locals_offset")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->locals_offset), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for locals_offset at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "locals_segment")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->locals_segment), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for locals_segment at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "marked_as_deleted")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->marked_as_deleted), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for marked_as_deleted at line %d\n", *line); return CFSML_FAILURE; } } else -#line 703 "savegame.cfsml" +#line 702 "savegame.cfsml" { _cfsml_error("script_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; @@ -3646,66 +3831,66 @@ _cfsml_read_script_t(FILE *fh, script_t* save_struc, const char *lastval, int *l return CFSML_SUCCESS; } -#line 396 "savegame.cfsml" +#line 395 "savegame.cfsml" static void -_cfsml_write_seg_manager_t(FILE *fh, seg_manager_t* save_struc) +_cfsml_write_seg_manager_t(Common::WriteStream *fh, seg_manager_t* save_struc) { int min, max, i; -#line 416 "savegame.cfsml" - fprintf(fh, "{\n"); - fprintf(fh, "id_seg_map = "); +#line 415 "savegame.cfsml" + WSprintf(fh, "{\n"); + WSprintf(fh, "id_seg_map = "); write_int_hash_map_tp(fh, (int_hash_map_t **) &(save_struc->id_seg_map)); - fprintf(fh, "\n"); - fprintf(fh, "heap = "); + WSprintf(fh, "\n"); + WSprintf(fh, "heap = "); min = max = save_struc->heap_size; if (!save_struc->heap) min = max = 0; /* Don't write if it points to NULL */ -#line 442 "savegame.cfsml" - fprintf(fh, "[%d][\n", max); +#line 441 "savegame.cfsml" + WSprintf(fh, "[%d][\n", max); for (i = 0; i < min; i++) { write_mem_obj_tp(fh, &(save_struc->heap[i])); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); } - fprintf(fh, "]"); - fprintf(fh, "\n"); - fprintf(fh, "heap_size = "); + WSprintf(fh, "]"); + WSprintf(fh, "\n"); + WSprintf(fh, "heap_size = "); _cfsml_write_int(fh, (int*) &(save_struc->heap_size)); - fprintf(fh, "\n"); - fprintf(fh, "reserved_id = "); + WSprintf(fh, "\n"); + WSprintf(fh, "reserved_id = "); _cfsml_write_int(fh, (int*) &(save_struc->reserved_id)); - fprintf(fh, "\n"); - fprintf(fh, "exports_wide = "); + WSprintf(fh, "\n"); + WSprintf(fh, "exports_wide = "); _cfsml_write_int(fh, (int*) &(save_struc->exports_wide)); - fprintf(fh, "\n"); - fprintf(fh, "sci1_1 = "); + WSprintf(fh, "\n"); + WSprintf(fh, "sci1_1 = "); _cfsml_write_int(fh, (int*) &(save_struc->sci1_1)); - fprintf(fh, "\n"); - fprintf(fh, "gc_mark_bits = "); + WSprintf(fh, "\n"); + WSprintf(fh, "gc_mark_bits = "); _cfsml_write_int(fh, (int*) &(save_struc->gc_mark_bits)); - fprintf(fh, "\n"); - fprintf(fh, "mem_allocated = "); + WSprintf(fh, "\n"); + WSprintf(fh, "mem_allocated = "); _cfsml_write_size_t(fh, (size_t*) &(save_struc->mem_allocated)); - fprintf(fh, "\n"); - fprintf(fh, "clones_seg_id = "); + WSprintf(fh, "\n"); + WSprintf(fh, "clones_seg_id = "); _cfsml_write_seg_id_t(fh, (seg_id_t*) &(save_struc->clones_seg_id)); - fprintf(fh, "\n"); - fprintf(fh, "lists_seg_id = "); + WSprintf(fh, "\n"); + WSprintf(fh, "lists_seg_id = "); _cfsml_write_seg_id_t(fh, (seg_id_t*) &(save_struc->lists_seg_id)); - fprintf(fh, "\n"); - fprintf(fh, "nodes_seg_id = "); + WSprintf(fh, "\n"); + WSprintf(fh, "nodes_seg_id = "); _cfsml_write_seg_id_t(fh, (seg_id_t*) &(save_struc->nodes_seg_id)); - fprintf(fh, "\n"); - fprintf(fh, "}"); + WSprintf(fh, "\n"); + WSprintf(fh, "}"); } -#line 489 "savegame.cfsml" +#line 488 "savegame.cfsml" static int -_cfsml_read_seg_manager_t(FILE *fh, seg_manager_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_seg_manager_t(Common::SeekableReadStream *fh, seg_manager_t* save_struc, const char *lastval, int *line, int *hiteof) { char *token; int min, max, i; -#line 547 "savegame.cfsml" +#line 546 "savegame.cfsml" int assignment, closed, done; if (strcmp(lastval, "{")) { @@ -3737,19 +3922,19 @@ _cfsml_read_seg_manager_t(FILE *fh, seg_manager_t* save_struc, const char *lastv return CFSML_FAILURE; } if (!strcmp(token, "id_seg_map")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (read_int_hash_map_tp(fh, (int_hash_map_t **) &(save_struc->id_seg_map), value, line, hiteof)) { _cfsml_error("Token expected by read_int_hash_map_tp() for id_seg_map at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "heap")) { -#line 609 "savegame.cfsml" +#line 608 "savegame.cfsml" if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) { _cfsml_error("Opening brackets expected at line %d\n", *line); return CFSML_FAILURE; } -#line 619 "savegame.cfsml" +#line 618 "savegame.cfsml" // Prepare to restore dynamic array max = strtol(value + 1, NULL, 0); if (max < 0) { @@ -3765,11 +3950,11 @@ _cfsml_read_seg_manager_t(FILE *fh, seg_manager_t* save_struc, const char *lastv _cfsml_register_pointer(save_struc->heap); } else save_struc->heap = NULL; -#line 643 "savegame.cfsml" +#line 642 "savegame.cfsml" done = i = 0; do { if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) { -#line 651 "savegame.cfsml" +#line 650 "savegame.cfsml" _cfsml_error("Token expected at line %d\n", *line); return 1; } @@ -3788,69 +3973,69 @@ _cfsml_read_seg_manager_t(FILE *fh, seg_manager_t* save_struc, const char *lastv save_struc->heap_size = max ; // Set array size accordingly } else if (!strcmp(token, "heap_size")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->heap_size), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for heap_size at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "reserved_id")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->reserved_id), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for reserved_id at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "exports_wide")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->exports_wide), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for exports_wide at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "sci1_1")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->sci1_1), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for sci1_1 at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "gc_mark_bits")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_int(fh, (int*) &(save_struc->gc_mark_bits), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_int() for gc_mark_bits at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "mem_allocated")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_size_t(fh, (size_t*) &(save_struc->mem_allocated), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_size_t() for mem_allocated at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "clones_seg_id")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_seg_id_t(fh, (seg_id_t*) &(save_struc->clones_seg_id), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_seg_id_t() for clones_seg_id at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "lists_seg_id")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_seg_id_t(fh, (seg_id_t*) &(save_struc->lists_seg_id), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_seg_id_t() for lists_seg_id at line %d\n", *line); return CFSML_FAILURE; } } else if (!strcmp(token, "nodes_seg_id")) { -#line 694 "savegame.cfsml" +#line 693 "savegame.cfsml" if (_cfsml_read_seg_id_t(fh, (seg_id_t*) &(save_struc->nodes_seg_id), value, line, hiteof)) { _cfsml_error("Token expected by _cfsml_read_seg_id_t() for nodes_seg_id at line %d\n", *line); return CFSML_FAILURE; } } else -#line 703 "savegame.cfsml" +#line 702 "savegame.cfsml" { _cfsml_error("seg_manager_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; @@ -3863,56 +4048,60 @@ _cfsml_read_seg_manager_t(FILE *fh, seg_manager_t* save_struc, const char *lastv // Auto-generated CFSML declaration and function block ends here // Auto-generation performed by cfsml.pl 0.8.2 -#line 384 "savegame.cfsml" +#line 457 "savegame.cfsml" -void write_songlib_t(FILE *fh, songlib_t *songlib) { +void write_songlib_t(Common::WriteStream *fh, songlib_t *songlib) { song_t *seeker = *(songlib->lib); int songcount = song_lib_count(*songlib); - fprintf(fh, "{\n"); - fprintf(fh, "songcount = %d\n", songcount); - fprintf(fh, "list = \n"); - fprintf(fh, "[\n"); + WSprintf(fh, "{\n"); + WSprintf(fh, "songcount = %d\n", songcount); + WSprintf(fh, "list = \n"); + WSprintf(fh, "[\n"); while (seeker) { seeker->restore_time = seeker->it->get_timepos(seeker->it); -#line 819 "savegame.cfsml" +#line 818 "savegame.cfsml" // Auto-generated CFSML data writer code _cfsml_write_song_t(fh, seeker); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 396 "savegame.cfsml" +#line 469 "savegame.cfsml" seeker = seeker->next; } - fprintf(fh, "]\n"); - fprintf(fh, "}\n"); + WSprintf(fh, "]\n"); + WSprintf(fh, "}\n"); } -int read_songlib_t(FILE *fh, songlib_t *songlib, const char *lastval, int *line, int *hiteof) { +int read_songlib_t(Common::SeekableReadStream *fh, songlib_t *songlib, const char *lastval, int *line, int *hiteof) { int songcount; int i; song_t *newsong; int oldstatus; - fscanf(fh, "{\n"); - fscanf(fh, "songcount = %d\n", &songcount); - fscanf(fh, "list = \n"); - fscanf(fh, "[\n"); + if (strcmp(lastval, "{")) { + _cfsml_error("Opening brackets expected at line %d\n", *line); + return CFSML_FAILURE; + } + // FIXME: error checking + SRSscanf(fh, "songcount = %d\n", &songcount); + SRSscanf(fh, "list = \n"); + SRSscanf(fh, "[\n"); *line += 4; song_lib_init(songlib); for (i = 0; i < songcount; i++) { // Auto-generated CFSML data reader code -#line 767 "savegame.cfsml" +#line 766 "savegame.cfsml" { -#line 778 "savegame.cfsml" +#line 777 "savegame.cfsml" int _cfsml_eof = 0, _cfsml_error; int dummy; -#line 783 "savegame.cfsml" +#line 782 "savegame.cfsml" const char *_cfsml_inp = lastval; -#line 790 "savegame.cfsml" +#line 789 "savegame.cfsml" _cfsml_error = read_song_tp(fh, &newsong, _cfsml_inp, &(*line), &_cfsml_eof); -#line 794 "savegame.cfsml" +#line 793 "savegame.cfsml" *hiteof = _cfsml_error; -#line 801 "savegame.cfsml" +#line 800 "savegame.cfsml" if (_cfsml_last_value_retrieved) { free(_cfsml_last_value_retrieved); _cfsml_last_value_retrieved = NULL; @@ -3923,11 +4112,11 @@ int read_songlib_t(FILE *fh, songlib_t *songlib, const char *lastval, int *line, } } // End of auto-generated CFSML data reader code -#line 416 "savegame.cfsml" +#line 493 "savegame.cfsml" song_lib_add(*songlib, newsong); } - fscanf(fh, "]\n"); - fscanf(fh, "}\n");; + SRSscanf(fh, "]\n"); + SRSscanf(fh, "}\n"); *line += 2; return 0; } @@ -3960,44 +4149,44 @@ int mem_obj_string_to_enum(const char *str) { static int bucket_length; -void write_int_hash_map_tp(FILE *fh, int_hash_map_t **foo) { -#line 819 "savegame.cfsml" +void write_int_hash_map_tp(Common::WriteStream *fh, int_hash_map_t **foo) { +#line 818 "savegame.cfsml" // Auto-generated CFSML data writer code _cfsml_write_int_hash_map_t(fh, *foo); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 454 "savegame.cfsml" +#line 531 "savegame.cfsml" } -void write_song_tp(FILE *fh, song_t **foo) { -#line 819 "savegame.cfsml" +void write_song_tp(Common::WriteStream *fh, song_t **foo) { +#line 818 "savegame.cfsml" // Auto-generated CFSML data writer code _cfsml_write_song_t(fh, *foo); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 458 "savegame.cfsml" +#line 535 "savegame.cfsml" } song_iterator_t *build_iterator(state_t *s, int song_nr, int type, songit_id_t id); -int read_song_tp(FILE *fh, song_t **foo, const char *lastval, int *line, int *hiteof) { +int read_song_tp(Common::SeekableReadStream *fh, song_t **foo, const char *lastval, int *line, int *hiteof) { char *token; int assignment; *foo = (song_t*) malloc(sizeof(song_t)); token = _cfsml_get_identifier(fh, line, hiteof, &assignment); // Auto-generated CFSML data reader code -#line 767 "savegame.cfsml" +#line 766 "savegame.cfsml" { -#line 778 "savegame.cfsml" +#line 777 "savegame.cfsml" int _cfsml_eof = 0, _cfsml_error; int dummy; -#line 783 "savegame.cfsml" +#line 782 "savegame.cfsml" const char *_cfsml_inp = token; -#line 790 "savegame.cfsml" +#line 789 "savegame.cfsml" _cfsml_error = _cfsml_read_song_t(fh, (*foo), _cfsml_inp, &(*line), &_cfsml_eof); -#line 794 "savegame.cfsml" +#line 793 "savegame.cfsml" *hiteof = _cfsml_error; -#line 801 "savegame.cfsml" +#line 800 "savegame.cfsml" if (_cfsml_last_value_retrieved) { free(_cfsml_last_value_retrieved); _cfsml_last_value_retrieved = NULL; @@ -4008,28 +4197,28 @@ int read_song_tp(FILE *fh, song_t **foo, const char *lastval, int *line, int *hi } } // End of auto-generated CFSML data reader code -#line 468 "savegame.cfsml" +#line 545 "savegame.cfsml" (*foo)->delay = 0; (*foo)->it = NULL; (*foo)->next_playing = (*foo)->next_stopping = (*foo)->next = NULL; return 0; } -int read_int_hash_map_tp(FILE *fh, int_hash_map_t **foo, const char *lastval, int *line, int *hiteof) { +int read_int_hash_map_tp(Common::SeekableReadStream *fh, int_hash_map_t **foo, const char *lastval, int *line, int *hiteof) { *foo = new int_hash_map_t; // Auto-generated CFSML data reader code -#line 767 "savegame.cfsml" +#line 766 "savegame.cfsml" { -#line 778 "savegame.cfsml" +#line 777 "savegame.cfsml" int _cfsml_eof = 0, _cfsml_error; int dummy; -#line 783 "savegame.cfsml" +#line 782 "savegame.cfsml" const char *_cfsml_inp = lastval; -#line 790 "savegame.cfsml" +#line 789 "savegame.cfsml" _cfsml_error = _cfsml_read_int_hash_map_t(fh, (*foo), _cfsml_inp, &(*line), &_cfsml_eof); -#line 794 "savegame.cfsml" +#line 793 "savegame.cfsml" *hiteof = _cfsml_error; -#line 801 "savegame.cfsml" +#line 800 "savegame.cfsml" if (_cfsml_last_value_retrieved) { free(_cfsml_last_value_retrieved); _cfsml_last_value_retrieved = NULL; @@ -4040,30 +4229,30 @@ int read_int_hash_map_tp(FILE *fh, int_hash_map_t **foo, const char *lastval, in } } // End of auto-generated CFSML data reader code -#line 477 "savegame.cfsml" +#line 554 "savegame.cfsml" (*foo)->holes = NULL; return 0; } -void write_int_hash_map_node_tp(FILE *fh, int_hash_map_t::node_t **foo) { +void write_int_hash_map_node_tp(Common::WriteStream *fh, int_hash_map_t::node_t **foo) { if (!(*foo)) { - fputs("\\null", fh); + WSprintf(fh, "\\null"); } else { - fprintf(fh,"[\n%d=>%d\n", (*foo)->name, (*foo)->value); + WSprintf(fh,"[\n%d=>%d\n", (*foo)->name, (*foo)->value); if ((*foo)->next) { -#line 819 "savegame.cfsml" +#line 818 "savegame.cfsml" // Auto-generated CFSML data writer code write_int_hash_map_node_tp(fh, &((*foo)->next)); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 488 "savegame.cfsml" +#line 565 "savegame.cfsml" } else - fputc('L', fh); - fputs("]", fh); + WSprintf(fh, "L"); + WSprintf(fh, "]"); } } -int read_int_hash_map_node_tp(FILE *fh, int_hash_map_t::node_t **foo, const char *lastval, int *line, int *hiteof) { +int read_int_hash_map_node_tp(Common::SeekableReadStream *fh, int_hash_map_t::node_t **foo, const char *lastval, int *line, int *hiteof) { static char buffer[80]; if (lastval[0] == '\\') { @@ -4077,7 +4266,7 @@ int read_int_hash_map_node_tp(FILE *fh, int_hash_map_t::node_t **foo, const char do { (*line)++; - fgets(buffer, 80, fh); + SRSgets(buffer, 80, fh); if (buffer[0] == 'L') { (*foo)->next = NULL; buffer[0] = buffer[1]; @@ -4099,38 +4288,38 @@ int read_int_hash_map_node_tp(FILE *fh, int_hash_map_t::node_t **foo, const char return 0; } -void write_menubar_tp(FILE *fh, menubar_t **foo) { +void write_menubar_tp(Common::WriteStream *fh, menubar_t **foo) { if (*foo) { -#line 819 "savegame.cfsml" +#line 818 "savegame.cfsml" // Auto-generated CFSML data writer code _cfsml_write_menubar_t(fh, (*foo)); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 533 "savegame.cfsml" +#line 610 "savegame.cfsml" } else { // Nothing to write - fputs("\\null\\", fh); + WSprintf(fh, "\\null\\"); } } -int read_menubar_tp(FILE *fh, menubar_t **foo, const char *lastval, int *line, int *hiteof) { +int read_menubar_tp(Common::SeekableReadStream *fh, menubar_t **foo, const char *lastval, int *line, int *hiteof) { if (lastval[0] == '\\') { *foo = NULL; // No menu bar } else { *foo = (menubar_t *) sci_malloc(sizeof(menubar_t)); // Auto-generated CFSML data reader code -#line 767 "savegame.cfsml" +#line 766 "savegame.cfsml" { -#line 778 "savegame.cfsml" +#line 777 "savegame.cfsml" int _cfsml_eof = 0, _cfsml_error; int dummy; -#line 783 "savegame.cfsml" +#line 782 "savegame.cfsml" const char *_cfsml_inp = lastval; -#line 790 "savegame.cfsml" +#line 789 "savegame.cfsml" _cfsml_error = _cfsml_read_menubar_t(fh, (*foo), _cfsml_inp, &(*line), &_cfsml_eof); -#line 794 "savegame.cfsml" +#line 793 "savegame.cfsml" *hiteof = _cfsml_error; -#line 801 "savegame.cfsml" +#line 800 "savegame.cfsml" if (_cfsml_last_value_retrieved) { free(_cfsml_last_value_retrieved); _cfsml_last_value_retrieved = NULL; @@ -4141,90 +4330,90 @@ int read_menubar_tp(FILE *fh, menubar_t **foo, const char *lastval, int *line, i } } // End of auto-generated CFSML data reader code -#line 545 "savegame.cfsml" +#line 622 "savegame.cfsml" } return *hiteof; } -void write_mem_obj_t(FILE *fh, mem_obj_t *foo) { - fprintf(fh, "%s\n", mem_obj_string_names[foo->type].name); -#line 819 "savegame.cfsml" +void write_mem_obj_t(Common::WriteStream *fh, mem_obj_t *foo) { + WSprintf(fh, "%s\n", mem_obj_string_names[foo->type].name); +#line 818 "savegame.cfsml" // Auto-generated CFSML data writer code _cfsml_write_int(fh, &foo->segmgr_id); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 552 "savegame.cfsml" +#line 629 "savegame.cfsml" switch (foo->type) { case MEM_OBJ_SCRIPT: -#line 819 "savegame.cfsml" +#line 818 "savegame.cfsml" // Auto-generated CFSML data writer code _cfsml_write_script_t(fh, &foo->data.script); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 555 "savegame.cfsml" +#line 632 "savegame.cfsml" break; case MEM_OBJ_CLONES: -#line 819 "savegame.cfsml" +#line 818 "savegame.cfsml" // Auto-generated CFSML data writer code _cfsml_write_clone_table_t(fh, &foo->data.clones); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 558 "savegame.cfsml" +#line 635 "savegame.cfsml" break; case MEM_OBJ_LOCALS: -#line 819 "savegame.cfsml" +#line 818 "savegame.cfsml" // Auto-generated CFSML data writer code _cfsml_write_local_variables_t(fh, &foo->data.locals); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 561 "savegame.cfsml" +#line 638 "savegame.cfsml" break; case MEM_OBJ_SYS_STRINGS: -#line 819 "savegame.cfsml" +#line 818 "savegame.cfsml" // Auto-generated CFSML data writer code _cfsml_write_sys_strings_t(fh, &foo->data.sys_strings); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 564 "savegame.cfsml" +#line 641 "savegame.cfsml" break; case MEM_OBJ_STACK: -#line 819 "savegame.cfsml" +#line 818 "savegame.cfsml" // Auto-generated CFSML data writer code _cfsml_write_int(fh, &foo->data.stack.nr); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 567 "savegame.cfsml" +#line 644 "savegame.cfsml" break; case MEM_OBJ_HUNK: break; case MEM_OBJ_LISTS: -#line 819 "savegame.cfsml" +#line 818 "savegame.cfsml" // Auto-generated CFSML data writer code _cfsml_write_list_table_t(fh, &foo->data.lists); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 572 "savegame.cfsml" +#line 649 "savegame.cfsml" break; case MEM_OBJ_NODES: -#line 819 "savegame.cfsml" +#line 818 "savegame.cfsml" // Auto-generated CFSML data writer code _cfsml_write_node_table_t(fh, &foo->data.nodes); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 575 "savegame.cfsml" +#line 652 "savegame.cfsml" break; case MEM_OBJ_DYNMEM: -#line 819 "savegame.cfsml" +#line 818 "savegame.cfsml" // Auto-generated CFSML data writer code _cfsml_write_dynmem_t(fh, &foo->data.dynmem); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 578 "savegame.cfsml" +#line 655 "savegame.cfsml" break; } } -int read_mem_obj_t(FILE *fh, mem_obj_t *foo, const char *lastval, int *line, int *hiteof) { +int read_mem_obj_t(Common::SeekableReadStream *fh, mem_obj_t *foo, const char *lastval, int *line, int *hiteof) { char buffer[80]; foo->type = mem_obj_string_to_enum(lastval); if (foo->type < 0) { @@ -4233,19 +4422,19 @@ int read_mem_obj_t(FILE *fh, mem_obj_t *foo, const char *lastval, int *line, int } // Auto-generated CFSML data reader code -#line 767 "savegame.cfsml" +#line 766 "savegame.cfsml" { -#line 778 "savegame.cfsml" +#line 777 "savegame.cfsml" int _cfsml_eof = 0, _cfsml_error; int dummy; -#line 786 "savegame.cfsml" +#line 785 "savegame.cfsml" const char *_cfsml_inp = _cfsml_get_identifier(fh, &(*line), &_cfsml_eof, &dummy); -#line 790 "savegame.cfsml" +#line 789 "savegame.cfsml" _cfsml_error = _cfsml_read_int(fh, &foo->segmgr_id, _cfsml_inp, &(*line), &_cfsml_eof); -#line 794 "savegame.cfsml" +#line 793 "savegame.cfsml" *hiteof = _cfsml_error; -#line 801 "savegame.cfsml" +#line 800 "savegame.cfsml" if (_cfsml_last_value_retrieved) { free(_cfsml_last_value_retrieved); _cfsml_last_value_retrieved = NULL; @@ -4256,23 +4445,23 @@ int read_mem_obj_t(FILE *fh, mem_obj_t *foo, const char *lastval, int *line, int } } // End of auto-generated CFSML data reader code -#line 591 "savegame.cfsml" +#line 668 "savegame.cfsml" switch (foo->type) { case MEM_OBJ_SCRIPT: // Auto-generated CFSML data reader code -#line 767 "savegame.cfsml" +#line 766 "savegame.cfsml" { -#line 778 "savegame.cfsml" +#line 777 "savegame.cfsml" int _cfsml_eof = 0, _cfsml_error; int dummy; -#line 786 "savegame.cfsml" +#line 785 "savegame.cfsml" const char *_cfsml_inp = _cfsml_get_identifier(fh, &(*line), &_cfsml_eof, &dummy); -#line 790 "savegame.cfsml" +#line 789 "savegame.cfsml" _cfsml_error = _cfsml_read_script_t(fh, &foo->data.script, _cfsml_inp, &(*line), &_cfsml_eof); -#line 794 "savegame.cfsml" +#line 793 "savegame.cfsml" *hiteof = _cfsml_error; -#line 801 "savegame.cfsml" +#line 800 "savegame.cfsml" if (_cfsml_last_value_retrieved) { free(_cfsml_last_value_retrieved); _cfsml_last_value_retrieved = NULL; @@ -4283,23 +4472,23 @@ int read_mem_obj_t(FILE *fh, mem_obj_t *foo, const char *lastval, int *line, int } } // End of auto-generated CFSML data reader code -#line 594 "savegame.cfsml" +#line 671 "savegame.cfsml" break; case MEM_OBJ_CLONES: // Auto-generated CFSML data reader code -#line 767 "savegame.cfsml" +#line 766 "savegame.cfsml" { -#line 778 "savegame.cfsml" +#line 777 "savegame.cfsml" int _cfsml_eof = 0, _cfsml_error; int dummy; -#line 786 "savegame.cfsml" +#line 785 "savegame.cfsml" const char *_cfsml_inp = _cfsml_get_identifier(fh, &(*line), &_cfsml_eof, &dummy); -#line 790 "savegame.cfsml" +#line 789 "savegame.cfsml" _cfsml_error = _cfsml_read_clone_table_t(fh, &foo->data.clones, _cfsml_inp, &(*line), &_cfsml_eof); -#line 794 "savegame.cfsml" +#line 793 "savegame.cfsml" *hiteof = _cfsml_error; -#line 801 "savegame.cfsml" +#line 800 "savegame.cfsml" if (_cfsml_last_value_retrieved) { free(_cfsml_last_value_retrieved); _cfsml_last_value_retrieved = NULL; @@ -4310,23 +4499,23 @@ int read_mem_obj_t(FILE *fh, mem_obj_t *foo, const char *lastval, int *line, int } } // End of auto-generated CFSML data reader code -#line 597 "savegame.cfsml" +#line 674 "savegame.cfsml" break; case MEM_OBJ_LOCALS: // Auto-generated CFSML data reader code -#line 767 "savegame.cfsml" +#line 766 "savegame.cfsml" { -#line 778 "savegame.cfsml" +#line 777 "savegame.cfsml" int _cfsml_eof = 0, _cfsml_error; int dummy; -#line 786 "savegame.cfsml" +#line 785 "savegame.cfsml" const char *_cfsml_inp = _cfsml_get_identifier(fh, &(*line), &_cfsml_eof, &dummy); -#line 790 "savegame.cfsml" +#line 789 "savegame.cfsml" _cfsml_error = _cfsml_read_local_variables_t(fh, &foo->data.locals, _cfsml_inp, &(*line), &_cfsml_eof); -#line 794 "savegame.cfsml" +#line 793 "savegame.cfsml" *hiteof = _cfsml_error; -#line 801 "savegame.cfsml" +#line 800 "savegame.cfsml" if (_cfsml_last_value_retrieved) { free(_cfsml_last_value_retrieved); _cfsml_last_value_retrieved = NULL; @@ -4337,23 +4526,23 @@ int read_mem_obj_t(FILE *fh, mem_obj_t *foo, const char *lastval, int *line, int } } // End of auto-generated CFSML data reader code -#line 600 "savegame.cfsml" +#line 677 "savegame.cfsml" break; case MEM_OBJ_SYS_STRINGS: // Auto-generated CFSML data reader code -#line 767 "savegame.cfsml" +#line 766 "savegame.cfsml" { -#line 778 "savegame.cfsml" +#line 777 "savegame.cfsml" int _cfsml_eof = 0, _cfsml_error; int dummy; -#line 786 "savegame.cfsml" +#line 785 "savegame.cfsml" const char *_cfsml_inp = _cfsml_get_identifier(fh, &(*line), &_cfsml_eof, &dummy); -#line 790 "savegame.cfsml" +#line 789 "savegame.cfsml" _cfsml_error = _cfsml_read_sys_strings_t(fh, &foo->data.sys_strings, _cfsml_inp, &(*line), &_cfsml_eof); -#line 794 "savegame.cfsml" +#line 793 "savegame.cfsml" *hiteof = _cfsml_error; -#line 801 "savegame.cfsml" +#line 800 "savegame.cfsml" if (_cfsml_last_value_retrieved) { free(_cfsml_last_value_retrieved); _cfsml_last_value_retrieved = NULL; @@ -4364,23 +4553,23 @@ int read_mem_obj_t(FILE *fh, mem_obj_t *foo, const char *lastval, int *line, int } } // End of auto-generated CFSML data reader code -#line 603 "savegame.cfsml" +#line 680 "savegame.cfsml" break; case MEM_OBJ_LISTS: // Auto-generated CFSML data reader code -#line 767 "savegame.cfsml" +#line 766 "savegame.cfsml" { -#line 778 "savegame.cfsml" +#line 777 "savegame.cfsml" int _cfsml_eof = 0, _cfsml_error; int dummy; -#line 786 "savegame.cfsml" +#line 785 "savegame.cfsml" const char *_cfsml_inp = _cfsml_get_identifier(fh, &(*line), &_cfsml_eof, &dummy); -#line 790 "savegame.cfsml" +#line 789 "savegame.cfsml" _cfsml_error = _cfsml_read_list_table_t(fh, &foo->data.lists, _cfsml_inp, &(*line), &_cfsml_eof); -#line 794 "savegame.cfsml" +#line 793 "savegame.cfsml" *hiteof = _cfsml_error; -#line 801 "savegame.cfsml" +#line 800 "savegame.cfsml" if (_cfsml_last_value_retrieved) { free(_cfsml_last_value_retrieved); _cfsml_last_value_retrieved = NULL; @@ -4391,23 +4580,23 @@ int read_mem_obj_t(FILE *fh, mem_obj_t *foo, const char *lastval, int *line, int } } // End of auto-generated CFSML data reader code -#line 606 "savegame.cfsml" +#line 683 "savegame.cfsml" break; case MEM_OBJ_NODES: // Auto-generated CFSML data reader code -#line 767 "savegame.cfsml" +#line 766 "savegame.cfsml" { -#line 778 "savegame.cfsml" +#line 777 "savegame.cfsml" int _cfsml_eof = 0, _cfsml_error; int dummy; -#line 786 "savegame.cfsml" +#line 785 "savegame.cfsml" const char *_cfsml_inp = _cfsml_get_identifier(fh, &(*line), &_cfsml_eof, &dummy); -#line 790 "savegame.cfsml" +#line 789 "savegame.cfsml" _cfsml_error = _cfsml_read_node_table_t(fh, &foo->data.nodes, _cfsml_inp, &(*line), &_cfsml_eof); -#line 794 "savegame.cfsml" +#line 793 "savegame.cfsml" *hiteof = _cfsml_error; -#line 801 "savegame.cfsml" +#line 800 "savegame.cfsml" if (_cfsml_last_value_retrieved) { free(_cfsml_last_value_retrieved); _cfsml_last_value_retrieved = NULL; @@ -4418,23 +4607,23 @@ int read_mem_obj_t(FILE *fh, mem_obj_t *foo, const char *lastval, int *line, int } } // End of auto-generated CFSML data reader code -#line 609 "savegame.cfsml" +#line 686 "savegame.cfsml" break; case MEM_OBJ_STACK: // Auto-generated CFSML data reader code -#line 767 "savegame.cfsml" +#line 766 "savegame.cfsml" { -#line 778 "savegame.cfsml" +#line 777 "savegame.cfsml" int _cfsml_eof = 0, _cfsml_error; int dummy; -#line 786 "savegame.cfsml" +#line 785 "savegame.cfsml" const char *_cfsml_inp = _cfsml_get_identifier(fh, &(*line), &_cfsml_eof, &dummy); -#line 790 "savegame.cfsml" +#line 789 "savegame.cfsml" _cfsml_error = _cfsml_read_int(fh, &foo->data.stack.nr, _cfsml_inp, &(*line), &_cfsml_eof); -#line 794 "savegame.cfsml" +#line 793 "savegame.cfsml" *hiteof = _cfsml_error; -#line 801 "savegame.cfsml" +#line 800 "savegame.cfsml" if (_cfsml_last_value_retrieved) { free(_cfsml_last_value_retrieved); _cfsml_last_value_retrieved = NULL; @@ -4445,7 +4634,7 @@ int read_mem_obj_t(FILE *fh, mem_obj_t *foo, const char *lastval, int *line, int } } // End of auto-generated CFSML data reader code -#line 612 "savegame.cfsml" +#line 689 "savegame.cfsml" foo->data.stack.entries = (reg_t *)sci_calloc(foo->data.stack.nr, sizeof(reg_t)); break; case MEM_OBJ_HUNK: @@ -4453,19 +4642,19 @@ int read_mem_obj_t(FILE *fh, mem_obj_t *foo, const char *lastval, int *line, int break; case MEM_OBJ_DYNMEM: // Auto-generated CFSML data reader code -#line 767 "savegame.cfsml" +#line 766 "savegame.cfsml" { -#line 778 "savegame.cfsml" +#line 777 "savegame.cfsml" int _cfsml_eof = 0, _cfsml_error; int dummy; -#line 786 "savegame.cfsml" +#line 785 "savegame.cfsml" const char *_cfsml_inp = _cfsml_get_identifier(fh, &(*line), &_cfsml_eof, &dummy); -#line 790 "savegame.cfsml" +#line 789 "savegame.cfsml" _cfsml_error = _cfsml_read_dynmem_t(fh, &foo->data.dynmem, _cfsml_inp, &(*line), &_cfsml_eof); -#line 794 "savegame.cfsml" +#line 793 "savegame.cfsml" *hiteof = _cfsml_error; -#line 801 "savegame.cfsml" +#line 800 "savegame.cfsml" if (_cfsml_last_value_retrieved) { free(_cfsml_last_value_retrieved); _cfsml_last_value_retrieved = NULL; @@ -4476,44 +4665,44 @@ int read_mem_obj_t(FILE *fh, mem_obj_t *foo, const char *lastval, int *line, int } } // End of auto-generated CFSML data reader code -#line 619 "savegame.cfsml" +#line 696 "savegame.cfsml" break; } return *hiteof; } -void write_mem_obj_tp(FILE *fh, mem_obj_t **foo) { +void write_mem_obj_tp(Common::WriteStream *fh, mem_obj_t **foo) { if (*foo) { -#line 819 "savegame.cfsml" +#line 818 "savegame.cfsml" // Auto-generated CFSML data writer code write_mem_obj_t(fh, (*foo)); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 628 "savegame.cfsml" +#line 705 "savegame.cfsml" } else { // Nothing to write - fputs("\\null\\", fh); + WSprintf(fh, "\\null\\"); } } -int read_mem_obj_tp(FILE *fh, mem_obj_t **foo, const char *lastval, int *line, int *hiteof) { +int read_mem_obj_tp(Common::SeekableReadStream *fh, mem_obj_t **foo, const char *lastval, int *line, int *hiteof) { if (lastval[0] == '\\') { *foo = NULL; // No menu bar } else { *foo = (mem_obj_t *)sci_malloc(sizeof(mem_obj_t)); // Auto-generated CFSML data reader code -#line 767 "savegame.cfsml" +#line 766 "savegame.cfsml" { -#line 778 "savegame.cfsml" +#line 777 "savegame.cfsml" int _cfsml_eof = 0, _cfsml_error; int dummy; -#line 783 "savegame.cfsml" +#line 782 "savegame.cfsml" const char *_cfsml_inp = lastval; -#line 790 "savegame.cfsml" +#line 789 "savegame.cfsml" _cfsml_error = read_mem_obj_t(fh, (*foo), _cfsml_inp, &(*line), &_cfsml_eof); -#line 794 "savegame.cfsml" +#line 793 "savegame.cfsml" *hiteof = _cfsml_error; -#line 801 "savegame.cfsml" +#line 800 "savegame.cfsml" if (_cfsml_last_value_retrieved) { free(_cfsml_last_value_retrieved); _cfsml_last_value_retrieved = NULL; @@ -4524,7 +4713,7 @@ int read_mem_obj_tp(FILE *fh, mem_obj_t **foo, const char *lastval, int *line, i } } // End of auto-generated CFSML data reader code -#line 639 "savegame.cfsml" +#line 716 "savegame.cfsml" return *hiteof; } return 0; @@ -4537,12 +4726,23 @@ void _gamestate_unfrob(state_t *s) { } -int gamestate_save(state_t *s, char *dirname) { - FILE *fh; +int gamestate_save(state_t *s, Common::WriteStream *fh, const char* savename) { sci_dir_t dir; char *filename; int fd; + tm curTime; + g_system->getTimeAndDate(curTime); + + SavegameMetadata *meta = new SavegameMetadata; + meta->savegame_version = FREESCI_CURRENT_SAVEGAME_VERSION; + meta->savegame_name = savename; + meta->version = s->version; + meta->game_version = s->game_version; + meta->savegame_date = ((curTime.tm_mday & 0xFF) << 24) | (((curTime.tm_mon + 1) & 0xFF) << 16) | ((curTime.tm_year + 1900) & 0xFFFF); + meta->savegame_time = ((curTime.tm_hour & 0xFF) << 16) | (((curTime.tm_min) & 0xFF) << 8) | ((curTime.tm_sec) & 0xFF); + fprintf(stderr, "date/time: %d %d\n", meta->savegame_date, meta->savegame_time); + _global_save_state = s; s->savegame_version = FREESCI_CURRENT_SAVEGAME_VERSION; s->dyn_views_list_serial = (s->dyn_views)? s->dyn_views->serial : -2; @@ -4554,22 +4754,6 @@ int gamestate_save(state_t *s, char *dirname) { return 1; } - scimkdir (dirname, 0700); - - if (chdir(dirname)) { - sciprintf("Could not enter directory '%s'\n", dirname); - return 1; - } - - sci_init_dir(&dir); - filename = sci_find_first(&dir, "*"); - while (filename) { - if (strcmp(filename, "..") && strcmp(filename, ".")) - unlink(filename); // Delete all files in directory - filename = sci_find_next(&dir); - } - sci_finish_find(&dir); - /* if (s->sound_server) { if ((s->sound_server->save)(s, dirname)) { @@ -4579,24 +4763,26 @@ int gamestate_save(state_t *s, char *dirname) { } } */ - fh = fopen("state", "w" FO_TEXT); - // Calculate the time spent with this game s->game_time = time(NULL) - s->game_start_time.tv_sec; -#line 819 "savegame.cfsml" +#line 818 "savegame.cfsml" +// Auto-generated CFSML data writer code + _cfsml_write_SavegameMetadata(fh, meta); + WSprintf(fh, "\n"); +// End of auto-generated CFSML data writer code +#line 769 "savegame.cfsml" +#line 818 "savegame.cfsml" // Auto-generated CFSML data writer code _cfsml_write_state_t(fh, s); - fprintf(fh, "\n"); + WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 699 "savegame.cfsml" +#line 770 "savegame.cfsml" - fclose(fh); + delete meta; _gamestate_unfrob(s); - chdir(".."); - return 0; } @@ -4842,19 +5028,13 @@ static void reconstruct_sounds(state_t *s) { } } -state_t *gamestate_restore(state_t *s, char *dirname) { - FILE *fh; +state_t *gamestate_restore(state_t *s, Common::SeekableReadStream *fh) { int fd; int i; int read_eof = 0; state_t *retval; songlib_t temp; - if (chdir(dirname)) { - sciprintf("Game state '%s' does not exist\n", dirname); - return NULL; - } - /* if (s->sound_server) { if ((s->sound_server->restore)(s, dirname)) { @@ -4872,12 +5052,53 @@ state_t *gamestate_restore(state_t *s, char *dirname) { _global_save_state = retval; retval->gfx_state = s->gfx_state; - fh = fopen("state", "r" FO_TEXT); - if (!fh) { - free(retval); + SavegameMetadata* meta = new SavegameMetadata; + memset(retval, 0, sizeof(SavegameMetadata)); + +// Auto-generated CFSML data reader code +#line 766 "savegame.cfsml" + { +#line 769 "savegame.cfsml" + int _cfsml_line_ctr = 0; +#line 774 "savegame.cfsml" + struct _cfsml_pointer_refstruct **_cfsml_myptrrefptr = _cfsml_get_current_refpointer(); +#line 777 "savegame.cfsml" + int _cfsml_eof = 0, _cfsml_error; + int dummy; +#line 785 "savegame.cfsml" + const char *_cfsml_inp = _cfsml_get_identifier(fh, &(_cfsml_line_ctr), &_cfsml_eof, &dummy); + +#line 789 "savegame.cfsml" + _cfsml_error = _cfsml_read_SavegameMetadata(fh, meta, _cfsml_inp, &(_cfsml_line_ctr), &_cfsml_eof); +#line 793 "savegame.cfsml" + read_eof = _cfsml_error; +#line 797 "savegame.cfsml" + _cfsml_free_pointer_references(_cfsml_myptrrefptr, _cfsml_error); +#line 800 "savegame.cfsml" + if (_cfsml_last_value_retrieved) { + free(_cfsml_last_value_retrieved); + _cfsml_last_value_retrieved = NULL; + } + if (_cfsml_last_identifier_retrieved) { + free(_cfsml_last_identifier_retrieved); + _cfsml_last_identifier_retrieved = NULL; + } + } +// End of auto-generated CFSML data reader code +#line 1048 "savegame.cfsml" + if ((meta->savegame_version < FREESCI_MINIMUM_SAVEGAME_VERSION) || + (meta->savegame_version > FREESCI_CURRENT_SAVEGAME_VERSION)) { + if (meta->savegame_version < FREESCI_MINIMUM_SAVEGAME_VERSION) + sciprintf("Old savegame version detected- can't load\n"); + else + sciprintf("Savegame version is %d- maximum supported is %0d\n", meta->savegame_version, FREESCI_CURRENT_SAVEGAME_VERSION); + + delete meta; return NULL; } + delete meta; + // Backwards compatibility settings retval->dyn_views = NULL; retval->drop_views = NULL; @@ -4888,25 +5109,25 @@ state_t *gamestate_restore(state_t *s, char *dirname) { retval->sound_volume = s->sound_volume; // Auto-generated CFSML data reader code -#line 767 "savegame.cfsml" +#line 766 "savegame.cfsml" { -#line 770 "savegame.cfsml" +#line 769 "savegame.cfsml" int _cfsml_line_ctr = 0; -#line 775 "savegame.cfsml" +#line 774 "savegame.cfsml" struct _cfsml_pointer_refstruct **_cfsml_myptrrefptr = _cfsml_get_current_refpointer(); -#line 778 "savegame.cfsml" +#line 777 "savegame.cfsml" int _cfsml_eof = 0, _cfsml_error; int dummy; -#line 786 "savegame.cfsml" +#line 785 "savegame.cfsml" const char *_cfsml_inp = _cfsml_get_identifier(fh, &(_cfsml_line_ctr), &_cfsml_eof, &dummy); -#line 790 "savegame.cfsml" +#line 789 "savegame.cfsml" _cfsml_error = _cfsml_read_state_t(fh, retval, _cfsml_inp, &(_cfsml_line_ctr), &_cfsml_eof); -#line 794 "savegame.cfsml" +#line 793 "savegame.cfsml" read_eof = _cfsml_error; -#line 798 "savegame.cfsml" +#line 797 "savegame.cfsml" _cfsml_free_pointer_references(_cfsml_myptrrefptr, _cfsml_error); -#line 801 "savegame.cfsml" +#line 800 "savegame.cfsml" if (_cfsml_last_value_retrieved) { free(_cfsml_last_value_retrieved); _cfsml_last_value_retrieved = NULL; @@ -4917,20 +5138,7 @@ state_t *gamestate_restore(state_t *s, char *dirname) { } } // End of auto-generated CFSML data reader code -#line 997 "savegame.cfsml" - - fclose(fh); - - if ((retval->savegame_version < FREESCI_MINIMUM_SAVEGAME_VERSION) || (retval->savegame_version > FREESCI_CURRENT_SAVEGAME_VERSION)) { - if (retval->savegame_version < FREESCI_MINIMUM_SAVEGAME_VERSION) - sciprintf("Old savegame version detected- can't load\n"); - else - sciprintf("Savegame version is %d- maximum supported is %0d\n", retval->savegame_version, FREESCI_CURRENT_SAVEGAME_VERSION); - - chdir(".."); - free(retval); - return NULL; - } +#line 1071 "savegame.cfsml" sfx_exit(&s->sound); _gamestate_unfrob(retval); @@ -5021,7 +5229,57 @@ state_t *gamestate_restore(state_t *s, char *dirname) { retval->sound.debug = s->sound.debug; reconstruct_sounds(retval); - chdir (".."); - return retval; } + +bool get_savegame_metadata(Common::SeekableReadStream* stream, SavegameMetadata* meta) { + int read_eof = 0; + +// Auto-generated CFSML data reader code +#line 766 "savegame.cfsml" + { +#line 769 "savegame.cfsml" + int _cfsml_line_ctr = 0; +#line 774 "savegame.cfsml" + struct _cfsml_pointer_refstruct **_cfsml_myptrrefptr = _cfsml_get_current_refpointer(); +#line 777 "savegame.cfsml" + int _cfsml_eof = 0, _cfsml_error; + int dummy; +#line 785 "savegame.cfsml" + const char *_cfsml_inp = _cfsml_get_identifier(stream, &(_cfsml_line_ctr), &_cfsml_eof, &dummy); + +#line 789 "savegame.cfsml" + _cfsml_error = _cfsml_read_SavegameMetadata(stream, meta, _cfsml_inp, &(_cfsml_line_ctr), &_cfsml_eof); +#line 793 "savegame.cfsml" + read_eof = _cfsml_error; +#line 797 "savegame.cfsml" + _cfsml_free_pointer_references(_cfsml_myptrrefptr, _cfsml_error); +#line 800 "savegame.cfsml" + if (_cfsml_last_value_retrieved) { + free(_cfsml_last_value_retrieved); + _cfsml_last_value_retrieved = NULL; + } + if (_cfsml_last_identifier_retrieved) { + free(_cfsml_last_identifier_retrieved); + _cfsml_last_identifier_retrieved = NULL; + } + } +// End of auto-generated CFSML data reader code +#line 1168 "savegame.cfsml" + + if (read_eof) + return false; + + if ((meta->savegame_version < FREESCI_MINIMUM_SAVEGAME_VERSION) || + (meta->savegame_version > FREESCI_CURRENT_SAVEGAME_VERSION)) { + if (meta->savegame_version < FREESCI_MINIMUM_SAVEGAME_VERSION) + sciprintf("Old savegame version detected- can't load\n"); + else + sciprintf("Savegame version is %d- maximum supported is %0d\n", meta->savegame_version, FREESCI_CURRENT_SAVEGAME_VERSION); + + return false; + } + + return true; +} + diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp index 1b2ee0c3e7..af072e2451 100644 --- a/engines/sci/engine/scriptdebug.cpp +++ b/engines/sci/engine/scriptdebug.cpp @@ -55,8 +55,10 @@ #include "sci/engine/kernel_types.h" #include "sci/include/sci_midi.h" #include "sci/include/sci_widgets.h" +#include "sci/sci.h" #include "common/util.h" +#include "common/savefile.h" #ifdef HAVE_UNISTD_H # include <unistd.h> @@ -1084,7 +1086,15 @@ int c_save_game(state_t *s) { } } - if (gamestate_save(s, cmd_params[0].str)) { + Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager(); + Common::OutSaveFile *out; + if (!(out = saveFileMan->openForSaving(cmd_params[0].str))) { + sciprintf("Error opening savegame \"%s\" for writing\n", cmd_params[0].str); + return 0; + } + + // TODO: enable custom descriptions? force filename into a specific format? + if (gamestate_save(s, out, "debugging")) { sciprintf("Saving the game state to '%s' failed\n", cmd_params[0].str); } @@ -1092,14 +1102,20 @@ int c_save_game(state_t *s) { } int c_restore_game(state_t *s) { - state_t *newstate; + state_t *newstate = NULL; if (!s) { sciprintf("Not in debug state\n"); return 1; } - newstate = gamestate_restore(s, cmd_params[0].str); + Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager(); + Common::SeekableReadStream *in; + if (!(in = saveFileMan->openForLoading(cmd_params[0].str))) { + // found a savegame file + newstate = gamestate_restore(s, in); + delete in; + } if (newstate) { s->successor = newstate; // Set successor diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp index 7cd3057a33..12fa5b19d8 100644 --- a/engines/sci/engine/vm.cpp +++ b/engines/sci/engine/vm.cpp @@ -2113,6 +2113,7 @@ int game_run(state_t **_s) { return 0; } +#if 0 int game_restore(state_t **_s, char *game_name) { state_t *s; int debug_state = _debugstate_valid; @@ -2139,6 +2140,7 @@ int game_restore(state_t **_s, char *game_name) { sciprintf(" Game::play() finished.\n"); return 0; } +#endif object_t *obj_get(state_t *s, reg_t offset) { mem_obj_t *memobj = GET_OBJECT_SEGMENT(s->seg_manager, offset.segment); diff --git a/engines/sci/include/engine.h b/engines/sci/include/engine.h index 5b6330587f..374572d510 100644 --- a/engines/sci/include/engine.h +++ b/engines/sci/include/engine.h @@ -28,6 +28,11 @@ #include "common/scummsys.h" +namespace Common { + class SeekableReadStream; + class WriteStream; +} + // FIXME. Remove after transiton to File class #include <sys/stat.h> @@ -44,8 +49,8 @@ #include "sci/include/gfx_state_internal.h" #include "sci/include/sfx_engine.h" -#define FREESCI_CURRENT_SAVEGAME_VERSION 7 -#define FREESCI_MINIMUM_SAVEGAME_VERSION 7 +#define FREESCI_CURRENT_SAVEGAME_VERSION 8 +#define FREESCI_MINIMUM_SAVEGAME_VERSION 8 #ifdef WIN32 # define FREESCI_GAMEDIR "FreeSCI" @@ -81,6 +86,16 @@ typedef struct { int palette; } drawn_pic_t; +// Savegame metadata +struct SavegameMetadata { + const char *savegame_name; + int savegame_version; + char *game_version; + sci_version_t version; + int savegame_date; + int savegame_time; +}; + typedef struct _state { int savegame_version; @@ -266,21 +281,26 @@ typedef struct _state { #define STATE_T_DEFINED int -gamestate_save(state_t *s, char *dirname); +gamestate_save(state_t *s, Common::WriteStream *save, const char *savename); /* Saves a game state to the hard disk in a portable way ** Parameters: (state_t *) s: The state to save -** (char *) dirname: The subdirectory to store it in +** (WriteStream *) save: The stream to save to +** (char *) savename: The description of the savegame ** Returns : (int) 0 on success, 1 otherwise */ state_t * -gamestate_restore(state_t *s, char *dirname); +gamestate_restore(state_t *s, Common::SeekableReadStream *save); /* Restores a game state from a directory ** Parameters: (state_t *) s: An older state from the same game ** (char *) dirname: The subdirectory to restore from ** Returns : (state_t *) NULL on failure, a pointer to a valid state_t otherwise */ +bool get_savegame_metadata(Common::SeekableReadStream* stream, SavegameMetadata* meta); +/* Read the header from a savegame +*/ + gfx_pixmap_color_t * get_pic_color(state_t *s, int color); /* Retrieves the gfx_pixmap_color_t associated with a game color index diff --git a/engines/sci/include/vm.h b/engines/sci/include/vm.h index 019dcd8a67..6df7723022 100644 --- a/engines/sci/include/vm.h +++ b/engines/sci/include/vm.h @@ -821,16 +821,4 @@ obj_get(struct _state *s, reg_t offset); ** Returns : (object_t *) The object in question, or NULL if there is none */ -int -test_savegame(struct _state *s, char *savegame_id, char *savegame_name, int savegame_name_length); -/* Simple savegame validity check -** Parameters: (state_t *) s: Pointer to the state_t to operate on -** (char *) savegame_id: Name of the savegame to check -** (char *) savegame_name: Pointer to a static buffer the savegame -** name string should be stored in -** (int) savegame_name_length: Max. number of bytes to write into the -** static string -** Returns : (int) 1 if it might be a savegame, 0 if not -*/ - #endif /* !_SCI_VM_H */ diff --git a/engines/sci/sci.cpp b/engines/sci/sci.cpp index 8d1a0b5095..23e143b13d 100644 --- a/engines/sci/sci.cpp +++ b/engines/sci/sci.cpp @@ -348,4 +348,10 @@ uint32 SciEngine::getFlags() const { return _gameDescription->desc.flags; } +Common::String SciEngine::getSavegameName(int nr) const { + char extension[6]; + snprintf(extension, sizeof(extension), ".%03d", nr); + return _targetName + extension; +} + } // End of namespace Sci diff --git a/engines/sci/sci.h b/engines/sci/sci.h index 2c1686c286..a454b7e23f 100644 --- a/engines/sci/sci.h +++ b/engines/sci/sci.h @@ -28,6 +28,7 @@ #include "engines/engine.h" #include "engines/advancedDetector.h" +#include "engines/advancedDetector.h" namespace Sci { @@ -83,6 +84,8 @@ public: Common::Platform getPlatform() const; uint32 getFlags() const; + Common::String getSavegameName(int nr) const; + private: const SciGameDescription *_gameDescription; Console *_console; |