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