📄 zip.c
字号:
" -A adjust self-extracting exe -J junk zipfile prefix (unzipsfx)"," -T test zipfile integrity -X eXclude eXtra file attributes",#endif /* ?VMS */#ifdef NTSD_EAS" -! use privileges (if granted) to obtain all aspects of WinNT security",#endif /* NTSD_EAS */#ifdef OS2" -E use the .LONGNAME Extended attribute (if found) as filename",#endif /* OS2 */#ifdef S_IFLNK" -y store symbolic links as the link instead of the referenced file",#endif /* !S_IFLNK */#ifdef VMS" \"-R\" PKZIP recursion (see manual) -w append version number to stored name",#else /* !VMS */" -R PKZIP recursion (see manual)",#endif /* ?VMS */#if defined(MSDOS) || defined(OS2)" -$ include volume label -S include system and hidden files",#endif#ifdef AMIGA# if CRYPT" -N store filenotes as comments -e encrypt"," -h show this help -n don't compress these suffixes"# else" -N store filenotes as comments -n don't compress these suffixes"# endif#else /* !AMIGA */# if CRYPT" -e encrypt -n don't compress these suffixes"# else" -h show this help -n don't compress these suffixes"# endif#endif /* ?AMIGA */#ifdef RISCOS," -I don't scan through Image files"#endif#endif /* ?MACOS */ }; for (i = 0; i < sizeof(copyright)/sizeof(char *); i++) { printf(copyright[i], "zip"); putchar('\n'); } for (i = 0; i < sizeof(text)/sizeof(char *); i++) { printf(text[i], VERSION, REVDATE); putchar('\n'); }#ifdef DOS check_for_windows("Zip");#endif}/* * XXX version_info() in a separate file */local void version_info()/* Print verbose info about program version and compile time options to stdout. */{ extent i; /* counter in text arrays */ char *envptr; /* Options info array */ static ZCONST char *comp_opts[] = {#ifdef ASM_CRC "ASM_CRC",#endif#ifdef ASMV "ASMV",#endif#ifdef DYN_ALLOC "DYN_ALLOC",#endif#ifdef MMAP "MMAP",#endif#ifdef BIG_MEM "BIG_MEM",#endif#ifdef MEDIUM_MEM "MEDIUM_MEM",#endif#ifdef SMALL_MEM "SMALL_MEM",#endif#ifdef DEBUG "DEBUG",#endif#ifdef USE_EF_UT_TIME "USE_EF_UT_TIME",#endif#ifdef NTSD_EAS "NTSD_EAS",#endif#if defined(WIN32) && defined(NO_W32TIMES_IZFIX) "NO_W32TIMES_IZFIX",#endif#ifdef VMS#ifdef VMSCLI "VMSCLI",#endif#ifdef VMS_IM_EXTRA "VMS_IM_EXTRA",#endif#ifdef VMS_PK_EXTRA "VMS_PK_EXTRA",#endif#endif /* VMS */#ifdef WILD_STOP_AT_DIR "WILD_STOP_AT_DIR",#endif#if CRYPT && defined(PASSWD_FROM_STDIN) "PASSWD_FROM_STDIN",#endif /* CRYPT & PASSWD_FROM_STDIN */ NULL }; static ZCONST char *zipenv_names[] = {#ifndef VMS# ifndef RISCOS "ZIP"# else /* RISCOS */ "Zip$Options"# endif /* ?RISCOS */#else /* VMS */ "ZIP_OPTS"#endif /* ?VMS */ ,"ZIPOPT"#ifdef AZTEC_C , /* extremely lame compiler bug workaround */#endif#ifndef __RSXNT__# ifdef __EMX__ ,"EMX" ,"EMXOPT"# endif# if (defined(__GO32__) && (!defined(__DJGPP__) || __DJGPP__ < 2)) ,"GO32" ,"GO32TMP"# endif# if (defined(__DJGPP__) && __DJGPP__ >= 2) ,"TMPDIR"# endif#endif /* !__RSXNT__ */#ifdef RISCOS ,"Zip$Exts"#endif }; for (i = 0; i < sizeof(copyright)/sizeof(char *); i++) { printf(copyright[i], "zip"); putchar('\n'); } for (i = 0; i < sizeof(versinfolines)/sizeof(char *); i++) { printf(versinfolines[i], "Zip", VERSION, REVDATE); putchar('\n'); } version_local(); puts("Zip special compilation options:");#if WSIZE != 0x8000 printf("\tWSIZE=%u\n", WSIZE);#endif for (i = 0; (int)i < (int)(sizeof(comp_opts)/sizeof(char *) - 1); i++) { printf("\t%s\n",comp_opts[i]); }#ifdef USE_ZLIB if (strcmp(ZLIB_VERSION, zlibVersion()) == 0) printf("\tUSE_ZLIB [zlib version %s]\n", ZLIB_VERSION); else printf("\tUSE_ZLIB [compiled with version %s, using version %s]\n", ZLIB_VERSION, zlibVersion()); i++; /* zlib use means there IS at least one compilation option */#endif#if CRYPT printf("\t[encryption, version %d.%d%s of %s]\n", CR_MAJORVER, CR_MINORVER, CR_BETA_VER, CR_VERSION_DATE); for (i = 0; i < sizeof(cryptnote)/sizeof(char *); i++) { printf(cryptnote[i]); putchar('\n'); } ++i; /* crypt support means there IS at least one compilation option */#endif if (i == 0) puts("\t[none]"); puts("\nZip environment options:"); for (i = 0; i < sizeof(zipenv_names)/sizeof(char *); i++) { envptr = getenv(zipenv_names[i]); printf("%16s: %s\n", zipenv_names[i], ((envptr == (char *)NULL || *envptr == 0) ? "[none]" : envptr)); }#ifdef DOS check_for_windows("Zip");#endif}#endif /* !WINDLL */#ifndef PROCNAME# define PROCNAME(n) procname(n, (action == DELETE || action == FRESHEN))#endif /* PROCNAME */#ifndef WINDLL#ifndef MACOSlocal void zipstdout()/* setup for writing zip file on stdout */{ int r; mesg = stderr; if (isatty(1)) ziperr(ZE_PARMS, "cannot write zip file to terminal"); if ((zipfile = malloc(4)) == NULL) ziperr(ZE_MEM, "was processing arguments"); strcpy(zipfile, "-"); if ((r = readzipfile()) != ZE_OK) ziperr(r, zipfile);}#endif /* !MACOS */local void check_zipfile(zipname, zippath) char *zipname; char *zippath; /* Invoke unzip -t on the given zip file */{#if (defined(MSDOS) && !defined(__GO32__)) || defined(__human68k__) int status, len; char *path, *p; status = spawnlp(P_WAIT, "unzip", "unzip", verbose ? "-t" : "-tqq", zipname, NULL);#ifdef __human68k__ if (status == -1) perror("unzip");#else/* * unzip isn't in PATH range, assume an absolute path to zip in argv[0] * and hope that unzip is in the same directory. */ if (status == -1) { p = MBSRCHR(zippath, '\\'); path = MBSRCHR((p == NULL ? zippath : p), '/'); if (path != NULL) p = path; if (p != NULL) { len = (int)(p - zippath) + 1; if ((path = malloc(len + sizeof("unzip.exe"))) == NULL) ziperr(ZE_MEM, "was creating unzip path"); memcpy(path, zippath, len); strcpy(&path[len], "unzip.exe"); status = spawnlp(P_WAIT, path, "unzip", verbose ? "-t" : "-tqq", zipname, NULL); free(path); } if (status == -1) perror("unzip"); }#endif /* ?__human68k__ */ if (status != 0) {#else /* (MSDOS && !__GO32__) || __human68k__ */ char cmd[FNMAX+16]; int result; /* Tell picky compilers to shut up about unused variables */ zippath = zippath; strcpy(cmd, "unzip -t ");#ifdef QDOS strcat(cmd, "-Q4 ");#endif if (!verbose) strcat(cmd, "-qq "); if ((int)strlen(zipname) > FNMAX) { error("zip filename too long"); }# ifdef UNIX strcat(cmd, "'"); /* accept space or $ in name */ strcat(cmd, zipname); strcat(cmd, "'");# else strcat(cmd, zipname);# endif result = system(cmd);# ifdef VMS /* Convert success severity to 0, others to non-zero. */ result = ((result & STS$M_SEVERITY) != STS$K_SUCCESS);# endif /* def VMS */ if (result) {#endif /* ?((MSDOS && !__GO32__) || __human68k__) */ fprintf(mesg, "test of %s FAILED\n", zipfile); ziperr(ZE_TEST, "original files unmodified"); } if (noisy) fprintf(mesg, "test of %s OK\n", zipfile);}#endif /* !WINDLL */local int get_filters(argc, argv) int argc; /* number of tokens in command line */ char **argv; /* command line tokens *//* Counts number of -R, -i or -x patterns, sets patterns and pcount */{ int i; int flag = 0, archive_seen = 0; char *iname, *p = NULL; FILE *fp; pcount = 0; for (i = 1; i < argc; i++) { if (argv[i][0] == '-') { p = argv[i]; while (*(++p) != '\0') { if (*p == 'i' || *p == 'x') break; } if (*p != '\0') { flag = *p; p = p[1] == '@' ? p + 2 : NULL; if (p != NULL && patterns == NULL) { fp = fopen(p, "r"); if (fp == NULL) { ZIPERR(ZE_OPEN, p); } while (fgets(errbuf, FNMAX, fp) != NULL) pcount++; fclose(fp); } } else if (MBSRCHR(argv[i], 'R') != NULL) { p = NULL; flag = 'R'; } else if (flag != 'R') { flag = 0; } } if (flag && (archive_seen || p != NULL)) { if (patterns != NULL) { /* second pass: create pattern entry */ if (p != NULL) { fp = fopen(p, "r"); if (fp == NULL) { ZIPERR(ZE_OPEN, p); } while ((p = getnam(errbuf, fp)) != NULL) { iname = ex2in(p, 0, (int *)NULL); if (iname != NULL) { patterns[pcount].zname = in2ex(iname); free(iname); } else { patterns[pcount].zname = NULL; } patterns[pcount].select = flag; if (flag != 'x') icount++; pcount++; } fclose(fp); flag = 0; p = NULL; } else if (argv[i][0] != '-') { iname = ex2in(argv[i], 0, (int *)NULL); patterns[pcount].zname = (iname != NULL ? in2ex(iname) : NULL); if (iname != NULL) free(iname); patterns[pcount].select = flag; switch (flag) { case 'i': icount++; break; case 'R': Rcount++; break; } pcount++; } } else if (p == NULL) pcount++; else flag = 0; } else { if (flag != 'R') flag = 0; /* only 'R' is allowed before zipfile arg */ if (argv[i][0] != '-') { archive_seen = 1; /* first non-flag arg is archive name */ } } } if (pcount == 0 || patterns != NULL) return ZE_OK; /* first pass and pattern count > 0: allocate space for pattern list */ patterns = (struct plist*) malloc(pcount * sizeof(struct plist)); if (patterns == NULL) { ZIPERR(ZE_MEM, "was creating pattern list"); } /* recall this function for second pass, filling the pattern list */ return get_filters(argc, argv);}#if CRYPT#ifndef WINDLLint encr_passwd(modeflag, pwbuf, size, zfn)int modeflag;char *pwbuf;int size;ZCONST char *zfn;{ char *prompt; /* Tell picky compilers to shut up about unused variables */ zfn = zfn; prompt = (modeflag == ZP_PW_VERIFY) ? "Verify password: " : "Enter password: "; if (getp(prompt, pwbuf, size) == NULL) { ziperr(ZE_PARMS, "stderr is not a tty"); } return IZ_PW_ENTERED;}#endif /* !WINDLL */#else /* !CRYPT */int encr_passwd(modeflag, pwbuf, size, zfn)int modeflag;char *pwbuf;int size;ZCONST char *zfn;{ /* Tell picky compilers to shut up about unused variables */ modeflag = modeflag; pwbuf = pwbuf; size = size; zfn = zfn; return ZE_LOGIC; /* This function should never be called! */}#endif /* CRYPT */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -