Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

173 lines
4.5 KiB

  1. //
  2. // CCSHELL stock definition and declaration header
  3. //
  4. #ifndef __CCSTOCK_H__
  5. #define __CCSTOCK_H__
  6. #ifndef RC_INVOKED
  7. // NT and Win95 environments set warnings differently. This makes
  8. // our project consistent across environments.
  9. #pragma warning(3:4101) // Unreferenced local variable
  10. //
  11. // Sugar-coating
  12. //
  13. #define PUBLIC
  14. #define PRIVATE
  15. #define IN
  16. #define OUT
  17. #define BLOCK
  18. #ifndef DECLARE_STANDARD_TYPES
  19. /*
  20. * For a type "FOO", define the standard derived types PFOO, CFOO, and PCFOO.
  21. */
  22. #define DECLARE_STANDARD_TYPES(type) typedef type *P##type; \
  23. typedef const type C##type; \
  24. typedef const type *PC##type;
  25. #endif
  26. #ifndef DECLARE_STANDARD_TYPES_U
  27. /*
  28. * For a type "FOO", define the standard derived UNALIGNED types PFOO, CFOO, and PCFOO.
  29. * WINNT: RISC boxes care about ALIGNED, intel does not.
  30. */
  31. #define DECLARE_STANDARD_TYPES_U(type) typedef UNALIGNED type *P##type; \
  32. typedef UNALIGNED const type C##type; \
  33. typedef UNALIGNED const type *PC##type;
  34. #endif
  35. // For string constants that are always wide
  36. #define __TEXTW(x) L##x
  37. #define TEXTW(x) __TEXTW(x)
  38. // Count of characters to count of bytes
  39. //
  40. #define CbFromCchW(cch) ((cch)*sizeof(WCHAR))
  41. #define CbFromCchA(cch) ((cch)*sizeof(CHAR))
  42. #ifdef UNICODE
  43. #define CbFromCch CbFromCchW
  44. #else // UNICODE
  45. #define CbFromCch CbFromCchA
  46. #endif // UNICODE
  47. // General flag macros
  48. //
  49. #define SetFlag(obj, f) do {obj |= (f);} while (0)
  50. #define ToggleFlag(obj, f) do {obj ^= (f);} while (0)
  51. #define ClearFlag(obj, f) do {obj &= ~(f);} while (0)
  52. #define IsFlagSet(obj, f) (BOOL)(((obj) & (f)) == (f))
  53. #define IsFlagClear(obj, f) (BOOL)(((obj) & (f)) != (f))
  54. // String macros
  55. //
  56. #define IsSzEqual(sz1, sz2) (BOOL)(lstrcmpi(sz1, sz2) == 0)
  57. #define IsSzEqualC(sz1, sz2) (BOOL)(lstrcmp(sz1, sz2) == 0)
  58. #define lstrnicmpA(sz1, sz2, cch) StrCmpNIA(sz1, sz2, cch)
  59. #define lstrnicmpW(sz1, sz2, cch) StrCmpNIW(sz1, sz2, cch)
  60. #define lstrncmpA(sz1, sz2, cch) StrCmpNA(sz1, sz2, cch)
  61. #define lstrncmpW(sz1, sz2, cch) StrCmpNW(sz1, sz2, cch)
  62. #ifdef UNICODE
  63. #define lstrnicmp lstrnicmpW
  64. #define lstrncmp lstrncmpW
  65. #else
  66. #define lstrnicmp lstrnicmpA
  67. #define lstrncmp lstrncmpA
  68. #endif
  69. #ifndef SIZEOF
  70. #define SIZEOF(a) sizeof(a)
  71. #endif
  72. #ifndef ARRAYSIZE
  73. #define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
  74. #endif
  75. #define SIZECHARS(sz) (sizeof(sz)/sizeof(sz[0]))
  76. #ifndef NULL_TERM_TCHARS
  77. #define NULL_TERM_TCHARS(sz); {sz[ARRAYSIZE(sz)-1] = TEXT('\0');}
  78. #endif
  79. #define InRange(id, idFirst, idLast) ((UINT)((id)-(idFirst)) <= (UINT)((idLast)-(idFirst)))
  80. #define ZeroInit(pv, cb) (memset((pv), 0, (cb)))
  81. #ifdef DEBUG
  82. // This macro is especially useful for cleaner looking code in
  83. // declarations or for single lines. For example, instead of:
  84. //
  85. // {
  86. // DWORD dwRet;
  87. // #ifdef DEBUG
  88. // DWORD dwDebugOnlyVariable;
  89. // #endif
  90. //
  91. // ....
  92. // }
  93. //
  94. // You can type:
  95. //
  96. // {
  97. // DWORD dwRet;
  98. // DEBUG_CODE( DWORD dwDebugOnlyVariable; )
  99. //
  100. // ....
  101. // }
  102. #define DEBUG_CODE(x) x
  103. #else
  104. #define DEBUG_CODE(x)
  105. #endif // DEBUG
  106. //
  107. // SAFECAST(obj, type)
  108. //
  109. // This macro is extremely useful for enforcing strong typechecking on other
  110. // macros. It generates no code.
  111. //
  112. // Simply insert this macro at the beginning of an expression list for
  113. // each parameter that must be typechecked. For example, for the
  114. // definition of MYMAX(x, y), where x and y absolutely must be integers,
  115. // use:
  116. //
  117. // #define MYMAX(x, y) (SAFECAST(x, int), SAFECAST(y, int), ((x) > (y) ? (x) : (y)))
  118. //
  119. //
  120. #define SAFECAST(_obj, _type) (((_type)(_obj)==(_obj)?0:0), (_type)(_obj))
  121. //
  122. // Bitfields don't get along too well with bools,
  123. // so here's an easy way to convert them:
  124. //
  125. #define BOOLIFY(expr) (!!(expr))
  126. // BUGBUG (scotth): we should probably make this a 'bool', but be careful
  127. // because the Alpha compiler might not recognize it yet. Talk to AndyP.
  128. // This isn't a BOOL because BOOL is signed and the compiler produces
  129. // sloppy code when testing for a single bit.
  130. typedef DWORD BITBOOL;
  131. #endif // RC_INVOKED
  132. #endif // __CCSTOCK_H__