xref: /original-bsd/usr.bin/talk/init_disp.c (revision 7323bcb8)
1 /*
2  * Copyright (c) 1983 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  */
17 
18 #ifndef lint
19 static char sccsid[] = "@(#)init_disp.c	5.3 (Berkeley) 06/29/88";
20 #endif /* not lint */
21 
22 /*
23  * Initialization code for the display package,
24  * as well as the signal handling routines.
25  */
26 
27 #include "talk.h"
28 #include <signal.h>
29 
30 /*
31  * Set up curses, catch the appropriate signals,
32  * and build the various windows.
33  */
34 init_display()
35 {
36 	void sig_sent();
37 	struct sigvec sigv;
38 
39 	initscr();
40 	(void) sigvec(SIGTSTP, (struct sigvec *)0, &sigv);
41 	sigv.sv_mask |= sigmask(SIGALRM);
42 	(void) sigvec(SIGTSTP, &sigv, (struct sigvec *)0);
43 	curses_initialized = 1;
44 	clear();
45 	refresh();
46 	noecho();
47 	crmode();
48 	signal(SIGINT, sig_sent);
49 	signal(SIGPIPE, sig_sent);
50 	/* curses takes care of ^Z */
51 	my_win.x_nlines = LINES / 2;
52 	my_win.x_ncols = COLS;
53 	my_win.x_win = newwin(my_win.x_nlines, my_win.x_ncols, 0, 0);
54 	scrollok(my_win.x_win, FALSE);
55 	wclear(my_win.x_win);
56 
57 	his_win.x_nlines = LINES / 2 - 1;
58 	his_win.x_ncols = COLS;
59 	his_win.x_win = newwin(his_win.x_nlines, his_win.x_ncols,
60 	    my_win.x_nlines+1, 0);
61 	scrollok(his_win.x_win, FALSE);
62 	wclear(his_win.x_win);
63 
64 	line_win = newwin(1, COLS, my_win.x_nlines, 0);
65 	box(line_win, '-', '-');
66 	wrefresh(line_win);
67 	/* let them know we are working on it */
68 	current_state = "No connection yet";
69 }
70 
71 /*
72  * Trade edit characters with the other talk. By agreement
73  * the first three characters each talk transmits after
74  * connection are the three edit characters.
75  */
76 set_edit_chars()
77 {
78 	char buf[3];
79 	int cc;
80 	struct sgttyb tty;
81 	struct ltchars ltc;
82 
83 	ioctl(0, TIOCGETP, &tty);
84 	ioctl(0, TIOCGLTC, (struct sgttyb *)&ltc);
85 	my_win.cerase = tty.sg_erase;
86 	my_win.kill = tty.sg_kill;
87 	if (ltc.t_werasc == (char) -1)
88 		my_win.werase = '\027';	 /* control W */
89 	else
90 		my_win.werase = ltc.t_werasc;
91 	buf[0] = my_win.cerase;
92 	buf[1] = my_win.kill;
93 	buf[2] = my_win.werase;
94 	cc = write(sockt, buf, sizeof(buf));
95 	if (cc != sizeof(buf) )
96 		p_error("Lost the connection");
97 	cc = read(sockt, buf, sizeof(buf));
98 	if (cc != sizeof(buf) )
99 		p_error("Lost the connection");
100 	his_win.cerase = buf[0];
101 	his_win.kill = buf[1];
102 	his_win.werase = buf[2];
103 }
104 
105 void
106 sig_sent()
107 {
108 
109 	message("Connection closing. Exiting");
110 	quit();
111 }
112 
113 /*
114  * All done talking...hang up the phone and reset terminal thingy's
115  */
116 quit()
117 {
118 
119 	if (curses_initialized) {
120 		wmove(his_win.x_win, his_win.x_nlines-1, 0);
121 		wclrtoeol(his_win.x_win);
122 		wrefresh(his_win.x_win);
123 		endwin();
124 	}
125 	if (invitation_waiting)
126 		send_delete();
127 	exit(0);
128 }
129