Listing 1: rmprep.c
Removing "LaserPrep" from a PostScript document
(reproduced by permission of the author, Vui Le, of Qualix)
/* rmprep.c
Remove "LaserPrep" from PostScript document.
Assumptions:
1) LaserPrep begins with the following 3 lines:
==> %!PS-Adobe-2.0 Query
==>
==> % *EOF*
2) The string "%!PS-Adobe-2.0" signifies the end of LaserPrep
and beginning of PostScript document.
*/
#include <stdio.h>
void main() {
char buf[3][BUFSIZ];
int isLaserPrep=1; /* assume file has LaserPrep */
int endLaserPrep=0; /* have we reached end of LaserPrep? */
fgets(buf[0], BUFSIZ, stdin);
fgets(buf[1], BUFSIZ, stdin);
fgets(buf[2], BUFSIZ, stdin);
if (strcmp(buf[0], "%!PS-Adobe-2.0 Query\n") != 0)
isLaserPrep &= 0; /* File doesn't have LaserPrep */
if (isLaserPrep &&
(strcmp(buf[1], "\n") != 0) &&
(strcmp(buf[1], "\r") != 0) &&
(strcmp(buf[1], "\r\n") != 0))
isLaserPrep &= 0;
if (isLaserPrep && (strcmp(buf[2], "% *EOF*\n") != 0))
isLaserPrep &= 0;
/* Not a LaserPrep, return stream to stdout */
if (!isLaserPrep) {
printf("%s", buf[0]);
printf("%s", buf[1]);
printf("%s", buf[2]);
}
fgets(buf[0], BUFSIZ, stdin);
/* Throw away lines until end of LaserPrep */
if (isLaserPrep) {
while (!feof(stdin) && !endLaserPrep) {
fgets(buf[0], BUFSIZ, stdin);
if (strcmp(buf[0], "%!PS-Adobe-2.0\n") == 0)
endLaserPrep = 1;
}
}
while (!feof(stdin)) {
printf("%s", buf[0]);
fgets(buf[0], BUFSIZ, stdin);
}
}
/* End of File */
|