⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zip.c

📁 infozip2.2源码
💻 C
📖 第 1 页 / 共 4 页
字号:
              translate_eol++; break;#ifndef WINDLL            case 'L':   /* Show license */              license();              RETURN(finish(ZE_OK));#endif            case 'm':   /* Delete files added or updated in zip file */              dispose = 1;  break;            case 'n':   /* Don't compress files with a special suffix */              special = NULL; /* will be set at next argument */              break;#ifdef AMIGA            case 'N':   /* Get zipfile comments from AmigaDOS filenotes */              filenotes = 1; break;#endif            case 'o':   /* Set zip file time to time of latest file in it */              latest = 1;  break;            case 'p':   /* Store path with name */              break;            /* (do nothing as annoyance avoidance) */            case 'P':   /* password for encryption */              if (k != 0) {                ZIPERR(ZE_PARMS, "use -P before zip file name");              }              if (key != NULL) {                ZIPERR(ZE_PARMS, "can only have one -P");              }#if CRYPT              k = 7;#else              ZIPERR(ZE_PARMS, "encryption not supported");#endif /* CRYPT */              break;#if defined(QDOS) || defined(QLZIP)            case 'Q':              qlflag  = strtol((p+1), &p, 10);              if (qlflag == 0) qlflag = 4;              p--;              break;#endif            case 'q':   /* Quiet operation */              noisy = 0;              if (verbose) verbose--;              break;            case 'r':   /* Recurse into subdirectories, match full path */              if (recurse == 2) {                ZIPERR(ZE_PARMS, "do not specify both -r and -R");              }              recurse = 1;  break;            case 'R':   /* Recurse into subdirectories, match filename */              if (recurse == 1) {                ZIPERR(ZE_PARMS, "do not specify both -r and -R");              }              recurse = 2;  break;#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(ATARI)            case 'S':              hidden_files = 1; break;#endif /* MSDOS || OS2 || WIN32 || ATARI */            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 */              vms_native = 1; 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') {                k = 5;                goto nextarg;              }              if (k != 4 &&                  (k != 3 || (action != UPDATE && action != FRESHEN))) {                ZIPERR(ZE_PARMS, "nothing to select from");              }              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            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 if (strcmp(zipfile, "-") == 0) {                ZIPERR(ZE_PARMS, "can't use - and -@ together");              }              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)                      zipwarn("name not matched: ", pp);                    else {                      ZIPERR(r, pp);                    }                }              break;            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 WIN32            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)        {#ifndef WINDLL        case 0:          zipstdout();          k = 3;          if (s) {            ZIPERR(ZE_PARMS, "can't use - and -@ together");          }          break;#endif        case 1:          ZIPERR(ZE_PARMS, "invalid path");          break;        case 2:          ZIPERR(ZE_PARMS, "invalid time");          break;        case 3:  case 4:          comment_stream = NULL;          if ((r = PROCNAME(argv[i])) != ZE_OK)            if (r == ZE_MISS)              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)            zipwarn("name not matched: ", argv[i]);          else {            ZIPERR(r, argv[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 = 3;          if (s)          {            while ((pp = getnam(errbuf, stdin)) != NULL)            {              k = 4;              if ((r = PROCNAME(pp)) != ZE_OK)                if (r == ZE_MISS)                  zipwarn("name not matched: ", pp);                else {                  ZIPERR(r, pp);                }            }            s = 0;          }          if (recurse == 2)            k = 6;          break;        case 1:          if ((tempath = malloc(strlen(argv[i]) + 1)) == NULL) {            ZIPERR(ZE_MEM, "was processing arguments");          }          strcpy(tempath, argv[i]);          k = 0;          break;        case 2:        {          int yyyy, mm, dd;       /* results of sscanf() */          if (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 = 0;          break;        }        case 3:  case 4:          if ((r = PROCNAME(argv[i])) != ZE_OK)            if (r == ZE_MISS)              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 = 0;      }    }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#ifndef WINDLL  if (k < 3) {               /* zip used as filter */    zipstdout();    comment_stream = NULL;    if ((r = procname("-")) != ZE_OK)      if (r == ZE_MISS)        zipwarn("name not matched: ", "-");      else {        ZIPERR(r, "-");      }    k = 4;    if (s) {      ZIPERR(ZE_PARMS, "can't use - and -@ together");    }  }#endif  /* 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) : 1;    }  }  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");  }#ifdef EBCDIC  if (aflag==ASCII && !translate_eol) {    /* Translation to ASCII implies EOL translation!     * The default translation mode is "UNIX" mode (single LF terminators).     */    translate_eol = 1;  }#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");#endif  if (zcount == 0 && (action != ADD || d)) {    zipwarn(zipfile, " not found or empty");#ifdef WINDLL    return ZE_NAME;#endif  }/* * 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 = strrchr(zipfile, '/')) != NULL ||#  ifdef MSDOS                          (p = strrchr(zipfile, '\\')) != NULL ||#  endif /* MSDOS */                          (p = strrchr(zipfile, ':')) != NULL))  {    if (*p == ':')      p++;#else#ifdef RISCOS  if (tempath == NULL && (p = strrchr(zipfile, '.')) != NULL)  {#else#ifdef QDOS  if (tempath == NULL && (p = LastDir(zipfile)) != NULL)  {#else  if (tempath == NULL && (p = strrchr(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 */  /* 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. */  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;#endif /* USE_EF_UT_TIME */      sprintf(errbuf, "zip diagnostic: marked file=%s\n", z->zname);      diag(errbuf);      if (action != DELETE &&#ifdef USE_EF_UT_TIME          ((t = filetime(z->name, (ulg *)NULL, (long *)NULL, &f_utim))#else /* !USE_EF_UT_TIME */          ((t = filetime(z->name, (ulg *)NULL, (long *)NULL, (iztimes *)NULL))#endif /* ?USE_EF_UT_TIME */              == 0 ||           t < before || (after && t >= after) ||           ((action == UPDATE || action == FRESHEN) &&#ifdef USE_EF_UT_TIME            ((get_ef_ut_ztime(z, &z_utim) & EB_UT_FL_MTIME) ?             f_utim.mtime <= ROUNDED_TIME(z_utim.mtime) : t <= z->tim)#else /* !USE_EF_UT_TIME */            t <= z->tim#endif /* ?USE_EF_UT_TIME */           )))      {        z->mark = comadd ? 2 : 0;        z->trash = t && t >= before &&                   (after == 0 || t < after);   /* delete if -um or -fm */        if (verbose) {          fprintf(mesg, "zip diagnostic: %s %s\n", z->zname,                 z->trash ? "up to date" : "missing or early");        }      }      else        k++;    }  /* Remove entries from found list that do not exist or are too old */  diag("stating new entries");  sprintf(errbuf, "zip diagnostic: fcount=%d\n", (int)fcount);  diag(errbuf);  for (f = found; f != NULL;) {    sprintf(errbuf, "zip diagnostic: new file=%s\n", f->zname);    diag(errbuf);    if (action == DELETE || action == FRESHEN ||        (t = filetime(f->name, (ulg *)NULL, (long *)NULL, (iztimes *)NULL))           == 0 ||        t < before || (after && t >= after) ||        (namecmp(f->zname, zipfile) == 0 && strcmp(zipfile, "-")))      f = fexpel(f);    else      f = f->nxt;  }  /* Make sure there's something left to do */  if (k == 0 && found == NULL &&      !(zfiles != NULL &&        (latest || fix || adjust || junk_sfx || comadd || zipedit))) {    if (test && (zfiles != NULL || zipbeg != 0)) {#ifndef WINDLL      check_zipfile(zipfile, argv[0]);#endif      RETURN(finish(ZE_OK));    }    if (action == UPDATE || action == FRESHEN) {      RETURN(finish(ZE_OK));    }    else if (zfiles == NULL && (latest || fix || adjust || junk_sfx)) {      ZIPERR(ZE_NAME, zipfile);    }#ifndef WINDLL    else if (recurse && (pcount == 0) && (first_listarg > 0)) {#ifdef VMS      strcpy(errbuf, "try: zip \"");      for (i = 1; i < (first_listarg - 1); i++)        strcat(strcat(errbuf, argv[i]), "\" ");      strcat(strcat(errbuf, argv[i]), " *.* -i");#else /* !VMS */      strcpy(errbuf, "try: zip");      for (i = 1; i < first_listarg; i++)        strcat(strcat(errbuf, " "), argv[i]);#  ifdef AMIGA      strcat(errbuf, " \"\" -i");#  else      strcat(errbuf, " . -i");#  endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -