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 /*
41*7c478bd9Sstevel@tonic-gate  * init_disp contains the initialization code for the display package,
42*7c478bd9Sstevel@tonic-gate  * as well as the signal handling routines
43*7c478bd9Sstevel@tonic-gate  */
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate #include "talk.h"
46*7c478bd9Sstevel@tonic-gate #include <signal.h>
47*7c478bd9Sstevel@tonic-gate #include <libintl.h>
48*7c478bd9Sstevel@tonic-gate 
49*7c478bd9Sstevel@tonic-gate #ifdef SYSV
50*7c478bd9Sstevel@tonic-gate #define	signal(s, f)	sigset(s, f)
51*7c478bd9Sstevel@tonic-gate #endif /* SYSV */
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate static void sig_sent();
54*7c478bd9Sstevel@tonic-gate 
55*7c478bd9Sstevel@tonic-gate /*
56*7c478bd9Sstevel@tonic-gate  * set up curses, catch the appropriate signals, and build the
57*7c478bd9Sstevel@tonic-gate  * various windows
58*7c478bd9Sstevel@tonic-gate  */
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate void
init_display()61*7c478bd9Sstevel@tonic-gate init_display()
62*7c478bd9Sstevel@tonic-gate {
63*7c478bd9Sstevel@tonic-gate 	initscr();
64*7c478bd9Sstevel@tonic-gate 	curses_initialized = 1;
65*7c478bd9Sstevel@tonic-gate 
66*7c478bd9Sstevel@tonic-gate 	clear();
67*7c478bd9Sstevel@tonic-gate 	refresh();
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate 	noecho();
70*7c478bd9Sstevel@tonic-gate 	crmode();
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate 	signal(SIGINT, sig_sent);
73*7c478bd9Sstevel@tonic-gate 	signal(SIGPIPE, sig_sent);
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate 	/* curses takes care of ^Z */
76*7c478bd9Sstevel@tonic-gate 
77*7c478bd9Sstevel@tonic-gate 	my_win.x_nlines = LINES / 2;
78*7c478bd9Sstevel@tonic-gate 	my_win.x_ncols = COLS;
79*7c478bd9Sstevel@tonic-gate 	my_win.x_win = newwin(my_win.x_nlines, my_win.x_ncols, 0, 0);
80*7c478bd9Sstevel@tonic-gate 	scrollok(my_win.x_win, FALSE);
81*7c478bd9Sstevel@tonic-gate 	wclear(my_win.x_win);
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate 	rem_win.x_nlines = LINES / 2 - 1;
84*7c478bd9Sstevel@tonic-gate 	rem_win.x_ncols = COLS;
85*7c478bd9Sstevel@tonic-gate 	rem_win.x_win = newwin(rem_win.x_nlines, rem_win.x_ncols,
86*7c478bd9Sstevel@tonic-gate 						my_win.x_nlines+1, 0);
87*7c478bd9Sstevel@tonic-gate 	scrollok(rem_win.x_win, FALSE);
88*7c478bd9Sstevel@tonic-gate 	wclear(rem_win.x_win);
89*7c478bd9Sstevel@tonic-gate 
90*7c478bd9Sstevel@tonic-gate 	line_win = newwin(1, COLS, my_win.x_nlines, 0);
91*7c478bd9Sstevel@tonic-gate 	box(line_win, '-', '-');
92*7c478bd9Sstevel@tonic-gate 	wrefresh(line_win);
93*7c478bd9Sstevel@tonic-gate 
94*7c478bd9Sstevel@tonic-gate 	/* let them know we are working on it */
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate 	current_state = gettext("No connection yet");
97*7c478bd9Sstevel@tonic-gate }
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate 	/*
100*7c478bd9Sstevel@tonic-gate 	 * trade edit characters with the other talk. By agreement
101*7c478bd9Sstevel@tonic-gate 	 * the first three characters each talk transmits after
102*7c478bd9Sstevel@tonic-gate 	 * connection are the three edit characters
103*7c478bd9Sstevel@tonic-gate 	 */
104*7c478bd9Sstevel@tonic-gate 
105*7c478bd9Sstevel@tonic-gate void
set_edit_chars()106*7c478bd9Sstevel@tonic-gate set_edit_chars()
107*7c478bd9Sstevel@tonic-gate {
108*7c478bd9Sstevel@tonic-gate 	char buf[3];
109*7c478bd9Sstevel@tonic-gate 	int cc;
110*7c478bd9Sstevel@tonic-gate #ifdef SYSV
111*7c478bd9Sstevel@tonic-gate 	struct termios tty;
112*7c478bd9Sstevel@tonic-gate 	ioctl(0, TCGETS, (struct termios *)&tty);
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate 	buf[0] = my_win.cerase = tty.c_cc[VERASE];
115*7c478bd9Sstevel@tonic-gate 					/* for SVID should be VERSE */
116*7c478bd9Sstevel@tonic-gate 	buf[1] = my_win.kill = tty.c_cc[VKILL];
117*7c478bd9Sstevel@tonic-gate 	buf[2] = my_win.werase = tty.c_cc[VWERASE];
118*7c478bd9Sstevel@tonic-gate 					/* for SVID should be VWERSE */
119*7c478bd9Sstevel@tonic-gate #else /* ! SYSV */
120*7c478bd9Sstevel@tonic-gate 	struct sgttyb tty;
121*7c478bd9Sstevel@tonic-gate 	struct ltchars ltc;
122*7c478bd9Sstevel@tonic-gate 
123*7c478bd9Sstevel@tonic-gate 	gtty(0, &tty);
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate 	ioctl(0, TIOCGLTC, (struct sgttyb *)&ltc);
126*7c478bd9Sstevel@tonic-gate 
127*7c478bd9Sstevel@tonic-gate 	my_win.cerase = tty.sg_erase;
128*7c478bd9Sstevel@tonic-gate 	my_win.kill = tty.sg_kill;
129*7c478bd9Sstevel@tonic-gate 
130*7c478bd9Sstevel@tonic-gate 	if (ltc.t_werasc == (char)-1) {
131*7c478bd9Sstevel@tonic-gate 		my_win.werase = '\027';	 /* control W */
132*7c478bd9Sstevel@tonic-gate 	} else {
133*7c478bd9Sstevel@tonic-gate 		my_win.werase = ltc.t_werasc;
134*7c478bd9Sstevel@tonic-gate 	}
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate 	buf[0] = my_win.cerase;
137*7c478bd9Sstevel@tonic-gate 	buf[1] = my_win.kill;
138*7c478bd9Sstevel@tonic-gate 	buf[2] = my_win.werase;
139*7c478bd9Sstevel@tonic-gate #endif /* SYSV */
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate 	cc = write(sockt, buf, sizeof (buf));
142*7c478bd9Sstevel@tonic-gate 
143*7c478bd9Sstevel@tonic-gate 	if (cc != sizeof (buf)) {
144*7c478bd9Sstevel@tonic-gate 		p_error(gettext("Lost the connection"));
145*7c478bd9Sstevel@tonic-gate 	}
146*7c478bd9Sstevel@tonic-gate 
147*7c478bd9Sstevel@tonic-gate 	cc = read(sockt, buf, sizeof (buf));
148*7c478bd9Sstevel@tonic-gate 
149*7c478bd9Sstevel@tonic-gate 	if (cc != sizeof (buf)) {
150*7c478bd9Sstevel@tonic-gate 		p_error(gettext("Lost the connection"));
151*7c478bd9Sstevel@tonic-gate 	}
152*7c478bd9Sstevel@tonic-gate 
153*7c478bd9Sstevel@tonic-gate 	rem_win.cerase = buf[0];
154*7c478bd9Sstevel@tonic-gate 	rem_win.kill = buf[1];
155*7c478bd9Sstevel@tonic-gate 	rem_win.werase = buf[2];
156*7c478bd9Sstevel@tonic-gate }
157*7c478bd9Sstevel@tonic-gate 
158*7c478bd9Sstevel@tonic-gate static void
sig_sent()159*7c478bd9Sstevel@tonic-gate sig_sent()
160*7c478bd9Sstevel@tonic-gate {
161*7c478bd9Sstevel@tonic-gate 	message(gettext("Connection closing. Exiting"));
162*7c478bd9Sstevel@tonic-gate 	quit();
163*7c478bd9Sstevel@tonic-gate }
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate /*
166*7c478bd9Sstevel@tonic-gate  * All done talking...hang up the phone and reset terminal thingy's
167*7c478bd9Sstevel@tonic-gate  */
168*7c478bd9Sstevel@tonic-gate 
169*7c478bd9Sstevel@tonic-gate void
quit()170*7c478bd9Sstevel@tonic-gate quit()
171*7c478bd9Sstevel@tonic-gate {
172*7c478bd9Sstevel@tonic-gate 	if (curses_initialized) {
173*7c478bd9Sstevel@tonic-gate 		wmove(rem_win.x_win, rem_win.x_nlines-1, 0);
174*7c478bd9Sstevel@tonic-gate 		wclrtoeol(rem_win.x_win);
175*7c478bd9Sstevel@tonic-gate 		wrefresh(rem_win.x_win);
176*7c478bd9Sstevel@tonic-gate 		endwin();
177*7c478bd9Sstevel@tonic-gate 	}
178*7c478bd9Sstevel@tonic-gate 
179*7c478bd9Sstevel@tonic-gate 	if (invitation_waiting) {
180*7c478bd9Sstevel@tonic-gate 		send_delete();
181*7c478bd9Sstevel@tonic-gate 	}
182*7c478bd9Sstevel@tonic-gate 
183*7c478bd9Sstevel@tonic-gate 	exit(0);
184*7c478bd9Sstevel@tonic-gate }
185