home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / tex / dvivga9.arc / SIGNEX.H < prev    next >
Text File  |  1988-05-30  |  2KB  |  58 lines

  1. /* -*-C-*- signex.h */
  2. /*-->signex*/
  3. /**********************************************************************/
  4. /******************************* signex *******************************/
  5. /**********************************************************************/
  6.  
  7. INT32
  8. signex(fp, n)     /* return n byte quantity from file fd */
  9. register FILE *fp;    /* file pointer     */
  10. register BYTE n;      /* number of bytes */
  11.  
  12. {
  13.     register BYTE n1; /* number of bytes      */
  14.     register INT32 number; /* number being constructed */
  15.  
  16.     number = (INT32)getc(fp);/* get first (high-order) byte */
  17.  
  18. #if    PCC_20
  19.     if (number > 127) /* sign bit is set, pad top of word with sign bit */
  20.     number |= 0xfffffff00;
  21.               /* this constant could be written for any */
  22.               /* 2's-complement machine as -1 & ~0xff, but */
  23.               /* PCC-20 does not collapse constant expressions */
  24.               /* at compile time, sigh... */
  25. #endif /* PCC_20 */
  26.  
  27. #if    (OS_ATARI | OS_UNIX)    /* 4.1BSD C compiler uses logical shift too */
  28.     if (number > 127) /* sign bit is set, pad top of word with sign bit */
  29.     number |= 0xffffff00;
  30. #endif /* OS_UNIX */
  31.  
  32.     n1 = n--;
  33.     while (n--)
  34.     {
  35.     number <<= 8;
  36.     number |= (INT32)getc(fp);
  37.     }
  38.  
  39. #if    (OS_ATARI | PCC_20 | OS_UNIX)
  40. #else /* NOT (OS_ATARI | PCC_20 | OS_UNIX) */
  41.  
  42.     /* NOTE: This code assumes that the right-shift is an arithmetic, rather
  43.     than logical, shift which will propagate the sign bit right.   According
  44.     to Kernighan and Ritchie, this is compiler dependent! */
  45.  
  46.     number<<=HOST_WORD_SIZE-8*n1;
  47.  
  48. #if    ARITHRSHIFT
  49.     number>>=HOST_WORD_SIZE-8*n1;  /* sign extend */
  50. #else /* NOT ARITHRSHIFT */
  51.     (void)fatal("signex():  no code implemented for logical right shift");
  52. #endif /* ARITHRSHIFT */
  53.  
  54. #endif /* (OS_ATARI | PCC_20 | OS_UNIX) */
  55.  
  56.     return((INT32)number);
  57. }
  58.