1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 1994 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate /* 31*7c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 32*7c478bd9Sstevel@tonic-gate * The Regents of the University of California 33*7c478bd9Sstevel@tonic-gate * All Rights Reserved 34*7c478bd9Sstevel@tonic-gate * 35*7c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 36*7c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 37*7c478bd9Sstevel@tonic-gate * contributors. 38*7c478bd9Sstevel@tonic-gate */ 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate /* 43*7c478bd9Sstevel@tonic-gate * init_disp contains the initialization code for the display package, 44*7c478bd9Sstevel@tonic-gate * as well as the signal handling routines 45*7c478bd9Sstevel@tonic-gate */ 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate #include "talk.h" 48*7c478bd9Sstevel@tonic-gate #include <signal.h> 49*7c478bd9Sstevel@tonic-gate #include <libintl.h> 50*7c478bd9Sstevel@tonic-gate 51*7c478bd9Sstevel@tonic-gate #ifdef SYSV 52*7c478bd9Sstevel@tonic-gate #define signal(s, f) sigset(s, f) 53*7c478bd9Sstevel@tonic-gate #endif /* SYSV */ 54*7c478bd9Sstevel@tonic-gate 55*7c478bd9Sstevel@tonic-gate static void sig_sent(); 56*7c478bd9Sstevel@tonic-gate 57*7c478bd9Sstevel@tonic-gate /* 58*7c478bd9Sstevel@tonic-gate * set up curses, catch the appropriate signals, and build the 59*7c478bd9Sstevel@tonic-gate * various windows 60*7c478bd9Sstevel@tonic-gate */ 61*7c478bd9Sstevel@tonic-gate 62*7c478bd9Sstevel@tonic-gate void 63*7c478bd9Sstevel@tonic-gate init_display() 64*7c478bd9Sstevel@tonic-gate { 65*7c478bd9Sstevel@tonic-gate initscr(); 66*7c478bd9Sstevel@tonic-gate curses_initialized = 1; 67*7c478bd9Sstevel@tonic-gate 68*7c478bd9Sstevel@tonic-gate clear(); 69*7c478bd9Sstevel@tonic-gate refresh(); 70*7c478bd9Sstevel@tonic-gate 71*7c478bd9Sstevel@tonic-gate noecho(); 72*7c478bd9Sstevel@tonic-gate crmode(); 73*7c478bd9Sstevel@tonic-gate 74*7c478bd9Sstevel@tonic-gate signal(SIGINT, sig_sent); 75*7c478bd9Sstevel@tonic-gate signal(SIGPIPE, sig_sent); 76*7c478bd9Sstevel@tonic-gate 77*7c478bd9Sstevel@tonic-gate /* curses takes care of ^Z */ 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate my_win.x_nlines = LINES / 2; 80*7c478bd9Sstevel@tonic-gate my_win.x_ncols = COLS; 81*7c478bd9Sstevel@tonic-gate my_win.x_win = newwin(my_win.x_nlines, my_win.x_ncols, 0, 0); 82*7c478bd9Sstevel@tonic-gate scrollok(my_win.x_win, FALSE); 83*7c478bd9Sstevel@tonic-gate wclear(my_win.x_win); 84*7c478bd9Sstevel@tonic-gate 85*7c478bd9Sstevel@tonic-gate rem_win.x_nlines = LINES / 2 - 1; 86*7c478bd9Sstevel@tonic-gate rem_win.x_ncols = COLS; 87*7c478bd9Sstevel@tonic-gate rem_win.x_win = newwin(rem_win.x_nlines, rem_win.x_ncols, 88*7c478bd9Sstevel@tonic-gate my_win.x_nlines+1, 0); 89*7c478bd9Sstevel@tonic-gate scrollok(rem_win.x_win, FALSE); 90*7c478bd9Sstevel@tonic-gate wclear(rem_win.x_win); 91*7c478bd9Sstevel@tonic-gate 92*7c478bd9Sstevel@tonic-gate line_win = newwin(1, COLS, my_win.x_nlines, 0); 93*7c478bd9Sstevel@tonic-gate box(line_win, '-', '-'); 94*7c478bd9Sstevel@tonic-gate wrefresh(line_win); 95*7c478bd9Sstevel@tonic-gate 96*7c478bd9Sstevel@tonic-gate /* let them know we are working on it */ 97*7c478bd9Sstevel@tonic-gate 98*7c478bd9Sstevel@tonic-gate current_state = gettext("No connection yet"); 99*7c478bd9Sstevel@tonic-gate } 100*7c478bd9Sstevel@tonic-gate 101*7c478bd9Sstevel@tonic-gate /* 102*7c478bd9Sstevel@tonic-gate * trade edit characters with the other talk. By agreement 103*7c478bd9Sstevel@tonic-gate * the first three characters each talk transmits after 104*7c478bd9Sstevel@tonic-gate * connection are the three edit characters 105*7c478bd9Sstevel@tonic-gate */ 106*7c478bd9Sstevel@tonic-gate 107*7c478bd9Sstevel@tonic-gate void 108*7c478bd9Sstevel@tonic-gate set_edit_chars() 109*7c478bd9Sstevel@tonic-gate { 110*7c478bd9Sstevel@tonic-gate char buf[3]; 111*7c478bd9Sstevel@tonic-gate int cc; 112*7c478bd9Sstevel@tonic-gate #ifdef SYSV 113*7c478bd9Sstevel@tonic-gate struct termios tty; 114*7c478bd9Sstevel@tonic-gate ioctl(0, TCGETS, (struct termios *)&tty); 115*7c478bd9Sstevel@tonic-gate 116*7c478bd9Sstevel@tonic-gate buf[0] = my_win.cerase = tty.c_cc[VERASE]; 117*7c478bd9Sstevel@tonic-gate /* for SVID should be VERSE */ 118*7c478bd9Sstevel@tonic-gate buf[1] = my_win.kill = tty.c_cc[VKILL]; 119*7c478bd9Sstevel@tonic-gate buf[2] = my_win.werase = tty.c_cc[VWERASE]; 120*7c478bd9Sstevel@tonic-gate /* for SVID should be VWERSE */ 121*7c478bd9Sstevel@tonic-gate #else /* ! SYSV */ 122*7c478bd9Sstevel@tonic-gate struct sgttyb tty; 123*7c478bd9Sstevel@tonic-gate struct ltchars ltc; 124*7c478bd9Sstevel@tonic-gate 125*7c478bd9Sstevel@tonic-gate gtty(0, &tty); 126*7c478bd9Sstevel@tonic-gate 127*7c478bd9Sstevel@tonic-gate ioctl(0, TIOCGLTC, (struct sgttyb *)<c); 128*7c478bd9Sstevel@tonic-gate 129*7c478bd9Sstevel@tonic-gate my_win.cerase = tty.sg_erase; 130*7c478bd9Sstevel@tonic-gate my_win.kill = tty.sg_kill; 131*7c478bd9Sstevel@tonic-gate 132*7c478bd9Sstevel@tonic-gate if (ltc.t_werasc == (char)-1) { 133*7c478bd9Sstevel@tonic-gate my_win.werase = '\027'; /* control W */ 134*7c478bd9Sstevel@tonic-gate } else { 135*7c478bd9Sstevel@tonic-gate my_win.werase = ltc.t_werasc; 136*7c478bd9Sstevel@tonic-gate } 137*7c478bd9Sstevel@tonic-gate 138*7c478bd9Sstevel@tonic-gate buf[0] = my_win.cerase; 139*7c478bd9Sstevel@tonic-gate buf[1] = my_win.kill; 140*7c478bd9Sstevel@tonic-gate buf[2] = my_win.werase; 141*7c478bd9Sstevel@tonic-gate #endif /* SYSV */ 142*7c478bd9Sstevel@tonic-gate 143*7c478bd9Sstevel@tonic-gate cc = write(sockt, buf, sizeof (buf)); 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gate if (cc != sizeof (buf)) { 146*7c478bd9Sstevel@tonic-gate p_error(gettext("Lost the connection")); 147*7c478bd9Sstevel@tonic-gate } 148*7c478bd9Sstevel@tonic-gate 149*7c478bd9Sstevel@tonic-gate cc = read(sockt, buf, sizeof (buf)); 150*7c478bd9Sstevel@tonic-gate 151*7c478bd9Sstevel@tonic-gate if (cc != sizeof (buf)) { 152*7c478bd9Sstevel@tonic-gate p_error(gettext("Lost the connection")); 153*7c478bd9Sstevel@tonic-gate } 154*7c478bd9Sstevel@tonic-gate 155*7c478bd9Sstevel@tonic-gate rem_win.cerase = buf[0]; 156*7c478bd9Sstevel@tonic-gate rem_win.kill = buf[1]; 157*7c478bd9Sstevel@tonic-gate rem_win.werase = buf[2]; 158*7c478bd9Sstevel@tonic-gate } 159*7c478bd9Sstevel@tonic-gate 160*7c478bd9Sstevel@tonic-gate static void 161*7c478bd9Sstevel@tonic-gate sig_sent() 162*7c478bd9Sstevel@tonic-gate { 163*7c478bd9Sstevel@tonic-gate message(gettext("Connection closing. Exiting")); 164*7c478bd9Sstevel@tonic-gate quit(); 165*7c478bd9Sstevel@tonic-gate } 166*7c478bd9Sstevel@tonic-gate 167*7c478bd9Sstevel@tonic-gate /* 168*7c478bd9Sstevel@tonic-gate * All done talking...hang up the phone and reset terminal thingy's 169*7c478bd9Sstevel@tonic-gate */ 170*7c478bd9Sstevel@tonic-gate 171*7c478bd9Sstevel@tonic-gate void 172*7c478bd9Sstevel@tonic-gate quit() 173*7c478bd9Sstevel@tonic-gate { 174*7c478bd9Sstevel@tonic-gate if (curses_initialized) { 175*7c478bd9Sstevel@tonic-gate wmove(rem_win.x_win, rem_win.x_nlines-1, 0); 176*7c478bd9Sstevel@tonic-gate wclrtoeol(rem_win.x_win); 177*7c478bd9Sstevel@tonic-gate wrefresh(rem_win.x_win); 178*7c478bd9Sstevel@tonic-gate endwin(); 179*7c478bd9Sstevel@tonic-gate } 180*7c478bd9Sstevel@tonic-gate 181*7c478bd9Sstevel@tonic-gate if (invitation_waiting) { 182*7c478bd9Sstevel@tonic-gate send_delete(); 183*7c478bd9Sstevel@tonic-gate } 184*7c478bd9Sstevel@tonic-gate 185*7c478bd9Sstevel@tonic-gate exit(0); 186*7c478bd9Sstevel@tonic-gate } 187