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