home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / DVI_MGR / dvimgr_s.lzh / dvimgr / findpost.h < prev    next >
Text File  |  1993-08-06  |  2KB  |  57 lines

  1. /* -*-C-*- findpost.h */
  2. /* correction according to N.Beebe 2-mar-88 */
  3. /*-->findpost*/
  4. /**********************************************************************/
  5. /****************************** findpost ******************************/
  6. /**********************************************************************/
  7.  
  8. void
  9. findpost()
  10.  
  11. {
  12.     register long       postambleptr;
  13.     register BYTE       i;
  14.     register UNSIGN16 the_char;         /* loop index */
  15.  
  16.     (void) FSEEK (dvifp, 0L, 2);        /* goto end of file */
  17.  
  18.     /* VAX VMS binary files are stored with NUL padding to the next
  19.     512 byte multiple.  We therefore search backwards to the last
  20.     non-NULL byte to find the real end-of-file, then move back from
  21.     that.  Even if we are not on a VAX VMS system, the DVI file might
  22.     have passed through one on its way to the current host, so we
  23.     ignore trailing NULs on all machines. */
  24.  
  25.     while (FSEEK(dvifp,-1L,1) == 0)
  26.     {
  27.         the_char = (UNSIGN16)fgetc(dvifp);
  28.         if (the_char)
  29.           break;                /* exit leaving pointer PAST last non-NUL */
  30.         UNGETC((char)the_char,dvifp);
  31.     }
  32.  
  33.     postambleptr = FTELL(dvifp) - 4;
  34.  
  35. #if    OS_VAXVMS
  36.     /* There is a problem with FSEEK() that I cannot fix just now.  A
  37.     request to position to end-of-file cannot be made to work correctly,
  38.     so FSEEK() positions in front of the last byte, instead of past it.
  39.     We therefore modify postambleptr accordingly to account for this. */
  40.  
  41.     postambleptr++;
  42. #endif
  43.  
  44.     (void) FSEEK (dvifp, postambleptr, 0);
  45.     while (TRUE)
  46.     {
  47.         (void) FSEEK (dvifp, --(postambleptr), 0);
  48.         if (((i = (BYTE)nosignex(dvifp,(BYTE)1)) != 223) &&
  49.             (i != DVIFORMAT))
  50.             (void)fatal("findpost():  Bad end of DVI file");
  51.         if (i == DVIFORMAT)
  52.             break;
  53.     }
  54.     (void) FSEEK (dvifp, postambleptr - 4, 0);
  55.     (void) FSEEK (dvifp, (long)nosignex(dvifp,(BYTE)4), 0);
  56. }
  57.