home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3.4.17 [SPARC, PA-RISC] / nextstep33_risc.iso / NextLibrary / TeX / tex / src / texview / dviinput.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-27  |  1.8 KB  |  106 lines

  1. /*
  2.  *   dviinput.c of dvisw software package.  This code is copyright (C) 1986
  3.  *   by Radical Eye Software.
  4.  *
  5.  *   Input files for the dvi file.  These routines could probably be
  6.  *   sped up significantly; they are very machine dependent, though, so
  7.  *   I will leave such tuning to the installer.   They simply get and
  8.  *   return bytes of the dvifile in batches of one, two, three, and four,
  9.  *   updateing the current position as necessary.
  10.  */
  11. #include "structures.h"
  12. void error() ;
  13. extern integer curpos ;
  14. extern FILE *dvifile ;
  15. extern quarterword *virpos, *virlim ;
  16.  
  17. void
  18. abortpage()
  19. {
  20.    printf("Tried to get byte %ld\n", curpos-1) ;
  21.    error("! unexpected eof on DVI file") ;
  22. }
  23.  
  24. shalfword
  25. dvibyte()
  26. {
  27.   register shalfword i ;
  28.  
  29.   if (virpos) {
  30.      if (virpos >= virlim)
  31.         return 140 ;
  32.      else
  33.         return *virpos++ ;
  34.   } else {
  35.      curpos++ ;
  36.      i = getc(dvifile) ;
  37.      if (i==EOF)
  38.        abortpage() ;
  39.      return(i) ;
  40.   }
  41. }
  42.  
  43. halfword
  44. twobytes()
  45. {
  46.   register halfword i ;
  47.   i = dvibyte() ;
  48.   return(i*256+dvibyte()) ; }
  49.  
  50. integer
  51. threebytes()
  52. {
  53.   register integer i ;
  54.   i = twobytes() ;
  55.   return(i*256+dvibyte()) ; }
  56.  
  57. shalfword
  58. signedbyte()
  59. {
  60.   register shalfword i ;
  61.   if (virpos) {
  62.      if (virpos >= virlim) {
  63.         i = 0 ;
  64.         error("! unexpected end of virtual packet") ;
  65.      } else
  66.         i = *virpos++ ;
  67.   } else {
  68.      curpos++ ;
  69.      if ((i=getc(dvifile))==EOF)
  70.        abortpage() ;
  71.   }
  72.   if (i<128) return(i) ;
  73.   else return(i-256) ;
  74. }
  75.  
  76. shalfword
  77. signedpair()
  78. {
  79.   register shalfword i ;
  80.   i = signedbyte() ;
  81.   return(i*256+dvibyte()) ;
  82. }
  83.  
  84. integer
  85. signedtrio()
  86. {
  87.   register integer i ;
  88.   i = signedpair() ;
  89.   return(i*256+dvibyte()) ;
  90. }
  91.  
  92. integer
  93. signedquad()
  94. {
  95.   register integer i ;
  96.   i = signedpair() ;
  97.   return(i*65536+twobytes()) ;
  98. }
  99.  
  100. void
  101. skipover(i)
  102.     int i ;
  103. {
  104.   while (i-->0) (void)dvibyte() ;
  105. }
  106.