1 /*
2   Copyright (c) 1990-2009 Info-ZIP.  All rights reserved.
3 
4   See the accompanying file LICENSE, version 2009-Jan-02 or later
5   (the contents of which are also included in unzip.h) for terms of use.
6   If, for some reason, all these files are missing, the Info-ZIP license
7   also may be found at:  ftp://ftp.info-zip.org/pub/infozip/license.html
8 */
9 /*---------------------------------------------------------------------------
10     WinCE "command line tool" specific configuration section:
11   ---------------------------------------------------------------------------*/
12 
13 #ifndef __wcecfg_h
14 #define __wcecfg_h
15 
16 /*---------------------------------------------------------------------------
17     Standard Win32 project flags
18   ---------------------------------------------------------------------------*/
19 
20 #ifdef _WIN32_WCE   /* for native Windows CE, force UNICODE mode */
21 #ifndef UNICODE
22 #define UNICODE
23 #endif
24 #endif /* _WIN32_WCE */
25 
26 // for UnZip, the "basic" part of the win32 api is sufficient
27 #ifndef WIN32_LEAN_AND_MEAN
28 #define WIN32_LEAN_AND_MEAN
29 #endif
30 
31 #if defined(_UNICODE) && !defined(UNICODE)
32 #define UNICODE
33 #endif
34 
35 #if defined(UNICODE) && !defined(_UNICODE)
36 #define _UNICODE
37 #endif
38 
39 #if defined(_DEBUG) && !defined(DEBUG)
40 #define DEBUG
41 #endif
42 
43 #if defined(DEBUG) && !defined(_DEBUG)
44 #define _DEBUG
45 #endif
46 
47 #if defined(_NDEBUG) && !defined(NDEBUG)
48 #define NDEBUG
49 #endif
50 
51 #if defined(NDEBUG) && !defined(_NDEBUG)
52 #define _NDEBUG
53 #endif
54 
55 //******************************************************************************
56 //***** Common Info-ZIP UnZip feature/configuration flags
57 //******************************************************************************
58 
59 // Windows CE environment allows support for UTC time stamps
60 #ifndef USE_EF_UT_TIME
61 #define USE_EF_UT_TIME
62 #endif
63 
64 // NTFS extended attributes support is not available on Windows CE
65 #ifndef NO_NTSD_EAS
66 #define NO_NTSD_EAS
67 #endif
68 
69 #ifdef NTSD_EAS
70 #undef NTSD_EAS
71 #endif
72 
73 #ifdef _WIN32_WCE
74 // Windows CE does not provide the rename() function needed for UNIXBACKUP
75 # ifndef NO_UNIXBACKUP
76 #  define NO_UNIXBACKUP
77 # endif
78 # ifdef UNIXBACKUP
79 #  undef UNIXBACKUP
80 # endif
81 #endif
82 
83 #if (!defined(NO_UNICODE_SUPPORT) && !defined(UNICODE_SUPPORT))
84 #define UNICODE_SUPPORT
85 #endif
86 #if (defined(UNICODE_SUPPORT) && !defined(UNICODE_WCHAR))
87 #define UNICODE_WCHAR           /* wchar_t is UTF-16 encoded on WinCE */
88 #endif
89 #ifdef UTF8_MAYBE_NATIVE
90 #undef UTF8_MAYBE_NATIVE        /* UTF-8 cannot be system charset on WinCE */
91 #endif
92 
93 #ifdef POCKET_UNZIP
94 // The PUnZip GUI interface does not make use of ZipInfo style archive
95 // listings.
96 // For the command-line tool, it may be considered to disable ZipInfo, too,
97 // to save memory and resources.
98 # ifndef NO_ZIPINFO
99 # define NO_ZIPINFO
100 # endif
101 #endif
102 
103 #ifndef POCKET_UNZIP
104 // CE does not support exception handling model
105 # define NO_EXCEPT_SIGNALS
106 # define MAIN main_stub
107 #endif
108 
109 //******************************************************************************
110 //***** Global defines, constants, and macros
111 //******************************************************************************
112 
113 #if (defined(_MSC_VER) && !defined(MSC))
114 #define MSC
115 #endif
116 
117 #ifndef PATH_MAX
118 #define PATH_MAX _MAX_PATH
119 #endif
120 
121 // WinCE uses ISO 8859-1 as codepage for 8-bit chars
122 #define CRTL_CP_IS_ISO
123 // The functionality of ISO <--> OEM conversion IS needed on WinCE, too!!
124 // (Otherwise, extended ASCII filenames and passwords in archives coming
125 // from other platforms may not be handled properly.)
126 // Since WinCE does not supply ISO <--> OEM conversion, we try to fall
127 // back to the hardcoded tables in the generic UnZip code.
128 
129 #define ASCII2OEM(c) (((c) & 0x80) ? iso2oem[(c) & 0x7f] : (c))
130 #if !defined(IZ_ISO2OEM_ARRAY)
131 #  define IZ_ISO2OEM_ARRAY
132 #endif
133 #if !defined(CRYP_USES_ISO2OEM)
134 #  define CRYP_USES_ISO2OEM
135 #endif
136 
137 #define OEM_TO_INTERN(src, dst)  {if ((src) != (dst)) strcpy((dst), (src));}
138 #define INTERN_TO_ISO(src, dst)  {if ((src) != (dst)) strcpy((dst), (src));}
139 #define INTERN_TO_OEM(src, dst)  {register uch c;\
140     register uch *dstp = (uch *)(dst), *srcp = (uch *)(src);\
141     do {\
142         c = (uch)foreign(*srcp++);\
143         *dstp++ = (uch)ASCII2OEM(c);\
144     } while (c != '\0');}
145 
146 #if defined(UNICODE)
147 #  define MBSTOTSTR mbstowcs
148 #  define TSTRTOMBS wcstombs
149 #else
150 #  define MBSTOTSTR strncpy
151 #  define TSTRTOMBS strncpy
152 #endif
153 
154 
155 #if (defined(_MBCS) && !defined(_WIN32_WCE))
156    /* MSC-specific version, _mbsinc() may not be available for other systems */
157 #  define CLEN(ptr) _mbclen((const UCHAR *)(ptr))
158 #  define PREINCSTR(ptr) (ptr = (char *)_mbsinc((const UCHAR *)(ptr)))
159 #  define MBSCHR(str, c) (char *)_mbschr((const UCHAR *)(str), (c))
160 #  define MBSRCHR(str, c) (char *)_mbsrchr((const UCHAR *)(str), (c))
161 #endif
162 
163 /* Up to now, all versions of Microsoft C runtime libraries lack the support
164  * for customized (non-US) switching rules between daylight saving time and
165  * standard time in the TZ environment variable string.
166  * But non-US timezone rules are correctly supported when timezone information
167  * is read from the OS system settings in the Win32 registry.
168  * The following work-around deletes any TZ environment setting from
169  * the process environment.  This results in a fallback of the RTL time
170  * handling code to the (correctly interpretable) OS system settings, read
171  * from the registry.
172  */
173 #ifdef USE_EF_UT_TIME
174 # if (defined(_WIN32_WCE) || defined(W32_USE_IZ_TIMEZONE))
175 #   define iz_w32_prepareTZenv()
176 # else
177 #   define iz_w32_prepareTZenv()        putenv("TZ=")
178 # endif
179 #endif
180 
181 #ifdef DIR_END
182 #undef DIR_END
183 #define DIR_END   '\\' // ZipInfo with VC++ 4.0 requires this
184 #endif
185 
186 // We are defining a few new error types for our code.
187 #define PK_EXCEPTION  500
188 #define PK_ABORTED    501
189 
190 #ifndef DATE_FORMAT
191 #define DATE_FORMAT   DF_MDY
192 #endif
193 #if ((_WIN32_WCE >= 211) && !defined(POCKET_UNZIP))
194 # ifndef USE_FWRITE
195 # define USE_FWRITE
196 # endif
197 #endif
198 #define lenEOL        2
199 #define PutNativeEOL  {*q++ = native(CR); *q++ = native(LF);}
200 
201 #define countof(a) (sizeof(a)/sizeof(*(a)))
202 
203 // The max number of retries (not including the first attempt) for entering
204 // a password for and encrypted file before giving up on that file.
205 #define MAX_PASSWORD_RETRIES 2
206 
207 #ifdef POCKET_UNZIP
208 
209 // Variables that we want to add to our Globals struct.
210 #define SYSTEM_SPECIFIC_GLOBALS  \
211    char  matchname[FILNAMSIZ];   \
212    int   notfirstcall;           \
213    char *zipfnPtr;               \
214    char *wildzipfnPtr;
215 
216 #else /* !POCKET_UNZIP */
217 
218 /* Static variables that we have to add to Uz_Globs: */
219 #define SYSTEM_SPECIFIC_GLOBALS \
220     char rootpath[_MAX_PATH];\
221     char *wildname, *matchname;\
222     int rootlen, notfirstcall;
223 
224 /* This replacement for C-RTL-supplied getch() (or similar) functionality
225  * avoids leaving unabsorbed LFs in the keyboard buffer under Windows95,
226  * and supports the <ALT>+[0]<digit><digit><digit> feature.
227  */
228 int getch_win32  OF((void));
229 
230 #endif /* ?POCKET_UNZIP */
231 
232 
233 //******************************************************************************
234 //***** Global headers
235 //******************************************************************************
236 
237 #include <windows.h>
238 #ifndef TIME_ZONE_ID_INVALID
239 #  define TIME_ZONE_ID_INVALID  (DWORD)0xFFFFFFFFL
240 #endif
241 #include <setjmp.h>
242 #include <stdlib.h>
243 #if defined(_MBCS) && !defined(_WIN32_WCE)
244 #include <mbstring.h>
245 #endif
246 #include <excpt.h>
247 #ifndef Cdecl
248 #define Cdecl __cdecl
249 #endif
250 #include "wince/wince.h"     // Our WinCE specific code and our debug function.
251 #ifdef POCKET_UNZIP
252 #include "wince/resource.h"  // Our resource constants
253 #include "wince/punzip.rcv"  // Our version information.
254 #endif
255 
256 
257 #ifndef _WIN32_WCE /* native Windows CE does not support 64-bit filesizes */
258 
259 /* 64-bit-Integers & Large File Support
260  *
261  *  If this is set it is assumed that the port
262  *  supports 64-bit file calls.  The types are
263  *  defined here.  Any local implementations are
264  *  in w32i64.c and the protypes for the calls are
265  *  in unzip.h.  Note that a port must support
266  *  these calls fully or should not set
267  *  LARGE_FILE_SUPPORT.
268  */
269 
270 /* Automatically set ZIP64_SUPPORT if supported */
271 
272 #ifndef NO_ZIP64_SUPPORT
273 # ifndef ZIP64_SUPPORT
274 #   if defined(_MSC_VER)
275 #     define ZIP64_SUPPORT
276 #   endif
277 # endif
278 #endif
279 
280 #ifdef ZIP64_SUPPORT
281   /* base type for file offsets and file sizes */
282 # if (defined(__GNUC__) || defined(ULONG_LONG_MAX))
283     typedef long long    zoff_t;
284 # else
285     /* all other compilers use this as intrinsic 64-bit type */
286     typedef __int64      zoff_t;
287 # endif
288 # define ZOFF_T_DEFINED
289 
290   /* user-defined types and format strings for 64-bit numbers and
291    * file pointer functions  (these depend on the rtl library and library
292    * headers used; they are NOT compiler-specific)
293    */
294 # if defined(_MSC_VER)
295     /* MS C and VC */
296     /* these systems use the Microsoft C RTL */
297 
298     /* 64-bit stat struct */
299     typedef struct _stati64 z_stat;
300 #   define Z_STAT_DEFINED
301 
302     /* printf format size prefix for zoff_t values */
303 #   define FZOFFT_FMT "I64"
304 #   define FZOFFT_HEX_WID_VALUE "16"
305 
306 # endif
307 
308 #endif
309 
310 /* If port has LARGE_FILE_SUPPORT then define here
311    to make automatic unless overridden */
312 
313 #ifndef LARGE_FILE_SUPPORT
314 # ifndef NO_LARGE_FILE_SUPPORT
315 #   if defined(_MSC_VER)
316 #     define LARGE_FILE_SUPPORT
317 #   endif
318 # endif
319 #endif
320 
321 #endif /* !_WIN32_WCE */
322 
323 #endif /* !__w32cfg_h */
324