14 #define Tversion Tversion9p
15 #define Twrite Twrite9p
29 getscreen(int argc, char **argv)
34 /* not exactly right */
35 for(i=0; i<argc-1; i++){
36 if(strcmp(argv[i], "-W") == 0)
40 if(initdraw(panic1, nil, "sam") < 0){
41 fprint(2, "samterm: initdraw: %r\n");
42 threadexitsall("init");
44 t = getenv("tabstop");
46 maxtab = strtoul(t, nil, 0);
47 draw(screen, screen->clipr, display->white, nil, ZP);
51 screensize(int *w, int *h)
56 fd = open("/dev/screen", OREAD);
59 n = read(fd, buf, sizeof(buf)-1);
61 if (n != sizeof(buf)-1)
65 *h = atoi(buf+4*12)-atoi(buf+2*12);
70 *w = atoi(buf+3*12)-atoi(buf+1*12);
78 snarfswap(char *fromsam, int nc, char **tosam)
85 return s ? strlen(s) : 0;
89 dumperrmsg(int count, int type, int count0, int c)
91 fprint(2, "samterm: host mesg: count %d %ux %ux %ux %s...ignored\n",
92 count, type, count0, c, rcvstring());
117 i = 1-i; /* toggle */
118 n = read(fd, plumbbuf[i].data, sizeof plumbbuf[i].data);
119 if(0) fprint(2, "ext %d\n", n);
121 fprint(2, "samterm: extern read error: %r\n");
122 threadexits("extern"); /* not a fatal error */
137 user = getenv("USER");
140 disp = getenv("DISPLAY");
142 exname = smprint("/tmp/.sam.%s.%s", user, disp);
144 exname = smprint("/tmp/.sam.%s", user);
146 fprint(2, "not posting for B: out of memory\n");
150 if(mkfifo(exname, 0600) < 0){
152 if(errno != EEXIST || stat(exname, &st) < 0)
154 if(!S_ISFIFO(st.st_mode)){
156 if(mkfifo(exname, 0600) < 0)
161 fd = open(exname, OREAD|ONONBLOCK);
168 * Turn off no-delay and provide ourselves as a lingering
169 * writer so as not to get end of file on read.
171 flags = fcntl(fd, F_GETFL, 0);
172 if(flags<0 || fcntl(fd, F_SETFL, flags&~O_NONBLOCK)<0
173 ||open(exname, OWRITE) < 0){
179 plumbc = chancreate(sizeof(int), 0);
180 chansetname(plumbc, "plumbc");
183 proccreate(extproc, arg, STACK);
184 atexit(removeextern);
188 plumbformat(Plumbmsg *m, int i)
190 char *addr, *data, *act;
193 data = (char*)plumbbuf[i].data;
195 if(n == 0 || 2+n+2 >= READBUFSIZE){
199 act = plumblookup(m->attr, "action");
200 if(act!=nil && strcmp(act, "showfile")!=0){
201 /* can't handle other cases yet */
205 addr = plumblookup(m->attr, "addr");
210 addr = strdup(addr); /* copy to safe storage; we'll overwrite data */
212 memmove(data, "B ", 2); /* we know there's enough room for this */
213 memmove(data+2, m->data, n);
215 if(data[n-1] != '\n')
218 if(n+strlen(addr)+1+1 <= READBUFSIZE)
219 n += sprint(data+n, "%s\n", addr);
237 m = plumbrecvfid(fid);
239 fprint(2, "samterm: plumb read error: %r\n");
240 threadexits("plumb"); /* not a fatal error */
242 if(plumbformat(m, i)){
244 i = 1-i; /* toggle */
254 plumbfd = plumbopen("send", OWRITE|OCEXEC); /* not open is ok */
255 fid = plumbopenfid("edit", OREAD|OCEXEC);
258 plumbc = chancreate(sizeof(int), 0);
259 chansetname(plumbc, "plumbc");
264 threadcreate(plumbproc, fid, STACK);
278 i = 1-i; /* toggle */
279 n = read(hostfd[0], hostbuf[i].data, sizeof hostbuf[i].data);
280 if(0) fprint(2, "hostproc %d\n", n);
282 fprint(2, "samterm: host read error: %r\n");
283 threadexitsall("host");
287 if(0) fprint(2, "hostproc send %d\n", which);
295 hostc = chancreate(sizeof(int), 0);
296 chansetname(hostc, "hostc");
297 proccreate(hostproc, hostc, STACK);