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