/* Copyright (C) 1989, 1990 Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.uucp)
This file is part of groff.
groff is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 1, or (at your option) any later
groff is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
You should have received a copy of the GNU General Public License along
with groff; see the file LICENSE. If not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
const char *do_file(FILE *, struct bounding_box
*);
int parse_bounding_box(char *, struct bounding_box
*);
#define const /* as nothing */
int parse_bounding_box();
fprintf(stderr
, "usage: %s filename\n", argv
[0]);
fp
= fopen(argv
[1], "r");
fprintf(stderr
, "%s: can't open `%s': ", argv
[0], argv
[1]);
message
= do_file(fp
, &bb
);
fprintf(stderr
, "%s: ", argv
[0]);
fprintf(stderr
, message
, argv
[1]);
printf("%d %d %d %d\n", bb
.llx
, bb
.lly
, bb
.urx
, bb
.ury
);
/* If the bounding box was found return NULL, and store the bounding box
in bb. If the bounding box was not found return a string suitable for
giving to printf with the filename as an argument saying why not. */
const char *do_file(fp
, bb
)
if (!fgets(buf
, sizeof(buf
), fp
))
if (strncmp("%!PS-Adobe-", buf
, 11) != 0)
return "%s is not conforming";
while (fgets(buf
, sizeof(buf
), fp
) != 0) {
if (buf
[0] != '%' || buf
[1] != '%'
|| strncmp(buf
+ 2, "EndComments", 11) == 0)
if (strncmp(buf
+ 2, "BoundingBox:", 12) == 0) {
int res
= parse_bounding_box(buf
+ 14, bb
);
return "the arguments to the %%%%BoundingBox comment in %s are bad";
/* in the trailer, the last BoundingBox comment is significant */
for (offset
= 512; !last_try
; offset
*= 2) {
if (offset
> 32768 || fseek(fp
, -offset
, 2) == -1) {
if (fseek(fp
, 0L, 0) == -1)
while (fgets(buf
, sizeof(buf
), fp
) != 0) {
if (buf
[0] == '%' && buf
[1] == '%') {
if (strncmp(buf
+ 2, "Trailer", 7) == 0)
if (strncmp(buf
+ 2, "BoundingBox:", 12) == 0) {
int res
= parse_bounding_box(buf
+ 14, bb
);
return "`(atend)' not allowed in trailer";
return "the arguments to the %%%%BoundingBox comment in %s are bad";
return "%%%%BoundingBox comment not found in %s";
/* Parse the argument to a %%BoundingBox comment. Return 1 if it
contains 4 numbers, 2 if it contains (atend), 0 otherwise. */
int parse_bounding_box(p
, bb
)
if (sscanf(p
, "%d %d %d %d",
&bb
->llx
, &bb
->lly
, &bb
->urx
, &bb
->ury
) == 4)
/* The Document Structuring Conventions say that the numbers
should be integers. Unfortunately some broken applications
if (sscanf(p
, "%lf %lf %lf %lf", &x1
, &x2
, &x3
, &x4
) == 4) {
for (; *p
== ' ' || *p
== '\t'; p
++)
if (strncmp(p
, "(atend)", 7) == 0) {