Commit | Line | Data |
---|---|---|
d0aeaf5a DF |
1 | /* |
2 | * Copyright (c) 1983 Regents of the University of California. | |
f9ac90b4 KB |
3 | * All rights reserved. |
4 | * | |
5 | * Redistribution and use in source and binary forms are permitted | |
b36fc510 KB |
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. | |
d0aeaf5a DF |
16 | */ |
17 | ||
963ce42e | 18 | #ifndef lint |
b36fc510 | 19 | static char sccsid[] = "@(#)init_disp.c 5.3 (Berkeley) %G%"; |
f9ac90b4 | 20 | #endif /* not lint */ |
6c507ccf MK |
21 | |
22 | /* | |
963ce42e MK |
23 | * Initialization code for the display package, |
24 | * as well as the signal handling routines. | |
6c507ccf MK |
25 | */ |
26 | ||
27 | #include "talk.h" | |
28 | #include <signal.h> | |
29 | ||
30 | /* | |
963ce42e MK |
31 | * Set up curses, catch the appropriate signals, |
32 | * and build the various windows. | |
6c507ccf | 33 | */ |
6c507ccf MK |
34 | init_display() |
35 | { | |
963ce42e | 36 | void sig_sent(); |
811eebdf | 37 | struct sigvec sigv; |
963ce42e MK |
38 | |
39 | initscr(); | |
811eebdf EW |
40 | (void) sigvec(SIGTSTP, (struct sigvec *)0, &sigv); |
41 | sigv.sv_mask |= sigmask(SIGALRM); | |
42 | (void) sigvec(SIGTSTP, &sigv, (struct sigvec *)0); | |
963ce42e MK |
43 | curses_initialized = 1; |
44 | clear(); | |
45 | refresh(); | |
46 | noecho(); | |
47 | crmode(); | |
48 | signal(SIGINT, sig_sent); | |
49 | signal(SIGPIPE, sig_sent); | |
6c507ccf | 50 | /* curses takes care of ^Z */ |
963ce42e MK |
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); | |
6c507ccf | 67 | /* let them know we are working on it */ |
963ce42e | 68 | current_state = "No connection yet"; |
6c507ccf MK |
69 | } |
70 | ||
963ce42e MK |
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 | */ | |
6c507ccf MK |
76 | set_edit_chars() |
77 | { | |
963ce42e MK |
78 | char buf[3]; |
79 | int cc; | |
80 | struct sgttyb tty; | |
81 | struct ltchars ltc; | |
6c507ccf | 82 | |
963ce42e MK |
83 | ioctl(0, TIOCGETP, &tty); |
84 | ioctl(0, TIOCGLTC, (struct sgttyb *)<c); | |
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]; | |
6c507ccf MK |
103 | } |
104 | ||
963ce42e MK |
105 | void |
106 | sig_sent() | |
6c507ccf | 107 | { |
963ce42e MK |
108 | |
109 | message("Connection closing. Exiting"); | |
110 | quit(); | |
6c507ccf MK |
111 | } |
112 | ||
113 | /* | |
114 | * All done talking...hang up the phone and reset terminal thingy's | |
115 | */ | |
6c507ccf MK |
116 | quit() |
117 | { | |
6c507ccf | 118 | |
963ce42e MK |
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(); | |
6c507ccf | 124 | } |
963ce42e MK |
125 | if (invitation_waiting) |
126 | send_delete(); | |
6c507ccf MK |
127 | exit(0); |
128 | } |