9 typedef struct Page Page;
40 Image *frame, *paper, *ground;
42 char pagespool[] = "/tmp/pagespool.";
75 [Corigsize] "orig size", 'o', Kesc, 0,
76 [Czoomin] "zoom in", '+', 0, 0,
77 [Czoomout] "zoom out", '-', 0, 0,
78 [Cfitwidth] "fit width", 'f', 0, 0,
79 [Cfitheight] "fit height", 'h', 0, 0,
80 [Crotate90] "rotate 90", 'r', 0, 0,
81 [Cupsidedown] "upside down", 'u', 0, 0,
82 [Cdummy1] "", 0, 0, 0,
83 [Cnext] "next", Kright, ' ', '\n',
84 [Cprev] "prev", Kleft, Kbs, 0,
85 [Czerox] "zerox", 'z', 0, 0,
86 [Cwrite] "write", 'w', 0, 0,
87 [Cext] "ext", 'x', 0, 0,
88 [Cdummy2] "", 0, 0, 0,
89 [Cquit] "quit", 'q', Kdel, Keof,
92 char *pagemenugen(int i);
93 char *cmdmenugen(int i);
109 {0xff, 0x80, 0xff, 0x80, 0xff, 0x00, 0xfe, 0x00,
110 0xff, 0x00, 0xff, 0x80, 0xff, 0xc0, 0xef, 0xe0,
111 0xc7, 0xf0, 0x03, 0xf0, 0x01, 0xe0, 0x00, 0xc0,
112 0x03, 0xff, 0x03, 0xff, 0x03, 0xff, 0x03, 0xff, },
113 {0x00, 0x00, 0x7f, 0x00, 0x7e, 0x00, 0x7c, 0x00,
114 0x7e, 0x00, 0x7f, 0x00, 0x6f, 0x80, 0x47, 0xc0,
115 0x03, 0xe0, 0x01, 0xf0, 0x00, 0xe0, 0x00, 0x40,
116 0x00, 0x00, 0x01, 0xb6, 0x01, 0xb6, 0x00, 0x00, }
119 void showpage1(Page *);
120 void showpage(Page *);
121 void drawpage(Page *);
122 Point pagesize(Page *);
125 addpage(Page *up, char *label, int (*popen)(Page *), void *pdata, int fd)
129 p = mallocz(sizeof(*p), 1);
130 p->label = strdup(label);
144 up->down = up->tail = p;
152 if(up && current == up)
158 resizewin(Point size)
162 if((wctl = open("/dev/wctl", OWRITE)) < 0)
165 size = addpt(size, Pt(Borderwidth*2, Borderwidth*2));
167 Point dsize = subpt(display->image->r.max, display->image->r.min);
172 /* can't just conver whole display */
173 if(eqpt(size, dsize))
176 fprint(wctl, "resize -dx %d -dy %d\n", size.x, size.y);
185 snprint(nam, sizeof nam, "%s%s%.12d%.8lux", pagespool, pfx, getpid(), id++);
186 return create(nam, OEXCL|ORCLOSE|ORDWR, 0600);
190 catchnote(void *, char *msg)
192 if(strstr(msg, "sys: write on closed pipe"))
194 if(strstr(msg, "hangup"))
196 if(strstr(msg, "alarm"))
198 if(strstr(msg, "interrupt"))
200 if(strstr(msg, "kill"))
213 for(mfd = 0; fd >= 0; fd = va_arg(arg, int), mfd++)
218 if((fd = open("/fd", OREAD)) < 0)
219 sysfatal("open: %r");
220 n = dirreadall(fd, &dir);
222 if(strstr(dir[i].name, "ctl"))
224 fd = atoi(dir[i].name);
232 pipeline(int fd, char *fmt, ...)
234 char buf[NPATH], *argv[4];
244 vsnprint(buf, sizeof buf, fmt, arg);
246 switch(rfork(RFPROC|RFMEM|RFFDG|RFREND|RFNOWAIT)){
252 dupfds(fd, pfd[1], 2, -1);
257 exec("/bin/rc", argv);
258 sysfatal("exec: %r");
270 while(strlen(s) > 20){
271 if((x = strchr(s, '/')) == nil)
289 if((fd = dup(p->fd, -1)) < 0){
298 if(strcmp(p->ext, "ico") == 0)
299 snprint(nam, sizeof(nam), "%s -c", p->ext);
301 snprint(nam, sizeof(nam), "%s -t9", p->ext);
302 pipeline(fd, "%s", nam);
306 * dont keep the file descriptor arround if it can simply
309 fd2path(p->fd, nam, sizeof(nam));
310 if(strncmp(nam, pagespool, strlen(pagespool))){
313 p->data = strdup(nam);
325 pipeline(p->fd, "%s", (char*)p->data);
335 char mnt[32], cmd[64], *argv[4];
338 snprint(mnt, sizeof(mnt), "/n/tapefs.%.12d%.8lux", getpid(), (ulong)p);
339 snprint(cmd, sizeof(cmd), "%s -m %s /fd/0", (char*)p->data, mnt);
340 switch(rfork(RFPROC|RFMEM|RFFDG|RFREND)){
346 dupfds(p->fd, 1, 2, -1);
351 exec("/bin/rc", argv);
352 sysfatal("exec: %r");
357 p->data = strdup(mnt);
365 char buf[NPATH], *s, *e;
371 e = buf+sizeof(buf)-1;
372 s += snprint(s, e-s, "%s/", (char*)p->data);
375 pipeline(fd, "awk '/\\<rootfile/{"
376 "if(match($0, /full\\-path\\=\\\"([^\\\"]+)\\\"/)){"
377 "print substr($0, RSTART+11,RLENGTH-12);exit}}'");
378 n = read(fd, s, e - s);
382 while(n > 0 && s[n-1] == '\n')
386 if((fd = open(buf, OREAD)) < 0)
388 pipeline(fd, "awk '/\\<item/{"
389 "if(match($0, /id\\=\\\"([^\\\"]+)\\\"/)){"
390 "id=substr($0, RSTART+4, RLENGTH-5);"
391 "if(match($0, /href\\=\\\"([^\\\"]+)\\\"/)){"
392 "item[id]=substr($0, RSTART+6, RLENGTH-7)}}};"
394 "if(match($0, /idref\\=\\\"([^\\\"]+)\\\"/)){"
395 "ref=substr($0, RSTART+7, RLENGTH-8);"
396 "print item[ref]; fflush}}'");
397 s = strrchr(buf, '/')+1;
398 while((n = read(fd, s, e-s)) > 0){
399 while(n > 0 && s[n-1] == '\n')
402 addpage(p, shortname(buf), popenfile, strdup(buf), -1);
408 typedef struct Ghost Ghost;
427 switch(rfork(RFPROC|RFMEM|RFFDG|RFNOWAIT)){
435 dupfds(gs->pdat, gs->pin, pfd[1], -1);
436 fprint(1, "%s DoPDFPage\n"
439 "dup (THIS IS NOT AN INFERNO BITMAP\\n) writestring "
440 "flushfile\n", p->label);
441 while((n = read(0, buf, sizeof buf)) > 0){
442 if(memcmp(buf, "THIS IS NOT AN INFERNO BITMAP\n", 30) == 0)
454 infernobithdr(char *buf, int n)
457 if(memcmp(buf, "compressed\n", 11) == 0)
459 if(strtochan((char*)buf))
461 if(memcmp(buf, " ", 10) == 0 &&
462 '0' <= buf[10] && buf[10] <= '9' &&
472 int n, i, pdf, ifd, ofd, pin[2], pout[2], pdat[2];
473 char buf[NBUF], nam[32], *argv[16];
479 if(read(ifd, buf, 5) != 5)
482 if(memcmp(buf, "%PDF-", 5) == 0)
502 argv[0] = (char*)p->data;
503 switch(rfork(RFPROC|RFMEM|RFFDG|RFREND|RFNOWAIT)){
508 dupfds(pin[1], pout[1], 2, pdat[1], ifd, -1);
510 dupfds(nullfd, nullfd, 2, pdat[1], ifd, -1);
512 pipeline(4, "%s", argv[0]);
515 argv[2] = "-sDEVICE=plan9";
516 argv[3] = "-sOutputFile=/fd/3";
518 argv[5] = pdf ? "-dDELAYSAFER" : "-dSAFER";
520 argv[7] = "-dTextAlphaBits=4";
521 argv[8] = "-dGraphicsAlphaBits=4";
522 snprint(buf, sizeof buf, "-r%d", ppi);
524 argv[10] = "-dDOINTERPOLATE";
525 argv[11] = pdf ? "-" : "/fd/4";
527 exec("/bin/gs", argv);
528 sysfatal("exec: %r");
539 "/PAGEOUT (/fd/1) (w) file def\n"
540 "/PAGE== { PAGEOUT exch write==only PAGEOUT (\\n) writestring PAGEOUT flushfile } def\n"
544 "/PDFSave null def\n"
545 "/DSCPageCount 0 def\n"
546 "/DoPDFPage {dup /Page# exch store pdfgetpage pdfshowpage } def\n"
548 "GS_PDF_ProcSet begin\n"
550 "(/fd/4) (r) file { DELAYSAFER { .setsafe } if } stopped pop pdfopen begin\n"
552 "pdfpagecount PAGE==\n";
555 if(write(pin[0], prolog, n) != n)
557 if((n = read(pout[0], buf, sizeof(buf)-1)) < 0)
565 gs = mallocz(sizeof(*gs), 1);
570 snprint(nam, sizeof nam, "%d", i);
571 addpage(p, nam, popenpdf, gs, -1);
574 /* keep ghostscript arround */
579 while((n = read(pdat[0], buf, sizeof(buf))) >= 0){
580 if(ofd >= 0 && (n <= 0 || infernobithdr(buf, n))){
581 snprint(nam, sizeof nam, "%d", i);
582 addpage(p, nam, popenimg, nil, ofd);
588 snprint(nam, sizeof nam, "%.4d", ++i);
589 if((ofd = createtmp(nam)) < 0)
590 ofd = dup(nullfd, -1);
592 if(write(ofd, buf, n) != n)
606 filetype(char *buf, int nbuf, char *typ, int ntyp)
608 int n, ifd[2], ofd[2];
611 if(infernobithdr(buf, nbuf)){
612 strncpy(typ, "image/p9bit", ntyp);
624 if(rfork(RFPROC|RFMEM|RFFDG|RFREND|RFNOWAIT) == 0){
625 dupfds(ifd[1], ofd[1], 2, -1);
629 exec("/bin/file", argv);
633 if(rfork(RFPROC|RFMEM|RFFDG|RFNOWAIT) == 0){
639 if((n = readn(ofd[0], typ, ntyp-1)) < 0)
642 while(n > 0 && typ[n-1] == '\n')
649 dircmp(void *p1, void *p2)
656 return strcmp(d1->name, d2->name);
667 "application/pdf", popengs, nil,
668 "application/postscript", popengs, nil,
669 "application/troff", popengs, "lp -dstdout",
670 "text/plain", popengs, "lp -dstdout",
671 "text/html", popengs, "uhtml | html2ms | tbl | troff -ms | lp -dstdout",
672 "application/dvi", popengs, "dvips -Pps -r0 -q1 -f1",
673 "application/doc", popengs, "doc2ps",
674 "application/zip", popentape, "fs/zipfs",
675 "application/x-tar", popentape, "fs/tarfs",
676 "application/x-ustar", popentape, "fs/tarfs",
677 "application/x-compress", popenfilter, "uncompress",
678 "application/x-gzip", popenfilter, "gunzip",
679 "application/x-bzip2", popenfilter, "bunzip2",
680 "image/gif", popenimg, "gif",
681 "image/jpeg", popenimg, "jpg",
682 "image/png", popenimg, "png",
683 "image/ppm", popenimg, "ppm",
684 "image/bmp", popenimg, "bmp",
685 "image/tga", popenimg, "tga",
686 "image/x-icon", popenimg, "ico",
687 "image/p9bit", popenimg, nil,
690 char buf[NBUF], typ[128], *file;
700 if((fd = open(file, OREAD)) < 0){
707 if((d = dirfstat(fd)) == nil){
716 snprint(buf, sizeof(buf), "%s/META-INF/container.xml", file);
717 if((tfd = open(buf, OREAD)) >= 0){
725 if((n = dirreadall(fd, &d)) < 0)
727 qsort(d, n, sizeof d[0], dircmp);
729 addpage(p, d[i].name, popenfile, smprint("%s/%s", file, d[i].name), -1);
735 memset(buf, 0, NBUF/2);
736 if((n = readn(fd, buf, NBUF/2)) <= 0)
738 filetype(buf, n, typ, sizeof(typ));
739 for(i=0; i<nelem(tab); i++)
740 if(strncmp(typ, tab[i].typ, strlen(tab[i].typ)) == 0)
743 werrstr("unknown image format: %s", typ);
747 p->data = tab[i].data;
748 p->open = tab[i].open;
749 if(seek(fd, 0, 0) < 0)
751 if((i = readn(fd, buf+n, n)) < 0)
753 if(i != n || memcmp(buf, buf+n, i)){
756 if((tfd = createtmp("file")) < 0)
759 if(write(tfd, buf, n) != n)
761 if((n = read(fd, buf, sizeof(buf))) < 0)
764 if(dup(tfd, fd) < 0){
794 for(p = root->down; p; p = t)
795 if((t = nextpage(p)) == x)
807 if(p->open == nil || (fd = p->open(p)) < 0)
811 pipeline(fd, "rotate -r %d", rotate);
813 pipeline(fd, "resize -x %d", resize.x);
815 pipeline(fd, "resize -y %d", resize.y);
825 if(p->open && p->image == nil){
829 if((p->image = readimage(display, fd, 1)) == nil)
830 fprint(2, "readimage: %r\n");
842 if(p->open == nil || p->image == nil)
844 lockdisplay(display);
846 unlockdisplay(display);
855 for(p = root->down; p; p = nextpage(p)){
856 if(age == 0) /* synchronous flush */
858 else if(!canqlock(p))
860 if((pagegen - p->gen) >= age)
867 loadpages(Page *p, int ahead, int oviewgen)
871 ahead++; /* load at least one */
872 unloadpages(ahead*2);
873 for(i = 0; i < ahead && p; p = nextpage(p), i++){
874 if(viewgen != oviewgen)
878 if(viewgen != oviewgen){
888 if(size.x && size.y && newwin){
892 lockdisplay(display);
894 unlockdisplay(display);
902 * A draw operation that touches only the area contained in bot but not in top.
903 * mp and sp get aligned with bot.min.
906 gendrawdiff(Image *dst, Rectangle bot, Rectangle top,
907 Image *src, Point sp, Image *mask, Point mp, int op)
913 if(Dx(bot)*Dy(bot) == 0)
916 /* no points in bot - top */
917 if(rectinrect(bot, top))
920 /* bot - top ≡ bot */
921 if(Dx(top)*Dy(top)==0 || rectXrect(bot, top)==0){
922 gendrawop(dst, bot, src, sp, mask, mp, op);
927 /* split bot into rectangles that don't intersect top */
929 if(bot.min.x < top.min.x){
930 r = Rect(bot.min.x, bot.min.y, top.min.x, bot.max.y);
931 delta = subpt(r.min, origin);
932 gendrawop(dst, r, src, addpt(sp, delta), mask, addpt(mp, delta), op);
933 bot.min.x = top.min.x;
937 if(bot.max.x > top.max.x){
938 r = Rect(top.max.x, bot.min.y, bot.max.x, bot.max.y);
939 delta = subpt(r.min, origin);
940 gendrawop(dst, r, src, addpt(sp, delta), mask, addpt(mp, delta), op);
941 bot.max.x = top.max.x;
945 if(bot.min.y < top.min.y){
946 r = Rect(bot.min.x, bot.min.y, bot.max.x, top.min.y);
947 delta = subpt(r.min, origin);
948 gendrawop(dst, r, src, addpt(sp, delta), mask, addpt(mp, delta), op);
949 bot.min.y = top.min.y;
953 if(bot.max.y > top.max.y){
954 r = Rect(bot.min.x, top.max.y, bot.max.x, bot.max.y);
955 delta = subpt(r.min, origin);
956 gendrawop(dst, r, src, addpt(sp, delta), mask, addpt(mp, delta), op);
957 bot.max.y = top.max.y;
962 alphachan(ulong chan)
964 for(; chan; chan >>= 8)
965 if(TYPE(chan) == CAlpha)
971 zoomdraw(Image *d, Rectangle r, Rectangle top, Image *b, Image *s, Point sp, int f)
979 if(r.min.x < d->r.min.x){
980 sp.x += (d->r.min.x - r.min.x)/f;
981 a.x = (d->r.min.x - r.min.x)%f;
982 r.min.x = d->r.min.x;
984 if(r.min.y < d->r.min.y){
985 sp.y += (d->r.min.y - r.min.y)/f;
986 a.y = (d->r.min.y - r.min.y)%f;
987 r.min.y = d->r.min.y;
990 w = s->r.max.x - sp.x;
994 dr.max.x = dr.min.x+w;
995 if(!alphachan(s->chan))
998 if(b) gendrawdiff(d, dr, top, b, sp, nil, ZP, SoverD);
999 gendrawdiff(d, dr, top, s, sp, nil, ZP, SoverD);
1002 if((t = allocimage(display, dr, s->chan, 0, 0)) == nil)
1004 for(; dr.min.y < r.max.y; dr.min.y++){
1005 dr.max.y = dr.min.y+1;
1006 draw(t, dr, s, nil, sp);
1013 for(sp=dr.min; dr.min.x < r.max.x; sp.x++){
1014 dr.max.x = dr.min.x+1;
1015 if(b) gendrawdiff(d, dr, top, b, sp, nil, ZP, SoverD);
1016 gendrawdiff(d, dr, top, t, sp, nil, ZP, SoverD);
1017 for(dr.min.x++; ++a.x < f && dr.min.x < r.max.x; dr.min.x++){
1018 dr.max.x = dr.min.x+1;
1019 gendrawdiff(d, dr, top, d, Pt(dr.min.x-1, dr.min.y), nil, ZP, SoverD);
1029 return p->image ? mulpt(subpt(p->image->r.max, p->image->r.min), zoom) : ZP;
1033 drawframe(Rectangle r)
1035 border(screen, r, -Borderwidth, frame, ZP);
1036 gendrawdiff(screen, screen->r, insetrect(r, -Borderwidth), ground, ZP, nil, ZP, SoverD);
1037 flushimage(display, 1);
1047 r = rectaddpt(Rpt(ZP, pagesize(p)), addpt(pos, screen->r.min));
1048 zoomdraw(screen, r, ZR, paper, i, i->r.min, zoom);
1050 r = Rpt(ZP, stringsize(font, p->label));
1051 r = rectaddpt(r, addpt(subpt(divpt(subpt(screen->r.max, screen->r.min), 2),
1052 divpt(r.max, 2)), screen->r.min));
1053 draw(screen, r, paper, nil, ZP);
1054 string(screen, r.min, display->black, ZP, font, p->label);
1060 translate(Page *p, Point d)
1066 if(i==0 || d.x==0 && d.y==0)
1068 r = rectaddpt(Rpt(ZP, pagesize(p)), addpt(pos, screen->r.min));
1069 pos = addpt(pos, d);
1070 nr = rectaddpt(r, d);
1071 rectclip(&r, screen->r);
1072 draw(screen, rectaddpt(r, d), screen, nil, r.min);
1073 zoomdraw(screen, nr, rectaddpt(r, d), paper, i, i->r.min, zoom);
1078 findpage(char *name)
1084 /* look in current document first */
1085 if(current && current->up){
1086 for(p = current->up->down; p; p = p->next)
1087 if(cistrncmp(p->label, name, n) == 0)
1090 /* look everywhere */
1091 for(p = root->down; p; p = nextpage(p))
1092 if(cistrncmp(p->label, name, n) == 0)
1102 for(p = root->down; i > 0 && p; p = nextpage(p))
1113 for(i = 0, p = root->down; p && p != x; p = nextpage(p))
1115 return (p == x) ? i : -1;
1130 if(i < 0 || i >= nelem(cmds))
1136 * spawn new proc to load a run of pages starting with p
1137 * the display should *not* be locked as it gets called
1138 * from recursive page load.
1148 esetcursor(&reading);
1154 switch(rfork(RFPROC|RFMEM)){
1156 sysfatal("rfork: %r");
1158 loadpages(p, NAHEAD, oviewgen);
1163 /* recursive display lock, called from main proc only */
1165 drawlock(int dolock){
1169 lockdisplay(display);
1172 unlockdisplay(display);
1190 for(p = nextpage(current); p; p = nextpage(p))
1191 if(p->image || p->open)
1201 for(p = prevpage(current); p; p = prevpage(p))
1202 if(p->image || p->open)
1210 char nam[64], *argv[4];
1217 if((fd = openpage(p)) < 0)
1219 if(rfork(RFPROC|RFMEM|RFFDG|RFENVG|RFNOTEG|RFNOWAIT) == 0){
1220 dupfds(fd, 1, 2, -1);
1221 snprint(nam, sizeof nam, "/bin/%s", argv0);
1226 sysfatal("exec: %r");
1237 char buf[128], label[64], *argv[4];
1243 snprint(label, sizeof(label), "%s %s", p->ext, p->label);
1245 ps = subpt(p->image->r.max, p->image->r.min);
1249 ps = subpt(screen->r.max, screen->r.min);
1251 if((fd = p->fd) < 0){
1252 if(p->open != popenfile)
1254 fd = open((char*)p->data, OREAD);
1259 if(rfork(RFPROC|RFMEM|RFFDG|RFNOTEG|RFNAMEG|RFNOWAIT) == 0){
1260 snprint(buf, sizeof(buf), "-pid %d -dx %d -dy %d", getpid(), ps.x, ps.y);
1261 if(newwindow(buf) != -1){
1262 dupfds(fd, 1, 2, -1);
1263 if((fd = open("/dev/label", OWRITE)) >= 0){
1264 write(fd, label, strlen(label));
1271 exec("/bin/rc", argv);
1286 if(new && getwindow(display, Refnone) == -1)
1287 sysfatal("getwindow: %r");
1298 void killcohort(void)
1301 for(i=0;i!=3;i++){ /* It's a long way to the kitchen */
1302 postnote(PNGROUP, cohort, "kill");
1307 void drawerr(Display *, char *msg)
1309 sysfatal("draw: %s", msg);
1315 fprint(2, "usage: %s [ -iRw ] [ -p ppi ] [ file ... ]\n", argv0);
1320 docmd(int i, Mouse *m)
1322 char buf[NPATH], *s;
1348 resize = subpt(screen->r.max, screen->r.min);
1354 resize = subpt(screen->r.max, screen->r.min);
1359 if(current == nil || !canqlock(current))
1361 o = subpt(m->xy, screen->r.min);
1365 pos = addpt(mulpt(subpt(pos, o), 2), o);
1370 pos = addpt(divpt(subpt(pos, o), 2), o);
1377 if(current == nil || !canqlock(current))
1381 if(current->up && current->up != root)
1382 s = current->up->label;
1383 snprint(buf, sizeof(buf), "%s%s%s.bit",
1387 if(eenter("Write", buf, sizeof(buf), m) > 0){
1388 if((fd = create(buf, OWRITE, 0666)) < 0){
1389 errstr(buf, sizeof(buf));
1390 eenter(buf, 0, 0, m);
1392 esetcursor(&reading);
1393 writeimage(fd, current->image, 0);
1402 if(current == nil || !canqlock(current))
1422 main(int argc, char *argv[])
1424 enum { Eplumb = 4 };
1449 ppi = atoi(EARGF(usage()));
1456 * so that we can stop all subprocesses with a note,
1457 * and to isolate rendezvous from other processes
1459 atnotify(catchnote, 1);
1460 if(cohort = rfork(RFPROC|RFNOTEG|RFNAMEG|RFREND)){
1469 s = smprint("-pid %d", getpid());
1470 if(newwindow(s) < 0)
1471 sysfatal("newwindow: %r");
1474 if(initdraw(drawerr, nil, argv0) < 0)
1475 sysfatal("initdraw: %r");
1476 paper = display->white;
1477 frame = display->black;
1478 ground = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x777777FF);
1479 display->locking = 1;
1480 unlockdisplay(display);
1483 einit(Ekeyboard|Emouse);
1484 eplumb(Eplumb, "image");
1485 memset(&m, 0, sizeof(m));
1486 if((nullfd = open("/dev/null", ORDWR)) < 0)
1487 sysfatal("open: %r");
1488 current = root = addpage(nil, "", nil, nil, -1);
1489 if(*argv == nil && !imode)
1490 addpage(root, "stdin", popenfile, strdup("/fd/0"), -1);
1491 for(; *argv; argv++)
1492 addpage(root, shortname(*argv), popenfile, strdup(*argv), -1);
1503 if(current && canqlock(current)){
1507 if((m.buttons & 1) == 0)
1509 translate(current, subpt(m.xy, o));
1513 } else if(m.buttons & 2){
1515 i = emenuhit(2, &m, &cmdmenu);
1518 } else if(m.buttons & 4){
1523 pagemenu.lasthit = pageindex(current);
1524 x = pageat(emenuhit(3, &m, &pagemenu));
1533 if(current == nil || !canqlock(current))
1536 translate(current, Pt(0, Dy(screen->r)/2));
1540 if(prevpage(current))
1546 if(current == nil || !canqlock(current))
1548 o = addpt(pos, pagesize(current));
1549 if(o.y > Dy(screen->r)){
1550 translate(current, Pt(0, -Dy(screen->r)/2));
1554 if(nextpage(current))
1560 for(i = 0; i<nelem(cmds); i++)
1561 if((cmds[i].k1 == e.kbdc) ||
1562 (cmds[i].k2 == e.kbdc) ||
1563 (cmds[i].k3 == e.kbdc))
1565 if(i < nelem(cmds)){
1569 if((e.kbdc < 0x20) ||
1570 (e.kbdc & 0xFF00) == KF ||
1571 (e.kbdc & 0xFF00) == Spec)
1573 snprint(buf, sizeof(buf), "%C", (Rune)e.kbdc);
1574 if(eenter("Go to", buf, sizeof(buf), &m) > 0)
1575 showpage(findpage(buf));
1580 if(pm && pm->ndata > 0){
1584 s = plumblookup(pm->attr, "action");
1585 if(s && strcmp(s, "quit")==0)
1587 if(s && strcmp(s, "showdata")==0){
1588 if((fd = createtmp("plumb")) < 0){
1589 fprint(2, "plumb: createtmp: %r\n");
1593 if(fd2path(fd, s, NPATH) < 0){
1597 write(fd, pm->data, pm->ndata);
1598 }else if(pm->data[0] == '/'){
1599 s = strdup(pm->data);
1601 s = malloc(strlen(pm->wdir)+1+pm->ndata+1);
1602 sprint(s, "%s/%s", pm->wdir, pm->data);
1605 showpage(addpage(root, shortname(s), popenfile, s, fd));