diff options
author | Peter Breitenlohner <peb@mppmu.mpg.de> | 2013-11-20 10:57:01 +0000 |
---|---|---|
committer | Peter Breitenlohner <peb@mppmu.mpg.de> | 2013-11-20 10:57:01 +0000 |
commit | 695d20df01561e83122b87ddadad734195c6b9c8 (patch) | |
tree | cca1a283f6060b1d13725fd9015a84d6adbae835 /Build/source/texk/seetexk | |
parent | 0fa20c33bf4ee9968010daae8c8c7607c3e1b39f (diff) |
seetexk (dviselect): Delay output until a page is selected
git-svn-id: svn://tug.org/texlive/trunk@32191 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/seetexk')
-rw-r--r-- | Build/source/texk/seetexk/ChangeLog | 7 | ||||
-rw-r--r-- | Build/source/texk/seetexk/dviconcat.c | 1 | ||||
-rw-r--r-- | Build/source/texk/seetexk/dviselect.c | 67 | ||||
-rwxr-xr-x | Build/source/texk/seetexk/seetexk.test | 21 |
4 files changed, 74 insertions, 22 deletions
diff --git a/Build/source/texk/seetexk/ChangeLog b/Build/source/texk/seetexk/ChangeLog index cb25ae24c0d..6d1344631af 100644 --- a/Build/source/texk/seetexk/ChangeLog +++ b/Build/source/texk/seetexk/ChangeLog @@ -1,3 +1,10 @@ +2013-11-20 Peter Breitenlohner <peb@mppmu.mpg.de> + + * dviselect.c: Delay opening output until a page is selected. + * seetexk.test: More tests with stdin and stdout. + + * dviconcat.c: Drop '#include <kpathsea/c-auto.h>'. + 2013-11-18 Akira Kakuto <kakuto@fuk.kindai.ac.jp> * dvibook.c, dviconcat.c, dviselect.c, dvitodvi.c, tempfile.c: diff --git a/Build/source/texk/seetexk/dviconcat.c b/Build/source/texk/seetexk/dviconcat.c index 3f4dda2d354..d776e57a3b5 100644 --- a/Build/source/texk/seetexk/dviconcat.c +++ b/Build/source/texk/seetexk/dviconcat.c @@ -29,7 +29,6 @@ #endif #ifdef KPATHSEA -#include <kpathsea/c-auto.h> #include <kpathsea/config.h> #include <kpathsea/c-fopen.h> #include <kpathsea/getopt.h> diff --git a/Build/source/texk/seetexk/dviselect.c b/Build/source/texk/seetexk/dviselect.c index efa6cb96f5b..6e55ab7a330 100644 --- a/Build/source/texk/seetexk/dviselect.c +++ b/Build/source/texk/seetexk/dviselect.c @@ -133,9 +133,10 @@ i32 OutputFontIndex; /* current (new) index in ouput */ struct pagelist *PageList; /* the list of allowed pages */ -const char *DVIFileName; /* name of input DVI file */ -FILE *inf; /* the input file itself */ -FILE *outf; /* the output DVI file */ +const char *DVIFileName; /* name of input DVI file */ +FILE *inf; /* the input file itself */ +const char *outname; /* name of output DVI file */ +FILE *outf; /* the output DVI file */ long StartOfLastPage; /* The file position just before we started the last page (this is later written to @@ -163,6 +164,7 @@ static int evenodd(char *); static int ParsePages(char *); static void HandleDVIFile(void); static void PutFontSelector(i32); +static void WritePreAmble(void); #ifndef KPATHSEA char *malloc(), *realloc(); @@ -282,6 +284,9 @@ BeginPage(void) if ((UseThisPage = DesiredPageP()) == 0) return; + if (NumberOfOutputPages == 0) + WritePreAmble(); + putbyte(outf, DVI_BOP); for (i = Count; i < &Count[10]; i++) PutLong(outf, *i); @@ -349,6 +354,9 @@ HandlePostAmble(void) { register i32 c; + if (NumberOfOutputPages == 0) + return; + (void) GetLong(inf); /* previous page pointer */ if (GetLong(inf) != Numerator) GripeMismatchedValue("numerator"); @@ -441,12 +449,18 @@ WriteFont(struct fontinfo *fi) } /* - * Handle the preamble. Someday we should update the comment field. + * Array to hold the preamble comment. + */ +static char PreComment[256]; + +/* + * Read the preamble. Someday we should update the comment field. */ static void -HandlePreAmble(void) +ReadPreAmble(void) { register int n, c; + char *comment = PreComment; c = getc(inf); if (c == EOF) @@ -459,17 +473,43 @@ HandlePreAmble(void) Numerator = GetLong(inf); Denominator = GetLong(inf); DVIMag = GetLong(inf); + c = GetByte(inf); + n = UnSign8(c); + *comment++ = (char)c; + while (--n >= 0) { + c = GetByte(inf); + *comment++ = (char)c; + } +} + +/* + * Open the output and write the preamble. + */ +static void +WritePreAmble(void) +{ + register int n, c; + char *comment = PreComment; + + if (outname == NULL) { + outf = stdout; + if (!isatty(fileno(outf))) + SET_BINARY(fileno(outf)); + } else if ((outf = fopen(outname, FOPEN_WBIN_MODE)) == 0) + error(1, -1, "cannot write %s", outname); + putbyte(outf, DVI_PRE); putbyte(outf, DVI_VERSION); PutLong(outf, Numerator); PutLong(outf, Denominator); PutLong(outf, DVIMag); - n = UnSign8(GetByte(inf)); + c = *comment++; + n = UnSign8(c); CurrentPosition = 15 + n; /* well, almost */ putbyte(outf, n); while (--n >= 0) { - c = GetByte(inf); + c = *comment++; putbyte(outf, c); } } @@ -479,7 +519,6 @@ main(int argc, char **argv) { register int c; register char *s; - char *outname = NULL; ProgName = *argv; setbuf(stderr, serrbuf); @@ -538,18 +577,12 @@ Usage: %s [-s] [-i infile] [-o outfile] pages [...] [infile [outfile]]\n", SET_BINARY(fileno(inf)); } else if ((inf = fopen(DVIFileName, FOPEN_RBIN_MODE)) == 0) error(1, -1, "cannot read %s", DVIFileName); - if (outname == NULL) { - outf = stdout; - if (!isatty(fileno(outf))) - SET_BINARY(fileno(outf)); - } else if ((outf = fopen(outname, FOPEN_WBIN_MODE)) == 0) - error(1, -1, "cannot write %s", outname); if ((FontFinder = SCreate(sizeof(struct fontinfo))) == 0) error(1, 0, "cannot create font finder (out of memory?)"); StartOfLastPage = -1; - HandlePreAmble(); + ReadPreAmble(); HandleDVIFile(); HandlePostAmble(); if (NumberOfOutputPages > 0) { @@ -561,10 +594,6 @@ Usage: %s [-s] [-i infile] [-o outfile] pages [...] [infile [outfile]]\n", } else { if (!SFlag) (void) fprintf(stderr, "Specified page may be out of range\n"); - if (outname) { - fclose (outf); - unlink (outname); - } return 1; } } diff --git a/Build/source/texk/seetexk/seetexk.test b/Build/source/texk/seetexk/seetexk.test index 41abfb8c576..af3c7d011ae 100755 --- a/Build/source/texk/seetexk/seetexk.test +++ b/Build/source/texk/seetexk/seetexk.test @@ -26,6 +26,23 @@ rm -rf play* echo dviselect tests OK +rm -rf play* +cat $srcdir/tests/play.dvi | ./dviselect =25 >playsel.dvi \ + 2>playsel.2 \ + && exit 1 + touch playnot.dvi \ + && diff playsel.dvi playnot.dvi \ + && diff playsel.2 $srcdir/tests/playnot.2 \ + || exit 1 + +rm -rf play* +cat $srcdir/tests/play.dvi | ./dviselect =5:15 >playsel.dvi \ + 2>playsel.2 \ + && diff playsel.2 $srcdir/tests/playsel.2 \ + || exit 1 + +echo dviselect with stdin and stdout tests OK + ./dvibook -s4 playsel.dvi playbook.dvi \ 2>playbook.2 \ && diff playbook.2 $srcdir/tests/playbook.2 \ @@ -35,12 +52,12 @@ echo dvibook tests OK rm -f playbook.2 -cat playsel.dvi | ./dvibook -s4 -o playbook.dvi \ +cat playsel.dvi | ./dvibook -s4 >playbook.dvi \ 2>playbook.2 \ && diff playbook.2 $srcdir/tests/playbook.2 \ || exit 1 -echo dvibook reading stdin tests OK +echo dvibook with stdin and stdout tests OK ./dviselect =5:7 $srcdir/tests/play.dvi playsel1.dvi \ 2>playconc.2 \ |