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

📄 unzip.c

📁 压缩解压,是unzip540的升级,这个外国网站摘来的源码,是evb编写.
💻 C
📖 第 1 页 / 共 5 页
字号:
    /* The easiest way found to force creation of libraries when selected     * members are to be unzipped. Explicitely add libraries names to the     * arguments list before the first member of the library.     */    if (! _setargv(&argc, &argv)) {        Info(slide, 0x401, ((char *)slide, "cannot process argv\n"));        retcode = PK_MEM;        goto cleanup_and_exit;    }#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)) {            retcode = (int)status;            goto cleanup_and_exit;        }    }#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)) {            retcode = (int)status;            goto cleanup_and_exit;        }    }#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;#ifdef THEOS    if (strncmp(p, "ZIPINFO.",8) == 0 || strstr(p, ".ZIPINFO:") != NULL ||        strncmp(p, "II.",3) == 0 || strstr(p, ".II:") != NULL ||#else    if (STRNICMP(p, LoadFarStringSmall(Zipnfo), 7) == 0 ||        STRNICMP(p, "ii", 2) == 0 ||#endif        (argc > 1 && strncmp(argv[1], "-Z", 2) == 0))    {        uO.zipinfo_mode = TRUE;#ifndef _WIN32_WCE /* Win CE does not support environment variables */        if ((error = envargs(&argc, &argv, LoadFarStringSmall(EnvZipInfo),                             LoadFarStringSmall2(EnvZipInfo2))) != PK_OK)            perror(LoadFarString(NoMemArguments));        else#endif            error = zi_opts(__G__ &argc, &argv);    } else#endif /* !NO_ZIPINFO */    {        uO.zipinfo_mode = FALSE;#ifndef _WIN32_WCE /* Win CE does not support environment variables */        if ((error = envargs(&argc, &argv, LoadFarStringSmall(EnvUnZip),                             LoadFarStringSmall2(EnvUnZip2))) != PK_OK)            perror(LoadFarString(NoMemArguments));        else#endif            error = uz_opts(__G__ &argc, &argv);    }#endif /* ?SFX */    if ((argc < 0) || error) {        retcode = error;        goto cleanup_and_exit;    }/*---------------------------------------------------------------------------    Now get the zipfile name from the command line and then process any re-    maining options and file specifications.  ---------------------------------------------------------------------------*/#ifdef DOS_FLX_H68_NLM_OS2_W32    /* convert MSDOS-style 'backward slash' directory separators to Unix-style     * 'forward slashes' 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#ifdef __human68k__        extern char *_toslash(char *);        _toslash(*G.pfnames);#else /* !__human68k__ */        char *q = *G.pfnames;        while (*q != '\0') {            if (*q == '\\')                *q = '/';            INCSTR(q);        }        ++G.pfnames;#endif /* ?__human68k__ */    }#endif /* DOS_FLX_H68_NLM_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)));                        /* don't extract here by accident */                        retcode = PK_PARAM;                        goto cleanup_and_exit;                    }                }                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);cleanup_and_exit:#if (defined(REENTRANT) && !defined(NO_EXCEPT_SIGNALS))    /* restore all signal handlers back to their state at function entry */    while (oldsighandlers != NULL) {        savsigs_info *thissigsav = oldsighandlers;        signal(thissigsav->sigtype, thissigsav->sighandler);        oldsighandlers = thissigsav->previous;        free(thissigsav);    }#endif#if (defined(MALLOC_WORK) && !defined(REENTRANT))    if (G.area.Slide != (uch *)NULL) {        free(G.area.Slide);        G.area.Slide = (uch *)NULL;    }#endif    return(retcode);} /* end main()/unzip() */#if (defined(REENTRANT) && !defined(NO_EXCEPT_SIGNALS))/*******************************//* Function setsignalhandler() *//*******************************/static int setsignalhandler(__G__ p_savedhandler_chain, signal_type,                            newhandler)    __GDEF    savsigs_info **p_savedhandler_chain;    int signal_type;    void (*newhandler)(int);{    savsigs_info *savsig;    savsig = malloc(sizeof(savsigs_info));    if (savsig == NULL) {        /* error message and break */        Info(slide, 0x401, ((char *)slide, LoadFarString(CantSaveSigHandler)));        return PK_MEM;    }    savsig->sigtype = signal_type;    savsig->sighandler = signal(SIGINT, newhandler);    if (savsig->sighandler == SIG_ERR) {        free(savsig);    } else {        savsig->previous = *p_savedhandler_chain;        *p_savedhandler_chain = savsig;    }    return PK_OK;} /* end function setsignalhandler() */#endif /* REENTRANT && !NO_EXCEPT_SIGNALS *//**********************//* Function uz_opts() *//**********************/int uz_opts(__G__ pargc, pargv)    __GDEF    int *pargc;    char ***pargv;{    char **argv, *s;    int argc, c, error=FALSE, negative=0;    argc = *pargc;    argv = *pargv;    while (++argv, (--argc > 0 && *argv != NULL && **argv == '-')) {        s = *argv + 1;        while ((c = *s++) != 0) {    /* "!= 0":  prevent Turbo C warning */#ifdef CMS_MVS            switch (tolower(c))#else            switch (c)#endif            {                case ('-'):                    ++negative;                    break;#ifdef RISCOS                case ('/'):                    if (negative) {   /* negative not allowed with -/ swap */                        Info(slide, 0x401, ((char *)slide,                          "error:  must give extensions list"));                        return(PK_PARAM);  /* don't extract here by accident */                    }                    exts2swap = s; /* override Unzip$Exts */                    s += strlen(s);                    break;#endif                case ('a'):                    if (negative) {                        uO.aflag = MAX(uO.aflag-negative,0);                        negative = 0;                    } else                        ++uO.aflag;                    break;#if (defined(DLL) && defined(API_DOC))                case ('A'):    /* extended help for API */                    APIhelp(__G__ argc, argv);                    *pargc = -1;  /* signal to exit successfully */                    return 0;#endif                case ('b'):                    if (negative) {#if (defined(TANDEM) || defined(VMS))                        uO.bflag = MAX(uO.bflag-negative,0);#endif                        negative = 0;   /* do nothing:  "-b" is default */                    } else {#ifdef VMS                        if (uO.aflag == 0)                           ++uO.bflag;

⌨️ 快捷键说明

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