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