22 getscreen(int argc, char **argv)
28 if(initdraw(panic1, nil, "sam") < 0){
29 fprint(2, "samterm: initdraw: %r\n");
30 threadexitsall("init");
32 t = getenv("tabstop");
34 maxtab = strtoul(t, nil, 0);
35 draw(screen, screen->clipr, display->white, nil, ZP);
39 screensize(int *w, int *h)
44 fd = open("/dev/screen", OREAD);
47 n = read(fd, buf, sizeof(buf)-1);
49 if (n != sizeof(buf)-1)
53 *h = atoi(buf+4*12)-atoi(buf+2*12);
58 *w = atoi(buf+3*12)-atoi(buf+1*12);
66 snarfswap(char *fromsam, int nc, char **tosam)
73 return s ? strlen(s) : 0;
77 dumperrmsg(int count, int type, int count0, int c)
79 fprint(2, "samterm: host mesg: count %d %ux %ux %ux %s...ignored\n",
80 count, type, count0, c, rcvstring());
106 i = 1-i; /* toggle */
107 n = threadread(fd, plumbbuf[i].data, sizeof plumbbuf[i].data);
109 fprint(2, "samterm: extern read error: %r\n");
110 threadexits("extern"); /* not a fatal error */
125 user = getenv("USER");
128 disp = getenv("DISPLAY");
130 exname = smprint("/tmp/.sam.%s.%s", user, disp);
132 exname = smprint("/tmp/.sam.%s", user);
134 fprint(2, "not posting for B: out of memory\n");
138 if(mkfifo(exname, 0600) < 0){
140 if(errno != EEXIST || stat(exname, &st) < 0)
142 if(!S_ISFIFO(st.st_mode)){
144 if(mkfifo(exname, 0600) < 0)
149 fd = open(exname, OREAD|O_NONBLOCK);
156 * Turn off no-delay and provide ourselves as a lingering
157 * writer so as not to get end of file on read.
159 flags = fcntl(fd, F_GETFL, 0);
160 if(flags<0 || fcntl(fd, F_SETFL, flags&~O_NONBLOCK)<0
161 ||open(exname, OWRITE) < 0){
167 plumbc = chancreate(sizeof(int), 0);
170 threadcreate(extproc, arg, STACK);
171 atexit(removeextern);
175 plumbformat(Plumbmsg *m, int i)
177 char *addr, *data, *act;
180 data = (char*)plumbbuf[i].data;
182 if(n == 0 || 2+n+2 >= READBUFSIZE){
186 act = plumblookup(m->attr, "action");
187 if(act!=nil && strcmp(act, "showfile")!=0){
188 /* can't handle other cases yet */
192 addr = plumblookup(m->attr, "addr");
197 addr = strdup(addr); /* copy to safe storage; we'll overwrite data */
199 memmove(data, "B ", 2); /* we know there's enough room for this */
200 memmove(data+2, m->data, n);
202 if(data[n-1] != '\n')
205 if(n+strlen(addr)+1+1 <= READBUFSIZE)
206 n += sprint(data+n, "%s\n", addr);
215 plumbproc(void *argv)
227 threadfdnoblock(*fdp);
229 m = threadplumbrecv(*fdp);
231 fprint(2, "samterm: plumb read error: %r\n");
232 threadexits("plumb"); /* not a fatal error */
234 if(plumbformat(m, i)){
236 i = 1-i; /* toggle */
247 plumbfd = plumbopen("send", OWRITE|OCEXEC); /* not open is ok */
248 fd = plumbopen("edit", OREAD|OCEXEC);
251 plumbc = chancreate(sizeof(int), 0);
258 threadcreate(plumbproc, arg, STACK);
271 threadfdnoblock(hostfd[0]);
273 i = 1-i; /* toggle */
274 n = threadread(hostfd[0], hostbuf[i].data, sizeof hostbuf[i].data);
276 fprint(2, "samterm: host read error: %r\n");
277 threadexitsall("host");
288 hostc = chancreate(sizeof(int), 0);
289 threadcreate(hostproc, hostc, STACK);