1 /*-
2 * Copyright (c) 1983, 1985
3 * The Regents of the University of California. All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8 #ifndef lint
9 static char sccsid[] = "@(#)init_disp.c 5.1 (Berkeley) 6/6/85";
10 #endif not lint
11
12 /*
13 * Initialization code for the display package,
14 * as well as the signal handling routines.
15 */
16
17 #define USE_OLD_TTY
18 #include "talk.h"
19 #include <sgtty.h>
20 #include <stdlib.h>
21 #include <signal.h>
22 #include <unistd.h>
23
24 void sig_sent();
25
26 /*
27 * Set up curses, catch the appropriate signals,
28 * and build the various windows.
29 */
30 void
init_display()31 init_display()
32 {
33 struct sigvec sigv;
34
35 initscr();
36 (void) sigvec(SIGTSTP, (struct sigvec *)0, &sigv);
37 sigv.sv_mask |= sigmask(SIGALRM);
38 (void) sigvec(SIGTSTP, &sigv, (struct sigvec *)0);
39 curses_initialized = 1;
40 clear();
41 refresh();
42 noecho();
43 crmode();
44 signal(SIGINT, sig_sent);
45 signal(SIGPIPE, sig_sent);
46 /* curses takes care of ^Z */
47 my_win.x_nlines = LINES / 2;
48 my_win.x_ncols = COLS;
49 my_win.x_win = newwin(my_win.x_nlines, my_win.x_ncols, 0, 0);
50 scrollok(my_win.x_win, FALSE);
51 wclear(my_win.x_win);
52
53 his_win.x_nlines = LINES / 2 - 1;
54 his_win.x_ncols = COLS;
55 his_win.x_win = newwin(his_win.x_nlines, his_win.x_ncols,
56 my_win.x_nlines+1, 0);
57 scrollok(his_win.x_win, FALSE);
58 wclear(his_win.x_win);
59
60 line_win = newwin(1, COLS, my_win.x_nlines, 0);
61 box(line_win, '-', '-');
62 wrefresh(line_win);
63 /* let them know we are working on it */
64 current_state = "No connection yet";
65 }
66
67 /*
68 * Trade edit characters with the other talk. By agreement
69 * the first three characters each talk transmits after
70 * connection are the three edit characters.
71 */
72 void
set_edit_chars()73 set_edit_chars()
74 {
75 char buf[3];
76 int cc;
77 struct sgttyb tty;
78 struct ltchars ltc;
79
80 ioctl(0, TIOCGETP, &tty);
81 ioctl(0, TIOCGLTC, (struct sgttyb *)<c);
82 my_win.cerase = tty.sg_erase;
83 my_win.kill = tty.sg_kill;
84 if (ltc.t_werasc == (char) -1)
85 my_win.werase = '\027'; /* control W */
86 else
87 my_win.werase = ltc.t_werasc;
88 buf[0] = my_win.cerase;
89 buf[1] = my_win.kill;
90 buf[2] = my_win.werase;
91 cc = write(sockt, buf, sizeof(buf));
92 if (cc != sizeof(buf) )
93 p_error("Lost the connection");
94 cc = read(sockt, buf, sizeof(buf));
95 if (cc != sizeof(buf) )
96 p_error("Lost the connection");
97 his_win.cerase = buf[0];
98 his_win.kill = buf[1];
99 his_win.werase = buf[2];
100 }
101
102 void
sig_sent()103 sig_sent()
104 {
105
106 message("Connection closing. Exiting");
107 quit();
108 }
109
110 /*
111 * All done talking...hang up the phone and reset terminal thingy's
112 */
113 __dead void
quit()114 quit()
115 {
116
117 if (curses_initialized) {
118 wmove(his_win.x_win, his_win.x_nlines-1, 0);
119 wclrtoeol(his_win.x_win);
120 wrefresh(his_win.x_win);
121 endwin();
122 }
123 if (invitation_waiting)
124 send_delete();
125 exit(0);
126 }
127