1 /* ucl_util.c -- utilities for the UCL library
3 This file is part of the UCL data compression library.
5 Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
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>
25 http://www.oberhumer.com/opensource/ucl/
33 /***********************************************************************
35 ************************************************************************/
40 return (expr
) ? 1 : 0;
44 /***********************************************************************
46 ************************************************************************/
48 /* If you use the UCL library in a product, you *must* keep this
49 * copyright string in the executable of your product.
52 const ucl_byte __ucl_copyright
[] =
54 "UCL real-time data compression library.\n"
55 "$Copyright: UCL (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002 Markus Franz Xaver Johannes Oberhumer $\n"
56 "<markus@oberhumer.com>\n"
57 "http://www.oberhumer.com\n"
59 "UCL version: v" UCL_VERSION_STRING
", " UCL_VERSION_DATE
"\n"
60 "UCL build date: " __DATE__
" " __TIME__
"\n\n"
61 "UCL special compilation options:\n"
67 #elif defined(__pic__)
70 #if (UINT_MAX < UCL_0xffffffffL)
73 #if defined(__UCL_STRICT_16BIT)
74 " __UCL_STRICT_16BIT\n"
76 #if (UINT_MAX > UCL_0xffffffffL)
77 " UINT_MAX=" _UCL_MEXPAND(UINT_MAX
) "\n"
79 #if (ULONG_MAX > UCL_0xffffffffL)
80 " ULONG_MAX=" _UCL_MEXPAND(ULONG_MAX
) "\n"
82 #if defined(UCL_BYTE_ORDER)
83 " UCL_BYTE_ORDER=" _UCL_MEXPAND(UCL_BYTE_ORDER
) "\n"
85 #if defined(UCL_UNALIGNED_OK_2)
86 " UCL_UNALIGNED_OK_2\n"
88 #if defined(UCL_UNALIGNED_OK_4)
89 " UCL_UNALIGNED_OK_4\n"
91 #if defined(UCL_ALIGNED_OK_4)
94 #if defined(__UCL_IN_MINIUCL)
99 "$Id: UCL " UCL_VERSION_STRING
" built " __DATE__
" " __TIME__
100 #if defined(__GNUC__) && defined(__VERSION__)
101 " by gcc " __VERSION__
102 #elif defined(__BORLANDC__)
103 " by Borland C " _UCL_MEXPAND(__BORLANDC__
)
104 #elif defined(_MSC_VER)
105 " by Microsoft C " _UCL_MEXPAND(_MSC_VER
)
106 #elif defined(__PUREC__)
107 " by Pure C " _UCL_MEXPAND(__PUREC__
)
108 #elif defined(__SC__)
109 " by Symantec C " _UCL_MEXPAND(__SC__
)
110 #elif defined(__TURBOC__)
111 " by Turbo C " _UCL_MEXPAND(__TURBOC__
)
112 #elif defined(__WATCOMC__)
113 " by Watcom C " _UCL_MEXPAND(__WATCOMC__
)
117 UCL_PUBLIC(const ucl_byte
*)
120 return __ucl_copyright
;
123 UCL_PUBLIC(ucl_uint32
)
129 UCL_PUBLIC(const char *)
130 ucl_version_string(void)
132 return UCL_VERSION_STRING
;
135 UCL_PUBLIC(const char *)
136 ucl_version_date(void)
138 return UCL_VERSION_DATE
;
141 UCL_PUBLIC(const ucl_charp
)
142 _ucl_version_string(void)
144 return UCL_VERSION_STRING
;
147 UCL_PUBLIC(const ucl_charp
)
148 _ucl_version_date(void)
150 return UCL_VERSION_DATE
;
154 /***********************************************************************
156 // adapted from free code by Mark Adler <madler@alumni.caltech.edu>
157 // see http://www.cdrom.com/pub/infozip/zlib/
158 ************************************************************************/
160 #define UCL_BASE 65521u /* largest prime smaller than 65536 */
161 #define UCL_NMAX 5552
162 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
164 #define UCL_DO1(buf,i) {s1 += buf[i]; s2 += s1;}
165 #define UCL_DO2(buf,i) UCL_DO1(buf,i); UCL_DO1(buf,i+1);
166 #define UCL_DO4(buf,i) UCL_DO2(buf,i); UCL_DO2(buf,i+2);
167 #define UCL_DO8(buf,i) UCL_DO4(buf,i); UCL_DO4(buf,i+4);
168 #define UCL_DO16(buf,i) UCL_DO8(buf,i); UCL_DO8(buf,i+8);
170 UCL_PUBLIC(ucl_uint32
)
171 ucl_adler32(ucl_uint32 adler
, const ucl_byte
*buf
, ucl_uint len
)
173 ucl_uint32 s1
= adler
& 0xffff;
174 ucl_uint32 s2
= (adler
>> 16) & 0xffff;
182 k
= len
< UCL_NMAX
? (int) len
: UCL_NMAX
;
198 return (s2
<< 16) | s1
;