ref: 4831c35a42234eebce41369cc63250710afa012a
dir: /window.c/
#include <u.h> #include <libc.h> #include "acme.h" int winopen(Win *w, char *f, int mode) { char buf[128]; int fd; snprint(buf, sizeof(buf), "/mnt/wsys/%d/%s", w->id, f); if((fd = open(buf, mode|OCEXEC)) < 0) sysfatal("open %s: %r", buf); return fd; } Win * wincreate(void) { Win *w; char buf[12]; w = mallocz(sizeof(Win), 1); w->ctl = open("/mnt/wsys/new/ctl", ORDWR|OCEXEC); if(w->ctl < 0) sysfatal("winopen: %r"); if(read(w->ctl, buf, sizeof(buf)) != sizeof(buf)) sysfatal("read ctl: %r"); w->id = atoi(buf); w->event = winopen(w, "event", ORDWR); w->addr = winopen(w, "addr", ORDWR); w->data = winopen(w, "data", ORDWR); return w; } void winclose(Win *w) { fprint(w->ctl, "delete"); close(w->event); close(w->addr); close(w->data); free(w); } void wintitle(Win *w, char *fmt, ...) { char *title; va_list args; va_start(args, fmt); title = vsmprint(fmt, args); va_end(args); winctl(w, "name %s\n", title); free(title); } void winctl(Win *w, char *fmt, ...) { va_list args; va_start(args, fmt); vfprint(w->ctl, fmt, args); va_end(args); } void winclear(Win *w) { fprint(w->addr, ","); fprint(w->data, ""); } void winerror(Win *w, char *fmt, ...) { int fd; va_list args; fd = winopen(w, "body", OWRITE); va_start(args, fmt); vfprint(fd, fmt, args); va_end(args); close(fd); } void winerror(Win *w, char *fmt, ...) { int errorfd; va_list args; errorfd = winopen(w, "errors", OWRITE); va_start(args, fmt); vfprint(errorfd, fmt, args); va_end(args); close(errorfd); }