17 int truetoboundingbox;
18 int textbits=4, gfxbits=4;
28 watcher(void *v, char *x)
31 if(strcmp(x, "die") != 0)
32 postnote(PNGROUP, notegp, x);
40 threadnotify(watcher, 1);
46 bell(void *u, char *x)
48 if(x && strcmp(x, "hangup") == 0)
51 if(x && strstr(x, "die") == nil)
52 fprint(2, "postnote %d: %s\n", getpid(), x);
54 /* alarms come from the gs monitor */
55 if(x && strstr(x, "alarm")){
56 postnote(PNGROUP, getpid(), "die (gs error)");
57 postnote(PNPROC, notewatcher, "die (gs error)");
60 /* function mentions u so that it's in the stack trace */
61 if((u == nil || u != x) && doabort)
64 /* fprint(2, "exiting %d\n", getpid()); */
74 s = va_arg(fmt->args, char*);
75 if(s == nil || s[0] == '\0')
76 return fmtstrcpy(fmt, "");
78 return fmtprint(fmt, "%#q", s);
84 fprint(2, "usage: page [-biRrwf] [-p ppi] file...\n");
95 threadmain(int argc, char **argv)
99 char *basename = argv[0];
100 enum { Ninput = 16 };
105 /* "temporary" debugging options */
119 textbits = atoi(EARGF(usage()));
120 gfxbits = atoi(EARGF(usage()));
131 ppi = atoi(EARGF(usage()));
134 truetoboundingbox = 1;
137 fprint(2, "%s: -w has only the effect of -R X11 systems\n", basename);
144 winsize = EARGF(usage());
155 notewatcher = proccreate(watcherproc, NULL, 1024);
156 if(notewatcher == -1){
157 sysfatal("proccreate");
162 threadnotify(bell, 1);
165 if(imagemode == 0 && argc == 0){
167 stdinfd = dup(0, -1);
169 open("/dev/tty", OREAD);
173 fmtinstall('a', afmt);
175 fmtinstall('R', Rfmt);
176 fmtinstall('P', Pfmt);
183 if(readn(stdinfd, buf, Ninput) != Ninput){
184 fprint(2, "page: short read reading %s\n", argv[0]);
190 if(!(b = Bopen(argv[0], OREAD))) {
191 fprint(2, "page: cannot open \"%s\"\n", argv[0]);
195 if(Bread(b, buf, Ninput) != Ninput) {
196 fprint(2, "page: short read reading %s\n", argv[0]);
204 doc = initgfx(nil, 0, nil, nil, 0);
205 else if(strncmp((char*)buf, "%PDF-", 5) == 0)
206 doc = initpdf(b, argc, argv, buf, Ninput);
207 else if(strncmp((char*)buf, "\x04%!", 2) == 0)
208 doc = initps(b, argc, argv, buf, Ninput);
209 else if(buf[0] == '\x1B' && strstr((char*)buf, "@PJL"))
210 doc = initps(b, argc, argv, buf, Ninput);
211 else if(strncmp((char*)buf, "%!", 2) == 0)
212 doc = initps(b, argc, argv, buf, Ninput);
213 else if(strcmp((char*)buf, "\xF7\x02\x01\x83\x92\xC0\x1C;") == 0)
214 doc = initdvi(b, argc, argv, buf, Ninput);
215 else if(strncmp((char*)buf, "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1", 8) == 0)
216 doc = initmsdoc(b, argc, argv, buf, Ninput);
217 else if(strncmp((char*)buf, "x T ", 4) == 0)
218 doc = inittroff(b, argc, argv, buf, Ninput);
221 fprint(2, "page: you can't specify -p with graphic files\n");
222 wexits("-p and graphics");
224 doc = initgfx(b, argc, argv, buf, Ninput);
228 fprint(2, "page: error reading file: %r\n");
229 wexits("document init");
232 if(doc->npage < 1 && !imagemode) {
233 fprint(2, "page: no pages found?\n");
237 if(reverse == -1) /* neither cmdline nor ps reader set it */
240 if(initdraw(0, 0, "page") < 0){
241 fprint(2, "page: initdraw failed: %r\n");
244 display->locking = 1;
246 truecolor = screen->depth > 8;
254 if(s && *s && strcmp(s, "note") != 0 && mknewwindow)
256 postnote(PNPROC, notewatcher, "die");
257 postnote(PNGROUP, getpid(), "die");