/* * Process in-band messages about window title changes. * The messages are of the form: * * \033];xxx\007 * * where xxx is the new directory. This format was chosen * because it changes the label on xterm windows. */ #include #include char *prog = "/bin/rwd"; void usage(void) { fprint(2, "usage: conswdir [/bin/rwd]\n"); exits("usage"); } void setpath(char *s) { switch(rfork(RFPROC|RFNOWAIT)){ case 0: execl(prog, prog, s, nil); _exits(nil); } } enum { None, Esc, Brack, Semi, Bell, }; int process(char *buf, int n, int *pn) { char *p; char path[4096]; int start, state; start = 0; state = None; for(p=buf; p= 2048) return (p - buf); else return start; } static void catchint(void*, char *msg) { if(strstr(msg, "interrupt")) noted(NCONT); else if(strstr(msg, "kill")) noted(NDFLT); else noted(NCONT); } void main(int argc, char **argv) { char buf[4096]; int n, m; notify(catchint); ARGBEGIN{ default: usage(); }ARGEND if(argc > 1) usage(); if(argc == 1) prog = argv[0]; n = 0; for(;;){ m = read(0, buf+n, sizeof buf-n); if(m < 0){ rerrstr(buf, sizeof buf); if(strstr(buf, "interrupt")) continue; exits(nil); } n += m; m = process(buf, n, &n); if(m > 0){ write(1, buf, m); memmove(buf, buf+m, n-m); n -= m; } } }