Initial checkin. funzip is the only thing that doesn't build

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1101 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
DarkWyrm 2002-09-21 14:54:45 +00:00
parent e619086410
commit 3ae76c23c8
58 changed files with 29081 additions and 0 deletions

80
src/apps/bin/unzip/BUGS Normal file
View File

@ -0,0 +1,80 @@
Bogus bugs (not our fault!):
---------------------------
By far THE BIGGEST source of bug reports to Info-ZIP/zip-bugs is the
incorrect transfer of zipfiles (or of the UnZip executable itself).
ALWAYS TRANSFER IN BINARY MODE! This includes ftp transfers and *both*
ends of a Kermit connection ("set file type binary"). If your copy
isn't exactly the same size as the original, you made a mistake.
Another common source of errors such as "compression method 8 not sup-
ported" is the existence of an old version of UnZip somewhere in your
path. Make sure you're using the version you think you're using; give
the full path explicitly if necessary. Executing "unzip" without any
options will print a help screen, at the top of which is the UnZip
version number and release date; and executing "unzip -v" without any
zipfile or other options will give information about what compiler was
used, the target operating system, any special UnZip options, and the
date of compilation--only for version 5.11 and later, though! (Also,
under Unix C shell and some Bourne shells, "which unzip" will print
the path of the unzip you're actually using. Under OS/2 and MS-DOS,
whch21gr.zip [on Simtel mirror sites] will do the same thing; in addi-
tion, "which -a unzip" will show *all* copies of "unzip" in your path.)
Bugs (real and/or imagined):
---------------------------
- [OS/2 DLL] when trying to use the REXX function UzUnZipToStem to extract a
file with `&' in its name, the DLL crashes (but UzUnZipToVar still works)
[Daniel H, 961215]
- UnZip has problems with archives bigger than 2GB; it may print "note: didn't
find end-of-central-dir signature at end of central dir" (harmless) or
may not be able to seek to member files [James Lemley 970107, Iris Spaniol
970206, ...]
- fix overwrite behavior: hidden/system problems?; etc.
- 32-bit DOS UnZip still unable to set volume labels?
- 32-bit DOS UnZip under OS/2 doesn't extract all wildcard zipfiles?
[DOS box: unzip386 (ver 5.12) x:\32bit\unix\emx09a\*.zip, Hobbes 3/95]
- 32-bit DOS UnZip under OS/2 doesn't set timestamp when overwriting files
on HPFS partition? (go32 and pmode/w both; emx/rsx OK) [Eberhard Mattes
950726]
- USE_FWRITE still causes occasional CRC errors when extracting on Pyramid?
[Kevin Fritz 931102]
- still NT/W95 bug with "unzip -v d:*.zip" not matching properly? [Steve S
940527]
980427: bug no longer exists, Opendir() must have been corrected by someone
- when ^Z received in no-echo mode, echo is not restored (works OK if
resume, however)
- signal() handler disabled after first use with one of BSD/SysV?
- MKS Korn shell: unzip assumes the MKS-style command-line environment
options are relevant to it, but this is not the case if unzip was called
by another program (e.g., from a .BAT file). A fix for this exists for
Borland compilers but not for MSC, Watcom, djgpp, etc.
- OS/2: for paths with one long component, the .LONGNAME EA may be saved for
all components (waste of disk space): how to check??
- VMS: for extracting to other directories, only the VMS-style "-d [.foo]"
format is accepted; "-d foo" should also be allowed. Long filenames are
not automatically truncated to 39.39.
- Novell Netware: Netware drives may clear the archive bit on extracted
files under OS/2 and/or MS-DOS. UnZip always *tries* to set the archive
bit, however. [pynq@uchicago, 940527]
- DEC Ultrix: on long zipfiles, unzip will sometimes fail (bad CRC, not always
reproducible); this is apparently due either to a hardware bug (cache mem)
or OS bug (page faults?) [Igor, Jean-loup, bottom of BUGS.long]
- funzip/more/decryption/no-echo bug: race condition(?) causes terminal to
be "reset" to no-echo state
- Macintosh (100200), Atari (020000) external file attributes not interpreted
correctly (both unzip and zipinfo)
- pkbug error: zipfile with incorrect csize and/or ucsize--check for end of
compressed (csize) data in uncompression routines:
unreduce.c: while (((outpos + outcnt) < ucsize) && (!zipeof)) {
[James Birdsall, Mark, bottom of BUGS.long]
- OS/2: directory EAs not restored if directory exists [Kai Uwe, KG27515@uark]
(subsequent note: no way to determine which EAs are newer ==> cannot
restore without user input)
(update: as of UnZip 5.30, option -o forces restoring of directory EAs)
- MS-DOS: Borland executables don't allow other than 80-column, 25/43/50-line
screen modes (Borland bug) [Michael Stillwell]

View File

@ -0,0 +1,62 @@
SubDir OBOS_TOP src apps bin unzip ;
BinCommand unzip :
unzip.c
crc32.c
crctab.c
crypt.c
envargs.c
explode.c
extract.c
fileio.c
globals.c
inflate.c
list.c
match.c
process.c
ttyio.c
unreduce.c
unshrink.c
zipinfo.c
beos.c
beosmain.cpp
;
LinkSharedOSLibs unzip : be ;
# Gettng funzip to build is going to require quite a bit more work than the other two...
#BinCommand funzip :
# funzip.c
# funzipdefs.c
# crc32.c
# crypt.c
# globals.c
# inflate.c
# ttyio.c
#;
#LinkSharedOSLibs funzip : be ;
BinCommand unzipsfx :
unzip.c
crc32.c
crctab.c
crypt.c
extract.c
fileio.c
globals.c
inflate.c
match.c
process.c
ttyio.c
beos.c
beosmain.cpp
sfxdefs.c
envargs.c
zipinfo.c
list.c
explode.c
;
LinkSharedOSLibs unzipsfx : be ;

View File

@ -0,0 +1,53 @@
This is version 2002-Feb-16 of the Info-ZIP copyright and license.
The definitive version of this document should be available at
ftp://ftp.info-zip.org/pub/infozip/license.html indefinitely.
Copyright (c) 1990-2002 Info-ZIP. All rights reserved.
For the purposes of this copyright and license, "Info-ZIP" is defined as
the following set of individuals:
Mark Adler, John Bush, Karl Davis, Harald Denker, Jean-Michel Dubois,
Jean-loup Gailly, Hunter Goatley, Ian Gorman, Chris Herborth, Dirk Haase,
Greg Hartwig, Robert Heath, Jonathan Hudson, Paul Kienitz, David Kirschbaum,
Johnny Lee, Onno van der Linden, Igor Mandrichenko, Steve P. Miller,
Sergio Monesi, Keith Owens, George Petrov, Greg Roelofs, Kai Uwe Rommel,
Steve Salisbury, Dave Smith, Christian Spieler, Antoine Verheijen,
Paul von Behren, Rich Wales, Mike White
This software is provided "as is," without warranty of any kind, express
or implied. In no event shall Info-ZIP or its contributors be held liable
for any direct, indirect, incidental, special or consequential damages
arising out of the use of or inability to use this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. Redistributions of source code must retain the above copyright notice,
definition, disclaimer, and this list of conditions.
2. Redistributions in binary form (compiled executables) must reproduce
the above copyright notice, definition, disclaimer, and this list of
conditions in documentation and/or other materials provided with the
distribution. The sole exception to this condition is redistribution
of a standard UnZipSFX binary as part of a self-extracting archive;
that is permitted without inclusion of this license, as long as the
normal UnZipSFX banner has not been removed from the binary or disabled.
3. Altered versions--including, but not limited to, ports to new operating
systems, existing ports with new graphical interfaces, and dynamic,
shared, or static library versions--must be plainly marked as such
and must not be misrepresented as being the original source. Such
altered versions also must not be misrepresented as being Info-ZIP
releases--including, but not limited to, labeling of the altered
versions with the names "Info-ZIP" (or any variation thereof, including,
but not limited to, different capitalizations), "Pocket UnZip," "WiZ"
or "MacZip" without the explicit permission of Info-ZIP. Such altered
versions are further prohibited from misrepresentative use of the
Zip-Bugs or Info-ZIP e-mail addresses or of the Info-ZIP URL(s).
4. Info-ZIP retains the right to use the names "Info-ZIP," "Zip," "UnZip,"
"UnZipSFX," "WiZ," "Pocket UnZip," "Pocket Zip," and "MacZip" for its
own source and binary releases.

143
src/apps/bin/unzip/Makefile Normal file
View File

@ -0,0 +1,143 @@
ifeq ($(WHAT)x, x)
###
include $(BUILDHOME)/etc/makefile-engine
###
LIST = \
unzip \
funzip \
unzipsfx
install: FORCE
for WHAT in $(LIST); do \
$(MAKE) $(PARALLELMFLAGS) WHAT=$$WHAT $@; \
done
ln -sf unzip $(INSTALL_BIN)/zipinfo
install -m 0644 unix/zipgrep $(INSTALL_BIN)
clean: FORCE
-rm -rf $(OBJ_DIR)
.DEFAULT: FORCE
for WHAT in $(LIST); do \
$(MAKE) $(PARALLELMFLAGS) WHAT=$$WHAT $@; \
done
FORCE:
else
SHELL = /bin/sh
###
include $(BUILDHOME)/etc/makefile-engine
###
TARGET = $(OBJ_DIR)/$(WHAT)
APP_VERSION = -app 5 4 0 f 0 -short 5.4 -long "5.4 "`echo -n -e '\302\251'`" 1998 Info-ZIP et. al."
LDFLAGS += -lbe
VPATH = .:beos
ifeq ($(WHAT), unzip)
SRCS = \
unzip.c \
crc32.c \
crctab.c \
crypt.c \
envargs.c \
explode.c \
extract.c \
fileio.c \
globals.c \
inflate.c \
list.c \
match.c \
process.c \
ttyio.c \
unreduce.c \
unshrink.c \
zipinfo.c \
beos.c \
beosmain.c
endif
ifeq ($(WHAT), unzipsfx)
SRCS = \
unzipsfx.c \
crc32.c \
crctab.c \
crypt.c \
extract_.c \
fileio.c \
globals.c \
inflate.c \
match.c \
process_.c \
ttyio.c \
beos_.c \
beosmain.c
endif
ifeq ($(WHAT), funzip)
SRCS = \
funzip.c \
crc32.c \
crypt_.c \
globals_.c \
inflate_.c \
ttyio_.c
endif
OBJS = $(SRCS_LIST_TO_OBJS)
INCLUDES += -I. -Ibeos
CFLAGS += -DPASSWD_FROM_STDIN
$(TARGET): $(OBJ_DIR) $(OBJS)
$(LD) -o $@ $(OBJS) $(LDFLAGS)
$(SETVERSION) $@ $(SYSTEM_VERSION) $(APP_VERSION)
$(OBJ_DIR)/crypt_.o: crypt.c $(OBJ_DIR)
cp -f crypt.c $(OBJ_DIR)/crypt_.c
$(CC) -c $(INCLUDES) $(CFLAGS) -DFUNZIP $(OBJ_DIR)/crypt_.c -o $(OBJ_DIR)/crypt_.o
$(OBJ_DIR)/extract_.o: extract.c $(OBJ_DIR)
cp -f extract.c $(OBJ_DIR)/extract_.c
$(CC) -c $(INCLUDES) $(CFLAGS) -DSFX $(OBJ_DIR)/extract_.c -o $(OBJ_DIR)/extract_.o
$(OBJ_DIR)/globals_.o: globals.c $(OBJ_DIR)
cp -f globals.c $(OBJ_DIR)/globals_.c
$(CC) -c $(INCLUDES) $(CFLAGS) -DFUNZIP $(OBJ_DIR)/globals_.c -o $(OBJ_DIR)/globals_.o
$(OBJ_DIR)/inflate_.o: inflate.c $(OBJ_DIR)
cp -f inflate.c $(OBJ_DIR)/inflate_.c
$(CC) -c $(INCLUDES) $(CFLAGS) -DFUNZIP $(OBJ_DIR)/inflate_.c -o $(OBJ_DIR)/inflate_.o
$(OBJ_DIR)/ttyio_.o: ttyio.c $(OBJ_DIR)
cp -f ttyio.c $(OBJ_DIR)/ttyio_.c
$(CC) -c $(INCLUDES) $(CFLAGS) -DFUNZIP $(OBJ_DIR)/ttyio_.c -o $(OBJ_DIR)/ttyio_.o
$(OBJ_DIR)/process_.o: process.c $(OBJ_DIR)
cp -f process.c $(OBJ_DIR)/process_.c
$(CC) -c $(INCLUDES) $(CFLAGS) -DSFX $(OBJ_DIR)/process_.c -o $(OBJ_DIR)/process_.o
$(OBJ_DIR)/beos_.o: beos/beos.c $(OBJ_DIR)
cp -f beos/beos.c $(OBJ_DIR)/beos_.c
$(CC) -c $(INCLUDES) $(CFLAGS) -DSFX $(OBJ_DIR)/beos_.c -o $(OBJ_DIR)/beos_.o
$(OBJ_DIR)/beosmain.o: beos/beosmain.cpp $(OBJ_DIR)
$(CC) -c $(INCLUDES) $(CFLAGS) beos/beosmain.cpp -o $(OBJ_DIR)/beosmain.o
$(OBJ_DIR)/unzipsfx.o: unzip.c $(OBJ_DIR)
cp -f unzip.c $(OBJ_DIR)/unzipsfx.c
$(CC) -c $(INCLUDES) $(CFLAGS) -DSFX $(OBJ_DIR)/unzipsfx.c -o $(OBJ_DIR)/unzipsfx.o
###
###
endif

610
src/apps/bin/unzip/api.c Normal file
View File

@ -0,0 +1,610 @@
/*
Copyright (c) 1990-2001 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
*/
/*---------------------------------------------------------------------------
api.c
This module supplies an UnZip engine for use directly from C/C++
programs. The functions are:
UzpVer *UzpVersion(void);
void UzpVersion2(UzpVer2 *version)
int UzpMain(int argc, char *argv[]);
int UzpAltMain(int argc, char *argv[], UzpInit *init);
int UzpValidate(char *archive, int AllCodes);
void UzpFreeMemBuffer(UzpBuffer *retstr);
int UzpUnzipToMemory(char *zip, char *file, UzpOpts *optflgs,
UzpCB *UsrFuncts, UzpBuffer *retstr);
non-WINDLL only (a special WINDLL variant is defined in windll/windll.c):
int UzpGrep(char *archive, char *file, char *pattern, int cmd, int SkipBin,
UzpCB *UsrFuncts);
OS/2 only (for now):
int UzpFileTree(char *name, cbList(callBack), char *cpInclude[],
char *cpExclude[]);
You must define `DLL' in order to include the API extensions.
---------------------------------------------------------------------------*/
#ifdef OS2
# define INCL_DOSMEMMGR
# include <os2.h>
#endif
#include <setjmp.h>
#define UNZIP_INTERNAL
#include "unzip.h"
#ifdef WINDLL
# include "windll/windll.h"
#endif
#include "unzvers.h"
#ifdef DLL /* This source file supplies DLL-only interface code. */
jmp_buf dll_error_return;
/*---------------------------------------------------------------------------
Documented API entry points
---------------------------------------------------------------------------*/
UzpVer * UZ_EXP UzpVersion() /* should be pointer to const struct */
{
static UzpVer version; /* doesn't change between calls */
version.structlen = UZPVER_LEN;
#ifdef BETA
version.flag = 1;
#else
version.flag = 0;
#endif
version.betalevel = UZ_BETALEVEL;
version.date = UZ_VERSION_DATE;
#ifdef ZLIB_VERSION
version.zlib_version = ZLIB_VERSION;
version.flag |= 2;
#else
version.zlib_version = NULL;
#endif
/* someday each of these may have a separate patchlevel: */
version.unzip.major = UZ_MAJORVER;
version.unzip.minor = UZ_MINORVER;
version.unzip.patchlevel = UZ_PATCHLEVEL;
version.zipinfo.major = ZI_MAJORVER;
version.zipinfo.minor = ZI_MINORVER;
version.zipinfo.patchlevel = UZ_PATCHLEVEL;
/* these are retained for backward compatibility only: */
version.os2dll.major = UZ_MAJORVER;
version.os2dll.minor = UZ_MINORVER;
version.os2dll.patchlevel = UZ_PATCHLEVEL;
version.windll.major = UZ_MAJORVER;
version.windll.minor = UZ_MINORVER;
version.windll.patchlevel = UZ_PATCHLEVEL;
return &version;
}
void UZ_EXP UzpVersion2(UzpVer2 *version)
{
version->structlen = UZPVER_LEN;
#ifdef BETA
version->flag = 1;
#else
version->flag = 0;
#endif
strcpy(version->betalevel, UZ_BETALEVEL);
strcpy(version->date, UZ_VERSION_DATE);
#ifdef ZLIB_VERSION
strcpy(version->zlib_version, ZLIB_VERSION);
version->flag |= 2;
#else
version->zlib_version[0] = '\0';
#endif
/* someday each of these may have a separate patchlevel: */
version->unzip.major = UZ_MAJORVER;
version->unzip.minor = UZ_MINORVER;
version->unzip.patchlevel = UZ_PATCHLEVEL;
version->zipinfo.major = ZI_MAJORVER;
version->zipinfo.minor = ZI_MINORVER;
version->zipinfo.patchlevel = UZ_PATCHLEVEL;
/* these are retained for backward compatibility only: */
version->os2dll.major = UZ_MAJORVER;
version->os2dll.minor = UZ_MINORVER;
version->os2dll.patchlevel = UZ_PATCHLEVEL;
version->windll.major = UZ_MAJORVER;
version->windll.minor = UZ_MINORVER;
version->windll.patchlevel = UZ_PATCHLEVEL;
}
#ifndef WINDLL
int UZ_EXP UzpAltMain(int argc, char *argv[], UzpInit *init)
{
int r, (*dummyfn)();
CONSTRUCTGLOBALS();
if (init->structlen >= (sizeof(ulg) + sizeof(dummyfn)) && init->msgfn)
G.message = init->msgfn;
if (init->structlen >= (sizeof(ulg) + 2*sizeof(dummyfn)) && init->inputfn)
G.input = init->inputfn;
if (init->structlen >= (sizeof(ulg) + 3*sizeof(dummyfn)) && init->pausefn)
G.mpause = init->pausefn;
if (init->structlen >= (sizeof(ulg) + 4*sizeof(dummyfn)) && init->userfn)
(*init->userfn)(); /* allow void* arg? */
r = unzip(__G__ argc, argv);
DESTROYGLOBALS();
RETURN(r);
}
#endif /* !WINDLL */
#ifndef __16BIT__
void UZ_EXP UzpFreeMemBuffer(UzpBuffer *retstr)
{
if (retstr->strptr != NULL) {
free(retstr->strptr);
retstr->strptr = NULL;
}
}
#ifndef WINDLL
static int UzpDLL_Init OF((zvoid *pG, UzpCB *UsrFuncts));
static int UzpDLL_Init(pG, UsrFuncts)
zvoid *pG;
UzpCB *UsrFuncts;
{
int (*dummyfn)();
if (UsrFuncts->structlen >= (sizeof(ulg) + sizeof(dummyfn)) &&
UsrFuncts->msgfn)
((Uz_Globs *)pG)->message = UsrFuncts->msgfn;
else
return FALSE;
if (UsrFuncts->structlen >= (sizeof(ulg) + 2*sizeof(dummyfn)) &&
UsrFuncts->inputfn)
((Uz_Globs *)pG)->input = UsrFuncts->inputfn;
if (UsrFuncts->structlen >= (sizeof(ulg) + 3*sizeof(dummyfn)) &&
UsrFuncts->pausefn)
((Uz_Globs *)pG)->mpause = UsrFuncts->pausefn;
if (UsrFuncts->structlen >= (sizeof(ulg) + 4*sizeof(dummyfn)) &&
UsrFuncts->passwdfn)
((Uz_Globs *)pG)->decr_passwd = UsrFuncts->passwdfn;
if (UsrFuncts->structlen >= (sizeof(ulg) + 5*sizeof(dummyfn)) &&
UsrFuncts->statrepfn)
((Uz_Globs *)pG)->statreportcb = UsrFuncts->statrepfn;
return TRUE;
}
int UZ_EXP UzpUnzipToMemory(char *zip, char *file, UzpOpts *optflgs,
UzpCB *UsrFuncts, UzpBuffer *retstr)
{
int r;
#if (defined(WINDLL) && !defined(CRTL_CP_IS_ISO))
char *intern_zip, *intern_file;
#endif
CONSTRUCTGLOBALS();
#if (defined(WINDLL) && !defined(CRTL_CP_IS_ISO))
intern_zip = (char *)malloc(strlen(zip)+1);
if (intern_zip == NULL) {
DESTROYGLOBALS();
return PK_MEM;
}
intern_file = (char *)malloc(strlen(file)+1);
if (intern_file == NULL) {
DESTROYGLOBALS();
free(intern_zip);
return PK_MEM;
}
ISO_TO_INTERN(zip, intern_zip);
ISO_TO_INTERN(file, intern_file);
# define zip intern_zip
# define file intern_file
#endif
/* Copy those options that are meaningful for UzpUnzipToMemory, instead of
* a simple "memcpy(G.UzO, optflgs, sizeof(UzpOpts));"
*/
uO.pwdarg = optflgs->pwdarg;
uO.aflag = optflgs->aflag;
uO.C_flag = optflgs->C_flag;
uO.qflag = optflgs->qflag; /* currently, overridden in unzipToMemory */
if (!UzpDLL_Init((zvoid *)&G, UsrFuncts)) {
DESTROYGLOBALS();
return PK_BADERR;
}
G.redirect_data = 1;
r = (unzipToMemory(__G__ zip, file, retstr) <= PK_WARN);
DESTROYGLOBALS();
#if (defined(WINDLL) && !defined(CRTL_CP_IS_ISO))
# undef file
# undef zip
free(intern_file);
free(intern_zip);
#endif
if (!r && retstr->strlength) {
free(retstr->strptr);
retstr->strptr = NULL;
}
return r;
}
#endif /* !WINDLL */
#endif /* !__16BIT__ */
#ifdef OS2DLL
int UZ_EXP UzpFileTree(char *name, cbList(callBack), char *cpInclude[],
char *cpExclude[])
{
int r;
CONSTRUCTGLOBALS();
uO.qflag = 2;
uO.vflag = 1;
uO.C_flag = 1;
G.wildzipfn = name;
G.process_all_files = TRUE;
if (cpInclude) {
char **ptr = cpInclude;
while (*ptr != NULL) ptr++;
G.filespecs = ptr - cpInclude;
G.pfnames = cpInclude, G.process_all_files = FALSE;
}
if (cpExclude) {
char **ptr = cpExclude;
while (*ptr != NULL) ptr++;
G.xfilespecs = ptr - cpExclude;
G.pxnames = cpExclude, G.process_all_files = FALSE;
}
G.processExternally = callBack;
r = process_zipfiles(__G)==0;
DESTROYGLOBALS();
return r;
}
#endif /* OS2DLL */
/*---------------------------------------------------------------------------
Helper functions
---------------------------------------------------------------------------*/
void setFileNotFound(__G)
__GDEF
{
G.filenotfound++;
}
int unzipToMemory(__GPRO__ char *zip, char *file, UzpBuffer *retstr)
{
int r;
char *incname[2];
G.process_all_files = FALSE;
G.extract_flag = TRUE;
uO.qflag = 2;
G.wildzipfn = zip;
G.pfnames = incname;
incname[0] = file;
incname[1] = NULL;
G.filespecs = 1;
r = process_zipfiles(__G);
if (retstr) {
retstr->strptr = (char *)G.redirect_buffer;
retstr->strlength = G.redirect_size;
}
return r; /* returns `PK_???' error values */
}
int redirect_outfile(__G)
__GDEF
{
if (G.redirect_size != 0 || G.redirect_buffer != NULL)
return FALSE;
#ifndef NO_SLIDE_REDIR
G.redirect_slide = !G.pInfo->textmode;
#endif
G.redirect_size = (G.pInfo->textmode ?
G.lrec.ucsize * lenEOL : G.lrec.ucsize);
#ifdef OS2
DosAllocMem((void **)&G.redirect_buffer, G.redirect_size+1,
PAG_READ|PAG_WRITE|PAG_COMMIT);
G.redirect_pointer = G.redirect_buffer;
#else
#ifdef __16BIT__
if ((ulg)((extent)G.redirect_size) != G.redirect_size)
return FALSE;
#endif
G.redirect_pointer =
G.redirect_buffer = malloc((extent)(G.redirect_size+1));
#endif
if (!G.redirect_buffer)
return FALSE;
G.redirect_pointer[G.redirect_size] = '\0';
return TRUE;
}
int writeToMemory(__GPRO__ ZCONST uch *rawbuf, extent size)
{
if ((uch *)rawbuf != G.redirect_pointer)
memcpy(G.redirect_pointer, rawbuf, size);
G.redirect_pointer += size;
return 0;
}
int close_redirect(__G)
__GDEF
{
if (G.pInfo->textmode) {
*G.redirect_pointer = '\0';
G.redirect_size = (ulg)(G.redirect_pointer - G.redirect_buffer);
if ((G.redirect_buffer =
realloc(G.redirect_buffer, G.redirect_size + 1)) == NULL) {
G.redirect_size = 0;
return EOF;
}
}
return 0;
}
#ifndef __16BIT__
#ifndef WINDLL
/* Purpose: Determine if file in archive contains the string szSearch
Parameters: archive = archive name
file = file contained in the archive. This cannot be
a wild card to be meaningful
pattern = string to search for
cmd = 0 - case-insensitive search
1 - case-sensitve search
2 - case-insensitive, whole words only
3 - case-sensitive, whole words only
SkipBin = if true, skip any files that have control
characters other than CR, LF, or tab in the first
100 characters.
Returns: TRUE if a match is found
FALSE if no match is found
-1 on error
Comments: This does not pretend to be as useful as the standard
Unix grep, which returns the strings associated with a
particular pattern, nor does it search past the first
matching occurrence of the pattern.
*/
int UZ_EXP UzpGrep(char *archive, char *file, char *pattern, int cmd,
int SkipBin, UzpCB *UsrFuncts)
{
int retcode = FALSE, compare;
ulg i, j, patternLen, buflen;
char * sz, *p;
UzpOpts flgopts;
UzpBuffer retstr;
memzero(&flgopts, sizeof(UzpOpts)); /* no special options */
if (!UzpUnzipToMemory(archive, file, &flgopts, UsrFuncts, &retstr)) {
return -1; /* not enough memory, file not found, or other error */
}
if (SkipBin) {
if (retstr.strlength < 100)
buflen = retstr.strlength;
else
buflen = 100;
for (i = 0; i < buflen; i++) {
if (iscntrl(retstr.strptr[i])) {
if ((retstr.strptr[i] != 0x0A) &&
(retstr.strptr[i] != 0x0D) &&
(retstr.strptr[i] != 0x09))
{
/* OK, we now think we have a binary file of some sort */
free(retstr.strptr);
return FALSE;
}
}
}
}
patternLen = strlen(pattern);
if (retstr.strlength < patternLen) {
free(retstr.strptr);
return FALSE;
}
sz = malloc(patternLen + 3); /* add two in case doing whole words only */
if (cmd > 1) {
strcpy(sz, " ");
strcat(sz, pattern);
strcat(sz, " ");
} else
strcpy(sz, pattern);
if ((cmd == 0) || (cmd == 2)) {
for (i = 0; i < strlen(sz); i++)
sz[i] = toupper(sz[i]);
for (i = 0; i < retstr.strlength; i++)
retstr.strptr[i] = toupper(retstr.strptr[i]);
}
for (i = 0; i < (retstr.strlength - patternLen); i++) {
p = &retstr.strptr[i];
compare = TRUE;
for (j = 0; j < patternLen; j++) {
/* We cannot do strncmp here, as we may be dealing with a
* "binary" file, such as a word processing file, or perhaps
* even a true executable of some sort. */
if (p[j] != sz[j]) {
compare = FALSE;
break;
}
}
if (compare == TRUE) {
retcode = TRUE;
break;
}
}
free(sz);
free(retstr.strptr);
return retcode;
}
#endif /* !WINDLL */
#endif /* !__16BIT__ */
int UZ_EXP UzpValidate(char *archive, int AllCodes)
{
int retcode;
CONSTRUCTGLOBALS();
uO.jflag = 1;
uO.tflag = 1;
uO.overwrite_none = 0;
G.extract_flag = (!uO.zipinfo_mode &&
!uO.cflag && !uO.tflag && !uO.vflag && !uO.zflag
#ifdef TIMESTAMP
&& !uO.T_flag
#endif
);
uO.qflag = 2; /* turn off all messages */
G.fValidate = TRUE;
G.pfnames = (char **)&fnames[0]; /* assign default filename vector */
#ifdef WINDLL
Wiz_NoPrinting(TRUE);
#endif
if (archive == NULL) { /* something is screwed up: no filename */
DESTROYGLOBALS();
return PK_NOZIP;
}
G.wildzipfn = (char *)malloc(FILNAMSIZ + 1);
strcpy(G.wildzipfn, archive);
#if (defined(WINDLL) && !defined(CRTL_CP_IS_ISO))
_ISO_INTERN(G.wildzipfn);
#endif
G.process_all_files = TRUE; /* for speed */
retcode = setjmp(dll_error_return);
if (retcode) {
#ifdef WINDLL
Wiz_NoPrinting(FALSE);
#endif
free(G.wildzipfn);
DESTROYGLOBALS();
return PK_BADERR;
}
retcode = process_zipfiles(__G);
free(G.wildzipfn);
#ifdef WINDLL
Wiz_NoPrinting(FALSE);
#endif
DESTROYGLOBALS();
/* PK_WARN == 1 and PK_FIND == 11. When we are just looking at an
archive, we should still be able to see the files inside it,
even if we can't decode them for some reason.
We also still want to be able to get at files even if there is
something odd about the zip archive, hence allow PK_WARN,
PK_FIND, IZ_UNSUP as well as PK_ERR
*/
if (AllCodes)
return retcode;
if ((retcode == PK_OK) || (retcode == PK_WARN) || (retcode == PK_ERR) ||
(retcode == IZ_UNSUP) || (retcode == PK_FIND))
return TRUE;
else
return FALSE;
}
#endif /* DLL */

View File

@ -0,0 +1,155 @@
/*
Copyright (c) 1990-2001 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
*/
/* apihelp.c */
#ifdef API_DOC
#define UNZIP_INTERNAL
#include "unzip.h"
#include "unzvers.h"
APIDocStruct APIDoc[] = {
{
"UZPVERSION" , "UzpVersion" ,
"UzpVer *UzpVersion(void);",
"Get version numbers of the API and the underlying UnZip code.\n\n"
"\t\tThis is used for comparing the version numbers of the run-time\n"
"\t\tDLL code with those expected from the unzip.h at compile time.\n"
"\t\tIf the version numbers do not match, there may be compatibility\n"
"\t\tproblems with further use of the DLL.\n\n"
" Example:\t/* Check the major version number of the DLL code. */\n"
"\t\tUzpVer *pVersion;\n"
"\t\tpVersion = UzpVersion();\n"
"\t\tif (pVersion->unzip.major != UZ_MAJORVER)\n"
"\t\t fprintf(stderr, \"error: using wrong version of DLL\\n\");\n\n"
"\t\tSee unzip.h for details and unzipstb.c for an example.\n"
},
{
"UZPMAIN" , "UzpMain" ,
"int UzpMain(int argc, char *argv[]);",
"Provide a direct entry point to the command line interface.\n\n"
"\t\tThis is used by the UnZip stub but you can use it in your\n"
"\t\town program as well. Output is sent to stdout.\n"
"\t\t0 on return indicates success.\n\n"
" Example:\t/* Extract 'test.zip' silently, junking paths. */\n"
"\t\tchar *argv[] = { \"-q\", \"-j\", \"test.zip\" };\n"
"\t\tint argc = 3;\n"
"\t\tif (UzpMain(argc,argv))\n"
"\t\t printf(\"error: unzip failed\\n\");\n\n"
"\t\tSee unzip.h for details.\n"
},
{
"UZPALTMAIN" , "UzpAltMain" ,
"int UzpAltMain(int argc, char *argv[], UzpInit *init);",
"Provide a direct entry point to the command line interface,\n"
"optionally installing replacement I/O handler functions.\n\n"
"\t\tAs with UzpMain(), output is sent to stdout by default.\n"
"\t\t`InputFn *inputfn' is not yet implemented. 0 on return\n"
"\t\tindicates success.\n\n"
" Example:\t/* Replace normal output and `more' functions. */\n"
"\t\tchar *argv[] = { \"-q\", \"-j\", \"test.zip\" };\n"
"\t\tint argc = 3;\n"
"\t\tUzpInit init = { 16, MyMessageFn, NULL, MyPauseFn };\n"
"\t\tif (UzpAltMain(argc,argv,&init))\n"
"\t\t printf(\"error: unzip failed\\n\");\n\n"
"\t\tSee unzip.h for details.\n"
},
{
"UZPUNZIPTOMEMORY", "UzpUnzipToMemory",
"int UzpUnzipToMemory(char *zip, char *file, UzpBuffer *retstr);",
"Pass the name of the zip file and the name of the file\n"
"\t\tyou wish to extract. UzpUnzipToMemory will create a\n"
"\t\tbuffer and return it in *retstr; 0 on return indicates\n"
"\t\tfailure.\n\n"
"\t\tSee unzip.h for details.\n"
},
{
"UZPFILETREE", "UzpFileTree",
"int UzpFileTree(char *name, cbList(callBack),\n"
"\t\t\tchar *cpInclude[], char *cpExclude[]);",
"Pass the name of the zip file, a callback function, an\n"
"\t\tinclude and exclude file list. UzpFileTree calls the\n"
"\t\tcallback for each valid file found in the zip file.\n"
"\t\t0 on return indicates failure.\n\n"
"\t\tSee unzip.h for details.\n"
},
{ 0 }
};
static int function_help OF((__GPRO__ APIDocStruct *doc, char *fname));
static int function_help(__G__ doc, fname)
__GDEF
APIDocStruct *doc;
char *fname;
{
strcpy(slide, fname);
/* strupr(slide); non-standard */
while (doc->compare && STRNICMP(doc->compare,slide,strlen(fname)))
doc++;
if (!doc->compare)
return 0;
else
Info(slide, 0, ((char *)slide,
" Function:\t%s\n\n Syntax:\t%s\n\n Purpose:\t%s",
doc->function, doc->syntax, doc->purpose));
return 1;
}
void APIhelp(__G__ argc, argv)
__GDEF
int argc;
char **argv;
{
if (argc > 1) {
struct APIDocStruct *doc;
if (function_help(__G__ APIDoc, argv[1]))
return;
#ifdef SYSTEM_API_DETAILS
if (function_help(__G__ SYSTEM_API_DETAILS, argv[1]))
return;
#endif
Info(slide, 0, ((char *)slide,
"%s is not a documented command.\n\n", argv[1]));
}
Info(slide, 0, ((char *)slide, "\
This API provides a number of external C and REXX functions for handling\n\
zipfiles in OS/2. Programmers are encouraged to expand this API.\n\
\n\
C functions: -- See unzip.h for details\n\
UzpVer *UzpVersion(void);\n\
int UzpMain(int argc, char *argv[]);\n\
int UzpAltMain(int argc, char *argv[], UzpInit *init);\n\
int UzpUnzipToMemory(char *zip, char *file, UzpBuffer *retstr);\n\
int UzpFileTree(char *name, cbList(callBack),\n\
char *cpInclude[], char *cpExclude[]);\n\n"));
#ifdef SYSTEM_API_BRIEF
Info(slide, 0, ((char *)slide, SYSTEM_API_BRIEF));
#endif
Info(slide, 0, ((char *)slide,
"\nFor more information, type 'unzip -A <function-name>'\n"));
}
#endif /* API_DOC */

1328
src/apps/bin/unzip/beos.c Normal file

File diff suppressed because it is too large Load Diff

46
src/apps/bin/unzip/beos.h Normal file
View File

@ -0,0 +1,46 @@
/*
Copyright (c) 1990-2000 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
*/
/* beos.h -- A few handy things for the BeOS port. */
/* (c) 1997 Chris Herborth (chrish@qnx.com) */
/* This is covered under the usual Info-ZIP copyright. */
/* "#define EF_BE_FL_UNCMPR 0x01" has been moved into unzpriv.h */
#define EB_BE_FL_BADBITS 0xfe /* bits currently undefined */
#define BEOS_ASSIGN_FILETYPE 1 /* call update_mime_info() */
/*
DR9 'Be' extra-field layout:
'Be' - signature
ef_size - size of data in this EF (little-endian unsigned short)
full_size - uncompressed data size (little-endian unsigned long)
flag - flags (byte)
flags & EB_BE_FL_UNCMPR = the data is not compressed
flags & EB_BE_FL_BADBITS = the data is corrupted or we
can't handle it properly
data - compressed or uncompressed file attribute data
If flag & EB_BE_FL_UNCMPR, the data is not compressed; this optimisation is
necessary to prevent wasted space for files with small attributes (which
appears to be quite common on the Advanced Access DR9 release). In this
case, there should be ( ef_size - EB_L_BE_LEN ) bytes of data, and full_size
should equal ( ef_size - EB_L_BE_LEN ).
If the data is compressed, there will be ( ef_size - EB_L_BE_LEN ) bytes of
compressed data, and full_size bytes of uncompressed data.
If a file has absolutely no attributes, there will not be a 'Be' extra field.
The uncompressed data is arranged like this:
attr_name\0 - C string
struct attr_info (fields in big-endian format)
attr_data (length in attr_info.size)
*/

View File

@ -0,0 +1,44 @@
// -*- C++ -*-
/*
Copyright (c) 1990-2000 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
*/
//
// WARNING: This is C++, not C! GNU C is not supported here!
//
// beos_init.cpp
//
// BeOS-specific C++ routines for use with Info-ZIP's UnZip 5.30 or later.
//
// This is necessary because we need to have an app_server connection to be
// able to ask the system to assign a MIME type to an un-typed file. Strange
// but true (the update_mime_info() call needs to send/receive messages).
//
// If you're writing your own Zip application, you probably DO NOT want to
// include this file!
#include <app/Application.h>
#ifdef SFX
const static char *unzip_signature = "application/x-vnd.Info-ZIP.UnZipSFX";
#else
const static char *unzip_signature = "application/x-vnd.Info-ZIP.UnZip";
#endif
extern "C" int main_stub( int argc, char *argv[] );
int main( int argc, char **argv )
{
BApplication app( unzip_signature );
int retval = main_stub( argc, argv );
app.PostMessage( B_QUIT_REQUESTED );
app.Run();
return retval;
}

View File

@ -0,0 +1,54 @@
/*
Copyright (c) 1990-2001 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
*/
/*---------------------------------------------------------------------------
consts.h
This file contains global, initialized variables that never change. It is
included by unzip.c and windll/windll.c.
---------------------------------------------------------------------------*/
/* And'ing with mask_bits[n] masks the lower n bits */
ZCONST ush near mask_bits[] = {
0x0000,
0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
};
ZCONST char Far VersionDate[] = UZ_VERSION_DATE; /* now defined in unzvers.h */
#ifndef SFX
ZCONST char Far EndSigMsg[] =
"\nnote: didn't find end-of-central-dir signature at end of central dir.\n";
#endif
ZCONST char Far CentSigMsg[] =
"error: expected central file header signature not found (file #%lu).\n";
ZCONST char Far SeekMsg[] =
"error [%s]: attempt to seek before beginning of zipfile\n%s";
ZCONST char Far FilenameNotMatched[] = "caution: filename not matched: %s\n";
ZCONST char Far ExclFilenameNotMatched[] =
"caution: excluded filename not matched: %s\n";
#ifdef VMS
ZCONST char Far ReportMsg[] = "\
(please check that you have transferred or created the zipfile in the\n\
appropriate BINARY mode--this includes ftp, Kermit, AND unzip'd zipfiles)\n";
#else
ZCONST char Far ReportMsg[] = "\
(please check that you have transferred or created the zipfile in the\n\
appropriate BINARY mode and that you have compiled UnZip properly)\n";
#endif
#ifndef SFX
ZCONST char Far Zipnfo[] = "zipinfo";
ZCONST char Far CompiledWith[] = "Compiled with %s%s for %s%s%s%s.\n\n";
#endif

View File

@ -0,0 +1,64 @@
/*
Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2000-Apr-09 or later
(the contents of which are also included in zip.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
*/
/* crc32.c -- compute the CRC-32 of a data stream
* Copyright (C) 1995 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* $Id: crc32.c,v 1.1 2002/09/21 14:54:45 darkwyrm Exp $ */
#define __CRC32_C /* identifies this source module */
#include "zip.h"
#ifndef USE_ZLIB
#ifndef ASM_CRC
#ifndef ZCONST
# define ZCONST const
#endif
#ifdef CRC32
# undef CRC32
#endif
#define CRC32(c, b) (crc_table[((int)(c) ^ (b)) & 0xff] ^ ((c) >> 8))
#define DO1(buf) crc = CRC32(crc, *buf++)
#define DO2(buf) DO1(buf); DO1(buf)
#define DO4(buf) DO2(buf); DO2(buf)
#define DO8(buf) DO4(buf); DO4(buf)
/* ========================================================================= */
ulg crc32(crc, buf, len)
register ulg crc; /* crc shift register */
register ZCONST uch *buf; /* pointer to bytes to pump through */
extent len; /* number of bytes in buf[] */
/* Run a set of bytes through the crc shift register. If buf is a NULL
pointer, then initialize the crc shift register contents instead.
Return the current crc in either case. */
{
register ZCONST ulg near *crc_table;
if (buf == NULL) return 0L;
crc_table = get_crc_table();
crc = crc ^ 0xffffffffL;
#ifndef NO_UNROLLED_LOOPS
while (len >= 8) {
DO8(buf);
len -= 8;
}
#endif
if (len) do {
DO1(buf);
} while (--len);
return crc ^ 0xffffffffL; /* (instead of ~c for 64-bit machines) */
}
#endif /* !ASM_CRC */
#endif /* !USE_ZLIB */

View File

@ -0,0 +1,232 @@
/*
Copyright (c) 1990-2001 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2000-Apr-09 or later
(the contents of which are also included in zip.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
*/
/*
* crc_i386.S, optimized CRC calculation function for Zip and UnZip,
* created by Paul Kienitz and Christian Spieler. Last revised 24 Dec 98.
*
* GRR 961110: incorporated Scott Field optimizations from win32/crc_i386.asm
* => overall 6% speedup in "unzip -tq" on 9MB zipfile (486-66)
*
* SPC 970402: revised for Rodney Brown's optimizations (32-bit-wide
* aligned reads for most of the data from buffer), can be
* disabled by defining the macro NO_32_BIT_LOADS
*
* SPC 971012: added Rodney Brown's additional tweaks for 32-bit-optimized
* CPUs (like the Pentium Pro, Pentium II, and probably some
* Pentium clones). This optimization is controlled by the
* preprocessor switch "__686" and is disabled by default.
* (This default is based on the assumption that most users
* do not yet work on a Pentium Pro or Pentium II machine ...)
*
* FLAT memory model assumed. Calling interface:
* - args are pushed onto the stack from right to left,
* - return value is given in the EAX register,
* - all other registers (with exception of EFLAGS) are preserved. (With
* GNU C 2.7.x, %edx and %ecx are `scratch' registers, but preserving
* them nevertheless adds only 4 single byte instructions.)
*
* This source generates the function
* ulg crc32(ulg crc, ZCONST uch *buf, extent len).
*
* The loop unrolling can be disabled by defining the macro NO_UNROLLED_LOOPS.
* This results in shorter code at the expense of reduced performance.
*/
/* This file is NOT used in conjunction with zlib. */
#ifndef USE_ZLIB
/* Preprocess with -DNO_UNDERLINE if your C compiler does not prefix
* external symbols with an underline character '_'.
*/
#if defined(NO_UNDERLINE) || defined(__ELF__)
# define _crc32 crc32
# define _get_crc_table get_crc_table
#endif
/* Use 16-byte alignment if your assembler supports it. Warning: gas
* uses a log(x) parameter (.align 4 means 16-byte alignment). On SVR4
* the parameter is a number of bytes.
*/
#ifndef ALIGNMENT
# define ALIGNMENT .align 4,0x90
#endif
#if defined(i386) || defined(_i386) || defined(_I386) || defined(__i386)
/* This version is for 386 Unix, OS/2, MSDOS in 32 bit mode (gcc & gas).
* Warning: it uses the AT&T syntax: mov source,dest
* This file is only optional. If you want to use the C version,
* remove -DASM_CRC from CFLAGS in Makefile and set OBJA to an empty string.
*/
.file "crc_i386.S"
#if defined(NO_STD_STACKFRAME) && defined(USE_STD_STACKFRAME)
# undef USE_STACKFRAME
#else
/* The default is to use standard stack frame entry, because it
* results in smaller code!
*/
# ifndef USE_STD_STACKFRAME
# define USE_STD_STACKFRAME
# endif
#endif
#ifdef USE_STD_STACKFRAME
# define _STD_ENTRY pushl %ebp ; movl %esp,%ebp
# define arg1 8(%ebp)
# define arg2 12(%ebp)
# define arg3 16(%ebp)
# define _STD_LEAVE popl %ebp
#else /* !USE_STD_STACKFRAME */
# define _STD_ENTRY
# define arg1 24(%esp)
# define arg2 28(%esp)
# define arg3 32(%esp)
# define _STD_LEAVE
#endif /* ?USE_STD_STACKFRAME */
/*
* These two (three) macros make up the loop body of the CRC32 cruncher.
* registers modified:
* eax : crc value "c"
* esi : pointer to next data byte (or lword) "buf++"
* registers read:
* edi : pointer to base of crc_table array
* scratch registers:
* ebx : index into crc_table array
* (requires upper three bytes = 0 when __686 is undefined)
*/
#ifndef __686 /* optimize for 386, 486, Pentium */
#define Do_CRC /* c = (c >> 8) ^ table[c & 0xFF] */\
movb %al, %bl ;/* tmp = c & 0xFF */\
shrl $8, %eax ;/* c = (c >> 8) */\
xorl (%edi, %ebx, 4), %eax ;/* c ^= table[tmp] */
#else /* __686 : optimize for Pentium Pro and compatible CPUs */
#define Do_CRC /* c = (c >> 8) ^ table[c & 0xFF] */\
movzbl %al, %ebx ;/* tmp = c & 0xFF */\
shrl $8, %eax ;/* c = (c >> 8) */\
xorl (%edi, %ebx, 4), %eax ;/* c ^=table[tmp] */
#endif /* ?__686 */
#define Do_CRC_byte /* c = (c >> 8) ^ table[(c^*buf++)&0xFF] */\
xorb (%esi), %al ;/* c ^= *buf */\
incl %esi ;/* buf++ */\
Do_CRC
#ifndef NO_32_BIT_LOADS
#define Do_CRC_lword \
xorl (%esi), %eax ;/* c ^= *(ulg *)buf */\
addl $4, %esi ;/* ((ulg *)buf)++ */\
Do_CRC \
Do_CRC \
Do_CRC \
Do_CRC
#endif /* !NO_32_BIT_LOADS */
.text
.globl _crc32
_crc32: /* ulg crc32(ulg crc, uch *buf, extent len) */
_STD_ENTRY
pushl %edi
pushl %esi
pushl %ebx
pushl %edx
pushl %ecx
movl arg2, %esi /* 2nd arg: uch *buf */
subl %eax, %eax /* > if (!buf) */
testl %esi, %esi /* > return 0; */
jz .L_fine /* > else { */
call _get_crc_table
movl %eax, %edi
movl arg1, %eax /* 1st arg: ulg crc */
#ifndef __686
subl %ebx, %ebx /* ebx=0; bl usable as dword */
#endif
movl arg3, %ecx /* 3rd arg: extent len */
notl %eax /* > c = ~crc; */
testl %ecx, %ecx
#ifndef NO_UNROLLED_LOOPS
jz .L_bail
# ifndef NO_32_BIT_LOADS
/* Assert now have positive length */
.L_align_loop:
testl $3, %esi /* Align buf on lword boundary */
jz .L_aligned_now
Do_CRC_byte
decl %ecx
jnz .L_align_loop
.L_aligned_now:
# endif /* !NO_32_BIT_LOADS */
movl %ecx, %edx /* save len in edx */
shrl $3, %ecx /* ecx = len / 8 */
jz .L_No_Eights
/* align loop head at start of 486 internal cache line !! */
ALIGNMENT
.L_Next_Eight:
# ifndef NO_32_BIT_LOADS
/* Do_CRC_lword */
xorl (%esi), %eax ;/* c ^= *(ulg *)buf */
addl $4, %esi ;/* ((ulg *)buf)++ */
Do_CRC
Do_CRC
Do_CRC
Do_CRC
/* Do_CRC_lword */
xorl (%esi), %eax ;/* c ^= *(ulg *)buf */
addl $4, %esi ;/* ((ulg *)buf)++ */
Do_CRC
Do_CRC
Do_CRC
Do_CRC
# else /* NO_32_BIT_LOADS */
Do_CRC_byte
Do_CRC_byte
Do_CRC_byte
Do_CRC_byte
Do_CRC_byte
Do_CRC_byte
Do_CRC_byte
Do_CRC_byte
# endif /* ?NO_32_BIT_LOADS */
decl %ecx
jnz .L_Next_Eight
.L_No_Eights:
movl %edx, %ecx
andl $7, %ecx /* ecx = len % 8 */
#endif /* !NO_UNROLLED_LOOPS */
jz .L_bail /* > if (len) */
/* align loop head at start of 486 internal cache line !! */
ALIGNMENT
.L_loupe: /* > do { */
Do_CRC_byte /* c = CRC32(c, *buf++); */
decl %ecx /* > } while (--len); */
jnz .L_loupe
.L_bail: /* > } */
notl %eax /* > return ~c; */
.L_fine:
popl %ecx
popl %edx
popl %ebx
popl %esi
popl %edi
_STD_LEAVE
ret
#else
error: this asm version is for 386 only
#endif /* i386 || _i386 || _I386 || __i386 */
#endif /* !USE_ZLIB */

227
src/apps/bin/unzip/crctab.c Normal file
View File

@ -0,0 +1,227 @@
/*
Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2000-Apr-09 or later
(the contents of which are also included in zip.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
*/
/* crctab.c -- supply the CRC table needed for CRC-32 calculations.
* Copyright (C) 1995 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* $Id: crctab.c,v 1.1 2002/09/21 14:54:45 darkwyrm Exp $ */
/*
Generate a table for a byte-wise 32-bit CRC calculation on the polynomial:
x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
Polynomials over GF(2) are represented in binary, one bit per coefficient,
with the lowest powers in the most significant bit. Then adding polynomials
is just exclusive-or, and multiplying a polynomial by x is a right shift by
one. If we call the above polynomial p, and represent a byte as the
polynomial q, also with the lowest power in the most significant bit (so the
byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
where a mod b means the remainder after dividing a by b.
This calculation is done using the shift-register method of multiplying and
taking the remainder. The register is initialized to zero, and for each
incoming bit, x^32 is added mod p to the register if the bit is a one (where
x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
x (which is shifting right by one and adding x^32 mod p if the bit shifted
out is a one). We start with the highest power (least significant bit) of
q and repeat for all eight bits of q.
The table is simply the CRC of all possible eight bit values. This is all
the information needed to generate CRC's on data a byte at a time for all
combinations of CRC register values and incoming bytes.
*/
#define __CRCTAB_C /* identifies this source module */
#include "zip.h"
#if (!defined(USE_ZLIB) || defined(USE_OWN_CRCTAB))
#ifndef ZCONST
# define ZCONST const
#endif
#ifdef DYNAMIC_CRC_TABLE
/* =========================================================================
* Make the crc table. This function is needed only if you want to compute
* the table dynamically.
*/
local void make_crc_table OF((void));
#if (defined(DYNALLOC_CRCTAB) && defined(REENTRANT))
error: Dynamic allocation of CRC table not safe with reentrant code.
#endif /* DYNALLOC_CRCTAB && REENTRANT */
#ifdef DYNALLOC_CRCTAB
local ulg near *crc_table = NULL;
# if 0 /* not used, since sizeof("near *") <= sizeof(int) */
/* Use this section when access to a "local int" is faster than access to
a "local pointer" (e.g.: i86 16bit code with far pointers). */
local int crc_table_empty = 1;
# define CRC_TABLE_IS_EMPTY (crc_table_empty != 0)
# define MARK_CRCTAB_FILLED crc_table_empty = 0
# define MARK_CRCTAB_EMPTY crc_table_empty = 1
# else
/* Use this section on systems where the size of pointers and ints is
equal (e.g.: all 32bit systems). */
# define CRC_TABLE_IS_EMPTY (crc_table == NULL)
# define MARK_CRCTAB_FILLED crc_table = crctab_p
# define MARK_CRCTAB_EMPTY crc_table = NULL
# endif
#else /* !DYNALLOC_CRCTAB */
local ulg near crc_table[256];
local int crc_table_empty = 1;
# define CRC_TABLE_IS_EMPTY (crc_table_empty != 0)
# define MARK_CRCTAB_FILLED crc_table_empty = 0
#endif /* ?DYNALLOC_CRCTAB */
local void make_crc_table()
{
ulg c; /* crc shift register */
int n; /* counter for all possible eight bit values */
int k; /* byte being shifted into crc apparatus */
#ifdef DYNALLOC_CRCTAB
ulg near *crctab_p; /* temporary pointer to allocated crc_table area */
#else /* !DYNALLOC_CRCTAB */
# define crctab_p crc_table
#endif /* DYNALLOC_CRCTAB */
#ifdef COMPUTE_XOR_PATTERN
/* This piece of code has been left here to explain how the XOR pattern
* used in the creation of the crc_table values can be recomputed.
* For production versions of this function, it is more efficient to
* supply the resultant pattern at compile time.
*/
ulg xor; /* polynomial exclusive-or pattern */
/* terms of polynomial defining this crc (except x^32): */
static uch p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
/* make exclusive-or pattern from polynomial (0xedb88320L) */
xor = 0L;
for (i = 0; i < sizeof(p)/sizeof(uch); i++)
xor |= 1L << (31 - p[i]);
#else
# define xor 0xedb88320L
#endif
#ifdef DYNALLOC_CRCTAB
crctab_p = (ulg near *) nearmalloc (256*sizeof(ulg));
if (crctab_p == NULL) {
ziperr(ZE_MEM, "crc_table allocation");
}
#endif /* DYNALLOC_CRCTAB */
for (n = 0; n < 256; n++) {
c = (ulg)n;
for (k = 8; k; k--)
c = c & 1 ? xor ^ (c >> 1) : c >> 1;
crctab_p[n] = c;
}
MARK_CRCTAB_FILLED;
}
#else /* !DYNAMIC_CRC_TABLE */
#ifdef DYNALLOC_CRCTAB
error: Inconsistent flags, DYNALLOC_CRCTAB without DYNAMIC_CRC_TABLE.
#endif
/* ========================================================================
* Table of CRC-32's of all single-byte values (made by make_crc_table)
*/
local ZCONST ulg near crc_table[256] = {
0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
0x2d02ef8dL
};
#endif /* ?DYNAMIC_CRC_TABLE */
/* use "OF((void))" here to work around a Borland TC++ 1.0 problem */
#ifdef USE_ZLIB
ZCONST uLongf *get_crc_table OF((void))
#else
ZCONST ulg near *get_crc_table OF((void))
#endif
{
#ifdef DYNAMIC_CRC_TABLE
if (CRC_TABLE_IS_EMPTY)
make_crc_table();
#endif
#ifdef USE_ZLIB
return (ZCONST uLongf *)crc_table;
#else
return (ZCONST ulg near *)crc_table;
#endif
}
#ifdef DYNALLOC_CRCTAB
void free_crc_table()
{
if (!CRC_TABLE_IS_EMPTY)
{
nearfree((ulg near *)crc_table);
MARK_CRCTAB_EMPTY;
}
}
#endif
#endif /* !USE_ZLIB || USE_OWN_CRCTAB */

583
src/apps/bin/unzip/crypt.c Normal file
View File

@ -0,0 +1,583 @@
/*
Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2000-Apr-09 or later
(the contents of which are also included in zip.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
*/
/*
crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h]
This encryption/decryption source code for Info-Zip software was
originally written in Europe. The whole source package can be
freely distributed, including from the USA. (Prior to January 2000,
re-export from the US was a violation of US law.)
NOTE on copyright history:
Previous versions of this source package (up to version 2.8) were
not copyrighted and put in the public domain. If you cannot comply
with the Info-Zip LICENSE, you may want to look for one of those
public domain versions.
*/
/*
This encryption code is a direct transcription of the algorithm from
Roger Schlafly, described by Phil Katz in the file appnote.txt. This
file (appnote.txt) is distributed with the PKZIP program (even in the
version without encryption capabilities).
*/
#define ZCRYPT_INTERNAL
#include "zip.h"
#include "crypt.h"
#include "ttyio.h"
#if CRYPT
#ifndef FALSE
# define FALSE 0
#endif
#ifdef ZIP
/* For the encoding task used in Zip (and ZipCloak), we want to initialize
the crypt algorithm with some reasonably unpredictable bytes, see
the crypthead() function. The standard rand() library function is
used to supply these `random' bytes, which in turn is initialized by
a srand() call. The srand() function takes an "unsigned" (at least 16bit)
seed value as argument to determine the starting point of the rand()
pseudo-random number generator.
This seed number is constructed as "Seed = Seed1 .XOR. Seed2" with
Seed1 supplied by the current time (= "(unsigned)time()") and Seed2
as some (hopefully) nondeterministic bitmask. On many (most) systems,
we use some "process specific" number, as the PID or something similar,
but when nothing unpredictable is available, a fixed number may be
sufficient.
NOTE:
1.) This implementation requires the availability of the following
standard UNIX C runtime library functions: time(), rand(), srand().
On systems where some of them are missing, the environment that
incorporates the crypt routines must supply suitable replacement
functions.
2.) It is a very bad idea to use a second call to time() to set the
"Seed2" number! In this case, both "Seed1" and "Seed2" would be
(almost) identical, resulting in a (mostly) "zero" constant seed
number passed to srand().
The implementation environment defined in the "zip.h" header should
supply a reasonable definition for ZCR_SEED2 (an unsigned number; for
most implementations of rand() and srand(), only the lower 16 bits are
significant!). An example that works on many systems would be
"#define ZCR_SEED2 (unsigned)getpid()".
The default definition for ZCR_SEED2 supplied below should be regarded
as a fallback to allow successful compilation in "beta state"
environments.
*/
# include <time.h> /* time() function supplies first part of crypt seed */
/* "last resort" source for second part of crypt seed pattern */
# ifndef ZCR_SEED2
# define ZCR_SEED2 (unsigned)3141592654L /* use PI as default pattern */
# endif
# ifdef GLOBAL /* used in Amiga system headers, maybe others too */
# undef GLOBAL
# endif
# define GLOBAL(g) g
#else /* !ZIP */
# define GLOBAL(g) G.g
#endif /* ?ZIP */
#ifdef UNZIP
/* char *key = (char *)NULL; moved to globals.h */
# ifndef FUNZIP
local int testp OF((__GPRO__ ZCONST uch *h));
local int testkey OF((__GPRO__ ZCONST uch *h, ZCONST char *key));
# endif
#endif /* UNZIP */
#ifndef UNZIP /* moved to globals.h for UnZip */
local ulg keys[3]; /* keys defining the pseudo-random sequence */
#endif /* !UNZIP */
#ifndef Trace
# ifdef CRYPT_DEBUG
# define Trace(x) fprintf x
# else
# define Trace(x)
# endif
#endif
#ifndef CRC_32_TAB
# define CRC_32_TAB crc_32_tab
#endif
#define CRC32(c, b) (CRC_32_TAB[((int)(c) ^ (b)) & 0xff] ^ ((c) >> 8))
/***********************************************************************
* Return the next byte in the pseudo-random sequence
*/
int decrypt_byte(__G)
__GDEF
{
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
* unpredictable manner on 16-bit systems; not a problem
* with any known compiler so far, though */
temp = ((unsigned)GLOBAL(keys[2]) & 0xffff) | 2;
return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
}
/***********************************************************************
* Update the encryption keys with the next byte of plain text
*/
int update_keys(__G__ c)
__GDEF
int c; /* byte of plain text */
{
GLOBAL(keys[0]) = CRC32(GLOBAL(keys[0]), c);
GLOBAL(keys[1]) += GLOBAL(keys[0]) & 0xff;
GLOBAL(keys[1]) = GLOBAL(keys[1]) * 134775813L + 1;
{
register int keyshift = (int)(GLOBAL(keys[1]) >> 24);
GLOBAL(keys[2]) = CRC32(GLOBAL(keys[2]), keyshift);
}
return c;
}
/***********************************************************************
* Initialize the encryption keys and the random header according to
* the given password.
*/
void init_keys(__G__ passwd)
__GDEF
ZCONST char *passwd; /* password string with which to modify keys */
{
GLOBAL(keys[0]) = 305419896L;
GLOBAL(keys[1]) = 591751049L;
GLOBAL(keys[2]) = 878082192L;
while (*passwd != '\0') {
update_keys(__G__ (int)*passwd);
passwd++;
}
}
#ifdef ZIP
/***********************************************************************
* Write encryption header to file zfile using the password passwd
* and the cyclic redundancy check crc.
*/
void crypthead(passwd, crc, zfile)
ZCONST char *passwd; /* password string */
ulg crc; /* crc of file being encrypted */
FILE *zfile; /* where to write header */
{
int n; /* index in random header */
int t; /* temporary */
int c; /* random byte */
int ztemp; /* temporary for zencoded value */
uch header[RAND_HEAD_LEN-2]; /* random header */
static unsigned calls = 0; /* ensure different random header each time */
/* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
* output of rand() to get less predictability, since rand() is
* often poorly implemented.
*/
if (++calls == 1) {
srand((unsigned)time(NULL) ^ ZCR_SEED2);
}
init_keys(passwd);
for (n = 0; n < RAND_HEAD_LEN-2; n++) {
c = (rand() >> 7) & 0xff;
header[n] = (uch)zencode(c, t);
}
/* Encrypt random header (last two bytes is high word of crc) */
init_keys(passwd);
for (n = 0; n < RAND_HEAD_LEN-2; n++) {
ztemp = zencode(header[n], t);
putc(ztemp, zfile);
}
ztemp = zencode((int)(crc >> 16) & 0xff, t);
putc(ztemp, zfile);
ztemp = zencode((int)(crc >> 24) & 0xff, t);
putc(ztemp, zfile);
}
#ifdef UTIL
/***********************************************************************
* Encrypt the zip entry described by z from file source to file dest
* using the password passwd. Return an error code in the ZE_ class.
*/
int zipcloak(z, source, dest, passwd)
struct zlist far *z; /* zip entry to encrypt */
FILE *source, *dest; /* source and destination files */
ZCONST char *passwd; /* password string */
{
int c; /* input byte */
int res; /* result code */
ulg n; /* holds offset and counts size */
ush flag; /* previous flags */
int t; /* temporary */
int ztemp; /* temporary storage for zencode value */
/* Set encrypted bit, clear extended local header bit and write local
header to output file */
if ((n = (ulg)ftell(dest)) == (ulg)-1L) return ZE_TEMP;
z->off = n;
flag = z->flg;
z->flg |= 1, z->flg &= ~8;
z->lflg |= 1, z->lflg &= ~8;
z->siz += RAND_HEAD_LEN;
if ((res = putlocal(z, dest)) != ZE_OK) return res;
/* Initialize keys with password and write random header */
crypthead(passwd, z->crc, dest);
/* Skip local header in input file */
if (fseek(source, (long)(4 + LOCHEAD + (ulg)z->nam + (ulg)z->ext),
SEEK_CUR)) {
return ferror(source) ? ZE_READ : ZE_EOF;
}
/* Encrypt data */
for (n = z->siz - RAND_HEAD_LEN; n; n--) {
if ((c = getc(source)) == EOF) {
return ferror(source) ? ZE_READ : ZE_EOF;
}
ztemp = zencode(c, t);
putc(ztemp, dest);
}
/* Skip extended local header in input file if there is one */
if ((flag & 8) != 0 && fseek(source, 16L, SEEK_CUR)) {
return ferror(source) ? ZE_READ : ZE_EOF;
}
if (fflush(dest) == EOF) return ZE_TEMP;
return ZE_OK;
}
/***********************************************************************
* Decrypt the zip entry described by z from file source to file dest
* using the password passwd. Return an error code in the ZE_ class.
*/
int zipbare(z, source, dest, passwd)
struct zlist far *z; /* zip entry to encrypt */
FILE *source, *dest; /* source and destination files */
ZCONST char *passwd; /* password string */
{
int c0, c1; /* last two input bytes */
ulg offset; /* used for file offsets */
ulg size; /* size of input data */
int r; /* size of encryption header */
int res; /* return code */
ush flag; /* previous flags */
/* Save position and skip local header in input file */
if ((offset = (ulg)ftell(source)) == (ulg)-1L ||
fseek(source, (long)(4 + LOCHEAD + (ulg)z->nam + (ulg)z->ext),
SEEK_CUR)) {
return ferror(source) ? ZE_READ : ZE_EOF;
}
/* Initialize keys with password */
init_keys(passwd);
/* Decrypt encryption header, save last two bytes */
c1 = 0;
for (r = RAND_HEAD_LEN; r; r--) {
c0 = c1;
if ((c1 = getc(source)) == EOF) {
return ferror(source) ? ZE_READ : ZE_EOF;
}
Trace((stdout, " (%02x)", c1));
zdecode(c1);
Trace((stdout, " %02x", c1));
}
Trace((stdout, "\n"));
/* If last two bytes of header don't match crc (or file time in the
* case of an extended local header), back up and just copy. For
* pkzip 2.0, the check has been reduced to one byte only.
*/
#ifdef ZIP10
if ((ush)(c0 | (c1<<8)) !=
(z->flg & 8 ? (ush) z->tim & 0xffff : (ush)(z->crc >> 16))) {
#else
c0++; /* avoid warning on unused variable */
if ((ush)c1 != (z->flg & 8 ? (ush) z->tim >> 8 : (ush)(z->crc >> 24))) {
#endif
if (fseek(source, offset, SEEK_SET)) {
return ferror(source) ? ZE_READ : ZE_EOF;
}
if ((res = zipcopy(z, source, dest)) != ZE_OK) return res;
return ZE_MISS;
}
/* Clear encrypted bit and local header bit, and write local header to
output file */
if ((offset = (ulg)ftell(dest)) == (ulg)-1L) return ZE_TEMP;
z->off = offset;
flag = z->flg;
z->flg &= ~9;
z->lflg &= ~9;
z->siz -= RAND_HEAD_LEN;
if ((res = putlocal(z, dest)) != ZE_OK) return res;
/* Decrypt data */
for (size = z->siz; size; size--) {
if ((c1 = getc(source)) == EOF) {
return ferror(source) ? ZE_READ : ZE_EOF;
}
zdecode(c1);
putc(c1, dest);
}
/* Skip extended local header in input file if there is one */
if ((flag & 8) != 0 && fseek(source, 16L, SEEK_CUR)) {
return ferror(source) ? ZE_READ : ZE_EOF;
}
if (fflush(dest) == EOF) return ZE_TEMP;
return ZE_OK;
}
#else /* !UTIL */
/***********************************************************************
* If requested, encrypt the data in buf, and in any case call fwrite()
* with the arguments to zfwrite(). Return what fwrite() returns.
*/
unsigned zfwrite(buf, item_size, nb, f)
zvoid *buf; /* data buffer */
extent item_size; /* size of each item in bytes */
extent nb; /* number of items */
FILE *f; /* file to write to */
{
int t; /* temporary */
if (key != (char *)NULL) { /* key is the global password pointer */
ulg size; /* buffer size */
char *p = (char*)buf; /* steps through buffer */
/* Encrypt data in buffer */
for (size = item_size*(ulg)nb; size != 0; p++, size--) {
*p = (char)zencode(*p, t);
}
}
/* Write the buffer out */
return fwrite(buf, item_size, nb, f);
}
#endif /* ?UTIL */
#endif /* ZIP */
#if (defined(UNZIP) && !defined(FUNZIP))
/***********************************************************************
* Get the password and set up keys for current zipfile member.
* Return PK_ class error.
*/
int decrypt(__G__ passwrd)
__GDEF
ZCONST char *passwrd;
{
ush b;
int n, r;
uch h[RAND_HEAD_LEN];
Trace((stdout, "\n[incnt = %d]: ", GLOBAL(incnt)));
/* get header once (turn off "encrypted" flag temporarily so we don't
* try to decrypt the same data twice) */
GLOBAL(pInfo->encrypted) = FALSE;
defer_leftover_input(__G);
for (n = 0; n < RAND_HEAD_LEN; n++) {
b = NEXTBYTE;
h[n] = (uch)b;
Trace((stdout, " (%02x)", h[n]));
}
undefer_input(__G);
GLOBAL(pInfo->encrypted) = TRUE;
if (GLOBAL(newzip)) { /* this is first encrypted member in this zipfile */
GLOBAL(newzip) = FALSE;
if (passwrd != (char *)NULL) { /* user gave password on command line */
if (!GLOBAL(key)) {
if ((GLOBAL(key) = (char *)malloc(strlen(passwrd)+1)) ==
(char *)NULL)
return PK_MEM2;
strcpy(GLOBAL(key), passwrd);
GLOBAL(nopwd) = TRUE; /* inhibit password prompting! */
}
} else if (GLOBAL(key)) { /* get rid of previous zipfile's key */
free(GLOBAL(key));
GLOBAL(key) = (char *)NULL;
}
}
/* if have key already, test it; else allocate memory for it */
if (GLOBAL(key)) {
if (!testp(__G__ h))
return PK_COOL; /* existing password OK (else prompt for new) */
else if (GLOBAL(nopwd))
return PK_WARN; /* user indicated no more prompting */
} else if ((GLOBAL(key) = (char *)malloc(IZ_PWLEN+1)) == (char *)NULL)
return PK_MEM2;
/* try a few keys */
n = 0;
do {
r = (*G.decr_passwd)((zvoid *)&G, &n, GLOBAL(key), IZ_PWLEN+1,
GLOBAL(zipfn), GLOBAL(filename));
if (r == IZ_PW_ERROR) { /* internal error in fetch of PW */
free (GLOBAL(key));
GLOBAL(key) = NULL;
return PK_MEM2;
}
if (r != IZ_PW_ENTERED) { /* user replied "skip" or "skip all" */
*GLOBAL(key) = '\0'; /* We try the NIL password, ... */
n = 0; /* and cancel fetch for this item. */
}
if (!testp(__G__ h))
return PK_COOL;
if (r == IZ_PW_CANCELALL) /* User replied "Skip all" */
GLOBAL(nopwd) = TRUE; /* inhibit any further PW prompt! */
} while (n > 0);
return PK_WARN;
} /* end function decrypt() */
/***********************************************************************
* Test the password. Return -1 if bad, 0 if OK.
*/
local int testp(__G__ h)
__GDEF
ZCONST uch *h;
{
int r;
char *key_translated;
/* On systems with "obscure" native character coding (e.g., EBCDIC),
* the first test translates the password to the "main standard"
* character coding. */
#ifdef STR_TO_CP1
/* allocate buffer for translated password */
if ((key_translated = malloc(strlen(GLOBAL(key)) + 1)) == (char *)NULL)
return -1;
/* first try, test password translated "standard" charset */
r = testkey(__G__ h, STR_TO_CP1(key_translated, GLOBAL(key)));
#else /* !STR_TO_CP1 */
/* first try, test password as supplied on the extractor's host */
r = testkey(__G__ h, GLOBAL(key));
#endif /* ?STR_TO_CP1 */
#ifdef STR_TO_CP2
if (r != 0) {
#ifndef STR_TO_CP1
/* now prepare for second (and maybe third) test with translated pwd */
if ((key_translated = malloc(strlen(GLOBAL(key)) + 1)) == (char *)NULL)
return -1;
#endif
/* second try, password translated to alternate ("standard") charset */
r = testkey(__G__ h, STR_TO_CP2(key_translated, GLOBAL(key)));
#ifdef STR_TO_CP3
if (r != 0)
/* third try, password translated to another "standard" charset */
r = testkey(__G__ h, STR_TO_CP3(key_translated, GLOBAL(key)));
#endif
#ifndef STR_TO_CP1
free(key_translated);
#endif
}
#endif /* STR_TO_CP2 */
#ifdef STR_TO_CP1
free(key_translated);
if (r != 0) {
/* last resort, test password as supplied on the extractor's host */
r = testkey(__G__ h, GLOBAL(key));
}
#endif /* STR_TO_CP1 */
return r;
} /* end function testp() */
local int testkey(__G__ h, key)
__GDEF
ZCONST uch *h; /* decrypted header */
ZCONST char *key; /* decryption password to test */
{
ush b;
#ifdef ZIP10
ush c;
#endif
int n;
uch *p;
uch hh[RAND_HEAD_LEN]; /* decrypted header */
/* set keys and save the encrypted header */
init_keys(__G__ key);
memcpy(hh, h, RAND_HEAD_LEN);
/* check password */
for (n = 0; n < RAND_HEAD_LEN; n++) {
zdecode(hh[n]);
Trace((stdout, " %02x", hh[n]));
}
Trace((stdout,
"\n lrec.crc= %08lx crec.crc= %08lx pInfo->ExtLocHdr= %s\n",
GLOBAL(lrec.crc32), GLOBAL(pInfo->crc),
GLOBAL(pInfo->ExtLocHdr) ? "true":"false"));
Trace((stdout, " incnt = %d unzip offset into zipfile = %ld\n",
GLOBAL(incnt),
GLOBAL(cur_zipfile_bufstart)+(GLOBAL(inptr)-GLOBAL(inbuf))));
/* same test as in zipbare(): */
#ifdef ZIP10 /* check two bytes */
c = hh[RAND_HEAD_LEN-2], b = hh[RAND_HEAD_LEN-1];
Trace((stdout,
" (c | (b<<8)) = %04x (crc >> 16) = %04x lrec.time = %04x\n",
(ush)(c | (b<<8)), (ush)(GLOBAL(lrec.crc32) >> 16),
((ush)GLOBAL(lrec.last_mod_dos_datetime) & 0xffff))));
if ((ush)(c | (b<<8)) != (GLOBAL(pInfo->ExtLocHdr) ?
((ush)GLOBAL(lrec.last_mod_dos_datetime) & 0xffff) :
(ush)(GLOBAL(lrec.crc32) >> 16)))
return -1; /* bad */
#else
b = hh[RAND_HEAD_LEN-1];
Trace((stdout, " b = %02x (crc >> 24) = %02x (lrec.time >> 8) = %02x\n",
b, (ush)(GLOBAL(lrec.crc32) >> 24),
((ush)GLOBAL(lrec.last_mod_dos_datetime) >> 8) & 0xff));
if (b != (GLOBAL(pInfo->ExtLocHdr) ?
((ush)GLOBAL(lrec.last_mod_dos_datetime) >> 8) & 0xff :
(ush)(GLOBAL(lrec.crc32) >> 24)))
return -1; /* bad */
#endif
/* password OK: decrypt current buffer contents before leaving */
for (n = (long)GLOBAL(incnt) > GLOBAL(csize) ?
(int)GLOBAL(csize) : GLOBAL(incnt),
p = GLOBAL(inptr); n--; p++)
zdecode(*p);
return 0; /* OK */
} /* end function testkey() */
#endif /* UNZIP && !FUNZIP */
#else /* !CRYPT */
/* something "externally visible" to shut up compiler/linker warnings */
int zcr_dummy;
#endif /* ?CRYPT */

178
src/apps/bin/unzip/crypt.h Normal file
View File

@ -0,0 +1,178 @@
/*
Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2000-Apr-09 or later
(the contents of which are also included in zip.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
*/
/*
crypt.h (full version) by Info-ZIP. Last revised: [see CR_VERSION_DATE]
This encryption/decryption source code for Info-Zip software was
originally written in Europe. The whole source package can be
freely distributed, including from the USA. (Prior to January 2000,
re-export from the US was a violation of US law.)
NOTE on copyright history:
Previous versions of this source package (up to version 2.8) were
not copyrighted and put in the public domain. If you cannot comply
with the Info-Zip LICENSE, you may want to look for one of those
public domain versions.
*/
#ifndef __crypt_h /* don't include more than once */
#define __crypt_h
#ifdef CRYPT
# undef CRYPT
#endif
/*
Logic of selecting "full crypt" code:
a) default behaviour:
- dummy crypt code when used to compile Zip
(because we do not distribute encrypting versions of Zip from US
servers)
- dummy crypt code when compiling UnZipSFX stub, to minimize size
- full crypt code when used to compile UnZip and fUnZip
b) USE_CRYPT defined:
- always full crypt code
c) NO_CRYPT defined:
- never full crypt code
NO_CRYPT takes precedence over USE_CRYPT
*/
#if defined(NO_CRYPT)
# define CRYPT 0 /* dummy version */
#else
#if defined(USE_CRYPT)
# define CRYPT 1 /* full version */
#else
#if (!defined(ZIP) && !defined(SFX))
# define CRYPT 1 /* full version */
#else
# define CRYPT 0 /* dummy version */
#endif
#endif /* ?USE_CRYPT */
#endif /* ?NO_CRYPT */
#if CRYPT
/* full version */
#ifdef CR_BETA
# undef CR_BETA /* this is not a beta release */
#endif
#define CR_MAJORVER 2
#define CR_MINORVER 9
#ifdef CR_BETA
# define CR_BETA_VER "a BETA"
# define CR_VERSION_DATE "05 May 2000" /* last real code change */
#else
# define CR_BETA_VER ""
# define CR_VERSION_DATE "05 May 2000" /* last public release date */
# define CR_RELEASE
#endif
#ifndef __G /* UnZip only, for now (DLL stuff) */
# define __G
# define __G__
# define __GDEF
# define __GPRO void
# define __GPRO__
#endif
#if defined(MSDOS) || defined(OS2) || defined(WIN32)
# ifndef DOS_OS2_W32
# define DOS_OS2_W32
# endif
#endif
#if defined(DOS_OS2_W32) || defined(__human68k__)
# ifndef DOS_H68_OS2_W32
# define DOS_H68_OS2_W32
# endif
#endif
#if defined(VM_CMS) || defined(MVS)
# ifndef CMS_MVS
# define CMS_MVS
# endif
#endif
/* To allow combining of Zip and UnZip static libraries in a single binary,
* the Zip and UnZip versions of the crypt core functions have to be named
* differently.
*/
#ifdef ZIP
# ifdef REALLY_SHORT_SYMS
# define decrypt_byte zdcrby
# else
# define decrypt_byte zp_decrypt_byte
# endif
# define update_keys zp_update_keys
# define init_keys zp_init_keys
#else /* !ZIP */
# ifdef REALLY_SHORT_SYMS
# define decrypt_byte dcrbyt
# endif
#endif /* ?ZIP */
#define IZ_PWLEN 80 /* input buffer size for reading encryption key */
#ifndef PWLEN /* for compatibility with previous zcrypt release... */
# define PWLEN IZ_PWLEN
#endif
#define RAND_HEAD_LEN 12 /* length of encryption random header */
/* the crc_32_tab array has to be provided externally for the crypt calculus */
#ifndef CRC_32_TAB /* UnZip provides this in globals.h */
# if (!defined(USE_ZLIB) || defined(USE_OWN_CRCTAB))
extern ZCONST ulg near *crc_32_tab;
# else
extern ZCONST ulg Far *crc_32_tab;
# endif
#endif /* !CRC_32_TAB */
/* encode byte c, using temp t. Warning: c must not have side effects. */
#define zencode(c,t) (t=decrypt_byte(__G), update_keys(c), t^(c))
/* decode byte c in place */
#define zdecode(c) update_keys(__G__ c ^= decrypt_byte(__G))
int decrypt_byte OF((__GPRO));
int update_keys OF((__GPRO__ int c));
void init_keys OF((__GPRO__ ZCONST char *passwd));
#ifdef ZIP
void crypthead OF((ZCONST char *, ulg, FILE *));
# ifdef UTIL
int zipcloak OF((struct zlist far *, FILE *, FILE *, ZCONST char *));
int zipbare OF((struct zlist far *, FILE *, FILE *, ZCONST char *));
# else
unsigned zfwrite OF((zvoid *, extent, extent, FILE *));
extern char *key;
# endif
#endif /* ZIP */
#if (defined(UNZIP) && !defined(FUNZIP))
int decrypt OF((__GPRO__ ZCONST char *passwrd));
#endif
#ifdef FUNZIP
extern int encrypted;
# ifdef NEXTBYTE
# undef NEXTBYTE
# endif
# define NEXTBYTE \
(encrypted? update_keys(__G__ getc(G.in)^decrypt_byte(__G)) : getc(G.in))
#endif /* FUNZIP */
#else /* !CRYPT */
/* dummy version */
#define zencode
#define zdecode
#define zfwrite fwrite
#endif /* ?CRYPT */
#endif /* !__crypt_h */

284
src/apps/bin/unzip/ebcdic.h Normal file
View File

@ -0,0 +1,284 @@
/*
Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2000-Apr-09 or later
(the contents of which are also included in zip.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
*/
/*---------------------------------------------------------------------------
ebcdic.h
The CECP 1047 (Extended de-facto EBCDIC) <-> ISO 8859-1 conversion tables,
from ftp://aix1.segi.ulg.ac.be/pub/docs/iso8859/iso8859.networking
NOTES:
<Paul_von_Behren@stortek.com> (OS/390 port 12/97)
These table no longer represent the standard mappings (for example in the
OS/390 iconv utility). In order to follow current standards I remapped
ebcdic x0a to ascii x15 and
ebcdic x85 to ascii x25 (and vice-versa)
Without these changes, newlines in auto-convert text files appeared
as literal \045.
I'm not sure what effect this remap would have on the MVS and CMS ports, so
I ifdef'd these changes. Hopefully these ifdef's can be removed when the
MVS/CMS folks test the new mappings.
Christian Spieler <spieler@ikp.tu-darmstadt.de>, 27-Apr-1998
The problem mentioned by Paul von Behren was already observed previously
on VM/CMS, during the preparation of the CMS&MVS port of UnZip 5.20 in
1996. At that point, the ebcdic tables were not changed since they seemed
to be an adopted standard (to my knowledge, these tables are still used
as presented in mainfraime KERMIT). Instead, the "end-of-line" conversion
feature of Zip's and UnZip's "text-translation" mode was used to force
correct mappings between ASCII and EBCDIC newline markers.
Before interchanging the ASCII mappings of the EBCDIC control characters
"NL" 0x25 and "LF" 0x15 according to the OS/390 setting, we have to
make sure that EBCDIC 0x15 is never used as line termination.
---------------------------------------------------------------------------*/
#ifndef __ebcdic_h /* prevent multiple inclusions */
#define __ebcdic_h
#ifndef ZCONST
# define ZCONST const
#endif
#ifdef EBCDIC
#ifndef MTS /* MTS uses a slightly "special" EBCDIC code page */
ZCONST uch ebcdic[] = {
0x00, 0x01, 0x02, 0x03, 0x37, 0x2D, 0x2E, 0x2F, /* 00 - 07 */
#ifdef OS390
0x16, 0x05, 0x15, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, /* 08 - 0F */
#else
0x16, 0x05, 0x25, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, /* 08 - 0F */
#endif
0x10, 0x11, 0x12, 0x13, 0x3C, 0x3D, 0x32, 0x26, /* 10 - 17 */
0x18, 0x19, 0x3F, 0x27, 0x1C, 0x1D, 0x1E, 0x1F, /* 18 - 1F */
0x40, 0x5A, 0x7F, 0x7B, 0x5B, 0x6C, 0x50, 0x7D, /* 20 - 27 */
0x4D, 0x5D, 0x5C, 0x4E, 0x6B, 0x60, 0x4B, 0x61, /* 28 - 2F */
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, /* 30 - 37 */
0xF8, 0xF9, 0x7A, 0x5E, 0x4C, 0x7E, 0x6E, 0x6F, /* 38 - 3F */
0x7C, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, /* 40 - 47 */
0xC8, 0xC9, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, /* 48 - 4F */
0xD7, 0xD8, 0xD9, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, /* 50 - 57 */
0xE7, 0xE8, 0xE9, 0xAD, 0xE0, 0xBD, 0x5F, 0x6D, /* 58 - 5F */
0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, /* 60 - 67 */
0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, /* 68 - 6F */
0x97, 0x98, 0x99, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, /* 70 - 77 */
0xA7, 0xA8, 0xA9, 0xC0, 0x4F, 0xD0, 0xA1, 0x07, /* 78 - 7F */
#ifdef OS390
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x06, 0x17, /* 80 - 87 */
#else
0x20, 0x21, 0x22, 0x23, 0x24, 0x15, 0x06, 0x17, /* 80 - 87 */
#endif
0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x09, 0x0A, 0x1B, /* 88 - 8F */
0x30, 0x31, 0x1A, 0x33, 0x34, 0x35, 0x36, 0x08, /* 90 - 97 */
0x38, 0x39, 0x3A, 0x3B, 0x04, 0x14, 0x3E, 0xFF, /* 98 - 9F */
0x41, 0xAA, 0x4A, 0xB1, 0x9F, 0xB2, 0x6A, 0xB5, /* A0 - A7 */
0xBB, 0xB4, 0x9A, 0x8A, 0xB0, 0xCA, 0xAF, 0xBC, /* A8 - AF */
0x90, 0x8F, 0xEA, 0xFA, 0xBE, 0xA0, 0xB6, 0xB3, /* B0 - B7 */
0x9D, 0xDA, 0x9B, 0x8B, 0xB7, 0xB8, 0xB9, 0xAB, /* B8 - BF */
0x64, 0x65, 0x62, 0x66, 0x63, 0x67, 0x9E, 0x68, /* C0 - C7 */
0x74, 0x71, 0x72, 0x73, 0x78, 0x75, 0x76, 0x77, /* C8 - CF */
0xAC, 0x69, 0xED, 0xEE, 0xEB, 0xEF, 0xEC, 0xBF, /* D0 - D7 */
0x80, 0xFD, 0xFE, 0xFB, 0xFC, 0xBA, 0xAE, 0x59, /* D8 - DF */
0x44, 0x45, 0x42, 0x46, 0x43, 0x47, 0x9C, 0x48, /* E0 - E7 */
0x54, 0x51, 0x52, 0x53, 0x58, 0x55, 0x56, 0x57, /* E8 - EF */
0x8C, 0x49, 0xCD, 0xCE, 0xCB, 0xCF, 0xCC, 0xE1, /* F0 - F7 */
0x70, 0xDD, 0xDE, 0xDB, 0xDC, 0x8D, 0x8E, 0xDF /* F8 - FF */
};
#if (defined(ZIP) || CRYPT)
ZCONST uch ascii[] = {
0x00, 0x01, 0x02, 0x03, 0x9C, 0x09, 0x86, 0x7F, /* 00 - 07 */
0x97, 0x8D, 0x8E, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, /* 08 - 0F */
#ifdef OS390
0x10, 0x11, 0x12, 0x13, 0x9D, 0x0A, 0x08, 0x87, /* 10 - 17 */
#else
0x10, 0x11, 0x12, 0x13, 0x9D, 0x85, 0x08, 0x87, /* 10 - 17 */
#endif
0x18, 0x19, 0x92, 0x8F, 0x1C, 0x1D, 0x1E, 0x1F, /* 18 - 1F */
#ifdef OS390
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x17, 0x1B, /* 20 - 27 */
#else
0x80, 0x81, 0x82, 0x83, 0x84, 0x0A, 0x17, 0x1B, /* 20 - 27 */
#endif
0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x05, 0x06, 0x07, /* 28 - 2F */
0x90, 0x91, 0x16, 0x93, 0x94, 0x95, 0x96, 0x04, /* 30 - 37 */
0x98, 0x99, 0x9A, 0x9B, 0x14, 0x15, 0x9E, 0x1A, /* 38 - 3F */
0x20, 0xA0, 0xE2, 0xE4, 0xE0, 0xE1, 0xE3, 0xE5, /* 40 - 47 */
0xE7, 0xF1, 0xA2, 0x2E, 0x3C, 0x28, 0x2B, 0x7C, /* 48 - 4F */
0x26, 0xE9, 0xEA, 0xEB, 0xE8, 0xED, 0xEE, 0xEF, /* 50 - 57 */
0xEC, 0xDF, 0x21, 0x24, 0x2A, 0x29, 0x3B, 0x5E, /* 58 - 5F */
0x2D, 0x2F, 0xC2, 0xC4, 0xC0, 0xC1, 0xC3, 0xC5, /* 60 - 67 */
0xC7, 0xD1, 0xA6, 0x2C, 0x25, 0x5F, 0x3E, 0x3F, /* 68 - 6F */
0xF8, 0xC9, 0xCA, 0xCB, 0xC8, 0xCD, 0xCE, 0xCF, /* 70 - 77 */
0xCC, 0x60, 0x3A, 0x23, 0x40, 0x27, 0x3D, 0x22, /* 78 - 7F */
0xD8, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* 80 - 87 */
0x68, 0x69, 0xAB, 0xBB, 0xF0, 0xFD, 0xFE, 0xB1, /* 88 - 8F */
0xB0, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, /* 90 - 97 */
0x71, 0x72, 0xAA, 0xBA, 0xE6, 0xB8, 0xC6, 0xA4, /* 98 - 9F */
0xB5, 0x7E, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, /* A0 - A7 */
0x79, 0x7A, 0xA1, 0xBF, 0xD0, 0x5B, 0xDE, 0xAE, /* A8 - AF */
0xAC, 0xA3, 0xA5, 0xB7, 0xA9, 0xA7, 0xB6, 0xBC, /* B0 - B7 */
0xBD, 0xBE, 0xDD, 0xA8, 0xAF, 0x5D, 0xB4, 0xD7, /* B8 - BF */
0x7B, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* C0 - C7 */
0x48, 0x49, 0xAD, 0xF4, 0xF6, 0xF2, 0xF3, 0xF5, /* C8 - CF */
0x7D, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, /* D0 - D7 */
0x51, 0x52, 0xB9, 0xFB, 0xFC, 0xF9, 0xFA, 0xFF, /* D8 - DF */
0x5C, 0xF7, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, /* E0 - E7 */
0x59, 0x5A, 0xB2, 0xD4, 0xD6, 0xD2, 0xD3, 0xD5, /* E8 - EF */
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* F0 - F7 */
0x38, 0x39, 0xB3, 0xDB, 0xDC, 0xD9, 0xDA, 0x9F /* F8 - FF */
};
#endif /* ZIP || CRYPT */
#else /* MTS */
/*
* This is the MTS ASCII->EBCDIC translation table. It provides a 1-1
* translation from ISO 8859/1 8-bit ASCII to IBM Code Page 37 EBCDIC.
*/
ZCONST uch ebcdic[] = {
0x00, 0x01, 0x02, 0x03, 0x37, 0x2D, 0x2E, 0x2F, /* 00 - 07 */
0x16, 0x05, 0x25, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, /* 08 - 0F */
0x10, 0x11, 0x12, 0x13, 0x3C, 0x3D, 0x32, 0x26, /* 10 - 17 */
0x18, 0x19, 0x3F, 0x27, 0x1C, 0x1D, 0x1E, 0x1F, /* 18 - 1F */
0x40, 0x5A, 0x7F, 0x7B, 0x5B, 0x6C, 0x50, 0x7D, /* 20 - 27 */
0x4D, 0x5D, 0x5C, 0x4E, 0x6B, 0x60, 0x4B, 0x61, /* 28 - 2F */
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, /* 30 - 37 */
0xF8, 0xF9, 0x7A, 0x5E, 0x4C, 0x7E, 0x6E, 0x6F, /* 38 - 3F */
0x7C, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, /* 40 - 47 */
0xC8, 0xC9, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, /* 48 - 4F */
0xD7, 0xD8, 0xD9, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, /* 50 - 57 */
0xE7, 0xE8, 0xE9, 0xBA, 0xE0, 0xBB, 0xB0, 0x6D, /* 58 - 5F */
0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, /* 60 - 67 */
0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, /* 68 - 6F */
0x97, 0x98, 0x99, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, /* 70 - 77 */
0xA7, 0xA8, 0xA9, 0xC0, 0x4F, 0xD0, 0xA1, 0x07, /* 78 - 7F */
0x20, 0x21, 0x22, 0x23, 0x24, 0x15, 0x06, 0x17, /* 80 - 87 */
0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x09, 0x0A, 0x1B, /* 88 - 8F */
0x30, 0x31, 0x1A, 0x33, 0x34, 0x35, 0x36, 0x08, /* 90 - 97 */
0x38, 0x39, 0x3A, 0x3B, 0x04, 0x14, 0x3E, 0xFF, /* 98 - 9F */
0x41, 0xAA, 0x4A, 0xB1, 0x9F, 0xB2, 0x6A, 0xB5, /* A0 - A7 */
0xBD, 0xB4, 0x9A, 0x8A, 0x5F, 0xCA, 0xAF, 0xBC, /* A8 - AF */
0x90, 0x8F, 0xEA, 0xFA, 0xBE, 0xA0, 0xB6, 0xB3, /* B0 - B7 */
0x9D, 0xDA, 0x9B, 0x8B, 0xB7, 0xB8, 0xB9, 0xAB, /* B8 - BF */
0x64, 0x65, 0x62, 0x66, 0x63, 0x67, 0x9E, 0x68, /* C0 - C7 */
0x74, 0x71, 0x72, 0x73, 0x78, 0x75, 0x76, 0x77, /* C8 - CF */
0xAC, 0x69, 0xED, 0xEE, 0xEB, 0xEF, 0xEC, 0xBF, /* D0 - D7 */
0x80, 0xFD, 0xFE, 0xFB, 0xFC, 0xAD, 0xAE, 0x59, /* D8 - DF */
0x44, 0x45, 0x42, 0x46, 0x43, 0x47, 0x9C, 0x48, /* E0 - E7 */
0x54, 0x51, 0x52, 0x53, 0x58, 0x55, 0x56, 0x57, /* E8 - EF */
0x8C, 0x49, 0xCD, 0xCE, 0xCB, 0xCF, 0xCC, 0xE1, /* F0 - F7 */
0x70, 0xDD, 0xDE, 0xDB, 0xDC, 0x8D, 0x8E, 0xDF /* F8 - FF */
};
#if (defined(ZIP) || CRYPT)
ZCONST uch ascii[] = {
0x00, 0x01, 0x02, 0x03, 0x9C, 0x09, 0x86, 0x7F, /* 00 - 07 */
0x97, 0x8D, 0x8E, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, /* 08 - 0F */
0x10, 0x11, 0x12, 0x13, 0x9D, 0x85, 0x08, 0x87, /* 10 - 17 */
0x18, 0x19, 0x92, 0x8F, 0x1C, 0x1D, 0x1E, 0x1F, /* 18 - 1F */
0x80, 0x81, 0x82, 0x83, 0x84, 0x0A, 0x17, 0x1B, /* 20 - 27 */
0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x05, 0x06, 0x07, /* 28 - 2F */
0x90, 0x91, 0x16, 0x93, 0x94, 0x95, 0x96, 0x04, /* 30 - 37 */
0x98, 0x99, 0x9A, 0x9B, 0x14, 0x15, 0x9E, 0x1A, /* 38 - 3F */
0x20, 0xA0, 0xE2, 0xE4, 0xE0, 0xE1, 0xE3, 0xE5, /* 40 - 47 */
0xE7, 0xF1, 0xA2, 0x2E, 0x3C, 0x28, 0x2B, 0x7C, /* 48 - 4F */
0x26, 0xE9, 0xEA, 0xEB, 0xE8, 0xED, 0xEE, 0xEF, /* 50 - 57 */
0xEC, 0xDF, 0x21, 0x24, 0x2A, 0x29, 0x3B, 0xAC, /* 58 - 5F */
0x2D, 0x2F, 0xC2, 0xC4, 0xC0, 0xC1, 0xC3, 0xC5, /* 60 - 67 */
0xC7, 0xD1, 0xA6, 0x2C, 0x25, 0x5F, 0x3E, 0x3F, /* 68 - 6F */
0xF8, 0xC9, 0xCA, 0xCB, 0xC8, 0xCD, 0xCE, 0xCF, /* 70 - 77 */
0xCC, 0x60, 0x3A, 0x23, 0x40, 0x27, 0x3D, 0x22, /* 78 - 7F */
0xD8, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* 80 - 87 */
0x68, 0x69, 0xAB, 0xBB, 0xF0, 0xFD, 0xFE, 0xB1, /* 88 - 8F */
0xB0, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, /* 90 - 97 */
0x71, 0x72, 0xAA, 0xBA, 0xE6, 0xB8, 0xC6, 0xA4, /* 98 - 9F */
0xB5, 0x7E, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, /* A0 - A7 */
0x79, 0x7A, 0xA1, 0xBF, 0xD0, 0xDD, 0xDE, 0xAE, /* A8 - AF */
0x5E, 0xA3, 0xA5, 0xB7, 0xA9, 0xA7, 0xB6, 0xBC, /* B0 - B7 */
0xBD, 0xBE, 0x5B, 0x5D, 0xAF, 0xA8, 0xB4, 0xD7, /* B8 - BF */
0x7B, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* C0 - C7 */
0x48, 0x49, 0xAD, 0xF4, 0xF6, 0xF2, 0xF3, 0xF5, /* C8 - CF */
0x7D, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, /* D0 - D7 */
0x51, 0x52, 0xB9, 0xFB, 0xFC, 0xF9, 0xFA, 0xFF, /* D8 - DF */
0x5C, 0xF7, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, /* E0 - E7 */
0x59, 0x5A, 0xB2, 0xD4, 0xD6, 0xD2, 0xD3, 0xD5, /* E8 - EF */
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* F0 - F7 */
0x38, 0x39, 0xB3, 0xDB, 0xDC, 0xD9, 0xDA, 0x9F /* F8 - FF */
};
#endif /* ZIP || CRYPT */
#endif /* ?MTS */
#endif /* EBCDIC */
/*---------------------------------------------------------------------------
The following conversion tables translate between IBM PC CP 850
(OEM codepage) and the "Western Europe & America" Windows codepage 1252.
The Windows codepage 1252 contains the ISO 8859-1 "Latin 1" codepage,
with some additional printable characters in the range (0x80 - 0x9F),
that is reserved to control codes in the ISO 8859-1 character table.
The ISO <--> OEM conversion tables were constructed with the help
of the WIN32 (Win16?) API's OemToAnsi() and AnsiToOem() conversion
functions and have been checked against the CP850 and LATIN1 tables
provided in the MS-Kermit 3.14 distribution.
---------------------------------------------------------------------------*/
#ifdef IZ_ISO2OEM_ARRAY
ZCONST uch Far iso2oem[] = {
0x3F, 0x3F, 0x27, 0x9F, 0x22, 0x2E, 0xC5, 0xCE, /* 80 - 87 */
0x5E, 0x25, 0x53, 0x3C, 0x4F, 0x3F, 0x3F, 0x3F, /* 88 - 8F */
0x3F, 0x27, 0x27, 0x22, 0x22, 0x07, 0x2D, 0x2D, /* 90 - 97 */
0x7E, 0x54, 0x73, 0x3E, 0x6F, 0x3F, 0x3F, 0x59, /* 98 - 9F */
0xFF, 0xAD, 0xBD, 0x9C, 0xCF, 0xBE, 0xDD, 0xF5, /* A0 - A7 */
0xF9, 0xB8, 0xA6, 0xAE, 0xAA, 0xF0, 0xA9, 0xEE, /* A8 - AF */
0xF8, 0xF1, 0xFD, 0xFC, 0xEF, 0xE6, 0xF4, 0xFA, /* B0 - B7 */
0xF7, 0xFB, 0xA7, 0xAF, 0xAC, 0xAB, 0xF3, 0xA8, /* B8 - BF */
0xB7, 0xB5, 0xB6, 0xC7, 0x8E, 0x8F, 0x92, 0x80, /* C0 - C7 */
0xD4, 0x90, 0xD2, 0xD3, 0xDE, 0xD6, 0xD7, 0xD8, /* C8 - CF */
0xD1, 0xA5, 0xE3, 0xE0, 0xE2, 0xE5, 0x99, 0x9E, /* D0 - D7 */
0x9D, 0xEB, 0xE9, 0xEA, 0x9A, 0xED, 0xE8, 0xE1, /* D8 - DF */
0x85, 0xA0, 0x83, 0xC6, 0x84, 0x86, 0x91, 0x87, /* E0 - E7 */
0x8A, 0x82, 0x88, 0x89, 0x8D, 0xA1, 0x8C, 0x8B, /* E8 - EF */
0xD0, 0xA4, 0x95, 0xA2, 0x93, 0xE4, 0x94, 0xF6, /* F0 - F7 */
0x9B, 0x97, 0xA3, 0x96, 0x81, 0xEC, 0xE7, 0x98 /* F8 - FF */
};
#endif /* IZ_ISO2OEM_ARRAY */
#ifdef IZ_OEM2ISO_ARRAY
ZCONST uch Far oem2iso[] = {
0xC7, 0xFC, 0xE9, 0xE2, 0xE4, 0xE0, 0xE5, 0xE7, /* 80 - 87 */
0xEA, 0xEB, 0xE8, 0xEF, 0xEE, 0xEC, 0xC4, 0xC5, /* 88 - 8F */
0xC9, 0xE6, 0xC6, 0xF4, 0xF6, 0xF2, 0xFB, 0xF9, /* 90 - 97 */
0xFF, 0xD6, 0xDC, 0xF8, 0xA3, 0xD8, 0xD7, 0x83, /* 98 - 9F */
0xE1, 0xED, 0xF3, 0xFA, 0xF1, 0xD1, 0xAA, 0xBA, /* A0 - A7 */
0xBF, 0xAE, 0xAC, 0xBD, 0xBC, 0xA1, 0xAB, 0xBB, /* A8 - AF */
0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xC1, 0xC2, 0xC0, /* B0 - B7 */
0xA9, 0xA6, 0xA6, 0x2B, 0x2B, 0xA2, 0xA5, 0x2B, /* B8 - BF */
0x2B, 0x2D, 0x2D, 0x2B, 0x2D, 0x2B, 0xE3, 0xC3, /* C0 - C7 */
0x2B, 0x2B, 0x2D, 0x2D, 0xA6, 0x2D, 0x2B, 0xA4, /* C8 - CF */
0xF0, 0xD0, 0xCA, 0xCB, 0xC8, 0x69, 0xCD, 0xCE, /* D0 - D7 */
0xCF, 0x2B, 0x2B, 0xA6, 0x5F, 0xA6, 0xCC, 0xAF, /* D8 - DF */
0xD3, 0xDF, 0xD4, 0xD2, 0xF5, 0xD5, 0xB5, 0xFE, /* E0 - E7 */
0xDE, 0xDA, 0xDB, 0xD9, 0xFD, 0xDD, 0xAF, 0xB4, /* E8 - EF */
0xAD, 0xB1, 0x3D, 0xBE, 0xB6, 0xA7, 0xF7, 0xB8, /* F0 - F7 */
0xB0, 0xA8, 0xB7, 0xB9, 0xB3, 0xB2, 0xA6, 0xA0 /* F8 - FF */
};
#endif /* IZ_OEM2ISO_ARRAY */
#if defined(THEOS) || defined(THEOS_SUPPORT)
# include "theos/charconv.h"
#endif
#endif /* __ebcdic_h */

View File

@ -0,0 +1,317 @@
/*
Copyright (c) 1990-2000 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
*/
/*----------------------------------------------------------------*
| envargs - add default options from environment to command line
|----------------------------------------------------------------
| Author: Bill Davidsen, original 10/13/91, revised 23 Oct 1991.
| This program is in the public domain.
|----------------------------------------------------------------
| Minor program notes:
| 1. Yes, the indirection is a tad complex
| 2. Parentheses were added where not needed in some cases
| to make the action of the code less obscure.
|----------------------------------------------------------------
| UnZip notes: 24 May 92 ("v1.4"):
| 1. #include "unzip.h" for prototypes (24 May 92)
| 2. changed ch to type char (24 May 92)
| 3. added an ifdef to avoid Borland warnings (24 May 92)
| 4. included Rich Wales' mksargs() routine (for MS-DOS, maybe
| OS/2? NT?) (4 Dec 93)
| 5. added alternate-variable string envstr2 (21 Apr 94)
| 6. added support for quoted arguments (6 Jul 96)
*----------------------------------------------------------------*/
#define __ENVARGS_C /* identifies this source module */
#define UNZIP_INTERNAL
#include "unzip.h"
#ifdef __EMX__ /* emx isspace() returns TRUE on extended ASCII !! */
# define ISspace(c) ((c) & 0x80 ? 0 : isspace((unsigned)c))
#else
# define ISspace(c) isspace((unsigned)c)
#endif /* ?__EMX__ */
static int count_args OF((ZCONST char *));
/* envargs() returns PK-style error code */
int envargs(Pargc, Pargv, envstr, envstr2)
int *Pargc;
char ***Pargv;
ZCONST char *envstr, *envstr2;
{
#ifndef RISCOS
char *getenv();
#endif
char *envptr; /* value returned by getenv */
char *bufptr; /* copy of env info */
int argc = 0; /* internal arg count */
register int ch; /* spare temp value */
char **argv; /* internal arg vector */
char **argvect; /* copy of vector address */
/* see if anything in the environment */
if ((envptr = getenv(envstr)) != (char *)NULL) /* usual var */
while (ISspace(*envptr)) /* must discard leading spaces */
envptr++;
if (envptr == (char *)NULL || *envptr == '\0')
if ((envptr = getenv(envstr2)) != (char *)NULL) /* alternate var */
while (ISspace(*envptr))
envptr++;
if (envptr == (char *)NULL || *envptr == '\0')
return PK_OK;
bufptr = malloc(1 + strlen(envptr));
if (bufptr == (char *)NULL)
return PK_MEM;
#if (defined(WIN32) || defined(WINDLL))
# ifdef WIN32
if (IsWinNT()) {
/* SPC: don't know codepage of 'real' WinNT console */
strcpy(bufptr, envptr);
} else {
/* Win95 environment is DOS and uses OEM character coding */
OEM_TO_INTERN(envptr, bufptr);
}
# else /* !WIN32 */
/* DOS environment uses OEM codepage */
OEM_TO_INTERN(envptr, bufptr);
# endif
#else /* !(WIN32 || WINDLL) */
strcpy(bufptr, envptr);
#endif /* ?(WIN32 || WINDLL) */
/* count the args so we can allocate room for them */
argc = count_args(bufptr);
/* allocate a vector large enough for all args */
argv = (char **)malloc((argc + *Pargc + 1) * sizeof(char *));
if (argv == (char **)NULL) {
free(bufptr);
return PK_MEM;
}
argvect = argv;
/* copy the program name first, that's always true */
*(argv++) = *((*Pargv)++);
/* copy the environment args next, may be changed */
do {
#if defined(AMIGA) || defined(UNIX)
if (*bufptr == '"') {
char *argstart = ++bufptr;
*(argv++) = argstart;
for (ch = *bufptr; ch != '\0' && ch != '\"';
ch = *PREINCSTR(bufptr))
if (ch == '\\' && bufptr[1] != '\0')
++bufptr; /* advance to char after backslash */
if (ch != '\0')
*(bufptr++) = '\0'; /* overwrite trailing " */
/* remove escape characters */
while ((argstart = MBSCHR(argstart, '\\')) != (char *)NULL) {
strcpy(argstart, argstart + 1);
if (*argstart)
++argstart;
}
} else {
*(argv++) = bufptr;
while ((ch = *bufptr) != '\0' && !ISspace(ch))
INCSTR(bufptr);
if (ch != '\0')
*(bufptr++) = '\0';
}
#else
#ifdef DOS_FLX_NLM_OS2_W32
/* we do not support backslash-quoting of quotes in quoted
* strings under DOS_FLX_NLM_OS2_W32, because backslashes are
* directory separators and double quotes are illegal in filenames */
if (*bufptr == '"') {
*(argv++) = ++bufptr;
while ((ch = *bufptr) != '\0' && ch != '\"')
INCSTR(bufptr);
if (ch != '\0')
*(bufptr++) = '\0';
} else {
*(argv++) = bufptr;
while ((ch = *bufptr) != '\0' && !ISspace(ch))
INCSTR(bufptr);
if (ch != '\0')
*(bufptr++) = '\0';
}
#else
*(argv++) = bufptr;
while ((ch = *bufptr) != '\0' && !ISspace(ch))
INCSTR(bufptr);
if (ch != '\0')
*(bufptr++) = '\0';
#endif /* ?DOS_FLX_NLM_OS2_W32 */
#endif /* ?(AMIGA || UNIX) */
while ((ch = *bufptr) != '\0' && ISspace(ch))
INCSTR(bufptr);
} while (ch);
/* now save old argc and copy in the old args */
argc += *Pargc;
while (--(*Pargc))
*(argv++) = *((*Pargv)++);
/* finally, add a NULL after the last arg, like Unix */
*argv = (char *)NULL;
/* save the values and return, indicating succes */
*Pargv = argvect;
*Pargc = argc;
return PK_OK;
}
static int count_args(s)
ZCONST char *s;
{
int count = 0;
char ch;
do {
/* count and skip args */
++count;
#if defined(AMIGA) || defined(UNIX)
if (*s == '\"') {
for (ch = *PREINCSTR(s); ch != '\0' && ch != '\"';
ch = *PREINCSTR(s))
if (ch == '\\' && s[1] != '\0')
++s;
if (*s)
++s; /* trailing quote */
} else
#else
#ifdef DOS_FLX_NLM_OS2_W32
if (*s == '\"') {
++s; /* leading quote */
while ((ch = *s) != '\0' && ch != '\"')
INCSTR(s);
if (*s)
++s; /* trailing quote */
} else
#endif /* DOS_FLX_NLM_OS2_W32 */
#endif /* ?(AMIGA || UNIX) */
while ((ch = *s) != '\0' && !ISspace(ch)) /* note else-clauses above */
INCSTR(s);
while ((ch = *s) != '\0' && ISspace(ch))
INCSTR(s);
} while (ch);
return count;
}
#ifdef TEST
int main(argc, argv)
int argc;
char **argv;
{
int err;
printf("Orig argv: %p\n", argv);
dump_args(argc, argv);
if ((err = envargs(&argc, &argv, "ENVTEST")) != PK_OK) {
perror("envargs: cannot get memory for arguments");
EXIT(err);
}
printf(" New argv: %p\n", argv);
dump_args(argc, argv);
}
void dump_args(argc, argv)
int argc;
char *argv[];
{
int i;
printf("\nDump %d args:\n", argc);
for (i = 0; i < argc; ++i)
printf("%3d %s\n", i, argv[i]);
}
#endif /* TEST */
#ifdef MSDOS /* DOS_OS2? DOS_OS2_W32? */
/*
* void mksargs(int *argcp, char ***argvp)
*
* Substitutes the extended command line argument list produced by
* the MKS Korn Shell in place of the command line info from DOS.
*
* The MKS shell gets around DOS's 128-byte limit on the length of
* a command line by passing the "real" command line in the envi-
* ronment. The "real" arguments are flagged by prepending a tilde
* (~) to each one.
*
* This "mksargs" routine creates a new argument list by scanning
* the environment from the beginning, looking for strings begin-
* ning with a tilde character. The new list replaces the original
* "argv" (pointed to by "argvp"), and the number of arguments
* in the new list replaces the original "argc" (pointed to by
* "argcp").
*
* Rich Wales
*/
void mksargs(argcp, argvp)
int *argcp;
char ***argvp;
{
#ifndef MSC /* declared differently in MSC 7.0 headers, at least */
#ifndef __WATCOMC__
extern char **environ; /* environment */
#endif
#endif
char **envp; /* pointer into environment */
char **newargv; /* new argument list */
char **argp; /* pointer into new arg list */
int newargc; /* new argument count */
/* sanity check */
if (environ == NULL || argcp == NULL || argvp == NULL || *argvp == NULL)
return;
/* find out how many environment arguments there are */
for (envp = environ, newargc = 0;
*envp != NULL && (*envp)[0] == '~';
envp++, newargc++)
;
if (newargc == 0)
return; /* no environment arguments */
/* set up new argument list */
newargv = (char **) malloc(sizeof(char **) * (newargc+1));
if (newargv == NULL)
return; /* malloc failed */
for (argp = newargv, envp = environ; *envp != NULL && (*envp)[0] == '~';
*argp++ = &(*envp++)[1])
;
*argp = NULL; /* null-terminate the list */
/* substitute new argument list in place of old one */
*argcp = newargc;
*argvp = newargv;
}
#endif /* MSDOS */

View File

@ -0,0 +1,615 @@
/*
Copyright (c) 1990-2002 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
*/
/* explode.c -- by Mark Adler
version c15, 6 July 1996 */
/* Copyright history:
- Starting with UnZip 5.41 of 16-April-2000, this source file
is covered by the Info-Zip LICENSE cited above.
- Prior versions of this source file, found in UnZip source packages
up to UnZip 5.40, were put in the public domain.
The original copyright note by Mark Adler was:
"You can do whatever you like with this source file,
though I would prefer that if you modify it and
redistribute it that you include comments to that effect
with your name and the date. Thank you."
History:
vers date who what
---- --------- -------------- ------------------------------------
c1 30 Mar 92 M. Adler explode that uses huft_build from inflate
(this gives over a 70% speed improvement
over the original unimplode.c, which
decoded a bit at a time)
c2 4 Apr 92 M. Adler fixed bug for file sizes a multiple of 32k.
c3 10 Apr 92 M. Adler added a little memory tracking if DEBUG
c4 11 Apr 92 M. Adler added NOMEMCPY do kill use of memcpy()
c5 21 Apr 92 M. Adler added the WSIZE #define to allow reducing
the 32K window size for specialized
applications.
c6 31 May 92 M. Adler added typecasts to eliminate some warnings
c7 27 Jun 92 G. Roelofs added more typecasts.
c8 17 Oct 92 G. Roelofs changed ULONG/UWORD/byte to ulg/ush/uch.
c9 19 Jul 93 J. Bush added more typecasts (to return values);
made l[256] array static for Amiga.
c10 8 Oct 93 G. Roelofs added used_csize for diagnostics; added
buf and unshrink arguments to flush();
undef'd various macros at end for Turbo C;
removed NEXTBYTE macro (now in unzip.h)
and bytebuf variable (not used); changed
memset() to memzero().
c11 9 Jan 94 M. Adler fixed incorrect used_csize calculation.
c12 9 Apr 94 G. Roelofs fixed split comments on preprocessor lines
to avoid bug in Encore compiler.
c13 25 Aug 94 M. Adler fixed distance-length comment (orig c9 fix)
c14 22 Nov 95 S. Maxwell removed unnecessary "static" on auto array
c15 6 Jul 96 W. Haidinger added ulg typecasts to flush() calls.
c16 8 Feb 98 C. Spieler added ZCONST modifiers to const tables
and #ifdef DEBUG around debugging code.
c16b 25 Mar 98 C. Spieler modified DLL code for slide redirection.
c16d 05 Jul 99 C. Spieler take care of flush() return values and
stop processing in case of errors
c17 04 Feb 01 C. Spieler reorganized code to reduce repetitions
of large code parts; adapted huft decoding
to the changes in inflate's huft_build()
due to support of deflate64; fixed memory
leaks (huft tables were not free'd when
get_tree() failed).
c17b 16 Feb 02 C. Spieler changed type of the "extra lengths" array
"extra" from ush into uch (to save space)
*/
/*
Explode imploded (PKZIP method 6 compressed) data. This compression
method searches for as much of the current string of bytes (up to a length
of ~320) in the previous 4K or 8K bytes. If it doesn't find any matches
(of at least length 2 or 3), it codes the next byte. Otherwise, it codes
the length of the matched string and its distance backwards from the
current position. Single bytes ("literals") are preceded by a one (a
single bit) and are either uncoded (the eight bits go directly into the
compressed stream for a total of nine bits) or Huffman coded with a
supplied literal code tree. If literals are coded, then the minimum match
length is three, otherwise it is two.
There are therefore four kinds of imploded streams: 8K search with coded
literals (min match = 3), 4K search with coded literals (min match = 3),
8K with uncoded literals (min match = 2), and 4K with uncoded literals
(min match = 2). The kind of stream is identified in two bits of a
general purpose bit flag that is outside of the compressed stream.
Distance-length pairs for matched strings are preceded by a zero bit (to
distinguish them from literals) and are always coded. The distance comes
first and is either the low six (4K) or low seven (8K) bits of the
distance (uncoded), followed by the high six bits of the distance coded.
Then the length is six bits coded (0..63 + min match length), and if the
maximum such length is coded, then it's followed by another eight bits
(uncoded) to be added to the coded length. This gives a match length
range of 2..320 or 3..321 bytes.
The literal, length, and distance codes are all represented in a slightly
compressed form themselves. What is sent are the lengths of the codes for
each value, which is sufficient to construct the codes. Each byte of the
code representation is the code length (the low four bits representing
1..16), and the number of values sequentially with that length (the high
four bits also representing 1..16). There are 256 literal code values (if
literals are coded), 64 length code values, and 64 distance code values,
in that order at the beginning of the compressed stream. Each set of code
values is preceded (redundantly) with a byte indicating how many bytes are
in the code description that follows, in the range 1..256.
The codes themselves are decoded using tables made by huft_build() from
the bit lengths. That routine and its comments are in the inflate.c
module.
*/
#define __EXPLODE_C /* identifies this source module */
#define UNZIP_INTERNAL
#include "unzip.h" /* must supply slide[] (uch) array and NEXTBYTE macro */
#ifndef WSIZE
# define WSIZE 0x8000 /* window size--must be a power of two, and */
#endif /* at least 8K for zip's implode method */
#if (defined(DLL) && !defined(NO_SLIDE_REDIR))
# define wszimpl (unsigned)(G._wsize)
#else
# if defined(USE_DEFLATE64) && defined(INT_16BIT)
# define wszimpl (unsigned)(WSIZE>>1)
# else /* !(USE_DEFLATE64 && INT_16BIT) */
# define wszimpl WSIZE
# endif /* !(USE_DEFLATE64 && INT_16BIT) */
#endif
/* routines here */
static int get_tree OF((__GPRO__ unsigned *l, unsigned n));
static int explode_lit OF((__GPRO__ struct huft *tb, struct huft *tl,
struct huft *td, int bb, int bl, int bd,
unsigned bdl));
static int explode_nolit OF((__GPRO__ struct huft *tl, struct huft *td,
int bl, int bd, unsigned bdl));
int explode OF((__GPRO));
/* The implode algorithm uses a sliding 4K or 8K byte window on the
uncompressed stream to find repeated byte strings. This is implemented
here as a circular buffer. The index is updated simply by incrementing
and then and'ing with 0x0fff (4K-1) or 0x1fff (8K-1). Here, the 32K
buffer of inflate is used, and it works just as well to always have
a 32K circular buffer, so the index is anded with 0x7fff. This is
done to allow the window to also be used as the output buffer. */
/* This must be supplied in an external module useable like "uch slide[8192];"
or "uch *slide;", where the latter would be malloc'ed. In unzip, slide[]
is actually a 32K area for use by inflate, which uses a 32K sliding window.
*/
#define INVALID_CODE 99
#define IS_INVALID_CODE(c) ((c) == INVALID_CODE)
/* Tables for length and distance */
static ZCONST ush cplen2[] =
{2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65};
static ZCONST ush cplen3[] =
{3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66};
static ZCONST uch extra[] =
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
8};
static ZCONST ush cpdist4[] =
{1, 65, 129, 193, 257, 321, 385, 449, 513, 577, 641, 705,
769, 833, 897, 961, 1025, 1089, 1153, 1217, 1281, 1345, 1409, 1473,
1537, 1601, 1665, 1729, 1793, 1857, 1921, 1985, 2049, 2113, 2177,
2241, 2305, 2369, 2433, 2497, 2561, 2625, 2689, 2753, 2817, 2881,
2945, 3009, 3073, 3137, 3201, 3265, 3329, 3393, 3457, 3521, 3585,
3649, 3713, 3777, 3841, 3905, 3969, 4033};
static ZCONST ush cpdist8[] =
{1, 129, 257, 385, 513, 641, 769, 897, 1025, 1153, 1281,
1409, 1537, 1665, 1793, 1921, 2049, 2177, 2305, 2433, 2561, 2689,
2817, 2945, 3073, 3201, 3329, 3457, 3585, 3713, 3841, 3969, 4097,
4225, 4353, 4481, 4609, 4737, 4865, 4993, 5121, 5249, 5377, 5505,
5633, 5761, 5889, 6017, 6145, 6273, 6401, 6529, 6657, 6785, 6913,
7041, 7169, 7297, 7425, 7553, 7681, 7809, 7937, 8065};
/* Macros for inflate() bit peeking and grabbing.
The usage is:
NEEDBITS(j)
x = b & mask_bits[j];
DUMPBITS(j)
where NEEDBITS makes sure that b has at least j bits in it, and
DUMPBITS removes the bits from b. The macros use the variable k
for the number of bits in b. Normally, b and k are register
variables for speed.
*/
#define NEEDBITS(n) {while(k<(n)){b|=((ulg)NEXTBYTE)<<k;k+=8;}}
#define DUMPBITS(n) {b>>=(n);k-=(n);}
#define DECODEHUFT(htab, bits, mask) {\
NEEDBITS((unsigned)(bits))\
t = (htab) + ((~(unsigned)b)&(mask));\
while (1) {\
DUMPBITS(t->b)\
if ((e=t->e) <= 32) break;\
if (IS_INVALID_CODE(e)) return 1;\
e &= 31;\
NEEDBITS(e)\
t = t->v.t + ((~(unsigned)b)&mask_bits[e]);\
}\
}
static int get_tree(__G__ l, n)
__GDEF
unsigned *l; /* bit lengths */
unsigned n; /* number expected */
/* Get the bit lengths for a code representation from the compressed
stream. If get_tree() returns 4, then there is an error in the data.
Otherwise zero is returned. */
{
unsigned i; /* bytes remaining in list */
unsigned k; /* lengths entered */
unsigned j; /* number of codes */
unsigned b; /* bit length for those codes */
/* get bit lengths */
i = NEXTBYTE + 1; /* length/count pairs to read */
k = 0; /* next code */
do {
b = ((j = NEXTBYTE) & 0xf) + 1; /* bits in code (1..16) */
j = ((j & 0xf0) >> 4) + 1; /* codes with those bits (1..16) */
if (k + j > n)
return 4; /* don't overflow l[] */
do {
l[k++] = b;
} while (--j);
} while (--i);
return k != n ? 4 : 0; /* should have read n of them */
}
static int explode_lit(__G__ tb, tl, td, bb, bl, bd, bdl)
__GDEF
struct huft *tb, *tl, *td; /* literal, length, and distance tables */
int bb, bl, bd; /* number of bits decoded by those */
unsigned bdl; /* number of distance low bits */
/* Decompress the imploded data using coded literals and a sliding
window (of size 2^(6+bdl) bytes). */
{
ulg s; /* bytes to decompress */
register unsigned e; /* table entry flag/number of extra bits */
unsigned n, d; /* length and index for copy */
unsigned w; /* current window position */
struct huft *t; /* pointer to table entry */
unsigned mb, ml, md; /* masks for bb, bl, and bd bits */
unsigned mdl; /* mask for bdl (distance lower) bits */
register ulg b; /* bit buffer */
register unsigned k; /* number of bits in bit buffer */
unsigned u; /* true if unflushed */
int retval = 0; /* error code returned: initialized to "no error" */
/* explode the coded data */
b = k = w = 0; /* initialize bit buffer, window */
u = 1; /* buffer unflushed */
mb = mask_bits[bb]; /* precompute masks for speed */
ml = mask_bits[bl];
md = mask_bits[bd];
mdl = mask_bits[bdl];
s = G.lrec.ucsize;
while (s > 0) /* do until ucsize bytes uncompressed */
{
NEEDBITS(1)
if (b & 1) /* then literal--decode it */
{
DUMPBITS(1)
s--;
DECODEHUFT(tb, bb, mb) /* get coded literal */
redirSlide[w++] = (uch)t->v.n;
if (w == wszimpl)
{
if ((retval = flush(__G__ redirSlide, (ulg)w, 0)) != 0)
return retval;
w = u = 0;
}
}
else /* else distance/length */
{
DUMPBITS(1)
NEEDBITS(bdl) /* get distance low bits */
d = (unsigned)b & mdl;
DUMPBITS(bdl)
DECODEHUFT(td, bd, md) /* get coded distance high bits */
d = w - d - t->v.n; /* construct offset */
DECODEHUFT(tl, bl, ml) /* get coded length */
n = t->v.n;
if (e) /* get length extra bits */
{
NEEDBITS(8)
n += (unsigned)b & 0xff;
DUMPBITS(8)
}
/* do the copy */
s = (s > (ulg)n ? s - (ulg)n : 0);
do {
#if (defined(DLL) && !defined(NO_SLIDE_REDIR))
if (G.redirect_slide) {
/* &= w/ wszimpl not needed and wrong if redirect */
if (d >= wszimpl)
return 1;
e = wszimpl - (d > w ? d : w);
} else
#endif
e = wszimpl - ((d &= wszimpl-1) > w ? d : w);
if (e > n) e = n;
n -= e;
if (u && w <= d)
{
memzero(redirSlide + w, e);
w += e;
d += e;
}
else
#ifndef NOMEMCPY
if (w - d >= e) /* (this test assumes unsigned comparison) */
{
memcpy(redirSlide + w, redirSlide + d, e);
w += e;
d += e;
}
else /* do it slow to avoid memcpy() overlap */
#endif /* !NOMEMCPY */
do {
redirSlide[w++] = redirSlide[d++];
} while (--e);
if (w == wszimpl)
{
if ((retval = flush(__G__ redirSlide, (ulg)w, 0)) != 0)
return retval;
w = u = 0;
}
} while (n);
}
}
/* flush out redirSlide */
if ((retval = flush(__G__ redirSlide, (ulg)w, 0)) != 0)
return retval;
if (G.csize + G.incnt + (k >> 3)) /* should have read csize bytes, but */
{ /* sometimes read one too many: k>>3 compensates */
G.used_csize = G.lrec.csize - G.csize - G.incnt - (k >> 3);
return 5;
}
return 0;
}
static int explode_nolit(__G__ tl, td, bl, bd, bdl)
__GDEF
struct huft *tl, *td; /* length and distance decoder tables */
int bl, bd; /* number of bits decoded by tl[] and td[] */
unsigned bdl; /* number of distance low bits */
/* Decompress the imploded data using uncoded literals and a sliding
window (of size 2^(6+bdl) bytes). */
{
ulg s; /* bytes to decompress */
register unsigned e; /* table entry flag/number of extra bits */
unsigned n, d; /* length and index for copy */
unsigned w; /* current window position */
struct huft *t; /* pointer to table entry */
unsigned ml, md; /* masks for bl and bd bits */
unsigned mdl; /* mask for bdl (distance lower) bits */
register ulg b; /* bit buffer */
register unsigned k; /* number of bits in bit buffer */
unsigned u; /* true if unflushed */
int retval = 0; /* error code returned: initialized to "no error" */
/* explode the coded data */
b = k = w = 0; /* initialize bit buffer, window */
u = 1; /* buffer unflushed */
ml = mask_bits[bl]; /* precompute masks for speed */
md = mask_bits[bd];
mdl = mask_bits[bdl];
s = G.lrec.ucsize;
while (s > 0) /* do until ucsize bytes uncompressed */
{
NEEDBITS(1)
if (b & 1) /* then literal--get eight bits */
{
DUMPBITS(1)
s--;
NEEDBITS(8)
redirSlide[w++] = (uch)b;
if (w == wszimpl)
{
if ((retval = flush(__G__ redirSlide, (ulg)w, 0)) != 0)
return retval;
w = u = 0;
}
DUMPBITS(8)
}
else /* else distance/length */
{
DUMPBITS(1)
NEEDBITS(bdl) /* get distance low bits */
d = (unsigned)b & mdl;
DUMPBITS(bdl)
DECODEHUFT(td, bd, md) /* get coded distance high bits */
d = w - d - t->v.n; /* construct offset */
DECODEHUFT(tl, bl, ml) /* get coded length */
n = t->v.n;
if (e) /* get length extra bits */
{
NEEDBITS(8)
n += (unsigned)b & 0xff;
DUMPBITS(8)
}
/* do the copy */
s = (s > (ulg)n ? s - (ulg)n : 0);
do {
#if (defined(DLL) && !defined(NO_SLIDE_REDIR))
if (G.redirect_slide) {
/* &= w/ wszimpl not needed and wrong if redirect */
if (d >= wszimpl)
return 1;
e = wszimpl - (d > w ? d : w);
} else
#endif
e = wszimpl - ((d &= wszimpl-1) > w ? d : w);
if (e > n) e = n;
n -= e;
if (u && w <= d)
{
memzero(redirSlide + w, e);
w += e;
d += e;
}
else
#ifndef NOMEMCPY
if (w - d >= e) /* (this test assumes unsigned comparison) */
{
memcpy(redirSlide + w, redirSlide + d, e);
w += e;
d += e;
}
else /* do it slow to avoid memcpy() overlap */
#endif /* !NOMEMCPY */
do {
redirSlide[w++] = redirSlide[d++];
} while (--e);
if (w == wszimpl)
{
if ((retval = flush(__G__ redirSlide, (ulg)w, 0)) != 0)
return retval;
w = u = 0;
}
} while (n);
}
}
/* flush out redirSlide */
if ((retval = flush(__G__ redirSlide, (ulg)w, 0)) != 0)
return retval;
if (G.csize + G.incnt + (k >> 3)) /* should have read csize bytes, but */
{ /* sometimes read one too many: k>>3 compensates */
G.used_csize = G.lrec.csize - G.csize - G.incnt - (k >> 3);
return 5;
}
return 0;
}
int explode(__G)
__GDEF
/* Explode an imploded compressed stream. Based on the general purpose
bit flag, decide on coded or uncoded literals, and an 8K or 4K sliding
window. Construct the literal (if any), length, and distance codes and
the tables needed to decode them (using huft_build() from inflate.c),
and call the appropriate routine for the type of data in the remainder
of the stream. The four routines are nearly identical, differing only
in whether the literal is decoded or simply read in, and in how many
bits are read in, uncoded, for the low distance bits. */
{
unsigned r; /* return codes */
struct huft *tb; /* literal code table */
struct huft *tl; /* length code table */
struct huft *td; /* distance code table */
int bb; /* bits for tb */
int bl; /* bits for tl */
int bd; /* bits for td */
unsigned bdl; /* number of uncoded lower distance bits */
unsigned l[256]; /* bit lengths for codes */
#if (defined(DLL) && !defined(NO_SLIDE_REDIR))
if (G.redirect_slide)
/* For 16-bit systems, it has already been checked at DLL entrance that
* the buffer size in G.redirect_size does not exceed unsigned range.
*/
G._wsize = G.redirect_size, redirSlide = G.redirect_buffer;
else
#if defined(USE_DEFLATE64) && defined(INT_16BIT)
/* For systems using 16-bit ints, reduce the used buffer size below
* the limit of "unsigned int" numbers range.
*/
G._wsize = WSIZE>>1, redirSlide = slide;
#else /* !(USE_DEFLATE64 && INT_16BIT) */
G._wsize = WSIZE, redirSlide = slide;
#endif /* !(USE_DEFLATE64 && INT_16BIT) */
#endif /* DLL && !NO_SLIDE_REDIR */
/* Tune base table sizes. Note: I thought that to truly optimize speed,
I would have to select different bl, bd, and bb values for different
compressed file sizes. I was surprised to find out that the values of
7, 7, and 9 worked best over a very wide range of sizes, except that
bd = 8 worked marginally better for large compressed sizes. */
bl = 7;
bd = (G.csize + G.incnt) > 200000L ? 8 : 7;
#ifdef DEBUG
G.hufts = 0; /* initialize huft's malloc'ed */
#endif
if (G.lrec.general_purpose_bit_flag & 4)
/* With literal tree--minimum match length is 3 */
{
bb = 9; /* base table size for literals */
if ((r = get_tree(__G__ l, 256)) != 0)
return (int)r;
if ((r = huft_build(__G__ l, 256, 256, NULL, NULL, &tb, &bb)) != 0)
{
if (r == 1)
huft_free(tb);
return (int)r;
}
if ((r = get_tree(__G__ l, 64)) != 0) {
huft_free(tb);
return (int)r;
}
if ((r = huft_build(__G__ l, 64, 0, cplen3, extra, &tl, &bl)) != 0)
{
if (r == 1)
huft_free(tl);
huft_free(tb);
return (int)r;
}
}
else
/* No literal tree--minimum match length is 2 */
{
tb = (struct huft *)NULL;
if ((r = get_tree(__G__ l, 64)) != 0)
return (int)r;
if ((r = huft_build(__G__ l, 64, 0, cplen2, extra, &tl, &bl)) != 0)
{
if (r == 1)
huft_free(tl);
return (int)r;
}
}
if ((r = get_tree(__G__ l, 64)) != 0) {
huft_free(tl);
if (tb != (struct huft *)NULL) huft_free(tb);
return (int)r;
}
if (G.lrec.general_purpose_bit_flag & 2) /* true if 8K */
{
bdl = 7;
r = huft_build(__G__ l, 64, 0, cpdist8, extra, &td, &bd);
}
else /* else 4K */
{
bdl = 6;
r = huft_build(__G__ l, 64, 0, cpdist4, extra, &td, &bd);
}
if (r != 0)
{
if (r == 1)
huft_free(td);
huft_free(tl);
if (tb != (struct huft *)NULL) huft_free(tb);
return (int)r;
}
if (tb != NULL) {
r = explode_lit(__G__ tb, tl, td, bb, bl, bd, bdl);
huft_free(tb);
} else {
r = explode_nolit(__G__ tl, td, bl, bd, bdl);
}
huft_free(td);
huft_free(tl);
Trace((stderr, "<%u > ", G.hufts));
return (int)r;
}
/* so explode.c and inflate.c can be compiled together into one object: */
#undef DECODEHUFT
#undef NEEDBITS
#undef DUMPBITS
#undef wszimpl

2266
src/apps/bin/unzip/extract.c Normal file

File diff suppressed because it is too large Load Diff

2552
src/apps/bin/unzip/fileio.c Normal file

File diff suppressed because it is too large Load Diff

617
src/apps/bin/unzip/funzip.c Normal file
View File

@ -0,0 +1,617 @@
/*
Copyright (c) 1990-2002 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
*/
/* funzip.c -- by Mark Adler */
#define VERSION "3.94 of 20 January 2002"
/* Copyright history:
- Starting with UnZip 5.41 of 16-April-2000, this source file
is covered by the Info-Zip LICENSE cited above.
- Prior versions of this source file, found in UnZip source packages
up to UnZip 5.40, were put in the public domain.
The original copyright note by Mark Adler was:
"You can do whatever you like with this source file,
though I would prefer that if you modify it and
redistribute it that you include comments to that effect
with your name and the date. Thank you."
History:
vers date who what
---- --------- -------------- ------------------------------------
1.0 13 Aug 92 M. Adler really simple unzip filter.
1.1 13 Aug 92 M. Adler cleaned up somewhat, give help if
stdin not redirected, warn if more
zip file entries after the first.
1.2 15 Aug 92 M. Adler added check of lengths for stored
entries, added more help.
1.3 16 Aug 92 M. Adler removed redundant #define's, added
decryption.
1.4 27 Aug 92 G. Roelofs added exit(0).
1.5 1 Sep 92 K. U. Rommel changed read/write modes for OS/2.
1.6 6 Sep 92 G. Roelofs modified to use dummy crypt.c and
crypt.h instead of -DCRYPT.
1.7 23 Sep 92 G. Roelofs changed to use DOS_OS2; included
crypt.c under MS-DOS.
1.8 9 Oct 92 M. Adler improved inflation error msgs.
1.9 17 Oct 92 G. Roelofs changed ULONG/UWORD/byte to ulg/ush/uch;
renamed inflate_entry() to inflate();
adapted to use new, in-place zdecode.
2.0 22 Oct 92 M. Adler allow filename argument, prompt for
passwords and don't echo, still allow
command-line password entry, but as an
option.
2.1 23 Oct 92 J-l. Gailly fixed crypt/store bug,
G. Roelofs removed crypt.c under MS-DOS, fixed
decryption check to compare single byte.
2.2 28 Oct 92 G. Roelofs removed declaration of key.
2.3 14 Dec 92 M. Adler replaced fseek (fails on stdin for SCO
Unix V.3.2.4). added quietflg for
inflate.c.
3.0 11 May 93 M. Adler added gzip support
3.1 9 Jul 93 K. U. Rommel fixed OS/2 pipe bug (PIPE_ERROR)
3.2 4 Sep 93 G. Roelofs moved crc_32_tab[] to tables.h; used FOPx
from unzip.h; nuked OUTB macro and outbuf;
replaced flush(); inlined FlushOutput();
renamed decrypt to encrypted
3.3 29 Sep 93 G. Roelofs replaced ReadByte() with NEXTBYTE macro;
revised (restored?) flush(); added FUNZIP
3.4 21 Oct 93 G. Roelofs renamed quietflg to qflag; changed outcnt,
H. Gessau second updcrc() arg and flush() arg to ulg;
added inflate_free(); added "g =" to null
getc(in) to avoid compiler warnings
3.5 31 Oct 93 H. Gessau changed DOS_OS2 to DOS_NT_OS2
3.6 6 Dec 93 H. Gessau added "near" to mask_bits[]
3.7 9 Dec 93 G. Roelofs added extent typecasts to fwrite() checks
3.8 28 Jan 94 GRR/JlG initialized g variable in main() for gcc
3.81 22 Feb 94 M. Hanning-Lee corrected usage message
3.82 27 Feb 94 G. Roelofs added some typecasts to avoid warnings
3.83 22 Jul 94 G. Roelofs changed fprintf to macro for DLLs
- 2 Aug 94 - public release with UnZip 5.11
- 28 Aug 94 - public release with UnZip 5.12
3.84 1 Oct 94 K. U. Rommel changes for Metaware High C
3.85 29 Oct 94 G. Roelofs changed fprintf macro to Info
3.86 7 May 95 K. Davis RISCOS patches;
P. Kienitz Amiga patches
3.87 12 Aug 95 G. Roelofs inflate_free(), DESTROYGLOBALS fixes
3.88 4 Sep 95 C. Spieler reordered macro to work around MSC 5.1 bug
3.89 22 Nov 95 PK/CS ifdef'd out updcrc() for ASM_CRC
3.9 17 Dec 95 G. Roelofs modified for USE_ZLIB (new fillinbuf())
- 30 Apr 96 - public release with UnZip 5.2
3.91 17 Aug 96 G. Roelofs main() -> return int (Peter Seebach)
3.92 13 Apr 97 G. Roelofs minor cosmetic fixes to messages
- 22 Apr 97 - public release with UnZip 5.3
- 31 May 97 - public release with UnZip 5.31
3.93 20 Sep 97 G. Roelofs minor cosmetic fixes to messages
- 3 Nov 97 - public release with UnZip 5.32
- 28 Nov 98 - public release with UnZip 5.4
- 16 Apr 00 - public release with UnZip 5.41
- 14 Jan 01 - public release with UnZip 5.42
3.94 20 Feb 01 C. Spieler added support for Deflate64(tm)
*/
/*
All funzip does is take a zipfile from stdin and decompress the
first entry to stdout. The entry has to be either deflated or
stored. If the entry is encrypted, then the decryption password
must be supplied on the command line as the first argument.
funzip needs to be linked with inflate.o and crypt.o compiled from
the unzip source. If decryption is desired, the full version of
crypt.c (and crypt.h) from zcrypt28.zip or later must be used.
*/
#ifndef FUNZIP
# define FUNZIP
#endif
#define UNZIP_INTERNAL
#include "unzip.h"
#include "crypt.h"
#include "ttyio.h"
#ifdef EBCDIC
# undef EBCDIC /* don't need ebcdic[] */
#endif
#include "tables.h" /* crc_32_tab[] */
#ifndef USE_ZLIB /* zlib's function is called inflate(), too */
# define UZinflate inflate
#endif
/* PKZIP header definitions */
#define ZIPMAG 0x4b50 /* two-byte zip lead-in */
#define LOCREM 0x0403 /* remaining two bytes in zip signature */
#define LOCSIG 0x04034b50L /* full signature */
#define LOCFLG 4 /* offset of bit flag */
#define CRPFLG 1 /* bit for encrypted entry */
#define EXTFLG 8 /* bit for extended local header */
#define LOCHOW 6 /* offset of compression method */
#define LOCTIM 8 /* file mod time (for decryption) */
#define LOCCRC 12 /* offset of crc */
#define LOCSIZ 16 /* offset of compressed size */
#define LOCLEN 20 /* offset of uncompressed length */
#define LOCFIL 24 /* offset of file name field length */
#define LOCEXT 26 /* offset of extra field length */
#define LOCHDR 28 /* size of local header, including LOCREM */
#define EXTHDR 16 /* size of extended local header, inc sig */
/* GZIP header definitions */
#define GZPMAG 0x8b1f /* two-byte gzip lead-in */
#define GZPHOW 0 /* offset of method number */
#define GZPFLG 1 /* offset of gzip flags */
#define GZPMUL 2 /* bit for multiple-part gzip file */
#define GZPISX 4 /* bit for extra field present */
#define GZPISF 8 /* bit for filename present */
#define GZPISC 16 /* bit for comment present */
#define GZPISE 32 /* bit for encryption */
#define GZPTIM 2 /* offset of Unix file modification time */
#define GZPEXF 6 /* offset of extra flags */
#define GZPCOS 7 /* offset of operating system compressed on */
#define GZPHDR 8 /* length of minimal gzip header */
#ifdef THEOS
/* Macros cause stack overflow in compiler */
ush SH(uch* p) { return ((ush)(uch)((p)[0]) | ((ush)(uch)((p)[1]) << 8)); }
ulg LG(uch* p) { return ((ulg)(SH(p)) | ((ulg)(SH((p)+2)) << 16)); }
#else /* !THEOS */
/* Macros for getting two-byte and four-byte header values */
#define SH(p) ((ush)(uch)((p)[0]) | ((ush)(uch)((p)[1]) << 8))
#define LG(p) ((ulg)(SH(p)) | ((ulg)(SH((p)+2)) << 16))
#endif /* ?THEOS */
/* Function prototypes */
static void err OF((int, char *));
#if (defined(USE_DEFLATE64) && defined(__16BIT__))
static int partflush OF((uch *rawbuf, unsigned w));
#endif
int main OF((int, char **));
/* Globals */
FILE *out; /* output file (*in moved to G struct) */
ulg outsiz; /* total bytes written to out */
int encrypted; /* flag to turn on decryption */
/* Masks for inflate.c */
ZCONST ush near mask_bits[] = {
0x0000,
0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
};
#ifdef USE_ZLIB
int fillinbuf(__G)
__GDEF
/* Fill input buffer for pull-model inflate() in zlib. Return the number of
* bytes in inbuf. */
{
/* GRR: check return value from fread(): same as read()? check errno? */
if ((G.incnt = fread((char *)G.inbuf, 1, INBUFSIZ, G.in)) <= 0)
return 0;
G.inptr = G.inbuf;
#if CRYPT
if (encrypted) {
uch *p;
int n;
for (n = G.incnt, p = G.inptr; n--; p++)
zdecode(*p);
}
#endif /* CRYPT */
return G.incnt;
}
#endif /* USE_ZLIB */
#if (!defined(USE_ZLIB) || defined(USE_OWN_CRCTAB))
#ifdef USE_ZLIB
ZCONST uLongf *get_crc_table()
{
return (ZCONST uLongf *)crc_32_tab;
}
#else /* !USE_ZLIB */
ZCONST ulg near *get_crc_table()
{
return crc_32_tab;
}
#endif /* ?USE_ZLIB */
#endif /* !USE_ZLIB || USE_OWN_CRCTAB */
static void err(n, m)
int n;
char *m;
/* Exit on error with a message and a code */
{
Info(slide, 1, ((char *)slide, "funzip error: %s\n", m));
DESTROYGLOBALS();
EXIT(n);
}
#if (defined(USE_DEFLATE64) && defined(__16BIT__))
static int partflush(rawbuf, w)
uch *rawbuf; /* start of buffer area to flush */
extent w; /* number of bytes to flush */
{
G.crc32val = crc32(G.crc32val, rawbuf, (extent)w);
if (fwrite((char *)rawbuf,1,(extent)w,out) != (extent)w && !PIPE_ERROR)
err(9, "out of space on stdout");
outsiz += w;
return 0;
}
int flush(w) /* used by inflate.c (FLUSH macro) */
ulg w; /* number of bytes to flush */
{
uch *rawbuf;
int ret;
/* On 16-bit systems (MSDOS, OS/2 1.x), the standard C library functions
* cannot handle writes of 64k blocks at once. For these systems, the
* blocks to flush are split into pieces of 32k or less.
*/
rawbuf = slide;
while (w > 0x8000L) {
ret = partflush(rawbuf, 0x8000);
if (ret != PK_OK)
return ret;
w -= 0x8000L;
rawbuf += (unsigned)0x8000;
}
return partflush(rawbuf, (extent)w);
} /* end function flush() */
#else /* !(USE_DEFLATE64 && __16BIT__) */
int flush(w) /* used by inflate.c (FLUSH macro) */
ulg w; /* number of bytes to flush */
{
G.crc32val = crc32(G.crc32val, slide, (extent)w);
if (fwrite((char *)slide,1,(extent)w,out) != (extent)w && !PIPE_ERROR)
err(9, "out of space on stdout");
outsiz += w;
return 0;
}
#endif /* ?(USE_DEFLATE64 && __16BIT__) */
int main(argc, argv)
int argc;
char **argv;
/* Given a zipfile on stdin, decompress the first entry to stdout. */
{
ush n;
uch h[LOCHDR]; /* first local header (GZPHDR < LOCHDR) */
int g = 0; /* true if gzip format */
unsigned method = 0; /* initialized here to shut up gcc warning */
#if CRYPT
char *s = " [-password]";
char *p; /* password */
#else /* !CRYPT */
char *s = "";
#endif /* ?CRYPT */
CONSTRUCTGLOBALS();
/* skip executable name */
argc--;
argv++;
#if CRYPT
/* get the command line password, if any */
p = (char *)NULL;
if (argc && **argv == '-')
{
argc--;
p = 1 + *argv++;
}
#endif /* CRYPT */
#ifdef MALLOC_WORK
/* The following expression is a cooked-down simplyfication of the
calculation for the work area size of UnZip (see unzip.c). For
fUnZip, the work area does not need to match the granularity
of the complex unshrink structures, because it only supports
inflation. But, like in UnZip, the zcalloc() wrapper function
is needed for the allocation, to support the 64kByte buffer on
16-bit systems.
*/
# define UZ_SLIDE_CHUNK (sizeof(shrint)+sizeof(uch)+sizeof(uch))
# define UZ_NUMOF_CHUNKS (unsigned)( (WSIZE+UZ_SLIDE_CHUNK-1)/UZ_SLIDE_CHUNK )
G.area.Slide = (uch *)zcalloc(UZ_NUMOF_CHUNKS, UZ_SLIDE_CHUNK);
# undef UZ_SLIDE_CHUNK
# undef UZ_NUMOF_CHUNKS
#endif
/* if no file argument and stdin not redirected, give the user help */
if (argc == 0 && isatty(0))
{
Info(slide, 1, ((char *)slide, "fUnZip (filter UnZip), version %s\n",
VERSION));
Info(slide, 1, ((char *)slide, "usage: ... | funzip%s | ...\n", s));
Info(slide, 1, ((char *)slide, " ... | funzip%s > outfile\n", s));
Info(slide, 1, ((char *)slide, " funzip%s infile.zip > outfile\n",s));
Info(slide, 1, ((char *)slide, " funzip%s infile.gz > outfile\n", s));
Info(slide, 1, ((char *)slide, "Extracts to stdout the gzip file or first\
zip entry of stdin or the given file.\n"));
DESTROYGLOBALS();
EXIT(3);
}
/* prepare to be a binary filter */
if (argc)
{
if ((G.in = fopen(*argv, FOPR)) == (FILE *)NULL)
err(2, "cannot find input file");
}
else
{
#ifdef DOS_FLX_NLM_OS2_W32
#if (defined(__HIGHC__) && !defined(FLEXOS))
setmode(stdin, _BINARY);
#else
setmode(0, O_BINARY); /* some buggy C libraries require BOTH setmode() */
#endif /* call AND the fdopen() in binary mode :-( */
#endif /* DOS_FLX_NLM_OS2_W32 */
#ifdef RISCOS
G.in = stdin;
#else
if ((G.in = fdopen(0, FOPR)) == (FILE *)NULL)
err(2, "cannot find stdin");
#endif
}
#ifdef DOS_FLX_H68_NLM_OS2_W32
#if (defined(__HIGHC__) && !defined(FLEXOS))
setmode(stdout, _BINARY);
#else
setmode(1, O_BINARY);
#endif
#endif /* DOS_FLX_H68_NLM_OS2_W32 */
#ifdef RISCOS
out = stdout;
#else
if ((out = fdopen(1, FOPW)) == (FILE *)NULL)
err(2, "cannot write to stdout");
#endif
/* read local header, check validity, and skip name and extra fields */
n = getc(G.in); n |= getc(G.in) << 8;
if (n == ZIPMAG)
{
if (fread((char *)h, 1, LOCHDR, G.in) != LOCHDR || SH(h) != LOCREM)
err(3, "invalid zipfile");
switch (method = SH(h + LOCHOW)) {
case STORED:
case DEFLATED:
#ifdef USE_DEFLATE64
case ENHDEFLATED:
#endif
break;
default:
err(3, "first entry not deflated or stored--cannot unpack");
break;
}
for (n = SH(h + LOCFIL); n--; ) g = getc(G.in);
for (n = SH(h + LOCEXT); n--; ) g = getc(G.in);
g = 0;
encrypted = h[LOCFLG] & CRPFLG;
}
else if (n == GZPMAG)
{
if (fread((char *)h, 1, GZPHDR, G.in) != GZPHDR)
err(3, "invalid gzip file");
if ((method = h[GZPHOW]) != DEFLATED && method != ENHDEFLATED)
err(3, "gzip file not deflated");
if (h[GZPFLG] & GZPMUL)
err(3, "cannot handle multi-part gzip files");
if (h[GZPFLG] & GZPISX)
{
n = getc(G.in); n |= getc(G.in) << 8;
while (n--) g = getc(G.in);
}
if (h[GZPFLG] & GZPISF)
while ((g = getc(G.in)) != 0 && g != EOF) ;
if (h[GZPFLG] & GZPISC)
while ((g = getc(G.in)) != 0 && g != EOF) ;
g = 1;
encrypted = h[GZPFLG] & GZPISE;
}
else
err(3, "input not a zip or gzip file");
/* if entry encrypted, decrypt and validate encryption header */
if (encrypted)
#if CRYPT
{
ush i, e;
if (p == (char *)NULL) {
if ((p = (char *)malloc(IZ_PWLEN+1)) == (char *)NULL)
err(1, "out of memory");
else if ((p = getp("Enter password: ", p, IZ_PWLEN+1)) == (char *)NULL)
err(1, "no tty to prompt for password");
}
#if (defined(USE_ZLIB) && !defined(USE_OWN_CRCTAB))
/* initialize crc_32_tab pointer for decryption */
CRC_32_TAB = (ZCONST ulg Far *)get_crc_table();
#endif
init_keys(p);
for (i = 0; i < RAND_HEAD_LEN; i++)
e = NEXTBYTE;
if (e != (ush)(h[LOCFLG] & EXTFLG ? h[LOCTIM + 1] : h[LOCCRC + 3]))
err(3, "incorrect password for first entry");
}
#else /* !CRYPT */
err(3, "cannot decrypt entry (need to recompile with full crypt.c)");
#endif /* ?CRYPT */
/* prepare output buffer and crc */
G.outptr = slide;
G.outcnt = 0L;
outsiz = 0L;
G.crc32val = CRCVAL_INITIAL;
/* decompress */
if (g || h[LOCHOW])
{ /* deflated entry */
int r;
#ifdef USE_ZLIB
/* need to allocate and prepare input buffer */
if ((G.inbuf = (uch *)malloc(INBUFSIZ)) == (uch *)NULL)
err(1, "out of memory");
#endif /* USE_ZLIB */
if ((r = UZinflate(__G__ (method == ENHDEFLATED))) != 0) {
if (r == 3)
err(1, "out of memory");
else
err(4, "invalid compressed data--format violated");
}
inflate_free(__G);
}
else
{ /* stored entry */
register ulg n;
n = LG(h + LOCLEN);
#if CRYPT
if (n != LG(h + LOCSIZ) - (encrypted ? RAND_HEAD_LEN : 0)) {
#else
if (n != LG(h + LOCSIZ)) {
#endif
Info(slide, 1, ((char *)slide, "len %ld, siz %ld\n", n, LG(h + LOCSIZ)));
err(4, "invalid compressed data--length mismatch");
}
while (n--) {
ush c = getc(G.in);
#if CRYPT
if (encrypted)
zdecode(c);
#endif
*G.outptr++ = (uch)c;
#if (defined(USE_DEFLATE64) && defined(__16BIT__))
if (++G.outcnt == (WSIZE>>1)) /* do FlushOutput() */
#else
if (++G.outcnt == WSIZE) /* do FlushOutput() */
#endif
{
G.crc32val = crc32(G.crc32val, slide, (extent)G.outcnt);
if (fwrite((char *)slide, 1,(extent)G.outcnt,out) != (extent)G.outcnt
&& !PIPE_ERROR)
err(9, "out of space on stdout");
outsiz += G.outcnt;
G.outptr = slide;
G.outcnt = 0L;
}
}
}
if (G.outcnt) /* flush one last time; no need to reset G.outptr/outcnt */
{
G.crc32val = crc32(G.crc32val, slide, (extent)G.outcnt);
if (fwrite((char *)slide, 1,(extent)G.outcnt,out) != (extent)G.outcnt
&& !PIPE_ERROR)
err(9, "out of space on stdout");
outsiz += G.outcnt;
}
fflush(out);
/* if extended header, get it */
if (g)
{
if (fread((char *)h + LOCCRC, 1, 8, G.in) != 8)
err(3, "gzip file ended prematurely");
}
else
if ((h[LOCFLG] & EXTFLG) &&
fread((char *)h + LOCCRC - 4, 1, EXTHDR, G.in) != EXTHDR)
err(3, "zipfile ended prematurely");
/* validate decompression */
if (LG(h + LOCCRC) != G.crc32val)
err(4, "invalid compressed data--crc error");
if (LG((g ? (h + LOCSIZ) : (h + LOCLEN))) != outsiz)
err(4, "invalid compressed data--length error");
/* check if there are more entries */
if (!g && fread((char *)h, 1, 4, G.in) == 4 && LG(h) == LOCSIG)
Info(slide, 1, ((char *)slide,
"funzip warning: zipfile has more than one entry--rest ignored\n"));
DESTROYGLOBALS();
RETURN (0);
}
/***********************/
/* Function readbyte() */
/***********************/
int readbyte(__G) /* refill inbuf and return a byte if available, else EOF */
__GDEF
{
if (G.mem_mode)
return EOF;
if (G.csize <= 0) {
G.csize--; /* for tests done after exploding */
G.incnt = 0;
return EOF;
}
if (G.incnt <= 0) {
if ((G.incnt = read(G.zipfd, (char *)G.inbuf, INBUFSIZ)) == 0) {
G.incnt = 0; /* do not allow negative value to affect stuff */
return EOF;
} else if (G.incnt < 0) { /* "fail" (abort, retry, ...) returns this */
/* another hack, but no real harm copying same thing twice */
(*G.message)((zvoid *)&G,
(uch *)LoadFarString(ReadError),
(ulg)strlen(LoadFarString(ReadError)), 0x401);
echon();
#ifdef WINDLL
longjmp(dll_error_return, 1);
#else
DESTROYGLOBALS();
EXIT(PK_BADERR); /* totally bailing; better than lock-up */
#endif
}
G.cur_zipfile_bufstart += INBUFSIZ; /* always starts on block bndry */
G.inptr = G.inbuf;
defer_leftover_input(__G); /* decrements G.csize */
}
#if CRYPT
if (G.pInfo->encrypted) {
uch *p;
int n;
/* This was previously set to decrypt one byte beyond G.csize, when
* incnt reached that far. GRR said, "but it's required: why?" This
* was a bug in fillinbuf() -- was it also a bug here?
*/
for (n = G.incnt, p = G.inptr; n--; p++)
zdecode(*p);
}
#endif /* CRYPT */
--G.incnt;
return *G.inptr++;
} /* end function readbyte() */

View File

@ -0,0 +1,106 @@
FUNZIP(1L) FUNZIP(1L)
NAME
funzip - filter for extracting from a ZIP archive in a
pipe
SYNOPSIS
funzip [-password] [input[.zip|.gz]]
ARGUMENTS
[-password]
Optional password to be used if ZIP archive is
encrypted. Decryption may not be supported at some
sites. See DESCRIPTION for more details.
[input[.zip|.gz]]
Optional input archive file specification. See
DESCRIPTION for details.
DESCRIPTION
funzip without a file argument acts as a filter; that is,
it assumes that a ZIP archive (or a gzip'd(1) file) is
being piped into standard input, and it extracts the first
member from the archive to stdout. When stdin comes from
a tty device, funzip assumes that this cannot be a stream
of (binary) compressed data and shows a short help text,
instead. If there is a file argument, then input is read
from the specified file instead of from stdin.
A password for encrypted zip files can be specified on the
command line (preceding the file name, if any) by prefix-
ing the password with a dash. Note that this constitutes
a security risk on many systems; currently running pro-
cesses are often visible via simple commands (e.g., ps(1)
under Unix), and command-line histories can be read. If
the first entry of the zip file is encrypted and no pass-
word is specified on the command line, then the user is
prompted for a password and the password is not echoed on
the console.
Given the limitation on single-member extraction, funzip
is most useful in conjunction with a secondary archiver
program such as tar(1). The following section includes an
example illustrating this usage in the case of disk back-
ups to tape.
EXAMPLES
To use funzip to extract the first member file of the
archive test.zip and to pipe it into more(1):
funzip test.zip | more
To use funzip to test the first member file of test.zip
(any errors will be reported on standard error):
funzip test.zip > /dev/null
Info-ZIP 17 February 2002 (v3.94) 1
FUNZIP(1L) FUNZIP(1L)
To use zip and funzip in place of compress(1) and zcat(1)
(or gzip(1L) and gzcat(1L)) for tape backups:
tar cf - . | zip -7 | dd of=/dev/nrst0 obs=8k
dd if=/dev/nrst0 ibs=8k | funzip | tar xf -
(where, for example, nrst0 is a SCSI tape drive).
BUGS
When piping an encrypted file into more and allowing fun-
zip to prompt for password, the terminal may sometimes be
reset to a non-echo mode. This is apparently due to a
race condition between the two programs; funzip changes
the terminal mode to non-echo before more reads its state,
and more then ``restores'' the terminal to this mode
before exiting. To recover, run funzip on the same file
but redirect to /dev/null rather than piping into more;
after prompting again for the password, funzip will reset
the terminal properly.
There is presently no way to extract any member but the
first from a ZIP archive. This would be useful in the
case where a ZIP archive is included within another
archive. In the case where the first member is a direc-
tory, funzip simply creates the directory and exits.
The functionality of funzip should be incorporated into
unzip itself (future release).
SEE ALSO
gzip(1L), unzip(1L), unzipsfx(1L), zip(1L), zipcloak(1L),
zipinfo(1L), zipnote(1L), zipsplit(1L)
URL
The Info-ZIP home page is currently at
http://www.info-zip.org/pub/infozip/
or
ftp://ftp.info-zip.org/pub/infozip/ .
AUTHOR
Mark Adler (Info-ZIP)
Info-ZIP 17 February 2002 (v3.94) 2

View File

@ -0,0 +1,4 @@
/*
Quick hack so that I can compile unzipsfx without playing with Jam rules
*/
#define USE_STRM_INPUT

View File

@ -0,0 +1,104 @@
/*
Copyright (c) 1990-2002 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
*/
/* Write out a fragment of assembly source giving offsets in "Uz_Globs"
* and "struct huft":
*/
#define UNZIP_INTERNAL
#include "unzip.h"
#include "crypt.h"
#ifndef REENTRANT
Uz_Globs G;
#endif
static int asm_setflag(const char *flagname);
static int ccp_setflag(const char *flagname);
static int asm_setflag(const char *flagname)
{
static const char asm_flagdef[] = "%-15s EQU 1\n";
return printf(asm_flagdef, flagname);
}
static int ccp_setflag(const char *flagname)
{
static const char ccp_flagdef[] = "#ifndef %s\n# define %s\n#endif\n";
return printf(ccp_flagdef, flagname, flagname);
}
int main(argc, argv)
int argc;
char **argv;
{
#ifdef REENTRANT
Uz_Globs *pG = NULL;
#endif
struct huft *t = NULL;
static const char asm_offsdef[] = "%-15s EQU %lu\n";
static const char ccp_offsdef[] = "#define %-15s %lu\n";
const char *out_format;
int (*set_flag)(const char *flagname);
int ccp_select = 0;
if (argc > 1 && argv[1] != NULL && !strcmp(argv[1], "-ccp"))
ccp_select = 1;
if (ccp_select) {
out_format = ccp_offsdef;
set_flag = ccp_setflag;
} else {
out_format = asm_offsdef;
set_flag = asm_setflag;
}
printf(out_format, "h_e", (ulg)&t->e - (ulg)t);
printf(out_format, "h_b", (ulg)&t->b - (ulg)t);
printf(out_format, "h_v_n", (ulg)&t->v.n - (ulg)t);
printf(out_format, "h_v_t", (ulg)&t->v.t - (ulg)t);
printf(out_format, "SIZEOF_huft", (ulg)sizeof(struct huft));
printf(out_format, "bb", (ulg)&G.bb - (ulg)&G);
printf(out_format, "bk", (ulg)&G.bk - (ulg)&G);
printf(out_format, "wp", (ulg)&G.wp - (ulg)&G);
#ifdef FUNZIP
printf(out_format, "in", (ulg)&G.in - (ulg)&G);
#else
printf(out_format, "incnt", (ulg)&G.incnt - (ulg)&G);
printf(out_format, "inptr", (ulg)&G.inptr - (ulg)&G);
printf(out_format, "csize", (ulg)&G.csize - (ulg)&G);
printf(out_format, "mem_mode", (ulg)&G.mem_mode - (ulg)&G);
#endif
printf(out_format, "redirslide", (ulg)&redirSlide - (ulg)&G);
printf(out_format, "SIZEOF_slide", (ulg)sizeof(redirSlide));
#if (defined(DLL) && !defined(NO_SLIDE_REDIR))
printf(out_format, "_wsize", (ulg)&G._wsize - (ulg)&G);
#endif /* DLL && !NO_SLIDE_REDIR */
printf(out_format, "CRYPT", (ulg)CRYPT);
#ifdef FUNZIP
(*set_flag)("FUNZIP");
#endif
#ifdef SFX
(*set_flag)("SFX");
#endif
#ifdef REENTRANT
(*set_flag)("REENTRANT");
#endif
#ifdef DLL
(*set_flag)("DLL");
# ifdef NO_SLIDE_REDIR
(*set_flag)("NO_SLIDE_REDIR");
# endif
#endif
#ifdef USE_DEFLATE64
(*set_flag)("USE_DEFLATE64");
#endif
return 0;
}

View File

@ -0,0 +1,215 @@
/*
Copyright (c) 1990-2000 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
*/
/*---------------------------------------------------------------------------
globals.c
Routines to allocate and initialize globals, with or without threads.
Contents: registerGlobalPointer()
deregisterGlobalPointer()
getGlobalPointer()
globalsCtor()
---------------------------------------------------------------------------*/
#define UNZIP_INTERNAL
#include "unzip.h"
#ifndef FUNZIP
/* initialization of sigs is completed at runtime so unzip(sfx) executable
* won't look like a zipfile
*/
char central_hdr_sig[4] = {0, 0, 0x01, 0x02};
char local_hdr_sig[4] = {0, 0, 0x03, 0x04};
char end_central_sig[4] = {0, 0, 0x05, 0x06};
/* extern char extd_local_sig[4] = {0, 0, 0x07, 0x08}; NOT USED YET */
ZCONST char *fnames[2] = {"*", NULL}; /* default filenames vector */
#endif
#ifndef REENTRANT
Uz_Globs G;
#else /* REENTRANT */
# ifndef USETHREADID
Uz_Globs *GG;
# else /* USETHREADID */
# define THREADID_ENTRIES 0x40
int lastScan;
Uz_Globs *threadPtrTable[THREADID_ENTRIES];
ulg threadIdTable [THREADID_ENTRIES] = {
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* Make sure there are */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* THREADID_ENTRIES 0s */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0
};
static ZCONST char Far TooManyThreads[] =
"error: more than %d simultaneous threads.\n\
Some threads are probably not calling DESTROYTHREAD()\n";
static ZCONST char Far EntryNotFound[] =
"error: couldn't find global pointer in table.\n\
Maybe somebody accidentally called DESTROYTHREAD() twice.\n";
static ZCONST char Far GlobalPointerMismatch[] =
"error: global pointer in table does not match pointer passed as\
parameter\n";
static void registerGlobalPointer OF((__GPRO));
static void registerGlobalPointer(__G)
__GDEF
{
int scan=0;
ulg tid = GetThreadId();
while (threadIdTable[scan] && scan < THREADID_ENTRIES)
scan++;
if (scan == THREADID_ENTRIES) {
ZCONST char *tooMany = LoadFarString(TooManyThreads);
Info(slide, 0x421, ((char *)slide, tooMany, THREADID_ENTRIES));
free(pG);
EXIT(PK_MEM); /* essentially memory error before we've started */
}
threadIdTable [scan] = tid;
threadPtrTable[scan] = pG;
lastScan = scan;
}
void deregisterGlobalPointer(__G)
__GDEF
{
int scan=0;
ulg tid = GetThreadId();
while (threadIdTable[scan] != tid && scan < THREADID_ENTRIES)
scan++;
/*---------------------------------------------------------------------------
There are two things we can do if we can't find the entry: ignore it or
scream. The most likely reason for it not to be here is the user calling
this routine twice. Since this could cause BIG problems if any globals
are accessed after the first call, we'd better scream.
---------------------------------------------------------------------------*/
if (scan == THREADID_ENTRIES || threadPtrTable[scan] != pG) {
ZCONST char *noEntry;
if (scan == THREADID_ENTRIES)
noEntry = LoadFarString(EntryNotFound);
else
noEntry = LoadFarString(GlobalPointerMismatch);
Info(slide, 0x421, ((char *)slide, noEntry));
EXIT(PK_WARN); /* programming error, but after we're all done */
}
threadIdTable [scan] = 0;
lastScan = scan;
free(threadPtrTable[scan]);
}
Uz_Globs *getGlobalPointer()
{
int scan=0;
ulg tid = GetThreadId();
while (threadIdTable[scan] != tid && scan < THREADID_ENTRIES)
scan++;
/*---------------------------------------------------------------------------
There are two things we can do if we can't find the entry: ignore it or
scream. The most likely reason for it not to be here is the user calling
this routine twice. Since this could cause BIG problems if any globals
are accessed after the first call, we'd better scream.
---------------------------------------------------------------------------*/
if (scan == THREADID_ENTRIES) {
ZCONST char *noEntry = LoadFarString(EntryNotFound);
fprintf(stderr, noEntry); /* can't use Info w/o a global pointer */
EXIT(PK_ERR); /* programming error while still working */
}
return threadPtrTable[scan];
}
# endif /* ?USETHREADID */
#endif /* ?REENTRANT */
Uz_Globs *globalsCtor()
{
#ifdef REENTRANT
Uz_Globs *pG = (Uz_Globs *)malloc(sizeof(Uz_Globs));
if (!pG)
return (Uz_Globs *)NULL;
#endif /* REENTRANT */
/* for REENTRANT version, G is defined as (*pG) */
memzero(&G, sizeof(Uz_Globs));
#ifndef FUNZIP
#ifdef CMS_MVS
uO.aflag=1;
uO.C_flag=1;
#endif
#ifdef TANDEM
uO.aflag=1; /* default to '-a' auto create Text Files as type 101 */
#endif
uO.lflag=(-1);
G.wildzipfn = "";
G.pfnames = (char **)fnames;
G.pxnames = (char **)&fnames[1];
G.pInfo = G.info;
G.sol = TRUE; /* at start of line */
G.message = UzpMessagePrnt;
G.input = UzpInput; /* not used by anyone at the moment... */
#if defined(WINDLL) || defined(MACOS)
G.mpause = NULL; /* has scrollbars: no need for pausing */
#else
G.mpause = UzpMorePause;
#endif
G.decr_passwd = UzpPassword;
#endif /* !FUNZIP */
#if (!defined(DOS_FLX_H68_NLM_OS2_W32) && !defined(AMIGA) && !defined(RISCOS))
#if (!defined(MACOS) && !defined(ATARI) && !defined(VMS))
G.echofd = -1;
#endif /* !(MACOS || ATARI || VMS) */
#endif /* !(DOS_FLX_H68_NLM_OS2_W32 || AMIGA || RISCOS) */
#ifdef SYSTEM_SPECIFIC_CTOR
SYSTEM_SPECIFIC_CTOR(__G);
#endif
#ifdef REENTRANT
#ifdef USETHREADID
registerGlobalPointer(__G);
#else
GG = &G;
#endif /* ?USETHREADID */
#endif /* REENTRANT */
return &G;
}

View File

@ -0,0 +1,425 @@
/*
Copyright (c) 1990-2002 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
*/
/*---------------------------------------------------------------------------
globals.h
There is usually no need to include this file since unzip.h includes it.
This header file is used by all of the UnZip source files. It contains
a struct definition that is used to "house" all of the global variables.
This is done to allow for multithreaded environments (OS/2, NT, Win95,
Unix) to call UnZip through an API without a semaphore. REENTRANT should
be defined for all platforms that require this.
GLOBAL CONSTRUCTOR AND DESTRUCTOR (API WRITERS READ THIS!!!)
------------------------------------------------------------
No, it's not C++, but it's as close as we can get with K&R.
The main() of each process that uses these globals must include the
CONSTRUCTGLOBALS; statement. This will malloc enough memory for the
structure and initialize any variables that require it. This must
also be done by any API function that jumps into the middle of the
code.
The DESTROYGLOBALS(); statement should be inserted before EVERY "EXIT(n)".
Naturally, it also needs to be put before any API returns as well.
In fact, it's much more important in API functions since the process
will NOT end, and therefore the memory WON'T automatically be freed
by the operating system.
USING VARIABLES FROM THE STRUCTURE
----------------------------------
All global variables must now be prefixed with `G.' which is either a
global struct (in which case it should be the only global variable) or
a macro for the value of a local pointer variable that is passed from
function to function. Yes, this is a pain. But it's the only way to
allow full reentrancy.
ADDING VARIABLES TO THE STRUCTURE
---------------------------------
If you make the inclusion of any variables conditional, be sure to only
check macros that are GUARANTEED to be included in every module.
For instance, newzip and pwdarg are needed only if CRYPT is TRUE,
but this is defined after unzip.h has been read. If you are not careful,
some modules will expect your variable to be part of this struct while
others won't. This will cause BIG problems. (Inexplicable crashes at
strange times, car fires, etc.) When in doubt, always include it!
Note also that UnZipSFX needs a few variables that UnZip doesn't. However,
it also includes some object files from UnZip. If we were to conditionally
include the extra variables that UnZipSFX needs, the object files from
UnZip would not mesh with the UnZipSFX object files. Result: we just
include the UnZipSFX variables every time. (It's only an extra 4 bytes
so who cares!)
ADDING FUNCTIONS
----------------
To support this new global struct, all functions must now conditionally
pass the globals pointer (pG) to each other. This is supported by 5 macros:
__GPRO, __GPRO__, __G, __G__ and __GDEF. A function that needs no other
parameters would look like this:
int extract_or_test_files(__G)
__GDEF
{
... stuff ...
}
A function with other parameters would look like:
int memextract(__G__ tgt, tgtsize, src, srcsize)
__GDEF
uch *tgt, *src;
ulg tgtsize, srcsize;
{
... stuff ...
}
In the Function Prototypes section of unzpriv.h, you should use __GPRO and
__GPRO__ instead:
int uz_opts OF((__GPRO__ int *pargc, char ***pargv));
int process_zipfiles OF((__GPRO));
Note that there is NO comma after __G__ or __GPRO__ and no semi-colon after
__GDEF. I wish there was another way but I don't think there is.
TESTING THE CODE
-----------------
Whether your platform requires reentrancy or not, you should always try
building with REENTRANT defined if any functions have been added. It is
pretty easy to forget a __G__ or a __GDEF and this mistake will only show
up if REENTRANT is defined. All platforms should run with REENTRANT
defined. Platforms that can't take advantage of it will just be paying
a performance penalty needlessly.
SIGNAL MADNESS
--------------
This whole pointer passing scheme falls apart when it comes to SIGNALs.
I handle this situation 2 ways right now. If you define USETHREADID,
UnZip will include a 64-entry table. Each entry can hold a global
pointer and thread ID for one thread. This should allow up to 64
threads to access UnZip simultaneously. Calling DESTROYGLOBALS()
will free the global struct and zero the table entry. If somebody
forgets to call DESTROYGLOBALS(), this table will eventually fill up
and UnZip will exit with an error message. A good way to test your
code to make sure you didn't forget a DESTROYGLOBALS() is to change
THREADID_ENTRIES to 3 or 4 in globals.c, making the table real small.
Then make a small test program that calls your API a dozen times.
Those platforms that don't have threads still need to be able to compile
with REENTRANT defined to test and see if new code is correctly written
to work either way. For these platforms, I simply keep a global pointer
called GG that points to the Globals structure. Good enough for testing.
I believe that NT has thread level storage. This could probably be used
to store a global pointer for the sake of the signal handler more cleanly
than my table approach.
---------------------------------------------------------------------------*/
#ifndef __globals_h
#define __globals_h
#ifdef USE_ZLIB
# include "zlib.h"
#endif
/*************/
/* Globals */
/*************/
typedef struct Globals {
#ifdef DLL
zvoid *callerglobs; /* pointer to structure of pass-through global vars */
#endif
/* command options of general use */
UzpOpts UzO; /* command options of general use */
#ifndef FUNZIP
/* command options specific to the high level command line interface */
#ifdef MORE
int M_flag; /* -M: built-in "more" function */
#endif
/* internal flags and general globals */
#ifdef MORE
int height; /* check for SIGWINCH, etc., eventually... */
int lines; /* count of lines displayed on current screen */
# if (defined(SCREENWIDTH) && defined(SCREENLWRAP))
int width;
int chars; /* count of screen characters in current line */
# endif
#endif /* MORE */
#if (defined(IZ_CHECK_TZ) && defined(USE_EF_UT_TIME))
int tz_is_valid; /* indicates that timezone info can be used */
#endif
int noargs; /* did true command line have *any* arguments? */
unsigned filespecs; /* number of real file specifications to be matched */
unsigned xfilespecs; /* number of excluded filespecs to be matched */
int process_all_files;
int overwrite_mode; /* 0 - query, 1 - always, 2 - never */
int create_dirs; /* used by main(), mapname(), checkdir() */
int extract_flag;
int newzip; /* reset in extract.c; used in crypt.c */
LONGINT real_ecrec_offset;
LONGINT expect_ecrec_offset;
long csize; /* used by decompr. (NEXTBYTE): must be signed */
long used_csize; /* used by extract_or_test_member(), explode() */
#ifdef DLL
int fValidate; /* true if only validating an archive */
int filenotfound;
int redirect_data; /* redirect data to memory buffer */
int redirect_text; /* redirect text output to buffer */
# ifndef NO_SLIDE_REDIR
int redirect_slide; /* redirect decompression area to mem buffer */
# if (defined(USE_DEFLATE64) && defined(INT_16BIT))
ulg _wsize; /* size of sliding window exceeds "unsigned" range */
# else
unsigned _wsize; /* sliding window size can be hold in unsigned */
# endif
# endif
ulg redirect_size; /* size of redirected output buffer */
uch *redirect_buffer; /* pointer to head of allocated buffer */
uch *redirect_pointer; /* pointer past end of written data */
# ifndef NO_SLIDE_REDIR
uch *redirect_sldptr; /* head of decompression slide buffer */
# endif
# ifdef OS2DLL
cbList(processExternally); /* call-back list */
# endif
#endif /* DLL */
char **pfnames;
char **pxnames;
char sig[4];
char answerbuf[10];
min_info info[DIR_BLKSIZ];
min_info *pInfo;
#endif /* !FUNZIP */
union work area; /* see unzpriv.h for definition of work */
#ifndef FUNZIP
# if (!defined(USE_ZLIB) || defined(USE_OWN_CRCTAB))
ZCONST ulg near *crc_32_tab;
# else
ZCONST ulg Far *crc_32_tab;
# endif
#endif
ulg crc32val; /* CRC shift reg. (was static in funzip) */
#ifdef FUNZIP
FILE *in; /* file descriptor of compressed stream */
#endif
uch *inbuf; /* input buffer (any size is OK) */
uch *inptr; /* pointer into input buffer */
int incnt;
#ifndef FUNZIP
ulg bitbuf;
int bits_left; /* unreduce and unshrink only */
int zipeof;
char *argv0; /* used for NT and EXE_EXTENSION */
char *wildzipfn;
char *zipfn; /* GRR: WINDLL: must nuke any malloc'd zipfn... */
#ifdef USE_STRM_INPUT
FILE *zipfd; /* zipfile file descriptor */
#else
int zipfd; /* zipfile file handle */
#endif
LONGINT ziplen;
LONGINT cur_zipfile_bufstart; /* extract_or_test, readbuf, ReadByte */
LONGINT extra_bytes; /* used in unzip.c, misc.c */
uch *extra_field; /* Unix, VMS, Mac, OS/2, Acorn, ... */
uch *hold;
local_file_hdr lrec; /* used in unzip.c, extract.c */
cdir_file_hdr crec; /* used in unzip.c, extract.c, misc.c */
ecdir_rec ecrec; /* used in unzip.c, extract.c */
struct stat statbuf; /* used by main, mapname, check_for_newer */
int mem_mode;
uch *outbufptr; /* extract.c static */
ulg outsize; /* extract.c static */
int reported_backslash; /* extract.c static */
int disk_full;
int newfile;
int didCRlast; /* fileio static */
ulg numlines; /* fileio static: number of lines printed */
int sol; /* fileio static: at start of line */
int no_ecrec; /* process static */
#ifdef SYMLINKS
int symlnk;
#endif
#ifdef NOVELL_BUG_FAILSAFE
int dne; /* true if stat() says file doesn't exist */
#endif
FILE *outfile;
uch *outbuf;
uch *realbuf;
#ifndef VMS /* if SMALL_MEM, outbuf2 is initialized in */
uch *outbuf2; /* process_zipfiles() (never changes); */
#endif /* else malloc'd ONLY if unshrink and -a */
#endif /* !FUNZIP */
uch *outptr;
ulg outcnt; /* number of chars stored in outbuf */
#ifndef FUNZIP
char filename[FILNAMSIZ]; /* also used by NT for temporary SFX path */
#ifdef CMS_MVS
char *tempfn; /* temp file used; erase on close */
#endif
char *key; /* crypt static: decryption password or NULL */
int nopwd; /* crypt static */
#endif /* !FUNZIP */
ulg keys[3]; /* crypt static: keys defining pseudo-random sequence */
#if (!defined(DOS_FLX_H68_NLM_OS2_W32) && !defined(AMIGA) && !defined(RISCOS))
#if (!defined(MACOS) && !defined(ATARI) && !defined(VMS))
int echofd; /* ttyio static: file descriptor whose echo is off */
#endif /* !(MACOS || ATARI || VMS) */
#endif /* !(DOS_FLX_H68_NLM_OS2_W32 || AMIGA || RISCOS) */
unsigned hufts; /* track memory usage */
#ifdef USE_ZLIB
int inflInit; /* inflate static: zlib inflate() initialized */
z_stream dstrm; /* inflate global: decompression stream */
#else
struct huft *fixed_tl; /* inflate static */
struct huft *fixed_td; /* inflate static */
int fixed_bl, fixed_bd; /* inflate static */
#ifdef USE_DEFLATE64
struct huft *fixed_tl64; /* inflate static */
struct huft *fixed_td64; /* inflate static */
int fixed_bl64, fixed_bd64; /* inflate static */
struct huft *fixed_tl32; /* inflate static */
struct huft *fixed_td32; /* inflate static */
int fixed_bl32, fixed_bd32; /* inflate static */
ZCONST ush *cplens; /* inflate static */
ZCONST uch *cplext; /* inflate static */
ZCONST uch *cpdext; /* inflate static */
#endif
unsigned wp; /* inflate static: current position in slide */
ulg bb; /* inflate static: bit buffer */
unsigned bk; /* inflate static: bits in bit buffer */
#endif /* ?USE_ZLIB */
#ifndef FUNZIP
#ifdef SMALL_MEM
char rgchBigBuffer[512];
char rgchSmallBuffer[96];
char rgchSmallBuffer2[160]; /* boosted to 160 for local3[] in unzip.c */
#endif
MsgFn *message;
InputFn *input;
PauseFn *mpause;
PasswdFn *decr_passwd;
StatCBFn *statreportcb;
#ifdef WINDLL
LPUSERFUNCTIONS lpUserFunctions;
#endif
int incnt_leftover; /* so improved NEXTBYTE does not waste input */
uch *inptr_leftover;
#ifdef VMS_TEXT_CONV
unsigned VMS_line_length; /* so native VMS variable-length text files */
int VMS_line_state; /* are readable on other platforms */
int VMS_line_pad;
#endif
#if (defined(SFX) && defined(CHEAP_SFX_AUTORUN))
char autorun_command[FILNAMSIZ];
#endif
#endif /* !FUNZIP */
#ifdef SYSTEM_SPECIFIC_GLOBALS
SYSTEM_SPECIFIC_GLOBALS
#endif
} Uz_Globs; /* end of struct Globals */
/***************************************************************************/
#ifdef FUNZIP
# if (!defined(USE_ZLIB) || defined(USE_OWN_CRCTAB))
extern ZCONST ulg near crc_32_tab[256];
# else
extern ZCONST ulg Far *crc_32_tab;
# endif
# define CRC_32_TAB crc_32_tab
#else
# define CRC_32_TAB G.crc_32_tab
#endif
Uz_Globs *globalsCtor OF((void));
/* pseudo constant sigs; they are initialized at runtime so unzip executable
* won't look like a zipfile
*/
extern char local_hdr_sig[4];
extern char central_hdr_sig[4];
extern char end_central_sig[4];
/* extern char extd_local_sig[4]; NOT USED YET */
#ifdef REENTRANT
# define G (*(Uz_Globs *)pG)
# define __G pG
# define __G__ pG,
# define __GPRO Uz_Globs *pG
# define __GPRO__ Uz_Globs *pG,
# define __GDEF Uz_Globs *pG;
# ifdef USETHREADID
extern int lastScan;
void deregisterGlobalPointer OF((__GPRO));
Uz_Globs *getGlobalPointer OF((void));
# define GETGLOBALS() Uz_Globs *pG = getGlobalPointer()
# define DESTROYGLOBALS() do {free_G_buffers(pG); \
deregisterGlobalPointer(pG);} while (0)
# else
extern Uz_Globs *GG;
# define GETGLOBALS() Uz_Globs *pG = GG
# define DESTROYGLOBALS() do {free_G_buffers(pG); free(pG);} while (0)
# endif /* ?USETHREADID */
# define CONSTRUCTGLOBALS() Uz_Globs *pG = globalsCtor()
#else /* !REENTRANT */
extern Uz_Globs G;
# define __G
# define __G__
# define __GPRO void
# define __GPRO__
# define __GDEF
# define GETGLOBALS()
# define CONSTRUCTGLOBALS() globalsCtor()
# define DESTROYGLOBALS()
#endif /* ?REENTRANT */
#define uO G.UzO
#endif /* __globals_h */

1499
src/apps/bin/unzip/inflate.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,39 @@
/*
Copyright (c) 1990-2000 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
*/
/* inflate.h for UnZip -- by Mark Adler
version c14f, 23 November 1995 */
/* Copyright history:
- Starting with UnZip 5.41 of 16-April-2000, this source file
is covered by the Info-Zip LICENSE cited above.
- Prior versions of this source file, found in UnZip source packages
up to UnZip 5.40, were put in the public domain.
The original copyright note by Mark Adler was:
"You can do whatever you like with this source file,
though I would prefer that if you modify it and
redistribute it that you include comments to that effect
with your name and the date. Thank you."
History:
vers date who what
---- --------- -------------- ------------------------------------
c14 12 Mar 93 M. Adler made inflate.c standalone with the
introduction of inflate.h.
c14d 28 Aug 93 G. Roelofs replaced flush/FlushOutput with new version
c14e 29 Sep 93 G. Roelofs moved everything into unzip.h; added crypt.h
c14f 23 Nov 95 G. Roelofs added UNZIP_INTERNAL to accommodate newly
split unzip.h
*/
#define UNZIP_INTERNAL
#include "unzip.h" /* provides slide[], typedefs and macros */
#ifdef FUNZIP
# include "crypt.h" /* provides NEXTBYTE macro for crypt version of funzip */
#endif

671
src/apps/bin/unzip/list.c Normal file
View File

@ -0,0 +1,671 @@
/*
Copyright (c) 1990-2001 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
*/
/*---------------------------------------------------------------------------
list.c
This file contains the non-ZipInfo-specific listing routines for UnZip.
Contains: list_files()
get_time_stamp() [optional feature]
ratio()
fnprint()
---------------------------------------------------------------------------*/
#define UNZIP_INTERNAL
#include "unzip.h"
#ifdef WINDLL
# ifdef POCKET_UNZIP
# include "wince/intrface.h"
# else
# include "windll/windll.h"
# endif
#endif
#ifdef TIMESTAMP
static int fn_is_dir OF((__GPRO));
#endif
#ifndef WINDLL
static ZCONST char Far CompFactorStr[] = "%c%d%%";
static ZCONST char Far CompFactor100[] = "100%%";
#ifdef OS2_EAS
static ZCONST char Far HeadersS[] =
" Length EAs ACLs Date Time Name";
static ZCONST char Far HeadersS1[] =
" -------- --- ---- ---- ---- ----";
#else
static ZCONST char Far HeadersS[] = " Length Date Time Name";
static ZCONST char Far HeadersS1[] = " -------- ---- ---- ----";
#endif
static ZCONST char Far HeadersL[] =
" Length Method Size Ratio Date Time CRC-32 Name";
static ZCONST char Far HeadersL1[] =
"-------- ------ ------- ----- ---- ---- ------ ----";
static ZCONST char Far *Headers[][2] =
{ {HeadersS, HeadersS1}, {HeadersL, HeadersL1} };
static ZCONST char Far CaseConversion[] =
"%s (\"^\" ==> case\n%s conversion)\n";
static ZCONST char Far LongHdrStats[] =
"%8lu %-7s%8lu %4s %02u-%02u-%02u %02u:%02u %08lx %c";
static ZCONST char Far LongFileTrailer[] =
"-------- ------- --- \
-------\n%8lu %8lu %4s %lu file%s\n";
#ifdef OS2_EAS
static ZCONST char Far ShortHdrStats[] =
"%9lu %6lu %6lu %02u-%02u-%02u %02u:%02u %c";
static ZCONST char Far ShortFileTrailer[] = " -------- ----- ----- \
-------\n%9lu %6lu %6lu %lu file%s\n";
static ZCONST char Far OS2ExtAttrTrailer[] =
"%lu file%s %lu bytes of OS/2 extended attributes attached.\n";
static ZCONST char Far OS2ACLTrailer[] =
"%lu file%s %lu bytes of access control lists attached.\n";
#else
static ZCONST char Far ShortHdrStats[] =
"%9lu %02u-%02u-%02u %02u:%02u %c";
static ZCONST char Far ShortFileTrailer[] = " -------- \
-------\n%9lu %lu file%s\n";
#endif /* ?OS2_EAS */
#endif /* !WINDLL */
/*************************/
/* Function list_files() */
/*************************/
int list_files(__G) /* return PK-type error code */
__GDEF
{
int do_this_file=FALSE, cfactor, error, error_in_archive=PK_COOL;
#ifndef WINDLL
char sgn, cfactorstr[10];
int longhdr=(uO.vflag>1);
#endif
int date_format;
ulg j, members=0L;
unsigned methnum;
#ifdef USE_EF_UT_TIME
iztimes z_utime;
struct tm *t;
#endif
unsigned yr, mo, dy, hh, mm;
ulg csiz, tot_csize=0L, tot_ucsize=0L;
#ifdef OS2_EAS
ulg ea_size, tot_easize=0L, tot_eafiles=0L;
ulg acl_size, tot_aclsize=0L, tot_aclfiles=0L;
#endif
min_info info;
char methbuf[8];
static ZCONST char dtype[]="NXFS"; /* see zi_short() */
static ZCONST char Far method[NUM_METHODS+1][8] =
{"Stored", "Shrunk", "Reduce1", "Reduce2", "Reduce3", "Reduce4",
"Implode", "Token", "Defl:#", "Def64#", "ImplDCL", "Unk:###"};
/*---------------------------------------------------------------------------
Unlike extract_or_test_files(), this routine confines itself to the cen-
tral directory. Thus its structure is somewhat simpler, since we can do
just a single loop through the entire directory, listing files as we go.
So to start off, print the heading line and then begin main loop through
the central directory. The results will look vaguely like the following:
Length Method Size Ratio Date Time CRC-32 Name ("^" ==> case
-------- ------ ------- ----- ---- ---- ------ ---- conversion)
44004 Implode 13041 71% 11-02-89 19:34 8b4207f7 Makefile.UNIX
3438 Shrunk 2209 36% 09-15-90 14:07 a2394fd8 ^dos-file.ext
16717 Defl:X 5252 69% 11-03-97 06:40 1ce0f189 WHERE
-------- ------- --- -------
64159 20502 68% 3 files
---------------------------------------------------------------------------*/
G.pInfo = &info;
date_format = DATE_FORMAT;
#ifndef WINDLL
if (uO.qflag < 2) {
if (uO.L_flag)
Info(slide, 0, ((char *)slide, LoadFarString(CaseConversion),
LoadFarStringSmall(Headers[longhdr][0]),
LoadFarStringSmall2(Headers[longhdr][1])));
else
Info(slide, 0, ((char *)slide, "%s\n%s\n",
LoadFarString(Headers[longhdr][0]),
LoadFarStringSmall(Headers[longhdr][1])));
}
#endif /* !WINDLL */
for (j = 1L;;j++) {
if (readbuf(__G__ G.sig, 4) == 0)
return PK_EOF;
if (strncmp(G.sig, central_hdr_sig, 4)) { /* is it a CentDir entry? */
if (((unsigned)(j - 1) & (unsigned)0xFFFF) ==
(unsigned)G.ecrec.total_entries_central_dir) {
/* "j modulus 64k" matches the reported 16-bit-unsigned
* number of directory entries -> probably, the regular
* end of the central directory has been reached
*/
break;
} else {
Info(slide, 0x401,
((char *)slide, LoadFarString(CentSigMsg), j));
Info(slide, 0x401,
((char *)slide, LoadFarString(ReportMsg)));
return PK_BADERR; /* sig not found */
}
}
/* process_cdir_file_hdr() sets pInfo->hostnum, pInfo->lcflag, ...: */
if ((error = process_cdir_file_hdr(__G)) != PK_COOL)
return error; /* only PK_EOF defined */
/*
* We could DISPLAY the filename instead of storing (and possibly trun-
* cating, in the case of a very long name) and printing it, but that
* has the disadvantage of not allowing case conversion--and it's nice
* to be able to see in the listing precisely how you have to type each
* filename in order for unzip to consider it a match. Speaking of
* which, if member names were specified on the command line, check in
* with match() to see if the current file is one of them, and make a
* note of it if it is.
*/
if ((error = do_string(__G__ G.crec.filename_length, DS_FN)) !=
PK_COOL) /* ^--(uses pInfo->lcflag) */
{
error_in_archive = error;
if (error > PK_WARN) /* fatal: can't continue */
return error;
}
if (G.extra_field != (uch *)NULL) {
free(G.extra_field);
G.extra_field = (uch *)NULL;
}
if ((error = do_string(__G__ G.crec.extra_field_length, EXTRA_FIELD))
!= 0)
{
error_in_archive = error;
if (error > PK_WARN) /* fatal */
return error;
}
if (!G.process_all_files) { /* check if specified on command line */
unsigned i;
do_this_file = FALSE;
for (i = 0; i < G.filespecs; i++)
if (match(G.filename, G.pfnames[i], uO.C_flag)) {
do_this_file = TRUE;
break; /* found match, so stop looping */
}
if (do_this_file) { /* check if this is an excluded file */
for (i = 0; i < G.xfilespecs; i++)
if (match(G.filename, G.pxnames[i], uO.C_flag)) {
do_this_file = FALSE; /* ^-- ignore case in match */
break;
}
}
}
/*
* If current file was specified on command line, or if no names were
* specified, do the listing for this file. Otherwise, get rid of the
* file comment and go back for the next file.
*/
if (G.process_all_files || do_this_file) {
#ifdef OS2DLL
/* this is used by UzpFileTree() to allow easy processing of lists
* of zip directory contents */
if (G.processExternally) {
if ((G.processExternally)(G.filename, &G.crec))
break;
++members;
} else {
#endif
#ifdef OS2_EAS
{
uch *ef_ptr = G.extra_field;
int ef_size, ef_len = G.crec.extra_field_length;
ea_size = acl_size = 0;
while (ef_len >= EB_HEADSIZE) {
ef_size = makeword(&ef_ptr[EB_LEN]);
switch (makeword(&ef_ptr[EB_ID])) {
case EF_OS2:
ea_size = makelong(&ef_ptr[EB_HEADSIZE]);
break;
case EF_ACL:
acl_size = makelong(&ef_ptr[EB_HEADSIZE]);
break;
}
ef_ptr += (ef_size + EB_HEADSIZE);
ef_len -= (ef_size + EB_HEADSIZE);
}
}
#endif
#ifdef USE_EF_UT_TIME
if (G.extra_field &&
#ifdef IZ_CHECK_TZ
G.tz_is_valid &&
#endif
(ef_scan_for_izux(G.extra_field, G.crec.extra_field_length, 1,
G.crec.last_mod_dos_datetime, &z_utime, NULL)
& EB_UT_FL_MTIME))
{
TIMET_TO_NATIVE(z_utime.mtime) /* NOP unless MSC 7.0, Mac */
t = localtime(&(z_utime.mtime));
} else
t = (struct tm *)NULL;
if (t != (struct tm *)NULL) {
mo = (unsigned)(t->tm_mon + 1);
dy = (unsigned)(t->tm_mday);
yr = (unsigned)(t->tm_year % 100);
hh = (unsigned)(t->tm_hour);
mm = (unsigned)(t->tm_min);
} else
#endif /* USE_EF_UT_TIME */
{
yr = ((((unsigned)(G.crec.last_mod_dos_datetime >> 25) & 0x7f)
+ 80) % (unsigned)100);
mo = ((unsigned)(G.crec.last_mod_dos_datetime >> 21) & 0x0f);
dy = ((unsigned)(G.crec.last_mod_dos_datetime >> 16) & 0x1f);
hh = (((unsigned)G.crec.last_mod_dos_datetime >> 11) & 0x1f);
mm = (((unsigned)G.crec.last_mod_dos_datetime >> 5) & 0x3f);
}
/* permute date so it displays according to nat'l convention
* ('methnum' is not yet set, it is used as temporary buffer) */
switch (date_format) {
case DF_YMD:
methnum = mo;
mo = yr; yr = dy; dy = methnum;
break;
case DF_DMY:
methnum = mo;
mo = dy; dy = methnum;
}
csiz = G.crec.csize;
if (G.crec.general_purpose_bit_flag & 1)
csiz -= 12; /* if encrypted, don't count encryption header */
if ((cfactor = ratio(G.crec.ucsize, csiz)) < 0) {
#ifndef WINDLL
sgn = '-';
#endif
cfactor = (-cfactor + 5) / 10;
} else {
#ifndef WINDLL
sgn = ' ';
#endif
cfactor = (cfactor + 5) / 10;
}
methnum = MIN(G.crec.compression_method, NUM_METHODS);
zfstrcpy(methbuf, method[methnum]);
if (methnum == DEFLATED || methnum == ENHDEFLATED) {
methbuf[5] = dtype[(G.crec.general_purpose_bit_flag>>1) & 3];
} else if (methnum >= NUM_METHODS) {
sprintf(&methbuf[4], "%03u", G.crec.compression_method);
}
#if 0 /* GRR/Euro: add this? */
#if defined(DOS_FLX_NLM_OS2_W32) || defined(THEOS) || defined(UNIX)
for (p = G.filename; *p; ++p)
if (!isprint(*p))
*p = '?'; /* change non-printable chars to '?' */
#endif /* DOS_FLX_NLM_OS2_W32 || THEOS || UNIX */
#endif /* 0 */
#ifdef WINDLL
/* send data to application for formatting and printing */
(*G.lpUserFunctions->SendApplicationMessage)(G.crec.ucsize, csiz,
(unsigned)cfactor, mo, dy, yr, hh, mm,
(char)(G.pInfo->lcflag ? '^' : ' '),
(LPSTR)fnfilter(G.filename, slide), (LPSTR)methbuf, G.crec.crc32,
(char)((G.crec.general_purpose_bit_flag & 1) ? 'E' : ' '));
#else /* !WINDLL */
if (cfactor == 100)
sprintf(cfactorstr, LoadFarString(CompFactor100));
else
sprintf(cfactorstr, LoadFarString(CompFactorStr), sgn, cfactor);
if (longhdr)
Info(slide, 0, ((char *)slide, LoadFarString(LongHdrStats),
G.crec.ucsize, methbuf, csiz, cfactorstr, mo, dy,
yr, hh, mm, G.crec.crc32, (G.pInfo->lcflag? '^':' ')));
else
#ifdef OS2_EAS
Info(slide, 0, ((char *)slide, LoadFarString(ShortHdrStats),
G.crec.ucsize, ea_size, acl_size,
mo, dy, yr, hh, mm, (G.pInfo->lcflag? '^':' ')));
#else
Info(slide, 0, ((char *)slide, LoadFarString(ShortHdrStats),
G.crec.ucsize,
mo, dy, yr, hh, mm, (G.pInfo->lcflag? '^':' ')));
#endif
fnprint(__G);
#endif /* ?WINDLL */
if ((error = do_string(__G__ G.crec.file_comment_length,
QCOND? DISPL_8 : SKIP)) != 0)
{
error_in_archive = error; /* might be just warning */
if (error > PK_WARN) /* fatal */
return error;
}
tot_ucsize += G.crec.ucsize;
tot_csize += csiz;
++members;
#ifdef OS2_EAS
if (ea_size) {
tot_easize += ea_size;
++tot_eafiles;
}
if (acl_size) {
tot_aclsize += acl_size;
++tot_aclfiles;
}
#endif
#ifdef OS2DLL
} /* end of "if (G.processExternally) {...} else {..." */
#endif
} else { /* not listing this file */
SKIP_(G.crec.file_comment_length)
}
} /* end for-loop (j: files in central directory) */
/*---------------------------------------------------------------------------
Print footer line and totals (compressed size, uncompressed size, number
of members in zipfile).
---------------------------------------------------------------------------*/
if (uO.qflag < 2
#ifdef OS2DLL
&& !G.processExternally
#endif
) {
if ((cfactor = ratio(tot_ucsize, tot_csize)) < 0) {
#ifndef WINDLL
sgn = '-';
#endif
cfactor = (-cfactor + 5) / 10;
} else {
#ifndef WINDLL
sgn = ' ';
#endif
cfactor = (cfactor + 5) / 10;
}
#ifdef WINDLL
/* pass the totals back to the calling application */
G.lpUserFunctions->TotalSizeComp = tot_csize;
G.lpUserFunctions->TotalSize = tot_ucsize;
G.lpUserFunctions->CompFactor = (ulg)cfactor;
G.lpUserFunctions->NumMembers = members;
#else /* !WINDLL */
if (cfactor == 100)
sprintf(cfactorstr, LoadFarString(CompFactor100));
else
sprintf(cfactorstr, LoadFarString(CompFactorStr), sgn, cfactor);
if (longhdr) {
Info(slide, 0, ((char *)slide, LoadFarString(LongFileTrailer),
tot_ucsize, tot_csize, cfactorstr, members, members==1? "":"s"));
#ifdef OS2_EAS
if (tot_easize || tot_aclsize)
Info(slide, 0, ((char *)slide, "\n"));
if (tot_eafiles && tot_easize)
Info(slide, 0, ((char *)slide, LoadFarString(OS2ExtAttrTrailer),
tot_eafiles, tot_eafiles == 1? " has" : "s have a total of",
tot_easize));
if (tot_aclfiles && tot_aclsize)
Info(slide, 0, ((char *)slide, LoadFarString(OS2ACLTrailer),
tot_aclfiles, tot_aclfiles == 1? " has" : "s have a total of",
tot_aclsize));
#endif /* OS2_EAS */
} else
#ifdef OS2_EAS
Info(slide, 0, ((char *)slide, LoadFarString(ShortFileTrailer),
tot_ucsize, tot_easize, tot_aclsize, members, members == 1?
"" : "s"));
#else
Info(slide, 0, ((char *)slide, LoadFarString(ShortFileTrailer),
tot_ucsize, members, members == 1? "" : "s"));
#endif /* OS2_EAS */
#endif /* ?WINDLL */
}
/*---------------------------------------------------------------------------
Double check that we're back at the end-of-central-directory record.
---------------------------------------------------------------------------*/
if (strncmp(G.sig, end_central_sig, 4)) { /* just to make sure again */
Info(slide, 0x401, ((char *)slide, LoadFarString(EndSigMsg)));
error_in_archive = PK_WARN; /* didn't find sig */
}
if (members == 0L && error_in_archive <= PK_WARN)
error_in_archive = PK_FIND;
return error_in_archive;
} /* end function list_files() */
#ifdef TIMESTAMP
/************************/
/* Function fn_is_dir() */
/************************/
static int fn_is_dir(__G) /* returns TRUE if G.filename is directory */
__GDEF
{
extent fn_len = strlen(G.filename);
register char endc;
return fn_len > 0 &&
((endc = lastchar(G.filename, fn_len)) == '/' ||
(G.pInfo->hostnum == FS_FAT_ && !MBSCHR(G.filename, '/') &&
endc == '\\'));
}
/*****************************/
/* Function get_time_stamp() */
/*****************************/
int get_time_stamp(__G__ last_modtime, nmember) /* return PK-type error code */
__GDEF
time_t *last_modtime;
ulg *nmember;
{
int do_this_file=FALSE, error, error_in_archive=PK_COOL;
ulg j;
#ifdef USE_EF_UT_TIME
iztimes z_utime;
#endif
min_info info;
/*---------------------------------------------------------------------------
Unlike extract_or_test_files() but like list_files(), this function works
on information in the central directory alone. Thus we have a single,
large loop through the entire directory, searching for the latest time
stamp.
---------------------------------------------------------------------------*/
*last_modtime = 0L; /* assuming no zipfile data older than 1970 */
*nmember = 0L;
G.pInfo = &info;
for (j = 1L;; j++) {
if (readbuf(__G__ G.sig, 4) == 0)
return PK_EOF;
if (strncmp(G.sig, central_hdr_sig, 4)) { /* is it a CentDir entry? */
if (((unsigned)(j - 1) & (unsigned)0xFFFF) ==
(unsigned)G.ecrec.total_entries_central_dir) {
/* "j modulus 64k" matches the reported 16-bit-unsigned
* number of directory entries -> probably, the regular
* end of the central directory has been reached
*/
break;
} else {
Info(slide, 0x401,
((char *)slide, LoadFarString(CentSigMsg), j));
Info(slide, 0x401,
((char *)slide, LoadFarString(ReportMsg)));
return PK_BADERR; /* sig not found */
}
}
/* process_cdir_file_hdr() sets pInfo->lcflag: */
if ((error = process_cdir_file_hdr(__G)) != PK_COOL)
return error; /* only PK_EOF defined */
if ((error = do_string(__G__ G.crec.filename_length, DS_FN)) != PK_OK)
{ /* ^-- (uses pInfo->lcflag) */
error_in_archive = error;
if (error > PK_WARN) /* fatal: can't continue */
return error;
}
if (G.extra_field != (uch *)NULL) {
free(G.extra_field);
G.extra_field = (uch *)NULL;
}
if ((error = do_string(__G__ G.crec.extra_field_length, EXTRA_FIELD))
!= 0)
{
error_in_archive = error;
if (error > PK_WARN) /* fatal */
return error;
}
if (!G.process_all_files) { /* check if specified on command line */
unsigned i;
do_this_file = FALSE;
for (i = 0; i < G.filespecs; i++)
if (match(G.filename, G.pfnames[i], uO.C_flag)) {
do_this_file = TRUE;
break; /* found match, so stop looping */
}
if (do_this_file) { /* check if this is an excluded file */
for (i = 0; i < G.xfilespecs; i++)
if (match(G.filename, G.pxnames[i], uO.C_flag)) {
do_this_file = FALSE; /* ^-- ignore case in match */
break;
}
}
}
/* If current file was specified on command line, or if no names were
* specified, check the time for this file. Either way, get rid of the
* file comment and go back for the next file.
* Directory entries are always ignored, to stay compatible with both
* Zip and PKZIP.
*/
if ((G.process_all_files || do_this_file) && !fn_is_dir(__G)) {
#ifdef USE_EF_UT_TIME
if (G.extra_field &&
#ifdef IZ_CHECK_TZ
G.tz_is_valid &&
#endif
(ef_scan_for_izux(G.extra_field, G.crec.extra_field_length, 1,
G.crec.last_mod_dos_datetime, &z_utime, NULL)
& EB_UT_FL_MTIME))
{
if (*last_modtime < z_utime.mtime)
*last_modtime = z_utime.mtime;
} else
#endif /* USE_EF_UT_TIME */
{
time_t modtime = dos_to_unix_time(G.crec.last_mod_dos_datetime);
if (*last_modtime < modtime)
*last_modtime = modtime;
}
++*nmember;
}
SKIP_(G.crec.file_comment_length)
} /* end for-loop (j: files in central directory) */
/*---------------------------------------------------------------------------
Double check that we're back at the end-of-central-directory record.
---------------------------------------------------------------------------*/
if (strncmp(G.sig, end_central_sig, 4)) { /* just to make sure again */
Info(slide, 0x401, ((char *)slide, LoadFarString(EndSigMsg)));
error_in_archive = PK_WARN;
}
if (*nmember == 0L && error_in_archive <= PK_WARN)
error_in_archive = PK_FIND;
return error_in_archive;
} /* end function get_time_stamp() */
#endif /* TIMESTAMP */
/********************/
/* Function ratio() */ /* also used by ZipInfo routines */
/********************/
int ratio(uc, c)
ulg uc, c;
{
ulg denom;
if (uc == 0)
return 0;
if (uc > 2000000L) { /* risk signed overflow if multiply numerator */
denom = uc / 1000L;
return ((uc >= c) ?
(int) ((uc-c + (denom>>1)) / denom) :
-((int) ((c-uc + (denom>>1)) / denom)));
} else { /* ^^^^^^^^ rounding */
denom = uc;
return ((uc >= c) ?
(int) ((1000L*(uc-c) + (denom>>1)) / denom) :
-((int) ((1000L*(c-uc) + (denom>>1)) / denom)));
} /* ^^^^^^^^ rounding */
}
/************************/
/* Function fnprint() */ /* also used by ZipInfo routines */
/************************/
void fnprint(__G) /* print filename (after filtering) and newline */
__GDEF
{
char *name = fnfilter(G.filename, slide);
(*G.message)((zvoid *)&G, (uch *)name, (ulg)strlen(name), 0);
(*G.message)((zvoid *)&G, (uch *)"\n", 1L, 0);
} /* end function fnprint() */

View File

@ -0,0 +1,14 @@
Contents of the "man" subdirectory for UnZip 5.41 and later:
Contents this file
funzip.1 fUnZip manual page, nroff format
unzip.1 UnZip manual page, nroff format
unzipsfx.1 UnZipSFX manual page, nroff format
zipgrep.1 ZipGrep manual page, nroff format
zipinfo.1 ZipInfo manual page, nroff format
This subdirectory contains the master source files for the UnZip user
documentation. Although these documents are Unix man-page sources, they
are of general interest and therefore stored separately.
Some non-Unix systems may supply a man-page reader where they could be
used; and they are the sources for the generic ASCII text document files.

View File

@ -0,0 +1,127 @@
.\" Copyright (c) 1990-2002 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
.\"
.\" funzip.1 by Greg Roelofs and others.
.\"
.\" =========================================================================
.\" define .EX/.EE (for multiline user-command examples; normal Courier font)
.de EX
.in +4n
.nf
.ft CW
..
.de EE
.ft R
.fi
.in -4n
..
.\" =========================================================================
.TH FUNZIP 1L "17 February 2002 (v3.94)" "Info-ZIP"
.SH NAME
funzip \- filter for extracting from a ZIP archive in a pipe
.PD
.SH SYNOPSIS
\fBfunzip\fP [\fB\-password\fP] [\fIinput[.zip|.gz]\fP]
.\" =========================================================================
.SH ARGUMENTS
.IP [\fI\-password\fP]
Optional password to be used if ZIP archive is encrypted. Decryption
may not be supported at some sites. See DESCRIPTION for more details.
.IP [\fIinput[.zip|.gz]\fP]
Optional input archive file specification. See DESCRIPTION for details.
.PD
.\" =========================================================================
.SH DESCRIPTION
.I funzip
without a file argument acts as a filter; that is, it assumes that a
ZIP archive (or a \fIgzip\fP'd(1) file) is being piped into
standard input, and it extracts the first member from the archive to stdout.
When stdin comes from a tty device,
.I funzip
assumes that this cannot be a stream of (binary) compressed data and
shows a short help text, instead.
If there is a file argument, then input is read from the specified file
instead of from stdin.
.PP
A password for encrypted zip files can be specified
on the command line (preceding the file name, if any) by prefixing the
password with a dash. Note that this constitutes a security risk on many
systems; currently running processes are often visible via simple commands
(e.g., \fIps\fP(1) under Unix), and command-line histories can be read.
If the first entry of the zip file is encrypted and
no password is specified on the command line, then the user is prompted for
a password and the password is not echoed on the console.
.PP
Given the limitation on single-member extraction, \fIfunzip\fP is most
useful in conjunction with a secondary archiver program such as \fItar\fP(1).
The following section includes an example illustrating this usage in the
case of disk backups to tape.
.PD
.\" =========================================================================
.SH EXAMPLES
To use \fIfunzip\fP to extract the first member file of the archive test.zip
and to pipe it into \fImore\fP(1):
.PP
.EX
funzip test.zip | more
.EE
.PP
To use \fIfunzip\fP to test the first member file of test.zip (any errors
will be reported on standard error):
.PP
.EX
funzip test.zip > /dev/null
.EE
.PP
To use \fIzip\fP and \fIfunzip\fP in place of \fIcompress\fP(1) and
\fIzcat\fP(1) (or \fIgzip\fP(1L) and \fIgzcat\fP(1L)) for tape backups:
.PP
.EX
tar cf \- . | zip \-7 | dd of=/dev/nrst0 obs=8k
dd if=/dev/nrst0 ibs=8k | funzip | tar xf \-
.EE
.PP
(where, for example, nrst0 is a SCSI tape drive).
.PD
.\" =========================================================================
.SH BUGS
When piping an encrypted file into \fImore\fP and allowing \fIfunzip\fP
to prompt for password, the terminal may sometimes be reset to a non-echo
mode. This is apparently due to a race condition between the two programs;
\fIfunzip\fP changes the terminal mode to non-echo before \fImore\fP reads
its state, and \fImore\fP then ``restores'' the terminal to this mode before
exiting. To recover, run \fIfunzip\fP on the same file but redirect to
/dev/null rather than piping into more; after prompting again for the
password, \fIfunzip\fP will reset the terminal properly.
.PP
There is presently no way to extract any member but the first from a ZIP
archive. This would be useful in the case where a ZIP archive is included
within another archive. In the case where the first member is a directory,
\fIfunzip\fP simply creates the directory and exits.
.PP
The functionality of \fIfunzip\fP should be incorporated into \fIunzip\fP
itself (future release).
.PD
.\" =========================================================================
.SH "SEE ALSO"
\fIgzip\fP(1L), \fIunzip\fP(1L), \fIunzipsfx\fP(1L), \fIzip\fP(1L),
\fIzipcloak\fP(1L), \fIzipinfo\fP(1L), \fIzipnote\fP(1L), \fIzipsplit\fP(1L)
.PD
.\" =========================================================================
.SH URL
The Info-ZIP home page is currently at
.EX
\fChttp://www.info-zip.org/pub/infozip/\fR
.EE
or
.EX
\fCftp://ftp.info-zip.org/pub/infozip/\fR .
.EE
.PD
.\" =========================================================================
.SH AUTHOR
Mark Adler (Info-ZIP)

View File

@ -0,0 +1,865 @@
.\" Copyright (c) 1990-2002 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
.\"
.\" unzip.1 by Greg Roelofs, Fulvio Marino, Jim van Zandt and others.
.\"
.\" =========================================================================
.\" define .EX/.EE (for multiline user-command examples; normal Courier font)
.de EX
.in +4n
.nf
.ft CW
..
.de EE
.ft R
.fi
.in -4n
..
.\" =========================================================================
.TH UNZIP 1L "17 February 2002 (v5.5)" "Info-ZIP"
.SH NAME
unzip \- list, test and extract compressed files in a ZIP archive
.PD
.SH SYNOPSIS
\fBunzip\fP [\fB\-Z\fP] [\fB\-cflptuvz\fP[\fBabjnoqsCLMVX$/:\fP]]
\fIfile\fP[\fI.zip\fP] [\fIfile(s)\fP\ .\|.\|.]
[\fB\-x\fP\ \fIxfile(s)\fP\ .\|.\|.] [\fB\-d\fP\ \fIexdir\fP]
.PD
.\" =========================================================================
.SH DESCRIPTION
\fIunzip\fP will list, test, or extract files from a ZIP archive, commonly
found on MS-DOS systems. The default behavior (with no options) is to extract
into the current directory (and subdirectories below it) all files from the
specified ZIP archive. A companion program, \fIzip\fP(1L), creates ZIP
archives; both programs are compatible with archives created by PKWARE's
\fIPKZIP\fP and \fIPKUNZIP\fP for MS-DOS, but in many cases the program
options or default behaviors differ.
.PD
.\" =========================================================================
.SH ARGUMENTS
.TP
.IR file [ .zip ]
Path of the ZIP archive(s). If the file specification is a wildcard,
each matching file is processed in an order determined by the operating
system (or file system). Only the filename can be a wildcard; the path
itself cannot. Wildcard expressions are similar to those supported in
commonly used Unix shells (\fIsh\fP, \fIksh\fP, \fIcsh\fP) and may contain:
.RS
.IP *
matches a sequence of 0 or more characters
.IP ?
matches exactly 1 character
.IP [.\|.\|.]
matches any single character found inside the brackets; ranges are specified
by a beginning character, a hyphen, and an ending character. If an exclamation
point or a caret (`!' or `^') follows the left bracket, then the range of
characters within the brackets is complemented (that is, anything \fIexcept\fP
the characters inside the brackets is considered a match).
.RE
.IP
(Be sure to quote any character that might otherwise be interpreted or
modified by the operating system, particularly under Unix and VMS.) If no
matches are found, the specification is assumed to be a literal filename;
and if that also fails, the suffix \fC.zip\fR is appended. Note that
self-extracting ZIP files are supported, as with any other ZIP archive;
just specify the \fC.exe\fR suffix (if any) explicitly.
.IP [\fIfile(s)\fP]
An optional list of archive members to be processed, separated by spaces.
(VMS versions compiled with VMSCLI defined must delimit files with commas
instead. See \fB\-v\fP in \fBOPTIONS\fP below.)
Regular expressions (wildcards) may be used to match multiple members; see
above. Again, be sure to quote expressions that would otherwise be expanded
or modified by the operating system.
.IP [\fB\-x\fP\ \fIxfile(s)\fP]
An optional list of archive members to be excluded from processing.
Since wildcard characters match directory separators (`/'), this option
may be used to exclude any files that are in subdirectories. For
example, ``\fCunzip foo *.[ch] -x */*\fR'' would extract all C source files
in the main directory, but none in any subdirectories. Without the \fB\-x\fP
option, all C source files in all directories within the zipfile would be
extracted.
.IP [\fB\-d\fP\ \fIexdir\fP]
An optional directory to which to extract files. By default, all files
and subdirectories are recreated in the current directory; the \fB\-d\fP
option allows extraction in an arbitrary directory (always assuming one
has permission to write to the directory). This option need not appear
at the end of the command line; it is also accepted before the zipfile
specification (with the normal options), immediately after the zipfile
specification, or between the \fIfile(s)\fP and the \fB\-x\fP option.
The option and directory may be concatenated without any white space
between them, but note that this may cause normal shell behavior to be
suppressed. In particular, ``\fC\-d\ ~\fR'' (tilde) is expanded by Unix
C shells into the name of the user's home directory, but ``\fC\-d~\fR''
is treated as a literal subdirectory ``\fB~\fP'' of the current directory.
.\" =========================================================================
.SH OPTIONS
Note that, in order to support obsolescent hardware, \fIunzip\fP's usage
screen is limited to 22 or 23 lines and should therefore be considered
only a reminder of the basic \fIunzip\fP syntax rather than an exhaustive
list of all possible flags. The exhaustive list follows:
.TP
.B \-Z
\fIzipinfo\fP(1L) mode. If the first option on the command line is \fB\-Z\fP,
the remaining options are taken to be \fIzipinfo\fP(1L) options. See the
appropriate manual page for a description of these options.
.TP
.B \-A
[OS/2, Unix DLL] print extended help for the DLL's programming interface (API).
.TP
.B \-c
extract files to stdout/screen (``CRT''). This option is similar to the
\fB\-p\fP option except that the name of each file is printed as it is
extracted, the \fB\-a\fP option is allowed, and ASCII-EBCDIC conversion
is automatically performed if appropriate. This option is not listed in
the \fIunzip\fP usage screen.
.TP
.B \-f
freshen existing files, i.e., extract only those files that
already exist on disk and that are newer than the disk copies. By
default \fIunzip\fP queries before overwriting, but the \fB\-o\fP option
may be used to suppress the queries. Note that under many operating systems,
the TZ (timezone) environment variable must be set correctly in order for
\fB\-f\fP and \fB\-u\fP to work properly (under Unix the variable is usually
set automatically). The reasons for this are somewhat subtle but
have to do with the differences between DOS-format file times (always local
time) and Unix-format times (always in GMT/UTC) and the necessity to compare
the two. A typical TZ value is ``PST8PDT'' (US Pacific time with automatic
adjustment for Daylight Savings Time or ``summer time'').
.TP
.B \-l
list archive files (short format). The names, uncompressed file sizes and
modification dates and times of the specified files are printed, along
with totals for all files specified. If UnZip was compiled with OS2_EAS
defined, the \fB\-l\fP option also lists columns for the sizes of stored
OS/2 extended attributes (EAs) and OS/2 access control lists (ACLs). In
addition, the zipfile comment and individual file comments (if any) are
displayed. If a file was archived from a single-case file system (for
example, the old MS-DOS FAT file system) and the \fB\-L\fP option was given,
the filename is converted to lowercase and is prefixed with a caret (^).
.TP
.B \-p
extract files to pipe (stdout). Nothing but the file data is sent to
stdout, and the files are always extracted in binary format, just as they
are stored (no conversions).
.TP
.B \-t
test archive files. This option extracts each specified file in memory
and compares the CRC (cyclic redundancy check, an enhanced checksum) of
the expanded file with the original file's stored CRC value.
.TP
.B \-T
[most OSes] set the timestamp on the archive(s) to that of the newest file
in each one. This corresponds to \fIzip\fP's \fB\-go\fP option except that
it can be used on wildcard zipfiles (e.g., ``\fCunzip \-T \e*.zip\fR'') and
is much faster.
.TP
.B \-u
update existing files and create new ones if needed. This option performs
the same function as the \fB\-f\fP option, extracting (with query) files
that are newer than those with the same name on disk, and in addition it
extracts those files that do not already exist on disk. See \fB\-f\fP
above for information on setting the timezone properly.
.TP
.B \-v
be verbose or print diagnostic version info. This option has evolved and
now behaves as both an option and a modifier. As an option it has two
purposes: when a zipfile is specified with no other options, \fB\-v\fP lists
archive files verbosely, adding to the basic \fB\-l\fP info the compression
method, compressed size, compression ratio and 32-bit CRC. When no zipfile
is specified (that is, the complete command is simply ``\fCunzip \-v\fR''), a
diagnostic screen is printed. In addition to the normal header with release
date and version, \fIunzip\fP lists the home Info-ZIP ftp site and where to
find a list of other ftp and non-ftp sites; the target operating system for
which it was compiled, as well as (possibly) the hardware on which it was
compiled, the compiler and version used, and the compilation date; any special
compilation options that might affect the program's operation (see also
\fBDECRYPTION\fP below); and any options stored in environment variables
that might do the same (see \fBENVIRONMENT OPTIONS\fP below). As a
modifier it works in conjunction with other options (e.g., \fB\-t\fP) to
produce more verbose or debugging output; this is not yet fully implemented
but will be in future releases.
.TP
.B \-z
display only the archive comment.
.PD
.\" =========================================================================
.SH MODIFIERS
.TP
.B \-a
convert text files. Ordinarily all files are extracted exactly as they
are stored (as ``binary'' files). The \fB\-a\fP option causes files identified
by \fIzip\fP as text files (those with the `t' label in \fIzipinfo\fP
listings, rather than `b') to be automatically extracted as such, converting
line endings, end-of-file characters and the character set itself as necessary.
(For example, Unix files use line feeds (LFs) for end-of-line (EOL) and
have no end-of-file (EOF) marker; Macintoshes use carriage returns (CRs)
for EOLs; and most PC operating systems use CR+LF for EOLs and control-Z for
EOF. In addition, IBM mainframes and the Michigan Terminal System use EBCDIC
rather than the more common ASCII character set, and NT supports Unicode.)
Note that \fIzip\fP's identification of text files is by no means perfect; some
``text'' files may actually be binary and vice versa. \fIunzip\fP therefore
prints ``\fC[text]\fR'' or ``\fC[binary]\fR'' as a visual check for each file
it extracts when using the \fB\-a\fP option. The \fB\-aa\fP option forces
all files to be extracted as text, regardless of the supposed file type.
.TP
.B \-b
[general] treat all files as binary (no text conversions). This is a shortcut
for \fB\-\-\-a\fP.
.TP
.B \-b
[Tandem] force the creation files with filecode type 180 ('C') when
extracting Zip entries marked as "text". (On Tandem, \fB\-a\fP is enabled
by default, see above).
.TP
.B \-b
[VMS] auto-convert binary files (see \fB\-a\fP above) to fixed-length,
512-byte record format. Doubling the option (\fB\-bb\fP) forces all files
to be extracted in this format. When extracting to standard output
(\fB\-c\fP or \fB\-p\fP option in effect), the default conversion of text
record delimiters is disabled for binary (\fB\-b\fP) resp. all (\fB\-bb\fP)
files.
.TP
.B \-B
[Unix only, and only if compiled with UNIXBACKUP defined] save a backup copy
of each overwritten file with a tilde appended (e.g., the old copy of
``\fCfoo\fR'' is renamed to ``\fCfoo~\fR''). This is similar to the default
behavior of \fIemacs\fP(1) in many locations.
.TP
.B \-C
match filenames case-insensitively. \fIunzip\fP's philosophy is ``you get
what you ask for'' (this is also responsible for the \fB\-L\fP/\fB\-U\fP
change; see the relevant options below). Because some file systems are fully
case-sensitive (notably those under the Unix operating system) and because
both ZIP archives and \fIunzip\fP itself are portable across platforms,
\fIunzip\fP's default behavior is to match both wildcard and literal filenames
case-sensitively. That is, specifying ``\fCmakefile\fR'' on the command line
will \fIonly\fP match ``makefile'' in the archive, not ``Makefile'' or
``MAKEFILE'' (and similarly for wildcard specifications). Since this does
not correspond to the behavior of many other operating/file systems (for
example, OS/2 HPFS, which preserves mixed case but is not sensitive to it),
the \fB\-C\fP option may be used to force all filename matches to be
case-insensitive. In the example above, all three files would then match
``\fCmakefile\fR'' (or ``\fCmake*\fR'', or similar). The \fB\-C\fP option
affects files in both the normal file list and the excluded-file list (xlist).
.TP
.B \-E
[MacOS only] display contents of MacOS extra field during restore operation.
.TP
.B \-F
[Acorn only] suppress removal of NFS filetype extension from stored filenames.
.TP
.B \-F
[non-Acorn systems supporting long filenames with embedded commas,
and only if compiled with ACORN_FTYPE_NFS defined] translate
filetype information from ACORN RISC OS extra field blocks into a
NFS filetype extension and append it to the names of the extracted files.
(When the stored filename appears to already have an appended NFS filetype
extension, it is replaced by the info from the extra field.)
.TP
.B \-i
[MacOS only] ignore filenames stored in MacOS extra fields. Instead, the
most compatible filename stored in the generic part of the entry's header
is used.
.TP
.B \-j
junk paths. The archive's directory structure is not recreated; all files
are deposited in the extraction directory (by default, the current one).
.TP
.B \-J
[BeOS only] junk file attributes. The file's BeOS file attributes are not
restored, just the file's data.
.TP
.B \-J
[MacOS only] ignore MacOS extra fields. All Macintosh specific info
is skipped. Data-fork and resource-fork are restored as separate files.
.TP
.B \-L
convert to lowercase any filename originating on an uppercase-only operating
system or file system. (This was \fIunzip\fP's default behavior in releases
prior to 5.11; the new default behavior is identical to the old behavior with
the \fB\-U\fP option, which is now obsolete and will be removed in a future
release.) Depending on the archiver, files archived under single-case
file systems (VMS, old MS-DOS FAT, etc.) may be stored as all-uppercase names;
this can be ugly or inconvenient when extracting to a case-preserving
file system such as OS/2 HPFS or a case-sensitive one such as under
Unix. By default \fIunzip\fP lists and extracts such filenames exactly as
they're stored (excepting truncation, conversion of unsupported characters,
etc.); this option causes the names of all files from certain systems to be
converted to lowercase. The \fB\-LL\fP option forces conversion of every
filename to lowercase, regardless of the originating file system.
.TP
.B \-M
pipe all output through an internal pager similar to the Unix \fImore\fP(1)
command. At the end of a screenful of output, \fIunzip\fP pauses with a
``\-\-More\-\-'' prompt; the next screenful may be viewed by pressing the
Enter (Return) key or the space bar. \fIunzip\fP can be terminated by
pressing the ``q'' key and, on some systems, the Enter/Return key. Unlike
Unix \fImore\fP(1), there is no forward-searching or editing capability.
Also, \fIunzip\fP doesn't notice if long lines wrap at the edge of the screen,
effectively resulting in the printing of two or more lines and the likelihood
that some text will scroll off the top of the screen before being viewed.
On some systems the number of available lines on the screen is not detected,
in which case \fIunzip\fP assumes the height is 24 lines.
.TP
.B \-n
never overwrite existing files. If a file already exists, skip the extraction
of that file without prompting. By default \fIunzip\fP queries before
extracting any file that already exists; the user may choose to overwrite
only the current file, overwrite all files, skip extraction of the current
file, skip extraction of all existing files, or rename the current file.
.TP
.B \-N
[Amiga] extract file comments as Amiga filenotes. File comments are created
with the \-c option of \fIzip\fP(1L), or with the \-N option of the Amiga port
of \fIzip\fP(1L), which stores filenotes as comments.
.TP
.B \-o
overwrite existing files without prompting. This is a dangerous option, so
use it with care. (It is often used with \fB\-f\fP, however, and is the only
way to overwrite directory EAs under OS/2.)
.IP \fB\-P\fP\ \fIpassword\fP
use \fIpassword\fP to decrypt encrypted zipfile entries (if any). \fBTHIS IS
INSECURE!\fP Many multi-user operating systems provide ways for any user to
see the current command line of any other user; even on stand-alone systems
there is always the threat of over-the-shoulder peeking. Storing the plaintext
password as part of a command line in an automated script is even worse.
Whenever possible, use the non-echoing, interactive prompt to enter passwords.
(And where security is truly important, use strong encryption such as Pretty
Good Privacy instead of the relatively weak encryption provided by standard
zipfile utilities.)
.TP
.B \-q
perform operations quietly (\fB\-qq\fP = even quieter). Ordinarily \fIunzip\fP
prints the names of the files it's extracting or testing, the extraction
methods, any file or zipfile comments that may be stored in the archive,
and possibly a summary when finished with each archive. The \fB\-q\fP[\fBq\fP]
options suppress the printing of some or all of these messages.
.TP
.B \-s
[OS/2, NT, MS-DOS] convert spaces in filenames to underscores. Since all PC
operating systems allow spaces in filenames, \fIunzip\fP by default extracts
filenames with spaces intact (e.g., ``\fCEA\ DATA.\ SF\fR''). This can be
awkward, however, since MS-DOS in particular does not gracefully support
spaces in filenames. Conversion of spaces to underscores can eliminate the
awkwardness in some cases.
.TP
.B \-U
(obsolete; to be removed in a future release) leave filenames uppercase if
created under MS-DOS, VMS, etc. See \fB\-L\fP above.
.TP
.B \-V
retain (VMS) file version numbers. VMS files can be stored with a version
number, in the format \fCfile.ext;##\fR. By default the ``\fC;##\fR'' version
numbers are stripped, but this option allows them to be retained. (On
file systems that limit filenames to particularly short lengths, the version
numbers may be truncated or stripped regardless of this option.)
.TP
.B \-X
[VMS, Unix, OS/2, NT] restore owner/protection info (UICs) under VMS, or user
and group info (UID/GID) under Unix, or access control lists (ACLs) under
certain network-enabled versions of OS/2 (Warp Server with IBM LAN
Server/Requester 3.0 to 5.0; Warp Connect with IBM Peer 1.0), or security ACLs
under Windows NT. In most cases this will require special system privileges,
and doubling the option (\fB\-XX\fP) under NT instructs \fIunzip\fP to use
privileges for extraction; but under Unix, for example, a user who belongs to
several groups can restore files owned by any of those groups, as long as the
user IDs match his or her own. Note that ordinary file attributes are always
restored--this option applies only to optional, extra ownership info available
on some operating systems. [NT's access control lists do not appear to be
especially compatible with OS/2's, so no attempt is made at cross-platform
portability of access privileges. It is not clear under what conditions this
would ever be useful anyway.]
.TP
.B \-$
.\" Amiga support possible eventually, but not yet
[MS-DOS, OS/2, NT] restore the volume label if the extraction medium is
removable (e.g., a diskette). Doubling the option (\fB\-$$\fP) allows fixed
media (hard disks) to be labelled as well. By default, volume labels are
ignored.
.IP \fB\-/\fP\ \fIextensions\fP
[Acorn only] overrides the extension list supplied by Unzip$Ext environment
variable. During extraction, filename extensions that match one of the items
in this extension list are swapped in front of the base name of the extracted
file.
.TP
.B \-:
[all but Acorn, VM/CMS, MVS, Tandem] allows to extract archive members into
locations outside of the current `` extraction root folder''. For security
reasons, \fIunzip\fP normally removes ``parent dir'' path components
(``../'') from the names of extracted file. This safety feature (new for
version 5.50) prevents \fIunzip\fP from accidentally writing files to
``sensitive'' areas outside the active extraction folder tree head. The
\fB\-:\fP option lets \fIunzip\fP switch back to its previous, more liberal
behaviour, to allow exact extraction of (older) archives that used ``../''
components to create multiple directory trees at the level of the current
extraction folder.
.PD
.\" =========================================================================
.SH "ENVIRONMENT OPTIONS"
\fIunzip\fP's default behavior may be modified via options placed in
an environment variable. This can be done with any option, but it
is probably most useful with the \fB\-a\fP, \fB\-L\fP, \fB\-C\fP, \fB\-q\fP,
\fB\-o\fP, or \fB\-n\fP modifiers: make \fIunzip\fP auto-convert text
files by default, make it convert filenames from uppercase systems to
lowercase, make it match names case-insensitively, make it quieter,
or make it always overwrite or never overwrite files as it extracts
them. For example, to make \fIunzip\fP act as quietly as possible, only
reporting errors, one would use one of the following commands:
.TP
Unix Bourne shell:
UNZIP=\-qq; export UNZIP
.TP
Unix C shell:
setenv UNZIP \-qq
.TP
OS/2 or MS-DOS:
set UNZIP=\-qq
.TP
VMS (quotes for \fIlowercase\fP):
define UNZIP_OPTS ""\-qq""
.PP
Environment options are, in effect, considered to be just like any other
command-line options, except that they are effectively the first options
on the command line. To override an environment option, one may use the
``minus operator'' to remove it. For instance, to override one of the
quiet-flags in the example above, use the command
.PP
.EX
unzip \-\-q[\fIother options\fP] zipfile
.EE
.PP
The first hyphen is the normal
switch character, and the second is a minus sign, acting on the q option.
Thus the effect here is to cancel one quantum of quietness. To cancel
both quiet flags, two (or more) minuses may be used:
.PP
.EX
unzip \-t\-\-q zipfile
unzip \-\-\-qt zipfile
.EE
.PP
(the two are equivalent). This may seem awkward
or confusing, but it is reasonably intuitive: just ignore the first
hyphen and go from there. It is also consistent with the behavior of
Unix \fInice\fP(1).
.PP
As suggested by the examples above, the default variable names are UNZIP_OPTS
for VMS (where the symbol used to install \fIunzip\fP as a foreign command
would otherwise be confused with the environment variable), and UNZIP
for all other operating systems. For compatibility with \fIzip\fP(1L),
UNZIPOPT is also accepted (don't ask). If both UNZIP and UNZIPOPT
are defined, however, UNZIP takes precedence. \fIunzip\fP's diagnostic
option (\fB\-v\fP with no zipfile name) can be used to check the values
of all four possible \fIunzip\fP and \fIzipinfo\fP environment variables.
.PP
The timezone variable (TZ) should be set according to the local timezone
in order for the \fB\-f\fP and \fB\-u\fP to operate correctly. See the
description of \fB\-f\fP above for details. This variable may also be
necessary in order for timestamps on extracted files to be set correctly.
Under Windows 95/NT \fIunzip\fP should know the correct timezone even if
TZ is unset, assuming the timezone is correctly set in the Control Panel.
.PD
.\" =========================================================================
.SH DECRYPTION
Encrypted archives are fully supported by Info-ZIP software, but due to
United States export restrictions, de-/encryption support might be disabled
in your compiled binary. However, since spring 2000, US export restrictions
have been liberated, and our source archives do now include full crypt code.
In case you need binary distributions with crypt support enabled, see the
file ``WHERE'' in any Info-ZIP source or binary distribution for locations
both inside and outside the US.
.PP
Some compiled versions of \fIunzip\fP may not support decryption.
To check a version for crypt support, either attempt to test or extract
an encrypted archive, or else check \fIunzip\fP's diagnostic
screen (see the \fB\-v\fP option above) for ``\fC[decryption]\fR'' as one
of the special compilation options.
.PP
As noted above, the \fB\-P\fP option may be used to supply a password on
the command line, but at a cost in security. The preferred decryption
method is simply to extract normally; if a zipfile member is encrypted,
\fIunzip\fP will prompt for the password without echoing what is typed.
\fIunzip\fP continues to use the same password as long as it appears to be
valid, by testing a 12-byte header on each file. The correct password will
always check out against the header, but there is a 1-in-256 chance that an
incorrect password will as well. (This is a security feature of the PKWARE
zipfile format; it helps prevent brute-force attacks that might otherwise
gain a large speed advantage by testing only the header.) In the case that
an incorrect password is given but it passes the header test anyway, either
an incorrect CRC will be generated for the extracted data or else \fIunzip\fP
will fail during the extraction because the ``decrypted'' bytes do not
constitute a valid compressed data stream.
.PP
If the first password fails the header check on some file, \fIunzip\fP will
prompt for another password, and so on until all files are extracted. If
a password is not known, entering a null password (that is, just a carriage
return or ``Enter'') is taken as a signal to skip all further prompting.
Only unencrypted files in the archive(s) will thereafter be extracted. (In
fact, that's not quite true; older versions of \fIzip\fP(1L) and
\fIzipcloak\fP(1L) allowed null passwords, so \fIunzip\fP checks each encrypted
file to see if the null password works. This may result in ``false positives''
and extraction errors, as noted above.)
.PP
Archives encrypted with 8-bit passwords (for example, passwords with accented
European characters) may not be portable across systems and/or other
archivers. This problem stems from the use of multiple encoding methods for
such characters, including Latin-1 (ISO 8859-1) and OEM code page 850. DOS
\fIPKZIP\fP 2.04g uses the OEM code page; Windows \fIPKZIP\fP 2.50 uses
Latin-1 (and is therefore incompatible with DOS \fIPKZIP\fP); Info-ZIP uses
the OEM code page on DOS, OS/2 and Win3.x ports but Latin-1 everywhere
else; and Nico Mak's \fIWinZip\fP 6.x does not allow 8-bit passwords at all.
\fIUnZip\fP 5.3 (or newer) attempts to use the default character set first
(e.g., Latin-1), followed by the alternate one (e.g., OEM code page) to test
passwords. On EBCDIC systems, if both of these fail, EBCDIC encoding will
be tested as a last resort. (EBCDIC is not tested on non-EBCDIC systems,
because there are no known archivers that encrypt using EBCDIC encoding.)
ISO character encodings other than Latin-1 are not supported.
.PD
.\" =========================================================================
.SH EXAMPLES
To use \fIunzip\fP to extract all members of the archive \fIletters.zip\fP
into the current directory and subdirectories below it, creating any
subdirectories as necessary:
.PP
.EX
unzip letters
.EE
.PP
To extract all members of \fIletters.zip\fP into the current directory only:
.PP
.EX
unzip -j letters
.EE
.PP
To test \fIletters.zip\fP, printing only a summary message indicating
whether the archive is OK or not:
.PP
.EX
unzip -tq letters
.EE
.PP
To test \fIall\fP zipfiles in the current directory, printing only the
summaries:
.PP
.EX
unzip -tq \e*.zip
.EE
.PP
(The backslash before the asterisk is only required if the shell expands
wildcards, as in Unix; double quotes could have been used instead, as in
the source examples below.)\ \ To extract to standard output all members of
\fIletters.zip\fP whose names end in \fI.tex\fP, auto-converting to the
local end-of-line convention and piping the output into \fImore\fP(1):
.PP
.EX
unzip \-ca letters \e*.tex | more
.EE
.PP
To extract the binary file \fIpaper1.dvi\fP to standard output and pipe it
to a printing program:
.PP
.EX
unzip \-p articles paper1.dvi | dvips
.EE
.PP
To extract all FORTRAN and C source files--*.f, *.c, *.h, and Makefile--into
the /tmp directory:
.PP
.EX
unzip source.zip "*.[fch]" Makefile -d /tmp
.EE
.PP
(the double quotes are necessary only in Unix and only if globbing is turned
on). To extract all FORTRAN and C source files, regardless of case (e.g.,
both *.c and *.C, and any makefile, Makefile, MAKEFILE or similar):
.PP
.EX
unzip \-C source.zip "*.[fch]" makefile -d /tmp
.EE
.PP
To extract any such files but convert any uppercase MS-DOS or VMS names to
lowercase and convert the line-endings of all of the files to the local
standard (without respect to any files that might be marked ``binary''):
.PP
.EX
unzip \-aaCL source.zip "*.[fch]" makefile -d /tmp
.EE
.PP
To extract only newer versions of the files already in the current
directory, without querying (NOTE: be careful of unzipping in one timezone a
zipfile created in another--ZIP archives other than those created by Zip 2.1
or later contain no timezone information, and a ``newer'' file from an eastern
timezone may, in fact, be older):
.PP
.EX
unzip \-fo sources
.EE
.PP
To extract newer versions of the files already in the current directory and
to create any files not already there (same caveat as previous example):
.PP
.EX
unzip \-uo sources
.EE
.PP
To display a diagnostic screen showing which \fIunzip\fP and \fIzipinfo\fP
options are stored in environment variables, whether decryption support was
compiled in, the compiler with which \fIunzip\fP was compiled, etc.:
.PP
.EX
unzip \-v
.EE
.PP
In the last five examples, assume that UNZIP or UNZIP_OPTS is set to -q.
To do a singly quiet listing:
.PP
.EX
unzip \-l file.zip
.EE
.PP
To do a doubly quiet listing:
.PP
.EX
unzip \-ql file.zip
.EE
.PP
(Note that the ``\fC.zip\fR'' is generally not necessary.) To do a standard
listing:
.PP
.EX
unzip \-\-ql file.zip
.EE
or
.EX
unzip \-l\-q file.zip
.EE
or
.EX
unzip \-l\-\-q file.zip
.EE
\fR(Extra minuses in options don't hurt.)
.PD
.\" =========================================================================
.SH TIPS
The current maintainer, being a lazy sort, finds it very useful to define
a pair of aliases: \fCtt\fR for ``\fCunzip \-tq\fR'' and \fCii\fR for
``\fCunzip \-Z\fR'' (or ``\fCzipinfo\fR''). One may then simply type
``\fCtt zipfile\fR'' to test an archive, something that is worth making a
habit of doing. With luck \fIunzip\fP will report ``\fCNo errors detected
in compressed data of zipfile.zip\fR,'' after which one may breathe a sigh
of relief.
.PP
The maintainer also finds it useful to set the UNZIP environment variable
to ``\fC\-aL\fR'' and is tempted to add ``\fC\-C\fR'' as well. His ZIPINFO
variable is set to ``\fC\-z\fR''.
.PD
.\" =========================================================================
.SH DIAGNOSTICS
The exit status (or error level) approximates the exit codes defined by PKWARE
and takes on the following values, except under VMS:
.RS
.IP 0
normal; no errors or warnings detected.
.IP 1
one or more warning errors were encountered, but processing completed
successfully anyway. This includes zipfiles where one or more files
was skipped due to unsupported compression method or encryption with an
unknown password.
.IP 2
a generic error in the zipfile format was detected. Processing may have
completed successfully anyway; some broken zipfiles created by other
archivers have simple work-arounds.
.IP 3
a severe error in the zipfile format was detected. Processing probably
failed immediately.
.IP 4
\fIunzip\fP was unable to allocate memory for one or more buffers during
program initialization.
.IP 5
\fIunzip\fP was unable to allocate memory or unable to obtain a tty to read
the decryption password(s).
.IP 6
\fIunzip\fP was unable to allocate memory during decompression to disk.
.IP 7
\fIunzip\fP was unable to allocate memory during in-memory decompression.
.IP 8
[currently not used]
.IP 9
the specified zipfiles were not found.
.IP 10
invalid options were specified on the command line.
.IP 11
no matching files were found.
.IP 50
the disk is (or was) full during extraction.
.IP 51
the end of the ZIP archive was encountered prematurely.
.IP 80
the user aborted \fIunzip\fP prematurely with control-C (or similar)
.IP 81
testing or extraction of one or more files failed due to unsupported
compression methods or unsupported decryption.
.IP 82
no files were found due to bad decryption password(s). (If even one file is
successfully processed, however, the exit status is 1.)
.RE
.PP
VMS interprets standard Unix (or PC) return values as other, scarier-looking
things, so \fIunzip\fP instead maps them into VMS-style status codes. The
current mapping is as follows: 1 (success) for normal exit, 0x7fff0001
for warning errors, and (0x7fff000? + 16*normal_unzip_exit_status) for all
other errors, where the `?' is 2 (error) for \fIunzip\fP values 2, 9-11 and
80-82, and 4 (fatal error) for the remaining ones (3-8, 50, 51). In addition,
there is a compilation option to expand upon this behavior: defining
RETURN_CODES results in a human-readable explanation of what the error
status means.
.PD
.\" =========================================================================
.SH BUGS
Multi-part archives are not yet supported, except in conjunction with
\fIzip\fP. (All parts must be concatenated together in order, and then
``\fCzip \-F\fR'' must be performed on the concatenated archive in order
to ``fix'' it.) This will definitely be corrected in the next major release.
.PP
Archives read from standard input are not yet supported, except with
\fIfunzip\fP (and then only the first member of the archive can be extracted).
.PP
Archives encrypted with 8-bit passwords (e.g., passwords with accented
European characters) may not be portable across systems and/or other
archivers. See the discussion in \fBDECRYPTION\fP above.
.PP
\fIunzip\fP's \fB\-M\fP (``more'') option is overly simplistic in its handling
of screen output; as noted above, it fails to detect the wrapping of long lines
and may thereby cause lines at the top of the screen to be scrolled off before
being read. \fIunzip\fP should detect and treat each occurrence of line-wrap
as one additional line printed. This requires knowledge of the screen's width
as well as its height. In addition, \fIunzip\fP should detect the true screen
geometry on all systems.
.PP
Dates, times and permissions of stored directories are not restored except
under Unix.
.PP
[MS-DOS] When extracting or testing files from an archive on a defective
floppy diskette, if the ``Fail'' option is chosen from DOS's ``Abort, Retry,
Fail?'' message, older versions of \fIunzip\fP may hang the system, requiring
a reboot. This problem appears to be fixed, but control-C (or control-Break)
can still be used to terminate \fIunzip\fP.
.PP
Under DEC Ultrix, \fIunzip\fP would sometimes fail on long zipfiles (bad CRC,
not always reproducible). This was apparently due either to a hardware bug
(cache memory) or an operating system bug (improper handling of page faults?).
Since Ultrix has been abandoned in favor of Digital Unix (OSF/1), this may not
be an issue anymore.
.PP
[Unix] Unix special files such as FIFO buffers (named pipes), block devices
and character devices are not restored even if they are somehow represented
in the zipfile, nor are hard-linked files relinked. Basically the only file
types restored by \fIunzip\fP are regular files, directories and symbolic
(soft) links.
.PP
[OS/2] Extended attributes for existing directories are only updated if the
\fB\-o\fP (``overwrite all'') option is given. This is a limitation of the
operating system; because directories only have a creation time associated
with them, \fIunzip\fP has no way to determine whether the stored attributes
are newer or older than those on disk. In practice this may mean a two-pass
approach is required: first unpack the archive normally (with or without
freshening/updating existing files), then overwrite just the directory entries
(e.g., ``\fCunzip -o foo */\fR'').
.PP
[VMS] When extracting to another directory, only the \fI[.foo]\fP syntax is
accepted for the \fB\-d\fP option; the simple Unix \fIfoo\fP syntax is
silently ignored (as is the less common VMS \fIfoo.dir\fP syntax).
.PP
[VMS] When the file being extracted already exists, \fIunzip\fP's query only
allows skipping, overwriting or renaming; there should additionally be a
choice for creating a new version of the file. In fact, the ``overwrite''
choice does create a new version; the old version is not overwritten or
deleted.
.PD
.\" =========================================================================
.SH "SEE ALSO"
\fIfunzip\fP(1L), \fIzip\fP(1L), \fIzipcloak\fP(1L), \fIzipgrep\fP(1L),
\fIzipinfo\fP(1L), \fIzipnote\fP(1L), \fIzipsplit\fP(1L)
.PD
.\" =========================================================================
.SH URL
The Info-ZIP home page is currently at
.EX
\fChttp://www.info-zip.org/pub/infozip/\fR
.EE
or
.EX
\fCftp://ftp.info-zip.org/pub/infozip/\fR .
.EE
.PD
.\" =========================================================================
.SH AUTHORS
The primary Info-ZIP authors (current semi-active members of the Zip-Bugs
workgroup) are: Greg ``Cave Newt'' Roelofs (UnZip); Onno van der Linden (Zip);
Jean-loup Gailly (compression); Mark Adler (decompression, fUnZip); Christian
Spieler (UnZip maintance coordination, VMS, MS-DOS, Windows 95, NT,
shared code, general Zip and UnZip integration and optimization);
Mike White (Windows GUI, Windows DLLs); Kai Uwe Rommel (OS/2);
Paul Kienitz (Amiga, Windows 95); Chris Herborth (BeOS, QNX, Atari);
Jonathan Hudson (SMS/QDOS); Sergio Monesi (Acorn RISC OS); Harald
Denker (Atari, MVS); John Bush (Solaris, Amiga); Hunter Goatley (VMS); Steve
Salisbury (Windows 95, NT); Steve Miller (Windows CE GUI), Johnny Lee (MS-DOS,
Windows 95, NT); and Dave Smith (Tandem NSK).
The author of the original unzip code upon which Info-ZIP's was based
is Samuel H. Smith; Carl Mascott did the first Unix port; and David P.
Kirschbaum organized and led Info-ZIP in its early days with Keith Petersen
hosting the original mailing list at WSMR-SimTel20. The full list of
contributors to UnZip has grown quite large; please refer to the CONTRIBS
file in the UnZip source distribution for a relatively complete version.
.PD
.\" =========================================================================
.SH VERSIONS
.ta \w'vx.xxnn'u +\w'fall 1989'u+3n
.PD 0
.IP "v1.2\t15 Mar 89" \w'\t\t'u
Samuel H. Smith
.IP "v2.0\t\ 9 Sep 89"
Samuel H. Smith
.IP "v2.x\tfall 1989"
many Usenet contributors
.IP "v3.0\t\ 1 May 90"
Info-ZIP (DPK, consolidator)
.IP "v3.1\t15 Aug 90"
Info-ZIP (DPK, consolidator)
.IP "v4.0\t\ 1 Dec 90"
Info-ZIP (GRR, maintainer)
.IP "v4.1\t12 May 91"
Info-ZIP
.IP "v4.2\t20 Mar 92"
Info-ZIP (Zip-Bugs subgroup, GRR)
.IP "v5.0\t21 Aug 92"
Info-ZIP (Zip-Bugs subgroup, GRR)
.IP "v5.01\t15 Jan 93"
Info-ZIP (Zip-Bugs subgroup, GRR)
.IP "v5.1\t\ 7 Feb 94"
Info-ZIP (Zip-Bugs subgroup, GRR)
.IP "v5.11\t\ 2 Aug 94"
Info-ZIP (Zip-Bugs subgroup, GRR)
.IP "v5.12\t28 Aug 94"
Info-ZIP (Zip-Bugs subgroup, GRR)
.IP "v5.2\t30 Apr 96"
Info-ZIP (Zip-Bugs subgroup, GRR)
.IP "v5.3\t22 Apr 97"
Info-ZIP (Zip-Bugs subgroup, GRR)
.IP "v5.31\t31 May 97"
Info-ZIP (Zip-Bugs subgroup, GRR)
.IP "v5.32\t\ 3 Nov 97"
Info-ZIP (Zip-Bugs subgroup, GRR)
.IP "v5.4\t28 Nov 98"
Info-ZIP (Zip-Bugs subgroup, SPC)
.IP "v5.41\t16 Apr 00"
Info-ZIP (Zip-Bugs subgroup, SPC)
.IP "v5.42\t14 Jan 01"
Info-ZIP (Zip-Bugs subgroup, SPC)
.IP "v5.5\t17 Feb 02"
Info-ZIP (Zip-Bugs subgroup, SPC)
.PD

View File

@ -0,0 +1,336 @@
.\" Copyright (c) 1990-2002 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
.\"
.\" unzipsfx.1 by Greg Roelofs
.\"
.\" =========================================================================
.\" define .EX/.EE (for multiline user-command examples; normal Courier font)
.de EX
.in +4n
.nf
.ft CW
..
.de EE
.ft R
.fi
.in -4n
..
.\" =========================================================================
.TH UNZIPSFX 1L "17 February 2002 (v5.5)" "Info-ZIP"
.SH NAME
unzipsfx \- self-extracting stub for prepending to ZIP archives
.PD
.SH SYNOPSIS
\fB<name of unzipsfx+archive combo>\fP [\fB\-cfptuz\fP[\fBajnoqsCLV$\fP]]
[\fIfile(s)\fP\ .\|.\|. [\fB\-x\fP\ \fIxfile(s)\fP\ .\|.\|.]]
.PD
.\" =========================================================================
.SH DESCRIPTION
\fIunzipsfx\fP is a modified version of \fIunzip\fP(1L) designed to be
prepended to existing ZIP archives in order to form self-extracting archives.
Instead of taking its first non-flag argument to be the zipfile(s) to be
extracted, \fIunzipsfx\fP seeks itself under the name by which it was invoked
and tests or extracts the contents of the appended archive. Because the
executable stub adds bulk to the archive (the whole purpose of which is to
be as small as possible), a number of the less-vital capabilities in regular
\fIunzip\fP have been removed. Among these are the usage (or help) screen,
the listing and diagnostic functions (\fB\-l\fP and \fB\-v\fP), the ability
to decompress older compression formats (the ``reduce,'' ``shrink'' and
``implode'' methods). The ability to extract to a directory other than
the current one can be selected as a compile-time option, which is now enabled
by default since UnZipSFX version 5.5. Similary, decryption is supported as
a compile-time option but should be avoided unless the attached archive
contains encrypted files. Starting with release 5.5, another compile-time
option adds a simple ``run command after extraction'' feature. This feature
is currently incompatible with the ``extract to different directory''
feature and remains disabled by default.
.PP
\fBNote that
self-extracting archives made with\fP \fIunzipsfx\fP \fBare no more (or less)
portable across different operating systems than is
the\fP \fIunzip\fP \fBexecutable itself.\fP In general a self-extracting
archive made on
a particular Unix system, for example, will only self-extract under the same
flavor of Unix. Regular \fIunzip\fP may still be used to extract the
embedded archive as with any normal zipfile, although it will generate
a harmless warning about extra bytes at the beginning of the zipfile.
\fIDespite this\fP, however, the self-extracting archive is technically
\fInot\fP a valid ZIP archive, and PKUNZIP may be unable to test or extract
it. This limitation is due to the simplistic manner in which the archive
is created; the internal directory structure is not updated to reflect the
extra bytes prepended to the original zipfile.
.PD
.\" =========================================================================
.SH ARGUMENTS
.IP [\fIfile(s)\fP]
An optional list of archive members to be processed.
Regular expressions (wildcards) similar to those in Unix \fIegrep\fP(1)
may be used to match multiple members. These wildcards may contain:
.RS
.IP *
matches a sequence of 0 or more characters
.IP ?
matches exactly 1 character
.IP [.\|.\|.]
matches any single character found inside the brackets; ranges are specified
by a beginning character, a hyphen, and an ending character. If an exclamation
point or a caret (`!' or `^') follows the left bracket, then the range of
characters within the brackets is complemented (that is, anything \fIexcept\fP
the characters inside the brackets is considered a match).
.RE
.IP
(Be sure to quote any character that might otherwise be interpreted or
modified by the operating system, particularly under Unix and VMS.)
.IP [\fB\-x\fP\ \fIxfile(s)\fP]
An optional list of archive members to be excluded from processing.
Since wildcard characters match directory separators (`/'), this option
may be used to exclude any files that are in subdirectories. For
example, ``\fCfoosfx *.[ch] -x */*\fR'' would extract all C source files
in the main directory, but none in any subdirectories. Without the \fB\-x\fP
option, all C source files in all directories within the zipfile would be
extracted.
.PP
If \fIunzipsfx\fP is compiled with SFX_EXDIR defined, the following option
is also enabled:
.IP [\fB\-d\fP\ \fIexdir\fP]
An optional directory to which to extract files. By default, all files
and subdirectories are recreated in the current directory; the \fB\-d\fP
option allows extraction in an arbitrary directory (always assuming one
has permission to write to the directory). The option and directory may
be concatenated without any white space between them, but note that this
may cause normal shell behavior to be suppressed. In particular,
``\fC\-d\ ~\fR'' (tilde) is expanded by Unix C shells into the name
of the user's home directory, but ``\fC\-d~\fR'' is treated as a
literal subdirectory ``\fB~\fP'' of the current directory.
.PD
.\" =========================================================================
.SH OPTIONS
\fIunzipsfx\fP supports the following \fIunzip\fP(1L) options: \fB\-c\fP
and \fB\-p\fP (extract to standard output/screen), \fB\-f\fP and \fB\-u\fP
(freshen and update existing files upon extraction), \fB\-t\fP (test
archive) and \fB\-z\fP (print archive comment). All normal listing options
(\fB\-l\fP, \fB\-v\fP and \fB\-Z\fP) have been removed, but the testing
option (\fB\-t\fP) may be used as a ``poor man's'' listing. Alternatively,
those creating self-extracting archives may wish to include a short listing
in the zipfile comment.
.PP
See \fIunzip\fP(1L) for a more complete description of these options.
.PD
.\" =========================================================================
.SH MODIFIERS
\fIunzipsfx\fP currently supports all \fIunzip\fP(1L) modifiers: \fB\-a\fP
(convert text files), \fB\-n\fP (never overwrite), \fB\-o\fP (overwrite
without prompting), \fB\-q\fP (operate quietly), \fB\-C\fP (match names
case-insensitively), \fB\-L\fP (convert uppercase-OS names to lowercase),
\fB\-j\fP (junk paths) and \fB\-V\fP (retain version numbers); plus the
following operating-system specific options: \fB\-X\fP (restore VMS
owner/protection info), \fB\-s\fP (convert spaces in filenames to underscores
[DOS, OS/2, NT]) and \fB\-$\fP (restore volume label [DOS, OS/2, NT, Amiga]).
.PP
(Support for regular ASCII text-conversion may be removed in future versions,
since it is simple enough for the archive's creator to ensure that text
files have the appropriate format for the local OS. EBCDIC conversion will
of course continue to be supported since the zipfile format implies ASCII
storage of text files.)
.PP
See \fIunzip\fP(1L) for a more complete description of these modifiers.
.PD
.\" =========================================================================
.SH "ENVIRONMENT OPTIONS"
\fIunzipsfx\fP uses the same environment variables as \fIunzip\fP(1L) does,
although this is likely to be an issue only for the person creating and
testing the self-extracting archive. See \fIunzip\fP(1L) for details.
.PD
.\" =========================================================================
.SH DECRYPTION
Decryption is supported exactly as in \fIunzip\fP(1L); that is, interactively
with a non-echoing prompt for the password(s). See \fIunzip\fP(1L) for
details. Once again, note that if the archive has no encrypted files there
is no reason to use a version of \fIunzipsfx\fP with decryption support;
that only adds to the size of the archive.
.PD
.\" =========================================================================
.SH AUTORUN COMMAND
When \fIunzipsfx\fP was compiled with CHEAP_SFX_AUTORUN defined, a simple
``command autorun'' feature is supported. You may enter a command into the
Zip archive comment, using the following format:
.PP
.EX
$AUTORUN$>[command line string]
.EE
.PP
When \fIunzipsfx\P recognizes the ``$AUTORUN$>'' token at the beginning
of the Zip archive comment, the remainder of the first line of the comment
(until the first newline character) is passed as a shell command to the
operating system using the C rtl ``system'' function. Before executing
the command, \fIunzipsfx\P displays the command on the console and prompts
the user for confirmation. When the user has switched off prompting by
specifying the \fB-q\fP option, autorun commands are never executed.
.PP
In case the archive comment contains additonal lines of text, the remainder
of the archive comment following the first line is displayed normally, unless
quiet operation was requested by supplying a \fB-q\fP option.
.PD
.\" =========================================================================
.SH EXAMPLES
To create a self-extracting archive \fIletters\fP from a regular zipfile
\fIletters.zip\fP and change the new archive's permissions to be
world-executable under Unix:
.PP
.EX
cat unzipsfx letters.zip > letters
chmod 755 letters
zip -A letters
.EE
.PP
To create the same archive under MS-DOS, OS/2 or NT (note the use of the
\fB/b\fP [binary] option to the \fIcopy\fP command):
.PP
.EX
copy /b unzipsfx.exe+letters.zip letters.exe
zip -A letters.exe
.EE
.PP
Under VMS:
.PP
.EX
copy unzipsfx.exe,letters.zip letters.exe
letters == "$currentdisk:[currentdir]letters.exe"
zip -A letters.exe
.EE
.PP
(The VMS \fIappend\fP command may also be used. The second command installs
the new program as a ``foreign command'' capable of taking arguments. The
third line assumes that Zip is already installed as a foreign command.)
Under AmigaDOS:
.PP
.EX
MakeSFX letters letters.zip UnZipSFX
.EE
.PP
(MakeSFX is included with the UnZip source distribution and with Amiga
binary distributions. ``\fCzip -A\fR'' doesn't work on Amiga self-extracting
archives.)
To test (or list) the newly created self-extracting archive:
.PP
.EX
letters \-t
.EE
.PP
To test \fIletters\fP quietly, printing only a summary message indicating
whether the archive is OK or not:
.PP
.EX
letters \-tqq
.EE
.PP
To extract the complete contents into the current directory, recreating all
files and subdirectories as necessary:
.PP
.EX
letters
.EE
.PP
To extract all \fC*.txt\fR files (in Unix quote the `*'):
.PP
.EX
letters *.txt
.EE
.PP
To extract everything \fIexcept\fP the \fC*.txt\fR files:
.PP
.EX
letters -x *.txt
.EE
.PP
To extract only the README file to standard output (the screen):
.PP
.EX
letters -c README
.EE
.PP
To print only the zipfile comment:
.PP
.EX
letters \-z
.EE
.PD
.\" =========================================================================
.SH LIMITATIONS
The principle and fundamental limitation of \fIunzipsfx\fP is that it is
not portable across architectures or operating systems, and therefore
neither are the resulting archives. For some architectures there is
limited portability, however (e.g., between some flavors of Intel-based Unix).
.PP
Another problem with the current implementation is that any archive
with ``junk'' prepended to the beginning technically is no longer a zipfile
(unless \fIzip\fP(1) is used to adjust the zipfile offsets appropriately,
as noted above). \fIunzip\fP(1) takes note of the prepended bytes
and ignores them since some file-transfer protocols, notably MacBinary, are
also known to prepend junk. But PKWARE's archiver suite may not be able to
deal with the modified archive unless its offsets have been adjusted.
.PP
\fIunzipsfx\fP has no knowledge of the user's PATH, so in general an archive
must either be in the current directory when it is invoked, or else a full
or relative path must be given. If a user attempts to extract the archive
from a directory in the PATH other than the current one, \fIunzipsfx\fP will
print a warning to the effect, ``can't find myself.'' This is always true
under Unix and may be true in some cases under MS-DOS, depending on the
compiler used (Microsoft C fully qualifies the program name, but other
compilers may not). Under OS/2 and NT there are operating-system calls
available that provide the full path name, so the archive may be invoked
from anywhere in the user's path. The situation is not known for AmigaDOS,
Atari TOS, MacOS, etc.
.PP
As noted above, a number of the normal \fIunzip\fP(1L) functions have
been removed in order to make \fIunzipsfx\fP smaller: usage and diagnostic
info, listing functions and extraction to other directories. Also, only
stored and deflated files are supported. The latter limitation is mainly
relevant to those who create SFX archives, however.
.PP
VMS users must know how to set up self-extracting archives as foreign
commands in order to use any of \fIunzipsfx\fP's options. This is not
necessary for simple extraction, but the command to do so then becomes,
e.g., ``\fCrun letters\fR'' (to continue the examples given above).
.PP
\fIunzipsfx\fP on the Amiga requires the use of a special program, MakeSFX,
in order to create working self-extracting archives; simple concatenation
does not work. (For technically oriented users, the attached archive is
defined as a ``debug hunk.'') There may be compatibility problems between
the ROM levels of older Amigas and newer ones.
.PP
All current bugs in \fIunzip\fP(1L) exist in \fIunzipsfx\fP as well.
.PD
.\" =========================================================================
.SH DIAGNOSTICS
\fIunzipsfx\fP's exit status (error level) is identical to that of
\fIunzip\fP(1L); see the corresponding man page.
.PD
.\" =========================================================================
.SH "SEE ALSO"
\fIfunzip\fP(1L), \fIunzip\fP(1L), \fIzip\fP(1L), \fIzipcloak\fP(1L),
\fIzipgrep\fP(1L), \fIzipinfo\fP(1L), \fIzipnote\fP(1L), \fIzipsplit\fP(1L)
.PD
.PD
.\" =========================================================================
.SH URL
The Info-ZIP home page is currently at
.EX
\fChttp://www.info-zip.org/pub/infozip/\fR
.EE
or
.EX
\fCftp://ftp.info-zip.org/pub/infozip/\fR .
.EE
.PD
.\" =========================================================================
.SH AUTHORS
Greg Roelofs was responsible for the basic modifications to UnZip necessary
to create UnZipSFX. See \fIunzip\fP(1L) for the current list of Zip-Bugs
authors, or the file CONTRIBS in the UnZip source distribution for the
full list of Info-ZIP contributors.
.PD

View File

@ -0,0 +1,89 @@
.\" Copyright (c) 1990-2002 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
.\"
.\" zipgrep.1 by Greg Roelofs.
.\"
.\" =========================================================================
.TH ZIPGREP 1L "17 February 2002" "Info-ZIP"
.SH NAME
zipgrep \- search files in a ZIP archive for lines matching a pattern
.PD
.SH SYNOPSIS
\fBzipgrep\fP [\fBegrep_options\fP] \fIpattern\fP
\fIfile\fP[\fI.zip\fP] [\fIfile(s)\fP\ .\|.\|.]
[\fB\-x\fP\ \fIxfile(s)\fP\ .\|.\|.]
.PD
.\" =========================================================================
.SH DESCRIPTION
\fIzipgrep\fP will search files within a ZIP archive for lines matching
the given string or pattern. \fIzipgrep\fP is a shell script and requires
\fIegrep\fP(1) and \fIunzip\fP(1L) to function. Its output is identical to
that of \fIegrep\fP(1).
.PD
.\" =========================================================================
.SH ARGUMENTS
.TP
.IP \fIpattern\fP
The pattern to be located within a ZIP archive. Any string or regular
expression accepted by \fIegrep\fP(1) may be used.
.IR file [ .zip ]
Path of the ZIP archive. (Wildcard expressions for the ZIP archive name are
not supported.) If the literal filename is not found, the suffix \fC.zip\fR
is appended. Note that self-extracting ZIP files are supported, as with any
other ZIP archive; just specify the \fC.exe\fR suffix (if any) explicitly.
.IP [\fIfile(s)\fP]
An optional list of archive members to be processed, separated by spaces.
If no member files are specified, all members of the ZIP archive are searched.
Regular expressions (wildcards) may be used to match multiple members:
.RS
.IP *
matches a sequence of 0 or more characters
.IP ?
matches exactly 1 character
.IP [.\|.\|.]
matches any single character found inside the brackets; ranges are specified
by a beginning character, a hyphen, and an ending character. If an exclamation
point or a caret (`!' or `^') follows the left bracket, then the range of
characters within the brackets is complemented (that is, anything \fIexcept\fP
the characters inside the brackets is considered a match).
.RE
.IP
(Be sure to quote any character that might otherwise be interpreted or
modified by the operating system.)
.IP [\fB\-x\fP\ \fIxfile(s)\fP]
An optional list of archive members to be excluded from processing.
Since wildcard characters match directory separators (`/'), this option
may be used to exclude any files that are in subdirectories. For
example, ``\fCzipgrep grumpy foo *.[ch] -x */*\fR'' would search for the
string ``grumpy'' in all C source files in the main directory of the ``foo''
archive, but none in any subdirectories. Without the \fB\-x\fP
option, all C source files in all directories within the zipfile would be
searched.
.\" =========================================================================
.SH OPTIONS
All options prior to the ZIP archive filename are passed to \fIegrep\fP(1).
.PD
.\" =========================================================================
.SH "SEE ALSO"
\fIegrep\fP(1), \fIunzip\fP(1L), \fIzip\fP(1L), \fIfunzip\fP(1L),
\fIzipcloak\fP(1L), \fIzipinfo\fP(1L), \fIzipnote\fP(1L), \fIzipsplit\fP(1L)
.PD
.\" =========================================================================
.SH URL
The Info-ZIP home page is currently at
.EX
\fChttp://www.info-zip.org/pub/infozip/\fR
.EE
or
.EX
\fCftp://ftp.info-zip.org/pub/infozip/\fR .
.EE
.PD
.\" =========================================================================
.SH AUTHORS
\fIzipgrep\fP was written by Jean-loup Gailly.
.PD

View File

@ -0,0 +1,488 @@
.\" Copyright (c) 1990-2002 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
.\"
.\" zipinfo.1 by Greg Roelofs and others.
.\"
.\" =========================================================================
.\" define .X macro (for long-line ZipInfo output examples; small Courier):
.de X
.nf
.ft CW
.ie n .ti -5
.el \{ .ti +2m
.ps -1 \}
\&\\$1
.ie n .ti +5
.el \{ .ti -2m
.ps +1 \}
.ft
.fi
..
.\" define .EX/.EE (for multiline user-command examples; normal Courier font)
.de EX
.in +4n
.nf
.ft CW
..
.de EE
.ft
.fi
.in -4n
..
.\" =========================================================================
.TH ZIPINFO 1L "17 February 2002 (v2.4)" "Info-ZIP"
.SH NAME
zipinfo \- list detailed information about a ZIP archive
.PD
.SH SYNOPSIS
\fBzipinfo\fP [\fB\-12smlvhMtTz\fP] \fIfile\fP[\fI.zip\fP]
[\fIfile(s)\fP\ .\|.\|.] [\fB\-x\fP\ \fIxfile(s)\fP\ .\|.\|.]
.PP
\fBunzip\fP \fB\-Z\fP [\fB\-12smlvhMtTz\fP] \fIfile\fP[\fI.zip\fP]
[\fIfile(s)\fP\ .\|.\|.] [\fB\-x\fP\ \fIxfile(s)\fP\ .\|.\|.]
.PD
.\" =========================================================================
.SH DESCRIPTION
\fIzipinfo\fP lists technical information about files in a ZIP archive, most
commonly found on MS-DOS systems. Such information includes file access
permissions, encryption status, type of compression, version and operating
system or file system of compressing program, and the like. The default
behavior (with no options) is
to list single-line entries for each file in the archive, with header and
trailer lines providing summary information for the entire archive. The
format is a cross between Unix ``\fCls \-l\fR'' and ``\fCunzip \-v\fR''
output. See
.B "DETAILED DESCRIPTION"
below. Note that \fIzipinfo\fP is the same program as \fIunzip\fP (under
Unix, a link to it); on some systems, however, \fIzipinfo\fP support may
have been omitted when \fIunzip\fP was compiled.
.PD
.\" =========================================================================
.SH ARGUMENTS
.TP
.IR file [ .zip ]
Path of the ZIP archive(s). If the file specification is a wildcard,
each matching file is processed in an order determined by the operating
system (or file system). Only the filename can be a wildcard; the path
itself cannot. Wildcard expressions are similar to Unix \fIegrep\fP(1)
(regular) expressions and may contain:
.RS
.IP *
matches a sequence of 0 or more characters
.IP ?
matches exactly 1 character
.IP [.\|.\|.]
matches any single character found inside the brackets; ranges are specified
by a beginning character, a hyphen, and an ending character. If an exclamation
point or a caret (`!' or `^') follows the left bracket, then the range of
characters within the brackets is complemented (that is, anything \fIexcept\fP
the characters inside the brackets is considered a match).
.RE
.IP
(Be sure to quote any character that might otherwise be interpreted or
modified by the operating system, particularly under Unix and VMS.) If no
matches are found, the specification is assumed to be a literal filename;
and if that also fails, the suffix \fC.zip\fR is appended. Note that
self-extracting ZIP files are supported; just specify the \fC.exe\fR suffix
(if any) explicitly.
.IP [\fIfile(s)\fP]
An optional list of archive members to be processed.
Regular expressions (wildcards) may be used to match multiple members; see
above. Again, be sure to quote expressions that would otherwise be expanded
or modified by the operating system.
.IP [\fB\-x\fP\ \fIxfile(s)\fP]
An optional list of archive members to be excluded from processing.
.\" =========================================================================
.SH OPTIONS
.TP
.B \-1
list filenames only, one per line. This option excludes all others; headers,
trailers and zipfile comments are never printed. It is intended for use in
Unix shell scripts.
.TP
.B \-2
list filenames only, one per line, but allow headers (\fB\-h\fP), trailers
(\fB\-t\fP) and zipfile comments (\fB\-z\fP), as well. This option may be
useful in cases where the stored filenames are particularly long.
.TP
.B \-s
list zipfile info in short Unix ``\fCls \-l\fR'' format. This is the default
behavior; see below.
.TP
.B \-m
list zipfile info in medium Unix ``\fCls \-l\fR'' format. Identical to the
\fB\-s\fP output, except that the compression factor, expressed as a
percentage, is also listed.
.TP
.B \-l
list zipfile info in long Unix ``\fCls \-l\fR'' format. As with \fB\-m\fP
except that the compressed size (in bytes) is printed instead of the
compression ratio.
.TP
.B \-v
list zipfile information in verbose, multi-page format.
.TP
.B \-h
list header line. The archive name, actual size (in bytes) and total number
of files is printed.
.TP
.B \-M
pipe all output through an internal pager similar to the Unix \fImore\fP(1)
command. At the end of a screenful of output, \fIzipinfo\fP pauses with a
``\-\-More\-\-'' prompt; the next screenful may be viewed by pressing the
Enter (Return) key or the space bar. \fIzipinfo\fP can be terminated by
pressing the ``q'' key and, on some systems, the Enter/Return key. Unlike
Unix \fImore\fP(1), there is no forward-searching or editing capability.
Also, \fIzipinfo\fP doesn't notice if long lines wrap at the edge of the
screen, effectively resulting in the printing of two or more lines and the
likelihood that some text will scroll off the top of the screen before being
viewed. On some systems the number of available lines on the screen is not
detected, in which case \fIzipinfo\fP assumes the height is 24 lines.
.TP
.B \-t
list totals for files listed or for all files. The number of files listed,
their uncompressed and compressed total sizes, and their overall compression
factor is printed; or, if only the totals line is being printed, the values
for the entire archive are given. Note that the total compressed (data)
size will never match the actual zipfile size, since the latter includes all
of the internal zipfile headers in addition to the compressed data.
.TP
.B \-T
print the file dates and times in a sortable decimal format (yymmdd.hhmmss).
The default date format is a more standard, human-readable version with
abbreviated month names (see examples below).
.TP
.B \-z
include the archive comment (if any) in the listing.
.PD
.\" =========================================================================
.SH "DETAILED DESCRIPTION"
.I zipinfo
has a number of modes, and its behavior can be rather difficult to fathom
if one isn't familiar with Unix \fIls\fP(1) (or even if one is). The default
behavior is to list files in the following format:
.PP
.X "-rw-rws--- 1.9 unx 2802 t- defX 11-Aug-91 13:48 perms.2660"
.PP
The last three fields are the modification date and time of
the file, and its name. The case of the filename is respected; thus
files that come from MS-DOS PKZIP are always capitalized. If the file
was zipped with a stored directory name, that is also displayed as part
of the filename.
.PP
The second and third fields indicate that the file was zipped under
Unix with version 1.9 of \fIzip\fP. Since it comes from Unix, the file
permissions at the beginning of the line are printed in Unix format.
The uncompressed file-size (2802 in this example) is the fourth field.
.PP
The fifth field consists of two characters, either of which may take
on several values. The first character may be either `t' or `b', indicating
that \fIzip\fP believes the file to be text or binary, respectively;
but if the file is encrypted, \fIzipinfo\fP
notes this fact by capitalizing the character (`T' or `B'). The second
character may also take on four values, depending on whether there is
an extended local header and/or an ``extra field'' associated with the
file (fully explained in PKWare's APPNOTE.TXT, but basically analogous to
pragmas in ANSI C--i.e., they provide a standard way to include non-standard
information in the archive). If neither exists, the character
will be a hyphen (`\-'); if there is an extended local header but no extra
field, `l'; if the reverse, `x'; and if both exist, `X'. Thus the
file in this example is (probably) a text file, is not encrypted, and
has neither an extra field nor an extended local header associated with it.
The example below, on the other hand, is an encrypted binary file with an
extra field:
.PP
.X "RWD,R,R 0.9 vms 168 Bx shrk 9-Aug-91 19:15 perms.0644"
.PP
Extra fields are used for various purposes (see discussion of the \fB\-v\fP
option below) including the storage of VMS file attributes, which is
presumably the case here. Note that the file attributes are listed in
VMS format. Some other possibilities for the host operating system (which
is actually a misnomer--host file system is more correct) include
OS/2 or NT with High Performance File System (HPFS), MS-DOS, OS/2 or NT
with File Allocation Table (FAT) file system, and Macintosh. These are
denoted as follows:
.PP
.X "-rw-a-- 1.0 hpf 5358 Tl i4:3 4-Dec-91 11:33 longfilename.hpfs"
.X "-r--ahs 1.1 fat 4096 b- i4:2 14-Jul-91 12:58 EA DATA. SF"
.X "--w------- 1.0 mac 17357 bx i8:2 4-May-92 04:02 unzip.macr"
.PP
File attributes in the first two cases are indicated in a Unix-like format,
where the seven subfields indicate whether the file: (1) is a directory,
(2) is readable (always true), (3) is writable, (4) is executable (guessed
on the basis of the extension--\fI.exe\fP, \fI.com\fP, \fI.bat\fP, \fI.cmd\fP
and \fI.btm\fP files are assumed to be so), (5) has its archive bit set,
(6) is hidden, and (7) is a system file. Interpretation of Macintosh file
attributes is unreliable because some Macintosh archivers don't store any
attributes in the archive.
.PP
Finally, the sixth field indicates
the compression method and possible sub-method used. There are six methods
known at present: storing (no compression), reducing, shrinking, imploding,
tokenizing (never publicly released), and deflating. In addition, there are
four levels of reducing (1 through 4); four types of imploding (4K or 8K
sliding dictionary, and 2 or 3 Shannon-Fano trees); and four levels of
deflating (superfast, fast, normal, maximum compression). \fIzipinfo\fP
represents these methods and their sub-methods as follows: \fIstor\fP;
\fIre:1\fP, \fIre:2\fP, etc.; \fIshrk\fP; \fIi4:2\fP, \fIi8:3\fP, etc.;
\fItokn\fP; and \fIdefS\fP, \fIdefF\fP, \fIdefN\fP, and \fIdefX\fP.
.PP
The medium and long listings are almost identical to the short format except
that they add information on the file's compression. The medium format lists
the file's compression factor as a percentage indicating the amount of space
that has been ``removed'':
.PP
.X "-rw-rws--- 1.5 unx 2802 t- 81% defX 11-Aug-91 13:48 perms.2660"
.PP
In this example, the file has been compressed by more than a factor of
five; the compressed data are only 19% of the original size. The long
format gives the compressed file's size in bytes, instead:
.PP
.X "-rw-rws--- 1.5 unx 2802 t- 538 defX 11-Aug-91 13:48 perms.2660"
.PP
Adding the \fB\-T\fP option changes the file date and time to decimal
format:
.PP
.X "-rw-rws--- 1.5 unx 2802 t- 538 defX 910811.134804 perms.2660"
.PP
Note that because of limitations in the MS-DOS format used to store file
times, the seconds field is always rounded to the nearest even second.
For Unix files this is expected to change in the next major releases of
\fIzip\fP(1L) and \fIunzip\fP.
.PP
In addition to individual file information, a default zipfile listing
also includes header and trailer lines:
.PP
.X "Archive: OS2.zip 5453 bytes 5 files"
.X ",,rw, 1.0 hpf 730 b- i4:3 26-Jun-92 23:40 Contents"
.X ",,rw, 1.0 hpf 3710 b- i4:3 26-Jun-92 23:33 makefile.os2"
.X ",,rw, 1.0 hpf 8753 b- i8:3 26-Jun-92 15:29 os2unzip.c"
.X ",,rw, 1.0 hpf 98 b- stor 21-Aug-91 15:34 unzip.def"
.X ",,rw, 1.0 hpf 95 b- stor 21-Aug-91 17:51 zipinfo.def"
.X "5 files, 13386 bytes uncompressed, 4951 bytes compressed: 63.0%"
.PP
The header line gives the name of the archive, its total size, and the
total number of files; the trailer gives the number of files listed,
their total uncompressed size, and their total compressed size (not
including any of \fIzip\fP's internal overhead). If, however, one or
more \fIfile(s)\fP are provided, the header and trailer lines are
not listed. This behavior is also similar to that of Unix's ``\fCls \-l\fR'';
it may be overridden by specifying the \fB\-h\fP and \fB\-t\fP options
explicitly.
In such a case the listing format must also be specified explicitly,
since \fB\-h\fP or \fB\-t\fP (or both) in the absence of other options implies
that ONLY the header or trailer line (or both) is listed. See the
\fBEXAMPLES\fP section below for a semi-intelligible translation of this
nonsense.
.PP
The verbose listing is mostly self-explanatory. It also lists file
comments and the zipfile comment, if any, and the type and number of bytes
in any stored extra fields. Currently known types of extra fields include
PKWARE's authentication (``AV'') info; OS/2 extended attributes; VMS
filesystem info, both PKWARE and Info-ZIP versions; Macintosh resource
forks; Acorn/Archimedes SparkFS info; and so on. (Note
that in the case of OS/2 extended attributes--perhaps the most common
use of zipfile extra fields--the size of the stored EAs as reported by
\fIzipinfo\fP may not match the number given by OS/2's \fIdir\fP command:
OS/2 always reports the number of bytes required in 16-bit format, whereas
\fIzipinfo\fP always reports the 32-bit storage.)
.PD
.\" =========================================================================
.SH "ENVIRONMENT OPTIONS"
Modifying \fIzipinfo\fP's default behavior via options placed in
an environment variable can be a bit complicated to explain, due to
\fIzipinfo\fP's attempts to handle various defaults in an intuitive,
yet Unix-like, manner. (Try not to laugh.) Nevertheless, there is some
underlying logic. In brief,
there are three ``priority levels'' of options: the default options;
environment options, which can override or add to the defaults; and
explicit options given by the user, which can override or add to
either of the above.
.PP
The default listing format, as noted above, corresponds roughly
to the "\fCzipinfo \-hst\fR" command (except when individual zipfile members
are specified).
A user who prefers the long-listing format (\fB\-l\fP) can make use of the
\fIzipinfo\fP's environment variable to change this default:
.TP
Unix Bourne shell:
\f(CW\&ZIPINFO=\-l; export ZIPINFO\fP
.TP
Unix C shell:
\f(CW\&setenv ZIPINFO \-l\fP
.TP
OS/2 or MS-DOS:
\f(CW\&set ZIPINFO=\-l\fP
.TP
VMS (quotes for \fIlowercase\fP):
\f(CW\&define ZIPINFO_OPTS "\-l"\fP
.EE
.PP
If, in addition, the user dislikes the trailer line, \fIzipinfo\fP's
concept of ``negative options'' may be used to override the default
inclusion of the line. This is accomplished by preceding the undesired
option with one or more minuses: e.g., ``\fC\-l\-t\fR'' or ``\fC\-\-tl\fR'',
in this example. The first hyphen is the regular switch character, but the
one before the `t' is a minus sign. The dual use of hyphens may seem a
little awkward, but it's reasonably intuitive nonetheless: simply ignore
the first hyphen and go from there. It is also consistent with the behavior
of the Unix command \fInice\fP(1).
.PP
As suggested above, the default variable names are ZIPINFO_OPTS for VMS
(where the symbol used to install \fIzipinfo\fP as a foreign command
would otherwise be confused with the environment variable), and ZIPINFO
for all other operating systems. For compatibility with \fIzip\fP(1L),
ZIPINFOOPT is also accepted (don't ask). If both ZIPINFO and ZIPINFOOPT
are defined, however, ZIPINFO takes precedence. \fIunzip\fP's diagnostic
option (\fB\-v\fP with no zipfile name) can be used to check the values
of all four possible \fIunzip\fP and \fIzipinfo\fP environment variables.
.PD
.\" =========================================================================
.SH EXAMPLES
To get a basic, short-format listing of the complete contents of a ZIP
archive \fIstorage.zip\fP, with both header and totals lines, use only
the archive name as an argument to zipinfo:
.PP
.EX
zipinfo storage
.EE
.PP
To produce a basic, long-format listing (not verbose), including header and
totals lines, use \fB\-l\fP:
.PP
.EX
zipinfo \-l storage
.EE
.PP
To list the complete contents of the archive without header and totals
lines, either negate the \fB\-h\fP and \fB\-t\fP options or else specify the
contents explicitly:
.PP
.EX
zipinfo \-\-h\-t storage
zipinfo storage \e*
.EE
.PP
(where the backslash is required only if the shell would otherwise expand
the `*' wildcard, as in Unix when globbing is turned on--double quotes around
the asterisk would have worked as well). To turn off the totals line by
default, use the environment variable (C shell is assumed here):
.PP
.EX
setenv ZIPINFO \-\-t
zipinfo storage
.EE
.PP
To get the full, short-format listing of the first example again, given
that the environment variable is set as in the previous example, it is
necessary to specify the \fB\-s\fP option explicitly, since the \fB\-t\fP
option by itself implies that ONLY the footer line is to be printed:
.PP
.EX
setenv ZIPINFO \-\-t
zipinfo \-t storage \fR[only totals line]\fP
zipinfo \-st storage \fR[full listing]\fP
.EE
.PP
The \fB\-s\fP option, like \fB\-m\fP and \fB\-l\fP, includes headers and
footers by default, unless otherwise specified. Since the environment
variable specified no footers and that has a higher precedence than the
default behavior of \fB\-s\fP, an explicit \fB\-t\fP option was necessary
to produce the full listing. Nothing was indicated about the header,
however, so the \fB\-s\fP option was sufficient. Note that both the
\fB\-h\fP and \fB\-t\fP options, when used by themselves or with
each other, override any default listing of member files; only the header
and/or footer are printed. This behavior is useful when \fIzipinfo\fP is
used with a wildcard zipfile specification; the contents of all zipfiles
are then summarized with a single command.
.PP
To list information on a single file within the archive, in medium format,
specify the filename explicitly:
.PP
.EX
zipinfo \-m storage unshrink.c
.EE
.PP
The specification of any member file, as in this example, will override
the default header and totals lines; only the single line of information
about the requested file will be printed. This is intuitively what one
would expect when requesting information about a single file. For multiple
files, it is often useful to know the total compressed and uncompressed
size; in such cases \fB\-t\fP may be specified explicitly:
.PP
.EX
zipinfo \-mt storage "*.[ch]" Mak\e*
.EE
.PP
To get maximal information about the ZIP archive, use the verbose
option. It is usually wise to pipe the output into a filter such as
Unix \fImore\fP(1) if the operating system allows it:
.PP
.EX
zipinfo \-v storage | more
.EE
.PP
Finally, to see the most recently modified files in the archive, use
the \fB\-T\fP option in conjunction with an external sorting utility
such as Unix \fIsort\fP(1) (and \fItail\fP(1) as well, in this example):
.PP
.EX
zipinfo \-T storage | sort -n +6 | tail -15
.EE
.PP
The \fB\-n\fP option to \fIsort\fP(1) tells it to sort numerically
rather than in ASCII order, and the \fB\+6\fP option tells it to sort
on the sixth field after the first one (i.e., the seventh field). This
assumes the default short-listing format; if \fB\-m\fP or \fB\-l\fP is
used, the proper \fIsort\fP(1) option would be \fB\+7\fP. The \fItail\fP(1)
command filters out all but the last 15 lines of the listing. Future
releases of \fIzipinfo\fP may incorporate date/time and filename sorting
as built-in options.
.PD
.\" =========================================================================
.SH TIPS
The author finds it convenient to define an alias \fIii\fP for \fIzipinfo\fP
on systems that allow aliases (or, on other systems, copy/rename the
executable, create a link or create a command file with the name \fIii\fP).
The \fIii\fP usage parallels the common \fIll\fP alias for long listings in
Unix, and the similarity between the outputs of the two commands was
intentional.
.PD
.\" =========================================================================
.SH BUGS
As with \fIunzip\fP, \fIzipinfo\fP's \fB\-M\fP (``more'') option is overly
simplistic in its handling of screen output; as noted above, it fails to detect
the wrapping of long lines and may thereby cause lines at the top of the screen
to be scrolled off before being read. \fIzipinfo\fP should detect and treat
each occurrence of line-wrap as one additional line printed. This requires
knowledge of the screen's width as well as its height. In addition,
\fIzipinfo\fP should detect the true screen geometry on all systems.
.PP
\fIzipinfo\fP's listing-format behavior is unnecessarily complex and should
be simplified. (This is not to say that it will be.)
.PP
.\" =========================================================================
.SH "SEE ALSO"
\fIls\fP(1), \fIfunzip\fP(1L), \fIunzip\fP(1L), \fIunzipsfx\fP(1L),
\fIzip\fP(1L), \fIzipcloak\fP(1L), \fIzipnote\fP(1L), \fIzipsplit\fP(1L)
.PD
.\" =========================================================================
.SH URL
The Info-ZIP home page is currently at
.EX
\fChttp://www.info-zip.org/pub/infozip/\fR
.EE
or
.EX
\fCftp://ftp.info-zip.org/pub/infozip/\fR .
.EE
.PD
.\" =========================================================================
.SH AUTHOR
Greg ``Cave Newt'' Roelofs. ZipInfo contains pattern-matching code
by Mark Adler and fixes/improvements by many others. Please refer to the
CONTRIBS file in the UnZip source distribution for a more complete list.

343
src/apps/bin/unzip/match.c Normal file
View File

@ -0,0 +1,343 @@
/*
Copyright (c) 1990-2002 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
*/
/*---------------------------------------------------------------------------
match.c
The match() routine recursively compares a string to a "pattern" (regular
expression), returning TRUE if a match is found or FALSE if not. This
version is specifically for use with unzip.c: as did the previous match()
routines from SEA and J. Kercheval, it leaves the case (upper, lower, or
mixed) of the string alone, but converts any uppercase characters in the
pattern to lowercase if indicated by the global var pInfo->lcflag (which
is to say, string is assumed to have been converted to lowercase already,
if such was necessary).
GRR: reversed order of text, pattern in matche() (now same as match());
added ignore_case/ic flags, Case() macro.
PaulK: replaced matche() with recmatch() from Zip, modified to have an
ignore_case argument; replaced test frame with simpler one.
---------------------------------------------------------------------------
Copyright on recmatch() from Zip's util.c (although recmatch() was almost
certainly written by Mark Adler...ask me how I can tell :-) ):
Copyright (C) 1990-1992 Mark Adler, Richard B. Wales, Jean-loup Gailly,
Kai Uwe Rommel and Igor Mandrichenko.
Permission is granted to any individual or institution to use, copy,
or redistribute this software so long as all of the original files are
included unmodified, that it is not sold for profit, and that this copy-
right notice is retained.
---------------------------------------------------------------------------
Match the pattern (wildcard) against the string (fixed):
match(string, pattern, ignore_case);
returns TRUE if string matches pattern, FALSE otherwise. In the pattern:
`*' matches any sequence of characters (zero or more)
`?' matches any single character
[SET] matches any character in the specified set,
[!SET] or [^SET] matches any character not in the specified set.
A set is composed of characters or ranges; a range looks like ``character
hyphen character'' (as in 0-9 or A-Z). [0-9a-zA-Z_] is the minimal set of
characters allowed in the [..] pattern construct. Other characters are
allowed (i.e., 8-bit characters) if your system will support them.
To suppress the special syntactic significance of any of ``[]*?!^-\'', in-
side or outside a [..] construct, and match the character exactly, precede
it with a ``\'' (backslash).
Note that "*.*" and "*." are treated specially under MS-DOS if DOSWILD is
defined. See the DOSWILD section below for an explanation. Note also
that with VMSWILD defined, '%' is used instead of '?', and sets (ranges)
are delimited by () instead of [].
---------------------------------------------------------------------------*/
#define __MATCH_C /* identifies this source module */
/* define ToLower() in here (for Unix, define ToLower to be macro (using
* isupper()); otherwise just use tolower() */
#define UNZIP_INTERNAL
#include "unzip.h"
#ifndef THEOS /* the Theos port defines its own variant of match() */
#if 0 /* this is not useful until it matches Amiga names insensitively */
#ifdef AMIGA /* some other platforms might also want to use this */
# define ANSI_CHARSET /* MOVE INTO UNZIP.H EVENTUALLY */
#endif
#endif /* 0 */
#ifdef ANSI_CHARSET
# ifdef ToLower
# undef ToLower
# endif
/* uppercase letters are values 41 thru 5A, C0 thru D6, and D8 thru DE */
# define IsUpper(c) (c>=0xC0 ? c<=0xDE && c!=0xD7 : c>=0x41 && c<=0x5A)
# define ToLower(c) (IsUpper((uch) c) ? (unsigned) c | 0x20 : (unsigned) c)
#endif
#define Case(x) (ic? ToLower(x) : (x))
#ifdef VMSWILD
# define WILDCHAR '%'
# define BEG_RANGE '('
# define END_RANGE ')'
#else
# define WILDCHAR '?'
# define BEG_RANGE '['
# define END_RANGE ']'
#endif
#if 0 /* GRR: add this to unzip.h someday... */
#if !(defined(MSDOS) && defined(DOSWILD))
#define match(s,p,ic) (recmatch((ZCONST uch *)p,(ZCONST uch *)s,ic) == 1)
int recmatch OF((ZCONST uch *pattern, ZCONST uch *string, int ignore_case));
#endif
#endif /* 0 */
static int recmatch OF((ZCONST uch *pattern, ZCONST uch *string,
int ignore_case));
/* match() is a shell to recmatch() to return only Boolean values. */
int match(string, pattern, ignore_case)
ZCONST char *string, *pattern;
int ignore_case;
{
#if (defined(MSDOS) && defined(DOSWILD))
char *dospattern;
int j = strlen(pattern);
/*---------------------------------------------------------------------------
Optional MS-DOS preprocessing section: compare last three chars of the
wildcard to "*.*" and translate to "*" if found; else compare the last
two characters to "*." and, if found, scan the non-wild string for dots.
If in the latter case a dot is found, return failure; else translate the
"*." to "*". In either case, continue with the normal (Unix-like) match
procedure after translation. (If not enough memory, default to normal
match.) This causes "a*.*" and "a*." to behave as MS-DOS users expect.
---------------------------------------------------------------------------*/
if ((dospattern = (char *)malloc(j+1)) != NULL) {
strcpy(dospattern, pattern);
if (!strcmp(dospattern+j-3, "*.*")) {
dospattern[j-2] = '\0'; /* nuke the ".*" */
} else if (!strcmp(dospattern+j-2, "*.")) {
char *p = MBSCHR(string, '.');
if (p) { /* found a dot: match fails */
free(dospattern);
return 0;
}
dospattern[j-1] = '\0'; /* nuke the end "." */
}
j = recmatch((uch *)dospattern, (uch *)string, ignore_case);
free(dospattern);
return j == 1;
} else
#endif /* MSDOS && DOSWILD */
return recmatch((uch *)pattern, (uch *)string, ignore_case) == 1;
}
static int recmatch(p, s, ic)
ZCONST uch *p; /* sh pattern to match */
ZCONST uch *s; /* string to which to match it */
int ic; /* true for case insensitivity */
/* Recursively compare the sh pattern p with the string s and return 1 if
* they match, and 0 or 2 if they don't or if there is a syntax error in the
* pattern. This routine recurses on itself no more deeply than the number
* of characters in the pattern. */
{
unsigned int c; /* pattern char or start of range in [-] loop */
/* Get first character, the pattern for new recmatch calls follows */
c = *p; INCSTR(p);
/* If that was the end of the pattern, match if string empty too */
if (c == 0)
return *s == 0;
/* '?' (or '%') matches any character (but not an empty string).
* If WILD_STOP_AT_DIR is defined, it won't match '/' */
if (c == WILDCHAR)
#ifdef WILD_STOP_AT_DIR
return (*s && *s != '/') ? recmatch(p, s + CLEN(s), ic) : 0;
#else
return *s ? recmatch(p, s + CLEN(s), ic) : 0;
#endif
/* '*' matches any number of characters, including zero */
#ifdef AMIGA
if (c == '#' && *p == '?') /* "#?" is Amiga-ese for "*" */
c = '*', p++;
#endif /* AMIGA */
if (c == '*') {
#ifdef WILD_STOP_AT_DIR
# ifdef AMIGA
if ((c = p[0]) == '#' && p[1] == '?') /* "#?" is Amiga-ese for "*" */
c = '*', p++;
if (c != '*') {
# else /* !AMIGA */
if (*p != '*') {
# endif /* ?AMIGA */
/* single '*': this doesn't match slashes */
for (; *s && *s != '/'; INCSTR(s))
if ((c = recmatch(p, s, ic)) != 0)
return (int)c;
/* end of pattern: matched if at end of string, else continue */
if (*p == 0)
return (*s == 0);
/* continue to match if at '/' in pattern, else give up */
return (*p == '/' || (*p == '\\' && p[1] == '/'))
? recmatch(p, s, ic) : 2;
}
/* '**': this matches slashes */
++p; /* move p behind the second '*' */
/* continue with the non-WILD_STOP_AT_DIR code variant */
#endif /* WILD_STOP_AT_DIR */
if (*p == 0)
return 1;
for (; *s; INCSTR(s))
if ((c = recmatch(p, s, ic)) != 0)
return (int)c;
return 2; /* 2 means give up--match will return false */
}
/* Parse and process the list of characters and ranges in brackets */
if (c == BEG_RANGE) {
int e; /* flag true if next char to be taken literally */
ZCONST uch *q; /* pointer to end of [-] group */
int r; /* flag true to match anything but the range */
if (*s == 0) /* need a character to match */
return 0;
p += (r = (*p == '!' || *p == '^')); /* see if reverse */
for (q = p, e = 0; *q; INCSTR(q)) /* find closing bracket */
if (e)
e = 0;
else
if (*q == '\\') /* GRR: change to ^ for MS-DOS, OS/2? */
e = 1;
else if (*q == END_RANGE)
break;
if (*q != END_RANGE) /* nothing matches if bad syntax */
return 0;
for (c = 0, e = (*p == '-'); p < q; INCSTR(p)) {
/* go through the list */
if (!e && *p == '\\') /* set escape flag if \ */
e = 1;
else if (!e && *p == '-') /* set start of range if - */
c = *(p-1);
else {
unsigned int cc = Case(*s);
if (*(p+1) != '-')
for (c = c ? c : *p; c <= *p; c++) /* compare range */
if ((unsigned)Case(c) == cc) /* typecast for MSC bug */
return r ? 0 : recmatch(q + 1, s + 1, ic);
c = e = 0; /* clear range, escape flags */
}
}
return r ? recmatch(q + CLEN(q), s + CLEN(s), ic) : 0;
/* bracket match failed */
}
/* if escape ('\'), just compare next character */
if (c == '\\' && (c = *p++) == 0) /* if \ at end, then syntax error */
return 0;
/* just a character--compare it */
#ifdef QDOS
return QMatch(Case((uch)c), Case(*s)) ? recmatch(p, s + CLEN(s), ic) : 0;
#else
return Case((uch)c) == Case(*s) ? recmatch(p, s + CLEN(s), ic) : 0;
#endif
} /* end function recmatch() */
#endif /* !THEOS */
int iswild(p) /* originally only used for stat()-bug workaround in */
ZCONST char *p; /* VAX C, Turbo/Borland C, Watcom C, Atari MiNT libs; */
{ /* now used in process_zipfiles() as well */
for (; *p; INCSTR(p))
if (*p == '\\' && *(p+1))
++p;
#ifdef THEOS
else if (*p == '?' || *p == '*' || *p=='#'|| *p == '@')
#else /* !THEOS */
#ifdef VMS
else if (*p == '%' || *p == '*')
#else /* !VMS */
#ifdef AMIGA
else if (*p == '?' || *p == '*' || (*p=='#' && p[1]=='?') || *p == '[')
#else /* !AMIGA */
else if (*p == '?' || *p == '*' || *p == '[')
#endif /* ?AMIGA */
#endif /* ?VMS */
#endif /* ?THEOS */
#ifdef QDOS
return (int)p;
#else
return TRUE;
#endif
return FALSE;
} /* end function iswild() */
#ifdef TEST_MATCH
#define put(s) {fputs(s,stdout); fflush(stdout);}
#ifdef main
# undef main
#endif
int main(int argc, char **argv)
{
char pat[256], str[256];
for (;;) {
put("Pattern (return to exit): ");
gets(pat);
if (!pat[0])
break;
for (;;) {
put("String (return for new pattern): ");
gets(str);
if (!str[0])
break;
printf("Case sensitive: %s insensitive: %s\n",
match(str, pat, 0) ? "YES" : "NO",
match(str, pat, 1) ? "YES" : "NO");
}
}
EXIT(0);
}
#endif /* TEST_MATCH */

1659
src/apps/bin/unzip/process.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,4 @@
/*
Quick hack so that I can compile unzipsfx without playing with Jam rules
*/
#define SFX

View File

@ -0,0 +1,89 @@
/*
Copyright (c) 1990-2000 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
*/
/*---------------------------------------------------------------------------
tables.h
This file contains only the 32-bit CRC table used in fUnZip;
it is in a separate file because it is rather big and ugly and
gets in the way during editing.
This file can be included in no more than ONE source file per
executable, of course.
---------------------------------------------------------------------------*/
#ifndef __tables_h /* prevent multiple inclusions */
#define __tables_h
#ifdef FUNZIP
#if (!defined(USE_ZLIB) || defined(USE_OWN_CRCTAB))
/* Table of CRC-32's of all single-byte values (made by makecrc.c) */
ZCONST ulg near crc_32_tab[256] = {
0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
0x2d02ef8dL
};
#else /* USE_ZLIB && !USE_OWN_CRCTAB */
ZCONST uLongf *crc_32_tab = NULL;
#endif /* ?(!USE_ZLIB || USE_OWN_CRCTAB) */
#endif /* FUNZIP */
#endif /* __tables_h */

View File

@ -0,0 +1,813 @@
/*
Copyright (c) 1990-2001 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2000-Apr-09 or later
(the contents of which are also included in zip.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
*/
/* Replacement time library functions, based on platform independent public
* domain timezone code from ftp://elsie.nci.nih.gov/pub, with mktime and
* mkgmtime from our own mktime.c in Zip.
*
* Contains: tzset()
* __tzset()
* gmtime()
* localtime()
* mktime()
* mkgmtime()
* GetPlatformLocalTimezone() [different versions]
*/
/* HISTORY/CHANGES
* 17 Jun 00, Paul Kienitz, added the PD-based tzset(), localtime(), and so on
* to amiga/filedate.c, replacing GNU-based functions which had
* replaced time_lib.c, both having been rejected for licensing
* reasons. Support for timezone files and leap seconds was removed.
*
* 23 Aug 00, Paul Kienitz, split into separate timezone.c file, made platform
* independent, copied in mktime() and mkgmtime() from Zip, renamed
* locale_TZ as GetPlatformLocalTimezone(), for use as a generic
* hook by other platforms.
*/
#ifndef __timezone_c
#define __timezone_c
#include "zip.h"
#include "timezone.h"
#include <ctype.h>
#include <errno.h>
#ifdef IZTZ_DEFINESTDGLOBALS
long timezone = 0;
int daylight = 0;
char *tzname[2];
#endif
#ifndef IZTZ_GETLOCALETZINFO
# define IZTZ_GETLOCALETZINFO(ptzstruct, pgenrulefunct) (FALSE)
#endif
int real_timezone_is_set = FALSE; /* set by tzset() */
#define TZDEFRULESTRING ",M4.1.0,M10.5.0"
#define TZDEFAULT "EST5EDT"
#define SECSPERMIN 60
#define MINSPERHOUR 60
#define HOURSPERDAY 24
#define DAYSPERWEEK 7
#define DAYSPERNYEAR 365
#define DAYSPERLYEAR 366
#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)
#define SECSPERDAY ((long) SECSPERHOUR * HOURSPERDAY)
#define MONSPERYEAR 12
#define EPOCH_WDAY 4 /* Jan 1, 1970 was thursday */
#define EPOCH_YEAR 1970
#define TM_YEAR_BASE 1900
#define FIRST_GOOD_YEAR ((time_t) -1 < (time_t) 1 ? EPOCH_YEAR-68 : EPOCH_YEAR)
#define LAST_GOOD_YEAR (EPOCH_YEAR + ((time_t) -1 < (time_t) 1 ? 67 : 135))
#define YDAYS(month, year) yr_days[leap(year)][month]
/* Nonzero if `y' is a leap year, else zero. */
#define leap(y) (((y) % 4 == 0 && (y) % 100 != 0) || (y) % 400 == 0)
/* Number of leap years from EPOCH_YEAR to `y' (not including `y' itself). */
#define _P4 ((EPOCH_YEAR / 4) * 4 + 1)
#define _P100 ((EPOCH_YEAR / 100) * 100 + 1)
#define _P400 ((EPOCH_YEAR / 400) * 400 + 1)
#define nleap(y) (((y) - _P4) / 4 - ((y) - _P100) / 100 + ((y) - _P400) / 400)
/* Length of month `m' (0 .. 11) */
#define monthlen(m, y) (yr_days[0][(m)+1] - yr_days[0][m] + \
((m) == 1 && leap(y)))
/* internal module-level constants */
#ifndef IZ_MKTIME_ONLY
static ZCONST char gmt[] = "GMT";
static ZCONST int mon_lengths[2][MONSPERYEAR] = {
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
};
#endif /* !IZ_MKTIME_ONLY */
static ZCONST int yr_days[2][MONSPERYEAR+1] = {
{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
{ 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
};
#ifndef IZ_MKTIME_ONLY
static ZCONST int year_lengths[2] = {
DAYSPERNYEAR, DAYSPERLYEAR
};
/* internal variables */
static struct state statism;
/* prototypes of static functions */
static time_t transtime OF((ZCONST time_t janfirst, ZCONST int year,
ZCONST struct rule * ZCONST rulep,
ZCONST long offset));
static void generate_transitions OF((register struct state * ZCONST sp,
ZCONST struct rule * ZCONST start,
ZCONST struct rule * ZCONST end));
static ZCONST char *getzname OF((ZCONST char *strp));
static ZCONST char *getnum OF((ZCONST char *strp, int * ZCONST nump,
ZCONST int min, ZCONST int max));
static ZCONST char *getsecs OF((ZCONST char *strp, long * ZCONST secsp));
static ZCONST char *getoffset OF((ZCONST char *strp, long * ZCONST offsetp));
static ZCONST char *getrule OF((ZCONST char *strp, struct rule * ZCONST rulep));
static int Parse_TZ OF((ZCONST char *name, register struct state * ZCONST sp));
static time_t transtime(janfirst, year, rulep, offset)
ZCONST time_t janfirst;
ZCONST int year;
ZCONST struct rule * ZCONST rulep;
ZCONST long offset;
{
register int leapyear;
register time_t value;
register int i;
int d, m1, yy0, yy1, yy2, dow;
value = 0;
leapyear = leap(year);
switch (rulep->r_type) {
case JULIAN_DAY:
/*
** Jn - Julian day, 1 == January 1, 60 == March 1 even in leap
** years.
** In non-leap years, or if the day number is 59 or less, just
** add SECSPERDAY times the day number-1 to the time of
** January 1, midnight, to get the day.
*/
value = janfirst + (rulep->r_day - 1) * SECSPERDAY;
if (leapyear && rulep->r_day >= 60)
value += SECSPERDAY;
break;
case DAY_OF_YEAR:
/*
** n - day of year.
** Just add SECSPERDAY times the day number to the time of
** January 1, midnight, to get the day.
*/
value = janfirst + rulep->r_day * SECSPERDAY;
break;
case MONTH_NTH_DAY_OF_WEEK:
/*
** Mm.n.d - nth "dth day" of month m.
*/
value = janfirst;
/*
for (i = 0; i < rulep->r_mon - 1; ++i)
value += mon_lengths[leapyear][i] * SECSPERDAY;
*/
value += yr_days[leapyear][rulep->r_mon - 1] * SECSPERDAY;
/*
** Use Zeller's Congruence to get day-of-week of first day of
** month.
*/
m1 = (rulep->r_mon + 9) % 12 + 1;
yy0 = (rulep->r_mon <= 2) ? (year - 1) : year;
yy1 = yy0 / 100;
yy2 = yy0 % 100;
dow = ((26 * m1 - 2) / 10 +
1 + yy2 + yy2 / 4 + yy1 / 4 - 2 * yy1) % 7;
if (dow < 0)
dow += DAYSPERWEEK;
/*
** "dow" is the day-of-week of the first day of the month. Get
** the day-of-month (zero-origin) of the first "dow" day of the
** month.
*/
d = rulep->r_day - dow;
if (d < 0)
d += DAYSPERWEEK;
for (i = 1; i < rulep->r_week; ++i) {
if (d + DAYSPERWEEK >= mon_lengths[leapyear][rulep->r_mon - 1])
break;
d += DAYSPERWEEK;
}
/*
** "d" is the day-of-month (zero-origin) of the day we want.
*/
value += d * SECSPERDAY;
break;
}
/*
** "value" is the Epoch-relative time of 00:00:00 UTC on the day in
** question. To get the Epoch-relative time of the specified local
** time on that day, add the transition time and the current offset
** from UTC.
*/
return value + rulep->r_time + offset;
}
static void generate_transitions(sp, start, end)
register struct state * ZCONST sp;
ZCONST struct rule * ZCONST start;
ZCONST struct rule * ZCONST end;
{
register int year;
register time_t janfirst;
time_t starttime;
time_t endtime;
long stdoffset = -sp->ttis[0].tt_gmtoff;
long dstoffset = -sp->ttis[1].tt_gmtoff;
register time_t * atp;
register unsigned char * typep;
/*
** Two transitions per year, from EPOCH_YEAR to LAST_GOOD_YEAR.
*/
sp->timecnt = 2 * (LAST_GOOD_YEAR - EPOCH_YEAR + 1);
atp = sp->ats;
typep = sp->types;
janfirst = 0;
for (year = EPOCH_YEAR; year <= LAST_GOOD_YEAR; ++year) {
starttime = transtime(janfirst, year, start, stdoffset);
endtime = transtime(janfirst, year, end, dstoffset);
if (starttime > endtime) {
*atp++ = endtime;
*typep++ = 0; /* DST ends */
*atp++ = starttime;
*typep++ = 1; /* DST begins */
} else {
*atp++ = starttime;
*typep++ = 1; /* DST begins */
*atp++ = endtime;
*typep++ = 0; /* DST ends */
}
janfirst += year_lengths[leap(year)] * SECSPERDAY;
}
}
static ZCONST char *getzname(strp)
ZCONST char *strp;
{
register char c;
while ((c = *strp) != '\0' && !isdigit(c) && c != ',' && c != '-' &&
c != '+')
++strp;
return strp;
}
static ZCONST char *getnum(strp, nump, min, max)
ZCONST char *strp;
int * ZCONST nump;
ZCONST int min;
ZCONST int max;
{
register char c;
register int num;
if (strp == NULL || !isdigit(c = *strp))
return NULL;
num = 0;
do {
num = num * 10 + (c - '0');
if (num > max)
return NULL; /* illegal value */
c = *++strp;
} while (isdigit(c));
if (num < min)
return NULL; /* illegal value */
*nump = num;
return strp;
}
static ZCONST char *getsecs(strp, secsp)
ZCONST char *strp;
long * ZCONST secsp;
{
int num;
/*
** `HOURSPERDAY * DAYSPERWEEK - 1' allows quasi-Posix rules like
** "M10.4.6/26", which does not conform to Posix,
** but which specifies the equivalent of
** ``02:00 on the first Sunday on or after 23 Oct''.
*/
strp = getnum(strp, &num, 0, HOURSPERDAY * DAYSPERWEEK - 1);
if (strp == NULL)
return NULL;
*secsp = num * (long) SECSPERHOUR;
if (*strp == ':') {
++strp;
strp = getnum(strp, &num, 0, MINSPERHOUR - 1);
if (strp == NULL)
return NULL;
*secsp += num * SECSPERMIN;
if (*strp == ':') {
++strp;
/* `SECSPERMIN' allows for leap seconds. */
strp = getnum(strp, &num, 0, SECSPERMIN);
if (strp == NULL)
return NULL;
*secsp += num;
}
}
return strp;
}
static ZCONST char *getoffset(strp, offsetp)
ZCONST char *strp;
long * ZCONST offsetp;
{
register int neg = 0;
if (*strp == '-') {
neg = 1;
++strp;
} else if (*strp == '+')
++strp;
strp = getsecs(strp, offsetp);
if (strp == NULL)
return NULL; /* illegal time */
if (neg)
*offsetp = -*offsetp;
return strp;
}
static ZCONST char *getrule(strp, rulep)
ZCONST char *strp;
struct rule * ZCONST rulep;
{
if (*strp == 'J') {
/*
** Julian day.
*/
rulep->r_type = JULIAN_DAY;
++strp;
strp = getnum(strp, &rulep->r_day, 1, DAYSPERNYEAR);
} else if (*strp == 'M') {
/*
** Month, week, day.
*/
rulep->r_type = MONTH_NTH_DAY_OF_WEEK;
++strp;
strp = getnum(strp, &rulep->r_mon, 1, MONSPERYEAR);
if (strp == NULL)
return NULL;
if (*strp++ != '.')
return NULL;
strp = getnum(strp, &rulep->r_week, 1, 5);
if (strp == NULL)
return NULL;
if (*strp++ != '.')
return NULL;
strp = getnum(strp, &rulep->r_day, 0, DAYSPERWEEK - 1);
} else if (isdigit(*strp)) {
/*
** Day of year.
*/
rulep->r_type = DAY_OF_YEAR;
strp = getnum(strp, &rulep->r_day, 0, DAYSPERLYEAR - 1);
} else return NULL; /* invalid format */
if (strp == NULL)
return NULL;
if (*strp == '/') {
/*
** Time specified.
*/
++strp;
strp = getsecs(strp, &rulep->r_time);
} else
rulep->r_time = 2 * SECSPERHOUR; /* default = 2:00:00 */
return strp;
}
static int Parse_TZ(name, sp)
ZCONST char *name;
register struct state * ZCONST sp;
{
ZCONST char * stdname;
ZCONST char * dstname;
size_t stdlen;
size_t dstlen;
long stdoffset;
long dstoffset;
register char * cp;
dstname = NULL;
stdname = name;
name = getzname(name);
stdlen = name - stdname;
if (stdlen < 3)
return -1;
if (*name == '\0')
return -1;
name = getoffset(name, &stdoffset);
if (name == NULL)
return -1;
if (*name != '\0') {
dstname = name;
name = getzname(name);
dstlen = name - dstname; /* length of DST zone name */
if (dstlen < 3)
return -1;
if (*name != '\0' && *name != ',' && *name != ';') {
name = getoffset(name, &dstoffset);
if (name == NULL)
return -1;
} else
dstoffset = stdoffset - SECSPERHOUR;
if (*name == '\0')
name = TZDEFRULESTRING;
if (*name == ',' || *name == ';') {
struct rule start;
struct rule end;
++name;
if ((name = getrule(name, &start)) == NULL)
return -1;
if (*name++ != ',')
return -1;
if ((name = getrule(name, &end)) == NULL)
return -1;
if (*name != '\0')
return -1;
sp->typecnt = 2; /* standard time and DST */
sp->ttis[0].tt_gmtoff = -stdoffset;
sp->ttis[0].tt_isdst = 0;
sp->ttis[0].tt_abbrind = 0;
sp->ttis[1].tt_gmtoff = -dstoffset;
sp->ttis[1].tt_isdst = 1;
sp->ttis[1].tt_abbrind = stdlen + 1;
generate_transitions(sp, &start, &end);
}
} else {
dstlen = 0;
sp->typecnt = 1; /* only standard time */
sp->timecnt = 0;
sp->ttis[0].tt_gmtoff = -stdoffset;
sp->ttis[0].tt_isdst = 0;
sp->ttis[0].tt_abbrind = 0;
}
sp->charcnt = stdlen + 1;
if (dstlen != 0)
sp->charcnt += dstlen + 1;
if ((size_t) sp->charcnt > sizeof(sp->chars))
return -1;
cp = sp->chars;
(void) strncpy(cp, stdname, stdlen);
cp += stdlen;
*cp++ = '\0';
if (dstlen != 0) {
(void) strncpy(cp, dstname, dstlen);
*(cp + dstlen) = '\0';
}
return 0;
}
void tzset()
{
char *TZstring;
int dstfirst;
static char *old_TZstring = NULL;
TZstring = getenv("TZ"); /* read TZ envvar */
if (old_TZstring && TZstring && !strcmp(old_TZstring, TZstring))
/* do not repeatedly parse an unchanged TZ specification */
return;
if ((TZstring && TZstring[0] && Parse_TZ(TZstring, &statism) == 0)
|| IZTZ_GETLOCALETZINFO(&statism, generate_transitions)
|| Parse_TZ(gmt, &statism) == 0) {
daylight = statism.typecnt > 1;
dstfirst = daylight && statism.ttis[0].tt_isdst && !statism.ttis[1].tt_isdst;
timezone = -statism.ttis[dstfirst].tt_gmtoff;
tzname[0] = statism.chars + statism.ttis[dstfirst].tt_abbrind;
tzname[1] = statism.chars + statism.ttis[!dstfirst].tt_abbrind;
real_timezone_is_set = TRUE;
if (TZstring) {
if (old_TZstring)
old_TZstring = realloc(old_TZstring, strlen(TZstring) + 1);
else
old_TZstring = malloc(strlen(TZstring) + 1);
if (old_TZstring)
strcpy(old_TZstring, TZstring);
}
} else {
timezone = 0; /* default is GMT0 which means no offsets */
daylight = 0; /* from local system time */
real_timezone_is_set = FALSE;
if (old_TZstring) {
free(old_TZstring);
old_TZstring = NULL;
}
}
#ifdef IZTZ_SETLOCALTZINFO
/* Some SAS/C library functions, e.g. stat(), call library */
/* __tzset() themselves. So envvar TZ *must* exist in order to */
/* to get the right offset from GMT. XXX TRY HARD to fix this! */
set_TZ(timezone, daylight);
#endif /* IZTZ_SETLOCALTZINFO */
}
/* XXX Does this also help SAS/C library work? */
void __tzset()
{
if (!real_timezone_is_set) tzset();
}
static struct tm _tmbuf;
struct tm *gmtime(when)
ZCONST time_t *when;
{
long days = *when / SECSPERDAY;
long secs = *when % SECSPERDAY;
int isleap;
memset(&_tmbuf, 0, sizeof(_tmbuf)); /* get any nonstandard fields */
_tmbuf.tm_wday = (days + EPOCH_WDAY) % 7;
_tmbuf.tm_year = EPOCH_YEAR - TM_YEAR_BASE;
isleap = leap(_tmbuf.tm_year + TM_YEAR_BASE);
while (days >= year_lengths[isleap]) {
days -= year_lengths[isleap];
_tmbuf.tm_year++;
isleap = leap(_tmbuf.tm_year + TM_YEAR_BASE);
}
_tmbuf.tm_mon = 0;
_tmbuf.tm_yday = days;
while (days >= mon_lengths[isleap][_tmbuf.tm_mon])
days -= mon_lengths[isleap][_tmbuf.tm_mon++];
_tmbuf.tm_mday = days + 1;
_tmbuf.tm_isdst = 0;
_tmbuf.tm_sec = secs % SECSPERMIN;
_tmbuf.tm_min = (secs / SECSPERMIN) % SECSPERMIN;
_tmbuf.tm_hour = secs / SECSPERHOUR;
return &_tmbuf;
}
struct tm *localtime(when)
ZCONST time_t *when;
{
time_t localwhen = *when;
int timetype;
struct tm *ret;
__tzset();
if (statism.timecnt == 0 || localwhen < statism.ats[0])
timetype = statism.ttis[0].tt_isdst && statism.typecnt > 1 &&
!statism.ttis[1].tt_isdst;
else {
for (timetype = 1; timetype < statism.timecnt; ++timetype)
if (localwhen < statism.ats[timetype])
break;
timetype = statism.types[timetype - 1];
}
localwhen += statism.ttis[timetype].tt_gmtoff;
ret = gmtime(&localwhen);
ret->tm_isdst = statism.ttis[timetype].tt_isdst;
return ret;
}
#ifdef NEED__ISINDST
int _isindst(tb)
struct tm *tb;
{
time_t localt; /* time_t equivalent of given tm struct */
time_t univt; /* assumed UTC value of given time */
long tzoffset_adj; /* timezone-adjustment `remainder' */
int bailout_cnt; /* counter of tries for tz correction */
int timetype;
__tzset();
/* when DST is unsupported in current timezone, DST is always off */
if (statism.typecnt <= 1) return FALSE;
localt = mkgmtime(tb);
if (localt == (time_t)-1)
/* specified time is out-of-range, default to FALSE */
return FALSE;
univt = localt - statism.ttis[0].tt_gmtoff;
bailout_cnt = 3;
do {
if (statism.timecnt == 0 || univt < statism.ats[0])
timetype = statism.ttis[0].tt_isdst && statism.typecnt > 1 &&
!statism.ttis[1].tt_isdst;
else {
for (timetype = 1; timetype < statism.timecnt; ++timetype)
if (univt < statism.ats[timetype])
break;
timetype = statism.types[timetype - 1];
}
if ((tzoffset_adj = localt - univt - statism.ttis[timetype].tt_gmtoff)
== 0L)
break;
univt += tzoffset_adj;
} while (--bailout_cnt > 0);
/* return TRUE when DST is active at given time */
return (statism.ttis[timetype].tt_isdst);
}
#endif /* NEED__ISINDST */
#endif /* !IZ_MKTIME_ONLY */
/* Return the equivalent in seconds past 12:00:00 a.m. Jan 1, 1970 GMT
of the local time and date in the exploded time structure `tm',
adjust out of range fields in `tm' and set `tm->tm_yday', `tm->tm_wday'.
If `tm->tm_isdst < 0' was passed to mktime(), the correct setting of
tm_isdst is determined and returned. Otherwise, mktime() assumes this
field as valid; its information is used when converting local time
to UTC.
Return -1 if time in `tm' cannot be represented as time_t value. */
time_t mktime(tm)
struct tm *tm;
{
struct tm *ltm; /* Local time. */
time_t loctime; /* The time_t value of local time. */
time_t then; /* The time to return. */
long tzoffset_adj; /* timezone-adjustment `remainder' */
int bailout_cnt; /* counter of tries for tz correction */
int save_isdst; /* Copy of the tm->isdst input value */
save_isdst = tm->tm_isdst;
loctime = mkgmtime(tm);
if (loctime == -1) {
tm->tm_isdst = save_isdst;
return (time_t)-1;
}
/* Correct for the timezone and any daylight savings time.
The correction is verified and repeated when not correct, to
take into account the rare case that a change to or from daylight
savings time occurs between when it is the time in `tm' locally
and when it is that time in Greenwich. After the second correction,
the "timezone & daylight" offset should be correct in all cases. To
be sure, we allow a third try, but then the loop is stopped. */
bailout_cnt = 3;
then = loctime;
do {
ltm = localtime(&then);
if (ltm == (struct tm *)NULL ||
(tzoffset_adj = loctime - mkgmtime(ltm)) == 0L)
break;
then += tzoffset_adj;
} while (--bailout_cnt > 0);
if (ltm == (struct tm *)NULL || tzoffset_adj != 0L) {
/* Signal failure if timezone adjustment did not converge. */
tm->tm_isdst = save_isdst;
return (time_t)-1;
}
if (save_isdst >= 0) {
if (ltm->tm_isdst && !save_isdst)
{
if (then + 3600 < then)
then = (time_t)-1;
else
then += 3600;
}
else if (!ltm->tm_isdst && save_isdst)
{
if (then - 3600 > then)
then = (time_t)-1;
else
then -= 3600;
}
ltm->tm_isdst = save_isdst;
}
if (tm != ltm) /* `tm' may already point to localtime's internal storage */
*tm = *ltm;
return then;
}
#ifndef NO_TIME_T_MAX
/* Provide default values for the upper limit of the time_t range.
These are the result of the decomposition into a `struct tm' for
the time value 0xFFFFFFFEL ( = (time_t)-2 ).
Note: `(time_t)-1' is reserved for "invalid time"! */
# ifndef TM_YEAR_MAX
# define TM_YEAR_MAX 2106
# endif
# ifndef TM_MON_MAX
# define TM_MON_MAX 1 /* February */
# endif
# ifndef TM_MDAY_MAX
# define TM_MDAY_MAX 7
# endif
# ifndef TM_HOUR_MAX
# define TM_HOUR_MAX 6
# endif
# ifndef TM_MIN_MAX
# define TM_MIN_MAX 28
# endif
# ifndef TM_SEC_MAX
# define TM_SEC_MAX 14
# endif
#endif /* NO_TIME_T_MAX */
/* Adjusts out-of-range values for `tm' field `tm_member'. */
#define ADJUST_TM(tm_member, tm_carry, modulus) \
if ((tm_member) < 0) { \
tm_carry -= (1 - ((tm_member)+1) / (modulus)); \
tm_member = (modulus-1) + (((tm_member)+1) % (modulus)); \
} else if ((tm_member) >= (modulus)) { \
tm_carry += (tm_member) / (modulus); \
tm_member = (tm_member) % (modulus); \
}
/* Return the equivalent in seconds past 12:00:00 a.m. Jan 1, 1970 GMT
of the Greenwich Mean time and date in the exploded time structure `tm'.
This function does always put back normalized values into the `tm' struct,
parameter, including the calculated numbers for `tm->tm_yday',
`tm->tm_wday', and `tm->tm_isdst'.
Returns -1 if the time in the `tm' parameter cannot be represented
as valid `time_t' number. */
time_t mkgmtime(tm)
struct tm *tm;
{
int years, months, days, hours, minutes, seconds;
years = tm->tm_year + TM_YEAR_BASE; /* year - 1900 -> year */
months = tm->tm_mon; /* 0..11 */
days = tm->tm_mday - 1; /* 1..31 -> 0..30 */
hours = tm->tm_hour; /* 0..23 */
minutes = tm->tm_min; /* 0..59 */
seconds = tm->tm_sec; /* 0..61 in ANSI C. */
ADJUST_TM(seconds, minutes, 60)
ADJUST_TM(minutes, hours, 60)
ADJUST_TM(hours, days, 24)
ADJUST_TM(months, years, 12)
if (days < 0)
do {
if (--months < 0) {
--years;
months = 11;
}
days += monthlen(months, years);
} while (days < 0);
else
while (days >= monthlen(months, years)) {
days -= monthlen(months, years);
if (++months >= 12) {
++years;
months = 0;
}
}
/* Restore adjusted values in tm structure */
tm->tm_year = years - TM_YEAR_BASE;
tm->tm_mon = months;
tm->tm_mday = days + 1;
tm->tm_hour = hours;
tm->tm_min = minutes;
tm->tm_sec = seconds;
/* Set `days' to the number of days into the year. */
days += YDAYS(months, years);
tm->tm_yday = days;
/* Now calculate `days' to the number of days since Jan 1, 1970. */
days = (unsigned)days + 365 * (unsigned)(years - EPOCH_YEAR) +
(unsigned)(nleap (years));
tm->tm_wday = ((unsigned)days + EPOCH_WDAY) % 7;
tm->tm_isdst = 0;
if (years < EPOCH_YEAR)
return (time_t)-1;
#if (defined(TM_YEAR_MAX) && defined(TM_MON_MAX) && defined(TM_MDAY_MAX))
#if (defined(TM_HOUR_MAX) && defined(TM_MIN_MAX) && defined(TM_SEC_MAX))
if (years > TM_YEAR_MAX ||
(years == TM_YEAR_MAX &&
(tm->tm_yday > (YDAYS(TM_MON_MAX, TM_YEAR_MAX) + (TM_MDAY_MAX - 1)) ||
(tm->tm_yday == (YDAYS(TM_MON_MAX, TM_YEAR_MAX) + (TM_MDAY_MAX - 1)) &&
(hours > TM_HOUR_MAX ||
(hours == TM_HOUR_MAX &&
(minutes > TM_MIN_MAX ||
(minutes == TM_MIN_MAX && seconds > TM_SEC_MAX) )))))))
return (time_t)-1;
#endif
#endif
return (time_t)(SECSPERDAY * (unsigned long)(unsigned)days +
SECSPERHOUR * (unsigned long)hours +
(unsigned long)(SECSPERMIN * minutes + seconds));
}
#endif /* __timezone_c */

View File

@ -0,0 +1,81 @@
/*
Copyright (c) 1990-2001 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2000-Apr-09 or later
(the contents of which are also included in zip.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
*/
#ifndef __timezone_h
#define __timezone_h
#ifndef IZ_MKTIME_ONLY
/* limits for our timezone info data:
* we support only basic standard and daylight time, with max 2 transitions
* per year, but for the maximum range of years a 32-bit second counter
* can cover (these are 136 years plus a bit more than one month)
*/
#define TZ_MAX_TIMES 272 /* (=2*(LastGoodYr + 1 - FirstGoodYr) */
#define TZ_MAX_TYPES 2 /* We only support basic standard and daylight */
#ifdef WIN32 /* Win32 tzinfo supplies at max (2 * 32) chars of tz names */
#define TZ_MAX_CHARS 64 /* Maximum number of abbreviation characters */
#else
#define TZ_MAX_CHARS 50 /* Maximum number of abbreviation characters */
#endif
/* supported types of transition rules */
#define JULIAN_DAY 0 /* Jn - Julian day */
#define DAY_OF_YEAR 1 /* n - day of year */
#define MONTH_NTH_DAY_OF_WEEK 2 /* Mm.n.d - month, week, day of week */
struct ttinfo {
long tt_gmtoff; /* UTC offset in seconds */
int tt_isdst; /* used to set tm_isdst */
int tt_abbrind; /* abbreviation list index */
};
struct state {
int timecnt;
int typecnt;
int charcnt;
time_t ats[TZ_MAX_TIMES];
unsigned char types[TZ_MAX_TIMES];
struct ttinfo ttis[TZ_MAX_TYPES];
char chars[TZ_MAX_CHARS];
};
struct rule {
int r_type; /* type of rule--JULIAN_DAY etc */
int r_day; /* day number of rule */
int r_week; /* week number of rule */
int r_mon; /* month number of rule */
long r_time; /* transition time of rule */
};
extern int real_timezone_is_set; /* set by tzset() */
/* prototypes of functions not in time.h */
void __tzset OF((void));
#ifdef NEED__ISINDST
int _isindst OF((struct tm *tb));
#endif
/* callback function to be supplied by the program that uses this library */
int GetPlatformLocalTimezone OF((register struct state * ZCONST sp,
void (*fill_tzstate_from_rules)(struct state * ZCONST sp_res,
ZCONST struct rule * ZCONST start,
ZCONST struct rule * ZCONST end)));
#ifdef IZTZ_SETLOCALTZINFO
void set_TZ OF((long time_zone, int day_light));
#endif
#endif /* !IZ_MKTIME_ONLY */
time_t mkgmtime OF((struct tm *tm));
#endif

700
src/apps/bin/unzip/ttyio.c Normal file
View File

@ -0,0 +1,700 @@
/*
Copyright (c) 1990-2001 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2000-Apr-09 or later
(the contents of which are also included in zip.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
*/
/*---------------------------------------------------------------------------
ttyio.c
This file contains routines for doing console input/output, including code
for non-echoing input. It is used by the encryption/decryption code but
does not contain any restricted code itself. This file is shared between
Info-ZIP's Zip and UnZip.
Contains: echo() (VMS only)
Echon() (Unix only)
Echoff() (Unix only)
screensize() (Unix only)
zgetch() (Unix, VMS, and non-Unix/VMS versions)
getp() ("PC," Unix/Atari/Be, VMS/VMCMS/MVS)
---------------------------------------------------------------------------*/
#define __TTYIO_C /* identifies this source module */
#include "zip.h"
#include "crypt.h"
#if (CRYPT || (defined(UNZIP) && !defined(FUNZIP)))
/* Non-echo console/keyboard input is needed for (en/de)cryption's password
* entry, and for UnZip(SFX)'s MORE and Pause features.
* (The corresponding #endif is found at the end of this module.)
*/
#include "ttyio.h"
#ifndef PUTC
# define PUTC putc
#endif
#ifdef ZIP
# ifdef GLOBAL /* used in Amiga system headers, maybe others too */
# undef GLOBAL
# endif
# define GLOBAL(g) g
#else
# define GLOBAL(g) G.g
#endif
#ifdef __BEOS__ /* why yes, we do */
# define HAVE_TERMIOS_H
#endif
#ifdef _POSIX_VERSION
# ifndef USE_POSIX_TERMIOS
# define USE_POSIX_TERMIOS /* use POSIX style termio (termios) */
# endif
# ifndef HAVE_TERMIOS_H
# define HAVE_TERMIOS_H /* POSIX termios.h */
# endif
#endif /* _POSIX_VERSION */
#ifdef UNZIP /* Zip handles this with the unix/configure script */
# ifndef _POSIX_VERSION
# if (defined(SYSV) || defined(CRAY)) && !defined(__MINT__)
# ifndef USE_SYSV_TERMIO
# define USE_SYSV_TERMIO
# endif
# ifdef COHERENT
# ifndef HAVE_TERMIO_H
# define HAVE_TERMIO_H
# endif
# ifdef HAVE_SYS_TERMIO_H
# undef HAVE_SYS_TERMIO_H
# endif
# else /* !COHERENT */
# ifdef HAVE_TERMIO_H
# undef HAVE_TERMIO_H
# endif
# ifndef HAVE_SYS_TERMIO_H
# define HAVE_SYS_TERMIO_H
# endif
# endif /* ?COHERENT */
# endif /* (SYSV || CRAY) && !__MINT__ */
# endif /* !_POSIX_VERSION */
# if !(defined(BSD4_4) || defined(SYSV) || defined(__convexc__))
# ifndef NO_FCNTL_H
# define NO_FCNTL_H
# endif
# endif /* !(BSD4_4 || SYSV || __convexc__) */
#endif /* UNZIP */
#ifdef HAVE_TERMIOS_H
# ifndef USE_POSIX_TERMIOS
# define USE_POSIX_TERMIOS
# endif
#endif
#if (defined(HAVE_TERMIO_H) || defined(HAVE_SYS_TERMIO_H))
# ifndef USE_SYSV_TERMIO
# define USE_SYSV_TERMIO
# endif
#endif
#if (defined(UNZIP) && !defined(FUNZIP) && defined(UNIX) && defined(MORE))
# include <sys/ioctl.h>
# define GOT_IOCTL_H
/* int ioctl OF((int, int, zvoid *)); GRR: may need for some systems */
#endif
#ifndef HAVE_WORKING_GETCH
/* include system support for switching of console echo */
# ifdef VMS
# include <descrip.h>
# include <iodef.h>
# include <ttdef.h>
# include <starlet.h>
# include <ssdef.h>
# else /* !VMS */
# ifdef HAVE_TERMIOS_H
# include <termios.h>
# define sgttyb termios
# define sg_flags c_lflag
# define GTTY(f, s) tcgetattr(f, (zvoid *) s)
# define STTY(f, s) tcsetattr(f, TCSAFLUSH, (zvoid *) s)
# else /* !HAVE_TERMIOS_H */
# ifdef USE_SYSV_TERMIO /* Amdahl, Cray, all SysV? */
# ifdef HAVE_TERMIO_H
# include <termio.h>
# endif
# ifdef HAVE_SYS_TERMIO_H
# include <sys/termio.h>
# endif
# ifdef NEED_PTEM
# include <sys/stream.h>
# include <sys/ptem.h>
# endif
# define sgttyb termio
# define sg_flags c_lflag
# define GTTY(f,s) ioctl(f,TCGETA,(zvoid *)s)
# define STTY(f,s) ioctl(f,TCSETAW,(zvoid *)s)
# else /* !USE_SYSV_TERMIO */
# ifndef CMS_MVS
# if (!defined(MINIX) && !defined(GOT_IOCTL_H))
# include <sys/ioctl.h>
# endif
# include <sgtty.h>
# define GTTY gtty
# define STTY stty
# ifdef UNZIP
/*
* XXX : Are these declarations needed at all ????
*/
/*
* GRR: let's find out... Hmmm, appears not...
int gtty OF((int, struct sgttyb *));
int stty OF((int, struct sgttyb *));
*/
# endif
# endif /* !CMS_MVS */
# endif /* ?USE_SYSV_TERMIO */
# endif /* ?HAVE_TERMIOS_H */
# ifndef NO_FCNTL_H
# ifndef UNZIP
# include <fcntl.h>
# endif
# else
char *ttyname OF((int));
# endif
# endif /* ?VMS */
#endif /* !HAVE_WORKING_GETCH */
#ifndef HAVE_WORKING_GETCH
#ifdef VMS
static struct dsc$descriptor_s DevDesc =
{11, DSC$K_DTYPE_T, DSC$K_CLASS_S, "SYS$COMMAND"};
/* {dsc$w_length, dsc$b_dtype, dsc$b_class, dsc$a_pointer}; */
/*
* Turn keyboard echoing on or off (VMS). Loosely based on VMSmunch.c
* and hence on Joe Meadows' file.c code.
*/
int echo(opt)
int opt;
{
/*
* For VMS v5.x:
* IO$_SENSEMODE/SETMODE info: Programming, Vol. 7A, System Programming,
* I/O User's: Part I, sec. 8.4.1.1, 8.4.3, 8.4.5, 8.6
* sys$assign(), sys$qio() info: Programming, Vol. 4B, System Services,
* System Services Reference Manual, pp. sys-23, sys-379
* fixed-length descriptor info: Programming, Vol. 3, System Services,
* Intro to System Routines, sec. 2.9.2
* Greg Roelofs, 15 Aug 91
*/
short DevChan, iosb[4];
long status;
unsigned long ttmode[2]; /* space for 8 bytes */
/* assign a channel to standard input */
status = sys$assign(&DevDesc, &DevChan, 0, 0);
if (!(status & 1))
return status;
/* use sys$qio and the IO$_SENSEMODE function to determine the current
* tty status (for password reading, could use IO$_READVBLK function
* instead, but echo on/off will be more general)
*/
status = sys$qiow(0, DevChan, IO$_SENSEMODE, &iosb, 0, 0,
ttmode, 8, 0, 0, 0, 0);
if (!(status & 1))
return status;
status = iosb[0];
if (!(status & 1))
return status;
/* modify mode buffer to be either NOECHO or ECHO
* (depending on function argument opt)
*/
if (opt == 0) /* off */
ttmode[1] |= TT$M_NOECHO; /* set NOECHO bit */
else
ttmode[1] &= ~((unsigned long) TT$M_NOECHO); /* clear NOECHO bit */
/* use the IO$_SETMODE function to change the tty status */
status = sys$qiow(0, DevChan, IO$_SETMODE, &iosb, 0, 0,
ttmode, 8, 0, 0, 0, 0);
if (!(status & 1))
return status;
status = iosb[0];
if (!(status & 1))
return status;
/* deassign the sys$input channel by way of clean-up */
status = sys$dassgn(DevChan);
if (!(status & 1))
return status;
return SS$_NORMAL; /* we be happy */
} /* end function echo() */
/*
* Read a single character from keyboard in non-echoing mode (VMS).
* (returns EOF in case of errors)
*/
int tt_getch()
{
short DevChan, iosb[4];
long status;
char kbbuf[16]; /* input buffer with - some - excess length */
/* assign a channel to standard input */
status = sys$assign(&DevDesc, &DevChan, 0, 0);
if (!(status & 1))
return EOF;
/* read a single character from SYS$COMMAND (no-echo) and
* wait for completion
*/
status = sys$qiow(0,DevChan,
IO$_READVBLK|IO$M_NOECHO|IO$M_NOFILTR,
&iosb, 0, 0,
&kbbuf, 1, 0, 0, 0, 0);
if ((status&1) == 1)
status = iosb[0];
/* deassign the sys$input channel by way of clean-up
* (for this step, we do not need to check the completion status)
*/
sys$dassgn(DevChan);
/* return the first char read, or EOF in case the read request failed */
return (int)(((status&1) == 1) ? (uch)kbbuf[0] : EOF);
} /* end function tt_getch() */
#else /* !VMS: basically Unix */
/* For VM/CMS and MVS, non-echo terminal input is not (yet?) supported. */
#ifndef CMS_MVS
#ifdef ZIP /* moved to globals.h for UnZip */
static int echofd=(-1); /* file descriptor whose echo is off */
#endif
/*
* Turn echo off for file descriptor f. Assumes that f is a tty device.
*/
void Echoff(__G__ f)
__GDEF
int f; /* file descriptor for which to turn echo off */
{
struct sgttyb sg; /* tty device structure */
GLOBAL(echofd) = f;
GTTY(f, &sg); /* get settings */
sg.sg_flags &= ~ECHO; /* turn echo off */
STTY(f, &sg);
}
/*
* Turn echo back on for file descriptor echofd.
*/
void Echon(__G)
__GDEF
{
struct sgttyb sg; /* tty device structure */
if (GLOBAL(echofd) != -1) {
GTTY(GLOBAL(echofd), &sg); /* get settings */
sg.sg_flags |= ECHO; /* turn echo on */
STTY(GLOBAL(echofd), &sg);
GLOBAL(echofd) = -1;
}
}
#endif /* !CMS_MVS */
#endif /* ?VMS */
#if (defined(UNZIP) && !defined(FUNZIP))
#if (defined(UNIX) || defined(__BEOS__))
#ifdef MORE
/*
* Get the number of lines on the output terminal. SCO Unix apparently
* defines TIOCGWINSZ but doesn't support it (!M_UNIX).
*
* GRR: will need to know width of terminal someday, too, to account for
* line-wrapping.
*/
#if (defined(TIOCGWINSZ) && !defined(M_UNIX))
int screensize(tt_rows, tt_cols)
int *tt_rows;
int *tt_cols;
{
struct winsize wsz;
#ifdef DEBUG_WINSZ
static int firsttime = TRUE;
#endif
/* see termio(4) under, e.g., SunOS */
if (ioctl(1, TIOCGWINSZ, &wsz) == 0) {
#ifdef DEBUG_WINSZ
if (firsttime) {
firsttime = FALSE;
fprintf(stderr, "ttyio.c screensize(): ws_row = %d\n",
wsz.ws_row);
fprintf(stderr, "ttyio.c screensize(): ws_col = %d\n",
wsz.ws_col);
}
#endif
/* number of rows */
if (tt_rows != NULL)
*tt_rows = (int)((wsz.ws_row > 0) ? wsz.ws_row : 24);
/* number of columns */
if (tt_cols != NULL)
*tt_cols = (int)((wsz.ws_col > 0) ? wsz.ws_col : 80);
return 0; /* signal success */
} else { /* this happens when piping to more(1), for example */
#ifdef DEBUG_WINSZ
if (firsttime) {
firsttime = FALSE;
fprintf(stderr,
"ttyio.c screensize(): ioctl(TIOCGWINSZ) failed\n"));
}
#endif
/* VT-100 assumed to be minimal hardware */
if (tt_rows != NULL)
*tt_rows = 24;
if (tt_cols != NULL)
*tt_cols = 80;
return 1; /* signal failure */
}
}
#else /* !TIOCGWINSZ: service not available, fall back to semi-bogus method */
int screensize(tt_rows, tt_cols)
int *tt_rows;
int *tt_cols;
{
char *envptr, *getenv();
int n;
int errstat = 0;
/* GRR: this is overly simplistic, but don't have access to stty/gtty
* system anymore
*/
if (tt_rows != NULL) {
envptr = getenv("LINES");
if (envptr == (char *)NULL || (n = atoi(envptr)) < 5) {
/* VT-100 assumed to be minimal hardware */
*tt_rows = 24;
errstat = 1; /* signal failure */
} else {
*tt_rows = n;
}
}
if (tt_cols != NULL) {
envptr = getenv("COLUMNS");
if (envptr == (char *)NULL || (n = atoi(envptr)) < 5) {
*tt_cols = 80;
errstat = 1; /* signal failure */
} else {
*tt_cols = n;
}
}
return errstat;
}
#endif /* ?(TIOCGWINSZ && !M_UNIX) */
#endif /* MORE */
/*
* Get a character from the given file descriptor without echo or newline.
*/
int zgetch(__G__ f)
__GDEF
int f; /* file descriptor from which to read */
{
#if (defined(USE_SYSV_TERMIO) || defined(USE_POSIX_TERMIOS))
char oldmin, oldtim;
#endif
char c;
struct sgttyb sg; /* tty device structure */
GTTY(f, &sg); /* get settings */
#if (defined(USE_SYSV_TERMIO) || defined(USE_POSIX_TERMIOS))
oldmin = sg.c_cc[VMIN]; /* save old values */
oldtim = sg.c_cc[VTIME];
sg.c_cc[VMIN] = 1; /* need only one char to return read() */
sg.c_cc[VTIME] = 0; /* no timeout */
sg.sg_flags &= ~ICANON; /* canonical mode off */
#else
sg.sg_flags |= CBREAK; /* cbreak mode on */
#endif
sg.sg_flags &= ~ECHO; /* turn echo off, too */
STTY(f, &sg); /* set cbreak mode */
GLOBAL(echofd) = f; /* in case ^C hit (not perfect: still CBREAK) */
read(f, &c, 1); /* read our character */
#if (defined(USE_SYSV_TERMIO) || defined(USE_POSIX_TERMIOS))
sg.c_cc[VMIN] = oldmin; /* restore old values */
sg.c_cc[VTIME] = oldtim;
sg.sg_flags |= ICANON; /* canonical mode on */
#else
sg.sg_flags &= ~CBREAK; /* cbreak mode off */
#endif
sg.sg_flags |= ECHO; /* turn echo on */
STTY(f, &sg); /* restore canonical mode */
GLOBAL(echofd) = -1;
return (int)(uch)c;
}
#else /* !UNIX && !__BEOS__ */
#ifndef VMS /* VMS supplies its own variant of getch() */
int zgetch(__G__ f)
__GDEF
int f; /* file descriptor from which to read (must be open already) */
{
char c, c2;
/*---------------------------------------------------------------------------
Get a character from the given file descriptor without echo; can't fake
CBREAK mode (i.e., newline required), but can get rid of all chars up to
and including newline.
---------------------------------------------------------------------------*/
echoff(f);
read(f, &c, 1);
if (c != '\n')
do {
read(f, &c2, 1); /* throw away all other chars up thru newline */
} while (c2 != '\n');
echon();
return (int)c;
}
#endif /* !VMS */
#endif /* ?(UNIX || __BEOS__) */
#endif /* UNZIP && !FUNZIP */
#endif /* !HAVE_WORKING_GETCH */
#if CRYPT /* getp() is only used with full encryption */
/*
* Simple compile-time check for source compatibility between
* zcrypt and ttyio:
*/
#if (!defined(CR_MAJORVER) || (CR_MAJORVER < 2) || (CR_MINORVER < 7))
error: This Info-ZIP tool requires zcrypt 2.7 or later.
#endif
/*
* Get a password of length n-1 or less into *p using the prompt *m.
* The entered password is not echoed.
*/
#ifdef HAVE_WORKING_GETCH
/*
* For the AMIGA, getch() is defined as Agetch(), which is in
* amiga/filedate.c; SAS/C 6.x provides a getch(), but since Agetch()
* uses the infrastructure that is already in place in filedate.c, it is
* smaller. With this function, echoff() and echon() are not needed.
*
* For the MAC, a non-echo macgetch() function is defined in the MacOS
* specific sources which uses the event handling mechanism of the
* desktop window manager to get a character from the keyboard.
*
* For the other systems in this section, a non-echo getch() function
* is either contained the C runtime library (conio package), or getch()
* is defined as an alias for a similar system specific RTL function.
*/
#ifndef WINDLL /* WINDLL does not support a console interface */
#ifndef QDOS /* QDOS supplies a variant of this function */
/* This is the getp() function for all systems (with TTY type user interface)
* that supply a working `non-echo' getch() function for "raw" console input.
*/
char *getp(__G__ m, p, n)
__GDEF
ZCONST char *m; /* prompt for password */
char *p; /* return value: line input */
int n; /* bytes available in p[] */
{
char c; /* one-byte buffer for read() to use */
int i; /* number of characters input */
char *w; /* warning on retry */
/* get password */
w = "";
do {
fputs(w, stderr); /* warning if back again */
fputs(m, stderr); /* display prompt and flush */
fflush(stderr);
i = 0;
do { /* read line, keeping first n characters */
if ((c = (char)getch()) == '\r')
c = '\n'; /* until user hits CR */
if (c == 8 || c == 127) {
if (i > 0) i--; /* the `backspace' and `del' keys works */
}
else if (i < n)
p[i++] = c; /* truncate past n */
} while (c != '\n');
PUTC('\n', stderr); fflush(stderr);
w = "(line too long--try again)\n";
} while (p[i-1] != '\n');
p[i-1] = 0; /* terminate at newline */
return p; /* return pointer to password */
} /* end function getp() */
#endif /* !QDOS */
#endif /* !WINDLL */
#else /* !HAVE_WORKING_GETCH */
#if (defined(UNIX) || defined(__MINT__) || defined(__BEOS__))
#ifndef _PATH_TTY
# ifdef __MINT__
# define _PATH_TTY ttyname(2)
# else
# define _PATH_TTY "/dev/tty"
# endif
#endif
char *getp(__G__ m, p, n)
__GDEF
ZCONST char *m; /* prompt for password */
char *p; /* return value: line input */
int n; /* bytes available in p[] */
{
char c; /* one-byte buffer for read() to use */
int i; /* number of characters input */
char *w; /* warning on retry */
int f; /* file descriptor for tty device */
#ifdef PASSWD_FROM_STDIN
/* Read from stdin. This is unsafe if the password is stored on disk. */
f = 0;
#else
/* turn off echo on tty */
if ((f = open(_PATH_TTY, 0)) == -1)
return NULL;
#endif
/* get password */
w = "";
do {
fputs(w, stderr); /* warning if back again */
fputs(m, stderr); /* prompt */
fflush(stderr);
i = 0;
echoff(f);
do { /* read line, keeping n */
read(f, &c, 1);
if (i < n)
p[i++] = c;
} while (c != '\n');
echon();
PUTC('\n', stderr); fflush(stderr);
w = "(line too long--try again)\n";
} while (p[i-1] != '\n');
p[i-1] = 0; /* terminate at newline */
#ifndef PASSWD_FROM_STDIN
close(f);
#endif
return p; /* return pointer to password */
} /* end function getp() */
#endif /* UNIX || __MINT__ || __BEOS__ */
#if (defined(VMS) || defined(CMS_MVS))
char *getp(__G__ m, p, n)
__GDEF
ZCONST char *m; /* prompt for password */
char *p; /* return value: line input */
int n; /* bytes available in p[] */
{
char c; /* one-byte buffer for read() to use */
int i; /* number of characters input */
char *w; /* warning on retry */
FILE *f; /* file structure for SYS$COMMAND device */
#ifdef PASSWD_FROM_STDIN
f = stdin;
#else
if ((f = fopen(ctermid(NULL), "r")) == NULL)
return NULL;
#endif
/* get password */
fflush(stdout);
w = "";
do {
if (*w) /* bug: VMS apparently adds \n to NULL fputs */
fputs(w, stderr); /* warning if back again */
fputs(m, stderr); /* prompt */
fflush(stderr);
i = 0;
echoff(f);
do { /* read line, keeping n */
if ((c = (char)getc(f)) == '\r')
c = '\n';
if (i < n)
p[i++] = c;
} while (c != '\n');
echon();
PUTC('\n', stderr); fflush(stderr);
w = "(line too long--try again)\n";
} while (p[i-1] != '\n');
p[i-1] = 0; /* terminate at newline */
#ifndef PASSWD_FROM_STDIN
fclose(f);
#endif
return p; /* return pointer to password */
} /* end function getp() */
#endif /* VMS || CMS_MVS */
#endif /* ?HAVE_WORKING_GETCH */
#endif /* CRYPT */
#endif /* CRYPT || (UNZIP && !FUNZIP) */

221
src/apps/bin/unzip/ttyio.h Normal file
View File

@ -0,0 +1,221 @@
/*
Copyright (c) 1990-2001 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2000-Apr-09 or later
(the contents of which are also included in zip.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
*/
/*
ttyio.h
*/
#ifndef __ttyio_h /* don't include more than once */
#define __ttyio_h
#ifndef __crypt_h
# include "crypt.h" /* ensure that encryption header file has been seen */
#endif
#if (CRYPT || (defined(UNZIP) && !defined(FUNZIP)))
/*
* Non-echo keyboard/console input support is needed and enabled.
*/
#ifndef __G /* UnZip only, for now (DLL stuff) */
# define __G
# define __G__
# define __GDEF
# define __GPRO void
# define __GPRO__
#endif
#ifndef ZCONST /* UnZip only (until have configure script like Zip) */
# define ZCONST const
#endif
#if (defined(MSDOS) || defined(OS2) || defined(WIN32))
# ifndef DOS_OS2_W32
# define DOS_OS2_W32
# endif
#endif
#if (defined(DOS_OS2_W32) || defined(__human68k__))
# ifndef DOS_H68_OS2_W32
# define DOS_H68_OS2_W32
# endif
#endif
#if (defined(DOS_OS2_W32) || defined(FLEXOS))
# ifndef DOS_FLX_OS2_W32
# define DOS_FLX_OS2_W32
# endif
#endif
#if (defined(DOS_H68_OS2_W32) || defined(FLEXOS))
# ifndef DOS_FLX_H68_OS2_W32
# define DOS_FLX_H68_OS2_W32
# endif
#endif
#if (defined(VM_CMS) || defined(MVS))
# ifndef CMS_MVS
# define CMS_MVS
# endif
#endif
/* Function prototypes */
/* The following systems supply a `non-echo' character input function "getch()"
* (or an alias) and do not need the echoff() / echon() function pair.
*/
#ifdef AMIGA
# define echoff(f)
# define echon()
# define getch() Agetch()
# define HAVE_WORKING_GETCH
#endif /* AMIGA */
#ifdef ATARI
# define echoff(f)
# define echon()
# include <osbind.h>
# define getch() (Cnecin() & 0x000000ff)
# define HAVE_WORKING_GETCH
#endif
#ifdef MACOS
# define echoff(f)
# define echon()
# define getch() macgetch()
# define HAVE_WORKING_GETCH
#endif
#ifdef NLM
# define echoff(f)
# define echon()
# define HAVE_WORKING_GETCH
#endif
#ifdef QDOS
# define echoff(f)
# define echon()
# define HAVE_WORKING_GETCH
#endif
#ifdef RISCOS
# define echoff(f)
# define echon()
# define getch() SWI_OS_ReadC()
# define HAVE_WORKING_GETCH
#endif
#ifdef DOS_H68_OS2_W32
# define echoff(f)
# define echon()
# ifdef WIN32
# ifndef getch
# define getch() getch_win32()
# endif
# else /* !WIN32 */
# ifdef __EMX__
# ifndef getch
# define getch() _read_kbd(0, 1, 0)
# endif
# else /* !__EMX__ */
# ifdef __GO32__
# include <pc.h>
# define getch() getkey()
# else /* !__GO32__ */
# include <conio.h>
# endif /* ?__GO32__ */
# endif /* ?__EMX__ */
# endif /* ?WIN32 */
# define HAVE_WORKING_GETCH
#endif /* DOS_H68_OS2_W32 */
#ifdef FLEXOS
# define echoff(f)
# define echon()
# define getch() getchar() /* not correct, but may not be on a console */
# define HAVE_WORKING_GETCH
#endif
/* For VM/CMS and MVS, we do not (yet) have any support to switch terminal
* input echo on and off. The following "fake" definitions allow inclusion
* of crypt support and UnZip's "pause prompting" features, but without
* any echo suppression.
*/
#ifdef CMS_MVS
# define echoff(f)
# define echon()
#endif
#ifdef TANDEM
# define echoff(f)
# define echon()
# define getch() zgetch() /* defined in TANDEMC */
# define HAVE_WORKING_GETCH
#endif
/* The THEOS C runtime library supplies the function conmask() to toggle
* terminal input echo on (conmask("e")) and off (conmask("n")). But,
* since THEOS C RTL also contains a working non-echo getch() function,
* the echo toggles are not needed.
*/
#ifdef THEOS
# define echoff(f)
# define echon()
# define HAVE_WORKING_GETCH
#endif
/* VMS has a single echo() function in ttyio.c to toggle terminal
* input echo on and off.
*/
#ifdef VMS
# define echoff(f) echo(0)
# define echon() echo(1)
# define getch() tt_getch()
# define FGETCH(f) tt_getch()
int echo OF((int));
int tt_getch OF((void));
#endif
/* For all other systems, ttyio.c supplies the two functions Echoff() and
* Echon() for suppressing and (re)enabling console input echo.
*/
#ifndef echoff
# define echoff(f) Echoff(__G__ f)
# define echon() Echon(__G)
void Echoff OF((__GPRO__ int f));
void Echon OF((__GPRO));
#endif
/* this stuff is used by MORE and also now by the ctrl-S code; fileio.c only */
#if (defined(UNZIP) && !defined(FUNZIP))
# ifdef HAVE_WORKING_GETCH
# define FGETCH(f) getch()
# endif
# ifndef FGETCH
/* default for all systems where no getch()-like function is available */
int zgetch OF((__GPRO__ int f));
# define FGETCH(f) zgetch(__G__ f)
# endif
#endif /* UNZIP && !FUNZIP */
#if (CRYPT && !defined(WINDLL))
char *getp OF((__GPRO__ ZCONST char *m, char *p, int n));
#endif
#else /* !(CRYPT || (UNZIP && !FUNZIP)) */
/*
* No need for non-echo keyboard/console input; provide dummy definitions.
*/
#define echoff(f)
#define echon()
#endif /* ?(CRYPT || (UNZIP && !FUNZIP)) */
#endif /* !__ttyio_h */

View File

@ -0,0 +1,35 @@
/*
Copyright (c) 1990-2002 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
*/
/*---------------------------------------------------------------------------
unreduce.c
Copyright-clean dummy module, without any real code.
If you really need unreduce support, replace this module by the full
source code, available as add-on package from our distribution site.
---------------------------------------------------------------------------*/
#define __UNREDUCE_C /* identifies this source module */
#define UNZIP_INTERNAL
#include "unzip.h" /* defines COPYRIGHT_CLEAN by default */
#ifndef COPYRIGHT_CLEAN
/* This line is indented to hide the #error directive from pure traditional
* K&R C preprocessors. These do not recognize the #error directive, but
* they also recognize only lines that start with a '#' in column 1 as
* preprocessor directives.
*/
#error This dummy-module does not support the unreduce method!
#endif /* !COPYRIGHT_CLEAN */

View File

@ -0,0 +1,314 @@
/*
Copyright (c) 1990-2001 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
*/
/*---------------------------------------------------------------------------
unshrink.c version 1.21 23 Nov 95
NOTE: This code may or may not infringe on the so-called "Welch
patent" owned by Unisys. (From reading the patent, it appears
that a pure LZW decompressor is *not* covered, but this claim has
not been tested in court, and Unisys is reported to believe other-
wise.) It is therefore the responsibility of the user to acquire
whatever license(s) may be required for legal use of this code.
THE INFO-ZIP GROUP DISCLAIMS ALL LIABILITY FOR USE OF THIS CODE
IN VIOLATION OF APPLICABLE PATENT LAW.
Shrinking is basically a dynamic LZW algorithm with allowed code sizes of
up to 13 bits; in addition, there is provision for partial clearing of
leaf nodes. PKWARE uses the special code 256 (decimal) to indicate a
change in code size or a partial clear of the code tree: 256,1 for the
former and 256,2 for the latter. [Note that partial clearing can "orphan"
nodes: the parent-to-be can be cleared before its new child is added,
but the child is added anyway (as an orphan, as though the parent still
existed). When the tree fills up to the point where the parent node is
reused, the orphan is effectively "adopted." Versions prior to 1.05 were
affected more due to greater use of pointers (to children and siblings
as well as parents).]
This replacement version of unshrink.c was written from scratch. It is
based only on the algorithms described in Mark Nelson's _The Data Compres-
sion Book_ and in Terry Welch's original paper in the June 1984 issue of
IEEE _Computer_; no existing source code, including any in Nelson's book,
was used.
Memory requirements have been reduced in this version and are now no more
than the original Sam Smith code. This is still larger than any of the
other algorithms: at a minimum, 8K+8K+16K (stack+values+parents) assuming
16-bit short ints, and this does not even include the output buffer (the
other algorithms leave the uncompressed data in the work area, typically
called slide[]). For machines with a 64KB data space this is a problem,
particularly when text conversion is required and line endings have more
than one character. UnZip's solution is to use two roughly equal halves
of outbuf for the ASCII conversion in such a case; the "unshrink" argument
to flush() signals that this is the case.
For large-memory machines, a second outbuf is allocated for translations,
but only if unshrinking and only if translations are required.
| binary mode | text mode
---------------------------------------------------
big mem | big outbuf | big outbuf + big outbuf2 <- malloc'd here
small mem | small outbuf | half + half small outbuf
Copyright 1994, 1995 Greg Roelofs. See the accompanying file "COPYING"
in UnZip 5.20 (or later) source or binary distributions.
---------------------------------------------------------------------------*/
#define __UNSHRINK_C /* identifies this source module */
#define UNZIP_INTERNAL
#include "unzip.h" /* defines LZW_CLEAN by default */
#ifndef LZW_CLEAN
static void partial_clear OF((__GPRO));
#ifdef DEBUG
# define OUTDBG(c) \
if ((c)<32 || (c)>=127) fprintf(stderr,"\\x%02x",(c)); else putc((c),stderr);
#else
# define OUTDBG(c)
#endif
/* HSIZE is defined as 2^13 (8192) in unzip.h */
#define BOGUSCODE 256
#define FLAG_BITS parent /* upper bits of parent[] used as flag bits */
#define CODE_MASK (HSIZE - 1) /* 0x1fff (lower bits are parent's index) */
#define FREE_CODE HSIZE /* 0x2000 (code is unused or was cleared) */
#define HAS_CHILD (HSIZE << 1) /* 0x4000 (code has a child--do not clear) */
#define parent G.area.shrink.Parent
#define Value G.area.shrink.value /* "value" conflicts with Pyramid ioctl.h */
#define stack G.area.shrink.Stack
/***********************/
/* Function unshrink() */
/***********************/
int unshrink(__G)
__GDEF
{
int offset = (HSIZE - 1);
uch *stacktop = stack + offset;
register uch *newstr;
int codesize=9, len, KwKwK, error;
shrint code, oldcode, freecode, curcode;
shrint lastfreecode;
unsigned int outbufsiz;
#if (defined(DLL) && !defined(NO_SLIDE_REDIR))
/* Normally realbuf and outbuf will be the same. However, if the data
* are redirected to a large memory buffer, realbuf will point to the
* new location while outbuf will remain pointing to the malloc'd
* memory buffer. */
uch *realbuf = G.outbuf;
#else
# define realbuf G.outbuf
#endif
/*---------------------------------------------------------------------------
Initialize various variables.
---------------------------------------------------------------------------*/
lastfreecode = BOGUSCODE;
#ifndef VMS /* VMS uses its own buffer scheme for textmode flush(). */
#ifndef SMALL_MEM
/* non-memory-limited machines: allocate second (large) buffer for
* textmode conversion in flush(), but only if needed */
if (G.pInfo->textmode && !G.outbuf2 &&
(G.outbuf2 = (uch *)malloc(TRANSBUFSIZ)) == (uch *)NULL)
return PK_MEM3;
#endif
#endif /* !VMS */
for (code = 0; code < BOGUSCODE; ++code) {
Value[code] = (uch)code;
parent[code] = BOGUSCODE;
}
for (code = BOGUSCODE+1; code < HSIZE; ++code)
parent[code] = FREE_CODE;
#if (defined(DLL) && !defined(NO_SLIDE_REDIR))
if (G.redirect_slide) { /* use normal outbuf unless we're a DLL routine */
realbuf = G.redirect_buffer;
outbufsiz = (unsigned)G.redirect_size;
} else
#endif
#ifdef DLL
if (G.pInfo->textmode && !G.redirect_data)
#else
if (G.pInfo->textmode)
#endif
outbufsiz = RAWBUFSIZ;
else
outbufsiz = OUTBUFSIZ;
G.outptr = realbuf;
G.outcnt = 0L;
/*---------------------------------------------------------------------------
Get and output first code, then loop over remaining ones.
---------------------------------------------------------------------------*/
READBITS(codesize, oldcode)
if (!G.zipeof) {
*G.outptr++ = (uch)oldcode;
OUTDBG((uch)oldcode)
++G.outcnt;
}
do {
READBITS(codesize, code)
if (G.zipeof)
break;
if (code == BOGUSCODE) { /* possible to have consecutive escapes? */
READBITS(codesize, code)
if (code == 1) {
++codesize;
Trace((stderr, " (codesize now %d bits)\n", codesize));
} else if (code == 2) {
Trace((stderr, " (partial clear code)\n"));
partial_clear(__G); /* clear leafs (nodes with no children) */
Trace((stderr, " (done with partial clear)\n"));
lastfreecode = BOGUSCODE; /* reset start of free-node search */
}
continue;
}
/*-----------------------------------------------------------------------
Translate code: traverse tree from leaf back to root.
-----------------------------------------------------------------------*/
newstr = stacktop;
curcode = code;
if (parent[curcode] == FREE_CODE) {
/* or (FLAG_BITS[curcode] & FREE_CODE)? */
KwKwK = TRUE;
Trace((stderr, " (found a KwKwK code %d; oldcode = %d)\n", code,
oldcode));
--newstr; /* last character will be same as first character */
curcode = oldcode;
} else
KwKwK = FALSE;
do {
*newstr-- = Value[curcode];
curcode = (shrint)(parent[curcode] & CODE_MASK);
} while (curcode != BOGUSCODE);
len = (int)(stacktop - newstr++);
if (KwKwK)
*stacktop = *newstr;
/*-----------------------------------------------------------------------
Write expanded string in reverse order to output buffer.
-----------------------------------------------------------------------*/
Trace((stderr, "code %4d; oldcode %4d; char %3d (%c); string [", code,
oldcode, (int)(*newstr), (*newstr<32 || *newstr>=127)? ' ':*newstr));
{
register uch *p;
for (p = newstr; p < newstr+len; ++p) {
*G.outptr++ = *p;
OUTDBG(*p)
if (++G.outcnt == outbufsiz) {
Trace((stderr, "doing flush(), outcnt = %lu\n", G.outcnt));
if ((error = flush(__G__ realbuf, G.outcnt, TRUE)) != 0) {
Trace((stderr, "unshrink: flush() error (%d)\n",
error));
return error;
}
G.outptr = realbuf;
G.outcnt = 0L;
Trace((stderr, "done with flush()\n"));
}
}
}
/*-----------------------------------------------------------------------
Add new leaf (first character of newstr) to tree as child of oldcode.
-----------------------------------------------------------------------*/
/* search for freecode */
freecode = (shrint)(lastfreecode + 1);
/* add if-test before loop for speed? */
while (parent[freecode] != FREE_CODE)
++freecode;
lastfreecode = freecode;
Trace((stderr, "]; newcode %d\n", freecode));
Value[freecode] = *newstr;
parent[freecode] = oldcode;
oldcode = code;
} while (!G.zipeof);
/*---------------------------------------------------------------------------
Flush any remaining data and return to sender...
---------------------------------------------------------------------------*/
if (G.outcnt > 0L) {
Trace((stderr, "doing final flush(), outcnt = %lu\n", G.outcnt));
if ((error = flush(__G__ realbuf, G.outcnt, TRUE)) != 0) {
Trace((stderr, "unshrink: flush() error (%d)\n", error));
return error;
}
Trace((stderr, "done with flush()\n"));
}
return PK_OK;
} /* end function unshrink() */
/****************************/
/* Function partial_clear() */ /* no longer recursive... */
/****************************/
static void partial_clear(__G)
__GDEF
{
register shrint code;
/* clear all nodes which have no children (i.e., leaf nodes only) */
/* first loop: mark each parent as such */
for (code = BOGUSCODE+1; code < HSIZE; ++code) {
register shrint cparent = (shrint)(parent[code] & CODE_MASK);
if (cparent > BOGUSCODE && cparent != FREE_CODE)
FLAG_BITS[cparent] |= HAS_CHILD; /* set parent's child-bit */
}
/* second loop: clear all nodes *not* marked as parents; reset flag bits */
for (code = BOGUSCODE+1; code < HSIZE; ++code) {
if (FLAG_BITS[code] & HAS_CHILD) /* just clear child-bit */
FLAG_BITS[code] &= ~HAS_CHILD;
else { /* leaf: lose it */
Trace((stderr, "%d\n", code));
parent[code] = FREE_CODE;
}
}
return;
}
#endif /* !LZW_CLEAN */

1980
src/apps/bin/unzip/unzip.c Normal file

File diff suppressed because it is too large Load Diff

609
src/apps/bin/unzip/unzip.h Normal file
View File

@ -0,0 +1,609 @@
/*---------------------------------------------------------------------------
unzip.h (new)
Copyright (c) 1990-2002 Info-ZIP. All rights reserved.
This header file contains the public macros and typedefs required by
both the UnZip sources and by any application using the UnZip API. If
UNZIP_INTERNAL is defined, it includes unzpriv.h (containing includes,
prototypes and extern variables used by the actual UnZip sources).
---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------
This is version 2000-Apr-09 of the Info-ZIP copyright and license.
The definitive version of this document should be available at
ftp://ftp.info-zip.org/pub/infozip/license.html indefinitely.
Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
For the purposes of this copyright and license, "Info-ZIP" is defined as
the following set of individuals:
Mark Adler, John Bush, Karl Davis, Harald Denker, Jean-Michel Dubois,
Jean-loup Gailly, Hunter Goatley, Ian Gorman, Chris Herborth, Dirk Haase,
Greg Hartwig, Robert Heath, Jonathan Hudson, Paul Kienitz, David Kirschbaum,
Johnny Lee, Onno van der Linden, Igor Mandrichenko, Steve P. Miller,
Sergio Monesi, Keith Owens, George Petrov, Greg Roelofs, Kai Uwe Rommel,
Steve Salisbury, Dave Smith, Christian Spieler, Antoine Verheijen,
Paul von Behren, Rich Wales, Mike White
This software is provided "as is," without warranty of any kind, express
or implied. In no event shall Info-ZIP or its contributors be held liable
for any direct, indirect, incidental, special or consequential damages
arising out of the use of or inability to use this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. Redistributions of source code must retain the above copyright notice,
definition, disclaimer, and this list of conditions.
2. Redistributions in binary form must reproduce the above copyright
notice, definition, disclaimer, and this list of conditions in
documentation and/or other materials provided with the distribution.
3. Altered versions--including, but not limited to, ports to new operating
systems, existing ports with new graphical interfaces, and dynamic,
shared, or static library versions--must be plainly marked as such
and must not be misrepresented as being the original source. Such
altered versions also must not be misrepresented as being Info-ZIP
releases--including, but not limited to, labeling of the altered
versions with the names "Info-ZIP" (or any variation thereof, including,
but not limited to, different capitalizations), "Pocket UnZip," "WiZ"
or "MacZip" without the explicit permission of Info-ZIP. Such altered
versions are further prohibited from misrepresentative use of the
Zip-Bugs or Info-ZIP e-mail addresses or of the Info-ZIP URL(s).
4. Info-ZIP retains the right to use the names "Info-ZIP," "Zip," "UnZip,"
"WiZ," "Pocket UnZip," "Pocket Zip," and "MacZip" for its own source and
binary releases.
---------------------------------------------------------------------------*/
#ifndef __unzip_h /* prevent multiple inclusions */
#define __unzip_h
/*---------------------------------------------------------------------------
Predefined, machine-specific macros.
---------------------------------------------------------------------------*/
#ifdef __GO32__ /* MS-DOS extender: NOT Unix */
# ifdef unix
# undef unix
# endif
# ifdef _unix
# undef _unix
# endif
# ifdef __unix
# undef __unix
# endif
# ifdef __unix__
# undef __unix__
# endif
#endif
#if ((defined(__convex__) || defined(__convexc__)) && !defined(CONVEX))
# define CONVEX
#endif
#if (defined(unix) || defined(_unix) || defined(__unix) || defined(__unix__))
# ifndef UNIX
# define UNIX
# endif
#endif /* unix || _unix || __unix || __unix__ */
#if (defined(M_XENIX) || defined(COHERENT) || defined(__hpux))
# ifndef UNIX
# define UNIX
# endif
#endif /* M_XENIX || COHERENT || __hpux */
#if (defined(CONVEX) || defined(MINIX) || defined(_AIX) || defined(__QNX__))
# ifndef UNIX
# define UNIX
# endif
#endif /* CONVEX || MINIX || _AIX || __QNX__ */
#if (defined(VM_CMS) || defined(MVS))
# define CMS_MVS
#endif
#if (defined(__OS2__) && !defined(OS2))
# define OS2
#endif
#if (defined(__TANDEM) && !defined(TANDEM))
# define TANDEM
#endif
#if (defined(__VMS) && !defined(VMS))
# define VMS
#endif
#if ((defined(__WIN32__) || defined(_WIN32)) && !defined(WIN32))
# define WIN32
#endif
#if ((defined(__WINNT__) || defined(__WINNT)) && !defined(WIN32))
# define WIN32
#endif
#ifdef __COMPILER_KCC__
# include <c-env.h>
# ifdef SYS_T20
# define TOPS20
# endif
#endif /* __COMPILER_KCC__ */
/* Borland C does not define __TURBOC__ if compiling for a 32-bit platform */
#ifdef __BORLANDC__
# ifndef __TURBOC__
# define __TURBOC__
# endif
# if (!defined(__MSDOS__) && !defined(OS2) && !defined(WIN32))
# define __MSDOS__
# endif
#endif
/* define MSDOS for Turbo C (unless OS/2) and Power C as well as Microsoft C */
#ifdef __POWERC
# define __TURBOC__
# define MSDOS
#endif /* __POWERC */
#if (defined(__MSDOS__) && !defined(MSDOS)) /* just to make sure */
# define MSDOS
#endif
/* RSXNTDJ (at least up to v1.3) compiles for WIN32 (RSXNT) using a derivate
of the EMX environment, but defines MSDOS and __GO32__. ARG !!! */
#if (defined(MSDOS) && defined(WIN32))
# undef MSDOS /* WIN32 is >>>not<<< MSDOS */
#endif
#if (defined(__GO32__) && defined(__EMX__) && defined(__RSXNT__))
# undef __GO32__
#endif
#if (defined(linux) && !defined(LINUX))
# define LINUX
#endif
#ifdef __riscos
# define RISCOS
#endif
#if (defined(THINK_C) || defined(MPW))
# define MACOS
#endif
#if (defined(__MWERKS__) && defined(macintosh))
# define MACOS
#endif
/* use prototypes and ANSI libraries if __STDC__, or Microsoft or Borland C, or
* Silicon Graphics, or Convex?, or IBM C Set/2, or GNU gcc/emx, or Watcom C,
* or Macintosh, or Windows NT, or Sequent, or Atari or IBM RS/6000.
*/
#if (defined(__STDC__) || defined(MSDOS) || defined(WIN32) || defined(__EMX__))
# ifndef PROTO
# define PROTO
# endif
# ifndef MODERN
# define MODERN
# endif
#endif
#if (defined(__IBMC__) || defined(__BORLANDC__) || defined(__WATCOMC__))
# ifndef PROTO
# define PROTO
# endif
# ifndef MODERN
# define MODERN
# endif
#endif
#if (defined(MACOS) || defined(ATARI_ST) || defined(RISCOS) || defined(THEOS))
# ifndef PROTO
# define PROTO
# endif
# ifndef MODERN
# define MODERN
# endif
#endif
/* Sequent running Dynix/ptx: non-modern compiler */
#if (defined(_AIX) || defined(sgi) || (defined(_SEQUENT_) && !defined(PTX)))
# ifndef PROTO
# define PROTO
# endif
# ifndef MODERN
# define MODERN
# endif
#endif
#if (defined(CMS_MVS) || defined(__BEOS__)) /* || defined(CONVEX) */
# ifndef PROTO
# define PROTO
# endif
# ifndef MODERN
# define MODERN
# endif
#endif
/* turn off prototypes if requested */
#if (defined(NOPROTO) && defined(PROTO))
# undef PROTO
#endif
/* used to remove arguments in function prototypes for non-ANSI C */
#ifdef PROTO
# define OF(a) a
#else
# define OF(a) ()
#endif
/* enable the "const" keyword only if MODERN and if not otherwise instructed */
#ifdef MODERN
# if (!defined(ZCONST) && (defined(USE_CONST) || !defined(NO_CONST)))
# define ZCONST const
# endif
#endif
#ifndef ZCONST
# define ZCONST
#endif
/*---------------------------------------------------------------------------
Grab system-specific public include headers.
---------------------------------------------------------------------------*/
#ifdef POCKET_UNZIP /* WinCE port */
# include "wince/punzip.h" /* must appear before windows.h */
#endif
#ifdef WINDLL
/* for UnZip, the "basic" part of the win32 api is sufficient */
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# define IZ_HASDEFINED_WIN32LEAN
# endif
# include <windows.h>
# include "windll/structs.h"
# ifdef IZ_HASDEFINEd_WIN32LEAN
# undef WIN32_LEAN_AND_MEAN
# undef IZ_HASDEFINED_WIN32LEAN
# endif
#endif
/*---------------------------------------------------------------------------
Grab system-dependent definition of EXPENTRY for prototypes below.
---------------------------------------------------------------------------*/
#if 0
#if (defined(OS2) && !defined(FUNZIP))
# ifdef UNZIP_INTERNAL
# define INCL_NOPM
# define INCL_DOSNLS
# define INCL_DOSPROCESS
# define INCL_DOSDEVICES
# define INCL_DOSDEVIOCTL
# define INCL_DOSERRORS
# define INCL_DOSMISC
# ifdef OS2DLL
# define INCL_REXXSAA
# include <rexxsaa.h>
# endif
# endif /* UNZIP_INTERNAL */
# include <os2.h>
# define UZ_EXP EXPENTRY
#endif /* OS2 && !FUNZIP */
#endif /* 0 */
#if (defined(OS2) && !defined(FUNZIP))
# if (defined(__IBMC__) || defined(__WATCOMC__))
# define UZ_EXP _System /* compiler keyword */
# else
# define UZ_EXP
# endif
#endif /* OS2 && !FUNZIP */
#if (defined(WINDLL) || defined(USE_UNZIP_LIB))
# ifndef EXPENTRY
# define UZ_EXP WINAPI
# else
# define UZ_EXP EXPENTRY
# endif
#endif
#ifndef UZ_EXP
# define UZ_EXP
#endif
/*---------------------------------------------------------------------------
Public typedefs.
---------------------------------------------------------------------------*/
#ifndef _IZ_TYPES_DEFINED
#ifdef MODERN
typedef void zvoid;
#else /* !MODERN */
# ifndef AOS_VS /* mostly modern? */
# ifndef VAXC /* not fully modern, but has knows 'void' */
# define void int
# endif /* !VAXC */
# endif /* !AOS_VS */
typedef char zvoid;
#endif /* ?MODERN */
typedef unsigned char uch; /* code assumes unsigned bytes; these type- */
typedef unsigned short ush; /* defs replace byte/UWORD/ULONG (which are */
typedef unsigned long ulg; /* predefined on some systems) & match zip */
#define _IZ_TYPES_DEFINED
#endif /* !_IZ_TYPES_DEFINED */
/* InputFn is not yet used and is likely to change: */
#ifdef PROTO
typedef int (UZ_EXP MsgFn) (zvoid *pG, uch *buf, ulg size, int flag);
typedef int (UZ_EXP InputFn) (zvoid *pG, uch *buf, int *size, int flag);
typedef void (UZ_EXP PauseFn) (zvoid *pG, ZCONST char *prompt, int flag);
typedef int (UZ_EXP PasswdFn) (zvoid *pG, int *rcnt, char *pwbuf,
int size, ZCONST char *zfn,
ZCONST char *efn);
typedef int (UZ_EXP StatCBFn) (zvoid *pG, int fnflag, ZCONST char *zfn,
ZCONST char *efn, ZCONST zvoid *details);
typedef void (UZ_EXP UsrIniFn) (void);
#else /* !PROTO */
typedef int (UZ_EXP MsgFn) ();
typedef int (UZ_EXP InputFn) ();
typedef void (UZ_EXP PauseFn) ();
typedef int (UZ_EXP PasswdFn) ();
typedef int (UZ_EXP StatCBFn) ();
typedef void (UZ_EXP UsrIniFn) ();
#endif /* ?PROTO */
typedef struct _UzpBuffer { /* rxstr */
ulg strlength; /* length of string */
char *strptr; /* pointer to string */
} UzpBuffer;
typedef struct _UzpInit {
ulg structlen; /* length of the struct being passed */
/* GRR: can we assume that each of these is a 32-bit pointer? if not,
* does it matter? add "far" keyword to make sure? */
MsgFn *msgfn;
InputFn *inputfn;
PauseFn *pausefn;
UsrIniFn *userfn; /* user init function to be called after */
/* globals constructed and initialized */
/* pointer to program's environment area or something? */
/* hooks for performance testing? */
/* hooks for extra unzip -v output? (detect CPU or other hardware?) */
/* anything else? let me (Greg) know... */
} UzpInit;
typedef struct _UzpCB {
ulg structlen; /* length of the struct being passed */
/* GRR: can we assume that each of these is a 32-bit pointer? if not,
* does it matter? add "far" keyword to make sure? */
MsgFn *msgfn;
InputFn *inputfn;
PauseFn *pausefn;
PasswdFn *passwdfn;
StatCBFn *statrepfn;
} UzpCB;
/* the collection of general UnZip option flags and option arguments */
typedef struct _UzpOpts {
#ifndef FUNZIP
char *exdir; /* pointer to extraction root directory (-d option) */
char *pwdarg; /* pointer to command-line password (-P option) */
int zipinfo_mode; /* behave like ZipInfo or like normal UnZip? */
int aflag; /* -a: do ASCII-EBCDIC and/or end-of-line translation */
#ifdef VMS
int bflag; /* -b: force fixed record format for binary files */
#endif
#ifdef TANDEM
int bflag; /* -b: create text files in 'C' format (180)*/
#endif
#ifdef UNIXBACKUP
int B_flag; /* -B: back up existing files by renaming to *~ first */
#endif
int cflag; /* -c: output to stdout */
int C_flag; /* -C: match filenames case-insensitively */
#ifdef MACOS
int E_flag; /* -E: [MacOS] show Mac extra field during restoring */
#endif
int fflag; /* -f: "freshen" (extract only newer files) */
#if (defined(RISCOS) || defined(ACORN_FTYPE_NFS))
int acorn_nfs_ext; /* -F: RISC OS types & NFS filetype extensions */
#endif
int hflag; /* -h: header line (zipinfo) */
#ifdef MACOS
int i_flag; /* -i: [MacOS] ignore filenames stored in Mac e.f. */
#endif
#ifdef RISCOS
int scanimage; /* -I: scan image files */
#endif
int jflag; /* -j: junk pathnames (unzip) */
#if (defined(__BEOS__) || defined(MACOS))
int J_flag; /* -J: ignore BeOS/MacOS extra field info (unzip) */
#endif
int lflag; /* -12slmv: listing format (zipinfo) */
int L_flag; /* -L: convert filenames from some OSes to lowercase */
int overwrite_none; /* -n: never overwrite files (no prompting) */
#ifdef AMIGA
int N_flag; /* -N: restore comments as AmigaDOS filenotes */
#endif
int overwrite_all; /* -o: OK to overwrite files without prompting */
#endif /* !FUNZIP */
int qflag; /* -q: produce a lot less output */
#ifndef FUNZIP
#if (defined(MSDOS) || defined(FLEXOS) || defined(OS2) || defined(WIN32))
int sflag; /* -s: convert spaces in filenames to underscores */
#endif
#if (defined(NLM))
int sflag; /* -s: convert spaces in filenames to underscores */
#endif
#if (defined(MSDOS) || defined(__human68k__) || defined(OS2) || defined(WIN32))
int volflag; /* -$: extract volume labels */
#endif
int tflag; /* -t: test (unzip) or totals line (zipinfo) */
int T_flag; /* -T: timestamps (unzip) or dec. time fmt (zipinfo) */
int uflag; /* -u: "update" (extract only newer/brand-new files) */
int vflag; /* -v: (verbosely) list directory */
int V_flag; /* -V: don't strip VMS version numbers */
#if (defined(__BEOS__) || defined(TANDEM) || defined(THEOS) || defined(UNIX))
int X_flag; /* -X: restore owner/protection or UID/GID or ACLs */
#endif
#if (defined(OS2) || defined(VMS) || defined(WIN32))
int X_flag; /* -X: restore owner/protection or UID/GID or ACLs */
#endif
int zflag; /* -z: display the zipfile comment (only, for unzip) */
#if (!defined(RISCOS) && !defined(CMS_MVS) && !defined(TANDEM))
int ddotflag; /* -:: don't skip over "../" path elements */
#endif
#endif /* !FUNZIP */
} UzpOpts;
/* intended to be a private struct: */
typedef struct _ver {
uch major; /* e.g., integer 5 */
uch minor; /* e.g., 2 */
uch patchlevel; /* e.g., 0 */
uch not_used;
} _version_type;
typedef struct _UzpVer {
ulg structlen; /* length of the struct being passed */
ulg flag; /* bit 0: is_beta bit 1: uses_zlib */
char *betalevel; /* e.g., "g BETA" or "" */
char *date; /* e.g., "4 Sep 95" (beta) or "4 September 1995" */
char *zlib_version; /* e.g., "0.95" or NULL */
_version_type unzip;
_version_type zipinfo;
_version_type os2dll;
_version_type windll;
} UzpVer;
/* for Visual BASIC access to Windows DLLs: */
typedef struct _UzpVer2 {
ulg structlen; /* length of the struct being passed */
ulg flag; /* bit 0: is_beta bit 1: uses_zlib */
char betalevel[10]; /* e.g., "g BETA" or "" */
char date[20]; /* e.g., "4 Sep 95" (beta) or "4 September 1995" */
char zlib_version[10]; /* e.g., "0.95" or NULL */
_version_type unzip;
_version_type zipinfo;
_version_type os2dll;
_version_type windll;
} UzpVer2;
typedef struct central_directory_file_header { /* CENTRAL */
uch version_made_by[2];
uch version_needed_to_extract[2];
ush general_purpose_bit_flag;
ush compression_method;
ulg last_mod_dos_datetime;
ulg crc32;
ulg csize;
ulg ucsize;
ush filename_length;
ush extra_field_length;
ush file_comment_length;
ush disk_number_start;
ush internal_file_attributes;
ulg external_file_attributes;
ulg relative_offset_local_header;
} cdir_file_hdr;
#define UZPINIT_LEN sizeof(UzpInit)
#define UZPVER_LEN sizeof(UzpVer)
#define cbList(func) int (* UZ_EXP func)(char *filename, cdir_file_hdr *crec)
/*---------------------------------------------------------------------------
Return (and exit) values of the public UnZip API functions.
---------------------------------------------------------------------------*/
/* external return codes */
#define PK_OK 0 /* no error */
#define PK_COOL 0 /* no error */
#define PK_WARN 1 /* warning error */
#define PK_ERR 2 /* error in zipfile */
#define PK_BADERR 3 /* severe error in zipfile */
#define PK_MEM 4 /* insufficient memory (during initialization) */
#define PK_MEM2 5 /* insufficient memory (password failure) */
#define PK_MEM3 6 /* insufficient memory (file decompression) */
#define PK_MEM4 7 /* insufficient memory (memory decompression) */
#define PK_MEM5 8 /* insufficient memory (not yet used) */
#define PK_NOZIP 9 /* zipfile not found */
#define PK_PARAM 10 /* bad or illegal parameters specified */
#define PK_FIND 11 /* no files found */
#define PK_DISK 50 /* disk full */
#define PK_EOF 51 /* unexpected EOF */
#define IZ_CTRLC 80 /* user hit ^C to terminate */
#define IZ_UNSUP 81 /* no files found: all unsup. compr/encrypt. */
#define IZ_BADPWD 82 /* no files found: all had bad password */
/* return codes of password fetches (negative = user abort; positive = error) */
#define IZ_PW_ENTERED 0 /* got some password string; use/try it */
#define IZ_PW_CANCEL -1 /* no password available (for this entry) */
#define IZ_PW_CANCELALL -2 /* no password, skip any further pwd. request */
#define IZ_PW_ERROR 5 /* = PK_MEM2 : failure (no mem, no tty, ...) */
/* flag values for status callback function */
#define UZ_ST_START_EXTRACT 1 /* no details */
#define UZ_ST_IN_PROGRESS 2 /* no details */
#define UZ_ST_FINISH_MEMBER 3 /* 'details': extracted size */
/* return values of status callback function */
#define UZ_ST_CONTINUE 0
#define UZ_ST_BREAK 1
/*---------------------------------------------------------------------------
Prototypes for public UnZip API (DLL) functions.
---------------------------------------------------------------------------*/
#define UzpMatch match
int UZ_EXP UzpMain OF((int argc, char **argv));
int UZ_EXP UzpAltMain OF((int argc, char **argv, UzpInit *init));
UzpVer * UZ_EXP UzpVersion OF((void));
void UZ_EXP UzpFreeMemBuffer OF((UzpBuffer *retstr));
#ifndef WINDLL
int UZ_EXP UzpUnzipToMemory OF((char *zip, char *file, UzpOpts *optflgs,
UzpCB *UsrFunc, UzpBuffer *retstr));
int UZ_EXP UzpGrep OF((char *archive, char *file,
char *pattern, int cmd, int SkipBin,
UzpCB *UsrFunc));
#endif
#ifdef OS2
int UZ_EXP UzpFileTree OF((char *name, cbList(callBack),
char *cpInclude[], char *cpExclude[]));
#endif
void UZ_EXP UzpVersion2 OF((UzpVer2 *version));
int UZ_EXP UzpValidate OF((char *archive, int AllCodes));
/* default I/O functions (can be swapped out via UzpAltMain() entry point): */
int UZ_EXP UzpMessagePrnt OF((zvoid *pG, uch *buf, ulg size, int flag));
int UZ_EXP UzpMessageNull OF((zvoid *pG, uch *buf, ulg size, int flag));
int UZ_EXP UzpInput OF((zvoid *pG, uch *buf, int *size, int flag));
void UZ_EXP UzpMorePause OF((zvoid *pG, ZCONST char *prompt, int flag));
int UZ_EXP UzpPassword OF((zvoid *pG, int *rcnt, char *pwbuf,
int size, ZCONST char *zfn,
ZCONST char *efn));
/*---------------------------------------------------------------------------
Remaining private stuff for UnZip compilation.
---------------------------------------------------------------------------*/
#ifdef UNZIP_INTERNAL
# include "unzpriv.h"
#endif
#endif /* !__unzip_h */

Binary file not shown.

View File

@ -0,0 +1,987 @@
UNZIP(1L) UNZIP(1L)
NAME
unzip - list, test and extract compressed files in a ZIP
archive
SYNOPSIS
unzip [-Z] [-cflptuvz[abjnoqsCLMVX$/:]] file[.zip]
[file(s) ...] [-x xfile(s) ...] [-d exdir]
DESCRIPTION
unzip will list, test, or extract files from a ZIP
archive, commonly found on MS-DOS systems. The default
behavior (with no options) is to extract into the current
directory (and subdirectories below it) all files from the
specified ZIP archive. A companion program, zip(1L), cre-
ates ZIP archives; both programs are compatible with
archives created by PKWARE's PKZIP and PKUNZIP for MS-DOS,
but in many cases the program options or default behaviors
differ.
ARGUMENTS
file[.zip]
Path of the ZIP archive(s). If the file specifica-
tion is a wildcard, each matching file is processed
in an order determined by the operating system (or
file system). Only the filename can be a wildcard;
the path itself cannot. Wildcard expressions are
similar to those supported in commonly used Unix
shells (sh, ksh, csh) and may contain:
* matches a sequence of 0 or more characters
? matches exactly 1 character
[...] matches any single character found inside
the brackets; ranges are specified by a
beginning character, a hyphen, and an ending
character. If an exclamation point or a
caret (`!' or `^') follows the left bracket,
then the range of characters within the
brackets is complemented (that is, anything
except the characters inside the brackets is
considered a match).
(Be sure to quote any character that might other-
wise be interpreted or modified by the operating
system, particularly under Unix and VMS.) If no
matches are found, the specification is assumed to
be a literal filename; and if that also fails, the
suffix .zip is appended. Note that self-extracting
ZIP files are supported, as with any other ZIP
archive; just specify the .exe suffix (if any)
explicitly.
Info-ZIP 17 February 2002 (v5.5) 1
UNZIP(1L) UNZIP(1L)
[file(s)]
An optional list of archive members to be pro-
cessed, separated by spaces. (VMS versions com-
piled with VMSCLI defined must delimit files with
commas instead. See -v in OPTIONS below.) Regular
expressions (wildcards) may be used to match multi-
ple members; see above. Again, be sure to quote
expressions that would otherwise be expanded or
modified by the operating system.
[-x xfile(s)]
An optional list of archive members to be excluded
from processing. Since wildcard characters match
directory separators (`/'), this option may be used
to exclude any files that are in subdirectories.
For example, ``unzip foo *.[ch] -x */*'' would
extract all C source files in the main directory,
but none in any subdirectories. Without the -x
option, all C source files in all directories
within the zipfile would be extracted.
[-d exdir]
An optional directory to which to extract files.
By default, all files and subdirectories are recre-
ated in the current directory; the -d option allows
extraction in an arbitrary directory (always assum-
ing one has permission to write to the directory).
This option need not appear at the end of the com-
mand line; it is also accepted before the zipfile
specification (with the normal options), immedi-
ately after the zipfile specification, or between
the file(s) and the -x option. The option and
directory may be concatenated without any white
space between them, but note that this may cause
normal shell behavior to be suppressed. In partic-
ular, ``-d ~'' (tilde) is expanded by Unix C shells
into the name of the user's home directory, but
``-d~'' is treated as a literal subdirectory ``~''
of the current directory.
OPTIONS
Note that, in order to support obsolescent hardware,
unzip's usage screen is limited to 22 or 23 lines and
should therefore be considered only a reminder of the
basic unzip syntax rather than an exhaustive list of all
possible flags. The exhaustive list follows:
-Z zipinfo(1L) mode. If the first option on the com-
mand line is -Z, the remaining options are taken to
be zipinfo(1L) options. See the appropriate manual
page for a description of these options.
-A [OS/2, Unix DLL] print extended help for the DLL's
programming interface (API).
Info-ZIP 17 February 2002 (v5.5) 2
UNZIP(1L) UNZIP(1L)
-c extract files to stdout/screen (``CRT''). This
option is similar to the -p option except that the
name of each file is printed as it is extracted,
the -a option is allowed, and ASCII-EBCDIC conver-
sion is automatically performed if appropriate.
This option is not listed in the unzip usage
screen.
-f freshen existing files, i.e., extract only those
files that already exist on disk and that are newer
than the disk copies. By default unzip queries
before overwriting, but the -o option may be used
to suppress the queries. Note that under many
operating systems, the TZ (timezone) environment
variable must be set correctly in order for -f and
-u to work properly (under Unix the variable is
usually set automatically). The reasons for this
are somewhat subtle but have to do with the differ-
ences between DOS-format file times (always local
time) and Unix-format times (always in GMT/UTC) and
the necessity to compare the two. A typical TZ
value is ``PST8PDT'' (US Pacific time with auto-
matic adjustment for Daylight Savings Time or
``summer time'').
-l list archive files (short format). The names,
uncompressed file sizes and modification dates and
times of the specified files are printed, along
with totals for all files specified. If UnZip was
compiled with OS2_EAS defined, the -l option also
lists columns for the sizes of stored OS/2 extended
attributes (EAs) and OS/2 access control lists
(ACLs). In addition, the zipfile comment and indi-
vidual file comments (if any) are displayed. If a
file was archived from a single-case file system
(for example, the old MS-DOS FAT file system) and
the -L option was given, the filename is converted
to lowercase and is prefixed with a caret (^).
-p extract files to pipe (stdout). Nothing but the
file data is sent to stdout, and the files are
always extracted in binary format, just as they are
stored (no conversions).
-t test archive files. This option extracts each
specified file in memory and compares the CRC
(cyclic redundancy check, an enhanced checksum) of
the expanded file with the original file's stored
CRC value.
-T [most OSes] set the timestamp on the archive(s) to
that of the newest file in each one. This corre-
sponds to zip's -go option except that it can be
used on wildcard zipfiles (e.g., ``unzip -T
Info-ZIP 17 February 2002 (v5.5) 3
UNZIP(1L) UNZIP(1L)
\*.zip'') and is much faster.
-u update existing files and create new ones if
needed. This option performs the same function as
the -f option, extracting (with query) files that
are newer than those with the same name on disk,
and in addition it extracts those files that do not
already exist on disk. See -f above for informa-
tion on setting the timezone properly.
-v be verbose or print diagnostic version info. This
option has evolved and now behaves as both an
option and a modifier. As an option it has two
purposes: when a zipfile is specified with no
other options, -v lists archive files verbosely,
adding to the basic -l info the compression method,
compressed size, compression ratio and 32-bit CRC.
When no zipfile is specified (that is, the complete
command is simply ``unzip -v''), a diagnostic
screen is printed. In addition to the normal
header with release date and version, unzip lists
the home Info-ZIP ftp site and where to find a list
of other ftp and non-ftp sites; the target operat-
ing system for which it was compiled, as well as
(possibly) the hardware on which it was compiled,
the compiler and version used, and the compilation
date; any special compilation options that might
affect the program's operation (see also DECRYPTION
below); and any options stored in environment vari-
ables that might do the same (see ENVIRONMENT
OPTIONS below). As a modifier it works in conjunc-
tion with other options (e.g., -t) to produce more
verbose or debugging output; this is not yet fully
implemented but will be in future releases.
-z display only the archive comment.
MODIFIERS
-a convert text files. Ordinarily all files are
extracted exactly as they are stored (as ``binary''
files). The -a option causes files identified by
zip as text files (those with the `t' label in zip-
info listings, rather than `b') to be automatically
extracted as such, converting line endings, end-of-
file characters and the character set itself as
necessary. (For example, Unix files use line feeds
(LFs) for end-of-line (EOL) and have no end-of-file
(EOF) marker; Macintoshes use carriage returns
(CRs) for EOLs; and most PC operating systems use
CR+LF for EOLs and control-Z for EOF. In addition,
IBM mainframes and the Michigan Terminal System use
EBCDIC rather than the more common ASCII character
set, and NT supports Unicode.) Note that zip's
identification of text files is by no means
Info-ZIP 17 February 2002 (v5.5) 4
UNZIP(1L) UNZIP(1L)
perfect; some ``text'' files may actually be binary
and vice versa. unzip therefore prints ``[text]''
or ``[binary]'' as a visual check for each file it
extracts when using the -a option. The -aa option
forces all files to be extracted as text, regard-
less of the supposed file type.
-b [general] treat all files as binary (no text con-
versions). This is a shortcut for ---a.
-b [Tandem] force the creation files with filecode
type 180 ('C') when extracting Zip entries marked
as "text". (On Tandem, -a is enabled by default,
see above).
-b [VMS] auto-convert binary files (see -a above) to
fixed-length, 512-byte record format. Doubling the
option (-bb) forces all files to be extracted in
this format. When extracting to standard output (-c
or -p option in effect), the default conversion of
text record delimiters is disabled for binary (-b)
resp. all (-bb) files.
-B [Unix only, and only if compiled with UNIXBACKUP
defined] save a backup copy of each overwritten
file with a tilde appended (e.g., the old copy of
``foo'' is renamed to ``foo~''). This is similar
to the default behavior of emacs(1) in many loca-
tions.
-C match filenames case-insensitively. unzip's phi-
losophy is ``you get what you ask for'' (this is
also responsible for the -L/-U change; see the rel-
evant options below). Because some file systems
are fully case-sensitive (notably those under the
Unix operating system) and because both ZIP
archives and unzip itself are portable across plat-
forms, unzip's default behavior is to match both
wildcard and literal filenames case-sensitively.
That is, specifying ``makefile'' on the command
line will only match ``makefile'' in the archive,
not ``Makefile'' or ``MAKEFILE'' (and similarly for
wildcard specifications). Since this does not cor-
respond to the behavior of many other operat-
ing/file systems (for example, OS/2 HPFS, which
preserves mixed case but is not sensitive to it),
the -C option may be used to force all filename
matches to be case-insensitive. In the example
above, all three files would then match ``make-
file'' (or ``make*'', or similar). The -C option
affects files in both the normal file list and the
excluded-file list (xlist).
-E [MacOS only] display contents of MacOS extra field
Info-ZIP 17 February 2002 (v5.5) 5
UNZIP(1L) UNZIP(1L)
during restore operation.
-F [Acorn only] suppress removal of NFS filetype
extension from stored filenames.
-F [non-Acorn systems supporting long filenames with
embedded commas, and only if compiled with
ACORN_FTYPE_NFS defined] translate filetype infor-
mation from ACORN RISC OS extra field blocks into a
NFS filetype extension and append it to the names
of the extracted files. (When the stored filename
appears to already have an appended NFS filetype
extension, it is replaced by the info from the
extra field.)
-i [MacOS only] ignore filenames stored in MacOS extra
fields. Instead, the most compatible filename
stored in the generic part of the entry's header is
used.
-j junk paths. The archive's directory structure is
not recreated; all files are deposited in the
extraction directory (by default, the current one).
-J [BeOS only] junk file attributes. The file's BeOS
file attributes are not restored, just the file's
data.
-J [MacOS only] ignore MacOS extra fields. All Macin-
tosh specific info is skipped. Data-fork and
resource-fork are restored as separate files.
-L convert to lowercase any filename originating on an
uppercase-only operating system or file system.
(This was unzip's default behavior in releases
prior to 5.11; the new default behavior is identi-
cal to the old behavior with the -U option, which
is now obsolete and will be removed in a future
release.) Depending on the archiver, files
archived under single-case file systems (VMS, old
MS-DOS FAT, etc.) may be stored as all-uppercase
names; this can be ugly or inconvenient when
extracting to a case-preserving file system such as
OS/2 HPFS or a case-sensitive one such as under
Unix. By default unzip lists and extracts such
filenames exactly as they're stored (excepting
truncation, conversion of unsupported characters,
etc.); this option causes the names of all files
from certain systems to be converted to lowercase.
The -LL option forces conversion of every filename
to lowercase, regardless of the originating file
system.
-M pipe all output through an internal pager similar
Info-ZIP 17 February 2002 (v5.5) 6
UNZIP(1L) UNZIP(1L)
to the Unix more(1) command. At the end of a
screenful of output, unzip pauses with a
``--More--'' prompt; the next screenful may be
viewed by pressing the Enter (Return) key or the
space bar. unzip can be terminated by pressing the
``q'' key and, on some systems, the Enter/Return
key. Unlike Unix more(1), there is no forward-
searching or editing capability. Also, unzip
doesn't notice if long lines wrap at the edge of
the screen, effectively resulting in the printing
of two or more lines and the likelihood that some
text will scroll off the top of the screen before
being viewed. On some systems the number of avail-
able lines on the screen is not detected, in which
case unzip assumes the height is 24 lines.
-n never overwrite existing files. If a file already
exists, skip the extraction of that file without
prompting. By default unzip queries before
extracting any file that already exists; the user
may choose to overwrite only the current file,
overwrite all files, skip extraction of the current
file, skip extraction of all existing files, or
rename the current file.
-N [Amiga] extract file comments as Amiga filenotes.
File comments are created with the -c option of
zip(1L), or with the -N option of the Amiga port of
zip(1L), which stores filenotes as comments.
-o overwrite existing files without prompting. This
is a dangerous option, so use it with care. (It is
often used with -f, however, and is the only way to
overwrite directory EAs under OS/2.)
-P password
use password to decrypt encrypted zipfile entries
(if any). THIS IS INSECURE! Many multi-user oper-
ating systems provide ways for any user to see the
current command line of any other user; even on
stand-alone systems there is always the threat of
over-the-shoulder peeking. Storing the plaintext
password as part of a command line in an automated
script is even worse. Whenever possible, use the
non-echoing, interactive prompt to enter passwords.
(And where security is truly important, use strong
encryption such as Pretty Good Privacy instead of
the relatively weak encryption provided by standard
zipfile utilities.)
-q perform operations quietly (-qq = even quieter).
Ordinarily unzip prints the names of the files it's
extracting or testing, the extraction methods, any
file or zipfile comments that may be stored in the
Info-ZIP 17 February 2002 (v5.5) 7
UNZIP(1L) UNZIP(1L)
archive, and possibly a summary when finished with
each archive. The -q[q] options suppress the
printing of some or all of these messages.
-s [OS/2, NT, MS-DOS] convert spaces in filenames to
underscores. Since all PC operating systems allow
spaces in filenames, unzip by default extracts
filenames with spaces intact (e.g.,
``EA DATA. SF''). This can be awkward, however,
since MS-DOS in particular does not gracefully sup-
port spaces in filenames. Conversion of spaces to
underscores can eliminate the awkwardness in some
cases.
-U (obsolete; to be removed in a future release) leave
filenames uppercase if created under MS-DOS, VMS,
etc. See -L above.
-V retain (VMS) file version numbers. VMS files can
be stored with a version number, in the format
file.ext;##. By default the ``;##'' version num-
bers are stripped, but this option allows them to
be retained. (On file systems that limit filenames
to particularly short lengths, the version numbers
may be truncated or stripped regardless of this
option.)
-X [VMS, Unix, OS/2, NT] restore owner/protection info
(UICs) under VMS, or user and group info (UID/GID)
under Unix, or access control lists (ACLs) under
certain network-enabled versions of OS/2 (Warp
Server with IBM LAN Server/Requester 3.0 to 5.0;
Warp Connect with IBM Peer 1.0), or security ACLs
under Windows NT. In most cases this will require
special system privileges, and doubling the option
(-XX) under NT instructs unzip to use privileges
for extraction; but under Unix, for example, a user
who belongs to several groups can restore files
owned by any of those groups, as long as the user
IDs match his or her own. Note that ordinary file
attributes are always restored--this option applies
only to optional, extra ownership info available on
some operating systems. [NT's access control lists
do not appear to be especially compatible with
OS/2's, so no attempt is made at cross-platform
portability of access privileges. It is not clear
under what conditions this would ever be useful
anyway.]
-$ [MS-DOS, OS/2, NT] restore the volume label if the
extraction medium is removable (e.g., a diskette).
Doubling the option (-$$) allows fixed media (hard
disks) to be labelled as well. By default, volume
labels are ignored.
Info-ZIP 17 February 2002 (v5.5) 8
UNZIP(1L) UNZIP(1L)
-/ extensions
[Acorn only] overrides the extension list supplied
by Unzip$Ext environment variable. During extrac-
tion, filename extensions that match one of the
items in this extension list are swapped in front
of the base name of the extracted file.
-: [all but Acorn, VM/CMS, MVS, Tandem] allows to
extract archive members into locations outside of
the current `` extraction root folder''. For secu-
rity reasons, unzip normally removes ``parent dir''
path components (``../'') from the names of
extracted file. This safety feature (new for ver-
sion 5.50) prevents unzip from accidentally writing
files to ``sensitive'' areas outside the active
extraction folder tree head. The -: option lets
unzip switch back to its previous, more liberal
behaviour, to allow exact extraction of (older)
archives that used ``../'' components to create
multiple directory trees at the level of the cur-
rent extraction folder.
ENVIRONMENT OPTIONS
unzip's default behavior may be modified via options
placed in an environment variable. This can be done with
any option, but it is probably most useful with the -a,
-L, -C, -q, -o, or -n modifiers: make unzip auto-convert
text files by default, make it convert filenames from
uppercase systems to lowercase, make it match names case-
insensitively, make it quieter, or make it always over-
write or never overwrite files as it extracts them. For
example, to make unzip act as quietly as possible, only
reporting errors, one would use one of the following com-
mands:
Unix Bourne shell:
UNZIP=-qq; export UNZIP
Unix C shell:
setenv UNZIP -qq
OS/2 or MS-DOS:
set UNZIP=-qq
VMS (quotes for lowercase):
define UNZIP_OPTS ""-qq""
Environment options are, in effect, considered to be just
like any other command-line options, except that they are
effectively the first options on the command line. To
override an environment option, one may use the ``minus
operator'' to remove it. For instance, to override one of
the quiet-flags in the example above, use the command
Info-ZIP 17 February 2002 (v5.5) 9
UNZIP(1L) UNZIP(1L)
unzip --q[other options] zipfile
The first hyphen is the normal switch character, and the
second is a minus sign, acting on the q option. Thus the
effect here is to cancel one quantum of quietness. To
cancel both quiet flags, two (or more) minuses may be
used:
unzip -t--q zipfile
unzip ---qt zipfile
(the two are equivalent). This may seem awkward or con-
fusing, but it is reasonably intuitive: just ignore the
first hyphen and go from there. It is also consistent
with the behavior of Unix nice(1).
As suggested by the examples above, the default variable
names are UNZIP_OPTS for VMS (where the symbol used to
install unzip as a foreign command would otherwise be con-
fused with the environment variable), and UNZIP for all
other operating systems. For compatibility with zip(1L),
UNZIPOPT is also accepted (don't ask). If both UNZIP and
UNZIPOPT are defined, however, UNZIP takes precedence.
unzip's diagnostic option (-v with no zipfile name) can be
used to check the values of all four possible unzip and
zipinfo environment variables.
The timezone variable (TZ) should be set according to the
local timezone in order for the -f and -u to operate cor-
rectly. See the description of -f above for details.
This variable may also be necessary in order for times-
tamps on extracted files to be set correctly. Under Win-
dows 95/NT unzip should know the correct timezone even if
TZ is unset, assuming the timezone is correctly set in the
Control Panel.
DECRYPTION
Encrypted archives are fully supported by Info-ZIP soft-
ware, but due to United States export restrictions,
de-/encryption support might be disabled in your compiled
binary. However, since spring 2000, US export restric-
tions have been liberated, and our source archives do now
include full crypt code. In case you need binary distri-
butions with crypt support enabled, see the file ``WHERE''
in any Info-ZIP source or binary distribution for loca-
tions both inside and outside the US.
Some compiled versions of unzip may not support decryp-
tion. To check a version for crypt support, either
attempt to test or extract an encrypted archive, or else
check unzip's diagnostic screen (see the -v option above)
for ``[decryption]'' as one of the special compilation
options.
Info-ZIP 17 February 2002 (v5.5) 10
UNZIP(1L) UNZIP(1L)
As noted above, the -P option may be used to supply a
password on the command line, but at a cost in security.
The preferred decryption method is simply to extract nor-
mally; if a zipfile member is encrypted, unzip will prompt
for the password without echoing what is typed. unzip
continues to use the same password as long as it appears
to be valid, by testing a 12-byte header on each file.
The correct password will always check out against the
header, but there is a 1-in-256 chance that an incorrect
password will as well. (This is a security feature of the
PKWARE zipfile format; it helps prevent brute-force
attacks that might otherwise gain a large speed advantage
by testing only the header.) In the case that an incor-
rect password is given but it passes the header test any-
way, either an incorrect CRC will be generated for the
extracted data or else unzip will fail during the extrac-
tion because the ``decrypted'' bytes do not constitute a
valid compressed data stream.
If the first password fails the header check on some file,
unzip will prompt for another password, and so on until
all files are extracted. If a password is not known,
entering a null password (that is, just a carriage return
or ``Enter'') is taken as a signal to skip all further
prompting. Only unencrypted files in the archive(s) will
thereafter be extracted. (In fact, that's not quite true;
older versions of zip(1L) and zipcloak(1L) allowed null
passwords, so unzip checks each encrypted file to see if
the null password works. This may result in ``false posi-
tives'' and extraction errors, as noted above.)
Archives encrypted with 8-bit passwords (for example,
passwords with accented European characters) may not be
portable across systems and/or other archivers. This
problem stems from the use of multiple encoding methods
for such characters, including Latin-1 (ISO 8859-1) and
OEM code page 850. DOS PKZIP 2.04g uses the OEM code
page; Windows PKZIP 2.50 uses Latin-1 (and is therefore
incompatible with DOS PKZIP); Info-ZIP uses the OEM code
page on DOS, OS/2 and Win3.x ports but Latin-1 everywhere
else; and Nico Mak's WinZip 6.x does not allow 8-bit pass-
words at all. UnZip 5.3 (or newer) attempts to use the
default character set first (e.g., Latin-1), followed by
the alternate one (e.g., OEM code page) to test passwords.
On EBCDIC systems, if both of these fail, EBCDIC encoding
will be tested as a last resort. (EBCDIC is not tested on
non-EBCDIC systems, because there are no known archivers
that encrypt using EBCDIC encoding.) ISO character encod-
ings other than Latin-1 are not supported.
EXAMPLES
To use unzip to extract all members of the archive let-
ters.zip into the current directory and subdirectories
below it, creating any subdirectories as necessary:
Info-ZIP 17 February 2002 (v5.5) 11
UNZIP(1L) UNZIP(1L)
unzip letters
To extract all members of letters.zip into the current
directory only:
unzip -j letters
To test letters.zip, printing only a summary message indi-
cating whether the archive is OK or not:
unzip -tq letters
To test all zipfiles in the current directory, printing
only the summaries:
unzip -tq \*.zip
(The backslash before the asterisk is only required if the
shell expands wildcards, as in Unix; double quotes could
have been used instead, as in the source examples
below.) To extract to standard output all members of let-
ters.zip whose names end in .tex, auto-converting to the
local end-of-line convention and piping the output into
more(1):
unzip -ca letters \*.tex | more
To extract the binary file paper1.dvi to standard output
and pipe it to a printing program:
unzip -p articles paper1.dvi | dvips
To extract all FORTRAN and C source files--*.f, *.c, *.h,
and Makefile--into the /tmp directory:
unzip source.zip "*.[fch]" Makefile -d /tmp
(the double quotes are necessary only in Unix and only if
globbing is turned on). To extract all FORTRAN and C
source files, regardless of case (e.g., both *.c and *.C,
and any makefile, Makefile, MAKEFILE or similar):
unzip -C source.zip "*.[fch]" makefile -d /tmp
To extract any such files but convert any uppercase MS-DOS
or VMS names to lowercase and convert the line-endings of
all of the files to the local standard (without respect to
any files that might be marked ``binary''):
unzip -aaCL source.zip "*.[fch]" makefile -d /tmp
To extract only newer versions of the files already in the
current directory, without querying (NOTE: be careful of
unzipping in one timezone a zipfile created in
Info-ZIP 17 February 2002 (v5.5) 12
UNZIP(1L) UNZIP(1L)
another--ZIP archives other than those created by Zip 2.1
or later contain no timezone information, and a ``newer''
file from an eastern timezone may, in fact, be older):
unzip -fo sources
To extract newer versions of the files already in the cur-
rent directory and to create any files not already there
(same caveat as previous example):
unzip -uo sources
To display a diagnostic screen showing which unzip and
zipinfo options are stored in environment variables,
whether decryption support was compiled in, the compiler
with which unzip was compiled, etc.:
unzip -v
In the last five examples, assume that UNZIP or UNZIP_OPTS
is set to -q. To do a singly quiet listing:
unzip -l file.zip
To do a doubly quiet listing:
unzip -ql file.zip
(Note that the ``.zip'' is generally not necessary.) To
do a standard listing:
unzip --ql file.zip
or
unzip -l-q file.zip
or
unzip -l--q file.zip
(Extra minuses in options don't hurt.)
TIPS
The current maintainer, being a lazy sort, finds it very
useful to define a pair of aliases: tt for ``unzip -tq''
and ii for ``unzip -Z'' (or ``zipinfo''). One may then
simply type ``tt zipfile'' to test an archive, something
that is worth making a habit of doing. With luck unzip
will report ``No errors detected in compressed data of
zipfile.zip,'' after which one may breathe a sigh of
relief.
The maintainer also finds it useful to set the UNZIP envi-
ronment variable to ``-aL'' and is tempted to add ``-C''
as well. His ZIPINFO variable is set to ``-z''.
DIAGNOSTICS
The exit status (or error level) approximates the exit
Info-ZIP 17 February 2002 (v5.5) 13
UNZIP(1L) UNZIP(1L)
codes defined by PKWARE and takes on the following values,
except under VMS:
0 normal; no errors or warnings detected.
1 one or more warning errors were encountered,
but processing completed successfully any-
way. This includes zipfiles where one or
more files was skipped due to unsupported
compression method or encryption with an
unknown password.
2 a generic error in the zipfile format was
detected. Processing may have completed
successfully anyway; some broken zipfiles
created by other archivers have simple work-
arounds.
3 a severe error in the zipfile format was
detected. Processing probably failed imme-
diately.
4 unzip was unable to allocate memory for one
or more buffers during program initializa-
tion.
5 unzip was unable to allocate memory or
unable to obtain a tty to read the decryp-
tion password(s).
6 unzip was unable to allocate memory during
decompression to disk.
7 unzip was unable to allocate memory during
in-memory decompression.
8 [currently not used]
9 the specified zipfiles were not found.
10 invalid options were specified on the com-
mand line.
11 no matching files were found.
50 the disk is (or was) full during extraction.
51 the end of the ZIP archive was encountered
prematurely.
80 the user aborted unzip prematurely with con-
trol-C (or similar)
81 testing or extraction of one or more files
Info-ZIP 17 February 2002 (v5.5) 14
UNZIP(1L) UNZIP(1L)
failed due to unsupported compression meth-
ods or unsupported decryption.
82 no files were found due to bad decryption
password(s). (If even one file is success-
fully processed, however, the exit status is
1.)
VMS interprets standard Unix (or PC) return values as
other, scarier-looking things, so unzip instead maps them
into VMS-style status codes. The current mapping is as
follows: 1 (success) for normal exit, 0x7fff0001 for
warning errors, and (0x7fff000? + 16*nor-
mal_unzip_exit_status) for all other errors, where the `?'
is 2 (error) for unzip values 2, 9-11 and 80-82, and 4
(fatal error) for the remaining ones (3-8, 50, 51). In
addition, there is a compilation option to expand upon
this behavior: defining RETURN_CODES results in a human-
readable explanation of what the error status means.
BUGS
Multi-part archives are not yet supported, except in con-
junction with zip. (All parts must be concatenated
together in order, and then ``zip -F'' must be performed
on the concatenated archive in order to ``fix'' it.) This
will definitely be corrected in the next major release.
Archives read from standard input are not yet supported,
except with funzip (and then only the first member of the
archive can be extracted).
Archives encrypted with 8-bit passwords (e.g., passwords
with accented European characters) may not be portable
across systems and/or other archivers. See the discussion
in DECRYPTION above.
unzip's -M (``more'') option is overly simplistic in its
handling of screen output; as noted above, it fails to
detect the wrapping of long lines and may thereby cause
lines at the top of the screen to be scrolled off before
being read. unzip should detect and treat each occurrence
of line-wrap as one additional line printed. This
requires knowledge of the screen's width as well as its
height. In addition, unzip should detect the true screen
geometry on all systems.
Dates, times and permissions of stored directories are not
restored except under Unix.
[MS-DOS] When extracting or testing files from an archive
on a defective floppy diskette, if the ``Fail'' option is
chosen from DOS's ``Abort, Retry, Fail?'' message, older
versions of unzip may hang the system, requiring a reboot.
This problem appears to be fixed, but control-C (or
Info-ZIP 17 February 2002 (v5.5) 15
UNZIP(1L) UNZIP(1L)
control-Break) can still be used to terminate unzip.
Under DEC Ultrix, unzip would sometimes fail on long zip-
files (bad CRC, not always reproducible). This was appar-
ently due either to a hardware bug (cache memory) or an
operating system bug (improper handling of page faults?).
Since Ultrix has been abandoned in favor of Digital Unix
(OSF/1), this may not be an issue anymore.
[Unix] Unix special files such as FIFO buffers (named
pipes), block devices and character devices are not
restored even if they are somehow represented in the zip-
file, nor are hard-linked files relinked. Basically the
only file types restored by unzip are regular files,
directories and symbolic (soft) links.
[OS/2] Extended attributes for existing directories are
only updated if the -o (``overwrite all'') option is
given. This is a limitation of the operating system;
because directories only have a creation time associated
with them, unzip has no way to determine whether the
stored attributes are newer or older than those on disk.
In practice this may mean a two-pass approach is required:
first unpack the archive normally (with or without fresh-
ening/updating existing files), then overwrite just the
directory entries (e.g., ``unzip -o foo */'').
[VMS] When extracting to another directory, only the
[.foo] syntax is accepted for the -d option; the simple
Unix foo syntax is silently ignored (as is the less common
VMS foo.dir syntax).
[VMS] When the file being extracted already exists,
unzip's query only allows skipping, overwriting or renam-
ing; there should additionally be a choice for creating a
new version of the file. In fact, the ``overwrite''
choice does create a new version; the old version is not
overwritten or deleted.
SEE ALSO
funzip(1L), zip(1L), zipcloak(1L), zipgrep(1L), zip-
info(1L), zipnote(1L), zipsplit(1L)
URL
The Info-ZIP home page is currently at
http://www.info-zip.org/pub/infozip/
or
ftp://ftp.info-zip.org/pub/infozip/ .
AUTHORS
The primary Info-ZIP authors (current semi-active members
of the Zip-Bugs workgroup) are: Greg ``Cave Newt''
Roelofs (UnZip); Onno van der Linden (Zip); Jean-loup
Gailly (compression); Mark Adler (decompression, fUnZip);
Info-ZIP 17 February 2002 (v5.5) 16
UNZIP(1L) UNZIP(1L)
Christian Spieler (UnZip maintance coordination, VMS, MS-
DOS, Windows 95, NT, shared code, general Zip and UnZip
integration and optimization); Mike White (Windows GUI,
Windows DLLs); Kai Uwe Rommel (OS/2); Paul Kienitz (Amiga,
Windows 95); Chris Herborth (BeOS, QNX, Atari); Jonathan
Hudson (SMS/QDOS); Sergio Monesi (Acorn RISC OS); Harald
Denker (Atari, MVS); John Bush (Solaris, Amiga); Hunter
Goatley (VMS); Steve Salisbury (Windows 95, NT); Steve
Miller (Windows CE GUI), Johnny Lee (MS-DOS, Windows 95,
NT); and Dave Smith (Tandem NSK). The author of the orig-
inal unzip code upon which Info-ZIP's was based is Samuel
H. Smith; Carl Mascott did the first Unix port; and David
P. Kirschbaum organized and led Info-ZIP in its early
days with Keith Petersen hosting the original mailing list
at WSMR-SimTel20. The full list of contributors to UnZip
has grown quite large; please refer to the CONTRIBS file
in the UnZip source distribution for a relatively complete
version.
VERSIONS
v1.2 15 Mar 89 Samuel H. Smith
v2.0 9 Sep 89 Samuel H. Smith
v2.x fall 1989 many Usenet contributors
v3.0 1 May 90 Info-ZIP (DPK, consolidator)
v3.1 15 Aug 90 Info-ZIP (DPK, consolidator)
v4.0 1 Dec 90 Info-ZIP (GRR, maintainer)
v4.1 12 May 91 Info-ZIP
v4.2 20 Mar 92 Info-ZIP (Zip-Bugs subgroup, GRR)
v5.0 21 Aug 92 Info-ZIP (Zip-Bugs subgroup, GRR)
v5.01 15 Jan 93 Info-ZIP (Zip-Bugs subgroup, GRR)
v5.1 7 Feb 94 Info-ZIP (Zip-Bugs subgroup, GRR)
v5.11 2 Aug 94 Info-ZIP (Zip-Bugs subgroup, GRR)
v5.12 28 Aug 94 Info-ZIP (Zip-Bugs subgroup, GRR)
v5.2 30 Apr 96 Info-ZIP (Zip-Bugs subgroup, GRR)
v5.3 22 Apr 97 Info-ZIP (Zip-Bugs subgroup, GRR)
v5.31 31 May 97 Info-ZIP (Zip-Bugs subgroup, GRR)
v5.32 3 Nov 97 Info-ZIP (Zip-Bugs subgroup, GRR)
v5.4 28 Nov 98 Info-ZIP (Zip-Bugs subgroup, SPC)
v5.41 16 Apr 00 Info-ZIP (Zip-Bugs subgroup, SPC)
v5.42 14 Jan 01 Info-ZIP (Zip-Bugs subgroup, SPC)
v5.5 17 Feb 02 Info-ZIP (Zip-Bugs subgroup, SPC)
Info-ZIP 17 February 2002 (v5.5) 17

Binary file not shown.

View File

@ -0,0 +1,342 @@
UNZIPSFX(1L) UNZIPSFX(1L)
NAME
unzipsfx - self-extracting stub for prepending to ZIP
archives
SYNOPSIS
<name of unzipsfx+archive combo> [-cfptuz[ajnoqsCLV$]]
[file(s) ... [-x xfile(s) ...]]
DESCRIPTION
unzipsfx is a modified version of unzip(1L) designed to be
prepended to existing ZIP archives in order to form self-
extracting archives. Instead of taking its first non-flag
argument to be the zipfile(s) to be extracted, unzipsfx
seeks itself under the name by which it was invoked and
tests or extracts the contents of the appended archive.
Because the executable stub adds bulk to the archive (the
whole purpose of which is to be as small as possible), a
number of the less-vital capabilities in regular unzip
have been removed. Among these are the usage (or help)
screen, the listing and diagnostic functions (-l and -v),
the ability to decompress older compression formats (the
``reduce,'' ``shrink'' and ``implode'' methods). The
ability to extract to a directory other than the current
one can be selected as a compile-time option, which is now
enabled by default since UnZipSFX version 5.5. Similary,
decryption is supported as a compile-time option but
should be avoided unless the attached archive contains
encrypted files. Starting with release 5.5, another com-
pile-time option adds a simple ``run command after extrac-
tion'' feature. This feature is currently incompatible
with the ``extract to different directory'' feature and
remains disabled by default.
Note that self-extracting archives made with unzipsfx are
no more (or less) portable across different operating sys-
tems than is the unzip executable itself. In general a
self-extracting archive made on a particular Unix system,
for example, will only self-extract under the same flavor
of Unix. Regular unzip may still be used to extract the
embedded archive as with any normal zipfile, although it
will generate a harmless warning about extra bytes at the
beginning of the zipfile. Despite this, however, the
self-extracting archive is technically not a valid ZIP
archive, and PKUNZIP may be unable to test or extract it.
This limitation is due to the simplistic manner in which
the archive is created; the internal directory structure
is not updated to reflect the extra bytes prepended to the
original zipfile.
ARGUMENTS
[file(s)]
An optional list of archive members to be pro-
cessed. Regular expressions (wildcards) similar to
those in Unix egrep(1) may be used to match
Info-ZIP 17 February 2002 (v5.5) 1
UNZIPSFX(1L) UNZIPSFX(1L)
multiple members. These wildcards may contain:
* matches a sequence of 0 or more characters
? matches exactly 1 character
[...] matches any single character found inside
the brackets; ranges are specified by a
beginning character, a hyphen, and an ending
character. If an exclamation point or a
caret (`!' or `^') follows the left bracket,
then the range of characters within the
brackets is complemented (that is, anything
except the characters inside the brackets is
considered a match).
(Be sure to quote any character that might other-
wise be interpreted or modified by the operating
system, particularly under Unix and VMS.)
[-x xfile(s)]
An optional list of archive members to be excluded
from processing. Since wildcard characters match
directory separators (`/'), this option may be used
to exclude any files that are in subdirectories.
For example, ``foosfx *.[ch] -x */*'' would extract
all C source files in the main directory, but none
in any subdirectories. Without the -x option, all
C source files in all directories within the zip-
file would be extracted.
If unzipsfx is compiled with SFX_EXDIR defined, the fol-
lowing option is also enabled:
[-d exdir]
An optional directory to which to extract files.
By default, all files and subdirectories are recre-
ated in the current directory; the -d option allows
extraction in an arbitrary directory (always assum-
ing one has permission to write to the directory).
The option and directory may be concatenated with-
out any white space between them, but note that
this may cause normal shell behavior to be sup-
pressed. In particular, ``-d ~'' (tilde) is
expanded by Unix C shells into the name of the
user's home directory, but ``-d~'' is treated as a
literal subdirectory ``~'' of the current direc-
tory.
OPTIONS
unzipsfx supports the following unzip(1L) options: -c and
-p (extract to standard output/screen), -f and -u (freshen
and update existing files upon extraction), -t (test
archive) and -z (print archive comment). All normal
Info-ZIP 17 February 2002 (v5.5) 2
UNZIPSFX(1L) UNZIPSFX(1L)
listing options (-l, -v and -Z) have been removed, but the
testing option (-t) may be used as a ``poor man's'' list-
ing. Alternatively, those creating self-extracting
archives may wish to include a short listing in the zip-
file comment.
See unzip(1L) for a more complete description of these
options.
MODIFIERS
unzipsfx currently supports all unzip(1L) modifiers: -a
(convert text files), -n (never overwrite), -o (overwrite
without prompting), -q (operate quietly), -C (match names
case-insensitively), -L (convert uppercase-OS names to
lowercase), -j (junk paths) and -V (retain version num-
bers); plus the following operating-system specific
options: -X (restore VMS owner/protection info), -s (con-
vert spaces in filenames to underscores [DOS, OS/2, NT])
and -$ (restore volume label [DOS, OS/2, NT, Amiga]).
(Support for regular ASCII text-conversion may be removed
in future versions, since it is simple enough for the
archive's creator to ensure that text files have the
appropriate format for the local OS. EBCDIC conversion
will of course continue to be supported since the zipfile
format implies ASCII storage of text files.)
See unzip(1L) for a more complete description of these
modifiers.
ENVIRONMENT OPTIONS
unzipsfx uses the same environment variables as unzip(1L)
does, although this is likely to be an issue only for the
person creating and testing the self-extracting archive.
See unzip(1L) for details.
DECRYPTION
Decryption is supported exactly as in unzip(1L); that is,
interactively with a non-echoing prompt for the pass-
word(s). See unzip(1L) for details. Once again, note
that if the archive has no encrypted files there is no
reason to use a version of unzipsfx with decryption sup-
port; that only adds to the size of the archive.
AUTORUN COMMAND
When unzipsfx was compiled with CHEAP_SFX_AUTORUN defined,
a simple ``command autorun'' feature is supported. You may
enter a command into the Zip archive comment, using the
following format:
$AUTORUN$>[command line string]
When unzipsfxP recognizes the ``$AUTORUN$>'' token at the
beginning of the Zip archive comment, the remainder of the
Info-ZIP 17 February 2002 (v5.5) 3
UNZIPSFX(1L) UNZIPSFX(1L)
first line of the comment (until the first newline charac-
ter) is passed as a shell command to the operating system
using the C rtl ``system'' function. Before executing the
command, unzipsfxP displays the command on the console and
prompts the user for confirmation. When the user has
switched off prompting by specifying the -q option,
autorun commands are never executed.
In case the archive comment contains additonal lines of
text, the remainder of the archive comment following the
first line is displayed normally, unless quiet operation
was requested by supplying a -q option.
EXAMPLES
To create a self-extracting archive letters from a regular
zipfile letters.zip and change the new archive's permis-
sions to be world-executable under Unix:
cat unzipsfx letters.zip > letters
chmod 755 letters
zip -A letters
To create the same archive under MS-DOS, OS/2 or NT (note
the use of the /b [binary] option to the copy command):
copy /b unzipsfx.exe+letters.zip letters.exe
zip -A letters.exe
Under VMS:
copy unzipsfx.exe,letters.zip letters.exe
letters == "$currentdisk:[currentdir]letters.exe"
zip -A letters.exe
(The VMS append command may also be used. The second com-
mand installs the new program as a ``foreign command''
capable of taking arguments. The third line assumes that
Zip is already installed as a foreign command.) Under
AmigaDOS:
MakeSFX letters letters.zip UnZipSFX
(MakeSFX is included with the UnZip source distribution
and with Amiga binary distributions. ``zip -A'' doesn't
work on Amiga self-extracting archives.) To test (or
list) the newly created self-extracting archive:
letters -t
To test letters quietly, printing only a summary message
indicating whether the archive is OK or not:
letters -tqq
Info-ZIP 17 February 2002 (v5.5) 4
UNZIPSFX(1L) UNZIPSFX(1L)
To extract the complete contents into the current direc-
tory, recreating all files and subdirectories as neces-
sary:
letters
To extract all *.txt files (in Unix quote the `*'):
letters *.txt
To extract everything except the *.txt files:
letters -x *.txt
To extract only the README file to standard output (the
screen):
letters -c README
To print only the zipfile comment:
letters -z
LIMITATIONS
The principle and fundamental limitation of unzipsfx is
that it is not portable across architectures or operating
systems, and therefore neither are the resulting archives.
For some architectures there is limited portability, how-
ever (e.g., between some flavors of Intel-based Unix).
Another problem with the current implementation is that
any archive with ``junk'' prepended to the beginning tech-
nically is no longer a zipfile (unless zip(1) is used to
adjust the zipfile offsets appropriately, as noted above).
unzip(1) takes note of the prepended bytes and ignores
them since some file-transfer protocols, notably MacBi-
nary, are also known to prepend junk. But PKWARE's
archiver suite may not be able to deal with the modified
archive unless its offsets have been adjusted.
unzipsfx has no knowledge of the user's PATH, so in gen-
eral an archive must either be in the current directory
when it is invoked, or else a full or relative path must
be given. If a user attempts to extract the archive from
a directory in the PATH other than the current one,
unzipsfx will print a warning to the effect, ``can't find
myself.'' This is always true under Unix and may be true
in some cases under MS-DOS, depending on the compiler used
(Microsoft C fully qualifies the program name, but other
compilers may not). Under OS/2 and NT there are operat-
ing-system calls available that provide the full path
name, so the archive may be invoked from anywhere in the
user's path. The situation is not known for AmigaDOS,
Atari TOS, MacOS, etc.
Info-ZIP 17 February 2002 (v5.5) 5
UNZIPSFX(1L) UNZIPSFX(1L)
As noted above, a number of the normal unzip(1L) functions
have been removed in order to make unzipsfx smaller:
usage and diagnostic info, listing functions and extrac-
tion to other directories. Also, only stored and deflated
files are supported. The latter limitation is mainly rel-
evant to those who create SFX archives, however.
VMS users must know how to set up self-extracting archives
as foreign commands in order to use any of unzipsfx's
options. This is not necessary for simple extraction, but
the command to do so then becomes, e.g., ``run letters''
(to continue the examples given above).
unzipsfx on the Amiga requires the use of a special pro-
gram, MakeSFX, in order to create working self-extracting
archives; simple concatenation does not work. (For tech-
nically oriented users, the attached archive is defined as
a ``debug hunk.'') There may be compatibility problems
between the ROM levels of older Amigas and newer ones.
All current bugs in unzip(1L) exist in unzipsfx as well.
DIAGNOSTICS
unzipsfx's exit status (error level) is identical to that
of unzip(1L); see the corresponding man page.
SEE ALSO
funzip(1L), unzip(1L), zip(1L), zipcloak(1L), zipgrep(1L),
zipinfo(1L), zipnote(1L), zipsplit(1L)
URL
The Info-ZIP home page is currently at
http://www.info-zip.org/pub/infozip/
or
ftp://ftp.info-zip.org/pub/infozip/ .
AUTHORS
Greg Roelofs was responsible for the basic modifications
to UnZip necessary to create UnZipSFX. See unzip(1L) for
the current list of Zip-Bugs authors, or the file CONTRIBS
in the UnZip source distribution for the full list of
Info-ZIP contributors.
Info-ZIP 17 February 2002 (v5.5) 6

View File

@ -0,0 +1,56 @@
/*
Copyright (c) 1990-2001 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
*/
/*---------------------------------------------------------------------------
unzipstb.c
Simple stub function for UnZip DLL (or shared library, whatever); does
exactly the same thing as normal UnZip, except for additional printf()s
of various version numbers, solely as a demonstration of what can/should
be checked when using the DLL. (If major version numbers ever differ,
assume program is incompatible with DLL--especially if DLL version is
older. This is not likely to be a problem with *this* simple program,
but most user programs will be much more complex.)
---------------------------------------------------------------------------*/
#include <stdio.h>
#include "unzip.h"
#include "unzvers.h"
int main(int argc, char *argv[])
{
static UzpVer *pVersion; /* no pervert jokes, please... */
pVersion = UzpVersion();
printf("UnZip stub: checking version numbers (DLL is dated %s)\n",
pVersion->date);
printf(" UnZip versions: expecting %d.%d%d, using %d.%d%d%s\n",
UZ_MAJORVER, UZ_MINORVER, UZ_PATCHLEVEL, pVersion->unzip.major,
pVersion->unzip.minor, pVersion->unzip.patchlevel, pVersion->betalevel);
printf(" ZipInfo versions: expecting %d.%d%d, using %d.%d%d\n",
ZI_MAJORVER, ZI_MINORVER, UZ_PATCHLEVEL, pVersion->zipinfo.major,
pVersion->zipinfo.minor, pVersion->zipinfo.patchlevel);
/*
D2_M*VER and os2dll.* are obsolete, though retained for compatibility:
printf(" OS2 DLL versions: expecting %d.%d%d, using %d.%d%d\n",
D2_MAJORVER, D2_MINORVER, D2_PATCHLEVEL, pVersion->os2dll.major,
pVersion->os2dll.minor, pVersion->os2dll.patchlevel);
*/
if (pVersion->flag & 2)
printf(" using zlib version %s\n", pVersion->zlib_version);
printf("\n");
/* call the actual UnZip routine (string-arguments version) */
return UzpMain(argc, argv);
}

2479
src/apps/bin/unzip/unzpriv.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,58 @@
/*
Copyright (c) 1990-2002 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
*/
/*
unzvers.h (for UnZip) by Info-ZIP.
*/
#ifndef __unzvers_h /* don't include more than once */
#define __unzvers_h
#ifdef BETA
# undef BETA /* undefine BETA for public releases */
#endif
#ifdef BETA
# define UZ_BETALEVEL "k BETA"
# define UZ_VERSION_DATE "17 Feb 02" /* internal beta version */
#else
# define UZ_BETALEVEL ""
# define UZ_VERSION_DATE "17 February 2002" /* official release version */
# define RELEASE
#endif
#define UZ_MAJORVER 5 /* UnZip */
#define UZ_MINORVER 5
#define ZI_MAJORVER 2 /* ZipInfo */
#define ZI_MINORVER 4
#define UZ_PATCHLEVEL 0
#define UZ_VER_STRING "5.5" /* keep in sync with Version numbers! */
#ifndef IZ_COMPANY_NAME /* might be already defined... */
# define IZ_COMPANY_NAME "Info-ZIP"
#endif
/* these are obsolete but remain for backward compatibility: */
#if (defined(OS2) || defined(__OS2__))
# define D2_MAJORVER UZ_MAJORVER /* DLL for OS/2 */
# define D2_MINORVER UZ_MINORVER
# define D2_PATCHLEVEL UZ_PATCHLEVEL
#endif
#define DW_MAJORVER UZ_MAJORVER /* DLL for MS Windows */
#define DW_MINORVER UZ_MINORVER
#define DW_PATCHLEVEL UZ_PATCHLEVEL
#define WIN_VERSION_DATE UZ_VERSION_DATE
#define UNZ_DLL_VERSION UZ_VER_STRING
#endif /* !__unzvers_h */

24
src/apps/bin/unzip/zip.h Normal file
View File

@ -0,0 +1,24 @@
/*
Copyright (c) 1990-2001 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
*/
/* This is a dummy zip.h to allow the source files shared with Zip (crypt.c,
crc32.c, crctab.c, ttyio.c) to compile for UnZip. (In case you are looking
for the Info-ZIP license, please follow the pointers above.) */
#ifndef __zip_h /* don't include more than once */
#define __zip_h
#define UNZIP_INTERNAL
#include "unzip.h"
#define local static
#define ZE_MEM PK_MEM
#define ziperr(c, h) return
#endif /* !__zip_h */

View File

@ -0,0 +1,89 @@
ZIPGREP(1L) ZIPGREP(1L)
NAME
zipgrep - search files in a ZIP archive for lines matching
a pattern
SYNOPSIS
zipgrep [egrep_options] pattern file[.zip] [file(s) ...]
[-x xfile(s) ...]
DESCRIPTION
zipgrep will search files within a ZIP archive for lines
matching the given string or pattern. zipgrep is a shell
script and requires egrep(1) and unzip(1L) to function.
Its output is identical to that of egrep(1).
ARGUMENTS
pattern
The pattern to be located within a ZIP archive.
Any string or regular expression accepted by
egrep(1) may be used. file[.zip] Path of the ZIP
archive. (Wildcard expressions for the ZIP archive
name are not supported.) If the literal filename
is not found, the suffix .zip is appended. Note
that self-extracting ZIP files are supported, as
with any other ZIP archive; just specify the .exe
suffix (if any) explicitly.
[file(s)]
An optional list of archive members to be pro-
cessed, separated by spaces. If no member files
are specified, all members of the ZIP archive are
searched. Regular expressions (wildcards) may be
used to match multiple members:
* matches a sequence of 0 or more characters
? matches exactly 1 character
[...] matches any single character found inside
the brackets; ranges are specified by a
beginning character, a hyphen, and an ending
character. If an exclamation point or a
caret (`!' or `^') follows the left bracket,
then the range of characters within the
brackets is complemented (that is, anything
except the characters inside the brackets is
considered a match).
(Be sure to quote any character that might other-
wise be interpreted or modified by the operating
system.)
[-x xfile(s)]
An optional list of archive members to be excluded
from processing. Since wildcard characters match
Info-ZIP 17 February 2002 1
ZIPGREP(1L) ZIPGREP(1L)
directory separators (`/'), this option may be used
to exclude any files that are in subdirectories.
For example, ``zipgrep grumpy foo *.[ch] -x */*''
would search for the string ``grumpy'' in all C
source files in the main directory of the ``foo''
archive, but none in any subdirectories. Without
the -x option, all C source files in all directo-
ries within the zipfile would be searched.
OPTIONS
All options prior to the ZIP archive filename are passed
to egrep(1).
SEE ALSO
egrep(1), unzip(1L), zip(1L), funzip(1L), zipcloak(1L),
zipinfo(1L), zipnote(1L), zipsplit(1L)
URL
The Info-ZIP home page is currently at http://www.info-
zip.org/pub/infozip/ or ftp://ftp.info-
zip.org/pub/infozip/ .
AUTHORS
zipgrep was written by Jean-loup Gailly.
Info-ZIP 17 February 2002 2

2193
src/apps/bin/unzip/zipinfo.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,513 @@
ZIPINFO(1L) ZIPINFO(1L)
NAME
zipinfo - list detailed information about a ZIP archive
SYNOPSIS
zipinfo [-12smlvhMtTz] file[.zip] [file(s) ...]
[-x xfile(s) ...]
unzip -Z [-12smlvhMtTz] file[.zip] [file(s) ...]
[-x xfile(s) ...]
DESCRIPTION
zipinfo lists technical information about files in a ZIP
archive, most commonly found on MS-DOS systems. Such
information includes file access permissions, encryption
status, type of compression, version and operating system
or file system of compressing program, and the like. The
default behavior (with no options) is to list single-line
entries for each file in the archive, with header and
trailer lines providing summary information for the entire
archive. The format is a cross between Unix ``ls -l'' and
``unzip -v'' output. See DETAILED DESCRIPTION below.
Note that zipinfo is the same program as unzip (under
Unix, a link to it); on some systems, however, zipinfo
support may have been omitted when unzip was compiled.
ARGUMENTS
file[.zip]
Path of the ZIP archive(s). If the file specifica-
tion is a wildcard, each matching file is processed
in an order determined by the operating system (or
file system). Only the filename can be a wildcard;
the path itself cannot. Wildcard expressions are
similar to Unix egrep(1) (regular) expressions and
may contain:
* matches a sequence of 0 or more characters
? matches exactly 1 character
[...] matches any single character found inside
the brackets; ranges are specified by a
beginning character, a hyphen, and an ending
character. If an exclamation point or a
caret (`!' or `^') follows the left bracket,
then the range of characters within the
brackets is complemented (that is, anything
except the characters inside the brackets is
considered a match).
(Be sure to quote any character that might other-
wise be interpreted or modified by the operating
system, particularly under Unix and VMS.) If no
matches are found, the specification is assumed to
be a literal filename; and if that also fails, the
Info-ZIP 17 February 2002 (v2.4) 1
ZIPINFO(1L) ZIPINFO(1L)
suffix .zip is appended. Note that self-extracting
ZIP files are supported; just specify the .exe suf-
fix (if any) explicitly.
[file(s)]
An optional list of archive members to be pro-
cessed. Regular expressions (wildcards) may be
used to match multiple members; see above. Again,
be sure to quote expressions that would otherwise
be expanded or modified by the operating system.
[-x xfile(s)]
An optional list of archive members to be excluded
from processing.
OPTIONS
-1 list filenames only, one per line. This option
excludes all others; headers, trailers and zipfile
comments are never printed. It is intended for use
in Unix shell scripts.
-2 list filenames only, one per line, but allow head-
ers (-h), trailers (-t) and zipfile comments (-z),
as well. This option may be useful in cases where
the stored filenames are particularly long.
-s list zipfile info in short Unix ``ls -l'' format.
This is the default behavior; see below.
-m list zipfile info in medium Unix ``ls -l'' format.
Identical to the -s output, except that the com-
pression factor, expressed as a percentage, is also
listed.
-l list zipfile info in long Unix ``ls -l'' format.
As with -m except that the compressed size (in
bytes) is printed instead of the compression ratio.
-v list zipfile information in verbose, multi-page
format.
-h list header line. The archive name, actual size
(in bytes) and total number of files is printed.
-M pipe all output through an internal pager similar
to the Unix more(1) command. At the end of a
screenful of output, zipinfo pauses with a
``--More--'' prompt; the next screenful may be
viewed by pressing the Enter (Return) key or the
space bar. zipinfo can be terminated by pressing
the ``q'' key and, on some systems, the
Enter/Return key. Unlike Unix more(1), there is no
forward-searching or editing capability. Also,
zipinfo doesn't notice if long lines wrap at the
Info-ZIP 17 February 2002 (v2.4) 2
ZIPINFO(1L) ZIPINFO(1L)
edge of the screen, effectively resulting in the
printing of two or more lines and the likelihood
that some text will scroll off the top of the
screen before being viewed. On some systems the
number of available lines on the screen is not
detected, in which case zipinfo assumes the height
is 24 lines.
-t list totals for files listed or for all files. The
number of files listed, their uncompressed and com-
pressed total sizes, and their overall compression
factor is printed; or, if only the totals line is
being printed, the values for the entire archive
are given. Note that the total compressed (data)
size will never match the actual zipfile size,
since the latter includes all of the internal zip-
file headers in addition to the compressed data.
-T print the file dates and times in a sortable deci-
mal format (yymmdd.hhmmss). The default date for-
mat is a more standard, human-readable version with
abbreviated month names (see examples below).
-z include the archive comment (if any) in the list-
ing.
DETAILED DESCRIPTION
zipinfo has a number of modes, and its behavior can be
rather difficult to fathom if one isn't familiar with Unix
ls(1) (or even if one is). The default behavior is to
list files in the following format:
-rw-rws--- 1.9 unx 2802 t- defX 11-Aug-91 13:48 perms.2660
The last three fields are the modification date and time
of the file, and its name. The case of the filename is
respected; thus files that come from MS-DOS PKZIP are
always capitalized. If the file was zipped with a stored
directory name, that is also displayed as part of the
filename.
The second and third fields indicate that the file was
zipped under Unix with version 1.9 of zip. Since it comes
from Unix, the file permissions at the beginning of the
line are printed in Unix format. The uncompressed file-
size (2802 in this example) is the fourth field.
The fifth field consists of two characters, either of
which may take on several values. The first character may
be either `t' or `b', indicating that zip believes the
file to be text or binary, respectively; but if the file
is encrypted, zipinfo notes this fact by capitalizing the
character (`T' or `B'). The second character may also
take on four values, depending on whether there is an
Info-ZIP 17 February 2002 (v2.4) 3
ZIPINFO(1L) ZIPINFO(1L)
extended local header and/or an ``extra field'' associated
with the file (fully explained in PKWare's APPNOTE.TXT,
but basically analogous to pragmas in ANSI C--i.e., they
provide a standard way to include non-standard information
in the archive). If neither exists, the character will be
a hyphen (`-'); if there is an extended local header but
no extra field, `l'; if the reverse, `x'; and if both
exist, `X'. Thus the file in this example is (probably) a
text file, is not encrypted, and has neither an extra
field nor an extended local header associated with it.
The example below, on the other hand, is an encrypted
binary file with an extra field:
RWD,R,R 0.9 vms 168 Bx shrk 9-Aug-91 19:15 perms.0644
Extra fields are used for various purposes (see discussion
of the -v option below) including the storage of VMS file
attributes, which is presumably the case here. Note that
the file attributes are listed in VMS format. Some other
possibilities for the host operating system (which is
actually a misnomer--host file system is more correct)
include OS/2 or NT with High Performance File System
(HPFS), MS-DOS, OS/2 or NT with File Allocation Table
(FAT) file system, and Macintosh. These are denoted as
follows:
-rw-a-- 1.0 hpf 5358 Tl i4:3 4-Dec-91 11:33 longfilename.hpfs
-r--ahs 1.1 fat 4096 b- i4:2 14-Jul-91 12:58 EA DATA. SF
--w------- 1.0 mac 17357 bx i8:2 4-May-92 04:02 unzip.macr
File attributes in the first two cases are indicated in a
Unix-like format, where the seven subfields indicate
whether the file: (1) is a directory, (2) is readable
(always true), (3) is writable, (4) is executable (guessed
on the basis of the extension--.exe, .com, .bat, .cmd and
.btm files are assumed to be so), (5) has its archive bit
set, (6) is hidden, and (7) is a system file. Interpreta-
tion of Macintosh file attributes is unreliable because
some Macintosh archivers don't store any attributes in the
archive.
Finally, the sixth field indicates the compression method
and possible sub-method used. There are six methods known
at present: storing (no compression), reducing, shrink-
ing, imploding, tokenizing (never publicly released), and
deflating. In addition, there are four levels of reducing
(1 through 4); four types of imploding (4K or 8K sliding
dictionary, and 2 or 3 Shannon-Fano trees); and four lev-
els of deflating (superfast, fast, normal, maximum com-
pression). zipinfo represents these methods and their
sub-methods as follows: stor; re:1, re:2, etc.; shrk;
i4:2, i8:3, etc.; tokn; and defS, defF, defN, and defX.
The medium and long listings are almost identical to the
Info-ZIP 17 February 2002 (v2.4) 4
ZIPINFO(1L) ZIPINFO(1L)
short format except that they add information on the
file's compression. The medium format lists the file's
compression factor as a percentage indicating the amount
of space that has been ``removed'':
-rw-rws--- 1.5 unx 2802 t- 81% defX 11-Aug-91 13:48 perms.2660
In this example, the file has been compressed by more than
a factor of five; the compressed data are only 19% of the
original size. The long format gives the compressed
file's size in bytes, instead:
-rw-rws--- 1.5 unx 2802 t- 538 defX 11-Aug-91 13:48 perms.2660
Adding the -T option changes the file date and time to
decimal format:
-rw-rws--- 1.5 unx 2802 t- 538 defX 910811.134804 perms.2660
Note that because of limitations in the MS-DOS format used
to store file times, the seconds field is always rounded
to the nearest even second. For Unix files this is
expected to change in the next major releases of zip(1L)
and unzip.
In addition to individual file information, a default zip-
file listing also includes header and trailer lines:
Archive: OS2.zip 5453 bytes 5 files
,,rw, 1.0 hpf 730 b- i4:3 26-Jun-92 23:40 Contents
,,rw, 1.0 hpf 3710 b- i4:3 26-Jun-92 23:33 makefile.os2
,,rw, 1.0 hpf 8753 b- i8:3 26-Jun-92 15:29 os2unzip.c
,,rw, 1.0 hpf 98 b- stor 21-Aug-91 15:34 unzip.def
,,rw, 1.0 hpf 95 b- stor 21-Aug-91 17:51 zipinfo.def
5 files, 13386 bytes uncompressed, 4951 bytes compressed: 63.0%
The header line gives the name of the archive, its total
size, and the total number of files; the trailer gives the
number of files listed, their total uncompressed size, and
their total compressed size (not including any of zip's
internal overhead). If, however, one or more file(s) are
provided, the header and trailer lines are not listed.
This behavior is also similar to that of Unix's ``ls -l'';
it may be overridden by specifying the -h and -t options
explicitly. In such a case the listing format must also
be specified explicitly, since -h or -t (or both) in the
absence of other options implies that ONLY the header or
trailer line (or both) is listed. See the EXAMPLES sec-
tion below for a semi-intelligible translation of this
nonsense.
The verbose listing is mostly self-explanatory. It also
lists file comments and the zipfile comment, if any, and
the type and number of bytes in any stored extra fields.
Info-ZIP 17 February 2002 (v2.4) 5
ZIPINFO(1L) ZIPINFO(1L)
Currently known types of extra fields include PKWARE's
authentication (``AV'') info; OS/2 extended attributes;
VMS filesystem info, both PKWARE and Info-ZIP versions;
Macintosh resource forks; Acorn/Archimedes SparkFS info;
and so on. (Note that in the case of OS/2 extended
attributes--perhaps the most common use of zipfile extra
fields--the size of the stored EAs as reported by zipinfo
may not match the number given by OS/2's dir command: OS/2
always reports the number of bytes required in 16-bit for-
mat, whereas zipinfo always reports the 32-bit storage.)
ENVIRONMENT OPTIONS
Modifying zipinfo's default behavior via options placed in
an environment variable can be a bit complicated to
explain, due to zipinfo's attempts to handle various
defaults in an intuitive, yet Unix-like, manner. (Try not
to laugh.) Nevertheless, there is some underlying logic.
In brief, there are three ``priority levels'' of options:
the default options; environment options, which can over-
ride or add to the defaults; and explicit options given by
the user, which can override or add to either of the
above.
The default listing format, as noted above, corresponds
roughly to the "zipinfo -hst" command (except when indi-
vidual zipfile members are specified). A user who prefers
the long-listing format (-l) can make use of the zipinfo's
environment variable to change this default:
Unix Bourne shell:
ZIPINFO=-l; export ZIPINFO
Unix C shell:
setenv ZIPINFO -l
OS/2 or MS-DOS:
set ZIPINFO=-l
VMS (quotes for lowercase):
define ZIPINFO_OPTS "-l"
If, in addition, the user dislikes the trailer line, zip-
info's concept of ``negative options'' may be used to
override the default inclusion of the line. This is
accomplished by preceding the undesired option with one or
more minuses: e.g., ``-l-t'' or ``--tl'', in this exam-
ple. The first hyphen is the regular switch character,
but the one before the `t' is a minus sign. The dual use
of hyphens may seem a little awkward, but it's reasonably
intuitive nonetheless: simply ignore the first hyphen and
go from there. It is also consistent with the behavior of
the Unix command nice(1).
As suggested above, the default variable names are
Info-ZIP 17 February 2002 (v2.4) 6
ZIPINFO(1L) ZIPINFO(1L)
ZIPINFO_OPTS for VMS (where the symbol used to install
zipinfo as a foreign command would otherwise be confused
with the environment variable), and ZIPINFO for all other
operating systems. For compatibility with zip(1L), ZIPIN-
FOOPT is also accepted (don't ask). If both ZIPINFO and
ZIPINFOOPT are defined, however, ZIPINFO takes precedence.
unzip's diagnostic option (-v with no zipfile name) can be
used to check the values of all four possible unzip and
zipinfo environment variables.
EXAMPLES
To get a basic, short-format listing of the complete con-
tents of a ZIP archive storage.zip, with both header and
totals lines, use only the archive name as an argument to
zipinfo:
zipinfo storage
To produce a basic, long-format listing (not verbose),
including header and totals lines, use -l:
zipinfo -l storage
To list the complete contents of the archive without
header and totals lines, either negate the -h and -t
options or else specify the contents explicitly:
zipinfo --h-t storage
zipinfo storage \*
(where the backslash is required only if the shell would
otherwise expand the `*' wildcard, as in Unix when glob-
bing is turned on--double quotes around the asterisk would
have worked as well). To turn off the totals line by
default, use the environment variable (C shell is assumed
here):
setenv ZIPINFO --t
zipinfo storage
To get the full, short-format listing of the first example
again, given that the environment variable is set as in
the previous example, it is necessary to specify the -s
option explicitly, since the -t option by itself implies
that ONLY the footer line is to be printed:
setenv ZIPINFO --t
zipinfo -t storage [only totals line]
zipinfo -st storage [full listing]
The -s option, like -m and -l, includes headers and foot-
ers by default, unless otherwise specified. Since the
environment variable specified no footers and that has a
higher precedence than the default behavior of -s, an
Info-ZIP 17 February 2002 (v2.4) 7
ZIPINFO(1L) ZIPINFO(1L)
explicit -t option was necessary to produce the full list-
ing. Nothing was indicated about the header, however, so
the -s option was sufficient. Note that both the -h and
-t options, when used by themselves or with each other,
override any default listing of member files; only the
header and/or footer are printed. This behavior is useful
when zipinfo is used with a wildcard zipfile specifica-
tion; the contents of all zipfiles are then summarized
with a single command.
To list information on a single file within the archive,
in medium format, specify the filename explicitly:
zipinfo -m storage unshrink.c
The specification of any member file, as in this example,
will override the default header and totals lines; only
the single line of information about the requested file
will be printed. This is intuitively what one would
expect when requesting information about a single file.
For multiple files, it is often useful to know the total
compressed and uncompressed size; in such cases -t may be
specified explicitly:
zipinfo -mt storage "*.[ch]" Mak\*
To get maximal information about the ZIP archive, use the
verbose option. It is usually wise to pipe the output
into a filter such as Unix more(1) if the operating system
allows it:
zipinfo -v storage | more
Finally, to see the most recently modified files in the
archive, use the -T option in conjunction with an external
sorting utility such as Unix sort(1) (and tail(1) as well,
in this example):
zipinfo -T storage | sort -n +6 | tail -15
The -n option to sort(1) tells it to sort numerically
rather than in ASCII order, and the +6 option tells it to
sort on the sixth field after the first one (i.e., the
seventh field). This assumes the default short-listing
format; if -m or -l is used, the proper sort(1) option
would be +7. The tail(1) command filters out all but the
last 15 lines of the listing. Future releases of zipinfo
may incorporate date/time and filename sorting as built-in
options.
TIPS
The author finds it convenient to define an alias ii for
zipinfo on systems that allow aliases (or, on other sys-
tems, copy/rename the executable, create a link or create
Info-ZIP 17 February 2002 (v2.4) 8
ZIPINFO(1L) ZIPINFO(1L)
a command file with the name ii). The ii usage parallels
the common ll alias for long listings in Unix, and the
similarity between the outputs of the two commands was
intentional.
BUGS
As with unzip, zipinfo's -M (``more'') option is overly
simplistic in its handling of screen output; as noted
above, it fails to detect the wrapping of long lines and
may thereby cause lines at the top of the screen to be
scrolled off before being read. zipinfo should detect and
treat each occurrence of line-wrap as one additional line
printed. This requires knowledge of the screen's width as
well as its height. In addition, zipinfo should detect
the true screen geometry on all systems.
zipinfo's listing-format behavior is unnecessarily complex
and should be simplified. (This is not to say that it
will be.)
SEE ALSO
ls(1), funzip(1L), unzip(1L), unzipsfx(1L), zip(1L), zip-
cloak(1L), zipnote(1L), zipsplit(1L)
URL
The Info-ZIP home page is currently at
http://www.info-zip.org/pub/infozip/
or
ftp://ftp.info-zip.org/pub/infozip/ .
AUTHOR
Greg ``Cave Newt'' Roelofs. ZipInfo contains pattern-
matching code by Mark Adler and fixes/improvements by many
others. Please refer to the CONTRIBS file in the UnZip
source distribution for a more complete list.
Info-ZIP 17 February 2002 (v2.4) 9