home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume35
/
psutils
/
part04
/
psbook.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-02-04
|
2KB
|
97 lines
/* psbook.c
* AJCD 27/1/91
* rearrange pages in conforming PS file for printing in signatures
*
* Usage:
* psbook [-q] [-s<signature>] [infile [outfile]]
*/
#include "psutil.h"
#include "patchlevel.h"
void usage()
{
fprintf(stderr, "%s release %d patchlevel %d\n", prog, RELEASE, PATCHLEVEL);
fprintf(stderr, "Usage: %s [-q] [-s<signature>] [infile [outfile]]\n",
prog);
fprintf(stderr, " <signature> must be positive and divisible by 4\n");
fflush(stderr);
exit(1);
}
main(argc, argv)
int argc;
char *argv[];
{
int signature = 0;
int currentpg, maxpage;
infile = stdin;
outfile = stdout;
verbose = 1;
for (prog = *argv++; --argc; argv++) {
if (argv[0][0] == '-') {
switch (argv[0][1]) {
case 's':
signature = atoi(*argv+2);
if (signature < 1 || signature % 4) usage();
break;
case 'q':
verbose = 0;
break;
case 'v':
default:
usage();
}
} else if (infile == stdin) {
if ((infile = fopen(*argv, "r")) == NULL) {
fprintf(stderr, "%s: can't open input file %s\n", prog, *argv);
fflush(stderr);
exit(1);
}
} else if (outfile == stdout) {
if ((outfile = fopen(*argv, "w")) == NULL) {
fprintf(stderr, "%s: can't open output file %s\n", prog, *argv);
fflush(stderr);
exit(1);
}
} else usage();
}
if ((infile=seekable(infile))==NULL) {
fprintf(stderr, "%s: can't seek input\n", prog);
fflush(stderr);
exit(1);
}
scanpages();
maxpage = pages+(4-pages%4)%4;
if (!signature)
signature = maxpage;
/* rearrange pages */
writeheader(maxpage);
writeprolog();
for (currentpg = 0; currentpg < maxpage; currentpg++) {
int actualpg = currentpg - currentpg%signature;
switch(currentpg%4) {
case 0:
case 3:
actualpg += signature-1-(currentpg%signature)/2;
break;
case 1:
case 2:
actualpg += (currentpg%signature)/2;
break;
}
if (actualpg < pages)
writepage(actualpg);
else
writeemptypage();
}
writetrailer();
exit(0);
}