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