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/tiff", popenimg, "tif",
684 "image/ppm", popenimg, "ppm",
685 "image/bmp", popenimg, "bmp",
686 "image/tga", popenimg, "tga",
687 "image/x-icon", popenimg, "ico",
688 "image/p9bit", popenimg, nil,
691 char buf[NBUF], typ[128], *file;
701 if((fd = open(file, OREAD)) < 0){
708 if((d = dirfstat(fd)) == nil){
717 snprint(buf, sizeof(buf), "%s/META-INF/container.xml", file);
718 if((tfd = open(buf, OREAD)) >= 0){
726 if((n = dirreadall(fd, &d)) < 0)
728 qsort(d, n, sizeof d[0], dircmp);
730 addpage(p, d[i].name, popenfile, smprint("%s/%s", file, d[i].name), -1);
736 memset(buf, 0, NBUF/2);
737 if((n = readn(fd, buf, NBUF/2)) <= 0)
739 filetype(buf, n, typ, sizeof(typ));
740 for(i=0; i<nelem(tab); i++)
741 if(strncmp(typ, tab[i].typ, strlen(tab[i].typ)) == 0)
744 werrstr("unknown image format: %s", typ);
748 p->data = tab[i].data;
749 p->open = tab[i].open;
750 if(seek(fd, 0, 0) < 0)
752 if((i = readn(fd, buf+n, n)) < 0)
754 if(i != n || memcmp(buf, buf+n, i)){
757 if((tfd = createtmp("file")) < 0)
760 if(write(tfd, buf, n) != n)
762 if((n = read(fd, buf, sizeof(buf))) < 0)
765 if(dup(tfd, fd) < 0){
795 for(p = root->down; p; p = t)
796 if((t = nextpage(p)) == x)
808 if(p->open == nil || (fd = p->open(p)) < 0)
812 pipeline(fd, "rotate -r %d", rotate);
814 pipeline(fd, "resize -x %d", resize.x);
816 pipeline(fd, "resize -y %d", resize.y);
826 if(p->open && p->image == nil){
830 if((p->image = readimage(display, fd, 1)) == nil)
831 fprint(2, "readimage: %r\n");
843 if(p->open == nil || p->image == nil)
845 lockdisplay(display);
847 unlockdisplay(display);
856 for(p = root->down; p; p = nextpage(p)){
857 if(age == 0) /* synchronous flush */
859 else if(!canqlock(p))
861 if((pagegen - p->gen) >= age)
868 loadpages(Page *p, int ahead, int oviewgen)
872 ahead++; /* load at least one */
873 unloadpages(ahead*2);
874 for(i = 0; i < ahead && p; p = nextpage(p), i++){
875 if(viewgen != oviewgen)
879 if(viewgen != oviewgen){
889 if(size.x && size.y && newwin){
893 lockdisplay(display);
895 unlockdisplay(display);
903 * A draw operation that touches only the area contained in bot but not in top.
904 * mp and sp get aligned with bot.min.
907 gendrawdiff(Image *dst, Rectangle bot, Rectangle top,
908 Image *src, Point sp, Image *mask, Point mp, int op)
914 if(Dx(bot)*Dy(bot) == 0)
917 /* no points in bot - top */
918 if(rectinrect(bot, top))
921 /* bot - top ≡ bot */
922 if(Dx(top)*Dy(top)==0 || rectXrect(bot, top)==0){
923 gendrawop(dst, bot, src, sp, mask, mp, op);
928 /* split bot into rectangles that don't intersect top */
930 if(bot.min.x < top.min.x){
931 r = Rect(bot.min.x, bot.min.y, top.min.x, bot.max.y);
932 delta = subpt(r.min, origin);
933 gendrawop(dst, r, src, addpt(sp, delta), mask, addpt(mp, delta), op);
934 bot.min.x = top.min.x;
938 if(bot.max.x > top.max.x){
939 r = Rect(top.max.x, bot.min.y, bot.max.x, bot.max.y);
940 delta = subpt(r.min, origin);
941 gendrawop(dst, r, src, addpt(sp, delta), mask, addpt(mp, delta), op);
942 bot.max.x = top.max.x;
946 if(bot.min.y < top.min.y){
947 r = Rect(bot.min.x, bot.min.y, bot.max.x, top.min.y);
948 delta = subpt(r.min, origin);
949 gendrawop(dst, r, src, addpt(sp, delta), mask, addpt(mp, delta), op);
950 bot.min.y = top.min.y;
954 if(bot.max.y > top.max.y){
955 r = Rect(bot.min.x, top.max.y, bot.max.x, bot.max.y);
956 delta = subpt(r.min, origin);
957 gendrawop(dst, r, src, addpt(sp, delta), mask, addpt(mp, delta), op);
958 bot.max.y = top.max.y;
963 alphachan(ulong chan)
965 for(; chan; chan >>= 8)
966 if(TYPE(chan) == CAlpha)
972 zoomdraw(Image *d, Rectangle r, Rectangle top, Image *b, Image *s, Point sp, int f)
980 if(r.min.x < d->r.min.x){
981 sp.x += (d->r.min.x - r.min.x)/f;
982 a.x = (d->r.min.x - r.min.x)%f;
983 r.min.x = d->r.min.x;
985 if(r.min.y < d->r.min.y){
986 sp.y += (d->r.min.y - r.min.y)/f;
987 a.y = (d->r.min.y - r.min.y)%f;
988 r.min.y = d->r.min.y;
991 w = s->r.max.x - sp.x;
995 dr.max.x = dr.min.x+w;
996 if(!alphachan(s->chan))
999 if(b) gendrawdiff(d, dr, top, b, sp, nil, ZP, SoverD);
1000 gendrawdiff(d, dr, top, s, sp, nil, ZP, SoverD);
1003 if((t = allocimage(display, dr, s->chan, 0, 0)) == nil)
1005 for(; dr.min.y < r.max.y; dr.min.y++){
1006 dr.max.y = dr.min.y+1;
1007 draw(t, dr, s, nil, sp);
1014 for(sp=dr.min; dr.min.x < r.max.x; sp.x++){
1015 dr.max.x = dr.min.x+1;
1016 if(b) gendrawdiff(d, dr, top, b, sp, nil, ZP, SoverD);
1017 gendrawdiff(d, dr, top, t, sp, nil, ZP, SoverD);
1018 for(dr.min.x++; ++a.x < f && dr.min.x < r.max.x; dr.min.x++){
1019 dr.max.x = dr.min.x+1;
1020 gendrawdiff(d, dr, top, d, Pt(dr.min.x-1, dr.min.y), nil, ZP, SoverD);
1030 return p->image ? mulpt(subpt(p->image->r.max, p->image->r.min), zoom) : ZP;
1034 drawframe(Rectangle r)
1036 border(screen, r, -Borderwidth, frame, ZP);
1037 gendrawdiff(screen, screen->r, insetrect(r, -Borderwidth), ground, ZP, nil, ZP, SoverD);
1038 flushimage(display, 1);
1048 r = rectaddpt(Rpt(ZP, pagesize(p)), addpt(pos, screen->r.min));
1049 zoomdraw(screen, r, ZR, paper, i, i->r.min, zoom);
1051 r = Rpt(ZP, stringsize(font, p->label));
1052 r = rectaddpt(r, addpt(subpt(divpt(subpt(screen->r.max, screen->r.min), 2),
1053 divpt(r.max, 2)), screen->r.min));
1054 draw(screen, r, paper, nil, ZP);
1055 string(screen, r.min, display->black, ZP, font, p->label);
1061 translate(Page *p, Point d)
1067 if(i==0 || d.x==0 && d.y==0)
1069 r = rectaddpt(Rpt(ZP, pagesize(p)), addpt(pos, screen->r.min));
1070 pos = addpt(pos, d);
1071 nr = rectaddpt(r, d);
1072 rectclip(&r, screen->r);
1073 draw(screen, rectaddpt(r, d), screen, nil, r.min);
1074 zoomdraw(screen, nr, rectaddpt(r, d), paper, i, i->r.min, zoom);
1079 findpage(char *name)
1085 /* look in current document first */
1086 if(current && current->up){
1087 for(p = current->up->down; p; p = p->next)
1088 if(cistrncmp(p->label, name, n) == 0)
1091 /* look everywhere */
1092 for(p = root->down; p; p = nextpage(p))
1093 if(cistrncmp(p->label, name, n) == 0)
1103 for(p = root->down; i > 0 && p; p = nextpage(p))
1114 for(i = 0, p = root->down; p && p != x; p = nextpage(p))
1116 return (p == x) ? i : -1;
1131 if(i < 0 || i >= nelem(cmds))
1137 * spawn new proc to load a run of pages starting with p
1138 * the display should *not* be locked as it gets called
1139 * from recursive page load.
1149 esetcursor(&reading);
1155 switch(rfork(RFPROC|RFMEM)){
1157 sysfatal("rfork: %r");
1159 loadpages(p, NAHEAD, oviewgen);
1164 /* recursive display lock, called from main proc only */
1166 drawlock(int dolock){
1170 lockdisplay(display);
1173 unlockdisplay(display);
1191 for(p = nextpage(current); p; p = nextpage(p))
1192 if(p->image || p->open)
1202 for(p = prevpage(current); p; p = prevpage(p))
1203 if(p->image || p->open)
1211 char nam[64], *argv[4];
1218 if((fd = openpage(p)) < 0)
1220 if(rfork(RFPROC|RFMEM|RFFDG|RFENVG|RFNOTEG|RFNOWAIT) == 0){
1221 dupfds(fd, 1, 2, -1);
1222 snprint(nam, sizeof nam, "/bin/%s", argv0);
1227 sysfatal("exec: %r");
1238 char buf[128], label[64], *argv[4];
1244 snprint(label, sizeof(label), "%s %s", p->ext, p->label);
1247 ps = addpt(subpt(p->image->r.max, p->image->r.min), Pt(24, 24));
1249 if((fd = p->fd) < 0){
1250 if(p->open != popenfile)
1252 fd = open((char*)p->data, OREAD);
1257 if(rfork(RFPROC|RFMEM|RFFDG|RFNOTEG|RFNAMEG|RFNOWAIT) == 0){
1258 snprint(buf, sizeof(buf), "-pid %d", getpid());
1259 if(newwindow(buf) != -1){
1260 dupfds(fd, 1, 2, -1);
1261 if((fd = open("/dev/label", OWRITE)) >= 0){
1262 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));