Rework and improve http download cache: check cache against file on the server and...
[Rockbox.git] / tools / ucl / src / ucl_conf.h
blob20bbd3b6cdfe917743be5ff627ebf94aa6b116e6
1 /* ucl_conf.h -- main internal configuration file for the the UCL library
3 This file is part of the UCL data compression library.
5 Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
6 All Rights Reserved.
8 The UCL library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of
11 the License, or (at your option) any later version.
13 The UCL library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with the UCL library; see the file COPYING.
20 If not, write to the Free Software Foundation, Inc.,
21 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 Markus F.X.J. Oberhumer
24 <markus@oberhumer.com>
28 /* WARNING: this file should *not* be used by applications. It is
29 part of the implementation of the library and is subject
30 to change.
34 #ifndef __UCL_CONF_H
35 #define __UCL_CONF_H
37 #if !defined(__UCL_IN_MINIUCL)
38 # ifndef __UCLCONF_H
39 # include <ucl/uclconf.h>
40 # endif
41 #endif
44 /***********************************************************************
45 // memory checkers
46 ************************************************************************/
48 #if defined(__BOUNDS_CHECKING_ON)
49 # include <unchecked.h>
50 #else
51 # define BOUNDS_CHECKING_OFF_DURING(stmt) stmt
52 # define BOUNDS_CHECKING_OFF_IN_EXPR(expr) (expr)
53 #endif
56 /***********************************************************************
57 // autoconf section
58 ************************************************************************/
60 #if !defined(UCL_HAVE_CONFIG_H)
61 # include <stddef.h> /* ptrdiff_t, size_t */
62 # include <string.h> /* memcpy, memmove, memcmp, memset */
63 # if !defined(NO_STDLIB_H)
64 # include <stdlib.h>
65 # endif
66 # define HAVE_MEMCMP
67 # define HAVE_MEMCPY
68 # define HAVE_MEMMOVE
69 # define HAVE_MEMSET
70 #else
71 # include <sys/types.h>
72 # if defined(STDC_HEADERS)
73 # include <string.h>
74 # include <stdlib.h>
75 # endif
76 # if defined(HAVE_STDDEF_H)
77 # include <stddef.h>
78 # endif
79 # if defined(HAVE_MEMORY_H)
80 # include <memory.h>
81 # endif
82 #endif
84 #if defined(__UCL_DOS16) || defined(__UCL_WIN16)
85 # define HAVE_MALLOC_H
86 # define HAVE_HALLOC
87 #endif
90 #undef NDEBUG
91 #if !defined(UCL_DEBUG)
92 # define NDEBUG
93 #endif
94 #if 1 || defined(UCL_DEBUG) || !defined(NDEBUG)
95 # if !defined(NO_STDIO_H)
96 # include <stdio.h>
97 # endif
98 #endif
99 #include <assert.h>
102 #if !defined(UCL_UNUSED)
103 # define UCL_UNUSED(parm) (parm = parm)
104 #endif
107 #if !defined(__inline__) && !defined(__GNUC__)
108 # if defined(__cplusplus)
109 # define __inline__ inline
110 # else
111 # define __inline__ /* nothing */
112 # endif
113 #endif
116 /***********************************************************************
118 ************************************************************************/
120 #if 1
121 # define UCL_BYTE(x) ((unsigned char) (x))
122 #else
123 # define UCL_BYTE(x) ((unsigned char) ((x) & 0xff))
124 #endif
125 #if 0
126 # define UCL_USHORT(x) ((unsigned short) (x))
127 #else
128 # define UCL_USHORT(x) ((unsigned short) ((x) & 0xffff))
129 #endif
131 #define UCL_MAX(a,b) ((a) >= (b) ? (a) : (b))
132 #define UCL_MIN(a,b) ((a) <= (b) ? (a) : (b))
133 #define UCL_MAX3(a,b,c) ((a) >= (b) ? UCL_MAX(a,c) : UCL_MAX(b,c))
134 #define UCL_MIN3(a,b,c) ((a) <= (b) ? UCL_MIN(a,c) : UCL_MIN(b,c))
136 #define ucl_sizeof(type) ((ucl_uint) (sizeof(type)))
138 #define UCL_HIGH(array) ((ucl_uint) (sizeof(array)/sizeof(*(array))))
140 /* this always fits into 16 bits */
141 #define UCL_SIZE(bits) (1u << (bits))
142 #define UCL_MASK(bits) (UCL_SIZE(bits) - 1)
144 #define UCL_LSIZE(bits) (1ul << (bits))
145 #define UCL_LMASK(bits) (UCL_LSIZE(bits) - 1)
147 #define UCL_USIZE(bits) ((ucl_uint) 1 << (bits))
148 #define UCL_UMASK(bits) (UCL_USIZE(bits) - 1)
150 /* Maximum value of a signed/unsigned type.
151 Do not use casts, avoid overflows ! */
152 #define UCL_STYPE_MAX(b) (((1l << (8*(b)-2)) - 1l) + (1l << (8*(b)-2)))
153 #define UCL_UTYPE_MAX(b) (((1ul << (8*(b)-1)) - 1ul) + (1ul << (8*(b)-1)))
156 /***********************************************************************
158 ************************************************************************/
160 #if !defined(SIZEOF_UNSIGNED)
161 # if (UINT_MAX == 0xffff)
162 # define SIZEOF_UNSIGNED 2
163 # elif (UINT_MAX == UCL_0xffffffffL)
164 # define SIZEOF_UNSIGNED 4
165 # elif (UINT_MAX >= UCL_0xffffffffL)
166 # define SIZEOF_UNSIGNED 8
167 # else
168 # error "SIZEOF_UNSIGNED"
169 # endif
170 #endif
172 #if !defined(SIZEOF_UNSIGNED_LONG)
173 # if (ULONG_MAX == UCL_0xffffffffL)
174 # define SIZEOF_UNSIGNED_LONG 4
175 # elif (ULONG_MAX >= UCL_0xffffffffL)
176 # define SIZEOF_UNSIGNED_LONG 8
177 # else
178 # error "SIZEOF_UNSIGNED_LONG"
179 # endif
180 #endif
183 #if !defined(SIZEOF_SIZE_T)
184 # define SIZEOF_SIZE_T SIZEOF_UNSIGNED_LONG
185 #endif
186 #if !defined(SIZE_T_MAX)
187 # define SIZE_T_MAX UCL_UTYPE_MAX(SIZEOF_SIZE_T)
188 #endif
191 /***********************************************************************
192 // <string.h> section
193 ************************************************************************/
195 #if defined(NO_MEMCMP)
196 # undef HAVE_MEMCMP
197 #endif
199 #if (UCL_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMCMP)
200 # define ucl_memcmp memcmp
201 #endif
202 #if (UCL_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMCPY)
203 # define ucl_memcpy memcpy
204 #endif
205 #if (UCL_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMMOVE)
206 # define ucl_memmove memmove
207 #endif
208 #if (UCL_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMSET)
209 # define ucl_memset memset
210 #endif
212 #if !defined(HAVE_MEMCMP)
213 # undef memcmp
214 # define memcmp ucl_memcmp
215 #endif
216 #if !defined(HAVE_MEMCPY)
217 # undef memcpy
218 # define memcpy ucl_memcpy
219 #endif
220 #if !defined(HAVE_MEMMOVE)
221 # undef memmove
222 # define memmove ucl_memmove
223 #endif
224 #if !defined(HAVE_MEMSET)
225 # undef memset
226 # define memset ucl_memset
227 #endif
230 /***********************************************************************
231 // compiler and architecture specific stuff
232 ************************************************************************/
234 /* Some defines that indicate if memory can be accessed at unaligned
235 * memory addresses. You should also test that this is actually faster
236 * even if it is allowed by your system.
239 #if 1 && defined(__UCL_i386) && (UINT_MAX == UCL_0xffffffffL)
240 # if !defined(UCL_UNALIGNED_OK_2) && (USHRT_MAX == 0xffff)
241 # define UCL_UNALIGNED_OK_2
242 # endif
243 # if !defined(UCL_UNALIGNED_OK_4) && (UCL_UINT32_MAX == UCL_0xffffffffL)
244 # define UCL_UNALIGNED_OK_4
245 # endif
246 #endif
248 #if defined(UCL_UNALIGNED_OK_2) || defined(UCL_UNALIGNED_OK_4)
249 # if !defined(UCL_UNALIGNED_OK)
250 # define UCL_UNALIGNED_OK
251 # endif
252 #endif
254 #if defined(__UCL_NO_UNALIGNED)
255 # undef UCL_UNALIGNED_OK
256 # undef UCL_UNALIGNED_OK_2
257 # undef UCL_UNALIGNED_OK_4
258 #endif
260 #if defined(UCL_UNALIGNED_OK_2) && (USHRT_MAX != 0xffff)
261 # error "UCL_UNALIGNED_OK_2 must not be defined on this system"
262 #endif
263 #if defined(UCL_UNALIGNED_OK_4) && (UCL_UINT32_MAX != UCL_0xffffffffL)
264 # error "UCL_UNALIGNED_OK_4 must not be defined on this system"
265 #endif
268 /* Many modern processors can transfer 32bit words much faster than
269 * bytes - this can significantly speed decompression.
272 #if defined(__UCL_NO_ALIGNED)
273 # undef UCL_ALIGNED_OK_4
274 #endif
276 #if defined(UCL_ALIGNED_OK_4) && (UCL_UINT32_MAX != UCL_0xffffffffL)
277 # error "UCL_ALIGNED_OK_4 must not be defined on this system"
278 #endif
281 /* Definitions for byte order, according to significance of bytes, from low
282 * addresses to high addresses. The value is what you get by putting '4'
283 * in the most significant byte, '3' in the second most significant byte,
284 * '2' in the second least significant byte, and '1' in the least
285 * significant byte.
286 * The byte order is only needed if we use UCL_UNALIGNED_OK.
289 #define UCL_LITTLE_ENDIAN 1234
290 #define UCL_BIG_ENDIAN 4321
291 #define UCL_PDP_ENDIAN 3412
293 #if !defined(UCL_BYTE_ORDER)
294 # if defined(MFX_BYTE_ORDER)
295 # define UCL_BYTE_ORDER MFX_BYTE_ORDER
296 # elif defined(__UCL_i386)
297 # define UCL_BYTE_ORDER UCL_LITTLE_ENDIAN
298 # elif defined(BYTE_ORDER)
299 # define UCL_BYTE_ORDER BYTE_ORDER
300 # elif defined(__BYTE_ORDER)
301 # define UCL_BYTE_ORDER __BYTE_ORDER
302 # endif
303 #endif
305 #if defined(UCL_BYTE_ORDER)
306 # if (UCL_BYTE_ORDER != UCL_LITTLE_ENDIAN) && \
307 (UCL_BYTE_ORDER != UCL_BIG_ENDIAN)
308 # error "invalid UCL_BYTE_ORDER"
309 # endif
310 #endif
312 #if defined(UCL_UNALIGNED_OK) && !defined(UCL_BYTE_ORDER)
313 # error "UCL_BYTE_ORDER is not defined"
314 #endif
317 /***********************************************************************
318 // some globals
319 ************************************************************************/
321 __UCL_EXTERN_C int __ucl_init_done;
322 __UCL_EXTERN_C const ucl_byte __ucl_copyright[];
323 UCL_EXTERN(const ucl_byte *) ucl_copyright(void);
324 __UCL_EXTERN_C const ucl_uint32 _ucl_crc32_table[256];
327 /***********************************************************************
328 // ANSI C preprocessor macros
329 ************************************************************************/
331 #define _UCL_STRINGIZE(x) #x
332 #define _UCL_MEXPAND(x) _UCL_STRINGIZE(x)
334 /* concatenate */
335 #define _UCL_CONCAT2(a,b) a ## b
336 #define _UCL_CONCAT3(a,b,c) a ## b ## c
337 #define _UCL_CONCAT4(a,b,c,d) a ## b ## c ## d
338 #define _UCL_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e
340 /* expand and concatenate (by using one level of indirection) */
341 #define _UCL_ECONCAT2(a,b) _UCL_CONCAT2(a,b)
342 #define _UCL_ECONCAT3(a,b,c) _UCL_CONCAT3(a,b,c)
343 #define _UCL_ECONCAT4(a,b,c,d) _UCL_CONCAT4(a,b,c,d)
344 #define _UCL_ECONCAT5(a,b,c,d,e) _UCL_CONCAT5(a,b,c,d,e)
347 /***********************************************************************
349 ************************************************************************/
351 #include "ucl_ptr.h"
354 #endif /* already included */
357 vi:ts=4:et