123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442 |
- #include "zip.h"
- #include <stdio.h>
- #include <time.h>
- #include <errno.h>
- #ifndef MVS
- int stat(const char *path, struct stat *buf)
- {
- if ((buf->fp = fopen(path, "r")) != NULL) {
- fldata_t fdata;
- if (fldata( buf->fp, buf->fname, &fdata ) == 0) {
- buf->st_dev = fdata.__device;
- buf->st_mode = *(short *)(&fdata);
- }
- strcpy( buf->fname, path );
- fclose(buf->fp);
- }
- return (buf->fp != NULL ? 0 : 1);
- }
- #endif
- #ifndef UTIL
- #define PAD 0
- #define PATH_END '/'
- #ifdef USE_ZIPMAIN
- int main OF((void));
- #endif
- int utime OF((char *, ztimbuf *));
- extern char *label;
- local ulg label_time = 0;
- local ulg label_mode = 0;
- local time_t label_utim = 0;
- #ifndef MVS
- int fstat(int fd, struct stat *buf)
- {
- fldata_t fdata;
- if ((fd != -1) && (fldata( (FILE *)fd, buf->fname, &fdata ) == 0)) {
- buf->st_dev = fdata.__device;
- buf->st_mode = *(short *)(&fdata);
- buf->fp = (FILE *)fd;
- return 0;
- }
- return -1;
- }
- #endif
- char *ex2in(x, isdir, pdosflag)
- char *x;
- int isdir;
- int *pdosflag;
- {
- char *n;
- char *t;
- int dosflag;
- char mem[10] = "";
- char ext[10] = "";
- dosflag = dosify;
-
- for (t = x; *t == '/'; t++)
- ;
-
- if (!pathput)
- t = last(t, PATH_END);
-
- if ((n = malloc(strlen(t) + 1)) == NULL)
- return NULL;
- strcpy(n, t);
- #ifdef MVS
-
- if (*n == '\'' && (t = strrchr(n, '\'')) != n) {
- if (!*(t+1)) {
-
- int l = strlen(n) - 2;
- memmove(n, n+1, l);
- *(n+l) = '\0';
- }
- }
-
- if (t = strrchr(n, '(')) {
- *t = '\0';
- strcpy(mem,t+1);
- if (t = strchr(mem, ')')) *t = '\0';
-
- if (t = strrchr(n, '.')) t++;
- else t = n;
- strcpy(ext,t);
-
- strcpy(t,mem);
- strcat(t,".");
- strcat(t,ext);
- }
-
- if (t = strrchr(n, '.')) {
- while (--t > n)
- if (*t == '.')
- *t = '/';
- }
- #else
-
- if (t = strchr(n, '.'))
- if (t = strchr(t+1, '.'))
- *t = '\0';
- t = n;
- #endif
- strcpy(n, t);
- if (isdir == 42) return n;
- if (dosify)
- msname(n);
- strtoasc(n, n);
-
- if (pdosflag)
- *pdosflag = dosflag;
- return n;
- }
- char *in2ex(n)
- char *n;
- {
- char *x;
- if ((x = malloc(strlen(n) + 1 + PAD)) == NULL)
- return NULL;
- strtoebc(x, n);
- return x;
- }
- void stamp(f, d)
- char *f;
- ulg d;
- {
- ztimbuf u;
-
- u.actime = u.modtime = dos2unixtime(d);
- utime(f, &u);
- }
- ulg filetime(f, a, n, t)
- char *f;
- ulg *a;
- long *n;
- iztimes *t;
- {
- FILE *stream;
- time_t ltime;
- if (strcmp(f, "-") != 0) {
- Trace((mesg, "opening file '%s' with '%s'\n", f, FOPR));
- if ((stream = fopen(f, FOPR)) == (FILE *)NULL) {
- return 0;
- } else {
- if (n != NULL) {
-
- fseek(stream, 0L, SEEK_END);
- *n = ftell(stream);
- Trace((mesg, "file size = %lu\n", *((ulg *)n)));
- }
- fclose(stream);
- }
- }
- else {
-
- if (n != NULL) {
- *n = -1L;
- }
- }
-
- time(<ime);
- if (t != NULL)
- t->atime = t->mtime = t->ctime = ltime;
-
- if (a != NULL)
- *a = 0;
- return unix2dostime(<ime);
- }
- int set_extra_field(z, z_utim)
- struct zlist far *z;
- iztimes *z_utim;
- {
- fldata_t fdata;
- FILE *stream;
- char *eb_ptr;
- #ifdef USE_EF_UT_TIME
- extent ef_l_len = (EB_HEADSIZE+EB_UT_LEN(1));
- #else
- extent ef_l_len = 0;
- #endif
- int set_cmsmvs_eb = 0;
- if (aflag == ASCII) {
- z->att = ASCII;
- } else {
- if (bflag)
- z->att = BINARY;
- else
- z->att = __EBCDIC;
- ef_l_len += sizeof(fdata)+EB_HEADSIZE;
- set_cmsmvs_eb = 1;
- }
- if (ef_l_len > 0) {
- z->extra = (char *)malloc(ef_l_len);
- if (z->extra == NULL) {
- printf("\nFLDATA : Unable to allocate memory !\n");
- return ZE_MEM;
- }
- z->cext = z->ext = ef_l_len;
- eb_ptr = z->cextra = z->extra;
- if (set_cmsmvs_eb) {
- if (bflag)
- stream = fopen(z->name,"rb");
- else
- stream = fopen(z->name,"r");
- if (stream == NULL) {
- printf("\nFLDATA : Could not open file : %s !\n",z->name);
- printf("Error %d: '%s'\n", errno, strerror(errno));
- return ZE_NONE;
- }
- fldata(stream,z->name,&fdata);
-
- #ifdef VM_CMS
- *(eb_ptr) = EF_VMCMS & 0xFF;
- *(eb_ptr+1) = EF_VMCMS >> 8;
- #else
- *(eb_ptr) = EF_MVS & 0xFF;
- *(eb_ptr+1) = EF_MVS >> 8;
- #endif
- *(eb_ptr+2) = sizeof(fdata) & 0xFF;
- *(eb_ptr+3) = sizeof(fdata) >> 8;
- memcpy(eb_ptr+EB_HEADSIZE,&fdata,sizeof(fdata));
- fclose(stream);
- #ifdef USE_EF_UT_TIME
- eb_ptr += (sizeof(fdata)+EB_HEADSIZE);
- #endif
- }
- #ifdef USE_EF_UT_TIME
- eb_ptr[0] = 0x55;
- eb_ptr[1] = 0x54;
- eb_ptr[2] = EB_UT_LEN(1);
- eb_ptr[3] = 0;
- eb_ptr[4] = EB_UT_FL_MTIME;
- eb_ptr[5] = (char)(z_utim->mtime);
- eb_ptr[6] = (char)(z_utim->mtime >> 8);
- eb_ptr[7] = (char)(z_utim->mtime >> 16);
- eb_ptr[8] = (char)(z_utim->mtime >> 24);
- #endif
- }
- return ZE_OK;
- }
- int deletedir(d)
- char *d;
- {
- return 0;
- }
- #ifdef USE_ZIPMAIN
- int main(void)
- {
- int argc=0;
- char *argv[50];
- int iArgLen;
- char argstr[256];
- char **pEPLIST, *pCmdStart, *pArgStart, *pArgEnd;
-
- pEPLIST = (char **)__xregs(0);
-
- pCmdStart = *(pEPLIST+0);
- pArgStart = *(pEPLIST+1);
- pArgEnd = *(pEPLIST+2);
- iArgLen = pArgEnd - pCmdStart + 1;
-
- memcpy(argstr, pCmdStart, iArgLen);
- argstr[iArgLen] = '\0';
-
- argv[argc++] = strtok(argstr, " ");
-
- while (argv[argc-1])
- argv[argc++] = strtok(NULL, " ");
- argc--;
-
- return zipmain(argc, argv);
- }
- #endif
- #endif
- void version_local()
- {
- char liblvlmsg [50+1];
- char *compiler = "?";
- char *platform = "?";
- char complevel[64];
-
- union {
- unsigned int iVRM;
- struct {
- unsigned int pd:4;
- unsigned int vv:4;
- unsigned int rr:8;
- unsigned int mm:16;
- } xVRM;
- } VRM;
-
- VRM.iVRM = __librel();
- sprintf(liblvlmsg, "Using runtime library level %s V%dR%dM%d",
- (VRM.xVRM.pd==1 ? "LE" : "CE"),
- VRM.xVRM.vv, VRM.xVRM.rr, VRM.xVRM.mm);
-
-
- #ifdef VM_CMS
- platform = "VM/CMS";
- #ifdef __IBMC__
- compiler = "IBM C";
- #else
- compiler = "C/370";
- #endif
- #endif
- #ifdef MVS
- platform = "MVS";
- #ifdef __IBMC__
- compiler = "IBM C/C++";
- #else
- compiler = "C/370";
- #endif
- #endif
- #ifdef __COMPILER_VER__
- VRM.iVRM = __COMPILER_VER__;
- sprintf(complevel," V%dR%dM%d",
- VRM.xVRM.vv, VRM.xVRM.rr, VRM.xVRM.mm);
- #else
- #ifdef __IBMC__
- sprintf(complevel," V%dR%d", __IBMC__ / 100, (__IBMC__ % 100)/10);
- #else
- complevel[0] = '\0';
- #endif
- #endif
- printf("Compiled with %s%s for %s%s%s.\n\n",
-
- compiler, complevel,
-
- platform,
-
- #ifdef __DATE__
- " on " __DATE__
- #ifdef __TIME__
- " at " __TIME__
- #endif
- #endif
- ".\n",
- liblvlmsg
- );
- }
|