CHook_Run(struct core_entry_t *entry, const char *format, ...)
{
va_list argp;
+ /* Environment Saving */
+ char *preserve_wnxt[10], *preserve_rnxt[NUMQ];
+ char *val_wnxt[10], *val_rnxt[NUMQ];
+ char *preserves[10], *preserveq[NUMQ];
+ HASHTAB preserve_namedregs;
+ char save_ccom[BUFFER_LEN];
+ /* */
int rval;
int (*module_func) (struct core_entry_t * entry, va_list argp);
module_func = NULL; /* Just for initialization purposes */
va_start(argp, format);
if (entry->flags & MODHOOK_SOFTCODE) {
+ /* Step 1: Save Environment */
+ save_global_nxt("chook_sc_save", preserve_wnxt, preserve_rnxt, val_wnxt,
+ val_rnxt);
+ save_global_regs("chook_sc_save", preserveq);
+ save_global_env("chook_sc_save", preserves);
+ init_namedregs(&preserve_namedregs);
+ copy_namedregs(&preserve_namedregs, &global_eval_context.namedregs);
+ clear_namedregs(&global_eval_context.namedregs);
+ init_namedregs(&global_eval_context.namedregs);
+ strncpy(save_ccom, global_eval_context.ccom, BUFFER_LEN);
+ /* Step 2: Call the Softcode Hook */
rval = CHook_SC(entry, format, argp);
va_end(argp);
+ /* Step 3: Restore the Environment */
+ memset(global_eval_context.ccom, '\0', BUFFER_LEN);
+ strcpy(global_eval_context.ccom, save_ccom);
+ clear_namedregs(&global_eval_context.namedregs);
+ init_namedregs(&global_eval_context.namedregs);
+ copy_namedregs(&global_eval_context.namedregs, &preserve_namedregs);
+ clear_namedregs(&preserve_namedregs);
+ restore_global_regs("chook_sc_save", preserveq);
+ restore_global_env("chook_sc_save", preserves);
+ restore_global_nxt("chook_sc_save", preserve_wnxt, preserve_rnxt,
+ val_wnxt, val_rnxt);
+
} else if (entry->flags & MODHOOK_MODULE) {
/* We'll do this code later */
va_end(argp);
int
CHook_SC(struct core_entry_t *entry, const char *format, va_list arguments)
{
- /* Register Saving */
- char *preserve_wnxt[10], *preserve_rnxt[NUMQ];
- char *val_wnxt[10], *val_rnxt[NUMQ];
- char *preserves[10], *preserveq[NUMQ];
- HASHTAB preserve_namedregs;
- /* */
- struct softcode_hook *sc_hook;
+ struct softcode_hook *sc_hook;
const char *s, *fptr;
char cmd_buf[BUFFER_LEN], tbuf[BUFFER_LEN];
char *r;
int break_count, spot = 0;
sc_hook = (struct softcode_hook *) entry->data;
- strcpy(global_eval_context.ccom, "");
/* Before we bother with va_list .. Make sure A) Its a good object, B) Its a good attribute */
if (!GoodObject(sc_hook->obj))
atr = atr_get(sc_hook->obj, sc_hook->attribute);
if (!atr)
return -1;
- /* Save Environment */
- save_global_nxt("chook_sc_save", preserve_wnxt, preserve_rnxt, val_wnxt,
- val_rnxt);
- save_global_regs("chook_sc_save", preserveq);
- save_global_env("chook_sc_save", preserves);
- init_namedregs(&preserve_namedregs);
- copy_namedregs(&preserve_namedregs, &global_eval_context.namedregs);
- clear_namedregs(&global_eval_context.namedregs);
- enactor = executor = cause = sc_hook->obj;
+ enactor = executor = cause = sc_hook->obj;
/* Ok.. Now that we haev all the info we need we need to build a parse_que with 0-10 being the args passed */
for (fptr = format; fptr && *fptr; fptr++) {
"%s:%d -> Unexpected format character '%c' in format \"%s\"",
__FILE__, __LINE__, *fptr, format);
/* Restore Environment */
- copy_namedregs(&global_eval_context.namedregs, &preserve_namedregs);
- free_namedregs(&preserve_namedregs);
- restore_global_regs("chook_sc_save", preserveq);
- restore_global_env("chook_sc_save", preserves);
- restore_global_nxt("chook_sc_save", preserve_wnxt, preserve_rnxt,
- val_wnxt, val_rnxt);
-
return -2;
}
}
ooref = local_ooref;
}
reset_cpu_timer();
- /* Restore Environment */
- copy_namedregs(&global_eval_context.namedregs, &preserve_namedregs);
- free_namedregs(&preserve_namedregs);
- restore_global_regs("chook_sc_save", preserveq);
- restore_global_env("chook_sc_save", preserves);
- restore_global_nxt("chook_sc_save", preserve_wnxt, preserve_rnxt,
- val_wnxt, val_rnxt);
- return 1;
+ return 1;
}