2 * Listener loop for subsystem library libss.a.
7 * Copyright 1987, 1988 by MIT Student Information Processing Board
9 * For copyright information, see copyright.h.
12 #include "copyright.h"
13 #include "ss_internal.h"
17 #include <sys/param.h>
23 static char const rcs_id[] =
27 typedef void sigret_t;
29 static ss_data *current_info;
30 static jmp_buf listen_jmpb;
32 static sigret_t print_prompt(int sig)
35 /* put input into a reasonable mode */
37 if (ioctl(fileno(stdin), TIOCGETP, &ttyb) != -1) {
38 if (ttyb.sg_flags & (CBREAK|RAW)) {
39 ttyb.sg_flags &= ~(CBREAK|RAW);
40 (void) ioctl(0, TIOCSETP, &ttyb);
44 (void) fputs(current_info->prompt, stdout);
45 (void) fflush(stdout);
48 static sigret_t listen_int_handler(int sig)
51 signal(SIGINT, listen_int_handler);
52 longjmp(listen_jmpb, 1);
55 int ss_listen (int sci_idx)
59 sigret_t (*sig_int)(int), (*sig_cont)(int), (*old_sig_cont)(int);
64 sigset_t omask, igmask;
70 ss_data *old_info = current_info;
72 current_info = info = ss_info(sci_idx);
73 sig_cont = (sigret_t (*)(int)) 0;
77 sigaddset(&igmask, SIGINT);
78 sigprocmask(SIG_BLOCK, &igmask, &omask);
80 mask = sigblock(sigmask(SIGINT));
82 memcpy(old_jmpb, listen_jmpb, sizeof(jmp_buf));
83 sig_int = signal(SIGINT, listen_int_handler);
86 sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0);
88 (void) sigsetmask(mask);
93 old_sig_cont = sig_cont;
94 sig_cont = signal(SIGCONT, print_prompt);
95 if (sig_cont == print_prompt)
96 sig_cont = old_sig_cont;
97 if (fgets(input, BUFSIZ, stdin) != input) {
101 cp = strchr(input, '\n');
107 (void) signal(SIGCONT, sig_cont);
108 for (end = input; *end; end++)
111 code = ss_execute_line (sci_idx, input);
112 if (code == SS_ET_COMMAND_NOT_FOUND) {
113 register char *c = input;
114 while (*c == ' ' || *c == '\t')
116 cp = strchr (c, ' ');
119 cp = strchr (c, '\t');
122 ss_error (sci_idx, 0,
123 "Unknown request \"%s\". Type \"?\" for a request list.",
129 (void) signal(SIGINT, sig_int);
130 memcpy(listen_jmpb, old_jmpb, sizeof(jmp_buf));
131 current_info = old_info;
135 void ss_abort_subsystem(int sci_idx, int code)
137 ss_info(sci_idx)->abort = 1;
138 ss_info(sci_idx)->exit_status = code;
142 void ss_quit(int argc, const char * const *argv, int sci_idx, pointer infop)
144 ss_abort_subsystem(sci_idx, 0);