1 | /* |
---|
2 | * |
---|
3 | * Copyright (C) 1989 by the Massachusetts Institute of Technology |
---|
4 | * Developed by the MIT Student Information Processing Board (SIPB). |
---|
5 | * For copying information, see the file mit-copyright.h in this release. |
---|
6 | * |
---|
7 | */ |
---|
8 | /* |
---|
9 | * $Id: rn.c,v 1.16 1999-02-02 20:39:50 kcr Exp $ |
---|
10 | * |
---|
11 | */ |
---|
12 | |
---|
13 | #ifndef lint |
---|
14 | static char rcsid_update_c[] = |
---|
15 | "$Id: rn.c,v 1.16 1999-02-02 20:39:50 kcr Exp $"; |
---|
16 | #endif /* lint */ |
---|
17 | |
---|
18 | #include <discuss/discuss.h> |
---|
19 | #include "globals.h" |
---|
20 | #include <stdio.h> |
---|
21 | #include <sys/types.h> |
---|
22 | #include <sys/file.h> |
---|
23 | #include <sys/ioctl.h> |
---|
24 | |
---|
25 | #if HAVE_TERMIOS_H |
---|
26 | #include <termios.h> |
---|
27 | #endif |
---|
28 | |
---|
29 | static unseen_transactions(); |
---|
30 | static char ss_buf[512]; |
---|
31 | |
---|
32 | static changed_meetings() |
---|
33 | { |
---|
34 | int code, n_matches, i; |
---|
35 | name_blk *set, *nbp; |
---|
36 | |
---|
37 | dsc_expand_mtg_set(user_id, "*", &set, &n_matches, &code); |
---|
38 | for (i = 0; i < n_matches; i++) { |
---|
39 | nbp = &set[i]; |
---|
40 | if (nbp->status & DSC_ST_CHANGED) { |
---|
41 | free(set); |
---|
42 | return 1; |
---|
43 | } |
---|
44 | } |
---|
45 | free(set); |
---|
46 | return 0; |
---|
47 | } |
---|
48 | |
---|
49 | rn(argc, argv, ss_idx) |
---|
50 | int argc; |
---|
51 | char **argv; |
---|
52 | int ss_idx; |
---|
53 | { |
---|
54 | int code = 0; |
---|
55 | int cmd; |
---|
56 | |
---|
57 | printf("Checking meetings...\n"); |
---|
58 | fflush(stdout); |
---|
59 | |
---|
60 | strcpy(ss_buf, "ckm"); |
---|
61 | ss_execute_line(ss_idx, ss_buf, &code); |
---|
62 | if (code != 0) goto punt; |
---|
63 | |
---|
64 | flag_interrupts(); |
---|
65 | printf("\n"); |
---|
66 | |
---|
67 | if (!changed_meetings()) |
---|
68 | return; |
---|
69 | |
---|
70 | for (;;) { |
---|
71 | cmd = more_break("Hit space to go to next meeting: ", " qn?"); |
---|
72 | if (interrupt) |
---|
73 | goto done; |
---|
74 | printf("\n"); |
---|
75 | switch(cmd) { |
---|
76 | case 'q': |
---|
77 | goto done; |
---|
78 | case ' ': |
---|
79 | case 'n': |
---|
80 | goto first_meeting; |
---|
81 | case '?': |
---|
82 | printf("List of possible responses:\n\n"); |
---|
83 | printf("<space>,n\tNext meeting\n"); |
---|
84 | printf("q\t\tQuit from read_new\n"); |
---|
85 | printf("?\t\tShow this list\n\n"); |
---|
86 | break; |
---|
87 | } |
---|
88 | } |
---|
89 | first_meeting: |
---|
90 | strcpy(ss_buf, "nm"); |
---|
91 | ss_execute_line(ss_idx, ss_buf, &code); |
---|
92 | if (code != 0) goto punt; |
---|
93 | |
---|
94 | while (1) { /* we get out when changed_meetings is false */ |
---|
95 | if (interrupt) |
---|
96 | break; |
---|
97 | |
---|
98 | while (unseen_transactions()) { |
---|
99 | if (interrupt) |
---|
100 | break; |
---|
101 | |
---|
102 | cmd = more_break("Hit space for next transaction: ", " qcnp\022tr?"); |
---|
103 | if (interrupt) |
---|
104 | break; |
---|
105 | printf("\n"); |
---|
106 | switch (cmd) { |
---|
107 | case 'q': |
---|
108 | goto done; |
---|
109 | case ' ': |
---|
110 | case 'n': |
---|
111 | if (dsc_public.current == 0) |
---|
112 | strcpy(ss_buf, "pr first"); |
---|
113 | else |
---|
114 | strcpy(ss_buf, "next"); |
---|
115 | ss_execute_line(ss_idx, ss_buf, &code); |
---|
116 | if (code != 0) goto punt; |
---|
117 | break; |
---|
118 | case 'c': |
---|
119 | catchup(0,0); |
---|
120 | break; |
---|
121 | case 'p': |
---|
122 | strcpy(ss_buf, "prev"); |
---|
123 | ss_execute_line(ss_idx, ss_buf, &code); |
---|
124 | if (code != 0) goto punt; |
---|
125 | break; |
---|
126 | case '\022': |
---|
127 | strcpy(ss_buf, "pr"); |
---|
128 | ss_execute_line(ss_idx, ss_buf, &code); |
---|
129 | if (code != 0) goto punt; |
---|
130 | break; |
---|
131 | case 'r': |
---|
132 | strcpy(ss_buf, "reply"); |
---|
133 | ss_execute_line(ss_idx, ss_buf, &code); |
---|
134 | if (code != 0) goto punt; |
---|
135 | break; |
---|
136 | case 't': |
---|
137 | strcpy(ss_buf, "talk"); |
---|
138 | ss_execute_line(ss_idx, ss_buf, &code); |
---|
139 | if (code != 0) goto punt; |
---|
140 | break; |
---|
141 | case '?': |
---|
142 | printf("List of possible responses:\n\n"); |
---|
143 | printf("<space>,n\tNext transaction\n"); |
---|
144 | printf("c\t\tCatch up on transactions in meeting\n"); |
---|
145 | printf("p\t\tPrevious transaction\n"); |
---|
146 | printf("^R\t\tReview current transaction\n"); |
---|
147 | printf("q\t\tQuit from read_new\n"); |
---|
148 | printf("r\t\tReply to current transaction\n"); |
---|
149 | printf("t\t\tEnter a new transaction\n"); |
---|
150 | printf("?\t\tShow this list\n\n"); |
---|
151 | break; |
---|
152 | } |
---|
153 | } |
---|
154 | |
---|
155 | if (!changed_meetings()) |
---|
156 | break; |
---|
157 | |
---|
158 | cmd = more_break("Hit space to go to next meeting: ", " qn?ptr\022"); |
---|
159 | if (interrupt) |
---|
160 | break; |
---|
161 | printf("\n"); |
---|
162 | switch(cmd) { |
---|
163 | case 'q': |
---|
164 | goto punt; |
---|
165 | case ' ': |
---|
166 | case 'n': |
---|
167 | strcpy(ss_buf, "nm"); |
---|
168 | ss_execute_line(ss_idx, ss_buf, &code); |
---|
169 | if (code != 0) goto punt; |
---|
170 | break; |
---|
171 | case 'p': |
---|
172 | strcpy(ss_buf, "prev"); |
---|
173 | ss_execute_line(ss_idx, ss_buf, &code); |
---|
174 | if (code != 0) goto punt; |
---|
175 | break; |
---|
176 | case '\022': |
---|
177 | strcpy(ss_buf, "pr"); |
---|
178 | ss_execute_line(ss_idx, ss_buf, &code); |
---|
179 | if (code != 0) goto punt; |
---|
180 | break; |
---|
181 | case 'r': |
---|
182 | strcpy(ss_buf, "reply"); |
---|
183 | ss_execute_line(ss_idx, ss_buf, &code); |
---|
184 | if (code != 0) goto punt; |
---|
185 | break; |
---|
186 | case 't': |
---|
187 | strcpy(ss_buf, "talk"); |
---|
188 | ss_execute_line(ss_idx, ss_buf, &code); |
---|
189 | if (code != 0) goto punt; |
---|
190 | break; |
---|
191 | case '?': |
---|
192 | printf("List of possible responses:\n\n"); |
---|
193 | printf("<space>,n\tNext meeting\n"); |
---|
194 | printf("p\t\tPrevious transaction\n"); |
---|
195 | printf("^R\t\tReview the current transaction\n"); |
---|
196 | printf("q\t\tQuit from read_new\n"); |
---|
197 | printf("r\t\tReply to current transaction\n"); |
---|
198 | printf("t\t\tEnter a new transaction\n"); |
---|
199 | printf("?\t\tShow this list\n\n"); |
---|
200 | break; |
---|
201 | } |
---|
202 | } |
---|
203 | |
---|
204 | done: |
---|
205 | return; |
---|
206 | |
---|
207 | punt: |
---|
208 | dont_flag_interrupts(); |
---|
209 | ss_perror(ss_idx, code, 0); |
---|
210 | } |
---|
211 | |
---|
212 | /* |
---|
213 | * Flames to /dev/null |
---|
214 | */ |
---|
215 | |
---|
216 | more_break(prompt, cmds) |
---|
217 | char *prompt; |
---|
218 | char *cmds; |
---|
219 | { |
---|
220 | int arg; |
---|
221 | char buf[1]; |
---|
222 | #if HAVE_TERMIOS_H |
---|
223 | struct termios tty, ntty; |
---|
224 | |
---|
225 | (void) tcflush(0, TCIFLUSH); |
---|
226 | (void) tcgetattr(0, &tty); |
---|
227 | ntty = tty; |
---|
228 | ntty.c_cc[VMIN] = 1; |
---|
229 | ntty.c_cc[VTIME] = 0; |
---|
230 | ntty.c_iflag &= ~(ICRNL); |
---|
231 | ntty.c_lflag &= ~(ICANON|ISIG|ECHO); |
---|
232 | (void) tcsetattr(0, TCSANOW, &ntty); |
---|
233 | #else |
---|
234 | struct sgttyb tty, ntty; |
---|
235 | |
---|
236 | arg = FREAD; /* Flush pending input */ |
---|
237 | ioctl(0, TIOCFLUSH, &arg); |
---|
238 | ioctl(0, TIOCGETP, &tty); /* Get parameters.. */ |
---|
239 | ntty = tty; |
---|
240 | ntty.sg_flags |= CBREAK; |
---|
241 | ntty.sg_flags &= ~ECHO; |
---|
242 | ioctl(0, TIOCSETP, &ntty); /* go to cbreak, ~echo */ |
---|
243 | #endif |
---|
244 | write(1, prompt, strlen(prompt)); |
---|
245 | for (;;) { |
---|
246 | if (read(0, buf, 1) != 1) { |
---|
247 | buf[0] = 'q'; |
---|
248 | break; |
---|
249 | } |
---|
250 | if (strchr(cmds, buf[0])) |
---|
251 | break; |
---|
252 | write(1, "\7", 1); |
---|
253 | } |
---|
254 | #if HAVE_TERMIOS_H |
---|
255 | (void) tcsetattr(0, TCSANOW, &tty); |
---|
256 | #else |
---|
257 | ioctl(0, TIOCSETP, &tty); |
---|
258 | #endif |
---|
259 | write(1, "\n", 1); |
---|
260 | return buf[0]; |
---|
261 | } |
---|
262 | |
---|
263 | static |
---|
264 | unseen_transactions() |
---|
265 | { |
---|
266 | return (dsc_public.current < dsc_public.m_info.last); |
---|
267 | } |
---|