home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 3 / Meeting_Pearls_III.iso / Pearls / texmf / source / dvips / dviinput.c < prev    next >
C/C++ Source or Header  |  1994-01-08  |  2KB  |  109 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 "dvips.h" /* The copyright notice in that file is included too! */
  9. #ifdef AMIGA
  10. #include "dviinput_protos.h"
  11. #include "dvips_protos.h"
  12. #else
  13. void error() ;
  14. #endif
  15. extern FILE *dvifile ;
  16. extern quarterword *curpos, *curlim ;
  17.  
  18. void
  19. abortpage()
  20. {
  21.    error("! unexpected eof on DVI file") ;
  22. }
  23.  
  24. shalfword  /* the value returned is, however, between 0 and 255 */
  25. dvibyte()
  26. {
  27.   register shalfword i ;
  28.   if (curpos) {
  29.      if (curpos>=curlim) return((shalfword)140) ;
  30.      return (*curpos++) ;
  31.   }
  32.   if ((i=getc(dvifile))==EOF)
  33.     abortpage() ;
  34.   return(i) ;
  35. }
  36.  
  37. halfword
  38. twobytes()
  39. {
  40.   register halfword i ;
  41.   i = dvibyte() ;
  42. #ifdef AMIGA
  43.   return (halfword) (i*256+dvibyte());
  44. #else
  45.   return(i*256+dvibyte()) ;
  46. #endif
  47. }
  48.  
  49. integer
  50. threebytes()
  51. {
  52.   register integer i ;
  53.   i = twobytes() ;
  54.   return(i*256+dvibyte()) ; }
  55.  
  56. shalfword
  57. signedbyte()
  58. {
  59.   register shalfword i ;
  60.   if (curpos) {
  61.      if (curpos>=curlim)
  62.        error("! unexpected end of virtual packet") ;
  63.      i = *curpos++ ;
  64.   } else if ((i=getc(dvifile))==EOF)
  65.     abortpage() ;
  66.   if (i<128) return(i) ;
  67.   else
  68. #ifdef AMIGA
  69.      return (shalfword)(i-256);
  70. #else
  71.  return(i-256) ;
  72. #endif
  73. }
  74.  
  75. shalfword
  76. signedpair()
  77. {
  78.   register shalfword i ;
  79.   i = signedbyte() ;
  80. #ifdef AMIGA
  81.   return (shalfword) (i*256+dvibyte());
  82. #else
  83.   return(i*256+dvibyte()) ;
  84. #endif
  85. }
  86.  
  87. integer
  88. signedtrio()
  89. {
  90.   register integer i ;
  91.   i = signedpair() ;
  92.   return(i*256+dvibyte()) ;
  93. }
  94.  
  95. integer
  96. signedquad()
  97. {
  98.   register integer i ;
  99.   i = signedpair() ;
  100.   return(i*65536+twobytes()) ;
  101. }
  102.  
  103. void
  104. skipover(i)
  105.         int i ;
  106. {
  107.   while (i-->0) (void)dvibyte() ;
  108. }
  109.