aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorMax Horn2009-02-15 22:28:12 +0000
committerMax Horn2009-02-15 22:28:12 +0000
commit57434d955fc6eaa77ab1ef5c408f733a59dabbcf (patch)
treeb38e715925e7c5fcc78229a9e8453055242f77b4 /engines
parent7adf7214928a11ae53035db593566beb9422f08d (diff)
downloadscummvm-rg350-57434d955fc6eaa77ab1ef5c408f733a59dabbcf.tar.gz
scummvm-rg350-57434d955fc6eaa77ab1ef5c408f733a59dabbcf.tar.bz2
scummvm-rg350-57434d955fc6eaa77ab1ef5c408f733a59dabbcf.zip
SCI: Run astyle to make the code be more compliant with our Code Formatting Guidelines: engine dir
svn-id: r38317
Diffstat (limited to 'engines')
-rw-r--r--engines/sci/engine/game.cpp175
-rw-r--r--engines/sci/engine/gc.cpp66
-rw-r--r--engines/sci/engine/grammar.cpp696
-rw-r--r--engines/sci/engine/heap.cpp193
-rw-r--r--engines/sci/engine/heap.h3
-rw-r--r--engines/sci/engine/kernel.cpp568
-rw-r--r--engines/sci/engine/kernel_compat.h18
-rw-r--r--engines/sci/engine/kernel_types.h2
-rw-r--r--engines/sci/engine/kevent.cpp167
-rw-r--r--engines/sci/engine/kfile.cpp618
-rw-r--r--engines/sci/engine/kgraphics.cpp1035
-rw-r--r--engines/sci/engine/klists.cpp204
-rw-r--r--engines/sci/engine/kmath.cpp66
-rw-r--r--engines/sci/engine/kmenu.cpp131
-rw-r--r--engines/sci/engine/kmovement.cpp203
-rw-r--r--engines/sci/engine/kpathing.cpp161
-rw-r--r--engines/sci/engine/kscripts.cpp100
-rw-r--r--engines/sci/engine/ksound.cpp612
-rw-r--r--engines/sci/engine/kstring.cpp252
-rw-r--r--engines/sci/engine/message.cpp94
-rw-r--r--engines/sci/engine/message.h14
-rw-r--r--engines/sci/engine/said.cpp1880
-rw-r--r--engines/sci/engine/savegame.cpp7229
-rw-r--r--engines/sci/engine/scriptconsole.cpp807
-rw-r--r--engines/sci/engine/scriptdebug.cpp2065
-rw-r--r--engines/sci/engine/seg_manager.cpp856
-rw-r--r--engines/sci/engine/sys_strings.cpp34
-rw-r--r--engines/sci/engine/vm.cpp699
28 files changed, 9054 insertions, 9894 deletions
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp
index ccf720f927..ef4012c0f4 100644
--- a/engines/sci/engine/game.cpp
+++ b/engines/sci/engine/game.cpp
@@ -39,18 +39,17 @@ extern int bp_flag;
static int
-_init_vocabulary(state_t *s) /* initialize vocabulary and related resources */
-{
+_init_vocabulary(state_t *s) { /* initialize vocabulary and related resources */
s->parser_lastmatch_word = SAID_NO_MATCH;
s->parser_rules = NULL;
- sciprintf("Initializing vocabulary\n");
-
- if ((s->resmgr->sci_version < SCI_VERSION_01_VGA)&&(s->parser_words = vocab_get_words(s->resmgr, &(s->parser_words_nr)))) {
+ sciprintf("Initializing vocabulary\n");
+
+ if ((s->resmgr->sci_version < SCI_VERSION_01_VGA) && (s->parser_words = vocab_get_words(s->resmgr, &(s->parser_words_nr)))) {
s->parser_suffices = vocab_get_suffices(s->resmgr, &(s->parser_suffices_nr));
if ((s->parser_branches = vocab_get_branches(s->resmgr, &(s->parser_branches_nr))))
- /* Now build a GNF grammar out of this */
- s->parser_rules = vocab_build_gnf(s->parser_branches, s->parser_branches_nr);
+ /* Now build a GNF grammar out of this */
+ s->parser_rules = vocab_build_gnf(s->parser_branches, s->parser_branches_nr);
} else {
sciprintf("Assuming that this game does not use a parser.\n");
@@ -76,8 +75,7 @@ _init_vocabulary(state_t *s) /* initialize vocabulary and related resources */
extern int _allocd_rules;
static void
-_free_vocabulary(state_t *s)
-{
+_free_vocabulary(state_t *s) {
sciprintf("Freeing vocabulary\n");
if (s->parser_words) {
@@ -99,8 +97,7 @@ _free_vocabulary(state_t *s)
static int
-_init_graphics_input(state_t *s)
-{
+_init_graphics_input(state_t *s) {
s->pic_priority_table = NULL;
s->pics = NULL;
s->pics_nr = 0;
@@ -108,8 +105,7 @@ _init_graphics_input(state_t *s)
}
static void
-_sci1_alloc_system_colors(state_t *s)
-{
+_sci1_alloc_system_colors(state_t *s) {
gfx_color_t white;
gfx_color_t black;
@@ -129,8 +125,7 @@ _sci1_alloc_system_colors(state_t *s)
}
int
-_reset_graphics_input(state_t *s)
-{
+_reset_graphics_input(state_t *s) {
resource_t *resource;
int font_nr;
gfx_color_t transparent;
@@ -141,33 +136,32 @@ _reset_graphics_input(state_t *s)
for (i = 0; i < 16; i++) {
if (gfxop_set_color(s->gfx_state, &(s->ega_colors[i]),
- gfx_sci0_image_colors[sci0_palette][i].r,
- gfx_sci0_image_colors[sci0_palette][i].g,
- gfx_sci0_image_colors[sci0_palette][i].b,
- 0, -1, -1))
+ gfx_sci0_image_colors[sci0_palette][i].r,
+ gfx_sci0_image_colors[sci0_palette][i].g,
+ gfx_sci0_image_colors[sci0_palette][i].b,
+ 0, -1, -1))
return 1;
gfxop_set_system_color(s->gfx_state, &(s->ega_colors[i]));
}
- } else
- {
+ } else {
/* Check for Amiga palette file. */
FILE *f = sci_fopen("spal", "rb");
if (f) {
- s->gfx_state->resstate->static_palette =
- gfxr_read_pal1_amiga(&s->gfx_state->resstate->static_palette_entries, f);
+ s->gfx_state->resstate->static_palette =
+ gfxr_read_pal1_amiga(&s->gfx_state->resstate->static_palette_entries, f);
fclose(f);
_sci1_alloc_system_colors(s);
} else {
resource = scir_find_resource(s->resmgr, sci_palette, 999, 1);
if (resource) {
- if (s->version < SCI_VERSION(1,001,000))
- s->gfx_state->resstate->static_palette =
- gfxr_read_pal1(999, &s->gfx_state->resstate->static_palette_entries,
- resource->data, resource->size);
- else
- s->gfx_state->resstate->static_palette =
- gfxr_read_pal11(999, &s->gfx_state->resstate->static_palette_entries,
- resource->data, resource->size);
+ if (s->version < SCI_VERSION(1, 001, 000))
+ s->gfx_state->resstate->static_palette =
+ gfxr_read_pal1(999, &s->gfx_state->resstate->static_palette_entries,
+ resource->data, resource->size);
+ else
+ s->gfx_state->resstate->static_palette =
+ gfxr_read_pal11(999, &s->gfx_state->resstate->static_palette_entries,
+ resource->data, resource->size);
_sci1_alloc_system_colors(s);
scir_unlock_resource(s->resmgr, resource, sci_palette, 999);
} else
@@ -195,7 +189,8 @@ _reset_graphics_input(state_t *s)
s->priority_first = 42; /* Priority zone 0 ends here */
if (s->version < SCI_VERSION_FTU_PRIORITY_14_ZONES)
- s->priority_last = 200; else
+ s->priority_last = 200;
+ else
s->priority_last = 190;
font_nr = -1;
@@ -214,8 +209,7 @@ _reset_graphics_input(state_t *s)
s->iconbar_port = gfxw_new_port(s->visual, NULL, gfx_rect(0, 0, 320, 200), s->ega_colors[0], transparent);
s->iconbar_port->flags |= GFXW_FLAG_NO_IMPLICIT_SWITCH;
- if (s->resmgr->sci_version >= SCI_VERSION_01_VGA)
- {
+ if (s->resmgr->sci_version >= SCI_VERSION_01_VGA) {
// This bit sets the foreground and background colors in VGA SCI games
#if 0
gfx_color_t fgcolor;
@@ -225,12 +219,12 @@ _reset_graphics_input(state_t *s)
fgcolor.mask = GFX_MASK_VISUAL;
bgcolor.visual = s->gfx_state->resstate->static_palette[255];
bgcolor.mask = GFX_MASK_VISUAL;
- s->titlebar_port = gfxw_new_port(s->visual, NULL, gfx_rect(0, 0, 320, 10),
- fgcolor, bgcolor);
+ s->titlebar_port = gfxw_new_port(s->visual, NULL, gfx_rect(0, 0, 320, 10),
+ fgcolor, bgcolor);
#endif
} else
- s->titlebar_port = gfxw_new_port(s->visual, NULL, gfx_rect(0, 0, 320, 10),
- s->ega_colors[0], s->ega_colors[15]);
+ s->titlebar_port = gfxw_new_port(s->visual, NULL, gfx_rect(0, 0, 320, 10),
+ s->ega_colors[0], s->ega_colors[15]);
s->titlebar_port->color.mask |= GFX_MASK_PRIORITY;
s->titlebar_port->color.priority = 11;
s->titlebar_port->bgcolor.mask |= GFX_MASK_PRIORITY;
@@ -259,8 +253,7 @@ _reset_graphics_input(state_t *s)
}
int
-game_init_graphics(state_t *s)
-{
+game_init_graphics(state_t *s) {
#ifndef WITH_PIC_SCALING
if (s->gfx_state->options->pic0_unscaled == 0)
sciprintf("WARNING: Pic scaling was disabled; your version of FreeSCI has no support for scaled pic drawing built in.\n");
@@ -272,8 +265,7 @@ game_init_graphics(state_t *s)
static void
-_free_graphics_input(state_t *s)
-{
+_free_graphics_input(state_t *s) {
sciprintf("Freeing graphics\n");
s->visual->widfree(GFXW(s->visual));
@@ -291,8 +283,7 @@ _free_graphics_input(state_t *s)
/*------------------------------------------------------------*/
int
-game_init_sound(state_t *s, int sound_flags)
-{
+game_init_sound(state_t *s, int sound_flags) {
if (s->resmgr->sci_version >= SCI_VERSION_01)
sound_flags |= SFX_STATE_FLAG_MULTIPLAY;
@@ -305,8 +296,7 @@ game_init_sound(state_t *s, int sound_flags)
/* Maps a class ID to the script the corresponding class is contained in */
/* Returns the script number suggested by vocab.996, or -1 if there's none */
static int
-suggested_script(resource_t *res, unsigned int classId)
-{
+suggested_script(resource_t *res, unsigned int classId) {
int offset;
if (!res || classId >= res->size >> 2)
return -1;
@@ -317,9 +307,8 @@ suggested_script(resource_t *res, unsigned int classId)
}
-int
-test_cursor_style(state_t *s)
-{
+int
+test_cursor_style(state_t *s) {
int resource_nr = 0;
int ok = 0;
@@ -331,8 +320,7 @@ test_cursor_style(state_t *s)
}
int
-create_class_table_sci11(state_t *s)
-{
+create_class_table_sci11(state_t *s) {
int scriptnr;
unsigned int seeker_offset;
char *seeker_ptr;
@@ -349,24 +337,22 @@ create_class_table_sci11(state_t *s)
for (scriptnr = 0; scriptnr < 1000; scriptnr++) {
resource_t *heap = scir_find_resource(s->resmgr, sci_heap,
- scriptnr, 0);
+ scriptnr, 0);
if (heap) {
int global_vars = getUInt16(heap->data + 2);
- seeker_ptr = (char*)heap->data + 4 + global_vars*2;
- seeker_offset = 4 + global_vars*2;
+ seeker_ptr = (char*)heap->data + 4 + global_vars * 2;
+ seeker_offset = 4 + global_vars * 2;
- while (getUInt16((byte*)seeker_ptr) == SCRIPT_OBJECT_MAGIC_NUMBER)
- {
- if (getUInt16((byte*)seeker_ptr + 14) & SCRIPT_INFO_CLASS)
- {
+ while (getUInt16((byte*)seeker_ptr) == SCRIPT_OBJECT_MAGIC_NUMBER) {
+ if (getUInt16((byte*)seeker_ptr + 14) & SCRIPT_INFO_CLASS) {
classnr = getUInt16((byte*)seeker_ptr + 10);
if (classnr >= s->classtable_size) {
if (classnr >= SCRIPT_MAX_CLASSTABLE_SIZE) {
- fprintf(stderr,"Invalid class number 0x%x in script.%d(0x%x), offset %04x\n",
- classnr, scriptnr, scriptnr, seeker_offset);
+ fprintf(stderr, "Invalid class number 0x%x in script.%d(0x%x), offset %04x\n",
+ classnr, scriptnr, scriptnr, seeker_offset);
return 1;
}
@@ -376,7 +362,7 @@ create_class_table_sci11(state_t *s)
s->classtable_size = classnr + 1; /* Adjust maximum number of entries */
}
-
+
s->classtable[classnr].reg.offset = seeker_offset;
s->classtable[classnr].reg.segment = 0;
s->classtable[classnr].script = scriptnr;
@@ -391,8 +377,7 @@ create_class_table_sci11(state_t *s)
return 0;
}
static int
-create_class_table_sci0(state_t *s)
-{
+create_class_table_sci0(state_t *s) {
int scriptnr;
unsigned int seeker;
int classnr;
@@ -410,7 +395,7 @@ create_class_table_sci0(state_t *s)
for (scriptnr = 0; scriptnr < 1000; scriptnr++) {
int objtype = 0;
resource_t *script = scir_find_resource(s->resmgr, sci_script,
- scriptnr, 0);
+ scriptnr, 0);
if (script) {
if (s->version < SCI_VERSION_FTU_NEW_SCRIPT_HEADER)
@@ -442,8 +427,8 @@ create_class_table_sci0(state_t *s)
if (classnr >= s->classtable_size) {
if (classnr >= SCRIPT_MAX_CLASSTABLE_SIZE) {
- fprintf(stderr,"Invalid class number 0x%x in script.%d(0x%x), offset %04x\n",
- classnr, scriptnr, scriptnr, seeker);
+ fprintf(stderr, "Invalid class number 0x%x in script.%d(0x%x), offset %04x\n",
+ classnr, scriptnr, scriptnr, seeker);
return 1;
}
@@ -481,15 +466,14 @@ create_class_table_sci0(state_t *s)
/* Architectural stuff: Init/Unintialize engine */
int
-script_init_engine(state_t *s, sci_version_t version)
-{
+script_init_engine(state_t *s, sci_version_t version) {
int result;
- s->max_version = SCI_VERSION(9,999,999); /* :-) */
+ s->max_version = SCI_VERSION(9, 999, 999); /* :-) */
s->min_version = 0; /* Set no real limits */
s->version = SCI_VERSION_DEFAULT_SCI0;
s->kernel_opt_flags = 0;
-
+
if (!version) {
s->version_lock_flag = 0;
} else {
@@ -499,16 +483,15 @@ script_init_engine(state_t *s, sci_version_t version)
script_detect_versions(s);
- if (s->version >= SCI_VERSION(1,001,000))
- result = create_class_table_sci11(s);
+ if (s->version >= SCI_VERSION(1, 001, 000))
+ result = create_class_table_sci11(s);
else
result = create_class_table_sci0(s);
-
- sm_init(&s->seg_manager, s->version >= SCI_VERSION(1,001,000));
+
+ sm_init(&s->seg_manager, s->version >= SCI_VERSION(1, 001, 000));
s->gc_countdown = GC_INTERVAL - 1;
- if (result)
- {
+ if (result) {
sciprintf("Failed to initialize class table\n");
return 1;
}
@@ -524,7 +507,7 @@ script_init_engine(state_t *s, sci_version_t version)
s->sys_strings = sm_allocate_sys_strings(&s->seg_manager,
- &s->sys_strings_segment);
+ &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);
@@ -561,7 +544,7 @@ script_init_engine(state_t *s, sci_version_t version)
/* Those two are used by FileIO for FIND_FIRST, FIND_NEXT */
if (s->version >= SCI_VERSION_FTU_LOFS_ABSOLUTE &&
- s->version < SCI_VERSION(1,001,000))
+ s->version < SCI_VERSION(1, 001, 000))
sm_set_export_width(&s->seg_manager, 1);
else
sm_set_export_width(&s->seg_manager, 0);
@@ -576,14 +559,12 @@ script_init_engine(state_t *s, sci_version_t version)
void
-script_set_gamestate_save_dir(state_t *s, const char* path)
-{
+script_set_gamestate_save_dir(state_t *s, const char* path) {
sys_string_set(s->sys_strings, SYS_STRING_SAVEDIR, path);
}
void
-script_free_vm_memory(state_t *s)
-{
+script_free_vm_memory(state_t *s) {
int i;
sciprintf("Freeing VM memory\n");
@@ -605,12 +586,11 @@ script_free_vm_memory(state_t *s)
}
extern void
-free_kfunct_tables(state_t *s);
+ free_kfunct_tables(state_t *s);
/* From kernel.c */
void
-script_free_engine(state_t *s)
-{
+script_free_engine(state_t *s) {
script_free_vm_memory(s);
sciprintf("Freeing state-dependant data\n");
@@ -622,16 +602,15 @@ script_free_engine(state_t *s)
}
void
-script_free_breakpoints(state_t *s)
-{
+script_free_breakpoints(state_t *s) {
breakpoint_t *bp, *bp_next;
/* Free breakpoint list */
bp = s->bp_list;
while (bp) {
bp_next = bp->next;
- if (bp->type == BREAK_SELECTOR) sci_free (bp->data.name);
- free (bp);
+ if (bp->type == BREAK_SELECTOR) sci_free(bp->data.name);
+ free(bp);
bp = bp_next;
}
@@ -644,8 +623,7 @@ script_free_breakpoints(state_t *s)
int
-game_init(state_t *s)
-{
+game_init(state_t *s) {
#ifdef __GNUC__XX
# warning "Fixme: Use new VM instantiation code all over the place"
#endif
@@ -653,7 +631,7 @@ game_init(state_t *s)
dstack_t *stack;
stack = sm_allocate_stack(&s->seg_manager, VM_STACK_SIZE,
- &s->stack_segment);
+ &s->stack_segment);
s->stack_base = stack->entries;
s->stack_top = s->stack_base + VM_STACK_SIZE;
@@ -701,8 +679,8 @@ game_init(state_t *s)
if (!s->game_name) {
sciprintf("Error: script.000, export 0 ("PREG") does not\n"
- " yield an object with a name -> sanity check failed\n",
- PRINT_REG(game_obj));
+ " yield an object with a name -> sanity check failed\n",
+ PRINT_REG(game_obj));
return 1;
}
@@ -726,18 +704,17 @@ game_init(state_t *s)
}
int
-game_exit(state_t *s)
-{
+game_exit(state_t *s) {
if (s->execution_stack) {
sci_free(s->execution_stack);
}
sfx_exit(&s->sound);
-/* Reinit because some other code depends on having a valid state */
- game_init_sound(s, SFX_STATE_FLAG_NOSOUND);
+ /* Reinit because some other code depends on having a valid state */
+ game_init_sound(s, SFX_STATE_FLAG_NOSOUND);
sm_destroy(&s->seg_manager);
-
+
if (s->synonyms_nr) {
sci_free(s->synonyms);
s->synonyms = NULL;
diff --git a/engines/sci/engine/gc.cpp b/engines/sci/engine/gc.cpp
index bdad84d7d4..484c0ec41d 100644
--- a/engines/sci/engine/gc.cpp
+++ b/engines/sci/engine/gc.cpp
@@ -32,8 +32,7 @@ typedef struct _worklist {
} worklist_t;
static worklist_t *
-fresh_worklist(worklist_t *old)
-{
+fresh_worklist(worklist_t *old) {
worklist_t *retval = (worklist_t*)sci_malloc(sizeof(worklist_t));
retval->used = 0;
retval->next = old;
@@ -41,14 +40,12 @@ fresh_worklist(worklist_t *old)
}
static worklist_t *
-new_worklist()
-{
+new_worklist() {
return fresh_worklist(NULL);
}
static void
-worklist_push(worklist_t **wlp, reg_t_hash_map_ptr hashmap, reg_t reg)
-{
+worklist_push(worklist_t **wlp, reg_t_hash_map_ptr hashmap, reg_t reg) {
worklist_t *wl = *wlp;
char added;
@@ -71,14 +68,12 @@ worklist_push(worklist_t **wlp, reg_t_hash_map_ptr hashmap, reg_t reg)
}
static int
-worklist_has_next(worklist_t *wl)
-{
+worklist_has_next(worklist_t *wl) {
return (wl && wl->used);
}
static reg_t
-worklist_pop(worklist_t **wlp)
-{
+worklist_pop(worklist_t **wlp) {
worklist_t *wl = *wlp;
reg_t retval;
@@ -98,8 +93,7 @@ worklist_pop(worklist_t **wlp)
}
static void
-free_worklist(worklist_t *wl)
-{
+free_worklist(worklist_t *wl) {
if (wl) {
if (wl->next)
free_worklist(wl->next);
@@ -114,13 +108,12 @@ typedef struct {
} normaliser_t;
void
-store_normalised(void *pre_normaliser, reg_t reg, int _)
-{
+store_normalised(void *pre_normaliser, reg_t reg, int _) {
seg_interface_t *interfce;
normaliser_t *normaliser = (normaliser_t *) pre_normaliser;
interfce = (reg.segment < normaliser->interfaces_nr)
- ? normaliser->interfaces[reg.segment]
- : NULL;
+ ? normaliser->interfaces[reg.segment]
+ : NULL;
if (interfce) {
reg = interfce->find_canonic_address(interfce, reg);
@@ -129,8 +122,7 @@ store_normalised(void *pre_normaliser, reg_t reg, int _)
}
static reg_t_hash_map_ptr
-normalise_hashmap_ptrs(reg_t_hash_map_ptr nonnormal_map, seg_interface_t **interfaces, int interfaces_nr)
-{
+normalise_hashmap_ptrs(reg_t_hash_map_ptr nonnormal_map, seg_interface_t **interfaces, int interfaces_nr) {
normaliser_t normaliser;
normaliser.normal_map = new_reg_t_hash_map();
@@ -148,15 +140,13 @@ typedef struct {
} worklist_manager_t;
void
-add_outgoing_refs(void *pre_wm, reg_t addr)
-{
+add_outgoing_refs(void *pre_wm, reg_t addr) {
worklist_manager_t *wm = (worklist_manager_t *) pre_wm;
worklist_push(wm->worklist_ref, wm->nonnormal_map, addr);
}
reg_t_hash_map_ptr
-find_all_used_references(state_t *s)
-{
+find_all_used_references(state_t *s) {
seg_manager_t *sm = &(s->seg_manager);
seg_interface_t **interfaces = (seg_interface_t**)sci_calloc(sizeof(seg_interface_t *), sm->heap_size);
reg_t_hash_map_ptr nonnormal_map = new_reg_t_hash_map();
@@ -210,7 +200,7 @@ find_all_used_references(state_t *s)
/* Init: Explicitly loaded scripts */
for (i = 1; i < sm->heap_size; i++)
if (interfaces[i]
- && interfaces[i]->type_id == MEM_OBJ_SCRIPT) {
+ && interfaces[i]->type_id == MEM_OBJ_SCRIPT) {
script_t *script = &(interfaces[i]->mobj->data.script);
if (script->lockers) { /* Explicitly loaded? */
@@ -223,8 +213,8 @@ find_all_used_references(state_t *s)
for (obj_nr = 0; obj_nr < script->objects_nr; obj_nr++) {
object_t *obj = script->objects + obj_nr;
worklist_push(&worklist,
- nonnormal_map,
- obj->pos);
+ nonnormal_map,
+ obj->pos);
}
}
}
@@ -238,15 +228,15 @@ find_all_used_references(state_t *s)
reg_t reg = worklist_pop(&worklist);
if (reg.segment != s->stack_segment) { /* No need to repeat this one */
#ifdef DEBUG_GC_VERBOSE
- sciprintf("[GC] Checking "PREG"\n", PRINT_REG(reg));
+ sciprintf("[GC] Checking "PREG"\n", PRINT_REG(reg));
#endif
if (reg.segment < sm->heap_size
- && interfaces[reg.segment])
+ && interfaces[reg.segment])
interfaces[reg.segment]->list_all_outgoing_references(interfaces[reg.segment],
- s,
- reg,
- &worklist_manager,
- add_outgoing_refs);
+ s,
+ reg,
+ &worklist_manager,
+ add_outgoing_refs);
}
}
@@ -273,8 +263,7 @@ typedef struct {
} deallocator_t;
void
-free_unless_used (void *pre_use_map, reg_t addr)
-{
+free_unless_used(void *pre_use_map, reg_t addr) {
deallocator_t *deallocator = (deallocator_t *) pre_use_map;
reg_t_hash_map_ptr use_map = deallocator->use_map;
@@ -290,8 +279,7 @@ free_unless_used (void *pre_use_map, reg_t addr)
}
void
-run_gc(state_t *s)
-{
+run_gc(state_t *s) {
int seg_nr;
deallocator_t deallocator;
seg_manager_t *sm = &(s->seg_manager);
@@ -312,8 +300,8 @@ run_gc(state_t *s)
#endif
deallocator.interfce->list_all_deallocatable(deallocator.interfce,
- &deallocator,
- free_unless_used);
+ &deallocator,
+ free_unless_used);
deallocator.interfce->deallocate_self(deallocator.interfce);
}
@@ -327,8 +315,8 @@ run_gc(state_t *s)
for (i = 0; i <= MEM_OBJ_MAX; i++)
if (deallocator.segcount[i])
sciprintf("\t%d\t* %s\n",
- deallocator.segcount[i],
- deallocator.segnames[i]);
+ deallocator.segcount[i],
+ deallocator.segnames[i]);
}
#endif
}
diff --git a/engines/sci/engine/grammar.cpp b/engines/sci/engine/grammar.cpp
index 311679ed87..3050cd800a 100644
--- a/engines/sci/engine/grammar.cpp
+++ b/engines/sci/engine/grammar.cpp
@@ -37,221 +37,213 @@
#define TOKEN_NON_NT (TOKEN_OPAREN | TOKEN_TERMINAL_CLASS | TOKEN_TERMINAL_GROUP | TOKEN_STUFFING_WORD)
#define TOKEN_TERMINAL (TOKEN_TERMINAL_CLASS | TOKEN_TERMINAL_GROUP)
- int _allocd_rules = 0;
+int _allocd_rules = 0;
static void
-vocab_print_rule(parse_rule_t *rule)
-{
- int i;
- int wspace = 0;
-
- if (!rule) {
- sciprintf("NULL rule");
- return;
- }
-
- sciprintf("[%03x] -> ", rule->id);
-
- if (!rule->length)
- sciprintf("e");
-
- for(i = 0; i < rule->length; i++) {
- uint token = rule->data[i];
-
- if (token == TOKEN_OPAREN) {
-
- if (i == rule->first_special)
- sciprintf("_");
-
- sciprintf("(");
- wspace = 0;
- } else if (token == TOKEN_CPAREN) {
-
- if (i == rule->first_special)
- sciprintf("_");
-
- sciprintf(")");
- wspace = 0;
- } else {
- if (wspace)
- sciprintf(" ");
-
- if (i == rule->first_special)
- sciprintf("_");
- if (token & TOKEN_TERMINAL_CLASS)
- sciprintf("C(%04x)", token & 0xffff);
- else if (token & TOKEN_TERMINAL_GROUP)
- sciprintf("G(%04x)", token & 0xffff);
- else if (token & TOKEN_STUFFING_WORD)
- sciprintf("%03x", token & 0xffff);
- else
- sciprintf("[%03x]", token); /* non-terminal */
- wspace = 1;
- }
-
- if (i == rule->first_special)
- sciprintf("_");
- }
- sciprintf(" [%d specials]", rule->specials_nr);
+vocab_print_rule(parse_rule_t *rule) {
+ int i;
+ int wspace = 0;
+
+ if (!rule) {
+ sciprintf("NULL rule");
+ return;
+ }
+
+ sciprintf("[%03x] -> ", rule->id);
+
+ if (!rule->length)
+ sciprintf("e");
+
+ for (i = 0; i < rule->length; i++) {
+ uint token = rule->data[i];
+
+ if (token == TOKEN_OPAREN) {
+
+ if (i == rule->first_special)
+ sciprintf("_");
+
+ sciprintf("(");
+ wspace = 0;
+ } else if (token == TOKEN_CPAREN) {
+
+ if (i == rule->first_special)
+ sciprintf("_");
+
+ sciprintf(")");
+ wspace = 0;
+ } else {
+ if (wspace)
+ sciprintf(" ");
+
+ if (i == rule->first_special)
+ sciprintf("_");
+ if (token & TOKEN_TERMINAL_CLASS)
+ sciprintf("C(%04x)", token & 0xffff);
+ else if (token & TOKEN_TERMINAL_GROUP)
+ sciprintf("G(%04x)", token & 0xffff);
+ else if (token & TOKEN_STUFFING_WORD)
+ sciprintf("%03x", token & 0xffff);
+ else
+ sciprintf("[%03x]", token); /* non-terminal */
+ wspace = 1;
+ }
+
+ if (i == rule->first_special)
+ sciprintf("_");
+ }
+ sciprintf(" [%d specials]", rule->specials_nr);
}
static void
-_vfree(parse_rule_t *rule)
-{
- free(rule);
- --_allocd_rules;
- rule = NULL;
+_vfree(parse_rule_t *rule) {
+ free(rule);
+ --_allocd_rules;
+ rule = NULL;
}
static parse_rule_t *
-_vdup(parse_rule_t *a)
-{
- parse_rule_t *rule = (parse_rule_t*)sci_malloc(sizeof(int) * (a->length + 4));
+_vdup(parse_rule_t *a) {
+ parse_rule_t *rule = (parse_rule_t*)sci_malloc(sizeof(int) * (a->length + 4));
- rule->id = a->id;
- rule->length = a->length;
- rule->specials_nr = a->specials_nr;
- rule->first_special = a->first_special;
- ++_allocd_rules;
+ rule->id = a->id;
+ rule->length = a->length;
+ rule->specials_nr = a->specials_nr;
+ rule->first_special = a->first_special;
+ ++_allocd_rules;
- memcpy(rule->data, a->data, sizeof(int) * a->length);
+ memcpy(rule->data, a->data, sizeof(int) * a->length);
- return rule;
+ return rule;
}
static parse_rule_t *
-_vinsert(parse_rule_t *turkey, parse_rule_t *stuffing)
-{
- int firstnt = turkey->first_special;
- parse_rule_t *rule;
-
- while ((firstnt < turkey->length)
- && (turkey->data[firstnt] & TOKEN_NON_NT))
- firstnt++;
-
- if ((firstnt == turkey->length)
- || (turkey->data[firstnt] != stuffing->id))
- return NULL;
-
- rule = (parse_rule_t*)sci_malloc(sizeof(int) * (turkey->length - 1 + stuffing->length + 4));
- rule->id = turkey->id;
- rule->specials_nr = turkey->specials_nr + stuffing->specials_nr - 1;
- rule->first_special = firstnt + stuffing->first_special;
- rule->length = turkey->length - 1 + stuffing->length;
- ++_allocd_rules;
-
- if (firstnt > 0)
- memcpy(rule->data, turkey->data, sizeof(int) * firstnt);
- memcpy(&(rule->data[firstnt]), stuffing->data, sizeof(int) * stuffing->length);
- if (firstnt < turkey->length - 1)
- memcpy(&(rule->data[firstnt + stuffing->length]), &(turkey->data[firstnt + 1]),
- sizeof(int) * (turkey->length - firstnt - 1));
-
- return rule;
+_vinsert(parse_rule_t *turkey, parse_rule_t *stuffing) {
+ int firstnt = turkey->first_special;
+ parse_rule_t *rule;
+
+ while ((firstnt < turkey->length)
+ && (turkey->data[firstnt] & TOKEN_NON_NT))
+ firstnt++;
+
+ if ((firstnt == turkey->length)
+ || (turkey->data[firstnt] != stuffing->id))
+ return NULL;
+
+ rule = (parse_rule_t*)sci_malloc(sizeof(int) * (turkey->length - 1 + stuffing->length + 4));
+ rule->id = turkey->id;
+ rule->specials_nr = turkey->specials_nr + stuffing->specials_nr - 1;
+ rule->first_special = firstnt + stuffing->first_special;
+ rule->length = turkey->length - 1 + stuffing->length;
+ ++_allocd_rules;
+
+ if (firstnt > 0)
+ memcpy(rule->data, turkey->data, sizeof(int) * firstnt);
+ memcpy(&(rule->data[firstnt]), stuffing->data, sizeof(int) * stuffing->length);
+ if (firstnt < turkey->length - 1)
+ memcpy(&(rule->data[firstnt + stuffing->length]), &(turkey->data[firstnt + 1]),
+ sizeof(int) * (turkey->length - firstnt - 1));
+
+ return rule;
}
static parse_rule_t *
-_vbuild_rule(parse_tree_branch_t *branch)
-{
- parse_rule_t *rule;
- int tokens = 0, tokenpos = 0, i;
-
- while (tokenpos < 10 && branch->data[tokenpos]) {
- int type = branch->data[tokenpos];
- tokenpos += 2;
-
- if ((type == VOCAB_TREE_NODE_COMPARE_TYPE)
- || (type == VOCAB_TREE_NODE_COMPARE_GROUP)
- || (type == VOCAB_TREE_NODE_FORCE_STORAGE))
- ++tokens;
- else if (type > VOCAB_TREE_NODE_LAST_WORD_STORAGE)
- tokens += 5;
- else return NULL; /* invalid */
- }
-
- rule = (parse_rule_t*)sci_malloc(sizeof(int) * (4 + tokens));
-
- ++_allocd_rules;
- rule->id = branch->id;
- rule->specials_nr = tokenpos >> 1;
- rule->length = tokens;
- rule->first_special = 0;
-
- tokens = 0;
- for (i = 0; i < tokenpos; i += 2) {
- int type = branch->data[i];
- int value = branch->data[i + 1];
-
- if (type == VOCAB_TREE_NODE_COMPARE_TYPE)
- rule->data[tokens++] = value | TOKEN_TERMINAL_CLASS;
- else if (type == VOCAB_TREE_NODE_COMPARE_GROUP)
- rule->data[tokens++] = value | TOKEN_TERMINAL_GROUP;
- else if (type == VOCAB_TREE_NODE_FORCE_STORAGE)
- rule->data[tokens++] = value | TOKEN_STUFFING_WORD;
- else { /* normal inductive rule */
- rule->data[tokens++] = TOKEN_OPAREN;
- rule->data[tokens++] = type | TOKEN_STUFFING_WORD;
- rule->data[tokens++] = value | TOKEN_STUFFING_WORD;
-
- if (i == 0)
- rule->first_special = tokens;
-
- rule->data[tokens++] = value; /* The non-terminal */
- rule->data[tokens++] = TOKEN_CPAREN;
- }
- }
-
- return rule;
+_vbuild_rule(parse_tree_branch_t *branch) {
+ parse_rule_t *rule;
+ int tokens = 0, tokenpos = 0, i;
+
+ while (tokenpos < 10 && branch->data[tokenpos]) {
+ int type = branch->data[tokenpos];
+ tokenpos += 2;
+
+ if ((type == VOCAB_TREE_NODE_COMPARE_TYPE)
+ || (type == VOCAB_TREE_NODE_COMPARE_GROUP)
+ || (type == VOCAB_TREE_NODE_FORCE_STORAGE))
+ ++tokens;
+ else if (type > VOCAB_TREE_NODE_LAST_WORD_STORAGE)
+ tokens += 5;
+ else return NULL; /* invalid */
+ }
+
+ rule = (parse_rule_t*)sci_malloc(sizeof(int) * (4 + tokens));
+
+ ++_allocd_rules;
+ rule->id = branch->id;
+ rule->specials_nr = tokenpos >> 1;
+ rule->length = tokens;
+ rule->first_special = 0;
+
+ tokens = 0;
+ for (i = 0; i < tokenpos; i += 2) {
+ int type = branch->data[i];
+ int value = branch->data[i + 1];
+
+ if (type == VOCAB_TREE_NODE_COMPARE_TYPE)
+ rule->data[tokens++] = value | TOKEN_TERMINAL_CLASS;
+ else if (type == VOCAB_TREE_NODE_COMPARE_GROUP)
+ rule->data[tokens++] = value | TOKEN_TERMINAL_GROUP;
+ else if (type == VOCAB_TREE_NODE_FORCE_STORAGE)
+ rule->data[tokens++] = value | TOKEN_STUFFING_WORD;
+ else { /* normal inductive rule */
+ rule->data[tokens++] = TOKEN_OPAREN;
+ rule->data[tokens++] = type | TOKEN_STUFFING_WORD;
+ rule->data[tokens++] = value | TOKEN_STUFFING_WORD;
+
+ if (i == 0)
+ rule->first_special = tokens;
+
+ rule->data[tokens++] = value; /* The non-terminal */
+ rule->data[tokens++] = TOKEN_CPAREN;
+ }
+ }
+
+ return rule;
}
static parse_rule_t *
-_vsatisfy_rule(parse_rule_t *rule, result_word_t *input)
-{
- int dep;
-
- if (!rule->specials_nr)
- return NULL;
-
- dep = rule->data[rule->first_special];
-
- if (((dep & TOKEN_TERMINAL_CLASS)
- && ((dep & 0xffff) & input->w_class))
- ||
- ((dep & TOKEN_TERMINAL_GROUP)
- && ((dep & 0xffff) & input->group))) {
- parse_rule_t *retval = (parse_rule_t*)sci_malloc(sizeof(int) * (4 + rule->length));
- ++_allocd_rules;
- retval->id = rule->id;
- retval->specials_nr = rule->specials_nr - 1;
- retval->length = rule->length;
- memcpy(retval->data, rule->data, sizeof(int) * retval->length);
- retval->data[rule->first_special] = TOKEN_STUFFING_WORD | input->group;
- retval->first_special = 0;
-
- if (retval->specials_nr) { /* find first special, if it exists */
- int tmp, i = rule->first_special;
-
- while ((i < rule->length)
- && ((tmp = retval->data[i]) & TOKEN_NON_NT)
- && !(tmp & TOKEN_TERMINAL))
- ++i;
-
- if (i < rule->length)
- retval->first_special = i;
- }
-
- return retval;
- }
- else return NULL;
+_vsatisfy_rule(parse_rule_t *rule, result_word_t *input) {
+ int dep;
+
+ if (!rule->specials_nr)
+ return NULL;
+
+ dep = rule->data[rule->first_special];
+
+ if (((dep & TOKEN_TERMINAL_CLASS)
+ && ((dep & 0xffff) & input->w_class))
+ ||
+ ((dep & TOKEN_TERMINAL_GROUP)
+ && ((dep & 0xffff) & input->group))) {
+ parse_rule_t *retval = (parse_rule_t*)sci_malloc(sizeof(int) * (4 + rule->length));
+ ++_allocd_rules;
+ retval->id = rule->id;
+ retval->specials_nr = rule->specials_nr - 1;
+ retval->length = rule->length;
+ memcpy(retval->data, rule->data, sizeof(int) * retval->length);
+ retval->data[rule->first_special] = TOKEN_STUFFING_WORD | input->group;
+ retval->first_special = 0;
+
+ if (retval->specials_nr) { /* find first special, if it exists */
+ int tmp, i = rule->first_special;
+
+ while ((i < rule->length)
+ && ((tmp = retval->data[i]) & TOKEN_NON_NT)
+ && !(tmp & TOKEN_TERMINAL))
+ ++i;
+
+ if (i < rule->length)
+ retval->first_special = i;
+ }
+
+ return retval;
+ } else return NULL;
}
/************** Rule lists **************/
void
-vocab_free_rule_list(parse_rule_list_t *list)
-{
+vocab_free_rule_list(parse_rule_list_t *list) {
if (list) {
_vfree(list->rule);
vocab_free_rule_list(list->next); /* Yep, this is slow and memory-intensive. */
@@ -260,19 +252,17 @@ vocab_free_rule_list(parse_rule_list_t *list)
}
static inline int
-_rules_equal_p(parse_rule_t *r1, parse_rule_t *r2)
-{
+_rules_equal_p(parse_rule_t *r1, parse_rule_t *r2) {
if ((r1->id != r2->id)
- || (r1->length != r2->length)
- || (r1->first_special != r2->first_special))
+ || (r1->length != r2->length)
+ || (r1->first_special != r2->first_special))
return 0;
return !(memcmp(r1->data, r2->data, sizeof(int) * r1->length));
}
static parse_rule_list_t *
-_vocab_add_rule(parse_rule_list_t *list, parse_rule_t *rule)
-{
+_vocab_add_rule(parse_rule_list_t *list, parse_rule_t *rule) {
parse_rule_list_t *new_elem;
int term;
@@ -284,7 +274,7 @@ _vocab_add_rule(parse_rule_list_t *list, parse_rule_t *rule)
new_elem->rule = rule;
new_elem->next = NULL;
- new_elem->terminal = term = ((term & TOKEN_TERMINAL)? term : 0);
+ new_elem->terminal = term = ((term & TOKEN_TERMINAL) ? term : 0);
if (!list)
return new_elem;
@@ -311,39 +301,34 @@ _vocab_add_rule(parse_rule_list_t *list, parse_rule_t *rule)
}
static void
-_vprl(parse_rule_list_t *list, int pos)
-{
+_vprl(parse_rule_list_t *list, int pos) {
if (list) {
sciprintf("R%03d: ", pos);
vocab_print_rule(list->rule);
sciprintf("\n");
- _vprl(list->next, pos+1);
+ _vprl(list->next, pos + 1);
} else {
sciprintf("%d rules total.\n", pos);
}
}
void
-vocab_print_rule_list(parse_rule_list_t *list)
-{
+vocab_print_rule_list(parse_rule_list_t *list) {
_vprl(list, 0);
}
static parse_rule_list_t *
-_vocab_split_rule_list(parse_rule_list_t *list)
-{
+_vocab_split_rule_list(parse_rule_list_t *list) {
if (!list->next
- || (list->next->terminal)) {
+ || (list->next->terminal)) {
parse_rule_list_t *tmp = list->next;
list->next = NULL;
return tmp;
- }
- else return _vocab_split_rule_list(list->next);
+ } else return _vocab_split_rule_list(list->next);
}
static void
-_vocab_free_empty_rule_list(parse_rule_list_t *list)
-{
+_vocab_free_empty_rule_list(parse_rule_list_t *list) {
if (list->next)
_vocab_free_empty_rule_list(list->next);
@@ -351,8 +336,7 @@ _vocab_free_empty_rule_list(parse_rule_list_t *list)
}
static parse_rule_list_t *
-_vocab_merge_rule_lists(parse_rule_list_t *l1, parse_rule_list_t *l2)
-{
+_vocab_merge_rule_lists(parse_rule_list_t *l1, parse_rule_list_t *l2) {
parse_rule_list_t *retval = l1, *seeker = l2;
while (seeker) {
retval = _vocab_add_rule(retval, seeker->rule);
@@ -364,15 +348,13 @@ _vocab_merge_rule_lists(parse_rule_list_t *l1, parse_rule_list_t *l2)
}
static int
-_vocab_rule_list_length(parse_rule_list_t *list)
-{
- return ((list)? _vocab_rule_list_length(list->next) + 1 : 0);
+_vocab_rule_list_length(parse_rule_list_t *list) {
+ return ((list) ? _vocab_rule_list_length(list->next) + 1 : 0);
}
static parse_rule_list_t *
-_vocab_clone_rule_list_by_id(parse_rule_list_t *list, int id)
-{
+_vocab_clone_rule_list_by_id(parse_rule_list_t *list, int id) {
parse_rule_list_t *result = NULL;
parse_rule_list_t *seeker = list;
@@ -388,8 +370,7 @@ _vocab_clone_rule_list_by_id(parse_rule_list_t *list, int id)
parse_rule_list_t *
-_vocab_build_gnf(parse_tree_branch_t *branches, int branches_nr, int verbose)
-{
+_vocab_build_gnf(parse_tree_branch_t *branches, int branches_nr, int verbose) {
int i;
int iterations = 0;
int last_termrules, termrules = 0;
@@ -453,27 +434,24 @@ _vocab_build_gnf(parse_tree_branch_t *branches, int branches_nr, int verbose)
}
parse_rule_list_t *
-vocab_build_gnf(parse_tree_branch_t *branches, int branches_nr)
-{
- return _vocab_build_gnf(branches, branches_nr, 0);
+vocab_build_gnf(parse_tree_branch_t *branches, int branches_nr) {
+ return _vocab_build_gnf(branches, branches_nr, 0);
}
void
-vocab_gnf_dump(parse_tree_branch_t *branches, int branches_nr)
-{
- parse_rule_list_t *tlist = _vocab_build_gnf(branches, branches_nr, 1);
+vocab_gnf_dump(parse_tree_branch_t *branches, int branches_nr) {
+ parse_rule_list_t *tlist = _vocab_build_gnf(branches, branches_nr, 1);
- sciprintf("%d allocd rules\n", _allocd_rules);
- vocab_free_rule_list(tlist);
+ sciprintf("%d allocd rules\n", _allocd_rules);
+ vocab_free_rule_list(tlist);
}
int
vocab_build_parse_tree(parse_tree_node_t *nodes, result_word_t *words, int words_nr,
- parse_tree_branch_t *branch0, parse_rule_list_t *rules)
-{
- return vocab_gnf_parse(nodes, words, words_nr, branch0, rules, 0);
+ parse_tree_branch_t *branch0, parse_rule_list_t *rules) {
+ return vocab_gnf_parse(nodes, words, words_nr, branch0, rules, 0);
}
@@ -481,11 +459,11 @@ static int
_vbpt_pareno(parse_tree_node_t *nodes, int *pos, int base)
/* Opens parentheses */
{
- nodes[base].content.branches[0] = (*pos)+1;
- nodes[++(*pos)].type = PARSE_TREE_NODE_BRANCH;
- nodes[*pos].content.branches[0] = 0;
- nodes[*pos].content.branches[1] = 0;
- return *pos;
+ nodes[base].content.branches[0] = (*pos) + 1;
+ nodes[++(*pos)].type = PARSE_TREE_NODE_BRANCH;
+ nodes[*pos].content.branches[0] = 0;
+ nodes[*pos].content.branches[1] = 0;
+ return *pos;
}
@@ -493,11 +471,11 @@ static int
_vbpt_parenc(parse_tree_node_t *nodes, int *pos, int paren)
/* Closes parentheses for appending */
{
- nodes[paren].content.branches[1] = ++(*pos);
- nodes[*pos].type = PARSE_TREE_NODE_BRANCH;
- nodes[*pos].content.branches[0] = 0;
- nodes[*pos].content.branches[1] = 0;
- return *pos;
+ nodes[paren].content.branches[1] = ++(*pos);
+ nodes[*pos].type = PARSE_TREE_NODE_BRANCH;
+ nodes[*pos].content.branches[0] = 0;
+ nodes[*pos].content.branches[1] = 0;
+ return *pos;
}
@@ -505,154 +483,152 @@ static int
_vbpt_append(parse_tree_node_t *nodes, int *pos, int base, int value)
/* writes one value to an existing base node and creates a successor node for writing */
{
- nodes[base].content.branches[0] = ++(*pos);
- nodes[*pos].type = PARSE_TREE_NODE_LEAF;
- nodes[*pos].content.value = value;
- nodes[base].content.branches[1] = ++(*pos);
- nodes[*pos].type = PARSE_TREE_NODE_BRANCH;
- nodes[*pos].content.branches[0] = 0;
- nodes[*pos].content.branches[1] = 0;
- return *pos;
+ nodes[base].content.branches[0] = ++(*pos);
+ nodes[*pos].type = PARSE_TREE_NODE_LEAF;
+ nodes[*pos].content.value = value;
+ nodes[base].content.branches[1] = ++(*pos);
+ nodes[*pos].type = PARSE_TREE_NODE_BRANCH;
+ nodes[*pos].content.branches[0] = 0;
+ nodes[*pos].content.branches[1] = 0;
+ return *pos;
}
static int
_vbpt_terminate(parse_tree_node_t *nodes, int *pos, int base, int value)
- /* Terminates, overwriting a nextwrite forknode */
+/* Terminates, overwriting a nextwrite forknode */
{
- nodes[base].type = PARSE_TREE_NODE_LEAF;
- nodes[base].content.value = value;
- return *pos;
+ nodes[base].type = PARSE_TREE_NODE_LEAF;
+ nodes[base].content.value = value;
+ return *pos;
}
static int
_vbpt_write_subexpression(parse_tree_node_t *nodes, int *pos,
- parse_rule_t *rule, int rulepos, int writepos)
-{
- uint token;
- while ((token = ((rulepos < rule->length)? rule->data[rulepos++] : TOKEN_CPAREN)) != TOKEN_CPAREN) {
- uint nexttoken = (rulepos < rule->length)? rule->data[rulepos] : TOKEN_CPAREN;
- if (token == TOKEN_OPAREN) {
- int wpold;
- int writepos2 = _vbpt_pareno(nodes, pos, wpold = writepos);
- rulepos = _vbpt_write_subexpression(nodes, pos, rule, rulepos, writepos2);
- nexttoken = (rulepos < rule->length)? rule->data[rulepos] : TOKEN_CPAREN;
- if (nexttoken != TOKEN_CPAREN)
- writepos = _vbpt_parenc(nodes, pos, wpold);
- } else if (token & TOKEN_STUFFING_WORD) {
- if (nexttoken == TOKEN_CPAREN)
- writepos = _vbpt_terminate(nodes, pos, writepos, token & 0xffff);
- else
- writepos = _vbpt_append(nodes, pos, writepos, token & 0xffff);
- } else {
- sciprintf("\nError in parser (grammar.c, _vbpt_write_subexpression()): Rule data broken in rule ");
- vocab_print_rule(rule);
- sciprintf(", at token position %d\n", *pos);
- return rulepos;
- }
- }
-
- return rulepos;
+ parse_rule_t *rule, int rulepos, int writepos) {
+ uint token;
+ while ((token = ((rulepos < rule->length) ? rule->data[rulepos++] : TOKEN_CPAREN)) != TOKEN_CPAREN) {
+ uint nexttoken = (rulepos < rule->length) ? rule->data[rulepos] : TOKEN_CPAREN;
+ if (token == TOKEN_OPAREN) {
+ int wpold;
+ int writepos2 = _vbpt_pareno(nodes, pos, wpold = writepos);
+ rulepos = _vbpt_write_subexpression(nodes, pos, rule, rulepos, writepos2);
+ nexttoken = (rulepos < rule->length) ? rule->data[rulepos] : TOKEN_CPAREN;
+ if (nexttoken != TOKEN_CPAREN)
+ writepos = _vbpt_parenc(nodes, pos, wpold);
+ } else if (token & TOKEN_STUFFING_WORD) {
+ if (nexttoken == TOKEN_CPAREN)
+ writepos = _vbpt_terminate(nodes, pos, writepos, token & 0xffff);
+ else
+ writepos = _vbpt_append(nodes, pos, writepos, token & 0xffff);
+ } else {
+ sciprintf("\nError in parser (grammar.c, _vbpt_write_subexpression()): Rule data broken in rule ");
+ vocab_print_rule(rule);
+ sciprintf(", at token position %d\n", *pos);
+ return rulepos;
+ }
+ }
+
+ return rulepos;
}
int
vocab_gnf_parse(parse_tree_node_t *nodes, result_word_t *words, int words_nr,
- parse_tree_branch_t *branch0, parse_rule_list_t *tlist, int verbose)
-{
- /* Get the start rules: */
- parse_rule_list_t *work = _vocab_clone_rule_list_by_id(tlist, branch0->data[1]);
- parse_rule_list_t *results = NULL;
- int word;
+ parse_tree_branch_t *branch0, parse_rule_list_t *tlist, int verbose) {
+ /* Get the start rules: */
+ parse_rule_list_t *work = _vocab_clone_rule_list_by_id(tlist, branch0->data[1]);
+ parse_rule_list_t *results = NULL;
+ int word;
- for (word = 0; word < words_nr; word++) {
- parse_rule_list_t *new_work = NULL;
- parse_rule_list_t *reduced_rules = NULL;
- parse_rule_list_t *seeker, *subseeker;
+ for (word = 0; word < words_nr; word++) {
+ parse_rule_list_t *new_work = NULL;
+ parse_rule_list_t *reduced_rules = NULL;
+ parse_rule_list_t *seeker, *subseeker;
- if (verbose)
- sciprintf("Adding word %d...\n", word);
+ if (verbose)
+ sciprintf("Adding word %d...\n", word);
- seeker = work;
- while (seeker) {
+ seeker = work;
+ while (seeker) {
- if (seeker->rule->specials_nr <= (words_nr - word))
- reduced_rules = _vocab_add_rule(reduced_rules, _vsatisfy_rule(seeker->rule, words + word));
+ if (seeker->rule->specials_nr <= (words_nr - word))
+ reduced_rules = _vocab_add_rule(reduced_rules, _vsatisfy_rule(seeker->rule, words + word));
- seeker = seeker->next;
- }
+ seeker = seeker->next;
+ }
+
+ if (reduced_rules == NULL) {
+ vocab_free_rule_list(work);
+ if (verbose)
+ sciprintf("No results.\n");
+ return 1;
+ }
+
+ vocab_free_rule_list(work);
+
+ if (word + 1 < words_nr) {
+ seeker = reduced_rules;
+
+ while (seeker) {
+ if (seeker->rule->specials_nr) {
+ int my_id = seeker->rule->data[seeker->rule->first_special];
+
+ subseeker = tlist;
+ while (subseeker) {
+ if (subseeker->rule->id == my_id)
+ new_work = _vocab_add_rule(new_work, _vinsert(seeker->rule, subseeker->rule));
+
+ subseeker = subseeker->next;
+ }
+ }
+
+ seeker = seeker->next;
+ }
+ vocab_free_rule_list(reduced_rules);
+ } else /* last word */
+ new_work = reduced_rules;
+
+ work = new_work;
+ if (verbose)
+ sciprintf("Now at %d candidates\n", _vocab_rule_list_length(work));
+ if (work == NULL) {
+ if (verbose)
+ sciprintf("No results.\n");
+ return 1;
+ }
+ }
+
+ results = work;
+
+ if (verbose) {
+ sciprintf("All results (excluding the surrounding '(141 %03x' and ')'):\n",
+ branch0->id);
+ vocab_print_rule_list(results);
+ sciprintf("\n");
+ }
- if (reduced_rules == NULL) {
- vocab_free_rule_list(work);
- if (verbose)
- sciprintf("No results.\n");
- return 1;
- }
+ /* now use the first result */
+ {
+ int temp, pos;
- vocab_free_rule_list(work);
+ nodes[0].type = PARSE_TREE_NODE_BRANCH;
+ nodes[0].content.branches[0] = 1;
+ nodes[0].content.branches[1] = 2;
- if (word +1 < words_nr) {
- seeker = reduced_rules;
+ nodes[1].type = PARSE_TREE_NODE_LEAF;
+ nodes[1].content.value = 0x141;
- while (seeker) {
- if (seeker->rule->specials_nr) {
- int my_id = seeker->rule->data[seeker->rule->first_special];
+ nodes[2].type = PARSE_TREE_NODE_BRANCH;
+ nodes[2].content.branches[0] = 0;
+ nodes[2].content.branches[1] = 0;
- subseeker = tlist;
- while (subseeker) {
- if (subseeker->rule->id == my_id)
- new_work = _vocab_add_rule(new_work, _vinsert(seeker->rule, subseeker->rule));
+ pos = 2;
- subseeker = subseeker->next;
- }
+ temp = _vbpt_append(nodes, &pos, 2, branch0->id);
+ /* _vbpt_write_subexpression(nodes, &pos, results[_vocab_rule_list_length(results)].rule, 0, temp); */
+ _vbpt_write_subexpression(nodes, &pos, results->rule, 0, temp);
}
- seeker = seeker->next;
- }
- vocab_free_rule_list(reduced_rules);
- } else /* last word */
- new_work = reduced_rules;
-
- work = new_work;
- if (verbose)
- sciprintf("Now at %d candidates\n", _vocab_rule_list_length(work));
- if (work == NULL) {
- if (verbose)
- sciprintf("No results.\n");
- return 1;
- }
- }
-
- results = work;
-
- if (verbose) {
- sciprintf("All results (excluding the surrounding '(141 %03x' and ')'):\n",
- branch0->id);
- vocab_print_rule_list(results);
- sciprintf("\n");
- }
-
- /* now use the first result */
- {
- int temp, pos;
-
- nodes[0].type = PARSE_TREE_NODE_BRANCH;
- nodes[0].content.branches[0] = 1;
- nodes[0].content.branches[1] = 2;
-
- nodes[1].type = PARSE_TREE_NODE_LEAF;
- nodes[1].content.value = 0x141;
-
- nodes[2].type = PARSE_TREE_NODE_BRANCH;
- nodes[2].content.branches[0] = 0;
- nodes[2].content.branches[1] = 0;
-
- pos = 2;
-
- temp = _vbpt_append(nodes, &pos, 2, branch0->id);
- /* _vbpt_write_subexpression(nodes, &pos, results[_vocab_rule_list_length(results)].rule, 0, temp); */
- _vbpt_write_subexpression(nodes, &pos, results->rule, 0, temp);
- }
-
- vocab_free_rule_list(results);
- return 0;
+ vocab_free_rule_list(results);
+ return 0;
}
diff --git a/engines/sci/engine/heap.cpp b/engines/sci/engine/heap.cpp
index 4b2314ace7..ac0c3c92b3 100644
--- a/engines/sci/engine/heap.cpp
+++ b/engines/sci/engine/heap.cpp
@@ -8,64 +8,56 @@
#define assert_in_range(pos) assert(pos>=1000 && pos<=0xffff)
-static void set_size(heap_t *h, int block_pos, int size)
-{
+static void set_size(heap_t *h, int block_pos, int size) {
assert_in_range(block_pos);
- assert(size<=0xffff-1000);
- putInt16(h->start+block_pos, size);
+ assert(size <= 0xffff - 1000);
+ putInt16(h->start + block_pos, size);
}
-static void set_next(heap_t* h, int block_pos, int next)
-{
+static void set_next(heap_t* h, int block_pos, int next) {
assert_in_range(block_pos);
assert_in_range(next);
- putInt16(h->start+block_pos+2, next);
+ putInt16(h->start + block_pos + 2, next);
}
-static unsigned int get_size(heap_t* h, int block_pos)
-{
+static unsigned int get_size(heap_t* h, int block_pos) {
assert_in_range(block_pos);
- return (guint16)getInt16(h->start+block_pos);
+ return (guint16)getInt16(h->start + block_pos);
}
-static unsigned int get_next(heap_t* h, int block_pos)
-{
+static unsigned int get_next(heap_t* h, int block_pos) {
assert_in_range(block_pos);
- return (guint16)getInt16(h->start+block_pos+2);
+ return (guint16)getInt16(h->start + block_pos + 2);
}
/*Allocates a new heap*/
-heap_t* heap_new()
-{
+heap_t* heap_new() {
heap_t* h;
- if((h= (heap_t*)sci_malloc(sizeof(heap_t)))==0) return 0;
+ if ((h = (heap_t*)sci_malloc(sizeof(heap_t))) == 0) return 0;
- if((h->start= sci_calloc(SCI_HEAP_SIZE, 1))==0)
- {
+ if ((h->start = sci_calloc(SCI_HEAP_SIZE, 1)) == 0) {
free(h);
return 0;
}
- h->base=h->start+1000;
- h->first_free=1000;
- h->old_ff=-1;
- set_size(h, 1000, 0xffff-1000);
+ h->base = h->start + 1000;
+ h->first_free = 1000;
+ h->old_ff = -1;
+ set_size(h, 1000, 0xffff - 1000);
set_next(h, 1000, 0xffff);
return h;
}
/*Deletes a heap*/
-void heap_del(heap_t* h)
-{
+void heap_del(heap_t* h) {
free(h->start);
free(h);
}
-int heap_meminfo(heap_t* h)
-{
+int heap_meminfo(heap_t* h) {
heap_ptr current = h->first_free;
int total = 0;
@@ -78,160 +70,134 @@ int heap_meminfo(heap_t* h)
}
-int heap_largest(heap_t* h)
-{
- int current=h->first_free;
- int best_pos=-1, best_size=0;
+int heap_largest(heap_t* h) {
+ int current = h->first_free;
+ int best_pos = -1, best_size = 0;
- while(current!=0xffff)
- {
- int size=get_size(h, current);
- int next=get_next(h, current);
+ while (current != 0xffff) {
+ int size = get_size(h, current);
+ int next = get_next(h, current);
- if(size>best_size)
- {
- best_pos=current;
- best_size=size;
+ if (size > best_size) {
+ best_pos = current;
+ best_size = size;
}
- current=next;
+ current = next;
}
return best_size;
}
-heap_ptr heap_allocate(heap_t* h, int size)
-{
- unsigned int previous=h->first_free;
- unsigned int current=previous;
+heap_ptr heap_allocate(heap_t* h, int size) {
+ unsigned int previous = h->first_free;
+ unsigned int current = previous;
if (!size) {
- fprintf(stderr,"Warning: heap_alloc'd zero bytes!\n");
+ fprintf(stderr, "Warning: heap_alloc'd zero bytes!\n");
size += 2;
}
- size+=2+(size&1);
+ size += 2 + (size & 1);
- while(current<0xffff)
- {
- int block_size=get_size(h, current);
- int next=get_next(h, current);
+ while (current < 0xffff) {
+ int block_size = get_size(h, current);
+ int next = get_next(h, current);
/*Is this block large enough?*/
- if(block_size>=size)
- {
+ if (block_size >= size) {
/*Swallow the block whole*/
- if(block_size<=size+4)
- {
- size=block_size;
+ if (block_size <= size + 4) {
+ size = block_size;
set_next(h, previous, next);
- }
- else {
+ } else {
/*Split the block*/
- int rest=current+size;
+ int rest = current + size;
set_next(h, previous, rest);
- set_size(h, rest, block_size-size);
+ set_size(h, rest, block_size - size);
set_next(h, rest, next);
- next=rest;
+ next = rest;
}
set_size(h, current, size);
- if(current==h->first_free) h->first_free=next;
+ if (current == h->first_free) h->first_free = next;
return current;
}
- previous=current;
- current=next;
+ previous = current;
+ current = next;
}
/*No large enough block was found.*/
return 0;
}
-void heap_free(heap_t* h, unsigned int m)
-{
+void heap_free(heap_t* h, unsigned int m) {
unsigned int previous, next;
assert_in_range(m);
- previous=next=h->first_free;
+ previous = next = h->first_free;
/*Find the previous and next blocks*/
- while(next < m)
- {
+ while (next < m) {
previous = next;
- assert(previous<0xffff);
- next=get_next(h, previous);
+ assert(previous < 0xffff);
+ next = get_next(h, previous);
if (next <= previous) {
- sciprintf("Heap corrupt. Aborting heap_free()...\n");
- return;
+ sciprintf("Heap corrupt. Aborting heap_free()...\n");
+ return;
}
}
if (h->first_free > m)
- h->first_free = m; /* Guarantee that first_free is correct */
-
- if(previous==next)
- {
- if(m<previous)
- {
- h->first_free=m;
- if(m+get_size(h, m)==previous)
- {
- set_size(h, m, get_size(h, m)+get_size(h, previous));
+ h->first_free = m; /* Guarantee that first_free is correct */
+
+ if (previous == next) {
+ if (m < previous) {
+ h->first_free = m;
+ if (m + get_size(h, m) == previous) {
+ set_size(h, m, get_size(h, m) + get_size(h, previous));
set_next(h, m, get_next(h, previous));
- }
- else set_next(h, m, previous);
- }
- else
- {
- if(previous+get_size(h, previous)==m)
- {
- set_size(h, previous, get_size(h, previous)+get_size(h, m));
+ } else set_next(h, m, previous);
+ } else {
+ if (previous + get_size(h, previous) == m) {
+ set_size(h, previous, get_size(h, previous) + get_size(h, m));
set_next(h, previous, 0xffff);
- }
- else
- {
+ } else {
set_next(h, previous, m);
set_next(h, m, next);
}
}
- }
- else
- {
+ } else {
set_next(h, previous, m);
set_next(h, m, next);
/*Try to merge with previous*/
- if(previous+get_size(h, previous)==m)
- {
- set_size(h, previous, get_size(h, previous)+get_size(h, m));
+ if (previous + get_size(h, previous) == m) {
+ set_size(h, previous, get_size(h, previous) + get_size(h, m));
set_next(h, previous, next);
- m=previous;
+ m = previous;
}
/*Try to merge with next*/
- if(m+get_size(h, m)==next)
- {
- set_size(h, m, get_size(h, m)+get_size(h, next));
+ if (m + get_size(h, m) == next) {
+ set_size(h, m, get_size(h, m) + get_size(h, next));
set_next(h, m, get_next(h, next));
}
}
}
-void save_ff(heap_t* h)
-{
- h->old_ff=h->first_free;
+void save_ff(heap_t* h) {
+ h->old_ff = h->first_free;
}
-void restore_ff(heap_t* h)
-{
- h->first_free=h->old_ff;
- set_size(h, h->first_free, 0xffff-h->first_free);
+void restore_ff(heap_t* h) {
+ h->first_free = h->old_ff;
+ set_size(h, h->first_free, 0xffff - h->first_free);
set_next(h, h->first_free, 0xffff);
}
-void heap_dump_free(heap_t *h)
-{
+void heap_dump_free(heap_t *h) {
int freedomseeker;
printf("\tfirst_free= %#x (oldff= %#x)\n\tFree Blocks:\n", h->first_free, h->old_ff);
@@ -243,8 +209,7 @@ void heap_dump_free(heap_t *h)
}
}
-void heap_dump_all(heap_t *h)
-{
+void heap_dump_all(heap_t *h) {
int seeker = 1000;
int free_seeker = h->first_free;
@@ -255,7 +220,7 @@ void heap_dump_all(heap_t *h)
if (is_free)
free_seeker = get_next(h, free_seeker);
- printf("%04x\t%d\t%s\n", seeker, size, is_free? "FREE": "");
+ printf("%04x\t%d\t%s\n", seeker, size, is_free ? "FREE" : "");
seeker += size;
}
}
diff --git a/engines/sci/engine/heap.h b/engines/sci/engine/heap.h
index 8c1f0dd3f4..181bd1925d 100644
--- a/engines/sci/engine/heap.h
+++ b/engines/sci/engine/heap.h
@@ -35,8 +35,7 @@
typedef guint16 heap_ptr;
-typedef struct
-{
+typedef struct {
byte* start;
byte* base;
unsigned int first_free;
diff --git a/engines/sci/engine/kernel.cpp b/engines/sci/engine/kernel.cpp
index 1c403f0a40..1c85ab448a 100644
--- a/engines/sci/engine/kernel.cpp
+++ b/engines/sci/engine/kernel.cpp
@@ -195,172 +195,171 @@ static int sci_max_allowed_unknown_kernel_functions[] = {
#define NOFUN(nm) {KF_NONE, nm, {NULL, NULL, NULL}}
sci_kernel_function_t kfunct_mappers[] = {
-/*00*/ DEFUN("Load", kLoad, "iii*"),
-/*01*/ DEFUN("UnLoad", kUnLoad, "i.*"),
-/*02*/ DEFUN("ScriptID", kScriptID, "Ioi*"),
-/*03*/ DEFUN("DisposeScript", kDisposeScript, "Oi"), /* Work around QfG1 bug */
-/*04*/ DEFUN("Clone", kClone, "o"),
-/*05*/ DEFUN("DisposeClone", kDisposeClone, "o"),
-/*06*/ DEFUN("IsObject", kIsObject, "."),
-/*07*/ DEFUN("RespondsTo", kRespondsTo, ".i"),
-/*08*/ DEFUN("DrawPic", kDrawPic, "i*"),
-/*09*/ DEFUN("Show", kShow, "i"),
-/*0a*/ DEFUN("PicNotValid", kPicNotValid, "i*"),
-/*0b*/ DEFUN("Animate", kAnimate, "LI*"), /* More like (li?)? */
-/*0c*/ DEFUN("SetNowSeen", kSetNowSeen, "oi*"), /* The second parameter is ignored */
-/*0d*/ DEFUN("NumLoops", kNumLoops, "o"),
-/*0e*/ DEFUN("NumCels", kNumCels, "o"),
-/*0f*/ DEFUN("CelWide", kCelWide, "iOiOi"),
-/*10*/ DEFUN("CelHigh", kCelHigh, "iOiOi"),
-/*11*/ DEFUN("DrawCel", kDrawCel, "iiiiii*"),
-/*12*/ DEFUN("AddToPic", kAddToPic, "Il*"),
-/*13*/ DEFUN("NewWindow", kNewWindow, "iiiiZRi*"),
-/*14*/ DEFUN("GetPort", kGetPort, ""),
-/*15*/ DEFUN("SetPort", kSetPort, "ii*"),
-/*16*/ DEFUN("DisposeWindow", kDisposeWindow, "ii*"),
-/*17*/ DEFUN("DrawControl", kDrawControl, "o"),
-/*18*/ DEFUN("HiliteControl", kHiliteControl, "o"),
-/*19*/ DEFUN("EditControl", kEditControl, "ZoZo"),
-/*1a*/ DEFUN("TextSize", kTextSize, "rZrii*r*"),
-/*1b*/ DEFUN("Display", kDisplay, ".*"),
-/*1c*/ DEFUN("GetEvent", kGetEvent, "io"),
-/*1d*/ DEFUN("GlobalToLocal", kGlobalToLocal, "o"),
-/*1e*/ DEFUN("LocalToGlobal", kLocalToGlobal, "o"),
-/*1f*/ DEFUN("MapKeyToDir", kMapKeyToDir, "o"),
-/*20*/ DEFUN("DrawMenuBar", kDrawMenuBar, "i"),
-/*21*/ DEFUN("MenuSelect", kMenuSelect, "oi*"),
-/*22*/ DEFUN("AddMenu", kAddMenu, "rr"),
-/*23*/ DEFUN("DrawStatus", kDrawStatus, "Zri*"),
-/*24*/ DEFUN("Parse", kParse, "ro"),
-/*25*/ DEFUN("Said", kSaid, "Zr"),
-/*26*/ DEFUN("SetSynonyms", kSetSynonyms, "o"),
-/*27*/ DEFUN("HaveMouse", kHaveMouse, ""),
-/*28*/ DEFUN("SetCursor", kSetCursor, "i*"),
-/*28*/ DEFUN("MoveCursor", kMoveCursor, "ii*"),
-/*29*/ DEFUN("FOpen", kFOpen, "ri"),
-/*2a*/ DEFUN("FPuts", kFPuts, "ir"),
-/*2b*/ DEFUN("FGets", kFGets, "rii"),
-/*2c*/ DEFUN("FClose", kFClose, "i"),
-/*2d*/ DEFUN("SaveGame", kSaveGame, "rirr*"),
-/*2e*/ DEFUN("RestoreGame", kRestoreGame, "rir*"),
-/*2f*/ DEFUN("RestartGame", kRestartGame, ""),
-/*30*/ DEFUN("GameIsRestarting", kGameIsRestarting, "i*"),
-/*31*/ DEFUN("DoSound", kDoSound, "iIo*"),
-/*32*/ DEFUN("NewList", kNewList, ""),
-/*33*/ DEFUN("DisposeList", kDisposeList, "l"),
-/*34*/ DEFUN("NewNode", kNewNode, ".."),
-/*35*/ DEFUN("FirstNode", kFirstNode, "Zl"),
-/*36*/ DEFUN("LastNode", kLastNode, "l"),
-/*37*/ DEFUN("EmptyList", kEmptyList, "l"),
-/*38*/ DEFUN("NextNode", kNextNode, "n!"),
-/*39*/ DEFUN("PrevNode", kPrevNode, "n"),
-/*3a*/ DEFUN("NodeValue", kNodeValue, "Zn!"),
-/*3b*/ DEFUN("AddAfter", kAddAfter, "lnn"),
-/*3c*/ DEFUN("AddToFront", kAddToFront, "ln"),
-/*3d*/ DEFUN("AddToEnd", kAddToEnd, "ln"),
-/*3e*/ DEFUN("FindKey", kFindKey, "l."),
-/*3f*/ DEFUN("DeleteKey", kDeleteKey, "l."),
-/*40*/ DEFUN("Random", kRandom, "i*"),
-/*41*/ DEFUN("Abs", kAbs, "Oi"),
-/*42*/ DEFUN("Sqrt", kSqrt, "i"),
-/*43*/ DEFUN("GetAngle", kGetAngle, "iiii"),
-/*44*/ DEFUN("GetDistance", kGetDistance, "iiiii*"),
-/*45*/ DEFUN("Wait", kWait, "i"),
-/*46*/ DEFUN("GetTime", kGetTime, "i*"),
-/*47*/ DEFUN("StrEnd", kStrEnd, "r"),
-/*48*/ DEFUN("StrCat", kStrCat, "rr"),
-/*49*/ DEFUN("StrCmp", kStrCmp, "rri*"),
-/*4a*/ DEFUN("StrLen", kStrLen, "r"),
-/*4b*/ DEFUN("StrCpy", kStrCpy, "rri*"),
-/*4c*/ DEFUN("Format", kFormat, "r.*"),
-/*4d*/ DEFUN("GetFarText", kGetFarText, "iir"),
-/*4e*/ DEFUN("ReadNumber", kReadNumber, "r"),
-/*4f*/ DEFUN("BaseSetter", kBaseSetter, "o"),
-/*50*/ DEFUN("DirLoop", kDirLoop, "oi"),
-/*51*/ DEFUN("CanBeHere", kCanBeHere, "ol*"),
-/*51*/ DEFUN("CantBeHere", kCanBeHere, "ol*"),
-/*52*/ DEFUN("OnControl", kOnControl, "i*"),
-/*53*/ DEFUN("InitBresen", kInitBresen, "oi*"),
-/*54*/ DEFUN("DoBresen", kDoBresen, "o"),
-/*55*/ DEFUN("DoAvoider", kDoAvoider, "o"),
-/*56*/ DEFUN("SetJump", kSetJump, "oiii"),
-/*57*/ DEFUN("SetDebug", kSetDebug, "i*"),
-/*58*/ NOFUN("InspectObj"),
-/*59*/ NOFUN("ShowSends"),
-/*5a*/ NOFUN("ShowObjs"),
-/*5b*/ NOFUN("ShowFree"),
-/*5c*/ DEFUN("MemoryInfo", kMemoryInfo, "i"),
-/*5d*/ NOFUN("StackUsage"),
-/*5e*/ NOFUN("Profiler"),
-/*5f*/ DEFUN("GetMenu", kGetMenu, "i."),
-/*60*/ DEFUN("SetMenu", kSetMenu, "i.*"),
-/*61*/ DEFUN("GetSaveFiles", kGetSaveFiles, "rrr"),
-/*62*/ DEFUN("GetCWD", kGetCWD, "r"),
-/*63*/ DEFUN("CheckFreeSpace", kCheckFreeSpace, "r"),
-/*64*/ DEFUN("ValidPath", kValidPath, "r"),
-/*65*/ DEFUN("CoordPri", kCoordPri, "i"),
-/*66*/ DEFUN("StrAt", kStrAt, "rii*"),
+ /*00*/ DEFUN("Load", kLoad, "iii*"),
+ /*01*/ DEFUN("UnLoad", kUnLoad, "i.*"),
+ /*02*/ DEFUN("ScriptID", kScriptID, "Ioi*"),
+ /*03*/ DEFUN("DisposeScript", kDisposeScript, "Oi"), /* Work around QfG1 bug */
+ /*04*/ DEFUN("Clone", kClone, "o"),
+ /*05*/ DEFUN("DisposeClone", kDisposeClone, "o"),
+ /*06*/ DEFUN("IsObject", kIsObject, "."),
+ /*07*/ DEFUN("RespondsTo", kRespondsTo, ".i"),
+ /*08*/ DEFUN("DrawPic", kDrawPic, "i*"),
+ /*09*/ DEFUN("Show", kShow, "i"),
+ /*0a*/ DEFUN("PicNotValid", kPicNotValid, "i*"),
+ /*0b*/ DEFUN("Animate", kAnimate, "LI*"), /* More like (li?)? */
+ /*0c*/ DEFUN("SetNowSeen", kSetNowSeen, "oi*"), /* The second parameter is ignored */
+ /*0d*/ DEFUN("NumLoops", kNumLoops, "o"),
+ /*0e*/ DEFUN("NumCels", kNumCels, "o"),
+ /*0f*/ DEFUN("CelWide", kCelWide, "iOiOi"),
+ /*10*/ DEFUN("CelHigh", kCelHigh, "iOiOi"),
+ /*11*/ DEFUN("DrawCel", kDrawCel, "iiiiii*"),
+ /*12*/ DEFUN("AddToPic", kAddToPic, "Il*"),
+ /*13*/ DEFUN("NewWindow", kNewWindow, "iiiiZRi*"),
+ /*14*/ DEFUN("GetPort", kGetPort, ""),
+ /*15*/ DEFUN("SetPort", kSetPort, "ii*"),
+ /*16*/ DEFUN("DisposeWindow", kDisposeWindow, "ii*"),
+ /*17*/ DEFUN("DrawControl", kDrawControl, "o"),
+ /*18*/ DEFUN("HiliteControl", kHiliteControl, "o"),
+ /*19*/ DEFUN("EditControl", kEditControl, "ZoZo"),
+ /*1a*/ DEFUN("TextSize", kTextSize, "rZrii*r*"),
+ /*1b*/ DEFUN("Display", kDisplay, ".*"),
+ /*1c*/ DEFUN("GetEvent", kGetEvent, "io"),
+ /*1d*/ DEFUN("GlobalToLocal", kGlobalToLocal, "o"),
+ /*1e*/ DEFUN("LocalToGlobal", kLocalToGlobal, "o"),
+ /*1f*/ DEFUN("MapKeyToDir", kMapKeyToDir, "o"),
+ /*20*/ DEFUN("DrawMenuBar", kDrawMenuBar, "i"),
+ /*21*/ DEFUN("MenuSelect", kMenuSelect, "oi*"),
+ /*22*/ DEFUN("AddMenu", kAddMenu, "rr"),
+ /*23*/ DEFUN("DrawStatus", kDrawStatus, "Zri*"),
+ /*24*/ DEFUN("Parse", kParse, "ro"),
+ /*25*/ DEFUN("Said", kSaid, "Zr"),
+ /*26*/ DEFUN("SetSynonyms", kSetSynonyms, "o"),
+ /*27*/ DEFUN("HaveMouse", kHaveMouse, ""),
+ /*28*/ DEFUN("SetCursor", kSetCursor, "i*"),
+ /*28*/ DEFUN("MoveCursor", kMoveCursor, "ii*"),
+ /*29*/ DEFUN("FOpen", kFOpen, "ri"),
+ /*2a*/ DEFUN("FPuts", kFPuts, "ir"),
+ /*2b*/ DEFUN("FGets", kFGets, "rii"),
+ /*2c*/ DEFUN("FClose", kFClose, "i"),
+ /*2d*/ DEFUN("SaveGame", kSaveGame, "rirr*"),
+ /*2e*/ DEFUN("RestoreGame", kRestoreGame, "rir*"),
+ /*2f*/ DEFUN("RestartGame", kRestartGame, ""),
+ /*30*/ DEFUN("GameIsRestarting", kGameIsRestarting, "i*"),
+ /*31*/ DEFUN("DoSound", kDoSound, "iIo*"),
+ /*32*/ DEFUN("NewList", kNewList, ""),
+ /*33*/ DEFUN("DisposeList", kDisposeList, "l"),
+ /*34*/ DEFUN("NewNode", kNewNode, ".."),
+ /*35*/ DEFUN("FirstNode", kFirstNode, "Zl"),
+ /*36*/ DEFUN("LastNode", kLastNode, "l"),
+ /*37*/ DEFUN("EmptyList", kEmptyList, "l"),
+ /*38*/ DEFUN("NextNode", kNextNode, "n!"),
+ /*39*/ DEFUN("PrevNode", kPrevNode, "n"),
+ /*3a*/ DEFUN("NodeValue", kNodeValue, "Zn!"),
+ /*3b*/ DEFUN("AddAfter", kAddAfter, "lnn"),
+ /*3c*/ DEFUN("AddToFront", kAddToFront, "ln"),
+ /*3d*/ DEFUN("AddToEnd", kAddToEnd, "ln"),
+ /*3e*/ DEFUN("FindKey", kFindKey, "l."),
+ /*3f*/ DEFUN("DeleteKey", kDeleteKey, "l."),
+ /*40*/ DEFUN("Random", kRandom, "i*"),
+ /*41*/ DEFUN("Abs", kAbs, "Oi"),
+ /*42*/ DEFUN("Sqrt", kSqrt, "i"),
+ /*43*/ DEFUN("GetAngle", kGetAngle, "iiii"),
+ /*44*/ DEFUN("GetDistance", kGetDistance, "iiiii*"),
+ /*45*/ DEFUN("Wait", kWait, "i"),
+ /*46*/ DEFUN("GetTime", kGetTime, "i*"),
+ /*47*/ DEFUN("StrEnd", kStrEnd, "r"),
+ /*48*/ DEFUN("StrCat", kStrCat, "rr"),
+ /*49*/ DEFUN("StrCmp", kStrCmp, "rri*"),
+ /*4a*/ DEFUN("StrLen", kStrLen, "r"),
+ /*4b*/ DEFUN("StrCpy", kStrCpy, "rri*"),
+ /*4c*/ DEFUN("Format", kFormat, "r.*"),
+ /*4d*/ DEFUN("GetFarText", kGetFarText, "iir"),
+ /*4e*/ DEFUN("ReadNumber", kReadNumber, "r"),
+ /*4f*/ DEFUN("BaseSetter", kBaseSetter, "o"),
+ /*50*/ DEFUN("DirLoop", kDirLoop, "oi"),
+ /*51*/ DEFUN("CanBeHere", kCanBeHere, "ol*"),
+ /*51*/ DEFUN("CantBeHere", kCanBeHere, "ol*"),
+ /*52*/ DEFUN("OnControl", kOnControl, "i*"),
+ /*53*/ DEFUN("InitBresen", kInitBresen, "oi*"),
+ /*54*/ DEFUN("DoBresen", kDoBresen, "o"),
+ /*55*/ DEFUN("DoAvoider", kDoAvoider, "o"),
+ /*56*/ DEFUN("SetJump", kSetJump, "oiii"),
+ /*57*/ DEFUN("SetDebug", kSetDebug, "i*"),
+ /*58*/ NOFUN("InspectObj"),
+ /*59*/ NOFUN("ShowSends"),
+ /*5a*/ NOFUN("ShowObjs"),
+ /*5b*/ NOFUN("ShowFree"),
+ /*5c*/ DEFUN("MemoryInfo", kMemoryInfo, "i"),
+ /*5d*/ NOFUN("StackUsage"),
+ /*5e*/ NOFUN("Profiler"),
+ /*5f*/ DEFUN("GetMenu", kGetMenu, "i."),
+ /*60*/ DEFUN("SetMenu", kSetMenu, "i.*"),
+ /*61*/ DEFUN("GetSaveFiles", kGetSaveFiles, "rrr"),
+ /*62*/ DEFUN("GetCWD", kGetCWD, "r"),
+ /*63*/ DEFUN("CheckFreeSpace", kCheckFreeSpace, "r"),
+ /*64*/ DEFUN("ValidPath", kValidPath, "r"),
+ /*65*/ DEFUN("CoordPri", kCoordPri, "i"),
+ /*66*/ DEFUN("StrAt", kStrAt, "rii*"),
#ifdef WIN32
-/*67*/ DEFUN("DeviceInfo", kDeviceInfo_Win32, "i.*"),
+ /*67*/ DEFUN("DeviceInfo", kDeviceInfo_Win32, "i.*"),
#else /* !WIN32 */
-/*67*/ DEFUN("DeviceInfo", kDeviceInfo_Unix, "i.*"),
+ /*67*/ DEFUN("DeviceInfo", kDeviceInfo_Unix, "i.*"),
#endif
-/*68*/ DEFUN("GetSaveDir", kGetSaveDir, ""),
-/*69*/ DEFUN("CheckSaveGame", kCheckSaveGame, ".*"),
-/*6a*/ DEFUN("ShakeScreen", kShakeScreen, "ii*"),
-/*6b*/ DEFUN("FlushResources", kFlushResources, "i"),
-/*6c*/ DEFUN("TimesSin", kTimesSin, "ii"),
-/*6d*/ DEFUN("TimesCos", kTimesCos, "ii"),
+ /*68*/ DEFUN("GetSaveDir", kGetSaveDir, ""),
+ /*69*/ DEFUN("CheckSaveGame", kCheckSaveGame, ".*"),
+ /*6a*/ DEFUN("ShakeScreen", kShakeScreen, "ii*"),
+ /*6b*/ DEFUN("FlushResources", kFlushResources, "i"),
+ /*6c*/ DEFUN("TimesSin", kTimesSin, "ii"),
+ /*6d*/ DEFUN("TimesCos", kTimesCos, "ii"),
#if 0
-/*6e*/ NOFUN(NULL),
-/*6f*/ NOFUN(NULL),
+ /*6e*/ NOFUN(NULL),
+ /*6f*/ NOFUN(NULL),
#else
-/*6e*/ DEFUN("6e", kTimesSin, "ii"),
-/*6f*/ DEFUN("6f", kTimesCos, "ii"),
+ /*6e*/ DEFUN("6e", kTimesSin, "ii"),
+ /*6f*/ DEFUN("6f", kTimesCos, "ii"),
#endif
-/*70*/ DEFUN("Graph", kGraph, ".*"),
-/*71*/ DEFUN("Joystick", kJoystick, ".*"),
-/*72*/ NOFUN(NULL),
-/*73*/ NOFUN(NULL),
-
- /* Experimental functions */
-/*74*/ DEFUN("FileIO", kFileIO, "i.*"),
-/*(?)*/ DEFUN("Memory", kMemory, "i.*"),
-/*(?)*/ DEFUN("Sort", kSort, "ooo"),
-/*(?)*/ DEFUN("AvoidPath", kAvoidPath, "ii.*"),
-/*(?)*/ DEFUN("Lock", kLock, "iii*"),
-/*(?)*/ DEFUN("Palette", kPalette, "i*"),
-/*(?)*/ DEFUN("IsItSkip", kIsItSkip, "iiiii"),
-
- /* Non-experimental Functions without a fixed ID */
+ /*70*/ DEFUN("Graph", kGraph, ".*"),
+ /*71*/ DEFUN("Joystick", kJoystick, ".*"),
+ /*72*/ NOFUN(NULL),
+ /*73*/ NOFUN(NULL),
+
+ /* Experimental functions */
+ /*74*/ DEFUN("FileIO", kFileIO, "i.*"),
+ /*(?)*/ DEFUN("Memory", kMemory, "i.*"),
+ /*(?)*/ DEFUN("Sort", kSort, "ooo"),
+ /*(?)*/ DEFUN("AvoidPath", kAvoidPath, "ii.*"),
+ /*(?)*/ DEFUN("Lock", kLock, "iii*"),
+ /*(?)*/ DEFUN("Palette", kPalette, "i*"),
+ /*(?)*/ DEFUN("IsItSkip", kIsItSkip, "iiiii"),
+
+ /* Non-experimental Functions without a fixed ID */
DEFUN("CosMult", kTimesCos, "ii"),
DEFUN("SinMult", kTimesSin, "ii"),
-/*(?)*/ DEFUN("CosDiv", kCosDiv, "ii"),
-/*(?)*/ DEFUN("PriCoord", kPriCoord, "i"),
-/*(?)*/ DEFUN("SinDiv", kSinDiv, "ii"),
-/*(?)*/ DEFUN("TimesCot", kTimesCot, "ii"),
-/*(?)*/ DEFUN("TimesTan", kTimesTan, "ii"),
-DEFUN("Message", kMessage, ".*"),
-DEFUN("DoAudio", kDoAudio, ".*"),
+ /*(?)*/ DEFUN("CosDiv", kCosDiv, "ii"),
+ /*(?)*/ DEFUN("PriCoord", kPriCoord, "i"),
+ /*(?)*/ DEFUN("SinDiv", kSinDiv, "ii"),
+ /*(?)*/ DEFUN("TimesCot", kTimesCot, "ii"),
+ /*(?)*/ DEFUN("TimesTan", kTimesTan, "ii"),
+ DEFUN("Message", kMessage, ".*"),
+ DEFUN("DoAudio", kDoAudio, ".*"),
- /* Special and NOP stuff */
+ /* Special and NOP stuff */
{KF_NEW, NULL, {k_Unknown, NULL, NULL}},
{KF_TERMINATOR, NULL, {NULL, NULL, NULL}} /* Terminator */
};
-static const char *argtype_description[] = {"Undetermined (WTF?)", "List","Node","Object","Reference","Arithmetic"};
+static const char *argtype_description[] = {"Undetermined (WTF?)", "List", "Node", "Object", "Reference", "Arithmetic"};
/******************** Kernel Oops ********************/
int
-kernel_oops(state_t *s, const char *file, int line, const char *reason)
-{
+kernel_oops(state_t *s, const char *file, int line, const char *reason) {
sciprintf("Kernel Oops in file %s, line %d: %s\n", file, line, reason);
- fprintf(stderr,"Kernel Oops in file %s, line %d: %s\n", file, line, reason);
+ fprintf(stderr, "Kernel Oops in file %s, line %d: %s\n", file, line, reason);
script_debug_flag = script_error_flag = 1;
return 0;
}
@@ -368,8 +367,7 @@ kernel_oops(state_t *s, const char *file, int line, const char *reason)
/* Allocates a set amount of memory for a specified use and returns a handle to it. */
reg_t
-kalloc(state_t *s, const char *type, int space)
-{
+kalloc(state_t *s, const char *type, int space) {
reg_t reg;
sm_alloc_hunk_entry(&s->seg_manager, type, space, &reg);
@@ -379,12 +377,10 @@ kalloc(state_t *s, const char *type, int space)
}
int
-has_kernel_function(state_t *s, const char *kname)
-{
+has_kernel_function(state_t *s, const char *kname) {
int i = 0;
- while (s->kernel_names[i])
- {
+ while (s->kernel_names[i]) {
if (!strcmp(s->kernel_names[i], kname))
return 1;
i++;
@@ -395,8 +391,7 @@ has_kernel_function(state_t *s, const char *kname)
/* Returns a pointer to the memory indicated by the specified handle */
byte *
-kmem(state_t *s, reg_t handle)
-{
+kmem(state_t *s, reg_t handle) {
mem_obj_t *mobj = GET_SEGMENT(s->seg_manager, handle.segment, MEM_OBJ_HUNK);
hunk_table_t *ht = &(mobj->data.hunks);
@@ -410,8 +405,7 @@ kmem(state_t *s, reg_t handle)
/* Frees the specified handle. Returns 0 on success, 1 otherwise. */
int
-kfree(state_t *s, reg_t handle)
-{
+kfree(state_t *s, reg_t handle) {
sm_free_hunk_entry(&s->seg_manager, handle);
return 0;
@@ -425,8 +419,7 @@ kfree(state_t *s, reg_t handle)
char *old_save_dir;
reg_t
-kRestartGame(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kRestartGame(state_t *s, int funct_nr, int argc, reg_t *argv) {
char *deref_save_dir = (char*)kernel_dereference_bulk_pointer(s, s->save_dir_copy, 1);
old_save_dir = strdup(deref_save_dir);
@@ -442,12 +435,10 @@ kRestartGame(state_t *s, int funct_nr, int argc, reg_t *argv)
** Returns the restarting_flag in acc
*/
reg_t
-kGameIsRestarting(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kGameIsRestarting(state_t *s, int funct_nr, int argc, reg_t *argv) {
char *deref_save_dir = (char*)kernel_dereference_bulk_pointer(s, s->save_dir_copy, 1);
- if (old_save_dir&&deref_save_dir)
- {
+ if (old_save_dir && deref_save_dir) {
strcpy(deref_save_dir, old_save_dir);
free(old_save_dir);
old_save_dir = NULL;
@@ -464,18 +455,16 @@ kGameIsRestarting(state_t *s, int funct_nr, int argc, reg_t *argv)
}
reg_t
-kHaveMouse(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kHaveMouse(state_t *s, int funct_nr, int argc, reg_t *argv) {
- return make_reg (0, (s->have_mouse_flag
- && gfxop_have_mouse(s->gfx_state))? -1 : 0);
+ return make_reg(0, (s->have_mouse_flag
+ && gfxop_have_mouse(s->gfx_state)) ? -1 : 0);
}
reg_t
-kMemoryInfo(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kMemoryInfo(state_t *s, int funct_nr, int argc, reg_t *argv) {
switch (argv[0].offset) {
case 0: /* Total free heap memory */
case 1: /* Largest heap block available */
@@ -484,42 +473,40 @@ kMemoryInfo(state_t *s, int funct_nr, int argc, reg_t *argv)
case 4: /* Amount of free DOS paragraphs- SCI01 */
return make_reg(0, 0x7fff); /* Must not be 0xffff, or some memory calculations will overflow */
- default: SCIkwarn(SCIkWARNING, "Unknown MemoryInfo operation: %04x\n", argv[0].offset);
+ default:
+ SCIkwarn(SCIkWARNING, "Unknown MemoryInfo operation: %04x\n", argv[0].offset);
}
return NULL_REG;
}
reg_t
-k_Unknown(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+k_Unknown(state_t *s, int funct_nr, int argc, reg_t *argv) {
if (funct_nr >= SCI_MAPPED_UNKNOWN_KFUNCTIONS_NR) {
SCIkwarn(SCIkSTUB, "Unhandled Unknown function %04x\n", funct_nr);
return NULL_REG;
- } else switch(kfunct_mappers[funct_nr].type) {
+ } else switch (kfunct_mappers[funct_nr].type) {
- case KF_NEW:
- return kfunct_mappers[funct_nr].sig_pair.fun(s, funct_nr, argc, argv);
+ case KF_NEW:
+ return kfunct_mappers[funct_nr].sig_pair.fun(s, funct_nr, argc, argv);
- case KF_NONE:
- default:
- SCIkwarn(SCIkSTUB, "Unhandled Unknown function %04x\n", funct_nr);
- return NULL_REG;
- }
+ case KF_NONE:
+ default:
+ SCIkwarn(SCIkSTUB, "Unhandled Unknown function %04x\n", funct_nr);
+ return NULL_REG;
+ }
}
reg_t
-kFlushResources(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kFlushResources(state_t *s, int funct_nr, int argc, reg_t *argv) {
run_gc(s);
SCIkdebug(SCIkROOM, "Entering room number %d\n", UKPV(0));
return s->r_acc;
}
reg_t
-kSetDebug(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kSetDebug(state_t *s, int funct_nr, int argc, reg_t *argv) {
sciprintf("Debug mode activated\n");
script_debug_flag = 1; /* Enter debug mode */
@@ -533,8 +520,7 @@ kSetDebug(state_t *s, int funct_nr, int argc, reg_t *argv)
#define _K_NEW_GETTIME_DATE 3
reg_t
-kGetTime(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kGetTime(state_t *s, int funct_nr, int argc, reg_t *argv) {
struct tm* loc_time;
GTimeVal time_prec;
time_t the_time;
@@ -544,12 +530,11 @@ kGetTime(state_t *s, int funct_nr, int argc, reg_t *argv)
/* Reset optimization flags: If this function is called,
** the game may be waiting for a timeout */
s->kernel_opt_flags &= ~(KERNEL_OPT_FLAG_GOT_EVENT
- | KERNEL_OPT_FLAG_GOT_2NDEVENT);
+ | KERNEL_OPT_FLAG_GOT_2NDEVENT);
#endif
#ifdef WIN32
- if (TIMERR_NOERROR != timeBeginPeriod(1))
- {
+ if (TIMERR_NOERROR != timeBeginPeriod(1)) {
fprintf(stderr, "timeBeginPeriod(1) failed in kGetTime!\n");
}
#endif /* WIN32 */
@@ -558,20 +543,19 @@ kGetTime(state_t *s, int funct_nr, int argc, reg_t *argv)
loc_time = localtime(&the_time);
#ifdef WIN32
- if (TIMERR_NOERROR != timeEndPeriod(1))
- {
+ if (TIMERR_NOERROR != timeEndPeriod(1)) {
fprintf(stderr, "timeEndPeriod(1) failed in kGetTime!\n");
}
#endif /* WIN32 */
- if (s->version<SCI_VERSION_FTU_NEW_GETTIME) { /* Use old semantics */
+ if (s->version < SCI_VERSION_FTU_NEW_GETTIME) { /* Use old semantics */
if (argc) { /* Get seconds since last am/pm switch */
retval = loc_time->tm_sec + loc_time->tm_min * 60 + (loc_time->tm_hour % 12) * 3600;
SCIkdebug(SCIkTIME, "GetTime(timeofday) returns %d\n", retval);
} else { /* Get time since game started */
- sci_get_current_time (&time_prec);
+ sci_get_current_time(&time_prec);
retval = ((time_prec.tv_usec - s->game_start_time.tv_usec) * 60 / 1000000) +
- (time_prec.tv_sec - s->game_start_time.tv_sec) * 60;
+ (time_prec.tv_sec - s->game_start_time.tv_sec) * 60;
SCIkdebug(SCIkTIME, "GetTime(elapsed) returns %d\n", retval);
}
} else {
@@ -579,25 +563,25 @@ kGetTime(state_t *s, int funct_nr, int argc, reg_t *argv)
mode 0 and the others. We assume that this is safe, though */
switch (mode) {
case _K_NEW_GETTIME_TICKS : {
- sci_get_current_time (&time_prec);
+ sci_get_current_time(&time_prec);
retval = ((time_prec.tv_usec - s->game_start_time.tv_usec) * 60 / 1000000) +
- (time_prec.tv_sec - s->game_start_time.tv_sec) * 60;
+ (time_prec.tv_sec - s->game_start_time.tv_sec) * 60;
SCIkdebug(SCIkTIME, "GetTime(elapsed) returns %d\n", retval);
break;
}
case _K_NEW_GETTIME_TIME_12HOUR : {
loc_time->tm_hour %= 12;
- retval=(loc_time->tm_min<<6)|(loc_time->tm_hour<<12)|(loc_time->tm_sec);
+ retval = (loc_time->tm_min << 6) | (loc_time->tm_hour << 12) | (loc_time->tm_sec);
SCIkdebug(SCIkTIME, "GetTime(12h) returns %d\n", retval);
break;
}
case _K_NEW_GETTIME_TIME_24HOUR : {
- retval=(loc_time->tm_min<<5)|(loc_time->tm_sec>>1)|(loc_time->tm_hour<<11);
+ retval = (loc_time->tm_min << 5) | (loc_time->tm_sec >> 1) | (loc_time->tm_hour << 11);
SCIkdebug(SCIkTIME, "GetTime(24h) returns %d\n", retval);
break;
}
case _K_NEW_GETTIME_DATE : {
- retval=(loc_time->tm_mon<<5)|loc_time->tm_mday|(loc_time->tm_year<<9);
+ retval = (loc_time->tm_mon << 5) | loc_time->tm_mday | (loc_time->tm_year << 9);
SCIkdebug(SCIkTIME, "GetTime(date) returns %d\n", retval);
break;
}
@@ -619,15 +603,14 @@ kGetTime(state_t *s, int funct_nr, int argc, reg_t *argv)
#define K_MEMORY_POKE 6
reg_t
-kMemory(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kMemory(state_t *s, int funct_nr, int argc, reg_t *argv) {
switch (UKPV(0)) {
case K_MEMORY_ALLOCATE_CRITICAL :
- if (!sm_alloc_dynmem(&s->seg_manager, UKPV(1),
- "kMemory() critical", &s->r_acc)) {
+ if (!sm_alloc_dynmem(&s->seg_manager, UKPV(1),
+ "kMemory() critical", &s->r_acc)) {
SCIkwarn(SCIkERROR, "Critical heap allocation failed\n");
script_error_flag = script_debug_flag = 1;
}
@@ -638,14 +621,14 @@ kMemory(state_t *s, int funct_nr, int argc, reg_t *argv)
case K_MEMORY_ALLOCATE_NONCRITICAL :
sm_alloc_dynmem(&s->seg_manager, UKPV(1),
- "kMemory() non-critical", &s->r_acc);
+ "kMemory() non-critical", &s->r_acc);
break;
case K_MEMORY_FREE :
if (sm_free_dynmem(&s->seg_manager, argv[1])) {
SCIkwarn(SCIkERROR, "Attempt to kMemory::free() non-dynmem pointer "PREG"!\n",
- PRINT_REG(argv[1]));
+ PRINT_REG(argv[1]));
}
break;
@@ -667,42 +650,43 @@ kMemory(state_t *s, int funct_nr, int argc, reg_t *argv)
}
break;
- }
+ }
case K_MEMORY_PEEK : {
byte *ref = kernel_dereference_bulk_pointer(s, argv[1], 2);
if (!ref) {
SCIkdebug(SCIkERROR, "Attempt to poke invalid memory at "PREG"!\n",
- PRINT_REG(argv[1]));
+ PRINT_REG(argv[1]));
return s->r_acc;
}
if (s->seg_manager.heap[argv[1].segment]->type == MEM_OBJ_LOCALS)
- return *((reg_t *) ref); else
+ return *((reg_t *) ref);
+ else
return make_reg(0, getInt16(ref));
}
- break;
+ break;
case K_MEMORY_POKE : {
byte *ref = kernel_dereference_bulk_pointer(s, argv[1], 2);
if (!ref) {
SCIkdebug(SCIkERROR, "Attempt to poke invalid memory at "PREG"!\n",
- PRINT_REG(argv[1]));
+ PRINT_REG(argv[1]));
return s->r_acc;
}
if (s->seg_manager.heap[argv[1].segment]->type == MEM_OBJ_LOCALS)
- *((reg_t *) ref) = argv[2]; else
- {
- if (argv[2].segment) {
- SCIkdebug(SCIkERROR, "Attempt to poke memory reference "PREG" to "PREG"!\n",
- PRINT_REG(argv[2]), PRINT_REG(argv[1]));
- return s->r_acc;
- putInt16(ref, argv[2].offset);
- }
-
+ *((reg_t *) ref) = argv[2];
+ else {
+ if (argv[2].segment) {
+ SCIkdebug(SCIkERROR, "Attempt to poke memory reference "PREG" to "PREG"!\n",
+ PRINT_REG(argv[2]), PRINT_REG(argv[1]));
+ return s->r_acc;
+ putInt16(ref, argv[2].offset);
}
+
+ }
return s->r_acc;
break;
@@ -713,16 +697,15 @@ kMemory(state_t *s, int funct_nr, int argc, reg_t *argv)
}
reg_t
-kstub(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kstub(state_t *s, int funct_nr, int argc, reg_t *argv) {
int i;
SCIkwarn(SCIkWARNING, "Unimplemented syscall: %s[%x](",
- s->kernel_names[funct_nr], funct_nr);
+ s->kernel_names[funct_nr], funct_nr);
for (i = 0; i < argc; i++) {
sciprintf(PREG, PRINT_REG(argv[i]));
- if (i+1 < argc) sciprintf(", ");
+ if (i + 1 < argc) sciprintf(", ");
}
sciprintf(")\n");
return NULL_REG;
@@ -730,18 +713,16 @@ kstub(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kNOP(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kNOP(state_t *s, int funct_nr, int argc, reg_t *argv) {
const char *problem = (const char*)(s->kfunct_table[funct_nr].orig_name ?
- "unmapped" : "NOP");
+ "unmapped" : "NOP");
SCIkwarn(SCIkWARNING, "Warning: Kernel function 0x%02x invoked: %s", funct_nr, problem);
if (s->kfunct_table[funct_nr].orig_name &&
- strcmp(s->kfunct_table[funct_nr].orig_name, SCRIPT_UNKNOWN_FUNCTION_STRING))
- {
- sciprintf(" (but its name is known to be %s)", s->kfunct_table[funct_nr].orig_name);
- }
+ strcmp(s->kfunct_table[funct_nr].orig_name, SCRIPT_UNKNOWN_FUNCTION_STRING)) {
+ sciprintf(" (but its name is known to be %s)", s->kfunct_table[funct_nr].orig_name);
+ }
sciprintf("\n");
return NULL_REG;
@@ -750,8 +731,7 @@ kNOP(state_t *s, int funct_nr, int argc, reg_t *argv)
void
-kernel_compile_signature(const char **s)
-{
+kernel_compile_signature(const char **s) {
const char *src = *s;
char *result;
int ellipsis = 0;
@@ -769,8 +749,8 @@ kernel_compile_signature(const char **s)
if (ellipsis) {
sciprintf("INTERNAL ERROR when compiling kernel"
- " function signature '%s': non-terminal ellipsis\n", *s,
- *src);
+ " function signature '%s': non-terminal ellipsis\n", *s,
+ *src);
exit(1);
}
@@ -813,7 +793,7 @@ kernel_compile_signature(const char **s)
case KSIG_SPEC_ALLOW_INV:
v |= KSIG_ALLOW_INV;
break;
-
+
case KSIG_SPEC_ELLIPSIS:
v |= KSIG_ELLIPSIS;
ellipsis = 1;
@@ -821,16 +801,16 @@ kernel_compile_signature(const char **s)
default: {
sciprintf("INTERNAL ERROR when compiling kernel"
- " function signature '%s': (%02x) not understood (aka"
- " '%c')\n",
- *s, c, c);
+ " function signature '%s': (%02x) not understood (aka"
+ " '%c')\n",
+ *s, c, c);
exit(1);
}
}
- } while (*src && (*src == KSIG_SPEC_ALLOW_INV ||
- *src == KSIG_SPEC_ELLIPSIS ||
- (c < 'a' && c != KSIG_SPEC_ANY)));
+ } while (*src && (*src == KSIG_SPEC_ALLOW_INV ||
+ *src == KSIG_SPEC_ELLIPSIS ||
+ (c < 'a' && c != KSIG_SPEC_ANY)));
/* To handle sum types */
result[index++] = v;
@@ -841,22 +821,21 @@ kernel_compile_signature(const char **s)
}
int
-script_map_kernel(state_t *s)
-{
+script_map_kernel(state_t *s) {
int functnr;
int mapped = 0;
int ignored = 0;
int functions_nr = s->kernel_names_nr;
int max_functions_nr
- = sci_max_allowed_unknown_kernel_functions[s->resmgr
- ->sci_version];
+ = sci_max_allowed_unknown_kernel_functions[s->resmgr
+ ->sci_version];
if (functions_nr < max_functions_nr) {
sciprintf("Warning: SCI version believed to have %d kernel"
- " functions, but only %d reported-- filling up"
- " remaining %d\n",
- max_functions_nr, functions_nr,
- max_functions_nr - functions_nr);
+ " functions, but only %d reported-- filling up"
+ " remaining %d\n",
+ max_functions_nr, functions_nr,
+ max_functions_nr - functions_nr);
functions_nr = max_functions_nr;
}
@@ -875,21 +854,19 @@ script_map_kernel(state_t *s)
if (sought_name)
for (seeker = 0; (found == -1)
- && kfunct_mappers[seeker].type != KF_TERMINATOR; seeker++)
+ && kfunct_mappers[seeker].type != KF_TERMINATOR; seeker++)
if (kfunct_mappers[seeker].name
- && strcmp(kfunct_mappers[seeker].name, sought_name) == 0)
+ && strcmp(kfunct_mappers[seeker].name, sought_name) == 0)
found = seeker; /* Found a kernel function with the same name! */
if (found == -1) {
- if (sought_name)
- {
+ if (sought_name) {
sciprintf("Warning: Kernel function %s[%x] unmapped\n",
- s->kernel_names[functnr], functnr);
+ s->kernel_names[functnr], functnr);
s->kfunct_table[functnr].fun = kNOP;
- } else
- {
+ } else {
sciprintf("Warning: Flagging kernel function %x as unknown\n",
- functnr);
+ functnr);
s->kfunct_table[functnr].fun = k_Unknown;
}
@@ -897,26 +874,26 @@ script_map_kernel(state_t *s)
s->kfunct_table[functnr].orig_name = sought_name;
} else switch (kfunct_mappers[found].type) {
- case KF_OLD:
- sciprintf("Emulated kernel function found.\nThis shouldn't happen anymore.");
- return 1;
+ case KF_OLD:
+ sciprintf("Emulated kernel function found.\nThis shouldn't happen anymore.");
+ return 1;
- case KF_NONE:
- s->kfunct_table[functnr].signature = NULL;
- ++ignored;
- break;
+ case KF_NONE:
+ s->kfunct_table[functnr].signature = NULL;
+ ++ignored;
+ break;
- case KF_NEW:
- s->kfunct_table[functnr] = kfunct_mappers[found].sig_pair;
- kernel_compile_signature(&(s->kfunct_table[functnr].signature));
- ++mapped;
- break;
- }
+ case KF_NEW:
+ s->kfunct_table[functnr] = kfunct_mappers[found].sig_pair;
+ kernel_compile_signature(&(s->kfunct_table[functnr].signature));
+ ++mapped;
+ break;
+ }
} /* for all functions requesting to be mapped */
sciprintf("Handled %d/%d kernel functions, mapping %d",
- mapped+ignored, s->kernel_names_nr, mapped);
+ mapped + ignored, s->kernel_names_nr, mapped);
if (ignored)
sciprintf(" and ignoring %d", ignored);
sciprintf(".\n");
@@ -924,15 +901,13 @@ script_map_kernel(state_t *s)
}
void
-free_kfunct_tables(state_t *s)
-{
+free_kfunct_tables(state_t *s) {
sci_free(s->kfunct_table);
s->kfunct_table = NULL;
}
int
-determine_reg_type(state_t *s, reg_t reg, int allow_invalid)
-{
+determine_reg_type(state_t *s, reg_t reg, int allow_invalid) {
mem_obj_t *mobj;
if (!reg.segment) {
@@ -942,7 +917,7 @@ determine_reg_type(state_t *s, reg_t reg, int allow_invalid)
}
if ((reg.segment >= s->seg_manager.heap_size)
- || !s->seg_manager.heap[reg.segment])
+ || !s->seg_manager.heap[reg.segment])
return 0; /* Invalid */
mobj = s->seg_manager.heap[reg.segment];
@@ -951,8 +926,8 @@ determine_reg_type(state_t *s, reg_t reg, int allow_invalid)
case MEM_OBJ_SCRIPT:
if (reg.offset <= mobj->data.script.buf_size
- && reg.offset >= -SCRIPT_OBJECT_MAGIC_OFFSET
- && RAW_IS_OBJECT(mobj->data.script.buf + reg.offset)) {
+ && reg.offset >= -SCRIPT_OBJECT_MAGIC_OFFSET
+ && RAW_IS_OBJECT(mobj->data.script.buf + reg.offset)) {
int idx = RAW_GET_CLASS_INDEX(&(mobj->data.script), reg);
if (idx >= 0 && idx < mobj->data.script.objects_nr)
return KSIG_OBJECT;
@@ -981,7 +956,7 @@ determine_reg_type(state_t *s, reg_t reg, int allow_invalid)
case MEM_OBJ_SYS_STRINGS:
if (allow_invalid || (reg.offset < SYS_STRINGS_MAX
- && mobj->data.sys_strings.strings[reg.offset].name))
+ && mobj->data.sys_strings.strings[reg.offset].name))
return KSIG_REF;
else
return KSIG_REF | KSIG_INVALID;
@@ -1011,16 +986,14 @@ determine_reg_type(state_t *s, reg_t reg, int allow_invalid)
}
const char *
-kernel_argtype_description(int type)
-{
- type &= ~KSIG_INVALID;
-
- return argtype_description[sci_ffs(type)];
+kernel_argtype_description(int type) {
+ type &= ~KSIG_INVALID;
+
+ return argtype_description[sci_ffs(type)];
}
int
-kernel_matches_signature(state_t *s, const char *sig, int argc, reg_t *argv)
-{
+kernel_matches_signature(state_t *s, const char *sig, int argc, reg_t *argv) {
if (!sig)
return 1;
@@ -1030,15 +1003,15 @@ kernel_matches_signature(state_t *s, const char *sig, int argc, reg_t *argv)
if (!type) {
sciprintf("[KERN] Could not determine type of ref "PREG";"
- " failing signature check\n",
- PRINT_REG(*argv));
+ " failing signature check\n",
+ PRINT_REG(*argv));
return 0;
}
-
+
if (type & KSIG_INVALID) {
sciprintf("[KERN] ref "PREG" was determined to be a %s, "
- "but the reference itself is invalid\n",
- PRINT_REG(*argv), kernel_argtype_description(type));
+ "but the reference itself is invalid\n",
+ PRINT_REG(*argv), kernel_argtype_description(type));
return 0;
}
@@ -1059,35 +1032,32 @@ kernel_matches_signature(state_t *s, const char *sig, int argc, reg_t *argv)
}
static inline void *
-_kernel_dereference_pointer(struct _state *s, reg_t pointer, int entries, int align)
-{
+_kernel_dereference_pointer(struct _state *s, reg_t pointer, int entries, int align) {
int maxsize;
- void *retval = sm_dereference(&s->seg_manager, pointer, &maxsize);
+ void *retval = sm_dereference(&s->seg_manager, pointer, &maxsize);
- if (pointer.offset & (align-1)) {
+ if (pointer.offset & (align - 1)) {
SCIkdebug(SCIkERROR, "Unaligned pointer read: "PREG" expected with %d alignment!\n",
- PRINT_REG(pointer), align);
+ PRINT_REG(pointer), align);
return NULL;
}
if (entries > maxsize) {
SCIkdebug(SCIkERROR, "Trying to dereference pointer "PREG" beyond end of segment!\n",
- PRINT_REG(pointer));
+ PRINT_REG(pointer));
return NULL;
}
- return retval;
+ return retval;
}
byte *
-kernel_dereference_bulk_pointer(struct _state *s, reg_t pointer, int entries)
-{
+kernel_dereference_bulk_pointer(struct _state *s, reg_t pointer, int entries) {
return (byte*)_kernel_dereference_pointer(s, pointer, entries, 1);
}
reg_t *
-kernel_dereference_reg_pointer(struct _state *s, reg_t pointer, int entries)
-{
+kernel_dereference_reg_pointer(struct _state *s, reg_t pointer, int entries) {
return (reg_t*)_kernel_dereference_pointer(s, pointer, entries, sizeof(reg_t));
}
diff --git a/engines/sci/engine/kernel_compat.h b/engines/sci/engine/kernel_compat.h
index a021064223..7606f8881f 100644
--- a/engines/sci/engine/kernel_compat.h
+++ b/engines/sci/engine/kernel_compat.h
@@ -55,21 +55,19 @@ if ((address) & 1) \
/* Sets a heap value if allowed */
static inline int
-getHeapInt16(unsigned char *base, int address)
-{
- if (address & 1)
- sciprintf("Warning: Unaligned read from %04x\n", (address) & 0xffff);
+getHeapInt16(unsigned char *base, int address) {
+ if (address & 1)
+ sciprintf("Warning: Unaligned read from %04x\n", (address) & 0xffff);
- return getInt16(base + address);
+ return getInt16(base + address);
}
static inline unsigned int
-getHeapUInt16(unsigned char *base, int address)
-{
- if (address & 1)
- sciprintf("Warning: Unaligned unsigned read from %04x\n", (address) & 0xffff);
+getHeapUInt16(unsigned char *base, int address) {
+ if (address & 1)
+ sciprintf("Warning: Unaligned unsigned read from %04x\n", (address) & 0xffff);
- return getUInt16(base + address);
+ return getUInt16(base + address);
}
diff --git a/engines/sci/engine/kernel_types.h b/engines/sci/engine/kernel_types.h
index f13e793457..9bff50e09e 100644
--- a/engines/sci/engine/kernel_types.h
+++ b/engines/sci/engine/kernel_types.h
@@ -81,7 +81,7 @@ determine_reg_type(state_t *s, reg_t reg, int allow_invalid);
** Parameters: (state_t *) s: The state to operate on
** (reg_t) reg: The register to check
** (int) allow_invalid: Allow invalid pointer values
-** Returns : one of KSIG_* below KSIG_NULL.
+** Returns : one of KSIG_* below KSIG_NULL.
** KSIG_INVALID set if the type of reg can be determined, but is invalid.
** 0 on error.
*/
diff --git a/engines/sci/engine/kevent.cpp b/engines/sci/engine/kevent.cpp
index 3b6df771e7..f559fb4184 100644
--- a/engines/sci/engine/kevent.cpp
+++ b/engines/sci/engine/kevent.cpp
@@ -32,14 +32,13 @@ int stop_on_event;
#define SCI_VARIABLE_GAME_SPEED 3
reg_t
-kGetEvent(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kGetEvent(state_t *s, int funct_nr, int argc, reg_t *argv) {
int mask = UKPV(0);
reg_t obj = argv[1];
sci_event_t e;
int oldx, oldy;
- int modifier_mask = SCI_VERSION_MAJOR(s->version)==0 ? SCI_EVM_ALL
- : SCI_EVM_NO_FOOLOCK;
+ int modifier_mask = SCI_VERSION_MAJOR(s->version) == 0 ? SCI_EVM_ALL
+ : SCI_EVM_NO_FOOLOCK;
if (s->kernel_opt_flags & KERNEL_OPT_FLAG_GOT_2NDEVENT) {
/* Penalty time- too many requests to this function without
@@ -48,7 +47,7 @@ kGetEvent(state_t *s, int funct_nr, int argc, reg_t *argv)
gfxop_usleep(s->gfx_state, (1000000 * delay) / 60);
}
-
+
/*If there's a simkey pending, and the game wants a keyboard event, use the
*simkey instead of a normal event*/
if (_kdebug_cheap_event_hack && (mask & SCI_EVT_KEYBOARD)) {
@@ -60,7 +59,7 @@ kGetEvent(state_t *s, int funct_nr, int argc, reg_t *argv)
_kdebug_cheap_event_hack = 0;
return make_reg(0, 1);
}
-
+
oldx = s->gfx_state->pointer_pos.x;
oldy = s->gfx_state->pointer_pos.y;
e = gfxop_get_event(s->gfx_state, mask);
@@ -75,7 +74,7 @@ kGetEvent(state_t *s, int funct_nr, int argc, reg_t *argv)
if (e.type)
s->kernel_opt_flags &= ~(KERNEL_OPT_FLAG_GOT_EVENT
- | KERNEL_OPT_FLAG_GOT_2NDEVENT);
+ | KERNEL_OPT_FLAG_GOT_2NDEVENT);
else {
if (s->kernel_opt_flags & KERNEL_OPT_FLAG_GOT_EVENT)
s->kernel_opt_flags |= KERNEL_OPT_FLAG_GOT_2NDEVENT;
@@ -83,95 +82,118 @@ kGetEvent(state_t *s, int funct_nr, int argc, reg_t *argv)
s->kernel_opt_flags |= KERNEL_OPT_FLAG_GOT_EVENT;
}
- switch(e.type)
- {
- case SCI_EVT_QUIT:
- quit_vm();
- break;
+ switch (e.type) {
+ case SCI_EVT_QUIT:
+ quit_vm();
+ break;
- case SCI_EVT_KEYBOARD: {
+ case SCI_EVT_KEYBOARD: {
- if ((e.buckybits & SCI_EVM_LSHIFT) && (e.buckybits & SCI_EVM_RSHIFT)
- && (e.data == '-')) {
+ if ((e.buckybits & SCI_EVM_LSHIFT) && (e.buckybits & SCI_EVM_RSHIFT)
+ && (e.data == '-')) {
- sciprintf("Debug mode activated\n");
+ sciprintf("Debug mode activated\n");
- script_debug_flag = 1; /* Enter debug mode */
- _debug_seeking = _debug_step_running = 0;
- s->onscreen_console = 0;
+ script_debug_flag = 1; /* Enter debug mode */
+ _debug_seeking = _debug_step_running = 0;
+ s->onscreen_console = 0;
- } else if ((e.buckybits & SCI_EVM_CTRL) && (e.data == '`')) {
+ } else if ((e.buckybits & SCI_EVM_CTRL) && (e.data == '`')) {
- script_debug_flag = 1; /* Enter debug mode */
- _debug_seeking = _debug_step_running = 0;
- s->onscreen_console = 1;
+ script_debug_flag = 1; /* Enter debug mode */
+ _debug_seeking = _debug_step_running = 0;
+ s->onscreen_console = 1;
- } else if ((e.buckybits & SCI_EVM_CTRL) && (e.data == '1')) {
+ } else if ((e.buckybits & SCI_EVM_CTRL) && (e.data == '1')) {
- if (s->visual)
- s->visual->print(GFXW(s->visual), 0);
+ if (s->visual)
+ s->visual->print(GFXW(s->visual), 0);
- } else {
- PUT_SEL32V(obj, type, SCI_EVT_KEYBOARD); /*Keyboard event*/
- s->r_acc=make_reg(0, 1);
- PUT_SEL32V(obj, message, e.character);
- /* We only care about the translated
- ** character */
- PUT_SEL32V(obj, modifiers, e.buckybits&modifier_mask);
+ } else {
+ PUT_SEL32V(obj, type, SCI_EVT_KEYBOARD); /*Keyboard event*/
+ s->r_acc = make_reg(0, 1);
+ PUT_SEL32V(obj, message, e.character);
+ /* We only care about the translated
+ ** character */
+ PUT_SEL32V(obj, modifiers, e.buckybits&modifier_mask);
+ }
+ }
+ break;
+
+ case SCI_EVT_MOUSE_RELEASE:
+ case SCI_EVT_MOUSE_PRESS: {
+ int extra_bits = 0;
+
+ if (mask & e.type) {
+ switch (e.data) {
+ case 2:
+ extra_bits = SCI_EVM_LSHIFT | SCI_EVM_RSHIFT;
+ break;
+ case 3:
+ extra_bits = SCI_EVM_CTRL;
+ default:
+ break;
}
- } break;
-
- case SCI_EVT_MOUSE_RELEASE:
- case SCI_EVT_MOUSE_PRESS: {
- int extra_bits=0;
-
- if(mask & e.type) {
- switch(e.data) {
- case 2: extra_bits=SCI_EVM_LSHIFT|SCI_EVM_RSHIFT; break;
- case 3: extra_bits=SCI_EVM_CTRL;
- default:break;
- }
-
- PUT_SEL32V(obj, type, e.type);
- PUT_SEL32V(obj, message, 1);
- PUT_SEL32V(obj, modifiers, (e.buckybits|extra_bits)&modifier_mask);
- s->r_acc = make_reg(0, 1);
- }
- } break;
- default: {
- s->r_acc = NULL_REG; /* Unknown or no event */
- }
+ PUT_SEL32V(obj, type, e.type);
+ PUT_SEL32V(obj, message, 1);
+ PUT_SEL32V(obj, modifiers, (e.buckybits | extra_bits)&modifier_mask);
+ s->r_acc = make_reg(0, 1);
}
+ }
+ break;
+
+ default: {
+ s->r_acc = NULL_REG; /* Unknown or no event */
+ }
+ }
if ((s->r_acc.offset) && (stop_on_event)) {
stop_on_event = 0;
script_debug_flag = 1;
- }
+ }
return s->r_acc;
}
reg_t
-kMapKeyToDir(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kMapKeyToDir(state_t *s, int funct_nr, int argc, reg_t *argv) {
reg_t obj = argv[0];
if (GET_SEL32V(obj, type) == SCI_EVT_KEYBOARD) { /* Keyboard */
int mover = -1;
switch (GET_SEL32V(obj, message)) {
- case SCI_K_HOME: mover = 8; break;
- case SCI_K_UP: mover = 1; break;
- case SCI_K_PGUP: mover = 2; break;
- case SCI_K_LEFT: mover = 7; break;
+ case SCI_K_HOME:
+ mover = 8;
+ break;
+ case SCI_K_UP:
+ mover = 1;
+ break;
+ case SCI_K_PGUP:
+ mover = 2;
+ break;
+ case SCI_K_LEFT:
+ mover = 7;
+ break;
case SCI_K_CENTER:
- case 76: mover = 0; break;
- case SCI_K_RIGHT: mover = 3; break;
- case SCI_K_END: mover = 6; break;
- case SCI_K_DOWN: mover = 5; break;
- case SCI_K_PGDOWN: mover = 4; break;
- default: break;
+ case 76:
+ mover = 0;
+ break;
+ case SCI_K_RIGHT:
+ mover = 3;
+ break;
+ case SCI_K_END:
+ mover = 6;
+ break;
+ case SCI_K_DOWN:
+ mover = 5;
+ break;
+ case SCI_K_PGDOWN:
+ mover = 4;
+ break;
+ default:
+ break;
}
if (mover >= 0) {
@@ -186,8 +208,7 @@ kMapKeyToDir(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kGlobalToLocal(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kGlobalToLocal(state_t *s, int funct_nr, int argc, reg_t *argv) {
reg_t obj = argc ? argv[0] : NULL_REG; /* Can this really happen? Lars */
if (obj.segment) {
@@ -204,8 +225,7 @@ kGlobalToLocal(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kLocalToGlobal(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kLocalToGlobal(state_t *s, int funct_nr, int argc, reg_t *argv) {
reg_t obj = argc ? argv[0] : NULL_REG; /* Can this really happen? Lars */
if (obj.segment) {
@@ -220,8 +240,7 @@ kLocalToGlobal(state_t *s, int funct_nr, int argc, reg_t *argv)
}
reg_t /* Not implemented */
-kJoystick(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kJoystick(state_t *s, int funct_nr, int argc, reg_t *argv) {
SCIkdebug(SCIkSTUB, "Unimplemented syscall 'Joystick()'\n", funct_nr);
return NULL_REG;
}
diff --git a/engines/sci/engine/kfile.cpp b/engines/sci/engine/kfile.cpp
index 9c4235852f..2dd7a4478a 100644
--- a/engines/sci/engine/kfile.cpp
+++ b/engines/sci/engine/kfile.cpp
@@ -58,8 +58,7 @@ static struct _savegame_index_struct {
** Otherwise, the new file is then opened for reading or writing.
*/
static FILE *
-f_open_mirrored(state_t *s, char *fname)
-{
+f_open_mirrored(state_t *s, char *fname) {
int fd;
char *buf = NULL;
int fsize;
@@ -91,7 +90,7 @@ f_open_mirrored(state_t *s, char *fname)
if (!IS_VALID_FD(fd) && buf) {
free(buf);
sciprintf("kfile.c: f_open_mirrored(): Warning: Could not create '%s' in '%s' (%d bytes to copy)\n",
- fname, s->work_dir, fsize);
+ fname, s->work_dir, fsize);
return NULL;
}
@@ -100,7 +99,7 @@ f_open_mirrored(state_t *s, char *fname)
ret = write(fd, buf, fsize);
if (ret < fsize) {
sciprintf("kfile.c: f_open_mirrored(): Warning: Could not write all %ld bytes to '%s' in '%s' (only wrote %ld)\n",
- (long)fsize, fname, s->work_dir, ret);
+ (long)fsize, fname, s->work_dir, ret);
}
free(buf);
@@ -118,8 +117,7 @@ f_open_mirrored(state_t *s, char *fname)
void
-file_open(state_t *s, char *filename, int mode)
-{
+file_open(state_t *s, char *filename, int mode) {
int retval = 1; /* Ignore file_handles[0] */
FILE *file = NULL;
@@ -138,8 +136,8 @@ file_open(state_t *s, char *filename, int mode)
}
if ((!file) && ((mode == _K_FILE_MODE_OPEN_OR_CREATE) || (mode == _K_FILE_MODE_CREATE))) {
- file = sci_fopen(filename, "w" FO_BINARY "+"); /* Attempt to create file */
- SCIkdebug(SCIkFILE, "Creating file %s with mode %d\n", filename, mode);
+ file = sci_fopen(filename, "w" FO_BINARY "+"); /* Attempt to create file */
+ SCIkdebug(SCIkFILE, "Creating file %s with mode %d\n", filename, mode);
}
if (!file) { /* Failed */
SCIkdebug(SCIkFILE, "file_open() failed\n");
@@ -159,43 +157,39 @@ file_open(state_t *s, char *filename, int mode)
}
reg_t
-kFOpen(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
- char *name = kernel_dereference_char_pointer(s, argv[0], 0);
- int mode = UKPV(1);
+kFOpen(state_t *s, int funct_nr, int argc, reg_t *argv) {
+ char *name = kernel_dereference_char_pointer(s, argv[0], 0);
+ int mode = UKPV(1);
- file_open(s, name, mode);
- return s->r_acc;
+ file_open(s, name, mode);
+ return s->r_acc;
}
-void file_close(state_t *s, int handle)
-{
- SCIkdebug(SCIkFILE, "Closing file %d\n", handle);
+void file_close(state_t *s, int handle) {
+ SCIkdebug(SCIkFILE, "Closing file %d\n", handle);
- if (handle == 0) {
- SCIkwarn(SCIkERROR, "Attempt to close file handle 0\n");
- return;
- }
+ if (handle == 0) {
+ SCIkwarn(SCIkERROR, "Attempt to close file handle 0\n");
+ return;
+ }
- if ((handle >= s->file_handles_nr) || (s->file_handles[handle] == NULL)) {
- SCIkwarn(SCIkERROR, "Attempt to close invalid/unused file handle %d\n", handle);
- return;
- }
+ if ((handle >= s->file_handles_nr) || (s->file_handles[handle] == NULL)) {
+ SCIkwarn(SCIkERROR, "Attempt to close invalid/unused file handle %d\n", handle);
+ return;
+ }
- fclose(s->file_handles[handle]);
+ fclose(s->file_handles[handle]);
- s->file_handles[handle] = NULL;
+ s->file_handles[handle] = NULL;
}
reg_t
-kFClose(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
- file_close(s, UKPV(0));
- return s->r_acc;
+kFClose(state_t *s, int funct_nr, int argc, reg_t *argv) {
+ file_close(s, UKPV(0));
+ return s->r_acc;
}
-void fputs_wrapper(state_t *s, int handle, int size, char *data)
-{
+void fputs_wrapper(state_t *s, int handle, int size, char *data) {
SCIkdebug(SCIkFILE, "FPuts'ing \"%s\" to handle %d\n", data, handle);
if (handle == 0) {
@@ -211,26 +205,24 @@ void fputs_wrapper(state_t *s, int handle, int size, char *data)
fwrite(data, 1, size, s->file_handles[handle]);
}
-void fwrite_wrapper(state_t *s, int handle, char *data, int length)
-{
- SCIkdebug(SCIkFILE, "fwrite()'ing \"%s\" to handle %d\n", data, handle);
+void fwrite_wrapper(state_t *s, int handle, char *data, int length) {
+ SCIkdebug(SCIkFILE, "fwrite()'ing \"%s\" to handle %d\n", data, handle);
- if (handle == 0) {
- SCIkwarn(SCIkERROR, "Attempt to write to file handle 0\n");
- return;
- }
+ if (handle == 0) {
+ SCIkwarn(SCIkERROR, "Attempt to write to file handle 0\n");
+ return;
+ }
- if ((handle >= s->file_handles_nr) || (s->file_handles[handle] == NULL)) {
- SCIkwarn(SCIkERROR, "Attempt to write to invalid/unused file handle %d\n", handle);
- return;
- }
+ if ((handle >= s->file_handles_nr) || (s->file_handles[handle] == NULL)) {
+ SCIkwarn(SCIkERROR, "Attempt to write to invalid/unused file handle %d\n", handle);
+ return;
+ }
- fwrite(data, 1, length, s->file_handles[handle]);
+ fwrite(data, 1, length, s->file_handles[handle]);
}
-reg_t kFPuts(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+reg_t kFPuts(state_t *s, int funct_nr, int argc, reg_t *argv) {
int handle = UKPV(0);
char *data = kernel_dereference_char_pointer(s, argv[1], 0);
@@ -239,75 +231,71 @@ reg_t kFPuts(state_t *s, int funct_nr, int argc, reg_t *argv)
}
static void
-fgets_wrapper(state_t *s, char *dest, int maxsize, int handle)
-{
- SCIkdebug(SCIkFILE, "FGets'ing %d bytes from handle %d\n", maxsize, handle);
+fgets_wrapper(state_t *s, char *dest, int maxsize, int handle) {
+ SCIkdebug(SCIkFILE, "FGets'ing %d bytes from handle %d\n", maxsize, handle);
- if (handle == 0) {
- SCIkwarn(SCIkERROR, "Attempt to read from file handle 0\n");
- return;
- }
+ if (handle == 0) {
+ SCIkwarn(SCIkERROR, "Attempt to read from file handle 0\n");
+ return;
+ }
- if ((handle >= s->file_handles_nr) || (s->file_handles[handle] == NULL)) {
- SCIkwarn(SCIkERROR, "Attempt to read from invalid/unused file handle %d\n", handle);
- return;
- }
+ if ((handle >= s->file_handles_nr) || (s->file_handles[handle] == NULL)) {
+ SCIkwarn(SCIkERROR, "Attempt to read from invalid/unused file handle %d\n", handle);
+ return;
+ }
- fgets(dest, maxsize, s->file_handles[handle]);
+ fgets(dest, maxsize, s->file_handles[handle]);
- SCIkdebug(SCIkFILE, "FGets'ed \"%s\"\n", dest);
+ SCIkdebug(SCIkFILE, "FGets'ed \"%s\"\n", dest);
}
static void
-fread_wrapper(state_t *s, char *dest, int bytes, int handle)
-{
- SCIkdebug(SCIkFILE, "fread()'ing %d bytes from handle %d\n", bytes, handle);
+fread_wrapper(state_t *s, char *dest, int bytes, int handle) {
+ SCIkdebug(SCIkFILE, "fread()'ing %d bytes from handle %d\n", bytes, handle);
- if (handle == 0) {
- SCIkwarn(SCIkERROR, "Attempt to read from file handle 0\n");
- return;
- }
+ if (handle == 0) {
+ SCIkwarn(SCIkERROR, "Attempt to read from file handle 0\n");
+ return;
+ }
- if ((handle >= s->file_handles_nr) || (s->file_handles[handle] == NULL)) {
- SCIkwarn(SCIkERROR, "Attempt to read from invalid/unused file handle %d\n", handle);
- return;
- }
+ if ((handle >= s->file_handles_nr) || (s->file_handles[handle] == NULL)) {
+ SCIkwarn(SCIkERROR, "Attempt to read from invalid/unused file handle %d\n", handle);
+ return;
+ }
- s->r_acc=make_reg(0,fread(dest, 1, bytes, s->file_handles[handle]));
+ s->r_acc = make_reg(0, fread(dest, 1, bytes, s->file_handles[handle]));
}
static void
-fseek_wrapper(state_t *s, int handle, int offset, int whence)
-{
+fseek_wrapper(state_t *s, int handle, int offset, int whence) {
- if (handle == 0) {
- SCIkwarn(SCIkERROR, "Attempt seek on file handle 0\n");
- return;
- }
+ if (handle == 0) {
+ SCIkwarn(SCIkERROR, "Attempt seek on file handle 0\n");
+ return;
+ }
- if ((handle >= s->file_handles_nr) || (s->file_handles[handle] == NULL)) {
- SCIkwarn(SCIkERROR, "Attempt seek on invalid/unused file handle %d\n", handle);
- return;
- }
+ if ((handle >= s->file_handles_nr) || (s->file_handles[handle] == NULL)) {
+ SCIkwarn(SCIkERROR, "Attempt seek on invalid/unused file handle %d\n", handle);
+ return;
+ }
- s->r_acc=make_reg(0, fseek(s->file_handles[handle], offset, whence));
+ s->r_acc = make_reg(0, fseek(s->file_handles[handle], offset, whence));
}
static char *
-_chdir_savedir(state_t *s)
-{
+_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);
+ 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);
+ "create it\n", save_dir);
sci_free(cwd);
return NULL;
@@ -320,11 +308,10 @@ _chdir_savedir(state_t *s)
}
static void
-_chdir_restoredir(char *dir)
-{
+_chdir_restoredir(char *dir) {
if (chdir(dir)) {
sciprintf(__FILE__": Can't seem to return to previous homedir '%s'\n",
- dir);
+ dir);
}
free(dir);
}
@@ -332,14 +319,13 @@ _chdir_restoredir(char *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)
-{
- char *dest = kernel_dereference_char_pointer(s, argv[0], 0);
- int maxsize = UKPV(1);
- int handle = UKPV(2);
+kFGets(state_t *s, int funct_nr, int argc, reg_t *argv) {
+ char *dest = kernel_dereference_char_pointer(s, argv[0], 0);
+ int maxsize = UKPV(1);
+ int handle = UKPV(2);
- fgets_wrapper(s, dest, maxsize, handle);
- return argv[0];
+ fgets_wrapper(s, dest, maxsize, handle);
+ return argv[0];
}
@@ -347,8 +333,7 @@ kFGets(state_t *s, int funct_nr, int argc, reg_t *argv)
** Writes the cwd to the supplied address and returns the address in acc.
*/
reg_t
-kGetCWD(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kGetCWD(state_t *s, int funct_nr, int argc, reg_t *argv) {
char *wd = sci_getcwd();
char *targetaddr = kernel_dereference_char_pointer(s, argv[0], 0);
@@ -356,7 +341,7 @@ kGetCWD(state_t *s, int funct_nr, int argc, reg_t *argv)
targetaddr[MAX_SAVE_DIR_SIZE - 1] = 0; /* Terminate */
SCIkdebug(SCIkFILE, "Copying cwd='%s'(%d chars) to %p",
- wd, strlen(wd), targetaddr);
+ wd, strlen(wd), targetaddr);
free(wd);
return argv[0];
@@ -364,8 +349,7 @@ kGetCWD(state_t *s, int funct_nr, int argc, reg_t *argv)
/* Returns a dynamically allocated pointer to the name of the requested save dir */
char *
-_k_get_savedir_name(int nr)
-{
+_k_get_savedir_name(int nr) {
char suffices[] = "0123456789abcdefghijklmnopqrstuvwxyz";
char *savedir_name = (char*)sci_malloc(strlen(FREESCI_SAVEDIR_PREFIX) + 2);
assert(nr >= 0);
@@ -378,8 +362,7 @@ _k_get_savedir_name(int nr)
}
void
-delete_savegame(state_t *s, int savedir_nr)
-{
+delete_savegame(state_t *s, int savedir_nr) {
char *workdir = _chdir_savedir(s);
char *savedir = _k_get_savedir_name(savedir_nr);
char buffer[256];
@@ -397,7 +380,7 @@ delete_savegame(state_t *s, int savedir_nr)
free(savedir);
_chdir_restoredir(workdir);
}
-
+
#define K_DEVICE_INFO_GET_DEVICE 0
#define K_DEVICE_INFO_GET_CURRENT_DEVICE 1
#define K_DEVICE_INFO_PATHS_EQUAL 2
@@ -408,62 +391,61 @@ delete_savegame(state_t *s, int savedir_nr)
#ifdef WIN32
reg_t
-kDeviceInfo_Win32(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kDeviceInfo_Win32(state_t *s, int funct_nr, int argc, reg_t *argv) {
char dir_buffer[MAXPATHLEN], dir_buffer2[MAXPATHLEN];
int mode = UKPV(0);
- switch(mode) {
+ switch (mode) {
case K_DEVICE_INFO_GET_DEVICE: {
char *input_s = (char*)kernel_dereference_bulk_pointer(s, argv[1], 0);
char *output_s = (char*)kernel_dereference_bulk_pointer(s, argv[2], 0);
- GetFullPathName (input_s, sizeof (dir_buffer)-1, dir_buffer, NULL);
+ GetFullPathName(input_s, sizeof(dir_buffer) - 1, dir_buffer, NULL);
strncpy(output_s, dir_buffer, 2);
output_s [2] = 0;
}
- break;
+ break;
case K_DEVICE_INFO_GET_CURRENT_DEVICE: {
char *output_s = (char*)kernel_dereference_bulk_pointer(s, argv[1], 0);
- _getcwd (dir_buffer, sizeof (dir_buffer)-1);
+ _getcwd(dir_buffer, sizeof(dir_buffer) - 1);
strncpy(output_s, dir_buffer, 2);
output_s [2] = 0;
}
- break;
+ break;
case K_DEVICE_INFO_PATHS_EQUAL: {
char *path1_s = (char*)kernel_dereference_bulk_pointer(s, argv[1], 0);
char *path2_s = (char*)kernel_dereference_bulk_pointer(s, argv[2], 0);
- GetFullPathName (path1_s, sizeof (dir_buffer)-1, dir_buffer, NULL);
- GetFullPathName (path2_s, sizeof (dir_buffer2)-1, dir_buffer2, NULL);
+ GetFullPathName(path1_s, sizeof(dir_buffer) - 1, dir_buffer, NULL);
+ GetFullPathName(path2_s, sizeof(dir_buffer2) - 1, dir_buffer2, NULL);
#ifdef _MSC_VER
- return make_reg(0, !stricmp (path1_s, path2_s));
+ return make_reg(0, !stricmp(path1_s, path2_s));
#else
- return make_reg(0, !strcasecmp (path1_s, path2_s));
+ return make_reg(0, !strcasecmp(path1_s, path2_s));
#endif
}
- break;
+ break;
case K_DEVICE_INFO_IS_FLOPPY: {
char *input_s = (char*)kernel_dereference_bulk_pointer(s, argv[1], 0);
- GetFullPathName (input_s, sizeof (dir_buffer)-1, dir_buffer, NULL);
+ GetFullPathName(input_s, sizeof(dir_buffer) - 1, dir_buffer, NULL);
dir_buffer [3] = 0; /* leave X:\ */
- return make_reg(0, GetDriveType (dir_buffer) == DRIVE_REMOVABLE);
+ return make_reg(0, GetDriveType(dir_buffer) == DRIVE_REMOVABLE);
}
- break;
+ break;
-/* SCI uses these in a less-than-portable way to delete savegames.
-** Read http://www-plan.cs.colorado.edu/creichen/freesci-logs/2005.10/log20051019.html
-** for more information on our workaround for this.
-*/
+ /* SCI uses these in a less-than-portable way to delete savegames.
+ ** Read http://www-plan.cs.colorado.edu/creichen/freesci-logs/2005.10/log20051019.html
+ ** for more information on our workaround for this.
+ */
case K_DEVICE_INFO_GET_SAVECAT_NAME: {
char *output_buffer = kernel_dereference_char_pointer(s, argv[1], 0);
char *game_prefix = kernel_dereference_char_pointer(s, argv[2], 0);
@@ -471,7 +453,7 @@ kDeviceInfo_Win32(state_t *s, int funct_nr, int argc, reg_t *argv)
sprintf(output_buffer, "%s/__throwaway", s->work_dir);
}
- break;
+ break;
case K_DEVICE_INFO_GET_SAVEFILE_NAME: {
char *output_buffer = kernel_dereference_char_pointer(s, argv[1], 0);
char *game_prefix = kernel_dereference_char_pointer(s, argv[2], 0);
@@ -479,7 +461,7 @@ kDeviceInfo_Win32(state_t *s, int funct_nr, int argc, reg_t *argv)
sprintf(output_buffer, "%s/__throwaway", s->work_dir);
delete_savegame(s, savegame_id);
}
- break;
+ break;
default: {
SCIkwarn(SCIkERROR, "Unknown DeviceInfo() sub-command: %d\n", mode);
}
@@ -490,25 +472,24 @@ kDeviceInfo_Win32(state_t *s, int funct_nr, int argc, reg_t *argv)
#else /* !WIN32 */
reg_t
-kDeviceInfo_Unix(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kDeviceInfo_Unix(state_t *s, int funct_nr, int argc, reg_t *argv) {
int mode = UKPV(0);
- switch(mode) {
+ switch (mode) {
case K_DEVICE_INFO_GET_DEVICE: {
char *output_s = kernel_dereference_char_pointer(s, argv[2], 0);
strcpy(output_s, "/");
}
- break;
+ break;
case K_DEVICE_INFO_GET_CURRENT_DEVICE: {
char *output_s = kernel_dereference_char_pointer(s, argv[1], 0);
strcpy(output_s, "/");
}
- break;
+ break;
case K_DEVICE_INFO_PATHS_EQUAL: {
char *path1_s = kernel_dereference_char_pointer(s, argv[1], 0);
@@ -516,35 +497,35 @@ kDeviceInfo_Unix(state_t *s, int funct_nr, int argc, reg_t *argv)
//return make_reg(0, !strcmp(path1_s, path2_s));
return make_reg(0, Common::matchString(path2_s, path1_s, true));
- }
- break;
+ }
+ break;
case K_DEVICE_INFO_IS_FLOPPY: {
return NULL_REG; /* Never */
}
- break;
+ break;
-/* SCI uses these in a less-than-portable way to delete savegames.
-** Read http://www-plan.cs.colorado.edu/creichen/freesci-logs/2005.10/log20051019.html
-** for more information on our workaround for this.
-*/
+ /* SCI uses these in a less-than-portable way to delete savegames.
+ ** Read http://www-plan.cs.colorado.edu/creichen/freesci-logs/2005.10/log20051019.html
+ ** for more information on our workaround for this.
+ */
case K_DEVICE_INFO_GET_SAVECAT_NAME: {
char *output_buffer = kernel_dereference_char_pointer(s, argv[1], 0);
-/* char *game_prefix = kernel_dereference_char_pointer(s, argv[2], 0);*/
+ /* char *game_prefix = kernel_dereference_char_pointer(s, argv[2], 0);*/
sprintf(output_buffer, "%s/__throwaway", s->work_dir);
}
- break;
+ break;
case K_DEVICE_INFO_GET_SAVEFILE_NAME: {
char *output_buffer = kernel_dereference_char_pointer(s, argv[1], 0);
-/* char *game_prefix = kernel_dereference_char_pointer(s, argv[2], 0);*/
+ /* char *game_prefix = kernel_dereference_char_pointer(s, argv[2], 0);*/
int savegame_id = UKPV(3);
sprintf(output_buffer, "%s/__throwaway", s->work_dir);
delete_savegame(s, savegame_id);
}
- break;
+ break;
default: {
SCIkwarn(SCIkERROR, "Unknown DeviceInfo() sub-command: %d\n", mode);
}
@@ -557,81 +538,77 @@ kDeviceInfo_Unix(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kGetSaveDir(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kGetSaveDir(state_t *s, int funct_nr, int argc, reg_t *argv) {
return make_reg(s->sys_strings_segment, SYS_STRING_SAVEDIR);
}
reg_t
-kCheckFreeSpace(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
- char *path = kernel_dereference_char_pointer(s, argv[0], 0);
- char *testpath = (char*)sci_malloc(strlen(path) + 15);
- char buf[1024];
- int fd;
- int failed = 0;
- int pathlen;
-
- strcpy(testpath, path);
- strcat(testpath, "freesci.foo");
- pathlen = strlen(testpath);
-
- while (IS_VALID_FD(fd = open(testpath, O_RDONLY))) {
- close(fd);
- if (testpath[pathlen - 2] == 'z') { /* Failed. */
- SCIkwarn(SCIkWARNING, "Failed to find non-existing file for free space test\n");
- free(testpath);
- return NULL_REG;
- }
-
- /* If this file couldn't be created, try freesci.fop, freesci.foq etc.,
- ** then freesci.fpa, freesci.fpb. Stop at freesci.fza.
- ** Yes, this is extremely arbitrary and very strange.
- */
- if (testpath[pathlen - 1] == 'z') {
- testpath[pathlen - 1] = 'a';
- ++testpath[pathlen - 2];
- }
- else
- ++testpath[pathlen - 1];
- }
-
- fd = creat(testpath, 0600);
-
- if (!IS_VALID_FD(fd)) {
- SCIkwarn(SCIkWARNING,"Could not test for disk space: %s\n", strerror(errno));
- SCIkwarn(SCIkWARNING,"Test path was '%s'\n", testpath);
- free(testpath);
- return NULL_REG;
- }
-
- memset(buf, 0, sizeof(buf));
- for (int i = 0; i < 1024; i++) /* Check for 1 MB */
- if (write(fd, buf, 1024) < 1024)
- failed = 1;
-
- close(fd);
-
- remove(testpath);
-
- sci_free(testpath);
-
- return make_reg(0, !failed);
+kCheckFreeSpace(state_t *s, int funct_nr, int argc, reg_t *argv) {
+ char *path = kernel_dereference_char_pointer(s, argv[0], 0);
+ char *testpath = (char*)sci_malloc(strlen(path) + 15);
+ char buf[1024];
+ int fd;
+ int failed = 0;
+ int pathlen;
+
+ strcpy(testpath, path);
+ strcat(testpath, "freesci.foo");
+ pathlen = strlen(testpath);
+
+ while (IS_VALID_FD(fd = open(testpath, O_RDONLY))) {
+ close(fd);
+ if (testpath[pathlen - 2] == 'z') { /* Failed. */
+ SCIkwarn(SCIkWARNING, "Failed to find non-existing file for free space test\n");
+ free(testpath);
+ return NULL_REG;
+ }
+
+ /* If this file couldn't be created, try freesci.fop, freesci.foq etc.,
+ ** then freesci.fpa, freesci.fpb. Stop at freesci.fza.
+ ** Yes, this is extremely arbitrary and very strange.
+ */
+ if (testpath[pathlen - 1] == 'z') {
+ testpath[pathlen - 1] = 'a';
+ ++testpath[pathlen - 2];
+ } else
+ ++testpath[pathlen - 1];
+ }
+
+ fd = creat(testpath, 0600);
+
+ if (!IS_VALID_FD(fd)) {
+ SCIkwarn(SCIkWARNING, "Could not test for disk space: %s\n", strerror(errno));
+ SCIkwarn(SCIkWARNING, "Test path was '%s'\n", testpath);
+ free(testpath);
+ return NULL_REG;
+ }
+
+ memset(buf, 0, sizeof(buf));
+ for (int i = 0; i < 1024; i++) /* Check for 1 MB */
+ if (write(fd, buf, 1024) < 1024)
+ failed = 1;
+
+ close(fd);
+
+ remove(testpath);
+
+ sci_free(testpath);
+
+ return make_reg(0, !failed);
}
int
_k_check_file(char *filename, int minfilesize)
- /* Returns 0 if the file exists and is big enough */
+/* Returns 0 if the file exists and is big enough */
{
return (sci_file_size(filename) < minfilesize);
}
int
-_k_find_savegame_by_name(char *game_id_file, char *name)
-{
+_k_find_savegame_by_name(char *game_id_file, char *name) {
int savedir_nr = -1;
int i;
char *buf = NULL;
@@ -664,8 +641,7 @@ _k_find_savegame_by_name(char *game_id_file, char *name)
#ifdef __DC__
static long
-get_file_mtime(int fd)
-{
+get_file_mtime(int fd) {
/* FIXME (Dreamcast): Not yet implemented */
return 0;
}
@@ -685,8 +661,7 @@ get_file_mtime(int fd)
*/
static long
-get_file_mtime_Unix(int fd) /* returns the */
-{
+get_file_mtime_Unix(int fd) { /* returns the */
struct stat fd_stat;
fstat(fd, &fd_stat);
@@ -695,15 +670,13 @@ get_file_mtime_Unix(int fd) /* returns the */
#endif
static int
-_savegame_index_struct_compare(const void *a, const void *b)
-{
+_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)->timestamp;
}
static void
-update_savegame_indices(const char *gfname)
-{
+update_savegame_indices(const char *gfname) {
int i;
_savegame_indices_nr = 0;
@@ -731,8 +704,7 @@ update_savegame_indices(const char *gfname)
}
int
-test_savegame(state_t *s, char *savegame_id, char *savegame_name, int savegame_name_length)
-{
+test_savegame(state_t *s, char *savegame_id, char *savegame_name, int savegame_name_length) {
FILE *f;
char buffer[80];
int version = -1;
@@ -741,12 +713,10 @@ test_savegame(state_t *s, char *savegame_id, char *savegame_name, int savegame_n
f = fopen("state", "r");
if (!f) return 0;
- while (!feof(f))
- {
+ while (!feof(f)) {
char *seeker;
fgets(buffer, sizeof(buffer), f);
- if ((seeker = strstr(buffer, "savegame_version = ")) != NULL)
- {
+ if ((seeker = strstr(buffer, "savegame_version = ")) != NULL) {
seeker += strlen("savegame_version = ");
version = strtol(seeker, NULL, 10);
break;
@@ -759,8 +729,7 @@ test_savegame(state_t *s, char *savegame_id, char *savegame_name, int savegame_n
}
reg_t
-kCheckSaveGame(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kCheckSaveGame(state_t *s, int funct_nr, int argc, reg_t *argv) {
char *game_id = kernel_dereference_char_pointer(s, argv[0], 0);
int savedir_nr = UKPV(1);
char *buf = NULL;
@@ -779,7 +748,7 @@ kCheckSaveGame(state_t *s, int funct_nr, int argc, reg_t *argv)
savedir_nr = _savegame_indices[savedir_nr].id;
- if (savedir_nr > MAX_SAVEGAME_NR-1) {
+ if (savedir_nr > MAX_SAVEGAME_NR - 1) {
_chdir_restoredir(workdir);
return NULL_REG;
}
@@ -794,8 +763,7 @@ kCheckSaveGame(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kGetSaveFiles(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kGetSaveFiles(state_t *s, int funct_nr, int argc, reg_t *argv) {
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];
@@ -822,7 +790,7 @@ kGetSaveFiles(state_t *s, int funct_nr, int argc, reg_t *argv)
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);
+ fgets(namebuf, SCI_MAX_SAVENAME_LENGTH - 1, idfile);
if (strlen(namebuf) > 0) {
if (namebuf[strlen(namebuf) - 1] == '\n')
@@ -853,8 +821,7 @@ kGetSaveFiles(state_t *s, int funct_nr, int argc, reg_t *argv)
}
reg_t
-kSaveGame(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+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;
int savedir_nr = UKPV(1);
@@ -889,7 +856,7 @@ kSaveGame(state_t *s, int funct_nr, int argc, reg_t *argv)
if (savedir_id >= MAX_SAVEGAME_NR) {
sciprintf("Internal error: Free savegame ID is %d, shouldn't happen!\n",
- savedir_id);
+ savedir_id);
return NULL_REG;
}
@@ -920,7 +887,7 @@ kSaveGame(state_t *s, int funct_nr, int argc, reg_t *argv)
s->r_acc = NULL_REG;
}
- chdir ("..");
+ chdir("..");
s->r_acc = make_reg(0, 1);
}
free(game_id_file_name);
@@ -933,8 +900,7 @@ 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)
-{
+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);
@@ -980,8 +946,7 @@ kRestoreGame(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kValidPath(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kValidPath(state_t *s, int funct_nr, int argc, reg_t *argv) {
char *pathname = kernel_dereference_char_pointer(s, argv[0], 0);
char cpath[MAXPATHLEN + 1];
getcwd(cpath, MAXPATHLEN + 1);
@@ -1007,8 +972,7 @@ kValidPath(state_t *s, int funct_nr, int argc, reg_t *argv)
char *
-write_filename_to_mem(state_t *s, reg_t address, char *string)
-{
+write_filename_to_mem(state_t *s, reg_t address, char *string) {
char *mem = kernel_dereference_char_pointer(s, address, 0);
if (string) {
@@ -1020,28 +984,26 @@ write_filename_to_mem(state_t *s, reg_t address, char *string)
}
void
-next_file(state_t *s)
-{
+next_file(state_t *s) {
if (write_filename_to_mem(s, s->dirseeker_outbuffer,
- sci_find_next(&(s->dirseeker))))
+ sci_find_next(&(s->dirseeker))))
s->r_acc = s->dirseeker_outbuffer;
else
s->r_acc = NULL_REG;
}
void
-first_file(state_t *s, const char *dir, char *mask, reg_t buffer)
-{
+first_file(state_t *s, const char *dir, char *mask, reg_t buffer) {
if (!buffer.segment) {
sciprintf("Warning: first_file(state,\"%s\",\"%s\", 0) invoked!\n",
- dir, mask);
+ dir, mask);
s->r_acc = NULL_REG;
return;
}
if (strcmp(dir, ".")) {
sciprintf("%s L%d: Non-local first_file: Not implemented yet\n",
- __FILE__, __LINE__);
+ __FILE__, __LINE__);
s->r_acc = NULL_REG;
return;
}
@@ -1053,114 +1015,102 @@ first_file(state_t *s, const char *dir, char *mask, reg_t buffer)
s->dirseeker_outbuffer = buffer;
if (write_filename_to_mem(s, s->dirseeker_outbuffer,
- sci_find_first(&(s->dirseeker), mask)))
+ sci_find_first(&(s->dirseeker), mask)))
s->r_acc = s->dirseeker_outbuffer;
else
s->r_acc = NULL_REG;
}
reg_t
-kFileIO(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
- int func_nr = UKPV(0);
+kFileIO(state_t *s, int funct_nr, int argc, reg_t *argv) {
+ int func_nr = UKPV(0);
- switch (func_nr) {
+ switch (func_nr) {
- case K_FILEIO_OPEN :
- {
- char *name = kernel_dereference_char_pointer(s, argv[1], 0);
- int mode = UKPV(2);
+ case K_FILEIO_OPEN : {
+ char *name = kernel_dereference_char_pointer(s, argv[1], 0);
+ int mode = UKPV(2);
- file_open(s, name, mode);
- break;
- }
- case K_FILEIO_CLOSE :
- {
- int handle = UKPV(1);
+ file_open(s, name, mode);
+ break;
+ }
+ case K_FILEIO_CLOSE : {
+ int handle = UKPV(1);
- file_close(s, handle);
- break;
- }
- case K_FILEIO_READ_RAW :
- {
- int handle = UKPV(1);
- char *dest = kernel_dereference_char_pointer(s, argv[2], 0);
- int size = UKPV(3);
-
- fread_wrapper(s, dest, size, handle);
- break;
- }
- case K_FILEIO_WRITE_RAW :
- {
- int handle = UKPV(1);
- char *buf = kernel_dereference_char_pointer(s, argv[2], 0);
- int size = UKPV(3);
-
- fwrite_wrapper(s, handle, buf, size);
- break;
- }
- case K_FILEIO_UNLINK :
- {
- char *name = kernel_dereference_char_pointer(s, argv[1], 0);
+ file_close(s, handle);
+ break;
+ }
+ case K_FILEIO_READ_RAW : {
+ int handle = UKPV(1);
+ char *dest = kernel_dereference_char_pointer(s, argv[2], 0);
+ int size = UKPV(3);
- unlink(name);
- break;
- }
- case K_FILEIO_READ_STRING :
- {
- char *dest = kernel_dereference_char_pointer(s, argv[1], 0);
- int size = UKPV(2);
- int handle = UKPV(3);
-
- fgets_wrapper(s, dest, size, handle);
- return argv[1];
- }
- case K_FILEIO_WRITE_STRING :
- {
- int handle = UKPV(1);
- int size = UKPV(3);
- char *buf = kernel_dereference_char_pointer(s, argv[2], size);
-
- if (buf)
- fputs_wrapper(s, handle, size, buf);
- break;
- }
- case K_FILEIO_SEEK :
- {
- int handle = UKPV(1);
- int offset = UKPV(2);
- int whence = UKPV(3);
-
- fseek_wrapper(s, handle, offset, whence);
- break;
- }
- case K_FILEIO_FIND_FIRST :
- {
- char *mask = kernel_dereference_char_pointer(s, argv[1], 0);
- reg_t buf = argv[2];
- /* int attr = UKPV(3); */ /* We won't use this, Win32 might, though... */
+ fread_wrapper(s, dest, size, handle);
+ break;
+ }
+ case K_FILEIO_WRITE_RAW : {
+ int handle = UKPV(1);
+ char *buf = kernel_dereference_char_pointer(s, argv[2], 0);
+ int size = UKPV(3);
+
+ fwrite_wrapper(s, handle, buf, size);
+ break;
+ }
+ case K_FILEIO_UNLINK : {
+ char *name = kernel_dereference_char_pointer(s, argv[1], 0);
+
+ unlink(name);
+ break;
+ }
+ case K_FILEIO_READ_STRING : {
+ char *dest = kernel_dereference_char_pointer(s, argv[1], 0);
+ int size = UKPV(2);
+ int handle = UKPV(3);
+
+ fgets_wrapper(s, dest, size, handle);
+ return argv[1];
+ }
+ case K_FILEIO_WRITE_STRING : {
+ int handle = UKPV(1);
+ int size = UKPV(3);
+ char *buf = kernel_dereference_char_pointer(s, argv[2], size);
+
+ if (buf)
+ fputs_wrapper(s, handle, size, buf);
+ break;
+ }
+ case K_FILEIO_SEEK : {
+ int handle = UKPV(1);
+ int offset = UKPV(2);
+ int whence = UKPV(3);
+
+ fseek_wrapper(s, handle, offset, whence);
+ break;
+ }
+ case K_FILEIO_FIND_FIRST : {
+ char *mask = kernel_dereference_char_pointer(s, argv[1], 0);
+ reg_t buf = argv[2];
+ /* int attr = UKPV(3); */ /* We won't use this, Win32 might, though... */
#ifndef WIN32
- if (strcmp(mask, "*.*")==0) strcpy(mask, "*"); /* For UNIX */
+ if (strcmp(mask, "*.*") == 0) strcpy(mask, "*"); /* For UNIX */
#endif
- first_file(s, ".", mask, buf);
+ first_file(s, ".", mask, buf);
- break;
- }
- case K_FILEIO_FIND_NEXT :
- {
- next_file(s);
- break;
- }
- case K_FILEIO_STAT :
- {
- char *name = kernel_dereference_char_pointer(s, argv[1], 0);
- s->r_acc=make_reg(0, 1-_k_check_file(name, 0));
- break;
- }
- default :
- SCIkwarn(SCIkERROR, "Unknown FileIO() sub-command: %d\n", func_nr);
- }
+ break;
+ }
+ case K_FILEIO_FIND_NEXT : {
+ next_file(s);
+ break;
+ }
+ case K_FILEIO_STAT : {
+ char *name = kernel_dereference_char_pointer(s, argv[1], 0);
+ s->r_acc = make_reg(0, 1 - _k_check_file(name, 0));
+ break;
+ }
+ default :
+ SCIkwarn(SCIkERROR, "Unknown FileIO() sub-command: %d\n", func_nr);
+ }
- return s->r_acc;
+ return s->r_acc;
}
diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp
index 0d12e40d6f..a44e71637a 100644
--- a/engines/sci/engine/kgraphics.cpp
+++ b/engines/sci/engine/kgraphics.cpp
@@ -109,8 +109,7 @@
static inline int
-sign_extend_byte(int value)
-{
+sign_extend_byte(int value) {
if (value & 0x80)
return value - 256;
else
@@ -119,8 +118,7 @@ sign_extend_byte(int value)
static void
-assert_primary_widget_lists(state_t *s)
-{
+assert_primary_widget_lists(state_t *s) {
if (!s->dyn_views) {
rect_t bounds = s->picture_port->bounds;
@@ -139,8 +137,7 @@ assert_primary_widget_lists(state_t *s)
}
static void
-reparentize_primary_widget_lists(state_t *s, gfxw_port_t *newport)
-{
+reparentize_primary_widget_lists(state_t *s, gfxw_port_t *newport) {
if (!newport)
newport = s->picture_port;
@@ -152,10 +149,9 @@ reparentize_primary_widget_lists(state_t *s, gfxw_port_t *newport)
}
int
-_find_view_priority(state_t *s, int y)
-{
- /* if (s->version <= SCI_VERSION_LTU_PRIORITY_OB1)
- ++y; */
+_find_view_priority(state_t *s, int y) {
+ /* if (s->version <= SCI_VERSION_LTU_PRIORITY_OB1)
+ ++y; */
if (s->pic_priority_table) { /* SCI01 priority table set? */
int j;
@@ -163,19 +159,17 @@ _find_view_priority(state_t *s, int y)
if (y < s->pic_priority_table[j+1])
return j;
return 14; /* Maximum */
- } else
- {
+ } else {
if (s->version >= SCI_VERSION_FTU_PRIORITY_14_ZONES)
return SCI0_VIEW_PRIORITY_14_ZONES(y);
else
return SCI0_VIEW_PRIORITY(y) == 15 ? 14 :
- SCI0_VIEW_PRIORITY(y);
+ SCI0_VIEW_PRIORITY(y);
}
}
int
-_find_priority_band(state_t *s, int nr)
-{
+_find_priority_band(state_t *s, int nr) {
if (s->version >= SCI_VERSION_FTU_PRIORITY_14_ZONES && (nr < 0 || nr > 14)) {
if (nr == 15)
return 0xffff;
@@ -207,8 +201,7 @@ _find_priority_band(state_t *s, int nr)
}
reg_t
-graph_save_box(state_t *s, rect_t area)
-{
+graph_save_box(state_t *s, rect_t area) {
reg_t handle = kalloc(s, "graph_save_box()", sizeof(gfxw_snapshot_t *));
gfxw_snapshot_t **ptr = (gfxw_snapshot_t **) kmem(s, handle);
@@ -219,8 +212,7 @@ graph_save_box(state_t *s, rect_t area)
void
-graph_restore_box(state_t *s, reg_t handle)
-{
+graph_restore_box(state_t *s, reg_t handle) {
gfxw_snapshot_t **ptr;
int port_nr = s->port->ID;
@@ -237,7 +229,7 @@ graph_restore_box(state_t *s, reg_t handle)
}
while (port_nr > 2 && !(s->port->flags & GFXW_FLAG_IMMUNE_TO_SNAPSHOTS)
- &&(gfxw_widget_matches_snapshot(*ptr, GFXW(s->port)))) {
+ && (gfxw_widget_matches_snapshot(*ptr, GFXW(s->port)))) {
/* This shouldn't ever happen, actually, since windows (ports w/ ID > 2) should all be immune */
gfxw_port_t *newport = gfxw_find_port(s->visual, port_nr);
SCIkwarn(SCIkERROR, "Port %d is not immune against snapshots!\n", s->port->ID);
@@ -285,43 +277,39 @@ graph_restore_box(state_t *s, reg_t handle)
static gfx_pixmap_color_t white = {GFX_COLOR_INDEX_UNMAPPED, 255, 255, 255};
gfx_pixmap_color_t *
-get_pic_color(state_t *s, int color)
-{
- if (s->resmgr->sci_version < SCI_VERSION_01_VGA)
+get_pic_color(state_t *s, int color) {
+ if (s->resmgr->sci_version < SCI_VERSION_01_VGA)
return &(s->ega_colors[color].visual);
if (color == 255)
return &white;
else if (color < KERNEL_COLORS_NR)
- return &(KERNEL_COLOR_PALETTE[color]); else
- {
- SCIkwarn(SCIkERROR, "Color index %d out of bounds for pic %d (%d max)",
- color, s->gfx_state->pic_nr, KERNEL_COLORS_NR);
- BREAKPOINT();
- return NULL; /* Well, rather, not return. But gcc gets scared here. */
- }
+ return &(KERNEL_COLOR_PALETTE[color]);
+ else {
+ SCIkwarn(SCIkERROR, "Color index %d out of bounds for pic %d (%d max)",
+ color, s->gfx_state->pic_nr, KERNEL_COLORS_NR);
+ BREAKPOINT();
+ return NULL; /* Well, rather, not return. But gcc gets scared here. */
+ }
}
static gfx_color_t
-graph_map_color(state_t *s, int color, int priority, int control)
-{
+graph_map_color(state_t *s, int color, int priority, int control) {
gfx_color_t retval;
- if (s->resmgr->sci_version < SCI_VERSION_01_VGA)
- {
+ if (s->resmgr->sci_version < SCI_VERSION_01_VGA) {
retval = s->ega_colors[(color >=0 && color < 16)? color : 0];
- gfxop_set_color(s->gfx_state, &retval, (color < 0)? -1 : retval.visual.r, retval.visual.g, retval.visual.b,
- (color == -1)? 255 : 0, priority, control);
- } else
- {
+ gfxop_set_color(s->gfx_state, &retval, (color < 0) ? -1 : retval.visual.r, retval.visual.g, retval.visual.b,
+ (color == -1) ? 255 : 0, priority, control);
+ } else {
retval.visual = *(get_pic_color(s, color));
retval.alpha = 0;
retval.priority = priority;
retval.control = control;
- retval.mask =
- GFX_MASK_VISUAL |
- ((priority >= 0)? GFX_MASK_PRIORITY : 0) |
- ((control >= 0)? GFX_MASK_CONTROL : 0);
+ retval.mask =
+ GFX_MASK_VISUAL |
+ ((priority >= 0) ? GFX_MASK_PRIORITY : 0) |
+ ((control >= 0) ? GFX_MASK_CONTROL : 0);
};
return retval;
@@ -331,27 +319,21 @@ graph_map_color(state_t *s, int color, int priority, int control)
reg_t
-kSetCursor_SCI11(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
- switch (argc)
- {
+kSetCursor_SCI11(state_t *s, int funct_nr, int argc, reg_t *argv) {
+ switch (argc) {
case 1 :
- if (UKPV(0) == 0)
- {
+ if (UKPV(0) == 0) {
s->save_mouse_pointer_view = s->mouse_pointer_view;
s->save_mouse_pointer_loop = s->mouse_pointer_loop;
s->save_mouse_pointer_cel = s->mouse_pointer_cel;
s->mouse_pointer_view = s->mouse_pointer_loop = s->mouse_pointer_cel = -1;
gfxop_set_pointer_cursor(s->gfx_state, GFXOP_NO_POINTER);
- }
- else
- {
+ } else {
s->mouse_pointer_view = s->save_mouse_pointer_view;
s->mouse_pointer_loop = s->save_mouse_pointer_loop;
s->mouse_pointer_cel = s->save_mouse_pointer_cel;
}
- case 2 :
- {
+ case 2 : {
point_t pt;
pt.x = UKPV(0);
pt.y = UKPV(1);
@@ -360,14 +342,14 @@ kSetCursor_SCI11(state_t *s, int funct_nr, int argc, reg_t *argv)
break;
}
case 3 :
- GFX_ASSERT(gfxop_set_pointer_view(s->gfx_state, UKPV(0), UKPV(1), UKPV(2), NULL));
+ GFX_ASSERT(gfxop_set_pointer_view(s->gfx_state, UKPV(0), UKPV(1), UKPV(2), NULL));
s->mouse_pointer_view = UKPV(0);
s->mouse_pointer_loop = UKPV(1);
s->mouse_pointer_cel = UKPV(2);
break;
case 9 : {
point_t hotspot = gfx_point(SKPV(3), SKPV(4));
-
+
// sciprintf("Setting hotspot at %d/%d\n", hotspot.x, hotspot.y);
gfxop_set_pointer_view(s->gfx_state, UKPV(0), UKPV(1), UKPV(2), &hotspot);
@@ -381,15 +363,13 @@ kSetCursor_SCI11(state_t *s, int funct_nr, int argc, reg_t *argv)
}
reg_t
-kSetCursor(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
- if (s->version >= SCI_VERSION(1,001,000)||
- has_kernel_function(s, "MoveCursor"))
- {
+kSetCursor(state_t *s, int funct_nr, int argc, reg_t *argv) {
+ if (s->version >= SCI_VERSION(1, 001, 000) ||
+ has_kernel_function(s, "MoveCursor")) {
return kSetCursor_SCI11(s, funct_nr, argc, argv);
}
-
- if (SKPV_OR_ALT(1,1)) {
+
+ if (SKPV_OR_ALT(1, 1)) {
s->mouse_pointer_view = SKPV(0);
} else
s->mouse_pointer_view = GFXOP_NO_POINTER;
@@ -400,7 +380,7 @@ kSetCursor(state_t *s, int funct_nr, int argc, reg_t *argv)
if (argc > 2) {
point_t newpos = gfx_point(SKPV(2) + s->port->bounds.x,
- SKPV(3) + s->port->bounds.y);
+ SKPV(3) + s->port->bounds.y);
GFX_ASSERT(gfxop_set_pointer_position(s->gfx_state, newpos));
}
@@ -412,28 +392,25 @@ kSetCursor(state_t *s, int funct_nr, int argc, reg_t *argv)
extern int oldx, oldy;
reg_t
-kMoveCursor(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kMoveCursor(state_t *s, int funct_nr, int argc, reg_t *argv) {
point_t newpos;
- static point_t oldpos = {0,0};
+ static point_t oldpos = {0, 0};
newpos = s->gfx_state->pointer_pos;
- if (argc == 1)
- {
+ if (argc == 1) {
/* Case ignored on IBM PC */
- } else
- {
- newpos.x = SKPV(0)+s->port->zone.x;
- newpos.y = SKPV(1)+s->port->zone.y;
+ } else {
+ newpos.x = SKPV(0) + s->port->zone.x;
+ newpos.y = SKPV(1) + s->port->zone.y;
- if (newpos.x > s->port->zone.x+s->port->zone.xl)
- newpos.x = s->port->zone.x+s->port->zone.xl;
- if (newpos.y > s->port->zone.y+s->port->zone.yl)
- newpos.y = s->port->zone.y+s->port->zone.yl;
+ if (newpos.x > s->port->zone.x + s->port->zone.xl)
+ newpos.x = s->port->zone.x + s->port->zone.xl;
+ if (newpos.y > s->port->zone.y + s->port->zone.yl)
+ newpos.y = s->port->zone.y + s->port->zone.yl;
- if (newpos.x < 0) newpos.x=0;
- if (newpos.y < 0) newpos.y=0;
+ if (newpos.x < 0) newpos.x = 0;
+ if (newpos.y < 0) newpos.y = 0;
oldpos = newpos;
}
@@ -444,15 +421,13 @@ kMoveCursor(state_t *s, int funct_nr, int argc, reg_t *argv)
}
static inline void
-_ascertain_port_contents(gfxw_port_t *port)
-{
+_ascertain_port_contents(gfxw_port_t *port) {
if (!port->contents)
port->contents = (gfxw_widget_t *) gfxw_new_list(port->bounds, 0);
}
reg_t
-kShow(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kShow(state_t *s, int funct_nr, int argc, reg_t *argv) {
int old_map = s->pic_visible_map;
s->pic_visible_map = (gfx_map_mask_t) UKPV_OR_ALT(0, 1);
@@ -466,7 +441,7 @@ kShow(state_t *s, int funct_nr, int argc, reg_t *argv)
if (old_map != s->pic_visible_map) {
if (s->pic_visible_map == GFX_MASK_VISUAL) /* Full widget redraw */
- s->visual->draw(GFXW(s->visual), gfx_point(0,0));
+ s->visual->draw(GFXW(s->visual), gfx_point(0, 0));
gfxop_update(s->gfx_state);
sciprintf("Switching visible map to %x\n", s->pic_visible_map);
@@ -484,8 +459,7 @@ kShow(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kPicNotValid(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kPicNotValid(state_t *s, int funct_nr, int argc, reg_t *argv) {
s->r_acc = make_reg(0, s->pic_not_valid);
if (argc)
s->pic_not_valid = (byte)UKPV(0);
@@ -494,8 +468,7 @@ kPicNotValid(state_t *s, int funct_nr, int argc, reg_t *argv)
}
void
-_k_redraw_box(state_t *s, int x1, int y1, int x2, int y2)
-{
+_k_redraw_box(state_t *s, int x1, int y1, int x2, int y2) {
sciprintf("_k_redraw_box(): Unimplemented!\n");
#if 0
int i;
@@ -504,37 +477,36 @@ _k_redraw_box(state_t *s, int x1, int y1, int x2, int y2)
sciprintf("Reanimating views\n", s->dyn_views_nr);
- for (i=0;i<s->dyn_views_nr;i++) {
+ for (i = 0;i < s->dyn_views_nr;i++) {
*(list[i].underBitsp) = graph_save_box(s,
- list[i].nsLeft,
- list[i].nsTop,
- list[i].nsRight-list[i].nsLeft,
- list[i].nsBottom-list[i].nsTop,
- SCI_MAP_VISUAL | SCI_MAP_PRIORITY);
+ list[i].nsLeft,
+ list[i].nsTop,
+ list[i].nsRight - list[i].nsLeft,
+ list[i].nsBottom - list[i].nsTop,
+ SCI_MAP_VISUAL | SCI_MAP_PRIORITY);
draw_view0(s->pic, s->ports[0],
- list[i].nsLeft, list[i].nsTop,
- list[i].priority, list[i].loop,
- list[i].cel, 0, list[i].view);
+ list[i].nsLeft, list[i].nsTop,
+ list[i].priority, list[i].loop,
+ list[i].cel, 0, list[i].view);
}
- graph_update_box(s, x1, y1, x2-x1, y2-y1);
+ graph_update_box(s, x1, y1, x2 - x1, y2 - y1);
- for (i=0;i<s->dyn_views_nr;i++) {
+ for (i = 0;i < s->dyn_views_nr;i++) {
graph_restore_box(s, *(list[i].underBitsp));
- list[i].underBits=0;
+ list[i].underBits = 0;
}
#endif
}
void
-_k_graph_rebuild_port_with_color(state_t *s, gfx_color_t newbgcolor)
-{
+_k_graph_rebuild_port_with_color(state_t *s, gfx_color_t newbgcolor) {
gfxw_port_t *port = s->port;
gfxw_port_t *newport;
-
+
newport = sciw_new_window(s, port->zone, port->font_nr, port->color, newbgcolor,
- s->titlebar_port->font_nr, s->ega_colors[15], s->ega_colors[8],
- port->title_text, port->port_flags & ~WINDOW_FLAG_TRANSPARENT);
+ s->titlebar_port->font_nr, s->ega_colors[15], s->ega_colors[8],
+ port->title_text, port->port_flags & ~WINDOW_FLAG_TRANSPARENT);
if (s->dyn_views) {
int found = 0;
@@ -555,8 +527,7 @@ static int port_origin_x;
static int port_origin_y;
reg_t
-kGraph(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kGraph(state_t *s, int funct_nr, int argc, reg_t *argv) {
rect_t area;
gfxw_port_t *port = s->port;
int redraw_port = 0;
@@ -566,7 +537,7 @@ kGraph(state_t *s, int funct_nr, int argc, reg_t *argv)
area.xl = area.xl - area.x; /* Since the actual coordinates are absolute */
area.yl = area.yl - area.y;
- switch(SKPV(0)) {
+ switch (SKPV(0)) {
case K_GRAPH_GET_COLORS_NR:
@@ -578,13 +549,13 @@ kGraph(state_t *s, int funct_nr, int argc, reg_t *argv)
gfx_color_t gfxcolor = graph_map_color(s, SKPV(5) & 0xf, SKPV_OR_ALT(6, -1), SKPV_OR_ALT(7, -1));
SCIkdebug(SCIkGRAPHICS, "draw_line((%d, %d), (%d, %d), col=%d, p=%d, c=%d, mask=%d)\n",
- SKPV(2), SKPV(1), SKPV(4), SKPV(3), SKPV(5), SKPV_OR_ALT(6, -1), SKPV_OR_ALT(7, -1),
- gfxcolor.mask);
+ SKPV(2), SKPV(1), SKPV(4), SKPV(3), SKPV(5), SKPV_OR_ALT(6, -1), SKPV_OR_ALT(7, -1),
+ gfxcolor.mask);
redraw_port = 1;
ADD_TO_CURRENT_BG_WIDGETS(GFXW(gfxw_new_line(gfx_point(SKPV(2), SKPV(1)),
- gfx_point(SKPV(4), SKPV(3)),
- gfxcolor, GFX_LINE_MODE_CORRECT, GFX_LINE_STYLE_NORMAL)));
+ gfx_point(SKPV(4), SKPV(3)),
+ gfxcolor, GFX_LINE_MODE_CORRECT, GFX_LINE_STYLE_NORMAL)));
}
break;
@@ -627,8 +598,8 @@ kGraph(state_t *s, int funct_nr, int argc, reg_t *argv)
color.mask = (byte)UKPV(5);
SCIkdebug(SCIkGRAPHICS, "fill_box_any((%d, %d), (%d, %d), col=%d, p=%d, c=%d, mask=%d)\n",
- SKPV(2), SKPV(1), SKPV(4), SKPV(3), SKPV(6), SKPV_OR_ALT(7, -1), SKPV_OR_ALT(8, -1),
- UKPV(5));
+ SKPV(2), SKPV(1), SKPV(4), SKPV(3), SKPV(6), SKPV_OR_ALT(7, -1), SKPV_OR_ALT(8, -1),
+ UKPV(5));
ADD_TO_CURRENT_BG_WIDGETS(gfxw_new_box(s->gfx_state, area, color, color, GFX_BOX_SHADE_FLAT));
@@ -638,7 +609,7 @@ kGraph(state_t *s, int funct_nr, int argc, reg_t *argv)
case K_GRAPH_UPDATE_BOX: {
SCIkdebug(SCIkGRAPHICS, "update_box(%d, %d, %d, %d)\n",
- SKPV(1), SKPV(2), SKPV(3), SKPV(4));
+ SKPV(1), SKPV(2), SKPV(3), SKPV(4));
area.x += s->port->zone.x;
area.y += s->port->zone.y;
@@ -652,7 +623,7 @@ kGraph(state_t *s, int funct_nr, int argc, reg_t *argv)
SCIkdebug(SCIkGRAPHICS, "redraw_box(%d, %d, %d, %d)\n",
- SKPV(1), SKPV(2), SKPV(3), SKPV(4));
+ SKPV(1), SKPV(2), SKPV(3), SKPV(4));
area.x += s->port->zone.x;
area.y += s->port->zone.y;
@@ -688,8 +659,7 @@ kGraph(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kTextSize(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kTextSize(state_t *s, int funct_nr, int argc, reg_t *argv) {
int width, height;
char *text = argv[1].segment ? (char *) kernel_dereference_bulk_pointer(s, argv[1], 0) : NULL;
reg_t *dest = kernel_dereference_reg_pointer(s, argv[0], 4);
@@ -709,9 +679,9 @@ kTextSize(state_t *s, int funct_nr, int argc, reg_t *argv)
}
GFX_ASSERT(gfxop_get_text_params(s->gfx_state, font_nr, text,
- maxwidth? maxwidth : MAX_TEXT_WIDTH_MAGIC_VALUE,
- &width, &height, 0,
- NULL, NULL, NULL));
+ maxwidth ? maxwidth : MAX_TEXT_WIDTH_MAGIC_VALUE,
+ &width, &height, 0,
+ NULL, NULL, NULL));
SCIkdebug(SCIkSTRINGS, "GetTextSize '%s' -> %dx%d\n", text, width, height);
dest[2] = make_reg(0, height);
@@ -725,21 +695,20 @@ kTextSize(state_t *s, int funct_nr, int argc, reg_t *argv)
int debug_sleeptime_factor = 1;
reg_t
-kWait(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kWait(state_t *s, int funct_nr, int argc, reg_t *argv) {
GTimeVal time;
int sleep_time = UKPV(0);
- sci_get_current_time (&time);
+ sci_get_current_time(&time);
s->r_acc = make_reg(0, ((time.tv_usec - s->last_wait_time.tv_usec) * 60 / 1000000) +
- (time.tv_sec - s->last_wait_time.tv_sec) * 60);
+ (time.tv_sec - s->last_wait_time.tv_sec) * 60);
memcpy(&(s->last_wait_time), &time, sizeof(GTimeVal));
/* Reset optimization flags: Game is playing along nicely anyway */
s->kernel_opt_flags &= ~(KERNEL_OPT_FLAG_GOT_EVENT
- | KERNEL_OPT_FLAG_GOT_2NDEVENT);
+ | KERNEL_OPT_FLAG_GOT_2NDEVENT);
sleep_time *= debug_sleeptime_factor;
GFX_ASSERT(gfxop_usleep(s->gfx_state, sleep_time * 1000000 / 60));
@@ -749,8 +718,7 @@ kWait(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kCoordPri(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kCoordPri(state_t *s, int funct_nr, int argc, reg_t *argv) {
int y = SKPV(0);
return make_reg(0, VIEW_PRIORITY(y));
@@ -758,8 +726,7 @@ kCoordPri(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kPriCoord(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kPriCoord(state_t *s, int funct_nr, int argc, reg_t *argv) {
int priority = SKPV(0);
return make_reg(0, PRIORITY_BAND_FIRST(priority));
@@ -769,8 +736,7 @@ kPriCoord(state_t *s, int funct_nr, int argc, reg_t *argv)
void
_k_dirloop(reg_t obj, word angle, state_t *s, int funct_nr,
- int argc, reg_t *argv)
-{
+ int argc, reg_t *argv) {
int view = GET_SEL32V(obj, view);
int signal = GET_SEL32V(obj, signal);
int loop;
@@ -809,7 +775,7 @@ _k_dirloop(reg_t obj, word angle, state_t *s, int funct_nr,
if (maxloops == GFX_ERROR) {
SCIkwarn(SCIkERROR, "Invalid view.%03d\n", view);
return;
- } else if ((loop>1)&&(maxloops < 4))
+ } else if ((loop > 1) && (maxloops < 4))
return;
PUT_SEL32V(obj, loop, loop);
@@ -817,8 +783,7 @@ _k_dirloop(reg_t obj, word angle, state_t *s, int funct_nr,
reg_t
-kDirLoop(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kDirLoop(state_t *s, int funct_nr, int argc, reg_t *argv) {
_k_dirloop(argv[0], UKPV(1), s, funct_nr, argc, argv);
return s->r_acc;
@@ -838,8 +803,7 @@ nsrect_clip(state_t *s, int y, abs_rect_t retval, int priority);
static int
collides_with(state_t *s, abs_rect_t area, reg_t other_obj, int use_nsrect, int view_mask, int funct_nr, int argc,
- reg_t *argv)
-{
+ reg_t *argv) {
int other_signal = GET_SEL32V(other_obj, signal);
int other_priority = GET_SEL32V(other_obj, priority);
int y = GET_SEL32SV(other_obj, y);
@@ -862,20 +826,20 @@ collides_with(state_t *s, abs_rect_t area, reg_t other_obj, int use_nsrect, int
return 0; /* Out of scope */
SCIkdebug(SCIkBRESEN, "OtherSignal=%04x, z=%04x obj="PREG"\n", other_signal,
- (other_signal & view_mask), PRINT_REG(other_obj));
+ (other_signal & view_mask), PRINT_REG(other_obj));
if ((other_signal & (view_mask)) == 0) {
- /* check whether the other object ignores actors */
+ /* check whether the other object ignores actors */
SCIkdebug(SCIkBRESEN, " against (%d,%d) to (%d,%d)\n",
- other_area.x, other_area.y, other_area.xend, other_area.yend);
+ other_area.x, other_area.y, other_area.xend, other_area.yend);
if (((other_area.xend > area.x)
- && (other_area.x < area.xend)) /* [other_x, other_xend] intersects [x, xend])? */
- &&
- ((other_area.yend > area.y)
- && (other_area.y < area.yend))) /* [other_y, other_yend] intersects [y, yend]? */
+ && (other_area.x < area.xend)) /* [other_x, other_xend] intersects [x, xend])? */
+ &&
+ ((other_area.yend > area.y)
+ && (other_area.y < area.yend))) /* [other_y, other_yend] intersects [y, yend]? */
return 1;
/* CR (from :Bob Heitman:) Collision rects have Mac semantics, ((0,0),(1,1)) only
** covers the coordinate (0,0) */
@@ -889,8 +853,7 @@ collides_with(state_t *s, abs_rect_t area, reg_t other_obj, int use_nsrect, int
reg_t
-kCanBeHere(state_t *s, int funct_nr, int argc, reg_t * argv)
-{
+kCanBeHere(state_t *s, int funct_nr, int argc, reg_t * argv) {
reg_t obj = argv[0];
reg_t cliplist_ref = KP_ALT(1, NULL_REG);
list_t *cliplist = NULL;
@@ -910,18 +873,18 @@ kCanBeHere(state_t *s, int funct_nr, int argc, reg_t * argv)
abs_zone.yend = GET_SEL32SV(obj, brBottom);
zone = gfx_rect(abs_zone.x + port->zone.x, abs_zone.y + port->zone.y,
- abs_zone.xend - abs_zone.x, abs_zone.yend - abs_zone.y);
+ abs_zone.xend - abs_zone.x, abs_zone.yend - abs_zone.y);
signal = GET_SEL32V(obj, signal);
- SCIkdebug(SCIkBRESEN,"Checking collision: (%d,%d) to (%d,%d) ([%d..%d]x[%d..%d]), obj="PREG", sig=%04x, cliplist="PREG"\n",
- GFX_PRINT_RECT(zone),
- abs_zone.x, abs_zone.xend, abs_zone.y, abs_zone.yend,
- PRINT_REG(obj), signal, PRINT_REG(cliplist_ref));
+ SCIkdebug(SCIkBRESEN, "Checking collision: (%d,%d) to (%d,%d) ([%d..%d]x[%d..%d]), obj="PREG", sig=%04x, cliplist="PREG"\n",
+ GFX_PRINT_RECT(zone),
+ abs_zone.x, abs_zone.xend, abs_zone.y, abs_zone.yend,
+ PRINT_REG(obj), signal, PRINT_REG(cliplist_ref));
illegal_bits = GET_SEL32V(obj, illegalBits);
retval = !(illegal_bits
- & (edgehit = gfxop_scan_bitmask(s->gfx_state, zone, GFX_MASK_CONTROL)));
+ & (edgehit = gfxop_scan_bitmask(s->gfx_state, zone, GFX_MASK_CONTROL)));
SCIkdebug(SCIkBRESEN, "edgehit = %04x (illegalBits %04x)\n", edgehit, illegal_bits);
if (retval == 0) {
@@ -931,24 +894,24 @@ kCanBeHere(state_t *s, int funct_nr, int argc, reg_t * argv)
retval = 0;
- if ((illegal_bits & 0x8000) /* If we are vulnerable to those views at all... */
- && s->dyn_views) { /* ...check against all stop-updated dynviews */
- gfxw_dyn_view_t *widget = (gfxw_dyn_view_t *) s->dyn_views->contents;
+ if ((illegal_bits & 0x8000) /* If we are vulnerable to those views at all... */
+ && s->dyn_views) { /* ...check against all stop-updated dynviews */
+ gfxw_dyn_view_t *widget = (gfxw_dyn_view_t *) s->dyn_views->contents;
- SCIkdebug(SCIkBRESEN, "Checking vs dynviews:\n");
+ SCIkdebug(SCIkBRESEN, "Checking vs dynviews:\n");
- while (widget) {
- if (widget->ID
- && (widget->signal & _K_VIEW_SIG_FLAG_FREESCI_STOPUPD)
- && ((widget->ID != obj.segment) || (widget->subID != obj.offset))
- && is_object(s, make_reg(widget->ID, widget->subID)))
- if (collides_with(s, abs_zone, make_reg(widget->ID, widget->subID), 1,
- GASEOUS_VIEW_MASK_ACTIVE, funct_nr, argc, argv))
- return not_register(s, NULL_REG);
+ while (widget) {
+ if (widget->ID
+ && (widget->signal & _K_VIEW_SIG_FLAG_FREESCI_STOPUPD)
+ && ((widget->ID != obj.segment) || (widget->subID != obj.offset))
+ && is_object(s, make_reg(widget->ID, widget->subID)))
+ if (collides_with(s, abs_zone, make_reg(widget->ID, widget->subID), 1,
+ GASEOUS_VIEW_MASK_ACTIVE, funct_nr, argc, argv))
+ return not_register(s, NULL_REG);
- widget = (gfxw_dyn_view_t *) widget->next;
- }
- }
+ widget = (gfxw_dyn_view_t *) widget->next;
+ }
+ }
if (signal & GASEOUS_VIEW_MASK_ACTIVE) {
retval = signal & GASEOUS_VIEW_MASK_ACTIVE; /* CanBeHere- it's either being disposed, or it ignores actors anyway */
@@ -990,8 +953,7 @@ kCanBeHere(state_t *s, int funct_nr, int argc, reg_t * argv)
} /* CanBeHere */
reg_t
-kIsItSkip(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kIsItSkip(state_t *s, int funct_nr, int argc, reg_t *argv) {
int view = SKPV(0);
int loop = SKPV(1);
int cel = SKPV(2);
@@ -1006,17 +968,16 @@ kIsItSkip(state_t *s, int funct_nr, int argc, reg_t *argv)
}
pxm = res->loops[loop].cels[cel];
- if (x > pxm->index_xl) x = pxm->index_xl-1;
- if (y > pxm->index_yl) y = pxm->index_yl-1;
+ if (x > pxm->index_xl) x = pxm->index_xl - 1;
+ if (y > pxm->index_yl) y = pxm->index_yl - 1;
return make_reg(0,
- pxm->index_data[y*pxm->index_xl+x] ==
- pxm->color_key);
+ pxm->index_data[y*pxm->index_xl+x] ==
+ pxm->color_key);
}
reg_t
-kCelHigh(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kCelHigh(state_t *s, int funct_nr, int argc, reg_t *argv) {
int view = SKPV(0);
int loop = SKPV(1);
int cel = SKPV(2);
@@ -1035,8 +996,7 @@ kCelHigh(state_t *s, int funct_nr, int argc, reg_t *argv)
}
reg_t
-kCelWide(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kCelWide(state_t *s, int funct_nr, int argc, reg_t *argv) {
int view = SKPV(0);
int loop = SKPV(1);
int cel = SKPV(2);
@@ -1055,8 +1015,7 @@ kCelWide(state_t *s, int funct_nr, int argc, reg_t *argv)
}
reg_t
-kNumLoops(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kNumLoops(state_t *s, int funct_nr, int argc, reg_t *argv) {
reg_t obj = argv[0];
int view = GET_SEL32V(obj, view);
int loops_nr = gfxop_lookup_view_get_loops(s->gfx_state, view);
@@ -1074,8 +1033,7 @@ kNumLoops(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kNumCels(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kNumCels(state_t *s, int funct_nr, int argc, reg_t *argv) {
reg_t obj = argv[0];
int loop = GET_SEL32V(obj, loop);
int view = GET_SEL32V(obj, view);
@@ -1088,14 +1046,13 @@ kNumCels(state_t *s, int funct_nr, int argc, reg_t *argv)
return NULL_REG;
}
- SCIkdebug(SCIkGRAPHICS, "NumCels(view.%d, %d) = %d\n", view, loop, cel+1);
+ SCIkdebug(SCIkGRAPHICS, "NumCels(view.%d, %d) = %d\n", view, loop, cel + 1);
return make_reg(0, cel + 1);
}
reg_t
-kOnControl(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kOnControl(state_t *s, int funct_nr, int argc, reg_t *argv) {
int arg = 0;
gfx_map_mask_t map;
int xstart, ystart;
@@ -1109,12 +1066,12 @@ kOnControl(state_t *s, int funct_nr, int argc, reg_t *argv)
map = (gfx_map_mask_t) SKPV(0);
}
- ystart = SKPV(arg+1);
+ ystart = SKPV(arg + 1);
xstart = SKPV(arg);
if (argc > 3) {
- ylen = SKPV(arg+3) - ystart;
- xlen = SKPV(arg+2) - xstart;
+ ylen = SKPV(arg + 3) - ystart;
+ xlen = SKPV(arg + 2) - xstart;
}
return make_reg(0, gfxop_scan_bitmask(s->gfx_state, gfx_rect(xstart, ystart + 10, xlen, ylen), map));
@@ -1126,8 +1083,7 @@ _k_view_list_free_backgrounds(state_t *s, view_object_t *list, int list_nr);
int sci01_priority_table_flags = 0;
reg_t
-kDrawPic(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kDrawPic(state_t *s, int funct_nr, int argc, reg_t *argv) {
int pic_nr = SKPV(0);
int add_to_pic = 1;
int palette = SKPV_OR_ALT(3, 0);
@@ -1143,14 +1099,14 @@ kDrawPic(state_t *s, int funct_nr, int argc, reg_t *argv)
add_to_pic = 0;
gfxop_disable_dirty_frames(s->gfx_state);
-
+
if (NULL != s->old_screen) {
gfxop_free_pixmap(s->gfx_state, s->old_screen);
}
s->old_screen = gfxop_grab_pixmap(s->gfx_state, gfx_rect(0, 10, 320, 190));
- SCIkdebug(SCIkGRAPHICS,"Drawing pic.%03d\n", SKPV(0));
+ SCIkdebug(SCIkGRAPHICS, "Drawing pic.%03d\n", SKPV(0));
if (!s->pics) {
s->pics = (drawn_pic_t*)sci_malloc(sizeof(drawn_pic_t) * (s->pics_nr = 8));
@@ -1193,10 +1149,10 @@ kDrawPic(state_t *s, int funct_nr, int argc, reg_t *argv)
if (sci01_priority_table_flags & 0x2) {
if (s->pic_priority_table) {
int i;
- fprintf(stderr,"---------------------------\nPriority table:\n");
+ fprintf(stderr, "---------------------------\nPriority table:\n");
for (i = 0; i < 16; i++)
- fprintf(stderr,"\t%d:\t%d\n", i, s->pic_priority_table[i]);
- fprintf(stderr,"---------------------------\n");
+ fprintf(stderr, "\t%d:\t%d\n", i, s->pic_priority_table[i]);
+ fprintf(stderr, "---------------------------\n");
}
}
if (sci01_priority_table_flags & 0x1)
@@ -1226,8 +1182,7 @@ kDrawPic(state_t *s, int funct_nr, int argc, reg_t *argv)
abs_rect_t
-set_base(state_t *s, reg_t object)
-{
+set_base(state_t *s, reg_t object) {
int x, y, original_y, z, ystep, xsize, ysize;
int xbase, ybase, xend, yend;
int view, loop, cel;
@@ -1268,7 +1223,7 @@ set_base(state_t *s, reg_t object)
}
gfxop_get_cel_parameters(s->gfx_state, view, loop, cel,
- &xsize, &ysize, &offset);
+ &xsize, &ysize, &offset);
xmod = offset.x;
ymod = offset.y;
@@ -1281,7 +1236,7 @@ set_base(state_t *s, reg_t object)
ybase = yend - ystep;
SCIkdebug(SCIkBASESETTER, "(%d,%d)+/-(%d,%d), (%d x %d) -> (%d, %d) to (%d, %d)\n",
- x, y, xmod, ymod, xsize, ysize, xbase, ybase, xend, yend);
+ x, y, xmod, ymod, xsize, ysize, xbase, ybase, xend, yend);
retval.x = xbase;
retval.y = ybase;
@@ -1293,12 +1248,11 @@ set_base(state_t *s, reg_t object)
void
-_k_base_setter(state_t *s, reg_t object)
-{
+_k_base_setter(state_t *s, reg_t object) {
abs_rect_t absrect = set_base(s, object);
if (lookup_selector(s, object, s->selector_map.brLeft, NULL, NULL)
- != SELECTOR_VARIABLE)
+ != SELECTOR_VARIABLE)
return; /* non-fatal */
if (s->version <= SCI_VERSION_LTU_BASE_OB1)
@@ -1311,8 +1265,7 @@ _k_base_setter(state_t *s, reg_t object)
}
reg_t
-kBaseSetter(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kBaseSetter(state_t *s, int funct_nr, int argc, reg_t *argv) {
reg_t object = argv[0];
@@ -1323,8 +1276,7 @@ kBaseSetter(state_t *s, int funct_nr, int argc, reg_t *argv)
static inline abs_rect_t
-nsrect_clip(state_t *s, int y, abs_rect_t retval, int priority)
-{
+nsrect_clip(state_t *s, int y, abs_rect_t retval, int priority) {
int pri_top;
if (priority == -1)
@@ -1343,11 +1295,10 @@ nsrect_clip(state_t *s, int y, abs_rect_t retval, int priority)
}
inline abs_rect_t
-calculate_nsrect(state_t *s, int x, int y, int view, int loop, int cel)
-{
+calculate_nsrect(state_t *s, int x, int y, int view, int loop, int cel) {
int xbase, ybase, xend, yend, xsize, ysize;
int xmod = 0, ymod = 0;
- abs_rect_t retval = {0,0,0,0};
+ abs_rect_t retval = {0, 0, 0, 0};
if (gfxop_check_cel(s->gfx_state, view, &loop, &cel)) {
xsize = ysize = xmod = ymod = 0;
@@ -1355,7 +1306,7 @@ calculate_nsrect(state_t *s, int x, int y, int view, int loop, int cel)
point_t offset = gfx_point(0, 0);
gfxop_get_cel_parameters(s->gfx_state, view, loop, cel,
- &xsize, &ysize, &offset);
+ &xsize, &ysize, &offset);
xmod = offset.x;
ymod = offset.y;
@@ -1375,8 +1326,7 @@ calculate_nsrect(state_t *s, int x, int y, int view, int loop, int cel)
}
inline abs_rect_t
-get_nsrect(state_t *s, reg_t object, byte clip)
-{
+get_nsrect(state_t *s, reg_t object, byte clip) {
int x, y, z;
int view, loop, cel;
abs_rect_t retval;
@@ -1406,12 +1356,11 @@ get_nsrect(state_t *s, reg_t object, byte clip)
}
static void
-_k_set_now_seen(state_t *s, reg_t object)
-{
+_k_set_now_seen(state_t *s, reg_t object) {
abs_rect_t absrect = get_nsrect(s, object, 0);
if (lookup_selector(s, object, s->selector_map.nsTop, NULL, NULL)
- != SELECTOR_VARIABLE) { return; } /* This isn't fatal */
+ != SELECTOR_VARIABLE) { return; } /* This isn't fatal */
PUT_SEL32V(object, nsLeft, absrect.x);
PUT_SEL32V(object, nsRight, absrect.xend);
@@ -1421,8 +1370,7 @@ _k_set_now_seen(state_t *s, reg_t object)
reg_t
-kSetNowSeen(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kSetNowSeen(state_t *s, int funct_nr, int argc, reg_t *argv) {
reg_t object = argv[0];
_k_set_now_seen(s, object);
@@ -1431,10 +1379,8 @@ kSetNowSeen(state_t *s, int funct_nr, int argc, reg_t *argv)
} /* kSetNowSeen */
reg_t
-kPalette(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
- switch (UKPV(0))
- {
+kPalette(state_t *s, int funct_nr, int argc, reg_t *argv) {
+ switch (UKPV(0)) {
case 5 : {
int r = UKPV(1);
int g = UKPV(2);
@@ -1443,24 +1389,23 @@ kPalette(state_t *s, int funct_nr, int argc, reg_t *argv)
int i, delta, bestindex = -1, bestdelta = 200000;
for (i = 0; i < KERNEL_COLORS_NR; i++) {
- int dr = abs (KERNEL_COLOR_PALETTE[i].r - r);
- int dg = abs (KERNEL_COLOR_PALETTE[i].g - g);
- int db = abs (KERNEL_COLOR_PALETTE[i].b - b);
+ int dr = abs(KERNEL_COLOR_PALETTE[i].r - r);
+ int dg = abs(KERNEL_COLOR_PALETTE[i].g - g);
+ int db = abs(KERNEL_COLOR_PALETTE[i].b - b);
- delta = dr*dr + dg * dg + db * db;
+ delta = dr * dr + dg * dg + db * db;
- if (delta < bestdelta)
- {
+ if (delta < bestdelta) {
bestdelta = delta;
bestindex = i;
}
}
- /* Don't warn about inexact mappings -- it's actually the
- ** rule rather than the exception */
+ /* Don't warn about inexact mappings -- it's actually the
+ ** rule rather than the exception */
return make_reg(0, bestindex);
}
-
+
case 4 :
case 6 :
break;
@@ -1475,23 +1420,21 @@ _k_draw_control(state_t *s, reg_t obj, int inverse);
static void
-_k_disable_delete_for_now(state_t *s, reg_t obj)
-{
- reg_t text_pos = GET_SEL32(obj, text);
- char *text = IS_NULL_REG(text_pos)? NULL : (char *) sm_dereference(&s->seg_manager, text_pos, NULL);
+_k_disable_delete_for_now(state_t *s, reg_t obj) {
+ reg_t text_pos = GET_SEL32(obj, text);
+ char *text = IS_NULL_REG(text_pos) ? NULL : (char *) sm_dereference(&s->seg_manager, text_pos, NULL);
int type = GET_SEL32V(obj, type);
int state = GET_SEL32V(obj, state);
if (type == K_CONTROL_BUTTON && text &&
- !strcmp(s->game_name, "sq4") &&
- s->version < SCI_VERSION(1,001,000) &&
- !strcmp(text, " Delete "))
+ !strcmp(s->game_name, "sq4") &&
+ s->version < SCI_VERSION(1, 001, 000) &&
+ !strcmp(text, " Delete "))
PUT_SEL32V(obj, state, (state | CONTROL_STATE_GRAY) & ~CONTROL_STATE_ENABLED);
}
reg_t
-kDrawControl(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kDrawControl(state_t *s, int funct_nr, int argc, reg_t *argv) {
reg_t obj = argv[0];
_k_disable_delete_for_now(s, obj);
@@ -1502,8 +1445,7 @@ kDrawControl(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kHiliteControl(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kHiliteControl(state_t *s, int funct_nr, int argc, reg_t *argv) {
reg_t obj = argv[0];
@@ -1513,8 +1455,7 @@ kHiliteControl(state_t *s, int funct_nr, int argc, reg_t *argv)
void
-update_cursor_limits(int *display_offset, int *cursor, int max_displayed)
-{
+update_cursor_limits(int *display_offset, int *cursor, int max_displayed) {
if (*cursor < *display_offset + 4) {
if (*cursor < 8)
*display_offset = 0;
@@ -1541,8 +1482,7 @@ update_cursor_limits(int *display_offset, int *cursor, int max_displayed)
reg_t
-kEditControl(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kEditControl(state_t *s, int funct_nr, int argc, reg_t *argv) {
reg_t obj = argv[0];
reg_t event = argv[1];
@@ -1551,7 +1491,8 @@ kEditControl(state_t *s, int funct_nr, int argc, reg_t *argv)
word ct_type = GET_SEL32V(obj, type);
switch (ct_type) {
- case 0: break; /* NOP */
+ case 0:
+ break; /* NOP */
case K_CONTROL_EDIT:
if (event.segment && ((GET_SEL32V(event, type)) == SCI_EVT_KEYBOARD)) {
@@ -1568,7 +1509,7 @@ kEditControl(state_t *s, int funct_nr, int argc, reg_t *argv)
if (!text) {
SCIkdebug(SCIkWARNING, "Could not draw control: "PREG" does not reference text!\n",
- PRINT_REG(text_pos));
+ PRINT_REG(text_pos));
return s->r_acc;
}
@@ -1586,21 +1527,39 @@ kEditControl(state_t *s, int funct_nr, int argc, reg_t *argv)
if (modifiers & SCI_EVM_CTRL) {
switch (tolower((char)key)) {
- case 'a': cursor = 0; break;
- case 'e': cursor = textlen; break;
- case 'f': if (cursor < textlen) ++cursor; break;
- case 'b': if (cursor > 0) --cursor; break;
- case 'k': text[cursor] = 0; break; /* Terminate string */
- case 'h': _K_EDIT_BACKSPACE; break;
- case 'd': _K_EDIT_DELETE; break;
+ case 'a':
+ cursor = 0;
+ break;
+ case 'e':
+ cursor = textlen;
+ break;
+ case 'f':
+ if (cursor < textlen) ++cursor;
+ break;
+ case 'b':
+ if (cursor > 0) --cursor;
+ break;
+ case 'k':
+ text[cursor] = 0;
+ break; /* Terminate string */
+ case 'h':
+ _K_EDIT_BACKSPACE;
+ break;
+ case 'd':
+ _K_EDIT_DELETE;
+ break;
}
PUT_SEL32V(event, claimed, 1);
} else if (modifiers & SCI_EVM_ALT) { /* Ctrl has precedence over Alt */
switch (key) {
- case 0x2100 /* A-f */: while ((cursor < textlen) && (text[cursor++] != ' ')); break;
- case 0x3000 /* A-b */: while ((cursor > 0) && (text[--cursor - 1] != ' ')); break;
+ case 0x2100 /* A-f */:
+ while ((cursor < textlen) && (text[cursor++] != ' '));
+ break;
+ case 0x3000 /* A-b */:
+ while ((cursor > 0) && (text[--cursor - 1] != ' '));
+ break;
case 0x2000 /* A-d */: {
while ((cursor < textlen) && (text[cursor] == ' ')) {
@@ -1621,20 +1580,32 @@ kEditControl(state_t *s, int funct_nr, int argc, reg_t *argv)
PUT_SEL32V(event, claimed, 1);
- switch(key) {
- case SCI_K_BACKSPACE: _K_EDIT_BACKSPACE; break;
+ switch (key) {
+ case SCI_K_BACKSPACE:
+ _K_EDIT_BACKSPACE;
+ break;
default:
PUT_SEL32V(event, claimed, 0);
}
} else if (key & 0xff00) {
- switch(key) {
- case SCI_K_HOME: cursor = 0; break;
- case SCI_K_END: cursor = textlen; break;
- case SCI_K_RIGHT: if (cursor + 1 <= textlen) ++cursor; break;
- case SCI_K_LEFT: if (cursor > 0) --cursor; break;
- case SCI_K_DELETE: _K_EDIT_DELETE; break;
+ switch (key) {
+ case SCI_K_HOME:
+ cursor = 0;
+ break;
+ case SCI_K_END:
+ cursor = textlen;
+ break;
+ case SCI_K_RIGHT:
+ if (cursor + 1 <= textlen) ++cursor;
+ break;
+ case SCI_K_LEFT:
+ if (cursor > 0) --cursor;
+ break;
+ case SCI_K_DELETE:
+ _K_EDIT_DELETE;
+ break;
}
PUT_SEL32V(event, claimed, 1);
@@ -1701,8 +1672,7 @@ kEditControl(state_t *s, int funct_nr, int argc, reg_t *argv)
static void
-_k_draw_control(state_t *s, reg_t obj, int inverse)
-{
+_k_draw_control(state_t *s, reg_t obj, int inverse) {
int x = GET_SEL32SV(obj, nsLeft);
int y = GET_SEL32SV(obj, nsTop);
int xl = GET_SEL32SV(obj, nsRight) - x;
@@ -1711,7 +1681,7 @@ _k_draw_control(state_t *s, reg_t obj, int inverse)
int font_nr = GET_SEL32V(obj, font);
reg_t text_pos = GET_SEL32(obj, text);
- char *text = IS_NULL_REG(text_pos)? NULL : (char *) sm_dereference(&s->seg_manager, text_pos, NULL);
+ char *text = IS_NULL_REG(text_pos) ? NULL : (char *) sm_dereference(&s->seg_manager, text_pos, NULL);
int view = GET_SEL32V(obj, view);
int cel = sign_extend_byte(GET_SEL32V(obj, cel));
int loop = sign_extend_byte(GET_SEL32V(obj, loop));
@@ -1732,8 +1702,8 @@ _k_draw_control(state_t *s, reg_t obj, int inverse)
SCIkdebug(SCIkGRAPHICS, "drawing button "PREG" to %d,%d\n", PRINT_REG(obj), x, y);
ADD_TO_CURRENT_BG_WIDGETS(sciw_new_button_control(s->port, obj, area, text, font_nr,
- (gint8)(state & CONTROL_STATE_FRAMED),
- (gint8)inverse, (gint8)(state & CONTROL_STATE_GRAY)));
+ (gint8)(state & CONTROL_STATE_FRAMED),
+ (gint8)inverse, (gint8)(state & CONTROL_STATE_GRAY)));
break;
case K_CONTROL_TEXT:
@@ -1742,9 +1712,9 @@ _k_draw_control(state_t *s, reg_t obj, int inverse)
SCIkdebug(SCIkGRAPHICS, "drawing text "PREG" to %d,%d, mode=%d\n", PRINT_REG(obj), x, y, mode);
ADD_TO_CURRENT_BG_WIDGETS(
- sciw_new_text_control(s->port, obj, area, text, font_nr, mode,
- (gint8)(!!(state & CONTROL_STATE_DITHER_FRAMED)),
- (gint8)inverse));
+ sciw_new_text_control(s->port, obj, area, text, font_nr, mode,
+ (gint8)(!!(state & CONTROL_STATE_DITHER_FRAMED)),
+ (gint8)inverse));
break;
case K_CONTROL_EDIT:
@@ -1765,10 +1735,10 @@ _k_draw_control(state_t *s, reg_t obj, int inverse)
case K_CONTROL_ICON:
- SCIkdebug(SCIkGRAPHICS, "drawing icon control "PREG" to %d,%d\n", PRINT_REG(obj), x, y -1);
+ SCIkdebug(SCIkGRAPHICS, "drawing icon control "PREG" to %d,%d\n", PRINT_REG(obj), x, y - 1);
ADD_TO_CURRENT_BG_WIDGETS(sciw_new_icon_control(s->port, obj, area, view, loop, cel,
- (gint8)(state & CONTROL_STATE_FRAMED), (gint8)inverse));
+ (gint8)(state & CONTROL_STATE_FRAMED), (gint8)inverse));
break;
case K_CONTROL_CONTROL:
@@ -1776,14 +1746,14 @@ _k_draw_control(state_t *s, reg_t obj, int inverse)
char **entries_list = NULL;
char *seeker;
int entries_nr;
- int lsTop = GET_SEL32V(obj, lsTop)-text_pos.offset;
+ int lsTop = GET_SEL32V(obj, lsTop) - text_pos.offset;
int list_top = 0;
int selection = 0;
int entry_size = GET_SEL32V(obj, x);
int i;
SCIkdebug(SCIkGRAPHICS, "drawing list control %04x to %d,%d, diff %d\n", obj, x, y,
- SCI_MAX_SAVENAME_LENGTH);
+ SCI_MAX_SAVENAME_LENGTH);
cursor = GET_SEL32V(obj, cursor) - text_pos.offset;
entries_nr = 0;
@@ -1807,7 +1777,7 @@ _k_draw_control(state_t *s, reg_t obj, int inverse)
}
ADD_TO_CURRENT_BG_WIDGETS(sciw_new_list_control(s->port, obj, area, font_nr, entries_list, entries_nr,
- list_top, selection, (gint8)inverse));
+ list_top, selection, (gint8)inverse));
if (entries_nr)
free(entries_list);
}
@@ -1818,7 +1788,7 @@ _k_draw_control(state_t *s, reg_t obj, int inverse)
default:
SCIkwarn(SCIkWARNING, "Unknown control type: %d at "PREG", at (%d, %d) size %d x %d\n",
- type, PRINT_REG(obj), x, y, xl, yl);
+ type, PRINT_REG(obj), x, y, xl, yl);
}
if (!s->pic_not_valid) {
@@ -1828,21 +1798,20 @@ _k_draw_control(state_t *s, reg_t obj, int inverse)
static void
-draw_rect_to_control_map(state_t *s, abs_rect_t abs_zone)
-{
+draw_rect_to_control_map(state_t *s, abs_rect_t abs_zone) {
gfxw_box_t *box;
gfx_color_t color;
gfxop_set_color(s->gfx_state, &color, -1, -1, -1, -1, -1, 0xf);
- SCIkdebug(SCIkGRAPHICS," adding control block (%d,%d)to(%d,%d)\n",
- abs_zone.x, abs_zone.y, abs_zone.xend, abs_zone.yend);
+ SCIkdebug(SCIkGRAPHICS, " adding control block (%d,%d)to(%d,%d)\n",
+ abs_zone.x, abs_zone.y, abs_zone.xend, abs_zone.yend);
box = gfxw_new_box(s->gfx_state,
- gfx_rect(abs_zone.x, abs_zone.y,
- abs_zone.xend - abs_zone.x,
- abs_zone.yend - abs_zone.y),
- color, color, GFX_BOX_SHADE_FLAT);
+ gfx_rect(abs_zone.x, abs_zone.y,
+ abs_zone.xend - abs_zone.x,
+ abs_zone.yend - abs_zone.y),
+ color, color, GFX_BOX_SHADE_FLAT);
assert_primary_widget_lists(s);
@@ -1850,8 +1819,7 @@ draw_rect_to_control_map(state_t *s, abs_rect_t abs_zone)
}
static inline void
-draw_obj_to_control_map(state_t *s, gfxw_dyn_view_t *view)
-{
+draw_obj_to_control_map(state_t *s, gfxw_dyn_view_t *view) {
reg_t obj = make_reg(view->ID, view->subID);
if (!is_object(s, obj))
@@ -1859,14 +1827,13 @@ draw_obj_to_control_map(state_t *s, gfxw_dyn_view_t *view)
if (!(view->signalp && (((reg_t *)view->signalp)->offset & _K_VIEW_SIG_FLAG_IGNORE_ACTOR))) {
abs_rect_t abs_zone = get_nsrect(s, make_reg(view->ID, view->subID), 1);
- draw_rect_to_control_map (s, abs_zone);
+ draw_rect_to_control_map(s, abs_zone);
}
}
static void
-_k_view_list_do_postdraw(state_t *s, gfxw_list_t *list)
-{
+_k_view_list_do_postdraw(state_t *s, gfxw_list_t *list) {
gfxw_dyn_view_t *widget = (gfxw_dyn_view_t *) list->contents;
while (widget) {
@@ -1909,7 +1876,7 @@ _k_view_list_do_postdraw(state_t *s, gfxw_list_t *list)
}
#ifdef DEBUG_LSRECT
else fprintf(stderr, "Not lsRecting "PREG" because %d\n", PRINT_REG(obj),
- lookup_selector(s, obj, s->selector_map.nsBottom, NULL, NULL));
+ lookup_selector(s, obj, s->selector_map.nsBottom, NULL, NULL));
#endif
if (widget->signal & _K_VIEW_SIG_FLAG_HIDDEN)
@@ -1928,15 +1895,14 @@ _k_view_list_do_postdraw(state_t *s, gfxw_list_t *list)
}
void
-_k_view_list_mark_free(state_t *s, reg_t off)
-{
+_k_view_list_mark_free(state_t *s, reg_t off) {
if (s->dyn_views) {
gfxw_dyn_view_t *w = (gfxw_dyn_view_t *) s->dyn_views->contents;
while (w) {
if (w->ID == off.segment
- && w->subID == off.offset) {
+ && w->subID == off.offset) {
w->under_bitsp = NULL;
}
@@ -1949,9 +1915,9 @@ static int _k_animate_ran = 0;
int
_k_view_list_dispose_loop(state_t *s, list_t *list, gfxw_dyn_view_t *widget,
- int funct_nr, int argc, reg_t *argv)
- /* disposes all list members flagged for disposal; funct_nr is the invoking kfunction */
- /* returns non-zero IFF views were dropped */
+ int funct_nr, int argc, reg_t *argv)
+/* disposes all list members flagged for disposal; funct_nr is the invoking kfunction */
+/* returns non-zero IFF views were dropped */
{
int signal;
int dropped = 0;
@@ -1974,35 +1940,35 @@ _k_view_list_dispose_loop(state_t *s, list_t *list, gfxw_dyn_view_t *widget,
if (!is_object(s, obj)) {
SCIkwarn(SCIkERROR, "Non-object "PREG" present"
- " in view list during delete time\n",
- PRINT_REG(obj));
+ " in view list during delete time\n",
+ PRINT_REG(obj));
obj = NULL_REG;
} else
- if (widget->under_bitsp) { /* Is there a bg picture left to clean? */
+ if (widget->under_bitsp) { /* Is there a bg picture left to clean? */
- reg_t mem_handle = *((reg_t*)(widget->under_bitsp));
+ reg_t mem_handle = *((reg_t*)(widget->under_bitsp));
- if (mem_handle.segment) {
- if (!kfree(s, mem_handle)) {
- *((reg_t*)(widget->under_bitsp)) = make_reg(0, widget->under_bits = 0);
- } else {
- SCIkwarn(SCIkWARNING,
- "Treating viewobj "PREG
- " as no longer"
- " present\n", PRINT_REG(obj));
- obj = NULL_REG;
+ if (mem_handle.segment) {
+ if (!kfree(s, mem_handle)) {
+ *((reg_t*)(widget->under_bitsp)) = make_reg(0, widget->under_bits = 0);
+ } else {
+ SCIkwarn(SCIkWARNING,
+ "Treating viewobj "PREG
+ " as no longer"
+ " present\n", PRINT_REG(obj));
+ obj = NULL_REG;
+ }
}
}
- }
if (is_object(s, obj)) {
if (invoke_selector(INV_SEL(obj, delete_, 1), 0))
SCIkwarn(SCIkWARNING, "Object at "PREG" requested deletion, but does not have"
- " a delete funcselector\n", PRINT_REG(obj));
+ " a delete funcselector\n", PRINT_REG(obj));
if (_k_animate_ran) {
SCIkwarn(SCIkWARNING, "Object at "PREG" invoked kAnimate() during deletion!\n",
- PRINT_REG(obj));
+ PRINT_REG(obj));
return dropped;
}
@@ -2015,14 +1981,14 @@ _k_view_list_dispose_loop(state_t *s, list_t *list, gfxw_dyn_view_t *widget,
}
SCIkdebug(SCIkGRAPHICS, "Freeing "PREG" with signal=%04x\n",
- PRINT_REG(obj), signal);
+ PRINT_REG(obj), signal);
if (!(signal & _K_VIEW_SIG_FLAG_HIDDEN)) {
SCIkdebug(SCIkGRAPHICS, "Adding view at "PREG" to background\n",
- PRINT_REG(obj));
+ PRINT_REG(obj));
if (!(gfxw_remove_id(widget->parent, widget->ID, widget->subID) == GFXW(widget))) {
SCIkwarn(SCIkERROR, "Attempt to remove view with ID %x:%x from list failed!\n",
- widget->ID, widget->subID);
+ widget->ID, widget->subID);
BREAKPOINT();
}
@@ -2032,8 +1998,7 @@ _k_view_list_dispose_loop(state_t *s, list_t *list, gfxw_dyn_view_t *widget,
widget->draw_bounds.y += s->dyn_views->bounds.y - widget->parent->bounds.y;
widget->draw_bounds.x += s->dyn_views->bounds.x - widget->parent->bounds.x;
dropped = 1;
- }
- else {
+ } else {
SCIkdebug(SCIkGRAPHICS, "Deleting view at "PREG"\n", PRINT_REG(obj));
widget->flags |= GFXW_FLAG_VISIBLE;
gfxw_annihilate(GFXW(widget));
@@ -2054,8 +2019,7 @@ _k_view_list_dispose_loop(state_t *s, list_t *list, gfxw_dyn_view_t *widget,
#define _K_MAKE_VIEW_LIST_DRAW_TO_CONTROL_MAP 4
static gfxw_dyn_view_t *
-_k_make_dynview_obj(state_t *s, reg_t obj, int options, int nr, int funct_nr, int argc, reg_t *argv)
-{
+_k_make_dynview_obj(state_t *s, reg_t obj, int options, int nr, int funct_nr, int argc, reg_t *argv) {
short oldloop, oldcel;
int cel, loop, view_nr = GET_SEL32SV(obj, view);
int palette;
@@ -2082,9 +2046,10 @@ _k_make_dynview_obj(state_t *s, reg_t obj, int options, int nr, int funct_nr, in
cel = oldcel = sign_extend_byte(GET_SEL32V(obj, cel));
if (s->selector_map.palette)
- palette = GET_SEL32V(obj, palette); else
- palette = 0;
-
+ palette = GET_SEL32V(obj, palette);
+ else
+ palette = 0;
+
/* Clip loop and cel, write back if neccessary */
if (gfxop_check_cel(s->gfx_state, view_nr, &loop, &cel)) {
return NULL;
@@ -2103,7 +2068,7 @@ _k_make_dynview_obj(state_t *s, reg_t obj, int options, int nr, int funct_nr, in
}
if (lookup_selector(s, obj, s->selector_map.underBits, &(under_bitsp), NULL)
- != SELECTOR_VARIABLE) {
+ != SELECTOR_VARIABLE) {
under_bitsp = NULL;
under_bits = NULL_REG;
SCIkdebug(SCIkGRAPHICS, "Object at "PREG" has no underBits\n", PRINT_REG(obj));
@@ -2111,7 +2076,7 @@ _k_make_dynview_obj(state_t *s, reg_t obj, int options, int nr, int funct_nr, in
under_bits = *((reg_t *)under_bitsp);
if (lookup_selector(s, obj, s->selector_map.signal, &(signalp), NULL)
- != SELECTOR_VARIABLE) {
+ != SELECTOR_VARIABLE) {
signalp = NULL;
signal = 0;
SCIkdebug(SCIkGRAPHICS, "Object at "PREG" has no signal selector\n", PRINT_REG(obj));
@@ -2121,13 +2086,13 @@ _k_make_dynview_obj(state_t *s, reg_t obj, int options, int nr, int funct_nr, in
}
widget = gfxw_new_dyn_view(s->gfx_state, pos, z, view_nr, loop, cel, palette,
- -1, -1, ALIGN_CENTER, ALIGN_BOTTOM, nr);
+ -1, -1, ALIGN_CENTER, ALIGN_BOTTOM, nr);
if (widget) {
widget = (gfxw_dyn_view_t *) gfxw_set_id(GFXW(widget), obj.segment, obj.offset);
widget = gfxw_dyn_view_set_params(widget, under_bits.segment,
- under_bitsp, signal, signalp);
+ under_bitsp, signal, signalp);
widget->flags |= GFXW_FLAG_IMMUNE_TO_SNAPSHOTS; /* Only works the first time 'round */
return widget;
@@ -2140,11 +2105,11 @@ _k_make_dynview_obj(state_t *s, reg_t obj, int options, int nr, int funct_nr, in
static void
_k_make_view_list(state_t *s, gfxw_list_t **widget_list, list_t *list, int options,
- int funct_nr, int argc, reg_t *argv)
- /* Creates a view_list from a node list in heap space. Returns the list, stores the
- ** number of list entries in *list_nr. Calls doit for each entry if cycle is set.
- ** argc, argv, funct_nr should be the same as in the calling kernel function.
- */
+ int funct_nr, int argc, reg_t *argv)
+/* Creates a view_list from a node list in heap space. Returns the list, stores the
+** number of list entries in *list_nr. Calls doit for each entry if cycle is set.
+** argc, argv, funct_nr should be the same as in the calling kernel function.
+*/
{
node_t *node;
int sequence_nr = 0;
@@ -2183,21 +2148,21 @@ _k_make_view_list(state_t *s, gfxw_list_t **widget_list, list_t *list, int optio
next_node = node->succ; /* In case the cast list was changed */
if (list->first.segment == 0 &&
- list->first.offset == 0) /* The cast list was completely emptied! */
+ list->first.offset == 0) /* The cast list was completely emptied! */
break;
tempWidget = _k_make_dynview_obj(s, obj, options, sequence_nr--,
- funct_nr, argc, argv);
- if (tempWidget)
+ funct_nr, argc, argv);
+ if (tempWidget)
GFX_ASSERT((*widget_list)->add(GFXWC(*widget_list), GFXW(tempWidget)));
- node = LOOKUP_NODE(next_node); /* Next node */
- }
+ node = LOOKUP_NODE(next_node); /* Next node */
+ }
- widget = (gfxw_dyn_view_t *) (*widget_list)->contents;
+ widget = (gfxw_dyn_view_t *)(*widget_list)->contents;
- while(widget) { /* Read back widget values */
+ while (widget) { /* Read back widget values */
if (widget->signalp)
widget->signal = ((reg_t *)(widget->signalp))->offset;
@@ -2207,13 +2172,12 @@ _k_make_view_list(state_t *s, gfxw_list_t **widget_list, list_t *list, int optio
static void
-_k_prepare_view_list(state_t *s, gfxw_list_t *list, int options)
-{
+_k_prepare_view_list(state_t *s, gfxw_list_t *list, int options) {
gfxw_dyn_view_t *view = (gfxw_dyn_view_t *) list->contents;
while (view) {
reg_t obj = make_reg(view->ID, view->subID);
int priority, _priority;
- int has_nsrect = (view->ID <=0)? 0 : lookup_selector(s, obj, s->selector_map.nsBottom, NULL, NULL) == SELECTOR_VARIABLE;
+ int has_nsrect = (view->ID <= 0) ? 0 : lookup_selector(s, obj, s->selector_map.nsBottom, NULL, NULL) == SELECTOR_VARIABLE;
int oldsignal = view->signal;
_k_set_now_seen(s, obj);
@@ -2226,7 +2190,7 @@ _k_prepare_view_list(state_t *s, gfxw_list_t *list, int options)
priority = _priority; /* Always for picviews */
} else { /* Dynview */
if (has_nsrect
- && !(view->signal & _K_VIEW_SIG_FLAG_FIX_PRI_ON)) { /* Calculate priority */
+ && !(view->signal & _K_VIEW_SIG_FLAG_FIX_PRI_ON)) { /* Calculate priority */
if (options & _K_MAKE_VIEW_LIST_CALC_PRIORITY)
PUT_SEL32V(obj, priority, _priority);
@@ -2257,36 +2221,32 @@ _k_prepare_view_list(state_t *s, gfxw_list_t *list, int options)
/* Extreme Pattern Matching ugliness ahead... */
- if (view->signal & _K_VIEW_SIG_FLAG_NO_UPDATE) {
- if (((view->signal & (_K_VIEW_SIG_FLAG_UPDATED | _K_VIEW_SIG_FLAG_FORCE_UPDATE))) /* 9.1.1.1 */
- || ((view->signal & (_K_VIEW_SIG_FLAG_HIDDEN | _K_VIEW_SIG_FLAG_REMOVE)) == _K_VIEW_SIG_FLAG_HIDDEN)
- || ((view->signal & (_K_VIEW_SIG_FLAG_HIDDEN | _K_VIEW_SIG_FLAG_REMOVE)) == _K_VIEW_SIG_FLAG_REMOVE) /* 9.1.1.2 */
- || ((view->signal & (_K_VIEW_SIG_FLAG_HIDDEN | _K_VIEW_SIG_FLAG_REMOVE | _K_VIEW_SIG_FLAG_ALWAYS_UPDATE)) == _K_VIEW_SIG_FLAG_ALWAYS_UPDATE) /* 9.1.1.3 */
- || ((view->signal & (_K_VIEW_SIG_FLAG_HIDDEN | _K_VIEW_SIG_FLAG_ALWAYS_UPDATE)) == (_K_VIEW_SIG_FLAG_HIDDEN | _K_VIEW_SIG_FLAG_ALWAYS_UPDATE))) /* 9.1.1.4 */
- {
- s->pic_not_valid++;
- view->signal &= ~_K_VIEW_SIG_FLAG_STOP_UPDATE;
- }
-
- else if (((view->signal & (_K_VIEW_SIG_FLAG_HIDDEN | _K_VIEW_SIG_FLAG_REMOVE | _K_VIEW_SIG_FLAG_ALWAYS_UPDATE)) == 0)
- || ((view->signal & (_K_VIEW_SIG_FLAG_HIDDEN | _K_VIEW_SIG_FLAG_REMOVE | _K_VIEW_SIG_FLAG_ALWAYS_UPDATE)) == (_K_VIEW_SIG_FLAG_HIDDEN | _K_VIEW_SIG_FLAG_REMOVE))
- || ((view->signal & (_K_VIEW_SIG_FLAG_HIDDEN | _K_VIEW_SIG_FLAG_ALWAYS_UPDATE)) == (_K_VIEW_SIG_FLAG_HIDDEN | _K_VIEW_SIG_FLAG_ALWAYS_UPDATE))
- || ((view->signal & (_K_VIEW_SIG_FLAG_HIDDEN | _K_VIEW_SIG_FLAG_ALWAYS_UPDATE)) == _K_VIEW_SIG_FLAG_HIDDEN))
- {
- view->signal &= ~_K_VIEW_SIG_FLAG_STOP_UPDATE;
- }
+ if (view->signal & _K_VIEW_SIG_FLAG_NO_UPDATE) {
+ if (((view->signal & (_K_VIEW_SIG_FLAG_UPDATED | _K_VIEW_SIG_FLAG_FORCE_UPDATE))) /* 9.1.1.1 */
+ || ((view->signal & (_K_VIEW_SIG_FLAG_HIDDEN | _K_VIEW_SIG_FLAG_REMOVE)) == _K_VIEW_SIG_FLAG_HIDDEN)
+ || ((view->signal & (_K_VIEW_SIG_FLAG_HIDDEN | _K_VIEW_SIG_FLAG_REMOVE)) == _K_VIEW_SIG_FLAG_REMOVE) /* 9.1.1.2 */
+ || ((view->signal & (_K_VIEW_SIG_FLAG_HIDDEN | _K_VIEW_SIG_FLAG_REMOVE | _K_VIEW_SIG_FLAG_ALWAYS_UPDATE)) == _K_VIEW_SIG_FLAG_ALWAYS_UPDATE) /* 9.1.1.3 */
+ || ((view->signal & (_K_VIEW_SIG_FLAG_HIDDEN | _K_VIEW_SIG_FLAG_ALWAYS_UPDATE)) == (_K_VIEW_SIG_FLAG_HIDDEN | _K_VIEW_SIG_FLAG_ALWAYS_UPDATE))) { /* 9.1.1.4 */
+ s->pic_not_valid++;
+ view->signal &= ~_K_VIEW_SIG_FLAG_STOP_UPDATE;
+ }
+
+ else if (((view->signal & (_K_VIEW_SIG_FLAG_HIDDEN | _K_VIEW_SIG_FLAG_REMOVE | _K_VIEW_SIG_FLAG_ALWAYS_UPDATE)) == 0)
+ || ((view->signal & (_K_VIEW_SIG_FLAG_HIDDEN | _K_VIEW_SIG_FLAG_REMOVE | _K_VIEW_SIG_FLAG_ALWAYS_UPDATE)) == (_K_VIEW_SIG_FLAG_HIDDEN | _K_VIEW_SIG_FLAG_REMOVE))
+ || ((view->signal & (_K_VIEW_SIG_FLAG_HIDDEN | _K_VIEW_SIG_FLAG_ALWAYS_UPDATE)) == (_K_VIEW_SIG_FLAG_HIDDEN | _K_VIEW_SIG_FLAG_ALWAYS_UPDATE))
+ || ((view->signal & (_K_VIEW_SIG_FLAG_HIDDEN | _K_VIEW_SIG_FLAG_ALWAYS_UPDATE)) == _K_VIEW_SIG_FLAG_HIDDEN)) {
+ view->signal &= ~_K_VIEW_SIG_FLAG_STOP_UPDATE;
+ }
+ } else {
+ if (view->signal & _K_VIEW_SIG_FLAG_STOP_UPDATE) {
+ s->pic_not_valid++;
+ view->signal &= ~_K_VIEW_SIG_FLAG_FORCE_UPDATE;
+ } else { /* if not STOP_UPDATE */
+ if (view->signal & _K_VIEW_SIG_FLAG_ALWAYS_UPDATE)
+ s->pic_not_valid++;
+ view->signal &= ~_K_VIEW_SIG_FLAG_FORCE_UPDATE;
+ }
}
- else {
- if (view->signal & _K_VIEW_SIG_FLAG_STOP_UPDATE) {
- s->pic_not_valid++;
- view->signal &= ~_K_VIEW_SIG_FLAG_FORCE_UPDATE;
- }
- else { /* if not STOP_UPDATE */
- if (view->signal & _K_VIEW_SIG_FLAG_ALWAYS_UPDATE)
- s->pic_not_valid++;
- view->signal &= ~_K_VIEW_SIG_FLAG_FORCE_UPDATE;
- }
- }
SCIkdebug(SCIkGRAPHICS, " dv["PREG"]: signal %04x -> %04x\n", PRINT_REG(obj), oldsignal, view->signal);
@@ -2301,8 +2261,7 @@ _k_prepare_view_list(state_t *s, gfxw_list_t *list, int options)
}
static void
-_k_update_signals_in_view_list(gfxw_list_t *old_list, gfxw_list_t *new_list)
-{ /* O(n^2)... a bit painful, but much faster than the redraws it helps prevent */
+_k_update_signals_in_view_list(gfxw_list_t *old_list, gfxw_list_t *new_list) { /* O(n^2)... a bit painful, but much faster than the redraws it helps prevent */
gfxw_dyn_view_t *old_widget = (gfxw_dyn_view_t *) old_list->contents;
/* Traverses all old widgets, updates them with signals from the new widgets.
@@ -2315,8 +2274,8 @@ _k_update_signals_in_view_list(gfxw_list_t *old_list, gfxw_list_t *new_list)
gfxw_dyn_view_t *new_widget = (gfxw_dyn_view_t *) new_list->contents;
while (new_widget
- && (new_widget->ID != old_widget->ID
- || new_widget->subID != old_widget->subID))
+ && (new_widget->ID != old_widget->ID
+ || new_widget->subID != old_widget->subID))
new_widget = (gfxw_dyn_view_t *) new_widget->next;
if (new_widget) {
@@ -2324,14 +2283,14 @@ _k_update_signals_in_view_list(gfxw_list_t *old_list, gfxw_list_t *new_list)
/* Transfer 'stopupd' flag */
if ((new_widget->pos.x != old_widget->pos.x)
- || (new_widget->pos.y != old_widget->pos.y)
- /* ** No idea why this is supposed to be bad **
- || (new_widget->z != old_widget->z)
- || (new_widget->view != old_widget->view)
- || (new_widget->loop != old_widget->loop)
- || (new_widget->cel != old_widget->cel)
- */
- )
+ || (new_widget->pos.y != old_widget->pos.y)
+ /* ** No idea why this is supposed to be bad **
+ || (new_widget->z != old_widget->z)
+ || (new_widget->view != old_widget->view)
+ || (new_widget->loop != old_widget->loop)
+ || (new_widget->cel != old_widget->cel)
+ */
+ )
carry = 0;
old_widget->signal = new_widget->signal |= carry;
@@ -2342,8 +2301,7 @@ _k_update_signals_in_view_list(gfxw_list_t *old_list, gfxw_list_t *new_list)
}
static void
-_k_view_list_kryptonize(gfxw_widget_t *v)
-{
+_k_view_list_kryptonize(gfxw_widget_t *v) {
if (v) {
v->flags &= ~GFXW_FLAG_IMMUNE_TO_SNAPSHOTS;
_k_view_list_kryptonize(v->next);
@@ -2351,8 +2309,7 @@ _k_view_list_kryptonize(gfxw_widget_t *v)
}
static void
-_k_raise_topmost_in_view_list(state_t *s, gfxw_list_t *list, gfxw_dyn_view_t *view)
-{
+_k_raise_topmost_in_view_list(state_t *s, gfxw_list_t *list, gfxw_dyn_view_t *view) {
if (view) {
gfxw_dyn_view_t *next = (gfxw_dyn_view_t *) view->next;
@@ -2360,10 +2317,10 @@ _k_raise_topmost_in_view_list(state_t *s, gfxw_list_t *list, gfxw_dyn_view_t *vi
if ((view->signal & (_K_VIEW_SIG_FLAG_NO_UPDATE | _K_VIEW_SIG_FLAG_HIDDEN | _K_VIEW_SIG_FLAG_ALWAYS_UPDATE)) == 0) {
SCIkdebug(SCIkGRAPHICS, "Forcing precedence 2 at ["PREG"] with %04x\n", PRINT_REG(make_reg(view->ID, view->subID)), view->signal);
view->force_precedence = 2;
-
- if ((view->signal & (_K_VIEW_SIG_FLAG_REMOVE | _K_VIEW_SIG_FLAG_HIDDEN)) == _K_VIEW_SIG_FLAG_REMOVE) {
- view->signal &= ~_K_VIEW_SIG_FLAG_REMOVE;
- }
+
+ if ((view->signal & (_K_VIEW_SIG_FLAG_REMOVE | _K_VIEW_SIG_FLAG_HIDDEN)) == _K_VIEW_SIG_FLAG_REMOVE) {
+ view->signal &= ~_K_VIEW_SIG_FLAG_REMOVE;
+ }
}
gfxw_remove_widget_from_container(view->parent, GFXW(view));
@@ -2372,7 +2329,7 @@ _k_raise_topmost_in_view_list(state_t *s, gfxw_list_t *list, gfxw_dyn_view_t *vi
if (view->signal & _K_VIEW_SIG_FLAG_HIDDEN)
gfxw_hide_widget(GFXW(view));
- else
+ else
gfxw_show_widget(GFXW(view));
list->add(GFXWC(list), GFXW(view));
@@ -2383,8 +2340,7 @@ _k_raise_topmost_in_view_list(state_t *s, gfxw_list_t *list, gfxw_dyn_view_t *vi
static void
-_k_redraw_view_list(state_t *s, gfxw_list_t *list)
-{
+_k_redraw_view_list(state_t *s, gfxw_list_t *list) {
gfxw_dyn_view_t *view = (gfxw_dyn_view_t *) list->contents;
while (view) {
@@ -2408,7 +2364,7 @@ _k_redraw_view_list(state_t *s, gfxw_list_t *list)
if (view->signal & _K_VIEW_SIG_FLAG_ALWAYS_UPDATE)
view->signal &= ~(_K_VIEW_SIG_FLAG_STOP_UPDATE | _K_VIEW_SIG_FLAG_UPDATED
- | _K_VIEW_SIG_FLAG_NO_UPDATE | _K_VIEW_SIG_FLAG_FORCE_UPDATE);
+ | _K_VIEW_SIG_FLAG_NO_UPDATE | _K_VIEW_SIG_FLAG_FORCE_UPDATE);
SCIkdebug(SCIkGRAPHICS, " at substep 11/14: signal %04x\n", view->signal);
@@ -2440,7 +2396,7 @@ _k_redraw_view_list(state_t *s, gfxw_list_t *list)
void
_k_draw_view_list(state_t *s, gfxw_list_t *list, int flags)
- /* Draws list_nr members of list to s->pic. */
+/* Draws list_nr members of list to s->pic. */
{
gfxw_dyn_view_t *widget = (gfxw_dyn_view_t *) list->contents;
@@ -2453,7 +2409,7 @@ _k_draw_view_list(state_t *s, gfxw_list_t *list, int flags)
widget = gfxw_picviewize_dynview(widget);
if (GFXW_IS_DYN_VIEW(widget) && widget->ID) {
- word signal = (flags & _K_DRAW_VIEW_LIST_USE_SIGNAL)? ((reg_t *)(widget->signalp))->offset : 0;
+ word signal = (flags & _K_DRAW_VIEW_LIST_USE_SIGNAL) ? ((reg_t *)(widget->signalp))->offset : 0;
if (signal & _K_VIEW_SIG_FLAG_HIDDEN)
gfxw_hide_widget(GFXW(widget));
@@ -2461,12 +2417,12 @@ _k_draw_view_list(state_t *s, gfxw_list_t *list, int flags)
gfxw_show_widget(GFXW(widget));
if (!(flags & _K_DRAW_VIEW_LIST_USE_SIGNAL)
- || ((flags & _K_DRAW_VIEW_LIST_DISPOSEABLE) && (signal & _K_VIEW_SIG_FLAG_DISPOSE_ME))
- || ((flags & _K_DRAW_VIEW_LIST_NONDISPOSEABLE) && !(signal & _K_VIEW_SIG_FLAG_DISPOSE_ME))) {
+ || ((flags & _K_DRAW_VIEW_LIST_DISPOSEABLE) && (signal & _K_VIEW_SIG_FLAG_DISPOSE_ME))
+ || ((flags & _K_DRAW_VIEW_LIST_NONDISPOSEABLE) && !(signal & _K_VIEW_SIG_FLAG_DISPOSE_ME))) {
if (flags & _K_DRAW_VIEW_LIST_USE_SIGNAL) {
signal &= ~(_K_VIEW_SIG_FLAG_STOP_UPDATE | _K_VIEW_SIG_FLAG_UPDATED |
- _K_VIEW_SIG_FLAG_NO_UPDATE | _K_VIEW_SIG_FLAG_FORCE_UPDATE);
+ _K_VIEW_SIG_FLAG_NO_UPDATE | _K_VIEW_SIG_FLAG_FORCE_UPDATE);
/* Clear all of those flags */
if (signal & _K_VIEW_SIG_FLAG_HIDDEN)
@@ -2487,8 +2443,7 @@ _k_draw_view_list(state_t *s, gfxw_list_t *list, int flags)
}
reg_t
-kAddToPic(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kAddToPic(state_t *s, int funct_nr, int argc, reg_t *argv) {
gfxw_list_t *pic_views;
reg_t list_ref = argv[0];
@@ -2507,7 +2462,7 @@ kAddToPic(state_t *s, int funct_nr, int argc, reg_t *argv)
control = KP_SINT(argv[6]);
widget = GFXW(gfxw_new_dyn_view(s->gfx_state, gfx_point(x, y), 0, view, loop, cel, 0,
- priority, -1 /* No priority */ , ALIGN_CENTER, ALIGN_BOTTOM, 0));
+ priority, -1 /* No priority */ , ALIGN_CENTER, ALIGN_BOTTOM, 0));
if (!widget) {
SCIkwarn(SCIkERROR, "Attempt to single-add invalid picview (%d/%d/%d)\n", view, loop, cel);
@@ -2515,9 +2470,9 @@ kAddToPic(state_t *s, int funct_nr, int argc, reg_t *argv)
widget->ID = -1;
if (control >= 0) {
abs_rect_t abs_zone = nsrect_clip(s, y,
- calculate_nsrect(s, x, y,
- view, loop, cel),
- priority);
+ calculate_nsrect(s, x, y,
+ view, loop, cel),
+ priority);
draw_rect_to_control_map(s, abs_zone);
}
@@ -2529,11 +2484,11 @@ kAddToPic(state_t *s, int funct_nr, int argc, reg_t *argv)
if (!list_ref.segment) {
SCIkdebug(SCIkWARNING, "Attempt to AddToPic single non-list: "PREG"\n",
- PRINT_REG(list_ref));
+ PRINT_REG(list_ref));
return s->r_acc;
}
-
+
list = LOOKUP_LIST(list_ref);
pic_views = gfxw_new_list(s->picture_port->bounds, 1);
@@ -2556,23 +2511,20 @@ kAddToPic(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kGetPort(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kGetPort(state_t *s, int funct_nr, int argc, reg_t *argv) {
return make_reg(0, s->port->ID);
}
reg_t
-kSetPort(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
- if (activated_icon_bar && argc == 6)
- {
+kSetPort(state_t *s, int funct_nr, int argc, reg_t *argv) {
+ if (activated_icon_bar && argc == 6) {
port_origin_x = port_origin_y = 0;
activated_icon_bar = 0;
return s->r_acc;
}
- switch (argc) {
+ switch (argc) {
case 1 : {
unsigned int port_nr = SKPV(0);
gfxw_port_t *new_port;
@@ -2583,7 +2535,7 @@ kSetPort(state_t *s, int funct_nr, int argc, reg_t *argv)
official semantics) would cut off the lower part of the
icons in an SCI1 icon bar. Instead we have an
iconbar_port that does not exist in SSCI. */
- if (port_nr == (unsigned int)-1) port_nr = s->iconbar_port->ID;
+ if (port_nr == (unsigned int) - 1) port_nr = s->iconbar_port->ID;
new_port = gfxw_find_port(s->visual, port_nr);
@@ -2600,8 +2552,7 @@ kSetPort(state_t *s, int funct_nr, int argc, reg_t *argv)
port_origin_y = SKPV(0);
port_origin_x = SKPV(1);
- if (SKPV(0) == -10)
- {
+ if (SKPV(0) == -10) {
s->port->draw(GFXW(s->port), gfxw_point_zero); /* Update the port we're leaving */
s->port = s->iconbar_port;
activated_icon_bar = 1;
@@ -2609,7 +2560,7 @@ kSetPort(state_t *s, int funct_nr, int argc, reg_t *argv)
}
s->gfx_state->options->pic_port_bounds = gfx_rect(UKPV(5), UKPV(4),
- UKPV(3), UKPV(2));
+ UKPV(3), UKPV(2));
/* FIXME: Should really only invalidate all loaded pic resources here;
this is overkill */
gfxr_free_all_resources(s->gfx_state->driver, s->gfx_state->resstate);
@@ -2625,8 +2576,7 @@ kSetPort(state_t *s, int funct_nr, int argc, reg_t *argv)
}
static inline void
-add_to_chrono(state_t *s, gfxw_widget_t *widget)
-{
+add_to_chrono(state_t *s, gfxw_widget_t *widget) {
gfxw_port_t *chrono_port;
gfxw_list_t *tw;
@@ -2638,8 +2588,7 @@ add_to_chrono(state_t *s, gfxw_widget_t *widget)
}
reg_t
-kDrawCel(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kDrawCel(state_t *s, int funct_nr, int argc, reg_t *argv) {
int view = SKPV(0);
int loop = SKPV(1);
int cel = SKPV(2);
@@ -2648,23 +2597,23 @@ kDrawCel(state_t *s, int funct_nr, int argc, reg_t *argv)
int priority = SKPV_OR_ALT(5, -1);
gfxw_view_t *new_view;
-/*
- if (!view) {
- SCIkwarn(SCIkERROR, "Attempt to draw non-existing view.%03d\n", view);
- return;
- }
-*/
-
+ /*
+ if (!view) {
+ SCIkwarn(SCIkERROR, "Attempt to draw non-existing view.%03d\n", view);
+ return;
+ }
+ */
+
if (gfxop_check_cel(s->gfx_state, view, &loop, &cel)) {
SCIkwarn(SCIkERROR, "Attempt to draw non-existing view.%03d\n", view);
return s->r_acc;
}
SCIkdebug(SCIkGRAPHICS, "DrawCel((%d,%d), (view.%d, %d, %d), p=%d)\n", x, y, view, loop,
- cel, priority);
+ cel, priority);
new_view = gfxw_new_view(s->gfx_state, gfx_point(x, y), view, loop, cel, 0, priority, -1,
- ALIGN_LEFT, ALIGN_TOP, GFXW_VIEW_FLAG_DONT_MODIFY_OFFSET);
+ ALIGN_LEFT, ALIGN_TOP, GFXW_VIEW_FLAG_DONT_MODIFY_OFFSET);
#if 0
add_to_chrono(s, GFXW(new_view));
@@ -2673,14 +2622,13 @@ kDrawCel(state_t *s, int funct_nr, int argc, reg_t *argv)
#endif
FULL_REDRAW();
-
+
return s->r_acc;
}
reg_t
-kDisposeWindow(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kDisposeWindow(state_t *s, int funct_nr, int argc, reg_t *argv) {
unsigned int goner_nr = SKPV(0);
gfxw_port_t *goner;
gfxw_port_t *pred;
@@ -2705,9 +2653,9 @@ kDisposeWindow(state_t *s, int funct_nr, int argc, reg_t *argv)
if (goner == s->port) /* Did we kill the active port? */
s->port = pred;
-/* Find the last port that exists and that isn't marked no-switch */
+ /* Find the last port that exists and that isn't marked no-switch */
while ((!s->visual->port_refs[id] && id >= 0) ||
- (s->visual->port_refs[id]->flags & GFXW_FLAG_NO_IMPLICIT_SWITCH))
+ (s->visual->port_refs[id]->flags & GFXW_FLAG_NO_IMPLICIT_SWITCH))
id--;
sciprintf("Activating port %d after disposing window %d\n", id, goner_nr);
@@ -2721,8 +2669,7 @@ kDisposeWindow(state_t *s, int funct_nr, int argc, reg_t *argv)
}
reg_t
-kNewWindow(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kNewWindow(state_t *s, int funct_nr, int argc, reg_t *argv) {
gfxw_port_t *window;
int x, y, xl, yl, flags;
gfx_color_t bgcolor;
@@ -2739,19 +2686,19 @@ kNewWindow(state_t *s, int funct_nr, int argc, reg_t *argv)
y += s->wm_port->bounds.y;
- if (x+xl > 319)
- x -= ((x+xl) - 319);
+ if (x + xl > 319)
+ x -= ((x + xl) - 319);
- flags = SKPV(5+argextra);
+ flags = SKPV(5 + argextra);
- priority = SKPV_OR_ALT(6+argextra, -1);
+ priority = SKPV_OR_ALT(6 + argextra, -1);
bgcolor.mask = 0;
- if (SKPV_OR_ALT(8+argextra, 255) >= 0) {
+ if (SKPV_OR_ALT(8 + argextra, 255) >= 0) {
if (s->resmgr->sci_version < SCI_VERSION_01_VGA)
- bgcolor.visual = *(get_pic_color(s, SKPV_OR_ALT(8+argextra, 15)));
+ bgcolor.visual = *(get_pic_color(s, SKPV_OR_ALT(8 + argextra, 15)));
else
- bgcolor.visual = *(get_pic_color(s, SKPV_OR_ALT(8+argextra, 255)));
+ bgcolor.visual = *(get_pic_color(s, SKPV_OR_ALT(8 + argextra, 255)));
bgcolor.mask = GFX_MASK_VISUAL;
}
@@ -2760,29 +2707,29 @@ kNewWindow(state_t *s, int funct_nr, int argc, reg_t *argv)
bgcolor.alpha = 0;
SCIkdebug(SCIkGRAPHICS, "New window with params %d, %d, %d, %d\n", SKPV(0), SKPV(1), SKPV(2), SKPV(3));
- fgcolor.visual = *(get_pic_color(s, SKPV_OR_ALT(7+argextra, 0)));
+ fgcolor.visual = *(get_pic_color(s, SKPV_OR_ALT(7 + argextra, 0)));
fgcolor.mask = GFX_MASK_VISUAL;
fgcolor.alpha = 0;
black.visual = *(get_pic_color(s, 0));
black.mask = GFX_MASK_VISUAL;
black.alpha = 0;
lWhite.visual = *(get_pic_color(s, s->resmgr->sci_version < SCI_VERSION_01_VGA ? 15 : 255)),
- lWhite.mask = GFX_MASK_VISUAL;
+ lWhite.mask = GFX_MASK_VISUAL;
lWhite.alpha = 0;
window = sciw_new_window(s, gfx_rect(x, y, xl, yl), s->titlebar_port->font_nr,
- fgcolor, bgcolor, s->titlebar_port->font_nr,
- lWhite,
- black,
- argv[4+argextra].segment ? kernel_dereference_char_pointer(s, argv[4+argextra], 0) : NULL,
- flags);
+ fgcolor, bgcolor, s->titlebar_port->font_nr,
+ lWhite,
+ black,
+ argv[4+argextra].segment ? kernel_dereference_char_pointer(s, argv[4+argextra], 0) : NULL,
+ flags);
/* PQ3 has the interpreter store underBits implicitly.
The feature was promptly removed after its release, never to be seen again. */
if (argextra)
- gfxw_port_auto_restore_background(s->visual, window,
- gfx_rect(SKPV(5), SKPV(4),
- SKPV(7)-SKPV(5), SKPV(6)-SKPV(4)));
+ gfxw_port_auto_restore_background(s->visual, window,
+ gfx_rect(SKPV(5), SKPV(4),
+ SKPV(7) - SKPV(5), SKPV(6) - SKPV(4)));
ADD_TO_WINDOW_PORT(window);
FULL_REDRAW();
@@ -2812,9 +2759,9 @@ kNewWindow(state_t *s, int funct_nr, int argc, reg_t *argv)
#define K_ANIMATE_TOP_CLOSE_BOTTOM_OPEN 13 /* close to bottom, reopen from bottom */
#define K_ANIMATE_BOTTOM_CLOSE_TOP_OPEN 14 /* close to top, reopen from top */
#define K_ANIMATE_CENTER_CLOSE_F_BORDER_OPEN_F 15 /* close from center to edges,
- ** reopen from edges to center */
+** reopen from edges to center */
#define K_ANIMATE_BORDER_CLOSE_F_CENTER_OPEN_F 16 /* close from edges to center, reopen from
- ** center to edges */
+** center to edges */
#define K_ANIMATE_CLOSE_CHECKERS_OPEN_CHECKERS 17 /* close random checkboard, reopen */
#define K_ANIMATE_SCROLL_LEFT 0x28
#define K_ANIMATE_SCROLL_RIGHT 0x29
@@ -2832,8 +2779,7 @@ kNewWindow(state_t *s, int funct_nr, int argc, reg_t *argv)
static void
-animate_do_animation(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+animate_do_animation(state_t *s, int funct_nr, int argc, reg_t *argv) {
int i, remaining_checkers;
int update_counter;
int granularity0 = s->animation_granularity << 1;
@@ -2866,13 +2812,13 @@ animate_do_animation(state_t *s, int funct_nr, int argc, reg_t *argv)
s->pic_animate = K_ANIMATE_OPEN_SIMPLE;
- switch(s->pic_animate) {
+ switch (s->pic_animate) {
case K_ANIMATE_BORDER_CLOSE_H_CENTER_OPEN_H :
for (i = 0; i < 159 + granularity1; i += granularity1) {
GRAPH_BLANK_BOX(s, i, 10, granularity1, 190, 0);
gfxop_update(s->gfx_state);
- GRAPH_BLANK_BOX(s, 319-i, 10, granularity1, 190, 0);
+ GRAPH_BLANK_BOX(s, 319 - i, 10, granularity1, 190, 0);
gfxop_update(s->gfx_state);
gfxop_usleep(s->gfx_state, s->animation_delay);
process_sound_events(s);
@@ -2881,10 +2827,10 @@ animate_do_animation(state_t *s, int funct_nr, int argc, reg_t *argv)
case K_ANIMATE_CENTER_OPEN_H :
- for (i = 159; i >= 1-granularity1; i -= granularity1) {
+ for (i = 159; i >= 1 - granularity1; i -= granularity1) {
GRAPH_UPDATE_BOX(s, i, 10, granularity1, 190);
gfxop_update(s->gfx_state);
- GRAPH_UPDATE_BOX(s, 319-i, 10, granularity1, 190);
+ GRAPH_UPDATE_BOX(s, 319 - i, 10, granularity1, 190);
gfxop_update(s->gfx_state);
gfxop_usleep(s->gfx_state, s->animation_delay);
process_sound_events(s);
@@ -2919,7 +2865,7 @@ animate_do_animation(state_t *s, int funct_nr, int argc, reg_t *argv)
case K_ANIMATE_LEFT_CLOSE_RIGHT_OPEN :
- for(i = 0; i < 319 + granularity0; i += granularity0) {
+ for (i = 0; i < 319 + granularity0; i += granularity0) {
GRAPH_BLANK_BOX(s, i, 10, granularity0, 190, 0);
gfxop_update(s->gfx_state);
gfxop_usleep(s->gfx_state, s->animation_delay / 2);
@@ -2928,7 +2874,7 @@ animate_do_animation(state_t *s, int funct_nr, int argc, reg_t *argv)
GRAPH_BLANK_BOX(s, 0, 10, 320, 190, 0);
case K_ANIMATE_RIGHT_OPEN :
- for(i = 319; i >= 1 - granularity0; i -= granularity0) {
+ for (i = 319; i >= 1 - granularity0; i -= granularity0) {
GRAPH_UPDATE_BOX(s, i, 10, granularity0, 190);
gfxop_update(s->gfx_state);
gfxop_usleep(s->gfx_state, s->animation_delay / 2);
@@ -2939,7 +2885,7 @@ animate_do_animation(state_t *s, int funct_nr, int argc, reg_t *argv)
case K_ANIMATE_RIGHT_CLOSE_LEFT_OPEN :
- for(i = 319; i >= 1-granularity0; i -= granularity0) {
+ for (i = 319; i >= 1 - granularity0; i -= granularity0) {
GRAPH_BLANK_BOX(s, i, 10, granularity0, 190, 0);
gfxop_update(s->gfx_state);
gfxop_usleep(s->gfx_state, s->animation_delay / 2);
@@ -2949,7 +2895,7 @@ animate_do_animation(state_t *s, int funct_nr, int argc, reg_t *argv)
case K_ANIMATE_LEFT_OPEN :
- for(i = 0; i < 319 + granularity0; i+= granularity0) {
+ for (i = 0; i < 319 + granularity0; i += granularity0) {
GRAPH_UPDATE_BOX(s, i, 10, granularity0, 190);
gfxop_update(s->gfx_state);
gfxop_usleep(s->gfx_state, s->animation_delay / 2);
@@ -2970,7 +2916,7 @@ animate_do_animation(state_t *s, int funct_nr, int argc, reg_t *argv)
case K_ANIMATE_BOTTOM_OPEN :
- for (i = 199; i >= 11 - granularity1; i-= granularity1) {
+ for (i = 199; i >= 11 - granularity1; i -= granularity1) {
GRAPH_UPDATE_BOX(s, 0, i, 320, granularity1);
gfxop_update(s->gfx_state);
gfxop_usleep(s->gfx_state, s->animation_delay);
@@ -2981,7 +2927,7 @@ animate_do_animation(state_t *s, int funct_nr, int argc, reg_t *argv)
case K_ANIMATE_BOTTOM_CLOSE_TOP_OPEN :
- for (i = 199; i >= 11 - granularity1; i-= granularity1) {
+ for (i = 199; i >= 11 - granularity1; i -= granularity1) {
GRAPH_BLANK_BOX(s, 0, i, 320, granularity1, 0);
gfxop_update(s->gfx_state);
gfxop_usleep(s->gfx_state, s->animation_delay);
@@ -2991,7 +2937,7 @@ animate_do_animation(state_t *s, int funct_nr, int argc, reg_t *argv)
case K_ANIMATE_TOP_OPEN :
- for (i = 10; i < 199 + granularity1; i+= granularity1) {
+ for (i = 10; i < 199 + granularity1; i += granularity1) {
GRAPH_UPDATE_BOX(s, 0, i, 320, granularity1);
gfxop_update(s->gfx_state);
gfxop_usleep(s->gfx_state, s->animation_delay);
@@ -3002,25 +2948,25 @@ animate_do_animation(state_t *s, int funct_nr, int argc, reg_t *argv)
case K_ANIMATE_CENTER_CLOSE_F_BORDER_OPEN_F :
- for (i = 31; i >= 1-granularity3; i -= granularity3) {
- int real_i = (i < 0)? 0 : i;
+ for (i = 31; i >= 1 - granularity3; i -= granularity3) {
+ int real_i = (i < 0) ? 0 : i;
int height_l = 3 * (granularity3 - real_i + i);
int width_l = 5 * (granularity3 - real_i + i);
int height = real_i * 3;
int width = real_i * 5;
GRAPH_BLANK_BOX(s, width, 10 + height,
- width_l, 190 - 2*height, 0);
+ width_l, 190 - 2*height, 0);
gfxop_update(s->gfx_state);
GRAPH_BLANK_BOX(s, 320 - width_l - width,
- 10 + height, width_l, 190 - 2*height, 0);
+ 10 + height, width_l, 190 - 2*height, 0);
gfxop_update(s->gfx_state);
GRAPH_BLANK_BOX(s, width, 10 + height,
- 320 - 2*width, height_l, 0);
+ 320 - 2*width, height_l, 0);
gfxop_update(s->gfx_state);
GRAPH_BLANK_BOX(s, width, 200 - height_l - height,
- 320 - 2*width, height_l, 0);
+ 320 - 2*width, height_l, 0);
gfxop_update(s->gfx_state);
gfxop_usleep(s->gfx_state, 4 * s->animation_delay);
@@ -3030,25 +2976,25 @@ animate_do_animation(state_t *s, int funct_nr, int argc, reg_t *argv)
case K_ANIMATE_BORDER_OPEN_F :
- for (i = 0; i < 31+granularity3; i += granularity3) {
- int real_i = (i < 0)? 0 : i;
+ for (i = 0; i < 31 + granularity3; i += granularity3) {
+ int real_i = (i < 0) ? 0 : i;
int height_l = 3 * (granularity3 - real_i + i);
int width_l = 5 * (granularity3 - real_i + i);
int height = real_i * 3;
int width = real_i * 5;
GRAPH_UPDATE_BOX(s, width, 10 + height,
- width_l, 190 - 2*height);
+ width_l, 190 - 2*height);
gfxop_update(s->gfx_state);
GRAPH_UPDATE_BOX(s, 320 - width_l - width,
- 10 + height, width_l, 190 - 2*height);
+ 10 + height, width_l, 190 - 2*height);
gfxop_update(s->gfx_state);
GRAPH_UPDATE_BOX(s, width, 10 + height,
- 320 - 2*width, height_l);
+ 320 - 2*width, height_l);
gfxop_update(s->gfx_state);
GRAPH_UPDATE_BOX(s, width, 200 - height_l - height,
- 320 - 2*width, height_l);
+ 320 - 2*width, height_l);
gfxop_update(s->gfx_state);
gfxop_usleep(s->gfx_state, 4 * s->animation_delay);
@@ -3060,25 +3006,25 @@ animate_do_animation(state_t *s, int funct_nr, int argc, reg_t *argv)
case K_ANIMATE_BORDER_CLOSE_F_CENTER_OPEN_F :
- for (i = 0; i < 31+granularity3; i += granularity3) {
- int real_i = (i < 0)? 0 : i;
+ for (i = 0; i < 31 + granularity3; i += granularity3) {
+ int real_i = (i < 0) ? 0 : i;
int height_l = 3 * (granularity3 - real_i + i);
int width_l = 5 * (granularity3 - real_i + i);
int height = real_i * 3;
int width = real_i * 5;
GRAPH_BLANK_BOX(s, width, 10 + height,
- width_l, 190 - 2*height, 0);
+ width_l, 190 - 2*height, 0);
gfxop_update(s->gfx_state);
GRAPH_BLANK_BOX(s, 320 - width_l - width,
- 10 + height, width_l, 190 - 2*height, 0);
+ 10 + height, width_l, 190 - 2*height, 0);
gfxop_update(s->gfx_state);
GRAPH_BLANK_BOX(s, width, 10 + height,
- 320 - 2*width, height_l, 0);
+ 320 - 2*width, height_l, 0);
gfxop_update(s->gfx_state);
GRAPH_BLANK_BOX(s, width, 200 - height_l - height,
- 320 - 2*width, height_l, 0);
+ 320 - 2*width, height_l, 0);
gfxop_update(s->gfx_state);
gfxop_usleep(s->gfx_state, 7 * s->animation_delay);
@@ -3088,25 +3034,25 @@ animate_do_animation(state_t *s, int funct_nr, int argc, reg_t *argv)
case K_ANIMATE_CENTER_OPEN_F :
- for (i = 31; i >= 1-granularity3; i -= granularity3) {
- int real_i = (i < 0)? 0 : i;
+ for (i = 31; i >= 1 - granularity3; i -= granularity3) {
+ int real_i = (i < 0) ? 0 : i;
int height_l = 3 * (granularity3 - real_i + i);
int width_l = 5 * (granularity3 - real_i + i);
int height = real_i * 3;
int width = real_i * 5;
GRAPH_UPDATE_BOX(s, width, 10 + height,
- width_l, 190 - 2*height);
+ width_l, 190 - 2*height);
gfxop_update(s->gfx_state);
GRAPH_UPDATE_BOX(s, 320 - width_l - width,
- 10 + height, width_l, 190 - 2*height);
+ 10 + height, width_l, 190 - 2*height);
gfxop_update(s->gfx_state);
GRAPH_UPDATE_BOX(s, width, 10 + height,
- 320 - 2 * width, height_l);
+ 320 - 2 * width, height_l);
gfxop_update(s->gfx_state);
GRAPH_UPDATE_BOX(s, width, 200 - height_l - height,
- 320 - 2 * width, height_l);
+ 320 - 2 * width, height_l);
gfxop_update(s->gfx_state);
gfxop_usleep(s->gfx_state, 7 * s->animation_delay);
@@ -3123,7 +3069,7 @@ animate_do_animation(state_t *s, int funct_nr, int argc, reg_t *argv)
update_counter = granularity1;
while (remaining_checkers) {
- int x, y, checker = 1 + (int) (1.0 * remaining_checkers*rand()/(RAND_MAX+1.0));
+ int x, y, checker = 1 + (int)(1.0 * remaining_checkers * rand() / (RAND_MAX + 1.0));
i = -1;
while (checker)
@@ -3154,7 +3100,7 @@ animate_do_animation(state_t *s, int funct_nr, int argc, reg_t *argv)
update_counter = granularity1;
while (remaining_checkers) {
- int x, y, checker = 1 + (int) (1.0 * remaining_checkers * rand()/(RAND_MAX+1.0));
+ int x, y, checker = 1 + (int)(1.0 * remaining_checkers * rand() / (RAND_MAX + 1.0));
i = -1;
while (checker)
@@ -3185,11 +3131,11 @@ animate_do_animation(state_t *s, int funct_nr, int argc, reg_t *argv)
for (i = 0; i < 319; i += granularity0) {
GFX_ASSERT(gfxop_draw_pixmap(s->gfx_state, newscreen,
- gfx_rect(320 - i, 0, i, 190),
- gfx_point(0, 10)));
+ gfx_rect(320 - i, 0, i, 190),
+ gfx_point(0, 10)));
GFX_ASSERT(gfxop_draw_pixmap(s->gfx_state, s->old_screen,
- gfx_rect(0, 0, 320 - i, 190),
- gfx_point(i, 10)));
+ gfx_rect(0, 0, 320 - i, 190),
+ gfx_point(i, 10)));
gfxop_update(s->gfx_state);
gfxop_usleep(s->gfx_state, s->animation_delay >> 3);
@@ -3201,11 +3147,11 @@ animate_do_animation(state_t *s, int funct_nr, int argc, reg_t *argv)
for (i = 0; i < 319; i += granularity0) {
GFX_ASSERT(gfxop_draw_pixmap(s->gfx_state, newscreen,
- gfx_rect(0, 0, i, 190),
- gfx_point(319-i, 10)));
+ gfx_rect(0, 0, i, 190),
+ gfx_point(319 - i, 10)));
GFX_ASSERT(gfxop_draw_pixmap(s->gfx_state, s->old_screen,
- gfx_rect(i, 0, 320 - i, 190),
- gfx_point(0, 10)));
+ gfx_rect(i, 0, 320 - i, 190),
+ gfx_point(0, 10)));
gfxop_update(s->gfx_state);
gfxop_usleep(s->gfx_state, s->animation_delay >> 3);
@@ -3217,11 +3163,11 @@ animate_do_animation(state_t *s, int funct_nr, int argc, reg_t *argv)
for (i = 0; i < 189; i += granularity0) {
GFX_ASSERT(gfxop_draw_pixmap(s->gfx_state, newscreen,
- gfx_rect(0, 190 - i, 320, i),
- gfx_point(0, 10)));
+ gfx_rect(0, 190 - i, 320, i),
+ gfx_point(0, 10)));
GFX_ASSERT(gfxop_draw_pixmap(s->gfx_state, s->old_screen,
- gfx_rect(0, 0, 320, 190 - i),
- gfx_point(0, 10 + i)));
+ gfx_rect(0, 0, 320, 190 - i),
+ gfx_point(0, 10 + i)));
gfxop_update(s->gfx_state);
gfxop_usleep(s->gfx_state, s->animation_delay >> 3);
@@ -3233,11 +3179,11 @@ animate_do_animation(state_t *s, int funct_nr, int argc, reg_t *argv)
for (i = 0; i < 189; i += granularity0) {
GFX_ASSERT(gfxop_draw_pixmap(s->gfx_state, newscreen,
- gfx_rect(0, 0, 320, i),
- gfx_point(0, 200 - i)));
+ gfx_rect(0, 0, 320, i),
+ gfx_point(0, 200 - i)));
GFX_ASSERT(gfxop_draw_pixmap(s->gfx_state, s->old_screen,
- gfx_rect(0, i, 320, 190 - i),
- gfx_point(0, 10)));
+ gfx_rect(0, i, 320, 190 - i),
+ gfx_point(0, 10)));
gfxop_update(s->gfx_state);
gfxop_usleep(s->gfx_state, s->animation_delay >> 3);
@@ -3261,7 +3207,7 @@ animate_do_animation(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
kAnimate(state_t *s, int funct_nr, int argc, reg_t *argv)
- /* Animations are supposed to take a maximum of s->animation_delay milliseconds. */
+/* Animations are supposed to take a maximum of s->animation_delay milliseconds. */
{
reg_t cast_list_ref = KP_ALT(0, NULL_REG);
int cycle = (KP_ALT(1, NULL_REG)).offset;
@@ -3286,22 +3232,22 @@ kAnimate(state_t *s, int funct_nr, int argc, reg_t *argv)
assert_primary_widget_lists(s);
if (!s->dyn_views->contents /* Only reparentize empty dynview list */
- && ((GFXWC(s->port) != GFXWC(s->dyn_views->parent)) /* If dynviews are on other port... */
- || (s->dyn_views->next))) /* ... or not on top of the view list */
+ && ((GFXWC(s->port) != GFXWC(s->dyn_views->parent)) /* If dynviews are on other port... */
+ || (s->dyn_views->next))) /* ... or not on top of the view list */
reparentize_primary_widget_lists(s, s->port);
if (cast_list) {
gfxw_list_t *templist = gfxw_new_list(s->dyn_views->bounds, 0);
- _k_make_view_list(s, &(templist), cast_list, (cycle? _K_MAKE_VIEW_LIST_CYCLE : 0)
- | _K_MAKE_VIEW_LIST_CALC_PRIORITY, funct_nr, argc, argv);
+ _k_make_view_list(s, &(templist), cast_list, (cycle ? _K_MAKE_VIEW_LIST_CYCLE : 0)
+ | _K_MAKE_VIEW_LIST_CALC_PRIORITY, funct_nr, argc, argv);
/* Make sure that none of the doits() did something evil */
assert_primary_widget_lists(s);
if (!s->dyn_views->contents /* Only reparentize empty dynview list */
- && ((GFXWC(s->port) != GFXWC(s->dyn_views->parent)) /* If dynviews are on other port... */
- || (s->dyn_views->next))) /* ... or not on top of the view list */
+ && ((GFXWC(s->port) != GFXWC(s->dyn_views->parent)) /* If dynviews are on other port... */
+ || (s->dyn_views->next))) /* ... or not on top of the view list */
reparentize_primary_widget_lists(s, s->port);
/* End of doit() recovery code */
@@ -3360,8 +3306,8 @@ kAnimate(state_t *s, int funct_nr, int argc, reg_t *argv)
}
if ((reparentize | retval)
- && (GFXWC(s->port) == GFXWC(s->dyn_views->parent)) /* If dynviews are on the same port... */
- && (s->dyn_views->next)) /* ... and not on top of the view list... */
+ && (GFXWC(s->port) == GFXWC(s->dyn_views->parent)) /* If dynviews are on the same port... */
+ && (s->dyn_views->next)) /* ... and not on top of the view list... */
reparentize_primary_widget_lists(s, s->port); /* ...then reparentize. */
_k_view_list_kryptonize(s->dyn_views->contents);
@@ -3375,8 +3321,7 @@ kAnimate(state_t *s, int funct_nr, int argc, reg_t *argv)
#define SHAKE_RIGHT 2
reg_t
-kShakeScreen(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kShakeScreen(state_t *s, int funct_nr, int argc, reg_t *argv) {
int shakes = SKPV_OR_ALT(0, 1);
int directions = SKPV_OR_ALT(1, 1);
gfx_pixmap_t *screen = gfxop_grab_pixmap(s->gfx_state, gfx_rect(0, 0, 320, 200));
@@ -3388,8 +3333,8 @@ kShakeScreen(state_t *s, int funct_nr, int argc, reg_t *argv)
gfxop_set_clip_zone(s->gfx_state, gfx_rect_fullscreen);
for (i = 0; i < shakes; i++) {
- int shake_down = (directions & SHAKE_DOWN)? 10 : 0;
- int shake_right = (directions & SHAKE_RIGHT)? 10 : 0;
+ int shake_down = (directions & SHAKE_DOWN) ? 10 : 0;
+ int shake_right = (directions & SHAKE_RIGHT) ? 10 : 0;
if (directions & SHAKE_DOWN)
gfxop_draw_box(s->gfx_state, gfx_rect(0, 0, 320, 10), s->ega_colors[0], s->ega_colors[0], GFX_BOX_SHADE_FLAT);
@@ -3398,7 +3343,7 @@ kShakeScreen(state_t *s, int funct_nr, int argc, reg_t *argv)
gfxop_draw_box(s->gfx_state, gfx_rect(0, 0, 10, 200), s->ega_colors[0], s->ega_colors[0], GFX_BOX_SHADE_FLAT);
gfxop_draw_pixmap(s->gfx_state, screen, gfx_rect(0, 0, 320 - shake_right, 200 - shake_down),
- gfx_point(shake_right, shake_down));
+ gfx_point(shake_right, shake_down));
gfxop_update(s->gfx_state);
gfxop_usleep(s->gfx_state, 50000);
@@ -3427,8 +3372,7 @@ kShakeScreen(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kDisplay(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kDisplay(state_t *s, int funct_nr, int argc, reg_t *argv) {
int argpt;
reg_t textp = argv[0];
int index = UKPV_OR_ALT(1, 0);
@@ -3436,13 +3380,13 @@ kDisplay(state_t *s, int funct_nr, int argc, reg_t *argv)
int save_under = 0;
gfx_color_t transparent;
char *text;
- gfxw_port_t *port = (s->port)? s->port : s->picture_port;
+ gfxw_port_t *port = (s->port) ? s->port : s->picture_port;
int update_immediately = 1;
gfx_color_t color0, *color1, bg_color;
gfx_alignment_t halign = ALIGN_LEFT;
- rect_t area = gfx_rect(port->draw_pos.x, port->draw_pos.y,
- 320 - port->draw_pos.x, 200 - port->draw_pos.y);
+ rect_t area = gfx_rect(port->draw_pos.x, port->draw_pos.y,
+ 320 - port->draw_pos.x, 200 - port->draw_pos.y);
int gray = port->gray_text;
int font_nr = port->font_nr;
gfxw_text_t *text_handle;
@@ -3468,7 +3412,7 @@ kDisplay(state_t *s, int funct_nr, int argc, reg_t *argv)
while (argpt < argc) {
- switch(UKPV(argpt++)) {
+ switch (UKPV(argpt++)) {
case K_DISPLAY_SET_COORDS:
@@ -3489,7 +3433,7 @@ kDisplay(state_t *s, int funct_nr, int argc, reg_t *argv)
SCIkdebug(SCIkGRAPHICS, "Display: set_color(%d)\n", temp);
if ((s->resmgr->sci_version < SCI_VERSION_01_VGA) && temp >= 0 && temp <= 15)
color0 = (s->ega_colors[temp]);
- else
+ else
if ((s->resmgr->sci_version >= SCI_VERSION_01_VGA) && temp >= 0 && temp < 256) {
color0.visual = *(get_pic_color(s, temp));
color0.mask = GFX_MASK_VISUAL;
@@ -3506,9 +3450,9 @@ kDisplay(state_t *s, int funct_nr, int argc, reg_t *argv)
SCIkdebug(SCIkGRAPHICS, "Display: set_bg_color(%d)\n", temp);
if ((s->resmgr->sci_version < SCI_VERSION_01_VGA) && temp >= 0 && temp <= 15)
bg_color = s->ega_colors[temp];
- else
+ else
if ((s->resmgr->sci_version >= SCI_VERSION_01_VGA) && temp >= 0 && temp <= 256) {
- bg_color.visual = *get_pic_color(s, temp);
+ bg_color.visual = *get_pic_color(s, temp);
bg_color.mask = GFX_MASK_VISUAL;
} else
if (temp == -1)
@@ -3526,7 +3470,7 @@ kDisplay(state_t *s, int funct_nr, int argc, reg_t *argv)
case K_DISPLAY_SET_FONT:
font_nr = KP_UINT(argv[argpt++]);
-
+
SCIkdebug(SCIkGRAPHICS, "Display: set_font(\"font.%03d\")\n", font_nr);
break;
@@ -3555,13 +3499,13 @@ kDisplay(state_t *s, int funct_nr, int argc, reg_t *argv)
case K_DONT_UPDATE_IMMEDIATELY:
- update_immediately=0;
+ update_immediately = 0;
SCIkdebug(SCIkGRAPHICS, "Display: set_dont_update()\n");
argpt++;
break;
default:
- SCIkdebug(SCIkGRAPHICS, "Unknown Display() command %x\n", UKPV(argpt-1));
+ SCIkdebug(SCIkGRAPHICS, "Unknown Display() command %x\n", UKPV(argpt - 1));
return NULL_REG;
}
}
@@ -3569,15 +3513,14 @@ kDisplay(state_t *s, int funct_nr, int argc, reg_t *argv)
if (s->version >= SCI_VERSION_FTU_DISPLAY_COORDS_FUZZY) {
if (halign == ALIGN_LEFT)
GFX_ASSERT(gfxop_get_text_params(s->gfx_state, font_nr, text,
- area.xl, &area.xl, &area.yl, 0,
- NULL, NULL, NULL));
+ area.xl, &area.xl, &area.yl, 0,
+ NULL, NULL, NULL));
/* Make the text fit on the screen */
if (area.x + area.xl > 320)
area.x += 320 - area.x - area.xl; /* Plus negative number = subtraction */
- if (area.y + area.yl > 200)
- {
+ if (area.y + area.yl > 200) {
area.y += 200 - area.y - area.yl; /* Plus negative number = subtraction */
}
}
@@ -3590,7 +3533,7 @@ kDisplay(state_t *s, int funct_nr, int argc, reg_t *argv)
assert_primary_widget_lists(s);
text_handle = gfxw_new_text(s->gfx_state, area, font_nr, text, halign,
- ALIGN_TOP, color0, *color1, bg_color, 0);
+ ALIGN_TOP, color0, *color1, bg_color, 0);
if (!text_handle) {
SCIkwarn(SCIkERROR, "Display: Failed to create text widget!\n");
@@ -3606,7 +3549,7 @@ kDisplay(state_t *s, int funct_nr, int argc, reg_t *argv)
text_handle->serial++; /* This is evil! */
SCIkdebug(SCIkGRAPHICS, "Saving (%d, %d) size (%d, %d) as "PREG"\n",
- save_area.x, save_area.y, save_area.xl, save_area.yl, s->r_acc);
+ save_area.x, save_area.y, save_area.xl, save_area.yl, s->r_acc);
}
@@ -3618,7 +3561,7 @@ kDisplay(state_t *s, int funct_nr, int argc, reg_t *argv)
*/
ADD_TO_CURRENT_FG_WIDGETS(GFXW(text_handle));
- if ((!s->pic_not_valid)&&update_immediately) { /* Refresh if drawn to valid picture */
+ if ((!s->pic_not_valid) && update_immediately) { /* Refresh if drawn to valid picture */
FULL_REDRAW();
SCIkdebug(SCIkGRAPHICS, "Refreshing display...\n");
}
diff --git a/engines/sci/engine/klists.cpp b/engines/sci/engine/klists.cpp
index d76acfbbbd..f2b1dc64dd 100644
--- a/engines/sci/engine/klists.cpp
+++ b/engines/sci/engine/klists.cpp
@@ -33,8 +33,7 @@
#endif
inline node_t *
-inline_lookup_node(state_t *s, reg_t addr, const char *file, int line)
-{
+inline_lookup_node(state_t *s, reg_t addr, const char *file, int line) {
mem_obj_t *mobj;
node_table_t *nt;
@@ -44,7 +43,7 @@ inline_lookup_node(state_t *s, reg_t addr, const char *file, int line)
mobj = GET_SEGMENT(s->seg_manager, addr.segment, MEM_OBJ_NODES);
if (!mobj) {
sciprintf("%s, L%d: Attempt to use non-node "PREG" as list node\n",
- __FILE__, __LINE__, PRINT_REG(addr));
+ __FILE__, __LINE__, PRINT_REG(addr));
script_debug_flag = script_error_flag = 1;
return NULL;
}
@@ -53,7 +52,7 @@ inline_lookup_node(state_t *s, reg_t addr, const char *file, int line)
if (!ENTRY_IS_VALID(nt, addr.offset)) {
sciprintf("%s, L%d: Attempt to use non-node "PREG" as list node\n",
- __FILE__, __LINE__, PRINT_REG(addr));
+ __FILE__, __LINE__, PRINT_REG(addr));
script_debug_flag = script_error_flag = 1;
return NULL;
}
@@ -62,8 +61,7 @@ inline_lookup_node(state_t *s, reg_t addr, const char *file, int line)
}
node_t *
-lookup_node(state_t *s, reg_t addr, const char *file, int line)
-{
+lookup_node(state_t *s, reg_t addr, const char *file, int line) {
return inline_lookup_node(s, addr, file, line);
}
@@ -71,8 +69,7 @@ lookup_node(state_t *s, reg_t addr, const char *file, int line)
inline list_t *
-_lookup_list(state_t *s, reg_t addr, const char *file, int line, int may_be_null)
-{
+_lookup_list(state_t *s, reg_t addr, const char *file, int line, int may_be_null) {
mem_obj_t *mobj;
list_table_t *lt;
@@ -83,7 +80,7 @@ _lookup_list(state_t *s, reg_t addr, const char *file, int line, int may_be_null
if (!mobj) {
sciprintf("%s, L%d: Attempt to use non-list "PREG" as list\n",
- __FILE__, __LINE__, PRINT_REG(addr));
+ __FILE__, __LINE__, PRINT_REG(addr));
script_debug_flag = script_error_flag = 1;
return NULL;
}
@@ -92,7 +89,7 @@ _lookup_list(state_t *s, reg_t addr, const char *file, int line, int may_be_null
if (!ENTRY_IS_VALID(lt, addr.offset)) {
sciprintf("%s, L%d: Attempt to use non-list "PREG" as list\n",
- __FILE__, __LINE__, PRINT_REG(addr));
+ __FILE__, __LINE__, PRINT_REG(addr));
script_debug_flag = script_error_flag = 1;
return NULL;
}
@@ -101,16 +98,14 @@ _lookup_list(state_t *s, reg_t addr, const char *file, int line, int may_be_null
}
list_t *
-lookup_list(state_t *s, reg_t addr, const char *file, int line)
-{
+lookup_list(state_t *s, reg_t addr, const char *file, int line) {
return _lookup_list(s, addr, file, line, 0);
}
int
-listp(state_t *s, reg_t addr)
-{
+listp(state_t *s, reg_t addr) {
return (s->seg_manager.heap[addr.segment]->type == MEM_OBJ_LISTS
- && ENTRY_IS_VALID(&(s->seg_manager.heap[addr.segment]->data.lists), addr.offset));
+ && ENTRY_IS_VALID(&(s->seg_manager.heap[addr.segment]->data.lists), addr.offset));
}
#ifdef DISABLE_VALIDATIONS
@@ -121,8 +116,7 @@ listp(state_t *s, reg_t addr)
#else
static inline int
-sane_nodep(state_t *s, reg_t addr)
-{
+sane_nodep(state_t *s, reg_t addr) {
int have_prev = 0;
reg_t prev = addr;
@@ -133,7 +127,7 @@ sane_nodep(state_t *s, reg_t addr)
return 0;
if ((have_prev)
- && !REG_EQ(node->pred, prev))
+ && !REG_EQ(node->pred, prev))
return 0;
prev = addr;
@@ -147,8 +141,7 @@ sane_nodep(state_t *s, reg_t addr)
int
-sane_listp(state_t *s, reg_t addr)
-{
+sane_listp(state_t *s, reg_t addr) {
list_t *l = LOOKUP_LIST(addr);
int empties = 0;
@@ -185,8 +178,7 @@ sane_listp(state_t *s, reg_t addr)
reg_t
-kNewList(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kNewList(state_t *s, int funct_nr, int argc, reg_t *argv) {
reg_t listbase;
list_t *l;
l = sm_alloc_list(&s->seg_manager, &listbase);
@@ -197,39 +189,37 @@ kNewList(state_t *s, int funct_nr, int argc, reg_t *argv)
}
reg_t
-kDisposeList(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kDisposeList(state_t *s, int funct_nr, int argc, reg_t *argv) {
list_t *l = LOOKUP_LIST(argv[0]);
if (!l) {
SCIkwarn(SCIkERROR, "Attempt to dispose non-list at "PREG"!\n",
- PRINT_REG(argv[0]));
+ PRINT_REG(argv[0]));
return NULL_REG;
}
if (!sane_listp(s, argv[0]))
- SCIkwarn(SCIkERROR,"List at "PREG" is not sane anymore!\n", PRINT_REG(argv[0]));
+ SCIkwarn(SCIkERROR, "List at "PREG" is not sane anymore!\n", PRINT_REG(argv[0]));
-/* if (!IS_NULL_REG(l->first)) {
- reg_t n_addr = l->first;
+ /* if (!IS_NULL_REG(l->first)) {
+ reg_t n_addr = l->first;
- while (!IS_NULL_REG(n_addr)) { /-* Free all nodes *-/
- node_t *n = LOOKUP_NODE(n_addr);
- sm_free_node(&s->seg_manager, n_addr);
- n_addr = n->succ;
- }
- }
+ while (!IS_NULL_REG(n_addr)) { /-* Free all nodes *-/
+ node_t *n = LOOKUP_NODE(n_addr);
+ sm_free_node(&s->seg_manager, n_addr);
+ n_addr = n->succ;
+ }
+ }
- sm_free_list(&s->seg_manager, argv[0]);
-*/
+ sm_free_list(&s->seg_manager, argv[0]);
+ */
return s->r_acc;
}
inline reg_t
-_k_new_node(state_t *s, reg_t value, reg_t key)
-{
+_k_new_node(state_t *s, reg_t value, reg_t key) {
reg_t nodebase;
node_t *n = sm_alloc_node(&s->seg_manager, &nodebase);
@@ -246,8 +236,7 @@ _k_new_node(state_t *s, reg_t value, reg_t key)
}
reg_t
-kNewNode(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kNewNode(state_t *s, int funct_nr, int argc, reg_t *argv) {
s->r_acc = _k_new_node(s, argv[0], argv[1]);
SCIkdebug(SCIkNODES, "New nodebase at "PREG"\n", PRINT_REG(s->r_acc));
@@ -258,13 +247,12 @@ kNewNode(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kFirstNode(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kFirstNode(state_t *s, int funct_nr, int argc, reg_t *argv) {
list_t *l = LOOKUP_NULL_LIST(argv[0]);
if (l && !sane_listp(s, argv[0]))
- SCIkwarn(SCIkERROR,"List at "PREG" is not sane anymore!\n",
- PRINT_REG(argv[0]));
+ SCIkwarn(SCIkERROR, "List at "PREG" is not sane anymore!\n",
+ PRINT_REG(argv[0]));
if (l)
return l->first;
@@ -274,13 +262,12 @@ kFirstNode(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kLastNode(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kLastNode(state_t *s, int funct_nr, int argc, reg_t *argv) {
list_t *l = LOOKUP_LIST(argv[0]);
- if (l&&!sane_listp(s, argv[0]))
- SCIkwarn(SCIkERROR,"List at "PREG" is not sane anymore!\n",
- PRINT_REG(argv[0]));
+ if (l && !sane_listp(s, argv[0]))
+ SCIkwarn(SCIkERROR, "List at "PREG" is not sane anymore!\n",
+ PRINT_REG(argv[0]));
if (l)
return l->last;
@@ -290,31 +277,29 @@ kLastNode(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kEmptyList(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kEmptyList(state_t *s, int funct_nr, int argc, reg_t *argv) {
list_t *l = LOOKUP_LIST(argv[0]);
if (!l || !sane_listp(s, argv[0]))
- SCIkwarn(SCIkERROR,"List at "PREG" is invalid or not sane anymore!\n",
- PRINT_REG(argv[0]));
+ SCIkwarn(SCIkERROR, "List at "PREG" is invalid or not sane anymore!\n",
+ PRINT_REG(argv[0]));
- return make_reg(0, ((l)? IS_NULL_REG(l->first) : 0));
+ return make_reg(0, ((l) ? IS_NULL_REG(l->first) : 0));
}
inline void
-_k_add_to_front(state_t *s, reg_t listbase, reg_t nodebase)
-{
+_k_add_to_front(state_t *s, reg_t listbase, reg_t nodebase) {
list_t *l = LOOKUP_LIST(listbase);
node_t *new_n = LOOKUP_NODE(nodebase);
SCIkdebug(SCIkNODES, "Adding node "PREG" to end of list "PREG"\n",
- PRINT_REG(nodebase), PRINT_REG(listbase));
+ PRINT_REG(nodebase), PRINT_REG(listbase));
if (!new_n)
SCIkwarn(SCIkERROR, "Attempt to add non-node ("PREG") to list at "PREG"\n",
- PRINT_REG(nodebase), PRINT_REG(listbase));
+ PRINT_REG(nodebase), PRINT_REG(listbase));
if (!l || !sane_listp(s, listbase))
- SCIkwarn(SCIkERROR,"List at "PREG" is not sane anymore!\n", PRINT_REG(listbase));
+ SCIkwarn(SCIkERROR, "List at "PREG" is not sane anymore!\n", PRINT_REG(listbase));
new_n->succ = l->first;
new_n->pred = NULL_REG;
@@ -329,19 +314,18 @@ _k_add_to_front(state_t *s, reg_t listbase, reg_t nodebase)
}
inline void
-_k_add_to_end(state_t *s, reg_t listbase, reg_t nodebase)
-{
+_k_add_to_end(state_t *s, reg_t listbase, reg_t nodebase) {
list_t *l = LOOKUP_LIST(listbase);
node_t *new_n = LOOKUP_NODE(nodebase);
SCIkdebug(SCIkNODES, "Adding node "PREG" to end of list "PREG"\n",
- PRINT_REG(nodebase), PRINT_REG(listbase));
+ PRINT_REG(nodebase), PRINT_REG(listbase));
if (!new_n)
SCIkwarn(SCIkERROR, "Attempt to add non-node ("PREG") to list at "PREG"\n",
- PRINT_REG(nodebase), PRINT_REG(listbase));
+ PRINT_REG(nodebase), PRINT_REG(listbase));
if (!l || !sane_listp(s, listbase))
- SCIkwarn(SCIkERROR,"List at "PREG" is not sane anymore!\n", PRINT_REG(listbase));
+ SCIkwarn(SCIkERROR, "List at "PREG" is not sane anymore!\n", PRINT_REG(listbase));
new_n->succ = NULL_REG;
new_n->pred = l->last;
@@ -357,13 +341,11 @@ _k_add_to_end(state_t *s, reg_t listbase, reg_t nodebase)
reg_t
-kNextNode(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kNextNode(state_t *s, int funct_nr, int argc, reg_t *argv) {
node_t *n = LOOKUP_NODE(argv[0]);
- if (!sane_nodep(s, argv[0]))
- {
- SCIkwarn(SCIkERROR,"List node at "PREG" is not sane anymore!\n",
- PRINT_REG(argv[0]));
+ if (!sane_nodep(s, argv[0])) {
+ SCIkwarn(SCIkERROR, "List node at "PREG" is not sane anymore!\n",
+ PRINT_REG(argv[0]));
script_error_flag = script_debug_flag = 0;
return NULL_REG;
}
@@ -372,25 +354,22 @@ kNextNode(state_t *s, int funct_nr, int argc, reg_t *argv)
}
reg_t
-kPrevNode(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kPrevNode(state_t *s, int funct_nr, int argc, reg_t *argv) {
node_t *n = LOOKUP_NODE(argv[0]);
if (!sane_nodep(s, argv[0]))
- SCIkwarn(SCIkERROR,"List node at "PREG" is not sane anymore!\n",
- PRINT_REG(argv[0]));
+ SCIkwarn(SCIkERROR, "List node at "PREG" is not sane anymore!\n",
+ PRINT_REG(argv[0]));
return n->pred;
}
reg_t
-kNodeValue(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kNodeValue(state_t *s, int funct_nr, int argc, reg_t *argv) {
node_t *n = LOOKUP_NODE(argv[0]);
- if (!sane_nodep(s, argv[0]))
- {
- SCIkwarn(SCIkERROR,"List node at "PREG" is not sane!\n",
- PRINT_REG(argv[0]));
+ if (!sane_nodep(s, argv[0])) {
+ SCIkwarn(SCIkERROR, "List node at "PREG" is not sane!\n",
+ PRINT_REG(argv[0]));
script_debug_flag = script_error_flag = 0;
return NULL_REG;
}
@@ -400,26 +379,24 @@ kNodeValue(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kAddToFront(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kAddToFront(state_t *s, int funct_nr, int argc, reg_t *argv) {
_k_add_to_front(s, argv[0], argv[1]);
return s->r_acc;
}
reg_t
-kAddAfter(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kAddAfter(state_t *s, int funct_nr, int argc, reg_t *argv) {
list_t *l = LOOKUP_LIST(argv[0]);
- node_t *firstnode = IS_NULL_REG(argv[1])? NULL : LOOKUP_NODE(argv[1]);
+ node_t *firstnode = IS_NULL_REG(argv[1]) ? NULL : LOOKUP_NODE(argv[1]);
node_t *newnode = LOOKUP_NODE(argv[2]);
if (!l || !sane_listp(s, argv[0]))
- SCIkwarn(SCIkERROR,"List at "PREG" is not sane anymore!\n",
- PRINT_REG(argv[0]));
+ SCIkwarn(SCIkERROR, "List at "PREG" is not sane anymore!\n",
+ PRINT_REG(argv[0]));
if (!newnode) {
- SCIkwarn(SCIkERROR,"New 'node' "PREG" is not a node!\n",
- argv[1], argv[2]);
+ SCIkwarn(SCIkERROR, "New 'node' "PREG" is not a node!\n",
+ argv[1], argv[2]);
return NULL_REG;
}
@@ -452,26 +429,24 @@ kAddAfter(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kAddToEnd(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kAddToEnd(state_t *s, int funct_nr, int argc, reg_t *argv) {
_k_add_to_end(s, argv[0], argv[1]);
return s->r_acc;
}
reg_t
-kFindKey(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kFindKey(state_t *s, int funct_nr, int argc, reg_t *argv) {
reg_t node_pos;
reg_t key = argv[1];
reg_t list_pos = argv[0];
SCIkdebug(SCIkNODES, "Looking for key "PREG" in list "PREG"\n",
- PRINT_REG(key), PRINT_REG(list_pos));
+ PRINT_REG(key), PRINT_REG(list_pos));
if (!sane_listp(s, list_pos))
- SCIkwarn(SCIkERROR,"List at "PREG" is not sane anymore!\n",
- PRINT_REG(list_pos));
+ SCIkwarn(SCIkERROR, "List at "PREG" is not sane anymore!\n",
+ PRINT_REG(list_pos));
node_pos = LOOKUP_LIST(list_pos)->first;
@@ -494,8 +469,7 @@ kFindKey(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kDeleteKey(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kDeleteKey(state_t *s, int funct_nr, int argc, reg_t *argv) {
reg_t node_pos = kFindKey(s, funct_nr, 2, argv);
node_t *n;
list_t *l = LOOKUP_LIST(argv[0]);
@@ -514,7 +488,7 @@ kDeleteKey(state_t *s, int funct_nr, int argc, reg_t *argv)
if (!IS_NULL_REG(n->succ))
LOOKUP_NODE(n->succ)->pred = n->pred;
-/* sm_free_node(&s->seg_manager, node_pos);*/
+ /* sm_free_node(&s->seg_manager, node_pos);*/
return make_reg(0, 1); /* Signal success */
}
@@ -522,34 +496,31 @@ kDeleteKey(state_t *s, int funct_nr, int argc, reg_t *argv)
-typedef struct
-{
+typedef struct {
reg_t key, value;
reg_t order;
} sort_temp_t;
int
-sort_temp_cmp(const void *p1, const void *p2)
-{
+sort_temp_cmp(const void *p1, const void *p2) {
sort_temp_t *st1 = (sort_temp_t *) p1;
sort_temp_t *st2 = (sort_temp_t *) p2;
if (st1->order.segment < st1->order.segment ||
- (st1->order.segment == st1->order.segment &&
- st1->order.offset < st2->order.offset))
+ (st1->order.segment == st1->order.segment &&
+ st1->order.offset < st2->order.offset))
return -1;
if (st1->order.segment > st2->order.segment ||
- (st1->order.segment == st2->order.segment &&
- st1->order.offset > st2->order.offset))
+ (st1->order.segment == st2->order.segment &&
+ st1->order.offset > st2->order.offset))
return 1;
return 0;
}
reg_t
-kSort(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kSort(state_t *s, int funct_nr, int argc, reg_t *argv) {
reg_t source = argv[0];
reg_t dest = argv[1];
reg_t order_func = argv[2];
@@ -558,8 +529,8 @@ kSort(state_t *s, int funct_nr, int argc, reg_t *argv)
int i;
- sort_temp_t *temp_array = (sort_temp_t *)
- malloc(sizeof(sort_temp_t)*input_size);
+ sort_temp_t *temp_array = (sort_temp_t *)
+ malloc(sizeof(sort_temp_t) * input_size);
reg_t input_data = GET_SEL32(source, elements);
reg_t output_data = GET_SEL32(dest, elements);
@@ -570,8 +541,7 @@ kSort(state_t *s, int funct_nr, int argc, reg_t *argv)
if (!input_size)
return s->r_acc;
- if (IS_NULL_REG(output_data))
- {
+ if (IS_NULL_REG(output_data)) {
list = sm_alloc_list(&s->seg_manager, &output_data);
list->first = list->last = NULL_REG;
PUT_SEL32(dest, elements, output_data);
@@ -583,8 +553,7 @@ kSort(state_t *s, int funct_nr, int argc, reg_t *argv)
node = LOOKUP_NODE(list->first);
i = 0;
- while (node)
- {
+ while (node) {
invoke_selector(INV_SEL(order_func, doit, 0), 1, node->value);
temp_array[i].key = node->key;
temp_array[i].value = node->value;
@@ -595,10 +564,9 @@ kSort(state_t *s, int funct_nr, int argc, reg_t *argv)
qsort(temp_array, input_size, sizeof(sort_temp_t), sort_temp_cmp);
- for (i=0;i<input_size;i++)
- {
+ for (i = 0;i < input_size;i++) {
reg_t lNode = _k_new_node(s, temp_array[i].key,
- temp_array[i].value);
+ temp_array[i].value);
_k_add_to_end(s, output_data, lNode);
}
diff --git a/engines/sci/engine/kmath.cpp b/engines/sci/engine/kmath.cpp
index 6925970d8a..ae8cc038dd 100644
--- a/engines/sci/engine/kmath.cpp
+++ b/engines/sci/engine/kmath.cpp
@@ -29,16 +29,14 @@
reg_t
-kRandom(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
- return make_reg(0,
- SKPV(0) + (int) ((SKPV(1) + 1.0 - SKPV(0)) * (rand() / (RAND_MAX + 1.0))));
+kRandom(state_t *s, int funct_nr, int argc, reg_t *argv) {
+ return make_reg(0,
+ SKPV(0) + (int)((SKPV(1) + 1.0 - SKPV(0)) * (rand() / (RAND_MAX + 1.0))));
}
reg_t
-kAbs(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kAbs(state_t *s, int funct_nr, int argc, reg_t *argv) {
/* This is a hack, but so is the code in Hoyle1 that needs it. */
if (argv[0].segment)
return make_reg(0, 0x3e8); /* Yes people, this is an object */
@@ -47,19 +45,17 @@ kAbs(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kSqrt(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kSqrt(state_t *s, int funct_nr, int argc, reg_t *argv) {
return make_reg(0, (gint16) sqrt((float) abs(SKPV(0))));
}
int
-get_angle(int xrel, int yrel)
-{
+get_angle(int xrel, int yrel) {
if ((xrel == 0) && (yrel == 0))
return 0;
else {
- int val = (int) (180.0/PI * atan2((double)xrel, (double)-yrel));
+ int val = (int)(180.0 / PI * atan2((double)xrel, (double) - yrel));
if (val < 0)
val += 360;
@@ -67,7 +63,7 @@ get_angle(int xrel, int yrel)
FSCI. SCI games sometimes check for equality with
"round" angles */
if (val % 45 == 44)
- val++;
+ val++;
else if (val % 45 == 1)
val--;
@@ -76,8 +72,7 @@ get_angle(int xrel, int yrel)
}
reg_t
-kGetAngle(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kGetAngle(state_t *s, int funct_nr, int argc, reg_t *argv) {
/* Based on behavior observed with a test program created with
** SCI Studio.
*/
@@ -89,7 +84,7 @@ kGetAngle(state_t *s, int funct_nr, int argc, reg_t *argv)
int yrel = y1 - y2; /* y-axis is mirrored. */
int angle;
- /* Move (xrel, yrel) to first quadrant. */
+ /* Move (xrel, yrel) to first quadrant. */
if (y1 < y2)
yrel = -yrel;
if (x2 < x1)
@@ -118,64 +113,58 @@ kGetAngle(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kGetDistance(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
- int xrel = (int) (((float) SKPV(1) - SKPV_OR_ALT(3, 0))/cos(SKPV_OR_ALT(5, 0)* PI / 180.0)); /* This works because cos(0)==1 */
- int yrel = SKPV(0) - SKPV_OR_ALT(2, 0);
+kGetDistance(state_t *s, int funct_nr, int argc, reg_t *argv) {
+ int xrel = (int)(((float) SKPV(1) - SKPV_OR_ALT(3, 0)) / cos(SKPV_OR_ALT(5, 0) * PI / 180.0)); /* This works because cos(0)==1 */
+ int yrel = SKPV(0) - SKPV_OR_ALT(2, 0);
return make_reg(0, (gint16)sqrt((float) xrel*xrel + yrel*yrel));
}
reg_t
-kTimesSin(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kTimesSin(state_t *s, int funct_nr, int argc, reg_t *argv) {
int angle = SKPV(0);
int factor = SKPV(1);
- return make_reg(0, (int) (factor * 1.0 * sin(angle * PI / 180.0)));
+ return make_reg(0, (int)(factor * 1.0 * sin(angle * PI / 180.0)));
}
reg_t
-kTimesCos(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kTimesCos(state_t *s, int funct_nr, int argc, reg_t *argv) {
int angle = SKPV(0);
int factor = SKPV(1);
- return make_reg(0, (int) (factor * 1.0 * cos(angle * PI / 180.0)));
+ return make_reg(0, (int)(factor * 1.0 * cos(angle * PI / 180.0)));
}
reg_t
-kCosDiv(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kCosDiv(state_t *s, int funct_nr, int argc, reg_t *argv) {
int angle = SKPV(0);
int value = SKPV(1);
double cosval = cos(angle * PI / 180.0);
if ((cosval < 0.0001) && (cosval > 0.0001)) {
- SCIkwarn(SCIkWARNING,"Attepted division by zero\n");
+ SCIkwarn(SCIkWARNING, "Attepted division by zero\n");
return make_reg(0, (gint16)0x8000);
} else
- return make_reg(0, (gint16) (value/cosval));
+ return make_reg(0, (gint16)(value / cosval));
}
reg_t
-kSinDiv(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kSinDiv(state_t *s, int funct_nr, int argc, reg_t *argv) {
int angle = SKPV(0);
int value = SKPV(1);
double sinval = sin(angle * PI / 180.0);
if ((sinval < 0.0001) && (sinval > 0.0001)) {
- SCIkwarn(SCIkWARNING,"Attepted division by zero\n");
+ SCIkwarn(SCIkWARNING, "Attepted division by zero\n");
return make_reg(0, (gint16)0x8000);
} else
- return make_reg(0, (gint16) (value/sinval));
+ return make_reg(0, (gint16)(value / sinval));
}
reg_t
-kTimesTan(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kTimesTan(state_t *s, int funct_nr, int argc, reg_t *argv) {
int param = SKPV(0);
int scale = SKPV_OR_ALT(1, 1);
@@ -184,12 +173,11 @@ kTimesTan(state_t *s, int funct_nr, int argc, reg_t *argv)
SCIkwarn(SCIkWARNING, "Attempted tan(pi/2)");
return make_reg(0, (gint16)0x8000);
} else
- return make_reg(0, (gint16) -(tan(param * PI / 180.0) * scale));
+ return make_reg(0, (gint16) - (tan(param * PI / 180.0) * scale));
}
reg_t
-kTimesCot(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kTimesCot(state_t *s, int funct_nr, int argc, reg_t *argv) {
int param = SKPV(0);
int scale = SKPV_OR_ALT(1, 1);
@@ -197,5 +185,5 @@ kTimesCot(state_t *s, int funct_nr, int argc, reg_t *argv)
SCIkwarn(SCIkWARNING, "Attempted tan(pi/2)");
return make_reg(0, (gint16)0x8000);
} else
- return make_reg(0, (gint16) (tan(param * PI / 180.0) * scale));
+ return make_reg(0, (gint16)(tan(param * PI / 180.0) * scale));
}
diff --git a/engines/sci/engine/kmenu.cpp b/engines/sci/engine/kmenu.cpp
index b4510d3d1a..408a8cffe9 100644
--- a/engines/sci/engine/kmenu.cpp
+++ b/engines/sci/engine/kmenu.cpp
@@ -31,13 +31,12 @@
reg_t
-kAddMenu(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kAddMenu(state_t *s, int funct_nr, int argc, reg_t *argv) {
char *name = kernel_dereference_char_pointer(s, argv[0], 0);
char *contents = kernel_dereference_char_pointer(s, argv[1], 0);
menubar_add_menu(s->gfx_state, s->menubar, name,
- contents, s->titlebar_port->font_nr, argv[1]);
+ contents, s->titlebar_port->font_nr, argv[1]);
return s->r_acc;
@@ -45,8 +44,7 @@ kAddMenu(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kSetMenu(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kSetMenu(state_t *s, int funct_nr, int argc, reg_t *argv) {
int index = UKPV(0);
int i = 2;
@@ -59,8 +57,7 @@ kSetMenu(state_t *s, int funct_nr, int argc, reg_t *argv)
}
reg_t
-kGetMenu(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kGetMenu(state_t *s, int funct_nr, int argc, reg_t *argv) {
int index = UKPV(0);
return menubar_get_attribute(s, (index >> 8) - 1, (index & 0xff) - 1, UKPV(1));
@@ -68,8 +65,7 @@ kGetMenu(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kDrawStatus(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kDrawStatus(state_t *s, int funct_nr, int argc, reg_t *argv) {
reg_t text = argv[0];
int fgcolor = SKPV_OR_ALT(1, s->status_bar_foreground);
int bgcolor = SKPV_OR_ALT(2, s->status_bar_background);
@@ -79,8 +75,8 @@ kDrawStatus(state_t *s, int funct_nr, int argc, reg_t *argv)
s->titlebar_port->bgcolor.visual = *(get_pic_color(s, bgcolor));
s->titlebar_port->bgcolor.mask = GFX_MASK_VISUAL;
- s->status_bar_foreground=fgcolor;
- s->status_bar_background=bgcolor;
+ s->status_bar_foreground = fgcolor;
+ s->status_bar_background = bgcolor;
if (NULL != s->status_bar_text) {
sci_free(s->status_bar_text);
@@ -99,8 +95,7 @@ kDrawStatus(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kDrawMenuBar(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kDrawMenuBar(state_t *s, int funct_nr, int argc, reg_t *argv) {
if (SKPV(0))
sciw_set_menubar(s, s->titlebar_port, s->menubar, -1);
@@ -122,20 +117,20 @@ static struct {
int fgcolor, bgcolor;
} _about_freesci_pages[ABOUT_FREESCI_PAGES_NR] = {
{"FreeSCI hackers and contributors",
- "Alexander R. Angas\nDirectX 8 driver, Event sound server, Generic memory functions"
- "\n\n"
- "Anders Baden Nielsen\nPPC testing"
- "\n\n"
- "Bas Zoetekouw\nMan pages, debian package management, CVS maintenance"
- "\n\n"
- "Carl Muckenhoupt\nSources to the SCI resource viewer tools that started it all"
- "\n\n"
- "Chris Kehler\nMakefile enhancements"
- "\n\n"
- "Christoph Reichenbach\nUN*X code, VM/Graphics/Sound/other infrastructure"
- "\n\n"
- "Christopher T. Lansdown\nOriginal CVS maintainer, Alpha compatibility fixes"
- ,0, 15},
+ "Alexander R. Angas\nDirectX 8 driver, Event sound server, Generic memory functions"
+ "\n\n"
+ "Anders Baden Nielsen\nPPC testing"
+ "\n\n"
+ "Bas Zoetekouw\nMan pages, debian package management, CVS maintenance"
+ "\n\n"
+ "Carl Muckenhoupt\nSources to the SCI resource viewer tools that started it all"
+ "\n\n"
+ "Chris Kehler\nMakefile enhancements"
+ "\n\n"
+ "Christoph Reichenbach\nUN*X code, VM/Graphics/Sound/other infrastructure"
+ "\n\n"
+ "Christopher T. Lansdown\nOriginal CVS maintainer, Alpha compatibility fixes"
+ , 0, 15},
{"More FreeSCI hackers and contributors",
"Claudio Matsuoka\nCVS snapshots, daily builds, BeOS and cygwin ports"
"\n\n"
@@ -150,7 +145,7 @@ static struct {
"George Reid\nFreeBSD package management"
"\n\n"
"Hubert Maier\nAmigaOS 4 port"
- ,0, 15},
+ , 0, 15},
{"Even more FreeSCI hackers & contributors",
"Hugues Valois\nGame selection menu"
"\n\n"
@@ -165,7 +160,7 @@ static struct {
"Matt Hargett\nClean-ups, bugfixes, Hardcore QA, Win32"
"\n\n"
"Max Horn\nSetJump implementation"
- ,0, 15},
+ , 0, 15},
{"Still more of them",
"Paul David Doherty\nGame version information"
"\n\n"
@@ -180,7 +175,7 @@ static struct {
"Ruediger Hanke\nPort to the MorphOS platform"
"\n\n"
"Rune Orsval\nConfiguration file editor"
- ,0, 15},
+ , 0, 15},
{"Is there no end to these contributors?",
"Rickard Lind\nMT32->GM MIDI mapping magic, sound research"
"\n\n"
@@ -199,18 +194,17 @@ static struct {
{"The CSCI5573 Team at CU Boulder",
"Xiaojun Chen\nSean Terrell\nChristoph Reichenbach\n\n"
"Special thanks to Prof. Dr. Gary Nutt\n\nfor allowing the FreeSCI VM extension as a\ncourse project in his Advanced OS course"
- ,0, 15},
+ , 0, 15},
{"Special Thanks",
"Special Thanks as well\n\n\nto the linuxgames.com and telefragged.com crew\nfor hosting us\n\n"
"To the savannah.gnu.org staff\nfor hosting our mailing list\n\n"
"To Bob Heitman and Corey Cole for their support"
- ,0, 15}
+ , 0, 15}
};
void
-about_freesci(state_t *s)
-{
+about_freesci(state_t *s) {
int page;
gfxw_port_t *port;
int bodyfont, titlefont;
@@ -228,7 +222,7 @@ about_freesci(state_t *s)
return;
}
- bodyfont = i+1;
+ bodyfont = i + 1;
for (page = 0; page < ABOUT_FREESCI_PAGES_NR; ++page) {
sci_event_t event;
int cont = 2;
@@ -238,9 +232,9 @@ about_freesci(state_t *s)
_about_freesci_pages[page].bgcolor = 15;
gfxop_get_text_params(s->gfx_state, bodyfont, _about_freesci_pages[page].body, 300, &width, &height, 0,
- NULL, NULL, NULL);
+ NULL, NULL, NULL);
gfxop_get_text_params(s->gfx_state, titlefont, _about_freesci_pages[page].title, 300, &width2, &foo, 0,
- NULL, NULL, NULL);
+ NULL, NULL, NULL);
width += 4;
width2 += 4;
@@ -250,21 +244,21 @@ about_freesci(state_t *s)
width = width2;
port = sciw_new_window(s, gfx_rect(156 - (width >> 1), 100 - (height >> 1), width, height),
- bodyfont, s->ega_colors[_about_freesci_pages[page].fgcolor],
- s->ega_colors[_about_freesci_pages[page].bgcolor],
- titlefont, s->ega_colors[15], s->ega_colors[0],
- _about_freesci_pages[page].title, WINDOW_FLAG_TITLE);
+ bodyfont, s->ega_colors[_about_freesci_pages[page].fgcolor],
+ s->ega_colors[_about_freesci_pages[page].bgcolor],
+ titlefont, s->ega_colors[15], s->ega_colors[0],
+ _about_freesci_pages[page].title, WINDOW_FLAG_TITLE);
- port->add(GFXWC(port), GFXW(gfxw_new_text(s->gfx_state, gfx_rect(0,0,width,height), bodyfont,
- _about_freesci_pages[page].body,
- ALIGN_CENTER, ALIGN_CENTER, port->color, port->color,
- port->bgcolor, 0)
- ));
+ port->add(GFXWC(port), GFXW(gfxw_new_text(s->gfx_state, gfx_rect(0, 0, width, height), bodyfont,
+ _about_freesci_pages[page].body,
+ ALIGN_CENTER, ALIGN_CENTER, port->color, port->color,
+ port->bgcolor, 0)
+ ));
s->visual->add(GFXWC(s->visual), GFXW(port));
port->add_dirty_abs(GFXWC(port), gfx_rect_fullscreen, 1);
- s->visual->draw(GFXW(s->visual), gfx_point(0,0));
+ s->visual->draw(GFXW(s->visual), gfx_point(0, 0));
gfxop_update(s->gfx_state);
while (cont) {
@@ -286,7 +280,7 @@ about_freesci(state_t *s)
port->widfree(GFXW(port));
- s->visual->draw(GFXW(s->visual), gfx_point(0,0));
+ s->visual->draw(GFXW(s->visual), gfx_point(0, 0));
gfxop_update(s->gfx_state);
}
@@ -294,8 +288,7 @@ about_freesci(state_t *s)
static inline int
-_menu_go_down(state_t *s, int menu_nr, int item_nr)
-{
+_menu_go_down(state_t *s, int menu_nr, int item_nr) {
int seeker, max = s->menubar->menus[menu_nr].items_nr;
seeker = item_nr + 1;
@@ -313,8 +306,7 @@ _menu_go_down(state_t *s, int menu_nr, int item_nr)
reg_t
-kMenuSelect(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kMenuSelect(state_t *s, int funct_nr, int argc, reg_t *argv) {
reg_t event = argv[0];
/*int pause_sound = UKPV_OR_ALT(1, 1);*/ /* FIXME: Do this eventually */
int claimed = 0;
@@ -333,33 +325,33 @@ kMenuSelect(state_t *s, int funct_nr, int argc, reg_t *argv)
int menuc, itemc;
if ((type == SCI_EVT_KEYBOARD)
- && (message == SCI_K_ESC))
+ && (message == SCI_K_ESC))
menu_mode = 1;
else if ((type == SCI_EVT_SAID) || message) { /* Don't claim 0 keyboard event */
- SCIkdebug(SCIkMENU,"Menu: Got %s event: %04x/%04x\n",
- ((type == SCI_EVT_SAID)? "SAID":"KBD"), message, modifiers);
+ SCIkdebug(SCIkMENU, "Menu: Got %s event: %04x/%04x\n",
+ ((type == SCI_EVT_SAID) ? "SAID" : "KBD"), message, modifiers);
for (menuc = 0; menuc < s->menubar->menus_nr; menuc++)
for (itemc = 0; itemc < s->menubar->menus[menuc].items_nr; itemc++) {
item = s->menubar->menus[menuc].items + itemc;
- SCIkdebug(SCIkMENU,"Menu: Checking against %s: %04x/%04x (type %d, %s)\n",
- item->text? item->text : "--bar--", item->key, item->modifiers,
- item->type, item->enabled? "enabled":"disabled");
+ SCIkdebug(SCIkMENU, "Menu: Checking against %s: %04x/%04x (type %d, %s)\n",
+ item->text ? item->text : "--bar--", item->key, item->modifiers,
+ item->type, item->enabled ? "enabled" : "disabled");
if (((item->type == MENU_TYPE_NORMAL)
- && (item->enabled))
- && (((type == SCI_EVT_KEYBOARD) /* keyboard event */
- && menubar_match_key(item, message, modifiers))
- || ((type == SCI_EVT_SAID) /* Said event */
- && (item->flags & MENU_ATTRIBUTE_FLAGS_SAID)
- && (said(s, item->said, (s->debug_mode & (1 << SCIkPARSER_NR))) != SAID_NO_MATCH)
- )
- )
- ) {
+ && (item->enabled))
+ && (((type == SCI_EVT_KEYBOARD) /* keyboard event */
+ && menubar_match_key(item, message, modifiers))
+ || ((type == SCI_EVT_SAID) /* Said event */
+ && (item->flags & MENU_ATTRIBUTE_FLAGS_SAID)
+ && (said(s, item->said, (s->debug_mode & (1 << SCIkPARSER_NR))) != SAID_NO_MATCH)
+ )
+ )
+ ) {
/* Claim the event */
- SCIkdebug(SCIkMENU,"Menu: Event CLAIMED for %d/%d\n", menuc, itemc);
+ SCIkdebug(SCIkMENU, "Menu: Event CLAIMED for %d/%d\n", menuc, itemc);
claimed = 1;
menu_nr = menuc;
item_nr = itemc;
@@ -526,8 +518,7 @@ kMenuSelect(state_t *s, int funct_nr, int argc, reg_t *argv)
s->r_acc = NULL_REG;
SCIkdebug(SCIkMENU, "Menu: Claim -> %04x\n", s->r_acc.offset);
- }
- else s->r_acc = NULL_REG; /* Not claimed */
+ } else s->r_acc = NULL_REG; /* Not claimed */
return s->r_acc;
}
diff --git a/engines/sci/engine/kmovement.cpp b/engines/sci/engine/kmovement.cpp
index 37ff5fb1f9..d6cc5d6fec 100644
--- a/engines/sci/engine/kmovement.cpp
+++ b/engines/sci/engine/kmovement.cpp
@@ -29,17 +29,17 @@
#include "sci/include/engine.h"
/*
-Compute "velocity" vector (xStep,yStep)=(vx,vy) for a jump from (0,0) to (dx,dy), with gravity gy.
+Compute "velocity" vector (xStep,yStep)=(vx,vy) for a jump from (0,0) to (dx,dy), with gravity gy.
The gravity is assumed to be non-negative.
If this was ordinary continuous physics, we would compute the desired (floating point!)
velocity vector (vx,vy) as follows, under the assumption that vx and vy are linearly correlated
-by some constant factor c, i.e. vy = c * vx:
+by some constant factor c, i.e. vy = c * vx:
dx = t * vx
dy = t * vy + gy * t^2 / 2
=> dy = c * dx + gy * (dx/vx)^2 / 2
=> |vx| = sqrt( gy * dx^2 / (2 * (dy - c * dx)) )
-Here, the sign of vx must be chosen equal to the sign of dx, obviously.
+Here, the sign of vx must be chosen equal to the sign of dx, obviously.
Clearly, this square root only makes sense in our context if the denominator is positive,
or equivalently, (dy - c * dx) must be positive. For simplicity and by symmetry
@@ -65,8 +65,7 @@ Still, what we compute in the end is of course not a real velocity anymore, but
used in an iterative stepping algorithm
*/
reg_t
-kSetJump(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kSetJump(state_t *s, int funct_nr, int argc, reg_t *argv) {
// Input data
reg_t object = argv[0];
int dx = SKPV(1);
@@ -98,18 +97,18 @@ kSetJump(state_t *s, int funct_nr, int argc, reg_t *argv)
// we ensure vx will be less than sqrt(gy * dx)).
if (dx + dy < 0) {
// dy is negative and |dy| > |dx|
- c = (2*abs(dy)) / dx;
+ c = (2 * abs(dy)) / dx;
//tmp = abs(dy); // ALMOST the resulting value, except for obvious rounding issues
} else {
// dy is either positive, or |dy| <= |dx|
- c = (dx*3/2 - dy) / dx;
+ c = (dx * 3 / 2 - dy) / dx;
// We force c to be strictly positive
if (c < 1)
c = 1;
//tmp = dx*3/2; // ALMOST the resulting value, except for obvious rounding issues
-
+
// FIXME: Where is the 3 coming from? Maybe they hard/coded, by "accident", that usually gy=3 ?
// Then this choice of will make t equal to roughly sqrt(dx)
}
@@ -121,7 +120,7 @@ kSetJump(state_t *s, int funct_nr, int argc, reg_t *argv)
SCIkdebug(SCIkBRESEN, "c: %d, tmp: %d\n", c, tmp);
-
+
// Compute x step
if (tmp != 0)
vx = (int)(dx * sqrt(gy / (2.0 * tmp)));
@@ -131,7 +130,7 @@ kSetJump(state_t *s, int funct_nr, int argc, reg_t *argv)
// Restore the left/right direction: dx and vx should have the same sign.
if (dxWasNegative)
vx = -vx;
-
+
if ((dy < 0) && (vx == 0)) {
// Special case: If this was a jump (almost) straight upward, i.e. dy < 0 (upward),
// and vx == 0 (i.e. no horizontal movement, at least not after rounding), then we
@@ -154,10 +153,10 @@ kSetJump(state_t *s, int funct_nr, int argc, reg_t *argv)
SCIkdebug(SCIkBRESEN, "SetJump for object at "PREG"\n", PRINT_REG(object));
SCIkdebug(SCIkBRESEN, "xStep: %d, yStep: %d\n", vx, vy);
-
+
PUT_SEL32V(object, xStep, vx);
PUT_SEL32V(object, yStep, vy);
-
+
return s->r_acc;
}
@@ -166,13 +165,12 @@ kSetJump(state_t *s, int funct_nr, int argc, reg_t *argv)
void
initialize_bresen(state_t *s, int funct_nr, int argc, reg_t *argv, reg_t mover, int step_factor,
- int deltax, int deltay)
-{
+ int deltax, int deltay) {
reg_t client = GET_SEL32(mover, client);
int stepx = GET_SEL32SV(client, xStep) * step_factor;
int stepy = GET_SEL32SV(client, yStep) * step_factor;
- int numsteps_x = stepx? (abs(deltax) + stepx-1) / stepx : 0;
- int numsteps_y = stepy? (abs(deltay) + stepy-1) / stepy : 0;
+ int numsteps_x = stepx ? (abs(deltax) + stepx - 1) / stepx : 0;
+ int numsteps_y = stepy ? (abs(deltay) + stepy - 1) / stepy : 0;
int bdi, i1;
int numsteps;
int deltax_step;
@@ -180,35 +178,35 @@ initialize_bresen(state_t *s, int funct_nr, int argc, reg_t *argv, reg_t mover,
if (numsteps_x > numsteps_y) {
numsteps = numsteps_x;
- deltax_step = (deltax < 0)? -stepx : stepx;
- deltay_step = numsteps? deltay / numsteps : deltay;
+ deltax_step = (deltax < 0) ? -stepx : stepx;
+ deltay_step = numsteps ? deltay / numsteps : deltay;
} else { /* numsteps_x <= numsteps_y */
numsteps = numsteps_y;
- deltay_step = (deltay < 0)? -stepy : stepy;
- deltax_step = numsteps? deltax / numsteps : deltax;
+ deltay_step = (deltay < 0) ? -stepy : stepy;
+ deltax_step = numsteps ? deltax / numsteps : deltax;
}
/* if (abs(deltax) > abs(deltay)) {*/ /* Bresenham on y */
if (numsteps_y < numsteps_x) {
PUT_SEL32V(mover, b_xAxis, _K_BRESEN_AXIS_Y);
- PUT_SEL32V(mover, b_incr, (deltay < 0)? -1 : 1);
+ PUT_SEL32V(mover, b_incr, (deltay < 0) ? -1 : 1);
/*
i1 = 2 * (abs(deltay) - abs(deltay_step * numsteps)) * abs(deltax_step);
bdi = -abs(deltax);
*/
- i1 = 2*(abs(deltay) - abs(deltay_step * (numsteps - 1))) * abs(deltax_step);
+ i1 = 2 * (abs(deltay) - abs(deltay_step * (numsteps - 1))) * abs(deltax_step);
bdi = -abs(deltax);
} else { /* Bresenham on x */
PUT_SEL32V(mover, b_xAxis, _K_BRESEN_AXIS_X);
- PUT_SEL32V(mover, b_incr, (deltax < 0)? -1 : 1);
+ PUT_SEL32V(mover, b_incr, (deltax < 0) ? -1 : 1);
/*
i1= 2 * (abs(deltax) - abs(deltax_step * numsteps)) * abs(deltay_step);
bdi = -abs(deltay);
*/
- i1 = 2*(abs(deltax) - abs(deltax_step * (numsteps - 1))) * abs(deltay_step);
+ i1 = 2 * (abs(deltax) - abs(deltax_step * (numsteps - 1))) * abs(deltay_step);
bdi = -abs(deltay);
}
@@ -218,9 +216,9 @@ initialize_bresen(state_t *s, int funct_nr, int argc, reg_t *argv, reg_t mover,
SCIkdebug(SCIkBRESEN, "Init bresen for mover "PREG": d=(%d,%d)\n", PRINT_REG(mover), deltax, deltay);
SCIkdebug(SCIkBRESEN, " steps=%d, mv=(%d, %d), i1= %d, i2=%d\n",
- numsteps, deltax_step, deltay_step, i1, bdi*2);
+ numsteps, deltax_step, deltay_step, i1, bdi*2);
-/* PUT_SEL32V(mover, b_movCnt, numsteps); *//* Needed for HQ1/Ogre? */
+ /* PUT_SEL32V(mover, b_movCnt, numsteps); *//* Needed for HQ1/Ogre? */
PUT_SEL32V(mover, b_di, bdi);
PUT_SEL32V(mover, b_i1, i1);
PUT_SEL32V(mover, b_i2, bdi * 2);
@@ -228,8 +226,7 @@ initialize_bresen(state_t *s, int funct_nr, int argc, reg_t *argv, reg_t mover,
}
reg_t
-kInitBresen(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kInitBresen(state_t *s, int funct_nr, int argc, reg_t *argv) {
reg_t mover = argv[0];
reg_t client = GET_SEL32(mover, client);
@@ -250,17 +247,15 @@ static enum {
INCREMENT_MOVECNT,
UNINITIALIZED
} handle_movecnt = UNINITIALIZED;
-
+
int parse_reg_t(state_t *s, const char *str, reg_t *dest); /* In scriptconsole.c */
-static int
-checksum_bytes(byte *data, int size)
-{
+static int
+checksum_bytes(byte *data, int size) {
int result = 0;
int i;
- for (i = 0; i < size; i++)
- {
+ for (i = 0; i < size; i++) {
result += *data;
data++;
}
@@ -269,45 +264,39 @@ checksum_bytes(byte *data, int size)
}
static void
-bresenham_autodetect(state_t *s)
-{
+bresenham_autodetect(state_t *s) {
reg_t motion_class;
- if (!parse_reg_t(s, "?Motion", &motion_class))
- {
+ if (!parse_reg_t(s, "?Motion", &motion_class)) {
object_t *obj = obj_get(s, motion_class);
reg_t fptr;
byte *buf;
-
- if (obj == NULL)
- {
- SCIkwarn(SCIkWARNING,"bresenham_autodetect failed!");
+
+ if (obj == NULL) {
+ SCIkwarn(SCIkWARNING, "bresenham_autodetect failed!");
handle_movecnt = INCREMENT_MOVECNT; /* Most games do this, so best guess */
return;
}
-
- if (lookup_selector(s, motion_class, s->selector_map.doit, NULL, &fptr) != SELECTOR_METHOD)
- {
- SCIkwarn(SCIkWARNING,"bresenham_autodetect failed!");
+
+ if (lookup_selector(s, motion_class, s->selector_map.doit, NULL, &fptr) != SELECTOR_METHOD) {
+ SCIkwarn(SCIkWARNING, "bresenham_autodetect failed!");
handle_movecnt = INCREMENT_MOVECNT; /* Most games do this, so best guess */
return;
}
buf = s->seg_manager.heap[fptr.segment]->data.script.buf + fptr.offset;
handle_movecnt = (SCI_VERSION_MAJOR(s->version) == 0 ||
- checksum_bytes(buf, 8) == 0x216) ? INCREMENT_MOVECNT : IGNORE_MOVECNT;
+ checksum_bytes(buf, 8) == 0x216) ? INCREMENT_MOVECNT : IGNORE_MOVECNT;
sciprintf("b-moveCnt action based on checksum: %s\n", handle_movecnt == IGNORE_MOVECNT ?
- "ignore" : "increment");
- } else
- {
- SCIkwarn(SCIkWARNING,"bresenham_autodetect failed!");
+ "ignore" : "increment");
+ } else {
+ SCIkwarn(SCIkWARNING, "bresenham_autodetect failed!");
handle_movecnt = INCREMENT_MOVECNT; /* Most games do this, so best guess */
}
}
reg_t
-kDoBresen(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kDoBresen(state_t *s, int funct_nr, int argc, reg_t *argv) {
reg_t mover = argv[0];
reg_t client = GET_SEL32(mover, client);
@@ -318,8 +307,8 @@ kDoBresen(state_t *s, int funct_nr, int argc, reg_t *argv)
int completed = 0;
int max_movcnt = GET_SEL32V(client, moveSpeed);
- if (SCI_VERSION_MAJOR(s->version)>0)
- signal&=~_K_VIEW_SIG_FLAG_HIT_OBSTACLE;
+ if (SCI_VERSION_MAJOR(s->version) > 0)
+ signal &= ~_K_VIEW_SIG_FLAG_HIT_OBSTACLE;
if (handle_movecnt == UNINITIALIZED)
bresenham_autodetect(s);
@@ -340,16 +329,12 @@ kDoBresen(state_t *s, int funct_nr, int argc, reg_t *argv)
// sciprintf("movecnt %d, move speed %d\n", movcnt, max_movcnt);
- if (handle_movecnt)
- {
- if (max_movcnt > movcnt)
- {
+ if (handle_movecnt) {
+ if (max_movcnt > movcnt) {
++movcnt;
PUT_SEL32V(mover, b_movCnt, movcnt); /* Needed for HQ1/Ogre? */
return NULL_REG;
- }
- else
- {
+ } else {
movcnt = 0;
PUT_SEL32V(mover, b_movCnt, movcnt); /* Needed for HQ1/Ogre? */
}
@@ -369,33 +354,33 @@ kDoBresen(state_t *s, int funct_nr, int argc, reg_t *argv)
x += dx;
y += dy;
- if ((MOVING_ON_X
- && (((x < destx) && (oldx >= destx)) /* Moving left, exceeded? */
- ||
- ((x > destx) && (oldx <= destx)) /* Moving right, exceeded? */
- ||
- ((x == destx) && (abs(dx) > abs(dy))) /* Moving fast, reached? */
- /* Treat this last case specially- when doing sub-pixel movements
- ** on the other axis, we could still be far away from the destination */
- )
- )
- || (MOVING_ON_Y
- && (((y < desty) && (oldy >= desty)) /* Moving upwards, exceeded? */
- ||
- ((y > desty) && (oldy <= desty)) /* Moving downwards, exceeded? */
- ||
- ((y == desty) && (abs(dy) >= abs(dx))) /* Moving fast, reached? */
- )
- )
+ if ((MOVING_ON_X
+ && (((x < destx) && (oldx >= destx)) /* Moving left, exceeded? */
+ ||
+ ((x > destx) && (oldx <= destx)) /* Moving right, exceeded? */
+ ||
+ ((x == destx) && (abs(dx) > abs(dy))) /* Moving fast, reached? */
+ /* Treat this last case specially- when doing sub-pixel movements
+ ** on the other axis, we could still be far away from the destination */
+ )
)
+ || (MOVING_ON_Y
+ && (((y < desty) && (oldy >= desty)) /* Moving upwards, exceeded? */
+ ||
+ ((y > desty) && (oldy <= desty)) /* Moving downwards, exceeded? */
+ ||
+ ((y == desty) && (abs(dy) >= abs(dx))) /* Moving fast, reached? */
+ )
+ )
+ )
/* Whew... in short: If we have reached or passed our target position */
- {
- x = destx;
- y = desty;
- completed = 1;
+ {
+ x = destx;
+ y = desty;
+ completed = 1;
- SCIkdebug(SCIkBRESEN, "Finished mover "PREG"\n", PRINT_REG(mover));
- }
+ SCIkdebug(SCIkBRESEN, "Finished mover "PREG"\n", PRINT_REG(mover));
+ }
PUT_SEL32V(client, x, x);
@@ -404,8 +389,9 @@ kDoBresen(state_t *s, int funct_nr, int argc, reg_t *argv)
SCIkdebug(SCIkBRESEN, "New data: (x,y)=(%d,%d), di=%d\n", x, y, bdi);
if (s->version >= SCI_VERSION_FTU_INVERSE_CANBEHERE)
- invoke_selector(INV_SEL(client, cantBeHere, 0), 0); else
- invoke_selector(INV_SEL(client, canBeHere, 0), 0);
+ invoke_selector(INV_SEL(client, cantBeHere, 0), 0);
+ else
+ invoke_selector(INV_SEL(client, canBeHere, 0), 0);
s->r_acc = not_register(s, s->r_acc);
@@ -422,7 +408,7 @@ kDoBresen(state_t *s, int funct_nr, int argc, reg_t *argv)
completed = 1;
}
- if (SCI_VERSION_MAJOR(s->version)>0)
+ if (SCI_VERSION_MAJOR(s->version) > 0)
if (completed)
invoke_selector(INV_SEL(mover, moveDone, 0), 0);
@@ -430,8 +416,8 @@ kDoBresen(state_t *s, int funct_nr, int argc, reg_t *argv)
}
extern void
-_k_dirloop(reg_t obj, word angle, state_t *s, int funct_nr,
- int argc, reg_t *argv);
+ _k_dirloop(reg_t obj, word angle, state_t *s, int funct_nr,
+ int argc, reg_t *argv);
/* From kgraphics.c, used as alternative looper */
int
@@ -439,13 +425,12 @@ is_heap_object(state_t *s, reg_t pos);
/* From kscripts.c */
extern int
-get_angle(int xrel, int yrel);
+ get_angle(int xrel, int yrel);
/* from kmath.c, used for calculating angles */
reg_t
-kDoAvoider(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kDoAvoider(state_t *s, int funct_nr, int argc, reg_t *argv) {
reg_t avoider = argv[0];
reg_t client, looper, mover;
int angle;
@@ -485,8 +470,8 @@ kDoAvoider(state_t *s, int funct_nr, int argc, reg_t *argv)
if (invoke_selector(INV_SEL(mover, doit, 1) , 0)) {
SCIkwarn(SCIkERROR, "Mover "PREG" of avoider "PREG
- " doesn't have a doit() funcselector\n",
- PRINT_REG(mover), PRINT_REG(avoider));
+ " doesn't have a doit() funcselector\n",
+ PRINT_REG(mover), PRINT_REG(avoider));
return NULL_REG;
}
@@ -496,7 +481,7 @@ kDoAvoider(state_t *s, int funct_nr, int argc, reg_t *argv)
if (invoke_selector(INV_SEL(client, isBlocked, 1) , 0)) {
SCIkwarn(SCIkERROR, "Client "PREG" of avoider "PREG" doesn't"
- " have an isBlocked() funcselector\n", PRINT_REG(client), PRINT_REG(avoider));
+ " have an isBlocked() funcselector\n", PRINT_REG(client), PRINT_REG(avoider));
return NULL_REG;
}
@@ -505,10 +490,10 @@ kDoAvoider(state_t *s, int funct_nr, int argc, reg_t *argv)
angle = get_angle(dx, dy);
SCIkdebug(SCIkBRESEN, "Movement (%d,%d), angle %d is %sblocked\n",
- dx, dy, angle, (s->r_acc.offset)? " ": "not ");
+ dx, dy, angle, (s->r_acc.offset) ? " " : "not ");
if (s->r_acc.offset) { /* isBlocked() returned non-zero */
- int rotation = (rand() & 1)? 45 : (360-45); /* Clockwise/counterclockwise */
+ int rotation = (rand() & 1) ? 45 : (360 - 45); /* Clockwise/counterclockwise */
int oldx = GET_SEL32V(client, x);
int oldy = GET_SEL32V(client, y);
int xstep = GET_SEL32V(client, xStep);
@@ -518,19 +503,19 @@ kDoAvoider(state_t *s, int funct_nr, int argc, reg_t *argv)
SCIkdebug(SCIkBRESEN, " avoider "PREG"\n", PRINT_REG(avoider));
for (moves = 0; moves < 8; moves++) {
- int move_x = (int) (sin(angle * PI / 180.0) * (xstep));
- int move_y = (int) (-cos(angle * PI / 180.0) * (ystep));
+ int move_x = (int)(sin(angle * PI / 180.0) * (xstep));
+ int move_y = (int)(-cos(angle * PI / 180.0) * (ystep));
PUT_SEL32V(client, x, oldx + move_x);
PUT_SEL32V(client, y, oldy + move_y);
SCIkdebug(SCIkBRESEN, "Pos (%d,%d): Trying angle %d; delta=(%d,%d)\n",
- oldx, oldy, angle, move_x, move_y);
+ oldx, oldy, angle, move_x, move_y);
if (invoke_selector(INV_SEL(client, canBeHere, 1) , 0)) {
SCIkwarn(SCIkERROR, "Client "PREG" of avoider "PREG" doesn't"
- " have a canBeHere() funcselector\n",
- PRINT_REG(client), PRINT_REG(avoider));
+ " have a canBeHere() funcselector\n",
+ PRINT_REG(client), PRINT_REG(avoider));
return NULL_REG;
}
@@ -551,7 +536,7 @@ kDoAvoider(state_t *s, int funct_nr, int argc, reg_t *argv)
}
SCIkwarn(SCIkWARNING, "DoAvoider failed for avoider "PREG"\n",
- PRINT_REG(avoider));
+ PRINT_REG(avoider));
} else {
int heading = GET_SEL32V(client, heading);
@@ -566,13 +551,13 @@ kDoAvoider(state_t *s, int funct_nr, int argc, reg_t *argv)
if (looper.segment) {
if (invoke_selector(INV_SEL(looper, doit, 1), 2, angle, client)) {
SCIkwarn(SCIkERROR, "Looper "PREG" of avoider "PREG" doesn't"
- " have a doit() funcselector\n",
- PRINT_REG(looper), PRINT_REG(avoider));
+ " have a doit() funcselector\n",
+ PRINT_REG(looper), PRINT_REG(avoider));
} else return s->r_acc;
} else
- /* No looper? Fall back to DirLoop */
+ /* No looper? Fall back to DirLoop */
- _k_dirloop(client, (word)angle, s, funct_nr, argc, argv);
+ _k_dirloop(client, (word)angle, s, funct_nr, argc, argv);
}
return s->r_acc;
diff --git a/engines/sci/engine/kpathing.cpp b/engines/sci/engine/kpathing.cpp
index cb83604b53..0ea8a07bc9 100644
--- a/engines/sci/engine/kpathing.cpp
+++ b/engines/sci/engine/kpathing.cpp
@@ -78,8 +78,7 @@
#define PF_FATAL -2
/* Floating point struct */
-typedef struct pointf
-{
+typedef struct pointf {
pointf() : x(0), y(0) {}
pointf(float x_, float y_) : x(x_), y(y_) {}
@@ -87,13 +86,11 @@ typedef struct pointf
} pointf_t;
pointf_t
-to_pointf(point_t p)
-{
+to_pointf(point_t p) {
return pointf(p.x, p.y);
}
-typedef struct vertex
-{
+typedef struct vertex {
/* Location */
point_t v;
@@ -115,8 +112,7 @@ typedef struct vertex
typedef CLIST_HEAD(vertices_head, vertex) vertices_head_t;
-typedef struct polygon
-{
+typedef struct polygon {
/* Circular list of vertices */
vertices_head_t vertices;
@@ -128,8 +124,7 @@ typedef struct polygon
} polygon_t;
/* Pathfinding state */
-typedef struct pf_state
-{
+typedef struct pf_state {
/* List of all polygons */
LIST_HEAD(polygons_head, polygon) polygons;
@@ -156,8 +151,7 @@ static vertex_t *vertex_cur;
/* Temporary hack to deal with points in reg_ts */
static int
-polygon_is_reg_t(unsigned char *list, int size)
-{
+polygon_is_reg_t(unsigned char *list, int size) {
int i;
/* Check the first three reg_ts */
@@ -171,8 +165,7 @@ polygon_is_reg_t(unsigned char *list, int size)
}
static point_t
-read_point(unsigned char *list, int is_reg_t, int offset)
-{
+read_point(unsigned char *list, int is_reg_t, int offset) {
point_t point;
if (!is_reg_t) {
@@ -185,11 +178,10 @@ read_point(unsigned char *list, int is_reg_t, int offset)
}
- /*** Debug functions ***/
+/*** Debug functions ***/
static void
-draw_line(state_t *s, point_t p1, point_t p2, int type)
-{
+draw_line(state_t *s, point_t p1, point_t p2, int type) {
/* Colors for polygon debugging.
** Green: Total access
** Red : Barred access
@@ -218,8 +210,7 @@ draw_line(state_t *s, point_t p1, point_t p2, int type)
}
static void
-draw_point(state_t *s, point_t p, int start)
-{
+draw_point(state_t *s, point_t p, int start) {
/* Colors for starting and end point
** Green: End point
** Blue: Starting point
@@ -243,8 +234,7 @@ draw_point(state_t *s, point_t p, int start)
}
static void
-draw_polygon(state_t *s, reg_t polygon)
-{
+draw_polygon(state_t *s, reg_t polygon) {
reg_t points = GET_SEL32(polygon, points);
int size = KP_UINT(GET_SEL32(polygon, size));
int type = KP_UINT(GET_SEL32(polygon, type));
@@ -265,8 +255,7 @@ draw_polygon(state_t *s, reg_t polygon)
}
static void
-draw_input(state_t *s, reg_t poly_list, point_t start, point_t end, int opt)
-{
+draw_input(state_t *s, reg_t poly_list, point_t start, point_t end, int opt) {
list_t *list;
node_t *node;
@@ -292,8 +281,7 @@ draw_input(state_t *s, reg_t poly_list, point_t start, point_t end, int opt)
}
static void
-print_polygon(state_t *s, reg_t polygon)
-{
+print_polygon(state_t *s, reg_t polygon) {
reg_t points = GET_SEL32(polygon, points);
int size = KP_UINT(GET_SEL32(polygon, size));
int type = KP_UINT(GET_SEL32(polygon, type));
@@ -314,8 +302,7 @@ print_polygon(state_t *s, reg_t polygon)
}
static void
-print_input(state_t *s, reg_t poly_list, point_t start, point_t end, int opt)
-{
+print_input(state_t *s, reg_t poly_list, point_t start, point_t end, int opt) {
list_t *list;
node_t *node;
@@ -343,7 +330,7 @@ print_input(state_t *s, reg_t poly_list, point_t start, point_t end, int opt)
}
- /*** Basic geometry functions ***/
+/*** Basic geometry functions ***/
static int
area(point_t a, point_t b, point_t c)
@@ -416,9 +403,9 @@ intersect_proper(point_t a, point_t b, point_t c, point_t d)
*/
{
int ab = (left(a, b, c) && left(b, a, d))
- || (left(a, b, d) && left(b, a, c));
+ || (left(a, b, d) && left(b, a, c));
int cd = (left(c, d, a) && left(d, c, b))
- || (left(c, d, b) && left(d, c, a));
+ || (left(c, d, b) && left(d, c, a));
return ab && cd;
}
@@ -435,11 +422,11 @@ intersect(point_t a, point_t b, point_t c, point_t d)
return 1;
return between(a, b, c) || between(a, b, d)
- || between (c, d, a) || between(c, d, b);
+ || between(c, d, a) || between(c, d, b);
}
- /*** Pathfinding ***/
+/*** Pathfinding ***/
static vertex_t *
vertex_new(point_t p)
@@ -585,7 +572,7 @@ fix_vertex_order(polygon_t *polygon)
** clockwise
*/
if (((area > 0) && (polygon->type == POLY_CONTAINED_ACCESS))
- || ((area < 0) && (polygon->type != POLY_CONTAINED_ACCESS))) {
+ || ((area < 0) && (polygon->type != POLY_CONTAINED_ACCESS))) {
vertices_head_t vertices;
/* Create a new circular list */
@@ -788,7 +775,7 @@ visible(vertex_t *vertex, vertex_t *vertex_prev, int visible, aatree_t *tree)
** if vertex_prev is invisible
*/
if (vertex_prev && !visible && between(p, w, vertex_prev->v))
- return 0;
+ return 0;
/* Find leftmost node of tree */
while ((tree_n = aatree_walk(tree_n, AATREE_WALK_LEFT)))
@@ -836,14 +823,14 @@ visible_vertices(pf_state_t *s, vertex_t *vert)
/* Check that there is more than one vertex. */
if (VERTEX_HAS_EDGES(vertex))
CLIST_FOREACH(vertex, &polygon->vertices, entries) {
- point_t high, low;
+ point_t high, low;
- /* Add edges that intersect the initial position of the sweeping line */
- clockwise(vertex, &high, &low);
+ /* Add edges that intersect the initial position of the sweeping line */
+ clockwise(vertex, &high, &low);
- if ((high.y < p.y) && (low.y >= p.y) && !POINT_EQUAL(low, p))
- aatree_insert(vertex, &tree, edge_compare);
- }
+ if ((high.y < p.y) && (low.y >= p.y) && !POINT_EQUAL(low, p))
+ aatree_insert(vertex, &tree, edge_compare);
+ }
}
is_visible = 1;
@@ -926,9 +913,9 @@ edge_on_screen_border(point_t p, point_t q)
{
/* FIXME get dimensions from somewhere? */
return ((p.x == 0 && q.x == 0)
- || (p.x == 319 && q.x == 319)
- || (p.y == 0 && q.y == 0)
- || (p.y == 189 && q.y == 189));
+ || (p.x == 319 && q.x == 319)
+ || (p.y == 0 && q.y == 0)
+ || (p.y == 189 && q.y == 189));
}
static int
@@ -944,7 +931,7 @@ find_free_point(pointf_t f, polygon_t *polygon, point_t *ret)
/* Try nearest point first */
p = gfx_point((int) floor(f.x + 0.5),
- (int) floor(f.y + 0.5));
+ (int) floor(f.y + 0.5));
if (contained(p, polygon) != CONT_INSIDE) {
*ret = p;
@@ -952,7 +939,7 @@ find_free_point(pointf_t f, polygon_t *polygon, point_t *ret)
}
p = gfx_point((int) floor(f.x),
- (int) floor(f.y));
+ (int) floor(f.y));
/* Try (x, y), (x + 1, y), (x , y + 1) and (x + 1, y + 1) */
if (contained(p, polygon) == CONT_INSIDE) {
@@ -1039,24 +1026,24 @@ intersection(point_t a, point_t b, vertex_t *vertex, pointf_t *ret)
point_t c = vertex->v;
point_t d = CLIST_NEXT(vertex, entries)->v;
- denom = a.x * (float) (d.y - c.y) +
- b.x * (float) (c.y - d.y) +
- d.x * (float) (b.y - a.y) +
- c.x * (float) (a.y - b.y);
+ denom = a.x * (float)(d.y - c.y) +
+ b.x * (float)(c.y - d.y) +
+ d.x * (float)(b.y - a.y) +
+ c.x * (float)(a.y - b.y);
if (denom == 0.0)
/* Segments are parallel, no intersection */
return PF_ERROR;
- num = a.x * (float) (d.y - c.y) +
- c.x * (float) (a.y - d.y) +
- d.x * (float) (c.y - a.y);
+ num = a.x * (float)(d.y - c.y) +
+ c.x * (float)(a.y - d.y) +
+ d.x * (float)(c.y - a.y);
s = num / denom;
- num = -(a.x * (float) (c.y - b.y) +
- b.x * (float) (a.y - c.y) +
- c.x * (float) (b.y - a.y));
+ num = -(a.x * (float)(c.y - b.y) +
+ b.x * (float)(a.y - c.y) +
+ c.x * (float)(b.y - a.y));
t = num / denom;
@@ -1204,25 +1191,25 @@ merge_point(pf_state_t *s, point_t v)
/* Check for already existing vertex */
LIST_FOREACH(polygon, &s->polygons, entries) {
CLIST_FOREACH(vertex, &polygon->vertices, entries)
- if (POINT_EQUAL(vertex->v, v))
- return vertex;
+ if (POINT_EQUAL(vertex->v, v))
+ return vertex;
}
v_new = vertex_new(v);
/* Check for point being on an edge */
LIST_FOREACH(polygon, &s->polygons, entries)
- /* Skip single-vertex polygons */
- if (VERTEX_HAS_EDGES(CLIST_FIRST(&polygon->vertices)))
- CLIST_FOREACH(vertex, &polygon->vertices, entries) {
- vertex_t *next = CLIST_NEXT(vertex, entries);
+ /* Skip single-vertex polygons */
+ if (VERTEX_HAS_EDGES(CLIST_FIRST(&polygon->vertices)))
+ CLIST_FOREACH(vertex, &polygon->vertices, entries) {
+ vertex_t *next = CLIST_NEXT(vertex, entries);
- if (between(vertex->v, next->v, v)) {
- /* Split edge by adding vertex */
- CLIST_INSERT_AFTER(vertex, v_new, entries);
- return v_new;
- }
- }
+ if (between(vertex->v, next->v, v)) {
+ /* Split edge by adding vertex */
+ CLIST_INSERT_AFTER(vertex, v_new, entries);
+ return v_new;
+ }
+ }
/* Add point as single-vertex polygon */
polygon = polygon_new(POLY_BARRED_ACCESS);
@@ -1368,8 +1355,7 @@ convert_polygon_set(state_t *s, reg_t poly_list, point_t start, point_t end, int
sciprintf("[avoidpath] Error: fatal error finding nearest intersecton\n");
free_pf_state(pf_s);
return NULL;
- }
- else if (err == PF_OK)
+ } else if (err == PF_OK)
/* Keep original start position if intersection
** was found
*/
@@ -1379,8 +1365,7 @@ convert_polygon_set(state_t *s, reg_t poly_list, point_t start, point_t end, int
sciprintf("[avoidpath] Error: couldn't fix start position for pathfinding\n");
free_pf_state(pf_s);
return NULL;
- }
- else if (polygon) {
+ } else if (polygon) {
/* Start position has moved */
pf_s->keep_start = 1;
if ((polygon->type != POLY_NEAREST_ACCESS))
@@ -1392,8 +1377,7 @@ convert_polygon_set(state_t *s, reg_t poly_list, point_t start, point_t end, int
sciprintf("[avoidpath] Error: couldn't fix end position for pathfinding\n");
free_pf_state(pf_s);
return NULL;
- }
- else {
+ } else {
/* Keep original end position if it is contained in a
** near-point accessible polygon
*/
@@ -1440,7 +1424,7 @@ visibility_graph(pf_state_t *s)
vertex_t *vertex;
CLIST_FOREACH(vertex, &polygon->vertices, entries)
- visible_vertices(s, vertex);
+ visible_vertices(s, vertex);
}
}
@@ -1464,11 +1448,11 @@ intersecting_polygons(pf_state_t *s)
/* Skip neighbouring edges */
if ((CLIST_NEXT(v1, entries) == v2)
- || CLIST_PREV(v1, entries) == v2)
+ || CLIST_PREV(v1, entries) == v2)
continue;
if (intersect(v1->v, CLIST_NEXT(v1, entries)->v,
- v2->v, CLIST_NEXT(v2, entries)->v))
+ v2->v, CLIST_NEXT(v2, entries)->v))
return 1;
}
}
@@ -1500,7 +1484,7 @@ dijkstra(pf_state_t *s)
vertex_t *vertex;
CLIST_FOREACH(vertex, &polygon->vertices, entries)
- LIST_INSERT_HEAD(&remain, vertex, dijkstra);
+ LIST_INSERT_HEAD(&remain, vertex, dijkstra);
}
s->vertex_start->dist = 0.0f;
@@ -1542,7 +1526,7 @@ dijkstra(pf_state_t *s)
continue;
new_dist = vertex_min->dist + distance(to_pointf(vertex_min->v),
- to_pointf(s->vertex_index[i]->v));
+ to_pointf(s->vertex_index[i]->v));
if (new_dist < s->vertex_index[i]->dist) {
s->vertex_index[i]->dist = new_dist;
s->vertex_index[i]->path_prev = vertex_min;
@@ -1570,7 +1554,7 @@ output_path(pf_state_t *p, state_t *s)
if (unreachable) {
/* If pathfinding failed we only return the path up to vertex_start */
oref = sm_alloc_dynmem(&s->seg_manager, POLY_POINT_SIZE * 3,
- AVOIDPATH_DYNMEM_STRING, &output);
+ AVOIDPATH_DYNMEM_STRING, &output);
if (p->keep_start)
POLY_SET_POINT(oref, 0, p->start.x, p->start.y);
@@ -1589,7 +1573,7 @@ output_path(pf_state_t *p, state_t *s)
}
oref = sm_alloc_dynmem(&s->seg_manager, POLY_POINT_SIZE * (path_len + 1 + p->keep_start + p->keep_end),
- AVOIDPATH_DYNMEM_STRING, &output);
+ AVOIDPATH_DYNMEM_STRING, &output);
/* Sentinel */
POLY_SET_POINT(oref, path_len + p->keep_start + p->keep_end, POLY_LAST_POINT, POLY_LAST_POINT);
@@ -1630,12 +1614,11 @@ output_path(pf_state_t *p, state_t *s)
}
reg_t
-kAvoidPath(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kAvoidPath(state_t *s, int funct_nr, int argc, reg_t *argv) {
point_t start = gfx_point(SKPV(0), SKPV(1));
if (s->debug_mode & (1 << SCIkAVOIDPATH_NR)) {
- gfxw_port_t *port= s->picture_port;
+ gfxw_port_t *port = s->picture_port;
if (!port->decorations) {
port->decorations = gfxw_new_list(gfx_rect(0, 0, 320, 200), 0);
@@ -1647,8 +1630,7 @@ kAvoidPath(state_t *s, int funct_nr, int argc, reg_t *argv)
switch (argc) {
- case 3 :
- {
+ case 3 : {
reg_t retval;
polygon_t *polygon = convert_polygon(s, argv[2]);
@@ -1664,8 +1646,7 @@ kAvoidPath(state_t *s, int funct_nr, int argc, reg_t *argv)
return retval;
}
case 6 :
- case 7 :
- {
+ case 7 : {
point_t end = gfx_point(SKPV(2), SKPV(3));
reg_t poly_list = argv[4];
/* int poly_list_size = UKPV(5); */
@@ -1697,8 +1678,8 @@ kAvoidPath(state_t *s, int funct_nr, int argc, reg_t *argv)
sciprintf("[avoidpath] Error: pathfinding failed for following input:\n");
print_input(s, poly_list, start, end, opt);
sciprintf("[avoidpath] Returning direct path from start point to end point\n");
- oref = sm_alloc_dynmem(&s->seg_manager, POLY_POINT_SIZE*3,
- AVOIDPATH_DYNMEM_STRING, &output);
+ oref = sm_alloc_dynmem(&s->seg_manager, POLY_POINT_SIZE * 3,
+ AVOIDPATH_DYNMEM_STRING, &output);
POLY_SET_POINT(oref, 0, start.x, start.y);
POLY_SET_POINT(oref, 1, end.x, end.y);
@@ -1719,7 +1700,7 @@ kAvoidPath(state_t *s, int funct_nr, int argc, reg_t *argv)
default:
SCIkwarn(SCIkWARNING, "Unknown AvoidPath subfunction %d\n",
- argc);
+ argc);
return NULL_REG;
break;
}
diff --git a/engines/sci/engine/kscripts.cpp b/engines/sci/engine/kscripts.cpp
index 02517365c8..d8c0292f6c 100644
--- a/engines/sci/engine/kscripts.cpp
+++ b/engines/sci/engine/kscripts.cpp
@@ -30,8 +30,7 @@
#include "sci/engine/kernel_types.h"
reg_t
-read_selector(state_t *s, reg_t object, selector_t selector_id, const char *file, int line)
-{
+read_selector(state_t *s, reg_t object, selector_t selector_id, const char *file, int line) {
reg_t *address;
if (lookup_selector(s, object, selector_id, &address, NULL) != SELECTOR_VARIABLE)
@@ -43,21 +42,20 @@ read_selector(state_t *s, reg_t object, selector_t selector_id, const char *file
void
write_selector(state_t *s, reg_t object, selector_t selector_id, reg_t value,
- const char *fname, int line)
-{
+ const char *fname, int line) {
reg_t *address;
if ((selector_id < 0) || (selector_id > s->selector_names_nr)) {
SCIkwarn(SCIkWARNING, "Attempt to write to invalid selector %d of"
- " object at "PREG" (%s L%d).\n", selector_id,
- PRINT_REG(object), fname, line);
+ " object at "PREG" (%s L%d).\n", selector_id,
+ PRINT_REG(object), fname, line);
return;
}
if (lookup_selector(s, object, selector_id, &address, NULL) != SELECTOR_VARIABLE)
SCIkwarn(SCIkWARNING, "Selector '%s' of object at %04x could not be"
- " written to (%s L%d)\n",
- s->selector_names[selector_id], object, fname, line);
+ " written to (%s L%d)\n",
+ s->selector_names[selector_id], object, fname, line);
else
*address = value;
@@ -65,9 +63,8 @@ write_selector(state_t *s, reg_t object, selector_t selector_id, reg_t value,
int
invoke_selector(state_t *s, reg_t object, int selector_id, int noinvalid, int kfunct,
- stack_ptr_t k_argp, int k_argc, /* Kernel function argp/argc */
- const char *fname, int line, int argc, ...)
-{
+ stack_ptr_t k_argp, int k_argc, /* Kernel function argp/argc */
+ const char *fname, int line, int argc, ...) {
va_list argp;
int i;
int framesize = 2 + 1 * argc;
@@ -84,7 +81,7 @@ invoke_selector(state_t *s, reg_t object, int selector_id, int noinvalid, int kf
if (slc_type == SELECTOR_NONE) {
SCIkwarn(SCIkERROR, "Selector '%s' of object at "PREG" could not be invoked (%s L%d)\n",
- s->selector_names[selector_id], PRINT_REG(object), fname, line);
+ s->selector_names[selector_id], PRINT_REG(object), fname, line);
if (noinvalid == 0)
KERNEL_OOPS("Not recoverable: VM was halted\n");
return 1;
@@ -101,17 +98,17 @@ invoke_selector(state_t *s, reg_t object, int selector_id, int noinvalid, int kf
/* Write "kernel" call to the stack, for debugging: */
xstack = add_exec_stack_entry(s, NULL_REG, NULL, NULL_REG,
- k_argc, k_argp - 1, 0, NULL_REG,
- s->execution_stack_pos, SCI_XS_CALLEE_LOCALS);
+ k_argc, k_argp - 1, 0, NULL_REG,
+ s->execution_stack_pos, SCI_XS_CALLEE_LOCALS);
xstack->selector = -42 - kfunct; /* Evil debugging hack to identify kernel function */
xstack->type = EXEC_STACK_TYPE_KERNEL;
/* Now commit the actual function: */
xstack = send_selector(s, object, object,
- stackframe, framesize, stackframe);
+ stackframe, framesize, stackframe);
- xstack->sp += argc+2;
- xstack->fp += argc+2;
+ xstack->sp += argc + 2;
+ xstack->fp += argc + 2;
run_vm(s, 0); /* Start a new vm */
@@ -122,8 +119,7 @@ invoke_selector(state_t *s, reg_t object, int selector_id, int noinvalid, int kf
int
-is_object(state_t *s, reg_t object)
-{
+is_object(state_t *s, reg_t object) {
return obj_get(s, object) != NULL;
}
@@ -133,28 +129,25 @@ is_object(state_t *s, reg_t object)
** This implementation ignores all resource numbers except the first one.
*/
reg_t
-kLoad(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kLoad(state_t *s, int funct_nr, int argc, reg_t *argv) {
int restype = KP_UINT(argv[0]);
int resnr = KP_UINT(argv[1]);
if (restype == sci_memory)/* Request to dynamically allocate hunk memory for later use */
return kalloc(s, "kLoad()", resnr);
-
+
return make_reg(0, ((restype << 11) | resnr)); /* Return the resource identifier as handle */
}
reg_t
-kLock(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
- int restype = UKPV(0)&0x7f;
+kLock(state_t *s, int funct_nr, int argc, reg_t *argv) {
+ int restype = UKPV(0) & 0x7f;
int resnr = UKPV(1);
int state = argc > 2 ? UKPV(2) : 1;
resource_t *which;
- switch (state)
- {
+ switch (state) {
case 1 :
scir_find_resource(s->resmgr, restype, resnr, 1);
break;
@@ -170,8 +163,7 @@ kLock(state_t *s, int funct_nr, int argc, reg_t *argv)
** Unloads an arbitrary resource of type 'restype' with resource numbber 'resnr'
*/
reg_t
-kUnLoad(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kUnLoad(state_t *s, int funct_nr, int argc, reg_t *argv) {
int restype = KP_UINT(argv[0]);
reg_t resnr = argv[1];
@@ -183,8 +175,7 @@ kUnLoad(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kClone(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kClone(state_t *s, int funct_nr, int argc, reg_t *argv) {
reg_t parent_addr = argv[0];
object_t *parent_obj = obj_get(s, parent_addr);
reg_t clone_addr;
@@ -225,18 +216,17 @@ kClone(state_t *s, int funct_nr, int argc, reg_t *argv)
extern void
-_k_view_list_mark_free(state_t *s, reg_t off); /* kgraphics.c */
+ _k_view_list_mark_free(state_t *s, reg_t off); /* kgraphics.c */
reg_t
-kDisposeClone(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kDisposeClone(state_t *s, int funct_nr, int argc, reg_t *argv) {
reg_t victim_addr = argv[0];
clone_t *victim_obj = obj_get(s, victim_addr);
word underBits;
if (!victim_obj) {
SCIkwarn(SCIkERROR, "Attempt to dispose non-class/object at "PREG"\n",
- PRINT_REG(victim_addr));
+ PRINT_REG(victim_addr));
return s->r_acc;
}
@@ -248,7 +238,7 @@ kDisposeClone(state_t *s, int funct_nr, int argc, reg_t *argv)
underBits = GET_SEL32V(victim_addr, underBits);
if (underBits) {
- SCIkwarn(SCIkWARNING,"Clone "PREG" was cleared with underBits set\n", PRINT_REG(victim_addr));
+ SCIkwarn(SCIkWARNING, "Clone "PREG" was cleared with underBits set\n", PRINT_REG(victim_addr));
}
#if 0
if (s->dyn_views) { /* Free any widget associated with the clone */
@@ -261,7 +251,7 @@ kDisposeClone(state_t *s, int funct_nr, int argc, reg_t *argv)
victim_obj->flags |= OBJECT_FLAG_FREED;
- _k_view_list_mark_free(s, victim_addr); /* Free on view list, if neccessary */
+ _k_view_list_mark_free(s, victim_addr); /* Free on view list, if neccessary */
return s->r_acc;
}
@@ -271,8 +261,7 @@ kDisposeClone(state_t *s, int funct_nr, int argc, reg_t *argv)
** Returns script dispatch address index in the supplied script
*/
reg_t
-kScriptID(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kScriptID(state_t *s, int funct_nr, int argc, reg_t *argv) {
int script = KP_UINT(argv[0]);
int index = KP_UINT(KP_ALT(1, NULL_REG));
@@ -294,7 +283,7 @@ kScriptID(state_t *s, int funct_nr, int argc, reg_t *argv)
if (index > scr->exports_nr) {
SCIkwarn(SCIkERROR, "Dispatch index too big: %d > %d\n",
- index, scr->exports_nr);
+ index, scr->exports_nr);
return NULL_REG;
}
@@ -303,19 +292,17 @@ kScriptID(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kDisposeScript(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kDisposeScript(state_t *s, int funct_nr, int argc, reg_t *argv) {
int script = argv[0].offset;
-
+
/* Work around QfG1 graveyard bug */
if (argv[0].segment) return s->r_acc;
- if (sm_script_is_loaded(&(s->seg_manager), script, SCRIPT_ID))
- {
- int id = sm_seg_get(&(s->seg_manager), script);
-
- if (s->execution_stack[s->execution_stack_pos].addr.pc.segment != id)
- sm_set_lockers(&(s->seg_manager), 1, script, SCRIPT_ID);
+ if (sm_script_is_loaded(&(s->seg_manager), script, SCRIPT_ID)) {
+ int id = sm_seg_get(&(s->seg_manager), script);
+
+ if (s->execution_stack[s->execution_stack_pos].addr.pc.segment != id)
+ sm_set_lockers(&(s->seg_manager), 1, script, SCRIPT_ID);
}
script_uninstantiate(s, script);
@@ -324,17 +311,15 @@ kDisposeScript(state_t *s, int funct_nr, int argc, reg_t *argv)
}
int
-is_heap_object(state_t *s, reg_t pos)
-{
+is_heap_object(state_t *s, reg_t pos) {
object_t *obj = obj_get(s, pos);
return (obj != NULL
- && (!(obj->flags & OBJECT_FLAG_FREED))
- && (!sm_script_is_marked_as_deleted(&s->seg_manager, pos.segment)));
+ && (!(obj->flags & OBJECT_FLAG_FREED))
+ && (!sm_script_is_marked_as_deleted(&s->seg_manager, pos.segment)));
}
reg_t
-kIsObject(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kIsObject(state_t *s, int funct_nr, int argc, reg_t *argv) {
if (argv[0].offset == 0xffff) /* Treated specially */
return NULL_REG;
else
@@ -342,12 +327,11 @@ kIsObject(state_t *s, int funct_nr, int argc, reg_t *argv)
}
reg_t
-kRespondsTo(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kRespondsTo(state_t *s, int funct_nr, int argc, reg_t *argv) {
reg_t obj = argv[0];
int selector = KP_UINT(argv[1]);
return make_reg(0, is_heap_object(s, obj)
- && lookup_selector(s, obj, selector, NULL, NULL) != SELECTOR_NONE);
+ && lookup_selector(s, obj, selector, NULL, NULL) != SELECTOR_NONE);
}
diff --git a/engines/sci/engine/ksound.cpp b/engines/sci/engine/ksound.cpp
index cae55695ce..2921c8458f 100644
--- a/engines/sci/engine/ksound.cpp
+++ b/engines/sci/engine/ksound.cpp
@@ -57,7 +57,7 @@
#define _K_SCI01_SOUND_MIDI_SEND 12
#define _K_SCI01_SOUND_REVERB 13 /* Get/Set */
#define _K_SCI01_SOUND_HOLD 14
-
+
#define _K_SCI1_SOUND_MASTER_VOLME 0 /* Set/Get */
#define _K_SCI1_SOUND_MUTE_SOUND 1
#define _K_SCI1_SOUND_UNUSED1 2
@@ -76,7 +76,7 @@
#define _K_SCI1_SOUND_SET_HANDLE_PRIORITY 15
#define _K_SCI1_SOUND_SET_HANDLE_LOOP 16
#define _K_SCI1_SOUND_UPDATE_CUES 17
-#define _K_SCI1_SOUND_MIDI_SEND 18
+#define _K_SCI1_SOUND_MIDI_SEND 18
#define _K_SCI1_SOUND_REVERB 19 /* Get/Set */
#define _K_SCI1_SOUND_UPDATE_VOL_PRI 20
@@ -91,16 +91,15 @@
static void
-script_set_priority(state_t *s, reg_t obj, int priority)
-{
+script_set_priority(state_t *s, reg_t obj, int priority) {
int song_nr = GET_SEL32V(obj, number);
resource_t *song = scir_find_resource(s->resmgr, sci_sound, song_nr, 0);
int flags = GET_SEL32V(obj, flags);
- if (priority == -1)
- {
+ if (priority == -1) {
if (song->data[0] == 0xf0)
- priority = song->data[1]; else
+ priority = song->data[1];
+ else
SCIkdebug(SCIkWARNING, "Attempt to unset song priority when there is no built-in value!\n");
flags &= ~SCI1_SOUND_FLAG_SCRIPTED_PRI;
@@ -111,8 +110,7 @@ script_set_priority(state_t *s, reg_t obj, int priority)
}
song_iterator_t *
-build_iterator(state_t *s, int song_nr, int type, songit_id_t id)
-{
+build_iterator(state_t *s, int song_nr, int type, songit_id_t id) {
resource_t *song = scir_find_resource(s->resmgr, sci_sound, song_nr, 0);
if (!song)
@@ -123,13 +121,12 @@ build_iterator(state_t *s, int song_nr, int type, songit_id_t id)
void
-process_sound_events(state_t *s) /* Get all sound events, apply their changes to the heap */
-{
+process_sound_events(state_t *s) { /* Get all sound events, apply their changes to the heap */
int result;
song_handle_t handle;
int cue;
- if (s->version>=SCI_VERSION_FTU_DOSOUND_VARIANT_1)
+ if (s->version >= SCI_VERSION_FTU_DOSOUND_VARIANT_1)
return;
/* SCI01 and later explicitly poll for everything */
@@ -144,26 +141,26 @@ process_sound_events(state_t *s) /* Get all sound events, apply their changes to
case SI_LOOP:
SCIkdebug(SCIkSOUND, "[process-sound] Song "PREG" looped (to %d)\n",
- PRINT_REG(obj), cue);
+ PRINT_REG(obj), cue);
/* PUT_SEL32V(obj, loops, GET_SEL32V(obj, loop) - 1);*/
PUT_SEL32V(obj, signal, -1);
break;
case SI_RELATIVE_CUE:
SCIkdebug(SCIkSOUND, "[process-sound] Song "PREG" received relative cue %d\n",
- PRINT_REG(obj), cue);
+ PRINT_REG(obj), cue);
PUT_SEL32V(obj, signal, cue + 0x7f);
break;
case SI_ABSOLUTE_CUE:
SCIkdebug(SCIkSOUND, "[process-sound] Song "PREG" received absolute cue %d\n",
- PRINT_REG(obj), cue);
+ PRINT_REG(obj), cue);
PUT_SEL32V(obj, signal, cue);
break;
case SI_FINISHED:
SCIkdebug(SCIkSOUND, "[process-sound] Song "PREG" finished\n",
- PRINT_REG(obj));
+ PRINT_REG(obj));
PUT_SEL32V(obj, signal, -1);
PUT_SEL32V(obj, state, _K_SOUND_STATUS_STOPPED);
break;
@@ -177,34 +174,61 @@ process_sound_events(state_t *s) /* Get all sound events, apply their changes to
reg_t
-kDoSound_SCI0(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kDoSound_SCI0(state_t *s, int funct_nr, int argc, reg_t *argv) {
reg_t obj = KP_ALT(1, NULL_REG);
word command = UKPV(0);
song_handle_t handle = FROBNICATE_HANDLE(obj);
- int number = obj.segment ?
- GET_SEL32V(obj, number) :
- -1; /* We were not going to use it anyway */
+ int number = obj.segment ?
+ GET_SEL32V(obj, number) :
+ -1; /* We were not going to use it anyway */
if (s->debug_mode & (1 << SCIkSOUNDCHK_NR)) {
int i;
SCIkdebug(SCIkSOUND, "Command 0x%x", command);
switch (command) {
- case 0: sciprintf("[InitObj]"); break;
- case 1: sciprintf("[Play]"); break;
- case 2: sciprintf("[NOP]"); break;
- case 3: sciprintf("[DisposeHandle]"); break;
- case 4: sciprintf("[SetSoundOn(?)]"); break;
- case 5: sciprintf("[Stop]"); break;
- case 6: sciprintf("[Suspend]"); break;
- case 7: sciprintf("[Resume]"); break;
- case 8: sciprintf("[Get(Set?)Volume]"); break;
- case 9: sciprintf("[Signal: Obj changed]"); break;
- case 10: sciprintf("[Fade(?)]"); break;
- case 11: sciprintf("[ChkDriver]"); break;
- case 12: sciprintf("[PlayNextSong (formerly StopAll)]"); break;
- default: sciprintf("[unknown]"); break;
+ case 0:
+ sciprintf("[InitObj]");
+ break;
+ case 1:
+ sciprintf("[Play]");
+ break;
+ case 2:
+ sciprintf("[NOP]");
+ break;
+ case 3:
+ sciprintf("[DisposeHandle]");
+ break;
+ case 4:
+ sciprintf("[SetSoundOn(?)]");
+ break;
+ case 5:
+ sciprintf("[Stop]");
+ break;
+ case 6:
+ sciprintf("[Suspend]");
+ break;
+ case 7:
+ sciprintf("[Resume]");
+ break;
+ case 8:
+ sciprintf("[Get(Set?)Volume]");
+ break;
+ case 9:
+ sciprintf("[Signal: Obj changed]");
+ break;
+ case 10:
+ sciprintf("[Fade(?)]");
+ break;
+ case 11:
+ sciprintf("[ChkDriver]");
+ break;
+ case 12:
+ sciprintf("[PlayNextSong (formerly StopAll)]");
+ break;
+ default:
+ sciprintf("[unknown]");
+ break;
}
sciprintf("(");
@@ -222,10 +246,10 @@ kDoSound_SCI0(state_t *s, int funct_nr, int argc, reg_t *argv)
if (obj.segment) {
sciprintf("Initializing song number %d\n", GET_SEL32V(obj, number));
SCRIPT_ASSERT_ZERO(sfx_add_song(&s->sound,
- build_iterator(s, number,
- SCI_SONG_ITERATOR_TYPE_SCI0,
- handle),
- 0, handle, number));
+ build_iterator(s, number,
+ SCI_SONG_ITERATOR_TYPE_SCI0,
+ handle),
+ 0, handle, number));
PUT_SEL32V(obj, state, _K_SOUND_STATUS_INITIALIZED);
PUT_SEL32(obj, handle, obj); /* ``sound handle'': we use the object address */
}
@@ -234,9 +258,9 @@ kDoSound_SCI0(state_t *s, int funct_nr, int argc, reg_t *argv)
case _K_SCI0_SOUND_PLAY_HANDLE:
if (obj.segment) {
sfx_song_set_status(&s->sound,
- handle, SOUND_STATUS_PLAYING);
+ handle, SOUND_STATUS_PLAYING);
sfx_song_set_loops(&s->sound,
- handle, GET_SEL32V(obj, loop));
+ handle, GET_SEL32V(obj, loop));
PUT_SEL32V(obj, state, _K_SOUND_STATUS_PLAYING);
}
break;
@@ -254,7 +278,7 @@ kDoSound_SCI0(state_t *s, int funct_nr, int argc, reg_t *argv)
case _K_SCI0_SOUND_STOP_HANDLE:
if (obj.segment) {
sfx_song_set_status(&s->sound,
- handle, SOUND_STATUS_STOPPED);
+ handle, SOUND_STATUS_STOPPED);
PUT_SEL32V(obj, state, SOUND_STATUS_STOPPED);
}
break;
@@ -262,7 +286,7 @@ kDoSound_SCI0(state_t *s, int funct_nr, int argc, reg_t *argv)
case _K_SCI0_SOUND_SUSPEND_HANDLE:
if (obj.segment) {
sfx_song_set_status(&s->sound,
- handle, SOUND_STATUS_SUSPENDED);
+ handle, SOUND_STATUS_SUSPENDED);
PUT_SEL32V(obj, state, SOUND_STATUS_SUSPENDED);
}
break;
@@ -270,7 +294,7 @@ kDoSound_SCI0(state_t *s, int funct_nr, int argc, reg_t *argv)
case _K_SCI0_SOUND_RESUME_HANDLE:
if (obj.segment) {
sfx_song_set_status(&s->sound,
- handle, SOUND_STATUS_PLAYING);
+ handle, SOUND_STATUS_PLAYING);
PUT_SEL32V(obj, state, SOUND_STATUS_PLAYING);
}
break;
@@ -286,7 +310,7 @@ kDoSound_SCI0(state_t *s, int funct_nr, int argc, reg_t *argv)
s->acc = s->sound_server->command(s, SOUND_COMMAND_GET_MUTE, 0, 0);*/
}
- break;
+ break;
case _K_SCI0_SOUND_VOLUME: {
/* range from 0x0 to 0xf */
@@ -298,23 +322,23 @@ kDoSound_SCI0(state_t *s, int funct_nr, int argc, reg_t *argv)
else
s->r_acc = make_reg(0, sfx_get_volume(&s->sound) >> 0xf);
}
- break;
+ break;
case _K_SCI0_SOUND_UPDATE_VOL_PRI:
if (obj.segment) {
sfx_song_set_loops(&s->sound,
- handle, GET_SEL32V(obj, loop));
+ handle, GET_SEL32V(obj, loop));
script_set_priority(s, obj, GET_SEL32V(obj, pri));
}
break;
case _K_SCI0_SOUND_FADE_HANDLE:
/*s->sound_server->command(s, SOUND_COMMAND_FADE_HANDLE, obj, 120);*/ /* Fade out in 2 secs */
- /* FIXME: The next couple of lines actually STOP the handle, rather
- ** than fading it! */
+ /* FIXME: The next couple of lines actually STOP the handle, rather
+ ** than fading it! */
if (obj.segment) {
sfx_song_set_status(&s->sound,
- handle, SOUND_STATUS_STOPPED);
+ handle, SOUND_STATUS_STOPPED);
PUT_SEL32V(obj, state, SOUND_STATUS_STOPPED);
PUT_SEL32V(obj, signal, -1);
}
@@ -325,7 +349,7 @@ kDoSound_SCI0(state_t *s, int funct_nr, int argc, reg_t *argv)
break;
case _K_SCI0_SOUND_PLAY_NEXT:
- /* sfx_all_stop(&s->sound);*/
+ /* sfx_all_stop(&s->sound);*/
break;
default:
@@ -339,40 +363,71 @@ kDoSound_SCI0(state_t *s, int funct_nr, int argc, reg_t *argv)
int
sfx_send_midi(sfx_state_t *self, song_handle_t handle, int channel,
- int command, int arg1, int arg2);
+ int command, int arg1, int arg2);
reg_t
-kDoSound_SCI01(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kDoSound_SCI01(state_t *s, int funct_nr, int argc, reg_t *argv) {
word command = UKPV(0);
reg_t obj = KP_ALT(1, NULL_REG);
- song_handle_t handle = FROBNICATE_HANDLE(obj);
- int number = obj.segment ?
- GET_SEL32V(obj, number) :
- -1; /* We were not going to use it anyway */
+ song_handle_t handle = FROBNICATE_HANDLE(obj);
+ int number = obj.segment ?
+ GET_SEL32V(obj, number) :
+ -1; /* We were not going to use it anyway */
if ((s->debug_mode & (1 << SCIkSOUNDCHK_NR))
- && command != _K_SCI01_SOUND_UPDATE_CUES) {
+ && command != _K_SCI01_SOUND_UPDATE_CUES) {
int i;
SCIkdebug(SCIkSOUND, "Command 0x%x", command);
switch (command) {
- case 0: sciprintf("[MasterVolume]"); break;
- case 1: sciprintf("[Mute]"); break;
- case 2: sciprintf("[NOP(2)]"); break;
- case 3: sciprintf("[GetPolyphony]"); break;
- case 4: sciprintf("[Update]"); break;
- case 5: sciprintf("[Init]"); break;
- case 6: sciprintf("[Dispose]"); break;
- case 7: sciprintf("[Play]"); break;
- case 8: sciprintf("[Stop]"); break;
- case 9: sciprintf("[Suspend]"); break;
- case 10: sciprintf("[Fade]"); break;
- case 11: sciprintf("[UpdateCues]"); break;
- case 12: sciprintf("[MidiSend]"); break;
- case 13: sciprintf("[Reverb]"); break;
- case 14: sciprintf("[Hold]"); break;
- default: sciprintf("[unknown]"); break;
+ case 0:
+ sciprintf("[MasterVolume]");
+ break;
+ case 1:
+ sciprintf("[Mute]");
+ break;
+ case 2:
+ sciprintf("[NOP(2)]");
+ break;
+ case 3:
+ sciprintf("[GetPolyphony]");
+ break;
+ case 4:
+ sciprintf("[Update]");
+ break;
+ case 5:
+ sciprintf("[Init]");
+ break;
+ case 6:
+ sciprintf("[Dispose]");
+ break;
+ case 7:
+ sciprintf("[Play]");
+ break;
+ case 8:
+ sciprintf("[Stop]");
+ break;
+ case 9:
+ sciprintf("[Suspend]");
+ break;
+ case 10:
+ sciprintf("[Fade]");
+ break;
+ case 11:
+ sciprintf("[UpdateCues]");
+ break;
+ case 12:
+ sciprintf("[MidiSend]");
+ break;
+ case 13:
+ sciprintf("[Reverb]");
+ break;
+ case 14:
+ sciprintf("[Hold]");
+ break;
+ default:
+ sciprintf("[unknown]");
+ break;
}
sciprintf("(");
@@ -384,10 +439,8 @@ kDoSound_SCI01(state_t *s, int funct_nr, int argc, reg_t *argv)
sciprintf(")\n");
}
- switch (command)
- {
- case _K_SCI01_SOUND_MASTER_VOLME :
- {
+ switch (command) {
+ case _K_SCI01_SOUND_MASTER_VOLME : {
int vol = SKPV_OR_ALT(1, -1);
if (vol != -1)
@@ -396,8 +449,7 @@ kDoSound_SCI01(state_t *s, int funct_nr, int argc, reg_t *argv)
s->r_acc = make_reg(0, sfx_get_volume(&s->sound) >> 0xf);
break;
}
- case _K_SCI01_SOUND_MUTE_SOUND :
- {
+ case _K_SCI01_SOUND_MUTE_SOUND : {
/* if there's a parameter, we're setting it. Otherwise,
we're querying it. */
/*int param = UPARAM_OR_ALT(1,-1);
@@ -409,17 +461,14 @@ kDoSound_SCI01(state_t *s, int funct_nr, int argc, reg_t *argv)
break;
}
- case _K_SCI01_SOUND_UNUSED :
- {
+ case _K_SCI01_SOUND_UNUSED : {
break;
}
- case _K_SCI01_SOUND_GET_POLYPHONY :
- {
+ case _K_SCI01_SOUND_GET_POLYPHONY : {
s->r_acc = make_reg(0, sfx_get_player_polyphony());
break;
}
- case _K_SCI01_SOUND_PLAY_HANDLE :
- {
+ case _K_SCI01_SOUND_PLAY_HANDLE : {
int looping = GET_SEL32V(obj, loop);
//int vol = GET_SEL32V(obj, vol);
int pri = GET_SEL32V(obj, pri);
@@ -427,46 +476,42 @@ kDoSound_SCI01(state_t *s, int funct_nr, int argc, reg_t *argv)
if (obj.segment) {
sfx_song_set_status(&s->sound,
- handle, SOUND_STATUS_PLAYING);
+ handle, SOUND_STATUS_PLAYING);
sfx_song_set_loops(&s->sound,
- handle, looping);
+ handle, looping);
sfx_song_renice(&s->sound,
- handle, pri);
+ handle, pri);
song_lib_set_restore_behavior(s->sound.songlib, handle, rb);
}
break;
}
- case _K_SCI01_SOUND_INIT_HANDLE :
- {
+ case _K_SCI01_SOUND_INIT_HANDLE : {
//int looping = GET_SEL32V(obj, loop);
//int vol = GET_SEL32V(obj, vol);
//int pri = GET_SEL32V(obj, pri);
- if (obj.segment && (scir_test_resource(s->resmgr, sci_sound, number)))
- {
+ if (obj.segment && (scir_test_resource(s->resmgr, sci_sound, number))) {
sciprintf("Initializing song number %d\n", number);
SCRIPT_ASSERT_ZERO(sfx_add_song(&s->sound,
- build_iterator(s, number,
- SCI_SONG_ITERATOR_TYPE_SCI1,
- handle),
- 0, handle, number));
+ build_iterator(s, number,
+ SCI_SONG_ITERATOR_TYPE_SCI1,
+ handle),
+ 0, handle, number));
PUT_SEL32(obj, nodePtr, obj);
PUT_SEL32(obj, handle, obj);
}
break;
}
- case _K_SCI01_SOUND_DISPOSE_HANDLE :
- {
+ case _K_SCI01_SOUND_DISPOSE_HANDLE : {
if (obj.segment) {
sfx_song_set_status(&s->sound,
- handle, SOUND_STATUS_STOPPED);
+ handle, SOUND_STATUS_STOPPED);
sfx_remove_song(&s->sound, handle);
}
break;
}
- case _K_SCI01_SOUND_UPDATE_HANDLE :
- {
+ case _K_SCI01_SOUND_UPDATE_HANDLE : {
/* FIXME: Get these from the sound server */
int signal = 0;
int min = 0;
@@ -479,7 +524,7 @@ kDoSound_SCI01(state_t *s, int funct_nr, int argc, reg_t *argv)
int pri = GET_SEL32V(obj, pri);
sfx_song_set_loops(&s->sound,
- handle, looping);
+ handle, looping);
sfx_song_renice(&s->sound, handle, pri);
SCIkdebug(SCIkSOUND, "[sound01-update-handle] -- CUE "PREG);
@@ -491,42 +536,38 @@ kDoSound_SCI01(state_t *s, int funct_nr, int argc, reg_t *argv)
break;
}
- case _K_SCI01_SOUND_STOP_HANDLE :
- {
+ case _K_SCI01_SOUND_STOP_HANDLE : {
PUT_SEL32V(obj, signal, -1);
if (obj.segment) {
sfx_song_set_status(&s->sound,
- handle, SOUND_STATUS_STOPPED);
+ handle, SOUND_STATUS_STOPPED);
}
break;
}
- case _K_SCI01_SOUND_SUSPEND_HANDLE :
- {
+ case _K_SCI01_SOUND_SUSPEND_HANDLE : {
int state = UKPV(2);
- int setstate = (state)?
- SOUND_STATUS_SUSPENDED : SOUND_STATUS_PLAYING;
+ int setstate = (state) ?
+ SOUND_STATUS_SUSPENDED : SOUND_STATUS_PLAYING;
if (obj.segment) {
sfx_song_set_status(&s->sound,
- handle, setstate);
+ handle, setstate);
}
break;
}
- case _K_SCI01_SOUND_FADE_HANDLE :
- {
+ case _K_SCI01_SOUND_FADE_HANDLE : {
/* There are four parameters that control the fade here.
* TODO: Figure out the exact semantics */
- /* FIXME: The next couple of lines actually STOP the song right away */
+ /* FIXME: The next couple of lines actually STOP the song right away */
PUT_SEL32V(obj, signal, -1);
if (obj.segment) {
sfx_song_set_status(&s->sound,
- handle, SOUND_STATUS_STOPPED);
+ handle, SOUND_STATUS_STOPPED);
}
break;
}
- case _K_SCI01_SOUND_UPDATE_CUES :
- {
+ case _K_SCI01_SOUND_UPDATE_CUES : {
int signal = 0;
int min = 0;
int sec = 0;
@@ -535,14 +576,14 @@ kDoSound_SCI01(state_t *s, int funct_nr, int argc, reg_t *argv)
int cue = 0;
while (result == SI_LOOP)
- result = sfx_poll_specific(&s->sound, handle, &cue);
+ result = sfx_poll_specific(&s->sound, handle, &cue);
switch (result) {
case SI_ABSOLUTE_CUE:
signal = cue;
SCIkdebug(SCIkSOUND, "--- [CUE] "PREG" Absolute Cue: %d\n",
- PRINT_REG(obj), signal);
+ PRINT_REG(obj), signal);
PUT_SEL32V(obj, signal, signal);
break;
@@ -550,7 +591,7 @@ kDoSound_SCI01(state_t *s, int funct_nr, int argc, reg_t *argv)
case SI_RELATIVE_CUE:
signal = cue;
SCIkdebug(SCIkSOUND, "--- [CUE] "PREG" Relative Cue: %d\n",
- PRINT_REG(obj), cue);
+ PRINT_REG(obj), cue);
/* FIXME to match commented-out semantics
* below, with proper storage of dataInc and
@@ -568,58 +609,55 @@ kDoSound_SCI01(state_t *s, int funct_nr, int argc, reg_t *argv)
break; /* Doesn't happen */
}
-/* switch (signal) */
-/* { */
-/* case 0x00: */
-/* if (dataInc!=GET_SEL32V(obj, dataInc)) */
-/* { */
-/* PUT_SEL32V(obj, dataInc, dataInc); */
-/* PUT_SEL32V(obj, signal, dataInc+0x7f); */
-/* } else */
-/* { */
-/* PUT_SEL32V(obj, signal, signal); */
-/* } */
-/* break; */
-/* case 0xFF: /\* May be unnecessary *\/ */
-/* sfx_song_set_status(&s->sound, */
-/* handle, SOUND_STATUS_STOPPED); */
-/* break; */
-/* default : */
-/* if (dataInc!=GET_SEL32V(obj, dataInc)) */
-/* { */
-/* PUT_SEL32V(obj, dataInc, dataInc); */
-/* PUT_SEL32V(obj, signal, dataInc+0x7f); */
-/* } else */
-/* { */
-/* PUT_SEL32V(obj, signal, signal); */
-/* } */
-/* break; */
-/* } */
+ /* switch (signal) */
+ /* { */
+ /* case 0x00: */
+ /* if (dataInc!=GET_SEL32V(obj, dataInc)) */
+ /* { */
+ /* PUT_SEL32V(obj, dataInc, dataInc); */
+ /* PUT_SEL32V(obj, signal, dataInc+0x7f); */
+ /* } else */
+ /* { */
+ /* PUT_SEL32V(obj, signal, signal); */
+ /* } */
+ /* break; */
+ /* case 0xFF: /\* May be unnecessary *\/ */
+ /* sfx_song_set_status(&s->sound, */
+ /* handle, SOUND_STATUS_STOPPED); */
+ /* break; */
+ /* default : */
+ /* if (dataInc!=GET_SEL32V(obj, dataInc)) */
+ /* { */
+ /* PUT_SEL32V(obj, dataInc, dataInc); */
+ /* PUT_SEL32V(obj, signal, dataInc+0x7f); */
+ /* } else */
+ /* { */
+ /* PUT_SEL32V(obj, signal, signal); */
+ /* } */
+ /* break; */
+ /* } */
PUT_SEL32V(obj, min, min);
PUT_SEL32V(obj, sec, sec);
PUT_SEL32V(obj, frame, frame);
break;
}
- case _K_SCI01_SOUND_MIDI_SEND :
- {
+ case _K_SCI01_SOUND_MIDI_SEND : {
int channel = SKPV(2);
- int midiCmd = UKPV(3) == 0xff ?
- 0xe0 : /* Pitch wheel */
- 0xb0; /* UKPV(3) is actually a controller number */
+ int midiCmd = UKPV(3) == 0xff ?
+ 0xe0 : /* Pitch wheel */
+ 0xb0; /* UKPV(3) is actually a controller number */
int controller = UKPV(3);
int param = UKPV(4);
- sfx_send_midi(&s->sound, handle,
- channel, midiCmd, controller, param);
+ sfx_send_midi(&s->sound, handle,
+ channel, midiCmd, controller, param);
break;
}
- case _K_SCI01_SOUND_REVERB :
- {
+ case _K_SCI01_SOUND_REVERB : {
break;
}
- case _K_SCI01_SOUND_HOLD :
- {
+ case _K_SCI01_SOUND_HOLD : {
//int flag = SKPV(2);
break;
}
@@ -630,48 +668,91 @@ kDoSound_SCI01(state_t *s, int funct_nr, int argc, reg_t *argv)
int
sfx_send_midi(sfx_state_t *self, song_handle_t handle, int channel,
- int command, int arg1, int arg2);
+ int command, int arg1, int arg2);
reg_t
-kDoSound_SCI1(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kDoSound_SCI1(state_t *s, int funct_nr, int argc, reg_t *argv) {
word command = UKPV(0);
reg_t obj = KP_ALT(1, NULL_REG);
song_handle_t handle = FROBNICATE_HANDLE(obj);
- int number = obj.segment ?
- GET_SEL32V(obj, number) :
- -1; /* We were not going to use it anyway */
+ int number = obj.segment ?
+ GET_SEL32V(obj, number) :
+ -1; /* We were not going to use it anyway */
CHECK_THIS_KERNEL_FUNCTION;
if ((s->debug_mode & (1 << SCIkSOUNDCHK_NR))
- && command != _K_SCI1_SOUND_UPDATE_CUES) {
+ && command != _K_SCI1_SOUND_UPDATE_CUES) {
int i;
SCIkdebug(SCIkSOUND, "Command 0x%x", command);
switch (command) {
- case 0: sciprintf("[MasterVolume]"); break;
- case 1: sciprintf("[Mute]"); break;
- case 2: sciprintf("[NOP(2)]"); break;
- case 3: sciprintf("[GetPolyphony]"); break;
- case 4: sciprintf("[GetAudioCapability]"); break;
- case 5: sciprintf("[GlobalSuspend]"); break;
- case 6: sciprintf("[Init]"); break;
- case 7: sciprintf("[Dispose]"); break;
- case 8: sciprintf("[Play]"); break;
- case 9: sciprintf("[Stop]"); break;
- case 10: sciprintf("[SuspendHandle]"); break;
- case 11: sciprintf("[Fade]"); break;
- case 12: sciprintf("[Hold]"); break;
- case 13: sciprintf("[Unused(13)]"); break;
- case 14: sciprintf("[SetVolume]"); break;
- case 15: sciprintf("[SetPriority]"); break;
- case 16: sciprintf("[SetLoop]"); break;
- case 17: sciprintf("[UpdateCues]"); break;
- case 18: sciprintf("[MidiSend]"); break;
- case 19: sciprintf("[Reverb]"); break;
- case 20: sciprintf("[UpdateVolPri]"); break;
- default: sciprintf("[unknown]"); break;
+ case 0:
+ sciprintf("[MasterVolume]");
+ break;
+ case 1:
+ sciprintf("[Mute]");
+ break;
+ case 2:
+ sciprintf("[NOP(2)]");
+ break;
+ case 3:
+ sciprintf("[GetPolyphony]");
+ break;
+ case 4:
+ sciprintf("[GetAudioCapability]");
+ break;
+ case 5:
+ sciprintf("[GlobalSuspend]");
+ break;
+ case 6:
+ sciprintf("[Init]");
+ break;
+ case 7:
+ sciprintf("[Dispose]");
+ break;
+ case 8:
+ sciprintf("[Play]");
+ break;
+ case 9:
+ sciprintf("[Stop]");
+ break;
+ case 10:
+ sciprintf("[SuspendHandle]");
+ break;
+ case 11:
+ sciprintf("[Fade]");
+ break;
+ case 12:
+ sciprintf("[Hold]");
+ break;
+ case 13:
+ sciprintf("[Unused(13)]");
+ break;
+ case 14:
+ sciprintf("[SetVolume]");
+ break;
+ case 15:
+ sciprintf("[SetPriority]");
+ break;
+ case 16:
+ sciprintf("[SetLoop]");
+ break;
+ case 17:
+ sciprintf("[UpdateCues]");
+ break;
+ case 18:
+ sciprintf("[MidiSend]");
+ break;
+ case 19:
+ sciprintf("[Reverb]");
+ break;
+ case 20:
+ sciprintf("[UpdateVolPri]");
+ break;
+ default:
+ sciprintf("[unknown]");
+ break;
}
sciprintf("(");
@@ -683,20 +764,17 @@ kDoSound_SCI1(state_t *s, int funct_nr, int argc, reg_t *argv)
sciprintf(")\n");
}
- switch (command)
- {
- case _K_SCI1_SOUND_MASTER_VOLME :
- {
- /*int vol = UPARAM_OR_ALT (1, -1);
+ switch (command) {
+ case _K_SCI1_SOUND_MASTER_VOLME : {
+ /*int vol = UPARAM_OR_ALT (1, -1);
- if (vol != -1)
- s->acc = s->sound_server->command(s, SOUND_COMMAND_SET_VOLUME, 0, vol);
- else
- s->acc = s->sound_server->command(s, SOUND_COMMAND_GET_VOLUME, 0, 0);
- break;*/
+ if (vol != -1)
+ s->acc = s->sound_server->command(s, SOUND_COMMAND_SET_VOLUME, 0, vol);
+ else
+ s->acc = s->sound_server->command(s, SOUND_COMMAND_GET_VOLUME, 0, 0);
+ break;*/
}
- case _K_SCI1_SOUND_MUTE_SOUND :
- {
+ case _K_SCI1_SOUND_MUTE_SOUND : {
/* if there's a parameter, we're setting it. Otherwise,
we're querying it. */
/*int param = UPARAM_OR_ALT(1,-1);
@@ -707,167 +785,147 @@ kDoSound_SCI1(state_t *s, int funct_nr, int argc, reg_t *argv)
s->acc = s->sound_server->command(s, SOUND_COMMAND_GET_MUTE, 0, 0);
break;*/
}
- case _K_SCI1_SOUND_UNUSED1 :
- {
+ case _K_SCI1_SOUND_UNUSED1 : {
break;
}
- case _K_SCI1_SOUND_GET_POLYPHONY :
- {
+ case _K_SCI1_SOUND_GET_POLYPHONY : {
/*s->acc = s->sound_server->command(s, SOUND_COMMAND_TEST, 0, 0);*/
break;
}
- case _K_SCI1_SOUND_GET_AUDIO_CAPABILITY :
- {
+ case _K_SCI1_SOUND_GET_AUDIO_CAPABILITY : {
return NULL_REG;
}
- case _K_SCI1_SOUND_PLAY_HANDLE :
- {
+ case _K_SCI1_SOUND_PLAY_HANDLE : {
int looping = GET_SEL32V(obj, loop);
//int vol = GET_SEL32V(obj, vol);
int pri = GET_SEL32V(obj, pri);
song_t *song = song_lib_find(s->sound.songlib, handle);
- if (GET_SEL32V(obj, nodePtr) && (song && number != song->resource_num))
- {
+ if (GET_SEL32V(obj, nodePtr) && (song && number != song->resource_num)) {
sfx_song_set_status(&s->sound,
- handle, SOUND_STATUS_STOPPED);
+ handle, SOUND_STATUS_STOPPED);
sfx_remove_song(&s->sound, handle);
PUT_SEL32(obj, nodePtr, NULL_REG);
}
- if (!GET_SEL32V(obj, nodePtr) && obj.segment)
- {
- if (!scir_test_resource(s->resmgr, sci_sound, number))
- {
+ if (!GET_SEL32V(obj, nodePtr) && obj.segment) {
+ if (!scir_test_resource(s->resmgr, sci_sound, number)) {
sciprintf("Could not open song number %d\n", number);
return NULL_REG;
}
sciprintf("Initializing song number %d\n", number);
SCRIPT_ASSERT_ZERO(sfx_add_song(&s->sound,
- build_iterator(s, number,
- SCI_SONG_ITERATOR_TYPE_SCI1,
- handle),
- 0, handle, number));
+ build_iterator(s, number,
+ SCI_SONG_ITERATOR_TYPE_SCI1,
+ handle),
+ 0, handle, number));
PUT_SEL32(obj, nodePtr, obj);
PUT_SEL32(obj, handle, obj);
}
if (obj.segment) {
sfx_song_set_status(&s->sound,
- handle, SOUND_STATUS_PLAYING);
+ handle, SOUND_STATUS_PLAYING);
sfx_song_set_loops(&s->sound,
- handle, looping);
+ handle, looping);
sfx_song_renice(&s->sound,
- handle, pri);
+ handle, pri);
}
break;
}
- case _K_SCI1_SOUND_INIT_HANDLE :
- {
+ case _K_SCI1_SOUND_INIT_HANDLE : {
//int looping = GET_SEL32V(obj, loop);
//int vol = GET_SEL32V(obj, vol);
//int pri = GET_SEL32V(obj, pri);
- if (GET_SEL32V(obj, nodePtr))
- {
+ if (GET_SEL32V(obj, nodePtr)) {
sfx_song_set_status(&s->sound,
- handle, SOUND_STATUS_STOPPED);
+ handle, SOUND_STATUS_STOPPED);
sfx_remove_song(&s->sound, handle);
}
if (obj.segment && (scir_test_resource(s->resmgr, sci_sound, number))) {
sciprintf("Initializing song number %d\n", number);
SCRIPT_ASSERT_ZERO(sfx_add_song(&s->sound,
- build_iterator(s, number,
- SCI_SONG_ITERATOR_TYPE_SCI1,
- handle),
- 0, handle, number));
+ build_iterator(s, number,
+ SCI_SONG_ITERATOR_TYPE_SCI1,
+ handle),
+ 0, handle, number));
PUT_SEL32(obj, nodePtr, obj);
PUT_SEL32(obj, handle, obj);
}
break;
}
- case _K_SCI1_SOUND_DISPOSE_HANDLE :
- {
+ case _K_SCI1_SOUND_DISPOSE_HANDLE : {
if (obj.segment) {
sfx_song_set_status(&s->sound,
- handle, SOUND_STATUS_STOPPED);
+ handle, SOUND_STATUS_STOPPED);
sfx_remove_song(&s->sound, handle);
}
break;
}
- case _K_SCI1_SOUND_STOP_HANDLE :
- {
+ case _K_SCI1_SOUND_STOP_HANDLE : {
PUT_SEL32V(obj, signal, -1);
if (obj.segment) {
sfx_song_set_status(&s->sound,
- handle, SOUND_STATUS_STOPPED);
+ handle, SOUND_STATUS_STOPPED);
}
break;
}
- case _K_SCI1_SOUND_SUSPEND_HANDLE :
- {
+ case _K_SCI1_SOUND_SUSPEND_HANDLE : {
break;
}
- case _K_SCI1_SOUND_FADE_HANDLE :
- {
+ case _K_SCI1_SOUND_FADE_HANDLE : {
fade_params_t fade;
if (obj.segment) {
fade.final_volume = UKPV(2);
fade.ticks_per_step = UKPV(3);
fade.step_size = UKPV(4);
fade.action = UKPV(5) ?
- FADE_ACTION_FADE_AND_STOP :
- FADE_ACTION_FADE_AND_CONT;
+ FADE_ACTION_FADE_AND_STOP :
+ FADE_ACTION_FADE_AND_CONT;
sfx_song_set_fade(&s->sound,
- handle,
- &fade);
+ handle,
+ &fade);
/* FIXME: The next couple of lines actually STOP the handle, rather
** than fading it! */
- if (UKPV(5))
- {
+ if (UKPV(5)) {
PUT_SEL32V(obj, signal, -1);
PUT_SEL32V(obj, nodePtr, 0);
PUT_SEL32V(obj, handle, 0);
sfx_song_set_status(&s->sound,
- handle, SOUND_STATUS_STOPPED);
+ handle, SOUND_STATUS_STOPPED);
}
}
break;
}
- case _K_SCI1_SOUND_HOLD_HANDLE :
- {
+ case _K_SCI1_SOUND_HOLD_HANDLE : {
int value = SKPV(2);
sfx_song_set_hold(&s->sound,
- handle, value);
+ handle, value);
break;
}
- case _K_SCI1_SOUND_UNUSED2 :
- {
+ case _K_SCI1_SOUND_UNUSED2 : {
break;
}
- case _K_SCI1_SOUND_SET_HANDLE_VOLUME :
- {
+ case _K_SCI1_SOUND_SET_HANDLE_VOLUME : {
break;
}
- case _K_SCI1_SOUND_SET_HANDLE_PRIORITY :
- {
+ case _K_SCI1_SOUND_SET_HANDLE_PRIORITY : {
int value = SKPV(2);
script_set_priority(s, obj, value);
break;
}
- case _K_SCI1_SOUND_SET_HANDLE_LOOP :
- {
+ case _K_SCI1_SOUND_SET_HANDLE_LOOP : {
break;
}
- case _K_SCI1_SOUND_UPDATE_CUES :
- {
+ case _K_SCI1_SOUND_UPDATE_CUES : {
int signal = 0;
//int min = 0;
//int sec = 0;
@@ -876,21 +934,21 @@ kDoSound_SCI1(state_t *s, int funct_nr, int argc, reg_t *argv)
int cue = 0;
while (result == SI_LOOP)
- result = sfx_poll_specific(&s->sound, handle, &cue);
+ result = sfx_poll_specific(&s->sound, handle, &cue);
switch (result) {
case SI_ABSOLUTE_CUE:
signal = cue;
fprintf(stderr, "[CUE] "PREG" Absolute Cue: %d\n",
- PRINT_REG(obj), signal);
+ PRINT_REG(obj), signal);
PUT_SEL32V(obj, signal, signal);
break;
case SI_RELATIVE_CUE:
fprintf(stderr, "[CUE] "PREG" Relative Cue: %d\n",
- PRINT_REG(obj), cue);
+ PRINT_REG(obj), cue);
PUT_SEL32V(obj, dataInc, cue);
PUT_SEL32V(obj, signal, cue + 127);
@@ -905,18 +963,15 @@ kDoSound_SCI1(state_t *s, int funct_nr, int argc, reg_t *argv)
}
break;
}
- case _K_SCI1_SOUND_MIDI_SEND :
- {
- sfx_send_midi(&s->sound, handle,
- UKPV(2), UKPV(3), UKPV(4), UKPV(5));
+ case _K_SCI1_SOUND_MIDI_SEND : {
+ sfx_send_midi(&s->sound, handle,
+ UKPV(2), UKPV(3), UKPV(4), UKPV(5));
break;
}
- case _K_SCI1_SOUND_REVERB :
- {
+ case _K_SCI1_SOUND_REVERB : {
break;
}
- case _K_SCI1_SOUND_UPDATE_VOL_PRI :
- {
+ case _K_SCI1_SOUND_UPDATE_VOL_PRI : {
break;
}
}
@@ -924,21 +979,18 @@ kDoSound_SCI1(state_t *s, int funct_nr, int argc, reg_t *argv)
}
reg_t
-kDoSound(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
- if (s->version>=SCI_VERSION_FTU_DOSOUND_VARIANT_2)
+kDoSound(state_t *s, int funct_nr, int argc, reg_t *argv) {
+ if (s->version >= SCI_VERSION_FTU_DOSOUND_VARIANT_2)
return kDoSound_SCI1(s, funct_nr, argc, argv);
- else if (s->version>=SCI_VERSION_FTU_DOSOUND_VARIANT_1)
+ else if (s->version >= SCI_VERSION_FTU_DOSOUND_VARIANT_1)
return kDoSound_SCI01(s, funct_nr, argc, argv);
else
return kDoSound_SCI0(s, funct_nr, argc, argv);
}
reg_t
-kDoAudio(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
- switch (UKPV(0))
- {
+kDoAudio(state_t *s, int funct_nr, int argc, reg_t *argv) {
+ switch (UKPV(0)) {
case _K_SCI1_AUDIO_POSITION :
return make_reg(0, -1); /* Finish immediately */
}
diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp
index 6143a2af88..f2b0f4ce75 100644
--- a/engines/sci/engine/kstring.cpp
+++ b/engines/sci/engine/kstring.cpp
@@ -38,7 +38,7 @@
char *
kernel_lookup_text(state_t *s, reg_t address, int index)
- /* Returns the string the script intended to address */
+/* Returns the string the script intended to address */
{
char *seeker;
resource_t *textres;
@@ -78,45 +78,43 @@ kernel_lookup_text(state_t *s, reg_t address, int index)
#ifdef SCI_SIMPLE_SAID_CODE
int
-vocab_match_simple(state_t *s, heap_ptr addr)
-{
- int nextitem;
- int listpos = 0;
-
- if (!s->parser_valid)
- return SAID_NO_MATCH;
-
- if (s->parser_valid == 2) { /* debug mode: sim_said */
- do {
- sciprintf("DEBUGMATCH: ");
- nextitem = s->heap[addr++];
-
- if (nextitem < 0xf0) {
- nextitem = nextitem << 8 | s->heap[addr++];
- if (s->parser_nodes[listpos].type
- || nextitem != s->parser_nodes[listpos++].content.value)
- return SAID_NO_MATCH;
- } else {
-
- if (nextitem == 0xff)
- return (s->parser_nodes[listpos++].type == -1)? SAID_FULL_MATCH : SAID_NO_MATCH; /* Finished? */
-
- if (s->parser_nodes[listpos].type != 1
- || nextitem != s->parser_nodes[listpos++].content.value)
- return SAID_NO_MATCH;
-
- }
- } while (42);
- } else { /* normal simple match mode */
- return vocab_simple_said_test(s, addr);
- }
+vocab_match_simple(state_t *s, heap_ptr addr) {
+ int nextitem;
+ int listpos = 0;
+
+ if (!s->parser_valid)
+ return SAID_NO_MATCH;
+
+ if (s->parser_valid == 2) { /* debug mode: sim_said */
+ do {
+ sciprintf("DEBUGMATCH: ");
+ nextitem = s->heap[addr++];
+
+ if (nextitem < 0xf0) {
+ nextitem = nextitem << 8 | s->heap[addr++];
+ if (s->parser_nodes[listpos].type
+ || nextitem != s->parser_nodes[listpos++].content.value)
+ return SAID_NO_MATCH;
+ } else {
+
+ if (nextitem == 0xff)
+ return (s->parser_nodes[listpos++].type == -1) ? SAID_FULL_MATCH : SAID_NO_MATCH; /* Finished? */
+
+ if (s->parser_nodes[listpos].type != 1
+ || nextitem != s->parser_nodes[listpos++].content.value)
+ return SAID_NO_MATCH;
+
+ }
+ } while (42);
+ } else { /* normal simple match mode */
+ return vocab_simple_said_test(s, addr);
+ }
}
#endif /* SCI_SIMPLE_SAID_CODE */
reg_t
-kSaid(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kSaid(state_t *s, int funct_nr, int argc, reg_t *argv) {
reg_t heap_said_block = argv[0];
byte *said_block;
int new_lastmatch;
@@ -142,27 +140,27 @@ kSaid(state_t *s, int funct_nr, int argc, reg_t *argv)
#ifdef SCI_SIMPLE_SAID_CODE
- s->acc = 0;
+ s->acc = 0;
- if (s->parser_lastmatch_word == SAID_FULL_MATCH)
- return; /* Matched before; we're not doing any more matching work today. */
+ if (s->parser_lastmatch_word == SAID_FULL_MATCH)
+ return; /* Matched before; we're not doing any more matching work today. */
- if ((new_lastmatch = vocab_match_simple(s, said_block)) != SAID_NO_MATCH) {
+ if ((new_lastmatch = vocab_match_simple(s, said_block)) != SAID_NO_MATCH) {
- if (s->debug_mode & (1 << SCIkPARSER_NR))
- sciprintf("Match (simple).\n");
- s->acc = 1;
+ if (s->debug_mode & (1 << SCIkPARSER_NR))
+ sciprintf("Match (simple).\n");
+ s->acc = 1;
- if (new_lastmatch == SAID_FULL_MATCH) /* Finished matching? */
- PUT_SELECTOR(s->parser_event, claimed, 1); /* claim event */
- /* otherwise, we have a partial match: Set new lastmatch word in all cases. */
+ if (new_lastmatch == SAID_FULL_MATCH) /* Finished matching? */
+ PUT_SELECTOR(s->parser_event, claimed, 1); /* claim event */
+ /* otherwise, we have a partial match: Set new lastmatch word in all cases. */
- s->parser_lastmatch_word = new_lastmatch;
- }
+ s->parser_lastmatch_word = new_lastmatch;
+ }
#else /* !SCI_SIMPLE_SAID_CODE */
if ((new_lastmatch = said(s, said_block, (s->debug_mode & (1 << SCIkPARSER_NR))))
- != SAID_NO_MATCH) { /* Build and possibly display a parse tree */
+ != SAID_NO_MATCH) { /* Build and possibly display a parse tree */
if (s->debug_mode & (1 << SCIkPARSER_NR))
sciprintf("Match.\n");
@@ -184,8 +182,7 @@ kSaid(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kSetSynonyms(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kSetSynonyms(state_t *s, int funct_nr, int argc, reg_t *argv) {
reg_t object = argv[0];
list_t *list;
node_t *node;
@@ -197,7 +194,7 @@ kSetSynonyms(state_t *s, int funct_nr, int argc, reg_t *argv)
s->synonyms_nr = 0;
- list = LOOKUP_LIST(GET_SEL32(object, elements));
+ list = LOOKUP_LIST(GET_SEL32(object, elements));
node = LOOKUP_NODE(list->first);
while (node) {
@@ -218,18 +215,18 @@ kSetSynonyms(state_t *s, int funct_nr, int argc, reg_t *argv)
int i;
if (s->synonyms_nr)
s->synonyms = (synonym_t*)sci_realloc(s->synonyms,
- sizeof(synonym_t) * (s->synonyms_nr + synonyms_nr));
+ sizeof(synonym_t) * (s->synonyms_nr + synonyms_nr));
else
s->synonyms = (synonym_t*)sci_malloc(sizeof(synonym_t) * synonyms_nr);
s->synonyms_nr += synonyms_nr;
SCIkdebug(SCIkPARSER, "Setting %d synonyms for script.%d\n",
- synonyms_nr, script);
+ synonyms_nr, script);
if (synonyms_nr > 16384) {
SCIkwarn(SCIkERROR, "Segtable corruption: script.%03d has %d synonyms!\n",
- script, synonyms_nr);
+ script, synonyms_nr);
/* We used to reset the corrupted value here. I really don't think it's appropriate.
* Lars */
} else
@@ -241,7 +238,7 @@ kSetSynonyms(state_t *s, int funct_nr, int argc, reg_t *argv)
}
} else SCIkwarn(SCIkWARNING, "Synonyms of script.%03d were requested, but script is not available\n");
- }
+ }
node = LOOKUP_NODE(node->succ);
}
@@ -256,8 +253,7 @@ kSetSynonyms(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kParse(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kParse(state_t *s, int funct_nr, int argc, reg_t *argv) {
reg_t stringpos = argv[0];
char *string = kernel_dereference_char_pointer(s, stringpos, 0);
int words_nr;
@@ -275,9 +271,9 @@ kParse(state_t *s, int funct_nr, int argc, reg_t *argv)
}
words = vocab_tokenize_string(string, &words_nr,
- s->parser_words, s->parser_words_nr,
- s->parser_suffices, s->parser_suffices_nr,
- &error);
+ s->parser_words, s->parser_words_nr,
+ s->parser_suffices, s->parser_suffices_nr,
+ &error);
s->parser_valid = 0; /* not valid */
if (words) {
@@ -298,7 +294,7 @@ kParse(state_t *s, int funct_nr, int argc, reg_t *argv)
}
if (vocab_build_parse_tree(&(s->parser_nodes[0]), words, words_nr, s->parser_branches,
- s->parser_rules))
+ s->parser_rules))
syntax_fail = 1; /* Building a tree failed */
#ifdef SCI_SIMPLE_SAID_CODE
@@ -333,7 +329,7 @@ kParse(state_t *s, int funct_nr, int argc, reg_t *argv)
if (error) {
char *pbase_str = kernel_dereference_char_pointer(s, s->parser_base, 0);
strcpy(pbase_str, error);
- SCIkdebug(SCIkPARSER,"Word unknown: %s\n", error);
+ SCIkdebug(SCIkPARSER, "Word unknown: %s\n", error);
/* Issue warning: */
invoke_selector(INV_SEL(s->game_obj, wordFail, 0), 2, s->parser_base, stringpos);
@@ -347,8 +343,7 @@ kParse(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kStrEnd(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kStrEnd(state_t *s, int funct_nr, int argc, reg_t *argv) {
reg_t address = argv[0];
char *seeker = kernel_dereference_char_pointer(s, address, 0);
@@ -359,8 +354,7 @@ kStrEnd(state_t *s, int funct_nr, int argc, reg_t *argv)
}
reg_t
-kStrCat(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kStrCat(state_t *s, int funct_nr, int argc, reg_t *argv) {
char *s1 = kernel_dereference_char_pointer(s, argv[0], 0);
char *s2 = kernel_dereference_char_pointer(s, argv[1], 0);
@@ -369,8 +363,7 @@ kStrCat(state_t *s, int funct_nr, int argc, reg_t *argv)
}
reg_t
-kStrCmp(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kStrCmp(state_t *s, int funct_nr, int argc, reg_t *argv) {
char *s1 = kernel_dereference_char_pointer(s, argv[0], 0);
char *s2 = kernel_dereference_char_pointer(s, argv[1], 0);
@@ -382,32 +375,30 @@ kStrCmp(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kStrCpy(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kStrCpy(state_t *s, int funct_nr, int argc, reg_t *argv) {
char *dest = (char *) kernel_dereference_bulk_pointer(s, argv[0], 0);
char *src = (char *) kernel_dereference_bulk_pointer(s, argv[1], 0);
if (!dest) {
SCIkdebug(SCIkWARNING, "Attempt to strcpy TO invalid pointer "PREG"!\n",
- PRINT_REG(argv[0]));
+ PRINT_REG(argv[0]));
return NULL_REG;
}
if (!src) {
SCIkdebug(SCIkWARNING, "Attempt to strcpy FROM invalid pointer "PREG"!\n",
- PRINT_REG(argv[1]));
+ PRINT_REG(argv[1]));
return NULL_REG;
}
- if (argc > 2)
- {
+ if (argc > 2) {
int length = SKPV(2);
- if (length>=0)
+ if (length >= 0)
strncpy(dest, src, length);
else {
if (s->seg_manager.heap[argv[0].segment]->type == MEM_OBJ_DYNMEM) {
reg_t *srcp = (reg_t *) src;
-
+
int i;
SCIkdebug(SCIkWARNING, "Performing reg_t to raw conversion for AvoidPath\n");
for (i = 0; i < -length / 2; i++) {
@@ -418,8 +409,7 @@ kStrCpy(state_t *s, int funct_nr, int argc, reg_t *argv)
} else
memcpy(dest, src, -length);
}
- }
- else
+ } else
strcpy(dest, src);
return argv[0];
@@ -427,31 +417,30 @@ kStrCpy(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kStrAt(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kStrAt(state_t *s, int funct_nr, int argc, reg_t *argv) {
unsigned char *dest = (unsigned char *) kernel_dereference_bulk_pointer(s, argv[0], 0);
reg_t *dest2;
if (!dest) {
SCIkdebug(SCIkWARNING, "Attempt to StrAt at invalid pointer "PREG"!\n",
- PRINT_REG(argv[0]));
+ PRINT_REG(argv[0]));
return NULL_REG;
}
if ((argc == 2) &&
-/* Our pathfinder already works around the issue we're trying to fix */
- (strcmp(sm_get_description(&(s->seg_manager), argv[0]),
- AVOIDPATH_DYNMEM_STRING) != 0) &&
- ((strlen((const char*)dest) < 2) || (!is_print_str((char*)dest))))
- /* SQ4 array handling detected */
+ /* Our pathfinder already works around the issue we're trying to fix */
+ (strcmp(sm_get_description(&(s->seg_manager), argv[0]),
+ AVOIDPATH_DYNMEM_STRING) != 0) &&
+ ((strlen((const char*)dest) < 2) || (!is_print_str((char*)dest))))
+ /* SQ4 array handling detected */
{
#ifndef WORDS_BIGENDIAN
int odd = KP_UINT(argv[1]) & 1;
#else
int odd = !(KP_UINT(argv[1]) & 1);
#endif
- dest2 = ((reg_t *) dest)+(KP_UINT(argv[1])/2);
- dest = ((unsigned char *) (&dest2->offset))+odd;
+ dest2 = ((reg_t *) dest) + (KP_UINT(argv[1]) / 2);
+ dest = ((unsigned char *)(&dest2->offset)) + odd;
} else dest += KP_UINT(argv[1]);
s->r_acc = make_reg(0, *dest);
@@ -464,8 +453,7 @@ kStrAt(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kReadNumber(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kReadNumber(state_t *s, int funct_nr, int argc, reg_t *argv) {
char *source = kernel_dereference_char_pointer(s, argv[0], 0);
while (isspace(*source))
@@ -490,8 +478,7 @@ kReadNumber(state_t *s, int funct_nr, int argc, reg_t *argv)
** the supplied parameters and writes it to the targ_address.
*/
reg_t
-kFormat(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kFormat(state_t *s, int funct_nr, int argc, reg_t *argv) {
int *arguments;
reg_t dest = argv[0];
char *target = (char *) kernel_dereference_bulk_pointer(s, dest, 0);
@@ -549,15 +536,16 @@ kFormat(state_t *s, int funct_nr, int argc, reg_t *argv)
char *destp;
if (xfer == '0')
- fillchar = '0'; else
+ fillchar = '0';
+ else
- if (xfer == '=') {
- align = ALIGN_CENTRE;
- source++;
- } else
+ if (xfer == '=') {
+ align = ALIGN_CENTRE;
+ source++;
+ } else
- if (isdigit(xfer))
- source--; /* Stepped over length argument */
+ if (isdigit(xfer))
+ source--; /* Stepped over length argument */
str_leng = strtol(source, &destp, 10);
@@ -580,7 +568,7 @@ kFormat(state_t *s, int funct_nr, int argc, reg_t *argv)
case 's': { /* Copy string */
reg_t reg = argv[startarg + paramindex];
char *tempsource = kernel_lookup_text(s, reg,
- arguments[paramindex + 1]);
+ arguments[paramindex + 1]);
int slen = strlen(tempsource);
int extralen = str_leng - slen;
CHECK_OVERFLOW1(target, extralen, NULL_REG);
@@ -604,9 +592,11 @@ kFormat(state_t *s, int funct_nr, int argc, reg_t *argv)
int half_extralen = extralen >> 1;
while (half_extralen-- > 0)
*target++ = ' '; /* Format into the text */
- break;}
+ break;
+ }
- default: break;
+ default:
+ break;
}
@@ -621,15 +611,17 @@ kFormat(state_t *s, int funct_nr, int argc, reg_t *argv)
half_extralen = extralen - (extralen >> 1);
while (half_extralen-- > 0)
*target++ = ' '; /* Format into the text */
- break;}
+ break;
+ }
- default: break;
+ default:
+ break;
}
mode = 0;
}
- break;
+ break;
case 'c': { /* insert character */
CHECK_OVERFLOW1(target, 2, NULL_REG);
@@ -640,10 +632,11 @@ kFormat(state_t *s, int funct_nr, int argc, reg_t *argv)
*target++ = arguments[paramindex++];
mode = 0;
}
- break;
+ break;
case 'x':
- case 'u': unsigned_var = 1;
+ case 'u':
+ unsigned_var = 1;
case 'd': { /* Copy decimal */
/* int templen; -- unused atm */
const char *format_string = "%d";
@@ -663,7 +656,7 @@ kFormat(state_t *s, int funct_nr, int argc, reg_t *argv)
mode = 0;
}
- break;
+ break;
default:
*target = '%';
target++;
@@ -679,7 +672,7 @@ kFormat(state_t *s, int funct_nr, int argc, reg_t *argv)
if (padding > 0) {
if (align > 0) {
memmove(writestart + padding,
- writestart, written);
+ writestart, written);
memset(writestart, fillchar, padding);
} else {
memset(target, ' ', padding);
@@ -687,7 +680,7 @@ kFormat(state_t *s, int funct_nr, int argc, reg_t *argv)
target += padding;
}
}
- }else { /* mode != 1 */
+ } else { /* mode != 1 */
*target = xfer;
target++;
}
@@ -701,8 +694,7 @@ kFormat(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kStrLen(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kStrLen(state_t *s, int funct_nr, int argc, reg_t *argv) {
char *str = kernel_dereference_char_pointer(s, argv[0], 0);
return make_reg(0, strlen(str));
@@ -710,8 +702,7 @@ kStrLen(state_t *s, int funct_nr, int argc, reg_t *argv)
reg_t
-kGetFarText(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kGetFarText(state_t *s, int funct_nr, int argc, reg_t *argv) {
resource_t *textres = scir_find_resource(s->resmgr, sci_text, UKPV(0), 0);
char *seeker;
int counter = UKPV(1);
@@ -739,15 +730,12 @@ kGetFarText(state_t *s, int funct_nr, int argc, reg_t *argv)
static message_state_t state;
reg_t
-kMessage(state_t *s, int funct_nr, int argc, reg_t *argv)
-{
+kMessage(state_t *s, int funct_nr, int argc, reg_t *argv) {
if (!state.initialized)
message_state_initialize(s->resmgr, &state);
- switch (UKPV(0))
- {
- case 0 :
- {
+ switch (UKPV(0)) {
+ case 0 : {
char *buffer = argc == 7 ? kernel_dereference_char_pointer(s, argv[6], 0) : NULL;
message_tuple_t tuple;
int module = UKPV(1);
@@ -757,34 +745,28 @@ kMessage(state_t *s, int funct_nr, int argc, reg_t *argv)
tuple.cond = UKPV(4);
tuple.seq = UKPV(5);
- if (message_state_load_res(&state, module) && message_get_specific(&state, &tuple))
- {
- if (buffer)
+ if (message_state_load_res(&state, module) && message_get_specific(&state, &tuple)) {
+ if (buffer)
message_get_text(&state, buffer, 100);
return make_reg(0, message_get_talker(&state)); /* Talker id */
- } else
- {
+ } else {
if (buffer) strcpy(buffer, DUMMY_MESSAGE);
return NULL_REG;
}
}
- case 1 :
- {
+ case 1 : {
char *buffer = argc == 7 ? kernel_dereference_char_pointer(s, argv[6], 0) : NULL;
- if (message_get_next(&state))
- {
- if (buffer)
+ if (message_get_next(&state)) {
+ if (buffer)
message_get_text(&state, buffer, 100);
return make_reg(0, message_get_talker(&state)); /* Talker id */
- } else
- {
+ } else {
if (buffer) strcpy(buffer, DUMMY_MESSAGE);
return NULL_REG;
}
}
- case 2 :
- {
+ case 2 : {
message_tuple_t tuple;
int module = UKPV(1);
tuple.noun = UKPV(2);
@@ -793,7 +775,7 @@ kMessage(state_t *s, int funct_nr, int argc, reg_t *argv)
tuple.seq = UKPV(5);
if (message_state_load_res(&state, module) && message_get_specific(&state, &tuple))
- return make_reg(0, message_get_length(&state)+1);
+ return make_reg(0, message_get_length(&state) + 1);
else return NULL_REG;
}
}
diff --git a/engines/sci/engine/message.cpp b/engines/sci/engine/message.cpp
index a92bafd80c..244734c12c 100644
--- a/engines/sci/engine/message.cpp
+++ b/engines/sci/engine/message.cpp
@@ -30,8 +30,7 @@
#if 0
// Unreferenced - removed
static
-int get_talker_trivial(index_record_cursor_t *cursor)
-{
+int get_talker_trivial(index_record_cursor_t *cursor) {
return -1;
}
#endif
@@ -41,8 +40,7 @@ int get_talker_trivial(index_record_cursor_t *cursor)
#if 0
// Unreferenced - removed
static
-void index_record_parse_2101(index_record_cursor_t *cursor, message_tuple_t *t)
-{
+void index_record_parse_2101(index_record_cursor_t *cursor, message_tuple_t *t) {
int noun = *(cursor->index_record + 0);
int verb = *(cursor->index_record + 1);
@@ -55,11 +53,10 @@ void index_record_parse_2101(index_record_cursor_t *cursor, message_tuple_t *t)
#if 0
// Unreferenced - removed
static
-void index_record_get_text_2101(index_record_cursor_t *cursor, char *buffer, int buffer_size)
-{
+void index_record_get_text_2101(index_record_cursor_t *cursor, char *buffer, int buffer_size) {
int offset = getUInt16(cursor->index_record + 2);
char *stringptr = (char *)cursor->resource_beginning + offset;
-
+
strncpy(buffer, stringptr, buffer_size);
}
#endif
@@ -67,8 +64,7 @@ void index_record_get_text_2101(index_record_cursor_t *cursor, char *buffer, int
#if 0
// Unreferenced - removed
static
-int header_get_index_record_count_2101(byte *header)
-{
+int header_get_index_record_count_2101(byte *header) {
return getUInt16(header + 4);
}
#endif
@@ -76,8 +72,7 @@ int header_get_index_record_count_2101(byte *header)
/* Version 3.411 and later code ahead */
static
-void index_record_parse_3411(index_record_cursor_t *cursor, message_tuple_t *t)
-{
+void index_record_parse_3411(index_record_cursor_t *cursor, message_tuple_t *t) {
int noun = *(cursor->index_record + 0);
int verb = *(cursor->index_record + 1);
int cond = *(cursor->index_record + 2);
@@ -90,49 +85,43 @@ void index_record_parse_3411(index_record_cursor_t *cursor, message_tuple_t *t)
}
static
-int index_record_get_talker_3411(index_record_cursor_t *cursor)
-{
+int index_record_get_talker_3411(index_record_cursor_t *cursor) {
return *(cursor->index_record + 4);
}
static
-void index_record_get_text_3411(index_record_cursor_t *cursor, char *buffer, int buffer_size)
-{
+void index_record_get_text_3411(index_record_cursor_t *cursor, char *buffer, int buffer_size) {
int offset = getUInt16(cursor->index_record + 5);
char *stringptr = (char *)cursor->resource_beginning + offset;
-
+
strncpy(buffer, stringptr, buffer_size);
}
static
-int header_get_index_record_count_3411(byte *header)
-{
+int header_get_index_record_count_3411(byte *header) {
return getUInt16(header + 8);
}
/* Generic code from here on */
static
-int four_tuple_match(message_tuple_t *t1, message_tuple_t *t2)
-{
- return
- t1->noun == t2->noun &&
- t1->verb == t2->verb &&
- t1->cond == t2->cond &&
- t1->seq == t2->seq;
+int four_tuple_match(message_tuple_t *t1, message_tuple_t *t2) {
+ return
+ t1->noun == t2->noun &&
+ t1->verb == t2->verb &&
+ t1->cond == t2->cond &&
+ t1->seq == t2->seq;
}
static
-void index_record_cursor_initialize(message_state_t *state, index_record_cursor_t *cursor)
-{
+void index_record_cursor_initialize(message_state_t *state, index_record_cursor_t *cursor) {
cursor->resource_beginning = state->current_res->data;
cursor->index_record = state->index_records;
cursor->index = 1;
}
static
-int index_record_next(message_state_t *state, index_record_cursor_t *cursor)
-{
+int index_record_next(message_state_t *state, index_record_cursor_t *cursor) {
if (cursor->index == state->record_count)
return 0;
cursor->index_record += state->handler->index_record_size;
@@ -141,15 +130,13 @@ int index_record_next(message_state_t *state, index_record_cursor_t *cursor)
}
static
-int index_record_find(message_state_t *state, message_tuple_t *t, index_record_cursor_t *cursor)
-{
+int index_record_find(message_state_t *state, message_tuple_t *t, index_record_cursor_t *cursor) {
message_tuple_t looking_at;
int found = 0;
index_record_cursor_initialize(state, cursor);
- do
- {
+ do {
state->handler->parse(cursor, &looking_at);
if (four_tuple_match(t, &looking_at))
found = 1;
@@ -160,46 +147,39 @@ int index_record_find(message_state_t *state, message_tuple_t *t, index_record_c
return found;
}
-int message_get_specific(message_state_t *state, message_tuple_t *t)
-{
+int message_get_specific(message_state_t *state, message_tuple_t *t) {
return index_record_find(state, t, &state->engine_cursor);
}
-int message_get_next(message_state_t *state)
-{
+int message_get_next(message_state_t *state) {
return index_record_next(state, &state->engine_cursor);
}
-int message_get_talker(message_state_t *state)
-{
+int message_get_talker(message_state_t *state) {
return state->handler->get_talker(&state->engine_cursor);
}
-int message_get_text(message_state_t *state, char *buffer, int length)
-{
+int message_get_text(message_state_t *state, char *buffer, int length) {
state->handler->get_text(&state->engine_cursor, buffer, length);
return strlen(buffer);
}
-int message_get_length(message_state_t *state)
-{
+int message_get_length(message_state_t *state) {
char buffer[500];
state->handler->get_text(&state->engine_cursor, buffer, sizeof(buffer));
return strlen(buffer);
}
-int message_state_load_res(message_state_t *state, int module)
-{
- if (state->module == module)
+int message_state_load_res(message_state_t *state, int module) {
+ if (state->module == module)
return 1;
state->module = module;
state->current_res = scir_find_resource(state->resmgr, sci_message, module, 0);
if (state->current_res == NULL ||
- state->current_res->data == NULL)
- {
+ state->current_res->data == NULL) {
sciprintf("Message subsystem: Failed to load %d.MSG\n", module);
return 0;
}
@@ -211,17 +191,17 @@ int message_state_load_res(message_state_t *state, int module)
return 1;
}
-static message_handler_t fixed_handler = {3411,
- index_record_parse_3411,
- index_record_get_talker_3411,
- index_record_get_text_3411,
- header_get_index_record_count_3411,
+static message_handler_t fixed_handler = {3411,
+ index_record_parse_3411,
+ index_record_get_talker_3411,
+ index_record_get_text_3411,
+ header_get_index_record_count_3411,
- 10,
- 11};
+ 10,
+ 11
+ };
-void message_state_initialize(resource_mgr_t *resmgr, message_state_t *state)
-{
+void message_state_initialize(resource_mgr_t *resmgr, message_state_t *state) {
// resource_t *tester = scir_find_resource(resmgr, sci_message, 0, 0);
//int version;
diff --git a/engines/sci/engine/message.h b/engines/sci/engine/message.h
index 6613ff6d0b..07f4b05121 100644
--- a/engines/sci/engine/message.h
+++ b/engines/sci/engine/message.h
@@ -27,16 +27,14 @@
#include "sci/include/sciresource.h"
-typedef struct
-{
+typedef struct {
int noun;
int verb;
int cond;
int seq;
} message_tuple_t;
-typedef struct
-{
+typedef struct {
byte *index_record;
int index;
byte *resource_beginning;
@@ -48,20 +46,18 @@ typedef int get_talker_t(index_record_cursor_t *cursor);
typedef void get_text_t(index_record_cursor_t *cursor, char *buffer, int buffer_size);
typedef int index_record_count_t(byte *header);
-typedef struct
-{
+typedef struct {
int version_id;
parse_index_record_t *parse;
get_talker_t *get_talker;
get_text_t *get_text;
index_record_count_t *index_record_count;
-
+
int header_size;
int index_record_size;
} message_handler_t;
-typedef struct
-{
+typedef struct {
int initialized;
message_handler_t *handler;
resource_mgr_t *resmgr;
diff --git a/engines/sci/engine/said.cpp b/engines/sci/engine/said.cpp
index 225b35365c..8194bad322 100644
--- a/engines/sci/engine/said.cpp
+++ b/engines/sci/engine/said.cpp
@@ -63,25 +63,25 @@
/* Tokens. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
- /* Put the tokens into the symbol table, so that GDB and other debuggers
- know about them. */
- enum yytokentype {
- WGROUP = 258,
- YY_COMMA = 259,
- YY_AMP = 260,
- YY_SLASH = 261,
- YY_PARENO = 262,
- YY_PARENC = 263,
- YY_BRACKETSO = 264,
- YY_BRACKETSC = 265,
- YY_HASH = 266,
- YY_LT = 267,
- YY_GT = 268,
- YY_BRACKETSO_LT = 269,
- YY_BRACKETSO_SLASH = 270,
- YY_LT_BRACKETSO = 271,
- YY_LT_PARENO = 272
- };
+/* Put the tokens into the symbol table, so that GDB and other debuggers
+ know about them. */
+enum yytokentype {
+ WGROUP = 258,
+ YY_COMMA = 259,
+ YY_AMP = 260,
+ YY_SLASH = 261,
+ YY_PARENO = 262,
+ YY_PARENC = 263,
+ YY_BRACKETSO = 264,
+ YY_BRACKETSC = 265,
+ YY_HASH = 266,
+ YY_LT = 267,
+ YY_GT = 268,
+ YY_BRACKETSO_LT = 269,
+ YY_BRACKETSO_SLASH = 270,
+ YY_LT_BRACKETSO = 271,
+ YY_LT_PARENO = 272
+};
#endif
/* Tokens. */
#define WGROUP 258
@@ -189,8 +189,7 @@ static int
yylex(void);
static int
-yyerror(char *s)
-{
+yyerror(char *s) {
said_parse_error = sci_strdup(s);
return 1; /* Abort */
}
@@ -303,14 +302,14 @@ typedef short int yytype_int16;
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static int
-YYID (int i)
+YYID(int i)
#else
static int
-YYID (i)
- int i;
+YYID(i)
+int i;
#endif
{
- return i;
+ return i;
}
#endif
@@ -343,13 +342,13 @@ YYID (i)
# endif
# ifdef YYSTACK_ALLOC
- /* Pacify GCC's `empty if-body' warning. */
+/* Pacify GCC's `empty if-body' warning. */
# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
# ifndef YYSTACK_ALLOC_MAXIMUM
- /* The OS might guarantee only one guard page at the bottom of the stack,
- and a page size can be as small as 4096 bytes. So we cannot safely
- invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
- to allow for a few compiler-allocated temporary stack slots. */
+/* The OS might guarantee only one guard page at the bottom of the stack,
+ and a page size can be as small as 4096 bytes. So we cannot safely
+ invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
+ to allow for a few compiler-allocated temporary stack slots. */
# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
# endif
# else
@@ -370,14 +369,14 @@ YYID (i)
# define YYMALLOC malloc
# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
-void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
+void *malloc(YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
# endif
# endif
# ifndef YYFREE
# define YYFREE free
# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
-void free (void *); /* INFRINGES ON USER NAME SPACE */
+void free(void *); /* INFRINGES ON USER NAME SPACE */
# endif
# endif
# endif
@@ -389,11 +388,10 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */
|| (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
/* A type that is properly aligned for any stack member. */
-union yyalloc
-{
- yytype_int16 yyss;
- YYSTYPE yyvs;
- };
+union yyalloc {
+ yytype_int16 yyss;
+ YYSTYPE yyvs;
+};
/* The size of the maximum gap between one aligned stack and the next. */
# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
@@ -462,158 +460,146 @@ union yyalloc
((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
-static const yytype_uint8 yytranslate[] =
-{
- 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
- 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 15, 16, 17
+static const yytype_uint8 yytranslate[] = {
+ 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
+ 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17
};
#if YYDEBUG
/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
YYRHS. */
-static const yytype_uint8 yyprhs[] =
-{
- 0, 0, 3, 6, 10, 15, 16, 18, 19, 21,
- 24, 29, 31, 34, 39, 41, 43, 45, 49, 51,
- 55, 59, 64, 70, 73, 75, 77, 79, 83, 88,
- 92, 97, 100, 105, 109, 112
+static const yytype_uint8 yyprhs[] = {
+ 0, 0, 3, 6, 10, 15, 16, 18, 19, 21,
+ 24, 29, 31, 34, 39, 41, 43, 45, 49, 51,
+ 55, 59, 64, 70, 73, 75, 77, 79, 83, 88,
+ 92, 97, 100, 105, 109, 112
};
/* YYRHS -- A `-1'-separated list of the rules' RHS. */
-static const yytype_int8 yyrhs[] =
-{
- 19, 0, -1, 21, 20, -1, 21, 22, 20, -1,
- 21, 22, 23, 20, -1, -1, 13, -1, -1, 27,
- -1, 6, 27, -1, 15, 6, 27, 10, -1, 6,
- -1, 6, 27, -1, 15, 6, 27, 10, -1, 6,
- -1, 3, -1, 26, -1, 9, 26, 10, -1, 24,
- -1, 7, 27, 8, -1, 26, 4, 26, -1, 26,
- 14, 29, 10, -1, 26, 4, 9, 26, 10, -1,
- 25, 28, -1, 25, -1, 28, -1, 29, -1, 14,
- 29, 10, -1, 29, 14, 29, 10, -1, 12, 24,
- 30, -1, 17, 7, 27, 8, -1, 12, 26, -1,
- 16, 9, 26, 10, -1, 12, 26, 30, -1, 12,
- 26, -1, 17, 7, 27, 8, -1
+static const yytype_int8 yyrhs[] = {
+ 19, 0, -1, 21, 20, -1, 21, 22, 20, -1,
+ 21, 22, 23, 20, -1, -1, 13, -1, -1, 27,
+ -1, 6, 27, -1, 15, 6, 27, 10, -1, 6,
+ -1, 6, 27, -1, 15, 6, 27, 10, -1, 6,
+ -1, 3, -1, 26, -1, 9, 26, 10, -1, 24,
+ -1, 7, 27, 8, -1, 26, 4, 26, -1, 26,
+ 14, 29, 10, -1, 26, 4, 9, 26, 10, -1,
+ 25, 28, -1, 25, -1, 28, -1, 29, -1, 14,
+ 29, 10, -1, 29, 14, 29, 10, -1, 12, 24,
+ 30, -1, 17, 7, 27, 8, -1, 12, 26, -1,
+ 16, 9, 26, 10, -1, 12, 26, 30, -1, 12,
+ 26, -1, 17, 7, 27, 8, -1
};
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
-static const yytype_uint8 yyrline[] =
-{
- 0, 138, 138, 140, 142, 148, 149, 156, 157, 163,
- 165, 167, 173, 175, 177, 183, 188, 190, 195, 197,
- 199, 201, 203, 209, 211, 213, 219, 221, 223, 229,
- 231, 233, 235, 241, 243, 245
+static const yytype_uint8 yyrline[] = {
+ 0, 138, 138, 140, 142, 148, 149, 156, 157, 163,
+ 165, 167, 173, 175, 177, 183, 188, 190, 195, 197,
+ 199, 201, 203, 209, 211, 213, 219, 221, 223, 229,
+ 231, 233, 235, 241, 243, 245
};
#endif
#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
First, the terminals, then, starting at YYNTOKENS, nonterminals. */
-static const char *const yytname[] =
-{
- "$end", "error", "$undefined", "WGROUP", "YY_COMMA", "YY_AMP",
- "YY_SLASH", "YY_PARENO", "YY_PARENC", "YY_BRACKETSO", "YY_BRACKETSC",
- "YY_HASH", "YY_LT", "YY_GT", "YY_BRACKETSO_LT", "YY_BRACKETSO_SLASH",
- "YY_LT_BRACKETSO", "YY_LT_PARENO", "$accept", "saidspec", "optcont",
- "leftspec", "midspec", "rightspec", "word", "cwordset", "wordset",
- "expr", "cwordrefset", "wordrefset", "recref", 0
+static const char *const yytname[] = {
+ "$end", "error", "$undefined", "WGROUP", "YY_COMMA", "YY_AMP",
+ "YY_SLASH", "YY_PARENO", "YY_PARENC", "YY_BRACKETSO", "YY_BRACKETSC",
+ "YY_HASH", "YY_LT", "YY_GT", "YY_BRACKETSO_LT", "YY_BRACKETSO_SLASH",
+ "YY_LT_BRACKETSO", "YY_LT_PARENO", "$accept", "saidspec", "optcont",
+ "leftspec", "midspec", "rightspec", "word", "cwordset", "wordset",
+ "expr", "cwordrefset", "wordrefset", "recref", 0
};
#endif
# ifdef YYPRINT
/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
token YYLEX-NUM. */
-static const yytype_uint16 yytoknum[] =
-{
- 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
- 265, 266, 267, 268, 269, 270, 271, 272
+static const yytype_uint16 yytoknum[] = {
+ 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
+ 265, 266, 267, 268, 269, 270, 271, 272
};
# endif
/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
-static const yytype_uint8 yyr1[] =
-{
- 0, 18, 19, 19, 19, 20, 20, 21, 21, 22,
- 22, 22, 23, 23, 23, 24, 25, 25, 26, 26,
- 26, 26, 26, 27, 27, 27, 28, 28, 28, 29,
- 29, 29, 29, 30, 30, 30
+static const yytype_uint8 yyr1[] = {
+ 0, 18, 19, 19, 19, 20, 20, 21, 21, 22,
+ 22, 22, 23, 23, 23, 24, 25, 25, 26, 26,
+ 26, 26, 26, 27, 27, 27, 28, 28, 28, 29,
+ 29, 29, 29, 30, 30, 30
};
/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
-static const yytype_uint8 yyr2[] =
-{
- 0, 2, 2, 3, 4, 0, 1, 0, 1, 2,
- 4, 1, 2, 4, 1, 1, 1, 3, 1, 3,
- 3, 4, 5, 2, 1, 1, 1, 3, 4, 3,
- 4, 2, 4, 3, 2, 4
+static const yytype_uint8 yyr2[] = {
+ 0, 2, 2, 3, 4, 0, 1, 0, 1, 2,
+ 4, 1, 2, 4, 1, 1, 1, 3, 1, 3,
+ 3, 4, 5, 2, 1, 1, 1, 3, 4, 3,
+ 4, 2, 4, 3, 2, 4
};
/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
STATE-NUM when YYTABLE doesn't specify something else to do. Zero
means the default is an error. */
-static const yytype_uint8 yydefact[] =
-{
- 7, 15, 0, 0, 0, 0, 0, 0, 0, 5,
- 18, 24, 16, 8, 25, 26, 0, 0, 18, 31,
- 0, 0, 0, 1, 11, 6, 0, 2, 5, 23,
- 0, 0, 0, 19, 17, 0, 0, 29, 27, 0,
- 0, 9, 0, 14, 0, 3, 5, 0, 20, 0,
- 0, 34, 0, 32, 30, 0, 12, 0, 4, 0,
- 21, 28, 33, 0, 10, 0, 22, 35, 13
+static const yytype_uint8 yydefact[] = {
+ 7, 15, 0, 0, 0, 0, 0, 0, 0, 5,
+ 18, 24, 16, 8, 25, 26, 0, 0, 18, 31,
+ 0, 0, 0, 1, 11, 6, 0, 2, 5, 23,
+ 0, 0, 0, 19, 17, 0, 0, 29, 27, 0,
+ 0, 9, 0, 14, 0, 3, 5, 0, 20, 0,
+ 0, 34, 0, 32, 30, 0, 12, 0, 4, 0,
+ 21, 28, 33, 0, 10, 0, 22, 35, 13
};
/* YYDEFGOTO[NTERM-NUM]. */
-static const yytype_int8 yydefgoto[] =
-{
- -1, 8, 27, 9, 28, 46, 10, 11, 12, 13,
- 14, 15, 37
+static const yytype_int8 yydefgoto[] = {
+ -1, 8, 27, 9, 28, 46, 10, 11, 12, 13,
+ 14, 15, 37
};
/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
STATE-NUM. */
#define YYPACT_NINF -24
-static const yytype_int8 yypact[] =
-{
- -1, -24, -1, 62, 62, 54, 1, 5, 18, 38,
- -24, 47, 3, -24, -24, 12, 23, 15, -3, 3,
- 28, 62, -1, -24, -1, -24, 42, -24, 39, -24,
- 53, 54, 54, -24, -24, 62, 50, -24, -24, 29,
- 41, -24, -1, -1, 52, -24, 55, 62, 3, 57,
- 63, 20, -1, -24, -24, 64, -24, -1, -24, 32,
- -24, -24, -24, 67, -24, 66, -24, -24, -24
+static const yytype_int8 yypact[] = {
+ -1, -24, -1, 62, 62, 54, 1, 5, 18, 38,
+ -24, 47, 3, -24, -24, 12, 23, 15, -3, 3,
+ 28, 62, -1, -24, -1, -24, 42, -24, 39, -24,
+ 53, 54, 54, -24, -24, 62, 50, -24, -24, 29,
+ 41, -24, -1, -1, 52, -24, 55, 62, 3, 57,
+ 63, 20, -1, -24, -24, 64, -24, -1, -24, 32,
+ -24, -24, -24, 67, -24, 66, -24, -24, -24
};
/* YYPGOTO[NTERM-NUM]. */
-static const yytype_int8 yypgoto[] =
-{
- -24, -24, -23, -24, -24, -24, 68, -24, 0, -2,
- 69, -4, 26
+static const yytype_int8 yypgoto[] = {
+ -24, -24, -23, -24, -24, -24, 68, -24, 0, -2,
+ 69, -4, 26
};
/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
@@ -621,43 +607,40 @@ static const yytype_int8 yypgoto[] =
number is the opposite. If zero, do what YYDEFACT says.
If YYTABLE_NINF, syntax error. */
#define YYTABLE_NINF -1
-static const yytype_uint8 yytable[] =
-{
- 16, 20, 1, 17, 19, 45, 2, 30, 3, 35,
- 21, 4, 22, 5, 36, 6, 7, 31, 23, 30,
- 40, 39, 41, 58, 30, 34, 32, 49, 50, 31,
- 48, 33, 35, 30, 31, 51, 30, 36, 38, 53,
- 55, 56, 66, 31, 24, 43, 31, 59, 42, 54,
- 63, 25, 25, 26, 44, 65, 1, 52, 57, 4,
- 2, 5, 47, 6, 7, 1, 4, 60, 25, 2,
- 6, 7, 18, 61, 64, 67, 68, 62, 0, 0,
- 29
+static const yytype_uint8 yytable[] = {
+ 16, 20, 1, 17, 19, 45, 2, 30, 3, 35,
+ 21, 4, 22, 5, 36, 6, 7, 31, 23, 30,
+ 40, 39, 41, 58, 30, 34, 32, 49, 50, 31,
+ 48, 33, 35, 30, 31, 51, 30, 36, 38, 53,
+ 55, 56, 66, 31, 24, 43, 31, 59, 42, 54,
+ 63, 25, 25, 26, 44, 65, 1, 52, 57, 4,
+ 2, 5, 47, 6, 7, 1, 4, 60, 25, 2,
+ 6, 7, 18, 61, 64, 67, 68, 62, 0, 0,
+ 29
};
-static const yytype_int8 yycheck[] =
-{
- 2, 5, 3, 3, 4, 28, 7, 4, 9, 12,
- 9, 12, 7, 14, 17, 16, 17, 14, 0, 4,
- 22, 21, 24, 46, 4, 10, 14, 31, 32, 14,
- 30, 8, 12, 4, 14, 35, 4, 17, 10, 10,
- 42, 43, 10, 14, 6, 6, 14, 47, 6, 8,
- 52, 13, 13, 15, 15, 57, 3, 7, 6, 12,
- 7, 14, 9, 16, 17, 3, 12, 10, 13, 7,
- 16, 17, 4, 10, 10, 8, 10, 51, -1, -1,
- 11
+static const yytype_int8 yycheck[] = {
+ 2, 5, 3, 3, 4, 28, 7, 4, 9, 12,
+ 9, 12, 7, 14, 17, 16, 17, 14, 0, 4,
+ 22, 21, 24, 46, 4, 10, 14, 31, 32, 14,
+ 30, 8, 12, 4, 14, 35, 4, 17, 10, 10,
+ 42, 43, 10, 14, 6, 6, 14, 47, 6, 8,
+ 52, 13, 13, 15, 15, 57, 3, 7, 6, 12,
+ 7, 14, 9, 16, 17, 3, 12, 10, 13, 7,
+ 16, 17, 4, 10, 10, 8, 10, 51, -1, -1,
+ 11
};
/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
symbol of state STATE-NUM. */
-static const yytype_uint8 yystos[] =
-{
- 0, 3, 7, 9, 12, 14, 16, 17, 19, 21,
- 24, 25, 26, 27, 28, 29, 27, 26, 24, 26,
- 29, 9, 7, 0, 6, 13, 15, 20, 22, 28,
- 4, 14, 14, 8, 10, 12, 17, 30, 10, 26,
- 27, 27, 6, 6, 15, 20, 23, 9, 26, 29,
- 29, 26, 7, 10, 8, 27, 27, 6, 20, 26,
- 10, 10, 30, 27, 10, 27, 10, 8, 10
+static const yytype_uint8 yystos[] = {
+ 0, 3, 7, 9, 12, 14, 16, 17, 19, 21,
+ 24, 25, 26, 27, 28, 29, 27, 26, 24, 26,
+ 29, 9, 7, 0, 6, 13, 15, 20, 22, 28,
+ 4, 14, 14, 8, 10, 12, 17, 30, 10, 26,
+ 27, 27, 6, 6, 15, 20, 23, 9, 26, 29,
+ 29, 26, 7, 10, 8, 27, 27, 6, 20, 26,
+ 10, 10, 30, 27, 10, 27, 10, 8, 10
};
#define yyerrok (yyerrstatus = 0)
@@ -784,28 +767,27 @@ do { \
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
-yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
+yy_symbol_value_print(FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
#else
static void
-yy_symbol_value_print (yyoutput, yytype, yyvaluep)
- FILE *yyoutput;
- int yytype;
- YYSTYPE const * const yyvaluep;
+yy_symbol_value_print(yyoutput, yytype, yyvaluep)
+FILE *yyoutput;
+int yytype;
+YYSTYPE const * const yyvaluep;
#endif
{
- if (!yyvaluep)
- return;
+ if (!yyvaluep)
+ return;
# ifdef YYPRINT
- if (yytype < YYNTOKENS)
- YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
+ if (yytype < YYNTOKENS)
+ YYPRINT(yyoutput, yytoknum[yytype], *yyvaluep);
# else
- YYUSE (yyoutput);
+ YYUSE(yyoutput);
# endif
- switch (yytype)
- {
- default:
- break;
- }
+ switch (yytype) {
+ default:
+ break;
+ }
}
@@ -816,22 +798,22 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep)
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
-yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
+yy_symbol_print(FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
#else
static void
-yy_symbol_print (yyoutput, yytype, yyvaluep)
- FILE *yyoutput;
- int yytype;
- YYSTYPE const * const yyvaluep;
+yy_symbol_print(yyoutput, yytype, yyvaluep)
+FILE *yyoutput;
+int yytype;
+YYSTYPE const * const yyvaluep;
#endif
{
- if (yytype < YYNTOKENS)
- YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
- else
- YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
+ if (yytype < YYNTOKENS)
+ YYFPRINTF(yyoutput, "token %s (", yytname[yytype]);
+ else
+ YYFPRINTF(yyoutput, "nterm %s (", yytname[yytype]);
- yy_symbol_value_print (yyoutput, yytype, yyvaluep);
- YYFPRINTF (yyoutput, ")");
+ yy_symbol_value_print(yyoutput, yytype, yyvaluep);
+ YYFPRINTF(yyoutput, ")");
}
/*------------------------------------------------------------------.
@@ -842,18 +824,18 @@ yy_symbol_print (yyoutput, yytype, yyvaluep)
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
-yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
+yy_stack_print(yytype_int16 *bottom, yytype_int16 *top)
#else
static void
-yy_stack_print (bottom, top)
- yytype_int16 *bottom;
- yytype_int16 *top;
+yy_stack_print(bottom, top)
+yytype_int16 *bottom;
+yytype_int16 *top;
#endif
{
- YYFPRINTF (stderr, "Stack now");
- for (; bottom <= top; ++bottom)
- YYFPRINTF (stderr, " %d", *bottom);
- YYFPRINTF (stderr, "\n");
+ YYFPRINTF(stderr, "Stack now");
+ for (; bottom <= top; ++bottom)
+ YYFPRINTF(stderr, " %d", *bottom);
+ YYFPRINTF(stderr, "\n");
}
# define YY_STACK_PRINT(Bottom, Top) \
@@ -870,28 +852,27 @@ do { \
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
-yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
+yy_reduce_print(YYSTYPE *yyvsp, int yyrule)
#else
static void
-yy_reduce_print (yyvsp, yyrule)
- YYSTYPE *yyvsp;
- int yyrule;
+yy_reduce_print(yyvsp, yyrule)
+YYSTYPE *yyvsp;
+int yyrule;
#endif
{
- int yynrhs = yyr2[yyrule];
- int yyi;
- unsigned long int yylno = yyrline[yyrule];
- YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
- yyrule - 1, yylno);
- /* The symbols being reduced. */
- for (yyi = 0; yyi < yynrhs; yyi++)
- {
- fprintf (stderr, " $%d = ", yyi + 1);
- yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
- &(yyvsp[(yyi + 1) - (yynrhs)])
- );
- fprintf (stderr, "\n");
- }
+ int yynrhs = yyr2[yyrule];
+ int yyi;
+ unsigned long int yylno = yyrline[yyrule];
+ YYFPRINTF(stderr, "Reducing stack by rule %d (line %lu):\n",
+ yyrule - 1, yylno);
+ /* The symbols being reduced. */
+ for (yyi = 0; yyi < yynrhs; yyi++) {
+ fprintf(stderr, " $%d = ", yyi + 1);
+ yy_symbol_print(stderr, yyrhs[yyprhs[yyrule] + yyi],
+ &(yyvsp[(yyi + 1) - (yynrhs)])
+ );
+ fprintf(stderr, "\n");
+ }
}
# define YY_REDUCE_PRINT(Rule) \
@@ -939,17 +920,17 @@ int yydebug;
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static YYSIZE_T
-yystrlen (const char *yystr)
+yystrlen(const char *yystr)
#else
static YYSIZE_T
-yystrlen (yystr)
- const char *yystr;
+yystrlen(yystr)
+const char *yystr;
#endif
{
- YYSIZE_T yylen;
- for (yylen = 0; yystr[yylen]; yylen++)
- continue;
- return yylen;
+ YYSIZE_T yylen;
+ for (yylen = 0; yystr[yylen]; yylen++)
+ continue;
+ return yylen;
}
# endif
# endif
@@ -963,21 +944,21 @@ yystrlen (yystr)
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static char *
-yystpcpy (char *yydest, const char *yysrc)
+yystpcpy(char *yydest, const char *yysrc)
#else
static char *
-yystpcpy (yydest, yysrc)
- char *yydest;
- const char *yysrc;
+yystpcpy(yydest, yysrc)
+char *yydest;
+const char *yysrc;
#endif
{
- char *yyd = yydest;
- const char *yys = yysrc;
+ char *yyd = yydest;
+ const char *yys = yysrc;
- while ((*yyd++ = *yys++) != '\0')
- continue;
+ while ((*yyd++ = *yys++) != '\0')
+ continue;
- return yyd - 1;
+ return yyd - 1;
}
# endif
# endif
@@ -991,42 +972,40 @@ yystpcpy (yydest, yysrc)
null, do not copy; instead, return the length of what the result
would have been. */
static YYSIZE_T
-yytnamerr (char *yyres, const char *yystr)
-{
- if (*yystr == '"')
- {
- YYSIZE_T yyn = 0;
- char const *yyp = yystr;
-
- for (;;)
- switch (*++yyp)
- {
- case '\'':
- case ',':
- goto do_not_strip_quotes;
-
- case '\\':
- if (*++yyp != '\\')
- goto do_not_strip_quotes;
- /* Fall through. */
- default:
- if (yyres)
- yyres[yyn] = *yyp;
- yyn++;
- break;
-
- case '"':
- if (yyres)
- yyres[yyn] = '\0';
- return yyn;
- }
- do_not_strip_quotes: ;
- }
-
- if (! yyres)
- return yystrlen (yystr);
-
- return yystpcpy (yyres, yystr) - yyres;
+yytnamerr(char *yyres, const char *yystr) {
+ if (*yystr == '"') {
+ YYSIZE_T yyn = 0;
+ char const *yyp = yystr;
+
+ for (;;)
+ switch (*++yyp) {
+ case '\'':
+ case ',':
+ goto do_not_strip_quotes;
+
+ case '\\':
+ if (*++yyp != '\\')
+ goto do_not_strip_quotes;
+ /* Fall through. */
+ default:
+ if (yyres)
+ yyres[yyn] = *yyp;
+ yyn++;
+ break;
+
+ case '"':
+ if (yyres)
+ yyres[yyn] = '\0';
+ return yyn;
+ }
+do_not_strip_quotes:
+ ;
+ }
+
+ if (! yyres)
+ return yystrlen(yystr);
+
+ return yystpcpy(yyres, yystr) - yyres;
}
# endif
@@ -1038,104 +1017,95 @@ yytnamerr (char *yyres, const char *yystr)
message will do. Return YYSIZE_MAXIMUM if overflow occurs during
size calculation. */
static YYSIZE_T
-yysyntax_error (char *yyresult, int yystate, int yychar)
-{
- int yyn = yypact[yystate];
-
- if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
- return 0;
- else
- {
- int yytype = YYTRANSLATE (yychar);
- YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
- YYSIZE_T yysize = yysize0;
- YYSIZE_T yysize1;
- int yysize_overflow = 0;
- enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
- char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
- int yyx;
+yysyntax_error(char *yyresult, int yystate, int yychar) {
+ int yyn = yypact[yystate];
+
+ if (!(YYPACT_NINF < yyn && yyn <= YYLAST))
+ return 0;
+ else {
+ int yytype = YYTRANSLATE(yychar);
+ YYSIZE_T yysize0 = yytnamerr(0, yytname[yytype]);
+ YYSIZE_T yysize = yysize0;
+ YYSIZE_T yysize1;
+ int yysize_overflow = 0;
+ enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
+ char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
+ int yyx;
# if 0
- /* This is so xgettext sees the translatable formats that are
- constructed on the fly. */
- YY_("syntax error, unexpected %s");
- YY_("syntax error, unexpected %s, expecting %s");
- YY_("syntax error, unexpected %s, expecting %s or %s");
- YY_("syntax error, unexpected %s, expecting %s or %s or %s");
- YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
+ /* This is so xgettext sees the translatable formats that are
+ constructed on the fly. */
+ YY_("syntax error, unexpected %s");
+ YY_("syntax error, unexpected %s, expecting %s");
+ YY_("syntax error, unexpected %s, expecting %s or %s");
+ YY_("syntax error, unexpected %s, expecting %s or %s or %s");
+ YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
# endif
- char *yyfmt;
- char const *yyf;
- static char const yyunexpected[] = "syntax error, unexpected %s";
- static char const yyexpecting[] = ", expecting %s";
- static char const yyor[] = " or %s";
- char yyformat[sizeof yyunexpected
- + sizeof yyexpecting - 1
- + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
- * (sizeof yyor - 1))];
- char const *yyprefix = yyexpecting;
-
- /* Start YYX at -YYN if negative to avoid negative indexes in
- YYCHECK. */
- int yyxbegin = yyn < 0 ? -yyn : 0;
-
- /* Stay within bounds of both yycheck and yytname. */
- int yychecklim = YYLAST - yyn + 1;
- int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
- int yycount = 1;
-
- yyarg[0] = yytname[yytype];
- yyfmt = yystpcpy (yyformat, yyunexpected);
-
- for (yyx = yyxbegin; yyx < yyxend; ++yyx)
- if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
- {
- if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
- {
- yycount = 1;
- yysize = yysize0;
- yyformat[sizeof yyunexpected - 1] = '\0';
- break;
- }
- yyarg[yycount++] = yytname[yyx];
- yysize1 = yysize + yytnamerr (0, yytname[yyx]);
- yysize_overflow |= (yysize1 < yysize);
- yysize = yysize1;
- yyfmt = yystpcpy (yyfmt, yyprefix);
- yyprefix = yyor;
- }
-
- yyf = YY_(yyformat);
- yysize1 = yysize + yystrlen (yyf);
- yysize_overflow |= (yysize1 < yysize);
- yysize = yysize1;
-
- if (yysize_overflow)
- return YYSIZE_MAXIMUM;
-
- if (yyresult)
- {
- /* Avoid sprintf, as that infringes on the user's name space.
- Don't have undefined behavior even if the translation
- produced a string with the wrong number of "%s"s. */
- char *yyp = yyresult;
- int yyi = 0;
- while ((*yyp = *yyf) != '\0')
- {
- if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
- {
- yyp += yytnamerr (yyp, yyarg[yyi++]);
- yyf += 2;
- }
- else
- {
- yyp++;
- yyf++;
+ char *yyfmt;
+ char const *yyf;
+ static char const yyunexpected[] = "syntax error, unexpected %s";
+ static char const yyexpecting[] = ", expecting %s";
+ static char const yyor[] = " or %s";
+ char yyformat[sizeof yyunexpected
+ + sizeof yyexpecting - 1
+ + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
+ * (sizeof yyor - 1))];
+ char const *yyprefix = yyexpecting;
+
+ /* Start YYX at -YYN if negative to avoid negative indexes in
+ YYCHECK. */
+ int yyxbegin = yyn < 0 ? -yyn : 0;
+
+ /* Stay within bounds of both yycheck and yytname. */
+ int yychecklim = YYLAST - yyn + 1;
+ int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
+ int yycount = 1;
+
+ yyarg[0] = yytname[yytype];
+ yyfmt = yystpcpy(yyformat, yyunexpected);
+
+ for (yyx = yyxbegin; yyx < yyxend; ++yyx)
+ if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) {
+ if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) {
+ yycount = 1;
+ yysize = yysize0;
+ yyformat[sizeof yyunexpected - 1] = '\0';
+ break;
+ }
+ yyarg[yycount++] = yytname[yyx];
+ yysize1 = yysize + yytnamerr(0, yytname[yyx]);
+ yysize_overflow |= (yysize1 < yysize);
+ yysize = yysize1;
+ yyfmt = yystpcpy(yyfmt, yyprefix);
+ yyprefix = yyor;
+ }
+
+ yyf = YY_(yyformat);
+ yysize1 = yysize + yystrlen(yyf);
+ yysize_overflow |= (yysize1 < yysize);
+ yysize = yysize1;
+
+ if (yysize_overflow)
+ return YYSIZE_MAXIMUM;
+
+ if (yyresult) {
+ /* Avoid sprintf, as that infringes on the user's name space.
+ Don't have undefined behavior even if the translation
+ produced a string with the wrong number of "%s"s. */
+ char *yyp = yyresult;
+ int yyi = 0;
+ while ((*yyp = *yyf) != '\0') {
+ if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) {
+ yyp += yytnamerr(yyp, yyarg[yyi++]);
+ yyf += 2;
+ } else {
+ yyp++;
+ yyf++;
+ }
+ }
}
- }
+ return yysize;
}
- return yysize;
- }
}
#endif /* YYERROR_VERBOSE */
@@ -1148,28 +1118,27 @@ yysyntax_error (char *yyresult, int yystate, int yychar)
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
-yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
+yydestruct(const char *yymsg, int yytype, YYSTYPE *yyvaluep)
#else
static void
-yydestruct (yymsg, yytype, yyvaluep)
- const char *yymsg;
- int yytype;
- YYSTYPE *yyvaluep;
+yydestruct(yymsg, yytype, yyvaluep)
+const char *yymsg;
+int yytype;
+YYSTYPE *yyvaluep;
#endif
{
- YYUSE (yyvaluep);
+ YYUSE(yyvaluep);
- if (!yymsg)
- yymsg = "Deleting";
- YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
+ if (!yymsg)
+ yymsg = "Deleting";
+ YY_SYMBOL_PRINT(yymsg, yytype, yyvaluep, yylocationp);
#if 0
- switch (yytype)
- {
+ switch (yytype) {
- default:
- break;
- }
+ default:
+ break;
+ }
#endif
}
@@ -1178,15 +1147,15 @@ yydestruct (yymsg, yytype, yyvaluep)
#ifdef YYPARSE_PARAM
#if defined __STDC__ || defined __cplusplus
-int yyparse (void *YYPARSE_PARAM);
+int yyparse(void *YYPARSE_PARAM);
#else
-int yyparse ();
+int yyparse();
#endif
#else /* ! YYPARSE_PARAM */
#if defined __STDC__ || defined __cplusplus
-int yyparse (void);
+int yyparse(void);
#else
-int yyparse ();
+int yyparse();
#endif
#endif /* ! YYPARSE_PARAM */
@@ -1211,651 +1180,631 @@ int yynerrs;
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
int
-yyparse (void *YYPARSE_PARAM)
+yyparse(void *YYPARSE_PARAM)
#else
int
-yyparse (YYPARSE_PARAM)
- void *YYPARSE_PARAM;
+yyparse(YYPARSE_PARAM)
+void *YYPARSE_PARAM;
#endif
#else /* ! YYPARSE_PARAM */
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
int
-yyparse (void)
+yyparse(void)
#else
int
-yyparse ()
+yyparse()
#endif
#endif
{
-
- int yystate;
- int yyn;
- int yyresult;
- /* Number of tokens to shift before error messages enabled. */
- int yyerrstatus;
- /* Look-ahead token as an internal (translated) token number. */
- int yytoken = 0;
+
+ int yystate;
+ int yyn;
+ int yyresult;
+ /* Number of tokens to shift before error messages enabled. */
+ int yyerrstatus;
+ /* Look-ahead token as an internal (translated) token number. */
+ int yytoken = 0;
#if YYERROR_VERBOSE
- /* Buffer for error messages, and its allocated size. */
- char yymsgbuf[128];
- char *yymsg = yymsgbuf;
- YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
+ /* Buffer for error messages, and its allocated size. */
+ char yymsgbuf[128];
+ char *yymsg = yymsgbuf;
+ YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
#endif
- /* Three stacks and their tools:
- `yyss': related to states,
- `yyvs': related to semantic values,
- `yyls': related to locations.
+ /* Three stacks and their tools:
+ `yyss': related to states,
+ `yyvs': related to semantic values,
+ `yyls': related to locations.
- Refer to the stacks thru separate pointers, to allow yyoverflow
- to reallocate them elsewhere. */
+ Refer to the stacks thru separate pointers, to allow yyoverflow
+ to reallocate them elsewhere. */
- /* The state stack. */
- yytype_int16 yyssa[YYINITDEPTH];
- yytype_int16 *yyss = yyssa;
- yytype_int16 *yyssp;
+ /* The state stack. */
+ yytype_int16 yyssa[YYINITDEPTH];
+ yytype_int16 *yyss = yyssa;
+ yytype_int16 *yyssp;
- /* The semantic value stack. */
- YYSTYPE yyvsa[YYINITDEPTH];
- YYSTYPE *yyvs = yyvsa;
- YYSTYPE *yyvsp;
+ /* The semantic value stack. */
+ YYSTYPE yyvsa[YYINITDEPTH];
+ YYSTYPE *yyvs = yyvsa;
+ YYSTYPE *yyvsp;
#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
- YYSIZE_T yystacksize = YYINITDEPTH;
+ YYSIZE_T yystacksize = YYINITDEPTH;
- /* The variables used to return semantic value and location from the
- action routines. */
- YYSTYPE yyval;
+ /* The variables used to return semantic value and location from the
+ action routines. */
+ YYSTYPE yyval;
- /* The number of symbols on the RHS of the reduced rule.
- Keep to zero when no symbol should be popped. */
- int yylen = 0;
+ /* The number of symbols on the RHS of the reduced rule.
+ Keep to zero when no symbol should be popped. */
+ int yylen = 0;
- YYDPRINTF ((stderr, "Starting parse\n"));
+ YYDPRINTF((stderr, "Starting parse\n"));
- yystate = 0;
- yyerrstatus = 0;
- yynerrs = 0;
- yychar = YYEMPTY; /* Cause a token to be read. */
+ yystate = 0;
+ yyerrstatus = 0;
+ yynerrs = 0;
+ yychar = YYEMPTY; /* Cause a token to be read. */
- /* Initialize stack pointers.
- Waste one element of value and location stack
- so that they stay on the same level as the state stack.
- The wasted elements are never initialized. */
+ /* Initialize stack pointers.
+ Waste one element of value and location stack
+ so that they stay on the same level as the state stack.
+ The wasted elements are never initialized. */
- yyssp = yyss;
- yyvsp = yyvs;
+ yyssp = yyss;
+ yyvsp = yyvs;
- goto yysetstate;
+ goto yysetstate;
-/*------------------------------------------------------------.
-| yynewstate -- Push a new state, which is found in yystate. |
-`------------------------------------------------------------*/
- yynewstate:
- /* In all cases, when you get here, the value and location stacks
- have just been pushed. So pushing a state here evens the stacks. */
- yyssp++;
+ /*------------------------------------------------------------.
+ | yynewstate -- Push a new state, which is found in yystate. |
+ `------------------------------------------------------------*/
+yynewstate:
+ /* In all cases, when you get here, the value and location stacks
+ have just been pushed. So pushing a state here evens the stacks. */
+ yyssp++;
- yysetstate:
- *yyssp = yystate;
+yysetstate:
+ *yyssp = yystate;
- if (yyss + yystacksize - 1 <= yyssp)
- {
- /* Get the current used size of the three stacks, in elements. */
- YYSIZE_T yysize = yyssp - yyss + 1;
+ if (yyss + yystacksize - 1 <= yyssp) {
+ /* Get the current used size of the three stacks, in elements. */
+ YYSIZE_T yysize = yyssp - yyss + 1;
#ifdef yyoverflow
- {
- /* Give user a chance to reallocate the stack. Use copies of
- these so that the &'s don't force the real ones into
- memory. */
- YYSTYPE *yyvs1 = yyvs;
- yytype_int16 *yyss1 = yyss;
-
-
- /* Each stack pointer address is followed by the size of the
- data in use in that stack, in bytes. This used to be a
- conditional around just the two extra args, but that might
- be undefined if yyoverflow is a macro. */
- yyoverflow (YY_("memory exhausted"),
- &yyss1, yysize * sizeof (*yyssp),
- &yyvs1, yysize * sizeof (*yyvsp),
-
- &yystacksize);
-
- yyss = yyss1;
- yyvs = yyvs1;
- }
+ {
+ /* Give user a chance to reallocate the stack. Use copies of
+ these so that the &'s don't force the real ones into
+ memory. */
+ YYSTYPE *yyvs1 = yyvs;
+ yytype_int16 *yyss1 = yyss;
+
+
+ /* Each stack pointer address is followed by the size of the
+ data in use in that stack, in bytes. This used to be a
+ conditional around just the two extra args, but that might
+ be undefined if yyoverflow is a macro. */
+ yyoverflow(YY_("memory exhausted"),
+ &yyss1, yysize * sizeof(*yyssp),
+ &yyvs1, yysize * sizeof(*yyvsp),
+
+ &yystacksize);
+
+ yyss = yyss1;
+ yyvs = yyvs1;
+ }
#else /* no yyoverflow */
# ifndef YYSTACK_RELOCATE
- goto yyexhaustedlab;
+ goto yyexhaustedlab;
# else
- /* Extend the stack our own way. */
- if (YYMAXDEPTH <= yystacksize)
- goto yyexhaustedlab;
- yystacksize *= 2;
- if (YYMAXDEPTH < yystacksize)
- yystacksize = YYMAXDEPTH;
-
- {
- yytype_int16 *yyss1 = yyss;
- union yyalloc *yyptr =
- (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
- if (! yyptr)
- goto yyexhaustedlab;
- YYSTACK_RELOCATE (yyss);
- YYSTACK_RELOCATE (yyvs);
+ /* Extend the stack our own way. */
+ if (YYMAXDEPTH <= yystacksize)
+ goto yyexhaustedlab;
+ yystacksize *= 2;
+ if (YYMAXDEPTH < yystacksize)
+ yystacksize = YYMAXDEPTH;
+
+ {
+ yytype_int16 *yyss1 = yyss;
+ union yyalloc *yyptr =
+ (union yyalloc *) YYSTACK_ALLOC(YYSTACK_BYTES(yystacksize));
+ if (! yyptr)
+ goto yyexhaustedlab;
+ YYSTACK_RELOCATE(yyss);
+ YYSTACK_RELOCATE(yyvs);
# undef YYSTACK_RELOCATE
- if (yyss1 != yyssa)
- YYSTACK_FREE (yyss1);
- }
+ if (yyss1 != yyssa)
+ YYSTACK_FREE(yyss1);
+ }
# endif
#endif /* no yyoverflow */
- yyssp = yyss + yysize - 1;
- yyvsp = yyvs + yysize - 1;
+ yyssp = yyss + yysize - 1;
+ yyvsp = yyvs + yysize - 1;
- YYDPRINTF ((stderr, "Stack size increased to %lu\n",
- (unsigned long int) yystacksize));
+ YYDPRINTF((stderr, "Stack size increased to %lu\n",
+ (unsigned long int) yystacksize));
- if (yyss + yystacksize - 1 <= yyssp)
- YYABORT;
- }
+ if (yyss + yystacksize - 1 <= yyssp)
+ YYABORT;
+ }
- YYDPRINTF ((stderr, "Entering state %d\n", yystate));
+ YYDPRINTF((stderr, "Entering state %d\n", yystate));
- goto yybackup;
+ goto yybackup;
-/*-----------.
-| yybackup. |
-`-----------*/
+ /*-----------.
+ | yybackup. |
+ `-----------*/
yybackup:
- /* Do appropriate processing given the current state. Read a
- look-ahead token if we need one and don't already have one. */
-
- /* First try to decide what to do without reference to look-ahead token. */
- yyn = yypact[yystate];
- if (yyn == YYPACT_NINF)
- goto yydefault;
-
- /* Not known => get a look-ahead token if don't already have one. */
-
- /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
- if (yychar == YYEMPTY)
- {
- YYDPRINTF ((stderr, "Reading a token: "));
- yychar = YYLEX;
- }
-
- if (yychar <= YYEOF)
- {
- yychar = yytoken = YYEOF;
- YYDPRINTF ((stderr, "Now at end of input.\n"));
- }
- else
- {
- yytoken = YYTRANSLATE (yychar);
- YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
- }
-
- /* If the proper action on seeing token YYTOKEN is to reduce or to
- detect an error, take that action. */
- yyn += yytoken;
- if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
- goto yydefault;
- yyn = yytable[yyn];
- if (yyn <= 0)
- {
- if (yyn == 0 || yyn == YYTABLE_NINF)
- goto yyerrlab;
- yyn = -yyn;
- goto yyreduce;
- }
-
- if (yyn == YYFINAL)
- YYACCEPT;
-
- /* Count tokens shifted since error; after three, turn off error
- status. */
- if (yyerrstatus)
- yyerrstatus--;
-
- /* Shift the look-ahead token. */
- YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
-
- /* Discard the shifted token unless it is eof. */
- if (yychar != YYEOF)
- yychar = YYEMPTY;
-
- yystate = yyn;
- *++yyvsp = yylval;
-
- goto yynewstate;
-
-
-/*-----------------------------------------------------------.
-| yydefault -- do the default action for the current state. |
-`-----------------------------------------------------------*/
+ /* Do appropriate processing given the current state. Read a
+ look-ahead token if we need one and don't already have one. */
+
+ /* First try to decide what to do without reference to look-ahead token. */
+ yyn = yypact[yystate];
+ if (yyn == YYPACT_NINF)
+ goto yydefault;
+
+ /* Not known => get a look-ahead token if don't already have one. */
+
+ /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
+ if (yychar == YYEMPTY) {
+ YYDPRINTF((stderr, "Reading a token: "));
+ yychar = YYLEX;
+ }
+
+ if (yychar <= YYEOF) {
+ yychar = yytoken = YYEOF;
+ YYDPRINTF((stderr, "Now at end of input.\n"));
+ } else {
+ yytoken = YYTRANSLATE(yychar);
+ YY_SYMBOL_PRINT("Next token is", yytoken, &yylval, &yylloc);
+ }
+
+ /* If the proper action on seeing token YYTOKEN is to reduce or to
+ detect an error, take that action. */
+ yyn += yytoken;
+ if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
+ goto yydefault;
+ yyn = yytable[yyn];
+ if (yyn <= 0) {
+ if (yyn == 0 || yyn == YYTABLE_NINF)
+ goto yyerrlab;
+ yyn = -yyn;
+ goto yyreduce;
+ }
+
+ if (yyn == YYFINAL)
+ YYACCEPT;
+
+ /* Count tokens shifted since error; after three, turn off error
+ status. */
+ if (yyerrstatus)
+ yyerrstatus--;
+
+ /* Shift the look-ahead token. */
+ YY_SYMBOL_PRINT("Shifting", yytoken, &yylval, &yylloc);
+
+ /* Discard the shifted token unless it is eof. */
+ if (yychar != YYEOF)
+ yychar = YYEMPTY;
+
+ yystate = yyn;
+ *++yyvsp = yylval;
+
+ goto yynewstate;
+
+
+ /*-----------------------------------------------------------.
+ | yydefault -- do the default action for the current state. |
+ `-----------------------------------------------------------*/
yydefault:
- yyn = yydefact[yystate];
- if (yyn == 0)
- goto yyerrlab;
- goto yyreduce;
+ yyn = yydefact[yystate];
+ if (yyn == 0)
+ goto yyerrlab;
+ goto yyreduce;
-/*-----------------------------.
-| yyreduce -- Do a reduction. |
-`-----------------------------*/
+ /*-----------------------------.
+ | yyreduce -- Do a reduction. |
+ `-----------------------------*/
yyreduce:
- /* yyn is the number of a rule to reduce with. */
- yylen = yyr2[yyn];
+ /* yyn is the number of a rule to reduce with. */
+ yylen = yyr2[yyn];
- /* If YYLEN is nonzero, implement the default value of the action:
- `$$ = $1'.
+ /* If YYLEN is nonzero, implement the default value of the action:
+ `$$ = $1'.
- Otherwise, the following line sets YYVAL to garbage.
- This behavior is undocumented and Bison
- users should not rely upon it. Assigning to YYVAL
- unconditionally makes the parser a bit smaller, and it avoids a
- GCC warning that YYVAL may be used uninitialized. */
- yyval = yyvsp[1-yylen];
+ Otherwise, the following line sets YYVAL to garbage.
+ This behavior is undocumented and Bison
+ users should not rely upon it. Assigning to YYVAL
+ unconditionally makes the parser a bit smaller, and it avoids a
+ GCC warning that YYVAL may be used uninitialized. */
+ yyval = yyvsp[1-yylen];
- YY_REDUCE_PRINT (yyn);
- switch (yyn)
- {
- case 2:
+ YY_REDUCE_PRINT(yyn);
+ switch (yyn) {
+ case 2:
#line 139 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = said_top_branch(said_attach_branch((yyvsp[(1) - (2)]), (yyvsp[(2) - (2)]))); }
- break;
+ {(yyval) = said_top_branch(said_attach_branch((yyvsp[(1) - (2)]), (yyvsp[(2) - (2)]))); }
+ break;
- case 3:
+ case 3:
#line 141 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = said_top_branch(said_attach_branch((yyvsp[(1) - (3)]), said_attach_branch((yyvsp[(2) - (3)]), (yyvsp[(3) - (3)])))); }
- break;
+ {(yyval) = said_top_branch(said_attach_branch((yyvsp[(1) - (3)]), said_attach_branch((yyvsp[(2) - (3)]), (yyvsp[(3) - (3)])))); }
+ break;
- case 4:
+ case 4:
#line 143 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = said_top_branch(said_attach_branch((yyvsp[(1) - (4)]), said_attach_branch((yyvsp[(2) - (4)]), said_attach_branch((yyvsp[(3) - (4)]), (yyvsp[(4) - (4)]))))); }
- break;
+ {(yyval) = said_top_branch(said_attach_branch((yyvsp[(1) - (4)]), said_attach_branch((yyvsp[(2) - (4)]), said_attach_branch((yyvsp[(3) - (4)]), (yyvsp[(4) - (4)]))))); }
+ break;
- case 5:
+ case 5:
#line 148 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = SAID_BRANCH_NULL; }
- break;
+ {(yyval) = SAID_BRANCH_NULL; }
+ break;
- case 6:
+ case 6:
#line 150 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = said_paren(said_value(0x14b, said_value(0xf900, said_terminal(0xf900))), SAID_BRANCH_NULL); }
- break;
+ {(yyval) = said_paren(said_value(0x14b, said_value(0xf900, said_terminal(0xf900))), SAID_BRANCH_NULL); }
+ break;
- case 7:
+ case 7:
#line 156 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = SAID_BRANCH_NULL; }
- break;
+ {(yyval) = SAID_BRANCH_NULL; }
+ break;
- case 8:
+ case 8:
#line 158 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = said_paren(said_value(0x141, said_value(0x149, (yyvsp[(1) - (1)]))), SAID_BRANCH_NULL); }
- break;
+ {(yyval) = said_paren(said_value(0x141, said_value(0x149, (yyvsp[(1) - (1)]))), SAID_BRANCH_NULL); }
+ break;
- case 9:
+ case 9:
#line 164 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = said_aug_branch(0x142, 0x14a, (yyvsp[(2) - (2)]), SAID_BRANCH_NULL); }
- break;
+ {(yyval) = said_aug_branch(0x142, 0x14a, (yyvsp[(2) - (2)]), SAID_BRANCH_NULL); }
+ break;
- case 10:
+ case 10:
#line 166 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = said_aug_branch(0x152, 0x142, said_aug_branch(0x142, 0x14a, (yyvsp[(3) - (4)]), SAID_BRANCH_NULL), SAID_BRANCH_NULL); }
- break;
+ {(yyval) = said_aug_branch(0x152, 0x142, said_aug_branch(0x142, 0x14a, (yyvsp[(3) - (4)]), SAID_BRANCH_NULL), SAID_BRANCH_NULL); }
+ break;
- case 11:
+ case 11:
#line 168 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = SAID_BRANCH_NULL; }
- break;
+ {(yyval) = SAID_BRANCH_NULL; }
+ break;
- case 12:
+ case 12:
#line 174 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = said_aug_branch(0x143, 0x14a, (yyvsp[(2) - (2)]), SAID_BRANCH_NULL); }
- break;
+ {(yyval) = said_aug_branch(0x143, 0x14a, (yyvsp[(2) - (2)]), SAID_BRANCH_NULL); }
+ break;
- case 13:
+ case 13:
#line 176 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = said_aug_branch(0x152, 0x143, said_aug_branch(0x143, 0x14a, (yyvsp[(3) - (4)]), SAID_BRANCH_NULL), SAID_BRANCH_NULL); }
- break;
+ {(yyval) = said_aug_branch(0x152, 0x143, said_aug_branch(0x143, 0x14a, (yyvsp[(3) - (4)]), SAID_BRANCH_NULL), SAID_BRANCH_NULL); }
+ break;
- case 14:
+ case 14:
#line 178 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = SAID_BRANCH_NULL; }
- break;
+ {(yyval) = SAID_BRANCH_NULL; }
+ break;
- case 15:
+ case 15:
#line 184 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = said_paren(said_value(0x141, said_value(0x153, said_terminal((yyvsp[(1) - (1)])))), SAID_BRANCH_NULL); }
- break;
+ {(yyval) = said_paren(said_value(0x141, said_value(0x153, said_terminal((yyvsp[(1) - (1)])))), SAID_BRANCH_NULL); }
+ break;
- case 16:
+ case 16:
#line 189 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = said_aug_branch(0x141, 0x14f, (yyvsp[(1) - (1)]), SAID_BRANCH_NULL); }
- break;
+ {(yyval) = said_aug_branch(0x141, 0x14f, (yyvsp[(1) - (1)]), SAID_BRANCH_NULL); }
+ break;
- case 17:
+ case 17:
#line 191 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = said_aug_branch(0x141, 0x14f, said_aug_branch(0x152, 0x14c, said_aug_branch(0x141, 0x14f, (yyvsp[(2) - (3)]), SAID_BRANCH_NULL), SAID_BRANCH_NULL), SAID_BRANCH_NULL); }
- break;
+ {(yyval) = said_aug_branch(0x141, 0x14f, said_aug_branch(0x152, 0x14c, said_aug_branch(0x141, 0x14f, (yyvsp[(2) - (3)]), SAID_BRANCH_NULL), SAID_BRANCH_NULL), SAID_BRANCH_NULL); }
+ break;
- case 18:
+ case 18:
#line 196 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = (yyvsp[(1) - (1)]); }
- break;
+ {(yyval) = (yyvsp[(1) - (1)]); }
+ break;
- case 19:
+ case 19:
#line 198 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = (yyvsp[(1) - (3)]); }
- break;
+ {(yyval) = (yyvsp[(1) - (3)]); }
+ break;
- case 20:
+ case 20:
#line 200 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = said_attach_branch((yyvsp[(1) - (3)]), (yyvsp[(3) - (3)])); }
- break;
+ {(yyval) = said_attach_branch((yyvsp[(1) - (3)]), (yyvsp[(3) - (3)])); }
+ break;
- case 21:
+ case 21:
#line 202 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = said_attach_branch((yyvsp[(1) - (4)]), (yyvsp[(3) - (4)])); }
- break;
+ {(yyval) = said_attach_branch((yyvsp[(1) - (4)]), (yyvsp[(3) - (4)])); }
+ break;
- case 22:
+ case 22:
#line 204 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = said_attach_branch((yyvsp[(1) - (5)]), (yyvsp[(3) - (5)])); }
- break;
+ {(yyval) = said_attach_branch((yyvsp[(1) - (5)]), (yyvsp[(3) - (5)])); }
+ break;
- case 23:
+ case 23:
#line 210 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = said_attach_branch((yyvsp[(1) - (2)]), (yyvsp[(2) - (2)])); }
- break;
+ {(yyval) = said_attach_branch((yyvsp[(1) - (2)]), (yyvsp[(2) - (2)])); }
+ break;
- case 24:
+ case 24:
#line 212 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = (yyvsp[(1) - (1)]); }
- break;
+ {(yyval) = (yyvsp[(1) - (1)]); }
+ break;
- case 25:
+ case 25:
#line 214 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = (yyvsp[(1) - (1)]); }
- break;
+ {(yyval) = (yyvsp[(1) - (1)]); }
+ break;
- case 26:
+ case 26:
#line 220 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = (yyvsp[(1) - (1)]); }
- break;
+ {(yyval) = (yyvsp[(1) - (1)]); }
+ break;
- case 27:
+ case 27:
#line 222 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = said_aug_branch(0x152, 0x144, (yyvsp[(2) - (3)]), SAID_BRANCH_NULL); }
- break;
+ {(yyval) = said_aug_branch(0x152, 0x144, (yyvsp[(2) - (3)]), SAID_BRANCH_NULL); }
+ break;
- case 28:
+ case 28:
#line 224 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = said_attach_branch((yyvsp[(1) - (4)]), said_aug_branch(0x152, 0x144, (yyvsp[(3) - (4)]), SAID_BRANCH_NULL)); }
- break;
+ {(yyval) = said_attach_branch((yyvsp[(1) - (4)]), said_aug_branch(0x152, 0x144, (yyvsp[(3) - (4)]), SAID_BRANCH_NULL)); }
+ break;
- case 29:
+ case 29:
#line 230 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = said_aug_branch(0x144, 0x14f, (yyvsp[(2) - (3)]), (yyvsp[(3) - (3)])); }
- break;
+ {(yyval) = said_aug_branch(0x144, 0x14f, (yyvsp[(2) - (3)]), (yyvsp[(3) - (3)])); }
+ break;
- case 30:
+ case 30:
#line 232 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = said_aug_branch(0x144, 0x14f, said_aug_branch(0x141, 0x144, (yyvsp[(2) - (4)]), SAID_BRANCH_NULL), SAID_BRANCH_NULL); }
- break;
+ {(yyval) = said_aug_branch(0x144, 0x14f, said_aug_branch(0x141, 0x144, (yyvsp[(2) - (4)]), SAID_BRANCH_NULL), SAID_BRANCH_NULL); }
+ break;
- case 31:
+ case 31:
#line 234 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = said_aug_branch(0x144, 0x14f, (yyvsp[(2) - (2)]), SAID_BRANCH_NULL); }
- break;
+ {(yyval) = said_aug_branch(0x144, 0x14f, (yyvsp[(2) - (2)]), SAID_BRANCH_NULL); }
+ break;
- case 32:
+ case 32:
#line 236 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = said_aug_branch(0x152, 0x144, said_aug_branch(0x144, 0x14f, (yyvsp[(3) - (4)]), SAID_BRANCH_NULL), SAID_BRANCH_NULL); }
- break;
+ {(yyval) = said_aug_branch(0x152, 0x144, said_aug_branch(0x144, 0x14f, (yyvsp[(3) - (4)]), SAID_BRANCH_NULL), SAID_BRANCH_NULL); }
+ break;
- case 33:
+ case 33:
#line 242 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = said_aug_branch(0x141, 0x144, said_aug_branch(0x144, 0x14f, (yyvsp[(2) - (3)]), SAID_BRANCH_NULL), (yyvsp[(3) - (3)])); }
- break;
+ {(yyval) = said_aug_branch(0x141, 0x144, said_aug_branch(0x144, 0x14f, (yyvsp[(2) - (3)]), SAID_BRANCH_NULL), (yyvsp[(3) - (3)])); }
+ break;
- case 34:
+ case 34:
#line 244 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = said_aug_branch(0x141, 0x144, said_aug_branch(0x144, 0x14f, (yyvsp[(2) - (2)]), SAID_BRANCH_NULL), SAID_BRANCH_NULL); }
- break;
+ {(yyval) = said_aug_branch(0x141, 0x144, said_aug_branch(0x144, 0x14f, (yyvsp[(2) - (2)]), SAID_BRANCH_NULL), SAID_BRANCH_NULL); }
+ break;
- case 35:
+ case 35:
#line 246 "../../full-svn/scummvm/trunk/engines/sci/engine/said.y"
- { (yyval) = said_aug_branch(0x141, 0x14c, (yyvsp[(2) - (4)]), SAID_BRANCH_NULL); }
- break;
+ {(yyval) = said_aug_branch(0x141, 0x14c, (yyvsp[(2) - (4)]), SAID_BRANCH_NULL); }
+ break;
-/* Line 1267 of yacc.c. */
+ /* Line 1267 of yacc.c. */
#line 1647 "y.tab.c"
- default: break;
- }
- YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
+ default:
+ break;
+ }
+ YY_SYMBOL_PRINT("-> $$ =", yyr1[yyn], &yyval, &yyloc);
- YYPOPSTACK (yylen);
- yylen = 0;
- YY_STACK_PRINT (yyss, yyssp);
+ YYPOPSTACK(yylen);
+ yylen = 0;
+ YY_STACK_PRINT(yyss, yyssp);
- *++yyvsp = yyval;
+ *++yyvsp = yyval;
- /* Now `shift' the result of the reduction. Determine what state
- that goes to, based on the state we popped back to and the rule
- number reduced by. */
+ /* Now `shift' the result of the reduction. Determine what state
+ that goes to, based on the state we popped back to and the rule
+ number reduced by. */
- yyn = yyr1[yyn];
+ yyn = yyr1[yyn];
- yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
- if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
- yystate = yytable[yystate];
- else
- yystate = yydefgoto[yyn - YYNTOKENS];
+ yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
+ if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
+ yystate = yytable[yystate];
+ else
+ yystate = yydefgoto[yyn - YYNTOKENS];
- goto yynewstate;
+ goto yynewstate;
-/*------------------------------------.
-| yyerrlab -- here on detecting error |
-`------------------------------------*/
+ /*------------------------------------.
+ | yyerrlab -- here on detecting error |
+ `------------------------------------*/
yyerrlab:
- /* If not already recovering from an error, report this error. */
- if (!yyerrstatus)
- {
- ++yynerrs;
+ /* If not already recovering from an error, report this error. */
+ if (!yyerrstatus) {
+ ++yynerrs;
#if ! YYERROR_VERBOSE
- yyerror (YY_("syntax error"));
+ yyerror(YY_("syntax error"));
#else
- {
- YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
- if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
- {
- YYSIZE_T yyalloc = 2 * yysize;
- if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
- yyalloc = YYSTACK_ALLOC_MAXIMUM;
- if (yymsg != yymsgbuf)
- YYSTACK_FREE (yymsg);
- yymsg = (char *) YYSTACK_ALLOC (yyalloc);
- if (yymsg)
- yymsg_alloc = yyalloc;
- else
- {
- yymsg = yymsgbuf;
- yymsg_alloc = sizeof yymsgbuf;
- }
- }
-
- if (0 < yysize && yysize <= yymsg_alloc)
- {
- (void) yysyntax_error (yymsg, yystate, yychar);
- yyerror (yymsg);
- }
- else
- {
- yyerror (YY_("syntax error"));
- if (yysize != 0)
- goto yyexhaustedlab;
- }
- }
+ {
+ YYSIZE_T yysize = yysyntax_error(0, yystate, yychar);
+ if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM) {
+ YYSIZE_T yyalloc = 2 * yysize;
+ if (!(yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
+ yyalloc = YYSTACK_ALLOC_MAXIMUM;
+ if (yymsg != yymsgbuf)
+ YYSTACK_FREE(yymsg);
+ yymsg = (char *) YYSTACK_ALLOC(yyalloc);
+ if (yymsg)
+ yymsg_alloc = yyalloc;
+ else {
+ yymsg = yymsgbuf;
+ yymsg_alloc = sizeof yymsgbuf;
+ }
+ }
+
+ if (0 < yysize && yysize <= yymsg_alloc) {
+ (void) yysyntax_error(yymsg, yystate, yychar);
+ yyerror(yymsg);
+ } else {
+ yyerror(YY_("syntax error"));
+ if (yysize != 0)
+ goto yyexhaustedlab;
+ }
+ }
#endif
- }
+ }
- if (yyerrstatus == 3)
- {
- /* If just tried and failed to reuse look-ahead token after an
- error, discard it. */
+ if (yyerrstatus == 3) {
+ /* If just tried and failed to reuse look-ahead token after an
+ error, discard it. */
- if (yychar <= YYEOF)
- {
- /* Return failure if at end of input. */
- if (yychar == YYEOF)
- YYABORT;
- }
- else
- {
- yydestruct ("Error: discarding",
- yytoken, &yylval);
- yychar = YYEMPTY;
+ if (yychar <= YYEOF) {
+ /* Return failure if at end of input. */
+ if (yychar == YYEOF)
+ YYABORT;
+ } else {
+ yydestruct("Error: discarding",
+ yytoken, &yylval);
+ yychar = YYEMPTY;
+ }
}
- }
- /* Else will try to reuse look-ahead token after shifting the error
- token. */
- goto yyerrlab1;
+ /* Else will try to reuse look-ahead token after shifting the error
+ token. */
+ goto yyerrlab1;
-/*---------------------------------------------------.
-| yyerrorlab -- error raised explicitly by YYERROR. |
-`---------------------------------------------------*/
+ /*---------------------------------------------------.
+ | yyerrorlab -- error raised explicitly by YYERROR. |
+ `---------------------------------------------------*/
yyerrorlab:
- /* Pacify compilers like GCC when the user code never invokes
- YYERROR and the label yyerrorlab therefore never appears in user
- code. */
- if (/*CONSTCOND*/ 0)
- goto yyerrorlab;
+ /* Pacify compilers like GCC when the user code never invokes
+ YYERROR and the label yyerrorlab therefore never appears in user
+ code. */
+ if (/*CONSTCOND*/ 0)
+ goto yyerrorlab;
- /* Do not reclaim the symbols of the rule which action triggered
- this YYERROR. */
- YYPOPSTACK (yylen);
- yylen = 0;
- YY_STACK_PRINT (yyss, yyssp);
- yystate = *yyssp;
- goto yyerrlab1;
+ /* Do not reclaim the symbols of the rule which action triggered
+ this YYERROR. */
+ YYPOPSTACK(yylen);
+ yylen = 0;
+ YY_STACK_PRINT(yyss, yyssp);
+ yystate = *yyssp;
+ goto yyerrlab1;
-/*-------------------------------------------------------------.
-| yyerrlab1 -- common code for both syntax error and YYERROR. |
-`-------------------------------------------------------------*/
+ /*-------------------------------------------------------------.
+ | yyerrlab1 -- common code for both syntax error and YYERROR. |
+ `-------------------------------------------------------------*/
yyerrlab1:
- yyerrstatus = 3; /* Each real token shifted decrements this. */
-
- for (;;)
- {
- yyn = yypact[yystate];
- if (yyn != YYPACT_NINF)
- {
- yyn += YYTERROR;
- if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
- {
- yyn = yytable[yyn];
- if (0 < yyn)
- break;
- }
- }
+ yyerrstatus = 3; /* Each real token shifted decrements this. */
+
+ for (;;) {
+ yyn = yypact[yystate];
+ if (yyn != YYPACT_NINF) {
+ yyn += YYTERROR;
+ if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) {
+ yyn = yytable[yyn];
+ if (0 < yyn)
+ break;
+ }
+ }
- /* Pop the current state because it cannot handle the error token. */
- if (yyssp == yyss)
- YYABORT;
+ /* Pop the current state because it cannot handle the error token. */
+ if (yyssp == yyss)
+ YYABORT;
- yydestruct ("Error: popping",
- yystos[yystate], yyvsp);
- YYPOPSTACK (1);
- yystate = *yyssp;
- YY_STACK_PRINT (yyss, yyssp);
- }
+ yydestruct("Error: popping",
+ yystos[yystate], yyvsp);
+ YYPOPSTACK(1);
+ yystate = *yyssp;
+ YY_STACK_PRINT(yyss, yyssp);
+ }
- if (yyn == YYFINAL)
- YYACCEPT;
+ if (yyn == YYFINAL)
+ YYACCEPT;
- *++yyvsp = yylval;
+ *++yyvsp = yylval;
- /* Shift the error token. */
- YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
+ /* Shift the error token. */
+ YY_SYMBOL_PRINT("Shifting", yystos[yyn], yyvsp, yylsp);
- yystate = yyn;
- goto yynewstate;
+ yystate = yyn;
+ goto yynewstate;
-/*-------------------------------------.
-| yyacceptlab -- YYACCEPT comes here. |
-`-------------------------------------*/
+ /*-------------------------------------.
+ | yyacceptlab -- YYACCEPT comes here. |
+ `-------------------------------------*/
yyacceptlab:
- yyresult = 0;
- goto yyreturn;
+ yyresult = 0;
+ goto yyreturn;
-/*-----------------------------------.
-| yyabortlab -- YYABORT comes here. |
-`-----------------------------------*/
+ /*-----------------------------------.
+ | yyabortlab -- YYABORT comes here. |
+ `-----------------------------------*/
yyabortlab:
- yyresult = 1;
- goto yyreturn;
+ yyresult = 1;
+ goto yyreturn;
#ifndef yyoverflow
-/*-------------------------------------------------.
-| yyexhaustedlab -- memory exhaustion comes here. |
-`-------------------------------------------------*/
+ /*-------------------------------------------------.
+ | yyexhaustedlab -- memory exhaustion comes here. |
+ `-------------------------------------------------*/
yyexhaustedlab:
- yyerror (YY_("memory exhausted"));
- yyresult = 2;
- /* Fall through. */
+ yyerror(YY_("memory exhausted"));
+ yyresult = 2;
+ /* Fall through. */
#endif
yyreturn:
- if (yychar != YYEOF && yychar != YYEMPTY)
- yydestruct ("Cleanup: discarding lookahead",
- yytoken, &yylval);
- /* Do not reclaim the symbols of the rule which action triggered
- this YYABORT or YYACCEPT. */
- YYPOPSTACK (yylen);
- YY_STACK_PRINT (yyss, yyssp);
- while (yyssp != yyss)
- {
- yydestruct ("Cleanup: popping",
- yystos[*yyssp], yyvsp);
- YYPOPSTACK (1);
- }
+ if (yychar != YYEOF && yychar != YYEMPTY)
+ yydestruct("Cleanup: discarding lookahead",
+ yytoken, &yylval);
+ /* Do not reclaim the symbols of the rule which action triggered
+ this YYABORT or YYACCEPT. */
+ YYPOPSTACK(yylen);
+ YY_STACK_PRINT(yyss, yyssp);
+ while (yyssp != yyss) {
+ yydestruct("Cleanup: popping",
+ yystos[*yyssp], yyvsp);
+ YYPOPSTACK(1);
+ }
#ifndef yyoverflow
- if (yyss != yyssa)
- YYSTACK_FREE (yyss);
+ if (yyss != yyssa)
+ YYSTACK_FREE(yyss);
#endif
#if YYERROR_VERBOSE
- if (yymsg != yymsgbuf)
- YYSTACK_FREE (yymsg);
+ if (yymsg != yymsgbuf)
+ YYSTACK_FREE(yymsg);
#endif
- /* Make sure YYID is used. */
- return YYID (yyresult);
+ /* Make sure YYID is used. */
+ return YYID(yyresult);
}
@@ -1865,11 +1814,11 @@ yyreturn:
int
parse_yy_token_lookup[] = {YY_COMMA, YY_AMP, YY_SLASH, YY_PARENO, YY_PARENC, YY_BRACKETSO, YY_BRACKETSC,
- YY_HASH, YY_LT, YY_GT};
+ YY_HASH, YY_LT, YY_GT
+ };
static int
-yylex(void)
-{
+yylex(void) {
int retval = said_tokens[said_token++];
if (retval < SAID_LONG(SAID_FIRST)) {
@@ -1903,8 +1852,7 @@ yylex(void)
#define SAID_NEXT_NODE ((said_tree_pos == 0) || (said_tree_pos >= VOCAB_TREE_NODES))? said_tree_pos = 0 : said_tree_pos++
static inline int
-said_leaf_node(tree_t pos, int value)
-{
+said_leaf_node(tree_t pos, int value) {
said_tree[pos].type = PARSE_TREE_NODE_LEAF;
if (value != VALUE_IGNORE)
@@ -1914,8 +1862,7 @@ said_leaf_node(tree_t pos, int value)
}
static inline int
-said_branch_node(tree_t pos, int left, int right)
-{
+said_branch_node(tree_t pos, int left, int right) {
said_tree[pos].type = PARSE_TREE_NODE_BRANCH;
if (left != VALUE_IGNORE)
@@ -1929,62 +1876,57 @@ said_branch_node(tree_t pos, int left, int right)
static tree_t
-said_paren(tree_t t1, tree_t t2)
-{
+said_paren(tree_t t1, tree_t t2) {
if (t1)
return said_branch_node(SAID_NEXT_NODE,
- t1,
- t2
- );
+ t1,
+ t2
+ );
else
return t2;
}
static tree_t
-said_value(int val, tree_t t)
-{
+said_value(int val, tree_t t) {
return said_branch_node(SAID_NEXT_NODE,
- said_leaf_node(SAID_NEXT_NODE, val),
- t
- );
-
+ said_leaf_node(SAID_NEXT_NODE, val),
+ t
+ );
+
}
static tree_t
-said_terminal(int val)
-{
+said_terminal(int val) {
return said_leaf_node(SAID_NEXT_NODE, val);
}
static tree_t
-said_aug_branch(int n1, int n2, tree_t t1, tree_t t2)
-{
+said_aug_branch(int n1, int n2, tree_t t1, tree_t t2) {
int retval;
retval = said_branch_node(SAID_NEXT_NODE,
- said_branch_node(SAID_NEXT_NODE,
- said_leaf_node(SAID_NEXT_NODE, n1),
- said_branch_node(SAID_NEXT_NODE,
- said_leaf_node(SAID_NEXT_NODE, n2),
- t1
- )
- ),
- t2
- );
+ said_branch_node(SAID_NEXT_NODE,
+ said_leaf_node(SAID_NEXT_NODE, n1),
+ said_branch_node(SAID_NEXT_NODE,
+ said_leaf_node(SAID_NEXT_NODE, n2),
+ t1
+ )
+ ),
+ t2
+ );
#ifdef SAID_DEBUG
- fprintf(stderr,"AUG(0x%x, 0x%x, [%04x], [%04x]) = [%04x]\n", n1, n2, t1, t2, retval);
+ fprintf(stderr, "AUG(0x%x, 0x%x, [%04x], [%04x]) = [%04x]\n", n1, n2, t1, t2, retval);
#endif
return retval;
}
static tree_t
-said_attach_branch(tree_t base, tree_t attacheant)
-{
+said_attach_branch(tree_t base, tree_t attacheant) {
#ifdef SAID_DEBUG
- fprintf(stderr,"ATT2([%04x], [%04x]) = [%04x]\n", base, attacheant, base);
+ fprintf(stderr, "ATT2([%04x], [%04x]) = [%04x]\n", base, attacheant, base);
#endif
if (!attacheant)
@@ -2001,8 +1943,7 @@ said_attach_branch(tree_t base, tree_t attacheant)
}
static said_spec_t
-said_top_branch(tree_t first)
-{
+said_top_branch(tree_t first) {
#ifdef SAID_DEBUG
fprintf(stderr, "TOP([%04x])\n", first);
#endif
@@ -2018,8 +1959,7 @@ said_top_branch(tree_t first)
int
-said_parse_spec(state_t *s, byte *spec)
-{
+said_parse_spec(state_t *s, byte *spec) {
int nextitem;
said_parse_error = NULL;
@@ -2086,10 +2026,10 @@ said_parse_spec(state_t *s, byte *spec)
static int
aug_get_next_sibling(parse_tree_node_t *tree, int pos, int *first, int *second)
- /* Returns the next sibling relative to the specified position in 'tree',
- ** sets *first and *second to its augment node values, returns the new position
- ** or 0 if there was no next sibling
- */
+/* Returns the next sibling relative to the specified position in 'tree',
+** sets *first and *second to its augment node values, returns the new position
+** or 0 if there was no next sibling
+*/
{
int seek, valpos;
@@ -2116,9 +2056,9 @@ aug_get_next_sibling(parse_tree_node_t *tree, int pos, int *first, int *second)
static int
aug_get_wgroup(parse_tree_node_t *tree, int pos)
- /* Returns 0 if pos in tree is not the root of a 3-element list, otherwise
- ** it returns the last element (which, in practice, is the word group
- */
+/* Returns 0 if pos in tree is not the root of a 3-element list, otherwise
+** it returns the last element (which, in practice, is the word group
+*/
{
int val;
@@ -2135,8 +2075,7 @@ aug_get_wgroup(parse_tree_node_t *tree, int pos)
static int
-aug_get_base_node(parse_tree_node_t *tree)
-{
+aug_get_base_node(parse_tree_node_t *tree) {
int startpos = 0;
AUG_READ_BRANCH(startpos, 1, startpos);
return startpos;
@@ -2148,10 +2087,10 @@ aug_get_base_node(parse_tree_node_t *tree)
static int
aug_get_first_child(parse_tree_node_t *tree, int pos, int *first, int *second)
- /* like aug_get_next_sibling, except that it recurses into the tree and
- ** finds the first child (usually *not* Ayanami Rei) of the current branch
- ** rather than its next sibling.
- */
+/* like aug_get_next_sibling, except that it recurses into the tree and
+** finds the first child (usually *not* Ayanami Rei) of the current branch
+** rather than its next sibling.
+*/
{
AUG_READ_BRANCH(pos, 0, pos);
AUG_ASSERT(pos);
@@ -2163,10 +2102,10 @@ aug_get_first_child(parse_tree_node_t *tree, int pos, int *first, int *second)
static void
aug_find_words_recursively(parse_tree_node_t *tree, int startpos,
- int *base_words, int *base_words_nr,
- int *ref_words, int *ref_words_nr,
- int maxwords, int refbranch)
- /* Finds and lists all base (141) and reference (144) words */
+ int *base_words, int *base_words_nr,
+ int *ref_words, int *ref_words_nr,
+ int maxwords, int refbranch)
+/* Finds and lists all base (141) and reference (144) words */
{
int major, minor;
int word;
@@ -2178,7 +2117,7 @@ aug_find_words_recursively(parse_tree_node_t *tree, int startpos,
while (pos) {
if ((word = aug_get_wgroup(tree, pos))) { /* found a word */
- if (!refbranch && major == WORD_TYPE_BASE) {
+ if (!refbranch && major == WORD_TYPE_BASE) {
if ((*base_words_nr) == maxwords) {
sciprintf("Out of regular words\n");
return; /* return gracefully */
@@ -2200,10 +2139,10 @@ aug_find_words_recursively(parse_tree_node_t *tree, int startpos,
}
if (major != WORD_TYPE_SYNTACTIC_SUGAR && major != WORD_TYPE_BASE && major != WORD_TYPE_REF)
sciprintf("aug_find_words_recursively(): Unknown word type %03x\n", major);
-
+
} else /* Did NOT find a word group: Attempt to recurse */
aug_find_words_recursively(tree, pos, base_words, base_words_nr,
- ref_words, ref_words_nr, maxwords, refbranch || major == WORD_TYPE_REF);
+ ref_words, ref_words_nr, maxwords, refbranch || major == WORD_TYPE_REF);
pos = aug_get_next_sibling(tree, pos, &major, &minor);
}
@@ -2212,10 +2151,10 @@ aug_find_words_recursively(parse_tree_node_t *tree, int startpos,
static void
aug_find_words(parse_tree_node_t *tree, int startpos,
- int *base_words, int *base_words_nr,
- int *ref_words, int *ref_words_nr,
- int maxwords)
- /* initializing wrapper for aug_find_words_recursively() */
+ int *base_words, int *base_words_nr,
+ int *ref_words, int *ref_words_nr,
+ int maxwords)
+/* initializing wrapper for aug_find_words_recursively() */
{
*base_words_nr = 0;
*ref_words_nr = 0;
@@ -2225,8 +2164,7 @@ aug_find_words(parse_tree_node_t *tree, int startpos,
static inline int
-aug_contains_word(int *list, int length, int word)
-{
+aug_contains_word(int *list, int length, int word) {
int i;
if (word == ANYWORD)
return (length);
@@ -2241,18 +2179,17 @@ aug_contains_word(int *list, int length, int word)
static int
augment_sentence_expression(parse_tree_node_t *saidt, int augment_pos,
- parse_tree_node_t *parset, int parse_branch,
- int major, int minor,
- int *base_words, int base_words_nr,
- int *ref_words, int ref_words_nr);
+ parse_tree_node_t *parset, int parse_branch,
+ int major, int minor,
+ int *base_words, int base_words_nr,
+ int *ref_words, int ref_words_nr);
static int
augment_match_expression_p(parse_tree_node_t *saidt, int augment_pos,
- parse_tree_node_t *parset, int parse_basepos,
- int major, int minor,
- int *base_words, int base_words_nr,
- int *ref_words, int ref_words_nr)
-{
+ parse_tree_node_t *parset, int parse_basepos,
+ int major, int minor,
+ int *base_words, int base_words_nr,
+ int *ref_words, int ref_words_nr) {
int cmajor, cminor, cpos;
cpos = aug_get_first_child(saidt, augment_pos, &cmajor, &cminor);
if (!cpos) {
@@ -2264,10 +2201,10 @@ augment_match_expression_p(parse_tree_node_t *saidt, int augment_pos,
if ((major == WORD_TYPE_BASE) && (minor == AUGMENT_SENTENCE_MINOR_RECURSE))
return augment_match_expression_p(saidt, cpos,
- parset, parse_basepos,
- cmajor, cminor,
- base_words, base_words_nr,
- ref_words, ref_words_nr);
+ parset, parse_basepos,
+ cmajor, cminor,
+ base_words, base_words_nr,
+ ref_words, ref_words_nr);
switch (major) {
@@ -2282,10 +2219,10 @@ augment_match_expression_p(parse_tree_node_t *saidt, int augment_pos,
return 1;
} else if (cminor == AUGMENT_SENTENCE_MINOR_MATCH_PHRASE) {
if (augment_sentence_expression(saidt, cpos,
- parset, parse_basepos,
- cmajor, cminor,
- base_words, base_words_nr,
- ref_words, ref_words_nr))
+ parset, parse_basepos,
+ cmajor, cminor,
+ base_words, base_words_nr,
+ ref_words, ref_words_nr))
return 1;
} else if (cminor == AUGMENT_SENTENCE_MINOR_PARENTHESES) {
int gc_major, gc_minor;
@@ -2293,10 +2230,10 @@ augment_match_expression_p(parse_tree_node_t *saidt, int augment_pos,
while (gchild) {
if (augment_match_expression_p(saidt, cpos,
- parset, parse_basepos,
- major, minor,
- base_words, base_words_nr,
- ref_words, ref_words_nr))
+ parset, parse_basepos,
+ major, minor,
+ base_words, base_words_nr,
+ ref_words, ref_words_nr))
return 1;
gchild = aug_get_next_sibling(saidt, gchild, &gc_major, &gc_minor);
}
@@ -2318,10 +2255,10 @@ augment_match_expression_p(parse_tree_node_t *saidt, int augment_pos,
return 1;
} else if (cminor == AUGMENT_SENTENCE_MINOR_MATCH_PHRASE) {
if (augment_match_expression_p(saidt, cpos,
- parset, parse_basepos,
- cmajor, cminor,
- base_words, base_words_nr,
- ref_words, ref_words_nr))
+ parset, parse_basepos,
+ cmajor, cminor,
+ base_words, base_words_nr,
+ ref_words, ref_words_nr))
return 1;
} else if (cminor == AUGMENT_SENTENCE_MINOR_PARENTHESES) {
int gc_major, gc_minor;
@@ -2329,10 +2266,10 @@ augment_match_expression_p(parse_tree_node_t *saidt, int augment_pos,
while (gchild) {
if (augment_match_expression_p(saidt, cpos,
- parset, parse_basepos,
- major, minor,
- base_words, base_words_nr,
- ref_words, ref_words_nr))
+ parset, parse_basepos,
+ major, minor,
+ base_words, base_words_nr,
+ ref_words, ref_words_nr))
return 1;
gchild = aug_get_next_sibling(saidt, gchild, &gc_major, &gc_minor);
}
@@ -2346,10 +2283,10 @@ augment_match_expression_p(parse_tree_node_t *saidt, int augment_pos,
case AUGMENT_SENTENCE_PART_BRACKETS:
if (augment_match_expression_p(saidt, cpos,
- parset, parse_basepos,
- cmajor, cminor,
- base_words, base_words_nr,
- ref_words, ref_words_nr))
+ parset, parse_basepos,
+ cmajor, cminor,
+ base_words, base_words_nr,
+ ref_words, ref_words_nr))
return 1;
scidprintf("Didn't match subexpression; checking sub-bracked predicate %03x\n", cmajor);
@@ -2382,17 +2319,16 @@ augment_match_expression_p(parse_tree_node_t *saidt, int augment_pos,
static int
augment_sentence_expression(parse_tree_node_t *saidt, int augment_pos,
- parse_tree_node_t *parset, int parse_branch,
- int major, int minor,
- int *base_words, int base_words_nr,
- int *ref_words, int ref_words_nr)
-{
+ parse_tree_node_t *parset, int parse_branch,
+ int major, int minor,
+ int *base_words, int base_words_nr,
+ int *ref_words, int ref_words_nr) {
int check_major, check_minor;
int check_pos = aug_get_first_child(saidt, augment_pos, &check_major, &check_minor);
do {
if (!(augment_match_expression_p(saidt, check_pos, parset, parse_branch,
- check_major, check_minor, base_words, base_words_nr,
- ref_words, ref_words_nr)))
+ check_major, check_minor, base_words, base_words_nr,
+ ref_words, ref_words_nr)))
return 0;
} while ((check_pos = aug_get_next_sibling(saidt, check_pos, &check_major, &check_minor)));
return 1;
@@ -2402,9 +2338,8 @@ augment_sentence_expression(parse_tree_node_t *saidt, int augment_pos,
static int
augment_sentence_part(parse_tree_node_t *saidt, int augment_pos,
- parse_tree_node_t *parset, int parse_basepos,
- int major, int minor)
-{
+ parse_tree_node_t *parset, int parse_basepos,
+ int major, int minor) {
int pmajor, pminor;
int parse_branch = parse_basepos;
int optional = 0;
@@ -2425,7 +2360,7 @@ augment_sentence_part(parse_tree_node_t *saidt, int augment_pos,
}
if ((major < 0x141)
- || (major > 0x143)) {
+ || (major > 0x143)) {
scidprintf("augment_sentence_part(): Unexpected sentence part major number %03x\n", major);
return 0;
}
@@ -2443,7 +2378,7 @@ augment_sentence_part(parse_tree_node_t *saidt, int augment_pos,
scidprintf("Found match with pminor = %03x\n", pminor);
aug_find_words(parset, parse_branch, base_words, &base_words_nr,
- ref_words, &ref_words_nr, AUGMENT_MAX_WORDS);
+ ref_words, &ref_words_nr, AUGMENT_MAX_WORDS);
foundwords |= (ref_words_nr | base_words_nr);
#ifdef SCI_DEBUG_PARSE_TREE_AUGMENTATION
sciprintf("%d base words:", base_words_nr);
@@ -2456,9 +2391,9 @@ augment_sentence_part(parse_tree_node_t *saidt, int augment_pos,
#endif
success = augment_sentence_expression(saidt, augment_pos,
- parset, parse_basepos, major, minor,
- base_words, base_words_nr,
- ref_words, ref_words_nr);
+ parset, parse_basepos, major, minor,
+ base_words, base_words_nr,
+ ref_words, ref_words_nr);
if (success) {
scidprintf("SUCCESS on augmenting (%03x %03x\n", major, minor);
@@ -2475,8 +2410,7 @@ augment_sentence_part(parse_tree_node_t *saidt, int augment_pos,
}
static int
-augment_parse_nodes(parse_tree_node_t *parset, parse_tree_node_t *saidt)
-{
+augment_parse_nodes(parse_tree_node_t *parset, parse_tree_node_t *saidt) {
int augment_basepos = 0;
int parse_basepos;
int major, minor;
@@ -2487,7 +2421,7 @@ augment_parse_nodes(parse_tree_node_t *parset, parse_tree_node_t *saidt)
sciprintf("augment_parse_nodes(): Parse tree is corrupt\n");
return 0;
}
-
+
augment_basepos = aug_get_base_node(saidt);
if (!augment_basepos) {
sciprintf("augment_parse_nodes(): Said tree is corrupt\n");
@@ -2496,7 +2430,7 @@ augment_parse_nodes(parse_tree_node_t *parset, parse_tree_node_t *saidt)
while ((augment_basepos = aug_get_next_sibling(saidt, augment_basepos, &major, &minor))) {
if ((major == 0x14b)
- && (minor == SAID_LONG(SAID_GT)))
+ && (minor == SAID_LONG(SAID_GT)))
dontclaim = 1; /* special case */
else /* normal sentence part */
if (!(augment_sentence_part(saidt, augment_basepos, parset, parse_basepos, major, minor))) {
@@ -2518,8 +2452,7 @@ augment_parse_nodes(parse_tree_node_t *parset, parse_tree_node_t *saidt)
/*******************/
int
-said(state_t *s, byte *spec, int verbose)
-{
+said(state_t *s, byte *spec, int verbose) {
int retval;
parse_tree_node_t *parse_tree_ptr = s->parser_nodes;
@@ -2550,8 +2483,7 @@ said(state_t *s, byte *spec, int verbose)
#ifdef SAID_DEBUG_PROGRAM
int
-main (int argc, char *argv)
-{
+main(int argc, char *argv) {
byte block[] = {0x01, 0x00, 0xf8, 0xf5, 0x02, 0x01, 0xf6, 0xf2, 0x02, 0x01, 0xf2, 0x01, 0x03, 0xff};
state_t s;
con_passthrough = 1;
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp
index 4abda55847..8c4d55a178 100644
--- a/engines/sci/engine/savegame.cpp
+++ b/engines/sci/engine/savegame.cpp
@@ -58,18 +58,15 @@ static state_t *_global_save_state;
void
-write_reg_t(FILE *fh, reg_t *foo)
-{
+write_reg_t(FILE *fh, reg_t *foo) {
fprintf(fh, PREG, PRINT_REG(*foo));
}
int
-read_reg_t(FILE *fh, reg_t *foo, const char *lastval, int *line, int *hiteof)
-{
+read_reg_t(FILE *fh, reg_t *foo, const char *lastval, int *line, int *hiteof) {
int segment, offset;
- if (sscanf(lastval, PREG, &segment, &offset)<2)
- {
+ if (sscanf(lastval, PREG, &segment, &offset) < 2) {
sciprintf("Error parsing reg_t on line %d\n", *line);
return 1;
}
@@ -79,21 +76,18 @@ read_reg_t(FILE *fh, reg_t *foo, const char *lastval, int *line, int *hiteof)
}
void
-write_sci_version(FILE *fh, sci_version_t *foo)
-{
+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));
+ SCI_VERSION_PATCHLEVEL(*foo));
}
int
-read_sci_version(FILE *fh, sci_version_t *foo, const char *lastval, int *line, int *hiteof)
-{
+read_sci_version(FILE *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)
-{
+write_PTN(FILE *fh, parse_tree_node_t *foo) {
if (foo->type == PARSE_TREE_NODE_LEAF)
fprintf(fh, "L%d", foo->content.value);
else
@@ -101,8 +95,7 @@ write_PTN(FILE *fh, parse_tree_node_t *foo)
}
int
-read_PTN(FILE *fh, parse_tree_node_t *foo, const char *lastval, int *line, int *hiteof)
-{
+read_PTN(FILE *fh, parse_tree_node_t *foo, const char *lastval, int *line, int *hiteof) {
if (lastval[0] == 'L') {
const char *c = lastval + 1;
char *strend;
@@ -206,21 +199,20 @@ typedef mem_obj_t *mem_obj_ptr;
#endif
static void
-_cfsml_error(const char *fmt, ...)
-{
- va_list argp;
+_cfsml_error(const char *fmt, ...) {
+ va_list argp;
- fprintf(stderr, "Error: ");
- va_start(argp, fmt);
- vfprintf(stderr, fmt, argp);
- va_end(argp);
+ fprintf(stderr, "Error: ");
+ va_start(argp, fmt);
+ vfprintf(stderr, fmt, argp);
+ va_end(argp);
}
static struct _cfsml_pointer_refstruct {
- struct _cfsml_pointer_refstruct *next;
- void *ptr;
+ struct _cfsml_pointer_refstruct *next;
+ void *ptr;
} *_cfsml_pointer_references = NULL;
static struct _cfsml_pointer_refstruct **_cfsml_pointer_references_current = &_cfsml_pointer_references;
@@ -229,229 +221,221 @@ static char *_cfsml_last_value_retrieved = NULL;
static char *_cfsml_last_identifier_retrieved = NULL;
static void
-_cfsml_free_pointer_references_recursively(struct _cfsml_pointer_refstruct *refs, int free_pointers)
-{
- if (!refs)
- return;
- #ifdef CFSML_DEBUG_MALLOC
- SCI_MEMTEST;
- #endif
-
- _cfsml_free_pointer_references_recursively(refs->next, free_pointers);
- #ifdef CFSML_DEBUG_MALLOC
- SCI_MEMTEST;
-
- fprintf(stderr,"Freeing ptrref %p [%p] %s\n", refs->ptr, refs, free_pointers?
- "ALL": "cleanup only");
- #endif
-
- if (free_pointers)
- free(refs->ptr);
-
- #ifdef CFSML_DEBUG_MALLOC
- SCI_MEMTEST;
- #endif
- free(refs);
- #ifdef CFSML_DEBUG_MALLOC
- SCI_MEMTEST;
- #endif
+_cfsml_free_pointer_references_recursively(struct _cfsml_pointer_refstruct *refs, int free_pointers) {
+ if (!refs)
+ return;
+#ifdef CFSML_DEBUG_MALLOC
+ SCI_MEMTEST;
+#endif
+
+ _cfsml_free_pointer_references_recursively(refs->next, free_pointers);
+#ifdef CFSML_DEBUG_MALLOC
+ SCI_MEMTEST;
+
+ fprintf(stderr, "Freeing ptrref %p [%p] %s\n", refs->ptr, refs, free_pointers ?
+ "ALL" : "cleanup only");
+#endif
+
+ if (free_pointers)
+ free(refs->ptr);
+
+#ifdef CFSML_DEBUG_MALLOC
+ SCI_MEMTEST;
+#endif
+ free(refs);
+#ifdef CFSML_DEBUG_MALLOC
+ SCI_MEMTEST;
+#endif
}
static void
-_cfsml_free_pointer_references(struct _cfsml_pointer_refstruct **meta_ref, int free_pointers)
-{
- _cfsml_free_pointer_references_recursively(*meta_ref, free_pointers);
- *meta_ref = NULL;
- _cfsml_pointer_references_current = meta_ref;
+_cfsml_free_pointer_references(struct _cfsml_pointer_refstruct **meta_ref, int free_pointers) {
+ _cfsml_free_pointer_references_recursively(*meta_ref, free_pointers);
+ *meta_ref = NULL;
+ _cfsml_pointer_references_current = meta_ref;
}
static struct _cfsml_pointer_refstruct **
-_cfsml_get_current_refpointer()
-{
- return _cfsml_pointer_references_current;
+ _cfsml_get_current_refpointer() {
+ return _cfsml_pointer_references_current;
}
-static void _cfsml_register_pointer(void *ptr)
-{
- struct _cfsml_pointer_refstruct *newref = (struct _cfsml_pointer_refstruct*)sci_malloc(sizeof (struct _cfsml_pointer_refstruct));
- #ifdef CFSML_DEBUG_MALLOC
- SCI_MEMTEST;
- fprintf(stderr,"Registering ptrref %p [%p]\n", ptr, newref);
- #endif
- newref->next = *_cfsml_pointer_references_current;
- newref->ptr = ptr;
- *_cfsml_pointer_references_current = newref;
+static void _cfsml_register_pointer(void *ptr) {
+ struct _cfsml_pointer_refstruct *newref = (struct _cfsml_pointer_refstruct*)sci_malloc(sizeof(struct _cfsml_pointer_refstruct));
+#ifdef CFSML_DEBUG_MALLOC
+ SCI_MEMTEST;
+ fprintf(stderr, "Registering ptrref %p [%p]\n", ptr, newref);
+#endif
+ newref->next = *_cfsml_pointer_references_current;
+ newref->ptr = ptr;
+ *_cfsml_pointer_references_current = newref;
}
static char *
-_cfsml_mangle_string(const char *s)
-{
- const char *source = s;
- char c;
- char *target = (char *) sci_malloc(1 + strlen(s) * 2); /* We will probably need less than that */
- char *writer = target;
-
- while ((c = *source++)) {
-
- if (c < 32) { /* Special character? */
- *writer++ = '\\'; /* Escape... */
- c += ('a' - 1);
- } else if (c == '\\' || c == '"')
- *writer++ = '\\'; /* Escape, but do not change */
- *writer++ = c;
-
- }
- *writer = 0; /* Terminate string */
-
- return (char *) sci_realloc(target, strlen(target) + 1);
+_cfsml_mangle_string(const char *s) {
+ const char *source = s;
+ char c;
+ char *target = (char *) sci_malloc(1 + strlen(s) * 2); /* We will probably need less than that */
+ char *writer = target;
+
+ while ((c = *source++)) {
+
+ if (c < 32) { /* Special character? */
+ *writer++ = '\\'; /* Escape... */
+ c += ('a' - 1);
+ } else if (c == '\\' || c == '"')
+ *writer++ = '\\'; /* Escape, but do not change */
+ *writer++ = c;
+
+ }
+ *writer = 0; /* Terminate string */
+
+ return (char *) sci_realloc(target, strlen(target) + 1);
}
static char *
-_cfsml_unmangle_string(const char *s, unsigned int length)
-{
- char *target = (char *) sci_malloc(1 + strlen(s));
- char *writer = target;
- const char *source = s;
- const char *end = s + length;
- char c;
-
- while ((source != end) && (c = *source++) && (c > 31)) {
- if (c == '\\') { /* Escaped character? */
- c = *source++;
- if ((c != '\\') && (c != '"')) /* Un-escape 0-31 only */
- c -= ('a' - 1);
- }
- *writer++ = c;
- }
- *writer = 0; /* Terminate string */
-
- return (char *) sci_realloc(target, strlen(target) + 1);
+_cfsml_unmangle_string(const char *s, unsigned int length) {
+ char *target = (char *) sci_malloc(1 + strlen(s));
+ char *writer = target;
+ const char *source = s;
+ const char *end = s + length;
+ char c;
+
+ while ((source != end) && (c = *source++) && (c > 31)) {
+ if (c == '\\') { /* Escaped character? */
+ c = *source++;
+ if ((c != '\\') && (c != '"')) /* Un-escape 0-31 only */
+ c -= ('a' - 1);
+ }
+ *writer++ = c;
+ }
+ *writer = 0; /* Terminate string */
+
+ return (char *) sci_realloc(target, strlen(target) + 1);
}
static char *
-_cfsml_get_identifier(FILE *fd, int *line, int *hiteof, int *assignment)
-{
- int c;
- int mem = 32;
- int pos = 0;
- int done = 0;
- char *retval = (char *) sci_malloc(mem);
-
- if (_cfsml_last_identifier_retrieved) {
- free(_cfsml_last_identifier_retrieved);
- _cfsml_last_identifier_retrieved = NULL;
- }
-
- while (isspace(c = fgetc(fd)) && (c != EOF));
- if (c == EOF) {
- _cfsml_error("Unexpected end of file at line %d\n", *line);
- free(retval);
- *hiteof = 1;
- return NULL;
- }
-
- ungetc(c, fd);
-
- while (((c = fgetc(fd)) != EOF) && ((pos == 0) || (c != '\n')) && (c != '=')) {
-
- 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);
- free(retval);
- return NULL;
- }
- retval[pos++] = c;
- } else
- if (pos != 0)
- done = 1; /* Finished the variable name */
- else if (c == '\n')
- ++(*line);
- }
-
- if (c == EOF) {
- _cfsml_error("Unexpected end of file at line %d\n", *line);
- free(retval);
- *hiteof = 1;
- return NULL;
- }
-
- if (c == '\n') {
- ++(*line);
- if (assignment)
- *assignment = 0;
- } else
- if (assignment)
- *assignment = 1;
-
- if (pos == 0) {
- _cfsml_error("Missing identifier in assignment at line %d\n", *line);
- free(retval);
- return NULL;
- }
-
- if (pos == mem - 1) /* Need more memory? */
- retval = (char *) sci_realloc(retval, mem += 1);
-
- retval[pos] = 0; /* Terminate string */
+_cfsml_get_identifier(FILE *fd, int *line, int *hiteof, int *assignment) {
+ int c;
+ int mem = 32;
+ int pos = 0;
+ int done = 0;
+ char *retval = (char *) sci_malloc(mem);
+
+ if (_cfsml_last_identifier_retrieved) {
+ free(_cfsml_last_identifier_retrieved);
+ _cfsml_last_identifier_retrieved = NULL;
+ }
+
+ while (isspace(c = fgetc(fd)) && (c != EOF));
+ if (c == EOF) {
+ _cfsml_error("Unexpected end of file at line %d\n", *line);
+ free(retval);
+ *hiteof = 1;
+ return NULL;
+ }
+
+ ungetc(c, fd);
+
+ while (((c = fgetc(fd)) != EOF) && ((pos == 0) || (c != '\n')) && (c != '=')) {
+
+ 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);
+ free(retval);
+ return NULL;
+ }
+ retval[pos++] = c;
+ } else
+ if (pos != 0)
+ done = 1; /* Finished the variable name */
+ else if (c == '\n')
+ ++(*line);
+ }
+
+ if (c == EOF) {
+ _cfsml_error("Unexpected end of file at line %d\n", *line);
+ free(retval);
+ *hiteof = 1;
+ return NULL;
+ }
+
+ if (c == '\n') {
+ ++(*line);
+ if (assignment)
+ *assignment = 0;
+ } else
+ if (assignment)
+ *assignment = 1;
+
+ if (pos == 0) {
+ _cfsml_error("Missing identifier in assignment at line %d\n", *line);
+ free(retval);
+ return NULL;
+ }
+
+ if (pos == mem - 1) /* Need more memory? */
+ retval = (char *) sci_realloc(retval, mem += 1);
+
+ retval[pos] = 0; /* Terminate string */
#line 323 "savegame.cfsml"
- return _cfsml_last_identifier_retrieved = retval;
+ return _cfsml_last_identifier_retrieved = retval;
}
static char *
-_cfsml_get_value(FILE *fd, int *line, int *hiteof)
-{
- int c;
- int mem = 64;
- int pos = 0;
- char *retval = (char *) sci_malloc(mem);
-
- if (_cfsml_last_value_retrieved) {
- free(_cfsml_last_value_retrieved);
- _cfsml_last_value_retrieved = NULL;
- }
+_cfsml_get_value(FILE *fd, int *line, int *hiteof) {
+ int c;
+ int mem = 64;
+ int pos = 0;
+ char *retval = (char *) sci_malloc(mem);
+
+ if (_cfsml_last_value_retrieved) {
+ free(_cfsml_last_value_retrieved);
+ _cfsml_last_value_retrieved = NULL;
+ }
- while (((c = fgetc(fd)) != EOF) && (c != '\n')) {
+ while (((c = fgetc(fd)) != EOF) && (c != '\n')) {
- if (pos == mem - 1) /* Need more memory? */
- retval = (char *) sci_realloc(retval, mem *= 2);
+ if (pos == mem - 1) /* Need more memory? */
+ retval = (char *) sci_realloc(retval, mem *= 2);
- if (pos || (!isspace(c)))
- retval[pos++] = c;
+ if (pos || (!isspace(c)))
+ retval[pos++] = c;
- }
+ }
- while ((pos > 0) && (isspace(retval[pos - 1])))
- --pos; /* Strip trailing whitespace */
+ while ((pos > 0) && (isspace(retval[pos - 1])))
+ --pos; /* Strip trailing whitespace */
- if (c == EOF)
- *hiteof = 1;
+ if (c == EOF)
+ *hiteof = 1;
- if (pos == 0) {
- _cfsml_error("Missing value in assignment at line %d\n", *line);
- free(retval);
- return NULL;
- }
+ if (pos == 0) {
+ _cfsml_error("Missing value in assignment at line %d\n", *line);
+ free(retval);
+ return NULL;
+ }
- if (c == '\n')
- ++(*line);
+ if (c == '\n')
+ ++(*line);
- if (pos == mem - 1) /* Need more memory? */
- retval = (char *) sci_realloc(retval, mem += 1);
+ if (pos == mem - 1) /* Need more memory? */
+ retval = (char *) sci_realloc(retval, mem += 1);
- retval[pos] = 0; /* Terminate string */
+ retval[pos] = 0; /* Terminate string */
#line 380 "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)
- */
+ 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 432 "savegame.cfsml"
static void
@@ -653,3474 +637,3396 @@ _cfsml_read_seg_manager_t(FILE *fh, seg_manager_t* save_struc, const char *lastv
#line 445 "savegame.cfsml"
static void
-_cfsml_write_synonym_t(FILE *fh, synonym_t* save_struc)
-{
- int min, max, i;
+_cfsml_write_synonym_t(FILE *fh, synonym_t* save_struc) {
+ int min, max, i;
#line 465 "savegame.cfsml"
- fprintf(fh, "{\n");
- fprintf(fh, "replaceant = ");
- _cfsml_write_int(fh, (int*) &(save_struc->replaceant));
- fprintf(fh, "\n");
- fprintf(fh, "replacement = ");
- _cfsml_write_int(fh, (int*) &(save_struc->replacement));
- fprintf(fh, "\n");
- fprintf(fh, "}");
+ fprintf(fh, "{\n");
+ fprintf(fh, "replaceant = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->replaceant));
+ fprintf(fh, "\n");
+ fprintf(fh, "replacement = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->replacement));
+ fprintf(fh, "\n");
+ fprintf(fh, "}");
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_synonym_t(FILE *fh, synonym_t* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
-int min, max, i;
+_cfsml_read_synonym_t(FILE *fh, synonym_t* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
+ int min, max, i;
#line 600 "savegame.cfsml"
- int assignment, closed, done;
-
- if (strcmp(lastval, "{")) {
- _cfsml_error("Reading record synonym_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, "replaceant")) {
+ int assignment, closed, done;
+
+ if (strcmp(lastval, "{")) {
+ _cfsml_error("Reading record synonym_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, "replaceant")) {
#line 750 "savegame.cfsml"
- if (_cfsml_read_int(fh, (int*) &(save_struc->replaceant), value, line, hiteof)) {
- _cfsml_error("Token expected by _cfsml_read_int() for replaceant at line %d\n", *line);
- return CFSML_FAILURE;
- }
- } else
- if (!strcmp(token, "replacement")) {
+ if (_cfsml_read_int(fh, (int*) &(save_struc->replaceant), value, line, hiteof)) {
+ _cfsml_error("Token expected by _cfsml_read_int() for replaceant at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+ } else
+ if (!strcmp(token, "replacement")) {
#line 750 "savegame.cfsml"
- if (_cfsml_read_int(fh, (int*) &(save_struc->replacement), value, line, hiteof)) {
- _cfsml_error("Token expected by _cfsml_read_int() for replacement at line %d\n", *line);
- return CFSML_FAILURE;
- }
- } else
+ if (_cfsml_read_int(fh, (int*) &(save_struc->replacement), value, line, hiteof)) {
+ _cfsml_error("Token expected by _cfsml_read_int() for replacement at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+ } else
#line 759 "savegame.cfsml"
- {
- _cfsml_error("synonym_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;
+ {
+ _cfsml_error("synonym_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 445 "savegame.cfsml"
static void
-_cfsml_write_sfx_state_t(FILE *fh, sfx_state_t* save_struc)
-{
- int min, max, i;
+_cfsml_write_sfx_state_t(FILE *fh, sfx_state_t* save_struc) {
+ int min, max, i;
#line 465 "savegame.cfsml"
- fprintf(fh, "{\n");
- fprintf(fh, "songlib = ");
- write_songlib_t(fh, (songlib_t*) &(save_struc->songlib));
- fprintf(fh, "\n");
- fprintf(fh, "}");
+ fprintf(fh, "{\n");
+ fprintf(fh, "songlib = ");
+ write_songlib_t(fh, (songlib_t*) &(save_struc->songlib));
+ fprintf(fh, "\n");
+ fprintf(fh, "}");
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_sfx_state_t(FILE *fh, sfx_state_t* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
-int min, max, i;
+_cfsml_read_sfx_state_t(FILE *fh, sfx_state_t* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
+ int min, max, i;
#line 600 "savegame.cfsml"
- int assignment, closed, done;
-
- if (strcmp(lastval, "{")) {
- _cfsml_error("Reading record sfx_state_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, "songlib")) {
+ int assignment, closed, done;
+
+ if (strcmp(lastval, "{")) {
+ _cfsml_error("Reading record sfx_state_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, "songlib")) {
#line 750 "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
+ 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 759 "savegame.cfsml"
- {
- _cfsml_error("sfx_state_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;
+ {
+ _cfsml_error("sfx_state_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 445 "savegame.cfsml"
static void
-_cfsml_write_clone_entry_t(FILE *fh, clone_entry_t* save_struc)
-{
- int min, max, i;
+_cfsml_write_clone_entry_t(FILE *fh, clone_entry_t* save_struc) {
+ int min, max, i;
#line 465 "savegame.cfsml"
- fprintf(fh, "{\n");
- fprintf(fh, "next_free = ");
- _cfsml_write_int(fh, (int*) &(save_struc->next_free));
- fprintf(fh, "\n");
- fprintf(fh, "entry = ");
- _cfsml_write_clone_t(fh, (clone_t*) &(save_struc->entry));
- fprintf(fh, "\n");
- fprintf(fh, "}");
+ fprintf(fh, "{\n");
+ fprintf(fh, "next_free = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->next_free));
+ fprintf(fh, "\n");
+ fprintf(fh, "entry = ");
+ _cfsml_write_clone_t(fh, (clone_t*) &(save_struc->entry));
+ fprintf(fh, "\n");
+ fprintf(fh, "}");
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_clone_entry_t(FILE *fh, clone_entry_t* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
-int min, max, i;
+_cfsml_read_clone_entry_t(FILE *fh, clone_entry_t* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
+ int min, max, i;
#line 600 "savegame.cfsml"
- int assignment, closed, done;
-
- if (strcmp(lastval, "{")) {
- _cfsml_error("Reading record clone_entry_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, "next_free")) {
+ int assignment, closed, done;
+
+ if (strcmp(lastval, "{")) {
+ _cfsml_error("Reading record clone_entry_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, "next_free")) {
#line 750 "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")) {
+ 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 750 "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
+ 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 759 "savegame.cfsml"
- {
- _cfsml_error("clone_entry_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;
+ {
+ _cfsml_error("clone_entry_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 445 "savegame.cfsml"
static void
-_cfsml_write_object_t(FILE *fh, object_t* save_struc)
-{
- int min, max, i;
+_cfsml_write_object_t(FILE *fh, object_t* save_struc) {
+ int min, max, i;
#line 465 "savegame.cfsml"
- fprintf(fh, "{\n");
- fprintf(fh, "flags = ");
- _cfsml_write_int(fh, (int*) &(save_struc->flags));
- fprintf(fh, "\n");
- fprintf(fh, "pos = ");
- write_reg_t(fh, (reg_t*) &(save_struc->pos));
- fprintf(fh, "\n");
- fprintf(fh, "variables_nr = ");
- _cfsml_write_int(fh, (int*) &(save_struc->variables_nr));
- fprintf(fh, "\n");
- fprintf(fh, "variable_names_nr = ");
- _cfsml_write_int(fh, (int*) &(save_struc->variable_names_nr));
- fprintf(fh, "\n");
- fprintf(fh, "methods_nr = ");
- _cfsml_write_int(fh, (int*) &(save_struc->methods_nr));
- fprintf(fh, "\n");
- fprintf(fh, "variables = ");
- min = max = save_struc->variables_nr;
- if (!save_struc->variables)
- min = max = 0; /* Don't write if it points to NULL */
+ fprintf(fh, "{\n");
+ fprintf(fh, "flags = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->flags));
+ fprintf(fh, "\n");
+ fprintf(fh, "pos = ");
+ write_reg_t(fh, (reg_t*) &(save_struc->pos));
+ fprintf(fh, "\n");
+ fprintf(fh, "variables_nr = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->variables_nr));
+ fprintf(fh, "\n");
+ fprintf(fh, "variable_names_nr = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->variable_names_nr));
+ fprintf(fh, "\n");
+ fprintf(fh, "methods_nr = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->methods_nr));
+ fprintf(fh, "\n");
+ fprintf(fh, "variables = ");
+ min = max = save_struc->variables_nr;
+ if (!save_struc->variables)
+ min = max = 0; /* Don't write if it points to NULL */
#line 491 "savegame.cfsml"
- fprintf(fh, "[%d][\n", max);
- for (i = 0; i < min; i++) {
- write_reg_t(fh, &(save_struc->variables[i]));
- fprintf(fh, "\n");
- }
- fprintf(fh, "]");
- fprintf(fh, "\n");
- fprintf(fh, "}");
+ fprintf(fh, "[%d][\n", max);
+ for (i = 0; i < min; i++) {
+ write_reg_t(fh, &(save_struc->variables[i]));
+ fprintf(fh, "\n");
+ }
+ fprintf(fh, "]");
+ fprintf(fh, "\n");
+ fprintf(fh, "}");
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_object_t(FILE *fh, object_t* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
-int min, max, i;
+_cfsml_read_object_t(FILE *fh, object_t* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
+ int min, max, i;
#line 600 "savegame.cfsml"
- int assignment, closed, done;
-
- if (strcmp(lastval, "{")) {
- _cfsml_error("Reading record object_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, "flags")) {
+ int assignment, closed, done;
+
+ if (strcmp(lastval, "{")) {
+ _cfsml_error("Reading record object_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, "flags")) {
#line 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 664 "savegame.cfsml"
- if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) {
- _cfsml_error("Opening brackets expected at line %d\n", *line);
- return CFSML_FAILURE;
- }
+ if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) {
+ _cfsml_error("Opening brackets expected at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
#line 674 "savegame.cfsml"
- /* Prepare to restore dynamic array */
- max = strtol(value + 1, NULL, 0);
- if (max < 0) {
- _cfsml_error("Invalid number of elements to allocate for dynamic array '%s' at line %d\n", token, *line);
- return CFSML_FAILURE;
- }
-
- if (max) {
- save_struc->variables = (reg_t *) sci_malloc(max * sizeof(reg_t));
+ /* Prepare to restore dynamic array */
+ max = strtol(value + 1, NULL, 0);
+ if (max < 0) {
+ _cfsml_error("Invalid number of elements to allocate for dynamic array '%s' at line %d\n", token, *line);
+ return CFSML_FAILURE;
+ }
+
+ if (max) {
+ save_struc->variables = (reg_t *) sci_malloc(max * sizeof(reg_t));
#ifdef SATISFY_PURIFY
- memset(save_struc->variables, 0, max * sizeof(reg_t));
+ memset(save_struc->variables, 0, max * sizeof(reg_t));
#endif
- _cfsml_register_pointer(save_struc->variables);
- }
- else
- save_struc->variables = NULL;
+ _cfsml_register_pointer(save_struc->variables);
+ } else
+ save_struc->variables = NULL;
#line 700 "savegame.cfsml"
- done = i = 0;
- do {
- if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
+ done = i = 0;
+ do {
+ if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
#line 708 "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 (read_reg_t(fh, &(save_struc->variables[i++]), value, line, hiteof)) {
- _cfsml_error("Token expected by read_reg_t() for variables[i++] at line %d\n", *line);
- return CFSML_FAILURE;
- }
- } else done = 1;
- } while (!done);
- save_struc->variables_nr = max ; /* Set array size accordingly */
- } else
+ _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 (read_reg_t(fh, &(save_struc->variables[i++]), value, line, hiteof)) {
+ _cfsml_error("Token expected by read_reg_t() for variables[i++] at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+ } else done = 1;
+ } while (!done);
+ save_struc->variables_nr = max ; /* Set array size accordingly */
+ } else
#line 759 "savegame.cfsml"
- {
- _cfsml_error("object_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;
+ {
+ _cfsml_error("object_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 445 "savegame.cfsml"
static void
-_cfsml_write_string(FILE *fh, char ** save_struc)
-{
+_cfsml_write_string(FILE *fh, char ** save_struc) {
#line 455 "savegame.cfsml"
- if (!(*save_struc))
- fprintf(fh, "\\null\\");
- else {
- char *token = _cfsml_mangle_string((const char *) *save_struc);
- fprintf(fh, "\"%s\"", token);
- free(token);
- }
+ if (!(*save_struc))
+ fprintf(fh, "\\null\\");
+ else {
+ char *token = _cfsml_mangle_string((const char *) * save_struc);
+ fprintf(fh, "\"%s\"", token);
+ free(token);
+ }
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_string(FILE *fh, char ** save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
+_cfsml_read_string(FILE *fh, char ** save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
#line 578 "savegame.cfsml"
- if (strcmp(lastval, "\\null\\")) { /* null pointer? */
- unsigned int length = strlen(lastval);
- if (*lastval == '"') { /* Quoted string? */
- while (lastval[length] != '"')
- --length;
-
- if (!length) { /* No matching double-quotes? */
- _cfsml_error("Unbalanced quotes at line %d\n", *line);
- return CFSML_FAILURE;
- }
-
- lastval++; /* ...and skip the opening quotes locally */
- length--;
- }
- *save_struc = _cfsml_unmangle_string(lastval, length);
- _cfsml_register_pointer(*save_struc);
- return CFSML_SUCCESS;
- } else {
- *save_struc = NULL;
- return CFSML_SUCCESS;
- }
+ if (strcmp(lastval, "\\null\\")) { /* null pointer? */
+ unsigned int length = strlen(lastval);
+ if (*lastval == '"') { /* Quoted string? */
+ while (lastval[length] != '"')
+ --length;
+
+ if (!length) { /* No matching double-quotes? */
+ _cfsml_error("Unbalanced quotes at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+
+ lastval++; /* ...and skip the opening quotes locally */
+ length--;
+ }
+ *save_struc = _cfsml_unmangle_string(lastval, length);
+ _cfsml_register_pointer(*save_struc);
+ return CFSML_SUCCESS;
+ } else {
+ *save_struc = NULL;
+ return CFSML_SUCCESS;
+ }
}
#line 445 "savegame.cfsml"
static void
-_cfsml_write_menubar_t(FILE *fh, menubar_t* save_struc)
-{
- int min, max, i;
+_cfsml_write_menubar_t(FILE *fh, menubar_t* save_struc) {
+ int min, max, i;
#line 465 "savegame.cfsml"
- fprintf(fh, "{\n");
- fprintf(fh, "menus = ");
- min = max = save_struc->menus_nr;
- if (!save_struc->menus)
- min = max = 0; /* Don't write if it points to NULL */
+ fprintf(fh, "{\n");
+ fprintf(fh, "menus = ");
+ min = max = save_struc->menus_nr;
+ if (!save_struc->menus)
+ min = max = 0; /* Don't write if it points to NULL */
#line 491 "savegame.cfsml"
- fprintf(fh, "[%d][\n", max);
- for (i = 0; i < min; i++) {
- _cfsml_write_menu_t(fh, &(save_struc->menus[i]));
- fprintf(fh, "\n");
- }
- fprintf(fh, "]");
- fprintf(fh, "\n");
- fprintf(fh, "}");
+ fprintf(fh, "[%d][\n", max);
+ for (i = 0; i < min; i++) {
+ _cfsml_write_menu_t(fh, &(save_struc->menus[i]));
+ fprintf(fh, "\n");
+ }
+ fprintf(fh, "]");
+ fprintf(fh, "\n");
+ fprintf(fh, "}");
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_menubar_t(FILE *fh, menubar_t* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
-int min, max, i;
+_cfsml_read_menubar_t(FILE *fh, menubar_t* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
+ int min, max, i;
#line 600 "savegame.cfsml"
- int assignment, closed, done;
-
- if (strcmp(lastval, "{")) {
- _cfsml_error("Reading record menubar_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, "menus")) {
+ int assignment, closed, done;
+
+ if (strcmp(lastval, "{")) {
+ _cfsml_error("Reading record menubar_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, "menus")) {
#line 664 "savegame.cfsml"
- if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) {
- _cfsml_error("Opening brackets expected at line %d\n", *line);
- return CFSML_FAILURE;
- }
+ if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) {
+ _cfsml_error("Opening brackets expected at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
#line 674 "savegame.cfsml"
- /* Prepare to restore dynamic array */
- max = strtol(value + 1, NULL, 0);
- if (max < 0) {
- _cfsml_error("Invalid number of elements to allocate for dynamic array '%s' at line %d\n", token, *line);
- return CFSML_FAILURE;
- }
-
- if (max) {
- save_struc->menus = (menu_t *) sci_malloc(max * sizeof(menu_t));
+ /* Prepare to restore dynamic array */
+ max = strtol(value + 1, NULL, 0);
+ if (max < 0) {
+ _cfsml_error("Invalid number of elements to allocate for dynamic array '%s' at line %d\n", token, *line);
+ return CFSML_FAILURE;
+ }
+
+ if (max) {
+ save_struc->menus = (menu_t *) sci_malloc(max * sizeof(menu_t));
#ifdef SATISFY_PURIFY
- memset(save_struc->menus, 0, max * sizeof(menu_t));
+ memset(save_struc->menus, 0, max * sizeof(menu_t));
#endif
- _cfsml_register_pointer(save_struc->menus);
- }
- else
- save_struc->menus = NULL;
+ _cfsml_register_pointer(save_struc->menus);
+ } else
+ save_struc->menus = NULL;
#line 700 "savegame.cfsml"
- done = i = 0;
- do {
- if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
+ done = i = 0;
+ do {
+ if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
#line 708 "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_menu_t(fh, &(save_struc->menus[i++]), value, line, hiteof)) {
- _cfsml_error("Token expected by _cfsml_read_menu_t() for menus[i++] at line %d\n", *line);
- return CFSML_FAILURE;
- }
- } else done = 1;
- } while (!done);
- save_struc->menus_nr = max ; /* Set array size accordingly */
- } else
+ _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_menu_t(fh, &(save_struc->menus[i++]), value, line, hiteof)) {
+ _cfsml_error("Token expected by _cfsml_read_menu_t() for menus[i++] at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+ } else done = 1;
+ } while (!done);
+ save_struc->menus_nr = max ; /* Set array size accordingly */
+ } else
#line 759 "savegame.cfsml"
- {
- _cfsml_error("menubar_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;
+ {
+ _cfsml_error("menubar_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 445 "savegame.cfsml"
static void
-_cfsml_write_size_t(FILE *fh, size_t* save_struc)
-{
- fprintf(fh, "%li", (long) *save_struc);
+_cfsml_write_size_t(FILE *fh, size_t* save_struc) {
+ fprintf(fh, "%li", (long) *save_struc);
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_size_t(FILE *fh, size_t* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
+_cfsml_read_size_t(FILE *fh, size_t* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
#line 565 "savegame.cfsml"
- *save_struc = strtol(lastval, &token, 0);
- if ( (*save_struc == 0) && (token == lastval) ) {
- _cfsml_error("strtol failed at line %d\n", *line);
- return CFSML_FAILURE;
- }
- if (*token != 0) {
- _cfsml_error("Non-integer encountered while parsing int value at line %d\n", *line);
- return CFSML_FAILURE;
- }
- return CFSML_SUCCESS;
+ *save_struc = strtol(lastval, &token, 0);
+ if ((*save_struc == 0) && (token == lastval)) {
+ _cfsml_error("strtol failed at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+ if (*token != 0) {
+ _cfsml_error("Non-integer encountered while parsing int value at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+ return CFSML_SUCCESS;
}
#line 445 "savegame.cfsml"
static void
-_cfsml_write_list_entry_t(FILE *fh, list_entry_t* save_struc)
-{
- int min, max, i;
+_cfsml_write_list_entry_t(FILE *fh, list_entry_t* save_struc) {
+ int min, max, i;
#line 465 "savegame.cfsml"
- fprintf(fh, "{\n");
- fprintf(fh, "next_free = ");
- _cfsml_write_int(fh, (int*) &(save_struc->next_free));
- fprintf(fh, "\n");
- fprintf(fh, "entry = ");
- _cfsml_write_list_t(fh, (list_t*) &(save_struc->entry));
- fprintf(fh, "\n");
- fprintf(fh, "}");
+ fprintf(fh, "{\n");
+ fprintf(fh, "next_free = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->next_free));
+ fprintf(fh, "\n");
+ fprintf(fh, "entry = ");
+ _cfsml_write_list_t(fh, (list_t*) &(save_struc->entry));
+ fprintf(fh, "\n");
+ fprintf(fh, "}");
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_list_entry_t(FILE *fh, list_entry_t* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
-int min, max, i;
+_cfsml_read_list_entry_t(FILE *fh, list_entry_t* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
+ int min, max, i;
#line 600 "savegame.cfsml"
- int assignment, closed, done;
-
- if (strcmp(lastval, "{")) {
- _cfsml_error("Reading record list_entry_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, "next_free")) {
+ int assignment, closed, done;
+
+ if (strcmp(lastval, "{")) {
+ _cfsml_error("Reading record list_entry_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, "next_free")) {
#line 750 "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")) {
+ 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 750 "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
+ 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 759 "savegame.cfsml"
- {
- _cfsml_error("list_entry_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;
+ {
+ _cfsml_error("list_entry_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 445 "savegame.cfsml"
static void
-_cfsml_write_int_hash_map_t(FILE *fh, int_hash_map_t* save_struc)
-{
- int min, max, i;
+_cfsml_write_int_hash_map_t(FILE *fh, int_hash_map_t* save_struc) {
+ int min, max, i;
#line 465 "savegame.cfsml"
- fprintf(fh, "{\n");
- fprintf(fh, "base_value = ");
- _cfsml_write_int(fh, (int*) &(save_struc->base_value));
- fprintf(fh, "\n");
- fprintf(fh, "nodes = ");
- min = max = DCS_INT_HASH_MAX+1;
+ fprintf(fh, "{\n");
+ fprintf(fh, "base_value = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->base_value));
+ fprintf(fh, "\n");
+ fprintf(fh, "nodes = ");
+ min = max = DCS_INT_HASH_MAX + 1;
#line 491 "savegame.cfsml"
- fprintf(fh, "[%d][\n", max);
- for (i = 0; i < min; i++) {
- write_int_hash_map_node_tp(fh, &(save_struc->nodes[i]));
- fprintf(fh, "\n");
- }
- fprintf(fh, "]");
- fprintf(fh, "\n");
- fprintf(fh, "}");
+ fprintf(fh, "[%d][\n", max);
+ for (i = 0; i < min; i++) {
+ write_int_hash_map_node_tp(fh, &(save_struc->nodes[i]));
+ fprintf(fh, "\n");
+ }
+ fprintf(fh, "]");
+ fprintf(fh, "\n");
+ fprintf(fh, "}");
}
#line 539 "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)
-{
- char *token;
-int min, max, i;
+_cfsml_read_int_hash_map_t(FILE *fh, int_hash_map_t* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
+ int min, max, i;
#line 600 "savegame.cfsml"
- int assignment, closed, done;
-
- if (strcmp(lastval, "{")) {
- _cfsml_error("Reading record int_hash_map_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, "base_value")) {
+ int assignment, closed, done;
+
+ if (strcmp(lastval, "{")) {
+ _cfsml_error("Reading record int_hash_map_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, "base_value")) {
#line 750 "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")) {
+ 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 664 "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;
+ 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 700 "savegame.cfsml"
- done = i = 0;
- do {
- if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
+ done = i = 0;
+ do {
+ if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
#line 708 "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 (read_int_hash_map_node_tp(fh, &(save_struc->nodes[i++]), value, line, hiteof)) {
- _cfsml_error("Token expected by read_int_hash_map_node_tp() for nodes[i++] at line %d\n", *line);
- return CFSML_FAILURE;
- }
- } else done = 1;
- } while (!done);
- } else
+ _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 (read_int_hash_map_node_tp(fh, &(save_struc->nodes[i++]), value, line, hiteof)) {
+ _cfsml_error("Token expected by read_int_hash_map_node_tp() for nodes[i++] at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+ } else done = 1;
+ } while (!done);
+ } else
#line 759 "savegame.cfsml"
- {
- _cfsml_error("int_hash_map_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;
+ {
+ _cfsml_error("int_hash_map_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 445 "savegame.cfsml"
static void
-_cfsml_write_gint16(FILE *fh, gint16* save_struc)
-{
- fprintf(fh, "%li", (long) *save_struc);
+_cfsml_write_gint16(FILE *fh, gint16* save_struc) {
+ fprintf(fh, "%li", (long) *save_struc);
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_gint16(FILE *fh, gint16* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
+_cfsml_read_gint16(FILE *fh, gint16* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
#line 565 "savegame.cfsml"
- *save_struc = strtol(lastval, &token, 0);
- if ( (*save_struc == 0) && (token == lastval) ) {
- _cfsml_error("strtol failed at line %d\n", *line);
- return CFSML_FAILURE;
- }
- if (*token != 0) {
- _cfsml_error("Non-integer encountered while parsing int value at line %d\n", *line);
- return CFSML_FAILURE;
- }
- return CFSML_SUCCESS;
+ *save_struc = strtol(lastval, &token, 0);
+ if ((*save_struc == 0) && (token == lastval)) {
+ _cfsml_error("strtol failed at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+ if (*token != 0) {
+ _cfsml_error("Non-integer encountered while parsing int value at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+ return CFSML_SUCCESS;
}
#line 445 "savegame.cfsml"
static void
-_cfsml_write_song_t(FILE *fh, song_t* save_struc)
-{
- int min, max, i;
+_cfsml_write_song_t(FILE *fh, song_t* save_struc) {
+ int min, max, i;
#line 465 "savegame.cfsml"
- fprintf(fh, "{\n");
- fprintf(fh, "handle = ");
- _cfsml_write_song_handle_t(fh, (song_handle_t*) &(save_struc->handle));
- fprintf(fh, "\n");
- fprintf(fh, "resource_num = ");
- _cfsml_write_int(fh, (int*) &(save_struc->resource_num));
- fprintf(fh, "\n");
- fprintf(fh, "priority = ");
- _cfsml_write_int(fh, (int*) &(save_struc->priority));
- fprintf(fh, "\n");
- fprintf(fh, "status = ");
- _cfsml_write_int(fh, (int*) &(save_struc->status));
- fprintf(fh, "\n");
- fprintf(fh, "restore_behavior = ");
- _cfsml_write_int(fh, (int*) &(save_struc->restore_behavior));
- fprintf(fh, "\n");
- fprintf(fh, "restore_time = ");
- _cfsml_write_int(fh, (int*) &(save_struc->restore_time));
- fprintf(fh, "\n");
- fprintf(fh, "loops = ");
- _cfsml_write_int(fh, (int*) &(save_struc->loops));
- fprintf(fh, "\n");
- fprintf(fh, "hold = ");
- _cfsml_write_int(fh, (int*) &(save_struc->hold));
- fprintf(fh, "\n");
- fprintf(fh, "}");
+ fprintf(fh, "{\n");
+ fprintf(fh, "handle = ");
+ _cfsml_write_song_handle_t(fh, (song_handle_t*) &(save_struc->handle));
+ fprintf(fh, "\n");
+ fprintf(fh, "resource_num = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->resource_num));
+ fprintf(fh, "\n");
+ fprintf(fh, "priority = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->priority));
+ fprintf(fh, "\n");
+ fprintf(fh, "status = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->status));
+ fprintf(fh, "\n");
+ fprintf(fh, "restore_behavior = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->restore_behavior));
+ fprintf(fh, "\n");
+ fprintf(fh, "restore_time = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->restore_time));
+ fprintf(fh, "\n");
+ fprintf(fh, "loops = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->loops));
+ fprintf(fh, "\n");
+ fprintf(fh, "hold = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->hold));
+ fprintf(fh, "\n");
+ fprintf(fh, "}");
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_song_t(FILE *fh, song_t* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
-int min, max, i;
+_cfsml_read_song_t(FILE *fh, song_t* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
+ int min, max, i;
#line 600 "savegame.cfsml"
- int assignment, closed, done;
-
- if (strcmp(lastval, "{")) {
- _cfsml_error("Reading record song_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, "handle")) {
+ int assignment, closed, done;
+
+ if (strcmp(lastval, "{")) {
+ _cfsml_error("Reading record song_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, "handle")) {
#line 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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
+ 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 759 "savegame.cfsml"
- {
- _cfsml_error("song_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;
+ {
+ _cfsml_error("song_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 445 "savegame.cfsml"
static void
-_cfsml_write_menu_item_t(FILE *fh, menu_item_t* save_struc)
-{
- int min, max, i;
+_cfsml_write_menu_item_t(FILE *fh, menu_item_t* save_struc) {
+ int min, max, i;
#line 465 "savegame.cfsml"
- fprintf(fh, "{\n");
- fprintf(fh, "type = ");
- _cfsml_write_int(fh, (int*) &(save_struc->type));
- fprintf(fh, "\n");
- fprintf(fh, "keytext = ");
- _cfsml_write_string(fh, (char **) &(save_struc->keytext));
- fprintf(fh, "\n");
- fprintf(fh, "keytext_size = ");
- _cfsml_write_int(fh, (int*) &(save_struc->keytext_size));
- fprintf(fh, "\n");
- fprintf(fh, "flags = ");
- _cfsml_write_int(fh, (int*) &(save_struc->flags));
- fprintf(fh, "\n");
- fprintf(fh, "said = ");
- min = max = MENU_SAID_SPEC_SIZE;
+ fprintf(fh, "{\n");
+ fprintf(fh, "type = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->type));
+ fprintf(fh, "\n");
+ fprintf(fh, "keytext = ");
+ _cfsml_write_string(fh, (char **) &(save_struc->keytext));
+ fprintf(fh, "\n");
+ fprintf(fh, "keytext_size = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->keytext_size));
+ fprintf(fh, "\n");
+ fprintf(fh, "flags = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->flags));
+ fprintf(fh, "\n");
+ fprintf(fh, "said = ");
+ min = max = MENU_SAID_SPEC_SIZE;
#line 491 "savegame.cfsml"
- fprintf(fh, "[%d][\n", max);
- for (i = 0; i < min; i++) {
- _cfsml_write_byte(fh, &(save_struc->said[i]));
- fprintf(fh, "\n");
- }
- fprintf(fh, "]");
- fprintf(fh, "\n");
- fprintf(fh, "said_pos = ");
- write_reg_t(fh, (reg_t*) &(save_struc->said_pos));
- fprintf(fh, "\n");
- fprintf(fh, "text = ");
- _cfsml_write_string(fh, (char **) &(save_struc->text));
- fprintf(fh, "\n");
- fprintf(fh, "text_pos = ");
- write_reg_t(fh, (reg_t*) &(save_struc->text_pos));
- fprintf(fh, "\n");
- fprintf(fh, "modifiers = ");
- _cfsml_write_int(fh, (int*) &(save_struc->modifiers));
- fprintf(fh, "\n");
- fprintf(fh, "key = ");
- _cfsml_write_int(fh, (int*) &(save_struc->key));
- fprintf(fh, "\n");
- fprintf(fh, "enabled = ");
- _cfsml_write_int(fh, (int*) &(save_struc->enabled));
- fprintf(fh, "\n");
- fprintf(fh, "tag = ");
- _cfsml_write_int(fh, (int*) &(save_struc->tag));
- fprintf(fh, "\n");
- fprintf(fh, "}");
+ fprintf(fh, "[%d][\n", max);
+ for (i = 0; i < min; i++) {
+ _cfsml_write_byte(fh, &(save_struc->said[i]));
+ fprintf(fh, "\n");
+ }
+ fprintf(fh, "]");
+ fprintf(fh, "\n");
+ fprintf(fh, "said_pos = ");
+ write_reg_t(fh, (reg_t*) &(save_struc->said_pos));
+ fprintf(fh, "\n");
+ fprintf(fh, "text = ");
+ _cfsml_write_string(fh, (char **) &(save_struc->text));
+ fprintf(fh, "\n");
+ fprintf(fh, "text_pos = ");
+ write_reg_t(fh, (reg_t*) &(save_struc->text_pos));
+ fprintf(fh, "\n");
+ fprintf(fh, "modifiers = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->modifiers));
+ fprintf(fh, "\n");
+ fprintf(fh, "key = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->key));
+ fprintf(fh, "\n");
+ fprintf(fh, "enabled = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->enabled));
+ fprintf(fh, "\n");
+ fprintf(fh, "tag = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->tag));
+ fprintf(fh, "\n");
+ fprintf(fh, "}");
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_menu_item_t(FILE *fh, menu_item_t* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
-int min, max, i;
+_cfsml_read_menu_item_t(FILE *fh, menu_item_t* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
+ int min, max, i;
#line 600 "savegame.cfsml"
- int assignment, closed, done;
-
- if (strcmp(lastval, "{")) {
- _cfsml_error("Reading record menu_item_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, "type")) {
+ int assignment, closed, done;
+
+ if (strcmp(lastval, "{")) {
+ _cfsml_error("Reading record menu_item_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, "type")) {
#line 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 664 "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;
+ 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 700 "savegame.cfsml"
- done = i = 0;
- do {
- if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
+ done = i = 0;
+ do {
+ if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
#line 708 "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_byte(fh, &(save_struc->said[i++]), value, line, hiteof)) {
- _cfsml_error("Token expected by _cfsml_read_byte() for said[i++] at line %d\n", *line);
- return CFSML_FAILURE;
- }
- } else done = 1;
- } while (!done);
- } else
- if (!strcmp(token, "said_pos")) {
+ _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_byte(fh, &(save_struc->said[i++]), value, line, hiteof)) {
+ _cfsml_error("Token expected by _cfsml_read_byte() for said[i++] at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+ } else done = 1;
+ } while (!done);
+ } else
+ if (!strcmp(token, "said_pos")) {
#line 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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
+ 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 759 "savegame.cfsml"
- {
- _cfsml_error("menu_item_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;
+ {
+ _cfsml_error("menu_item_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 445 "savegame.cfsml"
static void
-_cfsml_write_node_entry_t(FILE *fh, node_entry_t* save_struc)
-{
- int min, max, i;
+_cfsml_write_node_entry_t(FILE *fh, node_entry_t* save_struc) {
+ int min, max, i;
#line 465 "savegame.cfsml"
- fprintf(fh, "{\n");
- fprintf(fh, "next_free = ");
- _cfsml_write_int(fh, (int*) &(save_struc->next_free));
- fprintf(fh, "\n");
- fprintf(fh, "entry = ");
- _cfsml_write_node_t(fh, (node_t*) &(save_struc->entry));
- fprintf(fh, "\n");
- fprintf(fh, "}");
+ fprintf(fh, "{\n");
+ fprintf(fh, "next_free = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->next_free));
+ fprintf(fh, "\n");
+ fprintf(fh, "entry = ");
+ _cfsml_write_node_t(fh, (node_t*) &(save_struc->entry));
+ fprintf(fh, "\n");
+ fprintf(fh, "}");
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_node_entry_t(FILE *fh, node_entry_t* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
-int min, max, i;
+_cfsml_read_node_entry_t(FILE *fh, node_entry_t* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
+ int min, max, i;
#line 600 "savegame.cfsml"
- int assignment, closed, done;
-
- if (strcmp(lastval, "{")) {
- _cfsml_error("Reading record node_entry_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, "next_free")) {
+ int assignment, closed, done;
+
+ if (strcmp(lastval, "{")) {
+ _cfsml_error("Reading record node_entry_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, "next_free")) {
#line 750 "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")) {
+ 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 750 "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
+ 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 759 "savegame.cfsml"
- {
- _cfsml_error("node_entry_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;
+ {
+ _cfsml_error("node_entry_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 445 "savegame.cfsml"
static void
-_cfsml_write_seg_id_t(FILE *fh, seg_id_t* save_struc)
-{
- fprintf(fh, "%li", (long) *save_struc);
+_cfsml_write_seg_id_t(FILE *fh, seg_id_t* save_struc) {
+ fprintf(fh, "%li", (long) *save_struc);
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_seg_id_t(FILE *fh, seg_id_t* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
+_cfsml_read_seg_id_t(FILE *fh, seg_id_t* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
#line 565 "savegame.cfsml"
- *save_struc = strtol(lastval, &token, 0);
- if ( (*save_struc == 0) && (token == lastval) ) {
- _cfsml_error("strtol failed at line %d\n", *line);
- return CFSML_FAILURE;
- }
- if (*token != 0) {
- _cfsml_error("Non-integer encountered while parsing int value at line %d\n", *line);
- return CFSML_FAILURE;
- }
- return CFSML_SUCCESS;
+ *save_struc = strtol(lastval, &token, 0);
+ if ((*save_struc == 0) && (token == lastval)) {
+ _cfsml_error("strtol failed at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+ if (*token != 0) {
+ _cfsml_error("Non-integer encountered while parsing int value at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+ return CFSML_SUCCESS;
}
#line 445 "savegame.cfsml"
static void
-_cfsml_write_dynmem_t(FILE *fh, dynmem_t* save_struc)
-{
- int min, max, i;
+_cfsml_write_dynmem_t(FILE *fh, dynmem_t* save_struc) {
+ int min, max, i;
#line 465 "savegame.cfsml"
- fprintf(fh, "{\n");
- fprintf(fh, "size = ");
- _cfsml_write_int(fh, (int*) &(save_struc->size));
- fprintf(fh, "\n");
- fprintf(fh, "description = ");
- _cfsml_write_string(fh, (char **) &(save_struc->description));
- fprintf(fh, "\n");
- fprintf(fh, "buf = ");
- min = max = save_struc->size;
- if (!save_struc->buf)
- min = max = 0; /* Don't write if it points to NULL */
+ fprintf(fh, "{\n");
+ fprintf(fh, "size = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->size));
+ fprintf(fh, "\n");
+ fprintf(fh, "description = ");
+ _cfsml_write_string(fh, (char **) &(save_struc->description));
+ fprintf(fh, "\n");
+ fprintf(fh, "buf = ");
+ min = max = save_struc->size;
+ if (!save_struc->buf)
+ min = max = 0; /* Don't write if it points to NULL */
#line 491 "savegame.cfsml"
- fprintf(fh, "[%d][\n", max);
- for (i = 0; i < min; i++) {
- _cfsml_write_byte(fh, &(save_struc->buf[i]));
- fprintf(fh, "\n");
- }
- fprintf(fh, "]");
- fprintf(fh, "\n");
- fprintf(fh, "}");
+ fprintf(fh, "[%d][\n", max);
+ for (i = 0; i < min; i++) {
+ _cfsml_write_byte(fh, &(save_struc->buf[i]));
+ fprintf(fh, "\n");
+ }
+ fprintf(fh, "]");
+ fprintf(fh, "\n");
+ fprintf(fh, "}");
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_dynmem_t(FILE *fh, dynmem_t* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
-int min, max, i;
+_cfsml_read_dynmem_t(FILE *fh, dynmem_t* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
+ int min, max, i;
#line 600 "savegame.cfsml"
- int assignment, closed, done;
-
- if (strcmp(lastval, "{")) {
- _cfsml_error("Reading record dynmem_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, "size")) {
+ int assignment, closed, done;
+
+ if (strcmp(lastval, "{")) {
+ _cfsml_error("Reading record dynmem_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, "size")) {
#line 750 "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")) {
+ 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 750 "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")) {
+ 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 664 "savegame.cfsml"
- if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) {
- _cfsml_error("Opening brackets expected at line %d\n", *line);
- return CFSML_FAILURE;
- }
+ if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) {
+ _cfsml_error("Opening brackets expected at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
#line 674 "savegame.cfsml"
- /* Prepare to restore dynamic array */
- max = strtol(value + 1, NULL, 0);
- if (max < 0) {
- _cfsml_error("Invalid number of elements to allocate for dynamic array '%s' at line %d\n", token, *line);
- return CFSML_FAILURE;
- }
-
- if (max) {
- save_struc->buf = (byte *) sci_malloc(max * sizeof(byte));
+ /* Prepare to restore dynamic array */
+ max = strtol(value + 1, NULL, 0);
+ if (max < 0) {
+ _cfsml_error("Invalid number of elements to allocate for dynamic array '%s' at line %d\n", token, *line);
+ return CFSML_FAILURE;
+ }
+
+ if (max) {
+ save_struc->buf = (byte *) sci_malloc(max * sizeof(byte));
#ifdef SATISFY_PURIFY
- memset(save_struc->buf, 0, max * sizeof(byte));
+ memset(save_struc->buf, 0, max * sizeof(byte));
#endif
- _cfsml_register_pointer(save_struc->buf);
- }
- else
- save_struc->buf = NULL;
+ _cfsml_register_pointer(save_struc->buf);
+ } else
+ save_struc->buf = NULL;
#line 700 "savegame.cfsml"
- done = i = 0;
- do {
- if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
+ done = i = 0;
+ do {
+ if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
#line 708 "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_byte(fh, &(save_struc->buf[i++]), value, line, hiteof)) {
- _cfsml_error("Token expected by _cfsml_read_byte() for buf[i++] at line %d\n", *line);
- return CFSML_FAILURE;
- }
- } else done = 1;
- } while (!done);
- save_struc->size = max ; /* Set array size accordingly */
- } else
+ _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_byte(fh, &(save_struc->buf[i++]), value, line, hiteof)) {
+ _cfsml_error("Token expected by _cfsml_read_byte() for buf[i++] at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+ } else done = 1;
+ } while (!done);
+ save_struc->size = max ; /* Set array size accordingly */
+ } else
#line 759 "savegame.cfsml"
- {
- _cfsml_error("dynmem_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;
+ {
+ _cfsml_error("dynmem_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 445 "savegame.cfsml"
static void
-_cfsml_write_local_variables_t(FILE *fh, local_variables_t* save_struc)
-{
- int min, max, i;
+_cfsml_write_local_variables_t(FILE *fh, local_variables_t* save_struc) {
+ int min, max, i;
#line 465 "savegame.cfsml"
- fprintf(fh, "{\n");
- fprintf(fh, "script_id = ");
- _cfsml_write_int(fh, (int*) &(save_struc->script_id));
- fprintf(fh, "\n");
- fprintf(fh, "nr = ");
- _cfsml_write_int(fh, (int*) &(save_struc->nr));
- fprintf(fh, "\n");
- fprintf(fh, "locals = ");
- min = max = save_struc->nr;
- if (!save_struc->locals)
- min = max = 0; /* Don't write if it points to NULL */
+ fprintf(fh, "{\n");
+ fprintf(fh, "script_id = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->script_id));
+ fprintf(fh, "\n");
+ fprintf(fh, "nr = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->nr));
+ fprintf(fh, "\n");
+ fprintf(fh, "locals = ");
+ min = max = save_struc->nr;
+ if (!save_struc->locals)
+ min = max = 0; /* Don't write if it points to NULL */
#line 491 "savegame.cfsml"
- fprintf(fh, "[%d][\n", max);
- for (i = 0; i < min; i++) {
- write_reg_t(fh, &(save_struc->locals[i]));
- fprintf(fh, "\n");
- }
- fprintf(fh, "]");
- fprintf(fh, "\n");
- fprintf(fh, "}");
+ fprintf(fh, "[%d][\n", max);
+ for (i = 0; i < min; i++) {
+ write_reg_t(fh, &(save_struc->locals[i]));
+ fprintf(fh, "\n");
+ }
+ fprintf(fh, "]");
+ fprintf(fh, "\n");
+ fprintf(fh, "}");
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_local_variables_t(FILE *fh, local_variables_t* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
-int min, max, i;
+_cfsml_read_local_variables_t(FILE *fh, local_variables_t* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
+ int min, max, i;
#line 600 "savegame.cfsml"
- int assignment, closed, done;
-
- if (strcmp(lastval, "{")) {
- _cfsml_error("Reading record local_variables_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, "script_id")) {
+ int assignment, closed, done;
+
+ if (strcmp(lastval, "{")) {
+ _cfsml_error("Reading record local_variables_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, "script_id")) {
#line 750 "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")) {
+ 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 750 "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")) {
+ 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 664 "savegame.cfsml"
- if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) {
- _cfsml_error("Opening brackets expected at line %d\n", *line);
- return CFSML_FAILURE;
- }
+ if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) {
+ _cfsml_error("Opening brackets expected at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
#line 674 "savegame.cfsml"
- /* Prepare to restore dynamic array */
- max = strtol(value + 1, NULL, 0);
- if (max < 0) {
- _cfsml_error("Invalid number of elements to allocate for dynamic array '%s' at line %d\n", token, *line);
- return CFSML_FAILURE;
- }
-
- if (max) {
- save_struc->locals = (reg_t *) sci_malloc(max * sizeof(reg_t));
+ /* Prepare to restore dynamic array */
+ max = strtol(value + 1, NULL, 0);
+ if (max < 0) {
+ _cfsml_error("Invalid number of elements to allocate for dynamic array '%s' at line %d\n", token, *line);
+ return CFSML_FAILURE;
+ }
+
+ if (max) {
+ save_struc->locals = (reg_t *) sci_malloc(max * sizeof(reg_t));
#ifdef SATISFY_PURIFY
- memset(save_struc->locals, 0, max * sizeof(reg_t));
+ memset(save_struc->locals, 0, max * sizeof(reg_t));
#endif
- _cfsml_register_pointer(save_struc->locals);
- }
- else
- save_struc->locals = NULL;
+ _cfsml_register_pointer(save_struc->locals);
+ } else
+ save_struc->locals = NULL;
#line 700 "savegame.cfsml"
- done = i = 0;
- do {
- if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
+ done = i = 0;
+ do {
+ if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
#line 708 "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 (read_reg_t(fh, &(save_struc->locals[i++]), value, line, hiteof)) {
- _cfsml_error("Token expected by read_reg_t() for locals[i++] at line %d\n", *line);
- return CFSML_FAILURE;
- }
- } else done = 1;
- } while (!done);
- save_struc->nr = max ; /* Set array size accordingly */
- } else
+ _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 (read_reg_t(fh, &(save_struc->locals[i++]), value, line, hiteof)) {
+ _cfsml_error("Token expected by read_reg_t() for locals[i++] at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+ } else done = 1;
+ } while (!done);
+ save_struc->nr = max ; /* Set array size accordingly */
+ } else
#line 759 "savegame.cfsml"
- {
- _cfsml_error("local_variables_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;
+ {
+ _cfsml_error("local_variables_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 445 "savegame.cfsml"
static void
-_cfsml_write_state_t(FILE *fh, state_t* save_struc)
-{
- int min, max, i;
+_cfsml_write_state_t(FILE *fh, state_t* save_struc) {
+ int min, max, i;
#line 465 "savegame.cfsml"
- fprintf(fh, "{\n");
- fprintf(fh, "savegame_version = ");
- _cfsml_write_int(fh, (int*) &(save_struc->savegame_version));
- fprintf(fh, "\n");
- fprintf(fh, "game_version = ");
- _cfsml_write_string(fh, (char **) &(save_struc->game_version));
- fprintf(fh, "\n");
- fprintf(fh, "version = ");
- write_sci_version(fh, (sci_version_t*) &(save_struc->version));
- fprintf(fh, "\n");
- fprintf(fh, "menubar = ");
- write_menubar_tp(fh, (menubar_t **) &(save_struc->menubar));
- fprintf(fh, "\n");
- fprintf(fh, "status_bar_foreground = ");
- _cfsml_write_int(fh, (int*) &(save_struc->status_bar_foreground));
- fprintf(fh, "\n");
- fprintf(fh, "status_bar_background = ");
- _cfsml_write_int(fh, (int*) &(save_struc->status_bar_background));
- fprintf(fh, "\n");
- fprintf(fh, "seg_manager = ");
- _cfsml_write_seg_manager_t(fh, (seg_manager_t*) &(save_struc->seg_manager));
- fprintf(fh, "\n");
- fprintf(fh, "classtable_size = ");
- _cfsml_write_int(fh, (int*) &(save_struc->classtable_size));
- fprintf(fh, "\n");
- fprintf(fh, "classtable = ");
- min = max = save_struc->classtable_size;
- if (!save_struc->classtable)
- min = max = 0; /* Don't write if it points to NULL */
+ fprintf(fh, "{\n");
+ fprintf(fh, "savegame_version = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->savegame_version));
+ fprintf(fh, "\n");
+ fprintf(fh, "game_version = ");
+ _cfsml_write_string(fh, (char **) &(save_struc->game_version));
+ fprintf(fh, "\n");
+ fprintf(fh, "version = ");
+ write_sci_version(fh, (sci_version_t*) &(save_struc->version));
+ fprintf(fh, "\n");
+ fprintf(fh, "menubar = ");
+ write_menubar_tp(fh, (menubar_t **) &(save_struc->menubar));
+ fprintf(fh, "\n");
+ fprintf(fh, "status_bar_foreground = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->status_bar_foreground));
+ fprintf(fh, "\n");
+ fprintf(fh, "status_bar_background = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->status_bar_background));
+ fprintf(fh, "\n");
+ fprintf(fh, "seg_manager = ");
+ _cfsml_write_seg_manager_t(fh, (seg_manager_t*) &(save_struc->seg_manager));
+ fprintf(fh, "\n");
+ fprintf(fh, "classtable_size = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->classtable_size));
+ fprintf(fh, "\n");
+ fprintf(fh, "classtable = ");
+ min = max = save_struc->classtable_size;
+ if (!save_struc->classtable)
+ min = max = 0; /* Don't write if it points to NULL */
#line 491 "savegame.cfsml"
- fprintf(fh, "[%d][\n", max);
- for (i = 0; i < min; i++) {
- _cfsml_write_class_t(fh, &(save_struc->classtable[i]));
- fprintf(fh, "\n");
- }
- fprintf(fh, "]");
- fprintf(fh, "\n");
- fprintf(fh, "sound = ");
- _cfsml_write_sfx_state_t(fh, (sfx_state_t*) &(save_struc->sound));
- fprintf(fh, "\n");
- fprintf(fh, "}");
+ fprintf(fh, "[%d][\n", max);
+ for (i = 0; i < min; i++) {
+ _cfsml_write_class_t(fh, &(save_struc->classtable[i]));
+ fprintf(fh, "\n");
+ }
+ fprintf(fh, "]");
+ fprintf(fh, "\n");
+ fprintf(fh, "sound = ");
+ _cfsml_write_sfx_state_t(fh, (sfx_state_t*) &(save_struc->sound));
+ fprintf(fh, "\n");
+ fprintf(fh, "}");
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_state_t(FILE *fh, state_t* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
-int min, max, i;
+_cfsml_read_state_t(FILE *fh, state_t* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
+ int min, max, i;
#line 600 "savegame.cfsml"
- int assignment, closed, done;
-
- if (strcmp(lastval, "{")) {
- _cfsml_error("Reading record state_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, "savegame_version")) {
+ int assignment, closed, done;
+
+ if (strcmp(lastval, "{")) {
+ _cfsml_error("Reading record state_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, "savegame_version")) {
#line 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 664 "savegame.cfsml"
- if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) {
- _cfsml_error("Opening brackets expected at line %d\n", *line);
- return CFSML_FAILURE;
- }
+ if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) {
+ _cfsml_error("Opening brackets expected at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
#line 674 "savegame.cfsml"
- /* Prepare to restore dynamic array */
- max = strtol(value + 1, NULL, 0);
- if (max < 0) {
- _cfsml_error("Invalid number of elements to allocate for dynamic array '%s' at line %d\n", token, *line);
- return CFSML_FAILURE;
- }
-
- if (max) {
- save_struc->classtable = (class_t *) sci_malloc(max * sizeof(class_t));
+ /* Prepare to restore dynamic array */
+ max = strtol(value + 1, NULL, 0);
+ if (max < 0) {
+ _cfsml_error("Invalid number of elements to allocate for dynamic array '%s' at line %d\n", token, *line);
+ return CFSML_FAILURE;
+ }
+
+ if (max) {
+ save_struc->classtable = (class_t *) sci_malloc(max * sizeof(class_t));
#ifdef SATISFY_PURIFY
- memset(save_struc->classtable, 0, max * sizeof(class_t));
+ memset(save_struc->classtable, 0, max * sizeof(class_t));
#endif
- _cfsml_register_pointer(save_struc->classtable);
- }
- else
- save_struc->classtable = NULL;
+ _cfsml_register_pointer(save_struc->classtable);
+ } else
+ save_struc->classtable = NULL;
#line 700 "savegame.cfsml"
- done = i = 0;
- do {
- if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
+ done = i = 0;
+ do {
+ if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
#line 708 "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_class_t(fh, &(save_struc->classtable[i++]), value, line, hiteof)) {
- _cfsml_error("Token expected by _cfsml_read_class_t() for classtable[i++] at line %d\n", *line);
- return CFSML_FAILURE;
- }
- } else done = 1;
- } while (!done);
- save_struc->classtable_size = max ; /* Set array size accordingly */
- } else
- if (!strcmp(token, "sound")) {
+ _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_class_t(fh, &(save_struc->classtable[i++]), value, line, hiteof)) {
+ _cfsml_error("Token expected by _cfsml_read_class_t() for classtable[i++] at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+ } else done = 1;
+ } while (!done);
+ save_struc->classtable_size = max ; /* Set array size accordingly */
+ } else
+ if (!strcmp(token, "sound")) {
#line 750 "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
+ 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 759 "savegame.cfsml"
- {
- _cfsml_error("state_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;
+ {
+ _cfsml_error("state_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 445 "savegame.cfsml"
static void
-_cfsml_write_node_table_t(FILE *fh, node_table_t* save_struc)
-{
- int min, max, i;
+_cfsml_write_node_table_t(FILE *fh, node_table_t* save_struc) {
+ int min, max, i;
#line 465 "savegame.cfsml"
- fprintf(fh, "{\n");
- fprintf(fh, "entries_nr = ");
- _cfsml_write_int(fh, (int*) &(save_struc->entries_nr));
- fprintf(fh, "\n");
- fprintf(fh, "first_free = ");
- _cfsml_write_int(fh, (int*) &(save_struc->first_free));
- fprintf(fh, "\n");
- fprintf(fh, "entries_used = ");
- _cfsml_write_int(fh, (int*) &(save_struc->entries_used));
- fprintf(fh, "\n");
- fprintf(fh, "max_entry = ");
- _cfsml_write_int(fh, (int*) &(save_struc->max_entry));
- fprintf(fh, "\n");
- fprintf(fh, "table = ");
- min = max = save_struc->entries_nr;
- if (!save_struc->table)
- min = max = 0; /* Don't write if it points to NULL */
+ fprintf(fh, "{\n");
+ fprintf(fh, "entries_nr = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->entries_nr));
+ fprintf(fh, "\n");
+ fprintf(fh, "first_free = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->first_free));
+ fprintf(fh, "\n");
+ fprintf(fh, "entries_used = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->entries_used));
+ fprintf(fh, "\n");
+ fprintf(fh, "max_entry = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->max_entry));
+ fprintf(fh, "\n");
+ fprintf(fh, "table = ");
+ min = max = save_struc->entries_nr;
+ if (!save_struc->table)
+ min = max = 0; /* Don't write if it points to NULL */
#line 491 "savegame.cfsml"
- fprintf(fh, "[%d][\n", max);
- for (i = 0; i < min; i++) {
- _cfsml_write_node_entry_t(fh, &(save_struc->table[i]));
- fprintf(fh, "\n");
- }
- fprintf(fh, "]");
- fprintf(fh, "\n");
- fprintf(fh, "}");
+ fprintf(fh, "[%d][\n", max);
+ for (i = 0; i < min; i++) {
+ _cfsml_write_node_entry_t(fh, &(save_struc->table[i]));
+ fprintf(fh, "\n");
+ }
+ fprintf(fh, "]");
+ fprintf(fh, "\n");
+ fprintf(fh, "}");
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_node_table_t(FILE *fh, node_table_t* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
-int min, max, i;
+_cfsml_read_node_table_t(FILE *fh, node_table_t* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
+ int min, max, i;
#line 600 "savegame.cfsml"
- int assignment, closed, done;
-
- if (strcmp(lastval, "{")) {
- _cfsml_error("Reading record node_table_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, "entries_nr")) {
+ int assignment, closed, done;
+
+ if (strcmp(lastval, "{")) {
+ _cfsml_error("Reading record node_table_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, "entries_nr")) {
#line 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 664 "savegame.cfsml"
- if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) {
- _cfsml_error("Opening brackets expected at line %d\n", *line);
- return CFSML_FAILURE;
- }
+ if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) {
+ _cfsml_error("Opening brackets expected at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
#line 674 "savegame.cfsml"
- /* Prepare to restore dynamic array */
- max = strtol(value + 1, NULL, 0);
- if (max < 0) {
- _cfsml_error("Invalid number of elements to allocate for dynamic array '%s' at line %d\n", token, *line);
- return CFSML_FAILURE;
- }
-
- if (max) {
- save_struc->table = (node_entry_t *) sci_malloc(max * sizeof(node_entry_t));
+ /* Prepare to restore dynamic array */
+ max = strtol(value + 1, NULL, 0);
+ if (max < 0) {
+ _cfsml_error("Invalid number of elements to allocate for dynamic array '%s' at line %d\n", token, *line);
+ return CFSML_FAILURE;
+ }
+
+ if (max) {
+ save_struc->table = (node_entry_t *) sci_malloc(max * sizeof(node_entry_t));
#ifdef SATISFY_PURIFY
- memset(save_struc->table, 0, max * sizeof(node_entry_t));
+ memset(save_struc->table, 0, max * sizeof(node_entry_t));
#endif
- _cfsml_register_pointer(save_struc->table);
- }
- else
- save_struc->table = NULL;
+ _cfsml_register_pointer(save_struc->table);
+ } else
+ save_struc->table = NULL;
#line 700 "savegame.cfsml"
- done = i = 0;
- do {
- if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
+ done = i = 0;
+ do {
+ if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
#line 708 "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_node_entry_t(fh, &(save_struc->table[i++]), value, line, hiteof)) {
- _cfsml_error("Token expected by _cfsml_read_node_entry_t() for table[i++] at line %d\n", *line);
- return CFSML_FAILURE;
- }
- } else done = 1;
- } while (!done);
- save_struc->entries_nr = max ; /* Set array size accordingly */
- } else
+ _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_node_entry_t(fh, &(save_struc->table[i++]), value, line, hiteof)) {
+ _cfsml_error("Token expected by _cfsml_read_node_entry_t() for table[i++] at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+ } else done = 1;
+ } while (!done);
+ save_struc->entries_nr = max ; /* Set array size accordingly */
+ } else
#line 759 "savegame.cfsml"
- {
- _cfsml_error("node_table_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;
+ {
+ _cfsml_error("node_table_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 445 "savegame.cfsml"
static void
-_cfsml_write_sys_strings_t(FILE *fh, sys_strings_t* save_struc)
-{
- int min, max, i;
+_cfsml_write_sys_strings_t(FILE *fh, sys_strings_t* save_struc) {
+ int min, max, i;
#line 465 "savegame.cfsml"
- fprintf(fh, "{\n");
- fprintf(fh, "strings = ");
- min = max = SYS_STRINGS_MAX;
+ fprintf(fh, "{\n");
+ fprintf(fh, "strings = ");
+ min = max = SYS_STRINGS_MAX;
#line 491 "savegame.cfsml"
- fprintf(fh, "[%d][\n", max);
- for (i = 0; i < min; i++) {
- _cfsml_write_sys_string_t(fh, &(save_struc->strings[i]));
- fprintf(fh, "\n");
- }
- fprintf(fh, "]");
- fprintf(fh, "\n");
- fprintf(fh, "}");
+ fprintf(fh, "[%d][\n", max);
+ for (i = 0; i < min; i++) {
+ _cfsml_write_sys_string_t(fh, &(save_struc->strings[i]));
+ fprintf(fh, "\n");
+ }
+ fprintf(fh, "]");
+ fprintf(fh, "\n");
+ fprintf(fh, "}");
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_sys_strings_t(FILE *fh, sys_strings_t* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
-int min, max, i;
+_cfsml_read_sys_strings_t(FILE *fh, sys_strings_t* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
+ int min, max, i;
#line 600 "savegame.cfsml"
- int assignment, closed, done;
-
- if (strcmp(lastval, "{")) {
- _cfsml_error("Reading record sys_strings_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, "strings")) {
+ int assignment, closed, done;
+
+ if (strcmp(lastval, "{")) {
+ _cfsml_error("Reading record sys_strings_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, "strings")) {
#line 664 "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;
+ 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 700 "savegame.cfsml"
- done = i = 0;
- do {
- if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
+ done = i = 0;
+ do {
+ if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
#line 708 "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);
- return CFSML_FAILURE;
- }
- } else done = 1;
- } while (!done);
- } else
+ _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);
+ return CFSML_FAILURE;
+ }
+ } else done = 1;
+ } while (!done);
+ } else
#line 759 "savegame.cfsml"
- {
- _cfsml_error("sys_strings_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;
+ {
+ _cfsml_error("sys_strings_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 445 "savegame.cfsml"
static void
-_cfsml_write_byte(FILE *fh, byte* save_struc)
-{
- fprintf(fh, "%li", (long) *save_struc);
+_cfsml_write_byte(FILE *fh, byte* save_struc) {
+ fprintf(fh, "%li", (long) *save_struc);
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_byte(FILE *fh, byte* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
+_cfsml_read_byte(FILE *fh, byte* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
#line 565 "savegame.cfsml"
- *save_struc = strtol(lastval, &token, 0);
- if ( (*save_struc == 0) && (token == lastval) ) {
- _cfsml_error("strtol failed at line %d\n", *line);
- return CFSML_FAILURE;
- }
- if (*token != 0) {
- _cfsml_error("Non-integer encountered while parsing int value at line %d\n", *line);
- return CFSML_FAILURE;
- }
- return CFSML_SUCCESS;
+ *save_struc = strtol(lastval, &token, 0);
+ if ((*save_struc == 0) && (token == lastval)) {
+ _cfsml_error("strtol failed at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+ if (*token != 0) {
+ _cfsml_error("Non-integer encountered while parsing int value at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+ return CFSML_SUCCESS;
}
#line 445 "savegame.cfsml"
static void
-_cfsml_write_node_t(FILE *fh, node_t* save_struc)
-{
- int min, max, i;
+_cfsml_write_node_t(FILE *fh, node_t* save_struc) {
+ int min, max, i;
#line 465 "savegame.cfsml"
- fprintf(fh, "{\n");
- fprintf(fh, "pred = ");
- write_reg_t(fh, (reg_t*) &(save_struc->pred));
- fprintf(fh, "\n");
- fprintf(fh, "succ = ");
- write_reg_t(fh, (reg_t*) &(save_struc->succ));
- fprintf(fh, "\n");
- fprintf(fh, "key = ");
- write_reg_t(fh, (reg_t*) &(save_struc->key));
- fprintf(fh, "\n");
- fprintf(fh, "value = ");
- write_reg_t(fh, (reg_t*) &(save_struc->value));
- fprintf(fh, "\n");
- fprintf(fh, "}");
+ fprintf(fh, "{\n");
+ fprintf(fh, "pred = ");
+ write_reg_t(fh, (reg_t*) &(save_struc->pred));
+ fprintf(fh, "\n");
+ fprintf(fh, "succ = ");
+ write_reg_t(fh, (reg_t*) &(save_struc->succ));
+ fprintf(fh, "\n");
+ fprintf(fh, "key = ");
+ write_reg_t(fh, (reg_t*) &(save_struc->key));
+ fprintf(fh, "\n");
+ fprintf(fh, "value = ");
+ write_reg_t(fh, (reg_t*) &(save_struc->value));
+ fprintf(fh, "\n");
+ fprintf(fh, "}");
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_node_t(FILE *fh, node_t* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
-int min, max, i;
+_cfsml_read_node_t(FILE *fh, node_t* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
+ int min, max, i;
#line 600 "savegame.cfsml"
- int assignment, closed, done;
-
- if (strcmp(lastval, "{")) {
- _cfsml_error("Reading record node_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, "pred")) {
+ int assignment, closed, done;
+
+ if (strcmp(lastval, "{")) {
+ _cfsml_error("Reading record node_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, "pred")) {
#line 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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
+ 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 759 "savegame.cfsml"
- {
- _cfsml_error("node_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;
+ {
+ _cfsml_error("node_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 445 "savegame.cfsml"
static void
-_cfsml_write_list_table_t(FILE *fh, list_table_t* save_struc)
-{
- int min, max, i;
+_cfsml_write_list_table_t(FILE *fh, list_table_t* save_struc) {
+ int min, max, i;
#line 465 "savegame.cfsml"
- fprintf(fh, "{\n");
- fprintf(fh, "entries_nr = ");
- _cfsml_write_int(fh, (int*) &(save_struc->entries_nr));
- fprintf(fh, "\n");
- fprintf(fh, "first_free = ");
- _cfsml_write_int(fh, (int*) &(save_struc->first_free));
- fprintf(fh, "\n");
- fprintf(fh, "entries_used = ");
- _cfsml_write_int(fh, (int*) &(save_struc->entries_used));
- fprintf(fh, "\n");
- fprintf(fh, "max_entry = ");
- _cfsml_write_int(fh, (int*) &(save_struc->max_entry));
- fprintf(fh, "\n");
- fprintf(fh, "table = ");
- min = max = save_struc->entries_nr;
- if (!save_struc->table)
- min = max = 0; /* Don't write if it points to NULL */
+ fprintf(fh, "{\n");
+ fprintf(fh, "entries_nr = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->entries_nr));
+ fprintf(fh, "\n");
+ fprintf(fh, "first_free = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->first_free));
+ fprintf(fh, "\n");
+ fprintf(fh, "entries_used = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->entries_used));
+ fprintf(fh, "\n");
+ fprintf(fh, "max_entry = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->max_entry));
+ fprintf(fh, "\n");
+ fprintf(fh, "table = ");
+ min = max = save_struc->entries_nr;
+ if (!save_struc->table)
+ min = max = 0; /* Don't write if it points to NULL */
#line 491 "savegame.cfsml"
- fprintf(fh, "[%d][\n", max);
- for (i = 0; i < min; i++) {
- _cfsml_write_list_entry_t(fh, &(save_struc->table[i]));
- fprintf(fh, "\n");
- }
- fprintf(fh, "]");
- fprintf(fh, "\n");
- fprintf(fh, "}");
+ fprintf(fh, "[%d][\n", max);
+ for (i = 0; i < min; i++) {
+ _cfsml_write_list_entry_t(fh, &(save_struc->table[i]));
+ fprintf(fh, "\n");
+ }
+ fprintf(fh, "]");
+ fprintf(fh, "\n");
+ fprintf(fh, "}");
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_list_table_t(FILE *fh, list_table_t* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
-int min, max, i;
+_cfsml_read_list_table_t(FILE *fh, list_table_t* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
+ int min, max, i;
#line 600 "savegame.cfsml"
- int assignment, closed, done;
-
- if (strcmp(lastval, "{")) {
- _cfsml_error("Reading record list_table_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, "entries_nr")) {
+ int assignment, closed, done;
+
+ if (strcmp(lastval, "{")) {
+ _cfsml_error("Reading record list_table_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, "entries_nr")) {
#line 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 664 "savegame.cfsml"
- if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) {
- _cfsml_error("Opening brackets expected at line %d\n", *line);
- return CFSML_FAILURE;
- }
+ if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) {
+ _cfsml_error("Opening brackets expected at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
#line 674 "savegame.cfsml"
- /* Prepare to restore dynamic array */
- max = strtol(value + 1, NULL, 0);
- if (max < 0) {
- _cfsml_error("Invalid number of elements to allocate for dynamic array '%s' at line %d\n", token, *line);
- return CFSML_FAILURE;
- }
-
- if (max) {
- save_struc->table = (list_entry_t *) sci_malloc(max * sizeof(list_entry_t));
+ /* Prepare to restore dynamic array */
+ max = strtol(value + 1, NULL, 0);
+ if (max < 0) {
+ _cfsml_error("Invalid number of elements to allocate for dynamic array '%s' at line %d\n", token, *line);
+ return CFSML_FAILURE;
+ }
+
+ if (max) {
+ save_struc->table = (list_entry_t *) sci_malloc(max * sizeof(list_entry_t));
#ifdef SATISFY_PURIFY
- memset(save_struc->table, 0, max * sizeof(list_entry_t));
+ memset(save_struc->table, 0, max * sizeof(list_entry_t));
#endif
- _cfsml_register_pointer(save_struc->table);
- }
- else
- save_struc->table = NULL;
+ _cfsml_register_pointer(save_struc->table);
+ } else
+ save_struc->table = NULL;
#line 700 "savegame.cfsml"
- done = i = 0;
- do {
- if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
+ done = i = 0;
+ do {
+ if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
#line 708 "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_list_entry_t(fh, &(save_struc->table[i++]), value, line, hiteof)) {
- _cfsml_error("Token expected by _cfsml_read_list_entry_t() for table[i++] at line %d\n", *line);
- return CFSML_FAILURE;
- }
- } else done = 1;
- } while (!done);
- save_struc->entries_nr = max ; /* Set array size accordingly */
- } else
+ _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_list_entry_t(fh, &(save_struc->table[i++]), value, line, hiteof)) {
+ _cfsml_error("Token expected by _cfsml_read_list_entry_t() for table[i++] at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+ } else done = 1;
+ } while (!done);
+ save_struc->entries_nr = max ; /* Set array size accordingly */
+ } else
#line 759 "savegame.cfsml"
- {
- _cfsml_error("list_table_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;
+ {
+ _cfsml_error("list_table_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 445 "savegame.cfsml"
static void
-_cfsml_write_class_t(FILE *fh, class_t* save_struc)
-{
- int min, max, i;
+_cfsml_write_class_t(FILE *fh, class_t* save_struc) {
+ int min, max, i;
#line 465 "savegame.cfsml"
- fprintf(fh, "{\n");
- fprintf(fh, "script = ");
- _cfsml_write_int(fh, (int*) &(save_struc->script));
- fprintf(fh, "\n");
- fprintf(fh, "reg = ");
- write_reg_t(fh, (reg_t*) &(save_struc->reg));
- fprintf(fh, "\n");
- fprintf(fh, "}");
+ fprintf(fh, "{\n");
+ fprintf(fh, "script = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->script));
+ fprintf(fh, "\n");
+ fprintf(fh, "reg = ");
+ write_reg_t(fh, (reg_t*) &(save_struc->reg));
+ fprintf(fh, "\n");
+ fprintf(fh, "}");
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_class_t(FILE *fh, class_t* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
-int min, max, i;
+_cfsml_read_class_t(FILE *fh, class_t* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
+ int min, max, i;
#line 600 "savegame.cfsml"
- int assignment, closed, done;
-
- if (strcmp(lastval, "{")) {
- _cfsml_error("Reading record class_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, "script")) {
+ int assignment, closed, done;
+
+ if (strcmp(lastval, "{")) {
+ _cfsml_error("Reading record class_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, "script")) {
#line 750 "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")) {
+ 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 750 "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
+ 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 759 "savegame.cfsml"
- {
- _cfsml_error("class_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;
+ {
+ _cfsml_error("class_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 445 "savegame.cfsml"
static void
-_cfsml_write_song_handle_t(FILE *fh, song_handle_t* save_struc)
-{
- fprintf(fh, "%li", (long) *save_struc);
+_cfsml_write_song_handle_t(FILE *fh, song_handle_t* save_struc) {
+ fprintf(fh, "%li", (long) *save_struc);
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_song_handle_t(FILE *fh, song_handle_t* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
+_cfsml_read_song_handle_t(FILE *fh, song_handle_t* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
#line 565 "savegame.cfsml"
- *save_struc = strtol(lastval, &token, 0);
- if ( (*save_struc == 0) && (token == lastval) ) {
- _cfsml_error("strtol failed at line %d\n", *line);
- return CFSML_FAILURE;
- }
- if (*token != 0) {
- _cfsml_error("Non-integer encountered while parsing int value at line %d\n", *line);
- return CFSML_FAILURE;
- }
- return CFSML_SUCCESS;
+ *save_struc = strtol(lastval, &token, 0);
+ if ((*save_struc == 0) && (token == lastval)) {
+ _cfsml_error("strtol failed at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+ if (*token != 0) {
+ _cfsml_error("Non-integer encountered while parsing int value at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+ return CFSML_SUCCESS;
}
#line 445 "savegame.cfsml"
static void
-_cfsml_write_int(FILE *fh, int* save_struc)
-{
- fprintf(fh, "%li", (long) *save_struc);
+_cfsml_write_int(FILE *fh, int* save_struc) {
+ fprintf(fh, "%li", (long) *save_struc);
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_int(FILE *fh, int* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
+_cfsml_read_int(FILE *fh, int* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
#line 565 "savegame.cfsml"
- *save_struc = strtol(lastval, &token, 0);
- if ( (*save_struc == 0) && (token == lastval) ) {
- _cfsml_error("strtol failed at line %d\n", *line);
- return CFSML_FAILURE;
- }
- if (*token != 0) {
- _cfsml_error("Non-integer encountered while parsing int value at line %d\n", *line);
- return CFSML_FAILURE;
- }
- return CFSML_SUCCESS;
+ *save_struc = strtol(lastval, &token, 0);
+ if ((*save_struc == 0) && (token == lastval)) {
+ _cfsml_error("strtol failed at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+ if (*token != 0) {
+ _cfsml_error("Non-integer encountered while parsing int value at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+ return CFSML_SUCCESS;
}
#line 445 "savegame.cfsml"
static void
-_cfsml_write_menu_t(FILE *fh, menu_t* save_struc)
-{
- int min, max, i;
+_cfsml_write_menu_t(FILE *fh, menu_t* save_struc) {
+ int min, max, i;
#line 465 "savegame.cfsml"
- fprintf(fh, "{\n");
- fprintf(fh, "title = ");
- _cfsml_write_string(fh, (char **) &(save_struc->title));
- fprintf(fh, "\n");
- fprintf(fh, "title_width = ");
- _cfsml_write_int(fh, (int*) &(save_struc->title_width));
- fprintf(fh, "\n");
- fprintf(fh, "width = ");
- _cfsml_write_int(fh, (int*) &(save_struc->width));
- fprintf(fh, "\n");
- fprintf(fh, "items = ");
- min = max = save_struc->items_nr;
- if (!save_struc->items)
- min = max = 0; /* Don't write if it points to NULL */
+ fprintf(fh, "{\n");
+ fprintf(fh, "title = ");
+ _cfsml_write_string(fh, (char **) &(save_struc->title));
+ fprintf(fh, "\n");
+ fprintf(fh, "title_width = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->title_width));
+ fprintf(fh, "\n");
+ fprintf(fh, "width = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->width));
+ fprintf(fh, "\n");
+ fprintf(fh, "items = ");
+ min = max = save_struc->items_nr;
+ if (!save_struc->items)
+ min = max = 0; /* Don't write if it points to NULL */
#line 491 "savegame.cfsml"
- fprintf(fh, "[%d][\n", max);
- for (i = 0; i < min; i++) {
- _cfsml_write_menu_item_t(fh, &(save_struc->items[i]));
- fprintf(fh, "\n");
- }
- fprintf(fh, "]");
- fprintf(fh, "\n");
- fprintf(fh, "}");
+ fprintf(fh, "[%d][\n", max);
+ for (i = 0; i < min; i++) {
+ _cfsml_write_menu_item_t(fh, &(save_struc->items[i]));
+ fprintf(fh, "\n");
+ }
+ fprintf(fh, "]");
+ fprintf(fh, "\n");
+ fprintf(fh, "}");
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_menu_t(FILE *fh, menu_t* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
-int min, max, i;
+_cfsml_read_menu_t(FILE *fh, menu_t* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
+ int min, max, i;
#line 600 "savegame.cfsml"
- int assignment, closed, done;
-
- if (strcmp(lastval, "{")) {
- _cfsml_error("Reading record menu_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, "title")) {
+ int assignment, closed, done;
+
+ if (strcmp(lastval, "{")) {
+ _cfsml_error("Reading record menu_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, "title")) {
#line 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 664 "savegame.cfsml"
- if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) {
- _cfsml_error("Opening brackets expected at line %d\n", *line);
- return CFSML_FAILURE;
- }
+ if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) {
+ _cfsml_error("Opening brackets expected at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
#line 674 "savegame.cfsml"
- /* Prepare to restore dynamic array */
- max = strtol(value + 1, NULL, 0);
- if (max < 0) {
- _cfsml_error("Invalid number of elements to allocate for dynamic array '%s' at line %d\n", token, *line);
- return CFSML_FAILURE;
- }
-
- if (max) {
- save_struc->items = (menu_item_t *) sci_malloc(max * sizeof(menu_item_t));
+ /* Prepare to restore dynamic array */
+ max = strtol(value + 1, NULL, 0);
+ if (max < 0) {
+ _cfsml_error("Invalid number of elements to allocate for dynamic array '%s' at line %d\n", token, *line);
+ return CFSML_FAILURE;
+ }
+
+ if (max) {
+ save_struc->items = (menu_item_t *) sci_malloc(max * sizeof(menu_item_t));
#ifdef SATISFY_PURIFY
- memset(save_struc->items, 0, max * sizeof(menu_item_t));
+ memset(save_struc->items, 0, max * sizeof(menu_item_t));
#endif
- _cfsml_register_pointer(save_struc->items);
- }
- else
- save_struc->items = NULL;
+ _cfsml_register_pointer(save_struc->items);
+ } else
+ save_struc->items = NULL;
#line 700 "savegame.cfsml"
- done = i = 0;
- do {
- if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
+ done = i = 0;
+ do {
+ if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
#line 708 "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_menu_item_t(fh, &(save_struc->items[i++]), value, line, hiteof)) {
- _cfsml_error("Token expected by _cfsml_read_menu_item_t() for items[i++] at line %d\n", *line);
- return CFSML_FAILURE;
- }
- } else done = 1;
- } while (!done);
- save_struc->items_nr = max ; /* Set array size accordingly */
- } else
+ _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_menu_item_t(fh, &(save_struc->items[i++]), value, line, hiteof)) {
+ _cfsml_error("Token expected by _cfsml_read_menu_item_t() for items[i++] at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+ } else done = 1;
+ } while (!done);
+ save_struc->items_nr = max ; /* Set array size accordingly */
+ } else
#line 759 "savegame.cfsml"
- {
- _cfsml_error("menu_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;
+ {
+ _cfsml_error("menu_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 445 "savegame.cfsml"
static void
-_cfsml_write_long(FILE *fh, long* save_struc)
-{
- fprintf(fh, "%li", (long) *save_struc);
+_cfsml_write_long(FILE *fh, long* save_struc) {
+ fprintf(fh, "%li", (long) *save_struc);
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_long(FILE *fh, long* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
+_cfsml_read_long(FILE *fh, long* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
#line 565 "savegame.cfsml"
- *save_struc = strtol(lastval, &token, 0);
- if ( (*save_struc == 0) && (token == lastval) ) {
- _cfsml_error("strtol failed at line %d\n", *line);
- return CFSML_FAILURE;
- }
- if (*token != 0) {
- _cfsml_error("Non-integer encountered while parsing int value at line %d\n", *line);
- return CFSML_FAILURE;
- }
- return CFSML_SUCCESS;
+ *save_struc = strtol(lastval, &token, 0);
+ if ((*save_struc == 0) && (token == lastval)) {
+ _cfsml_error("strtol failed at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+ if (*token != 0) {
+ _cfsml_error("Non-integer encountered while parsing int value at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+ return CFSML_SUCCESS;
}
#line 445 "savegame.cfsml"
static void
-_cfsml_write_clone_table_t(FILE *fh, clone_table_t* save_struc)
-{
- int min, max, i;
+_cfsml_write_clone_table_t(FILE *fh, clone_table_t* save_struc) {
+ int min, max, i;
#line 465 "savegame.cfsml"
- fprintf(fh, "{\n");
- fprintf(fh, "entries_nr = ");
- _cfsml_write_int(fh, (int*) &(save_struc->entries_nr));
- fprintf(fh, "\n");
- fprintf(fh, "first_free = ");
- _cfsml_write_int(fh, (int*) &(save_struc->first_free));
- fprintf(fh, "\n");
- fprintf(fh, "entries_used = ");
- _cfsml_write_int(fh, (int*) &(save_struc->entries_used));
- fprintf(fh, "\n");
- fprintf(fh, "max_entry = ");
- _cfsml_write_int(fh, (int*) &(save_struc->max_entry));
- fprintf(fh, "\n");
- fprintf(fh, "table = ");
- min = max = save_struc->entries_nr;
- if (!save_struc->table)
- min = max = 0; /* Don't write if it points to NULL */
+ fprintf(fh, "{\n");
+ fprintf(fh, "entries_nr = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->entries_nr));
+ fprintf(fh, "\n");
+ fprintf(fh, "first_free = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->first_free));
+ fprintf(fh, "\n");
+ fprintf(fh, "entries_used = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->entries_used));
+ fprintf(fh, "\n");
+ fprintf(fh, "max_entry = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->max_entry));
+ fprintf(fh, "\n");
+ fprintf(fh, "table = ");
+ min = max = save_struc->entries_nr;
+ if (!save_struc->table)
+ min = max = 0; /* Don't write if it points to NULL */
#line 491 "savegame.cfsml"
- fprintf(fh, "[%d][\n", max);
- for (i = 0; i < min; i++) {
- _cfsml_write_clone_entry_t(fh, &(save_struc->table[i]));
- fprintf(fh, "\n");
- }
- fprintf(fh, "]");
- fprintf(fh, "\n");
- fprintf(fh, "}");
+ fprintf(fh, "[%d][\n", max);
+ for (i = 0; i < min; i++) {
+ _cfsml_write_clone_entry_t(fh, &(save_struc->table[i]));
+ fprintf(fh, "\n");
+ }
+ fprintf(fh, "]");
+ fprintf(fh, "\n");
+ fprintf(fh, "}");
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_clone_table_t(FILE *fh, clone_table_t* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
-int min, max, i;
+_cfsml_read_clone_table_t(FILE *fh, clone_table_t* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
+ int min, max, i;
#line 600 "savegame.cfsml"
- int assignment, closed, done;
-
- if (strcmp(lastval, "{")) {
- _cfsml_error("Reading record clone_table_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, "entries_nr")) {
+ int assignment, closed, done;
+
+ if (strcmp(lastval, "{")) {
+ _cfsml_error("Reading record clone_table_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, "entries_nr")) {
#line 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 664 "savegame.cfsml"
- if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) {
- _cfsml_error("Opening brackets expected at line %d\n", *line);
- return CFSML_FAILURE;
- }
+ if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) {
+ _cfsml_error("Opening brackets expected at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
#line 674 "savegame.cfsml"
- /* Prepare to restore dynamic array */
- max = strtol(value + 1, NULL, 0);
- if (max < 0) {
- _cfsml_error("Invalid number of elements to allocate for dynamic array '%s' at line %d\n", token, *line);
- return CFSML_FAILURE;
- }
-
- if (max) {
- save_struc->table = (clone_entry_t *) sci_malloc(max * sizeof(clone_entry_t));
+ /* Prepare to restore dynamic array */
+ max = strtol(value + 1, NULL, 0);
+ if (max < 0) {
+ _cfsml_error("Invalid number of elements to allocate for dynamic array '%s' at line %d\n", token, *line);
+ return CFSML_FAILURE;
+ }
+
+ if (max) {
+ save_struc->table = (clone_entry_t *) sci_malloc(max * sizeof(clone_entry_t));
#ifdef SATISFY_PURIFY
- memset(save_struc->table, 0, max * sizeof(clone_entry_t));
+ memset(save_struc->table, 0, max * sizeof(clone_entry_t));
#endif
- _cfsml_register_pointer(save_struc->table);
- }
- else
- save_struc->table = NULL;
+ _cfsml_register_pointer(save_struc->table);
+ } else
+ save_struc->table = NULL;
#line 700 "savegame.cfsml"
- done = i = 0;
- do {
- if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
+ done = i = 0;
+ do {
+ if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
#line 708 "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_clone_entry_t(fh, &(save_struc->table[i++]), value, line, hiteof)) {
- _cfsml_error("Token expected by _cfsml_read_clone_entry_t() for table[i++] at line %d\n", *line);
- return CFSML_FAILURE;
- }
- } else done = 1;
- } while (!done);
- save_struc->entries_nr = max ; /* Set array size accordingly */
- } else
+ _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_clone_entry_t(fh, &(save_struc->table[i++]), value, line, hiteof)) {
+ _cfsml_error("Token expected by _cfsml_read_clone_entry_t() for table[i++] at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+ } else done = 1;
+ } while (!done);
+ save_struc->entries_nr = max ; /* Set array size accordingly */
+ } else
#line 759 "savegame.cfsml"
- {
- _cfsml_error("clone_table_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;
+ {
+ _cfsml_error("clone_table_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 445 "savegame.cfsml"
static void
-_cfsml_write_clone_t(FILE *fh, clone_t* save_struc)
-{
- int min, max, i;
+_cfsml_write_clone_t(FILE *fh, clone_t* save_struc) {
+ int min, max, i;
#line 465 "savegame.cfsml"
- fprintf(fh, "{\n");
- fprintf(fh, "flags = ");
- _cfsml_write_int(fh, (int*) &(save_struc->flags));
- fprintf(fh, "\n");
- fprintf(fh, "pos = ");
- write_reg_t(fh, (reg_t*) &(save_struc->pos));
- fprintf(fh, "\n");
- fprintf(fh, "variables_nr = ");
- _cfsml_write_int(fh, (int*) &(save_struc->variables_nr));
- fprintf(fh, "\n");
- fprintf(fh, "variable_names_nr = ");
- _cfsml_write_int(fh, (int*) &(save_struc->variable_names_nr));
- fprintf(fh, "\n");
- fprintf(fh, "methods_nr = ");
- _cfsml_write_int(fh, (int*) &(save_struc->methods_nr));
- fprintf(fh, "\n");
- fprintf(fh, "variables = ");
- min = max = save_struc->variables_nr;
- if (!save_struc->variables)
- min = max = 0; /* Don't write if it points to NULL */
+ fprintf(fh, "{\n");
+ fprintf(fh, "flags = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->flags));
+ fprintf(fh, "\n");
+ fprintf(fh, "pos = ");
+ write_reg_t(fh, (reg_t*) &(save_struc->pos));
+ fprintf(fh, "\n");
+ fprintf(fh, "variables_nr = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->variables_nr));
+ fprintf(fh, "\n");
+ fprintf(fh, "variable_names_nr = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->variable_names_nr));
+ fprintf(fh, "\n");
+ fprintf(fh, "methods_nr = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->methods_nr));
+ fprintf(fh, "\n");
+ fprintf(fh, "variables = ");
+ min = max = save_struc->variables_nr;
+ if (!save_struc->variables)
+ min = max = 0; /* Don't write if it points to NULL */
#line 491 "savegame.cfsml"
- fprintf(fh, "[%d][\n", max);
- for (i = 0; i < min; i++) {
- write_reg_t(fh, &(save_struc->variables[i]));
- fprintf(fh, "\n");
- }
- fprintf(fh, "]");
- fprintf(fh, "\n");
- fprintf(fh, "}");
+ fprintf(fh, "[%d][\n", max);
+ for (i = 0; i < min; i++) {
+ write_reg_t(fh, &(save_struc->variables[i]));
+ fprintf(fh, "\n");
+ }
+ fprintf(fh, "]");
+ fprintf(fh, "\n");
+ fprintf(fh, "}");
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_clone_t(FILE *fh, clone_t* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
-int min, max, i;
+_cfsml_read_clone_t(FILE *fh, clone_t* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
+ int min, max, i;
#line 600 "savegame.cfsml"
- int assignment, closed, done;
-
- if (strcmp(lastval, "{")) {
- _cfsml_error("Reading record clone_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, "flags")) {
+ int assignment, closed, done;
+
+ if (strcmp(lastval, "{")) {
+ _cfsml_error("Reading record clone_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, "flags")) {
#line 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 664 "savegame.cfsml"
- if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) {
- _cfsml_error("Opening brackets expected at line %d\n", *line);
- return CFSML_FAILURE;
- }
+ if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) {
+ _cfsml_error("Opening brackets expected at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
#line 674 "savegame.cfsml"
- /* Prepare to restore dynamic array */
- max = strtol(value + 1, NULL, 0);
- if (max < 0) {
- _cfsml_error("Invalid number of elements to allocate for dynamic array '%s' at line %d\n", token, *line);
- return CFSML_FAILURE;
- }
-
- if (max) {
- save_struc->variables = (reg_t *) sci_malloc(max * sizeof(reg_t));
+ /* Prepare to restore dynamic array */
+ max = strtol(value + 1, NULL, 0);
+ if (max < 0) {
+ _cfsml_error("Invalid number of elements to allocate for dynamic array '%s' at line %d\n", token, *line);
+ return CFSML_FAILURE;
+ }
+
+ if (max) {
+ save_struc->variables = (reg_t *) sci_malloc(max * sizeof(reg_t));
#ifdef SATISFY_PURIFY
- memset(save_struc->variables, 0, max * sizeof(reg_t));
+ memset(save_struc->variables, 0, max * sizeof(reg_t));
#endif
- _cfsml_register_pointer(save_struc->variables);
- }
- else
- save_struc->variables = NULL;
+ _cfsml_register_pointer(save_struc->variables);
+ } else
+ save_struc->variables = NULL;
#line 700 "savegame.cfsml"
- done = i = 0;
- do {
- if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
+ done = i = 0;
+ do {
+ if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
#line 708 "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 (read_reg_t(fh, &(save_struc->variables[i++]), value, line, hiteof)) {
- _cfsml_error("Token expected by read_reg_t() for variables[i++] at line %d\n", *line);
- return CFSML_FAILURE;
- }
- } else done = 1;
- } while (!done);
- save_struc->variables_nr = max ; /* Set array size accordingly */
- } else
+ _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 (read_reg_t(fh, &(save_struc->variables[i++]), value, line, hiteof)) {
+ _cfsml_error("Token expected by read_reg_t() for variables[i++] at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+ } else done = 1;
+ } while (!done);
+ save_struc->variables_nr = max ; /* Set array size accordingly */
+ } else
#line 759 "savegame.cfsml"
- {
- _cfsml_error("clone_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;
+ {
+ _cfsml_error("clone_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 445 "savegame.cfsml"
static void
-_cfsml_write_list_t(FILE *fh, list_t* save_struc)
-{
- int min, max, i;
+_cfsml_write_list_t(FILE *fh, list_t* save_struc) {
+ int min, max, i;
#line 465 "savegame.cfsml"
- fprintf(fh, "{\n");
- fprintf(fh, "first = ");
- write_reg_t(fh, (reg_t*) &(save_struc->first));
- fprintf(fh, "\n");
- fprintf(fh, "last = ");
- write_reg_t(fh, (reg_t*) &(save_struc->last));
- fprintf(fh, "\n");
- fprintf(fh, "}");
+ fprintf(fh, "{\n");
+ fprintf(fh, "first = ");
+ write_reg_t(fh, (reg_t*) &(save_struc->first));
+ fprintf(fh, "\n");
+ fprintf(fh, "last = ");
+ write_reg_t(fh, (reg_t*) &(save_struc->last));
+ fprintf(fh, "\n");
+ fprintf(fh, "}");
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_list_t(FILE *fh, list_t* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
-int min, max, i;
+_cfsml_read_list_t(FILE *fh, list_t* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
+ int min, max, i;
#line 600 "savegame.cfsml"
- int assignment, closed, done;
-
- if (strcmp(lastval, "{")) {
- _cfsml_error("Reading record list_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, "first")) {
+ int assignment, closed, done;
+
+ if (strcmp(lastval, "{")) {
+ _cfsml_error("Reading record list_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, "first")) {
#line 750 "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")) {
+ 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 750 "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
+ 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 759 "savegame.cfsml"
- {
- _cfsml_error("list_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;
+ {
+ _cfsml_error("list_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 445 "savegame.cfsml"
static void
-_cfsml_write_sys_string_t(FILE *fh, sys_string_t* save_struc)
-{
- int min, max, i;
+_cfsml_write_sys_string_t(FILE *fh, sys_string_t* save_struc) {
+ int min, max, i;
#line 465 "savegame.cfsml"
- fprintf(fh, "{\n");
- fprintf(fh, "name = ");
- _cfsml_write_string(fh, (char **) &(save_struc->name));
- fprintf(fh, "\n");
- fprintf(fh, "max_size = ");
- _cfsml_write_int(fh, (int*) &(save_struc->max_size));
- fprintf(fh, "\n");
- fprintf(fh, "value = ");
- _cfsml_write_string(fh, (char **) &(save_struc->value));
- fprintf(fh, "\n");
- fprintf(fh, "}");
+ fprintf(fh, "{\n");
+ fprintf(fh, "name = ");
+ _cfsml_write_string(fh, (char **) &(save_struc->name));
+ fprintf(fh, "\n");
+ fprintf(fh, "max_size = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->max_size));
+ fprintf(fh, "\n");
+ fprintf(fh, "value = ");
+ _cfsml_write_string(fh, (char **) &(save_struc->value));
+ fprintf(fh, "\n");
+ fprintf(fh, "}");
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_sys_string_t(FILE *fh, sys_string_t* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
-int min, max, i;
+_cfsml_read_sys_string_t(FILE *fh, sys_string_t* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
+ int min, max, i;
#line 600 "savegame.cfsml"
- int assignment, closed, done;
-
- 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")) {
+ int assignment, closed, done;
+
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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
+ 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 759 "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;
+ {
+ _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 445 "savegame.cfsml"
static void
-_cfsml_write_script_t(FILE *fh, script_t* save_struc)
-{
- int min, max, i;
+_cfsml_write_script_t(FILE *fh, script_t* save_struc) {
+ int min, max, i;
#line 465 "savegame.cfsml"
- fprintf(fh, "{\n");
- fprintf(fh, "nr = ");
- _cfsml_write_int(fh, (int*) &(save_struc->nr));
- fprintf(fh, "\n");
- fprintf(fh, "buf_size = ");
- _cfsml_write_size_t(fh, (size_t*) &(save_struc->buf_size));
- fprintf(fh, "\n");
- fprintf(fh, "script_size = ");
- _cfsml_write_size_t(fh, (size_t*) &(save_struc->script_size));
- fprintf(fh, "\n");
- fprintf(fh, "heap_size = ");
- _cfsml_write_size_t(fh, (size_t*) &(save_struc->heap_size));
- fprintf(fh, "\n");
- fprintf(fh, "obj_indices = ");
- write_int_hash_map_tp(fh, (int_hash_map_t **) &(save_struc->obj_indices));
- fprintf(fh, "\n");
- fprintf(fh, "exports_nr = ");
- _cfsml_write_int(fh, (int*) &(save_struc->exports_nr));
- fprintf(fh, "\n");
- fprintf(fh, "synonyms_nr = ");
- _cfsml_write_int(fh, (int*) &(save_struc->synonyms_nr));
- fprintf(fh, "\n");
- fprintf(fh, "lockers = ");
- _cfsml_write_int(fh, (int*) &(save_struc->lockers));
- fprintf(fh, "\n");
- fprintf(fh, "objects_allocated = ");
- _cfsml_write_int(fh, (int*) &(save_struc->objects_allocated));
- fprintf(fh, "\n");
- fprintf(fh, "objects_nr = ");
- _cfsml_write_int(fh, (int*) &(save_struc->objects_nr));
- fprintf(fh, "\n");
- fprintf(fh, "objects = ");
- min = max = save_struc->objects_allocated;
- if (!save_struc->objects)
- min = max = 0; /* Don't write if it points to NULL */
+ fprintf(fh, "{\n");
+ fprintf(fh, "nr = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->nr));
+ fprintf(fh, "\n");
+ fprintf(fh, "buf_size = ");
+ _cfsml_write_size_t(fh, (size_t*) &(save_struc->buf_size));
+ fprintf(fh, "\n");
+ fprintf(fh, "script_size = ");
+ _cfsml_write_size_t(fh, (size_t*) &(save_struc->script_size));
+ fprintf(fh, "\n");
+ fprintf(fh, "heap_size = ");
+ _cfsml_write_size_t(fh, (size_t*) &(save_struc->heap_size));
+ fprintf(fh, "\n");
+ fprintf(fh, "obj_indices = ");
+ write_int_hash_map_tp(fh, (int_hash_map_t **) &(save_struc->obj_indices));
+ fprintf(fh, "\n");
+ fprintf(fh, "exports_nr = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->exports_nr));
+ fprintf(fh, "\n");
+ fprintf(fh, "synonyms_nr = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->synonyms_nr));
+ fprintf(fh, "\n");
+ fprintf(fh, "lockers = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->lockers));
+ fprintf(fh, "\n");
+ fprintf(fh, "objects_allocated = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->objects_allocated));
+ fprintf(fh, "\n");
+ fprintf(fh, "objects_nr = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->objects_nr));
+ fprintf(fh, "\n");
+ fprintf(fh, "objects = ");
+ min = max = save_struc->objects_allocated;
+ if (!save_struc->objects)
+ min = max = 0; /* Don't write if it points to NULL */
#line 491 "savegame.cfsml"
- fprintf(fh, "[%d][\n", max);
- for (i = 0; i < min; i++) {
- _cfsml_write_object_t(fh, &(save_struc->objects[i]));
- fprintf(fh, "\n");
- }
- fprintf(fh, "]");
- fprintf(fh, "\n");
- fprintf(fh, "locals_offset = ");
- _cfsml_write_int(fh, (int*) &(save_struc->locals_offset));
- fprintf(fh, "\n");
- fprintf(fh, "locals_segment = ");
- _cfsml_write_int(fh, (int*) &(save_struc->locals_segment));
- fprintf(fh, "\n");
- fprintf(fh, "marked_as_deleted = ");
- _cfsml_write_int(fh, (int*) &(save_struc->marked_as_deleted));
- fprintf(fh, "\n");
- fprintf(fh, "}");
+ fprintf(fh, "[%d][\n", max);
+ for (i = 0; i < min; i++) {
+ _cfsml_write_object_t(fh, &(save_struc->objects[i]));
+ fprintf(fh, "\n");
+ }
+ fprintf(fh, "]");
+ fprintf(fh, "\n");
+ fprintf(fh, "locals_offset = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->locals_offset));
+ fprintf(fh, "\n");
+ fprintf(fh, "locals_segment = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->locals_segment));
+ fprintf(fh, "\n");
+ fprintf(fh, "marked_as_deleted = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->marked_as_deleted));
+ fprintf(fh, "\n");
+ fprintf(fh, "}");
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_script_t(FILE *fh, script_t* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
-int min, max, i;
+_cfsml_read_script_t(FILE *fh, script_t* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
+ int min, max, i;
#line 600 "savegame.cfsml"
- int assignment, closed, done;
-
- if (strcmp(lastval, "{")) {
- _cfsml_error("Reading record script_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, "nr")) {
+ int assignment, closed, done;
+
+ if (strcmp(lastval, "{")) {
+ _cfsml_error("Reading record script_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, "nr")) {
#line 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 664 "savegame.cfsml"
- if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) {
- _cfsml_error("Opening brackets expected at line %d\n", *line);
- return CFSML_FAILURE;
- }
+ if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) {
+ _cfsml_error("Opening brackets expected at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
#line 674 "savegame.cfsml"
- /* Prepare to restore dynamic array */
- max = strtol(value + 1, NULL, 0);
- if (max < 0) {
- _cfsml_error("Invalid number of elements to allocate for dynamic array '%s' at line %d\n", token, *line);
- return CFSML_FAILURE;
- }
-
- if (max) {
- save_struc->objects = (object_t *) sci_malloc(max * sizeof(object_t));
+ /* Prepare to restore dynamic array */
+ max = strtol(value + 1, NULL, 0);
+ if (max < 0) {
+ _cfsml_error("Invalid number of elements to allocate for dynamic array '%s' at line %d\n", token, *line);
+ return CFSML_FAILURE;
+ }
+
+ if (max) {
+ save_struc->objects = (object_t *) sci_malloc(max * sizeof(object_t));
#ifdef SATISFY_PURIFY
- memset(save_struc->objects, 0, max * sizeof(object_t));
+ memset(save_struc->objects, 0, max * sizeof(object_t));
#endif
- _cfsml_register_pointer(save_struc->objects);
- }
- else
- save_struc->objects = NULL;
+ _cfsml_register_pointer(save_struc->objects);
+ } else
+ save_struc->objects = NULL;
#line 700 "savegame.cfsml"
- done = i = 0;
- do {
- if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
+ done = i = 0;
+ do {
+ if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
#line 708 "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_object_t(fh, &(save_struc->objects[i++]), value, line, hiteof)) {
- _cfsml_error("Token expected by _cfsml_read_object_t() for objects[i++] at line %d\n", *line);
- return CFSML_FAILURE;
- }
- } else done = 1;
- } while (!done);
- save_struc->objects_allocated = max ; /* Set array size accordingly */
- } else
- if (!strcmp(token, "locals_offset")) {
+ _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_object_t(fh, &(save_struc->objects[i++]), value, line, hiteof)) {
+ _cfsml_error("Token expected by _cfsml_read_object_t() for objects[i++] at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+ } else done = 1;
+ } while (!done);
+ save_struc->objects_allocated = max ; /* Set array size accordingly */
+ } else
+ if (!strcmp(token, "locals_offset")) {
#line 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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
+ 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 759 "savegame.cfsml"
- {
- _cfsml_error("script_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;
+ {
+ _cfsml_error("script_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 445 "savegame.cfsml"
static void
-_cfsml_write_seg_manager_t(FILE *fh, seg_manager_t* save_struc)
-{
- int min, max, i;
+_cfsml_write_seg_manager_t(FILE *fh, seg_manager_t* save_struc) {
+ int min, max, i;
#line 465 "savegame.cfsml"
- fprintf(fh, "{\n");
- fprintf(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 = ");
- min = max = save_struc->heap_size;
- if (!save_struc->heap)
- min = max = 0; /* Don't write if it points to NULL */
+ fprintf(fh, "{\n");
+ fprintf(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 = ");
+ min = max = save_struc->heap_size;
+ if (!save_struc->heap)
+ min = max = 0; /* Don't write if it points to NULL */
#line 491 "savegame.cfsml"
- fprintf(fh, "[%d][\n", max);
- for (i = 0; i < min; i++) {
- write_mem_obj_tp(fh, &(save_struc->heap[i]));
- fprintf(fh, "\n");
- }
- fprintf(fh, "]");
- fprintf(fh, "\n");
- fprintf(fh, "heap_size = ");
- _cfsml_write_int(fh, (int*) &(save_struc->heap_size));
- fprintf(fh, "\n");
- fprintf(fh, "reserved_id = ");
- _cfsml_write_int(fh, (int*) &(save_struc->reserved_id));
- fprintf(fh, "\n");
- fprintf(fh, "exports_wide = ");
- _cfsml_write_int(fh, (int*) &(save_struc->exports_wide));
- fprintf(fh, "\n");
- fprintf(fh, "sci1_1 = ");
- _cfsml_write_int(fh, (int*) &(save_struc->sci1_1));
- fprintf(fh, "\n");
- fprintf(fh, "gc_mark_bits = ");
- _cfsml_write_int(fh, (int*) &(save_struc->gc_mark_bits));
- fprintf(fh, "\n");
- fprintf(fh, "mem_allocated = ");
- _cfsml_write_size_t(fh, (size_t*) &(save_struc->mem_allocated));
- fprintf(fh, "\n");
- fprintf(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 = ");
- _cfsml_write_seg_id_t(fh, (seg_id_t*) &(save_struc->lists_seg_id));
- fprintf(fh, "\n");
- fprintf(fh, "nodes_seg_id = ");
- _cfsml_write_seg_id_t(fh, (seg_id_t*) &(save_struc->nodes_seg_id));
- fprintf(fh, "\n");
- fprintf(fh, "}");
+ fprintf(fh, "[%d][\n", max);
+ for (i = 0; i < min; i++) {
+ write_mem_obj_tp(fh, &(save_struc->heap[i]));
+ fprintf(fh, "\n");
+ }
+ fprintf(fh, "]");
+ fprintf(fh, "\n");
+ fprintf(fh, "heap_size = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->heap_size));
+ fprintf(fh, "\n");
+ fprintf(fh, "reserved_id = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->reserved_id));
+ fprintf(fh, "\n");
+ fprintf(fh, "exports_wide = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->exports_wide));
+ fprintf(fh, "\n");
+ fprintf(fh, "sci1_1 = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->sci1_1));
+ fprintf(fh, "\n");
+ fprintf(fh, "gc_mark_bits = ");
+ _cfsml_write_int(fh, (int*) &(save_struc->gc_mark_bits));
+ fprintf(fh, "\n");
+ fprintf(fh, "mem_allocated = ");
+ _cfsml_write_size_t(fh, (size_t*) &(save_struc->mem_allocated));
+ fprintf(fh, "\n");
+ fprintf(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 = ");
+ _cfsml_write_seg_id_t(fh, (seg_id_t*) &(save_struc->lists_seg_id));
+ fprintf(fh, "\n");
+ fprintf(fh, "nodes_seg_id = ");
+ _cfsml_write_seg_id_t(fh, (seg_id_t*) &(save_struc->nodes_seg_id));
+ fprintf(fh, "\n");
+ fprintf(fh, "}");
}
#line 539 "savegame.cfsml"
static int
-_cfsml_read_seg_manager_t(FILE *fh, seg_manager_t* save_struc, const char *lastval, int *line, int *hiteof)
-{
- char *token;
-int min, max, i;
+_cfsml_read_seg_manager_t(FILE *fh, seg_manager_t* save_struc, const char *lastval, int *line, int *hiteof) {
+ char *token;
+ int min, max, i;
#line 600 "savegame.cfsml"
- int assignment, closed, done;
-
- if (strcmp(lastval, "{")) {
- _cfsml_error("Reading record seg_manager_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, "id_seg_map")) {
+ int assignment, closed, done;
+
+ if (strcmp(lastval, "{")) {
+ _cfsml_error("Reading record seg_manager_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, "id_seg_map")) {
#line 750 "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")) {
+ 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 664 "savegame.cfsml"
- if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) {
- _cfsml_error("Opening brackets expected at line %d\n", *line);
- return CFSML_FAILURE;
- }
+ if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) {
+ _cfsml_error("Opening brackets expected at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
#line 674 "savegame.cfsml"
- /* Prepare to restore dynamic array */
- max = strtol(value + 1, NULL, 0);
- if (max < 0) {
- _cfsml_error("Invalid number of elements to allocate for dynamic array '%s' at line %d\n", token, *line);
- return CFSML_FAILURE;
- }
-
- if (max) {
- save_struc->heap = (mem_obj_ptr *) sci_malloc(max * sizeof(mem_obj_ptr));
+ /* Prepare to restore dynamic array */
+ max = strtol(value + 1, NULL, 0);
+ if (max < 0) {
+ _cfsml_error("Invalid number of elements to allocate for dynamic array '%s' at line %d\n", token, *line);
+ return CFSML_FAILURE;
+ }
+
+ if (max) {
+ save_struc->heap = (mem_obj_ptr *) sci_malloc(max * sizeof(mem_obj_ptr));
#ifdef SATISFY_PURIFY
- memset(save_struc->heap, 0, max * sizeof(mem_obj_ptr));
+ memset(save_struc->heap, 0, max * sizeof(mem_obj_ptr));
#endif
- _cfsml_register_pointer(save_struc->heap);
- }
- else
- save_struc->heap = NULL;
+ _cfsml_register_pointer(save_struc->heap);
+ } else
+ save_struc->heap = NULL;
#line 700 "savegame.cfsml"
- done = i = 0;
- do {
- if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
+ done = i = 0;
+ do {
+ if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) {
#line 708 "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 (read_mem_obj_tp(fh, &(save_struc->heap[i++]), value, line, hiteof)) {
- _cfsml_error("Token expected by read_mem_obj_tp() for heap[i++] at line %d\n", *line);
- return CFSML_FAILURE;
- }
- } else done = 1;
- } while (!done);
- save_struc->heap_size = max ; /* Set array size accordingly */
- } else
- if (!strcmp(token, "heap_size")) {
+ _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 (read_mem_obj_tp(fh, &(save_struc->heap[i++]), value, line, hiteof)) {
+ _cfsml_error("Token expected by read_mem_obj_tp() for heap[i++] at line %d\n", *line);
+ return CFSML_FAILURE;
+ }
+ } else done = 1;
+ } while (!done);
+ save_struc->heap_size = max ; /* Set array size accordingly */
+ } else
+ if (!strcmp(token, "heap_size")) {
#line 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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")) {
+ 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 750 "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
+ 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 759 "savegame.cfsml"
- {
- _cfsml_error("seg_manager_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;
+ {
+ _cfsml_error("seg_manager_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;
}
@@ -4128,77 +4034,73 @@ int min, max, i;
/* Auto-generation performed by cfsml.pl 0.8.2 */
#line 402 "savegame.cfsml"
-void
-write_songlib_t(FILE *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");
- while (seeker)
- {
- seeker->restore_time = seeker->it->get_timepos(seeker->it);
+void
+write_songlib_t(FILE *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");
+ while (seeker) {
+ seeker->restore_time = seeker->it->get_timepos(seeker->it);
#line 878 "savegame.cfsml"
-/* Auto-generated CFSML data writer code */
- _cfsml_write_song_t(fh, seeker);
- fprintf(fh, "\n");
-/* End of auto-generated CFSML data writer code */
+ /* Auto-generated CFSML data writer code */
+ _cfsml_write_song_t(fh, seeker);
+ fprintf(fh, "\n");
+ /* End of auto-generated CFSML data writer code */
#line 417 "savegame.cfsml"
- seeker = seeker->next;
- }
- fprintf(fh, "]\n");
- fprintf(fh, "}\n");
+ seeker = seeker->next;
+ }
+ fprintf(fh, "]\n");
+ fprintf(fh, "}\n");
}
int
-read_songlib_t(FILE *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");
- *line += 4;
- song_lib_init(songlib);
- for (i = 0; i < songcount; i++)
- {
-/* Auto-generated CFSML data reader code */
+read_songlib_t(FILE *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");
+ *line += 4;
+ song_lib_init(songlib);
+ for (i = 0; i < songcount; i++) {
+ /* Auto-generated CFSML data reader code */
#line 824 "savegame.cfsml"
- {
+ {
#line 835 "savegame.cfsml"
- int _cfsml_eof = 0, _cfsml_error;
- int dummy;
+ int _cfsml_eof = 0, _cfsml_error;
+ int dummy;
#line 840 "savegame.cfsml"
- const char *_cfsml_inp = lastval;
+ const char *_cfsml_inp = lastval;
#line 848 "savegame.cfsml"
- _cfsml_error = read_song_tp(fh, &newsong, _cfsml_inp, &(*line), &_cfsml_eof);
+ _cfsml_error = read_song_tp(fh, &newsong, _cfsml_inp, &(*line), &_cfsml_eof);
#line 853 "savegame.cfsml"
- *hiteof = _cfsml_error;
+ *hiteof = _cfsml_error;
#line 860 "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 */
+ 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 440 "savegame.cfsml"
- song_lib_add(*songlib, newsong);
- }
- fscanf(fh, "]\n");
- fscanf(fh, "}\n");;
- *line += 2;
- return 0;
+ song_lib_add(*songlib, newsong);
+ }
+ fscanf(fh, "]\n");
+ fscanf(fh, "}\n");;
+ *line += 2;
+ return 0;
}
struct {
@@ -4210,19 +4112,19 @@ struct {
{MEM_OBJ_CLONES, "CLONES"},
{MEM_OBJ_LOCALS, "LOCALS"},
{MEM_OBJ_STACK, "STACK"},
- {MEM_OBJ_SYS_STRINGS,"SYS_STRINGS"},
- {MEM_OBJ_LISTS,"LISTS"},
- {MEM_OBJ_NODES,"NODES"},
- {MEM_OBJ_HUNK,"HUNK"},
- {MEM_OBJ_DYNMEM,"DYNMEM"}};
+ {MEM_OBJ_SYS_STRINGS, "SYS_STRINGS"},
+ {MEM_OBJ_LISTS, "LISTS"},
+ {MEM_OBJ_NODES, "NODES"},
+ {MEM_OBJ_HUNK, "HUNK"},
+ {MEM_OBJ_DYNMEM, "DYNMEM"}
+};
int
-mem_obj_string_to_enum(const char *str)
-{
+mem_obj_string_to_enum(const char *str) {
int i;
- for (i = 0; i <= MEM_OBJ_MAX; i++)
- { if (!strcasecmp(mem_obj_string_names[i].name, str))
+ for (i = 0; i <= MEM_OBJ_MAX; i++) {
+ if (!strcasecmp(mem_obj_string_names[i].name, str))
return i;
}
@@ -4232,24 +4134,22 @@ 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)
-{
+write_int_hash_map_tp(FILE *fh, int_hash_map_t **foo) {
#line 878 "savegame.cfsml"
-/* Auto-generated CFSML data writer code */
- _cfsml_write_int_hash_map_t(fh, *foo);
- fprintf(fh, "\n");
-/* End of auto-generated CFSML data writer code */
+ /* Auto-generated CFSML data writer code */
+ _cfsml_write_int_hash_map_t(fh, *foo);
+ fprintf(fh, "\n");
+ /* End of auto-generated CFSML data writer code */
#line 482 "savegame.cfsml"
}
void
-write_song_tp(FILE *fh, song_t **foo)
-{
+write_song_tp(FILE *fh, song_t **foo) {
#line 878 "savegame.cfsml"
-/* Auto-generated CFSML data writer code */
- _cfsml_write_song_t(fh, *foo);
- fprintf(fh, "\n");
-/* End of auto-generated CFSML data writer code */
+ /* Auto-generated CFSML data writer code */
+ _cfsml_write_song_t(fh, *foo);
+ fprintf(fh, "\n");
+ /* End of auto-generated CFSML data writer code */
#line 488 "savegame.cfsml"
}
@@ -4257,89 +4157,83 @@ 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)
-{
- 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 */
+read_song_tp(FILE *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 824 "savegame.cfsml"
- {
+ {
#line 835 "savegame.cfsml"
- int _cfsml_eof = 0, _cfsml_error;
- int dummy;
+ int _cfsml_eof = 0, _cfsml_error;
+ int dummy;
#line 840 "savegame.cfsml"
- const char *_cfsml_inp = token;
+ const char *_cfsml_inp = token;
#line 848 "savegame.cfsml"
- _cfsml_error = _cfsml_read_song_t(fh, (*foo), _cfsml_inp, &(*line), &_cfsml_eof);
+ _cfsml_error = _cfsml_read_song_t(fh, (*foo), _cfsml_inp, &(*line), &_cfsml_eof);
#line 853 "savegame.cfsml"
- *hiteof = _cfsml_error;
+ *hiteof = _cfsml_error;
#line 860 "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 */
+ 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 501 "savegame.cfsml"
- (*foo)->delay = 0;
- (*foo)->it = NULL;
- (*foo)->next_playing = (*foo)->next_stopping = (*foo)->next = NULL;
- return 0;
+ (*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)
-{
+read_int_hash_map_tp(FILE *fh, int_hash_map_t **foo, const char *lastval, int *line, int *hiteof) {
*foo = (int_hash_map_t*)malloc(sizeof(int_hash_map_t));
-/* Auto-generated CFSML data reader code */
+ /* Auto-generated CFSML data reader code */
#line 824 "savegame.cfsml"
- {
+ {
#line 835 "savegame.cfsml"
- int _cfsml_eof = 0, _cfsml_error;
- int dummy;
+ int _cfsml_eof = 0, _cfsml_error;
+ int dummy;
#line 840 "savegame.cfsml"
- const char *_cfsml_inp = lastval;
+ const char *_cfsml_inp = lastval;
#line 848 "savegame.cfsml"
- _cfsml_error = _cfsml_read_int_hash_map_t(fh, (*foo), _cfsml_inp, &(*line), &_cfsml_eof);
+ _cfsml_error = _cfsml_read_int_hash_map_t(fh, (*foo), _cfsml_inp, &(*line), &_cfsml_eof);
#line 853 "savegame.cfsml"
- *hiteof = _cfsml_error;
+ *hiteof = _cfsml_error;
#line 860 "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 */
+ 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 511 "savegame.cfsml"
(*foo)->holes = NULL;
return 0;
}
void
-write_int_hash_map_node_tp(FILE *fh, int_hash_map_node_t **foo)
-{
- if (!(*foo))
- {
+write_int_hash_map_node_tp(FILE *fh, int_hash_map_node_t **foo) {
+ if (!(*foo)) {
fputs("\\null", fh);
- } else
- {
- fprintf(fh,"[\n%d=>%d\n", (*foo)->name, (*foo)->value);
- if ((*foo)->next)
- {
+ } else {
+ fprintf(fh, "[\n%d=>%d\n", (*foo)->name, (*foo)->value);
+ if ((*foo)->next) {
#line 878 "savegame.cfsml"
-/* Auto-generated CFSML data writer code */
- write_int_hash_map_node_tp(fh, &((*foo)->next));
- fprintf(fh, "\n");
-/* End of auto-generated CFSML data writer code */
+ /* Auto-generated CFSML data writer code */
+ write_int_hash_map_node_tp(fh, &((*foo)->next));
+ fprintf(fh, "\n");
+ /* End of auto-generated CFSML data writer code */
#line 527 "savegame.cfsml"
} else fputc('L', fh);
fputs("]", fh);
@@ -4347,39 +4241,31 @@ write_int_hash_map_node_tp(FILE *fh, int_hash_map_node_t **foo)
}
int
-read_int_hash_map_node_tp(FILE *fh, int_hash_map_node_t **foo, const char *lastval, int *line, int *hiteof)
-{
+read_int_hash_map_node_tp(FILE *fh, int_hash_map_node_t **foo, const char *lastval, int *line, int *hiteof) {
static char buffer[80];
if (lastval[0] == '\\') {
*foo = NULL; /* No hash map node */
} else {
*foo = (int_hash_map_node_t*)malloc(sizeof(int_hash_map_node_t));
- if (lastval[0] != '[')
- {
+ if (lastval[0] != '[') {
sciprintf("Expected opening bracket in hash_map_node_t on line %d\n", *line);
return 1;
}
-
+
do {
(*line)++;
fgets(buffer, 80, fh);
- if (buffer[0] == 'L')
- {
+ if (buffer[0] == 'L') {
(*foo)->next = NULL;
buffer[0] = buffer[1];
} /* HACK: deliberately no else clause here */
- if (buffer[0] == ']')
- {
+ if (buffer[0] == ']') {
break;
- }
- else if (buffer[0] == '[')
- {
+ } else if (buffer[0] == '[') {
if (read_int_hash_map_node_tp(fh, &((*foo)->next), buffer, line, hiteof))
return 1;
- }
- else if (sscanf(buffer, "%d=>%d", &((*foo)->name), &((*foo)->value))<2)
- {
+ } else if (sscanf(buffer, "%d=>%d", &((*foo)->name), &((*foo)->value)) < 2) {
sciprintf("Error parsing hash_map_node_t on line %d\n", *line);
return 1;
}
@@ -4390,15 +4276,14 @@ read_int_hash_map_node_tp(FILE *fh, int_hash_map_node_t **foo, const char *lastv
}
void
-write_menubar_tp(FILE *fh, menubar_t **foo)
-{
+write_menubar_tp(FILE *fh, menubar_t **foo) {
if (*foo) {
#line 878 "savegame.cfsml"
-/* Auto-generated CFSML data writer code */
- _cfsml_write_menubar_t(fh, (*foo));
- fprintf(fh, "\n");
-/* End of auto-generated CFSML data writer code */
+ /* Auto-generated CFSML data writer code */
+ _cfsml_write_menubar_t(fh, (*foo));
+ fprintf(fh, "\n");
+ /* End of auto-generated CFSML data writer code */
#line 581 "savegame.cfsml"
} else { /* Nothing to write */
@@ -4408,37 +4293,36 @@ write_menubar_tp(FILE *fh, menubar_t **foo)
int
-read_menubar_tp(FILE *fh, menubar_t **foo, const char *lastval, int *line, int *hiteof)
-{
+read_menubar_tp(FILE *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 */
+ /* Auto-generated CFSML data reader code */
#line 824 "savegame.cfsml"
- {
+ {
#line 835 "savegame.cfsml"
- int _cfsml_eof = 0, _cfsml_error;
- int dummy;
+ int _cfsml_eof = 0, _cfsml_error;
+ int dummy;
#line 840 "savegame.cfsml"
- const char *_cfsml_inp = lastval;
+ const char *_cfsml_inp = lastval;
#line 848 "savegame.cfsml"
- _cfsml_error = _cfsml_read_menubar_t(fh, (*foo), _cfsml_inp, &(*line), &_cfsml_eof);
+ _cfsml_error = _cfsml_read_menubar_t(fh, (*foo), _cfsml_inp, &(*line), &_cfsml_eof);
#line 853 "savegame.cfsml"
- *hiteof = _cfsml_error;
+ *hiteof = _cfsml_error;
#line 860 "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 */
+ 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 598 "savegame.cfsml"
}
@@ -4446,359 +4330,353 @@ read_menubar_tp(FILE *fh, menubar_t **foo, const char *lastval, int *line, int *
}
void
-write_mem_obj_t(FILE *fh, mem_obj_t *foo)
-{
- fprintf(fh, "%s\n", mem_obj_string_names[foo->type].name);
+write_mem_obj_t(FILE *fh, mem_obj_t *foo) {
+ fprintf(fh, "%s\n", mem_obj_string_names[foo->type].name);
#line 878 "savegame.cfsml"
-/* Auto-generated CFSML data writer code */
- _cfsml_write_int(fh, &foo->segmgr_id);
- fprintf(fh, "\n");
-/* End of auto-generated CFSML data writer code */
+ /* Auto-generated CFSML data writer code */
+ _cfsml_write_int(fh, &foo->segmgr_id);
+ fprintf(fh, "\n");
+ /* End of auto-generated CFSML data writer code */
#line 608 "savegame.cfsml"
- switch (foo->type)
- {
+ switch (foo->type) {
case MEM_OBJ_SCRIPT:
#line 878 "savegame.cfsml"
-/* Auto-generated CFSML data writer code */
- _cfsml_write_script_t(fh, &foo->data.script);
- fprintf(fh, "\n");
-/* End of auto-generated CFSML data writer code */
+ /* Auto-generated CFSML data writer code */
+ _cfsml_write_script_t(fh, &foo->data.script);
+ fprintf(fh, "\n");
+ /* End of auto-generated CFSML data writer code */
#line 612 "savegame.cfsml"
- break;
+ break;
case MEM_OBJ_CLONES:
#line 878 "savegame.cfsml"
-/* Auto-generated CFSML data writer code */
- _cfsml_write_clone_table_t(fh, &foo->data.clones);
- fprintf(fh, "\n");
-/* End of auto-generated CFSML data writer code */
+ /* Auto-generated CFSML data writer code */
+ _cfsml_write_clone_table_t(fh, &foo->data.clones);
+ fprintf(fh, "\n");
+ /* End of auto-generated CFSML data writer code */
#line 615 "savegame.cfsml"
- break;
+ break;
case MEM_OBJ_LOCALS:
#line 878 "savegame.cfsml"
-/* Auto-generated CFSML data writer code */
- _cfsml_write_local_variables_t(fh, &foo->data.locals);
- fprintf(fh, "\n");
-/* End of auto-generated CFSML data writer code */
+ /* Auto-generated CFSML data writer code */
+ _cfsml_write_local_variables_t(fh, &foo->data.locals);
+ fprintf(fh, "\n");
+ /* End of auto-generated CFSML data writer code */
#line 618 "savegame.cfsml"
- break;
+ break;
case MEM_OBJ_SYS_STRINGS:
#line 878 "savegame.cfsml"
-/* Auto-generated CFSML data writer code */
- _cfsml_write_sys_strings_t(fh, &foo->data.sys_strings);
- fprintf(fh, "\n");
-/* End of auto-generated CFSML data writer code */
+ /* Auto-generated CFSML data writer code */
+ _cfsml_write_sys_strings_t(fh, &foo->data.sys_strings);
+ fprintf(fh, "\n");
+ /* End of auto-generated CFSML data writer code */
#line 621 "savegame.cfsml"
- break;
+ break;
case MEM_OBJ_STACK:
#line 878 "savegame.cfsml"
-/* Auto-generated CFSML data writer code */
- _cfsml_write_int(fh, &foo->data.stack.nr);
- fprintf(fh, "\n");
-/* End of auto-generated CFSML data writer code */
+ /* Auto-generated CFSML data writer code */
+ _cfsml_write_int(fh, &foo->data.stack.nr);
+ fprintf(fh, "\n");
+ /* End of auto-generated CFSML data writer code */
#line 624 "savegame.cfsml"
- break;
+ break;
case MEM_OBJ_HUNK:
break;
- case MEM_OBJ_LISTS:
+ case MEM_OBJ_LISTS:
#line 878 "savegame.cfsml"
-/* Auto-generated CFSML data writer code */
- _cfsml_write_list_table_t(fh, &foo->data.lists);
- fprintf(fh, "\n");
-/* End of auto-generated CFSML data writer code */
+ /* Auto-generated CFSML data writer code */
+ _cfsml_write_list_table_t(fh, &foo->data.lists);
+ fprintf(fh, "\n");
+ /* End of auto-generated CFSML data writer code */
#line 629 "savegame.cfsml"
- break;
- case MEM_OBJ_NODES:
+ break;
+ case MEM_OBJ_NODES:
#line 878 "savegame.cfsml"
-/* Auto-generated CFSML data writer code */
- _cfsml_write_node_table_t(fh, &foo->data.nodes);
- fprintf(fh, "\n");
-/* End of auto-generated CFSML data writer code */
+ /* Auto-generated CFSML data writer code */
+ _cfsml_write_node_table_t(fh, &foo->data.nodes);
+ fprintf(fh, "\n");
+ /* End of auto-generated CFSML data writer code */
#line 632 "savegame.cfsml"
- break;
+ break;
case MEM_OBJ_DYNMEM:
#line 878 "savegame.cfsml"
-/* Auto-generated CFSML data writer code */
- _cfsml_write_dynmem_t(fh, &foo->data.dynmem);
- fprintf(fh, "\n");
-/* End of auto-generated CFSML data writer code */
+ /* Auto-generated CFSML data writer code */
+ _cfsml_write_dynmem_t(fh, &foo->data.dynmem);
+ fprintf(fh, "\n");
+ /* End of auto-generated CFSML data writer code */
#line 635 "savegame.cfsml"
- break;
+ break;
}
}
int
-read_mem_obj_t(FILE *fh, mem_obj_t *foo, const char *lastval, int *line, int *hiteof)
-{
+read_mem_obj_t(FILE *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)
- {
+ if (foo->type < 0) {
sciprintf("Unknown mem_obj_t type %s on line %d\n", lastval, *line);
return 1;
}
-/* Auto-generated CFSML data reader code */
+ /* Auto-generated CFSML data reader code */
#line 824 "savegame.cfsml"
- {
+ {
#line 835 "savegame.cfsml"
- int _cfsml_eof = 0, _cfsml_error;
- int dummy;
+ int _cfsml_eof = 0, _cfsml_error;
+ int dummy;
#line 843 "savegame.cfsml"
- const char *_cfsml_inp = _cfsml_get_identifier(fh, &(*line), &_cfsml_eof, &dummy);
+ const char *_cfsml_inp = _cfsml_get_identifier(fh, &(*line), &_cfsml_eof, &dummy);
#line 848 "savegame.cfsml"
- _cfsml_error = _cfsml_read_int(fh, &foo->segmgr_id, _cfsml_inp, &(*line), &_cfsml_eof);
+ _cfsml_error = _cfsml_read_int(fh, &foo->segmgr_id, _cfsml_inp, &(*line), &_cfsml_eof);
#line 853 "savegame.cfsml"
- *hiteof = _cfsml_error;
+ *hiteof = _cfsml_error;
#line 860 "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 */
+ 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 651 "savegame.cfsml"
- switch (foo->type)
- {
+ switch (foo->type) {
case MEM_OBJ_SCRIPT:
-/* Auto-generated CFSML data reader code */
+ /* Auto-generated CFSML data reader code */
#line 824 "savegame.cfsml"
- {
+ {
#line 835 "savegame.cfsml"
- int _cfsml_eof = 0, _cfsml_error;
- int dummy;
+ int _cfsml_eof = 0, _cfsml_error;
+ int dummy;
#line 843 "savegame.cfsml"
- const char *_cfsml_inp = _cfsml_get_identifier(fh, &(*line), &_cfsml_eof, &dummy);
+ const char *_cfsml_inp = _cfsml_get_identifier(fh, &(*line), &_cfsml_eof, &dummy);
#line 848 "savegame.cfsml"
- _cfsml_error = _cfsml_read_script_t(fh, &foo->data.script, _cfsml_inp, &(*line), &_cfsml_eof);
+ _cfsml_error = _cfsml_read_script_t(fh, &foo->data.script, _cfsml_inp, &(*line), &_cfsml_eof);
#line 853 "savegame.cfsml"
- *hiteof = _cfsml_error;
+ *hiteof = _cfsml_error;
#line 860 "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 */
+ 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 655 "savegame.cfsml"
- break;
+ break;
case MEM_OBJ_CLONES:
-/* Auto-generated CFSML data reader code */
+ /* Auto-generated CFSML data reader code */
#line 824 "savegame.cfsml"
- {
+ {
#line 835 "savegame.cfsml"
- int _cfsml_eof = 0, _cfsml_error;
- int dummy;
+ int _cfsml_eof = 0, _cfsml_error;
+ int dummy;
#line 843 "savegame.cfsml"
- const char *_cfsml_inp = _cfsml_get_identifier(fh, &(*line), &_cfsml_eof, &dummy);
+ const char *_cfsml_inp = _cfsml_get_identifier(fh, &(*line), &_cfsml_eof, &dummy);
#line 848 "savegame.cfsml"
- _cfsml_error = _cfsml_read_clone_table_t(fh, &foo->data.clones, _cfsml_inp, &(*line), &_cfsml_eof);
+ _cfsml_error = _cfsml_read_clone_table_t(fh, &foo->data.clones, _cfsml_inp, &(*line), &_cfsml_eof);
#line 853 "savegame.cfsml"
- *hiteof = _cfsml_error;
+ *hiteof = _cfsml_error;
#line 860 "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 */
+ 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 658 "savegame.cfsml"
- break;
+ break;
case MEM_OBJ_LOCALS:
-/* Auto-generated CFSML data reader code */
+ /* Auto-generated CFSML data reader code */
#line 824 "savegame.cfsml"
- {
+ {
#line 835 "savegame.cfsml"
- int _cfsml_eof = 0, _cfsml_error;
- int dummy;
+ int _cfsml_eof = 0, _cfsml_error;
+ int dummy;
#line 843 "savegame.cfsml"
- const char *_cfsml_inp = _cfsml_get_identifier(fh, &(*line), &_cfsml_eof, &dummy);
+ const char *_cfsml_inp = _cfsml_get_identifier(fh, &(*line), &_cfsml_eof, &dummy);
#line 848 "savegame.cfsml"
- _cfsml_error = _cfsml_read_local_variables_t(fh, &foo->data.locals, _cfsml_inp, &(*line), &_cfsml_eof);
+ _cfsml_error = _cfsml_read_local_variables_t(fh, &foo->data.locals, _cfsml_inp, &(*line), &_cfsml_eof);
#line 853 "savegame.cfsml"
- *hiteof = _cfsml_error;
+ *hiteof = _cfsml_error;
#line 860 "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 */
+ 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 661 "savegame.cfsml"
- break;
+ break;
case MEM_OBJ_SYS_STRINGS:
-/* Auto-generated CFSML data reader code */
+ /* Auto-generated CFSML data reader code */
#line 824 "savegame.cfsml"
- {
+ {
#line 835 "savegame.cfsml"
- int _cfsml_eof = 0, _cfsml_error;
- int dummy;
+ int _cfsml_eof = 0, _cfsml_error;
+ int dummy;
#line 843 "savegame.cfsml"
- const char *_cfsml_inp = _cfsml_get_identifier(fh, &(*line), &_cfsml_eof, &dummy);
+ const char *_cfsml_inp = _cfsml_get_identifier(fh, &(*line), &_cfsml_eof, &dummy);
#line 848 "savegame.cfsml"
- _cfsml_error = _cfsml_read_sys_strings_t(fh, &foo->data.sys_strings, _cfsml_inp, &(*line), &_cfsml_eof);
+ _cfsml_error = _cfsml_read_sys_strings_t(fh, &foo->data.sys_strings, _cfsml_inp, &(*line), &_cfsml_eof);
#line 853 "savegame.cfsml"
- *hiteof = _cfsml_error;
+ *hiteof = _cfsml_error;
#line 860 "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 */
+ 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 664 "savegame.cfsml"
- break;
+ break;
case MEM_OBJ_LISTS:
-/* Auto-generated CFSML data reader code */
+ /* Auto-generated CFSML data reader code */
#line 824 "savegame.cfsml"
- {
+ {
#line 835 "savegame.cfsml"
- int _cfsml_eof = 0, _cfsml_error;
- int dummy;
+ int _cfsml_eof = 0, _cfsml_error;
+ int dummy;
#line 843 "savegame.cfsml"
- const char *_cfsml_inp = _cfsml_get_identifier(fh, &(*line), &_cfsml_eof, &dummy);
+ const char *_cfsml_inp = _cfsml_get_identifier(fh, &(*line), &_cfsml_eof, &dummy);
#line 848 "savegame.cfsml"
- _cfsml_error = _cfsml_read_list_table_t(fh, &foo->data.lists, _cfsml_inp, &(*line), &_cfsml_eof);
+ _cfsml_error = _cfsml_read_list_table_t(fh, &foo->data.lists, _cfsml_inp, &(*line), &_cfsml_eof);
#line 853 "savegame.cfsml"
- *hiteof = _cfsml_error;
+ *hiteof = _cfsml_error;
#line 860 "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 */
+ 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 667 "savegame.cfsml"
- break;
+ break;
case MEM_OBJ_NODES:
-/* Auto-generated CFSML data reader code */
+ /* Auto-generated CFSML data reader code */
#line 824 "savegame.cfsml"
- {
+ {
#line 835 "savegame.cfsml"
- int _cfsml_eof = 0, _cfsml_error;
- int dummy;
+ int _cfsml_eof = 0, _cfsml_error;
+ int dummy;
#line 843 "savegame.cfsml"
- const char *_cfsml_inp = _cfsml_get_identifier(fh, &(*line), &_cfsml_eof, &dummy);
+ const char *_cfsml_inp = _cfsml_get_identifier(fh, &(*line), &_cfsml_eof, &dummy);
#line 848 "savegame.cfsml"
- _cfsml_error = _cfsml_read_node_table_t(fh, &foo->data.nodes, _cfsml_inp, &(*line), &_cfsml_eof);
+ _cfsml_error = _cfsml_read_node_table_t(fh, &foo->data.nodes, _cfsml_inp, &(*line), &_cfsml_eof);
#line 853 "savegame.cfsml"
- *hiteof = _cfsml_error;
+ *hiteof = _cfsml_error;
#line 860 "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 */
+ 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 670 "savegame.cfsml"
- break;
+ break;
case MEM_OBJ_STACK:
-/* Auto-generated CFSML data reader code */
+ /* Auto-generated CFSML data reader code */
#line 824 "savegame.cfsml"
- {
+ {
#line 835 "savegame.cfsml"
- int _cfsml_eof = 0, _cfsml_error;
- int dummy;
+ int _cfsml_eof = 0, _cfsml_error;
+ int dummy;
#line 843 "savegame.cfsml"
- const char *_cfsml_inp = _cfsml_get_identifier(fh, &(*line), &_cfsml_eof, &dummy);
+ const char *_cfsml_inp = _cfsml_get_identifier(fh, &(*line), &_cfsml_eof, &dummy);
#line 848 "savegame.cfsml"
- _cfsml_error = _cfsml_read_int(fh, &foo->data.stack.nr, _cfsml_inp, &(*line), &_cfsml_eof);
+ _cfsml_error = _cfsml_read_int(fh, &foo->data.stack.nr, _cfsml_inp, &(*line), &_cfsml_eof);
#line 853 "savegame.cfsml"
- *hiteof = _cfsml_error;
+ *hiteof = _cfsml_error;
#line 860 "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 */
+ 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 673 "savegame.cfsml"
- foo->data.stack.entries = (reg_t *)sci_calloc(foo->data.stack.nr, sizeof(reg_t));
- break;
+ foo->data.stack.entries = (reg_t *)sci_calloc(foo->data.stack.nr, sizeof(reg_t));
+ break;
case MEM_OBJ_HUNK:
init_hunk_table(&foo->data.hunks);
break;
case MEM_OBJ_DYNMEM:
-/* Auto-generated CFSML data reader code */
+ /* Auto-generated CFSML data reader code */
#line 824 "savegame.cfsml"
- {
+ {
#line 835 "savegame.cfsml"
- int _cfsml_eof = 0, _cfsml_error;
- int dummy;
+ int _cfsml_eof = 0, _cfsml_error;
+ int dummy;
#line 843 "savegame.cfsml"
- const char *_cfsml_inp = _cfsml_get_identifier(fh, &(*line), &_cfsml_eof, &dummy);
+ const char *_cfsml_inp = _cfsml_get_identifier(fh, &(*line), &_cfsml_eof, &dummy);
#line 848 "savegame.cfsml"
- _cfsml_error = _cfsml_read_dynmem_t(fh, &foo->data.dynmem, _cfsml_inp, &(*line), &_cfsml_eof);
+ _cfsml_error = _cfsml_read_dynmem_t(fh, &foo->data.dynmem, _cfsml_inp, &(*line), &_cfsml_eof);
#line 853 "savegame.cfsml"
- *hiteof = _cfsml_error;
+ *hiteof = _cfsml_error;
#line 860 "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 */
+ 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 680 "savegame.cfsml"
- break;
+ break;
}
return *hiteof;
}
void
-write_mem_obj_tp(FILE *fh, mem_obj_t **foo)
-{
+write_mem_obj_tp(FILE *fh, mem_obj_t **foo) {
if (*foo) {
#line 878 "savegame.cfsml"
-/* Auto-generated CFSML data writer code */
- write_mem_obj_t(fh, (*foo));
- fprintf(fh, "\n");
-/* End of auto-generated CFSML data writer code */
+ /* Auto-generated CFSML data writer code */
+ write_mem_obj_t(fh, (*foo));
+ fprintf(fh, "\n");
+ /* End of auto-generated CFSML data writer code */
#line 692 "savegame.cfsml"
} else { /* Nothing to write */
@@ -4807,36 +4685,35 @@ 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)
-{
+read_mem_obj_tp(FILE *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 */
+ /* Auto-generated CFSML data reader code */
#line 824 "savegame.cfsml"
- {
+ {
#line 835 "savegame.cfsml"
- int _cfsml_eof = 0, _cfsml_error;
- int dummy;
+ int _cfsml_eof = 0, _cfsml_error;
+ int dummy;
#line 840 "savegame.cfsml"
- const char *_cfsml_inp = lastval;
+ const char *_cfsml_inp = lastval;
#line 848 "savegame.cfsml"
- _cfsml_error = read_mem_obj_t(fh, (*foo), _cfsml_inp, &(*line), &_cfsml_eof);
+ _cfsml_error = read_mem_obj_t(fh, (*foo), _cfsml_inp, &(*line), &_cfsml_eof);
#line 853 "savegame.cfsml"
- *hiteof = _cfsml_error;
+ *hiteof = _cfsml_error;
#line 860 "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 */
+ 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 707 "savegame.cfsml"
return *hiteof;
}
@@ -4849,14 +4726,12 @@ read_mem_obj_tp(FILE *fh, mem_obj_t **foo, const char *lastval, int *line, int *
** to writing a gamestate to disk
*/
void
-_gamestate_unfrob(state_t *s)
-{
+_gamestate_unfrob(state_t *s) {
}
int
-gamestate_save(state_t *s, char *dirname)
-{
+gamestate_save(state_t *s, char *dirname) {
FILE *fh;
sci_dir_t dir;
char *filename;
@@ -4864,18 +4739,18 @@ gamestate_save(state_t *s, char *dirname)
_global_save_state = s;
s->savegame_version = FREESCI_CURRENT_SAVEGAME_VERSION;
- s->dyn_views_list_serial = (s->dyn_views)? s->dyn_views->serial : -2;
- s->drop_views_list_serial = (s->drop_views)? s->drop_views->serial : -2;
- s->port_serial = (s->port)? s->port->serial : -2;
+ s->dyn_views_list_serial = (s->dyn_views) ? s->dyn_views->serial : -2;
+ s->drop_views_list_serial = (s->drop_views) ? s->drop_views->serial : -2;
+ s->port_serial = (s->port) ? s->port->serial : -2;
if (s->execution_stack_base) {
sciprintf("Cannot save from below kernel function\n");
return 1;
}
- scimkdir (dirname, 0700);
+ scimkdir(dirname, 0700);
- if (chdir (dirname)) {
+ if (chdir(dirname)) {
sciprintf("Could not enter directory '%s'\n", dirname);
return 1;
}
@@ -4889,53 +4764,51 @@ gamestate_save(state_t *s, char *dirname)
}
sci_finish_find(&dir);
-/*
- if (s->sound_server) {
- if ((s->sound_server->save)(s, dirname)) {
- sciprintf("Saving failed for the sound subsystem\n");
- chdir ("..");
- return 1;
+ /*
+ if (s->sound_server) {
+ if ((s->sound_server->save)(s, dirname)) {
+ sciprintf("Saving failed for the sound subsystem\n");
+ chdir ("..");
+ return 1;
+ }
}
- }
-*/
+ */
fh = fopen("state", "w" FO_TEXT);
/* Calculate the time spent with this game */
s->game_time = time(NULL) - s->game_start_time.tv_sec;
-SCI_MEMTEST;
+ SCI_MEMTEST;
#line 878 "savegame.cfsml"
-/* Auto-generated CFSML data writer code */
- _cfsml_write_state_t(fh, s);
- fprintf(fh, "\n");
-/* End of auto-generated CFSML data writer code */
+ /* Auto-generated CFSML data writer code */
+ _cfsml_write_state_t(fh, s);
+ fprintf(fh, "\n");
+ /* End of auto-generated CFSML data writer code */
#line 774 "savegame.cfsml"
-SCI_MEMTEST;
+ SCI_MEMTEST;
fclose(fh);
_gamestate_unfrob(s);
- chdir ("..");
+ chdir("..");
return 0;
}
static seg_id_t
-find_unique_seg_by_type(seg_manager_t *self, int type)
-{
+find_unique_seg_by_type(seg_manager_t *self, int type) {
int i;
for (i = 0; i < self->heap_size; i++)
if (self->heap[i] &&
- self->heap[i]->type == type)
+ self->heap[i]->type == type)
return i;
return -1;
}
static byte *
-find_unique_script_block(state_t *s, byte *buf, int type)
-{
+find_unique_script_block(state_t *s, byte *buf, int type) {
int magic_pos_adder = s->version >= SCI_VERSION_FTU_NEW_SCRIPT_HEADER ? 0 : 2;
buf += magic_pos_adder;
@@ -4948,14 +4821,13 @@ find_unique_script_block(state_t *s, byte *buf, int type)
seeker_size = getUInt16(buf + 2);
buf += seeker_size;
- } while(1);
+ } while (1);
return NULL;
}
static
-void reconstruct_stack(state_t *retval)
-{
+void reconstruct_stack(state_t *retval) {
seg_id_t stack_seg = find_unique_seg_by_type(&retval->seg_manager, MEM_OBJ_STACK);
dstack_t *stack = &(retval->seg_manager.heap[stack_seg]->data.stack);
@@ -4965,8 +4837,7 @@ void reconstruct_stack(state_t *retval)
}
static
-int clone_entry_used(clone_table_t *table, int n)
-{
+int clone_entry_used(clone_table_t *table, int n) {
int backup;
int seeker = table->first_free;
clone_entry_t *entries = table->table;
@@ -4983,50 +4854,44 @@ int clone_entry_used(clone_table_t *table, int n)
}
static
-void load_script(state_t *s, seg_id_t seg)
-{
+void load_script(state_t *s, seg_id_t seg) {
resource_t *script, *heap;
script_t *scr = &(s->seg_manager.heap[seg]->data.script);
scr->buf = (byte *) malloc(scr->buf_size);
script = scir_find_resource(s->resmgr, sci_script, scr->nr, 0);
- if (s->version >= SCI_VERSION(1,001,000))
+ if (s->version >= SCI_VERSION(1, 001, 000))
heap = scir_find_resource(s->resmgr, sci_heap, scr->nr, 0);
- switch (s->seg_manager.sci1_1)
- {
+ switch (s->seg_manager.sci1_1) {
case 0 :
- sm_mcpy_in_out( &s->seg_manager, 0, script->data, script->size, seg, SEG_ID);
+ sm_mcpy_in_out(&s->seg_manager, 0, script->data, script->size, seg, SEG_ID);
break;
case 1 :
- sm_mcpy_in_out( &s->seg_manager, 0, script->data, script->size, seg, SEG_ID);
- sm_mcpy_in_out( &s->seg_manager, scr->script_size, heap->data, heap->size, seg, SEG_ID);
+ sm_mcpy_in_out(&s->seg_manager, 0, script->data, script->size, seg, SEG_ID);
+ sm_mcpy_in_out(&s->seg_manager, scr->script_size, heap->data, heap->size, seg, SEG_ID);
break;
}
}
static
-void reconstruct_scripts(state_t *s, seg_manager_t *self)
-{
+void reconstruct_scripts(state_t *s, seg_manager_t *self) {
int i;
mem_obj_t *mobj;
object_t **objects;
int *objects_nr;
for (i = 0; i < self->heap_size; i++)
- if (self->heap[i])
- {
+ if (self->heap[i]) {
mobj = self->heap[i];
- switch (mobj->type)
- {
- case MEM_OBJ_SCRIPT:
- {
+ switch (mobj->type) {
+ case MEM_OBJ_SCRIPT: {
int j;
script_t *scr = &mobj->data.script;
load_script(s, i);
scr->locals_block = scr->locals_segment == 0 ? NULL :
- &s->seg_manager.heap[scr->locals_segment]->data.locals;
+ &s->seg_manager.heap[scr->locals_segment]->data.locals;
scr->export_table = (guint16 *) find_unique_script_block(s, scr->buf, sci_obj_exports);
scr->synonyms = find_unique_script_block(s, scr->buf, sci_obj_synonyms);
scr->code = NULL;
@@ -5035,9 +4900,8 @@ void reconstruct_scripts(state_t *s, seg_manager_t *self)
if (!self->sci1_1)
scr->export_table += 3;
-
- for (j = 0; j < scr->objects_nr; j++)
- {
+
+ for (j = 0; j < scr->objects_nr; j++) {
byte *data = scr->buf + scr->objects[j].pos.offset;
scr->objects[j].base = scr->buf;
scr->objects[j].base_obj = data;
@@ -5048,45 +4912,38 @@ void reconstruct_scripts(state_t *s, seg_manager_t *self)
}
for (i = 0; i < self->heap_size; i++)
- if (self->heap[i])
- {
+ if (self->heap[i]) {
mobj = self->heap[i];
- switch (mobj->type)
- {
- case MEM_OBJ_SCRIPT:
- {
+ switch (mobj->type) {
+ case MEM_OBJ_SCRIPT: {
int j;
script_t *scr = &mobj->data.script;
- for (j = 0; j < scr->objects_nr; j++)
- {
+ for (j = 0; j < scr->objects_nr; j++) {
byte *data = scr->buf + scr->objects[j].pos.offset;
- if (self->sci1_1)
- {
- guint16 *funct_area = (guint16 *) (scr->buf + getUInt16( data + 6 ));
- guint16 *prop_area = (guint16 *) (scr->buf + getUInt16( data + 4 ));
+ if (self->sci1_1) {
+ guint16 *funct_area = (guint16 *)(scr->buf + getUInt16(data + 6));
+ guint16 *prop_area = (guint16 *)(scr->buf + getUInt16(data + 4));
scr->objects[j].base_method = funct_area;
scr->objects[j].base_vars = prop_area;
- } else
- {
- int funct_area = getUInt16( data + SCRIPT_FUNCTAREAPTR_OFFSET );
+ } else {
+ int funct_area = getUInt16(data + SCRIPT_FUNCTAREAPTR_OFFSET);
object_t *base_obj;
base_obj = obj_get(s, scr->objects[j].variables[SCRIPT_SPECIES_SELECTOR]);
- if (!base_obj)
- {
+ if (!base_obj) {
sciprintf("Object without a base class: Script %d, index %d (reg address "PREG"\n",
- scr->nr, j, PRINT_REG(scr->objects[j].variables[SCRIPT_SPECIES_SELECTOR]));
+ scr->nr, j, PRINT_REG(scr->objects[j].variables[SCRIPT_SPECIES_SELECTOR]));
continue;
}
scr->objects[j].variable_names_nr = base_obj->variables_nr;
scr->objects[j].base_obj = base_obj->base_obj;
- scr->objects[j].base_method = (guint16 *) (data + funct_area);
- scr->objects[j].base_vars = (guint16 *) (data + scr->objects[j].variable_names_nr * 2 + SCRIPT_SELECTOR_OFFSET);
+ scr->objects[j].base_method = (guint16 *)(data + funct_area);
+ scr->objects[j].base_vars = (guint16 *)(data + scr->objects[j].variable_names_nr * 2 + SCRIPT_SELECTOR_OFFSET);
}
}
}
@@ -5095,50 +4952,42 @@ void reconstruct_scripts(state_t *s, seg_manager_t *self)
}
void
-reconstruct_clones(state_t *s, seg_manager_t *self)
-{
+reconstruct_clones(state_t *s, seg_manager_t *self) {
int i;
mem_obj_t *mobj;
for (i = 0; i < self->heap_size; i++)
- if (self->heap[i])
- {
+ if (self->heap[i]) {
mobj = self->heap[i];
- switch (mobj->type)
- {
- case MEM_OBJ_CLONES:
- {
+ switch (mobj->type) {
+ case MEM_OBJ_CLONES: {
int j;
clone_entry_t *seeker = mobj->data.clones.table;
-
+
sciprintf("Free list: ");
for (j = mobj->data.clones.first_free;
- j != HEAPENTRY_INVALID;
- j = mobj->data.clones.table[j].next_free)
- {
+ j != HEAPENTRY_INVALID;
+ j = mobj->data.clones.table[j].next_free) {
sciprintf("%d ", j);
}
sciprintf("\n");
sciprintf("Entries w/zero vars: ");
- for (j = 0; j < mobj->data.clones.max_entry; j++)
- {
+ for (j = 0; j < mobj->data.clones.max_entry; j++) {
if (mobj->data.clones.table[j].entry.variables == NULL)
sciprintf("%d ", j);
}
sciprintf("\n");
- for (j = 0; j < mobj->data.clones.max_entry; j++)
- {
- object_t *base_obj;
+ for (j = 0; j < mobj->data.clones.max_entry; j++) {
+ object_t *base_obj;
if (!clone_entry_used(&mobj->data.clones, j)) {
seeker++;
continue;
}
base_obj = obj_get(s, seeker->entry.variables[SCRIPT_SPECIES_SELECTOR]);
- if (!base_obj)
- {
+ if (!base_obj) {
sciprintf("Clone entry without a base class: %d\n", j);
seeker->entry.base = seeker->entry.base_obj = NULL;
seeker->entry.base_vars = seeker->entry.base_method = NULL;
@@ -5165,49 +5014,45 @@ song_iterator_t *
new_fast_forward_iterator(song_iterator_t *it, int delta);
static
-void reconstruct_sounds(state_t *s)
-{
- song_t *seeker;
- int it_type = s->resmgr->sci_version >= SCI_VERSION_01 ?
- SCI_SONG_ITERATOR_TYPE_SCI1
- : SCI_SONG_ITERATOR_TYPE_SCI0;
-
- if (s->sound.songlib.lib)
- seeker = *(s->sound.songlib.lib);
- else
- {
- song_lib_init(&s->sound.songlib);
- seeker = NULL;
- }
- while (seeker)
- {
- song_iterator_t *base, *ff;
- int oldstatus;
- song_iterator_message_t msg;
-
- base = ff = build_iterator(s, seeker->resource_num, it_type, seeker->handle);
- if (seeker->restore_behavior == RESTORE_BEHAVIOR_CONTINUE)
- ff = (song_iterator_t *) new_fast_forward_iterator(base, seeker->restore_time);
- ff->init(ff);
-
- msg = songit_make_message(seeker->handle, SIMSG_SET_LOOPS(seeker->loops));
- songit_handle_message(&ff, msg);
- msg = songit_make_message(seeker->handle, SIMSG_SET_HOLD(seeker->hold));
- songit_handle_message(&ff, msg);
-
-
- oldstatus = seeker->status;
- seeker->status = SOUND_STATUS_STOPPED;
- seeker->it = ff;
- sfx_song_set_status(&s->sound, seeker->handle, oldstatus);
- seeker = seeker->next;
- }
+void reconstruct_sounds(state_t *s) {
+ song_t *seeker;
+ int it_type = s->resmgr->sci_version >= SCI_VERSION_01 ?
+ SCI_SONG_ITERATOR_TYPE_SCI1
+ : SCI_SONG_ITERATOR_TYPE_SCI0;
+
+ if (s->sound.songlib.lib)
+ seeker = *(s->sound.songlib.lib);
+ else {
+ song_lib_init(&s->sound.songlib);
+ seeker = NULL;
+ }
+ while (seeker) {
+ song_iterator_t *base, *ff;
+ int oldstatus;
+ song_iterator_message_t msg;
+
+ base = ff = build_iterator(s, seeker->resource_num, it_type, seeker->handle);
+ if (seeker->restore_behavior == RESTORE_BEHAVIOR_CONTINUE)
+ ff = (song_iterator_t *) new_fast_forward_iterator(base, seeker->restore_time);
+ ff->init(ff);
+
+ msg = songit_make_message(seeker->handle, SIMSG_SET_LOOPS(seeker->loops));
+ songit_handle_message(&ff, msg);
+ msg = songit_make_message(seeker->handle, SIMSG_SET_HOLD(seeker->hold));
+ songit_handle_message(&ff, msg);
+
+
+ oldstatus = seeker->status;
+ seeker->status = SOUND_STATUS_STOPPED;
+ seeker->it = ff;
+ sfx_song_set_status(&s->sound, seeker->handle, oldstatus);
+ seeker = seeker->next;
+ }
}
state_t *
-gamestate_restore(state_t *s, char *dirname)
-{
+gamestate_restore(state_t *s, char *dirname) {
FILE *fh;
int fd;
int i;
@@ -5215,19 +5060,19 @@ gamestate_restore(state_t *s, char *dirname)
state_t *retval;
songlib_t temp;
- if (chdir (dirname)) {
+ 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)) {
- sciprintf("Restoring failed for the sound subsystem\n");
- return NULL;
+ /*
+ if (s->sound_server) {
+ if ((s->sound_server->restore)(s, dirname)) {
+ sciprintf("Restoring failed for the sound subsystem\n");
+ return NULL;
+ }
}
- }
-*/
+ */
retval = (state_t *) sci_malloc(sizeof(state_t));
@@ -5243,7 +5088,7 @@ gamestate_restore(state_t *s, char *dirname)
return NULL;
}
- /* Backwards compatibility settings */
+ /* Backwards compatibility settings */
retval->dyn_views = NULL;
retval->drop_views = NULL;
retval->port = NULL;
@@ -5252,42 +5097,42 @@ gamestate_restore(state_t *s, char *dirname)
retval->sound_mute = s->sound_mute;
retval->sound_volume = s->sound_volume;
-/* Auto-generated CFSML data reader code */
+ /* Auto-generated CFSML data reader code */
#line 824 "savegame.cfsml"
- {
+ {
#line 827 "savegame.cfsml"
- int _cfsml_line_ctr = 0;
+ int _cfsml_line_ctr = 0;
#line 832 "savegame.cfsml"
- struct _cfsml_pointer_refstruct **_cfsml_myptrrefptr = _cfsml_get_current_refpointer();
+ struct _cfsml_pointer_refstruct **_cfsml_myptrrefptr = _cfsml_get_current_refpointer();
#line 835 "savegame.cfsml"
- int _cfsml_eof = 0, _cfsml_error;
- int dummy;
+ int _cfsml_eof = 0, _cfsml_error;
+ int dummy;
#line 843 "savegame.cfsml"
- const char *_cfsml_inp = _cfsml_get_identifier(fh, &(_cfsml_line_ctr), &_cfsml_eof, &dummy);
+ const char *_cfsml_inp = _cfsml_get_identifier(fh, &(_cfsml_line_ctr), &_cfsml_eof, &dummy);
#line 848 "savegame.cfsml"
- _cfsml_error = _cfsml_read_state_t(fh, retval, _cfsml_inp, &(_cfsml_line_ctr), &_cfsml_eof);
+ _cfsml_error = _cfsml_read_state_t(fh, retval, _cfsml_inp, &(_cfsml_line_ctr), &_cfsml_eof);
#line 853 "savegame.cfsml"
- read_eof = _cfsml_error;
+ read_eof = _cfsml_error;
#line 857 "savegame.cfsml"
- _cfsml_free_pointer_references(_cfsml_myptrrefptr, _cfsml_error);
+ _cfsml_free_pointer_references(_cfsml_myptrrefptr, _cfsml_error);
#line 860 "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 */
+ 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 1117 "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) ||
+ (retval->savegame_version > FREESCI_CURRENT_SAVEGAME_VERSION)) {
if (retval->savegame_version < FREESCI_MINIMUM_SAVEGAME_VERSION)
sciprintf("Old savegame version detected- can't load\n");
@@ -5332,7 +5177,7 @@ gamestate_restore(state_t *s, char *dirname)
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);
+ s->sys_strings);
/* Time state: */
sci_get_current_time(&(retval->last_wait_time));
@@ -5389,7 +5234,7 @@ gamestate_restore(state_t *s, char *dirname)
retval->sound.debug = s->sound.debug;
reconstruct_sounds(retval);
- chdir ("..");
+ chdir("..");
return retval;
}
diff --git a/engines/sci/engine/scriptconsole.cpp b/engines/sci/engine/scriptconsole.cpp
index bb8c053317..c2318dc634 100644
--- a/engines/sci/engine/scriptconsole.cpp
+++ b/engines/sci/engine/scriptconsole.cpp
@@ -60,12 +60,11 @@ typedef cmd_mm_entry_t cmd_page_t; /* Simple info page */
typedef struct {
const char *name;
const char *description;
- int (*command) (state_t *);
+ int (*command)(state_t *);
const char *param;
} cmd_command_t;
-typedef struct
-{
+typedef struct {
const char *name;
const char *description;
union {
@@ -130,112 +129,101 @@ cmd_param_t *cmd_params;
#ifdef WITH_DMALLOC
int
-c_dm_stats (state_t * s)
-{
+c_dm_stats(state_t * s) {
dmalloc_log_stats();
return 0;
}
int
-c_dm_log_unfreed (state_t * s)
-{
+c_dm_log_unfreed(state_t * s) {
dmalloc_log_unfreed();
return 0;
}
int
-c_dm_verify (state_t * s)
-{
+c_dm_verify(state_t * s) {
unsigned long pointer_var;
void *ptr;
- pointer_var = strtoul (cmd_params[0].str, NULL, 0);
+ pointer_var = strtoul(cmd_params[0].str, NULL, 0);
ptr = (void *) pointer_var;
- dmalloc_verify (ptr);
+ dmalloc_verify(ptr);
return 0;
}
int
-c_dm_debug (state_t * s)
-{
+c_dm_debug(state_t * s) {
if (cmd_paramlength) {
- long newval = strtol (cmd_params[0].str, NULL, 0);
+ long newval = strtol(cmd_params[0].str, NULL, 0);
- sciprintf ("Setting dmalloc_debug(%ld)\n", newval);
- dmalloc_debug (newval);
- }
- else
- sciprintf ("dmalloc_debug is at 0x%lx\n", dmalloc_debug_current());
+ sciprintf("Setting dmalloc_debug(%ld)\n", newval);
+ dmalloc_debug(newval);
+ } else
+ sciprintf("dmalloc_debug is at 0x%lx\n", dmalloc_debug_current());
return 0;
}
int
-c_dm_mark (state_t * s)
-{
+c_dm_mark(state_t * s) {
unsigned long mark = dmalloc_mark();
- dmalloc_message ("------------- MARK 0x%lx ---------------\n", mark);
- sciprintf ("mark 0x%lx\n", mark);
+ dmalloc_message("------------- MARK 0x%lx ---------------\n", mark);
+ sciprintf("mark 0x%lx\n", mark);
return 0;
}
int
-c_dm_chmark (state_t * s)
-{
- unsigned long mark = strtoul (cmd_params[0].str, NULL, 0);
- sciprintf ("Checking mark 0x%lx\n", mark);
- dmalloc_message ("--- Mark 0x%lx:\n", mark);
- dmalloc_log_changed (mark, 1, 1, 1);
+c_dm_chmark(state_t * s) {
+ unsigned long mark = strtoul(cmd_params[0].str, NULL, 0);
+ sciprintf("Checking mark 0x%lx\n", mark);
+ dmalloc_message("--- Mark 0x%lx:\n", mark);
+ dmalloc_log_changed(mark, 1, 1, 1);
return 0;
}
int
-c_dm_print (state_t * s)
-{
+c_dm_print(state_t * s) {
int i;
for (i = 0; i < cmd_paramlength; i++)
- dmalloc_message ("%s\n", cmd_params[i].str);
+ dmalloc_message("%s\n", cmd_params[i].str);
return 0;
}
void
-con_init_dmalloc()
-{
- con_hook_command (c_dm_stats, "dm_stats", "",
- "Prints memory usage stats\n to the dmalloc output file\n\n dm_stats");
- con_hook_command (c_dm_log_unfreed, "dm_log_unfreed", "",
- "Prints unfreed pointer\n information to the dmalloc\n output file\n\n"
- "USAGE\n\n dm_log_unfreed");
- con_hook_command (c_dm_verify, "dm_verify", "s",
- "Verifies one pointer,\n prints output to dmalloc file\n\nUSAGE\n\n"
- " dm_verify <ptr>\n dm_verify 0\n\n 'dm_verify 0' will verify\n ALL current pointers.\n");
- con_hook_command (c_dm_debug, "dm_debug", "s*",
- "Sets the dmalloc debug\n state or displays it\n\nUSAGE\n\n dm_debug <mode>\n dm_debug");
- con_hook_command (c_dm_mark, "dm_mark", "",
- "Gets a mark describing\n the current heap state\n\nUSAGE\n\n dm_mark\n\n"
- " The mark is written to the\n dmalloc output file and\n to sci output.\n\nSEE ALSO\n\n cm_chmark");
- con_hook_command (c_dm_chmark, "dm_chmark", "s",
- "Checks changes in the\n heap state since a certain\n mark was retrieved\n\n"
- "USAGE\n\n c_dm_chmark <mark>\n\n Output is written to the\n dmalloc output file.\n\n Use dm_mark to retrieve a\n"
- " mark.\n\nSEE ALSO\n\n c_dm_mark");
- con_hook_command (c_dm_print, "dm_print", "s*",
- "Prints something to the\n dmalloc output.\n\nUSAGE\n\n dm_print <text>");
+con_init_dmalloc() {
+ con_hook_command(c_dm_stats, "dm_stats", "",
+ "Prints memory usage stats\n to the dmalloc output file\n\n dm_stats");
+ con_hook_command(c_dm_log_unfreed, "dm_log_unfreed", "",
+ "Prints unfreed pointer\n information to the dmalloc\n output file\n\n"
+ "USAGE\n\n dm_log_unfreed");
+ con_hook_command(c_dm_verify, "dm_verify", "s",
+ "Verifies one pointer,\n prints output to dmalloc file\n\nUSAGE\n\n"
+ " dm_verify <ptr>\n dm_verify 0\n\n 'dm_verify 0' will verify\n ALL current pointers.\n");
+ con_hook_command(c_dm_debug, "dm_debug", "s*",
+ "Sets the dmalloc debug\n state or displays it\n\nUSAGE\n\n dm_debug <mode>\n dm_debug");
+ con_hook_command(c_dm_mark, "dm_mark", "",
+ "Gets a mark describing\n the current heap state\n\nUSAGE\n\n dm_mark\n\n"
+ " The mark is written to the\n dmalloc output file and\n to sci output.\n\nSEE ALSO\n\n cm_chmark");
+ con_hook_command(c_dm_chmark, "dm_chmark", "s",
+ "Checks changes in the\n heap state since a certain\n mark was retrieved\n\n"
+ "USAGE\n\n c_dm_chmark <mark>\n\n Output is written to the\n dmalloc output file.\n\n Use dm_mark to retrieve a\n"
+ " mark.\n\nSEE ALSO\n\n c_dm_mark");
+ con_hook_command(c_dm_print, "dm_print", "s*",
+ "Prints something to the\n dmalloc output.\n\nUSAGE\n\n dm_print <text>");
}
#else /* WITH_DMALLOC */
void
-con_init_dmalloc (void)
-{
+con_init_dmalloc(void) {
}
#endif /* WITH_DMALLOC */
void
-_cmd_exit (void)
-{
+_cmd_exit(void) {
int t;
for (t = 0; t < CMD_MM_ENTRIES; t++)
@@ -243,8 +231,7 @@ _cmd_exit (void)
}
static cmd_mm_entry_t *
-cmd_mm_find(char *name, int type)
-{
+cmd_mm_find(char *name, int type) {
int i;
for (i = 0; i < cmd_mm[type].entries; i++)
@@ -255,27 +242,24 @@ cmd_mm_find(char *name, int type)
}
static int
-_cmd_mm_comp (const void *a, const void *b)
-{
- return strcmp (((cmd_mm_entry_t *) a)->name, ((cmd_mm_entry_t *) b)->name);
+_cmd_mm_comp(const void *a, const void *b) {
+ return strcmp(((cmd_mm_entry_t *) a)->name, ((cmd_mm_entry_t *) b)->name);
}
void
-con_sort_all (void)
-{
+con_sort_all(void) {
int i;
for (i = 0; i < CMD_MM_ENTRIES; i++)
if (cmd_mm[i].entries && _lists_need_sorting & (1 << i))
- qsort (cmd_mm[i].data, cmd_mm[i].entries, cmd_mm[i].size_per_entry,
- _cmd_mm_comp);
+ qsort(cmd_mm[i].data, cmd_mm[i].entries, cmd_mm[i].size_per_entry,
+ _cmd_mm_comp);
_lists_need_sorting = 0;
}
void
-con_init (void)
-{
+con_init(void) {
if (!_cmd_initialized) {
int i;
@@ -288,70 +272,68 @@ con_init (void)
cmd_mm[i].data = sci_calloc(cmd_mm[i].allocated, cmd_mm[i].size_per_entry);
cmd_mm[i].print = cmd_mm_printers[i];
}
-
- atexit (_cmd_exit);
+
+ atexit(_cmd_exit);
/* Hook up some commands */
- con_hook_command (&c_version, "version", "",
- "Displays the version number");
- con_hook_command (&c_list, "list", "s*",
- "Lists various things (try 'list')");
- con_hook_command (&c_man, "man", "s",
- "Gives a short description of something");
- con_hook_command (&c_print, "print", "s", "Prints an int variable");
- con_hook_command (&c_set, "set", "si", "Sets an int variable");
- con_hook_command (&c_size, "size", "si",
- "Displays the size of a resource");
- con_hook_command (&c_dump, "dump", "si", "HexDumps a resource");
- con_hook_command (&c_hexgrep, "hexgrep", "shh*",
- "Searches some resources for a\n"
- " particular sequence of bytes, re-\n presented"
- " as hexadecimal numbers.\n\n"
- "EXAMPLES:\n hexgrep script e8 03 c8 00\n"
- " hexgrep pic.042 fe");
- con_hook_command (&c_dissectscript, "dissectscript", "i",
- "Examines a script.");
+ con_hook_command(&c_version, "version", "",
+ "Displays the version number");
+ con_hook_command(&c_list, "list", "s*",
+ "Lists various things (try 'list')");
+ con_hook_command(&c_man, "man", "s",
+ "Gives a short description of something");
+ con_hook_command(&c_print, "print", "s", "Prints an int variable");
+ con_hook_command(&c_set, "set", "si", "Sets an int variable");
+ con_hook_command(&c_size, "size", "si",
+ "Displays the size of a resource");
+ con_hook_command(&c_dump, "dump", "si", "HexDumps a resource");
+ con_hook_command(&c_hexgrep, "hexgrep", "shh*",
+ "Searches some resources for a\n"
+ " particular sequence of bytes, re-\n presented"
+ " as hexadecimal numbers.\n\n"
+ "EXAMPLES:\n hexgrep script e8 03 c8 00\n"
+ " hexgrep pic.042 fe");
+ con_hook_command(&c_dissectscript, "dissectscript", "i",
+ "Examines a script.");
con_hook_page("addresses",
- "Passing address parameters\n\n"
- " Address parameters may be passed in one of\n"
- " three forms:\n"
- " - ssss:oooo -- where 'ssss' denotes a\n"
- " segment and 'oooo' an offset. Example:\n"
- " \"a:c5\" would address something in seg-\n"
- " ment 0xa at offset 0xc5.\n"
- " - &scr:oooo -- where 'scr' is a script number\n"
- " and oooo an offset within that script; will\n"
- " fail if the script is not currently loaded\n"
- " - $REG -- where 'REG' is one of 'PC', 'ACC',\n"
- " 'PREV' or 'OBJ': References the address\n"
- " indicated by the register of this name.\n"
- " - $REG+n (or -n) -- Like $REG, but modifies\n"
- " the offset part by a specific amount (which\n"
- " is specified in hexadecimal).\n"
- " - ?obj -- Looks up an object with the specified\n"
- " name, uses its address. This will abort if\n"
- " the object name is ambiguous; in that case,\n"
- " a list of addresses and indices is provided.\n"
- " ?obj.idx may be used to disambiguate 'obj'\n"
- " by the index 'idx'.\n");
+ "Passing address parameters\n\n"
+ " Address parameters may be passed in one of\n"
+ " three forms:\n"
+ " - ssss:oooo -- where 'ssss' denotes a\n"
+ " segment and 'oooo' an offset. Example:\n"
+ " \"a:c5\" would address something in seg-\n"
+ " ment 0xa at offset 0xc5.\n"
+ " - &scr:oooo -- where 'scr' is a script number\n"
+ " and oooo an offset within that script; will\n"
+ " fail if the script is not currently loaded\n"
+ " - $REG -- where 'REG' is one of 'PC', 'ACC',\n"
+ " 'PREV' or 'OBJ': References the address\n"
+ " indicated by the register of this name.\n"
+ " - $REG+n (or -n) -- Like $REG, but modifies\n"
+ " the offset part by a specific amount (which\n"
+ " is specified in hexadecimal).\n"
+ " - ?obj -- Looks up an object with the specified\n"
+ " name, uses its address. This will abort if\n"
+ " the object name is ambiguous; in that case,\n"
+ " a list of addresses and indices is provided.\n"
+ " ?obj.idx may be used to disambiguate 'obj'\n"
+ " by the index 'idx'.\n");
con_init_dmalloc();
- con_hook_int (&con_passthrough, "con_passthrough",
- "scicon->stdout passthrough");
+ con_hook_int(&con_passthrough, "con_passthrough",
+ "scicon->stdout passthrough");
}
}
static inline int
-clone_is_used(clone_table_t *t, int idx)
-{
+clone_is_used(clone_table_t *t, int idx) {
return ENTRY_IS_VALID(t, idx);
}
int
-parse_reg_t(state_t *s, const char *str, reg_t *dest)
-{ /* Returns 0 on success */
+parse_reg_t(state_t *s, const char *str, reg_t *dest) { /* Returns 0 on success */
int rel_offsetting = 0;
const char *offsetting = NULL;
/* Non-NULL: Parse end of string for relative offsets */
@@ -365,25 +347,25 @@ parse_reg_t(state_t *s, const char *str, reg_t *dest)
if (*str == '$') { /* Register */
rel_offsetting = 1;
- if (!strncasecmp(str+1, "PC", 2)) {
+ if (!strncasecmp(str + 1, "PC", 2)) {
*dest = s->execution_stack[s->execution_stack_pos].addr.pc;
offsetting = str + 3;
- } else if (!strncasecmp(str+1, "P", 1)) {
+ } else if (!strncasecmp(str + 1, "P", 1)) {
*dest = s->execution_stack[s->execution_stack_pos].addr.pc;
offsetting = str + 2;
- } else if (!strncasecmp(str+1, "PREV", 4)) {
+ } else if (!strncasecmp(str + 1, "PREV", 4)) {
*dest = s->r_prev;
offsetting = str + 5;
- } else if (!strncasecmp(str+1, "ACC", 3)) {
+ } else if (!strncasecmp(str + 1, "ACC", 3)) {
*dest = s->r_acc;
offsetting = str + 4;
- } else if (!strncasecmp(str+1, "A", 1)) {
+ } else if (!strncasecmp(str + 1, "A", 1)) {
*dest = s->r_acc;
offsetting = str + 2;
- } else if (!strncasecmp(str+1, "OBJ", 3)) {
+ } else if (!strncasecmp(str + 1, "OBJ", 3)) {
*dest = s->execution_stack[s->execution_stack_pos].objp;
offsetting = str + 4;
- } else if (!strncasecmp(str+1, "O", 1)) {
+ } else if (!strncasecmp(str + 1, "O", 1)) {
*dest = s->execution_stack[s->execution_stack_pos].objp;
offsetting = str + 2;
} else return 1; /* No matching register */
@@ -400,9 +382,9 @@ parse_reg_t(state_t *s, const char *str, reg_t *dest)
if (!colon)
return 1;
*colon = 0;
- offsetting = colon+1;
+ offsetting = colon + 1;
- script_nr = strtol(str+1, &endptr, 10);
+ script_nr = strtol(str + 1, &endptr, 10);
if (*endptr)
return 1;
@@ -435,7 +417,7 @@ parse_reg_t(state_t *s, const char *str, reg_t *dest)
if (tmp) {
*tmp = 0;
- index = strtol(tmp+1, &endptr, 16);
+ index = strtol(tmp + 1, &endptr, 16);
if (*endptr)
return -1;
}
@@ -473,11 +455,11 @@ parse_reg_t(state_t *s, const char *str, reg_t *dest)
if (valid) {
char *objname = (char *) obj->base
- + obj->variables[SCRIPT_NAME_SELECTOR].offset;
+ + obj->variables[SCRIPT_NAME_SELECTOR].offset;
if (!strcmp(objname, str_objname)) {
/* Found a match! */
if (index < 0 ||
- times_found == index)
+ times_found == index)
*dest = objpos;
else if (times_found < 0 && index) {
@@ -502,7 +484,7 @@ parse_reg_t(state_t *s, const char *str, reg_t *dest)
return 1;
if (times_found > 1
- && index < 0) {
+ && index < 0) {
sciprintf("Ambiguous: Aborting.\n");
return 1; /* Ambiguous */
}
@@ -522,7 +504,7 @@ parse_reg_t(state_t *s, const char *str, reg_t *dest)
dest->segment = 0;
} else {
*colon = 0;
- offsetting = colon+1;
+ offsetting = colon + 1;
dest->segment = strtol(str, &endptr, 16);
if (*endptr)
@@ -545,14 +527,13 @@ parse_reg_t(state_t *s, const char *str, reg_t *dest)
}
void
-con_parse (state_t *s, const char *command)
-{
+con_parse(state_t *s, const char *command) {
int quote = 0; /* quoting? */
int done = 0; /* are we done yet? */
int cdone = 0; /* Done with the current command? */
const char *paramt; /* parameter types */
- char *cmd = (command && command[0]) ? (char *) sci_strdup (command) :
- (char *) sci_strdup(" ");
+ char *cmd = (command && command[0]) ? (char *) sci_strdup(command) :
+ (char *) sci_strdup(" ");
char *_cmd = cmd;
int pos = 0;
@@ -585,11 +566,11 @@ con_parse (state_t *s, const char *command)
cmd[pos] = onvar = 0;
break;
case '\\': /* don't check next char for special meaning */
- memmove (cmd + pos, cmd + pos + 1, strlen (cmd + pos) - 1);
+ memmove(cmd + pos, cmd + pos + 1, strlen(cmd + pos) - 1);
break;
case '"':
quote ^= 1;
- memmove (cmd + pos, cmd + pos + 1, strlen (cmd + pos));
+ memmove(cmd + pos, cmd + pos + 1, strlen(cmd + pos));
pos--;
break;
default:
@@ -597,9 +578,9 @@ con_parse (state_t *s, const char *command)
onvar = 1;
if (cmd_paramlength == parammem)
cmd_params = (cmd_param_t*)sci_realloc(cmd_params,
- sizeof (cmd_param_t)
- * (parammem += 8));
-
+ sizeof(cmd_param_t)
+ * (parammem += 8));
+
cmd_params[cmd_paramlength].str = cmd + pos;
cmd_paramlength++;
@@ -610,13 +591,13 @@ con_parse (state_t *s, const char *command)
}
if (quote)
- sciprintf ("unbalanced quotes\n");
- else if (strcmp (cmd, "") != 0) {
+ sciprintf("unbalanced quotes\n");
+ else if (strcmp(cmd, "") != 0) {
command_todo = (cmd_command_t *) cmd_mm_find(cmd, CMD_MM_CMD);
if (!command_todo)
- sciprintf ("%s: not found\n", cmd);
+ sciprintf("%s: not found\n", cmd);
else {
unsigned int minparams;
int need_state = 0;
@@ -627,19 +608,19 @@ con_parse (state_t *s, const char *command)
paramt++;
}
- minparams = strlen (paramt);
+ minparams = strlen(paramt);
- if ((paramt[0] != 0) && (paramt[strlen (paramt) - 1] == '*'))
+ if ((paramt[0] != 0) && (paramt[strlen(paramt) - 1] == '*'))
minparams -= 2;
if (cmd_paramlength < minparams)
- sciprintf ("%s: needs more than %d parameters\n",
- cmd, cmd_paramlength);
+ sciprintf("%s: needs more than %d parameters\n",
+ cmd, cmd_paramlength);
- else if ((cmd_paramlength > strlen (paramt))
- && ((strlen (paramt) == 0)
- || paramt[strlen (paramt) - 1] != '*'))
- sciprintf ("%s: too many parameters", cmd);
+ else if ((cmd_paramlength > strlen(paramt))
+ && ((strlen(paramt) == 0)
+ || paramt[strlen(paramt) - 1] != '*'))
+ sciprintf("%s: too many parameters", cmd);
else {
int do_execute = !need_state || s; /* /me wants an
** implication arrow */
@@ -651,7 +632,7 @@ con_parse (state_t *s, const char *command)
paramtype = paramt[paramtypepos];
if ((paramt[paramtypepos + 1])
- && (paramt[paramtypepos + 1] != '*'))
+ && (paramt[paramtypepos + 1] != '*'))
paramtypepos++;
/* seek next param type unless end of string or '* ' */
@@ -663,7 +644,7 @@ con_parse (state_t *s, const char *command)
case 'a': {
char *oldname = cmd_params[i].str;
if (parse_reg_t(s, oldname,
- &(cmd_params[i].reg))) {
+ &(cmd_params[i].reg))) {
sciprintf("%s: '%s' is not an address or object\n", cmd, oldname);
do_execute = 0;
}
@@ -673,34 +654,34 @@ con_parse (state_t *s, const char *command)
case 'i': {
char *orgstr = cmd_params[i].str;
- cmd_params[i].val = strtol (orgstr, &endptr, 0);
+ cmd_params[i].val = strtol(orgstr, &endptr, 0);
if (*endptr != '\0') {
do_execute = 0;
- sciprintf ("%s: '%s' is not an int\n", cmd, orgstr);
+ sciprintf("%s: '%s' is not an int\n", cmd, orgstr);
}
}
- break;
+ break;
case 'h': {
char *orgstr = cmd_params[i].str;
- cmd_params[i].val = strtol (orgstr, &endptr, 16);
+ cmd_params[i].val = strtol(orgstr, &endptr, 16);
if (*endptr != '\0') {
do_execute = 0;
- sciprintf ("%s: '%s' is not a hex number\n", cmd, orgstr);
+ sciprintf("%s: '%s' is not a hex number\n", cmd, orgstr);
}
cmd_params[i].val &= 0xff; /* Clip hex numbers to 0x00 ... 0xff */
}
- break;
+ break;
case 's':
break;
default:
fprintf(stderr, "Internal error: Heap corruption or prior assertion failed:\n"
- "Unknown parameter type '%c' for funtion\n", paramtype);
+ "Unknown parameter type '%c' for funtion\n", paramtype);
}
}
@@ -714,9 +695,9 @@ con_parse (state_t *s, const char *command)
cmd += pos;
}
- free (_cmd);
+ free(_cmd);
if (cmd_params)
- free (cmd_params);
+ free(cmd_params);
cmd_params = NULL;
}
@@ -740,8 +721,7 @@ con_iterate_entry(int ID, int *counter)
*/
static cmd_mm_entry_t *
-con_alloc_page_entry(int ID)
-{
+con_alloc_page_entry(int ID) {
int entry;
con_init();
@@ -753,20 +733,19 @@ con_alloc_page_entry(int ID)
nextsize <<= 1;
cmd_mm[ID].data = sci_realloc(cmd_mm[ID].data,
- nextsize * cmd_mm[ID].size_per_entry);
+ nextsize * cmd_mm[ID].size_per_entry);
cmd_mm[ID].allocated = nextsize;
}
_lists_need_sorting |= (1 << ID);
entry = cmd_mm[ID].entries++;
- return (cmd_mm_entry_t *) (((byte *)cmd_mm[ID].data)
- + entry * cmd_mm[ID].size_per_entry);
+ return (cmd_mm_entry_t *)(((byte *)cmd_mm[ID].data)
+ + entry * cmd_mm[ID].size_per_entry);
}
int
-con_hook_page(const char *name, const char *body)
-{
+con_hook_page(const char *name, const char *body) {
cmd_page_t *page = (cmd_page_t *) con_alloc_page_entry(CMD_MM_DOC);
page->name = name;
@@ -776,9 +755,8 @@ con_hook_page(const char *name, const char *body)
}
int
-con_hook_command (int command (state_t *), const char *name, const char *param,
- const char *description)
-{
+con_hook_command(int command(state_t *), const char *name, const char *param,
+ const char *description) {
cmd_command_t *cmd = NULL;
unsigned int i;
@@ -829,8 +807,7 @@ con_hook_command (int command (state_t *), const char *name, const char *param,
int
-con_hook_int (int *pointer, const char *name, const char *description)
-{
+con_hook_int(int *pointer, const char *name, const char *description) {
cmd_var_t *var;
if (pointer == NULL)
@@ -855,38 +832,36 @@ con_hook_int (int *pointer, const char *name, const char *description)
static int
-get_resource_number (char *resid)
+get_resource_number(char *resid)
/* Gets the resource number of a resource string, or returns -1 */
{
- int i, res = -1;
+ int i, res = -1;
- for (i = 0; i < sci_invalid_resource; i++)
- if (strcmp (sci_resource_types[i], resid) == 0)
- res = i;
- return res;
+ for (i = 0; i < sci_invalid_resource; i++)
+ if (strcmp(sci_resource_types[i], resid) == 0)
+ res = i;
+ return res;
}
static int
-c_version (state_t * s)
-{
+c_version(state_t * s) {
if (NULL == s) {
sciprintf("console.c: c_version: NULL passed for parameter s\n");
return -1;
}
- sciprintf ("FreeSCI, version " VERSION "\n");
- sciprintf ("Resource file version: %s\n", sci_version_types[s->resmgr->sci_version]);
- sciprintf ("Emulated interpreter version: %d.%03d.%03d\n",
- SCI_VERSION_MAJOR(s->version),
- SCI_VERSION_MINOR(s->version),
- SCI_VERSION_PATCHLEVEL(s->version));
-
+ sciprintf("FreeSCI, version " VERSION "\n");
+ sciprintf("Resource file version: %s\n", sci_version_types[s->resmgr->sci_version]);
+ sciprintf("Emulated interpreter version: %d.%03d.%03d\n",
+ SCI_VERSION_MAJOR(s->version),
+ SCI_VERSION_MINOR(s->version),
+ SCI_VERSION_PATCHLEVEL(s->version));
+
return 0;
}
static int
-c_list_words(state_t *s)
-{
+c_list_words(state_t *s) {
word_t **words;
int words_nr;
int i;
@@ -900,18 +875,17 @@ c_list_words(state_t *s)
for (i = 0; i < words_nr; i++)
sciprintf("%4d: %03x [%03x] %s\n",
- i,
- words[i]->w_class,
- words[i]->group,
- words[i]->word);
+ i,
+ words[i]->w_class,
+ words[i]->group,
+ words[i]->word);
vocab_free_words(words, words_nr);
return 0;
}
int
-c_list_suffices(state_t *s)
-{
+c_list_suffices(state_t *s) {
suffix_t **suffices;
int suffices_nr;
int i;
@@ -928,15 +902,15 @@ c_list_suffices(state_t *s)
suffix_t *suf = suffices[i];
strncpy(word_buf, suf->word_suffix,
- suf->word_suffix_length);
+ suf->word_suffix_length);
word_buf[suf->word_suffix_length] = 0;
strncpy(alt_buf, suf->alt_suffix,
- suf->alt_suffix_length);
+ suf->alt_suffix_length);
alt_buf[suf->alt_suffix_length] = 0;
sciprintf("%4d: (%03x) -%12s => -%12s (%03x)\n",
- i, suf->class_mask, word_buf,
- alt_buf, suf->result_class);
+ i, suf->class_mask, word_buf,
+ alt_buf, suf->result_class);
}
vocab_free_suffices(s->resmgr, suffices, suffices_nr);
@@ -944,86 +918,81 @@ c_list_suffices(state_t *s)
}
static void
-_cmd_print_command(cmd_mm_entry_t *data, int full)
-{
+_cmd_print_command(cmd_mm_entry_t *data, int full) {
const char *paramseeker = ((cmd_command_t *) data)->param;
if (full) {
- sciprintf ("SYNOPSIS\n\n %s ", data->name, paramseeker);
+ sciprintf("SYNOPSIS\n\n %s ", data->name, paramseeker);
while (*paramseeker) {
switch (*paramseeker) {
- case '!': break;
+ case '!':
+ break;
case 'i':
- sciprintf (" (int)");
+ sciprintf(" (int)");
break;
case 'a':
- sciprintf (" (addr)");
+ sciprintf(" (addr)");
break;
case 's':
- sciprintf (" (string)");
+ sciprintf(" (string)");
break;
case 'h':
- sciprintf (" (hexbyte)");
+ sciprintf(" (hexbyte)");
break;
case '*':
- sciprintf ("*");
+ sciprintf("*");
break;
default:
- sciprintf (" (Unknown(%c))", *paramseeker);
+ sciprintf(" (Unknown(%c))", *paramseeker);
}
paramseeker++;
}
sciprintf("\n\nDESCRIPTION\n\n %s",
- data->description);
+ data->description);
} else
sciprintf(" %s", data->name);
}
static void
-_cmd_print_var(cmd_mm_entry_t *data, int full)
-{
+_cmd_print_var(cmd_mm_entry_t *data, int full) {
cmd_var_t *var = (cmd_var_t *) data;
if (full)
- sciprintf ("VALUE\n\n");
+ sciprintf("VALUE\n\n");
sciprintf(" %s = %d\n", var->name, *(var->var.intp));
if (full)
sciprintf("\n\nDESCRIPTION\n\n %s",
- data->description);
+ data->description);
}
static void
-_cmd_print_page(cmd_mm_entry_t *data, int full)
-{
+_cmd_print_page(cmd_mm_entry_t *data, int full) {
if (full)
sciprintf("\n\nDESCRIPTION\n\n %s\n",
- data->description);
+ data->description);
else sciprintf("%s\n", data->name);
}
static int
-c_list (state_t * s)
-{
+c_list(state_t * s) {
if (_lists_need_sorting)
con_sort_all();
- if (cmd_paramlength == 0)
- {
- sciprintf ("usage: list [type]\nwhere type is one of the following:\n"
- "cmds - lists all commands\n"
- "vars - lists all variables\n"
- "docs - lists all misc. documentation\n"
- "\n"
- "restypes - lists all resource types\n"
- "selectors - lists all selectors\n"
- "syscalls - lists all kernel functions\n"
- "words - lists all kernel words\n"
- "suffixes - lists all suffix replacements\n"
- "[resource] - lists all [resource]s");
- }
- else if (cmd_paramlength == 1) {
+ if (cmd_paramlength == 0) {
+ sciprintf("usage: list [type]\nwhere type is one of the following:\n"
+ "cmds - lists all commands\n"
+ "vars - lists all variables\n"
+ "docs - lists all misc. documentation\n"
+ "\n"
+ "restypes - lists all resource types\n"
+ "selectors - lists all selectors\n"
+ "syscalls - lists all kernel functions\n"
+ "words - lists all kernel words\n"
+ "suffixes - lists all suffix replacements\n"
+ "[resource] - lists all [resource]s");
+ } else if (cmd_paramlength == 1) {
const char *mm_subsects[3] = {"cmds", "vars", "docs"};
int mm_found = -1;
int i;
@@ -1035,50 +1004,47 @@ c_list (state_t * s)
if (mm_found >= 0)
for (i = 0; i < cmd_mm[mm_found].entries; i++)
cmd_mm[mm_found].print((cmd_mm_entry_t *)
- (((byte *)cmd_mm[mm_found].data)
- + i * cmd_mm[mm_found].size_per_entry), 0);
+ (((byte *)cmd_mm[mm_found].data)
+ + i * cmd_mm[mm_found].size_per_entry), 0);
else {
if (!s) {
sciprintf("You need a state to do that!\n");
return 1;
}
-
+
if (!strcmp("selectors", cmd_params[0].str))
return c_selectornames(s);
else if (!strcmp("syscalls", cmd_params[0].str))
return c_kernelnames(s);
else if (!strcmp("suffixes", cmd_params[0].str)
- || !strcmp("suffices", cmd_params[0].str)
- || !strcmp("sufficos", cmd_params[0].str))
+ || !strcmp("suffices", cmd_params[0].str)
+ || !strcmp("sufficos", cmd_params[0].str))
/* sufficos: Accusative Plural of 'suffix' */
return c_list_suffices(s);
else if (!strcmp("words", cmd_params[0].str))
return c_list_words(s);
- else if (strcmp ("restypes", cmd_params[0].str) == 0) {
+ else if (strcmp("restypes", cmd_params[0].str) == 0) {
for (i = 0; i < sci_invalid_resource; i++)
- sciprintf ("%s\n", sci_resource_types[i]);
- }
- else {
- int res = get_resource_number (cmd_params[0].str);
+ sciprintf("%s\n", sci_resource_types[i]);
+ } else {
+ int res = get_resource_number(cmd_params[0].str);
if (res == -1)
- sciprintf ("Unknown resource type: '%s'\n", cmd_params[0].str);
+ sciprintf("Unknown resource type: '%s'\n", cmd_params[0].str);
else {
for (i = 0; i < sci_max_resource_nr[s->resmgr->sci_version]; i++)
- if (scir_test_resource (s->resmgr, res, i))
- sciprintf ("%s.%03d\n", sci_resource_types[res], i);
+ if (scir_test_resource(s->resmgr, res, i))
+ sciprintf("%s.%03d\n", sci_resource_types[res], i);
}
}
}
- }
- else
- sciprintf ("list can only be used with one argument");
+ } else
+ sciprintf("list can only be used with one argument");
return 0;
}
static int
-c_man (state_t * s)
-{
+c_man(state_t * s) {
int section = 0;
unsigned int i;
char *name = cmd_params[0].str;
@@ -1092,7 +1058,7 @@ c_man (state_t * s)
if (section < 0 || section >= CMD_MM_ENTRIES) {
sciprintf("Invalid section %d\n",
- section);
+ section);
return 1;
}
@@ -1102,7 +1068,7 @@ c_man (state_t * s)
else
for (i = 0; i < CMD_MM_ENTRIES && !section; i++) {
if ((entry = cmd_mm_find(name, i)))
- section = i+1;
+ section = i + 1;
}
if (!entry) {
@@ -1110,15 +1076,14 @@ c_man (state_t * s)
return 1;
}
- sciprintf ("-- %s: %s.%d\n", cmd_mm[section - 1].name, name, section);
+ sciprintf("-- %s: %s.%d\n", cmd_mm[section - 1].name, name, section);
cmd_mm[section - 1].print(entry, 1);
return 0;
}
static int
-c_set (state_t * s)
-{
+c_set(state_t * s) {
cmd_var_t *var = (cmd_var_t *) cmd_mm_find(cmd_params[0].str, CMD_MM_VAR);
if (var)
@@ -1128,214 +1093,186 @@ c_set (state_t * s)
}
static int
-c_print (state_t * s)
-{
+c_print(state_t * s) {
cmd_var_t *var = (cmd_var_t *) cmd_mm_find(cmd_params[0].str, CMD_MM_VAR);
if (var)
- sciprintf ("%d", *(var->var.intp));
+ sciprintf("%d", *(var->var.intp));
else
- sciprintf ("Not defined.");
+ sciprintf("Not defined.");
return 0;
}
static int
-c_size (state_t * s)
-{
- int res = get_resource_number (cmd_params[0].str);
- if (res == -1)
- sciprintf ("Resource type '%s' is not valid\n", cmd_params[0].str);
- else
- {
- resource_t *resource = scir_find_resource(s->resmgr, res, cmd_params[1].val, 0);
- if (resource)
- {
- sciprintf ("Size: %d\n", resource->size);
- }
- else
- sciprintf ("Resource %s.%03d not found\n", cmd_params[0].str,
- cmd_params[1].val);
- }
- return 0;
+c_size(state_t * s) {
+ int res = get_resource_number(cmd_params[0].str);
+ if (res == -1)
+ sciprintf("Resource type '%s' is not valid\n", cmd_params[0].str);
+ else {
+ resource_t *resource = scir_find_resource(s->resmgr, res, cmd_params[1].val, 0);
+ if (resource) {
+ sciprintf("Size: %d\n", resource->size);
+ } else
+ sciprintf("Resource %s.%03d not found\n", cmd_params[0].str,
+ cmd_params[1].val);
+ }
+ return 0;
}
static int
-c_dump (state_t * s)
-{
- int res = get_resource_number (cmd_params[0].str);
-
- if (res == -1)
- sciprintf ("Resource type '%s' is not valid\n", cmd_params[0].str);
- else
- {
- resource_t *resource = scir_find_resource(s->resmgr, res, cmd_params[1].val, 0);
- if (resource)
- sci_hexdump (resource->data, resource->size, 0);
- else
- sciprintf ("Resource %s.%03d not found\n", cmd_params[0].str,
- cmd_params[1].val);
- }
- return 0;
+c_dump(state_t * s) {
+ int res = get_resource_number(cmd_params[0].str);
+
+ if (res == -1)
+ sciprintf("Resource type '%s' is not valid\n", cmd_params[0].str);
+ else {
+ resource_t *resource = scir_find_resource(s->resmgr, res, cmd_params[1].val, 0);
+ if (resource)
+ sci_hexdump(resource->data, resource->size, 0);
+ else
+ sciprintf("Resource %s.%03d not found\n", cmd_params[0].str,
+ cmd_params[1].val);
+ }
+ return 0;
}
static int
-c_hexgrep (state_t * s)
-{
- int i, seeklen, resnr, restype, resmax;
- unsigned char *seekstr = NULL;
- resource_t *script = NULL;
- char *dot = strchr (cmd_params[0].str, '.');
-
- if (NULL == s)
- {
- fprintf(stderr, "console.c: c_hexgrep(): NULL passed for s\r\n");
- return(-1);
- }
-
- seekstr = (unsigned char*)sci_malloc (seeklen = (cmd_paramlength - 1));
-
- if (NULL == seekstr)
- {
- fprintf(stderr, "console.c: c_hexgrep(): malloc failed for seekstr\r\n");
- return(-1);
- }
-
- for (i = 0; i < seeklen; i++)
- seekstr[i] = (byte)cmd_params[i + 1].val;
-
- if (dot)
- {
- *dot = 0;
- resmax = resnr = atoi (dot + 1);
- }
- else
- {
- resnr = 0;
- resmax = 999;
- }
-
- if ((restype = get_resource_number (cmd_params[0].str)) == -1)
- {
- sciprintf ("Unknown resource type \"%s\"\n", cmd_params[0].str);
- free(seekstr);
- return 1;
- }
-
- for (; resnr <= resmax; resnr++)
- if ((script = scir_find_resource(s->resmgr, restype, resnr, 0)))
- {
- unsigned int seeker = 0, seekerold = 0;
- int comppos = 0;
- int output_script_name = 0;
-
- while (seeker < script->size)
- {
-
- if (script->data[seeker] == seekstr[comppos])
- {
- if (comppos == 0)
- seekerold = seeker;
-
- comppos++;
-
- if (comppos == seeklen)
- {
- comppos = 0;
- seeker = seekerold + 1;
-
- if (!output_script_name)
- {
- sciprintf ("\nIn %s.%03d:\n", sci_resource_types[restype], resnr);
- output_script_name = 1;
- }
- sciprintf (" 0x%04x\n", seekerold);
- }
+c_hexgrep(state_t * s) {
+ int i, seeklen, resnr, restype, resmax;
+ unsigned char *seekstr = NULL;
+ resource_t *script = NULL;
+ char *dot = strchr(cmd_params[0].str, '.');
+
+ if (NULL == s) {
+ fprintf(stderr, "console.c: c_hexgrep(): NULL passed for s\r\n");
+ return(-1);
+ }
+
+ seekstr = (unsigned char*)sci_malloc(seeklen = (cmd_paramlength - 1));
+
+ if (NULL == seekstr) {
+ fprintf(stderr, "console.c: c_hexgrep(): malloc failed for seekstr\r\n");
+ return(-1);
+ }
+
+ for (i = 0; i < seeklen; i++)
+ seekstr[i] = (byte)cmd_params[i + 1].val;
+
+ if (dot) {
+ *dot = 0;
+ resmax = resnr = atoi(dot + 1);
+ } else {
+ resnr = 0;
+ resmax = 999;
+ }
+
+ if ((restype = get_resource_number(cmd_params[0].str)) == -1) {
+ sciprintf("Unknown resource type \"%s\"\n", cmd_params[0].str);
+ free(seekstr);
+ return 1;
}
- else
- comppos = 0;
- seeker++;
- }
- }
+ for (; resnr <= resmax; resnr++)
+ if ((script = scir_find_resource(s->resmgr, restype, resnr, 0))) {
+ unsigned int seeker = 0, seekerold = 0;
+ int comppos = 0;
+ int output_script_name = 0;
- free (seekstr);
+ while (seeker < script->size) {
- return 0;
+ if (script->data[seeker] == seekstr[comppos]) {
+ if (comppos == 0)
+ seekerold = seeker;
+
+ comppos++;
+
+ if (comppos == seeklen) {
+ comppos = 0;
+ seeker = seekerold + 1;
+
+ if (!output_script_name) {
+ sciprintf("\nIn %s.%03d:\n", sci_resource_types[restype], resnr);
+ output_script_name = 1;
+ }
+ sciprintf(" 0x%04x\n", seekerold);
+ }
+ } else
+ comppos = 0;
+
+ seeker++;
+ }
+ }
+
+ free(seekstr);
+
+ return 0;
}
static int
-c_selectornames (state_t * s)
-{
- int namectr;
- char **snames = NULL;
- int seeker = 0;
-
- if (NULL == s)
- {
- sciprintf("console.c: c_selectornames(): NULL passed for parameter s\n");
- return -1;
- }
-
- snames = vocabulary_get_snames (s->resmgr, &namectr, s ? s->version : 0);
-
- if (!snames)
- {
- sciprintf ("No selector name table found!\n");
- return 1;
- }
-
- sciprintf ("Selector names in numeric order:\n");
- while (snames[seeker])
- {
- sciprintf ("%03x: %s\n", seeker, snames[seeker]);
- seeker++;
- }
- vocabulary_free_snames (snames);
- return 0;
+c_selectornames(state_t * s) {
+ int namectr;
+ char **snames = NULL;
+ int seeker = 0;
+
+ if (NULL == s) {
+ sciprintf("console.c: c_selectornames(): NULL passed for parameter s\n");
+ return -1;
+ }
+
+ snames = vocabulary_get_snames(s->resmgr, &namectr, s ? s->version : 0);
+
+ if (!snames) {
+ sciprintf("No selector name table found!\n");
+ return 1;
+ }
+
+ sciprintf("Selector names in numeric order:\n");
+ while (snames[seeker]) {
+ sciprintf("%03x: %s\n", seeker, snames[seeker]);
+ seeker++;
+ }
+ vocabulary_free_snames(snames);
+ return 0;
}
static int
-c_kernelnames (state_t * s)
-{
- int knamectr;
- char **knames = vocabulary_get_knames (s->resmgr, &knamectr);
- int seeker = 0;
-
- if (NULL == s) {
- sciprintf("console.c: c_kernelnames NULL passed for parameter s\n");
- return -1;
- }
-
- if (!knames)
- {
- sciprintf ("No kernel name table found!\n");
- return 1;
- }
-
- sciprintf ("Syscalls in numeric order:\n");
- for (seeker = 0; seeker < knamectr; seeker++)
- sciprintf ("%03x: %s\n", seeker, knames[seeker]);
-
- vocabulary_free_knames (knames);
- return 0;
+c_kernelnames(state_t * s) {
+ int knamectr;
+ char **knames = vocabulary_get_knames(s->resmgr, &knamectr);
+ int seeker = 0;
+
+ if (NULL == s) {
+ sciprintf("console.c: c_kernelnames NULL passed for parameter s\n");
+ return -1;
+ }
+
+ if (!knames) {
+ sciprintf("No kernel name table found!\n");
+ return 1;
+ }
+
+ sciprintf("Syscalls in numeric order:\n");
+ for (seeker = 0; seeker < knamectr; seeker++)
+ sciprintf("%03x: %s\n", seeker, knames[seeker]);
+
+ vocabulary_free_knames(knames);
+ return 0;
}
static int
-c_dissectscript (state_t * s)
-{
- if (NULL == s)
- {
- sciprintf("console.c: c_dissectscript(): NULL passed for parameter s\n");
- return -1;
- }
-
- script_dissect (s->resmgr, cmd_params[0].val, s->selector_names, s->selector_names_nr);
- return 0;
+c_dissectscript(state_t * s) {
+ if (NULL == s) {
+ sciprintf("console.c: c_dissectscript(): NULL passed for parameter s\n");
+ return -1;
+ }
+
+ script_dissect(s->resmgr, cmd_params[0].val, s->selector_names, s->selector_names_nr);
+ return 0;
}
#endif /* SCI_CONSOLE */
diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp
index d5e8c9778f..40095c61f3 100644
--- a/engines/sci/engine/scriptdebug.cpp
+++ b/engines/sci/engine/scriptdebug.cpp
@@ -92,7 +92,8 @@ static reg_t **p_var_base;
static int *p_var_max; /* May be NULL even in valid state! */
static const int MIDI_cmdlen[16] = {0, 0, 0, 0, 0, 0, 0, 0,
- 2, 2, 2, 2, 1, 1, 2, 0};
+ 2, 2, 2, 2, 1, 1, 2, 0
+ };
int _kdebug_cheap_event_hack = 0;
int _kdebug_cheap_soundcue_hack = -1;
@@ -104,33 +105,31 @@ char inputbuf[256] = "";
+ s->classtable[species].class_offset)
const char *
-_debug_get_input_default(void)
-{
- char newinpbuf[256];
+_debug_get_input_default(void) {
+ char newinpbuf[256];
- printf("> ");
- fgets(newinpbuf, 254, stdin);
+ printf("> ");
+ fgets(newinpbuf, 254, stdin);
- if (strlen(newinpbuf) != 0)
- memcpy(inputbuf, newinpbuf, 256);
+ if (strlen(newinpbuf) != 0)
+ memcpy(inputbuf, newinpbuf, 256);
- return inputbuf;
+ return inputbuf;
}
static inline int
-_parse_ticks(byte *data, int *offset_p, int size)
-{
+_parse_ticks(byte *data, int *offset_p, int size) {
int ticks = 0;
int tempticks;
int offset = 0;
do {
tempticks = data[offset++];
- ticks += (tempticks == SCI_MIDI_TIME_EXPANSION_PREFIX)?
- SCI_MIDI_TIME_EXPANSION_LENGTH : tempticks;
+ ticks += (tempticks == SCI_MIDI_TIME_EXPANSION_PREFIX) ?
+ SCI_MIDI_TIME_EXPANSION_LENGTH : tempticks;
} while (tempticks == SCI_MIDI_TIME_EXPANSION_PREFIX
- && offset < size);
+ && offset < size);
if (offset_p)
*offset_p = offset;
@@ -140,8 +139,7 @@ _parse_ticks(byte *data, int *offset_p, int size)
static void
-midi_hexdump(byte *data, int size, int notational_offset)
-{ /* Specialised for SCI01 tracks (this affects the way cumulative cues are treated ) */
+midi_hexdump(byte *data, int size, int notational_offset) { /* Specialised for SCI01 tracks (this affects the way cumulative cues are treated ) */
int offset = 0;
int prev = 0;
@@ -152,7 +150,7 @@ midi_hexdump(byte *data, int size, int notational_offset)
int old_offset = offset;
int offset_mod;
int time = _parse_ticks(data + offset, &offset_mod,
- size);
+ size);
int cmd;
int pleft;
int firstarg = 0;
@@ -161,15 +159,15 @@ midi_hexdump(byte *data, int size, int notational_offset)
offset += offset_mod;
fprintf(stderr, " [%04x] %d\t",
- old_offset + notational_offset, time);
+ old_offset + notational_offset, time);
cmd = data[offset];
if (!(cmd & 0x80)) {
cmd = prev;
if (prev < 0x80) {
fprintf(stderr, "Track broken at %x after"
- " offset mod of %d\n",
- offset + notational_offset, offset_mod);
+ " offset mod of %d\n",
+ offset + notational_offset, offset_mod);
sci_hexdump(data, size, notational_offset);
return;
}
@@ -184,7 +182,7 @@ midi_hexdump(byte *data, int size, int notational_offset)
pleft = MIDI_cmdlen[cmd >> 4];
if (SCI_MIDI_CONTROLLER(cmd) && data[offset]
- == SCI_MIDI_CUMULATIVE_CUE)
+ == SCI_MIDI_CUMULATIVE_CUE)
--pleft; /* This is SCI(0)1 specific */
for (i = 0; i < pleft; i++) {
@@ -221,7 +219,7 @@ midi_hexdump(byte *data, int size, int notational_offset)
if (old_offset >= offset) {
fprintf(stderr, "-- Not moving forward anymore,"
- " aborting (%x/%x)\n", offset, old_offset);
+ " aborting (%x/%x)\n", offset, old_offset);
return;
}
}
@@ -230,12 +228,11 @@ midi_hexdump(byte *data, int size, int notational_offset)
#define SONGDATA(x) data[offset + (x)]
#define CHECK_FOR_END_ABSOLUTE(off) if ((off) >= size) return;
static void
-sci01_song_header_dump(byte *data, int size)
-{
+sci01_song_header_dump(byte *data, int size) {
int offset = 0;
int smallest_start = 10000;
- sciprintf ("SCI01 song track mappings:\n");
+ sciprintf("SCI01 song track mappings:\n");
if (*data == 0xf0) /* SCI1 priority spec */
offset = 8;
@@ -264,17 +261,17 @@ sci01_song_header_dump(byte *data, int size)
smallest_start = track_offset;
end = getUInt16(data + offset + 2);
sciprintf(" - %04x -- %04x",
- track_offset, track_offset + end);
+ track_offset, track_offset + end);
if (track_offset == 0xfe)
sciprintf(" (PCM data)\n");
else
sciprintf(" (channel %d, special %d,"
- " %d playing notes, %d foo)\n",
- header1 & 0xf,
- header1 >> 4,
- header2 & 0xf,
- header2 >> 4);
+ " %d playing notes, %d foo)\n",
+ header1 & 0xf,
+ header1 >> 4,
+ header2 & 0xf,
+ header2 >> 4);
offset += 4;
}
@@ -286,12 +283,11 @@ sci01_song_header_dump(byte *data, int size)
-int c_sfx_01_header(state_t *s)
-{
+int c_sfx_01_header(state_t *s) {
resource_t *song = scir_find_resource(s->resmgr,
- sci_sound,
- cmd_params[0].val,
- 0);
+ sci_sound,
+ cmd_params[0].val,
+ 0);
if (!song) {
sciprintf("Doesn't exist\n");
@@ -302,12 +298,11 @@ int c_sfx_01_header(state_t *s)
return 0;
}
-int c_sfx_01_track(state_t *s)
-{
+int c_sfx_01_track(state_t *s) {
resource_t *song = scir_find_resource(s->resmgr,
- sci_sound,
- cmd_params[0].val,
- 0);
+ sci_sound,
+ cmd_params[0].val,
+ 0);
int offset = cmd_params[1].val;
@@ -325,8 +320,7 @@ int c_sfx_01_track(state_t *s)
const char *(*_debug_get_input)(void) = _debug_get_input_default;
int
-c_segtable(state_t *s)
-{
+c_segtable(state_t *s) {
int i;
sciprintf(" ---- segment table ----\n");
@@ -339,23 +333,23 @@ c_segtable(state_t *s)
case MEM_OBJ_SCRIPT:
sciprintf("S script.%03d l:%d ",
- mobj->data.script.nr,
- mobj->data.script.lockers);
+ mobj->data.script.nr,
+ mobj->data.script.lockers);
break;
case MEM_OBJ_CLONES:
sciprintf("C clones (%d allocd)",
- mobj->data.clones.entries_used);
+ mobj->data.clones.entries_used);
break;
case MEM_OBJ_LOCALS:
sciprintf("V locals %03d",
- mobj->data.locals.script_id);
+ mobj->data.locals.script_id);
break;
case MEM_OBJ_STACK:
sciprintf("D data stack (%d)",
- mobj->data.stack.nr);
+ mobj->data.stack.nr);
break;
case MEM_OBJ_SYS_STRINGS:
@@ -392,18 +386,16 @@ c_segtable(state_t *s)
static void
-print_obj_head(state_t *s, object_t *obj)
-{
+print_obj_head(state_t *s, object_t *obj) {
sciprintf(PREG" %s : %3d vars, %3d methods\n",
- PRINT_REG(obj->pos),
- obj_get_name(s, obj->pos),
- obj->variables_nr,
- obj->methods_nr);
+ PRINT_REG(obj->pos),
+ obj_get_name(s, obj->pos),
+ obj->variables_nr,
+ obj->methods_nr);
}
static void
-print_list(state_t *s, list_t *l)
-{
+print_list(state_t *s, list_t *l) {
reg_t pos = l->first;
reg_t my_prev = NULL_REG_INITIALIZER;
@@ -415,18 +407,18 @@ print_list(state_t *s, list_t *l)
if (!mobj || !ENTRY_IS_VALID(&(mobj->data.nodes), pos.offset)) {
sciprintf(" WARNING: "PREG": Doesn't contain list node!\n",
- PRINT_REG(pos));
+ PRINT_REG(pos));
return;
}
node = &(mobj->data.nodes.table[pos.offset].entry);
sciprintf("\t"PREG" : "PREG" -> "PREG"\n",
- PRINT_REG(pos), PRINT_REG(node->key), PRINT_REG(node->value));
+ PRINT_REG(pos), PRINT_REG(node->key), PRINT_REG(node->value));
if (!REG_EQ(my_prev, node->pred))
sciprintf(" WARNING: current node gives "PREG" as predecessor!\n",
- PRINT_REG(node->pred));
+ PRINT_REG(node->pred));
my_prev = pos;
pos = node->succ;
@@ -434,25 +426,24 @@ print_list(state_t *s, list_t *l)
if (!REG_EQ(my_prev, l->last))
sciprintf(" WARNING: Last node was expected to be "PREG", was "PREG"!\n",
- PRINT_REG(l->last), PRINT_REG(my_prev));
+ PRINT_REG(l->last), PRINT_REG(my_prev));
sciprintf("\t>\n");
}
static void
-_c_single_seg_info(state_t *s, mem_obj_t *mobj)
-{
+_c_single_seg_info(state_t *s, mem_obj_t *mobj) {
switch (mobj->type) {
case MEM_OBJ_SCRIPT: {
int i;
script_t *scr = &(mobj->data.script);
sciprintf("script.%03d locked by %d, bufsize=%d (%x)\n",
- scr->nr, scr->lockers, scr->buf_size, scr->buf_size);
+ scr->nr, scr->lockers, scr->buf_size, scr->buf_size);
if (scr->export_table)
sciprintf(" Exports: %4d at %d\n",
- scr->exports_nr,
- ((byte *) scr->export_table) - ((byte *)scr->buf));
+ scr->exports_nr,
+ ((byte *) scr->export_table) - ((byte *)scr->buf));
else
sciprintf(" Exports: none\n");
@@ -460,33 +451,33 @@ _c_single_seg_info(state_t *s, mem_obj_t *mobj)
if (scr->locals_block)
sciprintf(" Locals : %4d in segment 0x%x\n",
- scr->locals_block->nr,
- scr->locals_segment);
+ scr->locals_block->nr,
+ scr->locals_segment);
else
sciprintf(" Locals : none\n");
sciprintf(" Objects: %4d\n",
- scr->objects_nr);
+ scr->objects_nr);
for (i = 0; i < scr->objects_nr; i++) {
sciprintf(" ");
print_obj_head(s, scr->objects + i);
}
}
- break;
+ break;
case MEM_OBJ_LOCALS: {
local_variables_t *locals = &(mobj->data.locals);
sciprintf("locals for script.%03d\n", locals->script_id);
sciprintf(" %d (0x%x) locals\n", locals->nr, locals->nr);
}
- break;
+ break;
case MEM_OBJ_STACK: {
dstack_t *stack = &(mobj->data.stack);
sciprintf("stack\n");
sciprintf(" %d (0x%x) entries\n", stack->nr, stack->nr);
}
- break;
+ break;
case MEM_OBJ_SYS_STRINGS: {
sys_strings_t *strings = &(mobj->data.sys_strings);
@@ -496,16 +487,16 @@ _c_single_seg_info(state_t *s, mem_obj_t *mobj)
for (i = 0; i < SYS_STRINGS_MAX; i++)
if (strings->strings[i].name)
sciprintf(" %s[%d]=\"%s\"\n",
- strings->strings[i].name,
- strings->strings[i].max_size,
- strings->strings[i].value);
+ strings->strings[i].name,
+ strings->strings[i].max_size,
+ strings->strings[i].value);
}
- break;
+ break;
case MEM_OBJ_CLONES: {
int i = 0;
clone_table_t *ct =
- &(mobj->data.clones);
+ &(mobj->data.clones);
sciprintf("clones\n");
@@ -514,13 +505,13 @@ _c_single_seg_info(state_t *s, mem_obj_t *mobj)
sciprintf(" [%04x] ", i);
print_obj_head(s, &(ct->table[i].entry));
}
- }
- break;
+ }
+ break;
case MEM_OBJ_LISTS: {
int i = 0;
list_table_t *lt =
- &(mobj->data.lists);
+ &(mobj->data.lists);
sciprintf("lists\n");
for (i = 0; i < lt->max_entry; i++)
@@ -529,7 +520,7 @@ _c_single_seg_info(state_t *s, mem_obj_t *mobj)
print_list(s, &(lt->table[i].entry));
}
}
- break;
+ break;
case MEM_OBJ_NODES: {
sciprintf("nodes (total %d)\n", mobj->data.nodes.entries_used);
@@ -539,35 +530,35 @@ _c_single_seg_info(state_t *s, mem_obj_t *mobj)
case MEM_OBJ_HUNK: {
int i;
hunk_table_t *ht =
- &(mobj->data.hunks);
+ &(mobj->data.hunks);
sciprintf("hunk (total %d)\n", mobj->data.hunks.entries_used);
for (i = 0; i < ht->max_entry; i++)
if (ENTRY_IS_VALID(ht, i)) {
sciprintf(" [%04x] %d bytes at %p, type=%s\n",
- i, ht->table[i].entry.size, ht->table[i].entry.mem,
- ht->table[i].entry.type);
- }
+ i, ht->table[i].entry.size, ht->table[i].entry.mem,
+ ht->table[i].entry.type);
+ }
}
case MEM_OBJ_DYNMEM: {
sciprintf("dynmem (%s): %d bytes\n",
- mobj->data.dynmem.description?
- mobj->data.dynmem.description:"no description",
- mobj->data.dynmem.size);
+ mobj->data.dynmem.description ?
+ mobj->data.dynmem.description : "no description",
+ mobj->data.dynmem.size);
sci_hexdump(mobj->data.dynmem.buf, mobj->data.dynmem.size, 0);
}
- break;
+ break;
- default : sciprintf("Invalid type %d\n", mobj->type);
+ default :
+ sciprintf("Invalid type %d\n", mobj->type);
break;
}
}
static int
-show_node(state_t *s, reg_t addr)
-{
+show_node(state_t *s, reg_t addr) {
mem_obj_t *mobj = GET_SEGMENT(s->seg_manager, addr.segment, MEM_OBJ_LISTS);
@@ -583,8 +574,8 @@ show_node(state_t *s, reg_t addr)
list = &(lt->table[addr.offset].entry);
sciprintf(PREG" : first x last = ("PREG", "PREG")\n",
- PRINT_REG(addr), PRINT_REG(list->first),
- PRINT_REG(list->last));
+ PRINT_REG(addr), PRINT_REG(list->first),
+ PRINT_REG(list->last));
} else {
node_table_t *nt;
node_t *node;
@@ -604,11 +595,11 @@ show_node(state_t *s, reg_t addr)
node = &(nt->table[addr.offset].entry);
sciprintf(PREG" : prev x next = ("PREG", "PREG"); maps "PREG" -> "PREG"\n",
- PRINT_REG(addr),
- PRINT_REG(node->pred),
- PRINT_REG(node->succ),
- PRINT_REG(node->key),
- PRINT_REG(node->value));
+ PRINT_REG(addr),
+ PRINT_REG(node->pred),
+ PRINT_REG(node->succ),
+ PRINT_REG(node->key),
+ PRINT_REG(node->value));
}
return 0;
}
@@ -619,15 +610,13 @@ void
song_lib_dump(songlib_t songlib, int line);
static int
-c_songlib_print(state_t *s)
-{
+c_songlib_print(state_t *s) {
song_lib_dump(s->sound.songlib, __LINE__);
return 0;
}
static int
-c_vr(state_t *s)
-{
+c_vr(state_t *s) {
reg_t reg = cmd_params[0].reg;
reg_t reg_end = cmd_paramlength > 1 ? cmd_params[1].reg : NULL_REG;
int type_mask = determine_reg_type(s, reg, 1);
@@ -635,18 +624,17 @@ c_vr(state_t *s)
int found = 0;
sciprintf(PREG" is of type 0x%x%s: ", PRINT_REG(reg), type_mask & ~KSIG_INVALID,
- type_mask & KSIG_INVALID ? " (invalid)" : "");
+ type_mask & KSIG_INVALID ? " (invalid)" : "");
type_mask &= ~KSIG_INVALID;
if (reg.segment == 0
- && reg.offset == 0) {
+ && reg.offset == 0) {
sciprintf("Null.\n");
return 0;
}
- if (reg_end.segment != reg.segment)
- {
+ if (reg_end.segment != reg.segment) {
sciprintf("Ending segment different from starting segment. Assuming no bound on dump.\n");
reg_end = NULL_REG;
}
@@ -660,7 +648,8 @@ c_vr(state_t *s)
switch (type) {
- case 0: break;
+ case 0:
+ break;
case KSIG_LIST: {
list_t *l = LOOKUP_LIST(reg);
@@ -672,7 +661,7 @@ c_vr(state_t *s)
else
sciprintf("Invalid list.\n");
}
- break;
+ break;
case KSIG_NODE:
sciprintf("list node\n");
@@ -687,12 +676,11 @@ c_vr(state_t *s)
case KSIG_REF: {
int size;
unsigned char *block = sm_dereference(&s->seg_manager,
- reg, &size);
+ reg, &size);
sciprintf("raw data\n");
- if (reg_end.segment != 0 && size < reg_end.offset - reg.offset)
- {
+ if (reg_end.segment != 0 && size < reg_end.offset - reg.offset) {
sciprintf("Block end out of bounds (size %d). Resetting.\n", size);
reg_end = NULL_REG;
}
@@ -705,14 +693,15 @@ c_vr(state_t *s)
sci_hexdump(block, size, 0);
}
- break;
+ break;
case KSIG_ARITHMETIC:
sciprintf("arithmetic value\n %d (%04x)\n", (gint16) reg.offset, reg.offset);
break;
- default: sciprintf("unknown.\n", type);
+ default:
+ sciprintf("unknown.\n", type);
}
@@ -727,8 +716,7 @@ c_vr(state_t *s)
int
-c_segkill(state_t *s)
-{
+c_segkill(state_t *s) {
unsigned int i = 0;
while (i < cmd_paramlength) {
int nr = cmd_params[i++].val;
@@ -739,34 +727,31 @@ c_segkill(state_t *s)
}
static int
-c_mousepos(state_t *s)
-{
+c_mousepos(state_t *s) {
sci_event_t event;
sciprintf("Click somewhere in the game window...\n");
while (event = gfxop_get_event(s->gfx_state, SCI_EVT_MOUSE_RELEASE),
- event.type != SCI_EVT_MOUSE_RELEASE)
- {
+ event.type != SCI_EVT_MOUSE_RELEASE) {
};
- sciprintf("Mouse pointer at (%d, %d)\n",
- s->gfx_state->pointer_pos.x,
- s->gfx_state->pointer_pos.y);
+ sciprintf("Mouse pointer at (%d, %d)\n",
+ s->gfx_state->pointer_pos.x,
+ s->gfx_state->pointer_pos.y);
return 0;
}
int
-c_seginfo(state_t *s)
-{
+c_seginfo(state_t *s) {
unsigned int i = 0;
if (cmd_paramlength) {
while (i < cmd_paramlength) {
int nr = cmd_params[i++].val;
if (nr < 0
- || nr >= s->seg_manager.heap_size
- || !s->seg_manager.heap[nr]) {
+ || nr >= s->seg_manager.heap_size
+ || !s->seg_manager.heap[nr]) {
sciprintf("Segment %04x does not exist\n", nr);
return 1;
}
@@ -783,8 +768,7 @@ c_seginfo(state_t *s)
}
int
-c_debuginfo(state_t *s)
-{
+c_debuginfo(state_t *s) {
exec_stack_t *eframe = NULL;
if (!_debugstate_valid) {
@@ -796,14 +780,14 @@ c_debuginfo(state_t *s)
eframe = s->execution_stack + s->execution_stack_pos;
sciprintf("acc="PREG" prev="PREG" &rest=%x\n",
- PRINT_REG(s->r_acc),
- PRINT_REG(s->r_prev), *p_restadjust);
+ PRINT_REG(s->r_acc),
+ PRINT_REG(s->r_prev), *p_restadjust);
if (eframe)
sciprintf("pc="PREG" obj="PREG" fp="PSTK" sp="PSTK"\n",
- PRINT_REG(*p_pc),
- PRINT_REG(*p_objp),
- PRINT_STK(*p_pp),
- PRINT_STK(*p_sp));
+ PRINT_REG(*p_pc),
+ PRINT_REG(*p_objp),
+ PRINT_STK(*p_pp),
+ PRINT_STK(*p_sp));
else
sciprintf("<no execution stack: pc,obj,fp omitted>\n");
return 0;
@@ -811,8 +795,7 @@ c_debuginfo(state_t *s)
int
-c_step(state_t *s)
-{
+c_step(state_t *s) {
_debugstate_valid = 0;
if (cmd_paramlength && (cmd_params[0].val > 0))
_debug_step_running = cmd_params[0].val - 1;
@@ -822,121 +805,119 @@ c_step(state_t *s)
#if 0
// TODO Re-implement con:so
int
-c_stepover(state_t *s)
-{
- int opcode, opnumber;
-
- if (!_debugstate_valid) {
- sciprintf("Not in debug state\n");
- return 1;
- }
-
- _debugstate_valid = 0;
- opcode = s->heap [*p_pc];
- opnumber = opcode >> 1;
- if (opnumber == 0x22 /* callb */ || opnumber == 0x23 /* calle */ ||
- opnumber == 0x25 /* send */ || opnumber == 0x2a /* self */ ||
- opnumber == 0x2b /* super */)
- {
- _debug_seeking = _DEBUG_SEEK_SO;
- _debug_seek_level = s->execution_stack_pos;
- /* Store in _debug_seek_special the offset of the next command after send */
- switch (opcode)
- {
- case 0x46: /* calle W */
- _debug_seek_special = *p_pc + 5; break;
-
- case 0x44: /* callb W */
- case 0x47: /* calle B */
- case 0x56: /* super W */
- _debug_seek_special = *p_pc + 4; break;
-
- case 0x45: /* callb B */
- case 0x57: /* super B */
- case 0x4A: /* send W */
- case 0x54: /* self W */
- _debug_seek_special = *p_pc + 3; break;
-
- default:
- _debug_seek_special = *p_pc + 2;
- }
- }
-
- return 0;
+c_stepover(state_t *s) {
+ int opcode, opnumber;
+
+ if (!_debugstate_valid) {
+ sciprintf("Not in debug state\n");
+ return 1;
+ }
+
+ _debugstate_valid = 0;
+ opcode = s->heap [*p_pc];
+ opnumber = opcode >> 1;
+ if (opnumber == 0x22 /* callb */ || opnumber == 0x23 /* calle */ ||
+ opnumber == 0x25 /* send */ || opnumber == 0x2a /* self */ ||
+ opnumber == 0x2b /* super */) {
+ _debug_seeking = _DEBUG_SEEK_SO;
+ _debug_seek_level = s->execution_stack_pos;
+ /* Store in _debug_seek_special the offset of the next command after send */
+ switch (opcode) {
+ case 0x46: /* calle W */
+ _debug_seek_special = *p_pc + 5;
+ break;
+
+ case 0x44: /* callb W */
+ case 0x47: /* calle B */
+ case 0x56: /* super W */
+ _debug_seek_special = *p_pc + 4;
+ break;
+
+ case 0x45: /* callb B */
+ case 0x57: /* super B */
+ case 0x4A: /* send W */
+ case 0x54: /* self W */
+ _debug_seek_special = *p_pc + 3;
+ break;
+
+ default:
+ _debug_seek_special = *p_pc + 2;
+ }
+ }
+
+ return 0;
}
#endif
int
-c_sim_parse(state_t *s)
-{
- unsigned int i;
- const char *operators = ",&/()[]#<>";
-
- if (!_debugstate_valid) {
- sciprintf("Not in debug state\n");
- return 1;
- }
-
- if (cmd_paramlength == 0) {
- s->parser_valid = 0;
- return 0;
- }
-
- for (i = 0; i < cmd_paramlength; i++) {
- int flag = 0;
- char *token = cmd_params[i].str;
-
- if (strlen(token) == 1) {/* could be an operator */
- int j = 0;
- while (operators[j] && (operators[j] != token[0]))
- j++;
- if (operators[j]) {
- s->parser_nodes[i].type = 1;
- s->parser_nodes[i].content.value = j + 0xf0;
- flag = 1; /* found an operator */
- }
- }
-
- if (!flag) {
- char *openb = strchr(token, '['); /* look for opening braces */
- result_word_t *result;
-
- if (openb)
- *openb = 0; /* remove them and the rest */
-
- result = vocab_lookup_word(token, strlen(token),
- s->parser_words, s->parser_words_nr,
- s->parser_suffices, s->parser_suffices_nr);
-
- if (result) {
- s->parser_nodes[i].type = 0;
- s->parser_nodes[i].content.value = result->group;
- free(result);
- } else { /* group name was specified directly? */
- int val = strtol(token, NULL, 0);
- if (val) {
- s->parser_nodes[i].type = 0;
- s->parser_nodes[i].content.value = val;
- } else { /* invalid and not matched */
- sciprintf("Couldn't interpret '%s'\n", token);
- s->parser_valid = 0;
- return 1;
- }
- }
- }
-
- }
-
- s->parser_nodes[cmd_paramlength].type = -1; /* terminate */
-
- s->parser_valid = 2;
- return 0;
+c_sim_parse(state_t *s) {
+ unsigned int i;
+ const char *operators = ",&/()[]#<>";
+
+ if (!_debugstate_valid) {
+ sciprintf("Not in debug state\n");
+ return 1;
+ }
+
+ if (cmd_paramlength == 0) {
+ s->parser_valid = 0;
+ return 0;
+ }
+
+ for (i = 0; i < cmd_paramlength; i++) {
+ int flag = 0;
+ char *token = cmd_params[i].str;
+
+ if (strlen(token) == 1) {/* could be an operator */
+ int j = 0;
+ while (operators[j] && (operators[j] != token[0]))
+ j++;
+ if (operators[j]) {
+ s->parser_nodes[i].type = 1;
+ s->parser_nodes[i].content.value = j + 0xf0;
+ flag = 1; /* found an operator */
+ }
+ }
+
+ if (!flag) {
+ char *openb = strchr(token, '['); /* look for opening braces */
+ result_word_t *result;
+
+ if (openb)
+ *openb = 0; /* remove them and the rest */
+
+ result = vocab_lookup_word(token, strlen(token),
+ s->parser_words, s->parser_words_nr,
+ s->parser_suffices, s->parser_suffices_nr);
+
+ if (result) {
+ s->parser_nodes[i].type = 0;
+ s->parser_nodes[i].content.value = result->group;
+ free(result);
+ } else { /* group name was specified directly? */
+ int val = strtol(token, NULL, 0);
+ if (val) {
+ s->parser_nodes[i].type = 0;
+ s->parser_nodes[i].content.value = val;
+ } else { /* invalid and not matched */
+ sciprintf("Couldn't interpret '%s'\n", token);
+ s->parser_valid = 0;
+ return 1;
+ }
+ }
+ }
+
+ }
+
+ s->parser_nodes[cmd_paramlength].type = -1; /* terminate */
+
+ s->parser_valid = 2;
+ return 0;
}
int
-c_classtable(state_t *s)
-{
+c_classtable(state_t *s) {
int i;
if (!_debugstate_valid) {
@@ -948,16 +929,15 @@ c_classtable(state_t *s)
for (i = 0; i < s->classtable_size; i++)
if (s->classtable[i].reg.segment)
sciprintf(" Class 0x%x at "PREG" (script 0x%x)\n",
- i,
- PRINT_REG(s->classtable[i].reg),
- s->classtable[i].script);
+ i,
+ PRINT_REG(s->classtable[i].reg),
+ s->classtable[i].script);
- return 0;
+ return 0;
}
int
-c_viewinfo(state_t *s)
-{
+c_viewinfo(state_t *s) {
int view = cmd_params[0].val;
int palette = cmd_params[1].val;
int loops, i;
@@ -987,14 +967,14 @@ c_viewinfo(state_t *s)
if (con_can_handle_pixmaps()) {
view_pixmaps = gfxr_get_view(s->gfx_state->resstate,
- view, &i, &j, palette);
+ view, &i, &j, palette);
con_insert_pixmap(gfx_clone_pixmap(view_pixmaps->loops[i].cels[j],
- s->gfx_state->driver->mode));
+ s->gfx_state->driver->mode));
}
gfxop_get_cel_parameters(s->gfx_state, view, i, j, &width, &height, &mod);
- sciprintf(" cel %d: size %dx%d, adj+(%d,%d)\n",j, width, height, mod.x, mod.y);
+ sciprintf(" cel %d: size %dx%d, adj+(%d,%d)\n", j, width, height, mod.x, mod.y);
}
}
}
@@ -1002,198 +982,192 @@ c_viewinfo(state_t *s)
}
int
-c_list_sentence_fragments(state_t *s)
-{
- int i;
+c_list_sentence_fragments(state_t *s) {
+ int i;
- if (!s) {
- sciprintf("Not in debug state\n");
- return 1;
- }
+ if (!s) {
+ sciprintf("Not in debug state\n");
+ return 1;
+ }
- for (i = 0; i < s->parser_branches_nr; i++) {
- int j = 0;
+ for (i = 0; i < s->parser_branches_nr; i++) {
+ int j = 0;
- sciprintf("R%02d: [%x] ->", i, s->parser_branches[i].id);
- while ((j < 10) && s->parser_branches[i].data[j]) {
- int dat = s->parser_branches[i].data[j++];
+ sciprintf("R%02d: [%x] ->", i, s->parser_branches[i].id);
+ while ((j < 10) && s->parser_branches[i].data[j]) {
+ int dat = s->parser_branches[i].data[j++];
- switch (dat) {
- case VOCAB_TREE_NODE_COMPARE_TYPE:
- dat = s->parser_branches[i].data[j++];
- sciprintf(" C(%x)", dat);
- break;
+ switch (dat) {
+ case VOCAB_TREE_NODE_COMPARE_TYPE:
+ dat = s->parser_branches[i].data[j++];
+ sciprintf(" C(%x)", dat);
+ break;
- case VOCAB_TREE_NODE_COMPARE_GROUP:
- dat = s->parser_branches[i].data[j++];
- sciprintf(" WG(%x)", dat);
- break;
+ case VOCAB_TREE_NODE_COMPARE_GROUP:
+ dat = s->parser_branches[i].data[j++];
+ sciprintf(" WG(%x)", dat);
+ break;
- case VOCAB_TREE_NODE_FORCE_STORAGE:
- dat = s->parser_branches[i].data[j++];
- sciprintf(" FORCE(%x)", dat);
- break;
+ case VOCAB_TREE_NODE_FORCE_STORAGE:
+ dat = s->parser_branches[i].data[j++];
+ sciprintf(" FORCE(%x)", dat);
+ break;
- default:
- if (dat > VOCAB_TREE_NODE_LAST_WORD_STORAGE) {
- int dat2 = s->parser_branches[i].data[j++];
- sciprintf(" %x[%x]", dat, dat2);
- } else
- sciprintf(" ?%x?", dat);
- }
- }
- sciprintf("\n");
- }
+ default:
+ if (dat > VOCAB_TREE_NODE_LAST_WORD_STORAGE) {
+ int dat2 = s->parser_branches[i].data[j++];
+ sciprintf(" %x[%x]", dat, dat2);
+ } else
+ sciprintf(" ?%x?", dat);
+ }
+ }
+ sciprintf("\n");
+ }
- sciprintf("%d rules.\n", s->parser_branches_nr);
- return 0;
+ sciprintf("%d rules.\n", s->parser_branches_nr);
+ return 0;
}
enum {
- _parse_eoi,
- _parse_token_pareno,
- _parse_token_parenc,
- _parse_token_nil,
- _parse_token_number
+ _parse_eoi,
+ _parse_token_pareno,
+ _parse_token_parenc,
+ _parse_token_nil,
+ _parse_token_number
};
int
-_parse_getinp(int *i, int *nr)
-{
- char *token;
+_parse_getinp(int *i, int *nr) {
+ char *token;
- if ((unsigned)*i == cmd_paramlength)
- return _parse_eoi;
+ if ((unsigned)*i == cmd_paramlength)
+ return _parse_eoi;
- token = cmd_params[(*i)++].str;
+ token = cmd_params[(*i)++].str;
- if (!strcmp(token,"("))
- return _parse_token_pareno;
+ if (!strcmp(token, "("))
+ return _parse_token_pareno;
- if (!strcmp(token,")"))
- return _parse_token_parenc;
+ if (!strcmp(token, ")"))
+ return _parse_token_parenc;
- if (!strcmp(token,"nil"))
- return _parse_token_nil;
+ if (!strcmp(token, "nil"))
+ return _parse_token_nil;
- *nr = strtol(token, NULL, 0);
- return _parse_token_number;
+ *nr = strtol(token, NULL, 0);
+ return _parse_token_number;
}
int
-_parse_nodes(state_t *s, int *i, int *pos, int type, int nr)
-{
- int nexttk, nextval, newpos, oldpos;
-
- if (type == _parse_token_nil)
- return 0;
-
- if (type == _parse_token_number) {
- s->parser_nodes[*pos += 1].type = PARSE_TREE_NODE_LEAF;
- s->parser_nodes[*pos].content.value = nr;
- return *pos;
- }
- if (type == _parse_eoi) {
- sciprintf("Unbalanced parentheses\n");
- return -1;
- }
- if (type == _parse_token_parenc) {
- sciprintf("Syntax error at token %d\n", *i);
- return -1;
- }
- s->parser_nodes[oldpos = ++(*pos)].type = PARSE_TREE_NODE_BRANCH;
-
- nexttk = _parse_getinp(i, &nextval);
- if ((newpos = s->parser_nodes[oldpos].content.branches[0] = _parse_nodes(s, i, pos, nexttk, nextval)) == -1)
- return -1;
-
- nexttk = _parse_getinp(i, &nextval);
- if ((newpos = s->parser_nodes[oldpos].content.branches[1] = _parse_nodes(s, i, pos, nexttk, nextval)) == -1)
- return -1;
-
- if (_parse_getinp(i, &nextval) != _parse_token_parenc)
- sciprintf("Expected ')' at token %d\n", *i);
- return oldpos;
+_parse_nodes(state_t *s, int *i, int *pos, int type, int nr) {
+ int nexttk, nextval, newpos, oldpos;
+
+ if (type == _parse_token_nil)
+ return 0;
+
+ if (type == _parse_token_number) {
+ s->parser_nodes[*pos += 1].type = PARSE_TREE_NODE_LEAF;
+ s->parser_nodes[*pos].content.value = nr;
+ return *pos;
+ }
+ if (type == _parse_eoi) {
+ sciprintf("Unbalanced parentheses\n");
+ return -1;
+ }
+ if (type == _parse_token_parenc) {
+ sciprintf("Syntax error at token %d\n", *i);
+ return -1;
+ }
+ s->parser_nodes[oldpos = ++(*pos)].type = PARSE_TREE_NODE_BRANCH;
+
+ nexttk = _parse_getinp(i, &nextval);
+ if ((newpos = s->parser_nodes[oldpos].content.branches[0] = _parse_nodes(s, i, pos, nexttk, nextval)) == -1)
+ return -1;
+
+ nexttk = _parse_getinp(i, &nextval);
+ if ((newpos = s->parser_nodes[oldpos].content.branches[1] = _parse_nodes(s, i, pos, nexttk, nextval)) == -1)
+ return -1;
+
+ if (_parse_getinp(i, &nextval) != _parse_token_parenc)
+ sciprintf("Expected ')' at token %d\n", *i);
+ return oldpos;
}
int
-c_set_parse_nodes(state_t *s)
-{
- int i = 0;
- int foo, bar;
- int pos = -1;
+c_set_parse_nodes(state_t *s) {
+ int i = 0;
+ int foo, bar;
+ int pos = -1;
- if (!s) {
- sciprintf("Not in debug state\n");
- return 1;
- }
+ if (!s) {
+ sciprintf("Not in debug state\n");
+ return 1;
+ }
- bar = _parse_getinp(&i, &foo);
- if (_parse_nodes(s, &i, &pos, bar, foo) == -1)
- return 1;
+ bar = _parse_getinp(&i, &foo);
+ if (_parse_nodes(s, &i, &pos, bar, foo) == -1)
+ return 1;
- vocab_dump_parse_tree("debug-parse-tree", s->parser_nodes);
- return 0;
+ vocab_dump_parse_tree("debug-parse-tree", s->parser_nodes);
+ return 0;
}
/* from grammar.c: */
int
vocab_gnf_parse(parse_tree_node_t *nodes, result_word_t *words, int words_nr,
- parse_tree_branch_t *branch0, parse_rule_list_t *tlist, int verbose);
+ parse_tree_branch_t *branch0, parse_rule_list_t *tlist, int verbose);
/* parses with a GNF rule set */
int
-c_parse(state_t *s)
-{
- result_word_t *words;
- int words_nr;
- char *error;
- char *string;
+c_parse(state_t *s) {
+ result_word_t *words;
+ int words_nr;
+ char *error;
+ char *string;
- if (!s) {
- sciprintf("Not in debug state\n");
- return 1;
- }
+ if (!s) {
+ sciprintf("Not in debug state\n");
+ return 1;
+ }
- string = cmd_params[0].str;
- sciprintf("Parsing '%s'\n", string);
- words = vocab_tokenize_string(string, &words_nr,
- s->parser_words, s->parser_words_nr,
- s->parser_suffices, s->parser_suffices_nr,
- &error);
- if (words) {
+ string = cmd_params[0].str;
+ sciprintf("Parsing '%s'\n", string);
+ words = vocab_tokenize_string(string, &words_nr,
+ s->parser_words, s->parser_words_nr,
+ s->parser_suffices, s->parser_suffices_nr,
+ &error);
+ if (words) {
- int i, syntax_fail = 0;
+ int i, syntax_fail = 0;
- vocab_synonymize_tokens(words, words_nr, s->synonyms, s->synonyms_nr);
+ vocab_synonymize_tokens(words, words_nr, s->synonyms, s->synonyms_nr);
- sciprintf("Parsed to the following blocks:\n");
+ sciprintf("Parsed to the following blocks:\n");
- for (i = 0; i < words_nr; i++)
- sciprintf(" Type[%04x] Group[%04x]\n", words[i].w_class, words[i].group);
+ for (i = 0; i < words_nr; i++)
+ sciprintf(" Type[%04x] Group[%04x]\n", words[i].w_class, words[i].group);
- if (vocab_gnf_parse(&(s->parser_nodes[0]), words, words_nr, s->parser_branches,
- s->parser_rules, 1))
- syntax_fail = 1; /* Building a tree failed */
+ if (vocab_gnf_parse(&(s->parser_nodes[0]), words, words_nr, s->parser_branches,
+ s->parser_rules, 1))
+ syntax_fail = 1; /* Building a tree failed */
- free(words);
+ free(words);
- if (syntax_fail)
- sciprintf("Building a tree failed.\n");
- else
- vocab_dump_parse_tree("debug-parse-tree", s->parser_nodes);
+ if (syntax_fail)
+ sciprintf("Building a tree failed.\n");
+ else
+ vocab_dump_parse_tree("debug-parse-tree", s->parser_nodes);
- } else {
+ } else {
- sciprintf("Unknown word: '%s'\n", error);
- free(error);
- }
- return 0;
+ sciprintf("Unknown word: '%s'\n", error);
+ free(error);
+ }
+ return 0;
}
int
-c_save_game(state_t *s)
-{
+c_save_game(state_t *s) {
int omit_check = cmd_params[0].str[0] == '_';
int i;
@@ -1215,16 +1189,15 @@ c_save_game(state_t *s)
}
}
- if (gamestate_save(s, cmd_params[0].str)) {
- sciprintf("Saving the game state to '%s' failed\n", cmd_params[0].str);
- }
+ if (gamestate_save(s, cmd_params[0].str)) {
+ sciprintf("Saving the game state to '%s' failed\n", cmd_params[0].str);
+ }
return 0;
}
int
-c_restore_game(state_t *s)
-{
+c_restore_game(state_t *s) {
state_t *newstate;
if (!s) {
@@ -1232,7 +1205,7 @@ c_restore_game(state_t *s)
return 1;
}
- newstate = gamestate_restore(s, cmd_params[0].str);
+ newstate = gamestate_restore(s, cmd_params[0].str);
if (newstate) {
@@ -1252,44 +1225,42 @@ c_restore_game(state_t *s)
extern char *old_save_dir; /* Ouch */
int
-c_restart_game(state_t *s)
-{
- unsigned int i;
- char *deref_save_dir = (char*)kernel_dereference_bulk_pointer(s, s->save_dir_copy, 1);
+c_restart_game(state_t *s) {
+ unsigned int i;
+ char *deref_save_dir = (char*)kernel_dereference_bulk_pointer(s, s->save_dir_copy, 1);
- if (!s) {
- sciprintf("Not in debug state\n");
- return 1;
- }
+ if (!s) {
+ sciprintf("Not in debug state\n");
+ return 1;
+ }
- old_save_dir = strdup(deref_save_dir);
- for (i = 0; i < cmd_paramlength; i++) {
- if ((strcmp(cmd_params[0].str, "-r") == 0)
- || (strcmp(cmd_params[0].str, "--replay") == 0))
- s->restarting_flags |= SCI_GAME_WAS_RESTARTED_AT_LEAST_ONCE;
- else
- if ((strcmp(cmd_params[0].str, "-p") == 0)
- || (strcmp(cmd_params[0].str, "--play") == 0))
- s->restarting_flags &= ~SCI_GAME_WAS_RESTARTED_AT_LEAST_ONCE;
- else {
- sciprintf("Invalid parameter '%s'\n", cmd_params[0].str);
- return 1;
- }
- }
+ old_save_dir = strdup(deref_save_dir);
+ for (i = 0; i < cmd_paramlength; i++) {
+ if ((strcmp(cmd_params[0].str, "-r") == 0)
+ || (strcmp(cmd_params[0].str, "--replay") == 0))
+ s->restarting_flags |= SCI_GAME_WAS_RESTARTED_AT_LEAST_ONCE;
+ else
+ if ((strcmp(cmd_params[0].str, "-p") == 0)
+ || (strcmp(cmd_params[0].str, "--play") == 0))
+ s->restarting_flags &= ~SCI_GAME_WAS_RESTARTED_AT_LEAST_ONCE;
+ else {
+ sciprintf("Invalid parameter '%s'\n", cmd_params[0].str);
+ return 1;
+ }
+ }
- sciprintf("Restarting\n");
+ sciprintf("Restarting\n");
- s->restarting_flags |= SCI_GAME_IS_RESTARTING_NOW;
+ s->restarting_flags |= SCI_GAME_IS_RESTARTING_NOW;
- script_abort_flag = 1;
- _debugstate_valid = 0;
- return 0;
+ script_abort_flag = 1;
+ _debugstate_valid = 0;
+ return 0;
}
int
-c_stack(state_t *s)
-{
+c_stack(state_t *s) {
int i;
exec_stack_t *xs;
@@ -1310,40 +1281,36 @@ c_stack(state_t *s)
sciprintf("-- temp variables --\n");
if (xs->sp - i >= s->stack_base)
sciprintf(PSTK" = "PREG"\n",
- PRINT_STK(xs->sp - i), PRINT_REG(xs->sp[-i]));
+ PRINT_STK(xs->sp - i), PRINT_REG(xs->sp[-i]));
}
return 0;
}
-const char *selector_name(state_t *s, int selector)
-{
+const char *selector_name(state_t *s, int selector) {
if (selector >= 0 && selector < s->selector_names_nr)
return s->selector_names[selector];
else
return "--INVALID--";
}
-int prop_ofs_to_id(state_t *s, int prop_ofs, reg_t objp)
-{
+int prop_ofs_to_id(state_t *s, int prop_ofs, reg_t objp) {
object_t *obj = obj_get(s, objp);
byte *selectoroffset;
int selectors;
if (!obj) {
sciprintf("Applied prop_ofs_to_id on non-object at "PREG"\n",
- PRINT_REG(objp));
+ PRINT_REG(objp));
return -1;
}
selectors = obj->variables_nr;
- if (s->version < SCI_VERSION(1,001,000))
- selectoroffset = ((byte *) (obj->base_obj)) + SCRIPT_SELECTOR_OFFSET + selectors * 2;
- else
- {
- if (!(obj->variables[SCRIPT_INFO_SELECTOR].offset & SCRIPT_INFO_CLASS))
- {
+ if (s->version < SCI_VERSION(1, 001, 000))
+ selectoroffset = ((byte *)(obj->base_obj)) + SCRIPT_SELECTOR_OFFSET + selectors * 2;
+ else {
+ if (!(obj->variables[SCRIPT_INFO_SELECTOR].offset & SCRIPT_INFO_CLASS)) {
obj = obj_get(s, obj->variables[SCRIPT_SUPERCLASS_SELECTOR]);
selectoroffset = (byte *) obj->base_vars;
} else selectoroffset = (byte *) obj->base_vars;
@@ -1351,9 +1318,9 @@ int prop_ofs_to_id(state_t *s, int prop_ofs, reg_t objp)
if (prop_ofs < 0 || (prop_ofs >> 1) >= selectors) {
sciprintf("Applied prop_ofs_to_id to invalid property offset %x (property #%d not"
- " in [0..%d]) on object at "PREG"\n",
- prop_ofs, prop_ofs >> 1, selectors - 1,
- PRINT_REG(objp));
+ " in [0..%d]) on object at "PREG"\n",
+ prop_ofs, prop_ofs >> 1, selectors - 1,
+ PRINT_REG(objp));
return -1;
}
@@ -1380,7 +1347,7 @@ disassemble(state_t *s, reg_t pos, int print_bw_tag, int print_bytecode)
if (!memobj) {
sciprintf("Disassembly failed: Segment %04x non-existant or not a script\n",
- pos.segment);
+ pos.segment);
return retval;
} else script_entity = &(memobj->data.script);
@@ -1402,7 +1369,7 @@ disassemble(state_t *s, reg_t pos, int print_bw_tag, int print_bytecode)
opsize &= 1; /* byte if true, word if false */
-
+
sciprintf(PREG": ", PRINT_REG(pos));
if (print_bytecode) {
@@ -1410,11 +1377,13 @@ disassemble(state_t *s, reg_t pos, int print_bw_tag, int print_bytecode)
switch (formats[opcode][i++]) {
case Script_SByte:
- case Script_Byte: bytecount++;
+ case Script_Byte:
+ bytecount++;
break;
case Script_Word:
- case Script_SWord: bytecount += 2;
+ case Script_SWord:
+ bytecount += 2;
break;
case Script_SVariable:
@@ -1450,7 +1419,7 @@ disassemble(state_t *s, reg_t pos, int print_bw_tag, int print_bytecode)
}
if (print_bw_tag)
- sciprintf("[%c] ", opsize? 'B' : 'W');
+ sciprintf("[%c] ", opsize ? 'B' : 'W');
sciprintf("%s", s->opcodes[opcode].name);
i = 0;
@@ -1458,15 +1427,19 @@ disassemble(state_t *s, reg_t pos, int print_bw_tag, int print_bytecode)
switch (formats[opcode][i++]) {
- case Script_Invalid: sciprintf("-Invalid operation-"); break;
+ case Script_Invalid:
+ sciprintf("-Invalid operation-");
+ break;
case Script_SByte:
- case Script_Byte: sciprintf(" %02x", scr[retval.offset++]); break;
+ case Script_Byte:
+ sciprintf(" %02x", scr[retval.offset++]);
+ break;
case Script_Word:
case Script_SWord:
sciprintf(" %04x", 0xffff & (scr[retval.offset]
- | (scr[retval.offset+1] << 8)));
+ | (scr[retval.offset+1] << 8)));
retval.offset += 2;
break;
@@ -1481,15 +1454,15 @@ disassemble(state_t *s, reg_t pos, int print_bw_tag, int print_bytecode)
param_value = scr[retval.offset++];
else {
param_value = 0xffff & (scr[retval.offset]
- | (scr[retval.offset+1] << 8));
+ | (scr[retval.offset+1] << 8));
retval.offset += 2;
}
if (opcode == op_callk)
sciprintf(" %s[%x]", (param_value < s->kfunct_nr) ?
- ((param_value < s->kernel_names_nr) ? s->kernel_names[param_value] : "[Unknown(postulated)]")
- : "<invalid>", param_value);
- else sciprintf(opsize? " %02x" : " %04x", param_value);
+ ((param_value < s->kernel_names_nr) ? s->kernel_names[param_value] : "[Unknown(postulated)]")
+ : "<invalid>", param_value);
+ else sciprintf(opsize ? " %02x" : " %04x", param_value);
break;
@@ -1498,10 +1471,10 @@ disassemble(state_t *s, reg_t pos, int print_bw_tag, int print_bytecode)
param_value = scr[retval.offset++];
else {
param_value = 0xffff & (scr[retval.offset]
- | (scr[retval.offset+1] << 8));
+ | (scr[retval.offset+1] << 8));
retval.offset += 2;
}
- sciprintf (opsize? " %02x [%04x]" : " %04x", param_value);
+ sciprintf(opsize ? " %02x [%04x]" : " %04x", param_value);
break;
case Script_SRelative:
@@ -1509,13 +1482,14 @@ disassemble(state_t *s, reg_t pos, int print_bw_tag, int print_bytecode)
param_value = scr[retval.offset++];
else {
param_value = 0xffff & (scr[retval.offset]
- | (scr[retval.offset+1] << 8));
+ | (scr[retval.offset+1] << 8));
retval.offset += 2;
}
- sciprintf (opsize? " %02x [%04x]" : " %04x [%04x]", param_value, (0xffff) & (retval.offset + param_value));
+ sciprintf(opsize ? " %02x [%04x]" : " %04x [%04x]", param_value, (0xffff) & (retval.offset + param_value));
break;
- case Script_End: retval = NULL_REG;
+ case Script_End:
+ retval = NULL_REG;
break;
default:
@@ -1525,10 +1499,10 @@ disassemble(state_t *s, reg_t pos, int print_bw_tag, int print_bytecode)
if (REG_EQ(pos, *p_pc)) /* Extra information if debugging the current opcode */
- if ((opcode == op_pTos)||(opcode == op_sTop)||
- (opcode == op_pToa)||(opcode == op_aTop)||
- (opcode == op_dpToa)||(opcode == op_ipToa)||
- (opcode == op_dpTos)||(opcode == op_ipTos)) {
+ if ((opcode == op_pTos) || (opcode == op_sTop) ||
+ (opcode == op_pToa) || (opcode == op_aTop) ||
+ (opcode == op_dpToa) || (opcode == op_ipToa) ||
+ (opcode == op_dpTos) || (opcode == op_ipTos)) {
int prop_ofs = scr[pos.offset + 1];
int prop_id = prop_ofs_to_id(s, prop_ofs, *p_objp);
@@ -1541,7 +1515,7 @@ disassemble(state_t *s, reg_t pos, int print_bw_tag, int print_bytecode)
if (opcode == op_callk) {
int stackframe = (scr[pos.offset + 2] >> 1)
- + (*p_restadjust);
+ + (*p_restadjust);
int argc = ((*p_sp)[- stackframe - 1]).offset;
if (s->version >= SCI_VERSION_FTU_NEW_SCRIPT_HEADER)
@@ -1553,13 +1527,12 @@ disassemble(state_t *s, reg_t pos, int print_bw_tag, int print_bytecode)
for (int j = 0; j < argc; j++) {
sciprintf(PREG, PRINT_REG((*p_sp)[j - stackframe]));
- if (j+1 < argc)
+ if (j + 1 < argc)
sciprintf(", ");
}
sciprintf(")\n");
- }
- else if ((opcode == op_send) || (opcode == op_self)) {
+ } else if ((opcode == op_send) || (opcode == op_self)) {
int restmod = *p_restadjust;
int stackframe = (scr[pos.offset + 1] >> 1) + restmod;
reg_t *sb = *p_sp;
@@ -1585,10 +1558,10 @@ disassemble(state_t *s, reg_t pos, int print_bw_tag, int print_bytecode)
name = "<invalid>";
sciprintf(" %s::%s[", name, (selector > s->selector_names_nr)
- ? "<invalid>" : selector_name(s,selector));
+ ? "<invalid>" : selector_name(s, selector));
switch (lookup_selector(s, called_obj_addr, selector,
- &val_ref, &fun_ref)) {
+ &val_ref, &fun_ref)) {
case SELECTOR_METHOD:
sciprintf("FUNCT");
argc += restmod;
@@ -1626,58 +1599,55 @@ disassemble(state_t *s, reg_t pos, int print_bw_tag, int print_bytecode)
}
int
-c_dumpnodes(state_t *s)
-{
- int end = MIN(cmd_params[0].val, VOCAB_TREE_NODES);
- int i;
+c_dumpnodes(state_t *s) {
+ int end = MIN(cmd_params[0].val, VOCAB_TREE_NODES);
+ int i;
- if (!_debugstate_valid) {
- sciprintf("Not in debug state\n");
- return 1;
- }
+ if (!_debugstate_valid) {
+ sciprintf("Not in debug state\n");
+ return 1;
+ }
- for (i = 0; i < end; i++) {
- sciprintf(" Node %03x: ", i);
- if (s->parser_nodes[i].type == PARSE_TREE_NODE_LEAF)
- sciprintf("Leaf: %04x\n", s->parser_nodes[i].content.value);
- else
- sciprintf("Branch: ->%04x, ->%04x\n", s->parser_nodes[i].content.branches[0],
- s->parser_nodes[i].content.branches[1]);
- }
+ for (i = 0; i < end; i++) {
+ sciprintf(" Node %03x: ", i);
+ if (s->parser_nodes[i].type == PARSE_TREE_NODE_LEAF)
+ sciprintf("Leaf: %04x\n", s->parser_nodes[i].content.value);
+ else
+ sciprintf("Branch: ->%04x, ->%04x\n", s->parser_nodes[i].content.branches[0],
+ s->parser_nodes[i].content.branches[1]);
+ }
- return 0;
+ return 0;
}
static const char *varnames[] = {"global", "local", "temp", "param"};
static const char *varabbrev = "gltp";
int
-c_vmvarlist(state_t *s)
-{
- int i;
+c_vmvarlist(state_t *s) {
+ int i;
- for (i=0;i<4;i++) {
- sciprintf("%s vars at "PREG" ",
- varnames[i],
- PRINT_REG(make_reg(p_var_segs[i], p_vars[i] - p_var_base[i])));
- if (p_var_max)
- sciprintf(" total %d", p_var_max[i]);
- sciprintf("\n");
- }
- return 0;
+ for (i = 0;i < 4;i++) {
+ sciprintf("%s vars at "PREG" ",
+ varnames[i],
+ PRINT_REG(make_reg(p_var_segs[i], p_vars[i] - p_var_base[i])));
+ if (p_var_max)
+ sciprintf(" total %d", p_var_max[i]);
+ sciprintf("\n");
+ }
+ return 0;
}
int
-c_vmvars(state_t *s)
-{
+c_vmvars(state_t *s) {
const char *vartype_pre = strchr(varabbrev, *cmd_params[0].str);
int vartype;
int idx = cmd_params[1].val;
if (!vartype_pre) {
sciprintf("Invalid variable type '%c'\n",
- *cmd_params[0].str);
+ *cmd_params[0].str);
return 1;
}
vartype = vartype_pre - varabbrev;
@@ -1687,16 +1657,16 @@ c_vmvars(state_t *s)
return 1;
}
if ((p_var_max)
- && (p_var_max[vartype] <= idx)) {
+ && (p_var_max[vartype] <= idx)) {
sciprintf("Max. index is %d (0x%x)\n",
- p_var_max[vartype], p_var_max[vartype]);
+ p_var_max[vartype], p_var_max[vartype]);
return 1;
}
- switch(cmd_paramlength) {
+ switch (cmd_paramlength) {
case 2:
sciprintf("%s var %d == "PREG"\n", varnames[vartype], idx,
- PRINT_REG(p_vars[vartype][idx]));
+ PRINT_REG(p_vars[vartype][idx]));
break;
case 3:
@@ -1725,15 +1695,13 @@ static const char *_codebug_colstr = "\033[31m\033[1m";
static const char *_codebug_uncolstr = "\033[0m";
static void
-codebug_send_command(const char *cmd)
-{
+codebug_send_command(const char *cmd) {
if (_codebug_pid)
write(_codebug_commands[1], cmd, strlen(cmd));
}
static void
-_print_colored(int from_fd)
-{
+_print_colored(int from_fd) {
char buf[CODEBUG_BUFSIZE + 64];
char *buf_offset;
int br;
@@ -1756,28 +1724,25 @@ _print_colored(int from_fd)
}
void
-_codebug_kill_children()
-{
+_codebug_kill_children() {
if (_codebug_pid)
kill(_codebug_pid, SIGTERM);
}
void
-_codebug_sighandler(int i)
-{
+_codebug_sighandler(int i) {
if (i == SIGPIPE || i == SIGTERM)
kill(_codebug_pid, SIGTERM);
write(1, _codebug_uncolstr, strlen(_codebug_uncolstr));
fprintf(stderr, "Child process failed, aborting!\n");
fprintf(stderr, "(if you're using the UNIX sound server, you'll probably get spurious"
- " warnings regarding the sound server now...)\n");
+ " warnings regarding the sound server now...)\n");
exit(1);
}
static void
-do_codebug(char *path, char *datapath)
-{
+do_codebug(char *path, char *datapath) {
pipe(_codebug_stdin);
pipe(_codebug_stdout);
close(_codebug_commands[1]);
@@ -1786,7 +1751,7 @@ do_codebug(char *path, char *datapath)
if (_codebug_pid) {
fd_set fs;
int max_n;
-
+
/* parent process */
close(_codebug_stdin[0]);
close(_codebug_stdout[1]);
@@ -1840,8 +1805,7 @@ do_codebug(char *path, char *datapath)
}
static int
-c_codebug(state_t *s)
-{
+c_codebug(state_t *s) {
char *path = cmd_params[0].str;
if (_codebug_pid) {
@@ -1864,8 +1828,7 @@ c_codebug(state_t *s)
#endif
static int
-c_backtrace(state_t *s)
-{
+c_backtrace(state_t *s) {
int i;
if (!_debugstate_valid) {
@@ -1883,18 +1846,18 @@ c_backtrace(state_t *s)
case EXEC_STACK_TYPE_CALL: {/* Normal function */
sciprintf(" %x:[%x] %s::%s(", i, call->origin,
- objname, (call->selector == -1)? "<call[be]?>":
- selector_name(s,call->selector));
+ objname, (call->selector == -1) ? "<call[be]?>" :
+ selector_name(s, call->selector));
}
- break;
+ break;
case EXEC_STACK_TYPE_KERNEL: /* Kernel function */
sciprintf(" %x:[%x] k%s(", i, call->origin, s->kernel_names[-(call->selector)-42]);
break;
case EXEC_STACK_TYPE_VARSELECTOR:
- sciprintf(" %x:[%x] vs%s %s::%s (", i, call->origin, (call->argc)? "write" : "read",
- objname, s->selector_names[call->selector]);
+ sciprintf(" %x:[%x] vs%s %s::%s (", i, call->origin, (call->argc) ? "write" : "read",
+ objname, s->selector_names[call->selector]);
break;
} /* switch */
@@ -1914,17 +1877,17 @@ c_backtrace(state_t *s)
sciprintf("...");
sciprintf(")\n obj@"PREG,
- PRINT_REG(call->objp));
+ PRINT_REG(call->objp));
if (call->type == EXEC_STACK_TYPE_CALL) {
sciprintf(" pc="PREG,
- PRINT_REG(call->addr.pc));
+ PRINT_REG(call->addr.pc));
if (call->sp == CALL_SP_CARRY)
sciprintf(" sp,fp:carry");
else {
sciprintf(" sp="PSTK,
- PRINT_STK(call->sp));
+ PRINT_STK(call->sp));
sciprintf(" fp="PSTK,
- PRINT_STK(call->fp));
+ PRINT_STK(call->fp));
}
} else
sciprintf(" pc:none");
@@ -1938,14 +1901,13 @@ c_backtrace(state_t *s)
}
static int
-c_redraw_screen(state_t *s)
-{
+c_redraw_screen(state_t *s) {
if (!_debugstate_valid) {
sciprintf("Not in debug state\n");
return 1;
}
- s->visual->draw(GFXW(s->visual), gfx_point(0,0));
+ s->visual->draw(GFXW(s->visual), gfx_point(0, 0));
gfxop_update_box(s->gfx_state, gfx_rect(0, 0, 320, 200));
gfxop_update(s->gfx_state);
gfxop_usleep(s->gfx_state, 10);
@@ -1955,8 +1917,7 @@ c_redraw_screen(state_t *s)
static int
-c_clear_screen(state_t *s)
-{
+c_clear_screen(state_t *s) {
if (!_debugstate_valid) {
sciprintf("Not in debug state\n");
return 1;
@@ -1968,30 +1929,28 @@ c_clear_screen(state_t *s)
}
static int
-c_visible_map(state_t *s)
-{
- if (!s) {
- sciprintf("Not in debug state\n");
- return 1;
- }
+c_visible_map(state_t *s) {
+ if (!s) {
+ sciprintf("Not in debug state\n");
+ return 1;
+ }
//WARNING(fixme!)
#if 0
- if (s->onscreen_console)
- con_restore_screen(s, s->osc_backup);
+ if (s->onscreen_console)
+ con_restore_screen(s, s->osc_backup);
- if (cmd_params[0].val <= 3) s->pic_visible_map = cmd_params[0].val;
- c_redraw_screen(s);
+ if (cmd_params[0].val <= 3) s->pic_visible_map = cmd_params[0].val;
+ c_redraw_screen(s);
- if (s->onscreen_console)
- s->osc_backup = con_backup_screen(s);
+ if (s->onscreen_console)
+ s->osc_backup = con_backup_screen(s);
#endif
- return 0;
+ return 0;
}
static int
-c_gfx_current_port(state_t *s)
-{
+c_gfx_current_port(state_t *s) {
if (!_debugstate_valid) {
sciprintf("Not in debug state\n");
return 1;
@@ -2005,8 +1964,7 @@ c_gfx_current_port(state_t *s)
}
static int
-c_gfx_print_port(state_t *s)
-{
+c_gfx_print_port(state_t *s) {
gfxw_port_t *port;
if (!_debugstate_valid) {
@@ -2034,8 +1992,7 @@ c_gfx_print_port(state_t *s)
}
static int
-c_gfx_priority(state_t *s)
-{
+c_gfx_priority(state_t *s) {
if (!_debugstate_valid) {
sciprintf("Not in debug state\n");
return 1;
@@ -2056,8 +2013,7 @@ c_gfx_priority(state_t *s)
}
static int
-c_gfx_print_visual(state_t *s)
-{
+c_gfx_print_visual(state_t *s) {
if (!_debugstate_valid) {
sciprintf("Not in debug state\n");
return 1;
@@ -2072,8 +2028,7 @@ c_gfx_print_visual(state_t *s)
}
static int
-c_gfx_print_dynviews(state_t *s)
-{
+c_gfx_print_dynviews(state_t *s) {
if (!_debugstate_valid) {
sciprintf("Not in debug state\n");
return 1;
@@ -2088,8 +2043,7 @@ c_gfx_print_dynviews(state_t *s)
}
static int
-c_gfx_print_dropviews(state_t *s)
-{
+c_gfx_print_dropviews(state_t *s) {
if (!_debugstate_valid) {
sciprintf("Not in debug state\n");
return 1;
@@ -2104,8 +2058,7 @@ c_gfx_print_dropviews(state_t *s)
}
static int
-c_gfx_drawpic(state_t *s)
-{
+c_gfx_drawpic(state_t *s) {
int flags = 1, default_palette = 0;
if (!_debugstate_valid) {
@@ -2132,8 +2085,7 @@ extern gfxw_widget_t *debug_widgets[];
extern int debug_widget_pos;
static int
-c_gfx_print_widget(state_t *s)
-{
+c_gfx_print_widget(state_t *s) {
if (!_debugstate_valid) {
sciprintf("Not in debug state\n");
return 1;
@@ -2148,8 +2100,8 @@ c_gfx_print_widget(state_t *s)
debug_widgets[widget_nr]->print(debug_widgets[widget_nr], 0);
}
- } else if(debug_widget_pos>1)
- sciprintf("Widgets 0-%d are active\n", debug_widget_pos-1);
+ } else if (debug_widget_pos > 1)
+ sciprintf("Widgets 0-%d are active\n", debug_widget_pos - 1);
else if (debug_widget_pos == 1)
sciprintf("Widget 0 is active\n");
else
@@ -2160,8 +2112,7 @@ c_gfx_print_widget(state_t *s)
#endif
static int
-c_gfx_show_map(state_t *s)
-{
+c_gfx_show_map(state_t *s) {
int map = cmd_params[0].val;
if (!_debugstate_valid) {
sciprintf("Not in debug state\n");
@@ -2197,8 +2148,7 @@ c_gfx_show_map(state_t *s)
static int
-c_gfx_draw_cel(state_t *s)
-{
+c_gfx_draw_cel(state_t *s) {
int view = cmd_params[0].val;
int loop = cmd_params[1].val;
int cel = cmd_params[2].val;
@@ -2210,15 +2160,14 @@ c_gfx_draw_cel(state_t *s)
gfxop_set_clip_zone(s->gfx_state, gfx_rect_fullscreen);
gfxop_draw_cel(s->gfx_state, view, loop, cel, gfx_point(160, 100),
- s->ega_colors[0], palette);
+ s->ega_colors[0], palette);
gfxop_update(s->gfx_state);
return 0;
}
static int
-c_gfx_fill_screen(state_t *s)
-{
+c_gfx_fill_screen(state_t *s) {
int col = cmd_params[0].val;
if (!s) {
@@ -2237,8 +2186,7 @@ c_gfx_fill_screen(state_t *s)
}
static int
-c_gfx_draw_rect(state_t *s)
-{
+c_gfx_draw_rect(state_t *s) {
int col = cmd_params[4].val;
if (!s) {
@@ -2257,8 +2205,7 @@ c_gfx_draw_rect(state_t *s)
}
static int
-c_gfx_propagate_rect(state_t *s)
-{
+c_gfx_propagate_rect(state_t *s) {
int map = cmd_params[4].val;
rect_t rect;
@@ -2273,9 +2220,9 @@ c_gfx_propagate_rect(state_t *s)
gfxop_set_clip_zone(s->gfx_state, gfx_rect_fullscreen);
rect = gfx_rect(cmd_params[0].val,
- cmd_params[1].val,
- cmd_params[2].val,
- cmd_params[3].val);
+ cmd_params[1].val,
+ cmd_params[2].val,
+ cmd_params[3].val);
if (map == 1)
gfxop_clear_box(s->gfx_state, rect);
@@ -2296,13 +2243,12 @@ bb = GET_SELECTOR(pos, bb);
#if 0
// Unreferenced - removed
static int
-c_gfx_draw_viewobj(state_t *s)
-{
+c_gfx_draw_viewobj(state_t *s) {
#ifdef __GNUC__
#warning "Re-implement con:gfx_draw_viewobj"
#endif
#if 0
- heap_ptr pos = (heap_ptr) (cmd_params[0].val);
+ heap_ptr pos = (heap_ptr)(cmd_params[0].val);
int is_view;
int x, y, priority;
int nsLeft, nsRight, nsBottom, nsTop;
@@ -2325,13 +2271,13 @@ c_gfx_draw_viewobj(state_t *s)
is_view =
- (lookup_selector(s, pos, s->selector_map.x, NULL) == SELECTOR_VARIABLE)
- &&
- (lookup_selector(s, pos, s->selector_map.brLeft, NULL) == SELECTOR_VARIABLE)
- &&
- (lookup_selector(s, pos, s->selector_map.signal, NULL) == SELECTOR_VARIABLE)
- &&
- (lookup_selector(s, pos, s->selector_map.nsTop, NULL) == SELECTOR_VARIABLE);
+ (lookup_selector(s, pos, s->selector_map.x, NULL) == SELECTOR_VARIABLE)
+ &&
+ (lookup_selector(s, pos, s->selector_map.brLeft, NULL) == SELECTOR_VARIABLE)
+ &&
+ (lookup_selector(s, pos, s->selector_map.signal, NULL) == SELECTOR_VARIABLE)
+ &&
+ (lookup_selector(s, pos, s->selector_map.nsTop, NULL) == SELECTOR_VARIABLE);
if (!is_view) {
sciprintf("Not a dynamic View object.\n");
@@ -2351,27 +2297,27 @@ c_gfx_draw_viewobj(state_t *s)
nsBottom += 10;
gfxop_fill_box(s->gfx_state, gfx_rect(nsLeft, nsTop,
- nsRight - nsLeft + 1,
- nsBottom - nsTop + 1),
- s->ega_colors[2]);
+ nsRight - nsLeft + 1,
+ nsBottom - nsTop + 1),
+ s->ega_colors[2]);
gfxop_fill_box(s->gfx_state, gfx_rect(brLeft, brTop,
- brRight - brLeft + 1,
- brBottom - brTop + 1),
- s->ega_colors[1]);
+ brRight - brLeft + 1,
+ brBottom - brTop + 1),
+ s->ega_colors[1]);
- gfxop_fill_box(s->gfx_state, gfx_rect(x-1, y-1,
- 3, 3),
- s->ega_colors[0]);
+ gfxop_fill_box(s->gfx_state, gfx_rect(x - 1, y - 1,
+ 3, 3),
+ s->ega_colors[0]);
- gfxop_fill_box(s->gfx_state, gfx_rect(x-1, y,
- 3, 1),
- s->ega_colors[priority]);
+ gfxop_fill_box(s->gfx_state, gfx_rect(x - 1, y,
+ 3, 1),
+ s->ega_colors[priority]);
- gfxop_fill_box(s->gfx_state, gfx_rect(x, y-1,
- 1, 3),
- s->ega_colors[priority]);
+ gfxop_fill_box(s->gfx_state, gfx_rect(x, y - 1,
+ 1, 3),
+ s->ega_colors[priority]);
gfxop_update(s->gfx_state);
@@ -2381,8 +2327,7 @@ c_gfx_draw_viewobj(state_t *s)
#endif
static int
-c_gfx_flush_resources(state_t *s)
-{
+c_gfx_flush_resources(state_t *s) {
if (!_debugstate_valid) {
sciprintf("Not in debug state\n");
return 1;
@@ -2397,28 +2342,26 @@ c_gfx_flush_resources(state_t *s)
}
static int
-c_gfx_update_zone(state_t *s)
-{
+c_gfx_update_zone(state_t *s) {
if (!_debugstate_valid) {
sciprintf("Not in debug state\n");
return 1;
}
return s->gfx_state->driver->update(s->gfx_state->driver,
- gfx_rect(cmd_params[0].val,
- cmd_params[1].val,
- cmd_params[2].val,
- cmd_params[3].val),
- gfx_point(cmd_params[0].val,
- cmd_params[1].val),
- GFX_BUFFER_FRONT
- );
+ gfx_rect(cmd_params[0].val,
+ cmd_params[1].val,
+ cmd_params[2].val,
+ cmd_params[3].val),
+ gfx_point(cmd_params[0].val,
+ cmd_params[1].val),
+ GFX_BUFFER_FRONT
+ );
}
static int
-c_disasm_addr(state_t *s)
-{
+c_disasm_addr(state_t *s) {
reg_t vpc = cmd_params[0].reg;
int op_count = 1;
int do_bwc = 0;
@@ -2430,16 +2373,16 @@ c_disasm_addr(state_t *s)
size += vpc.offset; /* total segment size */
for (i = 1; i < cmd_paramlength; i++) {
- if (!strcasecmp(cmd_params[i].str, "bwt"))
- do_bwc = 1;
- else if (!strcasecmp(cmd_params[i].str, "bc"))
- do_bytes = 1;
- else if (toupper(cmd_params[i].str[0]) == 'C')
- op_count = atoi(cmd_params[i].str + 1);
- else {
- invalid = 1;
- sciprintf("Invalid option '%s'\n", cmd_params[i].str);
- }
+ if (!strcasecmp(cmd_params[i].str, "bwt"))
+ do_bwc = 1;
+ else if (!strcasecmp(cmd_params[i].str, "bc"))
+ do_bytes = 1;
+ else if (toupper(cmd_params[i].str[0]) == 'C')
+ op_count = atoi(cmd_params[i].str + 1);
+ else {
+ invalid = 1;
+ sciprintf("Invalid option '%s'\n", cmd_params[i].str);
+ }
}
if (invalid || op_count < 0)
@@ -2453,8 +2396,7 @@ c_disasm_addr(state_t *s)
static int
-c_disasm(state_t *s)
-{
+c_disasm(state_t *s) {
object_t *obj = obj_get(s, cmd_params[0].reg);
int selector_id = script_find_selector(s, cmd_params[1].str);
reg_t addr;
@@ -2482,8 +2424,7 @@ c_disasm(state_t *s)
}
static int
-c_sg(state_t *s)
-{
+c_sg(state_t *s) {
_debug_seeking = _DEBUG_SEEK_GLOBAL;
_debug_seek_special = cmd_params[0].val;
_debugstate_valid = 0;
@@ -2493,8 +2434,7 @@ c_sg(state_t *s)
static int
-c_snk(state_t *s)
-{
+c_snk(state_t *s) {
int callk_index;
char *endptr;
@@ -2507,25 +2447,22 @@ c_snk(state_t *s)
/* Try to convert the parameter to a number. If the conversion stops
before end of string, assume that the parameter is a function name
and scan the function table to find out the index. */
- callk_index = strtoul (cmd_params [0].str, &endptr, 0);
- if (*endptr != '\0')
- {
- int i;
-
- callk_index = -1;
- for (i = 0; i < s->kernel_names_nr; i++)
- if (!strcmp (cmd_params [0].str, s->kernel_names [i]))
- {
- callk_index = i;
- break;
- }
-
- if (callk_index == -1)
- {
- sciprintf ("Unknown kernel function '%s'\n", cmd_params [0].str);
- return 1;
- }
+ callk_index = strtoul(cmd_params [0].str, &endptr, 0);
+ if (*endptr != '\0') {
+ int i;
+
+ callk_index = -1;
+ for (i = 0; i < s->kernel_names_nr; i++)
+ if (!strcmp(cmd_params [0].str, s->kernel_names [i])) {
+ callk_index = i;
+ break;
+ }
+
+ if (callk_index == -1) {
+ sciprintf("Unknown kernel function '%s'\n", cmd_params [0].str);
+ return 1;
}
+ }
_debug_seeking = _DEBUG_SEEK_SPECIAL_CALLK;
_debug_seek_special = callk_index;
@@ -2539,8 +2476,7 @@ c_snk(state_t *s)
static int
-c_sret(state_t *s)
-{
+c_sret(state_t *s) {
_debug_seeking = _DEBUG_SEEK_LEVEL_RET;
_debug_seek_level = s->execution_stack_pos;
_debugstate_valid = 0;
@@ -2548,8 +2484,7 @@ c_sret(state_t *s)
}
static int
-c_go(state_t *s)
-{
+c_go(state_t *s) {
_debug_seeking = 0;
_debugstate_valid = 0;
script_debug_flag = 0;
@@ -2558,15 +2493,13 @@ c_go(state_t *s)
static int
-c_set_acc(state_t *s)
-{
+c_set_acc(state_t *s) {
s->r_acc = cmd_params[0].reg;
return 0;
}
static int
-c_send(state_t *s)
-{
+c_send(state_t *s) {
reg_t object = cmd_params[0].reg;
char *selector_name = cmd_params[1].str;
stack_ptr_t stackframe = s->execution_stack->sp;
@@ -2578,23 +2511,20 @@ c_send(state_t *s)
selector_id = vocabulary_lookup_sname(s->selector_names, selector_name);
- if (selector_id < 0)
- {
+ if (selector_id < 0) {
sciprintf("Unknown selector: \"%s\"\n", selector_name);
return 1;
}
o = obj_get(s, object);
- if (o == NULL)
- {
+ if (o == NULL) {
sciprintf("Address \""PREG"\" is not an object\n", PRINT_REG(object));
return 1;
}
selector_type = lookup_selector(s, object, selector_id, &vptr, &fptr);
- if (selector_type == SELECTOR_NONE)
- {
+ if (selector_type == SELECTOR_NONE) {
sciprintf("Object does not support selector: \"%s\"\n", selector_name);
return 1;
}
@@ -2602,19 +2532,19 @@ c_send(state_t *s)
stackframe[0] = make_reg(0, selector_id);
stackframe[1] = make_reg(0, cmd_paramlength - 2);
- for (i=2; i<cmd_paramlength; i++)
+ for (i = 2; i < cmd_paramlength; i++)
stackframe[i] = cmd_params[i].reg;
xstack = add_exec_stack_entry(s, fptr, s->execution_stack->sp + cmd_paramlength, object,
- cmd_paramlength - 2, s->execution_stack->sp - 1, 0, object,
- s->execution_stack_pos, SCI_XS_CALLEE_LOCALS);
- xstack->selector = selector_id;
+ cmd_paramlength - 2, s->execution_stack->sp - 1, 0, object,
+ s->execution_stack_pos, SCI_XS_CALLEE_LOCALS);
+ xstack->selector = selector_id;
xstack->type = selector_type == SELECTOR_VARIABLE ? EXEC_STACK_TYPE_VARSELECTOR :
- EXEC_STACK_TYPE_CALL;
+ EXEC_STACK_TYPE_CALL;
/* Now commit the actual function: */
xstack = send_selector(s, object, object,
- stackframe, cmd_paramlength - 2, stackframe);
+ stackframe, cmd_paramlength - 2, stackframe);
xstack->sp += cmd_paramlength;
xstack->fp += cmd_paramlength;
@@ -2625,8 +2555,7 @@ c_send(state_t *s)
}
static int
-c_resource_id(state_t *s)
-{
+c_resource_id(state_t *s) {
int id = cmd_params[0].val;
sciprintf("%s.%d (0x%x)\n", sci_resource_types[id >> 11], id &0x7ff, id & 0x7ff);
@@ -2634,8 +2563,7 @@ c_resource_id(state_t *s)
}
static int
-c_listclones(state_t *s)
-{
+c_listclones(state_t *s) {
/*
int i, j = 0;
sciprintf("Listing all logged clones:\n");
@@ -2662,10 +2590,9 @@ typedef struct {
static void
handle_config_update(const generic_config_flag_t *flags_list, int flags_nr,
- const char *subsystem,
- int *active_options_p,
- char *changestring /* or NULL to display*/)
-{
+ const char *subsystem,
+ int *active_options_p,
+ char *changestring /* or NULL to display*/) {
if (!changestring) {
int j;
@@ -2675,10 +2602,10 @@ handle_config_update(const generic_config_flag_t *flags_list, int flags_nr,
for (j = 0; j < flags_nr; j++)
if (*active_options_p
- & flags_list[j].flag) {
+ & flags_list[j].flag) {
sciprintf(" - %s (%c)\n",
- flags_list[j].name,
- flags_list[j].option);
+ flags_list[j].name,
+ flags_list[j].option);
}
} else {
@@ -2704,12 +2631,12 @@ handle_config_update(const generic_config_flag_t *flags_list, int flags_nr,
else
for (k = 0; !flag && k < flags_nr; k++)
if (flags_list[k].option
- == changestring[j])
+ == changestring[j])
flag = flags_list[k].flag;
if (!flag) {
sciprintf("Invalid/unknown mode flag '%c'\n",
- changestring[j]);
+ changestring[j]);
return;
}
flags |= flag;
@@ -2725,8 +2652,7 @@ handle_config_update(const generic_config_flag_t *flags_list, int flags_nr,
static int
c_handle_config_update(const generic_config_flag_t *flags, int flags_nr,
- const char *subsystem, int *active_options_p)
-{
+ const char *subsystem, int *active_options_p) {
unsigned int i;
if (!_debugstate_valid) {
@@ -2736,13 +2662,13 @@ c_handle_config_update(const generic_config_flag_t *flags, int flags_nr,
if (cmd_paramlength == 0)
handle_config_update(flags, flags_nr,
- subsystem, active_options_p,
- 0);
+ subsystem, active_options_p,
+ 0);
for (i = 0; i < cmd_paramlength; i++)
handle_config_update(flags, flags_nr,
- subsystem, active_options_p,
- cmd_params[i].str);
+ subsystem, active_options_p,
+ cmd_params[i].str);
return 0;
}
@@ -2769,54 +2695,50 @@ const generic_config_flag_t SCIk_Debug_Names[SCIk_DEBUG_MODES] = {
void
-set_debug_mode (struct _state *s, int mode, const char *areas)
-{
+set_debug_mode(struct _state *s, int mode, const char *areas) {
char *param = (char*)sci_malloc(strlen(areas) + 2);
- param[0] = (mode)? '+' : '-';
+ param[0] = (mode) ? '+' : '-';
strcpy(param + 1, areas);
handle_config_update(SCIk_Debug_Names, SCIk_DEBUG_MODES,
- "VM and kernel",
- (int *) &(s->debug_mode),
- param);
+ "VM and kernel",
+ (int *) &(s->debug_mode),
+ param);
sci_free(param);
}
int
-c_debuglog(state_t *s)
-{
+c_debuglog(state_t *s) {
return c_handle_config_update(SCIk_Debug_Names, SCIk_DEBUG_MODES,
- "VM and kernel",
- (int *) &(s->debug_mode));
+ "VM and kernel",
+ (int *) &(s->debug_mode));
}
#define SFX_DEBUG_MODES 2
#define FROBNICATE_HANDLE(reg) ((reg).segment << 16 | (reg).offset)
static int
-c_sfx_debuglog(state_t *s)
-{
+c_sfx_debuglog(state_t *s) {
const generic_config_flag_t sfx_debug_modes[SFX_DEBUG_MODES] = {
{"Song activation/deactivation", 's', SFX_DEBUG_SONGS},
{"Song cue polling and delivery", 'c', SFX_DEBUG_CUES}
};
return c_handle_config_update(sfx_debug_modes, SFX_DEBUG_MODES,
- "sound subsystem",
- (int *) &(s->sound.debug));
+ "sound subsystem",
+ (int *) &(s->sound.debug));
}
static int
-c_sfx_remove(state_t *s)
-{
+c_sfx_remove(state_t *s) {
reg_t id = cmd_params[0].reg;
int handle = FROBNICATE_HANDLE(id);
if (id.segment) {
sfx_song_set_status(&s->sound,
- handle, SOUND_STATUS_STOPPED);
+ handle, SOUND_STATUS_STOPPED);
sfx_remove_song(&s->sound, handle);
PUT_SEL32V(id, signal, -1);
PUT_SEL32V(id, nodePtr, 0);
@@ -2829,8 +2751,7 @@ c_sfx_remove(state_t *s)
#define GFX_DEBUG_MODES 4
int
-c_gfx_debuglog(state_t *s)
-{
+c_gfx_debuglog(state_t *s) {
gfx_driver_t *drv = s->gfx_state->driver;
const generic_config_flag_t gfx_debug_modes[GFX_DEBUG_MODES] = {
{ "Mouse Pointer", 'p', GFX_DEBUG_POINTER},
@@ -2840,14 +2761,13 @@ c_gfx_debuglog(state_t *s)
};
return c_handle_config_update(gfx_debug_modes, GFX_DEBUG_MODES,
- "graphics subsystem",
- (int *) &(drv->debug_flags));
+ "graphics subsystem",
+ (int *) &(drv->debug_flags));
}
int
-c_dump_words(state_t *s)
-{
+c_dump_words(state_t *s) {
int i;
if (!s) {
@@ -2870,19 +2790,17 @@ c_dump_words(state_t *s)
}
int
-c_simkey(state_t *s)
-{
- _kdebug_cheap_event_hack = cmd_params[0].val;
- return 0;
+c_simkey(state_t *s) {
+ _kdebug_cheap_event_hack = cmd_params[0].val;
+ return 0;
}
static int
-c_is_sample(state_t *s)
-{
+c_is_sample(state_t *s) {
resource_t *song = scir_find_resource(s->resmgr,
- sci_sound,
- cmd_params[0].val,
- 0);
+ sci_sound,
+ cmd_params[0].val,
+ 0);
song_iterator_t *songit;
sfx_pcm_feed_t *data;
@@ -2892,7 +2810,7 @@ c_is_sample(state_t *s)
}
songit = songit_new(song->data, song->size, SCI_SONG_ITERATOR_TYPE_SCI0,
- 0xcaffe /* What do I care about the ID? */);
+ 0xcaffe /* What do I care about the ID? */);
if (!songit) {
sciprintf("Error-- Could not convert to song iterator\n");
@@ -2901,10 +2819,10 @@ c_is_sample(state_t *s)
if ((data = songit->get_pcm_feed(songit))) {
sciprintf("\nIs sample (encoding %dHz/%s/%04x).\n",
- data->conf.rate, (data->conf.stereo)?
- ((data->conf.stereo == SFX_PCM_STEREO_LR)?
- "stereo-LR" : "stereo-RL") : "mono",
- data->conf.format);
+ data->conf.rate, (data->conf.stereo) ?
+ ((data->conf.stereo == SFX_PCM_STEREO_LR) ?
+ "stereo-LR" : "stereo-RL") : "mono",
+ data->conf.format);
data->destroy(data);
} else
sciprintf("Valid song, but not a sample.\n");
@@ -2915,10 +2833,9 @@ c_is_sample(state_t *s)
}
int
-c_simsoundcue(state_t *s)
-{
- _kdebug_cheap_soundcue_hack = cmd_params[0].val;
- return 0;
+c_simsoundcue(state_t *s) {
+ _kdebug_cheap_soundcue_hack = cmd_params[0].val;
+ return 0;
}
@@ -2941,8 +2858,7 @@ bb = GET_SELECTOR(pos, bb);
#warning "Re-implement viewobjinfo"
#endif
static void
-viewobjinfo(state_t *s, heap_ptr pos)
-{
+viewobjinfo(state_t *s, heap_ptr pos) {
char *signals[16] = {
"stop_update",
@@ -2995,7 +2911,7 @@ viewobjinfo(state_t *s, heap_ptr pos)
sciprintf("No priority.\n\n");
else
sciprintf("Priority = %d (band starts at %d)\n\n",
- priority, PRIORITY_BAND_FIRST(priority));
+ priority, PRIORITY_BAND_FIRST(priority));
if (have_rects) {
sciprintf("nsRect: [%d..%d]x[%d..%d]\n", nsLeft, nsRight, nsTop, nsBottom);
@@ -3007,11 +2923,11 @@ viewobjinfo(state_t *s, heap_ptr pos)
nsrect_clipped = get_nsrect(s, pos, 1);
brrect = set_base(s, pos);
sciprintf("new nsRect: [%d..%d]x[%d..%d]\n", nsrect.x, nsrect.xend,
- nsrect.y, nsrect.yend);
+ nsrect.y, nsrect.yend);
sciprintf("new clipped nsRect: [%d..%d]x[%d..%d]\n", nsrect_clipped.x,
- nsrect_clipped.xend, nsrect_clipped.y, nsrect_clipped.yend);
+ nsrect_clipped.xend, nsrect_clipped.y, nsrect_clipped.yend);
sciprintf("new brRect: [%d..%d]x[%d..%d]\n", brrect.x, brrect.xend,
- brrect.y, brrect.yend);
+ brrect.y, brrect.yend);
sciprintf("\n signals = %04x:\n", signal);
for (i = 0; i < 16; i++)
@@ -3023,8 +2939,7 @@ viewobjinfo(state_t *s, heap_ptr pos)
int
-objinfo(state_t *s, reg_t pos)
-{
+objinfo(state_t *s, reg_t pos) {
object_t *obj = obj_get(s, pos);
object_t *var_container = obj;
int i;
@@ -3045,7 +2960,7 @@ objinfo(state_t *s, reg_t pos)
sciprintf(" ");
if (i < var_container->variable_names_nr)
sciprintf("[%03x] %s = ", VM_OBJECT_GET_VARSELECTOR(var_container, i),
- selector_name(s, VM_OBJECT_GET_VARSELECTOR(var_container, i)));
+ selector_name(s, VM_OBJECT_GET_VARSELECTOR(var_container, i)));
else
sciprintf("p#%x = ", i);
@@ -3055,36 +2970,32 @@ objinfo(state_t *s, reg_t pos)
for (i = 0; i < obj->methods_nr; i++) {
reg_t fptr = VM_OBJECT_READ_FUNCTION(obj, i);
sciprintf(" [%03x] %s = "PREG"\n",
- VM_OBJECT_GET_FUNCSELECTOR(obj, i),
- selector_name(s, VM_OBJECT_GET_FUNCSELECTOR(obj, i)),
- PRINT_REG(fptr));
+ VM_OBJECT_GET_FUNCSELECTOR(obj, i),
+ selector_name(s, VM_OBJECT_GET_FUNCSELECTOR(obj, i)),
+ PRINT_REG(fptr));
}
- if (s->seg_manager.heap[pos.segment]->type==MEM_OBJ_SCRIPT)
+ if (s->seg_manager.heap[pos.segment]->type == MEM_OBJ_SCRIPT)
sciprintf("\nOwner script:\t%d\n", s->seg_manager.heap[pos.segment]->data.script.nr);
return 0;
}
int
-c_vo(state_t *s)
-{
+c_vo(state_t *s) {
return objinfo(s, cmd_params[0].reg);
}
int
-c_obj(state_t *s)
-{
+c_obj(state_t *s) {
return objinfo(s, *p_objp);
}
int
-c_accobj(state_t *s)
-{
+c_accobj(state_t *s) {
return objinfo(s, s->r_acc);
}
int
-c_shownode(state_t *s)
-{
+c_shownode(state_t *s) {
reg_t addr = cmd_params[0].reg;
return show_node(s, addr);
@@ -3093,92 +3004,83 @@ c_shownode(state_t *s)
/*** Breakpoint commands ***/
static breakpoint_t *
-bp_alloc(state_t *s)
-{
- breakpoint_t *bp;
+bp_alloc(state_t *s) {
+ breakpoint_t *bp;
- if (s->bp_list)
- {
- bp = s->bp_list;
- while (bp->next)
- bp = bp->next;
- bp->next = (breakpoint_t *) sci_malloc (sizeof (breakpoint_t));
- bp = bp->next;
- }
- else {
- s->bp_list = (breakpoint_t *) sci_malloc (sizeof (breakpoint_t));
- bp = s->bp_list;
- }
+ if (s->bp_list) {
+ bp = s->bp_list;
+ while (bp->next)
+ bp = bp->next;
+ bp->next = (breakpoint_t *) sci_malloc(sizeof(breakpoint_t));
+ bp = bp->next;
+ } else {
+ s->bp_list = (breakpoint_t *) sci_malloc(sizeof(breakpoint_t));
+ bp = s->bp_list;
+ }
- bp->next = NULL;
+ bp->next = NULL;
- return bp;
+ return bp;
}
int
-c_bpx(state_t *s)
-{
- breakpoint_t *bp;
+c_bpx(state_t *s) {
+ breakpoint_t *bp;
- /* Note: We can set a breakpoint on a method that has not been loaded yet.
- Thus, we can't check whether the command argument is a valid method name.
- A breakpoint set on an invalid method name will just never trigger. */
+ /* Note: We can set a breakpoint on a method that has not been loaded yet.
+ Thus, we can't check whether the command argument is a valid method name.
+ A breakpoint set on an invalid method name will just never trigger. */
- bp=bp_alloc (s);
+ bp = bp_alloc(s);
- bp->type = BREAK_SELECTOR;
- bp->data.name = (char*)sci_malloc (strlen (cmd_params [0].str)+1);
- strcpy (bp->data.name, cmd_params [0].str);
- s->have_bp |= BREAK_SELECTOR;
+ bp->type = BREAK_SELECTOR;
+ bp->data.name = (char*)sci_malloc(strlen(cmd_params [0].str) + 1);
+ strcpy(bp->data.name, cmd_params [0].str);
+ s->have_bp |= BREAK_SELECTOR;
- return 0;
+ return 0;
}
int
-c_bpe(state_t *s)
-{
- breakpoint_t *bp;
+c_bpe(state_t *s) {
+ breakpoint_t *bp;
- bp=bp_alloc (s);
+ bp = bp_alloc(s);
- bp->type = BREAK_EXPORT;
- bp->data.address = (cmd_params [0].val << 16 | cmd_params [1].val);
- s->have_bp |= BREAK_EXPORT;
+ bp->type = BREAK_EXPORT;
+ bp->data.address = (cmd_params [0].val << 16 | cmd_params [1].val);
+ s->have_bp |= BREAK_EXPORT;
- return 0;
+ return 0;
}
int
-c_bplist(state_t *s)
-{
- breakpoint_t *bp;
- int i = 0;
- long bpdata;
-
- bp = s->bp_list;
- while (bp)
- {
- sciprintf (" #%i: ", i);
- switch (bp->type)
- {
- case BREAK_SELECTOR:
- sciprintf ("Execute %s\n", bp->data.name);
- break;
- case BREAK_EXPORT:
- bpdata = bp->data.address;
- sciprintf ("Execute script %d, export %d\n", bpdata >> 16, bpdata & 0xFFFF);
- break;
- }
-
- bp = bp->next;
- i++;
- }
-
- return 0;
-}
-
-int c_bpdel(state_t *s)
-{
+c_bplist(state_t *s) {
+ breakpoint_t *bp;
+ int i = 0;
+ long bpdata;
+
+ bp = s->bp_list;
+ while (bp) {
+ sciprintf(" #%i: ", i);
+ switch (bp->type) {
+ case BREAK_SELECTOR:
+ sciprintf("Execute %s\n", bp->data.name);
+ break;
+ case BREAK_EXPORT:
+ bpdata = bp->data.address;
+ sciprintf("Execute script %d, export %d\n", bpdata >> 16, bpdata & 0xFFFF);
+ break;
+ }
+
+ bp = bp->next;
+ i++;
+ }
+
+ return 0;
+}
+
+int c_bpdel(state_t *s) {
breakpoint_t *bp, *bp_next, *bp_prev;
int i = 0, found = 0;
int type;
@@ -3186,23 +3088,21 @@ int c_bpdel(state_t *s)
/* Find breakpoint with given index */
bp_prev = NULL;
bp = s->bp_list;
- while (bp && i < cmd_params [0].val)
- {
- bp_prev = bp;
- bp = bp->next;
- i++;
- }
- if (!bp)
- {
- sciprintf ("Invalid breakpoint index %i\n", cmd_params [0].val);
- return 1;
- }
+ while (bp && i < cmd_params [0].val) {
+ bp_prev = bp;
+ bp = bp->next;
+ i++;
+ }
+ if (!bp) {
+ sciprintf("Invalid breakpoint index %i\n", cmd_params [0].val);
+ return 1;
+ }
/* Delete it */
bp_next = bp->next;
type = bp->type;
- if (type == BREAK_SELECTOR) sci_free (bp->data.name);
- free (bp);
+ if (type == BREAK_SELECTOR) sci_free(bp->data.name);
+ free(bp);
if (bp_prev)
bp_prev->next = bp_next;
else
@@ -3210,12 +3110,11 @@ int c_bpdel(state_t *s)
/* Check if there are more breakpoints of the same type. If not, clear
the respective bit in s->have_bp. */
- for (bp = s->bp_list; bp; bp=bp->next)
- if (bp->type == type)
- {
- found = 1;
- break;
- }
+ for (bp = s->bp_list; bp; bp = bp->next)
+ if (bp->type == type) {
+ found = 1;
+ break;
+ }
if (!found) s->have_bp &= ~type;
@@ -3223,8 +3122,7 @@ int c_bpdel(state_t *s)
}
int
-c_gnf(state_t *s)
-{
+c_gnf(state_t *s) {
if (!s) {
sciprintf("Not in debug state\n");
return 1;
@@ -3235,16 +3133,14 @@ c_gnf(state_t *s)
}
int
-c_se(state_t *s)
-{
- stop_on_event=1;
+c_se(state_t *s) {
+ stop_on_event = 1;
_debugstate_valid = script_debug_flag = script_error_flag = 0;
return 0;
}
int
-c_type(state_t *s)
-{
+c_type(state_t *s) {
int t = determine_reg_type(s, cmd_params[0].reg, 1);
int invalid = t & KSIG_INVALID;
@@ -3272,61 +3168,57 @@ c_type(state_t *s)
default:
sciprintf("Erroneous unknown type %02x(%d decimal)\n", t, t);
-
+
}
-
+
sciprintf("%s\n", invalid ? " (invalid)" : "");
return 0;
}
int
-c_statusbar(state_t *s)
-{
+c_statusbar(state_t *s) {
if (!s) {
sciprintf("Not in debug state\n");
return 1;
}
- s->titlebar_port->color=s->ega_colors[cmd_params[0].val];
- s->titlebar_port->bgcolor=s->ega_colors[cmd_params[1].val];
+ s->titlebar_port->color = s->ega_colors[cmd_params[0].val];
+ s->titlebar_port->bgcolor = s->ega_colors[cmd_params[1].val];
- s->status_bar_foreground=cmd_params[0].val;
- s->status_bar_background=cmd_params[1].val;
+ s->status_bar_foreground = cmd_params[0].val;
+ s->status_bar_background = cmd_params[1].val;
sciw_set_status_bar(s, s->titlebar_port, s->status_bar_text,
- s->status_bar_foreground,
- s->status_bar_background);
+ s->status_bar_foreground,
+ s->status_bar_background);
gfxop_update(s->gfx_state);
return 0;
}
int
-c_sci_version(state_t *s)
-{
+c_sci_version(state_t *s) {
if (!s) {
sciprintf("Not in debug state\n");
return 1;
}
sciprintf("Emulating SCI version %d.%03d.%03d\n",
- SCI_VERSION_MAJOR(s->version),
- SCI_VERSION_MINOR(s->version),
- SCI_VERSION_PATCHLEVEL(s->version));
+ SCI_VERSION_MAJOR(s->version),
+ SCI_VERSION_MINOR(s->version),
+ SCI_VERSION_PATCHLEVEL(s->version));
return 0;
}
int
-c_sleep(state_t *s)
-{
- sleep(cmd_params[0].val);
- return 0;
+c_sleep(state_t *s) {
+ sleep(cmd_params[0].val);
+ return 0;
}
static void
-_print_address(void * _, reg_t addr)
-{
+_print_address(void * _, reg_t addr) {
if (addr.segment)
sciprintf(" "PREG"\n", PRINT_REG(addr));
}
@@ -3339,8 +3231,7 @@ _print_address(void * _, reg_t addr)
}
static int
-c_gc_show_reachable(state_t *s)
-{
+c_gc_show_reachable(state_t *s) {
reg_t addr = cmd_params[0].reg;
GET_SEG_INTERFACE(addr.segment);
@@ -3353,8 +3244,7 @@ c_gc_show_reachable(state_t *s)
}
static int
-c_gc_show_freeable(state_t *s)
-{
+c_gc_show_freeable(state_t *s) {
reg_t addr = cmd_params[0].reg;
GET_SEG_INTERFACE(addr.segment);
@@ -3367,8 +3257,7 @@ c_gc_show_freeable(state_t *s)
}
static int
-c_gc_normalise(state_t *s)
-{
+c_gc_normalise(state_t *s) {
reg_t addr = cmd_params[0].reg;
GET_SEG_INTERFACE(addr.segment);
@@ -3382,38 +3271,34 @@ c_gc_normalise(state_t *s)
}
static int
-c_gc(state_t *s)
-{
+c_gc(state_t *s) {
run_gc(s);
return 0;
}
static void
-print_all_of_them(void *_1, reg_t reg, int _2)
-{
+print_all_of_them(void *_1, reg_t reg, int _2) {
sciprintf(" - "PREG"\n", PRINT_REG(reg));
}
static int
-c_gc_list_reachable(state_t *s)
-{
+c_gc_list_reachable(state_t *s) {
reg_t_hash_map_ptr use_map = find_all_used_references(s);
sciprintf("Reachable references (normalised):\n");
apply_to_reg_t_hash_map(use_map, NULL, print_all_of_them);
- free_reg_t_hash_map (use_map);
+ free_reg_t_hash_map(use_map);
return 0;
}
void
script_debug(state_t *s, reg_t *pc, stack_ptr_t *sp, stack_ptr_t *pp, reg_t *objp,
- int *restadjust,
- seg_id_t *segids, reg_t **variables,
- reg_t **variables_base, int *variables_nr,
- int bp)
-{
+ int *restadjust,
+ seg_id_t *segids, reg_t **variables,
+ reg_t **variables_base, int *variables_nr,
+ int bp) {
int have_windowed = s->gfx_state->driver->capabilities & GFX_CAPABILITY_WINDOWED;
static int last_step;
/* Do we support a separate console? */
@@ -3460,7 +3345,7 @@ script_debug(state_t *s, reg_t *pc, stack_ptr_t *sp, stack_ptr_t *pp, reg_t *obj
disassemble(s, *pc, 0, 1);
if (_debug_seeking == _DEBUG_SEEK_GLOBAL)
sciprintf("Global %d (0x%x) = "PREG"\n", _debug_seek_special,
- _debug_seek_special, PRINT_REG(s->script_000->locals_block->locals[_debug_seek_special]));
+ _debug_seek_special, PRINT_REG(s->script_000->locals_block->locals[_debug_seek_special]));
_debugstate_valid = old_debugstate;
@@ -3475,11 +3360,11 @@ script_debug(state_t *s, reg_t *pc, stack_ptr_t *sp, stack_ptr_t *pp, reg_t *obj
script_t *scr = &(memobj->data.script);
byte *code_buf = scr->buf;
int code_buf_size = scr->buf_size;
- int opcode = pc->offset >= code_buf_size? 0 : code_buf[pc->offset];
+ int opcode = pc->offset >= code_buf_size ? 0 : code_buf[pc->offset];
int op = opcode >> 1;
- int paramb1 = pc->offset + 1 >= code_buf_size? 0 : code_buf[pc->offset + 1];
- int paramf1 = (opcode & 1)? paramb1 :
- (pc->offset + 2 >= code_buf_size? 0 : getInt16(code_buf + pc->offset + 1));
+ int paramb1 = pc->offset + 1 >= code_buf_size ? 0 : code_buf[pc->offset + 1];
+ int paramf1 = (opcode & 1) ? paramb1 :
+ (pc->offset + 2 >= code_buf_size ? 0 : getInt16(code_buf + pc->offset + 1));
switch (_debug_seeking) {
@@ -3498,8 +3383,8 @@ script_debug(state_t *s, reg_t *pc, stack_ptr_t *sp, stack_ptr_t *pp, reg_t *obj
}
case _DEBUG_SEEK_SO:
- if (!REG_EQ(*pc,_debug_seek_reg) ||
- s->execution_stack_pos != _debug_seek_level)
+ if (!REG_EQ(*pc, _debug_seek_reg) ||
+ s->execution_stack_pos != _debug_seek_level)
return;
break;
@@ -3545,302 +3430,302 @@ script_debug(state_t *s, reg_t *pc, stack_ptr_t *sp, stack_ptr_t *pp, reg_t *obj
_debug_commands_not_hooked = 0;
- con_hook_command(c_sfx_remove, "sfx_remove", "!a",
- "Kills a playing sound.");
+ con_hook_command(c_sfx_remove, "sfx_remove", "!a",
+ "Kills a playing sound.");
con_hook_command(c_debuginfo, "registers", "", "Displays all current register values");
con_hook_command(c_vmvars, "vmvars", "!sia*", "Displays or changes variables in the VM\n\nFirst parameter is either g(lobal), l(ocal), t(emp) or p(aram).\nSecond parameter is the var number\nThird parameter (if specified) is the value to set the variable to");
con_hook_command(c_sci_version, "sci_version", "", "Prints the SCI version currently being emulated");
con_hook_command(c_vmvarlist, "vmvarlist", "!", "Displays the addresses of variables in the VM");
con_hook_command(c_step, "s", "i*", "Executes one or several operations\n\nEXAMPLES\n\n"
- " s 4\n\n Execute 4 commands\n\n s\n\n Execute next command");
+ " s 4\n\n Execute 4 commands\n\n s\n\n Execute next command");
#if 0
// TODO Re-implement con:so
con_hook_command(c_stepover, "so", "", "Executes one operation skipping over sends");
#endif
con_hook_command(c_disasm_addr, "disasm-addr", "!as*", "Disassembles one or more commands\n\n"
- "USAGE\n\n disasm-addr [startaddr] <options>\n\n"
- " Valid options are:\n"
- " bwt : Print byte/word tag\n"
- " c<x> : Disassemble <x> bytes\n"
- " bc : Print bytecode\n\n");
+ "USAGE\n\n disasm-addr [startaddr] <options>\n\n"
+ " Valid options are:\n"
+ " bwt : Print byte/word tag\n"
+ " c<x> : Disassemble <x> bytes\n"
+ " bc : Print bytecode\n\n");
con_hook_command(c_disasm, "disasm", "!as", "Disassembles a method by name\n\nUSAGE\n\n disasm <obj> <method>\n\n");
con_hook_command(c_obj, "obj", "!", "Displays information about the\n currently active object/class.\n"
- "\n\nSEE ALSO\n\n vo.1, accobj.1");
+ "\n\nSEE ALSO\n\n vo.1, accobj.1");
con_hook_command(c_accobj, "accobj", "!", "Displays information about an\n object or class at the\n"
- "address indexed by acc.\n\nSEE ALSO\n\n obj.1, vo.1");
+ "address indexed by acc.\n\nSEE ALSO\n\n obj.1, vo.1");
con_hook_command(c_classtable, "classtable", "", "Lists all available classes");
con_hook_command(c_stack, "stack", "i", "Dumps the specified number of stack elements");
con_hook_command(c_backtrace, "bt", "", "Dumps the send/self/super/call/calle/callb stack");
con_hook_command(c_snk, "snk", "s*", "Steps forward until it hits the next\n callk operation.\n"
- " If invoked with a parameter, it will\n look for that specific callk.\n");
+ " If invoked with a parameter, it will\n look for that specific callk.\n");
con_hook_command(c_se, "se", "", "Steps forward until an SCI event is received.\n");
con_hook_command(c_listclones, "clonetable", "", "Lists all registered clones");
con_hook_command(c_set_acc, "set_acc", "!a", "Sets the accumulator");
con_hook_command(c_send, "send", "!asa*", "Sends a message to an object\nExample: send ?fooScript cue");
con_hook_command(c_sret, "sret", "", "Steps forward until ret is called\n on the current execution"
- " stack\n level.");
+ " stack\n level.");
con_hook_command(c_resource_id, "resource_id", "i", "Identifies a resource number by\n"
- " splitting it up in resource type\n and resource number.");
+ " splitting it up in resource type\n and resource number.");
con_hook_command(c_clear_screen, "clear_screen", "", "Clears the screen, shows the\n background pic and picviews");
con_hook_command(c_redraw_screen, "redraw_screen", "", "Redraws the screen");
con_hook_command(c_debuglog, "debuglog", "!s*", "Sets the debug log modes.\n Possible parameters:\n"
- " +x (sets debugging for x)\n -x (unsets debugging for x)\n\nPossible values"
- " for x:\n u: Unimpl'd/stubbed stuff\n l: Lists and nodes\n g: Graphics\n"
- " c: Character handling\n m: Memory management\n f: Function call checks\n"
- " b: Bresenham details\n a: Audio\n d: System gfx management\n s: Base setter\n"
- " p: Parser\n M: The menu system\n S: Said specs\n F: File I/O\n t: GetTime\n"
- " e: 0.3.3 kernel emulation\n r: Room numbers\n P: Pathfinding\n"
- " *: Everything\n\n"
- " If invoked withour parameters,\n it will list all activated\n debug options.\n\n"
- "SEE ALSO\n"
- " gfx_debuglog.1, sfx_debuglog.1\n");
+ " +x (sets debugging for x)\n -x (unsets debugging for x)\n\nPossible values"
+ " for x:\n u: Unimpl'd/stubbed stuff\n l: Lists and nodes\n g: Graphics\n"
+ " c: Character handling\n m: Memory management\n f: Function call checks\n"
+ " b: Bresenham details\n a: Audio\n d: System gfx management\n s: Base setter\n"
+ " p: Parser\n M: The menu system\n S: Said specs\n F: File I/O\n t: GetTime\n"
+ " e: 0.3.3 kernel emulation\n r: Room numbers\n P: Pathfinding\n"
+ " *: Everything\n\n"
+ " If invoked withour parameters,\n it will list all activated\n debug options.\n\n"
+ "SEE ALSO\n"
+ " gfx_debuglog.1, sfx_debuglog.1\n");
con_hook_command(c_visible_map, "set_vismap", "i", "Sets the visible map.\n Default is 0 (visual).\n"
- " Other useful values are:\n 1: Priority\n 2: Control\n 3: Auxiliary\n");
+ " Other useful values are:\n 1: Priority\n 2: Control\n 3: Auxiliary\n");
con_hook_command(c_simkey, "simkey", "i", "Simulates a keypress with the\n specified scancode.\n");
con_hook_command(c_statusbar, "statusbar", "ii", "Sets the colors of the status bar. Also controllable from the script.\n");
con_hook_command(c_bpx, "bpx", "s", "Sets a breakpoint on the execution of\n the specified method.\n\n EXAMPLE:\n"
- " bpx ego::doit\n\n May also be used to set a breakpoint\n that applies whenever an object\n"
- " of a specific type is touched:\n bpx foo::\n");
+ " bpx ego::doit\n\n May also be used to set a breakpoint\n that applies whenever an object\n"
+ " of a specific type is touched:\n bpx foo::\n");
con_hook_command(c_bpe, "bpe", "ii", "Sets a breakpoint on the execution of specified"
- " exported function.\n");
+ " exported function.\n");
con_hook_command(c_bplist, "bplist", "", "Lists all breakpoints.\n");
con_hook_command(c_bpdel, "bpdel", "i", "Deletes a breakpoint with specified index.");
con_hook_command(c_go, "go", "", "Executes the script.\n");
con_hook_command(c_dumpnodes, "dumpnodes", "i", "shows the specified number of nodes\n"
- " from the parse node tree");
+ " from the parse node tree");
con_hook_command(c_save_game, "save_game", "s", "Saves the current game state to\n the hard disk");
con_hook_command(c_restore_game, "restore_game", "s", "Restores a saved game from the\n hard disk");
con_hook_command(c_restart_game, "restart", "s*", "Restarts the game.\n\nUSAGE\n\n restart [-r] [-p]"
- " [--play] [--replay]\n\n There are two ways to restart an SCI\n game:\n"
- " play (-p) calls the game object's play()\n method\n replay (-r) calls the replay() method");
+ " [--play] [--replay]\n\n There are two ways to restart an SCI\n game:\n"
+ " play (-p) calls the game object's play()\n method\n replay (-r) calls the replay() method");
con_hook_command(c_mousepos, "mousepos", "",
- "Reveal the location of a mouse click.\n\n");
+ "Reveal the location of a mouse click.\n\n");
con_hook_command(c_viewinfo, "viewinfo", "ii", "Displays the number of loops\n and cels of each loop"
- " for the\n specified view resource and palette.");
+ " for the\n specified view resource and palette.");
con_hook_command(c_list_sentence_fragments, "list_sentence_fragments", "", "Lists all sentence fragments (which\n"
- " are used to build Parse trees).");
+ " are used to build Parse trees).");
con_hook_command(c_parse, "parse", "s", "Parses a sequence of words and prints\n the resulting parse tree.\n"
- " The word sequence must be provided as a\n single string.");
+ " The word sequence must be provided as a\n single string.");
con_hook_command(c_gnf, "gnf", "", "Displays the Parse grammar\n in strict GNF");
con_hook_command(c_set_parse_nodes, "set_parse_nodes", "s*", "Sets the contents of all parse nodes.\n"
- " Input token must be separated by\n blanks.");
+ " Input token must be separated by\n blanks.");
con_hook_command(c_sfx_debuglog, "sfx_debuglog", "s*",
- "Sets or prints the sound subsystem debug\n"
- "settings\n\n"
- "USAGE\n\n"
- " sfx_debuglog {[+|-][p|u|x|b]+}*\n\n"
- " sfx_debuglog\n\n"
- " Prints current settings\n\n"
- " sfx_debuglog +X\n\n"
- " Activates all debug features listed in X\n\n"
- " sfx_debuglog -X\n\n"
- " Deactivates the debug features listed in X\n\n"
- " Debug features:\n"
- " s: Active song changes\n"
- " c: Song cues\n"
- "SEE ALSO\n"
- " debuglog.1, gfx_debuglog.1\n");
+ "Sets or prints the sound subsystem debug\n"
+ "settings\n\n"
+ "USAGE\n\n"
+ " sfx_debuglog {[+|-][p|u|x|b]+}*\n\n"
+ " sfx_debuglog\n\n"
+ " Prints current settings\n\n"
+ " sfx_debuglog +X\n\n"
+ " Activates all debug features listed in X\n\n"
+ " sfx_debuglog -X\n\n"
+ " Deactivates the debug features listed in X\n\n"
+ " Debug features:\n"
+ " s: Active song changes\n"
+ " c: Song cues\n"
+ "SEE ALSO\n"
+ " debuglog.1, gfx_debuglog.1\n");
con_hook_command(c_gfx_debuglog, "gfx_debuglog", "s*",
- "Sets or prints the gfx driver's debug\n"
- "settings\n\n"
- "USAGE\n\n"
- " gfx_debuglog {[+|-][p|u|x|b]+}*\n\n"
- " gfx_debuglog\n\n"
- " Prints current settings\n\n"
- " gfx_debuglog +X\n\n"
- " Activates all debug features listed in X\n\n"
- " gfx_debuglog -X\n\n"
- " Deactivates the debug features listed in X\n\n"
- " Debug features:\n"
- " p: Pointer\n"
- " u: Updates\n"
- " x: Pixmaps\n"
- " b: Basic features\n\n"
- "SEE ALSO\n"
- " debuglog.1, sfx_debuglog.1\n");
+ "Sets or prints the gfx driver's debug\n"
+ "settings\n\n"
+ "USAGE\n\n"
+ " gfx_debuglog {[+|-][p|u|x|b]+}*\n\n"
+ " gfx_debuglog\n\n"
+ " Prints current settings\n\n"
+ " gfx_debuglog +X\n\n"
+ " Activates all debug features listed in X\n\n"
+ " gfx_debuglog -X\n\n"
+ " Deactivates the debug features listed in X\n\n"
+ " Debug features:\n"
+ " p: Pointer\n"
+ " u: Updates\n"
+ " x: Pixmaps\n"
+ " b: Basic features\n\n"
+ "SEE ALSO\n"
+ " debuglog.1, sfx_debuglog.1\n");
#ifdef SCI_SIMPLE_SAID_CODE
con_hook_command(c_sim_parse, "simparse", "s*", "Simulates a parsed entity.\n\nUSAGE\n Call this"
- " function with a list of\n Said operators, words, and word group"
- "\n numbers to match Said() specs\n that look identical.\n"
- "\n Note that opening braces and\n everything behind them are\n"
- "\n removed from all non-operator\n parameter tokens.\n"
- "\n simparse without parameters\n removes the entity.\n");
+ " function with a list of\n Said operators, words, and word group"
+ "\n numbers to match Said() specs\n that look identical.\n"
+ "\n Note that opening braces and\n everything behind them are\n"
+ "\n removed from all non-operator\n parameter tokens.\n"
+ "\n simparse without parameters\n removes the entity.\n");
#endif /* SCI_SIMPLE_SAID_CODE */
#ifdef GFXW_DEBUG_WIDGETS
con_hook_command(c_gfx_print_widget, "gfx_print_widget", "i*", "If called with no parameters, it\n shows which widgets are active.\n"
- " With parameters, it lists the\n widget corresponding to the\n numerical index specified (for\n each parameter).");
+ " With parameters, it lists the\n widget corresponding to the\n numerical index specified (for\n each parameter).");
#endif
con_hook_command(c_gfx_flush_resources, "gfx_free_widgets", "", "Frees all dynamically allocated\n widgets (for memory profiling).\n");
con_hook_command(c_gfx_current_port, "gfx_current_port", "", "Determines the current port number");
con_hook_command(c_gfx_print_port, "gfx_print_port", "i*", "Displays all information about the\n specified port,"
- " or the current port\n if no port was specified.");
+ " or the current port\n if no port was specified.");
con_hook_command(c_gfx_print_visual, "gfx_print_visual", "", "Displays all information about the\n current widget state");
con_hook_command(c_gfx_print_dynviews, "gfx_print_dynviews", "", "Shows the dynview list");
con_hook_command(c_gfx_print_dropviews, "gfx_print_dropviews", "", "Shows the list of dropped\n dynviews");
con_hook_command(c_gfx_drawpic, "gfx_drawpic", "ii*", "Draws a pic resource\n\nUSAGE\n gfx_drawpic <nr> [<pal> [<fl>]]\n"
- " where <nr> is the number of the pic resource\n to draw\n <pal> is the optional default\n palette for the pic (0 is"
- "\n assumed if not specified)\n <fl> are any pic draw flags (default\n is 1)");
+ " where <nr> is the number of the pic resource\n to draw\n <pal> is the optional default\n palette for the pic (0 is"
+ "\n assumed if not specified)\n <fl> are any pic draw flags (default\n is 1)");
con_hook_command(c_dump_words, "dumpwords", "", "Lists all parser words");
con_hook_command(c_gfx_show_map, "gfx_show_map", "i", "Shows one of the screen maps\n Semantics of the int parameter:\n"
- " 0: visual map (back buffer)\n 1: priority map (back buf.)\n 2: control map (static buf.)");
+ " 0: visual map (back buffer)\n 1: priority map (back buf.)\n 2: control map (static buf.)");
con_hook_command(c_gfx_fill_screen, "gfx_fill_screen", "i", "Fills the screen with one\n of the EGA colors\n");
con_hook_command(c_gfx_draw_rect, "gfx_draw_rect", "iiiii", "Draws a rectangle to the screen\n with one of the EGA colors\n\nUSAGE\n\n"
- " gfx_draw_rect <x> <y> <xl> <yl> <color>");
+ " gfx_draw_rect <x> <y> <xl> <yl> <color>");
con_hook_command(c_gfx_propagate_rect,
- "gfx_propagate_rect",
- "iiiii",
- "Propagates a lower gfx buffer to a\n"
- " higher gfx buffer.\n\nUSAGE\n\n"
- " gfx_propagate_rect <x> <y> <xl> <yl> <buf>\n");
+ "gfx_propagate_rect",
+ "iiiii",
+ "Propagates a lower gfx buffer to a\n"
+ " higher gfx buffer.\n\nUSAGE\n\n"
+ " gfx_propagate_rect <x> <y> <xl> <yl> <buf>\n");
con_hook_command(c_gfx_update_zone, "gfx_update_zone", "iiii", "Propagates a rectangular area from\n the back buffer to the front buffer"
- "\n\nUSAGE\n\n"
- " gfx_update_zone <x> <y> <xl> <yl>");
+ "\n\nUSAGE\n\n"
+ " gfx_update_zone <x> <y> <xl> <yl>");
#if 0
// TODO: Re-enable con:draw_viewobj
con_hook_command(c_gfx_draw_viewobj, "draw_viewobj", "i", "Draws the nsRect and brRect of a\n dynview object.\n\n nsRect is green, brRect\n"
- " is blue.\n");
+ " is blue.\n");
#endif
con_hook_command(c_gfx_draw_cel, "gfx_draw_cel", "iiii", "Draws a single view\n cel to the center of the\n screen\n\n"
- "USAGE\n gfx_draw_cel <view> <loop> <cel> <palette>\n");
+ "USAGE\n gfx_draw_cel <view> <loop> <cel> <palette>\n");
con_hook_command(c_gfx_priority, "gfx_priority", "i*", "Prints information about priority\n bands\nUSAGE\n\n gfx_priority\n\n"
- " will print the min and max values\n for the priority bands\n\n gfx_priority <val>\n\n Print start of the priority\n"
- " band for the specified\n priority\n");
+ " will print the min and max values\n for the priority bands\n\n gfx_priority <val>\n\n Print start of the priority\n"
+ " band for the specified\n priority\n");
con_hook_command(c_segtable, "segtable", "!",
- "Gives a short listing of all segments\n\n"
- "SEE ALSO\n\n"
- " seginfo.1");
+ "Gives a short listing of all segments\n\n"
+ "SEE ALSO\n\n"
+ " seginfo.1");
con_hook_command(c_segkill, "segkill", "!i*",
- "Deletes the specified segment\n\n"
- "USAGE\n\n"
- " segkill <nr>\n");
+ "Deletes the specified segment\n\n"
+ "USAGE\n\n"
+ " segkill <nr>\n");
con_hook_command(c_seginfo, "seginfo", "!i*",
- "Explains the specified segment\n\n"
- "USAGE\n\n"
- " seginfo\n"
- " seginfo <nr>\n"
- " Either explains all active segments\n"
- " (no parameter) or the specified one.\n\n"
- "SEE ALSO\n\n"
- " segtable.1");
+ "Explains the specified segment\n\n"
+ "USAGE\n\n"
+ " seginfo\n"
+ " seginfo <nr>\n"
+ " Either explains all active segments\n"
+ " (no parameter) or the specified one.\n\n"
+ "SEE ALSO\n\n"
+ " segtable.1");
con_hook_command(c_vo, "vo", "!a",
- "Examines an object\n\n"
- "SEE ALSO\n\n"
- " addresses.3, type.1");
+ "Examines an object\n\n"
+ "SEE ALSO\n\n"
+ " addresses.3, type.1");
con_hook_command(c_vr, "vr", "!aa*",
- "Examines an arbitrary reference\n\n");
+ "Examines an arbitrary reference\n\n");
con_hook_command(c_sg, "sg", "!i",
- "Steps until the global variable with the\n"
- "specified index is modified.\n\nSEE ALSO\n\n"
- " s.1, snk.1, so.1, bpx.1");
+ "Steps until the global variable with the\n"
+ "specified index is modified.\n\nSEE ALSO\n\n"
+ " s.1, snk.1, so.1, bpx.1");
con_hook_command(c_songlib_print, "songlib_print", "",
- "");
+ "");
#ifdef HAVE_SYSV_IPC
con_hook_command(c_codebug, "codebug", "!s",
- "Starts codebugging mode\n\nUSAGE\n\n"
- " codebug path/to/old/freesci\n\n"
- " A different version of FreeSCI may be\n"
- " spawned as a child process; all commands\n"
- " send to this debugger will also be sent to\n"
- " to the child process.\n\nSEE ALSO\n\n codebugging.3");
+ "Starts codebugging mode\n\nUSAGE\n\n"
+ " codebug path/to/old/freesci\n\n"
+ " A different version of FreeSCI may be\n"
+ " spawned as a child process; all commands\n"
+ " send to this debugger will also be sent to\n"
+ " to the child process.\n\nSEE ALSO\n\n codebugging.3");
#endif
con_hook_command(c_type, "type", "!a",
- "Determines the type of a value\n\n"
- "SEE ALSO\n\n addresses.3, vo.1");
+ "Determines the type of a value\n\n"
+ "SEE ALSO\n\n addresses.3, vo.1");
con_hook_command(c_shownode, "shownode", "!a",
- "Prints information about a list node\n"
- " or list base.\n\n");
+ "Prints information about a list node\n"
+ " or list base.\n\n");
con_hook_command(c_is_sample, "is-sample", "i",
- "Tests whether a given sound resource\n"
- " is a PCM sample, and displays infor-\n"
- " mation on it if it is.\n\n");
+ "Tests whether a given sound resource\n"
+ " is a PCM sample, and displays infor-\n"
+ " mation on it if it is.\n\n");
con_hook_command(c_sfx_01_header, "sfx-01-header", "i",
- "Dumps the header of an SCI01 song\n\n"
- "SEE ALSO\n\n"
- " sfx-01-track.1\n\n");
+ "Dumps the header of an SCI01 song\n\n"
+ "SEE ALSO\n\n"
+ " sfx-01-track.1\n\n");
con_hook_command(c_sfx_01_track, "sfx-01-track", "ii",
- "Dumps a track from an SCI01 song\n\n"
- "USAGE\n\n"
- " sfx-01-track <song> <offset>\n\n"
- "SEE ALSO\n\n"
- " sfx-01-header.1\n\n");
- con_hook_command(c_sleep, "sleep", "i", "Suspends everything for the\n"
- " specified number of seconds");
+ "Dumps a track from an SCI01 song\n\n"
+ "USAGE\n\n"
+ " sfx-01-track <song> <offset>\n\n"
+ "SEE ALSO\n\n"
+ " sfx-01-header.1\n\n");
+ con_hook_command(c_sleep, "sleep", "i", "Suspends everything for the\n"
+ " specified number of seconds");
con_hook_command(c_gc_show_reachable, "gc-list-reachable", "!a",
- "Prints all addresses directly reachable from\n"
- " the memory object specified as parameter.\n\n"
- "SEE ALSO\n\n"
- " gc-list-freeable.1, gc-normalise.1, gc.1,\n"
- " gc-all-reachable.1");
+ "Prints all addresses directly reachable from\n"
+ " the memory object specified as parameter.\n\n"
+ "SEE ALSO\n\n"
+ " gc-list-freeable.1, gc-normalise.1, gc.1,\n"
+ " gc-all-reachable.1");
con_hook_command(c_gc_show_freeable, "gc-list-freeable", "!a",
- "Prints all addresses freeable in the segment\n"
- " associated with the address (offset is ignored).\n\n"
- "SEE ALSO\n\n"
- " gc-list-freeable.1, gc-normalise.1, gc.1,\n"
- " gc-all-reachable.1");
+ "Prints all addresses freeable in the segment\n"
+ " associated with the address (offset is ignored).\n\n"
+ "SEE ALSO\n\n"
+ " gc-list-freeable.1, gc-normalise.1, gc.1,\n"
+ " gc-all-reachable.1");
con_hook_command(c_gc_normalise, "gc-normalise", "!a",
- "Prints the \"normal\" address of a given address,\n"
- " i.e. the address we would free in order to free\n"
- " the object associated with the original address.\n\n"
- "SEE ALSO\n\n"
- " gc-list-freeable.1, gc-list-reachable.1, gc.1,\n"
- " gc-all-reachable.1");
+ "Prints the \"normal\" address of a given address,\n"
+ " i.e. the address we would free in order to free\n"
+ " the object associated with the original address.\n\n"
+ "SEE ALSO\n\n"
+ " gc-list-freeable.1, gc-list-reachable.1, gc.1,\n"
+ " gc-all-reachable.1");
con_hook_command(c_gc, "gc", "",
- "Performs garbage collection.\n\n"
- "SEE ALSO\n\n"
- " gc-list-freeable.1, gc-list-reachable.1,\n"
- " gc-all-reachable.1, gc-normalise.1");
+ "Performs garbage collection.\n\n"
+ "SEE ALSO\n\n"
+ " gc-list-freeable.1, gc-list-reachable.1,\n"
+ " gc-all-reachable.1, gc-normalise.1");
con_hook_command(c_gc_list_reachable, "gc-all-reachable", "",
- "Lists all reachable objects, normalised.\n\n"
- "SEE ALSO\n\n"
- " gc-list-freeable.1, gc-list-reachable.1,\n"
- " gc.1, gc-normalise.1");
+ "Lists all reachable objects, normalised.\n\n"
+ "SEE ALSO\n\n"
+ " gc-list-freeable.1, gc-list-reachable.1,\n"
+ " gc.1, gc-normalise.1");
con_hook_int(&script_debug_flag, "script_debug_flag", "Set != 0 to enable debugger\n");
con_hook_int(&script_checkloads_flag, "script_checkloads_flag", "Set != 0 to display information\n"
- " when scripts are loaded or unloaded");
+ " when scripts are loaded or unloaded");
con_hook_int(&script_abort_flag, "script_abort_flag", "Set != 0 to abort execution\n");
con_hook_int(&script_step_counter, "script_step_counter", "# of executed SCI operations\n");
con_hook_int(&sci_debug_flags, "debug_flags", "Debug flags:\n 0x0001: Log each command executed\n"
- " 0x0002: Break on warnings\n \0x0004: Print VM warnings\n");
+ " 0x0002: Break on warnings\n \0x0004: Print VM warnings\n");
con_hook_int(&_weak_validations, "weak_validations", "Set != 0 to turn some validation errors\n"
- " into warnings\n");
+ " into warnings\n");
con_hook_int(&script_gc_interval, "gc-interval", "Number of kernel calls in between gcs");
con_hook_int(&debug_sleeptime_factor, "sleep-factor", "Factor to multiply with wait times\n Set to 0 to speed up games");
con_hook_page("codebugging",
- "Co-debugging allows to run two (sufficiently\n"
- " recent) versions of FreeSCI concurrently,\n"
- " with one acting as a client of the other.\n"
- " Co-debugging can be started by calling\n"
- " 'codebug' (see codebug.1); note that the\n"
- " argument passed to it must be a version of\n"
- " FreeSCI that performs fflush(NULL) before\n"
- " each read; only late 0.3.3-devel and later\n"
- " have this property.\n\n"
- " In co-debug mode, all commands are sent to\n"
- " both programs, UNLESS one of the following\n"
- " prefixes is used:\n\n"
- " '.' : Only sends to the foreground version\n"
- " ':' : Only sends to tbe background version\n\n"
- " For example, when running 0.3.3 from within\n"
- " 0.6.0, \".version\" would determine the version\n"
- " as 0.6.0, and \"0.3.3\" would be returned for\n"
- " \":version\". Both versions would be print\n"
- " if only \"version\" was invoked, each result\n"
- " coming from a different process.\n\n"
- "COLORS\n\n"
- " Whenever possible, the background process will\n"
- " have its output marked by a non-default color\n"
- " (usually red).\n\n"
- "TROUBLESHOOTING\n\n"
- " If the background version appears to be silent,\n"
- " make sure it is calling fflush(NULL) before\n"
- " reading input.\n\n"
- "SEE ALSO\n\n"
- " codebug.1");
+ "Co-debugging allows to run two (sufficiently\n"
+ " recent) versions of FreeSCI concurrently,\n"
+ " with one acting as a client of the other.\n"
+ " Co-debugging can be started by calling\n"
+ " 'codebug' (see codebug.1); note that the\n"
+ " argument passed to it must be a version of\n"
+ " FreeSCI that performs fflush(NULL) before\n"
+ " each read; only late 0.3.3-devel and later\n"
+ " have this property.\n\n"
+ " In co-debug mode, all commands are sent to\n"
+ " both programs, UNLESS one of the following\n"
+ " prefixes is used:\n\n"
+ " '.' : Only sends to the foreground version\n"
+ " ':' : Only sends to tbe background version\n\n"
+ " For example, when running 0.3.3 from within\n"
+ " 0.6.0, \".version\" would determine the version\n"
+ " as 0.6.0, and \"0.3.3\" would be returned for\n"
+ " \":version\". Both versions would be print\n"
+ " if only \"version\" was invoked, each result\n"
+ " coming from a different process.\n\n"
+ "COLORS\n\n"
+ " Whenever possible, the background process will\n"
+ " have its output marked by a non-default color\n"
+ " (usually red).\n\n"
+ "TROUBLESHOOTING\n\n"
+ " If the background version appears to be silent,\n"
+ " make sure it is calling fflush(NULL) before\n"
+ " reading input.\n\n"
+ "SEE ALSO\n\n"
+ " codebug.1");
} /* If commands were not hooked up */
@@ -3877,21 +3762,21 @@ script_debug(state_t *s, reg_t *pc, stack_ptr_t *sp, stack_ptr_t *pp, reg_t *obj
/* Check if a specific destination has been given */
if (commandstring
- && (commandstring[0] == '.'
- || commandstring[0] == ':'))
+ && (commandstring[0] == '.'
+ || commandstring[0] == ':'))
skipfirst = 1;
#endif
#ifdef HAVE_SYSV_IPC
if (commandstring
- && commandstring[0] != '.') {
+ && commandstring[0] != '.') {
codebug_send_command(commandstring + skipfirst);
codebug_send_command("\n");
}
#endif
if (commandstring
- && commandstring[0] != ':')
- con_parse(s, commandstring + skipfirst);
+ && commandstring[0] != ':')
+ con_parse(s, commandstring + skipfirst);
sciprintf("\n");
/* Resume music playing */
diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp
index 78ad431a35..280dfbb104 100644
--- a/engines/sci/engine/seg_manager.cpp
+++ b/engines/sci/engine/seg_manager.cpp
@@ -1,5 +1,5 @@
/***************************************************************************
- seg_manager.c Copyright (C) 2002 Xiaojun Chen, Christoph Reichenbach
+ seg_manager.c Copyright (C) 2002 Xiaojun Chen, Christoph Reichenbach
This program may be modified and copied freely according to the terms of
@@ -46,14 +46,14 @@ mem_obj_t* mem_obj_allocate(seg_manager_t *self, seg_id_t segid, int hash_id, me
sciprintf( "%s, *d, no enough memory", __FILE__, __LINE__ ); \
return ret; \
}
-
+
#define INVALID_SCRIPT_ID -1
-
-void dbg_print( const char* msg, void *i ) {
+
+void dbg_print(const char* msg, void *i) {
#ifdef DEBUG_SEG_MANAGER
char buf[1000];
- sprintf( buf, "%s = [0x%x], dec:[%d]", msg, i, i);
- perror( buf );
+ sprintf(buf, "%s = [0x%x], dec:[%d]", msg, i, i);
+ perror(buf);
#endif
}
@@ -68,7 +68,7 @@ void
sm_script_initialise_locals(seg_manager_t *self, reg_t location);
static int
-_sm_deallocate (seg_manager_t* self, int seg, int recursive);
+_sm_deallocate(seg_manager_t* self, int seg, int recursive);
static hunk_t *
sm_alloc_hunk(seg_manager_t *self, reg_t *);
@@ -89,14 +89,13 @@ sm_check(seg_manager_t* self, int seg);
/*******************************/
static inline int
-find_free_id(seg_manager_t *self, int *id)
-{
+find_free_id(seg_manager_t *self, int *id) {
char was_added = 0;
int retval = 0;
while (!was_added) {
retval = int_hash_map_check_value(self->id_seg_map, self->reserved_id,
- 1, &was_added);
+ 1, &was_added);
*id = self->reserved_id--;
if (self->reserved_id < -1000000)
self->reserved_id = -10;
@@ -107,8 +106,7 @@ find_free_id(seg_manager_t *self, int *id)
}
static mem_obj_t *
-alloc_nonscript_segment(seg_manager_t *self, mem_obj_enum type, seg_id_t *segid)
-{ /* Allocates a non-script segment */
+alloc_nonscript_segment(seg_manager_t *self, mem_obj_enum type, seg_id_t *segid) { /* Allocates a non-script segment */
int id;
*segid = find_free_id(self, &id);
return mem_obj_allocate(self, *segid, id, type);
@@ -122,11 +120,11 @@ void sm_init(seg_manager_t* self, int sci1_1) {
self->id_seg_map = new_int_hash_map();
self->reserved_id = INVALID_SCRIPT_ID;
- int_hash_map_check_value (self->id_seg_map, self->reserved_id, 1, NULL); /* reserve 0 for seg_id */
+ int_hash_map_check_value(self->id_seg_map, self->reserved_id, 1, NULL); /* reserve 0 for seg_id */
self->reserved_id--; /* reserved_id runs in the reversed direction to make sure no one will use it. */
-
+
self->heap_size = DEFAULT_SCRIPTS;
- self->heap = (mem_obj_t**) sci_calloc(self->heap_size, sizeof(mem_obj_t *));
+ self->heap = (mem_obj_t**) sci_calloc(self->heap_size, sizeof(mem_obj_t *));
self->clones_seg_id = 0;
self->lists_seg_id = 0;
@@ -146,7 +144,7 @@ void sm_init(seg_manager_t* self, int sci1_1) {
}
/* destroy the object, free the memorys if allocated before */
-void sm_destroy (seg_manager_t* self) {
+void sm_destroy(seg_manager_t* self) {
int i;
/* free memory*/
for (i = 0; i < self->heap_size; i++) {
@@ -156,7 +154,7 @@ void sm_destroy (seg_manager_t* self) {
free_int_hash_map(self->id_seg_map);
- sci_free (self->heap);
+ sci_free(self->heap);
self->heap = NULL;
}
@@ -167,12 +165,12 @@ void sm_destroy (seg_manager_t* self) {
** 1 - allocated successfully
** seg_id - allocated segment id
*/
-mem_obj_t* sm_allocate_script (seg_manager_t* self, struct _state *s, int script_nr, int* seg_id) {
+mem_obj_t* sm_allocate_script(seg_manager_t* self, struct _state *s, int script_nr, int* seg_id) {
int seg;
char was_added;
mem_obj_t* mem;
- seg = int_hash_map_check_value (self->id_seg_map, script_nr, 1, &was_added);
+ seg = int_hash_map_check_value(self->id_seg_map, script_nr, 1, &was_added);
if (!was_added) {
*seg_id = seg;
return self->heap[*seg_id];
@@ -181,7 +179,7 @@ mem_obj_t* sm_allocate_script (seg_manager_t* self, struct _state *s, int script
/* allocate the mem_obj_t */
mem = mem_obj_allocate(self, seg, script_nr, MEM_OBJ_SCRIPT);
if (!mem) {
- sciprintf("%s, %d, Not enough memory, ", __FILE__, __LINE__ );
+ sciprintf("%s, %d, Not enough memory, ", __FILE__, __LINE__);
return NULL;
}
@@ -189,66 +187,58 @@ mem_obj_t* sm_allocate_script (seg_manager_t* self, struct _state *s, int script
return mem;
}
-static void sm_set_script_size(mem_obj_t *mem, struct _state *s, int script_nr)
-{
+static void sm_set_script_size(mem_obj_t *mem, struct _state *s, int script_nr) {
resource_t *script = scir_find_resource(s->resmgr, sci_script, script_nr, 0);
resource_t *heap = scir_find_resource(s->resmgr, sci_heap, script_nr, 0);
mem->data.script.script_size = script->size;
mem->data.script.heap_size = 0; /* Set later */
- if (!script || (s->version >= SCI_VERSION(1,001,000) && !heap))
- {
- sciprintf("%s: failed to load %s\n", __FUNCTION__,
- !script ? "script" : "heap");
+ if (!script || (s->version >= SCI_VERSION(1, 001, 000) && !heap)) {
+ sciprintf("%s: failed to load %s\n", __FUNCTION__,
+ !script ? "script" : "heap");
return;
}
if (s->version < SCI_VERSION_FTU_NEW_SCRIPT_HEADER) {
- mem->data.script.buf_size = script->size + getUInt16(script->data)*2;
+ mem->data.script.buf_size = script->size + getUInt16(script->data) * 2;
/* locals_size = getUInt16(script->data)*2; */
- }
- else if (s->version < SCI_VERSION(1,001,000)) {
+ } else if (s->version < SCI_VERSION(1, 001, 000)) {
mem->data.script.buf_size = script->size;
- }
- else
- {
+ } else {
mem->data.script.buf_size = script->size + heap->size;
mem->data.script.heap_size = heap->size;
-
+
/* Ensure that the start of the heap resource can be word-aligned. */
- if (script->size & 2)
- {
+ if (script->size & 2) {
mem->data.script.buf_size++;
mem->data.script.script_size++;
}
- if (mem->data.script.buf_size > 65535)
- {
+ if (mem->data.script.buf_size > 65535) {
sciprintf("Script and heap sizes combined exceed 64K.\n"
- "This means a fundamental design bug was made in FreeSCI\n"
- "regarding SCI1.1 games.\nPlease report this so it can be"
- "fixed in the next major version!\n");
+ "This means a fundamental design bug was made in FreeSCI\n"
+ "regarding SCI1.1 games.\nPlease report this so it can be"
+ "fixed in the next major version!\n");
return;
}
}
}
-int sm_initialise_script(mem_obj_t *mem, struct _state *s, int script_nr)
-{
+int sm_initialise_script(mem_obj_t *mem, struct _state *s, int script_nr) {
/* allocate the script.buf */
script_t *scr;
sm_set_script_size(mem, s, script_nr);
- mem->data.script.buf = (byte*) sci_malloc (mem->data.script.buf_size);
-
- dbg_print( "mem->data.script.buf ", mem->data.script.buf );
+ mem->data.script.buf = (byte*) sci_malloc(mem->data.script.buf_size);
+
+ dbg_print("mem->data.script.buf ", mem->data.script.buf);
if (!mem->data.script.buf) {
- sm_free_script ( mem );
- sciprintf("seg_manager.c: Not enough memory space for script size" );
+ sm_free_script(mem);
+ sciprintf("seg_manager.c: Not enough memory space for script size");
mem->data.script.buf_size = 0;
return 0;
}
-
+
/* Initialize objects */
scr = &(mem->data.script);
scr->objects = NULL;
@@ -268,8 +258,8 @@ int sm_initialise_script(mem_obj_t *mem, struct _state *s, int script_nr)
scr->obj_indices = new_int_hash_map();
- if (s->version >= SCI_VERSION(1,001,000))
- scr->heap_start = scr->buf + scr->script_size;
+ if (s->version >= SCI_VERSION(1, 001, 000))
+ scr->heap_start = scr->buf + scr->script_size;
else
scr->heap_start = scr->buf;
@@ -277,23 +267,22 @@ int sm_initialise_script(mem_obj_t *mem, struct _state *s, int script_nr)
}
int
-_sm_deallocate (seg_manager_t* self, int seg, int recursive)
-{
+_sm_deallocate(seg_manager_t* self, int seg, int recursive) {
mem_obj_t *mobj;
- VERIFY ( sm_check (self, seg), "invalid seg id" );
+ VERIFY(sm_check(self, seg), "invalid seg id");
mobj = self->heap[seg];
- int_hash_map_remove_value( self->id_seg_map, mobj->segmgr_id );
+ int_hash_map_remove_value(self->id_seg_map, mobj->segmgr_id);
switch (mobj->type) {
case MEM_OBJ_SCRIPT:
- sm_free_script ( mobj );
+ sm_free_script(mobj);
mobj->data.script.buf = NULL;
if (recursive && mobj->data.script.locals_segment)
_sm_deallocate(self, mobj->data.script.locals_segment,
- recursive);
+ recursive);
break;
case MEM_OBJ_LOCALS:
@@ -338,7 +327,7 @@ _sm_deallocate (seg_manager_t* self, int seg, int recursive)
break;
default:
fprintf(stderr, "Deallocating segment type %d not supported!\n",
- mobj->type);
+ mobj->type);
BREAKPOINT();
}
@@ -348,42 +337,38 @@ _sm_deallocate (seg_manager_t* self, int seg, int recursive)
return 1;
}
-int sm_script_marked_deleted(seg_manager_t* self, int script_nr)
-{
+int sm_script_marked_deleted(seg_manager_t* self, int script_nr) {
script_t *scr;
- int seg = sm_seg_get( self, script_nr );
- VERIFY ( sm_check (self, seg), "invalid seg id" );
-
+ int seg = sm_seg_get(self, script_nr);
+ VERIFY(sm_check(self, seg), "invalid seg id");
+
scr = &(self->heap[seg]->data.script);
return scr->marked_as_deleted;
}
-void sm_mark_script_deleted(seg_manager_t* self, int script_nr)
-{
+void sm_mark_script_deleted(seg_manager_t* self, int script_nr) {
script_t *scr;
- int seg = sm_seg_get( self, script_nr );
- VERIFY ( sm_check (self, seg), "invalid seg id" );
+ int seg = sm_seg_get(self, script_nr);
+ VERIFY(sm_check(self, seg), "invalid seg id");
scr = &(self->heap[seg]->data.script);
scr->marked_as_deleted = 1;
}
-void sm_unmark_script_deleted(seg_manager_t* self, int script_nr)
-{
+void sm_unmark_script_deleted(seg_manager_t* self, int script_nr) {
script_t *scr;
- int seg = sm_seg_get( self, script_nr );
- VERIFY ( sm_check (self, seg), "invalid seg id" );
+ int seg = sm_seg_get(self, script_nr);
+ VERIFY(sm_check(self, seg), "invalid seg id");
scr = &(self->heap[seg]->data.script);
scr->marked_as_deleted = 0;
}
int
-sm_script_is_marked_as_deleted(seg_manager_t* self, seg_id_t seg)
-{
+sm_script_is_marked_as_deleted(seg_manager_t* self, seg_id_t seg) {
script_t *scr;
- if (!sm_check (self, seg))
+ if (!sm_check(self, seg))
return 0;
if (self->heap[seg]->type != MEM_OBJ_SCRIPT)
@@ -394,19 +379,18 @@ sm_script_is_marked_as_deleted(seg_manager_t* self, seg_id_t seg)
}
-int sm_deallocate_script (seg_manager_t* self, int script_nr) {
- int seg = sm_seg_get( self, script_nr );
+int sm_deallocate_script(seg_manager_t* self, int script_nr) {
+ int seg = sm_seg_get(self, script_nr);
_sm_deallocate(self, seg, 1);
return 1;
}
mem_obj_t*
-mem_obj_allocate(seg_manager_t *self, seg_id_t segid, int hash_id, mem_obj_enum type)
-{
- mem_obj_t* mem = ( mem_obj_t* ) sci_calloc( sizeof (mem_obj_t), 1 );
- if( !mem ) {
- sciprintf( "seg_manager.c: invalid mem_obj " );
+mem_obj_allocate(seg_manager_t *self, seg_id_t segid, int hash_id, mem_obj_enum type) {
+ mem_obj_t* mem = (mem_obj_t*) sci_calloc(sizeof(mem_obj_t), 1);
+ if (!mem) {
+ sciprintf("seg_manager.c: invalid mem_obj ");
return NULL;
}
@@ -415,13 +399,13 @@ mem_obj_allocate(seg_manager_t *self, seg_id_t segid, int hash_id, mem_obj_enum
int oldhs = self->heap_size;
if (segid >= self->heap_size * 2) {
- sciprintf( "seg_manager.c: hash_map error or others??" );
+ sciprintf("seg_manager.c: hash_map error or others??");
return NULL;
}
self->heap_size *= 2;
- temp = sci_realloc ((void*)self->heap, self->heap_size * sizeof( mem_obj_t* ) );
+ temp = sci_realloc((void*)self->heap, self->heap_size * sizeof(mem_obj_t*));
if (!temp) {
- sciprintf("seg_manager.c: Not enough memory space for script size" );
+ sciprintf("seg_manager.c: Not enough memory space for script size");
return NULL;
}
self->heap = (mem_obj_t**) temp;
@@ -446,25 +430,24 @@ mem_obj_allocate(seg_manager_t *self, seg_id_t segid, int hash_id, mem_obj_enum
/* }; */
void
-sm_free_script ( mem_obj_t* mem )
-{
- if( !mem ) return;
- if( mem->data.script.buf ) {
- sci_free( mem->data.script.buf );
+sm_free_script(mem_obj_t* mem) {
+ if (!mem) return;
+ if (mem->data.script.buf) {
+ sci_free(mem->data.script.buf);
mem->data.script.buf = NULL;
mem->data.script.buf_size = 0;
}
- if( mem->data.script.objects ) {
+ if (mem->data.script.objects) {
int i;
- for( i = 0; i < mem->data.script.objects_nr; i++ ) {
+ for (i = 0; i < mem->data.script.objects_nr; i++) {
object_t* object = &mem->data.script.objects[i];
- if( object->variables ) {
- free( object->variables );
+ if (object->variables) {
+ free(object->variables);
object->variables = NULL;
object->variables_nr = 0;
}
}
- free( mem->data.script.objects );
+ free(mem->data.script.objects);
mem->data.script.objects = NULL;
mem->data.script.objects_nr = 0;
}
@@ -479,21 +462,21 @@ sm_free_script ( mem_obj_t* mem )
#if 0
// Unreferenced - removed
static void
-sm_mset (seg_manager_t* self, int offset, int c, size_t n, int id, int flag) {
+sm_mset(seg_manager_t* self, int offset, int c, size_t n, int id, int flag) {
mem_obj_t* mem_obj;
GET_SEGID();
mem_obj = self->heap[id];
switch (mem_obj->type) {
case MEM_OBJ_SCRIPT:
if (mem_obj->data.script.buf) {
- memset( mem_obj->data.script.buf + offset, c, n );
+ memset(mem_obj->data.script.buf + offset, c, n);
}
break;
case MEM_OBJ_CLONES:
- sciprintf( "memset for clones haven't been implemented\n" );
+ sciprintf("memset for clones haven't been implemented\n");
break;
default:
- sciprintf( "unknown mem obj type\n" );
+ sciprintf("unknown mem obj type\n");
break;
}
}
@@ -502,42 +485,42 @@ sm_mset (seg_manager_t* self, int offset, int c, size_t n, int id, int flag) {
#if 0
// Unreferenced - removed
static void
-sm_mcpy_in_in (seg_manager_t* self, int dst, const int src, size_t n, int id, int flag) {
+sm_mcpy_in_in(seg_manager_t* self, int dst, const int src, size_t n, int id, int flag) {
mem_obj_t* mem_obj;
GET_SEGID();
mem_obj = self->heap[id];
switch (mem_obj->type) {
case MEM_OBJ_SCRIPT:
if (mem_obj->data.script.buf) {
- memcpy ( mem_obj->data.script.buf + dst, mem_obj->data.script.buf + src, n );
+ memcpy(mem_obj->data.script.buf + dst, mem_obj->data.script.buf + src, n);
}
break;
case MEM_OBJ_CLONES:
- sciprintf( "memcpy for clones haven't been implemented\n" );
+ sciprintf("memcpy for clones haven't been implemented\n");
break;
default:
- sciprintf( "unknown mem obj type\n" );
+ sciprintf("unknown mem obj type\n");
break;
}
}
#endif
void
-sm_mcpy_in_out (seg_manager_t* self, int dst, const void* src, size_t n, int id, int flag) {
+sm_mcpy_in_out(seg_manager_t* self, int dst, const void* src, size_t n, int id, int flag) {
mem_obj_t* mem_obj;
GET_SEGID();
mem_obj = self->heap[id];
switch (mem_obj->type) {
case MEM_OBJ_SCRIPT:
if (mem_obj->data.script.buf) {
- memcpy ( mem_obj->data.script.buf + dst, src, n );
+ memcpy(mem_obj->data.script.buf + dst, src, n);
}
break;
case MEM_OBJ_CLONES:
- sciprintf( "memcpy for clones hasn't been implemented yet\n" );
+ sciprintf("memcpy for clones hasn't been implemented yet\n");
break;
default:
- sciprintf( "unknown mem obj type\n" );
+ sciprintf("unknown mem obj type\n");
break;
}
}
@@ -545,78 +528,76 @@ sm_mcpy_in_out (seg_manager_t* self, int dst, const void* src, size_t n, int id,
#if 0
// Unreferenced - removed
static void
-sm_mcpy_out_in (seg_manager_t* self, void* dst, const int src, size_t n, int id, int flag) {
+sm_mcpy_out_in(seg_manager_t* self, void* dst, const int src, size_t n, int id, int flag) {
mem_obj_t* mem_obj;
GET_SEGID();
mem_obj = self->heap[id];
switch (mem_obj->type) {
case MEM_OBJ_SCRIPT:
if (mem_obj->data.script.buf) {
- memcpy ( dst, mem_obj->data.script.buf + src, n );
+ memcpy(dst, mem_obj->data.script.buf + src, n);
}
break;
case MEM_OBJ_CLONES:
- sciprintf( "memcpy for clones hasn't been implemented yet\n" );
+ sciprintf("memcpy for clones hasn't been implemented yet\n");
break;
default:
- sciprintf( "unknown mem obj type\n" );
+ sciprintf("unknown mem obj type\n");
break;
}
}
#endif
gint16
-sm_get_heap (seg_manager_t* self, reg_t reg)
-{
+sm_get_heap(seg_manager_t* self, reg_t reg) {
mem_obj_t* mem_obj;
mem_obj_enum mem_type;
- VERIFY( sm_check (self, reg.segment), "Invalid seg id" );
+ VERIFY(sm_check(self, reg.segment), "Invalid seg id");
mem_obj = self->heap[reg.segment];
mem_type = mem_obj->type;
- switch( mem_type ) {
+ switch (mem_type) {
case MEM_OBJ_SCRIPT:
- VERIFY( reg.offset + 1 < (unsigned int)mem_obj->data.script.buf_size, "invalid offset\n" );
+ VERIFY(reg.offset + 1 < (unsigned int)mem_obj->data.script.buf_size, "invalid offset\n");
return (unsigned char)mem_obj->data.script.buf[reg.offset] |
- ( ((unsigned char)mem_obj->data.script.buf[reg.offset+1]) << 8 );
+ (((unsigned char)mem_obj->data.script.buf[reg.offset+1]) << 8);
case MEM_OBJ_CLONES:
- sciprintf( "memcpy for clones hasn't been implemented yet\n" );
+ sciprintf("memcpy for clones hasn't been implemented yet\n");
break;
default:
- sciprintf( "unknown mem obj type\n" );
+ sciprintf("unknown mem obj type\n");
break;
}
return 0; /* never get here */
}
-void sm_put_heap (seg_manager_t* self, reg_t reg, gint16 value ) {
+void sm_put_heap(seg_manager_t* self, reg_t reg, gint16 value) {
mem_obj_t* mem_obj;
mem_obj_enum mem_type;
- VERIFY( sm_check (self, reg.segment), "Invalid seg id" );
+ VERIFY(sm_check(self, reg.segment), "Invalid seg id");
mem_obj = self->heap[reg.segment];
mem_type = mem_obj->type;
- switch( mem_type ) {
+ switch (mem_type) {
case MEM_OBJ_SCRIPT:
- VERIFY( reg.offset + 1 < mem_obj->data.script.buf_size, "invalid offset" );
+ VERIFY(reg.offset + 1 < mem_obj->data.script.buf_size, "invalid offset");
mem_obj->data.script.buf[reg.offset] = value & 0xff;
mem_obj->data.script.buf[reg.offset + 1] = value >> 8;
break;
case MEM_OBJ_CLONES:
- sciprintf( "memcpy for clones haven't been implemented\n" );
+ sciprintf("memcpy for clones haven't been implemented\n");
break;
default:
- sciprintf( "unknown mem obj type\n" );
+ sciprintf("unknown mem obj type\n");
break;
}
}
/* return the seg if script_id is valid and in the map, else -1 */
-int sm_seg_get (seg_manager_t* self, int script_id)
-{
- return int_hash_map_check_value (self->id_seg_map, script_id, 0, NULL);
+int sm_seg_get(seg_manager_t* self, int script_id) {
+ return int_hash_map_check_value(self->id_seg_map, script_id, 0, NULL);
}
/* validate the seg
@@ -625,56 +606,55 @@ int sm_seg_get (seg_manager_t* self, int script_id)
** 1 - valid seg
*/
static int
-sm_check (seg_manager_t* self, int seg) {
- if ( seg < 0 || seg >= self->heap_size ) {
+sm_check(seg_manager_t* self, int seg) {
+ if (seg < 0 || seg >= self->heap_size) {
return 0;
}
if (!self->heap[seg]) {
- sciprintf("seg_manager.c: seg %x is removed from memory, but not removed from hash_map\n", seg );
+ sciprintf("seg_manager.c: seg %x is removed from memory, but not removed from hash_map\n", seg);
return 0;
}
return 1;
}
-int sm_script_is_loaded (seg_manager_t* self, int id, id_flag flag) {
+int sm_script_is_loaded(seg_manager_t* self, int id, id_flag flag) {
if (flag == SCRIPT_ID)
- id = sm_seg_get (self, id);
- return sm_check (self, id);
+ id = sm_seg_get(self, id);
+ return sm_check(self, id);
}
-void sm_increment_lockers (seg_manager_t* self, int id, id_flag flag) {
+void sm_increment_lockers(seg_manager_t* self, int id, id_flag flag) {
if (flag == SCRIPT_ID)
- id = sm_seg_get (self, id);
- VERIFY ( sm_check (self, id), "invalid seg id" );
+ id = sm_seg_get(self, id);
+ VERIFY(sm_check(self, id), "invalid seg id");
self->heap[id]->data.script.lockers++;
}
-void sm_decrement_lockers (seg_manager_t* self, int id, id_flag flag) {
+void sm_decrement_lockers(seg_manager_t* self, int id, id_flag flag) {
if (flag == SCRIPT_ID)
- id = sm_seg_get (self, id);
- VERIFY ( sm_check (self, id), "invalid seg id" );
+ id = sm_seg_get(self, id);
+ VERIFY(sm_check(self, id), "invalid seg id");
if (self->heap[id]->data.script.lockers > 0)
self->heap[id]->data.script.lockers--;
}
-int sm_get_lockers (seg_manager_t* self, int id, id_flag flag) {
+int sm_get_lockers(seg_manager_t* self, int id, id_flag flag) {
if (flag == SCRIPT_ID)
- id = sm_seg_get (self, id);
- VERIFY ( sm_check (self, id), "invalid seg id" );
+ id = sm_seg_get(self, id);
+ VERIFY(sm_check(self, id), "invalid seg id");
return self->heap[id]->data.script.lockers;
}
-void sm_set_lockers (seg_manager_t* self, int lockers, int id, id_flag flag) {
+void sm_set_lockers(seg_manager_t* self, int lockers, int id, id_flag flag) {
if (flag == SCRIPT_ID)
- id = sm_seg_get (self, id);
- VERIFY ( sm_check (self, id), "invalid seg id" );
+ id = sm_seg_get(self, id);
+ VERIFY(sm_check(self, id), "invalid seg id");
self->heap[id]->data.script.lockers = lockers;
}
void
-sm_set_export_table_offset (struct _seg_manager_t* self, int offset, int id, id_flag flag)
-{
+sm_set_export_table_offset(struct _seg_manager_t* self, int offset, int id, id_flag flag) {
script_t *scr = &(self->heap[id]->data.script);
GET_SEGID();
@@ -688,8 +668,7 @@ sm_set_export_table_offset (struct _seg_manager_t* self, int offset, int id, id_
}
int
-sm_hash_segment_data(struct _seg_manager_t* self, int id)
-{
+sm_hash_segment_data(struct _seg_manager_t* self, int id) {
int i, len, hash_code = 0x55555555;
char *buf;
@@ -705,16 +684,14 @@ sm_hash_segment_data(struct _seg_manager_t* self, int id)
}
void
-sm_set_export_width(struct _seg_manager_t* self, int flag)
-{
+sm_set_export_width(struct _seg_manager_t* self, int flag) {
self->exports_wide = flag;
}
#if 0
// Unreferenced - removed
static guint16 *
-sm_get_export_table_offset (struct _seg_manager_t* self, int id, int flag, int *max)
-{
+sm_get_export_table_offset(struct _seg_manager_t* self, int id, int flag, int *max) {
GET_SEGID();
if (max)
*max = self->heap[id]->data.script.exports_nr;
@@ -723,28 +700,26 @@ sm_get_export_table_offset (struct _seg_manager_t* self, int id, int flag, int *
#endif
void
-sm_set_synonyms_offset (struct _seg_manager_t* self, int offset, int id, id_flag flag) {
+sm_set_synonyms_offset(struct _seg_manager_t* self, int offset, int id, id_flag flag) {
GET_SEGID();
- self->heap[id]->data.script.synonyms =
- self->heap[id]->data.script.buf + offset;
+ self->heap[id]->data.script.synonyms =
+ self->heap[id]->data.script.buf + offset;
}
byte *
-sm_get_synonyms(seg_manager_t *self, int id, id_flag flag)
-{
+sm_get_synonyms(seg_manager_t *self, int id, id_flag flag) {
GET_SEGID();
return self->heap[id]->data.script.synonyms;
}
void
-sm_set_synonyms_nr (struct _seg_manager_t* self, int nr, int id, id_flag flag) {
+sm_set_synonyms_nr(struct _seg_manager_t* self, int nr, int id, id_flag flag) {
GET_SEGID();
self->heap[id]->data.script.synonyms_nr = nr;
}
int
-sm_get_synonyms_nr (struct _seg_manager_t* self, int id, id_flag flag)
-{
+sm_get_synonyms_nr(struct _seg_manager_t* self, int id, id_flag flag) {
GET_SEGID();
return self->heap[id]->data.script.synonyms_nr;
}
@@ -752,8 +727,7 @@ sm_get_synonyms_nr (struct _seg_manager_t* self, int id, id_flag flag)
#if 0
// Unreferenced - removed
static int
-sm_get_heappos (struct _seg_manager_t* self, int id, int flag)
-{
+sm_get_heappos(struct _seg_manager_t* self, int id, int flag) {
GET_SEGID();
return 0;
}
@@ -762,26 +736,25 @@ sm_get_heappos (struct _seg_manager_t* self, int id, int flag)
#if 0
// Unreferenced - removed
static void
-sm_set_variables (struct _seg_manager_t* self, reg_t reg, int obj_index, reg_t variable_reg, int variable_index ) {
+sm_set_variables(struct _seg_manager_t* self, reg_t reg, int obj_index, reg_t variable_reg, int variable_index) {
script_t* script;
- VERIFY ( sm_check (self, reg.segment), "invalid seg id" );
- VERIFY ( self->heap[reg.segment], "invalid mem" );
-
+ VERIFY(sm_check(self, reg.segment), "invalid seg id");
+ VERIFY(self->heap[reg.segment], "invalid mem");
+
script = &(self->heap[reg.segment]->data.script);
- VERIFY( obj_index < script->objects_nr, "Invalid obj_index" );
+ VERIFY(obj_index < script->objects_nr, "Invalid obj_index");
- VERIFY( variable_index >= 0
- && variable_index < script->objects[obj_index].variables_nr,
- "Attempt to write to invalid variable number" );
+ VERIFY(variable_index >= 0
+ && variable_index < script->objects[obj_index].variables_nr,
+ "Attempt to write to invalid variable number");
script->objects[obj_index].variables[variable_index] = variable_reg;
}
#endif
static inline int
-_relocate_block(seg_manager_t *self, reg_t *block, int block_location, int block_items, seg_id_t segment, int location)
-{
+_relocate_block(seg_manager_t *self, reg_t *block, int block_location, int block_items, seg_id_t segment, int location) {
int rel = location - block_location;
int index;
@@ -795,7 +768,7 @@ _relocate_block(seg_manager_t *self, reg_t *block, int block_location, int block
if (rel & 1) {
sciprintf("Error: Attempt to relocate odd variable #%d.5e (relative to %04x)\n",
- index, block_location);
+ index, block_location);
return 0;
}
block[index].segment = segment; /* Perform relocation */
@@ -806,42 +779,38 @@ _relocate_block(seg_manager_t *self, reg_t *block, int block_location, int block
}
static inline int
-_relocate_local(seg_manager_t *self, script_t *scr, seg_id_t segment, int location)
-{
+_relocate_local(seg_manager_t *self, script_t *scr, seg_id_t segment, int location) {
if (scr->locals_block)
return _relocate_block(self,
- scr->locals_block->locals, scr->locals_offset,
- scr->locals_block->nr,
- segment, location);
+ scr->locals_block->locals, scr->locals_offset,
+ scr->locals_block->nr,
+ segment, location);
else
return 0; /* No hands, no cookies */
}
static inline int
-_relocate_object(seg_manager_t *self, object_t *obj, seg_id_t segment, int location)
-{
- return _relocate_block(self,
- obj->variables, obj->pos.offset, obj->variables_nr,
- segment, location);
+_relocate_object(seg_manager_t *self, object_t *obj, seg_id_t segment, int location) {
+ return _relocate_block(self,
+ obj->variables, obj->pos.offset, obj->variables_nr,
+ segment, location);
}
void
-sm_script_add_code_block(seg_manager_t *self, reg_t location)
-{
+sm_script_add_code_block(seg_manager_t *self, reg_t location) {
mem_obj_t *mobj = self->heap[location.segment];
script_t *scr;
int index;
- VERIFY( !(location.segment >= self->heap_size || mobj->type != MEM_OBJ_SCRIPT),
- "Attempt to add a code block to non-script\n" );
+ VERIFY(!(location.segment >= self->heap_size || mobj->type != MEM_OBJ_SCRIPT),
+ "Attempt to add a code block to non-script\n");
scr = &(mobj->data.script);
- if (++scr->code_blocks_nr > scr->code_blocks_allocated)
- {
+ if (++scr->code_blocks_nr > scr->code_blocks_allocated) {
scr->code_blocks_allocated += DEFAULT_OBJECTS_INCREMENT;
scr->code = (code_block_t*)sci_realloc(scr->code, scr->code_blocks_allocated *
- sizeof(code_block_t));
+ sizeof(code_block_t));
}
index = scr->code_blocks_nr - 1;
@@ -850,26 +819,25 @@ sm_script_add_code_block(seg_manager_t *self, reg_t location)
}
void
-sm_script_relocate(seg_manager_t *self, reg_t block)
-{
+sm_script_relocate(seg_manager_t *self, reg_t block) {
mem_obj_t *mobj = self->heap[block.segment];
script_t *scr;
int count;
int i;
-
- VERIFY( !(block.segment >= self->heap_size || mobj->type != MEM_OBJ_SCRIPT),
- "Attempt relocate non-script\n" );
+
+ VERIFY(!(block.segment >= self->heap_size || mobj->type != MEM_OBJ_SCRIPT),
+ "Attempt relocate non-script\n");
scr = &(mobj->data.script);
- VERIFY( block.offset < scr->buf_size
- && getUInt16(scr->buf + block.offset)*2 + block.offset < scr->buf_size,
- "Relocation block outside of script\n" );
+ VERIFY(block.offset < scr->buf_size
+ && getUInt16(scr->buf + block.offset)*2 + block.offset < scr->buf_size,
+ "Relocation block outside of script\n");
count = getUInt16(scr->buf + block.offset);
for (i = 0; i <= count; i++) {
- int pos = getUInt16(scr->buf + block.offset + 2 + (i*2));
+ int pos = getUInt16(scr->buf + block.offset + 2 + (i * 2));
if (!pos) continue; /* FIXME: A hack pending investigation */
if (!_relocate_local(self, scr, block.segment, pos)) {
@@ -882,57 +850,56 @@ sm_script_relocate(seg_manager_t *self, reg_t block)
for (k = 0; !done && k < scr->code_blocks_nr; k++) {
if (pos >= scr->code[k].pos.offset &&
- pos < scr->code[k].pos.offset+scr->code[k].size)
+ pos < scr->code[k].pos.offset + scr->code[k].size)
done = 1;
}
if (!done) {
sciprintf("While processing relocation block "PREG":\n",
- PRINT_REG(block));
- sciprintf("Relocation failed for index %04x (%d/%d)\n", pos, i+1, count);
+ PRINT_REG(block));
+ sciprintf("Relocation failed for index %04x (%d/%d)\n", pos, i + 1, count);
if (scr->locals_block)
sciprintf("- locals: %d at %04x\n",
- scr->locals_block->nr,
- scr->locals_offset);
+ scr->locals_block->nr,
+ scr->locals_offset);
else
sciprintf("- No locals\n");
for (k = 0; k < scr->objects_nr; k++)
sciprintf("- obj#%d at %04x w/ %d vars\n",
- k,
- scr->objects[k].pos.offset,
- scr->objects[k].variables_nr);
+ k,
+ scr->objects[k].pos.offset,
+ scr->objects[k].variables_nr);
// SQ3 script 71 has broken relocation entries.
// Since this is mainstream, we can't break out as we used to do.
sciprintf("Trying to continue anyway...\n");
-// BREAKPOINT();
+// BREAKPOINT();
}
}
}
}
void
-sm_heap_relocate(seg_manager_t *self, state_t *s, reg_t block)
-{
+sm_heap_relocate(seg_manager_t *self, state_t *s, reg_t block) {
mem_obj_t *mobj = self->heap[block.segment];
script_t *scr;
int count;
int i;
-
- VERIFY( !(block.segment >= self->heap_size || mobj->type != MEM_OBJ_SCRIPT),
- "Attempt relocate non-script\n" );
+
+ VERIFY(!(block.segment >= self->heap_size || mobj->type != MEM_OBJ_SCRIPT),
+ "Attempt relocate non-script\n");
scr = &(mobj->data.script);
- VERIFY( block.offset < scr->heap_size
- && getUInt16(scr->heap_start + block.offset)*2 + block.offset < scr->buf_size,
- "Relocation block outside of script\n" );
+ VERIFY(block.offset < scr->heap_size
+ && getUInt16(scr->heap_start + block.offset)*2 + block.offset < scr->buf_size,
+ "Relocation block outside of script\n");
- if (scr->relocated) return;
+ if (scr->relocated) return;
scr->relocated = 1;
count = getUInt16(scr->heap_start + block.offset);
for (i = 0; i < count; i++) {
- int pos = getUInt16(scr->heap_start + block.offset + 2 + (i*2)) + scr->script_size;
+ int pos = getUInt16(scr->heap_start + block.offset + 2 + (i * 2)) + scr->script_size;
if (!_relocate_local(self, scr, block.segment, pos)) {
int k, done = 0;
@@ -944,19 +911,19 @@ sm_heap_relocate(seg_manager_t *self, state_t *s, reg_t block)
if (!done) {
sciprintf("While processing relocation block "PREG":\n",
- PRINT_REG(block));
- sciprintf("Relocation failed for index %04x (%d/%d)\n", pos, i+1, count);
+ PRINT_REG(block));
+ sciprintf("Relocation failed for index %04x (%d/%d)\n", pos, i + 1, count);
if (scr->locals_block)
sciprintf("- locals: %d at %04x\n",
- scr->locals_block->nr,
- scr->locals_offset);
+ scr->locals_block->nr,
+ scr->locals_offset);
else
sciprintf("- No locals\n");
for (k = 0; k < scr->objects_nr; k++)
sciprintf("- obj#%d at %04x w/ %d vars\n",
- k,
- scr->objects[k].pos.offset,
- scr->objects[k].variables_nr);
+ k,
+ scr->objects[k].pos.offset,
+ scr->objects[k].variables_nr);
sciprintf("Triggering breakpoint...\n");
BREAKPOINT();
}
@@ -970,8 +937,7 @@ reg_t
get_class_address(state_t *s, int classnr, int lock, reg_t caller);
static object_t *
-sm_script_obj_init0(seg_manager_t *self, state_t *s, reg_t obj_pos)
-{
+sm_script_obj_init0(seg_manager_t *self, state_t *s, reg_t obj_pos) {
mem_obj_t *mobj = self->heap[obj_pos.segment];
script_t *scr;
object_t *obj;
@@ -979,13 +945,13 @@ sm_script_obj_init0(seg_manager_t *self, state_t *s, reg_t obj_pos)
unsigned int base = obj_pos.offset - SCRIPT_OBJECT_MAGIC_OFFSET;
reg_t temp;
- VERIFY( !(obj_pos.segment >= self->heap_size || mobj->type != MEM_OBJ_SCRIPT),
- "Attempt to initialize object in non-script\n" );
+ VERIFY(!(obj_pos.segment >= self->heap_size || mobj->type != MEM_OBJ_SCRIPT),
+ "Attempt to initialize object in non-script\n");
scr = &(mobj->data.script);
- VERIFY( base < scr->buf_size,
- "Attempt to initialize object beyond end of script\n" );
+ VERIFY(base < scr->buf_size,
+ "Attempt to initialize object beyond end of script\n");
if (!scr->objects) {
scr->objects_allocated = DEFAULT_OBJECTS;
@@ -994,9 +960,9 @@ sm_script_obj_init0(seg_manager_t *self, state_t *s, reg_t obj_pos)
if (scr->objects_nr == scr->objects_allocated) {
scr->objects_allocated += DEFAULT_OBJECTS_INCREMENT;
scr->objects = (object_t*)sci_realloc(scr->objects,
- sizeof(object_t)
- * scr->objects_allocated);
-
+ sizeof(object_t)
+ * scr->objects_allocated);
+
}
temp = make_reg(obj_pos.segment, base);
@@ -1005,12 +971,12 @@ sm_script_obj_init0(seg_manager_t *self, state_t *s, reg_t obj_pos)
obj = scr->objects + id;
- VERIFY( base + SCRIPT_FUNCTAREAPTR_OFFSET < scr->buf_size,
- "Function area pointer stored beyond end of script\n" );
-
+ VERIFY(base + SCRIPT_FUNCTAREAPTR_OFFSET < scr->buf_size,
+ "Function area pointer stored beyond end of script\n");
+
{
- byte *data = (byte *) (scr->buf + base);
- int funct_area = getUInt16( data + SCRIPT_FUNCTAREAPTR_OFFSET );
+ byte *data = (byte *)(scr->buf + base);
+ int funct_area = getUInt16(data + SCRIPT_FUNCTAREAPTR_OFFSET);
int variables_nr;
int functions_nr;
int is_class;
@@ -1019,17 +985,17 @@ sm_script_obj_init0(seg_manager_t *self, state_t *s, reg_t obj_pos)
obj->flags = 0;
obj->pos = temp;
- VERIFY ( base + funct_area < scr->buf_size,
- "Function area pointer references beyond end of script" );
+ VERIFY(base + funct_area < scr->buf_size,
+ "Function area pointer references beyond end of script");
- variables_nr = getUInt16( data + SCRIPT_SELECTORCTR_OFFSET );
- functions_nr = getUInt16( data + funct_area - 2 );
- is_class = getUInt16( data + SCRIPT_INFO_OFFSET ) & SCRIPT_INFO_CLASS;
+ variables_nr = getUInt16(data + SCRIPT_SELECTORCTR_OFFSET);
+ functions_nr = getUInt16(data + funct_area - 2);
+ is_class = getUInt16(data + SCRIPT_INFO_OFFSET) & SCRIPT_INFO_CLASS;
- VERIFY ( base + funct_area + functions_nr * 2
- /* add again for classes, since those also store selectors */
- + (is_class? functions_nr * 2 : 0) < scr->buf_size,
- "Function area extends beyond end of script" );
+ VERIFY(base + funct_area + functions_nr * 2
+ /* add again for classes, since those also store selectors */
+ + (is_class ? functions_nr * 2 : 0) < scr->buf_size,
+ "Function area extends beyond end of script");
obj->variables_nr = variables_nr;
obj->variables = (reg_t*)sci_malloc(sizeof(reg_t) * variables_nr);
@@ -1037,32 +1003,31 @@ sm_script_obj_init0(seg_manager_t *self, state_t *s, reg_t obj_pos)
obj->methods_nr = functions_nr;
obj->base = scr->buf;
obj->base_obj = data;
- obj->base_method = (guint16 *) (data + funct_area);
+ obj->base_method = (guint16 *)(data + funct_area);
obj->base_vars = NULL;
for (i = 0; i < variables_nr; i++)
- obj->variables[i] = make_reg(0, getUInt16(data + (i*2)));
+ obj->variables[i] = make_reg(0, getUInt16(data + (i * 2)));
}
return obj;
}
static object_t *
-sm_script_obj_init11(seg_manager_t *self, state_t *s, reg_t obj_pos)
-{
+sm_script_obj_init11(seg_manager_t *self, state_t *s, reg_t obj_pos) {
mem_obj_t *mobj = self->heap[obj_pos.segment];
script_t *scr;
object_t *obj;
int id;
int base = obj_pos.offset;
- VERIFY( !(obj_pos.segment >= self->heap_size || mobj->type != MEM_OBJ_SCRIPT),
- "Attempt to initialize object in non-script\n" );
+ VERIFY(!(obj_pos.segment >= self->heap_size || mobj->type != MEM_OBJ_SCRIPT),
+ "Attempt to initialize object in non-script\n");
scr = &(mobj->data.script);
- VERIFY( base < scr->buf_size,
- "Attempt to initialize object beyond end of script\n" );
+ VERIFY(base < scr->buf_size,
+ "Attempt to initialize object beyond end of script\n");
if (!scr->objects) {
scr->objects_allocated = DEFAULT_OBJECTS;
@@ -1071,9 +1036,9 @@ sm_script_obj_init11(seg_manager_t *self, state_t *s, reg_t obj_pos)
if (scr->objects_nr == scr->objects_allocated) {
scr->objects_allocated += DEFAULT_OBJECTS_INCREMENT;
scr->objects = (object_t*)sci_realloc(scr->objects,
- sizeof(object_t)
- * scr->objects_allocated);
-
+ sizeof(object_t)
+ * scr->objects_allocated);
+
}
id = int_hash_map_check_value(scr->obj_indices, obj_pos.offset, 1, NULL);
@@ -1081,33 +1046,33 @@ sm_script_obj_init11(seg_manager_t *self, state_t *s, reg_t obj_pos)
obj = scr->objects + id;
- VERIFY( base + SCRIPT_FUNCTAREAPTR_OFFSET < scr->buf_size,
- "Function area pointer stored beyond end of script\n" );
-
+ VERIFY(base + SCRIPT_FUNCTAREAPTR_OFFSET < scr->buf_size,
+ "Function area pointer stored beyond end of script\n");
+
{
- byte *data = (byte *) (scr->buf + base);
- guint16 *funct_area = (guint16 *) (scr->buf + getUInt16( data + 6 ));
- guint16 *prop_area = (guint16 *) (scr->buf + getUInt16( data + 4 ));
+ byte *data = (byte *)(scr->buf + base);
+ guint16 *funct_area = (guint16 *)(scr->buf + getUInt16(data + 6));
+ guint16 *prop_area = (guint16 *)(scr->buf + getUInt16(data + 4));
int variables_nr;
int functions_nr;
int is_class;
int i;
-
+
obj->flags = 0;
obj->pos = obj_pos;
- VERIFY ( (byte *) funct_area < scr->buf + scr->buf_size,
- "Function area pointer references beyond end of script" );
+ VERIFY((byte *) funct_area < scr->buf + scr->buf_size,
+ "Function area pointer references beyond end of script");
variables_nr = getUInt16(data + 2);
functions_nr = *funct_area;
- is_class = getUInt16( data + 14 ) & SCRIPT_INFO_CLASS;
+ is_class = getUInt16(data + 14) & SCRIPT_INFO_CLASS;
obj->base_method = funct_area;
obj->base_vars = prop_area;
- VERIFY ( ((byte *) funct_area + functions_nr) < scr->buf + scr->buf_size,
- "Function area extends beyond end of script" );
+ VERIFY(((byte *) funct_area + functions_nr) < scr->buf + scr->buf_size,
+ "Function area extends beyond end of script");
obj->variables_nr = variables_nr;
obj->variable_names_nr = variables_nr;
@@ -1118,24 +1083,22 @@ sm_script_obj_init11(seg_manager_t *self, state_t *s, reg_t obj_pos)
obj->base_obj = data;
for (i = 0; i < variables_nr; i++)
- obj->variables[i] = make_reg(0, getUInt16(data + (i*2)));
+ obj->variables[i] = make_reg(0, getUInt16(data + (i * 2)));
}
return obj;
}
object_t *
-sm_script_obj_init(seg_manager_t *self, state_t *s, reg_t obj_pos)
-{
- if (!self->sci1_1)
+sm_script_obj_init(seg_manager_t *self, state_t *s, reg_t obj_pos) {
+ if (!self->sci1_1)
return sm_script_obj_init0(self, s, obj_pos);
else
return sm_script_obj_init11(self, s, obj_pos);
}
static local_variables_t *
-_sm_alloc_locals_segment(seg_manager_t *self, script_t *scr, int count)
-{
+_sm_alloc_locals_segment(seg_manager_t *self, script_t *scr, int count) {
if (!count) { /* No locals */
scr->locals_segment = 0;
scr->locals_block = NULL;
@@ -1151,7 +1114,7 @@ _sm_alloc_locals_segment(seg_manager_t *self, script_t *scr, int count)
VERIFY(mobj->data.locals.script_id == scr->nr, "Re-used locals segment belonged to other script");
} else
mobj = alloc_nonscript_segment(self, MEM_OBJ_LOCALS,
- &scr->locals_segment);
+ &scr->locals_segment);
locals = scr->locals_block = &(mobj->data.locals);
locals->script_id = scr->nr;
@@ -1163,13 +1126,12 @@ _sm_alloc_locals_segment(seg_manager_t *self, script_t *scr, int count)
}
void
-sm_script_initialise_locals_zero(seg_manager_t *self, seg_id_t seg, int count)
-{
+sm_script_initialise_locals_zero(seg_manager_t *self, seg_id_t seg, int count) {
mem_obj_t *mobj = self->heap[seg];
script_t *scr;
- VERIFY( !(seg >= self->heap_size || mobj->type != MEM_OBJ_SCRIPT),
- "Attempt to initialize locals in non-script\n" );
+ VERIFY(!(seg >= self->heap_size || mobj->type != MEM_OBJ_SCRIPT),
+ "Attempt to initialize locals in non-script\n");
scr = &(mobj->data.script);
@@ -1179,20 +1141,19 @@ sm_script_initialise_locals_zero(seg_manager_t *self, seg_id_t seg, int count)
}
void
-sm_script_initialise_locals(seg_manager_t *self, reg_t location)
-{
+sm_script_initialise_locals(seg_manager_t *self, reg_t location) {
mem_obj_t *mobj = self->heap[location.segment];
unsigned int count;
script_t *scr;
local_variables_t *locals;
- VERIFY( !(location.segment >= self->heap_size || mobj->type != MEM_OBJ_SCRIPT),
- "Attempt to initialize locals in non-script\n" );
+ VERIFY(!(location.segment >= self->heap_size || mobj->type != MEM_OBJ_SCRIPT),
+ "Attempt to initialize locals in non-script\n");
scr = &(mobj->data.script);
- VERIFY( location.offset + 1 < scr->buf_size,
- "Locals beyond end of script\n" );
+ VERIFY(location.offset + 1 < scr->buf_size,
+ "Locals beyond end of script\n");
if (self->sci1_1)
count = getUInt16(scr->buf + location.offset - 2);
@@ -1204,43 +1165,39 @@ sm_script_initialise_locals(seg_manager_t *self, reg_t location)
if (!(location.offset + count * 2 + 1 < scr->buf_size)) {
sciprintf("Locals extend beyond end of script: offset %04x, count %x vs size %x\n",
- location.offset, count, scr->buf_size);
+ location.offset, count, scr->buf_size);
count = (scr->buf_size - location.offset) >> 1;
}
locals = _sm_alloc_locals_segment(self, scr, count);
if (locals) {
int i;
- byte *base = (byte *) (scr->buf + location.offset);
+ byte *base = (byte *)(scr->buf + location.offset);
for (i = 0; i < count; i++)
- locals->locals[i].offset = getUInt16(base + i*2);
+ locals->locals[i].offset = getUInt16(base + i * 2);
}
}
void
-sm_script_relocate_exports_sci11(seg_manager_t *self, int seg)
-{
+sm_script_relocate_exports_sci11(seg_manager_t *self, int seg) {
mem_obj_t *mobj = self->heap[seg];
script_t *scr;
int i;
int location;
- VERIFY( !(seg >= self->heap_size || mobj->type != MEM_OBJ_SCRIPT),
- "Attempt to relocate exports in non-script\n" );
+ VERIFY(!(seg >= self->heap_size || mobj->type != MEM_OBJ_SCRIPT),
+ "Attempt to relocate exports in non-script\n");
scr = &(mobj->data.script);
- for (i = 0; i < scr->exports_nr; i++)
- {
+ for (i = 0; i < scr->exports_nr; i++) {
/* We are forced to use an ugly heuristic here to distinguish function
exports from object/class exports. The former kind points into the
script resource, the latter into the heap resource. */
location = getUInt16((byte *)(scr->export_table + i));
- if (getUInt16(scr->heap_start + location) == SCRIPT_OBJECT_MAGIC_NUMBER)
- {
- putInt16((byte *)(scr->export_table + i), location+scr->heap_start-scr->buf);
- } else
- {
+ if (getUInt16(scr->heap_start + location) == SCRIPT_OBJECT_MAGIC_NUMBER) {
+ putInt16((byte *)(scr->export_table + i), location + scr->heap_start - scr->buf);
+ } else {
/* Otherwise it's probably a function export,
and we don't need to do anything. */
}
@@ -1249,31 +1206,28 @@ sm_script_relocate_exports_sci11(seg_manager_t *self, int seg)
}
void
-sm_script_initialise_objects_sci11(seg_manager_t *self, state_t *s, int seg)
-{
+sm_script_initialise_objects_sci11(seg_manager_t *self, state_t *s, int seg) {
mem_obj_t *mobj = self->heap[seg];
script_t *scr;
byte *seeker;
- VERIFY( !(seg >= self->heap_size || mobj->type != MEM_OBJ_SCRIPT),
- "Attempt to relocate exports in non-script\n" );
+ VERIFY(!(seg >= self->heap_size || mobj->type != MEM_OBJ_SCRIPT),
+ "Attempt to relocate exports in non-script\n");
scr = &(mobj->data.script);
seeker = scr->heap_start + 4 + getUInt16(scr->heap_start + 2) * 2;
- while (getUInt16(seeker) == SCRIPT_OBJECT_MAGIC_NUMBER)
- {
+ while (getUInt16(seeker) == SCRIPT_OBJECT_MAGIC_NUMBER) {
- if (getUInt16(seeker + 14) & SCRIPT_INFO_CLASS)
- {
- int classpos = seeker-scr->buf;
+ if (getUInt16(seeker + 14) & SCRIPT_INFO_CLASS) {
+ int classpos = seeker - scr->buf;
int species = getUInt16(seeker + 10);
if (species < 0 || species >= s->classtable_size) {
sciprintf("Invalid species %d(0x%x) not in interval "
- "[0,%d) while instantiating script %d\n",
- species, species, s->classtable_size,
- scr->nr);
+ "[0,%d) while instantiating script %d\n",
+ species, species, s->classtable_size,
+ scr->nr);
script_debug_flag = script_error_flag = 1;
return;
}
@@ -1286,20 +1240,18 @@ sm_script_initialise_objects_sci11(seg_manager_t *self, state_t *s, int seg)
}
seeker = scr->heap_start + 4 + getUInt16(scr->heap_start + 2) * 2;
- while (getUInt16(seeker) == SCRIPT_OBJECT_MAGIC_NUMBER)
- {
+ while (getUInt16(seeker) == SCRIPT_OBJECT_MAGIC_NUMBER) {
reg_t reg;
object_t *obj;
reg.segment = seg;
- reg.offset = seeker-scr->buf;
+ reg.offset = seeker - scr->buf;
obj = sm_script_obj_init(&s->seg_manager, s, reg);
#if 0
- if (obj->variables[5].offset != 0xffff)
- {
+ if (obj->variables[5].offset != 0xffff) {
obj->variables[5] =
- INST_LOOKUP_CLASS(obj->variables[5].offset);
+ INST_LOOKUP_CLASS(obj->variables[5].offset);
base_obj = obj_get(s, obj->variables[5]);
@@ -1308,29 +1260,28 @@ sm_script_initialise_objects_sci11(seg_manager_t *self, state_t *s, int seg)
}
#endif
- /* Copy base from species class, as we need its selector IDs */
+ /* Copy base from species class, as we need its selector IDs */
obj->variables[6] =
- INST_LOOKUP_CLASS(obj->variables[6].offset);
-
+ INST_LOOKUP_CLASS(obj->variables[6].offset);
+
seeker += getUInt16(seeker + 2) * 2;
}
}
void
-sm_script_free_unused_objects(seg_manager_t *self, seg_id_t seg)
-{
+sm_script_free_unused_objects(seg_manager_t *self, seg_id_t seg) {
mem_obj_t *mobj = self->heap[seg];
script_t *scr;
- VERIFY( !(seg >= self->heap_size || mobj->type != MEM_OBJ_SCRIPT),
- "Attempt to free unused objects in non-script\n" );
+ VERIFY(!(seg >= self->heap_size || mobj->type != MEM_OBJ_SCRIPT),
+ "Attempt to free unused objects in non-script\n");
scr = &(mobj->data.script);
if (scr->objects_allocated > scr->objects_nr) {
if (scr->objects_nr)
scr->objects = (object_t*)sci_realloc(scr->objects, sizeof(object_t)
- * scr->objects_nr);
+ * scr->objects_nr);
else {
if (scr->objects_allocated)
sci_free(scr->objects);
@@ -1340,8 +1291,7 @@ sm_script_free_unused_objects(seg_manager_t *self, seg_id_t seg)
}
}
-static inline char *dynprintf(char *msg, ...)
-{
+static inline char *dynprintf(char *msg, ...) {
va_list argp;
char *buf = (char*)sci_malloc(strlen(msg) + 100);
@@ -1354,8 +1304,7 @@ static inline char *dynprintf(char *msg, ...)
dstack_t *
-sm_allocate_stack(seg_manager_t *self, int size, seg_id_t *segid)
-{
+sm_allocate_stack(seg_manager_t *self, int size, seg_id_t *segid) {
mem_obj_t *memobj = alloc_nonscript_segment(self, MEM_OBJ_STACK, segid);
dstack_t *retval = &(memobj->data.stack);
@@ -1366,8 +1315,7 @@ sm_allocate_stack(seg_manager_t *self, int size, seg_id_t *segid)
}
sys_strings_t *
-sm_allocate_sys_strings(seg_manager_t *self, seg_id_t *segid)
-{
+sm_allocate_sys_strings(seg_manager_t *self, seg_id_t *segid) {
mem_obj_t *memobj = alloc_nonscript_segment(self, MEM_OBJ_SYS_STRINGS, segid);
sys_strings_t *retval = &(memobj->data.sys_strings);
@@ -1377,8 +1325,7 @@ sm_allocate_sys_strings(seg_manager_t *self, seg_id_t *segid)
}
seg_id_t
-sm_allocate_reserved_segment(seg_manager_t *self, char *src_name)
-{
+sm_allocate_reserved_segment(seg_manager_t *self, char *src_name) {
seg_id_t segid;
mem_obj_t *memobj = alloc_nonscript_segment(self, MEM_OBJ_RESERVED, &segid);
char *name = sci_strdup(src_name);
@@ -1389,36 +1336,34 @@ sm_allocate_reserved_segment(seg_manager_t *self, char *src_name)
}
guint16
-sm_validate_export_func(struct _seg_manager_t* self, int pubfunct, int seg ) {
- script_t* script;
+sm_validate_export_func(struct _seg_manager_t* self, int pubfunct, int seg) {
+ script_t* script;
guint16 offset;
- VERIFY ( sm_check (self, seg), "invalid seg id" );
- VERIFY (self->heap[seg]->type == MEM_OBJ_SCRIPT, "Can only validate exports on scripts");
+ VERIFY(sm_check(self, seg), "invalid seg id");
+ VERIFY(self->heap[seg]->type == MEM_OBJ_SCRIPT, "Can only validate exports on scripts");
script = &self->heap[seg]->data.script;
- if( script->exports_nr <= pubfunct ) {
- sciprintf( "pubfunct is invalid" );
+ if (script->exports_nr <= pubfunct) {
+ sciprintf("pubfunct is invalid");
return 0;
}
if (self->exports_wide) pubfunct *= 2;
- offset = getUInt16( (byte*)(script->export_table + pubfunct) );
- VERIFY ( offset < script->buf_size, "invalid export function pointer" );
+ offset = getUInt16((byte*)(script->export_table + pubfunct));
+ VERIFY(offset < script->buf_size, "invalid export function pointer");
return offset;
}
void
-sm_free_hunk_entry(seg_manager_t *self, reg_t addr)
-{
+sm_free_hunk_entry(seg_manager_t *self, reg_t addr) {
sm_free_hunk(self, addr);
}
hunk_t *
-sm_alloc_hunk_entry(seg_manager_t *self, const char *hunk_type, int size, reg_t *reg)
-{
+sm_alloc_hunk_entry(seg_manager_t *self, const char *hunk_type, int size, reg_t *reg) {
hunk_t *h = sm_alloc_hunk(self, reg);
if (!h)
@@ -1432,17 +1377,15 @@ sm_alloc_hunk_entry(seg_manager_t *self, const char *hunk_type, int size, reg_t
}
static void
-_clone_cleanup(clone_t *clone)
-{
+_clone_cleanup(clone_t *clone) {
if (clone->variables)
sci_free(clone->variables); /* Free the dynamically allocated memory part */
}
static void
-_hunk_cleanup(hunk_t *hunk)
-{
+_hunk_cleanup(hunk_t *hunk) {
if (hunk->mem)
- free (hunk->mem);
+ free(hunk->mem);
}
DEFINE_HEAPENTRY(list, 8, 4)
@@ -1494,17 +1437,16 @@ DEFINE_ALLOC_DEALLOC(static, hunk, MEM_OBJ_HUNK, hunks)
byte *
-sm_dereference(seg_manager_t *self, reg_t pointer, int *size)
-{
+sm_dereference(seg_manager_t *self, reg_t pointer, int *size) {
mem_obj_t *mobj;
byte *base = NULL;
int count;
if (!pointer.segment
- || (pointer.segment >= self->heap_size)
- || !self->heap[pointer.segment]) {
+ || (pointer.segment >= self->heap_size)
+ || !self->heap[pointer.segment]) {
sciprintf("Error: Attempt to dereference invalid pointer "PREG"!\n",
- PRINT_REG(pointer));
+ PRINT_REG(pointer));
return NULL; /* Invalid */
}
@@ -1516,13 +1458,13 @@ sm_dereference(seg_manager_t *self, reg_t pointer, int *size)
case MEM_OBJ_SCRIPT:
if (pointer.offset > mobj->data.script.buf_size) {
sciprintf("Error: Attempt to dereference invalid pointer "PREG
- " into script segment (script size=%d)\n",
- PRINT_REG(pointer), mobj->data.script.buf_size);
+ " into script segment (script size=%d)\n",
+ PRINT_REG(pointer), mobj->data.script.buf_size);
return NULL;
}
if (size)
*size = mobj->data.script.buf_size - pointer.offset;
- return (byte *) (mobj->data.script.buf + pointer.offset);
+ return (byte *)(mobj->data.script.buf + pointer.offset);
break;
case MEM_OBJ_LOCALS:
@@ -1544,24 +1486,24 @@ sm_dereference(seg_manager_t *self, reg_t pointer, int *size)
if (size)
*size = mobj->data.sys_strings.strings[pointer.offset].max_size;
if (pointer.offset < SYS_STRINGS_MAX
- && mobj->data.sys_strings.strings[pointer.offset].name)
- return (byte *) (mobj->data.sys_strings.strings[pointer.offset].value);
+ && mobj->data.sys_strings.strings[pointer.offset].name)
+ return (byte *)(mobj->data.sys_strings.strings[pointer.offset].value);
else {
sciprintf("Error: Attempt to dereference invalid pointer "PREG"!\n",
- PRINT_REG(pointer));
+ PRINT_REG(pointer));
return NULL;
}
case MEM_OBJ_RESERVED:
sciprintf("Error: Trying to dereference pointer "PREG" to reserved segment `%s'!\n",
- mobj->data.reserved);
+ mobj->data.reserved);
return NULL;
break;
default:
sciprintf("Error: Trying to dereference pointer "PREG" to inappropriate"
- " segment!\n",
- PRINT_REG(pointer));
+ " segment!\n",
+ PRINT_REG(pointer));
return NULL;
}
@@ -1569,13 +1511,12 @@ sm_dereference(seg_manager_t *self, reg_t pointer, int *size)
*size = count;
return
- base + pointer.offset;
+ base + pointer.offset;
}
unsigned char *
-sm_alloc_dynmem(seg_manager_t *self, int size, const char *descr, reg_t *addr)
-{
+sm_alloc_dynmem(seg_manager_t *self, int size, const char *descr, reg_t *addr) {
seg_id_t seg;
mem_obj_t *mobj = alloc_nonscript_segment(self, MEM_OBJ_DYNMEM, &seg);
*addr = make_reg(seg, 0);
@@ -1589,19 +1530,17 @@ sm_alloc_dynmem(seg_manager_t *self, int size, const char *descr, reg_t *addr)
mobj->data.dynmem.description = descr;
- return (unsigned char *) (mobj->data.dynmem.buf);
+ return (unsigned char *)(mobj->data.dynmem.buf);
}
const char *
-sm_get_description(seg_manager_t *self, reg_t addr)
-{
+sm_get_description(seg_manager_t *self, reg_t addr) {
mem_obj_t *mobj = self->heap[addr.segment];
if (addr.segment >= self->heap_size)
- return "";
+ return "";
- switch (mobj->type)
- {
+ switch (mobj->type) {
case MEM_OBJ_DYNMEM:
return mobj->data.dynmem.description;
default:
@@ -1610,13 +1549,12 @@ sm_get_description(seg_manager_t *self, reg_t addr)
}
int
-sm_free_dynmem(seg_manager_t *self, reg_t addr)
-{
-
+sm_free_dynmem(seg_manager_t *self, reg_t addr) {
+
if (addr.segment <= 0
- || addr.segment >= self->heap_size
- || !self->heap[addr.segment]
- || self->heap[addr.segment]->type != MEM_OBJ_DYNMEM)
+ || addr.segment >= self->heap_size
+ || !self->heap[addr.segment]
+ || self->heap[addr.segment]->type != MEM_OBJ_DYNMEM)
return 1; /* error */
_sm_deallocate(self, addr.segment, 1);
@@ -1630,8 +1568,7 @@ sm_free_dynmem(seg_manager_t *self, reg_t addr)
static void
-free_at_address_stub (seg_interface_t *self, reg_t sub_addr)
-{
+free_at_address_stub(seg_interface_t *self, reg_t sub_addr) {
// sciprintf(" Request to free "PREG"\n", PRINT_REG(sub_addr));
/* STUB */
}
@@ -1639,87 +1576,78 @@ free_at_address_stub (seg_interface_t *self, reg_t sub_addr)
static reg_t
-find_canonic_address_base (seg_interface_t *self, reg_t addr)
-{
+find_canonic_address_base(seg_interface_t *self, reg_t addr) {
addr.offset = 0;
return addr;
}
static reg_t
-find_canonic_address_id (seg_interface_t *self, reg_t addr)
-{
+find_canonic_address_id(seg_interface_t *self, reg_t addr) {
return addr;
}
static void
-free_at_address_nop (seg_interface_t *self, reg_t sub_addr)
-{
+free_at_address_nop(seg_interface_t *self, reg_t sub_addr) {
}
static void
-list_all_deallocatable_nop (seg_interface_t *self, void *param, void (*note) (void*param, reg_t addr))
-{
+list_all_deallocatable_nop(seg_interface_t *self, void *param, void (*note)(void*param, reg_t addr)) {
}
static void
-list_all_deallocatable_base (seg_interface_t *self, void *param, void (*note) (void*param, reg_t addr))
-{
- (*note) (param, make_reg (self->seg_id, 0));
+list_all_deallocatable_base(seg_interface_t *self, void *param, void (*note)(void*param, reg_t addr)) {
+ (*note)(param, make_reg(self->seg_id, 0));
}
static void
-list_all_outgoing_references_nop (seg_interface_t *self, state_t *s, reg_t addr, void *param, void (*note) (void*param, reg_t addr))
-{
+list_all_outgoing_references_nop(seg_interface_t *self, state_t *s, reg_t addr, void *param, void (*note)(void*param, reg_t addr)) {
}
static void
-deallocate_self (seg_interface_t *self)
-{
- sci_free (self);
+deallocate_self(seg_interface_t *self) {
+ sci_free(self);
}
static void
-free_at_address_script (seg_interface_t *self, reg_t addr)
-{
+free_at_address_script(seg_interface_t *self, reg_t addr) {
script_t *script;
VERIFY(self->mobj->type == MEM_OBJ_SCRIPT, "Trying to free a non-script!");
script = &(self->mobj->data.script);
-/*
- sciprintf("[GC] Freeing script "PREG"\n", PRINT_REG(addr));
- if (script->locals_segment)
- sciprintf("[GC] Freeing locals %04x:0000\n", script->locals_segment);
-*/
+ /*
+ sciprintf("[GC] Freeing script "PREG"\n", PRINT_REG(addr));
+ if (script->locals_segment)
+ sciprintf("[GC] Freeing locals %04x:0000\n", script->locals_segment);
+ */
if (script->marked_as_deleted)
sm_deallocate_script(self->segmgr, script->nr);
}
static void
-list_all_outgoing_references_script (seg_interface_t *self, state_t *s, reg_t addr, void *param, void (*note) (void*param, reg_t addr))
-{
+list_all_outgoing_references_script(seg_interface_t *self, state_t *s, reg_t addr, void *param, void (*note)(void*param, reg_t addr)) {
script_t *script = &(self->mobj->data.script);
if (addr.offset <= script->buf_size
- && addr.offset >= -SCRIPT_OBJECT_MAGIC_OFFSET
- && RAW_IS_OBJECT(script->buf + addr.offset)) {
+ && addr.offset >= -SCRIPT_OBJECT_MAGIC_OFFSET
+ && RAW_IS_OBJECT(script->buf + addr.offset)) {
int idx = RAW_GET_CLASS_INDEX(script, addr);
if (idx >= 0 && idx < script->objects_nr) {
object_t *obj = script->objects + idx;
int i;
-
+
/* Note all local variables, if we have a local variable environment */
if (script->locals_segment)
- (*note) (param, make_reg(script->locals_segment, 0));
+ (*note)(param, make_reg(script->locals_segment, 0));
for (i = 0; i < obj->variables_nr; i++)
- (*note) (param, obj->variables[i]);
+ (*note)(param, obj->variables[i]);
} else {
fprintf(stderr, "Request for outgoing script-object reference at "PREG" yielded invalid index %d\n", PRINT_REG(addr), idx);
}
} else {
-/* fprintf(stderr, "Unexpected request for outgoing script-object references at "PREG"\n", PRINT_REG(addr));*/
- /* Happens e.g. when we're looking into strings */
+ /* fprintf(stderr, "Unexpected request for outgoing script-object references at "PREG"\n", PRINT_REG(addr));*/
+ /* Happens e.g. when we're looking into strings */
}
}
@@ -1748,21 +1676,19 @@ static seg_interface_t seg_interface_script = {
(*note) (param, make_reg(self->seg_id, i));
static void
-list_all_deallocatable_clones (seg_interface_t *self, void *param, void (*note) (void*param, reg_t addr))
-{
+list_all_deallocatable_clones(seg_interface_t *self, void *param, void (*note)(void*param, reg_t addr)) {
LIST_ALL_DEALLOCATABLE(clone, clones);
}
static void
-list_all_outgoing_references_clones (seg_interface_t *self, state_t *s, reg_t addr, void *param, void (*note) (void*param, reg_t addr))
-{
+list_all_outgoing_references_clones(seg_interface_t *self, state_t *s, reg_t addr, void *param, void (*note)(void*param, reg_t addr)) {
mem_obj_t *mobj = self->mobj;
clone_table_t *clone_table = &(mobj->data.clones);
clone_t *clone;
int i;
- assert (addr.segment == self->seg_id);
-
+ assert(addr.segment == self->seg_id);
+
if (!(ENTRY_IS_VALID(clone_table, addr.offset))) {
fprintf(stderr, "Unexpected request for outgoing references from clone at "PREG"\n", PRINT_REG(addr));
// BREAKPOINT();
@@ -1773,37 +1699,36 @@ list_all_outgoing_references_clones (seg_interface_t *self, state_t *s, reg_t ad
/* Emit all member variables (including references to the 'super' delegate) */
for (i = 0; i < clone->variables_nr; i++)
- (*note) (param, clone->variables[i]);
+ (*note)(param, clone->variables[i]);
/* Note that this also includes the 'base' object, which is part of the script and therefore also
** emits the locals. */
- (*note) (param, clone->pos);
+ (*note)(param, clone->pos);
// sciprintf("[GC] Reporting clone-pos "PREG"\n", PRINT_REG(clone->pos));
}
void
-free_at_address_clones(seg_interface_t *self, reg_t addr)
-{
+free_at_address_clones(seg_interface_t *self, reg_t addr) {
object_t *victim_obj;
- assert (addr.segment == self->seg_id);
+ assert(addr.segment == self->seg_id);
victim_obj = &(self->mobj->data.clones.table[addr.offset].entry);
#ifdef GC_DEBUG
if (!(victim_obj->flags & OBJECT_FLAG_FREED))
sciprintf("[GC] Warning: Clone "PREG" not reachable and not freed (freeing now)\n",
- PRINT_REG(addr));
+ PRINT_REG(addr));
# ifdef GC_DEBUG_VERBOSE
else
sciprintf("[GC-DEBUG] Clone "PREG": Freeing\n", PRINT_REG(addr));
# endif
#endif
-/*
- sciprintf("[GC] Clone "PREG": Freeing\n", PRINT_REG(addr));
- sciprintf("[GC] Clone had pos "PREG"\n", PRINT_REG(victim_obj->pos));
-*/
+ /*
+ sciprintf("[GC] Clone "PREG": Freeing\n", PRINT_REG(addr));
+ sciprintf("[GC] Clone had pos "PREG"\n", PRINT_REG(victim_obj->pos));
+ */
sci_free(victim_obj->variables);
victim_obj->variables = NULL;
sm_free_clone(self->segmgr, addr);
@@ -1825,27 +1750,25 @@ static seg_interface_t seg_interface_clones = {
static reg_t
-find_canonic_address_locals (seg_interface_t *self, reg_t addr)
-{
+find_canonic_address_locals(seg_interface_t *self, reg_t addr) {
local_variables_t *locals = &(self->mobj->data.locals);
/* Reference the owning script */
seg_id_t owner_seg = sm_seg_get(self->segmgr, locals->script_id);
- assert (owner_seg >= 0);
+ assert(owner_seg >= 0);
return make_reg(owner_seg, 0);
}
static void
-list_all_outgoing_references_locals (seg_interface_t *self, state_t *s, reg_t addr, void *param, void (*note) (void*param, reg_t addr))
-{
+list_all_outgoing_references_locals(seg_interface_t *self, state_t *s, reg_t addr, void *param, void (*note)(void*param, reg_t addr)) {
local_variables_t *locals = &(self->mobj->data.locals);
int i;
- assert (addr.segment == self->seg_id);
+ assert(addr.segment == self->seg_id);
for (i = 0; i < locals->nr; i++)
- (*note) (param, locals->locals[i]);
+ (*note)(param, locals->locals[i]);
}
/*-------------------- locals --------------------*/
@@ -1864,13 +1787,12 @@ static seg_interface_t seg_interface_locals = {
static void
-list_all_outgoing_references_stack (seg_interface_t *self, state_t *s, reg_t addr, void *param, void (*note) (void*param, reg_t addr))
-{
+list_all_outgoing_references_stack(seg_interface_t *self, state_t *s, reg_t addr, void *param, void (*note)(void*param, reg_t addr)) {
int i;
-fprintf(stderr, "Emitting %d stack entries\n", self->mobj->data.stack.nr);
- for (i = 0; i < self->mobj->data.stack.nr; i++)
- (*note) (param, self->mobj->data.stack.entries[i]);
-fprintf(stderr, "DONE");
+ fprintf(stderr, "Emitting %d stack entries\n", self->mobj->data.stack.nr);
+ for (i = 0; i < self->mobj->data.stack.nr; i++)
+ (*note)(param, self->mobj->data.stack.entries[i]);
+ fprintf(stderr, "DONE");
}
/*-------------------- stack --------------------*/
@@ -1902,14 +1824,12 @@ static seg_interface_t seg_interface_sys_strings = {
};
static void
-list_all_deallocatable_list (seg_interface_t *self, void *param, void (*note) (void*param, reg_t addr))
-{
+list_all_deallocatable_list(seg_interface_t *self, void *param, void (*note)(void*param, reg_t addr)) {
LIST_ALL_DEALLOCATABLE(list, lists);
}
static void
-list_all_outgoing_references_list (seg_interface_t *self, state_t *s, reg_t addr, void *param, void (*note) (void*param, reg_t addr))
-{
+list_all_outgoing_references_list(seg_interface_t *self, state_t *s, reg_t addr, void *param, void (*note)(void*param, reg_t addr)) {
list_table_t *table = &(self->mobj->data.lists);
list_t *list = &(table->table[addr.offset].entry);
@@ -1918,16 +1838,15 @@ list_all_outgoing_references_list (seg_interface_t *self, state_t *s, reg_t addr
return;
}
- note (param, list->first);
- note (param, list->last);
+ note(param, list->first);
+ note(param, list->last);
/* We could probably get away with just one of them, but
** let's be conservative here. */
}
static void
-free_at_address_lists (seg_interface_t *self, reg_t sub_addr)
-{
- sm_free_list (self->segmgr, sub_addr);
+free_at_address_lists(seg_interface_t *self, reg_t sub_addr) {
+ sm_free_list(self->segmgr, sub_addr);
}
/*-------------------- lists --------------------*/
@@ -1945,14 +1864,12 @@ static seg_interface_t seg_interface_lists = {
};
static void
-list_all_deallocatable_nodes (seg_interface_t *self, void *param, void (*note) (void*param, reg_t addr))
-{
+list_all_deallocatable_nodes(seg_interface_t *self, void *param, void (*note)(void*param, reg_t addr)) {
LIST_ALL_DEALLOCATABLE(node, nodes);
}
static void
-list_all_outgoing_references_nodes (seg_interface_t *self, state_t *s, reg_t addr, void *param, void (*note) (void*param, reg_t addr))
-{
+list_all_outgoing_references_nodes(seg_interface_t *self, state_t *s, reg_t addr, void *param, void (*note)(void*param, reg_t addr)) {
node_table_t *table = &(self->mobj->data.nodes);
node_t *node = &(table->table[addr.offset].entry);
@@ -1963,16 +1880,15 @@ list_all_outgoing_references_nodes (seg_interface_t *self, state_t *s, reg_t add
/* We need all four here. Can't just stick with 'pred' OR 'succ' because node operations allow us
** to walk around from any given node */
- note (param, node->pred);
- note (param, node->succ);
- note (param, node->key);
- note (param, node->value);
+ note(param, node->pred);
+ note(param, node->succ);
+ note(param, node->key);
+ note(param, node->value);
}
static void
-free_at_address_nodes (seg_interface_t *self, reg_t sub_addr)
-{
- sm_free_node (self->segmgr, sub_addr);
+free_at_address_nodes(seg_interface_t *self, reg_t sub_addr) {
+ sm_free_node(self->segmgr, sub_addr);
}
/*-------------------- nodes --------------------*/
@@ -1990,8 +1906,7 @@ static seg_interface_t seg_interface_nodes = {
};
static void
-list_all_deallocatable_hunk (seg_interface_t *self, void *param, void (*note) (void*param, reg_t addr))
-{
+list_all_deallocatable_hunk(seg_interface_t *self, void *param, void (*note)(void*param, reg_t addr)) {
LIST_ALL_DEALLOCATABLE(hunk, hunks);
}
@@ -2055,8 +1970,7 @@ static seg_interface_t* seg_interfaces[MEM_OBJ_MAX] = {
seg_interface_t *
-get_seg_interface(seg_manager_t *self, seg_id_t segid)
-{
+get_seg_interface(seg_manager_t *self, seg_id_t segid) {
mem_obj_t *mobj;
seg_interface_t *retval;
@@ -2065,10 +1979,10 @@ get_seg_interface(seg_manager_t *self, seg_id_t segid)
mobj = self->heap[segid];
retval = (seg_interface_t*)sci_malloc(sizeof(seg_interface_t));
- memcpy(retval, seg_interfaces[mobj->type - 1], sizeof (seg_interface_t));
+ memcpy(retval, seg_interfaces[mobj->type - 1], sizeof(seg_interface_t));
if (mobj->type != retval->type_id) {
- fprintf(stderr, "Improper segment interface for %d", mobj->type );
+ fprintf(stderr, "Improper segment interface for %d", mobj->type);
exit(1);
}
diff --git a/engines/sci/engine/sys_strings.cpp b/engines/sci/engine/sys_strings.cpp
index 5aeb1a64c0..bd31b715b5 100644
--- a/engines/sci/engine/sys_strings.cpp
+++ b/engines/sci/engine/sys_strings.cpp
@@ -30,22 +30,21 @@
#include "sci/include/sci_memory.h"
void
-sys_string_acquire(sys_strings_t *strings, int index, const char *name, int max_len)
-{
+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);
+ index);
BREAKPOINT();
}
if (str->name
- && (strcmp(name, str->name)
- || (str->max_size != max_len))) {
+ && (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);
+ "was '%s', tried to claim as '%s'\n",
+ index, str->name, name);
BREAKPOINT();
}
@@ -56,13 +55,12 @@ sys_string_acquire(sys_strings_t *strings, int index, const char *name, int max_
}
int
-sys_string_set(sys_strings_t *strings, int index, const char *value)
-{
+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);
+ index);
BREAKPOINT();
return 1;
}
@@ -73,26 +71,23 @@ sys_string_set(sys_strings_t *strings, int index, const char *value)
}
void
-sys_string_free(sys_strings_t *strings, int index)
-{
+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)
-{
+sys_string_free_all(sys_strings_t *strings) {
int i;
- for (i=0;i<SYS_STRINGS_MAX;i++)
- {
+ for (i = 0;i < SYS_STRINGS_MAX;i++) {
if (strings->strings[i].name)
sys_string_free(strings, i);
}
@@ -100,8 +95,7 @@ sys_string_free_all(sys_strings_t *strings)
}
void
-sys_strings_restore(sys_strings_t *new_strings, sys_strings_t *old_strings)
-{
+sys_strings_restore(sys_strings_t *new_strings, sys_strings_t *old_strings) {
int i;
/* First, pad memory */
diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp
index b19d07a7d1..a66ab70f7e 100644
--- a/engines/sci/engine/vm.cpp
+++ b/engines/sci/engine/vm.cpp
@@ -72,10 +72,8 @@ static jmp_buf vm_error_address;
#ifndef DISABLE_VALIDATIONS
static inline reg_t *
-validate_property(object_t *obj, int index)
-{
- if (!obj)
- {
+validate_property(object_t *obj, int index) {
+ if (!obj) {
if (sci_debug_flags & 4)
sciprintf("[VM] Sending to disposed object!\n");
_dummy_register = NULL_REG;
@@ -85,7 +83,7 @@ validate_property(object_t *obj, int index)
if (index < 0 || index >= obj->variables_nr) {
if (sci_debug_flags & 4)
sciprintf("[VM] Invalid property #%d (out of [0..%d]) requested!\n", index,
- obj->variables_nr);
+ obj->variables_nr);
_dummy_register = NULL_REG;
return &_dummy_register;
@@ -95,22 +93,20 @@ validate_property(object_t *obj, int index)
}
static inline stack_ptr_t
-validate_stack_addr(state_t *s, stack_ptr_t sp)
-{
+validate_stack_addr(state_t *s, stack_ptr_t sp) {
if (sp >= s->stack_base && sp < s->stack_top)
return sp;
script_debug_flag = script_error_flag = 1;
if (sci_debug_flags & 4)
sciprintf("[VM] Stack index %d out of valid range [%d..%d]\n",
- sp - s->stack_base, 0, s->stack_top - s->stack_base -1);
+ sp - s->stack_base, 0, s->stack_top - s->stack_base - 1);
return 0;
}
static inline int
-validate_arithmetic(reg_t reg)
-{
+validate_arithmetic(reg_t reg) {
if (reg.segment) {
if (!_weak_validations)
script_debug_flag = script_error_flag = 1;
@@ -123,8 +119,7 @@ validate_arithmetic(reg_t reg)
}
static inline int
-signed_validate_arithmetic(reg_t reg)
-{
+signed_validate_arithmetic(reg_t reg) {
if (reg.segment) {
if (!_weak_validations)
script_debug_flag = script_error_flag = 1;
@@ -132,16 +127,15 @@ signed_validate_arithmetic(reg_t reg)
sciprintf("[VM] Attempt to read arithmetic value from non-zero segment [%04x]\n", reg.segment);
return 0;
}
-
+
if (reg.offset&0x8000)
- return (signed) (reg.offset)-65536;
+ return (signed)(reg.offset) - 65536;
else
return reg.offset;
}
static inline int
-validate_variable(reg_t *r, reg_t *stack_base, int type, int max, int index, int line)
-{
+validate_variable(reg_t *r, reg_t *stack_base, int type, int max, int index, int line) {
const char *names[4] = {"global", "local", "temp", "param"};
if (index < 0 || index >= max) {
@@ -149,7 +143,7 @@ validate_variable(reg_t *r, reg_t *stack_base, int type, int max, int index, int
if (max == 0)
sciprintf("(variable type invalid)");
else
- sciprintf("(out of range [%d..%d])", 0, max-1);
+ sciprintf("(out of range [%d..%d])", 0, max - 1);
sciprintf(" in %s, line %d\n", __FILE__, line);
if (!_weak_validations)
script_debug_flag = script_error_flag = 1;
@@ -161,7 +155,7 @@ validate_variable(reg_t *r, reg_t *stack_base, int type, int max, int index, int
int total_offset = r - stack_base;
if (total_offset < 0 || total_offset >= VM_STACK_SIZE) {
sciprintf("[VM] Access would be outside even of the stack (%d); access denied\n",
- total_offset);
+ total_offset);
return 1;
} else {
sciprintf("[VM] Access within stack boundaries; access granted.\n");
@@ -175,8 +169,7 @@ validate_variable(reg_t *r, reg_t *stack_base, int type, int max, int index, int
}
static inline reg_t
-validate_read_var(reg_t *r, reg_t *stack_base, int type, int max, int index, int line, reg_t default_value)
-{
+validate_read_var(reg_t *r, reg_t *stack_base, int type, int max, int index, int line, reg_t default_value) {
if (!validate_variable(r, stack_base, type, max, index, line))
return r[index];
else
@@ -184,8 +177,7 @@ validate_read_var(reg_t *r, reg_t *stack_base, int type, int max, int index, int
}
static inline void
-validate_write_var(reg_t *r, reg_t *stack_base, int type, int max, int index, int line, reg_t value)
-{
+validate_write_var(reg_t *r, reg_t *stack_base, int type, int max, int index, int line, reg_t value) {
if (!validate_variable(r, stack_base, type, max, index, line))
r[index] = value;
}
@@ -219,8 +211,7 @@ validate_write_var(reg_t *r, reg_t *stack_base, int type, int max, int index, in
/*==--------------------------==*/
int
-script_error(state_t *s, const char *file, int line, const char *reason)
-{
+script_error(state_t *s, const char *file, int line, const char *reason) {
sciprintf("Script error in file %s, line %d: %s\n", file, line, reason);
script_debug_flag = script_error_flag = 1;
return 0;
@@ -228,8 +219,7 @@ script_error(state_t *s, const char *file, int line, const char *reason)
#define CORE_ERROR(area, msg) script_error(s, "[" area "] " __FILE__, __LINE__, msg)
reg_t
-get_class_address(state_t *s, int classnr, int lock, reg_t caller)
-{
+get_class_address(state_t *s, int classnr, int lock, reg_t caller) {
class_t *the_class = s->classtable + classnr;
if (NULL == s) {
@@ -238,10 +228,10 @@ get_class_address(state_t *s, int classnr, int lock, reg_t caller)
}
if (classnr < 0
- || s->classtable_size <= classnr
- || the_class->script < 0) {
+ || s->classtable_size <= classnr
+ || the_class->script < 0) {
sciprintf("[VM] Attempt to dereference class %x, which doesn't exist (max %x)\n",
- classnr, s->classtable_size);
+ classnr, s->classtable_size);
script_error_flag = script_debug_flag = 1;
return NULL_REG;
} else {
@@ -250,7 +240,7 @@ get_class_address(state_t *s, int classnr, int lock, reg_t caller)
if (!the_class->reg.segment) {
sciprintf("[VM] Trying to instantiate class %x by instantiating script 0x%x (%03d) failed;"
- " Entering debugger.\n", classnr, the_class->script);
+ " Entering debugger.\n", classnr, the_class->script);
script_error_flag = script_debug_flag = 1;
return NULL_REG;
}
@@ -287,61 +277,56 @@ get_class_address(state_t *s, int classnr, int lock, reg_t caller)
inline exec_stack_t *
execute_method(state_t *s, word script, word pubfunct, stack_ptr_t sp,
- reg_t calling_obj, word argc, stack_ptr_t argp)
-{
+ reg_t calling_obj, word argc, stack_ptr_t argp) {
int seg;
guint16 temp;
- if (!sm_script_is_loaded (&s->seg_manager, script, SCRIPT_ID)) /* Script not present yet? */
+ if (!sm_script_is_loaded(&s->seg_manager, script, SCRIPT_ID)) /* Script not present yet? */
script_instantiate(s, script);
else
sm_unmark_script_deleted(&s->seg_manager, script);
- seg = sm_seg_get( &s->seg_manager, script );
+ seg = sm_seg_get(&s->seg_manager, script);
- temp = sm_validate_export_func( &s->seg_manager, pubfunct, seg );
- VERIFY( temp, "Invalid pubfunct in export table" );
- if( !temp ) {
+ temp = sm_validate_export_func(&s->seg_manager, pubfunct, seg);
+ VERIFY(temp, "Invalid pubfunct in export table");
+ if (!temp) {
sciprintf("Request for invalid exported function 0x%x of script 0x%x\n", pubfunct, script);
script_error_flag = script_debug_flag = 1;
return NULL;
}
- /* Check if a breakpoint is set on this method */
- if (s->have_bp & BREAK_EXPORT)
- {
- breakpoint_t *bp;
- guint32 bpaddress;
-
- bpaddress = (script << 16 | pubfunct);
-
- bp = s->bp_list;
- while (bp)
- {
- if (bp->type == BREAK_EXPORT && bp->data.address == bpaddress)
- {
- sciprintf ("Break on script %d, export %d\n", script, pubfunct);
- script_debug_flag = 1;
- bp_flag = 1;
- break;
- }
- bp = bp->next;
- }
- }
-
- return add_exec_stack_entry(s, make_reg( seg, temp ),
- sp, calling_obj, argc, argp, -1, calling_obj,
- s->execution_stack_pos, seg);
+ /* Check if a breakpoint is set on this method */
+ if (s->have_bp & BREAK_EXPORT) {
+ breakpoint_t *bp;
+ guint32 bpaddress;
+
+ bpaddress = (script << 16 | pubfunct);
+
+ bp = s->bp_list;
+ while (bp) {
+ if (bp->type == BREAK_EXPORT && bp->data.address == bpaddress) {
+ sciprintf("Break on script %d, export %d\n", script, pubfunct);
+ script_debug_flag = 1;
+ bp_flag = 1;
+ break;
+ }
+ bp = bp->next;
+ }
+ }
+
+ return add_exec_stack_entry(s, make_reg(seg, temp),
+ sp, calling_obj, argc, argp, -1, calling_obj,
+ s->execution_stack_pos, seg);
}
static void
-_exec_varselectors(state_t *s)
-{ /* Executes all varselector read/write ops on the TOS */
+_exec_varselectors(state_t *s) { /* Executes all varselector read/write ops on the TOS */
/* Now check the TOS to execute all varselector entries */
if (s->execution_stack_pos >= 0)
while (s->execution_stack[s->execution_stack_pos].type == EXEC_STACK_TYPE_VARSELECTOR) {
- /* varselector access? */
+ /* varselector access? */
if (s->execution_stack[s->execution_stack_pos].argc) { /* write? */
reg_t temp = s->execution_stack[s->execution_stack_pos].variables_argp[1];
*(s->execution_stack[s->execution_stack_pos].addr.varp) = temp;
@@ -355,9 +340,9 @@ _exec_varselectors(state_t *s)
exec_stack_t *
send_selector(state_t *s, reg_t send_obj, reg_t work_obj,
- stack_ptr_t sp, int framesize, stack_ptr_t argp)
- /* send_obj and work_obj are equal for anything but 'super' */
- /* Returns a pointer to the TOS exec_stack element */
+ stack_ptr_t sp, int framesize, stack_ptr_t argp)
+/* send_obj and work_obj are equal for anything but 'super' */
+/* Returns a pointer to the TOS exec_stack element */
{
#ifdef VM_DEBUG_SEND
int i;
@@ -374,17 +359,17 @@ send_selector(state_t *s, reg_t send_obj, reg_t work_obj,
/* The selector calls we catch are stored below: */
int send_calls_nr = -1;
- if (NULL == s) {
- sciprintf("vm.c: exec_stack_t(): NULL passed for \"s\"\n");
- return NULL;
- }
+ if (NULL == s) {
+ sciprintf("vm.c: exec_stack_t(): NULL passed for \"s\"\n");
+ return NULL;
+ }
while (framesize > 0) {
selector = validate_arithmetic(*argp++);
argc = validate_arithmetic(*argp);
- if (argc > 0x800){ /* More arguments than the stack could possibly accomodate for */
+ if (argc > 0x800) { /* More arguments than the stack could possibly accomodate for */
CORE_ERROR("SEND", "More than 0x800 arguments to function call\n");
return NULL;
}
@@ -394,9 +379,9 @@ send_selector(state_t *s, reg_t send_obj, reg_t work_obj,
breakpoint_t *bp;
char method_name [256];
- sprintf (method_name, "%s::%s",
- obj_get_name(s, send_obj),
- s->selector_names [selector]);
+ sprintf(method_name, "%s::%s",
+ obj_get_name(s, send_obj),
+ s->selector_names [selector]);
bp = s->bp_list;
while (bp) {
@@ -404,9 +389,9 @@ send_selector(state_t *s, reg_t send_obj, reg_t work_obj,
if (bp->data.name[cmplen - 1] != ':')
cmplen = 256;
- if (bp->type == BREAK_SELECTOR && !strncmp (bp->data.name, method_name, cmplen)) {
- sciprintf ("Break on %s (in ["PREG"])\n", method_name,
- PRINT_REG(send_obj));
+ if (bp->type == BREAK_SELECTOR && !strncmp(bp->data.name, method_name, cmplen)) {
+ sciprintf("Break on %s (in ["PREG"])\n", method_name,
+ PRINT_REG(send_obj));
script_debug_flag = print_send_action = 1;
bp_flag = 1;
break;
@@ -417,19 +402,19 @@ send_selector(state_t *s, reg_t send_obj, reg_t work_obj,
#ifdef VM_DEBUG_SEND
sciprintf("Send to "PREG", selector %04x (%s):",
- PRINT_REG(send_obj), selector, s->selector_names[selector]);
+ PRINT_REG(send_obj), selector, s->selector_names[selector]);
#endif /* VM_DEBUG_SEND */
if (++send_calls_nr == (send_calls_allocated - 1))
send_calls = (calls_struct_t*)sci_realloc(send_calls, sizeof(calls_struct_t)
- * (send_calls_allocated *= 2));
+ * (send_calls_allocated *= 2));
switch (lookup_selector(s, send_obj, selector, &varp, &funcp)) {
case SELECTOR_NONE:
sciprintf("Send to invalid selector 0x%x of object at "PREG"\n",
- 0xffff & selector, PRINT_REG(send_obj));
+ 0xffff & selector, PRINT_REG(send_obj));
script_error_flag = script_debug_flag = 1;
--send_calls_nr;
break;
@@ -457,26 +442,26 @@ send_selector(state_t *s, reg_t send_obj, reg_t work_obj,
#endif
{ /* Argument is supplied -> Selector should be set */
- if (print_send_action) {
- reg_t oldReg = *varp;
- reg_t newReg = argp[1];
+ if (print_send_action) {
+ reg_t oldReg = *varp;
+ reg_t newReg = argp[1];
- sciprintf("[write to selector: change "PREG" to "PREG"]\n",
- PRINT_REG(oldReg), PRINT_REG(newReg));
- print_send_action = 0;
- }
- send_calls[send_calls_nr].address.var = varp; /* register the call */
- send_calls[send_calls_nr].argp = argp;
- send_calls[send_calls_nr].argc = argc;
- send_calls[send_calls_nr].selector = selector;
- send_calls[send_calls_nr].type = EXEC_STACK_TYPE_VARSELECTOR; /* Register as a varselector */
+ sciprintf("[write to selector: change "PREG" to "PREG"]\n",
+ PRINT_REG(oldReg), PRINT_REG(newReg));
+ print_send_action = 0;
+ }
+ send_calls[send_calls_nr].address.var = varp; /* register the call */
+ send_calls[send_calls_nr].argp = argp;
+ send_calls[send_calls_nr].argc = argc;
+ send_calls[send_calls_nr].selector = selector;
+ send_calls[send_calls_nr].type = EXEC_STACK_TYPE_VARSELECTOR; /* Register as a varselector */
- } break;
+ } break;
#ifdef STRICT_SEND
default:
--send_calls_nr;
sciprintf("Send error: Variable selector %04x in "PREG" called with %04x params\n",
- selector, PRINT_REG(send_obj), argc);
+ selector, PRINT_REG(send_obj), argc);
script_debug_flag = 1; /* Enter debug mode */
_debug_seeking = _debug_step_running = 0;
@@ -522,19 +507,19 @@ send_selector(state_t *s, reg_t send_obj, reg_t work_obj,
for (; send_calls_nr >= 0; send_calls_nr--)
if (send_calls[send_calls_nr].type == EXEC_STACK_TYPE_VARSELECTOR) /* Write/read variable? */
retval = add_exec_stack_varselector(s, work_obj, send_calls[send_calls_nr].argc,
- send_calls[send_calls_nr].argp,
- send_calls[send_calls_nr].selector,
- send_calls[send_calls_nr].address.var, origin);
+ send_calls[send_calls_nr].argp,
+ send_calls[send_calls_nr].selector,
+ send_calls[send_calls_nr].address.var, origin);
else
retval =
- add_exec_stack_entry(s, send_calls[send_calls_nr].address.func,
- send_calls[send_calls_nr].sp, work_obj,
- send_calls[send_calls_nr].argc,
- send_calls[send_calls_nr].argp,
- send_calls[send_calls_nr].selector,
- send_obj, origin,
- SCI_XS_CALLEE_LOCALS);
+ add_exec_stack_entry(s, send_calls[send_calls_nr].address.func,
+ send_calls[send_calls_nr].sp, work_obj,
+ send_calls[send_calls_nr].argc,
+ send_calls[send_calls_nr].argp,
+ send_calls[send_calls_nr].selector,
+ send_obj, origin,
+ SCI_XS_CALLEE_LOCALS);
_exec_varselectors(s);
@@ -545,10 +530,9 @@ send_selector(state_t *s, reg_t send_obj, reg_t work_obj,
exec_stack_t *
add_exec_stack_varselector(state_t *s, reg_t objp, int argc, stack_ptr_t argp,
- selector_t selector, reg_t *address, int origin)
-{
+ selector_t selector, reg_t *address, int origin) {
exec_stack_t *xstack = add_exec_stack_entry(s, NULL_REG, address, objp, argc, argp,
- selector, objp, origin, SCI_XS_CALLEE_LOCALS);
+ selector, objp, origin, SCI_XS_CALLEE_LOCALS);
/* Store selector address in sp */
xstack->addr.varp = address;
@@ -560,8 +544,8 @@ add_exec_stack_varselector(state_t *s, reg_t objp, int argc, stack_ptr_t argp,
exec_stack_t *
add_exec_stack_entry(state_t *s, reg_t pc, stack_ptr_t sp, reg_t objp, int argc,
- stack_ptr_t argp, selector_t selector, reg_t sendp, int origin,
- seg_id_t locals_segment)
+ stack_ptr_t argp, selector_t selector, reg_t sendp, int origin,
+ seg_id_t locals_segment)
/* Returns new TOS element for the execution stack*/
/* locals_segment may be -1 if derived from the called object */
{
@@ -569,14 +553,14 @@ add_exec_stack_entry(state_t *s, reg_t pc, stack_ptr_t sp, reg_t objp, int argc,
if (!s->execution_stack)
s->execution_stack =
- (exec_stack_t*)sci_malloc(sizeof(exec_stack_t) * (s->execution_stack_size = 16));
+ (exec_stack_t*)sci_malloc(sizeof(exec_stack_t) * (s->execution_stack_size = 16));
if (++(s->execution_stack_pos) == s->execution_stack_size) /* Out of stack space? */
s->execution_stack = (exec_stack_t*)sci_realloc(s->execution_stack,
- sizeof(exec_stack_t) * (s->execution_stack_size += 8));
+ sizeof(exec_stack_t) * (s->execution_stack_size += 8));
- /* sciprintf("Exec stack: [%d/%d], origin %d, at %p\n", s->execution_stack_pos,
- s->execution_stack_size, origin, s->execution_stack); */
+ /* sciprintf("Exec stack: [%d/%d], origin %d, at %p\n", s->execution_stack_pos,
+ s->execution_stack_size, origin, s->execution_stack); */
xstack = s->execution_stack + s->execution_stack_pos;
@@ -611,8 +595,7 @@ add_exec_stack_entry(state_t *s, reg_t pc, stack_ptr_t sp, reg_t objp, int argc,
void
-vm_handle_fatal_error(state_t *s, int line, const char *file)
-{
+vm_handle_fatal_error(state_t *s, int line, const char *file) {
fprintf(stderr, "Fatal VM error in %s, L%d; aborting...\n", file, line);
#ifdef HAVE_SETJMP_H
if (jump_initialized)
@@ -623,8 +606,7 @@ vm_handle_fatal_error(state_t *s, int line, const char *file)
}
static inline script_t *
-script_locate_by_segment(state_t *s, seg_id_t seg)
-{
+script_locate_by_segment(state_t *s, seg_id_t seg) {
mem_obj_t *memobj = GET_SEGMENT(s->seg_manager, seg, MEM_OBJ_SCRIPT);
if (memobj)
return &(memobj->data.script);
@@ -634,8 +616,7 @@ script_locate_by_segment(state_t *s, seg_id_t seg)
static reg_t
-pointer_add(state_t *s, reg_t base, int offset)
-{
+pointer_add(state_t *s, reg_t base, int offset) {
mem_obj_t *mobj = GET_SEGMENT_ANY(s->seg_manager, base.segment);
if (!mobj) {
@@ -647,7 +628,7 @@ pointer_add(state_t *s, reg_t base, int offset)
switch (mobj->type) {
case MEM_OBJ_LOCALS:
- base.offset += 2*offset;
+ base.offset += 2 * offset;
return base;
case MEM_OBJ_SCRIPT:
@@ -665,8 +646,7 @@ pointer_add(state_t *s, reg_t base, int offset)
}
static inline void
-gc_countdown(state_t *s)
-{
+gc_countdown(state_t *s) {
if (s->gc_countdown-- <= 0) {
s->gc_countdown = script_gc_interval;
run_gc(s);
@@ -676,8 +656,7 @@ gc_countdown(state_t *s)
static byte _fake_return_buffer[2] = {op_ret << 1, op_ret << 1};
void
-run_vm(state_t *s, int restoring)
-{
+run_vm(state_t *s, int restoring) {
reg_t *variables[4]; /* global, local, temp, param, as immediate pointers */
reg_t *variables_base[4]; /* Used for referencing VM ops */
seg_id_t variables_seg[4]; /* Same as above, contains segment IDs */
@@ -707,7 +686,7 @@ run_vm(state_t *s, int restoring)
script_error(s, __FILE__, __LINE__, "Program Counter gone astray");
return;
}
-
+
if (NULL == s) {
sciprintf("vm.c: run_vm(): NULL passed for \"s\"\n");
return;
@@ -736,7 +715,7 @@ run_vm(state_t *s, int restoring)
/* SCI code reads the zeroeth argument to determine argc */
if (s->script_000->locals_block)
variables_base[VAR_GLOBAL] = variables[VAR_GLOBAL]
- = s->script_000->locals_block->locals;
+ = s->script_000->locals_block->locals;
else
variables_base[VAR_GLOBAL] = variables[VAR_GLOBAL] = NULL;
@@ -794,10 +773,10 @@ run_vm(state_t *s, int restoring)
variables_seg[VAR_LOCAL] = local_script->locals_segment;
if (local_script->locals_block)
variables_base[VAR_LOCAL] = variables[VAR_LOCAL]
- = local_script->locals_block->locals;
+ = local_script->locals_block->locals;
else
variables_base[VAR_LOCAL] = variables[VAR_LOCAL]
- = NULL;
+ = NULL;
#ifndef DISABLE_VALIDATIONS
if (local_script->locals_block)
variables_max[VAR_LOCAL] = local_script->locals_block->nr;
@@ -821,14 +800,14 @@ run_vm(state_t *s, int restoring)
/* Debug if this has been requested: */
if (script_debug_flag || sci_debug_flags) {
script_debug(s, &(xs->addr.pc), &(xs->sp), &(xs->fp),
- &(xs->objp), &restadjust,
- variables_seg, variables, variables_base,
+ &(xs->objp), &restadjust,
+ variables_seg, variables, variables_base,
#ifdef DISABLE_VALIDATIONS
- NULL,
+ NULL,
#else
- variables_max,
+ variables_max,
#endif
- bp_flag);
+ bp_flag);
bp_flag = 0;
}
@@ -847,13 +826,21 @@ run_vm(state_t *s, int restoring)
opnumber = opcode >> 1;
for (temp = 0; formats[opnumber][temp]; temp++) /* formats comes from script.c */
- switch(formats[opnumber][temp]) {
+ switch (formats[opnumber][temp]) {
- case Script_Byte: opparams[temp] = GET_OP_BYTE(); break;
- case Script_SByte: opparams[temp] = GET_OP_SIGNED_BYTE(); break;
+ case Script_Byte:
+ opparams[temp] = GET_OP_BYTE();
+ break;
+ case Script_SByte:
+ opparams[temp] = GET_OP_SIGNED_BYTE();
+ break;
- case Script_Word: opparams[temp] = GET_OP_WORD(); break;
- case Script_SWord: opparams[temp] = GET_OP_SIGNED_WORD(); break;
+ case Script_Word:
+ opparams[temp] = GET_OP_WORD();
+ break;
+ case Script_SWord:
+ opparams[temp] = GET_OP_SIGNED_WORD();
+ break;
case Script_Variable:
case Script_Property:
@@ -862,15 +849,18 @@ run_vm(state_t *s, int restoring)
case Script_Temp:
case Script_Global:
case Script_Param:
- opparams[temp] = GET_OP_FLEX(); break;
+ opparams[temp] = GET_OP_FLEX();
+ break;
case Script_SVariable:
case Script_SRelative:
- opparams[temp] = GET_OP_SIGNED_FLEX(); break;
+ opparams[temp] = GET_OP_SIGNED_FLEX();
+ break;
case Script_Offset:
- opparams[temp] = GET_OP_FLEX(); break;
-
+ opparams[temp] = GET_OP_FLEX();
+ break;
+
case Script_None:
case Script_End:
break;
@@ -886,7 +876,7 @@ run_vm(state_t *s, int restoring)
switch (opnumber) {
case 0x00: /* bnot */
- s->r_acc = ACC_ARITHMETIC_L (0xffff ^ /*acc*/);
+ s->r_acc = ACC_ARITHMETIC_L(0xffff ^ /*acc*/);
break;
case 0x01: /* add */
@@ -898,11 +888,11 @@ run_vm(state_t *s, int restoring)
if (s->r_acc.segment) {
if (r_temp.segment) {
sciprintf("Error: Attempt to add two pointers, stack="PREG" and acc="PREG"!\n",
- PRINT_REG(r_temp), PRINT_REG(s->r_acc));
+ PRINT_REG(r_temp), PRINT_REG(s->r_acc));
script_debug_flag = script_error_flag = 1;
offset = 0;
} else {
- r_ptr = s->r_acc;
+ r_ptr = s->r_acc;
offset = r_temp.offset;
}
} else {
@@ -925,11 +915,11 @@ run_vm(state_t *s, int restoring)
if (s->r_acc.segment) {
if (r_temp.segment) {
sciprintf("Error: Attempt to subtract two pointers, stack="PREG" and acc="PREG"!\n",
- PRINT_REG(r_temp), PRINT_REG(s->r_acc));
+ PRINT_REG(r_temp), PRINT_REG(s->r_acc));
script_debug_flag = script_error_flag = 1;
offset = 0;
} else {
- r_ptr = s->r_acc;
+ r_ptr = s->r_acc;
offset = r_temp.offset;
}
} else {
@@ -944,7 +934,7 @@ run_vm(state_t *s, int restoring)
break;
case 0x03: /* mul */
- s->r_acc = ACC_ARITHMETIC_L (((gint16)POP()) * (gint16)/*acc*/);
+ s->r_acc = ACC_ARITHMETIC_L(((gint16)POP()) * (gint16)/*acc*/);
break;
case 0x04: /* div */
@@ -1092,18 +1082,18 @@ run_vm(state_t *s, int restoring)
case 0x20: { /* call */
int argc = (opparams[1] >> 1) /* Given as offset, but we need count */
- + 1 + restadjust;
+ + 1 + restadjust;
stack_ptr_t call_base = xs->sp - argc;
xs->sp[1].offset += restadjust;
xs_new = add_exec_stack_entry(s, make_reg(xs->addr.pc.segment,
- xs->addr.pc.offset
- + opparams[0]),
- xs->sp, xs->objp,
- (validate_arithmetic(*call_base))
- + restadjust,
- call_base, NULL_SELECTOR, xs->objp,
- s->execution_stack_pos, xs->local_segment);
+ xs->addr.pc.offset
+ + opparams[0]),
+ xs->sp, xs->objp,
+ (validate_arithmetic(*call_base))
+ + restadjust,
+ call_base, NULL_SELECTOR, xs->objp,
+ s->execution_stack_pos, xs->local_segment);
restadjust = 0; /* Used up the &rest adjustment */
xs->sp = call_base;
@@ -1114,7 +1104,7 @@ run_vm(state_t *s, int restoring)
case 0x21: /* callk */
gc_countdown(s);
- xs->sp -= (opparams[1] >> 1)+1;
+ xs->sp -= (opparams[1] >> 1) + 1;
if (s->version >= SCI_VERSION_FTU_NEW_SCRIPT_HEADER) {
xs->sp -= restadjust;
s->r_amp_rest = 0; /* We just used up the restadjust, remember? */
@@ -1132,16 +1122,16 @@ run_vm(state_t *s, int restoring)
argc += restadjust;
if (s->kfunct_table[opparams[0]].signature
- && !kernel_matches_signature(s,
- s->kfunct_table[opparams[0]]
- .signature,
- argc, xs->sp + 1)) {
+ && !kernel_matches_signature(s,
+ s->kfunct_table[opparams[0]]
+ .signature,
+ argc, xs->sp + 1)) {
sciprintf("[VM] Invalid arguments to kernel call %x\n",
- opparams[0]);
+ opparams[0]);
script_debug_flag = script_error_flag = 1;
} else {
s->r_acc = s->kfunct_table[opparams[0]]
- .fun(s, opparams[0], argc, xs->sp + 1);
+ .fun(s, opparams[0], argc, xs->sp + 1);
}
/* Call kernel function */
@@ -1151,7 +1141,7 @@ run_vm(state_t *s, int restoring)
xs_new = s->execution_stack + s->execution_stack_pos;
s->execution_stack_pos_changed = 1;
- if (s->version>=SCI_VERSION_FTU_NEW_SCRIPT_HEADER)
+ if (s->version >= SCI_VERSION_FTU_NEW_SCRIPT_HEADER)
restadjust = s->r_amp_rest;
}
@@ -1165,12 +1155,12 @@ run_vm(state_t *s, int restoring)
xs->sp[0].offset += restadjust;
xs_new = execute_method(s, 0, opparams[0], s_temp, xs->objp,
- xs->sp[0].offset, xs->sp);
+ xs->sp[0].offset, xs->sp);
restadjust = 0; /* Used up the &rest adjustment */
if (xs_new) /* in case of error, keep old stack */
s->execution_stack_pos_changed = 1;
break;
-
+
case 0x23: /* calle */
temp = ((opparams[2] >> 1) + restadjust + 1);
s_temp = xs->sp;
@@ -1178,9 +1168,9 @@ run_vm(state_t *s, int restoring)
xs->sp[0].offset += restadjust;
xs_new = execute_method(s, opparams[0], opparams[1], s_temp, xs->objp,
- xs->sp[0].offset, xs->sp);
+ xs->sp[0].offset, xs->sp);
restadjust = 0; /* Used up the &rest adjustment */
-
+
if (xs_new) /* in case of error, keep old stack */
s->execution_stack_pos_changed = 1;
break;
@@ -1216,7 +1206,7 @@ run_vm(state_t *s, int restoring)
xs = s->execution_stack + s->execution_stack_pos;
if (xs->sp == CALL_SP_CARRY /* Used in sends to 'carry' the stack pointer */
- || xs->type != EXEC_STACK_TYPE_CALL) {
+ || xs->type != EXEC_STACK_TYPE_CALL) {
xs->sp = old_sp;
xs->fp = old_fp;
}
@@ -1234,8 +1224,8 @@ run_vm(state_t *s, int restoring)
xs->sp[1].offset += restadjust;
xs_new = send_selector(s, s->r_acc, s->r_acc, s_temp,
- (int)(opparams[0]>>1) + (word)restadjust,
- xs->sp);
+ (int)(opparams[0] >> 1) + (word)restadjust,
+ xs->sp);
if (xs_new && xs_new != xs)
s->execution_stack_pos_changed = 1;
@@ -1254,8 +1244,8 @@ run_vm(state_t *s, int restoring)
xs->sp[1].offset += restadjust;
xs_new = send_selector(s, xs->objp, xs->objp, s_temp,
- (int)(opparams[0]>>1) + (word)restadjust,
- xs->sp);
+ (int)(opparams[0] >> 1) + (word)restadjust,
+ xs->sp);
if (xs_new && xs_new != xs)
s->execution_stack_pos_changed = 1;
@@ -1274,8 +1264,8 @@ run_vm(state_t *s, int restoring)
xs->sp[1].offset += restadjust;
xs_new = send_selector(s, r_temp, xs->objp, s_temp,
- (int)(opparams[1]>>1) + (word)restadjust,
- xs->sp);
+ (int)(opparams[1] >> 1) + (word)restadjust,
+ xs->sp);
if (xs_new && xs_new != xs)
s->execution_stack_pos_changed = 1;
@@ -1341,13 +1331,13 @@ run_vm(state_t *s, int restoring)
case 0x35: /* ipToa */
s->r_acc = OBJ_PROPERTY(obj, (opparams[0] >> 1));
s->r_acc = OBJ_PROPERTY(obj, (opparams[0] >> 1)) =
- ACC_ARITHMETIC_L( 1 + /*acc*/);
+ ACC_ARITHMETIC_L(1 + /*acc*/);
break;
case 0x36: /* dpToa */
s->r_acc = OBJ_PROPERTY(obj, (opparams[0] >> 1));
s->r_acc = OBJ_PROPERTY(obj, (opparams[0] >> 1)) =
- ACC_ARITHMETIC_L(-1 + /*acc*/);
+ ACC_ARITHMETIC_L(-1 + /*acc*/);
break;
case 0x37: /* ipTos */
@@ -1366,18 +1356,18 @@ run_vm(state_t *s, int restoring)
case 0x39: /* lofsa */
s->r_acc.segment = xs->addr.pc.segment;
- if (s->version >= SCI_VERSION(1,001,000))
- s->r_acc.offset = opparams[0]+local_script->script_size;
- else
- if (s->version >= SCI_VERSION_FTU_LOFS_ABSOLUTE)
- s->r_acc.offset = opparams[0];
+ if (s->version >= SCI_VERSION(1, 001, 000))
+ s->r_acc.offset = opparams[0] + local_script->script_size;
else
- s->r_acc.offset = xs->addr.pc.offset + opparams[0];
+ if (s->version >= SCI_VERSION_FTU_LOFS_ABSOLUTE)
+ s->r_acc.offset = opparams[0];
+ else
+ s->r_acc.offset = xs->addr.pc.offset + opparams[0];
#ifndef DISABLE_VALIDATIONS
if (s->r_acc.offset >= code_buf_size) {
sciprintf("VM: lofsa operation overflowed: "PREG" beyond end"
- " of script (at %04x)\n", PRINT_REG(s->r_acc),
- code_buf_size);
+ " of script (at %04x)\n", PRINT_REG(s->r_acc),
+ code_buf_size);
script_error_flag = script_debug_flag = 1;
}
#endif
@@ -1388,13 +1378,14 @@ run_vm(state_t *s, int restoring)
r_temp.segment = xs->addr.pc.segment;
if (s->version >= SCI_VERSION_FTU_LOFS_ABSOLUTE)
- r_temp.offset = opparams[0]; else
+ r_temp.offset = opparams[0];
+ else
r_temp.offset = xs->addr.pc.offset + opparams[0];
#ifndef DISABLE_VALIDATIONS
if (r_temp.offset >= code_buf_size) {
sciprintf("VM: lofss operation overflowed: "PREG" beyond end"
- " of script (at %04x)\n", PRINT_REG(r_temp),
- code_buf_size);
+ " of script (at %04x)\n", PRINT_REG(r_temp),
+ code_buf_size);
script_error_flag = script_debug_flag = 1;
}
#endif
@@ -1499,9 +1490,9 @@ run_vm(state_t *s, int restoring)
var_type = (opcode >> 1) & 0x3; /* Gets the variable type: g, l, t or p */
var_number = opparams[0];
s->r_acc = make_reg(0,
- 1 + validate_arithmetic(READ_VAR(var_type,
- var_number,
- s->r_acc)));
+ 1 + validate_arithmetic(READ_VAR(var_type,
+ var_number,
+ s->r_acc)));
WRITE_VAR(var_type, var_number, s->r_acc);
break;
@@ -1512,9 +1503,9 @@ run_vm(state_t *s, int restoring)
var_type = (opcode >> 1) & 0x3; /* Gets the variable type: g, l, t or p */
var_number = opparams[0];
r_temp = make_reg(0,
- 1 + validate_arithmetic(READ_VAR(var_type,
- var_number,
- s->r_acc)));
+ 1 + validate_arithmetic(READ_VAR(var_type,
+ var_number,
+ s->r_acc)));
PUSH32(r_temp);
WRITE_VAR(var_type, var_number, r_temp);
break;
@@ -1526,9 +1517,9 @@ run_vm(state_t *s, int restoring)
var_type = (opcode >> 1) & 0x3; /* Gets the variable type: g, l, t or p */
var_number = opparams[0] + signed_validate_arithmetic(s->r_acc);
s->r_acc = make_reg(0,
- 1 + validate_arithmetic(READ_VAR(var_type,
- var_number,
- s->r_acc)));
+ 1 + validate_arithmetic(READ_VAR(var_type,
+ var_number,
+ s->r_acc)));
WRITE_VAR(var_type, var_number, s->r_acc);
break;
@@ -1539,9 +1530,9 @@ run_vm(state_t *s, int restoring)
var_type = (opcode >> 1) & 0x3; /* Gets the variable type: g, l, t or p */
var_number = opparams[0] + signed_validate_arithmetic(s->r_acc);
r_temp = make_reg(0,
- 1 + validate_arithmetic(READ_VAR(var_type,
- var_number,
- s->r_acc)));
+ 1 + validate_arithmetic(READ_VAR(var_type,
+ var_number,
+ s->r_acc)));
PUSH32(r_temp);
WRITE_VAR(var_type, var_number, r_temp);
break;
@@ -1553,8 +1544,8 @@ run_vm(state_t *s, int restoring)
var_type = (opcode >> 1) & 0x3; /* Gets the variable type: g, l, t or p */
var_number = opparams[0];
s->r_acc = make_reg(0,
- -1 + validate_arithmetic(READ_VAR(var_type,
- var_number, s->r_acc)));
+ -1 + validate_arithmetic(READ_VAR(var_type,
+ var_number, s->r_acc)));
WRITE_VAR(var_type, var_number, s->r_acc);
break;
@@ -1565,8 +1556,8 @@ run_vm(state_t *s, int restoring)
var_type = (opcode >> 1) & 0x3; /* Gets the variable type: g, l, t or p */
var_number = opparams[0];
r_temp = make_reg(0,
- -1 + validate_arithmetic(READ_VAR(var_type,
- var_number, s->r_acc)));
+ -1 + validate_arithmetic(READ_VAR(var_type,
+ var_number, s->r_acc)));
PUSH32(r_temp);
WRITE_VAR(var_type, var_number, r_temp);
break;
@@ -1578,9 +1569,9 @@ run_vm(state_t *s, int restoring)
var_type = (opcode >> 1) & 0x3; /* Gets the variable type: g, l, t or p */
var_number = opparams[0] + signed_validate_arithmetic(s->r_acc);
s->r_acc = make_reg(0,
- -1 + validate_arithmetic(READ_VAR(var_type,
- var_number,
- s->r_acc)));
+ -1 + validate_arithmetic(READ_VAR(var_type,
+ var_number,
+ s->r_acc)));
WRITE_VAR(var_type, var_number, s->r_acc);
break;
@@ -1591,9 +1582,9 @@ run_vm(state_t *s, int restoring)
var_type = (opcode >> 1) & 0x3; /* Gets the variable type: g, l, t or p */
var_number = opparams[0] + signed_validate_arithmetic(s->r_acc);
r_temp = make_reg(0,
- -1 + validate_arithmetic(READ_VAR(var_type,
- var_number,
- s->r_acc)));
+ -1 + validate_arithmetic(READ_VAR(var_type,
+ var_number,
+ s->r_acc)));
PUSH32(r_temp);
WRITE_VAR(var_type, var_number, r_temp);
break;
@@ -1610,7 +1601,7 @@ run_vm(state_t *s, int restoring)
#ifndef DISABLE_VALIDATIONS
if (xs != s->execution_stack + s->execution_stack_pos) {
sciprintf("Error: xs is stale (%d vs %d); last command was %02x\n",
- xs-s->execution_stack, s->execution_stack_pos, opnumber);
+ xs - s->execution_stack, s->execution_stack_pos, opnumber);
}
#endif
@@ -1627,27 +1618,23 @@ run_vm(state_t *s, int restoring)
static inline int
-_obj_locate_varselector(state_t *s, object_t *obj, selector_t slc)
-{ /* Determines if obj explicitly defines slc as a varselector */
+_obj_locate_varselector(state_t *s, object_t *obj, selector_t slc) { /* Determines if obj explicitly defines slc as a varselector */
/* Returns -1 if not found */
-
- if (s->version < SCI_VERSION(1,001,000))
- {
+
+ if (s->version < SCI_VERSION(1, 001, 000)) {
int varnum = obj->variable_names_nr;
int selector_name_offset = varnum * 2 + SCRIPT_SELECTOR_OFFSET;
int i;
byte *buf = obj->base_obj + selector_name_offset;
obj->base_vars = (guint16 *) buf;
-
+
for (i = 0; i < varnum; i++)
if (getUInt16(buf + (i << 1)) == slc) /* Found it? */
return i; /* report success */
-
+
return -1; /* Failed */
- }
- else
- {
+ } else {
byte *buf = (byte *) obj->base_vars;
int i;
int varnum = obj->variables[1].offset;
@@ -1658,15 +1645,14 @@ _obj_locate_varselector(state_t *s, object_t *obj, selector_t slc)
for (i = 0; i < varnum; i++)
if (getUInt16(buf + (i << 1)) == slc) /* Found it? */
return i; /* report success */
-
+
return -1; /* Failed */
- }
+ }
}
static inline int
-_class_locate_funcselector(state_t *s, object_t *obj, selector_t slc)
-{ /* Determines if obj is a class and explicitly defines slc as a funcselector */
+_class_locate_funcselector(state_t *s, object_t *obj, selector_t slc) { /* Determines if obj is a class and explicitly defines slc as a funcselector */
/* Does NOT say anything about obj's superclasses, i.e. failure may be
** returned even if one of the superclasses defines the funcselector. */
int funcnum = obj->methods_nr;
@@ -1681,8 +1667,7 @@ _class_locate_funcselector(state_t *s, object_t *obj, selector_t slc)
static inline int
-_lookup_selector_function(state_t *s, int seg_id, object_t *obj, selector_t selector_id, reg_t *fptr)
-{
+_lookup_selector_function(state_t *s, int seg_id, object_t *obj, selector_t selector_id, reg_t *fptr) {
int index;
/* "recursive" lookup */
@@ -1691,17 +1676,16 @@ _lookup_selector_function(state_t *s, int seg_id, object_t *obj, selector_t sele
index = _class_locate_funcselector(s, obj, selector_id);
if (index >= 0) {
- if (fptr)
- {
- if (s->version < SCI_VERSION(1,001,000))
+ if (fptr) {
+ if (s->version < SCI_VERSION(1, 001, 000))
*fptr = make_reg(obj->pos.segment,
- getUInt16((byte *)
- (obj->base_method + index
- + obj->methods_nr + 1)));
+ getUInt16((byte *)
+ (obj->base_method + index
+ + obj->methods_nr + 1)));
else
*fptr = make_reg(obj->pos.segment,
- getUInt16((byte *)
- (obj->base_method + index * 2 + 2)));
+ getUInt16((byte *)
+ (obj->base_method + index * 2 + 2)));
}
return SELECTOR_METHOD;
@@ -1715,8 +1699,7 @@ _lookup_selector_function(state_t *s, int seg_id, object_t *obj, selector_t sele
}
int
-lookup_selector(state_t *s, reg_t obj_location, selector_t selector_id, reg_t **vptr, reg_t *fptr)
-{
+lookup_selector(state_t *s, reg_t obj_location, selector_t selector_id, reg_t **vptr, reg_t *fptr) {
object_t *obj = obj_get(s, obj_location);
object_t *species;
int index;
@@ -1752,22 +1735,21 @@ lookup_selector(state_t *s, reg_t obj_location, selector_t selector_id, reg_t **
if (vptr)
*vptr = obj->variables + index;
return SELECTOR_VARIABLE;
- } return
- _lookup_selector_function(s, obj_location.segment, obj, selector_id, fptr);
+ }
+ return
+ _lookup_selector_function(s, obj_location.segment, obj, selector_id, fptr);
}
/* Detects SCI versions by their different script header */
-void script_detect_versions(state_t *s)
-{
+void script_detect_versions(state_t *s) {
int c;
resource_t *script = {0};
-
- if (scir_find_resource(s->resmgr, sci_heap, 0, 0))
- {
- version_require_later_than(s, SCI_VERSION(1,001,000));
+
+ if (scir_find_resource(s->resmgr, sci_heap, 0, 0)) {
+ version_require_later_than(s, SCI_VERSION(1, 001, 000));
return;
}
@@ -1786,8 +1768,7 @@ void script_detect_versions(state_t *s)
seg_id_t
-script_get_segment(state_t *s, int script_nr, int load)
-{
+script_get_segment(state_t *s, int script_nr, int load) {
seg_id_t segment;
if ((load & SCRIPT_GET_LOAD) == SCRIPT_GET_LOAD)
@@ -1805,8 +1786,7 @@ script_get_segment(state_t *s, int script_nr, int load)
}
reg_t
-script_lookup_export(state_t *s, int script_nr, int export_index)
-{
+script_lookup_export(state_t *s, int script_nr, int export_index) {
seg_id_t seg = script_get_segment(s, script_nr, SCRIPT_GET_DONT_LOAD);
mem_obj_t *memobj;
script_t *script = NULL;
@@ -1815,7 +1795,7 @@ script_lookup_export(state_t *s, int script_nr, int export_index)
if (!seg) {
CORE_ERROR("EXPORTS", "Script invalid or not loaded");
sciprintf("Script was script.03d (0x%x)\n",
- script_nr, script_nr);
+ script_nr, script_nr);
return NULL_REG;
}
#endif
@@ -1827,8 +1807,8 @@ script_lookup_export(state_t *s, int script_nr, int export_index)
#ifndef DISABLE_VALIDATIONS
if (script
- && export_index < script->exports_nr
- && export_index >= 0)
+ && export_index < script->exports_nr
+ && export_index >= 0)
#endif
return make_reg(seg, getUInt16((byte *)(script->export_table + export_index)));
#ifndef DISABLE_VALIDATIONS
@@ -1838,7 +1818,7 @@ script_lookup_export(state_t *s, int script_nr, int export_index)
sciprintf("(script.%03d missing)\n", script_nr);
else
sciprintf("(script.%03d: Sought export %d/%d)\n",
- script_nr, export_index, script->exports_nr);
+ script_nr, export_index, script->exports_nr);
return NULL_REG;
}
#endif
@@ -1850,25 +1830,23 @@ int sm_script_marked_deleted(seg_manager_t* self, int script_nr);
int sm_initialise_script(mem_obj_t *mem, struct _state *s, int script_nr);
int
-script_instantiate_common(state_t *s, int script_nr, resource_t **script, resource_t **heap, int *was_new)
-{
+script_instantiate_common(state_t *s, int script_nr, resource_t **script, resource_t **heap, int *was_new) {
int seg;
int seg_id;
- int marked_for_deletion;
+ int marked_for_deletion;
mem_obj_t *mem;
reg_t reg;
*was_new = 1;
*script = scir_find_resource(s->resmgr, sci_script, script_nr, 0);
- if (s->version >= SCI_VERSION(1,001,000))
+ if (s->version >= SCI_VERSION(1, 001, 000))
*heap = scir_find_resource(s->resmgr, sci_heap, script_nr, 0);
- if (!*script || (s->version >= SCI_VERSION(1,001,000) && !heap)) {
+ if (!*script || (s->version >= SCI_VERSION(1, 001, 000) && !heap)) {
sciprintf("Script 0x%x requested but not found\n", script_nr);
/* script_debug_flag = script_error_flag = 1; */
- if (s->version >= SCI_VERSION(1,001,000))
- {
+ if (s->version >= SCI_VERSION(1, 001, 000)) {
if (*heap)
sciprintf("Inconsistency: heap resource WAS found\n");
else if (*script)
@@ -1877,30 +1855,27 @@ script_instantiate_common(state_t *s, int script_nr, resource_t **script, resour
return 0;
}
- if (NULL == s) {
- sciprintf("vm.c: script_instantiate(): NULL passed for \"s\"\n");
+ if (NULL == s) {
+ sciprintf("vm.c: script_instantiate(): NULL passed for \"s\"\n");
return 0;
}
- seg = sm_seg_get ( &s->seg_manager, script_nr );
- if (sm_script_is_loaded (&s->seg_manager, script_nr, SCRIPT_ID)) {
+ seg = sm_seg_get(&s->seg_manager, script_nr);
+ if (sm_script_is_loaded(&s->seg_manager, script_nr, SCRIPT_ID)) {
marked_for_deletion = sm_script_marked_deleted(&s->seg_manager, script_nr);
- if (!marked_for_deletion) {
- sm_increment_lockers( &s->seg_manager, seg, SEG_ID );
- return seg;
- }
- else
- {
+ if (!marked_for_deletion) {
+ sm_increment_lockers(&s->seg_manager, seg, SEG_ID);
+ return seg;
+ } else {
seg_id = seg;
mem = s->seg_manager.heap[seg];
sm_free_script(mem);
}
- }
- else if (!(mem = sm_allocate_script( &s->seg_manager, s, script_nr, &seg_id ))) { /* ALL YOUR SCRIPT BASE ARE BELONG TO US */
+ } else if (!(mem = sm_allocate_script(&s->seg_manager, s, script_nr, &seg_id))) { /* ALL YOUR SCRIPT BASE ARE BELONG TO US */
sciprintf("Not enough heap space for script size 0x%x of script 0x%x,"
- " should this happen?`\n",
- (*script)->size, script_nr);
+ " should this happen?`\n",
+ (*script)->size, script_nr);
script_debug_flag = script_error_flag = 1;
return 0;
}
@@ -1911,10 +1886,10 @@ script_instantiate_common(state_t *s, int script_nr, resource_t **script, resour
reg.offset = 0;
/* Set heap position (beyond the size word) */
- sm_set_lockers( &s->seg_manager, 1, reg.segment, SEG_ID );
- sm_set_export_table_offset( &s->seg_manager, 0, reg.segment, SEG_ID );
- sm_set_synonyms_offset( &s->seg_manager, 0, reg.segment, SEG_ID );
- sm_set_synonyms_nr( &s->seg_manager, 0, reg.segment, SEG_ID );
+ sm_set_lockers(&s->seg_manager, 1, reg.segment, SEG_ID);
+ sm_set_export_table_offset(&s->seg_manager, 0, reg.segment, SEG_ID);
+ sm_set_synonyms_offset(&s->seg_manager, 0, reg.segment, SEG_ID);
+ sm_set_synonyms_nr(&s->seg_manager, 0, reg.segment, SEG_ID);
*was_new = 0;
@@ -1922,8 +1897,7 @@ script_instantiate_common(state_t *s, int script_nr, resource_t **script, resour
}
int
-script_instantiate_sci0(state_t *s, int script_nr)
-{
+script_instantiate_sci0(state_t *s, int script_nr) {
int objtype;
unsigned int objlength;
reg_t reg, reg_tmp;
@@ -1952,15 +1926,15 @@ script_instantiate_sci0(state_t *s, int script_nr)
/* Instead, the script starts with a 16 bit int specifying the
** number of locals we need; these are then allocated and zeroed. */
- sm_mcpy_in_out( &s->seg_manager, 0, script->data, script->size, reg.segment, SEG_ID);
+ sm_mcpy_in_out(&s->seg_manager, 0, script->data, script->size, reg.segment, SEG_ID);
magic_pos_adder = 2; /* Step over the funny prefix */
if (locals_nr)
- sm_script_initialise_locals_zero( &s->seg_manager,
- reg.segment, locals_nr);
+ sm_script_initialise_locals_zero(&s->seg_manager,
+ reg.segment, locals_nr);
} else {
- sm_mcpy_in_out( &s->seg_manager, 0, script->data, script->size, reg.segment, SEG_ID);
+ sm_mcpy_in_out(&s->seg_manager, 0, script->data, script->size, reg.segment, SEG_ID);
magic_pos_adder = 0;
}
@@ -1977,7 +1951,7 @@ script_instantiate_sci0(state_t *s, int script_nr)
reg_t addr;
reg.offset += objlength; /* Step over the last checked object */
objtype = SEG_GET_HEAP(s, reg);
- if( !objtype ) break;
+ if (!objtype) break;
objlength = SEG_GET_HEAP(s, make_reg(reg.segment, reg.offset + 2));
@@ -1986,20 +1960,20 @@ script_instantiate_sci0(state_t *s, int script_nr)
addr = data_base;
- switch( objtype ) {
+ switch (objtype) {
case sci_obj_exports: {
- sm_set_export_table_offset( &s->seg_manager, data_base.offset,
- reg.segment, SEG_ID );
+ sm_set_export_table_offset(&s->seg_manager, data_base.offset,
+ reg.segment, SEG_ID);
}
- break;
+ break;
case sci_obj_synonyms:
- sm_set_synonyms_offset( &s->seg_manager, addr.offset, reg.segment, SEG_ID ); /* +4 is to step over the header */
- sm_set_synonyms_nr( &s->seg_manager, (objlength) / 4, reg.segment, SEG_ID );
+ sm_set_synonyms_offset(&s->seg_manager, addr.offset, reg.segment, SEG_ID); /* +4 is to step over the header */
+ sm_set_synonyms_nr(&s->seg_manager, (objlength) / 4, reg.segment, SEG_ID);
break;
case sci_obj_localvars:
- sm_script_initialise_locals( &s->seg_manager, data_base);
+ sm_script_initialise_locals(&s->seg_manager, data_base);
break;
case sci_obj_class: {
@@ -2009,9 +1983,9 @@ script_instantiate_sci0(state_t *s, int script_nr)
species = OBJ_SPECIES(s, reg_tmp);
if (species < 0 || species >= s->classtable_size) {
sciprintf("Invalid species %d(0x%x) not in interval "
- "[0,%d) while instantiating script %d\n",
- species, species, s->classtable_size,
- script_nr);
+ "[0,%d) while instantiating script %d\n",
+ species, species, s->classtable_size,
+ script_nr);
script_debug_flag = script_error_flag = 1;
return 1;
}
@@ -2021,8 +1995,8 @@ script_instantiate_sci0(state_t *s, int script_nr)
s->classtable[species].reg.offset = classpos;
/* Set technical class position-- into the block allocated for it */
- }
- break;
+ }
+ break;
default:
break;
@@ -2037,7 +2011,7 @@ script_instantiate_sci0(state_t *s, int script_nr)
reg_t addr;
reg.offset += objlength; /* Step over the last checked object */
objtype = SEG_GET_HEAP(s, reg);
- if( !objtype ) break;
+ if (!objtype) break;
objlength = SEG_GET_HEAP(s, make_reg(reg.segment, reg.offset + 2));
reg.offset += 4; /* Step over header */
@@ -2048,25 +2022,24 @@ script_instantiate_sci0(state_t *s, int script_nr)
sm_script_add_code_block(&s->seg_manager, addr);
break;
case sci_obj_object:
- case sci_obj_class:
- { /* object or class? */
+ case sci_obj_class: { /* object or class? */
object_t *obj = sm_script_obj_init(&s->seg_manager, s, addr);
object_t *base_obj;
/* Instantiate the superclass, if neccessary */
obj->variables[SCRIPT_SPECIES_SELECTOR] =
- INST_LOOKUP_CLASS(obj->variables[SCRIPT_SPECIES_SELECTOR].offset);
+ INST_LOOKUP_CLASS(obj->variables[SCRIPT_SPECIES_SELECTOR].offset);
base_obj = obj_get(s, obj->variables[SCRIPT_SPECIES_SELECTOR]);
obj->variable_names_nr = base_obj->variables_nr;
obj->base_obj = base_obj->base_obj;
- /* Copy base from species class, as we need its selector IDs */
+ /* Copy base from species class, as we need its selector IDs */
obj->variables[SCRIPT_SUPERCLASS_SELECTOR] =
- INST_LOOKUP_CLASS(obj->variables[SCRIPT_SUPERCLASS_SELECTOR].offset);
+ INST_LOOKUP_CLASS(obj->variables[SCRIPT_SUPERCLASS_SELECTOR].offset);
} /* if object or class */
- break;
+ break;
case sci_obj_pointers: /* A relocation table */
relocation = addr.offset;
break;
@@ -2095,8 +2068,7 @@ void
sm_heap_relocate(seg_manager_t *self, state_t *s, reg_t block);
int
-script_instantiate_sci11(state_t *s, int script_nr)
-{
+script_instantiate_sci11(state_t *s, int script_nr) {
resource_t *script, *heap;
int seg_id;
int heap_start;
@@ -2111,30 +2083,29 @@ script_instantiate_sci11(state_t *s, int script_nr)
if (script->size & 2)
heap_start ++;
- sm_mcpy_in_out( &s->seg_manager, 0, script->data, script->size, seg_id, SEG_ID);
- sm_mcpy_in_out( &s->seg_manager, heap_start, heap->data, heap->size, seg_id, SEG_ID);
+ sm_mcpy_in_out(&s->seg_manager, 0, script->data, script->size, seg_id, SEG_ID);
+ sm_mcpy_in_out(&s->seg_manager, heap_start, heap->data, heap->size, seg_id, SEG_ID);
- if (getUInt16(script->data+6) > 0)
+ if (getUInt16(script->data + 6) > 0)
sm_set_export_table_offset(&s->seg_manager, 6,
- seg_id, SEG_ID);
+ seg_id, SEG_ID);
reg.segment = seg_id;
- reg.offset = heap_start+4;
+ reg.offset = heap_start + 4;
sm_script_initialise_locals(&s->seg_manager, reg);
sm_script_relocate_exports_sci11(&s->seg_manager, seg_id);
sm_script_initialise_objects_sci11(&s->seg_manager, s, seg_id);
reg.offset = getUInt16(heap->data);
- sm_heap_relocate(&s->seg_manager, s, reg);
+ sm_heap_relocate(&s->seg_manager, s, reg);
return seg_id;
}
int
-script_instantiate(state_t *s, int script_nr)
-{
- if (s->version >= SCI_VERSION(1,001,000))
+script_instantiate(state_t *s, int script_nr) {
+ if (s->version >= SCI_VERSION(1, 001, 000))
return script_instantiate_sci11(s, script_nr);
else
return script_instantiate_sci0(s, script_nr);
@@ -2143,9 +2114,8 @@ script_instantiate(state_t *s, int script_nr)
void sm_mark_script_deleted(seg_manager_t* self, int script_nr);
void
-script_uninstantiate_sci0(state_t *s, int script_nr, seg_id_t seg)
-{
- reg_t reg = make_reg( seg, (s->version < SCI_VERSION_FTU_NEW_SCRIPT_HEADER)? 2 : 0 );
+script_uninstantiate_sci0(state_t *s, int script_nr, seg_id_t seg) {
+ reg_t reg = make_reg(seg, (s->version < SCI_VERSION_FTU_NEW_SCRIPT_HEADER) ? 2 : 0);
int objtype, objlength;
/* Make a pass over the object in order uninstantiate all superclasses */
@@ -2153,9 +2123,9 @@ script_uninstantiate_sci0(state_t *s, int script_nr, seg_id_t seg)
do {
reg.offset += objlength; /* Step over the last checked object */
-
+
objtype = SEG_GET_HEAP(s, reg);
- if( !objtype ) break;
+ if (!objtype) break;
objlength = SEG_GET_HEAP(s, make_reg(reg.segment, reg.offset + 2)); /* use SEG_UGET_HEAP ?? */
reg.offset += 4; /* Step over header */
@@ -2171,8 +2141,8 @@ script_uninstantiate_sci0(state_t *s, int script_nr, seg_id_t seg)
int superclass_script = s->classtable[superclass].script;
if (superclass_script == script_nr) {
- if( sm_get_lockers( &s->seg_manager, reg.segment, SEG_ID) )
- sm_decrement_lockers( &s->seg_manager, reg.segment, SEG_ID); /* Decrease lockers if this is us ourselves */
+ if (sm_get_lockers(&s->seg_manager, reg.segment, SEG_ID))
+ sm_decrement_lockers(&s->seg_manager, reg.segment, SEG_ID); /* Decrease lockers if this is us ourselves */
} else
script_uninstantiate(s, superclass_script);
/* Recurse to assure that the superclass lockers number gets decreased */
@@ -2187,22 +2157,21 @@ script_uninstantiate_sci0(state_t *s, int script_nr, seg_id_t seg)
}
void
-script_uninstantiate(state_t *s, int script_nr)
-{
- reg_t reg = make_reg( 0, (s->version < SCI_VERSION_FTU_NEW_SCRIPT_HEADER)? 2 : 0 );
+script_uninstantiate(state_t *s, int script_nr) {
+ reg_t reg = make_reg(0, (s->version < SCI_VERSION_FTU_NEW_SCRIPT_HEADER) ? 2 : 0);
int i;
- reg.segment = sm_seg_get( &s->seg_manager, script_nr);
+ reg.segment = sm_seg_get(&s->seg_manager, script_nr);
- if (!sm_script_is_loaded (&s->seg_manager, script_nr, SCRIPT_ID) || reg.segment <= 0 ) { /* Is it already loaded? */
+ if (!sm_script_is_loaded(&s->seg_manager, script_nr, SCRIPT_ID) || reg.segment <= 0) { /* Is it already loaded? */
/* sciprintf("Warning: unloading script 0x%x requested although not loaded\n", script_nr); */
/* This is perfectly valid SCI behaviour */
return;
}
- sm_decrement_lockers( &s->seg_manager, reg.segment, SEG_ID); /* One less locker */
+ sm_decrement_lockers(&s->seg_manager, reg.segment, SEG_ID); /* One less locker */
- if( sm_get_lockers( &s->seg_manager, reg.segment, SEG_ID) > 0 )
+ if (sm_get_lockers(&s->seg_manager, reg.segment, SEG_ID) > 0)
return;
/* Free all classtable references to this script */
@@ -2210,17 +2179,17 @@ script_uninstantiate(state_t *s, int script_nr)
if (s->classtable[i].reg.segment == reg.segment)
s->classtable[i].reg = NULL_REG;
- if (s->version < SCI_VERSION(1,001,000))
+ if (s->version < SCI_VERSION(1, 001, 000))
script_uninstantiate_sci0(s, script_nr, reg.segment);
else
sciprintf("FIXME: Add proper script uninstantiation for SCI 1.1\n");
- if( sm_get_lockers( &s->seg_manager, reg.segment, SEG_ID) )
+ if (sm_get_lockers(&s->seg_manager, reg.segment, SEG_ID))
return; /* if xxx.lockers > 0 */
- /* Otherwise unload it completely */
- /* Explanation: I'm starting to believe that this work is done by SCI itself. */
- sm_mark_script_deleted( &s->seg_manager, script_nr );
+ /* Otherwise unload it completely */
+ /* Explanation: I'm starting to believe that this work is done by SCI itself. */
+ sm_mark_script_deleted(&s->seg_manager, script_nr);
if (script_checkloads_flag)
sciprintf("Unloaded script 0x%x.\n", script_nr);
@@ -2230,20 +2199,18 @@ script_uninstantiate(state_t *s, int script_nr)
static void
-_init_stack_base_with_selector(state_t *s, selector_t selector)
-{
+_init_stack_base_with_selector(state_t *s, selector_t selector) {
s->stack_base[0] = make_reg(0, (word) selector);
s->stack_base[1] = NULL_REG;
}
static state_t *
-_game_run(state_t *s, int restoring)
-{
+_game_run(state_t *s, int restoring) {
state_t *successor = NULL;
int game_is_finished = 0;
do {
s->execution_stack_pos_changed = 0;
- run_vm(s, (successor || restoring)? 1 : 0);
+ run_vm(s, (successor || restoring) ? 1 : 0);
if (s->restarting_flags & SCI_GAME_IS_RESTARTING_NOW) { /* Restart was requested? */
sci_free(s->execution_stack);
@@ -2260,14 +2227,13 @@ _game_run(state_t *s, int restoring)
/* Call the play selector */
send_selector(s, s->game_obj, s->game_obj,
- s->stack_base, 2, s->stack_base);
+ s->stack_base, 2, s->stack_base);
script_abort_flag = 0;
s->restarting_flags = SCI_GAME_WAS_RESTARTED |
- SCI_GAME_WAS_RESTARTED_AT_LEAST_ONCE;
+ SCI_GAME_WAS_RESTARTED_AT_LEAST_ONCE;
- }
- else {
+ } else {
successor = s->successor;
if (successor) {
game_exit(s);
@@ -2277,18 +2243,18 @@ _game_run(state_t *s, int restoring)
if (!send_calls_allocated)
send_calls = (calls_struct_t*)sci_calloc(sizeof(calls_struct_t),
- send_calls_allocated = 16);
+ send_calls_allocated = 16);
if (script_abort_flag == SCRIPT_ABORT_WITH_REPLAY) {
sciprintf("Restarting with replay()\n");
s->execution_stack_pos = -1; /* Resatart with replay */
-
+
_init_stack_base_with_selector(s, s->selector_map.replay);
/* Call the replay selector */
send_selector(s, s->game_obj, s->game_obj,
- s->stack_base, 2,
- s->stack_base);
+ s->stack_base, 2,
+ s->stack_base);
}
script_abort_flag = 0;
@@ -2304,18 +2270,17 @@ _game_run(state_t *s, int restoring)
int objinfo(state_t *s, reg_t pos);
int
-game_run(state_t **_s)
-{
+game_run(state_t **_s) {
state_t *s = *_s;
sciprintf(" Calling %s::play()\n", s->game_name);
_init_stack_base_with_selector(s, s->selector_map.play); /* Call the play selector */
-
+
/* Now: Register the first element on the execution stack- */
if (!send_selector(s, s->game_obj, s->game_obj,
- s->stack_base, 2,
- s->stack_base) || script_error_flag) {
+ s->stack_base, 2,
+ s->stack_base) || script_error_flag) {
objinfo(s, s->game_obj);
sciprintf("Failed to run the game! Aborting...\n");
return 1;
@@ -2328,8 +2293,7 @@ game_run(state_t **_s)
}
int
-game_restore(state_t **_s, char *game_name)
-{
+game_restore(state_t **_s, char *game_name) {
state_t *s;
int debug_state = _debugstate_valid;
@@ -2345,13 +2309,13 @@ game_restore(state_t **_s, char *game_name)
s->restarting_flags = 0;
s->execution_stack_pos = -1; /* Resatart with replay */
-
+
_init_stack_base_with_selector(s, s->selector_map.replay);
/* Call the replay selector */
send_selector(s, s->game_obj, s->game_obj,
- s->stack_base, 2,
- s->stack_base);
+ s->stack_base, 2,
+ s->stack_base);
*_s = s = _game_run(s, 1);
@@ -2361,20 +2325,19 @@ game_restore(state_t **_s, char *game_name)
object_t *
-obj_get(state_t *s, reg_t offset)
-{
+obj_get(state_t *s, reg_t offset) {
mem_obj_t *memobj = GET_OBJECT_SEGMENT(s->seg_manager, offset.segment);
object_t *obj = NULL;
int idx;
if (memobj != NULL) {
if (memobj->type == MEM_OBJ_CLONES
- && ENTRY_IS_VALID(&memobj->data.clones, offset.offset))
+ && ENTRY_IS_VALID(&memobj->data.clones, offset.offset))
obj = &(memobj->data.clones.table[offset.offset].entry);
else if (memobj->type == MEM_OBJ_SCRIPT) {
if (offset.offset <= memobj->data.script.buf_size
- && offset.offset >= -SCRIPT_OBJECT_MAGIC_OFFSET
- && RAW_IS_OBJECT(memobj->data.script.buf + offset.offset)) {
+ && offset.offset >= -SCRIPT_OBJECT_MAGIC_OFFSET
+ && RAW_IS_OBJECT(memobj->data.script.buf + offset.offset)) {
idx = RAW_GET_CLASS_INDEX(&(memobj->data.script), offset);
if (idx >= 0 && idx < memobj->data.script.objects_nr)
obj = memobj->data.script.objects + idx;
@@ -2386,21 +2349,19 @@ obj_get(state_t *s, reg_t offset)
}
const char *
-obj_get_name(struct _state *s, reg_t pos)
-{
+obj_get_name(struct _state *s, reg_t pos) {
object_t *obj = obj_get(s, pos);
if (!obj)
return "<no such object>";
return
- (const char*)(obj->base + obj->variables[SCRIPT_NAME_SELECTOR].offset);
+ (const char*)(obj->base + obj->variables[SCRIPT_NAME_SELECTOR].offset);
}
void
-quit_vm()
-{
+quit_vm() {
script_abort_flag = 1; /* Terminate VM */
_debugstate_valid = 0;
_debug_seeking = 0;