2
2
* Listener loop for subsystem library libss.a.
4
* $Header: lib/ss/SCCS/s.listen.c 1.16 02/03/07 23:52:55-05:00 tytso@think.thunk.org $
4
* $Header: lib/ss/SCCS/s.listen.c 1.19 03/12/07 01:28:48-05:00 tytso@think.thunk.org $
5
5
* $Locker: <Not implemented> $
7
7
* Copyright 1987, 1988 by MIT Student Information Processing Board
36
28
static jmp_buf listen_jmpb;
37
29
static sigret_t (*sig_cont)(int);
39
static sigret_t print_prompt(int sig)
31
static sigret_t print_prompt(int sig __SS_ATTR((unused)))
42
/* put input into a reasonable mode */
44
if (ioctl(fileno(stdin), TIOCGETP, &ttyb) != -1) {
45
if (ttyb.sg_flags & (CBREAK|RAW)) {
46
ttyb.sg_flags &= ~(CBREAK|RAW);
47
(void) ioctl(0, TIOCSETP, &ttyb);
33
if (current_info->redisplay)
34
(*current_info->redisplay)();
36
(void) fputs(current_info->prompt, stdout);
37
(void) fflush(stdout);
51
(void) fputs(current_info->prompt, stdout);
52
(void) fflush(stdout);
55
static sigret_t listen_int_handler(int sig)
41
static sigret_t listen_int_handler(int sig __SS_ATTR((unused)))
57
43
putc('\n', stdout);
58
44
signal(SIGINT, listen_int_handler);
66
52
sigret_t (*sig_int)(int), (*old_sig_cont)(int);
67
53
char input[BUFSIZ];
69
54
sigset_t omask, igmask;
75
57
ss_data *old_info = current_info;
77
60
current_info = info = ss_info(sci_idx);
78
61
sig_cont = (sigret_t (*)(int)) 0;
81
63
sigemptyset(&igmask);
82
64
sigaddset(&igmask, SIGINT);
83
65
sigprocmask(SIG_BLOCK, &igmask, &omask);
85
mask = sigblock(sigmask(SIGINT));
87
66
memcpy(old_jmpb, listen_jmpb, sizeof(jmp_buf));
88
67
sig_int = signal(SIGINT, listen_int_handler);
89
68
setjmp(listen_jmpb);
91
69
sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0);
93
(void) sigsetmask(mask);
95
71
while(!info->abort) {
97
72
old_sig_cont = sig_cont;
98
73
sig_cont = signal(SIGCONT, print_prompt);
99
74
if (sig_cont == print_prompt)
100
75
sig_cont = old_sig_cont;
101
if (fgets(input, BUFSIZ, stdin) != input) {
103
(void) signal(SIGCONT, sig_cont);
77
line = (*info->readline)(current_info->prompt);
80
if (fgets(input, BUFSIZ, stdin) == input)
108
cp = strchr(input, '\n');
89
(void) signal(SIGCONT, sig_cont);
93
cp = strchr(line, '\n');
114
99
(void) signal(SIGCONT, sig_cont);
100
if (info->add_history)
101
(*info->add_history)(line);
116
code = ss_execute_line (sci_idx, input);
103
code = ss_execute_line (sci_idx, line);
117
104
if (code == SS_ET_COMMAND_NOT_FOUND) {
118
register char *c = input;
105
register char *c = line;
119
106
while (*c == ' ' || *c == '\t')
121
108
cp = strchr (c, ' ');
147
void ss_quit(int argc, const char * const *argv, int sci_idx, pointer infop)
136
void ss_quit(int argc __SS_ATTR((unused)),
137
const char * const *argv __SS_ATTR((unused)),
138
int sci_idx, pointer infop __SS_ATTR((unused)))
149
140
ss_abort_subsystem(sci_idx, 0);
144
#define get_request(tbl,idx) ((tbl) -> requests + (idx))
146
static char *cmd_generator(const char *text, int state)
149
static ss_request_table **rqtbl;
151
static char const * const * name;
152
ss_request_entry *request;
157
rqtbl = current_info->rqt_tables;
158
if (!rqtbl || !*rqtbl)
165
if (!name || !*name) {
166
request = get_request(*rqtbl, curr_rqt++);
167
name = request->command_names;
177
if (strncmp(*name, text, len) == 0) {
178
ret = malloc(strlen(*name)+1);
190
char **ss_rl_completion(const char *text, int start,
191
int end __SS_ATTR((unused)))
193
if ((start == 0) && current_info->rl_completion_matches)
194
return (*current_info->rl_completion_matches)
195
(text, cmd_generator);