8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / cmd-inet / usr.bin / talk / init_disp.c
bloba756651191455212d9a8dd0a33b0cac6e9e9a4a5
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
23 * Copyright 1994 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
33 * All Rights Reserved
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
37 * contributors.
40 #pragma ident "%Z%%M% %I% %E% SMI"
43 * init_disp contains the initialization code for the display package,
44 * as well as the signal handling routines
47 #include "talk.h"
48 #include <signal.h>
49 #include <libintl.h>
51 #ifdef SYSV
52 #define signal(s, f) sigset(s, f)
53 #endif /* SYSV */
55 static void sig_sent();
58 * set up curses, catch the appropriate signals, and build the
59 * various windows
62 void
63 init_display()
65 initscr();
66 curses_initialized = 1;
68 clear();
69 refresh();
71 noecho();
72 crmode();
74 signal(SIGINT, sig_sent);
75 signal(SIGPIPE, sig_sent);
77 /* curses takes care of ^Z */
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);
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);
92 line_win = newwin(1, COLS, my_win.x_nlines, 0);
93 box(line_win, '-', '-');
94 wrefresh(line_win);
96 /* let them know we are working on it */
98 current_state = gettext("No connection yet");
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
107 void
108 set_edit_chars()
110 char buf[3];
111 int cc;
112 #ifdef SYSV
113 struct termios tty;
114 ioctl(0, TCGETS, (struct termios *)&tty);
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;
125 gtty(0, &tty);
127 ioctl(0, TIOCGLTC, (struct sgttyb *)&ltc);
129 my_win.cerase = tty.sg_erase;
130 my_win.kill = tty.sg_kill;
132 if (ltc.t_werasc == (char)-1) {
133 my_win.werase = '\027'; /* control W */
134 } else {
135 my_win.werase = ltc.t_werasc;
138 buf[0] = my_win.cerase;
139 buf[1] = my_win.kill;
140 buf[2] = my_win.werase;
141 #endif /* SYSV */
143 cc = write(sockt, buf, sizeof (buf));
145 if (cc != sizeof (buf)) {
146 p_error(gettext("Lost the connection"));
149 cc = read(sockt, buf, sizeof (buf));
151 if (cc != sizeof (buf)) {
152 p_error(gettext("Lost the connection"));
155 rem_win.cerase = buf[0];
156 rem_win.kill = buf[1];
157 rem_win.werase = buf[2];
160 static void
161 sig_sent()
163 message(gettext("Connection closing. Exiting"));
164 quit();
168 * All done talking...hang up the phone and reset terminal thingy's
171 void
172 quit()
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();
181 if (invitation_waiting) {
182 send_delete();
185 exit(0);