Rev 1419 | Rev 1519 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1419 | Rev 1472 | ||
---|---|---|---|
Line 40... | Line 40... | ||
40 | */ |
40 | */ |
41 | 41 | ||
42 | #include <sys/ioctl.h> |
42 | #include <sys/ioctl.h> |
43 | 43 | ||
44 | #include <err.h> |
44 | #include <err.h> |
45 | #include <setjmp.h> |
45 | //#include <setjmp.h> |
46 | #include <signal.h> |
46 | //#include <signal.h> |
47 | #include <stdio.h> |
47 | #include <stdio.h> |
48 | #include <stdlib.h> |
48 | #include <stdlib.h> |
49 | #include <string.h> |
49 | #include <string.h> |
50 | #include <term.h> |
50 | #include <term.h> |
51 | #include <termios.h> |
51 | #include <termios.h> |
Line 202... | Line 202... | ||
202 | CRstr = "\r"; |
202 | CRstr = "\r"; |
203 | #endif |
203 | #endif |
204 | } |
204 | } |
205 | 205 | ||
206 | /* this foolery is needed to modify tty state `atomically' */ |
206 | /* this foolery is needed to modify tty state `atomically' */ |
207 | static jmp_buf scr_onstop; |
207 | //static jmp_buf scr_onstop; |
208 | 208 | ||
209 | static void |
209 | /* static void */ |
210 | stopset(int sig) |
210 | /* stopset(int sig) */ |
211 | { |
211 | /* { */ |
212 | sigset_t sigset; |
212 | /* sigset_t sigset; */ |
213 | 213 | ||
214 | (void) signal(sig, SIG_DFL); |
214 | /* (void) signal(sig, SIG_DFL); */ |
215 | (void) kill(getpid(), sig); |
215 | /* (void) kill(getpid(), sig); */ |
216 | sigemptyset(&sigset); |
216 | /* sigemptyset(&sigset); */ |
217 | sigaddset(&sigset, sig); |
217 | /* sigaddset(&sigset, sig); */ |
218 | (void) sigprocmask(SIG_UNBLOCK, &sigset, (sigset_t *)0); |
218 | /* (void) sigprocmask(SIG_UNBLOCK, &sigset, (sigset_t *)0); */ |
219 | longjmp(scr_onstop, 1); |
219 | /* longjmp(scr_onstop, 1); */ |
220 | } |
220 | /* } */ |
221 | 221 | ||
222 | static void |
222 | static void |
223 | scr_stop(int sig) |
223 | scr_stop(int sig) |
224 | { |
224 | { |
225 | sigset_t sigset; |
225 | // sigset_t sigset; |
226 | 226 | ||
227 | scr_end(); |
227 | scr_end(); |
228 | (void) kill(getpid(), sig); |
228 | /* (void) kill(getpid(), sig); */ |
229 | sigemptyset(&sigset); |
229 | /* sigemptyset(&sigset); */ |
230 | sigaddset(&sigset, sig); |
230 | /* sigaddset(&sigset, sig); */ |
231 | (void) sigprocmask(SIG_UNBLOCK, &sigset, (sigset_t *)0); |
231 | /* (void) sigprocmask(SIG_UNBLOCK, &sigset, (sigset_t *)0); */ |
232 | scr_set(); |
232 | scr_set(); |
233 | scr_msg(key_msg, 1); |
233 | scr_msg(key_msg, 1); |
234 | } |
234 | } |
235 | 235 | ||
236 | /* |
236 | /* |
Line 239... | Line 239... | ||
239 | void |
239 | void |
240 | scr_set(void) |
240 | scr_set(void) |
241 | { |
241 | { |
242 | struct winsize ws; |
242 | struct winsize ws; |
243 | struct termios newtt; |
243 | struct termios newtt; |
244 | sigset_t sigset, osigset; |
244 | // sigset_t sigset, osigset; |
245 | void (*ttou)(int); |
245 | void (*ttou)(int); |
246 | 246 | ||
247 | sigemptyset(&sigset); |
247 | /* sigemptyset(&sigset); */ |
248 | sigaddset(&sigset, SIGTSTP); |
248 | /* sigaddset(&sigset, SIGTSTP); */ |
249 | sigaddset(&sigset, SIGTTOU); |
249 | /* sigaddset(&sigset, SIGTTOU); */ |
250 | (void) sigprocmask(SIG_BLOCK, &sigset, &osigset); |
250 | /* (void) sigprocmask(SIG_BLOCK, &sigset, &osigset); */ |
251 | if ((tstp = signal(SIGTSTP, stopset)) == SIG_IGN) |
251 | /* if ((tstp = signal(SIGTSTP, stopset)) == SIG_IGN) */ |
252 | (void) signal(SIGTSTP, SIG_IGN); |
252 | /* (void) signal(SIGTSTP, SIG_IGN); */ |
253 | if ((ttou = signal(SIGTTOU, stopset)) == SIG_IGN) |
253 | /* if ((ttou = signal(SIGTTOU, stopset)) == SIG_IGN) */ |
254 | (void) signal(SIGTTOU, SIG_IGN); |
254 | /* (void) signal(SIGTTOU, SIG_IGN); */ |
255 | /* |
255 | /* /\* */ |
256 | * At last, we are ready to modify the tty state. If |
256 | /* * At last, we are ready to modify the tty state. If */ |
257 | * we stop while at it, stopset() above will longjmp back |
257 | /* * we stop while at it, stopset() above will longjmp back */ |
258 | * to the setjmp here and we will start over. |
258 | /* * to the setjmp here and we will start over. */ |
259 | */ |
259 | /* *\/ */ |
260 | (void) setjmp(scr_onstop); |
260 | /* (void) setjmp(scr_onstop); */ |
261 | (void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); |
261 | /* (void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); */ |
262 | Rows = 0, Cols = 0; |
262 | Rows = 0, Cols = 0; |
263 | if (ioctl(0, TIOCGWINSZ, &ws) == 0) { |
263 | if (ioctl(0, TIOCGWINSZ, &ws) == 0) { |
264 | Rows = ws.ws_row; |
264 | Rows = ws.ws_row; |
265 | Cols = ws.ws_col; |
265 | Cols = ws.ws_col; |
266 | } |
266 | } |
Line 281... | Line 281... | ||
281 | newtt = oldtt; |
281 | newtt = oldtt; |
282 | newtt.c_lflag &= ~(ICANON|ECHO); |
282 | newtt.c_lflag &= ~(ICANON|ECHO); |
283 | newtt.c_oflag &= ~OXTABS; |
283 | newtt.c_oflag &= ~OXTABS; |
284 | if (tcsetattr(0, TCSADRAIN, &newtt) < 0) |
284 | if (tcsetattr(0, TCSADRAIN, &newtt) < 0) |
285 | stop("tcsetattr() fails"); |
285 | stop("tcsetattr() fails"); |
286 | (void) sigprocmask(SIG_BLOCK, &sigset, &osigset); |
286 | /* (void) sigprocmask(SIG_BLOCK, &sigset, &osigset); */ |
287 | 287 | ||
288 | /* |
288 | /* |
289 | * We made it. We are now in screen mode, modulo TIstr |
289 | * We made it. We are now in screen mode, modulo TIstr |
290 | * (which we will fix immediately). |
290 | * (which we will fix immediately). |
291 | */ |
291 | */ |
292 | if (TIstr) |
292 | if (TIstr) |
293 | putstr(TIstr); /* termcap(5) says this is not padded */ |
293 | putstr(TIstr); /* termcap(5) says this is not padded */ |
294 | if (tstp != SIG_IGN) |
294 | /* if (tstp != SIG_IGN) */ |
295 | (void) signal(SIGTSTP, scr_stop); |
295 | /* (void) signal(SIGTSTP, scr_stop); */ |
296 | if (ttou != SIG_IGN) |
296 | /* if (ttou != SIG_IGN) */ |
297 | (void) signal(SIGTTOU, ttou); |
297 | /* (void) signal(SIGTTOU, ttou); */ |
298 | 298 | ||
299 | isset = 1; |
299 | isset = 1; |
300 | (void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); |
300 | // (void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); |
301 | scr_clear(); |
301 | scr_clear(); |
302 | } |
302 | } |
303 | 303 | ||
304 | /* |
304 | /* |
305 | * End screen mode. |
305 | * End screen mode. |
306 | */ |
306 | */ |
307 | void |
307 | void |
308 | scr_end(void) |
308 | scr_end(void) |
309 | { |
309 | { |
310 | sigset_t sigset, osigset; |
310 | // sigset_t sigset, osigset; |
311 | 311 | ||
312 | sigemptyset(&sigset); |
312 | /* sigemptyset(&sigset); */ |
313 | sigaddset(&sigset, SIGTSTP); |
313 | /* sigaddset(&sigset, SIGTSTP); */ |
314 | sigaddset(&sigset, SIGTTOU); |
314 | /* sigaddset(&sigset, SIGTTOU); */ |
315 | (void) sigprocmask(SIG_BLOCK, &sigset, &osigset); |
315 | /* (void) sigprocmask(SIG_BLOCK, &sigset, &osigset); */ |
316 | /* move cursor to last line */ |
316 | /* move cursor to last line */ |
317 | if (LLstr) |
317 | if (LLstr) |
318 | putstr(LLstr); /* termcap(5) says this is not padded */ |
318 | putstr(LLstr); /* termcap(5) says this is not padded */ |
319 | else |
319 | else |
320 | moveto(Rows - 1, 0); |
320 | moveto(Rows - 1, 0); |
321 | /* exit screen mode */ |
321 | /* exit screen mode */ |
322 | if (TEstr) |
322 | if (TEstr) |
323 | putstr(TEstr); /* termcap(5) says this is not padded */ |
323 | putstr(TEstr); /* termcap(5) says this is not padded */ |
324 | (void) fflush(stdout); |
324 | // (void) fflush(stdout); |
325 | (void) tcsetattr(0, TCSADRAIN, &oldtt); |
325 | (void) tcsetattr(0, TCSADRAIN, &oldtt); |
326 | isset = 0; |
326 | isset = 0; |
327 | /* restore signals */ |
327 | /* restore signals */ |
328 | (void) signal(SIGTSTP, tstp); |
328 | /* (void) signal(SIGTSTP, tstp); */ |
329 | (void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); |
329 | /* (void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); */ |
330 | } |
330 | } |
331 | 331 | ||
332 | void |
332 | void |
333 | stop(char *why) |
333 | stop(char *why) |
334 | { |
334 | { |
Line 363... | Line 363... | ||
363 | scr_update(void) |
363 | scr_update(void) |
364 | { |
364 | { |
365 | cell *bp, *sp; |
365 | cell *bp, *sp; |
366 | regcell so, cur_so = 0; |
366 | regcell so, cur_so = 0; |
367 | int i, ccol, j; |
367 | int i, ccol, j; |
368 | sigset_t sigset, osigset; |
368 | // sigset_t sigset, osigset; |
369 | static const struct shape *lastshape; |
369 | static const struct shape *lastshape; |
370 | 370 | ||
371 | sigemptyset(&sigset); |
371 | /* sigemptyset(&sigset); */ |
372 | sigaddset(&sigset, SIGTSTP); |
372 | /* sigaddset(&sigset, SIGTSTP); */ |
373 | (void) sigprocmask(SIG_BLOCK, &sigset, &osigset); |
373 | /* (void) sigprocmask(SIG_BLOCK, &sigset, &osigset); */ |
374 | 374 | ||
375 | /* always leave cursor after last displayed point */ |
375 | /* always leave cursor after last displayed point */ |
376 | curscreen[D_LAST * B_COLS - 1] = -1; |
376 | curscreen[D_LAST * B_COLS - 1] = -1; |
377 | 377 | ||
378 | if (score != curscore) { |
378 | if (score != curscore) { |
Line 463... | Line 463... | ||
463 | } |
463 | } |
464 | } |
464 | } |
465 | } |
465 | } |
466 | if (cur_so) |
466 | if (cur_so) |
467 | putpad(SEstr); |
467 | putpad(SEstr); |
468 | (void) fflush(stdout); |
468 | /* (void) fflush(stdout); */ |
469 | (void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); |
469 | /* (void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); */ |
470 | } |
470 | } |
471 | 471 | ||
472 | /* |
472 | /* |
473 | * Write a message (set!=0), or clear the same message (set==0). |
473 | * Write a message (set!=0), or clear the same message (set==0). |
474 | * (We need its length in case we have to overwrite with blanks.) |
474 | * (We need its length in case we have to overwrite with blanks.) |