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

📄 unzip.c

📁 完整的解压zip文件的源码。包含密码功能
💻 C
📖 第 1 页 / 共 4 页
字号:
#else /* !VMS */#ifdef COPYRIGHT_CLEAN   static ZCONST char Far UnzipUsageLine1[] = "\UnZip %d.%d%d%s of %s, by Info-ZIP.  Maintained by C. Spieler.  Send\n\bug reports to the authors at Zip-Bugs@lists.wku.edu; see README for details.\\n\n";#else   static ZCONST char Far UnzipUsageLine1[] = "\UnZip %d.%d%d%s of %s, by Info-ZIP.  UnReduce (c) 1989 by S. H. Smith.\n\Send bug reports to authors at Zip-Bugs@lists.wku.edu; see README for details.\\n\n";#endif /* ?COPYRIGHT_CLEAN */#define UnzipUsageLine1v        UnzipUsageLine1#endif /* ?VMS */static ZCONST char Far UnzipUsageLine2v[] = "\Latest sources and executables are at ftp://ftp.cdrom.com/pub/infozip/ , as of\\nabove date; see http://www.cdrom.com/pub/infozip/UnZip.html for other sites.\\n\n";#ifdef MACOSstatic ZCONST char Far UnzipUsageLine2[] = "\Usage: unzip %s[-opts[modifiers]] file[.zip] [list] [-d exdir]\n \ Default action is to extract files in list, to exdir;\n\  file[.zip] may be a wildcard.  %s\n";#else /* !MACOS */#ifdef VM_CMSstatic ZCONST char Far UnzipUsageLine2[] = "\Usage: unzip %s[-opts[modifiers]] file[.zip] [list] [-x xlist] [-d fm]\n \ Default action is to extract files in list, except those in xlist, to disk fm;\n\  file[.zip] may be a wildcard.  %s\n";#else /* !VM_CMS */static ZCONST char Far UnzipUsageLine2[] = "\Usage: unzip %s[-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]\n \ Default action is to extract files in list, except those in xlist, to exdir;\n\  file[.zip] may be a wildcard.  %s\n";#endif /* ?VM_CMS */#endif /* ?MACOS */#ifdef NO_ZIPINFO#  define ZIPINFO_MODE_OPTION  ""   static ZCONST char Far ZipInfoMode[] =     "(ZipInfo mode is disabled in this version.)";#else#  define ZIPINFO_MODE_OPTION  "[-Z] "#  ifdef VMS     static ZCONST char Far ZipInfoMode[] =       "\"-Z\" => ZipInfo mode (`unzip \"-Z\"' for usage).";#  else     static ZCONST char Far ZipInfoMode[] =       "-Z => ZipInfo mode (\"unzip -Z\" for usage).";#  endif#endif /* ?NO_ZIPINFO */#ifdef VMS   static ZCONST char Far VMSusageLine2b[] = "\=> define foreign command symbol in LOGIN.COM:  $ unzip :== $dev:[dir]unzip.exe\\n";#endif#ifdef MACOSstatic ZCONST char Far UnzipUsageLine3[] = "\n\  -d  extract files into exdir               -l  list files (short format)\n\  -f  freshen existing files, create none    -t  test compressed archive data\n\  -u  update files, create if necessary      -z  display archive comment\n\%s\n";#else /* !MACOS */#ifdef VM_CMSstatic ZCONST char Far UnzipUsageLine3[] = "\n\  -p  extract files to pipe, no messages     -l  list files (short format)\n\  -f  freshen existing files, create none    -t  test compressed archive data\n\  -u  update files, create if necessary      -z  display archive comment\n\  -x  exclude files that follow (in xlist)   -d  extract files onto disk fm\n\%s\n";#else /* !VM_CMS */static ZCONST char Far UnzipUsageLine3[] = "\n\  -p  extract files to pipe, no messages     -l  list files (short format)\n\  -f  freshen existing files, create none    -t  test compressed archive data\n\  -u  update files, create if necessary      -z  display archive comment\n\  -x  exclude files that follow (in xlist)   -d  extract files into exdir\n\%s\n";#endif /* ?VM_CMS */#endif /* ?MACOS */static ZCONST char Far UnzipUsageLine4[] = "\modifiers:                                   -q  quiet mode (-qq => quieter)\n\  -n  never overwrite existing files         -a  auto-convert any text files\n\  -o  overwrite files WITHOUT prompting      -aa treat ALL files as text\n \ -j  junk paths (do not make directories)   -v  be verbose/print version info\n\ %c-C%c match filenames case-insensitively    %c-L%c make (some) names \lowercase\n %-42s %c-V%c retain VMS version numbers\n%s";static ZCONST char Far UnzipUsageLine5[] = "\Examples (see unzip.doc for more info):\n\  unzip data1 -x joe   => extract all files except joe from zipfile data1.zip\n\%s\  unzip -fo foo %-6s => quietly replace existing %s if archive file newer\n";#endif /* ?SFX *//*****************************//*  main() / UzpMain() stub  *//*****************************/int MAIN(argc, argv)   /* return PK-type error code (except under VMS) */    int argc;    char *argv[];{    int r;    CONSTRUCTGLOBALS();    r = unzip(__G__ argc, argv);    DESTROYGLOBALS()    RETURN(r);}/*******************************//*  Primary UnZip entry point  *//*******************************/int unzip(__G__ argc, argv)    __GDEF    int argc;    char *argv[];{#ifndef NO_ZIPINFO    char *p;#endif#ifdef DOS_FLX_H68_OS2_W32    int i;#endif    int retcode, error=FALSE;#if (defined(__IBMC__) && defined(__DEBUG_ALLOC__))    extern void DebugMalloc(void);    atexit(DebugMalloc);#endif#ifdef MALLOC_WORK    G.area.Slide =(uch *)calloc(8193, sizeof(shrint)+sizeof(uch)+sizeof(uch));    G.area.shrink.Parent = (shrint *)G.area.Slide;    G.area.shrink.value = G.area.Slide + (sizeof(shrint)*(HSIZE+1));    G.area.shrink.Stack = G.area.Slide +                           (sizeof(shrint) + sizeof(uch))*(HSIZE+1);#endif/*---------------------------------------------------------------------------    Macintosh initialization code.  ---------------------------------------------------------------------------*/#ifdef MACOS    {        int a;        for (a = 0;  a < 4;  ++a)            G.rghCursor[a] = GetCursor(a+128);        G.giCursor = 0;    }#endif/*---------------------------------------------------------------------------    Human68K initialization code.  ---------------------------------------------------------------------------*/#ifdef __human68k__    InitTwentyOne();#endif/*---------------------------------------------------------------------------    Acorn RISC OS initialization code.  ---------------------------------------------------------------------------*/#ifdef RISCOS    set_prefix();#endif/*---------------------------------------------------------------------------    Set signal handler for restoring echo, warn of zipfile corruption, etc.  ---------------------------------------------------------------------------*/#ifdef SIGINT    signal(SIGINT, handler);#endif#ifdef SIGTERM                 /* some systems really have no SIGTERM */    signal(SIGTERM, handler);#endif#ifdef SIGBUS    signal(SIGBUS, handler);#endif#ifdef SIGSEGV    signal(SIGSEGV, handler);#endif#if (defined(WIN32) && defined(__RSXNT__))    for (i = 0 ; i < argc; i++) {       _ISO_INTERN(argv[i]);    }#endif/*---------------------------------------------------------------------------    First figure out if we're running in UnZip mode or ZipInfo mode, and put    the appropriate environment-variable options into the queue.  Then rip    through any command-line options lurking about...  ---------------------------------------------------------------------------*/#ifdef SFX    G.argv0 = argv[0];#if (defined(OS2) || defined(WIN32))    G.zipfn = GetLoadPath(__G);/* non-MSC NT puts path into G.filename[] */#else    G.zipfn = G.argv0;#endif#ifdef VMSCLI    {        ulg status = vms_unzip_cmdline(&argc, &argv);        if (!(status & 1))            return status;    }#endif /* VMSCLI */    uO.zipinfo_mode = FALSE;    error = uz_opts(__G__ &argc, &argv);   /* UnZipSFX call only */#else /* !SFX */#ifdef RISCOS    /* get the extensions to swap from environment */    getRISCOSexts(ENV_UNZIPEXTS);#endif#ifdef MSDOS    /* extract MKS extended argument list from environment (before envargs!) */    mksargs(&argc, &argv);#endif#ifdef VMSCLI    {        ulg status = vms_unzip_cmdline(&argc, &argv);        if (!(status & 1))            return status;    }#endif /* VMSCLI */    G.noargs = (argc == 1);   /* no options, no zipfile, no anything */#ifndef NO_ZIPINFO    for (p = argv[0] + strlen(argv[0]); p >= argv[0]; --p) {        if (*p == DIR_END#ifdef DIR_END2            || *p == DIR_END2#endif           )            break;    }    ++p;    if (STRNICMP(p, LoadFarStringSmall(Zipnfo), 7) == 0 ||        STRNICMP(p, "ii", 2) == 0 ||        (argc > 1 && strncmp(argv[1], "-Z", 2) == 0))    {        uO.zipinfo_mode = TRUE;        envargs(__G__ &argc, &argv, LoadFarStringSmall(EnvZipInfo),          LoadFarStringSmall2(EnvZipInfo2));        error = zi_opts(__G__ &argc, &argv);    } else#endif /* NO_ZIPINFO */    {        uO.zipinfo_mode = FALSE;        envargs(__G__ &argc, &argv, LoadFarStringSmall(EnvUnZip),          LoadFarStringSmall2(EnvUnZip2));        error = uz_opts(__G__ &argc, &argv);    }#endif /* ?SFX */    if ((argc < 0) || error)        return error;/*---------------------------------------------------------------------------    Now get the zipfile name from the command line and then process any re-    maining options and file specifications.  ---------------------------------------------------------------------------*/#ifdef DOS_FLX_H68_OS2_W32    /* convert MSDOS-style directory separators to Unix-style ones for     * user's convenience (include zipfile name itself)     */#ifdef SFX    for (G.pfnames = argv, i = argc;  i > 0;  --i) {#else    /* argc does not include the zipfile specification */    for (G.pfnames = argv, i = argc+1;  i > 0;  --i) {#endif        char *q;        for (q = *G.pfnames;  *q;  ++q)            if (*q == '\\')                *q = '/';        ++G.pfnames;    }#endif /* DOS_FLX_H68_OS2_W32 */#ifndef SFX    G.wildzipfn = *argv++;#endif#if (defined(SFX) && !defined(SFX_EXDIR)) /* only check for -x */    G.filespecs = argc;    G.xfilespecs = 0;    if (argc > 0) {        char **pp = argv-1;        G.pfnames = argv;        while (*++pp)            if (strcmp(*pp, "-x") == 0) {                if (pp > argv) {                    *pp = 0;              /* terminate G.pfnames */                    G.filespecs = pp - G.pfnames;                } else {                    G.pfnames = (char **)fnames;  /* defaults */                    G.filespecs = 0;                }                G.pxnames = pp + 1;      /* excluded-names ptr: _after_ -x */                G.xfilespecs = argc - G.filespecs - 1;                break;                    /* skip rest of args */            }        G.process_all_files = FALSE;    } else        G.process_all_files = TRUE;      /* for speed */#else /* !SFX || SFX_EXDIR */             /* check for -x or -d */    G.filespecs = argc;    G.xfilespecs = 0;    if (argc > 0) {        int in_files=FALSE, in_xfiles=FALSE;        char **pp = argv-1;        G.process_all_files = FALSE;        G.pfnames = argv;        while (*++pp) {            Trace((stderr, "pp - argv = %d\n", pp-argv));#ifdef CMS_MVS            if (!uO.exdir && STRNICMP(*pp, "-d", 2) == 0) {#else            if (!uO.exdir && strncmp(*pp, "-d", 2) == 0) {#endif                int firstarg = (pp == argv);                uO.exdir = (*pp) + 2;                if (in_files) {      /* ... zipfile ... -d exdir ... */                    *pp = (char *)NULL;         /* terminate G.pfnames */                    G.filespecs = pp - G.pfnames;                    in_files = FALSE;                } else if (in_xfiles) {                    *pp = (char *)NULL;         /* terminate G.pxnames */                    G.xfilespecs = pp - G.pxnames;                    /* "... -x xlist -d exdir":  nothing left */                }                /* first check for "-dexdir", then for "-d exdir" */                if (*uO.exdir == '\0') {                    if (*++pp)                        uO.exdir = *pp;                    else {                        Info(slide, 0x401, ((char *)slide,                          LoadFarString(MustGiveExdir)));                        return(PK_PARAM);  /* don't extract here by accident */                    }                }                if (firstarg) { /* ... zipfile -d exdir ... */                    if (pp[1]) {                        G.pfnames = pp + 1;  /* argv+2 */                        G.filespecs = argc - (G.pfnames-argv);  /* for now... */                    } else {                        G.process_all_files = TRUE;                        G.pfnames = (char **)fnames;  /* GRR: necessary? */                        G.filespecs = 0;     /* GRR: necessary? */                        break;                    }                }            } else if (!in_xfiles) {                if (strcmp(*pp, "-x") == 0) {                    in_xfiles = TRUE;                    if (pp == G.pfnames) {                        G.pfnames = (char **)fnames;  /* defaults */                        G.filespecs = 0;                    } else if (in_files) {                        *pp = 0;                   /* terminate G.pfnames */                        G.filespecs = pp - G.pfnames;  /* adjust count */                        in_files = FALSE;                    }                    G.pxnames = pp + 1; /* excluded-names ptr starts after -x */                    G.xfilespecs = argc - (G.pxnames-argv);  /* anything left */                } else                    in_files = TRUE;            }        }    } else        G.process_all_files = TRUE;      /* for speed */    if (uO.exdir != (char *)NULL && !G.extract_flag)    /* -d ignored */        Info(slide, 0x401, ((char *)slide, LoadFarString(NotExtracting)));#endif /* ?(SFX && !SFX_EXDIR) *//*---------------------------------------------------------------------------    Okey dokey, we have everything we need to get started.  Let's roll.  ---------------------------------------------------------------------------*/    retcode = process_zipfiles(__G);    return(retcode);} /* end main()/unzip() *//**********************//* Function uz_opts() *//**********************/int uz_opts(__G__ pargc, pargv)

⌨️ 快捷键说明

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