1 /* $NetBSD: init_disp.c,v 1.6 1994/12/09 02:14:17 jtc 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 #ifndef lint 37 #if 0 38 static char sccsid[] = "@(#)init_disp.c 8.2 (Berkeley) 2/16/94"; 39 #endif 40 static char rcsid[] = "$NetBSD: init_disp.c,v 1.6 1994/12/09 02:14:17 jtc Exp $"; 41 #endif /* not lint */ 42 43 /* 44 * Initialization code for the display package, 45 * as well as the signal handling routines. 46 */ 47 48 #include <sys/ioctl.h> 49 #include <sys/ioctl_compat.h> 50 51 #include <termios.h> 52 #include <signal.h> 53 #include <err.h> 54 #include "talk.h" 55 56 /* 57 * Set up curses, catch the appropriate signals, 58 * and build the various windows. 59 */ 60 init_display() 61 { 62 void sig_sent(); 63 struct sigvec sigv; 64 65 if (initscr() == NULL) 66 errx(1, "Terminal type unset or lacking necessary features."); 67 (void) sigvec(SIGTSTP, (struct sigvec *)0, &sigv); 68 sigv.sv_mask |= sigmask(SIGALRM); 69 (void) sigvec(SIGTSTP, &sigv, (struct sigvec *)0); 70 curses_initialized = 1; 71 clear(); 72 refresh(); 73 noecho(); 74 crmode(); 75 signal(SIGINT, sig_sent); 76 signal(SIGPIPE, sig_sent); 77 /* curses takes care of ^Z */ 78 my_win.x_nlines = LINES / 2; 79 my_win.x_ncols = COLS; 80 my_win.x_win = newwin(my_win.x_nlines, my_win.x_ncols, 0, 0); 81 scrollok(my_win.x_win, FALSE); 82 wclear(my_win.x_win); 83 84 his_win.x_nlines = LINES / 2 - 1; 85 his_win.x_ncols = COLS; 86 his_win.x_win = newwin(his_win.x_nlines, his_win.x_ncols, 87 my_win.x_nlines+1, 0); 88 scrollok(his_win.x_win, FALSE); 89 wclear(his_win.x_win); 90 91 line_win = newwin(1, COLS, my_win.x_nlines, 0); 92 box(line_win, '-', '-'); 93 wrefresh(line_win); 94 /* let them know we are working on it */ 95 current_state = "No connection yet"; 96 } 97 98 /* 99 * Trade edit characters with the other talk. By agreement 100 * the first three characters each talk transmits after 101 * connection are the three edit characters. 102 */ 103 set_edit_chars() 104 { 105 char buf[3]; 106 int cc; 107 struct termios tty; 108 109 tcgetattr(0, &tty); 110 my_win.cerase = tty.c_cc[VERASE]; 111 my_win.kill = tty.c_cc[VKILL]; 112 if (tty.c_cc[VWERASE] == (unsigned char) -1) 113 my_win.werase = '\027'; /* control W */ 114 else 115 my_win.werase = tty.c_cc[VWERASE]; 116 buf[0] = my_win.cerase; 117 buf[1] = my_win.kill; 118 buf[2] = my_win.werase; 119 cc = write(sockt, buf, sizeof(buf)); 120 if (cc != sizeof(buf) ) 121 p_error("Lost the connection"); 122 cc = read(sockt, buf, sizeof(buf)); 123 if (cc != sizeof(buf) ) 124 p_error("Lost the connection"); 125 his_win.cerase = buf[0]; 126 his_win.kill = buf[1]; 127 his_win.werase = buf[2]; 128 } 129 130 void 131 sig_sent() 132 { 133 134 message("Connection closing. Exiting"); 135 quit(); 136 } 137 138 /* 139 * All done talking...hang up the phone and reset terminal thingy's 140 */ 141 quit() 142 { 143 144 if (curses_initialized) { 145 wmove(his_win.x_win, his_win.x_nlines-1, 0); 146 wclrtoeol(his_win.x_win); 147 wrefresh(his_win.x_win); 148 endwin(); 149 } 150 if (invitation_waiting) 151 send_delete(); 152 exit(0); 153 } 154