home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / PRINTING / DVIPS54.ZIP / DVIPS / DVIINPUT.C < prev    next >
C/C++ Source or Header  |  1990-11-25  |  2KB  |  90 lines

  1. /*
  2.  *   Input bytes from the dvi file or the current virtual character.
  3.  *   These routines could probably be sped up significantly; but they are
  4.  *   very machine dependent, so I will leave such tuning to the installer.
  5.  *   They simply get and return bytes in batches of one, two, three, and four,
  6.  *   updating the current position as necessary.
  7.  */
  8. #include "structures.h" /* The copyright notice in that file is included too! */
  9. void error() ;
  10. extern FILE *dvifile ;
  11. extern quarterword *curpos, *curlim ;
  12.  
  13. void
  14. abortpage()
  15. {
  16.    error("! unexpected eof on DVI file") ;
  17. }
  18.  
  19. shalfword  /* the value returned is, however, between 0 and 255 */
  20. dvibyte()
  21. {
  22.   register shalfword i ;
  23.   if (curpos) {
  24.      if (curpos>=curlim) return((shalfword)140) ;
  25.      return (*curpos++) ;
  26.   }
  27.   if ((i=getc(dvifile))==EOF)
  28.     abortpage() ;
  29.   return(i) ;
  30. }
  31.  
  32. halfword
  33. twobytes()
  34. {
  35.   register halfword i ;
  36.   i = dvibyte() ;
  37.   return(i*256+dvibyte()) ; }
  38.  
  39. integer
  40. threebytes()
  41. {
  42.   register integer i ;
  43.   i = twobytes() ;
  44.   return(i*256+dvibyte()) ; }
  45.  
  46. shalfword
  47. signedbyte()
  48. {
  49.   register shalfword i ;
  50.   if (curpos) {
  51.      if (curpos>=curlim)
  52.        error("! unexpected end of virtual packet") ;
  53.      i = *curpos++ ;
  54.   } else if ((i=getc(dvifile))==EOF)
  55.     abortpage() ;
  56.   if (i<128) return(i) ;
  57.   else return(i-256) ;
  58. }
  59.  
  60. shalfword
  61. signedpair()
  62. {
  63.   register shalfword i ;
  64.   i = signedbyte() ;
  65.   return(i*256+dvibyte()) ;
  66. }
  67.  
  68. integer
  69. signedtrio()
  70. {
  71.   register integer i ;
  72.   i = signedpair() ;
  73.   return(i*256+dvibyte()) ;
  74. }
  75.  
  76. integer
  77. signedquad()
  78. {
  79.   register integer i ;
  80.   i = signedpair() ;
  81.   return(i*65536+twobytes()) ;
  82. }
  83.  
  84. void
  85. skipover(i)
  86.         int i ;
  87. {
  88.   while (i-->0) (void)dvibyte() ;
  89. }
  90.