home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / g / gs241j11.zip / INCLUDE.SNF / MISC.H < prev    next >
C/C++ Source or Header  |  1992-04-07  |  5KB  |  149 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.53 89/07/18 13:33:56 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. #ifndef NULL
  37. #if __STDC__ && !NOSTDHDRS
  38. #include <stddef.h>
  39. #else
  40. #define NULL            0
  41. #endif
  42. #endif
  43.  
  44. #define MAXSCREENS    3
  45. #define MAXCLIENTS    128
  46. #define MAXFORMATS    8
  47. #define MAXVISUALS_PER_SCREEN 50
  48.  
  49. typedef unsigned char *pointer;
  50. typedef int Bool;
  51. typedef unsigned long PIXEL;
  52. typedef unsigned long ATOM;
  53.  
  54.  
  55. #ifndef TRUE
  56. #define TRUE 1
  57. #define FALSE 0
  58. #endif
  59. #include "os.h"     /* for ALLOCATE_LOCAL and DEALLOCATE_LOCAL */
  60.  
  61. #define NullBox ((BoxPtr)0)
  62. #define MILLI_PER_MIN (1000 * 60)
  63. #define MILLI_PER_SECOND (1000)
  64.  
  65.     /* this next is used with None and ParentRelative to tell
  66.        PaintWin() what to use to paint the background. Also used
  67.        in the macro IS_VALID_PIXMAP */
  68.  
  69. #define USE_BACKGROUND_PIXEL 3
  70. #define USE_BORDER_PIXEL 3
  71.  
  72.  
  73. /* byte swap a long literal */
  74. #define lswapl(x) ((((x) & 0xff) << 24) |\
  75.            (((x) & 0xff00) << 8) |\
  76.            (((x) & 0xff0000) >> 8) |\
  77.            (((x) >> 24) & 0xff))
  78.  
  79. /* byte swap a short literal */
  80. #define lswaps(x) ((((x) & 0xff) << 8) | (((x) >> 8) & 0xff))
  81.  
  82. #define min(a, b) (((a) < (b)) ? (a) : (b))
  83. #define max(a, b) (((a) > (b)) ? (a) : (b))
  84. #define abs(a) ((a) > 0 ? (a) : -(a))
  85. #define fabs(a) ((a) > 0.0 ? (a) : -(a))    /* floating absolute value */
  86. #define sign(x) ((x) < 0 ? -1 : ((x) > 0 ? 1 : 0))
  87. /*
  88.  * return the least significant bit in x which is set
  89.  *
  90.  * This works on 1's complement and 2's complement machines.
  91.  * If you care about the extra instruction on 2's complement
  92.  * machines, change to ((x) & (-(x)))
  93.  */
  94. #define lowbit(x) ((x) & (~(x) + 1))
  95.  
  96. #define MAXSHORT 32767
  97. #define MINSHORT -MAXSHORT 
  98.  
  99.  
  100. /* some macros to help swap requests, replies, and events */
  101.  
  102. #define LengthRestB(stuff) \
  103.     (((unsigned long)stuff->length << 2) - sizeof(*stuff))
  104.  
  105. #define LengthRestS(stuff) \
  106.     (((unsigned long)stuff->length << 1) - (sizeof(*stuff) >> 1))
  107.  
  108. #define LengthRestL(stuff) \
  109.     ((unsigned long)stuff->length - (sizeof(*stuff) >> 2))
  110.  
  111. #define SwapRestS(stuff) \
  112.     SwapShorts((short *)(stuff + 1), LengthRestS(stuff))
  113.  
  114. #define SwapRestL(stuff) \
  115.     SwapLongs((long *)(stuff + 1), LengthRestL(stuff))
  116.  
  117. /* byte swap a long */
  118. #define swapl(x, n) n = ((char *) (x))[0];\
  119.          ((char *) (x))[0] = ((char *) (x))[3];\
  120.          ((char *) (x))[3] = n;\
  121.          n = ((char *) (x))[1];\
  122.          ((char *) (x))[1] = ((char *) (x))[2];\
  123.          ((char *) (x))[2] = n;
  124.  
  125. /* byte swap a short */
  126. #define swaps(x, n) n = ((char *) (x))[0];\
  127.          ((char *) (x))[0] = ((char *) (x))[1];\
  128.          ((char *) (x))[1] = n
  129.  
  130. /* copy long from src to dst byteswapping on the way */
  131. #define cpswapl(src, dst) \
  132.                  ((char *)&(dst))[0] = ((char *) &(src))[3];\
  133.                  ((char *)&(dst))[1] = ((char *) &(src))[2];\
  134.                  ((char *)&(dst))[2] = ((char *) &(src))[1];\
  135.                  ((char *)&(dst))[3] = ((char *) &(src))[0];
  136.  
  137. /* copy short from src to dst byteswapping on the way */
  138. #define cpswaps(src, dst)\
  139.          ((char *) &(dst))[0] = ((char *) &(src))[1];\
  140.          ((char *) &(dst))[1] = ((char *) &(src))[0];
  141.  
  142. extern void SwapLongs();
  143. extern void SwapShorts();
  144.  
  145. typedef struct _DDXPoint *DDXPointPtr;
  146. typedef struct _Box *BoxPtr;
  147.  
  148. #endif /* MISC_H */
  149.