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