2
Copyright (c) 1990-2001 Info-ZIP. All rights reserved.
4
See the accompanying file LICENSE, version 2000-Apr-09 or later
5
(the contents of which are also included in zip.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
9
/*---------------------------------------------------------------------------
13
Some useful functions Used by unzip and zip.
15
---------------------------------------------------------------------------*/
17
/*****************************************************************************/
19
/*****************************************************************************/
31
/*****************************************************************************/
33
/*****************************************************************************/
37
extern char MacPathEnd;
38
extern char *zipfile; /* filename of the Zipfile */
39
extern char *tempzip; /* Temporary zip file name */
40
extern ZCONST unsigned char MacRoman_to_WinCP1252[128];
43
static char argStr[1024];
44
static char *argv[MAX_ARGS + 1];
48
/*****************************************************************************/
50
/*****************************************************************************/
54
** Copy a C string to a Pascal string
58
unsigned char *CToPCpy(unsigned char *pstr, char *cstr)
61
register unsigned len;
65
while (len<255 && (*dptr++ = *cstr++)!='\0') ++len;
66
*pstr= (unsigned char)len;
72
** Copy a Pascal string to a C string
76
char *PToCCpy(unsigned char *pstr, char *cstr)
78
strncpy(cstr, (char *) &pstr[1], *pstr);
79
cstr[pstr[0]] = '\0'; /* set endmarker for c-string */
85
** strcpy() and strcat() work-alikes which allow overlapping buffers.
88
char *sstrcpy(char *to,const char *from)
90
memmove(to, from, 1+strlen(from));
94
char *sstrcat(char *to,const char *from)
96
sstrcpy(to + strlen(to), from);
103
** Alloc memory and init it
107
char *StrCalloc(unsigned short size)
111
if ((strPtr = calloc(size, sizeof(char))) == NULL)
112
printerr("StrCalloc failed:", -1, size, __LINE__, __FILE__, "");
114
Assert_it(strPtr,"strPtr == NULL","")
121
** Release only non NULL pointers
125
char *StrFree(char *strPtr)
140
** Return a value in a binary string
144
char *sBit2Str(unsigned short value)
146
static char str[sizeof(value)*8];
152
j = strwid - (biz + (biz >> 2)- (biz % 4 ? 0 : 1));
154
for (i = 0; i < j; i++) {
159
*tempPtr++ = ((value >> biz) & 1) + '0';
160
if (!(biz % 4) && biz) {
173
** Parse commandline style arguments
177
int ParseArguments(char *s, char ***arg)
179
int n = 1, Quote = 0;
182
argv[0] = GetAppName();
186
p1 = (char *) argStr;
187
while ((c = *p++) != 0) {
188
if (c==' ') continue;
196
if ((c=='"') || (c == '\'')) {
207
} while (*p && ((c = *p++) != ' ' || Quote));
216
** Print commandline style arguments
220
void PrintArguments(int argc, char **argv)
223
printf("\n Arguments:");
224
printf("\n --------------------------");
227
printf("\n argc: %d argv: [%s]", argc, &*argv[argc]);
229
printf("\n --------------------------\n\n");
236
** return some error-msg on file-system
240
int PrintUserHFSerr(int cond, int err, char *msg2)
249
msg = "No such Volume";
253
msg = "No such Drive";
257
msg = "Bad Volume Name";
261
msg = "File is already open for writing";
265
msg = "Directory/File not found";
269
msg = "Directory/File not found or incomplete pathname";
274
fprintf(stderr, "\n\n Error: %s ->%s", msg, msg2);
284
** Check mounted volumes and return number of volumes
285
** with the same name.
288
short CheckMountedVolumes(char *FullPath)
290
FSSpec volumes[50]; /* 50 Volumes should be enough */
291
char VolumeName[257], volume[257];
292
short actVolCount, volIndex = 1, VolCount = 0;
296
GetVolumeFromPath(FullPath, VolumeName);
298
err = OnLine(volumes, 50, &actVolCount, &volIndex);
299
printerr("OnLine:", (err != -35) && (err != 0), err, __LINE__, __FILE__, "");
301
for (i=0; i < actVolCount; i++)
303
PToCCpy(volumes[i].name,volume);
304
if (stricmp(volume, VolumeName) == 0) VolCount++;
306
printerr("OnLine: ", (VolCount == 0), VolCount, __LINE__, __FILE__, FullPath);
319
** compares strings, ignoring differences in case
323
int stricmp(const char *p1, const char *p2)
331
if (isalpha(*p1) && isalpha(*p2))
333
diff = toupper(*p1) - toupper(*p2);
334
if (diff) return diff;
347
** Convert the MacOS-Strings (Filenames/Findercomments) to a most compatible.
348
** These strings will be stored in the public area of the zip-archive.
349
** Every foreign platform (outside macos) will access these strings
353
void MakeCompatibleString(char *MacOS_Str,
354
const char SpcChar1, const char SpcChar2,
355
const char SpcChar3, const char SpcChar4,
356
short CurrTextEncodingBase)
361
Assert_it(MacOS_Str,"MakeCompatibleString MacOS_Str == NULL","")
362
for (tmpPtr = MacOS_Str; (curch = *tmpPtr) != '\0'; tmpPtr++)
364
if (curch == SpcChar1)
367
if (curch == SpcChar3)
370
/* now convert from MacRoman to ISO-8859-1 */
371
/* but convert only if MacRoman is activ */
372
if ((CurrTextEncodingBase == kTextEncodingMacRoman) &&
375
*tmpPtr = (char)MacRoman_to_WinCP1252[curch - 128];
383
Boolean CheckForSwitch(char *Switch, int argc, char **argv)
385
char *p; /* steps through option arguments */
386
int i; /* arg counter, root directory flag */
388
for (i = 1; i < argc; i++)
390
if (argv[i][0] == '-')
394
for (p = argv[i]+1; *p; p++)
400
if ((Switch[1] != NULL) &&
401
((*p == Switch[0]) && (*p == Switch[1])))
419
#if (defined(USE_SIOUX) || defined(MACUNZIP_STANDALONE))
422
** checks the condition and returns an error-msg
423
** this function is for internal use only
426
OSErr printerr(const char *msg, int cond, int err, int line, char *file,
432
fprintf(stderr, "\nint err: %d: %s %d [%d/%s] {%s}\n", clock(), msg, err,
442
Not Implemented for metrowerks SIOUX
445
void leftStatusString(char *status)
451
void rightStatusString(char *status)
458
void DoWarnUserDupVol( char *FullPath )
461
GetVolumeFromPath(FullPath, VolName);
463
printf("\n There are more than one volume that has the same name !!\n");
465
printf("\n Volume: %s\n",VolName);
467
printf("\n This port has one weak point:");
468
printf("\n It is based on pathnames. As you may be already know:");
469
printf("\n Pathnames are not unique on a Mac !");
470
printf("\n MacZip has problems to find the correct location of");
471
printf("\n the archive or the files.\n");
473
printf("\n My (Big) recommendation: Name all your volumes with an");
474
printf("\n unique name and MacZip will run without any problem.");