Interactive task calls take string arguments.

This commit is contained in:
steve 2003-02-24 06:35:45 +00:00
parent 7f8433148c
commit 70daee399f
3 changed files with 97 additions and 17 deletions

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: stop.cc,v 1.3 2003/02/23 06:41:54 steve Exp $"
#ident "$Id: stop.cc,v 1.4 2003/02/24 06:35:45 steve Exp $"
#endif
/*
@ -60,13 +60,17 @@ static void cmd_call(unsigned argc, char*argv[])
ntable = stop_current_scope->nintern;
}
/* This is an array of vpiHandles, for passing to the created
command. */
unsigned vpi_argc = argc - 1;
vpiHandle*vpi_argv = (vpiHandle*)calloc(vpi_argc, sizeof(vpiHandle));
vpiHandle*vpi_free = (vpiHandle*)calloc(vpi_argc, sizeof(vpiHandle));
unsigned errors = 0;
for (unsigned idx = 0 ; idx < vpi_argc ; idx += 1) {
vpiHandle handle = 0;
bool add_to_free_list = false;
/* Detect the special case that the argument is the
.(dot) string. This represents the handle for the
@ -74,6 +78,18 @@ static void cmd_call(unsigned argc, char*argv[])
if (stop_current_scope && (strcmp(argv[idx+1], ".") == 0))
handle = &stop_current_scope->base;
if (argv[idx+1][0] == '"') {
char*tmp = strdup(argv[idx+1]);
tmp[strlen(tmp)-1] = 0;
/* Create a temporary vpiStringConst to pass as a
handle. Make it temporary so that memory is
reclaimed after the call is completed. */
handle = vpip_make_string_const(strdup(tmp+1), false);
add_to_free_list = true;
free(tmp);
}
/* Try to find the vpiHandle within this scope that has
the name in argv[idx+2]. Look in the current scope. */
@ -110,6 +126,11 @@ static void cmd_call(unsigned argc, char*argv[])
}
vpi_argv[idx] = handle;
if (add_to_free_list)
vpi_free[idx] = handle;
else
vpi_free[idx] = 0;
}
/* If there are no errors so far, then make up a call to the
@ -118,16 +139,21 @@ static void cmd_call(unsigned argc, char*argv[])
if (errors == 0) {
vpiHandle call_handle = vpip_build_vpi_call(argv[0], 0, 0,
vpi_argc, vpi_argv);
if (call_handle == 0) {
free(vpi_argv);
return;
}
if (call_handle == 0)
goto out;
vpip_execute_vpi_call(0, call_handle);
vpi_free_object(call_handle);
}
out:
for (unsigned idx = 0 ; idx < vpi_argc ; idx += 1) {
if (vpi_free[idx])
vpi_free_object(vpi_free[idx]);
}
free(vpi_argv);
free(vpi_free);
}
static void cmd_cont(unsigned, char*[])
@ -319,9 +345,21 @@ static void invoke_command(char*txt)
; *cp; cp += strspn(cp, " ")) {
argv[argc] = cp;
cp += strcspn(cp, " ");
if (*cp)
*cp++ = 0;
if (cp[0] == '"') {
char*tmp = strchr(cp+1, '"');
if (tmp == 0) {
printf("Missing close-quote: %s\n", cp);
delete[]argv;
return;
}
cp = tmp + 1;
} else {
cp += strcspn(cp, " ");
}
if (*cp) *cp++ = 0;
argc += 1;
}
@ -341,8 +379,8 @@ static void invoke_command(char*txt)
cmd_table[idx].proc (argc, argv);
}
}
}
delete[]argv;
}
@ -358,12 +396,16 @@ void stop_handler(int rc)
if (input == 0)
break;
/* Advance to the first input character. */
char*first = input;
while (*first && isspace(*first))
first += 1;
invoke_command(first);
if (first[0] != 0) {
add_history(first);
invoke_command(first);
}
free(input);
}
@ -373,6 +415,9 @@ void stop_handler(int rc)
/*
* $Log: stop.cc,v $
* Revision 1.4 2003/02/24 06:35:45 steve
* Interactive task calls take string arguments.
*
* Revision 1.3 2003/02/23 06:41:54 steve
* Add to interactive stop mode support for
* current scope, the ability to scan/traverse

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: vpi_const.cc,v 1.21 2002/11/03 20:33:43 steve Exp $"
#ident "$Id: vpi_const.cc,v 1.22 2003/02/24 06:35:45 steve Exp $"
#endif
# include "vpi_priv.h"
@ -148,7 +148,6 @@ static void string_value(vpiHandle ref, p_vpi_value vp)
}
}
static const struct __vpirt vpip_string_rt = {
vpiConstant,
string_get,
@ -159,14 +158,40 @@ static const struct __vpirt vpip_string_rt = {
0
};
static int free_temp_string(vpiHandle obj)
{
struct __vpiStringConst*rfp = (struct __vpiStringConst*)obj;
assert(obj->vpi_type->type_code == vpiConstant);
vpiHandle vpip_make_string_const(char*text)
free(rfp->value);
free(rfp);
return 1;
}
static const struct __vpirt vpip_string_temp_rt = {
vpiConstant,
string_get,
0,
string_value,
0,
0,
0,
0,
free_temp_string
};
vpiHandle vpip_make_string_const(char*text, bool persistent_flag)
{
struct __vpiStringConst*obj;
obj = (struct __vpiStringConst*)
malloc(sizeof (struct __vpiStringConst));
obj->base.vpi_type = &vpip_string_rt;
obj->base.vpi_type = persistent_flag
? &vpip_string_rt
: &vpip_string_temp_rt;
obj->value = text;
return &obj->base;
@ -557,6 +582,9 @@ vpiHandle vpip_make_dec_const(int value)
/*
* $Log: vpi_const.cc,v $
* Revision 1.22 2003/02/24 06:35:45 steve
* Interactive task calls take string arguments.
*
* Revision 1.21 2002/11/03 20:33:43 steve
* Compiler error wrt ptrdiff_t.
*

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: vpi_priv.h,v 1.49 2003/02/23 06:41:54 steve Exp $"
#ident "$Id: vpi_priv.h,v 1.50 2003/02/24 06:35:45 steve Exp $"
#endif
# include "vpi_user.h"
@ -262,13 +262,17 @@ extern struct __vpiSysTaskCall*vpip_cur_task;
/*
* These are implemented in vpi_const.cc. These are vpiHandles for
* constants.
*
* The persistent flag to vpip_make_string_const causes the created
* handle to be persistent. This is necessary for cases where the
* string handle may be reused, which is the normal case.
*/
struct __vpiStringConst {
struct __vpiHandle base;
const char*value;
char*value;
};
vpiHandle vpip_make_string_const(char*text);
vpiHandle vpip_make_string_const(char*text, bool persistent =true);
struct __vpiBinaryConst {
struct __vpiHandle base;
@ -399,6 +403,9 @@ extern char *need_result_buf(unsigned cnt, vpi_rbuf_t type);
/*
* $Log: vpi_priv.h,v $
* Revision 1.50 2003/02/24 06:35:45 steve
* Interactive task calls take string arguments.
*
* Revision 1.49 2003/02/23 06:41:54 steve
* Add to interactive stop mode support for
* current scope, the ability to scan/traverse