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"))
209 for(mfd = 0; fd >= 0; fd = va_arg(arg, int), mfd++)
214 if((fd = open("/fd", OREAD)) < 0)
215 sysfatal("open: %r");
216 n = dirreadall(fd, &dir);
218 if(strstr(dir[i].name, "ctl"))
220 fd = atoi(dir[i].name);
228 pipeline(int fd, char *fmt, ...)
230 char buf[NPATH], *argv[4];
240 vsnprint(buf, sizeof buf, fmt, arg);
242 switch(rfork(RFPROC|RFMEM|RFFDG|RFREND|RFNOWAIT)){
248 dupfds(fd, pfd[1], 2, -1);
253 exec("/bin/rc", argv);
254 sysfatal("exec: %r");
266 while(strlen(s) > 20){
267 if((x = strchr(s, '/')) == nil)
285 if((fd = dup(p->fd, -1)) < 0){
294 if(strcmp(p->ext, "ico") == 0)
295 snprint(nam, sizeof(nam), "%s -c", p->ext);
297 snprint(nam, sizeof(nam), "%s -t9", p->ext);
298 pipeline(fd, "%s", nam);
302 * dont keep the file descriptor arround if it can simply
305 fd2path(p->fd, nam, sizeof(nam));
306 if(strncmp(nam, pagespool, strlen(pagespool))){
309 p->data = strdup(nam);
321 pipeline(p->fd, "%s", (char*)p->data);
331 char mnt[32], cmd[64], *argv[4];
334 snprint(mnt, sizeof(mnt), "/n/tapefs.%.12d%.8lux", getpid(), (ulong)p);
335 snprint(cmd, sizeof(cmd), "%s -m %s /fd/0", (char*)p->data, mnt);
336 switch(rfork(RFPROC|RFMEM|RFFDG|RFREND)){
342 dupfds(p->fd, 1, 2, -1);
347 exec("/bin/rc", argv);
348 sysfatal("exec: %r");
353 p->data = strdup(mnt);
361 char buf[NPATH], *s, *e;
367 e = buf+sizeof(buf)-1;
368 s += snprint(s, e-s, "%s/", (char*)p->data);
371 pipeline(fd, "awk '/\\<rootfile/{"
372 "if(match($0, /full\\-path\\=\\\"([^\\\"]+)\\\"/)){"
373 "print substr($0, RSTART+11,RLENGTH-12);exit}}'");
374 n = read(fd, s, e - s);
378 while(n > 0 && s[n-1] == '\n')
382 if((fd = open(buf, OREAD)) < 0)
384 pipeline(fd, "awk '/\\<item/{"
385 "if(match($0, /id\\=\\\"([^\\\"]+)\\\"/)){"
386 "id=substr($0, RSTART+4, RLENGTH-5);"
387 "if(match($0, /href\\=\\\"([^\\\"]+)\\\"/)){"
388 "item[id]=substr($0, RSTART+6, RLENGTH-7)}}};"
390 "if(match($0, /idref\\=\\\"([^\\\"]+)\\\"/)){"
391 "ref=substr($0, RSTART+7, RLENGTH-8);"
392 "print item[ref]; fflush}}'");
393 s = strrchr(buf, '/')+1;
394 while((n = read(fd, s, e-s)) > 0){
395 while(n > 0 && s[n-1] == '\n')
398 addpage(p, shortname(buf), popenfile, strdup(buf), -1);
404 typedef struct Ghost Ghost;
423 switch(rfork(RFPROC|RFMEM|RFFDG|RFNOWAIT)){
431 dupfds(gs->pdat, gs->pin, pfd[1], -1);
432 fprint(1, "%s DoPDFPage\n"
435 "dup (THIS IS NOT AN INFERNO BITMAP\\n) writestring "
436 "flushfile\n", p->label);
437 while((n = read(0, buf, sizeof buf)) > 0){
438 if(memcmp(buf, "THIS IS NOT AN INFERNO BITMAP\n", 30) == 0)
450 infernobithdr(char *buf, int n)
453 if(memcmp(buf, "compressed\n", 11) == 0)
455 if(strtochan((char*)buf))
457 if(memcmp(buf, " ", 10) == 0 &&
458 '0' <= buf[10] && buf[10] <= '9' &&
468 int n, i, pdf, ifd, ofd, pin[2], pout[2], pdat[2];
469 char buf[NBUF], nam[32], *argv[16];
475 if(read(ifd, buf, 5) != 5)
478 if(memcmp(buf, "%PDF-", 5) == 0)
498 argv[0] = (char*)p->data;
499 switch(rfork(RFPROC|RFMEM|RFFDG|RFREND|RFNOWAIT)){
504 dupfds(pin[1], pout[1], 2, pdat[1], ifd, -1);
506 dupfds(nullfd, nullfd, 2, pdat[1], ifd, -1);
508 pipeline(4, "%s", argv[0]);
511 argv[2] = "-sDEVICE=plan9";
512 argv[3] = "-sOutputFile=/fd/3";
514 argv[5] = pdf ? "-dDELAYSAFER" : "-dSAFER";
516 argv[7] = "-dTextAlphaBits=4";
517 argv[8] = "-dGraphicsAlphaBits=4";
518 snprint(buf, sizeof buf, "-r%d", ppi);
520 argv[10] = "-dDOINTERPOLATE";
521 argv[11] = pdf ? "-" : "/fd/4";
523 exec("/bin/gs", argv);
524 sysfatal("exec: %r");
535 "/PAGEOUT (/fd/1) (w) file def\n"
536 "/PAGE== { PAGEOUT exch write==only PAGEOUT (\\n) writestring PAGEOUT flushfile } def\n"
540 "/PDFSave null def\n"
541 "/DSCPageCount 0 def\n"
542 "/DoPDFPage {dup /Page# exch store pdfgetpage pdfshowpage } def\n"
544 "GS_PDF_ProcSet begin\n"
546 "(/fd/4) (r) file { DELAYSAFER { .setsafe } if } stopped pop pdfopen begin\n"
548 "pdfpagecount PAGE==\n";
551 if(write(pin[0], prolog, n) != n)
553 if((n = read(pout[0], buf, sizeof(buf)-1)) < 0)
561 gs = mallocz(sizeof(*gs), 1);
566 snprint(nam, sizeof nam, "%d", i);
567 addpage(p, nam, popenpdf, gs, -1);
570 /* keep ghostscript arround */
575 while((n = read(pdat[0], buf, sizeof(buf))) >= 0){
576 if(ofd >= 0 && (n <= 0 || infernobithdr(buf, n))){
577 snprint(nam, sizeof nam, "%d", i);
578 addpage(p, nam, popenimg, nil, ofd);
584 snprint(nam, sizeof nam, "%.4d", ++i);
585 if((ofd = createtmp(nam)) < 0)
586 ofd = dup(nullfd, -1);
588 if(write(ofd, buf, n) != n)
602 filetype(char *buf, int nbuf, char *typ, int ntyp)
604 int n, ifd[2], ofd[2];
607 if(infernobithdr(buf, nbuf)){
608 strncpy(typ, "image/p9bit", ntyp);
620 if(rfork(RFPROC|RFMEM|RFFDG|RFREND|RFNOWAIT) == 0){
621 dupfds(ifd[1], ofd[1], 2, -1);
625 exec("/bin/file", argv);
629 if(rfork(RFPROC|RFMEM|RFFDG|RFNOWAIT) == 0){
635 if((n = readn(ofd[0], typ, ntyp-1)) < 0)
638 while(n > 0 && typ[n-1] == '\n')
645 dircmp(void *p1, void *p2)
652 return strcmp(d1->name, d2->name);
663 "application/pdf", popengs, nil,
664 "application/postscript", popengs, nil,
665 "application/troff", popengs, "lp -dstdout",
666 "text/plain", popengs, "lp -dstdout",
667 "text/html", popengs, "uhtml | html2ms | tbl | troff -ms | lp -dstdout",
668 "application/dvi", popengs, "dvips -Pps -r0 -q1 -f1",
669 "application/doc", popengs, "doc2ps",
670 "application/zip", popentape, "fs/zipfs",
671 "application/x-tar", popentape, "fs/tarfs",
672 "application/x-ustar", popentape, "fs/tarfs",
673 "application/x-compress", popenfilter, "uncompress",
674 "application/x-gzip", popenfilter, "gunzip",
675 "application/x-bzip2", popenfilter, "bunzip2",
676 "image/gif", popenimg, "gif",
677 "image/jpeg", popenimg, "jpg",
678 "image/png", popenimg, "png",
679 "image/ppm", popenimg, "ppm",
680 "image/bmp", popenimg, "bmp",
681 "image/tga", popenimg, "tga",
682 "image/x-icon", popenimg, "ico",
683 "image/p9bit", popenimg, nil,
686 char buf[NBUF], typ[128], *file;
696 if((fd = open(file, OREAD)) < 0){
703 if((d = dirfstat(fd)) == nil){
712 snprint(buf, sizeof(buf), "%s/META-INF/container.xml", file);
713 if((tfd = open(buf, OREAD)) >= 0){
721 if((n = dirreadall(fd, &d)) < 0)
723 qsort(d, n, sizeof d[0], dircmp);
725 addpage(p, d[i].name, popenfile, smprint("%s/%s", file, d[i].name), -1);
731 memset(buf, 0, NBUF/2);
732 if((n = readn(fd, buf, NBUF/2)) <= 0)
734 filetype(buf, n, typ, sizeof(typ));
735 for(i=0; i<nelem(tab); i++)
736 if(strncmp(typ, tab[i].typ, strlen(tab[i].typ)) == 0)
739 werrstr("unknown image format: %s", typ);
743 p->data = tab[i].data;
744 p->open = tab[i].open;
745 if(seek(fd, 0, 0) < 0)
747 if((i = readn(fd, buf+n, n)) < 0)
749 if(i != n || memcmp(buf, buf+n, i)){
752 if((tfd = createtmp("file")) < 0)
755 if(write(tfd, buf, n) != n)
757 if((n = read(fd, buf, sizeof(buf))) < 0)
760 if(dup(tfd, fd) < 0){
790 for(p = root->down; p; p = t)
791 if((t = nextpage(p)) == x)
803 if(p->open == nil || (fd = p->open(p)) < 0)
807 pipeline(fd, "rotate -r %d", rotate);
809 pipeline(fd, "resize -x %d", resize.x);
811 pipeline(fd, "resize -y %d", resize.y);
821 if(p->open && p->image == nil){
825 if((p->image = readimage(display, fd, 1)) == nil)
826 fprint(2, "readimage: %r\n");
838 if(p->open == nil || p->image == nil)
840 lockdisplay(display);
842 unlockdisplay(display);
851 for(p = root->down; p; p = nextpage(p)){
852 if(age == 0) /* synchronous flush */
854 else if(!canqlock(p))
856 if((pagegen - p->gen) >= age)
863 loadpages(Page *p, int ahead, int oviewgen)
867 ahead++; /* load at least one */
868 unloadpages(ahead*2);
869 for(i = 0; i < ahead && p; p = nextpage(p), i++){
870 if(viewgen != oviewgen)
874 if(viewgen != oviewgen){
884 if(size.x && size.y && newwin){
888 lockdisplay(display);
890 unlockdisplay(display);
898 * A draw operation that touches only the area contained in bot but not in top.
899 * mp and sp get aligned with bot.min.
902 gendrawdiff(Image *dst, Rectangle bot, Rectangle top,
903 Image *src, Point sp, Image *mask, Point mp, int op)
909 if(Dx(bot)*Dy(bot) == 0)
912 /* no points in bot - top */
913 if(rectinrect(bot, top))
916 /* bot - top ≡ bot */
917 if(Dx(top)*Dy(top)==0 || rectXrect(bot, top)==0){
918 gendrawop(dst, bot, src, sp, mask, mp, op);
923 /* split bot into rectangles that don't intersect top */
925 if(bot.min.x < top.min.x){
926 r = Rect(bot.min.x, bot.min.y, top.min.x, bot.max.y);
927 delta = subpt(r.min, origin);
928 gendrawop(dst, r, src, addpt(sp, delta), mask, addpt(mp, delta), op);
929 bot.min.x = top.min.x;
933 if(bot.max.x > top.max.x){
934 r = Rect(top.max.x, bot.min.y, bot.max.x, bot.max.y);
935 delta = subpt(r.min, origin);
936 gendrawop(dst, r, src, addpt(sp, delta), mask, addpt(mp, delta), op);
937 bot.max.x = top.max.x;
941 if(bot.min.y < top.min.y){
942 r = Rect(bot.min.x, bot.min.y, bot.max.x, top.min.y);
943 delta = subpt(r.min, origin);
944 gendrawop(dst, r, src, addpt(sp, delta), mask, addpt(mp, delta), op);
945 bot.min.y = top.min.y;
949 if(bot.max.y > top.max.y){
950 r = Rect(bot.min.x, top.max.y, bot.max.x, bot.max.y);
951 delta = subpt(r.min, origin);
952 gendrawop(dst, r, src, addpt(sp, delta), mask, addpt(mp, delta), op);
953 bot.max.y = top.max.y;
958 alphachan(ulong chan)
960 for(; chan; chan >>= 8)
961 if(TYPE(chan) == CAlpha)
967 zoomdraw(Image *d, Rectangle r, Rectangle top, Image *b, Image *s, Point sp, int f)
975 if(r.min.x < d->r.min.x){
976 sp.x += (d->r.min.x - r.min.x)/f;
977 a.x = (d->r.min.x - r.min.x)%f;
978 r.min.x = d->r.min.x;
980 if(r.min.y < d->r.min.y){
981 sp.y += (d->r.min.y - r.min.y)/f;
982 a.y = (d->r.min.y - r.min.y)%f;
983 r.min.y = d->r.min.y;
986 w = s->r.max.x - sp.x;
990 dr.max.x = dr.min.x+w;
991 if(!alphachan(s->chan))
994 if(b) gendrawdiff(d, dr, top, b, sp, nil, ZP, SoverD);
995 gendrawdiff(d, dr, top, s, sp, nil, ZP, SoverD);
998 if((t = allocimage(display, dr, s->chan, 0, 0)) == nil)
1000 for(; dr.min.y < r.max.y; dr.min.y++){
1001 dr.max.y = dr.min.y+1;
1002 draw(t, dr, s, nil, sp);
1009 for(sp=dr.min; dr.min.x < r.max.x; sp.x++){
1010 dr.max.x = dr.min.x+1;
1011 if(b) gendrawdiff(d, dr, top, b, sp, nil, ZP, SoverD);
1012 gendrawdiff(d, dr, top, t, sp, nil, ZP, SoverD);
1013 for(dr.min.x++; ++a.x < f && dr.min.x < r.max.x; dr.min.x++){
1014 dr.max.x = dr.min.x+1;
1015 gendrawdiff(d, dr, top, d, Pt(dr.min.x-1, dr.min.y), nil, ZP, SoverD);
1025 return p->image ? mulpt(subpt(p->image->r.max, p->image->r.min), zoom) : ZP;
1029 drawframe(Rectangle r)
1031 border(screen, r, -Borderwidth, frame, ZP);
1032 gendrawdiff(screen, screen->r, insetrect(r, -Borderwidth), ground, ZP, nil, ZP, SoverD);
1033 flushimage(display, 1);
1043 r = rectaddpt(Rpt(ZP, pagesize(p)), addpt(pos, screen->r.min));
1044 zoomdraw(screen, r, ZR, paper, i, i->r.min, zoom);
1046 r = Rpt(ZP, stringsize(font, p->label));
1047 r = rectaddpt(r, addpt(subpt(divpt(subpt(screen->r.max, screen->r.min), 2),
1048 divpt(r.max, 2)), screen->r.min));
1049 draw(screen, r, paper, nil, ZP);
1050 string(screen, r.min, display->black, ZP, font, p->label);
1056 translate(Page *p, Point d)
1062 if(i==0 || d.x==0 && d.y==0)
1064 r = rectaddpt(Rpt(ZP, pagesize(p)), addpt(pos, screen->r.min));
1065 pos = addpt(pos, d);
1066 nr = rectaddpt(r, d);
1067 rectclip(&r, screen->r);
1068 draw(screen, rectaddpt(r, d), screen, nil, r.min);
1069 zoomdraw(screen, nr, rectaddpt(r, d), paper, i, i->r.min, zoom);
1074 findpage(char *name)
1080 /* look in current document first */
1081 if(current && current->up){
1082 for(p = current->up->down; p; p = p->next)
1083 if(cistrncmp(p->label, name, n) == 0)
1086 /* look everywhere */
1087 for(p = root->down; p; p = nextpage(p))
1088 if(cistrncmp(p->label, name, n) == 0)
1098 for(p = root->down; i > 0 && p; p = nextpage(p))
1109 for(i = 0, p = root->down; p && p != x; p = nextpage(p))
1111 return (p == x) ? i : -1;
1126 if(i < 0 || i >= nelem(cmds))
1132 * spawn new proc to load a run of pages starting with p
1133 * the display should *not* be locked as it gets called
1134 * from recursive page load.
1144 esetcursor(&reading);
1150 switch(rfork(RFPROC|RFMEM)){
1152 sysfatal("rfork: %r");
1154 loadpages(p, NAHEAD, oviewgen);
1159 /* recursive display lock, called from main proc only */
1161 drawlock(int dolock){
1165 lockdisplay(display);
1168 unlockdisplay(display);
1186 for(p = nextpage(current); p; p = nextpage(p))
1187 if(p->image || p->open)
1197 for(p = prevpage(current); p; p = prevpage(p))
1198 if(p->image || p->open)
1206 char nam[64], *argv[4];
1213 if((fd = openpage(p)) < 0)
1215 if(rfork(RFPROC|RFMEM|RFFDG|RFENVG|RFNOTEG|RFNOWAIT) == 0){
1216 dupfds(fd, 1, 2, -1);
1217 snprint(nam, sizeof nam, "/bin/%s", argv0);
1222 sysfatal("exec: %r");
1233 char buf[128], label[64], *argv[4];
1239 snprint(label, sizeof(label), "%s %s", p->ext, p->label);
1241 ps = subpt(p->image->r.max, p->image->r.min);
1245 ps = subpt(screen->r.max, screen->r.min);
1247 if((fd = p->fd) < 0){
1248 if(p->open != popenfile)
1250 fd = open((char*)p->data, OREAD);
1255 if(rfork(RFPROC|RFMEM|RFFDG|RFNOTEG|RFNAMEG|RFNOWAIT) == 0){
1256 snprint(buf, sizeof(buf), "-pid %d -dx %d -dy %d", getpid(), ps.x, ps.y);
1257 if(newwindow(buf) != -1){
1258 dupfds(fd, 1, 2, -1);
1259 if((fd = open("/dev/label", OWRITE)) >= 0){
1260 write(fd, label, strlen(label));
1267 exec("/bin/rc", argv);
1282 if(new && getwindow(display, Refnone) == -1)
1283 sysfatal("getwindow: %r");
1294 void killcohort(void)
1297 for(i=0;i!=3;i++){ /* It's a long way to the kitchen */
1298 postnote(PNGROUP, cohort, "kill");
1303 void drawerr(Display *, char *msg)
1305 sysfatal("draw: %s", msg);
1311 fprint(2, "usage: %s [ -iRw ] [ -p ppi ] [ file ... ]\n", argv0);
1316 docmd(int i, Mouse *m)
1318 char buf[NPATH], *s;
1344 resize = subpt(screen->r.max, screen->r.min);
1350 resize = subpt(screen->r.max, screen->r.min);
1355 if(current == nil || !canqlock(current))
1357 o = subpt(m->xy, screen->r.min);
1359 if(zoom < 0x40000000){
1361 pos = addpt(mulpt(subpt(pos, o), 2), o);
1366 pos = addpt(divpt(subpt(pos, o), 2), o);
1373 if(current == nil || !canqlock(current))
1377 if(current->up && current->up != root)
1378 s = current->up->label;
1379 snprint(buf, sizeof(buf), "%s%s%s.bit",
1383 if(eenter("Write", buf, sizeof(buf), m) > 0){
1384 if((fd = create(buf, OWRITE, 0666)) < 0){
1385 errstr(buf, sizeof(buf));
1386 eenter(buf, 0, 0, m);
1388 esetcursor(&reading);
1389 writeimage(fd, current->image, 0);
1398 if(current == nil || !canqlock(current))
1418 main(int argc, char *argv[])
1420 enum { Eplumb = 4 };
1445 ppi = atoi(EARGF(usage()));
1452 * so that we can stop all subprocesses with a note,
1453 * and to isolate rendezvous from other processes
1455 atnotify(catchnote, 1);
1456 if(cohort = rfork(RFPROC|RFNOTEG|RFNAMEG|RFREND)){
1465 s = smprint("-pid %d", getpid());
1466 if(newwindow(s) < 0)
1467 sysfatal("newwindow: %r");
1470 if(initdraw(drawerr, nil, argv0) < 0)
1471 sysfatal("initdraw: %r");
1472 paper = display->white;
1473 frame = display->black;
1474 ground = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x777777FF);
1475 display->locking = 1;
1476 unlockdisplay(display);
1479 einit(Ekeyboard|Emouse);
1480 eplumb(Eplumb, "image");
1481 memset(&m, 0, sizeof(m));
1482 if((nullfd = open("/dev/null", ORDWR)) < 0)
1483 sysfatal("open: %r");
1484 current = root = addpage(nil, "", nil, nil, -1);
1485 if(*argv == nil && !imode)
1486 addpage(root, "stdin", popenfile, strdup("/fd/0"), -1);
1487 for(; *argv; argv++)
1488 addpage(root, shortname(*argv), popenfile, strdup(*argv), -1);
1499 if(current && canqlock(current)){
1503 if((m.buttons & 1) == 0)
1505 translate(current, subpt(m.xy, o));
1509 } else if(m.buttons & 2){
1511 i = emenuhit(2, &m, &cmdmenu);
1514 } else if(m.buttons & 4){
1519 pagemenu.lasthit = pageindex(current);
1520 x = pageat(emenuhit(3, &m, &pagemenu));
1529 if(current == nil || !canqlock(current))
1532 translate(current, Pt(0, Dy(screen->r)/2));
1536 if(prevpage(current))
1542 if(current == nil || !canqlock(current))
1544 o = addpt(pos, pagesize(current));
1545 if(o.y > Dy(screen->r)){
1546 translate(current, Pt(0, -Dy(screen->r)/2));
1550 if(nextpage(current))
1556 for(i = 0; i<nelem(cmds); i++)
1557 if((cmds[i].k1 == e.kbdc) ||
1558 (cmds[i].k2 == e.kbdc) ||
1559 (cmds[i].k3 == e.kbdc))
1561 if(i < nelem(cmds)){
1565 if((e.kbdc < 0x20) ||
1566 (e.kbdc & 0xFF00) == KF ||
1567 (e.kbdc & 0xFF00) == Spec)
1569 snprint(buf, sizeof(buf), "%C", (Rune)e.kbdc);
1570 if(eenter("Go to", buf, sizeof(buf), &m) > 0)
1571 showpage(findpage(buf));
1576 if(pm && pm->ndata > 0){
1580 s = plumblookup(pm->attr, "action");
1581 if(s && strcmp(s, "quit")==0)
1583 if(s && strcmp(s, "showdata")==0){
1584 if((fd = createtmp("plumb")) < 0){
1585 fprint(2, "plumb: createtmp: %r\n");
1589 if(fd2path(fd, s, NPATH) < 0){
1593 write(fd, pm->data, pm->ndata);
1594 }else if(pm->data[0] == '/'){
1595 s = strdup(pm->data);
1597 s = malloc(strlen(pm->wdir)+1+pm->ndata+1);
1598 sprint(s, "%s/%s", pm->wdir, pm->data);
1601 showpage(addpage(root, shortname(s), popenfile, s, fd));