2 * Listener loop for subsystem library libss.a.
7 * Copyright 1987, 1988 by MIT Student Information Processing Board
9 * Permission to use, copy, modify, and distribute this software and
10 * its documentation for any purpose is hereby granted, provided that
11 * the names of M.I.T. and the M.I.T. S.I.P.B. not be used in
12 * advertising or publicity pertaining to distribution of the software
13 * without specific, written prior permission. M.I.T. and the
14 * M.I.T. S.I.P.B. make no representations about the suitability of
15 * this software for any purpose. It is provided "as is" without
16 * express or implied warranty.
19 #include "ss_internal.h"
23 #include <sys/param.h>
29 static char const rcs_id[] =
33 typedef void sigret_t;
35 static ss_data *current_info;
36 static jmp_buf listen_jmpb;
38 static sigret_t print_prompt(int sig)
41 /* put input into a reasonable mode */
43 if (ioctl(fileno(stdin), TIOCGETP, &ttyb) != -1) {
44 if (ttyb.sg_flags & (CBREAK|RAW)) {
45 ttyb.sg_flags &= ~(CBREAK|RAW);
46 (void) ioctl(0, TIOCSETP, &ttyb);
50 (void) fputs(current_info->prompt, stdout);
51 (void) fflush(stdout);
54 static sigret_t listen_int_handler(int sig)
57 signal(SIGINT, listen_int_handler);
58 longjmp(listen_jmpb, 1);
61 int ss_listen (int sci_idx)
65 sigret_t (*sig_int)(int), (*sig_cont)(int), (*old_sig_cont)(int);
70 sigset_t omask, igmask;
76 ss_data *old_info = current_info;
78 current_info = info = ss_info(sci_idx);
79 sig_cont = (sigret_t (*)(int)) 0;
83 sigaddset(&igmask, SIGINT);
84 sigprocmask(SIG_BLOCK, &igmask, &omask);
86 mask = sigblock(sigmask(SIGINT));
88 memcpy(old_jmpb, listen_jmpb, sizeof(jmp_buf));
89 sig_int = signal(SIGINT, listen_int_handler);
92 sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0);
94 (void) sigsetmask(mask);
99 old_sig_cont = sig_cont;
100 sig_cont = signal(SIGCONT, print_prompt);
101 if (sig_cont == print_prompt)
102 sig_cont = old_sig_cont;
103 if (fgets(input, BUFSIZ, stdin) != input) {
107 cp = strchr(input, '\n');
113 (void) signal(SIGCONT, sig_cont);
114 for (end = input; *end; end++)
117 code = ss_execute_line (sci_idx, input);
118 if (code == SS_ET_COMMAND_NOT_FOUND) {
119 register char *c = input;
120 while (*c == ' ' || *c == '\t')
122 cp = strchr (c, ' ');
125 cp = strchr (c, '\t');
128 ss_error (sci_idx, 0,
129 "Unknown request \"%s\". Type \"?\" for a request list.",
135 (void) signal(SIGINT, sig_int);
136 memcpy(listen_jmpb, old_jmpb, sizeof(jmp_buf));
137 current_info = old_info;
141 void ss_abort_subsystem(int sci_idx, int code)
143 ss_info(sci_idx)->abort = 1;
144 ss_info(sci_idx)->exit_status = code;
148 void ss_quit(int argc, const char * const *argv, int sci_idx, pointer infop)
150 ss_abort_subsystem(sci_idx, 0);