From 44984f46aa6fdc81fe8e5af29e09c9c624d864c5 Mon Sep 17 00:00:00 2001 From: jaortega Date: Thu, 15 Mar 2001 17:26:39 +0000 Subject: 0.3 pre-release --- mixlib/mix_vm_command.c | 171 +++++++++++++++++++++++++++++------------------- mixlib/mix_vm_command.h | 5 +- 2 files changed, 106 insertions(+), 70 deletions(-) (limited to 'mixlib') diff --git a/mixlib/mix_vm_command.c b/mixlib/mix_vm_command.c index 90283f0..9cc0d52 100644 --- a/mixlib/mix_vm_command.c +++ b/mixlib/mix_vm_command.c @@ -1,7 +1,7 @@ /* -*-c-*- -------------- mix_vm_command.c : * Implementation of the functions declared in mix_vm_command.h * ------------------------------------------------------------------ - * Last change: Time-stamp: "01/03/11 01:50:17 jose" + * Last change: Time-stamp: "01/03/15 15:57:52 jose" * ------------------------------------------------------------------ * Copyright (C) 2001 Free Software Foundation, Inc. * @@ -48,6 +48,7 @@ typedef struct struct mix_vm_cmd_dispatcher_t { mix_vm_t *vm; /* the virtual machine */ + gboolean result; /* last command's outcome */ gchar *program; /* the name of the last loaded program */ FILE *out; /* message output file */ FILE *err; /* error output file */ @@ -65,7 +66,7 @@ struct mix_vm_cmd_dispatcher_t }; /* command handlers */ -typedef int (*Function_)(mix_vm_cmd_dispatcher_t *, const gchar *); +typedef gboolean (*Function_)(mix_vm_cmd_dispatcher_t *, const gchar *); #define DEC_FUN(name) \ static int cmd_##name (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) @@ -189,6 +190,7 @@ mix_vm_cmd_dispatcher_new (FILE *out_fd, /* output messages file */ g_return_val_if_fail (out_fd && err_fd, NULL); result = g_new (mix_vm_cmd_dispatcher_t, 1); + result->result = TRUE; result->out = out_fd; result->err = err_fd; result->uptime = result->laptime = result->progtime = 0; @@ -270,7 +272,6 @@ gboolean /* TRUE if success, FALSE otherwise */ mix_vm_cmd_dispatcher_dispatch (mix_vm_cmd_dispatcher_t *dis, mix_vm_command_t cmd, const gchar *arg) { - gboolean result = FALSE; g_return_val_if_fail (dis != NULL, FALSE); if (dis->global_pre.func) @@ -280,7 +281,7 @@ mix_vm_cmd_dispatcher_dispatch (mix_vm_cmd_dispatcher_t *dis, { if (dis->pre_hooks[cmd].func) (dis->pre_hooks[cmd].func)(dis, arg, dis->pre_hooks[cmd].data); - result = (commands_[cmd].func)(dis, arg); + dis->result = (commands_[cmd].func)(dis, arg); if (dis->post_hooks[cmd].func) (dis->post_hooks[cmd].func)(dis, arg, dis->post_hooks[cmd].data); } @@ -294,7 +295,7 @@ mix_vm_cmd_dispatcher_dispatch (mix_vm_cmd_dispatcher_t *dis, fflush (dis->out); fflush (dis->err); - return result; + return dis->result; } /* dispatch a command in text format */ @@ -325,6 +326,14 @@ mix_vm_cmd_dispatcher_dispatch_text (mix_vm_cmd_dispatcher_t *dis, return result; } +/* get the last dispatch's result */ +gboolean +mix_vm_cmd_dispatcher_get_last_result (const mix_vm_cmd_dispatcher_t *dis) +{ + g_return_val_if_fail (dis != NULL, FALSE); + return dis->result; +} + /* get total uptime */ mix_time_t mix_vm_cmd_dispatcher_get_uptime (const mix_vm_cmd_dispatcher_t *dis) @@ -421,7 +430,7 @@ print_time_ (mix_vm_cmd_dispatcher_t *dis) /* commands */ -static int +static gboolean cmd_help_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) { static const int NO_OF_COLS = 6; @@ -462,14 +471,14 @@ cmd_help_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) return TRUE; } -static int +static gboolean cmd_load_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) { errno = 0; if (arg == NULL || *arg == '\0') { fputs (_("Missing file name\n"), dis->err); - return TRUE; + return FALSE; } mix_eval_remove_symbols_from_table (dis->eval, mix_vm_get_symbol_table (dis->vm)); @@ -479,8 +488,8 @@ cmd_load_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) if ( errno == 0 ) fputs (_("Wrong file format\n"), dis->err); else - perror (NULL); - return TRUE + 1; + fprintf (dis->err, "%s\n", strerror (errno)); + return FALSE; } if (dis->program != arg) @@ -500,11 +509,11 @@ cmd_load_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) } -static int +static gboolean cmd_run_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) { if (arg != NULL && *arg != '\0' && cmd_load_ (dis, arg) != TRUE) - return TRUE; + return FALSE; if (mix_vm_is_halted (dis->vm)) cmd_load_ (dis, dis->program); @@ -539,7 +548,7 @@ cmd_run_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) return TRUE; } -static int +static gboolean cmd_next_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) { int ins_no = 1; @@ -553,7 +562,8 @@ cmd_next_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) if (arg[k] != '\0') { fprintf (dis->err, _("Invalid argument: %s\n"), arg); - return cmd_help_ (dis, "next"); + cmd_help_ (dis, "next"); + return FALSE; } ins_no = atoi (arg); } @@ -582,16 +592,17 @@ cmd_next_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) return TRUE; } -static int +static gboolean cmd_pc_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) { fprintf (dis->out, "Current address: %d\n", mix_vm_get_prog_count (dis->vm)); return TRUE; } -static int +static gboolean cmd_psym_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) { + gboolean result = FALSE; const mix_symbol_table_t *table = mix_eval_symbol_table (dis->eval); if ( table == NULL ) fputs (_("Symbol table not available\n"), dis->err); @@ -601,17 +612,21 @@ cmd_psym_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) { mix_word_print (mix_symbol_table_value (table, arg), NULL); putc ('\n', dis->out); + result = TRUE; } else fprintf (dis->out, _("%s: symbol not defined\n"), arg); } else - mix_symbol_table_print (table, MIX_SYM_ROWS, stdout, TRUE); + { + mix_symbol_table_print (table, MIX_SYM_ROWS, stdout, TRUE); + result = TRUE; + } - return TRUE; + return result; } -static int +static gboolean cmd_preg_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) { mix_dump_context_set_opt (dis->dump, MIX_DUMP_NONE); @@ -642,7 +657,7 @@ cmd_preg_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) if ( i < 0 || i > 5 ) { fprintf (dis->err, _("Invalid I index: %d"), i); - return TRUE; + return FALSE; } mix_dump_context_add_opt (dis->dump, opt[i]); } @@ -650,13 +665,13 @@ cmd_preg_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) break; default: fprintf (dis->err, _("Invalid argument: %s\n"), arg); - return TRUE; + return FALSE; } mix_vm_dump (dis->vm, dis->dump); return TRUE; } -static int +static gboolean cmd_pflags_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) { mix_dump_context_set_opt (dis->dump, MIX_DUMP_CMP | MIX_DUMP_OVER); @@ -664,7 +679,7 @@ cmd_pflags_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) return TRUE; } -static int +static gboolean cmd_pall_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) { mix_dump_context_set_opt (dis->dump, MIX_DUMP_ALL_NOMEM); @@ -672,7 +687,7 @@ cmd_pall_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) return TRUE; } -static int +static gboolean cmd_pmem_ (mix_vm_cmd_dispatcher_t *dis, const gchar *carg) { glong begin = MIX_SHORT_ZERO, end = MIX_SHORT_ZERO; @@ -683,7 +698,7 @@ cmd_pmem_ (mix_vm_cmd_dispatcher_t *dis, const gchar *carg) if ( strlen (carg) == 0 ) { fputs (_("Missing memory address\n"), dis->err); - return TRUE; + return FALSE; } arg = g_strdup (carg); while (isdigit (arg[i])) @@ -718,6 +733,7 @@ cmd_pmem_ (mix_vm_cmd_dispatcher_t *dis, const gchar *carg) else if ( end < begin || end > MIX_VM_CELL_NO - 1 ) { fprintf (dis->err, _("Invalid range: %ld-%ld\n"), begin, end); + error = TRUE; } else { @@ -727,10 +743,10 @@ cmd_pmem_ (mix_vm_cmd_dispatcher_t *dis, const gchar *carg) mix_vm_dump (dis->vm, dis->dump); } g_free (arg); - return TRUE; + return !error; } -static int +static gboolean cmd_sreg_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) { int i = 0; @@ -785,10 +801,10 @@ cmd_sreg_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) cmd_help_ (dis, "sreg"); } - return TRUE; + return ok; } -static int +static gboolean cmd_scmp_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) { gboolean ok = (strlen (arg) == 1); @@ -812,10 +828,10 @@ cmd_scmp_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) cmd_help_ (dis, "scmp"); } - return TRUE; + return ok; } -static int +static gboolean cmd_sover_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) { gboolean ok = (strlen (arg) == 1); @@ -836,10 +852,10 @@ cmd_sover_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) cmd_help_ (dis, "sover"); } - return TRUE; + return ok; } -static int +static gboolean cmd_smem_ (mix_vm_cmd_dispatcher_t *dis, const gchar *carg) { gboolean ok = (strlen (carg) > 2 && isdigit (carg[0])); @@ -879,16 +895,17 @@ cmd_smem_ (mix_vm_cmd_dispatcher_t *dis, const gchar *carg) } g_free (arg); - return TRUE; + return ok; } -static int +static gboolean cmd_ssym_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) { + gboolean result = FALSE; if (arg == NULL || strlen(arg) == 0) { fprintf (dis->err, _("Missing arguments\n")); - return cmd_help_ (dis, "ssym"); + cmd_help_ (dis, "ssym"); } else { @@ -898,8 +915,10 @@ cmd_ssym_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) if (w != NULL && strtok (NULL, " \t") == NULL) { cmd_weval_ (dis, w); - if (mix_eval_last_error (dis->eval) == MIX_EVAL_OK) + if (mix_eval_last_error (dis->eval) == MIX_EVAL_OK) { mix_eval_set_symbol (dis->eval, s, mix_eval_value (dis->eval)); + result = TRUE; + } } else { @@ -907,11 +926,11 @@ cmd_ssym_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) cmd_help_ (dis, "ssym"); } g_free (a); - return TRUE; } + return result; } -static int +static gboolean cmd_sbp_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) { glong lineno; @@ -920,7 +939,8 @@ cmd_sbp_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) if (arg[k] != '\0') { fprintf (dis->err, _("Invalid argument: %s\n"), arg); - return cmd_help_ (dis, "sbp"); + cmd_help_ (dis, "sbp"); + return FALSE; } lineno = atol (arg); switch (k = mix_vm_set_breakpoint (dis->vm, lineno)) @@ -937,12 +957,12 @@ cmd_sbp_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) break; default: fprintf (dis->err, _("Breakpoint set at line %ld\n"), k); - break; + return TRUE; } - return TRUE; + return FALSE; } -static int +static gboolean cmd_sbpa_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) { glong address; @@ -951,7 +971,8 @@ cmd_sbpa_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) if (arg[k] != '\0') { fprintf (dis->err, _("Invalid argument: %s\n"), arg); - return cmd_help_ (dis, "sbpa"); + cmd_help_ (dis, "sbpa"); + return FALSE; } address = atol (arg); switch (mix_vm_set_breakpoint_address (dis->vm, address)) @@ -964,12 +985,12 @@ cmd_sbpa_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) break; default: fprintf (dis->err, _("Breakpoint set at address %ld\n"), address); - break; + return TRUE; } - return TRUE; + return FALSE; } -static int +static gboolean cmd_cbp_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) { glong lineno; @@ -978,7 +999,8 @@ cmd_cbp_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) if (arg[k] != '\0') { fprintf (dis->err, _("Invalid argument: %s\n"), arg); - return cmd_help_ (dis, "cbp"); + cmd_help_ (dis, "cbp"); + return FALSE; } lineno = atol (arg); switch (mix_vm_clear_breakpoint (dis->vm, lineno)) @@ -994,15 +1016,15 @@ cmd_cbp_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) break; case MIX_VM_BP_OK: fprintf (dis->err, _("Breakpoint cleared at line %ld\n"), lineno); - break; + return TRUE; default: g_assert_not_reached (); break; } - return TRUE; + return FALSE; } -static int +static gboolean cmd_cbpa_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) { glong address; @@ -1011,7 +1033,8 @@ cmd_cbpa_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) if (arg[k] != '\0') { fprintf (dis->err, _("Invalid argument: %s\n"), arg); - return cmd_help_ (dis, "cbpa"); + cmd_help_ (dis, "cbpa"); + return FALSE; } address = atol (arg); switch (mix_vm_clear_breakpoint_address (dis->vm, address)) @@ -1024,36 +1047,41 @@ cmd_cbpa_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) break; default: fprintf (dis->err, _("Breakpoint cleared at address %ld\n"), address); - break; + return TRUE; } - return TRUE; + return FALSE; } -static int +static gboolean cmd_cabp_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) { if (strlen (arg) != 0) { fprintf (dis->err, _("Invalid argument: %s\n"), arg); - return cmd_help_ (dis, "cabp"); + cmd_help_ (dis, "cabp"); + return FALSE; } mix_vm_clear_all_breakpoints (dis->vm); return TRUE; } -static int +static gboolean cmd_weval_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) { if ( strlen (arg) == 0 ) - return cmd_help_ (dis, "weval"); - + { + cmd_help_ (dis, "weval"); + return FALSE; + } + if (mix_eval_expression_with_loc (dis->eval, arg, mix_vm_get_prog_count (dis->vm)) == MIX_EVAL_OK) { mix_word_print_to_file (mix_eval_value (dis->eval), NULL, dis->out); putc ('\n', dis->out); + return TRUE; } else { @@ -1066,16 +1094,18 @@ cmd_weval_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) for (k = pos; k < len; ++k) fputc (arg[k], dis->err); fprintf (dis->err, _("\nEvaluation error: %s\n"), mix_eval_last_error_string (dis->eval)); + return FALSE; } - - return TRUE; } -static int +static gboolean cmd_w2d_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) { if ( strlen (arg) == 0 ) - return cmd_help_ (dis, "w2d"); + { + cmd_help_ (dis, "w2d"); + return FALSE; + } else { gchar *cp = g_strdup (arg), *a = cp; @@ -1102,8 +1132,11 @@ cmd_w2d_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) if (success) { if (strtok (NULL, "\t") != NULL) - fprintf (dis->err, _("The expression %s does not fit in a word\n"), - arg); + { + fprintf (dis->err, + _("The expression %s does not fit in a word\n"), arg); + success = FALSE; + } else { mix_word_t w = mix_bytes_to_word (bytes, k); @@ -1112,12 +1145,12 @@ cmd_w2d_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) } } g_free (cp); - } - return TRUE; + return success; + } } -static int +static gboolean cmd_tron_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) { dis->trace = TRUE; @@ -1125,7 +1158,7 @@ cmd_tron_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) return TRUE; } -static int +static gboolean cmd_troff_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) { dis->trace = FALSE; diff --git a/mixlib/mix_vm_command.h b/mixlib/mix_vm_command.h index a805e68..856c2d5 100644 --- a/mixlib/mix_vm_command.h +++ b/mixlib/mix_vm_command.h @@ -1,7 +1,7 @@ /* -*-c-*- ---------------- mix_vm_command.h : * declarations for mix_vm_command_t, describing commands issued to a vm * ------------------------------------------------------------------ - * Last change: Time-stamp: <01/03/09 21:53:43 jose> + * Last change: Time-stamp: <01/03/15 15:57:36 jose> * ------------------------------------------------------------------ * Copyright (C) 2001 Free Software Foundation, Inc. * @@ -107,6 +107,9 @@ extern gboolean mix_vm_cmd_dispatcher_dispatch_text (mix_vm_cmd_dispatcher_t *dis, const gchar *text); +/* get the last dispatch's result */ +extern gboolean +mix_vm_cmd_dispatcher_get_last_result (const mix_vm_cmd_dispatcher_t *dis); /* get total uptime */ extern mix_time_t -- cgit v1.2.3