SCP: Add support for operation when stdin isn't a tty
Also enhanced error messages for startup errors.
This commit is contained in:
parent
7ed68aed6a
commit
b15f753adc
2 changed files with 22 additions and 13 deletions
12
scp.c
12
scp.c
|
@ -6823,32 +6823,32 @@ for (i = 1; (dptr = sim_devices[i]) != NULL; i++) { /* reposition all */
|
||||||
}
|
}
|
||||||
stop_cpu = 0;
|
stop_cpu = 0;
|
||||||
sim_is_running = 1; /* flag running */
|
sim_is_running = 1; /* flag running */
|
||||||
if (sim_ttrun () != SCPE_OK) { /* set console mode */
|
if ((r = sim_ttrun ()) != SCPE_OK) { /* set console mode */
|
||||||
sim_is_running = 0; /* flag idle */
|
sim_is_running = 0; /* flag idle */
|
||||||
sim_ttcmd ();
|
sim_ttcmd ();
|
||||||
return SCPE_TTYERR;
|
return sim_messagef (SCPE_TTYERR, "sim_ttrun() returned: %s\n", sim_error_text (r));
|
||||||
}
|
}
|
||||||
if ((r = sim_check_console (30)) != SCPE_OK) { /* check console, error? */
|
if ((r = sim_check_console (30)) != SCPE_OK) { /* check console, error? */
|
||||||
sim_is_running = 0; /* flag idle */
|
sim_is_running = 0; /* flag idle */
|
||||||
sim_ttcmd ();
|
sim_ttcmd ();
|
||||||
return r;
|
sim_messagef (r, "sim_check_console () returned: %s\n", sim_error_text (r));
|
||||||
}
|
}
|
||||||
if (signal (SIGINT, int_handler) == SIG_ERR) { /* set WRU */
|
if (signal (SIGINT, int_handler) == SIG_ERR) { /* set WRU */
|
||||||
sim_is_running = 0; /* flag idle */
|
sim_is_running = 0; /* flag idle */
|
||||||
sim_ttcmd ();
|
sim_ttcmd ();
|
||||||
return SCPE_SIGERR;
|
return sim_messagef (SCPE_SIGERR, "Can't establish SIGINT");
|
||||||
}
|
}
|
||||||
#ifdef SIGHUP
|
#ifdef SIGHUP
|
||||||
if (signal (SIGHUP, int_handler) == SIG_ERR) { /* set WRU */
|
if (signal (SIGHUP, int_handler) == SIG_ERR) { /* set WRU */
|
||||||
sim_is_running = 0; /* flag idle */
|
sim_is_running = 0; /* flag idle */
|
||||||
sim_ttcmd ();
|
sim_ttcmd ();
|
||||||
return SCPE_SIGERR;
|
return sim_messagef (SCPE_SIGERR, "Can't establish SIGHUP");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (signal (SIGTERM, int_handler) == SIG_ERR) { /* set WRU */
|
if (signal (SIGTERM, int_handler) == SIG_ERR) { /* set WRU */
|
||||||
sim_is_running = 0; /* flag idle */
|
sim_is_running = 0; /* flag idle */
|
||||||
sim_ttcmd ();
|
sim_ttcmd ();
|
||||||
return SCPE_SIGERR;
|
return sim_messagef (SCPE_SIGERR, "Can't establish SIGTERM");
|
||||||
}
|
}
|
||||||
if (sim_step) /* set step timer */
|
if (sim_step) /* set step timer */
|
||||||
sim_activate (&sim_step_unit, sim_step);
|
sim_activate (&sim_step_unit, sim_step);
|
||||||
|
|
|
@ -2645,7 +2645,10 @@ if (!sim_rem_master_mode) {
|
||||||
if ((sim_con_ldsc.rxbps) && /* rate limiting && */
|
if ((sim_con_ldsc.rxbps) && /* rate limiting && */
|
||||||
(sim_gtime () < sim_con_ldsc.rxnexttime)) /* too soon? */
|
(sim_gtime () < sim_con_ldsc.rxnexttime)) /* too soon? */
|
||||||
return SCPE_OK; /* not yet */
|
return SCPE_OK; /* not yet */
|
||||||
c = sim_os_poll_kbd (); /* get character */
|
if (sim_ttisatty ())
|
||||||
|
c = sim_os_poll_kbd (); /* get character */
|
||||||
|
else
|
||||||
|
c = SCPE_OK;
|
||||||
if (c == SCPE_STOP) { /* ^E */
|
if (c == SCPE_STOP) { /* ^E */
|
||||||
stop_cpu = 1; /* Force a stop (which is picked up by sim_process_event */
|
stop_cpu = 1; /* Force a stop (which is picked up by sim_process_event */
|
||||||
return SCPE_OK;
|
return SCPE_OK;
|
||||||
|
@ -2984,7 +2987,11 @@ return r2;
|
||||||
|
|
||||||
t_bool sim_ttisatty (void)
|
t_bool sim_ttisatty (void)
|
||||||
{
|
{
|
||||||
return sim_os_ttisatty ();
|
static int answer = -1;
|
||||||
|
|
||||||
|
if (answer == -1)
|
||||||
|
answer = sim_os_ttisatty ();
|
||||||
|
return (t_bool)answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3220,13 +3227,14 @@ return SCPE_OK;
|
||||||
|
|
||||||
static t_stat sim_os_ttrun (void)
|
static t_stat sim_os_ttrun (void)
|
||||||
{
|
{
|
||||||
if ((std_input) && /* If Not Background process? */
|
if ((sim_ttisatty ()) &&
|
||||||
|
(std_input) && /* If Not Background process? */
|
||||||
(std_input != INVALID_HANDLE_VALUE)) {
|
(std_input != INVALID_HANDLE_VALUE)) {
|
||||||
if (!GetConsoleMode(std_input, &saved_input_mode))
|
if (!GetConsoleMode(std_input, &saved_input_mode))
|
||||||
return SCPE_TTYERR;
|
return sim_messagef (SCPE_TTYERR, "GetConsoleMode() error: 0x%X\n", GetLastError ());
|
||||||
if ((!SetConsoleMode(std_input, ENABLE_VIRTUAL_TERMINAL_INPUT)) &&
|
if ((!SetConsoleMode(std_input, ENABLE_VIRTUAL_TERMINAL_INPUT)) &&
|
||||||
(!SetConsoleMode(std_input, RAW_MODE)))
|
(!SetConsoleMode(std_input, RAW_MODE)))
|
||||||
return SCPE_TTYERR;
|
return sim_messagef (SCPE_TTYERR, "SetConsoleMode() error: 0x%X\n", GetLastError ());
|
||||||
}
|
}
|
||||||
if ((std_output) && /* If Not Background process? */
|
if ((std_output) && /* If Not Background process? */
|
||||||
(std_output != INVALID_HANDLE_VALUE)) {
|
(std_output != INVALID_HANDLE_VALUE)) {
|
||||||
|
@ -3249,7 +3257,8 @@ if (sim_log) {
|
||||||
_setmode (_fileno (sim_log), _O_TEXT);
|
_setmode (_fileno (sim_log), _O_TEXT);
|
||||||
}
|
}
|
||||||
sim_os_set_thread_priority (PRIORITY_NORMAL);
|
sim_os_set_thread_priority (PRIORITY_NORMAL);
|
||||||
if ((std_input) && /* If Not Background process? */
|
if ((sim_ttisatty ()) &&
|
||||||
|
(std_input) && /* If Not Background process? */
|
||||||
(std_input != INVALID_HANDLE_VALUE) &&
|
(std_input != INVALID_HANDLE_VALUE) &&
|
||||||
(!SetConsoleMode(std_input, saved_input_mode))) /* Restore Normal mode */
|
(!SetConsoleMode(std_input, saved_input_mode))) /* Restore Normal mode */
|
||||||
return SCPE_TTYERR;
|
return SCPE_TTYERR;
|
||||||
|
@ -3886,7 +3895,7 @@ static t_bool sim_os_poll_kbd_ready (int ms_timeout)
|
||||||
fd_set readfds;
|
fd_set readfds;
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
|
|
||||||
if (!sim_os_ttisatty()) { /* skip if !tty */
|
if (!sim_ttisatty()) { /* skip if !tty */
|
||||||
sim_os_ms_sleep (ms_timeout);
|
sim_os_ms_sleep (ms_timeout);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue