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