mirror of
https://github.com/simh/simh.git
synced 2026-01-25 19:56:25 +00:00
SCP: Provide a way to gather input from a user into an environment variable
SET ENV -P "Prompt String" EnvVar=Default
This commit is contained in:
47
scp.c
47
scp.c
@@ -1161,10 +1161,19 @@ static const char simh_help[] =
|
||||
"3Asynch\n"
|
||||
"+set asynch enable asynchronous I/O\n"
|
||||
"+set noasynch disable asynchronous I/O\n"
|
||||
#define HLP_SET_ENVIRON "*Commands SET Asynch"
|
||||
#define HLP_SET_ENVIRON "*Commands SET Environment"
|
||||
"3Environment\n"
|
||||
"4Explicitily Changing A Variable\n"
|
||||
"+set environment name=val set environment variable\n"
|
||||
"+set environment name clear environment variable\n"
|
||||
"4Gathering Input From A User\n"
|
||||
" Input from a user can be obtained by:\n\n"
|
||||
"+set environment -p \"Prompt String\" name=default\n\n"
|
||||
" The -p switch indicates that the user should be prompted\n"
|
||||
" with the indicated prompt string and the input provided\n"
|
||||
" will be saved in the environment variable 'name'. If no\n"
|
||||
" input is provided, the value specified as 'default' will be\n"
|
||||
" used.\n"
|
||||
#define HLP_SET_ON "*Commands SET Command_Status_Trap_Dispatching"
|
||||
"3Command Status Trap Dispatching\n"
|
||||
"+set on enables error checking after command\n"
|
||||
@@ -3996,11 +4005,43 @@ return SCPE_OK;
|
||||
|
||||
t_stat sim_set_environment (int32 flag, CONST char *cptr)
|
||||
{
|
||||
char varname[CBUFSIZE];
|
||||
char varname[CBUFSIZE], prompt[CBUFSIZE];
|
||||
|
||||
if ((!cptr) || (*cptr == 0)) /* now eol? */
|
||||
return SCPE_2FARG;
|
||||
cptr = get_glyph (cptr, varname, '='); /* get environment variable name */
|
||||
if (sim_switches & SWMASK ('P')) {
|
||||
char cbuf[CBUFSIZE];
|
||||
CONST char *deflt = NULL;
|
||||
|
||||
cptr = get_glyph_quoted (cptr, prompt, 0); /* get prompt */
|
||||
if (prompt[0] == '\0')
|
||||
return sim_messagef (SCPE_2FARG, "Missing Prompt and Environment Variable Name\n");
|
||||
if ((prompt[0] == '"') || (prompt[0] == '\'')) {
|
||||
prompt[strlen (prompt) - 1] = '\0';
|
||||
memmove (prompt, prompt + 1, strlen (prompt));
|
||||
}
|
||||
deflt = get_glyph (cptr, varname, '='); /* get environment variable name */
|
||||
if (deflt == NULL)
|
||||
deflt = "";
|
||||
if (*deflt) {
|
||||
strlcat (prompt, " [", sizeof (prompt));
|
||||
strlcat (prompt, deflt, sizeof (prompt));
|
||||
strlcat (prompt, "] ", sizeof (prompt));
|
||||
}
|
||||
else
|
||||
strlcat (prompt, " ", sizeof (prompt));
|
||||
if (sim_rem_cmd_active_line == -1) {
|
||||
cptr = read_line_p (prompt, cbuf, sizeof(cbuf), stdin);
|
||||
if ((cptr == NULL) || (*cptr == 0))
|
||||
cptr = deflt;
|
||||
else
|
||||
cptr = cbuf;
|
||||
}
|
||||
else
|
||||
cptr = deflt;
|
||||
}
|
||||
else
|
||||
cptr = get_glyph (cptr, varname, '='); /* get environment variable name */
|
||||
setenv(varname, cptr, 1);
|
||||
return SCPE_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user