home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 409_01 / debug.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-20  |  6.0 KB  |  175 lines

  1. /****************************************************************************
  2. *
  3. *                   Copyright (C) 1993 SciTech Software
  4. *                           All rights reserved.
  5. *
  6. * Filename:     $RCSfile: debug.h $
  7. * Version:      $Revision: 1.6 $
  8. *
  9. * Language:     ANSI C
  10. * Environment:  any
  11. *
  12. * Description:  General header file for portable code.
  13. *
  14. * $Id: debug.h 1.6 92/03/15 12:51:48 kjb Exp $
  15. *
  16. ****************************************************************************/
  17.  
  18. #ifndef __DEBUG_H
  19. #define __DEBUG_H
  20.  
  21. #ifdef  DEBUG
  22. #       define D(x) x
  23. #else
  24. #       define D(x)
  25. #endif
  26.  
  27. #define PRIVATE static
  28. #define PUBLIC
  29.  
  30. #if     defined(__MSDOS__)      /* Compiling for MSDOS                  */
  31. #       define MS(x) x
  32. #       define OS(x)
  33. #       define UX(x)
  34. #       define IR(x)
  35. #       define _8086        /* We know we have an 8086 type processor   */
  36. #if defined(__COMPACT__) || defined(__LARGE__) || defined(__HUGE__)
  37. #       define LDATA
  38. #ifndef NULL
  39. #       define NULL 0L
  40. #endif
  41. #else
  42. #ifndef NULL
  43. #       define NULL 0
  44. #endif
  45. #endif
  46. #elif   defined(__OS2__)        /* Compiling for 32 bit OS/2            */
  47. #       define MS(x)
  48. #       define OS(x) x
  49. #       define UX(x)
  50. #       define IR(x)
  51. #       define _80386       /* We know we have an 80386 type processor  */
  52. #       define MAXFILE  255     /* These are defined in <dir.h>, but    */
  53. #       define MAXDIR   255     /* on OS/2 machines, we just define     */
  54. #       define MAXPATH  255     /* them all to be the same size         */
  55. #       define near             /* Near and far do not exist under      */
  56. #       define far              /* 32 bit OS/2                          */
  57. #ifndef NULL
  58. #       define NULL 0L
  59. #endif
  60. #else                           /* Assume UNIX compilation              */
  61. #       define MS(x)
  62. #       define OS(x)
  63. #       define UX(x) x
  64. #if     defined(__IRIS4D__)     /* Compiling for the SGI Iris 4D        */
  65. #       define IR(x) x
  66. #else
  67. #       define IR(x)
  68. #endif
  69. #       define O_BINARY 0       /* no binary input mode in UNIX open()  */
  70. #       define MAXFILE  255     /* These are defined in <dir.h>, but    */
  71. #       define MAXDIR   255     /* on UNIX machines, we just define     */
  72. #       define MAXPATH  255     /* them all to be the same size         */
  73. #       define far              /* Near and far do not exist under      */
  74. #       define near             /* UNIX or the Iris.                    */
  75. #ifndef NULL
  76. #       define NULL ((void *)0)
  77. #endif
  78. #endif
  79.  
  80. /****************************************************************************
  81. *
  82. *   SEG(p)      Evaluates to the segment portion of an 8086 address.
  83. *   OFF(p)      Evaluates to the offset portion of an 8086 address.
  84. *   FP(s,o)     Creates a far pointer given a segment offset pair.
  85. *   PHYS(p)     Evaluates to a long holding a physical address
  86. *
  87. ****************************************************************************/
  88.  
  89. #ifdef  _8086
  90. #       define SEG(p)   ( (unsigned)(((unsigned long)((void far *)(p))) >> 16))
  91. #       define OFF(p)   ( (unsigned)(p) )
  92. #       define FP(s,o)  ( (void far *)( ((unsigned long)(s) << 16) +  \
  93.                           (unsigned long)(o) ))
  94. #       define PHYS(p)  ( (unsigned long)OFF(p) +                       \
  95.                           ((unsigned long)SEG(p) << 4))
  96. #else
  97. #       define PHYS(p)  (p)
  98. #endif  /* _8086 */
  99.  
  100. /****************************************************************************
  101. *
  102. *   NUMELE(array)       Evaluates to the array size in elements
  103. *   LASTELE(array)      Evaluates to a pointer to the last element
  104. *   INBOUNDS(array,p)   Evaluates to true if p points into the array
  105. *   RANGE(a,b,c)        Evaluates to true if a <= b <= c
  106. *   MAX(a,b)            Evaluates to a or b, whichever is larger
  107. *   MIN(a,b)            Evaluates to a or b, whichever is smaller
  108. *   ABS(a)              Evaluates to the absolute value of a
  109. *   NBITS(type)         Returns the number of bits in a variable of the
  110. *                       indicated type
  111. *   MAXINT              Evaluates to the value of the largest signed integer
  112. *
  113. ****************************************************************************/
  114.  
  115. #define NUMELE(a)       (sizeof(a)/sizeof(*(a)))
  116. #define LASTELE(a)      ((a) + (NUMELE(a)-1))
  117. #ifdef  LDATA
  118. #define TOOHIGH(a,p)    ((long)PHYS(p) - (long)PHYS(a) > (long)(NUMELE(a)-1))
  119. #define TOOLOW(a,p)     ((long)PHYS(p) - (long)PHYS(a) < 0)
  120. #else
  121. #define TOOHIGH(a,p)    ((long)(p) - (long)(a) > (long)(NUMELE(a)-1))
  122. #define TOOLOW(a,p)     ((long)(p) - (long)(a) < 0)
  123. #endif
  124. #define INBOUNDS(a,p)   ( ! (TOOHIGH(a,p) || TOOLOW(a,p)) )
  125.  
  126. #define _IS(t,x) (((t)1 << (x)) != 0)   /* Evaluates true if the width of */
  127.                                         /* variable of type t is < x.     */
  128.                                         /* The != 0 assures that the      */
  129.                                         /* answer is 1 or 0               */
  130.  
  131. #define NBITS(t) (4 * (1 + _IS(t,4) + _IS(t,8) + _IS(t,12) + _IS(t,16) \
  132.                          + _IS(t,20) + _IS(t,24) + _IS(t,28) + _IS(t,32)))
  133.  
  134. #define MAXINT          (((unsigned)~0) >> 1)
  135.  
  136. #ifndef MAX
  137. #       define MAX(a,b) ( ((a) > (b)) ? (a) : (b))
  138. #endif
  139. #ifndef MIN
  140. #       define MIN(a,b) ( ((a) < (b)) ? (a) : (b))
  141. #endif
  142. #ifndef ABS
  143. #       define ABS(a)   ((a) >= 0 ? (a) : -(a))
  144. #endif
  145. #ifndef    SIGN
  146. #        define SIGN(a)    ((a) > 0 ? 1 : -1)
  147. #endif
  148.  
  149. #define RANGE(a,b,c)    ( (a) <= (b) && (b) <= (c) )
  150.  
  151. /* General typedefs */
  152.  
  153. #ifndef __GENDEFS
  154. #define __GENDEFS
  155. typedef void            *ptr;
  156. typedef void near       *nearptr;
  157. typedef void far        *farptr;
  158. typedef unsigned char   uchar;
  159. typedef unsigned short  ushort;
  160. typedef unsigned int    uint;
  161. typedef unsigned long   ulong;
  162. typedef short           bool;
  163. #endif  /* __GENDEFS */
  164.  
  165. /* Boolean truth values */
  166.  
  167. #define false       0
  168. #define true        1
  169. #define FALSE       0
  170. #define TRUE        1
  171. #define NO          0
  172. #define YES         1
  173.  
  174. #endif  /* __DEBUG_H */
  175.