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:
Mark Pizzolato 2017-04-30 09:44:37 -07:00
parent 7a46fcf17c
commit 7ae5015610
3 changed files with 91 additions and 49 deletions

View file

@ -260,52 +260,53 @@ The EXPECT command now exists to provide a means of reacting to simulator output
#### New SCP Commands: #### New SCP Commands:
SCREENSHOT filename.bmp Save video window to the specified file SCREENSHOT filename.bmp Save video window to the specified file
SET ENVIRONMENT Name=Value Set Environment variable SET ENV Name=Value Set Environment variable
SET ASYNCH Enable Asynchronous I/O SET ENV -p "Prompt" Name=Default Gather User input into an Environment Variable
SET NOASYNCH Disable Asynchronous I/O SET ASYNCH Enable Asynchronous I/O
SET VERIFY Enable commang display while processing DO command files SET NOASYNCH Disable Asynchronous I/O
SET NOVERIFY Enable commang display while processing DO command files SET VERIFY Enable commang display while processing DO command files
SET MESSAGE Enable error message output when commands complete (default) SET NOVERIFY Enable commang display while processing DO command files
SET NOMESSAGE Disable error message output when commands complete SET MESSAGE Enable error message output when commands complete (default)
SET QUIET Set minimal output mode for command execution SET NOMESSAGE Disable error message output when commands complete
SET NOQUIET Set normal output mode for command execution SET QUIET Set minimal output mode for command execution
SET PROMPT Change the prompt used by the simulator (defaulr sim>) SET NOQUIET Set normal output mode for command execution
SET THROTTLE x/t Throttle t ms every x cycles SET PROMPT Change the prompt used by the simulator (defaulr sim>)
SET REMOTE TELNET=port Specify remote console telnet port SET THROTTLE x/t Throttle t ms every x cycles
SET REMOTE NOTELNET Disables remote console SET REMOTE TELNET=port Specify remote console telnet port
SET REMOTE CONNECTIONS=n Specify the number of concurrent remote console sessions SET REMOTE NOTELNET Disables remote console
SHOW FEATURES Displays the devices descriptions and features SET REMOTE CONNECTIONS=n Specify the number of concurrent remote console sessions
SHOW ASYNCH Display the current Asynchronous I/O status SHOW FEATURES Displays the devices descriptions and features
SHOW SERIAL Display the available and/or open serial ports SHOW ASYNCH Display the current Asynchronous I/O status
SHOW ETHERNET Display the available and/or open ethernet connections SHOW SERIAL Display the available and/or open serial ports
SHOW MULTIPLEXER Display the details about open multiplexer devices SHOW ETHERNET Display the available and/or open ethernet connections
SHOW CLOCKS Display the details about calibrated timers SHOW MULTIPLEXER Display the details about open multiplexer devices
SHOW REMOTE Display the remote console configuration SHOW CLOCKS Display the details about calibrated timers
SHOW ON Display ON condition dispatch actions SHOW REMOTE Display the remote console configuration
SET ON Enable ON condition error dispatching SHOW ON Display ON condition dispatch actions
SET NOON Disable ON condition error dispatching SET ON Enable ON condition error dispatching
GOTO Transfer to lable in the current DO command file SET NOON Disable ON condition error dispatching
CALL Call subroutine at indicated label GOTO Transfer to lable in the current DO command file
RETURN Return from subroutine call CALL Call subroutine at indicated label
SHIFT Slide argument parameters %1 thru %9 left 1 RETURN Return from subroutine call
NOOP A no-op command SHIFT Slide argument parameters %1 thru %9 left 1
ON Establish or cancel an ON condition dispatch NOOP A no-op command
IF Test some simulator state and conditionally execute commands ON Establish or cancel an ON condition dispatch
CD Change working directory IF Test some simulator state and conditionally execute commands
SET DEFAULT Change working directory CD Change working directory
PWD Show working directory SET DEFAULT Change working directory
SHOW DEFAULT Show working directory PWD Show working directory
DIR {path|file} Display file listing SHOW DEFAULT Show working directory
LS {path|file} Display file listing DIR {path|file} Display file listing
NEXT Step across a subroutine call or step a single instruction. LS {path|file} Display file listing
EXPECT React to output produced by a simulated system NEXT Step across a subroutine call or step a single instruction.
SEND Inject input to a simulated system's console EXPECT React to output produced by a simulated system
SCREENSHOT Snapshot the current video display window SEND Inject input to a simulated system's console
RUN UNTIL breakpoint Establish the breakpoiunt specified and run until it is encountered SCREENSHOT Snapshot the current video display window
RUN UNTIL "output-string" ... Establish the specified "output-string" as an EXPECT and run until it is encountered. RUN UNTIL breakpoint Establish the breakpoiunt specified and run until it is encountered
GO UNTIL breakpoint Establish the breakpoiunt specified and go until it is encountered RUN UNTIL "output-string" ... Establish the specified "output-string" as an EXPECT and run until it is encountered.
GO UNTILE "output-string" ... Establish the specified "output-string" as an EXPECT and go until it is encountered. GO UNTIL breakpoint Establish the breakpoiunt specified and go until it is encountered
GO UNTILE "output-string" ... Establish the specified "output-string" as an EXPECT and go until it is encountered.
#### Command Processing Enhancements #### Command Processing Enhancements

Binary file not shown.

47
scp.c
View file

@ -1161,10 +1161,19 @@ static const char simh_help[] =
"3Asynch\n" "3Asynch\n"
"+set asynch enable asynchronous I/O\n" "+set asynch enable asynchronous I/O\n"
"+set noasynch disable 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" "3Environment\n"
"4Explicitily Changing A Variable\n"
"+set environment name=val set environment variable\n" "+set environment name=val set environment variable\n"
"+set environment name clear 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" #define HLP_SET_ON "*Commands SET Command_Status_Trap_Dispatching"
"3Command Status Trap Dispatching\n" "3Command Status Trap Dispatching\n"
"+set on enables error checking after command\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) t_stat sim_set_environment (int32 flag, CONST char *cptr)
{ {
char varname[CBUFSIZE]; char varname[CBUFSIZE], prompt[CBUFSIZE];
if ((!cptr) || (*cptr == 0)) /* now eol? */ if ((!cptr) || (*cptr == 0)) /* now eol? */
return SCPE_2FARG; 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); setenv(varname, cptr, 1);
return SCPE_OK; return SCPE_OK;
} }