~ubuntu-branches/ubuntu/precise/boinc/precise

« back to all changes in this revision

Viewing changes to zip/zip/macos/source/macos.c

Tags: 6.12.8+dfsg-1
* New upstream release.
* Simplified debian/rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
  Copyright (c) 1990-1999 Info-ZIP.  All rights reserved.
3
 
 
4
 
  See the accompanying file LICENSE, version 1999-Oct-05 or later
5
 
  (the contents of which are also included in zip.h) for terms of use.
6
 
  If, for some reason, both of these files are missing, the Info-ZIP license
7
 
  also may be found at:  ftp://ftp.cdrom.com/pub/infozip/license.html
8
 
*/
9
 
/*---------------------------------------------------------------------------
10
 
 
11
 
  macos.c
12
 
 
13
 
  Macintosh-specific routines for use with Info-ZIP's Zip 2.3 and later.
14
 
 
15
 
  ---------------------------------------------------------------------------*/
16
 
 
17
 
 
18
 
/*****************************************************************************/
19
 
/*  Includes                                                                 */
20
 
/*****************************************************************************/
21
 
 
22
 
#include "zip.h"
23
 
 
24
 
#include "revision.h"
25
 
#include "z_crypt.h"
26
 
 
27
 
#include <signal.h>
28
 
#include <stdio.h>
29
 
#include <stdlib.h>
30
 
#include <sound.h>
31
 
 
32
 
#include <unistd.h>
33
 
 
34
 
#include <Strings.h>
35
 
#include <setjmp.h>
36
 
 
37
 
/* #include "charmap.h" */
38
 
#include "helpers.h"
39
 
#include "macstuff.h"
40
 
#include "pathname.h"
41
 
#include "recurse.h"
42
 
 
43
 
 
44
 
/*****************************************************************************/
45
 
/*  Macros, typedefs                                                         */
46
 
/*****************************************************************************/
47
 
 
48
 
#define PATH_END   MacPathEnd
49
 
 
50
 
/*****************************************************************************/
51
 
/*  Global Vars                                                              */
52
 
/*****************************************************************************/
53
 
 
54
 
int error_level;   /* used only in ziperr() */
55
 
 
56
 
 
57
 
/*  Note: sizeof() returns the size of this allusion
58
 
          13 is current length of "XtraStuf.mac:"      */
59
 
extern const char ResourceMark[13]; /* var is initialized in file pathname.c */
60
 
 
61
 
 
62
 
extern jmp_buf EnvForExit;
63
 
MacZipGlobals   MacZip;
64
 
 
65
 
unsigned long count_of_Zippedfiles = 0;
66
 
 
67
 
 
68
 
/*****************************************************************************/
69
 
/*  Module level Vars                                                        */
70
 
/*****************************************************************************/
71
 
 
72
 
static const char MacPathEnd = ':';   /* the Macintosh dir separator */
73
 
 
74
 
/*  Inform Progress vars */
75
 
long    estTicksToFinish;
76
 
long    createTime;
77
 
long    updateTicks;
78
 
 
79
 
static char *Time_Est_strings[] = {
80
 
        "Zipping Files; Items done:",
81
 
        "More than 24 hours",
82
 
        "More than %s hours",
83
 
        "About %s hours, %s minutes",
84
 
        "About an hour",
85
 
        "Less than an hour",
86
 
        "About %s minutes, %s seconds",
87
 
        "About a minute",
88
 
        "Less than a minute",
89
 
        "About %s seconds",
90
 
        "About a second",
91
 
        "About 1 minute, %s seconds"};
92
 
 
93
 
 
94
 
 
95
 
/*****************************************************************************/
96
 
/*  Prototypes                                                               */
97
 
/*****************************************************************************/
98
 
 
99
 
int DoCurrentDir(void);
100
 
 
101
 
void DoAboutBox(void);
102
 
void DoQuit(void);
103
 
void DoEventLoop(void);
104
 
 
105
 
void ZipInitAllVars(void);
106
 
void UserStop(void);
107
 
Boolean IsZipFile(char *name);
108
 
 
109
 
static long EstimateCompletionTime(const long progressMax,
110
 
                            const long progressSoFar, unsigned char percent);
111
 
static void UpdateTimeToComplete(void);
112
 
 
113
 
 
114
 
 
115
 
 
116
 
#ifdef USE_SIOUX
117
 
#include <sioux.h>
118
 
void DoWarnUserDupVol( char *FullPath );
119
 
 
120
 
/*****************************************************************************/
121
 
/*  Functions                                                                */
122
 
/*****************************************************************************/
123
 
 
124
 
/*
125
 
** Standalone Unzip with Metrowerks SIOUX starts here
126
 
**
127
 
*/
128
 
int main(int argc, char **argv)
129
 
{
130
 
    int return_code;
131
 
 
132
 
    SIOUXSettings.asktosaveonclose = FALSE;
133
 
    SIOUXSettings.showstatusline = TRUE;
134
 
 
135
 
    SIOUXSettings.columns = 100;
136
 
    SIOUXSettings.rows    = 40;
137
 
 
138
 
    /* 30 = MacZip Johnny Lee's; 40 = new (my) MacZip */
139
 
    MacZip.MacZipMode = NewZipMode_EF;
140
 
 
141
 
    argc = ccommand(&argv);
142
 
    if (verbose) PrintArguments(argc, argv);
143
 
 
144
 
    ZipInitAllVars();
145
 
 
146
 
    return_code = zipmain(argc, argv);
147
 
 
148
 
    if (verbose) printf("\n\n Finish");
149
 
    return return_code;
150
 
}
151
 
 
152
 
 
153
 
 
154
 
/*
155
 
** SIOUX needs no extra event handling
156
 
**
157
 
*/
158
 
 
159
 
void UserStop(void)
160
 
{
161
 
};
162
 
 
163
 
 
164
 
 
165
 
 
166
 
/*
167
 
** Password enter function '*' printed for each char
168
 
**
169
 
*/
170
 
 
171
 
int macgetch(void)
172
 
{
173
 
    WindowPtr whichWindow;
174
 
    EventRecord theEvent;
175
 
    char c;                     /* one-byte buffer for read() to use */
176
 
 
177
 
    do {
178
 
        SystemTask();
179
 
        if (!GetNextEvent(everyEvent, &theEvent))
180
 
            theEvent.what = nullEvent;
181
 
        else {
182
 
            switch (theEvent.what) {
183
 
            case keyDown:
184
 
                c = theEvent.message & charCodeMask;
185
 
                break;
186
 
            case mouseDown:
187
 
                if (FindWindow(theEvent.where, &whichWindow) ==
188
 
                    inSysWindow)
189
 
                    SystemClick(&theEvent, whichWindow);
190
 
                break;
191
 
            case updateEvt:
192
 
                break;
193
 
            }
194
 
        }
195
 
    } while (theEvent.what != keyDown);
196
 
 
197
 
    printf("*");
198
 
    fflush(stdout);
199
 
 
200
 
    return (int)c;
201
 
}
202
 
 
203
 
#endif
204
 
 
205
 
 
206
 
 
207
 
 
208
 
/******************************/
209
 
/*  Function version_local()  */
210
 
/******************************/
211
 
 
212
 
/*
213
 
** Print Compilers version and compile time/date
214
 
**
215
 
*/
216
 
 
217
 
void version_local()
218
 
{
219
 
/* prints e.g:
220
 
Compiled with  Metrowerks CodeWarrior version 2000 for  PowerPC Processor
221
 
 compile time:  Feb  4 1998 17:49:49.
222
 
*/
223
 
 
224
 
static ZCONST char CompiledWith[] =
225
 
                        "\n\nCompiled with %s %x for %s \n %s %s %s.\n\n";
226
 
 
227
 
    printf(CompiledWith,
228
 
 
229
 
 
230
 
#ifdef __MWERKS__
231
 
      " Metrowerks CodeWarrior version", __MWERKS__,
232
 
#endif
233
 
 
234
 
 
235
 
#ifdef __MC68K__
236
 
      " MC68K Processor",
237
 
#else
238
 
      " PowerPC Processor",
239
 
#endif
240
 
 
241
 
#ifdef __DATE__
242
 
      "compile time: ", __DATE__, __TIME__
243
 
#else
244
 
      "", "", ""
245
 
#endif
246
 
    );
247
 
} /* end function version_local() */
248
 
 
249
 
 
250
 
 
251
 
 
252
 
 
253
 
/*
254
 
** Deletes a dir if the switch '-m' is used
255
 
**
256
 
*/
257
 
 
258
 
int deletedir(char *path)
259
 
{
260
 
static char     Num = 0;
261
 
static FSSpec   trashfolder;
262
 
static Boolean  FirstCall = true;
263
 
static Boolean  Immediate_File_Deletion = false;
264
 
OSErr           err;
265
 
FSSpec          dirToDelete;
266
 
char            currpath[NAME_MAX], *envptr;
267
 
CInfoPBRec      fpb;
268
 
 
269
 
/* init this function */
270
 
if ((path == NULL) ||
271
 
    (strlen(path) == 0))
272
 
    {
273
 
    Num = 0;
274
 
    FirstCall = true;
275
 
    return -1;
276
 
    }
277
 
 
278
 
UserStop();
279
 
 
280
 
GetCompletePath(currpath,path,&dirToDelete, &err);
281
 
 
282
 
if (FirstCall == true)
283
 
    {
284
 
    FirstCall = false;
285
 
    envptr = getenv("Immediate_File_Deletion");
286
 
    if (!(envptr == (char *)NULL || *envptr == '\0'))
287
 
        {
288
 
        if (stricmp(envptr,"yes") == 0)
289
 
            Immediate_File_Deletion = true;
290
 
        else
291
 
            Immediate_File_Deletion = false;
292
 
        }
293
 
    err = FSpFindFolder(dirToDelete.vRefNum, kTrashFolderType,
294
 
                      kDontCreateFolder,&trashfolder);
295
 
    printerr("FSpFindFolder:",err,err,__LINE__,__FILE__,path);
296
 
    }
297
 
 
298
 
    fpb.dirInfo.ioNamePtr   = dirToDelete.name;
299
 
    fpb.dirInfo.ioVRefNum   = dirToDelete.vRefNum;
300
 
    fpb.dirInfo.ioDrDirID   = dirToDelete.parID;
301
 
    fpb.dirInfo.ioFDirIndex = 0;
302
 
 
303
 
    err = PBGetCatInfoSync(&fpb);
304
 
    printerr("PBGetCatInfo deletedir ", err, err,
305
 
             __LINE__, __FILE__, "");
306
 
 
307
 
if (fpb.dirInfo.ioDrNmFls > 0)
308
 
    {
309
 
    return 0;  /* do not move / delete folders which are not empty */
310
 
    }
311
 
 
312
 
if (Immediate_File_Deletion)
313
 
    {
314
 
    err = FSpDelete(&dirToDelete);
315
 
    return err;
316
 
    }
317
 
 
318
 
err = CatMove (dirToDelete.vRefNum, dirToDelete.parID,
319
 
               dirToDelete.name, trashfolder.parID, trashfolder.name);
320
 
 
321
 
/* -48 = file is already existing so we have to rename it before
322
 
   moving the file */
323
 
if (err == -48)
324
 
    {
325
 
    Num++;
326
 
    if (dirToDelete.name[0] >= 28) /* cut foldername if to long */
327
 
        dirToDelete.name[0] = 28;
328
 
    P2CStr(dirToDelete.name);
329
 
    sprintf(currpath,"%s~%d",(char *)dirToDelete.name,Num);
330
 
    C2PStr(currpath);
331
 
    C2PStr((char *)dirToDelete.name);
332
 
    err = HRename (dirToDelete.vRefNum, dirToDelete.parID,
333
 
                   dirToDelete.name, (unsigned char *) currpath);
334
 
 
335
 
    err = CatMove (dirToDelete.vRefNum, dirToDelete.parID,
336
 
                   (unsigned char *) currpath, trashfolder.parID,
337
 
                   trashfolder.name);
338
 
    }
339
 
 
340
 
return err;
341
 
}
342
 
 
343
 
 
344
 
 
345
 
 
346
 
/*
347
 
** Set the file-type so the archive will get the correct icon, type
348
 
** and creator code.
349
 
*/
350
 
 
351
 
void setfiletype(char *new_f, unsigned long Creator, unsigned long Type)
352
 
{
353
 
OSErr   err;
354
 
 
355
 
if (strcmp(zipfile, new_f) == 0)
356
 
    err = FSpChangeCreatorType(&MacZip.ZipFileSpec, Creator, Type);
357
 
printerr("FSpChangeCreatorType:", err, err, __LINE__, __FILE__, new_f);
358
 
 
359
 
return;
360
 
}
361
 
 
362
 
 
363
 
 
364
 
 
365
 
 
366
 
/*
367
 
** Convert the external (native) filename into Zip's internal Unix compatible
368
 
** name space.
369
 
*/
370
 
 
371
 
char *ex2in(char *externalFilen, int isdir, int *pdosflag)
372
 
/* char *externalFilen     external file name */
373
 
/* int isdir               input: externalFilen is a directory */
374
 
/* int *pdosflag           output: force MSDOS file attributes? */
375
 
/* Convert the external file name to a zip file name, returning the malloc'ed
376
 
   string or NULL if not enough memory. */
377
 
{
378
 
  char *internalFilen;              /* internal file name (malloc'ed) */
379
 
  char *t;                          /* shortened name */
380
 
  char *Pathname;
381
 
  char buffer[NAME_MAX];
382
 
  int dosflag;
383
 
 
384
 
  AssertStr(externalFilen, externalFilen)
385
 
  AssertBool(isdir,"")
386
 
 
387
 
  dosflag = dosify;  /* default for non-DOS and non-OS/2 */
388
 
 
389
 
  /* Find starting point in name before doing malloc */
390
 
  for (t = externalFilen; *t == PATH_END; t++)
391
 
      ;
392
 
 
393
 
  if (!MacZip.StoreFullPath)
394
 
        {
395
 
        Pathname = StripPartialDir(buffer, MacZip.SearchDir,t);
396
 
        }
397
 
  else
398
 
        {
399
 
        Pathname = t;
400
 
        }
401
 
 
402
 
  /* Make changes, if any, to the copied name (leave original intact) */
403
 
  if (!pathput)
404
 
    {
405
 
    t = last(Pathname, PATH_END);
406
 
    }
407
 
  else t = Pathname;
408
 
 
409
 
  /* Malloc space for internal name and copy it */
410
 
  if ((internalFilen = malloc(strlen(t) + 10 + strlen(ResourceMark) )) == NULL)
411
 
    return NULL;
412
 
 
413
 
  sstrcpy(internalFilen, t);
414
 
 
415
 
    /* we have to eliminate illegal chars:
416
 
     * The name space for Mac filenames and Zip filenames (unix style names)
417
 
     * do both include all printable extended-ASCII characters.  The only
418
 
     * difference we have to take care of is the single special character
419
 
     * used as path delimiter:
420
 
     * ':' on MacOS and '/' on Unix and '\' on Dos.
421
 
     * So, to convert between Mac filenames and Unix filenames without any
422
 
     * loss of information, we simply interchange ':' and '/'.  Additionally,
423
 
     * we try to convert the coding of the extended-ASCII characters into
424
 
     * InfoZip's standard ISO 8859-1 codepage table.
425
 
     */
426
 
  MakeCompatibleString(internalFilen, ':', '/', '/', ':',
427
 
                       MacZip.CurrTextEncodingBase);
428
 
 
429
 
  /* Returned malloc'ed name */
430
 
  if (pdosflag)
431
 
    *pdosflag = dosflag;
432
 
 
433
 
  if (isdir)
434
 
    {
435
 
    return internalFilen;      /* avoid warning on unused variable */
436
 
    }
437
 
 
438
 
  if (dosify)
439
 
    {
440
 
    msname(internalFilen);
441
 
    printf("\n ex2in: %s",internalFilen);
442
 
    }
443
 
 
444
 
  return internalFilen;
445
 
}
446
 
 
447
 
 
448
 
 
449
 
/*
450
 
** Collect all filenames. Go through all directories
451
 
**
452
 
*/
453
 
 
454
 
int wild(char *Pathpat)
455
 
                /* path/pattern to match */
456
 
/* If not in exclude mode, expand the pattern based on the contents of the
457
 
   file system.  Return an error code in the ZE_ class. */
458
 
{
459
 
FSSpec Spec;
460
 
char fullpath[NAME_MAX];
461
 
OSErr   err;
462
 
 
463
 
AssertStr(Pathpat, Pathpat);
464
 
 
465
 
if (noisy) printf("%s \n\n",GetZipVersionsInfo());
466
 
 
467
 
if (extra_fields == 0)
468
 
    {
469
 
    MacZip.DataForkOnly = true;
470
 
    }
471
 
 
472
 
/* for switch '-R' -> '.' means current dir */
473
 
if (strcmp(Pathpat,".") == 0) sstrcpy(Pathpat,"*");
474
 
 
475
 
sstrcpy(MacZip.Pattern,Pathpat);
476
 
 
477
 
if (recurse)
478
 
    {
479
 
    MacZip.StoreFoldersAlso = true;
480
 
    MacZip.SearchLevels = 0; /* if 0 we aren't checking levels */
481
 
    }
482
 
else
483
 
    {
484
 
    MacZip.StoreFoldersAlso = false;
485
 
    MacZip.SearchLevels = 1;
486
 
    }
487
 
 
488
 
/* make complete path */
489
 
GetCompletePath(fullpath, MacZip.Pattern, &Spec,&err);
490
 
err = PrintUserHFSerr((err != -43) && (err != 0), err, MacZip.Pattern);
491
 
printerr("GetCompletePath:", err, err, __LINE__, __FILE__, fullpath);
492
 
 
493
 
/* extract the filepattern */
494
 
GetFilename(MacZip.Pattern, fullpath);
495
 
 
496
 
/* extract Path and get FSSpec of search-path */
497
 
/* get FSSpec of search-path  ; we need a dir to start
498
 
   searching for filenames */
499
 
TruncFilename(MacZip.SearchDir, fullpath);
500
 
GetCompletePath(MacZip.SearchDir, MacZip.SearchDir, &Spec,&err);
501
 
 
502
 
if (noisy) {
503
 
    if (MacZip.SearchLevels == 0)
504
 
        {
505
 
        printf("\nSearch Pattern: [%s]   Levels: all", MacZip.Pattern);
506
 
        }
507
 
    else
508
 
        {
509
 
        printf("\nSearch Pattern: [%s]   Levels: %d", MacZip.Pattern,
510
 
               MacZip.SearchLevels);
511
 
        }
512
 
    printf("\nSearch Path:    [%s]", MacZip.SearchDir);
513
 
    printf("\nZip-File:       [%s] \n",MacZip.ZipFullPath);
514
 
 
515
 
}
516
 
 
517
 
/* we are working only with pathnames;
518
 
 * this can cause big problems on a mac ...
519
 
 */
520
 
if (CheckMountedVolumes(MacZip.SearchDir) > 1)
521
 
    DoWarnUserDupVol(MacZip.SearchDir);
522
 
 
523
 
/* start getting all filenames */
524
 
err = FSpRecurseDirectory(&Spec, MacZip.SearchLevels);
525
 
printerr("FSpRecurseDirectory:", err, err, __LINE__, __FILE__, "");
526
 
 
527
 
return ZE_OK;
528
 
}
529
 
 
530
 
 
531
 
 
532
 
/*
533
 
** Convert the internal filename into a external (native).
534
 
** The user will see this modified filename.
535
 
** For more performance:
536
 
** I do not completly switch back to the native macos filename.
537
 
** The user will still see directory separator '/' and the converted
538
 
** charset.
539
 
*/
540
 
 
541
 
char *in2ex(char *n)    /* internal file name */
542
 
/* Convert the zip file name to an external file name, returning the malloc'ed
543
 
   string or NULL if not enough memory. */
544
 
{
545
 
  char *x;              /* external file name */
546
 
 
547
 
  AssertStr(n,n)
548
 
 
549
 
  if ((x = malloc(strlen(n) + 1)) == NULL)
550
 
    return NULL;
551
 
 
552
 
  RfDfFilen2Real(x, n, MacZip.MacZipMode, MacZip.DataForkOnly,
553
 
                 &MacZip.CurrentFork);
554
 
 
555
 
  return x;
556
 
}
557
 
 
558
 
 
559
 
 
560
 
 
561
 
/*
562
 
** Process on filenames. This function will be called to collect
563
 
** the filenames.
564
 
*/
565
 
 
566
 
int procname(char *filename,         /* name to process */
567
 
             int caseflag)           /* true to force case-sensitive match
568
 
                                        (always false on a Mac) */
569
 
/* Process a name .  Return
570
 
   an error code in the ZE_ class. */
571
 
{
572
 
  int rc;                /* matched flag */
573
 
 
574
 
AssertBool(caseflag,"caseflag")
575
 
AssertStr(filename,filename)
576
 
 
577
 
        /* add or remove name of file */
578
 
rc = newname(filename, MacZip.isDirectory, caseflag);
579
 
 
580
 
return rc;
581
 
}
582
 
 
583
 
 
584
 
 
585
 
 
586
 
ulg filetime(
587
 
char *f,                /* name of file to get info on */
588
 
ulg *a,                 /* return value: file attributes */
589
 
long *n,                /* return value: file size */
590
 
iztimes *t)             /* return value: access, modific. and creation times */
591
 
/* If file *f does not exist, return 0.  Else, return the file's last
592
 
   modified date and time as an MSDOS date and time.  The date and
593
 
   time is returned in a long with the date most significant to allow
594
 
   unsigned integer comparison of absolute times.  Also, if a is not
595
 
   a NULL pointer, store the file attributes there, with the high two
596
 
   bytes being the Unix attributes, and the low byte being a mapping
597
 
   of that to DOS attributes.  If n is not NULL, store the file size
598
 
   there.  If t is not NULL, the file's access, modification and creation
599
 
   times are stored there as UNIX time_t values.
600
 
   If f is "-", use standard input as the file. If f is a device, return
601
 
   a file size of -1 */
602
 
{
603
 
  struct stat s;        /* results of stat() */
604
 
  char name[NAME_MAX];
605
 
  int len;
606
 
 
607
 
  AssertStr(f,f)
608
 
 
609
 
  len = strlen(f);
610
 
  sstrcpy(name, f);
611
 
 
612
 
  if (len == 0) return 0;
613
 
 
614
 
  if (SSTAT(name, &s) != 0)
615
 
             /* Accept about any file kind including directories
616
 
              * (stored with trailing : with -r option)
617
 
              */
618
 
    return 0;
619
 
 
620
 
  if (a != NULL) {
621
 
    *a = ((ulg)s.st_mode << 16) | !(s.st_mode & S_IWRITE);
622
 
    if (MacZip.isDirectory) {
623
 
      *a |= MSDOS_DIR_ATTR;
624
 
    }
625
 
  }
626
 
  if (n != NULL)
627
 
    *n = (s.st_mode & UNX_IFMT) == UNX_IFREG ? s.st_size : -1L;
628
 
  if (t != NULL) {
629
 
    t->atime = s.st_atime;
630
 
    t->mtime = s.st_mtime;
631
 
    t->ctime = s.st_ctime;   /* on Mac, st_ctime contains creation time! */
632
 
  }
633
 
 
634
 
  return unix2dostime(&s.st_mtime);
635
 
}
636
 
 
637
 
 
638
 
 
639
 
void stamp(char *f, ulg d)
640
 
/* char *f;                name of file to change */
641
 
/* ulg d;                  dos-style time to change it to */
642
 
/* Set last updated and accessed time of file f to the DOS time d. */
643
 
{
644
 
  time_t u[2];          /* argument for utime() */
645
 
 
646
 
f = f;
647
 
 
648
 
  /* Convert DOS time to time_t format in u */
649
 
 
650
 
  u[0] = u[1] = dos2unixtime(d);
651
 
/*  utime(f, u);  */
652
 
}
653
 
 
654
 
 
655
 
 
656
 
 
657
 
/*
658
 
**  return only the longest part of the path:
659
 
**  second parameter: Volume:test folder:second folder:
660
 
**  third parameter:  Volume:test folder:second folder:third folder:file
661
 
**  result will be:   third folder:file
662
 
**  first parameter:  contains string buffer that will be used to prepend
663
 
**                    the "resource mark" part in front of the result when
664
 
**                    a resource fork is processed in "M3" mode.
665
 
**
666
 
*/
667
 
 
668
 
char *StripPartialDir(char *CompletePath,
669
 
                      const char *PartialPath, const char *FullPath)
670
 
{
671
 
const char *tmpPtr1 = PartialPath;
672
 
const char *tmpPtr2 = FullPath;
673
 
int     result;
674
 
 
675
 
Assert_it(CompletePath,"StripPartialDir","")
676
 
AssertStrNoOverlap(FullPath,PartialPath,PartialPath)
677
 
 
678
 
if (MacZip.DataForkOnly)
679
 
        {
680
 
        tmpPtr2 += strlen(tmpPtr1);
681
 
        return (char *)tmpPtr2;
682
 
        }
683
 
 
684
 
switch (MacZip.MacZipMode)
685
 
    {
686
 
    case JohnnyLee_EF:
687
 
        {
688
 
        tmpPtr2 += strlen(tmpPtr1);
689
 
        return (char *)tmpPtr2;
690
 
        break;
691
 
        }
692
 
 
693
 
    case NewZipMode_EF:
694
 
        {           /* determine Fork type */
695
 
        result = strncmp(FullPath, ResourceMark, sizeof(ResourceMark)-2);
696
 
        if (result != 0)
697
 
            {                               /* data fork  */
698
 
            MacZip.CurrentFork = DataFork;
699
 
            tmpPtr2 += strlen(tmpPtr1);
700
 
             return (char *)tmpPtr2;
701
 
            }
702
 
        else
703
 
            {                                /* resource fork  */
704
 
            MacZip.CurrentFork = ResourceFork;
705
 
            sstrcpy(CompletePath, ResourceMark);
706
 
            tmpPtr2 += strlen(tmpPtr1);
707
 
            tmpPtr2 += sizeof(ResourceMark);
708
 
            sstrcat(CompletePath, tmpPtr2);
709
 
            return (char *)CompletePath;
710
 
            }
711
 
        break;
712
 
        }
713
 
    }
714
 
 
715
 
 return NULL;    /* function should never reach this point */
716
 
}
717
 
 
718
 
 
719
 
 
720
 
 
721
 
/*
722
 
** Init all global variables
723
 
** Must be called for each zip-run
724
 
*/
725
 
 
726
 
void ZipInitAllVars(void)
727
 
{
728
 
getcwd(MacZip.CurrentPath, sizeof(MacZip.CurrentPath));
729
 
/* MacZip.MacZipMode = JohnnyLee_EF;     */
730
 
MacZip.MacZipMode = NewZipMode_EF;
731
 
 
732
 
MacZip.DataForkOnly = false;
733
 
MacZip.CurrentFork = NoFork;
734
 
 
735
 
MacZip.StoreFoldersAlso = false;
736
 
 
737
 
MacZip.FoundFiles = 0;
738
 
MacZip.FoundDirectories = 0;
739
 
MacZip.RawCountOfItems = 0;
740
 
MacZip.BytesOfData = 0;
741
 
 
742
 
MacZip.StoreFullPath = false;
743
 
MacZip.StatingProgress = false;
744
 
MacZip.IncludeInvisible = false;
745
 
 
746
 
MacZip.isMacStatValid = false;
747
 
 
748
 
MacZip.CurrTextEncodingBase = FontScript();
749
 
 
750
 
MacZip.HaveGMToffset = false;
751
 
 
752
 
createTime = TickCount();
753
 
estTicksToFinish = -1;
754
 
updateTicks = 0;
755
 
 
756
 
/* init some functions */
757
 
IsZipFile(NULL);
758
 
 
759
 
destroy(NULL);
760
 
deletedir(NULL);
761
 
ShowCounter(true);
762
 
 
763
 
extra_fields = 1;
764
 
error_level = 0;
765
 
count_of_Zippedfiles = 0;
766
 
}
767
 
 
768
 
 
769
 
 
770
 
 
771
 
/*
772
 
** Get the findercomment and store it as file-comment in the Zip-file
773
 
**
774
 
*/
775
 
char *GetComment(char *filename)
776
 
{
777
 
OSErr       err;
778
 
static char buffer[NAME_MAX];
779
 
char buffer2[NAME_MAX];
780
 
char *tmpPtr;
781
 
 
782
 
if (filename == NULL) return NULL;
783
 
 
784
 
    /* now we can convert Unix-Path in HFS-Path */
785
 
for (tmpPtr = filename; *tmpPtr; tmpPtr++)
786
 
    if (*tmpPtr == '/')
787
 
      *tmpPtr = ':';
788
 
 
789
 
if (MacZip.StoreFullPath)
790
 
    {  /* filename is already a fullpath */
791
 
    sstrcpy(buffer,filename);
792
 
    }
793
 
else
794
 
    {  /* make a fullpath */
795
 
    sstrcpy(buffer,MacZip.SearchDir);
796
 
    sstrcat(buffer,filename);
797
 
    }
798
 
 
799
 
/* make fullpath and get FSSpec */
800
 
/* Unfortunately: I get only the converted filename here */
801
 
/* so filenames with extended characters can not be found  */
802
 
GetCompletePath(buffer2,buffer, &MacZip.fileSpec, &err);
803
 
printerr("GetCompletePath:",(err != -43) && (err != -120) && (err != 0) ,
804
 
          err,__LINE__,__FILE__,buffer);
805
 
 
806
 
err = FSpDTGetComment(&MacZip.fileSpec, (unsigned char *) buffer);
807
 
printerr("FSpDTGetComment:", (err != -5012) && (err != 0), err,
808
 
         __LINE__, __FILE__, filename);
809
 
P2CStr((unsigned char *) buffer);
810
 
if (err == -5012) return NULL;  /* no finder-comments found */
811
 
 
812
 
if (noisy) printf("\n%32s -> %s",filename, buffer);
813
 
/*
814
 
Beside the script change we need only to change 0x0d in 0x0a
815
 
so the last two arguments are not needed and does nothing.
816
 
*/
817
 
MakeCompatibleString(buffer, 0x0d, 0x0a, ' ', ' ',
818
 
                     MacZip.CurrTextEncodingBase);
819
 
 
820
 
return buffer;
821
 
}
822
 
 
823
 
 
824
 
 
825
 
 
826
 
/*
827
 
** Print a progress indicator for stating the files
828
 
**
829
 
*/
830
 
 
831
 
void PrintStatProgress(char *msg)
832
 
{
833
 
 
834
 
if (!noisy) return;     /* do no output if noisy is false */
835
 
 
836
 
MacZip.StatingProgress = true;
837
 
 
838
 
if (strcmp(msg,"done") == 0)
839
 
    {
840
 
    MacZip.StatingProgress = false;
841
 
    printf("\n ... done \n\n");
842
 
    }
843
 
else printf("\n %s",msg);
844
 
 
845
 
}
846
 
 
847
 
 
848
 
 
849
 
 
850
 
void InformProgress(const long progressMax, const long progressSoFar )
851
 
{
852
 
int curr_percent;
853
 
char no_time[5] = "...";
854
 
 
855
 
curr_percent = percent(progressMax, progressSoFar);
856
 
 
857
 
if (curr_percent < 95)
858
 
    {
859
 
    estTicksToFinish = EstimateCompletionTime(progressMax,
860
 
                                                  progressSoFar, curr_percent);
861
 
    }
862
 
else
863
 
    {
864
 
    rightStatusString(no_time);
865
 
    leftStatusString(no_time);
866
 
    }
867
 
 
868
 
updateTicks = TickCount() + 60;
869
 
return;
870
 
}
871
 
 
872
 
 
873
 
void ShowCounter(Boolean reset)
874
 
{
875
 
static char statusline[100];
876
 
static unsigned long filecount = 0;
877
 
 
878
 
if (reset)
879
 
        {
880
 
        filecount = 0;
881
 
        return;
882
 
        }
883
 
 
884
 
if (noisy)
885
 
    {
886
 
    sprintf(statusline, "%6d", filecount++);
887
 
    rightStatusString(statusline);
888
 
    }
889
 
}
890
 
 
891
 
 
892
 
static long EstimateCompletionTime(const long progressMax,
893
 
                                const long progressSoFar,
894
 
                                unsigned char curr_percent)
895
 
{
896
 
    long  max = progressMax, value = progressSoFar;
897
 
    static char buf[100];
898
 
    unsigned long ticksTakenSoFar = TickCount() - createTime;
899
 
    float currentRate = (float) ticksTakenSoFar / (float) value;
900
 
    long  newEst = (long)( currentRate * (float)( max - value ));
901
 
 
902
 
    sprintf(buf, "%d [%d%%]",progressSoFar, curr_percent);
903
 
    rightStatusString(buf);
904
 
 
905
 
    estTicksToFinish = newEst;
906
 
 
907
 
    UpdateTimeToComplete();
908
 
 
909
 
return estTicksToFinish;
910
 
}
911
 
 
912
 
 
913
 
 
914
 
 
915
 
 
916
 
static void UpdateTimeToComplete(void)
917
 
{
918
 
    short       days, hours, minutes, seconds;
919
 
    char    estStr[255];
920
 
    Str15   xx, yy;
921
 
    short   idx = 0;
922
 
 
923
 
    if ( estTicksToFinish == -1 )
924
 
        return;
925
 
 
926
 
    days    =   estTicksToFinish / 5184000L;
927
 
    hours   = ( estTicksToFinish - ( days * 5184000L )) / 216000L;
928
 
    minutes = ( estTicksToFinish - ( days * 5184000L ) -
929
 
              ( hours * 216000L )) / 3600L;
930
 
    seconds = ( estTicksToFinish - ( days * 5184000L ) -
931
 
              ( hours * 216000L ) - ( minutes * 3600L )) / 60L;
932
 
 
933
 
        xx[0] = 0;
934
 
        yy[0] = 0;
935
 
 
936
 
        if ( days )
937
 
        {
938
 
            /* "more than 24 hours" */
939
 
 
940
 
            idx = 1;
941
 
            goto setEstTimeStr;
942
 
        }
943
 
 
944
 
        if ( hours >= 8 )
945
 
        {
946
 
            /* "more than x hours" */
947
 
 
948
 
            NumToString( hours, xx );
949
 
            idx = 2;
950
 
            goto setEstTimeStr;
951
 
        }
952
 
 
953
 
        if ( estTicksToFinish > 252000L  )      /* > 1hr, 10 minutes */
954
 
        {
955
 
            /* "about x hours, y minutes" */
956
 
 
957
 
            NumToString( hours, xx );
958
 
            NumToString( minutes, yy );
959
 
            idx = 3;
960
 
            goto setEstTimeStr;
961
 
        }
962
 
 
963
 
        if ( estTicksToFinish > 198000L )   /* > 55 minutes */
964
 
        {
965
 
            /* "about an hour" */
966
 
            idx = 4;
967
 
            goto setEstTimeStr;
968
 
        }
969
 
 
970
 
        if ( estTicksToFinish > 144000L )   /* > 40 minutes */
971
 
        {
972
 
            /* "less than an hour" */
973
 
 
974
 
            idx = 5;
975
 
            goto setEstTimeStr;
976
 
        }
977
 
 
978
 
        if ( estTicksToFinish > 4200L )     /* > 1 minute, 10 sec */
979
 
        {
980
 
            /* "about x minutes, y seconds */
981
 
 
982
 
            NumToString( minutes, xx );
983
 
            NumToString( seconds, yy );
984
 
 
985
 
            if ( minutes == 1 )
986
 
                idx = 11;
987
 
            else
988
 
                idx = 6;
989
 
            goto setEstTimeStr;
990
 
        }
991
 
 
992
 
        if ( estTicksToFinish > 3000L )     /* > 50 seconds */
993
 
        {
994
 
            /* "about a minute" */
995
 
 
996
 
            idx = 7;
997
 
            goto setEstTimeStr;
998
 
        }
999
 
 
1000
 
        if ( estTicksToFinish > 1500L )     /* > 25 seconds */
1001
 
        {
1002
 
            /* "less than a minute" */
1003
 
 
1004
 
            idx = 8;
1005
 
            goto setEstTimeStr;
1006
 
        }
1007
 
 
1008
 
        if ( estTicksToFinish > 120L )      /* > 2 seconds */
1009
 
        {
1010
 
            NumToString( seconds, xx );
1011
 
            idx = 9;
1012
 
            goto setEstTimeStr;
1013
 
        }
1014
 
 
1015
 
        idx = 10;
1016
 
 
1017
 
    setEstTimeStr:
1018
 
        sprintf(estStr,Time_Est_strings[idx],P2CStr(xx),P2CStr(yy));
1019
 
        leftStatusString((char *)estStr);
1020
 
}
1021
 
 
1022
 
 
1023
 
 
1024
 
 
1025
 
 
1026
 
/*
1027
 
** Just return the zip version
1028
 
**
1029
 
*/
1030
 
 
1031
 
char *GetZipVersionsInfo(void)
1032
 
{
1033
 
static char ZipVersion[100];
1034
 
 
1035
 
sprintf(ZipVersion, "Zip Module\n%d.%d%d%s of %s", Z_MAJORVER, Z_MINORVER,
1036
 
        Z_PATCHLEVEL, Z_BETALEVEL, REVDATE);
1037
 
 
1038
 
return ZipVersion;
1039
 
}
1040
 
 
1041
 
 
1042
 
 
1043
 
 
1044
 
#ifndef USE_SIOUX
1045
 
 
1046
 
/*
1047
 
** Just return the copyright message
1048
 
**
1049
 
*/
1050
 
 
1051
 
char *GetZipCopyright(void)
1052
 
{
1053
 
static char CopyR[300];
1054
 
 
1055
 
sstrcpy(CopyR, copyright[0]);
1056
 
sstrcat(CopyR, copyright[1]);
1057
 
sstrcat(CopyR, "\r\rPlease send bug reports to the authors at\r"\
1058
 
              "Zip-Bugs@lists.wku.edu");
1059
 
 
1060
 
return CopyR;
1061
 
}
1062
 
 
1063
 
 
1064
 
 
1065
 
 
1066
 
/*
1067
 
** Just return the compilers date/time
1068
 
**
1069
 
*/
1070
 
 
1071
 
char *GetZipVersionLocal(void)
1072
 
{
1073
 
static char ZipVersionLocal[50];
1074
 
 
1075
 
sprintf(ZipVersionLocal, "[%s %s]", __DATE__, __TIME__);
1076
 
 
1077
 
return ZipVersionLocal;
1078
 
}
1079
 
 
1080
 
#endif  /*   #ifndef USE_SIOUX  */
1081
 
 
1082
 
 
1083
 
 
1084
 
 
1085
 
 
1086
 
const char *BOINC_RCSID_6f264625be = "$Id: macos.c 4979 2005-01-02 18:29:53Z ballen $";