00001 // $Id: zutil.h 751 2006-03-31 15:43:49Z alex $ 00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE 00003 ================================XARAHEADERSTART=========================== 00004 00005 Xara LX, a vector drawing and manipulation program. 00006 Copyright (C) 1993-2006 Xara Group Ltd. 00007 Copyright on certain contributions may be held in joint with their 00008 respective authors. See AUTHORS file for details. 00009 00010 LICENSE TO USE AND MODIFY SOFTWARE 00011 ---------------------------------- 00012 00013 This file is part of Xara LX. 00014 00015 Xara LX is free software; you can redistribute it and/or modify it 00016 under the terms of the GNU General Public License version 2 as published 00017 by the Free Software Foundation. 00018 00019 Xara LX and its component source files are distributed in the hope 00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the 00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00022 See the GNU General Public License for more details. 00023 00024 You should have received a copy of the GNU General Public License along 00025 with Xara LX (see the file GPL in the root directory of the 00026 distribution); if not, write to the Free Software Foundation, Inc., 51 00027 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00028 00029 00030 ADDITIONAL RIGHTS 00031 ----------------- 00032 00033 Conditional upon your continuing compliance with the GNU General Public 00034 License described above, Xara Group Ltd grants to you certain additional 00035 rights. 00036 00037 The additional rights are to use, modify, and distribute the software 00038 together with the wxWidgets library, the wxXtra library, and the "CDraw" 00039 library and any other such library that any version of Xara LX relased 00040 by Xara Group Ltd requires in order to compile and execute, including 00041 the static linking of that library to XaraLX. In the case of the 00042 "CDraw" library, you may satisfy obligation under the GNU General Public 00043 License to provide source code by providing a binary copy of the library 00044 concerned and a copy of the license accompanying it. 00045 00046 Nothing in this section restricts any of the rights you have under 00047 the GNU General Public License. 00048 00049 00050 SCOPE OF LICENSE 00051 ---------------- 00052 00053 This license applies to this program (XaraLX) and its constituent source 00054 files only, and does not necessarily apply to other Xara products which may 00055 in part share the same code base, and are subject to their own licensing 00056 terms. 00057 00058 This license does not apply to files in the wxXtra directory, which 00059 are built into a separate library, and are subject to the wxWindows 00060 license contained within that directory in the file "WXXTRA-LICENSE". 00061 00062 This license does not apply to the binary libraries (if any) within 00063 the "libs" directory, which are subject to a separate license contained 00064 within that directory in the file "LIBS-LICENSE". 00065 00066 00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS 00068 ---------------------------------------------- 00069 00070 Subject to the terms of the GNU Public License (see above), you are 00071 free to do whatever you like with your modifications. However, you may 00072 (at your option) wish contribute them to Xara's source tree. You can 00073 find details of how to do this at: 00074 http://www.xaraxtreme.org/developers/ 00075 00076 Prior to contributing your modifications, you will need to complete our 00077 contributor agreement. This can be found at: 00078 http://www.xaraxtreme.org/developers/contribute/ 00079 00080 Please note that Xara will not accept modifications which modify any of 00081 the text between the start and end of this header (marked 00082 XARAHEADERSTART and XARAHEADEREND). 00083 00084 00085 MARKS 00086 ----- 00087 00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara 00089 designs are registered or unregistered trademarks, design-marks, and/or 00090 service marks of Xara Group Ltd. All rights in these marks are reserved. 00091 00092 00093 Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK. 00094 http://www.xara.com/ 00095 00096 =================================XARAHEADEREND============================ 00097 */ 00098 00099 // This class contains all the file deflating code 00100 00101 #ifndef INC_ZIPUTIL 00102 #define INC_ZIPUTIL 00103 00104 // Our mapping for our classes onto the equivalents 00105 //#define z_stream ZStream 00106 //#define gz_stream GZipStream 00107 //#define deflate_state DeflateState 00108 00109 /* 00110 The 'zlib' compression library provides in-memory compression and 00111 decompression functions, including integrity checks of the uncompressed 00112 data. This version of the library supports only one compression method 00113 (deflation) but other algorithms may be added later and will have the same 00114 stream interface. 00115 00116 For compression the application must provide the output buffer and 00117 may optionally provide the input buffer for optimization. For decompression, 00118 the application must provide the input buffer and may optionally provide 00119 the output buffer for optimization. 00120 00121 Compression can be done in a single step if the buffers are large 00122 enough (for example if an input file is mmap'ed), or can be done by 00123 repeated calls of the compression function. In the latter case, the 00124 application must provide more input and/or consume the output 00125 (providing more output space) before each call. 00126 00127 The library does not install any signal handler. It is recommended to 00128 add at least a handler for SIGSEGV when decompressing; the library checks 00129 the consistency of the input data whenever possible but may go nuts 00130 for some forms of corrupted input. 00131 */ 00132 00133 #include <string.h> 00134 00135 // For the PNG stuff, change references to z_stream to ZStream 00136 #define ZStream z_stream 00137 00138 // Should really be this but version 1.1 Camelot does not seem to like different version numbers 00139 //#define ZLIB_VERSION "1.0" 00140 #define ZLIB_VERSION "0.92" 00141 #define ZLIB_VERSIONNO 0.92 00142 00143 // We will put the real version number in these new variables. 00144 #define ZLIB_MAJOR_VERSIONNO 0 00145 #define ZLIB_MINOR_VERSIONNO 99 00146 00147 //extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */ 00148 /* (size given to avoid silly warnings with Visual C++) */ 00149 00150 typedef void FAR *voidpf; 00151 typedef void *voidp; 00152 00153 typedef unsigned char Byte; /* 8 bits */ 00154 typedef UINT32 uInt; /* 16 bits or more */ 00155 typedef UINT32 uLong; /* 32 bits or more */ 00156 00157 typedef Byte FAR Bytef; 00158 typedef char FAR charf; 00159 typedef INT32 FAR intf; 00160 typedef uInt FAR uIntf; 00161 typedef uLong FAR uLongf; 00162 00163 #define ERR_MSG(err) (char*)z_errmsg[Z_NEED_DICT-(err)] 00164 00165 //#define ERR_RETURN(strm,err) return (strm->msg = ERR_MSG(err), (err)) 00166 /* To be used only when the state is known to be valid */ 00167 00168 // My old form 00169 //#define ERR_RETURN(strm,err) return (strm->msg = GZipFile::z_errmsg[Z_NEED_DICT-(err)], err) 00171 #define ERR_RETURN(strm,err) return (err) 00172 00173 00174 //------------------------------------------------------------------------------------------- 00175 // Constants from file zconf.h 00176 //------------------------------------------------------------------------------------------- 00177 00178 /* common constants */ 00179 00180 #define DEFLATED 8 00181 00182 #define DEF_WBITS 15 00183 /* default windowBits for decompression. MAX_WBITS is for compression only */ 00184 00185 /* 00186 * Compile with -DMAXSEG_64K if the alloc function cannot allocate more 00187 * than 64k bytes at a time (needed on systems with 16-bit INT32). 00188 */ 00189 //# define __32BIT__ 00190 //# define MAXSEG_64K 00191 00192 /* The memory requirements for deflate are (in bytes): 00193 1 << (windowBits+2) + 1 << (memLevel+9) 00194 that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) 00195 plus a few kilobytes for small objects. For example, if you want to reduce 00196 the default memory requirements from 256K to 128K, compile with 00197 make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" 00198 Of course this will generally degrade compression (there's no free lunch). 00199 00200 The memory requirements for inflate are (in bytes) 1 << windowBits 00201 that is, 32K for windowBits=15 (default value) plus a few kilobytes 00202 for small objects. 00203 */ 00204 00205 /* Maximum value for memLevel in deflateInit2 */ 00206 #define MAX_MEM_LEVEL 9 00207 00208 /* Maximum value for windowBits in deflateInit2 and inflateInit2 */ 00209 #define MAX_WBITS 15 /* 32K LZ77 window */ 00210 00211 00212 //------------------------------------------------------------------------------------------- 00213 // Constants from file zutil.h 00214 //------------------------------------------------------------------------------------------- 00215 00216 #if MAX_MEM_LEVEL >= 8 00217 # define DEF_MEM_LEVEL 8 00218 #else 00219 # define DEF_MEM_LEVEL MAX_MEM_LEVEL 00220 #endif 00221 /* default memLevel */ 00222 00223 #define STORED_BLOCK 0 00224 #define STATIC_TREES 1 00225 #define DYN_TREES 2 00226 /* The three kinds of block type */ 00227 00228 #define MIN_MATCH 3 00229 #define MAX_MATCH 258 00230 /* The minimum and maximum match lengths */ 00231 00232 #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ 00233 00234 typedef unsigned char uch; 00235 typedef uch FAR uchf; 00236 typedef unsigned short ush; 00237 typedef ush FAR ushf; 00238 typedef UINT32 ulg; 00239 00240 //------------------------------------------------------------------------------------------- 00241 // Constants from file zlib.h 00242 //------------------------------------------------------------------------------------------- 00243 00244 /* constants */ 00245 00246 #define Z_NO_FLUSH 0 00247 #define Z_PARTIAL_FLUSH 1 00248 #define Z_SYNC_FLUSH 2 00249 #define Z_FULL_FLUSH 3 00250 #define Z_FINISH 4 00251 /* Allowed flush values; see deflate() below for details */ 00252 00253 #define Z_OK 0 00254 #define Z_STREAM_END 1 00255 #define Z_NEED_DICT 2 00256 #define Z_ERRNO (-1) 00257 #define Z_STREAM_ERROR (-2) 00258 #define Z_DATA_ERROR (-3) 00259 #define Z_MEM_ERROR (-4) 00260 #define Z_BUF_ERROR (-5) 00261 #define Z_VERSION_ERROR (-6) 00262 // This is our special no compressed section found error 00263 #define Z_UNCOMPRESSED_ERROR (-7) 00264 /* Return codes for the compression/decompression functions. Negative 00265 * values are errors, positive values are used for special but normal events. 00266 */ 00267 00268 #define Z_NO_COMPRESSION 0 00269 #define Z_BEST_SPEED 1 00270 #define Z_BEST_COMPRESSION 9 00271 #define Z_DEFAULT_COMPRESSION (-1) 00272 /* compression levels */ 00273 00274 #define Z_FILTERED 1 00275 #define Z_HUFFMAN_ONLY 2 00276 #define Z_DEFAULT_STRATEGY 0 00277 /* compression strategy; see deflateInit2() below for details */ 00278 00279 #define Z_BINARY 0 00280 #define Z_ASCII 1 00281 #define Z_UNKNOWN 2 00282 /* Possible values of the data_type field */ 00283 00284 #define Z_DEFLATED 8 00285 /* The deflate compression method (the only one supported in this version) */ 00286 00287 #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ 00288 00289 00290 00291 //------------------------------------------------------------------------------------------- 00292 // Constants from file zutil.h 00293 //------------------------------------------------------------------------------------------- 00294 00295 /* target dependencies */ 00296 00297 /* Windows NT */ 00298 #define OS_CODE 0x0b 00299 #define zmemcpy memcpy 00300 #define zmemcmp memcmp 00301 #define zmemzero(dest, len) memset(dest, 0, len) 00302 00303 /* Diagnostic functions */ 00304 00305 #define _FTPRINTF TRACEUSER( "Neville", _T("%s"),x) 00306 00307 //#ifdef _DEBUG 00308 // #define DEBUG 1 00309 //#else 00310 // #undef DEBUG 00311 //#endif 00312 00313 #ifdef DEBUG 00314 # include <stdio.h> 00315 # ifndef verbose 00316 # define verbose 0 00317 # endif 00318 # define Assert(cond,msg) ERROR3IF(!(cond),msg); //{if(!(cond)) z_error(msg);} 00319 # define Assert3(msg) ERROR3(msg); //{if(!(cond)) z_error(msg);} 00320 # define Trace(x) {TRACEUSER( "Neville", _T("%s"),x); } 00321 # define Tracev(x) {if (verbose) TRACEUSER( "Neville", _T("%s"),x) ;} 00322 # define Tracevv(x) {if (verbose>1) TRACEUSER( "Neville", _T("%s"),x) ;} 00323 # define Tracec(c,x) {if (verbose && (c)) TRACEUSER( "Neville", _T("%s"),x) ;} 00324 # define Tracecv(c,x) {if (verbose>1 && (c)) TRACEUSER( "Neville", _T("%s"),x) ;} 00325 #else 00326 # define Assert(cond,msg) 00327 # define Trace(x) 00328 # define Tracev(x) 00329 # define Tracevv(x) 00330 # define Tracec(c,x) 00331 # define Tracecv(c,x) 00332 #endif 00333 00334 typedef uLong (*check_func)(uLong check, const Bytef *buf, uInt len); 00335 00336 //extern void z_error(char *m); 00337 #define z_error(m) ERROR3(m); 00338 00339 //#define ZALLOC(strm, items, size) CCMalloc(size) 00340 //#define ZFREE(strm, addr) {CCFree(addr); addr = NULL; } 00341 //#define TRY_FREE(s, p) {if (p) ZFREE(s, p)} 00342 00343 #define ZALLOC(strm, items, size) \ 00344 (*((strm)->zalloc))((strm)->opaque, (items), (size)) 00345 #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (void*)(addr)) 00346 #define TRY_FREE(s, p) {if (p) ZFREE(s, p);} 00347 00348 00349 #endif // INC_ZIPUTIL 00350 00351