diff options
author | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2001-07-06 22:28:51 +0000 |
---|---|---|
committer | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2001-07-06 22:28:51 +0000 |
commit | d23c118143cb68b290398c946c552c92cfa8a8ec (patch) | |
tree | 2a4d9c25ef4713e2eba42b2937ddd1f0195cb77d | |
parent | 74342aaaa7bf55eddd07f19453f8b75902c07aa1 (diff) | |
download | mdk-d23c118143cb68b290398c946c552c92cfa8a8ec.tar.gz mdk-d23c118143cb68b290398c946c552c92cfa8a8ec.tar.bz2 |
(mix_vm_cmd_dispatcher_new_with_config) new constructor
tron/troff substituted by trace on|off
-rw-r--r-- | mixlib/mix_vm_command.c | 66 | ||||
-rw-r--r-- | mixlib/mix_vm_command.h | 12 |
2 files changed, 56 insertions, 22 deletions
diff --git a/mixlib/mix_vm_command.c b/mixlib/mix_vm_command.c index e6f7e79..b3156c2 100644 --- a/mixlib/mix_vm_command.c +++ b/mixlib/mix_vm_command.c @@ -65,6 +65,7 @@ struct mix_vm_cmd_dispatcher_t hook_ post_hooks[MIX_CMD_INVALID]; /* Post-command hooks */ global_hook_ global_pre; /* global pre-command hook */ global_hook_ global_post; /* global post-command hook */ + mix_config_t *config; /* externally provided configuration */ }; /* command handlers */ @@ -94,8 +95,7 @@ DEC_FUN (cbpa_); DEC_FUN (cabp_); DEC_FUN (weval_); DEC_FUN (w2d_); -DEC_FUN (tron_); -DEC_FUN (troff_); +DEC_FUN (trace_); DEC_FUN (edit_); DEC_FUN (compile_); @@ -145,11 +145,16 @@ command_ commands_[] = { { "weval", cmd_weval_, N_("Evaluate a given W-expression"), "weval WEXPR"}, { "w2d", cmd_w2d_, N_("Convert a MIX word to its decimal value"), "w2d WORD"}, - { "tron", cmd_tron_, N_("Turn on instruction tracing."), "tron"}, - { "troff", cmd_troff_, N_("Turn off instruction tracing."), "troff"}, + { "trace", cmd_trace_, N_("Turn on/off instruction tracing."), + "trace on|off"}, { NULL, NULL, NULL, NULL}, }; +/* configuration keys */ +static const gchar *TRACE_KEY_ = "Trace"; +static const gchar *EDITOR_KEY_ = "Editor"; +static const gchar *ASM_KEY_ = "Assembler"; + /* external interface */ @@ -218,9 +223,28 @@ mix_vm_cmd_dispatcher_new (FILE *out_fd, /* output messages file */ result->pre_hooks[k].func = result->post_hooks[k].func = NULL; result->pre_hooks[k].data = result->post_hooks[k].data = NULL; } - + result->config = NULL; + + return result; +} + +mix_vm_cmd_dispatcher_t * +mix_vm_cmd_dispatcher_new_with_config (FILE *out, FILE *err, + mix_config_t *config) +{ + mix_vm_cmd_dispatcher_t *result = mix_vm_cmd_dispatcher_new (out, err); + if (result != NULL && (result->config = config) != NULL) + { + const gchar *val = mix_config_get (result->config, TRACE_KEY_); + if (val) cmd_trace_ (result, val); + val = mix_config_get (result->config, EDITOR_KEY_); + if (val) mix_vm_cmd_dispatcher_set_editor (result, val); + val = mix_config_get (result->config, ASM_KEY_); + if (val) mix_vm_cmd_dispatcher_set_assembler (result, val); + } return result; } + /* delete (does not close the fds in the constructor) */ void @@ -243,6 +267,8 @@ mix_vm_cmd_dispatcher_set_editor (mix_vm_cmd_dispatcher_t *dis, g_return_if_fail (dis != NULL); if (dis->editor) g_free (dis->editor); dis->editor = (edit_tplt) ? g_strdup (edit_tplt) : NULL; + if (dis->config && dis->editor) + mix_config_update (dis->config, EDITOR_KEY_, dis->editor); } void @@ -252,6 +278,8 @@ mix_vm_cmd_dispatcher_set_assembler (mix_vm_cmd_dispatcher_t *dis, g_return_if_fail (dis != NULL); if (dis->assembler) g_free (dis->assembler); dis->assembler = (asm_tplt) ? g_strdup (asm_tplt) : NULL; + if (dis->config && dis->assembler) + mix_config_update (dis->config, ASM_KEY_, dis->assembler); } const gchar * @@ -623,8 +651,6 @@ cmd_compile_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) } } - - static gboolean cmd_run_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) { @@ -1269,17 +1295,21 @@ cmd_w2d_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) } static gboolean -cmd_tron_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) -{ - dis->trace = TRUE; - fprintf (dis->out, _("Instruction tracing has been turned ON.\n")); - return TRUE; -} - -static gboolean -cmd_troff_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) +cmd_trace_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) { - dis->trace = FALSE; - fprintf (dis->out, _("Instruction tracing has been turned OFF.\n")); + static const gchar *ON = "on"; + static const gchar *OFF = "off"; + if (arg && !strcmp (arg, ON)) + { + dis->trace = TRUE; + if (dis->config) mix_config_update (dis->config, TRACE_KEY_, ON); + } + else if (arg && !strcmp (arg, OFF)) + { + dis->trace = FALSE; + if (dis->config) mix_config_update (dis->config, TRACE_KEY_, OFF); + } + else + cmd_help_ (dis, "trace"); return TRUE; } diff --git a/mixlib/mix_vm_command.h b/mixlib/mix_vm_command.h index 71e5820..b1c6839 100644 --- a/mixlib/mix_vm_command.h +++ b/mixlib/mix_vm_command.h @@ -28,6 +28,7 @@ #include <stdio.h> #include "mix.h" #include "mix_vm.h" +#include "mix_config.h" /* mix_vm_cmd_dispatcher encapsulates a virtual machine and helper objects, providing a command driven interface with output to @@ -61,8 +62,7 @@ typedef enum { MIX_CMD_CABP, /* clear all breakpoints */ MIX_CMD_WEVAL, /* evaluate a w-expression */ MIX_CMD_W2D, /* print word in decimal notation */ - MIX_CMD_TRON, /* enable instruction traces */ - MIX_CMD_TROFF, /* disble instruction traces */ + MIX_CMD_TRACE, /* enable/disable instruction traces */ MIX_CMD_INVALID, /* invalid command identifier */ } mix_vm_command_t; @@ -92,8 +92,12 @@ mix_vm_command_usage (mix_vm_command_t cmd); /* create a new command dispatcher */ extern mix_vm_cmd_dispatcher_t * -mix_vm_cmd_dispatcher_new (FILE *out_fd, /* output messages file */ - FILE *err_fd /* error messages file */); +mix_vm_cmd_dispatcher_new (FILE *out, /* output messages file */ + FILE *err /* error messages file */); + +extern mix_vm_cmd_dispatcher_t * +mix_vm_cmd_dispatcher_new_with_config (FILE *out, FILE *err, + mix_config_t *config); /* delete (does not close the fds in the constructor) */ extern void |