mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-15 06:08:35 +00:00
- Removed engine/sys_strings.*
- Renamed sys_string_t -> SystemString, sys_strings_t -> SystemStrings svn-id: r38916
This commit is contained in:
parent
2d1fd81f90
commit
6c879e96d1
@ -633,7 +633,11 @@ int script_init_engine(EngineState *s, sci_version_t version) {
|
||||
|
||||
s->sys_strings = s->seg_manager->allocateSysStrings(&s->sys_strings_segment);
|
||||
// Allocate static buffer for savegame and CWD directories
|
||||
sys_string_acquire(s->sys_strings, SYS_STRING_SAVEDIR, "savedir", MAX_SAVE_DIR_SIZE);
|
||||
SystemString *str = &s->sys_strings->strings[SYS_STRING_SAVEDIR];
|
||||
str->name = strdup("savedir");
|
||||
str->max_size = MAX_SAVE_DIR_SIZE;
|
||||
str->value = (char*)sci_malloc(MAX_SAVE_DIR_SIZE + 1);
|
||||
str->value[0] = 0; // Set to empty string
|
||||
|
||||
s->save_dir_copy = make_reg(s->sys_strings_segment, SYS_STRING_SAVEDIR);
|
||||
s->save_dir_edit_offset = 0;
|
||||
@ -677,7 +681,9 @@ int script_init_engine(EngineState *s, sci_version_t version) {
|
||||
}
|
||||
|
||||
void script_set_gamestate_save_dir(EngineState *s, const char *path) {
|
||||
sys_string_set(s->sys_strings, SYS_STRING_SAVEDIR, path);
|
||||
SystemString *str = &s->sys_strings->strings[SYS_STRING_SAVEDIR];
|
||||
strncpy(str->value, path, str->max_size);
|
||||
str->value[str->max_size] = 0; // Make sure to terminate
|
||||
}
|
||||
|
||||
void script_free_vm_memory(EngineState *s) {
|
||||
@ -759,7 +765,12 @@ int game_init(EngineState *s) {
|
||||
s->status_bar_foreground = 0;
|
||||
s->status_bar_background = s->resmgr->sci_version >= SCI_VERSION_01_VGA ? 255 : 15;
|
||||
|
||||
sys_string_acquire(s->sys_strings, SYS_STRING_PARSER_BASE, "parser-base", MAX_PARSER_BASE);
|
||||
SystemString *str = &s->sys_strings->strings[SYS_STRING_PARSER_BASE];
|
||||
str->name = strdup("parser-base");
|
||||
str->max_size = MAX_PARSER_BASE;
|
||||
str->value = (char*)sci_malloc(MAX_PARSER_BASE + 1);
|
||||
str->value[0] = 0; // Set to empty string
|
||||
|
||||
s->parser_base = make_reg(s->sys_strings_segment, SYS_STRING_PARSER_BASE);
|
||||
|
||||
s->game_start_time = g_system->getMillis();
|
||||
|
@ -428,14 +428,14 @@ RECORD script_t "script_t" {
|
||||
int marked_as_deleted;
|
||||
}
|
||||
|
||||
RECORD sys_string_t "sys_string_t" {
|
||||
RECORD SystemString "SystemString" {
|
||||
string name;
|
||||
int max_size;
|
||||
string value;
|
||||
}
|
||||
|
||||
RECORD sys_strings_t "sys_strings_t" {
|
||||
sys_string_t strings[STATIC SYS_STRINGS_MAX];
|
||||
RECORD SystemStrings "SystemStrings" {
|
||||
SystemString strings[STATIC SYS_STRINGS_MAX];
|
||||
}
|
||||
|
||||
RECORD dynmem_t "dynmem_t" {
|
||||
@ -624,7 +624,7 @@ void write_mem_obj_t(Common::WriteStream *fh, mem_obj_t *foo) {
|
||||
%CFSMLWRITE local_variables_t &foo->data.locals INTO fh;
|
||||
break;
|
||||
case MEM_OBJ_SYS_STRINGS:
|
||||
%CFSMLWRITE sys_strings_t &foo->data.sys_strings INTO fh;
|
||||
%CFSMLWRITE SystemStrings &foo->data.sys_strings INTO fh;
|
||||
break;
|
||||
case MEM_OBJ_STACK:
|
||||
%CFSMLWRITE int &foo->data.stack.nr INTO fh;
|
||||
@ -664,7 +664,7 @@ int read_mem_obj_t(Common::SeekableReadStream *fh, mem_obj_t *foo, const char *l
|
||||
%CFSMLREAD local_variables_t &foo->data.locals FROM fh ERRVAR *hiteof LINECOUNTER *line;
|
||||
break;
|
||||
case MEM_OBJ_SYS_STRINGS:
|
||||
%CFSMLREAD sys_strings_t &foo->data.sys_strings FROM fh ERRVAR *hiteof LINECOUNTER *line;
|
||||
%CFSMLREAD SystemStrings &foo->data.sys_strings FROM fh ERRVAR *hiteof LINECOUNTER *line;
|
||||
break;
|
||||
case MEM_OBJ_LISTS:
|
||||
%CFSMLREAD list_table_t &foo->data.lists FROM fh ERRVAR *hiteof LINECOUNTER *line;
|
||||
@ -1104,8 +1104,25 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
|
||||
retval->save_dir_edit_offset = 0;
|
||||
retval->sys_strings_segment = find_unique_seg_by_type(retval->seg_manager, MEM_OBJ_SYS_STRINGS);
|
||||
retval->sys_strings = &(((mem_obj_t *)(GET_SEGMENT(*retval->seg_manager, retval->sys_strings_segment, MEM_OBJ_SYS_STRINGS)))->data.sys_strings);
|
||||
sys_strings_restore(retval->sys_strings, s->sys_strings);
|
||||
|
||||
// Restore system strings
|
||||
SystemString *str;
|
||||
|
||||
// First, pad memory
|
||||
for (int i = 0; i < SYS_STRINGS_MAX; i++) {
|
||||
str = &retval->sys_strings->strings[i];
|
||||
char *data = str->value;
|
||||
if (data) {
|
||||
str->value = (char *)sci_malloc(str->max_size + 1);
|
||||
strcpy(str->value, data);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
|
||||
str = &retval->sys_strings->strings[SYS_STRING_SAVEDIR];
|
||||
strncpy(str->value, s->sys_strings->strings[SYS_STRING_SAVEDIR].value, str->max_size);
|
||||
str->value[str->max_size] = 0; // Make sure to terminate
|
||||
|
||||
// Time state:
|
||||
retval->last_wait_time = g_system->getMillis();
|
||||
retval->game_start_time = g_system->getMillis() - retval->game_time * 1000;
|
||||
|
@ -512,8 +512,8 @@ static void _cfsml_write_node_table_t(Common::WriteStream *fh, node_table_t* sav
|
||||
static int _cfsml_read_node_table_t(Common::SeekableReadStream *fh, node_table_t* save_struc, const char *lastval, int *line, int *hiteof);
|
||||
|
||||
#line 382 "engines/sci/engine/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);
|
||||
static void _cfsml_write_SystemString(Common::WriteStream *fh, SystemString* save_struc);
|
||||
static int _cfsml_read_SystemString(Common::SeekableReadStream *fh, SystemString* save_struc, const char *lastval, int *line, int *hiteof);
|
||||
|
||||
#line 382 "engines/sci/engine/savegame.cfsml"
|
||||
static void _cfsml_write_byte(Common::WriteStream *fh, byte* save_struc);
|
||||
@ -523,6 +523,10 @@ static int _cfsml_read_byte(Common::SeekableReadStream *fh, byte* save_struc, co
|
||||
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 382 "engines/sci/engine/savegame.cfsml"
|
||||
static void _cfsml_write_SystemStrings(Common::WriteStream *fh, SystemStrings* save_struc);
|
||||
static int _cfsml_read_SystemStrings(Common::SeekableReadStream *fh, SystemStrings* save_struc, const char *lastval, int *line, int *hiteof);
|
||||
|
||||
#line 382 "engines/sci/engine/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);
|
||||
@ -567,10 +571,6 @@ static int _cfsml_read_clone_t(Common::SeekableReadStream *fh, clone_t* save_str
|
||||
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 382 "engines/sci/engine/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 382 "engines/sci/engine/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);
|
||||
@ -2227,34 +2227,32 @@ _cfsml_read_node_table_t(Common::SeekableReadStream *fh, node_table_t* save_stru
|
||||
|
||||
#line 394 "engines/sci/engine/savegame.cfsml"
|
||||
static void
|
||||
_cfsml_write_sys_strings_t(Common::WriteStream *fh, sys_strings_t* save_struc)
|
||||
_cfsml_write_SystemString(Common::WriteStream *fh, SystemString* save_struc)
|
||||
{
|
||||
#line 411 "engines/sci/engine/savegame.cfsml"
|
||||
WSprintf(fh, "{\n");
|
||||
WSprintf(fh, "strings = ");
|
||||
int min, max;
|
||||
min = max = SYS_STRINGS_MAX;
|
||||
#line 438 "engines/sci/engine/savegame.cfsml"
|
||||
WSprintf(fh, "[%d][\n", max);
|
||||
for (int i = 0; i < min; i++) {
|
||||
_cfsml_write_sys_string_t(fh, &(save_struc->strings[i]));
|
||||
WSprintf(fh, "\n");
|
||||
}
|
||||
WSprintf(fh, "]");
|
||||
WSprintf(fh, "name = ");
|
||||
_cfsml_write_string(fh, (char **) &(save_struc->name));
|
||||
WSprintf(fh, "\n");
|
||||
WSprintf(fh, "max_size = ");
|
||||
_cfsml_write_int(fh, (int*) &(save_struc->max_size));
|
||||
WSprintf(fh, "\n");
|
||||
WSprintf(fh, "value = ");
|
||||
_cfsml_write_string(fh, (char **) &(save_struc->value));
|
||||
WSprintf(fh, "\n");
|
||||
WSprintf(fh, "}");
|
||||
}
|
||||
|
||||
#line 485 "engines/sci/engine/savegame.cfsml"
|
||||
static int
|
||||
_cfsml_read_sys_strings_t(Common::SeekableReadStream *fh, sys_strings_t* save_struc, const char *lastval, int *line, int *hiteof)
|
||||
_cfsml_read_SystemString(Common::SeekableReadStream *fh, SystemString* save_struc, const char *lastval, int *line, int *hiteof)
|
||||
{
|
||||
#line 540 "engines/sci/engine/savegame.cfsml"
|
||||
char *token;
|
||||
int assignment, closed;
|
||||
|
||||
if (strcmp(lastval, "{")) {
|
||||
_cfsml_error("Reading record sys_strings_t; expected opening braces in line %d, got \"%s\"\n", *line, lastval);
|
||||
_cfsml_error("Reading record SystemString; expected opening braces in line %d, got \"%s\"\n", *line, lastval);
|
||||
return CFSML_FAILURE;
|
||||
};
|
||||
closed = 0;
|
||||
@ -2281,39 +2279,30 @@ _cfsml_read_sys_strings_t(Common::SeekableReadStream *fh, sys_strings_t* save_st
|
||||
_cfsml_error("Expected token at line %d\n", *line);
|
||||
return CFSML_FAILURE;
|
||||
}
|
||||
if (!strcmp(token, "strings")) {
|
||||
#line 603 "engines/sci/engine/savegame.cfsml"
|
||||
if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) {
|
||||
_cfsml_error("Opening brackets expected at line %d\n", *line);
|
||||
return CFSML_FAILURE;
|
||||
}
|
||||
int max,done,i;
|
||||
// Prepare to restore static array
|
||||
max = SYS_STRINGS_MAX;
|
||||
#line 638 "engines/sci/engine/savegame.cfsml"
|
||||
done = i = 0;
|
||||
do {
|
||||
if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
|
||||
#line 646 "engines/sci/engine/savegame.cfsml"
|
||||
_cfsml_error("Token expected at line %d\n", *line);
|
||||
return 1;
|
||||
}
|
||||
if (strcmp(value, "]")) {
|
||||
if (i == max) {
|
||||
_cfsml_error("More elements than space available (%d) in '%s' at line %d\n", max, token, *line);
|
||||
return CFSML_FAILURE;
|
||||
}
|
||||
if (_cfsml_read_sys_string_t(fh, &(save_struc->strings[i++]), value, line, hiteof)) {
|
||||
_cfsml_error("Token expected by _cfsml_read_sys_string_t() for strings[i++] at line %d\n", *line);
|
||||
if (!strcmp(token, "name")) {
|
||||
#line 689 "engines/sci/engine/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
|
||||
done = 1;
|
||||
} while (!done);
|
||||
if (!strcmp(token, "max_size")) {
|
||||
#line 689 "engines/sci/engine/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 689 "engines/sci/engine/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 698 "engines/sci/engine/savegame.cfsml"
|
||||
{
|
||||
_cfsml_error("sys_strings_t: Assignment to invalid identifier '%s' in line %d\n", token, *line);
|
||||
_cfsml_error("SystemString: Assignment to invalid identifier '%s' in line %d\n", token, *line);
|
||||
return CFSML_FAILURE;
|
||||
}
|
||||
}
|
||||
@ -2442,6 +2431,102 @@ _cfsml_read_node_t(Common::SeekableReadStream *fh, node_t* save_struc, const cha
|
||||
return CFSML_SUCCESS;
|
||||
}
|
||||
|
||||
#line 394 "engines/sci/engine/savegame.cfsml"
|
||||
static void
|
||||
_cfsml_write_SystemStrings(Common::WriteStream *fh, SystemStrings* save_struc)
|
||||
{
|
||||
#line 411 "engines/sci/engine/savegame.cfsml"
|
||||
WSprintf(fh, "{\n");
|
||||
WSprintf(fh, "strings = ");
|
||||
int min, max;
|
||||
min = max = SYS_STRINGS_MAX;
|
||||
#line 438 "engines/sci/engine/savegame.cfsml"
|
||||
WSprintf(fh, "[%d][\n", max);
|
||||
for (int i = 0; i < min; i++) {
|
||||
_cfsml_write_SystemString(fh, &(save_struc->strings[i]));
|
||||
WSprintf(fh, "\n");
|
||||
}
|
||||
WSprintf(fh, "]");
|
||||
WSprintf(fh, "\n");
|
||||
WSprintf(fh, "}");
|
||||
}
|
||||
|
||||
#line 485 "engines/sci/engine/savegame.cfsml"
|
||||
static int
|
||||
_cfsml_read_SystemStrings(Common::SeekableReadStream *fh, SystemStrings* save_struc, const char *lastval, int *line, int *hiteof)
|
||||
{
|
||||
#line 540 "engines/sci/engine/savegame.cfsml"
|
||||
char *token;
|
||||
int assignment, closed;
|
||||
|
||||
if (strcmp(lastval, "{")) {
|
||||
_cfsml_error("Reading record SystemStrings; 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, "strings")) {
|
||||
#line 603 "engines/sci/engine/savegame.cfsml"
|
||||
if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) {
|
||||
_cfsml_error("Opening brackets expected at line %d\n", *line);
|
||||
return CFSML_FAILURE;
|
||||
}
|
||||
int max,done,i;
|
||||
// Prepare to restore static array
|
||||
max = SYS_STRINGS_MAX;
|
||||
#line 638 "engines/sci/engine/savegame.cfsml"
|
||||
done = i = 0;
|
||||
do {
|
||||
if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
|
||||
#line 646 "engines/sci/engine/savegame.cfsml"
|
||||
_cfsml_error("Token expected at line %d\n", *line);
|
||||
return 1;
|
||||
}
|
||||
if (strcmp(value, "]")) {
|
||||
if (i == max) {
|
||||
_cfsml_error("More elements than space available (%d) in '%s' at line %d\n", max, token, *line);
|
||||
return CFSML_FAILURE;
|
||||
}
|
||||
if (_cfsml_read_SystemString(fh, &(save_struc->strings[i++]), value, line, hiteof)) {
|
||||
_cfsml_error("Token expected by _cfsml_read_SystemString() for strings[i++] at line %d\n", *line);
|
||||
return CFSML_FAILURE;
|
||||
}
|
||||
} else
|
||||
done = 1;
|
||||
} while (!done);
|
||||
} else
|
||||
#line 698 "engines/sci/engine/savegame.cfsml"
|
||||
{
|
||||
_cfsml_error("SystemStrings: 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 394 "engines/sci/engine/savegame.cfsml"
|
||||
static void
|
||||
_cfsml_write_list_table_t(Common::WriteStream *fh, list_table_t* save_struc)
|
||||
@ -3680,91 +3765,6 @@ _cfsml_read_list_t(Common::SeekableReadStream *fh, list_t* save_struc, const cha
|
||||
return CFSML_SUCCESS;
|
||||
}
|
||||
|
||||
#line 394 "engines/sci/engine/savegame.cfsml"
|
||||
static void
|
||||
_cfsml_write_sys_string_t(Common::WriteStream *fh, sys_string_t* save_struc)
|
||||
{
|
||||
#line 411 "engines/sci/engine/savegame.cfsml"
|
||||
WSprintf(fh, "{\n");
|
||||
WSprintf(fh, "name = ");
|
||||
_cfsml_write_string(fh, (char **) &(save_struc->name));
|
||||
WSprintf(fh, "\n");
|
||||
WSprintf(fh, "max_size = ");
|
||||
_cfsml_write_int(fh, (int*) &(save_struc->max_size));
|
||||
WSprintf(fh, "\n");
|
||||
WSprintf(fh, "value = ");
|
||||
_cfsml_write_string(fh, (char **) &(save_struc->value));
|
||||
WSprintf(fh, "\n");
|
||||
WSprintf(fh, "}");
|
||||
}
|
||||
|
||||
#line 485 "engines/sci/engine/savegame.cfsml"
|
||||
static int
|
||||
_cfsml_read_sys_string_t(Common::SeekableReadStream *fh, sys_string_t* save_struc, const char *lastval, int *line, int *hiteof)
|
||||
{
|
||||
#line 540 "engines/sci/engine/savegame.cfsml"
|
||||
char *token;
|
||||
int assignment, closed;
|
||||
|
||||
if (strcmp(lastval, "{")) {
|
||||
_cfsml_error("Reading record sys_string_t; 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, "name")) {
|
||||
#line 689 "engines/sci/engine/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 689 "engines/sci/engine/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 689 "engines/sci/engine/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 698 "engines/sci/engine/savegame.cfsml"
|
||||
{
|
||||
_cfsml_error("sys_string_t: 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 394 "engines/sci/engine/savegame.cfsml"
|
||||
static void
|
||||
_cfsml_write_script_t(Common::WriteStream *fh, script_t* save_struc)
|
||||
@ -4334,7 +4334,7 @@ void write_mem_obj_t(Common::WriteStream *fh, mem_obj_t *foo) {
|
||||
case MEM_OBJ_SYS_STRINGS:
|
||||
#line 818 "engines/sci/engine/savegame.cfsml"
|
||||
// Auto-generated CFSML data writer code
|
||||
_cfsml_write_sys_strings_t(fh, &foo->data.sys_strings);
|
||||
_cfsml_write_SystemStrings(fh, &foo->data.sys_strings);
|
||||
WSprintf(fh, "\n");
|
||||
// End of auto-generated CFSML data writer code
|
||||
#line 628 "engines/sci/engine/savegame.cfsml"
|
||||
@ -4512,7 +4512,7 @@ int read_mem_obj_t(Common::SeekableReadStream *fh, mem_obj_t *foo, const char *l
|
||||
_cfsml_error = CFSML_FAILURE;
|
||||
} else {
|
||||
#line 788 "engines/sci/engine/savegame.cfsml"
|
||||
_cfsml_error = _cfsml_read_sys_strings_t(fh, &foo->data.sys_strings, _cfsml_inp, &(*line), &_cfsml_eof);
|
||||
_cfsml_error = _cfsml_read_SystemStrings(fh, &foo->data.sys_strings, _cfsml_inp, &(*line), &_cfsml_eof);
|
||||
}
|
||||
#line 793 "engines/sci/engine/savegame.cfsml"
|
||||
*hiteof = _cfsml_error;
|
||||
@ -5232,8 +5232,25 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
|
||||
retval->save_dir_edit_offset = 0;
|
||||
retval->sys_strings_segment = find_unique_seg_by_type(retval->seg_manager, MEM_OBJ_SYS_STRINGS);
|
||||
retval->sys_strings = &(((mem_obj_t *)(GET_SEGMENT(*retval->seg_manager, retval->sys_strings_segment, MEM_OBJ_SYS_STRINGS)))->data.sys_strings);
|
||||
sys_strings_restore(retval->sys_strings, s->sys_strings);
|
||||
|
||||
// Restore system strings
|
||||
SystemString *str;
|
||||
|
||||
// First, pad memory
|
||||
for (int i = 0; i < SYS_STRINGS_MAX; i++) {
|
||||
str = &retval->sys_strings->strings[i];
|
||||
char *data = str->value;
|
||||
if (data) {
|
||||
str->value = (char *)sci_malloc(str->max_size + 1);
|
||||
strcpy(str->value, data);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
|
||||
str = &retval->sys_strings->strings[SYS_STRING_SAVEDIR];
|
||||
strncpy(str->value, s->sys_strings->strings[SYS_STRING_SAVEDIR].value, str->max_size);
|
||||
str->value[str->max_size] = 0; // Make sure to terminate
|
||||
|
||||
// Time state:
|
||||
retval->last_wait_time = g_system->getMillis();
|
||||
retval->game_start_time = g_system->getMillis() - retval->game_time * 1000;
|
||||
@ -5319,7 +5336,7 @@ bool get_savegame_metadata(Common::SeekableReadStream* stream, SavegameMetadata*
|
||||
}
|
||||
}
|
||||
// End of auto-generated CFSML data reader code
|
||||
#line 1163 "engines/sci/engine/savegame.cfsml"
|
||||
#line 1180 "engines/sci/engine/savegame.cfsml"
|
||||
|
||||
if (read_eof)
|
||||
return false;
|
||||
|
@ -414,7 +414,7 @@ static void _c_single_seg_info(EngineState *s, mem_obj_t *mobj) {
|
||||
break;
|
||||
|
||||
case MEM_OBJ_SYS_STRINGS: {
|
||||
sys_strings_t *strings = &(mobj->data.sys_strings);
|
||||
SystemStrings *strings = &(mobj->data.sys_strings);
|
||||
int i;
|
||||
|
||||
sciprintf("system string table\n");
|
||||
|
@ -232,6 +232,7 @@ int SegManager::initialiseScript(mem_obj_t *mem, EngineState *s, int script_nr)
|
||||
int SegManager::deallocate(int seg, bool recursive) {
|
||||
mem_obj_t *mobj;
|
||||
VERIFY(check(seg), "invalid seg id");
|
||||
int i;
|
||||
|
||||
mobj = heap[seg];
|
||||
id_seg_map->removeKey(mobj->segmgr_id);
|
||||
@ -255,8 +256,19 @@ int SegManager::deallocate(int seg, bool recursive) {
|
||||
free(mobj->data.dynmem.buf);
|
||||
mobj->data.dynmem.buf = NULL;
|
||||
break;
|
||||
case MEM_OBJ_SYS_STRINGS:
|
||||
sys_string_free_all(&(mobj->data.sys_strings));
|
||||
case MEM_OBJ_SYS_STRINGS:
|
||||
for (i = 0; i < SYS_STRINGS_MAX; i++) {
|
||||
SystemString *str = &mobj->data.sys_strings.strings[i];
|
||||
if (str->name) {
|
||||
free(str->name);
|
||||
str->name = NULL;
|
||||
|
||||
free(str->value);
|
||||
str->value = NULL;
|
||||
|
||||
str->max_size = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MEM_OBJ_STACK:
|
||||
free(mobj->data.stack.entries);
|
||||
@ -1193,11 +1205,11 @@ dstack_t *SegManager::allocateStack(int size, seg_id_t *segid) {
|
||||
return retval;
|
||||
}
|
||||
|
||||
sys_strings_t *SegManager::allocateSysStrings(seg_id_t *segid) {
|
||||
SystemStrings *SegManager::allocateSysStrings(seg_id_t *segid) {
|
||||
mem_obj_t *memobj = allocNonscriptSegment(MEM_OBJ_SYS_STRINGS, segid);
|
||||
sys_strings_t *retval = &(memobj->data.sys_strings);
|
||||
SystemStrings *retval = &(memobj->data.sys_strings);
|
||||
|
||||
memset(retval, 0, sizeof(sys_string_t)*SYS_STRINGS_MAX);
|
||||
memset(retval, 0, sizeof(SystemString)*SYS_STRINGS_MAX);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
@ -300,8 +300,7 @@ public:
|
||||
// Allocates a system string table
|
||||
// Returns : (dstack_t *): The physical stack
|
||||
// (seg_id_t) segid: Segment ID of the stack
|
||||
// See also sys_string_acquire();
|
||||
sys_strings_t *allocateSysStrings(seg_id_t *segid);
|
||||
SystemStrings *allocateSysStrings(seg_id_t *segid);
|
||||
|
||||
|
||||
// 6, 7. Lists and Nodes
|
||||
|
@ -1,111 +0,0 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* $URL$
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sci/tools.h"
|
||||
#include "sci/engine/sys_strings.h"
|
||||
#include "sci/sci_memory.h"
|
||||
|
||||
namespace Sci {
|
||||
|
||||
void sys_string_acquire(sys_strings_t *strings, int index, const char *name, int max_len) {
|
||||
sys_string_t *str = strings->strings + index;
|
||||
|
||||
if (index < 0 || index >= SYS_STRINGS_MAX) {
|
||||
fprintf(stderr, "[SYSSTR] Error: Attempt to acquire string #%d\n",
|
||||
index);
|
||||
BREAKPOINT();
|
||||
}
|
||||
|
||||
if (str->name
|
||||
&& (strcmp(name, str->name)
|
||||
|| (str->max_size != max_len))) {
|
||||
fprintf(stderr, "[SYSSTR] Error: Attempt to re-acquire existing string #%d;"
|
||||
"was '%s', tried to claim as '%s'\n",
|
||||
index, str->name, name);
|
||||
BREAKPOINT();
|
||||
}
|
||||
|
||||
str->name = strdup(name);
|
||||
str->max_size = max_len;
|
||||
str->value = (char*)sci_malloc(max_len + 1);
|
||||
str->value[0] = 0; // Set to empty string
|
||||
}
|
||||
|
||||
int sys_string_set(sys_strings_t *strings, int index, const char *value) {
|
||||
sys_string_t *str = strings->strings + index;
|
||||
|
||||
if (index < 0 || index >= SYS_STRINGS_MAX || !str->name) {
|
||||
fprintf(stderr, "[SYSSTR] Error: Attempt to write to invalid/unused string #%d\n",
|
||||
index);
|
||||
BREAKPOINT();
|
||||
return 1;
|
||||
}
|
||||
|
||||
strncpy(str->value, value, str->max_size);
|
||||
str->value[str->max_size] = 0; // Make sure to terminate
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sys_string_free(sys_strings_t *strings, int index) {
|
||||
sys_string_t *str = strings->strings + index;
|
||||
|
||||
free(str->name);
|
||||
str->name = NULL;
|
||||
|
||||
free(str->value);
|
||||
str->value = NULL;
|
||||
|
||||
str->max_size = 0;
|
||||
}
|
||||
|
||||
void sys_string_free_all(sys_strings_t *strings) {
|
||||
int i;
|
||||
|
||||
for (i = 0;i < SYS_STRINGS_MAX;i++) {
|
||||
if (strings->strings[i].name)
|
||||
sys_string_free(strings, i);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void sys_strings_restore(sys_strings_t *new_strings, sys_strings_t *old_strings) {
|
||||
int i;
|
||||
|
||||
// First, pad memory
|
||||
for (i = 0; i < SYS_STRINGS_MAX; i++) {
|
||||
sys_string_t *s = new_strings->strings + i;
|
||||
char *data = s->value;
|
||||
if (data) {
|
||||
s->value = (char *)sci_malloc(s->max_size + 1);
|
||||
strcpy(s->value, data);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
|
||||
sys_string_set(new_strings, SYS_STRING_SAVEDIR, old_strings->strings[SYS_STRING_SAVEDIR].value);
|
||||
}
|
||||
|
||||
} // End of namespace Sci
|
@ -1,80 +0,0 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* $URL$
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SCI_ENGINE_SYS_STRINGS_H
|
||||
#define SCI_ENGINE_SYS_STRINGS_H
|
||||
|
||||
namespace Sci {
|
||||
|
||||
enum {
|
||||
SYS_STRINGS_MAX = 4,
|
||||
|
||||
SYS_STRING_SAVEDIR = 0,
|
||||
SYS_STRING_PARSER_BASE = 1,
|
||||
|
||||
MAX_PARSER_BASE = 64
|
||||
};
|
||||
|
||||
struct sys_string_t {
|
||||
char *name;
|
||||
int max_size;
|
||||
char *value;
|
||||
};
|
||||
|
||||
struct sys_strings_t {
|
||||
sys_string_t strings[SYS_STRINGS_MAX];
|
||||
};
|
||||
|
||||
void sys_string_acquire(sys_strings_t *strings, int index, const char *name, int max_len);
|
||||
/* Reserves a new system string
|
||||
** Parameters: (sys_strings_t *) strings: The string table to reserve in
|
||||
** (int) index: Index number to reserve
|
||||
** (const char *) name: Name the entry should be tagged with
|
||||
** (int) max_len: Maximum string length in bytes
|
||||
*/
|
||||
|
||||
int sys_string_set(sys_strings_t *strings, int index, const char *value);
|
||||
/* Sets the value of a system string
|
||||
** Parameters: (sys_strings_t *) strings: The string table to use
|
||||
** (int) index: Index of the string to write to
|
||||
** (const char *) value: The value to copy
|
||||
** Returns : 0 on success, 1 on error
|
||||
** Length clipping is performed.
|
||||
*/
|
||||
|
||||
void sys_strings_restore(sys_strings_t *new_strings, sys_strings_t *old_strings);
|
||||
/* Cleanup system strings after a gamestate restore
|
||||
** Parameters: (sys_strings_t *) The freshly loaded system strings to clean up
|
||||
** (sys_strings_t *) The old system strings to clean up
|
||||
*/
|
||||
|
||||
void sys_string_free_all(sys_strings_t *strings);
|
||||
/* Deallocates all allocated system strings
|
||||
** Parameters: (sys_strings_t *) strings: The string table to deallocate
|
||||
*/
|
||||
|
||||
} // End of namespace Sci
|
||||
|
||||
#endif // SCI_ENGINE_SYS_STRINGS_H
|
@ -32,12 +32,29 @@
|
||||
#include "sci/include/vm_types.h" // for reg_t
|
||||
#include "sci/include/heapmgr.h"
|
||||
|
||||
#include "sci/engine/sys_strings.h"
|
||||
|
||||
namespace Sci {
|
||||
|
||||
struct IntMapper;
|
||||
|
||||
enum {
|
||||
SYS_STRINGS_MAX = 4,
|
||||
|
||||
SYS_STRING_SAVEDIR = 0,
|
||||
SYS_STRING_PARSER_BASE = 1,
|
||||
|
||||
MAX_PARSER_BASE = 64
|
||||
};
|
||||
|
||||
struct SystemString {
|
||||
char *name;
|
||||
int max_size;
|
||||
char *value;
|
||||
};
|
||||
|
||||
struct SystemStrings {
|
||||
SystemString strings[SYS_STRINGS_MAX];
|
||||
};
|
||||
|
||||
#define VM_STACK_SIZE 0x1000
|
||||
/* Number of bytes to be allocated for the stack */
|
||||
|
||||
@ -277,7 +294,7 @@ struct mem_obj_t {
|
||||
clone_table_t clones;
|
||||
local_variables_t locals;
|
||||
dstack_t stack;
|
||||
sys_strings_t sys_strings;
|
||||
SystemStrings sys_strings;
|
||||
list_table_t lists;
|
||||
node_table_t nodes;
|
||||
hunk_table_t hunks;
|
||||
|
@ -226,7 +226,7 @@ struct EngineState {
|
||||
|
||||
/* System strings */
|
||||
seg_id_t sys_strings_segment;
|
||||
sys_strings_t *sys_strings;
|
||||
SystemStrings *sys_strings;
|
||||
|
||||
/* Parser data: */
|
||||
word_t **parser_words;
|
||||
|
@ -31,7 +31,6 @@ MODULE_OBJS = \
|
||||
engine/scriptconsole.o \
|
||||
engine/scriptdebug.o \
|
||||
engine/seg_manager.o \
|
||||
engine/sys_strings.o \
|
||||
engine/vm.o \
|
||||
gfx/font.o \
|
||||
gfx/gfx_driver.o \
|
||||
|
Loading…
Reference in New Issue
Block a user