init_disp.c revision 1.10 1 /* $NetBSD: init_disp.c,v 1.10 2001/12/07 12:10:09 blymn Exp $ */
2
3 /*
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36 #include <sys/cdefs.h>
37 #ifndef lint
38 #if 0
39 static char sccsid[] = "@(#)init_disp.c 8.2 (Berkeley) 2/16/94";
40 #endif
41 __RCSID("$NetBSD: init_disp.c,v 1.10 2001/12/07 12:10:09 blymn Exp $");
42 #endif /* not lint */
43
44 /*
45 * Initialization code for the display package,
46 * as well as the signal handling routines.
47 */
48
49 #include "talk.h"
50 #include <sys/ioctl.h>
51 #include <sys/ioctl_compat.h>
52 #include <err.h>
53 #include <signal.h>
54 #include <termios.h>
55 #include <stdlib.h>
56 #include <unistd.h>
57
58 /*
59 * Set up curses, catch the appropriate signals,
60 * and build the various windows.
61 */
62 void
63 init_display()
64 {
65 struct sigaction sa;
66
67 if (initscr() == NULL)
68 errx(1, "Terminal type unset or lacking necessary features.");
69 (void)sigaction(SIGTSTP, NULL, &sa);
70 sigaddset(&sa.sa_mask, SIGALRM);
71 (void)sigaction(SIGTSTP, &sa, NULL);
72 curses_initialized = 1;
73 clear();
74 refresh();
75 noecho();
76 cbreak();
77 signal(SIGINT, sig_sent);
78 signal(SIGPIPE, sig_sent);
79 /* curses takes care of ^Z */
80 my_win.x_nlines = LINES / 2;
81 my_win.x_ncols = COLS;
82 my_win.x_win = newwin(my_win.x_nlines, my_win.x_ncols, 0, 0);
83 scrollok(my_win.x_win, FALSE);
84 wclear(my_win.x_win);
85
86 his_win.x_nlines = LINES / 2 - 1;
87 his_win.x_ncols = COLS;
88 his_win.x_win = newwin(his_win.x_nlines, his_win.x_ncols,
89 my_win.x_nlines+1, 0);
90 scrollok(his_win.x_win, FALSE);
91 wclear(his_win.x_win);
92
93 line_win = newwin(1, COLS, my_win.x_nlines, 0);
94 box(line_win, '-', '-');
95 wrefresh(line_win);
96 /* let them know we are working on it */
97 current_state = "No connection yet";
98 }
99
100 /*
101 * Trade edit characters with the other talk. By agreement
102 * the first three characters each talk transmits after
103 * connection are the three edit characters.
104 */
105 void
106 set_edit_chars()
107 {
108 char buf[3];
109 int cc;
110 struct termios tty;
111
112 tcgetattr(0, &tty);
113 my_win.cerase = tty.c_cc[VERASE];
114 my_win.kill = tty.c_cc[VKILL];
115 if (tty.c_cc[VWERASE] == (unsigned char) -1)
116 my_win.werase = '\027'; /* control W */
117 else
118 my_win.werase = tty.c_cc[VWERASE];
119 buf[0] = my_win.cerase;
120 buf[1] = my_win.kill;
121 buf[2] = my_win.werase;
122 cc = write(sockt, buf, sizeof(buf));
123 if (cc != sizeof(buf) )
124 p_error("Lost the connection");
125 cc = read(sockt, buf, sizeof(buf));
126 if (cc != sizeof(buf) )
127 p_error("Lost the connection");
128 his_win.cerase = buf[0];
129 his_win.kill = buf[1];
130 his_win.werase = buf[2];
131 }
132
133 void
134 sig_sent(dummy)
135 int dummy;
136 {
137
138 message("Connection closing. Exiting");
139 quit();
140 }
141
142 /*
143 * All done talking...hang up the phone and reset terminal thingy's
144 */
145 void
146 quit()
147 {
148
149 if (curses_initialized) {
150 wmove(his_win.x_win, his_win.x_nlines-1, 0);
151 wclrtoeol(his_win.x_win);
152 wrefresh(his_win.x_win);
153 endwin();
154 }
155 if (invitation_waiting)
156 send_delete();
157 exit(0);
158 }
159