home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / VPR_DATA / DOGA / SOURCES / REND.LZH / REND / PICREAD.H < prev    next >
Text File  |  1993-10-02  |  1KB  |  82 lines

  1. #define BUFFERSIZE 4096
  2.  
  3. #ifndef DJBUG
  4. static char readbuffer[BUFFERSIZE];
  5. static int readp;
  6. #endif
  7.  
  8. static void    readinit()
  9. {
  10. #ifndef DJBUG
  11.     readp = BUFFERSIZE;
  12. #endif
  13. }
  14.  
  15. static inline void readcheck(FILE *fp)
  16. {
  17. #ifndef DJBUG
  18.     if (readp >= BUFFERSIZE) {
  19.         fread(readbuffer, 1, BUFFERSIZE, fp);
  20.         readp = 0;
  21.     }
  22. #endif
  23. }
  24.  
  25. static inline int        getshort( fp )
  26. FILE    *fp ;
  27. {
  28.     int        n ;
  29. #ifndef DJBUG
  30.     readcheck(fp);
  31. #ifdef X68000
  32.     n = *(unsigned short*)(readbuffer+readp);
  33.     readp += 2;
  34. #else
  35.     n = readbuffer[readp++] << 8 ;
  36.     n += readbuffer[readp++];
  37. #endif
  38. #else
  39.     n = fgetc(fp) << 8 ;
  40.     n += fgetc(fp);
  41. #endif
  42.     return( n );
  43. }
  44.  
  45. static inline long    getlong(FILE *fp)
  46. {
  47.     long n;
  48. #ifndef DJBUG
  49.     readcheck(fp);
  50.     if (readp > readbuffer-4) {
  51. #ifdef X68000
  52.         n = (unsigned long)(*(unsigned short*)(readbuffer+readp)) << 16;
  53.         readp += 2;
  54.         readcheck(fp);
  55. #else
  56.         n = readbuffer[readp++]  << 24 ;
  57.         n += readbuffer[readp++] << 16;
  58.         readcheck(fp);
  59.         n += readbuffer[readp++] <<  8;
  60.         n += readbuffer[readp++];
  61. #endif
  62.     } else {
  63. #ifdef X68000
  64.         n = *(unsigned long*)(readbuffer+readp);
  65.         readp += 4;
  66. #else
  67.         n = readbuffer[readp++]  << 24 ;
  68.         n += readbuffer[readp++] << 16;
  69.         n += readbuffer[readp++] <<  8;
  70.         n += readbuffer[readp++];
  71. #endif
  72.     }
  73. #else
  74.     n = fgetc(fp)  << 24 ;
  75.     n += fgetc(fp) << 16;
  76.     n += fgetc(fp) <<  8;
  77.     n += fgetc(fp);
  78. #endif
  79.     return n;
  80. }
  81.  
  82.