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

📄 zipsplit.c

📁 infozip2.2源码
💻 C
📖 第 1 页 / 共 2 页
字号:
  return *m == 'y' || *m == 'Y';}int main(argc, argv)int argc;               /* number of tokens in command line */char **argv;            /* command line tokens *//* Split a zip file into several zip files less than a specified size.  See   the command help in help() above. */{  ulg *a;               /* malloc'ed list of sizes, dest bins */  extent *b;            /* heads of bin linked lists (malloc'ed) */  ulg c;                /* bin capacity, start of central directory */  int d;                /* if true, just report the number of disks */  FILE *e;              /* input zip file */  FILE *f;              /* output index and zip files */  extent g;             /* number of bins from greedy(), entry to write */  int h;                /* how to split--true means simple split, counter */  ulg i = 0;            /* size of index file plus room to leave */  extent j;             /* steps through zip entries, bins */  int k;                /* next argument type */  extent *n = NULL;     /* next item in bin list (heads in b) */  ulg *p;               /* malloc'ed list of sizes, dest bins for greedy() */  char *q;              /* steps through option characters */  int r;                /* temporary variable, counter */  extent s;             /* number of bins needed */  ulg t;                /* total of sizes, end of central directory */  int u;                /* flag to wait for user on output files */  struct zlist far **w; /* malloc'ed table for zfiles linked list */  int x;                /* if true, make an index file */  struct zlist far *z;  /* steps through zfiles linked list */#ifdef AMIGA  char tailchar;         /* temporary variable used in name generation below */#endif  /* If no args, show help */  if (argc == 1)  {    help();    EXIT(0);  }  init_upper();           /* build case map table */  /* Go through args */  signal(SIGINT, handler);#ifdef SIGTERM                 /* Amiga has no SIGTERM */  signal(SIGTERM, handler);#endif  k = h = x = d = u = 0;  c = DEFSIZ;  for (r = 1; r < argc; r++)    if (*argv[r] == '-')      if (argv[r][1])        for (q = argv[r]+1; *q; q++)          switch (*q)          {            case 'b':   /* Specify path for output files */              if (k)                ziperr(ZE_PARMS, "options are separate and precede zip file");              else                k = 1;          /* Next non-option is path */              break;            case 'h':   /* Show help */              help();  EXIT(0);            case 'i':   /* Make an index file */              x = 1;              break;            case 'l': case 'L':  /* Show copyright and disclaimer */              license();  EXIT(0);            case 'n':   /* Specify maximum size of resulting zip files */              if (k)                ziperr(ZE_PARMS, "options are separate and precede zip file");              else                k = 2;          /* Next non-option is size */              break;            case 'p':              u = 1;              break;            case 'r':              if (k)                ziperr(ZE_PARMS, "options are separate and precede zip file");              else                k = 3;          /* Next non-option is room to leave */              break;            case 's':              h = 1;    /* Only try simple */              break;            case 't':   /* Just report number of disks */              d = 1;              break;            case 'v':   /* Show version info */              version_info();  EXIT(0);            default:              ziperr(ZE_PARMS, "Use option -h for help.");          }      else        ziperr(ZE_PARMS, "zip file cannot be stdin");    else      if (k == 0)        if (zipfile == NULL)        {          if ((zipfile = ziptyp(argv[r])) == NULL)            ziperr(ZE_MEM, "was processing arguments");        }        else          ziperr(ZE_PARMS, "can only specify one zip file");      else if (k == 1)      {        tempath = argv[r];        k = 0;      }      else if (k == 2)      {        if ((c = (ulg)atol(argv[r])) < 100)     /* 100 is smallest zip file */          ziperr(ZE_PARMS, "invalid size given. Use option -h for help.");        k = 0;      }      else              /* k must be 3 */      {        i = (ulg)atol(argv[r]);        k = 0;      }  if (zipfile == NULL)    ziperr(ZE_PARMS, "need to specify zip file");  /* Read zip file */  if ((r = readzipfile()) != ZE_OK)    ziperr(r, zipfile);  if (zfiles == NULL)    ziperr(ZE_NAME, zipfile);  /* Make a list of sizes and check against capacity.  Also compute the     size of the index file. */  c -= ENDHEAD + 4;                     /* subtract overhead/zipfile */  if ((a = (ulg *)talloc(zcount * sizeof(ulg))) == NULL ||      (w = (struct zlist far **)talloc(zcount * sizeof(struct zlist far *))) ==       NULL)  {    ziperr(ZE_MEM, "was computing split");    return 1;  }  t = 0;  for (j = 0, z = zfiles; j < zcount; j++, z = z->nxt)  {    w[j] = z;    if (x)      i += z->nam + 6 + NL;    t += a[j] = 8 + LOCHEAD + CENHEAD +           2 * (ulg)z->nam + 2 * (ulg)z->ext + z->com + z->siz;    if (a[j] > c)      ziperr(ZE_BIG, z->zname);  }  /* Decide on split to use, report number of files */  if (h)    s = simple(a, zcount, c, i);  else  {    if ((p = (ulg *)talloc(zcount * sizeof(ulg))) == NULL)      ziperr(ZE_MEM, "was computing split");    memcpy((char *)p, (char *)a, zcount * sizeof(ulg));    s = simple(a, zcount, c, i);    g = greedy(p, zcount, c, i);    if (s <= g)      tfree((zvoid *)p);    else    {      tfree((zvoid *)a);      a = p;      s = g;    }  }  printf("%ld zip files w%s be made (%ld%% efficiency)\n",         (ulg)s, d ? "ould" : "ill", ((200 * ((t + c - 1)/c)) / s + 1) >> 1);  if (d)  {    tfreeall();    free((zvoid *)zipfile);    zipfile = NULL;    EXIT(0);  }  /* Set up path for output files */  /* Point "name" past the path, where the filename should go */  if ((path = (char *)talloc(tempath == NULL ? 13 : strlen(tempath) + 14)) ==      NULL)    ziperr(ZE_MEM, "was making output file names");  if (tempath == NULL)     name = path;  else  {#ifndef VM_CMS    /* Copy the output path to the target */    strcpy(path, tempath);#endif#ifdef AMIGA    tailchar = path[strlen(path) - 1];  /* last character */    if (path[0] && (tailchar != '/') && (tailchar != ':'))      strcat(path, "/");    name = path + strlen(path);#else#  ifdef RISCOS    if (path[0] && path[strlen(path) - 1] != '.')      strcat(path, ".");    name = path + strlen(path);#  else /* !RISCOS */#   ifndef QDOS    if (path[0] && path[strlen(path) - 1] != '/')      strcat(path, "/");#   else    if (path[0] && path[strlen(path) - 1] != '_')      strcat(path, "_");#   endif    name = path + strlen(path);#  endif#endif /* ?AMIGA */  }  /* Make linked lists of results */  if ((b = (extent *)talloc(s * sizeof(extent))) == NULL ||      (n = (extent *)talloc(zcount * sizeof(extent))) == NULL)    ziperr(ZE_MEM, "was computing split");  for (j = 0; j < s; j++)    b[j] = (extent)-1;  j = zcount;  while (j--)  {    g = (extent)a[j];    n[j] = b[g];    b[g] = j;  }  /* Make a name template for the zip files that is eight or less characters     before the .zip, and that will not overwrite the original zip file. */  for (k = 1, j = s; j >= 10; j /= 10)    k++;  if (k > 7)    ziperr(ZE_PARMS, "way too many zip files must be made");/* * XXX, ugly .... *//* Find the final "path" separator character */#ifdef QDOS  q = LastDir(zipfile);#else#ifdef VMS  if ((q = strrchr(zipfile, ']')) != NULL)#else#ifdef AMIGA  if (((q = strrchr(zipfile, '/')) != NULL)                       || ((q = strrchr(zipfile, ':'))) != NULL)#else#ifdef RISCOS  if ((q = strrchr(zipfile, '.')) != NULL)#else#ifdef MVS  if ((q = strrchr(zipfile, '.')) != NULL)#else  if ((q = strrchr(zipfile, '/')) != NULL)#endif /* MVS */#endif /* RISCOS */#endif /* AMIGA */#endif /* VMS */    q++;  else    q = zipfile;#endif /* QDOS */  r = 0;  while ((g = *q++) != '\0' && g != ZPATH_SEP && r < 8 - k)    template[r++] = (char)g;  if (r == 0)    template[r++] = '_';  else if (g >= '0' && g <= '9')    template[r - 1] = (char)(template[r - 1] == '_' ? '-' : '_');  sprintf(template + r, TEMPL_FMT, k);#ifdef VM_CMS  /* For CMS, add the "path" as the filemode at the end */  if (tempath)  {     strcat(template,".");     strcat(template,tempath);  }#endif  /* Make the zip files from the linked lists of entry numbers */  if ((e = fopen(zipfile, FOPR)) == NULL)    ziperr(ZE_NAME, zipfile);  free((zvoid *)zipfile);  zipfile = NULL;  for (j = 0; j < s; j++)  {    /* jump here on a disk retry */   redobin:    /* prompt if requested */    if (u)    {      char m[10];      fprintf(stderr, "Insert disk #%ld of %ld and hit return: ",              (ulg)j + 1, (ulg)s);      fgets(m, 10, stdin);    }    /* write index file on first disk if requested */    if (j == 0 && x)    {      strcpy(name, INDEX);      printf("creating: %s\n", path);      indexmade = 1;      if ((f = fopen(path, "w")) == NULL)      {        if (u && retry()) goto redobin;        ziperr(ZE_CREAT, path);      }      for (j = 0; j < zcount; j++)        fprintf(f, "%5ld %s\n", a[j] + 1, w[j]->zname);      if ((j = ferror(f)) != 0 || fclose(f))      {        if (j)          fclose(f);        if (u && retry()) goto redobin;        ziperr(ZE_WRITE, path);      }    }    /* create output zip file j */    sprintf(name, template, j + 1L);    printf("creating: %s\n", path);    zipsmade = j + 1;    if ((f = fopen(path, FOPW)) == NULL)    {      if (u && retry()) goto redobin;      ziperr(ZE_CREAT, path);    }    tempzn = 0;    /* write local headers and copy compressed data */    for (g = b[j]; g != (extent)-1; g = (extent)n[g])    {      if (fseek(e, w[g]->off, SEEK_SET))        ziperr(ferror(e) ? ZE_READ : ZE_EOF, zipfile);      if ((r = zipcopy(w[g], e, f)) != ZE_OK)      {        if (r == ZE_TEMP)        {          if (u && retry()) goto redobin;          ziperr(ZE_WRITE, path);        }        else          ziperr(r, zipfile);      }    }    /* write central headers */    if ((c = ftell(f)) == (ulg)(-1L))    {      if (u && retry()) goto redobin;      ziperr(ZE_WRITE, path);    }    for (g = b[j], k = 0; g != (extent)-1; g = n[g], k++)      if ((r = putcentral(w[g], f)) != ZE_OK)      {        if (u && retry()) goto redobin;        ziperr(ZE_WRITE, path);      }    /* write end-of-central header */    if ((t = ftell(f)) == -1L ||        (r = putend(k, t - c, c, (extent)0, (char *)NULL, f)) != ZE_OK ||        ferror(f) || fclose(f))    {      if (u && retry()) goto redobin;      ziperr(ZE_WRITE, path);    }#ifdef RISCOS    /* Set the filetype to &DDC */    setfiletype(path,0xDDC);#endif  }  fclose(e);  /* Done! */  if (u)    fputs("Done.\n", stderr);  tfreeall();  RETURN(0);}

⌨️ 快捷键说明

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