home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / include / misc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-09  |  4.6 KB  |  158 lines

  1. /***********************************************************
  2. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  3. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Digital or MIT not be
  12. used in advertising or publicity pertaining to distribution of the
  13. software without specific, written prior permission.  
  14.  
  15. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  16. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  17. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  18. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  20. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21. SOFTWARE.
  22.  
  23. ******************************************************************/
  24. /* $XConsortium: misc.h,v 1.58 91/04/10 08:53:39 rws Exp $ */
  25. #ifndef MISC_H
  26. #define MISC_H 1
  27. /*
  28.  *  X internal definitions 
  29.  *
  30.  */
  31.  
  32.  
  33. extern unsigned long globalSerialNumber;
  34. extern unsigned long serverGeneration;
  35.  
  36. #include <X11/Xosdefs.h>
  37.  
  38. #ifndef NULL
  39. #ifndef X_NOT_STDC_ENV
  40. #include <stddef.h>
  41. #else
  42. #define NULL            0
  43. #endif
  44. #endif
  45.  
  46. #define MAXSCREENS    3
  47. #define MAXCLIENTS    128
  48. #define MAXFORMATS    8
  49. #define MAXVISUALS_PER_SCREEN 50
  50.  
  51. typedef unsigned char *pointer;
  52. typedef int Bool;
  53. typedef unsigned long PIXEL;
  54. typedef unsigned long ATOM;
  55.  
  56.  
  57. #ifndef TRUE
  58. #define TRUE 1
  59. #define FALSE 0
  60. #endif
  61. #include "os.h"     /* for ALLOCATE_LOCAL and DEALLOCATE_LOCAL */
  62. #include <X11/Xfuncs.h> /* for bcopy, bzero, and bcmp */
  63.  
  64. #define NullBox ((BoxPtr)0)
  65. #define MILLI_PER_MIN (1000 * 60)
  66. #define MILLI_PER_SECOND (1000)
  67.  
  68.     /* this next is used with None and ParentRelative to tell
  69.        PaintWin() what to use to paint the background. Also used
  70.        in the macro IS_VALID_PIXMAP */
  71.  
  72. #define USE_BACKGROUND_PIXEL 3
  73. #define USE_BORDER_PIXEL 3
  74.  
  75.  
  76. /* byte swap a long literal */
  77. #define lswapl(x) ((((x) & 0xff) << 24) |\
  78.            (((x) & 0xff00) << 8) |\
  79.            (((x) & 0xff0000) >> 8) |\
  80.            (((x) >> 24) & 0xff))
  81.  
  82. /* byte swap a short literal */
  83. #define lswaps(x) ((((x) & 0xff) << 8) | (((x) >> 8) & 0xff))
  84.  
  85. #define min(a, b) (((a) < (b)) ? (a) : (b))
  86. #define max(a, b) (((a) > (b)) ? (a) : (b))
  87. #ifndef abs
  88. #define abs(a) ((a) > 0 ? (a) : -(a))
  89. #endif
  90. #ifndef fabs
  91. #define fabs(a) ((a) > 0.0 ? (a) : -(a))    /* floating absolute value */
  92. #endif
  93. #define sign(x) ((x) < 0 ? -1 : ((x) > 0 ? 1 : 0))
  94. /* this assumes b > 0 */
  95. #define modulus(a, b, d)    if (((d) = (a) % (b)) < 0) (d) += (b)
  96. /*
  97.  * return the least significant bit in x which is set
  98.  *
  99.  * This works on 1's complement and 2's complement machines.
  100.  * If you care about the extra instruction on 2's complement
  101.  * machines, change to ((x) & (-(x)))
  102.  */
  103. #define lowbit(x) ((x) & (~(x) + 1))
  104.  
  105. #define MAXSHORT 32767
  106. #define MINSHORT -MAXSHORT 
  107.  
  108.  
  109. /* some macros to help swap requests, replies, and events */
  110.  
  111. #define LengthRestB(stuff) \
  112.     (((unsigned long)stuff->length << 2) - sizeof(*stuff))
  113.  
  114. #define LengthRestS(stuff) \
  115.     (((unsigned long)stuff->length << 1) - (sizeof(*stuff) >> 1))
  116.  
  117. #define LengthRestL(stuff) \
  118.     ((unsigned long)stuff->length - (sizeof(*stuff) >> 2))
  119.  
  120. #define SwapRestS(stuff) \
  121.     SwapShorts((short *)(stuff + 1), LengthRestS(stuff))
  122.  
  123. #define SwapRestL(stuff) \
  124.     SwapLongs((long *)(stuff + 1), LengthRestL(stuff))
  125.  
  126. /* byte swap a long */
  127. #define swapl(x, n) n = ((char *) (x))[0];\
  128.          ((char *) (x))[0] = ((char *) (x))[3];\
  129.          ((char *) (x))[3] = n;\
  130.          n = ((char *) (x))[1];\
  131.          ((char *) (x))[1] = ((char *) (x))[2];\
  132.          ((char *) (x))[2] = n;
  133.  
  134. /* byte swap a short */
  135. #define swaps(x, n) n = ((char *) (x))[0];\
  136.          ((char *) (x))[0] = ((char *) (x))[1];\
  137.          ((char *) (x))[1] = n
  138.  
  139. /* copy long from src to dst byteswapping on the way */
  140. #define cpswapl(src, dst) \
  141.                  ((char *)&(dst))[0] = ((char *) &(src))[3];\
  142.                  ((char *)&(dst))[1] = ((char *) &(src))[2];\
  143.                  ((char *)&(dst))[2] = ((char *) &(src))[1];\
  144.                  ((char *)&(dst))[3] = ((char *) &(src))[0];
  145.  
  146. /* copy short from src to dst byteswapping on the way */
  147. #define cpswaps(src, dst)\
  148.          ((char *) &(dst))[0] = ((char *) &(src))[1];\
  149.          ((char *) &(dst))[1] = ((char *) &(src))[0];
  150.  
  151. extern void SwapLongs();
  152. extern void SwapShorts();
  153.  
  154. typedef struct _DDXPoint *DDXPointPtr;
  155. typedef struct _Box *BoxPtr;
  156.  
  157. #endif /* MISC_H */
  158.