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