1 /* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)init_disp.c 8.1 (Berkeley) 06/06/93"; 10 #endif /* not lint */ 11 12 /* 13 * Initialization code for the display package, 14 * as well as the signal handling routines. 15 */ 16 17 #include <sys/ioctl.h> 18 #include <sys/ioctl_compat.h> 19 #include <signal.h> 20 #include "talk.h" 21 22 /* 23 * Set up curses, catch the appropriate signals, 24 * and build the various windows. 25 */ 26 init_display() 27 { 28 void sig_sent(); 29 struct sigvec sigv; 30 31 initscr(); 32 (void) sigvec(SIGTSTP, (struct sigvec *)0, &sigv); 33 sigv.sv_mask |= sigmask(SIGALRM); 34 (void) sigvec(SIGTSTP, &sigv, (struct sigvec *)0); 35 curses_initialized = 1; 36 clear(); 37 refresh(); 38 noecho(); 39 crmode(); 40 signal(SIGINT, sig_sent); 41 signal(SIGPIPE, sig_sent); 42 /* curses takes care of ^Z */ 43 my_win.x_nlines = LINES / 2; 44 my_win.x_ncols = COLS; 45 my_win.x_win = newwin(my_win.x_nlines, my_win.x_ncols, 0, 0); 46 scrollok(my_win.x_win, FALSE); 47 wclear(my_win.x_win); 48 49 his_win.x_nlines = LINES / 2 - 1; 50 his_win.x_ncols = COLS; 51 his_win.x_win = newwin(his_win.x_nlines, his_win.x_ncols, 52 my_win.x_nlines+1, 0); 53 scrollok(his_win.x_win, FALSE); 54 wclear(his_win.x_win); 55 56 line_win = newwin(1, COLS, my_win.x_nlines, 0); 57 box(line_win, '-', '-'); 58 wrefresh(line_win); 59 /* let them know we are working on it */ 60 current_state = "No connection yet"; 61 } 62 63 /* 64 * Trade edit characters with the other talk. By agreement 65 * the first three characters each talk transmits after 66 * connection are the three edit characters. 67 */ 68 set_edit_chars() 69 { 70 char buf[3]; 71 int cc; 72 struct sgttyb tty; 73 struct ltchars ltc; 74 75 ioctl(0, TIOCGETP, &tty); 76 ioctl(0, TIOCGLTC, (struct sgttyb *)<c); 77 my_win.cerase = tty.sg_erase; 78 my_win.kill = tty.sg_kill; 79 if (ltc.t_werasc == (char) -1) 80 my_win.werase = '\027'; /* control W */ 81 else 82 my_win.werase = ltc.t_werasc; 83 buf[0] = my_win.cerase; 84 buf[1] = my_win.kill; 85 buf[2] = my_win.werase; 86 cc = write(sockt, buf, sizeof(buf)); 87 if (cc != sizeof(buf) ) 88 p_error("Lost the connection"); 89 cc = read(sockt, buf, sizeof(buf)); 90 if (cc != sizeof(buf) ) 91 p_error("Lost the connection"); 92 his_win.cerase = buf[0]; 93 his_win.kill = buf[1]; 94 his_win.werase = buf[2]; 95 } 96 97 void 98 sig_sent() 99 { 100 101 message("Connection closing. Exiting"); 102 quit(); 103 } 104 105 /* 106 * All done talking...hang up the phone and reset terminal thingy's 107 */ 108 quit() 109 { 110 111 if (curses_initialized) { 112 wmove(his_win.x_win, his_win.x_nlines-1, 0); 113 wclrtoeol(his_win.x_win); 114 wrefresh(his_win.x_win); 115 endwin(); 116 } 117 if (invitation_waiting) 118 send_delete(); 119 exit(0); 120 } 121