📄 zip.c
字号:
} recurse = 2; break;#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(ATARI) case 'S': hidden_files = 1; break;#endif /* MSDOS || OS2 || WIN32 || ATARI */#ifdef MACOS case 'S': MacZip.IncludeInvisible = true; break;#endif /* MACOS */ case 't': /* Exclude files earlier than specified date */ if (p[1] == 't') { ++p; cmptime = &after; } else { cmptime = &before; } if (*cmptime) { ZIPERR(ZE_PARMS, (cmptime == &after ? "can only have one -tt" : "can only have one -t")); } k = 2; break; case 'T': /* test zip file */ test = 1; break; case 'u': /* Update zip file--overwrite only if newer */ if (action != ADD) { ZIPERR(ZE_PARMS, "specify just one action"); } action = UPDATE; break; case 'v': /* Mention oddities in zip file structure */ noisy = 1; verbose++; break;#ifdef VMS case 'V': /* Store in VMS format. (Record multiples.) */ vms_native++; break; case 'w': /* Append the VMS version number */ vmsver = 1; break;#endif /* VMS */ case 'i': /* Include only the following files */ case 'x': /* Exclude following files */ if (p[1] == '@' && p[2] != '\0') { goto nextarg; } if (zipfile == NULL) { ZIPERR(ZE_PARMS, "use -x or -i after name of zipfile"); } k = 5; break;#ifdef S_IFLNK case 'y': /* Store symbolic links as such */ linkput = 1; break;#endif /* S_IFLNK */ case 'z': /* Edit zip file comment */ zipedit = 1; break;#if defined(MSDOS) || defined(OS2) case '$': /* Include volume label */ volume_label = 1; break;#endif#ifndef MACOS case '@': /* read file names from stdin */ comment_stream = NULL; if (k < 3) /* zip file not read yet */ s = 1; /* defer -@ until after zipfile read */ else /* zip file read--do it now */ while ((pp = getnam(errbuf, stdin)) != NULL) { k = 4; if ((r = PROCNAME(pp)) != ZE_OK) { if (r == ZE_MISS) if (bad_open_is_error) { zipwarn("name not matched: ", pp); ZIPERR(ZE_OPEN, pp); } else { zipwarn("name not matched: ", pp); } else { ZIPERR(r, pp); } } } break;#endif /* !MACOS */ case 'X': extra_fields = 0; break;#ifdef OS2 case 'E': /* use the .LONGNAME EA (if any) as the file's name. */ use_longname_ea = 1; break;#endif#ifdef NTSD_EAS case '!': /* use security privilege overrides */ use_privileges = 1; break;#endif default: { sprintf(errbuf, "no such option: %c", *p); ZIPERR(ZE_PARMS, errbuf); } } else /* just a dash */ switch (k) {#if (!defined(MACOS) && !defined(WINDLL)) case 0: zipstdout(); k = 3; break;#endif /* !MACOS && !WINDLL */ case 1: ZIPERR(ZE_PARMS, "invalid path"); /* not reached */ case 2: ZIPERR(ZE_PARMS, "invalid time"); /* not reached */ case 3: case 4: comment_stream = NULL; if ((r = PROCNAME(argv[i])) != ZE_OK) { if (r == ZE_MISS) if (bad_open_is_error) { zipwarn("name not matched: ", argv[i]); ZIPERR(ZE_OPEN, argv[i]); } else { zipwarn("name not matched: ", argv[i]); } else { ZIPERR(r, argv[i]); } } if (k == 3) { first_listarg = i; k = 4; } } } else /* not an option */ { if (special == NULL) special = argv[i]; else if (k == 5) break; /* -i and -x arguments already scanned */ else if (k == 6) {#ifdef AMIGA if ((r = PROCNAME("")) != ZE_OK) {#else if ((r = PROCNAME(".")) != ZE_OK) {#endif if (r == ZE_MISS) if (bad_open_is_error) { zipwarn("name not matched: ", argv[i]); ZIPERR(ZE_OPEN, argv[i]); } else { zipwarn("name not matched: ", argv[i]); } else { ZIPERR(r, argv[i]); } } if (first_listarg == 0) first_listarg = i; break; } else switch (k) { case 0: if ((zipfile = ziptyp(argv[i])) == NULL) { ZIPERR(ZE_MEM, "was processing arguments"); } if ((r = readzipfile()) != ZE_OK) { ZIPERR(r, zipfile); } k = (recurse == 2 ? 6 : 3); break; case 1: if ((tempath = malloc(strlen(argv[i]) + 1)) == NULL) { ZIPERR(ZE_MEM, "was processing arguments"); } strcpy(tempath, argv[i]); k = (zipfile != NULL ? (first_listarg > 0 ? 4 : 3) : 0); break; case 2: { int yyyy, mm, dd; /* results of sscanf() */ /* Support ISO 8601 & American dates */ if ((sscanf(argv[i], "%4d-%2d-%2d", &yyyy, &mm, &dd) != 3 && sscanf(argv[i], "%2d%2d%4d", &mm, &dd, &yyyy) != 3) || mm < 1 || mm > 12 || dd < 1 || dd > 31) { ZIPERR(ZE_PARMS, (cmptime == &after ? "invalid date entered for -tt option" : "invalid date entered for -t option")); } *cmptime = dostime(yyyy, mm, dd, 0, 0, 0); k = (zipfile != NULL ? (first_listarg > 0 ? 4 : 3) : 0); break; } case 3: case 4: if ((r = PROCNAME(argv[i])) != ZE_OK) { if (r == ZE_MISS) if (bad_open_is_error) { zipwarn("name not matched: ", argv[i]); ZIPERR(ZE_OPEN, argv[i]); } else { zipwarn("name not matched: ", argv[i]); } else { ZIPERR(r, argv[i]); } } if (k == 3) { first_listarg = i; k = 4; } break; case 7: if ((key = malloc(strlen(argv[i]) + 1)) == NULL) { ZIPERR(ZE_MEM, "was processing arguments"); } strcpy(key, argv[i]); k = (zipfile != NULL ? (first_listarg > 0 ? 4 : 3) : 0); } } if ((k == 3 || k == 6) && (s)) { while ((pp = getnam(errbuf, stdin)) != NULL) { first_listarg = i + 1; k = 4; if ((r = PROCNAME(pp)) != ZE_OK) { if (r == ZE_MISS) if (bad_open_is_error) { zipwarn("name not matched: ", pp); ZIPERR(ZE_OPEN, pp); } else { zipwarn("name not matched: ", pp); } else { ZIPERR(r, pp); } } } s = 0; if (recurse == 2) k = 6; }nextarg: ; } if (k == 7 || k == 1) { ZIPERR(ZE_PARMS, "missing argument for -b or -P"); }#if (defined(MSDOS) || defined(OS2)) && !defined(WIN32) if ((k == 3 || k == 4) && volume_label == 1) { PROCNAME(NULL); k = 4; }#endif if (pcount && first_listarg == 0 && (k < 3 || (action != UPDATE && action != FRESHEN))) { ZIPERR(ZE_PARMS, "nothing to select from"); }#if (!defined(MACOS) && !defined(WINDLL)) if (k < 3) { /* zip used as filter */ zipstdout(); comment_stream = NULL; if ((r = procname("-", 0)) != ZE_OK) { if (r == ZE_MISS) if (bad_open_is_error) { zipwarn("name not matched: ", "-"); ZIPERR(ZE_OPEN, "-"); } else { zipwarn("name not matched: ", "-"); } else { ZIPERR(r, "-"); } } k = 4; if (s) { ZIPERR(ZE_PARMS, "can't use - and -@ together"); } }#endif /* !MACOS && !WINDLL */ /* Clean up selections ("3 <= k <= 5" now) */ if (k != 4 && first_listarg == 0 && (action == UPDATE || action == FRESHEN)) { /* if -u or -f with no args, do all, but, when present, apply filters */ for (z = zfiles; z != NULL; z = z->nxt) { z->mark = pcount ? filter(z->zname, 0) : 1;#ifdef DOS if (z->mark) z->dosflag = 1; /* force DOS attribs for incl. names */#endif } } if ((r = check_dup()) != ZE_OK) { /* remove duplicates in found list */ if (r == ZE_PARMS) { ZIPERR(r, "cannot repeat names in zip file"); } else { ZIPERR(r, "was processing list of files"); } } if (zcount) free((zvoid *)zsort); /* Check option combinations */ if (special == NULL) { ZIPERR(ZE_PARMS, "missing suffix list"); } if (level == 9 || !strcmp(special, ";") || !strcmp(special, ":")) special = NULL; /* compress everything */ if (action == DELETE && (method != BEST || dispose || recurse || key != NULL || comadd || zipedit)) { zipwarn("invalid option(s) used with -d; ignored.",""); /* reset flags - needed? */ method = BEST; dispose = 0; recurse = 0; if (key != NULL) { free((zvoid *)key); key = NULL; } comadd = 0; zipedit = 0; } if (linkput && dosify) { zipwarn("can't use -y with -k, -y ignored", ""); linkput = 0; } if (fix && adjust) { zipwarn("can't use -F with -A, -F ignored", ""); } if (test && !strcmp(zipfile, "-")) { test = 0; zipwarn("can't use -T on stdout, -T ignored", ""); } if ((action != ADD || d) && !strcmp(zipfile, "-")) { ZIPERR(ZE_PARMS, "can't use -d,-f,-u or -g on stdout\n"); }#if defined(EBCDIC) && !defined(OS390) if (aflag==ASCII && !translate_eol) { /* Translation to ASCII implies EOL translation! * (on OS390, consistent EOL translation is controlled separately) * The default translation mode is "UNIX" mode (single LF terminators). */ translate_eol = 2; }#endif#ifdef CMS_MVS if (aflag==ASCII && bflag) ZIPERR(ZE_PARMS, "can't use -a with -B");#endif#ifdef VMS if (!extra_fields && vms_native) { zipwarn("can't use -V with -X, -V ignored", ""); vms_native = 0; } if (vms_native && translate_eol) ZIPERR(ZE_PARMS, "can't use -V with -l or -ll");#endif if (zcount == 0 && (action != ADD || d)) { zipwarn(zipfile, " not found or empty"); } if (bad_open_is_error == 1) ZIPERR(ZE_PARMS, "-M not supported, use -MM for Must Match"); else if (bad_open_is_error > 1) bad_open_is_error = 1;/* * XXX make some kind of mktemppath() function for each OS. */#ifndef VM_CMS/* For CMS, leave tempath NULL. A-disk will be used as default. */ /* If -b not specified, make temporary path the same as the zip file */#if defined(MSDOS) || defined(__human68k__) || defined(AMIGA) if (tempath == NULL && ((p = MBSRCHR(zipfile, '/')) != NULL ||# ifdef MSDOS (p = MBSRCHR(zipfile, '\\')) != NULL ||# endif /* MSDOS */ (p = MBSRCHR(zipfile, ':')) != NULL)) { if (*p == ':') p++;#else#ifdef RISCOS if (tempath == NULL && (p = MBSRCHR(zipfile, '.')) != NULL) {#else#ifdef QDOS if (tempath == NULL && (p = LastDir(zipfile)) != NULL) {#else if (tempath == NULL && (p = MBSRCHR(zipfile, '/')) != NULL) {#endif /* QDOS */#endif /* RISCOS */#endif /* MSDOS || __human68k__ || AMIGA */ if ((tempath = malloc((int)(p - zipfile) + 1)) == NULL) { ZIPERR(ZE_MEM, "was processing arguments"); } r = *p; *p = 0; strcpy(tempath, zipfile); *p = (char)r; }#endif /* VM_CMS */#if (defined(IZ_CHECK_TZ) && defined(USE_EF_UT_TIME)) if (!zp_tz_is_valid) { zipwarn("TZ environment variable not found, cannot use UTC times!!",""); }#endif /* IZ_CHECK_TZ && USE_EF_UT_TIME */ /* For each marked entry, if not deleting, check if it exists, and if updating or freshening, compare date with entry in old zip file. Unmark if it doesn't exist or is too old, else update marked count. */#ifdef MACOS PrintStatProgress("Getting file information ...");#endif diag("stating marked entries"); k = 0; /* Initialize marked count */ for (z = zfiles; z != NULL; z = z->nxt) if (z->mark) {#ifdef USE_EF_UT_TIME iztimes f_utim, z_utim; ulg z_tim;#endif /* USE_EF_UT_TIME */ Trace((stderr, "zip diagnostics: marked file=%s\n", z->zname));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -