1 /* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by the University of 16 * California, Berkeley and its contributors. 17 * 4. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34 #ifndef lint 35 static char sccsid[] = "@(#)init_disp.c 8.2 (Berkeley) 2/16/94"; 36 #endif /* not lint */ 37 38 /* 39 * Initialization code for the display package, 40 * as well as the signal handling routines. 41 */ 42 43 #include <sys/ioctl.h> 44 #include <sys/ioctl_compat.h> 45 46 #include <signal.h> 47 #include <err.h> 48 #include "talk.h" 49 50 /* 51 * Set up curses, catch the appropriate signals, 52 * and build the various windows. 53 */ 54 init_display() 55 { 56 void sig_sent(); 57 struct sigvec sigv; 58 59 if (initscr() == NULL) 60 errx(1, "Terminal type unset or lacking necessary features."); 61 (void) sigvec(SIGTSTP, (struct sigvec *)0, &sigv); 62 sigv.sv_mask |= sigmask(SIGALRM); 63 (void) sigvec(SIGTSTP, &sigv, (struct sigvec *)0); 64 curses_initialized = 1; 65 clear(); 66 refresh(); 67 noecho(); 68 crmode(); 69 signal(SIGINT, sig_sent); 70 signal(SIGPIPE, sig_sent); 71 /* curses takes care of ^Z */ 72 my_win.x_nlines = LINES / 2; 73 my_win.x_ncols = COLS; 74 my_win.x_win = newwin(my_win.x_nlines, my_win.x_ncols, 0, 0); 75 scrollok(my_win.x_win, FALSE); 76 wclear(my_win.x_win); 77 78 his_win.x_nlines = LINES / 2 - 1; 79 his_win.x_ncols = COLS; 80 his_win.x_win = newwin(his_win.x_nlines, his_win.x_ncols, 81 my_win.x_nlines+1, 0); 82 scrollok(his_win.x_win, FALSE); 83 wclear(his_win.x_win); 84 85 line_win = newwin(1, COLS, my_win.x_nlines, 0); 86 box(line_win, '-', '-'); 87 wrefresh(line_win); 88 /* let them know we are working on it */ 89 current_state = "No connection yet"; 90 } 91 92 /* 93 * Trade edit characters with the other talk. By agreement 94 * the first three characters each talk transmits after 95 * connection are the three edit characters. 96 */ 97 set_edit_chars() 98 { 99 char buf[3]; 100 int cc; 101 struct sgttyb tty; 102 struct ltchars ltc; 103 104 ioctl(0, TIOCGETP, &tty); 105 ioctl(0, TIOCGLTC, (struct sgttyb *)<c); 106 my_win.cerase = tty.sg_erase; 107 my_win.kill = tty.sg_kill; 108 if (ltc.t_werasc == (char) -1) 109 my_win.werase = '\027'; /* control W */ 110 else 111 my_win.werase = ltc.t_werasc; 112 buf[0] = my_win.cerase; 113 buf[1] = my_win.kill; 114 buf[2] = my_win.werase; 115 cc = write(sockt, buf, sizeof(buf)); 116 if (cc != sizeof(buf) ) 117 p_error("Lost the connection"); 118 cc = read(sockt, buf, sizeof(buf)); 119 if (cc != sizeof(buf) ) 120 p_error("Lost the connection"); 121 his_win.cerase = buf[0]; 122 his_win.kill = buf[1]; 123 his_win.werase = buf[2]; 124 } 125 126 void 127 sig_sent() 128 { 129 130 message("Connection closing. Exiting"); 131 quit(); 132 } 133 134 /* 135 * All done talking...hang up the phone and reset terminal thingy's 136 */ 137 quit() 138 { 139 140 if (curses_initialized) { 141 wmove(his_win.x_win, his_win.x_nlines-1, 0); 142 wclrtoeol(his_win.x_win); 143 wrefresh(his_win.x_win); 144 endwin(); 145 } 146 if (invitation_waiting) 147 send_delete(); 148 exit(0); 149 } 150