📄 unzip.c
字号:
static char Far AsmInflateCodes[] = "ASM_INFLATECODES";
# endif
# ifdef ASM_CRC
static char Far AsmCRC[] = "ASM_CRC";
# endif
# ifdef REGARGS
static char Far RegArgs[] = "REGARGS";
# endif
# ifdef OLD_EXDIR
static char Far Old_Exdir[] = "OLD_EXDIR";
# endif
# ifdef CHECK_VERSIONS
static char Far Check_Versions[] = "CHECK_VERSIONS";
# endif
# ifdef RETURN_CODES
static char Far Return_Codes[] = "RETURN_CODES";
# endif
# ifdef RETURN_SEVERITY
static char Far Return_Severity[] = "RETURN_SEVERITY";
# endif
# ifdef DEBUG
static char Far Debug[] = "DEBUG";
# endif
# ifdef DEBUG_TIME
static char Far DebugTime[] = "DEBUG_TIME";
# endif
# ifdef CRYPT
static char Far Decryption[] = "[decryption]";
# endif
# ifdef __EMX__
static char Far EnvEMX[] = "EMX";
static char Far EnvEMXOPT[] = "EMXOPT";
# endif
# ifdef __GO32__
static char Far EnvGO32[] = "GO32";
static char Far EnvGO32TMP[] = "GO32TMP";
# endif
/* UnzipUsageLine1[] is also used in vms/cmdline.c: do not make it static */
char Far UnzipUsageLine1[] = "\
UnZip %s, by Info-ZIP. Portions (c) 1989 by S. H. Smith.\n\
Send bug reports to authors at zip-bugs@wkuvx1.wku.edu; see README for details.\
\n\n";
static char Far UnzipUsageLine2a[] = "\
Latest sources and executables are always in ftp.uu.net:/pub/archiving/zip, at\
\nleast as of date of this release; see \"Where\" for other ftp and non-ftp \
sites.\n\n";
#ifndef VMSCLI
static 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\n";
#ifdef NO_ZIPINFO
# define ZIPINFO_MODE_OPTION ""
static char Far ZipinfoMode[] =
"(ZipInfo mode is disabled in this version.)";
#else
# define ZIPINFO_MODE_OPTION "[-Z] "
# ifdef VMS
static char Far ZipinfoMode[] =
"\"-Z\" => ZipInfo mode (`unzip \"-Z\"' for usage).";
# else
static char Far ZipinfoMode[] =
"-Z => ZipInfo mode (\"unzip -Z\" for usage).";
# endif
#endif /* ?NO_ZIPINFO */
static char Far UnzipUsageLine3[] = "\
-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 which follow (in xlist) -d extract files into exdir\n\n";
static 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 (don't 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 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\n\
unzip -fo foo %-6s => quietly replace existing %s if archive file newer\n";
#endif /* !VMSCLI */
/* process_zipfiles() strings */
static char Far FilesProcessOK[] = "%d archive%s successfully processed.\n";
static char Far ArchiveWarning[] =
"%d archive%s had warnings but no fatal errors.\n";
static char Far ArchiveFatalError[] = "%d archive%s had fatal errors.\n";
static char Far FileHadNoZipfileDir[] =
"%d file%s had no zipfile directory.\n";
static char Far ZipfileWasDir[] = "1 \"zipfile\" was a directory.\n";
static char Far ManyZipfilesWereDir[] =
"%d \"zipfiles\" were directories.\n";
static char Far NoZipfileFound[] = "No zipfiles found.\n";
#endif /* ?SFX */
/* do_seekable() strings */
#ifndef SFX
#ifdef UNIX
static char Far CantFindZipfileDirMsg[] =
"%s: can't find zipfile directory in one of %s or\n\
%s%s.zip, and can't find %s, period.\n";
static char Far CantFindEitherZipfile[] =
"%s: can't find %s, %s.zip or %s, so there.\n";
#else /* !UNIX */
static char Far CantFindZipfileDirMsg[] =
"%s: can't find zipfile directory in %s,\n\
%sand can't find %s, period.\n";
static char Far CantFindEitherZipfile[] =
"%s: can't find either %s or %s, so there.\n";
#endif /* ?UNIX */
static char Far MaybeExe[] =
"note: %s may be a plain executable, not an archive\n";
static char Far CentDirNotInZipMsg[] = "\n\
Zipfile is part of a multi-disk archive, and this is not the disk on\n\
which the central zipfile directory begins.\n";
#ifdef NO_MULTIPART
static char Far NoMultiDiskArcSupport[] =
"\nerror [%s]: zipfile is part of multi-disk archive\n\
(sorry, not yet supported).\n";
static 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 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 char Far ExtraBytesAtStart[] =
"warning [%s]: extra %ld bytes at beginning or within zipfile\n\
(attempting to process anyway)\n";
#endif /* !SFX */
static char Far MissingBytes[] =
"error [%s]: missing %ld bytes in zipfile\n\
(attempting to process anyway)\n";
static char Far NullCentDirOffset[] =
"error [%s]: NULL central directory offset\n\
(attempting to process anyway)\n";
static char Far ZipfileEmpty[] = "warning [%s]: zipfile is empty\n";
static char Far CentDirStartNotFound[] =
"error [%s]: start of central directory not found;\n\
zipfile corrupt.\n%s";
static char Far ZipfileCommTrunc1[] = "\ncaution: zipfile comment truncated\n";
#ifdef MSWIN
# include "winsetup.c" /* duplicates some code in main() */
#else /* !MSWIN */
/******************/
/* Main program */
/******************/
int MAIN(argc, argv) /* return PK-type error code (except under VMS) */
int argc;
char *argv[];
{
#ifndef NO_ZIPINFO
char *p;
#endif
int error=FALSE;
#if defined(__IBMC__) && defined(__DEBUG_ALLOC__)
extern void DebugMalloc(void);
atexit(DebugMalloc);
#endif
/*---------------------------------------------------------------------------
Macintosh initialization code.
---------------------------------------------------------------------------*/
#ifdef MACOS
int a;
for (a = 0; a < 4; ++a)
rghCursor[a] = GetCursor(a+128);
giCursor = 0;
aflag=cflag=dflag=fflag=L_flag=jflag=qflag=tflag=uflag=vflag=zflag = 0;
local_hdr_sig[1] = central_hdr_sig[1] = end_central_sig[1] = '\0';
/* extd_local_sig[1] = '\0'; */
error = FALSE;
overwrite_none = overwrite_all = force_flag = 0;
#endif /* MACOS */
#ifdef MALLOC_WORK
area.Slide = (uch *)calloc(8193, sizeof(short)+sizeof(char)+sizeof(char));
area.shrink.Prefix_of = (short *)area.Slide;
area.shrink.Suffix_of = area.Slide + (sizeof(short)*(HSIZE+1));
area.shrink.Stack = area.Slide + (sizeof(short) + sizeof(char))*(HSIZE+1);
#endif
/*---------------------------------------------------------------------------
Human68K initialization code.
---------------------------------------------------------------------------*/
#ifdef __human68k__
InitTwentyOne();
#endif
/*---------------------------------------------------------------------------
Set signal handler for restoring echo, warn of zipfile corruption, etc.
---------------------------------------------------------------------------*/
signal(SIGINT, handler);
#ifdef SIGTERM /* some systems really have no SIGTERM */
signal(SIGTERM, handler);
#endif
#ifdef SIGBUS
signal(SIGBUS, handler);
#endif
#ifdef SIGSEGV
signal(SIGSEGV, handler);
#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
argv0 = argv[0];
#if defined(OS2) || defined(NT)
zipfn = GetLoadPath(); /* non-MSC NT puts path into filename[] */
#else
zipfn = argv0;
#endif
zipinfo_mode = FALSE;
if ((error = uz_opts(&argc, &argv)) != 0)
RETURN(error);
#else /* !SFX */
#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 */
#ifndef NO_ZIPINFO
if ((p = strrchr(argv[0], DIR_END)) == (char *)NULL)
p = argv[0];
else
++p;
if (STRNICMP(p, "zipinfo", 7) == 0 || STRNICMP(p, "ii", 2) == 0 ||
(argc > 1 && strncmp(argv[1], "-Z", 2) == 0))
{
zipinfo_mode = TRUE;
envargs(&argc, &argv, LoadFarStringSmall(EnvZipInfo),
LoadFarStringSmall2(EnvZipInfo2));
error = zi_opts(&argc, &argv);
} else
#endif /* NO_ZIPINFO */
{
zipinfo_mode = FALSE;
envargs(&argc, &argv, LoadFarStringSmall(EnvUnZip),
LoadFarStringSmall2(EnvUnZip2));
error = uz_opts(&argc, &argv);
}
if ((argc < 0) || error)
RETURN(error);
#endif /* ?SFX */
/*---------------------------------------------------------------------------
Now get the zipfile name from the command line and then process any re-
maining options and file specifications.
---------------------------------------------------------------------------*/
#ifdef DOS_NT_OS2
/* convert MSDOS-style directory separators to Unix-style ones for
* user's convenience (include zipfile name itself)
*/
pfnames = argv;
while (*pfnames != NULL) {
char *q;
for (q = *pfnames; *q; ++q)
if (*q == '\\')
*q = '/';
++pfnames;
}
#endif /* DOS_NT_OS2 */
#ifndef SFX
wildzipfn = *argv++;
#endif
#if (defined(OLD_EXDIR) || (defined(SFX) && !defined(SFX_EXDIR)))
#ifndef SFX
if (argc > 0) {
/* -d: "name/" immediately after zipfile name is a stored directory to
* be extracted--do NOT treat as directory to which to extract files
*/
if (extract_flag && !dflag) {
create_dirs = !fflag;
if ((error = checkdir(*argv, ROOT)) > 2) /* mem, or file in way */
RETURN(error);
else if (!error) { /* it IS extract-to dir, so adjust pointers */
++argv;
--argc;
}
}
}
#endif /* !SFX */
filespecs = argc;
xfilespecs = 0;
if (argc > 0) {
char **pp = argv-1;
pfnames = argv;
while (*++pp)
if (strcmp(*pp, "-x") == 0) {
if (pp > argv) {
*pp = 0; /* terminate pfnames */
filespecs = pp - pfnames;
} else {
pfnames = fnames; /* defaults */
filespecs = 0;
}
pxnames = pp + 1; /* excluded-names ptr starts after -x */
xfilespecs = argc - filespecs - 1;
break; /* skip rest of args */
}
process_all_files = FALSE;
} else
process_all_files = TRUE; /* for speed */
#else /* !(OLD_EXDIR || (SFX && !SFX_EXDIR)) */
filespecs = argc;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -