Source code of Windows XP (NT5)
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.

185 lines
4.6 KiB

  1. #ifndef _XPRS_H_
  2. #define _XPRS_H_
  3. /* -------------------------------------------------------------------- */
  4. /* */
  5. /* Copyright (c) 1991-1999 by Andrew Kadatch */
  6. /* */
  7. /* -------------------------------------------------------------------- */
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <assert.h>
  12. #include "xpress.h"
  13. #ifdef _MSC_VER
  14. #pragma code_seg ("PAGELK")
  15. #pragma optimize ("tgaw", on)
  16. #endif
  17. /* ------------------------ Configuration ----------------------------- */
  18. /* ------------- */
  19. #ifndef CODING_ALG
  20. #define CODING_ALG 1
  21. #endif
  22. #define CODING_DIRECT2 (1 << 1)
  23. #define CODING_DIRECT (1 << 2)
  24. #define CODING_BY_BIT (1 << 3)
  25. #define CODING_HUFF_LEN (1 << 4)
  26. #define CODING_HUFF_PTR (1 << 5)
  27. #define CODING_HUFF_ALL (1 << 6)
  28. #define CODING (1 << CODING_ALG)
  29. #define SUPPORT_CRC 0
  30. #define BUFF_SIZE_LOG XPRESS_MAX_BLOCK_LOG
  31. #define BUFF_SIZE (1<<BUFF_SIZE_LOG)
  32. #if 1
  33. #define MAX_OFFSET (BUFF_SIZE_LOG > 16 ? 16 : BUFF_SIZE_LOG)
  34. #else
  35. #define MAX_OFFSET 13
  36. #endif
  37. #if CODING == CODING_DIRECT2 && MAX_OFFSET > 13
  38. #undef MAX_OFFSET
  39. #define MAX_OFFSET 13
  40. #define DIRECT2_LEN_LOG (16 - MAX_OFFSET)
  41. #define DIRECT2_MAX_LEN ((1 << DIRECT2_LEN_LOG) - 1)
  42. #endif
  43. #if BUFF_SIZE < XPRESS_MAX_BLOCK
  44. #error BUFF_SIZE should not be less than XPRESS_MAX_BLOCK
  45. #endif
  46. #if CODING == CODING_HUFF_LEN
  47. #define MAX_LENGTH 32
  48. #define HUFF_SIZE (MAX_LENGTH * 2)
  49. #elif CODING & (CODING_HUFF_PTR | CODING_HUFF_ALL)
  50. #if (256 / MAX_OFFSET) >= 32
  51. #define MAX_LENGTH_LOG 5
  52. #else
  53. #define MAX_LENGTH_LOG 4
  54. #endif
  55. #define MAX_LENGTH (1 << MAX_LENGTH_LOG)
  56. #if CODING == CODING_HUFF_PTR
  57. #define HUFF_SIZE ((MAX_LENGTH * MAX_OFFSET + 1) & ~1)
  58. #elif CODING == CODING_HUFF_ALL
  59. #define HUFF_SIZE (256 + ((MAX_LENGTH * MAX_OFFSET + 1) & ~1))
  60. #endif
  61. #endif
  62. #define MIN_MATCH 3 /* min acceptable match length */
  63. #if CODING == CODING_HUFF_LEN
  64. #define DECODE_BITS 8
  65. #elif CODING & (CODING_HUFF_PTR | CODING_HUFF_ALL)
  66. #define DECODE_BITS 10
  67. #endif
  68. /* ---------------------- Useful types ------------------------ */
  69. /* ------------ */
  70. #define uchar unsigned char /* useful types */
  71. #define schar signed char
  72. #ifndef __alpha
  73. #define __unaligned
  74. #endif
  75. #define int4 int /* any long enough integral type */
  76. #define int2 short /* assert (2*sizeof(int2) == sizeof (int4)) */
  77. #define xint int /* any int type >= 32 bits && >= sizeof (bitmask4) */
  78. #define int32 int /* 32 bit type */
  79. #define int16 short /* 16 bit type */
  80. #if defined (_M_IX86) && !defined (i386)
  81. #define i386 1 // ifdef i386 asm code will be used for some encodings
  82. #endif
  83. #define tag_t int32
  84. #ifdef i386
  85. #define bitmask4 int32 // must be 32 bit for i386
  86. #define bitmask2 int16
  87. #else
  88. #define bitmask4 int4 // not important otherwise; shall not exceed xint
  89. #define bitmask2 int2
  90. #endif
  91. #define uint4 unsigned int4
  92. #define uint2 unsigned int2
  93. #define uxint unsigned xint
  94. #define uint32 unsigned int32
  95. #define uint16 unsigned int16
  96. #define utag_t unsigned tag_t
  97. #define ubitmask4 unsigned bitmask4
  98. #define ubitmask2 unsigned bitmask2
  99. #ifdef _MSC_VER
  100. #if _MSC_VER >= 1200
  101. #define INLINE __forceinline
  102. #else
  103. #define INLINE __inline
  104. #endif
  105. #pragma warning(disable:4127) /* conditional expression is constant */
  106. #pragma warning(disable:4711) /* function XXX selected for automatic inline expansion */
  107. #pragma warning(disable:4710) /* function XXX not expanded */
  108. #pragma warning(disable:4100) /* unreferenced formal paramter */
  109. #pragma warning(disable:4068) /* bogus "unknown pragma" */
  110. #endif
  111. #ifndef DEBUG
  112. #define DEBUG 0
  113. #endif
  114. #if !defined (INLINE) || DEBUG
  115. #undef INLINE
  116. #define INLINE static
  117. #endif
  118. #if !DEBUG
  119. #undef assert
  120. #define assert(x)
  121. #endif
  122. #if CODING & (CODING_DIRECT | CODING_DIRECT2)
  123. #define MIN_SIZE0 8
  124. #elif CODING == CODING_BY_BIT
  125. #define MIN_SIZE0 7
  126. #elif CODING == CODING_HUFF_LEN
  127. #define MIN_SIZE0 44
  128. #elif CODING == CODING_HUFF_PTR
  129. #define MIN_SIZE0 139
  130. #elif CODING == CODING_HUFF_ALL
  131. #define MIN_SIZE0 261
  132. #else
  133. #error wrong CODING
  134. #endif
  135. #define MIN_SIZE (MIN_SIZE0 + CRC_STAMP_SIZE)
  136. #define CRC32_FIRST 0
  137. #if SUPPORT_CRC
  138. #define CRC_STAMP_SIZE sizeof (uint32)
  139. #else
  140. #define CRC_STAMP_SIZE 0
  141. #endif
  142. #if DEBUG
  143. extern long xxx[];
  144. #endif
  145. #endif /* _XPRS_H_ */