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

📄 process.c

📁 压缩解压,是unzip540的升级,这个外国网站摘来的源码,是evb编写.
💻 C
📖 第 1 页 / 共 5 页
字号:
/*  Copyright (c) 1990-2004 Info-ZIP.  All rights reserved.  See the accompanying file LICENSE, version 2000-Apr-09 or later  (the contents of which are also included in unzip.h) for terms of use.  If, for some reason, all these files are missing, the Info-ZIP license  also may be found at:  ftp://ftp.info-zip.org/pub/infozip/license.html*//*---------------------------------------------------------------------------  process.c  This file contains the top-level routines for processing multiple zipfiles.  Contains:  process_zipfiles()             free_G_buffers()             do_seekable()             find_ecrec()             uz_end_central()             process_cdir_file_hdr()             get_cdir_ent()             process_local_file_hdr()             ef_scan_for_izux()             getRISCOSexfield()  ---------------------------------------------------------------------------*/#define UNZIP_INTERNAL#include "unzip.h"#ifdef WINDLL#  ifdef POCKET_UNZIP#    include "wince/intrface.h"#  else#    include "windll/windll.h"#  endif#endifstatic int    do_seekable        OF((__GPRO__ int lastchance));static int    find_ecrec         OF((__GPRO__ long searchlen));static ZCONST char Far CannotAllocateBuffers[] =  "error:  cannot allocate unzip buffers\n";#ifdef SFX   static ZCONST char Far CannotFindMyself[] =     "unzipsfx:  cannot find myself! [%s]\n";# ifdef CHEAP_SFX_AUTORUN   static ZCONST char Far AutorunPrompt[] =     "\nAuto-run command: %s\nExecute this command? [y/n] ";   static ZCONST char Far NotAutoRunning[] =     "Not executing auto-run command.";# endif#else /* !SFX */   /* process_zipfiles() strings */# if (defined(IZ_CHECK_TZ) && defined(USE_EF_UT_TIME))     static ZCONST char Far WarnInvalidTZ[] =       "Warning: TZ environment variable not found, cannot use UTC times!!\n";# endif   static ZCONST char Far FilesProcessOK[] =     "%d archive%s successfully processed.\n";   static ZCONST char Far ArchiveWarning[] =     "%d archive%s had warnings but no fatal errors.\n";   static ZCONST char Far ArchiveFatalError[] =     "%d archive%s had fatal errors.\n";   static ZCONST char Far FileHadNoZipfileDir[] =     "%d file%s had no zipfile directory.\n";   static ZCONST char Far ZipfileWasDir[] = "1 \"zipfile\" was a directory.\n";   static ZCONST char Far ManyZipfilesWereDir[] =     "%d \"zipfiles\" were directories.\n";   static ZCONST char Far NoZipfileFound[] = "No zipfiles found.\n";   /* do_seekable() strings */# ifdef UNIX   static ZCONST char Far CannotFindZipfileDirMsg[] =     "%s:  cannot find zipfile directory in one of %s or\n\        %s%s.zip, and cannot find %s, period.\n";   static ZCONST char Far CannotFindEitherZipfile[] =     "%s:  cannot find or open %s, %s.zip or %s.\n";# else /* !UNIX */# ifndef AMIGA   static ZCONST char Far CannotFindWildcardMatch[] =     "%s:  cannot find any matches for wildcard specification \"%s\".\n";# endif /* !AMIGA */   static ZCONST char Far CannotFindZipfileDirMsg[] =     "%s:  cannot find zipfile directory in %s,\n\        %sand cannot find %s, period.\n";   static ZCONST char Far CannotFindEitherZipfile[] =     "%s:  cannot find either %s or %s.\n";# endif /* ?UNIX */   extern ZCONST char Far Zipnfo[];       /* in unzip.c */#ifndef WINDLL   static ZCONST char Far Unzip[] = "unzip";#else   static ZCONST char Far Unzip[] = "UnZip DLL";#endif   static ZCONST char Far MaybeExe[] =     "note:  %s may be a plain executable, not an archive\n";   static ZCONST char Far CentDirNotInZipMsg[] = "\n\   [%s]:\n\     Zipfile is disk %u of a multi-disk archive, and this is not the disk on\n\     which the central zipfile directory begins (disk %u).\n";   static ZCONST char Far EndCentDirBogus[] =     "\nwarning [%s]:  end-of-central-directory record claims this\n\  is disk %u but that the central directory starts on disk %u; this is a\n\  contradiction.  Attempting to process anyway.\n";# ifdef NO_MULTIPART   static ZCONST char Far NoMultiDiskArcSupport[] =     "\nerror [%s]:  zipfile is part of multi-disk archive\n\  (sorry, not yet supported).\n";   static ZCONST char Far MaybePakBug[] = "warning [%s]:\  zipfile claims to be 2nd disk of a 2-part archive;\n\  attempting to process anyway.  If no further errors occur, this archive\n\  was probably created by PAK v2.51 or earlier.  This bug was reported to\n\  NoGate in March 1991 and was supposed to have been fixed by mid-1991; as\n\  of mid-1992 it still hadn't been.  (If further errors do occur, archive\n\  was probably created by PKZIP 2.04c or later; UnZip does not yet support\n\  multi-part archives.)\n";# else   static ZCONST char Far MaybePakBug[] = "warning [%s]:\  zipfile claims to be last disk of a multi-part archive;\n\  attempting to process anyway, assuming all parts have been concatenated\n\  together in order.  Expect \"errors\" and warnings...true multi-part support\\n  doesn't exist yet (coming soon).\n";# endif   static ZCONST char Far ExtraBytesAtStart[] =     "warning [%s]:  %ld extra byte%s at beginning or within zipfile\n\  (attempting to process anyway)\n";#endif /* ?SFX */static ZCONST char Far MissingBytes[] =  "error [%s]:  missing %ld bytes in zipfile\n\  (attempting to process anyway)\n";static ZCONST char Far NullCentDirOffset[] =  "error [%s]:  NULL central directory offset\n\  (attempting to process anyway)\n";static ZCONST char Far ZipfileEmpty[] = "warning [%s]:  zipfile is empty\n";static ZCONST char Far CentDirStartNotFound[] =  "error [%s]:  start of central directory not found;\n\  zipfile corrupt.\n%s";#ifndef SFX   static ZCONST char Far CentDirTooLong[] =     "error [%s]:  reported length of central directory is\n\  %ld bytes too long (Atari STZip zipfile?  J.H.Holm ZIPSPLIT 1.1\n\  zipfile?).  Compensating...\n";   static ZCONST char Far CentDirEndSigNotFound[] = "\  End-of-central-directory signature not found.  Either this file is not\n\  a zipfile, or it constitutes one disk of a multi-part archive.  In the\n\  latter case the central directory and zipfile comment will be found on\n\  the last disk(s) of this archive.\n";#else /* SFX */   static ZCONST char Far CentDirEndSigNotFound[] =     "  End-of-central-directory signature not found.\n";#endif /* ?SFX */static ZCONST char Far ZipfileCommTrunc1[] =  "\ncaution:  zipfile comment truncated\n";/*******************************//* Function process_zipfiles() *//*******************************/int process_zipfiles(__G)    /* return PK-type error code */    __GDEF{#ifndef SFX    char *lastzipfn = (char *)NULL;    int NumWinFiles, NumLoseFiles, NumWarnFiles;    int NumMissDirs, NumMissFiles;#endif    int error=0, error_in_archive=0;/*---------------------------------------------------------------------------    Start by allocating buffers and (re)constructing the various PK signature    strings.  ---------------------------------------------------------------------------*/    G.inbuf = (uch *)malloc(INBUFSIZ + 4);    /* 4 extra for hold[] (below) */    G.outbuf = (uch *)malloc(OUTBUFSIZ + 1);  /* 1 extra for string term. */    if ((G.inbuf == (uch *)NULL) || (G.outbuf == (uch *)NULL)) {        Info(slide, 0x401, ((char *)slide,          LoadFarString(CannotAllocateBuffers)));        return(PK_MEM);    }    G.hold = G.inbuf + INBUFSIZ;     /* to check for boundary-spanning sigs */#ifndef VMS     /* VMS uses its own buffer scheme for textmode flush(). */#ifdef SMALL_MEM    G.outbuf2 = G.outbuf+RAWBUFSIZ;  /* never changes */#endif#endif /* !VMS */#if 0 /* CRC_32_TAB has been NULLified by CONSTRUCTGLOBALS !!!! */    /* allocate the CRC table only later when we know we have a zipfile */    CRC_32_TAB = NULL;#endif /* 0 */    /* finish up initialization of magic signature strings */    local_hdr_sig[0]  /* = extd_local_sig[0] */ =       /* ASCII 'P', */      central_hdr_sig[0] = end_central_sig[0] = 0x50;   /* not EBCDIC */    local_hdr_sig[1]  /* = extd_local_sig[1] */ =       /* ASCII 'K', */      central_hdr_sig[1] = end_central_sig[1] = 0x4B;   /* not EBCDIC *//*---------------------------------------------------------------------------    Make sure timezone info is set correctly; localtime() returns GMT on    some OSes (e.g., Solaris 2.x) if this isn't done first.  The ifdefs were    initially copied from dos_to_unix_time() in fileio.c. probably, they are    still too strict; any listed OS that supplies tzset(), regardless of    whether the function does anything, should be removed from the ifdefs.  ---------------------------------------------------------------------------*/#if (defined(WIN32) && defined(USE_EF_UT_TIME))    /* For the Win32 environment, we may have to "prepare" the environment       prior to the tzset() call, to work around tzset() implementation bugs.     */    iz_w32_prepareTZenv();#endif#if (defined(IZ_CHECK_TZ) && defined(USE_EF_UT_TIME))#  ifndef VALID_TIMEZONE#     define VALID_TIMEZONE(tmp) \             (((tmp = getenv("TZ")) != NULL) && (*tmp != '\0'))#  endif    {        char *p;        G.tz_is_valid = VALID_TIMEZONE(p);#  ifndef SFX        if (!G.tz_is_valid) {            Info(slide, 0x401, ((char *)slide, LoadFarString(WarnInvalidTZ)));            error_in_archive = error = PK_WARN;        }#  endif /* !SFX */    }#endif /* IZ_CHECK_TZ && USE_EF_UT_TIME *//* For systems that do not have tzset() but supply this function using another   name (_tzset() or something similar), an appropiate "#define tzset ..."   should be added to the system specifc configuration section.  */#if (!defined(T20_VMS) && !defined(MACOS) && !defined(RISCOS) && !defined(QDOS))#if (!defined(BSD) && !defined(MTS) && !defined(CMS_MVS) && !defined(TANDEM))    tzset();#endif#endif/*---------------------------------------------------------------------------    Initialize the internal flag holding the mode of processing "overwrite    existing file" cases.  We do not use the calling interface flags directly    because the overwrite mode may be changed by user interaction while    processing archive files.  Such a change should not affect the option    settings as passed through the DLL calling interface.    In case of conflicting options, the 'safer' flag uO.overwrite_none takes    precedence.  ---------------------------------------------------------------------------*/    G.overwrite_mode = (uO.overwrite_none ? OVERWRT_NEVER :                        (uO.overwrite_all ? OVERWRT_ALWAYS : OVERWRT_QUERY));/*---------------------------------------------------------------------------    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(__G__ 0)) == PK_NOZIP) {#ifdef EXE_EXTENSION        int len=strlen(G.argv0);        /* append .exe if appropriate; also .sfx? */        if ( (G.zipfn = (char *)malloc(len+sizeof(EXE_EXTENSION))) !=             (char *)NULL ) {            strcpy(G.zipfn, G.argv0);            strcpy(G.zipfn+len, EXE_EXTENSION);            error = do_seekable(__G__ 0);            free(G.zipfn);            G.zipfn = G.argv0;  /* for "cannot find myself" message only */        }#endif /* EXE_EXTENSION */#ifdef WIN32        G.zipfn = G.argv0;  /* for "cannot 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)            Info(slide, 1, ((char *)slide, LoadFarString(CannotFindMyself),              G.zipfn));    }#ifdef CHEAP_SFX_AUTORUN    if (G.autorun_command[0] && !uO.qflag) { /* NO autorun without prompt! */        Info(slide, 0x81, ((char *)slide, LoadFarString(AutorunPrompt),                      FnFilter1(G.autorun_command)));        if (fgets(G.answerbuf, 9, stdin) != (char *)NULL            && toupper(*G.answerbuf) == 'Y')            system(G.autorun_command);        else            Info(slide, 1, ((char *)slide, LoadFarString(NotAutoRunning)));    }#endif /* CHEAP_SFX_AUTORUN */#else /* !SFX */    NumWinFiles = NumLoseFiles = NumWarnFiles = 0;    NumMissDirs = NumMissFiles = 0;    while ((G.zipfn = do_wild(__G__ G.wildzipfn)) != (char *)NULL) {        Trace((stderr, "do_wild( %s ) returns %s\n", G.wildzipfn, G.zipfn));        lastzipfn = G.zipfn;        /* print a blank line between the output of different zipfiles */        if (!uO.qflag  &&  error != PK_NOZIP  &&  error != IZ_DIR#ifdef TIMESTAMP            && (!uO.T_flag || uO.zipinfo_mode)#endif            && (NumWinFiles+NumLoseFiles+NumWarnFiles+NumMissFiles) > 0)            (*G.message)((zvoid *)&G, (uch *)"\n", 1L, 0);        if ((error = do_seekable(__G__ 0)) == PK_WARN)            ++NumWarnFiles;        else if (error == IZ_DIR)            ++NumMissDirs;        else if (error == PK_NOZIP)            ++NumMissFiles;        else if (error)            ++NumLoseFiles;        else            ++NumWinFiles;        Trace((stderr, "do_seekable(0) returns %d\n", error));

⌨️ 快捷键说明

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