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

📄 unzip.c

📁 完整的解压zip文件的源码。包含密码功能
💻 C
📖 第 1 页 / 共 4 页
字号:
/*---------------------------------------------------------------------------  unzip.c  UnZip - a zipfile extraction utility.  See below for make instructions, or  read the comments in Makefile and the various Contents files for more de-  tailed explanations.  To report a bug, send a *complete* description to  Zip-Bugs@lists.wku.edu; include machine type, operating system and ver-  sion, compiler and version, and reasonably detailed error messages or prob-  lem report.  To join Info-ZIP, see the instructions in README.  UnZip 5.x is a greatly expanded and partially rewritten successor to 4.x,  which in turn was almost a complete rewrite of version 3.x.  For a detailed  revision history, see UnzpHist.zip at quest.jpl.nasa.gov.  For a list of  the many (near infinite) contributors, see "CONTRIBS" in the UnZip source  distribution.  ---------------------------------------------------------------------------  [from original zipinfo.c]  This program reads great gobs of totally nifty information, including the  central directory stuff, from ZIP archives ("zipfiles" for short).  It  started as just a testbed for fooling with zipfiles, but at this point it  is actually a useful utility.  It also became the basis for the rewrite of  UnZip (3.16 -> 4.0), using the central directory for processing rather than  the individual (local) file headers.  As of ZipInfo v2.0 and UnZip v5.1, the two programs are combined into one.  If the executable is named "unzip" (or "unzip.exe", depending), it behaves  like UnZip by default; if it is named "zipinfo" or "ii", it behaves like  ZipInfo.  The ZipInfo behavior may also be triggered by use of unzip's -Z  option; for example, "unzip -Z [zipinfo_options] archive.zip".  Another dandy product from your buddies at Newtware!  Author:  Greg Roelofs, newt@pobox.com, http://pobox.com/~newt/           23 August 1990 -> April 1997  ---------------------------------------------------------------------------  Version:  unzip5??.{tar.Z | tar.gz | zip} for Unix, VMS, OS/2, MS-DOS, Amiga,              Atari, Windows 3.x/95/NT/CE, Macintosh, Human68K, Acorn RISC OS,              BeOS, SMS/QDOS, VM/CMS, MVS, AOS/VS and TOPS-20.  Decryption              requires sources in zcrypt28.zip.  See the accompanying "WHERE"              file in the main source distribution for ftp, uucp, BBS and mail-              server sites, or see http://www.cdrom.com/pub/infozip/UnZip.html .  Copyrights:  see accompanying file "COPYING" in UnZip source distribution.               (This software is free but NOT IN THE PUBLIC DOMAIN.  There               are some restrictions on commercial use.)  ---------------------------------------------------------------------------*/#define UNZIP_C#define UNZIP_INTERNAL#include "unzip.h"        /* includes, typedefs, macros, prototypes, etc. */#include "crypt.h"#include "version.h"#ifndef WINDLL            /* The WINDLL port uses windll/windll.c instead... *//*******************//* Local Functions *//*******************/#ifndef SFXstatic void  show_version_info  OF((__GPRO));#endif/*************//* Constants *//*************/#include "consts.h"  /* all constant global variables are in here */                     /* (non-constant globals were moved to globals.c) *//* constant local variables: */#ifndef SFX   static ZCONST char Far EnvUnZip[] = ENV_UNZIP;   static ZCONST char Far EnvUnZip2[] = ENV_UNZIP2;   static ZCONST char Far EnvZipInfo[] = ENV_ZIPINFO;   static ZCONST char Far EnvZipInfo2[] = ENV_ZIPINFO2;#ifdef RISCOS   static ZCONST char Far EnvUnZipExts[] = ENV_UNZIPEXTS;#endif /* RISCOS */#endif#if (!defined(SFX) || defined(SFX_EXDIR))   static ZCONST char Far NotExtracting[] =     "caution:  not extracting; -d ignored\n";   static ZCONST char Far MustGiveExdir[] =     "error:  must specify directory to which to extract with -d option\n";   static ZCONST char Far OnlyOneExdir[] =     "error:  -d option used more than once (only one exdir allowed)\n";#endif#if CRYPT   static ZCONST char Far MustGivePasswd[] =     "error:  must give decryption password with -P option\n";#endif#ifndef SFX   static ZCONST char Far Zfirst[] =   "error:  -Z must be first option for ZipInfo mode (check UNZIP variable?)\n";#endifstatic ZCONST char Far InvalidOptionsMsg[] = "error:\  -fn or any combination of -c, -l, -p, -t, -u and -v options invalid\n";static ZCONST char Far IgnoreOOptionMsg[] =  "caution:  both -n and -o specified; ignoring -o\n";/* usage() strings */#ifndef SFX#ifdef VMS   static ZCONST char Far Example3[] = "vms.c";   static ZCONST char Far Example2[] = "  unzip\ \"-V\" foo \"Bar\" => must quote uppercase options and filenames in VMS\n";#else /* !VMS */   static ZCONST char Far Example3[] = "ReadMe";#ifdef RISCOS   static ZCONST char Far Example2[] ="  unzip foo -d RAM:$   => extract all files from foo into RAMDisc\n";#else /* !RISCOS */#if (defined(OS2) || (defined(DOS_FLX_OS2_W32) && defined(MORE)))   static ZCONST char Far Example2[] =     "";                /* no room:  too many local3[] items */#else /* !OS2 */#ifdef MACOS   static ZCONST char Far Example2[] = ""; /* not needed */#else /* !MACOS */   static ZCONST char Far Example2[] = " \ unzip -p foo | more  => send contents of foo.zip via pipe into program more\n";#endif /* ?MACOS */#endif /* ?OS2 */#endif /* ?RISCOS */#endif /* ?VMS *//* local1[]:  command options */#if (defined(DLL) && defined(API_DOC))   static ZCONST char Far local1[] =     "  -A  print extended help for API functions";#else /* !(DLL && API_DOC) */   static ZCONST char Far local1[] = "";#endif /* ?(DLL && API_DOC) *//* local2[] and local3[]:  modifier options */#ifdef DOS_FLX_OS2_W32#ifdef FLEXOS   static ZCONST char Far local2[] = "";#else   static ZCONST char Far local2[] =     " -$  label removables (-$$ => fixed disks)";#endif#ifdef OS2#ifdef MORE   static ZCONST char Far local3[] = "\  -X  restore ACLs if supported              -s  spaces in filenames => '_'\n\                                             -M  pipe through \"more\" pager\n";#else   static ZCONST char Far local3[] = " \ -X  restore ACLs if supported              -s  spaces in filenames => '_'\n\n";#endif /* ?MORE */#else /* !OS2 */#ifdef WIN32#ifdef MORE   static ZCONST char Far local3[] = "\  -X  restore ACLs (-XX => use privileges)   -s  spaces in filenames => '_'\n\                                             -M  pipe through \"more\" pager\n";#else   static ZCONST char Far local3[] = " \ -X  restore ACLs (-XX => use privileges)   -s  spaces in filenames => '_'\n\n";#endif /* ?MORE */#else /* !WIN32 */#ifdef MORE   static ZCONST char Far local3[] = "  -\M  pipe through \"more\" pager              -s  spaces in filenames => '_'\n\n";#else   static ZCONST char Far local3[] = "\                                             -s  spaces in filenames => '_'\n";#endif#endif /* ?WIN32 */#endif /* ?OS2 || ?WIN32 */#else /* !DOS_FLX_OS2_W32 */#ifdef VMS   static ZCONST char Far local2[] = "\"-X\" restore owner/protection info";#ifdef MORE   static ZCONST char Far local3[] = "  \                                          \"-M\" pipe through \"more\" pager\n";#else   static ZCONST char Far local3[] = "\n";#endif#else /* !VMS */#if (defined(__BEOS__) || defined(TANDEM) || defined(UNIX))   static ZCONST char Far local2[] = " -X  restore UID/GID info";#ifdef MORE   static ZCONST char Far local3[] = "\                                             -M  pipe through \"more\" pager\n";#else   static ZCONST char Far local3[] = "\n";#endif#else /* !(__BEOS__ || TANDEM || UNIX) */#ifdef AMIGA   static ZCONST char Far local2[] = " -N  restore comments as filenotes";#ifdef MORE   static ZCONST char Far local3[] = "\                                             -M  pipe through \"more\" pager\n";#else   static ZCONST char Far local3[] = "\n";#endif#else /* !AMIGA */#ifdef MACOS   static ZCONST char Far local2[] = " -E  show Mac info during extraction";   static ZCONST char Far local3[] = " \ -i  ignore filenames in mac extra info     -J  junk (ignore) Mac extra info\n\n";#else /* !MACOS */#ifdef MORE   static ZCONST char Far local2[] = " -M  pipe through \"more\" pager";   static ZCONST char Far local3[] = "\n";#else   static ZCONST char Far local2[] = "";   /* Atari, Mac, CMS/MVS etc. */   static ZCONST char Far local3[] = "";#endif#endif /* ?MACOS */#endif /* ?AMIGA */#endif /* ?(__BEOS__ || TANDEM || UNIX) */#endif /* ?VMS */#endif /* ?DOS_FLX_OS2_W32 */#endif /* !SFX */#ifndef NO_ZIPINFO#ifdef VMS   static ZCONST char Far ZipInfoExample[] = "* or % (e.g., \"*font-%.zip\")";#else   static ZCONST char Far ZipInfoExample[] = "*, ?, [] (e.g., \"[a-j]*.zip\")";#endifstatic ZCONST char Far ZipInfoUsageLine1[] = "\ZipInfo %d.%d%d%s of %s, by Greg Roelofs and the Info-ZIP group.\n\\n\List name, date/time, attribute, size, compression method, etc., about files\n\in list (excluding those in xlist) contained in the specified .zip archive(s).\\n\"file[.zip]\" may be a wildcard name containing %s.\n\n\   usage:  zipinfo [-12smlvChMtTz] file[.zip] [list...] [-x xlist...]\n\      or:  unzip %s-Z%s [-12smlvChMtTz] file[.zip] [list...] [-x xlist...]\n";static ZCONST char Far ZipInfoUsageLine2[] = "\nmain\ listing-format options:             -s  short Unix \"ls -l\" format (def.)\n\  -1  filenames ONLY, one per line       -m  medium Unix \"ls -l\" format\n\  -2  just filenames but allow -h/-t/-z  -l  long Unix \"ls -l\" format\n\                                         -v  verbose, multi-page format\n";static ZCONST char Far ZipInfoUsageLine3[] = "miscellaneous options:\n\  -h  print header line       -t  print totals for listed files or for all\n\  -z  print zipfile comment  %c-T%c print file times in sortable decimal format\\n %c-C%c be case-insensitive   %s\  -x  exclude filenames that follow from listing\n";#ifdef MORE#ifdef VMS   static ZCONST char Far ZipInfoUsageLine4[] =     " \"-M\" page output through built-in \"more\"\n";#else   static ZCONST char Far ZipInfoUsageLine4[] =     "  -M  page output through built-in \"more\"\n";#endif#else /* !MORE */   static ZCONST char Far ZipInfoUsageLine4[] = "";#endif /* ?MORE */#endif /* !NO_ZIPINFO */#ifdef BETA#  ifdef VMSCLI   /* BetaVersion[] is also used in vms/cmdline.c:  do not make it static */     ZCONST char Far BetaVersion[] = "%s\        THIS IS STILL A BETA VERSION OF UNZIP%s -- DO NOT DISTRIBUTE.\n\n";#  else     static ZCONST char Far BetaVersion[] = "%s\        THIS IS STILL A BETA VERSION OF UNZIP%s -- DO NOT DISTRIBUTE.\n\n";#  endif#endif#ifdef SFX#  ifdef VMSCLI   /* UnzipSFXBanner[] is also used in vms/cmdline.c:  do not make it static */     ZCONST char Far UnzipSFXBanner[] =#  else     static ZCONST char Far UnzipSFXBanner[] =#  endif     "UnZipSFX %d.%d%d%s of %s, by Info-ZIP (Zip-Bugs@lists.wku.edu).\n";#  ifdef SFX_EXDIR     static ZCONST char Far UnzipSFXOpts[] =    "Valid options are -tfupcz and -d <exdir>; modifiers are -abjnoqCL%sV%s.\n";#  else     static ZCONST char Far UnzipSFXOpts[] =       "Valid options are -tfupcz; modifiers are -abjnoqCL%sV%s.\n";#  endif#else /* !SFX */   static ZCONST char Far CompileOptions[] =     "UnZip special compilation options:\n";   static ZCONST char Far CompileOptFormat[] = "\t%s\n";   static ZCONST char Far EnvOptions[] =     "\nUnZip and ZipInfo environment options:\n";   static ZCONST char Far EnvOptFormat[] = "%16s:  %s\n";   static ZCONST char Far None[] = "[none]";#  ifdef ACORN_FTYPE_NFS     static ZCONST char Far AcornFtypeNFS[] = "ACORN_FTYPE_NFS";#  endif#  ifdef ASM_CRC     static ZCONST char Far AsmCRC[] = "ASM_CRC";#  endif#  ifdef ASM_INFLATECODES     static ZCONST char Far AsmInflateCodes[] = "ASM_INFLATECODES";#  endif#  ifdef CHECK_VERSIONS     static ZCONST char Far Check_Versions[] = "CHECK_VERSIONS";#  endif#  ifdef COPYRIGHT_CLEAN     static ZCONST char Far Copyright_Clean[] =     "COPYRIGHT_CLEAN (PKZIP 0.9x unreducing method not supported)";#  endif#  ifdef DEBUG     static ZCONST char Far UDebug[] = "DEBUG";#  endif#  ifdef DEBUG_TIME     static ZCONST char Far DebugTime[] = "DEBUG_TIME";#  endif#  ifdef DLL     static ZCONST char Far Dll[] = "DLL";#  endif#  ifdef DOSWILD     static ZCONST char Far DosWild[] = "DOSWILD";#  endif#  ifdef LZW_CLEAN     static ZCONST char Far LZW_Clean[] =     "LZW_CLEAN (PKZIP/Zip 1.x unshrinking method not supported)";#  endif#  ifndef MORE     static ZCONST char Far No_More[] = "NO_MORE";#  endif#  ifdef NO_ZIPINFO     static ZCONST char Far No_ZipInfo[] = "NO_ZIPINFO";#  endif#  ifdef NTSD_EAS     static ZCONST char Far NTSDExtAttrib[] = "NTSD_EAS";#  endif#  ifdef OS2_EAS     static ZCONST char Far OS2ExtAttrib[] = "OS2_EAS";#  endif#  ifdef QLZIP     static ZCONST char Far SMSExFldOnUnix[] = "QLZIP";#  endif#  ifdef REENTRANT     static ZCONST char Far Reentrant[] = "REENTRANT";#  endif#  ifdef REGARGS     static ZCONST char Far RegArgs[] = "REGARGS";#  endif#  ifdef RETURN_CODES     static ZCONST char Far Return_Codes[] = "RETURN_CODES";#  endif#  ifdef SET_DIR_ATTRIB     static ZCONST char Far SetDirAttrib[] = "SET_DIR_ATTRIB";#  endif#  ifdef TIMESTAMP     static ZCONST char Far TimeStamp[] = "TIMESTAMP";#  endif#  ifdef UNIXBACKUP     static ZCONST char Far UnixBackup[] = "UNIXBACKUP";#  endif#  ifdef USE_EF_UT_TIME     static ZCONST char Far Use_EF_UT_time[] = "USE_EF_UT_TIME";#  endif#  ifndef LZW_CLEAN     static ZCONST char Far Use_Unshrink[] =     "USE_UNSHRINK (PKZIP/Zip 1.x unshrinking method supported)";#  endif#  ifndef COPYRIGHT_CLEAN     static ZCONST char Far Use_Smith_Code[] =     "USE_SMITH_CODE (PKZIP 0.9x unreducing method supported)";#  endif#  ifdef USE_VFAT     static ZCONST char Far Use_VFAT_support[] = "USE_VFAT";#  endif#  ifdef USE_ZLIB     static ZCONST char Far UseZlib[] =     "USE_ZLIB (compiled with version %s; using version %s)";#  endif#  ifdef VMS_TEXT_CONV     static ZCONST char Far VmsTextConv[] = "VMS_TEXT_CONV";#  endif#  ifdef VMSCLI     static ZCONST char Far VmsCLI[] = "VMSCLI";#  endif#  ifdef VMSWILD     static ZCONST char Far VmsWild[] = "VMSWILD";#  endif#  if CRYPT#    ifdef PASSWD_FROM_STDIN       static ZCONST char Far PasswdStdin[] = "PASSWD_FROM_STDIN";#    endif     static ZCONST char Far Decryption[] =       "\t[decryption, version %d.%d%s of %s]\n";     static ZCONST char Far CryptDate[] = CR_VERSION_DATE;#  endif#  ifndef __RSXNT__#    ifdef __EMX__       static ZCONST char Far EnvEMX[] = "EMX";       static ZCONST char Far EnvEMXOPT[] = "EMXOPT";#    endif#    if (defined(__GO32__) && (!defined(__DJGPP__) || (__DJGPP__ < 2)))       static ZCONST char Far EnvGO32[] = "GO32";       static ZCONST char Far EnvGO32TMP[] = "GO32TMP";#    endif#  endif /* !__RSXNT__ */#ifdef VMS/* UnzipUsageLine1[] is also used in vms/cmdline.c:  do not make it static */   ZCONST char Far UnzipUsageLine1[] = "\UnZip %d.%d%d%s of %s, by Info-ZIP.  For more details see: unzip -v.\n\n";#ifdef COPYRIGHT_CLEAN   static ZCONST char Far UnzipUsageLine1v[] = "\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 UnzipUsageLine1v[] = "\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 */

⌨️ 快捷键说明

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