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