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

📄 unzip.c

📁 另一个解zip文件的程序
💻 C
📖 第 1 页 / 共 5 页
字号:
                  LoadFarStringSmall(AsmCRC));
                ++numopts;
#endif
#ifdef REGARGS
                PRINTF(LoadFarString(CompileOptFormat),
                  LoadFarStringSmall(RegArgs));
                ++numopts;
#endif
#ifdef OLD_EXDIR
                PRINTF(LoadFarString(CompileOptFormat),
                  LoadFarStringSmall(Old_Exdir));
                ++numopts;
#endif
#ifdef CHECK_VERSIONS
                PRINTF(LoadFarString(CompileOptFormat),
                  LoadFarStringSmall(Check_Versions));
                ++numopts;
#endif
#ifdef RETURN_CODES
                PRINTF(LoadFarString(CompileOptFormat),
                  LoadFarStringSmall(Return_Codes));
                ++numopts;
#endif
#ifdef RETURN_SEVERITY
                PRINTF(LoadFarString(CompileOptFormat),
                  LoadFarStringSmall(Return_Severity));
                ++numopts;
#endif
#ifdef DEBUG
                PRINTF(LoadFarString(CompileOptFormat),
                  LoadFarStringSmall(Debug));
                ++numopts;
#endif
#ifdef DEBUG_TIME
                PRINTF(LoadFarString(CompileOptFormat),
                  LoadFarStringSmall(DebugTime));
                ++numopts;
#endif
#ifdef CRYPT
                PRINTF(LoadFarString(CompileOptFormat),
                  LoadFarStringSmall(Decryption));
                ++numopts;
#endif
                if (numopts == 0)
                    PRINTF(LoadFarString(CompileOptFormat),
                      LoadFarStringSmall(None));

                PRINTF(LoadFarString(EnvOptions));
                envptr = getenv(LoadFarStringSmall(EnvUnZip));
                PRINTF(LoadFarString(EnvOptFormat),
                  LoadFarStringSmall(EnvUnZip),
                  (envptr == (char *)NULL || *envptr == 0)?
                  LoadFarStringSmall2(None) : envptr);
                envptr = getenv(LoadFarStringSmall(EnvUnZip2));
                PRINTF(LoadFarString(EnvOptFormat),
                  LoadFarStringSmall(EnvUnZip2),
                  (envptr == (char *)NULL || *envptr == 0)?
                  LoadFarStringSmall2(None) : envptr);
                envptr = getenv(LoadFarStringSmall(EnvZipInfo));
                PRINTF(LoadFarString(EnvOptFormat),
                  LoadFarStringSmall(EnvZipInfo),
                  (envptr == (char *)NULL || *envptr == 0)?
                  LoadFarStringSmall2(None) : envptr);
                envptr = getenv(LoadFarStringSmall(EnvZipInfo2));
                PRINTF(LoadFarString(EnvOptFormat),
                  LoadFarStringSmall(EnvZipInfo2),
                  (envptr == (char *)NULL || *envptr == 0)?
                  LoadFarStringSmall2(None) : envptr);
#ifdef __EMX__
                envptr = getenv(LoadFarStringSmall(EnvEMX));
                PRINTF(LoadFarString(EnvOptFormat), LoadFarStringSmall(EnvEMX),
                  (envptr == (char *)NULL || *envptr == 0)?
                  LoadFarStringSmall2(None) : envptr);
                envptr = getenv(LoadFarStringSmall(EnvEMXOPT));
                PRINTF(LoadFarString(EnvOptFormat),
                  LoadFarStringSmall(EnvEMXOPT),
                  (envptr == (char *)NULL || *envptr == 0)?
                  LoadFarStringSmall2(None) : envptr);
#endif /* __EMX__ */
#ifdef __GO32__
                envptr = getenv(LoadFarStringSmall(EnvGO32));
                PRINTF(LoadFarString(EnvOptFormat), LoadFarStringSmall(EnvGO32),
                  (envptr == (char *)NULL || *envptr == 0)?
                  LoadFarStringSmall2(None) : envptr);
                envptr = getenv(LoadFarStringSmall(EnvGO32TMP));
                PRINTF(LoadFarString(EnvOptFormat),
                  LoadFarStringSmall(EnvGO32TMP),
                  (envptr == (char *)NULL || *envptr == 0)?
                  LoadFarStringSmall2(None) : envptr);
#endif /* __GO32__ */
            }
            return 0;
        } else
#endif /* !SFX */
            return usage(error);
    }

    if (cflag || tflag || vflag)
        extract_flag = FALSE;
    else
        extract_flag = TRUE;

    *pargc = argc;
    *pargv = argv;
    return 0;

} /* end function uz_opts() */





/********************/
/* Function usage() */
/********************/

#ifdef SFX
#  ifdef VMS
#    define LOCAL "X.  Quote uppercase options"
#  else
#    ifdef DOS_NT_OS2
#      define LOCAL "s$"
#    else
#       ifdef AMIGA
#         define LOCAL "$"
#       else
#         define LOCAL ""
#       endif
#    endif /* ?DOS_NT_OS2 */
#  endif /* ?VMS */

int usage(error)   /* return PK-type error code */
    int error;
{
    FILE *usagefp;

    if (error)
        usagefp = (FILE *)stderr;
    else
        usagefp = (FILE *)stdout;

    FPRINTF(usagefp, LoadFarString(UnzipSFXUsage),
      LoadFarStringSmall(UnzipVersion), LOCAL);
#ifdef BETA
    FPRINTF(usagefp, LoadFarString(BetaVersion), "\n", "SFX");
#endif

    if (error)
        return PK_PARAM;
    else
        return PK_COOL;     /* just wanted usage screen: no error */

} /* end function usage() */





#else /* !SFX */
#ifndef VMSCLI

int usage(error)   /* return PK-type error code */
    int error;
{
#ifdef VMS
#  define QUOT '\"'
#  define QUOTS "\""
#else
#  define QUOT ' '
#  define QUOTS ""
#endif

    FILE *usagefp;


/*---------------------------------------------------------------------------
    If user requested usage, send it to stdout; else send to stderr.
  ---------------------------------------------------------------------------*/

    if (error)
        usagefp = (FILE *)stderr;
    else
        usagefp = (FILE *)stdout;

/*---------------------------------------------------------------------------
    Print either ZipInfo usage or UnZip usage, depending on incantation.
    (Strings must be no longer than 512 bytes for Turbo C, apparently.)
  ---------------------------------------------------------------------------*/

    if (zipinfo_mode) {

#ifndef NO_ZIPINFO

        FPRINTF(usagefp, LoadFarString(ZipInfoUsageLine1),
          LoadFarStringSmall(ZipinfoVersion),
          LoadFarStringSmall2(ZipInfoExample), QUOTS,QUOTS);
        FPRINTF(usagefp, LoadFarString(ZipInfoUsageLine2));
        FPRINTF(usagefp, LoadFarString(ZipInfoUsageLine3), QUOT,QUOT);
#ifdef VMS
        FPRINTF(usagefp, "\nRemember that non-lowercase filespecs must be\
 quoted in VMS (e.g., \"Makefile\").\n");
#endif

#endif /* !NO_ZIPINFO */

    } else {   /* UnZip mode */

        FPRINTF(usagefp, LoadFarString(UnzipUsageLine1),
          LoadFarStringSmall(UnzipVersion));
#ifdef BETA
        FPRINTF(usagefp, LoadFarString(BetaVersion), "", "");
#endif
        FPRINTF(usagefp, LoadFarString(UnzipUsageLine2), ZIPINFO_MODE_OPTION,
          LoadFarStringSmall(ZipinfoMode));

        FPRINTF(usagefp, LoadFarString(UnzipUsageLine3));

        FPRINTF(usagefp, LoadFarString(UnzipUsageLine4), QUOT,QUOT, QUOT,QUOT,
                LoadFarStringSmall(loc_str), QUOT,QUOT,
                LoadFarStringSmall2(loc2str));

        /* This is extra work for SMALL_MEM, but it will work since
         * LoadFarStringSmall2 uses the same buffer.  Remember, this
         * is a hack. */
        FPRINTF(usagefp, LoadFarString(UnzipUsageLine5),
                LoadFarStringSmall(Example1),
                LoadFarStringSmall2(Example2),
                LoadFarStringSmall2(Example2));

    }

    if (error)
        return PK_PARAM;
    else
        return PK_COOL;     /* just wanted usage screen: no error */

} /* end function usage() */

#endif /* !VMSCLI */
#endif /* ?SFX */
#endif /* ?MSWIN */




/*******************************/
/* Function process_zipfiles() */
/*******************************/

int process_zipfiles()    /* return PK-type error code */
{
#ifndef SFX
    char *lastzipfn = (char *)NULL;
    int NumWinFiles, NumLoseFiles, NumWarnFiles;
    int NumMissDirs, NumMissFiles;
#endif
    int error=0, error_in_archive=0;


/*---------------------------------------------------------------------------
    Start by constructing the various PK signature strings.
  ---------------------------------------------------------------------------*/

    local_hdr_sig[0]  /* = extd_local_sig[0] */  = '\120';   /* ASCII 'P', */
    central_hdr_sig[0] = end_central_sig[0] = '\120';        /* not EBCDIC */

    strcpy(local_hdr_sig+1, LOCAL_HDR_SIG);
    strcpy(central_hdr_sig+1, CENTRAL_HDR_SIG);
    strcpy(end_central_sig+1, END_CENTRAL_SIG);
/*  strcpy(extd_local_sig+1, EXTD_LOCAL_SIG);   still to be used in multi? */

/*---------------------------------------------------------------------------
    Match (possible) wildcard zipfile specification with existing files and
    attempt to process each.  If no hits, try again after appending ".zip"
    suffix.  If still no luck, give up.
  ---------------------------------------------------------------------------*/

#ifdef SFX
    if ((error = do_seekable(0)) == PK_NOZIP) {
#ifdef EXE_EXTENSION
        int len=strlen(argv0);

        /* append .exe if appropriate; also .sfx? */
        if ((zipfn = (char *)malloc(len+5)) != (char *)NULL) {
            strcpy(zipfn, argv0);
            strcpy(zipfn+len, EXE_EXTENSION);
            error = do_seekable(0);
            free(zipfn);
            zipfn = argv0;  /* for "can't find myself" message only */
        }
#endif /* EXE_EXTENSION */
#ifdef NT
        zipfn = argv0;  /* for "can't find myself" message only */
#endif
    }
    if (error) {
        if (error == IZ_DIR)
            error_in_archive = PK_NOZIP;
        else
            error_in_archive = error;
        if (error == PK_NOZIP)
            FPRINTF(stderr, LoadFarString(CantFindMyself), zipfn);
    }

#else /* !SFX */
    NumWinFiles = NumLoseFiles = NumWarnFiles = 0;
    NumMissDirs = NumMissFiles = 0;

    while ((zipfn = do_wild(wildzipfn)) != (char *)NULL) {
        Trace((stderr, "do_wild( %s ) returns %s\n", wildzipfn, zipfn));

        lastzipfn = zipfn;

        /* print a blank line between the output of different zipfiles */
        if (!qflag  &&  error != PK_NOZIP  &&  error != IZ_DIR  &&
            (NumWinFiles+NumLoseFiles+NumWarnFiles+NumMissFiles) > 0)
            PRINTF("\n");
        FFLUSH(stdout);

        if ((error = do_seekable(0)) == PK_WARN)
            ++NumWarnFiles;
        else if (error == IZ_DIR)
            ++NumMissDirs;
        else if (error == PK_NOZIP)
            ++NumMissFiles;
        else if (error)
            ++NumLoseFiles;
        else
            ++NumWinFiles;

        if (error != IZ_DIR && error > error_in_archive)
            error_in_archive = error;
        Trace((stderr, "do_seekable(0) returns %d\n", error));

    } /* end while-loop (wildcard zipfiles) */

    if ((NumWinFiles + NumWarnFiles + NumLoseFiles) == 0  &&
        (NumMissDirs + NumMissFiles) == 1  &&  lastzipfn != (char *)NULL)
    {
        char *p = lastzipfn + strlen(lastzipfn);

        NumMissDirs = NumMissFiles = 0;
        if (error_in_archive == PK_NOZIP)
            error_in_archive = PK_COOL;
        zipfn = lastzipfn;
        strcpy(p, ".zip");

#ifdef UNIX
        if ((error = do_seekable(0)) == PK_NOZIP || error == IZ_DIR) {
            if (error == IZ_DIR)
                ++NumMissDirs;
            strcpy(p, ".ZIP");
            error = do_seekable(1);
        }
#else
        error = do_seekable(1);
#endif
        if (error == PK_WARN)
            ++NumWarnFiles;
        else if (error == IZ_DIR)
            ++NumMissDirs;
        else if (error == PK_NOZIP)
            /* if increment again => bug: "1 file had no zipfile directory." */
            /* ++NumMissFiles */ ;
        else if (error)

⌨️ 快捷键说明

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