123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507 |
- #include "zip.h"
- #include "amiga/amiga.h"
- #ifndef UTIL
- #define utime FileDate
- #define PAD 0
- #define PATH_END '/'
- extern char *label;
- local ulg label_time = 0;
- local ulg label_mode = 0;
- local time_t label_utim = 0;
- local char *readd OF((DIR *));
- local int wild_recurse OF((char *, char *));
- local char *readd(d)
- DIR *d;
- {
- struct dirent *e = readdir(d);
- return e == NULL ? (char *) NULL : e->d_name;
- }
- #define ONENAMELEN 30
- local int wild_recurse(whole, wildtail) char *whole; char *wildtail;
- {
- DIR *dir;
- char *subwild, *name, *newwhole = NULL, *glue = NULL, plug = 0, plug2;
- ush newlen, amatch = 0;
- BPTR lok;
- int e = ZE_MISS;
- if (!isshexp(wildtail))
- if (lok = Lock(whole, ACCESS_READ)) {
- UnLock(lok);
- return procname(whole, 0);
- } else
- return ZE_MISS;
-
- do {
- name = wildtail + strlen(wildtail) - 1;
- for (;;)
- if (name-- <= wildtail || *name == PATH_END) {
- subwild = name + 1;
- plug2 = *subwild;
- *subwild = 0;
- break;
- }
- if (glue)
- *glue = plug;
- glue = subwild;
- plug = plug2;
- dir = opendir(whole);
- } while (!dir && !disk_not_mounted && subwild > wildtail);
- wildtail = subwild;
- if ((subwild = strchr(wildtail + 1, PATH_END)) != NULL) {
-
- *(subwild++) = 0;
- newlen = strlen(whole) + strlen(subwild) + (ONENAMELEN + 2);
- } else
- newlen = strlen(whole) + (ONENAMELEN + 1);
- if (!dir || !(newwhole = malloc(newlen))) {
- if (glue)
- *glue = plug;
- e = dir ? ZE_MEM : ZE_MISS;
- goto ohforgetit;
- }
- strcpy(newwhole, whole);
- newlen = strlen(newwhole);
- if (glue)
- *glue = plug;
- if (!isshexp(wildtail)) {
- e = ZE_MISS;
- goto ohforgetit;
- }
- while (name = readd(dir)) {
- if (MATCH(wildtail, name, 0)) {
- strcpy(newwhole + newlen, name);
- if (subwild) {
- name = newwhole + strlen(newwhole);
- *(name++) = PATH_END;
- strcpy(name, subwild);
- e = wild_recurse(newwhole, name);
- } else
- e = procname(newwhole, 0);
- newwhole[newlen] = 0;
- if (e == ZE_OK)
- amatch = 1;
- else if (e != ZE_MISS)
- break;
- }
- }
- ohforgetit:
- if (dir) closedir(dir);
- if (subwild) *--subwild = PATH_END;
- if (newwhole) free(newwhole);
- if (e == ZE_MISS && amatch)
- e = ZE_OK;
- return e;
- }
- int wild(p) char *p;
- {
- char *use;
-
- if (strcmp(p, "-") == 0)
- return newname(p, 0, 0);
-
- if (use = strchr(p, ':')) {
- if (strchr(++use, ':'))
- return ZE_PARMS;
- } else
- use = p;
- return wild_recurse(p, use);
- }
- int procname(n, caseflag)
- char *n;
- int caseflag;
- {
- char *a;
- DIR *d;
- char *e;
- int m;
- char *p;
- struct stat s;
- struct zlist far *z;
- if (strcmp(n, "-") == 0)
- return newname(n, 0, caseflag);
- else if (LSSTAT(n, &s))
- {
-
- p = ex2in(n, 0, (int *)NULL);
- m = 1;
- for (z = zfiles; z != NULL; z = z->nxt) {
- if (MATCH(p, z->iname, caseflag))
- {
- z->mark = pcount ? filter(z->zname, caseflag) : 1;
- if (verbose)
- fprintf(mesg, "zip diagnostic: %scluding %s\n",
- z->mark ? "in" : "ex", z->name);
- m = 0;
- }
- }
- free((zvoid *)p);
- return m ? ZE_MISS : ZE_OK;
- }
-
- if ((s.st_mode & S_IFDIR) == 0)
- {
-
- if ((m = newname(n, 0, caseflag)) != ZE_OK)
- return m;
- } else {
-
- if ((p = malloc(strlen(n)+2)) == NULL)
- return ZE_MEM;
- strcpy(p, n);
- a = p + strlen(p);
- if (*p && a[-1] != '/' && a[-1] != ':')
- strcpy(a, "/");
- if (dirnames && (m = newname(p, 1, caseflag)) != ZE_OK) {
- free((zvoid *)p);
- return m;
- }
-
- if (recurse && (d = opendir(n)) != NULL)
- {
- while ((e = readd(d)) != NULL) {
- if ((a = malloc(strlen(p) + strlen(e) + 1)) == NULL)
- {
- closedir(d);
- free((zvoid *)p);
- return ZE_MEM;
- }
- strcat(strcpy(a, p), e);
- if ((m = procname(a, caseflag)) != ZE_OK)
- {
- if (m == ZE_MISS)
- zipwarn("name not matched: ", a);
- else
- ziperr(m, a);
- }
- free((zvoid *)a);
- }
- closedir(d);
- }
- free((zvoid *)p);
- }
- return ZE_OK;
- }
- char *ex2in(x, isdir, pdosflag)
- char *x;
- int isdir;
- int *pdosflag;
- {
- char *n;
- char *t;
- int dosflag;
- dosflag = dosify;
-
- if ((t = strrchr(x, ':')) != NULL)
- t++;
- else
- t = x;
- {
- char *tt = t;
- while (tt = strchr(tt, '/'))
- while (*++tt == '/')
- t = tt;
- }
- while (*t == '/')
- t++;
- if (!pathput)
- t = last(t, PATH_END);
-
- if ((n = malloc(strlen(t) + 1)) == NULL)
- return NULL;
- strcpy(n, t);
- if (dosify)
- msname(n);
-
- if (pdosflag)
- *pdosflag = dosflag;
- return n;
- }
- char *in2ex(n)
- char *n;
- {
- char *x;
- if ((x = malloc(strlen(n) + 1 + PAD)) == NULL)
- return NULL;
- strcpy(x, n);
- return x;
- }
- void stamp(f, d)
- char *f;
- ulg d;
- {
- time_t u[2];
-
- u[0] = u[1] = dos2unixtime(d);
-
- utime(f, u);
- }
- ulg filetime(f, a, n, t)
- char *f;
- ulg *a;
- long *n;
- iztimes *t;
- {
- struct stat s;
-
- char *name;
- int len = strlen(f);
- if (f == label) {
- if (a != NULL)
- *a = label_mode;
- if (n != NULL)
- *n = -2L;
- if (t != NULL)
- t->atime = t->mtime = t->ctime = label_utim;
- return label_time;
- }
- if ((name = malloc(len + 1)) == NULL) {
- ZIPERR(ZE_MEM, "filetime");
- }
- strcpy(name, f);
- if (name[len - 1] == '/')
- name[len - 1] = '\0';
-
- if (strcmp(f, "-") == 0) {
- if (fstat(fileno(stdin), &s) != 0)
- error("fstat(stdin)");
- } else if (SSTAT(name, &s) != 0) {
-
- free(name);
- return 0;
- }
- free(name);
- if (a != NULL) {
- *a = ((ulg)s.st_mode << 16) | !(s.st_mode & S_IWRITE);
- if ((s.st_mode & S_IFDIR) != 0) {
- *a |= MSDOS_DIR_ATTR;
- }
- }
- if (n != NULL)
- *n = (s.st_mode & S_IFMT) == S_IFREG ? s.st_size : -1L;
- if (t != NULL) {
- t->atime = s.st_atime;
- t->mtime = s.st_mtime;
- t->ctime = s.st_ctime;
- }
- return unix2dostime(&s.st_mtime);
- }
- int set_extra_field(z, z_utim)
- struct zlist far *z;
- iztimes *z_utim;
-
- {
- #ifdef USE_EF_UT_TIME
- #ifdef IZ_CHECK_TZ
- if (!zp_tz_is_valid) return ZE_OK;
- #endif
- if ((z->extra = (char *)malloc(EB_HEADSIZE+EB_UT_LEN(1))) == NULL)
- return ZE_MEM;
- z->extra[0] = 'U';
- z->extra[1] = 'T';
- z->extra[2] = EB_UT_LEN(1);
- z->extra[3] = 0;
- z->extra[4] = EB_UT_FL_MTIME;
- z->extra[5] = (char)(z_utim->mtime);
- z->extra[6] = (char)(z_utim->mtime >> 8);
- z->extra[7] = (char)(z_utim->mtime >> 16);
- z->extra[8] = (char)(z_utim->mtime >> 24);
- z->cextra = z->extra;
- z->cext = z->ext = (EB_HEADSIZE+EB_UT_LEN(1));
- return ZE_OK;
- #else
- return (int)(z-z);
- #endif
- }
- int deletedir(d)
- char *d;
- {
- return rmdir(d);
- }
- #endif
- int WBversion = (int)
- #include "ENV:Workbench"
- ;
- void version_local()
- {
- static ZCONST char CompiledWith[] = "Compiled with %s%s under %s%s%s%s.\n\n";
- char buf1[16];
- char buf2[16];
- char buf3[16];
- char buf4[16];
- #ifdef AMIGA
- # ifdef __SASC
- strcpy(buf1,"SAS/C ");
- # else
- # ifdef LATTICE
- strcpy(buf1,"Lattice C ");
- # else
- # ifdef AZTEC_C
- strcpy(buf1,"Manx Aztec C ");
- # else
- strcpy(buf1,"UNKNOWN ");
- # endif
- # endif
- # endif
- sprintf(buf3,"AmigaDOS v%d",WBversion);
- #else
- strcpy(buf1,"Unknown compiler ");
- strcpy(buf3,"Unknown OS");
- #endif
- #if defined(__VERSION__) && defined(__REVISION__)
- sprintf(buf2,"version %d.%d",__VERSION__,__REVISION__);
- #else
- # ifdef __VERSION__
- sprintf(buf2,"version %d",__VERSION__);
- # else
- sprintf(buf2,"unknown version");
- # endif
- #endif
- #ifdef __DATE__
- sprintf(buf4," on %s",__DATE__);
- #else
- strcpy(buf4," unknown date");
- #endif
- printf(CompiledWith,
- buf1,
- buf2,
- buf3,
- buf4,
- "",
- "" );
- }
|