12 static char exname[64];
15 getscreen(int argc, char **argv)
21 if(initdraw(panic1, nil, "sam") < 0){
22 fprint(2, "samterm: initimage: %r\n");
23 threadexitsall("init");
25 t = getenv("tabstop");
27 maxtab = strtoul(t, nil, 0);
28 draw(screen, screen->clipr, display->white, nil, ZP);
32 screensize(int *w, int *h)
37 fd = open("/dev/screen", OREAD);
40 n = read(fd, buf, sizeof(buf)-1);
42 if (n != sizeof(buf)-1)
46 *h = atoi(buf+4*12)-atoi(buf+2*12);
51 *w = atoi(buf+3*12)-atoi(buf+1*12);
59 snarfswap(char *fromsam, int nc, char **tosam)
64 f = open("/dev/snarf", 0);
70 *tosam = s1 = alloc(ss);
71 n = read(f, s1, ss-1);
81 f = create("/dev/snarf", 1, 0666);
83 write(f, fromsam, nc);
91 dumperrmsg(int count, int type, int count0, int c)
93 fprint(2, "samterm: host mesg: count %d %ux %ux %ux %s...ignored\n",
94 count, type, count0, c, rcvstring());
111 int i, n, which, *fdp;
120 i = 1-i; / * toggle * /
121 n = read(*fdp, plumbbuf[i].data, sizeof plumbbuf[i].data);
123 fprint(2, "samterm: extern read error: %r\n");
124 threadexits("extern"); / * not a fatal error * /
144 sprint(exname, "/srv/sam.%s", "rsc"/*getuser()*/);
145 fd = open(exname, 1, 0600);/* BUG was create */
146 if(fd < 0){ /* assume existing guy is more important */
152 sprint(buf, "%d", p[0]);
153 if(write(fd, buf, strlen(buf)) <= 0)
157 * leave p[0] open so if the file is removed the event
158 * library won't get an error
161 plumbc = chancreate(sizeof(int), 0);
164 proccreate(extproc, arg, 1024);
166 atexit(removeextern);
174 char *addr, *data, *act;
177 data = (char*)plumbbuf[i].data;
178 m = plumbunpack(data, plumbbuf[i].n);
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)
218 int i, n, which, *fdp;
227 i = 1-i; /* toggle */
228 n = read(*fdp, plumbbuf[i].data, READBUFSIZE);
230 fprint(2, "samterm: plumb read error: %r\n");
231 threadexits("plumb"); /* not a fatal error */
247 plumbfd = plumbopen("send", OWRITE|OCEXEC); /* not open is ok */
248 fd = plumbopen("edit", OREAD|OCEXEC);
251 plumbc = chancreate(sizeof(int), 0);
258 proccreate(plumbproc, arg, 4096);
279 i = 1-i; /* toggle */
280 n = read(0, hostbuf[i].data, sizeof hostbuf[i].data);
282 fprint(2, "samterm: host read error: %r\n");
283 threadexitsall("host");
294 hostc = chancreate(sizeof(int), 0);
295 proccreate(hostproc, hostc, 1024);