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

📄 zip.c

📁 infozip2.2源码
💻 C
📖 第 1 页 / 共 4 页
字号:
  for (i = 0; (int)i < (int)(sizeof(comp_opts)/sizeof(char *) - 1); i++)  {    printf("\t%s\n",comp_opts[i]);  }#if CRYPT  printf("\t[encryption, version %d.%d%s of %s]\n",            CR_MAJORVER, CR_MINORVER, CR_BETA_VER, CR_VERSION_DATE);  ++i;#endif /* CRYPT */  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));  }}#endif /* !WINDLL */#ifndef PROCNAME#  define PROCNAME(n) procname(n)#endif /* PROCNAME */#ifndef WINDLLlocal 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);}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);/* * 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 = strrchr(zippath, '\\');     path = strrchr((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");   }   if (status != 0) {#else /* (MSDOS && !__GO32__) || __human68k__ */   char cmd[FNMAX+16];   /* 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# ifdef VMS   if (!system(cmd)) {# else   if (system(cmd)) {# endif#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 -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] == '-') {      if ((p = strrchr(argv[i], 'i')) != NULL ||          (p = strrchr(argv[i], 'x')) != NULL) {        flag = *p;        p = p[1] == '@' ? p + 2 : NULL;        if (p != NULL && patterns == NULL) {          fp = fopen(p, "r");          if (fp == NULL) {            ZIPERR(ZE_NAME, p);          }          while (fgets(errbuf, FNMAX, fp) != NULL)            pcount++;          fclose(fp);        }      } else if (strrchr(argv[i], 'R') != NULL) {        flag = 'R';      } else if (flag != 'R') {        flag = 0;      }    }    if (flag && archive_seen) {      if (patterns != NULL) {        if (p != NULL) {          fp = fopen(p, "r");          if (fp == NULL) {            ZIPERR(ZE_NAME, p);          }          while ((p = getnam(errbuf, fp)) != NULL) {            iname = ex2in(p, 0, (int *)NULL);            patterns[pcount].zname = (iname != NULL ? in2ex(iname) : NULL);            if (iname != NULL)              free(iname);            patterns[pcount].select = flag;            if (flag != 'x')              icount++;            pcount++;          }          fclose(fp);          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;          if (flag != 'x')            icount++;          pcount++;        }      }      else if (p == NULL)       pcount++;    } else      archive_seen = 1;     /* first non-flag arg is archive name */  }  if (pcount == 0 || patterns != NULL) return ZE_OK;  patterns = (struct plist*) malloc(pcount * sizeof(struct plist));  if (patterns == NULL) {    ZIPERR(ZE_MEM, "was creating 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 */#ifndef USE_ZIPMAINint main(argc, argv)#elseint zipmain(argc, argv)#endifint argc;               /* number of tokens in command line */char **argv;            /* command line tokens *//* Add, update, freshen, or delete zip entries in a zip file.  See the   command help in help() above. */{  int a;                /* attributes of zip file */  ulg c;                /* start of central directory */  int d;                /* true if just adding to a zip file */  char *e;              /* malloc'd comment buffer */  struct flist far *f;  /* steps through found linked list */  int i;                /* arg counter, root directory flag */  int k;                /* next argument type, marked counter,                           comment size, entry count */  ulg n;                /* total of entry len's */  int o;                /* true if there were any ZE_OPEN errors */  char *p;              /* steps through option arguments */  char *pp;             /* temporary pointer */  ulg *cmptime = NULL;  /* pointer to 'before' or 'after' */  int r;                /* temporary variable */  int s;                /* flag to read names from stdin */  ulg t;                /* file time, length of central directory */  int first_listarg = 0;/* index of first arg of "process these files" list */  struct zlist far *v;  /* temporary variable */  struct zlist far * far *w;    /* pointer to last link in zfiles list */  FILE *x, *y;          /* input and output zip files */  struct zlist far *z;  /* steps through zfiles linked list */#if (!defined(VMS) && !defined(CMS_MVS))  char *zipbuf;         /* stdio buffer for the zip file */#endif /* !VMS && !CMS_MVS */  FILE *comment_stream; /* set to stderr if anything is read from stdin */#if defined(__IBMC__) && defined(__DEBUG_ALLOC__)  {    extern void DebugMalloc(void);    atexit(DebugMalloc);  }#endif#ifdef QDOS  {      extern void QDOSexit(void);      atexit(QDOSexit);  }#endif#ifdef RISCOS  set_prefix();#endif/* Re-initialize global variables to make the zip dll re-entrant. It is * possible that we could get away with not re-initializing all of these * but better safe than sorry. */#ifdef WINDLL  action = ADD; /* one of ADD, UPDATE, FRESHEN, or DELETE */  comadd = 0;   /* 1=add comments for new files */  zipedit = 0;  /* 1=edit zip comment and all file comments */  latest = 0;   /* 1=set zip file time to time of latest file */  before = 0;   /* 0=ignore, else exclude files before this time */  after = 0;    /* 0=ignore, else exclude files newer than this time */  test = 0;     /* 1=test zip file with unzip -t */  tempdir = 0;  /* 1=use temp directory (-b) */  junk_sfx = 0; /* 1=junk the sfx prefix */  zipstate = -1;  tempzip = NULL;  fcount = 0;  recurse = 0;         /* 1=recurse into directories; 2=match filenames */  dispose = 0;         /* 1=remove files after put in zip file */  pathput = 1;         /* 1=store path with name */  method = BEST;       /* one of BEST, DEFLATE (only), or STORE (only) */  dosify = 0;          /* 1=make new entries look like MSDOS */  verbose = 0;         /* 1=report oddities in zip file structure */  fix = 0;             /* 1=fix the zip file */  adjust = 0;          /* 1=adjust offsets for sfx'd file (keep preamble) */  level = 6;           /* 0=fastest compression, 9=best compression */  translate_eol = 0;   /* Translate end-of-line LF -> CR LF */#ifdef WIN32  use_longname_ea = 0; /* 1=use the .LONGNAME EA as the file's name */  use_privileges = 0;  /* 1=use security privileges overrides */#endif  hidden_files = 0;    /* process hidden and system files */  volume_label = 0;    /* add volume label */  dirnames = 1;        /* include directory entries by default */  linkput = 0;         /* 1=store symbolic links as such */  noisy = 1;           /* 0=quiet operation */  extra_fields = 1;    /* 0=do not create extra fields */  special = ".Z:.zip:.zoo:.arc:.lzh:.arj"; /* List of special suffixes */  key = NULL;          /* Scramble password if scrambling */  tempath = NULL;      /* Path for temporary files */  found = NULL;        /* where in found, or new found entry */  fnxt = &found;  patterns = NULL;     /* List of patterns to be matched */  pcount = 0;          /* number of patterns */  icount = 0;          /* number of include only patterns */#endif /* WINDLL */  mesg = (FILE *) stdout; /* cannot be made at link time for VMS */  comment_stream = (FILE *)stdin;  init_upper();           /* build case map table */#ifdef AMIGA  if (!VALID_TIMEZONE(p))    extra_fields = 0;     /* disable storing "UT" time stamps */#endif /* AMIGA */#ifdef DOS  if ((p = getenv("TZ")) == NULL || *p == '\0')    extra_fields = 0;     /* disable storing "UT" time stamps */#endif /* DOS */#ifdef VMSCLI    {        ulg status = vms_zip_cmdline(&argc, &argv);        if (!(status & 1))            return status;    }#endif /* VMSCLI */   /* extract extended argument list from environment */   expand_args(&argc, &argv);#ifndef WINDLL  /* Process arguments */  diag("processing arguments");  /* First, check if just the help or version screen should be displayed */  if (isatty(1)) {              /* output screen is available */    if (argc == 1)    {                           /* show help screen */#ifdef VMSCLI      VMSCLI_help();#else      help();#endif      EXIT(0);    }    else if (argc == 2 && strcmp(argv[1], "-v") == 0)    {                           /* show diagnostic version info */      version_info();      EXIT(0);    }  }#ifndef VMS#  ifndef RISCOS  envargs(&argc, &argv, "ZIPOPT", "ZIP");  /* get options from environment */#  else /* RISCOS */  envargs(&argc, &argv, "ZIPOPT", "Zip$Options");  /* get options from environment */  getRISCOSexts("Zip$Exts");        /* get the extensions to swap from environment */#  endif /* ? RISCOS */#else /* VMS */  envargs(&argc, &argv, "ZIPOPT", "ZIP_OPTS");  /* 4th arg for unzip compat. */#endif /* ?VMS */#endif /* !WINDLL */  zipfile = tempzip = NULL;  tempzf = NULL;  d = 0;                        /* disallow adding to a zip file */#ifndef WINDLL  signal(SIGINT, handler);#ifdef SIGTERM                  /* AMIGADOS and others have no SIGTERM */  signal(SIGTERM, handler);#endif#endif /* !WINDLL */  k = 0;                        /* Next non-option argument type */  s = 0;                        /* set by -@ if -@ is early */  r = get_filters(argc, argv);      /* scan first the -x and -i patterns */#ifdef WINDLL  if (r != ZE_OK)     return r;#endif  for (i = 1; i < argc; i++)  {    if (argv[i][0] == '-')      if (argv[i][1])        for (p = argv[i]+1; *p; p++)          switch (*p)          {#ifdef EBCDIC            case 'a':              aflag = ASCII;              printf("Translating to ASCII...\n");              break;#endif /* EBCDIC */#ifdef CMS_MVS            case 'B':              bflag = 1;              printf("Using binary mode...\n");              break;#endif /* CMS_MVS */            case '0':              method = STORE; level = 0; break;            case '1':  case '2':  case '3':  case '4':            case '5':  case '6':  case '7':  case '8':  case '9':                        /* Set the compression efficacy */              level = *p - '0';  break;            case 'A':   /* Adjust unzipsfx'd zipfile:  adjust offsets only */              adjust = 1; break;            case 'b':   /* Specify path for temporary file */              tempdir = 1;              if (k != 0) {                ZIPERR(ZE_PARMS, "use -b before zip file name");              }              else                k = 1;          /* Next non-option is path */              break;            case 'c':   /* Add comments for new files in zip file */              comadd = 1;  break;            case 'd':   /* Delete files from zip file */              if (action != ADD) {                ZIPERR(ZE_PARMS, "specify just one action");              }              action = DELETE;              break;            case 'D':   /* Do not add directory entries */              dirnames = 0; break;            case 'e':   /* Encrypt */#if !CRYPT              ZIPERR(ZE_PARMS, "encryption not supported");#else /* CRYPT */              if (key == NULL) {                if ((key = malloc(PWLEN+1)) == NULL) {                  ZIPERR(ZE_MEM, "was getting encryption password");                }                r = encr_passwd(ZP_PW_ENTER, key, PWLEN+1, zipfile);                if (r != IZ_PW_ENTERED) {                  if (r < IZ_PW_ENTERED)                    r = ZE_PARMS;                  ZIPERR(r, "was getting encryption password");                }                if (*key == '\0') {                  ZIPERR(ZE_PARMS, "zero length password not allowed");                }                if ((e = malloc(PWLEN+1)) == NULL) {                  ZIPERR(ZE_MEM, "was verifying encryption password");                }                r = encr_passwd(ZP_PW_VERIFY, e, PWLEN+1, zipfile);                if (r != IZ_PW_ENTERED && r != IZ_PW_SKIPVERIFY) {                  free((zvoid *)e);                  if (r < ZE_OK) r = ZE_PARMS;                  ZIPERR(r, "was verifying encryption password");                }                r = ((r == IZ_PW_SKIPVERIFY) ? 0 : strcmp(key, e));                free((zvoid *)e);                if (r) {                  ZIPERR(ZE_PARMS, "password verification failed");                }              }#endif /* !CRYPT */              break;            case 'F':   /* fix the zip file */              fix++; break;            case 'f':   /* Freshen zip file--overwrite only */              if (action != ADD) {                ZIPERR(ZE_PARMS, "specify just one action");              }              action = FRESHEN;              break;            case 'g':   /* Allow appending to a zip file */              d = 1;  break;#ifndef WINDLL            case 'h': case 'H': case '?':  /* Help */#ifdef VMSCLI              VMSCLI_help();#else              help();#endif              RETURN(finish(ZE_OK));#endif /* !WINDLL */#ifdef RISCOS            case 'I':   /* Don't scan through Image files */              scanimage = 0;              break;#endif            case 'j':   /* Junk directory names */              pathput = 0;  break;            case 'J':   /* Junk sfx prefix */              junk_sfx = 1;  break;            case 'k':   /* Make entries using DOS names (k for Katz) */              dosify = 1;  break;            case 'l':   /* Translate end-of-line */

⌨️ 快捷键说明

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