From ad547a6b5986815fda458221149728d9d9ab1d87 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Thu, 25 Feb 2021 19:22:25 +0000 Subject: restore Build,TODO from r57911 git-svn-id: svn://tug.org/texlive/trunk@57915 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/texk/psutils/psutils-src/psbook.c | 111 +++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 Build/source/texk/psutils/psutils-src/psbook.c (limited to 'Build/source/texk/psutils/psutils-src/psbook.c') diff --git a/Build/source/texk/psutils/psutils-src/psbook.c b/Build/source/texk/psutils/psutils-src/psbook.c new file mode 100644 index 00000000000..8bb0b6b6ace --- /dev/null +++ b/Build/source/texk/psutils/psutils-src/psbook.c @@ -0,0 +1,111 @@ +/* psbook.c + * (c) Reuben Thomas 2012-2014 + * (c) Angus J. C. Duggan 1991-1997 + * See file LICENSE for details. + * + * rearrange pages in conforming PS file for printing in signatures + */ + +#include "config.h" + +#include +#include "progname.h" +#include "binary-io.h" + +#include "psutil.h" + +const char *syntax = "[-q] [-sSIGNATURE] [INFILE [OUTFILE]]\n SIGNATURE must be positive and divisible by 4\n"; + +const char *argerr_message = ""; + +int +main(int argc, char *argv[]) +{ + int signature = 0; + int currentpg, maxpage; + int opt; + + set_program_name (argv[0]); + + verbose = 1; + + while((opt = getopt(argc, argv, "vqs:")) != EOF) { + switch(opt) { + case 's': /* signature size */ + signature = atoi(optarg); + if (signature < 1 || signature % 4) usage(); + break; + case 'q': /* quiet */ + verbose = 0; + break; + case 'v': /* version */ + default: + usage(); + break; + } + } + + infile = stdin; + outfile = stdout; + + /* Be defensive */ + if((argc - optind) < 0 || (argc - optind) > 2) usage(); + + if (optind != argc) { + /* User specified an input file */ + if ((infile = fopen(argv[optind], "rb")) == NULL) + die("can't open input file %s", argv[optind]); + optind++; + } + + if (optind != argc) { + /* User specified an output file */ + if ((outfile = fopen(argv[optind], "wb")) == NULL) + die("can't open output file %s", argv[optind]); + optind++; + } + + if(optind != argc) usage(); + + if (infile == stdin && set_binary_mode(fileno(stdin), O_BINARY) < 0) + die("can't reset stdin to binary mode"); + if (outfile == stdout && set_binary_mode(fileno(stdout), O_BINARY) < 0) + die("can't reset stdout to binary mode"); + + if ((infile=seekable(infile))==NULL) + die("can't seek input"); + + scanpages(NULL); + + if (!signature) + signature = maxpage = pages+(4-pages%4)%4; + else + maxpage = pages+(signature-pages%signature)%signature; + + /* rearrange pages */ + writeheader(maxpage, NULL); + writeprolog(); + writesetup(); + 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; + default: /* Avoid a compiler warning */ + break; + } + if (actualpg < pages) + writepage(actualpg); + else + writeemptypage(); + } + writetrailer(); + + return 0; +} -- cgit v1.2.3