132
132
int FAR PASCAL WEP ( int bSystemExit )
136
136
#endif /* !UNZIPLIB */
138
static int UnzipAllocMemory(unsigned int i, char *cmd, char *str,
139
char ***pargVee, unsigned int *pargCee)
141
if (((*pargVee)[i] = (char *)malloc(sizeof(char) * strlen(cmd)+1 ))
146
UnzipFreeArguments(*pargCee, pargVee);
147
fprintf(stdout, "Unable to allocate memory in unzip library at %s\n",
151
strcpy((*pargVee)[i], cmd);
156
static void UnzipFreeArguments(unsigned int argCee, char ***pargVee)
160
/* Free the arguments in the arrays */
161
for (i = 0; i < argCee; i++)
163
free ((*pargVee)[i]);
164
(*pargVee)[i] = NULL;
167
/* Then free the arrays themselves */
172
static int UnzipParseString(LPCSTR s, unsigned int *pargCee, char ***pargVee)
175
char *str1, *str2, *str3;
178
str1 = (char *) malloc(lstrlen(s)+4);
182
str2 = strchr(str1, '\"'); // get first occurance of double quote
184
while ((str3 = strchr(str1, '\t')) != NULL)
186
str3[0] = ' '; // Change tabs into a single space
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
193
while ((str2 = strchr(str1, '\"')) != NULL)
195
// Found an opening double quote; get the corresponding closing quote
196
str3 = strchr(str2+1, '\"');
200
return PK_PARAM; /* Something is screwy with the
203
str3[0] = '\0'; // terminate str2 with a NULL
205
size = _msize(*pargVee);
206
if ((*pargVee = (char **)realloc(*pargVee, size + sizeof(char *)))
209
fprintf(stdout, "Unable to allocate memory in unzip dll\n");
212
// argCee is incremented in UnzipAllocMemory
213
if (UnzipAllocMemory(i, str2+1, "Creating file list from string",
214
pargVee, pargCee) != PK_OK)
220
str3+=2; // Point past the whitespace character
221
str2[0] = '\0'; // Terminate str1
225
/* points to first occurance of a space */
226
str2 = strchr(str1, ' ');
228
/* Go through the string character by character, looking for instances
229
of two spaces together. Terminate when you find the trailing @
231
while ((str2[0] != '\0') && (str2[0] != '@'))
233
while ((str2[0] == ' ') && (str2[1] == ' '))
242
/* Do we still have a leading space? */
246
lstrcpy(str1, str3); // Dump the leading space
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.
258
while ((str2[0] != '\0') && (str3[0] != '@'))
260
str3 = strchr(str2+1, ' ');
262
size = _msize(pargVee);
263
if ((*pargVee = (char **)realloc(*pargVee, size + sizeof(char *)))
266
fprintf(stdout, "Unable to allocate memory in unzip dll\n");
269
if (UnzipAllocMemory(i, str2, "Creating file list from string",
270
pargVee, pargCee) != PK_OK)
140
285
BOOL WINAPI Wiz_Init(pG, lpUserFunc)
142
287
LPUSERFUNCTIONS lpUserFunc;
144
G.message = DllMessagePrint;
145
G.statreportcb = Wiz_StatReportCB;
146
if (lpUserFunc->sound == NULL)
147
lpUserFunc->sound = DummySound;
148
G.lpUserFunctions = lpUserFunc;
150
SETLOCALE(LC_CTYPE, "");
152
if (!G.lpUserFunctions->print ||
153
!G.lpUserFunctions->sound ||
154
!G.lpUserFunctions->replace)
289
G.message = DllMessagePrint;
290
G.statreportcb = Wiz_StatReportCB;
291
if (lpUserFunc->sound == NULL)
292
lpUserFunc->sound = DummySound;
293
G.lpUserFunctions = lpUserFunc;
295
SETLOCALE(LC_CTYPE, "");
297
if (!G.lpUserFunctions->print ||
298
!G.lpUserFunctions->sound ||
299
!G.lpUserFunctions->replace)
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)
282
#ifndef CRTL_CP_IS_ISO
283
char **intern_ifv = NULL, **intern_xfv = NULL;
286
if (ifnv == (char **)NULL && ifnc != 0)
289
for (f_cnt = 0; f_cnt < ifnc; f_cnt++)
290
if (ifnv[f_cnt] == (char *)NULL) {
294
if (xfnv == (char **)NULL && xfnc != 0)
297
for (f_cnt = 0; f_cnt < xfnc; f_cnt++)
298
if (xfnv[f_cnt] == (char *)NULL) {
303
G.process_all_files = (ifnc == 0 && xfnc == 0); /* for speed */
308
#ifdef CRTL_CP_IS_ISO
310
#else /* !CRTL_CP_IS_ISO */
311
unsigned bufsize = 0;
313
intern_ifv = (char **)malloc((ifnc+1)*sizeof(char **));
314
if (intern_ifv == (char **)NULL)
469
#ifndef CRTL_CP_IS_ISO
471
char **intern_ifv = NULL, **intern_xfv = NULL;
474
if (ifnv == (char **)NULL && ifnc != 0)
477
for (f_cnt = 0; f_cnt < ifnc; f_cnt++)
478
if (ifnv[f_cnt] == (char *)NULL) {
482
if (xfnv == (char **)NULL && xfnc != 0)
485
for (f_cnt = 0; f_cnt < xfnc; f_cnt++)
486
if (xfnv[f_cnt] == (char *)NULL) {
491
G.process_all_files = (ifnc == 0 && xfnc == 0); /* for speed */
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 */
503
#ifdef CRTL_CP_IS_ISO
505
#else /* !CRTL_CP_IS_ISO */
506
intern_ifv = (char **)malloc((ifnc+1)*sizeof(char **));
507
if (intern_ifv == (char **)NULL)
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)
524
for (f_cnt = 0; ; f_cnt++)
526
ISO_TO_INTERN(ifnv[f_cnt], intern_ifv[f_cnt]);
527
if ((f_cnt+1) >= ifnc)
529
intern_ifv[f_cnt+1] = intern_ifv[f_cnt] +
530
(strlen(intern_ifv[f_cnt]) + 1);
532
intern_ifv[ifnc] = (char *)NULL;
533
G.pfnames = intern_ifv;
534
#endif /* ?CRTL_CP_IS_ISO */
538
for (f_cnt = xfnc; --f_cnt >= 0;)
539
if (strlen(xfnv[f_cnt]) > ((WSIZE>>2) - 160))
541
/* exclude filename pattern is too long for internal buffers */
542
#ifndef CRTL_CP_IS_ISO
553
#ifdef CRTL_CP_IS_ISO
555
#else /* !CRTL_CP_IS_ISO */
556
intern_xfv = (char **)malloc((xfnc+1)*sizeof(char **));
557
if (intern_xfv == (char **)NULL)
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)
584
for (f_cnt = 0; ; f_cnt++)
586
ISO_TO_INTERN(xfnv[f_cnt], intern_xfv[f_cnt]);
587
if ((f_cnt+1) >= xfnc)
589
intern_xfv[f_cnt+1] = intern_xfv[f_cnt] +
590
(strlen(intern_xfv[f_cnt]) + 1);
592
intern_xfv[xfnc] = (char *)NULL;
593
G.pxnames = intern_xfv;
594
#endif /* ?CRTL_CP_IS_ISO */
597
/*---------------------------------------------------------------------------
598
Okey dokey, we have everything we need to get started. Let's roll.
599
---------------------------------------------------------------------------*/
601
retcode = setjmp(dll_error_return);
604
#ifndef CRTL_CP_IS_ISO
317
617
return PK_BADERR;
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)
620
retcode = process_zipfiles(__G);
621
#ifndef CRTL_CP_IS_ISO
325
630
free(intern_ifv);
330
for (f_cnt = 0; ; f_cnt++)
332
ISO_TO_INTERN(ifnv[f_cnt], intern_ifv[f_cnt]);
333
if ((f_cnt+1) >= ifnc)
335
intern_ifv[f_cnt+1] = intern_ifv[f_cnt] +
336
(strlen(intern_ifv[f_cnt]) + 1);
338
intern_ifv[ifnc] = (char *)NULL;
339
G.pfnames = intern_ifv;
340
#endif /* ?CRTL_CP_IS_ISO */
344
#ifdef CRTL_CP_IS_ISO
346
#else /* !CRTL_CP_IS_ISO */
347
unsigned bufsize = 0;
349
intern_xfv = (char **)malloc((xfnc+1)*sizeof(char **));
350
if (intern_xfv == (char **)NULL)
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)
376
for (f_cnt = 0; ; f_cnt++)
378
ISO_TO_INTERN(xfnv[f_cnt], intern_xfv[f_cnt]);
379
if ((f_cnt+1) >= xfnc)
381
intern_xfv[f_cnt+1] = intern_xfv[f_cnt] +
382
(strlen(intern_xfv[f_cnt]) + 1);
384
intern_xfv[xfnc] = (char *)NULL;
385
G.pxnames = intern_xfv;
386
#endif /* ?CRTL_CP_IS_ISO */
389
/*---------------------------------------------------------------------------
390
Okey dokey, we have everything we need to get started. Let's roll.
391
---------------------------------------------------------------------------*/
393
retcode = setjmp(dll_error_return);
396
#ifndef CRTL_CP_IS_ISO
412
retcode = process_zipfiles(__G);
413
#ifndef CRTL_CP_IS_ISO
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
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.
430
656
int WINAPI Wiz_SingleEntryUnzip(int ifnc, char **ifnv, int xfnc, char **xfnv,
431
657
LPDCL lpDCL, LPUSERFUNCTIONS lpUserFunc)
436
if (!Wiz_Init((zvoid *)&G, lpUserFunc))
442
if (lpDCL->lpszZipFN == NULL)
444
/* Something has screwed up, we don't have a filename */
449
if (!Wiz_SetOpts((zvoid *)&G, lpDCL))
662
if (!Wiz_Init((zvoid *)&G, lpUserFunc))
668
if (lpDCL->lpszZipFN == NULL)
670
/* Something has screwed up, we don't have a filename */
675
if (!Wiz_SetOpts((zvoid *)&G, lpDCL))
456
G.zipfn = lpDCL->lpszZipFN;
457
G.argv0 = lpDCL->lpszZipFN;
682
G.zipfn = lpDCL->lpszZipFN;
683
G.argv0 = lpDCL->lpszZipFN;
460
/* Here is the actual call to "unzip" the files (or whatever else you
463
retcode = Wiz_Unzip((zvoid *)&G, ifnc, ifnv, xfnc, xfnv);
686
/* Here is the actual call to "unzip" the files (or whatever else you
689
retcode = Wiz_Unzip((zvoid *)&G, ifnc, ifnv, xfnc, xfnv);
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.
717
int WINAPI Wiz_SingleEntryUnzpList(unsigned int ifnc, LPCSTR ExtList,
718
unsigned int xfnc, LPCSTR ExcList,
719
LPDCL lpDCL, LPUSERFUNCTIONS lpUserFunc)
722
char **argVExt, **argVExc;
723
unsigned int argCExt, argCExc;
725
argCExt = argCExc = 0;
729
if ((argVExt = (char **)malloc((ifnc)*sizeof(char *))) == NULL)
731
fprintf(stdout, "Unable to allocate memory in unzip dll\n");
734
if ((retcode = UnzipParseString(ExtList, &argCExt, &argVExt)) != PK_OK)
740
if ((argVExc = (char **)malloc((ifnc)*sizeof(char *))) == NULL)
742
fprintf(stdout, "Unable to allocate memory in unzip dll\n");
743
UnzipFreeArguments(argCExt, &argVExt);
746
if ((retcode = UnzipParseString(ExcList, &argCExc, &argVExc)) != PK_OK)
748
UnzipFreeArguments(argCExt, &argVExt);
753
retcode = Wiz_SingleEntryUnzip(argCExt, argVExt, argCExc, argVExc,
755
UnzipFreeArguments(argCExc, &argVExc);
756
UnzipFreeArguments(argCExt, &argVExt);
470
761
int win_fprintf(zvoid *pG, FILE *file, unsigned int size, char far *buffer)
472
if ((file != stderr) && (file != stdout))
763
if ((file != stderr) && (file != stdout))
474
return write(fileno(file),(char far *)(buffer),size);
765
return write(fileno(file),(char far *)(buffer),size);
477
return G.lpUserFunctions->print((LPSTR)buffer, size);
768
return G.lpUserFunctions->print((LPSTR)buffer, size);
481
772
/**********************************