From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 16-MAR-1992 19:31:59.13
To:	ARISIA::EVERHART
CC:	
Subj:	RE: Re: ZEN-1-0.dvi

From:	RELAY-INFO-VAX@CRVAX.SRI.COM@SMTP@CRDGW2
To:	Everhart@Arisia@MRGATE

Received:  by crdgw1.ge.com (5.57/GE 1.123)
	 id AA02096; Mon, 16 Mar 92 19:02:47 EST
Received: From SUN2.NSFNET-RELAY.AC.UK by CRVAX.SRI.COM with TCP; Mon, 16 MAR 92 15:13:43 PST
Received: from vax.rhbnc.ac.uk by sun2.nsfnet-relay.ac.uk via JANET with NIFTP 
          id <23093-0@sun2.nsfnet-relay.ac.uk>; Mon, 16 Mar 1992 17:28:04 +0000
Date: Mon, 16 MAR 92 17:29:19 BST
From: CHAA006@vax.rhbnc.ac.uk
To: INFO-VAX <@nsfnet-relay.ac.uk:INFO-VAX@CRVAX.SRI.com>
Subject: RE: Re: ZEN-1-0.dvi
Actually-To: <INFO-VAX%CRVAX.SRI.COM@UK.AC.NSFNET-RELAY>
Sender: JANET "CHAA006@UK.AC.RHBNC.VAX" <CHAA006@vax.rhbnc.ac.uk>
Message-Id: <22E0621D_00071E58.00957AD7846ED0E0$1_1@UK.AC.RHBNC.VAX>
Reply-To: Philip Taylor (RHBNC) <P.Taylor@vax.rhbnc.ac.uk>
Originally-To: $INFO-VAX,CBS%UK.AC.ULCC.NCDLAB::EDU.WASHINGTON.U::DEREK
Mailer: Janet_Mailshr V3.5 ( 13-OCT-1989 14:07:27 )

>The ZEN DVI file which Jay E. Morris had produced "bad end of dvi file" errors.
>(I have seen both this type of error and "error in postamble" errors.)  This
>indicates that something is "wrong" at the end of the file.  DVI files are
>supposed to terminate with a *minimum* of four x"DF" bytes.  There is no
>maximum.  DVI processors position to the end of the file, and "read" backwards
>looking for the beginning of the termination string.  If the last few bytes
>of the file are not x"DF" bytes, the "bad end of dvi file" is produced.  Once
>the beginning of the end is found, the DVI processor looks for the beginning
>of the "postamble".  Basically, a DVI file contains a table of contents at
>the end of the file.  The postamble information tells the DVI processor where
>to find specific information (using byte offsets) within the file.
> 
>Oh oh.  This is getting of the track.  ANYWAY, the point is that different
>TeX packages produce different DVI formats -- which are not necessarily
>interchangeable.  I have yet to see problems with DVI files interchanged
>between Un*x variants, but I have between different operating systems.  The
>formats I have seen are:
> 
>	VMS	- fixed-length, 512 byte records, last block padded
>	VM/CMS	- fixed-length, 1024 byte records, last block padded
>	NOS	- 7.5 bytes/word ASCII   (A non-standard NOS character set)
>	Un*x	- byte stream, 6 x"DF" bytes

The following program will unmangle most TeX-related files after they have been
transferred in such a way as to mess up their file structure or last page.  It
understands the padding conventions for DVI, TFM, etc. 

					Philip Taylor
			    ``The University of London at Windsor''

[Start of included file: VaryToFix.For]

	program varytofix
	implicit none
	integer i, j, k, length, limit
	character * 512 input
	character * 512 output
	logical end of file
	open (unit=1, status='old')
	open (unit=2, status='new', recordtype='fixed',
     &		recl=512, carriagecontrol='none')
	data end of file /.false./, j /0/
	do while (.not. end of file)
	   read (1, 1000, end=10) length, input
	   do i = 1, length
	      j = j + 1
	      output (j:j) = input (i:i)
	      if (j .eq. 512)
     &	      then
	      	   write (2, 2000) output
		   j = 0
	      else
	      end if
	   end do	      
	end do		
 0010   if (j .gt. 0)
     &	then
	     i = j
	     k = ichar (output (i:i))
	     if (k .eq. 245) 
     &	     then
		     k = 246
	     	     if (mod (i, 4) .eq. 0) limit = i + 1
	     	     if (mod (i, 4) .eq. 1) limit = i + 0
	     	     if (mod (i, 4) .eq. 2) limit = i + 3
	     	     if (mod (i, 4) .eq. 3) limit = i + 2
	     else
		     if (k .eq. 246)
     &	     	     then
	     	     	  if (mod (i, 4) .eq. 0) limit = i + 0
	     	     	  if (mod (i, 4) .eq. 1) limit = i - 1
	     	     	  if (mod (i, 4) .eq. 2) limit = i + 2
	     	     	  if (mod (i, 4) .eq. 3) limit = i + 1
		     else
	     	     	  limit = 0
		     end if
	     end if
	     do j = i+1, 512
	        if (limit .eq. 0)
     &		then
		     output (j:j) = char (k)
		else
		     if (j .le. limit)
     &		     then
		          output (j:j) = char (k)
 		     else
		     	  output (j:j) = char (0)
		     end if
		end if
	     end do
	     write (2, 2000) output
        else
	end if
	stop
 1000	format (q, a)
 2000	format (a)
	end


