9 vector<BBox> gs_bboxes(const char *in)
13 die("Cannot create pipe: %m");
17 die("Cannot fork: %m");
25 execlp("gs", "gs", "-sDEVICE=bbox", "-dSAFER", "-dBATCH", "-dNOPAUSE", "-q", in, NULL);
26 die("Cannot execute gs: %m");
30 FILE *f = fdopen(pipes[0], "r");
32 die("fdopen failed: %m");
36 while (fgets(line, sizeof(line), f))
38 char *eol = strchr(line, '\n');
40 die("Ghostscript produced too long lines");
43 if (!strncmp(line, "%%HiResBoundingBox: ", 20))
45 double x1, y1, x2, y2;
46 if (sscanf(line+20, "%lf%lf%lf%lf", &x1, &y1, &x2, &y2) != 4)
47 die("Cannot parse Ghostscript output: %s", line);
48 bboxes.push_back(BBox(x1, y1, x2, y2));
50 else if (line[0] != '%')
51 fprintf(stderr, "%s\n", line);
56 if (waitpid(pid, &stat, 0) < 0)
57 die("wait failed: %m");
58 if (!WIFEXITED(stat) || WEXITSTATUS(stat))
59 die("Ghostscript failed");