[comp.lang.postscript] EPSF fix to some Transcript 2.1 utilities

stevec@fornax.UUCP (Steve Cumming) (03/24/89)

As part of my crusade for structured postscript code,
here is a patch kit for Transcript 2.1

These fixes make psrv.c and psrev work correctly when
confronted with PostScript documents that contain
even vaguely EPSF conforming included documents.

A more detailed description of the problem and solution
is in the shar README file.

I hope that Adobe will better my poor efforts in the next 
release.

Steve Cumming	stevec@lccr.cs.sfu.ca	{uunet|...}!ubc-cs!fornax!stevec
School of CS
SFU		(604) 291-4399	        beneath the moon / the wuggly-ump
Vancouver, CDN				is hurtling on / kerblash kerplunk

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then feed it
# into a shell via "sh file" or similar.  To overwrite existing files,
# type "sh file -c".
# The tool that generated this appeared in the comp.sources.unix newsgroup;
# send mail to comp-sources-unix@uunet.uu.net if you want that tool.
# If this archive is complete, you will see the following message at the end:
#		"End of shell archive."
# Contents:  README.psrv psrv.c.patch psrev.c.patch pscomm.c.patch
#   transcript.h.patch
# Wrapped by stevec@naos on Thu Mar 23 12:40:52 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'README.psrv' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README.psrv'\"
else
echo shar: Extracting \"'README.psrv'\" \(1813 characters\)
sed "s/^X//" >'README.psrv' <<'END_OF_FILE'
X
XThis archive contains patches for Transcript 2.1.
XThe result is that psrv.c and psrev.c work correctly
Xfor postscript documents that contain EPSF conforming
Xpictures, graphics, or other inclusions.
X
XIn fact, as long as the inclusion begins with a %!Adobe
Xand ends with a %%Trailer, things will still work.
X
XInclusions may be nested to arbitrary depth.	
X
XMANIFEST:
X		psrv.c.patch
X		psrev.c.patch
X		transcript.h.patch
X		pscomm.c.patch
X
XFYI:
X
XTranscript 2.1 uses a shell script input filter,
Xsay psif. psif sets up various environment variables,
Xand the execs pscomm, which actually forks the filters
Xand talks to the printer. 
X
XIf the ENVIRONMENT variable REVERSE is defined, pscomm
Xforks psrv, which attempts to reverse the order of the
Xpages. This is useful on some postscript printers, depending
Xon the nature of the mechanical paper feed.
X
XFinding included pictures in the document, with included
X%%Page: comments confused the poor dear.
X
XI fixed psrev into the bargain.
X
XFIXES:
X
Xpsrv.c contains some additional debugging code, #ifdef'd
XDEBUG. In support of this, all the getchar() macros were
Xchanged to getc()'s. These changes ain't ifdef'd cause I
Xgot lazy. Should be OK on any BSDish unix though.
X
XThe patch to pscomm.c just prevents pscomm from subverting
Xsome debugging code of mine. You can ignore this patch is
Xyou like. There are two other patches which fix bugs that
Xmay be Sun or BSD specific. All the pscomm patches are 
X#ifdef'd SFU
X
XHOW_TO:
X
Xunshar these files in you src directory, apply patch,
Xand then edit the makefile CFLAGS to add 
X	-DEPSF -DSFU -DDEBUG 
Xin whatever combination suits you.
X
X
X
XSteve Cumming	stevec@lccr.cs.sfu.ca	{uunet|...}!ubc-cs!fornax!stevec
XSchool of CS
XSFU		(604) 291-4399	        beneath the moon / the wuggly-ump
XVancouver, CDN				is hurtling on / kerblash kerplunk

END_OF_FILE
echo shar: NEWLINE appended to \"'README.psrv'\"
if test 1814 -ne `wc -c <'README.psrv'`; then
    echo shar: \"'README.psrv'\" unpacked with wrong size!
fi
# end of 'README.psrv'
fi
if test -f 'psrv.c.patch' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'psrv.c.patch'\"
else
echo shar: Extracting \"'psrv.c.patch'\" \(3920 characters\)
sed "s/^X//" >'psrv.c.patch' <<'END_OF_FILE'
X*** psrv.c.dist	Thu Mar 23 09:04:28 1989
X--- psrv.c	Thu Mar 23 09:01:34 1989
X***************
X*** 84,89 ****
X--- 84,92 ----
X      struct stat statb;
X      long ptable[2000];
X      int page = 0;
X+ #ifdef EPSF
X+     int nest = 0;
X+ #endif EPSF
X      long endpro = -1;
X      long trailer = -1;
X      long lastchar;
X***************
X*** 95,106 ****
X      FILE *stmin;
X      char *tempdir;
X  
X      fdin = fileno(stdin);
X-     fdout = fileno(stdout);
X      stmin = stdin;
X  
X-     prog = *argv;
X  
X      if (fstat(fdin, &statb) == -1) pexit2(prog,"fstat", THROW_AWAY);
X      isregular = ((statb.st_mode & S_IFMT) == S_IFREG);
X  
X--- 98,124 ----
X      FILE *stmin;
X      char *tempdir;
X  
X+     prog = *argv;
X+ 
X+ #ifdef DEBUG
X+     /* see the angry SFU ifdef ins pscomm.c */
X+     if (argc > 1){
X+       stmin = fopen(argv[1],"r");
X+       fdin  = fileno(stmin);
X+     }
X+     else{
X+       fdin = fileno(stdin);
X+       stmin = stdin;
X+     }
X+ #else DEBUG
X      fdin = fileno(stdin);
X      stmin = stdin;
X+ #endif DEBUG
X+     fdout = fileno(stdout);
X  
X  
X+ 
X+ 
X      if (fstat(fdin, &statb) == -1) pexit2(prog,"fstat", THROW_AWAY);
X      isregular = ((statb.st_mode & S_IFMT) == S_IFREG);
X  
X***************
X*** 130,136 ****
X  	cnt = BUFSIZ - 1;
X  	bp = buf;
X  	if ((linestart = ftell(stmin)) == -1) pexit2(prog,"ftell",2);
X! 	while ((--cnt > 0) && ((*bp++ = (c = getchar())) != '\n')) {
X  	    if (c == EOF) {
X  		*--bp = '\0';
X  		break;
X--- 148,154 ----
X  	cnt = BUFSIZ - 1;
X  	bp = buf;
X  	if ((linestart = ftell(stmin)) == -1) pexit2(prog,"ftell",2);
X! 	while ((--cnt > 0) && ((*bp++ = (c = getc(stmin))) != '\n')) {
X  	    if (c == EOF) {
X  		*--bp = '\0';
X  		break;
X***************
X*** 138,149 ****
X  	}
X  	if (c != EOF) {
X  	    while (c != '\n') {
X! 		if ((c = getchar()) == EOF) break;
X  	    }
X  	}
X  	*bp = '\0';
X  	if ((c == EOF) && (bp == buf)) break;
X  	else if (*buf != '%') continue;
X  	else if (strncmp(buf,"%%Page:",7) == 0) {
X  	    ptable[page++] = linestart;
X  	    if (endpro == -1) endpro = linestart;
X--- 156,168 ----
X  	}
X  	if (c != EOF) {
X  	    while (c != '\n') {
X! 		if ((c = getc(stmin)) == EOF) break;
X  	    }
X  	}
X  	*bp = '\0';
X  	if ((c == EOF) && (bp == buf)) break;
X  	else if (*buf != '%') continue;
X+ #ifndef EPSF
X  	else if (strncmp(buf,"%%Page:",7) == 0) {
X  	    ptable[page++] = linestart;
X  	    if (endpro == -1) endpro = linestart;
X***************
X*** 152,157 ****
X--- 171,197 ----
X  	    trailer = linestart;
X  	    ptable[page] = linestart;
X  	}
X+ #else EPSF
X+ 	if (strncmp(buf,"%!",2) == 0){
X+ 	  nest++;
X+ 	  continue;
X+ 	}
X+ 	if (nest > 1){
X+ 	  /* the only thing of interest is a %%Trailer */
X+ 	  if (strncmp(buf,"%%Trailer",9) == 0) 
X+ 	    nest--;
X+ 	  continue;
X+ 	}
X+ 	if (strncmp(buf,"%%Page:",7) == 0) {
X+ 	    ptable[page++] = linestart;
X+ 	    if (endpro == -1) endpro = linestart;
X+ 	}
X+ 	else if (strncmp(buf,"%%Trailer",9) == 0) {
X+ 	    trailer = linestart;
X+ 	    ptable[page] = linestart;
X+ 	    nest--;
X+ 	} 
X+ #endif EPSF  
X      }
X      lastchar = ftell(stmin);
X      if (trailer == -1) ptable[page] = lastchar;
X***************
X*** 159,168 ****
X      VOIDC fseek(stmin,0L,0); VOIDC lseek(fdin, 0L, 0);
X  
X  #ifdef BSD
X      VOIDC kill(getppid(),SIGEMT);
X  #endif
X  
X!     if ((endpro == -1) || (page == 0)) {
X  	fprintf(stderr,"%s: file not reversible\n",prog);
X  	writesection(0L,lastchar);
X      }
X--- 199,216 ----
X      VOIDC fseek(stmin,0L,0); VOIDC lseek(fdin, 0L, 0);
X  
X  #ifdef BSD
X+ /* IMHO this is a bad plan.
X+    The parent could either wait() on its
X+    children quasi asynchronously by setting alarms,
X+    or else open a spare pipe, and listen for
X+    a byte with select.
X+ 
X+    or at least, is a signal that is SIGIGN by default.
X+ */
X      VOIDC kill(getppid(),SIGEMT);
X  #endif
X  
X!     if ((endpro == -1) || (page == 0) || (nest != 0)) {
X  	fprintf(stderr,"%s: file not reversible\n",prog);
X  	writesection(0L,lastchar);
X      }

END_OF_FILE
echo shar: NEWLINE appended to \"'psrv.c.patch'\"
if test 3921 -ne `wc -c <'psrv.c.patch'`; then
    echo shar: \"'psrv.c.patch'\" unpacked with wrong size!
fi
# end of 'psrv.c.patch'
fi
if test -f 'psrev.c.patch' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'psrev.c.patch'\"
else
echo shar: Extracting \"'psrev.c.patch'\" \(1866 characters\)
sed "s/^X//" >'psrev.c.patch' <<'END_OF_FILE'
X*** psrev.c.dist	Thu Mar 23 12:10:33 1989
X--- psrev.c	Thu Mar 23 09:09:46 1989
X***************
X*** 242,252 ****
X  #define ichMaxScT 40
X  char scT[ichMaxScT+1];
X  char *scT1;
X  
X  while (1)
X      { if (FEofReadSc(scT, ichMaxScT, ppsd))
X          { rgposPage[*pipgMac] = ppsd->posLineFst; break;}
X!     if (strncmp(scT, SCPAGE, ichMaxPage) == 0)
X          { rgposPage[*pipgMac] = ppsd->posLineFst;
X          scT1 = &scT[ichColon+1];
X          /* skip blanks */
X--- 242,265 ----
X  #define ichMaxScT 40
X  char scT[ichMaxScT+1];
X  char *scT1;
X+ #ifdef EPSF
X+ int  nest = 0;
X+ int  epsf_len = strlen(EPSFVERID);
X+ int  fake_len = strlen(SCVERID);      /* this connotes disapproval  */
X+                                       /* also a desire for backwards compatabilty */
X+ #endif EPSF
X  
X  while (1)
X      { if (FEofReadSc(scT, ichMaxScT, ppsd))
X          { rgposPage[*pipgMac] = ppsd->posLineFst; break;}
X! #ifdef EPSF
X!     if (scT[0] != '%' || scT[1] != '%' && scT[1] != '!')
X!       continue;
X!     else if ((strncmp(scT, EPSFVERID,epsf_len) == 0) || strncmp(scT,SCVERID,fake_len) == 0)
X!       nest++;
X!     else 
X! #endif EPSF
X!       if (strncmp(scT, SCPAGE, ichMaxPage) == 0 && nest == 0)
X          { rgposPage[*pipgMac] = ppsd->posLineFst;
X          scT1 = &scT[ichColon+1];
X          /* skip blanks */
X***************
X*** 260,269 ****
X--- 273,293 ----
X              (*pipgMac)++;
X          else break;
X          }
X+ #ifdef EPSF
X+     else if (strncmp(scT, SCTRAILER, ichMaxTrailer) == 0){
X+       if (nest == 0)
X+         { rgposPage[*pipgMac] = ppsd->posLineFst;
X+         break;
X+ 	}
X+       else
X+ 	nest--;
X+     }
X+ #else EPSF
X      else if (strncmp(scT, SCTRAILER, ichMaxTrailer) == 0)
X          { rgposPage[*pipgMac] = ppsd->posLineFst;
X          break;
X  	}
X+ #endif EPSF
X      }
X  while (! FEofReadSc(scT, 1, ppsd)) ;
X  ppsd->posMac = ppsd->posLineFst;

END_OF_FILE
echo shar: NEWLINE appended to \"'psrev.c.patch'\"
if test 1867 -ne `wc -c <'psrev.c.patch'`; then
    echo shar: \"'psrev.c.patch'\" unpacked with wrong size!
fi
# end of 'psrev.c.patch'
fi
if test -f 'pscomm.c.patch' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'pscomm.c.patch'\"
else
echo shar: Extracting \"'pscomm.c.patch'\" \(1171 characters\)
sed "s/^X//" >'pscomm.c.patch' <<'END_OF_FILE'
X*** pscomm.c.orig	Wed Mar 22 22:09:40 1989
X--- pscomm.c	Thu Mar 23 12:31:33 1989
X***************
X*** 177,182 ****
X--- 177,185 ----
X  #include <stdio.h>
X  #include <strings.h>
X  #include <errno.h>
X+ #ifdef SFU
X+ #include <fcntl.h>		/* missing this include file!?, LKT */
X+ #endif SFU
X  
X  #include <sys/file.h>
X  #include <sys/ioctl.h>
X***************
X*** 400,406 ****
X  		    break;
X  
X  		case 'r':	/* never reverse */
X! 		    argc--;
X  		    noReverse = 1;
X  		    break;
X  
X--- 403,411 ----
X  		    break;
X  
X  		case 'r':	/* never reverse */
X! #ifdef SFU
X! /*		    argc--;			-r takes no argument */
X! #endif SFU
X  		    noReverse = 1;
X  		    break;
X  
X***************
X*** 560,566 ****
X--- 565,580 ----
X  	    || close(fdpipe[1]) || close(fdpipe[0])) {
X  		myexit2(prog, "reverse child", THROW_AWAY);
X  	    }
X+ #ifdef SFU
X  	    execl(reverse, "psrv", pname, 0);
X+ #else
X+ 	    /* DONT call me with a bogus second arg
X+ 	       which I don't use, and which screws up
X+ 	       my tasteful debugging mode. "psrv" is 
X+ 	       also real questionabobble.
X+ 	    */
X+ 	    execl(reverse, "psrv", 0);
X+ #endif SFU
X  	    myexit2(prog,"reverse exec",THROW_AWAY);
X  	}
X  

END_OF_FILE
echo shar: NEWLINE appended to \"'pscomm.c.patch'\"
if test 1172 -ne `wc -c <'pscomm.c.patch'`; then
    echo shar: \"'pscomm.c.patch'\" unpacked with wrong size!
fi
# end of 'pscomm.c.patch'
fi
if test -f 'transcript.h.patch' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'transcript.h.patch'\"
else
echo shar: Extracting \"'transcript.h.patch'\" \(452 characters\)
sed "s/^X//" >'transcript.h.patch' <<'END_OF_FILE'
X*** transcript.h.orig	Wed Mar 22 18:40:26 1989
X--- transcript.h	Thu Mar 23 12:39:05 1989
X***************
X*** 41,46 ****
X--- 41,52 ----
X  #define PSVERSION 	23.0
X  #define COMMENTVERSION	"PS-Adobe-1.0"
X  
X+ #ifdef  EPSF
X+ #define EPSFVERSION     "PS-Adobe-2.0 EPSF-1.2"
X+ #define EPSFVERID       "%!PS-Adobe-2.0 EPSF-1.2"
X+ #define DITROFF_X_OFFSET 300 /* ditroffs conccrte left margin */
X+ #endif  EPSF
X+ 
X  #define VOID void
X  #define VOIDC (void)
X  

END_OF_FILE
echo shar: NEWLINE appended to \"'transcript.h.patch'\"
if test 453 -ne `wc -c <'transcript.h.patch'`; then
    echo shar: \"'transcript.h.patch'\" unpacked with wrong size!
fi
# end of 'transcript.h.patch'
fi
echo shar: End of shell archive.
exit 0
-- 
Steve Cumming	stevec@lccr.cs.sfu.ca	{uunet|...}!ubc-cs!fornax!stevec
School of CS
SFU		(604) 291-4399	        beneath the moon / the wuggly-ump
Vancouver, CDN				is hurtling on / kerblash kerplunk