~peter-pearse/ubuntu/natty/unzip/prop001

« back to all changes in this revision

Viewing changes to windll/windll.c

  • Committer: Bazaar Package Importer
  • Author(s): Santiago Vila
  • Date: 2009-05-08 20:02:40 UTC
  • mfrom: (1.1.2 upstream)
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20090508200240-7l4gypruop5863bd
* New upstream release. Closes: #496989.
* Enabled new Unicode support. Closes: #197427. This may or may not work
  for your already created zipfiles, but it's not a bug unless they were
  created using the Unicode feature present in zip 3.0.
* Built using DATE_FORMAT=DF_YMD so that unzip -l show dates in ISO format,
  as that's the only available one which makes sense. Closes: #312886.
* Enabled new bzip2 support. Closes: #426798.
* Exit code for zipgrep should now be the right one. Closes: #441997.
* The reason why a file may not be created is now shown. Closes: #478791.
* Summary of changes in this version not being the debian/* files:
- Manpages in section 1, not 1L.
- Branding patch. UnZip by Debian. Original by Info-ZIP.
- Always #include <unistd.h>. Debian GNU/kFreeBSD needs it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
  Copyright (c) 1990-2005 Info-ZIP.  All rights reserved.
 
2
  Copyright (c) 1990-2009 Info-ZIP.  All rights reserved.
3
3
 
4
 
  See the accompanying file LICENSE, version 2000-Apr-09 or later
 
4
  See the accompanying file LICENSE, version 2009-Jan-02 or later
5
5
  (the contents of which are also included in unzip.h) for terms of use.
6
6
  If, for some reason, all these files are missing, the Info-ZIP license
7
7
  also may be found at:  ftp://ftp.info-zip.org/pub/infozip/license.html
28
28
 
29
29
  ---------------------------------------------------------------------------*/
30
30
 
 
31
#define __WINDLL_C      /* identifies this source module */
 
32
 
31
33
#define WIN32_LEAN_AND_MEAN
32
 
#include <windows.h>
33
 
#ifdef __RSXNT__
34
 
#  include "../win32/rsxntwin.h"
35
 
#endif
36
 
#ifdef __BORLANDC__
37
 
#include <dir.h>
38
 
#endif
39
34
#define UNZIP_INTERNAL
40
35
#include "../unzip.h"
41
36
#include "../crypt.h"
43
38
#include "../windll/windll.h"
44
39
#include "../windll/structs.h"
45
40
#include "../consts.h"
 
41
#include <malloc.h>
46
42
 
47
43
/* Added type casts to prevent potential "type mismatch" error messages. */
48
44
#ifdef REENTRANT
76
72
/* Dummy sound function for those applications that don't use sound */
77
73
static void WINAPI DummySound(void);
78
74
 
 
75
static int UnzipAllocMemory(unsigned, char *, char *, char ***, unsigned *);
 
76
static int UnzipParseString(LPCSTR, unsigned *, char ***);
 
77
static void UnzipFreeArguments(unsigned, char ***);
 
78
 
79
79
#ifndef UNZIPLIB
80
80
/*  DLL Entry Point */
81
81
 
96
96
#endif
97
97
{
98
98
#ifndef WIN32
99
 
/* The startup code for the DLL initializes the local heap(if there is one)
100
 
 * with a call to LocalInit which locks the data segment.
101
 
 */
 
99
   /* The startup code for the DLL initializes the local heap(if there is one)
 
100
    * with a call to LocalInit which locks the data segment.
 
101
    */
102
102
 
103
 
if ( wHeapSize != 0 )
104
 
   {
105
 
   UnlockData( 0 );
106
 
   }
107
 
hInst = hInstance;
108
 
return 1;   /* Indicate that the DLL was initialized successfully. */
 
103
   if ( wHeapSize != 0 )
 
104
      {
 
105
      UnlockData( 0 );
 
106
      }
 
107
   hInst = hInstance;
 
108
   return 1;   /* Indicate that the DLL was initialized successfully. */
109
109
#else
110
 
BOOL rc = TRUE;
111
 
switch( dwReason )
112
 
   {
113
 
   case DLL_PROCESS_ATTACH:
114
 
      // DLL is loaded. Do your initialization here.
115
 
      // If cannot init, set rc to FALSE.
116
 
      hInst = hInstance;
117
 
      break;
 
110
   BOOL rc = TRUE;
 
111
   switch( dwReason )
 
112
      {
 
113
      case DLL_PROCESS_ATTACH:
 
114
         // DLL is loaded. Do your initialization here.
 
115
         // If cannot init, set rc to FALSE.
 
116
         hInst = hInstance;
 
117
         break;
118
118
 
119
 
   case DLL_PROCESS_DETACH:
120
 
      // DLL is unloaded. Do your cleanup here.
121
 
      break;
122
 
   default:
123
 
      break;
124
 
   }
125
 
return rc;
 
119
      case DLL_PROCESS_DETACH:
 
120
         // DLL is unloaded. Do your cleanup here.
 
121
         break;
 
122
      default:
 
123
         break;
 
124
      }
 
125
   return rc;
126
126
#endif
127
127
}
128
128
 
131
131
#endif
132
132
int FAR PASCAL WEP ( int bSystemExit )
133
133
{
134
 
return 1;
 
134
   return 1;
135
135
}
136
136
#endif /* !UNZIPLIB */
137
137
 
 
138
static int UnzipAllocMemory(unsigned int i, char *cmd, char *str,
 
139
                            char ***pargVee, unsigned int *pargCee)
 
140
{
 
141
    if (((*pargVee)[i] = (char *)malloc(sizeof(char) * strlen(cmd)+1 ))
 
142
        == NULL)
 
143
    {
 
144
        if (pargCee != NULL)
 
145
            (*pargCee)++;
 
146
        UnzipFreeArguments(*pargCee, pargVee);
 
147
        fprintf(stdout, "Unable to allocate memory in unzip library at %s\n",
 
148
                str);
 
149
        return PK_MEM;
 
150
    }
 
151
    strcpy((*pargVee)[i], cmd);
 
152
    (*pargCee)++;
 
153
    return PK_OK;
 
154
}
 
155
 
 
156
static void UnzipFreeArguments(unsigned int argCee, char ***pargVee)
 
157
{
 
158
    unsigned i;
 
159
 
 
160
    /* Free the arguments in the arrays */
 
161
    for (i = 0; i < argCee; i++)
 
162
    {
 
163
        free ((*pargVee)[i]);
 
164
        (*pargVee)[i] = NULL;
 
165
    }
 
166
 
 
167
    /* Then free the arrays themselves */
 
168
    free(*pargVee);
 
169
}
 
170
 
 
171
 
 
172
static int UnzipParseString(LPCSTR s, unsigned int *pargCee, char ***pargVee)
 
173
{
 
174
    unsigned int i = 0;
 
175
    char *str1, *str2, *str3;
 
176
    size_t size;
 
177
 
 
178
    str1 = (char *) malloc(lstrlen(s)+4);
 
179
    lstrcpy(str1, s);
 
180
    lstrcat(str1, " @");
 
181
 
 
182
    str2 = strchr(str1, '\"'); // get first occurance of double quote
 
183
 
 
184
    while ((str3 = strchr(str1, '\t')) != NULL)
 
185
    {
 
186
        str3[0] = ' '; // Change tabs into a single space
 
187
    }
 
188
 
 
189
    /* Note that if a quoted string contains multiple adjacent spaces, they
 
190
       will not be removed, because they could well point to a valid
 
191
       folder/file name.
 
192
     */
 
193
    while ((str2 = strchr(str1, '\"')) != NULL)
 
194
    {
 
195
        // Found an opening double quote; get the corresponding closing quote
 
196
        str3 = strchr(str2+1, '\"');
 
197
        if (str3 == NULL)
 
198
        {
 
199
            free(str1);
 
200
            return PK_PARAM; /* Something is screwy with the
 
201
                                string, bail out */
 
202
        }
 
203
        str3[0] = '\0';  // terminate str2 with a NULL
 
204
 
 
205
        size = _msize(*pargVee);
 
206
        if ((*pargVee = (char **)realloc(*pargVee, size + sizeof(char *)))
 
207
            == NULL)
 
208
        {
 
209
            fprintf(stdout, "Unable to allocate memory in unzip dll\n");
 
210
            return PK_MEM;
 
211
        }
 
212
        // argCee is incremented in UnzipAllocMemory
 
213
        if (UnzipAllocMemory(i, str2+1, "Creating file list from string",
 
214
                             pargVee, pargCee) != PK_OK)
 
215
        {
 
216
            free(str1);
 
217
            return PK_MEM;
 
218
        }
 
219
        i++;
 
220
        str3+=2;  // Point past the whitespace character
 
221
        str2[0] = '\0'; // Terminate str1
 
222
        lstrcat(str1, str3);
 
223
    }    // end while
 
224
 
 
225
    /* points to first occurance of a space */
 
226
    str2 = strchr(str1, ' ');
 
227
 
 
228
    /*  Go through the string character by character, looking for instances
 
229
        of two spaces together. Terminate when you find the trailing @
 
230
    */
 
231
    while ((str2[0] != '\0') && (str2[0] != '@'))
 
232
    {
 
233
        while ((str2[0] == ' ') && (str2[1] == ' '))
 
234
        {
 
235
            str3 = &str2[1];
 
236
            str2[0] = '\0';
 
237
            lstrcat(str1, str3);
 
238
        }
 
239
        str2++;
 
240
    }
 
241
 
 
242
    /* Do we still have a leading space? */
 
243
    if (str1[0] == ' ')
 
244
    {
 
245
        str3 = &str1[1];
 
246
        lstrcpy(str1, str3); // Dump the leading space
 
247
    }
 
248
 
 
249
 
 
250
    /* Okay, now we have gotten rid of any tabs and replaced them with
 
251
       spaces, and have replaced multiple spaces with a single space. We
 
252
       couldn't do this before because the folder names could have actually
 
253
       contained these characters.
 
254
    */
 
255
 
 
256
    str2 = str3 = str1;
 
257
 
 
258
    while ((str2[0] != '\0') && (str3[0] != '@'))
 
259
    {
 
260
        str3 = strchr(str2+1, ' ');
 
261
        str3[0] = '\0';
 
262
        size = _msize(pargVee);
 
263
        if ((*pargVee = (char **)realloc(*pargVee, size + sizeof(char *)))
 
264
            == NULL)
 
265
        {
 
266
            fprintf(stdout, "Unable to allocate memory in unzip dll\n");
 
267
            return PK_MEM;
 
268
        }
 
269
        if (UnzipAllocMemory(i, str2, "Creating file list from string",
 
270
                             pargVee, pargCee) != PK_OK)
 
271
        {
 
272
            free(str1);
 
273
            return PK_MEM;
 
274
        }
 
275
        i++;
 
276
        str3++;
 
277
        str2 = str3;
 
278
    }
 
279
    free(str1);
 
280
    return PK_OK;
 
281
}
 
282
 
138
283
/* DLL calls */
139
284
 
140
285
BOOL WINAPI Wiz_Init(pG, lpUserFunc)
141
286
zvoid *pG;
142
287
LPUSERFUNCTIONS lpUserFunc;
143
288
{
144
 
G.message = DllMessagePrint;
145
 
G.statreportcb = Wiz_StatReportCB;
146
 
if (lpUserFunc->sound == NULL)
147
 
   lpUserFunc->sound = DummySound;
148
 
G.lpUserFunctions = lpUserFunc;
149
 
 
150
 
SETLOCALE(LC_CTYPE, "");
151
 
 
152
 
if (!G.lpUserFunctions->print ||
153
 
    !G.lpUserFunctions->sound ||
154
 
    !G.lpUserFunctions->replace)
155
 
    return FALSE;
156
 
 
157
 
return TRUE;
 
289
    G.message = DllMessagePrint;
 
290
    G.statreportcb = Wiz_StatReportCB;
 
291
    if (lpUserFunc->sound == NULL)
 
292
       lpUserFunc->sound = DummySound;
 
293
    G.lpUserFunctions = lpUserFunc;
 
294
 
 
295
    SETLOCALE(LC_CTYPE, "");
 
296
 
 
297
    if (!G.lpUserFunctions->print ||
 
298
        !G.lpUserFunctions->sound ||
 
299
        !G.lpUserFunctions->replace)
 
300
        return FALSE;
 
301
 
 
302
    return TRUE;
158
303
}
159
304
 
160
305
/*
161
 
    ExtractOnlyNewer  = true for "update" without interaction
 
306
    StructVersID      = version of this structure (= UZ_DCL_STRUCTVER)
 
307
    ExtractOnlyNewer  = TRUE for "update" without interaction
162
308
                        (extract only newer/new files, without queries)
163
 
    SpaceToUnderscore = true if convert space to underscore
164
 
    PromptToOverwrite = true if prompt to overwrite is wanted
 
309
    SpaceToUnderscore = TRUE if convert space to underscore
 
310
    PromptToOverwrite = TRUE if prompt to overwrite is wanted
165
311
    fQuiet            = quiet flag:
166
312
                         0 = all messages, 1 = few messages, 2 = no messages
167
 
    ncflag            = write to stdout if true
 
313
    ncflag            = write to stdout if TRUE
168
314
    ntflag            = test zip file
169
315
    nvflag            = verbose listing
170
316
    nfflag            = "freshen" (replace existing files by newer versions)
173
319
                        0 = junk paths from filenames
174
320
                        1 = "safe" usage of paths in filenames (skip "../")
175
321
                        2 = allow also unsafe path components (dir traversal)
176
 
    noflag            = true if you are to always overwrite existing files
 
322
    noflag            = always overwriting existing files if TRUE
177
323
    naflag            = do end-of-line translation
178
324
    nZIflag           = get ZipInfo if TRUE
 
325
    B_flag            = backup existing files if TRUE
179
326
    C_flag            = be case insensitive if TRUE
 
327
    D_flag            = controls restoration of timestamps
 
328
                        0 = restore all timestamps (default)
 
329
                        1 = skip restoration of timestamps for folders
 
330
                            created on behalf of directory entries in the
 
331
                            Zip archive
 
332
                        2 = do not restore any timestamps; extracted files
 
333
                            and directories get stamped with the current time
 
334
    U_flag            = controls UTF-8 filename coding support
 
335
                        0 = automatic UTF-8 translation enabled (default)
 
336
                        1 = recognize UTF-8 coded names, but all non-ASCII
 
337
                            characters are "escaped" into "#Uxxxx"
 
338
                        2 = UTF-8 support is disabled, filename handling
 
339
                            works exactly as in previous UnZip versions
180
340
    fPrivilege        = 1 => restore ACLs in user mode,
181
341
                        2 => try to use privileges for restoring ACLs
182
342
    lpszZipFN         = zip file name
188
348
zvoid *pG;
189
349
LPDCL lpDCL;
190
350
{
 
351
    if (lpDCL->StructVersID != UZ_DCL_STRUCTVER)
 
352
        return FALSE;
 
353
 
191
354
    uO.qflag = lpDCL->fQuiet;  /* Quiet flag */
192
355
    G.pfnames = (char **)&fnames[0];    /* assign default file name vector */
193
356
    G.pxnames = (char **)&fnames[1];
199
362
    uO.vflag = lpDCL->nvflag;
200
363
    uO.zflag = lpDCL->nzflag;
201
364
    uO.aflag = lpDCL->naflag;
 
365
#ifdef UNIXBACKUP
 
366
    uO.B_flag = lpDCL->B_flag;
 
367
#endif
202
368
    uO.C_flag = lpDCL->C_flag;
 
369
    uO.D_flag = lpDCL->D_flag;
 
370
    uO.U_flag = lpDCL->U_flag;
203
371
    uO.overwrite_all = lpDCL->noflag;
204
372
    uO.overwrite_none = !(lpDCL->noflag || lpDCL->PromptToOverwrite);
205
373
    uO.uflag = lpDCL->ExtractOnlyNewer || lpDCL->nfflag;
238
406
#else
239
407
#  define pExDirRoot lpDCL->lpszExtractDir
240
408
#endif
 
409
       if (strlen(pExDirRoot) >= FILNAMSIZ)
 
410
           {
 
411
           /* The supplied extract root path exceed the filename size limit. */
 
412
#ifndef CRTL_CP_IS_ISO
 
413
           free(pExDirRoot);
 
414
#endif
 
415
           return FALSE;
 
416
           }
241
417
       uO.exdir = pExDirRoot;
242
418
       }
243
419
    else
248
424
/* G.wildzipfn needs to be initialized so that do_wild does not wind
249
425
   up clearing out the zip file name when it returns in process.c
250
426
*/
 
427
    if (strlen(lpDCL->lpszZipFN) >= FILNAMSIZ)
 
428
       /* length of supplied archive name exceed the system's filename limit */
 
429
       return FALSE;
 
430
 
251
431
    hwildZipFN = GlobalAlloc(GPTR, FILNAMSIZ);
252
432
    if (hwildZipFN == (HGLOBAL) NULL)
253
433
       return FALSE;
268
448
    if (hwildZipFN)
269
449
        hwildZipFN = GlobalFree(hwildZipFN);
270
450
 
 
451
#ifndef CRTL_CP_IS_ISO
 
452
    if (uO.exdir != NULL) {
 
453
        free(uO.exdir);
 
454
        uO.exdir = NULL;
 
455
    }
 
456
#endif
 
457
 
271
458
    uO.zipinfo_mode = FALSE;
272
459
}
273
460
 
278
465
int xfnc;
279
466
char **xfnv;
280
467
{
281
 
int retcode, f_cnt;
282
 
#ifndef CRTL_CP_IS_ISO
283
 
char **intern_ifv = NULL, **intern_xfv = NULL;
284
 
#endif
285
 
 
286
 
if (ifnv == (char **)NULL && ifnc != 0)
287
 
    ifnc = 0;
288
 
else
289
 
    for (f_cnt = 0; f_cnt < ifnc; f_cnt++)
290
 
        if (ifnv[f_cnt] == (char *)NULL) {
291
 
            ifnc = f_cnt;
292
 
            break;
293
 
        }
294
 
if (xfnv == (char **)NULL && xfnc != 0)
295
 
    xfnc = 0;
296
 
else
297
 
    for (f_cnt = 0; f_cnt < xfnc; f_cnt++)
298
 
        if (xfnv[f_cnt] == (char *)NULL) {
299
 
            xfnc = f_cnt;
300
 
            break;
301
 
        }
302
 
 
303
 
G.process_all_files = (ifnc == 0 && xfnc == 0);         /* for speed */
304
 
G.filespecs = ifnc;
305
 
G.xfilespecs = xfnc;
306
 
 
307
 
if (ifnc > 0) {
308
 
#ifdef CRTL_CP_IS_ISO
309
 
    G.pfnames = ifnv;
310
 
#else /* !CRTL_CP_IS_ISO */
311
 
    unsigned bufsize = 0;
312
 
 
313
 
    intern_ifv = (char **)malloc((ifnc+1)*sizeof(char **));
314
 
    if (intern_ifv == (char **)NULL)
315
 
        {
 
468
    int retcode, f_cnt;
 
469
#ifndef CRTL_CP_IS_ISO
 
470
    unsigned bufsize;
 
471
    char **intern_ifv = NULL, **intern_xfv = NULL;
 
472
#endif
 
473
 
 
474
    if (ifnv == (char **)NULL && ifnc != 0)
 
475
        ifnc = 0;
 
476
    else
 
477
        for (f_cnt = 0; f_cnt < ifnc; f_cnt++)
 
478
            if (ifnv[f_cnt] == (char *)NULL) {
 
479
                ifnc = f_cnt;
 
480
                break;
 
481
            }
 
482
    if (xfnv == (char **)NULL && xfnc != 0)
 
483
        xfnc = 0;
 
484
    else
 
485
        for (f_cnt = 0; f_cnt < xfnc; f_cnt++)
 
486
            if (xfnv[f_cnt] == (char *)NULL) {
 
487
                xfnc = f_cnt;
 
488
                break;
 
489
            }
 
490
 
 
491
    G.process_all_files = (ifnc == 0 && xfnc == 0);         /* for speed */
 
492
    G.filespecs = ifnc;
 
493
    G.xfilespecs = xfnc;
 
494
 
 
495
    if (ifnc > 0) {
 
496
        for (f_cnt = ifnc; --f_cnt >= 0;)
 
497
            if (strlen(ifnv[f_cnt]) > ((WSIZE>>2) - 160)) {
 
498
                /* include filename pattern is too long for internal buffers */
 
499
                FreeDllMem(__G);
 
500
                return PK_PARAM;
 
501
            }
 
502
 
 
503
#ifdef CRTL_CP_IS_ISO
 
504
        G.pfnames = ifnv;
 
505
#else /* !CRTL_CP_IS_ISO */
 
506
        intern_ifv = (char **)malloc((ifnc+1)*sizeof(char **));
 
507
        if (intern_ifv == (char **)NULL)
 
508
        {
 
509
            FreeDllMem(__G);
 
510
            return PK_BADERR;
 
511
        }
 
512
 
 
513
        bufsize = 0;
 
514
        for (f_cnt = ifnc; --f_cnt >= 0;)
 
515
            bufsize += strlen(ifnv[f_cnt]) + 1;
 
516
        intern_ifv[0] = (char *)malloc(bufsize);
 
517
        if (intern_ifv[0] == (char *)NULL)
 
518
        {
 
519
            free(intern_ifv);
 
520
            FreeDllMem(__G);
 
521
            return PK_BADERR;
 
522
        }
 
523
 
 
524
        for (f_cnt = 0; ; f_cnt++)
 
525
        {
 
526
            ISO_TO_INTERN(ifnv[f_cnt], intern_ifv[f_cnt]);
 
527
            if ((f_cnt+1) >= ifnc)
 
528
                break;
 
529
            intern_ifv[f_cnt+1] = intern_ifv[f_cnt] +
 
530
                                  (strlen(intern_ifv[f_cnt]) + 1);
 
531
        }
 
532
        intern_ifv[ifnc] = (char *)NULL;
 
533
        G.pfnames = intern_ifv;
 
534
#endif /* ?CRTL_CP_IS_ISO */
 
535
    }
 
536
 
 
537
    if (xfnc > 0) {
 
538
        for (f_cnt = xfnc; --f_cnt >= 0;)
 
539
            if (strlen(xfnv[f_cnt]) > ((WSIZE>>2) - 160))
 
540
            {
 
541
                /* exclude filename pattern is too long for internal buffers */
 
542
#ifndef CRTL_CP_IS_ISO
 
543
                if (ifnc > 0)
 
544
                {
 
545
                    free(intern_ifv[0]);
 
546
                    free(intern_ifv);
 
547
                }
 
548
#endif
 
549
                FreeDllMem(__G);
 
550
                return PK_PARAM;
 
551
            }
 
552
 
 
553
#ifdef CRTL_CP_IS_ISO
 
554
        G.pxnames = xfnv;
 
555
#else /* !CRTL_CP_IS_ISO */
 
556
        intern_xfv = (char **)malloc((xfnc+1)*sizeof(char **));
 
557
        if (intern_xfv == (char **)NULL)
 
558
        {
 
559
            if (ifnc > 0)
 
560
            {
 
561
                free(intern_ifv[0]);
 
562
                free(intern_ifv);
 
563
            }
 
564
            FreeDllMem(__G);
 
565
            return PK_BADERR;
 
566
        }
 
567
 
 
568
        bufsize = 0;
 
569
        for (f_cnt = xfnc; --f_cnt >= 0;)
 
570
            bufsize += strlen(xfnv[f_cnt]) + 1;
 
571
        intern_xfv[0] = (char *)malloc(bufsize);
 
572
        if (intern_xfv[0] == (char *)NULL)
 
573
        {
 
574
            free(intern_xfv);
 
575
            if (ifnc > 0)
 
576
            {
 
577
                free(intern_ifv[0]);
 
578
                free(intern_ifv);
 
579
            }
 
580
            FreeDllMem(__G);
 
581
            return PK_BADERR;
 
582
        }
 
583
 
 
584
        for (f_cnt = 0; ; f_cnt++)
 
585
        {
 
586
            ISO_TO_INTERN(xfnv[f_cnt], intern_xfv[f_cnt]);
 
587
            if ((f_cnt+1) >= xfnc)
 
588
                break;
 
589
            intern_xfv[f_cnt+1] = intern_xfv[f_cnt] +
 
590
                                  (strlen(intern_xfv[f_cnt]) + 1);
 
591
        }
 
592
        intern_xfv[xfnc] = (char *)NULL;
 
593
        G.pxnames = intern_xfv;
 
594
#endif /* ?CRTL_CP_IS_ISO */
 
595
    }
 
596
 
 
597
/*---------------------------------------------------------------------------
 
598
    Okey dokey, we have everything we need to get started.  Let's roll.
 
599
  ---------------------------------------------------------------------------*/
 
600
 
 
601
    retcode = setjmp(dll_error_return);
 
602
    if (retcode)
 
603
    {
 
604
#ifndef CRTL_CP_IS_ISO
 
605
        if (xfnc > 0)
 
606
        {
 
607
            free(intern_xfv[0]);
 
608
            free(intern_xfv);
 
609
        }
 
610
        if (ifnc > 0)
 
611
        {
 
612
            free(intern_ifv[0]);
 
613
            free(intern_ifv);
 
614
        }
 
615
#endif
316
616
        FreeDllMem(__G);
317
617
        return PK_BADERR;
318
 
        }
 
618
    }
319
619
 
320
 
    for (f_cnt = ifnc; --f_cnt >= 0;)
321
 
        bufsize += strlen(ifnv[f_cnt]) + 1;
322
 
    intern_ifv[0] = (char *)malloc(bufsize);
323
 
    if (intern_ifv[0] == (char *)NULL)
324
 
        {
 
620
    retcode = process_zipfiles(__G);
 
621
#ifndef CRTL_CP_IS_ISO
 
622
    if (xfnc > 0)
 
623
    {
 
624
        free(intern_xfv[0]);
 
625
        free(intern_xfv);
 
626
    }
 
627
    if (ifnc > 0)
 
628
    {
 
629
        free(intern_ifv[0]);
325
630
        free(intern_ifv);
326
 
        FreeDllMem(__G);
327
 
        return PK_BADERR;
328
 
        }
329
 
 
330
 
    for (f_cnt = 0; ; f_cnt++)
331
 
        {
332
 
        ISO_TO_INTERN(ifnv[f_cnt], intern_ifv[f_cnt]);
333
 
        if ((f_cnt+1) >= ifnc)
334
 
            break;
335
 
        intern_ifv[f_cnt+1] = intern_ifv[f_cnt] +
336
 
                              (strlen(intern_ifv[f_cnt]) + 1);
337
 
        }
338
 
    intern_ifv[ifnc] = (char *)NULL;
339
 
    G.pfnames = intern_ifv;
340
 
#endif /* ?CRTL_CP_IS_ISO */
341
 
    }
342
 
 
343
 
if (xfnc > 0) {
344
 
#ifdef CRTL_CP_IS_ISO
345
 
    G.pxnames = xfnv;
346
 
#else /* !CRTL_CP_IS_ISO */
347
 
    unsigned bufsize = 0;
348
 
 
349
 
    intern_xfv = (char **)malloc((xfnc+1)*sizeof(char **));
350
 
    if (intern_xfv == (char **)NULL)
351
 
        {
352
 
        if (ifnc > 0)
353
 
            {
354
 
            free(intern_ifv[0]);
355
 
            free(intern_ifv);
356
 
            }
357
 
        FreeDllMem(__G);
358
 
        return PK_BADERR;
359
 
        }
360
 
 
361
 
    for (f_cnt = xfnc; --f_cnt >= 0;)
362
 
        bufsize += strlen(xfnv[f_cnt]) + 1;
363
 
    intern_xfv[0] = (char *)malloc(bufsize);
364
 
    if (intern_xfv[0] == (char *)NULL)
365
 
        {
366
 
        free(intern_xfv);
367
 
        if (ifnc > 0)
368
 
            {
369
 
            free(intern_ifv[0]);
370
 
            free(intern_ifv);
371
 
            }
372
 
        FreeDllMem(__G);
373
 
        return PK_BADERR;
374
 
        }
375
 
 
376
 
    for (f_cnt = 0; ; f_cnt++)
377
 
        {
378
 
        ISO_TO_INTERN(xfnv[f_cnt], intern_xfv[f_cnt]);
379
 
        if ((f_cnt+1) >= xfnc)
380
 
            break;
381
 
        intern_xfv[f_cnt+1] = intern_xfv[f_cnt] +
382
 
                              (strlen(intern_xfv[f_cnt]) + 1);
383
 
        }
384
 
    intern_xfv[xfnc] = (char *)NULL;
385
 
    G.pxnames = intern_xfv;
386
 
#endif /* ?CRTL_CP_IS_ISO */
387
 
    }
388
 
 
389
 
/*---------------------------------------------------------------------------
390
 
    Okey dokey, we have everything we need to get started.  Let's roll.
391
 
  ---------------------------------------------------------------------------*/
392
 
 
393
 
retcode = setjmp(dll_error_return);
394
 
if (retcode)
395
 
   {
396
 
#ifndef CRTL_CP_IS_ISO
397
 
   if (xfnc > 0)
398
 
      {
399
 
      free(intern_xfv[0]);
400
 
      free(intern_xfv);
401
 
      }
402
 
   if (ifnc > 0)
403
 
      {
404
 
      free(intern_ifv[0]);
405
 
      free(intern_ifv);
406
 
      }
407
 
#endif
408
 
   FreeDllMem(__G);
409
 
   return PK_BADERR;
410
 
   }
411
 
 
412
 
retcode = process_zipfiles(__G);
413
 
#ifndef CRTL_CP_IS_ISO
414
 
if (xfnc > 0)
415
 
   {
416
 
   free(intern_xfv[0]);
417
 
   free(intern_xfv);
418
 
   }
419
 
if (ifnc > 0)
420
 
   {
421
 
   free(intern_ifv[0]);
422
 
   free(intern_ifv);
423
 
   }
424
 
#endif
425
 
FreeDllMem(__G);
426
 
return retcode;
 
631
    }
 
632
#endif
 
633
    FreeDllMem(__G);
 
634
    return retcode;
427
635
}
428
636
 
429
637
 
 
638
/*
 
639
ifnc       = number of file names being passed. If all files are to be
 
640
             extracted, then this can be zero.
 
641
ifnv       = file names to be unarchived. Wildcard patterns are recognized
 
642
             and expanded. If all files are to be extracted, then this can
 
643
             be NULL.
 
644
xfnc       = number of "file names to be excluded from processing" being
 
645
             passed. If all files are to be extracted, set this to zero.
 
646
xfnv       = file names to be excluded from the unarchiving process. Wildcard
 
647
             characters are allowed and expanded. If all files are to be
 
648
             extracted, set this argument to NULL.
 
649
lpDCL      = pointer to a structure with the flags for setting the
 
650
             various options, as well as the zip file name.
 
651
lpUserFunc = pointer to a structure that contains pointers to functions
 
652
             in the calling application, as well as sizes passed back to
 
653
             the calling application etc.
 
654
*/
 
655
 
430
656
int WINAPI Wiz_SingleEntryUnzip(int ifnc, char **ifnv, int xfnc, char **xfnv,
431
657
   LPDCL lpDCL, LPUSERFUNCTIONS lpUserFunc)
432
658
{
433
 
int retcode;
434
 
CONSTRUCTGLOBALS();
435
 
 
436
 
if (!Wiz_Init((zvoid *)&G, lpUserFunc))
437
 
   {
438
 
   DESTROYGLOBALS();
439
 
   return PK_BADERR;
440
 
   }
441
 
 
442
 
if (lpDCL->lpszZipFN == NULL)
443
 
   {
444
 
   /* Something has screwed up, we don't have a filename */
445
 
   DESTROYGLOBALS();
446
 
   return PK_NOZIP;
447
 
   }
448
 
 
449
 
if (!Wiz_SetOpts((zvoid *)&G, lpDCL))
450
 
   {
451
 
   DESTROYGLOBALS();
452
 
   return PK_MEM;
 
659
   int retcode;
 
660
   CONSTRUCTGLOBALS();
 
661
 
 
662
   if (!Wiz_Init((zvoid *)&G, lpUserFunc))
 
663
   {
 
664
      DESTROYGLOBALS();
 
665
      return PK_BADERR;
 
666
   }
 
667
 
 
668
   if (lpDCL->lpszZipFN == NULL)
 
669
   {
 
670
      /* Something has screwed up, we don't have a filename */
 
671
      DESTROYGLOBALS();
 
672
      return PK_NOZIP;
 
673
   }
 
674
 
 
675
   if (!Wiz_SetOpts((zvoid *)&G, lpDCL))
 
676
   {
 
677
      DESTROYGLOBALS();
 
678
      return PK_MEM;
453
679
   }
454
680
 
455
681
#ifdef SFX
456
 
G.zipfn = lpDCL->lpszZipFN;
457
 
G.argv0 = lpDCL->lpszZipFN;
 
682
   G.zipfn = lpDCL->lpszZipFN;
 
683
   G.argv0 = lpDCL->lpszZipFN;
458
684
#endif
459
685
 
460
 
/* Here is the actual call to "unzip" the files (or whatever else you
461
 
 * are doing.)
462
 
 */
463
 
retcode = Wiz_Unzip((zvoid *)&G, ifnc, ifnv, xfnc, xfnv);
464
 
 
465
 
DESTROYGLOBALS();
466
 
return retcode;
 
686
   /* Here is the actual call to "unzip" the files (or whatever else you
 
687
    * are doing.)
 
688
    */
 
689
   retcode = Wiz_Unzip((zvoid *)&G, ifnc, ifnv, xfnc, xfnv);
 
690
 
 
691
   DESTROYGLOBALS();
 
692
   return retcode;
 
693
}
 
694
 
 
695
 
 
696
/*
 
697
This calling wrapper provided a method to pass file lists as plain strings
 
698
instead of the usual string arrays. For VB Users only...
 
699
ifnc       = number of file names being passed. If all files are to be
 
700
             extracted, then this can be zero.
 
701
ExtList    = Pointer to a list of file names to be extracted, separated by
 
702
             white space. If all files are to be extracted, then this should
 
703
             be NULL. Parameter ifnc should have an accurate count of the
 
704
             number of filenames being passed in.
 
705
xfnc       = number of "file names to be excluded from processing" being
 
706
             passed. If all files are to be extracted, set this to zero.
 
707
ExcList    = Pointer to a list of file names to be excluded from processing.
 
708
             Parameter xfnc should have an accurate count of the number of
 
709
             the number of filenames being passed in.
 
710
lpDCL      = pointer to a structure with the flags for setting the
 
711
             various options, as well as the zip file name.
 
712
lpUserFunc = pointer to a structure that contains pointers to functions
 
713
             in the calling application, as well as sizes passed back to
 
714
             the calling application etc.
 
715
*/
 
716
 
 
717
int WINAPI Wiz_SingleEntryUnzpList(unsigned int ifnc, LPCSTR ExtList,
 
718
   unsigned int xfnc, LPCSTR ExcList,
 
719
   LPDCL lpDCL, LPUSERFUNCTIONS lpUserFunc)
 
720
{
 
721
    int retcode;
 
722
    char **argVExt, **argVExc;
 
723
    unsigned int argCExt, argCExc;
 
724
 
 
725
    argCExt = argCExc = 0;
 
726
 
 
727
    if (ExtList != NULL)
 
728
    {
 
729
        if ((argVExt = (char **)malloc((ifnc)*sizeof(char *))) == NULL)
 
730
        {
 
731
            fprintf(stdout, "Unable to allocate memory in unzip dll\n");
 
732
            return PK_MEM;
 
733
        }
 
734
        if ((retcode = UnzipParseString(ExtList, &argCExt, &argVExt)) != PK_OK)
 
735
            return retcode;
 
736
    }
 
737
 
 
738
    if (ExcList != NULL)
 
739
    {
 
740
        if ((argVExc = (char **)malloc((ifnc)*sizeof(char *))) == NULL)
 
741
        {
 
742
            fprintf(stdout, "Unable to allocate memory in unzip dll\n");
 
743
            UnzipFreeArguments(argCExt, &argVExt);
 
744
            return PK_MEM;
 
745
        }
 
746
        if ((retcode = UnzipParseString(ExcList, &argCExc, &argVExc)) != PK_OK)
 
747
        {
 
748
            UnzipFreeArguments(argCExt, &argVExt);
 
749
            return retcode;
 
750
        }
 
751
    }
 
752
 
 
753
    retcode = Wiz_SingleEntryUnzip(argCExt, argVExt, argCExc, argVExc,
 
754
                                   lpDCL, lpUserFunc);
 
755
    UnzipFreeArguments(argCExc, &argVExc);
 
756
    UnzipFreeArguments(argCExt, &argVExt);
 
757
    return retcode;
467
758
}
468
759
 
469
760
 
470
761
int win_fprintf(zvoid *pG, FILE *file, unsigned int size, char far *buffer)
471
762
{
472
 
if ((file != stderr) && (file != stdout))
 
763
   if ((file != stderr) && (file != stdout))
473
764
   {
474
 
   return write(fileno(file),(char far *)(buffer),size);
 
765
      return write(fileno(file),(char far *)(buffer),size);
475
766
   }
476
 
if (!fNoPrinting)
477
 
   return G.lpUserFunctions->print((LPSTR)buffer, size);
478
 
return (int)size;
 
767
   if (!fNoPrinting)
 
768
      return G.lpUserFunctions->print((LPSTR)buffer, size);
 
769
   return (int)size;
479
770
}
480
771
 
481
772
/**********************************
492
783
    ulg size;       /* length of string (may include nulls) */
493
784
    int flag;       /* flag bits */
494
785
{
495
 
if (!fNoPrinting)
496
 
   return G.lpUserFunctions->print((LPSTR)buf, size);
497
 
else
498
 
   return (int)size;
 
786
    if (!fNoPrinting)
 
787
        return G.lpUserFunctions->print((LPSTR)buf, size);
 
788
    else
 
789
        return (int)size;
499
790
}
500
791
 
501
792
#if 0 /* currently unused */
513
804
    ulg size;       /* length of string (may include nulls) */
514
805
    int flag;       /* flag bits */
515
806
{
516
 
return (!fNoPrinting ? G.lpUserFunctions->print((LPSTR)buf, size) : (int)size);
 
807
    return (!fNoPrinting
 
808
            ? G.lpUserFunctions->print((LPSTR)buf, size)
 
809
            : (int)size);
517
810
}
518
811
#endif /* never */
519
812
 
535
828
    ZCONST char *efn;   /* name of archiv entry being processed */
536
829
{
537
830
#if CRYPT
538
 
    LPSTR m;
 
831
    LPCSTR m;
539
832
 
540
833
    if (*rcnt == 0) {
541
834
        *rcnt = 2;
545
838
        m = "Password incorrect--reenter: ";
546
839
    }
547
840
 
548
 
    return (*G.lpUserFunctions->password)((LPSTR)pwbuf, size, m, (LPSTR)efn);
 
841
    return (*G.lpUserFunctions->password)((LPSTR)pwbuf, size, m, (LPCSTR)efn);
549
842
#else /* !CRYPT */
550
843
    return IZ_PW_ERROR; /* internal error, function should never get called */
551
844
#endif /* ?CRYPT */
554
847
/* Turn off all messages to the calling application */
555
848
void WINAPI Wiz_NoPrinting(int f)
556
849
{
557
 
fNoPrinting = f;
 
850
    fNoPrinting = f;
558
851
}
559
852
 
560
853
/* Dummy sound function for those applications that don't use sound */
581
874
        if ((G.lpUserFunctions->ServCallBk != NULL) &&
582
875
            (*G.lpUserFunctions->ServCallBk)(efn,
583
876
                                             (details == NULL ? 0L :
584
 
                                              *((unsigned long *)details))))
 
877
#ifdef Z_UINT8_DEFINED
 
878
                                              (z_uint8)(*((zusz_t *)details))
 
879
#else
 
880
                                              *((zusz_t *)details)
 
881
#endif
 
882
                                             )))
585
883
            rval = UZ_ST_BREAK;
 
884
        else if (G.lpUserFunctions->ServCallBk_i32 != NULL) {
 
885
             unsigned long siz_u4L = 0L;
 
886
             unsigned long siz_u4H = 0L;
 
887
             if (details != NULL) {
 
888
                 siz_u4L = (unsigned long)(*(zusz_t *)details);
 
889
#ifdef ZIP64_SUPPORT
 
890
                 siz_u4H = (unsigned long)((*(zusz_t *)details) >> 32);
 
891
#endif
 
892
             }
 
893
             if ((*G.lpUserFunctions->ServCallBk_i32)(efn, siz_u4L, siz_u4H))
 
894
                 rval = UZ_ST_BREAK;
 
895
        }
586
896
        break;
587
897
      case UZ_ST_IN_PROGRESS:
588
898
        break;
651
961
 
652
962
   Parameters: archive  = archive name
653
963
               file     = file contained in the archive. This cannot be
654
 
                          a wild card to be meaningful
 
964
                          a wildcard to be meaningful
655
965
               pattern  = string to search for
656
966
               cmd      = 0 - case-insensitive search
657
967
                          1 - case-sensitve search