#include #include #include void main(int argc, char **argv){ char f[12][24], t[5 * 12], buf[128], *i, *o, *e, *mod = nil; Dir *d; Rune r; int fd, n; while(9){ i = o = buf; e = buf + read(0, buf, sizeof buf - 1); if(e <= buf) break; *e = 0; while(i < e){ if(*i == 'k' || *i == 'K') mod = utfrune(i + 1, Kmod4); else if(*i == 'c'){ chartorune(&r, i + 1); if(mod != nil){ while(*i++) ; if(r == '\n'){ fd = open("/dev/wctl", OWRITE); if(fd >= 0){ write(fd, "new -r 380 0 1600 900", 21); close(fd); } continue; } fd = open("/dev/wsys", OREAD); if(fd < 0) continue; n = dirreadall(fd, &d); close(fd); while(--n >= 0){ sprint(t, "/dev/wsys/%s/wctl", d[n].name); fd = open(t, ORDWR); if(fd < 0) continue; if(read(fd, t, 60) == 60 && !strncmp(t + 48, " current ", 12)){ if(r >= (KF | 1) && r <= (KF | 12)) sprint(f[r - KF - 1], "/dev/wsys/%s/wctl", d[n].name); break; } close(fd); } free(d); if(n < 0) continue; switch(r){ case Kdown: write(fd, "hide", 4); break; case Kup: write(fd, "resize -r 380 0 1600 900", 24); break; case Kleft: write(fd, "resize -r 0 0 802 900", 21); break; case Kright: write(fd, "resize -r 798 0 1600 900", 24); break; } close(fd); continue; }else if(r >= (KF | 1) && r <= (KF | 12)){ while(*i++) ; r ^= KF; fd = open(f[r - 1], OWRITE); if(fd < 0){ if(argc <= r) continue; fd = open("/dev/wsys", OREAD); if(fd < 0) continue; n = dirreadall(fd, &d); close(fd); while(--n >= 0){ sprint(t, "/dev/wsys/%s/label", d[n].name); fd = open(t, ORDWR); if(fd < 0) continue; if(read(fd, t, sizeof t) == strlen(argv[r]) && !strncmp(t, argv[r], strlen(argv[r]))){ close(fd); sprint(f[r - 1], "/dev/wsys/%s/wctl", d[n].name); fd = open(f[r - 1], OWRITE); break; } close(fd); } free(d); if(n < 0 || fd < 0) continue; } write(fd, "current", 7); write(fd, "unhide", 6); close(fd); continue; } } while(*o++ = *i++) ; } write(1, buf, o - buf); } exits(nil); }