9 typedef struct Page Page;
46 ulong imemlimit = 8*MiB;
49 Image *frame, *paper, *ground;
51 char pagespool[] = "/tmp/pagespool.";
83 [Corigsize] "orig size", 'o', Kesc, 0,
84 [Czoomin] "zoom in", '+', 0, 0,
85 [Czoomout] "zoom out", '-', 0, 0,
86 [Cfitwidth] "fit width", 'f', 0, 0,
87 [Cfitheight] "fit height", 'h', 0, 0,
88 [Crotate90] "rotate 90", 'r', 0, 0,
89 [Cupsidedown] "upside down", 'u', 0, 0,
90 [Cdummy1] "", 0, 0, 0,
91 [Cnext] "next", Kright, ' ', '\n',
92 [Cprev] "prev", Kleft, Kbs, 0,
93 [Czerox] "zerox", 'z', 0, 0,
94 [Cwrite] "write", 'w', 0, 0,
95 [Cext] "ext", 'x', 0, 0,
96 [Cdummy2] "", 0, 0, 0,
97 [Cquit] "quit", 'q', Kdel, Keof,
100 char *pagemenugen(int i);
101 char *cmdmenugen(int i);
117 {0xff, 0x80, 0xff, 0x80, 0xff, 0x00, 0xfe, 0x00,
118 0xff, 0x00, 0xff, 0x80, 0xff, 0xc0, 0xef, 0xe0,
119 0xc7, 0xf0, 0x03, 0xf0, 0x01, 0xe0, 0x00, 0xc0,
120 0x03, 0xff, 0x03, 0xff, 0x03, 0xff, 0x03, 0xff, },
121 {0x00, 0x00, 0x7f, 0x00, 0x7e, 0x00, 0x7c, 0x00,
122 0x7e, 0x00, 0x7f, 0x00, 0x6f, 0x80, 0x47, 0xc0,
123 0x03, 0xe0, 0x01, 0xf0, 0x00, 0xe0, 0x00, 0x40,
124 0x00, 0x00, 0x01, 0xb6, 0x01, 0xb6, 0x00, 0x00, }
127 void showpage1(Page *);
128 void showpage(Page *);
129 void drawpage(Page *);
130 Point pagesize(Page *);
133 addpage(Page *up, char *label, int (*popen)(Page *), void *pdata, int fd)
137 p = mallocz(sizeof(*p), 1);
138 p->label = strdup(label);
147 up->down = up->tail = p;
155 if(up && current == up)
161 resizewin(Point size)
165 if((wctl = open("/dev/wctl", OWRITE)) < 0)
168 size = addpt(size, Pt(Borderwidth*2, Borderwidth*2));
170 Point dsize = subpt(display->image->r.max, display->image->r.min);
175 /* can't just conver whole display */
176 if(eqpt(size, dsize))
179 fprint(wctl, "resize -dx %d -dy %d\n", size.x, size.y);
188 snprint(nam, sizeof nam, "%s%s%.12d%.8lux", pagespool, pfx, getpid(), id++);
189 return create(nam, OEXCL|ORCLOSE|ORDWR, 0600);
193 catchnote(void *, char *msg)
195 if(strstr(msg, "sys: write on closed pipe"))
197 if(strstr(msg, "hangup"))
199 if(strstr(msg, "alarm"))
201 if(strstr(msg, "interrupt"))
203 if(strstr(msg, "kill"))
216 for(mfd = 0; fd >= 0; fd = va_arg(arg, int), mfd++)
221 if((fd = open("/fd", OREAD)) < 0)
222 sysfatal("open: %r");
223 n = dirreadall(fd, &dir);
225 if(strstr(dir[i].name, "ctl"))
227 fd = atoi(dir[i].name);
235 pipeline(int fd, char *fmt, ...)
237 char buf[NPATH], *argv[4];
247 vsnprint(buf, sizeof buf, fmt, arg);
249 switch(rfork(RFPROC|RFMEM|RFFDG|RFREND|RFNOWAIT)){
255 dupfds(fd, pfd[1], 2, -1);
260 exec("/bin/rc", argv);
261 sysfatal("exec: %r");
273 while(strlen(s) > 20){
274 if((x = strchr(s, '/')) == nil)
292 if((fd = dup(p->fd, -1)) < 0){
301 if(strcmp(p->ext, "ico") == 0)
302 snprint(nam, sizeof(nam), "%s -c", p->ext);
304 snprint(nam, sizeof(nam), "%s -t9", p->ext);
305 pipeline(fd, "%s", nam);
309 * dont keep the file descriptor arround if it can simply
312 fd2path(p->fd, nam, sizeof(nam));
313 if(strncmp(nam, pagespool, strlen(pagespool))){
316 p->data = strdup(nam);
328 pipeline(p->fd, "%s", (char*)p->data);
338 char mnt[32], cmd[64], *argv[4];
341 snprint(mnt, sizeof(mnt), "/n/tapefs.%.12d%.8lux", getpid(), (ulong)p);
342 snprint(cmd, sizeof(cmd), "%s -m %s /fd/0", (char*)p->data, mnt);
343 switch(rfork(RFPROC|RFMEM|RFFDG|RFREND)){
349 dupfds(p->fd, 1, 2, -1);
354 exec("/bin/rc", argv);
355 sysfatal("exec: %r");
360 p->data = strdup(mnt);
368 char buf[NPATH], *s, *e;
374 e = buf+sizeof(buf)-1;
375 s += snprint(s, e-s, "%s/", (char*)p->data);
378 pipeline(fd, "awk '/\\<rootfile/{"
379 "if(match($0, /full\\-path\\=\\\"([^\\\"]+)\\\"/)){"
380 "print substr($0, RSTART+11,RLENGTH-12);exit}}'");
381 n = read(fd, s, e - s);
385 while(n > 0 && s[n-1] == '\n')
389 if((fd = open(buf, OREAD)) < 0)
391 pipeline(fd, "awk '/\\<item/{"
392 "if(match($0, /id\\=\\\"([^\\\"]+)\\\"/)){"
393 "id=substr($0, RSTART+4, RLENGTH-5);"
394 "if(match($0, /href\\=\\\"([^\\\"]+)\\\"/)){"
395 "item[id]=substr($0, RSTART+6, RLENGTH-7)}}};"
397 "if(match($0, /idref\\=\\\"([^\\\"]+)\\\"/)){"
398 "ref=substr($0, RSTART+7, RLENGTH-8);"
399 "print item[ref]; fflush}}'");
400 s = strrchr(buf, '/')+1;
401 while((n = read(fd, s, e-s)) > 0){
402 while(n > 0 && s[n-1] == '\n')
405 addpage(p, shortname(buf), popenfile, strdup(buf), -1);
411 typedef struct Ghost Ghost;
430 switch(rfork(RFPROC|RFMEM|RFFDG|RFNOWAIT)){
438 dupfds(gs->pdat, gs->pin, pfd[1], -1);
439 fprint(1, "%s DoPDFPage\n"
442 "dup (THIS IS NOT AN INFERNO BITMAP\\n) writestring "
443 "flushfile\n", p->label);
444 while((n = read(0, buf, sizeof buf)) > 0){
445 if(memcmp(buf, "THIS IS NOT AN INFERNO BITMAP\n", 30) == 0)
457 infernobithdr(char *buf, int n)
460 if(memcmp(buf, "compressed\n", 11) == 0)
462 if(strtochan((char*)buf))
464 if(memcmp(buf, " ", 10) == 0 &&
465 '0' <= buf[10] && buf[10] <= '9' &&
475 int n, i, pdf, ifd, ofd, pin[2], pout[2], pdat[2];
476 char buf[NBUF], nam[32], *argv[16];
482 if(read(ifd, buf, 5) != 5)
485 if(memcmp(buf, "%PDF-", 5) == 0)
505 argv[0] = (char*)p->data;
506 switch(rfork(RFPROC|RFMEM|RFFDG|RFREND|RFNOWAIT)){
511 dupfds(pin[1], pout[1], 2, pdat[1], ifd, -1);
513 dupfds(nullfd, nullfd, 2, pdat[1], ifd, -1);
515 pipeline(4, "%s", argv[0]);
518 argv[2] = "-sDEVICE=plan9";
519 argv[3] = "-sOutputFile=/fd/3";
521 argv[5] = pdf ? "-dDELAYSAFER" : "-dSAFER";
523 argv[7] = "-dTextAlphaBits=4";
524 argv[8] = "-dGraphicsAlphaBits=4";
525 snprint(buf, sizeof buf, "-r%d", ppi);
527 argv[10] = "-dDOINTERPOLATE";
528 argv[11] = pdf ? "-" : "/fd/4";
530 exec("/bin/gs", argv);
531 sysfatal("exec: %r");
542 "/PAGEOUT (/fd/1) (w) file def\n"
543 "/PAGE== { PAGEOUT exch write==only PAGEOUT (\\n) writestring PAGEOUT flushfile } def\n"
547 "/PDFSave null def\n"
548 "/DSCPageCount 0 def\n"
549 "/DoPDFPage {dup /Page# exch store pdfgetpage pdfshowpage } def\n"
551 "GS_PDF_ProcSet begin\n"
553 "(/fd/4) (r) file { DELAYSAFER { .setsafe } if } stopped pop pdfopen begin\n"
555 "pdfpagecount PAGE==\n";
558 if(write(pin[0], prolog, n) != n)
560 if((n = read(pout[0], buf, sizeof(buf)-1)) < 0)
568 gs = mallocz(sizeof(*gs), 1);
573 snprint(nam, sizeof nam, "%d", i);
574 addpage(p, nam, popenpdf, gs, -1);
577 /* keep ghostscript arround */
582 while((n = read(pdat[0], buf, sizeof(buf))) >= 0){
583 if(ofd >= 0 && (n <= 0 || infernobithdr(buf, n))){
584 snprint(nam, sizeof nam, "%d", i);
585 addpage(p, nam, popenimg, nil, ofd);
591 snprint(nam, sizeof nam, "%.4d", ++i);
592 if((ofd = createtmp(nam)) < 0)
593 ofd = dup(nullfd, -1);
595 if(write(ofd, buf, n) != n)
609 filetype(char *buf, int nbuf, char *typ, int ntyp)
611 int n, ifd[2], ofd[2];
614 if(infernobithdr(buf, nbuf)){
615 strncpy(typ, "image/p9bit", ntyp);
627 if(rfork(RFPROC|RFMEM|RFFDG|RFREND|RFNOWAIT) == 0){
628 dupfds(ifd[1], ofd[1], 2, -1);
632 exec("/bin/file", argv);
636 if(rfork(RFPROC|RFMEM|RFFDG|RFNOWAIT) == 0){
642 if((n = readn(ofd[0], typ, ntyp-1)) < 0)
645 while(n > 0 && typ[n-1] == '\n')
652 dircmp(void *p1, void *p2)
659 return strcmp(d1->name, d2->name);
670 "application/pdf", popengs, nil,
671 "application/postscript", popengs, nil,
672 "application/troff", popengs, "lp -dstdout",
673 "text/plain", popengs, "lp -dstdout",
674 "text/html", popengs, "uhtml | html2ms | tbl | troff -ms | lp -dstdout",
675 "application/dvi", popengs, "dvips -Pps -r0 -q1 -f1",
676 "application/doc", popengs, "doc2ps",
677 "application/zip", popentape, "fs/zipfs",
678 "application/x-tar", popentape, "fs/tarfs",
679 "application/x-ustar", popentape, "fs/tarfs",
680 "application/x-compress", popenfilter, "uncompress",
681 "application/x-gzip", popenfilter, "gunzip",
682 "application/x-bzip2", popenfilter, "bunzip2",
683 "image/gif", popenimg, "gif",
684 "image/jpeg", popenimg, "jpg",
685 "image/png", popenimg, "png",
686 "image/tiff", popenimg, "tif",
687 "image/ppm", popenimg, "ppm",
688 "image/bmp", popenimg, "bmp",
689 "image/tga", popenimg, "tga",
690 "image/x-icon", popenimg, "ico",
691 "image/p9bit", popenimg, nil,
694 char buf[NBUF], typ[128], *file;
704 if((fd = open(file, OREAD)) < 0){
711 if((d = dirfstat(fd)) == nil){
720 snprint(buf, sizeof(buf), "%s/META-INF/container.xml", file);
721 if((tfd = open(buf, OREAD)) >= 0){
729 if((n = dirreadall(fd, &d)) < 0)
731 qsort(d, n, sizeof d[0], dircmp);
733 addpage(p, d[i].name, popenfile, smprint("%s/%s", file, d[i].name), -1);
739 memset(buf, 0, NBUF/2);
740 if((n = readn(fd, buf, NBUF/2)) <= 0)
742 filetype(buf, n, typ, sizeof(typ));
743 for(i=0; i<nelem(tab); i++)
744 if(strncmp(typ, tab[i].typ, strlen(tab[i].typ)) == 0)
747 werrstr("unknown image format: %s", typ);
751 p->data = tab[i].data;
752 p->open = tab[i].open;
753 if(seek(fd, 0, 0) < 0)
755 if((i = readn(fd, buf+n, n)) < 0)
757 if(i != n || memcmp(buf, buf+n, i)){
760 if((tfd = createtmp("file")) < 0)
763 if(write(tfd, buf, n) != n)
765 if((n = read(fd, buf, sizeof(buf))) < 0)
768 if(dup(tfd, fd) < 0){
798 for(p = root->down; p; p = t)
799 if((t = nextpage(p)) == x)
811 if(p->open == nil || (fd = p->open(p)) < 0)
815 pipeline(fd, "rotate -r %d", rotate);
817 pipeline(fd, "resize -x %d", resize.x);
819 pipeline(fd, "resize -y %d", resize.y);
829 return Dy(i->r)*bytesperline(i->r, i->depth);
835 if(p->lnext == nil || p->lnext == p)
837 p->lnext->lprev = p->lprev;
838 p->lprev->lnext = p->lnext;
850 p->lnext = lru.lnext;
856 if(p->open && p->image == nil){
859 if((p->image = readimage(display, fd, 1)) == nil)
860 fprint(2, "readimage: %r\n");
866 lockdisplay(display);
867 imemsize += imagesize(p->image);
868 unlockdisplay(display);
880 if(p->open == nil || p->image == nil)
882 lockdisplay(display);
883 imemsize -= imagesize(p->image);
885 unlockdisplay(display);
890 unloadpages(ulong limit)
894 while(imemsize >= limit && (p = lru.lprev) != &lru){
902 loadpages(Page *p, int oviewgen)
904 while(p && viewgen == oviewgen){
907 if(viewgen != oviewgen){
917 if(size.x && size.y && newwin){
921 lockdisplay(display);
923 unlockdisplay(display);
926 if(p != current || imemsize >= imemlimit)
933 * A draw operation that touches only the area contained in bot but not in top.
934 * mp and sp get aligned with bot.min.
937 gendrawdiff(Image *dst, Rectangle bot, Rectangle top,
938 Image *src, Point sp, Image *mask, Point mp, int op)
944 if(Dx(bot)*Dy(bot) == 0)
947 /* no points in bot - top */
948 if(rectinrect(bot, top))
951 /* bot - top ≡ bot */
952 if(Dx(top)*Dy(top)==0 || rectXrect(bot, top)==0){
953 gendrawop(dst, bot, src, sp, mask, mp, op);
958 /* split bot into rectangles that don't intersect top */
960 if(bot.min.x < top.min.x){
961 r = Rect(bot.min.x, bot.min.y, top.min.x, bot.max.y);
962 delta = subpt(r.min, origin);
963 gendrawop(dst, r, src, addpt(sp, delta), mask, addpt(mp, delta), op);
964 bot.min.x = top.min.x;
968 if(bot.max.x > top.max.x){
969 r = Rect(top.max.x, bot.min.y, bot.max.x, bot.max.y);
970 delta = subpt(r.min, origin);
971 gendrawop(dst, r, src, addpt(sp, delta), mask, addpt(mp, delta), op);
972 bot.max.x = top.max.x;
976 if(bot.min.y < top.min.y){
977 r = Rect(bot.min.x, bot.min.y, bot.max.x, top.min.y);
978 delta = subpt(r.min, origin);
979 gendrawop(dst, r, src, addpt(sp, delta), mask, addpt(mp, delta), op);
980 bot.min.y = top.min.y;
984 if(bot.max.y > top.max.y){
985 r = Rect(bot.min.x, top.max.y, bot.max.x, bot.max.y);
986 delta = subpt(r.min, origin);
987 gendrawop(dst, r, src, addpt(sp, delta), mask, addpt(mp, delta), op);
988 bot.max.y = top.max.y;
993 alphachan(ulong chan)
995 for(; chan; chan >>= 8)
996 if(TYPE(chan) == CAlpha)
1002 zoomdraw(Image *d, Rectangle r, Rectangle top, Image *b, Image *s, Point sp, int f)
1010 if(r.min.x < d->r.min.x){
1011 sp.x += (d->r.min.x - r.min.x)/f;
1012 a.x = (d->r.min.x - r.min.x)%f;
1013 r.min.x = d->r.min.x;
1015 if(r.min.y < d->r.min.y){
1016 sp.y += (d->r.min.y - r.min.y)/f;
1017 a.y = (d->r.min.y - r.min.y)%f;
1018 r.min.y = d->r.min.y;
1021 w = s->r.max.x - sp.x;
1025 dr.max.x = dr.min.x+w;
1026 if(!alphachan(s->chan))
1029 if(b) gendrawdiff(d, dr, top, b, sp, nil, ZP, SoverD);
1030 gendrawdiff(d, dr, top, s, sp, nil, ZP, SoverD);
1033 if((t = allocimage(display, dr, s->chan, 0, 0)) == nil)
1035 for(; dr.min.y < r.max.y; dr.min.y++){
1036 dr.max.y = dr.min.y+1;
1037 draw(t, dr, s, nil, sp);
1044 for(sp=dr.min; dr.min.x < r.max.x; sp.x++){
1045 dr.max.x = dr.min.x+1;
1046 if(b) gendrawdiff(d, dr, top, b, sp, nil, ZP, SoverD);
1047 gendrawdiff(d, dr, top, t, sp, nil, ZP, SoverD);
1048 for(dr.min.x++; ++a.x < f && dr.min.x < r.max.x; dr.min.x++){
1049 dr.max.x = dr.min.x+1;
1050 gendrawdiff(d, dr, top, d, Pt(dr.min.x-1, dr.min.y), nil, ZP, SoverD);
1060 return p->image ? mulpt(subpt(p->image->r.max, p->image->r.min), zoom) : ZP;
1064 drawframe(Rectangle r)
1066 border(screen, r, -Borderwidth, frame, ZP);
1067 gendrawdiff(screen, screen->r, insetrect(r, -Borderwidth), ground, ZP, nil, ZP, SoverD);
1068 flushimage(display, 1);
1078 r = rectaddpt(Rpt(ZP, pagesize(p)), addpt(pos, screen->r.min));
1079 zoomdraw(screen, r, ZR, paper, i, i->r.min, zoom);
1081 r = Rpt(ZP, stringsize(font, p->label));
1082 r = rectaddpt(r, addpt(subpt(divpt(subpt(screen->r.max, screen->r.min), 2),
1083 divpt(r.max, 2)), screen->r.min));
1084 draw(screen, r, paper, nil, ZP);
1085 string(screen, r.min, display->black, ZP, font, p->label);
1091 translate(Page *p, Point d)
1097 if(i==0 || d.x==0 && d.y==0)
1099 r = rectaddpt(Rpt(ZP, pagesize(p)), addpt(pos, screen->r.min));
1100 pos = addpt(pos, d);
1101 nr = rectaddpt(r, d);
1102 rectclip(&r, screen->r);
1103 draw(screen, rectaddpt(r, d), screen, nil, r.min);
1104 zoomdraw(screen, nr, rectaddpt(r, d), paper, i, i->r.min, zoom);
1109 findpage(char *name)
1115 /* look in current document first */
1116 if(current && current->up){
1117 for(p = current->up->down; p; p = p->next)
1118 if(cistrncmp(p->label, name, n) == 0)
1121 /* look everywhere */
1122 for(p = root->down; p; p = nextpage(p))
1123 if(cistrncmp(p->label, name, n) == 0)
1133 for(p = root->down; i > 0 && p; p = nextpage(p))
1144 for(i = 0, p = root->down; p && p != x; p = nextpage(p))
1146 return (p == x) ? i : -1;
1161 if(i < 0 || i >= nelem(cmds))
1167 * spawn new proc to load a run of pages starting with p
1168 * the display should *not* be locked as it gets called
1169 * from recursive page load.
1179 esetcursor(&reading);
1182 switch(rfork(RFPROC|RFMEM)){
1184 sysfatal("rfork: %r");
1186 loadpages(p, oviewgen);
1189 if(++nproc >= NPROC)
1194 /* recursive display lock, called from main proc only */
1196 drawlock(int dolock){
1200 lockdisplay(display);
1203 unlockdisplay(display);
1215 unloadpages(imemlimit/2);
1225 for(p = nextpage(current); p; p = nextpage(p))
1226 if(p->image || p->open)
1236 for(p = prevpage(current); p; p = prevpage(p))
1237 if(p->image || p->open)
1245 char nam[64], *argv[4];
1252 if((fd = openpage(p)) < 0)
1254 if(rfork(RFPROC|RFMEM|RFFDG|RFENVG|RFNOTEG|RFNOWAIT) == 0){
1255 dupfds(fd, 1, 2, -1);
1256 snprint(nam, sizeof nam, "/bin/%s", argv0);
1261 sysfatal("exec: %r");
1272 char label[64], *argv[4];
1278 snprint(label, sizeof(label), "%s %s", p->ext, p->label);
1281 ps = addpt(subpt(p->image->r.max, p->image->r.min), Pt(24, 24));
1283 if((fd = p->fd) < 0){
1284 if(p->open != popenfile)
1286 fd = open((char*)p->data, OREAD);
1291 if(rfork(RFPROC|RFMEM|RFFDG|RFNOTEG|RFNOWAIT) == 0){
1292 if(newwindow(nil) != -1){
1293 dupfds(fd, open("/dev/cons", OWRITE), open("/dev/cons", OWRITE), -1);
1294 if((fd = open("/dev/label", OWRITE)) >= 0){
1295 write(fd, label, strlen(label));
1304 exec("/bin/rc", argv);
1319 if(new && getwindow(display, Refnone) == -1)
1320 sysfatal("getwindow: %r");
1331 void killcohort(void)
1334 for(i=0;i!=3;i++){ /* It's a long way to the kitchen */
1335 postnote(PNGROUP, cohort, "kill");
1340 void drawerr(Display *, char *msg)
1342 sysfatal("draw: %s", msg);
1348 fprint(2, "usage: %s [ -iRw ] [ -m mb ] [ -p ppi ] [ file ... ]\n", argv0);
1353 docmd(int i, Mouse *m)
1355 char buf[NPATH], *s;
1381 resize = subpt(screen->r.max, screen->r.min);
1387 resize = subpt(screen->r.max, screen->r.min);
1392 if(current == nil || !canqlock(current))
1394 o = subpt(m->xy, screen->r.min);
1398 pos = addpt(mulpt(subpt(pos, o), 2), o);
1403 pos = addpt(divpt(subpt(pos, o), 2), o);
1410 if(current == nil || !canqlock(current))
1414 if(current->up && current->up != root)
1415 s = current->up->label;
1416 snprint(buf, sizeof(buf), "%s%s%s.bit",
1420 if(eenter("Write", buf, sizeof(buf), m) > 0){
1421 if((fd = create(buf, OWRITE, 0666)) < 0){
1422 errstr(buf, sizeof(buf));
1423 eenter(buf, 0, 0, m);
1425 esetcursor(&reading);
1426 writeimage(fd, current->image, 0);
1435 if(current == nil || !canqlock(current))
1455 main(int argc, char *argv[])
1457 enum { Eplumb = 4 };
1483 imemlimit = atol(EARGF(usage()))*MiB;
1486 ppi = atoi(EARGF(usage()));
1493 * so that we can stop all subprocesses with a note,
1494 * and to isolate rendezvous from other processes
1496 atnotify(catchnote, 1);
1497 if(cohort = rfork(RFPROC|RFNOTEG|RFNAMEG|RFREND)){
1506 if(newwindow(nil) < 0)
1507 sysfatal("newwindow: %r");
1509 if(initdraw(drawerr, nil, argv0) < 0)
1510 sysfatal("initdraw: %r");
1511 paper = display->white;
1512 frame = display->black;
1513 ground = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x777777FF);
1514 display->locking = 1;
1515 unlockdisplay(display);
1518 einit(Ekeyboard|Emouse);
1519 eplumb(Eplumb, "image");
1520 memset(&m, 0, sizeof(m));
1521 if((nullfd = open("/dev/null", ORDWR)) < 0)
1522 sysfatal("open: %r");
1526 current = root = addpage(nil, "", nil, nil, -1);
1527 if(*argv == nil && !imode)
1528 addpage(root, "stdin", popenfile, strdup("/fd/0"), -1);
1529 for(; *argv; argv++)
1530 addpage(root, shortname(*argv), popenfile, strdup(*argv), -1);
1541 if(current && canqlock(current)){
1545 if((m.buttons & 1) == 0)
1547 translate(current, subpt(m.xy, o));
1551 } else if(m.buttons & 2){
1553 i = emenuhit(2, &m, &cmdmenu);
1556 } else if(m.buttons & 4){
1561 pagemenu.lasthit = pageindex(current);
1562 x = pageat(emenuhit(3, &m, &pagemenu));
1571 if(current == nil || !canqlock(current))
1574 translate(current, Pt(0, Dy(screen->r)/2));
1578 if(prevpage(current))
1584 if(current == nil || !canqlock(current))
1586 o = addpt(pos, pagesize(current));
1587 if(o.y > Dy(screen->r)){
1588 translate(current, Pt(0, -Dy(screen->r)/2));
1592 if(nextpage(current))
1598 for(i = 0; i<nelem(cmds); i++)
1599 if((cmds[i].k1 == e.kbdc) ||
1600 (cmds[i].k2 == e.kbdc) ||
1601 (cmds[i].k3 == e.kbdc))
1603 if(i < nelem(cmds)){
1607 if((e.kbdc < 0x20) ||
1608 (e.kbdc & 0xFF00) == KF ||
1609 (e.kbdc & 0xFF00) == Spec)
1611 snprint(buf, sizeof(buf), "%C", (Rune)e.kbdc);
1612 if(eenter("Go to", buf, sizeof(buf), &m) > 0)
1613 showpage(findpage(buf));
1618 if(pm && pm->ndata > 0){
1622 s = plumblookup(pm->attr, "action");
1623 if(s && strcmp(s, "quit")==0)
1625 if(s && strcmp(s, "showdata")==0){
1626 if((fd = createtmp("plumb")) < 0){
1627 fprint(2, "plumb: createtmp: %r\n");
1631 if(fd2path(fd, s, NPATH) < 0){
1635 write(fd, pm->data, pm->ndata);
1636 }else if(pm->data[0] == '/'){
1637 s = strdup(pm->data);
1639 s = malloc(strlen(pm->wdir)+1+pm->ndata+1);
1640 sprint(s, "%s/%s", pm->wdir, pm->data);
1643 showpage(addpage(root, shortname(s), popenfile, s, fd));