1 | /* $NetBSD: init_disp.c,v 1.6 1994/12/09 02:14:17 jtc 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 | #ifndef lint |
---|
37 | #if 0 |
---|
38 | static char sccsid[] = "@(#)init_disp.c 8.2 (Berkeley) 2/16/94"; |
---|
39 | #endif |
---|
40 | static char rcsid[] = "$NetBSD: init_disp.c,v 1.6 1994/12/09 02:14:17 jtc Exp $"; |
---|
41 | #endif /* not lint */ |
---|
42 | |
---|
43 | /* |
---|
44 | * Initialization code for the display package, |
---|
45 | * as well as the signal handling routines. |
---|
46 | */ |
---|
47 | |
---|
48 | #include <sys/ioctl.h> |
---|
49 | |
---|
50 | #include <termios.h> |
---|
51 | #include <signal.h> |
---|
52 | #include "talk.h" |
---|
53 | |
---|
54 | /* |
---|
55 | * Set up curses, catch the appropriate signals, |
---|
56 | * and build the various windows. |
---|
57 | */ |
---|
58 | init_display() |
---|
59 | { |
---|
60 | void sig_sent(); |
---|
61 | struct sigaction action; |
---|
62 | |
---|
63 | if (initscr() == NULL) { |
---|
64 | fprintf(stderr, "talk: Terminal type unset or lacking necessary features.\n"); |
---|
65 | exit(1); |
---|
66 | } |
---|
67 | sigaction(SIGTSTP, NULL, &action); |
---|
68 | sigaddset(&action.sa_mask, SIGALRM); |
---|
69 | sigaction(SIGTSTP, &action, NULL); |
---|
70 | curses_initialized = 1; |
---|
71 | clear(); |
---|
72 | refresh(); |
---|
73 | noecho(); |
---|
74 | crmode(); |
---|
75 | action.sa_handler = sig_sent; |
---|
76 | sigemptyset(&action.sa_mask); |
---|
77 | action.sa_flags = 0; |
---|
78 | sigaction(SIGINT, &action, NULL); |
---|
79 | sigaction(SIGPIPE, &action, NULL); |
---|
80 | /* curses takes care of ^Z */ |
---|
81 | my_win.x_nlines = LINES / 2; |
---|
82 | my_win.x_ncols = COLS; |
---|
83 | my_win.x_win = newwin(my_win.x_nlines, my_win.x_ncols, 0, 0); |
---|
84 | scrollok(my_win.x_win, FALSE); |
---|
85 | wclear(my_win.x_win); |
---|
86 | |
---|
87 | his_win.x_nlines = LINES / 2 - 1; |
---|
88 | his_win.x_ncols = COLS; |
---|
89 | his_win.x_win = newwin(his_win.x_nlines, his_win.x_ncols, |
---|
90 | my_win.x_nlines+1, 0); |
---|
91 | scrollok(his_win.x_win, FALSE); |
---|
92 | wclear(his_win.x_win); |
---|
93 | |
---|
94 | line_win = newwin(1, COLS, my_win.x_nlines, 0); |
---|
95 | box(line_win, '-', '-'); |
---|
96 | wrefresh(line_win); |
---|
97 | /* let them know we are working on it */ |
---|
98 | current_state = "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 | 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() |
---|
135 | { |
---|
136 | |
---|
137 | message("Connection closing. Exiting"); |
---|
138 | quit(); |
---|
139 | } |
---|
140 | |
---|
141 | /* |
---|
142 | * All done talking...hang up the phone and reset terminal thingy's |
---|
143 | */ |
---|
144 | quit() |
---|
145 | { |
---|
146 | |
---|
147 | if (curses_initialized) { |
---|
148 | wmove(his_win.x_win, his_win.x_nlines-1, 0); |
---|
149 | wclrtoeol(his_win.x_win); |
---|
150 | wrefresh(his_win.x_win); |
---|
151 | endwin(); |
---|
152 | } |
---|
153 | if (invitation_waiting) |
---|
154 | send_delete(); |
---|
155 | exit(0); |
---|
156 | } |
---|