pci: don't do sanity check for missing pci bus, the check can misfire.
[minix.git] / commands / talk / screen.c
blob1b84ba471c0be51c266ac8fdaf0e9f198fcc96fd
1 /* screen.c Copyright Michael Temari 08/01/1996 All Rights Reserved */
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <stdio.h>
6 #include <signal.h>
7 #include <ctype.h>
8 #include <string.h>
9 #include <unistd.h>
10 #include <curses.h>
12 #include "screen.h"
14 _PROTOTYPE(void gotsig, (int sig));
15 _PROTOTYPE(static char *delword, (WINDOW *w));
17 struct {
18 WINDOW *win;
19 char erase;
20 char kill;
21 char werase;
22 } window[2];
24 static char line[80+1];
26 int ScreenDone = 0;
28 static WINDOW *dwin;
30 void gotsig(sig)
31 int sig;
33 ScreenDone = 1;
34 signal(sig, gotsig);
37 int ScreenInit()
39 int i;
41 if(initscr() == (WINDOW *)NULL) {
42 fprintf(stderr, "talk: Could not initscr\n");
43 return(-1);
45 signal(SIGINT, gotsig);
46 signal(SIGQUIT, gotsig);
47 signal(SIGPIPE, gotsig);
48 signal(SIGHUP, gotsig);
49 clear();
50 refresh();
51 noecho();
52 cbreak();
54 /* local window */
55 window[LOCALWIN].win = newwin(LINES / 2, COLS, 0, 0);
56 scrollok(window[LOCALWIN].win, TRUE);
57 wclear(window[LOCALWIN].win);
59 /* divider between windows */
60 dwin = newwin(1, COLS, LINES / 2, 0);
61 i = COLS;
62 while(i-- > 0)
63 waddch(dwin, '-');
64 wrefresh(dwin);
66 /* remote window */
67 window[REMOTEWIN].win = newwin(LINES - (LINES / 2) - 1, COLS, LINES / 2 + 1, 0);
68 scrollok(window[REMOTEWIN].win, TRUE);
69 wclear(window[REMOTEWIN].win);
71 return(0);
74 void ScreenMsg(msg)
75 char *msg;
77 WINDOW *w;
79 w =window[LOCALWIN].win;
81 wmove(w, 0, 0);
83 if(*msg != '\0') {
84 wprintw(w, "[%s]", msg);
85 wclrtoeol(w);
86 } else
87 werase(w);
89 wrefresh(w);
92 void ScreenWho(user, host)
93 char *user;
94 char *host;
96 if(*host != '\0') {
97 wmove(dwin, 0, (COLS - (1 + strlen(user) + 1 + strlen(host) + 1)) / 2);
98 wprintw(dwin, " %s@%s ", user, host);
99 } else {
100 wmove(dwin, 0, (COLS - (1 + strlen(user) + 1)) / 2);
101 wprintw(dwin, " %s ", user);
103 wrefresh(dwin);
106 void ScreenEdit(lcc, rcc)
107 char lcc[];
108 char rcc[];
110 window[LOCALWIN].erase = lcc[0];
111 window[LOCALWIN].kill = lcc[1];
112 window[LOCALWIN].werase = lcc[2];
113 window[REMOTEWIN].erase = rcc[0];
114 window[REMOTEWIN].kill = rcc[1];
115 window[REMOTEWIN].werase = rcc[2];
118 void ScreenPut(data, len, win)
119 char *data;
120 int len;
121 int win;
123 WINDOW *w;
124 unsigned char ch;
125 int r, c;
127 w = window[win].win;
129 while(len-- > 0) {
130 ch = *data++;
131 /* new line CR, NL */
132 if(ch == '\r' || ch == '\n') {
133 waddch(w, '\n');
134 } else
135 /* erase a character, BS, DEL */
136 if(ch == 0x08 || ch == 0x7f || ch == window[win].erase) {
137 getyx(w, r, c);
138 if(c > 0)
139 c--;
140 wmove(w, r, c);
141 waddch(w, ' ');
142 wmove(w, r, c);
143 } else
144 /* erase line CTL-U */
145 if(ch == 0x15 || ch == window[win].kill) {
146 getyx(w, r, c);
147 wmove(w, r, 0);
148 wclrtoeol(w);
149 } else
150 /* refresh CTL-L */
151 if(ch == 0x0c) {
152 if(win == LOCALWIN) {
153 touchwin(w);
154 wrefresh(w);
155 touchwin(window[REMOTEWIN].win);
156 wrefresh(window[REMOTEWIN].win);
158 } else
159 /* bell CTL-G */
160 if(ch == 0x07) {
161 putchar(ch);
163 else
164 /* erase last word CTL-W */
165 if(ch == 0x17 || ch == window[win].werase) {
166 (void) delword(w);
167 } else {
168 getyx(w, r, c);
169 if(1 || isprint(ch)) {
170 if(ch != ' ' && c == (COLS - 1))
171 wprintw(w, "\n%s", delword(w));
172 waddch(w, ch);
176 wrefresh(w);
179 static char *delword(w)
180 WINDOW *w;
182 int r, c;
183 int i = 0;
184 char ch;
185 char *p = &line[80];
187 *p-- = '\0';
188 getyx(w, r, c);
189 if(c == 0) return;
190 while(c >= 0) {
191 c--;
192 ch = mvwinch(w, r, c);
193 if(ch == ' ') break;
194 *p-- = ch;
195 i = 1;
196 waddch(w, ' ');
198 c += i;
199 wmove(w, r, c);
200 return(++p);
203 void ScreenEnd()
205 move(LINES - 1, 0);
206 refresh();
207 endwin();